xref: /OK3568_Linux_fs/u-boot/include/mailbox-uclass.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2016, NVIDIA CORPORATION.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier: GPL-2.0
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _MAILBOX_UCLASS_H
8*4882a593Smuzhiyun #define _MAILBOX_UCLASS_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /* See mailbox.h for background documentation. */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <mailbox.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct udevice;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /**
17*4882a593Smuzhiyun  * struct mbox_ops - The functions that a mailbox driver must implement.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun struct mbox_ops {
20*4882a593Smuzhiyun 	/**
21*4882a593Smuzhiyun 	 * of_xlate - Translate a client's device-tree (OF) mailbox specifier.
22*4882a593Smuzhiyun 	 *
23*4882a593Smuzhiyun 	 * The mailbox core calls this function as the first step in
24*4882a593Smuzhiyun 	 * implementing a client's mbox_get_by_*() call.
25*4882a593Smuzhiyun 	 *
26*4882a593Smuzhiyun 	 * If this function pointer is set to NULL, the mailbox core will use
27*4882a593Smuzhiyun 	 * a default implementation, which assumes #mbox-cells = <1>, and that
28*4882a593Smuzhiyun 	 * the DT cell contains a simple integer channel ID.
29*4882a593Smuzhiyun 	 *
30*4882a593Smuzhiyun 	 * At present, the mailbox API solely supports device-tree. If this
31*4882a593Smuzhiyun 	 * changes, other xxx_xlate() functions may be added to support those
32*4882a593Smuzhiyun 	 * other mechanisms.
33*4882a593Smuzhiyun 	 *
34*4882a593Smuzhiyun 	 * @chan:	The channel to hold the translation result.
35*4882a593Smuzhiyun 	 * @args:	The mailbox specifier values from device tree.
36*4882a593Smuzhiyun 	 * @return 0 if OK, or a negative error code.
37*4882a593Smuzhiyun 	 */
38*4882a593Smuzhiyun 	int (*of_xlate)(struct mbox_chan *chan,
39*4882a593Smuzhiyun 			struct ofnode_phandle_args *args);
40*4882a593Smuzhiyun 	/**
41*4882a593Smuzhiyun 	 * request - Request a translated channel.
42*4882a593Smuzhiyun 	 *
43*4882a593Smuzhiyun 	 * The mailbox core calls this function as the second step in
44*4882a593Smuzhiyun 	 * implementing a client's mbox_get_by_*() call, following a successful
45*4882a593Smuzhiyun 	 * xxx_xlate() call.
46*4882a593Smuzhiyun 	 *
47*4882a593Smuzhiyun 	 * @chan:	The channel to request; this has been filled in by a
48*4882a593Smuzhiyun 	 *		previoux xxx_xlate() function call.
49*4882a593Smuzhiyun 	 * @return 0 if OK, or a negative error code.
50*4882a593Smuzhiyun 	 */
51*4882a593Smuzhiyun 	int (*request)(struct mbox_chan *chan);
52*4882a593Smuzhiyun 	/**
53*4882a593Smuzhiyun 	 * free - Free a previously requested channel.
54*4882a593Smuzhiyun 	 *
55*4882a593Smuzhiyun 	 * This is the implementation of the client mbox_free() API.
56*4882a593Smuzhiyun 	 *
57*4882a593Smuzhiyun 	 * @chan:	The channel to free.
58*4882a593Smuzhiyun 	 * @return 0 if OK, or a negative error code.
59*4882a593Smuzhiyun 	 */
60*4882a593Smuzhiyun 	int (*free)(struct mbox_chan *chan);
61*4882a593Smuzhiyun 	/**
62*4882a593Smuzhiyun 	* send - Send a message over a mailbox channel
63*4882a593Smuzhiyun 	*
64*4882a593Smuzhiyun 	* @chan:	The channel to send to the message to.
65*4882a593Smuzhiyun 	* @data:	A pointer to the message to send.
66*4882a593Smuzhiyun 	* @return 0 if OK, or a negative error code.
67*4882a593Smuzhiyun 	*/
68*4882a593Smuzhiyun 	int (*send)(struct mbox_chan *chan, const void *data);
69*4882a593Smuzhiyun 	/**
70*4882a593Smuzhiyun 	* recv - Receive any available message from the channel.
71*4882a593Smuzhiyun 	*
72*4882a593Smuzhiyun 	* This function does not block. If not message is immediately
73*4882a593Smuzhiyun 	* available, the function should return an error.
74*4882a593Smuzhiyun 	*
75*4882a593Smuzhiyun 	* @chan:	The channel to receive to the message from.
76*4882a593Smuzhiyun 	* @data:	A pointer to the buffer to hold the received message.
77*4882a593Smuzhiyun 	* @return 0 if OK, -ENODATA if no message was available, or a negative
78*4882a593Smuzhiyun 	* error code.
79*4882a593Smuzhiyun 	*/
80*4882a593Smuzhiyun 	int (*recv)(struct mbox_chan *chan, void *data);
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #endif
84