1 /* 2 * Copyright (C) 2018-2022 Intel Corporation. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef TRUSTY_H_ 8 #define TRUSTY_H_ 9 #include <acrn_hv_defs.h> 10 #include <asm/seed.h> 11 12 #define RPMB_MAX_PARTITION_NUMBER 6U 13 #define MMC_PROD_NAME_WITH_PSN_LEN 15U 14 15 #define TRUSTY_RAM_SIZE (16UL * 1024UL * 1024UL) /* 16 MB for now */ 16 17 /* Trusty EPT rebase gpa: 511G */ 18 #define TRUSTY_EPT_REBASE_GPA (511UL * 1024UL * 1024UL * 1024UL) 19 20 #define NON_TRUSTY_PDPT_ENTRIES 511U 21 22 struct acrn_vcpu; 23 struct acrn_vm; 24 25 /* Structure of key info */ 26 struct trusty_key_info { 27 uint32_t size_of_this_struct; 28 29 /* version info: 30 0: baseline structure 31 1: add ** new field 32 */ 33 uint32_t version; 34 35 /* platform: 36 0: Dummy (fake secret) 37 1: APL (APL + ABL) 38 2: ICL (ICL + SBL) 39 3: ACRN (APL|ICL + SBL + ACRN) 40 4: Brillo (Android Things) 41 */ 42 uint32_t platform; 43 44 /* flags info: 45 Bit 0: manufacturing state (0:manufacturing done; 46 1:in manufacturing mode) 47 Bit 1: secure boot state (0:disabled; 1: enabled) 48 Bit 2: test seeds (ICL only - 0:production seeds; 1: test seeds) 49 other bits all reserved as 0 50 */ 51 uint32_t flags; 52 53 /* Keep 64-bit align */ 54 uint32_t pad1; 55 56 /* Seed list, include useeds(user seeds) and dseed(device seeds) */ 57 uint32_t num_seeds; 58 struct seed_info useed_list[BOOTLOADER_SEED_MAX_ENTRIES]; 59 struct seed_info dseed_list[BOOTLOADER_SEED_MAX_ENTRIES]; 60 61 /* For ICL+ */ 62 /* rpmb keys, Currently HMAC-SHA256 is used in RPMB spec 63 * and 256-bit (32byte) is enough. Hence only lower 32 bytes will be 64 * used for now for each entry. But keep higher 32 bytes for future 65 * extension. Note that, RPMB keys are already tied to storage device 66 * serial number.If there are multiple RPMB partitions, then we will 67 * get multiple available RPMB keys. And if rpmb_key[n][64] == 0, 68 * then the n-th RPMB key is unavailable (Either because of no such 69 * RPMB partition, or because OSloader doesn't want to share 70 * the n-th RPMB key with Trusty) 71 */ 72 uint8_t rpmb_key[RPMB_MAX_PARTITION_NUMBER][64]; 73 74 /* 256-bit AES encryption key to encrypt/decrypt attestation keybox, 75 this key should be derived from a fixed key which is RPMB seed. 76 RPMB key (HMAC key) and this encryption key (AES key) are both 77 derived from the same RPMB seed. 78 */ 79 uint8_t attkb_enc_key[32]; 80 81 /* For APL only */ 82 /* RPMB key is derived with dseed together with this serial number, 83 * for ICL +, CSE directly provides the rpmb_key which is already 84 * tied to serial number. Concatenation of emmc product name 85 * with a string representation of PSN 86 */ 87 char serial[MMC_PROD_NAME_WITH_PSN_LEN]; 88 char pad2; 89 }; 90 91 struct secure_world_memory { 92 /* The original secure world base address allocated by bootloader */ 93 uint64_t base_gpa_in_user_vm; 94 /* The secure world base address of HPA */ 95 uint64_t base_hpa; 96 /* Secure world runtime memory size */ 97 uint64_t length; 98 }; 99 100 struct secure_world_control { 101 /* Flag indicates Secure World's state */ 102 struct { 103 /* sworld supporting: 0(unsupported), 1(supported) */ 104 uint64_t supported : 1; 105 /* sworld running status: 0(inactive), 1(active) */ 106 uint64_t active : 1; 107 /* sworld context saving status: 0(unsaved), 1(saved) */ 108 uint64_t ctx_saved : 1; 109 uint64_t reserved : 61; 110 } flag; 111 /* Secure world memory structure */ 112 struct secure_world_memory sworld_memory; 113 }; 114 115 struct trusty_startup_param { 116 uint32_t size_of_this_struct; 117 uint32_t mem_size; 118 uint64_t tsc_per_ms; 119 uint64_t trusty_mem_base; 120 uint32_t reserved; 121 uint8_t padding[4]; 122 }; 123 124 void switch_world(struct acrn_vcpu *vcpu, int32_t next_world); 125 bool initialize_trusty(struct acrn_vcpu *vcpu, struct trusty_boot_param *boot_param); 126 void destroy_secure_world(struct acrn_vm *vm, bool need_clr_mem); 127 void save_sworld_context(struct acrn_vcpu *vcpu); 128 void restore_sworld_context(struct acrn_vcpu *vcpu); 129 130 #endif /* TRUSTY_H_ */ 131