acpi: adding functionality to lookup a device handle and to evaluate integer on it.
authorReto Achermann <reto.achermann@inf.ethz.ch>
Tue, 26 Jul 2016 08:49:36 +0000 (10:49 +0200)
committerReto Achermann <reto.achermann@inf.ethz.ch>
Tue, 26 Jul 2016 08:49:36 +0000 (10:49 +0200)
Signed-off-by: Reto Achermann <reto.achermann@inf.ethz.ch>

if/acpi.if
include/acpi_client/acpi_client.h
lib/acpi_client/acpi_client.c
usr/acpi/acpi_service.c

index 57b2cd5..28c1ac0 100644 (file)
@@ -39,6 +39,9 @@ interface acpi "acpi RPC Interface" {
     rpc reset(out errval err);
     rpc sleep(in uint32 state, out errval err);
 
+    rpc get_handle(in string devid, out uint64 handle, out errval err);
+    rpc eval_integer(in uint64 handle, in string path, out uint64 val, out errval err); 
+
     // Kludge: retrieve frame cap to VBE BIOS;
     rpc get_vbe_bios_cap(out errval err, out cap cap, out uint32 size);
 
index 83deec3..b7ad66c 100644 (file)
 /* forward declaration */
 struct acpi_rpc_client;
 
+typedef uint64_t acpi_device_handle_t;
+
+
 struct acpi_rpc_client* get_acpi_rpc_client(void);
 errval_t connect_to_acpi(void);
 
+errval_t acpi_client_get_device_handle(const char *dev_id,
+                                       acpi_device_handle_t *ret_handle);
+errval_t acpi_client_eval_integer(acpi_device_handle_t handle,
+                                  const char *path, uint64_t *data);
+
 errval_t acpi_reset(void);
 errval_t acpi_sleep(int state);
 errval_t acpi_get_vbe_bios_cap(struct capref *retcap, size_t *retsize);
index 455292b..e0d76c1 100644 (file)
@@ -28,6 +28,25 @@ static struct acpi_connection {
 
 static struct acpi_rpc_client* rpc_client;
 
+errval_t acpi_client_get_device_handle(const char *dev_id,
+                                       acpi_device_handle_t *ret_handle)
+{
+    assert(rpc_client != NULL);
+    errval_t err, msgerr;
+    err = rpc_client->vtbl.get_handle(rpc_client, dev_id, ret_handle, &msgerr);
+    return err_is_fail(err) ? err : msgerr;
+}
+
+errval_t acpi_client_eval_integer(acpi_device_handle_t handle,
+                                  const char *path, uint64_t *data)
+{
+    assert(rpc_client != NULL);
+    errval_t err, msgerr;
+    err = rpc_client->vtbl.eval_integer(rpc_client, handle, path, data, &msgerr);
+    return err_is_fail(err) ? err : msgerr;
+}
+
+
 errval_t acpi_reset(void)
 {
     assert(rpc_client != NULL);
index 30b8fc7..f456623 100644 (file)
@@ -260,12 +260,62 @@ static void sleep_handler(struct acpi_binding *b, uint32_t state)
     }
 }
 
+static void get_handle_handler(struct acpi_binding *b, char *dev_id)
+{
+    errval_t err = SYS_ERR_OK;;
+
+    debug_printf("Looking up handle for device '%s'\n", dev_id);
+
+    ACPI_STATUS s;
+    ACPI_HANDLE handle;
+    s = AcpiGetHandle (NULL,dev_id,&handle);
+    if (ACPI_FAILURE(s)) {
+        if (s == AE_BAD_PATHNAME) {
+            err = ACPI_ERR_INVALID_PATH_NAME;
+        } else {
+            err = ACPI_ERR_INVALID_HANDLE;
+        }
+    }
+
+    //out uint64 handle, out errval err
+    err = b->tx_vtbl.get_handle_response(b, NOP_CONT, (uint64_t)handle, err);
+    assert(err_is_ok(err));
+
+    free(dev_id);
+}
+
+static void eval_integer_handler(struct acpi_binding *b,
+                                 uint64_t handle, char *path)
+{
+    errval_t err = SYS_ERR_OK;
+
+    ACPI_STATUS s;
+    ACPI_INTEGER val = 0;
+    s = acpi_eval_integer((ACPI_HANDLE)handle, path, &val);
+    if (ACPI_FAILURE(s)) {
+        if (s == AE_BAD_PATHNAME) {
+            err = ACPI_ERR_INVALID_PATH_NAME;
+        } else {
+            err = ACPI_ERR_INVALID_HANDLE;
+        }
+        val = 0;
+    }
+
+    debug_printf("eval_integer_handler\n");
+    err = b->tx_vtbl.eval_integer_response(b, NOP_CONT, val, err);
+    free(path);
+}
+
+
 struct acpi_rx_vtbl acpi_rx_vtbl = {
     .get_pcie_confspace_call = get_pcie_confspace,
     .read_irq_table_call = read_irq_table,
     .set_device_irq_call = set_device_irq,
     .enable_and_route_interrupt_call = enable_interrupt_handler,
 
+    .get_handle_call = get_handle_handler,
+    .eval_integer_call = eval_integer_handler,
+
     .mm_alloc_range_proxy_call = mm_alloc_range_proxy_handler,
     .mm_realloc_range_proxy_call = mm_realloc_range_proxy_handler,
     .mm_free_proxy_call = mm_free_proxy_handler,