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