Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <assert.h> |
| 9 | #include <debug.h> |
| 10 | #include "scmi.h" |
| 11 | #include "scmi_private.h" |
| 12 | |
| 13 | /* |
| 14 | * API to set the SCMI power domain power state. |
| 15 | */ |
| 16 | int scmi_pwr_state_set(void *p, uint32_t domain_id, |
| 17 | uint32_t scmi_pwr_state) |
| 18 | { |
| 19 | mailbox_mem_t *mbx_mem; |
| 20 | int token = 0, ret; |
| 21 | |
| 22 | /* |
| 23 | * Only asynchronous mode of `set power state` command is allowed on |
| 24 | * application processors. |
| 25 | */ |
| 26 | uint32_t pwr_state_set_msg_flag = SCMI_PWR_STATE_SET_FLAG_ASYNC; |
| 27 | scmi_channel_t *ch = (scmi_channel_t *)p; |
| 28 | |
| 29 | validate_scmi_channel(ch); |
| 30 | |
| 31 | scmi_get_channel(ch); |
| 32 | |
| 33 | mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); |
| 34 | mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, |
| 35 | SCMI_PWR_STATE_SET_MSG, token); |
| 36 | mbx_mem->len = SCMI_PWR_STATE_SET_MSG_LEN; |
| 37 | mbx_mem->flags = SCMI_FLAG_RESP_POLL; |
| 38 | SCMI_PAYLOAD_ARG3(mbx_mem->payload, pwr_state_set_msg_flag, |
| 39 | domain_id, scmi_pwr_state); |
| 40 | |
| 41 | scmi_send_sync_command(ch); |
| 42 | |
| 43 | /* Get the return values */ |
| 44 | SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); |
| 45 | assert(mbx_mem->len == SCMI_PWR_STATE_SET_RESP_LEN); |
| 46 | assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); |
| 47 | |
| 48 | scmi_put_channel(ch); |
| 49 | |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * API to get the SCMI power domain power state. |
| 55 | */ |
| 56 | int scmi_pwr_state_get(void *p, uint32_t domain_id, |
| 57 | uint32_t *scmi_pwr_state) |
| 58 | { |
| 59 | mailbox_mem_t *mbx_mem; |
| 60 | int token = 0, ret; |
| 61 | scmi_channel_t *ch = (scmi_channel_t *)p; |
| 62 | |
| 63 | validate_scmi_channel(ch); |
| 64 | |
| 65 | scmi_get_channel(ch); |
| 66 | |
| 67 | mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); |
| 68 | mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_PWR_DMN_PROTO_ID, |
| 69 | SCMI_PWR_STATE_GET_MSG, token); |
| 70 | mbx_mem->len = SCMI_PWR_STATE_GET_MSG_LEN; |
| 71 | mbx_mem->flags = SCMI_FLAG_RESP_POLL; |
| 72 | SCMI_PAYLOAD_ARG1(mbx_mem->payload, domain_id); |
| 73 | |
| 74 | scmi_send_sync_command(ch); |
| 75 | |
| 76 | /* Get the return values */ |
| 77 | SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *scmi_pwr_state); |
| 78 | assert(mbx_mem->len == SCMI_PWR_STATE_GET_RESP_LEN); |
| 79 | assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); |
| 80 | |
| 81 | scmi_put_channel(ch); |
| 82 | |
| 83 | return ret; |
| 84 | } |