| 1 |
|
| 2 |
|
| 3 |
#include <cf9_reset.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <cpu/intel/common/common.h> |
| 6 |
#include <cpu/x86/cr.h> |
| 7 |
#include <cpu/x86/cache.h> |
| 8 |
#include <cpu/x86/mp.h> |
| 9 |
#include <cpu/x86/msr.h> |
| 10 |
#include <types.h> |
| 11 |
|
| 12 |
#include "txt_register.h" |
| 13 |
#include "txt_getsec.h" |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
static bool getsec_enabled(void) |
| 21 |
{ |
| 22 |
unsigned int ecx = cpuid_ecx(1); |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
if (!(ecx & CPUID_SMX) || !(ecx & CPUID_VMX)) { |
| 27 |
printk(BIOS_ERR, "SMX/VMX not supported by CPU\n"); |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
if (!ENV_ROMSTAGE_OR_BEFORE) { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
msr_t msr = rdmsr(IA32_FEATURE_CONTROL); |
| 41 |
if ((msr.lo & 0xff06) != 0xff06) { |
| 42 |
printk(BIOS_ERR, "GETSEC not enabled in IA32_FEATURE_CONTROL MSR\n"); |
| 43 |
return false; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
write_cr4(read_cr4() | CR4_SMXE); |
| 52 |
|
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
void enable_getsec_or_reset(void) |
| 57 |
{ |
| 58 |
msr_t msr = rdmsr(IA32_FEATURE_CONTROL); |
| 59 |
|
| 60 |
if (!(msr.lo & FEATURE_CONTROL_LOCK_BIT)) { |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
msr.lo |= 0xff06; |
| 66 |
wrmsr(IA32_FEATURE_CONTROL, msr); |
| 67 |
|
| 68 |
} else if ((msr.lo & 0xff06) != 0xff06) { |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
printk(BIOS_NOTICE, |
| 76 |
"IA32_FEATURE_CONTROL MSR locked with GETSEC and/or VMX disabled.\n" |
| 77 |
"Will perform a full reset to unlock this MSR.\n"); |
| 78 |
|
| 79 |
full_reset(); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
bool getsec_parameter(uint32_t *version_mask, |
| 90 |
uint32_t *version_numbers_supported, |
| 91 |
uint32_t *max_size_acm_area, |
| 92 |
uint32_t *memory_type_mask, |
| 93 |
uint32_t *senter_function_disable, |
| 94 |
uint32_t *txt_feature_flags) |
| 95 |
{ |
| 96 |
uint32_t i, eax, ebx, ecx; |
| 97 |
|
| 98 |
if (!getsec_enabled()) |
| 99 |
return false; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
for (i = 0; i < 0x1f; i++) { |
| 106 |
|
| 107 |
asm volatile ("getsec\n" |
| 108 |
: "=a" (eax), "=b" (ebx), "=c" (ecx) |
| 109 |
: "a" (IA32_GETSEC_PARAMETERS), "b" (i) :); |
| 110 |
switch (eax & 0x1f) { |
| 111 |
case 0: |
| 112 |
return true; |
| 113 |
case 1: |
| 114 |
if (version_mask) |
| 115 |
*version_mask = ebx; |
| 116 |
if (version_numbers_supported) |
| 117 |
*version_numbers_supported = ecx; |
| 118 |
break; |
| 119 |
case 2: |
| 120 |
if (max_size_acm_area) |
| 121 |
*max_size_acm_area = eax & ~0x1f; |
| 122 |
break; |
| 123 |
case 3: |
| 124 |
if (memory_type_mask) |
| 125 |
*memory_type_mask = eax; |
| 126 |
break; |
| 127 |
case 4: |
| 128 |
if (senter_function_disable) |
| 129 |
*senter_function_disable = eax & (0x3f00); |
| 130 |
break; |
| 131 |
case 5: |
| 132 |
if (txt_feature_flags) |
| 133 |
*txt_feature_flags = eax & (0x60); |
| 134 |
break; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
return true; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
bool getsec_capabilities(uint32_t *eax) |
| 148 |
{ |
| 149 |
if (!getsec_enabled()) |
| 150 |
return false; |
| 151 |
|
| 152 |
asm volatile ("getsec\n" |
| 153 |
: "=a" (*eax) |
| 154 |
: "a" (IA32_GETSEC_CAPABILITIES), "b" (0) :); |
| 155 |
|
| 156 |
return true; |
| 157 |
} |