| Antonio Nino Diaz | 652d20a | 2018-12-10 17:17:33 +0000 | [diff] [blame] | 1 | /* |
| Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2023, Arm Limited. All rights reserved. |
| Antonio Nino Diaz | 652d20a | 2018-12-10 17:17:33 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 6 | #include <assert.h> |
| Max Shvetsov | 103e056 | 2021-02-04 16:58:31 +0000 | [diff] [blame] | 7 | |
| J-Alves | 8f4a56f | 2020-10-28 10:29:05 +0000 | [diff] [blame] | 8 | #include <ffa_endpoints.h> |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 9 | #include <ffa_helpers.h> |
| 10 | #include <ffa_svc.h> |
| Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 11 | #include <smccc.h> |
| Antonio Nino Diaz | 652d20a | 2018-12-10 17:17:33 +0000 | [diff] [blame] | 12 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 13 | struct ffa_value ffa_service_call(struct ffa_value *args) |
| 14 | { |
| 15 | #if IMAGE_IVY |
| 16 | ffa_svc(args); |
| 17 | #else |
| 18 | ffa_smc(args); |
| 19 | #endif |
| 20 | return *args; |
| 21 | } |
| 22 | |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 23 | /*----------------------------------------------------------------------------- |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 24 | * FFA_RUN |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 25 | * |
| 26 | * Parameters |
| 27 | * uint32 Function ID (w0): 0x8400006D |
| 28 | * uint32 Target information (w1): Information to identify target SP/VM |
| 29 | * -Bits[31:16]: ID of SP/VM. |
| 30 | * -Bits[15:0]: ID of vCPU of SP/VM to run. |
| 31 | * Other Parameter registers w2-w7/x2-x7: Reserved (MBZ) |
| 32 | * |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 33 | * On failure, returns FFA_ERROR in w0 and error code in w2: |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 34 | * -INVALID_PARAMETERS: Unrecognized endpoint or vCPU ID |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 35 | * -NOT_SUPPORTED: This function is not implemented at this FFA instance |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 36 | * -DENIED: Callee is not in a state to handle this request |
| 37 | * -BUSY: vCPU is busy and caller must retry later |
| 38 | * -ABORTED: vCPU or VM ran into an unexpected error and has aborted |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 39 | */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 40 | struct ffa_value ffa_run(uint32_t dest_id, uint32_t vcpu_id) |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 41 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 42 | struct ffa_value args = { |
| Olivier Deprez | 56b270f | 2022-08-23 17:18:55 +0200 | [diff] [blame] | 43 | FFA_RUN, |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 44 | (dest_id << 16) | vcpu_id, |
| 45 | 0, 0, 0, 0, 0, 0 |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 48 | return ffa_service_call(&args); |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 51 | /*----------------------------------------------------------------------------- |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 52 | * FFA_MSG_SEND_DIRECT_REQ |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 53 | * |
| 54 | * Parameters |
| 55 | * uint32 Function ID (w0): 0x8400006F / 0xC400006F |
| 56 | * uint32 Source/Destination IDs (w1): Source and destination endpoint IDs |
| 57 | * -Bit[31:16]: Source endpoint ID |
| 58 | * -Bit[15:0]: Destination endpoint ID |
| 59 | * uint32/uint64 (w2/x2) - RFU MBZ |
| 60 | * w3-w7 - Implementation defined |
| 61 | * |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 62 | * On failure, returns FFA_ERROR in w0 and error code in w2: |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 63 | * -INVALID_PARAMETERS: Invalid endpoint ID or non-zero reserved register |
| 64 | * -DENIED: Callee is not in a state to handle this request |
| J-Alves | 7581c38 | 2020-05-07 18:34:20 +0100 | [diff] [blame] | 65 | * -NOT_SUPPORTED: This function is not implemented at this FFA instance |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 66 | * -BUSY: Message target is busy |
| 67 | * -ABORTED: Message target ran into an unexpected error and has aborted |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 68 | */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 69 | struct ffa_value ffa_msg_send_direct_req64(ffa_id_t source_id, |
| 70 | ffa_id_t dest_id, uint64_t arg0, |
| 71 | uint64_t arg1, uint64_t arg2, |
| 72 | uint64_t arg3, uint64_t arg4) |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 73 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 74 | struct ffa_value args = { |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 75 | .fid = FFA_MSG_SEND_DIRECT_REQ_SMC64, |
| 76 | .arg1 = ((uint32_t)(source_id << 16)) | (dest_id), |
| 77 | .arg2 = 0, |
| 78 | .arg3 = arg0, |
| 79 | .arg4 = arg1, |
| 80 | .arg5 = arg2, |
| 81 | .arg6 = arg3, |
| 82 | .arg7 = arg4, |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 85 | return ffa_service_call(&args); |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 88 | struct ffa_value ffa_msg_send_direct_req32(ffa_id_t source_id, |
| 89 | ffa_id_t dest_id, uint32_t arg0, |
| 90 | uint32_t arg1, uint32_t arg2, |
| 91 | uint32_t arg3, uint32_t arg4) |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 92 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 93 | struct ffa_value args = { |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 94 | .fid = FFA_MSG_SEND_DIRECT_REQ_SMC32, |
| 95 | .arg1 = ((uint32_t)(source_id << 16)) | (dest_id), |
| 96 | .arg2 = 0, |
| 97 | .arg3 = arg0, |
| 98 | .arg4 = arg1, |
| 99 | .arg5 = arg2, |
| 100 | .arg6 = arg3, |
| 101 | .arg7 = arg4, |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 104 | return ffa_service_call(&args); |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 105 | } |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 106 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 107 | struct ffa_value ffa_msg_send_direct_resp64(ffa_id_t source_id, |
| 108 | ffa_id_t dest_id, uint64_t arg0, |
| 109 | uint64_t arg1, uint64_t arg2, |
| 110 | uint64_t arg3, uint64_t arg4) |
| Olivier Deprez | 61be4c1 | 2019-12-06 17:45:07 +0100 | [diff] [blame] | 111 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 112 | struct ffa_value args = { |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 113 | .fid = FFA_MSG_SEND_DIRECT_RESP_SMC64, |
| 114 | .arg1 = ((uint32_t)(source_id << 16)) | (dest_id), |
| 115 | .arg2 = 0, |
| 116 | .arg3 = arg0, |
| 117 | .arg4 = arg1, |
| 118 | .arg5 = arg2, |
| 119 | .arg6 = arg3, |
| 120 | .arg7 = arg4, |
| 121 | }; |
| 122 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 123 | return ffa_service_call(&args); |
| Antonio Nino Diaz | ad8fcee | 2018-12-18 10:51:36 +0000 | [diff] [blame] | 124 | } |
| J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 125 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 126 | struct ffa_value ffa_msg_send_direct_resp32(ffa_id_t source_id, |
| 127 | ffa_id_t dest_id, uint32_t arg0, |
| 128 | uint32_t arg1, uint32_t arg2, |
| 129 | uint32_t arg3, uint32_t arg4) |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 130 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 131 | struct ffa_value args = { |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 132 | .fid = FFA_MSG_SEND_DIRECT_RESP_SMC32, |
| 133 | .arg1 = ((uint32_t)(source_id << 16)) | (dest_id), |
| 134 | .arg2 = 0, |
| 135 | .arg3 = arg0, |
| 136 | .arg4 = arg1, |
| 137 | .arg5 = arg2, |
| 138 | .arg6 = arg3, |
| 139 | .arg7 = arg4, |
| 140 | }; |
| 141 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 142 | return ffa_service_call(&args); |
| J-Alves | ecd3074 | 2021-02-19 18:31:06 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 145 | void ffa_memory_region_init_header(struct ffa_memory_region *memory_region, |
| 146 | ffa_id_t sender, |
| 147 | ffa_memory_attributes_t attributes, |
| 148 | ffa_memory_region_flags_t flags, |
| 149 | ffa_memory_handle_t handle, uint32_t tag, |
| 150 | uint32_t receiver_count) |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 151 | { |
| 152 | memory_region->sender = sender; |
| 153 | memory_region->attributes = attributes; |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 154 | memory_region->flags = flags; |
| 155 | memory_region->handle = handle; |
| 156 | memory_region->tag = tag; |
| J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 157 | memory_region->memory_access_desc_size = |
| 158 | sizeof(struct ffa_memory_access); |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 159 | memory_region->receiver_count = receiver_count; |
| 160 | memory_region->receivers_offset = |
| 161 | offsetof(struct ffa_memory_region, receivers); |
| J-Alves | b42d17f | 2022-07-04 12:42:13 +0100 | [diff] [blame] | 162 | memset(memory_region->reserved, 0, sizeof(memory_region->reserved)); |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 166 | * Copies as many as possible of the given constituents to the respective |
| 167 | * memory region and sets the respective offset. |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 168 | * |
| 169 | * Returns the number of constituents remaining which wouldn't fit, and (via |
| 170 | * return parameters) the size in bytes of the first fragment of data copied to |
| 171 | * `memory_region` (attributes, constituents and memory region header size), and |
| 172 | * the total size of the memory sharing message including all constituents. |
| 173 | */ |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 174 | static uint32_t ffa_memory_region_init_constituents( |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 175 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 176 | const struct ffa_memory_region_constituent constituents[], |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 177 | uint32_t constituent_count, uint32_t *total_length, |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 178 | uint32_t *fragment_length) |
| 179 | { |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 180 | struct ffa_composite_memory_region *composite_memory_region; |
| 181 | uint32_t fragment_max_constituents; |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 182 | uint32_t constituents_offset; |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 183 | uint32_t count_to_copy; |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 184 | |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 185 | /* |
| 186 | * Note that `sizeof(struct_ffa_memory_region)` and `sizeof(struct |
| 187 | * ffa_memory_access)` must both be multiples of 16 (as verified by the |
| 188 | * asserts in `ffa_memory.c`, so it is guaranteed that the offset we |
| 189 | * calculate here is aligned to a 64-bit boundary and so 64-bit values |
| 190 | * can be copied without alignment faults. |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 191 | * If there are multiple receiver endpoints, their respective access |
| 192 | * structure should point to the same offset value. |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 193 | */ |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 194 | for (uint32_t i = 0; i < memory_region->receiver_count; i++) { |
| 195 | memory_region->receivers[i].composite_memory_region_offset = |
| 196 | sizeof(struct ffa_memory_region) + |
| 197 | memory_region->receiver_count * |
| 198 | sizeof(struct ffa_memory_access); |
| 199 | } |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 200 | |
| 201 | composite_memory_region = |
| 202 | ffa_memory_region_get_composite(memory_region, 0); |
| 203 | composite_memory_region->page_count = 0; |
| 204 | composite_memory_region->constituent_count = constituent_count; |
| 205 | composite_memory_region->reserved_0 = 0; |
| 206 | |
| 207 | constituents_offset = |
| 208 | memory_region->receivers[0].composite_memory_region_offset + |
| 209 | sizeof(struct ffa_composite_memory_region); |
| 210 | fragment_max_constituents = |
| 211 | (memory_region_max_size - constituents_offset) / |
| 212 | sizeof(struct ffa_memory_region_constituent); |
| 213 | |
| 214 | count_to_copy = constituent_count; |
| 215 | if (count_to_copy > fragment_max_constituents) { |
| 216 | count_to_copy = fragment_max_constituents; |
| 217 | } |
| 218 | |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 219 | for (uint32_t i = 0; i < constituent_count; ++i) { |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 220 | if (i < count_to_copy) { |
| 221 | composite_memory_region->constituents[i] = |
| 222 | constituents[i]; |
| 223 | } |
| 224 | composite_memory_region->page_count += |
| 225 | constituents[i].page_count; |
| 226 | } |
| 227 | |
| 228 | if (total_length != NULL) { |
| 229 | *total_length = |
| 230 | constituents_offset + |
| 231 | composite_memory_region->constituent_count * |
| 232 | sizeof(struct ffa_memory_region_constituent); |
| 233 | } |
| 234 | if (fragment_length != NULL) { |
| 235 | *fragment_length = |
| 236 | constituents_offset + |
| 237 | count_to_copy * |
| 238 | sizeof(struct ffa_memory_region_constituent); |
| 239 | } |
| 240 | |
| 241 | return composite_memory_region->constituent_count - count_to_copy; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Initialises the given `ffa_memory_region` to be used for an |
| 246 | * `FFA_MEM_RETRIEVE_REQ` by the receiver of a memory transaction. |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 247 | * Initialises the given `ffa_memory_region` and copies as many as possible of |
| 248 | * the given constituents to it. |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 249 | * |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 250 | * Returns the number of constituents remaining which wouldn't fit, and (via |
| 251 | * return parameters) the size in bytes of the first fragment of data copied to |
| 252 | * `memory_region` (attributes, constituents and memory region header size), and |
| 253 | * the total size of the memory sharing message including all constituents. |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 254 | */ |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 255 | uint32_t ffa_memory_region_init( |
| 256 | struct ffa_memory_region *memory_region, size_t memory_region_max_size, |
| 257 | ffa_id_t sender, struct ffa_memory_access receivers[], |
| 258 | uint32_t receiver_count, |
| 259 | const struct ffa_memory_region_constituent constituents[], |
| 260 | uint32_t constituent_count, uint32_t tag, |
| 261 | ffa_memory_region_flags_t flags, enum ffa_memory_type type, |
| 262 | enum ffa_memory_cacheability cacheability, |
| 263 | enum ffa_memory_shareability shareability, uint32_t *total_length, |
| 264 | uint32_t *fragment_length) |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 265 | { |
| Karl Meakin | 92aa770 | 2023-10-11 18:48:01 +0100 | [diff] [blame] | 266 | ffa_memory_attributes_t attributes = { |
| 267 | .type = type, |
| 268 | .cacheability = cacheability, |
| 269 | .shareability = shareability, |
| 270 | }; |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 271 | |
| 272 | ffa_memory_region_init_header(memory_region, sender, attributes, flags, |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 273 | 0, tag, receiver_count); |
| 274 | |
| 275 | memcpy(memory_region->receivers, receivers, |
| 276 | receiver_count * sizeof(struct ffa_memory_access)); |
| 277 | |
| 278 | return ffa_memory_region_init_constituents( |
| 279 | memory_region, memory_region_max_size, constituents, |
| 280 | constituent_count, total_length, fragment_length); |
| 281 | } |
| 282 | |
| Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 283 | uint32_t ffa_memory_fragment_init( |
| 284 | struct ffa_memory_region_constituent *fragment, |
| 285 | size_t fragment_max_size, |
| 286 | const struct ffa_memory_region_constituent constituents[], |
| 287 | uint32_t constituent_count, uint32_t *fragment_length) |
| 288 | { |
| 289 | const uint32_t fragment_max_constituents = |
| 290 | fragment_max_size / |
| 291 | sizeof(struct ffa_memory_region_constituent); |
| 292 | |
| 293 | uint32_t count_to_copy = |
| 294 | MIN(constituent_count, fragment_max_constituents); |
| 295 | |
| 296 | for (uint32_t i = 0; i < count_to_copy; ++i) { |
| 297 | fragment[i] = constituents[i]; |
| 298 | } |
| 299 | |
| 300 | if (fragment_length != NULL) { |
| 301 | *fragment_length = count_to_copy * |
| 302 | sizeof(struct ffa_memory_region_constituent); |
| 303 | } |
| 304 | |
| 305 | return constituent_count - count_to_copy; |
| 306 | } |
| 307 | |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 308 | /** |
| 309 | * Initialises the given `ffa_memory_region` to be used for an |
| 310 | * `FFA_MEM_RETRIEVE_REQ` by the receiver of a memory transaction. |
| 311 | * |
| 312 | * Returns the size of the message written. |
| 313 | */ |
| 314 | uint32_t ffa_memory_retrieve_request_init( |
| 315 | struct ffa_memory_region *memory_region, ffa_memory_handle_t handle, |
| 316 | ffa_id_t sender, struct ffa_memory_access receivers[], |
| 317 | uint32_t receiver_count, uint32_t tag, ffa_memory_region_flags_t flags, |
| 318 | enum ffa_memory_type type, enum ffa_memory_cacheability cacheability, |
| 319 | enum ffa_memory_shareability shareability) |
| 320 | { |
| 321 | ffa_memory_attributes_t attributes = { |
| 322 | .type = type, |
| 323 | .cacheability = cacheability, |
| 324 | .shareability = shareability, |
| 325 | }; |
| 326 | |
| 327 | ffa_memory_region_init_header(memory_region, sender, attributes, flags, |
| 328 | handle, tag, receiver_count); |
| 329 | |
| 330 | memcpy(memory_region->receivers, receivers, |
| 331 | receiver_count * sizeof(struct ffa_memory_access)); |
| 332 | |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 333 | /* |
| 334 | * Offset 0 in this case means that the hypervisor should allocate the |
| 335 | * address ranges. This is the only configuration supported by Hafnium, |
| 336 | * as it enforces 1:1 mappings in the stage 2 page tables. |
| 337 | */ |
| Karl Meakin | 1331a8c | 2023-09-14 16:25:15 +0100 | [diff] [blame] | 338 | for (uint32_t i = 0; i < receiver_count; i++) { |
| 339 | memory_region->receivers[i].composite_memory_region_offset = 0; |
| 340 | memory_region->receivers[i].reserved_0 = 0; |
| 341 | } |
| J-Alves | f3a393c | 2020-10-23 16:00:39 +0100 | [diff] [blame] | 342 | |
| 343 | return sizeof(struct ffa_memory_region) + |
| 344 | memory_region->receiver_count * sizeof(struct ffa_memory_access); |
| 345 | } |
| 346 | |
| Karl Meakin | 3d879b8 | 2023-06-16 10:32:08 +0100 | [diff] [blame] | 347 | /** |
| 348 | * Configure `region` for a hypervisor retrieve request - i.e. all fields except |
| 349 | * `handle` are initialized to 0. |
| 350 | */ |
| 351 | void ffa_hypervisor_retrieve_request_init(struct ffa_memory_region *region, |
| 352 | ffa_memory_handle_t handle) |
| 353 | { |
| 354 | memset(region, 0, sizeof(struct ffa_memory_region)); |
| 355 | region->handle = handle; |
| 356 | } |
| 357 | |
| Max Shvetsov | c17c1d3 | 2020-06-11 15:03:01 +0100 | [diff] [blame] | 358 | /* |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 359 | * FFA Version ABI helper. |
| 360 | * Version fields: |
| 361 | * -Bits[30:16]: Major version. |
| 362 | * -Bits[15:0]: Minor version. |
| 363 | */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 364 | struct ffa_value ffa_version(uint32_t input_version) |
| J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 365 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 366 | struct ffa_value args = { |
| J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 367 | .fid = FFA_VERSION, |
| 368 | .arg1 = input_version |
| 369 | }; |
| 370 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 371 | return ffa_service_call(&args); |
| J-Alves | 8f08a05 | 2020-05-26 17:14:40 +0100 | [diff] [blame] | 372 | } |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 373 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 374 | struct ffa_value ffa_id_get(void) |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 375 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 376 | struct ffa_value args = { |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 377 | .fid = FFA_ID_GET |
| 378 | }; |
| 379 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 380 | return ffa_service_call(&args); |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 381 | } |
| 382 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 383 | struct ffa_value ffa_spm_id_get(void) |
| Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 384 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 385 | struct ffa_value args = { |
| Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 386 | .fid = FFA_SPM_ID_GET |
| 387 | }; |
| 388 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 389 | return ffa_service_call(&args); |
| Daniel Boulby | 198deda | 2021-03-03 11:35:25 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 392 | struct ffa_value ffa_msg_wait(void) |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 393 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 394 | struct ffa_value args = { |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 395 | .fid = FFA_MSG_WAIT |
| 396 | }; |
| 397 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 398 | return ffa_service_call(&args); |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 399 | } |
| 400 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 401 | struct ffa_value ffa_error(int32_t error_code) |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 402 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 403 | struct ffa_value args = { |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 404 | .fid = FFA_ERROR, |
| 405 | .arg1 = 0, |
| 406 | .arg2 = error_code |
| 407 | }; |
| 408 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 409 | return ffa_service_call(&args); |
| J-Alves | 5aecd98 | 2020-06-11 10:25:33 +0100 | [diff] [blame] | 410 | } |
| Max Shvetsov | c17c1d3 | 2020-06-11 15:03:01 +0100 | [diff] [blame] | 411 | |
| 412 | /* Query the higher EL if the requested FF-A feature is implemented. */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 413 | struct ffa_value ffa_features(uint32_t feature) |
| Max Shvetsov | c17c1d3 | 2020-06-11 15:03:01 +0100 | [diff] [blame] | 414 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 415 | struct ffa_value args = { |
| Max Shvetsov | c17c1d3 | 2020-06-11 15:03:01 +0100 | [diff] [blame] | 416 | .fid = FFA_FEATURES, |
| 417 | .arg1 = feature |
| 418 | }; |
| 419 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 420 | return ffa_service_call(&args); |
| Max Shvetsov | c17c1d3 | 2020-06-11 15:03:01 +0100 | [diff] [blame] | 421 | } |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 422 | |
| Karl Meakin | 31b8177 | 2023-03-14 15:38:17 +0000 | [diff] [blame] | 423 | /* Query the higher EL if the requested FF-A feature is implemented. */ |
| 424 | struct ffa_value ffa_features_with_input_property(uint32_t feature, uint32_t param) |
| 425 | { |
| 426 | struct ffa_value args = { |
| 427 | .fid = FFA_FEATURES, |
| 428 | .arg1 = feature, |
| 429 | .arg2 = param, |
| 430 | }; |
| 431 | |
| 432 | return ffa_service_call(&args); |
| 433 | } |
| 434 | |
| Raghu Krishnamurthy | ab5321a | 2023-04-23 16:14:28 -0700 | [diff] [blame] | 435 | /* Get information about VMs or SPs based on UUID, using registers. */ |
| 436 | struct ffa_value ffa_partition_info_get_regs(const struct ffa_uuid uuid, |
| 437 | const uint16_t start_index, |
| 438 | const uint16_t tag) |
| 439 | { |
| 440 | uint64_t arg1 = (uint64_t)uuid.uuid[1] << 32 | uuid.uuid[0]; |
| 441 | uint64_t arg2 = (uint64_t)uuid.uuid[3] << 32 | uuid.uuid[2]; |
| 442 | uint64_t arg3 = start_index | (uint64_t)tag << 16; |
| 443 | |
| 444 | struct ffa_value args = { |
| 445 | .fid = FFA_PARTITION_INFO_GET_REGS_SMC64, |
| 446 | .arg1 = arg1, |
| 447 | .arg2 = arg2, |
| 448 | .arg3 = arg3, |
| 449 | }; |
| 450 | |
| 451 | return ffa_service_call(&args); |
| 452 | } |
| 453 | |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 454 | /* Get information about VMs or SPs based on UUID */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 455 | struct ffa_value ffa_partition_info_get(const struct ffa_uuid uuid) |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 456 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 457 | struct ffa_value args = { |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 458 | .fid = FFA_PARTITION_INFO_GET, |
| Max Shvetsov | 0b7d25f | 2021-03-05 13:46:42 +0000 | [diff] [blame] | 459 | .arg1 = uuid.uuid[0], |
| 460 | .arg2 = uuid.uuid[1], |
| 461 | .arg3 = uuid.uuid[2], |
| 462 | .arg4 = uuid.uuid[3] |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 463 | }; |
| 464 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 465 | return ffa_service_call(&args); |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 466 | } |
| 467 | |
| J-Alves | 067daca | 2024-04-08 17:31:54 +0100 | [diff] [blame] | 468 | /* Querying the SPMC to release the rx buffers of the VM ID. */ |
| 469 | struct ffa_value ffa_rx_release_with_id(ffa_id_t vm_id) |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 470 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 471 | struct ffa_value args = { |
| J-Alves | 067daca | 2024-04-08 17:31:54 +0100 | [diff] [blame] | 472 | .fid = FFA_RX_RELEASE, |
| 473 | .arg1 = (uint64_t)vm_id, |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 474 | }; |
| 475 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 476 | return ffa_service_call(&args); |
| Max Shvetsov | c32f478 | 2020-06-23 09:41:15 +0100 | [diff] [blame] | 477 | } |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 478 | |
| J-Alves | 067daca | 2024-04-08 17:31:54 +0100 | [diff] [blame] | 479 | /* Query SPMC that the rx buffer of the partition can be released */ |
| 480 | struct ffa_value ffa_rx_release(void) |
| 481 | { |
| 482 | return ffa_rx_release_with_id(0); |
| 483 | } |
| 484 | |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 485 | /* Map the RXTX buffer */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 486 | struct ffa_value ffa_rxtx_map(uintptr_t send, uintptr_t recv, uint32_t pages) |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 487 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 488 | struct ffa_value args = { |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 489 | .fid = FFA_RXTX_MAP_SMC64, |
| 490 | .arg1 = send, |
| 491 | .arg2 = recv, |
| Daniel Boulby | d4da3dd | 2021-07-27 13:46:07 +0100 | [diff] [blame] | 492 | .arg3 = pages, |
| 493 | .arg4 = FFA_PARAM_MBZ, |
| 494 | .arg5 = FFA_PARAM_MBZ, |
| 495 | .arg6 = FFA_PARAM_MBZ, |
| 496 | .arg7 = FFA_PARAM_MBZ |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 497 | }; |
| 498 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 499 | return ffa_service_call(&args); |
| Ruari Phipps | bd0a7e4 | 2020-07-17 16:42:21 +0100 | [diff] [blame] | 500 | } |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 501 | |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 502 | /* Unmap the RXTX buffer allocated by the given FF-A component */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 503 | struct ffa_value ffa_rxtx_unmap(void) |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 504 | { |
| Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 505 | return ffa_rxtx_unmap_with_id(0); |
| 506 | } |
| 507 | |
| 508 | struct ffa_value ffa_rxtx_unmap_with_id(uint32_t id) |
| 509 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 510 | struct ffa_value args = { |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 511 | .fid = FFA_RXTX_UNMAP, |
| Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 512 | .arg1 = id << 16, |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 513 | .arg2 = FFA_PARAM_MBZ, |
| 514 | .arg3 = FFA_PARAM_MBZ, |
| 515 | .arg4 = FFA_PARAM_MBZ, |
| 516 | .arg5 = FFA_PARAM_MBZ, |
| 517 | .arg6 = FFA_PARAM_MBZ, |
| Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 518 | .arg7 = FFA_PARAM_MBZ, |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 519 | }; |
| 520 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 521 | return ffa_service_call(&args); |
| Daniel Boulby | e060290 | 2021-07-07 11:14:39 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame] | 524 | /** |
| 525 | * Copies data from the sender's send buffer to the recipient's receive buffer |
| 526 | * and notifies the receiver. |
| 527 | * |
| 528 | * `flags` may include a 'Delay Schedule Receiver interrupt'. |
| 529 | * |
| 530 | * Returns FFA_SUCCESS if the message is sent, or an error code otherwise: |
| 531 | * - INVALID_PARAMETERS: one or more of the parameters do not conform. |
| 532 | * - BUSY: receiver's mailbox was full. |
| 533 | * - DENIED: receiver is not in a state to handle the request or doesn't |
| 534 | * support indirect messages. |
| 535 | */ |
| J-Alves | ffdfafb | 2024-04-09 12:07:11 +0100 | [diff] [blame] | 536 | struct ffa_value ffa_msg_send2_with_id(uint32_t flags, ffa_id_t sender) |
| J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame] | 537 | { |
| 538 | struct ffa_value args = { |
| 539 | .fid = FFA_MSG_SEND2, |
| J-Alves | ffdfafb | 2024-04-09 12:07:11 +0100 | [diff] [blame] | 540 | .arg1 = sender << 16, |
| J-Alves | 779fba6 | 2024-04-05 14:14:40 +0100 | [diff] [blame] | 541 | .arg2 = flags, |
| 542 | .arg3 = FFA_PARAM_MBZ, |
| 543 | .arg4 = FFA_PARAM_MBZ, |
| 544 | .arg5 = FFA_PARAM_MBZ, |
| 545 | .arg6 = FFA_PARAM_MBZ, |
| 546 | .arg7 = FFA_PARAM_MBZ |
| 547 | }; |
| 548 | |
| 549 | return ffa_service_call(&args); |
| 550 | } |
| 551 | |
| J-Alves | ffdfafb | 2024-04-09 12:07:11 +0100 | [diff] [blame] | 552 | struct ffa_value ffa_msg_send2(uint32_t flags) |
| 553 | { |
| 554 | return ffa_msg_send2_with_id(flags, 0); |
| 555 | } |
| 556 | |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 557 | /* Donate memory to another partition */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 558 | struct ffa_value ffa_mem_donate(uint32_t descriptor_length, |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 559 | uint32_t fragment_length) |
| 560 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 561 | struct ffa_value args = { |
| J-Alves | 8984e72 | 2024-05-07 22:21:54 +0100 | [diff] [blame] | 562 | .fid = FFA_MEM_DONATE_SMC64, |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 563 | .arg1 = descriptor_length, |
| 564 | .arg2 = fragment_length, |
| 565 | .arg3 = FFA_PARAM_MBZ, |
| 566 | .arg4 = FFA_PARAM_MBZ |
| 567 | }; |
| 568 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 569 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /* Lend memory to another partition */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 573 | struct ffa_value ffa_mem_lend(uint32_t descriptor_length, |
| 574 | uint32_t fragment_length) |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 575 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 576 | struct ffa_value args = { |
| J-Alves | 8984e72 | 2024-05-07 22:21:54 +0100 | [diff] [blame] | 577 | .fid = FFA_MEM_LEND_SMC64, |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 578 | .arg1 = descriptor_length, |
| 579 | .arg2 = fragment_length, |
| 580 | .arg3 = FFA_PARAM_MBZ, |
| 581 | .arg4 = FFA_PARAM_MBZ |
| 582 | }; |
| 583 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 584 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /* Share memory with another partition */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 588 | struct ffa_value ffa_mem_share(uint32_t descriptor_length, |
| 589 | uint32_t fragment_length) |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 590 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 591 | struct ffa_value args = { |
| J-Alves | 8984e72 | 2024-05-07 22:21:54 +0100 | [diff] [blame] | 592 | .fid = FFA_MEM_SHARE_SMC64, |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 593 | .arg1 = descriptor_length, |
| 594 | .arg2 = fragment_length, |
| 595 | .arg3 = FFA_PARAM_MBZ, |
| 596 | .arg4 = FFA_PARAM_MBZ |
| 597 | }; |
| 598 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 599 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* Retrieve memory shared by another partition */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 603 | struct ffa_value ffa_mem_retrieve_req(uint32_t descriptor_length, |
| 604 | uint32_t fragment_length) |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 605 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 606 | struct ffa_value args = { |
| J-Alves | 8984e72 | 2024-05-07 22:21:54 +0100 | [diff] [blame] | 607 | .fid = FFA_MEM_RETRIEVE_REQ_SMC64, |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 608 | .arg1 = descriptor_length, |
| 609 | .arg2 = fragment_length, |
| 610 | .arg3 = FFA_PARAM_MBZ, |
| 611 | .arg4 = FFA_PARAM_MBZ, |
| 612 | .arg5 = FFA_PARAM_MBZ, |
| 613 | .arg6 = FFA_PARAM_MBZ, |
| 614 | .arg7 = FFA_PARAM_MBZ |
| 615 | }; |
| 616 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 617 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* Relinquish access to memory region */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 621 | struct ffa_value ffa_mem_relinquish(void) |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 622 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 623 | struct ffa_value args = { |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 624 | .fid = FFA_MEM_RELINQUISH, |
| 625 | }; |
| 626 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 627 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* Reclaim exclusive access to owned memory region */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 631 | struct ffa_value ffa_mem_reclaim(uint64_t handle, uint32_t flags) |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 632 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 633 | struct ffa_value args = { |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 634 | .fid = FFA_MEM_RECLAIM, |
| 635 | .arg1 = (uint32_t) handle, |
| 636 | .arg2 = (uint32_t) (handle >> 32), |
| 637 | .arg3 = flags |
| 638 | }; |
| 639 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 640 | return ffa_service_call(&args); |
| J-Alves | 3ea46d1 | 2020-09-09 11:13:05 +0100 | [diff] [blame] | 641 | } |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 642 | |
| Karl Meakin | 0d4f5ff | 2023-10-13 20:03:16 +0100 | [diff] [blame] | 643 | struct ffa_value ffa_mem_frag_rx(ffa_memory_handle_t handle, |
| 644 | uint32_t fragment_offset) |
| 645 | { |
| 646 | /* Note that sender MBZ at virtual instance. */ |
| 647 | struct ffa_value args = { |
| 648 | .fid = FFA_MEM_FRAG_RX, |
| 649 | .arg1 = (uint32_t)handle, |
| 650 | .arg2 = (uint32_t)(handle >> 32), |
| 651 | .arg3 = fragment_offset, |
| 652 | }; |
| 653 | |
| 654 | return ffa_service_call(&args); |
| 655 | } |
| 656 | |
| 657 | struct ffa_value ffa_mem_frag_tx(ffa_memory_handle_t handle, |
| 658 | uint32_t fragment_length) |
| 659 | { |
| 660 | struct ffa_value args = { |
| 661 | .fid = FFA_MEM_FRAG_TX, |
| 662 | .arg1 = (uint32_t)handle, |
| 663 | .arg2 = (uint32_t)(handle >> 32), |
| 664 | .arg3 = fragment_length, |
| 665 | }; |
| 666 | |
| 667 | /* Note that sender MBZ at virtual instance. */ |
| 668 | return ffa_service_call(&args); |
| 669 | } |
| 670 | |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 671 | /** Create Notifications Bitmap for the given VM */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 672 | struct ffa_value ffa_notification_bitmap_create(ffa_id_t vm_id, |
| 673 | ffa_vcpu_count_t vcpu_count) |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 674 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 675 | struct ffa_value args = { |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 676 | .fid = FFA_NOTIFICATION_BITMAP_CREATE, |
| 677 | .arg1 = vm_id, |
| 678 | .arg2 = vcpu_count, |
| 679 | .arg3 = FFA_PARAM_MBZ, |
| 680 | .arg4 = FFA_PARAM_MBZ, |
| 681 | .arg5 = FFA_PARAM_MBZ, |
| 682 | .arg6 = FFA_PARAM_MBZ, |
| 683 | .arg7 = FFA_PARAM_MBZ, |
| 684 | }; |
| 685 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 686 | return ffa_service_call(&args); |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** Destroy Notifications Bitmap for the given VM */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 690 | struct ffa_value ffa_notification_bitmap_destroy(ffa_id_t vm_id) |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 691 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 692 | struct ffa_value args = { |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 693 | .fid = FFA_NOTIFICATION_BITMAP_DESTROY, |
| 694 | .arg1 = vm_id, |
| 695 | .arg2 = FFA_PARAM_MBZ, |
| 696 | .arg3 = FFA_PARAM_MBZ, |
| 697 | .arg4 = FFA_PARAM_MBZ, |
| 698 | .arg5 = FFA_PARAM_MBZ, |
| 699 | .arg6 = FFA_PARAM_MBZ, |
| 700 | .arg7 = FFA_PARAM_MBZ, |
| 701 | }; |
| 702 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 703 | return ffa_service_call(&args); |
| J-Alves | bcb1f97 | 2021-03-11 14:03:54 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 706 | /** Bind VM to all the notifications in the bitmap */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 707 | struct ffa_value ffa_notification_bind(ffa_id_t sender, ffa_id_t receiver, |
| 708 | uint32_t flags, |
| 709 | ffa_notification_bitmap_t bitmap) |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 710 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 711 | struct ffa_value args = { |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 712 | .fid = FFA_NOTIFICATION_BIND, |
| 713 | .arg1 = (sender << 16) | (receiver), |
| 714 | .arg2 = flags, |
| 715 | .arg3 = (uint32_t)(bitmap & 0xFFFFFFFFU), |
| 716 | .arg4 = (uint32_t)(bitmap >> 32), |
| 717 | .arg5 = FFA_PARAM_MBZ, |
| 718 | .arg6 = FFA_PARAM_MBZ, |
| 719 | .arg7 = FFA_PARAM_MBZ, |
| 720 | }; |
| 721 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 722 | return ffa_service_call(&args); |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** Unbind previously bound VM from notifications in bitmap */ |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 726 | struct ffa_value ffa_notification_unbind(ffa_id_t sender, |
| 727 | ffa_id_t receiver, |
| 728 | ffa_notification_bitmap_t bitmap) |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 729 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 730 | struct ffa_value args = { |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 731 | .fid = FFA_NOTIFICATION_UNBIND, |
| 732 | .arg1 = (sender << 16) | (receiver), |
| 733 | .arg2 = FFA_PARAM_MBZ, |
| 734 | .arg3 = (uint32_t)(bitmap), |
| 735 | .arg4 = (uint32_t)(bitmap >> 32), |
| 736 | .arg5 = FFA_PARAM_MBZ, |
| 737 | .arg6 = FFA_PARAM_MBZ, |
| 738 | .arg7 = FFA_PARAM_MBZ, |
| 739 | }; |
| 740 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 741 | return ffa_service_call(&args); |
| J-Alves | 18c2805 | 2021-03-09 09:58:53 +0000 | [diff] [blame] | 742 | } |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 743 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 744 | struct ffa_value ffa_notification_set(ffa_id_t sender, ffa_id_t receiver, |
| 745 | uint32_t flags, |
| 746 | ffa_notification_bitmap_t bitmap) |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 747 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 748 | struct ffa_value args = { |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 749 | .fid = FFA_NOTIFICATION_SET, |
| 750 | .arg1 = (sender << 16) | (receiver), |
| 751 | .arg2 = flags, |
| 752 | .arg3 = (uint32_t)(bitmap & 0xFFFFFFFFU), |
| 753 | .arg4 = (uint32_t)(bitmap >> 32), |
| 754 | .arg5 = FFA_PARAM_MBZ, |
| 755 | .arg6 = FFA_PARAM_MBZ, |
| 756 | .arg7 = FFA_PARAM_MBZ |
| 757 | }; |
| 758 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 759 | return ffa_service_call(&args); |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 762 | struct ffa_value ffa_notification_get(ffa_id_t receiver, uint32_t vcpu_id, |
| 763 | uint32_t flags) |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 764 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 765 | struct ffa_value args = { |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 766 | .fid = FFA_NOTIFICATION_GET, |
| J-Alves | 3727719 | 2021-11-30 14:59:03 +0000 | [diff] [blame] | 767 | .arg1 = (vcpu_id << 16) | (receiver), |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 768 | .arg2 = flags, |
| 769 | .arg3 = FFA_PARAM_MBZ, |
| 770 | .arg4 = FFA_PARAM_MBZ, |
| 771 | .arg5 = FFA_PARAM_MBZ, |
| 772 | .arg6 = FFA_PARAM_MBZ, |
| 773 | .arg7 = FFA_PARAM_MBZ |
| 774 | }; |
| 775 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 776 | return ffa_service_call(&args); |
| J-Alves | f156ae9 | 2021-10-08 12:10:05 +0100 | [diff] [blame] | 777 | } |
| J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 778 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 779 | struct ffa_value ffa_notification_info_get(void) |
| J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 780 | { |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 781 | struct ffa_value args = { |
| J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 782 | .fid = FFA_NOTIFICATION_INFO_GET_SMC64, |
| 783 | .arg1 = FFA_PARAM_MBZ, |
| 784 | .arg2 = FFA_PARAM_MBZ, |
| 785 | .arg3 = FFA_PARAM_MBZ, |
| 786 | .arg4 = FFA_PARAM_MBZ, |
| 787 | .arg5 = FFA_PARAM_MBZ, |
| 788 | .arg6 = FFA_PARAM_MBZ, |
| 789 | .arg7 = FFA_PARAM_MBZ |
| 790 | }; |
| 791 | |
| Daniel Boulby | ce386b1 | 2022-03-29 18:36:36 +0100 | [diff] [blame] | 792 | return ffa_service_call(&args); |
| J-Alves | 5bce250 | 2021-06-14 14:27:45 +0100 | [diff] [blame] | 793 | } |
| Maksims Svecovs | 0b45223 | 2022-05-24 11:30:34 +0100 | [diff] [blame] | 794 | |
| 795 | static size_t char_to_arg_helper(const char *message, size_t size, |
| 796 | u_register_t *arg) |
| 797 | { |
| 798 | size_t to_write = size > sizeof(uint64_t) ? sizeof(uint64_t) : size; |
| 799 | |
| 800 | for (int i = 0; i < to_write; i++) { |
| 801 | ((char *)arg)[i] = message[i]; |
| 802 | } |
| 803 | return to_write; |
| 804 | } |
| 805 | |
| 806 | struct ffa_value ffa_console_log(const char *message, size_t char_count) |
| 807 | { |
| 808 | struct ffa_value args = { |
| 809 | .fid = FFA_CONSOLE_LOG_SMC64, |
| 810 | .arg1 = char_count, |
| 811 | }; |
| 812 | size_t written = 0; |
| 813 | |
| 814 | assert(char_count <= sizeof(uint64_t) * 6); |
| 815 | |
| 816 | written += char_to_arg_helper(&message[written], char_count - written, |
| 817 | &args.arg2); |
| 818 | written += char_to_arg_helper(&message[written], char_count - written, |
| 819 | &args.arg3); |
| 820 | written += char_to_arg_helper(&message[written], char_count - written, |
| 821 | &args.arg4); |
| 822 | written += char_to_arg_helper(&message[written], char_count - written, |
| 823 | &args.arg5); |
| 824 | written += char_to_arg_helper(&message[written], char_count - written, |
| 825 | &args.arg6); |
| 826 | char_to_arg_helper(&message[written], char_count - written, |
| 827 | &args.arg7); |
| 828 | |
| 829 | return ffa_service_call(&args); |
| 830 | } |
| Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 831 | |
| 832 | /** |
| 833 | * Initializes receiver permissions in a memory transaction descriptor. |
| 834 | */ |
| Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 835 | struct ffa_memory_access ffa_memory_access_init( |
| Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 836 | ffa_id_t receiver_id, enum ffa_data_access data_access, |
| 837 | enum ffa_instruction_access instruction_access, |
| Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 838 | ffa_memory_receiver_flags_t flags, |
| 839 | struct ffa_memory_access_impdef *impdef) |
| Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 840 | { |
| 841 | struct ffa_memory_access access; |
| 842 | access.reserved_0 = 0; |
| 843 | access.composite_memory_region_offset = 0; |
| 844 | access.receiver_permissions.flags = flags; |
| 845 | access.receiver_permissions.receiver = receiver_id; |
| 846 | access.receiver_permissions.permissions.data_access = data_access; |
| 847 | access.receiver_permissions.permissions.instruction_access = |
| 848 | instruction_access; |
| Daniel Boulby | a24f23a | 2023-11-15 18:23:40 +0000 | [diff] [blame] | 849 | access.impdef = impdef != NULL ? *impdef : |
| 850 | (struct ffa_memory_access_impdef){{0, 0}}; |
| Karl Meakin | 367ff54 | 2023-11-01 15:05:37 +0000 | [diff] [blame] | 851 | |
| 852 | return access; |
| 853 | } |
| Karl Meakin | bff9b3c | 2024-01-18 16:08:35 +0000 | [diff] [blame] | 854 | |
| 855 | /** |
| 856 | * Initialises the given `ffa_composite_memory_region` to be used for an |
| 857 | * `FFA_RXTX_MAP` forwarding in the case when Hypervisor needs the SPMC to map a |
| 858 | * VM's RXTX pair. |
| 859 | */ |
| 860 | static void |
| 861 | ffa_composite_memory_region_init(struct ffa_composite_memory_region *composite, |
| 862 | void *address, uint32_t page_count) |
| 863 | { |
| 864 | composite->page_count = page_count; |
| 865 | composite->constituent_count = 1; |
| 866 | composite->reserved_0 = 0; |
| 867 | |
| 868 | composite->constituents[0].page_count = page_count; |
| 869 | composite->constituents[0].address = (void *)address; |
| 870 | composite->constituents[0].reserved = 0; |
| 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Initialises the given `ffa_endpoint_rx_tx_descriptor` to be used for an |
| 875 | * `FFA_RXTX_MAP` forwarding in the case when Hypervisor needs the SPMC to map a |
| 876 | * VM's RXTX pair. |
| 877 | * |
| 878 | * Each buffer is described by an `ffa_composite_memory_region` containing |
| 879 | * one `ffa_memory_region_constituent`. |
| 880 | */ |
| 881 | void ffa_endpoint_rxtx_descriptor_init( |
| 882 | struct ffa_endpoint_rxtx_descriptor *desc, ffa_id_t endpoint_id, |
| 883 | void *rx_address, void *tx_address) |
| 884 | { |
| 885 | desc->endpoint_id = endpoint_id; |
| 886 | desc->reserved = 0; |
| 887 | desc->pad = 0; |
| 888 | |
| 889 | /* |
| 890 | * RX's composite descriptor is allocated after the enpoint descriptor. |
| 891 | * `sizeof(struct ffa_endpoint_rx_tx_descriptor)` is guaranteed to be |
| 892 | * 16-byte aligned. |
| 893 | */ |
| 894 | desc->rx_offset = sizeof(struct ffa_endpoint_rxtx_descriptor); |
| 895 | |
| 896 | ffa_composite_memory_region_init( |
| 897 | (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 898 | desc->rx_offset), |
| 899 | rx_address, 1); |
| 900 | |
| 901 | /* |
| 902 | * TX's composite descriptor is allocated after the RX descriptor. |
| 903 | * `sizeof(struct ffa_composite_memory_region)` and |
| 904 | * `sizeof(struct ffa_memory_region_constituent)` are guaranteed to be |
| 905 | * 16-byte aligned in ffa_memory.c. |
| 906 | */ |
| 907 | desc->tx_offset = desc->rx_offset + |
| 908 | sizeof(struct ffa_composite_memory_region) + |
| 909 | sizeof(struct ffa_memory_region_constituent); |
| 910 | |
| 911 | ffa_composite_memory_region_init( |
| 912 | (struct ffa_composite_memory_region *)((uintptr_t)desc + |
| 913 | desc->tx_offset), |
| 914 | tx_address, 1); |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * Mimics a forwarded FFA_RXTX_MAP call from a hypervisor. |
| 919 | */ |
| 920 | struct ffa_value ffa_rxtx_map_forward(struct ffa_endpoint_rxtx_descriptor *desc, |
| 921 | ffa_id_t endpoint_id, |
| 922 | void *rx_address, void *tx_address) |
| 923 | { |
| 924 | ffa_endpoint_rxtx_descriptor_init(desc, endpoint_id, rx_address, tx_address); |
| 925 | return ffa_rxtx_map(0, 0, 0); |
| 926 | } |