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