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);
98 static void __acpi_bus_trim(struct acpi_device *start);
101 * acpi_bus_hot_remove_device: hot-remove a device and its children
102 * @context: struct acpi_eject_event pointer (freed in this func)
104 * Hot-remove a device and its children. This function frees up the
105 * memory space passed by arg context, so that the caller may call
106 * this function asynchronously through acpi_os_hotplug_execute().
108 void acpi_bus_hot_remove_device(void *context)
110 struct acpi_eject_event *ej_event = (struct acpi_eject_event *) context;
111 struct acpi_device *device = ej_event->device;
112 acpi_handle handle = device->handle;
114 struct acpi_object_list arg_list;
115 union acpi_object arg;
116 acpi_status status = AE_OK;
117 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */
119 mutex_lock(&acpi_scan_lock);
121 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
122 "Hot-removing device %s...\n", dev_name(&device->dev)));
124 __acpi_bus_trim(device);
125 /* Device node has been released. */
128 if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", &temp))) {
130 arg_list.pointer = &arg;
131 arg.type = ACPI_TYPE_INTEGER;
132 arg.integer.value = 0;
133 acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
137 arg_list.pointer = &arg;
138 arg.type = ACPI_TYPE_INTEGER;
139 arg.integer.value = 1;
144 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
145 if (ACPI_FAILURE(status)) {
146 if (status != AE_NOT_FOUND)
147 acpi_handle_warn(handle, "Eject failed\n");
149 /* Tell the firmware the hot-remove operation has failed. */
150 acpi_evaluate_hotplug_ost(handle, ej_event->event,
154 mutex_unlock(&acpi_scan_lock);
158 EXPORT_SYMBOL(acpi_bus_hot_remove_device);
160 static ssize_t real_power_state_show(struct device *dev,
161 struct device_attribute *attr, char *buf)
163 struct acpi_device *adev = to_acpi_device(dev);
167 ret = acpi_device_get_power(adev, &state);
171 return sprintf(buf, "%s\n", acpi_power_state_string(state));
174 static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL);
176 static ssize_t power_state_show(struct device *dev,
177 struct device_attribute *attr, char *buf)
179 struct acpi_device *adev = to_acpi_device(dev);
181 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
184 static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
187 acpi_eject_store(struct device *d, struct device_attribute *attr,
188 const char *buf, size_t count)
192 acpi_object_type type = 0;
193 struct acpi_device *acpi_device = to_acpi_device(d);
194 struct acpi_eject_event *ej_event;
196 if ((!count) || (buf[0] != '1')) {
199 if (!acpi_device->driver && !acpi_device->handler) {
203 status = acpi_get_type(acpi_device->handle, &type);
204 if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
209 ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL);
215 ej_event->device = acpi_device;
216 if (acpi_device->flags.eject_pending) {
217 /* event originated from ACPI eject notification */
218 ej_event->event = ACPI_NOTIFY_EJECT_REQUEST;
219 acpi_device->flags.eject_pending = 0;
221 /* event originated from user */
222 ej_event->event = ACPI_OST_EC_OSPM_EJECT;
223 (void) acpi_evaluate_hotplug_ost(acpi_device->handle,
224 ej_event->event, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
227 acpi_os_hotplug_execute(acpi_bus_hot_remove_device, (void *)ej_event);
232 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
235 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
236 struct acpi_device *acpi_dev = to_acpi_device(dev);
238 return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
240 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
242 static ssize_t acpi_device_uid_show(struct device *dev,
243 struct device_attribute *attr, char *buf)
245 struct acpi_device *acpi_dev = to_acpi_device(dev);
247 return sprintf(buf, "%s\n", acpi_dev->pnp.unique_id);
249 static DEVICE_ATTR(uid, 0444, acpi_device_uid_show, NULL);
251 static ssize_t acpi_device_adr_show(struct device *dev,
252 struct device_attribute *attr, char *buf)
254 struct acpi_device *acpi_dev = to_acpi_device(dev);
256 return sprintf(buf, "0x%08x\n",
257 (unsigned int)(acpi_dev->pnp.bus_address));
259 static DEVICE_ATTR(adr, 0444, acpi_device_adr_show, NULL);
262 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
263 struct acpi_device *acpi_dev = to_acpi_device(dev);
264 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
267 result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
271 result = sprintf(buf, "%s\n", (char*)path.pointer);
276 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
278 /* sysfs file that shows description text from the ACPI _STR method */
279 static ssize_t description_show(struct device *dev,
280 struct device_attribute *attr,
282 struct acpi_device *acpi_dev = to_acpi_device(dev);
285 if (acpi_dev->pnp.str_obj == NULL)
289 * The _STR object contains a Unicode identifier for a device.
290 * We need to convert to utf-8 so it can be displayed.
292 result = utf16s_to_utf8s(
293 (wchar_t *)acpi_dev->pnp.str_obj->buffer.pointer,
294 acpi_dev->pnp.str_obj->buffer.length,
295 UTF16_LITTLE_ENDIAN, buf,
298 buf[result++] = '\n';
302 static DEVICE_ATTR(description, 0444, description_show, NULL);
305 acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
307 struct acpi_device *acpi_dev = to_acpi_device(dev);
309 return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
311 static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
313 static int acpi_device_setup_files(struct acpi_device *dev)
315 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
318 unsigned long long sun;
322 * Devices gotten from FADT don't have a "path" attribute
325 result = device_create_file(&dev->dev, &dev_attr_path);
330 if (!list_empty(&dev->pnp.ids)) {
331 result = device_create_file(&dev->dev, &dev_attr_hid);
335 result = device_create_file(&dev->dev, &dev_attr_modalias);
341 * If device has _STR, 'description' file is created
343 status = acpi_get_handle(dev->handle, "_STR", &temp);
344 if (ACPI_SUCCESS(status)) {
345 status = acpi_evaluate_object(dev->handle, "_STR",
347 if (ACPI_FAILURE(status))
348 buffer.pointer = NULL;
349 dev->pnp.str_obj = buffer.pointer;
350 result = device_create_file(&dev->dev, &dev_attr_description);
355 if (dev->flags.bus_address)
356 result = device_create_file(&dev->dev, &dev_attr_adr);
357 if (dev->pnp.unique_id)
358 result = device_create_file(&dev->dev, &dev_attr_uid);
360 status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
361 if (ACPI_SUCCESS(status)) {
362 dev->pnp.sun = (unsigned long)sun;
363 result = device_create_file(&dev->dev, &dev_attr_sun);
367 dev->pnp.sun = (unsigned long)-1;
371 * If device has _EJ0, 'eject' file is created that is used to trigger
372 * hot-removal function from userland.
374 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
375 if (ACPI_SUCCESS(status)) {
376 result = device_create_file(&dev->dev, &dev_attr_eject);
381 if (dev->flags.power_manageable) {
382 result = device_create_file(&dev->dev, &dev_attr_power_state);
386 if (dev->power.flags.power_resources)
387 result = device_create_file(&dev->dev,
388 &dev_attr_real_power_state);
395 static void acpi_device_remove_files(struct acpi_device *dev)
400 if (dev->flags.power_manageable) {
401 device_remove_file(&dev->dev, &dev_attr_power_state);
402 if (dev->power.flags.power_resources)
403 device_remove_file(&dev->dev,
404 &dev_attr_real_power_state);
408 * If device has _STR, remove 'description' file
410 status = acpi_get_handle(dev->handle, "_STR", &temp);
411 if (ACPI_SUCCESS(status)) {
412 kfree(dev->pnp.str_obj);
413 device_remove_file(&dev->dev, &dev_attr_description);
416 * If device has _EJ0, remove 'eject' file.
418 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
419 if (ACPI_SUCCESS(status))
420 device_remove_file(&dev->dev, &dev_attr_eject);
422 status = acpi_get_handle(dev->handle, "_SUN", &temp);
423 if (ACPI_SUCCESS(status))
424 device_remove_file(&dev->dev, &dev_attr_sun);
426 if (dev->pnp.unique_id)
427 device_remove_file(&dev->dev, &dev_attr_uid);
428 if (dev->flags.bus_address)
429 device_remove_file(&dev->dev, &dev_attr_adr);
430 device_remove_file(&dev->dev, &dev_attr_modalias);
431 device_remove_file(&dev->dev, &dev_attr_hid);
433 device_remove_file(&dev->dev, &dev_attr_path);
435 /* --------------------------------------------------------------------------
437 -------------------------------------------------------------------------- */
439 static const struct acpi_device_id *__acpi_match_device(
440 struct acpi_device *device, const struct acpi_device_id *ids)
442 const struct acpi_device_id *id;
443 struct acpi_hardware_id *hwid;
446 * If the device is not present, it is unnecessary to load device
449 if (!device->status.present)
452 for (id = ids; id->id[0]; id++)
453 list_for_each_entry(hwid, &device->pnp.ids, list)
454 if (!strcmp((char *) id->id, hwid->id))
461 * acpi_match_device - Match a struct device against a given list of ACPI IDs
462 * @ids: Array of struct acpi_device_id object to match against.
463 * @dev: The device structure to match.
465 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
466 * object for that handle and use that object to match against a given list of
469 * Return a pointer to the first matching ID on success or %NULL on failure.
471 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
472 const struct device *dev)
474 struct acpi_device *adev;
476 if (!ids || !ACPI_HANDLE(dev)
477 || ACPI_FAILURE(acpi_bus_get_device(ACPI_HANDLE(dev), &adev)))
480 return __acpi_match_device(adev, ids);
482 EXPORT_SYMBOL_GPL(acpi_match_device);
484 int acpi_match_device_ids(struct acpi_device *device,
485 const struct acpi_device_id *ids)
487 return __acpi_match_device(device, ids) ? 0 : -ENOENT;
489 EXPORT_SYMBOL(acpi_match_device_ids);
491 void acpi_free_ids(struct acpi_device *device)
493 struct acpi_hardware_id *id, *tmp;
495 list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) {
499 kfree(device->pnp.unique_id);
502 static void acpi_free_power_resources_lists(struct acpi_device *device)
506 if (device->wakeup.flags.valid)
507 acpi_power_resources_list_free(&device->wakeup.resources);
509 if (!device->flags.power_manageable)
512 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
513 struct acpi_device_power_state *ps = &device->power.states[i];
514 acpi_power_resources_list_free(&ps->resources);
518 static void acpi_device_release(struct device *dev)
520 struct acpi_device *acpi_dev = to_acpi_device(dev);
522 acpi_free_ids(acpi_dev);
523 acpi_free_power_resources_lists(acpi_dev);
527 static int acpi_bus_match(struct device *dev, struct device_driver *drv)
529 struct acpi_device *acpi_dev = to_acpi_device(dev);
530 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
532 return acpi_dev->flags.match_driver
533 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
536 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
538 struct acpi_device *acpi_dev = to_acpi_device(dev);
541 if (list_empty(&acpi_dev->pnp.ids))
544 if (add_uevent_var(env, "MODALIAS="))
546 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
547 sizeof(env->buf) - env->buflen);
548 if (len >= (sizeof(env->buf) - env->buflen))
554 static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
556 struct acpi_device *device = data;
558 device->driver->ops.notify(device, event);
561 static acpi_status acpi_device_notify_fixed(void *data)
563 struct acpi_device *device = data;
565 /* Fixed hardware devices have no handles */
566 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
570 static int acpi_device_install_notify_handler(struct acpi_device *device)
574 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
576 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
577 acpi_device_notify_fixed,
579 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
581 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
582 acpi_device_notify_fixed,
585 status = acpi_install_notify_handler(device->handle,
590 if (ACPI_FAILURE(status))
595 static void acpi_device_remove_notify_handler(struct acpi_device *device)
597 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
598 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
599 acpi_device_notify_fixed);
600 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
601 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
602 acpi_device_notify_fixed);
604 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
608 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
609 static int acpi_device_probe(struct device * dev)
611 struct acpi_device *acpi_dev = to_acpi_device(dev);
612 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
615 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
617 if (acpi_drv->ops.notify) {
618 ret = acpi_device_install_notify_handler(acpi_dev);
620 if (acpi_drv->ops.remove)
621 acpi_drv->ops.remove(acpi_dev);
622 acpi_dev->driver = NULL;
623 acpi_dev->driver_data = NULL;
628 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
629 "Found driver [%s] for device [%s]\n",
630 acpi_drv->name, acpi_dev->pnp.bus_id));
636 static int acpi_device_remove(struct device * dev)
638 struct acpi_device *acpi_dev = to_acpi_device(dev);
639 struct acpi_driver *acpi_drv = acpi_dev->driver;
642 if (acpi_drv->ops.notify)
643 acpi_device_remove_notify_handler(acpi_dev);
644 if (acpi_drv->ops.remove)
645 acpi_drv->ops.remove(acpi_dev);
647 acpi_dev->driver = NULL;
648 acpi_dev->driver_data = NULL;
654 struct bus_type acpi_bus_type = {
656 .match = acpi_bus_match,
657 .probe = acpi_device_probe,
658 .remove = acpi_device_remove,
659 .uevent = acpi_device_uevent,
662 int acpi_device_add(struct acpi_device *device,
663 void (*release)(struct device *))
666 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
669 if (device->handle) {
672 status = acpi_attach_data(device->handle, acpi_bus_data_handler,
674 if (ACPI_FAILURE(status)) {
675 acpi_handle_err(device->handle,
676 "Unable to attach device data\n");
684 * Link this device to its parent and siblings.
686 INIT_LIST_HEAD(&device->children);
687 INIT_LIST_HEAD(&device->node);
688 INIT_LIST_HEAD(&device->wakeup_list);
689 INIT_LIST_HEAD(&device->physical_node_list);
690 mutex_init(&device->physical_node_lock);
691 INIT_LIST_HEAD(&device->power_dependent);
693 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
695 pr_err(PREFIX "Memory allocation error\n");
700 mutex_lock(&acpi_device_lock);
702 * Find suitable bus_id and instance number in acpi_bus_id_list
703 * If failed, create one and link it into acpi_bus_id_list
705 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
706 if (!strcmp(acpi_device_bus_id->bus_id,
707 acpi_device_hid(device))) {
708 acpi_device_bus_id->instance_no++;
715 acpi_device_bus_id = new_bus_id;
716 strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
717 acpi_device_bus_id->instance_no = 0;
718 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
720 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
723 list_add_tail(&device->node, &device->parent->children);
725 if (device->wakeup.flags.valid)
726 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
727 mutex_unlock(&acpi_device_lock);
730 device->dev.parent = &device->parent->dev;
731 device->dev.bus = &acpi_bus_type;
732 device->dev.release = release;
733 result = device_add(&device->dev);
735 dev_err(&device->dev, "Error registering device\n");
739 result = acpi_device_setup_files(device);
741 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
742 dev_name(&device->dev));
744 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
748 mutex_lock(&acpi_device_lock);
750 list_del(&device->node);
751 list_del(&device->wakeup_list);
752 mutex_unlock(&acpi_device_lock);
755 acpi_detach_data(device->handle, acpi_bus_data_handler);
759 static void acpi_device_unregister(struct acpi_device *device)
761 mutex_lock(&acpi_device_lock);
763 list_del(&device->node);
765 list_del(&device->wakeup_list);
766 mutex_unlock(&acpi_device_lock);
768 acpi_detach_data(device->handle, acpi_bus_data_handler);
770 acpi_power_add_remove_device(device, false);
771 acpi_device_remove_files(device);
773 device->remove(device);
775 device_del(&device->dev);
777 * Transition the device to D3cold to drop the reference counts of all
778 * power resources the device depends on and turn off the ones that have
779 * no more references.
781 acpi_device_set_power(device, ACPI_STATE_D3_COLD);
782 put_device(&device->dev);
785 /* --------------------------------------------------------------------------
787 -------------------------------------------------------------------------- */
789 * acpi_bus_driver_init - add a device to a driver
790 * @device: the device to add and initialize
791 * @driver: driver for the device
793 * Used to initialize a device via its device driver. Called whenever a
794 * driver is bound to a device. Invokes the driver's add() ops.
797 acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
801 if (!device || !driver)
804 if (!driver->ops.add)
807 result = driver->ops.add(device);
809 device->driver = NULL;
810 device->driver_data = NULL;
814 device->driver = driver;
817 * TBD - Configuration Management: Assign resources to device based
818 * upon possible configuration and currently allocated resources.
821 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
822 "Driver successfully bound to device\n"));
827 * acpi_bus_register_driver - register a driver with the ACPI bus
828 * @driver: driver being registered
830 * Registers a driver with the ACPI bus. Searches the namespace for all
831 * devices that match the driver's criteria and binds. Returns zero for
832 * success or a negative error status for failure.
834 int acpi_bus_register_driver(struct acpi_driver *driver)
840 driver->drv.name = driver->name;
841 driver->drv.bus = &acpi_bus_type;
842 driver->drv.owner = driver->owner;
844 ret = driver_register(&driver->drv);
848 EXPORT_SYMBOL(acpi_bus_register_driver);
851 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
852 * @driver: driver to unregister
854 * Unregisters a driver with the ACPI bus. Searches the namespace for all
855 * devices that match the driver's criteria and unbinds.
857 void acpi_bus_unregister_driver(struct acpi_driver *driver)
859 driver_unregister(&driver->drv);
862 EXPORT_SYMBOL(acpi_bus_unregister_driver);
864 /* --------------------------------------------------------------------------
866 -------------------------------------------------------------------------- */
867 static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
869 struct acpi_device *device = NULL;
873 * Fixed hardware devices do not appear in the namespace and do not
874 * have handles, but we fabricate acpi_devices for them, so we have
875 * to deal with them specially.
881 status = acpi_get_parent(handle, &handle);
882 if (ACPI_FAILURE(status))
883 return status == AE_NULL_ENTRY ? NULL : acpi_root;
884 } while (acpi_bus_get_device(handle, &device));
889 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
893 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
894 union acpi_object *obj;
896 status = acpi_get_handle(handle, "_EJD", &tmp);
897 if (ACPI_FAILURE(status))
900 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
901 if (ACPI_SUCCESS(status)) {
902 obj = buffer.pointer;
903 status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
905 kfree(buffer.pointer);
909 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
911 void acpi_bus_data_handler(acpi_handle handle, void *context)
919 static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
920 struct acpi_device_wakeup *wakeup)
922 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
923 union acpi_object *package = NULL;
924 union acpi_object *element = NULL;
931 INIT_LIST_HEAD(&wakeup->resources);
934 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
935 if (ACPI_FAILURE(status)) {
936 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
940 package = (union acpi_object *)buffer.pointer;
942 if (!package || package->package.count < 2)
945 element = &(package->package.elements[0]);
949 if (element->type == ACPI_TYPE_PACKAGE) {
950 if ((element->package.count < 2) ||
951 (element->package.elements[0].type !=
952 ACPI_TYPE_LOCAL_REFERENCE)
953 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
957 element->package.elements[0].reference.handle;
959 (u32) element->package.elements[1].integer.value;
960 } else if (element->type == ACPI_TYPE_INTEGER) {
961 wakeup->gpe_device = NULL;
962 wakeup->gpe_number = element->integer.value;
967 element = &(package->package.elements[1]);
968 if (element->type != ACPI_TYPE_INTEGER)
971 wakeup->sleep_state = element->integer.value;
973 err = acpi_extract_power_resources(package, 2, &wakeup->resources);
977 if (!list_empty(&wakeup->resources)) {
980 sleep_state = acpi_power_min_system_level(&wakeup->resources);
981 if (sleep_state < wakeup->sleep_state) {
982 acpi_handle_warn(handle, "Overriding _PRW sleep state "
983 "(S%d) by S%d from power resources\n",
984 (int)wakeup->sleep_state, sleep_state);
985 wakeup->sleep_state = sleep_state;
988 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
991 kfree(buffer.pointer);
995 static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
997 struct acpi_device_id button_device_ids[] = {
1004 acpi_event_status event_status;
1006 device->wakeup.flags.notifier_present = 0;
1008 /* Power button, Lid switch always enable wakeup */
1009 if (!acpi_match_device_ids(device, button_device_ids)) {
1010 device->wakeup.flags.run_wake = 1;
1011 if (!acpi_match_device_ids(device, &button_device_ids[1])) {
1012 /* Do not use Lid/sleep button for S5 wakeup */
1013 if (device->wakeup.sleep_state == ACPI_STATE_S5)
1014 device->wakeup.sleep_state = ACPI_STATE_S4;
1016 device_set_wakeup_capable(&device->dev, true);
1020 status = acpi_get_gpe_status(device->wakeup.gpe_device,
1021 device->wakeup.gpe_number,
1023 if (status == AE_OK)
1024 device->wakeup.flags.run_wake =
1025 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
1028 static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
1031 acpi_status status = 0;
1034 /* Presence of _PRW indicates wake capable */
1035 status = acpi_get_handle(device->handle, "_PRW", &temp);
1036 if (ACPI_FAILURE(status))
1039 err = acpi_bus_extract_wakeup_device_power_package(device->handle,
1042 dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
1046 device->wakeup.flags.valid = 1;
1047 device->wakeup.prepare_count = 0;
1048 acpi_bus_set_run_wake_flags(device);
1049 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
1050 * system for the ACPI device with the _PRW object.
1051 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
1052 * So it is necessary to call _DSW object first. Only when it is not
1053 * present will the _PSW object used.
1055 err = acpi_device_sleep_wake(device, 0, 0, 0);
1057 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1058 "error in _DSW or _PSW evaluation\n"));
1061 static void acpi_bus_init_power_state(struct acpi_device *device, int state)
1063 struct acpi_device_power_state *ps = &device->power.states[state];
1064 char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
1065 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1069 INIT_LIST_HEAD(&ps->resources);
1071 /* Evaluate "_PRx" to get referenced power resources */
1072 status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
1073 if (ACPI_SUCCESS(status)) {
1074 union acpi_object *package = buffer.pointer;
1076 if (buffer.length && package
1077 && package->type == ACPI_TYPE_PACKAGE
1078 && package->package.count) {
1079 int err = acpi_extract_power_resources(package, 0,
1082 device->power.flags.power_resources = 1;
1084 ACPI_FREE(buffer.pointer);
1087 /* Evaluate "_PSx" to see if we can do explicit sets */
1089 status = acpi_get_handle(device->handle, pathname, &handle);
1090 if (ACPI_SUCCESS(status))
1091 ps->flags.explicit_set = 1;
1094 * State is valid if there are means to put the device into it.
1095 * D3hot is only valid if _PR3 present.
1097 if (!list_empty(&ps->resources)
1098 || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) {
1099 ps->flags.valid = 1;
1100 ps->flags.os_accessible = 1;
1103 ps->power = -1; /* Unknown - driver assigned */
1104 ps->latency = -1; /* Unknown - driver assigned */
1107 static void acpi_bus_get_power_flags(struct acpi_device *device)
1113 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1114 status = acpi_get_handle(device->handle, "_PS0", &handle);
1115 if (ACPI_FAILURE(status)) {
1116 status = acpi_get_handle(device->handle, "_PR0", &handle);
1117 if (ACPI_FAILURE(status))
1121 device->flags.power_manageable = 1;
1124 * Power Management Flags
1126 status = acpi_get_handle(device->handle, "_PSC", &handle);
1127 if (ACPI_SUCCESS(status))
1128 device->power.flags.explicit_get = 1;
1129 status = acpi_get_handle(device->handle, "_IRC", &handle);
1130 if (ACPI_SUCCESS(status))
1131 device->power.flags.inrush_current = 1;
1134 * Enumerate supported power management states
1136 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
1137 acpi_bus_init_power_state(device, i);
1139 INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
1141 /* Set defaults for D0 and D3 states (always valid) */
1142 device->power.states[ACPI_STATE_D0].flags.valid = 1;
1143 device->power.states[ACPI_STATE_D0].power = 100;
1144 device->power.states[ACPI_STATE_D3].flags.valid = 1;
1145 device->power.states[ACPI_STATE_D3].power = 0;
1147 /* Set D3cold's explicit_set flag if _PS3 exists. */
1148 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set)
1149 device->power.states[ACPI_STATE_D3_COLD].flags.explicit_set = 1;
1151 /* Presence of _PS3 or _PRx means we can put the device into D3 cold */
1152 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set ||
1153 device->power.flags.power_resources)
1154 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1;
1156 acpi_bus_init_power(device);
1159 static void acpi_bus_get_flags(struct acpi_device *device)
1161 acpi_status status = AE_OK;
1162 acpi_handle temp = NULL;
1164 /* Presence of _STA indicates 'dynamic_status' */
1165 status = acpi_get_handle(device->handle, "_STA", &temp);
1166 if (ACPI_SUCCESS(status))
1167 device->flags.dynamic_status = 1;
1169 /* Presence of _RMV indicates 'removable' */
1170 status = acpi_get_handle(device->handle, "_RMV", &temp);
1171 if (ACPI_SUCCESS(status))
1172 device->flags.removable = 1;
1174 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
1175 status = acpi_get_handle(device->handle, "_EJD", &temp);
1176 if (ACPI_SUCCESS(status))
1177 device->flags.ejectable = 1;
1179 status = acpi_get_handle(device->handle, "_EJ0", &temp);
1180 if (ACPI_SUCCESS(status))
1181 device->flags.ejectable = 1;
1185 static void acpi_device_get_busid(struct acpi_device *device)
1187 char bus_id[5] = { '?', 0 };
1188 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
1194 * The device's Bus ID is simply the object name.
1195 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
1197 if (ACPI_IS_ROOT_DEVICE(device)) {
1198 strcpy(device->pnp.bus_id, "ACPI");
1202 switch (device->device_type) {
1203 case ACPI_BUS_TYPE_POWER_BUTTON:
1204 strcpy(device->pnp.bus_id, "PWRF");
1206 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1207 strcpy(device->pnp.bus_id, "SLPF");
1210 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
1211 /* Clean up trailing underscores (if any) */
1212 for (i = 3; i > 1; i--) {
1213 if (bus_id[i] == '_')
1218 strcpy(device->pnp.bus_id, bus_id);
1224 * acpi_bay_match - see if a device is an ejectable driver bay
1226 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
1227 * then we can safely call it an ejectable drive bay
1229 static int acpi_bay_match(struct acpi_device *device){
1233 acpi_handle phandle;
1235 handle = device->handle;
1237 status = acpi_get_handle(handle, "_EJ0", &tmp);
1238 if (ACPI_FAILURE(status))
1241 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
1242 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
1243 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
1244 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
1247 if (acpi_get_parent(handle, &phandle))
1250 if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
1251 (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
1252 (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
1253 (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
1260 * acpi_dock_match - see if a device has a _DCK method
1262 static int acpi_dock_match(struct acpi_device *device)
1265 return acpi_get_handle(device->handle, "_DCK", &tmp);
1268 const char *acpi_device_hid(struct acpi_device *device)
1270 struct acpi_hardware_id *hid;
1272 if (list_empty(&device->pnp.ids))
1275 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1278 EXPORT_SYMBOL(acpi_device_hid);
1280 static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1282 struct acpi_hardware_id *id;
1284 id = kmalloc(sizeof(*id), GFP_KERNEL);
1288 id->id = kstrdup(dev_id, GFP_KERNEL);
1294 list_add_tail(&id->list, &device->pnp.ids);
1298 * Old IBM workstations have a DSDT bug wherein the SMBus object
1299 * lacks the SMBUS01 HID and the methods do not have the necessary "_"
1300 * prefix. Work around this.
1302 static int acpi_ibm_smbus_match(struct acpi_device *device)
1304 acpi_handle h_dummy;
1305 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
1308 if (!dmi_name_in_vendors("IBM"))
1311 /* Look for SMBS object */
1312 result = acpi_get_name(device->handle, ACPI_SINGLE_NAME, &path);
1316 if (strcmp("SMBS", path.pointer)) {
1321 /* Does it have the necessary (but misnamed) methods? */
1323 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "SBI", &h_dummy)) &&
1324 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBR", &h_dummy)) &&
1325 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBW", &h_dummy)))
1328 kfree(path.pointer);
1332 static void acpi_device_set_id(struct acpi_device *device)
1335 struct acpi_device_info *info;
1336 struct acpi_pnp_device_id_list *cid_list;
1339 switch (device->device_type) {
1340 case ACPI_BUS_TYPE_DEVICE:
1341 if (ACPI_IS_ROOT_DEVICE(device)) {
1342 acpi_add_id(device, ACPI_SYSTEM_HID);
1346 status = acpi_get_object_info(device->handle, &info);
1347 if (ACPI_FAILURE(status)) {
1348 printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__);
1352 if (info->valid & ACPI_VALID_HID)
1353 acpi_add_id(device, info->hardware_id.string);
1354 if (info->valid & ACPI_VALID_CID) {
1355 cid_list = &info->compatible_id_list;
1356 for (i = 0; i < cid_list->count; i++)
1357 acpi_add_id(device, cid_list->ids[i].string);
1359 if (info->valid & ACPI_VALID_ADR) {
1360 device->pnp.bus_address = info->address;
1361 device->flags.bus_address = 1;
1363 if (info->valid & ACPI_VALID_UID)
1364 device->pnp.unique_id = kstrdup(info->unique_id.string,
1370 * Some devices don't reliably have _HIDs & _CIDs, so add
1371 * synthetic HIDs to make sure drivers can find them.
1373 if (acpi_is_video_device(device))
1374 acpi_add_id(device, ACPI_VIDEO_HID);
1375 else if (ACPI_SUCCESS(acpi_bay_match(device)))
1376 acpi_add_id(device, ACPI_BAY_HID);
1377 else if (ACPI_SUCCESS(acpi_dock_match(device)))
1378 acpi_add_id(device, ACPI_DOCK_HID);
1379 else if (!acpi_ibm_smbus_match(device))
1380 acpi_add_id(device, ACPI_SMBUS_IBM_HID);
1381 else if (list_empty(&device->pnp.ids) &&
1382 ACPI_IS_ROOT_DEVICE(device->parent)) {
1383 acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
1384 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1385 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1389 case ACPI_BUS_TYPE_POWER:
1390 acpi_add_id(device, ACPI_POWER_HID);
1392 case ACPI_BUS_TYPE_PROCESSOR:
1393 acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
1395 case ACPI_BUS_TYPE_THERMAL:
1396 acpi_add_id(device, ACPI_THERMAL_HID);
1398 case ACPI_BUS_TYPE_POWER_BUTTON:
1399 acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
1401 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1402 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
1407 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1408 int type, unsigned long long sta)
1410 INIT_LIST_HEAD(&device->pnp.ids);
1411 device->device_type = type;
1412 device->handle = handle;
1413 device->parent = acpi_bus_get_parent(handle);
1414 STRUCT_TO_INT(device->status) = sta;
1415 acpi_device_get_busid(device);
1416 acpi_device_set_id(device);
1417 acpi_bus_get_flags(device);
1418 device->flags.match_driver = false;
1419 device_initialize(&device->dev);
1420 dev_set_uevent_suppress(&device->dev, true);
1423 void acpi_device_add_finalize(struct acpi_device *device)
1425 device->flags.match_driver = true;
1426 dev_set_uevent_suppress(&device->dev, false);
1427 kobject_uevent(&device->dev.kobj, KOBJ_ADD);
1430 static int acpi_add_single_object(struct acpi_device **child,
1431 acpi_handle handle, int type,
1432 unsigned long long sta)
1435 struct acpi_device *device;
1436 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1438 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1440 printk(KERN_ERR PREFIX "Memory allocation error\n");
1444 acpi_init_device_object(device, handle, type, sta);
1445 acpi_bus_get_power_flags(device);
1446 acpi_bus_get_wakeup_device_flags(device);
1448 result = acpi_device_add(device, acpi_device_release);
1450 acpi_device_release(&device->dev);
1454 acpi_power_add_remove_device(device, true);
1455 acpi_device_add_finalize(device);
1456 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1457 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
1458 dev_name(&device->dev), (char *) buffer.pointer,
1459 device->parent ? dev_name(&device->parent->dev) : "(null)"));
1460 kfree(buffer.pointer);
1465 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1466 unsigned long long *sta)
1469 acpi_object_type acpi_type;
1471 status = acpi_get_type(handle, &acpi_type);
1472 if (ACPI_FAILURE(status))
1475 switch (acpi_type) {
1476 case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
1477 case ACPI_TYPE_DEVICE:
1478 *type = ACPI_BUS_TYPE_DEVICE;
1479 status = acpi_bus_get_status_handle(handle, sta);
1480 if (ACPI_FAILURE(status))
1483 case ACPI_TYPE_PROCESSOR:
1484 *type = ACPI_BUS_TYPE_PROCESSOR;
1485 status = acpi_bus_get_status_handle(handle, sta);
1486 if (ACPI_FAILURE(status))
1489 case ACPI_TYPE_THERMAL:
1490 *type = ACPI_BUS_TYPE_THERMAL;
1491 *sta = ACPI_STA_DEFAULT;
1493 case ACPI_TYPE_POWER:
1494 *type = ACPI_BUS_TYPE_POWER;
1495 *sta = ACPI_STA_DEFAULT;
1504 static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
1505 void *not_used, void **return_value)
1507 struct acpi_device *device = NULL;
1509 unsigned long long sta;
1513 acpi_bus_get_device(handle, &device);
1517 result = acpi_bus_type_and_status(handle, &type, &sta);
1521 if (type == ACPI_BUS_TYPE_POWER) {
1522 acpi_add_power_resource(handle);
1526 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1527 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
1528 struct acpi_device_wakeup wakeup;
1531 status = acpi_get_handle(handle, "_PRW", &temp);
1532 if (ACPI_SUCCESS(status)) {
1533 acpi_bus_extract_wakeup_device_power_package(handle,
1535 acpi_power_resources_list_free(&wakeup.resources);
1537 return AE_CTRL_DEPTH;
1540 acpi_add_single_object(&device, handle, type, sta);
1542 return AE_CTRL_DEPTH;
1546 *return_value = device;
1551 static int acpi_scan_do_attach_handler(struct acpi_device *device, char *id)
1553 struct acpi_scan_handler *handler;
1555 list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) {
1556 const struct acpi_device_id *devid;
1558 for (devid = handler->ids; devid->id[0]; devid++) {
1561 if (strcmp((char *)devid->id, id))
1564 ret = handler->attach(device, devid);
1566 device->handler = handler;
1568 } else if (ret < 0) {
1576 static int acpi_scan_attach_handler(struct acpi_device *device)
1578 struct acpi_hardware_id *hwid;
1581 list_for_each_entry(hwid, &device->pnp.ids, list) {
1582 ret = acpi_scan_do_attach_handler(device, hwid->id);
1590 static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
1591 void *not_used, void **ret_not_used)
1593 struct acpi_device *device;
1594 unsigned long long sta_not_used;
1598 * Ignore errors ignored by acpi_bus_check_add() to avoid terminating
1599 * namespace walks prematurely.
1601 if (acpi_bus_type_and_status(handle, &ret, &sta_not_used))
1604 if (acpi_bus_get_device(handle, &device))
1605 return AE_CTRL_DEPTH;
1607 ret = acpi_scan_attach_handler(device);
1609 return ret > 0 ? AE_OK : AE_CTRL_DEPTH;
1611 ret = device_attach(&device->dev);
1612 return ret >= 0 ? AE_OK : AE_CTRL_DEPTH;
1616 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
1617 * @handle: Root of the namespace scope to scan.
1619 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
1622 * If no devices were found, -ENODEV is returned, but it does not mean that
1623 * there has been a real error. There just have been no suitable ACPI objects
1624 * in the table trunk from which the kernel could create a device and add an
1625 * appropriate driver.
1627 int acpi_bus_scan(acpi_handle handle)
1629 void *device = NULL;
1632 mutex_lock(&acpi_scan_lock);
1634 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
1635 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1636 acpi_bus_check_add, NULL, NULL, &device);
1640 else if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL)))
1641 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1642 acpi_bus_device_attach, NULL, NULL, NULL);
1644 mutex_unlock(&acpi_scan_lock);
1647 EXPORT_SYMBOL(acpi_bus_scan);
1649 static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,
1650 void *not_used, void **ret_not_used)
1652 struct acpi_device *device = NULL;
1654 if (!acpi_bus_get_device(handle, &device)) {
1655 struct acpi_scan_handler *dev_handler = device->handler;
1657 device->removal_type = ACPI_BUS_REMOVAL_EJECT;
1659 if (dev_handler->detach)
1660 dev_handler->detach(device);
1662 device->handler = NULL;
1664 device_release_driver(&device->dev);
1670 static acpi_status acpi_bus_remove(acpi_handle handle, u32 lvl_not_used,
1671 void *not_used, void **ret_not_used)
1673 struct acpi_device *device = NULL;
1675 if (!acpi_bus_get_device(handle, &device))
1676 acpi_device_unregister(device);
1681 static void __acpi_bus_trim(struct acpi_device *start)
1684 * Execute acpi_bus_device_detach() as a post-order callback to detach
1685 * all ACPI drivers from the device nodes being removed.
1687 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1688 acpi_bus_device_detach, NULL, NULL);
1689 acpi_bus_device_detach(start->handle, 0, NULL, NULL);
1691 * Execute acpi_bus_remove() as a post-order callback to remove device
1692 * nodes in the given namespace scope.
1694 acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL,
1695 acpi_bus_remove, NULL, NULL);
1696 acpi_bus_remove(start->handle, 0, NULL, NULL);
1699 void acpi_bus_trim(struct acpi_device *start)
1701 mutex_lock(&acpi_scan_lock);
1702 __acpi_bus_trim(start);
1703 mutex_unlock(&acpi_scan_lock);
1705 EXPORT_SYMBOL_GPL(acpi_bus_trim);
1707 static int acpi_bus_scan_fixed(void)
1712 * Enumerate all fixed-feature devices.
1714 if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
1715 struct acpi_device *device = NULL;
1717 result = acpi_add_single_object(&device, NULL,
1718 ACPI_BUS_TYPE_POWER_BUTTON,
1723 result = device_attach(&device->dev);
1727 device_init_wakeup(&device->dev, true);
1730 if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
1731 struct acpi_device *device = NULL;
1733 result = acpi_add_single_object(&device, NULL,
1734 ACPI_BUS_TYPE_SLEEP_BUTTON,
1739 result = device_attach(&device->dev);
1742 return result < 0 ? result : 0;
1745 int __init acpi_scan_init(void)
1749 result = bus_register(&acpi_bus_type);
1751 /* We don't want to quit even if we failed to add suspend/resume */
1752 printk(KERN_ERR PREFIX "Could not register bus type\n");
1755 acpi_pci_root_init();
1756 acpi_pci_link_init();
1757 acpi_platform_init();
1759 acpi_container_init();
1762 * Enumerate devices in the ACPI namespace.
1764 result = acpi_bus_scan(ACPI_ROOT_OBJECT);
1768 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
1772 result = acpi_bus_scan_fixed();
1774 acpi_device_unregister(acpi_root);
1778 acpi_update_all_gpes();