2 * Copyright (c) 2014 Google, Inc
4 * From Coreboot file cpu/intel/model_206ax/cache_as_ram.inc
7 * Copyright (C) 2005 Tyan (written by Yinghai Lu for Tyan)
8 * Copyright (C) 2007-2008 coresystems GmbH
11 * SPDX-License-Identifier: GPL-2.0
15 #include <asm/msr-index.h>
18 #include <asm/processor.h>
19 #include <asm/processor-flags.h>
20 #include <asm/arch/microcode.h>
22 #define MTRR_PHYS_BASE_MSR(reg) (0x200 + 2 * (reg))
23 #define MTRR_PHYS_MASK_MSR(reg) (0x200 + 2 * (reg) + 1)
25 #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
26 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
28 /* Cache 4GB - MRC_SIZE_KB for MRC */
29 #define CACHE_MRC_BYTES ((CONFIG_CACHE_MRC_SIZE_KB << 10) - 1)
30 #define CACHE_MRC_BASE (0xFFFFFFFF - CACHE_MRC_BYTES)
31 #define CACHE_MRC_MASK (~CACHE_MRC_BYTES)
33 #define CPU_PHYSMASK_HI (1 << (CONFIG_CPU_ADDR_BITS - 32) - 1)
35 #define NOEVICTMOD_MSR 0x2e0
38 * Note: ebp must not be touched in this code as it holds the BIST
39 * value (built-in self test). We preserve this value until it can
40 * be written to global_data when CAR is ready for use.
44 post_code(POST_CAR_START)
46 /* Send INIT IPI to all excluding ourself */
47 movl $0x000C4500, %eax
48 movl $0xFEE00300, %esi
51 /* TODO: Load microcode later - the 'no eviction' mode breaks this */
52 movl $MSR_IA32_UCODE_WRITE, %ecx
54 movl $_dt_ucode_base_size, %eax
56 addl $UCODE_HEADER_LEN, %eax
59 post_code(POST_CAR_SIPI)
60 /* Zero out all fixed range and variable range MTRRs */
61 movl $mtrr_table, %esi
62 movl $((mtrr_table_end - mtrr_table) / 2), %edi
73 post_code(POST_CAR_MTRR)
74 /* Configure the default memory type to uncacheable */
75 movl $MTRR_DEF_TYPE_MSR, %ecx
77 andl $(~0x00000cff), %eax
80 post_code(POST_CAR_UNCACHEABLE)
81 /* Set Cache-as-RAM base address */
82 movl $(MTRR_PHYS_BASE_MSR(0)), %ecx
83 movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
87 post_code(POST_CAR_BASE_ADDRESS)
88 /* Set Cache-as-RAM mask */
89 movl $(MTRR_PHYS_MASK_MSR(0)), %ecx
90 movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax
91 movl $CPU_PHYSMASK_HI, %edx
94 post_code(POST_CAR_MASK)
97 movl $MTRR_DEF_TYPE_MSR, %ecx
99 orl $MTRR_DEF_TYPE_EN, %eax
102 /* Enable cache (CR0.CD = 0, CR0.NW = 0) */
104 andl $(~(X86_CR0_CD | X86_CR0_NW)), %eax
108 /* enable the 'no eviction' mode */
109 movl $NOEVICTMOD_MSR, %ecx
115 /* Clear the cache memory region. This will also fill up the cache */
116 movl $CACHE_AS_RAM_BASE, %esi
118 movl $(CACHE_AS_RAM_SIZE / 4), %ecx
122 /* enable the 'no eviction run' state */
123 movl $NOEVICTMOD_MSR, %ecx
128 post_code(POST_CAR_FILL)
129 /* Enable Cache-as-RAM mode by disabling cache */
131 orl $X86_CR0_CD, %eax
134 /* Enable cache for our code in Flash because we do XIP here */
135 movl $MTRR_PHYS_BASE_MSR(1), %ecx
137 movl $car_init_ret, %eax
138 andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
139 orl $MTRR_TYPE_WRPROT, %eax
142 movl $MTRR_PHYS_MASK_MSR(1), %ecx
143 movl $CPU_PHYSMASK_HI, %edx
144 movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax
147 post_code(POST_CAR_ROM_CACHE)
148 #ifdef CONFIG_CACHE_MRC_BIN
149 /* Enable caching for ram init code to run faster */
150 movl $MTRR_PHYS_BASE_MSR(2), %ecx
151 movl $(CACHE_MRC_BASE | MTRR_TYPE_WRPROT), %eax
154 movl $MTRR_PHYS_MASK_MSR(2), %ecx
155 movl $(CACHE_MRC_MASK | MTRR_PHYS_MASK_VALID), %eax
156 movl $CPU_PHYSMASK_HI, %edx
160 post_code(POST_CAR_MRC_CACHE)
163 andl $(~(X86_CR0_CD | X86_CR0_NW)), %eax
166 post_code(POST_CAR_CPU_CACHE)
168 /* All CPUs need to be in Wait for SIPI state */
181 orl $X86_CR0_CD, %eax
185 movl $MTRR_DEF_TYPE_MSR, %ecx
187 andl $(~MTRR_DEF_TYPE_EN), %eax
190 /* Disable the no-eviction run state */
191 movl NOEVICTMOD_MSR, %ecx
198 /* Disable the no-eviction mode */
203 #ifdef CONFIG_CACHE_MRC_BIN
204 /* Clear the MTRR that was used to cache MRC */
207 movl $MTRR_PHYS_BASE_MSR(2), %ecx
209 movl $MTRR_PHYS_MASK_MSR(2), %ecx
214 movl $MTRR_DEF_TYPE_MSR, %ecx
216 orl $MTRR_DEF_TYPE_EN, %eax
225 .word 0x250, 0x258, 0x259
226 .word 0x268, 0x269, 0x26A
227 .word 0x26B, 0x26C, 0x26D
230 .word 0x200, 0x201, 0x202, 0x203
231 .word 0x204, 0x205, 0x206, 0x207
232 .word 0x208, 0x209, 0x20A, 0x20B
233 .word 0x20C, 0x20D, 0x20E, 0x20F
234 .word 0x210, 0x211, 0x212, 0x213
239 /* These next two fields are filled in by ifdtool */
240 .long 0 /* microcode base */
241 .long 0 /* microcode size */