Debian Codegraph @

plat/amd/versal2/sip_svc_setup.c

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