xref: /linux/drivers/tee/optee/optee_ffa.h (revision 288440de9e5fdb4a3ff73864850f080c1250fc81)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2019-2021, 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 specification.
9  */
10 
11 #ifndef __OPTEE_FFA_H
12 #define __OPTEE_FFA_H
13 
14 #include <linux/arm_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	1
31 #define OPTEE_FFA_VERSION_MINOR	0
32 
33 #define OPTEE_FFA_BLOCKING_CALL(id)	(id)
34 #define OPTEE_FFA_YIELDING_CALL_BIT	31
35 #define OPTEE_FFA_YIELDING_CALL(id)	((id) | BIT(OPTEE_FFA_YIELDING_CALL_BIT))
36 
37 /*
38  * Returns the API version implemented, currently follows the FF-A version.
39  * Call register usage:
40  * w3:    Service ID, OPTEE_FFA_GET_API_VERSION
41  * w4-w7: Not used (MBZ)
42  *
43  * Return register usage:
44  * w3:    OPTEE_FFA_VERSION_MAJOR
45  * w4:    OPTEE_FFA_VERSION_MINOR
46  * w5-w7: Not used (MBZ)
47  */
48 #define OPTEE_FFA_GET_API_VERSION	OPTEE_FFA_BLOCKING_CALL(0)
49 
50 /*
51  * Returns the revision of OP-TEE.
52  *
53  * Used by non-secure world to figure out which version of the Trusted OS
54  * is installed. Note that the returned revision is the revision of the
55  * Trusted OS, not of the API.
56  *
57  * Call register usage:
58  * w3:    Service ID, OPTEE_FFA_GET_OS_VERSION
59  * w4-w7: Unused (MBZ)
60  *
61  * Return register usage:
62  * w3:    CFG_OPTEE_REVISION_MAJOR
63  * w4:    CFG_OPTEE_REVISION_MINOR
64  * w5:    TEE_IMPL_GIT_SHA1 (or zero if not supported)
65  */
66 #define OPTEE_FFA_GET_OS_VERSION	OPTEE_FFA_BLOCKING_CALL(1)
67 
68 /*
69  * Exchange capabilities between normal world and secure world.
70  *
71  * Currently there are no defined capabilities. When features are added new
72  * capabilities may be added.
73  *
74  * Call register usage:
75  * w3:    Service ID, OPTEE_FFA_EXCHANGE_CAPABILITIES
76  * w4-w7: Note used (MBZ)
77  *
78  * Return register usage:
79  * w3:    Error code, 0 on success
80  * w4:    Bit[7:0]:  Number of parameters needed for RPC to be supplied
81  *                   as the second MSG arg struct for
82  *                   OPTEE_FFA_YIELDING_CALL_WITH_ARG.
83  *        Bit[31:8]: Reserved (MBZ)
84  * w5:	  Bitfield of secure world capabilities OPTEE_FFA_SEC_CAP_* below,
85  *	  unused bits MBZ.
86  * w6-w7: Not used (MBZ)
87  */
88 /*
89  * Secure world supports giving an offset into the argument shared memory
90  * object, see also OPTEE_FFA_YIELDING_CALL_WITH_ARG
91  */
92 #define OPTEE_FFA_SEC_CAP_ARG_OFFSET	BIT(0)
93 
94 #define OPTEE_FFA_EXCHANGE_CAPABILITIES OPTEE_FFA_BLOCKING_CALL(2)
95 
96 /*
97  * Unregister shared memory
98  *
99  * Call register usage:
100  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_UNREGISTER_SHM
101  * w4:    Shared memory handle, lower bits
102  * w5:    Shared memory handle, higher bits
103  * w6-w7: Not used (MBZ)
104  *
105  * Return register usage:
106  * w3:    Error code, 0 on success
107  * w4-w7: Note used (MBZ)
108  */
109 #define OPTEE_FFA_UNREGISTER_SHM	OPTEE_FFA_BLOCKING_CALL(3)
110 
111 /*
112  * Call with struct optee_msg_arg as argument in the supplied shared memory
113  * with a zero internal offset and normal cached memory attributes.
114  * Register usage:
115  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_WITH_ARG
116  * w4:    Lower 32 bits of a 64-bit Shared memory handle
117  * w5:    Upper 32 bits of a 64-bit Shared memory handle
118  * w6:    Offset into shared memory pointing to a struct optee_msg_arg
119  *	  right after the parameters of this struct (at offset
120  *	  OPTEE_MSG_GET_ARG_SIZE(num_params) follows a struct optee_msg_arg
121  *	  for RPC, this struct has reserved space for the number of RPC
122  *	  parameters as returned by OPTEE_FFA_EXCHANGE_CAPABILITIES.
123  *	  MBZ unless the bit OPTEE_FFA_SEC_CAP_ARG_OFFSET is received with
124  *	  OPTEE_FFA_EXCHANGE_CAPABILITIES.
125  * w7:    Not used (MBZ)
126  * Resume from RPC. Register usage:
127  * w3:    Service ID, OPTEE_FFA_YIELDING_CALL_RESUME
128  * w4-w6: Not used (MBZ)
129  * w7:    Resume info
130  *
131  * Normal return (yielding call is completed). Register usage:
132  * w3:    Error code, 0 on success
133  * w4:    OPTEE_FFA_YIELDING_CALL_RETURN_DONE
134  * w5-w7: Not used (MBZ)
135  *
136  * RPC interrupt return (RPC from secure world). Register usage:
137  * w3:    Error code == 0
138  * w4:    Any defined RPC code but OPTEE_FFA_YIELDING_CALL_RETURN_DONE
139  * w5-w6: Not used (MBZ)
140  * w7:    Resume info
141  *
142  * Possible error codes in register w3:
143  * 0:                       Success
144  * FFA_DENIED:              w4 isn't one of OPTEE_FFA_YIELDING_CALL_START
145  *                          OPTEE_FFA_YIELDING_CALL_RESUME
146  *
147  * Possible error codes for OPTEE_FFA_YIELDING_CALL_START,
148  * FFA_BUSY:               Number of OP-TEE OS threads exceeded,
149  *                         try again later
150  * FFA_DENIED:             RPC shared memory object not found
151  * FFA_INVALID_PARAMETER:  Bad shared memory handle or offset into the memory
152  *
153  * Possible error codes for OPTEE_FFA_YIELDING_CALL_RESUME
154  * FFA_INVALID_PARAMETER:  Bad resume info
155  */
156 #define OPTEE_FFA_YIELDING_CALL_WITH_ARG	OPTEE_FFA_YIELDING_CALL(0)
157 #define OPTEE_FFA_YIELDING_CALL_RESUME		OPTEE_FFA_YIELDING_CALL(1)
158 
159 #define OPTEE_FFA_YIELDING_CALL_RETURN_DONE		0
160 #define OPTEE_FFA_YIELDING_CALL_RETURN_RPC_CMD		1
161 #define OPTEE_FFA_YIELDING_CALL_RETURN_INTERRUPT	2
162 
163 #endif /*__OPTEE_FFA_H*/
164