1de6b79d8SGovindraj Raja /* 2de6b79d8SGovindraj Raja * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. 3de6b79d8SGovindraj Raja * 4de6b79d8SGovindraj Raja * SPDX-License-Identifier: BSD-3-Clause 5de6b79d8SGovindraj Raja */ 6de6b79d8SGovindraj Raja 7de6b79d8SGovindraj Raja #include <stdint.h> 8de6b79d8SGovindraj Raja 9de6b79d8SGovindraj Raja #include <common/debug.h> 10de6b79d8SGovindraj Raja #include <common/runtime_svc.h> 11273b8983SGovindraj Raja #include <lib/debugfs.h> 12*f7679d43SGovindraj Raja #include <lib/pmf/pmf.h> 13de6b79d8SGovindraj Raja #include <services/ven_el3_svc.h> 14de6b79d8SGovindraj Raja #include <tools_share/uuid.h> 15de6b79d8SGovindraj Raja 16de6b79d8SGovindraj Raja /* vendor-specific EL3 UUID */ 17de6b79d8SGovindraj Raja DEFINE_SVC_UUID2(ven_el3_svc_uid, 18de6b79d8SGovindraj Raja 0xb6011dca, 0x57c4, 0x407e, 0x83, 0xf0, 19de6b79d8SGovindraj Raja 0xa7, 0xed, 0xda, 0xf0, 0xdf, 0x6c); 20de6b79d8SGovindraj Raja 21de6b79d8SGovindraj Raja static int ven_el3_svc_setup(void) 22de6b79d8SGovindraj Raja { 23273b8983SGovindraj Raja #if USE_DEBUGFS 24273b8983SGovindraj Raja if (debugfs_smc_setup() != 0) { 25273b8983SGovindraj Raja return 1; 26273b8983SGovindraj Raja } 27273b8983SGovindraj Raja #endif /* USE_DEBUGFS */ 28273b8983SGovindraj Raja 29*f7679d43SGovindraj Raja #if ENABLE_PMF 30*f7679d43SGovindraj Raja if (pmf_setup() != 0) { 31*f7679d43SGovindraj Raja return 1; 32*f7679d43SGovindraj Raja } 33*f7679d43SGovindraj Raja #endif /* ENABLE_PMF */ 34*f7679d43SGovindraj Raja 35de6b79d8SGovindraj Raja return 0; 36de6b79d8SGovindraj Raja } 37de6b79d8SGovindraj Raja 38de6b79d8SGovindraj Raja /* 39de6b79d8SGovindraj Raja * This function handles Arm defined vendor-specific EL3 Service Calls. 40de6b79d8SGovindraj Raja */ 41de6b79d8SGovindraj Raja static uintptr_t ven_el3_svc_handler(unsigned int smc_fid, 42de6b79d8SGovindraj Raja u_register_t x1, 43de6b79d8SGovindraj Raja u_register_t x2, 44de6b79d8SGovindraj Raja u_register_t x3, 45de6b79d8SGovindraj Raja u_register_t x4, 46de6b79d8SGovindraj Raja void *cookie, 47de6b79d8SGovindraj Raja void *handle, 48de6b79d8SGovindraj Raja u_register_t flags) 49de6b79d8SGovindraj Raja { 50273b8983SGovindraj Raja #if USE_DEBUGFS 51273b8983SGovindraj Raja /* 52273b8983SGovindraj Raja * Dispatch debugfs calls to debugfs SMC handler and return its 53273b8983SGovindraj Raja * return value. 54273b8983SGovindraj Raja */ 55273b8983SGovindraj Raja if (is_debugfs_fid(smc_fid)) { 56273b8983SGovindraj Raja return debugfs_smc_handler(smc_fid, x1, x2, x3, x4, cookie, 57273b8983SGovindraj Raja handle, flags); 58273b8983SGovindraj Raja } 59273b8983SGovindraj Raja #endif /* USE_DEBUGFS */ 60273b8983SGovindraj Raja 61*f7679d43SGovindraj Raja #if ENABLE_PMF 62*f7679d43SGovindraj Raja 63*f7679d43SGovindraj Raja /* 64*f7679d43SGovindraj Raja * Dispatch PMF calls to PMF SMC handler and return its return 65*f7679d43SGovindraj Raja * value 66*f7679d43SGovindraj Raja */ 67*f7679d43SGovindraj Raja if (is_pmf_fid(smc_fid)) { 68*f7679d43SGovindraj Raja return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie, 69*f7679d43SGovindraj Raja handle, flags); 70*f7679d43SGovindraj Raja } 71*f7679d43SGovindraj Raja 72*f7679d43SGovindraj Raja #endif /* ENABLE_PMF */ 73*f7679d43SGovindraj Raja 74de6b79d8SGovindraj Raja switch (smc_fid) { 75de6b79d8SGovindraj Raja case VEN_EL3_SVC_UID: 76de6b79d8SGovindraj Raja /* Return UID to the caller */ 77de6b79d8SGovindraj Raja SMC_UUID_RET(handle, ven_el3_svc_uid); 78de6b79d8SGovindraj Raja break; 79de6b79d8SGovindraj Raja case VEN_EL3_SVC_VERSION: 80de6b79d8SGovindraj Raja SMC_RET2(handle, VEN_EL3_SVC_VERSION_MAJOR, VEN_EL3_SVC_VERSION_MINOR); 81de6b79d8SGovindraj Raja break; 82de6b79d8SGovindraj Raja default: 83273b8983SGovindraj Raja WARN("Unimplemented vendor-specific EL3 Service call: 0x%x\n", smc_fid); 84de6b79d8SGovindraj Raja SMC_RET1(handle, SMC_UNK); 85de6b79d8SGovindraj Raja break; 86de6b79d8SGovindraj Raja } 87de6b79d8SGovindraj Raja } 88de6b79d8SGovindraj Raja 89de6b79d8SGovindraj Raja /* Define a runtime service descriptor for fast SMC calls */ 90de6b79d8SGovindraj Raja DECLARE_RT_SVC( 91de6b79d8SGovindraj Raja ven_el3_svc, 92de6b79d8SGovindraj Raja OEN_VEN_EL3_START, 93de6b79d8SGovindraj Raja OEN_VEN_EL3_END, 94de6b79d8SGovindraj Raja SMC_TYPE_FAST, 95de6b79d8SGovindraj Raja ven_el3_svc_setup, 96de6b79d8SGovindraj Raja ven_el3_svc_handler 97de6b79d8SGovindraj Raja ); 98