cam_cdm_util.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_CDM_UTIL_H_
  7. #define _CAM_CDM_UTIL_H_
  8. /* Max len for tag name for header while dumping cmd buffer*/
  9. #define CAM_CDM_CMD_TAG_MAX_LEN 128
  10. #include <linux/types.h>
  11. enum cam_cdm_command {
  12. CAM_CDM_CMD_UNUSED = 0x0,
  13. CAM_CDM_CMD_DMI = 0x1,
  14. CAM_CDM_CMD_NOT_DEFINED = 0x2,
  15. CAM_CDM_CMD_REG_CONT = 0x3,
  16. CAM_CDM_CMD_REG_RANDOM = 0x4,
  17. CAM_CDM_CMD_BUFF_INDIRECT = 0x5,
  18. CAM_CDM_CMD_GEN_IRQ = 0x6,
  19. CAM_CDM_CMD_WAIT_EVENT = 0x7,
  20. CAM_CDM_CMD_CHANGE_BASE = 0x8,
  21. CAM_CDM_CMD_PERF_CTRL = 0x9,
  22. CAM_CDM_CMD_DMI_32 = 0xa,
  23. CAM_CDM_CMD_DMI_64 = 0xb,
  24. CAM_CDM_CMD_COMP_WAIT = 0xc,
  25. CAM_CDM_CLEAR_COMP_WAIT = 0xd,
  26. CAM_CDM_WAIT_PREFETCH_DISABLE = 0xe,
  27. CAM_CDM_CMD_PRIVATE_BASE = 0xf,
  28. CAM_CDM_CMD_SWD_DMI_32 = (CAM_CDM_CMD_PRIVATE_BASE + 0x64),
  29. CAM_CDM_CMD_SWD_DMI_64 = (CAM_CDM_CMD_PRIVATE_BASE + 0x65),
  30. CAM_CDM_CMD_PRIVATE_BASE_MAX = 0x7F,
  31. };
  32. /**
  33. * struct cam_cdm_utils_ops - Camera CDM util ops
  34. *
  35. * @cdm_get_cmd_header_size: Returns the size of the given command header
  36. * in DWORDs.
  37. * @command Command ID
  38. * @return Size of the command in DWORDs
  39. *
  40. * @cdm_required_size_reg_continuous: Calculates the size of a reg-continuous
  41. * command in dwords.
  42. * @numVals Number of continuous values
  43. * @return Size in dwords
  44. *
  45. * @cdm_required_size_reg_random: Calculates the size of a reg-random command
  46. * in dwords.
  47. * @numRegVals Number of register/value pairs
  48. * @return Size in dwords
  49. *
  50. * @cdm_required_size_dmi: Calculates the size of a DMI command in dwords.
  51. * @return Size in dwords
  52. *
  53. * @cdm_required_size_genirq: Calculates size of a Genirq command in dwords.
  54. * @return Size in dwords
  55. *
  56. * @cdm_required_size_indirect: Calculates the size of an indirect command
  57. * in dwords.
  58. * @return Size in dwords
  59. *
  60. * @cdm_required_size_comp_wait: Calculates the size of a comp-wait command
  61. * in dwords.
  62. * @return Size in dwords
  63. *
  64. * @cdm_required_size_clear_comp_event: Calculates the size of clear-comp-event
  65. * command in dwords.
  66. * @return Size in dwords
  67. *
  68. * @cdm_required_size_changebase: Calculates the size of a change-base command
  69. * in dwords.
  70. * @return Size in dwords
  71. *
  72. * @cdm_offsetof_dmi_addr: Returns the offset of address field in the DMI
  73. * command header.
  74. * @return Offset of addr field
  75. *
  76. * @cdm_offsetof_indirect_addr: Returns the offset of address field in the
  77. * indirect command header.
  78. * @return Offset of addr field
  79. *
  80. * @cdm_write_regcontinuous: Writes a command into the command buffer.
  81. * @pCmdBuffer: Pointer to command buffer
  82. * @reg: Beginning of the register address range where
  83. * values will be written.
  84. * @numVals: Number of values (registers) that will be written
  85. * @pVals : An array of values that will be written
  86. * @return Pointer in command buffer pointing past the written commands
  87. *
  88. * @cdm_write_regrandom: Writes a command into the command buffer in
  89. * register/value pairs.
  90. * @pCmdBuffer: Pointer to command buffer
  91. * @numRegVals: Number of register/value pairs that will be written
  92. * @pRegVals: An array of register/value pairs that will be written
  93. * The even indices are registers and the odd indices
  94. * arevalues, e.g., {reg1, val1, reg2, val2, ...}.
  95. * @return Pointer in command buffer pointing past the written commands
  96. *
  97. * @cdm_write_dmi: Writes a DMI command into the command bufferM.
  98. * @pCmdBuffer: Pointer to command buffer
  99. * @dmiCmd: DMI command
  100. * @DMIAddr: Address of the DMI
  101. * @DMISel: Selected bank that the DMI will write to
  102. * @length: Size of data in bytes
  103. * @return Pointer in command buffer pointing past the written commands
  104. *
  105. * @cdm_write_indirect: Writes a indirect command into the command buffer.
  106. * @pCmdBuffer: Pointer to command buffer
  107. * @indirectBufferAddr: Device address of the indirect cmd buffer.
  108. * @length: Size of data in bytes
  109. * @return Pointer in command buffer pointing past the written commands
  110. *
  111. * @cdm_write_changebase: Writes a changing CDM (address) base command into
  112. * the command buffer.
  113. * @pCmdBuffer: Pointer to command buffer
  114. * @base: New base (device) address
  115. * @return Pointer in command buffer pointing past the written commands
  116. *
  117. * @cdm_write_genirq: Writes a gen irq command into the command buffer.
  118. * @pCmdBuffer: Pointer to command buffer
  119. * @userdata: userdata or cookie return by hardware during irq.
  120. *
  121. * @cdm_write_wait_comp_event: Writes a wait comp event cmd into the
  122. * command buffer.
  123. * @pCmdBuffer: Pointer to command buffer
  124. * @mask1: This value decides which comp events to wait (0 - 31).
  125. * @mask2: This value decides which comp events to wait (32 - 65).
  126. *
  127. * @cdm_write_clear_comp_event: Writes a clear comp event cmd into the
  128. * command buffer.
  129. * @pCmdBuffer: Pointer to command buffer
  130. * @mask1: This value decides which comp events to clear (0 - 31).
  131. * @mask2: This value decides which comp events to clear (32 - 65).
  132. */
  133. struct cam_cdm_utils_ops {
  134. uint32_t (*cdm_get_cmd_header_size)(unsigned int command);
  135. uint32_t (*cdm_required_size_dmi)(void);
  136. uint32_t (*cdm_required_size_reg_continuous)(uint32_t numVals);
  137. uint32_t (*cdm_required_size_reg_random)(uint32_t numRegVals);
  138. uint32_t (*cdm_required_size_indirect)(void);
  139. uint32_t (*cdm_required_size_genirq)(void);
  140. uint32_t (*cdm_required_size_wait_event)(void);
  141. uint32_t (*cdm_required_size_changebase)(void);
  142. uint32_t (*cdm_required_size_comp_wait)(void);
  143. uint32_t (*cdm_required_size_clear_comp_event)(void);
  144. uint32_t (*cdm_required_size_prefetch_disable)(void);
  145. uint32_t (*cdm_offsetof_dmi_addr)(void);
  146. uint32_t (*cdm_offsetof_indirect_addr)(void);
  147. uint32_t *(*cdm_write_dmi)(
  148. uint32_t *pCmdBuffer,
  149. uint8_t dmiCmd,
  150. uint32_t DMIAddr,
  151. uint8_t DMISel,
  152. uint32_t dmiBufferAddr,
  153. uint32_t length);
  154. uint32_t* (*cdm_write_regcontinuous)(
  155. uint32_t *pCmdBuffer,
  156. uint32_t reg,
  157. uint32_t numVals,
  158. uint32_t *pVals);
  159. uint32_t *(*cdm_write_regrandom)(
  160. uint32_t *pCmdBuffer,
  161. uint32_t numRegVals,
  162. uint32_t *pRegVals);
  163. uint32_t *(*cdm_write_indirect)(
  164. uint32_t *pCmdBuffer,
  165. uint32_t indirectBufferAddr,
  166. uint32_t length);
  167. void (*cdm_write_genirq)(
  168. uint32_t *pCmdBuffer,
  169. uint32_t userdata,
  170. bool bit_wr_enable,
  171. uint32_t fifo_idx);
  172. uint32_t *(*cdm_write_wait_event)(
  173. uint32_t *pCmdBuffer,
  174. uint32_t iw,
  175. uint32_t id,
  176. uint32_t mask,
  177. uint32_t offset,
  178. uint32_t data);
  179. uint32_t *(*cdm_write_changebase)(
  180. uint32_t *pCmdBuffer,
  181. uint32_t base);
  182. uint32_t *(*cdm_write_wait_comp_event)(
  183. uint32_t *pCmdBuffer,
  184. uint32_t mask1,
  185. uint32_t mask2);
  186. uint32_t *(*cdm_write_clear_comp_event)(
  187. uint32_t *pCmdBuffer,
  188. uint32_t mask1,
  189. uint32_t mask2);
  190. uint32_t *(*cdm_write_wait_prefetch_disable)(
  191. uint32_t *pCmdBuffer,
  192. uint32_t id,
  193. uint32_t mask1,
  194. uint32_t mask2);
  195. };
  196. /**
  197. * struct cam_cdm_cmd_buf_dump_info; - Camera CDM dump info
  198. * @dst_offset: dst offset
  199. * @dst_max_size max size of destination buffer
  200. * @src_start: source start address
  201. * @src_end: source end address
  202. * @dst_start: dst start address
  203. */
  204. struct cam_cdm_cmd_buf_dump_info {
  205. size_t dst_offset;
  206. size_t dst_max_size;
  207. uint32_t *src_start;
  208. uint32_t *src_end;
  209. uintptr_t dst_start;
  210. };
  211. /**
  212. * struct cam_cdm_cmd_dump_header- Camera CDM dump header
  213. * @tag: tag name for header
  214. * @size: size of data
  215. * @word_size: size of each word
  216. */
  217. struct cam_cdm_cmd_dump_header {
  218. uint8_t tag[CAM_CDM_CMD_TAG_MAX_LEN];
  219. uint64_t size;
  220. uint32_t word_size;
  221. };
  222. /**
  223. * cam_cdm_util_log_cmd_bufs()
  224. *
  225. * @brief: Util function to log cdm command buffers
  226. *
  227. * @cmd_buffer_start: Pointer to start of cmd buffer
  228. * @cmd_buffer_end: Pointer to end of cmd buffer
  229. *
  230. */
  231. void cam_cdm_util_dump_cmd_buf(
  232. uint32_t *cmd_buffer_start, uint32_t *cmd_buffer_end);
  233. /**
  234. * cam_cdm_util_dump_cmd_bufs_v2()
  235. *
  236. * @brief: Util function to cdm command buffers
  237. * to a buffer
  238. *
  239. * @dump_info: Information about source and destination buffers
  240. *
  241. * return SUCCESS/FAILURE
  242. */
  243. int cam_cdm_util_dump_cmd_bufs_v2(
  244. struct cam_cdm_cmd_buf_dump_info *dump_info);
  245. #endif /* _CAM_CDM_UTIL_H_ */