| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
|
| 3 |
#include <cpu/x86/mtrr.h> |
| 4 |
#include <cpu/x86/msr.h> |
| 5 |
#include <cpu/x86/cr.h> |
| 6 |
#include <intelblocks/msr.h> |
| 7 |
|
| 8 |
.text |
| 9 |
.global chipset_teardown_car |
| 10 |
chipset_teardown_car: |
| 11 |
|
| 12 |
#if CONFIG(PAGING_IN_CACHE_AS_RAM) |
| 13 |
/* |
| 14 |
* Since Page table is located in CAR, disable paging before CAR |
| 15 |
* teardown. Also clear CR3 and CR4.PAE. |
| 16 |
*/ |
| 17 |
mov %cr0, %eax |
| 18 |
and $(~(CR0_PG)), %eax |
| 19 |
mov %eax, %cr0 |
| 20 |
xor %eax, %eax |
| 21 |
mov %eax, %cr3 |
| 22 |
mov %cr4, %eax |
| 23 |
and $(~(CR4_PAE)), %eax |
| 24 |
mov %eax, %cr4 |
| 25 |
#endif |
| 26 |
|
| 27 |
/* |
| 28 |
* Retrieve return address from stack as it will get trashed below if |
| 29 |
* execution is utilizing the cache-as-ram stack. |
| 30 |
*/ |
| 31 |
#if ENV_X86_64 |
| 32 |
pop %rbx |
| 33 |
#else |
| 34 |
pop %ebx |
| 35 |
#endif |
| 36 |
|
| 37 |
/* Disable MTRRs. */ |
| 38 |
mov $(MTRR_DEF_TYPE_MSR), %ecx |
| 39 |
rdmsr |
| 40 |
and $(~(MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN)), %eax |
| 41 |
wrmsr |
| 42 |
|
| 43 |
#if CONFIG(INTEL_CAR_NEM) |
| 44 |
.global car_nem_teardown |
| 45 |
car_nem_teardown: |
| 46 |
|
| 47 |
/* invalidate cache contents. */ |
| 48 |
invd |
| 49 |
|
| 50 |
/* Knock down bit 1 then bit 0 of NEM control not combining steps. */ |
| 51 |
mov $(MSR_EVICT_CTL), %ecx |
| 52 |
rdmsr |
| 53 |
and $(~(1 << 1)), %eax |
| 54 |
wrmsr |
| 55 |
and $(~(1 << 0)), %eax |
| 56 |
wrmsr |
| 57 |
|
| 58 |
#elif CONFIG(INTEL_CAR_CQOS) |
| 59 |
.global car_cqos_teardown |
| 60 |
car_cqos_teardown: |
| 61 |
|
| 62 |
/* Go back to all-evicting mode, set both masks to all-1s */ |
| 63 |
mov $MSR_L2_QOS_MASK(0), %ecx |
| 64 |
rdmsr |
| 65 |
mov $~0, %al |
| 66 |
wrmsr |
| 67 |
|
| 68 |
mov $MSR_L2_QOS_MASK(1), %ecx |
| 69 |
rdmsr |
| 70 |
mov $~0, %al |
| 71 |
wrmsr |
| 72 |
|
| 73 |
/* Reset CLOS selector to 0 */ |
| 74 |
mov $IA32_PQR_ASSOC, %ecx |
| 75 |
rdmsr |
| 76 |
and $~IA32_PQR_ASSOC_MASK, %edx |
| 77 |
wrmsr |
| 78 |
|
| 79 |
#elif CONFIG(INTEL_CAR_NEM_ENHANCED) |
| 80 |
.global car_nem_enhanced_teardown |
| 81 |
car_nem_enhanced_teardown: |
| 82 |
|
| 83 |
/* invalidate cache contents. */ |
| 84 |
invd |
| 85 |
|
| 86 |
/* Knock down bit 1 then bit 0 of NEM control not combining steps. */ |
| 87 |
mov $(MSR_EVICT_CTL), %ecx |
| 88 |
rdmsr |
| 89 |
and $(~(1 << 1)), %eax |
| 90 |
wrmsr |
| 91 |
and $(~(1 << 0)), %eax |
| 92 |
wrmsr |
| 93 |
|
| 94 |
/* Reset CLOS selector to 0 */ |
| 95 |
mov $IA32_PQR_ASSOC, %ecx |
| 96 |
rdmsr |
| 97 |
and $~IA32_PQR_ASSOC_MASK, %edx |
| 98 |
wrmsr |
| 99 |
#if CONFIG(CAR_HAS_L3_PROTECTED_WAYS) |
| 100 |
/* Set MSR 0xC85 L3_Protected_ways = 0x00000 */ |
| 101 |
mov $IA32_L3_PROTECTED_WAYS, %ecx |
| 102 |
xorl %eax, %eax |
| 103 |
xorl %edx, %edx |
| 104 |
wrmsr |
| 105 |
#endif |
| 106 |
#endif |
| 107 |
|
| 108 |
/* Return to caller. */ |
| 109 |
#if ENV_X86_64 |
| 110 |
jmp *%rbx |
| 111 |
#else |
| 112 |
jmp *%ebx |
| 113 |
#endif |