2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
7 #ifndef _ASM_ARCH_TEGRA_IVC_H
8 #define _ASM_ARCH_TEGRA_IVC_H
13 * Tegra IVC is a communication protocol that transfers fixed-size frames
14 * bi-directionally and in-order between the local CPU and some remote entity.
15 * Communication is via a statically sized and allocated buffer in shared
16 * memory and a notification mechanism.
18 * This API handles all aspects of the shared memory buffer's metadata, and
19 * leaves all aspects of the frame content to the calling code; frames
20 * typically contain some higher-level protocol. The notification mechanism is
21 * also handled externally to this API, since it can vary from instance to
24 * The client model is to first find some free (for TX) or filled (for RX)
25 * frame, process that frame's memory buffer (fill or read it), and then
26 * inform the protocol that the frame has been filled/read, i.e. advance the
27 * write/read pointer. If the channel is full, there may be no available frames
28 * to fill/read. In this case, client code may either poll for an available
29 * frame, or wait for the remote entity to send a notification to the local
34 * struct tegra_ivc - In-memory shared memory layout.
36 * This is described in detail in ivc.c.
38 struct tegra_ivc_channel_header;
41 * struct tegra_ivc - Software state of an IVC channel.
43 * This state is internal to the IVC code and should not be accessed directly
44 * by clients. It is public solely so clients can allocate storage for the
49 * rx_channel - Pointer to the shared memory region used to receive
50 * messages from the remote entity.
52 struct tegra_ivc_channel_header *rx_channel;
54 * tx_channel - Pointer to the shared memory region used to send
55 * messages to the remote entity.
57 struct tegra_ivc_channel_header *tx_channel;
59 * r_pos - The position in list of frames in rx_channel that we are
64 * w_pos - The position in list of frames in tx_channel that we are
69 * nframes - The number of frames allocated (in each direction) in
74 * frame_size - The size of each frame in shared memory.
78 * notify - Function to call to notify the remote processor of a
79 * change in channel state.
81 void (*notify)(struct tegra_ivc *);
85 * tegra_ivc_read_get_next_frame - Locate the next frame to receive.
87 * Locate the next frame to be received/processed, return the address of the
88 * frame, and do not remove it from the queue. Repeated calls to this function
89 * will return the same address until tegra_ivc_read_advance() is called.
91 * @ivc The IVC channel.
92 * @frame Pointer to be filled with the address of the frame to receive.
94 * @return 0 if a frame is available, else a negative error code.
96 int tegra_ivc_read_get_next_frame(struct tegra_ivc *ivc, void **frame);
99 * tegra_ivc_read_advance - Advance the read queue.
101 * Inform the protocol and remote entity that the frame returned by
102 * tegra_ivc_read_get_next_frame() has been processed. The remote end may then
103 * re-use it to transmit further data. Subsequent to this function returning,
104 * tegra_ivc_read_get_next_frame() will return a different frame.
106 * @ivc The IVC channel.
108 * @return 0 if OK, else a negative error code.
110 int tegra_ivc_read_advance(struct tegra_ivc *ivc);
113 * tegra_ivc_write_get_next_frame - Locate the next frame to fill for transmit.
115 * Locate the next frame to be filled for transmit, return the address of the
116 * frame, and do not add it to the queue. Repeated calls to this function
117 * will return the same address until tegra_ivc_read_advance() is called.
119 * @ivc The IVC channel.
120 * @frame Pointer to be filled with the address of the frame to fill.
122 * @return 0 if a frame is available, else a negative error code.
124 int tegra_ivc_write_get_next_frame(struct tegra_ivc *ivc, void **frame);
127 * tegra_ivc_write_advance - Advance the write queue.
129 * Inform the protocol and remote entity that the frame returned by
130 * tegra_ivc_write_get_next_frame() has been filled and should be transmitted.
131 * The remote end may then read data from it. Subsequent to this function
132 * returning, tegra_ivc_write_get_next_frame() will return a different frame.
134 * @ivc The IVC channel.
136 * @return 0 if OK, else a negative error code.
138 int tegra_ivc_write_advance(struct tegra_ivc *ivc);
141 * tegra_ivc_channel_notified - handle internal messages
143 * This function must be called following every notification.
145 * @ivc The IVC channel.
147 * @return 0 if the channel is ready for communication, or -EAGAIN if a
148 * channel reset is in progress.
150 int tegra_ivc_channel_notified(struct tegra_ivc *ivc);
153 * tegra_ivc_channel_reset - initiates a reset of the shared memory state
155 * This function must be called after a channel is initialized but before it
156 * is used for communication. The channel will be ready for use when a
157 * subsequent call to notify the remote of the channel reset indicates the
158 * reset operation is complete.
160 * @ivc The IVC channel.
162 void tegra_ivc_channel_reset(struct tegra_ivc *ivc);
165 * tegra_ivc_init - Initialize a channel's software state.
167 * @ivc The IVC channel.
168 * @rx_base Address of the the RX shared memory buffer.
169 * @tx_base Address of the the TX shared memory buffer.
170 * @nframes Number of frames in each shared memory buffer.
171 * @frame_size Size of each frame.
173 * @return 0 if OK, else a negative error code.
175 int tegra_ivc_init(struct tegra_ivc *ivc, ulong rx_base, ulong tx_base,
176 uint32_t nframes, uint32_t frame_size,
177 void (*notify)(struct tegra_ivc *));