xref: /rk3399_ARM-atf/plat/hisilicon/hikey/hisi_sip_svc.c (revision 9f505cc22a40e969963a7fe8d9c9d0e702ff0fcb)
1*9f505cc2SVincent Guittot /*
2*9f505cc2SVincent Guittot  * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
3*9f505cc2SVincent Guittot  *
4*9f505cc2SVincent Guittot  * SPDX-License-Identifier: BSD-3-Clause
5*9f505cc2SVincent Guittot  */
6*9f505cc2SVincent Guittot 
7*9f505cc2SVincent Guittot #include <hisi_sip_svc.h>
8*9f505cc2SVincent Guittot #include <debug.h>
9*9f505cc2SVincent Guittot #include <pmf.h>
10*9f505cc2SVincent Guittot #include <runtime_svc.h>
11*9f505cc2SVincent Guittot #include <stdint.h>
12*9f505cc2SVincent Guittot #include <uuid.h>
13*9f505cc2SVincent Guittot 
14*9f505cc2SVincent Guittot 
15*9f505cc2SVincent Guittot /* Hisi SiP Service UUID */
16*9f505cc2SVincent Guittot DEFINE_SVC_UUID(hisi_sip_svc_uid,
17*9f505cc2SVincent Guittot 		0xe599df74, 0x7682, 0x40aa, 0x9f, 0xf8,
18*9f505cc2SVincent Guittot 		0xc0, 0x85, 0x52, 0xbc, 0x39, 0x3f);
19*9f505cc2SVincent Guittot 
20*9f505cc2SVincent Guittot static int hisi_sip_setup(void)
21*9f505cc2SVincent Guittot {
22*9f505cc2SVincent Guittot 	if (pmf_setup() != 0)
23*9f505cc2SVincent Guittot 		return 1;
24*9f505cc2SVincent Guittot 	return 0;
25*9f505cc2SVincent Guittot }
26*9f505cc2SVincent Guittot 
27*9f505cc2SVincent Guittot /*
28*9f505cc2SVincent Guittot  * This function handles Hisi defined SiP Calls
29*9f505cc2SVincent Guittot  */
30*9f505cc2SVincent Guittot static uintptr_t hisi_sip_handler(unsigned int smc_fid,
31*9f505cc2SVincent Guittot 			u_register_t x1,
32*9f505cc2SVincent Guittot 			u_register_t x2,
33*9f505cc2SVincent Guittot 			u_register_t x3,
34*9f505cc2SVincent Guittot 			u_register_t x4,
35*9f505cc2SVincent Guittot 			void *cookie,
36*9f505cc2SVincent Guittot 			void *handle,
37*9f505cc2SVincent Guittot 			u_register_t flags)
38*9f505cc2SVincent Guittot {
39*9f505cc2SVincent Guittot 	int call_count = 0;
40*9f505cc2SVincent Guittot 
41*9f505cc2SVincent Guittot 	/*
42*9f505cc2SVincent Guittot 	 * Dispatch PMF calls to PMF SMC handler and return its return
43*9f505cc2SVincent Guittot 	 * value
44*9f505cc2SVincent Guittot 	 */
45*9f505cc2SVincent Guittot 	if (is_pmf_fid(smc_fid)) {
46*9f505cc2SVincent Guittot 		return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
47*9f505cc2SVincent Guittot 				handle, flags);
48*9f505cc2SVincent Guittot 	}
49*9f505cc2SVincent Guittot 
50*9f505cc2SVincent Guittot 	switch (smc_fid) {
51*9f505cc2SVincent Guittot 	case HISI_SIP_SVC_CALL_COUNT:
52*9f505cc2SVincent Guittot 		/* PMF calls */
53*9f505cc2SVincent Guittot 		call_count += PMF_NUM_SMC_CALLS;
54*9f505cc2SVincent Guittot 
55*9f505cc2SVincent Guittot 		/* State switch call */
56*9f505cc2SVincent Guittot 		call_count += 1;
57*9f505cc2SVincent Guittot 
58*9f505cc2SVincent Guittot 		SMC_RET1(handle, call_count);
59*9f505cc2SVincent Guittot 
60*9f505cc2SVincent Guittot 	case HISI_SIP_SVC_UID:
61*9f505cc2SVincent Guittot 		/* Return UID to the caller */
62*9f505cc2SVincent Guittot 		SMC_UUID_RET(handle, hisi_sip_svc_uid);
63*9f505cc2SVincent Guittot 
64*9f505cc2SVincent Guittot 	case HISI_SIP_SVC_VERSION:
65*9f505cc2SVincent Guittot 		/* Return the version of current implementation */
66*9f505cc2SVincent Guittot 		SMC_RET2(handle, HISI_SIP_SVC_VERSION_MAJOR, HISI_SIP_SVC_VERSION_MINOR);
67*9f505cc2SVincent Guittot 
68*9f505cc2SVincent Guittot 	default:
69*9f505cc2SVincent Guittot 		WARN("Unimplemented HISI SiP Service Call: 0x%x \n", smc_fid);
70*9f505cc2SVincent Guittot 		SMC_RET1(handle, SMC_UNK);
71*9f505cc2SVincent Guittot 	}
72*9f505cc2SVincent Guittot 
73*9f505cc2SVincent Guittot }
74*9f505cc2SVincent Guittot 
75*9f505cc2SVincent Guittot 
76*9f505cc2SVincent Guittot /* Define a runtime service descriptor for fast SMC calls */
77*9f505cc2SVincent Guittot DECLARE_RT_SVC(
78*9f505cc2SVincent Guittot 	hisi_sip_svc,
79*9f505cc2SVincent Guittot 	OEN_SIP_START,
80*9f505cc2SVincent Guittot 	OEN_SIP_END,
81*9f505cc2SVincent Guittot 	SMC_TYPE_FAST,
82*9f505cc2SVincent Guittot 	hisi_sip_setup,
83*9f505cc2SVincent Guittot 	hisi_sip_handler
84*9f505cc2SVincent Guittot );
85