Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / scan.c
blob0338f513a010064b14b1bc8adb6a30fd0d44e4db
1 /*
2 * scan.c - support for transforming the ACPI namespace into individual objects
3 */
5 #include <linux/module.h>
6 #include <linux/init.h>
7 #include <linux/slab.h>
8 #include <linux/kernel.h>
9 #include <linux/acpi.h>
10 #include <linux/signal.h>
11 #include <linux/kthread.h>
12 #include <linux/dmi.h>
14 #include <acpi/acpi_drivers.h>
16 #include "internal.h"
18 #define _COMPONENT ACPI_BUS_COMPONENT
19 ACPI_MODULE_NAME("scan");
20 #define STRUCT_TO_INT(s) (*((int*)&s))
21 extern struct acpi_device *acpi_root;
23 #define ACPI_BUS_CLASS "system_bus"
24 #define ACPI_BUS_HID "LNXSYBUS"
25 #define ACPI_BUS_DEVICE_NAME "System Bus"
27 #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
29 static LIST_HEAD(acpi_device_list);
30 static LIST_HEAD(acpi_bus_id_list);
31 DEFINE_MUTEX(acpi_device_lock);
32 LIST_HEAD(acpi_wakeup_device_list);
34 struct acpi_device_bus_id{
35 char bus_id[15];
36 unsigned int instance_no;
37 struct list_head node;
41 * Creates hid/cid(s) string needed for modalias and uevent
42 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
43 * char *modalias: "acpi:IBM0001:ACPI0001"
45 static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
46 int size)
48 int len;
49 int count;
50 struct acpi_hardware_id *id;
52 len = snprintf(modalias, size, "acpi:");
53 size -= len;
55 list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
56 count = snprintf(&modalias[len], size, "%s:", id->id);
57 if (count < 0 || count >= size)
58 return -EINVAL;
59 len += count;
60 size -= count;
63 modalias[len] = '\0';
64 return len;
67 static ssize_t
68 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
69 struct acpi_device *acpi_dev = to_acpi_device(dev);
70 int len;
72 /* Device has no HID and no CID or string is >1024 */
73 len = create_modalias(acpi_dev, buf, 1024);
74 if (len <= 0)
75 return 0;
76 buf[len++] = '\n';
77 return len;
79 static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
81 static void acpi_bus_hot_remove_device(void *context)
83 struct acpi_device *device;
84 acpi_handle handle = context;
85 struct acpi_object_list arg_list;
86 union acpi_object arg;
87 acpi_status status = AE_OK;
89 if (acpi_bus_get_device(handle, &device))
90 return;
92 if (!device)
93 return;
95 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
96 "Hot-removing device %s...\n", dev_name(&device->dev)));
98 if (acpi_bus_trim(device, 1)) {
99 printk(KERN_ERR PREFIX
100 "Removing device failed\n");
101 return;
104 /* power off device */
105 status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
106 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
107 printk(KERN_WARNING PREFIX
108 "Power-off device failed\n");
110 if (device->flags.lockable) {
111 arg_list.count = 1;
112 arg_list.pointer = &arg;
113 arg.type = ACPI_TYPE_INTEGER;
114 arg.integer.value = 0;
115 acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
118 arg_list.count = 1;
119 arg_list.pointer = &arg;
120 arg.type = ACPI_TYPE_INTEGER;
121 arg.integer.value = 1;
124 * TBD: _EJD support.
126 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
127 if (ACPI_FAILURE(status))
128 printk(KERN_WARNING PREFIX
129 "Eject device failed\n");
131 return;
134 static ssize_t
135 acpi_eject_store(struct device *d, struct device_attribute *attr,
136 const char *buf, size_t count)
138 int ret = count;
139 acpi_status status;
140 acpi_object_type type = 0;
141 struct acpi_device *acpi_device = to_acpi_device(d);
143 if ((!count) || (buf[0] != '1')) {
144 return -EINVAL;
146 #ifndef FORCE_EJECT
147 if (acpi_device->driver == NULL) {
148 ret = -ENODEV;
149 goto err;
151 #endif
152 status = acpi_get_type(acpi_device->handle, &type);
153 if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) {
154 ret = -ENODEV;
155 goto err;
158 acpi_os_hotplug_execute(acpi_bus_hot_remove_device, acpi_device->handle);
159 err:
160 return ret;
163 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
165 static ssize_t
166 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
167 struct acpi_device *acpi_dev = to_acpi_device(dev);
169 return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
171 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
173 static ssize_t
174 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
175 struct acpi_device *acpi_dev = to_acpi_device(dev);
176 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
177 int result;
179 result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
180 if (result)
181 goto end;
183 result = sprintf(buf, "%s\n", (char*)path.pointer);
184 kfree(path.pointer);
185 end:
186 return result;
188 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
190 static int acpi_device_setup_files(struct acpi_device *dev)
192 acpi_status status;
193 acpi_handle temp;
194 int result = 0;
197 * Devices gotten from FADT don't have a "path" attribute
199 if (dev->handle) {
200 result = device_create_file(&dev->dev, &dev_attr_path);
201 if (result)
202 goto end;
205 result = device_create_file(&dev->dev, &dev_attr_hid);
206 if (result)
207 goto end;
209 result = device_create_file(&dev->dev, &dev_attr_modalias);
210 if (result)
211 goto end;
214 * If device has _EJ0, 'eject' file is created that is used to trigger
215 * hot-removal function from userland.
217 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
218 if (ACPI_SUCCESS(status))
219 result = device_create_file(&dev->dev, &dev_attr_eject);
220 end:
221 return result;
224 static void acpi_device_remove_files(struct acpi_device *dev)
226 acpi_status status;
227 acpi_handle temp;
230 * If device has _EJ0, 'eject' file is created that is used to trigger
231 * hot-removal function from userland.
233 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
234 if (ACPI_SUCCESS(status))
235 device_remove_file(&dev->dev, &dev_attr_eject);
237 device_remove_file(&dev->dev, &dev_attr_modalias);
238 device_remove_file(&dev->dev, &dev_attr_hid);
239 if (dev->handle)
240 device_remove_file(&dev->dev, &dev_attr_path);
242 /* --------------------------------------------------------------------------
243 ACPI Bus operations
244 -------------------------------------------------------------------------- */
246 int acpi_match_device_ids(struct acpi_device *device,
247 const struct acpi_device_id *ids)
249 const struct acpi_device_id *id;
250 struct acpi_hardware_id *hwid;
253 * If the device is not present, it is unnecessary to load device
254 * driver for it.
256 if (!device->status.present)
257 return -ENODEV;
259 for (id = ids; id->id[0]; id++)
260 list_for_each_entry(hwid, &device->pnp.ids, list)
261 if (!strcmp((char *) id->id, hwid->id))
262 return 0;
264 return -ENOENT;
266 EXPORT_SYMBOL(acpi_match_device_ids);
268 static void acpi_free_ids(struct acpi_device *device)
270 struct acpi_hardware_id *id, *tmp;
272 list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) {
273 kfree(id->id);
274 kfree(id);
278 static void acpi_device_release(struct device *dev)
280 struct acpi_device *acpi_dev = to_acpi_device(dev);
282 acpi_free_ids(acpi_dev);
283 kfree(acpi_dev);
286 static int acpi_device_suspend(struct device *dev, pm_message_t state)
288 struct acpi_device *acpi_dev = to_acpi_device(dev);
289 struct acpi_driver *acpi_drv = acpi_dev->driver;
291 if (acpi_drv && acpi_drv->ops.suspend)
292 return acpi_drv->ops.suspend(acpi_dev, state);
293 return 0;
296 static int acpi_device_resume(struct device *dev)
298 struct acpi_device *acpi_dev = to_acpi_device(dev);
299 struct acpi_driver *acpi_drv = acpi_dev->driver;
301 if (acpi_drv && acpi_drv->ops.resume)
302 return acpi_drv->ops.resume(acpi_dev);
303 return 0;
306 static int acpi_bus_match(struct device *dev, struct device_driver *drv)
308 struct acpi_device *acpi_dev = to_acpi_device(dev);
309 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
311 return !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
314 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
316 struct acpi_device *acpi_dev = to_acpi_device(dev);
317 int len;
319 if (add_uevent_var(env, "MODALIAS="))
320 return -ENOMEM;
321 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
322 sizeof(env->buf) - env->buflen);
323 if (len >= (sizeof(env->buf) - env->buflen))
324 return -ENOMEM;
325 env->buflen += len;
326 return 0;
329 static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
331 struct acpi_device *device = data;
333 device->driver->ops.notify(device, event);
336 static acpi_status acpi_device_notify_fixed(void *data)
338 struct acpi_device *device = data;
340 /* Fixed hardware devices have no handles */
341 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
342 return AE_OK;
345 static int acpi_device_install_notify_handler(struct acpi_device *device)
347 acpi_status status;
349 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
350 status =
351 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
352 acpi_device_notify_fixed,
353 device);
354 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
355 status =
356 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
357 acpi_device_notify_fixed,
358 device);
359 else
360 status = acpi_install_notify_handler(device->handle,
361 ACPI_DEVICE_NOTIFY,
362 acpi_device_notify,
363 device);
365 if (ACPI_FAILURE(status))
366 return -EINVAL;
367 return 0;
370 static void acpi_device_remove_notify_handler(struct acpi_device *device)
372 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
373 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
374 acpi_device_notify_fixed);
375 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
376 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
377 acpi_device_notify_fixed);
378 else
379 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
380 acpi_device_notify);
383 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
384 static int acpi_start_single_object(struct acpi_device *);
385 static int acpi_device_probe(struct device * dev)
387 struct acpi_device *acpi_dev = to_acpi_device(dev);
388 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
389 int ret;
391 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
392 if (!ret) {
393 if (acpi_dev->bus_ops.acpi_op_start)
394 acpi_start_single_object(acpi_dev);
396 if (acpi_drv->ops.notify) {
397 ret = acpi_device_install_notify_handler(acpi_dev);
398 if (ret) {
399 if (acpi_drv->ops.remove)
400 acpi_drv->ops.remove(acpi_dev,
401 acpi_dev->removal_type);
402 return ret;
406 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
407 "Found driver [%s] for device [%s]\n",
408 acpi_drv->name, acpi_dev->pnp.bus_id));
409 get_device(dev);
411 return ret;
414 static int acpi_device_remove(struct device * dev)
416 struct acpi_device *acpi_dev = to_acpi_device(dev);
417 struct acpi_driver *acpi_drv = acpi_dev->driver;
419 if (acpi_drv) {
420 if (acpi_drv->ops.notify)
421 acpi_device_remove_notify_handler(acpi_dev);
422 if (acpi_drv->ops.remove)
423 acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
425 acpi_dev->driver = NULL;
426 acpi_dev->driver_data = NULL;
428 put_device(dev);
429 return 0;
432 struct bus_type acpi_bus_type = {
433 .name = "acpi",
434 .suspend = acpi_device_suspend,
435 .resume = acpi_device_resume,
436 .match = acpi_bus_match,
437 .probe = acpi_device_probe,
438 .remove = acpi_device_remove,
439 .uevent = acpi_device_uevent,
442 static int acpi_device_register(struct acpi_device *device)
444 int result;
445 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
446 int found = 0;
449 * Linkage
450 * -------
451 * Link this device to its parent and siblings.
453 INIT_LIST_HEAD(&device->children);
454 INIT_LIST_HEAD(&device->node);
455 INIT_LIST_HEAD(&device->wakeup_list);
457 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
458 if (!new_bus_id) {
459 printk(KERN_ERR PREFIX "Memory allocation error\n");
460 return -ENOMEM;
463 mutex_lock(&acpi_device_lock);
465 * Find suitable bus_id and instance number in acpi_bus_id_list
466 * If failed, create one and link it into acpi_bus_id_list
468 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
469 if (!strcmp(acpi_device_bus_id->bus_id,
470 acpi_device_hid(device))) {
471 acpi_device_bus_id->instance_no++;
472 found = 1;
473 kfree(new_bus_id);
474 break;
477 if (!found) {
478 acpi_device_bus_id = new_bus_id;
479 strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
480 acpi_device_bus_id->instance_no = 0;
481 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
483 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
485 if (device->parent)
486 list_add_tail(&device->node, &device->parent->children);
488 if (device->wakeup.flags.valid)
489 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
490 mutex_unlock(&acpi_device_lock);
492 if (device->parent)
493 device->dev.parent = &device->parent->dev;
494 device->dev.bus = &acpi_bus_type;
495 device->dev.release = &acpi_device_release;
496 result = device_register(&device->dev);
497 if (result) {
498 dev_err(&device->dev, "Error registering device\n");
499 goto end;
502 result = acpi_device_setup_files(device);
503 if (result)
504 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
505 dev_name(&device->dev));
507 device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
508 return 0;
509 end:
510 mutex_lock(&acpi_device_lock);
511 if (device->parent)
512 list_del(&device->node);
513 list_del(&device->wakeup_list);
514 mutex_unlock(&acpi_device_lock);
515 return result;
518 static void acpi_device_unregister(struct acpi_device *device, int type)
520 mutex_lock(&acpi_device_lock);
521 if (device->parent)
522 list_del(&device->node);
524 list_del(&device->wakeup_list);
525 mutex_unlock(&acpi_device_lock);
527 acpi_detach_data(device->handle, acpi_bus_data_handler);
529 acpi_device_remove_files(device);
530 device_unregister(&device->dev);
533 /* --------------------------------------------------------------------------
534 Driver Management
535 -------------------------------------------------------------------------- */
537 * acpi_bus_driver_init - add a device to a driver
538 * @device: the device to add and initialize
539 * @driver: driver for the device
541 * Used to initialize a device via its device driver. Called whenever a
542 * driver is bound to a device. Invokes the driver's add() ops.
544 static int
545 acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
547 int result = 0;
549 if (!device || !driver)
550 return -EINVAL;
552 if (!driver->ops.add)
553 return -ENOSYS;
555 result = driver->ops.add(device);
556 if (result) {
557 device->driver = NULL;
558 device->driver_data = NULL;
559 return result;
562 device->driver = driver;
565 * TBD - Configuration Management: Assign resources to device based
566 * upon possible configuration and currently allocated resources.
569 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
570 "Driver successfully bound to device\n"));
571 return 0;
574 static int acpi_start_single_object(struct acpi_device *device)
576 int result = 0;
577 struct acpi_driver *driver;
580 if (!(driver = device->driver))
581 return 0;
583 if (driver->ops.start) {
584 result = driver->ops.start(device);
585 if (result && driver->ops.remove)
586 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
589 return result;
593 * acpi_bus_register_driver - register a driver with the ACPI bus
594 * @driver: driver being registered
596 * Registers a driver with the ACPI bus. Searches the namespace for all
597 * devices that match the driver's criteria and binds. Returns zero for
598 * success or a negative error status for failure.
600 int acpi_bus_register_driver(struct acpi_driver *driver)
602 int ret;
604 if (acpi_disabled)
605 return -ENODEV;
606 driver->drv.name = driver->name;
607 driver->drv.bus = &acpi_bus_type;
608 driver->drv.owner = driver->owner;
610 ret = driver_register(&driver->drv);
611 return ret;
614 EXPORT_SYMBOL(acpi_bus_register_driver);
617 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
618 * @driver: driver to unregister
620 * Unregisters a driver with the ACPI bus. Searches the namespace for all
621 * devices that match the driver's criteria and unbinds.
623 void acpi_bus_unregister_driver(struct acpi_driver *driver)
625 driver_unregister(&driver->drv);
628 EXPORT_SYMBOL(acpi_bus_unregister_driver);
630 /* --------------------------------------------------------------------------
631 Device Enumeration
632 -------------------------------------------------------------------------- */
633 static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
635 acpi_status status;
636 int ret;
637 struct acpi_device *device;
640 * Fixed hardware devices do not appear in the namespace and do not
641 * have handles, but we fabricate acpi_devices for them, so we have
642 * to deal with them specially.
644 if (handle == NULL)
645 return acpi_root;
647 do {
648 status = acpi_get_parent(handle, &handle);
649 if (status == AE_NULL_ENTRY)
650 return NULL;
651 if (ACPI_FAILURE(status))
652 return acpi_root;
654 ret = acpi_bus_get_device(handle, &device);
655 if (ret == 0)
656 return device;
657 } while (1);
660 acpi_status
661 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
663 acpi_status status;
664 acpi_handle tmp;
665 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
666 union acpi_object *obj;
668 status = acpi_get_handle(handle, "_EJD", &tmp);
669 if (ACPI_FAILURE(status))
670 return status;
672 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
673 if (ACPI_SUCCESS(status)) {
674 obj = buffer.pointer;
675 status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
676 ejd);
677 kfree(buffer.pointer);
679 return status;
681 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
683 void acpi_bus_data_handler(acpi_handle handle, void *context)
686 /* TBD */
688 return;
691 static int acpi_bus_get_perf_flags(struct acpi_device *device)
693 device->performance.state = ACPI_STATE_UNKNOWN;
694 return 0;
697 static acpi_status
698 acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
699 union acpi_object *package)
701 int i = 0;
702 union acpi_object *element = NULL;
704 if (!device || !package || (package->package.count < 2))
705 return AE_BAD_PARAMETER;
707 element = &(package->package.elements[0]);
708 if (!element)
709 return AE_BAD_PARAMETER;
710 if (element->type == ACPI_TYPE_PACKAGE) {
711 if ((element->package.count < 2) ||
712 (element->package.elements[0].type !=
713 ACPI_TYPE_LOCAL_REFERENCE)
714 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
715 return AE_BAD_DATA;
716 device->wakeup.gpe_device =
717 element->package.elements[0].reference.handle;
718 device->wakeup.gpe_number =
719 (u32) element->package.elements[1].integer.value;
720 } else if (element->type == ACPI_TYPE_INTEGER) {
721 device->wakeup.gpe_number = element->integer.value;
722 } else
723 return AE_BAD_DATA;
725 element = &(package->package.elements[1]);
726 if (element->type != ACPI_TYPE_INTEGER) {
727 return AE_BAD_DATA;
729 device->wakeup.sleep_state = element->integer.value;
731 if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
732 return AE_NO_MEMORY;
734 device->wakeup.resources.count = package->package.count - 2;
735 for (i = 0; i < device->wakeup.resources.count; i++) {
736 element = &(package->package.elements[i + 2]);
737 if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
738 return AE_BAD_DATA;
740 device->wakeup.resources.handles[i] = element->reference.handle;
743 return AE_OK;
746 static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
748 struct acpi_device_id button_device_ids[] = {
749 {"PNP0C0D", 0},
750 {"PNP0C0C", 0},
751 {"PNP0C0E", 0},
752 {"", 0},
754 acpi_status status;
755 acpi_event_status event_status;
757 device->wakeup.run_wake_count = 0;
758 device->wakeup.flags.notifier_present = 0;
760 /* Power button, Lid switch always enable wakeup */
761 if (!acpi_match_device_ids(device, button_device_ids)) {
762 device->wakeup.flags.run_wake = 1;
763 device->wakeup.flags.always_enabled = 1;
764 return;
767 status = acpi_get_gpe_status(NULL, device->wakeup.gpe_number,
768 ACPI_NOT_ISR, &event_status);
769 if (status == AE_OK)
770 device->wakeup.flags.run_wake =
771 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
774 static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
776 acpi_status status = 0;
777 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
778 union acpi_object *package = NULL;
779 int psw_error;
781 /* _PRW */
782 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
783 if (ACPI_FAILURE(status)) {
784 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
785 goto end;
788 package = (union acpi_object *)buffer.pointer;
789 status = acpi_bus_extract_wakeup_device_power_package(device, package);
790 if (ACPI_FAILURE(status)) {
791 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
792 goto end;
795 kfree(buffer.pointer);
797 device->wakeup.flags.valid = 1;
798 device->wakeup.prepare_count = 0;
799 acpi_bus_set_run_wake_flags(device);
800 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
801 * system for the ACPI device with the _PRW object.
802 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
803 * So it is necessary to call _DSW object first. Only when it is not
804 * present will the _PSW object used.
806 psw_error = acpi_device_sleep_wake(device, 0, 0, 0);
807 if (psw_error)
808 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
809 "error in _DSW or _PSW evaluation\n"));
811 end:
812 if (ACPI_FAILURE(status))
813 device->flags.wake_capable = 0;
814 return 0;
817 static int acpi_bus_get_power_flags(struct acpi_device *device)
819 acpi_status status = 0;
820 acpi_handle handle = NULL;
821 u32 i = 0;
825 * Power Management Flags
827 status = acpi_get_handle(device->handle, "_PSC", &handle);
828 if (ACPI_SUCCESS(status))
829 device->power.flags.explicit_get = 1;
830 status = acpi_get_handle(device->handle, "_IRC", &handle);
831 if (ACPI_SUCCESS(status))
832 device->power.flags.inrush_current = 1;
835 * Enumerate supported power management states
837 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
838 struct acpi_device_power_state *ps = &device->power.states[i];
839 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
841 /* Evaluate "_PRx" to se if power resources are referenced */
842 acpi_evaluate_reference(device->handle, object_name, NULL,
843 &ps->resources);
844 if (ps->resources.count) {
845 device->power.flags.power_resources = 1;
846 ps->flags.valid = 1;
849 /* Evaluate "_PSx" to see if we can do explicit sets */
850 object_name[2] = 'S';
851 status = acpi_get_handle(device->handle, object_name, &handle);
852 if (ACPI_SUCCESS(status)) {
853 ps->flags.explicit_set = 1;
854 ps->flags.valid = 1;
857 /* State is valid if we have some power control */
858 if (ps->resources.count || ps->flags.explicit_set)
859 ps->flags.valid = 1;
861 ps->power = -1; /* Unknown - driver assigned */
862 ps->latency = -1; /* Unknown - driver assigned */
865 /* Set defaults for D0 and D3 states (always valid) */
866 device->power.states[ACPI_STATE_D0].flags.valid = 1;
867 device->power.states[ACPI_STATE_D0].power = 100;
868 device->power.states[ACPI_STATE_D3].flags.valid = 1;
869 device->power.states[ACPI_STATE_D3].power = 0;
871 /* TBD: System wake support and resource requirements. */
873 device->power.state = ACPI_STATE_UNKNOWN;
874 acpi_bus_get_power(device->handle, &(device->power.state));
876 return 0;
879 static int acpi_bus_get_flags(struct acpi_device *device)
881 acpi_status status = AE_OK;
882 acpi_handle temp = NULL;
885 /* Presence of _STA indicates 'dynamic_status' */
886 status = acpi_get_handle(device->handle, "_STA", &temp);
887 if (ACPI_SUCCESS(status))
888 device->flags.dynamic_status = 1;
890 /* Presence of _RMV indicates 'removable' */
891 status = acpi_get_handle(device->handle, "_RMV", &temp);
892 if (ACPI_SUCCESS(status))
893 device->flags.removable = 1;
895 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
896 status = acpi_get_handle(device->handle, "_EJD", &temp);
897 if (ACPI_SUCCESS(status))
898 device->flags.ejectable = 1;
899 else {
900 status = acpi_get_handle(device->handle, "_EJ0", &temp);
901 if (ACPI_SUCCESS(status))
902 device->flags.ejectable = 1;
905 /* Presence of _LCK indicates 'lockable' */
906 status = acpi_get_handle(device->handle, "_LCK", &temp);
907 if (ACPI_SUCCESS(status))
908 device->flags.lockable = 1;
910 /* Presence of _PS0|_PR0 indicates 'power manageable' */
911 status = acpi_get_handle(device->handle, "_PS0", &temp);
912 if (ACPI_FAILURE(status))
913 status = acpi_get_handle(device->handle, "_PR0", &temp);
914 if (ACPI_SUCCESS(status))
915 device->flags.power_manageable = 1;
917 /* Presence of _PRW indicates wake capable */
918 status = acpi_get_handle(device->handle, "_PRW", &temp);
919 if (ACPI_SUCCESS(status))
920 device->flags.wake_capable = 1;
922 /* TBD: Performance management */
924 return 0;
927 static void acpi_device_get_busid(struct acpi_device *device)
929 char bus_id[5] = { '?', 0 };
930 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
931 int i = 0;
934 * Bus ID
935 * ------
936 * The device's Bus ID is simply the object name.
937 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
939 if (ACPI_IS_ROOT_DEVICE(device)) {
940 strcpy(device->pnp.bus_id, "ACPI");
941 return;
944 switch (device->device_type) {
945 case ACPI_BUS_TYPE_POWER_BUTTON:
946 strcpy(device->pnp.bus_id, "PWRF");
947 break;
948 case ACPI_BUS_TYPE_SLEEP_BUTTON:
949 strcpy(device->pnp.bus_id, "SLPF");
950 break;
951 default:
952 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
953 /* Clean up trailing underscores (if any) */
954 for (i = 3; i > 1; i--) {
955 if (bus_id[i] == '_')
956 bus_id[i] = '\0';
957 else
958 break;
960 strcpy(device->pnp.bus_id, bus_id);
961 break;
966 * acpi_bay_match - see if a device is an ejectable driver bay
968 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
969 * then we can safely call it an ejectable drive bay
971 static int acpi_bay_match(struct acpi_device *device){
972 acpi_status status;
973 acpi_handle handle;
974 acpi_handle tmp;
975 acpi_handle phandle;
977 handle = device->handle;
979 status = acpi_get_handle(handle, "_EJ0", &tmp);
980 if (ACPI_FAILURE(status))
981 return -ENODEV;
983 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
984 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
985 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
986 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
987 return 0;
989 if (acpi_get_parent(handle, &phandle))
990 return -ENODEV;
992 if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) ||
993 (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) ||
994 (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) ||
995 (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp))))
996 return 0;
998 return -ENODEV;
1002 * acpi_dock_match - see if a device has a _DCK method
1004 static int acpi_dock_match(struct acpi_device *device)
1006 acpi_handle tmp;
1007 return acpi_get_handle(device->handle, "_DCK", &tmp);
1010 char *acpi_device_hid(struct acpi_device *device)
1012 struct acpi_hardware_id *hid;
1014 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1015 return hid->id;
1017 EXPORT_SYMBOL(acpi_device_hid);
1019 static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1021 struct acpi_hardware_id *id;
1023 id = kmalloc(sizeof(*id), GFP_KERNEL);
1024 if (!id)
1025 return;
1027 id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL);
1028 if (!id->id) {
1029 kfree(id);
1030 return;
1033 strcpy(id->id, dev_id);
1034 list_add_tail(&id->list, &device->pnp.ids);
1038 * Old IBM workstations have a DSDT bug wherein the SMBus object
1039 * lacks the SMBUS01 HID and the methods do not have the necessary "_"
1040 * prefix. Work around this.
1042 static int acpi_ibm_smbus_match(struct acpi_device *device)
1044 acpi_handle h_dummy;
1045 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
1046 int result;
1048 if (!dmi_name_in_vendors("IBM"))
1049 return -ENODEV;
1051 /* Look for SMBS object */
1052 result = acpi_get_name(device->handle, ACPI_SINGLE_NAME, &path);
1053 if (result)
1054 return result;
1056 if (strcmp("SMBS", path.pointer)) {
1057 result = -ENODEV;
1058 goto out;
1061 /* Does it have the necessary (but misnamed) methods? */
1062 result = -ENODEV;
1063 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "SBI", &h_dummy)) &&
1064 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBR", &h_dummy)) &&
1065 ACPI_SUCCESS(acpi_get_handle(device->handle, "SBW", &h_dummy)))
1066 result = 0;
1067 out:
1068 kfree(path.pointer);
1069 return result;
1072 static void acpi_device_set_id(struct acpi_device *device)
1074 acpi_status status;
1075 struct acpi_device_info *info;
1076 struct acpica_device_id_list *cid_list;
1077 int i;
1079 switch (device->device_type) {
1080 case ACPI_BUS_TYPE_DEVICE:
1081 if (ACPI_IS_ROOT_DEVICE(device)) {
1082 acpi_add_id(device, ACPI_SYSTEM_HID);
1083 break;
1086 status = acpi_get_object_info(device->handle, &info);
1087 if (ACPI_FAILURE(status)) {
1088 printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__);
1089 return;
1092 if (info->valid & ACPI_VALID_HID)
1093 acpi_add_id(device, info->hardware_id.string);
1094 if (info->valid & ACPI_VALID_CID) {
1095 cid_list = &info->compatible_id_list;
1096 for (i = 0; i < cid_list->count; i++)
1097 acpi_add_id(device, cid_list->ids[i].string);
1099 if (info->valid & ACPI_VALID_ADR) {
1100 device->pnp.bus_address = info->address;
1101 device->flags.bus_address = 1;
1104 kfree(info);
1107 * Some devices don't reliably have _HIDs & _CIDs, so add
1108 * synthetic HIDs to make sure drivers can find them.
1110 if (acpi_is_video_device(device))
1111 acpi_add_id(device, ACPI_VIDEO_HID);
1112 else if (ACPI_SUCCESS(acpi_bay_match(device)))
1113 acpi_add_id(device, ACPI_BAY_HID);
1114 else if (ACPI_SUCCESS(acpi_dock_match(device)))
1115 acpi_add_id(device, ACPI_DOCK_HID);
1116 else if (!acpi_ibm_smbus_match(device))
1117 acpi_add_id(device, ACPI_SMBUS_IBM_HID);
1118 else if (!acpi_device_hid(device) &&
1119 ACPI_IS_ROOT_DEVICE(device->parent)) {
1120 acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
1121 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
1122 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
1125 break;
1126 case ACPI_BUS_TYPE_POWER:
1127 acpi_add_id(device, ACPI_POWER_HID);
1128 break;
1129 case ACPI_BUS_TYPE_PROCESSOR:
1130 acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
1131 break;
1132 case ACPI_BUS_TYPE_THERMAL:
1133 acpi_add_id(device, ACPI_THERMAL_HID);
1134 break;
1135 case ACPI_BUS_TYPE_POWER_BUTTON:
1136 acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
1137 break;
1138 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1139 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
1140 break;
1144 * We build acpi_devices for some objects that don't have _HID or _CID,
1145 * e.g., PCI bridges and slots. Drivers can't bind to these objects,
1146 * but we do use them indirectly by traversing the acpi_device tree.
1147 * This generic ID isn't useful for driver binding, but it provides
1148 * the useful property that "every acpi_device has an ID."
1150 if (list_empty(&device->pnp.ids))
1151 acpi_add_id(device, "device");
1154 static int acpi_device_set_context(struct acpi_device *device)
1156 acpi_status status;
1159 * Context
1160 * -------
1161 * Attach this 'struct acpi_device' to the ACPI object. This makes
1162 * resolutions from handle->device very efficient. Fixed hardware
1163 * devices have no handles, so we skip them.
1165 if (!device->handle)
1166 return 0;
1168 status = acpi_attach_data(device->handle,
1169 acpi_bus_data_handler, device);
1170 if (ACPI_SUCCESS(status))
1171 return 0;
1173 printk(KERN_ERR PREFIX "Error attaching device data\n");
1174 return -ENODEV;
1177 static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
1179 if (!dev)
1180 return -EINVAL;
1182 dev->removal_type = ACPI_BUS_REMOVAL_EJECT;
1183 device_release_driver(&dev->dev);
1185 if (!rmdevice)
1186 return 0;
1189 * unbind _ADR-Based Devices when hot removal
1191 if (dev->flags.bus_address) {
1192 if ((dev->parent) && (dev->parent->ops.unbind))
1193 dev->parent->ops.unbind(dev);
1195 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
1197 return 0;
1200 static int acpi_add_single_object(struct acpi_device **child,
1201 acpi_handle handle, int type,
1202 unsigned long long sta,
1203 struct acpi_bus_ops *ops)
1205 int result;
1206 struct acpi_device *device;
1207 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1209 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1210 if (!device) {
1211 printk(KERN_ERR PREFIX "Memory allocation error\n");
1212 return -ENOMEM;
1215 INIT_LIST_HEAD(&device->pnp.ids);
1216 device->device_type = type;
1217 device->handle = handle;
1218 device->parent = acpi_bus_get_parent(handle);
1219 device->bus_ops = *ops; /* workround for not call .start */
1220 STRUCT_TO_INT(device->status) = sta;
1222 acpi_device_get_busid(device);
1225 * Flags
1226 * -----
1227 * Note that we only look for object handles -- cannot evaluate objects
1228 * until we know the device is present and properly initialized.
1230 result = acpi_bus_get_flags(device);
1231 if (result)
1232 goto end;
1235 * Initialize Device
1236 * -----------------
1237 * TBD: Synch with Core's enumeration/initialization process.
1239 acpi_device_set_id(device);
1242 * Power Management
1243 * ----------------
1245 if (device->flags.power_manageable) {
1246 result = acpi_bus_get_power_flags(device);
1247 if (result)
1248 goto end;
1252 * Wakeup device management
1253 *-----------------------
1255 if (device->flags.wake_capable) {
1256 result = acpi_bus_get_wakeup_device_flags(device);
1257 if (result)
1258 goto end;
1262 * Performance Management
1263 * ----------------------
1265 if (device->flags.performance_manageable) {
1266 result = acpi_bus_get_perf_flags(device);
1267 if (result)
1268 goto end;
1271 if ((result = acpi_device_set_context(device)))
1272 goto end;
1274 result = acpi_device_register(device);
1277 * Bind _ADR-Based Devices when hot add
1279 if (device->flags.bus_address) {
1280 if (device->parent && device->parent->ops.bind)
1281 device->parent->ops.bind(device);
1284 end:
1285 if (!result) {
1286 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1287 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1288 "Adding %s [%s] parent %s\n", dev_name(&device->dev),
1289 (char *) buffer.pointer,
1290 device->parent ? dev_name(&device->parent->dev) :
1291 "(null)"));
1292 kfree(buffer.pointer);
1293 *child = device;
1294 } else
1295 acpi_device_release(&device->dev);
1297 return result;
1300 #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
1301 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
1303 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1304 unsigned long long *sta)
1306 acpi_status status;
1307 acpi_object_type acpi_type;
1309 status = acpi_get_type(handle, &acpi_type);
1310 if (ACPI_FAILURE(status))
1311 return -ENODEV;
1313 switch (acpi_type) {
1314 case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
1315 case ACPI_TYPE_DEVICE:
1316 *type = ACPI_BUS_TYPE_DEVICE;
1317 status = acpi_bus_get_status_handle(handle, sta);
1318 if (ACPI_FAILURE(status))
1319 return -ENODEV;
1320 break;
1321 case ACPI_TYPE_PROCESSOR:
1322 *type = ACPI_BUS_TYPE_PROCESSOR;
1323 status = acpi_bus_get_status_handle(handle, sta);
1324 if (ACPI_FAILURE(status))
1325 return -ENODEV;
1326 break;
1327 case ACPI_TYPE_THERMAL:
1328 *type = ACPI_BUS_TYPE_THERMAL;
1329 *sta = ACPI_STA_DEFAULT;
1330 break;
1331 case ACPI_TYPE_POWER:
1332 *type = ACPI_BUS_TYPE_POWER;
1333 *sta = ACPI_STA_DEFAULT;
1334 break;
1335 default:
1336 return -ENODEV;
1339 return 0;
1342 static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
1343 void *context, void **return_value)
1345 struct acpi_bus_ops *ops = context;
1346 int type;
1347 unsigned long long sta;
1348 struct acpi_device *device;
1349 acpi_status status;
1350 int result;
1352 result = acpi_bus_type_and_status(handle, &type, &sta);
1353 if (result)
1354 return AE_OK;
1356 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1357 !(sta & ACPI_STA_DEVICE_FUNCTIONING))
1358 return AE_CTRL_DEPTH;
1361 * We may already have an acpi_device from a previous enumeration. If
1362 * so, we needn't add it again, but we may still have to start it.
1364 device = NULL;
1365 acpi_bus_get_device(handle, &device);
1366 if (ops->acpi_op_add && !device)
1367 acpi_add_single_object(&device, handle, type, sta, ops);
1369 if (!device)
1370 return AE_CTRL_DEPTH;
1372 if (ops->acpi_op_start && !(ops->acpi_op_add)) {
1373 status = acpi_start_single_object(device);
1374 if (ACPI_FAILURE(status))
1375 return AE_CTRL_DEPTH;
1378 if (!*return_value)
1379 *return_value = device;
1380 return AE_OK;
1383 static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,
1384 struct acpi_device **child)
1386 acpi_status status;
1387 void *device = NULL;
1389 status = acpi_bus_check_add(handle, 0, ops, &device);
1390 if (ACPI_SUCCESS(status))
1391 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1392 acpi_bus_check_add, NULL, ops, &device);
1394 if (child)
1395 *child = device;
1397 if (device)
1398 return 0;
1399 else
1400 return -ENODEV;
1404 * acpi_bus_add and acpi_bus_start
1406 * scan a given ACPI tree and (probably recently hot-plugged)
1407 * create and add or starts found devices.
1409 * If no devices were found -ENODEV is returned which does not
1410 * mean that this is a real error, there just have been no suitable
1411 * ACPI objects in the table trunk from which the kernel could create
1412 * a device and add/start an appropriate driver.
1416 acpi_bus_add(struct acpi_device **child,
1417 struct acpi_device *parent, acpi_handle handle, int type)
1419 struct acpi_bus_ops ops;
1421 memset(&ops, 0, sizeof(ops));
1422 ops.acpi_op_add = 1;
1424 return acpi_bus_scan(handle, &ops, child);
1426 EXPORT_SYMBOL(acpi_bus_add);
1428 int acpi_bus_start(struct acpi_device *device)
1430 struct acpi_bus_ops ops;
1432 if (!device)
1433 return -EINVAL;
1435 memset(&ops, 0, sizeof(ops));
1436 ops.acpi_op_start = 1;
1438 return acpi_bus_scan(device->handle, &ops, NULL);
1440 EXPORT_SYMBOL(acpi_bus_start);
1442 int acpi_bus_trim(struct acpi_device *start, int rmdevice)
1444 acpi_status status;
1445 struct acpi_device *parent, *child;
1446 acpi_handle phandle, chandle;
1447 acpi_object_type type;
1448 u32 level = 1;
1449 int err = 0;
1451 parent = start;
1452 phandle = start->handle;
1453 child = chandle = NULL;
1455 while ((level > 0) && parent && (!err)) {
1456 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
1457 chandle, &chandle);
1460 * If this scope is exhausted then move our way back up.
1462 if (ACPI_FAILURE(status)) {
1463 level--;
1464 chandle = phandle;
1465 acpi_get_parent(phandle, &phandle);
1466 child = parent;
1467 parent = parent->parent;
1469 if (level == 0)
1470 err = acpi_bus_remove(child, rmdevice);
1471 else
1472 err = acpi_bus_remove(child, 1);
1474 continue;
1477 status = acpi_get_type(chandle, &type);
1478 if (ACPI_FAILURE(status)) {
1479 continue;
1482 * If there is a device corresponding to chandle then
1483 * parse it (depth-first).
1485 if (acpi_bus_get_device(chandle, &child) == 0) {
1486 level++;
1487 phandle = chandle;
1488 chandle = NULL;
1489 parent = child;
1491 continue;
1493 return err;
1495 EXPORT_SYMBOL_GPL(acpi_bus_trim);
1497 static int acpi_bus_scan_fixed(void)
1499 int result = 0;
1500 struct acpi_device *device = NULL;
1501 struct acpi_bus_ops ops;
1503 memset(&ops, 0, sizeof(ops));
1504 ops.acpi_op_add = 1;
1505 ops.acpi_op_start = 1;
1508 * Enumerate all fixed-feature devices.
1510 if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
1511 result = acpi_add_single_object(&device, NULL,
1512 ACPI_BUS_TYPE_POWER_BUTTON,
1513 ACPI_STA_DEFAULT,
1514 &ops);
1517 if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
1518 result = acpi_add_single_object(&device, NULL,
1519 ACPI_BUS_TYPE_SLEEP_BUTTON,
1520 ACPI_STA_DEFAULT,
1521 &ops);
1524 return result;
1527 int __init acpi_scan_init(void)
1529 int result;
1530 struct acpi_bus_ops ops;
1532 memset(&ops, 0, sizeof(ops));
1533 ops.acpi_op_add = 1;
1534 ops.acpi_op_start = 1;
1536 result = bus_register(&acpi_bus_type);
1537 if (result) {
1538 /* We don't want to quit even if we failed to add suspend/resume */
1539 printk(KERN_ERR PREFIX "Could not register bus type\n");
1543 * Enumerate devices in the ACPI namespace.
1545 result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root);
1547 if (!result)
1548 result = acpi_bus_scan_fixed();
1550 if (result)
1551 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1553 return result;