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