xref: /rk3399_ARM-atf/include/services/drtm_svc.h (revision e62748e3f1f16934f0ef2d5742f3ca0b125eaea2)
1 /*
2  * Copyright (c) 2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier:    BSD-3-Clause
5  *
6  * DRTM service
7  *
8  * Authors:
9  *	Lucian Paul-Trifu <lucian.paultrifu@gmail.com>
10  *	Brian Nezvadovitz <brinez@microsoft.com> 2021-02-01
11  *
12  */
13 
14 #ifndef ARM_DRTM_SVC_H
15 #define ARM_DRTM_SVC_H
16 
17 /*
18  * SMC function IDs for DRTM Service
19  * Upper word bits set: Fast call, SMC64, Standard Secure Svc. Call (OEN = 4)
20  */
21 #define DRTM_FID(func_num)				\
22 	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) |		\
23 	(SMC_64 << FUNCID_CC_SHIFT) |			\
24 	(OEN_STD_START << FUNCID_OEN_SHIFT) |		\
25 	((func_num) << FUNCID_NUM_SHIFT))
26 
27 #define DRTM_FNUM_SVC_VERSION		U(0x110)
28 #define DRTM_FNUM_SVC_FEATURES		U(0x111)
29 #define DRTM_FNUM_SVC_UNPROTECT_MEM	U(0x113)
30 #define DRTM_FNUM_SVC_DYNAMIC_LAUNCH	U(0x114)
31 #define DRTM_FNUM_SVC_CLOSE_LOCALITY	U(0x115)
32 #define DRTM_FNUM_SVC_GET_ERROR		U(0x116)
33 #define DRTM_FNUM_SVC_SET_ERROR		U(0x117)
34 #define DRTM_FNUM_SVC_SET_TCB_HASH	U(0x118)
35 #define DRTM_FNUM_SVC_LOCK_TCB_HASH	U(0x119)
36 
37 #define ARM_DRTM_SVC_VERSION		DRTM_FID(DRTM_FNUM_SVC_VERSION)
38 #define ARM_DRTM_SVC_FEATURES		DRTM_FID(DRTM_FNUM_SVC_FEATURES)
39 #define ARM_DRTM_SVC_UNPROTECT_MEM	DRTM_FID(DRTM_FNUM_SVC_UNPROTECT_MEM)
40 #define ARM_DRTM_SVC_DYNAMIC_LAUNCH	DRTM_FID(DRTM_FNUM_SVC_DYNAMIC_LAUNCH)
41 #define ARM_DRTM_SVC_CLOSE_LOCALITY	DRTM_FID(DRTM_FNUM_SVC_CLOSE_LOCALITY)
42 #define ARM_DRTM_SVC_GET_ERROR		DRTM_FID(DRTM_FNUM_SVC_GET_ERROR)
43 #define ARM_DRTM_SVC_SET_ERROR		DRTM_FID(DRTM_FNUM_SVC_SET_ERROR)
44 #define ARM_DRTM_SVC_SET_TCB_HASH	DRTM_FID(DRTM_FNUM_SVC_SET_TCB_HASH)
45 #define ARM_DRTM_SVC_LOCK_TCB_HASH	DRTM_FID(DRTM_FNUM_SVC_LOCK_TCB_HASH)
46 
47 #define is_drtm_fid(_fid) \
48 	(((_fid) >= ARM_DRTM_SVC_VERSION) && ((_fid) <= ARM_DRTM_SVC_LOCK_TCB_HASH))
49 
50 /* ARM DRTM Service Calls version numbers */
51 #define ARM_DRTM_VERSION_MAJOR		U(0)
52 #define ARM_DRTM_VERSION_MAJOR_SHIFT	16
53 #define ARM_DRTM_VERSION_MAJOR_MASK	U(0x7FFF)
54 #define ARM_DRTM_VERSION_MINOR		U(1)
55 #define ARM_DRTM_VERSION_MINOR_SHIFT	0
56 #define ARM_DRTM_VERSION_MINOR_MASK	U(0xFFFF)
57 
58 #define ARM_DRTM_VERSION						\
59 	((((ARM_DRTM_VERSION_MAJOR) & ARM_DRTM_VERSION_MAJOR_MASK) <<	\
60 	ARM_DRTM_VERSION_MAJOR_SHIFT)					\
61 	| (((ARM_DRTM_VERSION_MINOR) & ARM_DRTM_VERSION_MINOR_MASK) <<	\
62 	ARM_DRTM_VERSION_MINOR_SHIFT))
63 
64 #define ARM_DRTM_FUNC_SHIFT	U(63)
65 #define ARM_DRTM_FUNC_MASK	U(0x1)
66 #define ARM_DRTM_FUNC_ID	U(0x0)
67 #define ARM_DRTM_FEAT_ID	U(0x1)
68 
69 /* Initialization routine for the DRTM service */
70 int drtm_setup(void);
71 
72 /* Handler to be called to handle DRTM SMC calls */
73 uint64_t drtm_smc_handler(uint32_t smc_fid,
74 			  uint64_t x1,
75 			  uint64_t x2,
76 			  uint64_t x3,
77 			  uint64_t x4,
78 			  void *cookie,
79 			  void *handle,
80 			  uint64_t flags);
81 
82 #endif /* ARM_DRTM_SVC_H */
83