xref: /optee_os/core/drivers/scmi-msg/common.h (revision 5c34a982f7e3cc1b802c20a166d892b8f5d35f18)
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 
15c007fb39SEtienne Carriere #define SCMI_VERSION			0x30000
16ae8c8068SEtienne Carriere #define SCMI_IMPL_VERSION		0
17ae8c8068SEtienne Carriere 
18ae8c8068SEtienne Carriere #define SCMI_PLAYLOAD_MAX		92
19ae8c8068SEtienne Carriere 
20ae8c8068SEtienne Carriere /*
21ae8c8068SEtienne Carriere  * Copy name identifier in target buffer following the SCMI specification
22ae8c8068SEtienne Carriere  * that state name identifier shall be a null terminated string.
23ae8c8068SEtienne Carriere  */
24ae8c8068SEtienne Carriere #define COPY_NAME_IDENTIFIER(_dst_array, _name)				\
25ae8c8068SEtienne Carriere 	do {								\
26ae8c8068SEtienne Carriere 		assert(strlen(_name) < sizeof(_dst_array));		\
27ae8c8068SEtienne Carriere 		strncpy((_dst_array), (_name), sizeof(_dst_array));	\
28ae8c8068SEtienne Carriere 	} while (0)
29ae8c8068SEtienne Carriere 
30ae8c8068SEtienne Carriere /* Common command identifiers shared by all procotols */
31ae8c8068SEtienne Carriere enum scmi_common_message_id {
32ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_VERSION = 0x000,
33ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_ATTRIBUTES = 0x001,
34ae8c8068SEtienne Carriere 	SCMI_PROTOCOL_MESSAGE_ATTRIBUTES = 0x002
35ae8c8068SEtienne Carriere };
36ae8c8068SEtienne Carriere 
37ae8c8068SEtienne Carriere /* Common platform-to-agent (p2a) PROTOCOL_VERSION structure */
38ae8c8068SEtienne Carriere struct scmi_protocol_version_p2a {
39ae8c8068SEtienne Carriere 	int32_t status;
40ae8c8068SEtienne Carriere 	uint32_t version;
41ae8c8068SEtienne Carriere };
42ae8c8068SEtienne Carriere 
43ae8c8068SEtienne Carriere /* Generic platform-to-agent (p2a) PROTOCOL_ATTRIBUTES structure */
44ae8c8068SEtienne Carriere struct scmi_protocol_attributes_p2a {
45ae8c8068SEtienne Carriere 	int32_t status;
46ae8c8068SEtienne Carriere 	uint32_t attributes;
47ae8c8068SEtienne Carriere };
48ae8c8068SEtienne Carriere 
49ae8c8068SEtienne Carriere /* Generic agent-to-platform (a2p) PROTOCOL_MESSAGE_ATTRIBUTES structure */
50ae8c8068SEtienne Carriere struct scmi_protocol_message_attributes_a2p {
51ae8c8068SEtienne Carriere 	uint32_t message_id;
52ae8c8068SEtienne Carriere };
53ae8c8068SEtienne Carriere 
54ae8c8068SEtienne Carriere /* Generic platform-to-agent (p2a) PROTOCOL_MESSAGE_ATTRIBUTES structure */
55ae8c8068SEtienne Carriere struct scmi_protocol_message_attributes_p2a {
56ae8c8068SEtienne Carriere 	int32_t status;
57ae8c8068SEtienne Carriere 	uint32_t attributes;
58ae8c8068SEtienne Carriere };
59ae8c8068SEtienne Carriere 
60ae8c8068SEtienne Carriere /*
61ae8c8068SEtienne Carriere  * struct scmi_msg - SCMI message context
62ae8c8068SEtienne Carriere  *
63659a1f88SEtienne Carriere  * @channel_id: SCMI channel ID, safely set from secure world
64ae8c8068SEtienne Carriere  * @protocol_id: SCMI protocol ID for the related message, set by caller agent
65ae8c8068SEtienne Carriere  * @message_id: SCMI message ID for the related message, set by caller agent
66ae8c8068SEtienne Carriere  * @in: Address of the incoming message payload copied in secure memory
67ae8c8068SEtienne Carriere  * @in_size: Byte length of the incoming message payload, set by caller agent
68ae8c8068SEtienne Carriere  * @out: Address of of the output message payload message in non-secure memory
69ae8c8068SEtienne Carriere  * @out_size: Byte length of the provisionned output buffer
70ae8c8068SEtienne Carriere  * @out_size_out: Byte length of the output message payload
71ae8c8068SEtienne Carriere  */
72ae8c8068SEtienne Carriere struct scmi_msg {
73659a1f88SEtienne Carriere 	unsigned int channel_id;
74ae8c8068SEtienne Carriere 	unsigned int protocol_id;
75ae8c8068SEtienne Carriere 	unsigned int message_id;
76ae8c8068SEtienne Carriere 	char *in;
77ae8c8068SEtienne Carriere 	size_t in_size;
78ae8c8068SEtienne Carriere 	char *out;
79ae8c8068SEtienne Carriere 	size_t out_size;
80ae8c8068SEtienne Carriere 	size_t out_size_out;
81ae8c8068SEtienne Carriere };
82ae8c8068SEtienne Carriere 
83ae8c8068SEtienne Carriere /*
84ae8c8068SEtienne Carriere  * Type scmi_msg_handler_t is used by procotol drivers to safely find
85ae8c8068SEtienne Carriere  * the handler function for the incoming message ID.
86ae8c8068SEtienne Carriere  */
87ae8c8068SEtienne Carriere typedef void (*scmi_msg_handler_t)(struct scmi_msg *msg);
88ae8c8068SEtienne Carriere 
89ae8c8068SEtienne Carriere /*
90ae8c8068SEtienne Carriere  * Process Read, process and write response for input SCMI message
91ae8c8068SEtienne Carriere  *
92ae8c8068SEtienne Carriere  * @msg: SCMI message context
93ae8c8068SEtienne Carriere  */
94ae8c8068SEtienne Carriere void scmi_process_message(struct scmi_msg *msg);
95ae8c8068SEtienne Carriere 
96ae8c8068SEtienne Carriere /*
97ae8c8068SEtienne Carriere  * Write SCMI response payload to output message shared memory
98ae8c8068SEtienne Carriere  *
99ae8c8068SEtienne Carriere  * @msg: SCMI message context
100ae8c8068SEtienne Carriere  * @payload: Output message payload
101ae8c8068SEtienne Carriere  * @size: Byte size of output message payload
102ae8c8068SEtienne Carriere  */
103ae8c8068SEtienne Carriere void scmi_write_response(struct scmi_msg *msg, void *payload, size_t size);
104ae8c8068SEtienne Carriere 
105ae8c8068SEtienne Carriere /*
106ae8c8068SEtienne Carriere  * Write status only SCMI response payload to output message shared memory
107ae8c8068SEtienne Carriere  *
108ae8c8068SEtienne Carriere  * @msg: SCMI message context
109ae8c8068SEtienne Carriere  * @status: SCMI status value returned to caller
110ae8c8068SEtienne Carriere  */
111ae8c8068SEtienne Carriere void scmi_status_response(struct scmi_msg *msg, int32_t status);
112*5c34a982SEtienne Carriere 
113*5c34a982SEtienne Carriere /*
114*5c34a982SEtienne Carriere  * Claim access to channel
115*5c34a982SEtienne Carriere  * @channel: SCMI channel reference
116*5c34a982SEtienne Carriere  * Return true upon success or false if the channel is already busy
117*5c34a982SEtienne Carriere  */
118*5c34a982SEtienne Carriere bool scmi_msg_claim_channel(struct scmi_msg_channel *channel);
119*5c34a982SEtienne Carriere 
120*5c34a982SEtienne Carriere /*
121*5c34a982SEtienne Carriere  * Release access channel
122*5c34a982SEtienne Carriere  * @channel: SCMI channel reference
123*5c34a982SEtienne Carriere  */
124*5c34a982SEtienne Carriere void scmi_msg_release_channel(struct scmi_msg_channel *channel);
125ae8c8068SEtienne Carriere #endif /* SCMI_MSG_COMMON_H */
126