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
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.
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,
22 #include <console/console.h>
23 #include <device/device.h>
24 #include <device/pci.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 <usbdebug_direct.h>
36 static const uint32_t microcode_updates[] = {
37 /* Dummy terminator */
44 static inline void strcpy(char *dst, char *src)
46 while (*src) *dst++ = *src++;
49 static void fill_processor_name(char *processor_name)
51 struct cpuid_result regs;
52 char temp_processor_name[49];
53 char *processor_name_start;
54 unsigned int *name_as_ints = (unsigned int *)temp_processor_name;
58 regs = cpuid(0x80000002 + i);
59 name_as_ints[i*4 + 0] = regs.eax;
60 name_as_ints[i*4 + 1] = regs.ebx;
61 name_as_ints[i*4 + 2] = regs.ecx;
62 name_as_ints[i*4 + 3] = regs.edx;
65 temp_processor_name[48] = 0;
67 /* Skip leading spaces */
68 processor_name_start = temp_processor_name;
69 while (*processor_name_start == ' ')
70 processor_name_start++;
72 memset(processor_name, 0, 49);
73 strcpy(processor_name, processor_name_start);
76 #define IA32_FEATURE_CONTROL 0x003a
78 #define CPUID_VMX (1 << 5)
79 #define CPUID_SMX (1 << 6)
80 static void enable_vmx(void)
82 struct cpuid_result regs;
85 msr = rdmsr(IA32_FEATURE_CONTROL);
87 if (msr.lo & (1 << 0)) {
88 /* VMX locked. If we set it again we get an illegal
95 if (regs.ecx & CPUID_VMX) {
97 if (regs.ecx & CPUID_SMX)
101 wrmsr(IA32_FEATURE_CONTROL, msr);
103 msr.lo |= (1 << 0); /* Set lock bit */
105 wrmsr(IA32_FEATURE_CONTROL, msr);
108 #define PMG_CST_CONFIG_CONTROL 0xe2
109 #define PMG_IO_BASE_ADDR 0xe3
110 #define PMG_IO_CAPTURE_ADDR 0xe4
111 #define PMB0 0x510 /* analogous to P_BLK in cpu.asl */
112 #define PMB1 0x0 /* IO port that triggers SMI once cores are in the same state.
113 See CSM Trigger, at PMG_CST_CONFIG_CONTROL[6:4] */
114 #define HIGHEST_CLEVEL 3
115 static void configure_c_states(void)
119 msr = rdmsr(PMG_CST_CONFIG_CONTROL);
120 msr.lo |= (1 << 15); // Lock configuration
121 msr.lo |= (1 << 10); // redirect IO-based CState transition requests to MWAIT
122 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
123 msr.lo &= ~7; msr.lo |= HIGHEST_CLEVEL; // support at most C3
124 // TODO Do we want Deep C4 and Dynamic L2 shrinking?
125 wrmsr(PMG_CST_CONFIG_CONTROL, msr);
128 msr = rdmsr(PMG_IO_BASE_ADDR);
129 msr.lo = (PMB0 + 4) | (PMB1 << 16);
130 wrmsr(PMG_IO_BASE_ADDR, msr);
132 // set C_LVL controls
133 msr = rdmsr(PMG_IO_CAPTURE_ADDR);
134 msr.lo = (PMB0 + 4) | ((HIGHEST_CLEVEL - 2) << 16); // -2 because LVL0+1 aren't counted
135 wrmsr(PMG_IO_CAPTURE_ADDR, msr);
138 #define IA32_MISC_ENABLE 0x1a0
139 static void configure_misc(void)
143 msr = rdmsr(IA32_MISC_ENABLE);
144 msr.lo |= (1 << 3); /* TM1 enable */
145 msr.lo |= (1 << 13); /* TM2 enable */
146 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
148 msr.lo |= (1 << 10); /* FERR# multiplexing */
150 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
151 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
153 // TODO Do we want Deep C4 and Dynamic L2 shrinking?
154 wrmsr(IA32_MISC_ENABLE, msr);
156 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
157 wrmsr(IA32_MISC_ENABLE, msr);
160 #if CONFIG_USBDEBUG_DIRECT
161 static unsigned ehci_debug_addr;
164 static void model_6ex_init(device_t cpu)
166 char processor_name[49];
168 /* Turn on caching if we haven't already */
171 /* Update the microcode */
172 intel_update_microcode(microcode_updates);
174 /* Print processor name */
175 fill_processor_name(processor_name);
176 printk_info("CPU: %s.\n", processor_name);
178 #if CONFIG_USBDEBUG_DIRECT
179 // Is this caution really needed?
181 ehci_debug_addr = get_ehci_debug();
189 #if CONFIG_USBDEBUG_DIRECT
190 set_ehci_debug(ehci_debug_addr);
193 /* Enable the local cpu apics */
196 /* Enable virtualization */
199 /* Configure C States */
200 configure_c_states();
202 /* Configure Enhanced SpeedStep and Thermal Sensors */
205 /* TODO: PIC thermal sensor control */
207 /* Start up my cpu siblings */
208 intel_sibling_init(cpu);
211 static struct device_operations cpu_dev_ops = {
212 .init = model_6ex_init,
215 static struct cpu_device_id cpu_table[] = {
216 { X86_VENDOR_INTEL, 0x06e0 }, /* Intel Core Solo/Core Duo */
217 { X86_VENDOR_INTEL, 0x06e8 }, /* Intel Core Solo/Core Duo */
218 { X86_VENDOR_INTEL, 0x06ec }, /* Intel Core Solo/Core Duo */
222 static const struct cpu_driver driver __cpu_driver = {
224 .id_table = cpu_table,