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