cam_cdm_util.h 9.0 KB

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