cam_cdm_intf_api.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 or
  71. * pf_args if it is page fault
  72. * @base_array_cnt : Input number of ioremapped address pair pointing
  73. * in base_array, needed only if selected cdm is a virtual.
  74. * @base_array : Input pointer to ioremapped address pair arrary
  75. * needed only if selected cdm is a virtual.
  76. * @priority : Priority of the client.
  77. * @cdm_version : CDM version is output while acquiring HW cdm and
  78. * it is Input while acquiring virtual cdm.
  79. * Currently fixing it to one version below
  80. * acquire API.
  81. * @ops : Output pointer updated by cdm driver to the CDM
  82. * util ops for this HW version of CDM acquired.
  83. * @handle : Output Unique handle generated for this acquire
  84. * @hw_idx : The physical CDM acquired
  85. *
  86. */
  87. struct cam_cdm_acquire_data {
  88. char identifier[128];
  89. uint32_t cell_index;
  90. enum cam_cdm_id id;
  91. void *userdata;
  92. void (*cam_cdm_callback)(uint32_t handle, void *userdata,
  93. enum cam_cdm_cb_status status, void *cookie);
  94. uint32_t base_array_cnt;
  95. struct cam_soc_reg_map *base_array[CAM_SOC_MAX_BLOCK];
  96. enum cam_cdm_bl_fifo_queue priority;
  97. struct cam_hw_version cdm_version;
  98. struct cam_cdm_utils_ops *ops;
  99. uint32_t handle;
  100. uint32_t hw_idx;
  101. };
  102. /**
  103. * struct cam_cdm_bl_cmd - Cam CDM HW bl command
  104. *
  105. * @bl_addr : Union of all three type for CDM BL commands
  106. * @mem_handle : Input mem handle of bl cmd
  107. * @offset : Input offset of the actual bl cmd in the memory pointed
  108. * by mem_handle
  109. * @len : Input length of the BL command, Cannot be more than 1MB and
  110. * this is will be validated with offset+size of the memory pointed
  111. * by mem_handle
  112. * @enable_debug_gen_irq : bool flag to submit extra gen_irq afteR bl_command
  113. * @arbitrate : bool flag to arbitrate on submitted BL boundary
  114. */
  115. struct cam_cdm_bl_cmd {
  116. union {
  117. int32_t mem_handle;
  118. uint32_t *hw_iova;
  119. uintptr_t kernel_iova;
  120. } bl_addr;
  121. uint32_t offset;
  122. uint32_t len;
  123. bool enable_debug_gen_irq;
  124. bool arbitrate;
  125. };
  126. /**
  127. * struct cam_cdm_bl_request - Cam CDM HW base & length (BL) request
  128. *
  129. * @flag : 1 for callback needed and 0 for no callback when this BL
  130. * request is done
  131. * @gen_irq_arb : enum for setting arbitration in gen_irq
  132. * @userdata :Input private data which will be returned as part
  133. * of callback if request for this bl request in flags.
  134. * @type : type of the submitted bl cmd address.
  135. * @cmd_arrary_count : Input number of BL commands to be submitted to CDM
  136. * @cookie : Cookie if the callback is gen irq status
  137. * @avail_buff_size: Available buffer size in bytes
  138. * @bl_cmd_array : Input payload holding the BL cmd's arrary
  139. * to be sumbitted.
  140. *
  141. */
  142. struct cam_cdm_bl_request {
  143. bool flag;
  144. bool gen_irq_arb;
  145. void *userdata;
  146. enum cam_cdm_bl_cmd_addr_type type;
  147. uint32_t cmd_arrary_count;
  148. struct cam_kmd_buf_info *genirq_buff;
  149. uint64_t cookie;
  150. struct cam_cdm_bl_cmd cmd[1];
  151. };
  152. /**
  153. * struct cam_cdm_bl_data - last submiited CDM BL data
  154. *
  155. * @mem_handle : Input mem handle of bl cmd
  156. * @hw_addr : Hw address of submitted Bl command
  157. * @offset : Input offset of the actual bl cmd in the memory pointed
  158. * by mem_handle
  159. * @len : length of submitted Bl command to CDM.
  160. * @input_len : Input length of the BL command, Cannot be more than 1MB and
  161. * this is will be validated with offset+size of the memory pointed
  162. * by mem_handle
  163. * @type : CDM bl cmd addr types.
  164. */
  165. struct cam_cdm_bl_data {
  166. int32_t mem_handle;
  167. dma_addr_t hw_addr;
  168. uint32_t offset;
  169. size_t len;
  170. uint32_t input_len;
  171. enum cam_cdm_bl_cmd_addr_type type;
  172. };
  173. /**
  174. * struct cam_cdm_bl_info
  175. *
  176. * @bl_count : No. of Bl commands submiited to CDM.
  177. * @cmd : payload holding the BL cmd's arrary
  178. * that is sumbitted.
  179. *
  180. */
  181. struct cam_cdm_bl_info {
  182. int32_t bl_count;
  183. struct cam_cdm_bl_data cmd[CAM_CDM_BL_CMD_MAX];
  184. };
  185. /**
  186. * @brief : API to get the CDM capabilities for a camera device type
  187. *
  188. * @identifier : Input pointer to a string which is the device label from dt
  189. * like vfe, ife, jpeg etc, We do not need cell index
  190. * assuming all devices of a single type maps to one SMMU
  191. * client
  192. * @cdm_handles : Input iommu handle memory pointer to update handles
  193. *
  194. * @return 0 on success
  195. */
  196. int cam_cdm_get_iommu_handle(char *identifier,
  197. struct cam_iommu_handle *cdm_handles);
  198. /**
  199. * @brief : API to acquire a CDM
  200. *
  201. * @data : Input data for the CDM to be acquired
  202. *
  203. * @return 0 on success
  204. */
  205. int cam_cdm_acquire(struct cam_cdm_acquire_data *data);
  206. /**
  207. * @brief : API to release a previously acquired CDM
  208. *
  209. * @handle : Input handle for the CDM to be released
  210. *
  211. * @return 0 on success
  212. */
  213. int cam_cdm_release(uint32_t handle);
  214. /**
  215. * @brief : API to submit the base & length (BL's) for acquired CDM
  216. *
  217. * @handle : Input cdm handle to which the BL's needs to be sumbitted.
  218. * @data : Input pointer to the BL's to be sumbitted
  219. *
  220. * @return 0 on success
  221. */
  222. int cam_cdm_submit_bls(uint32_t handle, struct cam_cdm_bl_request *data);
  223. /**
  224. * @brief : API to stream ON a previously acquired CDM,
  225. * during this we turn on/off clocks/power based on active clients.
  226. *
  227. * @handle : Input handle for the CDM to be released
  228. *
  229. * @return 0 on success
  230. */
  231. int cam_cdm_stream_on(uint32_t handle);
  232. /**
  233. * @brief : API to stream OFF a previously acquired CDM,
  234. * during this we turn on/off clocks/power based on active clients.
  235. *
  236. * @handle : Input handle for the CDM to be released
  237. *
  238. * @return 0 on success
  239. */
  240. int cam_cdm_stream_off(uint32_t handle);
  241. /**
  242. * @brief : API to reset previously acquired CDM,
  243. * this should be only performed only if the CDM is private.
  244. *
  245. * @handle : Input handle of the CDM to reset
  246. *
  247. * @return 0 on success
  248. */
  249. int cam_cdm_reset_hw(uint32_t handle);
  250. /**
  251. * @brief : API to publish CDM ops to HW blocks like IFE
  252. *
  253. * @return : CDM operations
  254. *
  255. */
  256. struct cam_cdm_utils_ops *cam_cdm_publish_ops(void);
  257. /**
  258. * @brief : API to register CDM hw to platform framework.
  259. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  260. */
  261. int cam_hw_cdm_init_module(void);
  262. /**
  263. * @brief : API to register CDM interface to platform framework.
  264. * @return struct platform_device pointer on on success, or ERR_PTR() on error.
  265. */
  266. int cam_cdm_intf_init_module(void);
  267. /**
  268. * @brief : API to remove CDM interface from platform framework.
  269. */
  270. void cam_cdm_intf_exit_module(void);
  271. /**
  272. * @brief : API to remove CDM hw from platform framework.
  273. */
  274. void cam_hw_cdm_exit_module(void);
  275. /**
  276. * @brief : API to flush previously acquired CDM,
  277. * this should be only performed only if the CDM is private.
  278. *
  279. * @handle : Input handle of the CDM to reset
  280. *
  281. * @return 0 on success
  282. */
  283. int cam_cdm_flush_hw(uint32_t handle);
  284. /**
  285. * @brief : API to detect culprit bl_tag in previously acquired CDM,
  286. * this should be only performed only if the CDM is private.
  287. *
  288. * @handle : Input handle of the CDM to reset
  289. *
  290. * @return 0 on success
  291. */
  292. int cam_cdm_handle_error(uint32_t handle);
  293. /**
  294. * @brief : API get CDM ops
  295. *
  296. * @return : CDM operations
  297. *
  298. */
  299. struct cam_cdm_utils_ops *cam_cdm_publish_ops(void);
  300. /**
  301. * @brief : API to detect hang in previously acquired CDM,
  302. * this should be only performed only if the CDM is private.
  303. *
  304. * @handle : Input handle of the CDM to detect hang
  305. *
  306. * @return 0 on success
  307. */
  308. int cam_cdm_detect_hang_error(uint32_t handle);
  309. /**
  310. * @brief : API to dump the CDM Debug registers
  311. *
  312. * @handle : Input handle of the CDM to dump the registers
  313. *
  314. * @return 0 on success
  315. */
  316. int cam_cdm_dump_debug_registers(uint32_t handle);
  317. #endif /* _CAM_CDM_API_H_ */