blob: c2019ab13b4b6b123454997ab095c3cb43ad844b [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Thomas Jourdan1a692d82009-07-01 17:01:17 +00002
3#include <console/console.h>
4#include <device/device.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +00005#include <cpu/cpu.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +00006#include <cpu/x86/msr.h>
Stefan Reinauer2a27b202010-12-11 22:14:44 +00007#include <cpu/intel/speedstep.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +00008#include <cpu/x86/cache.h>
Uwe Hermannaac8f662010-09-29 09:54:16 +00009#include <cpu/x86/name.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030010#include <cpu/intel/smm_reloc.h>
Elyes HAOUAS273c3482020-06-15 18:29:43 +020011
Nico Huber68d7c7a2012-10-02 11:46:11 +020012#define MSR_BBL_CR_CTL3 0x11e
Thomas Jourdan1a692d82009-07-01 17:01:17 +000013
Nico Huber68d7c7a2012-10-02 11:46:11 +020014static void configure_c_states(const int quad)
Thomas Jourdan1a692d82009-07-01 17:01:17 +000015{
16 msr_t msr;
17
Nico Huber68d7c7a2012-10-02 11:46:11 +020018 /* Is C5 requested and supported? */
Arthur Heymans98c92572022-11-07 11:39:58 +010019 const int c5 = southbridge_support_c5() &&
Nico Huber68d7c7a2012-10-02 11:46:11 +020020 (rdmsr(MSR_BBL_CR_CTL3).lo & (3 << 30)) &&
21 !(rdmsr(MSR_FSB_FREQ).lo & (1 << 31));
22 /* Is C6 requested and supported? */
Arthur Heymans98c92572022-11-07 11:39:58 +010023 const int c6 = southbridge_support_c6() &&
Nico Huber68d7c7a2012-10-02 11:46:11 +020024 ((cpuid_edx(5) >> (6 * 4)) & 0xf) && c5;
25
26 const int cst_range = (c6 ? 6 : (c5 ? 5 : 4)) - 2; /* zero means lvl2 */
27
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020028 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000029 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
Nico Huber68d7c7a2012-10-02 11:46:11 +020030 msr.lo |= (1 << 8);
Lee Leahy26eeb0f2017-03-15 18:08:50 -070031 if (quad)
Nico Huber68d7c7a2012-10-02 11:46:11 +020032 msr.lo = (msr.lo & ~(7 << 0)) | (4 << 0);
Nico Huber68d7c7a2012-10-02 11:46:11 +020033 if (c5) {
34 msr.lo &= ~(1 << 13);
35 msr.lo &= ~(7 << 0);
36 msr.lo |= (1 << 3); /* Enable dynamic L2. */
37 msr.lo |= (1 << 14); /* Enable deeper sleep */
38 }
39 /* Next two fields seem to be mutually exclusive: */
40 msr.lo &= ~(7 << 4);
41 msr.lo |= (1 << 10); /* Enable IO MWAIT redirection. */
42 if (c6)
43 msr.lo |= (1 << 25);
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020044 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000045
46 /* Set Processor MWAIT IO BASE */
47 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070048 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff)
49 << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010050 wrmsr(MSR_PMG_IO_BASE_ADDR, msr);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000051
52 /* Set IO Capture Address */
53 msr.hi = 0;
Nico Huber68d7c7a2012-10-02 11:46:11 +020054 msr.lo = ((PMB0_BASE + 4) & 0xffff) | ((cst_range & 0xffff) << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010055 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +020056
57 if (c5) {
58 msr = rdmsr(MSR_BBL_CR_CTL3);
59 msr.lo &= ~(7 << 25);
60 msr.lo |= (2 << 25);
61 msr.lo &= ~(3 << 30);
62 msr.lo |= (1 << 30);
63 wrmsr(MSR_BBL_CR_CTL3, msr);
64 }
Thomas Jourdan1a692d82009-07-01 17:01:17 +000065}
66
Nico Huber68d7c7a2012-10-02 11:46:11 +020067static void configure_p_states(const char stepping, const char cores)
Thomas Jourdan1a692d82009-07-01 17:01:17 +000068{
69 msr_t msr;
70
Nico Huber68d7c7a2012-10-02 11:46:11 +020071 msr = rdmsr(MSR_EXTENDED_CONFIG);
Patrick Georgif17c58b2014-08-09 20:48:12 +020072 /* Super LFM supported? */
Arthur Heymans98c92572022-11-07 11:39:58 +010073 if (northbridge_support_slfm() && (msr.lo & (1 << 27)))
Nico Huber68d7c7a2012-10-02 11:46:11 +020074 msr.lo |= (1 << 28); /* Enable Super LFM. */
75 wrmsr(MSR_EXTENDED_CONFIG, msr);
76
77 if (rdmsr(MSR_FSB_CLOCK_VCC).hi & (1 << (63 - 32))) {
78 /* Turbo supported? */
79 if ((stepping == 0xa) && (cores < 4)) {
80 msr = rdmsr(MSR_FSB_FREQ);
81 msr.lo |= (1 << 3); /* Enable hysteresis. */
82 wrmsr(MSR_FSB_FREQ, msr);
83 }
84 msr = rdmsr(IA32_PERF_CTL);
85 msr.hi &= ~(1 << (32 - 32)); /* Clear turbo disable. */
86 wrmsr(IA32_PERF_CTL, msr);
87 }
88
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020089 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Nico Huber68d7c7a2012-10-02 11:46:11 +020090 msr.lo &= ~(1 << 11); /* Enable hw coordination. */
91 msr.lo |= (1 << 15); /* Lock config until next reset. */
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020092 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +020093}
94
95#define MSR_EMTTM_CR_TABLE(x) (0xa8 + (x))
96#define MSR_EMTTM_TABLE_NUM 6
97static void configure_emttm_tables(void)
98{
99 int i;
100 int num_states, pstate_idx;
101 msr_t msr;
102 sst_table_t pstates;
103
104 /* Gather p-state information. */
105 speedstep_gen_pstates(&pstates);
106
107 /* Never turbo mode or Super LFM. */
108 num_states = pstates.num_states;
109 if (pstates.states[0].is_turbo)
110 --num_states;
111 if (pstates.states[pstates.num_states - 1].is_slfm)
112 --num_states;
113 /* Repeat lowest p-state if we haven't enough states. */
114 const int num_lowest_pstate =
115 (num_states < MSR_EMTTM_TABLE_NUM)
116 ? (MSR_EMTTM_TABLE_NUM - num_states) + 1
117 : 1;
118 /* Start from the lowest entry but skip Super LFM. */
119 if (pstates.states[pstates.num_states - 1].is_slfm)
120 pstate_idx = pstates.num_states - 2;
121 else
122 pstate_idx = pstates.num_states - 1;
123 for (i = 0; i < MSR_EMTTM_TABLE_NUM; ++i) {
124 if (i >= num_lowest_pstate)
125 --pstate_idx;
126 const sst_state_t *const pstate = &pstates.states[pstate_idx];
127 printk(BIOS_DEBUG, "writing P-State %d: %d, %d, "
128 "%2d, 0x%02x, %d; encoded: 0x%04x\n",
129 pstate_idx, pstate->dynfsb, pstate->nonint,
130 pstate->ratio, pstate->vid, pstate->power,
131 SPEEDSTEP_ENCODE_STATE(*pstate));
132 msr.hi = 0;
133 msr.lo = SPEEDSTEP_ENCODE_STATE(pstates.states[pstate_idx]) &
134 /* Don't set half ratios. */
135 ~SPEEDSTEP_RATIO_NONINT;
136 wrmsr(MSR_EMTTM_CR_TABLE(i), msr);
137 }
138
139 msr = rdmsr(MSR_EMTTM_CR_TABLE(5));
140 msr.lo |= (1 << 31); /* lock tables */
141 wrmsr(MSR_EMTTM_CR_TABLE(5), msr);
142}
143
Michael Büchler70fea012020-09-09 01:04:27 +0200144#define IA32_PECI_CTL 0x5a0
145
Nico Huber68d7c7a2012-10-02 11:46:11 +0200146static void configure_misc(const int eist, const int tm2, const int emttm)
147{
148 msr_t msr;
149
150 const u32 sub_cstates = cpuid_edx(5);
151
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200152 msr = rdmsr(IA32_MISC_ENABLE);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200153 msr.lo |= (1 << 3); /* TM1 enable */
154 if (tm2)
155 msr.lo |= (1 << 13); /* TM2 enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000156 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200157 msr.lo |= (1 << 18); /* MONITOR/MWAIT enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000158
159 msr.lo |= (1 << 10); /* FERR# multiplexing */
160
Nico Huber68d7c7a2012-10-02 11:46:11 +0200161 if (eist)
162 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000163
164 /* Enable C2E */
Lee Leahy26eeb0f2017-03-15 18:08:50 -0700165 if (((sub_cstates >> (2 * 4)) & 0xf) >= 2)
Nico Huber68d7c7a2012-10-02 11:46:11 +0200166 msr.lo |= (1 << 26);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000167
168 /* Enable C4E */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200169 if (((sub_cstates >> (4 * 4)) & 0xf) >= 2) {
170 msr.hi |= (1 << (32 - 32)); // C4E
171 msr.hi |= (1 << (33 - 32)); // Hard C4E
172 }
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000173
Nico Huber68d7c7a2012-10-02 11:46:11 +0200174 /* Enable EMTTM */
175 if (emttm)
176 msr.hi |= (1 << (36 - 32));
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000177
Nico Huber68d7c7a2012-10-02 11:46:11 +0200178 /* Enable turbo mode */
179 if (rdmsr(MSR_FSB_CLOCK_VCC).hi & (1 << (63 - 32)))
180 msr.hi &= ~(1 << (38 - 32));
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000181
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200182 wrmsr(IA32_MISC_ENABLE, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200183
184 if (eist) {
185 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200186 wrmsr(IA32_MISC_ENABLE, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200187 }
Michael Büchler70fea012020-09-09 01:04:27 +0200188
189 /* Enable PECI
190 WARNING: due to Erratum AW67 described in Intel document #318733
191 the microcode must be updated before this MSR is written to. */
192 msr = rdmsr(IA32_PECI_CTL);
193 msr.lo |= 1;
194 wrmsr(IA32_PECI_CTL, msr);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000195}
196
197#define PIC_SENS_CFG 0x1aa
Nico Huber68d7c7a2012-10-02 11:46:11 +0200198static void configure_pic_thermal_sensors(const int tm2, const int quad)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000199{
200 msr_t msr;
201
202 msr = rdmsr(PIC_SENS_CFG);
203
Nico Huber68d7c7a2012-10-02 11:46:11 +0200204 if (quad)
205 msr.lo |= (1 << 31);
206 else
207 msr.lo &= ~(1 << 31);
208 if (tm2)
209 msr.lo |= (1 << 20); /* Enable TM1 if TM2 fails. */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000210 msr.lo |= (1 << 21); // inter-core lock TM1
Nico Huber68d7c7a2012-10-02 11:46:11 +0200211 msr.lo |= (1 << 4); // Enable bypass filter /* What does it do? */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000212
213 wrmsr(PIC_SENS_CFG, msr);
214}
215
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100216static void model_1067x_init(struct device *cpu)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000217{
218 char processor_name[49];
219
Nico Huber68d7c7a2012-10-02 11:46:11 +0200220 /* Gather some information: */
221
222 const struct cpuid_result cpuid1 = cpuid(1);
223
224 /* Read stepping. */
225 const char stepping = cpuid1.eax & 0xf;
226 /* Read number of cores. */
227 const char cores = (cpuid1.ebx >> 16) & 0xf;
228 /* Is this a quad core? */
229 const char quad = cores > 2;
230 /* Is this even a multiprocessor? */
231 const char mp = cores > 1;
232
233 /* Enable EMTTM on uni- and on multi-processors if it's not disabled. */
234 const char emttm = !mp || !(rdmsr(MSR_EXTENDED_CONFIG).lo & 4);
235
236 /* Is enhanced speedstep supported? */
237 const char eist = (cpuid1.ecx & (1 << 7)) &&
238 !(rdmsr(IA32_PLATFORM_ID).lo & (1 << 17));
239 /* Test for TM2 only if EIST is available. */
240 const char tm2 = eist && (cpuid1.ecx & (1 << 8));
241
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000242 /* Print processor name */
243 fill_processor_name(processor_name);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000244 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000245
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000246 /* Configure C States */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200247 configure_c_states(quad);
248
249 /* Configure P States */
250 configure_p_states(stepping, cores);
251
252 /* EMTTM */
253 if (emttm)
254 configure_emttm_tables();
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000255
256 /* Configure Enhanced SpeedStep and Thermal Sensors */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200257 configure_misc(eist, tm2, emttm);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000258
259 /* PIC thermal sensor control */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200260 configure_pic_thermal_sensors(tm2, quad);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000261}
262
263static struct device_operations cpu_dev_ops = {
264 .init = model_1067x_init,
265};
266
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100267static const struct cpu_device_id cpu_table[] = {
Felix Held6a6ac1e2023-02-06 15:19:11 +0100268 { X86_VENDOR_INTEL, 0x10676, CPUID_EXACT_MATCH_MASK },
269 { X86_VENDOR_INTEL, 0x10677, CPUID_EXACT_MATCH_MASK },
270 { X86_VENDOR_INTEL, 0x1067A, CPUID_EXACT_MATCH_MASK },
Felix Held1e781652023-02-08 11:39:16 +0100271 CPU_TABLE_END
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000272};
273
274static const struct cpu_driver driver __cpu_driver = {
275 .ops = &cpu_dev_ops,
276 .id_table = cpu_table,
277};
278
Nico Huber68d7c7a2012-10-02 11:46:11 +0200279struct chip_operations cpu_intel_model_1067x_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900280 .name = "Intel Penryn CPU",
Nico Huber68d7c7a2012-10-02 11:46:11 +0200281};