xref: /rk3399_ARM-atf/plat/xilinx/versal_net/sip_svc_setup.c (revision fffde230ba23ae55c1f8a83310f4d7972088c0d2)
11d333e69SMichal Simek /*
2619bc13eSMichal Simek  * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
31d333e69SMichal Simek  * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
4c26aa08bSJay Buddhabhatti  * Copyright (c) 2022-2024, 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>
124a50363aSMichal Simek #include <inttypes.h>
138529c769SMichal Simek 
141d333e69SMichal Simek #include <common/debug.h>
151d333e69SMichal Simek #include <common/runtime_svc.h>
161d333e69SMichal Simek #include <tools_share/uuid.h>
171d333e69SMichal Simek 
180bf622deSMichal Simek #include "ipi_mailbox_svc.h"
198529c769SMichal Simek #include "plat_private.h"
208529c769SMichal Simek #include "pm_svc_main.h"
218529c769SMichal Simek 
221d333e69SMichal Simek /* SMC function IDs for SiP Service queries */
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)
28c26aa08bSJay Buddhabhatti #define SIP_SVC_VERSION_MINOR		(2U)
291d333e69SMichal Simek 
300bf622deSMichal Simek /* These macros are used to identify PM calls from the SMC function ID */
314a50363aSMichal Simek #define SIP_FID_MASK	GENMASK(23, 16)
324a50363aSMichal Simek #define XLNX_FID_MASK	GENMASK(23, 12)
330bf622deSMichal Simek #define PM_FID_VALUE	0u
340bf622deSMichal Simek #define IPI_FID_VALUE	0x1000u
354a50363aSMichal Simek #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
364a50363aSMichal Simek #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
370bf622deSMichal Simek 
381d333e69SMichal Simek /* SiP Service UUID */
391d333e69SMichal Simek DEFINE_SVC_UUID2(versal_net_sip_uuid,
40*baeeaddfSMaheedhar Bollapalli 		0x80d4c25au, 0xebaf, 0x11eb, 0x94, 0x68,
411d333e69SMichal Simek 		0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60);
421d333e69SMichal Simek 
431d333e69SMichal Simek /**
441d333e69SMichal Simek  * sip_svc_setup() - Setup SiP Service
45de7ed953SPrasad Kummari  *
46de7ed953SPrasad Kummari  * Return: 0 on success, negative error code on failure.
47de7ed953SPrasad Kummari  *
481d333e69SMichal Simek  */
sip_svc_setup(void)491d333e69SMichal Simek static int32_t sip_svc_setup(void)
501d333e69SMichal Simek {
518529c769SMichal Simek 	return sip_svc_setup_init();
521d333e69SMichal Simek }
531d333e69SMichal Simek 
541d333e69SMichal Simek /*
551d333e69SMichal Simek  * sip_svc_smc_handler() - Top-level SiP Service SMC handler
561d333e69SMichal Simek  *
571d333e69SMichal Simek  * Handler for all SiP SMC calls. Handles standard SIP requests
581d333e69SMichal Simek  * and calls PM SMC handler if the call is for a PM-API function.
591d333e69SMichal Simek  */
sip_svc_smc_handler(uint32_t smc_fid,u_register_t x1,u_register_t x2,u_register_t x3,u_register_t x4,void * cookie,void * handle,u_register_t flags)601d333e69SMichal Simek static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
611d333e69SMichal Simek 			     u_register_t x1,
621d333e69SMichal Simek 			     u_register_t x2,
631d333e69SMichal Simek 			     u_register_t x3,
641d333e69SMichal Simek 			     u_register_t x4,
651d333e69SMichal Simek 			     void *cookie,
661d333e69SMichal Simek 			     void *handle,
671d333e69SMichal Simek 			     u_register_t flags)
681d333e69SMichal Simek {
694a50363aSMichal Simek 	VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
704a50363aSMichal Simek 		smc_fid, x1, x2, x3, x4);
714a50363aSMichal Simek 
7283c3c36bSMaheedhar Bollapalli 	if ((smc_fid & SIP_FID_MASK) != 0U) {
734a50363aSMichal Simek 		WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
744a50363aSMichal Simek 		SMC_RET1(handle, SMC_UNK);
754a50363aSMichal Simek 	}
764a50363aSMichal Simek 
771d333e69SMichal Simek 	/* Let PM SMC handler deal with PM-related requests */
780bf622deSMichal Simek 	if (is_pm_fid(smc_fid)) {
790bf622deSMichal Simek 		return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
800bf622deSMichal Simek 				flags);
810bf622deSMichal Simek 	}
820bf622deSMichal Simek 
830bf622deSMichal Simek 	/* Let IPI SMC handler deal with IPI-related requests if platform */
840bf622deSMichal Simek 	if (is_ipi_fid(smc_fid)) {
850bf622deSMichal Simek 		return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
860bf622deSMichal Simek 	}
870bf622deSMichal Simek 
880bf622deSMichal Simek 	/* Let PM SMC handler deal with PM-related requests */
891d333e69SMichal Simek 	switch (smc_fid) {
901d333e69SMichal Simek 	case VERSAL_NET_SIP_SVC_UID:
911d333e69SMichal Simek 		SMC_UUID_RET(handle, versal_net_sip_uuid);
921d333e69SMichal Simek 
931d333e69SMichal Simek 	case VERSAL_NET_SIP_SVC_VERSION:
941d333e69SMichal Simek 		SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
951d333e69SMichal Simek 
961d333e69SMichal Simek 	default:
971d333e69SMichal Simek 		WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
981d333e69SMichal Simek 		SMC_RET1(handle, SMC_UNK);
991d333e69SMichal Simek 	}
1001d333e69SMichal Simek }
1011d333e69SMichal Simek 
1021d333e69SMichal Simek /* Register PM Service Calls as runtime service */
1031d333e69SMichal Simek DECLARE_RT_SVC(
1041d333e69SMichal Simek 		sip_svc,
1051d333e69SMichal Simek 		OEN_SIP_START,
1061d333e69SMichal Simek 		OEN_SIP_END,
1071d333e69SMichal Simek 		SMC_TYPE_FAST,
1081d333e69SMichal Simek 		sip_svc_setup,
1091d333e69SMichal Simek 		sip_svc_smc_handler);
110