1 #ifndef AMD_EARLYMTRR_C
2 #define AMD_EARLYMTRR_C
3 #include <cpu/x86/mtrr.h>
4 #include <cpu/amd/mtrr.h>
5 #include "cpu/x86/mtrr/earlymtrr.c"
7 /* the fixed and variable MTTRs are power-up with random values,
8 * clear them to MTRR_TYPE_UNCACHEABLE for safty.
10 static void do_amd_early_mtrr_init(const unsigned long *mtrr_msrs)
13 * The cache is not enabled in cr0 nor in MTRRdefType_MSR
14 * entry32.inc ensures the cache is not enabled in cr0
17 const unsigned long *msr_addr;
20 /* Enable the access to AMD RdDram and WrDram extension bits */
21 msr = rdmsr(SYSCFG_MSR);
22 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
23 wrmsr(SYSCFG_MSR, msr);
25 /* Inialize all of the relevant msrs to 0 */
29 for(msr_addr = mtrr_msrs; (msr_nr = *msr_addr); msr_addr++) {
33 /* Disable the access to AMD RdDram and WrDram extension bits */
34 msr = rdmsr(SYSCFG_MSR);
35 msr.lo &= ~SYSCFG_MSR_MtrrFixDramModEn;
36 wrmsr(SYSCFG_MSR, msr);
38 /* Enable memory access for 0 - 1MB using top_mem */
40 msr.lo = (((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK);
43 /* Enable caching for 0 - 1MB using variable mtrr */
45 set_var_mtrr(0, 0x00000000, (CONFIG_LB_MEM_TOPK << 10), MTRR_TYPE_WRBACK);
50 msr.lo |= 0x00000000 | MTRR_TYPE_WRBACK;
56 msr.lo |= (~((CONFIG_LB_MEM_TOPK << 10) - 1)) | 0x800;
60 #if defined(XIP_ROM_SIZE)
61 /* enable write through caching so we can do execute in place
64 set_var_mtrr(1, XIP_ROM_BASE, XIP_ROM_SIZE, MTRR_TYPE_WRBACK);
67 /* Set the default memory type and enable fixed and variable MTRRs
69 /* Enable Variable MTRRs */
72 wrmsr(MTRRdefType_MSR, msr);
74 /* Enable the MTRRs in SYSCFG */
75 msr = rdmsr(SYSCFG_MSR);
76 msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
77 wrmsr(SYSCFG_MSR, msr);
81 static void amd_early_mtrr_init(void)
83 static const unsigned long mtrr_msrs[] = {
90 0x200, 0x201, 0x202, 0x203,
91 0x204, 0x205, 0x206, 0x207,
92 0x208, 0x209, 0x20A, 0x20B,
93 0x20C, 0x20D, 0x20E, 0x20F,
95 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
97 0xC001001A, 0xC001001D,
98 /* NULL end of table */
102 /* wbinvd which is called in disable_cache() causes hangs on Opterons
103 * if there is no data in the cache.
104 * At this point we should not have the cache enabled so don't bother
107 /* disable_cache(); */
108 do_amd_early_mtrr_init(mtrr_msrs);
113 #endif /* AMD_EARLYMTRR_C */