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 int create_modalias(struct acpi_device *acpi_dev, char *modalias, int size){
42 if (!acpi_dev->flags.hardware_id)
45 len = snprintf(modalias, size, "acpi:%s:",
46 acpi_dev->pnp.hardware_id);
47 if (len < 0 || len >= size)
51 if (acpi_dev->flags.compatible_ids) {
52 struct acpi_compatible_id_list *cid_list;
56 cid_list = acpi_dev->pnp.cid_list;
57 for (i = 0; i < cid_list->count; i++) {
58 count = snprintf(&modalias[len], size, "%s:",
59 cid_list->id[i].value);
60 if (count < 0 || count >= size) {
61 printk(KERN_ERR "acpi: %s cid[%i] exceeds event buffer size",
62 acpi_dev->pnp.device_name, i);
75 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
76 struct acpi_device *acpi_dev = to_acpi_device(dev);
79 /* Device has no HID and no CID or string is >1024 */
80 len = create_modalias(acpi_dev, buf, 1024);
86 static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
88 static int acpi_eject_operation(acpi_handle handle, int lockable)
90 struct acpi_object_list arg_list;
91 union acpi_object arg;
92 acpi_status status = AE_OK;
100 arg_list.pointer = &arg;
101 arg.type = ACPI_TYPE_INTEGER;
102 arg.integer.value = 0;
103 acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
107 arg_list.pointer = &arg;
108 arg.type = ACPI_TYPE_INTEGER;
109 arg.integer.value = 1;
115 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
116 if (ACPI_FAILURE(status)) {
124 acpi_eject_store(struct device *d, struct device_attribute *attr,
125 const char *buf, size_t count)
132 acpi_object_type type = 0;
133 struct acpi_device *acpi_device = to_acpi_device(d);
135 if ((!count) || (buf[0] != '1')) {
139 if (acpi_device->driver == NULL) {
144 status = acpi_get_type(acpi_device->handle, &type);
145 if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
150 islockable = acpi_device->flags.lockable;
151 handle = acpi_device->handle;
153 result = acpi_bus_trim(acpi_device, 1);
156 result = acpi_eject_operation(handle, islockable);
165 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
168 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
169 struct acpi_device *acpi_dev = to_acpi_device(dev);
171 return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id);
173 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
176 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
177 struct acpi_device *acpi_dev = to_acpi_device(dev);
178 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
181 result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
185 result = sprintf(buf, "%s\n", (char*)path.pointer);
190 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
192 static int acpi_device_setup_files(struct acpi_device *dev)
199 * Devices gotten from FADT don't have a "path" attribute
202 result = device_create_file(&dev->dev, &dev_attr_path);
207 if(dev->flags.hardware_id) {
208 result = device_create_file(&dev->dev, &dev_attr_hid);
213 if (dev->flags.hardware_id || dev->flags.compatible_ids){
214 result = device_create_file(&dev->dev, &dev_attr_modalias);
220 * If device has _EJ0, 'eject' file is created that is used to trigger
221 * hot-removal function from userland.
223 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
224 if (ACPI_SUCCESS(status))
225 result = device_create_file(&dev->dev, &dev_attr_eject);
230 static void acpi_device_remove_files(struct acpi_device *dev)
236 * If device has _EJ0, 'eject' file is created that is used to trigger
237 * hot-removal function from userland.
239 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
240 if (ACPI_SUCCESS(status))
241 device_remove_file(&dev->dev, &dev_attr_eject);
243 if (dev->flags.hardware_id || dev->flags.compatible_ids)
244 device_remove_file(&dev->dev, &dev_attr_modalias);
246 if(dev->flags.hardware_id)
247 device_remove_file(&dev->dev, &dev_attr_hid);
249 device_remove_file(&dev->dev, &dev_attr_path);
251 /* --------------------------------------------------------------------------
253 -------------------------------------------------------------------------- */
255 int acpi_match_device_ids(struct acpi_device *device,
256 const struct acpi_device_id *ids)
258 const struct acpi_device_id *id;
260 if (device->flags.hardware_id) {
261 for (id = ids; id->id[0]; id++) {
262 if (!strcmp((char*)id->id, device->pnp.hardware_id))
267 if (device->flags.compatible_ids) {
268 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
271 for (id = ids; id->id[0]; id++) {
272 /* compare multiple _CID entries against driver ids */
273 for (i = 0; i < cid_list->count; i++) {
274 if (!strcmp((char*)id->id,
275 cid_list->id[i].value))
283 EXPORT_SYMBOL(acpi_match_device_ids);
285 static void acpi_device_release(struct device *dev)
287 struct acpi_device *acpi_dev = to_acpi_device(dev);
289 kfree(acpi_dev->pnp.cid_list);
293 static int acpi_device_suspend(struct device *dev, pm_message_t state)
295 struct acpi_device *acpi_dev = to_acpi_device(dev);
296 struct acpi_driver *acpi_drv = acpi_dev->driver;
298 if (acpi_drv && acpi_drv->ops.suspend)
299 return acpi_drv->ops.suspend(acpi_dev, state);
303 static int acpi_device_resume(struct device *dev)
305 struct acpi_device *acpi_dev = to_acpi_device(dev);
306 struct acpi_driver *acpi_drv = acpi_dev->driver;
308 if (acpi_drv && acpi_drv->ops.resume)
309 return acpi_drv->ops.resume(acpi_dev);
313 static int acpi_bus_match(struct device *dev, struct device_driver *drv)
315 struct acpi_device *acpi_dev = to_acpi_device(dev);
316 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
318 return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
321 static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
322 char *buffer, int buffer_size)
324 struct acpi_device *acpi_dev = to_acpi_device(dev);
326 strcpy(buffer, "MODALIAS=");
327 if (create_modalias(acpi_dev, buffer + 9, buffer_size - 9) > 0) {
334 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
335 static int acpi_start_single_object(struct acpi_device *);
336 static int acpi_device_probe(struct device * dev)
338 struct acpi_device *acpi_dev = to_acpi_device(dev);
339 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
342 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
344 if (acpi_dev->bus_ops.acpi_op_start)
345 acpi_start_single_object(acpi_dev);
346 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
347 "Found driver [%s] for device [%s]\n",
348 acpi_drv->name, acpi_dev->pnp.bus_id));
354 static int acpi_device_remove(struct device * dev)
356 struct acpi_device *acpi_dev = to_acpi_device(dev);
357 struct acpi_driver *acpi_drv = acpi_dev->driver;
360 if (acpi_drv->ops.stop)
361 acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
362 if (acpi_drv->ops.remove)
363 acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
365 acpi_dev->driver = NULL;
366 acpi_driver_data(dev) = NULL;
372 static void acpi_device_shutdown(struct device *dev)
374 struct acpi_device *acpi_dev = to_acpi_device(dev);
375 struct acpi_driver *acpi_drv = acpi_dev->driver;
377 if (acpi_drv && acpi_drv->ops.shutdown)
378 acpi_drv->ops.shutdown(acpi_dev);
383 struct bus_type acpi_bus_type = {
385 .suspend = acpi_device_suspend,
386 .resume = acpi_device_resume,
387 .shutdown = acpi_device_shutdown,
388 .match = acpi_bus_match,
389 .probe = acpi_device_probe,
390 .remove = acpi_device_remove,
391 .uevent = acpi_device_uevent,
394 static int acpi_device_register(struct acpi_device *device,
395 struct acpi_device *parent)
398 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
403 * Link this device to its parent and siblings.
405 INIT_LIST_HEAD(&device->children);
406 INIT_LIST_HEAD(&device->node);
407 INIT_LIST_HEAD(&device->g_list);
408 INIT_LIST_HEAD(&device->wakeup_list);
410 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
412 printk(KERN_ERR PREFIX "Memory allocation error\n");
416 spin_lock(&acpi_device_lock);
418 * Find suitable bus_id and instance number in acpi_bus_id_list
419 * If failed, create one and link it into acpi_bus_id_list
421 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
422 if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) {
423 acpi_device_bus_id->instance_no ++;
430 acpi_device_bus_id = new_bus_id;
431 strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device");
432 acpi_device_bus_id->instance_no = 0;
433 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
435 sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
437 if (device->parent) {
438 list_add_tail(&device->node, &device->parent->children);
439 list_add_tail(&device->g_list, &device->parent->g_list);
441 list_add_tail(&device->g_list, &acpi_device_list);
442 if (device->wakeup.flags.valid)
443 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
444 spin_unlock(&acpi_device_lock);
447 device->dev.parent = &parent->dev;
448 device->dev.bus = &acpi_bus_type;
449 device_initialize(&device->dev);
450 device->dev.release = &acpi_device_release;
451 result = device_add(&device->dev);
453 printk("Error adding device %s", device->dev.bus_id);
457 result = acpi_device_setup_files(device);
459 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
461 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
464 spin_lock(&acpi_device_lock);
465 if (device->parent) {
466 list_del(&device->node);
467 list_del(&device->g_list);
469 list_del(&device->g_list);
470 list_del(&device->wakeup_list);
471 spin_unlock(&acpi_device_lock);
475 static void acpi_device_unregister(struct acpi_device *device, int type)
477 spin_lock(&acpi_device_lock);
478 if (device->parent) {
479 list_del(&device->node);
480 list_del(&device->g_list);
482 list_del(&device->g_list);
484 list_del(&device->wakeup_list);
485 spin_unlock(&acpi_device_lock);
487 acpi_detach_data(device->handle, acpi_bus_data_handler);
489 acpi_device_remove_files(device);
490 device_unregister(&device->dev);
493 /* --------------------------------------------------------------------------
495 -------------------------------------------------------------------------- */
497 * acpi_bus_driver_init - add a device to a driver
498 * @device: the device to add and initialize
499 * @driver: driver for the device
501 * Used to initialize a device via its device driver. Called whenever a
502 * driver is bound to a device. Invokes the driver's add() ops.
505 acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
510 if (!device || !driver)
513 if (!driver->ops.add)
516 result = driver->ops.add(device);
518 device->driver = NULL;
519 acpi_driver_data(device) = NULL;
523 device->driver = driver;
526 * TBD - Configuration Management: Assign resources to device based
527 * upon possible configuration and currently allocated resources.
530 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
531 "Driver successfully bound to device\n"));
535 static int acpi_start_single_object(struct acpi_device *device)
538 struct acpi_driver *driver;
541 if (!(driver = device->driver))
544 if (driver->ops.start) {
545 result = driver->ops.start(device);
546 if (result && driver->ops.remove)
547 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
554 * acpi_bus_register_driver - register a driver with the ACPI bus
555 * @driver: driver being registered
557 * Registers a driver with the ACPI bus. Searches the namespace for all
558 * devices that match the driver's criteria and binds. Returns zero for
559 * success or a negative error status for failure.
561 int acpi_bus_register_driver(struct acpi_driver *driver)
567 driver->drv.name = driver->name;
568 driver->drv.bus = &acpi_bus_type;
569 driver->drv.owner = driver->owner;
571 ret = driver_register(&driver->drv);
575 EXPORT_SYMBOL(acpi_bus_register_driver);
578 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
579 * @driver: driver to unregister
581 * Unregisters a driver with the ACPI bus. Searches the namespace for all
582 * devices that match the driver's criteria and unbinds.
584 void acpi_bus_unregister_driver(struct acpi_driver *driver)
586 driver_unregister(&driver->drv);
589 EXPORT_SYMBOL(acpi_bus_unregister_driver);
591 /* --------------------------------------------------------------------------
593 -------------------------------------------------------------------------- */
595 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
599 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
600 union acpi_object *obj;
602 status = acpi_get_handle(handle, "_EJD", &tmp);
603 if (ACPI_FAILURE(status))
606 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
607 if (ACPI_SUCCESS(status)) {
608 obj = buffer.pointer;
609 status = acpi_get_handle(NULL, obj->string.pointer, ejd);
610 kfree(buffer.pointer);
614 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
616 void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
624 static int acpi_bus_get_perf_flags(struct acpi_device *device)
626 device->performance.state = ACPI_STATE_UNKNOWN;
631 acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
632 union acpi_object *package)
635 union acpi_object *element = NULL;
637 if (!device || !package || (package->package.count < 2))
638 return AE_BAD_PARAMETER;
640 element = &(package->package.elements[0]);
642 return AE_BAD_PARAMETER;
643 if (element->type == ACPI_TYPE_PACKAGE) {
644 if ((element->package.count < 2) ||
645 (element->package.elements[0].type !=
646 ACPI_TYPE_LOCAL_REFERENCE)
647 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
649 device->wakeup.gpe_device =
650 element->package.elements[0].reference.handle;
651 device->wakeup.gpe_number =
652 (u32) element->package.elements[1].integer.value;
653 } else if (element->type == ACPI_TYPE_INTEGER) {
654 device->wakeup.gpe_number = element->integer.value;
658 element = &(package->package.elements[1]);
659 if (element->type != ACPI_TYPE_INTEGER) {
662 device->wakeup.sleep_state = element->integer.value;
664 if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
667 device->wakeup.resources.count = package->package.count - 2;
668 for (i = 0; i < device->wakeup.resources.count; i++) {
669 element = &(package->package.elements[i + 2]);
670 if (element->type != ACPI_TYPE_ANY) {
674 device->wakeup.resources.handles[i] = element->reference.handle;
680 static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
682 acpi_status status = 0;
683 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
684 union acpi_object *package = NULL;
686 struct acpi_device_id button_device_ids[] = {
695 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
696 if (ACPI_FAILURE(status)) {
697 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
701 package = (union acpi_object *)buffer.pointer;
702 status = acpi_bus_extract_wakeup_device_power_package(device, package);
703 if (ACPI_FAILURE(status)) {
704 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
708 kfree(buffer.pointer);
710 device->wakeup.flags.valid = 1;
711 /* Power button, Lid switch always enable wakeup */
712 if (!acpi_match_device_ids(device, button_device_ids))
713 device->wakeup.flags.run_wake = 1;
716 if (ACPI_FAILURE(status))
717 device->flags.wake_capable = 0;
721 static int acpi_bus_get_power_flags(struct acpi_device *device)
723 acpi_status status = 0;
724 acpi_handle handle = NULL;
729 * Power Management Flags
731 status = acpi_get_handle(device->handle, "_PSC", &handle);
732 if (ACPI_SUCCESS(status))
733 device->power.flags.explicit_get = 1;
734 status = acpi_get_handle(device->handle, "_IRC", &handle);
735 if (ACPI_SUCCESS(status))
736 device->power.flags.inrush_current = 1;
739 * Enumerate supported power management states
741 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
742 struct acpi_device_power_state *ps = &device->power.states[i];
743 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
745 /* Evaluate "_PRx" to se if power resources are referenced */
746 acpi_evaluate_reference(device->handle, object_name, NULL,
748 if (ps->resources.count) {
749 device->power.flags.power_resources = 1;
753 /* Evaluate "_PSx" to see if we can do explicit sets */
754 object_name[2] = 'S';
755 status = acpi_get_handle(device->handle, object_name, &handle);
756 if (ACPI_SUCCESS(status)) {
757 ps->flags.explicit_set = 1;
761 /* State is valid if we have some power control */
762 if (ps->resources.count || ps->flags.explicit_set)
765 ps->power = -1; /* Unknown - driver assigned */
766 ps->latency = -1; /* Unknown - driver assigned */
769 /* Set defaults for D0 and D3 states (always valid) */
770 device->power.states[ACPI_STATE_D0].flags.valid = 1;
771 device->power.states[ACPI_STATE_D0].power = 100;
772 device->power.states[ACPI_STATE_D3].flags.valid = 1;
773 device->power.states[ACPI_STATE_D3].power = 0;
775 /* TBD: System wake support and resource requirements. */
777 device->power.state = ACPI_STATE_UNKNOWN;
782 static int acpi_bus_get_flags(struct acpi_device *device)
784 acpi_status status = AE_OK;
785 acpi_handle temp = NULL;
788 /* Presence of _STA indicates 'dynamic_status' */
789 status = acpi_get_handle(device->handle, "_STA", &temp);
790 if (ACPI_SUCCESS(status))
791 device->flags.dynamic_status = 1;
793 /* Presence of _CID indicates 'compatible_ids' */
794 status = acpi_get_handle(device->handle, "_CID", &temp);
795 if (ACPI_SUCCESS(status))
796 device->flags.compatible_ids = 1;
798 /* Presence of _RMV indicates 'removable' */
799 status = acpi_get_handle(device->handle, "_RMV", &temp);
800 if (ACPI_SUCCESS(status))
801 device->flags.removable = 1;
803 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
804 status = acpi_get_handle(device->handle, "_EJD", &temp);
805 if (ACPI_SUCCESS(status))
806 device->flags.ejectable = 1;
808 status = acpi_get_handle(device->handle, "_EJ0", &temp);
809 if (ACPI_SUCCESS(status))
810 device->flags.ejectable = 1;
813 /* Presence of _LCK indicates 'lockable' */
814 status = acpi_get_handle(device->handle, "_LCK", &temp);
815 if (ACPI_SUCCESS(status))
816 device->flags.lockable = 1;
818 /* Presence of _PS0|_PR0 indicates 'power manageable' */
819 status = acpi_get_handle(device->handle, "_PS0", &temp);
820 if (ACPI_FAILURE(status))
821 status = acpi_get_handle(device->handle, "_PR0", &temp);
822 if (ACPI_SUCCESS(status))
823 device->flags.power_manageable = 1;
825 /* Presence of _PRW indicates wake capable */
826 status = acpi_get_handle(device->handle, "_PRW", &temp);
827 if (ACPI_SUCCESS(status))
828 device->flags.wake_capable = 1;
830 /* TBD: Peformance management */
835 static void acpi_device_get_busid(struct acpi_device *device,
836 acpi_handle handle, int type)
838 char bus_id[5] = { '?', 0 };
839 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
845 * The device's Bus ID is simply the object name.
846 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
849 case ACPI_BUS_TYPE_SYSTEM:
850 strcpy(device->pnp.bus_id, "ACPI");
852 case ACPI_BUS_TYPE_POWER_BUTTON:
853 strcpy(device->pnp.bus_id, "PWRF");
855 case ACPI_BUS_TYPE_SLEEP_BUTTON:
856 strcpy(device->pnp.bus_id, "SLPF");
859 acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
860 /* Clean up trailing underscores (if any) */
861 for (i = 3; i > 1; i--) {
862 if (bus_id[i] == '_')
867 strcpy(device->pnp.bus_id, bus_id);
873 acpi_video_bus_match(struct acpi_device *device)
875 acpi_handle h_dummy1;
876 acpi_handle h_dummy2;
877 acpi_handle h_dummy3;
883 /* Since there is no HID, CID for ACPI Video drivers, we have
884 * to check well known required nodes for each feature we support.
887 /* Does this device able to support video switching ? */
888 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) &&
889 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
892 /* Does this device able to retrieve a video ROM ? */
893 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
896 /* Does this device able to configure which video head to be POSTed ? */
897 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
898 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
899 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
906 * acpi_bay_match - see if a device is an ejectable driver bay
908 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
909 * then we can safely call it an ejectable drive bay
911 static int acpi_bay_match(struct acpi_device *device){
917 handle = device->handle;
919 status = acpi_get_handle(handle, "_EJ0", &tmp);
920 if (ACPI_FAILURE(status))
923 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
924 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
925 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
926 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
929 if (acpi_get_parent(handle, &phandle))
932 if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
933 (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
934 (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
935 (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
941 static void acpi_device_set_id(struct acpi_device *device,
942 struct acpi_device *parent, acpi_handle handle,
945 struct acpi_device_info *info;
946 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
949 struct acpi_compatible_id_list *cid_list = NULL;
953 case ACPI_BUS_TYPE_DEVICE:
954 status = acpi_get_object_info(handle, &buffer);
955 if (ACPI_FAILURE(status)) {
956 printk("%s: Error reading device info\n", __FUNCTION__);
960 info = buffer.pointer;
961 if (info->valid & ACPI_VALID_HID)
962 hid = info->hardware_id.value;
963 if (info->valid & ACPI_VALID_UID)
964 uid = info->unique_id.value;
965 if (info->valid & ACPI_VALID_CID)
966 cid_list = &info->compatibility_id;
967 if (info->valid & ACPI_VALID_ADR) {
968 device->pnp.bus_address = info->address;
969 device->flags.bus_address = 1;
972 if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){
973 status = acpi_video_bus_match(device);
974 if(ACPI_SUCCESS(status))
975 hid = ACPI_VIDEO_HID;
977 status = acpi_bay_match(device);
978 if (ACPI_SUCCESS(status))
982 case ACPI_BUS_TYPE_POWER:
983 hid = ACPI_POWER_HID;
985 case ACPI_BUS_TYPE_PROCESSOR:
986 hid = ACPI_PROCESSOR_HID;
988 case ACPI_BUS_TYPE_SYSTEM:
989 hid = ACPI_SYSTEM_HID;
991 case ACPI_BUS_TYPE_THERMAL:
992 hid = ACPI_THERMAL_HID;
994 case ACPI_BUS_TYPE_POWER_BUTTON:
995 hid = ACPI_BUTTON_HID_POWERF;
997 case ACPI_BUS_TYPE_SLEEP_BUTTON:
998 hid = ACPI_BUTTON_HID_SLEEPF;
1005 * Fix for the system root bus device -- the only root-level device.
1007 if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
1009 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1010 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1014 strcpy(device->pnp.hardware_id, hid);
1015 device->flags.hardware_id = 1;
1018 strcpy(device->pnp.unique_id, uid);
1019 device->flags.unique_id = 1;
1022 device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
1023 if (device->pnp.cid_list)
1024 memcpy(device->pnp.cid_list, cid_list, cid_list->size);
1026 printk(KERN_ERR "Memory allocation error\n");
1029 kfree(buffer.pointer);
1032 static int acpi_device_set_context(struct acpi_device *device, int type)
1034 acpi_status status = AE_OK;
1039 * Attach this 'struct acpi_device' to the ACPI object. This makes
1040 * resolutions from handle->device very efficient. Note that we need
1041 * to be careful with fixed-feature devices as they all attach to the
1044 if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
1045 type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
1046 status = acpi_attach_data(device->handle,
1047 acpi_bus_data_handler, device);
1049 if (ACPI_FAILURE(status)) {
1050 printk("Error attaching device data\n");
1057 static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
1062 dev->removal_type = ACPI_BUS_REMOVAL_EJECT;
1063 device_release_driver(&dev->dev);
1069 * unbind _ADR-Based Devices when hot removal
1071 if (dev->flags.bus_address) {
1072 if ((dev->parent) && (dev->parent->ops.unbind))
1073 dev->parent->ops.unbind(dev);
1075 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
1081 acpi_add_single_object(struct acpi_device **child,
1082 struct acpi_device *parent, acpi_handle handle, int type,
1083 struct acpi_bus_ops *ops)
1086 struct acpi_device *device = NULL;
1092 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1094 printk(KERN_ERR PREFIX "Memory allocation error\n");
1098 device->handle = handle;
1099 device->parent = parent;
1100 device->bus_ops = *ops; /* workround for not call .start */
1103 acpi_device_get_busid(device, handle, type);
1108 * Get prior to calling acpi_bus_get_status() so we know whether
1109 * or not _STA is present. Note that we only look for object
1110 * handles -- cannot evaluate objects until we know the device is
1111 * present and properly initialized.
1113 result = acpi_bus_get_flags(device);
1120 * See if the device is present. We always assume that non-Device
1121 * and non-Processor objects (e.g. thermal zones, power resources,
1122 * etc.) are present, functioning, etc. (at least when parent object
1123 * is present). Note that _STA has a different meaning for some
1124 * objects (e.g. power resources) so we need to be careful how we use
1128 case ACPI_BUS_TYPE_PROCESSOR:
1129 case ACPI_BUS_TYPE_DEVICE:
1130 result = acpi_bus_get_status(device);
1131 if (ACPI_FAILURE(result) || !device->status.present) {
1137 STRUCT_TO_INT(device->status) =
1138 ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
1139 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
1146 * TBD: Synch with Core's enumeration/initialization process.
1150 * Hardware ID, Unique ID, & Bus Address
1151 * -------------------------------------
1153 acpi_device_set_id(device, parent, handle, type);
1159 if (device->flags.power_manageable) {
1160 result = acpi_bus_get_power_flags(device);
1166 * Wakeup device management
1167 *-----------------------
1169 if (device->flags.wake_capable) {
1170 result = acpi_bus_get_wakeup_device_flags(device);
1176 * Performance Management
1177 * ----------------------
1179 if (device->flags.performance_manageable) {
1180 result = acpi_bus_get_perf_flags(device);
1185 if ((result = acpi_device_set_context(device, type)))
1188 result = acpi_device_register(device, parent);
1191 * Bind _ADR-Based Devices when hot add
1193 if (device->flags.bus_address) {
1194 if (device->parent && device->parent->ops.bind)
1195 device->parent->ops.bind(device);
1202 kfree(device->pnp.cid_list);
1209 static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
1211 acpi_status status = AE_OK;
1212 struct acpi_device *parent = NULL;
1213 struct acpi_device *child = NULL;
1214 acpi_handle phandle = NULL;
1215 acpi_handle chandle = NULL;
1216 acpi_object_type type = 0;
1224 phandle = start->handle;
1227 * Parse through the ACPI namespace, identify all 'devices', and
1228 * create a new 'struct acpi_device' for each.
1230 while ((level > 0) && parent) {
1232 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
1236 * If this scope is exhausted then move our way back up.
1238 if (ACPI_FAILURE(status)) {
1241 acpi_get_parent(phandle, &phandle);
1243 parent = parent->parent;
1247 status = acpi_get_type(chandle, &type);
1248 if (ACPI_FAILURE(status))
1252 * If this is a scope object then parse it (depth-first).
1254 if (type == ACPI_TYPE_LOCAL_SCOPE) {
1262 * We're only interested in objects that we consider 'devices'.
1265 case ACPI_TYPE_DEVICE:
1266 type = ACPI_BUS_TYPE_DEVICE;
1268 case ACPI_TYPE_PROCESSOR:
1269 type = ACPI_BUS_TYPE_PROCESSOR;
1271 case ACPI_TYPE_THERMAL:
1272 type = ACPI_BUS_TYPE_THERMAL;
1274 case ACPI_TYPE_POWER:
1275 type = ACPI_BUS_TYPE_POWER;
1281 if (ops->acpi_op_add)
1282 status = acpi_add_single_object(&child, parent,
1283 chandle, type, ops);
1285 status = acpi_bus_get_device(chandle, &child);
1287 if (ACPI_FAILURE(status))
1290 if (ops->acpi_op_start && !(ops->acpi_op_add)) {
1291 status = acpi_start_single_object(child);
1292 if (ACPI_FAILURE(status))
1297 * If the device is present, enabled, and functioning then
1298 * parse its scope (depth-first). Note that we need to
1299 * represent absent devices to facilitate PnP notifications
1300 * -- but only the subtree head (not all of its children,
1301 * which will be enumerated when the parent is inserted).
1303 * TBD: Need notifications and other detection mechanisms
1304 * in place before we can fully implement this.
1306 if (child->status.present) {
1307 status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
1309 if (ACPI_SUCCESS(status)) {
1322 acpi_bus_add(struct acpi_device **child,
1323 struct acpi_device *parent, acpi_handle handle, int type)
1326 struct acpi_bus_ops ops;
1328 memset(&ops, 0, sizeof(ops));
1329 ops.acpi_op_add = 1;
1331 result = acpi_add_single_object(child, parent, handle, type, &ops);
1333 result = acpi_bus_scan(*child, &ops);
1338 EXPORT_SYMBOL(acpi_bus_add);
1340 int acpi_bus_start(struct acpi_device *device)
1343 struct acpi_bus_ops ops;
1349 result = acpi_start_single_object(device);
1351 memset(&ops, 0, sizeof(ops));
1352 ops.acpi_op_start = 1;
1353 result = acpi_bus_scan(device, &ops);
1358 EXPORT_SYMBOL(acpi_bus_start);
1360 int acpi_bus_trim(struct acpi_device *start, int rmdevice)
1363 struct acpi_device *parent, *child;
1364 acpi_handle phandle, chandle;
1365 acpi_object_type type;
1370 phandle = start->handle;
1371 child = chandle = NULL;
1373 while ((level > 0) && parent && (!err)) {
1374 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
1378 * If this scope is exhausted then move our way back up.
1380 if (ACPI_FAILURE(status)) {
1383 acpi_get_parent(phandle, &phandle);
1385 parent = parent->parent;
1388 err = acpi_bus_remove(child, rmdevice);
1390 err = acpi_bus_remove(child, 1);
1395 status = acpi_get_type(chandle, &type);
1396 if (ACPI_FAILURE(status)) {
1400 * If there is a device corresponding to chandle then
1401 * parse it (depth-first).
1403 if (acpi_bus_get_device(chandle, &child) == 0) {
1413 EXPORT_SYMBOL_GPL(acpi_bus_trim);
1416 static int acpi_bus_scan_fixed(struct acpi_device *root)
1419 struct acpi_device *device = NULL;
1420 struct acpi_bus_ops ops;
1425 memset(&ops, 0, sizeof(ops));
1426 ops.acpi_op_add = 1;
1427 ops.acpi_op_start = 1;
1430 * Enumerate all fixed-feature devices.
1432 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
1433 result = acpi_add_single_object(&device, acpi_root,
1435 ACPI_BUS_TYPE_POWER_BUTTON,
1439 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
1440 result = acpi_add_single_object(&device, acpi_root,
1442 ACPI_BUS_TYPE_SLEEP_BUTTON,
1449 static int __init acpi_scan_init(void)
1452 struct acpi_bus_ops ops;
1458 memset(&ops, 0, sizeof(ops));
1459 ops.acpi_op_add = 1;
1460 ops.acpi_op_start = 1;
1462 result = bus_register(&acpi_bus_type);
1464 /* We don't want to quit even if we failed to add suspend/resume */
1465 printk(KERN_ERR PREFIX "Could not register bus type\n");
1469 * Create the root device in the bus's device tree
1471 result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
1472 ACPI_BUS_TYPE_SYSTEM, &ops);
1477 * Enumerate devices in the ACPI namespace.
1479 result = acpi_bus_scan_fixed(acpi_root);
1481 result = acpi_bus_scan(acpi_root, &ops);
1484 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1490 subsys_initcall(acpi_scan_init);