1 /* 2 * Copyright (c) 2021-2022, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef RMMD_SVC_H 8 #define RMMD_SVC_H 9 10 #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 80 #ifndef __ASSEMBLER__ 81 #include <stdint.h> 82 83 int rmmd_setup(void); 84 uint64_t rmmd_rmi_handler(uint32_t smc_fid, 85 uint64_t x1, 86 uint64_t x2, 87 uint64_t x3, 88 uint64_t x4, 89 void *cookie, 90 void *handle, 91 uint64_t flags); 92 93 uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid, 94 uint64_t x1, 95 uint64_t x2, 96 uint64_t x3, 97 uint64_t x4, 98 void *cookie, 99 void *handle, 100 uint64_t flags); 101 102 #endif /* __ASSEMBLER__ */ 103 104 #endif /* RMMD_SVC_H */ 105