- Add new cvs code to cvs
[coreboot.git] / src / cpu / k8 / earlymtrr.c
1 #include <cpu/k8/mtrr.h>
2
3 /* the fixed and variable MTTRs are power-up with random values,
4  * clear them to MTRR_TYPE_UNCACHEABLE for safty.
5  */
6
7 static void early_mtrr_init(void)
8 {
9         static const unsigned long mtrr_msrs[] = {
10                 /* fixed mtrr */
11                 0x250, 0x258, 0x259,
12                 0x268, 0x269, 0x26A
13                 0x26B, 0x26C, 0x26D
14                 0x26E, 0x26F,
15                 /* var mtrr */
16                 0x200, 0x201, 0x202, 0x203,
17                 0x204, 0x205, 0x206, 0x207,
18                 0x208, 0x209, 0x20A, 0x20B,
19                 0x20C, 0x20D, 0x20E, 0x20F,
20                 /* var iorr msr */
21                 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019,
22                 /* mem top */
23                 0xC001001A, 0xC001001D,
24                 /* NULL end of table */
25                 0
26         };
27         msr_t msr;
28         const unsigned long *msr_addr;
29
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);
34
35         /* Inialize all of the relevant msrs to 0 */
36         msr.lo = 0;
37         msr.hi = 0;
38
39         for (msr_addr = mtrr_msrs; *msr_addr; msr_addr++) {
40                 wrmsr(*msr_addr, msr);
41         }
42
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);
47
48         /* Enable memory access for 0 - 1MB using top_mem */
49         msr.hi = 0;
50         msr.lo = ((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK;
51         wrmsr(TOP_MEM, msr);
52
53         /* Enable caching for 0 - 1MB using variable mtrr */
54         msr = rdmsr(0x200);
55         msr.hi &= 0xfffffff0;
56         msr.hi |= 0x00000000;
57         msr.lo &= 0x00000f00;
58         msr.lo |= 0x00000000 | MTRR_TYPE_WRBACK;
59         wrmsr(0x200, msr);
60
61         msr = rdmsr(0x201);
62         msr.hi &= 0xfffffff0;
63         msr.hi |= 0x0000000f;
64         msr.lo &= 0x000007ff;
65         msr.lo |= (~((CONFIG_LB_MEM_TOPK << 10) - 1)) | 0x800;
66         wrmsr(0x201, msr);
67
68 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
69         /* enable write through caching so we can do execute in place
70          * on the flash rom.
71          */
72         msr.hi = 0x00000000;
73         msr.lo = XIP_ROM_BASE | MTRR_TYPE_WRTHROUGH;
74         wrmsr(0x202, msr);
75 #error "FIXME verify the type of MTRR I have setup"
76         msr.hi = 0x0000000f;
77         msr.lo = ~(XIP_ROM_SIZE - 1) | 0x800;
78         wrmsr(0x203, msr);
79 #endif
80
81         /* Set the default memory type and enable fixed and variable MTRRs 
82          */
83         /* Enable Variable MTRRs */
84         msr.hi = 0x00000000;
85         msr.lo = 0x00000800;
86         wrmsr(MTRRdefType_MSR, msr);
87         
88         /* Enale the MTRRs in SYSCFG */
89         msr = rdmsr(SYSCFG_MSR);
90         msr.lo |= SYSCFG_MSR_MtrrVarDramEn;
91         wrmsr(SYSCFG_MSR, msr);
92
93         /* Enable the cache */
94         unsigned long cr0;
95         cr0 = read_cr0();
96         cr0 &= 0x9fffffff;
97         write_cr0(cr0);
98 }