2 * scan.c - support for transforming the ACPI namespace into individual objects
5 #include <linux/init.h>
6 #include <linux/acpi.h>
7 #include <linux/module.h>
9 #include <acpi/acpi_drivers.h>
10 #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
13 #define _COMPONENT ACPI_BUS_COMPONENT
14 ACPI_MODULE_NAME ("scan")
16 #define STRUCT_TO_INT(s) (*((int*)&s))
18 extern struct acpi_device *acpi_root;
21 #define ACPI_BUS_CLASS "system_bus"
22 #define ACPI_BUS_HID "ACPI_BUS"
23 #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
24 #define ACPI_BUS_DEVICE_NAME "System Bus"
26 static LIST_HEAD(acpi_device_list);
27 spinlock_t acpi_device_lock = SPIN_LOCK_UNLOCKED;
28 LIST_HEAD(acpi_wakeup_device_list);
30 static void acpi_device_release(struct kobject * kobj)
32 struct acpi_device * dev = container_of(kobj,struct acpi_device,kobj);
33 if (dev->pnp.cid_list)
34 kfree(dev->pnp.cid_list);
38 static struct kobj_type ktype_acpi_ns = {
39 .release = acpi_device_release,
42 static struct kset acpi_namespace_kset = {
46 .subsys = &acpi_subsys,
47 .ktype = &ktype_acpi_ns,
51 static void acpi_device_register(struct acpi_device * device, struct acpi_device * parent)
56 * Link this device to its parent and siblings.
58 INIT_LIST_HEAD(&device->children);
59 INIT_LIST_HEAD(&device->node);
60 INIT_LIST_HEAD(&device->g_list);
62 spin_lock(&acpi_device_lock);
64 list_add_tail(&device->node, &device->parent->children);
65 list_add_tail(&device->g_list,&device->parent->g_list);
67 list_add_tail(&device->g_list,&acpi_device_list);
68 spin_unlock(&acpi_device_lock);
70 kobject_init(&device->kobj);
71 strlcpy(device->kobj.name,device->pnp.bus_id,KOBJ_NAME_LEN);
73 device->kobj.parent = &parent->kobj;
74 device->kobj.ktype = &ktype_acpi_ns;
75 device->kobj.kset = &acpi_namespace_kset;
76 kobject_add(&device->kobj);
80 acpi_device_unregister (
81 struct acpi_device *device,
84 kobject_unregister(&device->kobj);
89 acpi_bus_data_handler (
94 ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
102 acpi_bus_get_power_flags (
103 struct acpi_device *device)
105 acpi_status status = 0;
106 acpi_handle handle = NULL;
109 ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
112 * Power Management Flags
114 status = acpi_get_handle(device->handle, "_PSC", &handle);
115 if (ACPI_SUCCESS(status))
116 device->power.flags.explicit_get = 1;
117 status = acpi_get_handle(device->handle, "_IRC", &handle);
118 if (ACPI_SUCCESS(status))
119 device->power.flags.inrush_current = 1;
122 * Enumerate supported power management states
124 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
125 struct acpi_device_power_state *ps = &device->power.states[i];
126 char object_name[5] = {'_','P','R','0'+i,'\0'};
128 /* Evaluate "_PRx" to se if power resources are referenced */
129 acpi_evaluate_reference(device->handle, object_name, NULL,
131 if (ps->resources.count) {
132 device->power.flags.power_resources = 1;
136 /* Evaluate "_PSx" to see if we can do explicit sets */
137 object_name[2] = 'S';
138 status = acpi_get_handle(device->handle, object_name, &handle);
139 if (ACPI_SUCCESS(status)) {
140 ps->flags.explicit_set = 1;
144 /* State is valid if we have some power control */
145 if (ps->resources.count || ps->flags.explicit_set)
148 ps->power = -1; /* Unknown - driver assigned */
149 ps->latency = -1; /* Unknown - driver assigned */
152 /* Set defaults for D0 and D3 states (always valid) */
153 device->power.states[ACPI_STATE_D0].flags.valid = 1;
154 device->power.states[ACPI_STATE_D0].power = 100;
155 device->power.states[ACPI_STATE_D3].flags.valid = 1;
156 device->power.states[ACPI_STATE_D3].power = 0;
158 /* TBD: System wake support and resource requirements. */
160 device->power.state = ACPI_STATE_UNKNOWN;
167 struct acpi_device *device,
171 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
173 if (device->flags.hardware_id)
174 if (strstr(ids, device->pnp.hardware_id))
177 if (device->flags.compatible_ids) {
178 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
181 /* compare multiple _CID entries against driver ids */
182 for (i = 0; i < cid_list->count; i++)
184 if (strstr(ids, cid_list->id[i].value))
192 acpi_os_free(buffer.pointer);
197 acpi_bus_extract_wakeup_device_power_package (
198 struct acpi_device *device,
199 union acpi_object *package)
202 union acpi_object *element = NULL;
204 if (!device || !package || (package->package.count < 2))
205 return AE_BAD_PARAMETER;
207 element = &(package->package.elements[0]);
209 return AE_BAD_PARAMETER;
210 if (element->type == ACPI_TYPE_PACKAGE) {
211 if ((element->package.count < 2) ||
212 (element->package.elements[0].type != ACPI_TYPE_LOCAL_REFERENCE) ||
213 (element->package.elements[1].type != ACPI_TYPE_INTEGER))
215 device->wakeup.gpe_device = element->package.elements[0].reference.handle;
216 device->wakeup.gpe_number = (u32)element->package.elements[1].integer.value;
217 }else if (element->type == ACPI_TYPE_INTEGER) {
218 device->wakeup.gpe_number = element->integer.value;
222 element = &(package->package.elements[1]);
223 if (element->type != ACPI_TYPE_INTEGER) {
226 device->wakeup.sleep_state = element->integer.value;
228 if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
231 device->wakeup.resources.count = package->package.count - 2;
232 for (i=0; i < device->wakeup.resources.count; i++) {
233 element = &(package->package.elements[i + 2]);
234 if (element->type != ACPI_TYPE_ANY ) {
238 device->wakeup.resources.handles[i] = element->reference.handle;
245 acpi_bus_get_wakeup_device_flags (
246 struct acpi_device *device)
248 acpi_status status = 0;
249 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
250 union acpi_object *package = NULL;
252 ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
255 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
256 if (ACPI_FAILURE(status)) {
257 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n"));
261 package = (union acpi_object *) buffer.pointer;
262 status = acpi_bus_extract_wakeup_device_power_package(device, package);
263 if (ACPI_FAILURE(status)) {
264 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error extracting _PRW package\n"));
268 acpi_os_free(buffer.pointer);
270 device->wakeup.flags.valid = 1;
271 /* Power button, Lid switch always enable wakeup*/
272 if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
273 device->wakeup.flags.run_wake = 1;
276 INIT_LIST_HEAD(&device->wakeup_list);
277 spin_lock(&acpi_device_lock);
278 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
279 spin_unlock(&acpi_device_lock);
282 if (ACPI_FAILURE(status))
283 device->flags.wake_capable = 0;
287 /* --------------------------------------------------------------------------
288 Performance Management
289 -------------------------------------------------------------------------- */
292 acpi_bus_get_perf_flags (
293 struct acpi_device *device)
295 device->performance.state = ACPI_STATE_UNKNOWN;
299 /* --------------------------------------------------------------------------
301 -------------------------------------------------------------------------- */
303 static LIST_HEAD(acpi_bus_drivers);
304 static DECLARE_MUTEX(acpi_bus_drivers_lock);
310 * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
311 * matches the specified driver's criteria.
315 struct acpi_device *device,
316 struct acpi_driver *driver)
318 if (driver && driver->ops.match)
319 return driver->ops.match(device, driver);
320 return acpi_match_ids(device, driver->ids);
325 * acpi_bus_driver_init
326 * --------------------
327 * Used to initialize a device via its device driver. Called whenever a
328 * driver is bound to a device. Invokes the driver's add() and start() ops.
331 acpi_bus_driver_init (
332 struct acpi_device *device,
333 struct acpi_driver *driver)
337 ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
339 if (!device || !driver)
340 return_VALUE(-EINVAL);
342 if (!driver->ops.add)
343 return_VALUE(-ENOSYS);
345 result = driver->ops.add(device);
347 device->driver = NULL;
348 acpi_driver_data(device) = NULL;
349 return_VALUE(result);
352 device->driver = driver;
355 * TBD - Configuration Management: Assign resources to device based
356 * upon possible configuration and currently allocated resources.
359 if (driver->ops.start) {
360 result = driver->ops.start(device);
361 if (result && driver->ops.remove)
362 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
363 return_VALUE(result);
366 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n"));
368 if (driver->ops.scan) {
369 driver->ops.scan(device);
375 static int acpi_driver_attach(struct acpi_driver * drv)
377 struct list_head * node, * next;
380 ACPI_FUNCTION_TRACE("acpi_driver_attach");
382 spin_lock(&acpi_device_lock);
383 list_for_each_safe(node, next, &acpi_device_list) {
384 struct acpi_device * dev = container_of(node, struct acpi_device, g_list);
386 if (dev->driver || !dev->status.present)
388 spin_unlock(&acpi_device_lock);
390 if (!acpi_bus_match(dev, drv)) {
391 if (!acpi_bus_driver_init(dev, drv)) {
392 atomic_inc(&drv->references);
394 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
395 drv->name, dev->pnp.bus_id));
398 spin_lock(&acpi_device_lock);
400 spin_unlock(&acpi_device_lock);
404 static int acpi_driver_detach(struct acpi_driver * drv)
406 struct list_head * node, * next;
408 ACPI_FUNCTION_TRACE("acpi_driver_detach");
410 spin_lock(&acpi_device_lock);
411 list_for_each_safe(node,next,&acpi_device_list) {
412 struct acpi_device * dev = container_of(node,struct acpi_device,g_list);
414 if (dev->driver == drv) {
415 spin_unlock(&acpi_device_lock);
417 drv->ops.remove(dev,ACPI_BUS_REMOVAL_NORMAL);
418 spin_lock(&acpi_device_lock);
420 dev->driver_data = NULL;
421 atomic_dec(&drv->references);
424 spin_unlock(&acpi_device_lock);
429 * acpi_bus_register_driver
430 * ------------------------
431 * Registers a driver with the ACPI bus. Searches the namespace for all
432 * devices that match the driver's criteria and binds. Returns the
433 * number of devices that were claimed by the driver, or a negative
434 * error status for failure.
437 acpi_bus_register_driver (
438 struct acpi_driver *driver)
442 ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
445 return_VALUE(-ENODEV);
448 return_VALUE(-EINVAL);
450 spin_lock(&acpi_device_lock);
451 list_add_tail(&driver->node, &acpi_bus_drivers);
452 spin_unlock(&acpi_device_lock);
453 count = acpi_driver_attach(driver);
457 EXPORT_SYMBOL(acpi_bus_register_driver);
461 * acpi_bus_unregister_driver
462 * --------------------------
463 * Unregisters a driver with the ACPI bus. Searches the namespace for all
464 * devices that match the driver's criteria and unbinds.
467 acpi_bus_unregister_driver (
468 struct acpi_driver *driver)
472 ACPI_FUNCTION_TRACE("acpi_bus_unregister_driver");
475 acpi_driver_detach(driver);
477 if (!atomic_read(&driver->references)) {
478 spin_lock(&acpi_device_lock);
479 list_del_init(&driver->node);
480 spin_unlock(&acpi_device_lock);
486 EXPORT_SYMBOL(acpi_bus_unregister_driver);
489 * acpi_bus_find_driver
490 * --------------------
491 * Parses the list of registered drivers looking for a driver applicable for
492 * the specified device.
495 acpi_bus_find_driver (
496 struct acpi_device *device)
499 struct list_head * node, *next;
501 ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
503 spin_lock(&acpi_device_lock);
504 list_for_each_safe(node,next,&acpi_bus_drivers) {
505 struct acpi_driver * driver = container_of(node,struct acpi_driver,node);
507 atomic_inc(&driver->references);
508 spin_unlock(&acpi_device_lock);
509 if (!acpi_bus_match(device, driver)) {
510 result = acpi_bus_driver_init(device, driver);
514 atomic_dec(&driver->references);
515 spin_lock(&acpi_device_lock);
517 spin_unlock(&acpi_device_lock);
520 return_VALUE(result);
524 /* --------------------------------------------------------------------------
526 -------------------------------------------------------------------------- */
530 struct acpi_device *device)
532 acpi_status status = AE_OK;
533 acpi_handle temp = NULL;
535 ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
537 /* Presence of _STA indicates 'dynamic_status' */
538 status = acpi_get_handle(device->handle, "_STA", &temp);
539 if (ACPI_SUCCESS(status))
540 device->flags.dynamic_status = 1;
542 /* Presence of _CID indicates 'compatible_ids' */
543 status = acpi_get_handle(device->handle, "_CID", &temp);
544 if (ACPI_SUCCESS(status))
545 device->flags.compatible_ids = 1;
547 /* Presence of _RMV indicates 'removable' */
548 status = acpi_get_handle(device->handle, "_RMV", &temp);
549 if (ACPI_SUCCESS(status))
550 device->flags.removable = 1;
552 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
553 status = acpi_get_handle(device->handle, "_EJD", &temp);
554 if (ACPI_SUCCESS(status))
555 device->flags.ejectable = 1;
557 status = acpi_get_handle(device->handle, "_EJ0", &temp);
558 if (ACPI_SUCCESS(status))
559 device->flags.ejectable = 1;
562 /* Presence of _LCK indicates 'lockable' */
563 status = acpi_get_handle(device->handle, "_LCK", &temp);
564 if (ACPI_SUCCESS(status))
565 device->flags.lockable = 1;
567 /* Presence of _PS0|_PR0 indicates 'power manageable' */
568 status = acpi_get_handle(device->handle, "_PS0", &temp);
569 if (ACPI_FAILURE(status))
570 status = acpi_get_handle(device->handle, "_PR0", &temp);
571 if (ACPI_SUCCESS(status))
572 device->flags.power_manageable = 1;
574 /* Presence of _PRW indicates wake capable */
575 status = acpi_get_handle(device->handle, "_PRW", &temp);
576 if (ACPI_SUCCESS(status))
577 device->flags.wake_capable = 1;
579 /* TBD: Peformance management */
584 static void acpi_device_get_busid(struct acpi_device * device, acpi_handle handle, int type)
586 char bus_id[5] = {'?',0};
587 struct acpi_buffer buffer = {sizeof(bus_id), bus_id};
593 * The device's Bus ID is simply the object name.
594 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
597 case ACPI_BUS_TYPE_SYSTEM:
598 strcpy(device->pnp.bus_id, "ACPI");
600 case ACPI_BUS_TYPE_POWER_BUTTON:
601 strcpy(device->pnp.bus_id, "PWRF");
603 case ACPI_BUS_TYPE_SLEEP_BUTTON:
604 strcpy(device->pnp.bus_id, "SLPF");
607 acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
608 /* Clean up trailing underscores (if any) */
609 for (i = 3; i > 1; i--) {
610 if (bus_id[i] == '_')
615 strcpy(device->pnp.bus_id, bus_id);
620 static void acpi_device_set_id(struct acpi_device * device, struct acpi_device * parent,
621 acpi_handle handle, int type)
623 struct acpi_device_info *info;
624 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
627 struct acpi_compatible_id_list *cid_list = NULL;
631 case ACPI_BUS_TYPE_DEVICE:
632 status = acpi_get_object_info(handle, &buffer);
633 if (ACPI_FAILURE(status)) {
634 printk("%s: Error reading device info\n",__FUNCTION__);
638 info = buffer.pointer;
639 if (info->valid & ACPI_VALID_HID)
640 hid = info->hardware_id.value;
641 if (info->valid & ACPI_VALID_UID)
642 uid = info->unique_id.value;
643 if (info->valid & ACPI_VALID_CID)
644 cid_list = &info->compatibility_id;
645 if (info->valid & ACPI_VALID_ADR) {
646 device->pnp.bus_address = info->address;
647 device->flags.bus_address = 1;
650 case ACPI_BUS_TYPE_POWER:
651 hid = ACPI_POWER_HID;
653 case ACPI_BUS_TYPE_PROCESSOR:
654 hid = ACPI_PROCESSOR_HID;
656 case ACPI_BUS_TYPE_SYSTEM:
657 hid = ACPI_SYSTEM_HID;
659 case ACPI_BUS_TYPE_THERMAL:
660 hid = ACPI_THERMAL_HID;
662 case ACPI_BUS_TYPE_POWER_BUTTON:
663 hid = ACPI_BUTTON_HID_POWERF;
665 case ACPI_BUS_TYPE_SLEEP_BUTTON:
666 hid = ACPI_BUTTON_HID_SLEEPF;
673 * Fix for the system root bus device -- the only root-level device.
675 if ((parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
677 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
678 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
682 strcpy(device->pnp.hardware_id, hid);
683 device->flags.hardware_id = 1;
686 strcpy(device->pnp.unique_id, uid);
687 device->flags.unique_id = 1;
690 device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
691 if (device->pnp.cid_list)
692 memcpy(device->pnp.cid_list, cid_list, cid_list->size);
694 printk(KERN_ERR "Memory allocation error\n");
697 acpi_os_free(buffer.pointer);
700 int acpi_device_set_context(struct acpi_device * device, int type)
702 acpi_status status = AE_OK;
707 * Attach this 'struct acpi_device' to the ACPI object. This makes
708 * resolutions from handle->device very efficient. Note that we need
709 * to be careful with fixed-feature devices as they all attach to the
712 if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
713 type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
714 status = acpi_attach_data(device->handle,
715 acpi_bus_data_handler, device);
717 if (ACPI_FAILURE(status)) {
718 printk("Error attaching device data\n");
725 void acpi_device_get_debug_info(struct acpi_device * device, acpi_handle handle, int type)
727 #ifdef CONFIG_ACPI_DEBUG_OUTPUT
728 char *type_string = NULL;
729 char name[80] = {'?','\0'};
730 acpi_buffer buffer = {sizeof(name), name};
733 case ACPI_BUS_TYPE_DEVICE:
734 type_string = "Device";
735 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
737 case ACPI_BUS_TYPE_POWER:
738 type_string = "Power Resource";
739 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
741 case ACPI_BUS_TYPE_PROCESSOR:
742 type_string = "Processor";
743 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
745 case ACPI_BUS_TYPE_SYSTEM:
746 type_string = "System";
747 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
749 case ACPI_BUS_TYPE_THERMAL:
750 type_string = "Thermal Zone";
751 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
753 case ACPI_BUS_TYPE_POWER_BUTTON:
754 type_string = "Power Button";
755 sprintf(name, "PWRB");
757 case ACPI_BUS_TYPE_SLEEP_BUTTON:
758 type_string = "Sleep Button";
759 sprintf(name, "SLPB");
763 printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
764 #endif /*CONFIG_ACPI_DEBUG_OUTPUT*/
769 struct acpi_device **child,
770 struct acpi_device *parent,
775 struct acpi_device *device = NULL;
777 ACPI_FUNCTION_TRACE("acpi_bus_add");
780 return_VALUE(-EINVAL);
782 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
784 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n"));
785 return_VALUE(-ENOMEM);
787 memset(device, 0, sizeof(struct acpi_device));
789 device->handle = handle;
790 device->parent = parent;
792 acpi_device_get_busid(device,handle,type);
797 * Get prior to calling acpi_bus_get_status() so we know whether
798 * or not _STA is present. Note that we only look for object
799 * handles -- cannot evaluate objects until we know the device is
800 * present and properly initialized.
802 result = acpi_bus_get_flags(device);
809 * See if the device is present. We always assume that non-Device()
810 * objects (e.g. thermal zones, power resources, processors, etc.) are
811 * present, functioning, etc. (at least when parent object is present).
812 * Note that _STA has a different meaning for some objects (e.g.
813 * power resources) so we need to be careful how we use it.
816 case ACPI_BUS_TYPE_DEVICE:
817 result = acpi_bus_get_status(device);
818 if (ACPI_FAILURE(result) || !device->status.present) {
824 STRUCT_TO_INT(device->status) = 0x0F;
831 * TBD: Synch with Core's enumeration/initialization process.
835 * Hardware ID, Unique ID, & Bus Address
836 * -------------------------------------
838 acpi_device_set_id(device,parent,handle,type);
844 if (device->flags.power_manageable) {
845 result = acpi_bus_get_power_flags(device);
851 * Wakeup device management
852 *-----------------------
854 if (device->flags.wake_capable) {
855 result = acpi_bus_get_wakeup_device_flags(device);
861 * Performance Management
862 * ----------------------
864 if (device->flags.performance_manageable) {
865 result = acpi_bus_get_perf_flags(device);
870 if ((result = acpi_device_set_context(device,type)))
873 acpi_device_get_debug_info(device,handle,type);
875 acpi_device_register(device,parent);
878 * Bind _ADR-Based Devices
879 * -----------------------
880 * If there's a a bus address (_ADR) then we utilize the parent's
881 * 'bind' function (if exists) to bind the ACPI- and natively-
882 * enumerated device representations.
884 if (device->flags.bus_address) {
885 if (device->parent && device->parent->ops.bind)
886 device->parent->ops.bind(device);
890 * Locate & Attach Driver
891 * ----------------------
892 * If there's a hardware id (_HID) or compatible ids (_CID) we check
893 * to see if there's a driver installed for this kind of device. Note
894 * that drivers can install before or after a device is enumerated.
896 * TBD: Assumes LDM provides driver hot-plug capability.
898 acpi_bus_find_driver(device);
904 if (device->pnp.cid_list)
905 kfree(device->pnp.cid_list);
909 return_VALUE(result);
911 EXPORT_SYMBOL(acpi_bus_add);
914 static int acpi_bus_scan (struct acpi_device *start)
916 acpi_status status = AE_OK;
917 struct acpi_device *parent = NULL;
918 struct acpi_device *child = NULL;
919 acpi_handle phandle = NULL;
920 acpi_handle chandle = NULL;
921 acpi_object_type type = 0;
924 ACPI_FUNCTION_TRACE("acpi_bus_scan");
927 return_VALUE(-EINVAL);
930 phandle = start->handle;
933 * Parse through the ACPI namespace, identify all 'devices', and
934 * create a new 'struct acpi_device' for each.
936 while ((level > 0) && parent) {
938 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
942 * If this scope is exhausted then move our way back up.
944 if (ACPI_FAILURE(status)) {
947 acpi_get_parent(phandle, &phandle);
949 parent = parent->parent;
953 status = acpi_get_type(chandle, &type);
954 if (ACPI_FAILURE(status))
958 * If this is a scope object then parse it (depth-first).
960 if (type == ACPI_TYPE_LOCAL_SCOPE) {
968 * We're only interested in objects that we consider 'devices'.
971 case ACPI_TYPE_DEVICE:
972 type = ACPI_BUS_TYPE_DEVICE;
974 case ACPI_TYPE_PROCESSOR:
975 type = ACPI_BUS_TYPE_PROCESSOR;
977 case ACPI_TYPE_THERMAL:
978 type = ACPI_BUS_TYPE_THERMAL;
980 case ACPI_TYPE_POWER:
981 type = ACPI_BUS_TYPE_POWER;
987 status = acpi_bus_add(&child, parent, chandle, type);
988 if (ACPI_FAILURE(status))
992 * If the device is present, enabled, and functioning then
993 * parse its scope (depth-first). Note that we need to
994 * represent absent devices to facilitate PnP notifications
995 * -- but only the subtree head (not all of its children,
996 * which will be enumerated when the parent is inserted).
998 * TBD: Need notifications and other detection mechanisms
999 * in place before we can fully implement this.
1001 if (child->status.present) {
1002 status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
1004 if (ACPI_SUCCESS(status)) {
1015 EXPORT_SYMBOL(acpi_bus_scan);
1019 acpi_bus_scan_fixed (
1020 struct acpi_device *root)
1023 struct acpi_device *device = NULL;
1025 ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
1028 return_VALUE(-ENODEV);
1031 * Enumerate all fixed-feature devices.
1033 if (acpi_fadt.pwr_button == 0)
1034 result = acpi_bus_add(&device, acpi_root,
1035 NULL, ACPI_BUS_TYPE_POWER_BUTTON);
1037 if (acpi_fadt.sleep_button == 0)
1038 result = acpi_bus_add(&device, acpi_root,
1039 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON);
1041 return_VALUE(result);
1045 static int __init acpi_scan_init(void)
1049 ACPI_FUNCTION_TRACE("acpi_scan_init");
1054 kset_register(&acpi_namespace_kset);
1057 * Create the root device in the bus's device tree
1059 result = acpi_bus_add(&acpi_root, NULL, ACPI_ROOT_OBJECT,
1060 ACPI_BUS_TYPE_SYSTEM);
1065 * Enumerate devices in the ACPI namespace.
1067 result = acpi_bus_scan_fixed(acpi_root);
1069 result = acpi_bus_scan(acpi_root);
1072 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1075 return_VALUE(result);
1078 subsys_initcall(acpi_scan_init);