xref: /optee_os/core/arch/arm/include/optee_ffa.h (revision 9fc2442cc66c279cb962c90c4375746fc9b28bb9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019, Linaro Limited
4  */
5 
6 /*
7  * This file is exported by OP-TEE and is kept in sync between secure world
8  * and normal world drivers. We're using ARM FF-A 1.0 EAC specification.
9  */
10 
11 #ifndef __OPTEE_FFA_H
12 #define __OPTEE_FFA_H
13 
14 #include <ffa.h>
15 
16 /*
17  * Normal world sends requests with FFA_MSG_SEND_DIRECT_REQ and
18  * responses are returned with FFA_MSG_SEND_DIRECT_RESP for normal
19  * messages.
20  *
21  * All requests with FFA_MSG_SEND_DIRECT_REQ and FFA_MSG_SEND_DIRECT_RESP
22  * are using the AArch32 SMC calling convention with register usage as
23  * defined in FF-A specification:
24  * w0:    Function ID (0x8400006F or 0x84000070)
25  * w1:    Source/Destination IDs
26  * w2:    Reserved (MBZ)
27  * w3-w7: Implementation defined, free to be used below
28  */
29 
30 #define OPTEE_FFA_VERSION_MAJOR	UINT32_C(0)
31 #define OPTEE_FFA_VERSION_MINOR	UINT32_C(9)
32 
33 #define OPTEE_FFA_BLOCKING_CALL(id)	UINT32_C(id)
34 #define OPTEE_FFA_YIELDING_CALL_BIT	31
35 #define OPTEE_FFA_YIELDING_CALL(id)	(UINT32_C(id) | \
36 					 BIT32(OPTEE_FFA_YIELDING_CALL_BIT))
37 
38 /*
39  * Returns the API version implemented, currently follows the FF-A version.
40  * Call register usage:
41  * w3:    Service ID, OPTEE_FFA_GET_API_VERSION
42  * w4-w7: Not used (MBZ)
43  *
44  * Return register usage:
45  * w3:    OPTEE_FFA_VERSION_MAJOR
46  * w4:    OPTEE_FFA_VERSION_MINOR
47  * w5-w7: Not used (MBZ)
48  */
49 #define OPTEE_FFA_GET_API_VERSION	OPTEE_FFA_BLOCKING_CALL(0)
50 
51 /*
52  * Returns the revision of OP-TEE.
53  *
54  * Used by non-secure world to figure out which version of the Trusted OS
55  * is installed. Note that the returned revision is the revision of the
56  * Trusted OS, not of the API.
57  *
58  * Call register usage:
59  * w3:    Service ID, OPTEE_FFA_GET_OS_VERSION
60  * w4-w7: Unused (MBZ)
61  *
62  * Return register usage:
63  * w3:    CFG_OPTEE_REVISION_MAJOR
64  * w4:    CFG_OPTEE_REVISION_MINOR
65  * w5:    TEE_IMPL_GIT_SHA1 (or zero if not supported)
66  */
67 #define OPTEE_FFA_GET_OS_VERSION	OPTEE_FFA_BLOCKING_CALL(1)
68 
69 /*
70  * Exchange capabilities between normal world and secure world.
71  *
72  * Currently there are no defined capabilities. When features are added new
73  * capabilities may be added.
74  *
75  * Call register usage:
76  * w3:    Service ID, OPTEE_FFA_EXCHANGE_CAPABILITIES
77  * w4-w7: Note used (MBZ)
78  *
79  * Return register usage:
80  * w3:    Error code, 0 on success
81  * w4:    Bit[1:0]:  Number of 4kB pages of shared memory to register with
82  *                   OPTEE_FFA_REGISTER_RPC_SHM to support RPC
83  *        Bit[31:2]: Reserved (MBZ)
84  * w5-w7: Note used (MBZ)
85  */
86 #define OPTEE_FFA_EXCHANGE_CAPABILITIES OPTEE_FFA_BLOCKING_CALL(2)
87 
88 /*
89  * Call with struct optee_msg_arg as argument in the supplied shared memory
90  * with a zero internal offset and normal cached memory attributes.
91  * Register usage:
92  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_WITH_ARG
93  * w4:    Lower 32 bits of a 64-bit Shared memory handle
94  * w5:    Upper 32 bits of a 64-bit Shared memory handle
95  * w6:    Offset into shared memory pointing to a struct optee_msg_arg
96  * w7:    Not used (MBZ)
97  *
98  * Call to register shared memory. The data is supplied in shared
99  * memory with a zero internal offset and normal cached memory attributes.
100  * The data is formatted as described in FF-A 1.0 EAC Table 44
101  * "Lend, donate or share memory transaction descriptor".
102  * Register usage:
103  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_REGISTER_SHM
104  * w4:    Lower 32 bits of a 64-bit Shared memory handle
105  * w5:    Upper 32 bits of a 64-bit Shared memory handle
106  * w6-w7: Not used (MBZ)
107  *
108  * Call to unregister shared memory. Register usage:
109  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM
110  * w4:    Lower 32 bits of a 64-bit Shared memory handle
111  * w5:    Upper 32 bits of a 64-bit Shared memory handle
112  * w6-w7: Not used (MBZ)
113  *
114  * Resume from RPC. Register usage:
115  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_RESUME
116  * If returning from OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_SHM:
117  *	w4:    Lower 32 bits of a 64-bit Shared memory handle
118  *	w5:    Upper 32 bits of a 64-bit Shared memory handle
119  *	       If the allocation failed both w4 and w5 are 0
120  *	w6:    Offset into shared memory pointing the table. If internal
121  *	       offset > 0 then one more 4kB page than requested has been
122  *	       allocated.
123  * else if resuming from another RPC:
124  *	w4-w6: Not used (MBZ)
125  * w7:    Resume info
126  *
127  * Normal return (yielding call is completed). Register usage:
128  * w3:    Error code, 0 on success
129  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_DONE
130  * w5-w7: Not used (MBZ)
131  *
132  * Alloc SHM return (RPC from secure world). Register usage:
133  * w3:    Error code == 0
134  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_KERN_SHM or
135  *	  OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_SUPPL_SHM
136  *	  allocate kernel private or supplicant memory respectively.
137  * w5:    Number of 4kB pages of shared memory
138  * w6:    Not used (MBZ)
139  * w7:    Resume info
140  *
141  * Free SHM return (RPC from secure world). Register usage:
142  * w3:    Error code == 0
143  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_FREE_KERN_SHM or
144  *	  OPTEE_FFA_YIELDING_CALL_RETURN_FREE_SUPPL_SHM
145  *	  free kernel private or supplicant memory respectively.
146  * w5:    Lower 32 bits of a 64-bit Shared memory handle
147  * w6:    Upper 32 bits of a 64-bit Shared memory handle
148  *	  The handle previously allocated with
149  *	  OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_KERN_SHM or
150  *	  OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_SUPPL_SHM.
151  * w7:    Resume info
152  *
153  * RPC cmd return (RPC from secure world). Register usage:
154  * w3:    Error code == 0
155  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_RPC_CMD
156  * w5:    Lower 32 bits of a 64-bit Shared memory handle
157  * w6:    Upper 32 bits of a 64-bit Shared memory handle
158  *	  The handle contains aed the RPC.
159  * w7:    Resume info
160  *
161  * RPC interrupt return (RPC from secure world). Register usage:
162  * w3:    Error code == 0
163  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_INTERRUPT
164  * w5-w6: Not used (MBZ)
165  * w7:    Resume info
166  *
167  * Possible error codes in register w3:
168  * 0:                       Success
169  * FFA_DENIED:              w4 isn't one of OPTEE_FFA_YIELDING_CALL_START
170  *                          OPTEE_FFA_YIELDING_CALL_REGISTER_SHM,
171  *                          OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM or
172  *                          OPTEE_FFA_YIELDING_CALL_RESUME
173  *
174  * Possible error codes for OPTEE_FFA_YIELDING_CALL_START,
175  * OPTEE_FFA_YIELDING_CALL_REGISTER_SHM and
176  * OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM
177  * FFA_BUSY:               Number of OP-TEE OS threads exceeded,
178  *                         try again later
179  * FFA_DENIED:             RPC shared memory object not found
180  * FFA_INVALID_PARAMETER:  Bad shared memory handle or offset into the memory
181  *
182  * Possible error codes for OPTEE_FFA_YIELDING_CALL_RESUME
183  * FFA_INVALID_PARAMETER:  Bad resume info
184  */
185 #define OPTEE_FFA_YIELDING_CALL_WITH_ARG	OPTEE_FFA_YIELDING_CALL(0)
186 #define OPTEE_FFA_YIELDING_CALL_REGISTER_SHM	OPTEE_FFA_YIELDING_CALL(1)
187 #define OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM	OPTEE_FFA_YIELDING_CALL(2)
188 #define OPTEE_FFA_YIELDING_CALL_RESUME		OPTEE_FFA_YIELDING_CALL(3)
189 
190 #define OPTEE_FFA_YIELDING_CALL_RETURN_DONE		0
191 #define OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_KERN_SHM	1
192 #define OPTEE_FFA_YIELDING_CALL_RETURN_ALLOC_SUPPL_SHM	2
193 #define OPTEE_FFA_YIELDING_CALL_RETURN_RESERVED0	3
194 #define OPTEE_FFA_YIELDING_CALL_RETURN_FREE_KERN_SHM	4
195 #define OPTEE_FFA_YIELDING_CALL_RETURN_FREE_SUPPL_SHM	5
196 #define OPTEE_FFA_YIELDING_CALL_RETURN_RESERVED1	6
197 #define OPTEE_FFA_YIELDING_CALL_RETURN_RPC_CMD		7
198 #define OPTEE_FFA_YIELDING_CALL_RETURN_INTERRUPT	8
199 
200 #endif /*__OPTEE_FFA_H*/
201 
202