1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <assert.h> 8*91f16700Schasinglulu 9*91f16700Schasinglulu #include <arch_helpers.h> 10*91f16700Schasinglulu #include <common/debug.h> 11*91f16700Schasinglulu #include <drivers/arm/css/scmi.h> 12*91f16700Schasinglulu 13*91f16700Schasinglulu #include "scmi_private.h" 14*91f16700Schasinglulu 15*91f16700Schasinglulu /* 16*91f16700Schasinglulu * API to set the SCMI system power state 17*91f16700Schasinglulu */ 18*91f16700Schasinglulu int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state) 19*91f16700Schasinglulu { 20*91f16700Schasinglulu mailbox_mem_t *mbx_mem; 21*91f16700Schasinglulu unsigned int token = 0; 22*91f16700Schasinglulu int ret; 23*91f16700Schasinglulu scmi_channel_t *ch = (scmi_channel_t *)p; 24*91f16700Schasinglulu 25*91f16700Schasinglulu validate_scmi_channel(ch); 26*91f16700Schasinglulu 27*91f16700Schasinglulu scmi_get_channel(ch); 28*91f16700Schasinglulu 29*91f16700Schasinglulu mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); 30*91f16700Schasinglulu mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, 31*91f16700Schasinglulu SCMI_SYS_PWR_STATE_SET_MSG, token); 32*91f16700Schasinglulu mbx_mem->len = SCMI_SYS_PWR_STATE_SET_MSG_LEN; 33*91f16700Schasinglulu mbx_mem->flags = SCMI_FLAG_RESP_POLL; 34*91f16700Schasinglulu SCMI_PAYLOAD_ARG2(mbx_mem->payload, flags, system_state); 35*91f16700Schasinglulu 36*91f16700Schasinglulu scmi_send_sync_command(ch); 37*91f16700Schasinglulu 38*91f16700Schasinglulu /* Get the return values */ 39*91f16700Schasinglulu SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); 40*91f16700Schasinglulu assert(mbx_mem->len == SCMI_SYS_PWR_STATE_SET_RESP_LEN); 41*91f16700Schasinglulu assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); 42*91f16700Schasinglulu 43*91f16700Schasinglulu scmi_put_channel(ch); 44*91f16700Schasinglulu 45*91f16700Schasinglulu return ret; 46*91f16700Schasinglulu } 47*91f16700Schasinglulu 48*91f16700Schasinglulu /* 49*91f16700Schasinglulu * API to get the SCMI system power state 50*91f16700Schasinglulu */ 51*91f16700Schasinglulu int scmi_sys_pwr_state_get(void *p, uint32_t *system_state) 52*91f16700Schasinglulu { 53*91f16700Schasinglulu mailbox_mem_t *mbx_mem; 54*91f16700Schasinglulu unsigned int token = 0; 55*91f16700Schasinglulu int ret; 56*91f16700Schasinglulu scmi_channel_t *ch = (scmi_channel_t *)p; 57*91f16700Schasinglulu 58*91f16700Schasinglulu validate_scmi_channel(ch); 59*91f16700Schasinglulu 60*91f16700Schasinglulu scmi_get_channel(ch); 61*91f16700Schasinglulu 62*91f16700Schasinglulu mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); 63*91f16700Schasinglulu mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, 64*91f16700Schasinglulu SCMI_SYS_PWR_STATE_GET_MSG, token); 65*91f16700Schasinglulu mbx_mem->len = SCMI_SYS_PWR_STATE_GET_MSG_LEN; 66*91f16700Schasinglulu mbx_mem->flags = SCMI_FLAG_RESP_POLL; 67*91f16700Schasinglulu 68*91f16700Schasinglulu scmi_send_sync_command(ch); 69*91f16700Schasinglulu 70*91f16700Schasinglulu /* Get the return values */ 71*91f16700Schasinglulu SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *system_state); 72*91f16700Schasinglulu assert(mbx_mem->len == SCMI_SYS_PWR_STATE_GET_RESP_LEN); 73*91f16700Schasinglulu assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); 74*91f16700Schasinglulu 75*91f16700Schasinglulu scmi_put_channel(ch); 76*91f16700Schasinglulu 77*91f16700Schasinglulu return ret; 78*91f16700Schasinglulu } 79