blob: 784e8ca0ae48484b49419e9d38beefda3fe6abf9 [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
Arthur Heymans5cb24d42021-06-23 13:17:33 +0200224 /*
225 * With Bootguard some RO caching of the flash is already set up by
226 * the ACM. It looks like in such a setup 'clear_car' will not properly fill
227 * the cachelines. Fill all the CAR cachelines explicitly using sfence.
228 * This assumes 64 bytes cachelines.
229 */
230 movl $CONFIG_DCACHE_RAM_BASE, %edi
231 movl $CONFIG_DCACHE_RAM_SIZE, %ecx
232 shr $0x06, %ecx
233 xor %eax, %eax
234
2351:
236 movl %eax, (%edi)
237 sfence
238 add $64, %edi
239 loop 1b
240
Arthur Heymans481c52d2019-11-08 17:05:04 +0100241 clear_car
242
243 jmp car_init_done
244
245no_bootguard_car_continue:
Subrata Banik03e971c2017-03-07 14:02:23 +0530246 /* Enable variable MTRRs */
247 mov $MTRR_DEF_TYPE_MSR, %ecx
248 rdmsr
249 or $MTRR_DEF_TYPE_EN, %eax
250 wrmsr
251
252 /* Enable caching */
253 mov %cr0, %eax
254 and $~(CR0_CD | CR0_NW), %eax
255 invd
256 mov %eax, %cr0
257
Julius Wernercd49cce2019-03-05 16:53:33 -0800258#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530259 jmp car_nem
Julius Wernercd49cce2019-03-05 16:53:33 -0800260#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530261 jmp car_cqos
Julius Wernercd49cce2019-03-05 16:53:33 -0800262#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530263 jmp car_nem_enhanced
264#else
265 jmp .halt_forever /* In case nothing has selected */
266#endif
267
268.global car_init_done
269car_init_done:
270
271 post_code(0x29)
272
273 /* Setup bootblock stack */
Arthur Heymansdf9cdcf2019-11-09 06:50:20 +0100274 mov $_ecar_stack, %esp
Subrata Banik03e971c2017-03-07 14:02:23 +0530275
Aaron Durbin028e18f2017-06-23 11:14:58 -0500276 /* Need to align stack to 16 bytes at call instruction. Account for
277 the two pushes below. */
278 andl $0xfffffff0, %esp
Patrick Rudolph2b771122020-11-30 13:52:42 +0100279
280#if ENV_X86_64
281 #include <cpu/x86/64bit/entry64.inc>
282 movd %mm2, %rdi
283 shlq $32, %rdi
284 movd %mm1, %rsi
285 or %rsi, %rdi
286 movd %mm0, %rsi
287#else
Aaron Durbin028e18f2017-06-23 11:14:58 -0500288 sub $8, %esp
289
Subrata Banik5885ffe2019-11-14 11:08:51 +0530290 /* push TSC value to stack */
Subrata Banik03e971c2017-03-07 14:02:23 +0530291 movd %mm2, %eax
292 pushl %eax /* tsc[63:32] */
293 movd %mm1, %eax
Elyes HAOUAS05498a22018-05-28 16:26:43 +0200294 pushl %eax /* tsc[31:0] */
Patrick Rudolph2b771122020-11-30 13:52:42 +0100295#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530296
297before_carstage:
298 post_code(0x2A)
299
300 call bootblock_c_entry
301 /* Never reached */
302
303.halt_forever:
304 post_code(POST_DEAD_CODE)
305 hlt
306 jmp .halt_forever
307
308fixed_mtrr_list:
309 .word MTRR_FIX_64K_00000
310 .word MTRR_FIX_16K_80000
311 .word MTRR_FIX_16K_A0000
312 .word MTRR_FIX_4K_C0000
313 .word MTRR_FIX_4K_C8000
314 .word MTRR_FIX_4K_D0000
315 .word MTRR_FIX_4K_D8000
316 .word MTRR_FIX_4K_E0000
317 .word MTRR_FIX_4K_E8000
318 .word MTRR_FIX_4K_F0000
319 .word MTRR_FIX_4K_F8000
320fixed_mtrr_list_size = . - fixed_mtrr_list
321
Julius Wernercd49cce2019-03-05 16:53:33 -0800322#if CONFIG(INTEL_CAR_NEM)
Subrata Banik03e971c2017-03-07 14:02:23 +0530323.global car_nem
324car_nem:
325 /* Disable cache eviction (setup stage) */
326 mov $MSR_EVICT_CTL, %ecx
327 rdmsr
328 or $0x1, %eax
329 wrmsr
330
331 post_code(0x26)
332
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100333 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530334
335 post_code(0x27)
336
337 /* Disable cache eviction (run stage) */
338 mov $MSR_EVICT_CTL, %ecx
339 rdmsr
340 or $0x2, %eax
341 wrmsr
342
343 post_code(0x28)
344
345 jmp car_init_done
346
Julius Wernercd49cce2019-03-05 16:53:33 -0800347#elif CONFIG(INTEL_CAR_CQOS)
Subrata Banik03e971c2017-03-07 14:02:23 +0530348.global car_cqos
349car_cqos:
350 /*
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530351 * Create CBM_LEN_MASK based on CBM_LEN
352 * Get CPUID.(EAX=10H, ECX=2H):EAX.CBM_LEN[bits 4:0]
353 */
354 mov $0x10, %eax
355 mov $0x2, %ecx
356 cpuid
357 and $0x1F, %eax
358 add $1, %al
359
360 mov $1, %ebx
361 mov %al, %cl
362 shl %cl, %ebx
363 sub $1, %ebx
364
365 /* Store the CBM_LEN_MASK in mm3 for later use. */
366 movd %ebx, %mm3
367
368 /*
Subrata Banik03e971c2017-03-07 14:02:23 +0530369 * Disable both L1 and L2 prefetcher. For yet-to-understood reason,
370 * prefetchers slow down filling cache with rep stos in CQOS mode.
371 */
372 mov $MSR_PREFETCH_CTL, %ecx
373 rdmsr
374 or $(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
375 wrmsr
376
377#if (CONFIG_DCACHE_RAM_SIZE == CONFIG_L2_CACHE_SIZE)
378/*
379 * If CAR size is set to full L2 size, mask is calculated as all-zeros.
380 * This is not supported by the CPU/uCode.
381 */
382#error "CQOS CAR may not use whole L2 cache area"
383#endif
384
385 /* Calculate how many bits to be used for CAR */
386 xor %edx, %edx
387 mov $CONFIG_DCACHE_RAM_SIZE, %eax /* dividend */
388 mov $CONFIG_CACHE_QOS_SIZE_PER_BIT, %ecx /* divisor */
389 div %ecx /* result is in eax */
390 mov %eax, %ecx /* save to ecx */
391 mov $1, %ebx
392 shl %cl, %ebx
393 sub $1, %ebx /* resulting mask is is in ebx */
394
395 /* Set this mask for initial cache fill */
396 mov $MSR_L2_QOS_MASK(0), %ecx
397 rdmsr
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530398 mov %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530399 wrmsr
400
401 /* Set CLOS selector to 0 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200402 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530403 rdmsr
404 and $~IA32_PQR_ASSOC_MASK, %edx /* select mask 0 */
405 wrmsr
406
407 /* We will need to block CAR region from evicts */
408 mov $MSR_L2_QOS_MASK(1), %ecx
409 rdmsr
410 /* Invert bits that are to be used for cache */
Naresh G Solankif329f0c2017-09-27 14:21:18 +0530411 mov %ebx, %eax
412 xor $~0, %eax /* invert 32 bits */
413
414 /*
415 * Use CBM_LEN_MASK stored in mm3 to set bits based on Capacity Bit
416 * Mask Length.
417 */
418 movd %mm3, %ebx
419 and %ebx, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530420 wrmsr
421
422 post_code(0x26)
423
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100424 clear_car
Subrata Banik03e971c2017-03-07 14:02:23 +0530425
426 post_code(0x27)
427
428 /* Cache is populated. Use mask 1 that will block evicts */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200429 mov $IA32_PQR_ASSOC, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530430 rdmsr
431 and $~IA32_PQR_ASSOC_MASK, %edx /* clear index bits first */
432 or $1, %edx /* select mask 1 */
433 wrmsr
434
435 /* Enable prefetchers */
436 mov $MSR_PREFETCH_CTL, %ecx
437 rdmsr
438 and $~(PREFETCH_L1_DISABLE | PREFETCH_L2_DISABLE), %eax
439 wrmsr
440
441 post_code(0x28)
442
443 jmp car_init_done
444
Julius Wernercd49cce2019-03-05 16:53:33 -0800445#elif CONFIG(INTEL_CAR_NEM_ENHANCED)
Subrata Banik03e971c2017-03-07 14:02:23 +0530446.global car_nem_enhanced
447car_nem_enhanced:
448 /* Disable cache eviction (setup stage) */
449 mov $MSR_EVICT_CTL, %ecx
450 rdmsr
451 or $0x1, %eax
452 wrmsr
453 post_code(0x26)
454
455 /* Create n-way set associativity of cache */
456 xorl %edi, %edi
457find_llc_subleaf:
458 movl %edi, %ecx
459 movl $0x04, %eax
460 cpuid
461 inc %edi
462 and $0xe0, %al /* EAX[7:5] = Cache Level */
463 cmp $0x60, %al /* Check to see if it is LLC */
464 jnz find_llc_subleaf
465
466 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530467 * Calculate the total LLC size
468 * (Line_Size + 1) * (Sets + 1) * (Partitions + 1) * (Ways + 1)
469 * (EBX[11:0] + 1) * (ECX + 1) * (EBX[21:12] + 1) * EBX[31:22] + 1)
470 */
471
472 mov %ebx, %eax
473 and $0xFFF, %eax
474 inc %eax
475 inc %ecx
476 mul %ecx
477 mov %eax, %ecx
478 mov %ebx, %eax
479 shr $12, %eax
480 and $0x3FF, %eax
481 inc %eax
482 mul %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530483 shr $22, %ebx
484 inc %ebx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530485 mov %ebx, %edx
486 mul %ebx /* eax now holds total LLC size */
Subrata Banik03e971c2017-03-07 14:02:23 +0530487
488 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530489 * The number of the ways that we want to protect from eviction
490 * can be calculated as RW data stack size / way size where way
491 * size is Total LLC size / Total number of LLC ways.
Subrata Banik03e971c2017-03-07 14:02:23 +0530492 */
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530493 div %ebx /* way size */
494 mov %eax, %ecx
495
Subrata Banik03e971c2017-03-07 14:02:23 +0530496 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530497 * Check if way size if bigger than the cache ram size.
498 * Then we need to allocate just one way for non-eviction
499 * of RW data.
500 */
Subrata Banik06039022021-03-09 14:40:39 +0530501 movl $0x01, %eax
502 cmp $CONFIG_DCACHE_RAM_SIZE, %ecx
503 jnc set_eviction_mask
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530504
505 /*
506 * RW data size / way size is equal to number of
507 * ways to be configured for non-eviction
508 */
Subrata Banik06039022021-03-09 14:40:39 +0530509 mov $CONFIG_DCACHE_RAM_SIZE, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530510 div %ecx
511 mov %eax, %ecx
512 movl $0x01, %eax
513 shl %cl, %eax
514 subl $0x01, %eax
515
516set_eviction_mask:
Subrata Banik1b12d782021-07-08 12:50:42 +0530517 mov %ebx, %edi /* back up number of ways */
518 mov %eax, %esi /* back up the non-eviction mask*/
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800519#if CONFIG(CAR_HAS_SF_MASKS)
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800520 /*
521 * SF mask is programmed with the double number of bits than
522 * the number of ways
523 */
524 mov $0x01, %eax
Subrata Banik1b12d782021-07-08 12:50:42 +0530525 mov %edi, %ecx
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800526 shl %cl, %eax
527 shl %cl, %eax
528 subl $0x01, %eax /* contains SF mask */
529 /*
530 * Program MSR 0x1891 IA32_CR_SF_QOS_MASK_1 with
531 * total number of LLC ways
532 */
533 movl $IA32_CR_SF_QOS_MASK_1, %ecx
534 xorl %edx, %edx
535 wrmsr
Shreesh Chhabbi860c6842020-12-03 15:06:20 -0800536#endif
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530537 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800538 * Program MSR 0xC91 IA32_L3_MASK_1
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530539 * This MSR contain one bit per each way of LLC
Subrata Banik03e971c2017-03-07 14:02:23 +0530540 * - If this bit is '0' - the way is protected from eviction
541 * - If this bit is '1' - the way is not protected from eviction
542 */
Subrata Banik06039022021-03-09 14:40:39 +0530543 mov $0x1, %eax
Subrata Banik1b12d782021-07-08 12:50:42 +0530544 mov %edi, %ecx
Subrata Banik06039022021-03-09 14:40:39 +0530545 shl %cl, %eax
546 subl $0x01, %eax
547 mov %eax, %ecx
Subrata Banik1b12d782021-07-08 12:50:42 +0530548 mov %esi, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530549
550 xor $~0, %eax /* invert 32 bits */
551 and %ecx, %eax
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200552 movl $IA32_L3_MASK_1, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530553 xorl %edx, %edx
554 wrmsr
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530555 /*
Shreesh Chhabbi87c7ec72020-12-03 14:07:15 -0800556 * Program MSR 0xC92 IA32_L3_MASK_2
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530557 * This MSR contain one bit per each way of LLC
558 * - If this bit is '0' - the way is protected from eviction
559 * - If this bit is '1' - the way is not protected from eviction
560 */
Subrata Banik1b12d782021-07-08 12:50:42 +0530561 mov %esi, %eax
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530562 movl $IA32_L3_MASK_2, %ecx
Subrata Banik03e971c2017-03-07 14:02:23 +0530563 xorl %edx, %edx
564 wrmsr
565 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530566 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530567 *
568 * Possible values:
569 * 0: Default value, no way mask should be applied
570 * 1: Apply way mask 1 to LLC
571 * 2: Apply way mask 2 to LLC
572 * 3: Shouldn't be use in NEM Mode
573 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200574 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530575 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530576 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530577#if CONFIG(COS_MAPPED_TO_MSB)
578 movl $0x02, %edx
579#else
580 movl $0x02, %eax
581#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530582 wrmsr
Arthur Heymans99a48bc2019-11-25 09:56:20 +0100583
584 clear_car
585
Subrata Banik03e971c2017-03-07 14:02:23 +0530586 /*
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530587 * Set IA32_PQR_ASSOC
Subrata Banik03e971c2017-03-07 14:02:23 +0530588 * At this stage we apply LLC_WAY_MASK_1 to the cache.
Subrata Banik03e971c2017-03-07 14:02:23 +0530589 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200590 movl $IA32_PQR_ASSOC, %ecx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530591 xorl %eax, %eax
Subrata Banik03e971c2017-03-07 14:02:23 +0530592 xorl %edx, %edx
Aamir Bohrac1d227d2020-07-16 09:03:06 +0530593#if CONFIG(COS_MAPPED_TO_MSB)
594 movl $0x01, %edx
595#else
596 movl $0x01, %eax
597#endif
Subrata Banik03e971c2017-03-07 14:02:23 +0530598 wrmsr
599
600 post_code(0x27)
601 /*
602 * Enable No-Eviction Mode Run State by setting
603 * NO_EVICT_MODE MSR 2E0h bit [1] = '1'.
604 */
605
606 movl $MSR_EVICT_CTL, %ecx
607 rdmsr
608 orl $0x02, %eax
609 wrmsr
610
611 post_code(0x28)
612
613 jmp car_init_done
614#endif