blob: 156d89c8d50de5ebe13e61c927eb87e3476d46ae [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 */
41#define RMMD_RMI_REQ_COMPLETE SMC64_RMI_FID(U(0x3F))
Soby Mathew68ea9542022-03-22 13:58:52 +000042
43/* The SMC in the range 0x8400 0190 - 0x8400 01AF are reserved for RSIs.*/
44
45/*
46 * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
47 * world and return to Realm world.
48 *
49 * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
50 */
51#define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0)
52#define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF)
53
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010054/* Construct RMM_EL3 fastcall std FID from offset */
55#define SMC64_RMMD_EL3_FID(_offset) \
56 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
57 (SMC_64 << FUNCID_CC_SHIFT) | \
58 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
59 (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
60 << FUNCID_NUM_SHIFT))
61
Soby Mathew68ea9542022-03-22 13:58:52 +000062/* The macros below are used to identify GTSI calls from the SMC function ID */
63#define is_rmmd_el3_fid(fid) __extension__ ({ \
64 __typeof__(fid) _fid = (fid); \
65 ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
66 (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\
67 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
68 (GET_SMC_CC(_fid) == SMC_64) && \
69 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
70 ((_fid & 0x00FE0000) == 0U)); })
71
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010072 /* 0x1B0 - 0x1B1 */
73#define RMMD_GTSI_DELEGATE SMC64_RMMD_EL3_FID(U(0))
74#define RMMD_GTSI_UNDELEGATE SMC64_RMMD_EL3_FID(U(1))
Soby Mathew68ea9542022-03-22 13:58:52 +000075
76/* Return error codes from RMM-EL3 SMCs */
77#define RMMD_OK 0
78#define RMMD_ERR_BAD_ADDR -2
79#define RMMD_ERR_BAD_PAS -3
80#define RMMD_ERR_NOMEM -4
81#define RMMD_ERR_INVAL -5
82#define RMMD_ERR_UNK -6
83
Soby Mathew294e1cf2022-03-22 16:19:39 +000084/* Acceptable SHA sizes for Challenge object */
85#define SHA256_DIGEST_SIZE 32U
86#define SHA384_DIGEST_SIZE 48U
87#define SHA512_DIGEST_SIZE 64U
88
Soby Mathewf05d93a2022-03-22 16:21:19 +000089/*
90 * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
91 * supported. The arguments to this SMC are :
92 * arg0 - Function ID.
93 * arg1 - Realm attestation key buffer Physical address.
94 * arg2 - Realm attestation key buffer size (in bytes).
95 * arg3 - The type of the elliptic curve to which the requested
96 * attestation key belongs to. The value should be one of the
97 * defined curve types.
98 * The return arguments are :
99 * ret0 - Status / error.
100 * ret1 - Size of the realm attestation key if successful.
101 */
Subhasish Ghosh3ad16032022-05-12 12:22:17 +0100102 /* 0x1B2 */
103#define RMMD_ATTEST_GET_REALM_KEY SMC64_RMMD_EL3_FID(U(2))
104
105/*
106 * Retrieve Platform token from EL3.
107 * The arguments to this SMC are :
108 * arg0 - Function ID.
109 * arg1 - Platform attestation token buffer Physical address. (The challenge
110 * object is passed in this buffer.)
111 * arg2 - Platform attestation token buffer size (in bytes).
112 * arg3 - Challenge object size (in bytes). It has to be one of the defined
113 * SHA hash sizes.
114 * The return arguments are :
115 * ret0 - Status / error.
116 * ret1 - Size of the platform token if successful.
117 */
118 /* 0x1B3 */
119#define RMMD_ATTEST_GET_PLAT_TOKEN SMC64_RMMD_EL3_FID(U(3))
Soby Mathewf05d93a2022-03-22 16:21:19 +0000120
121/* ECC Curve types for attest key generation */
122#define ATTEST_KEY_CURVE_ECC_SECP384R1 0
123
124
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500125#ifndef __ASSEMBLER__
126#include <stdint.h>
127
128int rmmd_setup(void);
129uint64_t rmmd_rmi_handler(uint32_t smc_fid,
130 uint64_t x1,
131 uint64_t x2,
132 uint64_t x3,
133 uint64_t x4,
134 void *cookie,
135 void *handle,
136 uint64_t flags);
137
Soby Mathew68ea9542022-03-22 13:58:52 +0000138uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500139 uint64_t x1,
140 uint64_t x2,
141 uint64_t x3,
142 uint64_t x4,
143 void *cookie,
144 void *handle,
145 uint64_t flags);
146
147#endif /* __ASSEMBLER__ */
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500148#endif /* RMMD_SVC_H */