blob: a567d285579110cd6dab9acb762aa67d285f6351 [file] [log] [blame]
Zelalem Aweke13dc8f12021-07-09 14:20:03 -05001/*
Subhasish Ghosh3ad16032022-05-12 12:22:17 +01002 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
Zelalem Aweke13dc8f12021-07-09 14:20:03 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef RMMD_SVC_H
8#define RMMD_SVC_H
9
Soby Mathew68ea9542022-03-22 13:58:52 +000010#include <lib/smccc.h>
11#include <lib/utils_def.h>
12
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010013/* STD calls FNUM Min/Max ranges */
Soby Mathew68ea9542022-03-22 13:58:52 +000014#define RMI_FNUM_MIN_VALUE U(0x150)
15#define RMI_FNUM_MAX_VALUE U(0x18F)
16
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010017/* Construct RMI fastcall std FID from offset */
18#define SMC64_RMI_FID(_offset) \
19 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
20 (SMC_64 << FUNCID_CC_SHIFT) | \
21 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
22 (((RMI_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
23 << FUNCID_NUM_SHIFT))
24
Soby Mathew68ea9542022-03-22 13:58:52 +000025#define is_rmi_fid(fid) __extension__ ({ \
26 __typeof__(fid) _fid = (fid); \
27 ((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) && \
28 (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) && \
29 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
30 (GET_SMC_CC(_fid) == SMC_64) && \
31 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
32 ((_fid & 0x00FE0000) == 0U)); })
33
34/*
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010035 * RMI_FNUM_REQ_COMPLETE is the only function in the RMI range that originates
Soby Mathew68ea9542022-03-22 13:58:52 +000036 * from the Realm world and is handled by the RMMD. The RMI functions are
37 * always invoked by the Normal world, forwarded by RMMD and handled by the
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010038 * RMM.
Soby Mathew68ea9542022-03-22 13:58:52 +000039 */
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010040 /* 0x18F */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +010041#define RMM_RMI_REQ_COMPLETE SMC64_RMI_FID(U(0x3F))
Soby Mathew68ea9542022-03-22 13:58:52 +000042
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000043/* RMM_BOOT_COMPLETE arg0 error codes */
44#define E_RMM_BOOT_SUCCESS (0)
45#define E_RMM_BOOT_UNKNOWN (-1)
46#define E_RMM_BOOT_VERSION_MISMATCH (-2)
47#define E_RMM_BOOT_CPUS_OUT_OF_RANGE (-3)
48#define E_RMM_BOOT_CPU_ID_OUT_OF_RANGE (-4)
49#define E_RMM_BOOT_INVALID_SHARED_BUFFER (-5)
50#define E_RMM_BOOT_MANIFEST_VERSION_NOT_SUPPORTED (-6)
51#define E_RMM_BOOT_MANIFEST_DATA_ERROR (-7)
52
53/* The SMC in the range 0x8400 0191 - 0x8400 01AF are reserved for RSIs.*/
Soby Mathew68ea9542022-03-22 13:58:52 +000054
55/*
56 * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
57 * world and return to Realm world.
58 *
59 * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
60 */
61#define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0)
62#define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF)
63
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010064/* Construct RMM_EL3 fastcall std FID from offset */
65#define SMC64_RMMD_EL3_FID(_offset) \
66 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
67 (SMC_64 << FUNCID_CC_SHIFT) | \
68 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
69 (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
70 << FUNCID_NUM_SHIFT))
71
Soby Mathew68ea9542022-03-22 13:58:52 +000072/* The macros below are used to identify GTSI calls from the SMC function ID */
73#define is_rmmd_el3_fid(fid) __extension__ ({ \
74 __typeof__(fid) _fid = (fid); \
75 ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
76 (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\
77 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
78 (GET_SMC_CC(_fid) == SMC_64) && \
79 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
80 ((_fid & 0x00FE0000) == 0U)); })
81
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010082 /* 0x1B0 - 0x1B1 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +010083#define RMM_GTSI_DELEGATE SMC64_RMMD_EL3_FID(U(0))
84#define RMM_GTSI_UNDELEGATE SMC64_RMMD_EL3_FID(U(1))
Soby Mathew68ea9542022-03-22 13:58:52 +000085
86/* Return error codes from RMM-EL3 SMCs */
Javier Almansa Sobrinodea652e2022-04-13 17:57:35 +010087#define E_RMM_OK 0
88#define E_RMM_UNK -1
89#define E_RMM_BAD_ADDR -2
90#define E_RMM_BAD_PAS -3
91#define E_RMM_NOMEM -4
92#define E_RMM_INVAL -5
Soby Mathew68ea9542022-03-22 13:58:52 +000093
Shruti Gupta23c87332023-10-26 12:01:28 +010094/* Return error codes from RMI SMCs */
95#define RMI_SUCCESS 0
96#define RMI_ERROR_INPUT 1
97
Soby Mathew294e1cf2022-03-22 16:19:39 +000098/* Acceptable SHA sizes for Challenge object */
99#define SHA256_DIGEST_SIZE 32U
100#define SHA384_DIGEST_SIZE 48U
101#define SHA512_DIGEST_SIZE 64U
102
Soby Mathewf05d93a2022-03-22 16:21:19 +0000103/*
104 * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
105 * supported. The arguments to this SMC are :
106 * arg0 - Function ID.
107 * arg1 - Realm attestation key buffer Physical address.
108 * arg2 - Realm attestation key buffer size (in bytes).
109 * arg3 - The type of the elliptic curve to which the requested
110 * attestation key belongs to. The value should be one of the
111 * defined curve types.
112 * The return arguments are :
113 * ret0 - Status / error.
114 * ret1 - Size of the realm attestation key if successful.
115 */
Subhasish Ghosh3ad16032022-05-12 12:22:17 +0100116 /* 0x1B2 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +0100117#define RMM_ATTEST_GET_REALM_KEY SMC64_RMMD_EL3_FID(U(2))
Subhasish Ghosh3ad16032022-05-12 12:22:17 +0100118
119/*
120 * Retrieve Platform token from EL3.
121 * The arguments to this SMC are :
122 * arg0 - Function ID.
123 * arg1 - Platform attestation token buffer Physical address. (The challenge
124 * object is passed in this buffer.)
125 * arg2 - Platform attestation token buffer size (in bytes).
126 * arg3 - Challenge object size (in bytes). It has to be one of the defined
127 * SHA hash sizes.
128 * The return arguments are :
129 * ret0 - Status / error.
130 * ret1 - Size of the platform token if successful.
131 */
132 /* 0x1B3 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +0100133#define RMM_ATTEST_GET_PLAT_TOKEN SMC64_RMMD_EL3_FID(U(3))
Soby Mathewf05d93a2022-03-22 16:21:19 +0000134
135/* ECC Curve types for attest key generation */
136#define ATTEST_KEY_CURVE_ECC_SECP384R1 0
137
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000138/*
139 * RMM_BOOT_COMPLETE originates on RMM when the boot finishes (either cold
140 * or warm boot). This is handled by the RMM-EL3 interface SMC handler.
141 *
142 * RMM_BOOT_COMPLETE FID is located at the end of the available range.
143 */
144 /* 0x1CF */
145#define RMM_BOOT_COMPLETE SMC64_RMMD_EL3_FID(U(0x1F))
146
147/*
148 * The major version number of the RMM Boot Interface implementation.
149 * Increase this whenever the semantics of the boot arguments change making it
150 * backwards incompatible.
151 */
152#define RMM_EL3_IFC_VERSION_MAJOR (U(0))
153
154/*
155 * The minor version number of the RMM Boot Interface implementation.
156 * Increase this when a bug is fixed, or a feature is added without
157 * breaking compatibility.
158 */
Shruti Gupta3440e562023-05-15 14:43:57 +0100159#define RMM_EL3_IFC_VERSION_MINOR (U(2))
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000160
161#define RMM_EL3_INTERFACE_VERSION \
162 (((RMM_EL3_IFC_VERSION_MAJOR << 16) & 0x7FFFF) | \
163 RMM_EL3_IFC_VERSION_MINOR)
164
165#define RMM_EL3_IFC_VERSION_GET_MAJOR(_version) (((_version) >> 16) \
166 & 0x7FFF)
167#define RMM_EL3_IFC_VERSION_GET_MAJOR_MINOR(_version) ((_version) & 0xFFFF)
Soby Mathewf05d93a2022-03-22 16:21:19 +0000168
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500169#ifndef __ASSEMBLER__
170#include <stdint.h>
171
172int rmmd_setup(void);
173uint64_t rmmd_rmi_handler(uint32_t smc_fid,
174 uint64_t x1,
175 uint64_t x2,
176 uint64_t x3,
177 uint64_t x4,
178 void *cookie,
179 void *handle,
180 uint64_t flags);
181
Soby Mathew68ea9542022-03-22 13:58:52 +0000182uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500183 uint64_t x1,
184 uint64_t x2,
185 uint64_t x3,
186 uint64_t x4,
187 void *cookie,
188 void *handle,
189 uint64_t flags);
190
191#endif /* __ASSEMBLER__ */
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500192#endif /* RMMD_SVC_H */