cam_cdm_intf_api.h 8.0 KB

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