J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1 | /* |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, 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 | |
| 10 | #include <lib/smccc.h> |
| 11 | #include <lib/utils_def.h> |
| 12 | #include <tools_share/uuid.h> |
| 13 | |
| 14 | /* FFA error codes. */ |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 15 | #define FFA_ERROR_NOT_SUPPORTED -1 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 16 | #define FFA_ERROR_INVALID_PARAMETER -2 |
| 17 | #define FFA_ERROR_NO_MEMORY -3 |
| 18 | #define FFA_ERROR_BUSY -4 |
| 19 | #define FFA_ERROR_INTERRUPTED -5 |
| 20 | #define FFA_ERROR_DENIED -6 |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 21 | #define FFA_ERROR_RETRY -7 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 22 | |
| 23 | /* The macros below are used to identify FFA calls from the SMC function ID */ |
| 24 | #define FFA_FNUM_MIN_VALUE U(0x60) |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 25 | #define FFA_FNUM_MAX_VALUE U(0x85) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 26 | #define is_ffa_fid(fid) __extension__ ({ \ |
| 27 | __typeof__(fid) _fid = (fid); \ |
| 28 | ((GET_SMC_NUM(_fid) >= FFA_FNUM_MIN_VALUE) && \ |
| 29 | (GET_SMC_NUM(_fid) <= FFA_FNUM_MAX_VALUE)); }) |
| 30 | |
| 31 | /* FFA_VERSION helpers */ |
| 32 | #define FFA_VERSION_MAJOR U(1) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 33 | #define FFA_VERSION_MAJOR_SHIFT 16 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 34 | #define FFA_VERSION_MAJOR_MASK U(0x7FFF) |
| 35 | #define FFA_VERSION_MINOR U(0) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 36 | #define FFA_VERSION_MINOR_SHIFT 0 |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 37 | #define FFA_VERSION_MINOR_MASK U(0xFFFF) |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 38 | #define FFA_VERSION_BIT31_MASK U(0x1u << 31) |
| 39 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 40 | |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 41 | #define MAKE_FFA_VERSION(major, minor) \ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 42 | ((((major) & FFA_VERSION_MAJOR_MASK) << FFA_VERSION_MAJOR_SHIFT) | \ |
| 43 | (((minor) & FFA_VERSION_MINOR_MASK) << FFA_VERSION_MINOR_SHIFT)) |
| 44 | #define FFA_VERSION_COMPILED MAKE_FFA_VERSION(FFA_VERSION_MAJOR, \ |
| 45 | FFA_VERSION_MINOR) |
| 46 | |
| 47 | /* FFA_MSG_SEND helpers */ |
| 48 | #define FFA_MSG_SEND_ATTRS_BLK_SHIFT U(0) |
| 49 | #define FFA_MSG_SEND_ATTRS_BLK_MASK U(0x1) |
| 50 | #define FFA_MSG_SEND_ATTRS_BLK U(0) |
| 51 | #define FFA_MSG_SEND_ATTRS_BLK_NOT U(1) |
| 52 | #define FFA_MSG_SEND_ATTRS(blk) \ |
| 53 | (((blk) & FFA_MSG_SEND_ATTRS_BLK_MASK) \ |
| 54 | << FFA_MSG_SEND_ATTRS_BLK_SHIFT) |
| 55 | |
| 56 | /* Get FFA fastcall std FID from function number */ |
| 57 | #define FFA_FID(smc_cc, func_num) \ |
| 58 | ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \ |
| 59 | ((smc_cc) << FUNCID_CC_SHIFT) | \ |
| 60 | (OEN_STD_START << FUNCID_OEN_SHIFT) | \ |
| 61 | ((func_num) << FUNCID_NUM_SHIFT)) |
| 62 | |
| 63 | /* FFA function numbers */ |
| 64 | #define FFA_FNUM_ERROR U(0x60) |
| 65 | #define FFA_FNUM_SUCCESS U(0x61) |
| 66 | #define FFA_FNUM_INTERRUPT U(0x62) |
| 67 | #define FFA_FNUM_VERSION U(0x63) |
| 68 | #define FFA_FNUM_FEATURES U(0x64) |
| 69 | #define FFA_FNUM_RX_RELEASE U(0x65) |
| 70 | #define FFA_FNUM_RXTX_MAP U(0x66) |
| 71 | #define FFA_FNUM_RXTX_UNMAP U(0x67) |
| 72 | #define FFA_FNUM_PARTITION_INFO_GET U(0x68) |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 73 | #define FFA_FNUM_ID_GET U(0x69) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 74 | #define FFA_FNUM_MSG_POLL U(0x6A) |
| 75 | #define FFA_FNUM_MSG_WAIT U(0x6B) |
| 76 | #define FFA_FNUM_MSG_YIELD U(0x6C) |
| 77 | #define FFA_FNUM_MSG_RUN U(0x6D) |
| 78 | #define FFA_FNUM_MSG_SEND U(0x6E) |
| 79 | #define FFA_FNUM_MSG_SEND_DIRECT_REQ U(0x6F) |
| 80 | #define FFA_FNUM_MSG_SEND_DIRECT_RESP U(0x70) |
| 81 | #define FFA_FNUM_MEM_DONATE U(0x71) |
| 82 | #define FFA_FNUM_MEM_LEND U(0x72) |
| 83 | #define FFA_FNUM_MEM_SHARE U(0x73) |
| 84 | #define FFA_FNUM_MEM_RETRIEVE_REQ U(0x74) |
| 85 | #define FFA_FNUM_MEM_RETRIEVE_RESP U(0x75) |
| 86 | #define FFA_FNUM_MEM_RELINQUISH U(0x76) |
| 87 | #define FFA_FNUM_MEM_RECLAIM U(0x77) |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 88 | #define FFA_FNUM_SECONDARY_EP_REGISTER U(0x84) |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 89 | #define FFA_FNUM_SPM_ID_GET U(0x85) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 90 | |
| 91 | /* FFA SMC32 FIDs */ |
| 92 | #define FFA_ERROR FFA_FID(SMC_32, FFA_FNUM_ERROR) |
| 93 | #define FFA_SUCCESS_SMC32 FFA_FID(SMC_32, FFA_FNUM_SUCCESS) |
| 94 | #define FFA_INTERRUPT FFA_FID(SMC_32, FFA_FNUM_INTERRUPT) |
| 95 | #define FFA_VERSION FFA_FID(SMC_32, FFA_FNUM_VERSION) |
| 96 | #define FFA_FEATURES FFA_FID(SMC_32, FFA_FNUM_FEATURES) |
| 97 | #define FFA_RX_RELEASE FFA_FID(SMC_32, FFA_FNUM_RX_RELEASE) |
| 98 | #define FFA_RXTX_MAP_SMC32 FFA_FID(SMC_32, FFA_FNUM_RXTX_MAP) |
| 99 | #define FFA_RXTX_UNMAP FFA_FID(SMC_32, FFA_FNUM_RXTX_UNMAP) |
| 100 | #define FFA_PARTITION_INFO_GET FFA_FID(SMC_32, FFA_FNUM_PARTITION_INFO_GET) |
| 101 | #define FFA_ID_GET FFA_FID(SMC_32, FFA_FNUM_ID_GET) |
| 102 | #define FFA_MSG_POLL FFA_FID(SMC_32, FFA_FNUM_MSG_POLL) |
| 103 | #define FFA_MSG_WAIT FFA_FID(SMC_32, FFA_FNUM_MSG_WAIT) |
| 104 | #define FFA_MSG_YIELD FFA_FID(SMC_32, FFA_FNUM_MSG_YIELD) |
| 105 | #define FFA_MSG_RUN FFA_FID(SMC_32, FFA_FNUM_MSG_RUN) |
| 106 | #define FFA_MSG_SEND FFA_FID(SMC_32, FFA_FNUM_MSG_SEND) |
| 107 | #define FFA_MSG_SEND_DIRECT_REQ_SMC32 \ |
| 108 | FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_REQ) |
| 109 | #define FFA_MSG_SEND_DIRECT_RESP_SMC32 \ |
| 110 | FFA_FID(SMC_32, FFA_FNUM_MSG_SEND_DIRECT_RESP) |
| 111 | #define FFA_MEM_DONATE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_DONATE) |
| 112 | #define FFA_MEM_LEND_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_LEND) |
| 113 | #define FFA_MEM_SHARE_SMC32 FFA_FID(SMC_32, FFA_FNUM_MEM_SHARE) |
| 114 | #define FFA_MEM_RETRIEVE_REQ_SMC32 \ |
| 115 | FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_REQ) |
| 116 | #define FFA_MEM_RETRIEVE_RESP FFA_FID(SMC_32, FFA_FNUM_MEM_RETRIEVE_RESP) |
| 117 | #define FFA_MEM_RELINQUISH FFA_FID(SMC_32, FFA_FNUM_MEM_RELINQUISH) |
| 118 | #define FFA_MEM_RECLAIM FFA_FID(SMC_32, FFA_FNUM_MEM_RECLAIM) |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 119 | #define FFA_SPM_ID_GET FFA_FID(SMC_32, FFA_FNUM_SPM_ID_GET) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 120 | |
| 121 | /* FFA SMC64 FIDs */ |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 122 | #define FFA_ERROR_SMC64 FFA_FID(SMC_64, FFA_FNUM_ERROR) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 123 | #define FFA_SUCCESS_SMC64 FFA_FID(SMC_64, FFA_FNUM_SUCCESS) |
| 124 | #define FFA_RXTX_MAP_SMC64 FFA_FID(SMC_64, FFA_FNUM_RXTX_MAP) |
| 125 | #define FFA_MSG_SEND_DIRECT_REQ_SMC64 \ |
| 126 | FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_REQ) |
| 127 | #define FFA_MSG_SEND_DIRECT_RESP_SMC64 \ |
| 128 | FFA_FID(SMC_64, FFA_FNUM_MSG_SEND_DIRECT_RESP) |
| 129 | #define FFA_MEM_DONATE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_DONATE) |
| 130 | #define FFA_MEM_LEND_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_LEND) |
| 131 | #define FFA_MEM_SHARE_SMC64 FFA_FID(SMC_64, FFA_FNUM_MEM_SHARE) |
| 132 | #define FFA_MEM_RETRIEVE_REQ_SMC64 \ |
| 133 | FFA_FID(SMC_64, FFA_FNUM_MEM_RETRIEVE_REQ) |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 134 | #define FFA_SECONDARY_EP_REGISTER_SMC64 \ |
| 135 | FFA_FID(SMC_64, FFA_FNUM_SECONDARY_EP_REGISTER) |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * Reserve a special value for traffic targeted to the Hypervisor or SPM. |
| 139 | */ |
| 140 | #define FFA_TARGET_INFO_MBZ U(0x0) |
| 141 | |
| 142 | /* |
| 143 | * Reserve a special value for MBZ parameters. |
| 144 | */ |
| 145 | #define FFA_PARAM_MBZ U(0x0) |
| 146 | |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 147 | /* |
| 148 | * Maximum FF-A endpoint id value |
| 149 | */ |
| 150 | #define FFA_ENDPOINT_ID_MAX U(1 << 16) |
| 151 | |
| 152 | /* |
| 153 | * Mask for source and destination endpoint id in |
| 154 | * a direct message request/response. |
| 155 | */ |
| 156 | #define FFA_DIRECT_MSG_ENDPOINT_ID_MASK U(0xffff) |
| 157 | |
| 158 | /* |
| 159 | * Bit shift for destination endpoint id in a direct message request/response. |
| 160 | */ |
| 161 | #define FFA_DIRECT_MSG_DESTINATION_SHIFT U(0) |
| 162 | |
| 163 | /* |
| 164 | * Bit shift for source endpoint id in a direct message request/response. |
| 165 | */ |
| 166 | #define FFA_DIRECT_MSG_SOURCE_SHIFT U(16) |
| 167 | |
| 168 | /****************************************************************************** |
| 169 | * ffa_endpoint_destination |
| 170 | *****************************************************************************/ |
| 171 | static inline uint16_t ffa_endpoint_destination(unsigned int ep) |
| 172 | { |
| 173 | return (ep >> FFA_DIRECT_MSG_DESTINATION_SHIFT) & |
| 174 | FFA_DIRECT_MSG_ENDPOINT_ID_MASK; |
| 175 | } |
| 176 | |
| 177 | /****************************************************************************** |
| 178 | * ffa_endpoint_source |
| 179 | *****************************************************************************/ |
| 180 | static inline uint16_t ffa_endpoint_source(unsigned int ep) |
| 181 | { |
| 182 | return (ep >> FFA_DIRECT_MSG_SOURCE_SHIFT) & |
| 183 | FFA_DIRECT_MSG_ENDPOINT_ID_MASK; |
| 184 | } |
| 185 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 186 | #endif /* FFA_SVC_H */ |