J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1 | /* |
Marc Bonnici | 8e1a755 | 2021-12-01 17:57:04 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef FFA_SVC_H |
| 8 | #define FFA_SVC_H |
| 9 | |
Marc Bonnici | 8e1a755 | 2021-12-01 17:57:04 +0000 | [diff] [blame] | 10 | #include <stdbool.h> |
| 11 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 12 | #include <lib/smccc.h> |
| 13 | #include <lib/utils_def.h> |
| 14 | #include <tools_share/uuid.h> |
| 15 | |
| 16 | /* FFA error codes. */ |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 17 | #define FFA_ERROR_NOT_SUPPORTED -1 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 18 | #define FFA_ERROR_INVALID_PARAMETER -2 |
| 19 | #define FFA_ERROR_NO_MEMORY -3 |
| 20 | #define FFA_ERROR_BUSY -4 |
| 21 | #define FFA_ERROR_INTERRUPTED -5 |
| 22 | #define FFA_ERROR_DENIED -6 |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 23 | #define FFA_ERROR_RETRY -7 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 24 | |
| 25 | /* The macros below are used to identify FFA calls from the SMC function ID */ |
| 26 | #define FFA_FNUM_MIN_VALUE U(0x60) |
J-Alves | 481c52f | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 27 | #define FFA_FNUM_MAX_VALUE U(0x87) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 28 | #define is_ffa_fid(fid) __extension__ ({ \ |
| 29 | __typeof__(fid) _fid = (fid); \ |
| 30 | ((GET_SMC_NUM(_fid) >= FFA_FNUM_MIN_VALUE) && \ |
| 31 | (GET_SMC_NUM(_fid) <= FFA_FNUM_MAX_VALUE)); }) |
| 32 | |
| 33 | /* FFA_VERSION helpers */ |
| 34 | #define FFA_VERSION_MAJOR U(1) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 35 | #define FFA_VERSION_MAJOR_SHIFT 16 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 36 | #define FFA_VERSION_MAJOR_MASK U(0x7FFF) |
J-Alves | 481c52f | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 37 | #define FFA_VERSION_MINOR U(1) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 38 | #define FFA_VERSION_MINOR_SHIFT 0 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 39 | #define FFA_VERSION_MINOR_MASK U(0xFFFF) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 40 | #define FFA_VERSION_BIT31_MASK U(0x1u << 31) |
Marc Bonnici | e95eb7c | 2021-12-08 14:24:03 +0000 | [diff] [blame] | 41 | #define FFA_VERSION_MASK U(0xFFFFFFFF) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 42 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 43 | |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 44 | #define MAKE_FFA_VERSION(major, minor) \ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 45 | ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \ |
| 46 | (((minor) & FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_SHIFT)) |
| 47 | #define FFA_VERSION_COMPILED MAKE_FFA_VERSION(FFA_VERSION_MAJOR, \ |
| 48 | FFA_VERSION_MINOR) |
| 49 | |
| 50 | /* FFA_MSG_SEND helpers */ |
| 51 | #define FFA_MSG_SEND_ATTRS_BLK_SHIFT U(0) |
| 52 | #define FFA_MSG_SEND_ATTRS_BLK_MASK U(0x1) |
| 53 | #define FFA_MSG_SEND_ATTRS_BLK U(0) |
| 54 | #define FFA_MSG_SEND_ATTRS_BLK_NOT U(1) |
| 55 | #define FFA_MSG_SEND_ATTRS(blk) \ |
| 56 | (((blk) & FFA_MSG_SEND_ATTRS_BLK_MASK) \ |
| 57 | << FFA_MSG_SEND_ATTRS_BLK_SHIFT) |
| 58 | |
| 59 | /* Get FFA fastcall std FID from function number */ |
| 60 | #define FFA_FID(smc_cc, func_num) \ |
| 61 | ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \ |
| 62 | ((smc_cc) << FUNCID_CC_SHIFT) | \ |
| 63 | (OEN_STD_START << FUNCID_OEN_SHIFT) | \ |
| 64 | ((func_num) << FUNCID_NUM_SHIFT)) |
| 65 | |
| 66 | /* FFA function numbers */ |
J-Alves | 481c52f | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 67 | #define FFA_FNUM_ERROR U(0x60) |
| 68 | #define FFA_FNUM_SUCCESS U(0x61) |
| 69 | #define FFA_FNUM_INTERRUPT U(0x62) |
| 70 | #define FFA_FNUM_VERSION U(0x63) |
| 71 | #define FFA_FNUM_FEATURES U(0x64) |
| 72 | #define FFA_FNUM_RX_RELEASE U(0x65) |
| 73 | #define FFA_FNUM_RXTX_MAP U(0x66) |
| 74 | #define FFA_FNUM_RXTX_UNMAP U(0x67) |
| 75 | #define FFA_FNUM_PARTITION_INFO_GET U(0x68) |
| 76 | #define FFA_FNUM_ID_GET U(0x69) |
| 77 | #define FFA_FNUM_MSG_POLL U(0x6A) /* Legacy FF-A v1.0 */ |
| 78 | #define FFA_FNUM_MSG_WAIT U(0x6B) |
| 79 | #define FFA_FNUM_MSG_YIELD U(0x6C) |
| 80 | #define FFA_FNUM_MSG_RUN U(0x6D) |
| 81 | #define FFA_FNUM_MSG_SEND U(0x6E) /* Legacy FF-A v1.0 */ |
| 82 | #define FFA_FNUM_MSG_SEND_DIRECT_REQ U(0x6F) |
| 83 | #define FFA_FNUM_MSG_SEND_DIRECT_RESP U(0x70) |
| 84 | #define FFA_FNUM_MEM_DONATE U(0x71) |
| 85 | #define FFA_FNUM_MEM_LEND U(0x72) |
| 86 | #define FFA_FNUM_MEM_SHARE U(0x73) |
| 87 | #define FFA_FNUM_MEM_RETRIEVE_REQ U(0x74) |
| 88 | #define FFA_FNUM_MEM_RETRIEVE_RESP U(0x75) |
| 89 | #define FFA_FNUM_MEM_RELINQUISH U(0x76) |
| 90 | #define FFA_FNUM_MEM_RECLAIM U(0x77) |
| 91 | #define FFA_FNUM_NORMAL_WORLD_RESUME U(0x7C) |
| 92 | |
| 93 | /* FF-A v1.1 */ |
| 94 | #define FFA_FNUM_NOTIFICATION_BITMAP_CREATE U(0x7D) |
| 95 | #define FFA_FNUM_NOTIFICATION_BITMAP_DESTROY U(0x7E) |
| 96 | #define FFA_FNUM_NOTIFICATION_BIND U(0x7F) |
| 97 | #define FFA_FNUM_NOTIFICATION_UNBIND U(0x80) |
| 98 | #define FFA_FNUM_NOTIFICATION_SET U(0x81) |
| 99 | #define FFA_FNUM_NOTIFICATION_GET U(0x82) |
| 100 | #define FFA_FNUM_NOTIFICATION_INFO_GET U(0x83) |
| 101 | #define FFA_FNUM_RX_ACQUIRE U(0x84) |
| 102 | #define FFA_FNUM_SPM_ID_GET U(0x85) |
| 103 | #define FFA_FNUM_MSG_SEND2 U(0x86) |
| 104 | #define FFA_FNUM_SECONDARY_EP_REGISTER U(0x87) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 105 | |
| 106 | /* FFA SMC32 FIDs */ |
| 107 | #define FFA_ERROR FFA_FID(SMC_32, FFA_FNUM_ERROR) |
| 108 | #define FFA_SUCCESS_SMC32 FFA_FID(SMC_32, FFA_FNUM_SUCCESS) |
| 109 | #define FFA_INTERRUPT FFA_FID(SMC_32, FFA_FNUM_INTERRUPT) |
| 110 | #define FFA_VERSION FFA_FID(SMC_32, FFA_FNUM_VERSION) |
| 111 | #define FFA_FEATURES FFA_FID(SMC_32, FFA_FNUM_FEATURES) |
| 112 | #define FFA_RX_RELEASE FFA_FID(SMC_32, FFA_FNUM_RX_RELEASE) |
Federico Recanati | 5c7c5c4 | 2022-03-18 10:30:00 +0100 | [diff] [blame] | 113 | #define FFA_RX_ACQUIRE FFA_FID(SMC_32, FFA_FNUM_RX_ACQUIRE) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 114 | #define FFA_RXTX_MAP_SMC32 FFA_FID(SMC_32, FFA_FNUM_RXTX_MAP) |
| 115 | #define FFA_RXTX_UNMAP FFA_FID(SMC_32, FFA_FNUM_RXTX_UNMAP) |
| 116 | #define FFA_PARTITION_INFO_GET FFA_FID(SMC_32, FFA_FNUM_PARTITION_INFO_GET) |
| 117 | #define FFA_ID_GET FFA_FID(SMC_32, FFA_FNUM_ID_GET) |
| 118 | #define FFA_MSG_POLL FFA_FID(SMC_32, FFA_FNUM_MSG_POLL) |
| 119 | #define FFA_MSG_WAIT FFA_FID(SMC_32, FFA_FNUM_MSG_WAIT) |
| 120 | #define FFA_MSG_YIELD FFA_FID(SMC_32, FFA_FNUM_MSG_YIELD) |
| 121 | #define FFA_MSG_RUN FFA_FID(SMC_32, FFA_FNUM_MSG_RUN) |
| 122 | #define FFA_MSG_SEND FFA_FID(SMC_32, FFA_FNUM_MSG_SEND) |
Federico Recanati | eecb4b0 | 2022-02-03 17:22:37 +0100 | [diff] [blame] | 123 | #define FFA_MSG_SEND2 FFA_FID(SMC_32, FFA_FNUM_MSG_SEND2) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 124 | #define FFA_MSG_SEND_DIRECT_REQ_SMC32 \ |
| 125 | FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_REQ) |
| 126 | #define FFA_MSG_SEND_DIRECT_RESP_SMC32 \ |
| 127 | FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_RESP) |
| 128 | #define FFA_MEM_DONATE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_DONATE) |
| 129 | #define FFA_MEM_LEND_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_LEND) |
| 130 | #define FFA_MEM_SHARE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_SHARE) |
| 131 | #define FFA_MEM_RETRIEVE_REQ_SMC32 \ |
| 132 | FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_REQ) |
| 133 | #define FFA_MEM_RETRIEVE_RESP FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_RESP) |
| 134 | #define FFA_MEM_RELINQUISH FFA_FID(SMC_32, FFA_FNUM_MEM_RELINQUISH) |
| 135 | #define FFA_MEM_RECLAIM FFA_FID(SMC_32, FFA_FNUM_MEM_RECLAIM) |
J-Alves | 2621cfd | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 136 | #define FFA_NOTIFICATION_BITMAP_CREATE \ |
| 137 | FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BITMAP_CREATE) |
| 138 | #define FFA_NOTIFICATION_BITMAP_DESTROY \ |
| 139 | FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BITMAP_DESTROY) |
| 140 | #define FFA_NOTIFICATION_BIND FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_BIND) |
| 141 | #define FFA_NOTIFICATION_UNBIND FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_UNBIND) |
| 142 | #define FFA_NOTIFICATION_SET FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_SET) |
| 143 | #define FFA_NOTIFICATION_GET FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_GET) |
| 144 | #define FFA_NOTIFICATION_INFO_GET \ |
| 145 | FFA_FID(SMC_32, FFA_FNUM_NOTIFICATION_INFO_GET) |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 146 | #define FFA_SPM_ID_GET FFA_FID(SMC_32, FFA_FNUM_SPM_ID_GET) |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 147 | #define FFA_NORMAL_WORLD_RESUME FFA_FID(SMC_32, FFA_FNUM_NORMAL_WORLD_RESUME) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 148 | |
| 149 | /* FFA SMC64 FIDs */ |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 150 | #define FFA_ERROR_SMC64 FFA_FID(SMC_64, FFA_FNUM_ERROR) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 151 | #define FFA_SUCCESS_SMC64 FFA_FID(SMC_64, FFA_FNUM_SUCCESS) |
| 152 | #define FFA_RXTX_MAP_SMC64 FFA_FID(SMC_64, FFA_FNUM_RXTX_MAP) |
| 153 | #define FFA_MSG_SEND_DIRECT_REQ_SMC64 \ |
| 154 | FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_REQ) |
| 155 | #define FFA_MSG_SEND_DIRECT_RESP_SMC64 \ |
| 156 | FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_RESP) |
| 157 | #define FFA_MEM_DONATE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_DONATE) |
| 158 | #define FFA_MEM_LEND_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_LEND) |
| 159 | #define FFA_MEM_SHARE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_SHARE) |
| 160 | #define FFA_MEM_RETRIEVE_REQ_SMC64 \ |
| 161 | FFA_FID(SMC_64, FFA_FNUM_MEM_RETRIEVE_REQ) |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 162 | #define FFA_SECONDARY_EP_REGISTER_SMC64 \ |
| 163 | FFA_FID(SMC_64, FFA_FNUM_SECONDARY_EP_REGISTER) |
J-Alves | 2621cfd | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 164 | #define FFA_NOTIFICATION_INFO_GET_SMC64 \ |
| 165 | FFA_FID(SMC_64, FFA_FNUM_NOTIFICATION_INFO_GET) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 166 | |
| 167 | /* |
Marc Bonnici | 9a29704 | 2022-02-14 17:06:09 +0000 | [diff] [blame] | 168 | * FF-A partition properties values. |
| 169 | */ |
| 170 | #define FFA_PARTITION_DIRECT_REQ_RECV U(1 << 0) |
| 171 | #define FFA_PARTITION_DIRECT_REQ_SEND U(1 << 1) |
| 172 | #define FFA_PARTITION_INDIRECT_MSG U(1 << 2) |
| 173 | |
| 174 | /* |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 175 | * Reserve a special value for traffic targeted to the Hypervisor or SPM. |
| 176 | */ |
| 177 | #define FFA_TARGET_INFO_MBZ U(0x0) |
| 178 | |
| 179 | /* |
| 180 | * Reserve a special value for MBZ parameters. |
| 181 | */ |
| 182 | #define FFA_PARAM_MBZ U(0x0) |
| 183 | |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 184 | /* |
| 185 | * Maximum FF-A endpoint id value |
| 186 | */ |
| 187 | #define FFA_ENDPOINT_ID_MAX U(1 << 16) |
| 188 | |
| 189 | /* |
Marc Bonnici | 8e1a755 | 2021-12-01 17:57:04 +0000 | [diff] [blame] | 190 | * Reserve endpoint id for the SPMD. |
| 191 | */ |
| 192 | #define SPMD_DIRECT_MSG_ENDPOINT_ID U(FFA_ENDPOINT_ID_MAX - 1) |
| 193 | |
| 194 | /* Mask and shift to check valid secure FF-A Endpoint ID. */ |
| 195 | #define SPMC_SECURE_ID_MASK U(1) |
| 196 | #define SPMC_SECURE_ID_SHIFT U(15) |
| 197 | |
| 198 | /* |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 199 | * Mask for source and destination endpoint id in |
| 200 | * a direct message request/response. |
| 201 | */ |
| 202 | #define FFA_DIRECT_MSG_ENDPOINT_ID_MASK U(0xffff) |
| 203 | |
| 204 | /* |
| 205 | * Bit shift for destination endpoint id in a direct message request/response. |
| 206 | */ |
| 207 | #define FFA_DIRECT_MSG_DESTINATION_SHIFT U(0) |
| 208 | |
| 209 | /* |
| 210 | * Bit shift for source endpoint id in a direct message request/response. |
| 211 | */ |
| 212 | #define FFA_DIRECT_MSG_SOURCE_SHIFT U(16) |
| 213 | |
| 214 | /****************************************************************************** |
| 215 | * ffa_endpoint_destination |
| 216 | *****************************************************************************/ |
| 217 | static inline uint16_t ffa_endpoint_destination(unsigned int ep) |
| 218 | { |
| 219 | return (ep >> FFA_DIRECT_MSG_DESTINATION_SHIFT) & |
| 220 | FFA_DIRECT_MSG_ENDPOINT_ID_MASK; |
| 221 | } |
| 222 | |
| 223 | /****************************************************************************** |
| 224 | * ffa_endpoint_source |
| 225 | *****************************************************************************/ |
| 226 | static inline uint16_t ffa_endpoint_source(unsigned int ep) |
| 227 | { |
| 228 | return (ep >> FFA_DIRECT_MSG_SOURCE_SHIFT) & |
| 229 | FFA_DIRECT_MSG_ENDPOINT_ID_MASK; |
| 230 | } |
| 231 | |
Marc Bonnici | 8e1a755 | 2021-12-01 17:57:04 +0000 | [diff] [blame] | 232 | /****************************************************************************** |
| 233 | * FF-A helper functions to determine partition ID world. |
| 234 | *****************************************************************************/ |
| 235 | |
| 236 | /* |
| 237 | * Determine if provided ID is in the secure world. |
| 238 | */ |
| 239 | static inline bool ffa_is_secure_world_id(uint16_t id) |
| 240 | { |
| 241 | return ((id >> SPMC_SECURE_ID_SHIFT) & SPMC_SECURE_ID_MASK) == 1; |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * Determine if provided ID is in the normal world. |
| 246 | */ |
| 247 | static inline bool ffa_is_normal_world_id(uint16_t id) |
| 248 | { |
| 249 | return !ffa_is_secure_world_id(id); |
| 250 | } |
| 251 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 252 | #endif /* FFA_SVC_H */ |