1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 /*
20  * Subset of Arm PSA Firmware Framework for Arm v8-A 1.0 EAC
21  * (https://developer.arm.com/docs/den0077/a) needed for shared memory.
22  */
23 
24 #include <interface/smc/smc_def.h>
25 #include <stdint.h>
26 
27 #ifndef STATIC_ASSERT
28 #define STATIC_ASSERT(e) _Static_assert(e, #e)
29 #endif
30 
31 #define FFA_CURRENT_VERSION_MAJOR (1U)
32 #define FFA_CURRENT_VERSION_MINOR (0U)
33 
34 #define FFA_VERSION_TO_MAJOR(version) ((version) >> 16)
35 #define FFA_VERSION_TO_MINOR(version) ((version) & (0xffff))
36 #define FFA_VERSION(major, minor) (((major) << 16) | (minor))
37 #define FFA_CURRENT_VERSION \
38     FFA_VERSION(FFA_CURRENT_VERSION_MAJOR, FFA_CURRENT_VERSION_MINOR)
39 
40 #define SMC_ENTITY_SHARED_MEMORY 4
41 
42 #define SMC_FASTCALL_NR_SHARED_MEMORY(nr) \
43     SMC_FASTCALL_NR(SMC_ENTITY_SHARED_MEMORY, nr)
44 #define SMC_FASTCALL64_NR_SHARED_MEMORY(nr) \
45     SMC_FASTCALL64_NR(SMC_ENTITY_SHARED_MEMORY, nr)
46 
47 #define FFA_PAGE_SIZE (4096)
48 
49 /**
50  * typedef ffa_endpoint_id16_t - Endpoint ID
51  *
52  * Current implementation only supports VMIDs. FFA spec also support stream
53  * endpoint ids.
54  */
55 typedef uint16_t ffa_endpoint_id16_t;
56 
57 /**
58  * struct ffa_cons_mrd - Constituent memory region descriptor
59  * @address:
60  *         Start address of contiguous memory region. Must be 4K page aligned.
61  * @page_count:
62  *         Number of 4K pages in region.
63  * @reserved_12_15:
64  *         Reserve bytes 12-15 to pad struct size to 16 bytes.
65  */
66 struct ffa_cons_mrd {
67     uint64_t address;
68     uint32_t page_count;
69     uint32_t reserved_12_15;
70 };
71 STATIC_ASSERT(sizeof(struct ffa_cons_mrd) == 16);
72 
73 /**
74  * struct ffa_comp_mrd - Composite memory region descriptor
75  * @total_page_count:
76  *         Number of 4k pages in memory region. Must match sum of
77  *         @address_range_array[].page_count.
78  * @address_range_count:
79  *         Number of entries in @address_range_array.
80  * @reserved_8_15:
81  *         Reserve bytes 8-15 to pad struct size to 16 byte alignment and
82  *         make @address_range_array 16 byte aligned.
83  * @address_range_array:
84  *         Array of &struct ffa_cons_mrd entries.
85  */
86 struct ffa_comp_mrd {
87     uint32_t total_page_count;
88     uint32_t address_range_count;
89     uint64_t reserved_8_15;
90     struct ffa_cons_mrd address_range_array[];
91 };
92 STATIC_ASSERT(sizeof(struct ffa_comp_mrd) == 16);
93 
94 /**
95  * typedef ffa_mem_attr8_t - Memory region attributes
96  *
97  * * @FFA_MEM_ATTR_DEVICE_NGNRNE:
98  *     Device-nGnRnE.
99  * * @FFA_MEM_ATTR_DEVICE_NGNRE:
100  *     Device-nGnRE.
101  * * @FFA_MEM_ATTR_DEVICE_NGRE:
102  *     Device-nGRE.
103  * * @FFA_MEM_ATTR_DEVICE_GRE:
104  *     Device-GRE.
105  * * @FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED
106  *     Normal memory. Non-cacheable.
107  * * @FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB
108  *     Normal memory. Write-back cached.
109  * * @FFA_MEM_ATTR_NON_SHAREABLE
110  *     Non-shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
111  * * @FFA_MEM_ATTR_OUTER_SHAREABLE
112  *     Outer Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
113  * * @FFA_MEM_ATTR_INNER_SHAREABLE
114  *     Inner Shareable. Combine with FFA_MEM_ATTR_NORMAL_MEMORY_*.
115  * * @FFA_MEM_ATTR_NONSECURE
116  *     Nonsecure.
117  *     Uses reserved bit 6, the same bit which a NONSECURE flag is in a
118  *     spec draft.
119  */
120 typedef uint8_t ffa_mem_attr8_t;
121 #define FFA_MEM_ATTR_DEVICE_NGNRNE ((1U << 4) | (0x0U << 2))
122 #define FFA_MEM_ATTR_DEVICE_NGNRE ((1U << 4) | (0x1U << 2))
123 #define FFA_MEM_ATTR_DEVICE_NGRE ((1U << 4) | (0x2U << 2))
124 #define FFA_MEM_ATTR_DEVICE_GRE ((1U << 4) | (0x3U << 2))
125 #define FFA_MEM_ATTR_NORMAL_MEMORY_UNCACHED ((2U << 4) | (0x1U << 2))
126 #define FFA_MEM_ATTR_NORMAL_MEMORY_CACHED_WB ((2U << 4) | (0x3U << 2))
127 #define FFA_MEM_ATTR_NON_SHAREABLE (0x0U << 0)
128 #define FFA_MEM_ATTR_OUTER_SHAREABLE (0x2U << 0)
129 #define FFA_MEM_ATTR_INNER_SHAREABLE (0x3U << 0)
130 #define FFA_MEM_ATTR_NONSECURE (1U << 6)
131 
132 /**
133  * typedef ffa_mem_perm8_t - Memory access permissions
134  *
135  * * @FFA_MEM_ATTR_RO
136  *     Request or specify read-only mapping.
137  * * @FFA_MEM_ATTR_RW
138  *     Request or allow read-write mapping.
139  * * @FFA_MEM_PERM_NX
140  *     Deny executable mapping.
141  * * @FFA_MEM_PERM_X
142  *     Request executable mapping.
143  */
144 typedef uint8_t ffa_mem_perm8_t;
145 #define FFA_MEM_PERM_RO (1U << 0)
146 #define FFA_MEM_PERM_RW (1U << 1)
147 #define FFA_MEM_PERM_NX (1U << 2)
148 #define FFA_MEM_PERM_X (1U << 3)
149 
150 /**
151  * typedef ffa_mem_flag8_t - Endpoint memory flags
152  *
153  * * @FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER
154  *     Non-retrieval Borrower. Memory region must not be or was not retrieved on
155  *     behalf of this endpoint.
156  */
157 typedef uint8_t ffa_mem_flag8_t;
158 #define FFA_MEM_FLAG_NON_RETRIEVAL_BORROWER (1U << 0)
159 
160 /**
161  * typedef ffa_mtd_flag32_t - Memory transaction descriptor flags
162  *
163  * * @FFA_MTD_FLAG_ZERO_MEMORY
164  *     Zero memory after unmapping from sender (must be 0 for share).
165  * * @FFA_MTD_FLAG_TIME_SLICING
166  *     Not supported by this implementation.
167  * * @FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH
168  *     Zero memory after unmapping from borrowers (must be 0 for share).
169  * * @FFA_MTD_FLAG_TYPE_MASK
170  *     Bit-mask to extract memory management transaction type from flags.
171  * * @FFA_MTD_FLAG_TYPE_SHARE_MEMORY
172  *     Share memory transaction flag.
173  *     Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from
174  *     @SMC_FC_FFA_MEM_SHARE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that
175  *     it must have.
176  * * @FFA_MTD_FLAG_TYPE_LEND_MEMORY
177  *     Lend memory transaction flag.
178  *     Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from
179  *     @SMC_FC_FFA_MEM_LEND and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify that
180  *     it must have.
181  * * @FFA_MTD_FLAG_TYPE_DONATE_MEMORY
182  *     Donate memory transaction flag.
183  *     Used by @SMC_FC_FFA_MEM_RETRIEVE_RESP to indicate that memory came from
184  *     @SMC_FC_FFA_MEM_DONATE and by @SMC_FC_FFA_MEM_RETRIEVE_REQ to specify
185  *     that it must have.
186  * * @FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK
187  *     Not supported by this implementation.
188  */
189 typedef uint32_t ffa_mtd_flag32_t;
190 #define FFA_MTD_FLAG_ZERO_MEMORY (1U << 0)
191 #define FFA_MTD_FLAG_TIME_SLICING (1U << 1)
192 #define FFA_MTD_FLAG_ZERO_MEMORY_AFTER_RELINQUISH (1U << 2)
193 #define FFA_MTD_FLAG_TYPE_MASK (3U << 3)
194 #define FFA_MTD_FLAG_TYPE_SHARE_MEMORY (1U << 3)
195 #define FFA_MTD_FLAG_TYPE_LEND_MEMORY (2U << 3)
196 #define FFA_MTD_FLAG_TYPE_DONATE_MEMORY (3U << 3)
197 #define FFA_MTD_FLAG_ADDRESS_RANGE_ALIGNMENT_HINT_MASK (0x1FU << 5)
198 
199 /**
200  * typedef ffa_mem_relinquish_flag32_t - Memory relinquish descriptor flags
201  *
202  * * @FFA_MEM_RELINQUISH_FLAG_ZERO_MEMORY
203  *     Zero memory after unmapping from sender (must be 0 for share).
204  * * @FFA_MEM_RELINQUISH_FLAG_TIME_SLICING
205  *     Not supported by this implementation.
206  */
207 typedef uint32_t ffa_mem_relinquish_flag32_t;
208 #define FFA_MEM_RELINQUISH_FLAG_ZERO_MEMORY (1U << 0)
209 #define FFA_MEM_RELINQUISH_FLAG_TIME_SLICING (1U << 1)
210 
211 /**
212  * struct ffa_mapd - Memory access permissions descriptor
213  * @endpoint_id:
214  *         Endpoint id that @memory_access_permissions and @flags apply to.
215  *         (&typedef ffa_endpoint_id16_t).
216  * @memory_access_permissions:
217  *         FFA_MEM_PERM_* values or'ed together (&typedef ffa_mem_perm8_t).
218  * @flags:
219  *         FFA_MEM_FLAG_* values or'ed together (&typedef ffa_mem_flag8_t).
220  */
221 struct ffa_mapd {
222     ffa_endpoint_id16_t endpoint_id;
223     ffa_mem_perm8_t memory_access_permissions;
224     ffa_mem_flag8_t flags;
225 };
226 STATIC_ASSERT(sizeof(struct ffa_mapd) == 4);
227 
228 /**
229  * struct ffa_emad - Endpoint memory access descriptor.
230  * @mapd:  &struct ffa_mapd.
231  * @comp_mrd_offset:
232  *         Offset of &struct ffa_comp_mrd form start of &struct ffa_mtd.
233  * @reserved_8_15:
234  *         Reserved bytes 8-15. Must be 0.
235  */
236 struct ffa_emad {
237     struct ffa_mapd mapd;
238     uint32_t comp_mrd_offset;
239     uint64_t reserved_8_15;
240 };
241 STATIC_ASSERT(sizeof(struct ffa_emad) == 16);
242 
243 /**
244  * struct ffa_mtd - Memory transaction descriptor.
245  * @sender_id:
246  *         Sender endpoint id.
247  * @memory_region_attributes:
248  *         FFA_MEM_ATTR_* values or'ed together (&typedef ffa_mem_attr8_t).
249  * @reserved_3:
250  *         Reserved bytes 3. Must be 0.
251  * @flags:
252  *         FFA_MTD_FLAG_* values or'ed together (&typedef ffa_mtd_flag32_t).
253  * @handle:
254  *         Id of shared memory object. Most be 0 for MEM_SHARE.
255  * @tag:   Client allocated tag. Must match original value.
256  * @reserved_24_27:
257  *         Reserved bytes 24-27. Must be 0.
258  * @emad_count:
259  *         Number of entries in @emad. Must be 1 in current implementation.
260  *         FFA spec allows more entries.
261  * @emad:
262  *         Endpoint memory access descriptor array (see @struct ffa_emad).
263  */
264 struct ffa_mtd {
265     ffa_endpoint_id16_t sender_id;
266     ffa_mem_attr8_t memory_region_attributes;
267     uint8_t reserved_3;
268     ffa_mtd_flag32_t flags;
269     uint64_t handle;
270     uint64_t tag;
271     uint32_t reserved_24_27;
272     uint32_t emad_count;
273     struct ffa_emad emad[];
274 };
275 STATIC_ASSERT(sizeof(struct ffa_mtd) == 32);
276 
277 /**
278  * struct ffa_mem_relinquish_descriptor - Relinquish request descriptor.
279  * @handle:
280  *         Id of shared memory object to relinquish.
281  * @flags:
282  *         FFA_MEM_RELINQUISH_FLAG_* values or'ed together
283  *         (&typedef ffa_mem_relinquish_flag32_t).
284  * @endpoint_count:
285  *         Number of entries in @endpoint_array.
286  * @endpoint_array:
287  *         Array of endpoint ids.
288  */
289 struct ffa_mem_relinquish_descriptor {
290     uint64_t handle;
291     uint32_t flags;
292     uint32_t endpoint_count;
293     ffa_endpoint_id16_t endpoint_array[];
294 };
295 STATIC_ASSERT(sizeof(struct ffa_mem_relinquish_descriptor) == 16);
296 
297 /**
298  * typedef ffa_features2_t - FFA_FEATURES values returned in w2
299  *
300  * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_MASK
301  *     For RXTX_MAP: min buffer size and alignment boundary mask.
302  * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_4K
303  *     For RXTX_MAP: min buffer size and alignment boundary is 4K.
304  * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_64K
305  *     For RXTX_MAP: min buffer size and alignment boundary is 64K.
306  * * @FFA_FEATURES2_RXTX_MAP_BUF_SIZE_16K
307  *     For RXTX_MAP: min buffer size and alignment boundary is 16K.
308  * * @FFA_FEATURES2_MEM_DYNAMIC_BUFFER
309  *     Supports custom buffers for memory transactions.
310  * * @FFA_FEATURES2_MEM_RETRIEVE_REQ_NS_BIT
311  *     Supports setting the NS bit on retrieved descriptors.
312  *
313  * For all other bits and commands: must be 0.
314  */
315 typedef uint32_t ffa_features2_t;
316 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_MASK 0x3U
317 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_4K 0x0U
318 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_64K 0x1U
319 #define FFA_FEATURES2_RXTX_MAP_BUF_SIZE_16K 0x2U
320 #define FFA_FEATURES2_MEM_DYNAMIC_BUFFER 0x1U
321 #define FFA_FEATURES2_MEM_RETRIEVE_REQ_NS_BIT 0x2U
322 
323 /**
324  * typedef ffa_features3_t - FFA_FEATURES values returned in w3
325  *
326  * * @FFA_FEATURES3_MEM_RETRIEVE_REQ_REFCOUNT_MASK
327  *     For FFA_MEM_RETRIEVE_REQ, bit[7-0]: Number of times receiver can
328  *     retrieve each memory region before relinquishing it specified as
329  *     ((1U << (value + 1)) - 1 (or value = bits in reference count - 1).
330  *
331  * For all other bits and commands: must be 0.
332  */
333 typedef uint32_t ffa_features3_t;
334 #define FFA_FEATURES3_MEM_RETRIEVE_REQ_REFCOUNT_MASK 0xffU
335 
336 /**
337  * enum ffa_error - FF-A error code
338  * @FFA_ERROR_NOT_SUPPORTED:
339  *         Operation is not supported by the current implementation.
340  * @FFA_ERROR_INVALID_PARAMETERS:
341  *         Invalid parameters. Conditions function specific.
342  * @FFA_ERROR_NO_MEMORY:
343  *         Not enough memory.
344  * @FFA_ERROR_BUSY:
345  *         Operation temporarily not possible. Conditions function specific.
346  * @FFA_ERROR_INTERRUPTED:
347  *         This error code is not specified in the FF-A specification.
348  * @FFA_ERROR_DENIED:
349  *         Operation not allowed. Conditions function specific.
350  * @FFA_ERROR_RETRY:
351  *         Operation temporarily not possible. Conditions function specific.
352  * @FFA_ERROR_ABORTED:
353  *         Operation aborted. Reason for abort is implementation specific.
354  * @FFA_ERROR_NO_DATA:
355  *         Requested information not available.
356  *
357  */
358 enum ffa_error {
359     FFA_ERROR_NOT_SUPPORTED = -1,
360     FFA_ERROR_INVALID_PARAMETERS = -2,
361     FFA_ERROR_NO_MEMORY = -3,
362     FFA_ERROR_BUSY = -4,
363     FFA_ERROR_INTERRUPTED = -5,
364     FFA_ERROR_DENIED = -6,
365     FFA_ERROR_RETRY = -7,
366     FFA_ERROR_ABORTED = -8,
367     FFA_ERROR_NO_DATA = -9,
368 };
369 
370 /**
371  * SMC_FC32_FFA_MIN - First 32 bit SMC opcode reserved for FFA
372  */
373 #define SMC_FC32_FFA_MIN SMC_FASTCALL_NR_SHARED_MEMORY(0x60)
374 
375 /**
376  * SMC_FC32_FFA_MAX - Last 32 bit SMC opcode reserved for FFA
377  */
378 #define SMC_FC32_FFA_MAX SMC_FASTCALL_NR_SHARED_MEMORY(0x7F)
379 
380 /**
381  * SMC_FC64_FFA_MIN - First 64 bit SMC opcode reserved for FFA
382  */
383 #define SMC_FC64_FFA_MIN SMC_FASTCALL64_NR_SHARED_MEMORY(0x60)
384 
385 /**
386  * SMC_FC64_FFA_MAX - Last 64 bit SMC opcode reserved for FFA
387  */
388 #define SMC_FC64_FFA_MAX SMC_FASTCALL64_NR_SHARED_MEMORY(0x7F)
389 
390 /**
391  * SMC_FC_FFA_ERROR - SMC error return opcode
392  *
393  * Register arguments:
394  *
395  * * w1:     VMID in [31:16], vCPU in [15:0]
396  * * w2:     Error code (&enum ffa_error)
397  */
398 #define SMC_FC_FFA_ERROR SMC_FASTCALL_NR_SHARED_MEMORY(0x60)
399 
400 /**
401  * SMC_FC_FFA_SUCCESS - 32 bit SMC success return opcode
402  *
403  * Register arguments:
404  *
405  * * w1:     VMID in [31:16], vCPU in [15:0]
406  * * w2-w7:  Function specific
407  */
408 #define SMC_FC_FFA_SUCCESS SMC_FASTCALL_NR_SHARED_MEMORY(0x61)
409 
410 /**
411  * SMC_FC64_FFA_SUCCESS - 64 bit SMC success return opcode
412  *
413  * Register arguments:
414  *
415  * * w1:             VMID in [31:16], vCPU in [15:0]
416  * * w2/x2-w7/x7:    Function specific
417  */
418 #define SMC_FC64_FFA_SUCCESS SMC_FASTCALL64_NR_SHARED_MEMORY(0x61)
419 
420 /**
421  * SMC_FC_FFA_INTERRUPT - SMC interrupt return opcode
422  *
423  * Register arguments:
424  *
425  * * w1:     VMID in [31:16], vCPU in [15:0]
426  * * w2:     Interrupt ID
427  */
428 #define SMC_FC_FFA_INTERRUPT SMC_FASTCALL_NR_SHARED_MEMORY(0x62)
429 
430 /**
431  * SMC_FC_FFA_VERSION - SMC opcode to return supported FF-A version
432  *
433  * Register arguments:
434  *
435  * * w1:     Major version bit[30:16] and minor version in bit[15:0] supported
436  *           by caller. Bit[31] must be 0.
437  *
438  * Return:
439  * * w0:     &SMC_FC_FFA_SUCCESS
440  * * w2:     Major version bit[30:16], minor version in bit[15:0], bit[31] must
441  *           be 0.
442  *
443  * or
444  *
445  * * w0:     &SMC_FC_FFA_ERROR
446  * * w2:     %FFA_ERROR_NOT_SUPPORTED if major version passed in is less than
447  *           the minimum major version supported.
448  */
449 #define SMC_FC_FFA_VERSION SMC_FASTCALL_NR_SHARED_MEMORY(0x63)
450 
451 /**
452  * SMC_FC_FFA_FEATURES - SMC opcode to check optional feature support
453  *
454  * Register arguments:
455  *
456  * * w1:     FF-A function ID
457  *
458  * Return:
459  * * w0:     &SMC_FC_FFA_SUCCESS
460  * * w2:     &typedef ffa_features2_t
461  * * w3:     &typedef ffa_features3_t
462  *
463  * or
464  *
465  * * w0:     &SMC_FC_FFA_ERROR
466  * * w2:     %FFA_ERROR_NOT_SUPPORTED if function is not implemented, or
467  *           %FFA_ERROR_INVALID_PARAMETERS if function id is not valid.
468  */
469 #define SMC_FC_FFA_FEATURES SMC_FASTCALL_NR_SHARED_MEMORY(0x64)
470 
471 /**
472  * SMC_FC_FFA_RX_RELEASE - SMC opcode to Relinquish ownership of a RX buffer
473  *
474  * Return:
475  * * w0:     &SMC_FC_FFA_SUCCESS
476  *
477  * or
478  *
479  * * w0:     &SMC_FC_FFA_ERROR
480  * * w2:     %FFA_ERROR_DENIED Caller did not have ownership of the RX buffer.
481  *           %FFA_ERROR_NOT_SUPPORTED if operation not supported
482  */
483 #define SMC_FC_FFA_RX_RELEASE SMC_FASTCALL_NR_SHARED_MEMORY(0x65)
484 
485 /**
486  * SMC_FC_FFA_RXTX_MAP - 32 bit SMC opcode to map message buffers
487  *
488  * Register arguments:
489  *
490  * * w1:     TX address
491  * * w2:     RX address
492  * * w3:     RX/TX page count in bit[5:0]
493  *
494  * Return:
495  * * w0:     &SMC_FC_FFA_SUCCESS
496  */
497 #define SMC_FC_FFA_RXTX_MAP SMC_FASTCALL_NR_SHARED_MEMORY(0x66)
498 
499 /**
500  * SMC_FC64_FFA_RXTX_MAP - 64 bit SMC opcode to map message buffers
501  *
502  * Register arguments:
503  *
504  * * x1:     TX address
505  * * x2:     RX address
506  * * x3:     RX/TX page count in bit[5:0]
507  *
508  * Return:
509  * * w0:     &SMC_FC_FFA_SUCCESS
510  */
511 #define SMC_FC64_FFA_RXTX_MAP SMC_FASTCALL64_NR_SHARED_MEMORY(0x66)
512 
513 /**
514  * SMC_FC_FFA_RXTX_UNMAP - SMC opcode to unmap message buffers
515  *
516  * Register arguments:
517  *
518  * * w1:     ID in [31:16]
519  *
520  * Return:
521  * * w0:     &SMC_FC_FFA_SUCCESS
522  */
523 #define SMC_FC_FFA_RXTX_UNMAP SMC_FASTCALL_NR_SHARED_MEMORY(0x67)
524 
525 /**
526  * SMC_FC_FFA_ID_GET - SMC opcode to get endpoint id of caller
527  *
528  * Return:
529  * * w0:     &SMC_FC_FFA_SUCCESS
530  * * w2:     ID in bit[15:0], bit[31:16] must be 0.
531  */
532 #define SMC_FC_FFA_ID_GET SMC_FASTCALL_NR_SHARED_MEMORY(0x69)
533 
534 /**
535  * SMC_FC_FFA_MSG_WAIT - SMC opcode to transition from running to waiting state
536  */
537 #define SMC_FC_FFA_MSG_WAIT SMC_FASTCALL_NR_SHARED_MEMORY(0x6B)
538 
539 /**
540  * SMC_FC_FFA_MSG_SEND_DIRECT_REQ - 32 bit SMC opcode to send direct message as
541  *                                  a request
542  *
543  * Register arguments:
544  *
545  * * w1:     Sender ID in bit[31:16], receiver ID in [15:0]
546  * * w2:     Message Flags.
547  *           bit[31]   : Message type. 0 for partition message and 1 for
548  *                       framework message.
549  *           bit[30:8] : Reserved. Must be 0.
550  *           bit[7:0]  : Framework message type. Must be 0 if partition message.
551  * * w3-w7:  Implementation defined.
552  */
553 #define SMC_FC_FFA_MSG_SEND_DIRECT_REQ SMC_FASTCALL_NR_SHARED_MEMORY(0x6F)
554 
555 /**
556  * SMC_FC64_FFA_MSG_SEND_DIRECT_REQ - 64 bit SMC opcode to send direct message
557  *                                    as a request
558  *
559  * Register arguments:
560  *
561  * * w1:     Sender ID in bit[31:16], receiver ID in [15:0]
562  * * w2:     Message Flags.
563  *           bit[31]   : Message type. 0 for partition message and 1 for
564  *                       framework message.
565  *           bit[30:8] : Reserved. Must be 0.
566  *           bit[7:0]  : Framework message type. Must be 0 if partition message.
567  * * x3-x7:  Implementation defined.
568  */
569 #define SMC_FC64_FFA_MSG_SEND_DIRECT_REQ SMC_FASTCALL64_NR_SHARED_MEMORY(0x6F)
570 
571 /**
572  * SMC_FC_FFA_MSG_SEND_DIRECT_RESP - 32 bit SMC opcode to send direct message as
573  *                                   a response
574  *
575  * Register arguments:
576  *
577  * * w1:     Sender ID in bit[31:16], receiver ID in [15:0]
578  * * w2:     Message Flags.
579  *           bit[31]   : Message type. 0 for partition message and 1 for
580  *                       framework message.
581  *           bit[30:8] : Reserved. Must be 0.
582  *           bit[7:0]  : Framework message type. Must be 0 if partition message.
583  * * w3-w7:  Implementation defined.
584  */
585 #define SMC_FC_FFA_MSG_SEND_DIRECT_RESP SMC_FASTCALL_NR_SHARED_MEMORY(0x70)
586 
587 /**
588  * SMC_FC64_FFA_MSG_SEND_DIRECT_RESP - 64 bit SMC opcode to send direct message
589  *                                     as a response
590  *
591  * Register arguments:
592  *
593  * * w1:     Sender ID in bit[31:16], receiver ID in [15:0]
594  * * w2:     Message Flags.
595  *           bit[31]   : Message type. 0 for partition message and 1 for
596  *                       framework message.
597  *           bit[30:8] : Reserved. Must be 0.
598  *           bit[7:0]  : Framework message type. Must be 0 if partition message.
599  * * x3-x7:  Implementation defined.
600  */
601 #define SMC_FC64_FFA_MSG_SEND_DIRECT_RESP SMC_FASTCALL64_NR_SHARED_MEMORY(0x70)
602 
603 /**
604  * SMC_FC_FFA_MEM_DONATE - 32 bit SMC opcode to donate memory
605  *
606  * Not supported.
607  */
608 #define SMC_FC_FFA_MEM_DONATE SMC_FASTCALL_NR_SHARED_MEMORY(0x71)
609 
610 /**
611  * SMC_FC_FFA_MEM_LEND - 32 bit SMC opcode to lend memory
612  *
613  * Not currently supported.
614  */
615 #define SMC_FC_FFA_MEM_LEND SMC_FASTCALL_NR_SHARED_MEMORY(0x72)
616 
617 /**
618  * SMC_FC_FFA_MEM_SHARE - 32 bit SMC opcode to share memory
619  *
620  * Register arguments:
621  *
622  * * w1:     Total length
623  * * w2:     Fragment length
624  * * w3:     Address
625  * * w4:     Page count
626  *
627  * Return:
628  * * w0:     &SMC_FC_FFA_SUCCESS
629  * * w2/w3:  Handle
630  *
631  * or
632  *
633  * * w0:     &SMC_FC_FFA_MEM_FRAG_RX
634  * * w1-:    See &SMC_FC_FFA_MEM_FRAG_RX
635  *
636  * or
637  *
638  * * w0:     &SMC_FC_FFA_ERROR
639  * * w2:     Error code (&enum ffa_error)
640  */
641 #define SMC_FC_FFA_MEM_SHARE SMC_FASTCALL_NR_SHARED_MEMORY(0x73)
642 
643 /**
644  * SMC_FC64_FFA_MEM_SHARE - 64 bit SMC opcode to share memory
645  *
646  * Register arguments:
647  *
648  * * w1:     Total length
649  * * w2:     Fragment length
650  * * x3:     Address
651  * * w4:     Page count
652  *
653  * Return:
654  * * w0:     &SMC_FC_FFA_SUCCESS
655  * * w2/w3:  Handle
656  *
657  * or
658  *
659  * * w0:     &SMC_FC_FFA_MEM_FRAG_RX
660  * * w1-:    See &SMC_FC_FFA_MEM_FRAG_RX
661  *
662  * or
663  *
664  * * w0:     &SMC_FC_FFA_ERROR
665  * * w2:     Error code (&enum ffa_error)
666  */
667 #define SMC_FC64_FFA_MEM_SHARE SMC_FASTCALL64_NR_SHARED_MEMORY(0x73)
668 
669 /**
670  * SMC_FC_FFA_MEM_RETRIEVE_REQ - 32 bit SMC opcode to retrieve shared memory
671  *
672  * Register arguments:
673  *
674  * * w1:     Total length
675  * * w2:     Fragment length
676  * * w3:     Address
677  * * w4:     Page count
678  *
679  * Return:
680  * * w0:             &SMC_FC_FFA_MEM_RETRIEVE_RESP
681  * * w1/x1-w5/x5:    See &SMC_FC_FFA_MEM_RETRIEVE_RESP
682  */
683 #define SMC_FC_FFA_MEM_RETRIEVE_REQ SMC_FASTCALL_NR_SHARED_MEMORY(0x74)
684 
685 /**
686  * SMC_FC64_FFA_MEM_RETRIEVE_REQ - 64 bit SMC opcode to retrieve shared memory
687  *
688  * Register arguments:
689  *
690  * * w1:     Total length
691  * * w2:     Fragment length
692  * * x3:     Address
693  * * w4:     Page count
694  *
695  * Return:
696  * * w0:             &SMC_FC_FFA_MEM_RETRIEVE_RESP
697  * * w1/x1-w5/x5:    See &SMC_FC_FFA_MEM_RETRIEVE_RESP
698  */
699 #define SMC_FC64_FFA_MEM_RETRIEVE_REQ SMC_FASTCALL64_NR_SHARED_MEMORY(0x74)
700 
701 /**
702  * SMC_FC_FFA_MEM_RETRIEVE_RESP - Retrieve 32 bit SMC return opcode
703  *
704  * Register arguments:
705  *
706  * * w1:     Total length
707  * * w2:     Fragment length
708  */
709 #define SMC_FC_FFA_MEM_RETRIEVE_RESP SMC_FASTCALL_NR_SHARED_MEMORY(0x75)
710 
711 /**
712  * SMC_FC_FFA_MEM_RELINQUISH - SMC opcode to relinquish shared memory
713  *
714  * Input in &struct ffa_mem_relinquish_descriptor format in message buffer.
715  *
716  * Return:
717  * * w0:     &SMC_FC_FFA_SUCCESS
718  */
719 #define SMC_FC_FFA_MEM_RELINQUISH SMC_FASTCALL_NR_SHARED_MEMORY(0x76)
720 
721 /**
722  * SMC_FC_FFA_MEM_RECLAIM - SMC opcode to reclaim shared memory
723  *
724  * Register arguments:
725  *
726  * * w1/w2:  Handle
727  * * w3:     Flags
728  *
729  * Return:
730  * * w0:     &SMC_FC_FFA_SUCCESS
731  */
732 #define SMC_FC_FFA_MEM_RECLAIM SMC_FASTCALL_NR_SHARED_MEMORY(0x77)
733 
734 /**
735  * SMC_FC_FFA_MEM_FRAG_RX - SMC opcode to request next fragment.
736  *
737  * Register arguments:
738  *
739  * * w1/w2:  Handle
740  * * w3:     Fragment offset.
741  * * w4:     Endpoint id ID in [31:16], if client is hypervisor.
742  *
743  * Return:
744  * * w0:             &SMC_FC_FFA_MEM_FRAG_TX
745  * * w1/x1-w5/x5:    See &SMC_FC_FFA_MEM_FRAG_TX
746  */
747 #define SMC_FC_FFA_MEM_FRAG_RX SMC_FASTCALL_NR_SHARED_MEMORY(0x7A)
748 
749 /**
750  * SMC_FC_FFA_MEM_FRAG_TX - SMC opcode to transmit next fragment
751  *
752  * Register arguments:
753  *
754  * * w1/w2:  Handle
755  * * w3:     Fragment length.
756  * * w4:     Sender endpoint id ID in [31:16], if client is hypervisor.
757  *
758  * Return:
759  * * w0:             &SMC_FC_FFA_MEM_FRAG_RX or &SMC_FC_FFA_SUCCESS.
760  * * w1/x1-w5/x5:    See opcode in w0.
761  */
762 #define SMC_FC_FFA_MEM_FRAG_TX SMC_FASTCALL_NR_SHARED_MEMORY(0x7B)
763 
764 /* FF-A v1.1 */
765 /**
766  * SMC_FC64_FFA_SECONDARY_EP_REGISTER - SMC opcode to register secondary
767  * core entrypoint.
768  *
769  * Register arguments:
770  *
771  * * x1:     Entry point address of a secondary execution context
772  *
773  * Return:
774  * * x0:     &SMC_FC64_FFA_SUCCESS
775  *
776  * or
777  *
778  * * x0:     &SMC_FC_FFA_ERROR
779  * * x2:     %FFA_ERROR_NOT_SUPPORTED Not supported
780  *           %FFA_ERROR_INVALID_PARAMETERS Invalid entry point specified
781  */
782 #define SMC_FC64_FFA_SECONDARY_EP_REGISTER SMC_FASTCALL64_NR_SHARED_MEMORY(0x87)
783