cam_isp_context.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. *
  98. */
  99. struct cam_isp_ctx_req {
  100. struct cam_ctx_request *base;
  101. struct cam_hw_update_entry cfg[CAM_ISP_CTX_CFG_MAX];
  102. uint32_t num_cfg;
  103. struct cam_hw_fence_map_entry fence_map_out
  104. [CAM_ISP_CTX_RES_MAX];
  105. uint32_t num_fence_map_out;
  106. struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX];
  107. uint32_t num_fence_map_in;
  108. uint32_t num_acked;
  109. int32_t bubble_report;
  110. struct cam_isp_prepare_hw_update_data hw_update_data;
  111. bool bubble_detected;
  112. };
  113. /**
  114. * struct cam_isp_context_state_monitor - ISP context state
  115. * monitoring for
  116. * debug purposes
  117. *
  118. * @curr_state: Current sub state that received req
  119. * @trigger: Event type of incoming req
  120. * @req_id: Request id
  121. * @frame_id: Frame id based on SOFs
  122. * @evt_time_stamp Current time stamp
  123. *
  124. */
  125. struct cam_isp_context_state_monitor {
  126. enum cam_isp_ctx_activated_substate curr_state;
  127. enum cam_isp_state_change_trigger trigger;
  128. uint64_t req_id;
  129. int64_t frame_id;
  130. unsigned int evt_time_stamp;
  131. };
  132. /**
  133. * struct cam_isp_context - ISP context object
  134. *
  135. * @base: Common context object pointer
  136. * @frame_id: Frame id tracking for the isp context
  137. * @substate_actiavted: Current substate for the activated state.
  138. * @process_bubble: Atomic variable to check if ctx is still
  139. * processing bubble.
  140. * @substate_machine: ISP substate machine for external interface
  141. * @substate_machine_irq: ISP substate machine for irq handling
  142. * @req_base: Common request object storage
  143. * @req_isp: ISP private request object storage
  144. * @hw_ctx: HW object returned by the acquire device command
  145. * @sof_timestamp_val: Captured time stamp value at sof hw event
  146. * @boot_timestamp: Boot time stamp for a given req_id
  147. * @active_req_cnt: Counter for the active request
  148. * @reported_req_id: Last reported request id
  149. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  150. * will invoke CRM cb at those event.
  151. * @last_applied_req_id: Last applied request id
  152. * @state_monitor_head: Write index to the state monitoring array
  153. * @cam_isp_ctx_state_monitor: State monitoring array
  154. * @rdi_only_context: Get context type information.
  155. * true, if context is rdi only context
  156. * @hw_acquired: Indicate whether HW resources are acquired
  157. * @init_received: Indicate whether init config packet is received
  158. * @split_acquire: Indicate whether a separate acquire is expected
  159. * @init_timestamp: Timestamp at which this context is initialized
  160. *
  161. */
  162. struct cam_isp_context {
  163. struct cam_context *base;
  164. int64_t frame_id;
  165. uint32_t substate_activated;
  166. atomic_t process_bubble;
  167. struct cam_ctx_ops *substate_machine;
  168. struct cam_isp_ctx_irq_ops *substate_machine_irq;
  169. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  170. struct cam_isp_ctx_req req_isp[CAM_CTX_REQ_MAX];
  171. void *hw_ctx;
  172. uint64_t sof_timestamp_val;
  173. uint64_t boot_timestamp;
  174. int32_t active_req_cnt;
  175. int64_t reported_req_id;
  176. uint32_t subscribe_event;
  177. int64_t last_applied_req_id;
  178. atomic64_t state_monitor_head;
  179. struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
  180. CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
  181. bool rdi_only_context;
  182. bool hw_acquired;
  183. bool init_received;
  184. bool split_acquire;
  185. unsigned int init_timestamp;
  186. };
  187. /**
  188. * cam_isp_context_init()
  189. *
  190. * @brief: Initialization function for the ISP context
  191. *
  192. * @ctx: ISP context obj to be initialized
  193. * @bridge_ops: Bridge call back funciton
  194. * @hw_intf: ISP hw manager interface
  195. * @ctx_id: ID for this context
  196. *
  197. */
  198. int cam_isp_context_init(struct cam_isp_context *ctx,
  199. struct cam_context *ctx_base,
  200. struct cam_req_mgr_kmd_ops *bridge_ops,
  201. struct cam_hw_mgr_intf *hw_intf,
  202. uint32_t ctx_id);
  203. /**
  204. * cam_isp_context_deinit()
  205. *
  206. * @brief: Deinitialize function for the ISP context
  207. *
  208. * @ctx: ISP context obj to be deinitialized
  209. *
  210. */
  211. int cam_isp_context_deinit(struct cam_isp_context *ctx);
  212. #endif /* __CAM_ISP_CONTEXT_H__ */