Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 3 | * |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 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> |
Stefan Reinauer | 2a27b20 | 2010-12-11 22:14:44 +0000 | [diff] [blame] | 31 | #include <cpu/intel/speedstep.h> |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame^] | 32 | #include <cpu/intel/hyperthreading.h> |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 33 | #include <cpu/x86/cache.h> |
Uwe Hermann | aac8f66 | 2010-09-29 09:54:16 +0000 | [diff] [blame] | 34 | #include <cpu/x86/name.h> |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 35 | |
| 36 | static const uint32_t microcode_updates[] = { |
Stefan Reinauer | c104cb0 | 2010-10-18 00:21:39 +0000 | [diff] [blame] | 37 | #include "microcode-2618-m441067AA07.h" |
| 38 | #include "microcode-2626-m1010677705.h" |
| 39 | #include "microcode-2498-m101067660C.h" |
| 40 | #include "microcode-2497-m041067660C.h" |
| 41 | #include "microcode-2499-m401067660C.h" |
| 42 | #include "microcode-2617-m111067AA07.h" |
| 43 | #include "microcode-2619-mA01067AA07.h" |
| 44 | #include "microcode-2623-m011067660C.h" |
| 45 | #include "microcode-2501-m801067660C.h" |
| 46 | |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 47 | /* Dummy terminator */ |
| 48 | 0x0, 0x0, 0x0, 0x0, |
| 49 | 0x0, 0x0, 0x0, 0x0, |
| 50 | 0x0, 0x0, 0x0, 0x0, |
| 51 | 0x0, 0x0, 0x0, 0x0, |
| 52 | }; |
| 53 | |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 54 | static void init_timer(void) |
| 55 | { |
| 56 | /* Set the apic timer to no interrupts and periodic mode */ |
| 57 | lapic_write(LAPIC_LVTT, (1 << 17)|(1<< 16)|(0 << 12)|(0 << 0)); |
| 58 | |
| 59 | /* Set the divider to 1, no divider */ |
| 60 | lapic_write(LAPIC_TDCR, LAPIC_TDR_DIV_1); |
| 61 | |
| 62 | /* Set the initial counter to 0xffffffff */ |
| 63 | lapic_write(LAPIC_TMICT, 0xffffffff); |
| 64 | } |
| 65 | |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 66 | #define IA32_FEATURE_CONTROL 0x003a |
| 67 | |
| 68 | #define CPUID_VMX (1 << 5) |
| 69 | #define CPUID_SMX (1 << 6) |
| 70 | static void enable_vmx(void) |
| 71 | { |
| 72 | struct cpuid_result regs; |
| 73 | msr_t msr; |
| 74 | |
| 75 | msr = rdmsr(IA32_FEATURE_CONTROL); |
| 76 | |
| 77 | if (msr.lo & (1 << 0)) { |
| 78 | /* VMX locked. If we set it again we get an illegal |
| 79 | * instruction |
| 80 | */ |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | regs = cpuid(1); |
| 85 | if (regs.ecx & CPUID_VMX) { |
| 86 | msr.lo |= (1 << 2); |
| 87 | if (regs.ecx & CPUID_SMX) |
| 88 | msr.lo |= (1 << 1); |
| 89 | } |
| 90 | |
| 91 | wrmsr(IA32_FEATURE_CONTROL, msr); |
| 92 | |
| 93 | msr.lo |= (1 << 0); /* Set lock bit */ |
| 94 | |
| 95 | wrmsr(IA32_FEATURE_CONTROL, msr); |
| 96 | } |
| 97 | |
| 98 | #define PMG_CST_CONFIG_CONTROL 0xe2 |
| 99 | #define PMG_IO_BASE_ADDR 0xe3 |
| 100 | #define PMG_IO_CAPTURE_ADDR 0xe4 |
| 101 | |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 102 | #define CST_RANGE 2 |
| 103 | static void configure_c_states(void) |
| 104 | { |
| 105 | msr_t msr; |
| 106 | |
| 107 | msr = rdmsr(PMG_CST_CONFIG_CONTROL); |
| 108 | |
| 109 | msr.lo |= (1 << 15); // config lock until next reset |
| 110 | msr.lo |= (1 << 14); // Deeper Sleep |
| 111 | msr.lo |= (1 << 10); // Enable IO MWAIT redirection |
| 112 | msr.lo &= ~(1 << 9); // Issue a single stop grant cycle upon stpclk |
| 113 | msr.lo |= (1 << 3); // Dynamic L2 |
| 114 | |
| 115 | wrmsr(PMG_CST_CONFIG_CONTROL, msr); |
| 116 | |
| 117 | /* Set Processor MWAIT IO BASE */ |
| 118 | msr.hi = 0; |
| 119 | msr.lo = ((PMB0_BASE + 4) & 0xffff) | (((PMB1_BASE + 9) & 0xffff) << 16); |
| 120 | wrmsr(PMG_IO_BASE_ADDR, msr); |
| 121 | |
| 122 | /* Set IO Capture Address */ |
| 123 | msr.hi = 0; |
| 124 | msr.lo = ((PMB0_BASE + 4) & 0xffff) | (( CST_RANGE & 0xffff) << 16); |
| 125 | wrmsr(PMG_IO_CAPTURE_ADDR, msr); |
| 126 | } |
| 127 | |
| 128 | #define IA32_MISC_ENABLE 0x1a0 |
| 129 | static void configure_misc(void) |
| 130 | { |
| 131 | msr_t msr; |
| 132 | |
| 133 | msr = rdmsr(IA32_MISC_ENABLE); |
| 134 | msr.lo |= (1 << 3); /* TM1 enable */ |
| 135 | msr.lo |= (1 << 13); /* TM2 enable */ |
| 136 | msr.lo |= (1 << 17); /* Bidirectional PROCHOT# */ |
| 137 | |
| 138 | msr.lo |= (1 << 10); /* FERR# multiplexing */ |
| 139 | |
| 140 | // TODO: Only if IA32_PLATFORM_ID[17] = 0 and IA32_PLATFORM_ID[50] = 1 |
| 141 | msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */ |
| 142 | |
| 143 | /* Enable C2E */ |
| 144 | msr.lo |= (1 << 26); |
| 145 | |
| 146 | /* Enable C4E */ |
| 147 | /* TODO This should only be done on mobile CPUs, see cpuid 5 */ |
| 148 | msr.hi |= (1 << (32 - 32)); // C4E |
| 149 | msr.hi |= (1 << (33 - 32)); // Hard C4E |
| 150 | |
| 151 | /* Enable EMTTM. */ |
| 152 | /* NOTE: We leave the EMTTM_CR_TABLE0-5 at their default values */ |
| 153 | msr.hi |= (1 << (36 - 32)); |
| 154 | |
| 155 | wrmsr(IA32_MISC_ENABLE, msr); |
| 156 | |
| 157 | msr.lo |= (1 << 20); /* Lock Enhanced SpeedStep Enable */ |
| 158 | wrmsr(IA32_MISC_ENABLE, msr); |
| 159 | } |
| 160 | |
| 161 | #define PIC_SENS_CFG 0x1aa |
| 162 | static void configure_pic_thermal_sensors(void) |
| 163 | { |
| 164 | msr_t msr; |
| 165 | |
| 166 | msr = rdmsr(PIC_SENS_CFG); |
| 167 | |
| 168 | msr.lo |= (1 << 21); // inter-core lock TM1 |
| 169 | msr.lo |= (1 << 4); // Enable bypass filter |
| 170 | |
| 171 | wrmsr(PIC_SENS_CFG, msr); |
| 172 | } |
| 173 | |
Stefan Reinauer | 7e00a44 | 2010-05-25 17:09:05 +0000 | [diff] [blame] | 174 | #if CONFIG_USBDEBUG |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 175 | static unsigned ehci_debug_addr; |
| 176 | #endif |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 177 | |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 178 | static void model_1067x_init(device_t cpu) |
| 179 | { |
| 180 | char processor_name[49]; |
| 181 | |
| 182 | /* Turn on caching if we haven't already */ |
| 183 | x86_enable_cache(); |
| 184 | |
| 185 | /* Update the microcode */ |
| 186 | intel_update_microcode(microcode_updates); |
| 187 | |
| 188 | /* Print processor name */ |
| 189 | fill_processor_name(processor_name); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 190 | printk(BIOS_INFO, "CPU: %s.\n", processor_name); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 191 | |
Stefan Reinauer | 7e00a44 | 2010-05-25 17:09:05 +0000 | [diff] [blame] | 192 | #if CONFIG_USBDEBUG |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 193 | // Is this caution really needed? |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 194 | if(!ehci_debug_addr) |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 195 | ehci_debug_addr = get_ehci_debug(); |
| 196 | set_ehci_debug(0); |
| 197 | #endif |
| 198 | |
| 199 | /* Setup MTRRs */ |
Sven Schnelle | adfbcb79 | 2012-01-10 12:01:43 +0100 | [diff] [blame] | 200 | x86_setup_mtrrs(); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 201 | x86_mtrr_check(); |
| 202 | |
Stefan Reinauer | 7e00a44 | 2010-05-25 17:09:05 +0000 | [diff] [blame] | 203 | #if CONFIG_USBDEBUG |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 204 | set_ehci_debug(ehci_debug_addr); |
| 205 | #endif |
| 206 | |
| 207 | /* Enable the local cpu apics */ |
| 208 | setup_lapic(); |
| 209 | |
| 210 | /* Initialize the APIC timer */ |
| 211 | init_timer(); |
| 212 | |
| 213 | /* Enable virtualization */ |
| 214 | enable_vmx(); |
| 215 | |
| 216 | /* Configure C States */ |
| 217 | configure_c_states(); |
| 218 | |
| 219 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 220 | configure_misc(); |
| 221 | |
| 222 | /* PIC thermal sensor control */ |
| 223 | configure_pic_thermal_sensors(); |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame^] | 224 | |
| 225 | /* Start up my cpu siblings */ |
| 226 | intel_sibling_init(cpu); |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static struct device_operations cpu_dev_ops = { |
| 230 | .init = model_1067x_init, |
| 231 | }; |
| 232 | |
| 233 | static struct cpu_device_id cpu_table[] = { |
| 234 | { X86_VENDOR_INTEL, 0x10676 }, /* Intel Core 2 Solo/Core Duo */ |
Stefan Reinauer | c104cb0 | 2010-10-18 00:21:39 +0000 | [diff] [blame] | 235 | { X86_VENDOR_INTEL, 0x10677 }, |
| 236 | { X86_VENDOR_INTEL, 0x1067A }, |
Thomas Jourdan | 1a692d8 | 2009-07-01 17:01:17 +0000 | [diff] [blame] | 237 | { 0, 0 }, |
| 238 | }; |
| 239 | |
| 240 | static const struct cpu_driver driver __cpu_driver = { |
| 241 | .ops = &cpu_dev_ops, |
| 242 | .id_table = cpu_table, |
| 243 | }; |
| 244 | |