1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved. 4*91f16700Schasinglulu * Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved. 5*91f16700Schasinglulu * 6*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 7*91f16700Schasinglulu */ 8*91f16700Schasinglulu 9*91f16700Schasinglulu /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */ 10*91f16700Schasinglulu 11*91f16700Schasinglulu #include <errno.h> 12*91f16700Schasinglulu #include <inttypes.h> 13*91f16700Schasinglulu 14*91f16700Schasinglulu #include <common/debug.h> 15*91f16700Schasinglulu #include <common/runtime_svc.h> 16*91f16700Schasinglulu #include <tools_share/uuid.h> 17*91f16700Schasinglulu 18*91f16700Schasinglulu #include "ipi_mailbox_svc.h" 19*91f16700Schasinglulu #include "plat_private.h" 20*91f16700Schasinglulu #include "pm_svc_main.h" 21*91f16700Schasinglulu 22*91f16700Schasinglulu /* SMC function IDs for SiP Service queries */ 23*91f16700Schasinglulu #define VERSAL_NET_SIP_SVC_CALL_COUNT (0x8200ff00U) 24*91f16700Schasinglulu #define VERSAL_NET_SIP_SVC_UID (0x8200ff01U) 25*91f16700Schasinglulu #define VERSAL_NET_SIP_SVC_VERSION (0x8200ff03U) 26*91f16700Schasinglulu 27*91f16700Schasinglulu /* SiP Service Calls version numbers */ 28*91f16700Schasinglulu #define SIP_SVC_VERSION_MAJOR (0U) 29*91f16700Schasinglulu #define SIP_SVC_VERSION_MINOR (1U) 30*91f16700Schasinglulu 31*91f16700Schasinglulu /* These macros are used to identify PM calls from the SMC function ID */ 32*91f16700Schasinglulu #define SIP_FID_MASK GENMASK(23, 16) 33*91f16700Schasinglulu #define XLNX_FID_MASK GENMASK(23, 12) 34*91f16700Schasinglulu #define PM_FID_VALUE 0u 35*91f16700Schasinglulu #define IPI_FID_VALUE 0x1000u 36*91f16700Schasinglulu #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE) 37*91f16700Schasinglulu #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE) 38*91f16700Schasinglulu 39*91f16700Schasinglulu /* SiP Service UUID */ 40*91f16700Schasinglulu DEFINE_SVC_UUID2(versal_net_sip_uuid, 41*91f16700Schasinglulu 0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68, 42*91f16700Schasinglulu 0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60); 43*91f16700Schasinglulu 44*91f16700Schasinglulu /** 45*91f16700Schasinglulu * sip_svc_setup() - Setup SiP Service 46*91f16700Schasinglulu * 47*91f16700Schasinglulu * Return: 0 on success, negative error code on failure. 48*91f16700Schasinglulu * 49*91f16700Schasinglulu */ 50*91f16700Schasinglulu static int32_t sip_svc_setup(void) 51*91f16700Schasinglulu { 52*91f16700Schasinglulu return sip_svc_setup_init(); 53*91f16700Schasinglulu } 54*91f16700Schasinglulu 55*91f16700Schasinglulu /* 56*91f16700Schasinglulu * sip_svc_smc_handler() - Top-level SiP Service SMC handler 57*91f16700Schasinglulu * 58*91f16700Schasinglulu * Handler for all SiP SMC calls. Handles standard SIP requests 59*91f16700Schasinglulu * and calls PM SMC handler if the call is for a PM-API function. 60*91f16700Schasinglulu */ 61*91f16700Schasinglulu static uintptr_t sip_svc_smc_handler(uint32_t smc_fid, 62*91f16700Schasinglulu u_register_t x1, 63*91f16700Schasinglulu u_register_t x2, 64*91f16700Schasinglulu u_register_t x3, 65*91f16700Schasinglulu u_register_t x4, 66*91f16700Schasinglulu void *cookie, 67*91f16700Schasinglulu void *handle, 68*91f16700Schasinglulu u_register_t flags) 69*91f16700Schasinglulu { 70*91f16700Schasinglulu VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n", 71*91f16700Schasinglulu smc_fid, x1, x2, x3, x4); 72*91f16700Schasinglulu 73*91f16700Schasinglulu if (smc_fid & SIP_FID_MASK) { 74*91f16700Schasinglulu WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid); 75*91f16700Schasinglulu SMC_RET1(handle, SMC_UNK); 76*91f16700Schasinglulu } 77*91f16700Schasinglulu 78*91f16700Schasinglulu /* Let PM SMC handler deal with PM-related requests */ 79*91f16700Schasinglulu if (is_pm_fid(smc_fid)) { 80*91f16700Schasinglulu return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 81*91f16700Schasinglulu flags); 82*91f16700Schasinglulu } 83*91f16700Schasinglulu 84*91f16700Schasinglulu /* Let IPI SMC handler deal with IPI-related requests if platform */ 85*91f16700Schasinglulu if (is_ipi_fid(smc_fid)) { 86*91f16700Schasinglulu return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); 87*91f16700Schasinglulu } 88*91f16700Schasinglulu 89*91f16700Schasinglulu /* Let PM SMC handler deal with PM-related requests */ 90*91f16700Schasinglulu switch (smc_fid) { 91*91f16700Schasinglulu case VERSAL_NET_SIP_SVC_CALL_COUNT: 92*91f16700Schasinglulu /* PM functions + default functions */ 93*91f16700Schasinglulu SMC_RET1(handle, 2); 94*91f16700Schasinglulu 95*91f16700Schasinglulu case VERSAL_NET_SIP_SVC_UID: 96*91f16700Schasinglulu SMC_UUID_RET(handle, versal_net_sip_uuid); 97*91f16700Schasinglulu 98*91f16700Schasinglulu case VERSAL_NET_SIP_SVC_VERSION: 99*91f16700Schasinglulu SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR); 100*91f16700Schasinglulu 101*91f16700Schasinglulu default: 102*91f16700Schasinglulu WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid); 103*91f16700Schasinglulu SMC_RET1(handle, SMC_UNK); 104*91f16700Schasinglulu } 105*91f16700Schasinglulu } 106*91f16700Schasinglulu 107*91f16700Schasinglulu /* Register PM Service Calls as runtime service */ 108*91f16700Schasinglulu DECLARE_RT_SVC( 109*91f16700Schasinglulu sip_svc, 110*91f16700Schasinglulu OEN_SIP_START, 111*91f16700Schasinglulu OEN_SIP_END, 112*91f16700Schasinglulu SMC_TYPE_FAST, 113*91f16700Schasinglulu sip_svc_setup, 114*91f16700Schasinglulu sip_svc_smc_handler); 115