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/kernel.h>
8 #include <linux/acpi.h>
10 #include <acpi/acpi_drivers.h>
11 #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
13 #define _COMPONENT ACPI_BUS_COMPONENT
14 ACPI_MODULE_NAME("scan");
15 #define STRUCT_TO_INT(s) (*((int*)&s))
16 extern struct acpi_device
*acpi_root
;
18 #define ACPI_BUS_CLASS "system_bus"
19 #define ACPI_BUS_HID "LNXSYBUS"
20 #define ACPI_BUS_DEVICE_NAME "System Bus"
22 static LIST_HEAD(acpi_device_list
);
23 static LIST_HEAD(acpi_bus_id_list
);
24 DEFINE_SPINLOCK(acpi_device_lock
);
25 LIST_HEAD(acpi_wakeup_device_list
);
27 struct acpi_device_bus_id
{
29 unsigned int instance_no
;
30 struct list_head node
;
34 * Creates hid/cid(s) string needed for modalias and uevent
35 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
36 * char *modalias: "acpi:IBM0001:ACPI0001"
38 static int create_modalias(struct acpi_device
*acpi_dev
, char *modalias
,
43 if (!acpi_dev
->flags
.hardware_id
)
46 len
= snprintf(modalias
, size
, "acpi:%s:",
47 acpi_dev
->pnp
.hardware_id
);
48 if (len
< 0 || len
>= size
)
52 if (acpi_dev
->flags
.compatible_ids
) {
53 struct acpi_compatible_id_list
*cid_list
;
57 cid_list
= acpi_dev
->pnp
.cid_list
;
58 for (i
= 0; i
< cid_list
->count
; i
++) {
59 count
= snprintf(&modalias
[len
], size
, "%s:",
60 cid_list
->id
[i
].value
);
61 if (count
< 0 || count
>= size
) {
62 printk(KERN_ERR PREFIX
"%s cid[%i] exceeds event buffer size",
63 acpi_dev
->pnp
.device_name
, i
);
76 acpi_device_modalias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
77 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
80 /* Device has no HID and no CID or string is >1024 */
81 len
= create_modalias(acpi_dev
, buf
, 1024);
87 static DEVICE_ATTR(modalias
, 0444, acpi_device_modalias_show
, NULL
);
89 static int acpi_eject_operation(acpi_handle handle
, int lockable
)
91 struct acpi_object_list arg_list
;
92 union acpi_object arg
;
93 acpi_status status
= AE_OK
;
101 arg_list
.pointer
= &arg
;
102 arg
.type
= ACPI_TYPE_INTEGER
;
103 arg
.integer
.value
= 0;
104 acpi_evaluate_object(handle
, "_LCK", &arg_list
, NULL
);
108 arg_list
.pointer
= &arg
;
109 arg
.type
= ACPI_TYPE_INTEGER
;
110 arg
.integer
.value
= 1;
116 status
= acpi_evaluate_object(handle
, "_EJ0", &arg_list
, NULL
);
117 if (ACPI_FAILURE(status
)) {
125 acpi_eject_store(struct device
*d
, struct device_attribute
*attr
,
126 const char *buf
, size_t count
)
133 acpi_object_type type
= 0;
134 struct acpi_device
*acpi_device
= to_acpi_device(d
);
136 if ((!count
) || (buf
[0] != '1')) {
140 if (acpi_device
->driver
== NULL
) {
145 status
= acpi_get_type(acpi_device
->handle
, &type
);
146 if (ACPI_FAILURE(status
) || (!acpi_device
->flags
.ejectable
)) {
151 islockable
= acpi_device
->flags
.lockable
;
152 handle
= acpi_device
->handle
;
154 result
= acpi_bus_trim(acpi_device
, 1);
157 result
= acpi_eject_operation(handle
, islockable
);
166 static DEVICE_ATTR(eject
, 0200, NULL
, acpi_eject_store
);
169 acpi_device_hid_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
170 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
172 return sprintf(buf
, "%s\n", acpi_dev
->pnp
.hardware_id
);
174 static DEVICE_ATTR(hid
, 0444, acpi_device_hid_show
, NULL
);
177 acpi_device_path_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
) {
178 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
179 struct acpi_buffer path
= {ACPI_ALLOCATE_BUFFER
, NULL
};
182 result
= acpi_get_name(acpi_dev
->handle
, ACPI_FULL_PATHNAME
, &path
);
186 result
= sprintf(buf
, "%s\n", (char*)path
.pointer
);
191 static DEVICE_ATTR(path
, 0444, acpi_device_path_show
, NULL
);
193 static int acpi_device_setup_files(struct acpi_device
*dev
)
200 * Devices gotten from FADT don't have a "path" attribute
203 result
= device_create_file(&dev
->dev
, &dev_attr_path
);
208 if(dev
->flags
.hardware_id
) {
209 result
= device_create_file(&dev
->dev
, &dev_attr_hid
);
214 if (dev
->flags
.hardware_id
|| dev
->flags
.compatible_ids
){
215 result
= device_create_file(&dev
->dev
, &dev_attr_modalias
);
221 * If device has _EJ0, 'eject' file is created that is used to trigger
222 * hot-removal function from userland.
224 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
225 if (ACPI_SUCCESS(status
))
226 result
= device_create_file(&dev
->dev
, &dev_attr_eject
);
231 static void acpi_device_remove_files(struct acpi_device
*dev
)
237 * If device has _EJ0, 'eject' file is created that is used to trigger
238 * hot-removal function from userland.
240 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
241 if (ACPI_SUCCESS(status
))
242 device_remove_file(&dev
->dev
, &dev_attr_eject
);
244 if (dev
->flags
.hardware_id
|| dev
->flags
.compatible_ids
)
245 device_remove_file(&dev
->dev
, &dev_attr_modalias
);
247 if(dev
->flags
.hardware_id
)
248 device_remove_file(&dev
->dev
, &dev_attr_hid
);
250 device_remove_file(&dev
->dev
, &dev_attr_path
);
252 /* --------------------------------------------------------------------------
254 -------------------------------------------------------------------------- */
256 int acpi_match_device_ids(struct acpi_device
*device
,
257 const struct acpi_device_id
*ids
)
259 const struct acpi_device_id
*id
;
261 if (device
->flags
.hardware_id
) {
262 for (id
= ids
; id
->id
[0]; id
++) {
263 if (!strcmp((char*)id
->id
, device
->pnp
.hardware_id
))
268 if (device
->flags
.compatible_ids
) {
269 struct acpi_compatible_id_list
*cid_list
= device
->pnp
.cid_list
;
272 for (id
= ids
; id
->id
[0]; id
++) {
273 /* compare multiple _CID entries against driver ids */
274 for (i
= 0; i
< cid_list
->count
; i
++) {
275 if (!strcmp((char*)id
->id
,
276 cid_list
->id
[i
].value
))
284 EXPORT_SYMBOL(acpi_match_device_ids
);
286 static void acpi_device_release(struct device
*dev
)
288 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
290 kfree(acpi_dev
->pnp
.cid_list
);
294 static int acpi_device_suspend(struct device
*dev
, pm_message_t state
)
296 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
297 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
299 if (acpi_drv
&& acpi_drv
->ops
.suspend
)
300 return acpi_drv
->ops
.suspend(acpi_dev
, state
);
304 static int acpi_device_resume(struct device
*dev
)
306 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
307 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
309 if (acpi_drv
&& acpi_drv
->ops
.resume
)
310 return acpi_drv
->ops
.resume(acpi_dev
);
314 static int acpi_bus_match(struct device
*dev
, struct device_driver
*drv
)
316 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
317 struct acpi_driver
*acpi_drv
= to_acpi_driver(drv
);
319 return !acpi_match_device_ids(acpi_dev
, acpi_drv
->ids
);
322 static int acpi_device_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
324 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
327 if (add_uevent_var(env
, "MODALIAS="))
329 len
= create_modalias(acpi_dev
, &env
->buf
[env
->buflen
- 1],
330 sizeof(env
->buf
) - env
->buflen
);
331 if (len
>= (sizeof(env
->buf
) - env
->buflen
))
337 static int acpi_bus_driver_init(struct acpi_device
*, struct acpi_driver
*);
338 static int acpi_start_single_object(struct acpi_device
*);
339 static int acpi_device_probe(struct device
* dev
)
341 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
342 struct acpi_driver
*acpi_drv
= to_acpi_driver(dev
->driver
);
345 ret
= acpi_bus_driver_init(acpi_dev
, acpi_drv
);
347 if (acpi_dev
->bus_ops
.acpi_op_start
)
348 acpi_start_single_object(acpi_dev
);
349 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
350 "Found driver [%s] for device [%s]\n",
351 acpi_drv
->name
, acpi_dev
->pnp
.bus_id
));
357 static int acpi_device_remove(struct device
* dev
)
359 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
360 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
363 if (acpi_drv
->ops
.stop
)
364 acpi_drv
->ops
.stop(acpi_dev
, acpi_dev
->removal_type
);
365 if (acpi_drv
->ops
.remove
)
366 acpi_drv
->ops
.remove(acpi_dev
, acpi_dev
->removal_type
);
368 acpi_dev
->driver
= NULL
;
369 acpi_driver_data(dev
) = NULL
;
375 static void acpi_device_shutdown(struct device
*dev
)
377 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
378 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
380 if (acpi_drv
&& acpi_drv
->ops
.shutdown
)
381 acpi_drv
->ops
.shutdown(acpi_dev
);
386 struct bus_type acpi_bus_type
= {
388 .suspend
= acpi_device_suspend
,
389 .resume
= acpi_device_resume
,
390 .shutdown
= acpi_device_shutdown
,
391 .match
= acpi_bus_match
,
392 .probe
= acpi_device_probe
,
393 .remove
= acpi_device_remove
,
394 .uevent
= acpi_device_uevent
,
397 static int acpi_device_register(struct acpi_device
*device
,
398 struct acpi_device
*parent
)
401 struct acpi_device_bus_id
*acpi_device_bus_id
, *new_bus_id
;
406 * Link this device to its parent and siblings.
408 INIT_LIST_HEAD(&device
->children
);
409 INIT_LIST_HEAD(&device
->node
);
410 INIT_LIST_HEAD(&device
->g_list
);
411 INIT_LIST_HEAD(&device
->wakeup_list
);
413 new_bus_id
= kzalloc(sizeof(struct acpi_device_bus_id
), GFP_KERNEL
);
415 printk(KERN_ERR PREFIX
"Memory allocation error\n");
419 spin_lock(&acpi_device_lock
);
421 * Find suitable bus_id and instance number in acpi_bus_id_list
422 * If failed, create one and link it into acpi_bus_id_list
424 list_for_each_entry(acpi_device_bus_id
, &acpi_bus_id_list
, node
) {
425 if(!strcmp(acpi_device_bus_id
->bus_id
, device
->flags
.hardware_id
? device
->pnp
.hardware_id
: "device")) {
426 acpi_device_bus_id
->instance_no
++;
433 acpi_device_bus_id
= new_bus_id
;
434 strcpy(acpi_device_bus_id
->bus_id
, device
->flags
.hardware_id
? device
->pnp
.hardware_id
: "device");
435 acpi_device_bus_id
->instance_no
= 0;
436 list_add_tail(&acpi_device_bus_id
->node
, &acpi_bus_id_list
);
438 sprintf(device
->dev
.bus_id
, "%s:%02x", acpi_device_bus_id
->bus_id
, acpi_device_bus_id
->instance_no
);
440 if (device
->parent
) {
441 list_add_tail(&device
->node
, &device
->parent
->children
);
442 list_add_tail(&device
->g_list
, &device
->parent
->g_list
);
444 list_add_tail(&device
->g_list
, &acpi_device_list
);
445 if (device
->wakeup
.flags
.valid
)
446 list_add_tail(&device
->wakeup_list
, &acpi_wakeup_device_list
);
447 spin_unlock(&acpi_device_lock
);
450 device
->dev
.parent
= &parent
->dev
;
451 device
->dev
.bus
= &acpi_bus_type
;
452 device_initialize(&device
->dev
);
453 device
->dev
.release
= &acpi_device_release
;
454 result
= device_add(&device
->dev
);
456 printk(KERN_ERR PREFIX
"Error adding device %s", device
->dev
.bus_id
);
460 result
= acpi_device_setup_files(device
);
462 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
, "Error creating sysfs interface for device %s\n", device
->dev
.bus_id
));
464 device
->removal_type
= ACPI_BUS_REMOVAL_NORMAL
;
467 spin_lock(&acpi_device_lock
);
468 if (device
->parent
) {
469 list_del(&device
->node
);
470 list_del(&device
->g_list
);
472 list_del(&device
->g_list
);
473 list_del(&device
->wakeup_list
);
474 spin_unlock(&acpi_device_lock
);
478 static void acpi_device_unregister(struct acpi_device
*device
, int type
)
480 spin_lock(&acpi_device_lock
);
481 if (device
->parent
) {
482 list_del(&device
->node
);
483 list_del(&device
->g_list
);
485 list_del(&device
->g_list
);
487 list_del(&device
->wakeup_list
);
488 spin_unlock(&acpi_device_lock
);
490 acpi_detach_data(device
->handle
, acpi_bus_data_handler
);
492 acpi_device_remove_files(device
);
493 device_unregister(&device
->dev
);
496 /* --------------------------------------------------------------------------
498 -------------------------------------------------------------------------- */
500 * acpi_bus_driver_init - add a device to a driver
501 * @device: the device to add and initialize
502 * @driver: driver for the device
504 * Used to initialize a device via its device driver. Called whenever a
505 * driver is bound to a device. Invokes the driver's add() ops.
508 acpi_bus_driver_init(struct acpi_device
*device
, struct acpi_driver
*driver
)
513 if (!device
|| !driver
)
516 if (!driver
->ops
.add
)
519 result
= driver
->ops
.add(device
);
521 device
->driver
= NULL
;
522 acpi_driver_data(device
) = NULL
;
526 device
->driver
= driver
;
529 * TBD - Configuration Management: Assign resources to device based
530 * upon possible configuration and currently allocated resources.
533 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
534 "Driver successfully bound to device\n"));
538 static int acpi_start_single_object(struct acpi_device
*device
)
541 struct acpi_driver
*driver
;
544 if (!(driver
= device
->driver
))
547 if (driver
->ops
.start
) {
548 result
= driver
->ops
.start(device
);
549 if (result
&& driver
->ops
.remove
)
550 driver
->ops
.remove(device
, ACPI_BUS_REMOVAL_NORMAL
);
557 * acpi_bus_register_driver - register a driver with the ACPI bus
558 * @driver: driver being registered
560 * Registers a driver with the ACPI bus. Searches the namespace for all
561 * devices that match the driver's criteria and binds. Returns zero for
562 * success or a negative error status for failure.
564 int acpi_bus_register_driver(struct acpi_driver
*driver
)
570 driver
->drv
.name
= driver
->name
;
571 driver
->drv
.bus
= &acpi_bus_type
;
572 driver
->drv
.owner
= driver
->owner
;
574 ret
= driver_register(&driver
->drv
);
578 EXPORT_SYMBOL(acpi_bus_register_driver
);
581 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
582 * @driver: driver to unregister
584 * Unregisters a driver with the ACPI bus. Searches the namespace for all
585 * devices that match the driver's criteria and unbinds.
587 void acpi_bus_unregister_driver(struct acpi_driver
*driver
)
589 driver_unregister(&driver
->drv
);
592 EXPORT_SYMBOL(acpi_bus_unregister_driver
);
594 /* --------------------------------------------------------------------------
596 -------------------------------------------------------------------------- */
598 acpi_bus_get_ejd(acpi_handle handle
, acpi_handle
*ejd
)
602 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
603 union acpi_object
*obj
;
605 status
= acpi_get_handle(handle
, "_EJD", &tmp
);
606 if (ACPI_FAILURE(status
))
609 status
= acpi_evaluate_object(handle
, "_EJD", NULL
, &buffer
);
610 if (ACPI_SUCCESS(status
)) {
611 obj
= buffer
.pointer
;
612 <<<<<<< HEAD
:drivers
/acpi
/scan
.c
613 status
= acpi_get_handle(NULL
, obj
->string
.pointer
, ejd
);
615 status
= acpi_get_handle(ACPI_ROOT_OBJECT
, obj
->string
.pointer
,
617 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/scan
.c
618 kfree(buffer
.pointer
);
622 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd
);
624 void acpi_bus_data_handler(acpi_handle handle
, u32 function
, void *context
)
632 static int acpi_bus_get_perf_flags(struct acpi_device
*device
)
634 device
->performance
.state
= ACPI_STATE_UNKNOWN
;
639 acpi_bus_extract_wakeup_device_power_package(struct acpi_device
*device
,
640 union acpi_object
*package
)
643 union acpi_object
*element
= NULL
;
645 if (!device
|| !package
|| (package
->package
.count
< 2))
646 return AE_BAD_PARAMETER
;
648 element
= &(package
->package
.elements
[0]);
650 return AE_BAD_PARAMETER
;
651 if (element
->type
== ACPI_TYPE_PACKAGE
) {
652 if ((element
->package
.count
< 2) ||
653 (element
->package
.elements
[0].type
!=
654 ACPI_TYPE_LOCAL_REFERENCE
)
655 || (element
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
))
657 device
->wakeup
.gpe_device
=
658 element
->package
.elements
[0].reference
.handle
;
659 device
->wakeup
.gpe_number
=
660 (u32
) element
->package
.elements
[1].integer
.value
;
661 } else if (element
->type
== ACPI_TYPE_INTEGER
) {
662 device
->wakeup
.gpe_number
= element
->integer
.value
;
666 element
= &(package
->package
.elements
[1]);
667 if (element
->type
!= ACPI_TYPE_INTEGER
) {
670 device
->wakeup
.sleep_state
= element
->integer
.value
;
672 if ((package
->package
.count
- 2) > ACPI_MAX_HANDLES
) {
675 device
->wakeup
.resources
.count
= package
->package
.count
- 2;
676 for (i
= 0; i
< device
->wakeup
.resources
.count
; i
++) {
677 element
= &(package
->package
.elements
[i
+ 2]);
678 if (element
->type
!= ACPI_TYPE_ANY
) {
682 device
->wakeup
.resources
.handles
[i
] = element
->reference
.handle
;
688 static int acpi_bus_get_wakeup_device_flags(struct acpi_device
*device
)
690 acpi_status status
= 0;
691 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
692 union acpi_object
*package
= NULL
;
694 struct acpi_device_id button_device_ids
[] = {
703 status
= acpi_evaluate_object(device
->handle
, "_PRW", NULL
, &buffer
);
704 if (ACPI_FAILURE(status
)) {
705 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PRW"));
709 package
= (union acpi_object
*)buffer
.pointer
;
710 status
= acpi_bus_extract_wakeup_device_power_package(device
, package
);
711 if (ACPI_FAILURE(status
)) {
712 ACPI_EXCEPTION((AE_INFO
, status
, "Extracting _PRW package"));
716 kfree(buffer
.pointer
);
718 device
->wakeup
.flags
.valid
= 1;
719 /* Power button, Lid switch always enable wakeup */
720 if (!acpi_match_device_ids(device
, button_device_ids
))
721 device
->wakeup
.flags
.run_wake
= 1;
724 if (ACPI_FAILURE(status
))
725 device
->flags
.wake_capable
= 0;
729 static int acpi_bus_get_power_flags(struct acpi_device
*device
)
731 acpi_status status
= 0;
732 acpi_handle handle
= NULL
;
737 * Power Management Flags
739 status
= acpi_get_handle(device
->handle
, "_PSC", &handle
);
740 if (ACPI_SUCCESS(status
))
741 device
->power
.flags
.explicit_get
= 1;
742 status
= acpi_get_handle(device
->handle
, "_IRC", &handle
);
743 if (ACPI_SUCCESS(status
))
744 device
->power
.flags
.inrush_current
= 1;
747 * Enumerate supported power management states
749 for (i
= ACPI_STATE_D0
; i
<= ACPI_STATE_D3
; i
++) {
750 struct acpi_device_power_state
*ps
= &device
->power
.states
[i
];
751 char object_name
[5] = { '_', 'P', 'R', '0' + i
, '\0' };
753 /* Evaluate "_PRx" to se if power resources are referenced */
754 acpi_evaluate_reference(device
->handle
, object_name
, NULL
,
756 if (ps
->resources
.count
) {
757 device
->power
.flags
.power_resources
= 1;
761 /* Evaluate "_PSx" to see if we can do explicit sets */
762 object_name
[2] = 'S';
763 status
= acpi_get_handle(device
->handle
, object_name
, &handle
);
764 if (ACPI_SUCCESS(status
)) {
765 ps
->flags
.explicit_set
= 1;
769 /* State is valid if we have some power control */
770 if (ps
->resources
.count
|| ps
->flags
.explicit_set
)
773 ps
->power
= -1; /* Unknown - driver assigned */
774 ps
->latency
= -1; /* Unknown - driver assigned */
777 /* Set defaults for D0 and D3 states (always valid) */
778 device
->power
.states
[ACPI_STATE_D0
].flags
.valid
= 1;
779 device
->power
.states
[ACPI_STATE_D0
].power
= 100;
780 device
->power
.states
[ACPI_STATE_D3
].flags
.valid
= 1;
781 device
->power
.states
[ACPI_STATE_D3
].power
= 0;
783 /* TBD: System wake support and resource requirements. */
785 device
->power
.state
= ACPI_STATE_UNKNOWN
;
790 static int acpi_bus_get_flags(struct acpi_device
*device
)
792 acpi_status status
= AE_OK
;
793 acpi_handle temp
= NULL
;
796 /* Presence of _STA indicates 'dynamic_status' */
797 status
= acpi_get_handle(device
->handle
, "_STA", &temp
);
798 if (ACPI_SUCCESS(status
))
799 device
->flags
.dynamic_status
= 1;
801 /* Presence of _CID indicates 'compatible_ids' */
802 status
= acpi_get_handle(device
->handle
, "_CID", &temp
);
803 if (ACPI_SUCCESS(status
))
804 device
->flags
.compatible_ids
= 1;
806 /* Presence of _RMV indicates 'removable' */
807 status
= acpi_get_handle(device
->handle
, "_RMV", &temp
);
808 if (ACPI_SUCCESS(status
))
809 device
->flags
.removable
= 1;
811 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
812 status
= acpi_get_handle(device
->handle
, "_EJD", &temp
);
813 if (ACPI_SUCCESS(status
))
814 device
->flags
.ejectable
= 1;
816 status
= acpi_get_handle(device
->handle
, "_EJ0", &temp
);
817 if (ACPI_SUCCESS(status
))
818 device
->flags
.ejectable
= 1;
821 /* Presence of _LCK indicates 'lockable' */
822 status
= acpi_get_handle(device
->handle
, "_LCK", &temp
);
823 if (ACPI_SUCCESS(status
))
824 device
->flags
.lockable
= 1;
826 /* Presence of _PS0|_PR0 indicates 'power manageable' */
827 status
= acpi_get_handle(device
->handle
, "_PS0", &temp
);
828 if (ACPI_FAILURE(status
))
829 status
= acpi_get_handle(device
->handle
, "_PR0", &temp
);
830 if (ACPI_SUCCESS(status
))
831 device
->flags
.power_manageable
= 1;
833 /* Presence of _PRW indicates wake capable */
834 status
= acpi_get_handle(device
->handle
, "_PRW", &temp
);
835 if (ACPI_SUCCESS(status
))
836 device
->flags
.wake_capable
= 1;
838 /* TBD: Performance management */
843 static void acpi_device_get_busid(struct acpi_device
*device
,
844 acpi_handle handle
, int type
)
846 char bus_id
[5] = { '?', 0 };
847 struct acpi_buffer buffer
= { sizeof(bus_id
), bus_id
};
853 * The device's Bus ID is simply the object name.
854 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
857 case ACPI_BUS_TYPE_SYSTEM
:
858 strcpy(device
->pnp
.bus_id
, "ACPI");
860 case ACPI_BUS_TYPE_POWER_BUTTON
:
861 strcpy(device
->pnp
.bus_id
, "PWRF");
863 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
864 strcpy(device
->pnp
.bus_id
, "SLPF");
867 acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
);
868 /* Clean up trailing underscores (if any) */
869 for (i
= 3; i
> 1; i
--) {
870 if (bus_id
[i
] == '_')
875 strcpy(device
->pnp
.bus_id
, bus_id
);
881 acpi_video_bus_match(struct acpi_device
*device
)
883 acpi_handle h_dummy1
;
884 acpi_handle h_dummy2
;
885 acpi_handle h_dummy3
;
891 /* Since there is no HID, CID for ACPI Video drivers, we have
892 * to check well known required nodes for each feature we support.
895 /* Does this device able to support video switching ? */
896 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOD", &h_dummy1
)) &&
897 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOS", &h_dummy2
)))
900 /* Does this device able to retrieve a video ROM ? */
901 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_ROM", &h_dummy1
)))
904 /* Does this device able to configure which video head to be POSTed ? */
905 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_VPO", &h_dummy1
)) &&
906 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_GPD", &h_dummy2
)) &&
907 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_SPD", &h_dummy3
)))
914 * acpi_bay_match - see if a device is an ejectable driver bay
916 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
917 * then we can safely call it an ejectable drive bay
919 static int acpi_bay_match(struct acpi_device
*device
){
925 handle
= device
->handle
;
927 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
928 if (ACPI_FAILURE(status
))
931 if ((ACPI_SUCCESS(acpi_get_handle(handle
, "_GTF", &tmp
))) ||
932 (ACPI_SUCCESS(acpi_get_handle(handle
, "_GTM", &tmp
))) ||
933 (ACPI_SUCCESS(acpi_get_handle(handle
, "_STM", &tmp
))) ||
934 (ACPI_SUCCESS(acpi_get_handle(handle
, "_SDD", &tmp
))))
937 if (acpi_get_parent(handle
, &phandle
))
940 if ((ACPI_SUCCESS(acpi_get_handle(phandle
, "_GTF", &tmp
))) ||
941 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_GTM", &tmp
))) ||
942 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_STM", &tmp
))) ||
943 (ACPI_SUCCESS(acpi_get_handle(phandle
, "_SDD", &tmp
))))
950 * acpi_dock_match - see if a device has a _DCK method
952 static int acpi_dock_match(struct acpi_device
*device
)
955 return acpi_get_handle(device
->handle
, "_DCK", &tmp
);
958 static void acpi_device_set_id(struct acpi_device
*device
,
959 struct acpi_device
*parent
, acpi_handle handle
,
962 struct acpi_device_info
*info
;
963 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
966 struct acpi_compatible_id_list
*cid_list
= NULL
;
967 const char *cid_add
= NULL
;
971 case ACPI_BUS_TYPE_DEVICE
:
972 status
= acpi_get_object_info(handle
, &buffer
);
973 if (ACPI_FAILURE(status
)) {
974 <<<<<<< HEAD
:drivers
/acpi
/scan
.c
975 printk(KERN_ERR PREFIX
"%s: Error reading device info\n", __FUNCTION__
);
977 printk(KERN_ERR PREFIX
"%s: Error reading device info\n", __func__
);
978 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/scan
.c
982 info
= buffer
.pointer
;
983 if (info
->valid
& ACPI_VALID_HID
)
984 hid
= info
->hardware_id
.value
;
985 if (info
->valid
& ACPI_VALID_UID
)
986 uid
= info
->unique_id
.value
;
987 if (info
->valid
& ACPI_VALID_CID
)
988 cid_list
= &info
->compatibility_id
;
989 if (info
->valid
& ACPI_VALID_ADR
) {
990 device
->pnp
.bus_address
= info
->address
;
991 device
->flags
.bus_address
= 1;
994 /* If we have a video/bay/dock device, add our selfdefined
995 HID to the CID list. Like that the video/bay/dock drivers
996 will get autoloaded and the device might still match
997 against another driver.
999 if (ACPI_SUCCESS(acpi_video_bus_match(device
)))
1000 cid_add
= ACPI_VIDEO_HID
;
1001 else if (ACPI_SUCCESS(acpi_bay_match(device
)))
1002 cid_add
= ACPI_BAY_HID
;
1003 else if (ACPI_SUCCESS(acpi_dock_match(device
)))
1004 cid_add
= ACPI_DOCK_HID
;
1007 case ACPI_BUS_TYPE_POWER
:
1008 hid
= ACPI_POWER_HID
;
1010 case ACPI_BUS_TYPE_PROCESSOR
:
1011 hid
= ACPI_PROCESSOR_HID
;
1013 case ACPI_BUS_TYPE_SYSTEM
:
1014 hid
= ACPI_SYSTEM_HID
;
1016 case ACPI_BUS_TYPE_THERMAL
:
1017 hid
= ACPI_THERMAL_HID
;
1019 case ACPI_BUS_TYPE_POWER_BUTTON
:
1020 hid
= ACPI_BUTTON_HID_POWERF
;
1022 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
1023 hid
= ACPI_BUTTON_HID_SLEEPF
;
1030 * Fix for the system root bus device -- the only root-level device.
1032 if (((acpi_handle
)parent
== ACPI_ROOT_OBJECT
) && (type
== ACPI_BUS_TYPE_DEVICE
)) {
1034 strcpy(device
->pnp
.device_name
, ACPI_BUS_DEVICE_NAME
);
1035 strcpy(device
->pnp
.device_class
, ACPI_BUS_CLASS
);
1039 strcpy(device
->pnp
.hardware_id
, hid
);
1040 device
->flags
.hardware_id
= 1;
1043 strcpy(device
->pnp
.unique_id
, uid
);
1044 device
->flags
.unique_id
= 1;
1046 if (cid_list
|| cid_add
) {
1047 struct acpi_compatible_id_list
*list
;
1052 size
= cid_list
->size
;
1053 } else if (cid_add
) {
1054 size
= sizeof(struct acpi_compatible_id_list
);
1055 cid_list
= ACPI_ALLOCATE_ZEROED((acpi_size
) size
);
1057 printk(KERN_ERR
"Memory allocation error\n");
1058 kfree(buffer
.pointer
);
1061 cid_list
->count
= 0;
1062 cid_list
->size
= size
;
1066 size
+= sizeof(struct acpi_compatible_id
);
1067 list
= kmalloc(size
, GFP_KERNEL
);
1071 memcpy(list
, cid_list
, cid_list
->size
);
1072 count
= cid_list
->count
;
1075 strncpy(list
->id
[count
].value
, cid_add
,
1076 ACPI_MAX_CID_LENGTH
);
1078 device
->flags
.compatible_ids
= 1;
1081 list
->count
= count
;
1082 device
->pnp
.cid_list
= list
;
1084 printk(KERN_ERR PREFIX
"Memory allocation error\n");
1087 kfree(buffer
.pointer
);
1090 static int acpi_device_set_context(struct acpi_device
*device
, int type
)
1092 acpi_status status
= AE_OK
;
1097 * Attach this 'struct acpi_device' to the ACPI object. This makes
1098 * resolutions from handle->device very efficient. Note that we need
1099 * to be careful with fixed-feature devices as they all attach to the
1102 if (type
!= ACPI_BUS_TYPE_POWER_BUTTON
&&
1103 type
!= ACPI_BUS_TYPE_SLEEP_BUTTON
) {
1104 status
= acpi_attach_data(device
->handle
,
1105 acpi_bus_data_handler
, device
);
1107 if (ACPI_FAILURE(status
)) {
1108 printk(KERN_ERR PREFIX
"Error attaching device data\n");
1115 static int acpi_bus_remove(struct acpi_device
*dev
, int rmdevice
)
1120 dev
->removal_type
= ACPI_BUS_REMOVAL_EJECT
;
1121 device_release_driver(&dev
->dev
);
1127 * unbind _ADR-Based Devices when hot removal
1129 if (dev
->flags
.bus_address
) {
1130 if ((dev
->parent
) && (dev
->parent
->ops
.unbind
))
1131 dev
->parent
->ops
.unbind(dev
);
1133 acpi_device_unregister(dev
, ACPI_BUS_REMOVAL_EJECT
);
1139 acpi_is_child_device(struct acpi_device
*device
,
1140 int (*matcher
)(struct acpi_device
*))
1142 int result
= -ENODEV
;
1145 if (ACPI_SUCCESS(matcher(device
)))
1147 } while ((device
= device
->parent
));
1153 acpi_add_single_object(struct acpi_device
**child
,
1154 struct acpi_device
*parent
, acpi_handle handle
, int type
,
1155 struct acpi_bus_ops
*ops
)
1158 struct acpi_device
*device
= NULL
;
1164 device
= kzalloc(sizeof(struct acpi_device
), GFP_KERNEL
);
1166 printk(KERN_ERR PREFIX
"Memory allocation error\n");
1170 device
->handle
= handle
;
1171 device
->parent
= parent
;
1172 device
->bus_ops
= *ops
; /* workround for not call .start */
1175 acpi_device_get_busid(device
, handle
, type
);
1180 * Get prior to calling acpi_bus_get_status() so we know whether
1181 * or not _STA is present. Note that we only look for object
1182 * handles -- cannot evaluate objects until we know the device is
1183 * present and properly initialized.
1185 result
= acpi_bus_get_flags(device
);
1192 * See if the device is present. We always assume that non-Device
1193 * and non-Processor objects (e.g. thermal zones, power resources,
1194 * etc.) are present, functioning, etc. (at least when parent object
1195 * is present). Note that _STA has a different meaning for some
1196 * objects (e.g. power resources) so we need to be careful how we use
1200 case ACPI_BUS_TYPE_PROCESSOR
:
1201 case ACPI_BUS_TYPE_DEVICE
:
1202 result
= acpi_bus_get_status(device
);
1203 if (ACPI_FAILURE(result
)) {
1207 if (!device
->status
.present
) {
1208 /* Bay and dock should be handled even if absent */
1210 acpi_is_child_device(device
, acpi_bay_match
)) &&
1212 acpi_is_child_device(device
, acpi_dock_match
))) {
1219 STRUCT_TO_INT(device
->status
) =
1220 ACPI_STA_DEVICE_PRESENT
| ACPI_STA_DEVICE_ENABLED
|
1221 ACPI_STA_DEVICE_UI
| ACPI_STA_DEVICE_FUNCTIONING
;
1228 * TBD: Synch with Core's enumeration/initialization process.
1232 * Hardware ID, Unique ID, & Bus Address
1233 * -------------------------------------
1235 acpi_device_set_id(device
, parent
, handle
, type
);
1241 if (device
->flags
.power_manageable
) {
1242 result
= acpi_bus_get_power_flags(device
);
1248 * Wakeup device management
1249 *-----------------------
1251 if (device
->flags
.wake_capable
) {
1252 result
= acpi_bus_get_wakeup_device_flags(device
);
1258 * Performance Management
1259 * ----------------------
1261 if (device
->flags
.performance_manageable
) {
1262 result
= acpi_bus_get_perf_flags(device
);
1267 if ((result
= acpi_device_set_context(device
, type
)))
1270 result
= acpi_device_register(device
, parent
);
1273 * Bind _ADR-Based Devices when hot add
1275 if (device
->flags
.bus_address
) {
1276 if (device
->parent
&& device
->parent
->ops
.bind
)
1277 device
->parent
->ops
.bind(device
);
1284 kfree(device
->pnp
.cid_list
);
1291 static int acpi_bus_scan(struct acpi_device
*start
, struct acpi_bus_ops
*ops
)
1293 acpi_status status
= AE_OK
;
1294 struct acpi_device
*parent
= NULL
;
1295 struct acpi_device
*child
= NULL
;
1296 acpi_handle phandle
= NULL
;
1297 acpi_handle chandle
= NULL
;
1298 acpi_object_type type
= 0;
1306 phandle
= start
->handle
;
1309 * Parse through the ACPI namespace, identify all 'devices', and
1310 * create a new 'struct acpi_device' for each.
1312 while ((level
> 0) && parent
) {
1314 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
1318 * If this scope is exhausted then move our way back up.
1320 if (ACPI_FAILURE(status
)) {
1323 acpi_get_parent(phandle
, &phandle
);
1325 parent
= parent
->parent
;
1329 status
= acpi_get_type(chandle
, &type
);
1330 if (ACPI_FAILURE(status
))
1334 * If this is a scope object then parse it (depth-first).
1336 if (type
== ACPI_TYPE_LOCAL_SCOPE
) {
1344 * We're only interested in objects that we consider 'devices'.
1347 case ACPI_TYPE_DEVICE
:
1348 type
= ACPI_BUS_TYPE_DEVICE
;
1350 case ACPI_TYPE_PROCESSOR
:
1351 type
= ACPI_BUS_TYPE_PROCESSOR
;
1353 case ACPI_TYPE_THERMAL
:
1354 type
= ACPI_BUS_TYPE_THERMAL
;
1356 case ACPI_TYPE_POWER
:
1357 type
= ACPI_BUS_TYPE_POWER
;
1363 if (ops
->acpi_op_add
)
1364 status
= acpi_add_single_object(&child
, parent
,
1365 chandle
, type
, ops
);
1367 status
= acpi_bus_get_device(chandle
, &child
);
1369 if (ACPI_FAILURE(status
))
1372 if (ops
->acpi_op_start
&& !(ops
->acpi_op_add
)) {
1373 status
= acpi_start_single_object(child
);
1374 if (ACPI_FAILURE(status
))
1379 * If the device is present, enabled, and functioning then
1380 * parse its scope (depth-first). Note that we need to
1381 * represent absent devices to facilitate PnP notifications
1382 * -- but only the subtree head (not all of its children,
1383 * which will be enumerated when the parent is inserted).
1385 * TBD: Need notifications and other detection mechanisms
1386 * in place before we can fully implement this.
1388 if (child
->status
.present
) {
1389 status
= acpi_get_next_object(ACPI_TYPE_ANY
, chandle
,
1391 if (ACPI_SUCCESS(status
)) {
1404 acpi_bus_add(struct acpi_device
**child
,
1405 struct acpi_device
*parent
, acpi_handle handle
, int type
)
1408 struct acpi_bus_ops ops
;
1410 memset(&ops
, 0, sizeof(ops
));
1411 ops
.acpi_op_add
= 1;
1413 result
= acpi_add_single_object(child
, parent
, handle
, type
, &ops
);
1415 result
= acpi_bus_scan(*child
, &ops
);
1420 EXPORT_SYMBOL(acpi_bus_add
);
1422 int acpi_bus_start(struct acpi_device
*device
)
1425 struct acpi_bus_ops ops
;
1431 result
= acpi_start_single_object(device
);
1433 memset(&ops
, 0, sizeof(ops
));
1434 ops
.acpi_op_start
= 1;
1435 result
= acpi_bus_scan(device
, &ops
);
1440 EXPORT_SYMBOL(acpi_bus_start
);
1442 int acpi_bus_trim(struct acpi_device
*start
, int rmdevice
)
1445 struct acpi_device
*parent
, *child
;
1446 acpi_handle phandle
, chandle
;
1447 acpi_object_type type
;
1452 phandle
= start
->handle
;
1453 child
= chandle
= NULL
;
1455 while ((level
> 0) && parent
&& (!err
)) {
1456 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
1460 * If this scope is exhausted then move our way back up.
1462 if (ACPI_FAILURE(status
)) {
1465 acpi_get_parent(phandle
, &phandle
);
1467 parent
= parent
->parent
;
1470 err
= acpi_bus_remove(child
, rmdevice
);
1472 err
= acpi_bus_remove(child
, 1);
1477 status
= acpi_get_type(chandle
, &type
);
1478 if (ACPI_FAILURE(status
)) {
1482 * If there is a device corresponding to chandle then
1483 * parse it (depth-first).
1485 if (acpi_bus_get_device(chandle
, &child
) == 0) {
1495 EXPORT_SYMBOL_GPL(acpi_bus_trim
);
1498 static int acpi_bus_scan_fixed(struct acpi_device
*root
)
1501 struct acpi_device
*device
= NULL
;
1502 struct acpi_bus_ops ops
;
1507 memset(&ops
, 0, sizeof(ops
));
1508 ops
.acpi_op_add
= 1;
1509 ops
.acpi_op_start
= 1;
1512 * Enumerate all fixed-feature devices.
1514 if ((acpi_gbl_FADT
.flags
& ACPI_FADT_POWER_BUTTON
) == 0) {
1515 result
= acpi_add_single_object(&device
, acpi_root
,
1517 ACPI_BUS_TYPE_POWER_BUTTON
,
1521 if ((acpi_gbl_FADT
.flags
& ACPI_FADT_SLEEP_BUTTON
) == 0) {
1522 result
= acpi_add_single_object(&device
, acpi_root
,
1524 ACPI_BUS_TYPE_SLEEP_BUTTON
,
1531 int __init
acpi_boot_ec_enable(void);
1533 static int __init
acpi_scan_init(void)
1536 struct acpi_bus_ops ops
;
1542 memset(&ops
, 0, sizeof(ops
));
1543 ops
.acpi_op_add
= 1;
1544 ops
.acpi_op_start
= 1;
1546 result
= bus_register(&acpi_bus_type
);
1548 /* We don't want to quit even if we failed to add suspend/resume */
1549 printk(KERN_ERR PREFIX
"Could not register bus type\n");
1553 * Create the root device in the bus's device tree
1555 result
= acpi_add_single_object(&acpi_root
, NULL
, ACPI_ROOT_OBJECT
,
1556 ACPI_BUS_TYPE_SYSTEM
, &ops
);
1561 * Enumerate devices in the ACPI namespace.
1563 result
= acpi_bus_scan_fixed(acpi_root
);
1565 /* EC region might be needed at bus_scan, so enable it now */
1566 acpi_boot_ec_enable();
1569 result
= acpi_bus_scan(acpi_root
, &ops
);
1572 acpi_device_unregister(acpi_root
, ACPI_BUS_REMOVAL_NORMAL
);
1578 subsys_initcall(acpi_scan_init
);