1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (c) 2020, Linaro Limited 4 * Copyright (c) 2018-2022, Arm Limited. All rights reserved. 5 */ 6 7 #ifndef __FFA_H 8 #define __FFA_H 9 10 /* This is based on the FF-A 1.0 EAC specification */ 11 12 #include <smccc.h> 13 #include <stdint.h> 14 #include <util.h> 15 16 /* Error codes */ 17 #define FFA_OK 0 18 #define FFA_NOT_SUPPORTED -1 19 #define FFA_INVALID_PARAMETERS -2 20 #define FFA_NO_MEMORY -3 21 #define FFA_BUSY -4 22 #define FFA_INTERRUPTED -5 23 #define FFA_DENIED -6 24 #define FFA_RETRY -7 25 #define FFA_ABORTED -8 26 27 /* FFA_VERSION helpers */ 28 #define FFA_VERSION_MAJOR U(1) 29 #define FFA_VERSION_MAJOR_SHIFT U(16) 30 #define FFA_VERSION_MAJOR_MASK U(0x7FFF) 31 #define FFA_VERSION_MINOR U(0) 32 #define FFA_VERSION_MINOR_SHIFT U(0) 33 #define FFA_VERSION_MINOR_MASK U(0xFFFF) 34 #define MAKE_FFA_VERSION(major, minor) \ 35 ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \ 36 ((minor) & FFA_VERSION_MINOR_MASK)) 37 38 /* Function IDs */ 39 #define FFA_ERROR U(0x84000060) 40 #define FFA_SUCCESS_32 U(0x84000061) 41 #define FFA_SUCCESS_64 U(0xC4000061) 42 #define FFA_INTERRUPT U(0x84000062) 43 #define FFA_VERSION U(0x84000063) 44 #define FFA_FEATURES U(0x84000064) 45 #define FFA_RX_RELEASE U(0x84000065) 46 #define FFA_RXTX_MAP_32 U(0x84000066) 47 #define FFA_RXTX_MAP_64 U(0xC4000066) 48 #define FFA_RXTX_UNMAP U(0x84000067) 49 #define FFA_PARTITION_INFO_GET U(0x84000068) 50 #define FFA_ID_GET U(0x84000069) 51 #define FFA_MSG_WAIT U(0x8400006B) 52 #define FFA_MSG_YIELD U(0x8400006C) 53 #define FFA_MSG_RUN U(0x8400006D) 54 #define FFA_MSG_SEND U(0x8400006E) 55 #define FFA_MSG_SEND_DIRECT_REQ_32 U(0x8400006F) 56 #define FFA_MSG_SEND_DIRECT_REQ_64 U(0xC400006F) 57 #define FFA_MSG_SEND_DIRECT_RESP_32 U(0x84000070) 58 #define FFA_MSG_SEND_DIRECT_RESP_64 U(0xC4000070) 59 #define FFA_MSG_POLL U(0x8400006A) 60 #define FFA_MEM_DONATE_32 U(0x84000071) 61 #define FFA_MEM_DONATE_64 U(0xC4000071) 62 #define FFA_MEM_LEND_32 U(0x84000072) 63 #define FFA_MEM_LEND_64 U(0xC4000072) 64 #define FFA_MEM_SHARE_32 U(0x84000073) 65 #define FFA_MEM_SHARE_64 U(0xC4000073) 66 #define FFA_MEM_RETRIEVE_REQ_32 U(0x84000074) 67 #define FFA_MEM_RETRIEVE_REQ_64 U(0xC4000074) 68 #define FFA_MEM_RETRIEVE_RESP U(0x84000075) 69 #define FFA_MEM_RELINQUISH U(0x84000076) 70 #define FFA_MEM_RECLAIM U(0x84000077) 71 #define FFA_MEM_FRAG_RX U(0x8400007A) 72 #define FFA_MEM_FRAG_TX U(0x8400007B) 73 #define FFA_SECONDARY_EP_REGISTER_64 U(0xC4000087) 74 #define FFA_MEM_PERM_GET_32 U(0x84000088) 75 #define FFA_MEM_PERM_GET_64 U(0xC4000088) 76 #define FFA_MEM_PERM_SET_32 U(0x84000089) 77 #define FFA_MEM_PERM_SET_64 U(0xC4000089) 78 79 /* Special value for traffic targeted to the Hypervisor or SPM */ 80 #define FFA_TARGET_INFO_MBZ U(0x0) 81 82 /* Memory attributes: Normal memory, Write-Back cacheable, Inner shareable */ 83 #define FFA_NORMAL_MEM_REG_ATTR U(0x2f) 84 85 /* Memory access permissions: Read-write */ 86 #define FFA_MEM_ACC_RW BIT(1) 87 88 /* Memory access permissions: executable */ 89 #define FFA_MEM_ACC_EXE BIT(3) 90 91 /* Memory access permissions mask */ 92 #define FFA_MEM_ACC_MASK 0xf 93 94 /* Clear memory before mapping in receiver */ 95 #define FFA_MEMORY_REGION_FLAG_CLEAR BIT(0) 96 /* Relayer may time slice this operation */ 97 #define FFA_MEMORY_REGION_FLAG_TIME_SLICE BIT(1) 98 /* Clear memory after receiver relinquishes it */ 99 #define FFA_MEMORY_REGION_FLAG_CLEAR_RELINQUISH BIT(2) 100 101 /* Share memory transaction */ 102 #define FFA_MEMORY_REGION_TRANSACTION_TYPE_SHARE SHIFT_U32(1, 3) 103 /* Relayer must choose the alignment boundary */ 104 #define FFA_MEMORY_REGION_FLAG_ANY_ALIGNMENT 0 105 106 #define FFA_MEM_PERM_DATA_PERM GENMASK_32(1, 0) 107 #define FFA_MEM_PERM_RW U(0x1) 108 #define FFA_MEM_PERM_RO U(0x3) 109 110 #define FFA_MEM_PERM_INSTRUCTION_PERM BIT(2) 111 #define FFA_MEM_PERM_NX BIT(2) 112 #define FFA_MEM_PERM_X U(0) 113 114 #define FFA_MEM_PERM_RESERVED GENMASK_32(31, 3) 115 116 /* Special value for MBZ parameters */ 117 #define FFA_PARAM_MBZ U(0x0) 118 119 /* 120 * Flags used for the FFA_PARTITION_INFO_GET return message: 121 * BIT(0): Supports receipt of direct requests 122 * BIT(1): Can send direct requests 123 * BIT(2): Cannot send and receive indirect messages 124 * BIT(3): Does not support receipt of notifications 125 * BIT(4-5): Partition ID is a PE endpoint ID 126 */ 127 #define FFA_PARTITION_DIRECT_REQ_RECV_SUPPORT BIT(0) 128 #define FFA_PARTITION_DIRECT_REQ_SEND_SUPPORT BIT(1) 129 130 #define FFA_MEMORY_HANDLE_SECURE_BIT BIT64(45) 131 #define FFA_MEMORY_HANDLE_NONE_SECURE_BIT BIT64(44) 132 133 #define FFA_BOOT_INFO_NAME_LEN U(16) 134 135 /* Boot Info descriptors type */ 136 #define FFA_BOOT_INFO_TYPE_IMDEF BIT(7) 137 #define FFA_BOOT_INFO_TYPE_ID_MASK GENMASK_32(6, 0) 138 #define FFA_BOOT_INFO_TYPE_ID_FDT U(0) 139 #define FFA_BOOT_INFO_TYPE_ID_HOB U(1) 140 141 /* Boot Info descriptors flags */ 142 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_MASK GENMASK_32(1, 0) 143 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_STRING U(0) 144 #define FFA_BOOT_INFO_FLAG_NAME_FORMAT_UUID U(1) 145 146 /** Bits [3:2] encode the format of the content field in ffa_boot_info_desc. */ 147 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_SHIFT U(2) 148 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_MASK GENMASK_32(3, 2) 149 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_VALUE U(1) 150 #define FFA_BOOT_INFO_FLAG_CONTENT_FORMAT_ADDR U(0) 151 152 #define FFA_BOOT_INFO_SIGNATURE U(0xFFA) 153 #define FFA_BOOT_INFO_VERSION U(0x10001) 154 155 #ifndef __ASSEMBLER__ 156 /* Constituent memory region descriptor */ 157 struct ffa_address_range { 158 uint64_t address; 159 uint32_t page_count; 160 uint32_t reserved; 161 }; 162 163 /* Composite memory region descriptor */ 164 struct ffa_mem_region { 165 uint32_t total_page_count; 166 uint32_t address_range_count; 167 uint64_t reserved; 168 struct ffa_address_range address_range_array[]; 169 }; 170 171 /* Memory access permissions descriptor */ 172 struct ffa_mem_access_perm { 173 uint16_t endpoint_id; 174 uint8_t perm; 175 uint8_t flags; 176 }; 177 178 /* Endpoint memory access descriptor */ 179 struct ffa_mem_access { 180 struct ffa_mem_access_perm access_perm; 181 uint32_t region_offs; 182 uint64_t reserved; 183 }; 184 185 /* Lend, donate or share memory transaction descriptor */ 186 struct ffa_mem_transaction { 187 uint16_t sender_id; 188 uint8_t mem_reg_attr; 189 uint8_t reserved0; 190 uint32_t flags; 191 uint64_t global_handle; 192 uint64_t tag; 193 uint32_t reserved1; 194 uint32_t mem_access_count; 195 struct ffa_mem_access mem_access_array[]; 196 }; 197 198 /* Partition information descriptor */ 199 struct ffa_partition_info { 200 uint16_t id; 201 uint16_t execution_context; 202 uint32_t partition_properties; 203 }; 204 205 /* Descriptor to relinquish a memory region (FFA_MEM_RELINQUISH) */ 206 struct ffa_mem_relinquish { 207 uint64_t handle; 208 uint32_t flags; 209 uint32_t endpoint_count; 210 uint16_t endpoint_id_array[]; 211 }; 212 213 /* FF-A v1.1 boot information descriptor */ 214 struct ffa_boot_info { 215 char name[FFA_BOOT_INFO_NAME_LEN]; 216 uint8_t type; 217 uint8_t reserved; 218 uint16_t flags; 219 uint32_t size; 220 uint64_t contents; 221 }; 222 223 /* FF-A v1.1 boot information header */ 224 struct ffa_boot_info_header { 225 uint32_t signature; 226 uint32_t version; 227 uint32_t blob_size; 228 uint32_t desc_size; 229 uint32_t desc_count; 230 uint32_t desc_offset; 231 uint64_t reserved; 232 }; 233 234 #endif /*__ASSEMBLER__*/ 235 #endif /* __FFA_H */ 236