Merge tag 'dmaengine-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul...
[linux-2.6-microblaze.git] / include / linux / arm-smccc.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  */
5 #ifndef __LINUX_ARM_SMCCC_H
6 #define __LINUX_ARM_SMCCC_H
7
8 #include <linux/args.h>
9 #include <linux/init.h>
10 #include <uapi/linux/const.h>
11
12 /*
13  * This file provides common defines for ARM SMC Calling Convention as
14  * specified in
15  * https://developer.arm.com/docs/den0028/latest
16  *
17  * This code is up-to-date with version DEN 0028 C
18  */
19
20 #define ARM_SMCCC_STD_CALL              _AC(0,U)
21 #define ARM_SMCCC_FAST_CALL             _AC(1,U)
22 #define ARM_SMCCC_TYPE_SHIFT            31
23
24 #define ARM_SMCCC_SMC_32                0
25 #define ARM_SMCCC_SMC_64                1
26 #define ARM_SMCCC_CALL_CONV_SHIFT       30
27
28 #define ARM_SMCCC_OWNER_MASK            0x3F
29 #define ARM_SMCCC_OWNER_SHIFT           24
30
31 #define ARM_SMCCC_FUNC_MASK             0xFFFF
32
33 #define ARM_SMCCC_IS_FAST_CALL(smc_val) \
34         ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT))
35 #define ARM_SMCCC_IS_64(smc_val) \
36         ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT))
37 #define ARM_SMCCC_FUNC_NUM(smc_val)     ((smc_val) & ARM_SMCCC_FUNC_MASK)
38 #define ARM_SMCCC_OWNER_NUM(smc_val) \
39         (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK)
40
41 #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
42         (((type) << ARM_SMCCC_TYPE_SHIFT) | \
43         ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
44         (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
45         ((func_num) & ARM_SMCCC_FUNC_MASK))
46
47 #define ARM_SMCCC_OWNER_ARCH            0
48 #define ARM_SMCCC_OWNER_CPU             1
49 #define ARM_SMCCC_OWNER_SIP             2
50 #define ARM_SMCCC_OWNER_OEM             3
51 #define ARM_SMCCC_OWNER_STANDARD        4
52 #define ARM_SMCCC_OWNER_STANDARD_HYP    5
53 #define ARM_SMCCC_OWNER_VENDOR_HYP      6
54 #define ARM_SMCCC_OWNER_TRUSTED_APP     48
55 #define ARM_SMCCC_OWNER_TRUSTED_APP_END 49
56 #define ARM_SMCCC_OWNER_TRUSTED_OS      50
57 #define ARM_SMCCC_OWNER_TRUSTED_OS_END  63
58
59 #define ARM_SMCCC_FUNC_QUERY_CALL_UID  0xff01
60
61 #define ARM_SMCCC_QUIRK_NONE            0
62 #define ARM_SMCCC_QUIRK_QCOM_A6         1 /* Save/restore register a6 */
63
64 #define ARM_SMCCC_VERSION_1_0           0x10000
65 #define ARM_SMCCC_VERSION_1_1           0x10001
66 #define ARM_SMCCC_VERSION_1_2           0x10002
67 #define ARM_SMCCC_VERSION_1_3           0x10003
68
69 #define ARM_SMCCC_1_3_SVE_HINT          0x10000
70
71 #define ARM_SMCCC_VERSION_FUNC_ID                                       \
72         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
73                            ARM_SMCCC_SMC_32,                            \
74                            0, 0)
75
76 #define ARM_SMCCC_ARCH_FEATURES_FUNC_ID                                 \
77         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
78                            ARM_SMCCC_SMC_32,                            \
79                            0, 1)
80
81 #define ARM_SMCCC_ARCH_SOC_ID                                           \
82         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
83                            ARM_SMCCC_SMC_32,                            \
84                            0, 2)
85
86 #define ARM_SMCCC_ARCH_WORKAROUND_1                                     \
87         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
88                            ARM_SMCCC_SMC_32,                            \
89                            0, 0x8000)
90
91 #define ARM_SMCCC_ARCH_WORKAROUND_2                                     \
92         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
93                            ARM_SMCCC_SMC_32,                            \
94                            0, 0x7fff)
95
96 #define ARM_SMCCC_ARCH_WORKAROUND_3                                     \
97         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
98                            ARM_SMCCC_SMC_32,                            \
99                            0, 0x3fff)
100
101 #define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID                           \
102         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
103                            ARM_SMCCC_SMC_32,                            \
104                            ARM_SMCCC_OWNER_VENDOR_HYP,                  \
105                            ARM_SMCCC_FUNC_QUERY_CALL_UID)
106
107 /* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74 */
108 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0      0xb66fb428U
109 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1      0xe911c52eU
110 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2      0x564bcaa9U
111 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3      0x743a004dU
112
113 /* KVM "vendor specific" services */
114 #define ARM_SMCCC_KVM_FUNC_FEATURES             0
115 #define ARM_SMCCC_KVM_FUNC_PTP                  1
116 #define ARM_SMCCC_KVM_FUNC_FEATURES_2           127
117 #define ARM_SMCCC_KVM_NUM_FUNCS                 128
118
119 #define ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID                       \
120         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
121                            ARM_SMCCC_SMC_32,                            \
122                            ARM_SMCCC_OWNER_VENDOR_HYP,                  \
123                            ARM_SMCCC_KVM_FUNC_FEATURES)
124
125 #define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED    1
126
127 /*
128  * ptp_kvm is a feature used for time sync between vm and host.
129  * ptp_kvm module in guest kernel will get service from host using
130  * this hypercall ID.
131  */
132 #define ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID                            \
133         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
134                            ARM_SMCCC_SMC_32,                            \
135                            ARM_SMCCC_OWNER_VENDOR_HYP,                  \
136                            ARM_SMCCC_KVM_FUNC_PTP)
137
138 /* ptp_kvm counter type ID */
139 #define KVM_PTP_VIRT_COUNTER                    0
140 #define KVM_PTP_PHYS_COUNTER                    1
141
142 /* Paravirtualised time calls (defined by ARM DEN0057A) */
143 #define ARM_SMCCC_HV_PV_TIME_FEATURES                           \
144         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
145                            ARM_SMCCC_SMC_64,                    \
146                            ARM_SMCCC_OWNER_STANDARD_HYP,        \
147                            0x20)
148
149 #define ARM_SMCCC_HV_PV_TIME_ST                                 \
150         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
151                            ARM_SMCCC_SMC_64,                    \
152                            ARM_SMCCC_OWNER_STANDARD_HYP,        \
153                            0x21)
154
155 /* TRNG entropy source calls (defined by ARM DEN0098) */
156 #define ARM_SMCCC_TRNG_VERSION                                  \
157         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
158                            ARM_SMCCC_SMC_32,                    \
159                            ARM_SMCCC_OWNER_STANDARD,            \
160                            0x50)
161
162 #define ARM_SMCCC_TRNG_FEATURES                                 \
163         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
164                            ARM_SMCCC_SMC_32,                    \
165                            ARM_SMCCC_OWNER_STANDARD,            \
166                            0x51)
167
168 #define ARM_SMCCC_TRNG_GET_UUID                                 \
169         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
170                            ARM_SMCCC_SMC_32,                    \
171                            ARM_SMCCC_OWNER_STANDARD,            \
172                            0x52)
173
174 #define ARM_SMCCC_TRNG_RND32                                    \
175         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
176                            ARM_SMCCC_SMC_32,                    \
177                            ARM_SMCCC_OWNER_STANDARD,            \
178                            0x53)
179
180 #define ARM_SMCCC_TRNG_RND64                                    \
181         ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                 \
182                            ARM_SMCCC_SMC_64,                    \
183                            ARM_SMCCC_OWNER_STANDARD,            \
184                            0x53)
185
186 /*
187  * Return codes defined in ARM DEN 0070A
188  * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C
189  */
190 #define SMCCC_RET_SUCCESS                       0
191 #define SMCCC_RET_NOT_SUPPORTED                 -1
192 #define SMCCC_RET_NOT_REQUIRED                  -2
193 #define SMCCC_RET_INVALID_PARAMETER             -3
194
195 #ifndef __ASSEMBLY__
196
197 #include <linux/linkage.h>
198 #include <linux/types.h>
199
200 enum arm_smccc_conduit {
201         SMCCC_CONDUIT_NONE,
202         SMCCC_CONDUIT_SMC,
203         SMCCC_CONDUIT_HVC,
204 };
205
206 /**
207  * arm_smccc_1_1_get_conduit()
208  *
209  * Returns the conduit to be used for SMCCCv1.1 or later.
210  *
211  * When SMCCCv1.1 is not present, returns SMCCC_CONDUIT_NONE.
212  */
213 enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void);
214
215 /**
216  * arm_smccc_get_version()
217  *
218  * Returns the version to be used for SMCCCv1.1 or later.
219  *
220  * When SMCCCv1.1 or above is not present, returns SMCCCv1.0, but this
221  * does not imply the presence of firmware or a valid conduit. Caller
222  * handling SMCCCv1.0 must determine the conduit by other means.
223  */
224 u32 arm_smccc_get_version(void);
225
226 void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit);
227
228 extern u64 smccc_has_sve_hint;
229
230 /**
231  * arm_smccc_get_soc_id_version()
232  *
233  * Returns the SOC ID version.
234  *
235  * When ARM_SMCCC_ARCH_SOC_ID is not present, returns SMCCC_RET_NOT_SUPPORTED.
236  */
237 s32 arm_smccc_get_soc_id_version(void);
238
239 /**
240  * arm_smccc_get_soc_id_revision()
241  *
242  * Returns the SOC ID revision.
243  *
244  * When ARM_SMCCC_ARCH_SOC_ID is not present, returns SMCCC_RET_NOT_SUPPORTED.
245  */
246 s32 arm_smccc_get_soc_id_revision(void);
247
248 /**
249  * struct arm_smccc_res - Result from SMC/HVC call
250  * @a0-a3 result values from registers 0 to 3
251  */
252 struct arm_smccc_res {
253         unsigned long a0;
254         unsigned long a1;
255         unsigned long a2;
256         unsigned long a3;
257 };
258
259 #ifdef CONFIG_ARM64
260 /**
261  * struct arm_smccc_1_2_regs - Arguments for or Results from SMC/HVC call
262  * @a0-a17 argument values from registers 0 to 17
263  */
264 struct arm_smccc_1_2_regs {
265         unsigned long a0;
266         unsigned long a1;
267         unsigned long a2;
268         unsigned long a3;
269         unsigned long a4;
270         unsigned long a5;
271         unsigned long a6;
272         unsigned long a7;
273         unsigned long a8;
274         unsigned long a9;
275         unsigned long a10;
276         unsigned long a11;
277         unsigned long a12;
278         unsigned long a13;
279         unsigned long a14;
280         unsigned long a15;
281         unsigned long a16;
282         unsigned long a17;
283 };
284
285 /**
286  * arm_smccc_1_2_hvc() - make HVC calls
287  * @args: arguments passed via struct arm_smccc_1_2_regs
288  * @res: result values via struct arm_smccc_1_2_regs
289  *
290  * This function is used to make HVC calls following SMC Calling Convention
291  * v1.2 or above. The content of the supplied param are copied from the
292  * structure to registers prior to the HVC instruction. The return values
293  * are updated with the content from registers on return from the HVC
294  * instruction.
295  */
296 asmlinkage void arm_smccc_1_2_hvc(const struct arm_smccc_1_2_regs *args,
297                                   struct arm_smccc_1_2_regs *res);
298
299 /**
300  * arm_smccc_1_2_smc() - make SMC calls
301  * @args: arguments passed via struct arm_smccc_1_2_regs
302  * @res: result values via struct arm_smccc_1_2_regs
303  *
304  * This function is used to make SMC calls following SMC Calling Convention
305  * v1.2 or above. The content of the supplied param are copied from the
306  * structure to registers prior to the SMC instruction. The return values
307  * are updated with the content from registers on return from the SMC
308  * instruction.
309  */
310 asmlinkage void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
311                                   struct arm_smccc_1_2_regs *res);
312 #endif
313
314 /**
315  * struct arm_smccc_quirk - Contains quirk information
316  * @id: quirk identification
317  * @state: quirk specific information
318  * @a6: Qualcomm quirk entry for returning post-smc call contents of a6
319  */
320 struct arm_smccc_quirk {
321         int     id;
322         union {
323                 unsigned long a6;
324         } state;
325 };
326
327 /**
328  * __arm_smccc_sve_check() - Set the SVE hint bit when doing SMC calls
329  *
330  * Sets the SMCCC hint bit to indicate if there is live state in the SVE
331  * registers, this modifies x0 in place and should never be called from C
332  * code.
333  */
334 asmlinkage unsigned long __arm_smccc_sve_check(unsigned long x0);
335
336 /**
337  * __arm_smccc_smc() - make SMC calls
338  * @a0-a7: arguments passed in registers 0 to 7
339  * @res: result values from registers 0 to 3
340  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
341  *
342  * This function is used to make SMC calls following SMC Calling Convention.
343  * The content of the supplied param are copied to registers 0 to 7 prior
344  * to the SMC instruction. The return values are updated with the content
345  * from register 0 to 3 on return from the SMC instruction.  An optional
346  * quirk structure provides vendor specific behavior.
347  */
348 #ifdef CONFIG_HAVE_ARM_SMCCC
349 asmlinkage void __arm_smccc_smc(unsigned long a0, unsigned long a1,
350                         unsigned long a2, unsigned long a3, unsigned long a4,
351                         unsigned long a5, unsigned long a6, unsigned long a7,
352                         struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
353 #else
354 static inline void __arm_smccc_smc(unsigned long a0, unsigned long a1,
355                         unsigned long a2, unsigned long a3, unsigned long a4,
356                         unsigned long a5, unsigned long a6, unsigned long a7,
357                         struct arm_smccc_res *res, struct arm_smccc_quirk *quirk)
358 {
359         *res = (struct arm_smccc_res){};
360 }
361 #endif
362
363 /**
364  * __arm_smccc_hvc() - make HVC calls
365  * @a0-a7: arguments passed in registers 0 to 7
366  * @res: result values from registers 0 to 3
367  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
368  *
369  * This function is used to make HVC calls following SMC Calling
370  * Convention.  The content of the supplied param are copied to registers 0
371  * to 7 prior to the HVC instruction. The return values are updated with
372  * the content from register 0 to 3 on return from the HVC instruction.  An
373  * optional quirk structure provides vendor specific behavior.
374  */
375 asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
376                         unsigned long a2, unsigned long a3, unsigned long a4,
377                         unsigned long a5, unsigned long a6, unsigned long a7,
378                         struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
379
380 #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
381
382 #define arm_smccc_smc_quirk(...) __arm_smccc_smc(__VA_ARGS__)
383
384 #define arm_smccc_hvc(...) __arm_smccc_hvc(__VA_ARGS__, NULL)
385
386 #define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__)
387
388 /* SMCCC v1.1 implementation madness follows */
389 #ifdef CONFIG_ARM64
390
391 #define SMCCC_SMC_INST  "smc    #0"
392 #define SMCCC_HVC_INST  "hvc    #0"
393
394 #elif defined(CONFIG_ARM)
395 #include <asm/opcodes-sec.h>
396 #include <asm/opcodes-virt.h>
397
398 #define SMCCC_SMC_INST  __SMC(0)
399 #define SMCCC_HVC_INST  __HVC(0)
400
401 #endif
402
403 /* nVHE hypervisor doesn't have a current thread so needs separate checks */
404 #if defined(CONFIG_ARM64_SVE) && !defined(__KVM_NVHE_HYPERVISOR__)
405
406 #define SMCCC_SVE_CHECK ALTERNATIVE("nop \n",  "bl __arm_smccc_sve_check \n", \
407                                     ARM64_SVE)
408 #define smccc_sve_clobbers "x16", "x30", "cc",
409
410 #else
411
412 #define SMCCC_SVE_CHECK
413 #define smccc_sve_clobbers
414
415 #endif
416
417 #define __constraint_read_2     "r" (arg0)
418 #define __constraint_read_3     __constraint_read_2, "r" (arg1)
419 #define __constraint_read_4     __constraint_read_3, "r" (arg2)
420 #define __constraint_read_5     __constraint_read_4, "r" (arg3)
421 #define __constraint_read_6     __constraint_read_5, "r" (arg4)
422 #define __constraint_read_7     __constraint_read_6, "r" (arg5)
423 #define __constraint_read_8     __constraint_read_7, "r" (arg6)
424 #define __constraint_read_9     __constraint_read_8, "r" (arg7)
425
426 #define __declare_arg_2(a0, res)                                        \
427         struct arm_smccc_res   *___res = res;                           \
428         register unsigned long arg0 asm("r0") = (u32)a0
429
430 #define __declare_arg_3(a0, a1, res)                                    \
431         typeof(a1) __a1 = a1;                                           \
432         struct arm_smccc_res   *___res = res;                           \
433         register unsigned long arg0 asm("r0") = (u32)a0;                        \
434         register typeof(a1) arg1 asm("r1") = __a1
435
436 #define __declare_arg_4(a0, a1, a2, res)                                \
437         typeof(a1) __a1 = a1;                                           \
438         typeof(a2) __a2 = a2;                                           \
439         struct arm_smccc_res   *___res = res;                           \
440         register unsigned long arg0 asm("r0") = (u32)a0;                        \
441         register typeof(a1) arg1 asm("r1") = __a1;                      \
442         register typeof(a2) arg2 asm("r2") = __a2
443
444 #define __declare_arg_5(a0, a1, a2, a3, res)                            \
445         typeof(a1) __a1 = a1;                                           \
446         typeof(a2) __a2 = a2;                                           \
447         typeof(a3) __a3 = a3;                                           \
448         struct arm_smccc_res   *___res = res;                           \
449         register unsigned long arg0 asm("r0") = (u32)a0;                        \
450         register typeof(a1) arg1 asm("r1") = __a1;                      \
451         register typeof(a2) arg2 asm("r2") = __a2;                      \
452         register typeof(a3) arg3 asm("r3") = __a3
453
454 #define __declare_arg_6(a0, a1, a2, a3, a4, res)                        \
455         typeof(a4) __a4 = a4;                                           \
456         __declare_arg_5(a0, a1, a2, a3, res);                           \
457         register typeof(a4) arg4 asm("r4") = __a4
458
459 #define __declare_arg_7(a0, a1, a2, a3, a4, a5, res)                    \
460         typeof(a5) __a5 = a5;                                           \
461         __declare_arg_6(a0, a1, a2, a3, a4, res);                       \
462         register typeof(a5) arg5 asm("r5") = __a5
463
464 #define __declare_arg_8(a0, a1, a2, a3, a4, a5, a6, res)                \
465         typeof(a6) __a6 = a6;                                           \
466         __declare_arg_7(a0, a1, a2, a3, a4, a5, res);                   \
467         register typeof(a6) arg6 asm("r6") = __a6
468
469 #define __declare_arg_9(a0, a1, a2, a3, a4, a5, a6, a7, res)            \
470         typeof(a7) __a7 = a7;                                           \
471         __declare_arg_8(a0, a1, a2, a3, a4, a5, a6, res);               \
472         register typeof(a7) arg7 asm("r7") = __a7
473
474 /*
475  * We have an output list that is not necessarily used, and GCC feels
476  * entitled to optimise the whole sequence away. "volatile" is what
477  * makes it stick.
478  */
479 #define __arm_smccc_1_1(inst, ...)                                      \
480         do {                                                            \
481                 register unsigned long r0 asm("r0");                    \
482                 register unsigned long r1 asm("r1");                    \
483                 register unsigned long r2 asm("r2");                    \
484                 register unsigned long r3 asm("r3");                    \
485                 CONCATENATE(__declare_arg_,                             \
486                             COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__);      \
487                 asm volatile(SMCCC_SVE_CHECK                            \
488                              inst "\n" :                                \
489                              "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3) \
490                              : CONCATENATE(__constraint_read_,          \
491                                            COUNT_ARGS(__VA_ARGS__))     \
492                              : smccc_sve_clobbers "memory");            \
493                 if (___res)                                             \
494                         *___res = (typeof(*___res)){r0, r1, r2, r3};    \
495         } while (0)
496
497 /*
498  * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call
499  *
500  * This is a variadic macro taking one to eight source arguments, and
501  * an optional return structure.
502  *
503  * @a0-a7: arguments passed in registers 0 to 7
504  * @res: result values from registers 0 to 3
505  *
506  * This macro is used to make SMC calls following SMC Calling Convention v1.1.
507  * The content of the supplied param are copied to registers 0 to 7 prior
508  * to the SMC instruction. The return values are updated with the content
509  * from register 0 to 3 on return from the SMC instruction if not NULL.
510  */
511 #define arm_smccc_1_1_smc(...)  __arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__)
512
513 /*
514  * arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call
515  *
516  * This is a variadic macro taking one to eight source arguments, and
517  * an optional return structure.
518  *
519  * @a0-a7: arguments passed in registers 0 to 7
520  * @res: result values from registers 0 to 3
521  *
522  * This macro is used to make HVC calls following SMC Calling Convention v1.1.
523  * The content of the supplied param are copied to registers 0 to 7 prior
524  * to the HVC instruction. The return values are updated with the content
525  * from register 0 to 3 on return from the HVC instruction if not NULL.
526  */
527 #define arm_smccc_1_1_hvc(...)  __arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__)
528
529 /*
530  * Like arm_smccc_1_1* but always returns SMCCC_RET_NOT_SUPPORTED.
531  * Used when the SMCCC conduit is not defined. The empty asm statement
532  * avoids compiler warnings about unused variables.
533  */
534 #define __fail_smccc_1_1(...)                                           \
535         do {                                                            \
536                 CONCATENATE(__declare_arg_,                             \
537                             COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__);      \
538                 asm ("" :                                               \
539                      : CONCATENATE(__constraint_read_,                  \
540                                    COUNT_ARGS(__VA_ARGS__))             \
541                      : smccc_sve_clobbers "memory");                    \
542                 if (___res)                                             \
543                         ___res->a0 = SMCCC_RET_NOT_SUPPORTED;           \
544         } while (0)
545
546 /*
547  * arm_smccc_1_1_invoke() - make an SMCCC v1.1 compliant call
548  *
549  * This is a variadic macro taking one to eight source arguments, and
550  * an optional return structure.
551  *
552  * @a0-a7: arguments passed in registers 0 to 7
553  * @res: result values from registers 0 to 3
554  *
555  * This macro will make either an HVC call or an SMC call depending on the
556  * current SMCCC conduit. If no valid conduit is available then -1
557  * (SMCCC_RET_NOT_SUPPORTED) is returned in @res.a0 (if supplied).
558  *
559  * The return value also provides the conduit that was used.
560  */
561 #define arm_smccc_1_1_invoke(...) ({                                    \
562                 int method = arm_smccc_1_1_get_conduit();               \
563                 switch (method) {                                       \
564                 case SMCCC_CONDUIT_HVC:                                 \
565                         arm_smccc_1_1_hvc(__VA_ARGS__);                 \
566                         break;                                          \
567                 case SMCCC_CONDUIT_SMC:                                 \
568                         arm_smccc_1_1_smc(__VA_ARGS__);                 \
569                         break;                                          \
570                 default:                                                \
571                         __fail_smccc_1_1(__VA_ARGS__);                  \
572                         method = SMCCC_CONDUIT_NONE;                    \
573                         break;                                          \
574                 }                                                       \
575                 method;                                                 \
576         })
577
578 #endif /*__ASSEMBLY__*/
579 #endif /*__LINUX_ARM_SMCCC_H*/