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 <cpu/x86/name.h>
36 static const uint32_t microcode_updates[] = {
37 /* Dummy terminator */
44 static void init_timer(void)
46 /* Set the apic timer to no interrupts and periodic mode */
47 lapic_write(LAPIC_LVTT, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0));
49 /* Set the divider to 1, no divider */
50 lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1);
52 /* Set the initial counter to 0xffffffff */
53 lapic_write(LAPIC_TMICT, 0xffffffff);
56 #define IA32_FEATURE_CONTROL 0x003a
58 #define CPUID_VMX (1 << 5)
59 #define CPUID_SMX (1 << 6)
60 static void enable_vmx(void)
62 struct cpuid_result regs;
65 msr = rdmsr(IA32_FEATURE_CONTROL);
67 if (msr.lo & (1 << 0)) {
68 /* VMX locked. If we set it again we get an illegal
75 if (regs.ecx & CPUID_VMX) {
77 if (regs.ecx & CPUID_SMX)
81 wrmsr(IA32_FEATURE_CONTROL, msr);
83 msr.lo |= (1 << 0); /* Set lock bit */
85 wrmsr(IA32_FEATURE_CONTROL, msr);
88 #define PMG_CST_CONFIG_CONTROL 0xe2
89 #define PMG_IO_BASE_ADDR 0xe3
90 #define PMG_IO_CAPTURE_ADDR 0xe4
92 #define PMB0_BASE 0x580
93 #define PMB1_BASE 0x800
95 static void configure_c_states(void)
99 msr = rdmsr(PMG_CST_CONFIG_CONTROL);
101 msr.lo |= (1 << 15); // config lock until next reset
102 msr.lo |= (1 << 14); // Deeper Sleep
103 msr.lo |= (1 << 10); // Enable IO MWAIT redirection
104 msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk
105 msr.lo |= (1 << 3); // Dynamic L2
107 wrmsr(PMG_CST_CONFIG_CONTROL, msr);
109 /* Set Processor MWAIT IO BASE */
111 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff) << 16);
112 wrmsr(PMG_IO_BASE_ADDR, msr);
114 /* Set IO Capture Address */
116 msr.lo = ((PMB0_BASE + 4) & 0xffff) | (( CST_RANGE & 0xffff) << 16);
117 wrmsr(PMG_IO_CAPTURE_ADDR, msr);
120 #define IA32_MISC_ENABLE 0x1a0
121 static void configure_misc(void)
125 msr = rdmsr(IA32_MISC_ENABLE);
126 msr.lo |= (1 << 3); /* TM1 enable */
127 msr.lo |= (1 << 13); /* TM2 enable */
128 msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */
130 msr.lo |= (1 << 10); /* FERR# multiplexing */
132 // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1
133 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
139 /* TODO This should only be done on mobile CPUs, see cpuid 5 */
140 msr.hi |= (1 << (32 - 32)); // C4E
141 msr.hi |= (1 << (33 - 32)); // Hard C4E
144 /* NOTE: We leave the EMTTM_CR_TABLE0-5 at their default values */
145 msr.hi |= (1 << (36 - 32));
147 wrmsr(IA32_MISC_ENABLE, msr);
149 msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */
150 wrmsr(IA32_MISC_ENABLE, msr);
153 #define PIC_SENS_CFG 0x1aa
154 static void configure_pic_thermal_sensors(void)
158 msr = rdmsr(PIC_SENS_CFG);
160 msr.lo |= (1 << 21); // inter-core lock TM1
161 msr.lo |= (1 << 4); // Enable bypass filter
163 wrmsr(PIC_SENS_CFG, msr);
167 static unsigned ehci_debug_addr;
170 static void model_1067x_init(device_t cpu)
172 char processor_name[49];
174 /* Turn on caching if we haven't already */
177 /* Update the microcode */
178 intel_update_microcode(microcode_updates);
180 /* Print processor name */
181 fill_processor_name(processor_name);
182 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
185 // Is this caution really needed?
187 ehci_debug_addr = get_ehci_debug();
196 set_ehci_debug(ehci_debug_addr);
199 /* Enable the local cpu apics */
202 /* Initialize the APIC timer */
205 /* Enable virtualization */
208 /* Configure C States */
209 configure_c_states();
211 /* Configure Enhanced SpeedStep and Thermal Sensors */
214 /* PIC thermal sensor control */
215 configure_pic_thermal_sensors();
217 /* Start up my cpu siblings */
218 intel_sibling_init(cpu);
221 static struct device_operations cpu_dev_ops = {
222 .init = model_1067x_init,
225 static struct cpu_device_id cpu_table[] = {
226 { X86_VENDOR_INTEL, 0x10676 }, /* Intel Core 2 Solo/Core Duo */
230 static const struct cpu_driver driver __cpu_driver = {
232 .id_table = cpu_table,