blob: 29bd3fe87f39a82114abe68e6fdbdc75ec57f718 [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
Arthur Heymans6da7fa22021-06-23 10:52:01 +020069#if CONFIG(SOC_INTEL_NO_BOOTGUARD_MSR)
70 xorl %eax, %eax
71#else
Arthur Heymanscd96fed52021-06-23 10:48:28 +020072 movl $MSR_BOOT_GUARD_SACM_INFO, %ecx
73 rdmsr
74 andl $B_BOOT_GUARD_SACM_INFO_NEM_ENABLED, %eax
Arthur Heymans6da7fa22021-06-23 10:52:01 +020075#endif
Arthur Heymanscd96fed52021-06-23 10:48:28 +020076.endm
77
Subrata Banik03e971c2017-03-07 14:02:23 +053078.global bootblock_pre_c_entry
79bootblock_pre_c_entry:
80
81 post_code(0x20)
82
Arthur Heymans481c52d2019-11-08 17:05:04 +010083/* Bootguard sets up its own CAR and needs separate handling */
84check_boot_guard:
Arthur Heymanscd96fed52021-06-23 10:48:28 +020085 is_bootguard_nem
Arthur Heymans481c52d2019-11-08 17:05:04 +010086 jz no_bootguard
87
88 /* Disable PBE timer */
89 movl $MSR_BC_PBEC, %ecx
90 movl $B_STOP_PBET, %eax
91 xorl %edx, %edx
92 wrmsr
93
94 jmp setup_car_mtrr
95
96no_bootguard:
Arthur Heymansc4772b92019-04-14 18:38:35 +020097 movl $no_reset, %esp /* return address */
98 jmp check_mtrr /* Check if CPU properly reset */
Subrata Banik03e971c2017-03-07 14:02:23 +053099
100no_reset:
101 post_code(0x21)
102
103 /* Clear/disable fixed MTRRs */
104 mov $fixed_mtrr_list_size, %ebx
105 xor %eax, %eax
106 xor %edx, %edx
107
108clear_fixed_mtrr:
109 add $-2, %ebx
110 movzwl fixed_mtrr_list(%ebx), %ecx
111 wrmsr
112 jnz clear_fixed_mtrr
113
114 post_code(0x22)
115
Arthur Heymansc57d3032021-06-16 09:56:26 +0200116 /* Figure out how many MTRRs we have, and clear them out */
Subrata Banik03e971c2017-03-07 14:02:23 +0530117 mov $MTRR_CAP_MSR, %ecx
118 rdmsr
119 movzb %al, %ebx /* Number of variable MTRRs */
120 mov $MTRR_PHYS_BASE(0), %ecx
121 xor %eax, %eax
122 xor %edx, %edx
123
124clear_var_mtrr:
125 wrmsr
126 inc %ecx
127 wrmsr
128 inc %ecx
129 dec %ebx
130 jnz clear_var_mtrr
131
132 post_code(0x23)
133
134 /* Configure default memory type to uncacheable (UC) */
135 mov $MTRR_DEF_TYPE_MSR, %ecx
136 rdmsr
137 /* Clear enable bits and set default type to UC. */
138 and $~(MTRR_DEF_TYPE_MASK | MTRR_DEF_TYPE_EN | \
139 MTRR_DEF_TYPE_FIX_EN), %eax
140 wrmsr
141
Arthur Heymans481c52d2019-11-08 17:05:04 +0100142setup_car_mtrr:
Subrata Banik03e971c2017-03-07 14:02:23 +0530143 /* Configure MTRR_PHYS_MASK_HIGH for proper addressing above 4GB
144 * based on the physical address size supported for this processor
145 * This is based on read from CPUID EAX = 080000008h, EAX bits [7:0]
146 *
147 * Examples:
148 * MTRR_PHYS_MASK_HIGH = 00000000Fh For 36 bit addressing
149 * MTRR_PHYS_MASK_HIGH = 0000000FFh For 40 bit addressing
150 */
151
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200152 movl $0x80000008, %eax /* Address sizes leaf */
Subrata Banik03e971c2017-03-07 14:02:23 +0530153 cpuid
154 sub $32, %al
155 movzx %al, %eax
156 xorl %esi, %esi
157 bts %eax, %esi
158 dec %esi /* esi <- MTRR_PHYS_MASK_HIGH */
159
160 post_code(0x24)
161
162#if ((CONFIG_DCACHE_RAM_SIZE & (CONFIG_DCACHE_RAM_SIZE - 1)) == 0)
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100163 find_free_mtrr
164 test %ebx, %ebx
165 jz .halt_forever
166
Subrata Banik03e971c2017-03-07 14:02:23 +0530167 /* Configure CAR region as write-back (WB) */
Subrata Banik03e971c2017-03-07 14:02:23 +0530168 mov $CONFIG_DCACHE_RAM_BASE, %eax
169 or $MTRR_TYPE_WRBACK, %eax
170 xor %edx,%edx
171 wrmsr
172
173 /* Configure the MTRR mask for the size region */
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100174 inc %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530175 mov $CONFIG_DCACHE_RAM_SIZE, %eax /* size mask */
176 dec %eax
177 not %eax
178 or $MTRR_PHYS_MASK_VALID, %eax
179 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
180 wrmsr
181#elif (CONFIG_DCACHE_RAM_SIZE == 768 * KiB) /* 768 KiB */
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100182 find_free_mtrr
183 test %ebx, %ebx
184 jz .halt_forever
185
Subrata Banik03e971c2017-03-07 14:02:23 +0530186 /* Configure CAR region as write-back (WB) */
Subrata Banik03e971c2017-03-07 14:02:23 +0530187 mov $CONFIG_DCACHE_RAM_BASE, %eax
188 or $MTRR_TYPE_WRBACK, %eax
189 xor %edx,%edx
190 wrmsr
191
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100192 incl %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530193 mov $(512 * KiB), %eax /* size mask */
194 dec %eax
195 not %eax
196 or $MTRR_PHYS_MASK_VALID, %eax
197 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
198 wrmsr
199
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100200 find_free_mtrr
201 test %ebx, %ebx
202 jz .halt_forever
2031:
Subrata Banik03e971c2017-03-07 14:02:23 +0530204 mov $(CONFIG_DCACHE_RAM_BASE + 512 * KiB), %eax
205 or $MTRR_TYPE_WRBACK, %eax
206 xor %edx,%edx
207 wrmsr
208
Arthur Heymans64c9c6d2019-11-25 09:45:40 +0100209 incl %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530210 mov $(256 * KiB), %eax /* size mask */
211 dec %eax
212 not %eax
213 or $MTRR_PHYS_MASK_VALID, %eax
214 movl %esi, %edx /* edx <- MTRR_PHYS_MASK_HIGH */
215 wrmsr
216#else
217#error "DCACHE_RAM_SIZE is not a power of 2 and setup code is missing"
218#endif
219 post_code(0x25)
220
Arthur Heymanscd96fed52021-06-23 10:48:28 +0200221 is_bootguard_nem
Arthur Heymans481c52d2019-11-08 17:05:04 +0100222 jz no_bootguard_car_continue
223
224 clear_car
225
226 jmp car_init_done
227
228no_bootguard_car_continue:
Subrata Banik03e971c2017-03-07 14:02:23 +0530229 /* Enable variable MTRRs */
230 mov $MTRR_DEF_TYPE_MSR, %ecx
231 rdmsr
232 or $MTRR_DEF_TYPE_EN, %eax
233 wrmsr
234
235 /* Enable caching */
236 mov %cr0, %eax
237 and $~(CR0_CD | CR0_NW), %eax
238 invd
239 mov %eax, %cr0
240
Julius Wernercd49cce2019-03-05 16:53:33 -0800241#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530242 jmp car_nem
Julius Wernercd49cce2019-03-05 16:53:33 -0800243#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530244 jmp car_cqos
Julius Wernercd49cce2019-03-05 16:53:33 -0800245#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530246 jmp car_nem_enhanced
247#else
248 jmp .halt_forever /* In case nothing has selected */
249#endif
250
251.global car_init_done
252car_init_done:
253
254 post_code(0x29)
255
256 /* Setup bootblock stack */
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +0100257 mov $_ecar_stack, %esp
Subrata Banik03e971c2017-03-07 14:02:23 +0530258
Aaron Durbin028e18f2017-06-23 11:14:58 -0500259 /* Need to align stack to 16 bytes at call instruction. Account for
260 the two pushes below. */
261 andl $0xfffffff0, %esp
Patrick Rudolph2b771122020-11-30 13:52:42 +0100262
263#if ENV_X86_64
264 #include <cpu/x86/64bit/entry64.inc>
265 movd %mm2, %rdi
266 shlq $32, %rdi
267 movd %mm1, %rsi
268 or %rsi, %rdi
269 movd %mm0, %rsi
270#else
Aaron Durbin028e18f2017-06-23 11:14:58 -0500271 sub $8, %esp
272
Subrata Banik5885ffe2019-11-14 11:08:51 +0530273 /* push TSC value to stack */
Subrata Banik03e971c2017-03-07 14:02:23 +0530274 movd %mm2, %eax
275 pushl %eax /* tsc[63:32] */
276 movd %mm1, %eax
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200277 pushl %eax /* tsc[31:0] */
Patrick Rudolph2b771122020-11-30 13:52:42 +0100278#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530279
280before_carstage:
281 post_code(0x2A)
282
283 call bootblock_c_entry
284 /* Never reached */
285
286.halt_forever:
287 post_code(POST_DEAD_CODE)
288 hlt
289 jmp .halt_forever
290
291fixed_mtrr_list:
292 .word MTRR_FIX_64K_00000
293 .word MTRR_FIX_16K_80000
294 .word MTRR_FIX_16K_A0000
295 .word MTRR_FIX_4K_C0000
296 .word MTRR_FIX_4K_C8000
297 .word MTRR_FIX_4K_D0000
298 .word MTRR_FIX_4K_D8000
299 .word MTRR_FIX_4K_E0000
300 .word MTRR_FIX_4K_E8000
301 .word MTRR_FIX_4K_F0000
302 .word MTRR_FIX_4K_F8000
303fixed_mtrr_list_size = . - fixed_mtrr_list
304
Julius Wernercd49cce2019-03-05 16:53:33 -0800305#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530306.global car_nem
307car_nem:
308 /* Disable cache eviction (setup stage) */
309 mov $MSR_EVICT_CTL, %ecx
310 rdmsr
311 or $0x1, %eax
312 wrmsr
313
314 post_code(0x26)
315
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100316 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530317
318 post_code(0x27)
319
320 /* Disable cache eviction (run stage) */
321 mov $MSR_EVICT_CTL, %ecx
322 rdmsr
323 or $0x2, %eax
324 wrmsr
325
326 post_code(0x28)
327
328 jmp car_init_done
329
Julius Wernercd49cce2019-03-05 16:53:33 -0800330#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530331.global car_cqos
332car_cqos:
333 /*
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530334 * Create CBM_LEN_MASK based on CBM_LEN
335 * Get CPUID.(EAX=10H, ECX=2H):EAX.CBM_LEN[bits 4:0]
336 */
337 mov $0x10, %eax
338 mov $0x2, %ecx
339 cpuid
340 and $0x1F, %eax
341 add $1, %al
342
343 mov $1, %ebx
344 mov %al, %cl
345 shl %cl, %ebx
346 sub $1, %ebx
347
348 /* Store the CBM_LEN_MASK in mm3 for later use. */
349 movd %ebx, %mm3
350
351 /*
Subrata Banik03e971c2017-03-07 14:02:23 +0530352 * Disable both L1 and L2 prefetcher. For yet-to-understood reason,
353 * prefetchers slow down filling cache with rep stos in CQOS mode.
354 */
355 mov $MSR_PREFETCH_CTL, %ecx
356 rdmsr
357 or $(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
358 wrmsr
359
360#if (CONFIG_DCACHE_RAM_SIZE == CONFIG_L2_CACHE_SIZE)
361/*
362 * If CAR size is set to full L2 size, mask is calculated as all-zeros.
363 * This is not supported by the CPU/uCode.
364 */
365#error "CQOS CAR may not use whole L2 cache area"
366#endif
367
368 /* Calculate how many bits to be used for CAR */
369 xor %edx, %edx
370 mov $CONFIG_DCACHE_RAM_SIZE, %eax /* dividend */
371 mov $CONFIG_CACHE_QOS_SIZE_PER_BIT, %ecx /* divisor */
372 div %ecx /* result is in eax */
373 mov %eax, %ecx /* save to ecx */
374 mov $1, %ebx
375 shl %cl, %ebx
376 sub $1, %ebx /* resulting mask is is in ebx */
377
378 /* Set this mask for initial cache fill */
379 mov $MSR_L2_QOS_MASK(0), %ecx
380 rdmsr
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530381 mov %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530382 wrmsr
383
384 /* Set CLOS selector to 0 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200385 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530386 rdmsr
387 and $~IA32_PQR_ASSOC_MASK, %edx /* select mask 0 */
388 wrmsr
389
390 /* We will need to block CAR region from evicts */
391 mov $MSR_L2_QOS_MASK(1), %ecx
392 rdmsr
393 /* Invert bits that are to be used for cache */
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530394 mov %ebx, %eax
395 xor $~0, %eax /* invert 32 bits */
396
397 /*
398 * Use CBM_LEN_MASK stored in mm3 to set bits based on Capacity Bit
399 * Mask Length.
400 */
401 movd %mm3, %ebx
402 and %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530403 wrmsr
404
405 post_code(0x26)
406
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100407 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530408
409 post_code(0x27)
410
411 /* Cache is populated. Use mask 1 that will block evicts */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200412 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530413 rdmsr
414 and $~IA32_PQR_ASSOC_MASK, %edx /* clear index bits first */
415 or $1, %edx /* select mask 1 */
416 wrmsr
417
418 /* Enable prefetchers */
419 mov $MSR_PREFETCH_CTL, %ecx
420 rdmsr
421 and $~(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
422 wrmsr
423
424 post_code(0x28)
425
426 jmp car_init_done
427
Julius Wernercd49cce2019-03-05 16:53:33 -0800428#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530429.global car_nem_enhanced
430car_nem_enhanced:
431 /* Disable cache eviction (setup stage) */
432 mov $MSR_EVICT_CTL, %ecx
433 rdmsr
434 or $0x1, %eax
435 wrmsr
436 post_code(0x26)
437
438 /* Create n-way set associativity of cache */
439 xorl %edi, %edi
440find_llc_subleaf:
441 movl %edi, %ecx
442 movl $0x04, %eax
443 cpuid
444 inc %edi
445 and $0xe0, %al /* EAX[7:5] = Cache Level */
446 cmp $0x60, %al /* Check to see if it is LLC */
447 jnz find_llc_subleaf
448
449 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530450 * Calculate the total LLC size
451 * (Line_Size + 1) * (Sets + 1) * (Partitions + 1) * (Ways + 1)
452 * (EBX[11:0] + 1) * (ECX + 1) * (EBX[21:12] + 1) * EBX[31:22] + 1)
453 */
454
455 mov %ebx, %eax
456 and $0xFFF, %eax
457 inc %eax
458 inc %ecx
459 mul %ecx
460 mov %eax, %ecx
461 mov %ebx, %eax
462 shr $12, %eax
463 and $0x3FF, %eax
464 inc %eax
465 mul %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530466 shr $22, %ebx
467 inc %ebx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530468 mov %ebx, %edx
469 mul %ebx /* eax now holds total LLC size */
Subrata Banik03e971c2017-03-07 14:02:23 +0530470
471 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530472 * The number of the ways that we want to protect from eviction
473 * can be calculated as RW data stack size / way size where way
474 * size is Total LLC size / Total number of LLC ways.
Subrata Banik03e971c2017-03-07 14:02:23 +0530475 */
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530476 div %ebx /* way size */
477 mov %eax, %ecx
478
Subrata Banik03e971c2017-03-07 14:02:23 +0530479 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530480 * Check if way size if bigger than the cache ram size.
481 * Then we need to allocate just one way for non-eviction
482 * of RW data.
483 */
Subrata Banik06039022021-03-09 14:40:39 +0530484 movl $0x01, %eax
485 cmp $CONFIG_DCACHE_RAM_SIZE, %ecx
486 jnc set_eviction_mask
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530487
488 /*
489 * RW data size / way size is equal to number of
490 * ways to be configured for non-eviction
491 */
Subrata Banik06039022021-03-09 14:40:39 +0530492 mov $CONFIG_DCACHE_RAM_SIZE, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530493 div %ecx
494 mov %eax, %ecx
495 movl $0x01, %eax
496 shl %cl, %eax
497 subl $0x01, %eax
498
499set_eviction_mask:
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800500 mov %ebx, %ecx /* back up number of ways */
501 mov %eax, %ebx /* back up the non-eviction mask*/
502#if CONFIG(CAR_HAS_SF_MASKS)
503 mov %ecx, %edi /* use number of ways to prepare SF mask */
504 /*
505 * SF mask is programmed with the double number of bits than
506 * the number of ways
507 */
508 mov $0x01, %eax
509 shl %cl, %eax
510 shl %cl, %eax
511 subl $0x01, %eax /* contains SF mask */
512 /*
513 * Program MSR 0x1891 IA32_CR_SF_QOS_MASK_1 with
514 * total number of LLC ways
515 */
516 movl $IA32_CR_SF_QOS_MASK_1, %ecx
517 xorl %edx, %edx
518 wrmsr
519 mov %edi, %ecx /* restore number of ways */
520#endif
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530521 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800522 * Program MSR 0xC91 IA32_L3_MASK_1
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530523 * This MSR contain one bit per each way of LLC
Subrata Banik03e971c2017-03-07 14:02:23 +0530524 * - If this bit is '0' - the way is protected from eviction
525 * - If this bit is '1' - the way is not protected from eviction
526 */
Subrata Banik06039022021-03-09 14:40:39 +0530527 mov $0x1, %eax
528 shl %cl, %eax
529 subl $0x01, %eax
530 mov %eax, %ecx
531 mov %ebx, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530532
533 xor $~0, %eax /* invert 32 bits */
534 and %ecx, %eax
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200535 movl $IA32_L3_MASK_1, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530536 xorl %edx, %edx
537 wrmsr
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530538 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800539 * Program MSR 0xC92 IA32_L3_MASK_2
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530540 * This MSR contain one bit per each way of LLC
541 * - If this bit is '0' - the way is protected from eviction
542 * - If this bit is '1' - the way is not protected from eviction
543 */
544 mov %ebx, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530545 movl $IA32_L3_MASK_2, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530546 xorl %edx, %edx
547 wrmsr
548 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530549 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530550 *
551 * Possible values:
552 * 0: Default value, no way mask should be applied
553 * 1: Apply way mask 1 to LLC
554 * 2: Apply way mask 2 to LLC
555 * 3: Shouldn't be use in NEM Mode
556 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200557 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530558 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530559 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530560#if CONFIG(COS_MAPPED_TO_MSB)
561 movl $0x02, %edx
562#else
563 movl $0x02, %eax
564#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530565 wrmsr
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100566
567 clear_car
568
Subrata Banik03e971c2017-03-07 14:02:23 +0530569 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530570 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530571 * At this stage we apply LLC_WAY_MASK_1 to the cache.
Subrata Banik03e971c2017-03-07 14:02:23 +0530572 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200573 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530574 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530575 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530576#if CONFIG(COS_MAPPED_TO_MSB)
577 movl $0x01, %edx
578#else
579 movl $0x01, %eax
580#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530581 wrmsr
582
583 post_code(0x27)
584 /*
585 * Enable No-Eviction Mode Run State by setting
586 * NO_EVICT_MODE MSR 2E0h bit [1] = '1'.
587 */
588
589 movl $MSR_EVICT_CTL, %ecx
590 rdmsr
591 orl $0x02, %eax
592 wrmsr
593
594 post_code(0x28)
595
596 jmp car_init_done
597#endif