This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / src / cpu / amd / mtrr / amd_earlymtrr.c
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"
6
7 /* the fixed and variable MTTRs are power-up with random values,
8  * clear them to MTRR_TYPE_UNCACHEABLE for safty.
9  */             
10 static void do_amd_early_mtrr_init(const unsigned long *mtrr_msrs)
11 {               
12         /* Precondition:
13          *   The cache is not enabled in cr0 nor in MTRRdefType_MSR
14          *   entry32.inc ensures the cache is not enabled in cr0
15          */
16         msr_t msr;
17         const unsigned long *msr_addr;
18 #if 0
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);
23 #endif
24
25         /* Inialize all of the relevant msrs to 0 */
26         msr.lo = 0;
27         msr.hi = 0;
28         unsigned long msr_nr;
29         for(msr_addr = mtrr_msrs; (msr_nr = *msr_addr); msr_addr++) {
30                 wrmsr(msr_nr, msr);
31         }
32 #if 0
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);
37 #endif
38
39         /* Enable memory access for 0 - 1MB using top_mem */
40         msr.hi = 0;
41         msr.lo = (((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK);
42         wrmsr(TOP_MEM, msr);
43
44 #if defined(CONFIG_XIP_ROM_SIZE)
45         /* enable write through caching so we can do execute in place
46          * on the flash rom.
47          */
48         set_var_mtrr(1, CONFIG_XIP_ROM_BASE, CONFIG_XIP_ROM_SIZE, MTRR_TYPE_WRBACK);
49 #endif
50
51         /* Set the default memory type and enable fixed and variable MTRRs 
52          */
53         /* Enable Variable MTRRs */
54         msr.hi = 0x00000000;
55         msr.lo = 0x00000800;
56         wrmsr(MTRRdefType_MSR, msr);
57
58         /* Enable the MTRRs in SYSCFG */
59         msr = rdmsr(SYSCFG_MSR);
60         msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
61         wrmsr(SYSCFG_MSR, msr);
62         
63 }
64
65 static void amd_early_mtrr_init(void)
66 {
67         static const unsigned long mtrr_msrs[] = {
68                 /* fixed mtrr */
69                 0x250, 0x258, 0x259,
70                 0x268, 0x269, 0x26A,
71                 0x26B, 0x26C, 0x26D,
72                 0x26E, 0x26F,
73                 /* var mtrr */
74                 0x200, 0x201, 0x202, 0x203,
75                 0x204, 0x205, 0x206, 0x207,
76                 0x208, 0x209, 0x20A, 0x20B,
77                 0x20C, 0x20D, 0x20E, 0x20F,
78                 /* var iorr */
79                 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
80                 /* mem top */
81                 0xC001001A, 0xC001001D,
82                 /* NULL end of table */
83                 0
84         };
85
86         /* wbinvd which is called in disable_cache() causes hangs on Opterons
87          * if there is no data in the cache.
88          * At this point we should not have the cache enabled so don't bother
89          * disabling it.
90          */
91         /* disable_cache(); */
92         do_amd_early_mtrr_init(mtrr_msrs);
93
94         enable_cache();
95 }
96
97 #endif /* AMD_EARLYMTRR_C */