xref: /rk3399_ARM-atf/drivers/scmi-msg/common.h (revision 7e4833cdde8235d228f1f1c40f52b989ad5aa98a)
1b4734308SPeng Fan /* SPDX-License-Identifier: BSD-3-Clause */
2b4734308SPeng Fan /*
3b4734308SPeng Fan  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4b4734308SPeng Fan  * Copyright (c) 2019-2020, Linaro Limited
5b4734308SPeng Fan  */
6b4734308SPeng Fan #ifndef SCMI_MSG_COMMON_H
7b4734308SPeng Fan #define SCMI_MSG_COMMON_H
8b4734308SPeng Fan 
9b4734308SPeng Fan #include <assert.h>
10b4734308SPeng Fan #include <stdbool.h>
11b4734308SPeng Fan #include <stdint.h>
12b4734308SPeng Fan #include <string.h>
13b4734308SPeng Fan 
14b4734308SPeng Fan #include "base.h"
15b4734308SPeng Fan #include "clock.h"
16*7e4833cdSPeng Fan #include "power_domain.h"
17b4734308SPeng Fan #include "reset_domain.h"
18b4734308SPeng Fan 
19b4734308SPeng Fan #define SCMI_VERSION			0x20000U
20b4734308SPeng Fan #define SCMI_IMPL_VERSION		0U
21b4734308SPeng Fan 
22b4734308SPeng Fan #define SCMI_PLAYLOAD_MAX		92U
23b4734308SPeng Fan 
24b4734308SPeng Fan /*
25b4734308SPeng Fan  * Copy name identifier in target buffer following the SCMI specification
26b4734308SPeng Fan  * that state name identifier shall be a null terminated string.
27b4734308SPeng Fan  */
28b4734308SPeng Fan #define COPY_NAME_IDENTIFIER(_dst_array, _name)				\
29b4734308SPeng Fan 	do {								\
30b4734308SPeng Fan 		assert(strlen(_name) < sizeof(_dst_array));		\
31b4734308SPeng Fan 		strlcpy((_dst_array), (_name), sizeof(_dst_array));	\
32b4734308SPeng Fan 	} while (0)
33b4734308SPeng Fan 
34b4734308SPeng Fan /* Common command identifiers shared by all procotols */
35b4734308SPeng Fan enum scmi_common_message_id {
36b4734308SPeng Fan 	SCMI_PROTOCOL_VERSION = 0x000,
37b4734308SPeng Fan 	SCMI_PROTOCOL_ATTRIBUTES = 0x001,
38b4734308SPeng Fan 	SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002
39b4734308SPeng Fan };
40b4734308SPeng Fan 
41b4734308SPeng Fan /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */
42b4734308SPeng Fan struct scmi_protocol_version_p2a {
43b4734308SPeng Fan 	int32_t status;
44b4734308SPeng Fan 	uint32_t version;
45b4734308SPeng Fan };
46b4734308SPeng Fan 
47b4734308SPeng Fan /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */
48b4734308SPeng Fan struct scmi_protocol_attributes_p2a {
49b4734308SPeng Fan 	int32_t status;
50b4734308SPeng Fan 	uint32_t attributes;
51b4734308SPeng Fan };
52b4734308SPeng Fan 
53b4734308SPeng Fan /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */
54b4734308SPeng Fan struct scmi_protocol_message_attributes_a2p {
55b4734308SPeng Fan 	uint32_t message_id;
56b4734308SPeng Fan };
57b4734308SPeng Fan 
58b4734308SPeng Fan /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */
59b4734308SPeng Fan struct scmi_protocol_message_attributes_p2a {
60b4734308SPeng Fan 	int32_t status;
61b4734308SPeng Fan 	uint32_t attributes;
62b4734308SPeng Fan };
63b4734308SPeng Fan 
64b4734308SPeng Fan /*
65b4734308SPeng Fan  * struct scmi_msg - SCMI message context
66b4734308SPeng Fan  *
67b4734308SPeng Fan  * @agent_id: SCMI agent ID, safely set from secure world
68b4734308SPeng Fan  * @protocol_id: SCMI protocol ID for the related message, set by caller agent
69b4734308SPeng Fan  * @message_id: SCMI message ID for the related message, set by caller agent
70b4734308SPeng Fan  * @in: Address of the incoming message payload copied in secure memory
71b4734308SPeng Fan  * @in_size: Byte length of the incoming message payload, set by caller agent
72b4734308SPeng Fan  * @out: Address of of the output message payload message in non-secure memory
73b4734308SPeng Fan  * @out_size: Byte length of the provisionned output buffer
74b4734308SPeng Fan  * @out_size_out: Byte length of the output message payload
75b4734308SPeng Fan  */
76b4734308SPeng Fan struct scmi_msg {
77b4734308SPeng Fan 	unsigned int agent_id;
78b4734308SPeng Fan 	unsigned int protocol_id;
79b4734308SPeng Fan 	unsigned int message_id;
80b4734308SPeng Fan 	char *in;
81b4734308SPeng Fan 	size_t in_size;
82b4734308SPeng Fan 	char *out;
83b4734308SPeng Fan 	size_t out_size;
84b4734308SPeng Fan 	size_t out_size_out;
85b4734308SPeng Fan };
86b4734308SPeng Fan 
87b4734308SPeng Fan /*
88b4734308SPeng Fan  * Type scmi_msg_handler_t is used by procotol drivers to safely find
89b4734308SPeng Fan  * the handler function for the incoming message ID.
90b4734308SPeng Fan  */
91b4734308SPeng Fan typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg);
92b4734308SPeng Fan 
93b4734308SPeng Fan /*
94b4734308SPeng Fan  * scmi_msg_get_base_handler - Return a handler for a base message
95b4734308SPeng Fan  * @msg - message to process
96b4734308SPeng Fan  * Return a function handler for the message or NULL
97b4734308SPeng Fan  */
98b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_base_handler(struct scmi_msg *msg);
99b4734308SPeng Fan 
100b4734308SPeng Fan /*
101b4734308SPeng Fan  * scmi_msg_get_clock_handler - Return a handler for a clock message
102b4734308SPeng Fan  * @msg - message to process
103b4734308SPeng Fan  * Return a function handler for the message or NULL
104b4734308SPeng Fan  */
105b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg);
106b4734308SPeng Fan 
107b4734308SPeng Fan /*
108b4734308SPeng Fan  * scmi_msg_get_rstd_handler - Return a handler for a reset domain message
109b4734308SPeng Fan  * @msg - message to process
110b4734308SPeng Fan  * Return a function handler for the message or NULL
111b4734308SPeng Fan  */
112b4734308SPeng Fan scmi_msg_handler_t scmi_msg_get_rstd_handler(struct scmi_msg *msg);
113b4734308SPeng Fan 
114b4734308SPeng Fan /*
115*7e4833cdSPeng Fan  * scmi_msg_get_pd_handler - Return a handler for a power domain message
116*7e4833cdSPeng Fan  * @msg - message to process
117*7e4833cdSPeng Fan  * Return a function handler for the message or NULL
118*7e4833cdSPeng Fan  */
119*7e4833cdSPeng Fan scmi_msg_handler_t scmi_msg_get_pd_handler(struct scmi_msg *msg);
120*7e4833cdSPeng Fan 
121*7e4833cdSPeng Fan /*
122b4734308SPeng Fan  * Process Read, process and write response for input SCMI message
123b4734308SPeng Fan  *
124b4734308SPeng Fan  * @msg: SCMI message context
125b4734308SPeng Fan  */
126b4734308SPeng Fan void scmi_process_message(struct scmi_msg *msg);
127b4734308SPeng Fan 
128b4734308SPeng Fan /*
129b4734308SPeng Fan  * Write SCMI response payload to output message shared memory
130b4734308SPeng Fan  *
131b4734308SPeng Fan  * @msg: SCMI message context
132b4734308SPeng Fan  * @payload: Output message payload
133b4734308SPeng Fan  * @size: Byte size of output message payload
134b4734308SPeng Fan  */
135b4734308SPeng Fan void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size);
136b4734308SPeng Fan 
137b4734308SPeng Fan /*
138b4734308SPeng Fan  * Write status only SCMI response payload to output message shared memory
139b4734308SPeng Fan  *
140b4734308SPeng Fan  * @msg: SCMI message context
141b4734308SPeng Fan  * @status: SCMI status value returned to caller
142b4734308SPeng Fan  */
143b4734308SPeng Fan void scmi_status_response(struct scmi_msg *msg, int32_t status);
144b4734308SPeng Fan #endif /* SCMI_MSG_COMMON_H */
145