xref: /rk3399_ARM-atf/include/services/rmmd_svc.h (revision e50fedbc869341d044d4cb3479a0ab3d4edaf225)
177c27753SZelalem Aweke /*
2fb00dc4aSSubhasish 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 
13fb00dc4aSSubhasish 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 
17fb00dc4aSSubhasish Ghosh /* Construct RMI fastcall std FID from offset */
18fb00dc4aSSubhasish Ghosh #define SMC64_RMI_FID(_offset)					  \
19fb00dc4aSSubhasish Ghosh 	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)			| \
20fb00dc4aSSubhasish Ghosh 	 (SMC_64 << FUNCID_CC_SHIFT)				| \
21fb00dc4aSSubhasish Ghosh 	 (OEN_STD_START << FUNCID_OEN_SHIFT)			| \
22fb00dc4aSSubhasish Ghosh 	 (((RMI_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK)	  \
23fb00dc4aSSubhasish Ghosh 	  << FUNCID_NUM_SHIFT))
24fb00dc4aSSubhasish 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 /*
35fb00dc4aSSubhasish 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
38fb00dc4aSSubhasish Ghosh  * RMM.
39319fb084SSoby Mathew  */
40fb00dc4aSSubhasish Ghosh 					/* 0x18F */
41*e50fedbcSJavier Almansa Sobrino #define RMM_RMI_REQ_COMPLETE		SMC64_RMI_FID(U(0x3F))
42319fb084SSoby Mathew 
438c980a4aSJavier Almansa Sobrino /* RMM_BOOT_COMPLETE arg0 error codes */
448c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_SUCCESS				(0)
458c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_UNKNOWN				(-1)
468c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_VERSION_MISMATCH			(-2)
478c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_CPUS_OUT_OF_RANGE			(-3)
488c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_CPU_ID_OUT_OF_RANGE			(-4)
498c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_INVALID_SHARED_BUFFER		(-5)
508c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_MANIFEST_VERSION_NOT_SUPPORTED	(-6)
518c980a4aSJavier Almansa Sobrino #define E_RMM_BOOT_MANIFEST_DATA_ERROR			(-7)
528c980a4aSJavier Almansa Sobrino 
538c980a4aSJavier Almansa Sobrino /* The SMC in the range 0x8400 0191 - 0x8400 01AF are reserved for RSIs.*/
54319fb084SSoby Mathew 
55319fb084SSoby Mathew /*
56319fb084SSoby Mathew  * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
57319fb084SSoby Mathew  * world and return to Realm world.
58319fb084SSoby Mathew  *
59319fb084SSoby Mathew  * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
60319fb084SSoby Mathew  */
61319fb084SSoby Mathew #define RMMD_EL3_FNUM_MIN_VALUE		U(0x1B0)
62319fb084SSoby Mathew #define RMMD_EL3_FNUM_MAX_VALUE		U(0x1CF)
63319fb084SSoby Mathew 
64fb00dc4aSSubhasish Ghosh /* Construct RMM_EL3 fastcall std FID from offset */
65fb00dc4aSSubhasish Ghosh #define SMC64_RMMD_EL3_FID(_offset)					  \
66fb00dc4aSSubhasish Ghosh 	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)				| \
67fb00dc4aSSubhasish Ghosh 	 (SMC_64 << FUNCID_CC_SHIFT)					| \
68fb00dc4aSSubhasish Ghosh 	 (OEN_STD_START << FUNCID_OEN_SHIFT)				| \
69fb00dc4aSSubhasish Ghosh 	 (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK)	  \
70fb00dc4aSSubhasish Ghosh 	  << FUNCID_NUM_SHIFT))
71fb00dc4aSSubhasish Ghosh 
72319fb084SSoby Mathew /* The macros below are used to identify GTSI calls from the SMC function ID */
73319fb084SSoby Mathew #define is_rmmd_el3_fid(fid) __extension__ ({		\
74319fb084SSoby Mathew 	__typeof__(fid) _fid = (fid);			\
75319fb084SSoby Mathew 	((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
76319fb084SSoby Mathew 	(GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE)  &&\
77319fb084SSoby Mathew 	(GET_SMC_TYPE(_fid) == SMC_TYPE_FAST)	    &&	\
78319fb084SSoby Mathew 	(GET_SMC_CC(_fid) == SMC_64)                &&	\
79319fb084SSoby Mathew 	(GET_SMC_OEN(_fid) == OEN_STD_START)        &&	\
80319fb084SSoby Mathew 	((_fid & 0x00FE0000) == 0U)); })
81319fb084SSoby Mathew 
82fb00dc4aSSubhasish Ghosh 					/* 0x1B0 - 0x1B1 */
83*e50fedbcSJavier Almansa Sobrino #define RMM_GTSI_DELEGATE		SMC64_RMMD_EL3_FID(U(0))
84*e50fedbcSJavier Almansa Sobrino #define RMM_GTSI_UNDELEGATE		SMC64_RMMD_EL3_FID(U(1))
85319fb084SSoby Mathew 
86319fb084SSoby Mathew /* Return error codes from RMM-EL3 SMCs */
87dc65ae46SJavier Almansa Sobrino #define E_RMM_OK			 0
88dc65ae46SJavier Almansa Sobrino #define E_RMM_UNK			-1
89dc65ae46SJavier Almansa Sobrino #define E_RMM_BAD_ADDR			-2
90dc65ae46SJavier Almansa Sobrino #define E_RMM_BAD_PAS			-3
91dc65ae46SJavier Almansa Sobrino #define E_RMM_NOMEM			-4
92dc65ae46SJavier Almansa Sobrino #define E_RMM_INVAL			-5
93319fb084SSoby Mathew 
940f9159b7SSoby Mathew /* Acceptable SHA sizes for Challenge object */
950f9159b7SSoby Mathew #define SHA256_DIGEST_SIZE	32U
960f9159b7SSoby Mathew #define SHA384_DIGEST_SIZE	48U
970f9159b7SSoby Mathew #define SHA512_DIGEST_SIZE	64U
980f9159b7SSoby Mathew 
99a0435105SSoby Mathew /*
100a0435105SSoby Mathew  * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
101a0435105SSoby Mathew  * supported. The arguments to this SMC are :
102a0435105SSoby Mathew  *    arg0 - Function ID.
103a0435105SSoby Mathew  *    arg1 - Realm attestation key buffer Physical address.
104a0435105SSoby Mathew  *    arg2 - Realm attestation key buffer size (in bytes).
105a0435105SSoby Mathew  *    arg3 - The type of the elliptic curve to which the requested
106a0435105SSoby Mathew  *           attestation key belongs to. The value should be one of the
107a0435105SSoby Mathew  *           defined curve types.
108a0435105SSoby Mathew  * The return arguments are :
109a0435105SSoby Mathew  *    ret0 - Status / error.
110a0435105SSoby Mathew  *    ret1 - Size of the realm attestation key if successful.
111a0435105SSoby Mathew  */
112fb00dc4aSSubhasish Ghosh 					/* 0x1B2 */
113*e50fedbcSJavier Almansa Sobrino #define RMM_ATTEST_GET_REALM_KEY	SMC64_RMMD_EL3_FID(U(2))
114fb00dc4aSSubhasish Ghosh 
115fb00dc4aSSubhasish Ghosh /*
116fb00dc4aSSubhasish Ghosh  * Retrieve Platform token from EL3.
117fb00dc4aSSubhasish Ghosh  * The arguments to this SMC are :
118fb00dc4aSSubhasish Ghosh  *    arg0 - Function ID.
119fb00dc4aSSubhasish Ghosh  *    arg1 - Platform attestation token buffer Physical address. (The challenge
120fb00dc4aSSubhasish Ghosh  *           object is passed in this buffer.)
121fb00dc4aSSubhasish Ghosh  *    arg2 - Platform attestation token buffer size (in bytes).
122fb00dc4aSSubhasish Ghosh  *    arg3 - Challenge object size (in bytes). It has to be one of the defined
123fb00dc4aSSubhasish Ghosh  *           SHA hash sizes.
124fb00dc4aSSubhasish Ghosh  * The return arguments are :
125fb00dc4aSSubhasish Ghosh  *    ret0 - Status / error.
126fb00dc4aSSubhasish Ghosh  *    ret1 - Size of the platform token if successful.
127fb00dc4aSSubhasish Ghosh  */
128fb00dc4aSSubhasish Ghosh 					/* 0x1B3 */
129*e50fedbcSJavier Almansa Sobrino #define RMM_ATTEST_GET_PLAT_TOKEN	SMC64_RMMD_EL3_FID(U(3))
130a0435105SSoby Mathew 
131a0435105SSoby Mathew /* ECC Curve types for attest key generation */
132a0435105SSoby Mathew #define ATTEST_KEY_CURVE_ECC_SECP384R1		0
133a0435105SSoby Mathew 
1348c980a4aSJavier Almansa Sobrino /*
1358c980a4aSJavier Almansa Sobrino  * RMM_BOOT_COMPLETE originates on RMM when the boot finishes (either cold
1368c980a4aSJavier Almansa Sobrino  * or warm boot). This is handled by the RMM-EL3 interface SMC handler.
1378c980a4aSJavier Almansa Sobrino  *
1388c980a4aSJavier Almansa Sobrino  * RMM_BOOT_COMPLETE FID is located at the end of the available range.
1398c980a4aSJavier Almansa Sobrino  */
1408c980a4aSJavier Almansa Sobrino 					 /* 0x1CF */
1418c980a4aSJavier Almansa Sobrino #define RMM_BOOT_COMPLETE		SMC64_RMMD_EL3_FID(U(0x1F))
1428c980a4aSJavier Almansa Sobrino 
1438c980a4aSJavier Almansa Sobrino /*
1448c980a4aSJavier Almansa Sobrino  * The major version number of the RMM Boot Interface implementation.
1458c980a4aSJavier Almansa Sobrino  * Increase this whenever the semantics of the boot arguments change making it
1468c980a4aSJavier Almansa Sobrino  * backwards incompatible.
1478c980a4aSJavier Almansa Sobrino  */
1488c980a4aSJavier Almansa Sobrino #define RMM_EL3_IFC_VERSION_MAJOR	(U(0))
1498c980a4aSJavier Almansa Sobrino 
1508c980a4aSJavier Almansa Sobrino /*
1518c980a4aSJavier Almansa Sobrino  * The minor version number of the RMM Boot Interface implementation.
1528c980a4aSJavier Almansa Sobrino  * Increase this when a bug is fixed, or a feature is added without
1538c980a4aSJavier Almansa Sobrino  * breaking compatibility.
1548c980a4aSJavier Almansa Sobrino  */
1558c980a4aSJavier Almansa Sobrino #define RMM_EL3_IFC_VERSION_MINOR	(U(1))
1568c980a4aSJavier Almansa Sobrino 
1578c980a4aSJavier Almansa Sobrino #define RMM_EL3_INTERFACE_VERSION				\
1588c980a4aSJavier Almansa Sobrino 	(((RMM_EL3_IFC_VERSION_MAJOR << 16) & 0x7FFFF) |	\
1598c980a4aSJavier Almansa Sobrino 		RMM_EL3_IFC_VERSION_MINOR)
1608c980a4aSJavier Almansa Sobrino 
1618c980a4aSJavier Almansa Sobrino #define RMM_EL3_IFC_VERSION_GET_MAJOR(_version) (((_version) >> 16) \
1628c980a4aSJavier Almansa Sobrino 								& 0x7FFF)
1638c980a4aSJavier Almansa Sobrino #define RMM_EL3_IFC_VERSION_GET_MAJOR_MINOR(_version) ((_version) & 0xFFFF)
164a0435105SSoby Mathew 
16577c27753SZelalem Aweke #ifndef __ASSEMBLER__
16677c27753SZelalem Aweke #include <stdint.h>
16777c27753SZelalem Aweke 
16877c27753SZelalem Aweke int rmmd_setup(void);
16977c27753SZelalem Aweke uint64_t rmmd_rmi_handler(uint32_t smc_fid,
17077c27753SZelalem Aweke 		uint64_t x1,
17177c27753SZelalem Aweke 		uint64_t x2,
17277c27753SZelalem Aweke 		uint64_t x3,
17377c27753SZelalem Aweke 		uint64_t x4,
17477c27753SZelalem Aweke 		void *cookie,
17577c27753SZelalem Aweke 		void *handle,
17677c27753SZelalem Aweke 		uint64_t flags);
17777c27753SZelalem Aweke 
178319fb084SSoby Mathew uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
17977c27753SZelalem Aweke 		uint64_t x1,
18077c27753SZelalem Aweke 		uint64_t x2,
18177c27753SZelalem Aweke 		uint64_t x3,
18277c27753SZelalem Aweke 		uint64_t x4,
18377c27753SZelalem Aweke 		void *cookie,
18477c27753SZelalem Aweke 		void *handle,
18577c27753SZelalem Aweke 		uint64_t flags);
18677c27753SZelalem Aweke 
18777c27753SZelalem Aweke #endif /* __ASSEMBLER__ */
18877c27753SZelalem Aweke #endif /* RMMD_SVC_H */
189