blob: 28dfc9ac6a150a1508a34432c119ea81a9763575 [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
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef SCMI_H
8#define SCMI_H
Soby Mathewea26bad2016-11-14 12:25:45 +00009
10#include <bakery_lock.h>
Chandni Cherukurie4bf6a02018-11-14 13:43:59 +053011#include <psci.h>
Soby Mathewea26bad2016-11-14 12:25:45 +000012#include <stddef.h>
13#include <stdint.h>
Roberto Vargas00996942017-11-13 13:41:58 +000014#include <spinlock.h>
Soby Mathewea26bad2016-11-14 12:25:45 +000015
16/* Supported SCMI Protocol Versions */
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010017#define SCMI_AP_CORE_PROTO_VER MAKE_SCMI_VERSION(1, 0)
Soby Mathewea26bad2016-11-14 12:25:45 +000018#define SCMI_PWR_DMN_PROTO_VER MAKE_SCMI_VERSION(1, 0)
19#define SCMI_SYS_PWR_PROTO_VER MAKE_SCMI_VERSION(1, 0)
20
21#define GET_SCMI_MAJOR_VER(ver) (((ver) >> 16) & 0xffff)
22#define GET_SCMI_MINOR_VER(ver) ((ver) & 0xffff)
23
24#define MAKE_SCMI_VERSION(maj, min) \
25 ((((maj) & 0xffff) << 16) | ((min) & 0xffff))
26
27/* Macro to check if the driver is compatible with the SCMI version reported */
28#define is_scmi_version_compatible(drv, scmi) \
29 ((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) && \
30 (GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi)))
31
32/* SCMI Protocol identifiers */
33#define SCMI_PWR_DMN_PROTO_ID 0x11
34#define SCMI_SYS_PWR_PROTO_ID 0x12
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010035/* The AP core protocol is a CSS platform-specific extension */
36#define SCMI_AP_CORE_PROTO_ID 0x90
Soby Mathewea26bad2016-11-14 12:25:45 +000037
38/* Mandatory messages IDs for all SCMI protocols */
39#define SCMI_PROTO_VERSION_MSG 0x0
40#define SCMI_PROTO_ATTR_MSG 0x1
41#define SCMI_PROTO_MSG_ATTR_MSG 0x2
42
43/* SCMI power domain management protocol message IDs */
44#define SCMI_PWR_STATE_SET_MSG 0x4
45#define SCMI_PWR_STATE_GET_MSG 0x5
46
47/* SCMI system power management protocol message IDs */
48#define SCMI_SYS_PWR_STATE_SET_MSG 0x3
49#define SCMI_SYS_PWR_STATE_GET_MSG 0x4
50
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010051/* SCMI AP core protocol message IDs */
52#define SCMI_AP_CORE_RESET_ADDR_SET_MSG 0x3
53#define SCMI_AP_CORE_RESET_ADDR_GET_MSG 0x4
54
Soby Mathewea26bad2016-11-14 12:25:45 +000055/* Helper macros for system power management protocol commands */
56
57/*
58 * Macros to describe the bit-fields of the `attribute` of system power domain
59 * protocol PROTOCOL_MSG_ATTRIBUTE message.
60 */
61#define SYS_PWR_ATTR_WARM_RESET_SHIFT 31
62#define SCMI_SYS_PWR_WARM_RESET_SUPPORTED (1U << SYS_PWR_ATTR_WARM_RESET_SHIFT)
63
64#define SYS_PWR_ATTR_SUSPEND_SHIFT 30
65#define SCMI_SYS_PWR_SUSPEND_SUPPORTED (1 << SYS_PWR_ATTR_SUSPEND_SHIFT)
66
67/*
68 * Macros to describe the bit-fields of the `flags` parameter of system power
69 * domain protocol SYSTEM_POWER_STATE_SET message.
70 */
71#define SYS_PWR_SET_GRACEFUL_REQ_SHIFT 0
72#define SCMI_SYS_PWR_GRACEFUL_REQ (1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
73#define SCMI_SYS_PWR_FORCEFUL_REQ (0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
74
75/*
76 * Macros to describe the `system_state` parameter of system power
77 * domain protocol SYSTEM_POWER_STATE_SET message.
78 */
79#define SCMI_SYS_PWR_SHUTDOWN 0x0
80#define SCMI_SYS_PWR_COLD_RESET 0x1
81#define SCMI_SYS_PWR_WARM_RESET 0x2
82#define SCMI_SYS_PWR_POWER_UP 0x3
83#define SCMI_SYS_PWR_SUSPEND 0x4
84
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +010085/*
86 * Macros to describe the bit-fields of the `attribute` of AP core protocol
87 * AP_CORE_RESET_ADDR set/get messages.
88 */
89#define SCMI_AP_CORE_LOCK_ATTR_SHIFT 0x0
90#define SCMI_AP_CORE_LOCK_ATTR (1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT)
91
Soby Mathewea26bad2016-11-14 12:25:45 +000092/* SCMI Error code definitions */
93#define SCMI_E_QUEUED 1
94#define SCMI_E_SUCCESS 0
95#define SCMI_E_NOT_SUPPORTED -1
96#define SCMI_E_INVALID_PARAM -2
97#define SCMI_E_DENIED -3
98#define SCMI_E_NOT_FOUND -4
99#define SCMI_E_OUT_OF_RANGE -5
100#define SCMI_E_BUSY -6
101
102/*
103 * SCMI driver platform information. The details of the doorbell mechanism
104 * can be found in the SCMI specification.
105 */
106typedef struct scmi_channel_plat_info {
107 /* SCMI mailbox memory */
108 uintptr_t scmi_mbx_mem;
109 /* The door bell register address */
110 uintptr_t db_reg_addr;
111 /* The bit mask that need to be preserved when ringing doorbell */
112 uint32_t db_preserve_mask;
113 /* The bit mask that need to be set to ring doorbell */
114 uint32_t db_modify_mask;
Samarth Parikh59cfa132017-11-23 14:23:21 +0530115 /* The handler for ringing doorbell */
116 void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info);
117 /* cookie is unused now. But added for future enhancements. */
118 void *cookie;
Soby Mathewea26bad2016-11-14 12:25:45 +0000119} scmi_channel_plat_info_t;
120
Roberto Vargas00996942017-11-13 13:41:58 +0000121
122#if HW_ASSISTED_COHERENCY
123typedef spinlock_t scmi_lock_t;
124#else
125typedef bakery_lock_t scmi_lock_t;
126#endif
127
Soby Mathewea26bad2016-11-14 12:25:45 +0000128/*
129 * Structure to represent an SCMI channel.
130 */
131typedef struct scmi_channel {
132 scmi_channel_plat_info_t *info;
133 /* The lock for channel access */
Roberto Vargas00996942017-11-13 13:41:58 +0000134 scmi_lock_t *lock;
Soby Mathewea26bad2016-11-14 12:25:45 +0000135 /* Indicate whether the channel is initialized */
136 int is_initialized;
137} scmi_channel_t;
138
139/* External Common API */
140void *scmi_init(scmi_channel_t *ch);
141int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id,
142 uint32_t *attr);
143int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version);
144
145/*
146 * Power domain protocol commands. Refer to the SCMI specification for more
147 * details on these commands.
148 */
149int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state);
150int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state);
151
152/*
153 * System power management protocol commands. Refer SCMI specification for more
154 * details on these commands.
155 */
156int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state);
157int scmi_sys_pwr_state_get(void *p, uint32_t *system_state);
158
Dimitris Papastamosaeaf1f02018-04-03 14:58:17 +0100159/* SCMI AP core configuration protocol commands. */
160int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr);
161int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr);
162
Chandni Cherukuri61f3a7c2018-10-11 14:08:08 +0530163/* API to get the platform specific SCMI channel information. */
164scmi_channel_plat_info_t *plat_css_get_scmi_info();
165
Chandni Cherukurie4bf6a02018-11-14 13:43:59 +0530166/* API to override default PSCI callbacks for platforms that support SCMI. */
167const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops);
168
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000169#endif /* SCMI_H */