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 /* 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 100 #ifndef __ASSEMBLER__ 101 #include <stdint.h> 102 103 int rmmd_setup(void); 104 uint64_t rmmd_rmi_handler(uint32_t smc_fid, 105 uint64_t x1, 106 uint64_t x2, 107 uint64_t x3, 108 uint64_t x4, 109 void *cookie, 110 void *handle, 111 uint64_t flags); 112 113 uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid, 114 uint64_t x1, 115 uint64_t x2, 116 uint64_t x3, 117 uint64_t x4, 118 void *cookie, 119 void *handle, 120 uint64_t flags); 121 122 #endif /* __ASSEMBLER__ */ 123 124 #endif /* RMMD_SVC_H */ 125