Merge with Linux 2.5.56.
[linux-2.6/linux-mips.git] / drivers / acpi / scan.c
blobe60e9f6d0714dfd2d91c5c1c90ead7e52e8328a9
1 /*
2 * scan.c - support for transforming the ACPI namespace into individual objects
3 */
5 #include <linux/init.h>
6 #include <linux/acpi.h>
8 #include "acpi_drivers.h"
9 #include "include/acinterp.h" /* for acpi_ex_eisa_id_to_string() */
12 #define _COMPONENT ACPI_BUS_COMPONENT
13 ACPI_MODULE_NAME ("scan")
15 #define STRUCT_TO_INT(s) (*((int*)&s))
17 extern struct acpi_device *acpi_root;
20 #define ACPI_BUS_CLASS "system_bus"
21 #define ACPI_BUS_HID "ACPI_BUS"
22 #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
23 #define ACPI_BUS_DEVICE_NAME "System Bus"
25 static LIST_HEAD(acpi_device_list);
26 static spinlock_t acpi_device_lock = SPIN_LOCK_UNLOCKED;
28 static void acpi_device_release(struct kobject * kobj)
30 struct acpi_device * dev = container_of(kobj,struct acpi_device,kobj);
31 kfree(dev);
34 static struct kobj_type ktype_acpi_ns = {
35 .release = acpi_device_release,
38 static struct kset acpi_namespace_kset = {
39 .kobj = {
40 .name = "namespace",
42 .subsys = &acpi_subsys,
43 .ktype = &ktype_acpi_ns,
47 static void acpi_device_register(struct acpi_device * device, struct acpi_device * parent)
50 * Linkage
51 * -------
52 * Link this device to its parent and siblings.
54 INIT_LIST_HEAD(&device->children);
55 INIT_LIST_HEAD(&device->node);
56 INIT_LIST_HEAD(&device->g_list);
58 spin_lock(&acpi_device_lock);
59 if (device->parent) {
60 list_add_tail(&device->node, &device->parent->children);
61 list_add_tail(&device->g_list,&device->parent->g_list);
62 } else
63 list_add_tail(&device->g_list,&acpi_device_list);
64 spin_unlock(&acpi_device_lock);
66 kobject_init(&device->kobj);
67 strncpy(device->kobj.name,device->pnp.bus_id,KOBJ_NAME_LEN);
68 if (parent)
69 device->kobj.parent = &parent->kobj;
70 device->kobj.ktype = &ktype_acpi_ns;
71 device->kobj.kset = &acpi_namespace_kset;
72 kobject_register(&device->kobj);
75 static int
76 acpi_device_unregister (
77 struct acpi_device *device,
78 int type)
80 kobject_unregister(&device->kobj);
81 return 0;
84 void
85 acpi_bus_data_handler (
86 acpi_handle handle,
87 u32 function,
88 void *context)
90 ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
92 /* TBD */
94 return_VOID;
97 static int
98 acpi_bus_get_power_flags (
99 struct acpi_device *device)
101 acpi_status status = 0;
102 acpi_handle handle = 0;
103 u32 i = 0;
105 ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
108 * Power Management Flags
110 status = acpi_get_handle(device->handle, "_PSC", &handle);
111 if (ACPI_SUCCESS(status))
112 device->power.flags.explicit_get = 1;
113 status = acpi_get_handle(device->handle, "_IRC", &handle);
114 if (ACPI_SUCCESS(status))
115 device->power.flags.inrush_current = 1;
116 status = acpi_get_handle(device->handle, "_PRW", &handle);
117 if (ACPI_SUCCESS(status))
118 device->power.flags.wake_capable = 1;
121 * Enumerate supported power management states
123 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
124 struct acpi_device_power_state *ps = &device->power.states[i];
125 char object_name[5] = {'_','P','R','0'+i,'\0'};
127 /* Evaluate "_PRx" to se if power resources are referenced */
128 acpi_evaluate_reference(device->handle, object_name, NULL,
129 &ps->resources);
130 if (ps->resources.count) {
131 device->power.flags.power_resources = 1;
132 ps->flags.valid = 1;
135 /* Evaluate "_PSx" to see if we can do explicit sets */
136 object_name[2] = 'S';
137 status = acpi_get_handle(device->handle, object_name, &handle);
138 if (ACPI_SUCCESS(status)) {
139 ps->flags.explicit_set = 1;
140 ps->flags.valid = 1;
143 /* State is valid if we have some power control */
144 if (ps->resources.count || ps->flags.explicit_set)
145 ps->flags.valid = 1;
147 ps->power = -1; /* Unknown - driver assigned */
148 ps->latency = -1; /* Unknown - driver assigned */
151 /* Set defaults for D0 and D3 states (always valid) */
152 device->power.states[ACPI_STATE_D0].flags.valid = 1;
153 device->power.states[ACPI_STATE_D0].power = 100;
154 device->power.states[ACPI_STATE_D3].flags.valid = 1;
155 device->power.states[ACPI_STATE_D3].power = 0;
157 /* TBD: System wake support and resource requirements. */
159 device->power.state = ACPI_STATE_UNKNOWN;
161 return 0;
165 /* --------------------------------------------------------------------------
166 Performance Management
167 -------------------------------------------------------------------------- */
169 static int
170 acpi_bus_get_perf_flags (
171 struct acpi_device *device)
173 device->performance.state = ACPI_STATE_UNKNOWN;
174 return 0;
177 /* --------------------------------------------------------------------------
178 Driver Management
179 -------------------------------------------------------------------------- */
181 static LIST_HEAD(acpi_bus_drivers);
182 static DECLARE_MUTEX(acpi_bus_drivers_lock);
186 * acpi_bus_match
187 * --------------
188 * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
189 * matches the specified driver's criteria.
191 static int
192 acpi_bus_match (
193 struct acpi_device *device,
194 struct acpi_driver *driver)
196 int error = 0;
197 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
199 if (device->flags.hardware_id)
200 if (strstr(driver->ids, device->pnp.hardware_id))
201 goto Done;
203 if (device->flags.compatible_ids) {
204 acpi_status status = AE_OK;
205 union acpi_object *object = NULL;
206 char cid[256] = {};
208 status = acpi_evaluate_object(device->handle, "_CID", NULL,
209 &buffer);
210 if (ACPI_FAILURE(status) || !buffer.pointer)
211 return -ENOENT;
213 object = (union acpi_object *) buffer.pointer;
215 switch (object->type) {
216 case ACPI_TYPE_INTEGER:
217 acpi_ex_eisa_id_to_string((u32) object->integer.value,
218 cid);
219 break;
220 case ACPI_TYPE_STRING:
221 strncpy(cid, object->string.pointer, sizeof(cid) - 1);
222 break;
223 case ACPI_TYPE_PACKAGE:
224 /* TBD: Support CID packages */
225 break;
228 if (strlen(cid) && strstr(driver->ids,cid))
229 goto Done;
231 error = -ENOENT;
233 Done:
234 if (buffer.pointer)
235 acpi_os_free(buffer.pointer);
236 return error;
241 * acpi_bus_driver_init
242 * --------------------
243 * Used to initialize a device via its device driver. Called whenever a
244 * driver is bound to a device. Invokes the driver's add() and start() ops.
246 static int
247 acpi_bus_driver_init (
248 struct acpi_device *device,
249 struct acpi_driver *driver)
251 int result = 0;
253 ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
255 if (!device || !driver)
256 return_VALUE(-EINVAL);
258 if (!driver->ops.add)
259 return_VALUE(-ENOSYS);
261 result = driver->ops.add(device);
262 if (result) {
263 device->driver = NULL;
264 acpi_driver_data(device) = NULL;
265 return_VALUE(result);
268 device->driver = driver;
271 * TBD - Configuration Management: Assign resources to device based
272 * upon possible configuration and currently allocated resources.
275 if (driver->ops.start) {
276 result = driver->ops.start(device);
277 if (result && driver->ops.remove)
278 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
279 return_VALUE(result);
282 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Driver successfully bound to device\n"));
284 if (driver->ops.scan) {
285 driver->ops.scan(device);
288 return_VALUE(0);
291 static int acpi_driver_attach(struct acpi_driver * drv)
293 struct list_head * node, * next;
295 ACPI_FUNCTION_TRACE("acpi_driver_attach");
297 spin_lock(&acpi_device_lock);
298 list_for_each_safe(node,next,&acpi_device_list) {
299 struct acpi_device * dev = container_of(node,struct acpi_device,g_list);
301 if (dev->driver || !dev->status.present)
302 continue;
303 spin_unlock(&acpi_device_lock);
305 if (!acpi_bus_match(dev,drv)) {
306 if (!acpi_bus_driver_init(dev,drv)) {
307 atomic_inc(&drv->references);
308 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
309 drv->name, dev->pnp.bus_id));
312 spin_lock(&acpi_device_lock);
314 spin_unlock(&acpi_device_lock);
315 return_VALUE(0);
318 static int acpi_driver_detach(struct acpi_driver * drv)
320 struct list_head * node, * next;
322 ACPI_FUNCTION_TRACE("acpi_driver_detach");
324 spin_lock(&acpi_device_lock);
325 list_for_each_safe(node,next,&acpi_device_list) {
326 struct acpi_device * dev = container_of(node,struct acpi_device,g_list);
328 if (dev->driver == drv) {
329 if (drv->ops.remove)
330 drv->ops.remove(dev,ACPI_BUS_REMOVAL_NORMAL);
331 dev->driver = NULL;
332 dev->driver_data = NULL;
333 atomic_dec(&drv->references);
336 spin_unlock(&acpi_device_lock);
337 return_VALUE(0);
341 * acpi_bus_register_driver
342 * ------------------------
343 * Registers a driver with the ACPI bus. Searches the namespace for all
344 * devices that match the driver's criteria and binds.
347 acpi_bus_register_driver (
348 struct acpi_driver *driver)
350 int error = 0;
352 ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
354 if (driver) {
355 spin_lock(&acpi_device_lock);
356 list_add_tail(&driver->node, &acpi_bus_drivers);
357 spin_unlock(&acpi_device_lock);
358 acpi_driver_attach(driver);
359 } else
360 error = -EINVAL;
362 return_VALUE(error);
367 * acpi_bus_unregister_driver
368 * --------------------------
369 * Unregisters a driver with the ACPI bus. Searches the namespace for all
370 * devices that match the driver's criteria and unbinds.
373 acpi_bus_unregister_driver (
374 struct acpi_driver *driver)
376 int error = 0;
378 ACPI_FUNCTION_TRACE("acpi_bus_unregister_driver");
380 if (driver) {
381 acpi_driver_detach(driver);
383 if (!atomic_read(&driver->references)) {
384 spin_lock(&acpi_device_lock);
385 list_del_init(&driver->node);
386 spin_unlock(&acpi_device_lock);
388 } else
389 error = -EINVAL;
390 return_VALUE(error);
394 * acpi_bus_find_driver
395 * --------------------
396 * Parses the list of registered drivers looking for a driver applicable for
397 * the specified device.
399 static int
400 acpi_bus_find_driver (
401 struct acpi_device *device)
403 int result = 0;
404 struct list_head * node, *next;
406 ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
408 if (!device->flags.hardware_id && !device->flags.compatible_ids)
409 goto Done;
411 spin_lock(&acpi_device_lock);
412 list_for_each_safe(node,next,&acpi_bus_drivers) {
413 struct acpi_driver * driver = container_of(node,struct acpi_driver,node);
415 atomic_inc(&driver->references);
416 spin_unlock(&acpi_device_lock);
417 if (!acpi_bus_match(device, driver)) {
418 result = acpi_bus_driver_init(device, driver);
419 if (!result)
420 goto Done;
422 atomic_dec(&driver->references);
423 spin_lock(&acpi_device_lock);
425 spin_unlock(&acpi_device_lock);
427 Done:
428 return_VALUE(result);
432 /* --------------------------------------------------------------------------
433 Device Enumeration
434 -------------------------------------------------------------------------- */
436 static int
437 acpi_bus_get_flags (
438 struct acpi_device *device)
440 acpi_status status = AE_OK;
441 acpi_handle temp = NULL;
443 ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
445 /* Presence of _STA indicates 'dynamic_status' */
446 status = acpi_get_handle(device->handle, "_STA", &temp);
447 if (ACPI_SUCCESS(status))
448 device->flags.dynamic_status = 1;
450 /* Presence of _CID indicates 'compatible_ids' */
451 status = acpi_get_handle(device->handle, "_CID", &temp);
452 if (ACPI_SUCCESS(status))
453 device->flags.compatible_ids = 1;
455 /* Presence of _RMV indicates 'removable' */
456 status = acpi_get_handle(device->handle, "_RMV", &temp);
457 if (ACPI_SUCCESS(status))
458 device->flags.removable = 1;
460 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
461 status = acpi_get_handle(device->handle, "_EJD", &temp);
462 if (ACPI_SUCCESS(status))
463 device->flags.ejectable = 1;
464 else {
465 status = acpi_get_handle(device->handle, "_EJ0", &temp);
466 if (ACPI_SUCCESS(status))
467 device->flags.ejectable = 1;
470 /* Presence of _LCK indicates 'lockable' */
471 status = acpi_get_handle(device->handle, "_LCK", &temp);
472 if (ACPI_SUCCESS(status))
473 device->flags.lockable = 1;
475 /* Presence of _PS0|_PR0 indicates 'power manageable' */
476 status = acpi_get_handle(device->handle, "_PS0", &temp);
477 if (ACPI_FAILURE(status))
478 status = acpi_get_handle(device->handle, "_PR0", &temp);
479 if (ACPI_SUCCESS(status))
480 device->flags.power_manageable = 1;
482 /* TBD: Peformance management */
484 return_VALUE(0);
487 static void acpi_device_get_busid(struct acpi_device * device, acpi_handle handle, int type)
489 char bus_id[5] = {'?',0};
490 struct acpi_buffer buffer = {sizeof(bus_id), bus_id};
491 int i = 0;
494 * Bus ID
495 * ------
496 * The device's Bus ID is simply the object name.
497 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
499 switch (type) {
500 case ACPI_BUS_TYPE_SYSTEM:
501 sprintf(device->pnp.bus_id, "%s", "ACPI");
502 break;
503 case ACPI_BUS_TYPE_POWER_BUTTON:
504 sprintf(device->pnp.bus_id, "%s", "PWRF");
505 break;
506 case ACPI_BUS_TYPE_SLEEP_BUTTON:
507 sprintf(device->pnp.bus_id, "%s", "SLPF");
508 break;
509 default:
510 acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
511 /* Clean up trailing underscores (if any) */
512 for (i = 3; i > 1; i--) {
513 if (bus_id[i] == '_')
514 bus_id[i] = '\0';
515 else
516 break;
518 sprintf(device->pnp.bus_id, "%s", bus_id);
519 break;
523 static void acpi_device_set_id(struct acpi_device * device, struct acpi_device * parent,
524 acpi_handle handle, int type)
526 struct acpi_device_info info;
527 char *hid = NULL;
528 char *uid = NULL;
529 acpi_status status;
531 switch (type) {
532 case ACPI_BUS_TYPE_DEVICE:
533 status = acpi_get_object_info(handle, &info);
534 if (ACPI_FAILURE(status)) {
535 printk("%s: Error reading device info\n",__FUNCTION__);
536 return;
538 /* Clean up info strings (not NULL terminated) */
539 info.hardware_id[sizeof(info.hardware_id)-1] = '\0';
540 info.unique_id[sizeof(info.unique_id)-1] = '\0';
541 if (info.valid & ACPI_VALID_HID)
542 hid = info.hardware_id;
543 if (info.valid & ACPI_VALID_UID)
544 uid = info.unique_id;
545 if (info.valid & ACPI_VALID_ADR) {
546 device->pnp.bus_address = info.address;
547 device->flags.bus_address = 1;
549 break;
550 case ACPI_BUS_TYPE_POWER:
551 hid = ACPI_POWER_HID;
552 break;
553 case ACPI_BUS_TYPE_PROCESSOR:
554 hid = ACPI_PROCESSOR_HID;
555 break;
556 case ACPI_BUS_TYPE_SYSTEM:
557 hid = ACPI_SYSTEM_HID;
558 break;
559 case ACPI_BUS_TYPE_THERMAL:
560 hid = ACPI_THERMAL_HID;
561 break;
562 case ACPI_BUS_TYPE_POWER_BUTTON:
563 hid = ACPI_BUTTON_HID_POWERF;
564 break;
565 case ACPI_BUS_TYPE_SLEEP_BUTTON:
566 hid = ACPI_BUTTON_HID_SLEEPF;
567 break;
571 * \_SB
572 * ----
573 * Fix for the system root bus device -- the only root-level device.
575 if ((parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
576 hid = ACPI_BUS_HID;
577 sprintf(device->pnp.device_name, "%s", ACPI_BUS_DEVICE_NAME);
578 sprintf(device->pnp.device_class, "%s", ACPI_BUS_CLASS);
581 if (hid) {
582 sprintf(device->pnp.hardware_id, "%s", hid);
583 device->flags.hardware_id = 1;
585 if (uid) {
586 sprintf(device->pnp.unique_id, "%s", uid);
587 device->flags.unique_id = 1;
591 int acpi_device_set_context(struct acpi_device * device, int type)
593 acpi_status status = AE_OK;
594 int result = 0;
596 * Context
597 * -------
598 * Attach this 'struct acpi_device' to the ACPI object. This makes
599 * resolutions from handle->device very efficient. Note that we need
600 * to be careful with fixed-feature devices as they all attach to the
601 * root object.
603 if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
604 type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
605 status = acpi_attach_data(device->handle,
606 acpi_bus_data_handler, device);
608 if (ACPI_FAILURE(status)) {
609 printk("Error attaching device data\n");
610 result = -ENODEV;
613 return result;
616 void acpi_device_get_debug_info(struct acpi_device * device, acpi_handle handle, int type)
618 #ifdef CONFIG_ACPI_DEBUG_OUTPUT
619 char *type_string = NULL;
620 char name[80] = {'?','\0'};
621 acpi_buffer buffer = {sizeof(name), name};
623 switch (type) {
624 case ACPI_BUS_TYPE_DEVICE:
625 type_string = "Device";
626 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
627 break;
628 case ACPI_BUS_TYPE_POWER:
629 type_string = "Power Resource";
630 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
631 break;
632 case ACPI_BUS_TYPE_PROCESSOR:
633 type_string = "Processor";
634 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
635 break;
636 case ACPI_BUS_TYPE_SYSTEM:
637 type_string = "System";
638 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
639 break;
640 case ACPI_BUS_TYPE_THERMAL:
641 type_string = "Thermal Zone";
642 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
643 break;
644 case ACPI_BUS_TYPE_POWER_BUTTON:
645 type_string = "Power Button";
646 sprintf(name, "PWRB");
647 break;
648 case ACPI_BUS_TYPE_SLEEP_BUTTON:
649 type_string = "Sleep Button";
650 sprintf(name, "SLPB");
651 break;
654 printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
655 #endif /*CONFIG_ACPI_DEBUG_OUTPUT*/
658 static int
659 acpi_bus_add (
660 struct acpi_device **child,
661 struct acpi_device *parent,
662 acpi_handle handle,
663 int type)
665 int result = 0;
666 struct acpi_device *device = NULL;
668 ACPI_FUNCTION_TRACE("acpi_bus_add");
670 if (!child)
671 return_VALUE(-EINVAL);
673 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
674 if (!device) {
675 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n"));
676 return_VALUE(-ENOMEM);
678 memset(device, 0, sizeof(struct acpi_device));
680 device->handle = handle;
681 device->parent = parent;
683 acpi_device_get_busid(device,handle,type);
686 * Flags
687 * -----
688 * Get prior to calling acpi_bus_get_status() so we know whether
689 * or not _STA is present. Note that we only look for object
690 * handles -- cannot evaluate objects until we know the device is
691 * present and properly initialized.
693 result = acpi_bus_get_flags(device);
694 if (result)
695 goto end;
698 * Status
699 * ------
700 * See if the device is present. We always assume that non-Device()
701 * objects (e.g. thermal zones, power resources, processors, etc.) are
702 * present, functioning, etc. (at least when parent object is present).
703 * Note that _STA has a different meaning for some objects (e.g.
704 * power resources) so we need to be careful how we use it.
706 switch (type) {
707 case ACPI_BUS_TYPE_DEVICE:
708 result = acpi_bus_get_status(device);
709 if (!result)
710 break;
711 if (!device->status.present)
712 result = -ENOENT;
713 goto end;
714 default:
715 STRUCT_TO_INT(device->status) = 0x0F;
716 break;
720 * Initialize Device
721 * -----------------
722 * TBD: Synch with Core's enumeration/initialization process.
726 * Hardware ID, Unique ID, & Bus Address
727 * -------------------------------------
729 acpi_device_set_id(device,parent,handle,type);
732 * Power Management
733 * ----------------
735 if (device->flags.power_manageable) {
736 result = acpi_bus_get_power_flags(device);
737 if (result)
738 goto end;
742 * Performance Management
743 * ----------------------
745 if (device->flags.performance_manageable) {
746 result = acpi_bus_get_perf_flags(device);
747 if (result)
748 goto end;
751 if ((result = acpi_device_set_context(device,type)))
752 goto end;
754 acpi_device_get_debug_info(device,handle,type);
756 acpi_device_register(device,parent);
759 * Bind _ADR-Based Devices
760 * -----------------------
761 * If there's a a bus address (_ADR) then we utilize the parent's
762 * 'bind' function (if exists) to bind the ACPI- and natively-
763 * enumerated device representations.
765 if (device->flags.bus_address) {
766 if (device->parent && device->parent->ops.bind)
767 device->parent->ops.bind(device);
771 * Locate & Attach Driver
772 * ----------------------
773 * If there's a hardware id (_HID) or compatible ids (_CID) we check
774 * to see if there's a driver installed for this kind of device. Note
775 * that drivers can install before or after a device is enumerated.
777 * TBD: Assumes LDM provides driver hot-plug capability.
779 acpi_bus_find_driver(device);
781 end:
782 if (!result)
783 *child = device;
784 else
785 kfree(device);
786 return_VALUE(result);
791 static int acpi_bus_scan (struct acpi_device *start)
793 acpi_status status = AE_OK;
794 struct acpi_device *parent = NULL;
795 struct acpi_device *child = NULL;
796 acpi_handle phandle = 0;
797 acpi_handle chandle = 0;
798 acpi_object_type type = 0;
799 u32 level = 1;
801 ACPI_FUNCTION_TRACE("acpi_bus_scan");
803 if (!start)
804 return_VALUE(-EINVAL);
806 parent = start;
807 phandle = start->handle;
810 * Parse through the ACPI namespace, identify all 'devices', and
811 * create a new 'struct acpi_device' for each.
813 while ((level > 0) && parent) {
815 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
816 chandle, &chandle);
819 * If this scope is exhausted then move our way back up.
821 if (ACPI_FAILURE(status)) {
822 level--;
823 chandle = phandle;
824 acpi_get_parent(phandle, &phandle);
825 if (parent->parent)
826 parent = parent->parent;
827 continue;
830 status = acpi_get_type(chandle, &type);
831 if (ACPI_FAILURE(status))
832 continue;
835 * If this is a scope object then parse it (depth-first).
837 if (type == ACPI_TYPE_LOCAL_SCOPE) {
838 level++;
839 phandle = chandle;
840 chandle = 0;
841 continue;
845 * We're only interested in objects that we consider 'devices'.
847 switch (type) {
848 case ACPI_TYPE_DEVICE:
849 type = ACPI_BUS_TYPE_DEVICE;
850 break;
851 case ACPI_TYPE_PROCESSOR:
852 type = ACPI_BUS_TYPE_PROCESSOR;
853 break;
854 case ACPI_TYPE_THERMAL:
855 type = ACPI_BUS_TYPE_THERMAL;
856 break;
857 case ACPI_TYPE_POWER:
858 type = ACPI_BUS_TYPE_POWER;
859 break;
860 default:
861 continue;
864 status = acpi_bus_add(&child, parent, chandle, type);
865 if (ACPI_FAILURE(status))
866 continue;
869 * If the device is present, enabled, and functioning then
870 * parse its scope (depth-first). Note that we need to
871 * represent absent devices to facilitate PnP notifications
872 * -- but only the subtree head (not all of its children,
873 * which will be enumerated when the parent is inserted).
875 * TBD: Need notifications and other detection mechanisms
876 * in place before we can fully implement this.
878 if (child->status.present) {
879 status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
880 0, NULL);
881 if (ACPI_SUCCESS(status)) {
882 level++;
883 phandle = chandle;
884 chandle = 0;
885 parent = child;
890 return_VALUE(0);
894 static int
895 acpi_bus_scan_fixed (
896 struct acpi_device *root)
898 int result = 0;
899 struct acpi_device *device = NULL;
901 ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
903 if (!root)
904 return_VALUE(-ENODEV);
907 * Enumerate all fixed-feature devices.
909 if (acpi_fadt.pwr_button == 0)
910 result = acpi_bus_add(&device, acpi_root,
911 NULL, ACPI_BUS_TYPE_POWER_BUTTON);
913 if (acpi_fadt.sleep_button == 0)
914 result = acpi_bus_add(&device, acpi_root,
915 NULL, ACPI_BUS_TYPE_SLEEP_BUTTON);
917 return_VALUE(result);
921 static int __init acpi_scan_init(void)
923 int result;
925 ACPI_FUNCTION_TRACE("acpi_scan_init");
927 if (acpi_disabled)
928 return_VALUE(0);
930 kset_register(&acpi_namespace_kset);
933 * Create the root device in the bus's device tree
935 result = acpi_bus_add(&acpi_root, NULL, ACPI_ROOT_OBJECT,
936 ACPI_BUS_TYPE_SYSTEM);
937 if (result)
938 goto Done;
941 * Enumerate devices in the ACPI namespace.
943 result = acpi_bus_scan_fixed(acpi_root);
944 if (!result)
945 result = acpi_bus_scan(acpi_root);
947 if (result)
948 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
950 Done:
951 return_VALUE(result);
954 subsys_initcall(acpi_scan_init);