2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
11 * A mailbox is a hardware mechanism for transferring small fixed-size messages
12 * and/or notifications between the CPU on which U-Boot runs and some other
13 * device such as an auxiliary CPU running firmware or a hardware module.
15 * Data transfer is optional; a mailbox may consist solely of a notification
16 * mechanism. When data transfer is implemented, it is via HW registers or
17 * FIFOs, rather than via RAM-based buffers. The mailbox API generally
18 * implements any communication protocol enforced solely by hardware, and
19 * leaves any higher-level protocols to other layers.
21 * A mailbox channel is a bi-directional mechanism that can send a message or
22 * notification to a single specific remote entity, and receive messages or
23 * notifications from that entity. The size, content, and format of such
24 * messages is defined by the mailbox implementation, or the remote entity with
25 * which it communicates; there is no general standard at this API level.
27 * A driver that implements UCLASS_MAILBOX is a mailbox provider. A provider
28 * will often implement multiple separate mailbox channels, since the hardware
29 * it manages often has this capability. mailbox-uclass.h describes the
30 * interface which mailbox providers must implement.
32 * Mailbox consumers/clients generate and send, or receive and process,
33 * messages. This header file describes the API used by clients.
39 * struct mbox_chan - A handle to a single mailbox channel.
41 * Clients provide storage for channels. The content of the channel structure
42 * is managed solely by the mailbox API and mailbox drivers. A mailbox channel
43 * is initialized by "get"ing the mailbox. The channel struct is passed to all
44 * other mailbox APIs to identify which mailbox to operate upon.
46 * @dev: The device which implements the mailbox.
47 * @id: The mailbox channel ID within the provider.
49 * Currently, the mailbox API assumes that a single integer ID is enough to
50 * identify and configure any mailbox channel for any mailbox provider. If this
51 * assumption becomes invalid in the future, the struct could be expanded to
52 * either (a) add more fields to allow mailbox providers to store additional
53 * information, or (b) replace the id field with an opaque pointer, which the
54 * provider would dynamically allocated during its .of_xlate op, and process
55 * during is .request op. This may require the addition of an extra op to clean
61 * Written by of_xlate. We assume a single id is enough for now. In the
62 * future, we might add more fields here.
68 * mbox_get_by_index - Get/request a mailbox by integer index
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
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.
81 * @return 0 if OK, or a negative error code.
83 int mbox_get_by_index(struct udevice *dev, int index, struct mbox_chan *chan);
86 * mbox_get_by_name - Get/request a mailbox by name
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
95 * @dev: The client device.
96 * @name: The name of the mailbox channel to request, within the client's
98 * @chan A pointer to a channel object to initialize.
99 * @return 0 if OK, or a negative error code.
101 int mbox_get_by_name(struct udevice *dev, const char *name,
102 struct mbox_chan *chan);
105 * mbox_free - Free a previously requested mailbox channel.
107 * @chan: A channel object that was previously successfully requested by
108 * calling mbox_get_by_*().
109 * @return 0 if OK, or a negative error code.
111 int mbox_free(struct mbox_chan *chan);
114 * mbox_send - Send a message over a mailbox channel
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.
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.
125 * @return 0 if OK, or a negative error code.
127 int mbox_send(struct mbox_chan *chan, const void *data);
130 * mbox_recv - Receive any available message from a mailbox channel
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.
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.
144 * @return 0 if OK, -ENODATA if no message was available, or a negative error
147 int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us);