Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 1 | /* |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <arch_helpers.h> |
| 10 | #include <common/debug.h> |
Antonio Nino Diaz | c30db5b | 2019-01-23 20:37:32 +0000 | [diff] [blame] | 11 | #include <drivers/arm/css/scmi.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 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; |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 22 | unsigned int token = 0; |
| 23 | int ret; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 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; |
Ambroise Vincent | a88a35d | 2019-02-14 09:48:21 +0000 | [diff] [blame] | 63 | unsigned int token = 0; |
| 64 | int ret; |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 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 | } |