4a621df31ab4e301ef5d96bda289c4790d41b043
[coreboot.git] / src / cpu / intel / model_106cx / model_106cx_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 the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <string.h>
24 #include <cpu/cpu.h>
25 #include <cpu/x86/mtrr.h>
26 #include <cpu/x86/msr.h>
27 #include <cpu/x86/lapic.h>
28 #include <cpu/intel/microcode.h>
29 #include <cpu/intel/hyperthreading.h>
30 #include <cpu/x86/cache.h>
31 #include <cpu/x86/mtrr.h>
32 #include <cpu/x86/name.h>
33 #include <usbdebug.h>
34
35 static const uint32_t microcode_updates[] = {
36         #include "microcode-2963-M01106C2217.h"
37         #include "microcode-2964-M04106C2218.h"
38         #include "microcode-2965-M08106C2219.h"
39         #include "microcode-3101-M04106CA107.h"
40         #include "microcode-3104-M08106CA107.h"
41         #include "microcode-3107-M10106CA107.h"
42
43         /*  Dummy terminator  */
44         0x0, 0x0, 0x0, 0x0,
45         0x0, 0x0, 0x0, 0x0,
46         0x0, 0x0, 0x0, 0x0,
47         0x0, 0x0, 0x0, 0x0,
48 };
49
50 #define IA32_FEATURE_CONTROL 0x003a
51
52 #define CPUID_VMX (1 << 5)
53 #define CPUID_SMX (1 << 6)
54 static void enable_vmx(void)
55 {
56         struct cpuid_result regs;
57         msr_t msr;
58
59         msr = rdmsr(IA32_FEATURE_CONTROL);
60
61         if (msr.lo & (1 << 0)) {
62                 /* VMX locked. If we set it again we get an illegal
63                  * instruction
64                  */
65                 return;
66         }
67
68         regs = cpuid(1);
69         if (regs.ecx & CPUID_VMX) {
70                 msr.lo |= (1 << 2);
71                 if (regs.ecx & CPUID_SMX)
72                         msr.lo |= (1 << 1);
73         }
74
75         wrmsr(IA32_FEATURE_CONTROL, msr);
76
77         msr.lo |= (1 << 0); /* Set lock bit */
78
79         wrmsr(IA32_FEATURE_CONTROL, msr);
80 }
81
82 #define PMG_CST_CONFIG_CONTROL  0xe2
83 #define PMG_IO_BASE_ADDR        0xe3
84 #define PMG_IO_CAPTURE_ADDR     0xe4
85 #define PMB0 0x510 /* analogous to P_BLK in cpu.asl */
86 #define PMB1 0x0        /* IO port that triggers SMI once cores are in the same state.
87                         See CSM Trigger, at PMG_CST_CONFIG_CONTROL[6:4] */
88 #define HIGHEST_CLEVEL          3
89 static void configure_c_states(void)
90 {
91         msr_t msr;
92
93         msr = rdmsr(PMG_CST_CONFIG_CONTROL);
94         msr.lo |= (1 << 15); // Lock configuration
95         msr.lo |= (1 << 10); // redirect IO-based CState transition requests to MWAIT
96         msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
97         msr.lo &= ~7; msr.lo |= HIGHEST_CLEVEL; // support at most C3
98         // TODO Do we want Deep C4 and  Dynamic L2 shrinking?
99         wrmsr(PMG_CST_CONFIG_CONTROL, msr);
100
101         // set P_BLK address
102         msr = rdmsr(PMG_IO_BASE_ADDR);
103         msr.lo = (PMB0 + 4) | (PMB1 << 16);
104         wrmsr(PMG_IO_BASE_ADDR, msr);
105
106         // set C_LVL controls
107         msr = rdmsr(PMG_IO_CAPTURE_ADDR);
108         msr.lo = (PMB0 + 4) | ((HIGHEST_CLEVEL - 2) << 16); // -2 because LVL0+1 aren't counted
109         wrmsr(PMG_IO_CAPTURE_ADDR, msr);
110 }
111
112 #define IA32_MISC_ENABLE        0x1a0
113 static void configure_misc(void)
114 {
115         msr_t msr;
116
117         msr = rdmsr(IA32_MISC_ENABLE);
118         msr.lo |= (1 << 3);     /* TM1 enable */
119         msr.lo |= (1 << 13);    /* TM2 enable */
120         msr.lo |= (1 << 17);    /* Bidirectional PROCHOT# */
121
122         msr.lo |= (1 << 10);    /* FERR# multiplexing */
123
124         // TODO: Only if  IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
125         msr.lo |= (1 << 16);    /* Enhanced SpeedStep Enable */
126
127         // TODO Do we want Deep C4 and  Dynamic L2 shrinking?
128         wrmsr(IA32_MISC_ENABLE, msr);
129
130         msr.lo |= (1 << 20);    /* Lock Enhanced SpeedStep Enable */
131         wrmsr(IA32_MISC_ENABLE, msr);
132 }
133
134 #if CONFIG_USBDEBUG
135 static unsigned ehci_debug_addr;
136 #endif
137
138 static void model_106cx_init(device_t cpu)
139 {
140         char processor_name[49];
141
142         /* Turn on caching if we haven't already */
143         x86_enable_cache();
144
145         /* Update the microcode */
146         intel_update_microcode(microcode_updates);
147
148         /* Print processor name */
149         fill_processor_name(processor_name);
150         printk(BIOS_INFO, "CPU: %s.\n", processor_name);
151
152 #if CONFIG_USBDEBUG
153         // Is this caution really needed?
154         if(!ehci_debug_addr)
155                 ehci_debug_addr = get_ehci_debug();
156         set_ehci_debug(0);
157 #endif
158
159         /* Setup MTRRs */
160         x86_setup_mtrrs(32);
161         x86_mtrr_check();
162
163 #if CONFIG_USBDEBUG
164         set_ehci_debug(ehci_debug_addr);
165 #endif
166
167         /* Enable the local cpu apics */
168         setup_lapic();
169
170         /* Enable virtualization */
171         enable_vmx();
172
173         /* Configure C States */
174         configure_c_states();
175
176         /* Configure Enhanced SpeedStep and Thermal Sensors */
177         configure_misc();
178
179         /* TODO: PIC thermal sensor control */
180
181         /* Start up my cpu siblings */
182         intel_sibling_init(cpu);
183 }
184
185 static struct device_operations cpu_dev_ops = {
186         .init     = model_106cx_init,
187 };
188
189 static struct cpu_device_id cpu_table[] = {
190         { X86_VENDOR_INTEL, 0x106c0 }, /* Intel Atom 230 */
191         { 0, 0 },
192 };
193
194 static const struct cpu_driver driver __cpu_driver = {
195         .ops      = &cpu_dev_ops,
196         .id_table = cpu_table,
197 };
198