mtk-cmdq.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2018 MediaTek Inc.
  4. *
  5. */
  6. #ifndef __MTK_CMDQ_H__
  7. #define __MTK_CMDQ_H__
  8. #include <linux/mailbox_client.h>
  9. #include <linux/mailbox/mtk-cmdq-mailbox.h>
  10. #include <linux/timer.h>
  11. #define CMDQ_ADDR_HIGH(addr) ((u32)(((addr) >> 16) & GENMASK(31, 0)))
  12. #define CMDQ_ADDR_LOW(addr) ((u16)(addr) | BIT(1))
  13. struct cmdq_pkt;
  14. struct cmdq_client_reg {
  15. u8 subsys;
  16. u16 offset;
  17. u16 size;
  18. };
  19. struct cmdq_client {
  20. struct mbox_client client;
  21. struct mbox_chan *chan;
  22. };
  23. /**
  24. * cmdq_dev_get_client_reg() - parse cmdq client reg from the device
  25. * node of CMDQ client
  26. * @dev: device of CMDQ mailbox client
  27. * @client_reg: CMDQ client reg pointer
  28. * @idx: the index of desired reg
  29. *
  30. * Return: 0 for success; else the error code is returned
  31. *
  32. * Help CMDQ client parsing the cmdq client reg
  33. * from the device node of CMDQ client.
  34. */
  35. int cmdq_dev_get_client_reg(struct device *dev,
  36. struct cmdq_client_reg *client_reg, int idx);
  37. /**
  38. * cmdq_mbox_create() - create CMDQ mailbox client and channel
  39. * @dev: device of CMDQ mailbox client
  40. * @index: index of CMDQ mailbox channel
  41. *
  42. * Return: CMDQ mailbox client pointer
  43. */
  44. struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
  45. /**
  46. * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
  47. * @client: the CMDQ mailbox client
  48. */
  49. void cmdq_mbox_destroy(struct cmdq_client *client);
  50. /**
  51. * cmdq_pkt_create() - create a CMDQ packet
  52. * @client: the CMDQ mailbox client
  53. * @size: required CMDQ buffer size
  54. *
  55. * Return: CMDQ packet pointer
  56. */
  57. struct cmdq_pkt *cmdq_pkt_create(struct cmdq_client *client, size_t size);
  58. /**
  59. * cmdq_pkt_destroy() - destroy the CMDQ packet
  60. * @pkt: the CMDQ packet
  61. */
  62. void cmdq_pkt_destroy(struct cmdq_pkt *pkt);
  63. /**
  64. * cmdq_pkt_write() - append write command to the CMDQ packet
  65. * @pkt: the CMDQ packet
  66. * @subsys: the CMDQ sub system code
  67. * @offset: register offset from CMDQ sub system
  68. * @value: the specified target register value
  69. *
  70. * Return: 0 for success; else the error code is returned
  71. */
  72. int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value);
  73. /**
  74. * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet
  75. * @pkt: the CMDQ packet
  76. * @subsys: the CMDQ sub system code
  77. * @offset: register offset from CMDQ sub system
  78. * @value: the specified target register value
  79. * @mask: the specified target register mask
  80. *
  81. * Return: 0 for success; else the error code is returned
  82. */
  83. int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys,
  84. u16 offset, u32 value, u32 mask);
  85. /*
  86. * cmdq_pkt_read_s() - append read_s command to the CMDQ packet
  87. * @pkt: the CMDQ packet
  88. * @high_addr_reg_idx: internal register ID which contains high address of pa
  89. * @addr_low: low address of pa
  90. * @reg_idx: the CMDQ internal register ID to cache read data
  91. *
  92. * Return: 0 for success; else the error code is returned
  93. */
  94. int cmdq_pkt_read_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx, u16 addr_low,
  95. u16 reg_idx);
  96. /**
  97. * cmdq_pkt_write_s() - append write_s command to the CMDQ packet
  98. * @pkt: the CMDQ packet
  99. * @high_addr_reg_idx: internal register ID which contains high address of pa
  100. * @addr_low: low address of pa
  101. * @src_reg_idx: the CMDQ internal register ID which cache source value
  102. *
  103. * Return: 0 for success; else the error code is returned
  104. *
  105. * Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
  106. * to get high address and call cmdq_pkt_assign() to assign value into internal
  107. * reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
  108. * call to this function.
  109. */
  110. int cmdq_pkt_write_s(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
  111. u16 addr_low, u16 src_reg_idx);
  112. /**
  113. * cmdq_pkt_write_s_mask() - append write_s with mask command to the CMDQ packet
  114. * @pkt: the CMDQ packet
  115. * @high_addr_reg_idx: internal register ID which contains high address of pa
  116. * @addr_low: low address of pa
  117. * @src_reg_idx: the CMDQ internal register ID which cache source value
  118. * @mask: the specified target address mask, use U32_MAX if no need
  119. *
  120. * Return: 0 for success; else the error code is returned
  121. *
  122. * Support write value to physical address without subsys. Use CMDQ_ADDR_HIGH()
  123. * to get high address and call cmdq_pkt_assign() to assign value into internal
  124. * reg. Also use CMDQ_ADDR_LOW() to get low address for addr_low parameter when
  125. * call to this function.
  126. */
  127. int cmdq_pkt_write_s_mask(struct cmdq_pkt *pkt, u16 high_addr_reg_idx,
  128. u16 addr_low, u16 src_reg_idx, u32 mask);
  129. /**
  130. * cmdq_pkt_write_s_value() - append write_s command to the CMDQ packet which
  131. * write value to a physical address
  132. * @pkt: the CMDQ packet
  133. * @high_addr_reg_idx: internal register ID which contains high address of pa
  134. * @addr_low: low address of pa
  135. * @value: the specified target value
  136. *
  137. * Return: 0 for success; else the error code is returned
  138. */
  139. int cmdq_pkt_write_s_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
  140. u16 addr_low, u32 value);
  141. /**
  142. * cmdq_pkt_write_s_mask_value() - append write_s command with mask to the CMDQ
  143. * packet which write value to a physical
  144. * address
  145. * @pkt: the CMDQ packet
  146. * @high_addr_reg_idx: internal register ID which contains high address of pa
  147. * @addr_low: low address of pa
  148. * @value: the specified target value
  149. * @mask: the specified target mask
  150. *
  151. * Return: 0 for success; else the error code is returned
  152. */
  153. int cmdq_pkt_write_s_mask_value(struct cmdq_pkt *pkt, u8 high_addr_reg_idx,
  154. u16 addr_low, u32 value, u32 mask);
  155. /**
  156. * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet
  157. * @pkt: the CMDQ packet
  158. * @event: the desired event type to wait
  159. * @clear: clear event or not after event arrive
  160. *
  161. * Return: 0 for success; else the error code is returned
  162. */
  163. int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event, bool clear);
  164. /**
  165. * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet
  166. * @pkt: the CMDQ packet
  167. * @event: the desired event to be cleared
  168. *
  169. * Return: 0 for success; else the error code is returned
  170. */
  171. int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event);
  172. /**
  173. * cmdq_pkt_set_event() - append set event command to the CMDQ packet
  174. * @pkt: the CMDQ packet
  175. * @event: the desired event to be set
  176. *
  177. * Return: 0 for success; else the error code is returned
  178. */
  179. int cmdq_pkt_set_event(struct cmdq_pkt *pkt, u16 event);
  180. /**
  181. * cmdq_pkt_poll() - Append polling command to the CMDQ packet, ask GCE to
  182. * execute an instruction that wait for a specified
  183. * hardware register to check for the value w/o mask.
  184. * All GCE hardware threads will be blocked by this
  185. * instruction.
  186. * @pkt: the CMDQ packet
  187. * @subsys: the CMDQ sub system code
  188. * @offset: register offset from CMDQ sub system
  189. * @value: the specified target register value
  190. *
  191. * Return: 0 for success; else the error code is returned
  192. */
  193. int cmdq_pkt_poll(struct cmdq_pkt *pkt, u8 subsys,
  194. u16 offset, u32 value);
  195. /**
  196. * cmdq_pkt_poll_mask() - Append polling command to the CMDQ packet, ask GCE to
  197. * execute an instruction that wait for a specified
  198. * hardware register to check for the value w/ mask.
  199. * All GCE hardware threads will be blocked by this
  200. * instruction.
  201. * @pkt: the CMDQ packet
  202. * @subsys: the CMDQ sub system code
  203. * @offset: register offset from CMDQ sub system
  204. * @value: the specified target register value
  205. * @mask: the specified target register mask
  206. *
  207. * Return: 0 for success; else the error code is returned
  208. */
  209. int cmdq_pkt_poll_mask(struct cmdq_pkt *pkt, u8 subsys,
  210. u16 offset, u32 value, u32 mask);
  211. /**
  212. * cmdq_pkt_assign() - Append logic assign command to the CMDQ packet, ask GCE
  213. * to execute an instruction that set a constant value into
  214. * internal register and use as value, mask or address in
  215. * read/write instruction.
  216. * @pkt: the CMDQ packet
  217. * @reg_idx: the CMDQ internal register ID
  218. * @value: the specified value
  219. *
  220. * Return: 0 for success; else the error code is returned
  221. */
  222. int cmdq_pkt_assign(struct cmdq_pkt *pkt, u16 reg_idx, u32 value);
  223. /**
  224. * cmdq_pkt_jump() - Append jump command to the CMDQ packet, ask GCE
  225. * to execute an instruction that change current thread PC to
  226. * a physical address which should contains more instruction.
  227. * @pkt: the CMDQ packet
  228. * @addr: physical address of target instruction buffer
  229. *
  230. * Return: 0 for success; else the error code is returned
  231. */
  232. int cmdq_pkt_jump(struct cmdq_pkt *pkt, dma_addr_t addr);
  233. /**
  234. * cmdq_pkt_finalize() - Append EOC and jump command to pkt.
  235. * @pkt: the CMDQ packet
  236. *
  237. * Return: 0 for success; else the error code is returned
  238. */
  239. int cmdq_pkt_finalize(struct cmdq_pkt *pkt);
  240. /**
  241. * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ
  242. * packet and call back at the end of done packet
  243. * @pkt: the CMDQ packet
  244. *
  245. * Return: 0 for success; else the error code is returned
  246. *
  247. * Trigger CMDQ to asynchronously execute the CMDQ packet and call back
  248. * at the end of done packet. Note that this is an ASYNC function. When the
  249. * function returned, it may or may not be finished.
  250. */
  251. int cmdq_pkt_flush_async(struct cmdq_pkt *pkt);
  252. #endif /* __MTK_CMDQ_H__ */