ivc.h 5.7 KB

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