1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpigen.h>
4 #include <console/console.h>
6 #include <intelblocks/acpi.h>
7 #include <intelblocks/sgx.h>
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
15 static inline uint64_t sgx_resource(uint32_t low
, uint32_t high
)
18 val
= (uint64_t)(high
& SGX_RESOURCE_MASK_HI
) << 32;
19 val
|= low
& SGX_RESOURCE_MASK_LO
;
23 void sgx_fill_ssdt(void)
26 struct cpuid_result cpuid_regs
;
27 uint64_t emna
= 0, elng
= 0;
29 if (is_sgx_supported()) {
31 * Get EPC base and size.
32 * Intel SDM: Table 36-6. CPUID Leaf 12H, Sub-Leaf Index 2 or
33 * higher for enumeration of SGX resources
35 cpuid_regs
= cpuid_ext(SGX_RESOURCE_ENUM_CPUID_LEAF
,
36 SGX_RESOURCE_ENUM_CPUID_SUBLEAF
);
38 if (cpuid_regs
.eax
& SGX_RESOURCE_ENUM_BIT
) {
39 /* EPC section enumerated */
41 emna
= sgx_resource(cpuid_regs
.eax
, cpuid_regs
.ebx
);
42 elng
= sgx_resource(cpuid_regs
.ecx
, cpuid_regs
.edx
);
45 printk(BIOS_DEBUG
, "SGX: EPC status = %d base = 0x%llx len = 0x%llx\n",
48 printk(BIOS_DEBUG
, "SGX: not supported.\n");
51 acpigen_write_scope("\\_SB.EPC");
53 acpigen_write_name_byte("EPCS", epcs
);
54 acpigen_write_name_qword("EMNA", emna
);
55 acpigen_write_name_qword("ELNG", elng
);