acpi: Correct get_handle implementation.
authorMoritz Hoffmann <moritz.hoffmann@hpe.com>
Tue, 26 Jul 2016 23:29:55 +0000 (16:29 -0700)
committerReto Achermann <reto.achermann@inf.ethz.ch>
Thu, 6 Oct 2016 09:02:00 +0000 (11:02 +0200)
Signed-off-by: Moritz Hoffmann <moritz.hoffmann@hpe.com>

errors/errno.fugu
usr/acpi/acpi_service.c

index 8637627..27346e7 100755 (executable)
@@ -835,6 +835,7 @@ errors acpi ACPI_ERR_ {
     failure GET_RESOURCES       "Failed to execute _CRT method.",
     failure SET_IRQ             "Failed to set IRQ for device.",
     failure NO_MADT_TABLE       "No APIC found in ACPI.",
+    failure OBJECT_NOT_FOUND    "Could not locate ACPI object.",
 };
 
 errors vtd VTD_ERR_ {
index 9b40e38..825ef66 100644 (file)
@@ -210,6 +210,31 @@ static void sleep_handler(struct acpi_binding *b, uint32_t state)
     }
 }
 
+
+static
+ACPI_STATUS get_handle_handler_callback(
+    ACPI_HANDLE                     Object,
+    UINT32                          NestingLevel,
+    void                            *Context,
+    void                            **ReturnValue) {
+
+    ACPI_STATUS as;
+    ACPI_DEVICE_INFO *device_info;
+    as = AcpiGetObjectInfo(Object, &device_info);
+    if (ACPI_FAILURE(as)) {
+        debug_printf("AcpiGetObjectInfo failed: %x\n", as);
+        return AE_OK;
+    }
+
+    if (device_info->HardwareId.Length &&
+            !strncmp(device_info->HardwareId.String, Context, device_info->HardwareId.Length)) {
+        debug_printf("device HardwareId=%s UniqueId=%s\n", device_info->HardwareId.String, device_info->UniqueId.String);
+        *ReturnValue = Object;
+    }
+    ACPI_FREE(device_info);
+    return AE_OK;
+}
+
 static void get_handle_handler(struct acpi_binding *b, char *dev_id)
 {
     errval_t err = SYS_ERR_OK;;
@@ -217,14 +242,14 @@ static void get_handle_handler(struct acpi_binding *b, char *dev_id)
     debug_printf("Looking up handle for device '%s'\n", dev_id);
 
     ACPI_STATUS s;
-    ACPI_HANDLE handle;
-    s = AcpiGetHandle (NULL,dev_id,&handle);
+    ACPI_HANDLE handle = NULL;
+
+    s = AcpiGetDevices(NULL, get_handle_handler_callback, dev_id, &handle);
     if (ACPI_FAILURE(s)) {
-        if (s == AE_BAD_PATHNAME) {
-            err = ACPI_ERR_INVALID_PATH_NAME;
-        } else {
-            err = ACPI_ERR_INVALID_HANDLE;
-        }
+        debug_printf("Looking up handle failed: %d\n", s);
+        err = ACPI_ERR_INVALID_HANDLE;
+    } else if (handle == NULL) {
+        err = ACPI_ERR_OBJECT_NOT_FOUND;
     }
 
     //out uint64 handle, out errval err