xref: /rk3399_ARM-atf/include/services/spm_mm_svc.h (revision 1e8b5354574ac389bb3d29fdfcb9631cc8108ccb)
1 /*
2  * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef SPM_MM_SVC_H
8 #define SPM_MM_SVC_H
9 
10 #include <lib/utils_def.h>
11 
12 /*
13  * The MM_VERSION_XXX definitions are used when responding to the
14  * MM_VERSION_AARCH32 service request. The version returned is different between
15  * this request and the SPM_MM_VERSION_AARCH32 request - both have been retained
16  * for compatibility.
17  */
18 #define MM_VERSION_MAJOR	U(1)
19 #define MM_VERSION_MAJOR_SHIFT	16
20 #define MM_VERSION_MAJOR_MASK	U(0x7FFF)
21 #define MM_VERSION_MINOR	U(0)
22 #define MM_VERSION_MINOR_SHIFT	0
23 #define MM_VERSION_MINOR_MASK	U(0xFFFF)
24 #define MM_VERSION_FORM(major, minor) ((major << MM_VERSION_MAJOR_SHIFT) | \
25 				       (minor))
26 #define MM_VERSION_COMPILED	MM_VERSION_FORM(MM_VERSION_MAJOR, \
27 						MM_VERSION_MINOR)
28 
29 #define SPM_MM_VERSION_MAJOR		  U(0)
30 #define SPM_MM_VERSION_MAJOR_SHIFT	  16
31 #define SPM_MM_VERSION_MAJOR_MASK	  U(0x7FFF)
32 #define SPM_MM_VERSION_MINOR		  U(1)
33 #define SPM_MM_VERSION_MINOR_SHIFT	  0
34 #define SPM_MM_VERSION_MINOR_MASK	  U(0xFFFF)
35 #define SPM_MM_VERSION_FORM(major, minor) ((major << \
36 					    SPM_MM_VERSION_MAJOR_SHIFT) | \
37 					   (minor))
38 #define SPM_MM_VERSION_COMPILED	SPM_MM_VERSION_FORM(SPM_MM_VERSION_MAJOR, \
39 						    SPM_MM_VERSION_MINOR)
40 
41 /* These macros are used to identify SPM-MM calls using the SMC function ID */
42 #define SPM_MM_FID_MASK			U(0xffff)
43 #define SPM_MM_FID_MIN_VALUE		U(0x40)
44 #define SPM_MM_FID_MAX_VALUE		U(0x7f)
45 #define is_spm_mm_fid(_fid)						 \
46 		((((_fid) & SPM_MM_FID_MASK) >= SPM_MM_FID_MIN_VALUE) && \
47 		 (((_fid) & SPM_MM_FID_MASK) <= SPM_MM_FID_MAX_VALUE))
48 
49 /*
50  * SMC IDs defined in [1] for accessing MM services from the Non-secure world.
51  * These FIDs occupy the range 0x40 - 0x5f.
52  * [1] DEN0060A_ARM_MM_Interface_Specification.pdf
53  */
54 #define MM_VERSION_AARCH32		U(0x84000040)
55 #define MM_COMMUNICATE_AARCH64		U(0xC4000041)
56 #define MM_COMMUNICATE_AARCH32		U(0x84000041)
57 
58 /*
59  * SMC IDs defined for accessing services implemented by the Secure Partition
60  * Manager from the Secure Partition(s). These services enable a partition to
61  * handle delegated events and request privileged operations from the manager.
62  * They occupy the range 0x60-0x7f.
63  */
64 #define SPM_MM_VERSION_AARCH32			U(0x84000060)
65 #define MM_SP_EVENT_COMPLETE_AARCH64		U(0xC4000061)
66 #define MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64	U(0xC4000064)
67 #define MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64	U(0xC4000065)
68 
69 /*
70  * Vendor-specific EL3 range SMC IDs defined for TPM start method for pre-FFA
71  * configuration. These SMCs are converted to MM_COMMUNICATE calls.
72  */
73 #define TPM_START_SMC_32			U(0x87000040)
74 #define TPM_START_SMC_64			U(0xC7000040)
75 
76 /*
77  * Macros used by MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64.
78  */
79 
80 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS	U(0)
81 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RW	U(1)
82 /* Value U(2) is reserved. */
83 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_RO	U(3)
84 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_MASK	U(3)
85 #define MM_SP_MEMORY_ATTRIBUTES_ACCESS_SHIFT	0
86 
87 #define MM_SP_MEMORY_ATTRIBUTES_EXEC		(U(0) << 2)
88 #define MM_SP_MEMORY_ATTRIBUTES_NON_EXEC	(U(1) << 2)
89 
90 
91 /* SPM error codes. */
92 #define SPM_MM_SUCCESS		  0
93 #define SPM_MM_NOT_SUPPORTED	 -1
94 #define SPM_MM_INVALID_PARAMETER -2
95 #define SPM_MM_DENIED		 -3
96 #define SPM_MM_NO_MEMORY	 -5
97 
98 #ifndef __ASSEMBLER__
99 
100 #include <stdint.h>
101 #include <tools_share/uuid.h>
102 
103 /*
104  * MM Communicate information structure. Required to generate MM Communicate
105  * payload to be shared with Standalone MM.
106  */
107 typedef struct mm_communicate_header {
108 	struct efi_guid	header_guid;
109 	size_t message_len;
110 	uint8_t data[1];
111 } mm_communicate_header_t;
112 
113 int32_t spm_mm_setup(void);
114 
115 uint64_t spm_mm_smc_handler(uint32_t smc_fid,
116 			    uint64_t x1,
117 			    uint64_t x2,
118 			    uint64_t x3,
119 			    uint64_t x4,
120 			    void *cookie,
121 			    void *handle,
122 			    uint64_t flags);
123 
124 /* Helper to enter a secure partition */
125 uint64_t spm_mm_sp_call(uint32_t smc_fid,
126 			uint64_t x1,
127 			uint64_t x2,
128 			uint64_t x3);
129 
130 /* Helper to handle TPM Start SVC call */
131 uint64_t spm_mm_tpm_start_handler(uint32_t smc_fid,
132 				  uint64_t x1,
133 				  uint64_t x2,
134 				  uint64_t x3,
135 				  uint64_t x4,
136 				  void *cookie,
137 				  void *handle,
138 				  uint64_t flags);
139 
140 #endif /* __ASSEMBLER__ */
141 
142 #endif /* SPM_MM_SVC_H */
143