Merge branch 'acpi-cleanup' into acpi-hotplug
[deliverable/linux.git] / drivers / acpi / scan.c
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/slab.h>
8 #include <linux/kernel.h>
9 #include <linux/acpi.h>
10 #include <linux/signal.h>
11 #include <linux/kthread.h>
12 #include <linux/dmi.h>
13 #include <linux/nls.h>
14
15 #include <asm/pgtable.h>
16
17 #include "internal.h"
18
19 #define _COMPONENT ACPI_BUS_COMPONENT
20 ACPI_MODULE_NAME("scan");
21 extern struct acpi_device *acpi_root;
22
23 #define ACPI_BUS_CLASS "system_bus"
24 #define ACPI_BUS_HID "LNXSYBUS"
25 #define ACPI_BUS_DEVICE_NAME "System Bus"
26
27 #define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
28
29 #define INVALID_ACPI_HANDLE ((acpi_handle)empty_zero_page)
30
31 /*
32 * If set, devices will be hot-removed even if they cannot be put offline
33 * gracefully (from the kernel's standpoint).
34 */
35 bool acpi_force_hot_remove;
36
37 static const char *dummy_hid = "device";
38
39 static LIST_HEAD(acpi_bus_id_list);
40 static DEFINE_MUTEX(acpi_scan_lock);
41 static LIST_HEAD(acpi_scan_handlers_list);
42 DEFINE_MUTEX(acpi_device_lock);
43 LIST_HEAD(acpi_wakeup_device_list);
44
45 struct acpi_device_bus_id{
46 char bus_id[15];
47 unsigned int instance_no;
48 struct list_head node;
49 };
50
51 void acpi_scan_lock_acquire(void)
52 {
53 mutex_lock(&acpi_scan_lock);
54 }
55 EXPORT_SYMBOL_GPL(acpi_scan_lock_acquire);
56
57 void acpi_scan_lock_release(void)
58 {
59 mutex_unlock(&acpi_scan_lock);
60 }
61 EXPORT_SYMBOL_GPL(acpi_scan_lock_release);
62
63 int acpi_scan_add_handler(struct acpi_scan_handler *handler)
64 {
65 if (!handler || !handler->attach)
66 return -EINVAL;
67
68 list_add_tail(&handler->list_node, &acpi_scan_handlers_list);
69 return 0;
70 }
71
72 int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler,
73 const char *hotplug_profile_name)
74 {
75 int error;
76
77 error = acpi_scan_add_handler(handler);
78 if (error)
79 return error;
80
81 acpi_sysfs_add_hotplug_profile(&handler->hotplug, hotplug_profile_name);
82 return 0;
83 }
84
85 /*
86 * Creates hid/cid(s) string needed for modalias and uevent
87 * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get:
88 * char *modalias: "acpi:IBM0001:ACPI0001"
89 */
90 static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
91 int size)
92 {
93 int len;
94 int count;
95 struct acpi_hardware_id *id;
96
97 if (list_empty(&acpi_dev->pnp.ids))
98 return 0;
99
100 len = snprintf(modalias, size, "acpi:");
101 size -= len;
102
103 list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
104 count = snprintf(&modalias[len], size, "%s:", id->id);
105 if (count < 0 || count >= size)
106 return -EINVAL;
107 len += count;
108 size -= count;
109 }
110
111 modalias[len] = '\0';
112 return len;
113 }
114
115 static ssize_t
116 acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, char *buf) {
117 struct acpi_device *acpi_dev = to_acpi_device(dev);
118 int len;
119
120 /* Device has no HID and no CID or string is >1024 */
121 len = create_modalias(acpi_dev, buf, 1024);
122 if (len <= 0)
123 return 0;
124 buf[len++] = '\n';
125 return len;
126 }
127 static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
128
129 static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
130 void **ret_p)
131 {
132 struct acpi_device *device = NULL;
133 struct acpi_device_physical_node *pn;
134 bool second_pass = (bool)data;
135 acpi_status status = AE_OK;
136
137 if (acpi_bus_get_device(handle, &device))
138 return AE_OK;
139
140 if (device->handler && !device->handler->hotplug.enabled) {
141 *ret_p = &device->dev;
142 return AE_SUPPORT;
143 }
144
145 mutex_lock(&device->physical_node_lock);
146
147 list_for_each_entry(pn, &device->physical_node_list, node) {
148 int ret;
149
150 if (second_pass) {
151 /* Skip devices offlined by the first pass. */
152 if (pn->put_online)
153 continue;
154 } else {
155 pn->put_online = false;
156 }
157 ret = device_offline(pn->dev);
158 if (acpi_force_hot_remove)
159 continue;
160
161 if (ret >= 0) {
162 pn->put_online = !ret;
163 } else {
164 *ret_p = pn->dev;
165 if (second_pass) {
166 status = AE_ERROR;
167 break;
168 }
169 }
170 }
171
172 mutex_unlock(&device->physical_node_lock);
173
174 return status;
175 }
176
177 static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
178 void **ret_p)
179 {
180 struct acpi_device *device = NULL;
181 struct acpi_device_physical_node *pn;
182
183 if (acpi_bus_get_device(handle, &device))
184 return AE_OK;
185
186 mutex_lock(&device->physical_node_lock);
187
188 list_for_each_entry(pn, &device->physical_node_list, node)
189 if (pn->put_online) {
190 device_online(pn->dev);
191 pn->put_online = false;
192 }
193
194 mutex_unlock(&device->physical_node_lock);
195
196 return AE_OK;
197 }
198
199 static int acpi_scan_hot_remove(struct acpi_device *device)
200 {
201 acpi_handle handle = device->handle;
202 struct device *errdev;
203 acpi_status status;
204 unsigned long long sta;
205
206 /*
207 * Carry out two passes here and ignore errors in the first pass,
208 * because if the devices in question are memory blocks and
209 * CONFIG_MEMCG is set, one of the blocks may hold data structures
210 * that the other blocks depend on, but it is not known in advance which
211 * block holds them.
212 *
213 * If the first pass is successful, the second one isn't needed, though.
214 */
215 errdev = NULL;
216 status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
217 NULL, acpi_bus_offline, (void *)false,
218 (void **)&errdev);
219 if (status == AE_SUPPORT) {
220 dev_warn(errdev, "Offline disabled.\n");
221 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
222 acpi_bus_online, NULL, NULL, NULL);
223 return -EPERM;
224 }
225 acpi_bus_offline(handle, 0, (void *)false, (void **)&errdev);
226 if (errdev) {
227 errdev = NULL;
228 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
229 NULL, acpi_bus_offline, (void *)true,
230 (void **)&errdev);
231 if (!errdev || acpi_force_hot_remove)
232 acpi_bus_offline(handle, 0, (void *)true,
233 (void **)&errdev);
234
235 if (errdev && !acpi_force_hot_remove) {
236 dev_warn(errdev, "Offline failed.\n");
237 acpi_bus_online(handle, 0, NULL, NULL);
238 acpi_walk_namespace(ACPI_TYPE_ANY, handle,
239 ACPI_UINT32_MAX, acpi_bus_online,
240 NULL, NULL, NULL);
241 return -EBUSY;
242 }
243 }
244
245 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
246 "Hot-removing device %s...\n", dev_name(&device->dev)));
247
248 acpi_bus_trim(device);
249
250 acpi_evaluate_lck(handle, 0);
251 /*
252 * TBD: _EJD support.
253 */
254 status = acpi_evaluate_ej0(handle);
255 if (status == AE_NOT_FOUND)
256 return -ENODEV;
257 else if (ACPI_FAILURE(status))
258 return -EIO;
259
260 /*
261 * Verify if eject was indeed successful. If not, log an error
262 * message. No need to call _OST since _EJ0 call was made OK.
263 */
264 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
265 if (ACPI_FAILURE(status)) {
266 acpi_handle_warn(handle,
267 "Status check after eject failed (0x%x)\n", status);
268 } else if (sta & ACPI_STA_DEVICE_ENABLED) {
269 acpi_handle_warn(handle,
270 "Eject incomplete - status 0x%llx\n", sta);
271 }
272
273 return 0;
274 }
275
276 static int acpi_scan_device_not_present(struct acpi_device *adev)
277 {
278 if (!acpi_device_enumerated(adev)) {
279 dev_warn(&adev->dev, "Still not present\n");
280 return -EALREADY;
281 }
282 acpi_bus_trim(adev);
283 return 0;
284 }
285
286 static int acpi_scan_device_check(struct acpi_device *adev)
287 {
288 int error;
289
290 acpi_bus_get_status(adev);
291 if (adev->status.present || adev->status.functional) {
292 /*
293 * This function is only called for device objects for which
294 * matching scan handlers exist. The only situation in which
295 * the scan handler is not attached to this device object yet
296 * is when the device has just appeared (either it wasn't
297 * present at all before or it was removed and then added
298 * again).
299 */
300 if (adev->handler) {
301 dev_warn(&adev->dev, "Already enumerated\n");
302 return -EALREADY;
303 }
304 error = acpi_bus_scan(adev->handle);
305 if (error) {
306 dev_warn(&adev->dev, "Namespace scan failure\n");
307 return error;
308 }
309 if (!adev->handler) {
310 dev_warn(&adev->dev, "Enumeration failure\n");
311 error = -ENODEV;
312 }
313 } else {
314 error = acpi_scan_device_not_present(adev);
315 }
316 return error;
317 }
318
319 static int acpi_scan_bus_check(struct acpi_device *adev)
320 {
321 struct acpi_scan_handler *handler = adev->handler;
322 struct acpi_device *child;
323 int error;
324
325 acpi_bus_get_status(adev);
326 if (!(adev->status.present || adev->status.functional)) {
327 acpi_scan_device_not_present(adev);
328 return 0;
329 }
330 if (handler && handler->hotplug.scan_dependent)
331 return handler->hotplug.scan_dependent(adev);
332
333 error = acpi_bus_scan(adev->handle);
334 if (error) {
335 dev_warn(&adev->dev, "Namespace scan failure\n");
336 return error;
337 }
338 list_for_each_entry(child, &adev->children, node) {
339 error = acpi_scan_bus_check(child);
340 if (error)
341 return error;
342 }
343 return 0;
344 }
345
346 static void acpi_device_hotplug(void *data, u32 src)
347 {
348 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
349 struct acpi_device *adev = data;
350 int error;
351
352 lock_device_hotplug();
353 mutex_lock(&acpi_scan_lock);
354
355 /*
356 * The device object's ACPI handle cannot become invalid as long as we
357 * are holding acpi_scan_lock, but it may have become invalid before
358 * that lock was acquired.
359 */
360 if (adev->handle == INVALID_ACPI_HANDLE)
361 goto out;
362
363 switch (src) {
364 case ACPI_NOTIFY_BUS_CHECK:
365 error = acpi_scan_bus_check(adev);
366 break;
367 case ACPI_NOTIFY_DEVICE_CHECK:
368 error = acpi_scan_device_check(adev);
369 break;
370 case ACPI_NOTIFY_EJECT_REQUEST:
371 case ACPI_OST_EC_OSPM_EJECT:
372 error = acpi_scan_hot_remove(adev);
373 break;
374 default:
375 error = -EINVAL;
376 break;
377 }
378 if (!error)
379 ost_code = ACPI_OST_SC_SUCCESS;
380
381 out:
382 acpi_evaluate_hotplug_ost(adev->handle, src, ost_code, NULL);
383 put_device(&adev->dev);
384 mutex_unlock(&acpi_scan_lock);
385 unlock_device_hotplug();
386 }
387
388 static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data)
389 {
390 u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE;
391 struct acpi_scan_handler *handler = data;
392 struct acpi_device *adev;
393 acpi_status status;
394
395 if (acpi_bus_get_device(handle, &adev))
396 goto err_out;
397
398 switch (type) {
399 case ACPI_NOTIFY_BUS_CHECK:
400 acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n");
401 break;
402 case ACPI_NOTIFY_DEVICE_CHECK:
403 acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n");
404 break;
405 case ACPI_NOTIFY_EJECT_REQUEST:
406 acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n");
407 if (!handler->hotplug.enabled) {
408 acpi_handle_err(handle, "Eject disabled\n");
409 ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED;
410 goto err_out;
411 }
412 acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST,
413 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
414 break;
415 default:
416 /* non-hotplug event; possibly handled by other handler */
417 return;
418 }
419 get_device(&adev->dev);
420 status = acpi_hotplug_execute(acpi_device_hotplug, adev, type);
421 if (ACPI_SUCCESS(status))
422 return;
423
424 put_device(&adev->dev);
425
426 err_out:
427 acpi_evaluate_hotplug_ost(handle, type, ost_code, NULL);
428 }
429
430 static ssize_t real_power_state_show(struct device *dev,
431 struct device_attribute *attr, char *buf)
432 {
433 struct acpi_device *adev = to_acpi_device(dev);
434 int state;
435 int ret;
436
437 ret = acpi_device_get_power(adev, &state);
438 if (ret)
439 return ret;
440
441 return sprintf(buf, "%s\n", acpi_power_state_string(state));
442 }
443
444 static DEVICE_ATTR(real_power_state, 0444, real_power_state_show, NULL);
445
446 static ssize_t power_state_show(struct device *dev,
447 struct device_attribute *attr, char *buf)
448 {
449 struct acpi_device *adev = to_acpi_device(dev);
450
451 return sprintf(buf, "%s\n", acpi_power_state_string(adev->power.state));
452 }
453
454 static DEVICE_ATTR(power_state, 0444, power_state_show, NULL);
455
456 static ssize_t
457 acpi_eject_store(struct device *d, struct device_attribute *attr,
458 const char *buf, size_t count)
459 {
460 struct acpi_device *acpi_device = to_acpi_device(d);
461 acpi_object_type not_used;
462 acpi_status status;
463
464 if (!count || buf[0] != '1')
465 return -EINVAL;
466
467 if ((!acpi_device->handler || !acpi_device->handler->hotplug.enabled)
468 && !acpi_device->driver)
469 return -ENODEV;
470
471 status = acpi_get_type(acpi_device->handle, &not_used);
472 if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable)
473 return -ENODEV;
474
475 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
476 ACPI_OST_SC_EJECT_IN_PROGRESS, NULL);
477 get_device(&acpi_device->dev);
478 status = acpi_hotplug_execute(acpi_device_hotplug, acpi_device,
479 ACPI_OST_EC_OSPM_EJECT);
480 if (ACPI_SUCCESS(status))
481 return count;
482
483 put_device(&acpi_device->dev);
484 acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT,
485 ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL);
486 return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN;
487 }
488
489 static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
490
491 static ssize_t
492 acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *buf) {
493 struct acpi_device *acpi_dev = to_acpi_device(dev);
494
495 return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
496 }
497 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
498
499 static ssize_t acpi_device_uid_show(struct device *dev,
500 struct device_attribute *attr, char *buf)
501 {
502 struct acpi_device *acpi_dev = to_acpi_device(dev);
503
504 return sprintf(buf, "%s\n", acpi_dev->pnp.unique_id);
505 }
506 static DEVICE_ATTR(uid, 0444, acpi_device_uid_show, NULL);
507
508 static ssize_t acpi_device_adr_show(struct device *dev,
509 struct device_attribute *attr, char *buf)
510 {
511 struct acpi_device *acpi_dev = to_acpi_device(dev);
512
513 return sprintf(buf, "0x%08x\n",
514 (unsigned int)(acpi_dev->pnp.bus_address));
515 }
516 static DEVICE_ATTR(adr, 0444, acpi_device_adr_show, NULL);
517
518 static ssize_t
519 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
520 struct acpi_device *acpi_dev = to_acpi_device(dev);
521 struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
522 int result;
523
524 result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
525 if (result)
526 goto end;
527
528 result = sprintf(buf, "%s\n", (char*)path.pointer);
529 kfree(path.pointer);
530 end:
531 return result;
532 }
533 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
534
535 /* sysfs file that shows description text from the ACPI _STR method */
536 static ssize_t description_show(struct device *dev,
537 struct device_attribute *attr,
538 char *buf) {
539 struct acpi_device *acpi_dev = to_acpi_device(dev);
540 int result;
541
542 if (acpi_dev->pnp.str_obj == NULL)
543 return 0;
544
545 /*
546 * The _STR object contains a Unicode identifier for a device.
547 * We need to convert to utf-8 so it can be displayed.
548 */
549 result = utf16s_to_utf8s(
550 (wchar_t *)acpi_dev->pnp.str_obj->buffer.pointer,
551 acpi_dev->pnp.str_obj->buffer.length,
552 UTF16_LITTLE_ENDIAN, buf,
553 PAGE_SIZE);
554
555 buf[result++] = '\n';
556
557 return result;
558 }
559 static DEVICE_ATTR(description, 0444, description_show, NULL);
560
561 static ssize_t
562 acpi_device_sun_show(struct device *dev, struct device_attribute *attr,
563 char *buf) {
564 struct acpi_device *acpi_dev = to_acpi_device(dev);
565
566 return sprintf(buf, "%lu\n", acpi_dev->pnp.sun);
567 }
568 static DEVICE_ATTR(sun, 0444, acpi_device_sun_show, NULL);
569
570 static int acpi_device_setup_files(struct acpi_device *dev)
571 {
572 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
573 acpi_status status;
574 unsigned long long sun;
575 int result = 0;
576
577 /*
578 * Devices gotten from FADT don't have a "path" attribute
579 */
580 if (dev->handle) {
581 result = device_create_file(&dev->dev, &dev_attr_path);
582 if (result)
583 goto end;
584 }
585
586 if (!list_empty(&dev->pnp.ids)) {
587 result = device_create_file(&dev->dev, &dev_attr_hid);
588 if (result)
589 goto end;
590
591 result = device_create_file(&dev->dev, &dev_attr_modalias);
592 if (result)
593 goto end;
594 }
595
596 /*
597 * If device has _STR, 'description' file is created
598 */
599 if (acpi_has_method(dev->handle, "_STR")) {
600 status = acpi_evaluate_object(dev->handle, "_STR",
601 NULL, &buffer);
602 if (ACPI_FAILURE(status))
603 buffer.pointer = NULL;
604 dev->pnp.str_obj = buffer.pointer;
605 result = device_create_file(&dev->dev, &dev_attr_description);
606 if (result)
607 goto end;
608 }
609
610 if (dev->pnp.type.bus_address)
611 result = device_create_file(&dev->dev, &dev_attr_adr);
612 if (dev->pnp.unique_id)
613 result = device_create_file(&dev->dev, &dev_attr_uid);
614
615 status = acpi_evaluate_integer(dev->handle, "_SUN", NULL, &sun);
616 if (ACPI_SUCCESS(status)) {
617 dev->pnp.sun = (unsigned long)sun;
618 result = device_create_file(&dev->dev, &dev_attr_sun);
619 if (result)
620 goto end;
621 } else {
622 dev->pnp.sun = (unsigned long)-1;
623 }
624
625 /*
626 * If device has _EJ0, 'eject' file is created that is used to trigger
627 * hot-removal function from userland.
628 */
629 if (acpi_has_method(dev->handle, "_EJ0")) {
630 result = device_create_file(&dev->dev, &dev_attr_eject);
631 if (result)
632 return result;
633 }
634
635 if (dev->flags.power_manageable) {
636 result = device_create_file(&dev->dev, &dev_attr_power_state);
637 if (result)
638 return result;
639
640 if (dev->power.flags.power_resources)
641 result = device_create_file(&dev->dev,
642 &dev_attr_real_power_state);
643 }
644
645 end:
646 return result;
647 }
648
649 static void acpi_device_remove_files(struct acpi_device *dev)
650 {
651 if (dev->flags.power_manageable) {
652 device_remove_file(&dev->dev, &dev_attr_power_state);
653 if (dev->power.flags.power_resources)
654 device_remove_file(&dev->dev,
655 &dev_attr_real_power_state);
656 }
657
658 /*
659 * If device has _STR, remove 'description' file
660 */
661 if (acpi_has_method(dev->handle, "_STR")) {
662 kfree(dev->pnp.str_obj);
663 device_remove_file(&dev->dev, &dev_attr_description);
664 }
665 /*
666 * If device has _EJ0, remove 'eject' file.
667 */
668 if (acpi_has_method(dev->handle, "_EJ0"))
669 device_remove_file(&dev->dev, &dev_attr_eject);
670
671 if (acpi_has_method(dev->handle, "_SUN"))
672 device_remove_file(&dev->dev, &dev_attr_sun);
673
674 if (dev->pnp.unique_id)
675 device_remove_file(&dev->dev, &dev_attr_uid);
676 if (dev->pnp.type.bus_address)
677 device_remove_file(&dev->dev, &dev_attr_adr);
678 device_remove_file(&dev->dev, &dev_attr_modalias);
679 device_remove_file(&dev->dev, &dev_attr_hid);
680 if (dev->handle)
681 device_remove_file(&dev->dev, &dev_attr_path);
682 }
683 /* --------------------------------------------------------------------------
684 ACPI Bus operations
685 -------------------------------------------------------------------------- */
686
687 static const struct acpi_device_id *__acpi_match_device(
688 struct acpi_device *device, const struct acpi_device_id *ids)
689 {
690 const struct acpi_device_id *id;
691 struct acpi_hardware_id *hwid;
692
693 /*
694 * If the device is not present, it is unnecessary to load device
695 * driver for it.
696 */
697 if (!device->status.present)
698 return NULL;
699
700 for (id = ids; id->id[0]; id++)
701 list_for_each_entry(hwid, &device->pnp.ids, list)
702 if (!strcmp((char *) id->id, hwid->id))
703 return id;
704
705 return NULL;
706 }
707
708 /**
709 * acpi_match_device - Match a struct device against a given list of ACPI IDs
710 * @ids: Array of struct acpi_device_id object to match against.
711 * @dev: The device structure to match.
712 *
713 * Check if @dev has a valid ACPI handle and if there is a struct acpi_device
714 * object for that handle and use that object to match against a given list of
715 * device IDs.
716 *
717 * Return a pointer to the first matching ID on success or %NULL on failure.
718 */
719 const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
720 const struct device *dev)
721 {
722 struct acpi_device *adev;
723 acpi_handle handle = ACPI_HANDLE(dev);
724
725 if (!ids || !handle || acpi_bus_get_device(handle, &adev))
726 return NULL;
727
728 return __acpi_match_device(adev, ids);
729 }
730 EXPORT_SYMBOL_GPL(acpi_match_device);
731
732 int acpi_match_device_ids(struct acpi_device *device,
733 const struct acpi_device_id *ids)
734 {
735 return __acpi_match_device(device, ids) ? 0 : -ENOENT;
736 }
737 EXPORT_SYMBOL(acpi_match_device_ids);
738
739 static void acpi_free_power_resources_lists(struct acpi_device *device)
740 {
741 int i;
742
743 if (device->wakeup.flags.valid)
744 acpi_power_resources_list_free(&device->wakeup.resources);
745
746 if (!device->flags.power_manageable)
747 return;
748
749 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
750 struct acpi_device_power_state *ps = &device->power.states[i];
751 acpi_power_resources_list_free(&ps->resources);
752 }
753 }
754
755 static void acpi_device_release(struct device *dev)
756 {
757 struct acpi_device *acpi_dev = to_acpi_device(dev);
758
759 acpi_free_pnp_ids(&acpi_dev->pnp);
760 acpi_free_power_resources_lists(acpi_dev);
761 kfree(acpi_dev);
762 }
763
764 static int acpi_bus_match(struct device *dev, struct device_driver *drv)
765 {
766 struct acpi_device *acpi_dev = to_acpi_device(dev);
767 struct acpi_driver *acpi_drv = to_acpi_driver(drv);
768
769 return acpi_dev->flags.match_driver
770 && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
771 }
772
773 static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
774 {
775 struct acpi_device *acpi_dev = to_acpi_device(dev);
776 int len;
777
778 if (list_empty(&acpi_dev->pnp.ids))
779 return 0;
780
781 if (add_uevent_var(env, "MODALIAS="))
782 return -ENOMEM;
783 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
784 sizeof(env->buf) - env->buflen);
785 if (len >= (sizeof(env->buf) - env->buflen))
786 return -ENOMEM;
787 env->buflen += len;
788 return 0;
789 }
790
791 static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
792 {
793 struct acpi_device *device = data;
794
795 device->driver->ops.notify(device, event);
796 }
797
798 static acpi_status acpi_device_notify_fixed(void *data)
799 {
800 struct acpi_device *device = data;
801
802 /* Fixed hardware devices have no handles */
803 acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
804 return AE_OK;
805 }
806
807 static int acpi_device_install_notify_handler(struct acpi_device *device)
808 {
809 acpi_status status;
810
811 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
812 status =
813 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
814 acpi_device_notify_fixed,
815 device);
816 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
817 status =
818 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
819 acpi_device_notify_fixed,
820 device);
821 else
822 status = acpi_install_notify_handler(device->handle,
823 ACPI_DEVICE_NOTIFY,
824 acpi_device_notify,
825 device);
826
827 if (ACPI_FAILURE(status))
828 return -EINVAL;
829 return 0;
830 }
831
832 static void acpi_device_remove_notify_handler(struct acpi_device *device)
833 {
834 if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
835 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
836 acpi_device_notify_fixed);
837 else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
838 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
839 acpi_device_notify_fixed);
840 else
841 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
842 acpi_device_notify);
843 }
844
845 static int acpi_device_probe(struct device *dev)
846 {
847 struct acpi_device *acpi_dev = to_acpi_device(dev);
848 struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
849 int ret;
850
851 if (acpi_dev->handler)
852 return -EINVAL;
853
854 if (!acpi_drv->ops.add)
855 return -ENOSYS;
856
857 ret = acpi_drv->ops.add(acpi_dev);
858 if (ret)
859 return ret;
860
861 acpi_dev->driver = acpi_drv;
862 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
863 "Driver [%s] successfully bound to device [%s]\n",
864 acpi_drv->name, acpi_dev->pnp.bus_id));
865
866 if (acpi_drv->ops.notify) {
867 ret = acpi_device_install_notify_handler(acpi_dev);
868 if (ret) {
869 if (acpi_drv->ops.remove)
870 acpi_drv->ops.remove(acpi_dev);
871
872 acpi_dev->driver = NULL;
873 acpi_dev->driver_data = NULL;
874 return ret;
875 }
876 }
877
878 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found driver [%s] for device [%s]\n",
879 acpi_drv->name, acpi_dev->pnp.bus_id));
880 get_device(dev);
881 return 0;
882 }
883
884 static int acpi_device_remove(struct device * dev)
885 {
886 struct acpi_device *acpi_dev = to_acpi_device(dev);
887 struct acpi_driver *acpi_drv = acpi_dev->driver;
888
889 if (acpi_drv) {
890 if (acpi_drv->ops.notify)
891 acpi_device_remove_notify_handler(acpi_dev);
892 if (acpi_drv->ops.remove)
893 acpi_drv->ops.remove(acpi_dev);
894 }
895 acpi_dev->driver = NULL;
896 acpi_dev->driver_data = NULL;
897
898 put_device(dev);
899 return 0;
900 }
901
902 struct bus_type acpi_bus_type = {
903 .name = "acpi",
904 .match = acpi_bus_match,
905 .probe = acpi_device_probe,
906 .remove = acpi_device_remove,
907 .uevent = acpi_device_uevent,
908 };
909
910 static void acpi_device_del(struct acpi_device *device)
911 {
912 mutex_lock(&acpi_device_lock);
913 if (device->parent)
914 list_del(&device->node);
915
916 list_del(&device->wakeup_list);
917 mutex_unlock(&acpi_device_lock);
918
919 acpi_power_add_remove_device(device, false);
920 acpi_device_remove_files(device);
921 if (device->remove)
922 device->remove(device);
923
924 device_del(&device->dev);
925 }
926
927 static LIST_HEAD(acpi_device_del_list);
928 static DEFINE_MUTEX(acpi_device_del_lock);
929
930 static void acpi_device_del_work_fn(struct work_struct *work_not_used)
931 {
932 for (;;) {
933 struct acpi_device *adev;
934
935 mutex_lock(&acpi_device_del_lock);
936
937 if (list_empty(&acpi_device_del_list)) {
938 mutex_unlock(&acpi_device_del_lock);
939 break;
940 }
941 adev = list_first_entry(&acpi_device_del_list,
942 struct acpi_device, del_list);
943 list_del(&adev->del_list);
944
945 mutex_unlock(&acpi_device_del_lock);
946
947 acpi_device_del(adev);
948 /*
949 * Drop references to all power resources that might have been
950 * used by the device.
951 */
952 acpi_power_transition(adev, ACPI_STATE_D3_COLD);
953 put_device(&adev->dev);
954 }
955 }
956
957 /**
958 * acpi_scan_drop_device - Drop an ACPI device object.
959 * @handle: Handle of an ACPI namespace node, not used.
960 * @context: Address of the ACPI device object to drop.
961 *
962 * This is invoked by acpi_ns_delete_node() during the removal of the ACPI
963 * namespace node the device object pointed to by @context is attached to.
964 *
965 * The unregistration is carried out asynchronously to avoid running
966 * acpi_device_del() under the ACPICA's namespace mutex and the list is used to
967 * ensure the correct ordering (the device objects must be unregistered in the
968 * same order in which the corresponding namespace nodes are deleted).
969 */
970 static void acpi_scan_drop_device(acpi_handle handle, void *context)
971 {
972 static DECLARE_WORK(work, acpi_device_del_work_fn);
973 struct acpi_device *adev = context;
974
975 mutex_lock(&acpi_device_del_lock);
976
977 /*
978 * Use the ACPI hotplug workqueue which is ordered, so this work item
979 * won't run after any hotplug work items submitted subsequently. That
980 * prevents attempts to register device objects identical to those being
981 * deleted from happening concurrently (such attempts result from
982 * hotplug events handled via the ACPI hotplug workqueue). It also will
983 * run after all of the work items submitted previosuly, which helps
984 * those work items to ensure that they are not accessing stale device
985 * objects.
986 */
987 if (list_empty(&acpi_device_del_list))
988 acpi_queue_hotplug_work(&work);
989
990 list_add_tail(&adev->del_list, &acpi_device_del_list);
991 /* Make acpi_ns_validate_handle() return NULL for this handle. */
992 adev->handle = INVALID_ACPI_HANDLE;
993
994 mutex_unlock(&acpi_device_del_lock);
995 }
996
997 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
998 {
999 acpi_status status;
1000
1001 if (!device)
1002 return -EINVAL;
1003
1004 status = acpi_get_data(handle, acpi_scan_drop_device, (void **)device);
1005 if (ACPI_FAILURE(status) || !*device) {
1006 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
1007 handle));
1008 return -ENODEV;
1009 }
1010 return 0;
1011 }
1012 EXPORT_SYMBOL(acpi_bus_get_device);
1013
1014 int acpi_device_add(struct acpi_device *device,
1015 void (*release)(struct device *))
1016 {
1017 int result;
1018 struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
1019 int found = 0;
1020
1021 if (device->handle) {
1022 acpi_status status;
1023
1024 status = acpi_attach_data(device->handle, acpi_scan_drop_device,
1025 device);
1026 if (ACPI_FAILURE(status)) {
1027 acpi_handle_err(device->handle,
1028 "Unable to attach device data\n");
1029 return -ENODEV;
1030 }
1031 }
1032
1033 /*
1034 * Linkage
1035 * -------
1036 * Link this device to its parent and siblings.
1037 */
1038 INIT_LIST_HEAD(&device->children);
1039 INIT_LIST_HEAD(&device->node);
1040 INIT_LIST_HEAD(&device->wakeup_list);
1041 INIT_LIST_HEAD(&device->physical_node_list);
1042 INIT_LIST_HEAD(&device->del_list);
1043 mutex_init(&device->physical_node_lock);
1044
1045 new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
1046 if (!new_bus_id) {
1047 pr_err(PREFIX "Memory allocation error\n");
1048 result = -ENOMEM;
1049 goto err_detach;
1050 }
1051
1052 mutex_lock(&acpi_device_lock);
1053 /*
1054 * Find suitable bus_id and instance number in acpi_bus_id_list
1055 * If failed, create one and link it into acpi_bus_id_list
1056 */
1057 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
1058 if (!strcmp(acpi_device_bus_id->bus_id,
1059 acpi_device_hid(device))) {
1060 acpi_device_bus_id->instance_no++;
1061 found = 1;
1062 kfree(new_bus_id);
1063 break;
1064 }
1065 }
1066 if (!found) {
1067 acpi_device_bus_id = new_bus_id;
1068 strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
1069 acpi_device_bus_id->instance_no = 0;
1070 list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
1071 }
1072 dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
1073
1074 if (device->parent)
1075 list_add_tail(&device->node, &device->parent->children);
1076
1077 if (device->wakeup.flags.valid)
1078 list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
1079 mutex_unlock(&acpi_device_lock);
1080
1081 if (device->parent)
1082 device->dev.parent = &device->parent->dev;
1083 device->dev.bus = &acpi_bus_type;
1084 device->dev.release = release;
1085 result = device_add(&device->dev);
1086 if (result) {
1087 dev_err(&device->dev, "Error registering device\n");
1088 goto err;
1089 }
1090
1091 result = acpi_device_setup_files(device);
1092 if (result)
1093 printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
1094 dev_name(&device->dev));
1095
1096 return 0;
1097
1098 err:
1099 mutex_lock(&acpi_device_lock);
1100 if (device->parent)
1101 list_del(&device->node);
1102 list_del(&device->wakeup_list);
1103 mutex_unlock(&acpi_device_lock);
1104
1105 err_detach:
1106 acpi_detach_data(device->handle, acpi_scan_drop_device);
1107 return result;
1108 }
1109
1110 /* --------------------------------------------------------------------------
1111 Driver Management
1112 -------------------------------------------------------------------------- */
1113 /**
1114 * acpi_bus_register_driver - register a driver with the ACPI bus
1115 * @driver: driver being registered
1116 *
1117 * Registers a driver with the ACPI bus. Searches the namespace for all
1118 * devices that match the driver's criteria and binds. Returns zero for
1119 * success or a negative error status for failure.
1120 */
1121 int acpi_bus_register_driver(struct acpi_driver *driver)
1122 {
1123 int ret;
1124
1125 if (acpi_disabled)
1126 return -ENODEV;
1127 driver->drv.name = driver->name;
1128 driver->drv.bus = &acpi_bus_type;
1129 driver->drv.owner = driver->owner;
1130
1131 ret = driver_register(&driver->drv);
1132 return ret;
1133 }
1134
1135 EXPORT_SYMBOL(acpi_bus_register_driver);
1136
1137 /**
1138 * acpi_bus_unregister_driver - unregisters a driver with the ACPI bus
1139 * @driver: driver to unregister
1140 *
1141 * Unregisters a driver with the ACPI bus. Searches the namespace for all
1142 * devices that match the driver's criteria and unbinds.
1143 */
1144 void acpi_bus_unregister_driver(struct acpi_driver *driver)
1145 {
1146 driver_unregister(&driver->drv);
1147 }
1148
1149 EXPORT_SYMBOL(acpi_bus_unregister_driver);
1150
1151 /* --------------------------------------------------------------------------
1152 Device Enumeration
1153 -------------------------------------------------------------------------- */
1154 static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
1155 {
1156 struct acpi_device *device = NULL;
1157 acpi_status status;
1158
1159 /*
1160 * Fixed hardware devices do not appear in the namespace and do not
1161 * have handles, but we fabricate acpi_devices for them, so we have
1162 * to deal with them specially.
1163 */
1164 if (!handle)
1165 return acpi_root;
1166
1167 do {
1168 status = acpi_get_parent(handle, &handle);
1169 if (ACPI_FAILURE(status))
1170 return status == AE_NULL_ENTRY ? NULL : acpi_root;
1171 } while (acpi_bus_get_device(handle, &device));
1172 return device;
1173 }
1174
1175 acpi_status
1176 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
1177 {
1178 acpi_status status;
1179 acpi_handle tmp;
1180 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
1181 union acpi_object *obj;
1182
1183 status = acpi_get_handle(handle, "_EJD", &tmp);
1184 if (ACPI_FAILURE(status))
1185 return status;
1186
1187 status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
1188 if (ACPI_SUCCESS(status)) {
1189 obj = buffer.pointer;
1190 status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
1191 ejd);
1192 kfree(buffer.pointer);
1193 }
1194 return status;
1195 }
1196 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
1197
1198 static int acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
1199 struct acpi_device_wakeup *wakeup)
1200 {
1201 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1202 union acpi_object *package = NULL;
1203 union acpi_object *element = NULL;
1204 acpi_status status;
1205 int err = -ENODATA;
1206
1207 if (!wakeup)
1208 return -EINVAL;
1209
1210 INIT_LIST_HEAD(&wakeup->resources);
1211
1212 /* _PRW */
1213 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
1214 if (ACPI_FAILURE(status)) {
1215 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
1216 return err;
1217 }
1218
1219 package = (union acpi_object *)buffer.pointer;
1220
1221 if (!package || package->package.count < 2)
1222 goto out;
1223
1224 element = &(package->package.elements[0]);
1225 if (!element)
1226 goto out;
1227
1228 if (element->type == ACPI_TYPE_PACKAGE) {
1229 if ((element->package.count < 2) ||
1230 (element->package.elements[0].type !=
1231 ACPI_TYPE_LOCAL_REFERENCE)
1232 || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
1233 goto out;
1234
1235 wakeup->gpe_device =
1236 element->package.elements[0].reference.handle;
1237 wakeup->gpe_number =
1238 (u32) element->package.elements[1].integer.value;
1239 } else if (element->type == ACPI_TYPE_INTEGER) {
1240 wakeup->gpe_device = NULL;
1241 wakeup->gpe_number = element->integer.value;
1242 } else {
1243 goto out;
1244 }
1245
1246 element = &(package->package.elements[1]);
1247 if (element->type != ACPI_TYPE_INTEGER)
1248 goto out;
1249
1250 wakeup->sleep_state = element->integer.value;
1251
1252 err = acpi_extract_power_resources(package, 2, &wakeup->resources);
1253 if (err)
1254 goto out;
1255
1256 if (!list_empty(&wakeup->resources)) {
1257 int sleep_state;
1258
1259 err = acpi_power_wakeup_list_init(&wakeup->resources,
1260 &sleep_state);
1261 if (err) {
1262 acpi_handle_warn(handle, "Retrieving current states "
1263 "of wakeup power resources failed\n");
1264 acpi_power_resources_list_free(&wakeup->resources);
1265 goto out;
1266 }
1267 if (sleep_state < wakeup->sleep_state) {
1268 acpi_handle_warn(handle, "Overriding _PRW sleep state "
1269 "(S%d) by S%d from power resources\n",
1270 (int)wakeup->sleep_state, sleep_state);
1271 wakeup->sleep_state = sleep_state;
1272 }
1273 }
1274 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
1275
1276 out:
1277 kfree(buffer.pointer);
1278 return err;
1279 }
1280
1281 static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
1282 {
1283 struct acpi_device_id button_device_ids[] = {
1284 {"PNP0C0C", 0},
1285 {"PNP0C0D", 0},
1286 {"PNP0C0E", 0},
1287 {"", 0},
1288 };
1289 acpi_status status;
1290 acpi_event_status event_status;
1291
1292 device->wakeup.flags.notifier_present = 0;
1293
1294 /* Power button, Lid switch always enable wakeup */
1295 if (!acpi_match_device_ids(device, button_device_ids)) {
1296 device->wakeup.flags.run_wake = 1;
1297 if (!acpi_match_device_ids(device, &button_device_ids[1])) {
1298 /* Do not use Lid/sleep button for S5 wakeup */
1299 if (device->wakeup.sleep_state == ACPI_STATE_S5)
1300 device->wakeup.sleep_state = ACPI_STATE_S4;
1301 }
1302 device_set_wakeup_capable(&device->dev, true);
1303 return;
1304 }
1305
1306 status = acpi_get_gpe_status(device->wakeup.gpe_device,
1307 device->wakeup.gpe_number,
1308 &event_status);
1309 if (status == AE_OK)
1310 device->wakeup.flags.run_wake =
1311 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
1312 }
1313
1314 static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
1315 {
1316 int err;
1317
1318 /* Presence of _PRW indicates wake capable */
1319 if (!acpi_has_method(device->handle, "_PRW"))
1320 return;
1321
1322 err = acpi_bus_extract_wakeup_device_power_package(device->handle,
1323 &device->wakeup);
1324 if (err) {
1325 dev_err(&device->dev, "_PRW evaluation error: %d\n", err);
1326 return;
1327 }
1328
1329 device->wakeup.flags.valid = 1;
1330 device->wakeup.prepare_count = 0;
1331 acpi_bus_set_run_wake_flags(device);
1332 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
1333 * system for the ACPI device with the _PRW object.
1334 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
1335 * So it is necessary to call _DSW object first. Only when it is not
1336 * present will the _PSW object used.
1337 */
1338 err = acpi_device_sleep_wake(device, 0, 0, 0);
1339 if (err)
1340 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1341 "error in _DSW or _PSW evaluation\n"));
1342 }
1343
1344 static void acpi_bus_init_power_state(struct acpi_device *device, int state)
1345 {
1346 struct acpi_device_power_state *ps = &device->power.states[state];
1347 char pathname[5] = { '_', 'P', 'R', '0' + state, '\0' };
1348 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1349 acpi_status status;
1350
1351 INIT_LIST_HEAD(&ps->resources);
1352
1353 /* Evaluate "_PRx" to get referenced power resources */
1354 status = acpi_evaluate_object(device->handle, pathname, NULL, &buffer);
1355 if (ACPI_SUCCESS(status)) {
1356 union acpi_object *package = buffer.pointer;
1357
1358 if (buffer.length && package
1359 && package->type == ACPI_TYPE_PACKAGE
1360 && package->package.count) {
1361 int err = acpi_extract_power_resources(package, 0,
1362 &ps->resources);
1363 if (!err)
1364 device->power.flags.power_resources = 1;
1365 }
1366 ACPI_FREE(buffer.pointer);
1367 }
1368
1369 /* Evaluate "_PSx" to see if we can do explicit sets */
1370 pathname[2] = 'S';
1371 if (acpi_has_method(device->handle, pathname))
1372 ps->flags.explicit_set = 1;
1373
1374 /*
1375 * State is valid if there are means to put the device into it.
1376 * D3hot is only valid if _PR3 present.
1377 */
1378 if (!list_empty(&ps->resources)
1379 || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) {
1380 ps->flags.valid = 1;
1381 ps->flags.os_accessible = 1;
1382 }
1383
1384 ps->power = -1; /* Unknown - driver assigned */
1385 ps->latency = -1; /* Unknown - driver assigned */
1386 }
1387
1388 static void acpi_bus_get_power_flags(struct acpi_device *device)
1389 {
1390 u32 i;
1391
1392 /* Presence of _PS0|_PR0 indicates 'power manageable' */
1393 if (!acpi_has_method(device->handle, "_PS0") &&
1394 !acpi_has_method(device->handle, "_PR0"))
1395 return;
1396
1397 device->flags.power_manageable = 1;
1398
1399 /*
1400 * Power Management Flags
1401 */
1402 if (acpi_has_method(device->handle, "_PSC"))
1403 device->power.flags.explicit_get = 1;
1404 if (acpi_has_method(device->handle, "_IRC"))
1405 device->power.flags.inrush_current = 1;
1406
1407 /*
1408 * Enumerate supported power management states
1409 */
1410 for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
1411 acpi_bus_init_power_state(device, i);
1412
1413 INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
1414
1415 /* Set defaults for D0 and D3 states (always valid) */
1416 device->power.states[ACPI_STATE_D0].flags.valid = 1;
1417 device->power.states[ACPI_STATE_D0].power = 100;
1418 device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
1419 device->power.states[ACPI_STATE_D3_COLD].power = 0;
1420
1421 /* Set D3cold's explicit_set flag if _PS3 exists. */
1422 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set)
1423 device->power.states[ACPI_STATE_D3_COLD].flags.explicit_set = 1;
1424
1425 /* Presence of _PS3 or _PRx means we can put the device into D3 cold */
1426 if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set ||
1427 device->power.flags.power_resources)
1428 device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible = 1;
1429
1430 if (acpi_bus_init_power(device)) {
1431 acpi_free_power_resources_lists(device);
1432 device->flags.power_manageable = 0;
1433 }
1434 }
1435
1436 static void acpi_bus_get_flags(struct acpi_device *device)
1437 {
1438 /* Presence of _STA indicates 'dynamic_status' */
1439 if (acpi_has_method(device->handle, "_STA"))
1440 device->flags.dynamic_status = 1;
1441
1442 /* Presence of _RMV indicates 'removable' */
1443 if (acpi_has_method(device->handle, "_RMV"))
1444 device->flags.removable = 1;
1445
1446 /* Presence of _EJD|_EJ0 indicates 'ejectable' */
1447 if (acpi_has_method(device->handle, "_EJD") ||
1448 acpi_has_method(device->handle, "_EJ0"))
1449 device->flags.ejectable = 1;
1450 }
1451
1452 static void acpi_device_get_busid(struct acpi_device *device)
1453 {
1454 char bus_id[5] = { '?', 0 };
1455 struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
1456 int i = 0;
1457
1458 /*
1459 * Bus ID
1460 * ------
1461 * The device's Bus ID is simply the object name.
1462 * TBD: Shouldn't this value be unique (within the ACPI namespace)?
1463 */
1464 if (ACPI_IS_ROOT_DEVICE(device)) {
1465 strcpy(device->pnp.bus_id, "ACPI");
1466 return;
1467 }
1468
1469 switch (device->device_type) {
1470 case ACPI_BUS_TYPE_POWER_BUTTON:
1471 strcpy(device->pnp.bus_id, "PWRF");
1472 break;
1473 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1474 strcpy(device->pnp.bus_id, "SLPF");
1475 break;
1476 default:
1477 acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
1478 /* Clean up trailing underscores (if any) */
1479 for (i = 3; i > 1; i--) {
1480 if (bus_id[i] == '_')
1481 bus_id[i] = '\0';
1482 else
1483 break;
1484 }
1485 strcpy(device->pnp.bus_id, bus_id);
1486 break;
1487 }
1488 }
1489
1490 /*
1491 * acpi_ata_match - see if an acpi object is an ATA device
1492 *
1493 * If an acpi object has one of the ACPI ATA methods defined,
1494 * then we can safely call it an ATA device.
1495 */
1496 bool acpi_ata_match(acpi_handle handle)
1497 {
1498 return acpi_has_method(handle, "_GTF") ||
1499 acpi_has_method(handle, "_GTM") ||
1500 acpi_has_method(handle, "_STM") ||
1501 acpi_has_method(handle, "_SDD");
1502 }
1503
1504 /*
1505 * acpi_bay_match - see if an acpi object is an ejectable driver bay
1506 *
1507 * If an acpi object is ejectable and has one of the ACPI ATA methods defined,
1508 * then we can safely call it an ejectable drive bay
1509 */
1510 bool acpi_bay_match(acpi_handle handle)
1511 {
1512 acpi_handle phandle;
1513
1514 if (!acpi_has_method(handle, "_EJ0"))
1515 return false;
1516 if (acpi_ata_match(handle))
1517 return true;
1518 if (ACPI_FAILURE(acpi_get_parent(handle, &phandle)))
1519 return false;
1520
1521 return acpi_ata_match(phandle);
1522 }
1523
1524 /*
1525 * acpi_dock_match - see if an acpi object has a _DCK method
1526 */
1527 bool acpi_dock_match(acpi_handle handle)
1528 {
1529 return acpi_has_method(handle, "_DCK");
1530 }
1531
1532 const char *acpi_device_hid(struct acpi_device *device)
1533 {
1534 struct acpi_hardware_id *hid;
1535
1536 if (list_empty(&device->pnp.ids))
1537 return dummy_hid;
1538
1539 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1540 return hid->id;
1541 }
1542 EXPORT_SYMBOL(acpi_device_hid);
1543
1544 static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
1545 {
1546 struct acpi_hardware_id *id;
1547
1548 id = kmalloc(sizeof(*id), GFP_KERNEL);
1549 if (!id)
1550 return;
1551
1552 id->id = kstrdup(dev_id, GFP_KERNEL);
1553 if (!id->id) {
1554 kfree(id);
1555 return;
1556 }
1557
1558 list_add_tail(&id->list, &pnp->ids);
1559 pnp->type.hardware_id = 1;
1560 }
1561
1562 /*
1563 * Old IBM workstations have a DSDT bug wherein the SMBus object
1564 * lacks the SMBUS01 HID and the methods do not have the necessary "_"
1565 * prefix. Work around this.
1566 */
1567 static bool acpi_ibm_smbus_match(acpi_handle handle)
1568 {
1569 char node_name[ACPI_PATH_SEGMENT_LENGTH];
1570 struct acpi_buffer path = { sizeof(node_name), node_name };
1571
1572 if (!dmi_name_in_vendors("IBM"))
1573 return false;
1574
1575 /* Look for SMBS object */
1576 if (ACPI_FAILURE(acpi_get_name(handle, ACPI_SINGLE_NAME, &path)) ||
1577 strcmp("SMBS", path.pointer))
1578 return false;
1579
1580 /* Does it have the necessary (but misnamed) methods? */
1581 if (acpi_has_method(handle, "SBI") &&
1582 acpi_has_method(handle, "SBR") &&
1583 acpi_has_method(handle, "SBW"))
1584 return true;
1585
1586 return false;
1587 }
1588
1589 static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
1590 int device_type)
1591 {
1592 acpi_status status;
1593 struct acpi_device_info *info;
1594 struct acpi_pnp_device_id_list *cid_list;
1595 int i;
1596
1597 switch (device_type) {
1598 case ACPI_BUS_TYPE_DEVICE:
1599 if (handle == ACPI_ROOT_OBJECT) {
1600 acpi_add_id(pnp, ACPI_SYSTEM_HID);
1601 break;
1602 }
1603
1604 status = acpi_get_object_info(handle, &info);
1605 if (ACPI_FAILURE(status)) {
1606 pr_err(PREFIX "%s: Error reading device info\n",
1607 __func__);
1608 return;
1609 }
1610
1611 if (info->valid & ACPI_VALID_HID)
1612 acpi_add_id(pnp, info->hardware_id.string);
1613 if (info->valid & ACPI_VALID_CID) {
1614 cid_list = &info->compatible_id_list;
1615 for (i = 0; i < cid_list->count; i++)
1616 acpi_add_id(pnp, cid_list->ids[i].string);
1617 }
1618 if (info->valid & ACPI_VALID_ADR) {
1619 pnp->bus_address = info->address;
1620 pnp->type.bus_address = 1;
1621 }
1622 if (info->valid & ACPI_VALID_UID)
1623 pnp->unique_id = kstrdup(info->unique_id.string,
1624 GFP_KERNEL);
1625
1626 kfree(info);
1627
1628 /*
1629 * Some devices don't reliably have _HIDs & _CIDs, so add
1630 * synthetic HIDs to make sure drivers can find them.
1631 */
1632 if (acpi_is_video_device(handle))
1633 acpi_add_id(pnp, ACPI_VIDEO_HID);
1634 else if (acpi_bay_match(handle))
1635 acpi_add_id(pnp, ACPI_BAY_HID);
1636 else if (acpi_dock_match(handle))
1637 acpi_add_id(pnp, ACPI_DOCK_HID);
1638 else if (acpi_ibm_smbus_match(handle))
1639 acpi_add_id(pnp, ACPI_SMBUS_IBM_HID);
1640 else if (list_empty(&pnp->ids) && handle == ACPI_ROOT_OBJECT) {
1641 acpi_add_id(pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */
1642 strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME);
1643 strcpy(pnp->device_class, ACPI_BUS_CLASS);
1644 }
1645
1646 break;
1647 case ACPI_BUS_TYPE_POWER:
1648 acpi_add_id(pnp, ACPI_POWER_HID);
1649 break;
1650 case ACPI_BUS_TYPE_PROCESSOR:
1651 acpi_add_id(pnp, ACPI_PROCESSOR_OBJECT_HID);
1652 break;
1653 case ACPI_BUS_TYPE_THERMAL:
1654 acpi_add_id(pnp, ACPI_THERMAL_HID);
1655 break;
1656 case ACPI_BUS_TYPE_POWER_BUTTON:
1657 acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF);
1658 break;
1659 case ACPI_BUS_TYPE_SLEEP_BUTTON:
1660 acpi_add_id(pnp, ACPI_BUTTON_HID_SLEEPF);
1661 break;
1662 }
1663 }
1664
1665 void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
1666 {
1667 struct acpi_hardware_id *id, *tmp;
1668
1669 list_for_each_entry_safe(id, tmp, &pnp->ids, list) {
1670 kfree(id->id);
1671 kfree(id);
1672 }
1673 kfree(pnp->unique_id);
1674 }
1675
1676 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
1677 int type, unsigned long long sta)
1678 {
1679 INIT_LIST_HEAD(&device->pnp.ids);
1680 device->device_type = type;
1681 device->handle = handle;
1682 device->parent = acpi_bus_get_parent(handle);
1683 acpi_set_device_status(device, sta);
1684 acpi_device_get_busid(device);
1685 acpi_set_pnp_ids(handle, &device->pnp, type);
1686 acpi_bus_get_flags(device);
1687 device->flags.match_driver = false;
1688 device->flags.initialized = true;
1689 device->flags.visited = false;
1690 device_initialize(&device->dev);
1691 dev_set_uevent_suppress(&device->dev, true);
1692 }
1693
1694 void acpi_device_add_finalize(struct acpi_device *device)
1695 {
1696 dev_set_uevent_suppress(&device->dev, false);
1697 kobject_uevent(&device->dev.kobj, KOBJ_ADD);
1698 }
1699
1700 static int acpi_add_single_object(struct acpi_device **child,
1701 acpi_handle handle, int type,
1702 unsigned long long sta)
1703 {
1704 int result;
1705 struct acpi_device *device;
1706 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1707
1708 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
1709 if (!device) {
1710 printk(KERN_ERR PREFIX "Memory allocation error\n");
1711 return -ENOMEM;
1712 }
1713
1714 acpi_init_device_object(device, handle, type, sta);
1715 acpi_bus_get_power_flags(device);
1716 acpi_bus_get_wakeup_device_flags(device);
1717
1718 result = acpi_device_add(device, acpi_device_release);
1719 if (result) {
1720 acpi_device_release(&device->dev);
1721 return result;
1722 }
1723
1724 acpi_power_add_remove_device(device, true);
1725 acpi_device_add_finalize(device);
1726 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
1727 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Added %s [%s] parent %s\n",
1728 dev_name(&device->dev), (char *) buffer.pointer,
1729 device->parent ? dev_name(&device->parent->dev) : "(null)"));
1730 kfree(buffer.pointer);
1731 *child = device;
1732 return 0;
1733 }
1734
1735 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1736 unsigned long long *sta)
1737 {
1738 acpi_status status;
1739 acpi_object_type acpi_type;
1740
1741 status = acpi_get_type(handle, &acpi_type);
1742 if (ACPI_FAILURE(status))
1743 return -ENODEV;
1744
1745 switch (acpi_type) {
1746 case ACPI_TYPE_ANY: /* for ACPI_ROOT_OBJECT */
1747 case ACPI_TYPE_DEVICE:
1748 *type = ACPI_BUS_TYPE_DEVICE;
1749 status = acpi_bus_get_status_handle(handle, sta);
1750 if (ACPI_FAILURE(status))
1751 return -ENODEV;
1752 break;
1753 case ACPI_TYPE_PROCESSOR:
1754 *type = ACPI_BUS_TYPE_PROCESSOR;
1755 status = acpi_bus_get_status_handle(handle, sta);
1756 if (ACPI_FAILURE(status))
1757 return -ENODEV;
1758 break;
1759 case ACPI_TYPE_THERMAL:
1760 *type = ACPI_BUS_TYPE_THERMAL;
1761 *sta = ACPI_STA_DEFAULT;
1762 break;
1763 case ACPI_TYPE_POWER:
1764 *type = ACPI_BUS_TYPE_POWER;
1765 *sta = ACPI_STA_DEFAULT;
1766 break;
1767 default:
1768 return -ENODEV;
1769 }
1770
1771 return 0;
1772 }
1773
1774 bool acpi_device_is_present(struct acpi_device *adev)
1775 {
1776 if (adev->status.present || adev->status.functional)
1777 return true;
1778
1779 adev->flags.initialized = false;
1780 return false;
1781 }
1782
1783 static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
1784 char *idstr,
1785 const struct acpi_device_id **matchid)
1786 {
1787 const struct acpi_device_id *devid;
1788
1789 for (devid = handler->ids; devid->id[0]; devid++)
1790 if (!strcmp((char *)devid->id, idstr)) {
1791 if (matchid)
1792 *matchid = devid;
1793
1794 return true;
1795 }
1796
1797 return false;
1798 }
1799
1800 static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr,
1801 const struct acpi_device_id **matchid)
1802 {
1803 struct acpi_scan_handler *handler;
1804
1805 list_for_each_entry(handler, &acpi_scan_handlers_list, list_node)
1806 if (acpi_scan_handler_matching(handler, idstr, matchid))
1807 return handler;
1808
1809 return NULL;
1810 }
1811
1812 void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val)
1813 {
1814 if (!!hotplug->enabled == !!val)
1815 return;
1816
1817 mutex_lock(&acpi_scan_lock);
1818
1819 hotplug->enabled = val;
1820
1821 mutex_unlock(&acpi_scan_lock);
1822 }
1823
1824 static void acpi_scan_init_hotplug(acpi_handle handle, int type)
1825 {
1826 struct acpi_device_pnp pnp = {};
1827 struct acpi_hardware_id *hwid;
1828 struct acpi_scan_handler *handler;
1829
1830 INIT_LIST_HEAD(&pnp.ids);
1831 acpi_set_pnp_ids(handle, &pnp, type);
1832
1833 if (!pnp.type.hardware_id)
1834 goto out;
1835
1836 /*
1837 * This relies on the fact that acpi_install_notify_handler() will not
1838 * install the same notify handler routine twice for the same handle.
1839 */
1840 list_for_each_entry(hwid, &pnp.ids, list) {
1841 handler = acpi_scan_match_handler(hwid->id, NULL);
1842 if (handler) {
1843 acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
1844 acpi_hotplug_notify_cb, handler);
1845 break;
1846 }
1847 }
1848
1849 out:
1850 acpi_free_pnp_ids(&pnp);
1851 }
1852
1853 static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
1854 void *not_used, void **return_value)
1855 {
1856 struct acpi_device *device = NULL;
1857 int type;
1858 unsigned long long sta;
1859 int result;
1860
1861 acpi_bus_get_device(handle, &device);
1862 if (device)
1863 goto out;
1864
1865 result = acpi_bus_type_and_status(handle, &type, &sta);
1866 if (result)
1867 return AE_OK;
1868
1869 if (type == ACPI_BUS_TYPE_POWER) {
1870 acpi_add_power_resource(handle);
1871 return AE_OK;
1872 }
1873
1874 acpi_scan_init_hotplug(handle, type);
1875
1876 acpi_add_single_object(&device, handle, type, sta);
1877 if (!device)
1878 return AE_CTRL_DEPTH;
1879
1880 out:
1881 if (!*return_value)
1882 *return_value = device;
1883
1884 return AE_OK;
1885 }
1886
1887 static int acpi_scan_attach_handler(struct acpi_device *device)
1888 {
1889 struct acpi_hardware_id *hwid;
1890 int ret = 0;
1891
1892 list_for_each_entry(hwid, &device->pnp.ids, list) {
1893 const struct acpi_device_id *devid;
1894 struct acpi_scan_handler *handler;
1895
1896 handler = acpi_scan_match_handler(hwid->id, &devid);
1897 if (handler) {
1898 ret = handler->attach(device, devid);
1899 if (ret > 0) {
1900 device->handler = handler;
1901 break;
1902 } else if (ret < 0) {
1903 break;
1904 }
1905 }
1906 }
1907 return ret;
1908 }
1909
1910 static void acpi_bus_attach(struct acpi_device *device)
1911 {
1912 struct acpi_device *child;
1913 int ret;
1914
1915 acpi_bus_get_status(device);
1916 /* Skip devices that are not present. */
1917 if (!acpi_device_is_present(device)) {
1918 device->flags.visited = false;
1919 return;
1920 }
1921 if (device->handler)
1922 goto ok;
1923
1924 if (!device->flags.initialized) {
1925 acpi_bus_update_power(device, NULL);
1926 device->flags.initialized = true;
1927 }
1928 device->flags.visited = false;
1929 ret = acpi_scan_attach_handler(device);
1930 if (ret < 0)
1931 return;
1932
1933 device->flags.match_driver = true;
1934 if (!ret) {
1935 ret = device_attach(&device->dev);
1936 if (ret < 0)
1937 return;
1938 }
1939 device->flags.visited = true;
1940
1941 ok:
1942 list_for_each_entry(child, &device->children, node)
1943 acpi_bus_attach(child);
1944 }
1945
1946 /**
1947 * acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
1948 * @handle: Root of the namespace scope to scan.
1949 *
1950 * Scan a given ACPI tree (probably recently hot-plugged) and create and add
1951 * found devices.
1952 *
1953 * If no devices were found, -ENODEV is returned, but it does not mean that
1954 * there has been a real error. There just have been no suitable ACPI objects
1955 * in the table trunk from which the kernel could create a device and add an
1956 * appropriate driver.
1957 *
1958 * Must be called under acpi_scan_lock.
1959 */
1960 int acpi_bus_scan(acpi_handle handle)
1961 {
1962 void *device = NULL;
1963
1964 if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
1965 acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
1966 acpi_bus_check_add, NULL, NULL, &device);
1967
1968 if (device) {
1969 acpi_bus_attach(device);
1970 return 0;
1971 }
1972 return -ENODEV;
1973 }
1974 EXPORT_SYMBOL(acpi_bus_scan);
1975
1976 /**
1977 * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
1978 * @adev: Root of the ACPI namespace scope to walk.
1979 *
1980 * Must be called under acpi_scan_lock.
1981 */
1982 void acpi_bus_trim(struct acpi_device *adev)
1983 {
1984 struct acpi_scan_handler *handler = adev->handler;
1985 struct acpi_device *child;
1986
1987 list_for_each_entry_reverse(child, &adev->children, node)
1988 acpi_bus_trim(child);
1989
1990 if (handler) {
1991 if (handler->detach)
1992 handler->detach(adev);
1993
1994 adev->handler = NULL;
1995 } else {
1996 device_release_driver(&adev->dev);
1997 }
1998 /*
1999 * Most likely, the device is going away, so put it into D3cold before
2000 * that.
2001 */
2002 acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
2003 adev->flags.initialized = false;
2004 adev->flags.visited = false;
2005 }
2006 EXPORT_SYMBOL_GPL(acpi_bus_trim);
2007
2008 static int acpi_bus_scan_fixed(void)
2009 {
2010 int result = 0;
2011
2012 /*
2013 * Enumerate all fixed-feature devices.
2014 */
2015 if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
2016 struct acpi_device *device = NULL;
2017
2018 result = acpi_add_single_object(&device, NULL,
2019 ACPI_BUS_TYPE_POWER_BUTTON,
2020 ACPI_STA_DEFAULT);
2021 if (result)
2022 return result;
2023
2024 device->flags.match_driver = true;
2025 result = device_attach(&device->dev);
2026 if (result < 0)
2027 return result;
2028
2029 device_init_wakeup(&device->dev, true);
2030 }
2031
2032 if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
2033 struct acpi_device *device = NULL;
2034
2035 result = acpi_add_single_object(&device, NULL,
2036 ACPI_BUS_TYPE_SLEEP_BUTTON,
2037 ACPI_STA_DEFAULT);
2038 if (result)
2039 return result;
2040
2041 device->flags.match_driver = true;
2042 result = device_attach(&device->dev);
2043 }
2044
2045 return result < 0 ? result : 0;
2046 }
2047
2048 int __init acpi_scan_init(void)
2049 {
2050 int result;
2051
2052 result = bus_register(&acpi_bus_type);
2053 if (result) {
2054 /* We don't want to quit even if we failed to add suspend/resume */
2055 printk(KERN_ERR PREFIX "Could not register bus type\n");
2056 }
2057
2058 acpi_pci_root_init();
2059 acpi_pci_link_init();
2060 acpi_processor_init();
2061 acpi_platform_init();
2062 acpi_lpss_init();
2063 acpi_cmos_rtc_init();
2064 acpi_container_init();
2065 acpi_memory_hotplug_init();
2066 acpi_dock_init();
2067
2068 mutex_lock(&acpi_scan_lock);
2069 /*
2070 * Enumerate devices in the ACPI namespace.
2071 */
2072 result = acpi_bus_scan(ACPI_ROOT_OBJECT);
2073 if (result)
2074 goto out;
2075
2076 result = acpi_bus_get_device(ACPI_ROOT_OBJECT, &acpi_root);
2077 if (result)
2078 goto out;
2079
2080 result = acpi_bus_scan_fixed();
2081 if (result) {
2082 acpi_detach_data(acpi_root->handle, acpi_scan_drop_device);
2083 acpi_device_del(acpi_root);
2084 put_device(&acpi_root->dev);
2085 goto out;
2086 }
2087
2088 acpi_update_all_gpes();
2089
2090 out:
2091 mutex_unlock(&acpi_scan_lock);
2092 return result;
2093 }
This page took 0.094846 seconds and 5 git commands to generate.