xref: /rk3399_ARM-atf/plat/hisilicon/hikey/hisi_sip_svc.c (revision 9a207532f8216bf83fed0891fed9ed0bc72ca450)
19f505cc2SVincent Guittot /*
29f505cc2SVincent Guittot  * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
39f505cc2SVincent Guittot  *
49f505cc2SVincent Guittot  * SPDX-License-Identifier: BSD-3-Clause
59f505cc2SVincent Guittot  */
69f505cc2SVincent Guittot 
79f505cc2SVincent Guittot #include <stdint.h>
89f505cc2SVincent Guittot 
9*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
10*09d40e0eSAntonio Nino Diaz #include <common/runtime_svc.h>
11*09d40e0eSAntonio Nino Diaz #include <lib/pmf/pmf.h>
12*09d40e0eSAntonio Nino Diaz #include <tools_share/uuid.h>
13*09d40e0eSAntonio Nino Diaz 
14*09d40e0eSAntonio Nino Diaz #include <hisi_sip_svc.h>
159f505cc2SVincent Guittot 
169f505cc2SVincent Guittot /* Hisi SiP Service UUID */
1703364865SRoberto Vargas DEFINE_SVC_UUID2(hisi_sip_svc_uid,
1803364865SRoberto Vargas 	0x74df99e5, 0x8276, 0xaa40, 0x9f, 0xf8,
199f505cc2SVincent Guittot 	0xc0, 0x85, 0x52, 0xbc, 0x39, 0x3f);
209f505cc2SVincent Guittot 
hisi_sip_setup(void)219f505cc2SVincent Guittot static int hisi_sip_setup(void)
229f505cc2SVincent Guittot {
239f505cc2SVincent Guittot 	if (pmf_setup() != 0)
249f505cc2SVincent Guittot 		return 1;
259f505cc2SVincent Guittot 	return 0;
269f505cc2SVincent Guittot }
279f505cc2SVincent Guittot 
289f505cc2SVincent Guittot /*
299f505cc2SVincent Guittot  * This function handles Hisi defined SiP Calls
309f505cc2SVincent Guittot  */
hisi_sip_handler(unsigned int 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)319f505cc2SVincent Guittot static uintptr_t hisi_sip_handler(unsigned int smc_fid,
329f505cc2SVincent Guittot 			u_register_t x1,
339f505cc2SVincent Guittot 			u_register_t x2,
349f505cc2SVincent Guittot 			u_register_t x3,
359f505cc2SVincent Guittot 			u_register_t x4,
369f505cc2SVincent Guittot 			void *cookie,
379f505cc2SVincent Guittot 			void *handle,
389f505cc2SVincent Guittot 			u_register_t flags)
399f505cc2SVincent Guittot {
409f505cc2SVincent Guittot 	int call_count = 0;
419f505cc2SVincent Guittot 
429f505cc2SVincent Guittot 	/*
439f505cc2SVincent Guittot 	 * Dispatch PMF calls to PMF SMC handler and return its return
449f505cc2SVincent Guittot 	 * value
459f505cc2SVincent Guittot 	 */
469f505cc2SVincent Guittot 	if (is_pmf_fid(smc_fid)) {
479f505cc2SVincent Guittot 		return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
489f505cc2SVincent Guittot 				handle, flags);
499f505cc2SVincent Guittot 	}
509f505cc2SVincent Guittot 
519f505cc2SVincent Guittot 	switch (smc_fid) {
529f505cc2SVincent Guittot 	case HISI_SIP_SVC_CALL_COUNT:
539f505cc2SVincent Guittot 		/* PMF calls */
549f505cc2SVincent Guittot 		call_count += PMF_NUM_SMC_CALLS;
559f505cc2SVincent Guittot 
569f505cc2SVincent Guittot 		/* State switch call */
579f505cc2SVincent Guittot 		call_count += 1;
589f505cc2SVincent Guittot 
599f505cc2SVincent Guittot 		SMC_RET1(handle, call_count);
609f505cc2SVincent Guittot 
619f505cc2SVincent Guittot 	case HISI_SIP_SVC_UID:
629f505cc2SVincent Guittot 		/* Return UID to the caller */
639f505cc2SVincent Guittot 		SMC_UUID_RET(handle, hisi_sip_svc_uid);
649f505cc2SVincent Guittot 
659f505cc2SVincent Guittot 	case HISI_SIP_SVC_VERSION:
669f505cc2SVincent Guittot 		/* Return the version of current implementation */
679f505cc2SVincent Guittot 		SMC_RET2(handle, HISI_SIP_SVC_VERSION_MAJOR, HISI_SIP_SVC_VERSION_MINOR);
689f505cc2SVincent Guittot 
699f505cc2SVincent Guittot 	default:
709f505cc2SVincent Guittot 		WARN("Unimplemented HISI SiP Service Call: 0x%x \n", smc_fid);
719f505cc2SVincent Guittot 		SMC_RET1(handle, SMC_UNK);
729f505cc2SVincent Guittot 	}
739f505cc2SVincent Guittot 
749f505cc2SVincent Guittot }
759f505cc2SVincent Guittot 
769f505cc2SVincent Guittot 
779f505cc2SVincent Guittot /* Define a runtime service descriptor for fast SMC calls */
789f505cc2SVincent Guittot DECLARE_RT_SVC(
799f505cc2SVincent Guittot 	hisi_sip_svc,
809f505cc2SVincent Guittot 	OEN_SIP_START,
819f505cc2SVincent Guittot 	OEN_SIP_END,
829f505cc2SVincent Guittot 	SMC_TYPE_FAST,
839f505cc2SVincent Guittot 	hisi_sip_setup,
849f505cc2SVincent Guittot 	hisi_sip_handler
859f505cc2SVincent Guittot );
86