1 /* SPDX-License-Identifier: GPL-2.0-only */
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/lapic_def.h>
9 /* Macro to access Local APIC registers at default base. */
10 #define LAPIC(x) $(LAPIC_DEFAULT_BASE | LAPIC_ ## x)
13 .global bootblock_pre_c_entry
15 #include <cpu/intel/car/cache_as_ram_symbols.inc>
20 bootblock_pre_c_entry:
23 post_code(POST_BOOTBLOCK_CAR)
25 movl $LAPIC_BASE_MSR, %ecx
27 andl $LAPIC_BASE_MSR_BOOTSTRAP_PROCESSOR, %eax
30 /* Clear/disable fixed MTRRs */
31 mov $fixed_mtrr_list, %ebx
39 cmp $fixed_mtrr_list_end, %ebx
42 /* Figure out how many MTRRs we have, and clear them out */
43 mov $MTRR_CAP_MSR, %ecx
45 movzb %al, %ebx /* Number of variable MTRRs */
46 mov $MTRR_PHYS_BASE(0), %ecx
57 post_code(POST_SOC_SET_DEF_MTRR_TYPE)
59 /* Configure the default memory type to uncacheable. */
60 movl $MTRR_DEF_TYPE_MSR, %ecx
62 andl $(~0x00000cff), %eax
65 post_code(POST_SOC_DETERMINE_CPU_ADDR_BITS)
67 /* Determine CPU_ADDR_BITS and load PHYSMASK high
70 movl $0x80000000, %eax
72 cmpl $0x80000008, %eax
74 movl $0x80000008, %eax
85 andl $(1 << 6 | 1 << 17), %edx /* PAE or PSE36 */
89 /* Preload high word of address mask (in %edx) for Variable
90 * MTRRs 0 and 1 and enable local APIC at default base.
94 movl $MTRR_PHYS_MASK(0), %ecx
96 movl $MTRR_PHYS_MASK(1), %ecx
98 movl $LAPIC_BASE_MSR, %ecx
103 andl $(~LAPIC_BASE_MSR_ADDR_MASK), %eax
104 orl $(LAPIC_DEFAULT_BASE | LAPIC_BASE_MSR_ENABLE), %eax
109 post_code(POST_SOC_BSP_INIT)
111 /* Send INIT IPI to all excluding ourself. */
112 movl LAPIC(ICR), %edi
113 movl $(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_INIT), %eax
120 andl $LAPIC_ICR_BUSY, %ecx
123 post_code(POST_SOC_COUNT_CORES)
132 jbe sipi_complete /* only one LAPIC ID in package */
150 jbe sipi_complete /* only LAPIC ID of a core */
152 /* For a hyper-threading processor, cache must not be disabled
153 * on an AP on the same physical package with the BSP.
158 post_code(POST_SOC_CPU_HYPER_THREADING)
160 /* Send Start IPI to all excluding ourself. */
161 movl LAPIC(ICR), %edi
162 movl $(LAPIC_DEST_ALLBUT | LAPIC_DM_STARTUP), %eax
163 orl $ap_sipi_vector_in_rom, %eax
170 andl $LAPIC_ICR_BUSY, %ecx
173 post_code(POST_SOC_CPU_SIBLING_DELAY)
175 /* Wait for sibling CPU to start. */
176 1: movl $(MTRR_PHYS_BASE(0)), %ecx
189 post_code(POST_SOC_CPU_AP_INIT)
191 /* Do not disable cache (so BSP can enable it). */
193 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
196 post_code(POST_SOC_SET_MTRR_BASE)
198 /* MTRR registers are shared between HT siblings. */
199 movl $(MTRR_PHYS_BASE(0)), %ecx
200 movl $(1 << 12), %eax
204 post_code(POST_SOC_AP_HALT)
215 post_code(POST_SOC_SET_CAR_BASE)
217 /* Set Cache-as-RAM base address. */
218 movl $(MTRR_PHYS_BASE(0)), %ecx
219 movl car_mtrr_start, %eax
220 orl $MTRR_TYPE_WRBACK, %eax
224 /* Set Cache-as-RAM mask. */
225 movl $(MTRR_PHYS_MASK(0)), %ecx
227 movl car_mtrr_mask, %eax
228 orl $MTRR_PHYS_MASK_VALID, %eax
231 post_code(POST_SOC_ENABLE_MTRRS)
234 movl $MTRR_DEF_TYPE_MSR, %ecx
236 orl $MTRR_DEF_TYPE_EN, %eax
239 /* Enable L2 cache Write-Back (WBINVD and FLUSH#).
241 * MSR is set when DisplayFamily_DisplayModel is one of:
242 * 06_0x, 06_17, 06_1C
244 * Description says this bit enables use of WBINVD and FLUSH#.
245 * Should this be set only after the system bus and/or memory
246 * controller can successfully handle write cycles?
249 #define EAX_FAMILY(a) (a << 8) /* for family <= 0fH */
250 #define EAX_MODEL(a) (((a & 0xf0) << 12) | ((a & 0xf) << 4))
255 andl $EAX_FAMILY(0x0f), %eax
256 cmpl $EAX_FAMILY(0x06), %eax
259 andl $EAX_MODEL(0xff), %eax
260 cmpl $EAX_MODEL(0x17), %eax
262 cmpl $EAX_MODEL(0x1c), %eax
264 andl $EAX_MODEL(0xf0), %eax
265 cmpl $EAX_MODEL(0x00), %eax
274 post_code(POST_SOC_ENABLE_CACHE)
276 /* Cache the whole rom to fetch microcode updates */
277 movl $MTRR_PHYS_BASE(1), %ecx
279 movl rom_mtrr_base, %eax
280 orl $MTRR_TYPE_WRPROT, %eax
282 movl $MTRR_PHYS_MASK(1), %ecx
284 movl rom_mtrr_mask, %eax
285 orl $MTRR_PHYS_MASK_VALID, %eax
288 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
290 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
294 #if CONFIG(MICROCODE_UPDATE_PRE_RAM)
296 /* put the return address in %esp */
297 movl $end_microcode_update, %esp
298 jmp update_bsp_microcode
299 end_microcode_update:
301 post_code(POST_SOC_DISABLE_CACHE)
302 /* Disable caching to change MTRR's. */
304 orl $CR0_CacheDisable, %eax
308 * An unidentified combination of speculative reads and branch
309 * predictions inside WRPROT-cacheable memory can cause invalidation
310 * of cachelines and loss of stack on models based on NetBurst
311 * microarchitecture. Therefore disable WRPROT region entirely for
312 * all family F models.
320 movl $MTRR_PHYS_MASK(1), %ecx
322 andl $(~MTRR_PHYS_MASK_VALID), %eax
327 /* Enable cache for our code in Flash because we do XIP here */
328 movl $MTRR_PHYS_BASE(1), %ecx
331 andl xip_mtrr_mask, %eax
332 orl $MTRR_TYPE_WRPROT, %eax
334 movl $MTRR_PHYS_MASK(1), %ecx
336 movl xip_mtrr_mask, %eax
337 orl $MTRR_PHYS_MASK_VALID, %eax
341 post_code(POST_SOC_FILL_CACHE)
344 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
348 /* Clear the cache memory region. This will also fill up the cache. */
351 movl $_car_mtrr_start, %edi
352 movl $_car_mtrr_size, %ecx
356 /* Setup the stack. */
357 mov $_ecar_stack, %esp
359 /* Need to align stack to 16 bytes at call instruction. Account for
361 andl $0xfffffff0, %esp
365 #include <cpu/x86/64bit/entry64.inc>
368 shlq $32, %rdi /* BIST */
370 or %rsi, %rdi /* tsc[63:32] */
371 movd %mm0, %rsi /* tsc[31:0] */
374 /* push TSC and BIST to stack */
376 pushl %eax /* BIST */
378 pushl %eax /* tsc[63:32] */
380 pushl %eax /* tsc[31:0] */
384 post_code(POST_BOOTBLOCK_BEFORE_C_ENTRY)
385 call bootblock_c_entry_bist
387 /* Should never see this postcode */
388 post_code(POST_DEAD_CODE)
395 .word MTRR_FIX_64K_00000
396 .word MTRR_FIX_16K_80000
397 .word MTRR_FIX_16K_A0000
398 .word MTRR_FIX_4K_C0000
399 .word MTRR_FIX_4K_C8000
400 .word MTRR_FIX_4K_D0000
401 .word MTRR_FIX_4K_D8000
402 .word MTRR_FIX_4K_E0000
403 .word MTRR_FIX_4K_E8000
404 .word MTRR_FIX_4K_F0000
405 .word MTRR_FIX_4K_F8000
408 _cache_as_ram_setup_end: