cam_isp_context.h 8.2 KB

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