cam_isp_context.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. #include "cam_req_mgr_workq.h"
  14. #define CAM_IFE_QTIMER_MUL_FACTOR 10000
  15. #define CAM_IFE_QTIMER_DIV_FACTOR 192
  16. /*
  17. * Maximum hw resource - This number is based on the maximum
  18. * output port resource. The current maximum resource number
  19. * is 24.
  20. */
  21. #define CAM_ISP_CTX_RES_MAX 24
  22. /*
  23. * Maximum entries in state monitoring array for error logging
  24. */
  25. #define CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES 40
  26. /*
  27. * Threshold response time in us beyond which a request is not expected
  28. * to be with IFE hw
  29. */
  30. #define CAM_ISP_CTX_RESPONSE_TIME_THRESHOLD 100000
  31. /* Number of words for dumping isp context */
  32. #define CAM_ISP_CTX_DUMP_NUM_WORDS 5
  33. /* Number of words for dumping isp context events*/
  34. #define CAM_ISP_CTX_DUMP_EVENT_NUM_WORDS 3
  35. /* Number of words for dumping request info*/
  36. #define CAM_ISP_CTX_DUMP_REQUEST_NUM_WORDS 2
  37. /* Maximum entries in event record */
  38. #define CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES 20
  39. /* Maximum length of tag while dumping */
  40. #define CAM_ISP_CONTEXT_DUMP_TAG_MAX_LEN 32
  41. /* forward declaration */
  42. struct cam_isp_context;
  43. /* cam isp context irq handling function type */
  44. typedef int (*cam_isp_hw_event_cb_func)(struct cam_isp_context *ctx_isp,
  45. void *evt_data);
  46. /**
  47. * enum cam_isp_ctx_activated_substate - sub states for activated
  48. *
  49. */
  50. enum cam_isp_ctx_activated_substate {
  51. CAM_ISP_CTX_ACTIVATED_SOF,
  52. CAM_ISP_CTX_ACTIVATED_APPLIED,
  53. CAM_ISP_CTX_ACTIVATED_EPOCH,
  54. CAM_ISP_CTX_ACTIVATED_BUBBLE,
  55. CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED,
  56. CAM_ISP_CTX_ACTIVATED_HW_ERROR,
  57. CAM_ISP_CTX_ACTIVATED_HALT,
  58. CAM_ISP_CTX_ACTIVATED_MAX,
  59. };
  60. /**
  61. * enum cam_isp_ctx_event_type - events for a request
  62. *
  63. */
  64. enum cam_isp_ctx_event {
  65. CAM_ISP_CTX_EVENT_SUBMIT,
  66. CAM_ISP_CTX_EVENT_APPLY,
  67. CAM_ISP_CTX_EVENT_EPOCH,
  68. CAM_ISP_CTX_EVENT_RUP,
  69. CAM_ISP_CTX_EVENT_BUFDONE,
  70. CAM_ISP_CTX_EVENT_MAX
  71. };
  72. /**
  73. * enum cam_isp_state_change_trigger - Different types of ISP events
  74. *
  75. */
  76. enum cam_isp_state_change_trigger {
  77. CAM_ISP_STATE_CHANGE_TRIGGER_ERROR,
  78. CAM_ISP_STATE_CHANGE_TRIGGER_APPLIED,
  79. CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
  80. CAM_ISP_STATE_CHANGE_TRIGGER_SOF,
  81. CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH,
  82. CAM_ISP_STATE_CHANGE_TRIGGER_DONE,
  83. CAM_ISP_STATE_CHANGE_TRIGGER_EOF,
  84. CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH,
  85. CAM_ISP_STATE_CHANGE_TRIGGER_MAX
  86. };
  87. /**
  88. * struct cam_isp_ctx_debug - Contains debug parameters
  89. *
  90. * @dentry: Debugfs entry
  91. * @enable_state_monitor_dump: Enable isp state monitor dump
  92. *
  93. */
  94. struct cam_isp_ctx_debug {
  95. struct dentry *dentry;
  96. uint32_t enable_state_monitor_dump;
  97. };
  98. /**
  99. * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks
  100. *
  101. * @irq_ops: Array of handle function pointers.
  102. *
  103. */
  104. struct cam_isp_ctx_irq_ops {
  105. cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX];
  106. };
  107. /**
  108. * struct cam_isp_ctx_req - ISP context request object
  109. *
  110. * @base: Common request object ponter
  111. * @cfg_info: ISP hardware configuration array
  112. * @total_num_cfg: Number of ISP hardware configuration entries
  113. * @fence_map_out: Output fence mapping array
  114. * @num_fence_map_out: Number of the output fence map
  115. * @fence_map_in: Input fence mapping array
  116. * @num_fence_map_in: Number of input fence map
  117. * @num_acked: Count to track acked entried for output.
  118. * If count equals the number of fence out, it means
  119. * the request has been completed.
  120. * @bubble_report: Flag to track if bubble report is active on
  121. * current request
  122. * @hw_update_data: HW update data for this request
  123. * @event_timestamp: Timestamp for different stage of request
  124. * @reapply: True if reapplying after bubble
  125. *
  126. */
  127. struct cam_isp_ctx_req {
  128. struct cam_ctx_request *base;
  129. struct cam_isp_hw_update_info cfg_info[CAM_IFE_HW_NUM_MAX];
  130. uint32_t total_num_cfg;
  131. struct cam_hw_fence_map_entry fence_map_out
  132. [CAM_ISP_CTX_RES_MAX];
  133. uint32_t num_fence_map_out;
  134. struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX];
  135. uint32_t num_fence_map_in;
  136. uint32_t num_acked;
  137. int32_t bubble_report;
  138. struct cam_isp_prepare_hw_update_data hw_update_data;
  139. ktime_t event_timestamp
  140. [CAM_ISP_CTX_EVENT_MAX];
  141. bool bubble_detected;
  142. bool reapply;
  143. };
  144. /**
  145. * struct cam_isp_context_state_monitor - ISP context state
  146. * monitoring for
  147. * debug purposes
  148. *
  149. * @curr_state: Current sub state that received req
  150. * @trigger: Event type of incoming req
  151. * @req_id: Request id
  152. * @frame_id: Frame id based on SOFs
  153. * @evt_time_stamp Current time stamp
  154. *
  155. */
  156. struct cam_isp_context_state_monitor {
  157. enum cam_isp_ctx_activated_substate curr_state;
  158. enum cam_isp_state_change_trigger trigger;
  159. uint64_t req_id;
  160. int64_t frame_id;
  161. unsigned int evt_time_stamp;
  162. };
  163. /**
  164. * struct cam_isp_context_req_id_info - ISP context request id
  165. * information for bufdone.
  166. *
  167. *@last_bufdone_req_id: Last bufdone request id
  168. *
  169. */
  170. struct cam_isp_context_req_id_info {
  171. int64_t last_bufdone_req_id;
  172. };
  173. /**
  174. *
  175. *
  176. * struct cam_isp_context_event_record - Information for last 20 Events
  177. * for a request; Submit, Apply, EPOCH, RUP, Buf done.
  178. *
  179. * @req_id: Last applied request id
  180. * @timestamp: Timestamp for the event
  181. *
  182. */
  183. struct cam_isp_context_event_record {
  184. uint64_t req_id;
  185. ktime_t timestamp;
  186. };
  187. /**
  188. * struct cam_isp_context - ISP context object
  189. *
  190. * @base: Common context object pointer
  191. * @frame_id: Frame id tracking for the isp context
  192. * @frame_id_meta: Frame id read every epoch for the ctx
  193. * meta from the sensor
  194. * @substate_actiavted: Current substate for the activated state.
  195. * @process_bubble: Atomic variable to check if ctx is still
  196. * processing bubble.
  197. * @bubble_frame_cnt: Count number of frames since the req is in bubble
  198. * @substate_machine: ISP substate machine for external interface
  199. * @substate_machine_irq: ISP substate machine for irq handling
  200. * @req_base: Common request object storage
  201. * @req_isp: ISP private request object storage
  202. * @hw_ctx: HW object returned by the acquire device command
  203. * @sof_timestamp_val: Captured time stamp value at sof hw event
  204. * @boot_timestamp: Boot time stamp for a given req_id
  205. * @active_req_cnt: Counter for the active request
  206. * @reported_req_id: Last reported request id
  207. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  208. * will invoke CRM cb at those event.
  209. * @last_applied_req_id: Last applied request id
  210. * @state_monitor_head: Write index to the state monitoring array
  211. * @req_info Request id information about last buf done
  212. * @cam_isp_ctx_state_monitor: State monitoring array
  213. * @event_record_head: Write index to the state monitoring array
  214. * @event_record: Event record array
  215. * @rdi_only_context: Get context type information.
  216. * true, if context is rdi only context
  217. * @offline_context: Indicate whether context is for offline IFE
  218. * @hw_acquired: Indicate whether HW resources are acquired
  219. * @init_received: Indicate whether init config packet is received
  220. * @split_acquire: Indicate whether a separate acquire is expected
  221. * @custom_enabled: Custom HW enabled for this ctx
  222. * @use_frame_header_ts: Use frame header for qtimer ts
  223. * @init_timestamp: Timestamp at which this context is initialized
  224. * @isp_device_type: ISP device type
  225. * @rxd_epoch: Indicate whether epoch has been received. Used to
  226. * decide whether to apply request in offline ctx
  227. * @workq: Worker thread for offline ife
  228. * @trigger_id: ID provided by CRM for each ctx on the link
  229. *
  230. */
  231. struct cam_isp_context {
  232. struct cam_context *base;
  233. int64_t frame_id;
  234. uint32_t frame_id_meta;
  235. uint32_t substate_activated;
  236. atomic_t process_bubble;
  237. uint32_t bubble_frame_cnt;
  238. struct cam_ctx_ops *substate_machine;
  239. struct cam_isp_ctx_irq_ops *substate_machine_irq;
  240. struct cam_ctx_request req_base[CAM_CTX_REQ_MAX];
  241. struct cam_isp_ctx_req req_isp[CAM_CTX_REQ_MAX];
  242. void *hw_ctx;
  243. uint64_t sof_timestamp_val;
  244. uint64_t boot_timestamp;
  245. int32_t active_req_cnt;
  246. int64_t reported_req_id;
  247. uint32_t subscribe_event;
  248. int64_t last_applied_req_id;
  249. atomic64_t state_monitor_head;
  250. struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
  251. CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
  252. struct cam_isp_context_req_id_info req_info;
  253. atomic64_t event_record_head[
  254. CAM_ISP_CTX_EVENT_MAX];
  255. struct cam_isp_context_event_record event_record[
  256. CAM_ISP_CTX_EVENT_MAX][CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES];
  257. bool rdi_only_context;
  258. bool offline_context;
  259. bool hw_acquired;
  260. bool init_received;
  261. bool split_acquire;
  262. bool custom_enabled;
  263. bool use_frame_header_ts;
  264. unsigned int init_timestamp;
  265. uint32_t isp_device_type;
  266. atomic_t rxd_epoch;
  267. struct cam_req_mgr_core_workq *workq;
  268. int32_t trigger_id;
  269. };
  270. /**
  271. * struct cam_isp_context_dump_header - ISP context dump header
  272. * @tag: Tag name for the header
  273. * @word_size: Size of word
  274. * @size: Size of data
  275. *
  276. */
  277. struct cam_isp_context_dump_header {
  278. uint8_t tag[CAM_ISP_CONTEXT_DUMP_TAG_MAX_LEN];
  279. uint64_t size;
  280. uint32_t word_size;
  281. };
  282. /**
  283. * cam_isp_context_init()
  284. *
  285. * @brief: Initialization function for the ISP context
  286. *
  287. * @ctx: ISP context obj to be initialized
  288. * @bridge_ops: Bridge call back funciton
  289. * @hw_intf: ISP hw manager interface
  290. * @ctx_id: ID for this context
  291. * @isp_device_type Isp device type
  292. *
  293. */
  294. int cam_isp_context_init(struct cam_isp_context *ctx,
  295. struct cam_context *ctx_base,
  296. struct cam_req_mgr_kmd_ops *bridge_ops,
  297. struct cam_hw_mgr_intf *hw_intf,
  298. uint32_t ctx_id,
  299. uint32_t isp_device_type);
  300. /**
  301. * cam_isp_context_deinit()
  302. *
  303. * @brief: Deinitialize function for the ISP context
  304. *
  305. * @ctx: ISP context obj to be deinitialized
  306. *
  307. */
  308. int cam_isp_context_deinit(struct cam_isp_context *ctx);
  309. #endif /* __CAM_ISP_CONTEXT_H__ */