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