converted acpi to the new device architecture

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25805 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2008-06-04 23:05:02 +00:00
parent 9223644a02
commit 53e6934549
4 changed files with 104 additions and 173 deletions
@@ -14,7 +14,7 @@
typedef struct acpi_device_info {
char *path; // path
uint32 type; // type
device_node_handle node;
device_node *node;
char name[32]; // name (for fast log)
} acpi_device_info;
@@ -44,9 +44,9 @@ acpi_evaluate_method(acpi_device device, const char *method, acpi_object_type *r
static status_t
acpi_device_init_driver(device_node_handle node, void *user_cookie, void **cookie)
acpi_device_init_driver(device_node *node, void **cookie)
{
char *path;
const char *path;
acpi_device_info *device;
status_t status = B_OK;
uint32 type;
@@ -57,14 +57,12 @@ acpi_device_init_driver(device_node_handle node, void *user_cookie, void **cooki
return B_ERROR;
device = malloc(sizeof(*device));
if (device == NULL) {
free(path);
if (device == NULL)
return B_NO_MEMORY;
}
memset(device, 0, sizeof(*device));
device->path = path;
device->path = strdup(path);
device->type = type;
device->node = node;
@@ -83,14 +81,13 @@ acpi_device_init_driver(device_node_handle node, void *user_cookie, void **cooki
}
static status_t
static void
acpi_device_uninit_driver(void *cookie)
{
acpi_device_info *device = cookie;
free(device->path);
free(device);
return B_OK;
}
@@ -118,9 +115,9 @@ acpi_device_module_info gACPIDeviceModule = {
NULL, // register device (our parent registered us)
acpi_device_init_driver,
acpi_device_uninit_driver,
NULL, // removed
NULL, // cleanup
NULL, // get supported paths
NULL, // register child devices
NULL, // rescan devices
NULL, // device removed
},
acpi_get_object_type,
acpi_get_object,
@@ -33,64 +33,53 @@ module_dependency module_dependencies[] = {
static float
acpi_module_supports_device(device_node_handle parent, bool *_noConnection)
acpi_module_supports_device(device_node *parent)
{
char *bus;
const char *bus;
// make sure parent is really device root
if (gDeviceManager->get_attr_string(parent, B_DRIVER_BUS, &bus, false))
if (gDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false))
return B_ERROR;
if (strcmp(bus, "root")) {
free(bus);
if (strcmp(bus, "root"))
return 0.0;
}
free(bus);
return 1.0;
}
static status_t
acpi_module_register_device(device_node_handle parent)
acpi_module_register_device(device_node *parent)
{
device_attr attrs[] = {
// info about ourself
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: ACPI_ROOT_MODULE_NAME }},
// unique connection name
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string: "ACPI" }},
// mark as being a bus
{ PNP_BUS_IS_BUS, B_UINT8_TYPE, { ui8: 1 }},
// search for device drivers once all devices are detected
//{ PNP_BUS_DEFER_PROBE, B_UINT8_TYPE, { ui8: 1 }},
// don't scan if loaded as we own I/O resources
//{ PNP_DRIVER_NO_LIVE_RESCAN, B_UINT8_TYPE, { ui8: 1 }},
{ B_DEVICE_PRETTY_NAME, B_STRING_TYPE, { string: "ACPI" }},
// tell ns dump driver to register a device in devfs
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: ACPI_NS_DUMP_MODULE_NAME }},
{ B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_KEEP_DRIVER_LOADED }},
{}
};
io_resource_handle *resourceHandles = NULL;
device_node_handle node;
return gDeviceManager->register_device(parent, attrs, resourceHandles, &node);
io_resource *resources = NULL;
return gDeviceManager->register_node(parent, ACPI_ROOT_MODULE_NAME, attrs, resources, NULL);
}
static status_t
acpi_enumerate_child_devices(device_node_handle node, const char *root)
acpi_enumerate_child_devices(device_node *node, const char *root)
{
char result[255];
void *counter = NULL;
device_node *parent = NULL;
TRACE(("acpi_enumerate_child_devices: recursing from %s\n", root));
// get a reference on the parent
parent = gDeviceManager->get_parent_node(node);
while (get_next_entry(ACPI_TYPE_ANY, root, result, 255, &counter) == B_OK) {
uint32 type = get_object_type(result);
device_node_handle deviceNode;
device_node *deviceNode;
if (!strcmp("\\_PR_", result) || !strcmp("\\_TZ_", result)
|| !strcmp("\\_SI_", result) || !strcmp("\\_SB_", result)) {
@@ -103,10 +92,8 @@ acpi_enumerate_child_devices(device_node_handle node, const char *root)
char hid[9] = "";
device_attr attrs[] = {
// info about device
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: ACPI_DEVICE_MODULE_NAME }},
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string:
"path: %"ACPI_DEVICE_PATH_ITEM"%" }},
{ B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }},
// location on ACPI bus
{ ACPI_DEVICE_PATH_ITEM, B_STRING_TYPE, { string: result }},
@@ -115,17 +102,17 @@ acpi_enumerate_child_devices(device_node_handle node, const char *root)
{ ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: type }},
// consumer specification
{ B_DRIVER_BUS, B_STRING_TYPE, { string: "acpi" }},
{ B_DRIVER_MAPPING, B_STRING_TYPE, { string:
/*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string:
"hid_%" ACPI_DEVICE_HID_ITEM "%" }},
{ B_DRIVER_MAPPING "/0", B_STRING_TYPE, { string:
"type_%" ACPI_DEVICE_TYPE_ITEM "%" }},
"type_%" ACPI_DEVICE_TYPE_ITEM "%" }},*/
{ B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_CHILD_ON_DEMAND }},
{ NULL }
};
get_device_hid(result, hid);
if (gDeviceManager->register_device(node, attrs, NULL, &deviceNode) == B_OK)
if (gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs, NULL, &deviceNode) == B_OK)
acpi_enumerate_child_devices(deviceNode, result);
break;
}
@@ -134,10 +121,8 @@ acpi_enumerate_child_devices(device_node_handle node, const char *root)
case ACPI_TYPE_THERMAL: {
device_attr attrs[] = {
// info about device
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: ACPI_DEVICE_MODULE_NAME }},
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string:
"path: %"ACPI_DEVICE_PATH_ITEM"%" }},
{ B_DEVICE_BUS, B_STRING_TYPE, { string: "acpi" }},
// location on ACPI bus
{ ACPI_DEVICE_PATH_ITEM, B_STRING_TYPE, { string: result }},
@@ -145,13 +130,13 @@ acpi_enumerate_child_devices(device_node_handle node, const char *root)
{ ACPI_DEVICE_TYPE_ITEM, B_UINT32_TYPE, { ui32: type }},
// consumer specification
{ B_DRIVER_BUS, B_STRING_TYPE, { string: "acpi" }},
{ B_DRIVER_MAPPING, B_STRING_TYPE, { string:
"type_%" ACPI_DEVICE_TYPE_ITEM "%" }},
/*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string:
"type_%" ACPI_DEVICE_TYPE_ITEM "%" }},*/
{ B_DEVICE_FLAGS, B_UINT32_TYPE, { ui32: B_FIND_CHILD_ON_DEMAND }},
{ NULL }
};
if (gDeviceManager->register_device(node, attrs, NULL, &deviceNode) == B_OK)
if (gDeviceManager->register_node(node, ACPI_DEVICE_MODULE_NAME, attrs, NULL, &deviceNode) == B_OK)
acpi_enumerate_child_devices(deviceNode, result);
break;
}
@@ -169,33 +154,29 @@ acpi_enumerate_child_devices(device_node_handle node, const char *root)
static status_t
acpi_module_register_child_devices(void *cookie)
{
device_node_handle node = cookie;
status_t err;
device_node *node = cookie;
err = gDeviceManager->publish_device(node, "acpi/namespace", ACPI_NS_DUMP_DEVICE_MODULE_NAME);
if (err != B_OK) {
return err;
}
return acpi_enumerate_child_devices(node, "\\");
}
static void
acpi_module_get_paths(const char ***_bus, const char ***_device)
{
static const char *kBus[] = {"root", NULL};
*_bus = kBus;
*_device = NULL;
}
static status_t
acpi_module_init(device_node_handle node, void *user_cookie, void **_cookie)
acpi_module_init(device_node *node, void **_cookie)
{
*_cookie = node;
return B_OK;
}
static status_t
static void
acpi_module_uninit(void *cookie)
{
return B_OK;
}
@@ -221,23 +202,18 @@ apci_module_std_ops(int32 op, ...)
static struct acpi_root_info sACPIModule = {
{
{
{
ACPI_ROOT_MODULE_NAME,
0,
apci_module_std_ops
},
acpi_module_supports_device,
acpi_module_register_device,
acpi_module_init,
acpi_module_uninit,
NULL, // removed
NULL, // cleanup
acpi_module_get_paths,
ACPI_ROOT_MODULE_NAME,
0,
apci_module_std_ops
},
acpi_module_supports_device,
acpi_module_register_device,
acpi_module_init,
acpi_module_uninit,
acpi_module_register_child_devices,
NULL, // rescan bus
NULL, // rescan devices
NULL, // device removed
},
enable_fixed_event,
@@ -13,7 +13,7 @@
typedef struct acpi_ns_device_info {
device_node_handle node;
device_node *node;
acpi_root_info *acpi;
void *acpi_cookie;
} acpi_ns_device_info;
@@ -104,8 +104,9 @@ dump_acpi_namespace(acpi_ns_device_info *device, char *root, void *buf, size_t*
----- */
static status_t
acpi_namespace_open(acpi_ns_device_info *device, uint32 flags, void** cookie)
acpi_namespace_open(void *_cookie, const char* path, int flags, void** cookie)
{
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
dprintf("\nacpi_ns_dump: device_open\n");
*cookie = device;
@@ -117,8 +118,9 @@ acpi_namespace_open(acpi_ns_device_info *device, uint32 flags, void** cookie)
acpi_namespace_read - handle read() calls
----- */
static status_t
acpi_namespace_read (acpi_ns_device_info *device, off_t position, void *buf, size_t* num_bytes)
acpi_namespace_read(void *_cookie, off_t position, void *buf, size_t* num_bytes)
{
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
size_t bytes = 0;
if (position == 0) { // First read
@@ -143,7 +145,7 @@ acpi_namespace_read (acpi_ns_device_info *device, off_t position, void *buf, siz
----- */
static status_t
acpi_namespace_write (void* cookie, off_t position, const void* buffer, size_t* num_bytes)
acpi_namespace_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
{
dprintf("acpi_ns_dump: device_write\n");
*num_bytes = 0; /* tell caller nothing was written */
@@ -156,7 +158,7 @@ acpi_namespace_write (void* cookie, off_t position, const void* buffer, size_t*
----- */
static status_t
acpi_namespace_control (void* cookie, uint32 op, void* arg, size_t len)
acpi_namespace_control(void* cookie, uint32 op, void* arg, size_t len)
{
dprintf("acpi_ns_dump: device_control\n");
return B_BAD_VALUE;
@@ -168,7 +170,7 @@ acpi_namespace_control (void* cookie, uint32 op, void* arg, size_t len)
----- */
static status_t
acpi_namespace_close (void* cookie)
acpi_namespace_close(void* cookie)
{
dprintf("acpi_ns_dump: device_close\n");
return B_OK;
@@ -180,7 +182,7 @@ acpi_namespace_close (void* cookie)
all i/o is complete.
----- */
static status_t
acpi_namespace_free (void* cookie)
acpi_namespace_free(void* cookie)
{
dprintf("acpi_ns_dump: device_free\n");
@@ -188,103 +190,59 @@ acpi_namespace_free (void* cookie)
}
static status_t
acpi_namespace_init_device(device_node_handle node, void *user_cookie, void **cookie)
{
acpi_ns_device_info *device;
status_t res;
// #pragma mark - device module API
device = (acpi_ns_device_info *)calloc(1, sizeof(*device));
static status_t
acpi_namespace_init_device(void *_cookie, void **cookie)
{
device_node *node = (device_node *)_cookie;
status_t err;
acpi_ns_device_info *device = (acpi_ns_device_info *)calloc(1, sizeof(*device));
if (device == NULL)
return B_NO_MEMORY;
device->node = node;
// register it everywhere
res = gDeviceManager->init_driver(gDeviceManager->get_parent(node), NULL,
(driver_module_info **)&device->acpi, &device->acpi_cookie);
if (res != B_OK)
goto err;
err = gDeviceManager->get_driver(node, (driver_module_info **)&device->acpi,
(void **)&device->acpi_cookie);
if (err != B_OK) {
free(device);
return err;
}
*cookie = device;
return B_OK;
}
err:
static void
acpi_namespace_uninit_device(void *_cookie)
{
acpi_ns_device_info *device = (acpi_ns_device_info *)_cookie;
free(device);
return res;
}
static status_t
acpi_namespace_uninit_device(acpi_ns_device_info *device)
{
gDeviceManager->uninit_driver(gDeviceManager->get_parent(device->node));
free(device);
return B_OK;
}
static status_t
acpi_namespace_added(device_node_handle node)
{
device_attr attrs[] = {
{ B_DRIVER_MODULE, B_STRING_TYPE, { string: ACPI_NS_DUMP_MODULE_NAME }},
{ PNP_DRIVER_CONNECTION, B_STRING_TYPE, { string: "namespace" }},
// we want devfs on top of us (who wouldn't?)
{ B_DRIVER_FIXED_CHILD, B_STRING_TYPE, { string: PNP_DEVFS_MODULE_NAME }},
// tell which name we want to have in devfs
{ PNP_DEVFS_FILENAME, B_STRING_TYPE, { string: "acpi/namespace" }},
{ NULL }
};
return gDeviceManager->register_device(node, attrs, NULL, &node);
}
static status_t
std_ops(int32 op, ...)
{
switch (op) {
case B_MODULE_INIT:
case B_MODULE_UNINIT:
return B_OK;
default:
return B_ERROR;
}
}
pnp_devfs_driver_info acpi_ns_dump_module = {
struct device_module_info acpi_ns_dump_module = {
{
{
ACPI_NS_DUMP_MODULE_NAME,
0,
std_ops
},
NULL,
acpi_namespace_added,
acpi_namespace_init_device,
(status_t (*) (void *))acpi_namespace_uninit_device,
ACPI_NS_DUMP_DEVICE_MODULE_NAME,
0,
NULL
},
(status_t (*)(void *, uint32, void **)) &acpi_namespace_open,
acpi_namespace_init_device,
acpi_namespace_uninit_device,
NULL,
acpi_namespace_open,
acpi_namespace_close,
acpi_namespace_free,
(status_t (*)(void *, uint32, void *, size_t)) &acpi_namespace_control,
acpi_namespace_read,
acpi_namespace_write,
NULL,
NULL,
acpi_namespace_control,
NULL,
NULL
};
@@ -7,18 +7,18 @@
#ifndef __ACPI_PRIV_H__
#define __ACPI_PRIV_H__
#include <device_manager.h>
#include <KernelExport.h>
#include <ACPI.h>
#include <pnp_devfs.h>
// name of ACPI root module
#define ACPI_ROOT_MODULE_NAME "bus_managers/acpi/root/device_v1"
#define ACPI_ROOT_MODULE_NAME "bus_managers/acpi/root/driver_v1"
// name of ACPI device modules
#define ACPI_DEVICE_MODULE_NAME "bus_managers/acpi/device_v1"
#define ACPI_DEVICE_MODULE_NAME "bus_managers/acpi/driver_v1"
// name of the ACPI namespace device
#define ACPI_NS_DUMP_MODULE_NAME "drivers/power/namespace/acpi/device/v1"
#define ACPI_NS_DUMP_DEVICE_MODULE_NAME "bus_managers/acpi/namespace/device_v1"
extern device_manager_info *gDeviceManager;
@@ -28,7 +28,7 @@ extern device_manager_info *gDeviceManager;
// ACPI root.
typedef struct acpi_root_info {
bus_module_info info;
driver_module_info info;
/* Fixed Event Management */
@@ -61,7 +61,7 @@ typedef struct acpi_root_info {
extern struct acpi_module_info acpi_module;
extern pnp_devfs_driver_info acpi_ns_dump_module;
extern struct device_module_info acpi_ns_dump_module;
extern acpi_device_module_info gACPIDeviceModule;