6ade52511024294b4016174e30616e8d316f3620
[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_RAMTOP) + TOP_MEM_MASK) & ~TOP_MEM_MASK);
42         wrmsr(TOP_MEM, msr);
43
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
48 #else
49 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
50 #endif
51         /* enable write through caching so we can do execute in place
52          * on the flash rom.
53          */
54         set_var_mtrr(1, REAL_XIP_ROM_BASE, CONFIG_XIP_ROM_SIZE, MTRR_TYPE_WRBACK);
55 #endif
56
57         /* Set the default memory type and enable fixed and variable MTRRs 
58          */
59         /* Enable Variable MTRRs */
60         msr.hi = 0x00000000;
61         msr.lo = 0x00000800;
62         wrmsr(MTRRdefType_MSR, msr);
63
64         /* Enable the MTRRs in SYSCFG */
65         msr = rdmsr(SYSCFG_MSR);
66         msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
67         wrmsr(SYSCFG_MSR, msr);
68         
69 }
70
71 static void amd_early_mtrr_init(void)
72 {
73         static const unsigned long mtrr_msrs[] = {
74                 /* fixed mtrr */
75                 0x250, 0x258, 0x259,
76                 0x268, 0x269, 0x26A,
77                 0x26B, 0x26C, 0x26D,
78                 0x26E, 0x26F,
79                 /* var mtrr */
80                 0x200, 0x201, 0x202, 0x203,
81                 0x204, 0x205, 0x206, 0x207,
82                 0x208, 0x209, 0x20A, 0x20B,
83                 0x20C, 0x20D, 0x20E, 0x20F,
84                 /* var iorr */
85                 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
86                 /* mem top */
87                 0xC001001A, 0xC001001D,
88                 /* NULL end of table */
89                 0
90         };
91
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
95          * disabling it.
96          */
97         /* disable_cache(); */
98         do_amd_early_mtrr_init(mtrr_msrs);
99
100         enable_cache();
101 }
102
103 #endif /* AMD_EARLYMTRR_C */