From 413ce2db29ac236af62fceeff8a9f9c5391a6297 Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Tue, 26 Jul 2016 16:29:55 -0700 Subject: [PATCH] acpi: Correct get_handle implementation. Signed-off-by: Moritz Hoffmann --- errors/errno.fugu | 1 + usr/acpi/acpi_service.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/errors/errno.fugu b/errors/errno.fugu index 8637627..27346e7 100755 --- a/errors/errno.fugu +++ b/errors/errno.fugu @@ -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_ { diff --git a/usr/acpi/acpi_service.c b/usr/acpi/acpi_service.c index 9b40e38..825ef66 100644 --- a/usr/acpi/acpi_service.c +++ b/usr/acpi/acpi_service.c @@ -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 -- 1.7.2.5