cam_cdm_util.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_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_changebase: Calculates the size of a change-base command
  64. * in dwords.
  65. * @return Size in dwords
  66. *
  67. * @cdm_offsetof_dmi_addr: Returns the offset of address field in the DMI
  68. * command header.
  69. * @return Offset of addr field
  70. *
  71. * @cdm_offsetof_indirect_addr: Returns the offset of address field in the
  72. * indirect command header.
  73. * @return Offset of addr field
  74. *
  75. * @cdm_write_regcontinuous: Writes a command into the command buffer.
  76. * @pCmdBuffer: Pointer to command buffer
  77. * @reg: Beginning of the register address range where
  78. * values will be written.
  79. * @numVals: Number of values (registers) that will be written
  80. * @pVals : An array of values that will be written
  81. * @return Pointer in command buffer pointing past the written commands
  82. *
  83. * @cdm_write_regrandom: Writes a command into the command buffer in
  84. * register/value pairs.
  85. * @pCmdBuffer: Pointer to command buffer
  86. * @numRegVals: Number of register/value pairs that will be written
  87. * @pRegVals: An array of register/value pairs that will be written
  88. * The even indices are registers and the odd indices
  89. * arevalues, e.g., {reg1, val1, reg2, val2, ...}.
  90. * @return Pointer in command buffer pointing past the written commands
  91. *
  92. * @cdm_write_dmi: Writes a DMI command into the command bufferM.
  93. * @pCmdBuffer: Pointer to command buffer
  94. * @dmiCmd: DMI command
  95. * @DMIAddr: Address of the DMI
  96. * @DMISel: Selected bank that the DMI will write to
  97. * @length: Size of data in bytes
  98. * @return Pointer in command buffer pointing past the written commands
  99. *
  100. * @cdm_write_indirect: Writes a indirect command into the command buffer.
  101. * @pCmdBuffer: Pointer to command buffer
  102. * @indirectBufferAddr: Device address of the indirect cmd buffer.
  103. * @length: Size of data in bytes
  104. * @return Pointer in command buffer pointing past the written commands
  105. *
  106. * @cdm_write_changebase: Writes a changing CDM (address) base command into
  107. * the command buffer.
  108. * @pCmdBuffer: Pointer to command buffer
  109. * @base: New base (device) address
  110. * @return Pointer in command buffer pointing past the written commands
  111. *
  112. * @cdm_write_genirq: Writes a gen irq command into the command buffer.
  113. * @pCmdBuffer: Pointer to command buffer
  114. * @userdata: userdata or cookie return by hardware during irq.
  115. *
  116. * @cdm_write_wait_comp_event: Writes a wait comp event cmd into the
  117. * command buffer.
  118. * @pCmdBuffer: Pointer to command buffer
  119. * @mask1: This value decides which comp events to wait (0 - 31).
  120. * @mask2: This value decides which comp events to wait (32 - 65).
  121. */
  122. struct cam_cdm_utils_ops {
  123. uint32_t (*cdm_get_cmd_header_size)(unsigned int command);
  124. uint32_t (*cdm_required_size_dmi)(void);
  125. uint32_t (*cdm_required_size_reg_continuous)(uint32_t numVals);
  126. uint32_t (*cdm_required_size_reg_random)(uint32_t numRegVals);
  127. uint32_t (*cdm_required_size_indirect)(void);
  128. uint32_t (*cdm_required_size_genirq)(void);
  129. uint32_t (*cdm_required_size_wait_event)(void);
  130. uint32_t (*cdm_required_size_changebase)(void);
  131. uint32_t (*cdm_required_size_comp_wait)(void);
  132. uint32_t (*cdm_required_size_prefetch_disable)(void);
  133. uint32_t (*cdm_offsetof_dmi_addr)(void);
  134. uint32_t (*cdm_offsetof_indirect_addr)(void);
  135. uint32_t *(*cdm_write_dmi)(
  136. uint32_t *pCmdBuffer,
  137. uint8_t dmiCmd,
  138. uint32_t DMIAddr,
  139. uint8_t DMISel,
  140. uint32_t dmiBufferAddr,
  141. uint32_t length);
  142. uint32_t* (*cdm_write_regcontinuous)(
  143. uint32_t *pCmdBuffer,
  144. uint32_t reg,
  145. uint32_t numVals,
  146. uint32_t *pVals);
  147. uint32_t *(*cdm_write_regrandom)(
  148. uint32_t *pCmdBuffer,
  149. uint32_t numRegVals,
  150. uint32_t *pRegVals);
  151. uint32_t *(*cdm_write_indirect)(
  152. uint32_t *pCmdBuffer,
  153. uint32_t indirectBufferAddr,
  154. uint32_t length);
  155. void (*cdm_write_genirq)(
  156. uint32_t *pCmdBuffer,
  157. uint32_t userdata,
  158. bool bit_wr_enable,
  159. uint32_t fifo_idx);
  160. uint32_t *(*cdm_write_wait_event)(
  161. uint32_t *pCmdBuffer,
  162. uint32_t iw,
  163. uint32_t id,
  164. uint32_t mask,
  165. uint32_t offset,
  166. uint32_t data);
  167. uint32_t *(*cdm_write_changebase)(
  168. uint32_t *pCmdBuffer,
  169. uint32_t base);
  170. uint32_t *(*cdm_write_wait_comp_event)(
  171. uint32_t *pCmdBuffer,
  172. uint32_t mask1,
  173. uint32_t mask2);
  174. uint32_t *(*cdm_write_wait_prefetch_disable)(
  175. uint32_t *pCmdBuffer,
  176. uint32_t id,
  177. uint32_t mask1,
  178. uint32_t mask2);
  179. };
  180. /**
  181. * struct cam_cdm_cmd_buf_dump_info; - Camera CDM dump info
  182. * @dst_offset: dst offset
  183. * @dst_max_size max size of destination buffer
  184. * @src_start: source start address
  185. * @src_end: source end address
  186. * @dst_start: dst start address
  187. */
  188. struct cam_cdm_cmd_buf_dump_info {
  189. size_t dst_offset;
  190. size_t dst_max_size;
  191. uint32_t *src_start;
  192. uint32_t *src_end;
  193. uintptr_t dst_start;
  194. };
  195. /**
  196. * struct cam_cdm_cmd_dump_header- Camera CDM dump header
  197. * @tag: tag name for header
  198. * @size: size of data
  199. * @word_size: size of each word
  200. */
  201. struct cam_cdm_cmd_dump_header {
  202. uint8_t tag[CAM_CDM_CMD_TAG_MAX_LEN];
  203. uint64_t size;
  204. uint32_t word_size;
  205. };
  206. /**
  207. * cam_cdm_util_log_cmd_bufs()
  208. *
  209. * @brief: Util function to log cdm command buffers
  210. *
  211. * @cmd_buffer_start: Pointer to start of cmd buffer
  212. * @cmd_buffer_end: Pointer to end of cmd buffer
  213. *
  214. */
  215. void cam_cdm_util_dump_cmd_buf(
  216. uint32_t *cmd_buffer_start, uint32_t *cmd_buffer_end);
  217. /**
  218. * cam_cdm_util_dump_cmd_bufs_v2()
  219. *
  220. * @brief: Util function to cdm command buffers
  221. * to a buffer
  222. *
  223. * @dump_info: Information about source and destination buffers
  224. *
  225. * return SUCCESS/FAILURE
  226. */
  227. int cam_cdm_util_dump_cmd_bufs_v2(
  228. struct cam_cdm_cmd_buf_dump_info *dump_info);
  229. #endif /* _CAM_CDM_UTIL_H_ */