sde_encoder_phys.h 30 KB

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