ivc.h 5.7 KB

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