cam_isp_context.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_ISP_CONTEXT_H_
  6. #define _CAM_ISP_CONTEXT_H_
  7. #include <linux/spinlock.h>
  8. #include <media/cam_isp.h>
  9. #include <media/cam_defs.h>
  10. #include <media/cam_tfe.h>
  11. #include "cam_context.h"
  12. #include "cam_isp_hw_mgr_intf.h"
  13. /*
  14. * Maximum hw resource - This number is based on the maximum
  15. * output port resource. The current maximum resource number
  16. * is 24.
  17. */
  18. #define CAM_ISP_CTX_RES_MAX 24
  19. /*
  20. * Maximum configuration entry size - This is based on the
  21. * worst case DUAL IFE use case plus some margin.
  22. */
  23. #define CAM_ISP_CTX_CFG_MAX 22
  24. /*
  25. * Maximum entries in state monitoring array for error logging
  26. */
  27. #define CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES 40
  28. /* forward declaration */
  29. struct cam_isp_context;
  30. /* cam isp context irq handling function type */
  31. typedef int (*cam_isp_hw_event_cb_func)(struct cam_isp_context *ctx_isp,
  32. void *evt_data);
  33. /**
  34. * enum cam_isp_ctx_activated_substate - sub states for activated
  35. *
  36. */
  37. enum cam_isp_ctx_activated_substate {
  38. CAM_ISP_CTX_ACTIVATED_SOF,
  39. CAM_ISP_CTX_ACTIVATED_APPLIED,
  40. CAM_ISP_CTX_ACTIVATED_EPOCH,
  41. CAM_ISP_CTX_ACTIVATED_BUBBLE,
  42. CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED,
  43. CAM_ISP_CTX_ACTIVATED_HW_ERROR,
  44. CAM_ISP_CTX_ACTIVATED_HALT,
  45. CAM_ISP_CTX_ACTIVATED_MAX,
  46. };
  47. /**
  48. * enum cam_isp_state_change_trigger - Different types of ISP events
  49. *
  50. */
  51. enum cam_isp_state_change_trigger {
  52. CAM_ISP_STATE_CHANGE_TRIGGER_ERROR,
  53. CAM_ISP_STATE_CHANGE_TRIGGER_APPLIED,
  54. CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
  55. CAM_ISP_STATE_CHANGE_TRIGGER_SOF,
  56. CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH,
  57. CAM_ISP_STATE_CHANGE_TRIGGER_DONE,
  58. CAM_ISP_STATE_CHANGE_TRIGGER_EOF,
  59. CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH,
  60. CAM_ISP_STATE_CHANGE_TRIGGER_MAX
  61. };
  62. /**
  63. * struct cam_isp_ctx_debug - Contains debug parameters
  64. *
  65. * @dentry: Debugfs entry
  66. * @enable_state_monitor_dump: Enable isp state monitor dump
  67. *
  68. */
  69. struct cam_isp_ctx_debug {
  70. struct dentry *dentry;
  71. uint32_t enable_state_monitor_dump;
  72. };
  73. /**
  74. * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks
  75. *
  76. * @irq_ops: Array of handle function pointers.
  77. *
  78. */
  79. struct cam_isp_ctx_irq_ops {
  80. cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX];
  81. };
  82. /**
  83. * struct cam_isp_ctx_req - ISP context request object
  84. *
  85. * @base: Common request object ponter
  86. * @cfg: ISP hardware configuration array
  87. * @num_cfg: Number of ISP hardware configuration entries
  88. * @fence_map_out: Output fence mapping array
  89. * @num_fence_map_out: Number of the output fence map
  90. * @fence_map_in: Input fence mapping array
  91. * @num_fence_map_in: Number of input fence map
  92. * @num_acked: Count to track acked entried for output.
  93. * If count equals the number of fence out, it means
  94. * the request has been completed.
  95. * @bubble_report: Flag to track if bubble report is active on
  96. * current request
  97. * @hw_update_data: HW update data for this request
  98. * @reapply: True if reapplying after bubble
  99. *
  100. */
  101. struct cam_isp_ctx_req {
  102. struct cam_ctx_request *base;
  103. struct cam_hw_update_entry cfg[CAM_ISP_CTX_CFG_MAX];
  104. uint32_t num_cfg;
  105. struct cam_hw_fence_map_entry fence_map_out
  106. [CAM_ISP_CTX_RES_MAX];
  107. uint32_t num_fence_map_out;
  108. struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX];
  109. uint32_t num_fence_map_in;
  110. uint32_t num_acked;
  111. int32_t bubble_report;
  112. struct cam_isp_prepare_hw_update_data hw_update_data;
  113. bool bubble_detected;
  114. bool reapply;
  115. };
  116. /**
  117. * struct cam_isp_context_state_monitor - ISP context state
  118. * monitoring for
  119. * debug purposes
  120. *
  121. * @curr_state: Current sub state that received req
  122. * @trigger: Event type of incoming req
  123. * @req_id: Request id
  124. * @frame_id: Frame id based on SOFs
  125. * @evt_time_stamp Current time stamp
  126. *
  127. */
  128. struct cam_isp_context_state_monitor {
  129. enum cam_isp_ctx_activated_substate curr_state;
  130. enum cam_isp_state_change_trigger trigger;
  131. uint64_t req_id;
  132. int64_t frame_id;
  133. unsigned int evt_time_stamp;
  134. };
  135. /**
  136. * struct cam_isp_context - ISP context object
  137. *
  138. * @base: Common context object pointer
  139. * @frame_id: Frame id tracking for the isp context
  140. * @substate_actiavted: Current substate for the activated state.
  141. * @process_bubble: Atomic variable to check if ctx is still
  142. * processing bubble.
  143. * @bubble_frame_cnt: Count number of frames since the req is in bubble
  144. * @substate_machine: ISP substate machine for external interface
  145. * @substate_machine_irq: ISP substate machine for irq handling
  146. * @req_base: Common request object storage
  147. * @req_isp: ISP private request object storage
  148. * @hw_ctx: HW object returned by the acquire device command
  149. * @sof_timestamp_val: Captured time stamp value at sof hw event
  150. * @boot_timestamp: Boot time stamp for a given req_id
  151. * @active_req_cnt: Counter for the active request
  152. * @reported_req_id: Last reported request id
  153. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  154. * will invoke CRM cb at those event.
  155. * @last_applied_req_id: Last applied request id
  156. * @state_monitor_head: Write index to the state monitoring array
  157. * @cam_isp_ctx_state_monitor: State monitoring array
  158. * @rdi_only_context: Get context type information.
  159. * true, if context is rdi only context
  160. * @hw_acquired: Indicate whether HW resources are acquired
  161. * @init_received: Indicate whether init config packet is received
  162. * @split_acquire: Indicate whether a separate acquire is expected
  163. * @init_timestamp: Timestamp at which this context is initialized
  164. * @isp_device_type ISP device type
  165. *
  166. */
  167. struct cam_isp_context {
  168. struct cam_context *base;
  169. int64_t frame_id;
  170. enum cam_isp_ctx_activated_substate substate_activated;
  171. atomic_t process_bubble;
  172. uint32_t bubble_frame_cnt;
  173. struct cam_ctx_ops *substate_machine;
  174. struct cam_isp_ctx_irq_ops *substate_machine_irq;
  175. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  176. struct cam_isp_ctx_req req_isp[CAM_CTX_REQ_MAX];
  177. void *hw_ctx;
  178. uint64_t sof_timestamp_val;
  179. uint64_t boot_timestamp;
  180. int32_t active_req_cnt;
  181. int64_t reported_req_id;
  182. uint32_t subscribe_event;
  183. int64_t last_applied_req_id;
  184. atomic64_t state_monitor_head;
  185. struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
  186. CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
  187. bool rdi_only_context;
  188. bool hw_acquired;
  189. bool init_received;
  190. bool split_acquire;
  191. unsigned int init_timestamp;
  192. uint32_t isp_device_type;
  193. };
  194. /**
  195. * cam_isp_context_init()
  196. *
  197. * @brief: Initialization function for the ISP context
  198. *
  199. * @ctx: ISP context obj to be initialized
  200. * @bridge_ops: Bridge call back funciton
  201. * @hw_intf: ISP hw manager interface
  202. * @ctx_id: ID for this context
  203. * @isp_device_type Isp device type
  204. *
  205. */
  206. int cam_isp_context_init(struct cam_isp_context *ctx,
  207. struct cam_context *ctx_base,
  208. struct cam_req_mgr_kmd_ops *bridge_ops,
  209. struct cam_hw_mgr_intf *hw_intf,
  210. uint32_t ctx_id,
  211. uint32_t isp_device_type);
  212. /**
  213. * cam_isp_context_deinit()
  214. *
  215. * @brief: Deinitialize function for the ISP context
  216. *
  217. * @ctx: ISP context obj to be deinitialized
  218. *
  219. */
  220. int cam_isp_context_deinit(struct cam_isp_context *ctx);
  221. #endif /* __CAM_ISP_CONTEXT_H__ */