xref: /arm-trusted-firmware/include/drivers/arm/css/scmi.h (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #ifndef SCMI_H
8*91f16700Schasinglulu #define SCMI_H
9*91f16700Schasinglulu 
10*91f16700Schasinglulu #include <stddef.h>
11*91f16700Schasinglulu #include <stdint.h>
12*91f16700Schasinglulu 
13*91f16700Schasinglulu #include <lib/bakery_lock.h>
14*91f16700Schasinglulu #include <lib/psci/psci.h>
15*91f16700Schasinglulu #include <lib/spinlock.h>
16*91f16700Schasinglulu 
17*91f16700Schasinglulu /* Supported SCMI Protocol Versions */
18*91f16700Schasinglulu #define SCMI_AP_CORE_PROTO_VER			MAKE_SCMI_VERSION(1, 0)
19*91f16700Schasinglulu #define SCMI_PWR_DMN_PROTO_VER			MAKE_SCMI_VERSION(2, 0)
20*91f16700Schasinglulu #define SCMI_SYS_PWR_PROTO_VER			MAKE_SCMI_VERSION(1, 0)
21*91f16700Schasinglulu 
22*91f16700Schasinglulu #define GET_SCMI_MAJOR_VER(ver)			(((ver) >> 16) & 0xffff)
23*91f16700Schasinglulu #define GET_SCMI_MINOR_VER(ver)			((ver) & 0xffff)
24*91f16700Schasinglulu 
25*91f16700Schasinglulu #define MAKE_SCMI_VERSION(maj, min)	\
26*91f16700Schasinglulu 			((((maj) & 0xffff) << 16) | ((min) & 0xffff))
27*91f16700Schasinglulu 
28*91f16700Schasinglulu /*
29*91f16700Schasinglulu  * Check that the driver's version is same or higher than the reported SCMI
30*91f16700Schasinglulu  * version. We accept lower major version numbers, as all affected protocols
31*91f16700Schasinglulu  * so far stay backwards compatible. This might need to be revisited in the
32*91f16700Schasinglulu  * future.
33*91f16700Schasinglulu  */
34*91f16700Schasinglulu #define is_scmi_version_compatible(drv, scmi)				\
35*91f16700Schasinglulu 	((GET_SCMI_MAJOR_VER(drv) > GET_SCMI_MAJOR_VER(scmi)) ||	\
36*91f16700Schasinglulu 	((GET_SCMI_MAJOR_VER(drv) == GET_SCMI_MAJOR_VER(scmi)) &&	\
37*91f16700Schasinglulu 	(GET_SCMI_MINOR_VER(drv) <= GET_SCMI_MINOR_VER(scmi))))
38*91f16700Schasinglulu 
39*91f16700Schasinglulu /* SCMI Protocol identifiers */
40*91f16700Schasinglulu #define SCMI_PWR_DMN_PROTO_ID			0x11
41*91f16700Schasinglulu #define SCMI_SYS_PWR_PROTO_ID			0x12
42*91f16700Schasinglulu /* The AP core protocol is a CSS platform-specific extension */
43*91f16700Schasinglulu #define SCMI_AP_CORE_PROTO_ID			0x90
44*91f16700Schasinglulu 
45*91f16700Schasinglulu /* Mandatory messages IDs for all SCMI protocols */
46*91f16700Schasinglulu #define SCMI_PROTO_VERSION_MSG			0x0
47*91f16700Schasinglulu #define SCMI_PROTO_ATTR_MSG			0x1
48*91f16700Schasinglulu #define SCMI_PROTO_MSG_ATTR_MSG			0x2
49*91f16700Schasinglulu 
50*91f16700Schasinglulu /* SCMI power domain management protocol message IDs */
51*91f16700Schasinglulu #define SCMI_PWR_STATE_SET_MSG			0x4
52*91f16700Schasinglulu #define SCMI_PWR_STATE_GET_MSG			0x5
53*91f16700Schasinglulu 
54*91f16700Schasinglulu /* SCMI system power management protocol message IDs */
55*91f16700Schasinglulu #define SCMI_SYS_PWR_STATE_SET_MSG		0x3
56*91f16700Schasinglulu #define SCMI_SYS_PWR_STATE_GET_MSG		0x4
57*91f16700Schasinglulu 
58*91f16700Schasinglulu /* SCMI AP core protocol message IDs */
59*91f16700Schasinglulu #define SCMI_AP_CORE_RESET_ADDR_SET_MSG		0x3
60*91f16700Schasinglulu #define SCMI_AP_CORE_RESET_ADDR_GET_MSG		0x4
61*91f16700Schasinglulu 
62*91f16700Schasinglulu /* Helper macros for system power management protocol commands */
63*91f16700Schasinglulu 
64*91f16700Schasinglulu /*
65*91f16700Schasinglulu  * Macros to describe the bit-fields of the `attribute` of system power domain
66*91f16700Schasinglulu  * protocol PROTOCOL_MSG_ATTRIBUTE message.
67*91f16700Schasinglulu  */
68*91f16700Schasinglulu #define SYS_PWR_ATTR_WARM_RESET_SHIFT		31
69*91f16700Schasinglulu #define SCMI_SYS_PWR_WARM_RESET_SUPPORTED	(1U << SYS_PWR_ATTR_WARM_RESET_SHIFT)
70*91f16700Schasinglulu 
71*91f16700Schasinglulu #define SYS_PWR_ATTR_SUSPEND_SHIFT		30
72*91f16700Schasinglulu #define SCMI_SYS_PWR_SUSPEND_SUPPORTED		(1 << SYS_PWR_ATTR_SUSPEND_SHIFT)
73*91f16700Schasinglulu 
74*91f16700Schasinglulu /*
75*91f16700Schasinglulu  * Macros to describe the bit-fields of the `flags` parameter of system power
76*91f16700Schasinglulu  * domain protocol SYSTEM_POWER_STATE_SET message.
77*91f16700Schasinglulu  */
78*91f16700Schasinglulu #define SYS_PWR_SET_GRACEFUL_REQ_SHIFT		0
79*91f16700Schasinglulu #define SCMI_SYS_PWR_GRACEFUL_REQ		(1 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
80*91f16700Schasinglulu #define SCMI_SYS_PWR_FORCEFUL_REQ		(0 << SYS_PWR_SET_GRACEFUL_REQ_SHIFT)
81*91f16700Schasinglulu 
82*91f16700Schasinglulu /*
83*91f16700Schasinglulu  * Macros to describe the `system_state` parameter of system power
84*91f16700Schasinglulu  * domain protocol SYSTEM_POWER_STATE_SET message.
85*91f16700Schasinglulu  */
86*91f16700Schasinglulu #define SCMI_SYS_PWR_SHUTDOWN			0x0
87*91f16700Schasinglulu #define SCMI_SYS_PWR_COLD_RESET			0x1
88*91f16700Schasinglulu #define SCMI_SYS_PWR_WARM_RESET			0x2
89*91f16700Schasinglulu #define SCMI_SYS_PWR_POWER_UP			0x3
90*91f16700Schasinglulu #define SCMI_SYS_PWR_SUSPEND			0x4
91*91f16700Schasinglulu 
92*91f16700Schasinglulu /*
93*91f16700Schasinglulu  * Macros to describe the bit-fields of the `attribute` of AP core protocol
94*91f16700Schasinglulu  * AP_CORE_RESET_ADDR set/get messages.
95*91f16700Schasinglulu  */
96*91f16700Schasinglulu #define SCMI_AP_CORE_LOCK_ATTR_SHIFT		0x0
97*91f16700Schasinglulu #define SCMI_AP_CORE_LOCK_ATTR			(1U << SCMI_AP_CORE_LOCK_ATTR_SHIFT)
98*91f16700Schasinglulu 
99*91f16700Schasinglulu /* SCMI Error code definitions */
100*91f16700Schasinglulu #define SCMI_E_QUEUED			1
101*91f16700Schasinglulu #define SCMI_E_SUCCESS			0
102*91f16700Schasinglulu #define SCMI_E_NOT_SUPPORTED		-1
103*91f16700Schasinglulu #define SCMI_E_INVALID_PARAM		-2
104*91f16700Schasinglulu #define SCMI_E_DENIED			-3
105*91f16700Schasinglulu #define SCMI_E_NOT_FOUND		-4
106*91f16700Schasinglulu #define SCMI_E_OUT_OF_RANGE		-5
107*91f16700Schasinglulu #define SCMI_E_BUSY			-6
108*91f16700Schasinglulu 
109*91f16700Schasinglulu /*
110*91f16700Schasinglulu  * SCMI driver platform information. The details of the doorbell mechanism
111*91f16700Schasinglulu  * can be found in the SCMI specification.
112*91f16700Schasinglulu  */
113*91f16700Schasinglulu typedef struct scmi_channel_plat_info {
114*91f16700Schasinglulu 	/* SCMI mailbox memory */
115*91f16700Schasinglulu 	uintptr_t scmi_mbx_mem;
116*91f16700Schasinglulu 	/* The door bell register address */
117*91f16700Schasinglulu 	uintptr_t db_reg_addr;
118*91f16700Schasinglulu 	/* The bit mask that need to be preserved when ringing doorbell */
119*91f16700Schasinglulu 	uint32_t db_preserve_mask;
120*91f16700Schasinglulu 	/* The bit mask that need to be set to ring doorbell */
121*91f16700Schasinglulu 	uint32_t db_modify_mask;
122*91f16700Schasinglulu 	/* The handler for ringing doorbell */
123*91f16700Schasinglulu 	void (*ring_doorbell)(struct scmi_channel_plat_info *plat_info);
124*91f16700Schasinglulu 	/* cookie is unused now. But added for future enhancements. */
125*91f16700Schasinglulu 	void *cookie;
126*91f16700Schasinglulu } scmi_channel_plat_info_t;
127*91f16700Schasinglulu 
128*91f16700Schasinglulu 
129*91f16700Schasinglulu #if HW_ASSISTED_COHERENCY
130*91f16700Schasinglulu typedef spinlock_t scmi_lock_t;
131*91f16700Schasinglulu #else
132*91f16700Schasinglulu typedef bakery_lock_t scmi_lock_t;
133*91f16700Schasinglulu #endif
134*91f16700Schasinglulu 
135*91f16700Schasinglulu /*
136*91f16700Schasinglulu  * Structure to represent an SCMI channel.
137*91f16700Schasinglulu  */
138*91f16700Schasinglulu typedef struct scmi_channel {
139*91f16700Schasinglulu 	scmi_channel_plat_info_t *info;
140*91f16700Schasinglulu 	 /* The lock for channel access */
141*91f16700Schasinglulu 	scmi_lock_t *lock;
142*91f16700Schasinglulu 	/* Indicate whether the channel is initialized */
143*91f16700Schasinglulu 	int is_initialized;
144*91f16700Schasinglulu } scmi_channel_t;
145*91f16700Schasinglulu 
146*91f16700Schasinglulu /* External Common API */
147*91f16700Schasinglulu void *scmi_init(scmi_channel_t *ch);
148*91f16700Schasinglulu int scmi_proto_msg_attr(void *p, uint32_t proto_id, uint32_t command_id,
149*91f16700Schasinglulu 						uint32_t *attr);
150*91f16700Schasinglulu int scmi_proto_version(void *p, uint32_t proto_id, uint32_t *version);
151*91f16700Schasinglulu 
152*91f16700Schasinglulu /*
153*91f16700Schasinglulu  * Power domain protocol commands. Refer to the SCMI specification for more
154*91f16700Schasinglulu  * details on these commands.
155*91f16700Schasinglulu  */
156*91f16700Schasinglulu int scmi_pwr_state_set(void *p, uint32_t domain_id, uint32_t scmi_pwr_state);
157*91f16700Schasinglulu int scmi_pwr_state_get(void *p, uint32_t domain_id, uint32_t *scmi_pwr_state);
158*91f16700Schasinglulu 
159*91f16700Schasinglulu /*
160*91f16700Schasinglulu  * System power management protocol commands. Refer SCMI specification for more
161*91f16700Schasinglulu  * details on these commands.
162*91f16700Schasinglulu  */
163*91f16700Schasinglulu int scmi_sys_pwr_state_set(void *p, uint32_t flags, uint32_t system_state);
164*91f16700Schasinglulu int scmi_sys_pwr_state_get(void *p, uint32_t *system_state);
165*91f16700Schasinglulu 
166*91f16700Schasinglulu /* SCMI AP core configuration protocol commands. */
167*91f16700Schasinglulu int scmi_ap_core_set_reset_addr(void *p, uint64_t reset_addr, uint32_t attr);
168*91f16700Schasinglulu int scmi_ap_core_get_reset_addr(void *p, uint64_t *reset_addr, uint32_t *attr);
169*91f16700Schasinglulu 
170*91f16700Schasinglulu /* API to get the platform specific SCMI channel information. */
171*91f16700Schasinglulu scmi_channel_plat_info_t *plat_css_get_scmi_info(unsigned int channel_id);
172*91f16700Schasinglulu 
173*91f16700Schasinglulu /* API to override default PSCI callbacks for platforms that support SCMI. */
174*91f16700Schasinglulu const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops);
175*91f16700Schasinglulu 
176*91f16700Schasinglulu #endif /* SCMI_H */
177