cam_cdm_intf_api.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_CDM_API_H_
  7. #define _CAM_CDM_API_H_
  8. #include <media/cam_defs.h>
  9. #include "cam_cdm_util.h"
  10. #include "cam_soc_util.h"
  11. #include "cam_packet_util.h"
  12. #define CAM_CDM_BL_CMD_MAX 25
  13. /* enum cam_cdm_id - Enum for possible CAM CDM hardwares */
  14. enum cam_cdm_id {
  15. CAM_CDM_VIRTUAL,
  16. CAM_CDM_HW_ANY,
  17. CAM_CDM_CPAS,
  18. CAM_CDM_IFE,
  19. CAM_CDM_TFE,
  20. CAM_CDM_OPE,
  21. CAM_CDM_IPE0,
  22. CAM_CDM_IPE1,
  23. CAM_CDM_BPS,
  24. CAM_CDM_VFE,
  25. CAM_CDM_RT,
  26. CAM_CDM_MAX
  27. };
  28. /* enum cam_cdm_cb_status - Enum for possible CAM CDM callback */
  29. enum cam_cdm_cb_status {
  30. CAM_CDM_CB_STATUS_BL_SUCCESS,
  31. CAM_CDM_CB_STATUS_INVALID_BL_CMD,
  32. CAM_CDM_CB_STATUS_PAGEFAULT,
  33. CAM_CDM_CB_STATUS_HW_RESET_ONGOING,
  34. CAM_CDM_CB_STATUS_HW_RESET_DONE,
  35. CAM_CDM_CB_STATUS_HW_FLUSH,
  36. CAM_CDM_CB_STATUS_HW_RESUBMIT,
  37. CAM_CDM_CB_STATUS_HW_ERROR,
  38. CAM_CDM_CB_STATUS_UNKNOWN_ERROR,
  39. };
  40. /* enum cam_cdm_bl_cmd_addr_type - Enum for possible CDM bl cmd addr types */
  41. enum cam_cdm_bl_cmd_addr_type {
  42. CAM_CDM_BL_CMD_TYPE_MEM_HANDLE,
  43. CAM_CDM_BL_CMD_TYPE_HW_IOVA,
  44. CAM_CDM_BL_CMD_TYPE_KERNEL_IOVA,
  45. };
  46. /* enum cam_cdm_bl_fifo - interface commands.*/
  47. enum cam_cdm_bl_fifo_queue {
  48. CAM_CDM_BL_FIFO_0,
  49. CAM_CDM_BL_FIFO_1,
  50. CAM_CDM_BL_FIFO_2,
  51. CAM_CDM_BL_FIFO_3,
  52. CAM_CDM_BL_FIFO_MAX,
  53. };
  54. /**
  55. * struct cam_cdm_acquire_data - Cam CDM acquire data structure
  56. *
  57. * @identifier : Input identifier string which is the device label from dt
  58. * like vfe, ife, jpeg etc
  59. * @cell_index : Input integer identifier pointing to the cell index from dt
  60. * of the device. This can be used to form a unique string
  61. * with @identifier like vfe0, ife1, jpeg0 etc
  62. * @id : ID of a specific or any CDM HW which needs to be acquired.
  63. * @userdata : Input private data which will be returned as part
  64. * of callback.
  65. * @cam_cdm_callback : Input callback pointer for triggering the
  66. * callbacks from CDM driver
  67. * @handle : CDM Client handle
  68. * @userdata : Private data given at the time of acquire
  69. * @status : Callback status
  70. * @cookie : Cookie if the callback is gen irq status
  71. * @base_array_cnt : Input number of ioremapped address pair pointing
  72. * in base_array, needed only if selected cdm is a virtual.
  73. * @base_array : Input pointer to ioremapped address pair arrary
  74. * needed only if selected cdm is a virtual.
  75. * @priority : Priority of the client.
  76. * @cdm_version : CDM version is output while acquiring HW cdm and
  77. * it is Input while acquiring virtual cdm.
  78. * Currently fixing it to one version below
  79. * acquire API.
  80. * @ops : Output pointer updated by cdm driver to the CDM
  81. * util ops for this HW version of CDM acquired.
  82. * @handle : Output Unique handle generated for this acquire
  83. *
  84. */
  85. struct cam_cdm_acquire_data {
  86. char identifier[128];
  87. uint32_t cell_index;
  88. enum cam_cdm_id id;
  89. void *userdata;
  90. void (*cam_cdm_callback)(uint32_t handle, void *userdata,
  91. enum cam_cdm_cb_status status, uint64_t cookie);
  92. uint32_t base_array_cnt;
  93. struct cam_soc_reg_map *base_array[CAM_SOC_MAX_BLOCK];
  94. enum cam_cdm_bl_fifo_queue priority;
  95. struct cam_hw_version cdm_version;
  96. struct cam_cdm_utils_ops *ops;
  97. uint32_t handle;
  98. };
  99. /**
  100. * struct cam_cdm_bl_cmd - Cam CDM HW bl command
  101. *
  102. * @bl_addr : Union of all three type for CDM BL commands
  103. * @mem_handle : Input mem handle of bl cmd
  104. * @offset : Input offset of the actual bl cmd in the memory pointed
  105. * by mem_handle
  106. * @len : Input length of the BL command, Cannot be more than 1MB and
  107. * this is will be validated with offset+size of the memory pointed
  108. * by mem_handle
  109. * @enable_debug_gen_irq : bool flag to submit extra gen_irq afteR bl_command
  110. * @arbitrate : bool flag to arbitrate on submitted BL boundary
  111. */
  112. struct cam_cdm_bl_cmd {
  113. union {
  114. int32_t mem_handle;
  115. uint32_t *hw_iova;
  116. uintptr_t kernel_iova;
  117. } bl_addr;
  118. uint32_t offset;
  119. uint32_t len;
  120. bool enable_debug_gen_irq;
  121. bool arbitrate;
  122. };
  123. /**
  124. * struct cam_cdm_bl_request - Cam CDM HW base & length (BL) request
  125. *
  126. * @flag : 1 for callback needed and 0 for no callback when this BL
  127. * request is done
  128. * @gen_irq_arb : enum for setting arbitration in gen_irq
  129. * @userdata :Input private data which will be returned as part
  130. * of callback if request for this bl request in flags.
  131. * @type : type of the submitted bl cmd address.
  132. * @cmd_arrary_count : Input number of BL commands to be submitted to CDM
  133. * @cookie : Cookie if the callback is gen irq status
  134. * @avail_buff_size: Available buffer size in bytes
  135. * @bl_cmd_array : Input payload holding the BL cmd's arrary
  136. * to be sumbitted.
  137. *
  138. */
  139. struct cam_cdm_bl_request {
  140. bool flag;
  141. bool gen_irq_arb;
  142. void *userdata;
  143. enum cam_cdm_bl_cmd_addr_type type;
  144. uint32_t cmd_arrary_count;
  145. struct cam_kmd_buf_info *genirq_buff;
  146. uint64_t cookie;
  147. struct cam_cdm_bl_cmd cmd[1];
  148. };
  149. /**
  150. * struct cam_cdm_bl_data - last submiited CDM BL data
  151. *
  152. * @mem_handle : Input mem handle of bl cmd
  153. * @hw_addr : Hw address of submitted Bl command
  154. * @offset : Input offset of the actual bl cmd in the memory pointed
  155. * by mem_handle
  156. * @len : length of submitted Bl command to CDM.
  157. * @input_len : Input length of the BL command, Cannot be more than 1MB and
  158. * this is will be validated with offset+size of the memory pointed
  159. * by mem_handle
  160. * @type : CDM bl cmd addr types.
  161. */
  162. struct cam_cdm_bl_data {
  163. int32_t mem_handle;
  164. dma_addr_t hw_addr;
  165. uint32_t offset;
  166. size_t len;
  167. uint32_t input_len;
  168. enum cam_cdm_bl_cmd_addr_type type;
  169. };
  170. /**
  171. * struct cam_cdm_bl_info
  172. *
  173. * @bl_count : No. of Bl commands submiited to CDM.
  174. * @cmd : payload holding the BL cmd's arrary
  175. * that is sumbitted.
  176. *
  177. */
  178. struct cam_cdm_bl_info {
  179. int32_t bl_count;
  180. struct cam_cdm_bl_data cmd[CAM_CDM_BL_CMD_MAX];
  181. };
  182. /**
  183. * @brief : API to get the CDM capabilities for a camera device type
  184. *
  185. * @identifier : Input pointer to a string which is the device label from dt
  186. * like vfe, ife, jpeg etc, We do not need cell index
  187. * assuming all devices of a single type maps to one SMMU
  188. * client
  189. * @cdm_handles : Input iommu handle memory pointer to update handles
  190. *
  191. * @return 0 on success
  192. */
  193. int cam_cdm_get_iommu_handle(char *identifier,
  194. struct cam_iommu_handle *cdm_handles);
  195. /**
  196. * @brief : API to acquire a CDM
  197. *
  198. * @data : Input data for the CDM to be acquired
  199. *
  200. * @return 0 on success
  201. */
  202. int cam_cdm_acquire(struct cam_cdm_acquire_data *data);
  203. /**
  204. * @brief : API to release a previously acquired CDM
  205. *
  206. * @handle : Input handle for the CDM to be released
  207. *
  208. * @return 0 on success
  209. */
  210. int cam_cdm_release(uint32_t handle);
  211. /**
  212. * @brief : API to submit the base & length (BL's) for acquired CDM
  213. *
  214. * @handle : Input cdm handle to which the BL's needs to be sumbitted.
  215. * @data : Input pointer to the BL's to be sumbitted
  216. *
  217. * @return 0 on success
  218. */
  219. int cam_cdm_submit_bls(uint32_t handle, struct cam_cdm_bl_request *data);
  220. /**
  221. * @brief : API to stream ON a previously acquired CDM,
  222. * during this we turn on/off clocks/power based on active clients.
  223. *
  224. * @handle : Input handle for the CDM to be released
  225. *
  226. * @return 0 on success
  227. */
  228. int cam_cdm_stream_on(uint32_t handle);
  229. /**
  230. * @brief : API to stream OFF a previously acquired CDM,
  231. * during this we turn on/off clocks/power based on active clients.
  232. *
  233. * @handle : Input handle for the CDM to be released
  234. *
  235. * @return 0 on success
  236. */
  237. int cam_cdm_stream_off(uint32_t handle);
  238. /**
  239. * @brief : API to reset previously acquired CDM,
  240. * this should be only performed only if the CDM is private.
  241. *
  242. * @handle : Input handle of the CDM to reset
  243. *
  244. * @return 0 on success
  245. */
  246. int cam_cdm_reset_hw(uint32_t handle);
  247. /**
  248. * @brief : API to publish CDM ops to HW blocks like IFE
  249. *
  250. * @return : CDM operations
  251. *
  252. */
  253. struct cam_cdm_utils_ops *cam_cdm_publish_ops(void);
  254. /**
  255. * @brief : API to register CDM hw to platform framework.
  256. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  257. */
  258. int cam_hw_cdm_init_module(void);
  259. /**
  260. * @brief : API to register CDM interface to platform framework.
  261. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  262. */
  263. int cam_cdm_intf_init_module(void);
  264. /**
  265. * @brief : API to remove CDM interface from platform framework.
  266. */
  267. void cam_cdm_intf_exit_module(void);
  268. /**
  269. * @brief : API to remove CDM hw from platform framework.
  270. */
  271. void cam_hw_cdm_exit_module(void);
  272. /**
  273. * @brief : API to flush previously acquired CDM,
  274. * this should be only performed only if the CDM is private.
  275. *
  276. * @handle : Input handle of the CDM to reset
  277. *
  278. * @return 0 on success
  279. */
  280. int cam_cdm_flush_hw(uint32_t handle);
  281. /**
  282. * @brief : API to detect culprit bl_tag in previously acquired CDM,
  283. * this should be only performed only if the CDM is private.
  284. *
  285. * @handle : Input handle of the CDM to reset
  286. *
  287. * @return 0 on success
  288. */
  289. int cam_cdm_handle_error(uint32_t handle);
  290. /**
  291. * @brief : API get CDM ops
  292. *
  293. * @return : CDM operations
  294. *
  295. */
  296. struct cam_cdm_utils_ops *cam_cdm_publish_ops(void);
  297. /**
  298. * @brief : API to detect hang in previously acquired CDM,
  299. * this should be only performed only if the CDM is private.
  300. *
  301. * @handle : Input handle of the CDM to detect hang
  302. *
  303. * @return 0 on success
  304. */
  305. int cam_cdm_detect_hang_error(uint32_t handle);
  306. /**
  307. * @brief : API to dump the CDM Debug registers
  308. *
  309. * @handle : Input handle of the CDM to dump the registers
  310. *
  311. * @return 0 on success
  312. */
  313. int cam_cdm_dump_debug_registers(uint32_t handle);
  314. #endif /* _CAM_CDM_API_H_ */