cam_cdm_intf_api.h 9.6 KB

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