cam_isp_context.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. *
  100. */
  101. struct cam_isp_ctx_debug {
  102. struct dentry *dentry;
  103. uint32_t enable_state_monitor_dump;
  104. };
  105. /**
  106. * struct cam_isp_ctx_irq_ops - Function table for handling IRQ callbacks
  107. *
  108. * @irq_ops: Array of handle function pointers.
  109. *
  110. */
  111. struct cam_isp_ctx_irq_ops {
  112. cam_isp_hw_event_cb_func irq_ops[CAM_ISP_HW_EVENT_MAX];
  113. };
  114. /**
  115. * struct cam_isp_ctx_req - ISP context request object
  116. *
  117. * @base: Common request object ponter
  118. * @cfg: ISP hardware configuration array
  119. * @num_cfg: Number of ISP hardware configuration entries
  120. * @fence_map_out: Output fence mapping array
  121. * @num_fence_map_out: Number of the output fence map
  122. * @fence_map_in: Input fence mapping array
  123. * @num_fence_map_in: Number of input fence map
  124. * @num_acked: Count to track acked entried for output.
  125. * If count equals the number of fence out, it means
  126. * the request has been completed.
  127. * @bubble_report: Flag to track if bubble report is active on
  128. * current request
  129. * @hw_update_data: HW update data for this request
  130. * @event_timestamp: Timestamp for different stage of request
  131. * @reapply: True if reapplying after bubble
  132. *
  133. */
  134. struct cam_isp_ctx_req {
  135. struct cam_ctx_request *base;
  136. struct cam_hw_update_entry cfg[CAM_ISP_CTX_CFG_MAX];
  137. uint32_t num_cfg;
  138. struct cam_hw_fence_map_entry fence_map_out
  139. [CAM_ISP_CTX_RES_MAX];
  140. uint32_t num_fence_map_out;
  141. struct cam_hw_fence_map_entry fence_map_in[CAM_ISP_CTX_RES_MAX];
  142. uint32_t num_fence_map_in;
  143. uint32_t num_acked;
  144. int32_t bubble_report;
  145. struct cam_isp_prepare_hw_update_data hw_update_data;
  146. ktime_t event_timestamp
  147. [CAM_ISP_CTX_EVENT_MAX];
  148. bool bubble_detected;
  149. bool reapply;
  150. };
  151. /**
  152. * struct cam_isp_context_state_monitor - ISP context state
  153. * monitoring for
  154. * debug purposes
  155. *
  156. * @curr_state: Current sub state that received req
  157. * @trigger: Event type of incoming req
  158. * @req_id: Request id
  159. * @frame_id: Frame id based on SOFs
  160. * @evt_time_stamp Current time stamp
  161. *
  162. */
  163. struct cam_isp_context_state_monitor {
  164. enum cam_isp_ctx_activated_substate curr_state;
  165. enum cam_isp_state_change_trigger trigger;
  166. uint64_t req_id;
  167. int64_t frame_id;
  168. unsigned int evt_time_stamp;
  169. };
  170. /**
  171. * struct cam_isp_context_req_id_info - ISP context request id
  172. * information for bufdone.
  173. *
  174. *@last_bufdone_req_id: Last bufdone request id
  175. *
  176. */
  177. struct cam_isp_context_req_id_info {
  178. int64_t last_bufdone_req_id;
  179. };
  180. /**
  181. *
  182. *
  183. * struct cam_isp_context_event_record - Information for last 20 Events
  184. * for a request; Submit, Apply, EPOCH, RUP, Buf done.
  185. *
  186. * @req_id: Last applied request id
  187. * @timestamp: Timestamp for the event
  188. *
  189. */
  190. struct cam_isp_context_event_record {
  191. uint64_t req_id;
  192. ktime_t timestamp;
  193. };
  194. /**
  195. * struct cam_isp_context - ISP context object
  196. *
  197. * @base: Common context object pointer
  198. * @frame_id: Frame id tracking for the isp context
  199. * @frame_id_meta: Frame id read every epoch for the ctx
  200. * meta from the sensor
  201. * @substate_actiavted: Current substate for the activated state.
  202. * @process_bubble: Atomic variable to check if ctx is still
  203. * processing bubble.
  204. * @substate_machine: ISP substate machine for external interface
  205. * @substate_machine_irq: ISP substate machine for irq handling
  206. * @req_base: Common request object storage
  207. * @req_isp: ISP private request object storage
  208. * @hw_ctx: HW object returned by the acquire device command
  209. * @sof_timestamp_val: Captured time stamp value at sof hw event
  210. * @boot_timestamp: Boot time stamp for a given req_id
  211. * @active_req_cnt: Counter for the active request
  212. * @reported_req_id: Last reported request id
  213. * @subscribe_event: The irq event mask that CRM subscribes to, IFE
  214. * will invoke CRM cb at those event.
  215. * @last_applied_req_id: Last applied request id
  216. * @state_monitor_head: Write index to the state monitoring array
  217. * @req_info Request id information about last buf done
  218. * @cam_isp_ctx_state_monitor: State monitoring array
  219. * @event_record_head: Write index to the state monitoring array
  220. * @event_record: Event record array
  221. * @rdi_only_context: Get context type information.
  222. * true, if context is rdi only context
  223. * @offline_context: Indicate whether context is for offline IFE
  224. * @hw_acquired: Indicate whether HW resources are acquired
  225. * @init_received: Indicate whether init config packet is received
  226. * @split_acquire: Indicate whether a separate acquire is expected
  227. * @custom_enabled: Custom HW enabled for this ctx
  228. * @use_frame_header_ts: Use frame header for qtimer ts
  229. * @support_consumed_addr: Indicate whether HW has last consumed addr reg
  230. * @init_timestamp: Timestamp at which this context is initialized
  231. * @isp_device_type: ISP device type
  232. * @rxd_epoch: Indicate whether epoch has been received. Used to
  233. * decide whether to apply request in offline ctx
  234. * @workq: Worker thread for offline ife
  235. * @trigger_id: ID provided by CRM for each ctx on the link
  236. *
  237. */
  238. struct cam_isp_context {
  239. struct cam_context *base;
  240. int64_t frame_id;
  241. uint32_t frame_id_meta;
  242. uint32_t substate_activated;
  243. atomic_t process_bubble;
  244. struct cam_ctx_ops *substate_machine;
  245. struct cam_isp_ctx_irq_ops *substate_machine_irq;
  246. struct cam_ctx_request req_base[CAM_ISP_CTX_REQ_MAX];
  247. struct cam_isp_ctx_req req_isp[CAM_ISP_CTX_REQ_MAX];
  248. void *hw_ctx;
  249. uint64_t sof_timestamp_val;
  250. uint64_t boot_timestamp;
  251. int32_t active_req_cnt;
  252. int64_t reported_req_id;
  253. uint32_t subscribe_event;
  254. int64_t last_applied_req_id;
  255. atomic64_t state_monitor_head;
  256. struct cam_isp_context_state_monitor cam_isp_ctx_state_monitor[
  257. CAM_ISP_CTX_STATE_MONITOR_MAX_ENTRIES];
  258. struct cam_isp_context_req_id_info req_info;
  259. atomic64_t event_record_head[
  260. CAM_ISP_CTX_EVENT_MAX];
  261. struct cam_isp_context_event_record event_record[
  262. CAM_ISP_CTX_EVENT_MAX][CAM_ISP_CTX_EVENT_RECORD_MAX_ENTRIES];
  263. bool rdi_only_context;
  264. bool offline_context;
  265. bool hw_acquired;
  266. bool init_received;
  267. bool split_acquire;
  268. bool custom_enabled;
  269. bool use_frame_header_ts;
  270. bool support_consumed_addr;
  271. unsigned int init_timestamp;
  272. uint32_t isp_device_type;
  273. atomic_t rxd_epoch;
  274. struct cam_req_mgr_core_workq *workq;
  275. int32_t trigger_id;
  276. };
  277. /**
  278. * struct cam_isp_context_dump_header - ISP context dump header
  279. * @tag: Tag name for the header
  280. * @word_size: Size of word
  281. * @size: Size of data
  282. *
  283. */
  284. struct cam_isp_context_dump_header {
  285. uint8_t tag[CAM_ISP_CONTEXT_DUMP_TAG_MAX_LEN];
  286. uint64_t size;
  287. uint32_t word_size;
  288. };
  289. /**
  290. * cam_isp_context_init()
  291. *
  292. * @brief: Initialization function for the ISP context
  293. *
  294. * @ctx: ISP context obj to be initialized
  295. * @bridge_ops: Bridge call back funciton
  296. * @hw_intf: ISP hw manager interface
  297. * @ctx_id: ID for this context
  298. * @isp_device_type Isp device type
  299. *
  300. */
  301. int cam_isp_context_init(struct cam_isp_context *ctx,
  302. struct cam_context *ctx_base,
  303. struct cam_req_mgr_kmd_ops *bridge_ops,
  304. struct cam_hw_mgr_intf *hw_intf,
  305. uint32_t ctx_id,
  306. uint32_t isp_device_type);
  307. /**
  308. * cam_isp_context_deinit()
  309. *
  310. * @brief: Deinitialize function for the ISP context
  311. *
  312. * @ctx: ISP context obj to be deinitialized
  313. *
  314. */
  315. int cam_isp_context_deinit(struct cam_isp_context *ctx);
  316. #endif /* __CAM_ISP_CONTEXT_H__ */