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