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