11d333e69SMichal Simek /* 21d333e69SMichal Simek * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. 31d333e69SMichal Simek * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved. 41d333e69SMichal Simek * Copyright (C) 2022, Advanced Micro Devices, Inc. All rights reserved. 51d333e69SMichal Simek * 61d333e69SMichal Simek * SPDX-License-Identifier: BSD-3-Clause 71d333e69SMichal Simek */ 81d333e69SMichal Simek 91d333e69SMichal Simek /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */ 101d333e69SMichal Simek 118529c769SMichal Simek #include <errno.h> 128529c769SMichal Simek 131d333e69SMichal Simek #include <common/debug.h> 141d333e69SMichal Simek #include <common/runtime_svc.h> 151d333e69SMichal Simek #include <tools_share/uuid.h> 161d333e69SMichal Simek 17*0bf622deSMichal Simek #include "ipi_mailbox_svc.h" 188529c769SMichal Simek #include "plat_private.h" 198529c769SMichal Simek #include "pm_svc_main.h" 208529c769SMichal Simek 211d333e69SMichal Simek /* SMC function IDs for SiP Service queries */ 221d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_CALL_COUNT (0x8200ff00U) 231d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_UID (0x8200ff01U) 241d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_VERSION (0x8200ff03U) 251d333e69SMichal Simek 261d333e69SMichal Simek /* SiP Service Calls version numbers */ 271d333e69SMichal Simek #define SIP_SVC_VERSION_MAJOR (0U) 281d333e69SMichal Simek #define SIP_SVC_VERSION_MINOR (1U) 291d333e69SMichal Simek 30*0bf622deSMichal Simek /* These macros are used to identify PM calls from the SMC function ID */ 31*0bf622deSMichal Simek #define PM_FID_MASK 0xf000u 32*0bf622deSMichal Simek #define PM_FID_VALUE 0u 33*0bf622deSMichal Simek #define IPI_FID_VALUE 0x1000u 34*0bf622deSMichal Simek #define is_pm_fid(_fid) (((_fid) & PM_FID_MASK) == PM_FID_VALUE) 35*0bf622deSMichal Simek #define is_ipi_fid(_fid) (((_fid) & PM_FID_MASK) == IPI_FID_VALUE) 36*0bf622deSMichal Simek 371d333e69SMichal Simek /* SiP Service UUID */ 381d333e69SMichal Simek DEFINE_SVC_UUID2(versal_net_sip_uuid, 391d333e69SMichal Simek 0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68, 401d333e69SMichal Simek 0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60); 411d333e69SMichal Simek 421d333e69SMichal Simek /** 431d333e69SMichal Simek * sip_svc_setup() - Setup SiP Service 441d333e69SMichal Simek */ 451d333e69SMichal Simek static int32_t sip_svc_setup(void) 461d333e69SMichal Simek { 478529c769SMichal Simek return sip_svc_setup_init(); 481d333e69SMichal Simek } 491d333e69SMichal Simek 501d333e69SMichal Simek /* 511d333e69SMichal Simek * sip_svc_smc_handler() - Top-level SiP Service SMC handler 521d333e69SMichal Simek * 531d333e69SMichal Simek * Handler for all SiP SMC calls. Handles standard SIP requests 541d333e69SMichal Simek * and calls PM SMC handler if the call is for a PM-API function. 551d333e69SMichal Simek */ 561d333e69SMichal Simek static uintptr_t sip_svc_smc_handler(uint32_t smc_fid, 571d333e69SMichal Simek u_register_t x1, 581d333e69SMichal Simek u_register_t x2, 591d333e69SMichal Simek u_register_t x3, 601d333e69SMichal Simek u_register_t x4, 611d333e69SMichal Simek void *cookie, 621d333e69SMichal Simek void *handle, 631d333e69SMichal Simek u_register_t flags) 641d333e69SMichal Simek { 651d333e69SMichal Simek /* Let PM SMC handler deal with PM-related requests */ 66*0bf622deSMichal Simek if (is_pm_fid(smc_fid)) { 67*0bf622deSMichal Simek return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 68*0bf622deSMichal Simek flags); 69*0bf622deSMichal Simek } 70*0bf622deSMichal Simek 71*0bf622deSMichal Simek /* Let IPI SMC handler deal with IPI-related requests if platform */ 72*0bf622deSMichal Simek if (is_ipi_fid(smc_fid)) { 73*0bf622deSMichal Simek return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); 74*0bf622deSMichal Simek } 75*0bf622deSMichal Simek 76*0bf622deSMichal Simek /* Let PM SMC handler deal with PM-related requests */ 771d333e69SMichal Simek switch (smc_fid) { 781d333e69SMichal Simek case VERSAL_NET_SIP_SVC_CALL_COUNT: 791d333e69SMichal Simek /* PM functions + default functions */ 801d333e69SMichal Simek SMC_RET1(handle, 2); 811d333e69SMichal Simek 821d333e69SMichal Simek case VERSAL_NET_SIP_SVC_UID: 831d333e69SMichal Simek SMC_UUID_RET(handle, versal_net_sip_uuid); 841d333e69SMichal Simek 851d333e69SMichal Simek case VERSAL_NET_SIP_SVC_VERSION: 861d333e69SMichal Simek SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR); 871d333e69SMichal Simek 881d333e69SMichal Simek default: 891d333e69SMichal Simek WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid); 901d333e69SMichal Simek SMC_RET1(handle, SMC_UNK); 911d333e69SMichal Simek } 921d333e69SMichal Simek } 931d333e69SMichal Simek 941d333e69SMichal Simek /* Register PM Service Calls as runtime service */ 951d333e69SMichal Simek DECLARE_RT_SVC( 961d333e69SMichal Simek sip_svc, 971d333e69SMichal Simek OEN_SIP_START, 981d333e69SMichal Simek OEN_SIP_END, 991d333e69SMichal Simek SMC_TYPE_FAST, 1001d333e69SMichal Simek sip_svc_setup, 1011d333e69SMichal Simek sip_svc_smc_handler); 102