blob: 723fd06edc21e5470bbc445717c258a44e82cc5b [file] [log] [blame]
Soby Mathewea26bad2016-11-14 12:25:45 +00001/*
Samarth Parikh59cfa132017-11-23 14:23:21 +05302 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Soby Mathewea26bad2016-11-14 12:25:45 +00003 *
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 */
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010015#define SCMI_AP_CORE_PROTO_VER MAKE_SCMI_VERSION(1, 0)
Soby Mathewea26bad2016-11-14 12:25:45 +000016#define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0)
17#define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0)
18
19#define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff)
20#define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff)
21
22#define MAKE_SCMI_VERSION(maj, min) \
23 ((((maj) & 0xffff) << 16) | ((min) & 0xffff))
24
25/* Macro to check if the driver is compatible with the SCMI version reported */
26#define is_scmi_version_compatible(drv, scmi) \
27 ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \
28 (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi)))
29
30/* SCMI Protocol identifiers */
31#define SCMI_PWR_DMN_PROTO_ID 0x11
32#define SCMI_SYS_PWR_PROTO_ID 0x12
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010033/* The AP core protocol is a CSS platform-specific extension */
34#define SCMI_AP_CORE_PROTO_ID 0x90
Soby Mathewea26bad2016-11-14 12:25:45 +000035
36/* Mandatory messages IDs for all SCMI protocols */
37#define SCMI_PROTO_VERSION_MSG 0x0
38#define SCMI_PROTO_ATTR_MSG 0x1
39#define SCMI_PROTO_MSG_ATTR_MSG 0x2
40
41/* SCMI power domain management protocol message IDs */
42#define SCMI_PWR_STATE_SET_MSG 0x4
43#define SCMI_PWR_STATE_GET_MSG 0x5
44
45/* SCMI system power management protocol message IDs */
46#define SCMI_SYS_PWR_STATE_SET_MSG 0x3
47#define SCMI_SYS_PWR_STATE_GET_MSG 0x4
48
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010049/* SCMI AP core protocol message IDs */
50#define SCMI_AP_CORE_RESET_ADDR_SET_MSG 0x3
51#define SCMI_AP_CORE_RESET_ADDR_GET_MSG 0x4
52
Soby Mathewea26bad2016-11-14 12:25:45 +000053/* Helper macros for system power management protocol commands */
54
55/*
56 * Macros to describe the bit-fields of the `attribute` of system power domain
57 * protocol PROTOCOL_MSG_ATTRIBUTE message.
58 */
59#define SYS_PWR_ATTR_WARM_RESET_SHIFT 31
60#define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT)
61
62#define SYS_PWR_ATTR_SUSPEND_SHIFT 30
63#define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT)
64
65/*
66 * Macros to describe the bit-fields of the `flags` parameter of system power
67 * domain protocol SYSTEM_POWER_STATE_SET message.
68 */
69#define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0
70#define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
71#define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
72
73/*
74 * Macros to describe the `system_state` parameter of system power
75 * domain protocol SYSTEM_POWER_STATE_SET message.
76 */
77#define SCMI_SYS_PWR_SHUTDOWN 0x0
78#define SCMI_SYS_PWR_COLD_RESET 0x1
79#define SCMI_SYS_PWR_WARM_RESET 0x2
80#define SCMI_SYS_PWR_POWER_UP 0x3
81#define SCMI_SYS_PWR_SUSPEND 0x4
82
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010083/*
84 * Macros to describe the bit-fields of the `attribute` of AP core protocol
85 * AP_CORE_RESET_ADDR set/get messages.
86 */
87#define SCMI_AP_CORE_LOCK_ATTR_SHIFT 0x0
88#define SCMI_AP_CORE_LOCK_ATTR (1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT)
89
Soby Mathewea26bad2016-11-14 12:25:45 +000090/* SCMI Error code definitions */
91#define SCMI_E_QUEUED 1
92#define SCMI_E_SUCCESS 0
93#define SCMI_E_NOT_SUPPORTED -1
94#define SCMI_E_INVALID_PARAM -2
95#define SCMI_E_DENIED -3
96#define SCMI_E_NOT_FOUND -4
97#define SCMI_E_OUT_OF_RANGE -5
98#define SCMI_E_BUSY -6
99
100/*
101 * SCMI driver platform information. The details of the doorbell mechanism
102 * can be found in the SCMI specification.
103 */
104typedef struct scmi_channel_plat_info {
105 /* SCMI mailbox memory */
106 uintptr_t scmi_mbx_mem;
107 /* The door bell register address */
108 uintptr_t db_reg_addr;
109 /* The bit mask that need to be preserved when ringing doorbell */
110 uint32_t db_preserve_mask;
111 /* The bit mask that need to be set to ring doorbell */
112 uint32_t db_modify_mask;
Samarth Parikh59cfa132017-11-23 14:23:21 +0530113 /* The handler for ringing doorbell */
114 void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info);
115 /* cookie is unused now. But added for future enhancements. */
116 void *cookie;
Soby Mathewea26bad2016-11-14 12:25:45 +0000117} scmi_channel_plat_info_t;
118
119/*
120 * Structure to represent an SCMI channel.
121 */
122typedef struct scmi_channel {
123 scmi_channel_plat_info_t *info;
124 /* The lock for channel access */
125 bakery_lock_t *lock;
126 /* Indicate whether the channel is initialized */
127 int is_initialized;
128} scmi_channel_t;
129
130/* External Common API */
131void *scmi_init(scmi_channel_t *ch);
132int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id,
133 uint32_t *attr);
134int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version);
135
136/*
137 * Power domain protocol commands. Refer to the SCMI specification for more
138 * details on these commands.
139 */
140int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state);
141int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state);
142
143/*
144 * System power management protocol commands. Refer SCMI specification for more
145 * details on these commands.
146 */
147int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state);
148int scmi_sys_pwr_state_get(void *p, uint32_t *system_state);
149
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +0100150/* SCMI AP core configuration protocol commands. */
151int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr);
152int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr);
153
Soby Mathewea26bad2016-11-14 12:25:45 +0000154#endif /* __CSS_SCMI_H__ */