cam_cdm_intf_api.h 9.9 KB

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