blob: 2fbdddd43396c77868c0fb2798a3786b9eb02ffc [file] [log] [blame]
Zelalem Aweke13dc8f12021-07-09 14:20:03 -05001/*
Soby Mathew68ea9542022-03-22 13:58:52 +00002 * 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
13/* Construct RMM fastcall std FID from function number */
14#define RMM_FID(smc_cc, func_num) \
15 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
16 ((smc_cc) << FUNCID_CC_SHIFT) | \
17 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
18 ((func_num) << FUNCID_NUM_SHIFT))
19
20/* The macros below are used to identify RMI calls from the SMC function ID */
21#define RMI_FNUM_MIN_VALUE U(0x150)
22#define RMI_FNUM_MAX_VALUE U(0x18F)
23
24#define is_rmi_fid(fid) __extension__ ({ \
25 __typeof__(fid) _fid = (fid); \
26 ((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) && \
27 (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) && \
28 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
29 (GET_SMC_CC(_fid) == SMC_64) && \
30 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
31 ((_fid & 0x00FE0000) == 0U)); })
32
33/*
34 * RMI_FNUM_REQ_COMPLETE is the only function in the RMI rnage that originates
35 * from the Realm world and is handled by the RMMD. The RMI functions are
36 * always invoked by the Normal world, forwarded by RMMD and handled by the
37 * RMM
38 */
39#define RMI_FNUM_REQ_COMPLETE U(0x18F)
40#define RMMD_RMI_REQ_COMPLETE RMM_FID(SMC_64, RMI_FNUM_REQ_COMPLETE)
41
42/* The SMC in the range 0x8400 0190 - 0x8400 01AF are reserved for RSIs.*/
43
44/*
45 * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
46 * world and return to Realm world.
47 *
48 * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
49 */
50#define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0)
51#define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF)
52
53/* The macros below are used to identify GTSI calls from the SMC function ID */
54#define is_rmmd_el3_fid(fid) __extension__ ({ \
55 __typeof__(fid) _fid = (fid); \
56 ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
57 (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\
58 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
59 (GET_SMC_CC(_fid) == SMC_64) && \
60 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
61 ((_fid & 0x00FE0000) == 0U)); })
62
63/* RMMD Service Function NUmbers */
64#define GTSI_DELEGATE U(0x1B0)
65#define GTSI_UNDELEGATE U(0x1B1)
66#define ATTEST_GET_REALM_KEY U(0x1B2)
67#define ATTEST_GET_PLAT_TOKEN U(0x1B3)
68
69#define RMMD_GTSI_DELEGATE RMM_FID(SMC_64, GTSI_DELEGATE)
70#define RMMD_GTSI_UNDELEGATE RMM_FID(SMC_64, GTSI_UNDELEGATE)
71
72/* Return error codes from RMM-EL3 SMCs */
73#define RMMD_OK 0
74#define RMMD_ERR_BAD_ADDR -2
75#define RMMD_ERR_BAD_PAS -3
76#define RMMD_ERR_NOMEM -4
77#define RMMD_ERR_INVAL -5
78#define RMMD_ERR_UNK -6
79
Soby Mathew294e1cf2022-03-22 16:19:39 +000080/*
81 * Retrieve Platform token from EL3.
82 * The arguments to this SMC are :
83 * arg0 - Function ID.
84 * arg1 - Platform attestation token buffer Physical address. (The challenge
85 * object is passed in this buffer.)
86 * arg2 - Platform attestation token buffer size (in bytes).
87 * arg3 - Challenge object size (in bytes). It has be one of the defined SHA hash
88 * sizes.
89 * The return arguments are :
90 * ret0 - Status / error.
91 * ret1 - Size of the platform token if successful.
92 */
93#define RMMD_ATTEST_GET_PLAT_TOKEN RMM_FID(SMC_64, ATTEST_GET_PLAT_TOKEN)
94
95/* Acceptable SHA sizes for Challenge object */
96#define SHA256_DIGEST_SIZE 32U
97#define SHA384_DIGEST_SIZE 48U
98#define SHA512_DIGEST_SIZE 64U
99
Soby Mathewf05d93a2022-03-22 16:21:19 +0000100/*
101 * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
102 * supported. The arguments to this SMC are :
103 * arg0 - Function ID.
104 * arg1 - Realm attestation key buffer Physical address.
105 * arg2 - Realm attestation key buffer size (in bytes).
106 * arg3 - The type of the elliptic curve to which the requested
107 * attestation key belongs to. The value should be one of the
108 * defined curve types.
109 * The return arguments are :
110 * ret0 - Status / error.
111 * ret1 - Size of the realm attestation key if successful.
112 */
113#define RMMD_ATTEST_GET_REALM_KEY RMM_FID(SMC_64, ATTEST_GET_REALM_KEY)
114
115/* ECC Curve types for attest key generation */
116#define ATTEST_KEY_CURVE_ECC_SECP384R1 0
117
118
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500119#ifndef __ASSEMBLER__
120#include <stdint.h>
121
122int rmmd_setup(void);
123uint64_t rmmd_rmi_handler(uint32_t smc_fid,
124 uint64_t x1,
125 uint64_t x2,
126 uint64_t x3,
127 uint64_t x4,
128 void *cookie,
129 void *handle,
130 uint64_t flags);
131
Soby Mathew68ea9542022-03-22 13:58:52 +0000132uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500133 uint64_t x1,
134 uint64_t x2,
135 uint64_t x3,
136 uint64_t x4,
137 void *cookie,
138 void *handle,
139 uint64_t flags);
140
141#endif /* __ASSEMBLER__ */
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500142#endif /* RMMD_SVC_H */