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