xref: /rk3399_ARM-atf/include/services/rmmd_svc.h (revision fb00dc4a7b208cf416d082bb4367b54286bc8e3b)
177c27753SZelalem Aweke /*
2*fb00dc4aSSubhasish Ghosh  * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
377c27753SZelalem Aweke  *
477c27753SZelalem Aweke  * SPDX-License-Identifier: BSD-3-Clause
577c27753SZelalem Aweke  */
677c27753SZelalem Aweke 
777c27753SZelalem Aweke #ifndef RMMD_SVC_H
877c27753SZelalem Aweke #define RMMD_SVC_H
977c27753SZelalem Aweke 
10319fb084SSoby Mathew #include <lib/smccc.h>
11319fb084SSoby Mathew #include <lib/utils_def.h>
12319fb084SSoby Mathew 
13*fb00dc4aSSubhasish Ghosh /* STD calls FNUM Min/Max ranges */
14319fb084SSoby Mathew #define RMI_FNUM_MIN_VALUE	U(0x150)
15319fb084SSoby Mathew #define RMI_FNUM_MAX_VALUE	U(0x18F)
16319fb084SSoby Mathew 
17*fb00dc4aSSubhasish Ghosh /* Construct RMI fastcall std FID from offset */
18*fb00dc4aSSubhasish Ghosh #define SMC64_RMI_FID(_offset)					  \
19*fb00dc4aSSubhasish Ghosh 	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)			| \
20*fb00dc4aSSubhasish Ghosh 	 (SMC_64 << FUNCID_CC_SHIFT)				| \
21*fb00dc4aSSubhasish Ghosh 	 (OEN_STD_START << FUNCID_OEN_SHIFT)			| \
22*fb00dc4aSSubhasish Ghosh 	 (((RMI_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK)	  \
23*fb00dc4aSSubhasish Ghosh 	  << FUNCID_NUM_SHIFT))
24*fb00dc4aSSubhasish Ghosh 
25319fb084SSoby Mathew #define is_rmi_fid(fid) __extension__ ({		\
26319fb084SSoby Mathew 	__typeof__(fid) _fid = (fid);			\
27319fb084SSoby Mathew 	((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) &&	\
28319fb084SSoby Mathew 	 (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) &&	\
29319fb084SSoby Mathew 	 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)	   &&	\
30319fb084SSoby Mathew 	 (GET_SMC_CC(_fid) == SMC_64)              &&	\
31319fb084SSoby Mathew 	 (GET_SMC_OEN(_fid) == OEN_STD_START)      &&	\
32319fb084SSoby Mathew 	 ((_fid & 0x00FE0000) == 0U)); })
33319fb084SSoby Mathew 
34319fb084SSoby Mathew /*
35*fb00dc4aSSubhasish Ghosh  * RMI_FNUM_REQ_COMPLETE is the only function in the RMI range that originates
36319fb084SSoby Mathew  * from the Realm world and is handled by the RMMD. The RMI functions are
37319fb084SSoby Mathew  * always invoked by the Normal world, forwarded by RMMD and handled by the
38*fb00dc4aSSubhasish Ghosh  * RMM.
39319fb084SSoby Mathew  */
40*fb00dc4aSSubhasish Ghosh 					/* 0x18F */
41*fb00dc4aSSubhasish Ghosh #define RMMD_RMI_REQ_COMPLETE		SMC64_RMI_FID(U(0x3F))
42319fb084SSoby Mathew 
43319fb084SSoby Mathew /* The SMC in the range 0x8400 0190 - 0x8400 01AF are reserved for RSIs.*/
44319fb084SSoby Mathew 
45319fb084SSoby Mathew /*
46319fb084SSoby Mathew  * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
47319fb084SSoby Mathew  * world and return to Realm world.
48319fb084SSoby Mathew  *
49319fb084SSoby Mathew  * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
50319fb084SSoby Mathew  */
51319fb084SSoby Mathew #define RMMD_EL3_FNUM_MIN_VALUE		U(0x1B0)
52319fb084SSoby Mathew #define RMMD_EL3_FNUM_MAX_VALUE		U(0x1CF)
53319fb084SSoby Mathew 
54*fb00dc4aSSubhasish Ghosh /* Construct RMM_EL3 fastcall std FID from offset */
55*fb00dc4aSSubhasish Ghosh #define SMC64_RMMD_EL3_FID(_offset)					  \
56*fb00dc4aSSubhasish Ghosh 	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)				| \
57*fb00dc4aSSubhasish Ghosh 	 (SMC_64 << FUNCID_CC_SHIFT)					| \
58*fb00dc4aSSubhasish Ghosh 	 (OEN_STD_START << FUNCID_OEN_SHIFT)				| \
59*fb00dc4aSSubhasish Ghosh 	 (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK)	  \
60*fb00dc4aSSubhasish Ghosh 	  << FUNCID_NUM_SHIFT))
61*fb00dc4aSSubhasish Ghosh 
62319fb084SSoby Mathew /* The macros below are used to identify GTSI calls from the SMC function ID */
63319fb084SSoby Mathew #define is_rmmd_el3_fid(fid) __extension__ ({		\
64319fb084SSoby Mathew 	__typeof__(fid) _fid = (fid);			\
65319fb084SSoby Mathew 	((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
66319fb084SSoby Mathew 	(GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE)  &&\
67319fb084SSoby Mathew 	(GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)	    &&	\
68319fb084SSoby Mathew 	(GET_SMC_CC(_fid) == SMC_64)                &&	\
69319fb084SSoby Mathew 	(GET_SMC_OEN(_fid) == OEN_STD_START)        &&	\
70319fb084SSoby Mathew 	((_fid & 0x00FE0000) == 0U)); })
71319fb084SSoby Mathew 
72*fb00dc4aSSubhasish Ghosh 					/* 0x1B0 - 0x1B1 */
73*fb00dc4aSSubhasish Ghosh #define RMMD_GTSI_DELEGATE		SMC64_RMMD_EL3_FID(U(0))
74*fb00dc4aSSubhasish Ghosh #define RMMD_GTSI_UNDELEGATE		SMC64_RMMD_EL3_FID(U(1))
75319fb084SSoby Mathew 
76319fb084SSoby Mathew /* Return error codes from RMM-EL3 SMCs */
77319fb084SSoby Mathew #define RMMD_OK				0
78319fb084SSoby Mathew #define RMMD_ERR_BAD_ADDR		-2
79319fb084SSoby Mathew #define RMMD_ERR_BAD_PAS		-3
80319fb084SSoby Mathew #define RMMD_ERR_NOMEM			-4
81319fb084SSoby Mathew #define RMMD_ERR_INVAL			-5
82319fb084SSoby Mathew #define RMMD_ERR_UNK			-6
83319fb084SSoby Mathew 
840f9159b7SSoby Mathew /* Acceptable SHA sizes for Challenge object */
850f9159b7SSoby Mathew #define SHA256_DIGEST_SIZE	32U
860f9159b7SSoby Mathew #define SHA384_DIGEST_SIZE	48U
870f9159b7SSoby Mathew #define SHA512_DIGEST_SIZE	64U
880f9159b7SSoby Mathew 
89a0435105SSoby Mathew /*
90a0435105SSoby Mathew  * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
91a0435105SSoby Mathew  * supported. The arguments to this SMC are :
92a0435105SSoby Mathew  *    arg0 - Function ID.
93a0435105SSoby Mathew  *    arg1 - Realm attestation key buffer Physical address.
94a0435105SSoby Mathew  *    arg2 - Realm attestation key buffer size (in bytes).
95a0435105SSoby Mathew  *    arg3 - The type of the elliptic curve to which the requested
96a0435105SSoby Mathew  *           attestation key belongs to. The value should be one of the
97a0435105SSoby Mathew  *           defined curve types.
98a0435105SSoby Mathew  * The return arguments are :
99a0435105SSoby Mathew  *    ret0 - Status / error.
100a0435105SSoby Mathew  *    ret1 - Size of the realm attestation key if successful.
101a0435105SSoby Mathew  */
102*fb00dc4aSSubhasish Ghosh 					/* 0x1B2 */
103*fb00dc4aSSubhasish Ghosh #define RMMD_ATTEST_GET_REALM_KEY	SMC64_RMMD_EL3_FID(U(2))
104*fb00dc4aSSubhasish Ghosh 
105*fb00dc4aSSubhasish Ghosh /*
106*fb00dc4aSSubhasish Ghosh  * Retrieve Platform token from EL3.
107*fb00dc4aSSubhasish Ghosh  * The arguments to this SMC are :
108*fb00dc4aSSubhasish Ghosh  *    arg0 - Function ID.
109*fb00dc4aSSubhasish Ghosh  *    arg1 - Platform attestation token buffer Physical address. (The challenge
110*fb00dc4aSSubhasish Ghosh  *           object is passed in this buffer.)
111*fb00dc4aSSubhasish Ghosh  *    arg2 - Platform attestation token buffer size (in bytes).
112*fb00dc4aSSubhasish Ghosh  *    arg3 - Challenge object size (in bytes). It has to be one of the defined
113*fb00dc4aSSubhasish Ghosh  *           SHA hash sizes.
114*fb00dc4aSSubhasish Ghosh  * The return arguments are :
115*fb00dc4aSSubhasish Ghosh  *    ret0 - Status / error.
116*fb00dc4aSSubhasish Ghosh  *    ret1 - Size of the platform token if successful.
117*fb00dc4aSSubhasish Ghosh  */
118*fb00dc4aSSubhasish Ghosh 					/* 0x1B3 */
119*fb00dc4aSSubhasish Ghosh #define RMMD_ATTEST_GET_PLAT_TOKEN	SMC64_RMMD_EL3_FID(U(3))
120a0435105SSoby Mathew 
121a0435105SSoby Mathew /* ECC Curve types for attest key generation */
122a0435105SSoby Mathew #define ATTEST_KEY_CURVE_ECC_SECP384R1		0
123a0435105SSoby Mathew 
124a0435105SSoby Mathew 
12577c27753SZelalem Aweke #ifndef __ASSEMBLER__
12677c27753SZelalem Aweke #include <stdint.h>
12777c27753SZelalem Aweke 
12877c27753SZelalem Aweke int rmmd_setup(void);
12977c27753SZelalem Aweke uint64_t rmmd_rmi_handler(uint32_t smc_fid,
13077c27753SZelalem Aweke 		uint64_t x1,
13177c27753SZelalem Aweke 		uint64_t x2,
13277c27753SZelalem Aweke 		uint64_t x3,
13377c27753SZelalem Aweke 		uint64_t x4,
13477c27753SZelalem Aweke 		void *cookie,
13577c27753SZelalem Aweke 		void *handle,
13677c27753SZelalem Aweke 		uint64_t flags);
13777c27753SZelalem Aweke 
138319fb084SSoby Mathew uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
13977c27753SZelalem Aweke 		uint64_t x1,
14077c27753SZelalem Aweke 		uint64_t x2,
14177c27753SZelalem Aweke 		uint64_t x3,
14277c27753SZelalem Aweke 		uint64_t x4,
14377c27753SZelalem Aweke 		void *cookie,
14477c27753SZelalem Aweke 		void *handle,
14577c27753SZelalem Aweke 		uint64_t flags);
14677c27753SZelalem Aweke 
14777c27753SZelalem Aweke #endif /* __ASSEMBLER__ */
14877c27753SZelalem Aweke #endif /* RMMD_SVC_H */
149