blob: c928e43bd793f68d55519fd609c9b17c7a2ed4eb [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Venkatesh Yadav Abbarapu7ace4af2020-11-23 04:26:54 -08002 * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
Michal Simek249e0042023-02-20 12:53:31 +01003 * Copyright (c) 2023, Advanced Micro Devices Inc. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08006 */
7
8/* Top level SMC handler for SiP calls. Dispatch PM calls to PM SMC handler. */
9
Michal Simekdb988fe2023-02-14 13:10:29 +010010#include <inttypes.h>
11
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <common/runtime_svc.h>
13#include <tools_share/uuid.h>
14
Amit Nagalf7ecba32023-02-15 18:43:55 +053015#include <custom_svc.h>
Wendy Liangf8fec362017-09-06 09:39:55 -070016#include "ipi_mailbox_svc.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080017#include "pm_svc_main.h"
18
19/* SMC function IDs for SiP Service queries */
Venkatesh Yadav Abbarapued4f1e82022-04-29 09:58:30 +053020#define ZYNQMP_SIP_SVC_CALL_COUNT U(0x8200ff00)
21#define ZYNQMP_SIP_SVC_UID U(0x8200ff01)
22#define ZYNQMP_SIP_SVC_VERSION U(0x8200ff03)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080023
24/* SiP Service Calls version numbers */
25#define SIP_SVC_VERSION_MAJOR 0
26#define SIP_SVC_VERSION_MINOR 1
27
Wendy Liangf8fec362017-09-06 09:39:55 -070028/* These macros are used to identify PM, IPI calls from the SMC function ID */
Michal Simekdb988fe2023-02-14 13:10:29 +010029#define SIP_FID_MASK GENMASK(23, 16)
30#define XLNX_FID_MASK GENMASK(23, 12)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080031#define PM_FID_VALUE 0u
Wendy Liangf8fec362017-09-06 09:39:55 -070032#define IPI_FID_VALUE 0x1000u
Michal Simek249e0042023-02-20 12:53:31 +010033#define EM_FID_VALUE 0x3000u
Michal Simekdb988fe2023-02-14 13:10:29 +010034#define is_em_fid(_fid) (((_fid) & XLNX_FID_MASK) == EM_FID_VALUE)
35#define is_pm_fid(_fid) (((_fid) & XLNX_FID_MASK) == PM_FID_VALUE)
36#define is_ipi_fid(_fid) (((_fid) & XLNX_FID_MASK) == IPI_FID_VALUE)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080037
38/* SiP Service UUID */
Roberto Vargaseace8f12018-04-26 13:36:53 +010039DEFINE_SVC_UUID2(zynqmp_sip_uuid,
40 0x5c9b1b2a, 0x0586, 0x2340, 0xa6, 0x1b,
41 0xb9, 0x25, 0x82, 0x2d, 0xe3, 0xa5);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080042
43/**
44 * sip_svc_setup() - Setup SiP Service
45 *
46 * Invokes PM setup
47 */
48static int32_t sip_svc_setup(void)
49{
50 /* PM implementation as SiP Service */
Rajan Vaja720fd9d2018-10-05 04:42:57 -070051 return pm_setup();
Soren Brinkmann76fcae32016-03-06 20:16:27 -080052}
53
54/**
55 * sip_svc_smc_handler() - Top-level SiP Service SMC handler
56 *
57 * Handler for all SiP SMC calls. Handles standard SIP requests
58 * and calls PM SMC handler if the call is for a PM-API function.
59 */
Venkatesh Yadav Abbarapuc9505352022-05-16 17:29:04 +053060static uintptr_t sip_svc_smc_handler(uint32_t smc_fid,
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090061 u_register_t x1,
62 u_register_t x2,
63 u_register_t x3,
64 u_register_t x4,
65 void *cookie,
66 void *handle,
67 u_register_t flags)
Soren Brinkmann76fcae32016-03-06 20:16:27 -080068{
Michal Simekdb988fe2023-02-14 13:10:29 +010069 VERBOSE("SMCID: 0x%08x, x1: 0x%016" PRIx64 ", x2: 0x%016" PRIx64 ", x3: 0x%016" PRIx64 ", x4: 0x%016" PRIx64 "\n",
70 smc_fid, x1, x2, x3, x4);
71
Michal Simekdb988fe2023-02-14 13:10:29 +010072 if (smc_fid & SIP_FID_MASK) {
73 WARN("SMC out of SiP assinged range: 0x%x\n", smc_fid);
74 SMC_RET1(handle, SMC_UNK);
75 }
76
Michal Simek249e0042023-02-20 12:53:31 +010077 /* Let EM SMC handler deal with EM-related requests */
78 if (is_em_fid(smc_fid)) {
79 return em_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
80 flags);
81 }
82
Soren Brinkmann76fcae32016-03-06 20:16:27 -080083 /* Let PM SMC handler deal with PM-related requests */
Michal Simekdb455e12023-02-14 08:06:17 +010084 if (is_pm_fid(smc_fid)) {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080085 return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
86 flags);
87 }
88
Wendy Liangf8fec362017-09-06 09:39:55 -070089 /* Let IPI SMC handler deal with IPI-related requests */
90 if (is_ipi_fid(smc_fid)) {
91 return ipi_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle,
92 flags);
93 }
94
Soren Brinkmann76fcae32016-03-06 20:16:27 -080095 switch (smc_fid) {
96 case ZYNQMP_SIP_SVC_CALL_COUNT:
97 /* PM functions + default functions */
98 SMC_RET1(handle, PM_API_MAX + 2);
99
100 case ZYNQMP_SIP_SVC_UID:
101 SMC_UUID_RET(handle, zynqmp_sip_uuid);
102
103 case ZYNQMP_SIP_SVC_VERSION:
104 SMC_RET2(handle, SIP_SVC_VERSION_MAJOR, SIP_SVC_VERSION_MINOR);
105
Amit Nagalf7ecba32023-02-15 18:43:55 +0530106 case ZYNQMP_SIP_SVC_CUSTOM:
107 case ZYNQMP_SIP_SVC64_CUSTOM:
108 return custom_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
109 handle, flags);
110
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800111 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 */
118DECLARE_RT_SVC(
119 sip_svc,
120 OEN_SIP_START,
121 OEN_SIP_END,
Venkatesh Yadav Abbarapu336f9f82022-04-28 16:39:07 +0530122 (uint8_t)SMC_TYPE_FAST,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800123 sip_svc_setup,
124 sip_svc_smc_handler);