xref: /rk3399_ARM-atf/plat/xilinx/versal_net/sip_svc_setup.c (revision 8529c7694f8d614e76dcc80b394ec8a6751df44c)
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 
11*8529c769SMichal Simek #include <errno.h>
12*8529c769SMichal Simek 
131d333e69SMichal Simek #include <common/debug.h>
141d333e69SMichal Simek #include <common/runtime_svc.h>
151d333e69SMichal Simek #include <tools_share/uuid.h>
161d333e69SMichal Simek 
17*8529c769SMichal Simek #include "plat_private.h"
18*8529c769SMichal Simek #include "pm_svc_main.h"
19*8529c769SMichal Simek 
201d333e69SMichal Simek /* SMC function IDs for SiP Service queries */
211d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_CALL_COUNT	(0x8200ff00U)
221d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_UID		(0x8200ff01U)
231d333e69SMichal Simek #define VERSAL_NET_SIP_SVC_VERSION	(0x8200ff03U)
241d333e69SMichal Simek 
251d333e69SMichal Simek /* SiP Service Calls version numbers */
261d333e69SMichal Simek #define SIP_SVC_VERSION_MAJOR		(0U)
271d333e69SMichal Simek #define SIP_SVC_VERSION_MINOR		(1U)
281d333e69SMichal Simek 
291d333e69SMichal Simek /* SiP Service UUID */
301d333e69SMichal Simek DEFINE_SVC_UUID2(versal_net_sip_uuid,
311d333e69SMichal Simek 		0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68,
321d333e69SMichal Simek 		0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60);
331d333e69SMichal Simek 
341d333e69SMichal Simek /**
351d333e69SMichal Simek  * sip_svc_setup() - Setup SiP Service
361d333e69SMichal Simek  */
371d333e69SMichal Simek static int32_t sip_svc_setup(void)
381d333e69SMichal Simek {
39*8529c769SMichal Simek 	return sip_svc_setup_init();
401d333e69SMichal Simek }
411d333e69SMichal Simek 
421d333e69SMichal Simek /*
431d333e69SMichal Simek  * sip_svc_smc_handler() - Top-level SiP Service SMC handler
441d333e69SMichal Simek  *
451d333e69SMichal Simek  * Handler for all SiP SMC calls. Handles standard SIP requests
461d333e69SMichal Simek  * and calls PM SMC handler if the call is for a PM-API function.
471d333e69SMichal Simek  */
481d333e69SMichal Simek static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
491d333e69SMichal Simek 			     u_register_t x1,
501d333e69SMichal Simek 			     u_register_t x2,
511d333e69SMichal Simek 			     u_register_t x3,
521d333e69SMichal Simek 			     u_register_t x4,
531d333e69SMichal Simek 			     void *cookie,
541d333e69SMichal Simek 			     void *handle,
551d333e69SMichal Simek 			     u_register_t flags)
561d333e69SMichal Simek {
571d333e69SMichal Simek 	/* Let PM SMC handler deal with PM-related requests */
581d333e69SMichal Simek 	switch (smc_fid) {
591d333e69SMichal Simek 	case VERSAL_NET_SIP_SVC_CALL_COUNT:
601d333e69SMichal Simek 		/* PM functions + default functions */
611d333e69SMichal Simek 		SMC_RET1(handle, 2);
621d333e69SMichal Simek 
631d333e69SMichal Simek 	case VERSAL_NET_SIP_SVC_UID:
641d333e69SMichal Simek 		SMC_UUID_RET(handle, versal_net_sip_uuid);
651d333e69SMichal Simek 
661d333e69SMichal Simek 	case VERSAL_NET_SIP_SVC_VERSION:
671d333e69SMichal Simek 		SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
681d333e69SMichal Simek 
691d333e69SMichal Simek 	default:
701d333e69SMichal Simek 		WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
711d333e69SMichal Simek 		SMC_RET1(handle, SMC_UNK);
721d333e69SMichal Simek 	}
731d333e69SMichal Simek }
741d333e69SMichal Simek 
751d333e69SMichal Simek /* Register PM Service Calls as runtime service */
761d333e69SMichal Simek DECLARE_RT_SVC(
771d333e69SMichal Simek 		sip_svc,
781d333e69SMichal Simek 		OEN_SIP_START,
791d333e69SMichal Simek 		OEN_SIP_END,
801d333e69SMichal Simek 		SMC_TYPE_FAST,
811d333e69SMichal Simek 		sip_svc_setup,
821d333e69SMichal Simek 		sip_svc_smc_handler);
83