blob: 1bd2192a61c716f51d4ef5fafef56845f1e8e357 [file] [log] [blame]
Tejas Patel354fe572018-12-14 00:55:37 -08001/*
Tanmay Shahff34daa2021-08-09 11:00:41 -07002 * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved.
Jay Buddhabhatti26e138a2022-12-21 23:03:35 -08003 * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved.
Tejas Patel354fe572018-12-14 00:55:37 -08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8/*
9 * Top-level SMC handler for Versal power management calls and
10 * IPI setup functions for communication with PMC.
11 */
12
13#include <errno.h>
14#include <plat_private.h>
Tejas Patel59c608a2019-01-09 04:10:29 -080015#include <stdbool.h>
16#include <common/runtime_svc.h>
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053017#include <plat/common/platform.h>
Tejas Patel59c608a2019-01-09 04:10:29 -080018#include "pm_api_sys.h"
Tejas Patel354fe572018-12-14 00:55:37 -080019#include "pm_client.h"
20#include "pm_ipi.h"
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060021#include <drivers/arm/gicv3.h>
Tanmay Shahfde084c2022-09-13 10:24:27 -070022#include "../drivers/arm/gic/v3/gicv3_private.h"
23
24#define MODE 0x80000000U
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060025
26#define XSCUGIC_SGIR_EL1_INITID_SHIFT 24U
Abhyuday Godhasaraedc38ae2021-08-04 23:58:46 -070027#define INVALID_SGI 0xFFU
Tanmay Shahfdae9e82022-08-26 15:06:00 -070028#define PM_INIT_SUSPEND_CB (30U)
29#define PM_NOTIFY_CB (32U)
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060030DEFINE_RENAME_SYSREG_RW_FUNCS(icc_asgi1r_el1, S3_0_C12_C11_6)
Tejas Patel354fe572018-12-14 00:55:37 -080031
Tejas Patel59c608a2019-01-09 04:10:29 -080032/* pm_up = true - UP, pm_up = false - DOWN */
33static bool pm_up;
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +053034static uint32_t sgi = (uint32_t)INVALID_SGI;
Tejas Patel59c608a2019-01-09 04:10:29 -080035
Tanmay Shahfdae9e82022-08-26 15:06:00 -070036static void notify_os(void)
37{
38 int32_t cpu;
39 uint32_t reg;
40
41 cpu = plat_my_core_pos() + 1U;
42
43 reg = (cpu | (sgi << XSCUGIC_SGIR_EL1_INITID_SHIFT));
44 write_icc_asgi1r_el1(reg);
45}
46
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053047static uint64_t ipi_fiq_handler(uint32_t id, uint32_t flags, void *handle,
48 void *cookie)
49{
Tanmay Shahfdae9e82022-08-26 15:06:00 -070050 uint32_t payload[4] = {0};
Naman Trivedi Manojbhaibeec83f2023-03-07 12:41:12 +053051 enum pm_ret_status ret;
Tanmay Shahfdae9e82022-08-26 15:06:00 -070052
53 VERBOSE("Received IPI FIQ from firmware\n");
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060054
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053055 (void)plat_ic_acknowledge_interrupt();
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060056
Naman Trivedi Manojbhaibeec83f2023-03-07 12:41:12 +053057 ret = pm_get_callbackdata(payload, ARRAY_SIZE(payload), 0, 0);
58 if (ret != PM_RET_SUCCESS) {
59 payload[0] = ret;
60 }
61
Tanmay Shahfdae9e82022-08-26 15:06:00 -070062 switch (payload[0]) {
63 case PM_INIT_SUSPEND_CB:
64 case PM_NOTIFY_CB:
65 if (sgi != INVALID_SGI) {
66 notify_os();
67 }
68 break;
Naman Trivedi Manojbhaibeec83f2023-03-07 12:41:12 +053069 case PM_RET_ERROR_INVALID_CRC:
70 pm_ipi_irq_clear(primary_proc);
71 WARN("Invalid CRC in the payload\n");
72 break;
73
Tanmay Shahfdae9e82022-08-26 15:06:00 -070074 default:
75 pm_ipi_irq_clear(primary_proc);
76 WARN("Invalid IPI payload\n");
77 break;
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060078 }
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053079
80 /* Clear FIQ */
81 plat_ic_end_of_interrupt(id);
82
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060083 return 0;
84}
85
86/**
87 * pm_register_sgi() - PM register the IPI interrupt
88 *
89 * @sgi - SGI number to be used for communication.
Venkatesh Yadav Abbarapuc8bbedc2021-04-19 07:49:57 -060090 * @reset - Reset to invalid SGI when reset=1.
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060091 * @return On success, the initialization function must return 0.
92 * Any other return value will cause the framework to ignore
93 * the service
94 *
95 * Update the SGI number to be used.
96 *
97 */
Venkatesh Yadav Abbarapu2cefbcd2022-07-31 14:05:40 +053098int32_t pm_register_sgi(uint32_t sgi_num, uint32_t reset)
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060099{
Venkatesh Yadav Abbarapuc8bbedc2021-04-19 07:49:57 -0600100 if (reset == 1U) {
101 sgi = INVALID_SGI;
102 return 0;
103 }
104
105 if (sgi != INVALID_SGI) {
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -0600106 return -EBUSY;
107 }
108
109 if (sgi_num >= GICV3_MAX_SGI_TARGETS) {
110 return -EINVAL;
111 }
112
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +0530113 sgi = (uint32_t)sgi_num;
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +0530114 return 0;
115}
116
Tejas Patel354fe572018-12-14 00:55:37 -0800117/**
118 * pm_setup() - PM service setup
119 *
120 * @return On success, the initialization function must return 0.
121 * Any other return value will cause the framework to ignore
122 * the service
123 *
124 * Initialization functions for Versal power management for
125 * communicaton with PMC.
126 *
127 * Called from sip_svc_setup initialization function with the
128 * rt_svc_init signature.
129 */
Venkatesh Yadav Abbarapu2cefbcd2022-07-31 14:05:40 +0530130int32_t pm_setup(void)
Tejas Patel354fe572018-12-14 00:55:37 -0800131{
HariBabu Gattemaa811712022-10-07 00:07:49 -0700132 int32_t ret = 0;
Tejas Patel354fe572018-12-14 00:55:37 -0800133
HariBabu Gattemaa811712022-10-07 00:07:49 -0700134 pm_ipi_init(primary_proc);
135 pm_up = true;
Tejas Patel354fe572018-12-14 00:55:37 -0800136
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +0530137 /*
138 * Enable IPI IRQ
139 * assume the rich OS is OK to handle callback IRQs now.
140 * Even if we were wrong, it would not enable the IRQ in
141 * the GIC.
142 */
143 pm_ipi_irq_enable(primary_proc);
144
145 ret = request_intr_type_el3(PLAT_VERSAL_IPI_IRQ, ipi_fiq_handler);
Abhyuday Godhasara44877942021-08-05 02:59:26 -0700146 if (ret != 0) {
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +0530147 WARN("BL31: registering IPI interrupt failed\n");
148 }
Tanmay Shahfde084c2022-09-13 10:24:27 -0700149
150 gicd_write_irouter(gicv3_driver_data->gicd_base, PLAT_VERSAL_IPI_IRQ, MODE);
Tejas Patel354fe572018-12-14 00:55:37 -0800151 return ret;
152}
Tejas Patel59c608a2019-01-09 04:10:29 -0800153
154/**
Tanmay Shahff34daa2021-08-09 11:00:41 -0700155 * eemi_for_compatibility() - EEMI calls handler for deprecated calls
Tejas Patel59c608a2019-01-09 04:10:29 -0800156 *
Tanmay Shahff34daa2021-08-09 11:00:41 -0700157 * @return - If EEMI API found then, uintptr_t type address, else 0
Tejas Patel59c608a2019-01-09 04:10:29 -0800158 *
Tanmay Shahff34daa2021-08-09 11:00:41 -0700159 * Some EEMI API's use case needs to be changed in Linux driver, so they
160 * can take advantage of common EEMI handler in TF-A. As of now the old
161 * implementation of these APIs are required to maintain backward compatibility
162 * until their use case in linux driver changes.
Tejas Patel59c608a2019-01-09 04:10:29 -0800163 */
Tanmay Shahff34daa2021-08-09 11:00:41 -0700164static uintptr_t eemi_for_compatibility(uint32_t api_id, uint32_t *pm_arg,
165 void *handle, uint32_t security_flag)
Tejas Patel59c608a2019-01-09 04:10:29 -0800166{
167 enum pm_ret_status ret;
168
Tanmay Shahff34daa2021-08-09 11:00:41 -0700169 switch (api_id) {
Tejas Patel59c608a2019-01-09 04:10:29 -0800170
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800171 case (uint32_t)PM_IOCTL:
Tejas Patel9141f442019-01-10 03:03:48 -0800172 {
Naman Patelb8434b12022-11-16 01:54:23 -0800173 uint32_t value = 0U;
Tejas Patel9141f442019-01-10 03:03:48 -0800174
175 ret = pm_api_ioctl(pm_arg[0], pm_arg[1], pm_arg[2],
Venkatesh Yadav Abbarapu4b233392021-10-20 22:11:53 -0600176 pm_arg[3], pm_arg[4],
177 &value, security_flag);
Tanmay Shahff34daa2021-08-09 11:00:41 -0700178 if (ret == PM_RET_ERROR_NOTSUPPORTED)
179 return (uintptr_t)0;
180
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530181 SMC_RET1(handle, (uint64_t)ret | ((uint64_t)value) << 32U);
Tejas Patel9141f442019-01-10 03:03:48 -0800182 }
183
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800184 case (uint32_t)PM_QUERY_DATA:
Tejas Patela3e34ad2019-02-01 17:25:19 +0530185 {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700186 uint32_t data[PAYLOAD_ARG_CNT] = { 0 };
Tejas Patela3e34ad2019-02-01 17:25:19 +0530187
188 ret = pm_query_data(pm_arg[0], pm_arg[1], pm_arg[2],
Michal Simek57cf55a2022-07-29 07:48:59 +0200189 pm_arg[3], data, security_flag);
Rajan Vaja030620d2020-11-23 04:13:54 -0800190
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530191 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)data[0] << 32U),
Michal Simek57cf55a2022-07-29 07:48:59 +0200192 (uint64_t)data[1] | ((uint64_t)data[2] << 32U));
Rajan Vaja030620d2020-11-23 04:13:54 -0800193 }
Tejas Patel59c608a2019-01-09 04:10:29 -0800194
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800195 case (uint32_t)PM_FEATURE_CHECK:
Tejas Patel59c608a2019-01-09 04:10:29 -0800196 {
Ronak Jain70d1c582022-02-04 00:42:55 -0800197 uint32_t result[PAYLOAD_ARG_CNT] = {0U};
Tejas Patel59c608a2019-01-09 04:10:29 -0800198
Ronak Jain70d1c582022-02-04 00:42:55 -0800199 ret = pm_feature_check(pm_arg[0], result, security_flag);
Venkatesh Yadav Abbarapua0657d92022-07-20 09:03:22 +0530200 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)result[0] << 32U),
201 (uint64_t)result[1] | ((uint64_t)result[2] << 32U));
Tejas Patel59c608a2019-01-09 04:10:29 -0800202 }
203
Tanmay Shahff34daa2021-08-09 11:00:41 -0700204 case PM_LOAD_PDI:
Tejas Patel59c608a2019-01-09 04:10:29 -0800205 {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700206 ret = pm_load_pdi(pm_arg[0], pm_arg[1], pm_arg[2],
207 security_flag);
208 SMC_RET1(handle, (uint64_t)ret);
209 }
Tejas Patel59c608a2019-01-09 04:10:29 -0800210
Tanmay Shahff34daa2021-08-09 11:00:41 -0700211 default:
212 return (uintptr_t)0;
Tejas Patel59c608a2019-01-09 04:10:29 -0800213 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700214}
Tejas Patel59c608a2019-01-09 04:10:29 -0800215
Tanmay Shahff34daa2021-08-09 11:00:41 -0700216/**
217 * eemi_psci_debugfs_handler() - EEMI API invoked from PSCI
218 *
219 * These EEMI APIs performs CPU specific power management tasks.
220 * These EEMI APIs are invoked either from PSCI or from debugfs in kernel.
221 * These calls require CPU specific processing before sending IPI request to
222 * Platform Management Controller. For example enable/disable CPU specific
223 * interrupts. This requires separate handler for these calls and may not be
224 * handled using common eemi handler
225 */
226static uintptr_t eemi_psci_debugfs_handler(uint32_t api_id, uint32_t *pm_arg,
227 void *handle, uint32_t security_flag)
228{
229 enum pm_ret_status ret;
Tejas Patel59c608a2019-01-09 04:10:29 -0800230
Tanmay Shahff34daa2021-08-09 11:00:41 -0700231 switch (api_id) {
Tejas Patel59c608a2019-01-09 04:10:29 -0800232
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800233 case (uint32_t)PM_SELF_SUSPEND:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700234 ret = pm_self_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
235 pm_arg[3], security_flag);
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530236 SMC_RET1(handle, (u_register_t)ret);
Tejas Patel59c608a2019-01-09 04:10:29 -0800237
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800238 case (uint32_t)PM_FORCE_POWERDOWN:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700239 ret = pm_force_powerdown(pm_arg[0], pm_arg[1], security_flag);
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530240 SMC_RET1(handle, (u_register_t)ret);
Tejas Patel84275bf2020-09-01 04:43:53 -0700241
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800242 case (uint32_t)PM_REQ_SUSPEND:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700243 ret = pm_req_suspend(pm_arg[0], pm_arg[1], pm_arg[2],
244 pm_arg[3], security_flag);
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530245 SMC_RET1(handle, (u_register_t)ret);
Tejas Patel84275bf2020-09-01 04:43:53 -0700246
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800247 case (uint32_t)PM_ABORT_SUSPEND:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700248 ret = pm_abort_suspend(pm_arg[0], security_flag);
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530249 SMC_RET1(handle, (u_register_t)ret);
Tejas Patel59c608a2019-01-09 04:10:29 -0800250
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800251 case (uint32_t)PM_SYSTEM_SHUTDOWN:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700252 ret = pm_system_shutdown(pm_arg[0], pm_arg[1], security_flag);
Venkatesh Yadav Abbarapud90e47b2022-07-28 08:50:30 +0530253 SMC_RET1(handle, (u_register_t)ret);
Tejas Patel59c608a2019-01-09 04:10:29 -0800254
Tanmay Shahff34daa2021-08-09 11:00:41 -0700255 default:
256 return (uintptr_t)0;
Tejas Patel59c608a2019-01-09 04:10:29 -0800257 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700258}
Tejas Patel59c608a2019-01-09 04:10:29 -0800259
Tanmay Shahff34daa2021-08-09 11:00:41 -0700260/**
261 * TF_A_specific_handler() - SMC handler for TF-A specific functionality
262 *
263 * These EEMI calls performs functionality that does not require
264 * IPI transaction. The handler ends in TF-A and returns requested data to
Michal Simek509bfc72022-09-14 09:32:47 +0200265 * kernel from TF-A.
Tanmay Shahff34daa2021-08-09 11:00:41 -0700266 */
267static uintptr_t TF_A_specific_handler(uint32_t api_id, uint32_t *pm_arg,
268 void *handle, uint32_t security_flag)
269{
270 switch (api_id) {
Tejas Patel59c608a2019-01-09 04:10:29 -0800271
Tanmay Shah0dde16c2021-12-14 04:53:40 -0800272 case TF_A_PM_REGISTER_SGI:
273 {
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +0530274 int32_t ret;
Tanmay Shah0dde16c2021-12-14 04:53:40 -0800275
276 ret = pm_register_sgi(pm_arg[0], pm_arg[1]);
277 if (ret != 0) {
278 SMC_RET1(handle, (uint32_t)PM_RET_ERROR_ARGS);
279 }
280
281 SMC_RET1(handle, (uint32_t)PM_RET_SUCCESS);
282 }
283
Tanmay Shahff34daa2021-08-09 11:00:41 -0700284 case PM_GET_CALLBACK_DATA:
Tejas Patel59c608a2019-01-09 04:10:29 -0800285 {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700286 uint32_t result[4] = {0};
Naman Trivedi Manojbhaibeec83f2023-03-07 12:41:12 +0530287 enum pm_ret_status ret;
288
289 ret = pm_get_callbackdata(result, ARRAY_SIZE(result), security_flag, 1U);
290 if (ret != 0) {
291 result[0] = ret;
292 }
Tejas Patel59c608a2019-01-09 04:10:29 -0800293
Tanmay Shahff34daa2021-08-09 11:00:41 -0700294 SMC_RET2(handle,
Venkatesh Yadav Abbarapua0657d92022-07-20 09:03:22 +0530295 (uint64_t)result[0] | ((uint64_t)result[1] << 32U),
296 (uint64_t)result[2] | ((uint64_t)result[3] << 32U));
Tejas Patel59c608a2019-01-09 04:10:29 -0800297 }
298
Tejas Patel044001d2019-01-21 17:56:48 +0530299 case PM_GET_TRUSTZONE_VERSION:
300 SMC_RET1(handle, (uint64_t)PM_RET_SUCCESS |
Jay Buddhabhattic3da9c02022-04-04 23:42:04 -0700301 ((uint64_t)TZ_VERSION << 32U));
Tejas Patel044001d2019-01-21 17:56:48 +0530302
Tanmay Shahff34daa2021-08-09 11:00:41 -0700303 default:
304 return (uintptr_t)0;
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700305 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700306}
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700307
Tanmay Shahff34daa2021-08-09 11:00:41 -0700308/**
309 * eemi_handler() - Prepare EEMI payload and perform IPI transaction
310 *
311 * EEMI - Embedded Energy Management Interface is Xilinx proprietary protocol
312 * to allow communication between power management controller and different
313 * processing clusters.
314 *
315 * This handler prepares EEMI protocol payload received from kernel and performs
316 * IPI transaction.
317 */
318static uintptr_t eemi_handler(uint32_t api_id, uint32_t *pm_arg,
319 void *handle, uint32_t security_flag)
320{
321 enum pm_ret_status ret;
322 uint32_t buf[PAYLOAD_ARG_CNT] = {0};
Ravi Patel22b0b492019-03-06 12:34:46 +0530323
Tanmay Shahff34daa2021-08-09 11:00:41 -0700324 ret = pm_handle_eemi_call(security_flag, api_id, pm_arg[0], pm_arg[1],
325 pm_arg[2], pm_arg[3], pm_arg[4],
326 (uint64_t *)buf);
327 /*
328 * Two IOCTLs, to get clock name and pinctrl name of pm_query_data API
329 * receives 5 words of respoonse from firmware. Currently linux driver can
330 * receive only 4 words from TF-A. So, this needs to be handled separately
331 * than other eemi calls.
332 */
Jay Buddhabhattif2f84b32023-02-09 22:56:53 -0800333 if (api_id == (uint32_t)PM_QUERY_DATA) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700334 if ((pm_arg[0] == XPM_QID_CLOCK_GET_NAME ||
335 pm_arg[0] == XPM_QID_PINCTRL_GET_FUNCTION_NAME) &&
336 ret == PM_RET_SUCCESS) {
Venkatesh Yadav Abbarapu2d27cb92022-07-31 14:08:53 +0530337 SMC_RET2(handle, (uint64_t)buf[0] | ((uint64_t)buf[1] << 32U),
338 (uint64_t)buf[2] | ((uint64_t)buf[3] << 32U));
Tanmay Shahff34daa2021-08-09 11:00:41 -0700339 }
Ravi Patel22b0b492019-03-06 12:34:46 +0530340 }
341
Venkatesh Yadav Abbarapu2d27cb92022-07-31 14:08:53 +0530342 SMC_RET2(handle, (uint64_t)ret | ((uint64_t)buf[0] << 32U),
343 (uint64_t)buf[1] | ((uint64_t)buf[2] << 32U));
Tanmay Shahff34daa2021-08-09 11:00:41 -0700344}
Jolly Shahed05a712019-03-22 05:33:39 +0530345
Tanmay Shahff34daa2021-08-09 11:00:41 -0700346/**
347 * pm_smc_handler() - SMC handler for PM-API calls coming from EL1/EL2.
348 * @smc_fid - Function Identifier
349 * @x1 - x4 - SMC64 Arguments from kernel
Venkatesh Yadav Abbarapu4b233392021-10-20 22:11:53 -0600350 * x3 (upper 32-bits) and x4 are Unused
Tanmay Shahff34daa2021-08-09 11:00:41 -0700351 * @cookie - Unused
352 * @handler - Pointer to caller's context structure
353 *
354 * @return - Unused
355 *
356 * Determines that smc_fid is valid and supported PM SMC Function ID from the
357 * list of pm_api_ids, otherwise completes the request with
358 * the unknown SMC Function ID
359 *
360 * The SMC calls for PM service are forwarded from SIP Service SMC handler
361 * function with rt_svc_handle signature
362 */
363uint64_t pm_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
Venkatesh Yadav Abbarapud3c0eb42022-05-24 14:02:52 +0530364 uint64_t x4, const void *cookie, void *handle, uint64_t flags)
Tanmay Shahff34daa2021-08-09 11:00:41 -0700365{
366 uintptr_t ret;
367 uint32_t pm_arg[PAYLOAD_ARG_CNT] = {0};
368 uint32_t security_flag = SECURE_FLAG;
369 uint32_t api_id;
Saeed Nowshadi2294b422019-06-03 10:22:35 -0700370
Tanmay Shahff34daa2021-08-09 11:00:41 -0700371 /* Handle case where PM wasn't initialized properly */
Michal Simek5e2f5962022-09-13 11:48:53 +0200372 if (pm_up == false) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700373 SMC_RET1(handle, SMC_UNK);
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530374 }
Saeed Nowshadi2294b422019-06-03 10:22:35 -0700375
Tanmay Shahff34daa2021-08-09 11:00:41 -0700376 /*
377 * Mark BIT24 payload (i.e 1st bit of pm_arg[3] ) as non-secure (1)
378 * if smc called is non secure
379 */
Michal Simek5e2f5962022-09-13 11:48:53 +0200380 if (is_caller_non_secure(flags) != 0) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700381 security_flag = NON_SECURE_FLAG;
Tejas Patel5c154e12020-11-25 01:53:12 -0800382 }
383
Tanmay Shahff34daa2021-08-09 11:00:41 -0700384 pm_arg[0] = (uint32_t)x1;
Venkatesh Yadav Abbarapu2d27cb92022-07-31 14:08:53 +0530385 pm_arg[1] = (uint32_t)(x1 >> 32U);
Tanmay Shahff34daa2021-08-09 11:00:41 -0700386 pm_arg[2] = (uint32_t)x2;
Venkatesh Yadav Abbarapu2d27cb92022-07-31 14:08:53 +0530387 pm_arg[3] = (uint32_t)(x2 >> 32U);
Venkatesh Yadav Abbarapu4b233392021-10-20 22:11:53 -0600388 pm_arg[4] = (uint32_t)x3;
Tanmay Shahff34daa2021-08-09 11:00:41 -0700389 (void)(x4);
390 api_id = smc_fid & FUNCID_NUM_MASK;
Tejas Patel42015552020-11-25 01:56:57 -0800391
Tanmay Shahff34daa2021-08-09 11:00:41 -0700392 ret = eemi_for_compatibility(api_id, pm_arg, handle, security_flag);
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530393 if (ret != (uintptr_t)0) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700394 return ret;
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530395 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700396
397 ret = eemi_psci_debugfs_handler(api_id, pm_arg, handle, flags);
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530398 if (ret != (uintptr_t)0) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700399 return ret;
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530400 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700401
402 ret = TF_A_specific_handler(api_id, pm_arg, handle, security_flag);
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530403 if (ret != (uintptr_t)0) {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700404 return ret;
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +0530405 }
Tanmay Shahff34daa2021-08-09 11:00:41 -0700406
407 ret = eemi_handler(api_id, pm_arg, handle, security_flag);
408
409 return ret;
Tejas Patel59c608a2019-01-09 04:10:29 -0800410}