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