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