Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Dunlap | 9b6d97b | 2006-07-12 02:08:00 -0400 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 14 | ACPI_MODULE_NAME("scan") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #define STRUCT_TO_INT(s) (*((int*)&s)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 16 | extern struct acpi_device *acpi_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 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 | |
| 23 | static LIST_HEAD(acpi_device_list); |
| 24 | DEFINE_SPINLOCK(acpi_device_lock); |
| 25 | LIST_HEAD(acpi_wakeup_device_list); |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 28 | static void acpi_device_release(struct kobject *kobj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 30 | struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj); |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 31 | kfree(dev->pnp.cid_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | kfree(dev); |
| 33 | } |
| 34 | |
| 35 | struct acpi_device_attribute { |
| 36 | struct attribute attr; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 37 | ssize_t(*show) (struct acpi_device *, char *); |
| 38 | ssize_t(*store) (struct acpi_device *, const char *, size_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | typedef void acpi_device_sysfs_files(struct kobject *, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 42 | const struct attribute *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | static void setup_sys_fs_device_files(struct acpi_device *dev, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 45 | acpi_device_sysfs_files * func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define to_acpi_device(n) container_of(n, struct acpi_device, kobj) |
| 53 | #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr); |
| 54 | |
| 55 | static ssize_t acpi_device_attr_show(struct kobject *kobj, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | struct attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
| 58 | struct acpi_device *device = to_acpi_device(kobj); |
| 59 | struct acpi_device_attribute *attribute = to_handle_attr(attr); |
Dmitry Torokhov | 70f2817 | 2005-04-29 01:27:34 -0500 | [diff] [blame] | 60 | return attribute->show ? attribute->show(device, buf) : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | static ssize_t acpi_device_attr_store(struct kobject *kobj, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | struct attribute *attr, const char *buf, |
| 64 | size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | struct acpi_device *device = to_acpi_device(kobj); |
| 67 | struct acpi_device_attribute *attribute = to_handle_attr(attr); |
Dmitry Torokhov | 70f2817 | 2005-04-29 01:27:34 -0500 | [diff] [blame] | 68 | return attribute->store ? attribute->store(device, buf, len) : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static struct sysfs_ops acpi_device_sysfs_ops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | .show = acpi_device_attr_show, |
| 73 | .store = acpi_device_attr_store, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static struct kobj_type ktype_acpi_ns = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | .sysfs_ops = &acpi_device_sysfs_ops, |
| 78 | .release = acpi_device_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 81 | static int namespace_uevent(struct kset *kset, struct kobject *kobj, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | char **envp, int num_envp, char *buffer, |
| 83 | int buffer_size) |
| 84 | { |
| 85 | struct acpi_device *dev = to_acpi_device(kobj); |
| 86 | int i = 0; |
| 87 | int len = 0; |
| 88 | |
| 89 | if (!dev->driver) |
| 90 | return 0; |
| 91 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 92 | if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, |
| 93 | "PHYSDEVDRIVER=%s", dev->driver->name)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return -ENOMEM; |
| 95 | |
| 96 | envp[i] = NULL; |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 101 | static struct kset_uevent_ops namespace_uevent_ops = { |
| 102 | .uevent = &namespace_uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static struct kset acpi_namespace_kset = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | .kobj = { |
| 107 | .name = "namespace", |
| 108 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | .subsys = &acpi_subsys, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 110 | .ktype = &ktype_acpi_ns, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 111 | .uevent_ops = &namespace_uevent_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* -------------------------------------------------------------------------- |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 115 | ACPI sysfs device file support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | -------------------------------------------------------------------------- */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | static ssize_t acpi_eject_store(struct acpi_device *device, |
| 118 | const char *buf, size_t count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | #define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \ |
| 121 | static struct acpi_device_attribute acpi_device_attr_##_name = \ |
| 122 | __ATTR(_name, _mode, _show, _store) |
| 123 | |
| 124 | ACPI_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 Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 128 | * @dev: acpi_device object |
| 129 | * @func: function pointer to create or destroy the device file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | */ |
| 131 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | setup_sys_fs_device_files(struct acpi_device *dev, |
| 133 | acpi_device_sysfs_files * func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | acpi_status status; |
| 136 | acpi_handle temp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | static int acpi_eject_operation(acpi_handle handle, int lockable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | return (-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | static ssize_t |
| 183 | acpi_eject_store(struct acpi_device *device, const char *buf, size_t count) |
| 184 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | int result; |
| 186 | int ret = count; |
| 187 | int islockable; |
| 188 | acpi_status status; |
| 189 | acpi_handle handle; |
| 190 | acpi_object_type type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | if ((!count) || (buf[0] != '1')) { |
| 193 | return -EINVAL; |
| 194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | if (ACPI_FAILURE(status) || (!device->flags.ejectable)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | ret = -ENODEV; |
| 204 | goto err; |
| 205 | } |
| 206 | |
| 207 | islockable = device->flags.lockable; |
| 208 | handle = device->handle; |
| 209 | |
Ashok Raj | eefa27a | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 210 | result = acpi_bus_trim(device, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | if (!result) |
| 213 | result = acpi_eject_operation(handle, islockable); |
| 214 | |
| 215 | if (result) { |
| 216 | ret = -EBUSY; |
| 217 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | return ret; |
| 220 | } |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /* -------------------------------------------------------------------------- |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 223 | ACPI Bus operations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | -------------------------------------------------------------------------- */ |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 225 | static inline struct acpi_device * to_acpi_dev(struct device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 227 | return container_of(dev, struct acpi_device, dev); |
| 228 | } |
| 229 | |
| 230 | static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state) |
| 231 | { |
| 232 | struct acpi_device * dev, * next; |
| 233 | int result; |
| 234 | |
| 235 | spin_lock(&acpi_device_lock); |
| 236 | list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) { |
| 237 | if (dev->driver && dev->driver->ops.suspend) { |
| 238 | spin_unlock(&acpi_device_lock); |
| 239 | result = dev->driver->ops.suspend(dev, 0); |
| 240 | if (result) { |
| 241 | printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n", |
| 242 | acpi_device_name(dev), |
| 243 | acpi_device_bid(dev), result); |
| 244 | } |
| 245 | spin_lock(&acpi_device_lock); |
| 246 | } |
| 247 | } |
| 248 | spin_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 252 | static int acpi_device_suspend(struct device * dev, pm_message_t state) |
| 253 | { |
| 254 | struct acpi_device * acpi_dev = to_acpi_dev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 256 | /* |
| 257 | * For now, we should only register 1 generic device - |
| 258 | * the ACPI root device - and from there, we walk the |
| 259 | * tree of ACPI devices to suspend each one using the |
| 260 | * ACPI driver methods. |
| 261 | */ |
| 262 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) |
| 263 | root_suspend(acpi_dev, state); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int root_resume(struct acpi_device * acpi_dev) |
| 268 | { |
| 269 | struct acpi_device * dev, * next; |
| 270 | int result; |
| 271 | |
| 272 | spin_lock(&acpi_device_lock); |
| 273 | list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) { |
| 274 | if (dev->driver && dev->driver->ops.resume) { |
| 275 | spin_unlock(&acpi_device_lock); |
| 276 | result = dev->driver->ops.resume(dev, 0); |
| 277 | if (result) { |
| 278 | printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n", |
| 279 | acpi_device_name(dev), |
| 280 | acpi_device_bid(dev), result); |
| 281 | } |
| 282 | spin_lock(&acpi_device_lock); |
| 283 | } |
| 284 | } |
| 285 | spin_unlock(&acpi_device_lock); |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int acpi_device_resume(struct device * dev) |
| 290 | { |
| 291 | struct acpi_device * acpi_dev = to_acpi_dev(dev); |
| 292 | |
| 293 | /* |
| 294 | * For now, we should only register 1 generic device - |
| 295 | * the ACPI root device - and from there, we walk the |
| 296 | * tree of ACPI devices to resume each one using the |
| 297 | * ACPI driver methods. |
| 298 | */ |
| 299 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) |
| 300 | root_resume(acpi_dev); |
| 301 | return 0; |
| 302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 305 | * acpi_bus_match - match device IDs to driver's supported IDs |
| 306 | * @device: the device that we are trying to match to a driver |
| 307 | * @driver: driver whose device id table is being checked |
| 308 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it |
| 310 | * matches the specified driver's criteria. |
| 311 | */ |
| 312 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
| 315 | if (driver && driver->ops.match) |
| 316 | return driver->ops.match(device, driver); |
| 317 | return acpi_match_ids(device, driver->ids); |
| 318 | } |
| 319 | |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 320 | static struct bus_type acpi_bus_type = { |
| 321 | .name = "acpi", |
| 322 | .suspend = acpi_device_suspend, |
| 323 | .resume = acpi_device_resume, |
| 324 | }; |
| 325 | |
| 326 | static void acpi_device_register(struct acpi_device *device, |
| 327 | struct acpi_device *parent) |
| 328 | { |
| 329 | int err; |
| 330 | |
| 331 | /* |
| 332 | * Linkage |
| 333 | * ------- |
| 334 | * Link this device to its parent and siblings. |
| 335 | */ |
| 336 | INIT_LIST_HEAD(&device->children); |
| 337 | INIT_LIST_HEAD(&device->node); |
| 338 | INIT_LIST_HEAD(&device->g_list); |
| 339 | INIT_LIST_HEAD(&device->wakeup_list); |
| 340 | |
| 341 | spin_lock(&acpi_device_lock); |
| 342 | if (device->parent) { |
| 343 | list_add_tail(&device->node, &device->parent->children); |
| 344 | list_add_tail(&device->g_list, &device->parent->g_list); |
| 345 | } else |
| 346 | list_add_tail(&device->g_list, &acpi_device_list); |
| 347 | if (device->wakeup.flags.valid) |
| 348 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); |
| 349 | spin_unlock(&acpi_device_lock); |
| 350 | |
| 351 | strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN); |
| 352 | if (parent) |
| 353 | device->kobj.parent = &parent->kobj; |
| 354 | device->kobj.ktype = &ktype_acpi_ns; |
| 355 | device->kobj.kset = &acpi_namespace_kset; |
| 356 | err = kobject_register(&device->kobj); |
| 357 | if (err < 0) |
| 358 | printk(KERN_WARNING "%s: kobject_register error: %d\n", |
| 359 | __FUNCTION__, err); |
| 360 | create_sysfs_device_files(device); |
| 361 | } |
| 362 | |
| 363 | static void acpi_device_unregister(struct acpi_device *device, int type) |
| 364 | { |
| 365 | spin_lock(&acpi_device_lock); |
| 366 | if (device->parent) { |
| 367 | list_del(&device->node); |
| 368 | list_del(&device->g_list); |
| 369 | } else |
| 370 | list_del(&device->g_list); |
| 371 | |
| 372 | list_del(&device->wakeup_list); |
| 373 | |
| 374 | spin_unlock(&acpi_device_lock); |
| 375 | |
| 376 | acpi_detach_data(device->handle, acpi_bus_data_handler); |
| 377 | remove_sysfs_device_files(device); |
| 378 | kobject_unregister(&device->kobj); |
| 379 | } |
| 380 | |
| 381 | /* -------------------------------------------------------------------------- |
| 382 | Driver Management |
| 383 | -------------------------------------------------------------------------- */ |
| 384 | static LIST_HEAD(acpi_bus_drivers); |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 387 | * acpi_bus_driver_init - add a device to a driver |
| 388 | * @device: the device to add and initialize |
| 389 | * @driver: driver for the device |
| 390 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | * Used to initialize a device via its device driver. Called whenever a |
| 392 | * driver is bound to a device. Invokes the driver's add() and start() ops. |
| 393 | */ |
| 394 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | if (!device || !driver) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 401 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | if (!driver->ops.add) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 404 | return -ENOSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | result = driver->ops.add(device); |
| 407 | if (result) { |
| 408 | device->driver = NULL; |
| 409 | acpi_driver_data(device) = NULL; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 410 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | device->driver = driver; |
| 414 | |
| 415 | /* |
| 416 | * TBD - Configuration Management: Assign resources to device based |
| 417 | * upon possible configuration and currently allocated resources. |
| 418 | */ |
| 419 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 421 | "Driver successfully bound to device\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 422 | return 0; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 425 | static int acpi_start_single_object(struct acpi_device *device) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 426 | { |
| 427 | int result = 0; |
| 428 | struct acpi_driver *driver; |
| 429 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 430 | |
| 431 | if (!(driver = device->driver)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 432 | return 0; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (driver->ops.start) { |
| 435 | result = driver->ops.start(device); |
| 436 | if (result && driver->ops.remove) |
| 437 | driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 440 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 443 | static void acpi_driver_attach(struct acpi_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 445 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | spin_lock(&acpi_device_lock); |
| 449 | list_for_each_safe(node, next, &acpi_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | struct acpi_device *dev = |
| 451 | container_of(node, struct acpi_device, g_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | if (dev->driver || !dev->status.present) |
| 454 | continue; |
| 455 | spin_unlock(&acpi_device_lock); |
| 456 | |
| 457 | if (!acpi_bus_match(dev, drv)) { |
| 458 | if (!acpi_bus_driver_init(dev, drv)) { |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 459 | acpi_start_single_object(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | atomic_inc(&drv->references); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 462 | "Found driver [%s] for device [%s]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | drv->name, dev->pnp.bus_id)); |
| 464 | } |
| 465 | } |
| 466 | spin_lock(&acpi_device_lock); |
| 467 | } |
| 468 | spin_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Bjorn Helgaas | 06ea8e0 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 471 | static void acpi_driver_detach(struct acpi_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | spin_lock(&acpi_device_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | list_for_each_safe(node, next, &acpi_device_list) { |
| 478 | struct acpi_device *dev = |
| 479 | container_of(node, struct acpi_device, g_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | if (dev->driver == drv) { |
| 482 | spin_unlock(&acpi_device_lock); |
| 483 | if (drv->ops.remove) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | spin_lock(&acpi_device_lock); |
| 486 | dev->driver = NULL; |
| 487 | dev->driver_data = NULL; |
| 488 | atomic_dec(&drv->references); |
| 489 | } |
| 490 | } |
| 491 | spin_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 495 | * acpi_bus_register_driver - register a driver with the ACPI bus |
| 496 | * @driver: driver being registered |
| 497 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | * Registers a driver with the ACPI bus. Searches the namespace for all |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 499 | * devices that match the driver's criteria and binds. Returns zero for |
| 500 | * success or a negative error status for failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | int acpi_bus_register_driver(struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 506 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | spin_lock(&acpi_device_lock); |
| 509 | list_add_tail(&driver->node, &acpi_bus_drivers); |
| 510 | spin_unlock(&acpi_device_lock); |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 511 | acpi_driver_attach(driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 513 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | EXPORT_SYMBOL(acpi_bus_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 519 | * acpi_bus_unregister_driver - unregisters a driver with the APIC bus |
| 520 | * @driver: driver to unregister |
| 521 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | * Unregisters a driver with the ACPI bus. Searches the namespace for all |
| 523 | * devices that match the driver's criteria and unbinds. |
| 524 | */ |
Bjorn Helgaas | 06ea8e0 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 525 | void acpi_bus_unregister_driver(struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Bjorn Helgaas | 1a36561 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 527 | acpi_driver_detach(driver); |
| 528 | |
| 529 | if (!atomic_read(&driver->references)) { |
| 530 | spin_lock(&acpi_device_lock); |
| 531 | list_del_init(&driver->node); |
| 532 | spin_unlock(&acpi_device_lock); |
| 533 | } |
Bjorn Helgaas | 06ea8e0 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 534 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | EXPORT_SYMBOL(acpi_bus_unregister_driver); |
| 538 | |
| 539 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 540 | * acpi_bus_find_driver - check if there is a driver installed for the device |
| 541 | * @device: device that we are trying to find a supporting driver for |
| 542 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * Parses the list of registered drivers looking for a driver applicable for |
| 544 | * the specified device. |
| 545 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | static int acpi_bus_find_driver(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | int result = 0; |
| 549 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | spin_lock(&acpi_device_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | list_for_each_safe(node, next, &acpi_bus_drivers) { |
| 554 | struct acpi_driver *driver = |
| 555 | container_of(node, struct acpi_driver, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | atomic_inc(&driver->references); |
| 558 | spin_unlock(&acpi_device_lock); |
| 559 | if (!acpi_bus_match(device, driver)) { |
| 560 | result = acpi_bus_driver_init(device, driver); |
| 561 | if (!result) |
| 562 | goto Done; |
| 563 | } |
| 564 | atomic_dec(&driver->references); |
| 565 | spin_lock(&acpi_device_lock); |
| 566 | } |
| 567 | spin_unlock(&acpi_device_lock); |
| 568 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 570 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* -------------------------------------------------------------------------- |
| 574 | Device Enumeration |
| 575 | -------------------------------------------------------------------------- */ |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 576 | acpi_status |
| 577 | acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd) |
| 578 | { |
| 579 | acpi_status status; |
| 580 | acpi_handle tmp; |
| 581 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 582 | union acpi_object *obj; |
| 583 | |
| 584 | status = acpi_get_handle(handle, "_EJD", &tmp); |
| 585 | if (ACPI_FAILURE(status)) |
| 586 | return status; |
| 587 | |
| 588 | status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer); |
| 589 | if (ACPI_SUCCESS(status)) { |
| 590 | obj = buffer.pointer; |
| 591 | status = acpi_get_handle(NULL, obj->string.pointer, ejd); |
| 592 | kfree(buffer.pointer); |
| 593 | } |
| 594 | return status; |
| 595 | } |
| 596 | EXPORT_SYMBOL_GPL(acpi_bus_get_ejd); |
| 597 | |
Zhang Rui | 9e89dde | 2006-12-07 20:56:16 +0800 | [diff] [blame^] | 598 | void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) |
| 599 | { |
| 600 | |
| 601 | /* TBD */ |
| 602 | |
| 603 | return; |
| 604 | } |
| 605 | |
| 606 | int acpi_match_ids(struct acpi_device *device, char *ids) |
| 607 | { |
| 608 | if (device->flags.hardware_id) |
| 609 | if (strstr(ids, device->pnp.hardware_id)) |
| 610 | return 0; |
| 611 | |
| 612 | if (device->flags.compatible_ids) { |
| 613 | struct acpi_compatible_id_list *cid_list = device->pnp.cid_list; |
| 614 | int i; |
| 615 | |
| 616 | /* compare multiple _CID entries against driver ids */ |
| 617 | for (i = 0; i < cid_list->count; i++) { |
| 618 | if (strstr(ids, cid_list->id[i].value)) |
| 619 | return 0; |
| 620 | } |
| 621 | } |
| 622 | return -ENOENT; |
| 623 | } |
| 624 | |
| 625 | static int acpi_bus_get_perf_flags(struct acpi_device *device) |
| 626 | { |
| 627 | device->performance.state = ACPI_STATE_UNKNOWN; |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static acpi_status |
| 632 | acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device, |
| 633 | union acpi_object *package) |
| 634 | { |
| 635 | int i = 0; |
| 636 | union acpi_object *element = NULL; |
| 637 | |
| 638 | if (!device || !package || (package->package.count < 2)) |
| 639 | return AE_BAD_PARAMETER; |
| 640 | |
| 641 | element = &(package->package.elements[0]); |
| 642 | if (!element) |
| 643 | return AE_BAD_PARAMETER; |
| 644 | if (element->type == ACPI_TYPE_PACKAGE) { |
| 645 | if ((element->package.count < 2) || |
| 646 | (element->package.elements[0].type != |
| 647 | ACPI_TYPE_LOCAL_REFERENCE) |
| 648 | || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) |
| 649 | return AE_BAD_DATA; |
| 650 | device->wakeup.gpe_device = |
| 651 | element->package.elements[0].reference.handle; |
| 652 | device->wakeup.gpe_number = |
| 653 | (u32) element->package.elements[1].integer.value; |
| 654 | } else if (element->type == ACPI_TYPE_INTEGER) { |
| 655 | device->wakeup.gpe_number = element->integer.value; |
| 656 | } else |
| 657 | return AE_BAD_DATA; |
| 658 | |
| 659 | element = &(package->package.elements[1]); |
| 660 | if (element->type != ACPI_TYPE_INTEGER) { |
| 661 | return AE_BAD_DATA; |
| 662 | } |
| 663 | device->wakeup.sleep_state = element->integer.value; |
| 664 | |
| 665 | if ((package->package.count - 2) > ACPI_MAX_HANDLES) { |
| 666 | return AE_NO_MEMORY; |
| 667 | } |
| 668 | device->wakeup.resources.count = package->package.count - 2; |
| 669 | for (i = 0; i < device->wakeup.resources.count; i++) { |
| 670 | element = &(package->package.elements[i + 2]); |
| 671 | if (element->type != ACPI_TYPE_ANY) { |
| 672 | return AE_BAD_DATA; |
| 673 | } |
| 674 | |
| 675 | device->wakeup.resources.handles[i] = element->reference.handle; |
| 676 | } |
| 677 | |
| 678 | return AE_OK; |
| 679 | } |
| 680 | |
| 681 | static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) |
| 682 | { |
| 683 | acpi_status status = 0; |
| 684 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 685 | union acpi_object *package = NULL; |
| 686 | |
| 687 | |
| 688 | /* _PRW */ |
| 689 | status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); |
| 690 | if (ACPI_FAILURE(status)) { |
| 691 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); |
| 692 | goto end; |
| 693 | } |
| 694 | |
| 695 | package = (union acpi_object *)buffer.pointer; |
| 696 | status = acpi_bus_extract_wakeup_device_power_package(device, package); |
| 697 | if (ACPI_FAILURE(status)) { |
| 698 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package")); |
| 699 | goto end; |
| 700 | } |
| 701 | |
| 702 | kfree(buffer.pointer); |
| 703 | |
| 704 | device->wakeup.flags.valid = 1; |
| 705 | /* Power button, Lid switch always enable wakeup */ |
| 706 | if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E")) |
| 707 | device->wakeup.flags.run_wake = 1; |
| 708 | |
| 709 | end: |
| 710 | if (ACPI_FAILURE(status)) |
| 711 | device->flags.wake_capable = 0; |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int acpi_bus_get_power_flags(struct acpi_device *device) |
| 716 | { |
| 717 | acpi_status status = 0; |
| 718 | acpi_handle handle = NULL; |
| 719 | u32 i = 0; |
| 720 | |
| 721 | |
| 722 | /* |
| 723 | * Power Management Flags |
| 724 | */ |
| 725 | status = acpi_get_handle(device->handle, "_PSC", &handle); |
| 726 | if (ACPI_SUCCESS(status)) |
| 727 | device->power.flags.explicit_get = 1; |
| 728 | status = acpi_get_handle(device->handle, "_IRC", &handle); |
| 729 | if (ACPI_SUCCESS(status)) |
| 730 | device->power.flags.inrush_current = 1; |
| 731 | |
| 732 | /* |
| 733 | * Enumerate supported power management states |
| 734 | */ |
| 735 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) { |
| 736 | struct acpi_device_power_state *ps = &device->power.states[i]; |
| 737 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; |
| 738 | |
| 739 | /* Evaluate "_PRx" to se if power resources are referenced */ |
| 740 | acpi_evaluate_reference(device->handle, object_name, NULL, |
| 741 | &ps->resources); |
| 742 | if (ps->resources.count) { |
| 743 | device->power.flags.power_resources = 1; |
| 744 | ps->flags.valid = 1; |
| 745 | } |
| 746 | |
| 747 | /* Evaluate "_PSx" to see if we can do explicit sets */ |
| 748 | object_name[2] = 'S'; |
| 749 | status = acpi_get_handle(device->handle, object_name, &handle); |
| 750 | if (ACPI_SUCCESS(status)) { |
| 751 | ps->flags.explicit_set = 1; |
| 752 | ps->flags.valid = 1; |
| 753 | } |
| 754 | |
| 755 | /* State is valid if we have some power control */ |
| 756 | if (ps->resources.count || ps->flags.explicit_set) |
| 757 | ps->flags.valid = 1; |
| 758 | |
| 759 | ps->power = -1; /* Unknown - driver assigned */ |
| 760 | ps->latency = -1; /* Unknown - driver assigned */ |
| 761 | } |
| 762 | |
| 763 | /* Set defaults for D0 and D3 states (always valid) */ |
| 764 | device->power.states[ACPI_STATE_D0].flags.valid = 1; |
| 765 | device->power.states[ACPI_STATE_D0].power = 100; |
| 766 | device->power.states[ACPI_STATE_D3].flags.valid = 1; |
| 767 | device->power.states[ACPI_STATE_D3].power = 0; |
| 768 | |
| 769 | /* TBD: System wake support and resource requirements. */ |
| 770 | |
| 771 | device->power.state = ACPI_STATE_UNKNOWN; |
| 772 | |
| 773 | return 0; |
| 774 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 775 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | static int acpi_bus_get_flags(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 778 | acpi_status status = AE_OK; |
| 779 | acpi_handle temp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | |
| 782 | /* Presence of _STA indicates 'dynamic_status' */ |
| 783 | status = acpi_get_handle(device->handle, "_STA", &temp); |
| 784 | if (ACPI_SUCCESS(status)) |
| 785 | device->flags.dynamic_status = 1; |
| 786 | |
| 787 | /* Presence of _CID indicates 'compatible_ids' */ |
| 788 | status = acpi_get_handle(device->handle, "_CID", &temp); |
| 789 | if (ACPI_SUCCESS(status)) |
| 790 | device->flags.compatible_ids = 1; |
| 791 | |
| 792 | /* Presence of _RMV indicates 'removable' */ |
| 793 | status = acpi_get_handle(device->handle, "_RMV", &temp); |
| 794 | if (ACPI_SUCCESS(status)) |
| 795 | device->flags.removable = 1; |
| 796 | |
| 797 | /* Presence of _EJD|_EJ0 indicates 'ejectable' */ |
| 798 | status = acpi_get_handle(device->handle, "_EJD", &temp); |
| 799 | if (ACPI_SUCCESS(status)) |
| 800 | device->flags.ejectable = 1; |
| 801 | else { |
| 802 | status = acpi_get_handle(device->handle, "_EJ0", &temp); |
| 803 | if (ACPI_SUCCESS(status)) |
| 804 | device->flags.ejectable = 1; |
| 805 | } |
| 806 | |
| 807 | /* Presence of _LCK indicates 'lockable' */ |
| 808 | status = acpi_get_handle(device->handle, "_LCK", &temp); |
| 809 | if (ACPI_SUCCESS(status)) |
| 810 | device->flags.lockable = 1; |
| 811 | |
| 812 | /* Presence of _PS0|_PR0 indicates 'power manageable' */ |
| 813 | status = acpi_get_handle(device->handle, "_PS0", &temp); |
| 814 | if (ACPI_FAILURE(status)) |
| 815 | status = acpi_get_handle(device->handle, "_PR0", &temp); |
| 816 | if (ACPI_SUCCESS(status)) |
| 817 | device->flags.power_manageable = 1; |
| 818 | |
| 819 | /* Presence of _PRW indicates wake capable */ |
| 820 | status = acpi_get_handle(device->handle, "_PRW", &temp); |
| 821 | if (ACPI_SUCCESS(status)) |
| 822 | device->flags.wake_capable = 1; |
| 823 | |
| 824 | /* TBD: Peformance management */ |
| 825 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 826 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 829 | static void acpi_device_get_busid(struct acpi_device *device, |
| 830 | acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | char bus_id[5] = { '?', 0 }; |
| 833 | struct acpi_buffer buffer = { sizeof(bus_id), bus_id }; |
| 834 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | /* |
| 837 | * Bus ID |
| 838 | * ------ |
| 839 | * The device's Bus ID is simply the object name. |
| 840 | * TBD: Shouldn't this value be unique (within the ACPI namespace)? |
| 841 | */ |
| 842 | switch (type) { |
| 843 | case ACPI_BUS_TYPE_SYSTEM: |
| 844 | strcpy(device->pnp.bus_id, "ACPI"); |
| 845 | break; |
| 846 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 847 | strcpy(device->pnp.bus_id, "PWRF"); |
| 848 | break; |
| 849 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 850 | strcpy(device->pnp.bus_id, "SLPF"); |
| 851 | break; |
| 852 | default: |
| 853 | acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); |
| 854 | /* Clean up trailing underscores (if any) */ |
| 855 | for (i = 3; i > 1; i--) { |
| 856 | if (bus_id[i] == '_') |
| 857 | bus_id[i] = '\0'; |
| 858 | else |
| 859 | break; |
| 860 | } |
| 861 | strcpy(device->pnp.bus_id, bus_id); |
| 862 | break; |
| 863 | } |
| 864 | } |
| 865 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | static void acpi_device_set_id(struct acpi_device *device, |
| 867 | struct acpi_device *parent, acpi_handle handle, |
| 868 | int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | struct acpi_device_info *info; |
| 871 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 872 | char *hid = NULL; |
| 873 | char *uid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | struct acpi_compatible_id_list *cid_list = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 875 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | switch (type) { |
| 878 | case ACPI_BUS_TYPE_DEVICE: |
| 879 | status = acpi_get_object_info(handle, &buffer); |
| 880 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | printk("%s: Error reading device info\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | return; |
| 883 | } |
| 884 | |
| 885 | info = buffer.pointer; |
| 886 | if (info->valid & ACPI_VALID_HID) |
| 887 | hid = info->hardware_id.value; |
| 888 | if (info->valid & ACPI_VALID_UID) |
| 889 | uid = info->unique_id.value; |
| 890 | if (info->valid & ACPI_VALID_CID) |
| 891 | cid_list = &info->compatibility_id; |
| 892 | if (info->valid & ACPI_VALID_ADR) { |
| 893 | device->pnp.bus_address = info->address; |
| 894 | device->flags.bus_address = 1; |
| 895 | } |
| 896 | break; |
| 897 | case ACPI_BUS_TYPE_POWER: |
| 898 | hid = ACPI_POWER_HID; |
| 899 | break; |
| 900 | case ACPI_BUS_TYPE_PROCESSOR: |
| 901 | hid = ACPI_PROCESSOR_HID; |
| 902 | break; |
| 903 | case ACPI_BUS_TYPE_SYSTEM: |
| 904 | hid = ACPI_SYSTEM_HID; |
| 905 | break; |
| 906 | case ACPI_BUS_TYPE_THERMAL: |
| 907 | hid = ACPI_THERMAL_HID; |
| 908 | break; |
| 909 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 910 | hid = ACPI_BUTTON_HID_POWERF; |
| 911 | break; |
| 912 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 913 | hid = ACPI_BUTTON_HID_SLEEPF; |
| 914 | break; |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | * \_SB |
| 919 | * ---- |
| 920 | * Fix for the system root bus device -- the only root-level device. |
| 921 | */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 922 | if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | hid = ACPI_BUS_HID; |
| 924 | strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); |
| 925 | strcpy(device->pnp.device_class, ACPI_BUS_CLASS); |
| 926 | } |
| 927 | |
| 928 | if (hid) { |
| 929 | strcpy(device->pnp.hardware_id, hid); |
| 930 | device->flags.hardware_id = 1; |
| 931 | } |
| 932 | if (uid) { |
| 933 | strcpy(device->pnp.unique_id, uid); |
| 934 | device->flags.unique_id = 1; |
| 935 | } |
| 936 | if (cid_list) { |
| 937 | device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL); |
| 938 | if (device->pnp.cid_list) |
| 939 | memcpy(device->pnp.cid_list, cid_list, cid_list->size); |
| 940 | else |
| 941 | printk(KERN_ERR "Memory allocation error\n"); |
| 942 | } |
| 943 | |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 944 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 947 | static int acpi_device_set_context(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
| 949 | acpi_status status = AE_OK; |
| 950 | int result = 0; |
| 951 | /* |
| 952 | * Context |
| 953 | * ------- |
| 954 | * Attach this 'struct acpi_device' to the ACPI object. This makes |
| 955 | * resolutions from handle->device very efficient. Note that we need |
| 956 | * to be careful with fixed-feature devices as they all attach to the |
| 957 | * root object. |
| 958 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 959 | if (type != ACPI_BUS_TYPE_POWER_BUTTON && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | type != ACPI_BUS_TYPE_SLEEP_BUTTON) { |
| 961 | status = acpi_attach_data(device->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 962 | acpi_bus_data_handler, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | |
| 964 | if (ACPI_FAILURE(status)) { |
| 965 | printk("Error attaching device data\n"); |
| 966 | result = -ENODEV; |
| 967 | } |
| 968 | } |
| 969 | return result; |
| 970 | } |
| 971 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 972 | static void acpi_device_get_debug_info(struct acpi_device *device, |
| 973 | acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | { |
| 975 | #ifdef CONFIG_ACPI_DEBUG_OUTPUT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 976 | char *type_string = NULL; |
| 977 | char name[80] = { '?', '\0' }; |
| 978 | struct acpi_buffer buffer = { sizeof(name), name }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
| 980 | switch (type) { |
| 981 | case ACPI_BUS_TYPE_DEVICE: |
| 982 | type_string = "Device"; |
| 983 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 984 | break; |
| 985 | case ACPI_BUS_TYPE_POWER: |
| 986 | type_string = "Power Resource"; |
| 987 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 988 | break; |
| 989 | case ACPI_BUS_TYPE_PROCESSOR: |
| 990 | type_string = "Processor"; |
| 991 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 992 | break; |
| 993 | case ACPI_BUS_TYPE_SYSTEM: |
| 994 | type_string = "System"; |
| 995 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 996 | break; |
| 997 | case ACPI_BUS_TYPE_THERMAL: |
| 998 | type_string = "Thermal Zone"; |
| 999 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 1000 | break; |
| 1001 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 1002 | type_string = "Power Button"; |
| 1003 | sprintf(name, "PWRB"); |
| 1004 | break; |
| 1005 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 1006 | type_string = "Sleep Button"; |
| 1007 | sprintf(name, "SLPB"); |
| 1008 | break; |
| 1009 | } |
| 1010 | |
| 1011 | printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | #endif /*CONFIG_ACPI_DEBUG_OUTPUT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1015 | static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1017 | int result = 0; |
| 1018 | struct acpi_driver *driver; |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | |
| 1021 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1022 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
| 1024 | driver = dev->driver; |
| 1025 | |
| 1026 | if ((driver) && (driver->ops.remove)) { |
| 1027 | |
| 1028 | if (driver->ops.stop) { |
| 1029 | result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT); |
| 1030 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1031 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT); |
| 1035 | if (result) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1036 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | atomic_dec(&dev->driver->references); |
| 1040 | dev->driver = NULL; |
| 1041 | acpi_driver_data(dev) = NULL; |
| 1042 | } |
| 1043 | |
| 1044 | if (!rmdevice) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1045 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | |
| 1047 | if (dev->flags.bus_address) { |
| 1048 | if ((dev->parent) && (dev->parent->ops.unbind)) |
| 1049 | dev->parent->ops.unbind(dev); |
| 1050 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); |
| 1053 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1054 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1057 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1058 | acpi_add_single_object(struct acpi_device **child, |
| 1059 | struct acpi_device *parent, acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1061 | int result = 0; |
| 1062 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | if (!child) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1066 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
| 1068 | device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); |
| 1069 | if (!device) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 1070 | printk(KERN_ERR PREFIX "Memory allocation error\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1071 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | } |
| 1073 | memset(device, 0, sizeof(struct acpi_device)); |
| 1074 | |
| 1075 | device->handle = handle; |
| 1076 | device->parent = parent; |
| 1077 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1078 | acpi_device_get_busid(device, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
| 1080 | /* |
| 1081 | * Flags |
| 1082 | * ----- |
| 1083 | * Get prior to calling acpi_bus_get_status() so we know whether |
| 1084 | * or not _STA is present. Note that we only look for object |
| 1085 | * handles -- cannot evaluate objects until we know the device is |
| 1086 | * present and properly initialized. |
| 1087 | */ |
| 1088 | result = acpi_bus_get_flags(device); |
| 1089 | if (result) |
| 1090 | goto end; |
| 1091 | |
| 1092 | /* |
| 1093 | * Status |
| 1094 | * ------ |
Keiichiro Tokunaga | 6940fab | 2005-03-30 23:15:47 -0500 | [diff] [blame] | 1095 | * See if the device is present. We always assume that non-Device |
| 1096 | * and non-Processor objects (e.g. thermal zones, power resources, |
| 1097 | * etc.) are present, functioning, etc. (at least when parent object |
| 1098 | * is present). Note that _STA has a different meaning for some |
| 1099 | * objects (e.g. power resources) so we need to be careful how we use |
| 1100 | * it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | */ |
| 1102 | switch (type) { |
Keiichiro Tokunaga | 6940fab | 2005-03-30 23:15:47 -0500 | [diff] [blame] | 1103 | case ACPI_BUS_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | case ACPI_BUS_TYPE_DEVICE: |
| 1105 | result = acpi_bus_get_status(device); |
| 1106 | if (ACPI_FAILURE(result) || !device->status.present) { |
| 1107 | result = -ENOENT; |
| 1108 | goto end; |
| 1109 | } |
| 1110 | break; |
| 1111 | default: |
| 1112 | STRUCT_TO_INT(device->status) = 0x0F; |
| 1113 | break; |
| 1114 | } |
| 1115 | |
| 1116 | /* |
| 1117 | * Initialize Device |
| 1118 | * ----------------- |
| 1119 | * TBD: Synch with Core's enumeration/initialization process. |
| 1120 | */ |
| 1121 | |
| 1122 | /* |
| 1123 | * Hardware ID, Unique ID, & Bus Address |
| 1124 | * ------------------------------------- |
| 1125 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1126 | acpi_device_set_id(device, parent, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
| 1128 | /* |
| 1129 | * Power Management |
| 1130 | * ---------------- |
| 1131 | */ |
| 1132 | if (device->flags.power_manageable) { |
| 1133 | result = acpi_bus_get_power_flags(device); |
| 1134 | if (result) |
| 1135 | goto end; |
| 1136 | } |
| 1137 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1138 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | * Wakeup device management |
| 1140 | *----------------------- |
| 1141 | */ |
| 1142 | if (device->flags.wake_capable) { |
| 1143 | result = acpi_bus_get_wakeup_device_flags(device); |
| 1144 | if (result) |
| 1145 | goto end; |
| 1146 | } |
| 1147 | |
| 1148 | /* |
| 1149 | * Performance Management |
| 1150 | * ---------------------- |
| 1151 | */ |
| 1152 | if (device->flags.performance_manageable) { |
| 1153 | result = acpi_bus_get_perf_flags(device); |
| 1154 | if (result) |
| 1155 | goto end; |
| 1156 | } |
| 1157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1158 | if ((result = acpi_device_set_context(device, type))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | goto end; |
| 1160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1161 | acpi_device_get_debug_info(device, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1163 | acpi_device_register(device, parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
| 1165 | /* |
| 1166 | * Bind _ADR-Based Devices |
| 1167 | * ----------------------- |
| 1168 | * If there's a a bus address (_ADR) then we utilize the parent's |
| 1169 | * 'bind' function (if exists) to bind the ACPI- and natively- |
| 1170 | * enumerated device representations. |
| 1171 | */ |
| 1172 | if (device->flags.bus_address) { |
| 1173 | if (device->parent && device->parent->ops.bind) |
| 1174 | device->parent->ops.bind(device); |
| 1175 | } |
| 1176 | |
| 1177 | /* |
| 1178 | * Locate & Attach Driver |
| 1179 | * ---------------------- |
| 1180 | * If there's a hardware id (_HID) or compatible ids (_CID) we check |
| 1181 | * to see if there's a driver installed for this kind of device. Note |
| 1182 | * that drivers can install before or after a device is enumerated. |
| 1183 | * |
| 1184 | * TBD: Assumes LDM provides driver hot-plug capability. |
| 1185 | */ |
Thomas Renninger | bd7ce5b | 2005-10-03 10:39:00 -0700 | [diff] [blame] | 1186 | acpi_bus_find_driver(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1188 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | if (!result) |
| 1190 | *child = device; |
| 1191 | else { |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 1192 | kfree(device->pnp.cid_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | kfree(device); |
| 1194 | } |
| 1195 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1196 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1199 | static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1201 | acpi_status status = AE_OK; |
| 1202 | struct acpi_device *parent = NULL; |
| 1203 | struct acpi_device *child = NULL; |
| 1204 | acpi_handle phandle = NULL; |
| 1205 | acpi_handle chandle = NULL; |
| 1206 | acpi_object_type type = 0; |
| 1207 | u32 level = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
| 1210 | if (!start) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1211 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
| 1213 | parent = start; |
| 1214 | phandle = start->handle; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | /* |
| 1217 | * Parse through the ACPI namespace, identify all 'devices', and |
| 1218 | * create a new 'struct acpi_device' for each. |
| 1219 | */ |
| 1220 | while ((level > 0) && parent) { |
| 1221 | |
| 1222 | status = acpi_get_next_object(ACPI_TYPE_ANY, phandle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1223 | chandle, &chandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | /* |
| 1226 | * If this scope is exhausted then move our way back up. |
| 1227 | */ |
| 1228 | if (ACPI_FAILURE(status)) { |
| 1229 | level--; |
| 1230 | chandle = phandle; |
| 1231 | acpi_get_parent(phandle, &phandle); |
| 1232 | if (parent->parent) |
| 1233 | parent = parent->parent; |
| 1234 | continue; |
| 1235 | } |
| 1236 | |
| 1237 | status = acpi_get_type(chandle, &type); |
| 1238 | if (ACPI_FAILURE(status)) |
| 1239 | continue; |
| 1240 | |
| 1241 | /* |
| 1242 | * If this is a scope object then parse it (depth-first). |
| 1243 | */ |
| 1244 | if (type == ACPI_TYPE_LOCAL_SCOPE) { |
| 1245 | level++; |
| 1246 | phandle = chandle; |
| 1247 | chandle = NULL; |
| 1248 | continue; |
| 1249 | } |
| 1250 | |
| 1251 | /* |
| 1252 | * We're only interested in objects that we consider 'devices'. |
| 1253 | */ |
| 1254 | switch (type) { |
| 1255 | case ACPI_TYPE_DEVICE: |
| 1256 | type = ACPI_BUS_TYPE_DEVICE; |
| 1257 | break; |
| 1258 | case ACPI_TYPE_PROCESSOR: |
| 1259 | type = ACPI_BUS_TYPE_PROCESSOR; |
| 1260 | break; |
| 1261 | case ACPI_TYPE_THERMAL: |
| 1262 | type = ACPI_BUS_TYPE_THERMAL; |
| 1263 | break; |
| 1264 | case ACPI_TYPE_POWER: |
| 1265 | type = ACPI_BUS_TYPE_POWER; |
| 1266 | break; |
| 1267 | default: |
| 1268 | continue; |
| 1269 | } |
| 1270 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1271 | if (ops->acpi_op_add) |
| 1272 | status = acpi_add_single_object(&child, parent, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1273 | chandle, type); |
| 1274 | else |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1275 | status = acpi_bus_get_device(chandle, &child); |
| 1276 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1277 | if (ACPI_FAILURE(status)) |
| 1278 | continue; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1279 | |
| 1280 | if (ops->acpi_op_start) { |
| 1281 | status = acpi_start_single_object(child); |
| 1282 | if (ACPI_FAILURE(status)) |
| 1283 | continue; |
| 1284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | /* |
| 1287 | * If the device is present, enabled, and functioning then |
| 1288 | * parse its scope (depth-first). Note that we need to |
| 1289 | * represent absent devices to facilitate PnP notifications |
| 1290 | * -- but only the subtree head (not all of its children, |
| 1291 | * which will be enumerated when the parent is inserted). |
| 1292 | * |
| 1293 | * TBD: Need notifications and other detection mechanisms |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1294 | * in place before we can fully implement this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | */ |
| 1296 | if (child->status.present) { |
| 1297 | status = acpi_get_next_object(ACPI_TYPE_ANY, chandle, |
| 1298 | NULL, NULL); |
| 1299 | if (ACPI_SUCCESS(status)) { |
| 1300 | level++; |
| 1301 | phandle = chandle; |
| 1302 | chandle = NULL; |
| 1303 | parent = child; |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1308 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1311 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1312 | acpi_bus_add(struct acpi_device **child, |
| 1313 | struct acpi_device *parent, acpi_handle handle, int type) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1314 | { |
| 1315 | int result; |
| 1316 | struct acpi_bus_ops ops; |
| 1317 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1318 | |
| 1319 | result = acpi_add_single_object(child, parent, handle, type); |
| 1320 | if (!result) { |
| 1321 | memset(&ops, 0, sizeof(ops)); |
| 1322 | ops.acpi_op_add = 1; |
| 1323 | result = acpi_bus_scan(*child, &ops); |
| 1324 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1325 | return result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1326 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1327 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1328 | EXPORT_SYMBOL(acpi_bus_add); |
| 1329 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1330 | int acpi_bus_start(struct acpi_device *device) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1331 | { |
| 1332 | int result; |
| 1333 | struct acpi_bus_ops ops; |
| 1334 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1335 | |
| 1336 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1337 | return -EINVAL; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1338 | |
| 1339 | result = acpi_start_single_object(device); |
| 1340 | if (!result) { |
| 1341 | memset(&ops, 0, sizeof(ops)); |
| 1342 | ops.acpi_op_start = 1; |
| 1343 | result = acpi_bus_scan(device, &ops); |
| 1344 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1345 | return result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1346 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1347 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1348 | EXPORT_SYMBOL(acpi_bus_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Kristen Accardi | ceaba66 | 2006-02-23 17:56:01 -0800 | [diff] [blame] | 1350 | int acpi_bus_trim(struct acpi_device *start, int rmdevice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1352 | acpi_status status; |
| 1353 | struct acpi_device *parent, *child; |
| 1354 | acpi_handle phandle, chandle; |
| 1355 | acpi_object_type type; |
| 1356 | u32 level = 1; |
| 1357 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1359 | parent = start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | phandle = start->handle; |
| 1361 | child = chandle = NULL; |
| 1362 | |
| 1363 | while ((level > 0) && parent && (!err)) { |
| 1364 | status = acpi_get_next_object(ACPI_TYPE_ANY, phandle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1365 | chandle, &chandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
| 1367 | /* |
| 1368 | * If this scope is exhausted then move our way back up. |
| 1369 | */ |
| 1370 | if (ACPI_FAILURE(status)) { |
| 1371 | level--; |
| 1372 | chandle = phandle; |
| 1373 | acpi_get_parent(phandle, &phandle); |
| 1374 | child = parent; |
| 1375 | parent = parent->parent; |
| 1376 | |
| 1377 | if (level == 0) |
| 1378 | err = acpi_bus_remove(child, rmdevice); |
| 1379 | else |
| 1380 | err = acpi_bus_remove(child, 1); |
| 1381 | |
| 1382 | continue; |
| 1383 | } |
| 1384 | |
| 1385 | status = acpi_get_type(chandle, &type); |
| 1386 | if (ACPI_FAILURE(status)) { |
| 1387 | continue; |
| 1388 | } |
| 1389 | /* |
| 1390 | * If there is a device corresponding to chandle then |
| 1391 | * parse it (depth-first). |
| 1392 | */ |
| 1393 | if (acpi_bus_get_device(chandle, &child) == 0) { |
| 1394 | level++; |
| 1395 | phandle = chandle; |
| 1396 | chandle = NULL; |
| 1397 | parent = child; |
| 1398 | } |
| 1399 | continue; |
| 1400 | } |
| 1401 | return err; |
| 1402 | } |
Kristen Accardi | ceaba66 | 2006-02-23 17:56:01 -0800 | [diff] [blame] | 1403 | EXPORT_SYMBOL_GPL(acpi_bus_trim); |
| 1404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1406 | static int acpi_bus_scan_fixed(struct acpi_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1408 | int result = 0; |
| 1409 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
| 1412 | if (!root) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1413 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
| 1415 | /* |
| 1416 | * Enumerate all fixed-feature devices. |
| 1417 | */ |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1418 | if (acpi_fadt.pwr_button == 0) { |
| 1419 | result = acpi_add_single_object(&device, acpi_root, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1420 | NULL, |
| 1421 | ACPI_BUS_TYPE_POWER_BUTTON); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1422 | if (!result) |
| 1423 | result = acpi_start_single_object(device); |
| 1424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1426 | if (acpi_fadt.sleep_button == 0) { |
| 1427 | result = acpi_add_single_object(&device, acpi_root, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1428 | NULL, |
| 1429 | ACPI_BUS_TYPE_SLEEP_BUTTON); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1430 | if (!result) |
| 1431 | result = acpi_start_single_object(device); |
| 1432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1434 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } |
| 1436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | static int __init acpi_scan_init(void) |
| 1438 | { |
| 1439 | int result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1440 | struct acpi_bus_ops ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
| 1443 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1444 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | |
Randy Dunlap | 9b6d97b | 2006-07-12 02:08:00 -0400 | [diff] [blame] | 1446 | result = kset_register(&acpi_namespace_kset); |
| 1447 | if (result < 0) |
| 1448 | printk(KERN_ERR PREFIX "kset_register error: %d\n", result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1450 | result = bus_register(&acpi_bus_type); |
| 1451 | if (result) { |
| 1452 | /* We don't want to quit even if we failed to add suspend/resume */ |
| 1453 | printk(KERN_ERR PREFIX "Could not register bus type\n"); |
| 1454 | } |
| 1455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | /* |
| 1457 | * Create the root device in the bus's device tree |
| 1458 | */ |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1459 | result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1460 | ACPI_BUS_TYPE_SYSTEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | if (result) |
| 1462 | goto Done; |
| 1463 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1464 | result = acpi_start_single_object(acpi_root); |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1465 | if (result) |
| 1466 | goto Done; |
| 1467 | |
| 1468 | acpi_root->dev.bus = &acpi_bus_type; |
| 1469 | snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name); |
| 1470 | result = device_register(&acpi_root->dev); |
| 1471 | if (result) { |
| 1472 | /* We don't want to quit even if we failed to add suspend/resume */ |
| 1473 | printk(KERN_ERR PREFIX "Could not register device\n"); |
| 1474 | } |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | /* |
| 1477 | * Enumerate devices in the ACPI namespace. |
| 1478 | */ |
| 1479 | result = acpi_bus_scan_fixed(acpi_root); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1480 | if (!result) { |
| 1481 | memset(&ops, 0, sizeof(ops)); |
| 1482 | ops.acpi_op_add = 1; |
| 1483 | ops.acpi_op_start = 1; |
| 1484 | result = acpi_bus_scan(acpi_root, &ops); |
| 1485 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | |
| 1487 | if (result) |
| 1488 | acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); |
| 1489 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1490 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1491 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | subsys_initcall(acpi_scan_init); |