2 * scan.c - support for transforming the ACPI namespace into individual objects
5 #include <linux/init.h>
6 #include <linux/acpi.h>
8 #include <acpi/acpi_drivers.h>
9 #include <acpi/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 spinlock_t acpi_device_lock
= SPIN_LOCK_UNLOCKED
;
27 LIST_HEAD(acpi_wakeup_device_list
);
29 static void acpi_device_release(struct kobject
* kobj
)
31 struct acpi_device
* dev
= container_of(kobj
,struct acpi_device
,kobj
);
32 if (dev
->pnp
.cid_list
)
33 kfree(dev
->pnp
.cid_list
);
37 static struct kobj_type ktype_acpi_ns
= {
38 .release
= acpi_device_release
,
41 static struct kset acpi_namespace_kset
= {
45 .subsys
= &acpi_subsys
,
46 .ktype
= &ktype_acpi_ns
,
50 static void acpi_device_register(struct acpi_device
* device
, struct acpi_device
* parent
)
55 * Link this device to its parent and siblings.
57 INIT_LIST_HEAD(&device
->children
);
58 INIT_LIST_HEAD(&device
->node
);
59 INIT_LIST_HEAD(&device
->g_list
);
61 spin_lock(&acpi_device_lock
);
63 list_add_tail(&device
->node
, &device
->parent
->children
);
64 list_add_tail(&device
->g_list
,&device
->parent
->g_list
);
66 list_add_tail(&device
->g_list
,&acpi_device_list
);
67 spin_unlock(&acpi_device_lock
);
69 kobject_init(&device
->kobj
);
70 strlcpy(device
->kobj
.name
,device
->pnp
.bus_id
,KOBJ_NAME_LEN
);
72 device
->kobj
.parent
= &parent
->kobj
;
73 device
->kobj
.ktype
= &ktype_acpi_ns
;
74 device
->kobj
.kset
= &acpi_namespace_kset
;
75 kobject_add(&device
->kobj
);
79 acpi_device_unregister (
80 struct acpi_device
*device
,
83 kobject_unregister(&device
->kobj
);
88 acpi_bus_data_handler (
93 ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
101 acpi_bus_get_power_flags (
102 struct acpi_device
*device
)
104 acpi_status status
= 0;
105 acpi_handle handle
= NULL
;
108 ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
111 * Power Management Flags
113 status
= acpi_get_handle(device
->handle
, "_PSC", &handle
);
114 if (ACPI_SUCCESS(status
))
115 device
->power
.flags
.explicit_get
= 1;
116 status
= acpi_get_handle(device
->handle
, "_IRC", &handle
);
117 if (ACPI_SUCCESS(status
))
118 device
->power
.flags
.inrush_current
= 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
,
130 if (ps
->resources
.count
) {
131 device
->power
.flags
.power_resources
= 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;
143 /* State is valid if we have some power control */
144 if (ps
->resources
.count
|| ps
->flags
.explicit_set
)
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
;
166 struct acpi_device
*device
,
170 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
172 if (device
->flags
.hardware_id
)
173 if (strstr(ids
, device
->pnp
.hardware_id
))
176 if (device
->flags
.compatible_ids
) {
177 struct acpi_compatible_id_list
*cid_list
= device
->pnp
.cid_list
;
180 /* compare multiple _CID entries against driver ids */
181 for (i
= 0; i
< cid_list
->count
; i
++)
183 if (strstr(ids
, cid_list
->id
[i
].value
))
191 acpi_os_free(buffer
.pointer
);
196 acpi_bus_extract_wakeup_device_power_package (
197 struct acpi_device
*device
,
198 union acpi_object
*package
)
201 union acpi_object
*element
= NULL
;
203 if (!device
|| !package
|| (package
->package
.count
< 2))
204 return AE_BAD_PARAMETER
;
206 element
= &(package
->package
.elements
[0]);
208 return AE_BAD_PARAMETER
;
209 if (element
->type
== ACPI_TYPE_PACKAGE
) {
210 if ((element
->package
.count
< 2) ||
211 (element
->package
.elements
[0].type
!= ACPI_TYPE_LOCAL_REFERENCE
) ||
212 (element
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
))
214 device
->wakeup
.gpe_device
= element
->package
.elements
[0].reference
.handle
;
215 device
->wakeup
.gpe_number
= (u32
)element
->package
.elements
[1].integer
.value
;
216 }else if (element
->type
== ACPI_TYPE_INTEGER
) {
217 device
->wakeup
.gpe_number
= element
->integer
.value
;
221 element
= &(package
->package
.elements
[1]);
222 if (element
->type
!= ACPI_TYPE_INTEGER
) {
225 device
->wakeup
.sleep_state
= element
->integer
.value
;
227 if ((package
->package
.count
- 2) > ACPI_MAX_HANDLES
) {
230 device
->wakeup
.resources
.count
= package
->package
.count
- 2;
231 for (i
=0; i
< device
->wakeup
.resources
.count
; i
++) {
232 element
= &(package
->package
.elements
[i
+ 2]);
233 if (element
->type
!= ACPI_TYPE_ANY
) {
237 device
->wakeup
.resources
.handles
[i
] = element
->reference
.handle
;
244 acpi_bus_get_wakeup_device_flags (
245 struct acpi_device
*device
)
247 acpi_status status
= 0;
248 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
249 union acpi_object
*package
= NULL
;
251 ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
254 status
= acpi_evaluate_object(device
->handle
, "_PRW", NULL
, &buffer
);
255 if (ACPI_FAILURE(status
)) {
256 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error evaluating _PRW\n"));
260 package
= (union acpi_object
*) buffer
.pointer
;
261 status
= acpi_bus_extract_wakeup_device_power_package(device
, package
);
262 if (ACPI_FAILURE(status
)) {
263 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error extracting _PRW package\n"));
267 acpi_os_free(buffer
.pointer
);
269 device
->wakeup
.flags
.valid
= 1;
270 /* Power button, Lid switch always enable wakeup*/
271 if (!acpi_match_ids(device
, "PNP0C0D,PNP0C0C,PNP0C0E"))
272 device
->wakeup
.flags
.run_wake
= 1;
275 INIT_LIST_HEAD(&device
->wakeup_list
);
276 spin_lock(&acpi_device_lock
);
277 list_add_tail(&device
->wakeup_list
, &acpi_wakeup_device_list
);
278 spin_unlock(&acpi_device_lock
);
281 if (ACPI_FAILURE(status
))
282 device
->flags
.wake_capable
= 0;
286 /* --------------------------------------------------------------------------
287 Performance Management
288 -------------------------------------------------------------------------- */
291 acpi_bus_get_perf_flags (
292 struct acpi_device
*device
)
294 device
->performance
.state
= ACPI_STATE_UNKNOWN
;
298 /* --------------------------------------------------------------------------
300 -------------------------------------------------------------------------- */
302 static LIST_HEAD(acpi_bus_drivers
);
303 static DECLARE_MUTEX(acpi_bus_drivers_lock
);
309 * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
310 * matches the specified driver's criteria.
314 struct acpi_device
*device
,
315 struct acpi_driver
*driver
)
317 return acpi_match_ids(device
, driver
->ids
);
322 * acpi_bus_driver_init
323 * --------------------
324 * Used to initialize a device via its device driver. Called whenever a
325 * driver is bound to a device. Invokes the driver's add() and start() ops.
328 acpi_bus_driver_init (
329 struct acpi_device
*device
,
330 struct acpi_driver
*driver
)
334 ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
336 if (!device
|| !driver
)
337 return_VALUE(-EINVAL
);
339 if (!driver
->ops
.add
)
340 return_VALUE(-ENOSYS
);
342 result
= driver
->ops
.add(device
);
344 device
->driver
= NULL
;
345 acpi_driver_data(device
) = NULL
;
346 return_VALUE(result
);
349 device
->driver
= driver
;
352 * TBD - Configuration Management: Assign resources to device based
353 * upon possible configuration and currently allocated resources.
356 if (driver
->ops
.start
) {
357 result
= driver
->ops
.start(device
);
358 if (result
&& driver
->ops
.remove
)
359 driver
->ops
.remove(device
, ACPI_BUS_REMOVAL_NORMAL
);
360 return_VALUE(result
);
363 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Driver successfully bound to device\n"));
365 if (driver
->ops
.scan
) {
366 driver
->ops
.scan(device
);
372 static int acpi_driver_attach(struct acpi_driver
* drv
)
374 struct list_head
* node
, * next
;
377 ACPI_FUNCTION_TRACE("acpi_driver_attach");
379 spin_lock(&acpi_device_lock
);
380 list_for_each_safe(node
, next
, &acpi_device_list
) {
381 struct acpi_device
* dev
= container_of(node
, struct acpi_device
, g_list
);
383 if (dev
->driver
|| !dev
->status
.present
)
385 spin_unlock(&acpi_device_lock
);
387 if (!acpi_bus_match(dev
, drv
)) {
388 if (!acpi_bus_driver_init(dev
, drv
)) {
389 atomic_inc(&drv
->references
);
391 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found driver [%s] for device [%s]\n",
392 drv
->name
, dev
->pnp
.bus_id
));
395 spin_lock(&acpi_device_lock
);
397 spin_unlock(&acpi_device_lock
);
401 static int acpi_driver_detach(struct acpi_driver
* drv
)
403 struct list_head
* node
, * next
;
405 ACPI_FUNCTION_TRACE("acpi_driver_detach");
407 spin_lock(&acpi_device_lock
);
408 list_for_each_safe(node
,next
,&acpi_device_list
) {
409 struct acpi_device
* dev
= container_of(node
,struct acpi_device
,g_list
);
411 if (dev
->driver
== drv
) {
412 spin_unlock(&acpi_device_lock
);
414 drv
->ops
.remove(dev
,ACPI_BUS_REMOVAL_NORMAL
);
415 spin_lock(&acpi_device_lock
);
417 dev
->driver_data
= NULL
;
418 atomic_dec(&drv
->references
);
421 spin_unlock(&acpi_device_lock
);
426 * acpi_bus_register_driver
427 * ------------------------
428 * Registers a driver with the ACPI bus. Searches the namespace for all
429 * devices that match the driver's criteria and binds. Returns the
430 * number of devices that were claimed by the driver, or a negative
431 * error status for failure.
434 acpi_bus_register_driver (
435 struct acpi_driver
*driver
)
439 ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
442 return_VALUE(-ENODEV
);
445 return_VALUE(-EINVAL
);
447 spin_lock(&acpi_device_lock
);
448 list_add_tail(&driver
->node
, &acpi_bus_drivers
);
449 spin_unlock(&acpi_device_lock
);
450 count
= acpi_driver_attach(driver
);
457 * acpi_bus_unregister_driver
458 * --------------------------
459 * Unregisters a driver with the ACPI bus. Searches the namespace for all
460 * devices that match the driver's criteria and unbinds.
463 acpi_bus_unregister_driver (
464 struct acpi_driver
*driver
)
468 ACPI_FUNCTION_TRACE("acpi_bus_unregister_driver");
471 acpi_driver_detach(driver
);
473 if (!atomic_read(&driver
->references
)) {
474 spin_lock(&acpi_device_lock
);
475 list_del_init(&driver
->node
);
476 spin_unlock(&acpi_device_lock
);
484 * acpi_bus_find_driver
485 * --------------------
486 * Parses the list of registered drivers looking for a driver applicable for
487 * the specified device.
490 acpi_bus_find_driver (
491 struct acpi_device
*device
)
494 struct list_head
* node
, *next
;
496 ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
498 if (!device
->flags
.hardware_id
&& !device
->flags
.compatible_ids
)
501 spin_lock(&acpi_device_lock
);
502 list_for_each_safe(node
,next
,&acpi_bus_drivers
) {
503 struct acpi_driver
* driver
= container_of(node
,struct acpi_driver
,node
);
505 atomic_inc(&driver
->references
);
506 spin_unlock(&acpi_device_lock
);
507 if (!acpi_bus_match(device
, driver
)) {
508 result
= acpi_bus_driver_init(device
, driver
);
512 atomic_dec(&driver
->references
);
513 spin_lock(&acpi_device_lock
);
515 spin_unlock(&acpi_device_lock
);
518 return_VALUE(result
);
522 /* --------------------------------------------------------------------------
524 -------------------------------------------------------------------------- */
528 struct acpi_device
*device
)
530 acpi_status status
= AE_OK
;
531 acpi_handle temp
= NULL
;
533 ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
535 /* Presence of _STA indicates 'dynamic_status' */
536 status
= acpi_get_handle(device
->handle
, "_STA", &temp
);
537 if (ACPI_SUCCESS(status
))
538 device
->flags
.dynamic_status
= 1;
540 /* Presence of _CID indicates 'compatible_ids' */
541 status
= acpi_get_handle(device
->handle
, "_CID", &temp
);
542 if (ACPI_SUCCESS(status
))
543 device
->flags
.compatible_ids
= 1;
545 /* Presence of _RMV indicates 'removable' */
546 status
= acpi_get_handle(device
->handle
, "_RMV", &temp
);
547 if (ACPI_SUCCESS(status
))
548 device
->flags
.removable
= 1;
550 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
551 status
= acpi_get_handle(device
->handle
, "_EJD", &temp
);
552 if (ACPI_SUCCESS(status
))
553 device
->flags
.ejectable
= 1;
555 status
= acpi_get_handle(device
->handle
, "_EJ0", &temp
);
556 if (ACPI_SUCCESS(status
))
557 device
->flags
.ejectable
= 1;
560 /* Presence of _LCK indicates 'lockable' */
561 status
= acpi_get_handle(device
->handle
, "_LCK", &temp
);
562 if (ACPI_SUCCESS(status
))
563 device
->flags
.lockable
= 1;
565 /* Presence of _PS0|_PR0 indicates 'power manageable' */
566 status
= acpi_get_handle(device
->handle
, "_PS0", &temp
);
567 if (ACPI_FAILURE(status
))
568 status
= acpi_get_handle(device
->handle
, "_PR0", &temp
);
569 if (ACPI_SUCCESS(status
))
570 device
->flags
.power_manageable
= 1;
572 /* Presence of _PRW indicates wake capable */
573 status
= acpi_get_handle(device
->handle
, "_PRW", &temp
);
574 if (ACPI_SUCCESS(status
))
575 device
->flags
.wake_capable
= 1;
577 /* TBD: Peformance management */
582 static void acpi_device_get_busid(struct acpi_device
* device
, acpi_handle handle
, int type
)
584 char bus_id
[5] = {'?',0};
585 struct acpi_buffer buffer
= {sizeof(bus_id
), bus_id
};
591 * The device's Bus ID is simply the object name.
592 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
595 case ACPI_BUS_TYPE_SYSTEM
:
596 strcpy(device
->pnp
.bus_id
, "ACPI");
598 case ACPI_BUS_TYPE_POWER_BUTTON
:
599 strcpy(device
->pnp
.bus_id
, "PWRF");
601 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
602 strcpy(device
->pnp
.bus_id
, "SLPF");
605 acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
);
606 /* Clean up trailing underscores (if any) */
607 for (i
= 3; i
> 1; i
--) {
608 if (bus_id
[i
] == '_')
613 strcpy(device
->pnp
.bus_id
, bus_id
);
618 static void acpi_device_set_id(struct acpi_device
* device
, struct acpi_device
* parent
,
619 acpi_handle handle
, int type
)
621 struct acpi_device_info
*info
;
622 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
625 struct acpi_compatible_id_list
*cid_list
= NULL
;
629 case ACPI_BUS_TYPE_DEVICE
:
630 status
= acpi_get_object_info(handle
, &buffer
);
631 if (ACPI_FAILURE(status
)) {
632 printk("%s: Error reading device info\n",__FUNCTION__
);
636 info
= buffer
.pointer
;
637 if (info
->valid
& ACPI_VALID_HID
)
638 hid
= info
->hardware_id
.value
;
639 if (info
->valid
& ACPI_VALID_UID
)
640 uid
= info
->unique_id
.value
;
641 if (info
->valid
& ACPI_VALID_CID
)
642 cid_list
= &info
->compatibility_id
;
643 if (info
->valid
& ACPI_VALID_ADR
) {
644 device
->pnp
.bus_address
= info
->address
;
645 device
->flags
.bus_address
= 1;
648 case ACPI_BUS_TYPE_POWER
:
649 hid
= ACPI_POWER_HID
;
651 case ACPI_BUS_TYPE_PROCESSOR
:
652 hid
= ACPI_PROCESSOR_HID
;
654 case ACPI_BUS_TYPE_SYSTEM
:
655 hid
= ACPI_SYSTEM_HID
;
657 case ACPI_BUS_TYPE_THERMAL
:
658 hid
= ACPI_THERMAL_HID
;
660 case ACPI_BUS_TYPE_POWER_BUTTON
:
661 hid
= ACPI_BUTTON_HID_POWERF
;
663 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
664 hid
= ACPI_BUTTON_HID_SLEEPF
;
671 * Fix for the system root bus device -- the only root-level device.
673 if ((parent
== ACPI_ROOT_OBJECT
) && (type
== ACPI_BUS_TYPE_DEVICE
)) {
675 strcpy(device
->pnp
.device_name
, ACPI_BUS_DEVICE_NAME
);
676 strcpy(device
->pnp
.device_class
, ACPI_BUS_CLASS
);
680 strcpy(device
->pnp
.hardware_id
, hid
);
681 device
->flags
.hardware_id
= 1;
684 strcpy(device
->pnp
.unique_id
, uid
);
685 device
->flags
.unique_id
= 1;
688 device
->pnp
.cid_list
= kmalloc(cid_list
->size
, GFP_KERNEL
);
689 if (device
->pnp
.cid_list
)
690 memcpy(device
->pnp
.cid_list
, cid_list
, cid_list
->size
);
692 printk(KERN_ERR
"Memory allocation error\n");
695 acpi_os_free(buffer
.pointer
);
698 int acpi_device_set_context(struct acpi_device
* device
, int type
)
700 acpi_status status
= AE_OK
;
705 * Attach this 'struct acpi_device' to the ACPI object. This makes
706 * resolutions from handle->device very efficient. Note that we need
707 * to be careful with fixed-feature devices as they all attach to the
710 if (type
!= ACPI_BUS_TYPE_POWER_BUTTON
&&
711 type
!= ACPI_BUS_TYPE_SLEEP_BUTTON
) {
712 status
= acpi_attach_data(device
->handle
,
713 acpi_bus_data_handler
, device
);
715 if (ACPI_FAILURE(status
)) {
716 printk("Error attaching device data\n");
723 void acpi_device_get_debug_info(struct acpi_device
* device
, acpi_handle handle
, int type
)
725 #ifdef CONFIG_ACPI_DEBUG_OUTPUT
726 char *type_string
= NULL
;
727 char name
[80] = {'?','\0'};
728 acpi_buffer buffer
= {sizeof(name
), name
};
731 case ACPI_BUS_TYPE_DEVICE
:
732 type_string
= "Device";
733 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
735 case ACPI_BUS_TYPE_POWER
:
736 type_string
= "Power Resource";
737 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
739 case ACPI_BUS_TYPE_PROCESSOR
:
740 type_string
= "Processor";
741 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
743 case ACPI_BUS_TYPE_SYSTEM
:
744 type_string
= "System";
745 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
747 case ACPI_BUS_TYPE_THERMAL
:
748 type_string
= "Thermal Zone";
749 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
751 case ACPI_BUS_TYPE_POWER_BUTTON
:
752 type_string
= "Power Button";
753 sprintf(name
, "PWRB");
755 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
756 type_string
= "Sleep Button";
757 sprintf(name
, "SLPB");
761 printk(KERN_DEBUG
"Found %s %s [%p]\n", type_string
, name
, handle
);
762 #endif /*CONFIG_ACPI_DEBUG_OUTPUT*/
767 struct acpi_device
**child
,
768 struct acpi_device
*parent
,
773 struct acpi_device
*device
= NULL
;
775 ACPI_FUNCTION_TRACE("acpi_bus_add");
778 return_VALUE(-EINVAL
);
780 device
= kmalloc(sizeof(struct acpi_device
), GFP_KERNEL
);
782 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Memory allocation error\n"));
783 return_VALUE(-ENOMEM
);
785 memset(device
, 0, sizeof(struct acpi_device
));
787 device
->handle
= handle
;
788 device
->parent
= parent
;
790 acpi_device_get_busid(device
,handle
,type
);
795 * Get prior to calling acpi_bus_get_status() so we know whether
796 * or not _STA is present. Note that we only look for object
797 * handles -- cannot evaluate objects until we know the device is
798 * present and properly initialized.
800 result
= acpi_bus_get_flags(device
);
807 * See if the device is present. We always assume that non-Device()
808 * objects (e.g. thermal zones, power resources, processors, etc.) are
809 * present, functioning, etc. (at least when parent object is present).
810 * Note that _STA has a different meaning for some objects (e.g.
811 * power resources) so we need to be careful how we use it.
814 case ACPI_BUS_TYPE_DEVICE
:
815 result
= acpi_bus_get_status(device
);
816 if (ACPI_FAILURE(result
) || !device
->status
.present
) {
822 STRUCT_TO_INT(device
->status
) = 0x0F;
829 * TBD: Synch with Core's enumeration/initialization process.
833 * Hardware ID, Unique ID, & Bus Address
834 * -------------------------------------
836 acpi_device_set_id(device
,parent
,handle
,type
);
842 if (device
->flags
.power_manageable
) {
843 result
= acpi_bus_get_power_flags(device
);
849 * Wakeup device management
850 *-----------------------
852 if (device
->flags
.wake_capable
) {
853 result
= acpi_bus_get_wakeup_device_flags(device
);
859 * Performance Management
860 * ----------------------
862 if (device
->flags
.performance_manageable
) {
863 result
= acpi_bus_get_perf_flags(device
);
868 if ((result
= acpi_device_set_context(device
,type
)))
871 acpi_device_get_debug_info(device
,handle
,type
);
873 acpi_device_register(device
,parent
);
876 * Bind _ADR-Based Devices
877 * -----------------------
878 * If there's a a bus address (_ADR) then we utilize the parent's
879 * 'bind' function (if exists) to bind the ACPI- and natively-
880 * enumerated device representations.
882 if (device
->flags
.bus_address
) {
883 if (device
->parent
&& device
->parent
->ops
.bind
)
884 device
->parent
->ops
.bind(device
);
888 * Locate & Attach Driver
889 * ----------------------
890 * If there's a hardware id (_HID) or compatible ids (_CID) we check
891 * to see if there's a driver installed for this kind of device. Note
892 * that drivers can install before or after a device is enumerated.
894 * TBD: Assumes LDM provides driver hot-plug capability.
896 acpi_bus_find_driver(device
);
902 if (device
->pnp
.cid_list
)
903 kfree(device
->pnp
.cid_list
);
907 return_VALUE(result
);
912 static int acpi_bus_scan (struct acpi_device
*start
)
914 acpi_status status
= AE_OK
;
915 struct acpi_device
*parent
= NULL
;
916 struct acpi_device
*child
= NULL
;
917 acpi_handle phandle
= NULL
;
918 acpi_handle chandle
= NULL
;
919 acpi_object_type type
= 0;
922 ACPI_FUNCTION_TRACE("acpi_bus_scan");
925 return_VALUE(-EINVAL
);
928 phandle
= start
->handle
;
931 * Parse through the ACPI namespace, identify all 'devices', and
932 * create a new 'struct acpi_device' for each.
934 while ((level
> 0) && parent
) {
936 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
940 * If this scope is exhausted then move our way back up.
942 if (ACPI_FAILURE(status
)) {
945 acpi_get_parent(phandle
, &phandle
);
947 parent
= parent
->parent
;
951 status
= acpi_get_type(chandle
, &type
);
952 if (ACPI_FAILURE(status
))
956 * If this is a scope object then parse it (depth-first).
958 if (type
== ACPI_TYPE_LOCAL_SCOPE
) {
966 * We're only interested in objects that we consider 'devices'.
969 case ACPI_TYPE_DEVICE
:
970 type
= ACPI_BUS_TYPE_DEVICE
;
972 case ACPI_TYPE_PROCESSOR
:
973 type
= ACPI_BUS_TYPE_PROCESSOR
;
975 case ACPI_TYPE_THERMAL
:
976 type
= ACPI_BUS_TYPE_THERMAL
;
978 case ACPI_TYPE_POWER
:
979 type
= ACPI_BUS_TYPE_POWER
;
985 status
= acpi_bus_add(&child
, parent
, chandle
, type
);
986 if (ACPI_FAILURE(status
))
990 * If the device is present, enabled, and functioning then
991 * parse its scope (depth-first). Note that we need to
992 * represent absent devices to facilitate PnP notifications
993 * -- but only the subtree head (not all of its children,
994 * which will be enumerated when the parent is inserted).
996 * TBD: Need notifications and other detection mechanisms
997 * in place before we can fully implement this.
999 if (child
->status
.present
) {
1000 status
= acpi_get_next_object(ACPI_TYPE_ANY
, chandle
,
1002 if (ACPI_SUCCESS(status
)) {
1016 acpi_bus_scan_fixed (
1017 struct acpi_device
*root
)
1020 struct acpi_device
*device
= NULL
;
1022 ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
1025 return_VALUE(-ENODEV
);
1028 * Enumerate all fixed-feature devices.
1030 if (acpi_fadt
.pwr_button
== 0)
1031 result
= acpi_bus_add(&device
, acpi_root
,
1032 NULL
, ACPI_BUS_TYPE_POWER_BUTTON
);
1034 if (acpi_fadt
.sleep_button
== 0)
1035 result
= acpi_bus_add(&device
, acpi_root
,
1036 NULL
, ACPI_BUS_TYPE_SLEEP_BUTTON
);
1038 return_VALUE(result
);
1042 static int __init
acpi_scan_init(void)
1046 ACPI_FUNCTION_TRACE("acpi_scan_init");
1051 kset_register(&acpi_namespace_kset
);
1054 * Create the root device in the bus's device tree
1056 result
= acpi_bus_add(&acpi_root
, NULL
, ACPI_ROOT_OBJECT
,
1057 ACPI_BUS_TYPE_SYSTEM
);
1062 * Enumerate devices in the ACPI namespace.
1064 result
= acpi_bus_scan_fixed(acpi_root
);
1066 result
= acpi_bus_scan(acpi_root
);
1069 acpi_device_unregister(acpi_root
, ACPI_BUS_REMOVAL_NORMAL
);
1072 return_VALUE(result
);
1075 subsys_initcall(acpi_scan_init
);