blob: 8fa8a44804eadd21e031b157133bf3dad12da870 [file] [log] [blame]
Tejas Patel9d09ff92019-01-08 01:46:35 -08001/*
Tanmay Shahff34daa2021-08-09 11:00:41 -07002 * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved.
Tejas Patel9d09ff92019-01-08 01:46:35 -08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
8 * Versal system level PM-API functions and communication with PMC via
9 * IPI interrupts
10 */
11
12#include <pm_common.h>
13#include <pm_ipi.h>
Tejas Patelfe0e10a2019-12-08 23:29:44 -080014#include <plat/common/platform.h>
Tejas Patel9d09ff92019-01-08 01:46:35 -080015#include "pm_api_sys.h"
16#include "pm_client.h"
Rajan Vaja030620d2020-11-23 04:13:54 -080017#include "pm_defs.h"
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053018#include "pm_svc_main.h"
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -060019#include "../drivers/arm/gic/v3/gicv3_private.h"
Tejas Patel9d09ff92019-01-08 01:46:35 -080020
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -080021/* default shutdown/reboot scope is system(2) */
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +053022static uint32_t pm_shutdown_scope = XPM_SHUTDOWN_SUBTYPE_RST_SYSTEM;
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -080023
24/**
25 * pm_get_shutdown_scope() - Get the currently set shutdown scope
26 *
27 * @return Shutdown scope value
28 */
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +053029uint32_t pm_get_shutdown_scope(void)
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -080030{
31 return pm_shutdown_scope;
32}
33
Tejas Patel9d09ff92019-01-08 01:46:35 -080034/* PM API functions */
35
36/**
Tanmay Shahff34daa2021-08-09 11:00:41 -070037 * pm_handle_eemi_call() - PM call for processor to send eemi payload
Tejas Patel18072da2021-02-25 20:16:56 -080038 * @flag 0 - Call from secure source
39 * 1 - Call from non-secure source
Tanmay Shahff34daa2021-08-09 11:00:41 -070040 * @x0 to x5 Arguments received per SMC64 standard
41 * @result Payload received from firmware
Tejas Patel9d09ff92019-01-08 01:46:35 -080042 *
Tanmay Shahff34daa2021-08-09 11:00:41 -070043 * @return PM_RET_SUCCESS on success or error code
Tejas Patel9d09ff92019-01-08 01:46:35 -080044 */
Tanmay Shahff34daa2021-08-09 11:00:41 -070045enum pm_ret_status pm_handle_eemi_call(uint32_t flag, uint32_t x0, uint32_t x1,
46 uint32_t x2, uint32_t x3, uint32_t x4,
47 uint32_t x5, uint64_t *result)
Tejas Patel9d09ff92019-01-08 01:46:35 -080048{
Tanmay Shahff34daa2021-08-09 11:00:41 -070049 uint32_t payload[PAYLOAD_ARG_CNT] = {0};
50 uint32_t module_id;
Tejas Patel9d09ff92019-01-08 01:46:35 -080051
Venkatesh Yadav Abbarapua0657d92022-07-20 09:03:22 +053052 module_id = (x0 & MODULE_ID_MASK) >> 8U;
Tejas Patelfe0e10a2019-12-08 23:29:44 -080053
Tanmay Shahff34daa2021-08-09 11:00:41 -070054 //default module id is for LIBPM
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +053055 if (module_id == 0) {
Tanmay Shahff34daa2021-08-09 11:00:41 -070056 module_id = LIBPM_MODULE_ID;
Venkatesh Yadav Abbarapuab167132022-05-25 15:18:24 +053057 }
Ravi Patel476b5b12019-08-12 03:10:10 -070058
Tanmay Shahff34daa2021-08-09 11:00:41 -070059 PM_PACK_PAYLOAD6(payload, module_id, flag, x0, x1, x2, x3, x4, x5);
60 return pm_ipi_send_sync(primary_proc, payload, (uint32_t *)result, PAYLOAD_ARG_CNT);
Ravi Patel476b5b12019-08-12 03:10:10 -070061}
62
63/**
Tejas Patelfe0e10a2019-12-08 23:29:44 -080064 * pm_self_suspend() - PM call for processor to suspend itself
65 * @nid Node id of the processor or subsystem
66 * @latency Requested maximum wakeup latency (not supported)
67 * @state Requested state
68 * @address Resume address
Tejas Patel18072da2021-02-25 20:16:56 -080069 * @flag 0 - Call from secure source
70 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -080071 *
72 * This is a blocking call, it will return only once PMU has responded.
73 * On a wakeup, resume address will be automatically set by PMU.
74 *
75 * @return Returns status, either success or error+reason
76 */
77enum pm_ret_status pm_self_suspend(uint32_t nid,
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +053078 uint32_t latency,
79 uint32_t state,
Tejas Patel18072da2021-02-25 20:16:56 -080080 uintptr_t address, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -080081{
82 uint32_t payload[PAYLOAD_ARG_CNT];
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +053083 uint32_t cpuid = plat_my_core_pos();
Tejas Patelfe0e10a2019-12-08 23:29:44 -080084 const struct pm_proc *proc = pm_get_proc(cpuid);
85
Abhyuday Godhasara44877942021-08-05 02:59:26 -070086 if (proc == NULL) {
Tejas Patelfe0e10a2019-12-08 23:29:44 -080087 WARN("Failed to get proc %d\n", cpuid);
88 return PM_RET_ERROR_INTERNAL;
89 }
90
91 /*
92 * Do client specific suspend operations
93 * (e.g. set powerdown request bit)
94 */
95 pm_client_suspend(proc, state);
96
97 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -080098 PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, flag, PM_SELF_SUSPEND,
Tejas Patelfe0e10a2019-12-08 23:29:44 -080099 proc->node_id, latency, state, address,
100 (address >> 32));
101 return pm_ipi_send_sync(proc, payload, NULL, 0);
102}
103
104/**
105 * pm_abort_suspend() - PM call to announce that a prior suspend request
106 * is to be aborted.
107 * @reason Reason for the abort
Tejas Patel18072da2021-02-25 20:16:56 -0800108 * @flag 0 - Call from secure source
109 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800110 *
111 * Calling PU expects the PMU to abort the initiated suspend procedure.
112 * This is a non-blocking call without any acknowledge.
113 *
114 * @return Returns status, either success or error+reason
115 */
Tejas Patel18072da2021-02-25 20:16:56 -0800116enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800117{
118 uint32_t payload[PAYLOAD_ARG_CNT];
119
120 /*
121 * Do client specific abort suspend operations
122 * (e.g. enable interrupts and clear powerdown request bit)
123 */
124 pm_client_abort_suspend();
125
126 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -0800127 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_ABORT_SUSPEND,
128 reason, primary_proc->node_id);
Abhyuday Godhasara7ae761b2021-06-24 05:50:44 -0700129 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800130}
131
132/**
133 * pm_req_suspend() - PM call to request for another PU or subsystem to
134 * be suspended gracefully.
135 * @target Node id of the targeted PU or subsystem
136 * @ack Flag to specify whether acknowledge is requested
137 * @latency Requested wakeup latency (not supported)
138 * @state Requested state (not supported)
Tejas Patel18072da2021-02-25 20:16:56 -0800139 * @flag 0 - Call from secure source
140 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800141 *
142 * @return Returns status, either success or error+reason
143 */
144enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack,
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +0530145 uint32_t latency, uint32_t state,
Tejas Patel18072da2021-02-25 20:16:56 -0800146 uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800147{
148 uint32_t payload[PAYLOAD_ARG_CNT];
149
150 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800151 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_REQ_SUSPEND, target,
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800152 latency, state);
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700153 if (ack == IPI_BLOCKING) {
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800154 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700155 } else {
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800156 return pm_ipi_send(primary_proc, payload);
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700157 }
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800158}
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800159
160/**
Tejas Patel49cd8712019-01-23 14:18:51 +0530161 * pm_req_wakeup() - PM call for processor to wake up selected processor
162 * or subsystem
163 * @target Device ID of the processor or subsystem to wake up
164 * @set_address Resume address presence indicator
165 * 1 - resume address specified, 0 - otherwise
166 * @address Resume address
167 * @ack Flag to specify whether acknowledge requested
Tejas Patel18072da2021-02-25 20:16:56 -0800168 * @flag 0 - Call from secure source
169 * 1 - Call from non-secure source
Tejas Patel49cd8712019-01-23 14:18:51 +0530170 *
171 * This API function is either used to power up another APU core for SMP
172 * (by PSCI) or to power up an entirely different PU or subsystem, such
173 * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be
174 * automatically set by PMC.
175 *
176 * @return Returns status, either success or error+reason
177 */
178enum pm_ret_status pm_req_wakeup(uint32_t target, uint32_t set_address,
Tejas Patel18072da2021-02-25 20:16:56 -0800179 uintptr_t address, uint8_t ack, uint32_t flag)
Tejas Patel49cd8712019-01-23 14:18:51 +0530180{
181 uint32_t payload[PAYLOAD_ARG_CNT];
182
183 /* Send request to the PMC to perform the wake of the PU */
Tejas Patel18072da2021-02-25 20:16:56 -0800184 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQ_WAKEUP, target,
Tejas Patel49cd8712019-01-23 14:18:51 +0530185 set_address, address, ack);
186
187 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
188}
189
190/**
Rajan Vaja649e9242019-03-04 11:09:40 +0530191 * pm_get_callbackdata() - Read from IPI response buffer
192 * @data - array of PAYLOAD_ARG_CNT elements
Tejas Patel18072da2021-02-25 20:16:56 -0800193 * @flag - 0 - Call from secure source
194 * 1 - Call from non-secure source
Rajan Vaja649e9242019-03-04 11:09:40 +0530195 *
196 * Read value from ipi buffer response buffer.
197 */
Tejas Patel18072da2021-02-25 20:16:56 -0800198void pm_get_callbackdata(uint32_t *data, size_t count, uint32_t flag)
Rajan Vaja649e9242019-03-04 11:09:40 +0530199{
200 /* Return if interrupt is not from PMU */
Abhyuday Godhasara44877942021-08-05 02:59:26 -0700201 if (pm_ipi_irq_status(primary_proc) == 0) {
Rajan Vaja649e9242019-03-04 11:09:40 +0530202 return;
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700203 }
Rajan Vaja649e9242019-03-04 11:09:40 +0530204
205 pm_ipi_buff_read_callb(data, count);
206 pm_ipi_irq_clear(primary_proc);
207}
208
209/**
Tanmay Shahff34daa2021-08-09 11:00:41 -0700210 * pm_pll_set_param() - Set PLL parameter
Tejas Patel1f56fb12019-01-08 01:46:40 -0800211 *
Tanmay Shahff34daa2021-08-09 11:00:41 -0700212 * This API is deprecated and maintained here for backward compatibility.
213 * New use of this API should be avoided for versal platform.
214 * This API and its use cases will be removed for versal platform.
Tejas Patel84275bf2020-09-01 04:43:53 -0700215 *
Tejas Patel023116d2019-01-08 01:46:41 -0800216 * @clk_id PLL clock ID
217 * @param PLL parameter ID
218 * @value Value to set for PLL parameter
Tejas Patel18072da2021-02-25 20:16:56 -0800219 * @flag 0 - Call from secure source
220 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800221 *
222 * @return Returns status, either success or error+reason
223 */
224enum pm_ret_status pm_pll_set_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800225 uint32_t value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800226{
227 uint32_t payload[PAYLOAD_ARG_CNT];
228
229 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800230 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_PARAMETER,
231 clk_id, param, value);
Tejas Patel023116d2019-01-08 01:46:41 -0800232
233 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
234}
235
236/**
237 * pm_pll_get_param() - Get PLL parameter value
Tanmay Shahff34daa2021-08-09 11:00:41 -0700238 *
239 * This API is deprecated and maintained here for backward compatibility.
240 * New use of this API should be avoided for versal platform.
241 * This API and its use cases will be removed for versal platform.
242 *
Tejas Patel023116d2019-01-08 01:46:41 -0800243 * @clk_id PLL clock ID
244 * @param PLL parameter ID
245 * @value: Buffer to store PLL parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800246 * @flag 0 - Call from secure source
247 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800248 *
249 * @return Returns status, either success or error+reason
250 */
251enum pm_ret_status pm_pll_get_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800252 uint32_t *value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800253{
254 uint32_t payload[PAYLOAD_ARG_CNT];
255
256 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800257 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_PARAMETER,
258 clk_id, param);
Tejas Patel023116d2019-01-08 01:46:41 -0800259
260 return pm_ipi_send_sync(primary_proc, payload, value, 1);
261}
262
263/**
264 * pm_pll_set_mode() - Set PLL mode
Tanmay Shahff34daa2021-08-09 11:00:41 -0700265 *
266 * This API is deprecated and maintained here for backward compatibility.
267 * New use of this API should be avoided for versal platform.
268 * This API and its use cases will be removed for versal platform.
269 *
Tejas Patel023116d2019-01-08 01:46:41 -0800270 * @clk_id PLL clock ID
271 * @mode PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800272 * @flag 0 - Call from secure source
273 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800274 *
275 * @return Returns status, either success or error+reason
276 */
Tejas Patel18072da2021-02-25 20:16:56 -0800277enum pm_ret_status pm_pll_set_mode(uint32_t clk_id, uint32_t mode,
278 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800279{
280 uint32_t payload[PAYLOAD_ARG_CNT];
281
282 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800283 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_MODE,
284 clk_id, mode);
Tejas Patel023116d2019-01-08 01:46:41 -0800285
286 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
287}
288
289/**
290 * pm_pll_get_mode() - Get PLL mode
Tanmay Shahff34daa2021-08-09 11:00:41 -0700291 *
292 * This API is deprecated and maintained here for backward compatibility.
293 * New use of this API should be avoided for versal platform.
294 * This API and its use cases will be removed for versal platform.
295 *
Tejas Patel023116d2019-01-08 01:46:41 -0800296 * @clk_id PLL clock ID
297 * @mode: Buffer to store PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800298 * @flag 0 - Call from secure source
299 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800300 *
301 * @return Returns status, either success or error+reason
302 */
Tejas Patel18072da2021-02-25 20:16:56 -0800303enum pm_ret_status pm_pll_get_mode(uint32_t clk_id, uint32_t *mode,
304 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800305{
306 uint32_t payload[PAYLOAD_ARG_CNT];
307
308 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800309 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_MODE,
310 clk_id);
Tejas Patel023116d2019-01-08 01:46:41 -0800311
312 return pm_ipi_send_sync(primary_proc, payload, mode, 1);
313}
Tejas Patel6b282252019-01-10 03:03:47 -0800314
315/**
316 * pm_force_powerdown() - PM call to request for another PU or subsystem to
317 * be powered down forcefully
318 * @target Device ID of the PU node to be forced powered down.
319 * @ack Flag to specify whether acknowledge is requested
Tejas Patel18072da2021-02-25 20:16:56 -0800320 * @flag 0 - Call from secure source
321 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800322 *
323 * @return Returns status, either success or error+reason
324 */
Tejas Patel18072da2021-02-25 20:16:56 -0800325enum pm_ret_status pm_force_powerdown(uint32_t target, uint8_t ack,
326 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800327{
328 uint32_t payload[PAYLOAD_ARG_CNT];
329
330 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800331 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_FORCE_POWERDOWN,
332 target, ack);
Tejas Patel6b282252019-01-10 03:03:47 -0800333
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700334 if (ack == IPI_BLOCKING) {
Tejas Patel6b282252019-01-10 03:03:47 -0800335 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700336 } else {
Tejas Patel6b282252019-01-10 03:03:47 -0800337 return pm_ipi_send(primary_proc, payload);
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700338 }
Tejas Patel6b282252019-01-10 03:03:47 -0800339}
340
341/**
342 * pm_system_shutdown() - PM call to request a system shutdown or restart
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800343 * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope
Tejas Patel6b282252019-01-10 03:03:47 -0800344 * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system
Tejas Patel18072da2021-02-25 20:16:56 -0800345 * @flag 0 - Call from secure source
346 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800347 *
348 * @return Returns status, either success or error+reason
349 */
Tejas Patel18072da2021-02-25 20:16:56 -0800350enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype,
351 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800352{
353 uint32_t payload[PAYLOAD_ARG_CNT];
354
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800355 if (type == XPM_SHUTDOWN_TYPE_SETSCOPE_ONLY) {
356 /* Setting scope for subsequent PSCI reboot or shutdown */
357 pm_shutdown_scope = subtype;
358 return PM_RET_SUCCESS;
359 }
360
Tejas Patel6b282252019-01-10 03:03:47 -0800361 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800362 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SYSTEM_SHUTDOWN,
363 type, subtype);
Tejas Patel6b282252019-01-10 03:03:47 -0800364
365 return pm_ipi_send_non_blocking(primary_proc, payload);
366}
Tejas Patel9141f442019-01-10 03:03:48 -0800367
368/**
Tanmay Shahff34daa2021-08-09 11:00:41 -0700369 * pm_query_data() - PM API for querying firmware data
370 *
371 * This API is deprecated and maintained here for backward compatibility.
372 * New use of this API should be avoided for versal platform.
373 * This API and its use cases will be removed for versal platform.
374 *
375 * @qid The type of data to query
376 * @arg1 Argument 1 to requested query data call
377 * @arg2 Argument 2 to requested query data call
378 * @arg3 Argument 3 to requested query data call
379 * @data Returned output data
380 * @flag 0 - Call from secure source
381 * 1 - Call from non-secure source
382 *
383 * @retur - 0 if success else non-zero error code of type
384 * enum pm_ret_status
385 */
Tejas Patela3e34ad2019-02-01 17:25:19 +0530386enum pm_ret_status pm_query_data(uint32_t qid, uint32_t arg1, uint32_t arg2,
Tejas Patel18072da2021-02-25 20:16:56 -0800387 uint32_t arg3, uint32_t *data, uint32_t flag)
Tejas Patela3e34ad2019-02-01 17:25:19 +0530388{
Rajan Vaja030620d2020-11-23 04:13:54 -0800389 uint32_t ret;
Tanmay Shahff34daa2021-08-09 11:00:41 -0700390 uint32_t version[PAYLOAD_ARG_CNT] = {0};
Tejas Patela3e34ad2019-02-01 17:25:19 +0530391 uint32_t payload[PAYLOAD_ARG_CNT];
Rajan Vaja030620d2020-11-23 04:13:54 -0800392 uint32_t fw_api_version;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530393
394 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800395 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_QUERY_DATA, qid,
396 arg1, arg2, arg3);
Rajan Vaja030620d2020-11-23 04:13:54 -0800397
Tanmay Shahff34daa2021-08-09 11:00:41 -0700398 ret = pm_feature_check(PM_QUERY_DATA, &version[0], flag);
399 if (ret == PM_RET_SUCCESS) {
Venkatesh Yadav Abbarapua0657d92022-07-20 09:03:22 +0530400 fw_api_version = version[0] & 0xFFFFU;
Tanmay Shahff34daa2021-08-09 11:00:41 -0700401 if ((fw_api_version == 2U) &&
402 ((qid == XPM_QID_CLOCK_GET_NAME) ||
403 (qid == XPM_QID_PINCTRL_GET_FUNCTION_NAME))) {
404 ret = pm_ipi_send_sync(primary_proc, payload, data, PAYLOAD_ARG_CNT);
405 if (ret == PM_RET_SUCCESS) {
406 ret = data[0];
407 data[0] = data[1];
408 data[1] = data[2];
409 data[2] = data[3];
410 }
Rajan Vaja030620d2020-11-23 04:13:54 -0800411 } else {
Tanmay Shahff34daa2021-08-09 11:00:41 -0700412 ret = pm_ipi_send_sync(primary_proc, payload, data, PAYLOAD_ARG_CNT);
Rajan Vaja030620d2020-11-23 04:13:54 -0800413 }
414 }
415 return ret;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530416}
417/**
Tejas Patel9141f442019-01-10 03:03:48 -0800418 * pm_api_ioctl() - PM IOCTL API for device control and configs
Tanmay Shahff34daa2021-08-09 11:00:41 -0700419 *
420 * This API is deprecated and maintained here for backward compatibility.
421 * New use of this API should be avoided for versal platform.
422 * This API and its use cases will be removed for versal platform.
423 *
Tejas Patel9141f442019-01-10 03:03:48 -0800424 * @device_id Device ID
425 * @ioctl_id ID of the requested IOCTL
426 * @arg1 Argument 1 to requested IOCTL call
427 * @arg2 Argument 2 to requested IOCTL call
Venkatesh Yadav Abbarapu4b233392021-10-20 22:11:53 -0600428 * @arg3 Argument 3 to requested IOCTL call
Tejas Patel9141f442019-01-10 03:03:48 -0800429 * @value Returned output value
Tejas Patel18072da2021-02-25 20:16:56 -0800430 * @flag 0 - Call from secure source
431 * 1 - Call from non-secure source
Tejas Patel9141f442019-01-10 03:03:48 -0800432 *
433 * This function calls IOCTL to firmware for device control and configuration.
434 *
Tanmay Shahff34daa2021-08-09 11:00:41 -0700435 * @return Returns status, either 0 on success or non-zero error code
436 * of type enum pm_ret_status
Tejas Patel9141f442019-01-10 03:03:48 -0800437 */
438enum pm_ret_status pm_api_ioctl(uint32_t device_id, uint32_t ioctl_id,
Venkatesh Yadav Abbarapu4b233392021-10-20 22:11:53 -0600439 uint32_t arg1, uint32_t arg2, uint32_t arg3,
440 uint32_t *value, uint32_t flag)
Tejas Patel9141f442019-01-10 03:03:48 -0800441{
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700442 enum pm_ret_status ret;
Tejas Patel9141f442019-01-10 03:03:48 -0800443
444 switch (ioctl_id) {
445 case IOCTL_SET_PLL_FRAC_MODE:
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700446 ret = pm_pll_set_mode(arg1, arg2, flag);
447 break;
Tejas Patel9141f442019-01-10 03:03:48 -0800448 case IOCTL_GET_PLL_FRAC_MODE:
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700449 ret = pm_pll_get_mode(arg1, value, flag);
450 break;
Tejas Patel9141f442019-01-10 03:03:48 -0800451 case IOCTL_SET_PLL_FRAC_DATA:
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700452 ret = pm_pll_set_param(arg1, PM_PLL_PARAM_DATA, arg2, flag);
453 break;
Tejas Patel9141f442019-01-10 03:03:48 -0800454 case IOCTL_GET_PLL_FRAC_DATA:
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700455 ret = pm_pll_get_param(arg1, PM_PLL_PARAM_DATA, value, flag);
456 break;
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -0600457 case IOCTL_SET_SGI:
458 /* Get the sgi number */
Venkatesh Yadav Abbarapuc8bbedc2021-04-19 07:49:57 -0600459 ret = pm_register_sgi(arg1, arg2);
460 if (ret != 0) {
Venkatesh Yadav Abbarapuaa4898a2021-03-31 03:07:40 -0600461 return PM_RET_ERROR_ARGS;
462 }
463 gicd_write_irouter(gicv3_driver_data->gicd_base,
Venkatesh Yadav Abbarapubde87592022-05-24 11:11:12 +0530464 (uint32_t)PLAT_VERSAL_IPI_IRQ, MODE);
Michal Simek89e3c292022-08-04 14:08:32 +0200465 ret = PM_RET_SUCCESS;
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700466 break;
Tejas Patel9141f442019-01-10 03:03:48 -0800467 default:
Tanmay Shahff34daa2021-08-09 11:00:41 -0700468 return PM_RET_ERROR_NOTSUPPORTED;
Tejas Patel9141f442019-01-10 03:03:48 -0800469 }
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700470
471 return ret;
Tejas Patel9141f442019-01-10 03:03:48 -0800472}
Tejas Pateldb812052019-01-23 14:18:53 +0530473
474/**
475 * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended
476 * @target Device id of the targeted PU or subsystem
477 * @wkup_node Device id of the wakeup peripheral
478 * @enable Enable or disable the specified peripheral as wake source
Tejas Patel18072da2021-02-25 20:16:56 -0800479 * @flag 0 - Call from secure source
480 * 1 - Call from non-secure source
Tejas Pateldb812052019-01-23 14:18:53 +0530481 *
482 * @return Returns status, either success or error+reason
483 */
484enum pm_ret_status pm_set_wakeup_source(uint32_t target, uint32_t wkup_device,
Tejas Patel18072da2021-02-25 20:16:56 -0800485 uint8_t enable, uint32_t flag)
Tejas Pateldb812052019-01-23 14:18:53 +0530486{
487 uint32_t payload[PAYLOAD_ARG_CNT];
488
Tejas Patel18072da2021-02-25 20:16:56 -0800489 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_SET_WAKEUP_SOURCE,
490 target, wkup_device, enable);
Abhyuday Godhasara7ae761b2021-06-24 05:50:44 -0700491 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Tejas Pateldb812052019-01-23 14:18:53 +0530492}
Ravi Patel22b0b492019-03-06 12:34:46 +0530493
494/**
495 * pm_feature_check() - Returns the supported API version if supported
496 * @api_id API ID to check
Tejas Patel18072da2021-02-25 20:16:56 -0800497 * @flag 0 - Call from secure source
498 * 1 - Call from non-secure source
Ronak Jain70d1c582022-02-04 00:42:55 -0800499 * @ret_payload pointer to array of PAYLOAD_ARG_CNT number of
500 * words Returned supported API version and bitmasks
501 * for IOCTL and QUERY ID
Ravi Patel22b0b492019-03-06 12:34:46 +0530502 *
503 * @return Returns status, either success or error+reason
504 */
Ronak Jain70d1c582022-02-04 00:42:55 -0800505enum pm_ret_status pm_feature_check(uint32_t api_id, uint32_t *ret_payload,
Tejas Patel18072da2021-02-25 20:16:56 -0800506 uint32_t flag)
Ravi Patel22b0b492019-03-06 12:34:46 +0530507{
Ronak Jain70d1c582022-02-04 00:42:55 -0800508 uint32_t payload[PAYLOAD_ARG_CNT];
Tanmay Shahff34daa2021-08-09 11:00:41 -0700509 uint32_t module_id;
510
Ronak Jain70d1c582022-02-04 00:42:55 -0800511 /* Return version of API which are implemented in ATF only */
Ravi Patel22b0b492019-03-06 12:34:46 +0530512 switch (api_id) {
513 case PM_GET_CALLBACK_DATA:
514 case PM_GET_TRUSTZONE_VERSION:
Ronak Jain70d1c582022-02-04 00:42:55 -0800515 ret_payload[0] = PM_API_VERSION_2;
516 return PM_RET_SUCCESS;
Rajan Vajaad1ffff2021-01-20 00:53:45 -0800517 case PM_LOAD_PDI:
Ronak Jain70d1c582022-02-04 00:42:55 -0800518 ret_payload[0] = PM_API_BASE_VERSION;
Tanmay Shahff34daa2021-08-09 11:00:41 -0700519 return PM_RET_SUCCESS;
Ravi Patel22b0b492019-03-06 12:34:46 +0530520 default:
Abhyuday Godhasara95374b42021-08-05 07:07:35 -0700521 break;
522 }
523
Venkatesh Yadav Abbarapua0657d92022-07-20 09:03:22 +0530524 module_id = (api_id & MODULE_ID_MASK) >> 8U;
Ravi Patel22b0b492019-03-06 12:34:46 +0530525
Ronak Jain70d1c582022-02-04 00:42:55 -0800526 /*
527 * feature check should be done only for LIBPM module
528 * If module_id is 0, then we consider it LIBPM module as default id
529 */
530 if ((module_id > 0) && (module_id != LIBPM_MODULE_ID)) {
531 return PM_RET_SUCCESS;
Abhyuday Godhasaraddc46622021-08-05 03:14:17 -0700532 }
Ravi Patel22b0b492019-03-06 12:34:46 +0530533
Ronak Jain70d1c582022-02-04 00:42:55 -0800534 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag,
535 PM_FEATURE_CHECK, api_id);
536 return pm_ipi_send_sync(primary_proc, payload, ret_payload, PAYLOAD_ARG_CNT);
Ravi Patel22b0b492019-03-06 12:34:46 +0530537}
Jolly Shahed05a712019-03-22 05:33:39 +0530538
539/**
540 * pm_load_pdi() - Load the PDI
541 *
542 * This function provides support to load PDI from linux
543 *
544 * src: Source device of pdi(DDR, OCM, SD etc)
545 * address_low: lower 32-bit Linear memory space address
546 * address_high: higher 32-bit Linear memory space address
Tejas Patel18072da2021-02-25 20:16:56 -0800547 * @flag 0 - Call from secure source
548 * 1 - Call from non-secure source
Jolly Shahed05a712019-03-22 05:33:39 +0530549 *
550 * @return Returns status, either success or error+reason
551 */
Tejas Patel18072da2021-02-25 20:16:56 -0800552enum pm_ret_status pm_load_pdi(uint32_t src, uint32_t address_low,
553 uint32_t address_high, uint32_t flag)
Jolly Shahed05a712019-03-22 05:33:39 +0530554{
555 uint32_t payload[PAYLOAD_ARG_CNT];
556
557 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800558 PM_PACK_PAYLOAD4(payload, LOADER_MODULE_ID, flag, PM_LOAD_PDI, src,
Jolly Shahed05a712019-03-22 05:33:39 +0530559 address_high, address_low);
560 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
561}
Saeed Nowshadi2294b422019-06-03 10:22:35 -0700562
563/**
Tejas Patel42015552020-11-25 01:56:57 -0800564 * pm_register_notifier() - PM call to register a subsystem to be notified
565 * about the device event
566 * @device_id Device ID for the Node to which the event is related
567 * @event Event in question
568 * @wake Wake subsystem upon capturing the event if value 1
569 * @enable Enable the registration for value 1, disable for value 0
Tejas Patel18072da2021-02-25 20:16:56 -0800570 * @flag 0 - Call from secure source
571 * 1 - Call from non-secure source
Tejas Patel42015552020-11-25 01:56:57 -0800572 *
573 * @return Returns status, either success or error+reason
574 */
575enum pm_ret_status pm_register_notifier(uint32_t device_id, uint32_t event,
Tejas Patel18072da2021-02-25 20:16:56 -0800576 uint32_t wake, uint32_t enable,
577 uint32_t flag)
Tejas Patel42015552020-11-25 01:56:57 -0800578{
579 uint32_t payload[PAYLOAD_ARG_CNT];
580
581 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800582 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REGISTER_NOTIFIER,
Tejas Patel42015552020-11-25 01:56:57 -0800583 device_id, event, wake, enable);
584
585 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
586}