Etienne Carriere | 02fd126 | 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 | |
AKASHI Takahiro | 6c90f82 | 2023-10-11 19:06:58 +0900 | [diff] [blame] | 13 | #include <scmi_protocols.h> |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 14 | #include <asm/types.h> |
| 15 | |
| 16 | struct udevice; |
Etienne Carriere | a1e8751 | 2022-05-31 18:09:18 +0200 | [diff] [blame] | 17 | struct scmi_channel; |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 18 | |
AKASHI Takahiro | 7b3aa37 | 2023-10-11 19:06:54 +0900 | [diff] [blame] | 19 | /** |
| 20 | * struct scmi_agent_proto_priv - Private data in device for SCMI agent |
| 21 | * @channel: Reference to the SCMI channel to use |
| 22 | */ |
| 23 | struct scmi_agent_proto_priv { |
| 24 | struct scmi_channel *channel; |
| 25 | }; |
| 26 | |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 27 | /* |
| 28 | * struct scmi_msg - Context of a SCMI message sent and the response received |
| 29 | * |
| 30 | * @protocol_id: SCMI protocol ID |
| 31 | * @message_id: SCMI message ID for a defined protocol ID |
| 32 | * @in_msg: Pointer to the message payload sent by the driver |
| 33 | * @in_msg_sz: Byte size of the message payload sent |
| 34 | * @out_msg: Pointer to buffer to store response message payload |
| 35 | * @out_msg_sz: Byte size of the response buffer and response payload |
| 36 | */ |
| 37 | struct scmi_msg { |
| 38 | unsigned int protocol_id; |
| 39 | unsigned int message_id; |
| 40 | u8 *in_msg; |
| 41 | size_t in_msg_sz; |
| 42 | u8 *out_msg; |
| 43 | size_t out_msg_sz; |
| 44 | }; |
| 45 | |
| 46 | /* Helper macro to match a message on input/output array references */ |
| 47 | #define SCMI_MSG_IN(_protocol, _message, _in_array, _out_array) \ |
| 48 | (struct scmi_msg){ \ |
| 49 | .protocol_id = (_protocol), \ |
| 50 | .message_id = (_message), \ |
| 51 | .in_msg = (uint8_t *)&(_in_array), \ |
| 52 | .in_msg_sz = sizeof(_in_array), \ |
| 53 | .out_msg = (uint8_t *)&(_out_array), \ |
| 54 | .out_msg_sz = sizeof(_out_array), \ |
| 55 | } |
| 56 | |
| 57 | /** |
Etienne Carriere | 187cea1 | 2022-05-31 18:09:21 +0200 | [diff] [blame] | 58 | * devm_scmi_of_get_channel() - Get SCMI channel handle from SCMI agent DT node |
| 59 | * |
| 60 | * @dev: Device requesting a channel |
Etienne Carriere | 187cea1 | 2022-05-31 18:09:21 +0200 | [diff] [blame] | 61 | * @return 0 on success and a negative errno on failure |
| 62 | */ |
AKASHI Takahiro | 7b3aa37 | 2023-10-11 19:06:54 +0900 | [diff] [blame] | 63 | int devm_scmi_of_get_channel(struct udevice *dev); |
Etienne Carriere | 187cea1 | 2022-05-31 18:09:21 +0200 | [diff] [blame] | 64 | |
| 65 | /** |
Etienne Carriere | 6325520 | 2021-11-08 08:56:07 +0100 | [diff] [blame] | 66 | * devm_scmi_process_msg() - Send and process an SCMI message |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 67 | * |
Etienne Carriere | 6325520 | 2021-11-08 08:56:07 +0100 | [diff] [blame] | 68 | * Send a message to an SCMI server through a target SCMI agent device. |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 69 | * Caller sets scmi_msg::out_msg_sz to the output message buffer size. |
| 70 | * On return, scmi_msg::out_msg_sz stores the response payload size. |
| 71 | * |
Etienne Carriere | 2f26c04 | 2022-02-21 09:22:40 +0100 | [diff] [blame] | 72 | * @dev: SCMI device |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 73 | * @msg: Message structure reference |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 74 | * Return: 0 on success and a negative errno on failure |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 75 | */ |
AKASHI Takahiro | 7b3aa37 | 2023-10-11 19:06:54 +0900 | [diff] [blame] | 76 | int devm_scmi_process_msg(struct udevice *dev, struct scmi_msg *msg); |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 77 | |
| 78 | /** |
AKASHI Takahiro | 6c90f82 | 2023-10-11 19:06:58 +0900 | [diff] [blame] | 79 | * scmi_get_protocol() - get protocol instance |
| 80 | * |
| 81 | * @dev: SCMI agent device |
| 82 | * @id: SCMI protocol ID |
| 83 | * |
| 84 | * Obtain the device instance for given protocol ID, @id. |
| 85 | * |
| 86 | * Return: Pointer to the device if found, null otherwise |
| 87 | */ |
| 88 | struct udevice *scmi_get_protocol(struct udevice *dev, |
| 89 | enum scmi_std_protocol id); |
| 90 | |
| 91 | /** |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 92 | * scmi_to_linux_errno() - Convert an SCMI error code into a Linux errno code |
| 93 | * |
| 94 | * @scmi_errno: SCMI error code value |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 95 | * Return: 0 for successful status and a negative errno otherwise |
Etienne Carriere | 02fd126 | 2020-09-09 18:44:00 +0200 | [diff] [blame] | 96 | */ |
| 97 | int scmi_to_linux_errno(s32 scmi_errno); |
| 98 | |
| 99 | #endif /* SCMI_H */ |