acpi: create fake acpi devices for FADT power and sleep buttons.

* adjust ACPIDeviceModule to accept nodes without ACPI_DEVICE_PATH_ITEM.
This commit is contained in:
Jérôme Duval
2013-10-30 22:29:38 +01:00
parent daf95c6d8c
commit cb4d33ca26
2 changed files with 48 additions and 6 deletions
@@ -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;
@@ -9,8 +9,11 @@
#include <stdlib.h>
#include <string.h>
#include "ACPIPrivate.h"
#include "ACPIPrivate.h"
extern "C" {
#include "acpi.h"
}
#include <dpc.h>
#include <PCI.h>
@@ -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, "\\");
}