cam_isp_context.h 13 KB

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