1 /* 2 * Copyright (c) 2017-2019, 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 power domain power state. 17 */ 18 int scmi_pwr_state_set(void *p, uint32_t domain_id, 19 uint32_t scmi_pwr_state) 20 { 21 mailbox_mem_t *mbx_mem; 22 unsigned int token = 0; 23 int ret; 24 25 /* 26 * Only asynchronous mode of `set power state` command is allowed on 27 * application processors. 28 */ 29 uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC; 30 scmi_channel_t *ch = (scmi_channel_t *)p; 31 32 validate_scmi_channel(ch); 33 34 scmi_get_channel(ch); 35 36 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); 37 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, 38 SCMI_PWR_STATE_SET_MSG, token); 39 mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN; 40 mbx_mem->flags = SCMI_FLAG_RESP_POLL; 41 SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag, 42 domain_id, scmi_pwr_state); 43 44 scmi_send_sync_command(ch); 45 46 /* Get the return values */ 47 SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); 48 assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN); 49 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); 50 51 scmi_put_channel(ch); 52 53 return ret; 54 } 55 56 /* 57 * API to get the SCMI power domain power state. 58 */ 59 int scmi_pwr_state_get(void *p, uint32_t domain_id, 60 uint32_t *scmi_pwr_state) 61 { 62 mailbox_mem_t *mbx_mem; 63 unsigned int token = 0; 64 int ret; 65 scmi_channel_t *ch = (scmi_channel_t *)p; 66 67 validate_scmi_channel(ch); 68 69 scmi_get_channel(ch); 70 71 mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); 72 mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, 73 SCMI_PWR_STATE_GET_MSG, token); 74 mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN; 75 mbx_mem->flags = SCMI_FLAG_RESP_POLL; 76 SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id); 77 78 scmi_send_sync_command(ch); 79 80 /* Get the return values */ 81 SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state); 82 assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN); 83 assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); 84 85 scmi_put_channel(ch); 86 87 return ret; 88 } 89