2 * Copyright 2009, Clemens Zeidler. All rights reserved.
3 * Copyright 2006, Jérôme Duval. All rights reserved.
5 * Distributed under the terms of the MIT License.
13 #include "ACPIPrivate.h"
21 //#define TRACE_ACPI_MODULE
22 #ifdef TRACE_ACPI_MODULE
23 # define TRACE(x) dprintf x
29 device_manager_info
* gDeviceManager
= NULL
;
30 pci_module_info
* gPCIManager
= NULL
;
31 dpc_module_info
* gDPC
= NULL
;
33 module_dependency module_dependencies
[] = {
34 {B_DEVICE_MANAGER_MODULE_NAME
, (module_info
**)&gDeviceManager
},
35 {B_PCI_MODULE_NAME
, (module_info
**)&gPCIManager
},
36 {B_DPC_MODULE_NAME
, (module_info
**)&gDPC
},
42 acpi_module_supports_device(device_node
* parent
)
44 // make sure parent is really device root
46 if (gDeviceManager
->get_attr_string(parent
, B_DEVICE_BUS
, &bus
, false))
49 if (strcmp(bus
, "root"))
57 acpi_module_register_device(device_node
* parent
)
59 device_attr attrs
[] = {
60 { B_DEVICE_PRETTY_NAME
, B_STRING_TYPE
, { string
: "ACPI" }},
62 { B_DEVICE_FLAGS
, B_UINT32_TYPE
, { ui32
: B_KEEP_DRIVER_LOADED
}},
66 return gDeviceManager
->register_node(parent
, ACPI_ROOT_MODULE_NAME
, attrs
,
72 acpi_enumerate_child_devices(device_node
* node
, const char* root
)
77 TRACE(("acpi_enumerate_child_devices: recursing from %s\n", root
));
79 while (get_next_entry(ACPI_TYPE_ANY
, root
, result
,
80 sizeof(result
), &counter
) == B_OK
) {
81 uint32 type
= get_object_type(result
);
82 device_node
* deviceNode
;
86 case ACPI_TYPE_PROCESSOR
:
87 case ACPI_TYPE_THERMAL
:
88 case ACPI_TYPE_DEVICE
: {
90 device_attr attrs
[] = {
92 { B_DEVICE_BUS
, B_STRING_TYPE
, { string
: "acpi" }},
94 // location on ACPI bus
95 { ACPI_DEVICE_PATH_ITEM
, B_STRING_TYPE
, { string
: result
}},
97 // info about the device
98 { ACPI_DEVICE_HID_ITEM
, B_STRING_TYPE
, { string
: hid
}},
99 { ACPI_DEVICE_TYPE_ITEM
, B_UINT32_TYPE
, { ui32
: type
}},
101 // consumer specification
102 /*{ B_DRIVER_MAPPING, B_STRING_TYPE, { string:
103 "hid_%" ACPI_DEVICE_HID_ITEM "%" }},
104 { B_DRIVER_MAPPING "/0", B_STRING_TYPE, { string:
105 "type_%" ACPI_DEVICE_TYPE_ITEM "%" }},*/
106 { B_DEVICE_FLAGS
, B_UINT32_TYPE
, { ui32
: /*B_FIND_CHILD_ON_DEMAND|*/B_FIND_MULTIPLE_CHILDREN
}},
110 if (type
== ACPI_TYPE_DEVICE
)
111 get_device_hid(result
, hid
, sizeof(hid
));
113 if (gDeviceManager
->register_node(node
, ACPI_DEVICE_MODULE_NAME
, attrs
,
114 NULL
, &deviceNode
) == B_OK
)
115 acpi_enumerate_child_devices(deviceNode
, result
);
119 acpi_enumerate_child_devices(node
, result
);
130 acpi_module_register_child_devices(void* cookie
)
132 device_node
* node
= (device_node
*)cookie
;
134 status_t status
= gDeviceManager
->publish_device(node
, "acpi/namespace",
135 ACPI_NS_DUMP_DEVICE_MODULE_NAME
);
139 if ((AcpiGbl_FADT
.Flags
& ACPI_FADT_POWER_BUTTON
) == 0) {
140 dprintf("registering power button\n");
141 device_attr attrs
[] = {
143 { B_DEVICE_BUS
, B_STRING_TYPE
, { string
: "acpi" }},
145 // info about the device
146 { ACPI_DEVICE_HID_ITEM
, B_STRING_TYPE
, { string
: "ACPI_FPB" }},
147 { ACPI_DEVICE_TYPE_ITEM
, B_UINT32_TYPE
, { ui32
: ACPI_TYPE_DEVICE
}},
149 // consumer specification
150 { B_DEVICE_FLAGS
, B_UINT32_TYPE
, { ui32
: B_FIND_MULTIPLE_CHILDREN
}},
153 device_node
* deviceNode
;
154 gDeviceManager
->register_node(node
, ACPI_DEVICE_MODULE_NAME
, attrs
,
157 if ((AcpiGbl_FADT
.Flags
& ACPI_FADT_SLEEP_BUTTON
) == 0) {
158 dprintf("registering sleep button\n");
159 device_attr attrs
[] = {
161 { B_DEVICE_BUS
, B_STRING_TYPE
, { string
: "acpi" }},
163 // info about the device
164 { ACPI_DEVICE_HID_ITEM
, B_STRING_TYPE
, { string
: "ACPI_FSB" }},
165 { ACPI_DEVICE_TYPE_ITEM
, B_UINT32_TYPE
, { ui32
: ACPI_TYPE_DEVICE
}},
167 // consumer specification
168 { B_DEVICE_FLAGS
, B_UINT32_TYPE
, { ui32
: B_FIND_MULTIPLE_CHILDREN
}},
171 device_node
* deviceNode
;
172 gDeviceManager
->register_node(node
, ACPI_DEVICE_MODULE_NAME
, attrs
,
177 return acpi_enumerate_child_devices(node
, "\\");
182 acpi_module_init(device_node
* node
, void** _cookie
)
190 acpi_module_uninit(void* cookie
)
196 acpi_module_std_ops(int32 op
, ...)
202 return get_module(B_ACPI_MODULE_NAME
, &module
);
203 // this serializes our module initialization
206 case B_MODULE_UNINIT
:
207 return put_module(B_ACPI_MODULE_NAME
);
214 static struct acpi_root_info sACPIRootModule
= {
217 ACPI_ROOT_MODULE_NAME
,
222 acpi_module_supports_device
,
223 acpi_module_register_device
,
226 acpi_module_register_child_devices
,
227 NULL
, // rescan devices
228 NULL
, // device removed
235 install_notify_handler
,
236 remove_notify_handler
,
245 install_address_space_handler
,
246 remove_address_space_handler
,
251 install_fixed_event_handler
,
252 remove_fixed_event_handler
,
260 ns_handle_to_pathname
,
263 get_irq_routing_table
,
264 get_current_resources
,
265 get_possible_resources
,
266 set_current_resources
,
275 module_info
* modules
[] = {
276 (module_info
*)&gACPIModule
,
277 (module_info
*)&sACPIRootModule
,
278 (module_info
*)&acpi_ns_dump_module
,
279 (module_info
*)&gACPIDeviceModule
,
280 (module_info
*)&embedded_controller_driver_module
,
281 (module_info
*)&embedded_controller_device_module
,