aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c206
1 files changed, 129 insertions, 77 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index b23825ecfa37..449c556274c0 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -26,6 +26,8 @@ extern struct acpi_device *acpi_root;
26 26
27#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent) 27#define ACPI_IS_ROOT_DEVICE(device) (!(device)->parent)
28 28
29static const char *dummy_hid = "device";
30
29static LIST_HEAD(acpi_device_list); 31static LIST_HEAD(acpi_device_list);
30static LIST_HEAD(acpi_bus_id_list); 32static LIST_HEAD(acpi_bus_id_list);
31DEFINE_MUTEX(acpi_device_lock); 33DEFINE_MUTEX(acpi_device_lock);
@@ -49,6 +51,9 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
49 int count; 51 int count;
50 struct acpi_hardware_id *id; 52 struct acpi_hardware_id *id;
51 53
54 if (list_empty(&acpi_dev->pnp.ids))
55 return 0;
56
52 len = snprintf(modalias, size, "acpi:"); 57 len = snprintf(modalias, size, "acpi:");
53 size -= len; 58 size -= len;
54 59
@@ -202,13 +207,15 @@ static int acpi_device_setup_files(struct acpi_device *dev)
202 goto end; 207 goto end;
203 } 208 }
204 209
205 result = device_create_file(&dev->dev, &dev_attr_hid); 210 if (!list_empty(&dev->pnp.ids)) {
206 if (result) 211 result = device_create_file(&dev->dev, &dev_attr_hid);
207 goto end; 212 if (result)
213 goto end;
208 214
209 result = device_create_file(&dev->dev, &dev_attr_modalias); 215 result = device_create_file(&dev->dev, &dev_attr_modalias);
210 if (result) 216 if (result)
211 goto end; 217 goto end;
218 }
212 219
213 /* 220 /*
214 * If device has _EJ0, 'eject' file is created that is used to trigger 221 * If device has _EJ0, 'eject' file is created that is used to trigger
@@ -316,6 +323,9 @@ static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
316 struct acpi_device *acpi_dev = to_acpi_device(dev); 323 struct acpi_device *acpi_dev = to_acpi_device(dev);
317 int len; 324 int len;
318 325
326 if (list_empty(&acpi_dev->pnp.ids))
327 return 0;
328
319 if (add_uevent_var(env, "MODALIAS=")) 329 if (add_uevent_var(env, "MODALIAS="))
320 return -ENOMEM; 330 return -ENOMEM;
321 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1], 331 len = create_modalias(acpi_dev, &env->buf[env->buflen - 1],
@@ -695,54 +705,85 @@ static int acpi_bus_get_perf_flags(struct acpi_device *device)
695} 705}
696 706
697static acpi_status 707static acpi_status
698acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device, 708acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
699 union acpi_object *package) 709 struct acpi_device_wakeup *wakeup)
700{ 710{
701 int i = 0; 711 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
712 union acpi_object *package = NULL;
702 union acpi_object *element = NULL; 713 union acpi_object *element = NULL;
714 acpi_status status;
715 int i = 0;
703 716
704 if (!device || !package || (package->package.count < 2)) 717 if (!wakeup)
705 return AE_BAD_PARAMETER; 718 return AE_BAD_PARAMETER;
706 719
720 /* _PRW */
721 status = acpi_evaluate_object(handle, "_PRW", NULL, &buffer);
722 if (ACPI_FAILURE(status)) {
723 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW"));
724 return status;
725 }
726
727 package = (union acpi_object *)buffer.pointer;
728
729 if (!package || (package->package.count < 2)) {
730 status = AE_BAD_DATA;
731 goto out;
732 }
733
707 element = &(package->package.elements[0]); 734 element = &(package->package.elements[0]);
708 if (!element) 735 if (!element) {
709 return AE_BAD_PARAMETER; 736 status = AE_BAD_DATA;
737 goto out;
738 }
710 if (element->type == ACPI_TYPE_PACKAGE) { 739 if (element->type == ACPI_TYPE_PACKAGE) {
711 if ((element->package.count < 2) || 740 if ((element->package.count < 2) ||
712 (element->package.elements[0].type != 741 (element->package.elements[0].type !=
713 ACPI_TYPE_LOCAL_REFERENCE) 742 ACPI_TYPE_LOCAL_REFERENCE)
714 || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) 743 || (element->package.elements[1].type != ACPI_TYPE_INTEGER)) {
715 return AE_BAD_DATA; 744 status = AE_BAD_DATA;
716 device->wakeup.gpe_device = 745 goto out;
746 }
747 wakeup->gpe_device =
717 element->package.elements[0].reference.handle; 748 element->package.elements[0].reference.handle;
718 device->wakeup.gpe_number = 749 wakeup->gpe_number =
719 (u32) element->package.elements[1].integer.value; 750 (u32) element->package.elements[1].integer.value;
720 } else if (element->type == ACPI_TYPE_INTEGER) { 751 } else if (element->type == ACPI_TYPE_INTEGER) {
721 device->wakeup.gpe_number = element->integer.value; 752 wakeup->gpe_device = NULL;
722 } else 753 wakeup->gpe_number = element->integer.value;
723 return AE_BAD_DATA; 754 } else {
755 status = AE_BAD_DATA;
756 goto out;
757 }
724 758
725 element = &(package->package.elements[1]); 759 element = &(package->package.elements[1]);
726 if (element->type != ACPI_TYPE_INTEGER) { 760 if (element->type != ACPI_TYPE_INTEGER) {
727 return AE_BAD_DATA; 761 status = AE_BAD_DATA;
762 goto out;
728 } 763 }
729 device->wakeup.sleep_state = element->integer.value; 764 wakeup->sleep_state = element->integer.value;
730 765
731 if ((package->package.count - 2) > ACPI_MAX_HANDLES) { 766 if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
732 return AE_NO_MEMORY; 767 status = AE_NO_MEMORY;
768 goto out;
733 } 769 }
734 device->wakeup.resources.count = package->package.count - 2; 770 wakeup->resources.count = package->package.count - 2;
735 for (i = 0; i < device->wakeup.resources.count; i++) { 771 for (i = 0; i < wakeup->resources.count; i++) {
736 element = &(package->package.elements[i + 2]); 772 element = &(package->package.elements[i + 2]);
737 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) 773 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
738 return AE_BAD_DATA; 774 status = AE_BAD_DATA;
775 goto out;
776 }
739 777
740 device->wakeup.resources.handles[i] = element->reference.handle; 778 wakeup->resources.handles[i] = element->reference.handle;
741 } 779 }
742 780
743 acpi_gpe_can_wake(device->wakeup.gpe_device, device->wakeup.gpe_number); 781 acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
744 782
745 return AE_OK; 783 out:
784 kfree(buffer.pointer);
785
786 return status;
746} 787}
747 788
748static void acpi_bus_set_run_wake_flags(struct acpi_device *device) 789static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
@@ -756,13 +797,12 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
756 acpi_status status; 797 acpi_status status;
757 acpi_event_status event_status; 798 acpi_event_status event_status;
758 799
759 device->wakeup.run_wake_count = 0;
760 device->wakeup.flags.notifier_present = 0; 800 device->wakeup.flags.notifier_present = 0;
761 801
762 /* Power button, Lid switch always enable wakeup */ 802 /* Power button, Lid switch always enable wakeup */
763 if (!acpi_match_device_ids(device, button_device_ids)) { 803 if (!acpi_match_device_ids(device, button_device_ids)) {
764 device->wakeup.flags.run_wake = 1; 804 device->wakeup.flags.run_wake = 1;
765 device->wakeup.flags.always_enabled = 1; 805 device_set_wakeup_capable(&device->dev, true);
766 return; 806 return;
767 } 807 }
768 808
@@ -774,29 +814,24 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
774 !!(event_status & ACPI_EVENT_FLAG_HANDLE); 814 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
775} 815}
776 816
777static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) 817static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
778{ 818{
819 acpi_handle temp;
779 acpi_status status = 0; 820 acpi_status status = 0;
780 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
781 union acpi_object *package = NULL;
782 int psw_error; 821 int psw_error;
783 822
784 /* _PRW */ 823 /* Presence of _PRW indicates wake capable */
785 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 824 status = acpi_get_handle(device->handle, "_PRW", &temp);
786 if (ACPI_FAILURE(status)) { 825 if (ACPI_FAILURE(status))
787 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRW")); 826 return;
788 goto end;
789 }
790 827
791 package = (union acpi_object *)buffer.pointer; 828 status = acpi_bus_extract_wakeup_device_power_package(device->handle,
792 status = acpi_bus_extract_wakeup_device_power_package(device, package); 829 &device->wakeup);
793 if (ACPI_FAILURE(status)) { 830 if (ACPI_FAILURE(status)) {
794 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package")); 831 ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
795 goto end; 832 return;
796 } 833 }
797 834
798 kfree(buffer.pointer);
799
800 device->wakeup.flags.valid = 1; 835 device->wakeup.flags.valid = 1;
801 device->wakeup.prepare_count = 0; 836 device->wakeup.prepare_count = 0;
802 acpi_bus_set_run_wake_flags(device); 837 acpi_bus_set_run_wake_flags(device);
@@ -810,13 +845,10 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
810 if (psw_error) 845 if (psw_error)
811 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 846 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
812 "error in _DSW or _PSW evaluation\n")); 847 "error in _DSW or _PSW evaluation\n"));
813
814end:
815 if (ACPI_FAILURE(status))
816 device->flags.wake_capable = 0;
817 return 0;
818} 848}
819 849
850static void acpi_bus_add_power_resource(acpi_handle handle);
851
820static int acpi_bus_get_power_flags(struct acpi_device *device) 852static int acpi_bus_get_power_flags(struct acpi_device *device)
821{ 853{
822 acpi_status status = 0; 854 acpi_status status = 0;
@@ -845,8 +877,12 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
845 acpi_evaluate_reference(device->handle, object_name, NULL, 877 acpi_evaluate_reference(device->handle, object_name, NULL,
846 &ps->resources); 878 &ps->resources);
847 if (ps->resources.count) { 879 if (ps->resources.count) {
880 int j;
881
848 device->power.flags.power_resources = 1; 882 device->power.flags.power_resources = 1;
849 ps->flags.valid = 1; 883 ps->flags.valid = 1;
884 for (j = 0; j < ps->resources.count; j++)
885 acpi_bus_add_power_resource(ps->resources.handles[j]);
850 } 886 }
851 887
852 /* Evaluate "_PSx" to see if we can do explicit sets */ 888 /* Evaluate "_PSx" to see if we can do explicit sets */
@@ -871,10 +907,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
871 device->power.states[ACPI_STATE_D3].flags.valid = 1; 907 device->power.states[ACPI_STATE_D3].flags.valid = 1;
872 device->power.states[ACPI_STATE_D3].power = 0; 908 device->power.states[ACPI_STATE_D3].power = 0;
873 909
874 /* TBD: System wake support and resource requirements. */ 910 acpi_bus_init_power(device);
875
876 device->power.state = ACPI_STATE_UNKNOWN;
877 acpi_bus_get_power(device->handle, &(device->power.state));
878 911
879 return 0; 912 return 0;
880} 913}
@@ -910,6 +943,10 @@ static int acpi_bus_get_flags(struct acpi_device *device)
910 if (ACPI_SUCCESS(status)) 943 if (ACPI_SUCCESS(status))
911 device->flags.lockable = 1; 944 device->flags.lockable = 1;
912 945
946 /* Power resources cannot be power manageable. */
947 if (device->device_type == ACPI_BUS_TYPE_POWER)
948 return 0;
949
913 /* Presence of _PS0|_PR0 indicates 'power manageable' */ 950 /* Presence of _PS0|_PR0 indicates 'power manageable' */
914 status = acpi_get_handle(device->handle, "_PS0", &temp); 951 status = acpi_get_handle(device->handle, "_PS0", &temp);
915 if (ACPI_FAILURE(status)) 952 if (ACPI_FAILURE(status))
@@ -917,11 +954,6 @@ static int acpi_bus_get_flags(struct acpi_device *device)
917 if (ACPI_SUCCESS(status)) 954 if (ACPI_SUCCESS(status))
918 device->flags.power_manageable = 1; 955 device->flags.power_manageable = 1;
919 956
920 /* Presence of _PRW indicates wake capable */
921 status = acpi_get_handle(device->handle, "_PRW", &temp);
922 if (ACPI_SUCCESS(status))
923 device->flags.wake_capable = 1;
924
925 /* TBD: Performance management */ 957 /* TBD: Performance management */
926 958
927 return 0; 959 return 0;
@@ -1010,10 +1042,13 @@ static int acpi_dock_match(struct acpi_device *device)
1010 return acpi_get_handle(device->handle, "_DCK", &tmp); 1042 return acpi_get_handle(device->handle, "_DCK", &tmp);
1011} 1043}
1012 1044
1013char *acpi_device_hid(struct acpi_device *device) 1045const char *acpi_device_hid(struct acpi_device *device)
1014{ 1046{
1015 struct acpi_hardware_id *hid; 1047 struct acpi_hardware_id *hid;
1016 1048
1049 if (list_empty(&device->pnp.ids))
1050 return dummy_hid;
1051
1017 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list); 1052 hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
1018 return hid->id; 1053 return hid->id;
1019} 1054}
@@ -1142,16 +1177,6 @@ static void acpi_device_set_id(struct acpi_device *device)
1142 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF); 1177 acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
1143 break; 1178 break;
1144 } 1179 }
1145
1146 /*
1147 * We build acpi_devices for some objects that don't have _HID or _CID,
1148 * e.g., PCI bridges and slots. Drivers can't bind to these objects,
1149 * but we do use them indirectly by traversing the acpi_device tree.
1150 * This generic ID isn't useful for driver binding, but it provides
1151 * the useful property that "every acpi_device has an ID."
1152 */
1153 if (list_empty(&device->pnp.ids))
1154 acpi_add_id(device, "device");
1155} 1180}
1156 1181
1157static int acpi_device_set_context(struct acpi_device *device) 1182static int acpi_device_set_context(struct acpi_device *device)
@@ -1255,11 +1280,7 @@ static int acpi_add_single_object(struct acpi_device **child,
1255 * Wakeup device management 1280 * Wakeup device management
1256 *----------------------- 1281 *-----------------------
1257 */ 1282 */
1258 if (device->flags.wake_capable) { 1283 acpi_bus_get_wakeup_device_flags(device);
1259 result = acpi_bus_get_wakeup_device_flags(device);
1260 if (result)
1261 goto end;
1262 }
1263 1284
1264 /* 1285 /*
1265 * Performance Management 1286 * Performance Management
@@ -1303,6 +1324,20 @@ end:
1303#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ 1324#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
1304 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) 1325 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
1305 1326
1327static void acpi_bus_add_power_resource(acpi_handle handle)
1328{
1329 struct acpi_bus_ops ops = {
1330 .acpi_op_add = 1,
1331 .acpi_op_start = 1,
1332 };
1333 struct acpi_device *device = NULL;
1334
1335 acpi_bus_get_device(handle, &device);
1336 if (!device)
1337 acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,
1338 ACPI_STA_DEFAULT, &ops);
1339}
1340
1306static int acpi_bus_type_and_status(acpi_handle handle, int *type, 1341static int acpi_bus_type_and_status(acpi_handle handle, int *type,
1307 unsigned long long *sta) 1342 unsigned long long *sta)
1308{ 1343{
@@ -1357,8 +1392,16 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
1357 return AE_OK; 1392 return AE_OK;
1358 1393
1359 if (!(sta & ACPI_STA_DEVICE_PRESENT) && 1394 if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
1360 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) 1395 !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
1396 struct acpi_device_wakeup wakeup;
1397 acpi_handle temp;
1398
1399 status = acpi_get_handle(handle, "_PRW", &temp);
1400 if (ACPI_SUCCESS(status))
1401 acpi_bus_extract_wakeup_device_power_package(handle,
1402 &wakeup);
1361 return AE_CTRL_DEPTH; 1403 return AE_CTRL_DEPTH;
1404 }
1362 1405
1363 /* 1406 /*
1364 * We may already have an acpi_device from a previous enumeration. If 1407 * We may already have an acpi_device from a previous enumeration. If
@@ -1431,6 +1474,7 @@ EXPORT_SYMBOL(acpi_bus_add);
1431int acpi_bus_start(struct acpi_device *device) 1474int acpi_bus_start(struct acpi_device *device)
1432{ 1475{
1433 struct acpi_bus_ops ops; 1476 struct acpi_bus_ops ops;
1477 int result;
1434 1478
1435 if (!device) 1479 if (!device)
1436 return -EINVAL; 1480 return -EINVAL;
@@ -1438,7 +1482,11 @@ int acpi_bus_start(struct acpi_device *device)
1438 memset(&ops, 0, sizeof(ops)); 1482 memset(&ops, 0, sizeof(ops));
1439 ops.acpi_op_start = 1; 1483 ops.acpi_op_start = 1;
1440 1484
1441 return acpi_bus_scan(device->handle, &ops, NULL); 1485 result = acpi_bus_scan(device->handle, &ops, NULL);
1486
1487 acpi_update_all_gpes();
1488
1489 return result;
1442} 1490}
1443EXPORT_SYMBOL(acpi_bus_start); 1491EXPORT_SYMBOL(acpi_bus_start);
1444 1492
@@ -1542,6 +1590,8 @@ int __init acpi_scan_init(void)
1542 printk(KERN_ERR PREFIX "Could not register bus type\n"); 1590 printk(KERN_ERR PREFIX "Could not register bus type\n");
1543 } 1591 }
1544 1592
1593 acpi_power_init();
1594
1545 /* 1595 /*
1546 * Enumerate devices in the ACPI namespace. 1596 * Enumerate devices in the ACPI namespace.
1547 */ 1597 */
@@ -1552,6 +1602,8 @@ int __init acpi_scan_init(void)
1552 1602
1553 if (result) 1603 if (result)
1554 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL); 1604 acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
1605 else
1606 acpi_update_all_gpes();
1555 1607
1556 return result; 1608 return result;
1557} 1609}