blob: 464746257d8ee98b41a5dcc03a70c84f02566e9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * scan.c - support for transforming the ACPI namespace into individual objects
3 */
4
5#include <linux/module.h>
6#include <linux/init.h>
Randy Dunlap9b6d97b2006-07-12 02:08:00 -04007#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/acpi.h>
9
10#include <acpi/acpi_drivers.h>
11#include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#define _COMPONENT ACPI_BUS_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040014ACPI_MODULE_NAME("scan")
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#define STRUCT_TO_INT(s) (*((int*)&s))
Len Brown4be44fc2005-08-05 00:44:28 -040016extern struct acpi_device *acpi_root;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
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"
22
23static LIST_HEAD(acpi_device_list);
24DEFINE_SPINLOCK(acpi_device_lock);
25LIST_HEAD(acpi_wakeup_device_list);
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Len Brown4be44fc2005-08-05 00:44:28 -040028static void acpi_device_release(struct kobject *kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Len Brown4be44fc2005-08-05 00:44:28 -040030 struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj);
Jesper Juhl6044ec82005-11-07 01:01:32 -080031 kfree(dev->pnp.cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 kfree(dev);
33}
34
35struct acpi_device_attribute {
36 struct attribute attr;
Len Brown4be44fc2005-08-05 00:44:28 -040037 ssize_t(*show) (struct acpi_device *, char *);
38 ssize_t(*store) (struct acpi_device *, const char *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039};
40
41typedef void acpi_device_sysfs_files(struct kobject *,
Len Brown4be44fc2005-08-05 00:44:28 -040042 const struct attribute *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44static void setup_sys_fs_device_files(struct acpi_device *dev,
Len Brown4be44fc2005-08-05 00:44:28 -040045 acpi_device_sysfs_files * func);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47#define create_sysfs_device_files(dev) \
48 setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file)
49#define remove_sysfs_device_files(dev) \
50 setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file)
51
Zhang Rui1d268b02006-12-07 20:56:19 +080052#define to_acpi_dev(n) container_of(n, struct acpi_device, kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr);
54
55static ssize_t acpi_device_attr_show(struct kobject *kobj,
Len Brown4be44fc2005-08-05 00:44:28 -040056 struct attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Zhang Rui1d268b02006-12-07 20:56:19 +080058 struct acpi_device *device = to_acpi_dev(kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 struct acpi_device_attribute *attribute = to_handle_attr(attr);
Dmitry Torokhov70f28172005-04-29 01:27:34 -050060 return attribute->show ? attribute->show(device, buf) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62static ssize_t acpi_device_attr_store(struct kobject *kobj,
Len Brown4be44fc2005-08-05 00:44:28 -040063 struct attribute *attr, const char *buf,
64 size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Zhang Rui1d268b02006-12-07 20:56:19 +080066 struct acpi_device *device = to_acpi_dev(kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct acpi_device_attribute *attribute = to_handle_attr(attr);
Dmitry Torokhov70f28172005-04-29 01:27:34 -050068 return attribute->store ? attribute->store(device, buf, len) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static struct sysfs_ops acpi_device_sysfs_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -040072 .show = acpi_device_attr_show,
73 .store = acpi_device_attr_store,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
76static struct kobj_type ktype_acpi_ns = {
Len Brown4be44fc2005-08-05 00:44:28 -040077 .sysfs_ops = &acpi_device_sysfs_ops,
78 .release = acpi_device_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079};
80
Kay Sievers312c0042005-11-16 09:00:00 +010081static int namespace_uevent(struct kset *kset, struct kobject *kobj,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 char **envp, int num_envp, char *buffer,
83 int buffer_size)
84{
Zhang Rui1d268b02006-12-07 20:56:19 +080085 struct acpi_device *dev = to_acpi_dev(kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 int i = 0;
87 int len = 0;
88
89 if (!dev->driver)
90 return 0;
91
Kay Sievers312c0042005-11-16 09:00:00 +010092 if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
93 "PHYSDEVDRIVER=%s", dev->driver->name))
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return -ENOMEM;
95
96 envp[i] = NULL;
97
98 return 0;
99}
100
Kay Sievers312c0042005-11-16 09:00:00 +0100101static struct kset_uevent_ops namespace_uevent_ops = {
102 .uevent = &namespace_uevent,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
104
105static struct kset acpi_namespace_kset = {
Len Brown4be44fc2005-08-05 00:44:28 -0400106 .kobj = {
107 .name = "namespace",
108 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .subsys = &acpi_subsys,
Len Brown4be44fc2005-08-05 00:44:28 -0400110 .ktype = &ktype_acpi_ns,
Kay Sievers312c0042005-11-16 09:00:00 +0100111 .uevent_ops = &namespace_uevent_ops,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* --------------------------------------------------------------------------
Kay Sievers312c0042005-11-16 09:00:00 +0100115 ACPI sysfs device file support
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 -------------------------------------------------------------------------- */
Len Brown4be44fc2005-08-05 00:44:28 -0400117static ssize_t acpi_eject_store(struct acpi_device *device,
118 const char *buf, size_t count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120#define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \
121static struct acpi_device_attribute acpi_device_attr_##_name = \
122 __ATTR(_name, _mode, _show, _store)
123
124ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
125
126/**
127 * setup_sys_fs_device_files - sets up the device files under device namespace
Martin Waitz67be2dd2005-05-01 08:59:26 -0700128 * @dev: acpi_device object
129 * @func: function pointer to create or destroy the device file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 */
131static void
Len Brown4be44fc2005-08-05 00:44:28 -0400132setup_sys_fs_device_files(struct acpi_device *dev,
133 acpi_device_sysfs_files * func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Len Brown4be44fc2005-08-05 00:44:28 -0400135 acpi_status status;
136 acpi_handle temp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 /*
139 * If device has _EJ0, 'eject' file is created that is used to trigger
140 * hot-removal function from userland.
141 */
142 status = acpi_get_handle(dev->handle, "_EJ0", &temp);
143 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400144 (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Len Brown4be44fc2005-08-05 00:44:28 -0400147static int acpi_eject_operation(acpi_handle handle, int lockable)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 struct acpi_object_list arg_list;
150 union acpi_object arg;
151 acpi_status status = AE_OK;
152
153 /*
154 * TBD: evaluate _PS3?
155 */
156
157 if (lockable) {
158 arg_list.count = 1;
159 arg_list.pointer = &arg;
160 arg.type = ACPI_TYPE_INTEGER;
161 arg.integer.value = 0;
162 acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
163 }
164
165 arg_list.count = 1;
166 arg_list.pointer = &arg;
167 arg.type = ACPI_TYPE_INTEGER;
168 arg.integer.value = 1;
169
170 /*
171 * TBD: _EJD support.
172 */
173
174 status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
175 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400176 return (-ENODEV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static ssize_t
183acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
184{
Len Brown4be44fc2005-08-05 00:44:28 -0400185 int result;
186 int ret = count;
187 int islockable;
188 acpi_status status;
189 acpi_handle handle;
190 acpi_object_type type = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 if ((!count) || (buf[0] != '1')) {
193 return -EINVAL;
194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#ifndef FORCE_EJECT
196 if (device->driver == NULL) {
197 ret = -ENODEV;
198 goto err;
199 }
200#endif
201 status = acpi_get_type(device->handle, &type);
Len Brown4be44fc2005-08-05 00:44:28 -0400202 if (ACPI_FAILURE(status) || (!device->flags.ejectable)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 ret = -ENODEV;
204 goto err;
205 }
206
207 islockable = device->flags.lockable;
208 handle = device->handle;
209
Ashok Rajeefa27a2006-03-28 17:04:00 -0500210 result = acpi_bus_trim(device, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 if (!result)
213 result = acpi_eject_operation(handle, islockable);
214
215 if (result) {
216 ret = -EBUSY;
217 }
Len Brown4be44fc2005-08-05 00:44:28 -0400218 err:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return ret;
220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/* --------------------------------------------------------------------------
Zhang Rui9e89dde2006-12-07 20:56:16 +0800223 ACPI Bus operations
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 -------------------------------------------------------------------------- */
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800225static int acpi_device_suspend(struct device *dev, pm_message_t state)
Zhang Rui9e89dde2006-12-07 20:56:16 +0800226{
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800227 struct acpi_device *acpi_dev = to_acpi_device(dev);
228 struct acpi_driver *acpi_drv = acpi_dev->driver;
Zhang Rui9e89dde2006-12-07 20:56:16 +0800229
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800230 if (acpi_drv && acpi_drv->ops.suspend)
231 return acpi_drv->ops.suspend(acpi_dev, state);
232 return 0;
233}
234
235static int acpi_device_resume(struct device *dev)
236{
237 struct acpi_device *acpi_dev = to_acpi_device(dev);
238 struct acpi_driver *acpi_drv = acpi_dev->driver;
239
240 if (acpi_drv && acpi_drv->ops.resume)
241 return acpi_drv->ops.resume(acpi_dev);
242 return 0;
243}
244
245static int acpi_bus_match(struct device *dev, struct device_driver *drv)
246{
247 struct acpi_device *acpi_dev = to_acpi_device(dev);
248 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
249
250 if (acpi_drv->ops.match)
251 return !acpi_drv->ops.match(acpi_dev, acpi_drv);
252 return !acpi_match_ids(acpi_dev, acpi_drv->ids);
253}
254
255static int acpi_device_uevent(struct device *dev, char **envp, int num_envp,
256 char *buffer, int buffer_size)
257{
258 struct acpi_device *acpi_dev = to_acpi_device(dev);
259 int i = 0, length = 0, ret = 0;
260
261 if (acpi_dev->flags.hardware_id)
262 ret = add_uevent_var(envp, num_envp, &i,
263 buffer, buffer_size, &length,
264 "HWID=%s", acpi_dev->pnp.hardware_id);
265 if (ret)
266 return -ENOMEM;
267 if (acpi_dev->flags.compatible_ids) {
268 int j;
269 struct acpi_compatible_id_list *cid_list;
270
271 cid_list = acpi_dev->pnp.cid_list;
272
273 for (j = 0; j < cid_list->count; j++) {
274 ret = add_uevent_var(envp, num_envp, &i, buffer,
275 buffer_size, &length, "COMPTID=%s",
276 cid_list->id[j].value);
277 if (ret)
278 return -ENOMEM;
Zhang Rui9e89dde2006-12-07 20:56:16 +0800279 }
280 }
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800281
282 envp[i] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return 0;
284}
285
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800286static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
287static int acpi_start_single_object(struct acpi_device *);
288static int acpi_device_probe(struct device * dev)
Zhang Rui9e89dde2006-12-07 20:56:16 +0800289{
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800290 struct acpi_device *acpi_dev = to_acpi_device(dev);
291 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
292 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800294 ret = acpi_bus_driver_init(acpi_dev, acpi_drv);
295 if (!ret) {
296 acpi_start_single_object(acpi_dev);
297 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
298 "Found driver [%s] for device [%s]\n",
299 acpi_drv->name, acpi_dev->pnp.bus_id));
300 get_device(dev);
Zhang Rui9e89dde2006-12-07 20:56:16 +0800301 }
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800302 return ret;
303}
304
305static int acpi_device_remove(struct device * dev)
306{
307 struct acpi_device *acpi_dev = to_acpi_device(dev);
308 struct acpi_driver *acpi_drv = acpi_dev->driver;
309
310 if (acpi_drv) {
311 if (acpi_drv->ops.stop)
312 acpi_drv->ops.stop(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
313 if (acpi_drv->ops.remove)
314 acpi_drv->ops.remove(acpi_dev, ACPI_BUS_REMOVAL_NORMAL);
315 }
316 acpi_dev->driver = NULL;
317 acpi_driver_data(dev) = NULL;
318
319 put_device(dev);
Zhang Rui9e89dde2006-12-07 20:56:16 +0800320 return 0;
321}
322
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800323static void acpi_device_shutdown(struct device *dev)
Zhang Rui9e89dde2006-12-07 20:56:16 +0800324{
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800325 struct acpi_device *acpi_dev = to_acpi_device(dev);
326 struct acpi_driver *acpi_drv = acpi_dev->driver;
Zhang Rui9e89dde2006-12-07 20:56:16 +0800327
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800328 if (acpi_drv && acpi_drv->ops.shutdown)
329 acpi_drv->ops.shutdown(acpi_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800331 return ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Zhang Rui9e89dde2006-12-07 20:56:16 +0800334static struct bus_type acpi_bus_type = {
335 .name = "acpi",
336 .suspend = acpi_device_suspend,
337 .resume = acpi_device_resume,
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800338 .shutdown = acpi_device_shutdown,
339 .match = acpi_bus_match,
340 .probe = acpi_device_probe,
341 .remove = acpi_device_remove,
342 .uevent = acpi_device_uevent,
Zhang Rui9e89dde2006-12-07 20:56:16 +0800343};
344
345static void acpi_device_register(struct acpi_device *device,
346 struct acpi_device *parent)
347{
348 int err;
349
350 /*
351 * Linkage
352 * -------
353 * Link this device to its parent and siblings.
354 */
355 INIT_LIST_HEAD(&device->children);
356 INIT_LIST_HEAD(&device->node);
357 INIT_LIST_HEAD(&device->g_list);
358 INIT_LIST_HEAD(&device->wakeup_list);
359
360 spin_lock(&acpi_device_lock);
361 if (device->parent) {
362 list_add_tail(&device->node, &device->parent->children);
363 list_add_tail(&device->g_list, &device->parent->g_list);
364 } else
365 list_add_tail(&device->g_list, &acpi_device_list);
366 if (device->wakeup.flags.valid)
367 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
368 spin_unlock(&acpi_device_lock);
369
370 strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
371 if (parent)
372 device->kobj.parent = &parent->kobj;
373 device->kobj.ktype = &ktype_acpi_ns;
374 device->kobj.kset = &acpi_namespace_kset;
375 err = kobject_register(&device->kobj);
376 if (err < 0)
377 printk(KERN_WARNING "%s: kobject_register error: %d\n",
378 __FUNCTION__, err);
379 create_sysfs_device_files(device);
380}
381
382static void acpi_device_unregister(struct acpi_device *device, int type)
383{
384 spin_lock(&acpi_device_lock);
385 if (device->parent) {
386 list_del(&device->node);
387 list_del(&device->g_list);
388 } else
389 list_del(&device->g_list);
390
391 list_del(&device->wakeup_list);
392
393 spin_unlock(&acpi_device_lock);
394
395 acpi_detach_data(device->handle, acpi_bus_data_handler);
396 remove_sysfs_device_files(device);
397 kobject_unregister(&device->kobj);
398}
399
400/* --------------------------------------------------------------------------
401 Driver Management
402 -------------------------------------------------------------------------- */
403static LIST_HEAD(acpi_bus_drivers);
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405/**
Randy Dunlapd758a8f2006-01-06 01:31:00 -0500406 * acpi_bus_driver_init - add a device to a driver
407 * @device: the device to add and initialize
408 * @driver: driver for the device
409 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 * Used to initialize a device via its device driver. Called whenever a
411 * driver is bound to a device. Invokes the driver's add() and start() ops.
412 */
413static int
Len Brown4be44fc2005-08-05 00:44:28 -0400414acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Len Brown4be44fc2005-08-05 00:44:28 -0400416 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419 if (!device || !driver)
Patrick Mocheld550d982006-06-27 00:41:40 -0400420 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 if (!driver->ops.add)
Patrick Mocheld550d982006-06-27 00:41:40 -0400423 return -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 result = driver->ops.add(device);
426 if (result) {
427 device->driver = NULL;
428 acpi_driver_data(device) = NULL;
Patrick Mocheld550d982006-06-27 00:41:40 -0400429 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
432 device->driver = driver;
433
434 /*
435 * TBD - Configuration Management: Assign resources to device based
436 * upon possible configuration and currently allocated resources.
437 */
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
440 "Driver successfully bound to device\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400441 return 0;
Rajesh Shah3fb02732005-04-28 00:25:52 -0700442}
443
Adrian Bunk8713cbe2005-09-02 17:16:48 -0400444static int acpi_start_single_object(struct acpi_device *device)
Rajesh Shah3fb02732005-04-28 00:25:52 -0700445{
446 int result = 0;
447 struct acpi_driver *driver;
448
Rajesh Shah3fb02732005-04-28 00:25:52 -0700449
450 if (!(driver = device->driver))
Patrick Mocheld550d982006-06-27 00:41:40 -0400451 return 0;
Rajesh Shah3fb02732005-04-28 00:25:52 -0700452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (driver->ops.start) {
454 result = driver->ops.start(device);
455 if (result && driver->ops.remove)
456 driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
Patrick Mocheld550d982006-06-27 00:41:40 -0400459 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
461
Bjorn Helgaas9d9f7492006-03-28 17:04:00 -0500462static void acpi_driver_attach(struct acpi_driver *drv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Len Brown4be44fc2005-08-05 00:44:28 -0400464 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 spin_lock(&acpi_device_lock);
468 list_for_each_safe(node, next, &acpi_device_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400469 struct acpi_device *dev =
470 container_of(node, struct acpi_device, g_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 if (dev->driver || !dev->status.present)
473 continue;
474 spin_unlock(&acpi_device_lock);
475
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800476 if (!acpi_bus_match(&(dev->dev), &(drv->drv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (!acpi_bus_driver_init(dev, drv)) {
Rajesh Shah3fb02732005-04-28 00:25:52 -0700478 acpi_start_single_object(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 atomic_inc(&drv->references);
Len Brown4be44fc2005-08-05 00:44:28 -0400480 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
481 "Found driver [%s] for device [%s]\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 drv->name, dev->pnp.bus_id));
483 }
484 }
485 spin_lock(&acpi_device_lock);
486 }
487 spin_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488}
489
Bjorn Helgaas06ea8e082006-04-27 05:25:00 -0400490static void acpi_driver_detach(struct acpi_driver *drv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Len Brown4be44fc2005-08-05 00:44:28 -0400492 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 spin_lock(&acpi_device_lock);
Len Brown4be44fc2005-08-05 00:44:28 -0400496 list_for_each_safe(node, next, &acpi_device_list) {
497 struct acpi_device *dev =
498 container_of(node, struct acpi_device, g_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 if (dev->driver == drv) {
501 spin_unlock(&acpi_device_lock);
502 if (drv->ops.remove)
Len Brown4be44fc2005-08-05 00:44:28 -0400503 drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 spin_lock(&acpi_device_lock);
505 dev->driver = NULL;
506 dev->driver_data = NULL;
507 atomic_dec(&drv->references);
508 }
509 }
510 spin_unlock(&acpi_device_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
513/**
Randy Dunlapd758a8f2006-01-06 01:31:00 -0500514 * acpi_bus_register_driver - register a driver with the ACPI bus
515 * @driver: driver being registered
516 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 * Registers a driver with the ACPI bus. Searches the namespace for all
Bjorn Helgaas9d9f7492006-03-28 17:04:00 -0500518 * devices that match the driver's criteria and binds. Returns zero for
519 * success or a negative error status for failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 */
Len Brown4be44fc2005-08-05 00:44:28 -0400521int acpi_bus_register_driver(struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -0400525 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 spin_lock(&acpi_device_lock);
528 list_add_tail(&driver->node, &acpi_bus_drivers);
529 spin_unlock(&acpi_device_lock);
Bjorn Helgaas9d9f7492006-03-28 17:04:00 -0500530 acpi_driver_attach(driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Patrick Mocheld550d982006-06-27 00:41:40 -0400532 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Len Brown4be44fc2005-08-05 00:44:28 -0400535EXPORT_SYMBOL(acpi_bus_register_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537/**
Randy Dunlapd758a8f2006-01-06 01:31:00 -0500538 * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
539 * @driver: driver to unregister
540 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 * Unregisters a driver with the ACPI bus. Searches the namespace for all
542 * devices that match the driver's criteria and unbinds.
543 */
Bjorn Helgaas06ea8e082006-04-27 05:25:00 -0400544void acpi_bus_unregister_driver(struct acpi_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Bjorn Helgaas1a365612006-03-28 17:04:00 -0500546 acpi_driver_detach(driver);
547
548 if (!atomic_read(&driver->references)) {
549 spin_lock(&acpi_device_lock);
550 list_del_init(&driver->node);
551 spin_unlock(&acpi_device_lock);
552 }
Bjorn Helgaas06ea8e082006-04-27 05:25:00 -0400553 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
Len Brown4be44fc2005-08-05 00:44:28 -0400555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556EXPORT_SYMBOL(acpi_bus_unregister_driver);
557
558/**
Randy Dunlapd758a8f2006-01-06 01:31:00 -0500559 * acpi_bus_find_driver - check if there is a driver installed for the device
560 * @device: device that we are trying to find a supporting driver for
561 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 * Parses the list of registered drivers looking for a driver applicable for
563 * the specified device.
564 */
Len Brown4be44fc2005-08-05 00:44:28 -0400565static int acpi_bus_find_driver(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Len Brown4be44fc2005-08-05 00:44:28 -0400567 int result = 0;
568 struct list_head *node, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 spin_lock(&acpi_device_lock);
Len Brown4be44fc2005-08-05 00:44:28 -0400572 list_for_each_safe(node, next, &acpi_bus_drivers) {
573 struct acpi_driver *driver =
574 container_of(node, struct acpi_driver, node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 atomic_inc(&driver->references);
577 spin_unlock(&acpi_device_lock);
Patrick Mochel5d9464a2006-12-07 20:56:27 +0800578 if (!acpi_bus_match(&(device->dev), &(driver->drv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 result = acpi_bus_driver_init(device, driver);
580 if (!result)
581 goto Done;
582 }
583 atomic_dec(&driver->references);
584 spin_lock(&acpi_device_lock);
585 }
586 spin_unlock(&acpi_device_lock);
587
Len Brown4be44fc2005-08-05 00:44:28 -0400588 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -0400589 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/* --------------------------------------------------------------------------
593 Device Enumeration
594 -------------------------------------------------------------------------- */
Len Brownc8f7a622006-07-09 17:22:28 -0400595acpi_status
596acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
597{
598 acpi_status status;
599 acpi_handle tmp;
600 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
601 union acpi_object *obj;
602
603 status = acpi_get_handle(handle, "_EJD", &tmp);
604 if (ACPI_FAILURE(status))
605 return status;
606
607 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
608 if (ACPI_SUCCESS(status)) {
609 obj = buffer.pointer;
610 status = acpi_get_handle(NULL, obj->string.pointer, ejd);
611 kfree(buffer.pointer);
612 }
613 return status;
614}
615EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
616
Zhang Rui9e89dde2006-12-07 20:56:16 +0800617void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
618{
619
620 /* TBD */
621
622 return;
623}
624
625int acpi_match_ids(struct acpi_device *device, char *ids)
626{
627 if (device->flags.hardware_id)
628 if (strstr(ids, device->pnp.hardware_id))
629 return 0;
630
631 if (device->flags.compatible_ids) {
632 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
633 int i;
634
635 /* compare multiple _CID entries against driver ids */
636 for (i = 0; i < cid_list->count; i++) {
637 if (strstr(ids, cid_list->id[i].value))
638 return 0;
639 }
640 }
641 return -ENOENT;
642}
643
644static int acpi_bus_get_perf_flags(struct acpi_device *device)
645{
646 device->performance.state = ACPI_STATE_UNKNOWN;
647 return 0;
648}
649
650static acpi_status
651acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
652 union acpi_object *package)
653{
654 int i = 0;
655 union acpi_object *element = NULL;
656
657 if (!device || !package || (package->package.count < 2))
658 return AE_BAD_PARAMETER;
659
660 element = &(package->package.elements[0]);
661 if (!element)
662 return AE_BAD_PARAMETER;
663 if (element->type == ACPI_TYPE_PACKAGE) {
664 if ((element->package.count < 2) ||
665 (element->package.elements[0].type !=
666 ACPI_TYPE_LOCAL_REFERENCE)
667 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
668 return AE_BAD_DATA;
669 device->wakeup.gpe_device =
670 element->package.elements[0].reference.handle;
671 device->wakeup.gpe_number =
672 (u32) element->package.elements[1].integer.value;
673 } else if (element->type == ACPI_TYPE_INTEGER) {
674 device->wakeup.gpe_number = element->integer.value;
675 } else
676 return AE_BAD_DATA;
677
678 element = &(package->package.elements[1]);
679 if (element->type != ACPI_TYPE_INTEGER) {
680 return AE_BAD_DATA;
681 }
682 device->wakeup.sleep_state = element->integer.value;
683
684 if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
685 return AE_NO_MEMORY;
686 }
687 device->wakeup.resources.count = package->package.count - 2;
688 for (i = 0; i < device->wakeup.resources.count; i++) {
689 element = &(package->package.elements[i + 2]);
690 if (element->type != ACPI_TYPE_ANY) {
691 return AE_BAD_DATA;
692 }
693
694 device->wakeup.resources.handles[i] = element->reference.handle;
695 }
696
697 return AE_OK;
698}
699
700static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
701{
702 acpi_status status = 0;
703 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
704 union acpi_object *package = NULL;
705
706
707 /* _PRW */
708 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
709 if (ACPI_FAILURE(status)) {
710 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
711 goto end;
712 }
713
714 package = (union acpi_object *)buffer.pointer;
715 status = acpi_bus_extract_wakeup_device_power_package(device, package);
716 if (ACPI_FAILURE(status)) {
717 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
718 goto end;
719 }
720
721 kfree(buffer.pointer);
722
723 device->wakeup.flags.valid = 1;
724 /* Power button, Lid switch always enable wakeup */
725 if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
726 device->wakeup.flags.run_wake = 1;
727
728 end:
729 if (ACPI_FAILURE(status))
730 device->flags.wake_capable = 0;
731 return 0;
732}
733
734static int acpi_bus_get_power_flags(struct acpi_device *device)
735{
736 acpi_status status = 0;
737 acpi_handle handle = NULL;
738 u32 i = 0;
739
740
741 /*
742 * Power Management Flags
743 */
744 status = acpi_get_handle(device->handle, "_PSC", &handle);
745 if (ACPI_SUCCESS(status))
746 device->power.flags.explicit_get = 1;
747 status = acpi_get_handle(device->handle, "_IRC", &handle);
748 if (ACPI_SUCCESS(status))
749 device->power.flags.inrush_current = 1;
750
751 /*
752 * Enumerate supported power management states
753 */
754 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
755 struct acpi_device_power_state *ps = &device->power.states[i];
756 char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
757
758 /* Evaluate "_PRx" to se if power resources are referenced */
759 acpi_evaluate_reference(device->handle, object_name, NULL,
760 &ps->resources);
761 if (ps->resources.count) {
762 device->power.flags.power_resources = 1;
763 ps->flags.valid = 1;
764 }
765
766 /* Evaluate "_PSx" to see if we can do explicit sets */
767 object_name[2] = 'S';
768 status = acpi_get_handle(device->handle, object_name, &handle);
769 if (ACPI_SUCCESS(status)) {
770 ps->flags.explicit_set = 1;
771 ps->flags.valid = 1;
772 }
773
774 /* State is valid if we have some power control */
775 if (ps->resources.count || ps->flags.explicit_set)
776 ps->flags.valid = 1;
777
778 ps->power = -1; /* Unknown - driver assigned */
779 ps->latency = -1; /* Unknown - driver assigned */
780 }
781
782 /* Set defaults for D0 and D3 states (always valid) */
783 device->power.states[ACPI_STATE_D0].flags.valid = 1;
784 device->power.states[ACPI_STATE_D0].power = 100;
785 device->power.states[ACPI_STATE_D3].flags.valid = 1;
786 device->power.states[ACPI_STATE_D3].power = 0;
787
788 /* TBD: System wake support and resource requirements. */
789
790 device->power.state = ACPI_STATE_UNKNOWN;
791
792 return 0;
793}
Len Brownc8f7a622006-07-09 17:22:28 -0400794
Len Brown4be44fc2005-08-05 00:44:28 -0400795static int acpi_bus_get_flags(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Len Brown4be44fc2005-08-05 00:44:28 -0400797 acpi_status status = AE_OK;
798 acpi_handle temp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 /* Presence of _STA indicates 'dynamic_status' */
802 status = acpi_get_handle(device->handle, "_STA", &temp);
803 if (ACPI_SUCCESS(status))
804 device->flags.dynamic_status = 1;
805
806 /* Presence of _CID indicates 'compatible_ids' */
807 status = acpi_get_handle(device->handle, "_CID", &temp);
808 if (ACPI_SUCCESS(status))
809 device->flags.compatible_ids = 1;
810
811 /* Presence of _RMV indicates 'removable' */
812 status = acpi_get_handle(device->handle, "_RMV", &temp);
813 if (ACPI_SUCCESS(status))
814 device->flags.removable = 1;
815
816 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
817 status = acpi_get_handle(device->handle, "_EJD", &temp);
818 if (ACPI_SUCCESS(status))
819 device->flags.ejectable = 1;
820 else {
821 status = acpi_get_handle(device->handle, "_EJ0", &temp);
822 if (ACPI_SUCCESS(status))
823 device->flags.ejectable = 1;
824 }
825
826 /* Presence of _LCK indicates 'lockable' */
827 status = acpi_get_handle(device->handle, "_LCK", &temp);
828 if (ACPI_SUCCESS(status))
829 device->flags.lockable = 1;
830
831 /* Presence of _PS0|_PR0 indicates 'power manageable' */
832 status = acpi_get_handle(device->handle, "_PS0", &temp);
833 if (ACPI_FAILURE(status))
834 status = acpi_get_handle(device->handle, "_PR0", &temp);
835 if (ACPI_SUCCESS(status))
836 device->flags.power_manageable = 1;
837
838 /* Presence of _PRW indicates wake capable */
839 status = acpi_get_handle(device->handle, "_PRW", &temp);
840 if (ACPI_SUCCESS(status))
841 device->flags.wake_capable = 1;
842
843 /* TBD: Peformance management */
844
Patrick Mocheld550d982006-06-27 00:41:40 -0400845 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Len Brown4be44fc2005-08-05 00:44:28 -0400848static void acpi_device_get_busid(struct acpi_device *device,
849 acpi_handle handle, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Len Brown4be44fc2005-08-05 00:44:28 -0400851 char bus_id[5] = { '?', 0 };
852 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
853 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 /*
856 * Bus ID
857 * ------
858 * The device's Bus ID is simply the object name.
859 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
860 */
861 switch (type) {
862 case ACPI_BUS_TYPE_SYSTEM:
863 strcpy(device->pnp.bus_id, "ACPI");
864 break;
865 case ACPI_BUS_TYPE_POWER_BUTTON:
866 strcpy(device->pnp.bus_id, "PWRF");
867 break;
868 case ACPI_BUS_TYPE_SLEEP_BUTTON:
869 strcpy(device->pnp.bus_id, "SLPF");
870 break;
871 default:
872 acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
873 /* Clean up trailing underscores (if any) */
874 for (i = 3; i > 1; i--) {
875 if (bus_id[i] == '_')
876 bus_id[i] = '\0';
877 else
878 break;
879 }
880 strcpy(device->pnp.bus_id, bus_id);
881 break;
882 }
883}
884
Len Brown4be44fc2005-08-05 00:44:28 -0400885static void acpi_device_set_id(struct acpi_device *device,
886 struct acpi_device *parent, acpi_handle handle,
887 int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
Len Brown4be44fc2005-08-05 00:44:28 -0400889 struct acpi_device_info *info;
890 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
891 char *hid = NULL;
892 char *uid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 struct acpi_compatible_id_list *cid_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400894 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 switch (type) {
897 case ACPI_BUS_TYPE_DEVICE:
898 status = acpi_get_object_info(handle, &buffer);
899 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400900 printk("%s: Error reading device info\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 return;
902 }
903
904 info = buffer.pointer;
905 if (info->valid & ACPI_VALID_HID)
906 hid = info->hardware_id.value;
907 if (info->valid & ACPI_VALID_UID)
908 uid = info->unique_id.value;
909 if (info->valid & ACPI_VALID_CID)
910 cid_list = &info->compatibility_id;
911 if (info->valid & ACPI_VALID_ADR) {
912 device->pnp.bus_address = info->address;
913 device->flags.bus_address = 1;
914 }
915 break;
916 case ACPI_BUS_TYPE_POWER:
917 hid = ACPI_POWER_HID;
918 break;
919 case ACPI_BUS_TYPE_PROCESSOR:
920 hid = ACPI_PROCESSOR_HID;
921 break;
922 case ACPI_BUS_TYPE_SYSTEM:
923 hid = ACPI_SYSTEM_HID;
924 break;
925 case ACPI_BUS_TYPE_THERMAL:
926 hid = ACPI_THERMAL_HID;
927 break;
928 case ACPI_BUS_TYPE_POWER_BUTTON:
929 hid = ACPI_BUTTON_HID_POWERF;
930 break;
931 case ACPI_BUS_TYPE_SLEEP_BUTTON:
932 hid = ACPI_BUTTON_HID_SLEEPF;
933 break;
934 }
935
936 /*
937 * \_SB
938 * ----
939 * Fix for the system root bus device -- the only root-level device.
940 */
Bob Moorec51a4de2005-11-17 13:07:00 -0500941 if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 hid = ACPI_BUS_HID;
943 strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
944 strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
945 }
946
947 if (hid) {
948 strcpy(device->pnp.hardware_id, hid);
949 device->flags.hardware_id = 1;
950 }
951 if (uid) {
952 strcpy(device->pnp.unique_id, uid);
953 device->flags.unique_id = 1;
954 }
955 if (cid_list) {
956 device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
957 if (device->pnp.cid_list)
958 memcpy(device->pnp.cid_list, cid_list, cid_list->size);
959 else
960 printk(KERN_ERR "Memory allocation error\n");
961 }
962
Len Brown02438d82006-06-30 03:19:10 -0400963 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964}
965
Len Brown4be44fc2005-08-05 00:44:28 -0400966static int acpi_device_set_context(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
968 acpi_status status = AE_OK;
969 int result = 0;
970 /*
971 * Context
972 * -------
973 * Attach this 'struct acpi_device' to the ACPI object. This makes
974 * resolutions from handle->device very efficient. Note that we need
975 * to be careful with fixed-feature devices as they all attach to the
976 * root object.
977 */
Len Brown4be44fc2005-08-05 00:44:28 -0400978 if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
980 status = acpi_attach_data(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400981 acpi_bus_data_handler, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (ACPI_FAILURE(status)) {
984 printk("Error attaching device data\n");
985 result = -ENODEV;
986 }
987 }
988 return result;
989}
990
Len Brown4be44fc2005-08-05 00:44:28 -0400991static void acpi_device_get_debug_info(struct acpi_device *device,
992 acpi_handle handle, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994#ifdef CONFIG_ACPI_DEBUG_OUTPUT
Len Brown4be44fc2005-08-05 00:44:28 -0400995 char *type_string = NULL;
996 char name[80] = { '?', '\0' };
997 struct acpi_buffer buffer = { sizeof(name), name };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 switch (type) {
1000 case ACPI_BUS_TYPE_DEVICE:
1001 type_string = "Device";
1002 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1003 break;
1004 case ACPI_BUS_TYPE_POWER:
1005 type_string = "Power Resource";
1006 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1007 break;
1008 case ACPI_BUS_TYPE_PROCESSOR:
1009 type_string = "Processor";
1010 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1011 break;
1012 case ACPI_BUS_TYPE_SYSTEM:
1013 type_string = "System";
1014 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1015 break;
1016 case ACPI_BUS_TYPE_THERMAL:
1017 type_string = "Thermal Zone";
1018 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1019 break;
1020 case ACPI_BUS_TYPE_POWER_BUTTON:
1021 type_string = "Power Button";
1022 sprintf(name, "PWRB");
1023 break;
1024 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1025 type_string = "Sleep Button";
1026 sprintf(name, "SLPB");
1027 break;
1028 }
1029
1030 printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
Len Brown4be44fc2005-08-05 00:44:28 -04001031#endif /*CONFIG_ACPI_DEBUG_OUTPUT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Len Brown4be44fc2005-08-05 00:44:28 -04001034static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
Len Brown4be44fc2005-08-05 00:44:28 -04001036 int result = 0;
1037 struct acpi_driver *driver;
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040 if (!dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001041 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 driver = dev->driver;
1044
1045 if ((driver) && (driver->ops.remove)) {
1046
1047 if (driver->ops.stop) {
1048 result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
1049 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001050 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052
1053 result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
1054 if (result) {
Patrick Mocheld550d982006-06-27 00:41:40 -04001055 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057
1058 atomic_dec(&dev->driver->references);
1059 dev->driver = NULL;
1060 acpi_driver_data(dev) = NULL;
1061 }
1062
1063 if (!rmdevice)
Patrick Mocheld550d982006-06-27 00:41:40 -04001064 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 if (dev->flags.bus_address) {
1067 if ((dev->parent) && (dev->parent->ops.unbind))
1068 dev->parent->ops.unbind(dev);
1069 }
Len Brown4be44fc2005-08-05 00:44:28 -04001070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
1072
Patrick Mocheld550d982006-06-27 00:41:40 -04001073 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074}
1075
Rajesh Shah3fb02732005-04-28 00:25:52 -07001076static int
Len Brown4be44fc2005-08-05 00:44:28 -04001077acpi_add_single_object(struct acpi_device **child,
1078 struct acpi_device *parent, acpi_handle handle, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079{
Len Brown4be44fc2005-08-05 00:44:28 -04001080 int result = 0;
1081 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 if (!child)
Patrick Mocheld550d982006-06-27 00:41:40 -04001085 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
1088 if (!device) {
Len Brown64684632006-06-26 23:41:38 -04001089 printk(KERN_ERR PREFIX "Memory allocation error\n");
Patrick Mocheld550d982006-06-27 00:41:40 -04001090 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092 memset(device, 0, sizeof(struct acpi_device));
1093
1094 device->handle = handle;
1095 device->parent = parent;
1096
Len Brown4be44fc2005-08-05 00:44:28 -04001097 acpi_device_get_busid(device, handle, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 /*
1100 * Flags
1101 * -----
1102 * Get prior to calling acpi_bus_get_status() so we know whether
1103 * or not _STA is present. Note that we only look for object
1104 * handles -- cannot evaluate objects until we know the device is
1105 * present and properly initialized.
1106 */
1107 result = acpi_bus_get_flags(device);
1108 if (result)
1109 goto end;
1110
1111 /*
1112 * Status
1113 * ------
Keiichiro Tokunaga6940fab2005-03-30 23:15:47 -05001114 * See if the device is present. We always assume that non-Device
1115 * and non-Processor objects (e.g. thermal zones, power resources,
1116 * etc.) are present, functioning, etc. (at least when parent object
1117 * is present). Note that _STA has a different meaning for some
1118 * objects (e.g. power resources) so we need to be careful how we use
1119 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 */
1121 switch (type) {
Keiichiro Tokunaga6940fab2005-03-30 23:15:47 -05001122 case ACPI_BUS_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 case ACPI_BUS_TYPE_DEVICE:
1124 result = acpi_bus_get_status(device);
1125 if (ACPI_FAILURE(result) || !device->status.present) {
1126 result = -ENOENT;
1127 goto end;
1128 }
1129 break;
1130 default:
1131 STRUCT_TO_INT(device->status) = 0x0F;
1132 break;
1133 }
1134
1135 /*
1136 * Initialize Device
1137 * -----------------
1138 * TBD: Synch with Core's enumeration/initialization process.
1139 */
1140
1141 /*
1142 * Hardware ID, Unique ID, & Bus Address
1143 * -------------------------------------
1144 */
Len Brown4be44fc2005-08-05 00:44:28 -04001145 acpi_device_set_id(device, parent, handle, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 /*
1148 * Power Management
1149 * ----------------
1150 */
1151 if (device->flags.power_manageable) {
1152 result = acpi_bus_get_power_flags(device);
1153 if (result)
1154 goto end;
1155 }
1156
Len Brown4be44fc2005-08-05 00:44:28 -04001157 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 * Wakeup device management
1159 *-----------------------
1160 */
1161 if (device->flags.wake_capable) {
1162 result = acpi_bus_get_wakeup_device_flags(device);
1163 if (result)
1164 goto end;
1165 }
1166
1167 /*
1168 * Performance Management
1169 * ----------------------
1170 */
1171 if (device->flags.performance_manageable) {
1172 result = acpi_bus_get_perf_flags(device);
1173 if (result)
1174 goto end;
1175 }
1176
Len Brown4be44fc2005-08-05 00:44:28 -04001177 if ((result = acpi_device_set_context(device, type)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 goto end;
1179
Len Brown4be44fc2005-08-05 00:44:28 -04001180 acpi_device_get_debug_info(device, handle, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
Len Brown4be44fc2005-08-05 00:44:28 -04001182 acpi_device_register(device, parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 /*
1185 * Bind _ADR-Based Devices
1186 * -----------------------
1187 * If there's a a bus address (_ADR) then we utilize the parent's
1188 * 'bind' function (if exists) to bind the ACPI- and natively-
1189 * enumerated device representations.
1190 */
1191 if (device->flags.bus_address) {
1192 if (device->parent && device->parent->ops.bind)
1193 device->parent->ops.bind(device);
1194 }
1195
1196 /*
1197 * Locate & Attach Driver
1198 * ----------------------
1199 * If there's a hardware id (_HID) or compatible ids (_CID) we check
1200 * to see if there's a driver installed for this kind of device. Note
1201 * that drivers can install before or after a device is enumerated.
1202 *
1203 * TBD: Assumes LDM provides driver hot-plug capability.
1204 */
Thomas Renningerbd7ce5b2005-10-03 10:39:00 -07001205 acpi_bus_find_driver(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Len Brown4be44fc2005-08-05 00:44:28 -04001207 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 if (!result)
1209 *child = device;
1210 else {
Jesper Juhl6044ec82005-11-07 01:01:32 -08001211 kfree(device->pnp.cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 kfree(device);
1213 }
1214
Patrick Mocheld550d982006-06-27 00:41:40 -04001215 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Len Brown4be44fc2005-08-05 00:44:28 -04001218static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
Len Brown4be44fc2005-08-05 00:44:28 -04001220 acpi_status status = AE_OK;
1221 struct acpi_device *parent = NULL;
1222 struct acpi_device *child = NULL;
1223 acpi_handle phandle = NULL;
1224 acpi_handle chandle = NULL;
1225 acpi_object_type type = 0;
1226 u32 level = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 if (!start)
Patrick Mocheld550d982006-06-27 00:41:40 -04001230 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 parent = start;
1233 phandle = start->handle;
Len Brown4be44fc2005-08-05 00:44:28 -04001234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 /*
1236 * Parse through the ACPI namespace, identify all 'devices', and
1237 * create a new 'struct acpi_device' for each.
1238 */
1239 while ((level > 0) && parent) {
1240
1241 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
Len Brown4be44fc2005-08-05 00:44:28 -04001242 chandle, &chandle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /*
1245 * If this scope is exhausted then move our way back up.
1246 */
1247 if (ACPI_FAILURE(status)) {
1248 level--;
1249 chandle = phandle;
1250 acpi_get_parent(phandle, &phandle);
1251 if (parent->parent)
1252 parent = parent->parent;
1253 continue;
1254 }
1255
1256 status = acpi_get_type(chandle, &type);
1257 if (ACPI_FAILURE(status))
1258 continue;
1259
1260 /*
1261 * If this is a scope object then parse it (depth-first).
1262 */
1263 if (type == ACPI_TYPE_LOCAL_SCOPE) {
1264 level++;
1265 phandle = chandle;
1266 chandle = NULL;
1267 continue;
1268 }
1269
1270 /*
1271 * We're only interested in objects that we consider 'devices'.
1272 */
1273 switch (type) {
1274 case ACPI_TYPE_DEVICE:
1275 type = ACPI_BUS_TYPE_DEVICE;
1276 break;
1277 case ACPI_TYPE_PROCESSOR:
1278 type = ACPI_BUS_TYPE_PROCESSOR;
1279 break;
1280 case ACPI_TYPE_THERMAL:
1281 type = ACPI_BUS_TYPE_THERMAL;
1282 break;
1283 case ACPI_TYPE_POWER:
1284 type = ACPI_BUS_TYPE_POWER;
1285 break;
1286 default:
1287 continue;
1288 }
1289
Rajesh Shah3fb02732005-04-28 00:25:52 -07001290 if (ops->acpi_op_add)
1291 status = acpi_add_single_object(&child, parent,
Len Brown4be44fc2005-08-05 00:44:28 -04001292 chandle, type);
1293 else
Rajesh Shah3fb02732005-04-28 00:25:52 -07001294 status = acpi_bus_get_device(chandle, &child);
1295
Len Brown4be44fc2005-08-05 00:44:28 -04001296 if (ACPI_FAILURE(status))
1297 continue;
Rajesh Shah3fb02732005-04-28 00:25:52 -07001298
1299 if (ops->acpi_op_start) {
1300 status = acpi_start_single_object(child);
1301 if (ACPI_FAILURE(status))
1302 continue;
1303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 /*
1306 * If the device is present, enabled, and functioning then
1307 * parse its scope (depth-first). Note that we need to
1308 * represent absent devices to facilitate PnP notifications
1309 * -- but only the subtree head (not all of its children,
1310 * which will be enumerated when the parent is inserted).
1311 *
1312 * TBD: Need notifications and other detection mechanisms
Len Brown4be44fc2005-08-05 00:44:28 -04001313 * in place before we can fully implement this.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 */
1315 if (child->status.present) {
1316 status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
1317 NULL, NULL);
1318 if (ACPI_SUCCESS(status)) {
1319 level++;
1320 phandle = chandle;
1321 chandle = NULL;
1322 parent = child;
1323 }
1324 }
1325 }
1326
Patrick Mocheld550d982006-06-27 00:41:40 -04001327 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Rajesh Shah3fb02732005-04-28 00:25:52 -07001330int
Len Brown4be44fc2005-08-05 00:44:28 -04001331acpi_bus_add(struct acpi_device **child,
1332 struct acpi_device *parent, acpi_handle handle, int type)
Rajesh Shah3fb02732005-04-28 00:25:52 -07001333{
1334 int result;
1335 struct acpi_bus_ops ops;
1336
Rajesh Shah3fb02732005-04-28 00:25:52 -07001337
1338 result = acpi_add_single_object(child, parent, handle, type);
1339 if (!result) {
1340 memset(&ops, 0, sizeof(ops));
1341 ops.acpi_op_add = 1;
1342 result = acpi_bus_scan(*child, &ops);
1343 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001344 return result;
Rajesh Shah3fb02732005-04-28 00:25:52 -07001345}
Len Brown4be44fc2005-08-05 00:44:28 -04001346
Rajesh Shah3fb02732005-04-28 00:25:52 -07001347EXPORT_SYMBOL(acpi_bus_add);
1348
Len Brown4be44fc2005-08-05 00:44:28 -04001349int acpi_bus_start(struct acpi_device *device)
Rajesh Shah3fb02732005-04-28 00:25:52 -07001350{
1351 int result;
1352 struct acpi_bus_ops ops;
1353
Rajesh Shah3fb02732005-04-28 00:25:52 -07001354
1355 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001356 return -EINVAL;
Rajesh Shah3fb02732005-04-28 00:25:52 -07001357
1358 result = acpi_start_single_object(device);
1359 if (!result) {
1360 memset(&ops, 0, sizeof(ops));
1361 ops.acpi_op_start = 1;
1362 result = acpi_bus_scan(device, &ops);
1363 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001364 return result;
Rajesh Shah3fb02732005-04-28 00:25:52 -07001365}
Len Brown4be44fc2005-08-05 00:44:28 -04001366
Rajesh Shah3fb02732005-04-28 00:25:52 -07001367EXPORT_SYMBOL(acpi_bus_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Kristen Accardiceaba662006-02-23 17:56:01 -08001369int acpi_bus_trim(struct acpi_device *start, int rmdevice)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
Len Brown4be44fc2005-08-05 00:44:28 -04001371 acpi_status status;
1372 struct acpi_device *parent, *child;
1373 acpi_handle phandle, chandle;
1374 acpi_object_type type;
1375 u32 level = 1;
1376 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
Len Brown4be44fc2005-08-05 00:44:28 -04001378 parent = start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 phandle = start->handle;
1380 child = chandle = NULL;
1381
1382 while ((level > 0) && parent && (!err)) {
1383 status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
Len Brown4be44fc2005-08-05 00:44:28 -04001384 chandle, &chandle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 /*
1387 * If this scope is exhausted then move our way back up.
1388 */
1389 if (ACPI_FAILURE(status)) {
1390 level--;
1391 chandle = phandle;
1392 acpi_get_parent(phandle, &phandle);
1393 child = parent;
1394 parent = parent->parent;
1395
1396 if (level == 0)
1397 err = acpi_bus_remove(child, rmdevice);
1398 else
1399 err = acpi_bus_remove(child, 1);
1400
1401 continue;
1402 }
1403
1404 status = acpi_get_type(chandle, &type);
1405 if (ACPI_FAILURE(status)) {
1406 continue;
1407 }
1408 /*
1409 * If there is a device corresponding to chandle then
1410 * parse it (depth-first).
1411 */
1412 if (acpi_bus_get_device(chandle, &child) == 0) {
1413 level++;
1414 phandle = chandle;
1415 chandle = NULL;
1416 parent = child;
1417 }
1418 continue;
1419 }
1420 return err;
1421}
Kristen Accardiceaba662006-02-23 17:56:01 -08001422EXPORT_SYMBOL_GPL(acpi_bus_trim);
1423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Len Brown4be44fc2005-08-05 00:44:28 -04001425static int acpi_bus_scan_fixed(struct acpi_device *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Len Brown4be44fc2005-08-05 00:44:28 -04001427 int result = 0;
1428 struct acpi_device *device = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 if (!root)
Patrick Mocheld550d982006-06-27 00:41:40 -04001432 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 /*
1435 * Enumerate all fixed-feature devices.
1436 */
Rajesh Shah3fb02732005-04-28 00:25:52 -07001437 if (acpi_fadt.pwr_button == 0) {
1438 result = acpi_add_single_object(&device, acpi_root,
Len Brown4be44fc2005-08-05 00:44:28 -04001439 NULL,
1440 ACPI_BUS_TYPE_POWER_BUTTON);
Rajesh Shah3fb02732005-04-28 00:25:52 -07001441 if (!result)
1442 result = acpi_start_single_object(device);
1443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Rajesh Shah3fb02732005-04-28 00:25:52 -07001445 if (acpi_fadt.sleep_button == 0) {
1446 result = acpi_add_single_object(&device, acpi_root,
Len Brown4be44fc2005-08-05 00:44:28 -04001447 NULL,
1448 ACPI_BUS_TYPE_SLEEP_BUTTON);
Rajesh Shah3fb02732005-04-28 00:25:52 -07001449 if (!result)
1450 result = acpi_start_single_object(device);
1451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Patrick Mocheld550d982006-06-27 00:41:40 -04001453 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454}
1455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456static int __init acpi_scan_init(void)
1457{
1458 int result;
Rajesh Shah3fb02732005-04-28 00:25:52 -07001459 struct acpi_bus_ops ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 if (acpi_disabled)
Patrick Mocheld550d982006-06-27 00:41:40 -04001463 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Randy Dunlap9b6d97b2006-07-12 02:08:00 -04001465 result = kset_register(&acpi_namespace_kset);
1466 if (result < 0)
1467 printk(KERN_ERR PREFIX "kset_register error: %d\n", result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Patrick Mochel5b327262006-05-10 10:33:00 -04001469 result = bus_register(&acpi_bus_type);
1470 if (result) {
1471 /* We don't want to quit even if we failed to add suspend/resume */
1472 printk(KERN_ERR PREFIX "Could not register bus type\n");
1473 }
1474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 /*
1476 * Create the root device in the bus's device tree
1477 */
Rajesh Shah3fb02732005-04-28 00:25:52 -07001478 result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -04001479 ACPI_BUS_TYPE_SYSTEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 if (result)
1481 goto Done;
1482
Rajesh Shah3fb02732005-04-28 00:25:52 -07001483 result = acpi_start_single_object(acpi_root);
Patrick Mochel5b327262006-05-10 10:33:00 -04001484 if (result)
1485 goto Done;
1486
1487 acpi_root->dev.bus = &acpi_bus_type;
1488 snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name);
1489 result = device_register(&acpi_root->dev);
1490 if (result) {
1491 /* We don't want to quit even if we failed to add suspend/resume */
1492 printk(KERN_ERR PREFIX "Could not register device\n");
1493 }
Rajesh Shah3fb02732005-04-28 00:25:52 -07001494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 /*
1496 * Enumerate devices in the ACPI namespace.
1497 */
1498 result = acpi_bus_scan_fixed(acpi_root);
Rajesh Shah3fb02732005-04-28 00:25:52 -07001499 if (!result) {
1500 memset(&ops, 0, sizeof(ops));
1501 ops.acpi_op_add = 1;
1502 ops.acpi_op_start = 1;
1503 result = acpi_bus_scan(acpi_root, &ops);
1504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 if (result)
1507 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1508
Len Brown4be44fc2005-08-05 00:44:28 -04001509 Done:
Patrick Mocheld550d982006-06-27 00:41:40 -04001510 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511}
1512
1513subsys_initcall(acpi_scan_init);