sde_encoder_phys.h 27 KB

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