c43b8debb1f513d42148f2c6e5e44bbd0400bcac
[coreboot.git] / src / cpu / intel / model_6fx / model_6fx_init.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * 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>
33 #include <cpu/x86/mtrr.h>
34 #include <cpu/x86/name.h>
35 #include <usbdebug.h>
36
37 static const uint32_t microcode_updates[] = {
38         #include "microcode-2129-m206f257.h"
39         #include "microcode-2334-m016fbB6.h"
40         #include "microcode-2336-m106fbB6.h"
41         #include "microcode-2337-m806fbB6.h"
42         #include "microcode-2346-m16fda3.h"
43         #include "microcode-2347-m206fda3.h"
44         #include "microcode-2348-m806fda3.h"
45         #include "microcode-2374-m16f6cb.h"
46         #include "microcode-2375-m206f6cc.h"
47         #include "microcode-2376-m46f6cd.h"
48         #include "microcode-2380-m106f768.h"
49         #include "microcode-2381-m406f769.h"
50         #include "microcode-2385-m806fa94.h"
51         #include "microcode-2389-m16f25a.h"
52         #include "microcode-2986-m086fbB8.h"
53         #include "microcode-2990-m046fbB9.h"
54         #include "microcode-2991-m406fbB9.h"
55         /*  Dummy terminator  */
56         0x0, 0x0, 0x0, 0x0,
57         0x0, 0x0, 0x0, 0x0,
58         0x0, 0x0, 0x0, 0x0,
59         0x0, 0x0, 0x0, 0x0,
60 };
61
62 #define IA32_FEATURE_CONTROL 0x003a
63
64 #define CPUID_VMX (1 << 5)
65 #define CPUID_SMX (1 << 6)
66 static void enable_vmx(void)
67 {
68         struct cpuid_result regs;
69         msr_t msr;
70
71         msr = rdmsr(IA32_FEATURE_CONTROL);
72
73         if (msr.lo & (1 << 0)) {
74                 /* VMX locked. If we set it again we get an illegal
75                  * instruction
76                  */
77                 return;
78         }
79
80         regs = cpuid(1);
81         if (regs.ecx & CPUID_VMX) {
82                 msr.lo |= (1 << 2);
83                 if (regs.ecx & CPUID_SMX)
84                         msr.lo |= (1 << 1);
85         }
86
87         wrmsr(IA32_FEATURE_CONTROL, msr);
88
89         msr.lo |= (1 << 0); /* Set lock bit */
90
91         wrmsr(IA32_FEATURE_CONTROL, msr);
92 }
93
94 #define PMG_CST_CONFIG_CONTROL  0xe2
95 #define PMG_IO_BASE_ADDR        0xe3
96 #define PMG_IO_CAPTURE_ADDR     0xe4
97
98 /* MWAIT coordination I/O base address. This must match
99  * the \_PR_.CPU0 PM base address.
100  */
101 #define PMB0_BASE               0x510
102
103 /* PMB1: I/O port that triggers SMI once cores are in the same state.
104  * See CSM Trigger, at PMG_CST_CONFIG_CONTROL[6:4]
105  */
106 #define PMB1_BASE               0x800
107 #define HIGHEST_CLEVEL          3
108 static void configure_c_states(void)
109 {
110         msr_t msr;
111
112         msr = rdmsr(PMG_CST_CONFIG_CONTROL);
113
114         msr.lo |= (1 << 15); // config lock until next reset
115         msr.lo |= (1 << 14); // Deeper Sleep
116         msr.lo |= (1 << 10); // Enable IO MWAIT redirection
117         msr.lo &= ~(1 << 9); // Issue a  single stop grant cycle upon stpclk
118         msr.lo |= (1 << 3); // Dynamic L2
119
120         /* Number of supported C-States */
121         msr.lo &= ~7;
122         msr.lo |= HIGHEST_CLEVEL; // support at most C3
123
124         wrmsr(PMG_CST_CONFIG_CONTROL, msr);
125
126         /* Set Processor MWAIT IO BASE */
127         msr.hi = 0;
128         msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff) << 16);
129         wrmsr(PMG_IO_BASE_ADDR, msr);
130
131         /* Set C_LVL controls and IO Capture Address */
132         msr.hi = 0;
133         msr.lo = (PMB0_BASE + 4) | ((HIGHEST_CLEVEL - 2) << 16); // -2 because LVL0+1 aren't counted
134         wrmsr(PMG_IO_CAPTURE_ADDR, msr);
135 }
136
137 #define IA32_MISC_ENABLE        0x1a0
138 static void configure_misc(void)
139 {
140         msr_t msr;
141
142         msr = rdmsr(IA32_MISC_ENABLE);
143         msr.lo |= (1 << 3);     /* TM1 enable */
144         msr.lo |= (1 << 13);    /* TM2 enable */
145         msr.lo |= (1 << 17);    /* Bidirectional PROCHOT# */
146
147         msr.lo |= (1 << 10);    /* FERR# multiplexing */
148
149         // TODO: Only if  IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
150         msr.lo |= (1 << 16);    /* Enhanced SpeedStep Enable */
151
152         /* Enable C2E */
153         msr.lo |= (1 << 26);
154
155         /* Enable C4E */
156         /* TODO This should only be done on mobile CPUs, see cpuid 5 */
157         msr.hi |= (1 << (32 - 32)); // C4E
158         msr.hi |= (1 << (33 - 32)); // Hard C4E
159
160         /* Enable EMTTM. */
161         /* NOTE: We leave the EMTTM_CR_TABLE0-5 at their default values */
162         msr.hi |= (1 << (36 - 32));
163
164         wrmsr(IA32_MISC_ENABLE, msr);
165
166         msr.lo |= (1 << 20);    /* Lock Enhanced SpeedStep Enable */
167         wrmsr(IA32_MISC_ENABLE, msr);
168 }
169
170 #define PIC_SENS_CFG    0x1aa
171 static void configure_pic_thermal_sensors(void)
172 {
173         msr_t msr;
174
175         msr = rdmsr(PIC_SENS_CFG);
176
177         msr.lo |= (1 << 21); // inter-core lock TM1
178         msr.lo |= (1 << 4); // Enable bypass filter
179
180         wrmsr(PIC_SENS_CFG, msr);
181 }
182
183 #if CONFIG_USBDEBUG
184 static unsigned ehci_debug_addr;
185 #endif
186
187 static void model_6fx_init(device_t cpu)
188 {
189         char processor_name[49];
190
191         /* Turn on caching if we haven't already */
192         x86_enable_cache();
193
194         /* Update the microcode */
195         intel_update_microcode(microcode_updates);
196
197         /* Print processor name */
198         fill_processor_name(processor_name);
199         printk(BIOS_INFO, "CPU: %s.\n", processor_name);
200
201 #if CONFIG_USBDEBUG
202         // Is this caution really needed?
203         if(!ehci_debug_addr)
204                 ehci_debug_addr = get_ehci_debug();
205         set_ehci_debug(0);
206 #endif
207
208         /* Setup MTRRs */
209         x86_setup_mtrrs(36);
210         x86_mtrr_check();
211
212         /* Setup Page Attribute Tables (PAT) */
213         // TODO set up PAT
214
215 #if CONFIG_USBDEBUG
216         set_ehci_debug(ehci_debug_addr);
217 #endif
218
219         /* Enable the local cpu apics */
220         setup_lapic();
221
222         /* Enable virtualization */
223         enable_vmx();
224
225         /* Configure C States */
226         configure_c_states();
227
228         /* Configure Enhanced SpeedStep and Thermal Sensors */
229         configure_misc();
230
231         /* PIC thermal sensor control */
232         configure_pic_thermal_sensors();
233
234         /* Start up my cpu siblings */
235         intel_sibling_init(cpu);
236 }
237
238 static struct device_operations cpu_dev_ops = {
239         .init     = model_6fx_init,
240 };
241
242 static struct cpu_device_id cpu_table[] = {
243         { X86_VENDOR_INTEL, 0x06f0 }, /* Intel Core 2 Solo/Core Duo */
244         { X86_VENDOR_INTEL, 0x06f2 }, /* Intel Core 2 Solo/Core Duo */
245         { X86_VENDOR_INTEL, 0x06f6 }, /* Intel Core 2 Solo/Core Duo */
246         { X86_VENDOR_INTEL, 0x06f7 }, /* Intel Core 2 Solo/Core Duo */
247         { X86_VENDOR_INTEL, 0x06fa }, /* Intel Core 2 Solo/Core Duo */
248         { X86_VENDOR_INTEL, 0x06fb }, /* Intel Core 2 Solo/Core Duo */
249         { X86_VENDOR_INTEL, 0x06fd }, /* Intel Core 2 Solo/Core Duo */
250         { X86_VENDOR_INTEL, 0x10676 }, /* Core2 Duo E8200 */
251         { 0, 0 },
252 };
253
254 static const struct cpu_driver driver __cpu_driver = {
255         .ops      = &cpu_dev_ops,
256         .id_table = cpu_table,
257 };
258