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