Debian Codegraph @

src/cpu/intel/car/non-evict/cache_as_ram.S

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cpu/intel/post_codes.h>
4 #include <cpu/x86/mtrr.h>
5 #include <cpu/x86/cache.h>
6 #include <cpu/x86/post_code.h>
7 #include <cpu/x86/64bit/entry64.inc>
8
9 #define NoEvictMod_MSR 0x2e0
10 #define BBL_CR_CTL3_MSR 0x11e
11
12 .section .init
13 .global bootblock_pre_c_entry
14
15 #include <cpu/intel/car/cache_as_ram_symbols.inc>
16
17 .code32
18 _cache_as_ram_setup:
19
20 bootblock_pre_c_entry:
21 movl $cache_as_ram, %esp /* return address */
22 jmp check_mtrr /* Check if CPU properly reset */
23
24 cache_as_ram:
25 post_code(POSTCODE_BOOTBLOCK_CAR)
26
27 /* Send INIT IPI to all excluding ourself. */
28 movl $0x000C4500, %eax
29 movl $0xFEE00300, %esi
30 movl %eax, (%esi)
31
32 /* All CPUs need to be in Wait for SIPI state */
33 wait_for_sipi:
34 movl (%esi), %eax
35 bt $12, %eax
36 jc wait_for_sipi
37
38 post_code(POSTCODE_SOC_SET_DEF_MTRR_TYPE)
39 /* Clean-up MTRR_DEF_TYPE_MSR. */
40 movl $MTRR_DEF_TYPE_MSR, %ecx
41 xorl %eax, %eax
42 xorl %edx, %edx
43 wrmsr
44
45 post_code(POSTCODE_SOC_CLEAR_FIXED_MTRRS)
46 /* Clear/disable fixed MTRRs */
47 mov $fixed_mtrr_list, %ebx
48 xor %eax, %eax
49 xor %edx, %edx
50
51 clear_fixed_mtrr:
52 movzwl (%ebx), %ecx
53 wrmsr
54 add $2, %ebx
55 cmp $fixed_mtrr_list_end, %ebx
56 jl clear_fixed_mtrr
57
58 /* Zero out all variable range MTRRs. */
59 movl $MTRR_CAP_MSR, %ecx
60 rdmsr
61 andl $0xff, %eax
62 shl $1, %eax
63 movl %eax, %edi
64 movl $0x200, %ecx
65 xorl %eax, %eax
66 xorl %edx, %edx
67 clear_var_mtrrs:
68 wrmsr
69 add $1, %ecx
70 dec %edi
71 jnz clear_var_mtrrs
72
73 /* Determine CPU_ADDR_BITS and load PHYSMASK high word to %edx. */
74 movl $0x80000008, %eax
75 cpuid
76 movb %al, %cl
77 sub $32, %cl
78 movl $1, %edx
79 shl %cl, %edx
80 subl $1, %edx
81
82 /* Preload high word of address mask (in %edx) for Variable
83 * MTRRs 0 and 1.
84 */
85 addrsize_set_high:
86 xorl %eax, %eax
87 movl $MTRR_PHYS_MASK(0), %ecx
88 wrmsr
89 movl $MTRR_PHYS_MASK(1), %ecx
90 wrmsr
91
92 post_code(POSTCODE_SOC_SET_MTRR_BASE)
93 /* Set Cache-as-RAM base address. */
94 movl $(MTRR_PHYS_BASE(0)), %ecx
95 movl car_mtrr_start, %eax
96 orl $MTRR_TYPE_WRBACK, %eax
97 xorl %edx, %edx
98 wrmsr
99
100 post_code(POSTCODE_SOC_SET_MTRR_MASK)
101 /* Set Cache-as-RAM mask. */
102 movl $(MTRR_PHYS_MASK(0)), %ecx
103 rdmsr
104 mov car_mtrr_mask, %eax
105 orl $MTRR_PHYS_MASK_VALID, %eax
106 wrmsr
107
108 /* Enable cache for our code in Flash because we do XIP here */
109 movl $MTRR_PHYS_BASE(1), %ecx
110 xorl %edx, %edx
111 mov rom_mtrr_base, %eax
112 orl $MTRR_TYPE_WRPROT, %eax
113 wrmsr
114
115 movl $MTRR_PHYS_MASK(1), %ecx
116 rdmsr
117 mov rom_mtrr_mask, %eax
118 orl $MTRR_PHYS_MASK_VALID, %eax
119 wrmsr
120
121 post_code(POSTCODE_SOC_ENABLE_MTRRS)
122
123 /* Enable MTRR. */
124 movl $MTRR_DEF_TYPE_MSR, %ecx
125 rdmsr
126 orl $MTRR_DEF_TYPE_EN, %eax
127 wrmsr
128
129 #if CONFIG(CPU_HAS_L2_ENABLE_MSR)
130 /*
131 * Enable the L2 cache. Currently this assumes that this
132 * only affect socketed CPU's for which this is always valid,
133 * hence the static preprocesser.
134 */
135 movl $BBL_CR_CTL3_MSR, %ecx
136 rdmsr
137 orl $0x100, %eax
138 wrmsr
139 #endif
140
141 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
142 movl %cr0, %eax
143 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
144 invd
145 movl %eax, %cr0
146
147 #if CONFIG(MICROCODE_UPDATE_PRE_RAM)
148 update_microcode:
149 /* put the return address in %esp */
150 movl $end_microcode_update, %esp
151 jmp update_bsp_microcode
152 end_microcode_update:
153 #endif
154
155 /* Disable caching. */
156 movl %cr0, %eax
157 orl $CR0_CacheDisable, %eax
158 movl %eax, %cr0
159
160 invd
161
162 /* Enable caching */
163 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
164 movl %eax, %cr0
165
166 /* enable the 'no eviction' mode */
167 movl $NoEvictMod_MSR, %ecx
168 rdmsr
169 orl $1, %eax
170 andl $~2, %eax
171 wrmsr
172
173 /* Fill up the cache next. */
174 movl $_car_mtrr_start, %edi
175
176 /* Number of loops. */
177 movl $_car_mtrr_size, %ecx
178 shr $6, %ecx
179 xorl %ebx, %ebx
180 mov $64, %bl
181
182 1:
183 /*
184 * BWG: *One* location in each 64-byte cache line must be written
185 * to set all cached values to modified state.
186 *
187 * Value of %eax doesn't matter here. CAR is zeroed later.
188 *
189 * Zeroing the whole cache here *not* work when CR0.CD = 0.
190 * Zeroing the whole cache here *does* work when CR0.CD = 1,
191 * but will be a couple of times slower (4 times on Sandy Bridge).
192 */
193 movl %eax, (%edi)
194 addl %ebx, %edi
195
196 loop 1b
197
198 /* enable the 'no eviction run' state. */
199 movl $NoEvictMod_MSR, %ecx
200 rdmsr
201 or $3, %al
202 wrmsr
203
204 post_code(POSTCODE_SOC_ENABLE_CACHE)
205
206 /* Now that CAR is enabled clear it. */
207 movl $_car_mtrr_start, %edi
208 movl $_car_mtrr_size, %ecx
209 cld
210 xorl %eax, %eax
211 shr $2, %ecx
212 rep stosl
213
214 /* Setup the stack. */
215 mov $_ecar_stack, %esp
216
217 /* Need to align stack to 16 bytes at call instruction. Account for
218 the pushes below. */
219 andl $0xfffffff0, %esp
220
221 #if ENV_X86_64
222 setup_longmode $PML4E
223
224 movd %mm2, %rdi
225 shlq $32, %rdi
226 movd %mm1, %rsi
227 or %rsi, %rdi
228 movd %mm0, %rsi
229
230 #else
231 subl $4, %esp
232 /* push TSC and BIST to stack */
233 movd %mm0, %eax
234 pushl %eax /* BIST */
235 movd %mm2, %eax
236 pushl %eax /* tsc[63:32] */
237 movd %mm1, %eax
238 pushl %eax /* tsc[31:0] */
239 #endif
240
241 /* Copy .data section content to Cache-As-Ram */
242 #include <cpu/x86/copy_data_section.inc>
243
244 before_c_entry:
245 post_code(POSTCODE_BOOTBLOCK_BEFORE_C_ENTRY)
246 call bootblock_c_entry_bist
247
248 /* Should never see this postcode */
249 post_code(POSTCODE_DEAD_CODE)
250
251
252 .Lhlt:
253 hlt
254 jmp .Lhlt
255
256 fixed_mtrr_list:
257 .word MTRR_FIX_64K_00000
258 .word MTRR_FIX_16K_80000
259 .word MTRR_FIX_16K_A0000
260 .word MTRR_FIX_4K_C0000
261 .word MTRR_FIX_4K_C8000
262 .word MTRR_FIX_4K_D0000
263 .word MTRR_FIX_4K_D8000
264 .word MTRR_FIX_4K_E0000
265 .word MTRR_FIX_4K_E8000
266 .word MTRR_FIX_4K_F0000
267 .word MTRR_FIX_4K_F8000
268 fixed_mtrr_list_end:
269
270 _cache_as_ram_setup_end: