1 /*
2 * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
3 * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
4 * Copyright (c) 2022-2025, Advanced Micro Devices, Inc. All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 /* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
10
11 #include <errno.h>
12 #include <inttypes.h>
13
14 #include <common/debug.h>
15 #include <common/runtime_svc.h>
16 #include <drivers/scmi-msg.h>
17 #include <scmi.h>
18 #include <tools_share/uuid.h>
19
20 #include <custom_svc.h>
21 #include "ipi_mailbox_svc.h"
22 #include "plat_private.h"
23 #include "pm_svc_main.h"
24
25 /* SMC function IDs for SiP Service queries */
26 #define SIP_SVC_UID (0x8200ff01U)
27 #define SIP_SVC_VERSION (0x8200ff03U)
28
29 /* SiP Service Calls version numbers */
30 #define SIP_SVC_VERSION_MAJOR (0U)
31 #define SIP_SVC_VERSION_MINOR (2U)
32
33 /* These macros are used to identify PM calls from the SMC function ID */
34 #define SIP_FID_MASK GENMASK(23, 16)
35 #define XLNX_FID_MASK GENMASK(23, 12)
36 #define PM_FID_VALUE 0u
37 #define IPI_FID_VALUE 0x1000u
38 #define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
39 #define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
40
41 /* SiP Service UUID */
42 DEFINE_SVC_UUID2(_sip_uuid,
43 0x0499eb70, 0x5ed0, 0x11ee, 0xb3, 0x0a,
44 0x87, 0xd1, 0x1d, 0x4f, 0x8a, 0x9b);
45
46 /**
47 * sip_svc_setup() - Setup SiP Service
48 *
49 * Return: 0 on success, negative error code on failure.
50 *
51 */
sip_svc_setup(void)52 static int32_t sip_svc_setup(void)
53 {
54 return sip_svc_setup_init();
55 }
56
57 /*
58 * sip_svc_smc_handler() - Top-level SiP Service SMC handler
59 *
60 * Handler for all SiP SMC calls. Handles standard SIP requests
61 * and calls PM SMC handler if the call is for a PM-API function.
62 */
sip_svc_smc_handler(uint32_t 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)63 static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
64 u_register_t x1,
65 u_register_t x2,
66 u_register_t x3,
67 u_register_t x4,
68 void *cookie,
69 void *handle,
70 u_register_t flags)
71 {
72 VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
73 smc_fid, x1, x2, x3, x4);
74
75 if ((smc_fid & SIP_FID_MASK) != 0U) {
76 WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
77 SMC_RET1(handle, SMC_UNK);
78 }
79
80 /* Let PM SMC handler deal with PM-related requests */
81 if (is_pm_fid(smc_fid)) {
82 return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
83 }
84
85 /* Let IPI SMC handler deal with IPI-related requests if platform */
86 if (is_ipi_fid(smc_fid)) {
87 return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
88 }
89
90 /* Let PM SMC handler deal with PM-related requests */
91 switch (smc_fid) {
92 case SIP_SVC_UID:
93 SMC_UUID_RET(handle, _sip_uuid);
94
95 case SIP_SVC_VERSION:
96 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
97
98 #if (TFA_NO_PM == 1)
99 case SIP_SCMI:
100 if (platform_id != EMU) {
101 scmi_smt_fastcall_smc_entry(0);
102 SMC_RET1(handle, 0);
103 }
104 WARN("SCMI is not working on EMU\n");
105 SMC_RET1(handle, SMC_UNK);
106 #endif
107 case SOC_SIP_SVC_CUSTOM:
108 case SOC_SIP_SVC64_CUSTOM:
109 return custom_smc_handler(smc_fid, x1, x2, x3, x4,
110 cookie, handle, flags);
111 default:
112 WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
113 SMC_RET1(handle, SMC_UNK);
114 }
115 }
116
117 /* Register PM Service Calls as runtime service */
118 DECLARE_RT_SVC(
119 sip_svc,
120 OEN_SIP_START,
121 OEN_SIP_END,
122 SMC_TYPE_FAST,
123 sip_svc_setup,
124 sip_svc_smc_handler);
125