xref: /rk3399_ARM-atf/plat/xilinx/versal/sip_svc_setup.c (revision ab43d15b9137cf8def6d97ee878d60cad48ae770)
1 /*
2  * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
8 
9 #include <common/debug.h>
10 #include <common/runtime_svc.h>
11 #include <tools_share/uuid.h>
12 #include "pm_svc_main.h"
13 
14 /* SMC function IDs for SiP Service queries */
15 #define VERSAL_SIP_SVC_CALL_COUNT	0x8200ff00
16 #define VERSAL_SIP_SVC_UID		0x8200ff01
17 #define VERSAL_SIP_SVC_VERSION		0x8200ff03
18 
19 /* SiP Service Calls version numbers */
20 #define SIP_SVC_VERSION_MAJOR	0
21 #define SIP_SVC_VERSION_MINOR	1
22 
23 /* These macros are used to identify PM calls from the SMC function ID */
24 #define PM_FID_MASK	0xf000u
25 #define PM_FID_VALUE	0u
26 #define is_pm_fid(_fid) (((_fid) & PM_FID_MASK) == PM_FID_VALUE)
27 
28 /* SiP Service UUID */
29 DEFINE_SVC_UUID2(versal_sip_uuid,
30 		0x2ab9e4ec, 0x93b9, 0x11e7, 0xa0, 0x19,
31 		0xdf, 0xe0, 0xdb, 0xad, 0x0a, 0xe0);
32 
33 /**
34  * sip_svc_setup() - Setup SiP Service
35  *
36  * Invokes PM setup
37  */
38 static int32_t sip_svc_setup(void)
39 {
40 	/* PM implementation as SiP Service */
41 	pm_setup();
42 
43 	return 0;
44 }
45 
46 /**
47  * sip_svc_smc_handler() - Top-level SiP Service SMC handler
48  *
49  * Handler for all SiP SMC calls. Handles standard SIP requests
50  * and calls PM SMC handler if the call is for a PM-API function.
51  */
52 uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
53 			     u_register_t x1,
54 			     u_register_t x2,
55 			     u_register_t x3,
56 			     u_register_t x4,
57 			     void *cookie,
58 			     void *handle,
59 			     u_register_t flags)
60 {
61 	/* Let PM SMC handler deal with PM-related requests */
62 	if (is_pm_fid(smc_fid)) {
63 		return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
64 				      flags);
65 	}
66 
67 	/* Let PM SMC handler deal with PM-related requests */
68 	switch (smc_fid) {
69 	case VERSAL_SIP_SVC_CALL_COUNT:
70 		/* PM functions + default functions */
71 		SMC_RET1(handle, 2);
72 
73 	case VERSAL_SIP_SVC_UID:
74 		SMC_UUID_RET(handle, versal_sip_uuid);
75 
76 	case VERSAL_SIP_SVC_VERSION:
77 		SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
78 
79 	default:
80 		WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
81 		SMC_RET1(handle, SMC_UNK);
82 	}
83 }
84 
85 /* Register PM Service Calls as runtime service */
86 DECLARE_RT_SVC(
87 		sip_svc,
88 		OEN_SIP_START,
89 		OEN_SIP_END,
90 		SMC_TYPE_FAST,
91 		sip_svc_setup,
92 		sip_svc_smc_handler);
93