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