blob: 0c27dec5901a742432aee9d6d79b1f8575e006e2 [file] [log] [blame]
Michal Simek91794362022-08-31 16:45:14 +02001/*
Michal Simek2a47faa2023-04-14 08:43:51 +02002 * Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.
Michal Simek91794362022-08-31 16:45:14 +02003 * Copyright (c) 2018-2022, Xilinx, Inc. All rights reserved.
Michal Simek01297072023-04-25 14:14:06 +02004 * Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved.
Michal Simek91794362022-08-31 16:45:14 +02005 *
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
Michal Simekdc708ac2022-09-19 13:52:54 +020011#include <errno.h>
Michal Simek6e45f942023-02-15 12:39:22 +010012#include <inttypes.h>
Michal Simekdc708ac2022-09-19 13:52:54 +020013
Michal Simek91794362022-08-31 16:45:14 +020014#include <common/debug.h>
15#include <common/runtime_svc.h>
16#include <tools_share/uuid.h>
17
Michal Simekaa5443e2022-09-19 14:04:55 +020018#include "ipi_mailbox_svc.h"
Michal Simekdc708ac2022-09-19 13:52:54 +020019#include "plat_private.h"
20#include "pm_svc_main.h"
21
Michal Simek91794362022-08-31 16:45:14 +020022/* SMC function IDs for SiP Service queries */
23#define VERSAL_NET_SIP_SVC_CALL_COUNT (0x8200ff00U)
24#define VERSAL_NET_SIP_SVC_UID (0x8200ff01U)
25#define VERSAL_NET_SIP_SVC_VERSION (0x8200ff03U)
26
27/* SiP Service Calls version numbers */
28#define SIP_SVC_VERSION_MAJOR (0U)
29#define SIP_SVC_VERSION_MINOR (1U)
30
Michal Simekaa5443e2022-09-19 14:04:55 +020031/* These macros are used to identify PM calls from the SMC function ID */
Michal Simek6e45f942023-02-15 12:39:22 +010032#define SIP_FID_MASK GENMASK(23, 16)
33#define XLNX_FID_MASK GENMASK(23, 12)
Michal Simekaa5443e2022-09-19 14:04:55 +020034#define PM_FID_VALUE 0u
35#define IPI_FID_VALUE 0x1000u
Michal Simek6e45f942023-02-15 12:39:22 +010036#define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
37#define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
Michal Simekaa5443e2022-09-19 14:04:55 +020038
Michal Simek91794362022-08-31 16:45:14 +020039/* SiP Service UUID */
40DEFINE_SVC_UUID2(versal_net_sip_uuid,
41 0x80d4c25a, 0xebaf, 0x11eb, 0x94, 0x68,
42 0x0b, 0x4e, 0x3b, 0x8f, 0xc3, 0x60);
43
44/**
45 * sip_svc_setup() - Setup SiP Service
Prasad Kummari7d0623a2023-06-09 14:32:00 +053046 *
47 * Return: 0 on success, negative error code on failure.
48 *
Michal Simek91794362022-08-31 16:45:14 +020049 */
50static int32_t sip_svc_setup(void)
51{
Michal Simekdc708ac2022-09-19 13:52:54 +020052 return sip_svc_setup_init();
Michal Simek91794362022-08-31 16:45:14 +020053}
54
55/*
56 * sip_svc_smc_handler() - Top-level SiP Service SMC handler
57 *
58 * Handler for all SiP SMC calls. Handles standard SIP requests
59 * and calls PM SMC handler if the call is for a PM-API function.
60 */
61static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
62 u_register_t x1,
63 u_register_t x2,
64 u_register_t x3,
65 u_register_t x4,
66 void *cookie,
67 void *handle,
68 u_register_t flags)
69{
Michal Simek6e45f942023-02-15 12:39:22 +010070 VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
71 smc_fid, x1, x2, x3, x4);
72
73 if (smc_fid & SIP_FID_MASK) {
74 WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
75 SMC_RET1(handle, SMC_UNK);
76 }
77
Michal Simek91794362022-08-31 16:45:14 +020078 /* Let PM SMC handler deal with PM-related requests */
Michal Simekaa5443e2022-09-19 14:04:55 +020079 if (is_pm_fid(smc_fid)) {
80 return smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
81 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 */
Michal Simek91794362022-08-31 16:45:14 +020090 switch (smc_fid) {
91 case VERSAL_NET_SIP_SVC_CALL_COUNT:
92 /* PM functions + default functions */
93 SMC_RET1(handle, 2);
94
95 case VERSAL_NET_SIP_SVC_UID:
96 SMC_UUID_RET(handle, versal_net_sip_uuid);
97
98 case VERSAL_NET_SIP_SVC_VERSION:
99 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
100
101 default:
102 WARN("Unimplemented SiP Service Call: 0x%x\n", smc_fid);
103 SMC_RET1(handle, SMC_UNK);
104 }
105}
106
107/* Register PM Service Calls as runtime service */
108DECLARE_RT_SVC(
109 sip_svc,
110 OEN_SIP_START,
111 OEN_SIP_END,
112 SMC_TYPE_FAST,
113 sip_svc_setup,
114 sip_svc_smc_handler);