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