2 * scan.c - support for transforming the ACPI namespace into individual objects
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/slab.h>
8 #include <linux/kernel.h>
9 #include <linux/acpi.h>
10 #include <linux/signal.h>
11 #include <linux/kthread.h>
12 #include <linux/dmi.h>
13 #include <linux/nls.h>
15 #include <acpi/acpi_drivers.h>
19 #define _COMPONENT ACPI_BUS_COMPONENT
20 ACPI_MODULE_NAME("scan");
21 #define STRUCT_TO_INT(s) (*((int*)&s))
22 extern struct acpi_device *acpi_root;
24 #define ACPI_BUS_CLASS "system_bus"
25 #define ACPI_BUS_HID "LNXSYBUS"
26 #define ACPI_BUS_DEVICE_NAME "System Bus"
28 #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
30 static const char *dummy_hid = "device";
32 static LIST_HEAD(acpi_device_list);
33 static LIST_HEAD(acpi_bus_id_list);
34 static DEFINE_MUTEX(acpi_scan_lock);
35 static LIST_HEAD(acpi_scan_handlers_list);
36 DEFINE_MUTEX(acpi_device_lock);
37 LIST_HEAD(acpi_wakeup_device_list);
39 struct acpi_device_bus_id{
41 unsigned int instance_no;
42 struct list_head node;
45 int acpi_scan_add_handler(struct acpi_scan_handler *handler)
47 if (!handler || !handler->attach)
50 list_add_tail(&handler->list_node, &acpi_scan_handlers_list);
55 * Creates hid/cid(s) string needed for modalias and uevent
56 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
57 * char *modalias: "acpi:IBM0001:ACPI0001"
59 static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
64 struct acpi_hardware_id *id;
66 if (list_empty(&acpi_dev->pnp.ids))
69 len = snprintf(modalias, size, "acpi:");
72 list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
73 count = snprintf(&modalias[len], size, "%s:", id->id);
74 if (count < 0 || count >= size)
85 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
86 struct acpi_device *acpi_dev = to_acpi_device(dev);
89 /* Device has no HID and no CID or string is >1024 */
90 len = create_modalias(acpi_dev, buf, 1024);
96 static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
99 * acpi_bus_hot_remove_device: hot-remove a device and its children
100 * @context: struct acpi_eject_event pointer (freed in this func)
102 * Hot-remove a device and its children. This function frees up the
103 * memory space passed by arg context, so that the caller may call
104 * this function asynchronously through acpi_os_hotplug_execute().
106 void acpi_bus_hot_remove_device(void *context)
108 struct acpi_eject_event *ej_event = (struct acpi_eject_event *) context;
109 struct acpi_device *device = ej_event->device;
110 acpi_handle handle = device->handle;
112 struct acpi_object_list arg_list;
113 union acpi_object arg;
114 acpi_status status = AE_OK;
115 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */
117 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
118 "Hot-removing device %s...\n", dev_name(&device->dev)));
120 acpi_bus_trim(device);
121 /* Device node has been released. */
124 /* power off device */
125 status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
126 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
127 printk(KERN_WARNING PREFIX
128 "Power-off device failed\n");
130 if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", &temp))) {
132 arg_list.pointer = &arg;
133 arg.type = ACPI_TYPE_INTEGER;
134 arg.integer.value = 0;
135 acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
139 arg_list.pointer = &arg;
140 arg.type = ACPI_TYPE_INTEGER;
141 arg.integer.value = 1;
146 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
147 if (ACPI_FAILURE(status)) {
148 if (status != AE_NOT_FOUND)
149 printk(KERN_WARNING PREFIX
150 "Eject device failed\n");
158 /* Inform firmware the hot-remove operation has completed w/ error */
159 (void) acpi_evaluate_hotplug_ost(handle,
160 ej_event->event, ost_code, NULL);
164 EXPORT_SYMBOL(acpi_bus_hot_remove_device);
166 static ssize_t real_power_state_show(struct device *dev,
167 struct device_attribute *attr, char *buf)
169 struct acpi_device *adev = to_acpi_device(dev);
173 ret = acpi_device_get_power(adev, &state);
177 return sprintf(buf, "%s\n", acpi_power_state_string(state));
180 static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL);
182 static ssize_t power_state_show(struct device *dev,
183 struct device_attribute *attr, char *buf)
185 struct acpi_device *adev = to_acpi_device(dev);
187 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
190 static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
193 acpi_eject_store(struct device *d, struct device_attribute *attr,
194 const char *buf, size_t count)
198 acpi_object_type type = 0;
199 struct acpi_device *acpi_device = to_acpi_device(d);
200 struct acpi_eject_event *ej_event;
202 if ((!count) || (buf[0] != '1')) {
206 if (acpi_device->driver == NULL) {
211 status = acpi_get_type(acpi_device->handle, &type);
212 if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
217 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
223 ej_event->device = acpi_device;
224 if (acpi_device->flags.eject_pending) {
225 /* event originated from ACPI eject notification */
226 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
227 acpi_device->flags.eject_pending = 0;
229 /* event originated from user */
230 ej_event->event = ACPI_OST_EC_OSPM_EJECT;
231 (void) acpi_evaluate_hotplug_ost(acpi_device->handle,
232 ej_event->event, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
235 acpi_os_hotplug_execute(acpi_bus_hot_remove_device, (void *)ej_event);
240 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
243 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
244 struct acpi_device *acpi_dev = to_acpi_device(dev);
246 return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
248 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
250 static ssize_t acpi_device_uid_show(struct device *dev,
251 struct device_attribute *attr, char *buf)
253 struct acpi_device *acpi_dev = to_acpi_device(dev);
255 return sprintf(buf, "%s\n", acpi_dev->pnp.unique_id);
257 static DEVICE_ATTR(uid, 0444, acpi_device_uid_show, NULL);
259 static ssize_t acpi_device_adr_show(struct device *dev,
260 struct device_attribute *attr, char *buf)
262 struct acpi_device *acpi_dev = to_acpi_device(dev);
264 return sprintf(buf, "0x%08x\n",
265 (unsigned int)(acpi_dev->pnp.bus_address));
267 static DEVICE_ATTR(adr, 0444, acpi_device_adr_show, NULL);
270 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
271 struct acpi_device *acpi_dev = to_acpi_device(dev);
272 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
275 result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
279 result = sprintf(buf, "%s\n", (char*)path.pointer);
284 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
286 /* sysfs file that shows description text from the ACPI _STR method */
287 static ssize_t description_show(struct device *dev,
288 struct device_attribute *attr,
290 struct acpi_device *acpi_dev = to_acpi_device(dev);
293 if (acpi_dev->pnp.str_obj == NULL)
297 * The _STR object contains a Unicode identifier for a device.
298 * We need to convert to utf-8 so it can be displayed.
300 result = utf16s_to_utf8s(
301 (wchar_t *)acpi_dev->pnp.str_obj->buffer.pointer,
302 acpi_dev->pnp.str_obj->buffer.length,
303 UTF16_LITTLE_ENDIAN, buf,
306 buf[result++] = '\n';
310 static DEVICE_ATTR(description, 0444, description_show, NULL);
313 acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
315 struct acpi_device *acpi_dev = to_acpi_device(dev);
317 return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
319 static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
321 static int acpi_device_setup_files(struct acpi_device *dev)
323 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
326 unsigned long long sun;
330 * Devices gotten from FADT don't have a "path" attribute
333 result = device_create_file(&dev->dev, &dev_attr_path);
338 if (!list_empty(&dev->pnp.ids)) {
339 result = device_create_file(&dev->dev, &dev_attr_hid);
343 result = device_create_file(&dev->dev, &dev_attr_modalias);
349 * If device has _STR, 'description' file is created
351 status = acpi_get_handle(dev->handle, "_STR", &temp);
352 if (ACPI_SUCCESS(status)) {
353 status = acpi_evaluate_object(dev->handle, "_STR",
355 if (ACPI_FAILURE(status))
356 buffer.pointer = NULL;
357 dev->pnp.str_obj = buffer.pointer;
358 result = device_create_file(&dev->dev, &dev_attr_description);
363 if (dev->flags.bus_address)
364 result = device_create_file(&dev->dev, &dev_attr_adr);
365 if (dev->pnp.unique_id)
366 result = device_create_file(&dev->dev, &dev_attr_uid);
368 status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
369 if (ACPI_SUCCESS(status)) {
370 dev->pnp.sun = (unsigned long)sun;
371 result = device_create_file(&dev->dev, &dev_attr_sun);
375 dev->pnp.sun = (unsigned long)-1;
379 * If device has _EJ0, 'eject' file is created that is used to trigger
380 * hot-removal function from userland.
382 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
383 if (ACPI_SUCCESS(status)) {
384 result = device_create_file(&dev->dev, &dev_attr_eject);
389 if (dev->flags.power_manageable) {
390 result = device_create_file(&dev->dev, &dev_attr_power_state);
394 if (dev->power.flags.power_resources)
395 result = device_create_file(&dev->dev,
396 &dev_attr_real_power_state);
403 static void acpi_device_remove_files(struct acpi_device *dev)
408 if (dev->flags.power_manageable) {
409 device_remove_file(&dev->dev, &dev_attr_power_state);
410 if (dev->power.flags.power_resources)
411 device_remove_file(&dev->dev,
412 &dev_attr_real_power_state);
416 * If device has _STR, remove 'description' file
418 status = acpi_get_handle(dev->handle, "_STR", &temp);
419 if (ACPI_SUCCESS(status)) {
420 kfree(dev->pnp.str_obj);
421 device_remove_file(&dev->dev, &dev_attr_description);
424 * If device has _EJ0, remove 'eject' file.
426 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
427 if (ACPI_SUCCESS(status))
428 device_remove_file(&dev->dev, &dev_attr_eject);
430 status = acpi_get_handle(dev->handle, "_SUN", &temp);
431 if (ACPI_SUCCESS(status))
432 device_remove_file(&dev->dev, &dev_attr_sun);
434 if (dev->pnp.unique_id)
435 device_remove_file(&dev->dev, &dev_attr_uid);
436 if (dev->flags.bus_address)
437 device_remove_file(&dev->dev, &dev_attr_adr);
438 device_remove_file(&dev->dev, &dev_attr_modalias);
439 device_remove_file(&dev->dev, &dev_attr_hid);
441 device_remove_file(&dev->dev, &dev_attr_path);
443 /* --------------------------------------------------------------------------
445 -------------------------------------------------------------------------- */
447 static const struct acpi_device_id *__acpi_match_device(
448 struct acpi_device *device, const struct acpi_device_id *ids)
450 const struct acpi_device_id *id;
451 struct acpi_hardware_id *hwid;
454 * If the device is not present, it is unnecessary to load device
457 if (!device->status.present)
460 for (id = ids; id->id[0]; id++)
461 list_for_each_entry(hwid, &device->pnp.ids, list)
462 if (!strcmp((char *) id->id, hwid->id))
469 * acpi_match_device - Match a struct device against a given list of ACPI IDs
470 * @ids: Array of struct acpi_device_id object to match against.
471 * @dev: The device structure to match.
473 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
474 * object for that handle and use that object to match against a given list of
477 * Return a pointer to the first matching ID on success or %NULL on failure.
479 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
480 const struct device *dev)
482 struct acpi_device *adev;
484 if (!ids || !ACPI_HANDLE(dev)
485 || ACPI_FAILURE(acpi_bus_get_device(ACPI_HANDLE(dev), &adev)))
488 return __acpi_match_device(adev, ids);
490 EXPORT_SYMBOL_GPL(acpi_match_device);
492 int acpi_match_device_ids(struct acpi_device *device,
493 const struct acpi_device_id *ids)
495 return __acpi_match_device(device, ids) ? 0 : -ENOENT;
497 EXPORT_SYMBOL(acpi_match_device_ids);
499 void acpi_free_ids(struct acpi_device *device)
501 struct acpi_hardware_id *id, *tmp;
503 list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) {
507 kfree(device->pnp.unique_id);
510 static void acpi_free_power_resources_lists(struct acpi_device *device)
514 if (device->wakeup.flags.valid)
515 acpi_power_resources_list_free(&device->wakeup.resources);
517 if (!device->flags.power_manageable)
520 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
521 struct acpi_device_power_state *ps = &device->power.states[i];
522 acpi_power_resources_list_free(&ps->resources);
526 static void acpi_device_release(struct device *dev)
528 struct acpi_device *acpi_dev = to_acpi_device(dev);
530 acpi_free_ids(acpi_dev);
531 acpi_free_power_resources_lists(acpi_dev);
535 static int acpi_bus_match(struct device *dev, struct device_driver *drv)
537 struct acpi_device *acpi_dev = to_acpi_device(dev);
538 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
540 return acpi_dev->flags.match_driver
541 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
544 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
546 struct acpi_device *acpi_dev = to_acpi_device(dev);
549 if (list_empty(&acpi_dev->pnp.ids))
552 if (add_uevent_var(env, "MODALIAS="))
554 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
555 sizeof(env->buf) - env->buflen);
556 if (len >= (sizeof(env->buf) - env->buflen))
562 static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
564 struct acpi_device *device = data;
566 device->driver->ops.notify(device, event);
569 static acpi_status acpi_device_notify_fixed(void *data)
571 struct acpi_device *device = data;
573 /* Fixed hardware devices have no handles */
574 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
578 static int acpi_device_install_notify_handler(struct acpi_device *device)
582 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
584 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
585 acpi_device_notify_fixed,
587 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
589 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
590 acpi_device_notify_fixed,
593 status = acpi_install_notify_handler(device->handle,
598 if (ACPI_FAILURE(status))
603 static void acpi_device_remove_notify_handler(struct acpi_device *device)
605 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
606 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
607 acpi_device_notify_fixed);
608 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
609 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
610 acpi_device_notify_fixed);
612 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
616 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
617 static int acpi_device_probe(struct device * dev)
619 struct acpi_device *acpi_dev = to_acpi_device(dev);
620 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
623 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
625 if (acpi_drv->ops.notify) {
626 ret = acpi_device_install_notify_handler(acpi_dev);
628 if (acpi_drv->ops.remove)
629 acpi_drv->ops.remove(acpi_dev);
634 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
635 "Found driver [%s] for device [%s]\n",
636 acpi_drv->name, acpi_dev->pnp.bus_id));
642 static int acpi_device_remove(struct device * dev)
644 struct acpi_device *acpi_dev = to_acpi_device(dev);
645 struct acpi_driver *acpi_drv = acpi_dev->driver;
648 if (acpi_drv->ops.notify)
649 acpi_device_remove_notify_handler(acpi_dev);
650 if (acpi_drv->ops.remove)
651 acpi_drv->ops.remove(acpi_dev);
653 acpi_dev->driver = NULL;
654 acpi_dev->driver_data = NULL;
660 struct bus_type acpi_bus_type = {
662 .match = acpi_bus_match,
663 .probe = acpi_device_probe,
664 .remove = acpi_device_remove,
665 .uevent = acpi_device_uevent,
668 int acpi_device_add(struct acpi_device *device,
669 void (*release)(struct device *))
672 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
675 if (device->handle) {
678 status = acpi_attach_data(device->handle, acpi_bus_data_handler,
680 if (ACPI_FAILURE(status)) {
681 acpi_handle_err(device->handle,
682 "Unable to attach device data\n");
690 * Link this device to its parent and siblings.
692 INIT_LIST_HEAD(&device->children);
693 INIT_LIST_HEAD(&device->node);
694 INIT_LIST_HEAD(&device->wakeup_list);
695 INIT_LIST_HEAD(&device->physical_node_list);
696 mutex_init(&device->physical_node_lock);
697 INIT_LIST_HEAD(&device->power_dependent);
699 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
701 pr_err(PREFIX "Memory allocation error\n");
706 mutex_lock(&acpi_device_lock);
708 * Find suitable bus_id and instance number in acpi_bus_id_list
709 * If failed, create one and link it into acpi_bus_id_list
711 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
712 if (!strcmp(acpi_device_bus_id->bus_id,
713 acpi_device_hid(device))) {
714 acpi_device_bus_id->instance_no++;
721 acpi_device_bus_id = new_bus_id;
722 strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
723 acpi_device_bus_id->instance_no = 0;
724 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
726 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
729 list_add_tail(&device->node, &device->parent->children);
731 if (device->wakeup.flags.valid)
732 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
733 mutex_unlock(&acpi_device_lock);
736 device->dev.parent = &device->parent->dev;
737 device->dev.bus = &acpi_bus_type;
738 device->dev.release = release;
739 result = device_add(&device->dev);
741 dev_err(&device->dev, "Error registering device\n");
745 result = acpi_device_setup_files(device);
747 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
748 dev_name(&device->dev));
750 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
754 mutex_lock(&acpi_device_lock);
756 list_del(&device->node);
757 list_del(&device->wakeup_list);
758 mutex_unlock(&acpi_device_lock);
761 acpi_detach_data(device->handle, acpi_bus_data_handler);
765 static void acpi_device_unregister(struct acpi_device *device)
767 mutex_lock(&acpi_device_lock);
769 list_del(&device->node);
771 list_del(&device->wakeup_list);
772 mutex_unlock(&acpi_device_lock);
774 acpi_detach_data(device->handle, acpi_bus_data_handler);
776 acpi_power_add_remove_device(device, false);
777 acpi_device_remove_files(device);
779 device->remove(device);
781 device_del(&device->dev);
783 * Drop the reference counts of all power resources the device depends
784 * on and turn off the ones that have no more references.
786 acpi_power_transition(device, ACPI_STATE_D3_COLD);
787 put_device(&device->dev);
790 /* --------------------------------------------------------------------------
792 -------------------------------------------------------------------------- */
794 * acpi_bus_driver_init - add a device to a driver
795 * @device: the device to add and initialize
796 * @driver: driver for the device
798 * Used to initialize a device via its device driver. Called whenever a
799 * driver is bound to a device. Invokes the driver's add() ops.
802 acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
806 if (!device || !driver)
809 if (!driver->ops.add)
812 result = driver->ops.add(device);
814 device->driver = NULL;
815 device->driver_data = NULL;
819 device->driver = driver;
822 * TBD - Configuration Management: Assign resources to device based
823 * upon possible configuration and currently allocated resources.
826 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
827 "Driver successfully bound to device\n"));
832 * acpi_bus_register_driver - register a driver with the ACPI bus
833 * @driver: driver being registered
835 * Registers a driver with the ACPI bus. Searches the namespace for all
836 * devices that match the driver's criteria and binds. Returns zero for
837 * success or a negative error status for failure.
839 int acpi_bus_register_driver(struct acpi_driver *driver)
845 driver->drv.name = driver->name;
846 driver->drv.bus = &acpi_bus_type;
847 driver->drv.owner = driver->owner;
849 ret = driver_register(&driver->drv);
853 EXPORT_SYMBOL(acpi_bus_register_driver);
856 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
857 * @driver: driver to unregister
859 * Unregisters a driver with the ACPI bus. Searches the namespace for all
860 * devices that match the driver's criteria and unbinds.
862 void acpi_bus_unregister_driver(struct acpi_driver *driver)
864 driver_unregister(&driver->drv);
867 EXPORT_SYMBOL(acpi_bus_unregister_driver);
869 /* --------------------------------------------------------------------------
871 -------------------------------------------------------------------------- */
872 static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
874 struct acpi_device *device = NULL;
878 * Fixed hardware devices do not appear in the namespace and do not
879 * have handles, but we fabricate acpi_devices for them, so we have
880 * to deal with them specially.
886 status = acpi_get_parent(handle, &handle);
887 if (ACPI_FAILURE(status))
888 return status == AE_NULL_ENTRY ? NULL : acpi_root;
889 } while (acpi_bus_get_device(handle, &device));
894 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
898 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
899 union acpi_object *obj;
901 status = acpi_get_handle(handle, "_EJD", &tmp);
902 if (ACPI_FAILURE(status))
905 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
906 if (ACPI_SUCCESS(status)) {
907 obj = buffer.pointer;
908 status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
910 kfree(buffer.pointer);
914 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
916 void acpi_bus_data_handler(acpi_handle handle, void *context)
924 static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
925 struct acpi_device_wakeup *wakeup)
927 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
928 union acpi_object *package = NULL;
929 union acpi_object *element = NULL;
936 INIT_LIST_HEAD(&wakeup->resources);
939 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
940 if (ACPI_FAILURE(status)) {
941 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
945 package = (union acpi_object *)buffer.pointer;
947 if (!package || package->package.count < 2)
950 element = &(package->package.elements[0]);
954 if (element->type == ACPI_TYPE_PACKAGE) {
955 if ((element->package.count < 2) ||
956 (element->package.elements[0].type !=
957 ACPI_TYPE_LOCAL_REFERENCE)
958 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
962 element->package.elements[0].reference.handle;
964 (u32) element->package.elements[1].integer.value;
965 } else if (element->type == ACPI_TYPE_INTEGER) {
966 wakeup->gpe_device = NULL;
967 wakeup->gpe_number = element->integer.value;
972 element = &(package->package.elements[1]);
973 if (element->type != ACPI_TYPE_INTEGER)
976 wakeup->sleep_state = element->integer.value;
978 err = acpi_extract_power_resources(package, 2, &wakeup->resources);
982 if (!list_empty(&wakeup->resources)) {
985 sleep_state = acpi_power_min_system_level(&wakeup->resources);
986 if (sleep_state < wakeup->sleep_state) {
987 acpi_handle_warn(handle, "Overriding _PRW sleep state "
988 "(S%d) by S%d from power resources\n",
989 (int)wakeup->sleep_state, sleep_state);
990 wakeup->sleep_state = sleep_state;
993 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
996 kfree(buffer.pointer);
1000 static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
1002 struct acpi_device_id button_device_ids[] = {
1009 acpi_event_status event_status;
1011 device->wakeup.flags.notifier_present = 0;
1013 /* Power button, Lid switch always enable wakeup */
1014 if (!acpi_match_device_ids(device, button_device_ids)) {
1015 device->wakeup.flags.run_wake = 1;
1016 if (!acpi_match_device_ids(device, &button_device_ids[1])) {
1017 /* Do not use Lid/sleep button for S5 wakeup */
1018 if (device->wakeup.sleep_state == ACPI_STATE_S5)
1019 device->wakeup.sleep_state = ACPI_STATE_S4;
1021 device_set_wakeup_capable(&device->dev, true);
1025 status = acpi_get_gpe_status(device->wakeup.gpe_device,
1026 device->wakeup.gpe_number,
1028 if (status == AE_OK)
1029 device->wakeup.flags.run_wake =
1030 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
1033 static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
1036 acpi_status status = 0;
1039 /* Presence of _PRW indicates wake capable */
1040 status = acpi_get_handle(device->handle, "_PRW", &temp);
1041 if (ACPI_FAILURE(status))
1044 err = acpi_bus_extract_wakeup_device_power_package(device->handle,
1047 dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
1051 device->wakeup.flags.valid = 1;
1052 device->wakeup.prepare_count = 0;
1053 acpi_bus_set_run_wake_flags(device);
1054 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
1055 * system for the ACPI device with the _PRW object.
1056 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
1057 * So it is necessary to call _DSW object first. Only when it is not
1058 * present will the _PSW object used.
1060 err = acpi_device_sleep_wake(device, 0, 0, 0);
1062 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1063 "error in _DSW or _PSW evaluation\n"));
1066 static void acpi_bus_init_power_state(struct acpi_device *device, int state)
1068 struct acpi_device_power_state *ps = &device->power.states[state];
1069 char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
1070 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1074 INIT_LIST_HEAD(&ps->resources);
1076 /* Evaluate "_PRx" to get referenced power resources */
1077 status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
1078 if (ACPI_SUCCESS(status)) {
1079 union acpi_object *package = buffer.pointer;
1081 if (buffer.length && package
1082 && package->type == ACPI_TYPE_PACKAGE
1083 && package->package.count) {
1084 int err = acpi_extract_power_resources(package, 0,
1087 device->power.flags.power_resources = 1;
1089 ACPI_FREE(buffer.pointer);
1092 /* Evaluate "_PSx" to see if we can do explicit sets */
1094 status = acpi_get_handle(device->handle, pathname, &handle);
1095 if (ACPI_SUCCESS(status))
1096 ps->flags.explicit_set = 1;
1099 * State is valid if there are means to put the device into it.
1100 * D3hot is only valid if _PR3 present.
1102 if (!list_empty(&ps->resources)
1103 || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) {
1104 ps->flags.valid = 1;
1105 ps->flags.os_accessible = 1;
1108 ps->power = -1; /* Unknown - driver assigned */
1109 ps->latency = -1; /* Unknown - driver assigned */
1112 static void acpi_bus_get_power_flags(struct acpi_device *device)
1118 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1119 status = acpi_get_handle(device->handle, "_PS0", &handle);
1120 if (ACPI_FAILURE(status)) {
1121 status = acpi_get_handle(device->handle, "_PR0", &handle);
1122 if (ACPI_FAILURE(status))
1126 device->flags.power_manageable = 1;
1129 * Power Management Flags
1131 status = acpi_get_handle(device->handle, "_PSC", &handle);
1132 if (ACPI_SUCCESS(status))
1133 device->power.flags.explicit_get = 1;
1134 status = acpi_get_handle(device->handle, "_IRC", &handle);
1135 if (ACPI_SUCCESS(status))
1136 device->power.flags.inrush_current = 1;
1139 * Enumerate supported power management states
1141 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
1142 acpi_bus_init_power_state(device, i);
1144 INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
1146 /* Set defaults for D0 and D3 states (always valid) */
1147 device->power.states[ACPI_STATE_D0].flags.valid = 1;
1148 device->power.states[ACPI_STATE_D0].power = 100;
1149 device->power.states[ACPI_STATE_D3].flags.valid = 1;
1150 device->power.states[ACPI_STATE_D3].power = 0;
1152 /* Set D3cold's explicit_set flag if _PS3 exists. */
1153 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set)
1154 device->power.states[ACPI_STATE_D3_COLD].flags.explicit_set = 1;
1156 /* Presence of _PS3 or _PRx means we can put the device into D3 cold */
1157 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set ||
1158 device->power.flags.power_resources)
1159 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1;
1161 acpi_bus_init_power(device);
1164 static void acpi_bus_get_flags(struct acpi_device *device)
1166 acpi_status status = AE_OK;
1167 acpi_handle temp = NULL;
1169 /* Presence of _STA indicates 'dynamic_status' */
1170 status = acpi_get_handle(device->handle, "_STA", &temp);
1171 if (ACPI_SUCCESS(status))
1172 device->flags.dynamic_status = 1;
1174 /* Presence of _RMV indicates 'removable' */
1175 status = acpi_get_handle(device->handle, "_RMV", &temp);
1176 if (ACPI_SUCCESS(status))
1177 device->flags.removable = 1;
1179 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
1180 status = acpi_get_handle(device->handle, "_EJD", &temp);
1181 if (ACPI_SUCCESS(status))
1182 device->flags.ejectable = 1;
1184 status = acpi_get_handle(device->handle, "_EJ0", &temp);
1185 if (ACPI_SUCCESS(status))
1186 device->flags.ejectable = 1;
1190 static void acpi_device_get_busid(struct acpi_device *device)
1192 char bus_id[5] = { '?', 0 };
1193 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
1199 * The device's Bus ID is simply the object name.
1200 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
1202 if (ACPI_IS_ROOT_DEVICE(device)) {
1203 strcpy(device->pnp.bus_id, "ACPI");
1207 switch (device->device_type) {
1208 case ACPI_BUS_TYPE_POWER_BUTTON:
1209 strcpy(device->pnp.bus_id, "PWRF");
1211 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1212 strcpy(device->pnp.bus_id, "SLPF");
1215 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
1216 /* Clean up trailing underscores (if any) */
1217 for (i = 3; i > 1; i--) {
1218 if (bus_id[i] == '_')
1223 strcpy(device->pnp.bus_id, bus_id);
1229 * acpi_bay_match - see if a device is an ejectable driver bay
1231 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
1232 * then we can safely call it an ejectable drive bay
1234 static int acpi_bay_match(struct acpi_device *device){
1238 acpi_handle phandle;
1240 handle = device->handle;
1242 status = acpi_get_handle(handle, "_EJ0", &tmp);
1243 if (ACPI_FAILURE(status))
1246 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
1247 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
1248 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
1249 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
1252 if (acpi_get_parent(handle, &phandle))
1255 if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
1256 (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
1257 (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
1258 (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
1265 * acpi_dock_match - see if a device has a _DCK method
1267 static int acpi_dock_match(struct acpi_device *device)
1270 return acpi_get_handle(device->handle, "_DCK", &tmp);
1273 const char *acpi_device_hid(struct acpi_device *device)
1275 struct acpi_hardware_id *hid;
1277 if (list_empty(&device->pnp.ids))
1280 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1283 EXPORT_SYMBOL(acpi_device_hid);
1285 static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1287 struct acpi_hardware_id *id;
1289 id = kmalloc(sizeof(*id), GFP_KERNEL);
1293 id->id = kstrdup(dev_id, GFP_KERNEL);
1299 list_add_tail(&id->list, &device->pnp.ids);
1303 * Old IBM workstations have a DSDT bug wherein the SMBus object
1304 * lacks the SMBUS01 HID and the methods do not have the necessary "_"
1305 * prefix. Work around this.
1307 static int acpi_ibm_smbus_match(struct acpi_device *device)
1309 acpi_handle h_dummy;
1310 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
1313 if (!dmi_name_in_vendors("IBM"))
1316 /* Look for SMBS object */
1317 result = acpi_get_name(device->handle, ACPI_SINGLE_NAME, &path);
1321 if (strcmp("SMBS", path.pointer)) {
1326 /* Does it have the necessary (but misnamed) methods? */
1328 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "SBI", &h_dummy)) &&
1329 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBR", &h_dummy)) &&
1330 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBW", &h_dummy)))
1333 kfree(path.pointer);
1337 static void acpi_device_set_id(struct acpi_device *device)
1340 struct acpi_device_info *info;
1341 struct acpi_pnp_device_id_list *cid_list;
1344 switch (device->device_type) {
1345 case ACPI_BUS_TYPE_DEVICE:
1346 if (ACPI_IS_ROOT_DEVICE(device)) {
1347 acpi_add_id(device, ACPI_SYSTEM_HID);
1351 status = acpi_get_object_info(device->handle, &info);
1352 if (ACPI_FAILURE(status)) {
1353 printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__);
1357 if (info->valid & ACPI_VALID_HID)
1358 acpi_add_id(device, info->hardware_id.string);
1359 if (info->valid & ACPI_VALID_CID) {
1360 cid_list = &info->compatible_id_list;
1361 for (i = 0; i < cid_list->count; i++)
1362 acpi_add_id(device, cid_list->ids[i].string);
1364 if (info->valid & ACPI_VALID_ADR) {
1365 device->pnp.bus_address = info->address;
1366 device->flags.bus_address = 1;
1368 if (info->valid & ACPI_VALID_UID)
1369 device->pnp.unique_id = kstrdup(info->unique_id.string,
1375 * Some devices don't reliably have _HIDs & _CIDs, so add
1376 * synthetic HIDs to make sure drivers can find them.
1378 if (acpi_is_video_device(device))
1379 acpi_add_id(device, ACPI_VIDEO_HID);
1380 else if (ACPI_SUCCESS(acpi_bay_match(device)))
1381 acpi_add_id(device, ACPI_BAY_HID);
1382 else if (ACPI_SUCCESS(acpi_dock_match(device)))
1383 acpi_add_id(device, ACPI_DOCK_HID);
1384 else if (!acpi_ibm_smbus_match(device))
1385 acpi_add_id(device, ACPI_SMBUS_IBM_HID);
1386 else if (list_empty(&device->pnp.ids) &&
1387 ACPI_IS_ROOT_DEVICE(device->parent)) {
1388 acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
1389 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1390 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1394 case ACPI_BUS_TYPE_POWER:
1395 acpi_add_id(device, ACPI_POWER_HID);
1397 case ACPI_BUS_TYPE_PROCESSOR:
1398 acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
1400 case ACPI_BUS_TYPE_THERMAL:
1401 acpi_add_id(device, ACPI_THERMAL_HID);
1403 case ACPI_BUS_TYPE_POWER_BUTTON:
1404 acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
1406 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1407 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
1412 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1413 int type, unsigned long long sta)
1415 INIT_LIST_HEAD(&device->pnp.ids);
1416 device->device_type = type;
1417 device->handle = handle;
1418 device->parent = acpi_bus_get_parent(handle);
1419 STRUCT_TO_INT(device->status) = sta;
1420 acpi_device_get_busid(device);
1421 acpi_device_set_id(device);
1422 acpi_bus_get_flags(device);
1423 device->flags.match_driver = false;
1424 device_initialize(&device->dev);
1425 dev_set_uevent_suppress(&device->dev, true);
1428 void acpi_device_add_finalize(struct acpi_device *device)
1430 device->flags.match_driver = true;
1431 dev_set_uevent_suppress(&device->dev, false);
1432 kobject_uevent(&device->dev.kobj, KOBJ_ADD);
1435 static int acpi_add_single_object(struct acpi_device **child,
1436 acpi_handle handle, int type,
1437 unsigned long long sta)
1440 struct acpi_device *device;
1441 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1443 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1445 printk(KERN_ERR PREFIX "Memory allocation error\n");
1449 acpi_init_device_object(device, handle, type, sta);
1450 acpi_bus_get_power_flags(device);
1451 acpi_bus_get_wakeup_device_flags(device);
1453 result = acpi_device_add(device, acpi_device_release);
1455 acpi_device_release(&device->dev);
1459 acpi_power_add_remove_device(device, true);
1460 acpi_device_add_finalize(device);
1461 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1462 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
1463 dev_name(&device->dev), (char *) buffer.pointer,
1464 device->parent ? dev_name(&device->parent->dev) : "(null)"));
1465 kfree(buffer.pointer);
1470 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1471 unsigned long long *sta)
1474 acpi_object_type acpi_type;
1476 status = acpi_get_type(handle, &acpi_type);
1477 if (ACPI_FAILURE(status))
1480 switch (acpi_type) {
1481 case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
1482 case ACPI_TYPE_DEVICE:
1483 *type = ACPI_BUS_TYPE_DEVICE;
1484 status = acpi_bus_get_status_handle(handle, sta);
1485 if (ACPI_FAILURE(status))
1488 case ACPI_TYPE_PROCESSOR:
1489 *type = ACPI_BUS_TYPE_PROCESSOR;
1490 status = acpi_bus_get_status_handle(handle, sta);
1491 if (ACPI_FAILURE(status))
1494 case ACPI_TYPE_THERMAL:
1495 *type = ACPI_BUS_TYPE_THERMAL;
1496 *sta = ACPI_STA_DEFAULT;
1498 case ACPI_TYPE_POWER:
1499 *type = ACPI_BUS_TYPE_POWER;
1500 *sta = ACPI_STA_DEFAULT;
1509 static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
1510 void *not_used, void **return_value)
1512 struct acpi_device *device = NULL;
1514 unsigned long long sta;
1518 acpi_bus_get_device(handle, &device);
1522 result = acpi_bus_type_and_status(handle, &type, &sta);
1526 if (type == ACPI_BUS_TYPE_POWER) {
1527 acpi_add_power_resource(handle);
1531 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1532 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
1533 struct acpi_device_wakeup wakeup;
1536 status = acpi_get_handle(handle, "_PRW", &temp);
1537 if (ACPI_SUCCESS(status)) {
1538 acpi_bus_extract_wakeup_device_power_package(handle,
1540 acpi_power_resources_list_free(&wakeup.resources);
1542 return AE_CTRL_DEPTH;
1545 acpi_add_single_object(&device, handle, type, sta);
1547 return AE_CTRL_DEPTH;
1551 *return_value = device;
1556 static int acpi_scan_attach_handler(struct acpi_device *device)
1558 struct acpi_scan_handler *handler;
1561 list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) {
1562 const struct acpi_device_id *id;
1564 id = __acpi_match_device(device, handler->ids);
1568 ret = handler->attach(device, id);
1570 device->handler = handler;
1572 } else if (ret < 0) {
1579 static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
1580 void *not_used, void **ret_not_used)
1582 struct acpi_device *device;
1583 unsigned long long sta_not_used;
1587 * Ignore errors ignored by acpi_bus_check_add() to avoid terminating
1588 * namespace walks prematurely.
1590 if (acpi_bus_type_and_status(handle, &ret, &sta_not_used))
1593 if (acpi_bus_get_device(handle, &device))
1594 return AE_CTRL_DEPTH;
1596 ret = acpi_scan_attach_handler(device);
1598 return ret > 0 ? AE_OK : AE_CTRL_DEPTH;
1600 ret = device_attach(&device->dev);
1601 return ret >= 0 ? AE_OK : AE_CTRL_DEPTH;
1605 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
1606 * @handle: Root of the namespace scope to scan.
1608 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
1611 * If no devices were found, -ENODEV is returned, but it does not mean that
1612 * there has been a real error. There just have been no suitable ACPI objects
1613 * in the table trunk from which the kernel could create a device and add an
1614 * appropriate driver.
1616 int acpi_bus_scan(acpi_handle handle)
1618 void *device = NULL;
1621 mutex_lock(&acpi_scan_lock);
1623 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
1624 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1625 acpi_bus_check_add, NULL, NULL, &device);
1629 else if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL)))
1630 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1631 acpi_bus_device_attach, NULL, NULL, NULL);
1633 mutex_unlock(&acpi_scan_lock);
1636 EXPORT_SYMBOL(acpi_bus_scan);
1638 static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,
1639 void *not_used, void **ret_not_used)
1641 struct acpi_device *device = NULL;
1643 if (!acpi_bus_get_device(handle, &device)) {
1644 struct acpi_scan_handler *dev_handler = device->handler;
1646 device->removal_type = ACPI_BUS_REMOVAL_EJECT;
1648 if (dev_handler->detach)
1649 dev_handler->detach(device);
1651 device->handler = NULL;
1653 device_release_driver(&device->dev);
1659 static acpi_status acpi_bus_remove(acpi_handle handle, u32 lvl_not_used,
1660 void *not_used, void **ret_not_used)
1662 struct acpi_device *device = NULL;
1664 if (!acpi_bus_get_device(handle, &device))
1665 acpi_device_unregister(device);
1670 void acpi_bus_trim(struct acpi_device *start)
1672 mutex_lock(&acpi_scan_lock);
1675 * Execute acpi_bus_device_detach() as a post-order callback to detach
1676 * all ACPI drivers from the device nodes being removed.
1678 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1679 acpi_bus_device_detach, NULL, NULL);
1680 acpi_bus_device_detach(start->handle, 0, NULL, NULL);
1682 * Execute acpi_bus_remove() as a post-order callback to remove device
1683 * nodes in the given namespace scope.
1685 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1686 acpi_bus_remove, NULL, NULL);
1687 acpi_bus_remove(start->handle, 0, NULL, NULL);
1689 mutex_unlock(&acpi_scan_lock);
1691 EXPORT_SYMBOL_GPL(acpi_bus_trim);
1693 static int acpi_bus_scan_fixed(void)
1698 * Enumerate all fixed-feature devices.
1700 if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
1701 struct acpi_device *device = NULL;
1703 result = acpi_add_single_object(&device, NULL,
1704 ACPI_BUS_TYPE_POWER_BUTTON,
1709 result = device_attach(&device->dev);
1713 device_init_wakeup(&device->dev, true);
1716 if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
1717 struct acpi_device *device = NULL;
1719 result = acpi_add_single_object(&device, NULL,
1720 ACPI_BUS_TYPE_SLEEP_BUTTON,
1725 result = device_attach(&device->dev);
1728 return result < 0 ? result : 0;
1731 int __init acpi_scan_init(void)
1735 result = bus_register(&acpi_bus_type);
1737 /* We don't want to quit even if we failed to add suspend/resume */
1738 printk(KERN_ERR PREFIX "Could not register bus type\n");
1741 acpi_pci_root_init();
1742 acpi_pci_link_init();
1743 acpi_platform_init();
1747 * Enumerate devices in the ACPI namespace.
1749 result = acpi_bus_scan(ACPI_ROOT_OBJECT);
1753 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
1757 result = acpi_bus_scan_fixed();
1759 acpi_device_unregister(acpi_root);
1763 acpi_update_all_gpes();