cam_cdm_util.h 8.5 KB

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