xref: /optee_os/core/drivers/scmi-msg/common.h (revision c007fb39a1a69caed90a1e94c6be0f400d8ea34e)
1ae8c8068SEtienne Carriere /* SPDX-License-Identifier: BSD-3-Clause */
2ae8c8068SEtienne Carriere /*
3ae8c8068SEtienne Carriere  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4ae8c8068SEtienne Carriere  * Copyright (c) 2019, Linaro Limited
5ae8c8068SEtienne Carriere  */
6ae8c8068SEtienne Carriere #ifndef SCMI_MSG_COMMON_H
7ae8c8068SEtienne Carriere #define SCMI_MSG_COMMON_H
8ae8c8068SEtienne Carriere 
9ae8c8068SEtienne Carriere #include <assert.h>
10ae8c8068SEtienne Carriere #include <stdbool.h>
11ae8c8068SEtienne Carriere #include <stdint.h>
12ae8c8068SEtienne Carriere #include <string.h>
13ae8c8068SEtienne Carriere #include <types_ext.h>
14ae8c8068SEtienne Carriere 
15ae8c8068SEtienne Carriere #include "base.h"
16a7a9e3baSEtienne Carriere #include "clock.h"
1756a1f10eSEtienne Carriere #include "reset_domain.h"
18ae8c8068SEtienne Carriere 
19*c007fb39SEtienne Carriere #define SCMI_VERSION			0x30000
20ae8c8068SEtienne Carriere #define SCMI_IMPL_VERSION		0
21ae8c8068SEtienne Carriere 
22ae8c8068SEtienne Carriere #define SCMI_PLAYLOAD_MAX		92
23ae8c8068SEtienne Carriere 
24ae8c8068SEtienne Carriere /*
25ae8c8068SEtienne Carriere  * Copy name identifier in target buffer following the SCMI specification
26ae8c8068SEtienne Carriere  * that state name identifier shall be a null terminated string.
27ae8c8068SEtienne Carriere  */
28ae8c8068SEtienne Carriere #define COPY_NAME_IDENTIFIER(_dst_array, _name)				\
29ae8c8068SEtienne Carriere 	do {								\
30ae8c8068SEtienne Carriere 		assert(strlen(_name) < sizeof(_dst_array));		\
31ae8c8068SEtienne Carriere 		strncpy((_dst_array), (_name), sizeof(_dst_array));	\
32ae8c8068SEtienne Carriere 	} while (0)
33ae8c8068SEtienne Carriere 
34ae8c8068SEtienne Carriere /* Common command identifiers shared by all procotols */
35ae8c8068SEtienne Carriere enum scmi_common_message_id {
36ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_VERSION = 0x000,
37ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_ATTRIBUTES = 0x001,
38ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002
39ae8c8068SEtienne Carriere };
40ae8c8068SEtienne Carriere 
41ae8c8068SEtienne Carriere /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */
42ae8c8068SEtienne Carriere struct scmi_protocol_version_p2a {
43ae8c8068SEtienne Carriere 	int32_t status;
44ae8c8068SEtienne Carriere 	uint32_t version;
45ae8c8068SEtienne Carriere };
46ae8c8068SEtienne Carriere 
47ae8c8068SEtienne Carriere /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */
48ae8c8068SEtienne Carriere struct scmi_protocol_attributes_p2a {
49ae8c8068SEtienne Carriere 	int32_t status;
50ae8c8068SEtienne Carriere 	uint32_t attributes;
51ae8c8068SEtienne Carriere };
52ae8c8068SEtienne Carriere 
53ae8c8068SEtienne Carriere /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */
54ae8c8068SEtienne Carriere struct scmi_protocol_message_attributes_a2p {
55ae8c8068SEtienne Carriere 	uint32_t message_id;
56ae8c8068SEtienne Carriere };
57ae8c8068SEtienne Carriere 
58ae8c8068SEtienne Carriere /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */
59ae8c8068SEtienne Carriere struct scmi_protocol_message_attributes_p2a {
60ae8c8068SEtienne Carriere 	int32_t status;
61ae8c8068SEtienne Carriere 	uint32_t attributes;
62ae8c8068SEtienne Carriere };
63ae8c8068SEtienne Carriere 
64ae8c8068SEtienne Carriere /*
65ae8c8068SEtienne Carriere  * struct scmi_msg - SCMI message context
66ae8c8068SEtienne Carriere  *
67ae8c8068SEtienne Carriere  * @agent_id: SCMI agent ID, safely set from secure world
68ae8c8068SEtienne Carriere  * @protocol_id: SCMI protocol ID for the related message, set by caller agent
69ae8c8068SEtienne Carriere  * @message_id: SCMI message ID for the related message, set by caller agent
70ae8c8068SEtienne Carriere  * @in: Address of the incoming message payload copied in secure memory
71ae8c8068SEtienne Carriere  * @in_size: Byte length of the incoming message payload, set by caller agent
72ae8c8068SEtienne Carriere  * @out: Address of of the output message payload message in non-secure memory
73ae8c8068SEtienne Carriere  * @out_size: Byte length of the provisionned output buffer
74ae8c8068SEtienne Carriere  * @out_size_out: Byte length of the output message payload
75ae8c8068SEtienne Carriere  */
76ae8c8068SEtienne Carriere struct scmi_msg {
77ae8c8068SEtienne Carriere 	unsigned int agent_id;
78ae8c8068SEtienne Carriere 	unsigned int protocol_id;
79ae8c8068SEtienne Carriere 	unsigned int message_id;
80ae8c8068SEtienne Carriere 	char *in;
81ae8c8068SEtienne Carriere 	size_t in_size;
82ae8c8068SEtienne Carriere 	char *out;
83ae8c8068SEtienne Carriere 	size_t out_size;
84ae8c8068SEtienne Carriere 	size_t out_size_out;
85ae8c8068SEtienne Carriere };
86ae8c8068SEtienne Carriere 
87ae8c8068SEtienne Carriere /*
88ae8c8068SEtienne Carriere  * Type scmi_msg_handler_t is used by procotol drivers to safely find
89ae8c8068SEtienne Carriere  * the handler function for the incoming message ID.
90ae8c8068SEtienne Carriere  */
91ae8c8068SEtienne Carriere typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg);
92ae8c8068SEtienne Carriere 
93ae8c8068SEtienne Carriere /*
94ae8c8068SEtienne Carriere  * scmi_msg_get_base_handler - Return a handler for a base message
95ae8c8068SEtienne Carriere  * @msg - message to process
96ae8c8068SEtienne Carriere  * Return a function handler for the message or NULL
97ae8c8068SEtienne Carriere  */
98ae8c8068SEtienne Carriere scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg);
99ae8c8068SEtienne Carriere 
100a7a9e3baSEtienne Carriere #ifdef CFG_SCMI_MSG_CLOCK
101a7a9e3baSEtienne Carriere /*
102a7a9e3baSEtienne Carriere  * scmi_msg_get_clock_handler - Return a handler for a clock message
103a7a9e3baSEtienne Carriere  * @msg - message to process
104a7a9e3baSEtienne Carriere  * Return a function handler for the message or NULL
105a7a9e3baSEtienne Carriere  */
106a7a9e3baSEtienne Carriere scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg);
107e179489eSEtienne Carriere #else
108e179489eSEtienne Carriere static inline
109e179489eSEtienne Carriere scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
110e179489eSEtienne Carriere {
111e179489eSEtienne Carriere 	return NULL;
112e179489eSEtienne Carriere }
113a7a9e3baSEtienne Carriere #endif
114a7a9e3baSEtienne Carriere 
11556a1f10eSEtienne Carriere #ifdef CFG_SCMI_MSG_RESET_DOMAIN
11656a1f10eSEtienne Carriere /*
11756a1f10eSEtienne Carriere  * scmi_msg_get_rd_handler - Return a handler for a reset domain message
11856a1f10eSEtienne Carriere  * @msg - message to process
11956a1f10eSEtienne Carriere  * Return a function handler for the message or NULL
12056a1f10eSEtienne Carriere  */
12156a1f10eSEtienne Carriere scmi_msg_handler_t scmi_msg_get_rd_handler(struct scmi_msg *msg);
122e179489eSEtienne Carriere #else
123e179489eSEtienne Carriere static inline
124e179489eSEtienne Carriere scmi_msg_handler_t scmi_msg_get_rd_handler(struct scmi_msg *msg __unused)
125e179489eSEtienne Carriere {
126e179489eSEtienne Carriere 	return NULL;
127e179489eSEtienne Carriere }
12856a1f10eSEtienne Carriere #endif
12956a1f10eSEtienne Carriere 
130006d89b8SEtienne Carriere #ifdef CFG_SCMI_MSG_VOLTAGE_DOMAIN
131006d89b8SEtienne Carriere /*
132006d89b8SEtienne Carriere  * scmi_msg_get_voltd_handler - Return a handler for a voltage domain message
133006d89b8SEtienne Carriere  * @msg - message to process
134006d89b8SEtienne Carriere  * Return a function handler for the message or NULL
135006d89b8SEtienne Carriere  */
136006d89b8SEtienne Carriere scmi_msg_handler_t scmi_msg_get_voltd_handler(struct scmi_msg *msg);
137006d89b8SEtienne Carriere #else
138006d89b8SEtienne Carriere static inline
139006d89b8SEtienne Carriere scmi_msg_handler_t scmi_msg_get_voltd_handler(struct scmi_msg *msg __unused)
140006d89b8SEtienne Carriere {
141006d89b8SEtienne Carriere 	return NULL;
142006d89b8SEtienne Carriere }
143006d89b8SEtienne Carriere #endif
144006d89b8SEtienne Carriere 
145ae8c8068SEtienne Carriere /*
146ae8c8068SEtienne Carriere  * Process Read, process and write response for input SCMI message
147ae8c8068SEtienne Carriere  *
148ae8c8068SEtienne Carriere  * @msg: SCMI message context
149ae8c8068SEtienne Carriere  */
150ae8c8068SEtienne Carriere void scmi_process_message(struct scmi_msg *msg);
151ae8c8068SEtienne Carriere 
152ae8c8068SEtienne Carriere /*
153ae8c8068SEtienne Carriere  * Write SCMI response payload to output message shared memory
154ae8c8068SEtienne Carriere  *
155ae8c8068SEtienne Carriere  * @msg: SCMI message context
156ae8c8068SEtienne Carriere  * @payload: Output message payload
157ae8c8068SEtienne Carriere  * @size: Byte size of output message payload
158ae8c8068SEtienne Carriere  */
159ae8c8068SEtienne Carriere void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size);
160ae8c8068SEtienne Carriere 
161ae8c8068SEtienne Carriere /*
162ae8c8068SEtienne Carriere  * Write status only SCMI response payload to output message shared memory
163ae8c8068SEtienne Carriere  *
164ae8c8068SEtienne Carriere  * @msg: SCMI message context
165ae8c8068SEtienne Carriere  * @status: SCMI status value returned to caller
166ae8c8068SEtienne Carriere  */
167ae8c8068SEtienne Carriere void scmi_status_response(struct scmi_msg *msg, int32_t status);
168ae8c8068SEtienne Carriere #endif /* SCMI_MSG_COMMON_H */
169