1 /* 2 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. 3 * Copyright (c) 2023, Advanced Micro Devices Inc. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */ 9 10 #include <inttypes.h> 11 12 #include <common/runtime_svc.h> 13 #include <tools_share/uuid.h> 14 15 #include <custom_svc.h> 16 #include "ipi_mailbox_svc.h" 17 #include "pm_svc_main.h" 18 19 /* SMC function IDs for SiP Service queries */ 20 #define ZYNQMP_SIP_SVC_CALL_COUNT U(0x8200ff00) 21 #define ZYNQMP_SIP_SVC_UID U(0x8200ff01) 22 #define ZYNQMP_SIP_SVC_VERSION U(0x8200ff03) 23 24 /* SiP Service Calls version numbers */ 25 #define SIP_SVC_VERSION_MAJOR 0 26 #define SIP_SVC_VERSION_MINOR 1 27 28 /* These macros are used to identify PM, IPI calls from the SMC function ID */ 29 #define SIP_FID_MASK GENMASK(23, 16) 30 #define XLNX_FID_MASK GENMASK(23, 12) 31 #define PM_FID_VALUE 0u 32 #define IPI_FID_VALUE 0x1000u 33 #define EM_FID_VALUE 0x3000u 34 #define is_em_fid(_fid) (((_fid) & XLNX_FID_MASK) == EM_FID_VALUE) 35 #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE) 36 #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE) 37 38 /* SiP Service UUID */ 39 DEFINE_SVC_UUID2(zynqmp_sip_uuid, 40 0x5c9b1b2a, 0x0586, 0x2340, 0xa6, 0x1b, 41 0xb9, 0x25, 0x82, 0x2d, 0xe3, 0xa5); 42 43 /** 44 * sip_svc_setup() - Setup SiP Service 45 * 46 * Invokes PM setup 47 */ 48 static int32_t sip_svc_setup(void) 49 { 50 /* PM implementation as SiP Service */ 51 return pm_setup(); 52 } 53 54 /** 55 * sip_svc_smc_handler() - Top-level SiP Service SMC handler 56 * 57 * Handler for all SiP SMC calls. Handles standard SIP requests 58 * and calls PM SMC handler if the call is for a PM-API function. 59 */ 60 static uintptr_t sip_svc_smc_handler(uint32_t smc_fid, 61 u_register_t x1, 62 u_register_t x2, 63 u_register_t x3, 64 u_register_t x4, 65 void *cookie, 66 void *handle, 67 u_register_t flags) 68 { 69 VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n", 70 smc_fid, x1, x2, x3, x4); 71 72 if (smc_fid & SIP_FID_MASK) { 73 WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid); 74 SMC_RET1(handle, SMC_UNK); 75 } 76 77 /* Let EM SMC handler deal with EM-related requests */ 78 if (is_em_fid(smc_fid)) { 79 return em_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 80 flags); 81 } 82 83 /* Let PM SMC handler deal with PM-related requests */ 84 if (is_pm_fid(smc_fid)) { 85 return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 86 flags); 87 } 88 89 /* Let IPI SMC handler deal with IPI-related requests */ 90 if (is_ipi_fid(smc_fid)) { 91 return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 92 flags); 93 } 94 95 switch (smc_fid) { 96 case ZYNQMP_SIP_SVC_CALL_COUNT: 97 /* PM functions + default functions */ 98 SMC_RET1(handle, PM_API_MAX + 2); 99 100 case ZYNQMP_SIP_SVC_UID: 101 SMC_UUID_RET(handle, zynqmp_sip_uuid); 102 103 case ZYNQMP_SIP_SVC_VERSION: 104 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR); 105 106 case ZYNQMP_SIP_SVC_CUSTOM: 107 case ZYNQMP_SIP_SVC64_CUSTOM: 108 return custom_smc_handler(smc_fid, x1, x2, x3, x4, cookie, 109 handle, flags); 110 111 default: 112 WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid); 113 SMC_RET1(handle, SMC_UNK); 114 } 115 } 116 117 /* Register PM Service Calls as runtime service */ 118 DECLARE_RT_SVC( 119 sip_svc, 120 OEN_SIP_START, 121 OEN_SIP_END, 122 (uint8_t)SMC_TYPE_FAST, 123 sip_svc_setup, 124 sip_svc_smc_handler); 125