2 * This file is part of the coreboot project.
4 * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5 * Copyright (C) 2005 Eswar Nallusamy, LANL
6 * Copyright (C) 2005 Tyan
7 * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
8 * Copyright (C) 2007 coresystems GmbH
9 * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
10 * Copyright (C) 2007,2008 Carl-Daniel Hailfinger
11 * Copyright (C) 2008 VIA Technologies, Inc.
12 * (Written by Jason Zhao <jasonzhao@viatech.com.cn> for VIA)
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; version 2 of the License.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <cpu/x86/car.h>
29 #include <cpu/x86/stack.h>
30 #include <cpu/x86/mtrr.h>
32 #define CacheSize CONFIG_DCACHE_RAM_SIZE
33 #define CacheBase CONFIG_DCACHE_RAM_BASE
42 /* Set the default memory type and enable fixed and variable MTRRs. */
43 movl $MTRRdefType_MSR, %ecx
45 movl $(MTRRdefTypeEn | MTRRdefTypeFixEn), %eax
48 /* Clear all MTRRs. */
50 movl $all_mtrr_msrs, %esi
55 jz clear_fixed_var_mtrr_out
61 jmp clear_fixed_var_mtrr
65 .long MTRRfix64K_00000_MSR
66 .long MTRRfix16K_80000_MSR
67 .long MTRRfix16K_A0000_MSR
68 .long MTRRfix4K_C0000_MSR
69 .long MTRRfix4K_C8000_MSR
70 .long MTRRfix4K_D0000_MSR
71 .long MTRRfix4K_D8000_MSR
72 .long MTRRfix4K_E0000_MSR
73 .long MTRRfix4K_E8000_MSR
74 .long MTRRfix4K_F0000_MSR
75 .long MTRRfix4K_F8000_MSR
78 .long MTRRphysBase_MSR(0)
79 .long MTRRphysMask_MSR(0)
80 .long MTRRphysBase_MSR(1)
81 .long MTRRphysMask_MSR(1)
82 .long MTRRphysBase_MSR(2)
83 .long MTRRphysMask_MSR(2)
84 .long MTRRphysBase_MSR(3)
85 .long MTRRphysMask_MSR(3)
86 .long MTRRphysBase_MSR(4)
87 .long MTRRphysMask_MSR(4)
88 .long MTRRphysBase_MSR(5)
89 .long MTRRphysMask_MSR(5)
90 .long MTRRphysBase_MSR(6)
91 .long MTRRphysMask_MSR(6)
92 .long MTRRphysBase_MSR(7)
93 .long MTRRphysMask_MSR(7)
95 .long 0x000 /* NULL, end of table */
97 clear_fixed_var_mtrr_out:
98 movl $MTRRphysBase_MSR(0), %ecx
100 movl $(CacheBase | MTRR_TYPE_WRBACK), %eax
103 movl $MTRRphysMask_MSR(0), %ecx
104 /* This assumes we never access addresses above 2^36 in CAR. */
105 movl $0x0000000f, %edx
106 movl $(~(CacheSize - 1) | MTRRphysMaskValid), %eax
109 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
110 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
112 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
116 * Enable write base caching so we can do execute in place (XIP)
119 movl $MTRRphysBase_MSR(1), %ecx
122 * IMPORTANT: The two lines below can _not_ be written like this:
123 * movl $(REAL_XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
124 * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
126 movl $REAL_XIP_ROM_BASE, %eax
127 orl $MTRR_TYPE_WRBACK, %eax
130 movl $MTRRphysMask_MSR(1), %ecx
131 movl $0x0000000f, %edx
132 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
135 /* Set the default memory type and enable fixed and variable MTRRs. */
136 /* TODO: Or also enable fixed MTRRs? Bug in the code? */
137 movl $MTRRdefType_MSR, %ecx
139 movl $(MTRRdefTypeEn), %eax
144 /* Read the range with lodsl. */
146 movl $CacheBase, %esi
148 movl $(CacheSize >> 2), %ecx
151 movl $CacheBase, %esi
153 movl $(CacheSize >> 2), %ecx
156 * 0x5c5c5c5c is a memory test pattern.
157 * TODO: Check if everything works with the zero pattern as well.
159 /* xorl %eax, %eax */
160 xorl $0x5c5c5c5c, %eax
164 movl REAL_XIP_ROM_BASE, %esi
166 movl $(CONFIG_XIP_ROM_SIZE >> 2), %ecx
171 * The key point of this CAR code is C7 cache does not turn into
172 * "no fill" mode, which is not compatible with general CAR code.
175 movl $(CacheBase + CacheSize - 4), %eax
198 restore_bist_result()
200 /* We need to set EBP? No need. */
202 pushl %eax /* BIST */
206 * TODO: Backup stack in CACHE_AS_RAM into MMX and SSE and after we
207 * get STACK up, we restore that. It is only needed if we
211 /* We don't need CAR from now on. */
215 /* Set the default memory type and enable variable MTRRs. */
216 /* TODO: Or also enable fixed MTRRs? Bug in the code? */
217 movl $MTRRdefType_MSR, %ecx
219 movl $(MTRRdefTypeEn), %eax
222 /* Enable caching for CONFIG_RAMBASE..CONFIG_RAMTOP. */
223 movl $MTRRphysBase_MSR(0), %ecx
225 movl $(CONFIG_RAMBASE | MTRR_TYPE_WRBACK), %eax
228 movl $MTRRphysMask_MSR(0), %ecx
229 movl $0x0000000f, %edx /* AMD 40 bit 0xff */
230 movl $(~(CONFIG_RAMTOP - CONFIG_RAMBASE - 1) | MTRRphysMaskValid), %eax
233 /* Cache XIP_ROM_BASE-SIZE to speedup coreboot code. */
234 movl $MTRRphysBase_MSR(1), %ecx
236 movl $REAL_XIP_ROM_BASE, %eax
237 orl $MTRR_TYPE_WRBACK, %eax
240 movl $MTRRphysMask_MSR(1), %ecx
242 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
248 /* Clear boot_complete flag. */
252 cld /* Clear direction flag. */
256 movl $ROMSTAGE_STACK, %esp