cam_cdm_intf_api.h 8.7 KB

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