diff options
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r-- | drivers/acpi/scan.c | 1220 |
1 files changed, 591 insertions, 629 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 2e0fc8c3b58b..64f26db10c8e 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -21,101 +21,305 @@ extern struct acpi_device *acpi_root; | |||
21 | #define ACPI_BUS_DEVICE_NAME "System Bus" | 21 | #define ACPI_BUS_DEVICE_NAME "System Bus" |
22 | 22 | ||
23 | static LIST_HEAD(acpi_device_list); | 23 | static LIST_HEAD(acpi_device_list); |
24 | static LIST_HEAD(acpi_bus_id_list); | ||
24 | DEFINE_SPINLOCK(acpi_device_lock); | 25 | DEFINE_SPINLOCK(acpi_device_lock); |
25 | LIST_HEAD(acpi_wakeup_device_list); | 26 | LIST_HEAD(acpi_wakeup_device_list); |
26 | 27 | ||
28 | struct acpi_device_bus_id{ | ||
29 | char bus_id[15]; | ||
30 | unsigned int instance_no; | ||
31 | struct list_head node; | ||
32 | }; | ||
33 | static int acpi_eject_operation(acpi_handle handle, int lockable) | ||
34 | { | ||
35 | struct acpi_object_list arg_list; | ||
36 | union acpi_object arg; | ||
37 | acpi_status status = AE_OK; | ||
38 | |||
39 | /* | ||
40 | * TBD: evaluate _PS3? | ||
41 | */ | ||
42 | |||
43 | if (lockable) { | ||
44 | arg_list.count = 1; | ||
45 | arg_list.pointer = &arg; | ||
46 | arg.type = ACPI_TYPE_INTEGER; | ||
47 | arg.integer.value = 0; | ||
48 | acpi_evaluate_object(handle, "_LCK", &arg_list, NULL); | ||
49 | } | ||
27 | 50 | ||
28 | static void acpi_device_release(struct kobject *kobj) | 51 | arg_list.count = 1; |
52 | arg_list.pointer = &arg; | ||
53 | arg.type = ACPI_TYPE_INTEGER; | ||
54 | arg.integer.value = 1; | ||
55 | |||
56 | /* | ||
57 | * TBD: _EJD support. | ||
58 | */ | ||
59 | |||
60 | status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); | ||
61 | if (ACPI_FAILURE(status)) { | ||
62 | return (-ENODEV); | ||
63 | } | ||
64 | |||
65 | return (0); | ||
66 | } | ||
67 | |||
68 | static ssize_t | ||
69 | acpi_eject_store(struct device *d, struct device_attribute *attr, | ||
70 | const char *buf, size_t count) | ||
29 | { | 71 | { |
30 | struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj); | 72 | int result; |
31 | kfree(dev->pnp.cid_list); | 73 | int ret = count; |
32 | kfree(dev); | 74 | int islockable; |
75 | acpi_status status; | ||
76 | acpi_handle handle; | ||
77 | acpi_object_type type = 0; | ||
78 | struct acpi_device *acpi_device = to_acpi_device(d); | ||
79 | |||
80 | if ((!count) || (buf[0] != '1')) { | ||
81 | return -EINVAL; | ||
82 | } | ||
83 | #ifndef FORCE_EJECT | ||
84 | if (acpi_device->driver == NULL) { | ||
85 | ret = -ENODEV; | ||
86 | goto err; | ||
87 | } | ||
88 | #endif | ||
89 | status = acpi_get_type(acpi_device->handle, &type); | ||
90 | if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) { | ||
91 | ret = -ENODEV; | ||
92 | goto err; | ||
93 | } | ||
94 | |||
95 | islockable = acpi_device->flags.lockable; | ||
96 | handle = acpi_device->handle; | ||
97 | |||
98 | result = acpi_bus_trim(acpi_device, 1); | ||
99 | |||
100 | if (!result) | ||
101 | result = acpi_eject_operation(handle, islockable); | ||
102 | |||
103 | if (result) { | ||
104 | ret = -EBUSY; | ||
105 | } | ||
106 | err: | ||
107 | return ret; | ||
33 | } | 108 | } |
34 | 109 | ||
35 | struct acpi_device_attribute { | 110 | static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); |
36 | struct attribute attr; | 111 | |
37 | ssize_t(*show) (struct acpi_device *, char *); | 112 | static ssize_t |
38 | ssize_t(*store) (struct acpi_device *, const char *, size_t); | 113 | acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) { |
39 | }; | 114 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
115 | |||
116 | return sprintf(buf, "%s\n", acpi_dev->pnp.hardware_id); | ||
117 | } | ||
118 | static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL); | ||
40 | 119 | ||
41 | typedef void acpi_device_sysfs_files(struct kobject *, | 120 | static ssize_t |
42 | const struct attribute *); | 121 | acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) { |
122 | struct acpi_device *acpi_dev = to_acpi_device(dev); | ||
123 | struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
124 | int result; | ||
125 | |||
126 | result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path); | ||
127 | if(result) | ||
128 | goto end; | ||
129 | |||
130 | result = sprintf(buf, "%s\n", (char*)path.pointer); | ||
131 | kfree(path.pointer); | ||
132 | end: | ||
133 | return result; | ||
134 | } | ||
135 | static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL); | ||
136 | |||
137 | static int acpi_device_setup_files(struct acpi_device *dev) | ||
138 | { | ||
139 | acpi_status status; | ||
140 | acpi_handle temp; | ||
141 | int result = 0; | ||
43 | 142 | ||
44 | static void setup_sys_fs_device_files(struct acpi_device *dev, | 143 | /* |
45 | acpi_device_sysfs_files * func); | 144 | * Devices gotten from FADT don't have a "path" attribute |
145 | */ | ||
146 | if(dev->handle) { | ||
147 | result = device_create_file(&dev->dev, &dev_attr_path); | ||
148 | if(result) | ||
149 | goto end; | ||
150 | } | ||
151 | |||
152 | if(dev->flags.hardware_id) { | ||
153 | result = device_create_file(&dev->dev, &dev_attr_hid); | ||
154 | if(result) | ||
155 | goto end; | ||
156 | } | ||
157 | |||
158 | /* | ||
159 | * If device has _EJ0, 'eject' file is created that is used to trigger | ||
160 | * hot-removal function from userland. | ||
161 | */ | ||
162 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); | ||
163 | if (ACPI_SUCCESS(status)) | ||
164 | result = device_create_file(&dev->dev, &dev_attr_eject); | ||
165 | end: | ||
166 | return result; | ||
167 | } | ||
46 | 168 | ||
47 | #define create_sysfs_device_files(dev) \ | 169 | static void acpi_device_remove_files(struct acpi_device *dev) |
48 | setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file) | 170 | { |
49 | #define remove_sysfs_device_files(dev) \ | 171 | acpi_status status; |
50 | setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file) | 172 | acpi_handle temp; |
51 | 173 | ||
52 | #define to_acpi_device(n) container_of(n, struct acpi_device, kobj) | 174 | /* |
53 | #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr); | 175 | * If device has _EJ0, 'eject' file is created that is used to trigger |
176 | * hot-removal function from userland. | ||
177 | */ | ||
178 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); | ||
179 | if (ACPI_SUCCESS(status)) | ||
180 | device_remove_file(&dev->dev, &dev_attr_eject); | ||
54 | 181 | ||
55 | static ssize_t acpi_device_attr_show(struct kobject *kobj, | 182 | if(dev->flags.hardware_id) |
56 | struct attribute *attr, char *buf) | 183 | device_remove_file(&dev->dev, &dev_attr_hid); |
184 | if(dev->handle) | ||
185 | device_remove_file(&dev->dev, &dev_attr_path); | ||
186 | } | ||
187 | /* -------------------------------------------------------------------------- | ||
188 | ACPI Bus operations | ||
189 | -------------------------------------------------------------------------- */ | ||
190 | static void acpi_device_release(struct device *dev) | ||
57 | { | 191 | { |
58 | struct acpi_device *device = to_acpi_device(kobj); | 192 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
59 | struct acpi_device_attribute *attribute = to_handle_attr(attr); | 193 | |
60 | return attribute->show ? attribute->show(device, buf) : -EIO; | 194 | kfree(acpi_dev->pnp.cid_list); |
195 | kfree(acpi_dev); | ||
61 | } | 196 | } |
62 | static ssize_t acpi_device_attr_store(struct kobject *kobj, | 197 | |
63 | struct attribute *attr, const char *buf, | 198 | static int acpi_device_suspend(struct device *dev, pm_message_t state) |
64 | size_t len) | ||
65 | { | 199 | { |
66 | struct acpi_device *device = to_acpi_device(kobj); | 200 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
67 | struct acpi_device_attribute *attribute = to_handle_attr(attr); | 201 | struct acpi_driver *acpi_drv = acpi_dev->driver; |
68 | return attribute->store ? attribute->store(device, buf, len) : -EIO; | 202 | |
203 | if (acpi_drv && acpi_drv->ops.suspend) | ||
204 | return acpi_drv->ops.suspend(acpi_dev, state); | ||
205 | return 0; | ||
69 | } | 206 | } |
70 | 207 | ||
71 | static struct sysfs_ops acpi_device_sysfs_ops = { | 208 | static int acpi_device_resume(struct device *dev) |
72 | .show = acpi_device_attr_show, | 209 | { |
73 | .store = acpi_device_attr_store, | 210 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
74 | }; | 211 | struct acpi_driver *acpi_drv = acpi_dev->driver; |
75 | 212 | ||
76 | static struct kobj_type ktype_acpi_ns = { | 213 | if (acpi_drv && acpi_drv->ops.resume) |
77 | .sysfs_ops = &acpi_device_sysfs_ops, | 214 | return acpi_drv->ops.resume(acpi_dev); |
78 | .release = acpi_device_release, | 215 | return 0; |
79 | }; | 216 | } |
80 | 217 | ||
81 | static int namespace_uevent(struct kset *kset, struct kobject *kobj, | 218 | static int acpi_bus_match(struct device *dev, struct device_driver *drv) |
82 | char **envp, int num_envp, char *buffer, | ||
83 | int buffer_size) | ||
84 | { | 219 | { |
85 | struct acpi_device *dev = to_acpi_device(kobj); | 220 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
86 | int i = 0; | 221 | struct acpi_driver *acpi_drv = to_acpi_driver(drv); |
87 | int len = 0; | ||
88 | 222 | ||
89 | if (!dev->driver) | 223 | return !acpi_match_ids(acpi_dev, acpi_drv->ids); |
90 | return 0; | 224 | } |
91 | 225 | ||
92 | if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, | 226 | static int acpi_device_uevent(struct device *dev, char **envp, int num_envp, |
93 | "PHYSDEVDRIVER=%s", dev->driver->name)) | 227 | char *buffer, int buffer_size) |
228 | { | ||
229 | struct acpi_device *acpi_dev = to_acpi_device(dev); | ||
230 | int i = 0, length = 0, ret = 0; | ||
231 | |||
232 | if (acpi_dev->flags.hardware_id) | ||
233 | ret = add_uevent_var(envp, num_envp, &i, | ||
234 | buffer, buffer_size, &length, | ||
235 | "HWID=%s", acpi_dev->pnp.hardware_id); | ||
236 | if (ret) | ||
94 | return -ENOMEM; | 237 | return -ENOMEM; |
238 | if (acpi_dev->flags.compatible_ids) { | ||
239 | int j; | ||
240 | struct acpi_compatible_id_list *cid_list; | ||
241 | |||
242 | cid_list = acpi_dev->pnp.cid_list; | ||
243 | |||
244 | for (j = 0; j < cid_list->count; j++) { | ||
245 | ret = add_uevent_var(envp, num_envp, &i, buffer, | ||
246 | buffer_size, &length, "COMPTID=%s", | ||
247 | cid_list->id[j].value); | ||
248 | if (ret) | ||
249 | return -ENOMEM; | ||
250 | } | ||
251 | } | ||
95 | 252 | ||
96 | envp[i] = NULL; | 253 | envp[i] = NULL; |
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *); | ||
258 | static int acpi_start_single_object(struct acpi_device *); | ||
259 | static int acpi_device_probe(struct device * dev) | ||
260 | { | ||
261 | struct acpi_device *acpi_dev = to_acpi_device(dev); | ||
262 | struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver); | ||
263 | int ret; | ||
264 | |||
265 | ret = acpi_bus_driver_init(acpi_dev, acpi_drv); | ||
266 | if (!ret) { | ||
267 | if (acpi_dev->bus_ops.acpi_op_start) | ||
268 | acpi_start_single_object(acpi_dev); | ||
269 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
270 | "Found driver [%s] for device [%s]\n", | ||
271 | acpi_drv->name, acpi_dev->pnp.bus_id)); | ||
272 | get_device(dev); | ||
273 | } | ||
274 | return ret; | ||
275 | } | ||
276 | |||
277 | static int acpi_device_remove(struct device * dev) | ||
278 | { | ||
279 | struct acpi_device *acpi_dev = to_acpi_device(dev); | ||
280 | struct acpi_driver *acpi_drv = acpi_dev->driver; | ||
281 | |||
282 | if (acpi_drv) { | ||
283 | if (acpi_drv->ops.stop) | ||
284 | acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type); | ||
285 | if (acpi_drv->ops.remove) | ||
286 | acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type); | ||
287 | } | ||
288 | acpi_dev->driver = NULL; | ||
289 | acpi_driver_data(dev) = NULL; | ||
97 | 290 | ||
291 | put_device(dev); | ||
98 | return 0; | 292 | return 0; |
99 | } | 293 | } |
100 | 294 | ||
101 | static struct kset_uevent_ops namespace_uevent_ops = { | 295 | static void acpi_device_shutdown(struct device *dev) |
102 | .uevent = &namespace_uevent, | 296 | { |
103 | }; | 297 | struct acpi_device *acpi_dev = to_acpi_device(dev); |
298 | struct acpi_driver *acpi_drv = acpi_dev->driver; | ||
299 | |||
300 | if (acpi_drv && acpi_drv->ops.shutdown) | ||
301 | acpi_drv->ops.shutdown(acpi_dev); | ||
104 | 302 | ||
105 | static struct kset acpi_namespace_kset = { | 303 | return ; |
106 | .kobj = { | 304 | } |
107 | .name = "namespace", | 305 | |
108 | }, | 306 | static struct bus_type acpi_bus_type = { |
109 | .subsys = &acpi_subsys, | 307 | .name = "acpi", |
110 | .ktype = &ktype_acpi_ns, | 308 | .suspend = acpi_device_suspend, |
111 | .uevent_ops = &namespace_uevent_ops, | 309 | .resume = acpi_device_resume, |
310 | .shutdown = acpi_device_shutdown, | ||
311 | .match = acpi_bus_match, | ||
312 | .probe = acpi_device_probe, | ||
313 | .remove = acpi_device_remove, | ||
314 | .uevent = acpi_device_uevent, | ||
112 | }; | 315 | }; |
113 | 316 | ||
114 | static void acpi_device_register(struct acpi_device *device, | 317 | static int acpi_device_register(struct acpi_device *device, |
115 | struct acpi_device *parent) | 318 | struct acpi_device *parent) |
116 | { | 319 | { |
117 | int err; | 320 | int result; |
118 | 321 | struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id; | |
322 | int found = 0; | ||
119 | /* | 323 | /* |
120 | * Linkage | 324 | * Linkage |
121 | * ------- | 325 | * ------- |
@@ -126,7 +330,33 @@ static void acpi_device_register(struct acpi_device *device, | |||
126 | INIT_LIST_HEAD(&device->g_list); | 330 | INIT_LIST_HEAD(&device->g_list); |
127 | INIT_LIST_HEAD(&device->wakeup_list); | 331 | INIT_LIST_HEAD(&device->wakeup_list); |
128 | 332 | ||
333 | new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL); | ||
334 | if (!new_bus_id) { | ||
335 | printk(KERN_ERR PREFIX "Memory allocation error\n"); | ||
336 | return -ENOMEM; | ||
337 | } | ||
338 | |||
129 | spin_lock(&acpi_device_lock); | 339 | spin_lock(&acpi_device_lock); |
340 | /* | ||
341 | * Find suitable bus_id and instance number in acpi_bus_id_list | ||
342 | * If failed, create one and link it into acpi_bus_id_list | ||
343 | */ | ||
344 | list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) { | ||
345 | if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) { | ||
346 | acpi_device_bus_id->instance_no ++; | ||
347 | found = 1; | ||
348 | kfree(new_bus_id); | ||
349 | break; | ||
350 | } | ||
351 | } | ||
352 | if(!found) { | ||
353 | acpi_device_bus_id = new_bus_id; | ||
354 | strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device"); | ||
355 | acpi_device_bus_id->instance_no = 0; | ||
356 | list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list); | ||
357 | } | ||
358 | sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no); | ||
359 | |||
130 | if (device->parent) { | 360 | if (device->parent) { |
131 | list_add_tail(&device->node, &device->parent->children); | 361 | list_add_tail(&device->node, &device->parent->children); |
132 | list_add_tail(&device->g_list, &device->parent->g_list); | 362 | list_add_tail(&device->g_list, &device->parent->g_list); |
@@ -136,16 +366,33 @@ static void acpi_device_register(struct acpi_device *device, | |||
136 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); | 366 | list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list); |
137 | spin_unlock(&acpi_device_lock); | 367 | spin_unlock(&acpi_device_lock); |
138 | 368 | ||
139 | strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN); | 369 | if (device->parent) |
140 | if (parent) | 370 | device->dev.parent = &parent->dev; |
141 | device->kobj.parent = &parent->kobj; | 371 | device->dev.bus = &acpi_bus_type; |
142 | device->kobj.ktype = &ktype_acpi_ns; | 372 | device_initialize(&device->dev); |
143 | device->kobj.kset = &acpi_namespace_kset; | 373 | device->dev.release = &acpi_device_release; |
144 | err = kobject_register(&device->kobj); | 374 | result = device_add(&device->dev); |
145 | if (err < 0) | 375 | if(result) { |
146 | printk(KERN_WARNING "%s: kobject_register error: %d\n", | 376 | printk("Error adding device %s", device->dev.bus_id); |
147 | __FUNCTION__, err); | 377 | goto end; |
148 | create_sysfs_device_files(device); | 378 | } |
379 | |||
380 | result = acpi_device_setup_files(device); | ||
381 | if(result) | ||
382 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id)); | ||
383 | |||
384 | device->removal_type = ACPI_BUS_REMOVAL_NORMAL; | ||
385 | return 0; | ||
386 | end: | ||
387 | spin_lock(&acpi_device_lock); | ||
388 | if (device->parent) { | ||
389 | list_del(&device->node); | ||
390 | list_del(&device->g_list); | ||
391 | } else | ||
392 | list_del(&device->g_list); | ||
393 | list_del(&device->wakeup_list); | ||
394 | spin_unlock(&acpi_device_lock); | ||
395 | return result; | ||
149 | } | 396 | } |
150 | 397 | ||
151 | static void acpi_device_unregister(struct acpi_device *device, int type) | 398 | static void acpi_device_unregister(struct acpi_device *device, int type) |
@@ -158,81 +405,143 @@ static void acpi_device_unregister(struct acpi_device *device, int type) | |||
158 | list_del(&device->g_list); | 405 | list_del(&device->g_list); |
159 | 406 | ||
160 | list_del(&device->wakeup_list); | 407 | list_del(&device->wakeup_list); |
161 | |||
162 | spin_unlock(&acpi_device_lock); | 408 | spin_unlock(&acpi_device_lock); |
163 | 409 | ||
164 | acpi_detach_data(device->handle, acpi_bus_data_handler); | 410 | acpi_detach_data(device->handle, acpi_bus_data_handler); |
165 | remove_sysfs_device_files(device); | 411 | |
166 | kobject_unregister(&device->kobj); | 412 | acpi_device_remove_files(device); |
413 | device_unregister(&device->dev); | ||
167 | } | 414 | } |
168 | 415 | ||
169 | void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) | 416 | /* -------------------------------------------------------------------------- |
417 | Driver Management | ||
418 | -------------------------------------------------------------------------- */ | ||
419 | /** | ||
420 | * acpi_bus_driver_init - add a device to a driver | ||
421 | * @device: the device to add and initialize | ||
422 | * @driver: driver for the device | ||
423 | * | ||
424 | * Used to initialize a device via its device driver. Called whenever a | ||
425 | * driver is bound to a device. Invokes the driver's add() ops. | ||
426 | */ | ||
427 | static int | ||
428 | acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver) | ||
170 | { | 429 | { |
430 | int result = 0; | ||
171 | 431 | ||
172 | /* TBD */ | ||
173 | 432 | ||
174 | return; | 433 | if (!device || !driver) |
175 | } | 434 | return -EINVAL; |
176 | 435 | ||
177 | static int acpi_bus_get_power_flags(struct acpi_device *device) | 436 | if (!driver->ops.add) |
178 | { | 437 | return -ENOSYS; |
179 | acpi_status status = 0; | ||
180 | acpi_handle handle = NULL; | ||
181 | u32 i = 0; | ||
182 | 438 | ||
439 | result = driver->ops.add(device); | ||
440 | if (result) { | ||
441 | device->driver = NULL; | ||
442 | acpi_driver_data(device) = NULL; | ||
443 | return result; | ||
444 | } | ||
183 | 445 | ||
184 | /* | 446 | device->driver = driver; |
185 | * Power Management Flags | ||
186 | */ | ||
187 | status = acpi_get_handle(device->handle, "_PSC", &handle); | ||
188 | if (ACPI_SUCCESS(status)) | ||
189 | device->power.flags.explicit_get = 1; | ||
190 | status = acpi_get_handle(device->handle, "_IRC", &handle); | ||
191 | if (ACPI_SUCCESS(status)) | ||
192 | device->power.flags.inrush_current = 1; | ||
193 | 447 | ||
194 | /* | 448 | /* |
195 | * Enumerate supported power management states | 449 | * TBD - Configuration Management: Assign resources to device based |
450 | * upon possible configuration and currently allocated resources. | ||
196 | */ | 451 | */ |
197 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) { | ||
198 | struct acpi_device_power_state *ps = &device->power.states[i]; | ||
199 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; | ||
200 | 452 | ||
201 | /* Evaluate "_PRx" to se if power resources are referenced */ | 453 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
202 | acpi_evaluate_reference(device->handle, object_name, NULL, | 454 | "Driver successfully bound to device\n")); |
203 | &ps->resources); | 455 | return 0; |
204 | if (ps->resources.count) { | 456 | } |
205 | device->power.flags.power_resources = 1; | ||
206 | ps->flags.valid = 1; | ||
207 | } | ||
208 | 457 | ||
209 | /* Evaluate "_PSx" to see if we can do explicit sets */ | 458 | static int acpi_start_single_object(struct acpi_device *device) |
210 | object_name[2] = 'S'; | 459 | { |
211 | status = acpi_get_handle(device->handle, object_name, &handle); | 460 | int result = 0; |
212 | if (ACPI_SUCCESS(status)) { | 461 | struct acpi_driver *driver; |
213 | ps->flags.explicit_set = 1; | ||
214 | ps->flags.valid = 1; | ||
215 | } | ||
216 | 462 | ||
217 | /* State is valid if we have some power control */ | ||
218 | if (ps->resources.count || ps->flags.explicit_set) | ||
219 | ps->flags.valid = 1; | ||
220 | 463 | ||
221 | ps->power = -1; /* Unknown - driver assigned */ | 464 | if (!(driver = device->driver)) |
222 | ps->latency = -1; /* Unknown - driver assigned */ | 465 | return 0; |
466 | |||
467 | if (driver->ops.start) { | ||
468 | result = driver->ops.start(device); | ||
469 | if (result && driver->ops.remove) | ||
470 | driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); | ||
223 | } | 471 | } |
224 | 472 | ||
225 | /* Set defaults for D0 and D3 states (always valid) */ | 473 | return result; |
226 | device->power.states[ACPI_STATE_D0].flags.valid = 1; | 474 | } |
227 | device->power.states[ACPI_STATE_D0].power = 100; | ||
228 | device->power.states[ACPI_STATE_D3].flags.valid = 1; | ||
229 | device->power.states[ACPI_STATE_D3].power = 0; | ||
230 | 475 | ||
231 | /* TBD: System wake support and resource requirements. */ | 476 | /** |
477 | * acpi_bus_register_driver - register a driver with the ACPI bus | ||
478 | * @driver: driver being registered | ||
479 | * | ||
480 | * Registers a driver with the ACPI bus. Searches the namespace for all | ||
481 | * devices that match the driver's criteria and binds. Returns zero for | ||
482 | * success or a negative error status for failure. | ||
483 | */ | ||
484 | int acpi_bus_register_driver(struct acpi_driver *driver) | ||
485 | { | ||
486 | int ret; | ||
232 | 487 | ||
233 | device->power.state = ACPI_STATE_UNKNOWN; | 488 | if (acpi_disabled) |
489 | return -ENODEV; | ||
490 | driver->drv.name = driver->name; | ||
491 | driver->drv.bus = &acpi_bus_type; | ||
492 | driver->drv.owner = driver->owner; | ||
234 | 493 | ||
235 | return 0; | 494 | ret = driver_register(&driver->drv); |
495 | return ret; | ||
496 | } | ||
497 | |||
498 | EXPORT_SYMBOL(acpi_bus_register_driver); | ||
499 | |||
500 | /** | ||
501 | * acpi_bus_unregister_driver - unregisters a driver with the APIC bus | ||
502 | * @driver: driver to unregister | ||
503 | * | ||
504 | * Unregisters a driver with the ACPI bus. Searches the namespace for all | ||
505 | * devices that match the driver's criteria and unbinds. | ||
506 | */ | ||
507 | void acpi_bus_unregister_driver(struct acpi_driver *driver) | ||
508 | { | ||
509 | driver_unregister(&driver->drv); | ||
510 | } | ||
511 | |||
512 | EXPORT_SYMBOL(acpi_bus_unregister_driver); | ||
513 | |||
514 | /* -------------------------------------------------------------------------- | ||
515 | Device Enumeration | ||
516 | -------------------------------------------------------------------------- */ | ||
517 | acpi_status | ||
518 | acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd) | ||
519 | { | ||
520 | acpi_status status; | ||
521 | acpi_handle tmp; | ||
522 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
523 | union acpi_object *obj; | ||
524 | |||
525 | status = acpi_get_handle(handle, "_EJD", &tmp); | ||
526 | if (ACPI_FAILURE(status)) | ||
527 | return status; | ||
528 | |||
529 | status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer); | ||
530 | if (ACPI_SUCCESS(status)) { | ||
531 | obj = buffer.pointer; | ||
532 | status = acpi_get_handle(NULL, obj->string.pointer, ejd); | ||
533 | kfree(buffer.pointer); | ||
534 | } | ||
535 | return status; | ||
536 | } | ||
537 | EXPORT_SYMBOL_GPL(acpi_bus_get_ejd); | ||
538 | |||
539 | void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context) | ||
540 | { | ||
541 | |||
542 | /* TBD */ | ||
543 | |||
544 | return; | ||
236 | } | 545 | } |
237 | 546 | ||
238 | int acpi_match_ids(struct acpi_device *device, char *ids) | 547 | int acpi_match_ids(struct acpi_device *device, char *ids) |
@@ -254,6 +563,12 @@ int acpi_match_ids(struct acpi_device *device, char *ids) | |||
254 | return -ENOENT; | 563 | return -ENOENT; |
255 | } | 564 | } |
256 | 565 | ||
566 | static int acpi_bus_get_perf_flags(struct acpi_device *device) | ||
567 | { | ||
568 | device->performance.state = ACPI_STATE_UNKNOWN; | ||
569 | return 0; | ||
570 | } | ||
571 | |||
257 | static acpi_status | 572 | static acpi_status |
258 | acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device, | 573 | acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device, |
259 | union acpi_object *package) | 574 | union acpi_object *package) |
@@ -338,359 +653,66 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
338 | return 0; | 653 | return 0; |
339 | } | 654 | } |
340 | 655 | ||
341 | /* -------------------------------------------------------------------------- | 656 | static int acpi_bus_get_power_flags(struct acpi_device *device) |
342 | ACPI sysfs device file support | ||
343 | -------------------------------------------------------------------------- */ | ||
344 | static ssize_t acpi_eject_store(struct acpi_device *device, | ||
345 | const char *buf, size_t count); | ||
346 | |||
347 | #define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \ | ||
348 | static struct acpi_device_attribute acpi_device_attr_##_name = \ | ||
349 | __ATTR(_name, _mode, _show, _store) | ||
350 | |||
351 | ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); | ||
352 | |||
353 | /** | ||
354 | * setup_sys_fs_device_files - sets up the device files under device namespace | ||
355 | * @dev: acpi_device object | ||
356 | * @func: function pointer to create or destroy the device file | ||
357 | */ | ||
358 | static void | ||
359 | setup_sys_fs_device_files(struct acpi_device *dev, | ||
360 | acpi_device_sysfs_files * func) | ||
361 | { | ||
362 | acpi_status status; | ||
363 | acpi_handle temp = NULL; | ||
364 | |||
365 | /* | ||
366 | * If device has _EJ0, 'eject' file is created that is used to trigger | ||
367 | * hot-removal function from userland. | ||
368 | */ | ||
369 | status = acpi_get_handle(dev->handle, "_EJ0", &temp); | ||
370 | if (ACPI_SUCCESS(status)) | ||
371 | (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr); | ||
372 | } | ||
373 | |||
374 | static int acpi_eject_operation(acpi_handle handle, int lockable) | ||
375 | { | 657 | { |
376 | struct acpi_object_list arg_list; | 658 | acpi_status status = 0; |
377 | union acpi_object arg; | 659 | acpi_handle handle = NULL; |
378 | acpi_status status = AE_OK; | 660 | u32 i = 0; |
379 | |||
380 | /* | ||
381 | * TBD: evaluate _PS3? | ||
382 | */ | ||
383 | |||
384 | if (lockable) { | ||
385 | arg_list.count = 1; | ||
386 | arg_list.pointer = &arg; | ||
387 | arg.type = ACPI_TYPE_INTEGER; | ||
388 | arg.integer.value = 0; | ||
389 | acpi_evaluate_object(handle, "_LCK", &arg_list, NULL); | ||
390 | } | ||
391 | 661 | ||
392 | arg_list.count = 1; | ||
393 | arg_list.pointer = &arg; | ||
394 | arg.type = ACPI_TYPE_INTEGER; | ||
395 | arg.integer.value = 1; | ||
396 | 662 | ||
397 | /* | 663 | /* |
398 | * TBD: _EJD support. | 664 | * Power Management Flags |
399 | */ | 665 | */ |
400 | 666 | status = acpi_get_handle(device->handle, "_PSC", &handle); | |
401 | status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); | 667 | if (ACPI_SUCCESS(status)) |
402 | if (ACPI_FAILURE(status)) { | 668 | device->power.flags.explicit_get = 1; |
403 | return (-ENODEV); | 669 | status = acpi_get_handle(device->handle, "_IRC", &handle); |
404 | } | 670 | if (ACPI_SUCCESS(status)) |
405 | 671 | device->power.flags.inrush_current = 1; | |
406 | return (0); | ||
407 | } | ||
408 | |||
409 | static ssize_t | ||
410 | acpi_eject_store(struct acpi_device *device, const char *buf, size_t count) | ||
411 | { | ||
412 | int result; | ||
413 | int ret = count; | ||
414 | int islockable; | ||
415 | acpi_status status; | ||
416 | acpi_handle handle; | ||
417 | acpi_object_type type = 0; | ||
418 | |||
419 | if ((!count) || (buf[0] != '1')) { | ||
420 | return -EINVAL; | ||
421 | } | ||
422 | #ifndef FORCE_EJECT | ||
423 | if (device->driver == NULL) { | ||
424 | ret = -ENODEV; | ||
425 | goto err; | ||
426 | } | ||
427 | #endif | ||
428 | status = acpi_get_type(device->handle, &type); | ||
429 | if (ACPI_FAILURE(status) || (!device->flags.ejectable)) { | ||
430 | ret = -ENODEV; | ||
431 | goto err; | ||
432 | } | ||
433 | |||
434 | islockable = device->flags.lockable; | ||
435 | handle = device->handle; | ||
436 | |||
437 | result = acpi_bus_trim(device, 1); | ||
438 | |||
439 | if (!result) | ||
440 | result = acpi_eject_operation(handle, islockable); | ||
441 | |||
442 | if (result) { | ||
443 | ret = -EBUSY; | ||
444 | } | ||
445 | err: | ||
446 | return ret; | ||
447 | } | ||
448 | |||
449 | /* -------------------------------------------------------------------------- | ||
450 | Performance Management | ||
451 | -------------------------------------------------------------------------- */ | ||
452 | |||
453 | static int acpi_bus_get_perf_flags(struct acpi_device *device) | ||
454 | { | ||
455 | device->performance.state = ACPI_STATE_UNKNOWN; | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | /* -------------------------------------------------------------------------- | ||
460 | Driver Management | ||
461 | -------------------------------------------------------------------------- */ | ||
462 | |||
463 | static LIST_HEAD(acpi_bus_drivers); | ||
464 | |||
465 | /** | ||
466 | * acpi_bus_match - match device IDs to driver's supported IDs | ||
467 | * @device: the device that we are trying to match to a driver | ||
468 | * @driver: driver whose device id table is being checked | ||
469 | * | ||
470 | * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it | ||
471 | * matches the specified driver's criteria. | ||
472 | */ | ||
473 | static int | ||
474 | acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver) | ||
475 | { | ||
476 | if (driver && driver->ops.match) | ||
477 | return driver->ops.match(device, driver); | ||
478 | return acpi_match_ids(device, driver->ids); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * acpi_bus_driver_init - add a device to a driver | ||
483 | * @device: the device to add and initialize | ||
484 | * @driver: driver for the device | ||
485 | * | ||
486 | * Used to initialize a device via its device driver. Called whenever a | ||
487 | * driver is bound to a device. Invokes the driver's add() and start() ops. | ||
488 | */ | ||
489 | static int | ||
490 | acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver) | ||
491 | { | ||
492 | int result = 0; | ||
493 | |||
494 | |||
495 | if (!device || !driver) | ||
496 | return -EINVAL; | ||
497 | |||
498 | if (!driver->ops.add) | ||
499 | return -ENOSYS; | ||
500 | |||
501 | result = driver->ops.add(device); | ||
502 | if (result) { | ||
503 | device->driver = NULL; | ||
504 | acpi_driver_data(device) = NULL; | ||
505 | return result; | ||
506 | } | ||
507 | |||
508 | device->driver = driver; | ||
509 | 672 | ||
510 | /* | 673 | /* |
511 | * TBD - Configuration Management: Assign resources to device based | 674 | * Enumerate supported power management states |
512 | * upon possible configuration and currently allocated resources. | ||
513 | */ | 675 | */ |
676 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) { | ||
677 | struct acpi_device_power_state *ps = &device->power.states[i]; | ||
678 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; | ||
514 | 679 | ||
515 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 680 | /* Evaluate "_PRx" to se if power resources are referenced */ |
516 | "Driver successfully bound to device\n")); | 681 | acpi_evaluate_reference(device->handle, object_name, NULL, |
517 | return 0; | 682 | &ps->resources); |
518 | } | 683 | if (ps->resources.count) { |
519 | 684 | device->power.flags.power_resources = 1; | |
520 | static int acpi_start_single_object(struct acpi_device *device) | 685 | ps->flags.valid = 1; |
521 | { | ||
522 | int result = 0; | ||
523 | struct acpi_driver *driver; | ||
524 | |||
525 | |||
526 | if (!(driver = device->driver)) | ||
527 | return 0; | ||
528 | |||
529 | if (driver->ops.start) { | ||
530 | result = driver->ops.start(device); | ||
531 | if (result && driver->ops.remove) | ||
532 | driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL); | ||
533 | } | ||
534 | |||
535 | return result; | ||
536 | } | ||
537 | |||
538 | static void acpi_driver_attach(struct acpi_driver *drv) | ||
539 | { | ||
540 | struct list_head *node, *next; | ||
541 | |||
542 | |||
543 | spin_lock(&acpi_device_lock); | ||
544 | list_for_each_safe(node, next, &acpi_device_list) { | ||
545 | struct acpi_device *dev = | ||
546 | container_of(node, struct acpi_device, g_list); | ||
547 | |||
548 | if (dev->driver || !dev->status.present) | ||
549 | continue; | ||
550 | spin_unlock(&acpi_device_lock); | ||
551 | |||
552 | if (!acpi_bus_match(dev, drv)) { | ||
553 | if (!acpi_bus_driver_init(dev, drv)) { | ||
554 | acpi_start_single_object(dev); | ||
555 | atomic_inc(&drv->references); | ||
556 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
557 | "Found driver [%s] for device [%s]\n", | ||
558 | drv->name, dev->pnp.bus_id)); | ||
559 | } | ||
560 | } | 686 | } |
561 | spin_lock(&acpi_device_lock); | ||
562 | } | ||
563 | spin_unlock(&acpi_device_lock); | ||
564 | } | ||
565 | |||
566 | static void acpi_driver_detach(struct acpi_driver *drv) | ||
567 | { | ||
568 | struct list_head *node, *next; | ||
569 | 687 | ||
570 | 688 | /* Evaluate "_PSx" to see if we can do explicit sets */ | |
571 | spin_lock(&acpi_device_lock); | 689 | object_name[2] = 'S'; |
572 | list_for_each_safe(node, next, &acpi_device_list) { | 690 | status = acpi_get_handle(device->handle, object_name, &handle); |
573 | struct acpi_device *dev = | 691 | if (ACPI_SUCCESS(status)) { |
574 | container_of(node, struct acpi_device, g_list); | 692 | ps->flags.explicit_set = 1; |
575 | 693 | ps->flags.valid = 1; | |
576 | if (dev->driver == drv) { | ||
577 | spin_unlock(&acpi_device_lock); | ||
578 | if (drv->ops.remove) | ||
579 | drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL); | ||
580 | spin_lock(&acpi_device_lock); | ||
581 | dev->driver = NULL; | ||
582 | dev->driver_data = NULL; | ||
583 | atomic_dec(&drv->references); | ||
584 | } | 694 | } |
585 | } | ||
586 | spin_unlock(&acpi_device_lock); | ||
587 | } | ||
588 | |||
589 | /** | ||
590 | * acpi_bus_register_driver - register a driver with the ACPI bus | ||
591 | * @driver: driver being registered | ||
592 | * | ||
593 | * Registers a driver with the ACPI bus. Searches the namespace for all | ||
594 | * devices that match the driver's criteria and binds. Returns zero for | ||
595 | * success or a negative error status for failure. | ||
596 | */ | ||
597 | int acpi_bus_register_driver(struct acpi_driver *driver) | ||
598 | { | ||
599 | |||
600 | if (acpi_disabled) | ||
601 | return -ENODEV; | ||
602 | |||
603 | spin_lock(&acpi_device_lock); | ||
604 | list_add_tail(&driver->node, &acpi_bus_drivers); | ||
605 | spin_unlock(&acpi_device_lock); | ||
606 | acpi_driver_attach(driver); | ||
607 | |||
608 | return 0; | ||
609 | } | ||
610 | |||
611 | EXPORT_SYMBOL(acpi_bus_register_driver); | ||
612 | |||
613 | /** | ||
614 | * acpi_bus_unregister_driver - unregisters a driver with the APIC bus | ||
615 | * @driver: driver to unregister | ||
616 | * | ||
617 | * Unregisters a driver with the ACPI bus. Searches the namespace for all | ||
618 | * devices that match the driver's criteria and unbinds. | ||
619 | */ | ||
620 | void acpi_bus_unregister_driver(struct acpi_driver *driver) | ||
621 | { | ||
622 | acpi_driver_detach(driver); | ||
623 | |||
624 | if (!atomic_read(&driver->references)) { | ||
625 | spin_lock(&acpi_device_lock); | ||
626 | list_del_init(&driver->node); | ||
627 | spin_unlock(&acpi_device_lock); | ||
628 | } | ||
629 | return; | ||
630 | } | ||
631 | |||
632 | EXPORT_SYMBOL(acpi_bus_unregister_driver); | ||
633 | |||
634 | /** | ||
635 | * acpi_bus_find_driver - check if there is a driver installed for the device | ||
636 | * @device: device that we are trying to find a supporting driver for | ||
637 | * | ||
638 | * Parses the list of registered drivers looking for a driver applicable for | ||
639 | * the specified device. | ||
640 | */ | ||
641 | static int acpi_bus_find_driver(struct acpi_device *device) | ||
642 | { | ||
643 | int result = 0; | ||
644 | struct list_head *node, *next; | ||
645 | 695 | ||
696 | /* State is valid if we have some power control */ | ||
697 | if (ps->resources.count || ps->flags.explicit_set) | ||
698 | ps->flags.valid = 1; | ||
646 | 699 | ||
647 | spin_lock(&acpi_device_lock); | 700 | ps->power = -1; /* Unknown - driver assigned */ |
648 | list_for_each_safe(node, next, &acpi_bus_drivers) { | 701 | ps->latency = -1; /* Unknown - driver assigned */ |
649 | struct acpi_driver *driver = | ||
650 | container_of(node, struct acpi_driver, node); | ||
651 | |||
652 | atomic_inc(&driver->references); | ||
653 | spin_unlock(&acpi_device_lock); | ||
654 | if (!acpi_bus_match(device, driver)) { | ||
655 | result = acpi_bus_driver_init(device, driver); | ||
656 | if (!result) | ||
657 | goto Done; | ||
658 | } | ||
659 | atomic_dec(&driver->references); | ||
660 | spin_lock(&acpi_device_lock); | ||
661 | } | 702 | } |
662 | spin_unlock(&acpi_device_lock); | ||
663 | |||
664 | Done: | ||
665 | return result; | ||
666 | } | ||
667 | 703 | ||
668 | /* -------------------------------------------------------------------------- | 704 | /* Set defaults for D0 and D3 states (always valid) */ |
669 | Device Enumeration | 705 | device->power.states[ACPI_STATE_D0].flags.valid = 1; |
670 | -------------------------------------------------------------------------- */ | 706 | device->power.states[ACPI_STATE_D0].power = 100; |
707 | device->power.states[ACPI_STATE_D3].flags.valid = 1; | ||
708 | device->power.states[ACPI_STATE_D3].power = 0; | ||
671 | 709 | ||
672 | acpi_status | 710 | /* TBD: System wake support and resource requirements. */ |
673 | acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd) | ||
674 | { | ||
675 | acpi_status status; | ||
676 | acpi_handle tmp; | ||
677 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
678 | union acpi_object *obj; | ||
679 | 711 | ||
680 | status = acpi_get_handle(handle, "_EJD", &tmp); | 712 | device->power.state = ACPI_STATE_UNKNOWN; |
681 | if (ACPI_FAILURE(status)) | ||
682 | return status; | ||
683 | 713 | ||
684 | status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer); | 714 | return 0; |
685 | if (ACPI_SUCCESS(status)) { | ||
686 | obj = buffer.pointer; | ||
687 | status = acpi_get_handle(NULL, obj->string.pointer, ejd); | ||
688 | kfree(buffer.pointer); | ||
689 | } | ||
690 | return status; | ||
691 | } | 715 | } |
692 | EXPORT_SYMBOL_GPL(acpi_bus_get_ejd); | ||
693 | |||
694 | 716 | ||
695 | static int acpi_bus_get_flags(struct acpi_device *device) | 717 | static int acpi_bus_get_flags(struct acpi_device *device) |
696 | { | 718 | { |
@@ -782,6 +804,75 @@ static void acpi_device_get_busid(struct acpi_device *device, | |||
782 | } | 804 | } |
783 | } | 805 | } |
784 | 806 | ||
807 | static int | ||
808 | acpi_video_bus_match(struct acpi_device *device) | ||
809 | { | ||
810 | acpi_handle h_dummy1; | ||
811 | acpi_handle h_dummy2; | ||
812 | acpi_handle h_dummy3; | ||
813 | |||
814 | |||
815 | if (!device) | ||
816 | return -EINVAL; | ||
817 | |||
818 | /* Since there is no HID, CID for ACPI Video drivers, we have | ||
819 | * to check well known required nodes for each feature we support. | ||
820 | */ | ||
821 | |||
822 | /* Does this device able to support video switching ? */ | ||
823 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) && | ||
824 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2))) | ||
825 | return 0; | ||
826 | |||
827 | /* Does this device able to retrieve a video ROM ? */ | ||
828 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1))) | ||
829 | return 0; | ||
830 | |||
831 | /* Does this device able to configure which video head to be POSTed ? */ | ||
832 | if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) && | ||
833 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) && | ||
834 | ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3))) | ||
835 | return 0; | ||
836 | |||
837 | return -ENODEV; | ||
838 | } | ||
839 | |||
840 | /* | ||
841 | * acpi_bay_match - see if a device is an ejectable driver bay | ||
842 | * | ||
843 | * If an acpi object is ejectable and has one of the ACPI ATA methods defined, | ||
844 | * then we can safely call it an ejectable drive bay | ||
845 | */ | ||
846 | static int acpi_bay_match(struct acpi_device *device){ | ||
847 | acpi_status status; | ||
848 | acpi_handle handle; | ||
849 | acpi_handle tmp; | ||
850 | acpi_handle phandle; | ||
851 | |||
852 | handle = device->handle; | ||
853 | |||
854 | status = acpi_get_handle(handle, "_EJ0", &tmp); | ||
855 | if (ACPI_FAILURE(status)) | ||
856 | return -ENODEV; | ||
857 | |||
858 | if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) || | ||
859 | (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) || | ||
860 | (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) || | ||
861 | (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp)))) | ||
862 | return 0; | ||
863 | |||
864 | if (acpi_get_parent(handle, &phandle)) | ||
865 | return -ENODEV; | ||
866 | |||
867 | if ((ACPI_SUCCESS(acpi_get_handle(phandle, "_GTF", &tmp))) || | ||
868 | (ACPI_SUCCESS(acpi_get_handle(phandle, "_GTM", &tmp))) || | ||
869 | (ACPI_SUCCESS(acpi_get_handle(phandle, "_STM", &tmp))) || | ||
870 | (ACPI_SUCCESS(acpi_get_handle(phandle, "_SDD", &tmp)))) | ||
871 | return 0; | ||
872 | |||
873 | return -ENODEV; | ||
874 | } | ||
875 | |||
785 | static void acpi_device_set_id(struct acpi_device *device, | 876 | static void acpi_device_set_id(struct acpi_device *device, |
786 | struct acpi_device *parent, acpi_handle handle, | 877 | struct acpi_device *parent, acpi_handle handle, |
787 | int type) | 878 | int type) |
@@ -812,6 +903,16 @@ static void acpi_device_set_id(struct acpi_device *device, | |||
812 | device->pnp.bus_address = info->address; | 903 | device->pnp.bus_address = info->address; |
813 | device->flags.bus_address = 1; | 904 | device->flags.bus_address = 1; |
814 | } | 905 | } |
906 | |||
907 | if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){ | ||
908 | status = acpi_video_bus_match(device); | ||
909 | if(ACPI_SUCCESS(status)) | ||
910 | hid = ACPI_VIDEO_HID; | ||
911 | |||
912 | status = acpi_bay_match(device); | ||
913 | if (ACPI_SUCCESS(status)) | ||
914 | hid = ACPI_BAY_HID; | ||
915 | } | ||
815 | break; | 916 | break; |
816 | case ACPI_BUS_TYPE_POWER: | 917 | case ACPI_BUS_TYPE_POWER: |
817 | hid = ACPI_POWER_HID; | 918 | hid = ACPI_POWER_HID; |
@@ -890,41 +991,22 @@ static int acpi_device_set_context(struct acpi_device *device, int type) | |||
890 | 991 | ||
891 | static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) | 992 | static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) |
892 | { | 993 | { |
893 | int result = 0; | ||
894 | struct acpi_driver *driver; | ||
895 | |||
896 | |||
897 | if (!dev) | 994 | if (!dev) |
898 | return -EINVAL; | 995 | return -EINVAL; |
899 | 996 | ||
900 | driver = dev->driver; | 997 | dev->removal_type = ACPI_BUS_REMOVAL_EJECT; |
901 | 998 | device_release_driver(&dev->dev); | |
902 | if ((driver) && (driver->ops.remove)) { | ||
903 | |||
904 | if (driver->ops.stop) { | ||
905 | result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT); | ||
906 | if (result) | ||
907 | return result; | ||
908 | } | ||
909 | |||
910 | result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT); | ||
911 | if (result) { | ||
912 | return result; | ||
913 | } | ||
914 | |||
915 | atomic_dec(&dev->driver->references); | ||
916 | dev->driver = NULL; | ||
917 | acpi_driver_data(dev) = NULL; | ||
918 | } | ||
919 | 999 | ||
920 | if (!rmdevice) | 1000 | if (!rmdevice) |
921 | return 0; | 1001 | return 0; |
922 | 1002 | ||
1003 | /* | ||
1004 | * unbind _ADR-Based Devices when hot removal | ||
1005 | */ | ||
923 | if (dev->flags.bus_address) { | 1006 | if (dev->flags.bus_address) { |
924 | if ((dev->parent) && (dev->parent->ops.unbind)) | 1007 | if ((dev->parent) && (dev->parent->ops.unbind)) |
925 | dev->parent->ops.unbind(dev); | 1008 | dev->parent->ops.unbind(dev); |
926 | } | 1009 | } |
927 | |||
928 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); | 1010 | acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT); |
929 | 1011 | ||
930 | return 0; | 1012 | return 0; |
@@ -932,7 +1014,8 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice) | |||
932 | 1014 | ||
933 | static int | 1015 | static int |
934 | acpi_add_single_object(struct acpi_device **child, | 1016 | acpi_add_single_object(struct acpi_device **child, |
935 | struct acpi_device *parent, acpi_handle handle, int type) | 1017 | struct acpi_device *parent, acpi_handle handle, int type, |
1018 | struct acpi_bus_ops *ops) | ||
936 | { | 1019 | { |
937 | int result = 0; | 1020 | int result = 0; |
938 | struct acpi_device *device = NULL; | 1021 | struct acpi_device *device = NULL; |
@@ -949,6 +1032,8 @@ acpi_add_single_object(struct acpi_device **child, | |||
949 | 1032 | ||
950 | device->handle = handle; | 1033 | device->handle = handle; |
951 | device->parent = parent; | 1034 | device->parent = parent; |
1035 | device->bus_ops = *ops; /* workround for not call .start */ | ||
1036 | |||
952 | 1037 | ||
953 | acpi_device_get_busid(device, handle, type); | 1038 | acpi_device_get_busid(device, handle, type); |
954 | 1039 | ||
@@ -1033,31 +1118,16 @@ acpi_add_single_object(struct acpi_device **child, | |||
1033 | if ((result = acpi_device_set_context(device, type))) | 1118 | if ((result = acpi_device_set_context(device, type))) |
1034 | goto end; | 1119 | goto end; |
1035 | 1120 | ||
1036 | acpi_device_register(device, parent); | 1121 | result = acpi_device_register(device, parent); |
1037 | 1122 | ||
1038 | /* | 1123 | /* |
1039 | * Bind _ADR-Based Devices | 1124 | * Bind _ADR-Based Devices when hot add |
1040 | * ----------------------- | ||
1041 | * If there's a a bus address (_ADR) then we utilize the parent's | ||
1042 | * 'bind' function (if exists) to bind the ACPI- and natively- | ||
1043 | * enumerated device representations. | ||
1044 | */ | 1125 | */ |
1045 | if (device->flags.bus_address) { | 1126 | if (device->flags.bus_address) { |
1046 | if (device->parent && device->parent->ops.bind) | 1127 | if (device->parent && device->parent->ops.bind) |
1047 | device->parent->ops.bind(device); | 1128 | device->parent->ops.bind(device); |
1048 | } | 1129 | } |
1049 | 1130 | ||
1050 | /* | ||
1051 | * Locate & Attach Driver | ||
1052 | * ---------------------- | ||
1053 | * If there's a hardware id (_HID) or compatible ids (_CID) we check | ||
1054 | * to see if there's a driver installed for this kind of device. Note | ||
1055 | * that drivers can install before or after a device is enumerated. | ||
1056 | * | ||
1057 | * TBD: Assumes LDM provides driver hot-plug capability. | ||
1058 | */ | ||
1059 | acpi_bus_find_driver(device); | ||
1060 | |||
1061 | end: | 1131 | end: |
1062 | if (!result) | 1132 | if (!result) |
1063 | *child = device; | 1133 | *child = device; |
@@ -1143,14 +1213,14 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops) | |||
1143 | 1213 | ||
1144 | if (ops->acpi_op_add) | 1214 | if (ops->acpi_op_add) |
1145 | status = acpi_add_single_object(&child, parent, | 1215 | status = acpi_add_single_object(&child, parent, |
1146 | chandle, type); | 1216 | chandle, type, ops); |
1147 | else | 1217 | else |
1148 | status = acpi_bus_get_device(chandle, &child); | 1218 | status = acpi_bus_get_device(chandle, &child); |
1149 | 1219 | ||
1150 | if (ACPI_FAILURE(status)) | 1220 | if (ACPI_FAILURE(status)) |
1151 | continue; | 1221 | continue; |
1152 | 1222 | ||
1153 | if (ops->acpi_op_start) { | 1223 | if (ops->acpi_op_start && !(ops->acpi_op_add)) { |
1154 | status = acpi_start_single_object(child); | 1224 | status = acpi_start_single_object(child); |
1155 | if (ACPI_FAILURE(status)) | 1225 | if (ACPI_FAILURE(status)) |
1156 | continue; | 1226 | continue; |
@@ -1188,13 +1258,13 @@ acpi_bus_add(struct acpi_device **child, | |||
1188 | int result; | 1258 | int result; |
1189 | struct acpi_bus_ops ops; | 1259 | struct acpi_bus_ops ops; |
1190 | 1260 | ||
1261 | memset(&ops, 0, sizeof(ops)); | ||
1262 | ops.acpi_op_add = 1; | ||
1191 | 1263 | ||
1192 | result = acpi_add_single_object(child, parent, handle, type); | 1264 | result = acpi_add_single_object(child, parent, handle, type, &ops); |
1193 | if (!result) { | 1265 | if (!result) |
1194 | memset(&ops, 0, sizeof(ops)); | ||
1195 | ops.acpi_op_add = 1; | ||
1196 | result = acpi_bus_scan(*child, &ops); | 1266 | result = acpi_bus_scan(*child, &ops); |
1197 | } | 1267 | |
1198 | return result; | 1268 | return result; |
1199 | } | 1269 | } |
1200 | 1270 | ||
@@ -1280,127 +1350,35 @@ static int acpi_bus_scan_fixed(struct acpi_device *root) | |||
1280 | { | 1350 | { |
1281 | int result = 0; | 1351 | int result = 0; |
1282 | struct acpi_device *device = NULL; | 1352 | struct acpi_device *device = NULL; |
1283 | 1353 | struct acpi_bus_ops ops; | |
1284 | 1354 | ||
1285 | if (!root) | 1355 | if (!root) |
1286 | return -ENODEV; | 1356 | return -ENODEV; |
1287 | 1357 | ||
1358 | memset(&ops, 0, sizeof(ops)); | ||
1359 | ops.acpi_op_add = 1; | ||
1360 | ops.acpi_op_start = 1; | ||
1361 | |||
1288 | /* | 1362 | /* |
1289 | * Enumerate all fixed-feature devices. | 1363 | * Enumerate all fixed-feature devices. |
1290 | */ | 1364 | */ |
1291 | if (acpi_fadt.pwr_button == 0) { | 1365 | if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) { |
1292 | result = acpi_add_single_object(&device, acpi_root, | 1366 | result = acpi_add_single_object(&device, acpi_root, |
1293 | NULL, | 1367 | NULL, |
1294 | ACPI_BUS_TYPE_POWER_BUTTON); | 1368 | ACPI_BUS_TYPE_POWER_BUTTON, |
1295 | if (!result) | 1369 | &ops); |
1296 | result = acpi_start_single_object(device); | ||
1297 | } | 1370 | } |
1298 | 1371 | ||
1299 | if (acpi_fadt.sleep_button == 0) { | 1372 | if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) { |
1300 | result = acpi_add_single_object(&device, acpi_root, | 1373 | result = acpi_add_single_object(&device, acpi_root, |
1301 | NULL, | 1374 | NULL, |
1302 | ACPI_BUS_TYPE_SLEEP_BUTTON); | 1375 | ACPI_BUS_TYPE_SLEEP_BUTTON, |
1303 | if (!result) | 1376 | &ops); |
1304 | result = acpi_start_single_object(device); | ||
1305 | } | 1377 | } |
1306 | 1378 | ||
1307 | return result; | 1379 | return result; |
1308 | } | 1380 | } |
1309 | 1381 | ||
1310 | |||
1311 | static inline struct acpi_device * to_acpi_dev(struct device * dev) | ||
1312 | { | ||
1313 | return container_of(dev, struct acpi_device, dev); | ||
1314 | } | ||
1315 | |||
1316 | |||
1317 | static int root_suspend(struct acpi_device * acpi_dev, pm_message_t state) | ||
1318 | { | ||
1319 | struct acpi_device * dev, * next; | ||
1320 | int result; | ||
1321 | |||
1322 | spin_lock(&acpi_device_lock); | ||
1323 | list_for_each_entry_safe_reverse(dev, next, &acpi_device_list, g_list) { | ||
1324 | if (dev->driver && dev->driver->ops.suspend) { | ||
1325 | spin_unlock(&acpi_device_lock); | ||
1326 | result = dev->driver->ops.suspend(dev, 0); | ||
1327 | if (result) { | ||
1328 | printk(KERN_ERR PREFIX "[%s - %s] Suspend failed: %d\n", | ||
1329 | acpi_device_name(dev), | ||
1330 | acpi_device_bid(dev), result); | ||
1331 | } | ||
1332 | spin_lock(&acpi_device_lock); | ||
1333 | } | ||
1334 | } | ||
1335 | spin_unlock(&acpi_device_lock); | ||
1336 | return 0; | ||
1337 | } | ||
1338 | |||
1339 | |||
1340 | static int acpi_device_suspend(struct device * dev, pm_message_t state) | ||
1341 | { | ||
1342 | struct acpi_device * acpi_dev = to_acpi_dev(dev); | ||
1343 | |||
1344 | /* | ||
1345 | * For now, we should only register 1 generic device - | ||
1346 | * the ACPI root device - and from there, we walk the | ||
1347 | * tree of ACPI devices to suspend each one using the | ||
1348 | * ACPI driver methods. | ||
1349 | */ | ||
1350 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) | ||
1351 | root_suspend(acpi_dev, state); | ||
1352 | return 0; | ||
1353 | } | ||
1354 | |||
1355 | |||
1356 | |||
1357 | static int root_resume(struct acpi_device * acpi_dev) | ||
1358 | { | ||
1359 | struct acpi_device * dev, * next; | ||
1360 | int result; | ||
1361 | |||
1362 | spin_lock(&acpi_device_lock); | ||
1363 | list_for_each_entry_safe(dev, next, &acpi_device_list, g_list) { | ||
1364 | if (dev->driver && dev->driver->ops.resume) { | ||
1365 | spin_unlock(&acpi_device_lock); | ||
1366 | result = dev->driver->ops.resume(dev, 0); | ||
1367 | if (result) { | ||
1368 | printk(KERN_ERR PREFIX "[%s - %s] resume failed: %d\n", | ||
1369 | acpi_device_name(dev), | ||
1370 | acpi_device_bid(dev), result); | ||
1371 | } | ||
1372 | spin_lock(&acpi_device_lock); | ||
1373 | } | ||
1374 | } | ||
1375 | spin_unlock(&acpi_device_lock); | ||
1376 | return 0; | ||
1377 | } | ||
1378 | |||
1379 | |||
1380 | static int acpi_device_resume(struct device * dev) | ||
1381 | { | ||
1382 | struct acpi_device * acpi_dev = to_acpi_dev(dev); | ||
1383 | |||
1384 | /* | ||
1385 | * For now, we should only register 1 generic device - | ||
1386 | * the ACPI root device - and from there, we walk the | ||
1387 | * tree of ACPI devices to resume each one using the | ||
1388 | * ACPI driver methods. | ||
1389 | */ | ||
1390 | if (acpi_dev->handle == ACPI_ROOT_OBJECT) | ||
1391 | root_resume(acpi_dev); | ||
1392 | return 0; | ||
1393 | } | ||
1394 | |||
1395 | |||
1396 | static struct bus_type acpi_bus_type = { | ||
1397 | .name = "acpi", | ||
1398 | .suspend = acpi_device_suspend, | ||
1399 | .resume = acpi_device_resume, | ||
1400 | }; | ||
1401 | |||
1402 | |||
1403 | |||
1404 | static int __init acpi_scan_init(void) | 1382 | static int __init acpi_scan_init(void) |
1405 | { | 1383 | { |
1406 | int result; | 1384 | int result; |
@@ -1410,9 +1388,9 @@ static int __init acpi_scan_init(void) | |||
1410 | if (acpi_disabled) | 1388 | if (acpi_disabled) |
1411 | return 0; | 1389 | return 0; |
1412 | 1390 | ||
1413 | result = kset_register(&acpi_namespace_kset); | 1391 | memset(&ops, 0, sizeof(ops)); |
1414 | if (result < 0) | 1392 | ops.acpi_op_add = 1; |
1415 | printk(KERN_ERR PREFIX "kset_register error: %d\n", result); | 1393 | ops.acpi_op_start = 1; |
1416 | 1394 | ||
1417 | result = bus_register(&acpi_bus_type); | 1395 | result = bus_register(&acpi_bus_type); |
1418 | if (result) { | 1396 | if (result) { |
@@ -1424,32 +1402,16 @@ static int __init acpi_scan_init(void) | |||
1424 | * Create the root device in the bus's device tree | 1402 | * Create the root device in the bus's device tree |
1425 | */ | 1403 | */ |
1426 | result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT, | 1404 | result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT, |
1427 | ACPI_BUS_TYPE_SYSTEM); | 1405 | ACPI_BUS_TYPE_SYSTEM, &ops); |
1428 | if (result) | 1406 | if (result) |
1429 | goto Done; | 1407 | goto Done; |
1430 | 1408 | ||
1431 | result = acpi_start_single_object(acpi_root); | ||
1432 | if (result) | ||
1433 | goto Done; | ||
1434 | |||
1435 | acpi_root->dev.bus = &acpi_bus_type; | ||
1436 | snprintf(acpi_root->dev.bus_id, BUS_ID_SIZE, "%s", acpi_bus_type.name); | ||
1437 | result = device_register(&acpi_root->dev); | ||
1438 | if (result) { | ||
1439 | /* We don't want to quit even if we failed to add suspend/resume */ | ||
1440 | printk(KERN_ERR PREFIX "Could not register device\n"); | ||
1441 | } | ||
1442 | |||
1443 | /* | 1409 | /* |
1444 | * Enumerate devices in the ACPI namespace. | 1410 | * Enumerate devices in the ACPI namespace. |
1445 | */ | 1411 | */ |
1446 | result = acpi_bus_scan_fixed(acpi_root); | 1412 | result = acpi_bus_scan_fixed(acpi_root); |
1447 | if (!result) { | 1413 | if (!result) |
1448 | memset(&ops, 0, sizeof(ops)); | ||
1449 | ops.acpi_op_add = 1; | ||
1450 | ops.acpi_op_start = 1; | ||
1451 | result = acpi_bus_scan(acpi_root, &ops); | 1414 | result = acpi_bus_scan(acpi_root, &ops); |
1452 | } | ||
1453 | 1415 | ||
1454 | if (result) | 1416 | if (result) |
1455 | acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); | 1417 | acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); |