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