| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpigen.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <cpu/cpu.h> |
| 6 |
#include <intelblocks/acpi.h> |
| 7 |
#include <intelblocks/sgx.h> |
| 8 |
|
| 9 |
#define SGX_RESOURCE_ENUM_CPUID_LEAF 0x12 |
| 10 |
#define SGX_RESOURCE_ENUM_CPUID_SUBLEAF 0x2 |
| 11 |
#define SGX_RESOURCE_ENUM_BIT 0x1 |
| 12 |
#define SGX_RESOURCE_MASK_LO 0xfffff000UL |
| 13 |
#define SGX_RESOURCE_MASK_HI 0xfffffUL |
| 14 |
|
| 15 |
static inline uint64_t sgx_resource(uint32_t low, uint32_t high) |
| 16 |
{ |
| 17 |
uint64_t val; |
| 18 |
val = (uint64_t)(high & SGX_RESOURCE_MASK_HI) << 32; |
| 19 |
val |= low & SGX_RESOURCE_MASK_LO; |
| 20 |
return val; |
| 21 |
} |
| 22 |
|
| 23 |
void sgx_fill_ssdt(void) |
| 24 |
{ |
| 25 |
bool epcs = false; |
| 26 |
struct cpuid_result cpuid_regs; |
| 27 |
uint64_t emna = 0, elng = 0; |
| 28 |
|
| 29 |
if (is_sgx_supported()) { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
cpuid_regs = cpuid_ext(SGX_RESOURCE_ENUM_CPUID_LEAF, |
| 36 |
SGX_RESOURCE_ENUM_CPUID_SUBLEAF); |
| 37 |
|
| 38 |
if (cpuid_regs.eax & SGX_RESOURCE_ENUM_BIT) { |
| 39 |
|
| 40 |
epcs = true; |
| 41 |
emna = sgx_resource(cpuid_regs.eax, cpuid_regs.ebx); |
| 42 |
elng = sgx_resource(cpuid_regs.ecx, cpuid_regs.edx); |
| 43 |
} |
| 44 |
|
| 45 |
printk(BIOS_DEBUG, "SGX: EPC status = %d base = 0x%llx len = 0x%llx\n", |
| 46 |
epcs, emna, elng); |
| 47 |
} else { |
| 48 |
printk(BIOS_DEBUG, "SGX: not supported.\n"); |
| 49 |
} |
| 50 |
|
| 51 |
acpigen_write_scope("\\_SB.EPC"); |
| 52 |
{ |
| 53 |
acpigen_write_name_byte("EPCS", epcs); |
| 54 |
acpigen_write_name_qword("EMNA", emna); |
| 55 |
acpigen_write_name_qword("ELNG", elng); |
| 56 |
} |
| 57 |
acpigen_pop_len(); |
| 58 |
} |