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