xref: /rk3399_rockchip-uboot/arch/arm/include/asm/arch-tegra/ivc.h (revision 9f84da8de1873593d9b708aa4a8a24f46e67c744)
1*49626ea8SStephen Warren /*
2*49626ea8SStephen Warren  * Copyright (c) 2016, NVIDIA CORPORATION.
3*49626ea8SStephen Warren  *
4*49626ea8SStephen Warren  * SPDX-License-Identifier: GPL-2.0
5*49626ea8SStephen Warren  */
6*49626ea8SStephen Warren 
7*49626ea8SStephen Warren #ifndef _ASM_ARCH_TEGRA_IVC_H
8*49626ea8SStephen Warren #define _ASM_ARCH_TEGRA_IVC_H
9*49626ea8SStephen Warren 
10*49626ea8SStephen Warren #include <common.h>
11*49626ea8SStephen Warren 
12*49626ea8SStephen Warren /*
13*49626ea8SStephen Warren  * Tegra IVC is a communication protocol that transfers fixed-size frames
14*49626ea8SStephen Warren  * bi-directionally and in-order between the local CPU and some remote entity.
15*49626ea8SStephen Warren  * Communication is via a statically sized and allocated buffer in shared
16*49626ea8SStephen Warren  * memory and a notification mechanism.
17*49626ea8SStephen Warren  *
18*49626ea8SStephen Warren  * This API handles all aspects of the shared memory buffer's metadata, and
19*49626ea8SStephen Warren  * leaves all aspects of the frame content to the calling code; frames
20*49626ea8SStephen Warren  * typically contain some higher-level protocol. The notification mechanism is
21*49626ea8SStephen Warren  * also handled externally to this API, since it can vary from instance to
22*49626ea8SStephen Warren  * instance.
23*49626ea8SStephen Warren  *
24*49626ea8SStephen Warren  * The client model is to first find some free (for TX) or filled (for RX)
25*49626ea8SStephen Warren  * frame, process that frame's memory buffer (fill or read it), and then
26*49626ea8SStephen Warren  * inform the protocol that the frame has been filled/read, i.e. advance the
27*49626ea8SStephen Warren  * write/read pointer. If the channel is full, there may be no available frames
28*49626ea8SStephen Warren  * to fill/read. In this case, client code may either poll for an available
29*49626ea8SStephen Warren  * frame, or wait for the remote entity to send a notification to the local
30*49626ea8SStephen Warren  * CPU.
31*49626ea8SStephen Warren  */
32*49626ea8SStephen Warren 
33*49626ea8SStephen Warren /**
34*49626ea8SStephen Warren  * struct tegra_ivc - In-memory shared memory layout.
35*49626ea8SStephen Warren  *
36*49626ea8SStephen Warren  * This is described in detail in ivc.c.
37*49626ea8SStephen Warren  */
38*49626ea8SStephen Warren struct tegra_ivc_channel_header;
39*49626ea8SStephen Warren 
40*49626ea8SStephen Warren /**
41*49626ea8SStephen Warren  * struct tegra_ivc - Software state of an IVC channel.
42*49626ea8SStephen Warren  *
43*49626ea8SStephen Warren  * This state is internal to the IVC code and should not be accessed directly
44*49626ea8SStephen Warren  * by clients. It is public solely so clients can allocate storage for the
45*49626ea8SStephen Warren  * structure.
46*49626ea8SStephen Warren  */
47*49626ea8SStephen Warren struct tegra_ivc {
48*49626ea8SStephen Warren 	/**
49*49626ea8SStephen Warren 	 * rx_channel - Pointer to the shared memory region used to receive
50*49626ea8SStephen Warren 	 * messages from the remote entity.
51*49626ea8SStephen Warren 	 */
52*49626ea8SStephen Warren 	struct tegra_ivc_channel_header *rx_channel;
53*49626ea8SStephen Warren 	/**
54*49626ea8SStephen Warren 	 * tx_channel - Pointer to the shared memory region used to send
55*49626ea8SStephen Warren 	 * messages to the remote entity.
56*49626ea8SStephen Warren 	 */
57*49626ea8SStephen Warren 	struct tegra_ivc_channel_header *tx_channel;
58*49626ea8SStephen Warren 	/**
59*49626ea8SStephen Warren 	 * r_pos - The position in list of frames in rx_channel that we are
60*49626ea8SStephen Warren 	 * reading from.
61*49626ea8SStephen Warren 	 */
62*49626ea8SStephen Warren 	uint32_t r_pos;
63*49626ea8SStephen Warren 	/**
64*49626ea8SStephen Warren 	 * w_pos - The position in list of frames in tx_channel that we are
65*49626ea8SStephen Warren 	 * writing to.
66*49626ea8SStephen Warren 	 */
67*49626ea8SStephen Warren 	uint32_t w_pos;
68*49626ea8SStephen Warren 	/**
69*49626ea8SStephen Warren 	 * nframes - The number of frames allocated (in each direction) in
70*49626ea8SStephen Warren 	 * shared memory.
71*49626ea8SStephen Warren 	 */
72*49626ea8SStephen Warren 	uint32_t nframes;
73*49626ea8SStephen Warren 	/**
74*49626ea8SStephen Warren 	 * frame_size - The size of each frame in shared memory.
75*49626ea8SStephen Warren 	 */
76*49626ea8SStephen Warren 	uint32_t frame_size;
77*49626ea8SStephen Warren 	/**
78*49626ea8SStephen Warren 	 * notify - Function to call to notify the remote processor of a
79*49626ea8SStephen Warren 	 * change in channel state.
80*49626ea8SStephen Warren 	 */
81*49626ea8SStephen Warren 	void (*notify)(struct tegra_ivc *);
82*49626ea8SStephen Warren };
83*49626ea8SStephen Warren 
84*49626ea8SStephen Warren /**
85*49626ea8SStephen Warren  * tegra_ivc_read_get_next_frame - Locate the next frame to receive.
86*49626ea8SStephen Warren  *
87*49626ea8SStephen Warren  * Locate the next frame to be received/processed, return the address of the
88*49626ea8SStephen Warren  * frame, and do not remove it from the queue. Repeated calls to this function
89*49626ea8SStephen Warren  * will return the same address until tegra_ivc_read_advance() is called.
90*49626ea8SStephen Warren  *
91*49626ea8SStephen Warren  * @ivc		The IVC channel.
92*49626ea8SStephen Warren  * @frame	Pointer to be filled with the address of the frame to receive.
93*49626ea8SStephen Warren  *
94*49626ea8SStephen Warren  * @return 0 if a frame is available, else a negative error code.
95*49626ea8SStephen Warren  */
96*49626ea8SStephen Warren int tegra_ivc_read_get_next_frame(struct tegra_ivc *ivc, void **frame);
97*49626ea8SStephen Warren 
98*49626ea8SStephen Warren /**
99*49626ea8SStephen Warren  * tegra_ivc_read_advance - Advance the read queue.
100*49626ea8SStephen Warren  *
101*49626ea8SStephen Warren  * Inform the protocol and remote entity that the frame returned by
102*49626ea8SStephen Warren  * tegra_ivc_read_get_next_frame() has been processed. The remote end may then
103*49626ea8SStephen Warren  * re-use it to transmit further data. Subsequent to this function returning,
104*49626ea8SStephen Warren  * tegra_ivc_read_get_next_frame() will return a different frame.
105*49626ea8SStephen Warren  *
106*49626ea8SStephen Warren  * @ivc		The IVC channel.
107*49626ea8SStephen Warren  *
108*49626ea8SStephen Warren  * @return 0 if OK, else a negative error code.
109*49626ea8SStephen Warren  */
110*49626ea8SStephen Warren int tegra_ivc_read_advance(struct tegra_ivc *ivc);
111*49626ea8SStephen Warren 
112*49626ea8SStephen Warren /**
113*49626ea8SStephen Warren  * tegra_ivc_write_get_next_frame - Locate the next frame to fill for transmit.
114*49626ea8SStephen Warren  *
115*49626ea8SStephen Warren  * Locate the next frame to be filled for transmit, return the address of the
116*49626ea8SStephen Warren  * frame, and do not add it to the queue. Repeated calls to this function
117*49626ea8SStephen Warren  * will return the same address until tegra_ivc_read_advance() is called.
118*49626ea8SStephen Warren  *
119*49626ea8SStephen Warren  * @ivc		The IVC channel.
120*49626ea8SStephen Warren  * @frame	Pointer to be filled with the address of the frame to fill.
121*49626ea8SStephen Warren  *
122*49626ea8SStephen Warren  * @return 0 if a frame is available, else a negative error code.
123*49626ea8SStephen Warren  */
124*49626ea8SStephen Warren int tegra_ivc_write_get_next_frame(struct tegra_ivc *ivc, void **frame);
125*49626ea8SStephen Warren 
126*49626ea8SStephen Warren /**
127*49626ea8SStephen Warren  * tegra_ivc_write_advance - Advance the write queue.
128*49626ea8SStephen Warren  *
129*49626ea8SStephen Warren  * Inform the protocol and remote entity that the frame returned by
130*49626ea8SStephen Warren  * tegra_ivc_write_get_next_frame() has been filled and should be transmitted.
131*49626ea8SStephen Warren  * The remote end may then read data from it. Subsequent to this function
132*49626ea8SStephen Warren  * returning, tegra_ivc_write_get_next_frame() will return a different frame.
133*49626ea8SStephen Warren  *
134*49626ea8SStephen Warren  * @ivc		The IVC channel.
135*49626ea8SStephen Warren  *
136*49626ea8SStephen Warren  * @return 0 if OK, else a negative error code.
137*49626ea8SStephen Warren  */
138*49626ea8SStephen Warren int tegra_ivc_write_advance(struct tegra_ivc *ivc);
139*49626ea8SStephen Warren 
140*49626ea8SStephen Warren /**
141*49626ea8SStephen Warren  * tegra_ivc_channel_notified - handle internal messages
142*49626ea8SStephen Warren  *
143*49626ea8SStephen Warren  * This function must be called following every notification.
144*49626ea8SStephen Warren  *
145*49626ea8SStephen Warren  * @ivc		The IVC channel.
146*49626ea8SStephen Warren  *
147*49626ea8SStephen Warren  * @return 0 if the channel is ready for communication, or -EAGAIN if a
148*49626ea8SStephen Warren  * channel reset is in progress.
149*49626ea8SStephen Warren  */
150*49626ea8SStephen Warren int tegra_ivc_channel_notified(struct tegra_ivc *ivc);
151*49626ea8SStephen Warren 
152*49626ea8SStephen Warren /**
153*49626ea8SStephen Warren  * tegra_ivc_channel_reset - initiates a reset of the shared memory state
154*49626ea8SStephen Warren  *
155*49626ea8SStephen Warren  * This function must be called after a channel is initialized but before it
156*49626ea8SStephen Warren  * is used for communication. The channel will be ready for use when a
157*49626ea8SStephen Warren  * subsequent call to notify the remote of the channel reset indicates the
158*49626ea8SStephen Warren  * reset operation is complete.
159*49626ea8SStephen Warren  *
160*49626ea8SStephen Warren  * @ivc		The IVC channel.
161*49626ea8SStephen Warren  */
162*49626ea8SStephen Warren void tegra_ivc_channel_reset(struct tegra_ivc *ivc);
163*49626ea8SStephen Warren 
164*49626ea8SStephen Warren /**
165*49626ea8SStephen Warren  * tegra_ivc_init - Initialize a channel's software state.
166*49626ea8SStephen Warren  *
167*49626ea8SStephen Warren  * @ivc		The IVC channel.
168*49626ea8SStephen Warren  * @rx_base	Address of the the RX shared memory buffer.
169*49626ea8SStephen Warren  * @tx_base	Address of the the TX shared memory buffer.
170*49626ea8SStephen Warren  * @nframes	Number of frames in each shared memory buffer.
171*49626ea8SStephen Warren  * @frame_size	Size of each frame.
172*49626ea8SStephen Warren  *
173*49626ea8SStephen Warren  * @return 0 if OK, else a negative error code.
174*49626ea8SStephen Warren  */
175*49626ea8SStephen Warren int tegra_ivc_init(struct tegra_ivc *ivc, ulong rx_base, ulong tx_base,
176*49626ea8SStephen Warren 		   uint32_t nframes, uint32_t frame_size,
177*49626ea8SStephen Warren 		   void (*notify)(struct tegra_ivc *));
178*49626ea8SStephen Warren 
179*49626ea8SStephen Warren #endif
180