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 "ACPI_BUS"
20 #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
21 #define ACPI_BUS_DEVICE_NAME "System Bus"
23 static LIST_HEAD(acpi_device_list
);
24 DEFINE_SPINLOCK(acpi_device_lock
);
25 LIST_HEAD(acpi_wakeup_device_list
);
27 static int acpi_eject_operation(acpi_handle handle
, int lockable
)
29 struct acpi_object_list arg_list
;
30 union acpi_object arg
;
31 acpi_status status
= AE_OK
;
39 arg_list
.pointer
= &arg
;
40 arg
.type
= ACPI_TYPE_INTEGER
;
41 arg
.integer
.value
= 0;
42 acpi_evaluate_object(handle
, "_LCK", &arg_list
, NULL
);
46 arg_list
.pointer
= &arg
;
47 arg
.type
= ACPI_TYPE_INTEGER
;
48 arg
.integer
.value
= 1;
54 status
= acpi_evaluate_object(handle
, "_EJ0", &arg_list
, NULL
);
55 if (ACPI_FAILURE(status
)) {
63 acpi_eject_store(struct device
*d
, struct device_attribute
*attr
,
64 const char *buf
, size_t count
)
71 acpi_object_type type
= 0;
72 struct acpi_device
*acpi_device
= to_acpi_device(d
);
74 if ((!count
) || (buf
[0] != '1')) {
78 if (acpi_device
->driver
== NULL
) {
83 status
= acpi_get_type(acpi_device
->handle
, &type
);
84 if (ACPI_FAILURE(status
) || (!acpi_device
->flags
.ejectable
)) {
89 islockable
= acpi_device
->flags
.lockable
;
90 handle
= acpi_device
->handle
;
92 result
= acpi_bus_trim(acpi_device
, 1);
95 result
= acpi_eject_operation(handle
, islockable
);
104 static DEVICE_ATTR(eject
, 0200, NULL
, acpi_eject_store
);
106 static void acpi_device_setup_files(struct acpi_device
*dev
)
112 * If device has _EJ0, 'eject' file is created that is used to trigger
113 * hot-removal function from userland.
115 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
116 if (ACPI_SUCCESS(status
))
117 device_create_file(&dev
->dev
, &dev_attr_eject
);
120 static void acpi_device_remove_files(struct acpi_device
*dev
)
126 * If device has _EJ0, 'eject' file is created that is used to trigger
127 * hot-removal function from userland.
129 status
= acpi_get_handle(dev
->handle
, "_EJ0", &temp
);
130 if (ACPI_SUCCESS(status
))
131 device_remove_file(&dev
->dev
, &dev_attr_eject
);
133 /* --------------------------------------------------------------------------
135 -------------------------------------------------------------------------- */
136 static void acpi_device_release(struct device
*dev
)
138 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
140 kfree(acpi_dev
->pnp
.cid_list
);
144 static int acpi_device_suspend(struct device
*dev
, pm_message_t state
)
146 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
147 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
149 if (acpi_drv
&& acpi_drv
->ops
.suspend
)
150 return acpi_drv
->ops
.suspend(acpi_dev
, state
);
154 static int acpi_device_resume(struct device
*dev
)
156 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
157 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
159 if (acpi_drv
&& acpi_drv
->ops
.resume
)
160 return acpi_drv
->ops
.resume(acpi_dev
);
164 static int acpi_bus_match(struct device
*dev
, struct device_driver
*drv
)
166 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
167 struct acpi_driver
*acpi_drv
= to_acpi_driver(drv
);
169 return !acpi_match_ids(acpi_dev
, acpi_drv
->ids
);
172 static int acpi_device_uevent(struct device
*dev
, char **envp
, int num_envp
,
173 char *buffer
, int buffer_size
)
175 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
176 int i
= 0, length
= 0, ret
= 0;
178 if (acpi_dev
->flags
.hardware_id
)
179 ret
= add_uevent_var(envp
, num_envp
, &i
,
180 buffer
, buffer_size
, &length
,
181 "HWID=%s", acpi_dev
->pnp
.hardware_id
);
184 if (acpi_dev
->flags
.compatible_ids
) {
186 struct acpi_compatible_id_list
*cid_list
;
188 cid_list
= acpi_dev
->pnp
.cid_list
;
190 for (j
= 0; j
< cid_list
->count
; j
++) {
191 ret
= add_uevent_var(envp
, num_envp
, &i
, buffer
,
192 buffer_size
, &length
, "COMPTID=%s",
193 cid_list
->id
[j
].value
);
203 static int acpi_bus_driver_init(struct acpi_device
*, struct acpi_driver
*);
204 static int acpi_start_single_object(struct acpi_device
*);
205 static int acpi_device_probe(struct device
* dev
)
207 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
208 struct acpi_driver
*acpi_drv
= to_acpi_driver(dev
->driver
);
211 ret
= acpi_bus_driver_init(acpi_dev
, acpi_drv
);
213 if (acpi_dev
->bus_ops
.acpi_op_start
)
214 acpi_start_single_object(acpi_dev
);
215 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
216 "Found driver [%s] for device [%s]\n",
217 acpi_drv
->name
, acpi_dev
->pnp
.bus_id
));
223 static int acpi_device_remove(struct device
* dev
)
225 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
226 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
229 if (acpi_drv
->ops
.stop
)
230 acpi_drv
->ops
.stop(acpi_dev
, acpi_dev
->removal_type
);
231 if (acpi_drv
->ops
.remove
)
232 acpi_drv
->ops
.remove(acpi_dev
, acpi_dev
->removal_type
);
234 acpi_dev
->driver
= NULL
;
235 acpi_driver_data(dev
) = NULL
;
241 static void acpi_device_shutdown(struct device
*dev
)
243 struct acpi_device
*acpi_dev
= to_acpi_device(dev
);
244 struct acpi_driver
*acpi_drv
= acpi_dev
->driver
;
246 if (acpi_drv
&& acpi_drv
->ops
.shutdown
)
247 acpi_drv
->ops
.shutdown(acpi_dev
);
252 static struct bus_type acpi_bus_type
= {
254 .suspend
= acpi_device_suspend
,
255 .resume
= acpi_device_resume
,
256 .shutdown
= acpi_device_shutdown
,
257 .match
= acpi_bus_match
,
258 .probe
= acpi_device_probe
,
259 .remove
= acpi_device_remove
,
260 .uevent
= acpi_device_uevent
,
263 static void acpi_device_register(struct acpi_device
*device
,
264 struct acpi_device
*parent
)
269 * Link this device to its parent and siblings.
271 INIT_LIST_HEAD(&device
->children
);
272 INIT_LIST_HEAD(&device
->node
);
273 INIT_LIST_HEAD(&device
->g_list
);
274 INIT_LIST_HEAD(&device
->wakeup_list
);
276 spin_lock(&acpi_device_lock
);
277 if (device
->parent
) {
278 list_add_tail(&device
->node
, &device
->parent
->children
);
279 list_add_tail(&device
->g_list
, &device
->parent
->g_list
);
281 list_add_tail(&device
->g_list
, &acpi_device_list
);
282 if (device
->wakeup
.flags
.valid
)
283 list_add_tail(&device
->wakeup_list
, &acpi_wakeup_device_list
);
284 spin_unlock(&acpi_device_lock
);
287 device
->dev
.parent
= &parent
->dev
;
288 device
->dev
.bus
= &acpi_bus_type
;
289 device_initialize(&device
->dev
);
290 sprintf(device
->dev
.bus_id
, "%s", device
->pnp
.bus_id
);
291 device
->dev
.release
= &acpi_device_release
;
292 device_add(&device
->dev
);
294 acpi_device_setup_files(device
);
295 device
->removal_type
= ACPI_BUS_REMOVAL_NORMAL
;
298 static void acpi_device_unregister(struct acpi_device
*device
, int type
)
300 spin_lock(&acpi_device_lock
);
301 if (device
->parent
) {
302 list_del(&device
->node
);
303 list_del(&device
->g_list
);
305 list_del(&device
->g_list
);
307 list_del(&device
->wakeup_list
);
308 spin_unlock(&acpi_device_lock
);
310 acpi_detach_data(device
->handle
, acpi_bus_data_handler
);
312 acpi_device_remove_files(device
);
313 device_unregister(&device
->dev
);
316 /* --------------------------------------------------------------------------
318 -------------------------------------------------------------------------- */
320 * acpi_bus_driver_init - add a device to a driver
321 * @device: the device to add and initialize
322 * @driver: driver for the device
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() ops.
328 acpi_bus_driver_init(struct acpi_device
*device
, struct acpi_driver
*driver
)
333 if (!device
|| !driver
)
336 if (!driver
->ops
.add
)
339 result
= driver
->ops
.add(device
);
341 device
->driver
= NULL
;
342 acpi_driver_data(device
) = NULL
;
346 device
->driver
= driver
;
349 * TBD - Configuration Management: Assign resources to device based
350 * upon possible configuration and currently allocated resources.
353 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
354 "Driver successfully bound to device\n"));
358 static int acpi_start_single_object(struct acpi_device
*device
)
361 struct acpi_driver
*driver
;
364 if (!(driver
= device
->driver
))
367 if (driver
->ops
.start
) {
368 result
= driver
->ops
.start(device
);
369 if (result
&& driver
->ops
.remove
)
370 driver
->ops
.remove(device
, ACPI_BUS_REMOVAL_NORMAL
);
377 * acpi_bus_register_driver - register a driver with the ACPI bus
378 * @driver: driver being registered
380 * Registers a driver with the ACPI bus. Searches the namespace for all
381 * devices that match the driver's criteria and binds. Returns zero for
382 * success or a negative error status for failure.
384 int acpi_bus_register_driver(struct acpi_driver
*driver
)
390 driver
->drv
.name
= driver
->name
;
391 driver
->drv
.bus
= &acpi_bus_type
;
392 driver
->drv
.owner
= driver
->owner
;
394 ret
= driver_register(&driver
->drv
);
398 EXPORT_SYMBOL(acpi_bus_register_driver
);
401 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
402 * @driver: driver to unregister
404 * Unregisters a driver with the ACPI bus. Searches the namespace for all
405 * devices that match the driver's criteria and unbinds.
407 void acpi_bus_unregister_driver(struct acpi_driver
*driver
)
409 driver_unregister(&driver
->drv
);
412 EXPORT_SYMBOL(acpi_bus_unregister_driver
);
414 /* --------------------------------------------------------------------------
416 -------------------------------------------------------------------------- */
418 acpi_bus_get_ejd(acpi_handle handle
, acpi_handle
*ejd
)
422 struct acpi_buffer buffer
= {ACPI_ALLOCATE_BUFFER
, NULL
};
423 union acpi_object
*obj
;
425 status
= acpi_get_handle(handle
, "_EJD", &tmp
);
426 if (ACPI_FAILURE(status
))
429 status
= acpi_evaluate_object(handle
, "_EJD", NULL
, &buffer
);
430 if (ACPI_SUCCESS(status
)) {
431 obj
= buffer
.pointer
;
432 status
= acpi_get_handle(NULL
, obj
->string
.pointer
, ejd
);
433 kfree(buffer
.pointer
);
437 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd
);
439 void acpi_bus_data_handler(acpi_handle handle
, u32 function
, void *context
)
447 int acpi_match_ids(struct acpi_device
*device
, char *ids
)
449 if (device
->flags
.hardware_id
)
450 if (strstr(ids
, device
->pnp
.hardware_id
))
453 if (device
->flags
.compatible_ids
) {
454 struct acpi_compatible_id_list
*cid_list
= device
->pnp
.cid_list
;
457 /* compare multiple _CID entries against driver ids */
458 for (i
= 0; i
< cid_list
->count
; i
++) {
459 if (strstr(ids
, cid_list
->id
[i
].value
))
466 static int acpi_bus_get_perf_flags(struct acpi_device
*device
)
468 device
->performance
.state
= ACPI_STATE_UNKNOWN
;
473 acpi_bus_extract_wakeup_device_power_package(struct acpi_device
*device
,
474 union acpi_object
*package
)
477 union acpi_object
*element
= NULL
;
479 if (!device
|| !package
|| (package
->package
.count
< 2))
480 return AE_BAD_PARAMETER
;
482 element
= &(package
->package
.elements
[0]);
484 return AE_BAD_PARAMETER
;
485 if (element
->type
== ACPI_TYPE_PACKAGE
) {
486 if ((element
->package
.count
< 2) ||
487 (element
->package
.elements
[0].type
!=
488 ACPI_TYPE_LOCAL_REFERENCE
)
489 || (element
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
))
491 device
->wakeup
.gpe_device
=
492 element
->package
.elements
[0].reference
.handle
;
493 device
->wakeup
.gpe_number
=
494 (u32
) element
->package
.elements
[1].integer
.value
;
495 } else if (element
->type
== ACPI_TYPE_INTEGER
) {
496 device
->wakeup
.gpe_number
= element
->integer
.value
;
500 element
= &(package
->package
.elements
[1]);
501 if (element
->type
!= ACPI_TYPE_INTEGER
) {
504 device
->wakeup
.sleep_state
= element
->integer
.value
;
506 if ((package
->package
.count
- 2) > ACPI_MAX_HANDLES
) {
509 device
->wakeup
.resources
.count
= package
->package
.count
- 2;
510 for (i
= 0; i
< device
->wakeup
.resources
.count
; i
++) {
511 element
= &(package
->package
.elements
[i
+ 2]);
512 if (element
->type
!= ACPI_TYPE_ANY
) {
516 device
->wakeup
.resources
.handles
[i
] = element
->reference
.handle
;
522 static int acpi_bus_get_wakeup_device_flags(struct acpi_device
*device
)
524 acpi_status status
= 0;
525 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
526 union acpi_object
*package
= NULL
;
530 status
= acpi_evaluate_object(device
->handle
, "_PRW", NULL
, &buffer
);
531 if (ACPI_FAILURE(status
)) {
532 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _PRW"));
536 package
= (union acpi_object
*)buffer
.pointer
;
537 status
= acpi_bus_extract_wakeup_device_power_package(device
, package
);
538 if (ACPI_FAILURE(status
)) {
539 ACPI_EXCEPTION((AE_INFO
, status
, "Extracting _PRW package"));
543 kfree(buffer
.pointer
);
545 device
->wakeup
.flags
.valid
= 1;
546 /* Power button, Lid switch always enable wakeup */
547 if (!acpi_match_ids(device
, "PNP0C0D,PNP0C0C,PNP0C0E"))
548 device
->wakeup
.flags
.run_wake
= 1;
551 if (ACPI_FAILURE(status
))
552 device
->flags
.wake_capable
= 0;
556 static int acpi_bus_get_power_flags(struct acpi_device
*device
)
558 acpi_status status
= 0;
559 acpi_handle handle
= NULL
;
564 * Power Management Flags
566 status
= acpi_get_handle(device
->handle
, "_PSC", &handle
);
567 if (ACPI_SUCCESS(status
))
568 device
->power
.flags
.explicit_get
= 1;
569 status
= acpi_get_handle(device
->handle
, "_IRC", &handle
);
570 if (ACPI_SUCCESS(status
))
571 device
->power
.flags
.inrush_current
= 1;
574 * Enumerate supported power management states
576 for (i
= ACPI_STATE_D0
; i
<= ACPI_STATE_D3
; i
++) {
577 struct acpi_device_power_state
*ps
= &device
->power
.states
[i
];
578 char object_name
[5] = { '_', 'P', 'R', '0' + i
, '\0' };
580 /* Evaluate "_PRx" to se if power resources are referenced */
581 acpi_evaluate_reference(device
->handle
, object_name
, NULL
,
583 if (ps
->resources
.count
) {
584 device
->power
.flags
.power_resources
= 1;
588 /* Evaluate "_PSx" to see if we can do explicit sets */
589 object_name
[2] = 'S';
590 status
= acpi_get_handle(device
->handle
, object_name
, &handle
);
591 if (ACPI_SUCCESS(status
)) {
592 ps
->flags
.explicit_set
= 1;
596 /* State is valid if we have some power control */
597 if (ps
->resources
.count
|| ps
->flags
.explicit_set
)
600 ps
->power
= -1; /* Unknown - driver assigned */
601 ps
->latency
= -1; /* Unknown - driver assigned */
604 /* Set defaults for D0 and D3 states (always valid) */
605 device
->power
.states
[ACPI_STATE_D0
].flags
.valid
= 1;
606 device
->power
.states
[ACPI_STATE_D0
].power
= 100;
607 device
->power
.states
[ACPI_STATE_D3
].flags
.valid
= 1;
608 device
->power
.states
[ACPI_STATE_D3
].power
= 0;
610 /* TBD: System wake support and resource requirements. */
612 device
->power
.state
= ACPI_STATE_UNKNOWN
;
617 static int acpi_bus_get_flags(struct acpi_device
*device
)
619 acpi_status status
= AE_OK
;
620 acpi_handle temp
= NULL
;
623 /* Presence of _STA indicates 'dynamic_status' */
624 status
= acpi_get_handle(device
->handle
, "_STA", &temp
);
625 if (ACPI_SUCCESS(status
))
626 device
->flags
.dynamic_status
= 1;
628 /* Presence of _CID indicates 'compatible_ids' */
629 status
= acpi_get_handle(device
->handle
, "_CID", &temp
);
630 if (ACPI_SUCCESS(status
))
631 device
->flags
.compatible_ids
= 1;
633 /* Presence of _RMV indicates 'removable' */
634 status
= acpi_get_handle(device
->handle
, "_RMV", &temp
);
635 if (ACPI_SUCCESS(status
))
636 device
->flags
.removable
= 1;
638 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
639 status
= acpi_get_handle(device
->handle
, "_EJD", &temp
);
640 if (ACPI_SUCCESS(status
))
641 device
->flags
.ejectable
= 1;
643 status
= acpi_get_handle(device
->handle
, "_EJ0", &temp
);
644 if (ACPI_SUCCESS(status
))
645 device
->flags
.ejectable
= 1;
648 /* Presence of _LCK indicates 'lockable' */
649 status
= acpi_get_handle(device
->handle
, "_LCK", &temp
);
650 if (ACPI_SUCCESS(status
))
651 device
->flags
.lockable
= 1;
653 /* Presence of _PS0|_PR0 indicates 'power manageable' */
654 status
= acpi_get_handle(device
->handle
, "_PS0", &temp
);
655 if (ACPI_FAILURE(status
))
656 status
= acpi_get_handle(device
->handle
, "_PR0", &temp
);
657 if (ACPI_SUCCESS(status
))
658 device
->flags
.power_manageable
= 1;
660 /* Presence of _PRW indicates wake capable */
661 status
= acpi_get_handle(device
->handle
, "_PRW", &temp
);
662 if (ACPI_SUCCESS(status
))
663 device
->flags
.wake_capable
= 1;
665 /* TBD: Peformance management */
670 static void acpi_device_get_busid(struct acpi_device
*device
,
671 acpi_handle handle
, int type
)
673 char bus_id
[5] = { '?', 0 };
674 struct acpi_buffer buffer
= { sizeof(bus_id
), bus_id
};
680 * The device's Bus ID is simply the object name.
681 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
684 case ACPI_BUS_TYPE_SYSTEM
:
685 strcpy(device
->pnp
.bus_id
, "ACPI");
687 case ACPI_BUS_TYPE_POWER_BUTTON
:
688 strcpy(device
->pnp
.bus_id
, "PWRF");
690 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
691 strcpy(device
->pnp
.bus_id
, "SLPF");
694 acpi_get_name(handle
, ACPI_SINGLE_NAME
, &buffer
);
695 /* Clean up trailing underscores (if any) */
696 for (i
= 3; i
> 1; i
--) {
697 if (bus_id
[i
] == '_')
702 strcpy(device
->pnp
.bus_id
, bus_id
);
708 acpi_video_bus_match(struct acpi_device
*device
)
710 acpi_handle h_dummy1
;
711 acpi_handle h_dummy2
;
712 acpi_handle h_dummy3
;
718 /* Since there is no HID, CID for ACPI Video drivers, we have
719 * to check well known required nodes for each feature we support.
722 /* Does this device able to support video switching ? */
723 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOD", &h_dummy1
)) &&
724 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_DOS", &h_dummy2
)))
727 /* Does this device able to retrieve a video ROM ? */
728 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_ROM", &h_dummy1
)))
731 /* Does this device able to configure which video head to be POSTed ? */
732 if (ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_VPO", &h_dummy1
)) &&
733 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_GPD", &h_dummy2
)) &&
734 ACPI_SUCCESS(acpi_get_handle(device
->handle
, "_SPD", &h_dummy3
)))
740 static int acpi_pci_bridge_match(struct acpi_device
*device
)
745 /* pci bridge has _PRT but isn't PNP0A03 */
746 status
= acpi_get_handle(device
->handle
, METHOD_NAME__PRT
, &handle
);
747 if (ACPI_FAILURE(status
))
749 if (!acpi_match_ids(device
, "PNP0A03"))
754 static void acpi_device_set_id(struct acpi_device
*device
,
755 struct acpi_device
*parent
, acpi_handle handle
,
758 struct acpi_device_info
*info
;
759 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
762 struct acpi_compatible_id_list
*cid_list
= NULL
;
766 case ACPI_BUS_TYPE_DEVICE
:
767 status
= acpi_get_object_info(handle
, &buffer
);
768 if (ACPI_FAILURE(status
)) {
769 printk("%s: Error reading device info\n", __FUNCTION__
);
773 info
= buffer
.pointer
;
774 if (info
->valid
& ACPI_VALID_HID
)
775 hid
= info
->hardware_id
.value
;
776 if (info
->valid
& ACPI_VALID_UID
)
777 uid
= info
->unique_id
.value
;
778 if (info
->valid
& ACPI_VALID_CID
)
779 cid_list
= &info
->compatibility_id
;
780 if (info
->valid
& ACPI_VALID_ADR
) {
781 device
->pnp
.bus_address
= info
->address
;
782 device
->flags
.bus_address
= 1;
785 if(!(info
->valid
& (ACPI_VALID_HID
| ACPI_VALID_CID
))){
786 status
= acpi_video_bus_match(device
);
787 if(ACPI_SUCCESS(status
))
788 hid
= ACPI_VIDEO_HID
;
790 status
= acpi_pci_bridge_match(device
);
791 if(ACPI_SUCCESS(status
))
792 hid
= ACPI_PCI_BRIDGE_HID
;
795 case ACPI_BUS_TYPE_POWER
:
796 hid
= ACPI_POWER_HID
;
798 case ACPI_BUS_TYPE_PROCESSOR
:
799 hid
= ACPI_PROCESSOR_HID
;
801 case ACPI_BUS_TYPE_SYSTEM
:
802 hid
= ACPI_SYSTEM_HID
;
804 case ACPI_BUS_TYPE_THERMAL
:
805 hid
= ACPI_THERMAL_HID
;
807 case ACPI_BUS_TYPE_POWER_BUTTON
:
808 hid
= ACPI_BUTTON_HID_POWERF
;
810 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
811 hid
= ACPI_BUTTON_HID_SLEEPF
;
818 * Fix for the system root bus device -- the only root-level device.
820 if (((acpi_handle
)parent
== ACPI_ROOT_OBJECT
) && (type
== ACPI_BUS_TYPE_DEVICE
)) {
822 strcpy(device
->pnp
.device_name
, ACPI_BUS_DEVICE_NAME
);
823 strcpy(device
->pnp
.device_class
, ACPI_BUS_CLASS
);
827 strcpy(device
->pnp
.hardware_id
, hid
);
828 device
->flags
.hardware_id
= 1;
831 strcpy(device
->pnp
.unique_id
, uid
);
832 device
->flags
.unique_id
= 1;
835 device
->pnp
.cid_list
= kmalloc(cid_list
->size
, GFP_KERNEL
);
836 if (device
->pnp
.cid_list
)
837 memcpy(device
->pnp
.cid_list
, cid_list
, cid_list
->size
);
839 printk(KERN_ERR
"Memory allocation error\n");
842 kfree(buffer
.pointer
);
845 static int acpi_device_set_context(struct acpi_device
*device
, int type
)
847 acpi_status status
= AE_OK
;
852 * Attach this 'struct acpi_device' to the ACPI object. This makes
853 * resolutions from handle->device very efficient. Note that we need
854 * to be careful with fixed-feature devices as they all attach to the
857 if (type
!= ACPI_BUS_TYPE_POWER_BUTTON
&&
858 type
!= ACPI_BUS_TYPE_SLEEP_BUTTON
) {
859 status
= acpi_attach_data(device
->handle
,
860 acpi_bus_data_handler
, device
);
862 if (ACPI_FAILURE(status
)) {
863 printk("Error attaching device data\n");
870 static void acpi_device_get_debug_info(struct acpi_device
*device
,
871 acpi_handle handle
, int type
)
873 #ifdef CONFIG_ACPI_DEBUG_OUTPUT
874 char *type_string
= NULL
;
875 char name
[80] = { '?', '\0' };
876 struct acpi_buffer buffer
= { sizeof(name
), name
};
879 case ACPI_BUS_TYPE_DEVICE
:
880 type_string
= "Device";
881 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
883 case ACPI_BUS_TYPE_POWER
:
884 type_string
= "Power Resource";
885 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
887 case ACPI_BUS_TYPE_PROCESSOR
:
888 type_string
= "Processor";
889 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
891 case ACPI_BUS_TYPE_SYSTEM
:
892 type_string
= "System";
893 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
895 case ACPI_BUS_TYPE_THERMAL
:
896 type_string
= "Thermal Zone";
897 acpi_get_name(handle
, ACPI_FULL_PATHNAME
, &buffer
);
899 case ACPI_BUS_TYPE_POWER_BUTTON
:
900 type_string
= "Power Button";
901 sprintf(name
, "PWRB");
903 case ACPI_BUS_TYPE_SLEEP_BUTTON
:
904 type_string
= "Sleep Button";
905 sprintf(name
, "SLPB");
909 printk(KERN_DEBUG
"Found %s %s [%p]\n", type_string
, name
, handle
);
910 #endif /*CONFIG_ACPI_DEBUG_OUTPUT */
913 static int acpi_bus_remove(struct acpi_device
*dev
, int rmdevice
)
918 dev
->removal_type
= ACPI_BUS_REMOVAL_EJECT
;
919 device_release_driver(&dev
->dev
);
924 acpi_device_unregister(dev
, ACPI_BUS_REMOVAL_EJECT
);
930 acpi_add_single_object(struct acpi_device
**child
,
931 struct acpi_device
*parent
, acpi_handle handle
, int type
,
932 struct acpi_bus_ops
*ops
)
935 struct acpi_device
*device
= NULL
;
941 device
= kmalloc(sizeof(struct acpi_device
), GFP_KERNEL
);
943 printk(KERN_ERR PREFIX
"Memory allocation error\n");
946 memset(device
, 0, sizeof(struct acpi_device
));
948 device
->handle
= handle
;
949 device
->parent
= parent
;
950 device
->bus_ops
= *ops
; /* workround for not call .start */
953 acpi_device_get_busid(device
, handle
, type
);
958 * Get prior to calling acpi_bus_get_status() so we know whether
959 * or not _STA is present. Note that we only look for object
960 * handles -- cannot evaluate objects until we know the device is
961 * present and properly initialized.
963 result
= acpi_bus_get_flags(device
);
970 * See if the device is present. We always assume that non-Device
971 * and non-Processor objects (e.g. thermal zones, power resources,
972 * etc.) are present, functioning, etc. (at least when parent object
973 * is present). Note that _STA has a different meaning for some
974 * objects (e.g. power resources) so we need to be careful how we use
978 case ACPI_BUS_TYPE_PROCESSOR
:
979 case ACPI_BUS_TYPE_DEVICE
:
980 result
= acpi_bus_get_status(device
);
981 if (ACPI_FAILURE(result
) || !device
->status
.present
) {
987 STRUCT_TO_INT(device
->status
) = 0x0F;
994 * TBD: Synch with Core's enumeration/initialization process.
998 * Hardware ID, Unique ID, & Bus Address
999 * -------------------------------------
1001 acpi_device_set_id(device
, parent
, handle
, type
);
1007 if (device
->flags
.power_manageable
) {
1008 result
= acpi_bus_get_power_flags(device
);
1014 * Wakeup device management
1015 *-----------------------
1017 if (device
->flags
.wake_capable
) {
1018 result
= acpi_bus_get_wakeup_device_flags(device
);
1024 * Performance Management
1025 * ----------------------
1027 if (device
->flags
.performance_manageable
) {
1028 result
= acpi_bus_get_perf_flags(device
);
1033 if ((result
= acpi_device_set_context(device
, type
)))
1036 acpi_device_get_debug_info(device
, handle
, type
);
1038 acpi_device_register(device
, parent
);
1044 kfree(device
->pnp
.cid_list
);
1051 static int acpi_bus_scan(struct acpi_device
*start
, struct acpi_bus_ops
*ops
)
1053 acpi_status status
= AE_OK
;
1054 struct acpi_device
*parent
= NULL
;
1055 struct acpi_device
*child
= NULL
;
1056 acpi_handle phandle
= NULL
;
1057 acpi_handle chandle
= NULL
;
1058 acpi_object_type type
= 0;
1066 phandle
= start
->handle
;
1069 * Parse through the ACPI namespace, identify all 'devices', and
1070 * create a new 'struct acpi_device' for each.
1072 while ((level
> 0) && parent
) {
1074 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
1078 * If this scope is exhausted then move our way back up.
1080 if (ACPI_FAILURE(status
)) {
1083 acpi_get_parent(phandle
, &phandle
);
1085 parent
= parent
->parent
;
1089 status
= acpi_get_type(chandle
, &type
);
1090 if (ACPI_FAILURE(status
))
1094 * If this is a scope object then parse it (depth-first).
1096 if (type
== ACPI_TYPE_LOCAL_SCOPE
) {
1104 * We're only interested in objects that we consider 'devices'.
1107 case ACPI_TYPE_DEVICE
:
1108 type
= ACPI_BUS_TYPE_DEVICE
;
1110 case ACPI_TYPE_PROCESSOR
:
1111 type
= ACPI_BUS_TYPE_PROCESSOR
;
1113 case ACPI_TYPE_THERMAL
:
1114 type
= ACPI_BUS_TYPE_THERMAL
;
1116 case ACPI_TYPE_POWER
:
1117 type
= ACPI_BUS_TYPE_POWER
;
1123 if (ops
->acpi_op_add
)
1124 status
= acpi_add_single_object(&child
, parent
,
1125 chandle
, type
, ops
);
1127 status
= acpi_bus_get_device(chandle
, &child
);
1129 if (ACPI_FAILURE(status
))
1132 if (ops
->acpi_op_start
&& !(ops
->acpi_op_add
)) {
1133 status
= acpi_start_single_object(child
);
1134 if (ACPI_FAILURE(status
))
1139 * If the device is present, enabled, and functioning then
1140 * parse its scope (depth-first). Note that we need to
1141 * represent absent devices to facilitate PnP notifications
1142 * -- but only the subtree head (not all of its children,
1143 * which will be enumerated when the parent is inserted).
1145 * TBD: Need notifications and other detection mechanisms
1146 * in place before we can fully implement this.
1148 if (child
->status
.present
) {
1149 status
= acpi_get_next_object(ACPI_TYPE_ANY
, chandle
,
1151 if (ACPI_SUCCESS(status
)) {
1164 acpi_bus_add(struct acpi_device
**child
,
1165 struct acpi_device
*parent
, acpi_handle handle
, int type
)
1168 struct acpi_bus_ops ops
;
1170 memset(&ops
, 0, sizeof(ops
));
1171 ops
.acpi_op_add
= 1;
1173 result
= acpi_add_single_object(child
, parent
, handle
, type
, &ops
);
1175 result
= acpi_bus_scan(*child
, &ops
);
1180 EXPORT_SYMBOL(acpi_bus_add
);
1182 int acpi_bus_start(struct acpi_device
*device
)
1185 struct acpi_bus_ops ops
;
1191 result
= acpi_start_single_object(device
);
1193 memset(&ops
, 0, sizeof(ops
));
1194 ops
.acpi_op_start
= 1;
1195 result
= acpi_bus_scan(device
, &ops
);
1200 EXPORT_SYMBOL(acpi_bus_start
);
1202 int acpi_bus_trim(struct acpi_device
*start
, int rmdevice
)
1205 struct acpi_device
*parent
, *child
;
1206 acpi_handle phandle
, chandle
;
1207 acpi_object_type type
;
1212 phandle
= start
->handle
;
1213 child
= chandle
= NULL
;
1215 while ((level
> 0) && parent
&& (!err
)) {
1216 status
= acpi_get_next_object(ACPI_TYPE_ANY
, phandle
,
1220 * If this scope is exhausted then move our way back up.
1222 if (ACPI_FAILURE(status
)) {
1225 acpi_get_parent(phandle
, &phandle
);
1227 parent
= parent
->parent
;
1230 err
= acpi_bus_remove(child
, rmdevice
);
1232 err
= acpi_bus_remove(child
, 1);
1237 status
= acpi_get_type(chandle
, &type
);
1238 if (ACPI_FAILURE(status
)) {
1242 * If there is a device corresponding to chandle then
1243 * parse it (depth-first).
1245 if (acpi_bus_get_device(chandle
, &child
) == 0) {
1255 EXPORT_SYMBOL_GPL(acpi_bus_trim
);
1258 static int acpi_bus_scan_fixed(struct acpi_device
*root
)
1261 struct acpi_device
*device
= NULL
;
1262 struct acpi_bus_ops ops
;
1267 memset(&ops
, 0, sizeof(ops
));
1268 ops
.acpi_op_add
= 1;
1269 ops
.acpi_op_start
= 1;
1272 * Enumerate all fixed-feature devices.
1274 if (acpi_fadt
.pwr_button
== 0) {
1275 result
= acpi_add_single_object(&device
, acpi_root
,
1277 ACPI_BUS_TYPE_POWER_BUTTON
,
1281 if (acpi_fadt
.sleep_button
== 0) {
1282 result
= acpi_add_single_object(&device
, acpi_root
,
1284 ACPI_BUS_TYPE_SLEEP_BUTTON
,
1291 static int __init
acpi_scan_init(void)
1294 struct acpi_bus_ops ops
;
1300 memset(&ops
, 0, sizeof(ops
));
1301 ops
.acpi_op_add
= 1;
1302 ops
.acpi_op_start
= 1;
1304 result
= bus_register(&acpi_bus_type
);
1306 /* We don't want to quit even if we failed to add suspend/resume */
1307 printk(KERN_ERR PREFIX
"Could not register bus type\n");
1311 * Create the root device in the bus's device tree
1313 result
= acpi_add_single_object(&acpi_root
, NULL
, ACPI_ROOT_OBJECT
,
1314 ACPI_BUS_TYPE_SYSTEM
, &ops
);
1319 * Enumerate devices in the ACPI namespace.
1321 result
= acpi_bus_scan_fixed(acpi_root
);
1323 result
= acpi_bus_scan(acpi_root
, &ops
);
1326 acpi_device_unregister(acpi_root
, ACPI_BUS_REMOVAL_NORMAL
);
1332 subsys_initcall(acpi_scan_init
);