blob: 94adc8c3272f77b6ebe80aaf448fa1e0cc46628e [file] [log] [blame]
Thomas Jourdan1a692d82009-07-01 17:01:17 +00001/*
2 * This file is part of the coreboot project.
Stefan Reinauer14e22772010-04-27 06:56:47 +00003 *
Thomas Jourdan1a692d82009-07-01 17:01:17 +00004 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; version 2 of
7 * the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Thomas Jourdan1a692d82009-07-01 17:01:17 +000013 */
14
15#include <console/console.h>
16#include <device/device.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000017#include <cpu/cpu.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000018#include <cpu/x86/msr.h>
Arthur Heymans6336d4c2018-01-25 21:38:25 +010019#include <cpu/x86/mp.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000020#include <cpu/x86/lapic.h>
Stefan Reinauer2a27b202010-12-11 22:14:44 +000021#include <cpu/intel/speedstep.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000022#include <cpu/x86/cache.h>
Uwe Hermannaac8f662010-09-29 09:54:16 +000023#include <cpu/x86/name.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030024#include <cpu/intel/smm_reloc.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060025#include <cpu/intel/common/common.h>
Nico Huber68d7c7a2012-10-02 11:46:11 +020026#include "chip.h"
27
Thomas Jourdan1a692d82009-07-01 17:01:17 +000028static void init_timer(void)
29{
Elyes HAOUASd6e96862016-08-21 10:12:15 +020030 /* Set the APIC timer to no interrupts and periodic mode */
Lee Leahy9d62e7e2017-03-15 17:40:50 -070031 lapic_write(LAPIC_LVTT, (1 << 17) | (1 << 16) | (0 << 12) | (0 << 0));
Thomas Jourdan1a692d82009-07-01 17:01:17 +000032
33 /* Set the divider to 1, no divider */
34 lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1);
35
36 /* Set the initial counter to 0xffffffff */
37 lapic_write(LAPIC_TMICT, 0xffffffff);
38}
39
Nico Huber68d7c7a2012-10-02 11:46:11 +020040#define MSR_BBL_CR_CTL3 0x11e
Thomas Jourdan1a692d82009-07-01 17:01:17 +000041
Nico Huber68d7c7a2012-10-02 11:46:11 +020042static void configure_c_states(const int quad)
Thomas Jourdan1a692d82009-07-01 17:01:17 +000043{
44 msr_t msr;
45
Nico Huber68d7c7a2012-10-02 11:46:11 +020046 /* Find pointer to CPU configuration. */
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110047 const struct device *lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
Nico Huber68d7c7a2012-10-02 11:46:11 +020048 const struct cpu_intel_model_1067x_config *const conf =
49 (lapic && lapic->chip_info) ? lapic->chip_info : NULL;
50
51 /* Is C5 requested and supported? */
52 const int c5 = conf && conf->c5 &&
53 (rdmsr(MSR_BBL_CR_CTL3).lo & (3 << 30)) &&
54 !(rdmsr(MSR_FSB_FREQ).lo & (1 << 31));
55 /* Is C6 requested and supported? */
56 const int c6 = conf && conf->c6 &&
57 ((cpuid_edx(5) >> (6 * 4)) & 0xf) && c5;
58
59 const int cst_range = (c6 ? 6 : (c5 ? 5 : 4)) - 2; /* zero means lvl2 */
60
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020061 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000062 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
Nico Huber68d7c7a2012-10-02 11:46:11 +020063 msr.lo |= (1 << 8);
Lee Leahy26eeb0f2017-03-15 18:08:50 -070064 if (quad)
Nico Huber68d7c7a2012-10-02 11:46:11 +020065 msr.lo = (msr.lo & ~(7 << 0)) | (4 << 0);
Nico Huber68d7c7a2012-10-02 11:46:11 +020066 if (c5) {
67 msr.lo &= ~(1 << 13);
68 msr.lo &= ~(7 << 0);
69 msr.lo |= (1 << 3); /* Enable dynamic L2. */
70 msr.lo |= (1 << 14); /* Enable deeper sleep */
71 }
72 /* Next two fields seem to be mutually exclusive: */
73 msr.lo &= ~(7 << 4);
74 msr.lo |= (1 << 10); /* Enable IO MWAIT redirection. */
75 if (c6)
76 msr.lo |= (1 << 25);
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +020077 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000078
79 /* Set Processor MWAIT IO BASE */
80 msr.hi = 0;
Lee Leahycdc50482017-03-15 18:26:18 -070081 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff)
82 << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010083 wrmsr(MSR_PMG_IO_BASE_ADDR, msr);
Thomas Jourdan1a692d82009-07-01 17:01:17 +000084
85 /* Set IO Capture Address */
86 msr.hi = 0;
Nico Huber68d7c7a2012-10-02 11:46:11 +020087 msr.lo = ((PMB0_BASE + 4) & 0xffff) | ((cst_range & 0xffff) << 16);
Patrick Georgi644e83b2013-02-09 15:35:30 +010088 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +020089
90 if (c5) {
91 msr = rdmsr(MSR_BBL_CR_CTL3);
92 msr.lo &= ~(7 << 25);
93 msr.lo |= (2 << 25);
94 msr.lo &= ~(3 << 30);
95 msr.lo |= (1 << 30);
96 wrmsr(MSR_BBL_CR_CTL3, msr);
97 }
Thomas Jourdan1a692d82009-07-01 17:01:17 +000098}
99
Nico Huber68d7c7a2012-10-02 11:46:11 +0200100static void configure_p_states(const char stepping, const char cores)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000101{
102 msr_t msr;
103
Nico Huber68d7c7a2012-10-02 11:46:11 +0200104 /* Find pointer to CPU configuration. */
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100105 const struct device *lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200106 struct cpu_intel_model_1067x_config *const conf =
107 (lapic && lapic->chip_info) ? lapic->chip_info : NULL;
108
109 msr = rdmsr(MSR_EXTENDED_CONFIG);
Patrick Georgif17c58b2014-08-09 20:48:12 +0200110 /* Super LFM supported? */
111 if (conf && conf->slfm && (msr.lo & (1 << 27)))
Nico Huber68d7c7a2012-10-02 11:46:11 +0200112 msr.lo |= (1 << 28); /* Enable Super LFM. */
113 wrmsr(MSR_EXTENDED_CONFIG, msr);
114
115 if (rdmsr(MSR_FSB_CLOCK_VCC).hi & (1 << (63 - 32))) {
116 /* Turbo supported? */
117 if ((stepping == 0xa) && (cores < 4)) {
118 msr = rdmsr(MSR_FSB_FREQ);
119 msr.lo |= (1 << 3); /* Enable hysteresis. */
120 wrmsr(MSR_FSB_FREQ, msr);
121 }
122 msr = rdmsr(IA32_PERF_CTL);
123 msr.hi &= ~(1 << (32 - 32)); /* Clear turbo disable. */
124 wrmsr(IA32_PERF_CTL, msr);
125 }
126
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200127 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200128 msr.lo &= ~(1 << 11); /* Enable hw coordination. */
129 msr.lo |= (1 << 15); /* Lock config until next reset. */
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200130 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200131}
132
133#define MSR_EMTTM_CR_TABLE(x) (0xa8 + (x))
134#define MSR_EMTTM_TABLE_NUM 6
135static void configure_emttm_tables(void)
136{
137 int i;
138 int num_states, pstate_idx;
139 msr_t msr;
140 sst_table_t pstates;
141
142 /* Gather p-state information. */
143 speedstep_gen_pstates(&pstates);
144
145 /* Never turbo mode or Super LFM. */
146 num_states = pstates.num_states;
147 if (pstates.states[0].is_turbo)
148 --num_states;
149 if (pstates.states[pstates.num_states - 1].is_slfm)
150 --num_states;
151 /* Repeat lowest p-state if we haven't enough states. */
152 const int num_lowest_pstate =
153 (num_states < MSR_EMTTM_TABLE_NUM)
154 ? (MSR_EMTTM_TABLE_NUM - num_states) + 1
155 : 1;
156 /* Start from the lowest entry but skip Super LFM. */
157 if (pstates.states[pstates.num_states - 1].is_slfm)
158 pstate_idx = pstates.num_states - 2;
159 else
160 pstate_idx = pstates.num_states - 1;
161 for (i = 0; i < MSR_EMTTM_TABLE_NUM; ++i) {
162 if (i >= num_lowest_pstate)
163 --pstate_idx;
164 const sst_state_t *const pstate = &pstates.states[pstate_idx];
165 printk(BIOS_DEBUG, "writing P-State %d: %d, %d, "
166 "%2d, 0x%02x, %d; encoded: 0x%04x\n",
167 pstate_idx, pstate->dynfsb, pstate->nonint,
168 pstate->ratio, pstate->vid, pstate->power,
169 SPEEDSTEP_ENCODE_STATE(*pstate));
170 msr.hi = 0;
171 msr.lo = SPEEDSTEP_ENCODE_STATE(pstates.states[pstate_idx]) &
172 /* Don't set half ratios. */
173 ~SPEEDSTEP_RATIO_NONINT;
174 wrmsr(MSR_EMTTM_CR_TABLE(i), msr);
175 }
176
177 msr = rdmsr(MSR_EMTTM_CR_TABLE(5));
178 msr.lo |= (1 << 31); /* lock tables */
179 wrmsr(MSR_EMTTM_CR_TABLE(5), msr);
180}
181
182static void configure_misc(const int eist, const int tm2, const int emttm)
183{
184 msr_t msr;
185
186 const u32 sub_cstates = cpuid_edx(5);
187
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200188 msr = rdmsr(IA32_MISC_ENABLE);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200189 msr.lo |= (1 << 3); /* TM1 enable */
190 if (tm2)
191 msr.lo |= (1 << 13); /* TM2 enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000192 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200193 msr.lo |= (1 << 18); /* MONITOR/MWAIT enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000194
195 msr.lo |= (1 << 10); /* FERR# multiplexing */
196
Nico Huber68d7c7a2012-10-02 11:46:11 +0200197 if (eist)
198 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000199
200 /* Enable C2E */
Lee Leahy26eeb0f2017-03-15 18:08:50 -0700201 if (((sub_cstates >> (2 * 4)) & 0xf) >= 2)
Nico Huber68d7c7a2012-10-02 11:46:11 +0200202 msr.lo |= (1 << 26);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000203
204 /* Enable C4E */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200205 if (((sub_cstates >> (4 * 4)) & 0xf) >= 2) {
206 msr.hi |= (1 << (32 - 32)); // C4E
207 msr.hi |= (1 << (33 - 32)); // Hard C4E
208 }
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000209
Nico Huber68d7c7a2012-10-02 11:46:11 +0200210 /* Enable EMTTM */
211 if (emttm)
212 msr.hi |= (1 << (36 - 32));
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000213
Nico Huber68d7c7a2012-10-02 11:46:11 +0200214 /* Enable turbo mode */
215 if (rdmsr(MSR_FSB_CLOCK_VCC).hi & (1 << (63 - 32)))
216 msr.hi &= ~(1 << (38 - 32));
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000217
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200218 wrmsr(IA32_MISC_ENABLE, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200219
220 if (eist) {
221 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200222 wrmsr(IA32_MISC_ENABLE, msr);
Nico Huber68d7c7a2012-10-02 11:46:11 +0200223 }
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000224}
225
226#define PIC_SENS_CFG 0x1aa
Nico Huber68d7c7a2012-10-02 11:46:11 +0200227static void configure_pic_thermal_sensors(const int tm2, const int quad)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000228{
229 msr_t msr;
230
231 msr = rdmsr(PIC_SENS_CFG);
232
Nico Huber68d7c7a2012-10-02 11:46:11 +0200233 if (quad)
234 msr.lo |= (1 << 31);
235 else
236 msr.lo &= ~(1 << 31);
237 if (tm2)
238 msr.lo |= (1 << 20); /* Enable TM1 if TM2 fails. */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000239 msr.lo |= (1 << 21); // inter-core lock TM1
Nico Huber68d7c7a2012-10-02 11:46:11 +0200240 msr.lo |= (1 << 4); // Enable bypass filter /* What does it do? */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000241
242 wrmsr(PIC_SENS_CFG, msr);
243}
244
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100245static void model_1067x_init(struct device *cpu)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000246{
247 char processor_name[49];
248
Nico Huber68d7c7a2012-10-02 11:46:11 +0200249
250 /* Gather some information: */
251
252 const struct cpuid_result cpuid1 = cpuid(1);
253
254 /* Read stepping. */
255 const char stepping = cpuid1.eax & 0xf;
256 /* Read number of cores. */
257 const char cores = (cpuid1.ebx >> 16) & 0xf;
258 /* Is this a quad core? */
259 const char quad = cores > 2;
260 /* Is this even a multiprocessor? */
261 const char mp = cores > 1;
262
263 /* Enable EMTTM on uni- and on multi-processors if it's not disabled. */
264 const char emttm = !mp || !(rdmsr(MSR_EXTENDED_CONFIG).lo & 4);
265
266 /* Is enhanced speedstep supported? */
267 const char eist = (cpuid1.ecx & (1 << 7)) &&
268 !(rdmsr(IA32_PLATFORM_ID).lo & (1 << 17));
269 /* Test for TM2 only if EIST is available. */
270 const char tm2 = eist && (cpuid1.ecx & (1 << 8));
271
272
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000273 /* Turn on caching if we haven't already */
274 x86_enable_cache();
275
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000276 /* Print processor name */
277 fill_processor_name(processor_name);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000278 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000279
Elyes HAOUASd6e96862016-08-21 10:12:15 +0200280 /* Enable the local CPU APICs */
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000281 setup_lapic();
282
283 /* Initialize the APIC timer */
284 init_timer();
285
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000286 /* Configure C States */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200287 configure_c_states(quad);
288
289 /* Configure P States */
290 configure_p_states(stepping, cores);
291
292 /* EMTTM */
293 if (emttm)
294 configure_emttm_tables();
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000295
296 /* Configure Enhanced SpeedStep and Thermal Sensors */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200297 configure_misc(eist, tm2, emttm);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000298
299 /* PIC thermal sensor control */
Nico Huber68d7c7a2012-10-02 11:46:11 +0200300 configure_pic_thermal_sensors(tm2, quad);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000301}
302
303static struct device_operations cpu_dev_ops = {
304 .init = model_1067x_init,
305};
306
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100307static const struct cpu_device_id cpu_table[] = {
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000308 { X86_VENDOR_INTEL, 0x10676 }, /* Intel Core 2 Solo/Core Duo */
Stefan Reinauerc104cb02010-10-18 00:21:39 +0000309 { X86_VENDOR_INTEL, 0x10677 },
310 { X86_VENDOR_INTEL, 0x1067A },
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000311 { 0, 0 },
312};
313
314static const struct cpu_driver driver __cpu_driver = {
315 .ops = &cpu_dev_ops,
316 .id_table = cpu_table,
317};
318
Nico Huber68d7c7a2012-10-02 11:46:11 +0200319struct chip_operations cpu_intel_model_1067x_ops = {
320 CHIP_NAME("Intel Penryn CPU")
321};