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