1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef QL_TIPC_SMCALL_H_
26 #define QL_TIPC_SMCALL_H_
27 
28 #define SMC_NUM_ENTITIES 64
29 #define SMC_NUM_ARGS 4
30 #define SMC_NUM_PARAMS (SMC_NUM_ARGS - 1)
31 
32 #define SMC_IS_FASTCALL(smc_nr) ((smc_nr)&0x80000000)
33 #define SMC_IS_SMC64(smc_nr) ((smc_nr)&0x40000000)
34 #define SMC_ENTITY(smc_nr) (((smc_nr)&0x3F000000) >> 24)
35 #define SMC_FUNCTION(smc_nr) ((smc_nr)&0x0000FFFF)
36 
37 #define SMC_NR(entity, fn, fastcall, smc64)               \
38     ((((fastcall)&0x1U) << 31) | (((smc64)&0x1U) << 30) | \
39      (((entity)&0x3FU) << 24) | ((fn)&0xFFFFU))
40 
41 #define SMC_FASTCALL_NR(entity, fn) SMC_NR((entity), (fn), 1, 0)
42 #define SMC_STDCALL_NR(entity, fn) SMC_NR((entity), (fn), 0, 0)
43 #define SMC_FASTCALL64_NR(entity, fn) SMC_NR((entity), (fn), 1, 1)
44 #define SMC_STDCALL64_NR(entity, fn) SMC_NR((entity), (fn), 0, 1)
45 
46 /* ARM Architecture calls */
47 #define SMC_ENTITY_ARCH 0
48 /* CPU Service calls */
49 #define SMC_ENTITY_CPU 1
50 /* SIP Service calls */
51 #define SMC_ENTITY_SIP 2
52 /* OEM Service calls */
53 #define SMC_ENTITY_OEM 3
54 /* Standard Service calls */
55 #define SMC_ENTITY_STD 4
56 /* Reserved for future use */
57 #define SMC_ENTITY_RESERVED 5
58 /* Trusted Application calls */
59 #define SMC_ENTITY_TRUSTED_APP 48
60 /* Trusted OS calls */
61 #define SMC_ENTITY_TRUSTED_OS 50
62 /* Used for secure -> nonsecure logging */
63 #define SMC_ENTITY_LOGGING 51
64 /* Trusted OS calls internal to secure monitor */
65 #define SMC_ENTITY_SECURE_MONITOR 60
66 
67 /* FC = Fast call, SC = Standard call */
68 #define SMC_SC_RESTART_LAST SMC_STDCALL_NR(SMC_ENTITY_SECURE_MONITOR, 0)
69 #define SMC_SC_LOCKED_NOP SMC_STDCALL_NR(SMC_ENTITY_SECURE_MONITOR, 1)
70 
71 /**
72  * SMC_SC_RESTART_FIQ - Re-enter trusty after it was interrupted by an fiq
73  *
74  * No arguments, no return value.
75  *
76  * Re-enter trusty after returning to ns to process an fiq. Must be called iff
77  * trusty returns SM_ERR_FIQ_INTERRUPTED.
78  *
79  * Enable by selecting api version TRUSTY_API_VERSION_RESTART_FIQ (1) or later.
80  */
81 #define SMC_SC_RESTART_FIQ SMC_STDCALL_NR(SMC_ENTITY_SECURE_MONITOR, 2)
82 
83 /**
84  * SMC_SC_NOP - Enter trusty to run pending work.
85  *
86  * No arguments.
87  *
88  * Returns SM_ERR_NOP_INTERRUPTED or SM_ERR_NOP_DONE.
89  * If SM_ERR_NOP_INTERRUPTED is returned, the call must be repeated.
90  *
91  * Enable by selecting api version TRUSTY_API_VERSION_SMP (2) or later.
92  */
93 #define SMC_SC_NOP SMC_STDCALL_NR(SMC_ENTITY_SECURE_MONITOR, 3)
94 
95 /*
96  * Return from secure os to non-secure os with return value in r1
97  */
98 #define SMC_SC_NS_RETURN SMC_STDCALL_NR(SMC_ENTITY_SECURE_MONITOR, 0)
99 
100 #define SMC_FC_RESERVED SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 0)
101 #define SMC_FC_FIQ_EXIT SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 1)
102 #define SMC_FC_REQUEST_FIQ SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 2)
103 
104 #define TRUSTY_IRQ_TYPE_NORMAL (0)
105 #define TRUSTY_IRQ_TYPE_PER_CPU (1)
106 #define TRUSTY_IRQ_TYPE_DOORBELL (2)
107 #define SMC_FC_GET_NEXT_IRQ SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 3)
108 
109 #define SMC_FC_FIQ_ENTER SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 4)
110 
111 #define SMC_FC64_SET_FIQ_HANDLER SMC_FASTCALL64_NR(SMC_ENTITY_SECURE_MONITOR, 5)
112 #define SMC_FC64_GET_FIQ_REGS SMC_FASTCALL64_NR(SMC_ENTITY_SECURE_MONITOR, 6)
113 
114 #define SMC_FC_CPU_SUSPEND SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 7)
115 #define SMC_FC_CPU_RESUME SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 8)
116 
117 #define SMC_FC_AARCH_SWITCH SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 9)
118 #define SMC_FC_GET_VERSION_STR SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 10)
119 
120 /**
121  * SMC_FC_API_VERSION - Find and select supported API version.
122  *
123  * @r1: Version supported by client.
124  *
125  * Returns version supported by trusty.
126  *
127  * If multiple versions are supported, the client should start by calling
128  * SMC_FC_API_VERSION with the largest version it supports. Trusty will then
129  * return a version it supports. If the client does not support the version
130  * returned by trusty and the version returned is less than the version
131  * requested, repeat the call with the largest supported version less than the
132  * last returned version.
133  *
134  * This call must be made before any calls that are affected by the api version.
135  */
136 #define TRUSTY_API_VERSION_RESTART_FIQ (1)
137 #define TRUSTY_API_VERSION_SMP (2)
138 #define TRUSTY_API_VERSION_SMP_NOP (3)
139 #define TRUSTY_API_VERSION_PHYS_MEM_OBJ (4)
140 #define TRUSTY_API_VERSION_MEM_OBJ (5)
141 #define TRUSTY_API_VERSION_CURRENT (5)
142 #define SMC_FC_API_VERSION SMC_FASTCALL_NR(SMC_ENTITY_SECURE_MONITOR, 11)
143 
144 /* TRUSTED_OS entity calls */
145 #define SMC_SC_VIRTIO_GET_DESCR SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 20)
146 #define SMC_SC_VIRTIO_START SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 21)
147 #define SMC_SC_VIRTIO_STOP SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 22)
148 
149 #define SMC_SC_VDEV_RESET SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 23)
150 #define SMC_SC_VDEV_KICK_VQ SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 24)
151 #define SMC_NC_VDEV_KICK_VQ SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 25)
152 
153 /* Queueless Trusty IPC Interface */
154 #define SMC_SC_TRUSTY_IPC_CREATE_QL_DEV \
155     SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 30)
156 #define SMC_SC_TRUSTY_IPC_SHUTDOWN_QL_DEV \
157     SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 31)
158 #define SMC_SC_TRUSTY_IPC_HANDLE_QL_DEV_CMD \
159     SMC_STDCALL_NR(SMC_ENTITY_TRUSTED_OS, 32)
160 #define SMC_FC_HANDLE_QL_TIPC_DEV_CMD SMC_FASTCALL_NR(SMC_ENTITY_TRUSTED_OS, 32)
161 
162 #endif /* QL_TIPC_SMCALL_H_ */
163