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