diff options
author | Dave Jones <davej@redhat.com> | 2006-06-04 19:37:58 -0400 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2006-06-04 19:37:58 -0400 |
commit | 1f729e0660f974cec1f0f7f4fba03ea4c2c4b9a9 (patch) | |
tree | 9254031f1f252e5b38c962b3e2ed93a0351ce319 /arch/i386 | |
parent | 911cb74bb9e77e40749abc2fca6fe74d87d940f3 (diff) |
[CPUFREQ] Prepare powernow-k8 for future CPUs.
Forthcoming AMD products will use a different algorithm for transitioning
pstates than the current generation Opteron products do. The attached
patch allows the powernow-k8 driver to work with those products.
Signed-off-by: Mark Langsdorf <mark.langsdorf@amd.com>
Signed-off-by: Dave Jones <davej@redhat.com>
Diffstat (limited to 'arch/i386')
-rw-r--r-- | arch/i386/kernel/cpu/cpufreq/powernow-k8.c | 336 | ||||
-rw-r--r-- | arch/i386/kernel/cpu/cpufreq/powernow-k8.h | 40 |
2 files changed, 290 insertions, 86 deletions
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c index 517de6cb0d0a..b4277f58f40c 100644 --- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c +++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * (c) 2003, 2004, 2005 Advanced Micro Devices, Inc. | 2 | * (c) 2003-2006 Advanced Micro Devices, Inc. |
3 | * Your use of this code is subject to the terms and conditions of the | 3 | * Your use of this code is subject to the terms and conditions of the |
4 | * GNU general public license version 2. See "COPYING" or | 4 | * GNU general public license version 2. See "COPYING" or |
5 | * http://www.gnu.org/licenses/gpl.html | 5 | * http://www.gnu.org/licenses/gpl.html |
@@ -14,7 +14,7 @@ | |||
14 | * Based upon datasheets & sample CPUs kindly provided by AMD. | 14 | * Based upon datasheets & sample CPUs kindly provided by AMD. |
15 | * | 15 | * |
16 | * Valuable input gratefully received from Dave Jones, Pavel Machek, | 16 | * Valuable input gratefully received from Dave Jones, Pavel Machek, |
17 | * Dominik Brodowski, and others. | 17 | * Dominik Brodowski, Jacob Shin, and others. |
18 | * Originally developed by Paul Devriendt. | 18 | * Originally developed by Paul Devriendt. |
19 | * Processor information obtained from Chapter 9 (Power and Thermal Management) | 19 | * Processor information obtained from Chapter 9 (Power and Thermal Management) |
20 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD | 20 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD |
@@ -46,7 +46,7 @@ | |||
46 | 46 | ||
47 | #define PFX "powernow-k8: " | 47 | #define PFX "powernow-k8: " |
48 | #define BFX PFX "BIOS error: " | 48 | #define BFX PFX "BIOS error: " |
49 | #define VERSION "version 1.60.2" | 49 | #define VERSION "version 2.00.00" |
50 | #include "powernow-k8.h" | 50 | #include "powernow-k8.h" |
51 | 51 | ||
52 | /* serialize freq changes */ | 52 | /* serialize freq changes */ |
@@ -54,6 +54,8 @@ static DEFINE_MUTEX(fidvid_mutex); | |||
54 | 54 | ||
55 | static struct powernow_k8_data *powernow_data[NR_CPUS]; | 55 | static struct powernow_k8_data *powernow_data[NR_CPUS]; |
56 | 56 | ||
57 | static int cpu_family = CPU_OPTERON; | ||
58 | |||
57 | #ifndef CONFIG_SMP | 59 | #ifndef CONFIG_SMP |
58 | static cpumask_t cpu_core_map[1]; | 60 | static cpumask_t cpu_core_map[1]; |
59 | #endif | 61 | #endif |
@@ -64,16 +66,36 @@ static u32 find_freq_from_fid(u32 fid) | |||
64 | return 800 + (fid * 100); | 66 | return 800 + (fid * 100); |
65 | } | 67 | } |
66 | 68 | ||
69 | |||
67 | /* Return a frequency in KHz, given an input fid */ | 70 | /* Return a frequency in KHz, given an input fid */ |
68 | static u32 find_khz_freq_from_fid(u32 fid) | 71 | static u32 find_khz_freq_from_fid(u32 fid) |
69 | { | 72 | { |
70 | return 1000 * find_freq_from_fid(fid); | 73 | return 1000 * find_freq_from_fid(fid); |
71 | } | 74 | } |
72 | 75 | ||
73 | /* Return a voltage in miliVolts, given an input vid */ | 76 | /* Return a frequency in MHz, given an input fid and did */ |
74 | static u32 find_millivolts_from_vid(struct powernow_k8_data *data, u32 vid) | 77 | static u32 find_freq_from_fiddid(u32 fid, u32 did) |
78 | { | ||
79 | return 100 * (fid + 0x10) >> did; | ||
80 | } | ||
81 | |||
82 | static u32 find_khz_freq_from_fiddid(u32 fid, u32 did) | ||
75 | { | 83 | { |
76 | return 1550-vid*25; | 84 | return 1000 * find_freq_from_fiddid(fid, did); |
85 | } | ||
86 | |||
87 | static u32 find_fid_from_pstate(u32 pstate) | ||
88 | { | ||
89 | u32 hi, lo; | ||
90 | rdmsr(MSR_PSTATE_DEF_BASE + pstate, lo, hi); | ||
91 | return lo & HW_PSTATE_FID_MASK; | ||
92 | } | ||
93 | |||
94 | static u32 find_did_from_pstate(u32 pstate) | ||
95 | { | ||
96 | u32 hi, lo; | ||
97 | rdmsr(MSR_PSTATE_DEF_BASE + pstate, lo, hi); | ||
98 | return (lo & HW_PSTATE_DID_MASK) >> HW_PSTATE_DID_SHIFT; | ||
77 | } | 99 | } |
78 | 100 | ||
79 | /* Return the vco fid for an input fid | 101 | /* Return the vco fid for an input fid |
@@ -98,6 +120,9 @@ static int pending_bit_stuck(void) | |||
98 | { | 120 | { |
99 | u32 lo, hi; | 121 | u32 lo, hi; |
100 | 122 | ||
123 | if (cpu_family) | ||
124 | return 0; | ||
125 | |||
101 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | 126 | rdmsr(MSR_FIDVID_STATUS, lo, hi); |
102 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; | 127 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; |
103 | } | 128 | } |
@@ -111,6 +136,14 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data) | |||
111 | u32 lo, hi; | 136 | u32 lo, hi; |
112 | u32 i = 0; | 137 | u32 i = 0; |
113 | 138 | ||
139 | if (cpu_family) { | ||
140 | rdmsr(MSR_PSTATE_STATUS, lo, hi); | ||
141 | i = lo & HW_PSTATE_MASK; | ||
142 | rdmsr(MSR_PSTATE_DEF_BASE + i, lo, hi); | ||
143 | data->currfid = lo & HW_PSTATE_FID_MASK; | ||
144 | data->currdid = (lo & HW_PSTATE_DID_MASK) >> HW_PSTATE_DID_SHIFT; | ||
145 | return 0; | ||
146 | } | ||
114 | do { | 147 | do { |
115 | if (i++ > 10000) { | 148 | if (i++ > 10000) { |
116 | dprintk("detected change pending stuck\n"); | 149 | dprintk("detected change pending stuck\n"); |
@@ -175,7 +208,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid) | |||
175 | do { | 208 | do { |
176 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); | 209 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); |
177 | if (i++ > 100) { | 210 | if (i++ > 100) { |
178 | printk(KERN_ERR PFX "internal error - pending bit very stuck - no further pstate changes possible\n"); | 211 | printk(KERN_ERR PFX "Hardware error - pending bit very stuck - no further pstate changes possible\n"); |
179 | return 1; | 212 | return 1; |
180 | } | 213 | } |
181 | } while (query_current_values_with_pending_wait(data)); | 214 | } while (query_current_values_with_pending_wait(data)); |
@@ -255,7 +288,15 @@ static int decrease_vid_code_by_step(struct powernow_k8_data *data, u32 reqvid, | |||
255 | return 0; | 288 | return 0; |
256 | } | 289 | } |
257 | 290 | ||
258 | /* Change the fid and vid, by the 3 phases. */ | 291 | /* Change hardware pstate by single MSR write */ |
292 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) | ||
293 | { | ||
294 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); | ||
295 | data->currfid = find_fid_from_pstate(pstate); | ||
296 | return 0; | ||
297 | } | ||
298 | |||
299 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ | ||
259 | static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 reqvid) | 300 | static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 reqvid) |
260 | { | 301 | { |
261 | if (core_voltage_pre_transition(data, reqvid)) | 302 | if (core_voltage_pre_transition(data, reqvid)) |
@@ -474,26 +515,35 @@ static int check_supported_cpu(unsigned int cpu) | |||
474 | goto out; | 515 | goto out; |
475 | 516 | ||
476 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | 517 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); |
477 | if ((eax & CPUID_XFAM) != CPUID_XFAM_K8) | 518 | if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) && |
519 | ((eax & CPUID_XFAM) < CPUID_XFAM_10H)) | ||
478 | goto out; | 520 | goto out; |
479 | 521 | ||
480 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || | 522 | if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { |
481 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_G)) { | 523 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || |
482 | printk(KERN_INFO PFX "Processor cpuid %x not supported\n", eax); | 524 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_G)) { |
483 | goto out; | 525 | printk(KERN_INFO PFX "Processor cpuid %x not supported\n", eax); |
484 | } | 526 | goto out; |
527 | } | ||
485 | 528 | ||
486 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); | 529 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); |
487 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { | 530 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { |
488 | printk(KERN_INFO PFX | 531 | printk(KERN_INFO PFX |
489 | "No frequency change capabilities detected\n"); | 532 | "No frequency change capabilities detected\n"); |
490 | goto out; | 533 | goto out; |
491 | } | 534 | } |
492 | 535 | ||
493 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | 536 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); |
494 | if ((edx & P_STATE_TRANSITION_CAPABLE) != P_STATE_TRANSITION_CAPABLE) { | 537 | if ((edx & P_STATE_TRANSITION_CAPABLE) != P_STATE_TRANSITION_CAPABLE) { |
495 | printk(KERN_INFO PFX "Power state transitions not supported\n"); | 538 | printk(KERN_INFO PFX "Power state transitions not supported\n"); |
496 | goto out; | 539 | goto out; |
540 | } | ||
541 | } else { /* must be a HW Pstate capable processor */ | ||
542 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
543 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) | ||
544 | cpu_family = CPU_HW_PSTATE; | ||
545 | else | ||
546 | goto out; | ||
497 | } | 547 | } |
498 | 548 | ||
499 | rc = 1; | 549 | rc = 1; |
@@ -547,12 +597,18 @@ static void print_basics(struct powernow_k8_data *data) | |||
547 | { | 597 | { |
548 | int j; | 598 | int j; |
549 | for (j = 0; j < data->numps; j++) { | 599 | for (j = 0; j < data->numps; j++) { |
550 | if (data->powernow_table[j].frequency != CPUFREQ_ENTRY_INVALID) | 600 | if (data->powernow_table[j].frequency != CPUFREQ_ENTRY_INVALID) { |
551 | printk(KERN_INFO PFX " %d : fid 0x%x (%d MHz), vid 0x%x (%d mV)\n", j, | 601 | if (cpu_family) { |
602 | printk(KERN_INFO PFX " %d : fid 0x%x gid 0x%x (%d MHz)\n", j, (data->powernow_table[j].index & 0xff00) >> 8, | ||
603 | (data->powernow_table[j].index & 0xff0000) >> 16, | ||
604 | data->powernow_table[j].frequency/1000); | ||
605 | } else { | ||
606 | printk(KERN_INFO PFX " %d : fid 0x%x (%d MHz), vid 0x%x\n", j, | ||
552 | data->powernow_table[j].index & 0xff, | 607 | data->powernow_table[j].index & 0xff, |
553 | data->powernow_table[j].frequency/1000, | 608 | data->powernow_table[j].frequency/1000, |
554 | data->powernow_table[j].index >> 8, | 609 | data->powernow_table[j].index >> 8); |
555 | find_millivolts_from_vid(data, data->powernow_table[j].index >> 8)); | 610 | } |
611 | } | ||
556 | } | 612 | } |
557 | if (data->batps) | 613 | if (data->batps) |
558 | printk(KERN_INFO PFX "Only %d pstates on battery\n", data->batps); | 614 | printk(KERN_INFO PFX "Only %d pstates on battery\n", data->batps); |
@@ -702,7 +758,7 @@ static int find_psb_table(struct powernow_k8_data *data) | |||
702 | #ifdef CONFIG_X86_POWERNOW_K8_ACPI | 758 | #ifdef CONFIG_X86_POWERNOW_K8_ACPI |
703 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index) | 759 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index) |
704 | { | 760 | { |
705 | if (!data->acpi_data.state_count) | 761 | if (!data->acpi_data.state_count || cpu_family) |
706 | return; | 762 | return; |
707 | 763 | ||
708 | data->irt = (data->acpi_data.states[index].control >> IRT_SHIFT) & IRT_MASK; | 764 | data->irt = (data->acpi_data.states[index].control >> IRT_SHIFT) & IRT_MASK; |
@@ -715,9 +771,8 @@ static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned | |||
715 | 771 | ||
716 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | 772 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) |
717 | { | 773 | { |
718 | int i; | ||
719 | int cntlofreq = 0; | ||
720 | struct cpufreq_frequency_table *powernow_table; | 774 | struct cpufreq_frequency_table *powernow_table; |
775 | int ret_val; | ||
721 | 776 | ||
722 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { | 777 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { |
723 | dprintk("register performance failed: bad ACPI data\n"); | 778 | dprintk("register performance failed: bad ACPI data\n"); |
@@ -746,6 +801,85 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | |||
746 | goto err_out; | 801 | goto err_out; |
747 | } | 802 | } |
748 | 803 | ||
804 | if (cpu_family) | ||
805 | ret_val = fill_powernow_table_pstate(data, powernow_table); | ||
806 | else | ||
807 | ret_val = fill_powernow_table_fidvid(data, powernow_table); | ||
808 | if (ret_val) | ||
809 | goto err_out_mem; | ||
810 | |||
811 | powernow_table[data->acpi_data.state_count].frequency = CPUFREQ_TABLE_END; | ||
812 | powernow_table[data->acpi_data.state_count].index = 0; | ||
813 | data->powernow_table = powernow_table; | ||
814 | |||
815 | /* fill in data */ | ||
816 | data->numps = data->acpi_data.state_count; | ||
817 | print_basics(data); | ||
818 | powernow_k8_acpi_pst_values(data, 0); | ||
819 | |||
820 | /* notify BIOS that we exist */ | ||
821 | acpi_processor_notify_smm(THIS_MODULE); | ||
822 | |||
823 | return 0; | ||
824 | |||
825 | err_out_mem: | ||
826 | kfree(powernow_table); | ||
827 | |||
828 | err_out: | ||
829 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | ||
830 | |||
831 | /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */ | ||
832 | data->acpi_data.state_count = 0; | ||
833 | |||
834 | return -ENODEV; | ||
835 | } | ||
836 | |||
837 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) | ||
838 | { | ||
839 | int i; | ||
840 | |||
841 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
842 | u32 index; | ||
843 | u32 hi = 0, lo = 0; | ||
844 | u32 fid; | ||
845 | u32 did; | ||
846 | |||
847 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; | ||
848 | if (index > MAX_HW_PSTATE) { | ||
849 | printk(KERN_ERR PFX "invalid pstate %d - bad value %d.\n", i, index); | ||
850 | printk(KERN_ERR PFX "Please report to BIOS manufacturer\n"); | ||
851 | } | ||
852 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); | ||
853 | if (!(hi & HW_PSTATE_VALID_MASK)) { | ||
854 | dprintk("invalid pstate %d, ignoring\n", index); | ||
855 | powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
856 | continue; | ||
857 | } | ||
858 | |||
859 | fid = lo & HW_PSTATE_FID_MASK; | ||
860 | did = (lo & HW_PSTATE_DID_MASK) >> HW_PSTATE_DID_SHIFT; | ||
861 | |||
862 | dprintk(" %d : fid 0x%x, did 0x%x\n", index, fid, did); | ||
863 | |||
864 | powernow_table[i].index = index | (fid << HW_FID_INDEX_SHIFT) | (did << HW_DID_INDEX_SHIFT); | ||
865 | |||
866 | powernow_table[i].frequency = find_khz_freq_from_fiddid(fid, did); | ||
867 | |||
868 | if (powernow_table[i].frequency != (data->acpi_data.states[i].core_frequency * 1000)) { | ||
869 | printk(KERN_INFO PFX "invalid freq entries %u kHz vs. %u kHz\n", | ||
870 | powernow_table[i].frequency, | ||
871 | (unsigned int) (data->acpi_data.states[i].core_frequency * 1000)); | ||
872 | powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
873 | continue; | ||
874 | } | ||
875 | } | ||
876 | return 0; | ||
877 | } | ||
878 | |||
879 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) | ||
880 | { | ||
881 | int i; | ||
882 | int cntlofreq = 0; | ||
749 | for (i = 0; i < data->acpi_data.state_count; i++) { | 883 | for (i = 0; i < data->acpi_data.state_count; i++) { |
750 | u32 fid; | 884 | u32 fid; |
751 | u32 vid; | 885 | u32 vid; |
@@ -786,7 +920,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | |||
786 | if ((powernow_table[i].frequency != powernow_table[cntlofreq].frequency) || | 920 | if ((powernow_table[i].frequency != powernow_table[cntlofreq].frequency) || |
787 | (powernow_table[i].index != powernow_table[cntlofreq].index)) { | 921 | (powernow_table[i].index != powernow_table[cntlofreq].index)) { |
788 | printk(KERN_ERR PFX "Too many lo freq table entries\n"); | 922 | printk(KERN_ERR PFX "Too many lo freq table entries\n"); |
789 | goto err_out_mem; | 923 | return 1; |
790 | } | 924 | } |
791 | 925 | ||
792 | dprintk("double low frequency table entry, ignoring it.\n"); | 926 | dprintk("double low frequency table entry, ignoring it.\n"); |
@@ -804,31 +938,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | |||
804 | continue; | 938 | continue; |
805 | } | 939 | } |
806 | } | 940 | } |
807 | |||
808 | powernow_table[data->acpi_data.state_count].frequency = CPUFREQ_TABLE_END; | ||
809 | powernow_table[data->acpi_data.state_count].index = 0; | ||
810 | data->powernow_table = powernow_table; | ||
811 | |||
812 | /* fill in data */ | ||
813 | data->numps = data->acpi_data.state_count; | ||
814 | print_basics(data); | ||
815 | powernow_k8_acpi_pst_values(data, 0); | ||
816 | |||
817 | /* notify BIOS that we exist */ | ||
818 | acpi_processor_notify_smm(THIS_MODULE); | ||
819 | |||
820 | return 0; | 941 | return 0; |
821 | |||
822 | err_out_mem: | ||
823 | kfree(powernow_table); | ||
824 | |||
825 | err_out: | ||
826 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | ||
827 | |||
828 | /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */ | ||
829 | data->acpi_data.state_count = 0; | ||
830 | |||
831 | return -ENODEV; | ||
832 | } | 942 | } |
833 | 943 | ||
834 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) | 944 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) |
@@ -844,20 +954,20 @@ static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned | |||
844 | #endif /* CONFIG_X86_POWERNOW_K8_ACPI */ | 954 | #endif /* CONFIG_X86_POWERNOW_K8_ACPI */ |
845 | 955 | ||
846 | /* Take a frequency, and issue the fid/vid transition command */ | 956 | /* Take a frequency, and issue the fid/vid transition command */ |
847 | static int transition_frequency(struct powernow_k8_data *data, unsigned int index) | 957 | static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned int index) |
848 | { | 958 | { |
849 | u32 fid; | 959 | u32 fid = 0; |
850 | u32 vid; | 960 | u32 vid = 0; |
851 | int res, i; | 961 | int res, i; |
852 | struct cpufreq_freqs freqs; | 962 | struct cpufreq_freqs freqs; |
853 | 963 | ||
854 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | 964 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); |
855 | 965 | ||
966 | /* fid/vid correctness check for k8 */ | ||
856 | /* fid are the lower 8 bits of the index we stored into | 967 | /* fid are the lower 8 bits of the index we stored into |
857 | * the cpufreq frequency table in find_psb_table, vid are | 968 | * the cpufreq frequency table in find_psb_table, vid |
858 | * the upper 8 bits. | 969 | * are the upper 8 bits. |
859 | */ | 970 | */ |
860 | |||
861 | fid = data->powernow_table[index].index & 0xFF; | 971 | fid = data->powernow_table[index].index & 0xFF; |
862 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; | 972 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; |
863 | 973 | ||
@@ -881,19 +991,55 @@ static int transition_frequency(struct powernow_k8_data *data, unsigned int inde | |||
881 | 991 | ||
882 | dprintk("cpu %d, changing to fid 0x%x, vid 0x%x\n", | 992 | dprintk("cpu %d, changing to fid 0x%x, vid 0x%x\n", |
883 | smp_processor_id(), fid, vid); | 993 | smp_processor_id(), fid, vid); |
884 | |||
885 | freqs.cpu = data->cpu; | ||
886 | freqs.old = find_khz_freq_from_fid(data->currfid); | 994 | freqs.old = find_khz_freq_from_fid(data->currfid); |
887 | freqs.new = find_khz_freq_from_fid(fid); | 995 | freqs.new = find_khz_freq_from_fid(fid); |
888 | for_each_cpu_mask(i, cpu_core_map[data->cpu]) { | 996 | |
997 | for_each_cpu_mask(i, *(data->available_cores)) { | ||
889 | freqs.cpu = i; | 998 | freqs.cpu = i; |
890 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 999 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
891 | } | 1000 | } |
892 | 1001 | ||
893 | res = transition_fid_vid(data, fid, vid); | 1002 | res = transition_fid_vid(data, fid, vid); |
894 | |||
895 | freqs.new = find_khz_freq_from_fid(data->currfid); | 1003 | freqs.new = find_khz_freq_from_fid(data->currfid); |
896 | for_each_cpu_mask(i, cpu_core_map[data->cpu]) { | 1004 | |
1005 | for_each_cpu_mask(i, *(data->available_cores)) { | ||
1006 | freqs.cpu = i; | ||
1007 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1008 | } | ||
1009 | return res; | ||
1010 | } | ||
1011 | |||
1012 | /* Take a frequency, and issue the hardware pstate transition command */ | ||
1013 | static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned int index) | ||
1014 | { | ||
1015 | u32 fid = 0; | ||
1016 | u32 did = 0; | ||
1017 | u32 pstate = 0; | ||
1018 | int res, i; | ||
1019 | struct cpufreq_freqs freqs; | ||
1020 | |||
1021 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1022 | |||
1023 | /* get fid did for hardware pstate transition */ | ||
1024 | pstate = index & HW_PSTATE_MASK; | ||
1025 | if (pstate > MAX_HW_PSTATE) | ||
1026 | return 0; | ||
1027 | fid = (index & HW_FID_INDEX_MASK) >> HW_FID_INDEX_SHIFT; | ||
1028 | did = (index & HW_DID_INDEX_MASK) >> HW_DID_INDEX_SHIFT; | ||
1029 | freqs.old = find_khz_freq_from_fiddid(data->currfid, data->currdid); | ||
1030 | freqs.new = find_khz_freq_from_fiddid(fid, did); | ||
1031 | |||
1032 | for_each_cpu_mask(i, *(data->available_cores)) { | ||
1033 | freqs.cpu = i; | ||
1034 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1035 | } | ||
1036 | |||
1037 | res = transition_pstate(data, pstate); | ||
1038 | data->currfid = find_fid_from_pstate(pstate); | ||
1039 | data->currdid = find_did_from_pstate(pstate); | ||
1040 | freqs.new = find_khz_freq_from_fiddid(data->currfid, data->currdid); | ||
1041 | |||
1042 | for_each_cpu_mask(i, *(data->available_cores)) { | ||
897 | freqs.cpu = i; | 1043 | freqs.cpu = i; |
898 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 1044 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
899 | } | 1045 | } |
@@ -936,13 +1082,18 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi | |||
936 | if (query_current_values_with_pending_wait(data)) | 1082 | if (query_current_values_with_pending_wait(data)) |
937 | goto err_out; | 1083 | goto err_out; |
938 | 1084 | ||
939 | dprintk("targ: curr fid 0x%x, vid 0x%x\n", | 1085 | if (cpu_family) |
1086 | dprintk("targ: curr fid 0x%x, did 0x%x\n", | ||
1087 | data->currfid, data->currvid); | ||
1088 | else { | ||
1089 | dprintk("targ: curr fid 0x%x, vid 0x%x\n", | ||
940 | data->currfid, data->currvid); | 1090 | data->currfid, data->currvid); |
941 | 1091 | ||
942 | if ((checkvid != data->currvid) || (checkfid != data->currfid)) { | 1092 | if ((checkvid != data->currvid) || (checkfid != data->currfid)) { |
943 | printk(KERN_INFO PFX | 1093 | printk(KERN_INFO PFX |
944 | "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n", | 1094 | "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n", |
945 | checkfid, data->currfid, checkvid, data->currvid); | 1095 | checkfid, data->currfid, checkvid, data->currvid); |
1096 | } | ||
946 | } | 1097 | } |
947 | 1098 | ||
948 | if (cpufreq_frequency_table_target(pol, data->powernow_table, targfreq, relation, &newstate)) | 1099 | if (cpufreq_frequency_table_target(pol, data->powernow_table, targfreq, relation, &newstate)) |
@@ -952,7 +1103,11 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi | |||
952 | 1103 | ||
953 | powernow_k8_acpi_pst_values(data, newstate); | 1104 | powernow_k8_acpi_pst_values(data, newstate); |
954 | 1105 | ||
955 | if (transition_frequency(data, newstate)) { | 1106 | if (cpu_family) |
1107 | ret = transition_frequency_pstate(data, newstate); | ||
1108 | else | ||
1109 | ret = transition_frequency_fidvid(data, newstate); | ||
1110 | if (ret) { | ||
956 | printk(KERN_ERR PFX "transition frequency failed\n"); | 1111 | printk(KERN_ERR PFX "transition frequency failed\n"); |
957 | ret = 1; | 1112 | ret = 1; |
958 | mutex_unlock(&fidvid_mutex); | 1113 | mutex_unlock(&fidvid_mutex); |
@@ -960,7 +1115,10 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi | |||
960 | } | 1115 | } |
961 | mutex_unlock(&fidvid_mutex); | 1116 | mutex_unlock(&fidvid_mutex); |
962 | 1117 | ||
963 | pol->cur = find_khz_freq_from_fid(data->currfid); | 1118 | if (cpu_family) |
1119 | pol->cur = find_khz_freq_from_fiddid(data->currfid, data->currdid); | ||
1120 | else | ||
1121 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
964 | ret = 0; | 1122 | ret = 0; |
965 | 1123 | ||
966 | err_out: | 1124 | err_out: |
@@ -1005,14 +1163,13 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1005 | * Use the PSB BIOS structure. This is only availabe on | 1163 | * Use the PSB BIOS structure. This is only availabe on |
1006 | * an UP version, and is deprecated by AMD. | 1164 | * an UP version, and is deprecated by AMD. |
1007 | */ | 1165 | */ |
1008 | |||
1009 | if ((num_online_cpus() != 1) || (num_possible_cpus() != 1)) { | 1166 | if ((num_online_cpus() != 1) || (num_possible_cpus() != 1)) { |
1010 | printk(KERN_ERR PFX "MP systems not supported by PSB BIOS structure\n"); | 1167 | printk(KERN_ERR PFX "MP systems not supported by PSB BIOS structure\n"); |
1011 | kfree(data); | 1168 | kfree(data); |
1012 | return -ENODEV; | 1169 | return -ENODEV; |
1013 | } | 1170 | } |
1014 | if (pol->cpu != 0) { | 1171 | if (pol->cpu != 0) { |
1015 | printk(KERN_ERR PFX "init not cpu 0\n"); | 1172 | printk(KERN_ERR PFX "No _PSS objects for CPU other than CPU0\n"); |
1016 | kfree(data); | 1173 | kfree(data); |
1017 | return -ENODEV; | 1174 | return -ENODEV; |
1018 | } | 1175 | } |
@@ -1040,20 +1197,28 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1040 | if (query_current_values_with_pending_wait(data)) | 1197 | if (query_current_values_with_pending_wait(data)) |
1041 | goto err_out; | 1198 | goto err_out; |
1042 | 1199 | ||
1043 | fidvid_msr_init(); | 1200 | if (!cpu_family) |
1201 | fidvid_msr_init(); | ||
1044 | 1202 | ||
1045 | /* run on any CPU again */ | 1203 | /* run on any CPU again */ |
1046 | set_cpus_allowed(current, oldmask); | 1204 | set_cpus_allowed(current, oldmask); |
1047 | 1205 | ||
1048 | pol->governor = CPUFREQ_DEFAULT_GOVERNOR; | 1206 | pol->governor = CPUFREQ_DEFAULT_GOVERNOR; |
1049 | pol->cpus = cpu_core_map[pol->cpu]; | 1207 | if (cpu_family) |
1208 | pol->cpus = cpumask_of_cpu(pol->cpu); | ||
1209 | else | ||
1210 | pol->cpus = cpu_core_map[pol->cpu]; | ||
1211 | data->available_cores = &(pol->cpus); | ||
1050 | 1212 | ||
1051 | /* Take a crude guess here. | 1213 | /* Take a crude guess here. |
1052 | * That guess was in microseconds, so multiply with 1000 */ | 1214 | * That guess was in microseconds, so multiply with 1000 */ |
1053 | pol->cpuinfo.transition_latency = (((data->rvo + 8) * data->vstable * VST_UNITS_20US) | 1215 | pol->cpuinfo.transition_latency = (((data->rvo + 8) * data->vstable * VST_UNITS_20US) |
1054 | + (3 * (1 << data->irt) * 10)) * 1000; | 1216 | + (3 * (1 << data->irt) * 10)) * 1000; |
1055 | 1217 | ||
1056 | pol->cur = find_khz_freq_from_fid(data->currfid); | 1218 | if (cpu_family) |
1219 | pol->cur = find_khz_freq_from_fiddid(data->currfid, data->currdid); | ||
1220 | else | ||
1221 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1057 | dprintk("policy current frequency %d kHz\n", pol->cur); | 1222 | dprintk("policy current frequency %d kHz\n", pol->cur); |
1058 | 1223 | ||
1059 | /* min/max the cpu is capable of */ | 1224 | /* min/max the cpu is capable of */ |
@@ -1067,8 +1232,12 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | |||
1067 | 1232 | ||
1068 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | 1233 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); |
1069 | 1234 | ||
1070 | printk("cpu_init done, current fid 0x%x, vid 0x%x\n", | 1235 | if (cpu_family) |
1071 | data->currfid, data->currvid); | 1236 | dprintk("cpu_init done, current fid 0x%x, did 0x%x\n", |
1237 | data->currfid, data->currdid); | ||
1238 | else | ||
1239 | dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n", | ||
1240 | data->currfid, data->currvid); | ||
1072 | 1241 | ||
1073 | powernow_data[pol->cpu] = data; | 1242 | powernow_data[pol->cpu] = data; |
1074 | 1243 | ||
@@ -1154,8 +1323,9 @@ static int __cpuinit powernowk8_init(void) | |||
1154 | } | 1323 | } |
1155 | 1324 | ||
1156 | if (supported_cpus == num_online_cpus()) { | 1325 | if (supported_cpus == num_online_cpus()) { |
1157 | printk(KERN_INFO PFX "Found %d AMD Athlon 64 / Opteron " | 1326 | printk(KERN_INFO PFX "Found %d %s " |
1158 | "processors (" VERSION ")\n", supported_cpus); | 1327 | "processors (" VERSION ")\n", supported_cpus, |
1328 | boot_cpu_data.x86_model_id); | ||
1159 | return cpufreq_register_driver(&cpufreq_amd64_driver); | 1329 | return cpufreq_register_driver(&cpufreq_amd64_driver); |
1160 | } | 1330 | } |
1161 | 1331 | ||
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h index 79a7c5c87edc..bf8ad9e43da3 100644 --- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h +++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * (c) 2003, 2004, 2005 Advanced Micro Devices, Inc. | 2 | * (c) 2003-2006 Advanced Micro Devices, Inc. |
3 | * Your use of this code is subject to the terms and conditions of the | 3 | * Your use of this code is subject to the terms and conditions of the |
4 | * GNU general public license version 2. See "COPYING" or | 4 | * GNU general public license version 2. See "COPYING" or |
5 | * http://www.gnu.org/licenses/gpl.html | 5 | * http://www.gnu.org/licenses/gpl.html |
@@ -21,8 +21,8 @@ struct powernow_k8_data { | |||
21 | u32 plllock; /* pll lock time, units 1 us */ | 21 | u32 plllock; /* pll lock time, units 1 us */ |
22 | u32 exttype; /* extended interface = 1 */ | 22 | u32 exttype; /* extended interface = 1 */ |
23 | 23 | ||
24 | /* keep track of the current fid / vid */ | 24 | /* keep track of the current fid / vid or did */ |
25 | u32 currvid, currfid; | 25 | u32 currvid, currfid, currdid; |
26 | 26 | ||
27 | /* the powernow_table includes all frequency and vid/fid pairings: | 27 | /* the powernow_table includes all frequency and vid/fid pairings: |
28 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | 28 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. |
@@ -34,6 +34,10 @@ struct powernow_k8_data { | |||
34 | * used to determine valid frequency/vid/fid states */ | 34 | * used to determine valid frequency/vid/fid states */ |
35 | struct acpi_processor_performance acpi_data; | 35 | struct acpi_processor_performance acpi_data; |
36 | #endif | 36 | #endif |
37 | /* we need to keep track of associated cores, but let cpufreq | ||
38 | * handle hotplug events - so just point at cpufreq pol->cpus | ||
39 | * structure */ | ||
40 | cpumask_t *available_cores; | ||
37 | }; | 41 | }; |
38 | 42 | ||
39 | 43 | ||
@@ -43,6 +47,7 @@ struct powernow_k8_data { | |||
43 | #define CPUID_XFAM_K8 0 | 47 | #define CPUID_XFAM_K8 0 |
44 | #define CPUID_XMOD 0x000f0000 /* extended model */ | 48 | #define CPUID_XMOD 0x000f0000 /* extended model */ |
45 | #define CPUID_XMOD_REV_G 0x00060000 | 49 | #define CPUID_XMOD_REV_G 0x00060000 |
50 | #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */ | ||
46 | #define CPUID_USE_XFAM_XMOD 0x00000f00 | 51 | #define CPUID_USE_XFAM_XMOD 0x00000f00 |
47 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 | 52 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 |
48 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 | 53 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 |
@@ -79,6 +84,32 @@ struct powernow_k8_data { | |||
79 | #define MSR_S_HI_CURRENT_VID 0x0000003f | 84 | #define MSR_S_HI_CURRENT_VID 0x0000003f |
80 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | 85 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 |
81 | 86 | ||
87 | |||
88 | /* Hardware Pstate _PSS and MSR definitions */ | ||
89 | #define USE_HW_PSTATE 0x00000080 | ||
90 | #define HW_PSTATE_FID_MASK 0x0000003f | ||
91 | #define HW_PSTATE_DID_MASK 0x000001c0 | ||
92 | #define HW_PSTATE_DID_SHIFT 6 | ||
93 | #define HW_PSTATE_MASK 0x00000007 | ||
94 | #define HW_PSTATE_VALID_MASK 0x80000000 | ||
95 | #define HW_FID_INDEX_SHIFT 8 | ||
96 | #define HW_FID_INDEX_MASK 0x0000ff00 | ||
97 | #define HW_DID_INDEX_SHIFT 16 | ||
98 | #define HW_DID_INDEX_MASK 0x00ff0000 | ||
99 | #define HW_WATTS_MASK 0xff | ||
100 | #define HW_PWR_DVR_MASK 0x300 | ||
101 | #define HW_PWR_DVR_SHIFT 8 | ||
102 | #define HW_PWR_MAX_MULT 3 | ||
103 | #define MAX_HW_PSTATE 8 /* hw pstate supports up to 8 */ | ||
104 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ | ||
105 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | ||
106 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | ||
107 | |||
108 | /* define the two driver architectures */ | ||
109 | #define CPU_OPTERON 0 | ||
110 | #define CPU_HW_PSTATE 1 | ||
111 | |||
112 | |||
82 | /* | 113 | /* |
83 | * There are restrictions frequencies have to follow: | 114 | * There are restrictions frequencies have to follow: |
84 | * - only 1 entry in the low fid table ( <=1.4GHz ) | 115 | * - only 1 entry in the low fid table ( <=1.4GHz ) |
@@ -182,6 +213,9 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | |||
182 | 213 | ||
183 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | 214 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); |
184 | 215 | ||
216 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
217 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
218 | |||
185 | #ifdef CONFIG_SMP | 219 | #ifdef CONFIG_SMP |
186 | static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) | 220 | static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) |
187 | { | 221 | { |