diff --git a/src/add-ons/kernel/bus_managers/acpi/Device.cpp b/src/add-ons/kernel/bus_managers/acpi/Device.cpp index 136f86633b..7b7ed1d725 100644 --- a/src/add-ons/kernel/bus_managers/acpi/Device.cpp +++ b/src/add-ons/kernel/bus_managers/acpi/Device.cpp @@ -57,6 +57,8 @@ acpi_get_object_type(acpi_device device) static status_t acpi_get_object(acpi_device device, const char *path, acpi_object_type **return_value) { + if (device->path == NULL) + return B_BAD_VALUE; if (path) { char objname[255]; snprintf(objname, sizeof(objname), "%s.%s", device->path, path); @@ -86,13 +88,12 @@ static status_t acpi_device_init_driver(device_node *node, void **cookie) { ACPI_HANDLE handle; - const char *path; + const char *path = NULL; uint32 type; if (gDeviceManager->get_attr_uint32(node, ACPI_DEVICE_TYPE_ITEM, &type, false) != B_OK) return B_ERROR; - if (gDeviceManager->get_attr_string(node, ACPI_DEVICE_PATH_ITEM, &path, false) != B_OK) - return B_ERROR; + gDeviceManager->get_attr_string(node, ACPI_DEVICE_PATH_ITEM, &path, false); acpi_device_cookie *device = (acpi_device_cookie*)malloc(sizeof(*device)); if (device == NULL) @@ -100,13 +101,13 @@ acpi_device_init_driver(device_node *node, void **cookie) memset(device, 0, sizeof(*device)); - if (AcpiGetHandle(NULL, (ACPI_STRING)path, &handle) != AE_OK) { + if (path != NULL && AcpiGetHandle(NULL, (ACPI_STRING)path, &handle) != AE_OK) { free(device); return B_ENTRY_NOT_FOUND; } device->handle = handle; - device->path = strdup(path); + device->path = path != NULL ? strdup(path) : NULL; device->type = type; device->node = node; diff --git a/src/add-ons/kernel/bus_managers/acpi/Module.cpp b/src/add-ons/kernel/bus_managers/acpi/Module.cpp index dd639787a4..244311b19f 100644 --- a/src/add-ons/kernel/bus_managers/acpi/Module.cpp +++ b/src/add-ons/kernel/bus_managers/acpi/Module.cpp @@ -9,8 +9,11 @@ #include #include -#include "ACPIPrivate.h" +#include "ACPIPrivate.h" +extern "C" { +#include "acpi.h" +} #include #include @@ -133,6 +136,44 @@ acpi_module_register_child_devices(void* cookie) if (status != B_OK) return status; + if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) { + dprintf("registering power button\n"); + device_attr attrs[] = { + // info about device + { B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }}, + + // info about the device + { ACPI_DEVICE_HID_ITEM, B_STRING_TYPE, { string: "ACPI_FPB" }}, + { ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: ACPI_TYPE_DEVICE }}, + + // consumer specification + { B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_MULTIPLE_CHILDREN }}, + { NULL } + }; + device_node* deviceNode; + gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs, + NULL, &deviceNode); + } + if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) { + dprintf("registering sleep button\n"); + device_attr attrs[] = { + // info about device + { B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }}, + + // info about the device + { ACPI_DEVICE_HID_ITEM, B_STRING_TYPE, { string: "ACPI_FSB" }}, + { ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: ACPI_TYPE_DEVICE }}, + + // consumer specification + { B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_MULTIPLE_CHILDREN }}, + { NULL } + }; + device_node* deviceNode; + gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs, + NULL, &deviceNode); + + } + return acpi_enumerate_child_devices(node, "\\"); }