blob: d880c2588d1cb2fe484344a750ff62310e794de4 [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Subrata Banik03e971c2017-03-07 14:02:23 +05302
3#include <commonlib/helpers.h>
Arthur Heymans481c52d2019-11-08 17:05:04 +01004#include <cpu/intel/msr.h>
Subrata Banik03e971c2017-03-07 14:02:23 +05305#include <cpu/x86/cache.h>
6#include <cpu/x86/cr.h>
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +02007#include <cpu/x86/msr.h>
Subrata Banik03e971c2017-03-07 14:02:23 +05308#include <cpu/x86/mtrr.h>
9#include <cpu/x86/post_code.h>
10#include <rules.h>
11#include <intelblocks/msr.h>
12
Kyösti Mälkki7522a8f2020-11-20 16:47:38 +020013.section .init, "ax", @progbits
14
Patrick Rudolph2b771122020-11-30 13:52:42 +010015.code32
Arthur Heymans64c9c6d2019-11-25 09:45:40 +010016
17/*
18 * macro: find_free_mtrr
19 * Clobbers: %eax, %ebx, %ecx, %edx.
20 * Returns:
21 * %ebx contains the number of freely available MTRR's.
22 * It should be checked against 0.
23 * %ecx holds the MTRR_BASE of the free MTRR.
24 */
25.macro find_free_mtrr
26 /* Figure out how many MTRRs we have */
27 mov $MTRR_CAP_MSR, %ecx
28 rdmsr
29 movzb %al, %ebx /* Number of variable MTRRs */
30
31 /* Find a free variable MTRR */
32 movl $MTRR_PHYS_MASK(0), %ecx
331:
34 rdmsr
35 test $MTRR_PHYS_MASK_VALID, %eax
36 jz 2f
37 addl $2, %ecx
38 dec %ebx
39 jnz 1b
402:
41 /* %ecx needs to hold the MTRR_BASE */
42 decl %ecx
43.endm
44
Arthur Heymans99a48bc2019-11-25 09:56:20 +010045/*
46 * macro: clear_car
47 * Clears the region between CONFIG_DCACHE_RAM_BASE and
48 * CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE to populate
49 * cachelines.
50 * Clobbers %eax, %ecx, %edi.
51 */
52.macro clear_car
53 /* Clear the cache memory region. This will also fill up the cache */
54 movl $CONFIG_DCACHE_RAM_BASE, %edi
55 movl $CONFIG_DCACHE_RAM_SIZE, %ecx
56 shr $0x02, %ecx
57 xor %eax, %eax
58 cld
59 rep stosl
60.endm
61
Arthur Heymanscd96fed52021-06-23 10:48:28 +020062/*
63 * macro: is_bootguard_nem
64 * Checks if the Bootguard ACM has enabled non eviction mode
65 * Clobbers %eax, %ecx, %edx
66 * Returns %eax and sets/unsets zero flag
67 */
68.macro is_bootguard_nem
69 movl $MSR_BOOT_GUARD_SACM_INFO, %ecx
70 rdmsr
71 andl $B_BOOT_GUARD_SACM_INFO_NEM_ENABLED, %eax
72.endm
73
Subrata Banik03e971c2017-03-07 14:02:23 +053074.global bootblock_pre_c_entry
75bootblock_pre_c_entry:
76
77 post_code(0x20)
78
Arthur Heymans481c52d2019-11-08 17:05:04 +010079/* Bootguard sets up its own CAR and needs separate handling */
80check_boot_guard:
Arthur Heymanscd96fed52021-06-23 10:48:28 +020081 is_bootguard_nem
Arthur Heymans481c52d2019-11-08 17:05:04 +010082 jz no_bootguard
83
84 /* Disable PBE timer */
85 movl $MSR_BC_PBEC, %ecx
86 movl $B_STOP_PBET, %eax
87 xorl %edx, %edx
88 wrmsr
89
90 jmp setup_car_mtrr
91
92no_bootguard:
Arthur Heymansc4772b92019-04-14 18:38:35 +020093 movl $no_reset, %esp /* return address */
94 jmp check_mtrr /* Check if CPU properly reset */
Subrata Banik03e971c2017-03-07 14:02:23 +053095
96no_reset:
97 post_code(0x21)
98
99 /* Clear/disable fixed MTRRs */
100 mov $fixed_mtrr_list_size, %ebx
101 xor %eax, %eax
102 xor %edx, %edx
103
104clear_fixed_mtrr:
105 add $-2, %ebx
106 movzwl fixed_mtrr_list(%ebx), %ecx
107 wrmsr
108 jnz clear_fixed_mtrr
109
110 post_code(0x22)
111
Arthur Heymansc57d3032021-06-16 09:56:26 +0200112 /* Figure out how many MTRRs we have, and clear them out */
Subrata Banik03e971c2017-03-07 14:02:23 +0530113 mov $MTRR_CAP_MSR, %ecx
114 rdmsr
115 movzb %al, %ebx /* Number of variable MTRRs */
116 mov $MTRR_PHYS_BASE(0), %ecx
117 xor %eax, %eax
118 xor %edx, %edx
119
120clear_var_mtrr:
121 wrmsr
122 inc %ecx
123 wrmsr
124 inc %ecx
125 dec %ebx
126 jnz clear_var_mtrr
127
128 post_code(0x23)
129
130 /* Configure default memory type to uncacheable (UC) */
131 mov $MTRR_DEF_TYPE_MSR, %ecx
132 rdmsr
133 /* Clear enable bits and set default type to UC. */
134 and $~(MTRR_DEF_TYPE_MASK | MTRR_DEF_TYPE_EN | \
135 MTRR_DEF_TYPE_FIX_EN), %eax
136 wrmsr
137
Arthur Heymans481c52d2019-11-08 17:05:04 +0100138setup_car_mtrr:
Subrata Banik03e971c2017-03-07 14:02:23 +0530139 /* Configure MTRR_PHYS_MASK_HIGH for proper addressing above 4GB
140 * based on the physical address size supported for this processor
141 * This is based on read from CPUID EAX = 080000008h, EAX bits [7:0]
142 *
143 * Examples:
144 * MTRR_PHYS_MASK_HIGH = 00000000Fh For 36 bit addressing
145 * MTRR_PHYS_MASK_HIGH = 0000000FFh For 40 bit addressing
146 */
147
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200148 movl $0x80000008, %eax /* Address sizes leaf */
Subrata Banik03e971c2017-03-07 14:02:23 +0530149 cpuid
150 sub $32, %al
151 movzx %al, %eax
152 xorl %esi, %esi
153 bts %eax, %esi
154 dec %esi /* esi <- MTRR_PHYS_MASK_HIGH */
155
156 post_code(0x24)
157
158#if ((CONFIG_DCACHE_RAM_SIZE & (CONFIG_DCACHE_RAM_SIZE - 1)) == 0)
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100159 find_free_mtrr
160 test %ebx, %ebx
161 jz .halt_forever
162
Subrata Banik03e971c2017-03-07 14:02:23 +0530163 /* Configure CAR region as write-back (WB) */
Subrata Banik03e971c2017-03-07 14:02:23 +0530164 mov $CONFIG_DCACHE_RAM_BASE, %eax
165 or $MTRR_TYPE_WRBACK, %eax
166 xor %edx,%edx
167 wrmsr
168
169 /* Configure the MTRR mask for the size region */
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100170 inc %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530171 mov $CONFIG_DCACHE_RAM_SIZE, %eax /* size mask */
172 dec %eax
173 not %eax
174 or $MTRR_PHYS_MASK_VALID, %eax
175 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
176 wrmsr
177#elif (CONFIG_DCACHE_RAM_SIZE == 768 * KiB) /* 768 KiB */
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100178 find_free_mtrr
179 test %ebx, %ebx
180 jz .halt_forever
181
Subrata Banik03e971c2017-03-07 14:02:23 +0530182 /* Configure CAR region as write-back (WB) */
Subrata Banik03e971c2017-03-07 14:02:23 +0530183 mov $CONFIG_DCACHE_RAM_BASE, %eax
184 or $MTRR_TYPE_WRBACK, %eax
185 xor %edx,%edx
186 wrmsr
187
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100188 incl %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530189 mov $(512 * KiB), %eax /* size mask */
190 dec %eax
191 not %eax
192 or $MTRR_PHYS_MASK_VALID, %eax
193 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
194 wrmsr
195
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100196 find_free_mtrr
197 test %ebx, %ebx
198 jz .halt_forever
1991:
Subrata Banik03e971c2017-03-07 14:02:23 +0530200 mov $(CONFIG_DCACHE_RAM_BASE + 512 * KiB), %eax
201 or $MTRR_TYPE_WRBACK, %eax
202 xor %edx,%edx
203 wrmsr
204
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100205 incl %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530206 mov $(256 * KiB), %eax /* size mask */
207 dec %eax
208 not %eax
209 or $MTRR_PHYS_MASK_VALID, %eax
210 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
211 wrmsr
212#else
213#error "DCACHE_RAM_SIZE is not a power of 2 and setup code is missing"
214#endif
215 post_code(0x25)
216
Arthur Heymanscd96fed52021-06-23 10:48:28 +0200217 is_bootguard_nem
Arthur Heymans481c52d2019-11-08 17:05:04 +0100218 jz no_bootguard_car_continue
219
220 clear_car
221
222 jmp car_init_done
223
224no_bootguard_car_continue:
Subrata Banik03e971c2017-03-07 14:02:23 +0530225 /* Enable variable MTRRs */
226 mov $MTRR_DEF_TYPE_MSR, %ecx
227 rdmsr
228 or $MTRR_DEF_TYPE_EN, %eax
229 wrmsr
230
231 /* Enable caching */
232 mov %cr0, %eax
233 and $~(CR0_CD | CR0_NW), %eax
234 invd
235 mov %eax, %cr0
236
Julius Wernercd49cce2019-03-05 16:53:33 -0800237#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530238 jmp car_nem
Julius Wernercd49cce2019-03-05 16:53:33 -0800239#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530240 jmp car_cqos
Julius Wernercd49cce2019-03-05 16:53:33 -0800241#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530242 jmp car_nem_enhanced
243#else
244 jmp .halt_forever /* In case nothing has selected */
245#endif
246
247.global car_init_done
248car_init_done:
249
250 post_code(0x29)
251
252 /* Setup bootblock stack */
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +0100253 mov $_ecar_stack, %esp
Subrata Banik03e971c2017-03-07 14:02:23 +0530254
Aaron Durbin028e18f2017-06-23 11:14:58 -0500255 /* Need to align stack to 16 bytes at call instruction. Account for
256 the two pushes below. */
257 andl $0xfffffff0, %esp
Patrick Rudolph2b771122020-11-30 13:52:42 +0100258
259#if ENV_X86_64
260 #include <cpu/x86/64bit/entry64.inc>
261 movd %mm2, %rdi
262 shlq $32, %rdi
263 movd %mm1, %rsi
264 or %rsi, %rdi
265 movd %mm0, %rsi
266#else
Aaron Durbin028e18f2017-06-23 11:14:58 -0500267 sub $8, %esp
268
Subrata Banik5885ffe2019-11-14 11:08:51 +0530269 /* push TSC value to stack */
Subrata Banik03e971c2017-03-07 14:02:23 +0530270 movd %mm2, %eax
271 pushl %eax /* tsc[63:32] */
272 movd %mm1, %eax
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200273 pushl %eax /* tsc[31:0] */
Patrick Rudolph2b771122020-11-30 13:52:42 +0100274#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530275
276before_carstage:
277 post_code(0x2A)
278
279 call bootblock_c_entry
280 /* Never reached */
281
282.halt_forever:
283 post_code(POST_DEAD_CODE)
284 hlt
285 jmp .halt_forever
286
287fixed_mtrr_list:
288 .word MTRR_FIX_64K_00000
289 .word MTRR_FIX_16K_80000
290 .word MTRR_FIX_16K_A0000
291 .word MTRR_FIX_4K_C0000
292 .word MTRR_FIX_4K_C8000
293 .word MTRR_FIX_4K_D0000
294 .word MTRR_FIX_4K_D8000
295 .word MTRR_FIX_4K_E0000
296 .word MTRR_FIX_4K_E8000
297 .word MTRR_FIX_4K_F0000
298 .word MTRR_FIX_4K_F8000
299fixed_mtrr_list_size = . - fixed_mtrr_list
300
Julius Wernercd49cce2019-03-05 16:53:33 -0800301#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530302.global car_nem
303car_nem:
304 /* Disable cache eviction (setup stage) */
305 mov $MSR_EVICT_CTL, %ecx
306 rdmsr
307 or $0x1, %eax
308 wrmsr
309
310 post_code(0x26)
311
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100312 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530313
314 post_code(0x27)
315
316 /* Disable cache eviction (run stage) */
317 mov $MSR_EVICT_CTL, %ecx
318 rdmsr
319 or $0x2, %eax
320 wrmsr
321
322 post_code(0x28)
323
324 jmp car_init_done
325
Julius Wernercd49cce2019-03-05 16:53:33 -0800326#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530327.global car_cqos
328car_cqos:
329 /*
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530330 * Create CBM_LEN_MASK based on CBM_LEN
331 * Get CPUID.(EAX=10H, ECX=2H):EAX.CBM_LEN[bits 4:0]
332 */
333 mov $0x10, %eax
334 mov $0x2, %ecx
335 cpuid
336 and $0x1F, %eax
337 add $1, %al
338
339 mov $1, %ebx
340 mov %al, %cl
341 shl %cl, %ebx
342 sub $1, %ebx
343
344 /* Store the CBM_LEN_MASK in mm3 for later use. */
345 movd %ebx, %mm3
346
347 /*
Subrata Banik03e971c2017-03-07 14:02:23 +0530348 * Disable both L1 and L2 prefetcher. For yet-to-understood reason,
349 * prefetchers slow down filling cache with rep stos in CQOS mode.
350 */
351 mov $MSR_PREFETCH_CTL, %ecx
352 rdmsr
353 or $(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
354 wrmsr
355
356#if (CONFIG_DCACHE_RAM_SIZE == CONFIG_L2_CACHE_SIZE)
357/*
358 * If CAR size is set to full L2 size, mask is calculated as all-zeros.
359 * This is not supported by the CPU/uCode.
360 */
361#error "CQOS CAR may not use whole L2 cache area"
362#endif
363
364 /* Calculate how many bits to be used for CAR */
365 xor %edx, %edx
366 mov $CONFIG_DCACHE_RAM_SIZE, %eax /* dividend */
367 mov $CONFIG_CACHE_QOS_SIZE_PER_BIT, %ecx /* divisor */
368 div %ecx /* result is in eax */
369 mov %eax, %ecx /* save to ecx */
370 mov $1, %ebx
371 shl %cl, %ebx
372 sub $1, %ebx /* resulting mask is is in ebx */
373
374 /* Set this mask for initial cache fill */
375 mov $MSR_L2_QOS_MASK(0), %ecx
376 rdmsr
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530377 mov %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530378 wrmsr
379
380 /* Set CLOS selector to 0 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200381 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530382 rdmsr
383 and $~IA32_PQR_ASSOC_MASK, %edx /* select mask 0 */
384 wrmsr
385
386 /* We will need to block CAR region from evicts */
387 mov $MSR_L2_QOS_MASK(1), %ecx
388 rdmsr
389 /* Invert bits that are to be used for cache */
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530390 mov %ebx, %eax
391 xor $~0, %eax /* invert 32 bits */
392
393 /*
394 * Use CBM_LEN_MASK stored in mm3 to set bits based on Capacity Bit
395 * Mask Length.
396 */
397 movd %mm3, %ebx
398 and %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530399 wrmsr
400
401 post_code(0x26)
402
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100403 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530404
405 post_code(0x27)
406
407 /* Cache is populated. Use mask 1 that will block evicts */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200408 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530409 rdmsr
410 and $~IA32_PQR_ASSOC_MASK, %edx /* clear index bits first */
411 or $1, %edx /* select mask 1 */
412 wrmsr
413
414 /* Enable prefetchers */
415 mov $MSR_PREFETCH_CTL, %ecx
416 rdmsr
417 and $~(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
418 wrmsr
419
420 post_code(0x28)
421
422 jmp car_init_done
423
Julius Wernercd49cce2019-03-05 16:53:33 -0800424#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530425.global car_nem_enhanced
426car_nem_enhanced:
427 /* Disable cache eviction (setup stage) */
428 mov $MSR_EVICT_CTL, %ecx
429 rdmsr
430 or $0x1, %eax
431 wrmsr
432 post_code(0x26)
433
434 /* Create n-way set associativity of cache */
435 xorl %edi, %edi
436find_llc_subleaf:
437 movl %edi, %ecx
438 movl $0x04, %eax
439 cpuid
440 inc %edi
441 and $0xe0, %al /* EAX[7:5] = Cache Level */
442 cmp $0x60, %al /* Check to see if it is LLC */
443 jnz find_llc_subleaf
444
445 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530446 * Calculate the total LLC size
447 * (Line_Size + 1) * (Sets + 1) * (Partitions + 1) * (Ways + 1)
448 * (EBX[11:0] + 1) * (ECX + 1) * (EBX[21:12] + 1) * EBX[31:22] + 1)
449 */
450
451 mov %ebx, %eax
452 and $0xFFF, %eax
453 inc %eax
454 inc %ecx
455 mul %ecx
456 mov %eax, %ecx
457 mov %ebx, %eax
458 shr $12, %eax
459 and $0x3FF, %eax
460 inc %eax
461 mul %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530462 shr $22, %ebx
463 inc %ebx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530464 mov %ebx, %edx
465 mul %ebx /* eax now holds total LLC size */
Subrata Banik03e971c2017-03-07 14:02:23 +0530466
467 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530468 * The number of the ways that we want to protect from eviction
469 * can be calculated as RW data stack size / way size where way
470 * size is Total LLC size / Total number of LLC ways.
Subrata Banik03e971c2017-03-07 14:02:23 +0530471 */
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530472 div %ebx /* way size */
473 mov %eax, %ecx
474
Subrata Banik03e971c2017-03-07 14:02:23 +0530475 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530476 * Check if way size if bigger than the cache ram size.
477 * Then we need to allocate just one way for non-eviction
478 * of RW data.
479 */
Subrata Banik06039022021-03-09 14:40:39 +0530480 movl $0x01, %eax
481 cmp $CONFIG_DCACHE_RAM_SIZE, %ecx
482 jnc set_eviction_mask
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530483
484 /*
485 * RW data size / way size is equal to number of
486 * ways to be configured for non-eviction
487 */
Subrata Banik06039022021-03-09 14:40:39 +0530488 mov $CONFIG_DCACHE_RAM_SIZE, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530489 div %ecx
490 mov %eax, %ecx
491 movl $0x01, %eax
492 shl %cl, %eax
493 subl $0x01, %eax
494
495set_eviction_mask:
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800496 mov %ebx, %ecx /* back up number of ways */
497 mov %eax, %ebx /* back up the non-eviction mask*/
498#if CONFIG(CAR_HAS_SF_MASKS)
499 mov %ecx, %edi /* use number of ways to prepare SF mask */
500 /*
501 * SF mask is programmed with the double number of bits than
502 * the number of ways
503 */
504 mov $0x01, %eax
505 shl %cl, %eax
506 shl %cl, %eax
507 subl $0x01, %eax /* contains SF mask */
508 /*
509 * Program MSR 0x1891 IA32_CR_SF_QOS_MASK_1 with
510 * total number of LLC ways
511 */
512 movl $IA32_CR_SF_QOS_MASK_1, %ecx
513 xorl %edx, %edx
514 wrmsr
515 mov %edi, %ecx /* restore number of ways */
516#endif
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530517 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800518 * Program MSR 0xC91 IA32_L3_MASK_1
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530519 * This MSR contain one bit per each way of LLC
Subrata Banik03e971c2017-03-07 14:02:23 +0530520 * - If this bit is '0' - the way is protected from eviction
521 * - If this bit is '1' - the way is not protected from eviction
522 */
Subrata Banik06039022021-03-09 14:40:39 +0530523 mov $0x1, %eax
524 shl %cl, %eax
525 subl $0x01, %eax
526 mov %eax, %ecx
527 mov %ebx, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530528
529 xor $~0, %eax /* invert 32 bits */
530 and %ecx, %eax
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200531 movl $IA32_L3_MASK_1, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530532 xorl %edx, %edx
533 wrmsr
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530534 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800535 * Program MSR 0xC92 IA32_L3_MASK_2
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530536 * This MSR contain one bit per each way of LLC
537 * - If this bit is '0' - the way is protected from eviction
538 * - If this bit is '1' - the way is not protected from eviction
539 */
540 mov %ebx, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530541 movl $IA32_L3_MASK_2, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530542 xorl %edx, %edx
543 wrmsr
544 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530545 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530546 *
547 * Possible values:
548 * 0: Default value, no way mask should be applied
549 * 1: Apply way mask 1 to LLC
550 * 2: Apply way mask 2 to LLC
551 * 3: Shouldn't be use in NEM Mode
552 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200553 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530554 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530555 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530556#if CONFIG(COS_MAPPED_TO_MSB)
557 movl $0x02, %edx
558#else
559 movl $0x02, %eax
560#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530561 wrmsr
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100562
563 clear_car
564
Subrata Banik03e971c2017-03-07 14:02:23 +0530565 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530566 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530567 * At this stage we apply LLC_WAY_MASK_1 to the cache.
Subrata Banik03e971c2017-03-07 14:02:23 +0530568 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200569 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530570 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530571 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530572#if CONFIG(COS_MAPPED_TO_MSB)
573 movl $0x01, %edx
574#else
575 movl $0x01, %eax
576#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530577 wrmsr
578
579 post_code(0x27)
580 /*
581 * Enable No-Eviction Mode Run State by setting
582 * NO_EVICT_MODE MSR 2E0h bit [1] = '1'.
583 */
584
585 movl $MSR_EVICT_CTL, %ecx
586 rdmsr
587 orl $0x02, %eax
588 wrmsr
589
590 post_code(0x28)
591
592 jmp car_init_done
593#endif