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";
33 * The following ACPI IDs are known to be suitable for representing as
36 static const struct acpi_device_id acpi_platform_device_ids
[] = {
41 static LIST_HEAD(acpi_device_list
);
42 static LIST_HEAD(acpi_bus_id_list
);
43 DEFINE_MUTEX(acpi_device_lock
);
44 LIST_HEAD(acpi_wakeup_device_list
);
46 struct acpi_device_bus_id
{
48 unsigned int instance_no
;
49 struct list_head node
;
53 * Creates hid/cid(s) string needed for modalias and uevent
54 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
55 * char *modalias: "acpi:IBM0001:ACPI0001"
57 static int create_modalias(struct acpi_device
*acpi_dev
, char *modalias
,
62 struct acpi_hardware_id
*id
;
64 if (list_empty(&acpi_dev
->pnp
.ids
))
67 len
= snprintf(modalias
, size
, "acpi:");
70 list_for_each_entry(id
, &acpi_dev
->pnp
.ids
, list
) {
71 count
= snprintf(&modalias
[len
], size
, "%s:", id
->id
);
72 if (count
< 0 || count
>= size
)
83 acpi_device_modalias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
84 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
87 /* Device has no HID and no CID or string is >1024 */
88 len
= create_modalias(acpi_dev
, buf
, 1024);
94 static DEVICE_ATTR(modalias
, 0444, acpi_device_modalias_show
, NULL
);
97 * acpi_bus_hot_remove_device: hot-remove a device and its children
98 * @context: struct acpi_eject_event pointer (freed in this func)
100 * Hot-remove a device and its children. This function frees up the
101 * memory space passed by arg context, so that the caller may call
102 * this function asynchronously through acpi_os_hotplug_execute().
104 void acpi_bus_hot_remove_device(void *context
)
106 struct acpi_eject_event
*ej_event
= (struct acpi_eject_event
*) context
;
107 struct acpi_device
*device
;
108 acpi_handle handle
= ej_event
->handle
;
109 struct acpi_object_list arg_list
;
110 union acpi_object arg
;
111 acpi_status status
= AE_OK
;
112 u32 ost_code
= ACPI_OST_SC_NON_SPECIFIC_FAILURE
; /* default */
114 if (acpi_bus_get_device(handle
, &device
))
120 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
121 "Hot-removing device %s...\n", dev_name(&device
->dev
)));
123 if (acpi_bus_trim(device
, 1)) {
124 printk(KERN_ERR PREFIX
125 "Removing device failed\n");
129 /* power off device */
130 status
= acpi_evaluate_object(handle
, "_PS3", NULL
, NULL
);
131 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
)
132 printk(KERN_WARNING PREFIX
133 "Power-off device failed\n");
135 if (device
->flags
.lockable
) {
137 arg_list
.pointer
= &arg
;
138 arg
.type
= ACPI_TYPE_INTEGER
;
139 arg
.integer
.value
= 0;
140 acpi_evaluate_object(handle
, "_LCK", &arg_list
, NULL
);
144 arg_list
.pointer
= &arg
;
145 arg
.type
= ACPI_TYPE_INTEGER
;
146 arg
.integer
.value
= 1;
151 status
= acpi_evaluate_object(handle
, "_EJ0", &arg_list
, NULL
);
152 if (ACPI_FAILURE(status
)) {
153 if (status
!= AE_NOT_FOUND
)
154 printk(KERN_WARNING PREFIX
155 "Eject device failed\n");
163 /* Inform firmware the hot-remove operation has completed w/ error */
164 (void) acpi_evaluate_hotplug_ost(handle
,
165 ej_event
->event
, ost_code
, NULL
);
171 acpi_eject_store(struct device
*d
, struct device_attribute
*attr
,
172 const char *buf
, size_t count
)
176 acpi_object_type type
= 0;
177 struct acpi_device
*acpi_device
= to_acpi_device(d
);
178 struct acpi_eject_event
*ej_event
;
180 if ((!count
) || (buf
[0] != '1')) {
184 if (acpi_device
->driver
== NULL
) {
189 status
= acpi_get_type(acpi_device
->handle
, &type
);
190 if (ACPI_FAILURE(status
) || (!acpi_device
->flags
.ejectable
)) {
195 ej_event
= kmalloc(sizeof(*ej_event
), GFP_KERNEL
);
201 ej_event
->handle
= acpi_device
->handle
;
202 if (acpi_device
->flags
.eject_pending
) {
203 /* event originated from ACPI eject notification */
204 ej_event
->event
= ACPI_NOTIFY_EJECT_REQUEST
;
205 acpi_device
->flags
.eject_pending
= 0;
207 /* event originated from user */
208 ej_event
->event
= ACPI_OST_EC_OSPM_EJECT
;
209 (void) acpi_evaluate_hotplug_ost(ej_event
->handle
,
210 ej_event
->event
, ACPI_OST_SC_EJECT_IN_PROGRESS
, NULL
);
213 acpi_os_hotplug_execute(acpi_bus_hot_remove_device
, (void *)ej_event
);
218 static DEVICE_ATTR(eject
, 0200, NULL
, acpi_eject_store
);
221 acpi_device_hid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
222 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
224 return sprintf(buf
, "%s\n", acpi_device_hid(acpi_dev
));
226 static DEVICE_ATTR(hid
, 0444, acpi_device_hid_show
, NULL
);
229 acpi_device_path_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
230 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
231 struct acpi_buffer path
= {ACPI_ALLOCATE_BUFFER
, NULL
};
234 result
= acpi_get_name(acpi_dev
->handle
, ACPI_FULL_PATHNAME
, &path
);
238 result
= sprintf(buf
, "%s\n", (char*)path
.pointer
);
243 static DEVICE_ATTR(path
, 0444, acpi_device_path_show
, NULL
);
245 /* sysfs file that shows description text from the ACPI _STR method */
246 static ssize_t
description_show(struct device
*dev
,
247 struct device_attribute
*attr
,
249 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
252 if (acpi_dev
->pnp
.str_obj
== NULL
)
256 * The _STR object contains a Unicode identifier for a device.
257 * We need to convert to utf-8 so it can be displayed.
259 result
= utf16s_to_utf8s(
260 (wchar_t *)acpi_dev
->pnp
.str_obj
->buffer
.pointer
,
261 acpi_dev
->pnp
.str_obj
->buffer
.length
,
262 UTF16_LITTLE_ENDIAN
, buf
,
265 buf
[result
++] = '\n';
269 static DEVICE_ATTR(description
, 0444, description_show
, NULL
);
271 static int acpi_device_setup_files(struct acpi_device
*dev
)
273 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
279 * Devices gotten from FADT don't have a "path" attribute
282 result
= device_create_file(&dev
->dev
, &dev_attr_path
);
287 if (!list_empty(&dev
->pnp
.ids
)) {
288 result
= device_create_file(&dev
->dev
, &dev_attr_hid
);
292 result
= device_create_file(&dev
->dev
, &dev_attr_modalias
);
298 * If device has _STR, 'description' file is created
300 status
= acpi_get_handle(dev
->handle
, "_STR", &temp
);
301 if (ACPI_SUCCESS(status
)) {
302 status
= acpi_evaluate_object(dev
->handle
, "_STR",
304 if (ACPI_FAILURE(status
))
305 buffer
.pointer
= NULL
;
306 dev
->pnp
.str_obj
= buffer
.pointer
;
307 result
= device_create_file(&dev
->dev
, &dev_attr_description
);
313 * If device has _EJ0, 'eject' file is created that is used to trigger
314 * hot-removal function from userland.
316 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
317 if (ACPI_SUCCESS(status
))
318 result
= device_create_file(&dev
->dev
, &dev_attr_eject
);
323 static void acpi_device_remove_files(struct acpi_device
*dev
)
329 * If device has _STR, remove 'description' file
331 status
= acpi_get_handle(dev
->handle
, "_STR", &temp
);
332 if (ACPI_SUCCESS(status
)) {
333 kfree(dev
->pnp
.str_obj
);
334 device_remove_file(&dev
->dev
, &dev_attr_description
);
337 * If device has _EJ0, remove 'eject' file.
339 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
340 if (ACPI_SUCCESS(status
))
341 device_remove_file(&dev
->dev
, &dev_attr_eject
);
343 device_remove_file(&dev
->dev
, &dev_attr_modalias
);
344 device_remove_file(&dev
->dev
, &dev_attr_hid
);
346 device_remove_file(&dev
->dev
, &dev_attr_path
);
348 /* --------------------------------------------------------------------------
350 -------------------------------------------------------------------------- */
352 static const struct acpi_device_id
*__acpi_match_device(
353 struct acpi_device
*device
, const struct acpi_device_id
*ids
)
355 const struct acpi_device_id
*id
;
356 struct acpi_hardware_id
*hwid
;
359 * If the device is not present, it is unnecessary to load device
362 if (!device
->status
.present
)
365 for (id
= ids
; id
->id
[0]; id
++)
366 list_for_each_entry(hwid
, &device
->pnp
.ids
, list
)
367 if (!strcmp((char *) id
->id
, hwid
->id
))
374 * acpi_match_device - Match a struct device against a given list of ACPI IDs
375 * @ids: Array of struct acpi_device_id object to match against.
376 * @dev: The device structure to match.
378 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
379 * object for that handle and use that object to match against a given list of
382 * Return a pointer to the first matching ID on success or %NULL on failure.
384 const struct acpi_device_id
*acpi_match_device(const struct acpi_device_id
*ids
,
385 const struct device
*dev
)
387 struct acpi_device
*adev
;
389 if (!ids
|| !dev
->acpi_handle
390 || ACPI_FAILURE(acpi_bus_get_device(dev
->acpi_handle
, &adev
)))
393 return __acpi_match_device(adev
, ids
);
395 EXPORT_SYMBOL_GPL(acpi_match_device
);
397 int acpi_match_device_ids(struct acpi_device
*device
,
398 const struct acpi_device_id
*ids
)
400 return __acpi_match_device(device
, ids
) ? 0 : -ENOENT
;
402 EXPORT_SYMBOL(acpi_match_device_ids
);
404 static void acpi_free_ids(struct acpi_device
*device
)
406 struct acpi_hardware_id
*id
, *tmp
;
408 list_for_each_entry_safe(id
, tmp
, &device
->pnp
.ids
, list
) {
414 static void acpi_device_release(struct device
*dev
)
416 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
418 acpi_free_ids(acpi_dev
);
422 static int acpi_bus_match(struct device
*dev
, struct device_driver
*drv
)
424 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
425 struct acpi_driver
*acpi_drv
= to_acpi_driver(drv
);
427 return !acpi_match_device_ids(acpi_dev
, acpi_drv
->ids
);
430 static int acpi_device_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
432 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
435 if (list_empty(&acpi_dev
->pnp
.ids
))
438 if (add_uevent_var(env
, "MODALIAS="))
440 len
= create_modalias(acpi_dev
, &env
->buf
[env
->buflen
- 1],
441 sizeof(env
->buf
) - env
->buflen
);
442 if (len
>= (sizeof(env
->buf
) - env
->buflen
))
448 static void acpi_device_notify(acpi_handle handle
, u32 event
, void *data
)
450 struct acpi_device
*device
= data
;
452 device
->driver
->ops
.notify(device
, event
);
455 static acpi_status
acpi_device_notify_fixed(void *data
)
457 struct acpi_device
*device
= data
;
459 /* Fixed hardware devices have no handles */
460 acpi_device_notify(NULL
, ACPI_FIXED_HARDWARE_EVENT
, device
);
464 static int acpi_device_install_notify_handler(struct acpi_device
*device
)
468 if (device
->device_type
== ACPI_BUS_TYPE_POWER_BUTTON
)
470 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON
,
471 acpi_device_notify_fixed
,
473 else if (device
->device_type
== ACPI_BUS_TYPE_SLEEP_BUTTON
)
475 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON
,
476 acpi_device_notify_fixed
,
479 status
= acpi_install_notify_handler(device
->handle
,
484 if (ACPI_FAILURE(status
))
489 static void acpi_device_remove_notify_handler(struct acpi_device
*device
)
491 if (device
->device_type
== ACPI_BUS_TYPE_POWER_BUTTON
)
492 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON
,
493 acpi_device_notify_fixed
);
494 else if (device
->device_type
== ACPI_BUS_TYPE_SLEEP_BUTTON
)
495 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON
,
496 acpi_device_notify_fixed
);
498 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
502 static int acpi_bus_driver_init(struct acpi_device
*, struct acpi_driver
*);
503 static int acpi_start_single_object(struct acpi_device
*);
504 static int acpi_device_probe(struct device
* dev
)
506 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
507 struct acpi_driver
*acpi_drv
= to_acpi_driver(dev
->driver
);
510 ret
= acpi_bus_driver_init(acpi_dev
, acpi_drv
);
512 if (acpi_dev
->bus_ops
.acpi_op_start
)
513 acpi_start_single_object(acpi_dev
);
515 if (acpi_drv
->ops
.notify
) {
516 ret
= acpi_device_install_notify_handler(acpi_dev
);
518 if (acpi_drv
->ops
.remove
)
519 acpi_drv
->ops
.remove(acpi_dev
,
520 acpi_dev
->removal_type
);
525 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
526 "Found driver [%s] for device [%s]\n",
527 acpi_drv
->name
, acpi_dev
->pnp
.bus_id
));
533 static int acpi_device_remove(struct device
* dev
)
535 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
536 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
539 if (acpi_drv
->ops
.notify
)
540 acpi_device_remove_notify_handler(acpi_dev
);
541 if (acpi_drv
->ops
.remove
)
542 acpi_drv
->ops
.remove(acpi_dev
, acpi_dev
->removal_type
);
544 acpi_dev
->driver
= NULL
;
545 acpi_dev
->driver_data
= NULL
;
551 struct bus_type acpi_bus_type
= {
553 .match
= acpi_bus_match
,
554 .probe
= acpi_device_probe
,
555 .remove
= acpi_device_remove
,
556 .uevent
= acpi_device_uevent
,
559 static int acpi_device_register(struct acpi_device
*device
)
562 struct acpi_device_bus_id
*acpi_device_bus_id
, *new_bus_id
;
568 * Link this device to its parent and siblings.
570 INIT_LIST_HEAD(&device
->children
);
571 INIT_LIST_HEAD(&device
->node
);
572 INIT_LIST_HEAD(&device
->wakeup_list
);
573 INIT_LIST_HEAD(&device
->physical_node_list
);
574 mutex_init(&device
->physical_node_lock
);
576 new_bus_id
= kzalloc(sizeof(struct acpi_device_bus_id
), GFP_KERNEL
);
578 printk(KERN_ERR PREFIX
"Memory allocation error\n");
582 mutex_lock(&acpi_device_lock
);
584 * Find suitable bus_id and instance number in acpi_bus_id_list
585 * If failed, create one and link it into acpi_bus_id_list
587 list_for_each_entry(acpi_device_bus_id
, &acpi_bus_id_list
, node
) {
588 if (!strcmp(acpi_device_bus_id
->bus_id
,
589 acpi_device_hid(device
))) {
590 acpi_device_bus_id
->instance_no
++;
597 acpi_device_bus_id
= new_bus_id
;
598 strcpy(acpi_device_bus_id
->bus_id
, acpi_device_hid(device
));
599 acpi_device_bus_id
->instance_no
= 0;
600 list_add_tail(&acpi_device_bus_id
->node
, &acpi_bus_id_list
);
602 dev_set_name(&device
->dev
, "%s:%02x", acpi_device_bus_id
->bus_id
, acpi_device_bus_id
->instance_no
);
605 list_add_tail(&device
->node
, &device
->parent
->children
);
607 if (device
->wakeup
.flags
.valid
)
608 list_add_tail(&device
->wakeup_list
, &acpi_wakeup_device_list
);
609 mutex_unlock(&acpi_device_lock
);
612 device
->dev
.parent
= &device
->parent
->dev
;
613 device
->dev
.bus
= &acpi_bus_type
;
614 device
->dev
.release
= &acpi_device_release
;
615 result
= device_register(&device
->dev
);
617 dev_err(&device
->dev
, "Error registering device\n");
621 result
= acpi_device_setup_files(device
);
623 printk(KERN_ERR PREFIX
"Error creating sysfs interface for device %s\n",
624 dev_name(&device
->dev
));
626 device
->removal_type
= ACPI_BUS_REMOVAL_NORMAL
;
629 mutex_lock(&acpi_device_lock
);
631 list_del(&device
->node
);
632 list_del(&device
->wakeup_list
);
633 mutex_unlock(&acpi_device_lock
);
637 static void acpi_device_unregister(struct acpi_device
*device
, int type
)
639 mutex_lock(&acpi_device_lock
);
641 list_del(&device
->node
);
643 list_del(&device
->wakeup_list
);
644 mutex_unlock(&acpi_device_lock
);
646 acpi_detach_data(device
->handle
, acpi_bus_data_handler
);
648 acpi_device_remove_files(device
);
649 device_unregister(&device
->dev
);
652 /* --------------------------------------------------------------------------
654 -------------------------------------------------------------------------- */
656 * acpi_bus_driver_init - add a device to a driver
657 * @device: the device to add and initialize
658 * @driver: driver for the device
660 * Used to initialize a device via its device driver. Called whenever a
661 * driver is bound to a device. Invokes the driver's add() ops.
664 acpi_bus_driver_init(struct acpi_device
*device
, struct acpi_driver
*driver
)
668 if (!device
|| !driver
)
671 if (!driver
->ops
.add
)
674 result
= driver
->ops
.add(device
);
676 device
->driver
= NULL
;
677 device
->driver_data
= NULL
;
681 device
->driver
= driver
;
684 * TBD - Configuration Management: Assign resources to device based
685 * upon possible configuration and currently allocated resources.
688 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
689 "Driver successfully bound to device\n"));
693 static int acpi_start_single_object(struct acpi_device
*device
)
696 struct acpi_driver
*driver
;
699 if (!(driver
= device
->driver
))
702 if (driver
->ops
.start
) {
703 result
= driver
->ops
.start(device
);
704 if (result
&& driver
->ops
.remove
)
705 driver
->ops
.remove(device
, ACPI_BUS_REMOVAL_NORMAL
);
712 * acpi_bus_register_driver - register a driver with the ACPI bus
713 * @driver: driver being registered
715 * Registers a driver with the ACPI bus. Searches the namespace for all
716 * devices that match the driver's criteria and binds. Returns zero for
717 * success or a negative error status for failure.
719 int acpi_bus_register_driver(struct acpi_driver
*driver
)
725 driver
->drv
.name
= driver
->name
;
726 driver
->drv
.bus
= &acpi_bus_type
;
727 driver
->drv
.owner
= driver
->owner
;
729 ret
= driver_register(&driver
->drv
);
733 EXPORT_SYMBOL(acpi_bus_register_driver
);
736 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
737 * @driver: driver to unregister
739 * Unregisters a driver with the ACPI bus. Searches the namespace for all
740 * devices that match the driver's criteria and unbinds.
742 void acpi_bus_unregister_driver(struct acpi_driver
*driver
)
744 driver_unregister(&driver
->drv
);
747 EXPORT_SYMBOL(acpi_bus_unregister_driver
);
749 /* --------------------------------------------------------------------------
751 -------------------------------------------------------------------------- */
752 static struct acpi_device
*acpi_bus_get_parent(acpi_handle handle
)
756 struct acpi_device
*device
;
759 * Fixed hardware devices do not appear in the namespace and do not
760 * have handles, but we fabricate acpi_devices for them, so we have
761 * to deal with them specially.
767 status
= acpi_get_parent(handle
, &handle
);
768 if (status
== AE_NULL_ENTRY
)
770 if (ACPI_FAILURE(status
))
773 ret
= acpi_bus_get_device(handle
, &device
);
780 acpi_bus_get_ejd(acpi_handle handle
, acpi_handle
*ejd
)
784 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
785 union acpi_object
*obj
;
787 status
= acpi_get_handle(handle
, "_EJD", &tmp
);
788 if (ACPI_FAILURE(status
))
791 status
= acpi_evaluate_object(handle
, "_EJD", NULL
, &buffer
);
792 if (ACPI_SUCCESS(status
)) {
793 obj
= buffer
.pointer
;
794 status
= acpi_get_handle(ACPI_ROOT_OBJECT
, obj
->string
.pointer
,
796 kfree(buffer
.pointer
);
800 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd
);
802 void acpi_bus_data_handler(acpi_handle handle
, void *context
)
810 static int acpi_bus_get_perf_flags(struct acpi_device
*device
)
812 device
->performance
.state
= ACPI_STATE_UNKNOWN
;
817 acpi_bus_extract_wakeup_device_power_package(acpi_handle handle
,
818 struct acpi_device_wakeup
*wakeup
)
820 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
821 union acpi_object
*package
= NULL
;
822 union acpi_object
*element
= NULL
;
827 return AE_BAD_PARAMETER
;
830 status
= acpi_evaluate_object(handle
, "_PRW", NULL
, &buffer
);
831 if (ACPI_FAILURE(status
)) {
832 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PRW"));
836 package
= (union acpi_object
*)buffer
.pointer
;
838 if (!package
|| (package
->package
.count
< 2)) {
839 status
= AE_BAD_DATA
;
843 element
= &(package
->package
.elements
[0]);
845 status
= AE_BAD_DATA
;
848 if (element
->type
== ACPI_TYPE_PACKAGE
) {
849 if ((element
->package
.count
< 2) ||
850 (element
->package
.elements
[0].type
!=
851 ACPI_TYPE_LOCAL_REFERENCE
)
852 || (element
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
)) {
853 status
= AE_BAD_DATA
;
857 element
->package
.elements
[0].reference
.handle
;
859 (u32
) element
->package
.elements
[1].integer
.value
;
860 } else if (element
->type
== ACPI_TYPE_INTEGER
) {
861 wakeup
->gpe_device
= NULL
;
862 wakeup
->gpe_number
= element
->integer
.value
;
864 status
= AE_BAD_DATA
;
868 element
= &(package
->package
.elements
[1]);
869 if (element
->type
!= ACPI_TYPE_INTEGER
) {
870 status
= AE_BAD_DATA
;
873 wakeup
->sleep_state
= element
->integer
.value
;
875 if ((package
->package
.count
- 2) > ACPI_MAX_HANDLES
) {
876 status
= AE_NO_MEMORY
;
879 wakeup
->resources
.count
= package
->package
.count
- 2;
880 for (i
= 0; i
< wakeup
->resources
.count
; i
++) {
881 element
= &(package
->package
.elements
[i
+ 2]);
882 if (element
->type
!= ACPI_TYPE_LOCAL_REFERENCE
) {
883 status
= AE_BAD_DATA
;
887 wakeup
->resources
.handles
[i
] = element
->reference
.handle
;
890 acpi_setup_gpe_for_wake(handle
, wakeup
->gpe_device
, wakeup
->gpe_number
);
893 kfree(buffer
.pointer
);
898 static void acpi_bus_set_run_wake_flags(struct acpi_device
*device
)
900 struct acpi_device_id button_device_ids
[] = {
907 acpi_event_status event_status
;
909 device
->wakeup
.flags
.notifier_present
= 0;
911 /* Power button, Lid switch always enable wakeup */
912 if (!acpi_match_device_ids(device
, button_device_ids
)) {
913 device
->wakeup
.flags
.run_wake
= 1;
914 device_set_wakeup_capable(&device
->dev
, true);
918 status
= acpi_get_gpe_status(device
->wakeup
.gpe_device
,
919 device
->wakeup
.gpe_number
,
922 device
->wakeup
.flags
.run_wake
=
923 !!(event_status
& ACPI_EVENT_FLAG_HANDLE
);
926 static void acpi_bus_get_wakeup_device_flags(struct acpi_device
*device
)
929 acpi_status status
= 0;
932 /* Presence of _PRW indicates wake capable */
933 status
= acpi_get_handle(device
->handle
, "_PRW", &temp
);
934 if (ACPI_FAILURE(status
))
937 status
= acpi_bus_extract_wakeup_device_power_package(device
->handle
,
939 if (ACPI_FAILURE(status
)) {
940 ACPI_EXCEPTION((AE_INFO
, status
, "Extracting _PRW package"));
944 device
->wakeup
.flags
.valid
= 1;
945 device
->wakeup
.prepare_count
= 0;
946 acpi_bus_set_run_wake_flags(device
);
947 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
948 * system for the ACPI device with the _PRW object.
949 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
950 * So it is necessary to call _DSW object first. Only when it is not
951 * present will the _PSW object used.
953 psw_error
= acpi_device_sleep_wake(device
, 0, 0, 0);
955 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
956 "error in _DSW or _PSW evaluation\n"));
959 static void acpi_bus_add_power_resource(acpi_handle handle
);
961 static int acpi_bus_get_power_flags(struct acpi_device
*device
)
963 acpi_status status
= 0;
964 acpi_handle handle
= NULL
;
969 * Power Management Flags
971 status
= acpi_get_handle(device
->handle
, "_PSC", &handle
);
972 if (ACPI_SUCCESS(status
))
973 device
->power
.flags
.explicit_get
= 1;
974 status
= acpi_get_handle(device
->handle
, "_IRC", &handle
);
975 if (ACPI_SUCCESS(status
))
976 device
->power
.flags
.inrush_current
= 1;
979 * Enumerate supported power management states
981 for (i
= ACPI_STATE_D0
; i
<= ACPI_STATE_D3_HOT
; i
++) {
982 struct acpi_device_power_state
*ps
= &device
->power
.states
[i
];
983 char object_name
[5] = { '_', 'P', 'R', '0' + i
, '\0' };
985 /* Evaluate "_PRx" to se if power resources are referenced */
986 acpi_evaluate_reference(device
->handle
, object_name
, NULL
,
988 if (ps
->resources
.count
) {
991 device
->power
.flags
.power_resources
= 1;
992 for (j
= 0; j
< ps
->resources
.count
; j
++)
993 acpi_bus_add_power_resource(ps
->resources
.handles
[j
]);
996 /* Evaluate "_PSx" to see if we can do explicit sets */
997 object_name
[2] = 'S';
998 status
= acpi_get_handle(device
->handle
, object_name
, &handle
);
999 if (ACPI_SUCCESS(status
))
1000 ps
->flags
.explicit_set
= 1;
1003 * State is valid if there are means to put the device into it.
1004 * D3hot is only valid if _PR3 present.
1006 if (ps
->resources
.count
||
1007 (ps
->flags
.explicit_set
&& i
< ACPI_STATE_D3_HOT
))
1008 ps
->flags
.valid
= 1;
1010 ps
->power
= -1; /* Unknown - driver assigned */
1011 ps
->latency
= -1; /* Unknown - driver assigned */
1014 /* Set defaults for D0 and D3 states (always valid) */
1015 device
->power
.states
[ACPI_STATE_D0
].flags
.valid
= 1;
1016 device
->power
.states
[ACPI_STATE_D0
].power
= 100;
1017 device
->power
.states
[ACPI_STATE_D3
].flags
.valid
= 1;
1018 device
->power
.states
[ACPI_STATE_D3
].power
= 0;
1020 /* Set D3cold's explicit_set flag if _PS3 exists. */
1021 if (device
->power
.states
[ACPI_STATE_D3_HOT
].flags
.explicit_set
)
1022 device
->power
.states
[ACPI_STATE_D3_COLD
].flags
.explicit_set
= 1;
1024 acpi_bus_init_power(device
);
1029 static int acpi_bus_get_flags(struct acpi_device
*device
)
1031 acpi_status status
= AE_OK
;
1032 acpi_handle temp
= NULL
;
1035 /* Presence of _STA indicates 'dynamic_status' */
1036 status
= acpi_get_handle(device
->handle
, "_STA", &temp
);
1037 if (ACPI_SUCCESS(status
))
1038 device
->flags
.dynamic_status
= 1;
1040 /* Presence of _RMV indicates 'removable' */
1041 status
= acpi_get_handle(device
->handle
, "_RMV", &temp
);
1042 if (ACPI_SUCCESS(status
))
1043 device
->flags
.removable
= 1;
1045 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
1046 status
= acpi_get_handle(device
->handle
, "_EJD", &temp
);
1047 if (ACPI_SUCCESS(status
))
1048 device
->flags
.ejectable
= 1;
1050 status
= acpi_get_handle(device
->handle
, "_EJ0", &temp
);
1051 if (ACPI_SUCCESS(status
))
1052 device
->flags
.ejectable
= 1;
1055 /* Presence of _LCK indicates 'lockable' */
1056 status
= acpi_get_handle(device
->handle
, "_LCK", &temp
);
1057 if (ACPI_SUCCESS(status
))
1058 device
->flags
.lockable
= 1;
1060 /* Power resources cannot be power manageable. */
1061 if (device
->device_type
== ACPI_BUS_TYPE_POWER
)
1064 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1065 status
= acpi_get_handle(device
->handle
, "_PS0", &temp
);
1066 if (ACPI_FAILURE(status
))
1067 status
= acpi_get_handle(device
->handle
, "_PR0", &temp
);
1068 if (ACPI_SUCCESS(status
))
1069 device
->flags
.power_manageable
= 1;
1071 /* TBD: Performance management */
1076 static void acpi_device_get_busid(struct acpi_device
*device
)
1078 char bus_id
[5] = { '?', 0 };
1079 struct acpi_buffer buffer
= { sizeof(bus_id
), bus_id
};
1085 * The device's Bus ID is simply the object name.
1086 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
1088 if (ACPI_IS_ROOT_DEVICE(device
)) {
1089 strcpy(device
->pnp
.bus_id
, "ACPI");
1093 switch (device
->device_type
) {
1094 case ACPI_BUS_TYPE_POWER_BUTTON
:
1095 strcpy(device
->pnp
.bus_id
, "PWRF");
1097 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
1098 strcpy(device
->pnp
.bus_id
, "SLPF");
1101 acpi_get_name(device
->handle
, ACPI_SINGLE_NAME
, &buffer
);
1102 /* Clean up trailing underscores (if any) */
1103 for (i
= 3; i
> 1; i
--) {
1104 if (bus_id
[i
] == '_')
1109 strcpy(device
->pnp
.bus_id
, bus_id
);
1115 * acpi_bay_match - see if a device is an ejectable driver bay
1117 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
1118 * then we can safely call it an ejectable drive bay
1120 static int acpi_bay_match(struct acpi_device
*device
){
1124 acpi_handle phandle
;
1126 handle
= device
->handle
;
1128 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
1129 if (ACPI_FAILURE(status
))
1132 if ((ACPI_SUCCESS(acpi_get_handle(handle
, "_GTF", &tmp
))) ||
1133 (ACPI_SUCCESS(acpi_get_handle(handle
, "_GTM", &tmp
))) ||
1134 (ACPI_SUCCESS(acpi_get_handle(handle
, "_STM", &tmp
))) ||
1135 (ACPI_SUCCESS(acpi_get_handle(handle
, "_SDD", &tmp
))))
1138 if (acpi_get_parent(handle
, &phandle
))
1141 if ((ACPI_SUCCESS(acpi_get_handle(phandle
, "_GTF", &tmp
))) ||
1142 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_GTM", &tmp
))) ||
1143 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_STM", &tmp
))) ||
1144 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_SDD", &tmp
))))
1151 * acpi_dock_match - see if a device has a _DCK method
1153 static int acpi_dock_match(struct acpi_device
*device
)
1156 return acpi_get_handle(device
->handle
, "_DCK", &tmp
);
1159 const char *acpi_device_hid(struct acpi_device
*device
)
1161 struct acpi_hardware_id
*hid
;
1163 if (list_empty(&device
->pnp
.ids
))
1166 hid
= list_first_entry(&device
->pnp
.ids
, struct acpi_hardware_id
, list
);
1169 EXPORT_SYMBOL(acpi_device_hid
);
1171 static void acpi_add_id(struct acpi_device
*device
, const char *dev_id
)
1173 struct acpi_hardware_id
*id
;
1175 id
= kmalloc(sizeof(*id
), GFP_KERNEL
);
1179 id
->id
= kstrdup(dev_id
, GFP_KERNEL
);
1185 list_add_tail(&id
->list
, &device
->pnp
.ids
);
1189 * Old IBM workstations have a DSDT bug wherein the SMBus object
1190 * lacks the SMBUS01 HID and the methods do not have the necessary "_"
1191 * prefix. Work around this.
1193 static int acpi_ibm_smbus_match(struct acpi_device
*device
)
1195 acpi_handle h_dummy
;
1196 struct acpi_buffer path
= {ACPI_ALLOCATE_BUFFER
, NULL
};
1199 if (!dmi_name_in_vendors("IBM"))
1202 /* Look for SMBS object */
1203 result
= acpi_get_name(device
->handle
, ACPI_SINGLE_NAME
, &path
);
1207 if (strcmp("SMBS", path
.pointer
)) {
1212 /* Does it have the necessary (but misnamed) methods? */
1214 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "SBI", &h_dummy
)) &&
1215 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "SBR", &h_dummy
)) &&
1216 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "SBW", &h_dummy
)))
1219 kfree(path
.pointer
);
1223 static void acpi_device_set_id(struct acpi_device
*device
)
1226 struct acpi_device_info
*info
;
1227 struct acpica_device_id_list
*cid_list
;
1230 switch (device
->device_type
) {
1231 case ACPI_BUS_TYPE_DEVICE
:
1232 if (ACPI_IS_ROOT_DEVICE(device
)) {
1233 acpi_add_id(device
, ACPI_SYSTEM_HID
);
1237 status
= acpi_get_object_info(device
->handle
, &info
);
1238 if (ACPI_FAILURE(status
)) {
1239 printk(KERN_ERR PREFIX
"%s: Error reading device info\n", __func__
);
1243 if (info
->valid
& ACPI_VALID_HID
)
1244 acpi_add_id(device
, info
->hardware_id
.string
);
1245 if (info
->valid
& ACPI_VALID_CID
) {
1246 cid_list
= &info
->compatible_id_list
;
1247 for (i
= 0; i
< cid_list
->count
; i
++)
1248 acpi_add_id(device
, cid_list
->ids
[i
].string
);
1250 if (info
->valid
& ACPI_VALID_ADR
) {
1251 device
->pnp
.bus_address
= info
->address
;
1252 device
->flags
.bus_address
= 1;
1258 * Some devices don't reliably have _HIDs & _CIDs, so add
1259 * synthetic HIDs to make sure drivers can find them.
1261 if (acpi_is_video_device(device
))
1262 acpi_add_id(device
, ACPI_VIDEO_HID
);
1263 else if (ACPI_SUCCESS(acpi_bay_match(device
)))
1264 acpi_add_id(device
, ACPI_BAY_HID
);
1265 else if (ACPI_SUCCESS(acpi_dock_match(device
)))
1266 acpi_add_id(device
, ACPI_DOCK_HID
);
1267 else if (!acpi_ibm_smbus_match(device
))
1268 acpi_add_id(device
, ACPI_SMBUS_IBM_HID
);
1269 else if (!acpi_device_hid(device
) &&
1270 ACPI_IS_ROOT_DEVICE(device
->parent
)) {
1271 acpi_add_id(device
, ACPI_BUS_HID
); /* \_SB, LNXSYBUS */
1272 strcpy(device
->pnp
.device_name
, ACPI_BUS_DEVICE_NAME
);
1273 strcpy(device
->pnp
.device_class
, ACPI_BUS_CLASS
);
1277 case ACPI_BUS_TYPE_POWER
:
1278 acpi_add_id(device
, ACPI_POWER_HID
);
1280 case ACPI_BUS_TYPE_PROCESSOR
:
1281 acpi_add_id(device
, ACPI_PROCESSOR_OBJECT_HID
);
1283 case ACPI_BUS_TYPE_THERMAL
:
1284 acpi_add_id(device
, ACPI_THERMAL_HID
);
1286 case ACPI_BUS_TYPE_POWER_BUTTON
:
1287 acpi_add_id(device
, ACPI_BUTTON_HID_POWERF
);
1289 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
1290 acpi_add_id(device
, ACPI_BUTTON_HID_SLEEPF
);
1295 static int acpi_device_set_context(struct acpi_device
*device
)
1302 * Attach this 'struct acpi_device' to the ACPI object. This makes
1303 * resolutions from handle->device very efficient. Fixed hardware
1304 * devices have no handles, so we skip them.
1306 if (!device
->handle
)
1309 status
= acpi_attach_data(device
->handle
,
1310 acpi_bus_data_handler
, device
);
1311 if (ACPI_SUCCESS(status
))
1314 printk(KERN_ERR PREFIX
"Error attaching device data\n");
1318 static int acpi_bus_remove(struct acpi_device
*dev
, int rmdevice
)
1323 dev
->removal_type
= ACPI_BUS_REMOVAL_EJECT
;
1324 device_release_driver(&dev
->dev
);
1330 * unbind _ADR-Based Devices when hot removal
1332 if (dev
->flags
.bus_address
) {
1333 if ((dev
->parent
) && (dev
->parent
->ops
.unbind
))
1334 dev
->parent
->ops
.unbind(dev
);
1336 acpi_device_unregister(dev
, ACPI_BUS_REMOVAL_EJECT
);
1341 static int acpi_add_single_object(struct acpi_device
**child
,
1342 acpi_handle handle
, int type
,
1343 unsigned long long sta
,
1344 struct acpi_bus_ops
*ops
)
1347 struct acpi_device
*device
;
1348 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1350 device
= kzalloc(sizeof(struct acpi_device
), GFP_KERNEL
);
1352 printk(KERN_ERR PREFIX
"Memory allocation error\n");
1356 INIT_LIST_HEAD(&device
->pnp
.ids
);
1357 device
->device_type
= type
;
1358 device
->handle
= handle
;
1359 device
->parent
= acpi_bus_get_parent(handle
);
1360 device
->bus_ops
= *ops
; /* workround for not call .start */
1361 STRUCT_TO_INT(device
->status
) = sta
;
1363 acpi_device_get_busid(device
);
1368 * Note that we only look for object handles -- cannot evaluate objects
1369 * until we know the device is present and properly initialized.
1371 result
= acpi_bus_get_flags(device
);
1378 * TBD: Synch with Core's enumeration/initialization process.
1380 acpi_device_set_id(device
);
1386 if (device
->flags
.power_manageable
) {
1387 result
= acpi_bus_get_power_flags(device
);
1393 * Wakeup device management
1394 *-----------------------
1396 acpi_bus_get_wakeup_device_flags(device
);
1399 * Performance Management
1400 * ----------------------
1402 if (device
->flags
.performance_manageable
) {
1403 result
= acpi_bus_get_perf_flags(device
);
1408 if ((result
= acpi_device_set_context(device
)))
1411 result
= acpi_device_register(device
);
1414 * Bind _ADR-Based Devices when hot add
1416 if (device
->flags
.bus_address
) {
1417 if (device
->parent
&& device
->parent
->ops
.bind
)
1418 device
->parent
->ops
.bind(device
);
1423 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
1424 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1425 "Adding %s [%s] parent %s\n", dev_name(&device
->dev
),
1426 (char *) buffer
.pointer
,
1427 device
->parent
? dev_name(&device
->parent
->dev
) :
1429 kfree(buffer
.pointer
);
1432 acpi_device_release(&device
->dev
);
1437 #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
1438 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
1440 static void acpi_bus_add_power_resource(acpi_handle handle
)
1442 struct acpi_bus_ops ops
= {
1446 struct acpi_device
*device
= NULL
;
1448 acpi_bus_get_device(handle
, &device
);
1450 acpi_add_single_object(&device
, handle
, ACPI_BUS_TYPE_POWER
,
1451 ACPI_STA_DEFAULT
, &ops
);
1454 static int acpi_bus_type_and_status(acpi_handle handle
, int *type
,
1455 unsigned long long *sta
)
1458 acpi_object_type acpi_type
;
1460 status
= acpi_get_type(handle
, &acpi_type
);
1461 if (ACPI_FAILURE(status
))
1464 switch (acpi_type
) {
1465 case ACPI_TYPE_ANY
: /* for ACPI_ROOT_OBJECT */
1466 case ACPI_TYPE_DEVICE
:
1467 *type
= ACPI_BUS_TYPE_DEVICE
;
1468 status
= acpi_bus_get_status_handle(handle
, sta
);
1469 if (ACPI_FAILURE(status
))
1472 case ACPI_TYPE_PROCESSOR
:
1473 *type
= ACPI_BUS_TYPE_PROCESSOR
;
1474 status
= acpi_bus_get_status_handle(handle
, sta
);
1475 if (ACPI_FAILURE(status
))
1478 case ACPI_TYPE_THERMAL
:
1479 *type
= ACPI_BUS_TYPE_THERMAL
;
1480 *sta
= ACPI_STA_DEFAULT
;
1482 case ACPI_TYPE_POWER
:
1483 *type
= ACPI_BUS_TYPE_POWER
;
1484 *sta
= ACPI_STA_DEFAULT
;
1493 static acpi_status
acpi_bus_check_add(acpi_handle handle
, u32 lvl
,
1494 void *context
, void **return_value
)
1496 struct acpi_bus_ops
*ops
= context
;
1498 unsigned long long sta
;
1499 struct acpi_device
*device
;
1503 result
= acpi_bus_type_and_status(handle
, &type
, &sta
);
1507 if (!(sta
& ACPI_STA_DEVICE_PRESENT
) &&
1508 !(sta
& ACPI_STA_DEVICE_FUNCTIONING
)) {
1509 struct acpi_device_wakeup wakeup
;
1512 status
= acpi_get_handle(handle
, "_PRW", &temp
);
1513 if (ACPI_SUCCESS(status
))
1514 acpi_bus_extract_wakeup_device_power_package(handle
,
1516 return AE_CTRL_DEPTH
;
1520 * We may already have an acpi_device from a previous enumeration. If
1521 * so, we needn't add it again, but we may still have to start it.
1524 acpi_bus_get_device(handle
, &device
);
1525 if (ops
->acpi_op_add
&& !device
) {
1526 acpi_add_single_object(&device
, handle
, type
, sta
, ops
);
1527 /* Is the device a known good platform device? */
1529 && !acpi_match_device_ids(device
, acpi_platform_device_ids
))
1530 acpi_create_platform_device(device
);
1534 return AE_CTRL_DEPTH
;
1536 if (ops
->acpi_op_start
&& !(ops
->acpi_op_add
)) {
1537 status
= acpi_start_single_object(device
);
1538 if (ACPI_FAILURE(status
))
1539 return AE_CTRL_DEPTH
;
1543 *return_value
= device
;
1547 static int acpi_bus_scan(acpi_handle handle
, struct acpi_bus_ops
*ops
,
1548 struct acpi_device
**child
)
1551 void *device
= NULL
;
1553 status
= acpi_bus_check_add(handle
, 0, ops
, &device
);
1554 if (ACPI_SUCCESS(status
))
1555 acpi_walk_namespace(ACPI_TYPE_ANY
, handle
, ACPI_UINT32_MAX
,
1556 acpi_bus_check_add
, NULL
, ops
, &device
);
1568 * acpi_bus_add and acpi_bus_start
1570 * scan a given ACPI tree and (probably recently hot-plugged)
1571 * create and add or starts found devices.
1573 * If no devices were found -ENODEV is returned which does not
1574 * mean that this is a real error, there just have been no suitable
1575 * ACPI objects in the table trunk from which the kernel could create
1576 * a device and add/start an appropriate driver.
1580 acpi_bus_add(struct acpi_device
**child
,
1581 struct acpi_device
*parent
, acpi_handle handle
, int type
)
1583 struct acpi_bus_ops ops
;
1585 memset(&ops
, 0, sizeof(ops
));
1586 ops
.acpi_op_add
= 1;
1588 return acpi_bus_scan(handle
, &ops
, child
);
1590 EXPORT_SYMBOL(acpi_bus_add
);
1592 int acpi_bus_start(struct acpi_device
*device
)
1594 struct acpi_bus_ops ops
;
1600 memset(&ops
, 0, sizeof(ops
));
1601 ops
.acpi_op_start
= 1;
1603 result
= acpi_bus_scan(device
->handle
, &ops
, NULL
);
1605 acpi_update_all_gpes();
1609 EXPORT_SYMBOL(acpi_bus_start
);
1611 int acpi_bus_trim(struct acpi_device
*start
, int rmdevice
)
1614 struct acpi_device
*parent
, *child
;
1615 acpi_handle phandle
, chandle
;
1616 acpi_object_type type
;
1621 phandle
= start
->handle
;
1622 child
= chandle
= NULL
;
1624 while ((level
> 0) && parent
&& (!err
)) {
1625 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
1629 * If this scope is exhausted then move our way back up.
1631 if (ACPI_FAILURE(status
)) {
1634 acpi_get_parent(phandle
, &phandle
);
1636 parent
= parent
->parent
;
1639 err
= acpi_bus_remove(child
, rmdevice
);
1641 err
= acpi_bus_remove(child
, 1);
1646 status
= acpi_get_type(chandle
, &type
);
1647 if (ACPI_FAILURE(status
)) {
1651 * If there is a device corresponding to chandle then
1652 * parse it (depth-first).
1654 if (acpi_bus_get_device(chandle
, &child
) == 0) {
1664 EXPORT_SYMBOL_GPL(acpi_bus_trim
);
1666 static int acpi_bus_scan_fixed(void)
1669 struct acpi_device
*device
= NULL
;
1670 struct acpi_bus_ops ops
;
1672 memset(&ops
, 0, sizeof(ops
));
1673 ops
.acpi_op_add
= 1;
1674 ops
.acpi_op_start
= 1;
1677 * Enumerate all fixed-feature devices.
1679 if ((acpi_gbl_FADT
.flags
& ACPI_FADT_POWER_BUTTON
) == 0) {
1680 result
= acpi_add_single_object(&device
, NULL
,
1681 ACPI_BUS_TYPE_POWER_BUTTON
,
1684 device_init_wakeup(&device
->dev
, true);
1687 if ((acpi_gbl_FADT
.flags
& ACPI_FADT_SLEEP_BUTTON
) == 0) {
1688 result
= acpi_add_single_object(&device
, NULL
,
1689 ACPI_BUS_TYPE_SLEEP_BUTTON
,
1697 int __init
acpi_scan_init(void)
1700 struct acpi_bus_ops ops
;
1702 memset(&ops
, 0, sizeof(ops
));
1703 ops
.acpi_op_add
= 1;
1704 ops
.acpi_op_start
= 1;
1706 result
= bus_register(&acpi_bus_type
);
1708 /* We don't want to quit even if we failed to add suspend/resume */
1709 printk(KERN_ERR PREFIX
"Could not register bus type\n");
1715 * Enumerate devices in the ACPI namespace.
1717 result
= acpi_bus_scan(ACPI_ROOT_OBJECT
, &ops
, &acpi_root
);
1720 result
= acpi_bus_scan_fixed();
1723 acpi_device_unregister(acpi_root
, ACPI_BUS_REMOVAL_NORMAL
);
1725 acpi_update_all_gpes();