| 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 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 |
unsigned int token = 0; |
| 22 |
int ret; |
| 23 |
scmi_channel_t *ch = (scmi_channel_t *)p; |
| 24 |
|
| 25 |
validate_scmi_channel(ch); |
| 26 |
|
| 27 |
scmi_get_channel(ch); |
| 28 |
|
| 29 |
mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); |
| 30 |
mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, |
| 31 |
SCMI_SYS_PWR_STATE_SET_MSG, token); |
| 32 |
mbx_mem->len = SCMI_SYS_PWR_STATE_SET_MSG_LEN; |
| 33 |
mbx_mem->flags = SCMI_FLAG_RESP_POLL; |
| 34 |
SCMI_PAYLOAD_ARG2(mbx_mem->payload, flags, system_state); |
| 35 |
|
| 36 |
scmi_send_sync_command(ch); |
| 37 |
|
| 38 |
/* Get the return values */ |
| 39 |
SCMI_PAYLOAD_RET_VAL1(mbx_mem->payload, ret); |
| 40 |
assert(mbx_mem->len == SCMI_SYS_PWR_STATE_SET_RESP_LEN); |
| 41 |
assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); |
| 42 |
|
| 43 |
scmi_put_channel(ch); |
| 44 |
|
| 45 |
return ret; |
| 46 |
} |
| 47 |
|
| 48 |
/* |
| 49 |
* API to get the SCMI system power state |
| 50 |
*/ |
| 51 |
int scmi_sys_pwr_state_get(void *p, uint32_t *system_state) |
| 52 |
{ |
| 53 |
mailbox_mem_t *mbx_mem; |
| 54 |
unsigned int token = 0; |
| 55 |
int ret; |
| 56 |
scmi_channel_t *ch = (scmi_channel_t *)p; |
| 57 |
|
| 58 |
validate_scmi_channel(ch); |
| 59 |
|
| 60 |
scmi_get_channel(ch); |
| 61 |
|
| 62 |
mbx_mem = (mailbox_mem_t *)(ch->info->scmi_mbx_mem); |
| 63 |
mbx_mem->msg_header = SCMI_MSG_CREATE(SCMI_SYS_PWR_PROTO_ID, |
| 64 |
SCMI_SYS_PWR_STATE_GET_MSG, token); |
| 65 |
mbx_mem->len = SCMI_SYS_PWR_STATE_GET_MSG_LEN; |
| 66 |
mbx_mem->flags = SCMI_FLAG_RESP_POLL; |
| 67 |
|
| 68 |
scmi_send_sync_command(ch); |
| 69 |
|
| 70 |
/* Get the return values */ |
| 71 |
SCMI_PAYLOAD_RET_VAL2(mbx_mem->payload, ret, *system_state); |
| 72 |
assert(mbx_mem->len == SCMI_SYS_PWR_STATE_GET_RESP_LEN); |
| 73 |
assert(token == SCMI_MSG_GET_TOKEN(mbx_mem->msg_header)); |
| 74 |
|
| 75 |
scmi_put_channel(ch); |
| 76 |
|
| 77 |
return ret; |
| 78 |
} |