blob: e70266fb61c9455b68c2e32f248631878cf55e1c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warren62389352016-05-13 15:50:29 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren62389352016-05-13 15:50:29 -06004 */
5
Stephen Warren769d52e2016-06-17 09:43:56 -06006#ifndef _MAILBOX_H
7#define _MAILBOX_H
Stephen Warren62389352016-05-13 15:50:29 -06008
Tom Rini675dd312024-04-30 07:35:28 -06009#include <linux/types.h>
10
Stephen Warren62389352016-05-13 15:50:29 -060011/**
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 Warren769d52e2016-06-17 09:43:56 -060030 * it manages often has this capability. mailbox-uclass.h describes the
Stephen Warren62389352016-05-13 15:50:29 -060031 * 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
37struct 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 Vutla600e46b2018-08-27 15:57:47 +053049 * @con_priv: Hook for controller driver to attach private data
Stephen Warren62389352016-05-13 15:50:29 -060050 *
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 */
60struct mbox_chan {
61 struct udevice *dev;
Lokesh Vutla600e46b2018-08-27 15:57:47 +053062 /* Written by of_xlate.*/
Stephen Warren62389352016-05-13 15:50:29 -060063 unsigned long id;
Lokesh Vutla600e46b2018-08-27 15:57:47 +053064 void *con_priv;
Stephen Warren62389352016-05-13 15:50:29 -060065};
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 Schuchardt185f8122022-01-19 18:05:50 +010081 * Return: 0 if OK, or a negative error code.
Stephen Warren62389352016-05-13 15:50:29 -060082 */
83int 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 Schuchardt185f8122022-01-19 18:05:50 +010099 * Return: 0 if OK, or a negative error code.
Stephen Warren62389352016-05-13 15:50:29 -0600100 */
101int 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 Schuchardt185f8122022-01-19 18:05:50 +0100109 * Return: 0 if OK, or a negative error code.
Stephen Warren62389352016-05-13 15:50:29 -0600110 */
111int 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 Schuchardt185f8122022-01-19 18:05:50 +0100125 * Return: 0 if OK, or a negative error code.
Stephen Warren62389352016-05-13 15:50:29 -0600126 */
127int 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 Schuchardt185f8122022-01-19 18:05:50 +0100144 * Return: 0 if OK, -ENODATA if no message was available, or a negative error
Stephen Warren62389352016-05-13 15:50:29 -0600145 * code.
146 */
147int mbox_recv(struct mbox_chan *chan, void *data, ulong timeout_us);
148
149#endif