1 #include <cpu/k8/mtrr.h>
3 /* the fixed and variable MTTRs are power-up with random values,
4 * clear them to MTRR_TYPE_UNCACHEABLE for safty.
7 static void early_mtrr_init(void)
9 static const unsigned long mtrr_msrs[] = {
16 0x200, 0x201, 0x202, 0x203,
17 0x204, 0x205, 0x206, 0x207,
18 0x208, 0x209, 0x20A, 0x20B,
19 0x20C, 0x20D, 0x20E, 0x20F,
21 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
23 0xC001001A, 0xC001001D,
24 /* NULL end of table */
28 const unsigned long *msr_addr;
30 /* Enable the access to AMD RdDram and WrDram extension bits */
31 msr = rdmsr(SYSCFG_MSR);
32 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
33 wrmsr(SYSCFG_MSR, msr);
35 /* Inialize all of the relevant msrs to 0 */
39 for (msr_addr = mtrr_msrs; *msr_addr; msr_addr++) {
40 wrmsr(*msr_addr, msr);
43 /* Disable the access to AMD RdDram and WrDram extension bits */
44 msr = rdmsr(SYSCFG_MSR);
45 msr.lo &= ~SYSCFG_MSR_MtrrFixDramModEn;
46 wrmsr(SYSCFG_MSR, msr);
48 /* Enable memory access for 0 - 1MB using top_mem */
50 msr.lo = ((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK;
53 /* Enable caching for 0 - 1MB using variable mtrr */
58 msr.lo |= 0x00000000 | MTRR_TYPE_WRBACK;
65 msr.lo |= (~((CONFIG_LB_MEM_TOPK << 10) - 1)) | 0x800;
68 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
69 /* enable write through caching so we can do execute in place
73 msr.lo = XIP_ROM_BASE | MTRR_TYPE_WRTHROUGH;
75 #error "FIXME verify the type of MTRR I have setup"
77 msr.lo = ~(XIP_ROM_SIZE - 1) | 0x800;
81 /* Set the default memory type and enable fixed and variable MTRRs
83 /* Enable Variable MTRRs */
86 wrmsr(MTRRdefType_MSR, msr);
88 /* Enale the MTRRs in SYSCFG */
89 msr = rdmsr(SYSCFG_MSR);
90 msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
91 wrmsr(SYSCFG_MSR, msr);
93 /* Enable the cache */