1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2018-2019, Linaro Limited 4 */ 5 #ifndef __PTA_SYSTEM_H 6 #define __PTA_SYSTEM_H 7 8 #include <util.h> 9 10 /* 11 * Interface to the pseudo TA, which is provides misc. auxiliary services, 12 * extending existing GlobalPlatform Core API 13 */ 14 15 #define PTA_SYSTEM_UUID { 0x3a2f8978, 0x5dc0, 0x11e8, { \ 16 0x9c, 0x2d, 0xfa, 0x7a, 0xe0, 0x1b, 0xbe, 0xbc } } 17 18 /* 19 * Having keys with too few bits impose a potential security risk, hence set a 20 * lower bound of 128 bits. 21 */ 22 #define TA_DERIVED_KEY_MIN_SIZE 16 23 24 /* Same value as max in huk_subkey_derive */ 25 #define TA_DERIVED_KEY_MAX_SIZE 32 26 27 #define TA_DERIVED_EXTRA_DATA_MAX_SIZE 1024 28 29 /* 30 * Add (re-seed) caller-provided entropy to the RNG pool. Keymaster 31 * implementations need to securely mix the provided entropy into their pool, 32 * which also must contain internally-generated entropy from a hardware random 33 * number generator. 34 * 35 * [in] memref[0]: entropy input data 36 */ 37 #define PTA_SYSTEM_ADD_RNG_ENTROPY 0 38 39 /* 40 * Derives a device and TA unique key. The caller can also provide extra data 41 * that will be mixed together with existing device unique properties. If no 42 * extra data is provided, then the derived key will only use device unique 43 * properties and caller TA UUID. 44 * 45 * [in] params[0].memref.buffer Buffer for extra data 46 * [in] params[0].memref.size Size of extra data (max 1024 bytes) 47 * [out] params[1].memref.buffer Buffer for the derived key 48 * [out] params[1].memref.size Size of the derived key (16 to 32 bytes) 49 */ 50 #define PTA_SYSTEM_DERIVE_TA_UNIQUE_KEY 1 51 52 /* Memory can be shared with other TAs */ 53 #define PTA_SYSTEM_MAP_FLAG_SHAREABLE BIT32(0) 54 /* Read/write memory */ 55 #define PTA_SYSTEM_MAP_FLAG_WRITEABLE BIT32(1) 56 /* Executable memory */ 57 #define PTA_SYSTEM_MAP_FLAG_EXECUTABLE BIT32(2) 58 59 /* 60 * Map zero initialized memory 61 * 62 * [in] value[0].a: Number of bytes 63 * [in] value[0].b: Flags, 0 or PTA_SYSTEM_MAP_FLAG_SHAREABLE 64 * [out] value[1].a: Address upper 32-bits 65 * [out] value[1].b: Address lower 32-bits 66 * [in] value[2].a: Extra pad before memory range 67 * [in] value[2].b: Extra pad after memory range 68 */ 69 #define PTA_SYSTEM_MAP_ZI 2 70 71 /* 72 * Unmap memory 73 * 74 * [in] value[0].a: Number of bytes 75 * [in] value[0].b: Must be 0 76 * [in] value[1].a: Address upper 32-bits 77 * [in] value[1].b: Address lower 32-bits 78 */ 79 #define PTA_SYSTEM_UNMAP 3 80 81 /* 82 * Find and opens an TA binary and return a handle 83 * 84 * [in] memref[0]: UUID of TA binary 85 * [out] value[1].a: Handle to TA binary 86 * [out] value[1].b: 0 87 */ 88 #define PTA_SYSTEM_OPEN_TA_BINARY 4 89 90 /* 91 * Close an TA binary handle 92 * 93 * When a TA is done mapping new parts of an TA binary it closes the handle 94 * to free resources, established mappings remains. 95 * 96 * [in] value[1].a: Handle to TA binary 97 * [in] value[1].b: Must be 0 98 * 99 * Returns TEE_SUCCESS if the TA binary was verified successfully. 100 */ 101 #define PTA_SYSTEM_CLOSE_TA_BINARY 5 102 103 /* 104 * Map segment of TA binary 105 * 106 * Different parts of an TA binary file needs different permissions. 107 * Read-write mapped parts are private to the TA, while read-only (which 108 * includes execute) mapped parts are shared with other TAs. This is 109 * transparent to the TA. If the supplied address in value[3] is 0 a 110 * suitable address is selected, else it will either be mapped at that 111 * address of an error is returned. 112 * 113 * [in] value[0].a: Handle to TA binary 114 * [in] value[0].b: Flags, PTA_SYSTEM_MAP_FLAG_* 115 * [in] value[1].a: Offset into TA binary, must be page aligned 116 * [in] value[1].b: Number of bytes, the last page will be zero 117 * extended if not page aligned 118 * [in/out] value[2].a: Address upper 32-bits 119 * [in/out] value[2].b: Address lower 32-bits 120 * [in] value[3].a: Extra pad before memory range 121 * [in] value[3].b: Extra pad after memory range 122 */ 123 #define PTA_SYSTEM_MAP_TA_BINARY 6 124 125 /* 126 * Copy a memory range from TA binary 127 * 128 * [in] value[0].a: Handle to TA binary 129 * [in] value[0].b: Offset into TA binary 130 * [out] memref[1]: Destination 131 */ 132 #define PTA_SYSTEM_COPY_FROM_TA_BINARY 7 133 134 /* 135 * Set memory protection 136 * 137 * [in] value[0].a: Number of bytes 138 * [in] value[0].b: Flags, PTA_SYSTEM_MAP_FLAG_* 139 * [in] value[1].a: Address upper 32-bits 140 * [in] value[1].b: Address lower 32-bits 141 */ 142 #define PTA_SYSTEM_SET_PROT 8 143 144 /* 145 * Remap a segment of a TA mapping 146 * 147 * Moves an already mapped segment of a TA to a new address. If the 148 * supplied new address is 0 a suitable address is selected, else it will 149 * either be mapped at that address or an error is returned. 150 * 151 * [in] value[0].a: Number of bytes, must match length rounded up to 152 * closest page of original mapping 153 * [in] value[0].b: Must be 0 154 * [in] value[1].a: Old address upper 32-bits 155 * [in] value[1].b: Old address lower 32-bits 156 * [in/out] value[2].a: New address upper 32-bits 157 * [in/out] value[2].b: New address lower 32-bits 158 * [in] value[3].a: Extra pad before memory range 159 * [in] value[3].b: Extra pad after memory range 160 */ 161 #define PTA_SYSTEM_REMAP 9 162 163 /* 164 * Load a shared library 165 * 166 * [in] memref[0]: the UUID of the shared library (@filename) 167 * [in] value[1].a: @flags, must be (RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE) 168 * 169 * Used by: (libdl) dlopen(const char *filename, int flags) 170 */ 171 #define PTA_SYSTEM_DLOPEN 10 172 173 /* 174 * Resolve a symbol in a previously loaded shared library or in the whole TA 175 * 176 * [in] memref[0]: the UUID of the shared library, or the nil UUID to 177 * search the whole TA 178 * [in] memref[1]: symbol name (@symbol) 179 * [out] value[2]: address of the symbol or NULL 180 * 181 * Used by: (libdl) dlsym(void *handle, const char *symbol) 182 */ 183 #define PTA_SYSTEM_DLSYM 11 184 185 /* 186 * Retrieves a copy of the TPM Event log held in secure memory. 187 * 188 * [out] memref[0]: Pointer to the buffer where to store the event log. 189 */ 190 #define PTA_SYSTEM_GET_TPM_EVENT_LOG 12 191 192 #endif /* __PTA_SYSTEM_H */ 193