2 * This file is part of the coreboot project.
4 * Copyright (C) 2007-2009 coresystems GmbH
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.
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.
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
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.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 <usbdebug_direct.h>
34 static const uint32_t microcode_updates[] = {
35 /* Dummy terminator */
42 static inline void strcpy(char *dst, char *src)
44 while (*src) *dst++ = *src++;
47 static void fill_processor_name(char *processor_name)
49 struct cpuid_result regs;
50 char temp_processor_name[49];
51 char *processor_name_start;
52 unsigned int *name_as_ints = (unsigned int *)temp_processor_name;
56 regs = cpuid(0x80000002 + i);
57 name_as_ints[i*4 + 0] = regs.eax;
58 name_as_ints[i*4 + 1] = regs.ebx;
59 name_as_ints[i*4 + 2] = regs.ecx;
60 name_as_ints[i*4 + 3] = regs.edx;
63 temp_processor_name[48] = 0;
65 /* Skip leading spaces */
66 processor_name_start = temp_processor_name;
67 while (*processor_name_start == ' ')
68 processor_name_start++;
70 memset(processor_name, 0, 49);
71 strcpy(processor_name, processor_name_start);
74 #define IA32_FEATURE_CONTROL 0x003a
76 #define CPUID_VMX (1 << 5)
77 #define CPUID_SMX (1 << 6)
78 static void enable_vmx(void)
80 struct cpuid_result regs;
83 msr = rdmsr(IA32_FEATURE_CONTROL);
85 if (msr.lo & (1 << 0)) {
86 /* VMX locked. If we set it again we get an illegal
93 if (regs.ecx & CPUID_VMX) {
95 if (regs.ecx & CPUID_SMX)
99 wrmsr(IA32_FEATURE_CONTROL, msr);
101 msr.lo |= (1 << 0); /* Set lock bit */
103 wrmsr(IA32_FEATURE_CONTROL, msr);
106 #define PMG_CST_CONFIG_CONTROL 0xe2
107 #define PMG_IO_BASE_ADDR 0xe3
108 #define PMG_IO_CAPTURE_ADDR 0xe4
109 #define PMB0 0x510 /* analogous to P_BLK in cpu.asl */
110 #define PMB1 0x0 /* IO port that triggers SMI once cores are in the same state.
111 See CSM Trigger, at PMG_CST_CONFIG_CONTROL[6:4] */
112 #define HIGHEST_CLEVEL 3
113 static void configure_c_states(void)
117 msr = rdmsr(PMG_CST_CONFIG_CONTROL);
118 msr.lo |= (1 << 15); // Lock configuration
119 msr.lo |= (1 << 10); // redirect IO-based CState transition requests to MWAIT
120 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
121 msr.lo &= ~7; msr.lo |= HIGHEST_CLEVEL; // support at most C3
122 // TODO Do we want Deep C4 and Dynamic L2 shrinking?
123 wrmsr(PMG_CST_CONFIG_CONTROL, msr);
126 msr = rdmsr(PMG_IO_BASE_ADDR);
127 msr.lo = (PMB0 + 4) | (PMB1 << 16);
128 wrmsr(PMG_IO_BASE_ADDR, msr);
130 // set C_LVL controls
131 msr = rdmsr(PMG_IO_CAPTURE_ADDR);
132 msr.lo = (PMB0 + 4) | ((HIGHEST_CLEVEL - 2) << 16); // -2 because LVL0+1 aren't counted
133 wrmsr(PMG_IO_CAPTURE_ADDR, msr);
136 #define IA32_MISC_ENABLE 0x1a0
137 static void configure_misc(void)
141 msr = rdmsr(IA32_MISC_ENABLE);
142 msr.lo |= (1 << 3); /* TM1 enable */
143 msr.lo |= (1 << 13); /* TM2 enable */
144 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
146 msr.lo |= (1 << 10); /* FERR# multiplexing */
148 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
149 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
151 // TODO Do we want Deep C4 and Dynamic L2 shrinking?
152 wrmsr(IA32_MISC_ENABLE, msr);
154 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
155 wrmsr(IA32_MISC_ENABLE, msr);
158 #if CONFIG_USBDEBUG_DIRECT
159 static unsigned ehci_debug_addr;
162 static void model_106cx_init(device_t cpu)
164 char processor_name[49];
166 /* Turn on caching if we haven't already */
169 /* Update the microcode */
170 intel_update_microcode(microcode_updates);
172 /* Print processor name */
173 fill_processor_name(processor_name);
174 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
176 #if CONFIG_USBDEBUG_DIRECT
177 // Is this caution really needed?
179 ehci_debug_addr = get_ehci_debug();
187 #if CONFIG_USBDEBUG_DIRECT
188 set_ehci_debug(ehci_debug_addr);
191 /* Enable the local cpu apics */
194 /* Enable virtualization */
197 /* Configure C States */
198 configure_c_states();
200 /* Configure Enhanced SpeedStep and Thermal Sensors */
203 /* TODO: PIC thermal sensor control */
205 /* Start up my cpu siblings */
206 intel_sibling_init(cpu);
209 static struct device_operations cpu_dev_ops = {
210 .init = model_106cx_init,
213 static struct cpu_device_id cpu_table[] = {
214 { X86_VENDOR_INTEL, 0x106c0 }, /* Intel Atom 230 */
218 static const struct cpu_driver driver __cpu_driver = {
220 .id_table = cpu_table,