123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- /*
- * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
- /*!
- * File containing client-side RPC functions for the PM service. These
- * functions are ported to clients that communicate to the SC.
- *
- * @addtogroup PM_SVC
- * @{
- */
- /* Includes */
- #include <stdlib.h>
- #include <sci/sci_types.h>
- #include <sci/svc/rm/sci_rm_api.h>
- #include <sci/svc/pm/sci_pm_api.h>
- #include <sci/sci_rpc.h>
- #include "sci_pm_rpc.h"
- /* Local Defines */
- /* Local Types */
- /* Local Functions */
- sc_err_t sc_pm_set_sys_power_mode(sc_ipc_t ipc, sc_pm_power_mode_t mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_SYS_POWER_MODE;
- RPC_U8(&msg, 0U) = (uint8_t)mode;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_partition_power_mode(sc_ipc_t ipc, sc_rm_pt_t pt,
- sc_pm_power_mode_t mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_PARTITION_POWER_MODE;
- RPC_U8(&msg, 0U) = (uint8_t)pt;
- RPC_U8(&msg, 1U) = (uint8_t)mode;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_get_sys_power_mode(sc_ipc_t ipc, sc_rm_pt_t pt,
- sc_pm_power_mode_t *mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_SYS_POWER_MODE;
- RPC_U8(&msg, 0U) = (uint8_t)pt;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- if (mode != NULL) {
- *mode = RPC_U8(&msg, 0U);
- }
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_power_mode_t mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_RESOURCE_POWER_MODE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)mode;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_get_resource_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_power_mode_t *mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_RESOURCE_POWER_MODE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- if (mode != NULL) {
- *mode = RPC_U8(&msg, 0U);
- }
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_req_low_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_power_mode_t mode)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_LOW_POWER_MODE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)mode;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_req_cpu_low_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_power_mode_t mode,
- sc_pm_wake_src_t wake_src)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_CPU_LOW_POWER_MODE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)mode;
- RPC_U8(&msg, 3U) = (uint8_t)wake_src;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_cpu_resume_addr(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_faddr_t address)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CPU_RESUME_ADDR;
- RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)address;
- RPC_U16(&msg, 8U) = (uint16_t)resource;
- RPC_SIZE(&msg) = 4U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_cpu_resume(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_bool_t isPrimary, sc_faddr_t address)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CPU_RESUME;
- RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)address;
- RPC_U16(&msg, 8U) = (uint16_t)resource;
- RPC_U8(&msg, 10U) = (uint8_t)isPrimary;
- RPC_SIZE(&msg) = 4U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_req_sys_if_power_mode(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_sys_if_t sys_if,
- sc_pm_power_mode_t hpm,
- sc_pm_power_mode_t lpm)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REQ_SYS_IF_POWER_MODE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)sys_if;
- RPC_U8(&msg, 3U) = (uint8_t)hpm;
- RPC_U8(&msg, 4U) = (uint8_t)lpm;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CLOCK_RATE;
- RPC_U32(&msg, 0U) = *(uint32_t *)rate;
- RPC_U16(&msg, 4U) = (uint16_t)resource;
- RPC_U8(&msg, 6U) = (uint8_t)clk;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- *rate = RPC_U32(&msg, 0U);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_CLOCK_RATE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)clk;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- if (rate != NULL) {
- *rate = RPC_U32(&msg, 0U);
- }
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_clock_enable(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_clk_t clk, sc_bool_t enable, sc_bool_t autog)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_CLOCK_ENABLE;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)clk;
- RPC_U8(&msg, 3U) = (uint8_t)enable;
- RPC_U8(&msg, 4U) = (uint8_t)autog;
- RPC_SIZE(&msg) = 3U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_set_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_clk_t clk, sc_pm_clk_parent_t parent)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_SET_CLOCK_PARENT;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)clk;
- RPC_U8(&msg, 3U) = (uint8_t)parent;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_get_clock_parent(sc_ipc_t ipc, sc_rsrc_t resource,
- sc_pm_clk_t clk, sc_pm_clk_parent_t *parent)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_GET_CLOCK_PARENT;
- RPC_U16(&msg, 0U) = (uint16_t)resource;
- RPC_U8(&msg, 2U) = (uint8_t)clk;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- if (parent != NULL) {
- *parent = RPC_U8(&msg, 0U);
- }
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_reset(sc_ipc_t ipc, sc_pm_reset_type_t type)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_RESET;
- RPC_U8(&msg, 0U) = (uint8_t)type;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_reset_reason(sc_ipc_t ipc, sc_pm_reset_reason_t *reason)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_RESET_REASON;
- RPC_SIZE(&msg) = 1U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- if (reason != NULL) {
- *reason = RPC_U8(&msg, 0U);
- }
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_boot(sc_ipc_t ipc, sc_rm_pt_t pt,
- sc_rsrc_t resource_cpu, sc_faddr_t boot_addr,
- sc_rsrc_t resource_mu, sc_rsrc_t resource_dev)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_BOOT;
- RPC_U32(&msg, 0U) = (uint32_t)(boot_addr >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)boot_addr;
- RPC_U16(&msg, 8U) = (uint16_t)resource_cpu;
- RPC_U16(&msg, 10U) = (uint16_t)resource_mu;
- RPC_U16(&msg, 12U) = (uint16_t)resource_dev;
- RPC_U8(&msg, 14U) = (uint8_t)pt;
- RPC_SIZE(&msg) = 5U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- void sc_pm_reboot(sc_ipc_t ipc, sc_pm_reset_type_t type)
- {
- sc_rpc_msg_t msg;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REBOOT;
- RPC_U8(&msg, 0U) = (uint8_t)type;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_TRUE);
- }
- sc_err_t sc_pm_reboot_partition(sc_ipc_t ipc, sc_rm_pt_t pt,
- sc_pm_reset_type_t type)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_REBOOT_PARTITION;
- RPC_U8(&msg, 0U) = (uint8_t)pt;
- RPC_U8(&msg, 1U) = (uint8_t)type;
- RPC_SIZE(&msg) = 2U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- sc_err_t sc_pm_cpu_start(sc_ipc_t ipc, sc_rsrc_t resource, sc_bool_t enable,
- sc_faddr_t address)
- {
- sc_rpc_msg_t msg;
- uint8_t result;
- RPC_VER(&msg) = SC_RPC_VERSION;
- RPC_SVC(&msg) = (uint8_t)SC_RPC_SVC_PM;
- RPC_FUNC(&msg) = (uint8_t)PM_FUNC_CPU_START;
- RPC_U32(&msg, 0U) = (uint32_t)(address >> 32U);
- RPC_U32(&msg, 4U) = (uint32_t)address;
- RPC_U16(&msg, 8U) = (uint16_t)resource;
- RPC_U8(&msg, 10U) = (uint8_t)enable;
- RPC_SIZE(&msg) = 4U;
- sc_call_rpc(ipc, &msg, SC_FALSE);
- result = RPC_R8(&msg);
- return (sc_err_t)result;
- }
- /**@}*/
|