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