xref: /freebsd/sys/dev/psci/smccc.h (revision 511ae023fb33f9e354b5e57b8db7c9c93a43be6b)
1f651b525SAndrew Turner /*-
2f651b525SAndrew Turner  * SPDX-License-Identifier: BSD-2-Clause
3f651b525SAndrew Turner  *
4f651b525SAndrew Turner  * Copyright (c) 2018 Andrew Turner
5f651b525SAndrew Turner  *
6f651b525SAndrew Turner  * This software was developed by SRI International and the University of
7f651b525SAndrew Turner  * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
8f651b525SAndrew Turner  * ("CTSRD"), as part of the DARPA CRASH research programme.
9f651b525SAndrew Turner  *
10f651b525SAndrew Turner  * Redistribution and use in source and binary forms, with or without
11f651b525SAndrew Turner  * modification, are permitted provided that the following conditions
12f651b525SAndrew Turner  * are met:
13f651b525SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
14f651b525SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
15f651b525SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright
16f651b525SAndrew Turner  *    notice, this list of conditions and the following disclaimer in the
17f651b525SAndrew Turner  *    documentation and/or other materials provided with the distribution.
18f651b525SAndrew Turner  *
19f651b525SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20f651b525SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21f651b525SAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22f651b525SAndrew Turner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23f651b525SAndrew Turner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24f651b525SAndrew Turner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25f651b525SAndrew Turner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26f651b525SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27f651b525SAndrew Turner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28f651b525SAndrew Turner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29f651b525SAndrew Turner  * SUCH DAMAGE.
30f651b525SAndrew Turner  */
31f651b525SAndrew Turner 
32f651b525SAndrew Turner #ifndef	_PSCI_SMCCC_H_
33f651b525SAndrew Turner #define	_PSCI_SMCCC_H_
34f651b525SAndrew Turner 
35*511ae023SAndrew Turner #define	SMCCC_MAKE_VERSION(maj, min)	((maj) << 16 | (min))
36f651b525SAndrew Turner #define	SMCCC_VERSION_MAJOR(ver)	(((ver) >> 16) & 0x7fff)
37f651b525SAndrew Turner #define	SMCCC_VERSION_MINOR(ver)	((ver) & 0xffff)
38f651b525SAndrew Turner 
39f651b525SAndrew Turner #define	SMCCC_FUNC_ID(type, call_conv, range, func)	\
40f651b525SAndrew Turner 	(((type) << 31) |				\
41f651b525SAndrew Turner 	 ((call_conv) << 30) |				\
42f651b525SAndrew Turner 	 (((range) & 0x3f) << 24) |				\
43f651b525SAndrew Turner 	 ((func) & 0xffff))
44f651b525SAndrew Turner 
45f651b525SAndrew Turner #define	SMCCC_YIELDING_CALL	0
46f651b525SAndrew Turner #define	SMCCC_FAST_CALL		1
47f651b525SAndrew Turner 
48f651b525SAndrew Turner #define	SMCCC_32BIT_CALL	0
49f651b525SAndrew Turner #define	SMCCC_64BIT_CALL	1
50f651b525SAndrew Turner 
517722d8c7SRuslan Bukin #define	SMCCC_ARM_ARCH_CALLS		0
527722d8c7SRuslan Bukin #define	SMCCC_CPU_SERVICE_CALLS		1
537722d8c7SRuslan Bukin #define	SMCCC_SIP_SERVICE_CALLS		2
547722d8c7SRuslan Bukin #define	SMCCC_OEM_SERVICE_CALLS		3
557722d8c7SRuslan Bukin #define	SMCCC_STD_SECURE_SERVICE_CALLS	4
567722d8c7SRuslan Bukin #define	SMCCC_STD_HYP_SERVICE_CALLS	5
577722d8c7SRuslan Bukin #define	SMCCC_VENDOR_HYP_SERVICE_CALLS	6
587722d8c7SRuslan Bukin 
597722d8c7SRuslan Bukin struct arm_smccc_res {
607722d8c7SRuslan Bukin 	register_t a0;
617722d8c7SRuslan Bukin 	register_t a1;
627722d8c7SRuslan Bukin 	register_t a2;
637722d8c7SRuslan Bukin 	register_t a3;
647722d8c7SRuslan Bukin };
657722d8c7SRuslan Bukin 
6609d1a08dSAndrew Turner /*
6709d1a08dSAndrew Turner  * Arm Architecture Calls.
6809d1a08dSAndrew Turner  * These are documented in the document ARM DEN 0070A.
6909d1a08dSAndrew Turner  */
70f651b525SAndrew Turner #define	SMCCC_VERSION							\
7195c4b3c7SAndrew Turner     SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0)
72f651b525SAndrew Turner #define	SMCCC_ARCH_FEATURES						\
7395c4b3c7SAndrew Turner     SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 1)
74f651b525SAndrew Turner #define	SMCCC_ARCH_WORKAROUND_1						\
7595c4b3c7SAndrew Turner     SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0x8000)
760594061eSAndrew Turner #define	SMCCC_ARCH_WORKAROUND_2						\
770594061eSAndrew Turner     SMCCC_FUNC_ID(SMCCC_FAST_CALL, SMCCC_32BIT_CALL, 0, 0x7fff)
78f651b525SAndrew Turner 
7909d1a08dSAndrew Turner /* The return values from ARM DEN 0070A. */
8009d1a08dSAndrew Turner #define	SMCCC_RET_SUCCESS		0
8109d1a08dSAndrew Turner #define	SMCCC_RET_NOT_SUPPORTED		-1
8209d1a08dSAndrew Turner #define	SMCCC_RET_NOT_REQUIRED		-2
8309d1a08dSAndrew Turner 
840600af1fSAndrew Turner void smccc_init(void);
850600af1fSAndrew Turner uint32_t smccc_get_version(void);
86f651b525SAndrew Turner int32_t smccc_arch_features(uint32_t);
87f651b525SAndrew Turner int smccc_arch_workaround_1(void);
88100a6d19SAndrew Turner int smccc_arch_workaround_2(int);
89f651b525SAndrew Turner 
907722d8c7SRuslan Bukin int arm_smccc_smc(register_t, register_t, register_t, register_t, register_t,
917722d8c7SRuslan Bukin     register_t, register_t, register_t, struct arm_smccc_res *res);
927722d8c7SRuslan Bukin int arm_smccc_hvc(register_t, register_t, register_t, register_t, register_t,
937722d8c7SRuslan Bukin     register_t, register_t, register_t, struct arm_smccc_res *res);
94f651b525SAndrew Turner 
95e4c35361SAndrew Turner #define	arm_smccc_invoke_1(func, a0, res)				\
96e4c35361SAndrew Turner     func(a0,  0,  0,  0,  0,  0,  0,  0, res)
97e4c35361SAndrew Turner #define	arm_smccc_invoke_2(func, a0, a1, res)				\
98e4c35361SAndrew Turner     func(a0, a1,  0,  0,  0,  0,  0,  0, res)
99e4c35361SAndrew Turner #define	arm_smccc_invoke_3(func, a0, a1, a2, res)			\
100e4c35361SAndrew Turner     func(a0, a1, a2,  0,  0,  0,  0,  0, res)
101e4c35361SAndrew Turner #define	arm_smccc_invoke_4(func, a0, a1, a2, a3, res)			\
102e4c35361SAndrew Turner     func(a0, a1, a2, a3,  0,  0,  0,  0, res)
103e4c35361SAndrew Turner #define	arm_smccc_invoke_5(func, a0, a1, a2, a3, a4, res)		\
104e4c35361SAndrew Turner     func(a0, a1, a2, a3, a4,  0,  0,  0, res)
105e4c35361SAndrew Turner #define	arm_smccc_invoke_6(func, a0, a1, a2, a3, a4, a5, res)		\
106e4c35361SAndrew Turner     func(a0, a1, a2, a3, a4, a5,  0,  0, res)
107e4c35361SAndrew Turner #define	arm_smccc_invoke_7(func, a0, a1, a2, a3, a4, a5, a6, res)	\
108e4c35361SAndrew Turner     func(a0, a1, a2, a3, a4, a5, a6,  0, res)
109e4c35361SAndrew Turner #define	arm_smccc_invoke_8(func, a0, a1, a2, a3, a4, a5, a6, a7, res)	\
110e4c35361SAndrew Turner     func(a0, a1, a2, a3, a4, a5, a6, a7, res)
111e4c35361SAndrew Turner 
112e4c35361SAndrew Turner #define	_arm_smccc_invoke_macro(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) \
113e4c35361SAndrew Turner     NAME
114e4c35361SAndrew Turner #define	_arm_smccc_invoke(func, a0, ...)				\
115e4c35361SAndrew Turner     _arm_smccc_invoke_macro(__VA_ARGS__, arm_smccc_invoke_8,		\
116e4c35361SAndrew Turner       arm_smccc_invoke_7, arm_smccc_invoke_6, arm_smccc_invoke_5,	\
117e4c35361SAndrew Turner       arm_smccc_invoke_4, arm_smccc_invoke_3, arm_smccc_invoke_2,	\
118e4c35361SAndrew Turner       arm_smccc_invoke_1)(func, a0, __VA_ARGS__)
119e4c35361SAndrew Turner 
120e4c35361SAndrew Turner #define	arm_smccc_invoke_hvc(a0, ...)					\
121e4c35361SAndrew Turner     _arm_smccc_invoke(arm_smccc_hvc, a0, __VA_ARGS__)
122e4c35361SAndrew Turner #define	arm_smccc_invoke_smc(a0, ...)					\
123e4c35361SAndrew Turner     _arm_smccc_invoke(arm_smccc_smc, a0, __VA_ARGS__)
124e4c35361SAndrew Turner #define	arm_smccc_invoke(a0, ...)					\
125e4c35361SAndrew Turner     _arm_smccc_invoke(psci_callfn, a0, __VA_ARGS__)
126e4c35361SAndrew Turner 
1277a58bf04SWei Hu struct arm_smccc_1_2_regs {
1287a58bf04SWei Hu 	register_t a0;
1297a58bf04SWei Hu 	register_t a1;
1307a58bf04SWei Hu 	register_t a2;
1317a58bf04SWei Hu 	register_t a3;
1327a58bf04SWei Hu 	register_t a4;
1337a58bf04SWei Hu 	register_t a5;
1347a58bf04SWei Hu 	register_t a6;
1357a58bf04SWei Hu 	register_t a7;
1367a58bf04SWei Hu 	register_t a8;
1377a58bf04SWei Hu 	register_t a9;
1387a58bf04SWei Hu 	register_t a10;
1397a58bf04SWei Hu 	register_t a11;
1407a58bf04SWei Hu 	register_t a12;
1417a58bf04SWei Hu 	register_t a13;
1427a58bf04SWei Hu 	register_t a14;
1437a58bf04SWei Hu 	register_t a15;
1447a58bf04SWei Hu 	register_t a16;
1457a58bf04SWei Hu 	register_t a17;
1467a58bf04SWei Hu };
1477a58bf04SWei Hu 
1487a58bf04SWei Hu int arm_smccc_1_2_hvc(const struct arm_smccc_1_2_regs *args,
1497a58bf04SWei Hu     struct arm_smccc_1_2_regs *res);
1507a58bf04SWei Hu int arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
1517a58bf04SWei Hu     struct arm_smccc_1_2_regs *res);
152f651b525SAndrew Turner #endif /* _PSCI_SMCCC_H_ */
153