sde_crtc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. /*
  2. * Copyright (c) 2015-2020 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _SDE_CRTC_H_
  19. #define _SDE_CRTC_H_
  20. #include <linux/kthread.h>
  21. #include <linux/of_fdt.h>
  22. #include <drm/drm_crtc.h>
  23. #include "msm_prop.h"
  24. #include "sde_fence.h"
  25. #include "sde_kms.h"
  26. #include "sde_core_perf.h"
  27. #include "sde_hw_ds.h"
  28. #define SDE_CRTC_NAME_SIZE 12
  29. /* define the maximum number of in-flight frame events */
  30. /* Expand it to 2x for handling atleast 2 connectors safely */
  31. #define SDE_CRTC_FRAME_EVENT_SIZE (4 * 2)
  32. /**
  33. * enum sde_crtc_client_type: crtc client type
  34. * @RT_CLIENT: RealTime client like video/cmd mode display
  35. * voting through apps rsc
  36. * @NRT_CLIENT: Non-RealTime client like WB display
  37. * voting through apps rsc
  38. * @RT_RSC_CLIENT: Realtime display RSC voting client
  39. */
  40. enum sde_crtc_client_type {
  41. RT_CLIENT,
  42. NRT_CLIENT,
  43. RT_RSC_CLIENT,
  44. };
  45. /**
  46. * enum sde_crtc_output_capture_point
  47. * @MIXER_OUT : capture mixer output
  48. * @DSPP_OUT : capture output of dspp
  49. */
  50. enum sde_crtc_output_capture_point {
  51. CAPTURE_MIXER_OUT,
  52. CAPTURE_DSPP_OUT
  53. };
  54. /**
  55. * enum sde_crtc_idle_pc_state: states of idle power collapse
  56. * @IDLE_PC_NONE: no-op
  57. * @IDLE_PC_ENABLE: enable idle power-collapse
  58. * @IDLE_PC_DISABLE: disable idle power-collapse
  59. */
  60. enum sde_crtc_idle_pc_state {
  61. IDLE_PC_NONE,
  62. IDLE_PC_ENABLE,
  63. IDLE_PC_DISABLE,
  64. };
  65. /**
  66. * @connectors : Currently associated drm connectors for retire event
  67. * @num_connectors: Number of associated drm connectors for retire event
  68. * @list: event list
  69. */
  70. struct sde_crtc_retire_event {
  71. struct drm_connector *connectors[MAX_CONNECTORS];
  72. int num_connectors;
  73. struct list_head list;
  74. };
  75. /**
  76. * struct sde_crtc_mixer: stores the map for each virtual pipeline in the CRTC
  77. * @hw_lm: LM HW Driver context
  78. * @hw_ctl: CTL Path HW driver context
  79. * @hw_dspp: DSPP HW driver context
  80. * @hw_ds: DS HW driver context
  81. * @encoder: Encoder attached to this lm & ctl
  82. * @mixer_op_mode: mixer blending operation mode
  83. */
  84. struct sde_crtc_mixer {
  85. struct sde_hw_mixer *hw_lm;
  86. struct sde_hw_ctl *hw_ctl;
  87. struct sde_hw_dspp *hw_dspp;
  88. struct sde_hw_ds *hw_ds;
  89. struct drm_encoder *encoder;
  90. u32 mixer_op_mode;
  91. };
  92. /**
  93. * struct sde_crtc_frame_event: stores crtc frame event for crtc processing
  94. * @work: base work structure
  95. * @crtc: Pointer to crtc handling this event
  96. * @connector: pointer to drm connector which is source of frame event
  97. * @list: event list
  98. * @ts: timestamp at queue entry
  99. * @event: event identifier
  100. */
  101. struct sde_crtc_frame_event {
  102. struct kthread_work work;
  103. struct drm_crtc *crtc;
  104. struct drm_connector *connector;
  105. struct list_head list;
  106. ktime_t ts;
  107. u32 event;
  108. };
  109. /**
  110. * struct sde_crtc_event - event callback tracking structure
  111. * @list: Linked list tracking node
  112. * @kt_work: Kthread worker structure
  113. * @sde_crtc: Pointer to associated sde_crtc structure
  114. * @cb_func: Pointer to callback function
  115. * @usr: Pointer to user data to be provided to the callback
  116. */
  117. struct sde_crtc_event {
  118. struct list_head list;
  119. struct kthread_work kt_work;
  120. void *sde_crtc;
  121. void (*cb_func)(struct drm_crtc *crtc, void *usr);
  122. void *usr;
  123. };
  124. /**
  125. * struct sde_crtc_fps_info - structure for measuring fps periodicity
  126. * @frame_count : Total frames during configured periodic duration
  127. * @last_sampled_time_us: Stores the last ktime in microsecs when fps
  128. * was calculated
  129. * @measured_fps : Last measured fps value
  130. * @fps_periodic_duration : Duration in milliseconds to measure the fps.
  131. * Default value is 1 second.
  132. * @time_buf : Buffer for storing ktime of the commits
  133. * @next_time_index : index into time_buf for storing ktime for next commit
  134. */
  135. struct sde_crtc_fps_info {
  136. u32 frame_count;
  137. ktime_t last_sampled_time_us;
  138. u32 measured_fps;
  139. u32 fps_periodic_duration;
  140. ktime_t *time_buf;
  141. u32 next_time_index;
  142. };
  143. /**
  144. * struct sde_ltm_buffer - defines LTM buffer structure.
  145. * @fb: frm framebuffer for the buffer
  146. * @gem: drm gem handle for the buffer
  147. * @asapce : pointer to address space
  148. * @drm_fb_id: framebuffer id associated with this buffer
  149. * @offset: offset for alignment
  150. * @iova: device address
  151. * @kva: kernel virtual address
  152. * @node: list node for LTM buffer list;
  153. */
  154. struct sde_ltm_buffer {
  155. struct drm_framebuffer *fb;
  156. struct drm_gem_object *gem;
  157. struct msm_gem_address_space *aspace;
  158. u32 drm_fb_id;
  159. u32 offset;
  160. u64 iova;
  161. void *kva;
  162. struct list_head node;
  163. };
  164. /**
  165. * struct sde_crtc_misr_info - structure for misr information
  166. * @misr_enable : enable/disable flag
  167. * @misr_frame_count : Number of frames for misr calculation.
  168. */
  169. struct sde_crtc_misr_info {
  170. bool misr_enable;
  171. u32 misr_frame_count;
  172. };
  173. /*
  174. * Maximum number of free event structures to cache
  175. */
  176. #define SDE_CRTC_MAX_EVENT_COUNT 16
  177. /**
  178. * struct sde_crtc - virtualized CRTC data structure
  179. * @base : Base drm crtc structure
  180. * @name : ASCII description of this crtc
  181. * @num_ctls : Number of ctl paths in use
  182. * @num_mixers : Number of mixers in use
  183. * @mixers_swapped: Whether the mixers have been swapped for left/right update
  184. * especially in the case of DSC Merge.
  185. * @mixers : List of active mixers
  186. * @event : Pointer to last received drm vblank event. If there is a
  187. * pending vblank event, this will be non-null.
  188. * @vsync_count : Running count of received vsync events
  189. * @drm_requested_vblank : Whether vblanks have been enabled in the encoder
  190. * @property_info : Opaque structure for generic property support
  191. * @property_defaults : Array of default values for generic property support
  192. * @output_fence : output release fence context
  193. * @stage_cfg : H/w mixer stage configuration
  194. * @active_cfg : H/w pipes active that shouldn't be staged
  195. * @debugfs_root : Parent of debugfs node
  196. * @priv_handle : Pointer to external private handle, if present
  197. * @vblank_cb_count : count of vblank callback since last reset
  198. * @play_count : frame count between crtc enable and disable
  199. * @vblank_cb_time : ktime at vblank count reset
  200. * @vblank_last_cb_time : ktime at last vblank notification
  201. * @sysfs_dev : sysfs device node for crtc
  202. * @vsync_event_sf : vsync event notifier sysfs device
  203. * @enabled : whether the SDE CRTC is currently enabled. updated in the
  204. * commit-thread, not state-swap time which is earlier, so
  205. * safe to make decisions on during VBLANK on/off work
  206. * @ds_reconfig : force reconfiguration of the destination scaler block
  207. * @feature_list : list of color processing features supported on a crtc
  208. * @active_list : list of color processing features are active
  209. * @dirty_list : list of color processing features are dirty
  210. * @ad_dirty : list containing ad properties that are dirty
  211. * @ad_active : list containing ad properties that are active
  212. * @crtc_lock : crtc lock around create, destroy and access.
  213. * @frame_pending : Whether or not an update is pending
  214. * @frame_events : static allocation of in-flight frame events
  215. * @frame_event_list : available frame event list
  216. * @spin_lock : spin lock for frame event, transaction status, etc...
  217. * @event_thread : Pointer to event handler thread
  218. * @event_worker : Event worker queue
  219. * @event_cache : Local cache of event worker structures
  220. * @event_free_list : List of available event structures
  221. * @event_lock : Spinlock around event handling code
  222. * @misr_enable_sui : boolean entry indicates misr enable/disable status
  223. * for secure cases.
  224. * @misr_enable_debugfs : boolean entry indicates misr enable/disable status
  225. * from debugfs.
  226. * @misr_frame_count : misr frame count provided by client
  227. * @misr_data : store misr data before turning off the clocks.
  228. * @idle_notify_work: delayed worker to notify idle timeout to user space
  229. * @power_event : registered power event handle
  230. * @cur_perf : current performance committed to clock/bandwidth driver
  231. * @plane_mask_old: keeps track of the planes used in the previous commit
  232. * @frame_trigger_mode: frame trigger mode
  233. * @cp_pu_feature_mask: mask indicating cp feature enable for partial update
  234. * @ltm_buffer_cnt : number of ltm buffers
  235. * @ltm_buffers : struct stores ltm buffer related data
  236. * @ltm_buf_free : list of LTM buffers that are available
  237. * @ltm_buf_busy : list of LTM buffers that are been used by HW
  238. * @ltm_hist_en : flag to indicate whether LTM hist is enabled or not
  239. * @ltm_buffer_lock : muttx to protect ltm_buffers allcation and free
  240. * @ltm_lock : Spinlock to protect ltm buffer_cnt, hist_en and ltm lists
  241. * @needs_hw_reset : Initiate a hw ctl reset
  242. */
  243. struct sde_crtc {
  244. struct drm_crtc base;
  245. char name[SDE_CRTC_NAME_SIZE];
  246. /* HW Resources reserved for the crtc */
  247. u32 num_ctls;
  248. u32 num_mixers;
  249. bool mixers_swapped;
  250. struct sde_crtc_mixer mixers[CRTC_DUAL_MIXERS];
  251. struct drm_pending_vblank_event *event;
  252. u32 vsync_count;
  253. struct msm_property_info property_info;
  254. struct msm_property_data property_data[CRTC_PROP_COUNT];
  255. struct drm_property_blob *blob_info;
  256. /* output fence support */
  257. struct sde_fence_context *output_fence;
  258. struct sde_hw_stage_cfg stage_cfg;
  259. struct sde_hw_stage_cfg active_cfg;
  260. struct dentry *debugfs_root;
  261. void *priv_handle;
  262. u32 vblank_cb_count;
  263. u64 play_count;
  264. ktime_t vblank_cb_time;
  265. ktime_t vblank_last_cb_time;
  266. struct sde_crtc_fps_info fps_info;
  267. struct device *sysfs_dev;
  268. struct kernfs_node *vsync_event_sf;
  269. bool enabled;
  270. bool ds_reconfig;
  271. struct list_head feature_list;
  272. struct list_head active_list;
  273. struct list_head dirty_list;
  274. struct list_head ad_dirty;
  275. struct list_head ad_active;
  276. struct list_head user_event_list;
  277. struct mutex crtc_lock;
  278. struct mutex crtc_cp_lock;
  279. atomic_t frame_pending;
  280. struct sde_crtc_frame_event frame_events[SDE_CRTC_FRAME_EVENT_SIZE];
  281. struct list_head frame_event_list;
  282. spinlock_t spin_lock;
  283. /* for handling internal event thread */
  284. struct sde_crtc_event event_cache[SDE_CRTC_MAX_EVENT_COUNT];
  285. struct list_head event_free_list;
  286. spinlock_t event_lock;
  287. bool misr_enable_sui;
  288. bool misr_enable_debugfs;
  289. u32 misr_frame_count;
  290. struct kthread_delayed_work idle_notify_work;
  291. struct sde_power_event *power_event;
  292. struct sde_core_perf_params cur_perf;
  293. struct sde_core_perf_params new_perf;
  294. u32 plane_mask_old;
  295. /* blob for histogram data */
  296. struct drm_property_blob *hist_blob;
  297. enum frame_trigger_mode_type frame_trigger_mode;
  298. u32 cp_pu_feature_mask;
  299. u32 ltm_buffer_cnt;
  300. struct sde_ltm_buffer *ltm_buffers[LTM_BUFFER_SIZE];
  301. struct list_head ltm_buf_free;
  302. struct list_head ltm_buf_busy;
  303. bool ltm_hist_en;
  304. struct drm_msm_ltm_cfg_param ltm_cfg;
  305. struct mutex ltm_buffer_lock;
  306. spinlock_t ltm_lock;
  307. bool needs_hw_reset;
  308. };
  309. #define to_sde_crtc(x) container_of(x, struct sde_crtc, base)
  310. /**
  311. * struct sde_crtc_state - sde container for atomic crtc state
  312. * @base: Base drm crtc state structure
  313. * @connectors : Currently associated drm connectors
  314. * @num_connectors: Number of associated drm connectors
  315. * @rsc_client : sde rsc client when mode is valid
  316. * @is_ppsplit : Whether current topology requires PPSplit special handling
  317. * @bw_control : true if bw/clk controlled by core bw/clk properties
  318. * @bw_split_vote : true if bw controlled by llcc/dram bw properties
  319. * @crtc_roi : Current CRTC ROI. Possibly sub-rectangle of mode.
  320. * Origin top left of CRTC.
  321. * @lm_bounds : LM boundaries based on current mode full resolution, no ROI.
  322. * Origin top left of CRTC.
  323. * @lm_roi : Current LM ROI, possibly sub-rectangle of mode.
  324. * Origin top left of CRTC.
  325. * @user_roi_list : List of user's requested ROIs as from set property
  326. * @cached_user_roi_list : Copy of user_roi_list from previous PU frame
  327. * @property_state: Local storage for msm_prop properties
  328. * @property_values: Current crtc property values
  329. * @input_fence_timeout_ns : Cached input fence timeout, in ns
  330. * @num_dim_layers: Number of dim layers
  331. * @dim_layer: Dim layer configs
  332. * @num_ds: Number of destination scalers to be configured
  333. * @num_ds_enabled: Number of destination scalers enabled
  334. * @ds_dirty: Boolean to indicate if dirty or not
  335. * @ds_cfg: Destination scaler config
  336. * @scl3_lut_cfg: QSEED3 lut config
  337. * @new_perf: new performance state being requested
  338. */
  339. struct sde_crtc_state {
  340. struct drm_crtc_state base;
  341. struct drm_connector *connectors[MAX_CONNECTORS];
  342. int num_connectors;
  343. struct sde_rsc_client *rsc_client;
  344. bool rsc_update;
  345. bool bw_control;
  346. bool bw_split_vote;
  347. bool is_ppsplit;
  348. struct sde_rect crtc_roi;
  349. struct sde_rect lm_bounds[CRTC_DUAL_MIXERS];
  350. struct sde_rect lm_roi[CRTC_DUAL_MIXERS];
  351. struct msm_roi_list user_roi_list, cached_user_roi_list;
  352. struct msm_property_state property_state;
  353. struct msm_property_value property_values[CRTC_PROP_COUNT];
  354. uint64_t input_fence_timeout_ns;
  355. uint32_t num_dim_layers;
  356. struct sde_hw_dim_layer dim_layer[SDE_MAX_DIM_LAYERS];
  357. uint32_t num_ds;
  358. uint32_t num_ds_enabled;
  359. bool ds_dirty;
  360. struct sde_hw_ds_cfg ds_cfg[SDE_MAX_DS_COUNT];
  361. struct sde_hw_scaler3_lut_cfg scl3_lut_cfg;
  362. struct sde_core_perf_params new_perf;
  363. };
  364. enum sde_crtc_irq_state {
  365. IRQ_NOINIT,
  366. IRQ_ENABLED,
  367. IRQ_DISABLING,
  368. IRQ_DISABLED,
  369. };
  370. /**
  371. * sde_crtc_irq_info - crtc interrupt info
  372. * @irq: interrupt callback
  373. * @event: event type of the interrupt
  374. * @func: function pointer to enable/disable the interrupt
  375. * @list: list of user customized event in crtc
  376. * @state: state of the interrupt
  377. * @state_lock: spin lock for interrupt state
  378. */
  379. struct sde_crtc_irq_info {
  380. struct sde_irq_callback irq;
  381. u32 event;
  382. int (*func)(struct drm_crtc *crtc, bool en,
  383. struct sde_irq_callback *irq);
  384. struct list_head list;
  385. enum sde_crtc_irq_state state;
  386. spinlock_t state_lock;
  387. };
  388. #define to_sde_crtc_state(x) \
  389. container_of(x, struct sde_crtc_state, base)
  390. /**
  391. * sde_crtc_get_property - query integer value of crtc property
  392. * @S: Pointer to crtc state
  393. * @X: Property index, from enum msm_mdp_crtc_property
  394. * Returns: Integer value of requested property
  395. */
  396. #define sde_crtc_get_property(S, X) \
  397. ((S) && ((X) < CRTC_PROP_COUNT) ? ((S)->property_values[(X)].value) : 0)
  398. /**
  399. * sde_crtc_get_mixer_width - get the mixer width
  400. * Mixer width will be same as panel width(/2 for split)
  401. * unless destination scaler feature is enabled
  402. */
  403. static inline int sde_crtc_get_mixer_width(struct sde_crtc *sde_crtc,
  404. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  405. {
  406. u32 mixer_width;
  407. if (!sde_crtc || !cstate || !mode)
  408. return 0;
  409. if (cstate->num_ds_enabled)
  410. mixer_width = cstate->ds_cfg[0].lm_width;
  411. else
  412. mixer_width = (sde_crtc->num_mixers == CRTC_DUAL_MIXERS ?
  413. mode->hdisplay / CRTC_DUAL_MIXERS : mode->hdisplay);
  414. return mixer_width;
  415. }
  416. /**
  417. * sde_crtc_get_mixer_height - get the mixer height
  418. * Mixer height will be same as panel height unless
  419. * destination scaler feature is enabled
  420. */
  421. static inline int sde_crtc_get_mixer_height(struct sde_crtc *sde_crtc,
  422. struct sde_crtc_state *cstate, struct drm_display_mode *mode)
  423. {
  424. if (!sde_crtc || !cstate || !mode)
  425. return 0;
  426. return (cstate->num_ds_enabled ?
  427. cstate->ds_cfg[0].lm_height : mode->vdisplay);
  428. }
  429. /**
  430. * sde_crtc_get_num_datapath - get the number of datapath active
  431. * @crtc: Pointer to drm crtc object
  432. */
  433. static inline int sde_crtc_get_num_datapath(struct drm_crtc *crtc)
  434. {
  435. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  436. return sde_crtc ? sde_crtc->num_mixers : 0;
  437. }
  438. /**
  439. * sde_crtc_frame_pending - retun the number of pending frames
  440. * @crtc: Pointer to drm crtc object
  441. */
  442. static inline int sde_crtc_frame_pending(struct drm_crtc *crtc)
  443. {
  444. struct sde_crtc *sde_crtc;
  445. if (!crtc)
  446. return -EINVAL;
  447. sde_crtc = to_sde_crtc(crtc);
  448. return atomic_read(&sde_crtc->frame_pending);
  449. }
  450. /**
  451. * sde_crtc_set_needs_hw_reset - set hw reset flag, to handle reset during
  452. * commit kickoff
  453. * @crtc: Pointer to DRM crtc instance
  454. */
  455. static inline void sde_crtc_set_needs_hw_reset(struct drm_crtc *crtc)
  456. {
  457. struct sde_crtc *sde_crtc;
  458. if (!crtc)
  459. return;
  460. sde_crtc = to_sde_crtc(crtc);
  461. sde_crtc->needs_hw_reset = true;
  462. }
  463. /**
  464. * sde_crtc_reset_hw - attempt hardware reset on errors
  465. * @crtc: Pointer to DRM crtc instance
  466. * @old_state: Pointer to crtc state for previous commit
  467. * @recovery_events: Whether or not recovery events are enabled
  468. * Returns: Zero if current commit should still be attempted
  469. */
  470. int sde_crtc_reset_hw(struct drm_crtc *crtc, struct drm_crtc_state *old_state,
  471. bool recovery_events);
  472. /**
  473. * sde_crtc_request_frame_reset - requests for next frame reset
  474. * @crtc: Pointer to drm crtc object
  475. */
  476. static inline int sde_crtc_request_frame_reset(struct drm_crtc *crtc)
  477. {
  478. struct sde_crtc *sde_crtc = to_sde_crtc(crtc);
  479. if (sde_crtc->frame_trigger_mode == FRAME_DONE_WAIT_POSTED_START)
  480. sde_crtc_reset_hw(crtc, crtc->state, false);
  481. return 0;
  482. }
  483. /**
  484. * sde_crtc_vblank - enable or disable vblanks for this crtc
  485. * @crtc: Pointer to drm crtc object
  486. * @en: true to enable vblanks, false to disable
  487. */
  488. int sde_crtc_vblank(struct drm_crtc *crtc, bool en);
  489. /**
  490. * sde_crtc_commit_kickoff - trigger kickoff of the commit for this crtc
  491. * @crtc: Pointer to drm crtc object
  492. * @old_state: Pointer to drm crtc old state object
  493. */
  494. void sde_crtc_commit_kickoff(struct drm_crtc *crtc,
  495. struct drm_crtc_state *old_state);
  496. /**
  497. * sde_crtc_prepare_commit - callback to prepare for output fences
  498. * @crtc: Pointer to drm crtc object
  499. * @old_state: Pointer to drm crtc old state object
  500. */
  501. void sde_crtc_prepare_commit(struct drm_crtc *crtc,
  502. struct drm_crtc_state *old_state);
  503. /**
  504. * sde_crtc_complete_commit - callback signalling completion of current commit
  505. * @crtc: Pointer to drm crtc object
  506. * @old_state: Pointer to drm crtc old state object
  507. */
  508. void sde_crtc_complete_commit(struct drm_crtc *crtc,
  509. struct drm_crtc_state *old_state);
  510. /**
  511. * sde_crtc_init - create a new crtc object
  512. * @dev: sde device
  513. * @plane: base plane
  514. * @Return: new crtc object or error
  515. */
  516. struct drm_crtc *sde_crtc_init(struct drm_device *dev, struct drm_plane *plane);
  517. /**
  518. * sde_crtc_post_init - update crtc object with post initialization. It
  519. * can update the debugfs, sysfs, entires.
  520. * @dev: sde device
  521. * @crtc: Pointer to drm crtc structure
  522. */
  523. int sde_crtc_post_init(struct drm_device *dev, struct drm_crtc *crtc);
  524. /**
  525. * sde_crtc_complete_flip - complete flip for clients
  526. * @crtc: Pointer to drm crtc object
  527. * @file: client to cancel's file handle
  528. */
  529. void sde_crtc_complete_flip(struct drm_crtc *crtc, struct drm_file *file);
  530. /**
  531. * sde_crtc_register_custom_event - api for enabling/disabling crtc event
  532. * @kms: Pointer to sde_kms
  533. * @crtc_drm: Pointer to crtc object
  534. * @event: Event that client is interested
  535. * @en: Flag to enable/disable the event
  536. */
  537. int sde_crtc_register_custom_event(struct sde_kms *kms,
  538. struct drm_crtc *crtc_drm, u32 event, bool en);
  539. /**
  540. * sde_crtc_get_intf_mode - get interface mode of the given crtc
  541. * @crtc: Pointert to DRM crtc
  542. * @crtc: Pointert to DRM crtc_state
  543. */
  544. enum sde_intf_mode sde_crtc_get_intf_mode(struct drm_crtc *crtc,
  545. struct drm_crtc_state *cstate);
  546. /**
  547. * sde_crtc_get_fps_mode - get frame rate of the given crtc
  548. * @crtc: Pointert to crtc
  549. */
  550. u32 sde_crtc_get_fps_mode(struct drm_crtc *crtc);
  551. /**
  552. * sde_crtc_get_client_type - check the crtc type- rt, rsc_rt, etc.
  553. * @crtc: Pointer to crtc
  554. */
  555. static inline enum sde_crtc_client_type sde_crtc_get_client_type(
  556. struct drm_crtc *crtc)
  557. {
  558. struct sde_crtc_state *cstate =
  559. crtc ? to_sde_crtc_state(crtc->state) : NULL;
  560. if (!cstate)
  561. return RT_CLIENT;
  562. return cstate->rsc_client ? RT_RSC_CLIENT : RT_CLIENT;
  563. }
  564. /**
  565. * sde_crtc_is_rt_client - check if real-time client or not
  566. * @crtc: Pointer to DRM crtc
  567. * @crtc_state: Pointer to DRM crtc_state
  568. */
  569. static inline bool sde_crtc_is_rt_client(struct drm_crtc *crtc,
  570. struct drm_crtc_state *cstate)
  571. {
  572. if (!crtc || !cstate)
  573. return true;
  574. return (sde_crtc_get_intf_mode(crtc, cstate) != INTF_MODE_WB_LINE);
  575. }
  576. /**
  577. * sde_crtc_is_enabled - check if sde crtc is enabled or not
  578. * @crtc: Pointer to crtc
  579. */
  580. static inline bool sde_crtc_is_enabled(struct drm_crtc *crtc)
  581. {
  582. return crtc ? crtc->enabled : false;
  583. }
  584. /**
  585. * sde_crtc_is_reset_required - validate the reset request based on the
  586. * pm_suspend and crtc's active status. crtc's are left active
  587. * on pm_suspend during LP1/LP2 states, as the display is still
  588. * left ON. Avoid reset for the subsequent pm_resume in such cases.
  589. * @crtc: Pointer to crtc
  590. * return: false if in suspend state and crtc active, true otherwise
  591. */
  592. static inline bool sde_crtc_is_reset_required(struct drm_crtc *crtc)
  593. {
  594. /*
  595. * reset is required even when there is no crtc_state as it is required
  596. * to create the initial state object
  597. */
  598. if (!crtc || !crtc->state)
  599. return true;
  600. /* reset not required if crtc is active during suspend state */
  601. if (sde_kms_is_suspend_state(crtc->dev) && crtc->state->active)
  602. return false;
  603. return true;
  604. }
  605. /**
  606. * sde_crtc_event_queue - request event callback
  607. * @crtc: Pointer to drm crtc structure
  608. * @func: Pointer to callback function
  609. * @usr: Pointer to user data to be passed to callback
  610. * @color_processing_event: True if color processing event
  611. * Returns: Zero on success
  612. */
  613. int sde_crtc_event_queue(struct drm_crtc *crtc,
  614. void (*func)(struct drm_crtc *crtc, void *usr),
  615. void *usr, bool color_processing_event);
  616. /**
  617. * sde_crtc_get_crtc_roi - retrieve the crtc_roi from the given state object
  618. * used to allow the planes to adjust their final lm out_xy value in the
  619. * case of partial update
  620. * @crtc_state: Pointer to crtc state
  621. * @crtc_roi: Output pointer to crtc roi in the given state
  622. */
  623. void sde_crtc_get_crtc_roi(struct drm_crtc_state *state,
  624. const struct sde_rect **crtc_roi);
  625. /**
  626. * sde_crtc_is_crtc_roi_dirty - retrieve whether crtc_roi was updated this frame
  627. * Note: Only use during atomic_check since dirty properties may be popped
  628. * @crtc_state: Pointer to crtc state
  629. * Return: true if roi is dirty, false otherwise
  630. */
  631. bool sde_crtc_is_crtc_roi_dirty(struct drm_crtc_state *state);
  632. /** sde_crt_get_secure_level - retrieve the secure level from the give state
  633. * object, this is used to determine the secure state of the crtc
  634. * @crtc : Pointer to drm crtc structure
  635. * @usr: Pointer to drm crtc state
  636. * return: secure_level
  637. */
  638. static inline int sde_crtc_get_secure_level(struct drm_crtc *crtc,
  639. struct drm_crtc_state *state)
  640. {
  641. if (!crtc || !state)
  642. return -EINVAL;
  643. return sde_crtc_get_property(to_sde_crtc_state(state),
  644. CRTC_PROP_SECURITY_LEVEL);
  645. }
  646. /** sde_crtc_atomic_check_has_modeset - checks if the new_crtc_state in the
  647. * drm_atomic_state has a modeset
  648. * @state : pointer to drm_atomic_state
  649. * @crtc : Pointer to drm crtc structure
  650. * Returns true if crtc has modeset
  651. */
  652. static inline bool sde_crtc_atomic_check_has_modeset(
  653. struct drm_atomic_state *state, struct drm_crtc *crtc)
  654. {
  655. struct drm_crtc_state *crtc_state;
  656. if (!state || !crtc)
  657. return false;
  658. crtc_state = drm_atomic_get_new_crtc_state(state,
  659. crtc);
  660. return (crtc_state && drm_atomic_crtc_needs_modeset(crtc_state));
  661. }
  662. /**
  663. * sde_crtc_get_secure_transition - determines the operations to be
  664. * performed before transitioning to secure state
  665. * This function should be called after swapping the new state
  666. * @crtc: Pointer to drm crtc structure
  667. * @old_crtc_state: Poniter to previous CRTC state
  668. * Returns the bitmask of operations need to be performed, -Error in
  669. * case of error cases
  670. */
  671. int sde_crtc_get_secure_transition_ops(struct drm_crtc *crtc,
  672. struct drm_crtc_state *old_crtc_state,
  673. bool old_valid_fb);
  674. /**
  675. * sde_crtc_find_plane_fb_modes - finds the modes of all planes attached
  676. * to crtc
  677. * @crtc: Pointer to DRM crtc object
  678. * @fb_ns: number of non secure planes
  679. * @fb_sec: number of secure-playback planes
  680. * @fb_sec_dir: number of secure-ui/secure-camera planes
  681. */
  682. int sde_crtc_find_plane_fb_modes(struct drm_crtc *crtc,
  683. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  684. /**
  685. * sde_crtc_state_find_plane_fb_modes - finds the modes of all planes attached
  686. * to the crtc state
  687. * @crtc_state: Pointer to DRM crtc state object
  688. * @fb_ns: number of non secure planes
  689. * @fb_sec: number of secure-playback planes
  690. * @fb_sec_dir: number of secure-ui/secure-camera planes
  691. */
  692. int sde_crtc_state_find_plane_fb_modes(struct drm_crtc_state *state,
  693. uint32_t *fb_ns, uint32_t *fb_sec, uint32_t *fb_sec_dir);
  694. /**
  695. * sde_crtc_secure_ctrl - Initiates the transition between secure and
  696. * non-secure world
  697. * @crtc: Pointer to crtc
  698. * @post_commit: if this operation is triggered after commit
  699. */
  700. int sde_crtc_secure_ctrl(struct drm_crtc *crtc, bool post_commit);
  701. /**
  702. * sde_crtc_helper_reset_properties - reset properties to default values in the
  703. * given DRM CRTC state object
  704. * @crtc: Pointer to DRM crtc object
  705. * @crtc_state: Pointer to DRM crtc state object
  706. * Returns: 0 on success, negative errno on failure
  707. */
  708. int sde_crtc_helper_reset_custom_properties(struct drm_crtc *crtc,
  709. struct drm_crtc_state *crtc_state);
  710. /**
  711. * sde_crtc_timeline_status - current buffer timeline status
  712. * @crtc: Pointer to crtc
  713. */
  714. void sde_crtc_timeline_status(struct drm_crtc *crtc);
  715. /**
  716. * sde_crtc_update_cont_splash_settings - update mixer settings
  717. * during device bootup for cont_splash use case
  718. * @crtc: Pointer to drm crtc structure
  719. */
  720. void sde_crtc_update_cont_splash_settings(
  721. struct drm_crtc *crtc);
  722. /**
  723. * sde_crtc_misr_setup - to configure and enable/disable MISR
  724. * @crtc: Pointer to drm crtc structure
  725. * @enable: boolean to indicate enable/disable misr
  726. * @frame_count: frame_count to be configured
  727. */
  728. void sde_crtc_misr_setup(struct drm_crtc *crtc, bool enable, u32 frame_count);
  729. /**
  730. * sde_crtc_get_misr_info - to configure and enable/disable MISR
  731. * @crtc: Pointer to drm crtc structure
  732. * @crtc_misr_info: Pointer to crtc misr info structure
  733. */
  734. void sde_crtc_get_misr_info(struct drm_crtc *crtc,
  735. struct sde_crtc_misr_info *crtc_misr_info);
  736. #endif /* _SDE_CRTC_H_ */