k3-ringacc.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * K3 Ring Accelerator (RA) subsystem interface
  4. *
  5. * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com
  6. */
  7. #ifndef __SOC_TI_K3_RINGACC_API_H_
  8. #define __SOC_TI_K3_RINGACC_API_H_
  9. #include <linux/types.h>
  10. struct device_node;
  11. /**
  12. * enum k3_ring_mode - &struct k3_ring_cfg mode
  13. *
  14. * RA ring operational modes
  15. *
  16. * @K3_RINGACC_RING_MODE_RING: Exposed Ring mode for SW direct access
  17. * @K3_RINGACC_RING_MODE_MESSAGE: Messaging mode. Messaging mode requires
  18. * that all accesses to the queue must go through this IP so that all
  19. * accesses to the memory are controlled and ordered. This IP then
  20. * controls the entire state of the queue, and SW has no directly control,
  21. * such as through doorbells and cannot access the storage memory directly.
  22. * This is particularly useful when more than one SW or HW entity can be
  23. * the producer and/or consumer at the same time
  24. * @K3_RINGACC_RING_MODE_CREDENTIALS: Credentials mode is message mode plus
  25. * stores credentials with each message, requiring the element size to be
  26. * doubled to fit the credentials. Any exposed memory should be protected
  27. * by a firewall from unwanted access
  28. */
  29. enum k3_ring_mode {
  30. K3_RINGACC_RING_MODE_RING = 0,
  31. K3_RINGACC_RING_MODE_MESSAGE,
  32. K3_RINGACC_RING_MODE_CREDENTIALS,
  33. K3_RINGACC_RING_MODE_INVALID
  34. };
  35. /**
  36. * enum k3_ring_size - &struct k3_ring_cfg elm_size
  37. *
  38. * RA ring element's sizes in bytes.
  39. */
  40. enum k3_ring_size {
  41. K3_RINGACC_RING_ELSIZE_4 = 0,
  42. K3_RINGACC_RING_ELSIZE_8,
  43. K3_RINGACC_RING_ELSIZE_16,
  44. K3_RINGACC_RING_ELSIZE_32,
  45. K3_RINGACC_RING_ELSIZE_64,
  46. K3_RINGACC_RING_ELSIZE_128,
  47. K3_RINGACC_RING_ELSIZE_256,
  48. K3_RINGACC_RING_ELSIZE_INVALID
  49. };
  50. struct k3_ringacc;
  51. struct k3_ring;
  52. /**
  53. * enum k3_ring_cfg - RA ring configuration structure
  54. *
  55. * @size: Ring size, number of elements
  56. * @elm_size: Ring element size
  57. * @mode: Ring operational mode
  58. * @flags: Ring configuration flags. Possible values:
  59. * @K3_RINGACC_RING_SHARED: when set allows to request the same ring
  60. * few times. It's usable when the same ring is used as Free Host PD ring
  61. * for different flows, for example.
  62. * Note: Locking should be done by consumer if required
  63. * @dma_dev: Master device which is using and accessing to the ring
  64. * memory when the mode is K3_RINGACC_RING_MODE_RING. Memory allocations
  65. * should be done using this device.
  66. * @asel: Address Space Select value for physical addresses
  67. */
  68. struct k3_ring_cfg {
  69. u32 size;
  70. enum k3_ring_size elm_size;
  71. enum k3_ring_mode mode;
  72. #define K3_RINGACC_RING_SHARED BIT(1)
  73. u32 flags;
  74. struct device *dma_dev;
  75. u32 asel;
  76. };
  77. #define K3_RINGACC_RING_ID_ANY (-1)
  78. /**
  79. * of_k3_ringacc_get_by_phandle - find a RA by phandle property
  80. * @np: device node
  81. * @propname: property name containing phandle on RA node
  82. *
  83. * Returns pointer on the RA - struct k3_ringacc
  84. * or -ENODEV if not found,
  85. * or -EPROBE_DEFER if not yet registered
  86. */
  87. struct k3_ringacc *of_k3_ringacc_get_by_phandle(struct device_node *np,
  88. const char *property);
  89. #define K3_RINGACC_RING_USE_PROXY BIT(1)
  90. /**
  91. * k3_ringacc_request_ring - request ring from ringacc
  92. * @ringacc: pointer on ringacc
  93. * @id: ring id or K3_RINGACC_RING_ID_ANY for any general purpose ring
  94. * @flags:
  95. * @K3_RINGACC_RING_USE_PROXY: if set - proxy will be allocated and
  96. * used to access ring memory. Sopported only for rings in
  97. * Message/Credentials/Queue mode.
  98. *
  99. * Returns pointer on the Ring - struct k3_ring
  100. * or NULL in case of failure.
  101. */
  102. struct k3_ring *k3_ringacc_request_ring(struct k3_ringacc *ringacc,
  103. int id, u32 flags);
  104. int k3_ringacc_request_rings_pair(struct k3_ringacc *ringacc,
  105. int fwd_id, int compl_id,
  106. struct k3_ring **fwd_ring,
  107. struct k3_ring **compl_ring);
  108. /**
  109. * k3_ringacc_ring_reset - ring reset
  110. * @ring: pointer on Ring
  111. *
  112. * Resets ring internal state ((hw)occ, (hw)idx).
  113. */
  114. void k3_ringacc_ring_reset(struct k3_ring *ring);
  115. /**
  116. * k3_ringacc_ring_reset - ring reset for DMA rings
  117. * @ring: pointer on Ring
  118. *
  119. * Resets ring internal state ((hw)occ, (hw)idx). Should be used for rings
  120. * which are read by K3 UDMA, like TX or Free Host PD rings.
  121. */
  122. void k3_ringacc_ring_reset_dma(struct k3_ring *ring, u32 occ);
  123. /**
  124. * k3_ringacc_ring_free - ring free
  125. * @ring: pointer on Ring
  126. *
  127. * Resets ring and free all alocated resources.
  128. */
  129. int k3_ringacc_ring_free(struct k3_ring *ring);
  130. /**
  131. * k3_ringacc_get_ring_id - Get the Ring ID
  132. * @ring: pointer on ring
  133. *
  134. * Returns the Ring ID
  135. */
  136. u32 k3_ringacc_get_ring_id(struct k3_ring *ring);
  137. /**
  138. * k3_ringacc_get_ring_irq_num - Get the irq number for the ring
  139. * @ring: pointer on ring
  140. *
  141. * Returns the interrupt number which can be used to request the interrupt
  142. */
  143. int k3_ringacc_get_ring_irq_num(struct k3_ring *ring);
  144. /**
  145. * k3_ringacc_ring_cfg - ring configure
  146. * @ring: pointer on ring
  147. * @cfg: Ring configuration parameters (see &struct k3_ring_cfg)
  148. *
  149. * Configures ring, including ring memory allocation.
  150. * Returns 0 on success, errno otherwise.
  151. */
  152. int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg);
  153. /**
  154. * k3_ringacc_ring_get_size - get ring size
  155. * @ring: pointer on ring
  156. *
  157. * Returns ring size in number of elements.
  158. */
  159. u32 k3_ringacc_ring_get_size(struct k3_ring *ring);
  160. /**
  161. * k3_ringacc_ring_get_free - get free elements
  162. * @ring: pointer on ring
  163. *
  164. * Returns number of free elements in the ring.
  165. */
  166. u32 k3_ringacc_ring_get_free(struct k3_ring *ring);
  167. /**
  168. * k3_ringacc_ring_get_occ - get ring occupancy
  169. * @ring: pointer on ring
  170. *
  171. * Returns total number of valid entries on the ring
  172. */
  173. u32 k3_ringacc_ring_get_occ(struct k3_ring *ring);
  174. /**
  175. * k3_ringacc_ring_is_full - checks if ring is full
  176. * @ring: pointer on ring
  177. *
  178. * Returns true if the ring is full
  179. */
  180. u32 k3_ringacc_ring_is_full(struct k3_ring *ring);
  181. /**
  182. * k3_ringacc_ring_push - push element to the ring tail
  183. * @ring: pointer on ring
  184. * @elem: pointer on ring element buffer
  185. *
  186. * Push one ring element to the ring tail. Size of the ring element is
  187. * determined by ring configuration &struct k3_ring_cfg elm_size.
  188. *
  189. * Returns 0 on success, errno otherwise.
  190. */
  191. int k3_ringacc_ring_push(struct k3_ring *ring, void *elem);
  192. /**
  193. * k3_ringacc_ring_pop - pop element from the ring head
  194. * @ring: pointer on ring
  195. * @elem: pointer on ring element buffer
  196. *
  197. * Push one ring element from the ring head. Size of the ring element is
  198. * determined by ring configuration &struct k3_ring_cfg elm_size..
  199. *
  200. * Returns 0 on success, errno otherwise.
  201. */
  202. int k3_ringacc_ring_pop(struct k3_ring *ring, void *elem);
  203. /**
  204. * k3_ringacc_ring_push_head - push element to the ring head
  205. * @ring: pointer on ring
  206. * @elem: pointer on ring element buffer
  207. *
  208. * Push one ring element to the ring head. Size of the ring element is
  209. * determined by ring configuration &struct k3_ring_cfg elm_size.
  210. *
  211. * Returns 0 on success, errno otherwise.
  212. * Not Supported by ring modes: K3_RINGACC_RING_MODE_RING
  213. */
  214. int k3_ringacc_ring_push_head(struct k3_ring *ring, void *elem);
  215. /**
  216. * k3_ringacc_ring_pop_tail - pop element from the ring tail
  217. * @ring: pointer on ring
  218. * @elem: pointer on ring element buffer
  219. *
  220. * Push one ring element from the ring tail. Size of the ring element is
  221. * determined by ring configuration &struct k3_ring_cfg elm_size.
  222. *
  223. * Returns 0 on success, errno otherwise.
  224. * Not Supported by ring modes: K3_RINGACC_RING_MODE_RING
  225. */
  226. int k3_ringacc_ring_pop_tail(struct k3_ring *ring, void *elem);
  227. u32 k3_ringacc_get_tisci_dev_id(struct k3_ring *ring);
  228. /* DMA ring support */
  229. struct ti_sci_handle;
  230. /**
  231. * struct struct k3_ringacc_init_data - Initialization data for DMA rings
  232. */
  233. struct k3_ringacc_init_data {
  234. const struct ti_sci_handle *tisci;
  235. u32 tisci_dev_id;
  236. u32 num_rings;
  237. };
  238. struct k3_ringacc *k3_ringacc_dmarings_init(struct platform_device *pdev,
  239. struct k3_ringacc_init_data *data);
  240. #endif /* __SOC_TI_K3_RINGACC_API_H_ */