blob: 46a54e597d0d925249ccfb296274062c57580bc9 [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 * Copyright (C) 2007-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <console/console.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <string.h>
26#include <cpu/cpu.h>
27#include <cpu/x86/mtrr.h>
28#include <cpu/x86/msr.h>
29#include <cpu/x86/lapic.h>
30#include <cpu/intel/microcode.h>
31#include <cpu/intel/hyperthreading.h>
32#include <cpu/x86/cache.h>
Uwe Hermannaac8f662010-09-29 09:54:16 +000033#include <cpu/x86/name.h>
Thomas Jourdan1a692d82009-07-01 17:01:17 +000034
35static const uint32_t microcode_updates[] = {
Stefan Reinauerc104cb02010-10-18 00:21:39 +000036 #include "microcode-2618-m441067AA07.h"
37 #include "microcode-2626-m1010677705.h"
38 #include "microcode-2498-m101067660C.h"
39 #include "microcode-2497-m041067660C.h"
40 #include "microcode-2499-m401067660C.h"
41 #include "microcode-2617-m111067AA07.h"
42 #include "microcode-2619-mA01067AA07.h"
43 #include "microcode-2623-m011067660C.h"
44 #include "microcode-2501-m801067660C.h"
45
Thomas Jourdan1a692d82009-07-01 17:01:17 +000046 /* Dummy terminator */
47 0x0, 0x0, 0x0, 0x0,
48 0x0, 0x0, 0x0, 0x0,
49 0x0, 0x0, 0x0, 0x0,
50 0x0, 0x0, 0x0, 0x0,
51};
52
Thomas Jourdan1a692d82009-07-01 17:01:17 +000053static void init_timer(void)
54{
55 /* Set the apic timer to no interrupts and periodic mode */
56 lapic_write(LAPIC_LVTT, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0));
57
58 /* Set the divider to 1, no divider */
59 lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1);
60
61 /* Set the initial counter to 0xffffffff */
62 lapic_write(LAPIC_TMICT, 0xffffffff);
63}
64
Thomas Jourdan1a692d82009-07-01 17:01:17 +000065#define IA32_FEATURE_CONTROL 0x003a
66
67#define CPUID_VMX (1 << 5)
68#define CPUID_SMX (1 << 6)
69static void enable_vmx(void)
70{
71 struct cpuid_result regs;
72 msr_t msr;
73
74 msr = rdmsr(IA32_FEATURE_CONTROL);
75
76 if (msr.lo & (1 << 0)) {
77 /* VMX locked. If we set it again we get an illegal
78 * instruction
79 */
80 return;
81 }
82
83 regs = cpuid(1);
84 if (regs.ecx & CPUID_VMX) {
85 msr.lo |= (1 << 2);
86 if (regs.ecx & CPUID_SMX)
87 msr.lo |= (1 << 1);
88 }
89
90 wrmsr(IA32_FEATURE_CONTROL, msr);
91
92 msr.lo |= (1 << 0); /* Set lock bit */
93
94 wrmsr(IA32_FEATURE_CONTROL, msr);
95}
96
97#define PMG_CST_CONFIG_CONTROL 0xe2
98#define PMG_IO_BASE_ADDR 0xe3
99#define PMG_IO_CAPTURE_ADDR 0xe4
100
101#define PMB0_BASE 0x580
102#define PMB1_BASE 0x800
103#define CST_RANGE 2
104static void configure_c_states(void)
105{
106 msr_t msr;
107
108 msr = rdmsr(PMG_CST_CONFIG_CONTROL);
109
110 msr.lo |= (1 << 15); // config lock until next reset
111 msr.lo |= (1 << 14); // Deeper Sleep
112 msr.lo |= (1 << 10); // Enable IO MWAIT redirection
113 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
114 msr.lo |= (1 << 3); // Dynamic L2
115
116 wrmsr(PMG_CST_CONFIG_CONTROL, msr);
117
118 /* Set Processor MWAIT IO BASE */
119 msr.hi = 0;
120 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff) << 16);
121 wrmsr(PMG_IO_BASE_ADDR, msr);
122
123 /* Set IO Capture Address */
124 msr.hi = 0;
125 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (( CST_RANGE & 0xffff) << 16);
126 wrmsr(PMG_IO_CAPTURE_ADDR, msr);
127}
128
129#define IA32_MISC_ENABLE 0x1a0
130static void configure_misc(void)
131{
132 msr_t msr;
133
134 msr = rdmsr(IA32_MISC_ENABLE);
135 msr.lo |= (1 << 3); /* TM1 enable */
136 msr.lo |= (1 << 13); /* TM2 enable */
137 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
138
139 msr.lo |= (1 << 10); /* FERR# multiplexing */
140
141 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
142 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
143
144 /* Enable C2E */
145 msr.lo |= (1 << 26);
146
147 /* Enable C4E */
148 /* TODO This should only be done on mobile CPUs, see cpuid 5 */
149 msr.hi |= (1 << (32 - 32)); // C4E
150 msr.hi |= (1 << (33 - 32)); // Hard C4E
151
152 /* Enable EMTTM. */
153 /* NOTE: We leave the EMTTM_CR_TABLE0-5 at their default values */
154 msr.hi |= (1 << (36 - 32));
155
156 wrmsr(IA32_MISC_ENABLE, msr);
157
158 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
159 wrmsr(IA32_MISC_ENABLE, msr);
160}
161
162#define PIC_SENS_CFG 0x1aa
163static void configure_pic_thermal_sensors(void)
164{
165 msr_t msr;
166
167 msr = rdmsr(PIC_SENS_CFG);
168
169 msr.lo |= (1 << 21); // inter-core lock TM1
170 msr.lo |= (1 << 4); // Enable bypass filter
171
172 wrmsr(PIC_SENS_CFG, msr);
173}
174
Stefan Reinauer7e00a442010-05-25 17:09:05 +0000175#if CONFIG_USBDEBUG
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000176static unsigned ehci_debug_addr;
177#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000178
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000179static void model_1067x_init(device_t cpu)
180{
181 char processor_name[49];
182
183 /* Turn on caching if we haven't already */
184 x86_enable_cache();
185
186 /* Update the microcode */
187 intel_update_microcode(microcode_updates);
188
189 /* Print processor name */
190 fill_processor_name(processor_name);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000191 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000192
Stefan Reinauer7e00a442010-05-25 17:09:05 +0000193#if CONFIG_USBDEBUG
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000194 // Is this caution really needed?
Stefan Reinauer14e22772010-04-27 06:56:47 +0000195 if(!ehci_debug_addr)
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000196 ehci_debug_addr = get_ehci_debug();
197 set_ehci_debug(0);
198#endif
199
200 /* Setup MTRRs */
201 x86_setup_mtrrs(36);
202 x86_mtrr_check();
203
Stefan Reinauer7e00a442010-05-25 17:09:05 +0000204#if CONFIG_USBDEBUG
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000205 set_ehci_debug(ehci_debug_addr);
206#endif
207
208 /* Enable the local cpu apics */
209 setup_lapic();
210
211 /* Initialize the APIC timer */
212 init_timer();
213
214 /* Enable virtualization */
215 enable_vmx();
216
217 /* Configure C States */
218 configure_c_states();
219
220 /* Configure Enhanced SpeedStep and Thermal Sensors */
221 configure_misc();
222
223 /* PIC thermal sensor control */
224 configure_pic_thermal_sensors();
225
226 /* Start up my cpu siblings */
227 intel_sibling_init(cpu);
228}
229
230static struct device_operations cpu_dev_ops = {
231 .init = model_1067x_init,
232};
233
234static struct cpu_device_id cpu_table[] = {
235 { X86_VENDOR_INTEL, 0x10676 }, /* Intel Core 2 Solo/Core Duo */
Stefan Reinauerc104cb02010-10-18 00:21:39 +0000236 { X86_VENDOR_INTEL, 0x10677 },
237 { X86_VENDOR_INTEL, 0x1067A },
Thomas Jourdan1a692d82009-07-01 17:01:17 +0000238 { 0, 0 },
239};
240
241static const struct cpu_driver driver __cpu_driver = {
242 .ops = &cpu_dev_ops,
243 .id_table = cpu_table,
244};
245