2 * This file is part of the coreboot project.
4 * Copyright (C) 2005-2007 Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Carl-Daniel Hailfinger
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #define CacheSize CONFIG_DCACHE_RAM_SIZE
22 #define CacheBase (0xd0000 - CacheSize)
24 /* leave some space for global variable to pass to RAM stage */
25 #define GlobalVarSize CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE
27 /* for CAR with FAM10 */
28 #define CacheSizeAPStack 0x400 /* 1K */
30 #define MSR_FAM10 0xC001102A
32 #define jmp_if_k8(x) comisd %xmm2, %xmm1; jb x
34 #define CPUID_MASK 0x0ff00f00
35 #define CPUID_VAL_FAM10_ROTATED 0x0f000010
37 #include <cpu/x86/mtrr.h>
38 #include <cpu/amd/mtrr.h>
42 * xmm2: fam10 comparison value
46 /* Save the BIST result */
49 /* for normal part %ebx already contain cpu_init_detected from fallback call */
59 /* figure out cpu family */
63 /* base family is bits 8..11, extended family is bits 20..27 */
64 andl $CPUID_MASK, %eax
65 /* reorder bits for easier comparison by value */
68 movl $CPUID_VAL_FAM10_ROTATED, %eax
72 /* check if cpu_init_detected */
73 movl $MTRRdefType_MSR, %ecx
76 movl %eax, %ebx /* We store the status */
78 jmp_if_k8(CAR_FAM10_out_post_errata)
80 /* for GH, CAR need to set DRAM Base/Limit Registers to direct that to node0 */
82 /* Only BSP needed, for other nodes set during HT/memory init. */
83 /* So we need to check if it is BSP */
89 /* Enable RT tables on BSP */
90 movl $0x8000c06c, %eax
98 /* Setup temporary DRAM map: [0,16M) bit 0-23 */
99 movl $0x8000c144, %eax
106 movl $0x8000c140, %eax
115 /* Errata 193: Disable clean copybacks to L3 cache to allow cached ROM.
116 * Re-enable it in after RAM is initialized and before CAR is disabled
118 movl $0xc001102a, %ecx
123 /* Erratum 343, RevGuide for Fam10h, Pub#41322 Rev. 3.33 */
125 /* read-address has to be stored in the ecx register */
126 movl $MSR_FAM10, %ecx
128 /* execute special read command for msr-register. Result is then in the EDX:EAX-registers (MSBs in EDX) */
131 /* Set bit 35 to 1 in EAX */
134 /* write back the modified register EDX:EAX to the MSR specified in ECX */
137 /* Erratum 343 end */
139 CAR_FAM10_out_post_errata:
141 /* Set MtrrFixDramModEn for clear fixed mtrr */
142 enable_fixed_mtrr_dram_modify:
143 movl $SYSCFG_MSR, %ecx
145 andl $(~(SYSCFG_MSR_MtrrFixDramEn | SYSCFG_MSR_MtrrVarDramEn)), %eax
146 orl $SYSCFG_MSR_MtrrFixDramModEn, %eax
149 /* Clear all MTRRs */
151 movl $fixed_mtrr_msr, %esi
153 clear_fixed_var_mtrr:
156 jz clear_fixed_var_mtrr_out
162 jmp clear_fixed_var_mtrr
163 clear_fixed_var_mtrr_out:
165 /* 0x06 is the WB IO type for a given 4k segment.
166 * 0x1e is the MEM IO type for a given 4k segment (K10 and above).
167 * segs is the number of 4k segments in the area of the particular
168 * register we want to use for CAR.
169 * reg is the register where the IO type should be stored.
171 .macro extractmask segs, reg
173 /* The xorl here is superfluous because at the point of first execution
174 * of this macro, %eax and %edx are cleared. Later invocations of this
175 * macro will have a monotonically increasing segs parameter.
182 movl $0x1e000000, \reg /* WB MEM type */
184 movl $0x1e1e0000, \reg /* WB MEM type */
186 movl $0x1e1e1e00, \reg /* WB MEM type */
188 movl $0x1e1e1e1e, \reg /* WB MEM type */
193 movl $0x06000000, \reg /* WB IO type */
195 movl $0x06060000, \reg /* WB IO type */
197 movl $0x06060600, \reg /* WB IO type */
199 movl $0x06060606, \reg /* WB IO type */
202 .endif /* if \segs <= 0 */
205 /* size is the cache size in bytes we want to use for CAR.
206 * windowoffset is the 32k-aligned window into CAR size
208 .macro simplemask carsize, windowoffset
209 .set gas_bug_workaround,(((\carsize - \windowoffset) / 0x1000) - 4)
210 extractmask gas_bug_workaround, %eax
211 .set gas_bug_workaround,(((\carsize - \windowoffset) / 0x1000))
212 extractmask gas_bug_workaround, %edx
213 /* Without the gas bug workaround, the entire macro would consist only of the
215 extractmask (((\carsize - \windowoffset) / 0x1000) - 4), %eax
216 extractmask (((\carsize - \windowoffset) / 0x1000)), %edx
220 #if CacheSize > 0x10000
221 #error Invalid CAR size, must be at most 64k.
223 #if CacheSize < 0x1000
224 #error Invalid CAR size, must be at least 4k. This is a processor limitation.
226 #if (CacheSize & (0x1000 - 1))
227 #error Invalid CAR size, is not a multiple of 4k. This is a processor limitation.
230 #if CacheSize > 0x8000
231 /* enable caching for 32K-64K using fixed mtrr */
232 movl $0x268, %ecx /* fix4k_c0000*/
233 simplemask CacheSize, 0x8000
237 /* enable caching for 0-32K using fixed mtrr */
238 movl $0x269, %ecx /* fix4k_c8000*/
239 simplemask CacheSize, 0
242 /* enable memory access for first MBs using top_mem */
245 movl $(((CONFIG_RAMTOP) + TOP_MEM_MASK) & ~TOP_MEM_MASK) , %eax
248 #if defined(CONFIG_XIP_ROM_SIZE) && defined(CONFIG_XIP_ROM_BASE)
249 /* enable write base caching so we can do execute in place
255 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
256 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
258 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
260 movl $REAL_XIP_ROM_BASE, %eax
261 orl $MTRR_TYPE_WRBACK, %eax
265 movl $0xff, %edx /* (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1 for K8 (CONFIG_CPU_ADDR_BITS = 40) */
266 jmp_if_k8(wbcache_post_fam10_setup)
267 movl $0xffff, %edx /* (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1 for FAM10 (CONFIG_CPU_ADDR_BITS = 48) */
268 wbcache_post_fam10_setup:
269 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | 0x800), %eax
271 #endif /* CONFIG_XIP_ROM_SIZE && CONFIG_XIP_ROM_BASE */
273 /* Set the default memory type and enable fixed and variable MTRRs */
274 movl $MTRRdefType_MSR, %ecx
276 /* Enable Variable and Fixed MTRRs */
277 movl $0x00000c00, %eax
280 /* Enable the MTRRs and IORRs in SYSCFG */
281 movl $SYSCFG_MSR, %ecx
283 orl $(SYSCFG_MSR_MtrrVarDramEn | SYSCFG_MSR_MtrrFixDramEn), %eax
290 andl $0x9fffffff, %eax
293 jmp_if_k8(fam10_end_part1)
295 /* So we need to check if it is BSP */
304 /* Read the range with lodsl*/
306 movl $CacheBase, %esi
307 movl $(CacheSize >> 2), %ecx
310 /* Clear the range */
311 movl $CacheBase, %edi
312 movl $(CacheSize >> 2), %ecx
316 /* set up the stack pointer */
317 movl $(CacheBase + CacheSize - GlobalVarSize), %eax
324 /* need to set stack pointer for AP */
325 /* it will be from CacheBase + (CacheSize - GlobalVarSize)/2 - (NodeID<<CoreIDbits + CoreID) * CacheSizeAPStack*/
326 /* So need to get the NodeID and CoreID at first */
327 /* If NB_CFG bit 54 is set just use initial apicid, otherwise need to reverse it */
329 /* store our init detected */
332 /* get the coreid bits at first */
333 movl $0x80000008, %eax
339 /* get the initial apic id */
344 /* get the nb cfg bit 54 */
345 movl $0xc001001f, %ecx /* NB_CFG_MSR */
347 movl %edi, %ecx /* CoreID bits */
353 /* calculate stack pointer */
354 movl $CacheSizeAPStack, %eax
356 movl $(CacheBase + (CacheSize - GlobalVarSize)/2), %esp
359 /* retrive init detected */
373 /* Restore the BIST result */
376 /* We need to set ebp ? No need */
378 pushl %ebx /* init detected */
379 pushl %eax /* bist */
380 call cache_as_ram_main
381 /* We will not go back */
383 post_code(0xaf) /* Should never see this postcode */
386 .long 0x250, 0x258, 0x259
387 .long 0x268, 0x269, 0x26A
388 .long 0x26B, 0x26C, 0x26D
391 .long 0x200, 0x201, 0x202, 0x203
392 .long 0x204, 0x205, 0x206, 0x207
393 .long 0x208, 0x209, 0x20A, 0x20B
394 .long 0x20C, 0x20D, 0x20E, 0x20F
396 .long 0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019
398 .long 0xC001001A, 0xC001001D
399 .long 0x000 /* NULL, end of table */
401 cache_as_ram_setup_out: