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> |
| 7 | #include <linux/acpi.h> |
| 8 | |
| 9 | #include <acpi/acpi_drivers.h> |
| 10 | #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #define _COMPONENT ACPI_BUS_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 13 | ACPI_MODULE_NAME("scan") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #define STRUCT_TO_INT(s) (*((int*)&s)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 15 | extern struct acpi_device *acpi_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #define ACPI_BUS_CLASS "system_bus" |
| 18 | #define ACPI_BUS_HID "ACPI_BUS" |
| 19 | #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver" |
| 20 | #define ACPI_BUS_DEVICE_NAME "System Bus" |
| 21 | |
| 22 | static LIST_HEAD(acpi_device_list); |
| 23 | DEFINE_SPINLOCK(acpi_device_lock); |
| 24 | LIST_HEAD(acpi_wakeup_device_list); |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 27 | static void acpi_device_release(struct kobject *kobj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 29 | struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj); |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 30 | kfree(dev->pnp.cid_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | kfree(dev); |
| 32 | } |
| 33 | |
| 34 | struct acpi_device_attribute { |
| 35 | struct attribute attr; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 36 | ssize_t(*show) (struct acpi_device *, char *); |
| 37 | ssize_t(*store) (struct acpi_device *, const char *, size_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | typedef void acpi_device_sysfs_files(struct kobject *, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 41 | const struct attribute *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | static void setup_sys_fs_device_files(struct acpi_device *dev, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 44 | acpi_device_sysfs_files * func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #define create_sysfs_device_files(dev) \ |
| 47 | setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file) |
| 48 | #define remove_sysfs_device_files(dev) \ |
| 49 | setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file) |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define to_acpi_device(n) container_of(n, struct acpi_device, kobj) |
| 52 | #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr); |
| 53 | |
| 54 | static ssize_t acpi_device_attr_show(struct kobject *kobj, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | struct attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | struct acpi_device *device = to_acpi_device(kobj); |
| 58 | struct acpi_device_attribute *attribute = to_handle_attr(attr); |
Dmitry Torokhov | 70f2817 | 2005-04-29 01:27:34 -0500 | [diff] [blame] | 59 | return attribute->show ? attribute->show(device, buf) : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | static ssize_t acpi_device_attr_store(struct kobject *kobj, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 62 | struct attribute *attr, const char *buf, |
| 63 | size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | struct acpi_device *device = to_acpi_device(kobj); |
| 66 | struct acpi_device_attribute *attribute = to_handle_attr(attr); |
Dmitry Torokhov | 70f2817 | 2005-04-29 01:27:34 -0500 | [diff] [blame] | 67 | return attribute->store ? attribute->store(device, buf, len) : -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static struct sysfs_ops acpi_device_sysfs_ops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | .show = acpi_device_attr_show, |
| 72 | .store = acpi_device_attr_store, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | static struct kobj_type ktype_acpi_ns = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | .sysfs_ops = &acpi_device_sysfs_ops, |
| 77 | .release = acpi_device_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 80 | static int namespace_uevent(struct kset *kset, struct kobject *kobj, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | char **envp, int num_envp, char *buffer, |
| 82 | int buffer_size) |
| 83 | { |
| 84 | struct acpi_device *dev = to_acpi_device(kobj); |
| 85 | int i = 0; |
| 86 | int len = 0; |
| 87 | |
| 88 | if (!dev->driver) |
| 89 | return 0; |
| 90 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 91 | if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, |
| 92 | "PHYSDEVDRIVER=%s", dev->driver->name)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return -ENOMEM; |
| 94 | |
| 95 | envp[i] = NULL; |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 100 | static struct kset_uevent_ops namespace_uevent_ops = { |
| 101 | .uevent = &namespace_uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static struct kset acpi_namespace_kset = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | .kobj = { |
| 106 | .name = "namespace", |
| 107 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | .subsys = &acpi_subsys, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 109 | .ktype = &ktype_acpi_ns, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 110 | .uevent_ops = &namespace_uevent_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | static void acpi_device_register(struct acpi_device *device, |
| 114 | struct acpi_device *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | /* |
| 117 | * Linkage |
| 118 | * ------- |
| 119 | * Link this device to its parent and siblings. |
| 120 | */ |
| 121 | INIT_LIST_HEAD(&device->children); |
| 122 | INIT_LIST_HEAD(&device->node); |
| 123 | INIT_LIST_HEAD(&device->g_list); |
| 124 | INIT_LIST_HEAD(&device->wakeup_list); |
| 125 | |
| 126 | spin_lock(&acpi_device_lock); |
| 127 | if (device->parent) { |
| 128 | list_add_tail(&device->node, &device->parent->children); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | list_add_tail(&device->g_list, &device->parent->g_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 131 | list_add_tail(&device->g_list, &acpi_device_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | if (device->wakeup.flags.valid) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | spin_unlock(&acpi_device_lock); |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (parent) |
| 138 | device->kobj.parent = &parent->kobj; |
| 139 | device->kobj.ktype = &ktype_acpi_ns; |
| 140 | device->kobj.kset = &acpi_namespace_kset; |
| 141 | kobject_register(&device->kobj); |
| 142 | create_sysfs_device_files(device); |
| 143 | } |
| 144 | |
Bjorn Helgaas | 06ea8e08 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 145 | static void acpi_device_unregister(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | spin_lock(&acpi_device_lock); |
| 148 | if (device->parent) { |
| 149 | list_del(&device->node); |
| 150 | list_del(&device->g_list); |
| 151 | } else |
| 152 | list_del(&device->g_list); |
| 153 | |
| 154 | list_del(&device->wakeup_list); |
| 155 | |
| 156 | spin_unlock(&acpi_device_lock); |
| 157 | |
| 158 | acpi_detach_data(device->handle, acpi_bus_data_handler); |
| 159 | remove_sysfs_device_files(device); |
| 160 | kobject_unregister(&device->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | /* TBD */ |
| 167 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 168 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | static int acpi_bus_get_power_flags(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | acpi_status status = 0; |
| 174 | acpi_handle handle = NULL; |
| 175 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * Power Management Flags |
| 180 | */ |
| 181 | status = acpi_get_handle(device->handle, "_PSC", &handle); |
| 182 | if (ACPI_SUCCESS(status)) |
| 183 | device->power.flags.explicit_get = 1; |
| 184 | status = acpi_get_handle(device->handle, "_IRC", &handle); |
| 185 | if (ACPI_SUCCESS(status)) |
| 186 | device->power.flags.inrush_current = 1; |
| 187 | |
| 188 | /* |
| 189 | * Enumerate supported power management states |
| 190 | */ |
| 191 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) { |
| 192 | struct acpi_device_power_state *ps = &device->power.states[i]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* Evaluate "_PRx" to se if power resources are referenced */ |
| 196 | acpi_evaluate_reference(device->handle, object_name, NULL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | &ps->resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (ps->resources.count) { |
| 199 | device->power.flags.power_resources = 1; |
| 200 | ps->flags.valid = 1; |
| 201 | } |
| 202 | |
| 203 | /* Evaluate "_PSx" to see if we can do explicit sets */ |
| 204 | object_name[2] = 'S'; |
| 205 | status = acpi_get_handle(device->handle, object_name, &handle); |
| 206 | if (ACPI_SUCCESS(status)) { |
| 207 | ps->flags.explicit_set = 1; |
| 208 | ps->flags.valid = 1; |
| 209 | } |
| 210 | |
| 211 | /* State is valid if we have some power control */ |
| 212 | if (ps->resources.count || ps->flags.explicit_set) |
| 213 | ps->flags.valid = 1; |
| 214 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | ps->power = -1; /* Unknown - driver assigned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | ps->latency = -1; /* Unknown - driver assigned */ |
| 217 | } |
| 218 | |
| 219 | /* Set defaults for D0 and D3 states (always valid) */ |
| 220 | device->power.states[ACPI_STATE_D0].flags.valid = 1; |
| 221 | device->power.states[ACPI_STATE_D0].power = 100; |
| 222 | device->power.states[ACPI_STATE_D3].flags.valid = 1; |
| 223 | device->power.states[ACPI_STATE_D3].power = 0; |
| 224 | |
| 225 | /* TBD: System wake support and resource requirements. */ |
| 226 | |
| 227 | device->power.state = ACPI_STATE_UNKNOWN; |
| 228 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 229 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | int acpi_match_ids(struct acpi_device *device, char *ids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if (device->flags.hardware_id) |
| 235 | if (strstr(ids, device->pnp.hardware_id)) |
Bjorn Helgaas | 1a36561 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 236 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | if (device->flags.compatible_ids) { |
| 239 | struct acpi_compatible_id_list *cid_list = device->pnp.cid_list; |
| 240 | int i; |
| 241 | |
| 242 | /* compare multiple _CID entries against driver ids */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | for (i = 0; i < cid_list->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if (strstr(ids, cid_list->id[i].value)) |
Bjorn Helgaas | 1a36561 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 245 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
Bjorn Helgaas | 1a36561 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 248 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device, |
| 253 | union acpi_object *package) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | int i = 0; |
| 256 | union acpi_object *element = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | if (!device || !package || (package->package.count < 2)) |
| 259 | return AE_BAD_PARAMETER; |
| 260 | |
| 261 | element = &(package->package.elements[0]); |
| 262 | if (!element) |
| 263 | return AE_BAD_PARAMETER; |
| 264 | if (element->type == ACPI_TYPE_PACKAGE) { |
| 265 | if ((element->package.count < 2) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 266 | (element->package.elements[0].type != |
| 267 | ACPI_TYPE_LOCAL_REFERENCE) |
| 268 | || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | return AE_BAD_DATA; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | device->wakeup.gpe_device = |
| 271 | element->package.elements[0].reference.handle; |
| 272 | device->wakeup.gpe_number = |
| 273 | (u32) element->package.elements[1].integer.value; |
| 274 | } else if (element->type == ACPI_TYPE_INTEGER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | device->wakeup.gpe_number = element->integer.value; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return AE_BAD_DATA; |
| 278 | |
| 279 | element = &(package->package.elements[1]); |
| 280 | if (element->type != ACPI_TYPE_INTEGER) { |
| 281 | return AE_BAD_DATA; |
| 282 | } |
| 283 | device->wakeup.sleep_state = element->integer.value; |
| 284 | |
| 285 | if ((package->package.count - 2) > ACPI_MAX_HANDLES) { |
| 286 | return AE_NO_MEMORY; |
| 287 | } |
| 288 | device->wakeup.resources.count = package->package.count - 2; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | for (i = 0; i < device->wakeup.resources.count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | element = &(package->package.elements[i + 2]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | if (element->type != ACPI_TYPE_ANY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | return AE_BAD_DATA; |
| 293 | } |
| 294 | |
| 295 | device->wakeup.resources.handles[i] = element->reference.handle; |
| 296 | } |
| 297 | |
| 298 | return AE_OK; |
| 299 | } |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | acpi_status status = 0; |
| 304 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 305 | union acpi_object *package = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | /* _PRW */ |
| 309 | status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); |
| 310 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 311 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | goto end; |
| 313 | } |
| 314 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | package = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | status = acpi_bus_extract_wakeup_device_power_package(device, package); |
| 317 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 318 | ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | goto end; |
| 320 | } |
| 321 | |
| 322 | acpi_os_free(buffer.pointer); |
| 323 | |
| 324 | device->wakeup.flags.valid = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | /* Power button, Lid switch always enable wakeup */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E")) |
| 327 | device->wakeup.flags.run_wake = 1; |
| 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (ACPI_FAILURE(status)) |
| 331 | device->flags.wake_capable = 0; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 332 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* -------------------------------------------------------------------------- |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 336 | ACPI sysfs device file support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | -------------------------------------------------------------------------- */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | static ssize_t acpi_eject_store(struct acpi_device *device, |
| 339 | const char *buf, size_t count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | #define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \ |
| 342 | static struct acpi_device_attribute acpi_device_attr_##_name = \ |
| 343 | __ATTR(_name, _mode, _show, _store) |
| 344 | |
| 345 | ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); |
| 346 | |
| 347 | /** |
| 348 | * setup_sys_fs_device_files - sets up the device files under device namespace |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 349 | * @dev: acpi_device object |
| 350 | * @func: function pointer to create or destroy the device file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | */ |
| 352 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 353 | setup_sys_fs_device_files(struct acpi_device *dev, |
| 354 | acpi_device_sysfs_files * func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 356 | acpi_status status; |
| 357 | acpi_handle temp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * If device has _EJ0, 'eject' file is created that is used to trigger |
| 361 | * hot-removal function from userland. |
| 362 | */ |
| 363 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); |
| 364 | if (ACPI_SUCCESS(status)) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | static int acpi_eject_operation(acpi_handle handle, int lockable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
| 370 | struct acpi_object_list arg_list; |
| 371 | union acpi_object arg; |
| 372 | acpi_status status = AE_OK; |
| 373 | |
| 374 | /* |
| 375 | * TBD: evaluate _PS3? |
| 376 | */ |
| 377 | |
| 378 | if (lockable) { |
| 379 | arg_list.count = 1; |
| 380 | arg_list.pointer = &arg; |
| 381 | arg.type = ACPI_TYPE_INTEGER; |
| 382 | arg.integer.value = 0; |
| 383 | acpi_evaluate_object(handle, "_LCK", &arg_list, NULL); |
| 384 | } |
| 385 | |
| 386 | arg_list.count = 1; |
| 387 | arg_list.pointer = &arg; |
| 388 | arg.type = ACPI_TYPE_INTEGER; |
| 389 | arg.integer.value = 1; |
| 390 | |
| 391 | /* |
| 392 | * TBD: _EJD support. |
| 393 | */ |
| 394 | |
| 395 | status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); |
| 396 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | return (-ENODEV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | static ssize_t |
| 404 | acpi_eject_store(struct acpi_device *device, const char *buf, size_t count) |
| 405 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | int result; |
| 407 | int ret = count; |
| 408 | int islockable; |
| 409 | acpi_status status; |
| 410 | acpi_handle handle; |
| 411 | acpi_object_type type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | if ((!count) || (buf[0] != '1')) { |
| 414 | return -EINVAL; |
| 415 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | #ifndef FORCE_EJECT |
| 417 | if (device->driver == NULL) { |
| 418 | ret = -ENODEV; |
| 419 | goto err; |
| 420 | } |
| 421 | #endif |
| 422 | status = acpi_get_type(device->handle, &type); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | if (ACPI_FAILURE(status) || (!device->flags.ejectable)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | ret = -ENODEV; |
| 425 | goto err; |
| 426 | } |
| 427 | |
| 428 | islockable = device->flags.lockable; |
| 429 | handle = device->handle; |
| 430 | |
Ashok Raj | eefa27a | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 431 | result = acpi_bus_trim(device, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | if (!result) |
| 434 | result = acpi_eject_operation(handle, islockable); |
| 435 | |
| 436 | if (result) { |
| 437 | ret = -EBUSY; |
| 438 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | return ret; |
| 441 | } |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* -------------------------------------------------------------------------- |
| 444 | Performance Management |
| 445 | -------------------------------------------------------------------------- */ |
| 446 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | static int acpi_bus_get_perf_flags(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | device->performance.state = ACPI_STATE_UNKNOWN; |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | /* -------------------------------------------------------------------------- |
| 454 | Driver Management |
| 455 | -------------------------------------------------------------------------- */ |
| 456 | |
| 457 | static LIST_HEAD(acpi_bus_drivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 460 | * acpi_bus_match - match device IDs to driver's supported IDs |
| 461 | * @device: the device that we are trying to match to a driver |
| 462 | * @driver: driver whose device id table is being checked |
| 463 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it |
| 465 | * matches the specified driver's criteria. |
| 466 | */ |
| 467 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
| 470 | if (driver && driver->ops.match) |
| 471 | return driver->ops.match(device, driver); |
| 472 | return acpi_match_ids(device, driver->ids); |
| 473 | } |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 476 | * acpi_bus_driver_init - add a device to a driver |
| 477 | * @device: the device to add and initialize |
| 478 | * @driver: driver for the device |
| 479 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | * Used to initialize a device via its device driver. Called whenever a |
| 481 | * driver is bound to a device. Invokes the driver's add() and start() ops. |
| 482 | */ |
| 483 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | if (!device || !driver) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 490 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | if (!driver->ops.add) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 493 | return -ENOSYS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | result = driver->ops.add(device); |
| 496 | if (result) { |
| 497 | device->driver = NULL; |
| 498 | acpi_driver_data(device) = NULL; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 499 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | device->driver = driver; |
| 503 | |
| 504 | /* |
| 505 | * TBD - Configuration Management: Assign resources to device based |
| 506 | * upon possible configuration and currently allocated resources. |
| 507 | */ |
| 508 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 509 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 510 | "Driver successfully bound to device\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 511 | return 0; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 514 | static int acpi_start_single_object(struct acpi_device *device) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 515 | { |
| 516 | int result = 0; |
| 517 | struct acpi_driver *driver; |
| 518 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 519 | |
| 520 | if (!(driver = device->driver)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 521 | return 0; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | if (driver->ops.start) { |
| 524 | result = driver->ops.start(device); |
| 525 | if (result && driver->ops.remove) |
| 526 | driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 529 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 532 | static void acpi_driver_attach(struct acpi_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 534 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | spin_lock(&acpi_device_lock); |
| 538 | list_for_each_safe(node, next, &acpi_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 539 | struct acpi_device *dev = |
| 540 | container_of(node, struct acpi_device, g_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | if (dev->driver || !dev->status.present) |
| 543 | continue; |
| 544 | spin_unlock(&acpi_device_lock); |
| 545 | |
| 546 | if (!acpi_bus_match(dev, drv)) { |
| 547 | if (!acpi_bus_driver_init(dev, drv)) { |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 548 | acpi_start_single_object(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | atomic_inc(&drv->references); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 550 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 551 | "Found driver [%s] for device [%s]\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | drv->name, dev->pnp.bus_id)); |
| 553 | } |
| 554 | } |
| 555 | spin_lock(&acpi_device_lock); |
| 556 | } |
| 557 | spin_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Bjorn Helgaas | 06ea8e08 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 560 | static void acpi_driver_detach(struct acpi_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 562 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | spin_lock(&acpi_device_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 566 | list_for_each_safe(node, next, &acpi_device_list) { |
| 567 | struct acpi_device *dev = |
| 568 | container_of(node, struct acpi_device, g_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | if (dev->driver == drv) { |
| 571 | spin_unlock(&acpi_device_lock); |
| 572 | if (drv->ops.remove) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 573 | drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | spin_lock(&acpi_device_lock); |
| 575 | dev->driver = NULL; |
| 576 | dev->driver_data = NULL; |
| 577 | atomic_dec(&drv->references); |
| 578 | } |
| 579 | } |
| 580 | spin_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 584 | * acpi_bus_register_driver - register a driver with the ACPI bus |
| 585 | * @driver: driver being registered |
| 586 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | * Registers a driver with the ACPI bus. Searches the namespace for all |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 588 | * devices that match the driver's criteria and binds. Returns zero for |
| 589 | * success or a negative error status for failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 591 | int acpi_bus_register_driver(struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 595 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | spin_lock(&acpi_device_lock); |
| 598 | list_add_tail(&driver->node, &acpi_bus_drivers); |
| 599 | spin_unlock(&acpi_device_lock); |
Bjorn Helgaas | 9d9f749 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 600 | acpi_driver_attach(driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 602 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 605 | EXPORT_SYMBOL(acpi_bus_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 608 | * acpi_bus_unregister_driver - unregisters a driver with the APIC bus |
| 609 | * @driver: driver to unregister |
| 610 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | * Unregisters a driver with the ACPI bus. Searches the namespace for all |
| 612 | * devices that match the driver's criteria and unbinds. |
| 613 | */ |
Bjorn Helgaas | 06ea8e08 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 614 | void acpi_bus_unregister_driver(struct acpi_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Bjorn Helgaas | 1a36561 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 616 | acpi_driver_detach(driver); |
| 617 | |
| 618 | if (!atomic_read(&driver->references)) { |
| 619 | spin_lock(&acpi_device_lock); |
| 620 | list_del_init(&driver->node); |
| 621 | spin_unlock(&acpi_device_lock); |
| 622 | } |
Bjorn Helgaas | 06ea8e08 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 623 | return; |
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 | |
| 628 | /** |
Randy Dunlap | d758a8f | 2006-01-06 01:31:00 -0500 | [diff] [blame] | 629 | * acpi_bus_find_driver - check if there is a driver installed for the device |
| 630 | * @device: device that we are trying to find a supporting driver for |
| 631 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | * Parses the list of registered drivers looking for a driver applicable for |
| 633 | * the specified device. |
| 634 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | static int acpi_bus_find_driver(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 637 | int result = 0; |
| 638 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | spin_lock(&acpi_device_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 642 | list_for_each_safe(node, next, &acpi_bus_drivers) { |
| 643 | struct acpi_driver *driver = |
| 644 | container_of(node, struct acpi_driver, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| 646 | atomic_inc(&driver->references); |
| 647 | spin_unlock(&acpi_device_lock); |
| 648 | if (!acpi_bus_match(device, driver)) { |
| 649 | result = acpi_bus_driver_init(device, driver); |
| 650 | if (!result) |
| 651 | goto Done; |
| 652 | } |
| 653 | atomic_dec(&driver->references); |
| 654 | spin_lock(&acpi_device_lock); |
| 655 | } |
| 656 | spin_unlock(&acpi_device_lock); |
| 657 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 659 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /* -------------------------------------------------------------------------- |
| 663 | Device Enumeration |
| 664 | -------------------------------------------------------------------------- */ |
| 665 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 666 | static int acpi_bus_get_flags(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 668 | acpi_status status = AE_OK; |
| 669 | acpi_handle temp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | /* Presence of _STA indicates 'dynamic_status' */ |
| 673 | status = acpi_get_handle(device->handle, "_STA", &temp); |
| 674 | if (ACPI_SUCCESS(status)) |
| 675 | device->flags.dynamic_status = 1; |
| 676 | |
| 677 | /* Presence of _CID indicates 'compatible_ids' */ |
| 678 | status = acpi_get_handle(device->handle, "_CID", &temp); |
| 679 | if (ACPI_SUCCESS(status)) |
| 680 | device->flags.compatible_ids = 1; |
| 681 | |
| 682 | /* Presence of _RMV indicates 'removable' */ |
| 683 | status = acpi_get_handle(device->handle, "_RMV", &temp); |
| 684 | if (ACPI_SUCCESS(status)) |
| 685 | device->flags.removable = 1; |
| 686 | |
| 687 | /* Presence of _EJD|_EJ0 indicates 'ejectable' */ |
| 688 | status = acpi_get_handle(device->handle, "_EJD", &temp); |
| 689 | if (ACPI_SUCCESS(status)) |
| 690 | device->flags.ejectable = 1; |
| 691 | else { |
| 692 | status = acpi_get_handle(device->handle, "_EJ0", &temp); |
| 693 | if (ACPI_SUCCESS(status)) |
| 694 | device->flags.ejectable = 1; |
| 695 | } |
| 696 | |
| 697 | /* Presence of _LCK indicates 'lockable' */ |
| 698 | status = acpi_get_handle(device->handle, "_LCK", &temp); |
| 699 | if (ACPI_SUCCESS(status)) |
| 700 | device->flags.lockable = 1; |
| 701 | |
| 702 | /* Presence of _PS0|_PR0 indicates 'power manageable' */ |
| 703 | status = acpi_get_handle(device->handle, "_PS0", &temp); |
| 704 | if (ACPI_FAILURE(status)) |
| 705 | status = acpi_get_handle(device->handle, "_PR0", &temp); |
| 706 | if (ACPI_SUCCESS(status)) |
| 707 | device->flags.power_manageable = 1; |
| 708 | |
| 709 | /* Presence of _PRW indicates wake capable */ |
| 710 | status = acpi_get_handle(device->handle, "_PRW", &temp); |
| 711 | if (ACPI_SUCCESS(status)) |
| 712 | device->flags.wake_capable = 1; |
| 713 | |
| 714 | /* TBD: Peformance management */ |
| 715 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 716 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | static void acpi_device_get_busid(struct acpi_device *device, |
| 720 | acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 722 | char bus_id[5] = { '?', 0 }; |
| 723 | struct acpi_buffer buffer = { sizeof(bus_id), bus_id }; |
| 724 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * Bus ID |
| 728 | * ------ |
| 729 | * The device's Bus ID is simply the object name. |
| 730 | * TBD: Shouldn't this value be unique (within the ACPI namespace)? |
| 731 | */ |
| 732 | switch (type) { |
| 733 | case ACPI_BUS_TYPE_SYSTEM: |
| 734 | strcpy(device->pnp.bus_id, "ACPI"); |
| 735 | break; |
| 736 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 737 | strcpy(device->pnp.bus_id, "PWRF"); |
| 738 | break; |
| 739 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 740 | strcpy(device->pnp.bus_id, "SLPF"); |
| 741 | break; |
| 742 | default: |
| 743 | acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); |
| 744 | /* Clean up trailing underscores (if any) */ |
| 745 | for (i = 3; i > 1; i--) { |
| 746 | if (bus_id[i] == '_') |
| 747 | bus_id[i] = '\0'; |
| 748 | else |
| 749 | break; |
| 750 | } |
| 751 | strcpy(device->pnp.bus_id, bus_id); |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 756 | static void acpi_device_set_id(struct acpi_device *device, |
| 757 | struct acpi_device *parent, acpi_handle handle, |
| 758 | int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 760 | struct acpi_device_info *info; |
| 761 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 762 | char *hid = NULL; |
| 763 | char *uid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | struct acpi_compatible_id_list *cid_list = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 765 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
| 767 | switch (type) { |
| 768 | case ACPI_BUS_TYPE_DEVICE: |
| 769 | status = acpi_get_object_info(handle, &buffer); |
| 770 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 771 | printk("%s: Error reading device info\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | |
| 775 | info = buffer.pointer; |
| 776 | if (info->valid & ACPI_VALID_HID) |
| 777 | hid = info->hardware_id.value; |
| 778 | if (info->valid & ACPI_VALID_UID) |
| 779 | uid = info->unique_id.value; |
| 780 | if (info->valid & ACPI_VALID_CID) |
| 781 | cid_list = &info->compatibility_id; |
| 782 | if (info->valid & ACPI_VALID_ADR) { |
| 783 | device->pnp.bus_address = info->address; |
| 784 | device->flags.bus_address = 1; |
| 785 | } |
| 786 | break; |
| 787 | case ACPI_BUS_TYPE_POWER: |
| 788 | hid = ACPI_POWER_HID; |
| 789 | break; |
| 790 | case ACPI_BUS_TYPE_PROCESSOR: |
| 791 | hid = ACPI_PROCESSOR_HID; |
| 792 | break; |
| 793 | case ACPI_BUS_TYPE_SYSTEM: |
| 794 | hid = ACPI_SYSTEM_HID; |
| 795 | break; |
| 796 | case ACPI_BUS_TYPE_THERMAL: |
| 797 | hid = ACPI_THERMAL_HID; |
| 798 | break; |
| 799 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 800 | hid = ACPI_BUTTON_HID_POWERF; |
| 801 | break; |
| 802 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 803 | hid = ACPI_BUTTON_HID_SLEEPF; |
| 804 | break; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * \_SB |
| 809 | * ---- |
| 810 | * Fix for the system root bus device -- the only root-level device. |
| 811 | */ |
Bob Moore | c51a4de | 2005-11-17 13:07:00 -0500 | [diff] [blame] | 812 | if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | hid = ACPI_BUS_HID; |
| 814 | strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); |
| 815 | strcpy(device->pnp.device_class, ACPI_BUS_CLASS); |
| 816 | } |
| 817 | |
| 818 | if (hid) { |
| 819 | strcpy(device->pnp.hardware_id, hid); |
| 820 | device->flags.hardware_id = 1; |
| 821 | } |
| 822 | if (uid) { |
| 823 | strcpy(device->pnp.unique_id, uid); |
| 824 | device->flags.unique_id = 1; |
| 825 | } |
| 826 | if (cid_list) { |
| 827 | device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL); |
| 828 | if (device->pnp.cid_list) |
| 829 | memcpy(device->pnp.cid_list, cid_list, cid_list->size); |
| 830 | else |
| 831 | printk(KERN_ERR "Memory allocation error\n"); |
| 832 | } |
| 833 | |
| 834 | acpi_os_free(buffer.pointer); |
| 835 | } |
| 836 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 837 | static int acpi_device_set_context(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | { |
| 839 | acpi_status status = AE_OK; |
| 840 | int result = 0; |
| 841 | /* |
| 842 | * Context |
| 843 | * ------- |
| 844 | * Attach this 'struct acpi_device' to the ACPI object. This makes |
| 845 | * resolutions from handle->device very efficient. Note that we need |
| 846 | * to be careful with fixed-feature devices as they all attach to the |
| 847 | * root object. |
| 848 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 849 | if (type != ACPI_BUS_TYPE_POWER_BUTTON && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | type != ACPI_BUS_TYPE_SLEEP_BUTTON) { |
| 851 | status = acpi_attach_data(device->handle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 852 | acpi_bus_data_handler, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | |
| 854 | if (ACPI_FAILURE(status)) { |
| 855 | printk("Error attaching device data\n"); |
| 856 | result = -ENODEV; |
| 857 | } |
| 858 | } |
| 859 | return result; |
| 860 | } |
| 861 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 862 | static void acpi_device_get_debug_info(struct acpi_device *device, |
| 863 | acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
| 865 | #ifdef CONFIG_ACPI_DEBUG_OUTPUT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | char *type_string = NULL; |
| 867 | char name[80] = { '?', '\0' }; |
| 868 | struct acpi_buffer buffer = { sizeof(name), name }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | switch (type) { |
| 871 | case ACPI_BUS_TYPE_DEVICE: |
| 872 | type_string = "Device"; |
| 873 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 874 | break; |
| 875 | case ACPI_BUS_TYPE_POWER: |
| 876 | type_string = "Power Resource"; |
| 877 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 878 | break; |
| 879 | case ACPI_BUS_TYPE_PROCESSOR: |
| 880 | type_string = "Processor"; |
| 881 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 882 | break; |
| 883 | case ACPI_BUS_TYPE_SYSTEM: |
| 884 | type_string = "System"; |
| 885 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 886 | break; |
| 887 | case ACPI_BUS_TYPE_THERMAL: |
| 888 | type_string = "Thermal Zone"; |
| 889 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 890 | break; |
| 891 | case ACPI_BUS_TYPE_POWER_BUTTON: |
| 892 | type_string = "Power Button"; |
| 893 | sprintf(name, "PWRB"); |
| 894 | break; |
| 895 | case ACPI_BUS_TYPE_SLEEP_BUTTON: |
| 896 | type_string = "Sleep Button"; |
| 897 | sprintf(name, "SLPB"); |
| 898 | break; |
| 899 | } |
| 900 | |
| 901 | printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 902 | #endif /*CONFIG_ACPI_DEBUG_OUTPUT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 905 | static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 907 | int result = 0; |
| 908 | struct acpi_driver *driver; |
| 909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
| 911 | if (!dev) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 912 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | driver = dev->driver; |
| 915 | |
| 916 | if ((driver) && (driver->ops.remove)) { |
| 917 | |
| 918 | if (driver->ops.stop) { |
| 919 | result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT); |
| 920 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 921 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT); |
| 925 | if (result) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 926 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | atomic_dec(&dev->driver->references); |
| 930 | dev->driver = NULL; |
| 931 | acpi_driver_data(dev) = NULL; |
| 932 | } |
| 933 | |
| 934 | if (!rmdevice) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 935 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
| 937 | if (dev->flags.bus_address) { |
| 938 | if ((dev->parent) && (dev->parent->ops.unbind)) |
| 939 | dev->parent->ops.unbind(dev); |
| 940 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); |
| 943 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 944 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 947 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 948 | acpi_add_single_object(struct acpi_device **child, |
| 949 | struct acpi_device *parent, acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 951 | int result = 0; |
| 952 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | if (!child) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 956 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
| 958 | device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); |
| 959 | if (!device) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 960 | printk(KERN_ERR PREFIX "Memory allocation error\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 961 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | } |
| 963 | memset(device, 0, sizeof(struct acpi_device)); |
| 964 | |
| 965 | device->handle = handle; |
| 966 | device->parent = parent; |
| 967 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 968 | acpi_device_get_busid(device, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
| 970 | /* |
| 971 | * Flags |
| 972 | * ----- |
| 973 | * Get prior to calling acpi_bus_get_status() so we know whether |
| 974 | * or not _STA is present. Note that we only look for object |
| 975 | * handles -- cannot evaluate objects until we know the device is |
| 976 | * present and properly initialized. |
| 977 | */ |
| 978 | result = acpi_bus_get_flags(device); |
| 979 | if (result) |
| 980 | goto end; |
| 981 | |
| 982 | /* |
| 983 | * Status |
| 984 | * ------ |
Keiichiro Tokunaga | 6940fab | 2005-03-30 23:15:47 -0500 | [diff] [blame] | 985 | * See if the device is present. We always assume that non-Device |
| 986 | * and non-Processor objects (e.g. thermal zones, power resources, |
| 987 | * etc.) are present, functioning, etc. (at least when parent object |
| 988 | * is present). Note that _STA has a different meaning for some |
| 989 | * objects (e.g. power resources) so we need to be careful how we use |
| 990 | * it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | */ |
| 992 | switch (type) { |
Keiichiro Tokunaga | 6940fab | 2005-03-30 23:15:47 -0500 | [diff] [blame] | 993 | case ACPI_BUS_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | case ACPI_BUS_TYPE_DEVICE: |
| 995 | result = acpi_bus_get_status(device); |
| 996 | if (ACPI_FAILURE(result) || !device->status.present) { |
| 997 | result = -ENOENT; |
| 998 | goto end; |
| 999 | } |
| 1000 | break; |
| 1001 | default: |
| 1002 | STRUCT_TO_INT(device->status) = 0x0F; |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * Initialize Device |
| 1008 | * ----------------- |
| 1009 | * TBD: Synch with Core's enumeration/initialization process. |
| 1010 | */ |
| 1011 | |
| 1012 | /* |
| 1013 | * Hardware ID, Unique ID, & Bus Address |
| 1014 | * ------------------------------------- |
| 1015 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1016 | acpi_device_set_id(device, parent, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
| 1018 | /* |
| 1019 | * Power Management |
| 1020 | * ---------------- |
| 1021 | */ |
| 1022 | if (device->flags.power_manageable) { |
| 1023 | result = acpi_bus_get_power_flags(device); |
| 1024 | if (result) |
| 1025 | goto end; |
| 1026 | } |
| 1027 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1028 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | * Wakeup device management |
| 1030 | *----------------------- |
| 1031 | */ |
| 1032 | if (device->flags.wake_capable) { |
| 1033 | result = acpi_bus_get_wakeup_device_flags(device); |
| 1034 | if (result) |
| 1035 | goto end; |
| 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * Performance Management |
| 1040 | * ---------------------- |
| 1041 | */ |
| 1042 | if (device->flags.performance_manageable) { |
| 1043 | result = acpi_bus_get_perf_flags(device); |
| 1044 | if (result) |
| 1045 | goto end; |
| 1046 | } |
| 1047 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1048 | if ((result = acpi_device_set_context(device, type))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | goto end; |
| 1050 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1051 | acpi_device_get_debug_info(device, handle, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1053 | acpi_device_register(device, parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* |
| 1056 | * Bind _ADR-Based Devices |
| 1057 | * ----------------------- |
| 1058 | * If there's a a bus address (_ADR) then we utilize the parent's |
| 1059 | * 'bind' function (if exists) to bind the ACPI- and natively- |
| 1060 | * enumerated device representations. |
| 1061 | */ |
| 1062 | if (device->flags.bus_address) { |
| 1063 | if (device->parent && device->parent->ops.bind) |
| 1064 | device->parent->ops.bind(device); |
| 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | * Locate & Attach Driver |
| 1069 | * ---------------------- |
| 1070 | * If there's a hardware id (_HID) or compatible ids (_CID) we check |
| 1071 | * to see if there's a driver installed for this kind of device. Note |
| 1072 | * that drivers can install before or after a device is enumerated. |
| 1073 | * |
| 1074 | * TBD: Assumes LDM provides driver hot-plug capability. |
| 1075 | */ |
Thomas Renninger | bd7ce5b | 2005-10-03 10:39:00 -0700 | [diff] [blame] | 1076 | acpi_bus_find_driver(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1078 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | if (!result) |
| 1080 | *child = device; |
| 1081 | else { |
Jesper Juhl | 6044ec8 | 2005-11-07 01:01:32 -0800 | [diff] [blame] | 1082 | kfree(device->pnp.cid_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | kfree(device); |
| 1084 | } |
| 1085 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1086 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1089 | static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1091 | acpi_status status = AE_OK; |
| 1092 | struct acpi_device *parent = NULL; |
| 1093 | struct acpi_device *child = NULL; |
| 1094 | acpi_handle phandle = NULL; |
| 1095 | acpi_handle chandle = NULL; |
| 1096 | acpi_object_type type = 0; |
| 1097 | u32 level = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | if (!start) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1101 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
| 1103 | parent = start; |
| 1104 | phandle = start->handle; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | /* |
| 1107 | * Parse through the ACPI namespace, identify all 'devices', and |
| 1108 | * create a new 'struct acpi_device' for each. |
| 1109 | */ |
| 1110 | while ((level > 0) && parent) { |
| 1111 | |
| 1112 | status = acpi_get_next_object(ACPI_TYPE_ANY, phandle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1113 | chandle, &chandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | /* |
| 1116 | * If this scope is exhausted then move our way back up. |
| 1117 | */ |
| 1118 | if (ACPI_FAILURE(status)) { |
| 1119 | level--; |
| 1120 | chandle = phandle; |
| 1121 | acpi_get_parent(phandle, &phandle); |
| 1122 | if (parent->parent) |
| 1123 | parent = parent->parent; |
| 1124 | continue; |
| 1125 | } |
| 1126 | |
| 1127 | status = acpi_get_type(chandle, &type); |
| 1128 | if (ACPI_FAILURE(status)) |
| 1129 | continue; |
| 1130 | |
| 1131 | /* |
| 1132 | * If this is a scope object then parse it (depth-first). |
| 1133 | */ |
| 1134 | if (type == ACPI_TYPE_LOCAL_SCOPE) { |
| 1135 | level++; |
| 1136 | phandle = chandle; |
| 1137 | chandle = NULL; |
| 1138 | continue; |
| 1139 | } |
| 1140 | |
| 1141 | /* |
| 1142 | * We're only interested in objects that we consider 'devices'. |
| 1143 | */ |
| 1144 | switch (type) { |
| 1145 | case ACPI_TYPE_DEVICE: |
| 1146 | type = ACPI_BUS_TYPE_DEVICE; |
| 1147 | break; |
| 1148 | case ACPI_TYPE_PROCESSOR: |
| 1149 | type = ACPI_BUS_TYPE_PROCESSOR; |
| 1150 | break; |
| 1151 | case ACPI_TYPE_THERMAL: |
| 1152 | type = ACPI_BUS_TYPE_THERMAL; |
| 1153 | break; |
| 1154 | case ACPI_TYPE_POWER: |
| 1155 | type = ACPI_BUS_TYPE_POWER; |
| 1156 | break; |
| 1157 | default: |
| 1158 | continue; |
| 1159 | } |
| 1160 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1161 | if (ops->acpi_op_add) |
| 1162 | status = acpi_add_single_object(&child, parent, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1163 | chandle, type); |
| 1164 | else |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1165 | status = acpi_bus_get_device(chandle, &child); |
| 1166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1167 | if (ACPI_FAILURE(status)) |
| 1168 | continue; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1169 | |
| 1170 | if (ops->acpi_op_start) { |
| 1171 | status = acpi_start_single_object(child); |
| 1172 | if (ACPI_FAILURE(status)) |
| 1173 | continue; |
| 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
| 1176 | /* |
| 1177 | * If the device is present, enabled, and functioning then |
| 1178 | * parse its scope (depth-first). Note that we need to |
| 1179 | * represent absent devices to facilitate PnP notifications |
| 1180 | * -- but only the subtree head (not all of its children, |
| 1181 | * which will be enumerated when the parent is inserted). |
| 1182 | * |
| 1183 | * TBD: Need notifications and other detection mechanisms |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1184 | * in place before we can fully implement this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | */ |
| 1186 | if (child->status.present) { |
| 1187 | status = acpi_get_next_object(ACPI_TYPE_ANY, chandle, |
| 1188 | NULL, NULL); |
| 1189 | if (ACPI_SUCCESS(status)) { |
| 1190 | level++; |
| 1191 | phandle = chandle; |
| 1192 | chandle = NULL; |
| 1193 | parent = child; |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1198 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1201 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1202 | acpi_bus_add(struct acpi_device **child, |
| 1203 | struct acpi_device *parent, acpi_handle handle, int type) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1204 | { |
| 1205 | int result; |
| 1206 | struct acpi_bus_ops ops; |
| 1207 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1208 | |
| 1209 | result = acpi_add_single_object(child, parent, handle, type); |
| 1210 | if (!result) { |
| 1211 | memset(&ops, 0, sizeof(ops)); |
| 1212 | ops.acpi_op_add = 1; |
| 1213 | result = acpi_bus_scan(*child, &ops); |
| 1214 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1215 | return result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1216 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1217 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1218 | EXPORT_SYMBOL(acpi_bus_add); |
| 1219 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1220 | int acpi_bus_start(struct acpi_device *device) |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1221 | { |
| 1222 | int result; |
| 1223 | struct acpi_bus_ops ops; |
| 1224 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1225 | |
| 1226 | if (!device) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1227 | return -EINVAL; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1228 | |
| 1229 | result = acpi_start_single_object(device); |
| 1230 | if (!result) { |
| 1231 | memset(&ops, 0, sizeof(ops)); |
| 1232 | ops.acpi_op_start = 1; |
| 1233 | result = acpi_bus_scan(device, &ops); |
| 1234 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1235 | return result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1236 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1237 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1238 | EXPORT_SYMBOL(acpi_bus_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
Kristen Accardi | ceaba66 | 2006-02-23 17:56:01 -0800 | [diff] [blame] | 1240 | int acpi_bus_trim(struct acpi_device *start, int rmdevice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1242 | acpi_status status; |
| 1243 | struct acpi_device *parent, *child; |
| 1244 | acpi_handle phandle, chandle; |
| 1245 | acpi_object_type type; |
| 1246 | u32 level = 1; |
| 1247 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1249 | parent = start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | phandle = start->handle; |
| 1251 | child = chandle = NULL; |
| 1252 | |
| 1253 | while ((level > 0) && parent && (!err)) { |
| 1254 | status = acpi_get_next_object(ACPI_TYPE_ANY, phandle, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1255 | chandle, &chandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
| 1257 | /* |
| 1258 | * If this scope is exhausted then move our way back up. |
| 1259 | */ |
| 1260 | if (ACPI_FAILURE(status)) { |
| 1261 | level--; |
| 1262 | chandle = phandle; |
| 1263 | acpi_get_parent(phandle, &phandle); |
| 1264 | child = parent; |
| 1265 | parent = parent->parent; |
| 1266 | |
| 1267 | if (level == 0) |
| 1268 | err = acpi_bus_remove(child, rmdevice); |
| 1269 | else |
| 1270 | err = acpi_bus_remove(child, 1); |
| 1271 | |
| 1272 | continue; |
| 1273 | } |
| 1274 | |
| 1275 | status = acpi_get_type(chandle, &type); |
| 1276 | if (ACPI_FAILURE(status)) { |
| 1277 | continue; |
| 1278 | } |
| 1279 | /* |
| 1280 | * If there is a device corresponding to chandle then |
| 1281 | * parse it (depth-first). |
| 1282 | */ |
| 1283 | if (acpi_bus_get_device(chandle, &child) == 0) { |
| 1284 | level++; |
| 1285 | phandle = chandle; |
| 1286 | chandle = NULL; |
| 1287 | parent = child; |
| 1288 | } |
| 1289 | continue; |
| 1290 | } |
| 1291 | return err; |
| 1292 | } |
Kristen Accardi | ceaba66 | 2006-02-23 17:56:01 -0800 | [diff] [blame] | 1293 | EXPORT_SYMBOL_GPL(acpi_bus_trim); |
| 1294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1296 | static int acpi_bus_scan_fixed(struct acpi_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1298 | int result = 0; |
| 1299 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
| 1302 | if (!root) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1303 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
| 1305 | /* |
| 1306 | * Enumerate all fixed-feature devices. |
| 1307 | */ |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1308 | if (acpi_fadt.pwr_button == 0) { |
| 1309 | result = acpi_add_single_object(&device, acpi_root, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1310 | NULL, |
| 1311 | ACPI_BUS_TYPE_POWER_BUTTON); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1312 | if (!result) |
| 1313 | result = acpi_start_single_object(device); |
| 1314 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1316 | if (acpi_fadt.sleep_button == 0) { |
| 1317 | result = acpi_add_single_object(&device, acpi_root, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1318 | NULL, |
| 1319 | ACPI_BUS_TYPE_SLEEP_BUTTON); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1320 | if (!result) |
| 1321 | result = acpi_start_single_object(device); |
| 1322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1324 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1327 | |
Len Brown | 531881d | 2006-05-15 03:06:41 -0400 | [diff] [blame] | 1328 | static inline struct acpi_device * to_acpi_dev(struct device * dev) |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1329 | { |
| 1330 | return container_of(dev, struct acpi_device, dev); |
| 1331 | } |
| 1332 | |
| 1333 | |
Len Brown | 531881d | 2006-05-15 03:06:41 -0400 | [diff] [blame] | 1334 | static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state) |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1335 | { |
| 1336 | struct acpi_device * dev, * next; |
| 1337 | int result; |
| 1338 | |
| 1339 | spin_lock(&acpi_device_lock); |
| 1340 | list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) { |
| 1341 | if (dev->driver && dev->driver->ops.suspend) { |
| 1342 | spin_unlock(&acpi_device_lock); |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1343 | result = dev->driver->ops.suspend(dev, 0); |
| 1344 | if (result) { |
| 1345 | printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n", |
| 1346 | acpi_device_name(dev), |
| 1347 | acpi_device_bid(dev), result); |
| 1348 | } |
| 1349 | spin_lock(&acpi_device_lock); |
| 1350 | } |
| 1351 | } |
| 1352 | spin_unlock(&acpi_device_lock); |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | static int acpi_device_suspend(struct device * dev, pm_message_t state) |
| 1358 | { |
| 1359 | struct acpi_device * acpi_dev = to_acpi_dev(dev); |
| 1360 | |
| 1361 | /* |
| 1362 | * For now, we should only register 1 generic device - |
| 1363 | * the ACPI root device - and from there, we walk the |
| 1364 | * tree of ACPI devices to suspend each one using the |
| 1365 | * ACPI driver methods. |
| 1366 | */ |
| 1367 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) |
Len Brown | 531881d | 2006-05-15 03:06:41 -0400 | [diff] [blame] | 1368 | root_suspend(acpi_dev, state); |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | static int root_resume(struct acpi_device * acpi_dev) |
| 1375 | { |
| 1376 | struct acpi_device * dev, * next; |
| 1377 | int result; |
| 1378 | |
| 1379 | spin_lock(&acpi_device_lock); |
| 1380 | list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) { |
| 1381 | if (dev->driver && dev->driver->ops.resume) { |
| 1382 | spin_unlock(&acpi_device_lock); |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1383 | result = dev->driver->ops.resume(dev, 0); |
| 1384 | if (result) { |
| 1385 | printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n", |
| 1386 | acpi_device_name(dev), |
| 1387 | acpi_device_bid(dev), result); |
| 1388 | } |
| 1389 | spin_lock(&acpi_device_lock); |
| 1390 | } |
| 1391 | } |
| 1392 | spin_unlock(&acpi_device_lock); |
| 1393 | return 0; |
| 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | static int acpi_device_resume(struct device * dev) |
| 1398 | { |
| 1399 | struct acpi_device * acpi_dev = to_acpi_dev(dev); |
| 1400 | |
| 1401 | /* |
| 1402 | * For now, we should only register 1 generic device - |
| 1403 | * the ACPI root device - and from there, we walk the |
| 1404 | * tree of ACPI devices to resume each one using the |
| 1405 | * ACPI driver methods. |
| 1406 | */ |
| 1407 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) |
| 1408 | root_resume(acpi_dev); |
| 1409 | return 0; |
| 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | struct bus_type acpi_bus_type = { |
| 1414 | .name = "acpi", |
| 1415 | .suspend = acpi_device_suspend, |
| 1416 | .resume = acpi_device_resume, |
| 1417 | }; |
| 1418 | |
| 1419 | |
| 1420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | static int __init acpi_scan_init(void) |
| 1422 | { |
| 1423 | int result; |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1424 | struct acpi_bus_ops ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
| 1427 | if (acpi_disabled) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1428 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | kset_register(&acpi_namespace_kset); |
| 1431 | |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1432 | result = bus_register(&acpi_bus_type); |
| 1433 | if (result) { |
| 1434 | /* We don't want to quit even if we failed to add suspend/resume */ |
| 1435 | printk(KERN_ERR PREFIX "Could not register bus type\n"); |
| 1436 | } |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | /* |
| 1439 | * Create the root device in the bus's device tree |
| 1440 | */ |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1441 | result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1442 | ACPI_BUS_TYPE_SYSTEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | if (result) |
| 1444 | goto Done; |
| 1445 | |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1446 | result = acpi_start_single_object(acpi_root); |
Patrick Mochel | 5b32726 | 2006-05-10 10:33:00 -0400 | [diff] [blame] | 1447 | if (result) |
| 1448 | goto Done; |
| 1449 | |
| 1450 | acpi_root->dev.bus = &acpi_bus_type; |
| 1451 | snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name); |
| 1452 | result = device_register(&acpi_root->dev); |
| 1453 | if (result) { |
| 1454 | /* We don't want to quit even if we failed to add suspend/resume */ |
| 1455 | printk(KERN_ERR PREFIX "Could not register device\n"); |
| 1456 | } |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | /* |
| 1459 | * Enumerate devices in the ACPI namespace. |
| 1460 | */ |
| 1461 | result = acpi_bus_scan_fixed(acpi_root); |
Rajesh Shah | 3fb0273 | 2005-04-28 00:25:52 -0700 | [diff] [blame] | 1462 | if (!result) { |
| 1463 | memset(&ops, 0, sizeof(ops)); |
| 1464 | ops.acpi_op_add = 1; |
| 1465 | ops.acpi_op_start = 1; |
| 1466 | result = acpi_bus_scan(acpi_root, &ops); |
| 1467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
| 1469 | if (result) |
| 1470 | acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); |
| 1471 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1472 | Done: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame^] | 1473 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | subsys_initcall(acpi_scan_init); |