2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
8 * File containing client-side RPC functions for the PM service. These
9 * functions are ported to clients that communicate to the SC.
17 #include <sci/sci_types.h>
18 #include <sci/svc/rm/sci_rm_api.h>
19 #include <sci/svc/pm/sci_pm_api.h>
20 #include <sci/sci_rpc.h>
22 #include "sci_pm_rpc.h"
30 sc_err_t
sc_pm_set_sys_power_mode(sc_ipc_t ipc
, sc_pm_power_mode_t mode
)
35 RPC_VER(&msg
) = SC_RPC_VERSION
;
36 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
37 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_SYS_POWER_MODE
;
38 RPC_U8(&msg
, 0U) = (uint8_t)mode
;
41 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
43 result
= RPC_R8(&msg
);
44 return (sc_err_t
)result
;
47 sc_err_t
sc_pm_set_partition_power_mode(sc_ipc_t ipc
, sc_rm_pt_t pt
,
48 sc_pm_power_mode_t mode
)
53 RPC_VER(&msg
) = SC_RPC_VERSION
;
54 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
55 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_PARTITION_POWER_MODE
;
56 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
57 RPC_U8(&msg
, 1U) = (uint8_t)mode
;
60 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
62 result
= RPC_R8(&msg
);
63 return (sc_err_t
)result
;
66 sc_err_t
sc_pm_get_sys_power_mode(sc_ipc_t ipc
, sc_rm_pt_t pt
,
67 sc_pm_power_mode_t
*mode
)
72 RPC_VER(&msg
) = SC_RPC_VERSION
;
73 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
74 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_GET_SYS_POWER_MODE
;
75 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
78 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
80 result
= RPC_R8(&msg
);
82 *mode
= RPC_U8(&msg
, 0U);
85 return (sc_err_t
)result
;
88 sc_err_t
sc_pm_set_resource_power_mode(sc_ipc_t ipc
, sc_rsrc_t resource
,
89 sc_pm_power_mode_t mode
)
94 RPC_VER(&msg
) = SC_RPC_VERSION
;
95 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
96 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_RESOURCE_POWER_MODE
;
97 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
98 RPC_U8(&msg
, 2U) = (uint8_t)mode
;
101 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
103 result
= RPC_R8(&msg
);
104 return (sc_err_t
)result
;
107 sc_err_t
sc_pm_get_resource_power_mode(sc_ipc_t ipc
, sc_rsrc_t resource
,
108 sc_pm_power_mode_t
*mode
)
113 RPC_VER(&msg
) = SC_RPC_VERSION
;
114 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
115 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_GET_RESOURCE_POWER_MODE
;
116 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
119 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
121 result
= RPC_R8(&msg
);
123 *mode
= RPC_U8(&msg
, 0U);
126 return (sc_err_t
)result
;
129 sc_err_t
sc_pm_req_low_power_mode(sc_ipc_t ipc
, sc_rsrc_t resource
,
130 sc_pm_power_mode_t mode
)
135 RPC_VER(&msg
) = SC_RPC_VERSION
;
136 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
137 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_REQ_LOW_POWER_MODE
;
138 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
139 RPC_U8(&msg
, 2U) = (uint8_t)mode
;
142 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
144 result
= RPC_R8(&msg
);
145 return (sc_err_t
)result
;
148 sc_err_t
sc_pm_req_cpu_low_power_mode(sc_ipc_t ipc
, sc_rsrc_t resource
,
149 sc_pm_power_mode_t mode
,
150 sc_pm_wake_src_t wake_src
)
155 RPC_VER(&msg
) = SC_RPC_VERSION
;
156 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
157 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_REQ_CPU_LOW_POWER_MODE
;
158 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
159 RPC_U8(&msg
, 2U) = (uint8_t)mode
;
160 RPC_U8(&msg
, 3U) = (uint8_t)wake_src
;
163 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
165 result
= RPC_R8(&msg
);
166 return (sc_err_t
)result
;
169 sc_err_t
sc_pm_set_cpu_resume_addr(sc_ipc_t ipc
, sc_rsrc_t resource
,
175 RPC_VER(&msg
) = SC_RPC_VERSION
;
176 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
177 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_CPU_RESUME_ADDR
;
178 RPC_U32(&msg
, 0U) = (uint32_t)(address
>> 32U);
179 RPC_U32(&msg
, 4U) = (uint32_t)address
;
180 RPC_U16(&msg
, 8U) = (uint16_t)resource
;
183 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
185 result
= RPC_R8(&msg
);
186 return (sc_err_t
)result
;
189 sc_err_t
sc_pm_set_cpu_resume(sc_ipc_t ipc
, sc_rsrc_t resource
,
190 sc_bool_t isPrimary
, sc_faddr_t address
)
195 RPC_VER(&msg
) = SC_RPC_VERSION
;
196 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
197 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_CPU_RESUME
;
198 RPC_U32(&msg
, 0U) = (uint32_t)(address
>> 32U);
199 RPC_U32(&msg
, 4U) = (uint32_t)address
;
200 RPC_U16(&msg
, 8U) = (uint16_t)resource
;
201 RPC_U8(&msg
, 10U) = (uint8_t)isPrimary
;
204 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
206 result
= RPC_R8(&msg
);
207 return (sc_err_t
)result
;
210 sc_err_t
sc_pm_req_sys_if_power_mode(sc_ipc_t ipc
, sc_rsrc_t resource
,
211 sc_pm_sys_if_t sys_if
,
212 sc_pm_power_mode_t hpm
,
213 sc_pm_power_mode_t lpm
)
218 RPC_VER(&msg
) = SC_RPC_VERSION
;
219 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
220 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_REQ_SYS_IF_POWER_MODE
;
221 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
222 RPC_U8(&msg
, 2U) = (uint8_t)sys_if
;
223 RPC_U8(&msg
, 3U) = (uint8_t)hpm
;
224 RPC_U8(&msg
, 4U) = (uint8_t)lpm
;
227 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
229 result
= RPC_R8(&msg
);
230 return (sc_err_t
)result
;
233 sc_err_t
sc_pm_set_clock_rate(sc_ipc_t ipc
, sc_rsrc_t resource
,
234 sc_pm_clk_t clk
, sc_pm_clock_rate_t
*rate
)
239 RPC_VER(&msg
) = SC_RPC_VERSION
;
240 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
241 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_CLOCK_RATE
;
242 RPC_U32(&msg
, 0U) = *(uint32_t *)rate
;
243 RPC_U16(&msg
, 4U) = (uint16_t)resource
;
244 RPC_U8(&msg
, 6U) = (uint8_t)clk
;
247 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
249 *rate
= RPC_U32(&msg
, 0U);
250 result
= RPC_R8(&msg
);
251 return (sc_err_t
)result
;
254 sc_err_t
sc_pm_get_clock_rate(sc_ipc_t ipc
, sc_rsrc_t resource
,
255 sc_pm_clk_t clk
, sc_pm_clock_rate_t
*rate
)
260 RPC_VER(&msg
) = SC_RPC_VERSION
;
261 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
262 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_GET_CLOCK_RATE
;
263 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
264 RPC_U8(&msg
, 2U) = (uint8_t)clk
;
267 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
270 *rate
= RPC_U32(&msg
, 0U);
273 result
= RPC_R8(&msg
);
274 return (sc_err_t
)result
;
277 sc_err_t
sc_pm_clock_enable(sc_ipc_t ipc
, sc_rsrc_t resource
,
278 sc_pm_clk_t clk
, sc_bool_t enable
, sc_bool_t autog
)
283 RPC_VER(&msg
) = SC_RPC_VERSION
;
284 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
285 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_CLOCK_ENABLE
;
286 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
287 RPC_U8(&msg
, 2U) = (uint8_t)clk
;
288 RPC_U8(&msg
, 3U) = (uint8_t)enable
;
289 RPC_U8(&msg
, 4U) = (uint8_t)autog
;
292 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
294 result
= RPC_R8(&msg
);
295 return (sc_err_t
)result
;
298 sc_err_t
sc_pm_set_clock_parent(sc_ipc_t ipc
, sc_rsrc_t resource
,
299 sc_pm_clk_t clk
, sc_pm_clk_parent_t parent
)
304 RPC_VER(&msg
) = SC_RPC_VERSION
;
305 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
306 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_SET_CLOCK_PARENT
;
307 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
308 RPC_U8(&msg
, 2U) = (uint8_t)clk
;
309 RPC_U8(&msg
, 3U) = (uint8_t)parent
;
312 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
314 result
= RPC_R8(&msg
);
315 return (sc_err_t
)result
;
318 sc_err_t
sc_pm_get_clock_parent(sc_ipc_t ipc
, sc_rsrc_t resource
,
319 sc_pm_clk_t clk
, sc_pm_clk_parent_t
*parent
)
324 RPC_VER(&msg
) = SC_RPC_VERSION
;
325 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
326 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_GET_CLOCK_PARENT
;
327 RPC_U16(&msg
, 0U) = (uint16_t)resource
;
328 RPC_U8(&msg
, 2U) = (uint8_t)clk
;
331 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
333 result
= RPC_R8(&msg
);
334 if (parent
!= NULL
) {
335 *parent
= RPC_U8(&msg
, 0U);
338 return (sc_err_t
)result
;
341 sc_err_t
sc_pm_reset(sc_ipc_t ipc
, sc_pm_reset_type_t type
)
346 RPC_VER(&msg
) = SC_RPC_VERSION
;
347 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
348 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_RESET
;
349 RPC_U8(&msg
, 0U) = (uint8_t)type
;
352 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
354 result
= RPC_R8(&msg
);
355 return (sc_err_t
)result
;
358 sc_err_t
sc_pm_reset_reason(sc_ipc_t ipc
, sc_pm_reset_reason_t
*reason
)
363 RPC_VER(&msg
) = SC_RPC_VERSION
;
364 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
365 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_RESET_REASON
;
368 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
370 result
= RPC_R8(&msg
);
371 if (reason
!= NULL
) {
372 *reason
= RPC_U8(&msg
, 0U);
375 return (sc_err_t
)result
;
378 sc_err_t
sc_pm_boot(sc_ipc_t ipc
, sc_rm_pt_t pt
,
379 sc_rsrc_t resource_cpu
, sc_faddr_t boot_addr
,
380 sc_rsrc_t resource_mu
, sc_rsrc_t resource_dev
)
385 RPC_VER(&msg
) = SC_RPC_VERSION
;
386 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
387 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_BOOT
;
388 RPC_U32(&msg
, 0U) = (uint32_t)(boot_addr
>> 32U);
389 RPC_U32(&msg
, 4U) = (uint32_t)boot_addr
;
390 RPC_U16(&msg
, 8U) = (uint16_t)resource_cpu
;
391 RPC_U16(&msg
, 10U) = (uint16_t)resource_mu
;
392 RPC_U16(&msg
, 12U) = (uint16_t)resource_dev
;
393 RPC_U8(&msg
, 14U) = (uint8_t)pt
;
396 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
398 result
= RPC_R8(&msg
);
399 return (sc_err_t
)result
;
402 void sc_pm_reboot(sc_ipc_t ipc
, sc_pm_reset_type_t type
)
406 RPC_VER(&msg
) = SC_RPC_VERSION
;
407 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
408 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_REBOOT
;
409 RPC_U8(&msg
, 0U) = (uint8_t)type
;
412 sc_call_rpc(ipc
, &msg
, SC_TRUE
);
417 sc_err_t
sc_pm_reboot_partition(sc_ipc_t ipc
, sc_rm_pt_t pt
,
418 sc_pm_reset_type_t type
)
423 RPC_VER(&msg
) = SC_RPC_VERSION
;
424 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
425 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_REBOOT_PARTITION
;
426 RPC_U8(&msg
, 0U) = (uint8_t)pt
;
427 RPC_U8(&msg
, 1U) = (uint8_t)type
;
430 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
432 result
= RPC_R8(&msg
);
433 return (sc_err_t
)result
;
436 sc_err_t
sc_pm_cpu_start(sc_ipc_t ipc
, sc_rsrc_t resource
, sc_bool_t enable
,
442 RPC_VER(&msg
) = SC_RPC_VERSION
;
443 RPC_SVC(&msg
) = (uint8_t)SC_RPC_SVC_PM
;
444 RPC_FUNC(&msg
) = (uint8_t)PM_FUNC_CPU_START
;
445 RPC_U32(&msg
, 0U) = (uint32_t)(address
>> 32U);
446 RPC_U32(&msg
, 4U) = (uint32_t)address
;
447 RPC_U16(&msg
, 8U) = (uint16_t)resource
;
448 RPC_U8(&msg
, 10U) = (uint8_t)enable
;
451 sc_call_rpc(ipc
, &msg
, SC_FALSE
);
453 result
= RPC_R8(&msg
);
454 return (sc_err_t
)result
;