1 #include <cpu/p6/mtrr.h>
2 #include <cpu/p6/msr.h>
4 static inline unsigned long read_cr0(void)
7 asm volatile ("movl %%cr0, %0" : "=r" (cr0));
11 static inline void write_cr0(unsigned long cr0)
13 asm volatile ("movl %0, %%cr0" : : "r" (cr0));
16 /* the fixed and variable MTTRs are power-up with random values,
17 * clear them to MTRR_TYPE_UNCACHEABLE for safty.
20 static void early_mtrr_init(void)
22 static const unsigned long mtrr_msrs[] = {
29 0x200, 0x201, 0x202, 0x203,
30 0x204, 0x205, 0x206, 0x207,
31 0x208, 0x209, 0x20A, 0x20B,
32 0x20C, 0x20D, 0x20E, 0x20F,
33 /* NULL end of table */
37 const unsigned long *msr_addr;
40 print_debug("Disabling cache\r\n");
41 /* Just to be sure, take all the steps to disable the cache.
42 * This may not be needed, but C3's may...
43 * Invalidate the cache */
44 asm volatile ("invd");
46 /* Disable the cache */
51 /* Disable Variable MTRRs */
54 wrmsr(MTRRdefType_MSR, msr);
56 /* Invalidate the cache again */
57 asm volatile ("invd");
59 print_debug("Clearing mtrr\r\n");
61 /* Inialize all of the relevant msrs to 0 */
64 for(msr_addr = mtrr_msrs; *msr_addr; msr_addr++) {
65 wrmsr(*msr_addr, msr);
68 /* Enable caching for 0 - 1MB using variable mtrr */
73 msr.lo |= 0x00000000 | MTRR_TYPE_WRBACK;
80 msr.lo |= (~((CONFIG_LB_MEM_TOPK << 10) - 1)) | 0x800;
83 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
84 print_debug("Setting XIP\r\n");
85 /* enable write through caching so we can do execute in place
89 msr.lo = XIP_ROM_BASE | MTRR_TYPE_WRTHROUGH;
92 msr.lo = ~(XIP_ROM_SIZE - 1) | 0x800;
96 /* Set the default memory type and enable fixed and variable MTRRs
98 /* Enable Variable MTRRs */
101 wrmsr(MTRRdefType_MSR, msr);
103 /* Enable the cache */
107 print_debug("Enabled the cache\r\n");