1 /* 2 * Copyright (C) 2019-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef SGX_H 8 #define SGX_H 9 10 #define CPUID_SGX_LEAF 0x12U 11 #define CPUID_SGX_EPC_SUBLEAF_BASE 0x2U 12 #define CPUID_SGX_EPC_TYPE_MASK 0xFU 13 #define CPUID_SGX_EPC_TYPE_INVALID 0x0U 14 #define CPUID_SGX_EPC_TYPE_VALID 0x1U 15 #define CPUID_SGX_EPC_HIGH_MASK 0x000FFFFFU 16 #define CPUID_SGX_EPC_LOW_MASK 0xFFFFF000U 17 18 #define MAX_EPC_SECTIONS 4U 19 /** 20 * @file sgx.h 21 * 22 * @brief public APIs for SGX 23 */ 24 25 /** 26 * @brief SGX 27 * 28 * @defgroup acrn_sgx ACRN SGX 29 * @{ 30 */ 31 32 struct epc_section 33 { 34 uint64_t base; /* EPC section base, must be page aligned */ 35 uint64_t size; /* EPC section size in byte, must be page aligned */ 36 }; 37 38 struct epc_map 39 { 40 uint64_t hpa; /* EPC reource address in host, must be page aligned */ 41 uint64_t gpa; /* EPC reource address in guest, must be page aligned */ 42 uint64_t size; /* EPC reource size in byte, must be page aligned */ 43 }; 44 45 /** 46 * @brief Get physcial EPC sections of the platform. 47 * 48 * @retval Physical EPC sections of the platform 49 * 50 */ 51 struct epc_section* get_phys_epc(void); 52 53 /** 54 * @brief Get EPC resource information for a specific VM. 55 * 56 * @param[in] vm_id VM ID to specify a VM 57 * 58 * @retval EPC sections for a VM 59 * 60 * @pre vm_id < CONFIG_MAX_VM_NUM 61 * 62 */ 63 struct epc_map* get_epc_mapping(uint16_t vm_id); 64 65 /** 66 * @brief If SGX support is enabled or not for a specific VM. 67 * 68 * @param[in] vm_id VM ID to specify a VM 69 * 70 * @retval True when SGX is supported in the specific VM 71 * @retval False When SGX is not supported in the specific VM 72 * 73 * @pre vm_id < CONFIG_MAX_VM_NUM 74 * 75 */ 76 bool is_vsgx_supported(uint16_t vm_id); 77 78 /** 79 * @brief SGX initialization. 80 * 81 * Init SGX and parition EPC resource for VMs. 82 * 83 * @retval 0 on success 84 * @retval <0 on failure 85 * 86 */ 87 int32_t init_sgx(void); 88 /** 89 * @} 90 */ 91 92 #endif 93