xref: /openbmc/linux/include/linux/arm-smccc.h (revision 701fae8d)
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 #define ARM_SMCCC_CALL_HINTS		ARM_SMCCC_1_3_SVE_HINT
71 
72 
73 #define ARM_SMCCC_VERSION_FUNC_ID					\
74 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
75 			   ARM_SMCCC_SMC_32,				\
76 			   0, 0)
77 
78 #define ARM_SMCCC_ARCH_FEATURES_FUNC_ID					\
79 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
80 			   ARM_SMCCC_SMC_32,				\
81 			   0, 1)
82 
83 #define ARM_SMCCC_ARCH_SOC_ID						\
84 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
85 			   ARM_SMCCC_SMC_32,				\
86 			   0, 2)
87 
88 #define ARM_SMCCC_ARCH_WORKAROUND_1					\
89 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
90 			   ARM_SMCCC_SMC_32,				\
91 			   0, 0x8000)
92 
93 #define ARM_SMCCC_ARCH_WORKAROUND_2					\
94 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
95 			   ARM_SMCCC_SMC_32,				\
96 			   0, 0x7fff)
97 
98 #define ARM_SMCCC_ARCH_WORKAROUND_3					\
99 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
100 			   ARM_SMCCC_SMC_32,				\
101 			   0, 0x3fff)
102 
103 #define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID				\
104 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
105 			   ARM_SMCCC_SMC_32,				\
106 			   ARM_SMCCC_OWNER_VENDOR_HYP,			\
107 			   ARM_SMCCC_FUNC_QUERY_CALL_UID)
108 
109 /* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74 */
110 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0	0xb66fb428U
111 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1	0xe911c52eU
112 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2	0x564bcaa9U
113 #define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3	0x743a004dU
114 
115 /* KVM "vendor specific" services */
116 #define ARM_SMCCC_KVM_FUNC_FEATURES		0
117 #define ARM_SMCCC_KVM_FUNC_PTP			1
118 #define ARM_SMCCC_KVM_FUNC_FEATURES_2		127
119 #define ARM_SMCCC_KVM_NUM_FUNCS			128
120 
121 #define ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID			\
122 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
123 			   ARM_SMCCC_SMC_32,				\
124 			   ARM_SMCCC_OWNER_VENDOR_HYP,			\
125 			   ARM_SMCCC_KVM_FUNC_FEATURES)
126 
127 #define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED	1
128 
129 /*
130  * ptp_kvm is a feature used for time sync between vm and host.
131  * ptp_kvm module in guest kernel will get service from host using
132  * this hypercall ID.
133  */
134 #define ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID				\
135 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
136 			   ARM_SMCCC_SMC_32,				\
137 			   ARM_SMCCC_OWNER_VENDOR_HYP,			\
138 			   ARM_SMCCC_KVM_FUNC_PTP)
139 
140 /* ptp_kvm counter type ID */
141 #define KVM_PTP_VIRT_COUNTER			0
142 #define KVM_PTP_PHYS_COUNTER			1
143 
144 /* Paravirtualised time calls (defined by ARM DEN0057A) */
145 #define ARM_SMCCC_HV_PV_TIME_FEATURES				\
146 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
147 			   ARM_SMCCC_SMC_64,			\
148 			   ARM_SMCCC_OWNER_STANDARD_HYP,	\
149 			   0x20)
150 
151 #define ARM_SMCCC_HV_PV_TIME_ST					\
152 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
153 			   ARM_SMCCC_SMC_64,			\
154 			   ARM_SMCCC_OWNER_STANDARD_HYP,	\
155 			   0x21)
156 
157 /* TRNG entropy source calls (defined by ARM DEN0098) */
158 #define ARM_SMCCC_TRNG_VERSION					\
159 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
160 			   ARM_SMCCC_SMC_32,			\
161 			   ARM_SMCCC_OWNER_STANDARD,		\
162 			   0x50)
163 
164 #define ARM_SMCCC_TRNG_FEATURES					\
165 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
166 			   ARM_SMCCC_SMC_32,			\
167 			   ARM_SMCCC_OWNER_STANDARD,		\
168 			   0x51)
169 
170 #define ARM_SMCCC_TRNG_GET_UUID					\
171 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
172 			   ARM_SMCCC_SMC_32,			\
173 			   ARM_SMCCC_OWNER_STANDARD,		\
174 			   0x52)
175 
176 #define ARM_SMCCC_TRNG_RND32					\
177 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
178 			   ARM_SMCCC_SMC_32,			\
179 			   ARM_SMCCC_OWNER_STANDARD,		\
180 			   0x53)
181 
182 #define ARM_SMCCC_TRNG_RND64					\
183 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
184 			   ARM_SMCCC_SMC_64,			\
185 			   ARM_SMCCC_OWNER_STANDARD,		\
186 			   0x53)
187 
188 /*
189  * Return codes defined in ARM DEN 0070A
190  * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C
191  */
192 #define SMCCC_RET_SUCCESS			0
193 #define SMCCC_RET_NOT_SUPPORTED			-1
194 #define SMCCC_RET_NOT_REQUIRED			-2
195 #define SMCCC_RET_INVALID_PARAMETER		-3
196 
197 #ifndef __ASSEMBLY__
198 
199 #include <linux/linkage.h>
200 #include <linux/types.h>
201 
202 enum arm_smccc_conduit {
203 	SMCCC_CONDUIT_NONE,
204 	SMCCC_CONDUIT_SMC,
205 	SMCCC_CONDUIT_HVC,
206 };
207 
208 /**
209  * arm_smccc_1_1_get_conduit()
210  *
211  * Returns the conduit to be used for SMCCCv1.1 or later.
212  *
213  * When SMCCCv1.1 is not present, returns SMCCC_CONDUIT_NONE.
214  */
215 enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void);
216 
217 /**
218  * arm_smccc_get_version()
219  *
220  * Returns the version to be used for SMCCCv1.1 or later.
221  *
222  * When SMCCCv1.1 or above is not present, returns SMCCCv1.0, but this
223  * does not imply the presence of firmware or a valid conduit. Caller
224  * handling SMCCCv1.0 must determine the conduit by other means.
225  */
226 u32 arm_smccc_get_version(void);
227 
228 void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit);
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_smc() - make SMC calls
329  * @a0-a7: arguments passed in registers 0 to 7
330  * @res: result values from registers 0 to 3
331  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
332  *
333  * This function is used to make SMC calls following SMC Calling Convention.
334  * The content of the supplied param are copied to registers 0 to 7 prior
335  * to the SMC instruction. The return values are updated with the content
336  * from register 0 to 3 on return from the SMC instruction.  An optional
337  * quirk structure provides vendor specific behavior.
338  */
339 #ifdef CONFIG_HAVE_ARM_SMCCC
340 asmlinkage void __arm_smccc_smc(unsigned long a0, unsigned long a1,
341 			unsigned long a2, unsigned long a3, unsigned long a4,
342 			unsigned long a5, unsigned long a6, unsigned long a7,
343 			struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
344 #else
__arm_smccc_smc(unsigned long a0,unsigned long a1,unsigned long a2,unsigned long a3,unsigned long a4,unsigned long a5,unsigned long a6,unsigned long a7,struct arm_smccc_res * res,struct arm_smccc_quirk * quirk)345 static inline void __arm_smccc_smc(unsigned long a0, unsigned long a1,
346 			unsigned long a2, unsigned long a3, unsigned long a4,
347 			unsigned long a5, unsigned long a6, unsigned long a7,
348 			struct arm_smccc_res *res, struct arm_smccc_quirk *quirk)
349 {
350 	*res = (struct arm_smccc_res){};
351 }
352 #endif
353 
354 /**
355  * __arm_smccc_hvc() - make HVC calls
356  * @a0-a7: arguments passed in registers 0 to 7
357  * @res: result values from registers 0 to 3
358  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
359  *
360  * This function is used to make HVC calls following SMC Calling
361  * Convention.  The content of the supplied param are copied to registers 0
362  * to 7 prior to the HVC instruction. The return values are updated with
363  * the content from register 0 to 3 on return from the HVC instruction.  An
364  * optional quirk structure provides vendor specific behavior.
365  */
366 asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
367 			unsigned long a2, unsigned long a3, unsigned long a4,
368 			unsigned long a5, unsigned long a6, unsigned long a7,
369 			struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
370 
371 #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
372 
373 #define arm_smccc_smc_quirk(...) __arm_smccc_smc(__VA_ARGS__)
374 
375 #define arm_smccc_hvc(...) __arm_smccc_hvc(__VA_ARGS__, NULL)
376 
377 #define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__)
378 
379 /* SMCCC v1.1 implementation madness follows */
380 #ifdef CONFIG_ARM64
381 
382 #define SMCCC_SMC_INST	"smc	#0"
383 #define SMCCC_HVC_INST	"hvc	#0"
384 
385 #elif defined(CONFIG_ARM)
386 #include <asm/opcodes-sec.h>
387 #include <asm/opcodes-virt.h>
388 
389 #define SMCCC_SMC_INST	__SMC(0)
390 #define SMCCC_HVC_INST	__HVC(0)
391 
392 #endif
393 
394 #define __constraint_read_2	"r" (arg0)
395 #define __constraint_read_3	__constraint_read_2, "r" (arg1)
396 #define __constraint_read_4	__constraint_read_3, "r" (arg2)
397 #define __constraint_read_5	__constraint_read_4, "r" (arg3)
398 #define __constraint_read_6	__constraint_read_5, "r" (arg4)
399 #define __constraint_read_7	__constraint_read_6, "r" (arg5)
400 #define __constraint_read_8	__constraint_read_7, "r" (arg6)
401 #define __constraint_read_9	__constraint_read_8, "r" (arg7)
402 
403 #define __declare_arg_2(a0, res)					\
404 	struct arm_smccc_res   *___res = res;				\
405 	register unsigned long arg0 asm("r0") = (u32)a0
406 
407 #define __declare_arg_3(a0, a1, res)					\
408 	typeof(a1) __a1 = a1;						\
409 	struct arm_smccc_res   *___res = res;				\
410 	register unsigned long arg0 asm("r0") = (u32)a0;			\
411 	register typeof(a1) arg1 asm("r1") = __a1
412 
413 #define __declare_arg_4(a0, a1, a2, res)				\
414 	typeof(a1) __a1 = a1;						\
415 	typeof(a2) __a2 = a2;						\
416 	struct arm_smccc_res   *___res = res;				\
417 	register unsigned long arg0 asm("r0") = (u32)a0;			\
418 	register typeof(a1) arg1 asm("r1") = __a1;			\
419 	register typeof(a2) arg2 asm("r2") = __a2
420 
421 #define __declare_arg_5(a0, a1, a2, a3, res)				\
422 	typeof(a1) __a1 = a1;						\
423 	typeof(a2) __a2 = a2;						\
424 	typeof(a3) __a3 = a3;						\
425 	struct arm_smccc_res   *___res = res;				\
426 	register unsigned long arg0 asm("r0") = (u32)a0;			\
427 	register typeof(a1) arg1 asm("r1") = __a1;			\
428 	register typeof(a2) arg2 asm("r2") = __a2;			\
429 	register typeof(a3) arg3 asm("r3") = __a3
430 
431 #define __declare_arg_6(a0, a1, a2, a3, a4, res)			\
432 	typeof(a4) __a4 = a4;						\
433 	__declare_arg_5(a0, a1, a2, a3, res);				\
434 	register typeof(a4) arg4 asm("r4") = __a4
435 
436 #define __declare_arg_7(a0, a1, a2, a3, a4, a5, res)			\
437 	typeof(a5) __a5 = a5;						\
438 	__declare_arg_6(a0, a1, a2, a3, a4, res);			\
439 	register typeof(a5) arg5 asm("r5") = __a5
440 
441 #define __declare_arg_8(a0, a1, a2, a3, a4, a5, a6, res)		\
442 	typeof(a6) __a6 = a6;						\
443 	__declare_arg_7(a0, a1, a2, a3, a4, a5, res);			\
444 	register typeof(a6) arg6 asm("r6") = __a6
445 
446 #define __declare_arg_9(a0, a1, a2, a3, a4, a5, a6, a7, res)		\
447 	typeof(a7) __a7 = a7;						\
448 	__declare_arg_8(a0, a1, a2, a3, a4, a5, a6, res);		\
449 	register typeof(a7) arg7 asm("r7") = __a7
450 
451 /*
452  * We have an output list that is not necessarily used, and GCC feels
453  * entitled to optimise the whole sequence away. "volatile" is what
454  * makes it stick.
455  */
456 #define __arm_smccc_1_1(inst, ...)					\
457 	do {								\
458 		register unsigned long r0 asm("r0");			\
459 		register unsigned long r1 asm("r1");			\
460 		register unsigned long r2 asm("r2");			\
461 		register unsigned long r3 asm("r3"); 			\
462 		CONCATENATE(__declare_arg_,				\
463 			    COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__);	\
464 		asm volatile(inst "\n" :				\
465 			     "=r" (r0), "=r" (r1), "=r" (r2), "=r" (r3)	\
466 			     : CONCATENATE(__constraint_read_,		\
467 					   COUNT_ARGS(__VA_ARGS__))	\
468 			     : "memory");				\
469 		if (___res)						\
470 			*___res = (typeof(*___res)){r0, r1, r2, r3};	\
471 	} while (0)
472 
473 /*
474  * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call
475  *
476  * This is a variadic macro taking one to eight source arguments, and
477  * an optional return structure.
478  *
479  * @a0-a7: arguments passed in registers 0 to 7
480  * @res: result values from registers 0 to 3
481  *
482  * This macro is used to make SMC calls following SMC Calling Convention v1.1.
483  * The content of the supplied param are copied to registers 0 to 7 prior
484  * to the SMC instruction. The return values are updated with the content
485  * from register 0 to 3 on return from the SMC instruction if not NULL.
486  */
487 #define arm_smccc_1_1_smc(...)	__arm_smccc_1_1(SMCCC_SMC_INST, __VA_ARGS__)
488 
489 /*
490  * arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call
491  *
492  * This is a variadic macro taking one to eight source arguments, and
493  * an optional return structure.
494  *
495  * @a0-a7: arguments passed in registers 0 to 7
496  * @res: result values from registers 0 to 3
497  *
498  * This macro is used to make HVC calls following SMC Calling Convention v1.1.
499  * The content of the supplied param are copied to registers 0 to 7 prior
500  * to the HVC instruction. The return values are updated with the content
501  * from register 0 to 3 on return from the HVC instruction if not NULL.
502  */
503 #define arm_smccc_1_1_hvc(...)	__arm_smccc_1_1(SMCCC_HVC_INST, __VA_ARGS__)
504 
505 /*
506  * Like arm_smccc_1_1* but always returns SMCCC_RET_NOT_SUPPORTED.
507  * Used when the SMCCC conduit is not defined. The empty asm statement
508  * avoids compiler warnings about unused variables.
509  */
510 #define __fail_smccc_1_1(...)						\
511 	do {								\
512 		CONCATENATE(__declare_arg_,				\
513 			    COUNT_ARGS(__VA_ARGS__))(__VA_ARGS__);	\
514 		asm ("" :						\
515 		     : CONCATENATE(__constraint_read_,			\
516 				   COUNT_ARGS(__VA_ARGS__))		\
517 		     : "memory");					\
518 		if (___res)						\
519 			___res->a0 = SMCCC_RET_NOT_SUPPORTED;		\
520 	} while (0)
521 
522 /*
523  * arm_smccc_1_1_invoke() - make an SMCCC v1.1 compliant call
524  *
525  * This is a variadic macro taking one to eight source arguments, and
526  * an optional return structure.
527  *
528  * @a0-a7: arguments passed in registers 0 to 7
529  * @res: result values from registers 0 to 3
530  *
531  * This macro will make either an HVC call or an SMC call depending on the
532  * current SMCCC conduit. If no valid conduit is available then -1
533  * (SMCCC_RET_NOT_SUPPORTED) is returned in @res.a0 (if supplied).
534  *
535  * The return value also provides the conduit that was used.
536  */
537 #define arm_smccc_1_1_invoke(...) ({					\
538 		int method = arm_smccc_1_1_get_conduit();		\
539 		switch (method) {					\
540 		case SMCCC_CONDUIT_HVC:					\
541 			arm_smccc_1_1_hvc(__VA_ARGS__);			\
542 			break;						\
543 		case SMCCC_CONDUIT_SMC:					\
544 			arm_smccc_1_1_smc(__VA_ARGS__);			\
545 			break;						\
546 		default:						\
547 			__fail_smccc_1_1(__VA_ARGS__);			\
548 			method = SMCCC_CONDUIT_NONE;			\
549 			break;						\
550 		}							\
551 		method;							\
552 	})
553 
554 #endif /*__ASSEMBLY__*/
555 #endif /*__LINUX_ARM_SMCCC_H*/
556