1 /* 2 * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef EL3_SPMC_FFA_MEM_H 8 #define EL3_SPMC_FFA_MEM_H 9 10 #include <assert.h> 11 12 /* 13 * Subset of Arm Firmware Framework for Armv8-A 14 * (https://developer.arm.com/docs/den0077/a) needed for shared memory. 15 */ 16 17 /** 18 * typedef ffa_endpoint_id16_t - Endpoint ID 19 * 20 * Current implementation only supports VM IDs. FF-A spec also support stream 21 * endpoint ids. 22 */ 23 typedef uint16_t ffa_endpoint_id16_t; 24 25 /** 26 * struct ffa_cons_mrd - Constituent memory region descriptor 27 * @address: 28 * Start address of contiguous memory region. Must be 4K page aligned. 29 * @page_count: 30 * Number of 4K pages in region. 31 * @reserved_12_15: 32 * Reserve bytes 12-15 to pad struct size to 16 bytes. 33 */ 34 struct ffa_cons_mrd { 35 uint64_t address; 36 uint32_t page_count; 37 uint32_t reserved_12_15; 38 }; 39 CASSERT(sizeof(struct ffa_cons_mrd) == 16, assert_ffa_cons_mrd_size_mismatch); 40 41 /** 42 * struct ffa_comp_mrd - Composite memory region descriptor 43 * @total_page_count: 44 * Number of 4k pages in memory region. Must match sum of 45 * @address_range_array[].page_count. 46 * @address_range_count: 47 * Number of entries in @address_range_array. 48 * @reserved_8_15: 49 * Reserve bytes 8-15 to pad struct size to 16 byte alignment and 50 * make @address_range_array 16 byte aligned. 51 * @address_range_array: 52 * Array of &struct ffa_cons_mrd entries. 53 */ 54 struct ffa_comp_mrd { 55 uint32_t total_page_count; 56 uint32_t address_range_count; 57 uint64_t reserved_8_15; 58 struct ffa_cons_mrd address_range_array[]; 59 }; 60 CASSERT(sizeof(struct ffa_comp_mrd) == 16, assert_ffa_comp_mrd_size_mismatch); 61 62 /** 63 * typedef ffa_mem_attr8_t - Memory region attributes 64 * 65 * * @FFA_MEM_ATTR_DEVICE_NGNRNE: 66 * Device-nGnRnE. 67 * * @FFA_MEM_ATTR_DEVICE_NGNRE: 68 * Device-nGnRE. 69 * * @FFA_MEM_ATTR_DEVICE_NGRE: 70 * Device-nGRE. 71 * * @FFA_MEM_ATTR_DEVICE_GRE: 72 * Device-GRE. 73 * * @FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED 74 * Normal memory. Non-cacheable. 75 * * @FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB 76 * Normal memory. Write-back cached. 77 * * @FFA_MEM_ATTR_NON_SHAREABLE 78 * Non-shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 79 * * @FFA_MEM_ATTR_OUTER_SHAREABLE 80 * Outer Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 81 * * @FFA_MEM_ATTR_INNER_SHAREABLE 82 * Inner Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*. 83 */ 84 typedef uint8_t ffa_mem_attr8_t; 85 #define FFA_MEM_ATTR_DEVICE_NGNRNE ((1U << 4) | (0x0U << 2)) 86 #define FFA_MEM_ATTR_DEVICE_NGNRE ((1U << 4) | (0x1U << 2)) 87 #define FFA_MEM_ATTR_DEVICE_NGRE ((1U << 4) | (0x2U << 2)) 88 #define FFA_MEM_ATTR_DEVICE_GRE ((1U << 4) | (0x3U << 2)) 89 #define FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED ((2U << 4) | (0x1U << 2)) 90 #define FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB ((2U << 4) | (0x3U << 2)) 91 #define FFA_MEM_ATTR_NON_SHAREABLE (0x0U << 0) 92 #define FFA_MEM_ATTR_OUTER_SHAREABLE (0x2U << 0) 93 #define FFA_MEM_ATTR_INNER_SHAREABLE (0x3U << 0) 94 95 /** 96 * typedef ffa_mem_perm8_t - Memory access permissions 97 * 98 * * @FFA_MEM_ATTR_RO 99 * Request or specify read-only mapping. 100 * * @FFA_MEM_ATTR_RW 101 * Request or allow read-write mapping. 102 * * @FFA_MEM_PERM_NX 103 * Deny executable mapping. 104 * * @FFA_MEM_PERM_X 105 * Request executable mapping. 106 */ 107 typedef uint8_t ffa_mem_perm8_t; 108 #define FFA_MEM_PERM_RO (1U << 0) 109 #define FFA_MEM_PERM_RW (1U << 1) 110 #define FFA_MEM_PERM_NX (1U << 2) 111 #define FFA_MEM_PERM_X (1U << 3) 112 113 /** 114 * typedef ffa_mem_flag8_t - Endpoint memory flags 115 * 116 * * @FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER 117 * Non-retrieval Borrower. Memory region must not be or was not retrieved on 118 * behalf of this endpoint. 119 */ 120 typedef uint8_t ffa_mem_flag8_t; 121 #define FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER (1U << 0) 122 123 /** 124 * typedef ffa_mtd_flag32_t - Memory transaction descriptor flags 125 * 126 * * @FFA_MTD_FLAG_ZERO_MEMORY 127 * Zero memory after unmapping from sender (must be 0 for share). 128 * * @FFA_MTD_FLAG_TIME_SLICING 129 * Not supported by this implementation. 130 * * @FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH 131 * Zero memory after unmapping from borrowers (must be 0 for share). 132 * * @FFA_MTD_FLAG_TYPE_MASK 133 * Bit-mask to extract memory management transaction type from flags. 134 * * @FFA_MTD_FLAG_TYPE_SHARE_MEMORY 135 * Share memory transaction flag. 136 * Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from 137 * @SMC_FC_FFA_MEM_SHARE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that 138 * it must have. 139 * * @FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK 140 * Not supported by this implementation. 141 */ 142 typedef uint32_t ffa_mtd_flag32_t; 143 #define FFA_MTD_FLAG_ZERO_MEMORY (1U << 0) 144 #define FFA_MTD_FLAG_TIME_SLICING (1U << 1) 145 #define FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH (1U << 2) 146 #define FFA_MTD_FLAG_TYPE_MASK (3U << 3) 147 #define FFA_MTD_FLAG_TYPE_SHARE_MEMORY (1U << 3) 148 #define FFA_MTD_FLAG_TYPE_LEND_MEMORY (1U << 4) 149 #define FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK (0x1FU << 5) 150 151 /** 152 * struct ffa_mapd - Memory access permissions descriptor 153 * @endpoint_id: 154 * Endpoint id that @memory_access_permissions and @flags apply to. 155 * (&typedef ffa_endpoint_id16_t). 156 * @memory_access_permissions: 157 * FFA_MEM_PERM_* values or'ed together (&typedef ffa_mem_perm8_t). 158 * @flags: 159 * FFA_MEM_FLAG_* values or'ed together (&typedef ffa_mem_flag8_t). 160 */ 161 struct ffa_mapd { 162 ffa_endpoint_id16_t endpoint_id; 163 ffa_mem_perm8_t memory_access_permissions; 164 ffa_mem_flag8_t flags; 165 }; 166 CASSERT(sizeof(struct ffa_mapd) == 4, assert_ffa_mapd_size_mismatch); 167 168 /** 169 * struct ffa_emad_v1_0 - Endpoint memory access descriptor. 170 * @mapd: &struct ffa_mapd. 171 * @comp_mrd_offset: 172 * Offset of &struct ffa_comp_mrd from start of &struct ffa_mtd_v1_0. 173 * @reserved_8_15: 174 * Reserved bytes 8-15. Must be 0. 175 */ 176 struct ffa_emad_v1_0 { 177 struct ffa_mapd mapd; 178 uint32_t comp_mrd_offset; 179 uint64_t reserved_8_15; 180 }; 181 CASSERT(sizeof(struct ffa_emad_v1_0) == 16, assert_ffa_emad_v1_0_size_mismatch); 182 183 /** 184 * struct ffa_mtd_v1_0 - Memory transaction descriptor. 185 * @sender_id: 186 * Sender endpoint id. 187 * @memory_region_attributes: 188 * FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr8_t). 189 * @reserved_3: 190 * Reserved bytes 3. Must be 0. 191 * @flags: 192 * FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t). 193 * @handle: 194 * Id of shared memory object. Must be 0 for MEM_SHARE or MEM_LEND. 195 * @tag: Client allocated tag. Must match original value. 196 * @reserved_24_27: 197 * Reserved bytes 24-27. Must be 0. 198 * @emad_count: 199 * Number of entries in @emad. Must be 1 in current implementation. 200 * FFA spec allows more entries. 201 * @emad: 202 * Endpoint memory access descriptor array (see @struct ffa_emad_v1_0). 203 */ 204 struct ffa_mtd_v1_0 { 205 ffa_endpoint_id16_t sender_id; 206 ffa_mem_attr8_t memory_region_attributes; 207 uint8_t reserved_3; 208 ffa_mtd_flag32_t flags; 209 uint64_t handle; 210 uint64_t tag; 211 uint32_t reserved_24_27; 212 uint32_t emad_count; 213 struct ffa_emad_v1_0 emad[]; 214 }; 215 CASSERT(sizeof(struct ffa_mtd_v1_0) == 32, assert_ffa_mtd_size_v1_0_mismatch); 216 217 #endif /* EL3_SPMC_FFA_MEM_H */ 218