177c27753SZelalem Aweke /* 2319fb084SSoby Mathew * Copyright (c) 2021-2022, ARM Limited and Contributors. All rights reserved. 377c27753SZelalem Aweke * 477c27753SZelalem Aweke * SPDX-License-Identifier: BSD-3-Clause 577c27753SZelalem Aweke */ 677c27753SZelalem Aweke 777c27753SZelalem Aweke #ifndef RMMD_SVC_H 877c27753SZelalem Aweke #define RMMD_SVC_H 977c27753SZelalem Aweke 10319fb084SSoby Mathew #include <lib/smccc.h> 11319fb084SSoby Mathew #include <lib/utils_def.h> 12319fb084SSoby Mathew 13319fb084SSoby Mathew /* Construct RMM fastcall std FID from function number */ 14319fb084SSoby Mathew #define RMM_FID(smc_cc, func_num) \ 15319fb084SSoby Mathew ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \ 16319fb084SSoby Mathew ((smc_cc) << FUNCID_CC_SHIFT) | \ 17319fb084SSoby Mathew (OEN_STD_START << FUNCID_OEN_SHIFT) | \ 18319fb084SSoby Mathew ((func_num) << FUNCID_NUM_SHIFT)) 19319fb084SSoby Mathew 20319fb084SSoby Mathew /* The macros below are used to identify RMI calls from the SMC function ID */ 21319fb084SSoby Mathew #define RMI_FNUM_MIN_VALUE U(0x150) 22319fb084SSoby Mathew #define RMI_FNUM_MAX_VALUE U(0x18F) 23319fb084SSoby Mathew 24319fb084SSoby Mathew #define is_rmi_fid(fid) __extension__ ({ \ 25319fb084SSoby Mathew __typeof__(fid) _fid = (fid); \ 26319fb084SSoby Mathew ((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) && \ 27319fb084SSoby Mathew (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) && \ 28319fb084SSoby Mathew (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \ 29319fb084SSoby Mathew (GET_SMC_CC(_fid) == SMC_64) && \ 30319fb084SSoby Mathew (GET_SMC_OEN(_fid) == OEN_STD_START) && \ 31319fb084SSoby Mathew ((_fid & 0x00FE0000) == 0U)); }) 32319fb084SSoby Mathew 33319fb084SSoby Mathew /* 34319fb084SSoby Mathew * RMI_FNUM_REQ_COMPLETE is the only function in the RMI rnage that originates 35319fb084SSoby Mathew * from the Realm world and is handled by the RMMD. The RMI functions are 36319fb084SSoby Mathew * always invoked by the Normal world, forwarded by RMMD and handled by the 37319fb084SSoby Mathew * RMM 38319fb084SSoby Mathew */ 39319fb084SSoby Mathew #define RMI_FNUM_REQ_COMPLETE U(0x18F) 40319fb084SSoby Mathew #define RMMD_RMI_REQ_COMPLETE RMM_FID(SMC_64, RMI_FNUM_REQ_COMPLETE) 41319fb084SSoby Mathew 42319fb084SSoby Mathew /* The SMC in the range 0x8400 0190 - 0x8400 01AF are reserved for RSIs.*/ 43319fb084SSoby Mathew 44319fb084SSoby Mathew /* 45319fb084SSoby Mathew * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm 46319fb084SSoby Mathew * world and return to Realm world. 47319fb084SSoby Mathew * 48319fb084SSoby Mathew * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range. 49319fb084SSoby Mathew */ 50319fb084SSoby Mathew #define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0) 51319fb084SSoby Mathew #define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF) 52319fb084SSoby Mathew 53319fb084SSoby Mathew /* The macros below are used to identify GTSI calls from the SMC function ID */ 54319fb084SSoby Mathew #define is_rmmd_el3_fid(fid) __extension__ ({ \ 55319fb084SSoby Mathew __typeof__(fid) _fid = (fid); \ 56319fb084SSoby Mathew ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\ 57319fb084SSoby Mathew (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\ 58319fb084SSoby Mathew (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \ 59319fb084SSoby Mathew (GET_SMC_CC(_fid) == SMC_64) && \ 60319fb084SSoby Mathew (GET_SMC_OEN(_fid) == OEN_STD_START) && \ 61319fb084SSoby Mathew ((_fid & 0x00FE0000) == 0U)); }) 62319fb084SSoby Mathew 63319fb084SSoby Mathew /* RMMD Service Function NUmbers */ 64319fb084SSoby Mathew #define GTSI_DELEGATE U(0x1B0) 65319fb084SSoby Mathew #define GTSI_UNDELEGATE U(0x1B1) 66319fb084SSoby Mathew #define ATTEST_GET_REALM_KEY U(0x1B2) 67319fb084SSoby Mathew #define ATTEST_GET_PLAT_TOKEN U(0x1B3) 68319fb084SSoby Mathew 69319fb084SSoby Mathew #define RMMD_GTSI_DELEGATE RMM_FID(SMC_64, GTSI_DELEGATE) 70319fb084SSoby Mathew #define RMMD_GTSI_UNDELEGATE RMM_FID(SMC_64, GTSI_UNDELEGATE) 71319fb084SSoby Mathew 72319fb084SSoby Mathew /* Return error codes from RMM-EL3 SMCs */ 73319fb084SSoby Mathew #define RMMD_OK 0 74319fb084SSoby Mathew #define RMMD_ERR_BAD_ADDR -2 75319fb084SSoby Mathew #define RMMD_ERR_BAD_PAS -3 76319fb084SSoby Mathew #define RMMD_ERR_NOMEM -4 77319fb084SSoby Mathew #define RMMD_ERR_INVAL -5 78319fb084SSoby Mathew #define RMMD_ERR_UNK -6 79319fb084SSoby Mathew 800f9159b7SSoby Mathew /* 810f9159b7SSoby Mathew * Retrieve Platform token from EL3. 820f9159b7SSoby Mathew * The arguments to this SMC are : 830f9159b7SSoby Mathew * arg0 - Function ID. 840f9159b7SSoby Mathew * arg1 - Platform attestation token buffer Physical address. (The challenge 850f9159b7SSoby Mathew * object is passed in this buffer.) 860f9159b7SSoby Mathew * arg2 - Platform attestation token buffer size (in bytes). 870f9159b7SSoby Mathew * arg3 - Challenge object size (in bytes). It has be one of the defined SHA hash 880f9159b7SSoby Mathew * sizes. 890f9159b7SSoby Mathew * The return arguments are : 900f9159b7SSoby Mathew * ret0 - Status / error. 910f9159b7SSoby Mathew * ret1 - Size of the platform token if successful. 920f9159b7SSoby Mathew */ 930f9159b7SSoby Mathew #define RMMD_ATTEST_GET_PLAT_TOKEN RMM_FID(SMC_64, ATTEST_GET_PLAT_TOKEN) 940f9159b7SSoby Mathew 950f9159b7SSoby Mathew /* Acceptable SHA sizes for Challenge object */ 960f9159b7SSoby Mathew #define SHA256_DIGEST_SIZE 32U 970f9159b7SSoby Mathew #define SHA384_DIGEST_SIZE 48U 980f9159b7SSoby Mathew #define SHA512_DIGEST_SIZE 64U 990f9159b7SSoby Mathew 100*a0435105SSoby Mathew /* 101*a0435105SSoby Mathew * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is 102*a0435105SSoby Mathew * supported. The arguments to this SMC are : 103*a0435105SSoby Mathew * arg0 - Function ID. 104*a0435105SSoby Mathew * arg1 - Realm attestation key buffer Physical address. 105*a0435105SSoby Mathew * arg2 - Realm attestation key buffer size (in bytes). 106*a0435105SSoby Mathew * arg3 - The type of the elliptic curve to which the requested 107*a0435105SSoby Mathew * attestation key belongs to. The value should be one of the 108*a0435105SSoby Mathew * defined curve types. 109*a0435105SSoby Mathew * The return arguments are : 110*a0435105SSoby Mathew * ret0 - Status / error. 111*a0435105SSoby Mathew * ret1 - Size of the realm attestation key if successful. 112*a0435105SSoby Mathew */ 113*a0435105SSoby Mathew #define RMMD_ATTEST_GET_REALM_KEY RMM_FID(SMC_64, ATTEST_GET_REALM_KEY) 114*a0435105SSoby Mathew 115*a0435105SSoby Mathew /* ECC Curve types for attest key generation */ 116*a0435105SSoby Mathew #define ATTEST_KEY_CURVE_ECC_SECP384R1 0 117*a0435105SSoby Mathew 118*a0435105SSoby Mathew 11977c27753SZelalem Aweke #ifndef __ASSEMBLER__ 12077c27753SZelalem Aweke #include <stdint.h> 12177c27753SZelalem Aweke 12277c27753SZelalem Aweke int rmmd_setup(void); 12377c27753SZelalem Aweke uint64_t rmmd_rmi_handler(uint32_t smc_fid, 12477c27753SZelalem Aweke uint64_t x1, 12577c27753SZelalem Aweke uint64_t x2, 12677c27753SZelalem Aweke uint64_t x3, 12777c27753SZelalem Aweke uint64_t x4, 12877c27753SZelalem Aweke void *cookie, 12977c27753SZelalem Aweke void *handle, 13077c27753SZelalem Aweke uint64_t flags); 13177c27753SZelalem Aweke 132319fb084SSoby Mathew uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid, 13377c27753SZelalem Aweke uint64_t x1, 13477c27753SZelalem Aweke uint64_t x2, 13577c27753SZelalem Aweke uint64_t x3, 13677c27753SZelalem Aweke uint64_t x4, 13777c27753SZelalem Aweke void *cookie, 13877c27753SZelalem Aweke void *handle, 13977c27753SZelalem Aweke uint64_t flags); 14077c27753SZelalem Aweke 14177c27753SZelalem Aweke #endif /* __ASSEMBLER__ */ 14277c27753SZelalem Aweke #endif /* RMMD_SVC_H */ 143