1*c359aeb1SJohn Powell /* 2*c359aeb1SJohn Powell * Copyright (c) 2026, Arm Limited. All rights reserved. 3*c359aeb1SJohn Powell * 4*c359aeb1SJohn Powell * SPDX-License-Identifier: BSD-3-Clause 5*c359aeb1SJohn Powell */ 6*c359aeb1SJohn Powell 7*c359aeb1SJohn Powell #ifndef FIRME_SVC_H 8*c359aeb1SJohn Powell #define FIRME_SVC_H 9*c359aeb1SJohn Powell 10*c359aeb1SJohn Powell #include <common/sha_common_macros.h> 11*c359aeb1SJohn Powell #include <lib/smccc.h> 12*c359aeb1SJohn Powell #include <lib/utils_def.h> 13*c359aeb1SJohn Powell 14*c359aeb1SJohn Powell /* FIRME service versions currently supported */ 15*c359aeb1SJohn Powell /* Version 0.0 returns not supported */ 16*c359aeb1SJohn Powell #define FIRME_BASE_VERSION_MAJOR U(1) 17*c359aeb1SJohn Powell #define FIRME_BASE_VERSION_MINOR U(0) 18*c359aeb1SJohn Powell #define FIRME_GRANULE_MGMT_VERSION_MAJOR U(1) 19*c359aeb1SJohn Powell #define FIRME_GRANULE_MGMT_VERSION_MINOR U(0) 20*c359aeb1SJohn Powell #define FIRME_IDE_KEY_MGMT_VERSION_MAJOR U(0) 21*c359aeb1SJohn Powell #define FIRME_IDE_KEY_MGMT_VERSION_MINOR U(0) 22*c359aeb1SJohn Powell #define FIRME_MECID_MGMT_VERSION_MAJOR U(0) 23*c359aeb1SJohn Powell #define FIRME_MECID_MGMT_VERSION_MINOR U(0) 24*c359aeb1SJohn Powell #define FIRME_ATTESTATION_VERSION_MAJOR U(0) 25*c359aeb1SJohn Powell #define FIRME_ATTESTATION_VERSION_MINOR U(0) 26*c359aeb1SJohn Powell #define FIRME_INTEGRATED_DEVICE_MGMT_VERSION_MAJOR U(0) 27*c359aeb1SJohn Powell #define FIRME_INTEGRATED_DEVICE_MGMT_VERSION_MINOR U(0) 28*c359aeb1SJohn Powell 29*c359aeb1SJohn Powell #define FIRME_VERSION_MAJOR_SHIFT U(16) 30*c359aeb1SJohn Powell #define FIRME_VERSION_MAJOR_MASK U(0x7FFF) 31*c359aeb1SJohn Powell #define FIRME_VERSION_MINOR_SHIFT U(0) 32*c359aeb1SJohn Powell #define FIRME_VERSION_MINOR_MASK U(0xFFFF) 33*c359aeb1SJohn Powell #define FIRME_VERSION(major, minor) ((((major) & FIRME_VERSION_MAJOR_MASK) << \ 34*c359aeb1SJohn Powell FIRME_VERSION_MAJOR_SHIFT) | \ 35*c359aeb1SJohn Powell (((minor) & FIRME_VERSION_MINOR_MASK) << \ 36*c359aeb1SJohn Powell FIRME_VERSION_MINOR_SHIFT)) 37*c359aeb1SJohn Powell 38*c359aeb1SJohn Powell 39*c359aeb1SJohn Powell /* FIRME service ID definitions */ 40*c359aeb1SJohn Powell typedef enum { 41*c359aeb1SJohn Powell FIRME_BASE_ID = 0, 42*c359aeb1SJohn Powell FIRME_GRANULE_MGMT_ID = 1, 43*c359aeb1SJohn Powell FIRME_IDE_KEY_MGMT_ID = 2, 44*c359aeb1SJohn Powell FIRME_MECID_MGMT_ID = 3, 45*c359aeb1SJohn Powell FIRME_ATTESTATION_ID = 4, 46*c359aeb1SJohn Powell FIRME_INTEGRATED_DEVICE_MGMT_ID = 5, 47*c359aeb1SJohn Powell FIRME_SERVICE_ID_MAX = 6, 48*c359aeb1SJohn Powell } firme_service_id_e; 49*c359aeb1SJohn Powell 50*c359aeb1SJohn Powell typedef enum { 51*c359aeb1SJohn Powell FIRME_SECURE = 0, 52*c359aeb1SJohn Powell FIRME_NONSECURE = 1, 53*c359aeb1SJohn Powell FIRME_REALM = 2 54*c359aeb1SJohn Powell } firme_instance_e; 55*c359aeb1SJohn Powell 56*c359aeb1SJohn Powell typedef struct { 57*c359aeb1SJohn Powell uint32_t version; 58*c359aeb1SJohn Powell uint8_t instance_support; 59*c359aeb1SJohn Powell uint8_t num_feature_regs; 60*c359aeb1SJohn Powell uint64_t feature_reg[16]; 61*c359aeb1SJohn Powell } firme_service_info_t; 62*c359aeb1SJohn Powell 63*c359aeb1SJohn Powell /* FIRME SMC return codes */ 64*c359aeb1SJohn Powell #define FIRME_SUCCESS 0 65*c359aeb1SJohn Powell #define FIRME_NOT_SUPPORTED -1 66*c359aeb1SJohn Powell #define FIRME_INVALID_PARAMETERS -2 67*c359aeb1SJohn Powell #define FIRME_ABORTED -3 68*c359aeb1SJohn Powell #define FIRME_INCOMPLETE -4 69*c359aeb1SJohn Powell #define FIRME_DENIED -5 70*c359aeb1SJohn Powell #define FIRME_RETRY -6 71*c359aeb1SJohn Powell #define FIRME_IN_PROGRESS -7 72*c359aeb1SJohn Powell #define FIRME_EXISTS -8 73*c359aeb1SJohn Powell #define FIRME_NO_ENTRY -9 74*c359aeb1SJohn Powell #define FIRME_NO_MEMORY -10 75*c359aeb1SJohn Powell #define FIRME_BAD_DATA -11 76*c359aeb1SJohn Powell 77*c359aeb1SJohn Powell /* Range of function IDs used by FIRME interface */ 78*c359aeb1SJohn Powell #define FIRME_FNUM_MIN_VALUE U(0x400) 79*c359aeb1SJohn Powell #define FIRME_FNUM_MAX_VALUE U(0x412) 80*c359aeb1SJohn Powell 81*c359aeb1SJohn Powell /* Construct FIRME fastcall std FID from offset */ 82*c359aeb1SJohn Powell #define SMC64_FIRME_FID(_offset) \ 83*c359aeb1SJohn Powell ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | (SMC_64 << FUNCID_CC_SHIFT) | \ 84*c359aeb1SJohn Powell (OEN_STD_START << FUNCID_OEN_SHIFT) | \ 85*c359aeb1SJohn Powell (((FIRME_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \ 86*c359aeb1SJohn Powell << FUNCID_NUM_SHIFT)) 87*c359aeb1SJohn Powell 88*c359aeb1SJohn Powell #define is_firme_fid(fid) \ 89*c359aeb1SJohn Powell __extension__({ \ 90*c359aeb1SJohn Powell __typeof__(fid) _fid = (fid); \ 91*c359aeb1SJohn Powell ((GET_SMC_NUM(_fid) >= FIRME_FNUM_MIN_VALUE) && \ 92*c359aeb1SJohn Powell (GET_SMC_NUM(_fid) <= FIRME_FNUM_MAX_VALUE) && \ 93*c359aeb1SJohn Powell (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \ 94*c359aeb1SJohn Powell (GET_SMC_CC(_fid) == SMC_64) && \ 95*c359aeb1SJohn Powell (GET_SMC_OEN(_fid) == OEN_STD_START) && \ 96*c359aeb1SJohn Powell ((_fid & 0x00FE0000) == 0U)); \ 97*c359aeb1SJohn Powell }) 98*c359aeb1SJohn Powell 99*c359aeb1SJohn Powell /* FIRME Granule Transition Bit Fields */ 100*c359aeb1SJohn Powell 101*c359aeb1SJohn Powell #define FIRME_GM_GPI_SET_TGT_GPI_SHIFT U(0) 102*c359aeb1SJohn Powell #define FIRME_GM_GPI_SET_TGT_GPI_MASK U(0xF) 103*c359aeb1SJohn Powell 104*c359aeb1SJohn Powell /* Base service feature register definitions */ 105*c359aeb1SJohn Powell #define FIRME_BASE_VERSION_BIT BIT(0) 106*c359aeb1SJohn Powell #define FIRME_BASE_FEATURES_BIT BIT(1) 107*c359aeb1SJohn Powell #define FIRME_BASE_MIN_SH_BUF_SZ_SHIFT U(0) 108*c359aeb1SJohn Powell #define FIRME_BASE_MIN_SH_BUF_SZ_MASK U(0x3) 109*c359aeb1SJohn Powell #define FIRME_BASE_MAX_SH_BUF_PG_CNT_SHIFT U(2) 110*c359aeb1SJohn Powell #define FIRME_BASE_MAX_SH_BUF_PG_CNT_MASK U(0x3FFF) 111*c359aeb1SJohn Powell #define FIRME_BASE_SERVICE_LIST_SHIFT U(16) 112*c359aeb1SJohn Powell #define FIRME_BASE_SERVICE_LIST_MASK U(0xFFFF) 113*c359aeb1SJohn Powell #define FIRME_BASE_SERVICE_GRANULE_MGMT_BIT BIT(16) 114*c359aeb1SJohn Powell 115*c359aeb1SJohn Powell /* Granule management service feature register definitions. */ 116*c359aeb1SJohn Powell #define FIRME_GM_GPI_SET_BIT BIT(0) 117*c359aeb1SJohn Powell #define FIRME_GM_GPI_OP_CONTINUE_BIT BIT(1) 118*c359aeb1SJohn Powell #define FIRME_GM_L1_CREATE_BIT BIT(2) 119*c359aeb1SJohn Powell #define FIRME_GM_L1_DESTROY_BIT BIT(3) 120*c359aeb1SJohn Powell #define FIRME_GM_PPS_SHIFT U(6) 121*c359aeb1SJohn Powell #define FIRME_GM_PPS_MASK U(0x7) 122*c359aeb1SJohn Powell #define FIRME_GM_L0GPTSZ_SHIFT U(2) 123*c359aeb1SJohn Powell #define FIRME_GM_L0GPTSZ_MASK U(0xF) 124*c359aeb1SJohn Powell #define FIRME_GM_PGS_SHIFT U(0) 125*c359aeb1SJohn Powell #define FIRME_GM_PGS_MASK U(0x3) 126*c359aeb1SJohn Powell 127*c359aeb1SJohn Powell /* 128*c359aeb1SJohn Powell * FIRME_SERVICE_VERSION 129*c359aeb1SJohn Powell * 130*c359aeb1SJohn Powell * This function returns the supported version for a specified 131*c359aeb1SJohn Powell * FIRME service. 132*c359aeb1SJohn Powell * 133*c359aeb1SJohn Powell * Arguments 134*c359aeb1SJohn Powell * arg0(w0): Function ID 0xC4000400 135*c359aeb1SJohn Powell * arg1(x1): Service ID bits[63:0] Unused 136*c359aeb1SJohn Powell * bits[7:0] ID of FIRME service 137*c359aeb1SJohn Powell * 138*c359aeb1SJohn Powell * Return 139*c359aeb1SJohn Powell * ret0(w0): Success bits[31] Set to indicate negative value 140*c359aeb1SJohn Powell * bits[30:16] Major version 141*c359aeb1SJohn Powell * bits[15:0] Minor version 142*c359aeb1SJohn Powell * Failure Negative value encodes FIRME_NOT_SUPPORTED 143*c359aeb1SJohn Powell */ 144*c359aeb1SJohn Powell #define FIRME_SERVICE_VERSION_FID SMC64_FIRME_FID(U(0)) 145*c359aeb1SJohn Powell 146*c359aeb1SJohn Powell /* 147*c359aeb1SJohn Powell * FIRME_FEATURES 148*c359aeb1SJohn Powell * 149*c359aeb1SJohn Powell * This function returns the features supported by the FIRME interface. 150*c359aeb1SJohn Powell * 151*c359aeb1SJohn Powell * Supported from v1.0 152*c359aeb1SJohn Powell * 153*c359aeb1SJohn Powell * Arguments 154*c359aeb1SJohn Powell * arg0(w0): Function ID 0xC4000401. 155*c359aeb1SJohn Powell * arg1(w1): Index Index of the feature register to be returned to the 156*c359aeb1SJohn Powell * caller. Current supported values are 0, 1, and 2. 157*c359aeb1SJohn Powell * All others reserved. 158*c359aeb1SJohn Powell * 159*c359aeb1SJohn Powell * Return 160*c359aeb1SJohn Powell * ret0(x0): Status FIRME_SUCCESS 161*c359aeb1SJohn Powell * FIRME_NOT_SUPPORTED 162*c359aeb1SJohn Powell * FIRME_INVALID_PARAMETERS 163*c359aeb1SJohn Powell * ret1(x1): Requested feature register if successful. 164*c359aeb1SJohn Powell */ 165*c359aeb1SJohn Powell #define FIRME_SERVICE_FEATURES_FID SMC64_FIRME_FID(U(1)) 166*c359aeb1SJohn Powell 167*c359aeb1SJohn Powell /* 168*c359aeb1SJohn Powell * FIRME_GM_GPI_SET 169*c359aeb1SJohn Powell * 170*c359aeb1SJohn Powell * This function requests a GPI transition for a set of physically contiguous 171*c359aeb1SJohn Powell * granules of memory. 172*c359aeb1SJohn Powell * 173*c359aeb1SJohn Powell * Supported from v1.0 174*c359aeb1SJohn Powell * 175*c359aeb1SJohn Powell * Arguments 176*c359aeb1SJohn Powell * arg0(w0): Function ID 0xC4000402 177*c359aeb1SJohn Powell * arg1(x1): Base Address Physical base address of the granules whose GPI 178*c359aeb1SJohn Powell * encoding must be changed. 179*c359aeb1SJohn Powell * arg2(x2): Granule Count Number of granules GPI to change starting from 180*c359aeb1SJohn Powell * base address. 181*c359aeb1SJohn Powell * arg3(x3): Attributes bits[63:4] Reserved 182*c359aeb1SJohn Powell * bits[3:0] Target GPI encoding of the granules. 183*c359aeb1SJohn Powell * 184*c359aeb1SJohn Powell * Return 185*c359aeb1SJohn Powell * ret0(x0): Status FIRME_SUCCESS 186*c359aeb1SJohn Powell * FIRME_NOT_SUPPORTED 187*c359aeb1SJohn Powell * FIRME_INVALID_PARAMETERS 188*c359aeb1SJohn Powell * FIRME_DENIED 189*c359aeb1SJohn Powell * FIRME_RETRY 190*c359aeb1SJohn Powell * ret1(x1): Count of granules whose GPI encoding was change. 191*c359aeb1SJohn Powell */ 192*c359aeb1SJohn Powell #define FIRME_GM_GPI_SET_FID SMC64_FIRME_FID(U(0x2)) 193*c359aeb1SJohn Powell 194*c359aeb1SJohn Powell /* These are unimplemented so far and will be added in the future. */ 195*c359aeb1SJohn Powell 196*c359aeb1SJohn Powell /* Granule management service ABIs */ 197*c359aeb1SJohn Powell #define FIRME_GM_GPI_OP_CONTINUE SMC64_FIRME_FID(U(0x12)) 198*c359aeb1SJohn Powell #define FIRME_GM_L1_GPT_CREATE SMC64_FIRME_FID(U(0xE)) 199*c359aeb1SJohn Powell #define FIRME_GM_L1_GPT_DESTROY SMC64_FIRME_FID(U(0xF)) 200*c359aeb1SJohn Powell 201*c359aeb1SJohn Powell /* IDE key management service */ 202*c359aeb1SJohn Powell #define FIRME_IDE_KEYSET_PROG SMC64_FIRME_FID(U(0x3)) 203*c359aeb1SJohn Powell #define FIRME_IDE_KEYSET_GO SMC64_FIRME_FID(U(0x4)) 204*c359aeb1SJohn Powell #define FIRME_IDE_KEYSET_STOP SMC64_FIRME_FID(U(0x5)) 205*c359aeb1SJohn Powell #define FIRME_IDE_KEYSET_POLL SMC64_FIRME_FID(U(0x6)) 206*c359aeb1SJohn Powell 207*c359aeb1SJohn Powell /* MECID management service */ 208*c359aeb1SJohn Powell #define FIRME_MEC_REFRESH SMC64_FIRME_FID(U(0x7)) 209*c359aeb1SJohn Powell 210*c359aeb1SJohn Powell /* Attestation service */ 211*c359aeb1SJohn Powell #define FIRME_ATTEST_PAT_GET SMC64_FIRME_FID(U(0x8)) 212*c359aeb1SJohn Powell #define FIRME_ATTEST_RAK_GET SMC64_FIRME_FID(U(0x9)) 213*c359aeb1SJohn Powell #define FIRME_ATTEST_RAT_SIGN SMC64_FIRME_FID(U(0xA)) 214*c359aeb1SJohn Powell #define FIRME_ATTEST_PAT_EXT_CLAIMS_STAGE SMC64_FIRME_FID(U(0xB)) 215*c359aeb1SJohn Powell #define FIRME_ATTEST_PAT_EXT_CLAIMS_CLEAR SMC64_FIRME_FID(U(0xC)) 216*c359aeb1SJohn Powell #define FIRME_ATTEST_PAT_EXT_CLAIMS_FINALISE SMC64_FIRME_FID(U(0xD)) 217*c359aeb1SJohn Powell 218*c359aeb1SJohn Powell /* Integrated device management service */ 219*c359aeb1SJohn Powell #define FIRME_IDEV_OP_START SMC64_FIRME_FID(U(0x10)) 220*c359aeb1SJohn Powell #define FIRME_IDEV_OP_CONTINUE SMC64_FIRME_FID(U(0x11)) 221*c359aeb1SJohn Powell 222*c359aeb1SJohn Powell /* Top level handler for FIRME SMC calls. */ 223*c359aeb1SJohn Powell uint64_t firme_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, 224*c359aeb1SJohn Powell uint64_t x4, void *cookie, void *handle, uint64_t flags); 225*c359aeb1SJohn Powell 226*c359aeb1SJohn Powell firme_service_info_t *firme_granule_mgmt_service_get_info(void); 227*c359aeb1SJohn Powell 228*c359aeb1SJohn Powell u_register_t firme_base_service_handler(firme_instance_e instance, uint32_t smc_fid, 229*c359aeb1SJohn Powell uint64_t x1, uint64_t x2, uint64_t x3, 230*c359aeb1SJohn Powell uint64_t x4, void *cookie, void *handle, 231*c359aeb1SJohn Powell uint64_t flags); 232*c359aeb1SJohn Powell 233*c359aeb1SJohn Powell u_register_t firme_granule_mgmt_service_handler(firme_instance_e instance, 234*c359aeb1SJohn Powell uint32_t smc_fid, uint64_t x1, 235*c359aeb1SJohn Powell uint64_t x2, uint64_t x3, 236*c359aeb1SJohn Powell uint64_t x4, void *cookie, 237*c359aeb1SJohn Powell void *handle, uint64_t flags); 238*c359aeb1SJohn Powell 239*c359aeb1SJohn Powell #endif /* FIRME_SVC_H */ 240