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