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;
19 /* Enable the access to AMD RdDram and WrDram extension bits */
20 msr = rdmsr(SYSCFG_MSR);
21 msr.lo |= SYSCFG_MSR_MtrrFixDramModEn;
22 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);
39 /* Enable memory access for 0 - 1MB using top_mem */
41 msr.lo = (((CONFIG_RAMTOP) + TOP_MEM_MASK) & ~TOP_MEM_MASK);
44 #if defined(CONFIG_XIP_ROM_SIZE)
45 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
46 extern unsigned long AUTO_XIP_ROM_BASE;
47 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
49 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
51 /* enable write through caching so we can do execute in place
54 set_var_mtrr(1, REAL_XIP_ROM_BASE, CONFIG_XIP_ROM_SIZE, MTRR_TYPE_WRBACK);
57 /* Set the default memory type and enable fixed and variable MTRRs
59 /* Enable Variable MTRRs */
62 wrmsr(MTRRdefType_MSR, msr);
64 /* Enable the MTRRs in SYSCFG */
65 msr = rdmsr(SYSCFG_MSR);
66 msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
67 wrmsr(SYSCFG_MSR, msr);
71 static void amd_early_mtrr_init(void)
73 static const unsigned long mtrr_msrs[] = {
80 0x200, 0x201, 0x202, 0x203,
81 0x204, 0x205, 0x206, 0x207,
82 0x208, 0x209, 0x20A, 0x20B,
83 0x20C, 0x20D, 0x20E, 0x20F,
85 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
87 0xC001001A, 0xC001001D,
88 /* NULL end of table */
92 /* wbinvd which is called in disable_cache() causes hangs on Opterons
93 * if there is no data in the cache.
94 * At this point we should not have the cache enabled so don't bother
97 /* disable_cache(); */
98 do_amd_early_mtrr_init(mtrr_msrs);
103 #endif /* AMD_EARLYMTRR_C */