xref: /OK3568_Linux_fs/kernel/drivers/cpufreq/powernow-k8.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  (c) 2003-2006 Advanced Micro Devices, Inc.
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun struct powernow_k8_data {
7*4882a593Smuzhiyun 	unsigned int cpu;
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun 	u32 numps;  /* number of p-states */
10*4882a593Smuzhiyun 	u32 batps;  /* number of p-states supported on battery */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun 	/* these values are constant when the PSB is used to determine
13*4882a593Smuzhiyun 	 * vid/fid pairings, but are modified during the ->target() call
14*4882a593Smuzhiyun 	 * when ACPI is used */
15*4882a593Smuzhiyun 	u32 rvo;     /* ramp voltage offset */
16*4882a593Smuzhiyun 	u32 irt;     /* isochronous relief time */
17*4882a593Smuzhiyun 	u32 vidmvs;  /* usable value calculated from mvs */
18*4882a593Smuzhiyun 	u32 vstable; /* voltage stabilization time, units 20 us */
19*4882a593Smuzhiyun 	u32 plllock; /* pll lock time, units 1 us */
20*4882a593Smuzhiyun 	u32 exttype; /* extended interface = 1 */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 	/* keep track of the current fid / vid or pstate */
23*4882a593Smuzhiyun 	u32 currvid;
24*4882a593Smuzhiyun 	u32 currfid;
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 	/* the powernow_table includes all frequency and vid/fid pairings:
27*4882a593Smuzhiyun 	 * fid are the lower 8 bits of the index, vid are the upper 8 bits.
28*4882a593Smuzhiyun 	 * frequency is in kHz */
29*4882a593Smuzhiyun 	struct cpufreq_frequency_table  *powernow_table;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 	/* the acpi table needs to be kept. it's only available if ACPI was
32*4882a593Smuzhiyun 	 * used to determine valid frequency/vid/fid states */
33*4882a593Smuzhiyun 	struct acpi_processor_performance acpi_data;
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	/* we need to keep track of associated cores, but let cpufreq
36*4882a593Smuzhiyun 	 * handle hotplug events - so just point at cpufreq pol->cpus
37*4882a593Smuzhiyun 	 * structure */
38*4882a593Smuzhiyun 	struct cpumask *available_cores;
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /* processor's cpuid instruction support */
42*4882a593Smuzhiyun #define CPUID_PROCESSOR_SIGNATURE	1	/* function 1 */
43*4882a593Smuzhiyun #define CPUID_XFAM			0x0ff00000	/* extended family */
44*4882a593Smuzhiyun #define CPUID_XFAM_K8			0
45*4882a593Smuzhiyun #define CPUID_XMOD			0x000f0000	/* extended model */
46*4882a593Smuzhiyun #define CPUID_XMOD_REV_MASK		0x000c0000
47*4882a593Smuzhiyun #define CPUID_XFAM_10H			0x00100000	/* family 0x10 */
48*4882a593Smuzhiyun #define CPUID_USE_XFAM_XMOD		0x00000f00
49*4882a593Smuzhiyun #define CPUID_GET_MAX_CAPABILITIES	0x80000000
50*4882a593Smuzhiyun #define CPUID_FREQ_VOLT_CAPABILITIES	0x80000007
51*4882a593Smuzhiyun #define P_STATE_TRANSITION_CAPABLE	6
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For     */
54*4882a593Smuzhiyun /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and   */
55*4882a593Smuzhiyun /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */
56*4882a593Smuzhiyun /* the register number is placed in ecx, and the data is returned in edx:eax. */
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #define MSR_FIDVID_CTL      0xc0010041
59*4882a593Smuzhiyun #define MSR_FIDVID_STATUS   0xc0010042
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /* Field definitions within the FID VID Low Control MSR : */
62*4882a593Smuzhiyun #define MSR_C_LO_INIT_FID_VID     0x00010000
63*4882a593Smuzhiyun #define MSR_C_LO_NEW_VID          0x00003f00
64*4882a593Smuzhiyun #define MSR_C_LO_NEW_FID          0x0000003f
65*4882a593Smuzhiyun #define MSR_C_LO_VID_SHIFT        8
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /* Field definitions within the FID VID High Control MSR : */
68*4882a593Smuzhiyun #define MSR_C_HI_STP_GNT_TO	  0x000fffff
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /* Field definitions within the FID VID Low Status MSR : */
71*4882a593Smuzhiyun #define MSR_S_LO_CHANGE_PENDING   0x80000000   /* cleared when completed */
72*4882a593Smuzhiyun #define MSR_S_LO_MAX_RAMP_VID     0x3f000000
73*4882a593Smuzhiyun #define MSR_S_LO_MAX_FID          0x003f0000
74*4882a593Smuzhiyun #define MSR_S_LO_START_FID        0x00003f00
75*4882a593Smuzhiyun #define MSR_S_LO_CURRENT_FID      0x0000003f
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun /* Field definitions within the FID VID High Status MSR : */
78*4882a593Smuzhiyun #define MSR_S_HI_MIN_WORKING_VID  0x3f000000
79*4882a593Smuzhiyun #define MSR_S_HI_MAX_WORKING_VID  0x003f0000
80*4882a593Smuzhiyun #define MSR_S_HI_START_VID        0x00003f00
81*4882a593Smuzhiyun #define MSR_S_HI_CURRENT_VID      0x0000003f
82*4882a593Smuzhiyun #define MSR_C_HI_STP_GNT_BENIGN	  0x00000001
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * There are restrictions frequencies have to follow:
86*4882a593Smuzhiyun  * - only 1 entry in the low fid table ( <=1.4GHz )
87*4882a593Smuzhiyun  * - lowest entry in the high fid table must be >= 2 * the entry in the
88*4882a593Smuzhiyun  *   low fid table
89*4882a593Smuzhiyun  * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry
90*4882a593Smuzhiyun  *   in the low fid table
91*4882a593Smuzhiyun  * - the parts can only step at <= 200 MHz intervals, odd fid values are
92*4882a593Smuzhiyun  *   supported in revision G and later revisions.
93*4882a593Smuzhiyun  * - lowest frequency must be >= interprocessor hypertransport link speed
94*4882a593Smuzhiyun  *   (only applies to MP systems obviously)
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */
98*4882a593Smuzhiyun #define LO_FID_TABLE_TOP     7	/* fid values marking the boundary    */
99*4882a593Smuzhiyun #define HI_FID_TABLE_BOTTOM  8	/* between the low and high tables    */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun #define LO_VCOFREQ_TABLE_TOP    1400	/* corresponding vco frequency values */
102*4882a593Smuzhiyun #define HI_VCOFREQ_TABLE_BOTTOM 1600
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #define MIN_FREQ_RESOLUTION  200 /* fids jump by 2 matching freq jumps by 200 */
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define MAX_FID 0x2a	/* Spec only gives FID values as far as 5 GHz */
107*4882a593Smuzhiyun #define LEAST_VID 0x3e	/* Lowest (numerically highest) useful vid value */
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #define MIN_FREQ 800	/* Min and max freqs, per spec */
110*4882a593Smuzhiyun #define MAX_FREQ 5000
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun #define INVALID_FID_MASK 0xffffffc0  /* not a valid fid if these bits are set */
113*4882a593Smuzhiyun #define INVALID_VID_MASK 0xffffffc0  /* not a valid vid if these bits are set */
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #define VID_OFF 0x3f
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun #define MAXIMUM_VID_STEPS 1  /* Current cpus only allow a single step of 25mV */
122*4882a593Smuzhiyun #define VST_UNITS_20US 20   /* Voltage Stabilization Time is in units of 20us */
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /*
125*4882a593Smuzhiyun  * Most values of interest are encoded in a single field of the _PSS
126*4882a593Smuzhiyun  * entries: the "control" value.
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #define IRT_SHIFT      30
130*4882a593Smuzhiyun #define RVO_SHIFT      28
131*4882a593Smuzhiyun #define EXT_TYPE_SHIFT 27
132*4882a593Smuzhiyun #define PLL_L_SHIFT    20
133*4882a593Smuzhiyun #define MVS_SHIFT      18
134*4882a593Smuzhiyun #define VST_SHIFT      11
135*4882a593Smuzhiyun #define VID_SHIFT       6
136*4882a593Smuzhiyun #define IRT_MASK        3
137*4882a593Smuzhiyun #define RVO_MASK        3
138*4882a593Smuzhiyun #define EXT_TYPE_MASK   1
139*4882a593Smuzhiyun #define PLL_L_MASK   0x7f
140*4882a593Smuzhiyun #define MVS_MASK        3
141*4882a593Smuzhiyun #define VST_MASK     0x7f
142*4882a593Smuzhiyun #define VID_MASK     0x1f
143*4882a593Smuzhiyun #define FID_MASK     0x1f
144*4882a593Smuzhiyun #define EXT_VID_MASK 0x3f
145*4882a593Smuzhiyun #define EXT_FID_MASK 0x3f
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun /*
149*4882a593Smuzhiyun  * Version 1.4 of the PSB table. This table is constructed by BIOS and is
150*4882a593Smuzhiyun  * to tell the OS's power management driver which VIDs and FIDs are
151*4882a593Smuzhiyun  * supported by this particular processor.
152*4882a593Smuzhiyun  * If the data in the PSB / PST is wrong, then this driver will program the
153*4882a593Smuzhiyun  * wrong values into hardware, which is very likely to lead to a crash.
154*4882a593Smuzhiyun  */
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun #define PSB_ID_STRING      "AMDK7PNOW!"
157*4882a593Smuzhiyun #define PSB_ID_STRING_LEN  10
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun #define PSB_VERSION_1_4  0x14
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun struct psb_s {
162*4882a593Smuzhiyun 	u8 signature[10];
163*4882a593Smuzhiyun 	u8 tableversion;
164*4882a593Smuzhiyun 	u8 flags1;
165*4882a593Smuzhiyun 	u16 vstable;
166*4882a593Smuzhiyun 	u8 flags2;
167*4882a593Smuzhiyun 	u8 num_tables;
168*4882a593Smuzhiyun 	u32 cpuid;
169*4882a593Smuzhiyun 	u8 plllocktime;
170*4882a593Smuzhiyun 	u8 maxfid;
171*4882a593Smuzhiyun 	u8 maxvid;
172*4882a593Smuzhiyun 	u8 numps;
173*4882a593Smuzhiyun };
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */
176*4882a593Smuzhiyun struct pst_s {
177*4882a593Smuzhiyun 	u8 fid;
178*4882a593Smuzhiyun 	u8 vid;
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun static int core_voltage_pre_transition(struct powernow_k8_data *data,
182*4882a593Smuzhiyun 	u32 reqvid, u32 regfid);
183*4882a593Smuzhiyun static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid);
184*4882a593Smuzhiyun static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
189