xref: /rk3399_ARM-atf/plat/xilinx/versal/sip_svc_setup.c (revision c73a90e571e763e3afc1d9cbef09e7d134b25af8)
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 	switch (smc_fid) {
63 	case VERSAL_SIP_SVC_CALL_COUNT:
64 		/* PM functions + default functions */
65 		SMC_RET1(handle, 2);
66 
67 	case VERSAL_SIP_SVC_UID:
68 		SMC_UUID_RET(handle, versal_sip_uuid);
69 
70 	case VERSAL_SIP_SVC_VERSION:
71 		SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
72 
73 	default:
74 		WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
75 		SMC_RET1(handle, SMC_UNK);
76 	}
77 }
78 
79 /* Register PM Service Calls as runtime service */
80 DECLARE_RT_SVC(
81 		sip_svc,
82 		OEN_SIP_START,
83 		OEN_SIP_END,
84 		SMC_TYPE_FAST,
85 		sip_svc_setup,
86 		sip_svc_smc_handler);
87