1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved. 4*91f16700Schasinglulu * 5*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 6*91f16700Schasinglulu */ 7*91f16700Schasinglulu 8*91f16700Schasinglulu /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */ 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <inttypes.h> 11*91f16700Schasinglulu 12*91f16700Schasinglulu #include <common/debug.h> 13*91f16700Schasinglulu #include <common/runtime_svc.h> 14*91f16700Schasinglulu #include <tools_share/uuid.h> 15*91f16700Schasinglulu 16*91f16700Schasinglulu #include "ipi_mailbox_svc.h" 17*91f16700Schasinglulu #include "pm_svc_main.h" 18*91f16700Schasinglulu 19*91f16700Schasinglulu /* SMC function IDs for SiP Service queries */ 20*91f16700Schasinglulu #define VERSAL_SIP_SVC_CALL_COUNT U(0x8200ff00) 21*91f16700Schasinglulu #define VERSAL_SIP_SVC_UID U(0x8200ff01) 22*91f16700Schasinglulu #define VERSAL_SIP_SVC_VERSION U(0x8200ff03) 23*91f16700Schasinglulu 24*91f16700Schasinglulu /* SiP Service Calls version numbers */ 25*91f16700Schasinglulu #define SIP_SVC_VERSION_MAJOR U(0) 26*91f16700Schasinglulu #define SIP_SVC_VERSION_MINOR U(1) 27*91f16700Schasinglulu 28*91f16700Schasinglulu /* These macros are used to identify PM calls from the SMC function ID */ 29*91f16700Schasinglulu #define SIP_FID_MASK GENMASK(23, 16) 30*91f16700Schasinglulu #define XLNX_FID_MASK GENMASK(23, 12) 31*91f16700Schasinglulu #define PM_FID_VALUE 0u 32*91f16700Schasinglulu #define IPI_FID_VALUE 0x1000u 33*91f16700Schasinglulu #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE) 34*91f16700Schasinglulu #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE) 35*91f16700Schasinglulu 36*91f16700Schasinglulu /* SiP Service UUID */ 37*91f16700Schasinglulu DEFINE_SVC_UUID2(versal_sip_uuid, 38*91f16700Schasinglulu 0x2ab9e4ecU, 0x93b9U, 0x11e7U, 0xa0U, 0x19U, 39*91f16700Schasinglulu 0xdfU, 0xe0U, 0xdbU, 0xadU, 0x0aU, 0xe0U); 40*91f16700Schasinglulu 41*91f16700Schasinglulu /** 42*91f16700Schasinglulu * sip_svc_setup() - Setup SiP Service 43*91f16700Schasinglulu * 44*91f16700Schasinglulu * Return: 0 on success,negative error code on failure. 45*91f16700Schasinglulu * 46*91f16700Schasinglulu * Invokes PM setup. 47*91f16700Schasinglulu */ 48*91f16700Schasinglulu static int32_t sip_svc_setup(void) 49*91f16700Schasinglulu { 50*91f16700Schasinglulu /* PM implementation as SiP Service */ 51*91f16700Schasinglulu (void)pm_setup(); 52*91f16700Schasinglulu 53*91f16700Schasinglulu return 0; 54*91f16700Schasinglulu } 55*91f16700Schasinglulu 56*91f16700Schasinglulu /** 57*91f16700Schasinglulu * sip_svc_smc_handler() - Top-level SiP Service SMC handler. 58*91f16700Schasinglulu * @smc_fid: Function Identifier. 59*91f16700Schasinglulu * @x1: SMC64 Arguments 1 from kernel. 60*91f16700Schasinglulu * @x2: SMC64 Arguments 2 from kernel. 61*91f16700Schasinglulu * @x3: SMC64 Arguments 3 from kernel(upper 32-bits). 62*91f16700Schasinglulu * @x4: SMC64 Arguments 4 from kernel. 63*91f16700Schasinglulu * @cookie: Unused 64*91f16700Schasinglulu * @handle: Pointer to caller's context structure. 65*91f16700Schasinglulu * @flags: SECURE_FLAG or NON_SECURE_FLAG. 66*91f16700Schasinglulu * 67*91f16700Schasinglulu * Handler for all SiP SMC calls. Handles standard SIP requests 68*91f16700Schasinglulu * and calls PM SMC handler if the call is for a PM-API function. 69*91f16700Schasinglulu * 70*91f16700Schasinglulu * Return: Unused. 71*91f16700Schasinglulu */ 72*91f16700Schasinglulu uintptr_t sip_svc_smc_handler(uint32_t smc_fid, 73*91f16700Schasinglulu u_register_t x1, 74*91f16700Schasinglulu u_register_t x2, 75*91f16700Schasinglulu u_register_t x3, 76*91f16700Schasinglulu u_register_t x4, 77*91f16700Schasinglulu void *cookie, 78*91f16700Schasinglulu void *handle, 79*91f16700Schasinglulu u_register_t flags) 80*91f16700Schasinglulu { 81*91f16700Schasinglulu VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n", 82*91f16700Schasinglulu smc_fid, x1, x2, x3, x4); 83*91f16700Schasinglulu 84*91f16700Schasinglulu if (smc_fid & SIP_FID_MASK) { 85*91f16700Schasinglulu WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid); 86*91f16700Schasinglulu SMC_RET1(handle, SMC_UNK); 87*91f16700Schasinglulu } 88*91f16700Schasinglulu 89*91f16700Schasinglulu /* Let PM SMC handler deal with PM-related requests */ 90*91f16700Schasinglulu if (is_pm_fid(smc_fid)) { 91*91f16700Schasinglulu return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 92*91f16700Schasinglulu flags); 93*91f16700Schasinglulu } 94*91f16700Schasinglulu 95*91f16700Schasinglulu /* Let IPI SMC handler deal with IPI-related requests */ 96*91f16700Schasinglulu if (is_ipi_fid(smc_fid)) { 97*91f16700Schasinglulu return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, 98*91f16700Schasinglulu flags); 99*91f16700Schasinglulu } 100*91f16700Schasinglulu 101*91f16700Schasinglulu /* Let PM SMC handler deal with PM-related requests */ 102*91f16700Schasinglulu switch (smc_fid) { 103*91f16700Schasinglulu case VERSAL_SIP_SVC_CALL_COUNT: 104*91f16700Schasinglulu /* PM functions + default functions */ 105*91f16700Schasinglulu SMC_RET1(handle, 2); 106*91f16700Schasinglulu 107*91f16700Schasinglulu case VERSAL_SIP_SVC_UID: 108*91f16700Schasinglulu SMC_UUID_RET(handle, versal_sip_uuid); 109*91f16700Schasinglulu 110*91f16700Schasinglulu case VERSAL_SIP_SVC_VERSION: 111*91f16700Schasinglulu SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR); 112*91f16700Schasinglulu 113*91f16700Schasinglulu default: 114*91f16700Schasinglulu WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid); 115*91f16700Schasinglulu SMC_RET1(handle, SMC_UNK); 116*91f16700Schasinglulu } 117*91f16700Schasinglulu } 118*91f16700Schasinglulu 119*91f16700Schasinglulu /* Register PM Service Calls as runtime service */ 120*91f16700Schasinglulu DECLARE_RT_SVC( 121*91f16700Schasinglulu sip_svc, 122*91f16700Schasinglulu OEN_SIP_START, 123*91f16700Schasinglulu OEN_SIP_END, 124*91f16700Schasinglulu SMC_TYPE_FAST, 125*91f16700Schasinglulu sip_svc_setup, 126*91f16700Schasinglulu sip_svc_smc_handler); 127