blob: 6c6698feade15f7ab034d665874a8f4e4fde8384 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dave Jones1f729e02006-06-04 19:37:58 -04002 * (c) 2003-2006 Advanced Micro Devices, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Your use of this code is subject to the terms and conditions of the
4 * GNU general public license version 2. See "COPYING" or
5 * http://www.gnu.org/licenses/gpl.html
6 */
7
Andreas Herrmanna266d9f2008-11-21 14:49:25 +01008
9enum pstate {
10 HW_PSTATE_INVALID = 0xff,
11 HW_PSTATE_0 = 0,
12 HW_PSTATE_1 = 1,
13 HW_PSTATE_2 = 2,
14 HW_PSTATE_3 = 3,
15 HW_PSTATE_4 = 4,
16 HW_PSTATE_5 = 5,
17 HW_PSTATE_6 = 6,
18 HW_PSTATE_7 = 7,
19};
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct powernow_k8_data {
22 unsigned int cpu;
23
24 u32 numps; /* number of p-states */
25 u32 batps; /* number of p-states supported on battery */
Mark Langsdorfc5829cd2007-10-17 16:52:08 -050026 u32 max_hw_pstate; /* maximum legal hardware pstate */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28 /* these values are constant when the PSB is used to determine
29 * vid/fid pairings, but are modified during the ->target() call
30 * when ACPI is used */
31 u32 rvo; /* ramp voltage offset */
32 u32 irt; /* isochronous relief time */
33 u32 vidmvs; /* usable value calculated from mvs */
34 u32 vstable; /* voltage stabilization time, units 20 us */
35 u32 plllock; /* pll lock time, units 1 us */
Dave Jones841e40b2005-07-28 09:40:04 -070036 u32 exttype; /* extended interface = 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Mark Langsdorfc5829cd2007-10-17 16:52:08 -050038 /* keep track of the current fid / vid or pstate */
Andreas Herrmanna266d9f2008-11-21 14:49:25 +010039 u32 currvid;
40 u32 currfid;
41 enum pstate currpstate;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 /* the powernow_table includes all frequency and vid/fid pairings:
44 * fid are the lower 8 bits of the index, vid are the upper 8 bits.
45 * frequency is in kHz */
46 struct cpufreq_frequency_table *powernow_table;
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 /* the acpi table needs to be kept. it's only available if ACPI was
49 * used to determine valid frequency/vid/fid states */
Linus Torvaldsf607e3a2008-08-19 13:34:59 -070050 struct acpi_processor_performance acpi_data;
Thomas Renninger57f4fa62009-02-04 01:17:45 +010051
Dave Jones1f729e02006-06-04 19:37:58 -040052 /* we need to keep track of associated cores, but let cpufreq
53 * handle hotplug events - so just point at cpufreq pol->cpus
54 * structure */
Rusty Russell835481d2009-01-04 05:18:06 -080055 struct cpumask *available_cores;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
58
59/* processor's cpuid instruction support */
60#define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */
61#define CPUID_XFAM 0x0ff00000 /* extended family */
62#define CPUID_XFAM_K8 0
63#define CPUID_XMOD 0x000f0000 /* extended model */
Mark Langsdorf6c9cda72007-12-14 13:00:23 -060064#define CPUID_XMOD_REV_MASK 0x000c0000
Dave Jones30046e52007-05-13 11:55:14 -040065#define CPUID_XFAM_10H 0x00100000 /* family 0x10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#define CPUID_USE_XFAM_XMOD 0x00000f00
67#define CPUID_GET_MAX_CAPABILITIES 0x80000000
68#define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007
69#define P_STATE_TRANSITION_CAPABLE 6
70
71/* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */
72/* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */
73/* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */
74/* the register number is placed in ecx, and the data is returned in edx:eax. */
75
76#define MSR_FIDVID_CTL 0xc0010041
77#define MSR_FIDVID_STATUS 0xc0010042
78
79/* Field definitions within the FID VID Low Control MSR : */
80#define MSR_C_LO_INIT_FID_VID 0x00010000
Dave Jones841e40b2005-07-28 09:40:04 -070081#define MSR_C_LO_NEW_VID 0x00003f00
82#define MSR_C_LO_NEW_FID 0x0000003f
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define MSR_C_LO_VID_SHIFT 8
84
85/* Field definitions within the FID VID High Control MSR : */
Dave Jones32ee8c32006-02-28 00:43:23 -050086#define MSR_C_HI_STP_GNT_TO 0x000fffff
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88/* Field definitions within the FID VID Low Status MSR : */
Dave Jones841e40b2005-07-28 09:40:04 -070089#define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */
90#define MSR_S_LO_MAX_RAMP_VID 0x3f000000
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define MSR_S_LO_MAX_FID 0x003f0000
92#define MSR_S_LO_START_FID 0x00003f00
93#define MSR_S_LO_CURRENT_FID 0x0000003f
94
95/* Field definitions within the FID VID High Status MSR : */
Dave Jones841e40b2005-07-28 09:40:04 -070096#define MSR_S_HI_MIN_WORKING_VID 0x3f000000
97#define MSR_S_HI_MAX_WORKING_VID 0x003f0000
98#define MSR_S_HI_START_VID 0x00003f00
99#define MSR_S_HI_CURRENT_VID 0x0000003f
100#define MSR_C_HI_STP_GNT_BENIGN 0x00000001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Dave Jones1f729e02006-06-04 19:37:58 -0400102
103/* Hardware Pstate _PSS and MSR definitions */
104#define USE_HW_PSTATE 0x00000080
Dave Jones1f729e02006-06-04 19:37:58 -0400105#define HW_PSTATE_MASK 0x00000007
106#define HW_PSTATE_VALID_MASK 0x80000000
Mark Langsdorfc5829cd2007-10-17 16:52:08 -0500107#define HW_PSTATE_MAX_MASK 0x000000f0
108#define HW_PSTATE_MAX_SHIFT 4
Dave Jones1f729e02006-06-04 19:37:58 -0400109#define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */
110#define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */
111#define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */
Mark Langsdorfc5829cd2007-10-17 16:52:08 -0500112#define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */
Dave Jones1f729e02006-06-04 19:37:58 -0400113
114/* define the two driver architectures */
115#define CPU_OPTERON 0
116#define CPU_HW_PSTATE 1
117
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/*
120 * There are restrictions frequencies have to follow:
121 * - only 1 entry in the low fid table ( <=1.4GHz )
122 * - lowest entry in the high fid table must be >= 2 * the entry in the
123 * low fid table
124 * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry
125 * in the low fid table
Langsdorf, Mark019a61b2005-11-29 14:18:03 -0600126 * - the parts can only step at <= 200 MHz intervals, odd fid values are
127 * supported in revision G and later revisions.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 * - lowest frequency must be >= interprocessor hypertransport link speed
129 * (only applies to MP systems obviously)
130 */
131
132/* fids (frequency identifiers) are arranged in 2 tables - lo and hi */
Langsdorf, Mark019a61b2005-11-29 14:18:03 -0600133#define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */
135
136#define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */
137#define HI_VCOFREQ_TABLE_BOTTOM 1600
138
139#define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */
140
141#define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */
Dave Jones841e40b2005-07-28 09:40:04 -0700142#define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144#define MIN_FREQ 800 /* Min and max freqs, per spec */
145#define MAX_FREQ 5000
146
Langsdorf, Mark019a61b2005-11-29 14:18:03 -0600147#define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */
Dave Jones841e40b2005-07-28 09:40:04 -0700148#define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */
149
150#define VID_OFF 0x3f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152#define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */
153
154#define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */
155
156#define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */
Simon Arlott27b46d72007-10-20 01:13:56 +0200157#define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159/*
Simon Arlott27b46d72007-10-20 01:13:56 +0200160 * Most values of interest are encoded in a single field of the _PSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 * entries: the "control" value.
162 */
Dave Jones32ee8c32006-02-28 00:43:23 -0500163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define IRT_SHIFT 30
165#define RVO_SHIFT 28
Dave Jones2bcad932005-07-29 09:56:41 -0700166#define EXT_TYPE_SHIFT 27
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define PLL_L_SHIFT 20
168#define MVS_SHIFT 18
169#define VST_SHIFT 11
170#define VID_SHIFT 6
171#define IRT_MASK 3
172#define RVO_MASK 3
Dave Jones2bcad932005-07-29 09:56:41 -0700173#define EXT_TYPE_MASK 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#define PLL_L_MASK 0x7f
175#define MVS_MASK 3
176#define VST_MASK 0x7f
177#define VID_MASK 0x1f
Langsdorf, Mark6cad6472006-06-08 10:33:19 -0500178#define FID_MASK 0x1f
179#define EXT_VID_MASK 0x3f
180#define EXT_FID_MASK 0x3f
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182
183/*
184 * Version 1.4 of the PSB table. This table is constructed by BIOS and is
185 * to tell the OS's power management driver which VIDs and FIDs are
186 * supported by this particular processor.
187 * If the data in the PSB / PST is wrong, then this driver will program the
188 * wrong values into hardware, which is very likely to lead to a crash.
189 */
190
191#define PSB_ID_STRING "AMDK7PNOW!"
192#define PSB_ID_STRING_LEN 10
193
194#define PSB_VERSION_1_4 0x14
195
196struct psb_s {
197 u8 signature[10];
198 u8 tableversion;
199 u8 flags1;
200 u16 vstable;
201 u8 flags2;
202 u8 num_tables;
203 u32 cpuid;
204 u8 plllocktime;
205 u8 maxfid;
206 u8 maxvid;
207 u8 numps;
208};
209
210/* Pairs of fid/vid values are appended to the version 1.4 PSB table. */
211struct pst_s {
212 u8 fid;
213 u8 vid;
214};
215
216#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg)
217
218static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid);
219static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid);
220static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
221
222static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
Dave Jones065b8072005-05-31 19:03:46 -0700223
Dave Jones1f729e02006-06-04 19:37:58 -0400224static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
225static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
226
Dave Jones065b8072005-05-31 19:03:46 -0700227#ifdef CONFIG_SMP
228static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
229{
230}
231#else
232static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
233{
234 cpu_set(0, cpu_sharedcore_mask[0]);
235}
236#endif