cam_isp_context.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_ISP_CONTEXT_H_
  6. #define _CAM_ISP_CONTEXT_H_
  7. #include <linux/spinlock_types.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. /* max requests per ctx for isp */
  23. #define CAM_ISP_CTX_REQ_MAX 8
  24. /*
  25. * Maximum entries in state monitoring array for error logging
  26. */
  27. #define CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES 40
  28. /*
  29. * Threshold response time in us beyond which a request is not expected
  30. * to be with IFE hw
  31. */
  32. #define CAM_ISP_CTX_RESPONSE_TIME_THRESHOLD 100000
  33. /* Number of words for dumping isp context */
  34. #define CAM_ISP_CTX_DUMP_NUM_WORDS 5
  35. /* Number of words for dumping isp context events*/
  36. #define CAM_ISP_CTX_DUMP_EVENT_NUM_WORDS 3
  37. /* Number of words for dumping request info*/
  38. #define CAM_ISP_CTX_DUMP_REQUEST_NUM_WORDS 2
  39. /* Maximum entries in event record */
  40. #define CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES 20
  41. /* Maximum length of tag while dumping */
  42. #define CAM_ISP_CONTEXT_DUMP_TAG_MAX_LEN 32
  43. /* forward declaration */
  44. struct cam_isp_context;
  45. /* cam isp context irq handling function type */
  46. typedef int (*cam_isp_hw_event_cb_func)(struct cam_isp_context *ctx_isp,
  47. void *evt_data);
  48. /**
  49. * enum cam_isp_ctx_activated_substate - sub states for activated
  50. *
  51. */
  52. enum cam_isp_ctx_activated_substate {
  53. CAM_ISP_CTX_ACTIVATED_SOF,
  54. CAM_ISP_CTX_ACTIVATED_APPLIED,
  55. CAM_ISP_CTX_ACTIVATED_EPOCH,
  56. CAM_ISP_CTX_ACTIVATED_BUBBLE,
  57. CAM_ISP_CTX_ACTIVATED_BUBBLE_APPLIED,
  58. CAM_ISP_CTX_ACTIVATED_HW_ERROR,
  59. CAM_ISP_CTX_ACTIVATED_HALT,
  60. CAM_ISP_CTX_ACTIVATED_MAX,
  61. };
  62. /**
  63. * enum cam_isp_ctx_event_type - events for a request
  64. *
  65. */
  66. enum cam_isp_ctx_event {
  67. CAM_ISP_CTX_EVENT_SUBMIT,
  68. CAM_ISP_CTX_EVENT_APPLY,
  69. CAM_ISP_CTX_EVENT_EPOCH,
  70. CAM_ISP_CTX_EVENT_RUP,
  71. CAM_ISP_CTX_EVENT_BUFDONE,
  72. CAM_ISP_CTX_EVENT_MAX
  73. };
  74. /**
  75. * enum cam_isp_state_change_trigger - Different types of ISP events
  76. *
  77. */
  78. enum cam_isp_state_change_trigger {
  79. CAM_ISP_STATE_CHANGE_TRIGGER_ERROR,
  80. CAM_ISP_STATE_CHANGE_TRIGGER_APPLIED,
  81. CAM_ISP_STATE_CHANGE_TRIGGER_REG_UPDATE,
  82. CAM_ISP_STATE_CHANGE_TRIGGER_SOF,
  83. CAM_ISP_STATE_CHANGE_TRIGGER_EPOCH,
  84. CAM_ISP_STATE_CHANGE_TRIGGER_DONE,
  85. CAM_ISP_STATE_CHANGE_TRIGGER_EOF,
  86. CAM_ISP_STATE_CHANGE_TRIGGER_FLUSH,
  87. CAM_ISP_STATE_CHANGE_TRIGGER_MAX
  88. };
  89. /**
  90. * struct cam_isp_ctx_debug - Contains debug parameters
  91. *
  92. * @dentry: Debugfs entry
  93. * @enable_state_monitor_dump: Enable isp state monitor dump
  94. * @enable_cdm_cmd_buff_dump: Enable CDM Command buffer dump
  95. *
  96. */
  97. struct cam_isp_ctx_debug {
  98. struct dentry *dentry;
  99. uint32_t enable_state_monitor_dump;
  100. uint8_t enable_cdm_cmd_buff_dump;
  101. };
  102. /**
  103. * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks
  104. *
  105. * @irq_ops: Array of handle function pointers.
  106. *
  107. */
  108. struct cam_isp_ctx_irq_ops {
  109. cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX];
  110. };
  111. /**
  112. * struct cam_isp_ctx_req - ISP context request object
  113. *
  114. * @base: Common request object ponter
  115. * @cfg: ISP hardware configuration array
  116. * @num_cfg: Number of ISP hardware configuration entries
  117. * @fence_map_out: Output fence mapping array
  118. * @num_fence_map_out: Number of the output fence map
  119. * @fence_map_in: Input fence mapping array
  120. * @num_fence_map_in: Number of input fence map
  121. * @num_acked: Count to track acked entried for output.
  122. * If count equals the number of fence out, it means
  123. * the request has been completed.
  124. * @num_deferred_acks: Number of buf_dones/acks that are deferred to
  125. * handle or signalled in special scenarios.
  126. * Increment this count instead of num_acked and
  127. * handle the events later where eventually
  128. * increment num_acked.
  129. * @deferred_fence_map_index Saves the indices of fence_map_out for which
  130. * handling of buf_done is deferred.
  131. * @bubble_report: Flag to track if bubble report is active on
  132. * current request
  133. * @hw_update_data: HW update data for this request
  134. * @event_timestamp: Timestamp for different stage of request
  135. * @reapply: True if reapplying after bubble
  136. * @cdm_reset_before_apply: For bubble re-apply when buf done not coming set
  137. * to True
  138. *
  139. */
  140. struct cam_isp_ctx_req {
  141. struct cam_ctx_request *base;
  142. struct cam_hw_update_entry *cfg;
  143. uint32_t num_cfg;
  144. struct cam_hw_fence_map_entry *fence_map_out;
  145. uint32_t num_fence_map_out;
  146. struct cam_hw_fence_map_entry *fence_map_in;
  147. uint32_t num_fence_map_in;
  148. uint32_t num_acked;
  149. uint32_t num_deferred_acks;
  150. uint32_t deferred_fence_map_index[CAM_ISP_CTX_RES_MAX];
  151. int32_t bubble_report;
  152. struct cam_isp_prepare_hw_update_data hw_update_data;
  153. ktime_t event_timestamp
  154. [CAM_ISP_CTX_EVENT_MAX];
  155. bool bubble_detected;
  156. bool reapply;
  157. bool cdm_reset_before_apply;
  158. };
  159. /**
  160. * struct cam_isp_context_state_monitor - ISP context state
  161. * monitoring for
  162. * debug purposes
  163. *
  164. * @curr_state: Current sub state that received req
  165. * @trigger: Event type of incoming req
  166. * @req_id: Request id
  167. * @frame_id: Frame id based on SOFs
  168. * @evt_time_stamp Current time stamp
  169. *
  170. */
  171. struct cam_isp_context_state_monitor {
  172. enum cam_isp_ctx_activated_substate curr_state;
  173. enum cam_isp_state_change_trigger trigger;
  174. uint64_t req_id;
  175. int64_t frame_id;
  176. unsigned int evt_time_stamp;
  177. };
  178. /**
  179. * struct cam_isp_context_req_id_info - ISP context request id
  180. * information for bufdone.
  181. *
  182. *@last_bufdone_req_id: Last bufdone request id
  183. *
  184. */
  185. struct cam_isp_context_req_id_info {
  186. int64_t last_bufdone_req_id;
  187. };
  188. /**
  189. *
  190. *
  191. * struct cam_isp_context_event_record - Information for last 20 Events
  192. * for a request; Submit, Apply, EPOCH, RUP, Buf done.
  193. *
  194. * @req_id: Last applied request id
  195. * @timestamp: Timestamp for the event
  196. *
  197. */
  198. struct cam_isp_context_event_record {
  199. uint64_t req_id;
  200. ktime_t timestamp;
  201. };
  202. /**
  203. * struct cam_isp_context - ISP context object
  204. *
  205. * @base: Common context object pointer
  206. * @frame_id: Frame id tracking for the isp context
  207. * @frame_id_meta: Frame id read every epoch for the ctx
  208. * meta from the sensor
  209. * @substate_actiavted: Current substate for the activated state.
  210. * @process_bubble: Atomic variable to check if ctx is still
  211. * processing bubble.
  212. * @substate_machine: ISP substate machine for external interface
  213. * @substate_machine_irq: ISP substate machine for irq handling
  214. * @req_base: Common request object storage
  215. * @req_isp: ISP private request object storage
  216. * @hw_ctx: HW object returned by the acquire device command
  217. * @sof_timestamp_val: Captured time stamp value at sof hw event
  218. * @boot_timestamp: Boot time stamp for a given req_id
  219. * @active_req_cnt: Counter for the active request
  220. * @reported_req_id: Last reported request id
  221. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  222. * will invoke CRM cb at those event.
  223. * @last_applied_req_id: Last applied request id
  224. * @last_sof_timestamp: SOF timestamp of the last frame
  225. * @bubble_frame_cnt: Count of the frame after bubble
  226. * @state_monitor_head: Write index to the state monitoring array
  227. * @req_info Request id information about last buf done
  228. * @cam_isp_ctx_state_monitor: State monitoring array
  229. * @event_record_head: Write index to the state monitoring array
  230. * @event_record: Event record array
  231. * @rdi_only_context: Get context type information.
  232. * true, if context is rdi only context
  233. * @offline_context: Indicate whether context is for offline IFE
  234. * @hw_acquired: Indicate whether HW resources are acquired
  235. * @init_received: Indicate whether init config packet is received
  236. * @split_acquire: Indicate whether a separate acquire is expected
  237. * @custom_enabled: Custom HW enabled for this ctx
  238. * @use_frame_header_ts: Use frame header for qtimer ts
  239. * @support_consumed_addr: Indicate whether HW has last consumed addr reg
  240. * @aeb_enabled: Indicate if stream is for AEB
  241. * @apply_in_progress Whether request apply is in progress
  242. * @use_default_apply: Use default settings in case of frame skip
  243. * @init_timestamp: Timestamp at which this context is initialized
  244. * @isp_device_type: ISP device type
  245. * @rxd_epoch: Indicate whether epoch has been received. Used to
  246. * decide whether to apply request in offline ctx
  247. * @workq: Worker thread for offline ife
  248. * @trigger_id: ID provided by CRM for each ctx on the link
  249. * @last_bufdone_err_apply_req_id: last bufdone error apply request id
  250. * @v4l2_event_sub_ids contains individual bits representing subscribed v4l2 ids
  251. *
  252. */
  253. struct cam_isp_context {
  254. struct cam_context *base;
  255. int64_t frame_id;
  256. uint32_t frame_id_meta;
  257. uint32_t substate_activated;
  258. atomic_t process_bubble;
  259. struct cam_ctx_ops *substate_machine;
  260. struct cam_isp_ctx_irq_ops *substate_machine_irq;
  261. struct cam_ctx_request req_base[CAM_ISP_CTX_REQ_MAX];
  262. struct cam_isp_ctx_req req_isp[CAM_ISP_CTX_REQ_MAX];
  263. void *hw_ctx;
  264. uint64_t sof_timestamp_val;
  265. uint64_t boot_timestamp;
  266. int32_t active_req_cnt;
  267. int64_t reported_req_id;
  268. uint32_t subscribe_event;
  269. int64_t last_applied_req_id;
  270. uint64_t last_sof_timestamp;
  271. uint32_t bubble_frame_cnt;
  272. atomic64_t state_monitor_head;
  273. struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
  274. CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
  275. struct cam_isp_context_req_id_info req_info;
  276. atomic64_t event_record_head[
  277. CAM_ISP_CTX_EVENT_MAX];
  278. struct cam_isp_context_event_record event_record[
  279. CAM_ISP_CTX_EVENT_MAX][CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES];
  280. bool rdi_only_context;
  281. bool offline_context;
  282. bool hw_acquired;
  283. bool init_received;
  284. bool split_acquire;
  285. bool custom_enabled;
  286. bool use_frame_header_ts;
  287. bool support_consumed_addr;
  288. bool aeb_enabled;
  289. atomic_t apply_in_progress;
  290. bool use_default_apply;
  291. unsigned int init_timestamp;
  292. uint32_t isp_device_type;
  293. atomic_t rxd_epoch;
  294. struct cam_req_mgr_core_workq *workq;
  295. int32_t trigger_id;
  296. int64_t last_bufdone_err_apply_req_id;
  297. uint32_t v4l2_event_sub_ids;
  298. };
  299. /**
  300. * struct cam_isp_context_dump_header - ISP context dump header
  301. * @tag: Tag name for the header
  302. * @word_size: Size of word
  303. * @size: Size of data
  304. *
  305. */
  306. struct cam_isp_context_dump_header {
  307. uint8_t tag[CAM_ISP_CONTEXT_DUMP_TAG_MAX_LEN];
  308. uint64_t size;
  309. uint32_t word_size;
  310. };
  311. /** * struct cam_isp_ctx_req_mini_dump - ISP mini dumprequest
  312. *
  313. * @map_out: Output fence mapping
  314. * @map_in: Input fence mapping
  315. * @io_cfg: IO buffer configuration
  316. * @request_id: Request ID
  317. * @num_fence_map_out: Number of the output fence map
  318. * @num_fence_map_in: Number of input fence map
  319. * @num_io_cfg: Number of ISP hardware configuration entries
  320. * @num_acked: Count to track acked entried for output.
  321. * @num_deferred_acks: Number of buf_dones/acks that are deferred to
  322. * handle or signalled in special scenarios.
  323. * Increment this count instead of num_acked and
  324. * handle the events later where eventually
  325. * increment num_acked.
  326. * @bubble_report: Flag to track if bubble report is active on
  327. * current request
  328. * @bubble_detected: Flag to track if bubble is detected
  329. * @reapply: True if reapplying after bubble
  330. * @cdm_reset_before_apply: For bubble re-apply when buf done not coming set
  331. * to True
  332. *
  333. */
  334. struct cam_isp_ctx_req_mini_dump {
  335. struct cam_hw_fence_map_entry *map_out;
  336. struct cam_hw_fence_map_entry *map_in;
  337. struct cam_buf_io_cfg *io_cfg;
  338. uint64_t request_id;
  339. uint8_t num_fence_map_in;
  340. uint8_t num_fence_map_out;
  341. uint8_t num_io_cfg;
  342. uint8_t num_acked;
  343. uint8_t num_deferred_acks;
  344. bool bubble_report;
  345. bool bubble_detected;
  346. bool reapply;
  347. bool cdm_reset_before_apply;
  348. };
  349. /**
  350. * struct cam_isp_ctx_mini_dump_info - Isp context mini dump data
  351. *
  352. * @active_list: Active Req list
  353. * @pending_list: Pending req list
  354. * @wait_list: Wait Req List
  355. * @event_record: Event record
  356. * @sof_timestamp_val: Captured time stamp value at sof hw event
  357. * @boot_timestamp: Boot time stamp for a given req_id
  358. * @last_sof_timestamp: SOF timestamp of the last frame
  359. * @init_timestamp: Timestamp at which this context is initialized
  360. * @frame_id: Frame id read every epoch for the ctx
  361. * @reported_req_id: Last reported request id
  362. * @last_applied_req_id: Last applied request id
  363. * @frame_id_meta: Frame id for meta
  364. * @ctx_id: Context id
  365. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  366. * will invoke CRM cb at those event.
  367. * @bubble_frame_cnt: Count of the frame after bubble
  368. * @isp_device_type: ISP device type
  369. * @active_req_cnt: Counter for the active request
  370. * @trigger_id: ID provided by CRM for each ctx on the link
  371. * @substate_actiavted: Current substate for the activated state.
  372. * @rxd_epoch: Indicate whether epoch has been received. Used to
  373. * decide whether to apply request in offline ctx
  374. * @process_bubble: Atomic variable to check if ctx is still
  375. * processing bubble.
  376. * @apply_in_progress Whether request apply is in progress
  377. * @rdi_only_context: Get context type information.
  378. * true, if context is rdi only context
  379. * @offline_context: Indicate whether context is for offline IFE
  380. * @hw_acquired: Indicate whether HW resources are acquired
  381. * @init_received: Indicate whether init config packet is received
  382. * meta from the sensor
  383. * @split_acquire: Indicate whether a separate acquire is expected
  384. * @custom_enabled: Custom HW enabled for this ctx
  385. * @use_frame_header_ts: Use frame header for qtimer ts
  386. * @support_consumed_addr: Indicate whether HW has last consumed addr reg
  387. * @use_default_apply: Use default settings in case of frame skip
  388. *
  389. */
  390. struct cam_isp_ctx_mini_dump_info {
  391. struct cam_isp_ctx_req_mini_dump *active_list;
  392. struct cam_isp_ctx_req_mini_dump *pending_list;
  393. struct cam_isp_ctx_req_mini_dump *wait_list;
  394. struct cam_isp_context_event_record event_record[
  395. CAM_ISP_CTX_EVENT_MAX][CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES];
  396. uint64_t sof_timestamp_val;
  397. uint64_t boot_timestamp;
  398. uint64_t last_sof_timestamp;
  399. uint64_t init_timestamp;
  400. int64_t frame_id;
  401. int64_t reported_req_id;
  402. int64_t last_applied_req_id;
  403. int64_t last_bufdone_err_apply_req_id;
  404. uint32_t frame_id_meta;
  405. uint8_t ctx_id;
  406. uint8_t subscribe_event;
  407. uint8_t bubble_frame_cnt;
  408. uint8_t isp_device_type;
  409. uint8_t active_req_cnt;
  410. uint8_t trigger_id;
  411. uint8_t substate_activated;
  412. uint8_t rxd_epoch;
  413. uint8_t process_bubble;
  414. uint8_t active_cnt;
  415. uint8_t pending_cnt;
  416. uint8_t wait_cnt;
  417. bool apply_in_progress;
  418. bool rdi_only_context;
  419. bool offline_context;
  420. bool hw_acquired;
  421. bool init_received;
  422. bool split_acquire;
  423. bool custom_enabled;
  424. bool use_frame_header_ts;
  425. bool support_consumed_addr;
  426. bool use_default_apply;
  427. };
  428. /**
  429. * cam_isp_context_init()
  430. *
  431. * @brief: Initialization function for the ISP context
  432. *
  433. * @ctx: ISP context obj to be initialized
  434. * @bridge_ops: Bridge call back funciton
  435. * @hw_intf: ISP hw manager interface
  436. * @ctx_id: ID for this context
  437. * @isp_device_type Isp device type
  438. * @img_iommu_hdl IOMMU HDL for image buffers
  439. *
  440. */
  441. int cam_isp_context_init(struct cam_isp_context *ctx,
  442. struct cam_context *ctx_base,
  443. struct cam_req_mgr_kmd_ops *bridge_ops,
  444. struct cam_hw_mgr_intf *hw_intf,
  445. uint32_t ctx_id,
  446. uint32_t isp_device_type,
  447. int img_iommu_hdl);
  448. /**
  449. * cam_isp_context_deinit()
  450. *
  451. * @brief: Deinitialize function for the ISP context
  452. *
  453. * @ctx: ISP context obj to be deinitialized
  454. *
  455. */
  456. int cam_isp_context_deinit(struct cam_isp_context *ctx);
  457. #endif /* __CAM_ISP_CONTEXT_H__ */