sde_encoder_phys.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef __SDE_ENCODER_PHYS_H__
  7. #define __SDE_ENCODER_PHYS_H__
  8. #include <linux/jiffies.h>
  9. #include <linux/sde_rsc.h>
  10. #include "sde_kms.h"
  11. #include "sde_hw_intf.h"
  12. #include "sde_hw_pingpong.h"
  13. #include "sde_hw_ctl.h"
  14. #include "sde_hw_top.h"
  15. #include "sde_hw_wb.h"
  16. #include "sde_hw_cdm.h"
  17. #include "sde_hw_dnsc_blur.h"
  18. #include "sde_encoder.h"
  19. #include "sde_connector.h"
  20. #define SDE_ENCODER_NAME_MAX 16
  21. /* wait for at most 2 vsync for lowest refresh rate (24hz) */
  22. #define DEFAULT_KICKOFF_TIMEOUT_MS 84
  23. /* if default timeout fails wait additional time in 1s increments */
  24. #define EXTENDED_KICKOFF_TIMEOUT_MS 1000
  25. #define EXTENDED_KICKOFF_TIMEOUT_ITERS 10
  26. /* wait 1 sec for the emulated targets */
  27. #define MAX_KICKOFF_TIMEOUT_MS 100000
  28. #define MAX_TE_PROFILE_COUNT 5
  29. /**
  30. * enum sde_enc_split_role - Role this physical encoder will play in a
  31. * split-panel configuration, where one panel is master, and others slaves.
  32. * Masters have extra responsibilities, like managing the VBLANK IRQ.
  33. * @ENC_ROLE_SOLO: This is the one and only panel. This encoder is master.
  34. * @ENC_ROLE_MASTER: This encoder is the master of a split panel config.
  35. * @ENC_ROLE_SLAVE: This encoder is not the master of a split panel config.
  36. * @ENC_ROLE_SKIP: This encoder is not participating in kickoffs
  37. */
  38. enum sde_enc_split_role {
  39. ENC_ROLE_SOLO,
  40. ENC_ROLE_MASTER,
  41. ENC_ROLE_SLAVE,
  42. ENC_ROLE_SKIP
  43. };
  44. /**
  45. * enum sde_enc_enable_state - current enabled state of the physical encoder
  46. * @SDE_ENC_DISABLING: Encoder transitioning to disable state
  47. * Events bounding transition are encoder type specific
  48. * @SDE_ENC_DISABLED: Encoder is disabled
  49. * @SDE_ENC_ENABLING: Encoder transitioning to enabled
  50. * Events bounding transition are encoder type specific
  51. * @SDE_ENC_ENABLED: Encoder is enabled
  52. * @SDE_ENC_ERR_NEEDS_HW_RESET: Encoder is enabled, but requires a hw_reset
  53. * to recover from a previous error
  54. */
  55. enum sde_enc_enable_state {
  56. SDE_ENC_DISABLING,
  57. SDE_ENC_DISABLED,
  58. SDE_ENC_ENABLING,
  59. SDE_ENC_ENABLED,
  60. SDE_ENC_ERR_NEEDS_HW_RESET
  61. };
  62. enum sde_enc_irqs {
  63. SDE_ENC_CMD_TE_ASSERT,
  64. SDE_ENC_CMD_TE_DEASSERT,
  65. SDE_ENC_CMD_TEAR_DETECT,
  66. SDE_ENC_IRQ_MAX
  67. };
  68. struct sde_encoder_phys;
  69. /**
  70. * struct sde_encoder_virt_ops - Interface the containing virtual encoder
  71. * provides for the physical encoders to use to callback.
  72. * @handle_vblank_virt: Notify virtual encoder of vblank IRQ reception
  73. * Note: This is called from IRQ handler context.
  74. * @handle_underrun_virt: Notify virtual encoder of underrun IRQ reception
  75. * Note: This is called from IRQ handler context.
  76. * @handle_frame_done: Notify virtual encoder that this phys encoder
  77. * completes last request frame.
  78. * @get_qsync_fps: Returns the min fps for the qsync feature.
  79. */
  80. struct sde_encoder_virt_ops {
  81. void (*handle_vblank_virt)(struct drm_encoder *parent,
  82. struct sde_encoder_phys *phys);
  83. void (*handle_underrun_virt)(struct drm_encoder *parent,
  84. struct sde_encoder_phys *phys);
  85. void (*handle_frame_done)(struct drm_encoder *parent,
  86. struct sde_encoder_phys *phys, u32 event);
  87. void (*get_qsync_fps)(struct drm_encoder *parent,
  88. u32 *qsync_fps, struct drm_connector_state *conn_state);
  89. };
  90. /**
  91. * struct sde_encoder_phys_ops - Interface the physical encoders provide to
  92. * the containing virtual encoder.
  93. * @late_register: DRM Call. Add Userspace interfaces, debugfs.
  94. * @prepare_commit: MSM Atomic Call, start of atomic commit sequence
  95. * @is_master: Whether this phys_enc is the current master
  96. * encoder. Can be switched at enable time. Based
  97. * on split_role and current mode (CMD/VID).
  98. * @mode_fixup: DRM Call. Fixup a DRM mode.
  99. * @cont_splash_mode_set: mode set with specific HW resources during
  100. * cont splash enabled state.
  101. * @mode_set: DRM Call. Set a DRM mode.
  102. * This likely caches the mode, for use at enable.
  103. * @enable: DRM Call. Enable a DRM mode.
  104. * @disable: DRM Call. Disable mode.
  105. * @atomic_check: DRM Call. Atomic check new DRM state.
  106. * @destroy: DRM Call. Destroy and release resources.
  107. * @get_hw_resources: Populate the structure with the hardware
  108. * resources that this phys_enc is using.
  109. * Expect no overlap between phys_encs.
  110. * @control_vblank_irq Register/Deregister for VBLANK IRQ
  111. * @wait_for_commit_done: Wait for hardware to have flushed the
  112. * current pending frames to hardware
  113. * @wait_for_tx_complete: Wait for hardware to transfer the pixels
  114. * to the panel
  115. * @wait_for_vblank: Wait for VBLANK, for sub-driver internal use
  116. * @prepare_for_kickoff: Do any work necessary prior to a kickoff
  117. * For CMD encoder, may wait for previous tx done
  118. * @handle_post_kickoff: Do any work necessary post-kickoff work
  119. * @trigger_flush: Process flush event on physical encoder
  120. * @trigger_start: Process start event on physical encoder
  121. * @clear_flush_mask: clear flush mask
  122. * @needs_single_flush: Whether encoder slaves need to be flushed
  123. * @setup_misr: Sets up MISR, enable and disables based on sysfs
  124. * @collect_misr: Collects MISR data on frame update
  125. * @hw_reset: Issue HW recovery such as CTL reset and clear
  126. * SDE_ENC_ERR_NEEDS_HW_RESET state
  127. * @irq_control: Handler to enable/disable all the encoder IRQs
  128. * @update_split_role: Update the split role of the phys enc
  129. * @control_te: Interface to control the vsync_enable status
  130. * @restore: Restore all the encoder configs.
  131. * @is_autorefresh_enabled: provides the autorefresh current
  132. * enable/disable state.
  133. * @is_autoref_disable_pending: Indicates if autorefresh disable commit in progress
  134. * @get_line_count: Obtain current internal vertical line count
  135. * @wait_dma_trigger: Returns true if lut dma has to trigger and wait
  136. * unitl transaction is complete.
  137. * @wait_for_active: Wait for display scan line to be in active area
  138. * @setup_vsync_source: Configure vsync source selection for cmd mode.
  139. * @get_underrun_line_count: Obtain and log current internal vertical line
  140. * count and underrun line count
  141. * @add_to_minidump: Add this phys_enc data to minidumps
  142. * @disable_autorefresh: Disable autorefresh
  143. * @idle_pc_cache_display_status: caches display status at idle power collapse
  144. * @wait_for_vsync_on_autorefresh_busy: Wait for vsync if autorefresh status busy
  145. */
  146. struct sde_encoder_phys_ops {
  147. int (*late_register)(struct sde_encoder_phys *encoder,
  148. struct dentry *debugfs_root);
  149. void (*prepare_commit)(struct sde_encoder_phys *encoder);
  150. bool (*is_master)(struct sde_encoder_phys *encoder);
  151. bool (*mode_fixup)(struct sde_encoder_phys *encoder,
  152. const struct drm_display_mode *mode,
  153. struct drm_display_mode *adjusted_mode);
  154. void (*mode_set)(struct sde_encoder_phys *encoder,
  155. struct drm_display_mode *mode,
  156. struct drm_display_mode *adjusted_mode, bool *reinit_mixers);
  157. void (*cont_splash_mode_set)(struct sde_encoder_phys *encoder,
  158. struct drm_display_mode *adjusted_mode);
  159. void (*enable)(struct sde_encoder_phys *encoder);
  160. void (*disable)(struct sde_encoder_phys *encoder);
  161. int (*atomic_check)(struct sde_encoder_phys *encoder,
  162. struct drm_crtc_state *crtc_state,
  163. struct drm_connector_state *conn_state);
  164. void (*destroy)(struct sde_encoder_phys *encoder);
  165. void (*get_hw_resources)(struct sde_encoder_phys *encoder,
  166. struct sde_encoder_hw_resources *hw_res,
  167. struct drm_connector_state *conn_state);
  168. int (*control_vblank_irq)(struct sde_encoder_phys *enc, bool enable);
  169. int (*wait_for_commit_done)(struct sde_encoder_phys *phys_enc);
  170. int (*wait_for_tx_complete)(struct sde_encoder_phys *phys_enc);
  171. int (*wait_for_vblank)(struct sde_encoder_phys *phys_enc);
  172. int (*prepare_for_kickoff)(struct sde_encoder_phys *phys_enc,
  173. struct sde_encoder_kickoff_params *params);
  174. void (*handle_post_kickoff)(struct sde_encoder_phys *phys_enc);
  175. void (*trigger_flush)(struct sde_encoder_phys *phys_enc);
  176. void (*trigger_start)(struct sde_encoder_phys *phys_enc);
  177. void (*clear_flush_mask)(struct sde_encoder_phys *phys_enc, bool clear);
  178. bool (*needs_single_flush)(struct sde_encoder_phys *phys_enc);
  179. void (*setup_misr)(struct sde_encoder_phys *phys_encs,
  180. bool enable, u32 frame_count);
  181. int (*collect_misr)(struct sde_encoder_phys *phys_enc, bool nonblock,
  182. u32 *misr_value);
  183. void (*hw_reset)(struct sde_encoder_phys *phys_enc);
  184. void (*irq_control)(struct sde_encoder_phys *phys, bool enable);
  185. void (*dynamic_irq_control)(struct sde_encoder_phys *phys, bool enable);
  186. void (*update_split_role)(struct sde_encoder_phys *phys_enc,
  187. enum sde_enc_split_role role);
  188. void (*control_te)(struct sde_encoder_phys *phys_enc, bool enable);
  189. void (*restore)(struct sde_encoder_phys *phys);
  190. bool (*is_autorefresh_enabled)(struct sde_encoder_phys *phys);
  191. bool (*is_autoref_disable_pending)(struct sde_encoder_phys *phys);
  192. int (*get_line_count)(struct sde_encoder_phys *phys);
  193. bool (*wait_dma_trigger)(struct sde_encoder_phys *phys);
  194. int (*wait_for_active)(struct sde_encoder_phys *phys);
  195. void (*setup_vsync_source)(struct sde_encoder_phys *phys, u32 vsync_source,
  196. struct msm_display_info *disp_info);
  197. u32 (*get_underrun_line_count)(struct sde_encoder_phys *phys);
  198. void (*add_to_minidump)(struct sde_encoder_phys *phys);
  199. void (*disable_autorefresh)(struct sde_encoder_phys *phys);
  200. void (*idle_pc_cache_display_status)(struct sde_encoder_phys *phys);
  201. void (*wait_for_vsync_on_autorefresh_busy)(struct sde_encoder_phys *phys_enc);
  202. };
  203. /**
  204. * enum sde_intr_idx - sde encoder interrupt index
  205. * @INTR_IDX_VSYNC: Vsync interrupt for video mode panel
  206. * @INTR_IDX_PINGPONG: Pingpong done interrupt for cmd mode panel
  207. * @INTR_IDX_UNDERRUN: Underrun interrupt for video and cmd mode panel
  208. * @INTR_IDX_CTL_START:Control start interrupt to indicate the frame start
  209. * @INTR_IDX_CTL_DONE: Control done interrupt indicating the control path being idle
  210. * @INTR_IDX_RDPTR: Readpointer done interrupt for cmd mode panel
  211. * @INTR_IDX_WB_DONE: Writeback done interrupt for WB
  212. * @INTR_IDX_PP1_OVFL: Pingpong overflow interrupt on PP1 for Concurrent WB
  213. * @INTR_IDX_PP2_OVFL: Pingpong overflow interrupt on PP2 for Concurrent WB
  214. * @INTR_IDX_PP3_OVFL: Pingpong overflow interrupt on PP3 for Concurrent WB
  215. * @INTR_IDX_PP4_OVFL: Pingpong overflow interrupt on PP4 for Concurrent WB
  216. * @INTR_IDX_PP5_OVFL: Pingpong overflow interrupt on PP5 for Concurrent WB
  217. * @INTR_IDX_PP_CWB_OVFL: Pingpong overflow interrupt on PP_CWB0/1 for Concurrent WB
  218. * @INTR_IDX_PP_CWB2_OVFL: Pingpong overflow interrupt on PP_CWB2/3 for Concurrent WB
  219. * @INTR_IDX_AUTOREFRESH_DONE: Autorefresh done for cmd mode panel meaning
  220. * autorefresh has triggered a double buffer flip
  221. * @INTR_IDX_WRPTR: Writepointer start interrupt for cmd mode panel
  222. * @INTR_IDX_WB_LINEPTR: Programmable lineptr interrupt for WB
  223. * @INTF_IDX_TEAR_DETECT: Tear detect interrupt
  224. * @INTR_IDX_TE_ASSERT: TE Assert interrupt
  225. * @INTR_IDX_TE_DEASSERT: TE Deassert interrupt
  226. */
  227. enum sde_intr_idx {
  228. INTR_IDX_VSYNC,
  229. INTR_IDX_PINGPONG,
  230. INTR_IDX_UNDERRUN,
  231. INTR_IDX_CTL_START,
  232. INTR_IDX_CTL_DONE,
  233. INTR_IDX_RDPTR,
  234. INTR_IDX_AUTOREFRESH_DONE,
  235. INTR_IDX_WB_DONE,
  236. INTR_IDX_PP1_OVFL,
  237. INTR_IDX_PP2_OVFL,
  238. INTR_IDX_PP3_OVFL,
  239. INTR_IDX_PP4_OVFL,
  240. INTR_IDX_PP5_OVFL,
  241. INTR_IDX_PP_CWB_OVFL,
  242. INTR_IDX_PP_CWB2_OVFL,
  243. INTR_IDX_WRPTR,
  244. INTR_IDX_WB_LINEPTR,
  245. INTF_IDX_TEAR_DETECT,
  246. INTR_IDX_TE_ASSERT,
  247. INTR_IDX_TE_DEASSERT,
  248. INTR_IDX_MAX,
  249. };
  250. /**
  251. * sde_encoder_irq - tracking structure for interrupts
  252. * @name: string name of interrupt
  253. * @intr_type: Encoder interrupt type
  254. * @intr_idx: Encoder interrupt enumeration
  255. * @hw_idx: HW Block ID
  256. * @irq_idx: IRQ interface lookup index from SDE IRQ framework
  257. * will be -EINVAL if IRQ is not registered
  258. * @irq_cb: interrupt callback
  259. */
  260. struct sde_encoder_irq {
  261. const char *name;
  262. enum sde_intr_type intr_type;
  263. enum sde_intr_idx intr_idx;
  264. int hw_idx;
  265. int irq_idx;
  266. struct sde_irq_callback cb;
  267. };
  268. /**
  269. * struct sde_encoder_phys - physical encoder that drives a single INTF block
  270. * tied to a specific panel / sub-panel. Abstract type, sub-classed by
  271. * phys_vid or phys_cmd for video mode or command mode encs respectively.
  272. * @parent: Pointer to the containing virtual encoder
  273. * @connector: If a mode is set, cached pointer to the active connector
  274. * @ops: Operations exposed to the virtual encoder
  275. * @parent_ops: Callbacks exposed by the parent to the phys_enc
  276. * @hw_mdptop: Hardware interface to the top registers
  277. * @hw_ctl: Hardware interface to the ctl registers
  278. * @hw_intf: Hardware interface to INTF registers
  279. * @hw_cdm: Hardware interface to the cdm registers
  280. * @hw_qdss: Hardware interface to the qdss registers
  281. * @cdm_cfg: Chroma-down hardware configuration
  282. * @hw_pp: Hardware interface to the ping pong registers
  283. * @hw_dnsc_blur: Hardware interface to the downscale blur registers
  284. * @sde_kms: Pointer to the sde_kms top level
  285. * @cached_mode: DRM mode cached at mode_set time, acted on in enable
  286. * @wd_jitter : Pointer to watchdog jitter prams
  287. * @enabled: Whether the encoder has enabled and running a mode
  288. * @split_role: Role to play in a split-panel configuration
  289. * @intf_mode: Interface mode
  290. * @intf_idx: Interface index on sde hardware
  291. * @intf_cfg: Interface hardware configuration
  292. * @intf_cfg_v1: Interface hardware configuration to be used if control
  293. * path supports SDE_CTL_ACTIVE_CFG
  294. * @comp_type: Type of compression supported
  295. * @comp_ratio: Compression ratio multiplied by 100
  296. * @dsc_extra_pclk_cycle_cnt: Extra pclk cycle count for DSC over DP
  297. * @dsc_extra_disp_width: Additional display width for DSC over DP
  298. * @poms_align_vsync: poms with vsync aligned
  299. * @dce_bytes_per_line: Compressed bytes per line
  300. * @enc_spinlock: Virtual-Encoder-Wide Spin Lock for IRQ purposes
  301. * @enable_state: Enable state tracking
  302. * @vblank_refcount: Reference count of vblank request
  303. * @wbirq_refcount: Reference count of wb irq request
  304. * @vsync_cnt: Vsync count for the physical encoder
  305. * @last_vsync_timestamp: store last vsync timestamp
  306. * @underrun_cnt: Underrun count for the physical encoder
  307. * @pending_kickoff_cnt: Atomic counter tracking the number of kickoffs
  308. * vs. the number of done/vblank irqs. Should hover
  309. * between 0-2 Incremented when a new kickoff is
  310. * scheduled. Decremented in irq handler
  311. * @pending_retire_fence_cnt: Atomic counter tracking the pending retire
  312. * fences that have to be signalled.
  313. * @pending_ctl_start_cnt: Atomic counter tracking the pending ctl-start-irq,
  314. * used to release commit thread. Currently managed
  315. * only for writeback encoder and the counter keeps
  316. * increasing for other type of encoders.
  317. * @pending_kickoff_wq: Wait queue for blocking until kickoff completes
  318. * @kickoff_timeout_ms: kickoff timeout in mill seconds
  319. * @irq: IRQ tracking structures
  320. * @has_intf_te: Interface TE configuration support
  321. * @cont_splash_enabled: Variable to store continuous splash settings.
  322. * @in_clone_mode Indicates if encoder is in clone mode ref@CWB
  323. * @vfp_cached: cached vertical front porch to be used for
  324. * programming ROT and MDP fetch start
  325. * @pf_time_in_us: Programmable fetch time in micro-seconds
  326. * @sde_hw_fence_error_status: Hw fence error handing flag controled by userspace
  327. * that if handing fence error in driver
  328. * @sde_hw_fence_error_value: hw fence error value from cb function
  329. * @sde_hw_fence_handle: Hw fence driver client handle, this handle was returned
  330. * during the call 'msm_hw_fence_register' to register the
  331. * client
  332. * @fence_error_handle_in_progress:
  333. * bool to indicate if fence error handling in progress
  334. * This is set once fence error occurs and cleared only when
  335. * good frame is received. Not cleared in continous fence
  336. * error cases
  337. * @frame_trigger_mode: frame trigger mode indication for command
  338. * mode display
  339. * @recovered: flag set to true when recovered from pp timeout
  340. * @autorefresh_disable_trans: flag set to true during autorefresh disable transition
  341. * @sim_qsync_frame: Current simulated qsync frame type
  342. */
  343. struct sde_encoder_phys {
  344. struct drm_encoder *parent;
  345. struct drm_connector *connector;
  346. struct sde_encoder_phys_ops ops;
  347. struct sde_encoder_virt_ops parent_ops;
  348. struct sde_hw_mdp *hw_mdptop;
  349. struct sde_hw_ctl *hw_ctl;
  350. struct sde_hw_intf *hw_intf;
  351. struct sde_hw_cdm *hw_cdm;
  352. struct sde_hw_qdss *hw_qdss;
  353. struct sde_hw_cdm_cfg cdm_cfg;
  354. struct sde_hw_pingpong *hw_pp;
  355. struct sde_hw_dnsc_blur *hw_dnsc_blur;
  356. struct sde_kms *sde_kms;
  357. struct drm_display_mode cached_mode;
  358. struct intf_wd_jitter_params wd_jitter;
  359. enum sde_enc_split_role split_role;
  360. enum sde_intf_mode intf_mode;
  361. enum sde_intf intf_idx;
  362. struct sde_hw_intf_cfg intf_cfg;
  363. struct sde_hw_intf_cfg_v1 intf_cfg_v1;
  364. enum msm_display_compression_type comp_type;
  365. u32 comp_ratio;
  366. u32 dsc_extra_pclk_cycle_cnt;
  367. u32 dsc_extra_disp_width;
  368. bool poms_align_vsync;
  369. u32 dce_bytes_per_line;
  370. spinlock_t *enc_spinlock;
  371. enum sde_enc_enable_state enable_state;
  372. struct mutex *vblank_ctl_lock;
  373. atomic_t vblank_refcount;
  374. atomic_t wbirq_refcount;
  375. atomic_t vsync_cnt;
  376. ktime_t last_vsync_timestamp;
  377. atomic_t underrun_cnt;
  378. atomic_t pending_kickoff_cnt;
  379. atomic_t pending_retire_fence_cnt;
  380. atomic_t pending_ctl_start_cnt;
  381. wait_queue_head_t pending_kickoff_wq;
  382. u32 kickoff_timeout_ms;
  383. struct sde_encoder_irq irq[INTR_IDX_MAX];
  384. bool has_intf_te;
  385. bool cont_splash_enabled;
  386. bool in_clone_mode;
  387. int vfp_cached;
  388. u32 pf_time_in_us;
  389. bool sde_hw_fence_error_status;
  390. int sde_hw_fence_error_value;
  391. u64 sde_hw_fence_handle;
  392. bool fence_error_handle_in_progress;
  393. enum frame_trigger_mode_type frame_trigger_mode;
  394. bool recovered;
  395. bool autorefresh_disable_trans;
  396. enum sde_sim_qsync_frame sim_qsync_frame;
  397. };
  398. static inline int sde_encoder_phys_inc_pending(struct sde_encoder_phys *phys)
  399. {
  400. return atomic_inc_return(&phys->pending_kickoff_cnt);
  401. }
  402. /*
  403. * sde_encoder_clear_fence_error_in_progress - clear fence_error_handle_in_progress flag
  404. * after good frame
  405. * @phys_enc: Pointer to physical encoder structure
  406. */
  407. void sde_encoder_clear_fence_error_in_progress(struct sde_encoder_phys *phys_enc);
  408. /**
  409. * sde_encoder_hw_fence_signal - hw fence related fence error handing
  410. * @phys_enc: Pointer to physical encoder structure
  411. * return: 0 on success; error code otherwise
  412. */
  413. static inline int sde_encoder_hw_fence_signal(struct sde_encoder_phys *phys_enc);
  414. /**
  415. * struct sde_encoder_phys_vid - sub-class of sde_encoder_phys to handle video
  416. * mode specific operations
  417. * @base: Baseclass physical encoder structure
  418. * @timing_params: Current timing parameter
  419. * @error_count: Number of consecutive kickoffs that experienced an error
  420. */
  421. struct sde_encoder_phys_vid {
  422. struct sde_encoder_phys base;
  423. struct intf_timing_params timing_params;
  424. int error_count;
  425. };
  426. /**
  427. * struct sde_encoder_phys_cmd_autorefresh - autorefresh state tracking
  428. * @cfg: current active autorefresh configuration
  429. * @kickoff_cnt: atomic count tracking autorefresh done irq kickoffs pending
  430. * @kickoff_wq: wait queue for waiting on autorefresh done irq
  431. */
  432. struct sde_encoder_phys_cmd_autorefresh {
  433. struct sde_hw_autorefresh cfg;
  434. atomic_t kickoff_cnt;
  435. wait_queue_head_t kickoff_wq;
  436. };
  437. /**
  438. * struct sde_encoder_phys_cmd_te_timestamp - list node to keep track of
  439. * rd_ptr/TE timestamp
  440. * @list: list node
  441. * @timestamp: TE timestamp
  442. */
  443. struct sde_encoder_phys_cmd_te_timestamp {
  444. struct list_head list;
  445. ktime_t timestamp;
  446. };
  447. /**
  448. * struct sde_encoder_phys_cmd - sub-class of sde_encoder_phys to handle command
  449. * mode specific operations
  450. * @base: Baseclass physical encoder structure
  451. * @stream_sel: Stream selection for multi-stream interfaces
  452. * @frame_tx_timeout_report_cnt: number of pp_done/ctl_done irq timeout errors
  453. * @autorefresh: autorefresh feature state
  454. * @pending_vblank_cnt: Atomic counter tracking pending wait for VBLANK
  455. * @pending_vblank_wq: Wait queue for blocking until VBLANK received
  456. * @wr_ptr_wait_success: log wr_ptr_wait success for release fence trigger
  457. * @te_timestamp_list: List head for the TE timestamp list
  458. * @te_timestamp: Array of size MAX_TE_PROFILE_COUNT te_timestamp_list elements
  459. * @qsync_threshold_lines: tearcheck threshold lines calculated based on qsync_min_fps
  460. */
  461. struct sde_encoder_phys_cmd {
  462. struct sde_encoder_phys base;
  463. int stream_sel;
  464. int frame_tx_timeout_report_cnt;
  465. struct sde_encoder_phys_cmd_autorefresh autorefresh;
  466. atomic_t pending_vblank_cnt;
  467. wait_queue_head_t pending_vblank_wq;
  468. bool wr_ptr_wait_success;
  469. struct list_head te_timestamp_list;
  470. struct sde_encoder_phys_cmd_te_timestamp
  471. te_timestamp[MAX_TE_PROFILE_COUNT];
  472. u32 qsync_threshold_lines;
  473. };
  474. /**
  475. * struct sde_encoder_phys_wb - sub-class of sde_encoder_phys to handle
  476. * writeback specific operations
  477. * @base: Baseclass physical encoder structure
  478. * @hw_wb: Hardware interface to the wb registers
  479. * @wbdone_timeout: Timeout value for writeback done in msec
  480. * @wb_cfg: Writeback hardware configuration
  481. * @cdp_cfg: Writeback CDP configuration
  482. * @wb_roi: Writeback region-of-interest
  483. * @wb_fmt: Writeback pixel format
  484. * @wb_fb: Pointer to current writeback framebuffer
  485. * @wb_aspace: Pointer to current writeback address space
  486. * @old_fb: Pointer to old writeback framebuffer
  487. * @old_aspace: Pointer to old writeback address space
  488. * @aspace: address space identifier for non-secure/secure domain
  489. * @wb_dev: Pointer to writeback device
  490. * @bo_disable: Buffer object(s) to use during the disabling state
  491. * @fb_disable: Frame buffer to use during the disabling state
  492. * @sc_cfg: Stores wb system cache config
  493. * @crtc: Pointer to drm_crtc
  494. * @prog_line: Cached programmable line value used to trigger early wb-fence
  495. */
  496. struct sde_encoder_phys_wb {
  497. struct sde_encoder_phys base;
  498. struct sde_hw_wb *hw_wb;
  499. u32 wbdone_timeout;
  500. struct sde_hw_wb_cfg wb_cfg;
  501. struct sde_hw_wb_cdp_cfg cdp_cfg;
  502. struct sde_rect wb_roi;
  503. const struct sde_format *wb_fmt;
  504. struct drm_framebuffer *wb_fb;
  505. struct msm_gem_address_space *wb_aspace;
  506. struct drm_framebuffer *old_fb;
  507. struct msm_gem_address_space *old_aspace;
  508. struct msm_gem_address_space *aspace[SDE_IOMMU_DOMAIN_MAX];
  509. struct sde_wb_device *wb_dev;
  510. struct drm_gem_object *bo_disable[SDE_MAX_PLANES];
  511. struct drm_framebuffer *fb_disable;
  512. struct sde_hw_wb_sc_cfg sc_cfg;
  513. struct drm_crtc *crtc;
  514. u32 prog_line;
  515. };
  516. /**
  517. * struct sde_enc_phys_init_params - initialization parameters for phys encs
  518. * @sde_kms: Pointer to the sde_kms top level
  519. * @parent: Pointer to the containing virtual encoder
  520. * @parent_ops: Callbacks exposed by the parent to the phys_enc
  521. * @split_role: Role to play in a split-panel configuration
  522. * @intf_idx: Interface index this phys_enc will control
  523. * @wb_idx: Writeback index this phys_enc will control
  524. * @comp_type: Type of compression supported
  525. * @enc_spinlock: Virtual-Encoder-Wide Spin Lock for IRQ purposes
  526. */
  527. struct sde_enc_phys_init_params {
  528. struct sde_kms *sde_kms;
  529. struct drm_encoder *parent;
  530. struct sde_encoder_virt_ops parent_ops;
  531. enum sde_enc_split_role split_role;
  532. enum sde_intf intf_idx;
  533. enum sde_wb wb_idx;
  534. enum msm_display_compression_type comp_type;
  535. spinlock_t *enc_spinlock;
  536. struct mutex *vblank_ctl_lock;
  537. };
  538. /**
  539. * sde_encoder_wait_info - container for passing arguments to irq wait functions
  540. * @wq: wait queue structure
  541. * @atomic_cnt: wait until atomic_cnt equals zero
  542. * @count_check: wait for specific atomic_cnt instead of zero.
  543. * @timeout_ms: timeout value in milliseconds
  544. */
  545. struct sde_encoder_wait_info {
  546. wait_queue_head_t *wq;
  547. atomic_t *atomic_cnt;
  548. u32 count_check;
  549. s64 timeout_ms;
  550. };
  551. /**
  552. * sde_encoder_phys_vid_init - Construct a new video mode physical encoder
  553. * @p: Pointer to init params structure
  554. * Return: Error code or newly allocated encoder
  555. */
  556. struct sde_encoder_phys *sde_encoder_phys_vid_init(
  557. struct sde_enc_phys_init_params *p);
  558. /**
  559. * sde_encoder_phys_cmd_init - Construct a new command mode physical encoder
  560. * @p: Pointer to init params structure
  561. * Return: Error code or newly allocated encoder
  562. */
  563. struct sde_encoder_phys *sde_encoder_phys_cmd_init(
  564. struct sde_enc_phys_init_params *p);
  565. /**
  566. * sde_encoder_phys_wb_init - Construct a new writeback physical encoder
  567. * @p: Pointer to init params structure
  568. * Return: Error code or newly allocated encoder
  569. */
  570. #if IS_ENABLED(CONFIG_DRM_SDE_WB)
  571. struct sde_encoder_phys *sde_encoder_phys_wb_init(
  572. struct sde_enc_phys_init_params *p);
  573. #else
  574. static inline
  575. struct sde_encoder_phys *sde_encoder_phys_wb_init(
  576. struct sde_enc_phys_init_params *p)
  577. {
  578. return NULL;
  579. }
  580. #endif /* CONFIG_DRM_SDE_WB */
  581. void sde_encoder_phys_setup_cdm(struct sde_encoder_phys *phys_enc,
  582. struct drm_framebuffer *fb, const struct sde_format *format,
  583. struct sde_rect *wb_roi);
  584. /**
  585. * sde_encoder_helper_get_pp_line_count - pingpong linecount helper function
  586. * @drm_enc: Pointer to drm encoder structure
  587. * @info: structure used to populate the pp line count information
  588. */
  589. void sde_encoder_helper_get_pp_line_count(struct drm_encoder *drm_enc,
  590. struct sde_hw_pp_vsync_info *info);
  591. /**
  592. * sde_encoder_helper_get_kickoff_timeout_ms- get the kickoff timeout value based on fps
  593. * @drm_enc: Pointer to drm encoder structure
  594. * Returns: Kickoff timeout in milli seconds
  595. */
  596. u32 sde_encoder_helper_get_kickoff_timeout_ms(struct drm_encoder *drm_enc);
  597. /**
  598. * sde_encoder_helper_trigger_flush - control flush helper function
  599. * This helper function may be optionally specified by physical
  600. * encoders if they require ctl_flush triggering.
  601. * @phys_enc: Pointer to physical encoder structure
  602. */
  603. void sde_encoder_helper_trigger_flush(struct sde_encoder_phys *phys_enc);
  604. /**
  605. * sde_encoder_helper_trigger_start - control start helper function
  606. * This helper function may be optionally specified by physical
  607. * encoders if they require ctl_start triggering.
  608. * @phys_enc: Pointer to physical encoder structure
  609. */
  610. void sde_encoder_helper_trigger_start(struct sde_encoder_phys *phys_enc);
  611. /**
  612. * sde_encoder_helper_vsync_config - configure vsync source for cmd mode
  613. * @phys_enc: Pointer to physical encoder structure
  614. * @vsync_source: vsync source selection
  615. */
  616. void sde_encoder_helper_vsync_config(struct sde_encoder_phys *phys_enc, u32 vsync_source);
  617. /**
  618. * sde_encoder_helper_wait_event_timeout - wait for event with timeout
  619. * taking into account that jiffies may jump between reads leading to
  620. * incorrectly detected timeouts. Prevent failure in this scenario by
  621. * making sure that elapsed time during wait is valid.
  622. * @drm_id: drm object id for logging
  623. * @hw_id: hw instance id for logging
  624. * @info: wait info structure
  625. */
  626. int sde_encoder_helper_wait_event_timeout(
  627. int32_t drm_id,
  628. int32_t hw_id,
  629. struct sde_encoder_wait_info *info);
  630. /*
  631. * sde_encoder_get_fps - get the allowed panel jitter in nanoseconds
  632. * @frame_rate: custom input frame rate
  633. * @jitter_num: jitter numerator value
  634. * @jitter_denom: jitter denomerator value,
  635. * @l_bound: lower frame period boundary
  636. * @u_bound: upper frame period boundary
  637. */
  638. void sde_encoder_helper_get_jitter_bounds_ns(uint32_t frame_rate,
  639. u32 jitter_num, u32 jitter_denom,
  640. ktime_t *l_bound, ktime_t *u_bound);
  641. /**
  642. * sde_encoder_helper_switch_vsync - switch vsync source to WD or default
  643. * @drm_enc: Pointer to drm encoder structure
  644. * @watchdog_te: switch vsync source to watchdog TE
  645. */
  646. int sde_encoder_helper_switch_vsync(struct drm_encoder *drm_enc,
  647. bool watchdog_te);
  648. /**
  649. * sde_encoder_helper_hw_reset - issue ctl hw reset
  650. * This helper function may be optionally specified by physical
  651. * encoders if they require ctl hw reset. If state is currently
  652. * SDE_ENC_ERR_NEEDS_HW_RESET, it is set back to SDE_ENC_ENABLED.
  653. * @phys_enc: Pointer to physical encoder structure
  654. */
  655. void sde_encoder_helper_hw_reset(struct sde_encoder_phys *phys_enc);
  656. static inline enum sde_3d_blend_mode sde_encoder_helper_get_3d_blend_mode(
  657. struct sde_encoder_phys *phys_enc)
  658. {
  659. struct msm_display_topology def;
  660. enum sde_enc_split_role split_role;
  661. int ret, num_lm;
  662. bool mode_3d;
  663. if (!phys_enc || phys_enc->enable_state == SDE_ENC_DISABLING ||
  664. !phys_enc->connector || !phys_enc->connector->state)
  665. return BLEND_3D_NONE;
  666. ret = sde_connector_state_get_topology
  667. (phys_enc->connector->state, &def);
  668. if (ret)
  669. return BLEND_3D_NONE;
  670. if (phys_enc->hw_intf && phys_enc->hw_intf->cfg.split_link_en)
  671. return BLEND_3D_NONE;
  672. num_lm = def.num_lm;
  673. mode_3d = (num_lm > def.num_enc) ? true : false;
  674. split_role = phys_enc->split_role;
  675. if (split_role == ENC_ROLE_SOLO && num_lm == 2 && mode_3d)
  676. return BLEND_3D_H_ROW_INT;
  677. if ((split_role == ENC_ROLE_MASTER || split_role == ENC_ROLE_SLAVE)
  678. && num_lm == 4 && mode_3d)
  679. return BLEND_3D_H_ROW_INT;
  680. return BLEND_3D_NONE;
  681. }
  682. /**
  683. * sde_encoder_phys_is_cwb_disabling - Check if CWB encoder attached to this
  684. * CRTC and it is in SDE_ENC_DISABLING state.
  685. * @phys_enc: Pointer to physical encoder structure
  686. * @crtc: drm crtc
  687. * @Return: true if cwb encoder is in disabling state
  688. */
  689. static inline bool sde_encoder_phys_is_cwb_disabling(
  690. struct sde_encoder_phys *phys, struct drm_crtc *crtc)
  691. {
  692. struct sde_encoder_phys_wb *wb_enc;
  693. if (!phys || !phys->in_clone_mode ||
  694. phys->enable_state != SDE_ENC_DISABLING)
  695. return false;
  696. wb_enc = container_of(phys, struct sde_encoder_phys_wb, base);
  697. return (wb_enc->crtc == crtc) ? true : false;
  698. }
  699. /**
  700. * sde_encoder_helper_split_config - split display configuration helper function
  701. * This helper function may be used by physical encoders to configure
  702. * the split display related registers.
  703. * @phys_enc: Pointer to physical encoder structure
  704. * @interface: enum sde_intf setting
  705. */
  706. void sde_encoder_helper_split_config(
  707. struct sde_encoder_phys *phys_enc,
  708. enum sde_intf interface);
  709. /**
  710. * sde_encoder_helper_reset_mixers - reset mixers associated with phys enc
  711. * @phys_enc: Pointer to physical encoder structure
  712. * @fb: Optional fb for specifying new mixer output resolution, may be NULL
  713. * Return: Zero on success
  714. */
  715. int sde_encoder_helper_reset_mixers(struct sde_encoder_phys *phys_enc,
  716. struct drm_framebuffer *fb);
  717. /**
  718. * sde_encoder_helper_hw_fence_sw_override - reset mixers and do hw-fence sw override
  719. * @phys_enc: Pointer to physical encoder structure
  720. * @ctl: Pointer to hw_ctl structure
  721. */
  722. void sde_encoder_helper_hw_fence_sw_override(struct sde_encoder_phys *phys_enc,
  723. struct sde_hw_ctl *ctl);
  724. /**
  725. * sde_encoder_helper_report_irq_timeout - utility to report error that irq has
  726. * timed out, including reporting frame error event to crtc and debug dump
  727. * @phys_enc: Pointer to physical encoder structure
  728. * @intr_idx: Failing interrupt index
  729. */
  730. void sde_encoder_helper_report_irq_timeout(struct sde_encoder_phys *phys_enc,
  731. enum sde_intr_idx intr_idx);
  732. /**
  733. * sde_encoder_helper_wait_for_irq - utility to wait on an irq.
  734. * note: will call sde_encoder_helper_wait_for_irq on timeout
  735. * @phys_enc: Pointer to physical encoder structure
  736. * @intr_idx: encoder interrupt index
  737. * @wait_info: wait info struct
  738. * @Return: 0 or -ERROR
  739. */
  740. int sde_encoder_helper_wait_for_irq(struct sde_encoder_phys *phys_enc,
  741. enum sde_intr_idx intr_idx,
  742. struct sde_encoder_wait_info *wait_info);
  743. /**
  744. * sde_encoder_helper_register_irq - register and enable an irq
  745. * @phys_enc: Pointer to physical encoder structure
  746. * @intr_idx: encoder interrupt index
  747. * @Return: 0 or -ERROR
  748. */
  749. int sde_encoder_helper_register_irq(struct sde_encoder_phys *phys_enc,
  750. enum sde_intr_idx intr_idx);
  751. /**
  752. * sde_encoder_helper_unregister_irq - unregister and disable an irq
  753. * @phys_enc: Pointer to physical encoder structure
  754. * @intr_idx: encoder interrupt index
  755. * @Return: 0 or -ERROR
  756. */
  757. int sde_encoder_helper_unregister_irq(struct sde_encoder_phys *phys_enc,
  758. enum sde_intr_idx intr_idx);
  759. /**
  760. * sde_encoder_helper_update_intf_cfg - update interface configuration for
  761. * single control path.
  762. * @phys_enc: Pointer to physical encoder structure
  763. */
  764. void sde_encoder_helper_update_intf_cfg(
  765. struct sde_encoder_phys *phys_enc);
  766. /**
  767. * sde_encoder_restore_tearcheck_rd_ptr - restore interface rd_ptr configuration
  768. * This function reads the panel scan line value using a DCS command
  769. * and overrides the internal interface read pointer configuration.
  770. * @phys_enc: Pointer to physical encoder structure
  771. */
  772. void sde_encoder_restore_tearcheck_rd_ptr(struct sde_encoder_phys *phys_enc);
  773. /**
  774. * _sde_encoder_phys_is_dual_ctl - check if encoder needs dual ctl path.
  775. * @phys_enc: Pointer to physical encoder structure
  776. * @Return: true if dual ctl paths else false
  777. */
  778. static inline bool _sde_encoder_phys_is_dual_ctl(
  779. struct sde_encoder_phys *phys_enc)
  780. {
  781. struct sde_kms *sde_kms;
  782. enum sde_rm_topology_name topology;
  783. const struct sde_rm_topology_def* def;
  784. if (!phys_enc) {
  785. pr_err("invalid phys_enc\n");
  786. return false;
  787. }
  788. sde_kms = phys_enc->sde_kms;
  789. if (!sde_kms) {
  790. pr_err("invalid kms\n");
  791. return false;
  792. }
  793. topology = sde_connector_get_topology_name(phys_enc->connector);
  794. def = sde_rm_topology_get_topology_def(&sde_kms->rm, topology);
  795. if (IS_ERR_OR_NULL(def)) {
  796. pr_err("invalid topology\n");
  797. return false;
  798. }
  799. return (def->num_ctl == 2) ? true : false;
  800. }
  801. /**
  802. * _sde_encoder_phys_is_ppsplit - check if pp_split is enabled
  803. * @phys_enc: Pointer to physical encoder structure
  804. * @Return: true or false
  805. */
  806. static inline bool _sde_encoder_phys_is_ppsplit(
  807. struct sde_encoder_phys *phys_enc)
  808. {
  809. enum sde_rm_topology_name topology;
  810. if (!phys_enc) {
  811. pr_err("invalid phys_enc\n");
  812. return false;
  813. }
  814. topology = sde_connector_get_topology_name(phys_enc->connector);
  815. if (topology == SDE_RM_TOPOLOGY_PPSPLIT)
  816. return true;
  817. return false;
  818. }
  819. static inline bool sde_encoder_phys_needs_single_flush(
  820. struct sde_encoder_phys *phys_enc)
  821. {
  822. if (!phys_enc)
  823. return false;
  824. return (_sde_encoder_phys_is_ppsplit(phys_enc) ||
  825. !_sde_encoder_phys_is_dual_ctl(phys_enc));
  826. }
  827. /**
  828. * sde_encoder_helper_hw_fence_extended_wait - extended kickoff wait for hw-fence enabled case
  829. * @phys_enc: Pointer to physical encoder structure
  830. * @ctl: Pointer to hw ctl structure
  831. * @wait_info: Pointer to wait_info structure
  832. * @wait_type: Enum indicating the irq to wait for
  833. * Returns: -ETIMEDOUT in the case that the extended wait times out, 0 otherwise
  834. */
  835. int sde_encoder_helper_hw_fence_extended_wait(struct sde_encoder_phys *phys_enc,
  836. struct sde_hw_ctl *ctl, struct sde_encoder_wait_info *wait_info, int wait_type);
  837. /**
  838. * sde_encoder_helper_phys_disable - helper function to disable virt encoder
  839. * @phys_enc: Pointer to physical encoder structure
  840. * @wb_enc: Pointer to writeback encoder structure
  841. */
  842. void sde_encoder_helper_phys_disable(struct sde_encoder_phys *phys_enc,
  843. struct sde_encoder_phys_wb *wb_enc);
  844. /**
  845. * sde_encoder_helper_phys_reset - helper function to reset virt encoder
  846. * if vsync is missing on phys encoder
  847. * @phys_enc: Pointer to physical encoder structure
  848. */
  849. void sde_encoder_helper_phys_reset(struct sde_encoder_phys *phys_enc);
  850. /**
  851. * sde_encoder_helper_setup_misr - helper function to setup misr
  852. * @phys_enc: Pointer to physical encoder structure
  853. * @enable: enable/disable flag
  854. * @frame_count: frame count for misr
  855. */
  856. void sde_encoder_helper_setup_misr(struct sde_encoder_phys *phys_enc,
  857. bool enable, u32 frame_count);
  858. /**
  859. * sde_encoder_helper_collect_misr - helper function to collect misr
  860. * @phys_enc: Pointer to physical encoder structure
  861. * @nonblock: blocking/non-blocking flag
  862. * @misr_value: pointer to misr value
  863. * @Return: zero on success
  864. */
  865. int sde_encoder_helper_collect_misr(struct sde_encoder_phys *phys_enc,
  866. bool nonblock, u32 *misr_value);
  867. #endif /* __sde_encoder_phys_H__ */