2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * 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
22 #include <cpu/x86/cache.h>
23 #include <cpu/x86/msr.h>
24 #include <cpu/x86/mtrr.h>
26 static const uint32_t microcode_updates[] = {
27 #include "x06_microcode.h"
31 u32 hdrver; /* Header Version */
32 u32 rev; /* Patch ID */
36 u32 cksum; /* Checksum */
37 u32 ldrver; /* Loader Version */
38 u32 pf; /* Platform ID */
40 u32 data_size; /* Data size */
41 u32 total_size; /* Total size */
47 static inline u32 read_microcode_rev(void)
49 /* Some Intel Cpus can be very finicky about the
50 * CPUID sequence used. So this is implemented in
51 * assembly so that it works reliably.
56 "xorl %%eax, %%eax\n\t"
57 "xorl %%edx, %%edx\n\t"
58 "movl $0x8b, %%ecx\n\t"
60 "movl $0x01, %%eax\n\t"
62 "movl $0x08b, %%ecx\n\t"
65 "=a" (msr.lo), "=d" (msr.hi)
73 void intel_update_microcode(const void *microcode_updates)
76 unsigned int pf, rev, sig;
77 unsigned int x86_model, x86_family;
78 const struct microcode *m;
82 /* cpuid sets msr 0x8B iff a microcode update has been loaded. */
89 x86_model = (eax >>4) & 0x0f;
90 x86_family = (eax >>8) & 0x0f;
94 if ((x86_model >= 5)||(x86_family>6)) {
96 pf = 1 << ((msr.hi >> 18) & 7);
99 m = microcode_updates;
100 for(c = microcode_updates; m->hdrver; m = (const struct microcode *)c) {
101 if ((m->sig == sig) && (m->pf & pf)) {
102 unsigned int new_rev;
103 msr.lo = (unsigned long)(&m->bits) & 0xffffffff;
107 /* Read back the new microcode version */
108 new_rev = read_microcode_rev();
119 static void set_var_mtrr(
120 unsigned reg, unsigned base, unsigned size, unsigned type)
123 /* Bit Bit 32-35 of MTRRphysMask should be set to 1 */
124 /* FIXME: It only support 4G less range */
126 basem.lo = base | type;
128 wrmsr(MTRRphysBase_MSR(reg), basem);
129 maskm.lo = ~(size - 1) | MTRRphysMaskValid;
130 maskm.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1;
131 wrmsr(MTRRphysMask_MSR(reg), maskm);
134 static void enable_rom_caching(void)
139 set_var_mtrr(1, 0xffc00000, 4*1024*1024, MTRR_TYPE_WRPROT);
142 /* Enable Variable MTRRs */
145 wrmsr(MTRRdefType_MSR, msr);
148 static void bootblock_cpu_init(void)
150 enable_rom_caching();
151 intel_update_microcode(microcode_updates);