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