aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-11-07 13:13:52 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-07 13:13:52 -0500
commit3c00303206c3a1ccd86579efdc90bc35f140962e (patch)
tree66170c84b5ddaeb102aea3530517a26657b6ea29 /drivers/acpi
parent83dbb15e9cd78a3619e3db36777e2f81d09b2914 (diff)
parentefb90582c575084723cc14302c1300cb26c7e01f (diff)
Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux
* 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux: cpuidle: Single/Global registration of idle states cpuidle: Split cpuidle_state structure and move per-cpu statistics fields cpuidle: Remove CPUIDLE_FLAG_IGNORE and dev->prepare() cpuidle: Move dev->last_residency update to driver enter routine; remove dev->last_state ACPI: Fix CONFIG_ACPI_DOCK=n compiler warning ACPI: Export FADT pm_profile integer value to userspace thermal: Prevent polling from happening during system suspend ACPI: Drop ACPI_NO_HARDWARE_INIT ACPI atomicio: Convert width in bits to bytes in __acpi_ioremap_fast() PNPACPI: Simplify disabled resource registration ACPI: Fix possible recursive locking in hwregs.c ACPI: use kstrdup() mrst pmu: update comment tools/power turbostat: less verbose debugging
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/acpica/hwregs.c11
-rw-r--r--drivers/acpi/atomicio.c2
-rw-r--r--drivers/acpi/bus.c8
-rw-r--r--drivers/acpi/processor_driver.c20
-rw-r--r--drivers/acpi/processor_idle.c251
-rw-r--r--drivers/acpi/scan.c3
-rw-r--r--drivers/acpi/sysfs.c14
7 files changed, 233 insertions, 76 deletions
diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 55accb7018bb..cc70f3fdcdd1 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -269,16 +269,17 @@ acpi_status acpi_hw_clear_acpi_status(void)
269 269
270 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS, 270 status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
271 ACPI_BITMASK_ALL_FIXED_STATUS); 271 ACPI_BITMASK_ALL_FIXED_STATUS);
272 if (ACPI_FAILURE(status)) { 272
273 goto unlock_and_exit; 273 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
274 } 274
275 if (ACPI_FAILURE(status))
276 goto exit;
275 277
276 /* Clear the GPE Bits in all GPE registers in all GPE blocks */ 278 /* Clear the GPE Bits in all GPE registers in all GPE blocks */
277 279
278 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL); 280 status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
279 281
280 unlock_and_exit: 282exit:
281 acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
282 return_ACPI_STATUS(status); 283 return_ACPI_STATUS(status);
283} 284}
284 285
diff --git a/drivers/acpi/atomicio.c b/drivers/acpi/atomicio.c
index 04ae1c88c03c..cfc0cc10af39 100644
--- a/drivers/acpi/atomicio.c
+++ b/drivers/acpi/atomicio.c
@@ -76,7 +76,7 @@ static void __iomem *__acpi_ioremap_fast(phys_addr_t paddr,
76{ 76{
77 struct acpi_iomap *map; 77 struct acpi_iomap *map;
78 78
79 map = __acpi_find_iomap(paddr, size); 79 map = __acpi_find_iomap(paddr, size/8);
80 if (map) 80 if (map)
81 return map->vaddr + (paddr - map->paddr); 81 return map->vaddr + (paddr - map->paddr);
82 else 82 else
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 437ddbf0c49a..9ecec98bc76e 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -911,10 +911,7 @@ void __init acpi_early_init(void)
911 } 911 }
912#endif 912#endif
913 913
914 status = 914 status = acpi_enable_subsystem(~ACPI_NO_ACPI_ENABLE);
915 acpi_enable_subsystem(~
916 (ACPI_NO_HARDWARE_INIT |
917 ACPI_NO_ACPI_ENABLE));
918 if (ACPI_FAILURE(status)) { 915 if (ACPI_FAILURE(status)) {
919 printk(KERN_ERR PREFIX "Unable to enable ACPI\n"); 916 printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
920 goto error0; 917 goto error0;
@@ -935,8 +932,7 @@ static int __init acpi_bus_init(void)
935 932
936 acpi_os_initialize1(); 933 acpi_os_initialize1();
937 934
938 status = 935 status = acpi_enable_subsystem(ACPI_NO_ACPI_ENABLE);
939 acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
940 if (ACPI_FAILURE(status)) { 936 if (ACPI_FAILURE(status)) {
941 printk(KERN_ERR PREFIX 937 printk(KERN_ERR PREFIX
942 "Unable to start the ACPI Interpreter\n"); 938 "Unable to start the ACPI Interpreter\n");
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index a4e0f1ba6040..9d7bc9f6b6cc 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -426,7 +426,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
426 426
427 if (action == CPU_ONLINE && pr) { 427 if (action == CPU_ONLINE && pr) {
428 acpi_processor_ppc_has_changed(pr, 0); 428 acpi_processor_ppc_has_changed(pr, 0);
429 acpi_processor_cst_has_changed(pr); 429 acpi_processor_hotplug(pr);
430 acpi_processor_reevaluate_tstate(pr, action); 430 acpi_processor_reevaluate_tstate(pr, action);
431 acpi_processor_tstate_has_changed(pr); 431 acpi_processor_tstate_has_changed(pr);
432 } 432 }
@@ -503,8 +503,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
503 acpi_processor_get_throttling_info(pr); 503 acpi_processor_get_throttling_info(pr);
504 acpi_processor_get_limit_info(pr); 504 acpi_processor_get_limit_info(pr);
505 505
506 506 if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
507 if (cpuidle_get_driver() == &acpi_idle_driver)
508 acpi_processor_power_init(pr, device); 507 acpi_processor_power_init(pr, device);
509 508
510 pr->cdev = thermal_cooling_device_register("Processor", device, 509 pr->cdev = thermal_cooling_device_register("Processor", device,
@@ -800,17 +799,9 @@ static int __init acpi_processor_init(void)
800 799
801 memset(&errata, 0, sizeof(errata)); 800 memset(&errata, 0, sizeof(errata));
802 801
803 if (!cpuidle_register_driver(&acpi_idle_driver)) {
804 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
805 acpi_idle_driver.name);
806 } else {
807 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
808 cpuidle_get_driver()->name);
809 }
810
811 result = acpi_bus_register_driver(&acpi_processor_driver); 802 result = acpi_bus_register_driver(&acpi_processor_driver);
812 if (result < 0) 803 if (result < 0)
813 goto out_cpuidle; 804 return result;
814 805
815 acpi_processor_install_hotplug_notify(); 806 acpi_processor_install_hotplug_notify();
816 807
@@ -821,11 +812,6 @@ static int __init acpi_processor_init(void)
821 acpi_processor_throttling_init(); 812 acpi_processor_throttling_init();
822 813
823 return 0; 814 return 0;
824
825out_cpuidle:
826 cpuidle_unregister_driver(&acpi_idle_driver);
827
828 return result;
829} 815}
830 816
831static void __exit acpi_processor_exit(void) 817static void __exit acpi_processor_exit(void)
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 9b88f9828d8c..73b2909dddfe 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -741,22 +741,25 @@ static inline void acpi_idle_do_entry(struct acpi_processor_cx *cx)
741/** 741/**
742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type 742 * acpi_idle_enter_c1 - enters an ACPI C1 state-type
743 * @dev: the target CPU 743 * @dev: the target CPU
744 * @state: the state data 744 * @drv: cpuidle driver containing cpuidle state info
745 * @index: index of target state
745 * 746 *
746 * This is equivalent to the HALT instruction. 747 * This is equivalent to the HALT instruction.
747 */ 748 */
748static int acpi_idle_enter_c1(struct cpuidle_device *dev, 749static int acpi_idle_enter_c1(struct cpuidle_device *dev,
749 struct cpuidle_state *state) 750 struct cpuidle_driver *drv, int index)
750{ 751{
751 ktime_t kt1, kt2; 752 ktime_t kt1, kt2;
752 s64 idle_time; 753 s64 idle_time;
753 struct acpi_processor *pr; 754 struct acpi_processor *pr;
754 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 755 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
756 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
755 757
756 pr = __this_cpu_read(processors); 758 pr = __this_cpu_read(processors);
759 dev->last_residency = 0;
757 760
758 if (unlikely(!pr)) 761 if (unlikely(!pr))
759 return 0; 762 return -EINVAL;
760 763
761 local_irq_disable(); 764 local_irq_disable();
762 765
@@ -764,7 +767,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
764 if (acpi_idle_suspend) { 767 if (acpi_idle_suspend) {
765 local_irq_enable(); 768 local_irq_enable();
766 cpu_relax(); 769 cpu_relax();
767 return 0; 770 return -EINVAL;
768 } 771 }
769 772
770 lapic_timer_state_broadcast(pr, cx, 1); 773 lapic_timer_state_broadcast(pr, cx, 1);
@@ -773,37 +776,47 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
773 kt2 = ktime_get_real(); 776 kt2 = ktime_get_real();
774 idle_time = ktime_to_us(ktime_sub(kt2, kt1)); 777 idle_time = ktime_to_us(ktime_sub(kt2, kt1));
775 778
779 /* Update device last_residency*/
780 dev->last_residency = (int)idle_time;
781
776 local_irq_enable(); 782 local_irq_enable();
777 cx->usage++; 783 cx->usage++;
778 lapic_timer_state_broadcast(pr, cx, 0); 784 lapic_timer_state_broadcast(pr, cx, 0);
779 785
780 return idle_time; 786 return index;
781} 787}
782 788
783/** 789/**
784 * acpi_idle_enter_simple - enters an ACPI state without BM handling 790 * acpi_idle_enter_simple - enters an ACPI state without BM handling
785 * @dev: the target CPU 791 * @dev: the target CPU
786 * @state: the state data 792 * @drv: cpuidle driver with cpuidle state information
793 * @index: the index of suggested state
787 */ 794 */
788static int acpi_idle_enter_simple(struct cpuidle_device *dev, 795static int acpi_idle_enter_simple(struct cpuidle_device *dev,
789 struct cpuidle_state *state) 796 struct cpuidle_driver *drv, int index)
790{ 797{
791 struct acpi_processor *pr; 798 struct acpi_processor *pr;
792 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 799 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
800 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
793 ktime_t kt1, kt2; 801 ktime_t kt1, kt2;
794 s64 idle_time_ns; 802 s64 idle_time_ns;
795 s64 idle_time; 803 s64 idle_time;
796 804
797 pr = __this_cpu_read(processors); 805 pr = __this_cpu_read(processors);
806 dev->last_residency = 0;
798 807
799 if (unlikely(!pr)) 808 if (unlikely(!pr))
800 return 0; 809 return -EINVAL;
801
802 if (acpi_idle_suspend)
803 return(acpi_idle_enter_c1(dev, state));
804 810
805 local_irq_disable(); 811 local_irq_disable();
806 812
813 if (acpi_idle_suspend) {
814 local_irq_enable();
815 cpu_relax();
816 return -EINVAL;
817 }
818
819
807 if (cx->entry_method != ACPI_CSTATE_FFH) { 820 if (cx->entry_method != ACPI_CSTATE_FFH) {
808 current_thread_info()->status &= ~TS_POLLING; 821 current_thread_info()->status &= ~TS_POLLING;
809 /* 822 /*
@@ -815,7 +828,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
815 if (unlikely(need_resched())) { 828 if (unlikely(need_resched())) {
816 current_thread_info()->status |= TS_POLLING; 829 current_thread_info()->status |= TS_POLLING;
817 local_irq_enable(); 830 local_irq_enable();
818 return 0; 831 return -EINVAL;
819 } 832 }
820 } 833 }
821 834
@@ -837,6 +850,9 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
837 idle_time = idle_time_ns; 850 idle_time = idle_time_ns;
838 do_div(idle_time, NSEC_PER_USEC); 851 do_div(idle_time, NSEC_PER_USEC);
839 852
853 /* Update device last_residency*/
854 dev->last_residency = (int)idle_time;
855
840 /* Tell the scheduler how much we idled: */ 856 /* Tell the scheduler how much we idled: */
841 sched_clock_idle_wakeup_event(idle_time_ns); 857 sched_clock_idle_wakeup_event(idle_time_ns);
842 858
@@ -848,7 +864,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
848 864
849 lapic_timer_state_broadcast(pr, cx, 0); 865 lapic_timer_state_broadcast(pr, cx, 0);
850 cx->time += idle_time; 866 cx->time += idle_time;
851 return idle_time; 867 return index;
852} 868}
853 869
854static int c3_cpu_count; 870static int c3_cpu_count;
@@ -857,37 +873,43 @@ static DEFINE_RAW_SPINLOCK(c3_lock);
857/** 873/**
858 * acpi_idle_enter_bm - enters C3 with proper BM handling 874 * acpi_idle_enter_bm - enters C3 with proper BM handling
859 * @dev: the target CPU 875 * @dev: the target CPU
860 * @state: the state data 876 * @drv: cpuidle driver containing state data
877 * @index: the index of suggested state
861 * 878 *
862 * If BM is detected, the deepest non-C3 idle state is entered instead. 879 * If BM is detected, the deepest non-C3 idle state is entered instead.
863 */ 880 */
864static int acpi_idle_enter_bm(struct cpuidle_device *dev, 881static int acpi_idle_enter_bm(struct cpuidle_device *dev,
865 struct cpuidle_state *state) 882 struct cpuidle_driver *drv, int index)
866{ 883{
867 struct acpi_processor *pr; 884 struct acpi_processor *pr;
868 struct acpi_processor_cx *cx = cpuidle_get_statedata(state); 885 struct cpuidle_state_usage *state_usage = &dev->states_usage[index];
886 struct acpi_processor_cx *cx = cpuidle_get_statedata(state_usage);
869 ktime_t kt1, kt2; 887 ktime_t kt1, kt2;
870 s64 idle_time_ns; 888 s64 idle_time_ns;
871 s64 idle_time; 889 s64 idle_time;
872 890
873 891
874 pr = __this_cpu_read(processors); 892 pr = __this_cpu_read(processors);
893 dev->last_residency = 0;
875 894
876 if (unlikely(!pr)) 895 if (unlikely(!pr))
877 return 0; 896 return -EINVAL;
897
878 898
879 if (acpi_idle_suspend) 899 if (acpi_idle_suspend) {
880 return(acpi_idle_enter_c1(dev, state)); 900 cpu_relax();
901 return -EINVAL;
902 }
881 903
882 if (!cx->bm_sts_skip && acpi_idle_bm_check()) { 904 if (!cx->bm_sts_skip && acpi_idle_bm_check()) {
883 if (dev->safe_state) { 905 if (drv->safe_state_index >= 0) {
884 dev->last_state = dev->safe_state; 906 return drv->states[drv->safe_state_index].enter(dev,
885 return dev->safe_state->enter(dev, dev->safe_state); 907 drv, drv->safe_state_index);
886 } else { 908 } else {
887 local_irq_disable(); 909 local_irq_disable();
888 acpi_safe_halt(); 910 acpi_safe_halt();
889 local_irq_enable(); 911 local_irq_enable();
890 return 0; 912 return -EINVAL;
891 } 913 }
892 } 914 }
893 915
@@ -904,7 +926,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
904 if (unlikely(need_resched())) { 926 if (unlikely(need_resched())) {
905 current_thread_info()->status |= TS_POLLING; 927 current_thread_info()->status |= TS_POLLING;
906 local_irq_enable(); 928 local_irq_enable();
907 return 0; 929 return -EINVAL;
908 } 930 }
909 } 931 }
910 932
@@ -954,6 +976,9 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
954 idle_time = idle_time_ns; 976 idle_time = idle_time_ns;
955 do_div(idle_time, NSEC_PER_USEC); 977 do_div(idle_time, NSEC_PER_USEC);
956 978
979 /* Update device last_residency*/
980 dev->last_residency = (int)idle_time;
981
957 /* Tell the scheduler how much we idled: */ 982 /* Tell the scheduler how much we idled: */
958 sched_clock_idle_wakeup_event(idle_time_ns); 983 sched_clock_idle_wakeup_event(idle_time_ns);
959 984
@@ -965,7 +990,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
965 990
966 lapic_timer_state_broadcast(pr, cx, 0); 991 lapic_timer_state_broadcast(pr, cx, 0);
967 cx->time += idle_time; 992 cx->time += idle_time;
968 return idle_time; 993 return index;
969} 994}
970 995
971struct cpuidle_driver acpi_idle_driver = { 996struct cpuidle_driver acpi_idle_driver = {
@@ -974,14 +999,16 @@ struct cpuidle_driver acpi_idle_driver = {
974}; 999};
975 1000
976/** 1001/**
977 * acpi_processor_setup_cpuidle - prepares and configures CPUIDLE 1002 * acpi_processor_setup_cpuidle_cx - prepares and configures CPUIDLE
1003 * device i.e. per-cpu data
1004 *
978 * @pr: the ACPI processor 1005 * @pr: the ACPI processor
979 */ 1006 */
980static int acpi_processor_setup_cpuidle(struct acpi_processor *pr) 1007static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr)
981{ 1008{
982 int i, count = CPUIDLE_DRIVER_STATE_START; 1009 int i, count = CPUIDLE_DRIVER_STATE_START;
983 struct acpi_processor_cx *cx; 1010 struct acpi_processor_cx *cx;
984 struct cpuidle_state *state; 1011 struct cpuidle_state_usage *state_usage;
985 struct cpuidle_device *dev = &pr->power.dev; 1012 struct cpuidle_device *dev = &pr->power.dev;
986 1013
987 if (!pr->flags.power_setup_done) 1014 if (!pr->flags.power_setup_done)
@@ -992,9 +1019,62 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
992 } 1019 }
993 1020
994 dev->cpu = pr->id; 1021 dev->cpu = pr->id;
1022
1023 if (max_cstate == 0)
1024 max_cstate = 1;
1025
1026 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1027 cx = &pr->power.states[i];
1028 state_usage = &dev->states_usage[count];
1029
1030 if (!cx->valid)
1031 continue;
1032
1033#ifdef CONFIG_HOTPLUG_CPU
1034 if ((cx->type != ACPI_STATE_C1) && (num_online_cpus() > 1) &&
1035 !pr->flags.has_cst &&
1036 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1037 continue;
1038#endif
1039
1040 cpuidle_set_statedata(state_usage, cx);
1041
1042 count++;
1043 if (count == CPUIDLE_STATE_MAX)
1044 break;
1045 }
1046
1047 dev->state_count = count;
1048
1049 if (!count)
1050 return -EINVAL;
1051
1052 return 0;
1053}
1054
1055/**
1056 * acpi_processor_setup_cpuidle states- prepares and configures cpuidle
1057 * global state data i.e. idle routines
1058 *
1059 * @pr: the ACPI processor
1060 */
1061static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
1062{
1063 int i, count = CPUIDLE_DRIVER_STATE_START;
1064 struct acpi_processor_cx *cx;
1065 struct cpuidle_state *state;
1066 struct cpuidle_driver *drv = &acpi_idle_driver;
1067
1068 if (!pr->flags.power_setup_done)
1069 return -EINVAL;
1070
1071 if (pr->flags.power == 0)
1072 return -EINVAL;
1073
1074 drv->safe_state_index = -1;
995 for (i = 0; i < CPUIDLE_STATE_MAX; i++) { 1075 for (i = 0; i < CPUIDLE_STATE_MAX; i++) {
996 dev->states[i].name[0] = '\0'; 1076 drv->states[i].name[0] = '\0';
997 dev->states[i].desc[0] = '\0'; 1077 drv->states[i].desc[0] = '\0';
998 } 1078 }
999 1079
1000 if (max_cstate == 0) 1080 if (max_cstate == 0)
@@ -1002,7 +1082,6 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1002 1082
1003 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) { 1083 for (i = 1; i < ACPI_PROCESSOR_MAX_POWER && i <= max_cstate; i++) {
1004 cx = &pr->power.states[i]; 1084 cx = &pr->power.states[i];
1005 state = &dev->states[count];
1006 1085
1007 if (!cx->valid) 1086 if (!cx->valid)
1008 continue; 1087 continue;
@@ -1013,8 +1092,8 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1013 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED)) 1092 !(acpi_gbl_FADT.flags & ACPI_FADT_C2_MP_SUPPORTED))
1014 continue; 1093 continue;
1015#endif 1094#endif
1016 cpuidle_set_statedata(state, cx);
1017 1095
1096 state = &drv->states[count];
1018 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i); 1097 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d", i);
1019 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN); 1098 strncpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1020 state->exit_latency = cx->latency; 1099 state->exit_latency = cx->latency;
@@ -1027,13 +1106,13 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1027 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1106 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1028 1107
1029 state->enter = acpi_idle_enter_c1; 1108 state->enter = acpi_idle_enter_c1;
1030 dev->safe_state = state; 1109 drv->safe_state_index = count;
1031 break; 1110 break;
1032 1111
1033 case ACPI_STATE_C2: 1112 case ACPI_STATE_C2:
1034 state->flags |= CPUIDLE_FLAG_TIME_VALID; 1113 state->flags |= CPUIDLE_FLAG_TIME_VALID;
1035 state->enter = acpi_idle_enter_simple; 1114 state->enter = acpi_idle_enter_simple;
1036 dev->safe_state = state; 1115 drv->safe_state_index = count;
1037 break; 1116 break;
1038 1117
1039 case ACPI_STATE_C3: 1118 case ACPI_STATE_C3:
@@ -1049,7 +1128,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1049 break; 1128 break;
1050 } 1129 }
1051 1130
1052 dev->state_count = count; 1131 drv->state_count = count;
1053 1132
1054 if (!count) 1133 if (!count)
1055 return -EINVAL; 1134 return -EINVAL;
@@ -1057,7 +1136,7 @@ static int acpi_processor_setup_cpuidle(struct acpi_processor *pr)
1057 return 0; 1136 return 0;
1058} 1137}
1059 1138
1060int acpi_processor_cst_has_changed(struct acpi_processor *pr) 1139int acpi_processor_hotplug(struct acpi_processor *pr)
1061{ 1140{
1062 int ret = 0; 1141 int ret = 0;
1063 1142
@@ -1078,7 +1157,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1078 cpuidle_disable_device(&pr->power.dev); 1157 cpuidle_disable_device(&pr->power.dev);
1079 acpi_processor_get_power_info(pr); 1158 acpi_processor_get_power_info(pr);
1080 if (pr->flags.power) { 1159 if (pr->flags.power) {
1081 acpi_processor_setup_cpuidle(pr); 1160 acpi_processor_setup_cpuidle_cx(pr);
1082 ret = cpuidle_enable_device(&pr->power.dev); 1161 ret = cpuidle_enable_device(&pr->power.dev);
1083 } 1162 }
1084 cpuidle_resume_and_unlock(); 1163 cpuidle_resume_and_unlock();
@@ -1086,10 +1165,72 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1086 return ret; 1165 return ret;
1087} 1166}
1088 1167
1168int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1169{
1170 int cpu;
1171 struct acpi_processor *_pr;
1172
1173 if (disabled_by_idle_boot_param())
1174 return 0;
1175
1176 if (!pr)
1177 return -EINVAL;
1178
1179 if (nocst)
1180 return -ENODEV;
1181
1182 if (!pr->flags.power_setup_done)
1183 return -ENODEV;
1184
1185 /*
1186 * FIXME: Design the ACPI notification to make it once per
1187 * system instead of once per-cpu. This condition is a hack
1188 * to make the code that updates C-States be called once.
1189 */
1190
1191 if (smp_processor_id() == 0 &&
1192 cpuidle_get_driver() == &acpi_idle_driver) {
1193
1194 cpuidle_pause_and_lock();
1195 /* Protect against cpu-hotplug */
1196 get_online_cpus();
1197
1198 /* Disable all cpuidle devices */
1199 for_each_online_cpu(cpu) {
1200 _pr = per_cpu(processors, cpu);
1201 if (!_pr || !_pr->flags.power_setup_done)
1202 continue;
1203 cpuidle_disable_device(&_pr->power.dev);
1204 }
1205
1206 /* Populate Updated C-state information */
1207 acpi_processor_setup_cpuidle_states(pr);
1208
1209 /* Enable all cpuidle devices */
1210 for_each_online_cpu(cpu) {
1211 _pr = per_cpu(processors, cpu);
1212 if (!_pr || !_pr->flags.power_setup_done)
1213 continue;
1214 acpi_processor_get_power_info(_pr);
1215 if (_pr->flags.power) {
1216 acpi_processor_setup_cpuidle_cx(_pr);
1217 cpuidle_enable_device(&_pr->power.dev);
1218 }
1219 }
1220 put_online_cpus();
1221 cpuidle_resume_and_unlock();
1222 }
1223
1224 return 0;
1225}
1226
1227static int acpi_processor_registered;
1228
1089int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, 1229int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1090 struct acpi_device *device) 1230 struct acpi_device *device)
1091{ 1231{
1092 acpi_status status = 0; 1232 acpi_status status = 0;
1233 int retval;
1093 static int first_run; 1234 static int first_run;
1094 1235
1095 if (disabled_by_idle_boot_param()) 1236 if (disabled_by_idle_boot_param())
@@ -1126,9 +1267,26 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1126 * platforms that only support C1. 1267 * platforms that only support C1.
1127 */ 1268 */
1128 if (pr->flags.power) { 1269 if (pr->flags.power) {
1129 acpi_processor_setup_cpuidle(pr); 1270 /* Register acpi_idle_driver if not already registered */
1130 if (cpuidle_register_device(&pr->power.dev)) 1271 if (!acpi_processor_registered) {
1131 return -EIO; 1272 acpi_processor_setup_cpuidle_states(pr);
1273 retval = cpuidle_register_driver(&acpi_idle_driver);
1274 if (retval)
1275 return retval;
1276 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
1277 acpi_idle_driver.name);
1278 }
1279 /* Register per-cpu cpuidle_device. Cpuidle driver
1280 * must already be registered before registering device
1281 */
1282 acpi_processor_setup_cpuidle_cx(pr);
1283 retval = cpuidle_register_device(&pr->power.dev);
1284 if (retval) {
1285 if (acpi_processor_registered == 0)
1286 cpuidle_unregister_driver(&acpi_idle_driver);
1287 return retval;
1288 }
1289 acpi_processor_registered++;
1132 } 1290 }
1133 return 0; 1291 return 0;
1134} 1292}
@@ -1139,8 +1297,13 @@ int acpi_processor_power_exit(struct acpi_processor *pr,
1139 if (disabled_by_idle_boot_param()) 1297 if (disabled_by_idle_boot_param())
1140 return 0; 1298 return 0;
1141 1299
1142 cpuidle_unregister_device(&pr->power.dev); 1300 if (pr->flags.power) {
1143 pr->flags.power_setup_done = 0; 1301 cpuidle_unregister_device(&pr->power.dev);
1302 acpi_processor_registered--;
1303 if (acpi_processor_registered == 0)
1304 cpuidle_unregister_driver(&acpi_idle_driver);
1305 }
1144 1306
1307 pr->flags.power_setup_done = 0;
1145 return 0; 1308 return 0;
1146} 1309}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 449c556274c0..8ab80bafe3f1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1062,13 +1062,12 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id)
1062 if (!id) 1062 if (!id)
1063 return; 1063 return;
1064 1064
1065 id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL); 1065 id->id = kstrdup(dev_id, GFP_KERNEL);
1066 if (!id->id) { 1066 if (!id->id) {
1067 kfree(id); 1067 kfree(id);
1068 return; 1068 return;
1069 } 1069 }
1070 1070
1071 strcpy(id->id, dev_id);
1072 list_add_tail(&id->list, &device->pnp.ids); 1071 list_add_tail(&id->list, &device->pnp.ids);
1073} 1072}
1074 1073
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index c538d0ef10ff..9f66181c814e 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -706,11 +706,23 @@ static void __exit interrupt_stats_exit(void)
706 return; 706 return;
707} 707}
708 708
709static ssize_t
710acpi_show_profile(struct device *dev, struct device_attribute *attr,
711 char *buf)
712{
713 return sprintf(buf, "%d\n", acpi_gbl_FADT.preferred_profile);
714}
715
716static const struct device_attribute pm_profile_attr =
717 __ATTR(pm_profile, S_IRUGO, acpi_show_profile, NULL);
718
709int __init acpi_sysfs_init(void) 719int __init acpi_sysfs_init(void)
710{ 720{
711 int result; 721 int result;
712 722
713 result = acpi_tables_sysfs_init(); 723 result = acpi_tables_sysfs_init();
714 724 if (result)
725 return result;
726 result = sysfs_create_file(acpi_kobj, &pm_profile_attr.attr);
715 return result; 727 return result;
716} 728}