Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 1 | /* 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 | |
| 15 | struct udevice; |
Etienne Carriere | 8bcb1b4 | 2022-05-31 18:09:18 +0200 | [diff] [blame^] | 16 | struct scmi_channel; |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * struct scmi_msg - Context of a SCMI message sent and the response received |
| 20 | * |
| 21 | * @protocol_id: SCMI protocol ID |
| 22 | * @message_id: SCMI message ID for a defined protocol ID |
| 23 | * @in_msg: Pointer to the message payload sent by the driver |
| 24 | * @in_msg_sz: Byte size of the message payload sent |
| 25 | * @out_msg: Pointer to buffer to store response message payload |
| 26 | * @out_msg_sz: Byte size of the response buffer and response payload |
| 27 | */ |
| 28 | struct scmi_msg { |
| 29 | unsigned int protocol_id; |
| 30 | unsigned int message_id; |
| 31 | u8 *in_msg; |
| 32 | size_t in_msg_sz; |
| 33 | u8 *out_msg; |
| 34 | size_t out_msg_sz; |
| 35 | }; |
| 36 | |
| 37 | /* Helper macro to match a message on input/output array references */ |
| 38 | #define SCMI_MSG_IN(_protocol, _message, _in_array, _out_array) \ |
| 39 | (struct scmi_msg){ \ |
| 40 | .protocol_id = (_protocol), \ |
| 41 | .message_id = (_message), \ |
| 42 | .in_msg = (uint8_t *)&(_in_array), \ |
| 43 | .in_msg_sz = sizeof(_in_array), \ |
| 44 | .out_msg = (uint8_t *)&(_out_array), \ |
| 45 | .out_msg_sz = sizeof(_out_array), \ |
| 46 | } |
| 47 | |
| 48 | /** |
Etienne Carriere | 5ddbbd1 | 2021-11-08 08:56:07 +0100 | [diff] [blame] | 49 | * devm_scmi_process_msg() - Send and process an SCMI message |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 50 | * |
Etienne Carriere | 5ddbbd1 | 2021-11-08 08:56:07 +0100 | [diff] [blame] | 51 | * Send a message to an SCMI server through a target SCMI agent device. |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 52 | * Caller sets scmi_msg::out_msg_sz to the output message buffer size. |
| 53 | * On return, scmi_msg::out_msg_sz stores the response payload size. |
| 54 | * |
Etienne Carriere | 6983710 | 2022-02-21 09:22:40 +0100 | [diff] [blame] | 55 | * @dev: SCMI device |
Etienne Carriere | 8bcb1b4 | 2022-05-31 18:09:18 +0200 | [diff] [blame^] | 56 | * @channel: Communication channel for the device |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 57 | * @msg: Message structure reference |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 58 | * Return: 0 on success and a negative errno on failure |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 59 | */ |
Etienne Carriere | 8bcb1b4 | 2022-05-31 18:09:18 +0200 | [diff] [blame^] | 60 | int devm_scmi_process_msg(struct udevice *dev, struct scmi_channel *channel, |
| 61 | struct scmi_msg *msg); |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code |
| 65 | * |
| 66 | * @scmi_errno: SCMI error code value |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 67 | * Return: 0 for successful status and a negative errno otherwise |
Etienne Carriere | 358599e | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 68 | */ |
| 69 | int scmi_to_linux_errno(s32 scmi_errno); |
| 70 | |
| 71 | #endif /* SCMI_H */ |