xref: /OK3568_Linux_fs/u-boot/include/scmi_agent.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4*4882a593Smuzhiyun  * Copyright (C) 2019-2020, Linaro Limited
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * An SCMI agent device represent on communication path from a
7*4882a593Smuzhiyun  * device driver to the remote SCMI server which driver sends
8*4882a593Smuzhiyun  * messages to and receives response messages from.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun #ifndef SCMI_AGENT_H
11*4882a593Smuzhiyun #define SCMI_AGENT_H
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <asm/types.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct udevice;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * struct scmi_msg - Context of a SCMI message sent and the response received
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * @protocol_id:	SCMI protocol ID
21*4882a593Smuzhiyun  * @message_id:		SCMI message ID for a defined protocol ID
22*4882a593Smuzhiyun  * @in_msg:		Pointer to the message payload sent by the driver
23*4882a593Smuzhiyun  * @in_msg_sz:		Byte size of the message payload sent
24*4882a593Smuzhiyun  * @out_msg:		Pointer to buffer to store response message payload
25*4882a593Smuzhiyun  * @out_msg_sz:		Byte size of the response buffer and response payload
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun struct scmi_msg {
28*4882a593Smuzhiyun 	unsigned int protocol_id;
29*4882a593Smuzhiyun 	unsigned int message_id;
30*4882a593Smuzhiyun 	u8 *in_msg;
31*4882a593Smuzhiyun 	size_t in_msg_sz;
32*4882a593Smuzhiyun 	u8 *out_msg;
33*4882a593Smuzhiyun 	size_t out_msg_sz;
34*4882a593Smuzhiyun };
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* Helper macro to match a message on input/output array references */
37*4882a593Smuzhiyun #define SCMI_MSG_IN(_protocol, _message, _in_array, _out_array) \
38*4882a593Smuzhiyun 	(struct scmi_msg){			\
39*4882a593Smuzhiyun 		.protocol_id = (_protocol),	\
40*4882a593Smuzhiyun 		.message_id = (_message),	\
41*4882a593Smuzhiyun 		.in_msg = (uint8_t *)&(_in_array),	\
42*4882a593Smuzhiyun 		.in_msg_sz = sizeof(_in_array),	\
43*4882a593Smuzhiyun 		.out_msg = (uint8_t *)&(_out_array),	\
44*4882a593Smuzhiyun 		.out_msg_sz = sizeof(_out_array),	\
45*4882a593Smuzhiyun 	}
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun  * scmi_send_and_process_msg() - send and process a SCMI message
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * Send a message to a SCMI server through a target SCMI agent device.
51*4882a593Smuzhiyun  * Caller sets scmi_msg::out_msg_sz to the output message buffer size.
52*4882a593Smuzhiyun  * On return, scmi_msg::out_msg_sz stores the response payload size.
53*4882a593Smuzhiyun  *
54*4882a593Smuzhiyun  * @dev:	SCMI agent device
55*4882a593Smuzhiyun  * @msg:	Message structure reference
56*4882a593Smuzhiyun  * @return 0 on success and a negative errno on failure
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /**
61*4882a593Smuzhiyun  * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  * @scmi_errno:	SCMI error code value
64*4882a593Smuzhiyun  * @return 0 for successful status and a negative errno otherwise
65*4882a593Smuzhiyun  */
66*4882a593Smuzhiyun int scmi_to_linux_errno(s32 scmi_errno);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun #endif /* SCMI_H */
69