Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Stephen Warren | 769d52e | 2016-06-17 09:43:56 -0600 | [diff] [blame] | 6 | #ifndef _MAILBOX_H |
| 7 | #define _MAILBOX_H |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 8 | |
Tom Rini | 03de305 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 11 | /** |
| 12 | * A mailbox is a hardware mechanism for transferring small fixed-size messages |
| 13 | * and/or notifications between the CPU on which U-Boot runs and some other |
| 14 | * device such as an auxiliary CPU running firmware or a hardware module. |
| 15 | * |
| 16 | * Data transfer is optional; a mailbox may consist solely of a notification |
| 17 | * mechanism. When data transfer is implemented, it is via HW registers or |
| 18 | * FIFOs, rather than via RAM-based buffers. The mailbox API generally |
| 19 | * implements any communication protocol enforced solely by hardware, and |
| 20 | * leaves any higher-level protocols to other layers. |
| 21 | * |
| 22 | * A mailbox channel is a bi-directional mechanism that can send a message or |
| 23 | * notification to a single specific remote entity, and receive messages or |
| 24 | * notifications from that entity. The size, content, and format of such |
| 25 | * messages is defined by the mailbox implementation, or the remote entity with |
| 26 | * which it communicates; there is no general standard at this API level. |
| 27 | * |
| 28 | * A driver that implements UCLASS_MAILBOX is a mailbox provider. A provider |
| 29 | * will often implement multiple separate mailbox channels, since the hardware |
Stephen Warren | 769d52e | 2016-06-17 09:43:56 -0600 | [diff] [blame] | 30 | * it manages often has this capability. mailbox-uclass.h describes the |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 31 | * interface which mailbox providers must implement. |
| 32 | * |
| 33 | * Mailbox consumers/clients generate and send, or receive and process, |
| 34 | * messages. This header file describes the API used by clients. |
| 35 | */ |
| 36 | |
| 37 | struct udevice; |
| 38 | |
| 39 | /** |
| 40 | * struct mbox_chan - A handle to a single mailbox channel. |
| 41 | * |
| 42 | * Clients provide storage for channels. The content of the channel structure |
| 43 | * is managed solely by the mailbox API and mailbox drivers. A mailbox channel |
| 44 | * is initialized by "get"ing the mailbox. The channel struct is passed to all |
| 45 | * other mailbox APIs to identify which mailbox to operate upon. |
| 46 | * |
| 47 | * @dev: The device which implements the mailbox. |
| 48 | * @id: The mailbox channel ID within the provider. |
Lokesh Vutla | 600e46b | 2018-08-27 15:57:47 +0530 | [diff] [blame] | 49 | * @con_priv: Hook for controller driver to attach private data |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 50 | * |
| 51 | * Currently, the mailbox API assumes that a single integer ID is enough to |
| 52 | * identify and configure any mailbox channel for any mailbox provider. If this |
| 53 | * assumption becomes invalid in the future, the struct could be expanded to |
| 54 | * either (a) add more fields to allow mailbox providers to store additional |
| 55 | * information, or (b) replace the id field with an opaque pointer, which the |
| 56 | * provider would dynamically allocated during its .of_xlate op, and process |
| 57 | * during is .request op. This may require the addition of an extra op to clean |
| 58 | * up the allocation. |
| 59 | */ |
| 60 | struct mbox_chan { |
| 61 | struct udevice *dev; |
Lokesh Vutla | 600e46b | 2018-08-27 15:57:47 +0530 | [diff] [blame] | 62 | /* Written by of_xlate.*/ |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 63 | unsigned long id; |
Lokesh Vutla | 600e46b | 2018-08-27 15:57:47 +0530 | [diff] [blame] | 64 | void *con_priv; |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
| 68 | * mbox_get_by_index - Get/request a mailbox by integer index |
| 69 | * |
| 70 | * This looks up and requests a mailbox channel. The index is relative to the |
| 71 | * client device; each device is assumed to have n mailbox channels associated |
| 72 | * with it somehow, and this function finds and requests one of them. The |
| 73 | * mapping of client device channel indices to provider channels may be via |
| 74 | * device-tree properties, board-provided mapping tables, or some other |
| 75 | * mechanism. |
| 76 | * |
| 77 | * @dev: The client device. |
| 78 | * @index: The index of the mailbox channel to request, within the |
| 79 | * client's list of channels. |
| 80 | * @chan A pointer to a channel object to initialize. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 81 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 82 | */ |
| 83 | int mbox_get_by_index(struct udevice *dev, int index, struct mbox_chan *chan); |
| 84 | |
| 85 | /** |
| 86 | * mbox_get_by_name - Get/request a mailbox by name |
| 87 | * |
| 88 | * This looks up and requests a mailbox channel. The name is relative to the |
| 89 | * client device; each device is assumed to have n mailbox channels associated |
| 90 | * with it somehow, and this function finds and requests one of them. The |
| 91 | * mapping of client device channel names to provider channels may be via |
| 92 | * device-tree properties, board-provided mapping tables, or some other |
| 93 | * mechanism. |
| 94 | * |
| 95 | * @dev: The client device. |
| 96 | * @name: The name of the mailbox channel to request, within the client's |
| 97 | * list of channels. |
| 98 | * @chan A pointer to a channel object to initialize. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 99 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 100 | */ |
| 101 | int mbox_get_by_name(struct udevice *dev, const char *name, |
| 102 | struct mbox_chan *chan); |
| 103 | |
| 104 | /** |
| 105 | * mbox_free - Free a previously requested mailbox channel. |
| 106 | * |
| 107 | * @chan: A channel object that was previously successfully requested by |
| 108 | * calling mbox_get_by_*(). |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 109 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 110 | */ |
| 111 | int mbox_free(struct mbox_chan *chan); |
| 112 | |
| 113 | /** |
| 114 | * mbox_send - Send a message over a mailbox channel |
| 115 | * |
| 116 | * This function will send a message to the remote entity. It may return before |
| 117 | * the remote entity has received and/or processed the message. |
| 118 | * |
| 119 | * @chan: A channel object that was previously successfully requested by |
| 120 | * calling mbox_get_by_*(). |
| 121 | * @data: A pointer to the message to transfer. The format and size of |
| 122 | * the memory region pointed at by @data is determined by the |
| 123 | * mailbox provider. Providers that solely transfer notifications |
| 124 | * will ignore this parameter. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 125 | * Return: 0 if OK, or a negative error code. |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 126 | */ |
| 127 | int mbox_send(struct mbox_chan *chan, const void *data); |
| 128 | |
| 129 | /** |
| 130 | * mbox_recv - Receive any available message from a mailbox channel |
| 131 | * |
| 132 | * This function will wait (up to the specified @timeout_us) for a message to |
| 133 | * be sent by the remote entity, and write the content of any such message |
| 134 | * into a caller-provided buffer. |
| 135 | * |
| 136 | * @chan: A channel object that was previously successfully requested by |
| 137 | * calling mbox_get_by_*(). |
| 138 | * @data: A pointer to the buffer to receive the message. The format and |
| 139 | * size of the memory region pointed at by @data is determined by |
| 140 | * the mailbox provider. Providers that solely transfer |
| 141 | * notifications will ignore this parameter. |
| 142 | * @timeout_us: The maximum time to wait for a message to be available, in |
| 143 | * micro-seconds. A value of 0 does not wait at all. |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 144 | * Return: 0 if OK, -ENODATA if no message was available, or a negative error |
Stephen Warren | 6238935 | 2016-05-13 15:50:29 -0600 | [diff] [blame] | 145 | * code. |
| 146 | */ |
| 147 | int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us); |
| 148 | |
| 149 | #endif |