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