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