blob: 5015c06be99a25276600fca82591c33c7cb52e23 [file] [log] [blame]
Etienne Carriere02fd1262020-09-09 18:44:00 +02001/* SPDX-License-Identifier: GPL-2.0 OR 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 * An SCMI agent device represent on communication path from a
7 * device driver to the remote SCMI server which driver sends
8 * messages to and receives response messages from.
9 */
10#ifndef SCMI_AGENT_H
11#define SCMI_AGENT_H
12
13#include <asm/types.h>
14
15struct udevice;
16
17/*
18 * struct scmi_msg - Context of a SCMI message sent and the response received
19 *
20 * @protocol_id: SCMI protocol ID
21 * @message_id: SCMI message ID for a defined protocol ID
22 * @in_msg: Pointer to the message payload sent by the driver
23 * @in_msg_sz: Byte size of the message payload sent
24 * @out_msg: Pointer to buffer to store response message payload
25 * @out_msg_sz: Byte size of the response buffer and response payload
26 */
27struct scmi_msg {
28 unsigned int protocol_id;
29 unsigned int message_id;
30 u8 *in_msg;
31 size_t in_msg_sz;
32 u8 *out_msg;
33 size_t out_msg_sz;
34};
35
36/* Helper macro to match a message on input/output array references */
37#define SCMI_MSG_IN(_protocol, _message, _in_array, _out_array) \
38 (struct scmi_msg){ \
39 .protocol_id = (_protocol), \
40 .message_id = (_message), \
41 .in_msg = (uint8_t *)&(_in_array), \
42 .in_msg_sz = sizeof(_in_array), \
43 .out_msg = (uint8_t *)&(_out_array), \
44 .out_msg_sz = sizeof(_out_array), \
45 }
46
47/**
Etienne Carriere63255202021-11-08 08:56:07 +010048 * devm_scmi_process_msg() - Send and process an SCMI message
Etienne Carriere02fd1262020-09-09 18:44:00 +020049 *
Etienne Carriere63255202021-11-08 08:56:07 +010050 * Send a message to an SCMI server through a target SCMI agent device.
Etienne Carriere02fd1262020-09-09 18:44:00 +020051 * Caller sets scmi_msg::out_msg_sz to the output message buffer size.
52 * On return, scmi_msg::out_msg_sz stores the response payload size.
53 *
54 * @dev: SCMI agent device
55 * @msg: Message structure reference
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010056 * Return: 0 on success and a negative errno on failure
Etienne Carriere02fd1262020-09-09 18:44:00 +020057 */
58int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg);
59
60/**
61 * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code
62 *
63 * @scmi_errno: SCMI error code value
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010064 * Return: 0 for successful status and a negative errno otherwise
Etienne Carriere02fd1262020-09-09 18:44:00 +020065 */
66int scmi_to_linux_errno(s32 scmi_errno);
67
68#endif /* SCMI_H */