blob: 850402a54c7d5a8c42f7719245977e92daade8c1 [file] [log] [blame]
Soby Mathewea26bad2016-11-14 12:25:45 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __CSS_SCMI_H__
8#define __CSS_SCMI_H__
9
10#include <bakery_lock.h>
11#include <stddef.h>
12#include <stdint.h>
13
14/* Supported SCMI Protocol Versions */
15#define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0)
16#define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0)
17
18#define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff)
19#define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff)
20
21#define MAKE_SCMI_VERSION(maj, min) \
22 ((((maj) & 0xffff) << 16) | ((min) & 0xffff))
23
24/* Macro to check if the driver is compatible with the SCMI version reported */
25#define is_scmi_version_compatible(drv, scmi) \
26 ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \
27 (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi)))
28
29/* SCMI Protocol identifiers */
30#define SCMI_PWR_DMN_PROTO_ID 0x11
31#define SCMI_SYS_PWR_PROTO_ID 0x12
32
33/* Mandatory messages IDs for all SCMI protocols */
34#define SCMI_PROTO_VERSION_MSG 0x0
35#define SCMI_PROTO_ATTR_MSG 0x1
36#define SCMI_PROTO_MSG_ATTR_MSG 0x2
37
38/* SCMI power domain management protocol message IDs */
39#define SCMI_PWR_STATE_SET_MSG 0x4
40#define SCMI_PWR_STATE_GET_MSG 0x5
41
42/* SCMI system power management protocol message IDs */
43#define SCMI_SYS_PWR_STATE_SET_MSG 0x3
44#define SCMI_SYS_PWR_STATE_GET_MSG 0x4
45
46/* Helper macros for system power management protocol commands */
47
48/*
49 * Macros to describe the bit-fields of the `attribute` of system power domain
50 * protocol PROTOCOL_MSG_ATTRIBUTE message.
51 */
52#define SYS_PWR_ATTR_WARM_RESET_SHIFT 31
53#define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT)
54
55#define SYS_PWR_ATTR_SUSPEND_SHIFT 30
56#define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT)
57
58/*
59 * Macros to describe the bit-fields of the `flags` parameter of system power
60 * domain protocol SYSTEM_POWER_STATE_SET message.
61 */
62#define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0
63#define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
64#define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
65
66/*
67 * Macros to describe the `system_state` parameter of system power
68 * domain protocol SYSTEM_POWER_STATE_SET message.
69 */
70#define SCMI_SYS_PWR_SHUTDOWN 0x0
71#define SCMI_SYS_PWR_COLD_RESET 0x1
72#define SCMI_SYS_PWR_WARM_RESET 0x2
73#define SCMI_SYS_PWR_POWER_UP 0x3
74#define SCMI_SYS_PWR_SUSPEND 0x4
75
76/* SCMI Error code definitions */
77#define SCMI_E_QUEUED 1
78#define SCMI_E_SUCCESS 0
79#define SCMI_E_NOT_SUPPORTED -1
80#define SCMI_E_INVALID_PARAM -2
81#define SCMI_E_DENIED -3
82#define SCMI_E_NOT_FOUND -4
83#define SCMI_E_OUT_OF_RANGE -5
84#define SCMI_E_BUSY -6
85
86/*
87 * SCMI driver platform information. The details of the doorbell mechanism
88 * can be found in the SCMI specification.
89 */
90typedef struct scmi_channel_plat_info {
91 /* SCMI mailbox memory */
92 uintptr_t scmi_mbx_mem;
93 /* The door bell register address */
94 uintptr_t db_reg_addr;
95 /* The bit mask that need to be preserved when ringing doorbell */
96 uint32_t db_preserve_mask;
97 /* The bit mask that need to be set to ring doorbell */
98 uint32_t db_modify_mask;
99} scmi_channel_plat_info_t;
100
101/*
102 * Structure to represent an SCMI channel.
103 */
104typedef struct scmi_channel {
105 scmi_channel_plat_info_t *info;
106 /* The lock for channel access */
107 bakery_lock_t *lock;
108 /* Indicate whether the channel is initialized */
109 int is_initialized;
110} scmi_channel_t;
111
112/* External Common API */
113void *scmi_init(scmi_channel_t *ch);
114int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id,
115 uint32_t *attr);
116int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version);
117
118/*
119 * Power domain protocol commands. Refer to the SCMI specification for more
120 * details on these commands.
121 */
122int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state);
123int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state);
124
125/*
126 * System power management protocol commands. Refer SCMI specification for more
127 * details on these commands.
128 */
129int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state);
130int scmi_sys_pwr_state_get(void *p, uint32_t *system_state);
131
132#endif /* __CSS_SCMI_H__ */