cam_isp_context.h 11 KB

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