Merge tag 'drm-intel-next-2022-10-28' of git://anongit.freedesktop.org/drm/drm-intel...
[platform/kernel/linux-rpi.git] / drivers / gpu / drm / i915 / display / intel_display_types.h
1 /*
2  * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
3  * Copyright (c) 2007-2008 Intel Corporation
4  *   Jesse Barnes <jesse.barnes@intel.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25
26 #ifndef __INTEL_DISPLAY_TYPES_H__
27 #define __INTEL_DISPLAY_TYPES_H__
28
29 #include <linux/i2c.h>
30 #include <linux/pm_qos.h>
31 #include <linux/pwm.h>
32 #include <linux/sched/clock.h>
33
34 #include <drm/display/drm_dp_dual_mode_helper.h>
35 #include <drm/display/drm_dp_mst_helper.h>
36 #include <drm/display/drm_dsc.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_encoder.h>
40 #include <drm/drm_fourcc.h>
41 #include <drm/drm_framebuffer.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
44 #include <drm/drm_vblank.h>
45 #include <drm/drm_vblank_work.h>
46 #include <drm/i915_mei_hdcp_interface.h>
47 #include <media/cec-notifier.h>
48
49 #include "i915_vma.h"
50 #include "i915_vma_types.h"
51 #include "intel_bios.h"
52 #include "intel_display.h"
53 #include "intel_display_power.h"
54 #include "intel_dpll_mgr.h"
55 #include "intel_pm_types.h"
56
57 struct drm_printer;
58 struct __intel_global_objs_state;
59 struct intel_ddi_buf_trans;
60 struct intel_fbc;
61 struct intel_connector;
62
63 /*
64  * Display related stuff
65  */
66
67 /* these are outputs from the chip - integrated only
68    external chips are via DVO or SDVO output */
69 enum intel_output_type {
70         INTEL_OUTPUT_UNUSED = 0,
71         INTEL_OUTPUT_ANALOG = 1,
72         INTEL_OUTPUT_DVO = 2,
73         INTEL_OUTPUT_SDVO = 3,
74         INTEL_OUTPUT_LVDS = 4,
75         INTEL_OUTPUT_TVOUT = 5,
76         INTEL_OUTPUT_HDMI = 6,
77         INTEL_OUTPUT_DP = 7,
78         INTEL_OUTPUT_EDP = 8,
79         INTEL_OUTPUT_DSI = 9,
80         INTEL_OUTPUT_DDI = 10,
81         INTEL_OUTPUT_DP_MST = 11,
82 };
83
84 enum hdmi_force_audio {
85         HDMI_AUDIO_OFF_DVI = -2,        /* no aux data for HDMI-DVI converter */
86         HDMI_AUDIO_OFF,                 /* force turn off HDMI audio */
87         HDMI_AUDIO_AUTO,                /* trust EDID */
88         HDMI_AUDIO_ON,                  /* force turn on HDMI audio */
89 };
90
91 /* "Broadcast RGB" property */
92 enum intel_broadcast_rgb {
93         INTEL_BROADCAST_RGB_AUTO,
94         INTEL_BROADCAST_RGB_FULL,
95         INTEL_BROADCAST_RGB_LIMITED,
96 };
97
98 struct intel_fb_view {
99         /*
100          * The remap information used in the remapped and rotated views to
101          * create the DMA scatter-gather list for each FB color plane. This sg
102          * list is created along with the view type (gtt.type) specific
103          * i915_vma object and contains the list of FB object pages (reordered
104          * in the rotated view) that are visible in the view.
105          * In the normal view the FB object's backing store sg list is used
106          * directly and hence the remap information here is not used.
107          */
108         struct i915_gtt_view gtt;
109
110         /*
111          * The GTT view (gtt.type) specific information for each FB color
112          * plane. In the normal GTT view all formats (up to 4 color planes),
113          * in the rotated and remapped GTT view all no-CCS formats (up to 2
114          * color planes) are supported.
115          *
116          * The view information shared by all FB color planes in the FB,
117          * like dst x/y and src/dst width, is stored separately in
118          * intel_plane_state.
119          */
120         struct i915_color_plane_view {
121                 u32 offset;
122                 unsigned int x, y;
123                 /*
124                  * Plane stride in:
125                  *   bytes for 0/180 degree rotation
126                  *   pixels for 90/270 degree rotation
127                  */
128                 unsigned int mapping_stride;
129                 unsigned int scanout_stride;
130         } color_plane[4];
131 };
132
133 struct intel_framebuffer {
134         struct drm_framebuffer base;
135         struct intel_frontbuffer *frontbuffer;
136
137         /* Params to remap the FB pages and program the plane registers in each view. */
138         struct intel_fb_view normal_view;
139         union {
140                 struct intel_fb_view rotated_view;
141                 struct intel_fb_view remapped_view;
142         };
143
144         struct i915_address_space *dpt_vm;
145 };
146
147 enum intel_hotplug_state {
148         INTEL_HOTPLUG_UNCHANGED,
149         INTEL_HOTPLUG_CHANGED,
150         INTEL_HOTPLUG_RETRY,
151 };
152
153 struct intel_encoder {
154         struct drm_encoder base;
155
156         enum intel_output_type type;
157         enum port port;
158         u16 cloneable;
159         u8 pipe_mask;
160         enum intel_hotplug_state (*hotplug)(struct intel_encoder *encoder,
161                                             struct intel_connector *connector);
162         enum intel_output_type (*compute_output_type)(struct intel_encoder *,
163                                                       struct intel_crtc_state *,
164                                                       struct drm_connector_state *);
165         int (*compute_config)(struct intel_encoder *,
166                               struct intel_crtc_state *,
167                               struct drm_connector_state *);
168         int (*compute_config_late)(struct intel_encoder *,
169                                    struct intel_crtc_state *,
170                                    struct drm_connector_state *);
171         void (*update_prepare)(struct intel_atomic_state *,
172                                struct intel_encoder *,
173                                struct intel_crtc *);
174         void (*pre_pll_enable)(struct intel_atomic_state *,
175                                struct intel_encoder *,
176                                const struct intel_crtc_state *,
177                                const struct drm_connector_state *);
178         void (*pre_enable)(struct intel_atomic_state *,
179                            struct intel_encoder *,
180                            const struct intel_crtc_state *,
181                            const struct drm_connector_state *);
182         void (*enable)(struct intel_atomic_state *,
183                        struct intel_encoder *,
184                        const struct intel_crtc_state *,
185                        const struct drm_connector_state *);
186         void (*update_complete)(struct intel_atomic_state *,
187                                 struct intel_encoder *,
188                                 struct intel_crtc *);
189         void (*disable)(struct intel_atomic_state *,
190                         struct intel_encoder *,
191                         const struct intel_crtc_state *,
192                         const struct drm_connector_state *);
193         void (*post_disable)(struct intel_atomic_state *,
194                              struct intel_encoder *,
195                              const struct intel_crtc_state *,
196                              const struct drm_connector_state *);
197         void (*post_pll_disable)(struct intel_atomic_state *,
198                                  struct intel_encoder *,
199                                  const struct intel_crtc_state *,
200                                  const struct drm_connector_state *);
201         void (*update_pipe)(struct intel_atomic_state *,
202                             struct intel_encoder *,
203                             const struct intel_crtc_state *,
204                             const struct drm_connector_state *);
205         /* Read out the current hw state of this connector, returning true if
206          * the encoder is active. If the encoder is enabled it also set the pipe
207          * it is connected to in the pipe parameter. */
208         bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
209         /* Reconstructs the equivalent mode flags for the current hardware
210          * state. This must be called _after_ display->get_pipe_config has
211          * pre-filled the pipe config. Note that intel_encoder->base.crtc must
212          * be set correctly before calling this function. */
213         void (*get_config)(struct intel_encoder *,
214                            struct intel_crtc_state *pipe_config);
215
216         /*
217          * Optional hook called during init/resume to sync any state
218          * stored in the encoder (eg. DP link parameters) wrt. the HW state.
219          */
220         void (*sync_state)(struct intel_encoder *encoder,
221                            const struct intel_crtc_state *crtc_state);
222
223         /*
224          * Optional hook, returning true if this encoder allows a fastset
225          * during the initial commit, false otherwise.
226          */
227         bool (*initial_fastset_check)(struct intel_encoder *encoder,
228                                       struct intel_crtc_state *crtc_state);
229
230         /*
231          * Acquires the power domains needed for an active encoder during
232          * hardware state readout.
233          */
234         void (*get_power_domains)(struct intel_encoder *encoder,
235                                   struct intel_crtc_state *crtc_state);
236         /*
237          * Called during system suspend after all pending requests for the
238          * encoder are flushed (for example for DP AUX transactions) and
239          * device interrupts are disabled.
240          */
241         void (*suspend)(struct intel_encoder *);
242         /*
243          * Called during system reboot/shutdown after all the
244          * encoders have been disabled and suspended.
245          */
246         void (*shutdown)(struct intel_encoder *encoder);
247         /*
248          * Enable/disable the clock to the port.
249          */
250         void (*enable_clock)(struct intel_encoder *encoder,
251                              const struct intel_crtc_state *crtc_state);
252         void (*disable_clock)(struct intel_encoder *encoder);
253         /*
254          * Returns whether the port clock is enabled or not.
255          */
256         bool (*is_clock_enabled)(struct intel_encoder *encoder);
257         const struct intel_ddi_buf_trans *(*get_buf_trans)(struct intel_encoder *encoder,
258                                                            const struct intel_crtc_state *crtc_state,
259                                                            int *n_entries);
260         void (*set_signal_levels)(struct intel_encoder *encoder,
261                                   const struct intel_crtc_state *crtc_state);
262
263         enum hpd_pin hpd_pin;
264         enum intel_display_power_domain power_domain;
265         /* for communication with audio component; protected by av_mutex */
266         const struct drm_connector *audio_connector;
267
268         /* VBT information for this encoder (may be NULL for older platforms) */
269         const struct intel_bios_encoder_data *devdata;
270 };
271
272 struct intel_panel_bl_funcs {
273         /* Connector and platform specific backlight functions */
274         int (*setup)(struct intel_connector *connector, enum pipe pipe);
275         u32 (*get)(struct intel_connector *connector, enum pipe pipe);
276         void (*set)(const struct drm_connector_state *conn_state, u32 level);
277         void (*disable)(const struct drm_connector_state *conn_state, u32 level);
278         void (*enable)(const struct intel_crtc_state *crtc_state,
279                        const struct drm_connector_state *conn_state, u32 level);
280         u32 (*hz_to_pwm)(struct intel_connector *connector, u32 hz);
281 };
282
283 enum drrs_type {
284         DRRS_TYPE_NONE,
285         DRRS_TYPE_STATIC,
286         DRRS_TYPE_SEAMLESS,
287 };
288
289 struct intel_vbt_panel_data {
290         struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
291         struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
292
293         /* Feature bits */
294         unsigned int panel_type:4;
295         unsigned int lvds_dither:1;
296         unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
297
298         bool vrr;
299
300         u8 seamless_drrs_min_refresh_rate;
301         enum drrs_type drrs_type;
302
303         struct {
304                 int max_link_rate;
305                 int rate;
306                 int lanes;
307                 int preemphasis;
308                 int vswing;
309                 int bpp;
310                 struct edp_power_seq pps;
311                 u8 drrs_msa_timing_delay;
312                 bool low_vswing;
313                 bool initialized;
314                 bool hobl;
315         } edp;
316
317         struct {
318                 bool enable;
319                 bool full_link;
320                 bool require_aux_wakeup;
321                 int idle_frames;
322                 int tp1_wakeup_time_us;
323                 int tp2_tp3_wakeup_time_us;
324                 int psr2_tp2_tp3_wakeup_time_us;
325         } psr;
326
327         struct {
328                 u16 pwm_freq_hz;
329                 u16 brightness_precision_bits;
330                 bool present;
331                 bool active_low_pwm;
332                 u8 min_brightness;      /* min_brightness/255 of max */
333                 u8 controller;          /* brightness controller number */
334                 enum intel_backlight_type type;
335         } backlight;
336
337         /* MIPI DSI */
338         struct {
339                 u16 panel_id;
340                 struct mipi_config *config;
341                 struct mipi_pps_data *pps;
342                 u16 bl_ports;
343                 u16 cabc_ports;
344                 u8 seq_version;
345                 u32 size;
346                 u8 *data;
347                 const u8 *sequence[MIPI_SEQ_MAX];
348                 u8 *deassert_seq; /* Used by fixup_mipi_sequences() */
349                 enum drm_panel_orientation orientation;
350         } dsi;
351 };
352
353 struct intel_panel {
354         struct list_head fixed_modes;
355
356         /* backlight */
357         struct {
358                 bool present;
359                 u32 level;
360                 u32 min;
361                 u32 max;
362                 bool enabled;
363                 bool combination_mode;  /* gen 2/4 only */
364                 bool active_low_pwm;
365                 bool alternate_pwm_increment;   /* lpt+ */
366
367                 /* PWM chip */
368                 u32 pwm_level_min;
369                 u32 pwm_level_max;
370                 bool pwm_enabled;
371                 bool util_pin_active_low;       /* bxt+ */
372                 u8 controller;          /* bxt+ only */
373                 struct pwm_device *pwm;
374                 struct pwm_state pwm_state;
375
376                 /* DPCD backlight */
377                 union {
378                         struct {
379                                 struct drm_edp_backlight_info info;
380                         } vesa;
381                         struct {
382                                 bool sdr_uses_aux;
383                         } intel;
384                 } edp;
385
386                 struct backlight_device *device;
387
388                 const struct intel_panel_bl_funcs *funcs;
389                 const struct intel_panel_bl_funcs *pwm_funcs;
390                 void (*power)(struct intel_connector *, bool enable);
391         } backlight;
392
393         struct intel_vbt_panel_data vbt;
394 };
395
396 struct intel_digital_port;
397
398 enum check_link_response {
399         HDCP_LINK_PROTECTED     = 0,
400         HDCP_TOPOLOGY_CHANGE,
401         HDCP_LINK_INTEGRITY_FAILURE,
402         HDCP_REAUTH_REQUEST
403 };
404
405 /*
406  * This structure serves as a translation layer between the generic HDCP code
407  * and the bus-specific code. What that means is that HDCP over HDMI differs
408  * from HDCP over DP, so to account for these differences, we need to
409  * communicate with the receiver through this shim.
410  *
411  * For completeness, the 2 buses differ in the following ways:
412  *      - DP AUX vs. DDC
413  *              HDCP registers on the receiver are set via DP AUX for DP, and
414  *              they are set via DDC for HDMI.
415  *      - Receiver register offsets
416  *              The offsets of the registers are different for DP vs. HDMI
417  *      - Receiver register masks/offsets
418  *              For instance, the ready bit for the KSV fifo is in a different
419  *              place on DP vs HDMI
420  *      - Receiver register names
421  *              Seriously. In the DP spec, the 16-bit register containing
422  *              downstream information is called BINFO, on HDMI it's called
423  *              BSTATUS. To confuse matters further, DP has a BSTATUS register
424  *              with a completely different definition.
425  *      - KSV FIFO
426  *              On HDMI, the ksv fifo is read all at once, whereas on DP it must
427  *              be read 3 keys at a time
428  *      - Aksv output
429  *              Since Aksv is hidden in hardware, there's different procedures
430  *              to send it over DP AUX vs DDC
431  */
432 struct intel_hdcp_shim {
433         /* Outputs the transmitter's An and Aksv values to the receiver. */
434         int (*write_an_aksv)(struct intel_digital_port *dig_port, u8 *an);
435
436         /* Reads the receiver's key selection vector */
437         int (*read_bksv)(struct intel_digital_port *dig_port, u8 *bksv);
438
439         /*
440          * Reads BINFO from DP receivers and BSTATUS from HDMI receivers. The
441          * definitions are the same in the respective specs, but the names are
442          * different. Call it BSTATUS since that's the name the HDMI spec
443          * uses and it was there first.
444          */
445         int (*read_bstatus)(struct intel_digital_port *dig_port,
446                             u8 *bstatus);
447
448         /* Determines whether a repeater is present downstream */
449         int (*repeater_present)(struct intel_digital_port *dig_port,
450                                 bool *repeater_present);
451
452         /* Reads the receiver's Ri' value */
453         int (*read_ri_prime)(struct intel_digital_port *dig_port, u8 *ri);
454
455         /* Determines if the receiver's KSV FIFO is ready for consumption */
456         int (*read_ksv_ready)(struct intel_digital_port *dig_port,
457                               bool *ksv_ready);
458
459         /* Reads the ksv fifo for num_downstream devices */
460         int (*read_ksv_fifo)(struct intel_digital_port *dig_port,
461                              int num_downstream, u8 *ksv_fifo);
462
463         /* Reads a 32-bit part of V' from the receiver */
464         int (*read_v_prime_part)(struct intel_digital_port *dig_port,
465                                  int i, u32 *part);
466
467         /* Enables HDCP signalling on the port */
468         int (*toggle_signalling)(struct intel_digital_port *dig_port,
469                                  enum transcoder cpu_transcoder,
470                                  bool enable);
471
472         /* Enable/Disable stream encryption on DP MST Transport Link */
473         int (*stream_encryption)(struct intel_connector *connector,
474                                  bool enable);
475
476         /* Ensures the link is still protected */
477         bool (*check_link)(struct intel_digital_port *dig_port,
478                            struct intel_connector *connector);
479
480         /* Detects panel's hdcp capability. This is optional for HDMI. */
481         int (*hdcp_capable)(struct intel_digital_port *dig_port,
482                             bool *hdcp_capable);
483
484         /* HDCP adaptation(DP/HDMI) required on the port */
485         enum hdcp_wired_protocol protocol;
486
487         /* Detects whether sink is HDCP2.2 capable */
488         int (*hdcp_2_2_capable)(struct intel_digital_port *dig_port,
489                                 bool *capable);
490
491         /* Write HDCP2.2 messages */
492         int (*write_2_2_msg)(struct intel_digital_port *dig_port,
493                              void *buf, size_t size);
494
495         /* Read HDCP2.2 messages */
496         int (*read_2_2_msg)(struct intel_digital_port *dig_port,
497                             u8 msg_id, void *buf, size_t size);
498
499         /*
500          * Implementation of DP HDCP2.2 Errata for the communication of stream
501          * type to Receivers. In DP HDCP2.2 Stream type is one of the input to
502          * the HDCP2.2 Cipher for En/De-Cryption. Not applicable for HDMI.
503          */
504         int (*config_stream_type)(struct intel_digital_port *dig_port,
505                                   bool is_repeater, u8 type);
506
507         /* Enable/Disable HDCP 2.2 stream encryption on DP MST Transport Link */
508         int (*stream_2_2_encryption)(struct intel_connector *connector,
509                                      bool enable);
510
511         /* HDCP2.2 Link Integrity Check */
512         int (*check_2_2_link)(struct intel_digital_port *dig_port,
513                               struct intel_connector *connector);
514 };
515
516 struct intel_hdcp {
517         const struct intel_hdcp_shim *shim;
518         /* Mutex for hdcp state of the connector */
519         struct mutex mutex;
520         u64 value;
521         struct delayed_work check_work;
522         struct work_struct prop_work;
523
524         /* HDCP1.4 Encryption status */
525         bool hdcp_encrypted;
526
527         /* HDCP2.2 related definitions */
528         /* Flag indicates whether this connector supports HDCP2.2 or not. */
529         bool hdcp2_supported;
530
531         /* HDCP2.2 Encryption status */
532         bool hdcp2_encrypted;
533
534         /*
535          * Content Stream Type defined by content owner. TYPE0(0x0) content can
536          * flow in the link protected by HDCP2.2 or HDCP1.4, where as TYPE1(0x1)
537          * content can flow only through a link protected by HDCP2.2.
538          */
539         u8 content_type;
540
541         bool is_paired;
542         bool is_repeater;
543
544         /*
545          * Count of ReceiverID_List received. Initialized to 0 at AKE_INIT.
546          * Incremented after processing the RepeaterAuth_Send_ReceiverID_List.
547          * When it rolls over re-auth has to be triggered.
548          */
549         u32 seq_num_v;
550
551         /*
552          * Count of RepeaterAuth_Stream_Manage msg propagated.
553          * Initialized to 0 on AKE_INIT. Incremented after every successful
554          * transmission of RepeaterAuth_Stream_Manage message. When it rolls
555          * over re-Auth has to be triggered.
556          */
557         u32 seq_num_m;
558
559         /*
560          * Work queue to signal the CP_IRQ. Used for the waiters to read the
561          * available information from HDCP DP sink.
562          */
563         wait_queue_head_t cp_irq_queue;
564         atomic_t cp_irq_count;
565         int cp_irq_count_cached;
566
567         /*
568          * HDCP register access for gen12+ need the transcoder associated.
569          * Transcoder attached to the connector could be changed at modeset.
570          * Hence caching the transcoder here.
571          */
572         enum transcoder cpu_transcoder;
573         /* Only used for DP MST stream encryption */
574         enum transcoder stream_transcoder;
575 };
576
577 struct intel_connector {
578         struct drm_connector base;
579         /*
580          * The fixed encoder this connector is connected to.
581          */
582         struct intel_encoder *encoder;
583
584         /* ACPI device id for ACPI and driver cooperation */
585         u32 acpi_device_id;
586
587         /* Reads out the current hw, returning true if the connector is enabled
588          * and active (i.e. dpms ON state). */
589         bool (*get_hw_state)(struct intel_connector *);
590
591         /* Panel info for eDP and LVDS */
592         struct intel_panel panel;
593
594         /* Cached EDID for eDP and LVDS. May hold ERR_PTR for invalid EDID. */
595         struct edid *edid;
596         struct edid *detect_edid;
597
598         /* Number of times hotplug detection was tried after an HPD interrupt */
599         int hotplug_retries;
600
601         /* since POLL and HPD connectors may use the same HPD line keep the native
602            state of connector->polled in case hotplug storm detection changes it */
603         u8 polled;
604
605         struct drm_dp_mst_port *port;
606
607         struct intel_dp *mst_port;
608
609         /* Work struct to schedule a uevent on link train failure */
610         struct work_struct modeset_retry_work;
611
612         struct intel_hdcp hdcp;
613 };
614
615 struct intel_digital_connector_state {
616         struct drm_connector_state base;
617
618         enum hdmi_force_audio force_audio;
619         int broadcast_rgb;
620 };
621
622 #define to_intel_digital_connector_state(x) container_of(x, struct intel_digital_connector_state, base)
623
624 struct dpll {
625         /* given values */
626         int n;
627         int m1, m2;
628         int p1, p2;
629         /* derived values */
630         int     dot;
631         int     vco;
632         int     m;
633         int     p;
634 };
635
636 struct intel_atomic_state {
637         struct drm_atomic_state base;
638
639         intel_wakeref_t wakeref;
640
641         struct __intel_global_objs_state *global_objs;
642         int num_global_objs;
643
644         bool dpll_set, modeset;
645
646         struct intel_shared_dpll_state shared_dpll[I915_NUM_PLLS];
647
648         /*
649          * Current watermarks can't be trusted during hardware readout, so
650          * don't bother calculating intermediate watermarks.
651          */
652         bool skip_intermediate_wm;
653
654         bool rps_interactive;
655
656         struct i915_sw_fence commit_ready;
657
658         struct llist_node freed;
659 };
660
661 struct intel_plane_state {
662         struct drm_plane_state uapi;
663
664         /*
665          * actual hardware state, the state we program to the hardware.
666          * The following members are used to verify the hardware state:
667          * During initial hw readout, they need to be copied from uapi.
668          */
669         struct {
670                 struct drm_crtc *crtc;
671                 struct drm_framebuffer *fb;
672
673                 u16 alpha;
674                 u16 pixel_blend_mode;
675                 unsigned int rotation;
676                 enum drm_color_encoding color_encoding;
677                 enum drm_color_range color_range;
678                 enum drm_scaling_filter scaling_filter;
679         } hw;
680
681         struct i915_vma *ggtt_vma;
682         struct i915_vma *dpt_vma;
683         unsigned long flags;
684 #define PLANE_HAS_FENCE BIT(0)
685
686         struct intel_fb_view view;
687
688         /* Plane pxp decryption state */
689         bool decrypt;
690
691         /* Plane state to display black pixels when pxp is borked */
692         bool force_black;
693
694         /* plane control register */
695         u32 ctl;
696
697         /* plane color control register */
698         u32 color_ctl;
699
700         /* chroma upsampler control register */
701         u32 cus_ctl;
702
703         /*
704          * scaler_id
705          *    = -1 : not using a scaler
706          *    >=  0 : using a scalers
707          *
708          * plane requiring a scaler:
709          *   - During check_plane, its bit is set in
710          *     crtc_state->scaler_state.scaler_users by calling helper function
711          *     update_scaler_plane.
712          *   - scaler_id indicates the scaler it got assigned.
713          *
714          * plane doesn't require a scaler:
715          *   - this can happen when scaling is no more required or plane simply
716          *     got disabled.
717          *   - During check_plane, corresponding bit is reset in
718          *     crtc_state->scaler_state.scaler_users by calling helper function
719          *     update_scaler_plane.
720          */
721         int scaler_id;
722
723         /*
724          * planar_linked_plane:
725          *
726          * ICL planar formats require 2 planes that are updated as pairs.
727          * This member is used to make sure the other plane is also updated
728          * when required, and for update_slave() to find the correct
729          * plane_state to pass as argument.
730          */
731         struct intel_plane *planar_linked_plane;
732
733         /*
734          * planar_slave:
735          * If set don't update use the linked plane's state for updating
736          * this plane during atomic commit with the update_slave() callback.
737          *
738          * It's also used by the watermark code to ignore wm calculations on
739          * this plane. They're calculated by the linked plane's wm code.
740          */
741         u32 planar_slave;
742
743         struct drm_intel_sprite_colorkey ckey;
744
745         struct drm_rect psr2_sel_fetch_area;
746
747         /* Clear Color Value */
748         u64 ccval;
749
750         const char *no_fbc_reason;
751 };
752
753 struct intel_initial_plane_config {
754         struct intel_framebuffer *fb;
755         struct i915_vma *vma;
756         unsigned int tiling;
757         int size;
758         u32 base;
759         u8 rotation;
760 };
761
762 struct intel_scaler {
763         int in_use;
764         u32 mode;
765 };
766
767 struct intel_crtc_scaler_state {
768 #define SKL_NUM_SCALERS 2
769         struct intel_scaler scalers[SKL_NUM_SCALERS];
770
771         /*
772          * scaler_users: keeps track of users requesting scalers on this crtc.
773          *
774          *     If a bit is set, a user is using a scaler.
775          *     Here user can be a plane or crtc as defined below:
776          *       bits 0-30 - plane (bit position is index from drm_plane_index)
777          *       bit 31    - crtc
778          *
779          * Instead of creating a new index to cover planes and crtc, using
780          * existing drm_plane_index for planes which is well less than 31
781          * planes and bit 31 for crtc. This should be fine to cover all
782          * our platforms.
783          *
784          * intel_atomic_setup_scalers will setup available scalers to users
785          * requesting scalers. It will gracefully fail if request exceeds
786          * avilability.
787          */
788 #define SKL_CRTC_INDEX 31
789         unsigned scaler_users;
790
791         /* scaler used by crtc for panel fitting purpose */
792         int scaler_id;
793 };
794
795 /* {crtc,crtc_state}->mode_flags */
796 /* Flag to get scanline using frame time stamps */
797 #define I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP (1<<1)
798 /* Flag to use the scanline counter instead of the pixel counter */
799 #define I915_MODE_FLAG_USE_SCANLINE_COUNTER (1<<2)
800 /*
801  * TE0 or TE1 flag is set if the crtc has a DSI encoder which
802  * is operating in command mode.
803  * Flag to use TE from DSI0 instead of VBI in command mode
804  */
805 #define I915_MODE_FLAG_DSI_USE_TE0 (1<<3)
806 /* Flag to use TE from DSI1 instead of VBI in command mode */
807 #define I915_MODE_FLAG_DSI_USE_TE1 (1<<4)
808 /* Flag to indicate mipi dsi periodic command mode where we do not get TE */
809 #define I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE (1<<5)
810 /* Do tricks to make vblank timestamps sane with VRR? */
811 #define I915_MODE_FLAG_VRR (1<<6)
812
813 struct intel_wm_level {
814         bool enable;
815         u32 pri_val;
816         u32 spr_val;
817         u32 cur_val;
818         u32 fbc_val;
819 };
820
821 struct intel_pipe_wm {
822         struct intel_wm_level wm[5];
823         bool fbc_wm_enabled;
824         bool pipe_enabled;
825         bool sprites_enabled;
826         bool sprites_scaled;
827 };
828
829 struct skl_wm_level {
830         u16 min_ddb_alloc;
831         u16 blocks;
832         u8 lines;
833         bool enable;
834         bool ignore_lines;
835         bool can_sagv;
836 };
837
838 struct skl_plane_wm {
839         struct skl_wm_level wm[8];
840         struct skl_wm_level uv_wm[8];
841         struct skl_wm_level trans_wm;
842         struct {
843                 struct skl_wm_level wm0;
844                 struct skl_wm_level trans_wm;
845         } sagv;
846         bool is_planar;
847 };
848
849 struct skl_pipe_wm {
850         struct skl_plane_wm planes[I915_MAX_PLANES];
851         bool use_sagv_wm;
852 };
853
854 enum vlv_wm_level {
855         VLV_WM_LEVEL_PM2,
856         VLV_WM_LEVEL_PM5,
857         VLV_WM_LEVEL_DDR_DVFS,
858         NUM_VLV_WM_LEVELS,
859 };
860
861 struct vlv_wm_state {
862         struct g4x_pipe_wm wm[NUM_VLV_WM_LEVELS];
863         struct g4x_sr_wm sr[NUM_VLV_WM_LEVELS];
864         u8 num_levels;
865         bool cxsr;
866 };
867
868 struct vlv_fifo_state {
869         u16 plane[I915_MAX_PLANES];
870 };
871
872 enum g4x_wm_level {
873         G4X_WM_LEVEL_NORMAL,
874         G4X_WM_LEVEL_SR,
875         G4X_WM_LEVEL_HPLL,
876         NUM_G4X_WM_LEVELS,
877 };
878
879 struct g4x_wm_state {
880         struct g4x_pipe_wm wm;
881         struct g4x_sr_wm sr;
882         struct g4x_sr_wm hpll;
883         bool cxsr;
884         bool hpll_en;
885         bool fbc_en;
886 };
887
888 struct intel_crtc_wm_state {
889         union {
890                 /*
891                  * raw:
892                  * The "raw" watermark values produced by the formula
893                  * given the plane's current state. They do not consider
894                  * how much FIFO is actually allocated for each plane.
895                  *
896                  * optimal:
897                  * The "optimal" watermark values given the current
898                  * state of the planes and the amount of FIFO
899                  * allocated to each, ignoring any previous state
900                  * of the planes.
901                  *
902                  * intermediate:
903                  * The "intermediate" watermark values when transitioning
904                  * between the old and new "optimal" values. Used when
905                  * the watermark registers are single buffered and hence
906                  * their state changes asynchronously with regards to the
907                  * actual plane registers. These are essentially the
908                  * worst case combination of the old and new "optimal"
909                  * watermarks, which are therefore safe to use when the
910                  * plane is in either its old or new state.
911                  */
912                 struct {
913                         struct intel_pipe_wm intermediate;
914                         struct intel_pipe_wm optimal;
915                 } ilk;
916
917                 struct {
918                         struct skl_pipe_wm raw;
919                         /* gen9+ only needs 1-step wm programming */
920                         struct skl_pipe_wm optimal;
921                         struct skl_ddb_entry ddb;
922                         /*
923                          * pre-icl: for packed/planar CbCr
924                          * icl+: for everything
925                          */
926                         struct skl_ddb_entry plane_ddb[I915_MAX_PLANES];
927                         /* pre-icl: for planar Y */
928                         struct skl_ddb_entry plane_ddb_y[I915_MAX_PLANES];
929                 } skl;
930
931                 struct {
932                         struct g4x_pipe_wm raw[NUM_VLV_WM_LEVELS]; /* not inverted */
933                         struct vlv_wm_state intermediate; /* inverted */
934                         struct vlv_wm_state optimal; /* inverted */
935                         struct vlv_fifo_state fifo_state;
936                 } vlv;
937
938                 struct {
939                         struct g4x_pipe_wm raw[NUM_G4X_WM_LEVELS];
940                         struct g4x_wm_state intermediate;
941                         struct g4x_wm_state optimal;
942                 } g4x;
943         };
944
945         /*
946          * Platforms with two-step watermark programming will need to
947          * update watermark programming post-vblank to switch from the
948          * safe intermediate watermarks to the optimal final
949          * watermarks.
950          */
951         bool need_postvbl_update;
952 };
953
954 enum intel_output_format {
955         INTEL_OUTPUT_FORMAT_RGB,
956         INTEL_OUTPUT_FORMAT_YCBCR420,
957         INTEL_OUTPUT_FORMAT_YCBCR444,
958 };
959
960 struct intel_mpllb_state {
961         u32 clock; /* in KHz */
962         u32 ref_control;
963         u32 mpllb_cp;
964         u32 mpllb_div;
965         u32 mpllb_div2;
966         u32 mpllb_fracn1;
967         u32 mpllb_fracn2;
968         u32 mpllb_sscen;
969         u32 mpllb_sscstep;
970 };
971
972 struct intel_crtc_state {
973         /*
974          * uapi (drm) state. This is the software state shown to userspace.
975          * In particular, the following members are used for bookkeeping:
976          * - crtc
977          * - state
978          * - *_changed
979          * - event
980          * - commit
981          * - mode_blob
982          */
983         struct drm_crtc_state uapi;
984
985         /*
986          * actual hardware state, the state we program to the hardware.
987          * The following members are used to verify the hardware state:
988          * - enable
989          * - active
990          * - mode / pipe_mode / adjusted_mode
991          * - color property blobs.
992          *
993          * During initial hw readout, they need to be copied to uapi.
994          *
995          * Bigjoiner will allow a transcoder mode that spans 2 pipes;
996          * Use the pipe_mode for calculations like watermarks, pipe
997          * scaler, and bandwidth.
998          *
999          * Use adjusted_mode for things that need to know the full
1000          * mode on the transcoder, which spans all pipes.
1001          */
1002         struct {
1003                 bool active, enable;
1004                 /* logical state of LUTs */
1005                 struct drm_property_blob *degamma_lut, *gamma_lut, *ctm;
1006                 struct drm_display_mode mode, pipe_mode, adjusted_mode;
1007                 enum drm_scaling_filter scaling_filter;
1008         } hw;
1009
1010         /* actual state of LUTs */
1011         struct drm_property_blob *pre_csc_lut, *post_csc_lut;
1012
1013         /**
1014          * quirks - bitfield with hw state readout quirks
1015          *
1016          * For various reasons the hw state readout code might not be able to
1017          * completely faithfully read out the current state. These cases are
1018          * tracked with quirk flags so that fastboot and state checker can act
1019          * accordingly.
1020          */
1021 #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS       (1<<0) /* unreliable sync mode.flags */
1022         unsigned long quirks;
1023
1024         unsigned fb_bits; /* framebuffers to flip */
1025         bool update_pipe; /* can a fast modeset be performed? */
1026         bool disable_cxsr;
1027         bool update_wm_pre, update_wm_post; /* watermarks are updated */
1028         bool fifo_changed; /* FIFO split is changed */
1029         bool preload_luts;
1030         bool inherited; /* state inherited from BIOS? */
1031
1032         /* Ask the hardware to actually async flip? */
1033         bool do_async_flip;
1034
1035         /* Pipe source size (ie. panel fitter input size)
1036          * All planes will be positioned inside this space,
1037          * and get clipped at the edges. */
1038         struct drm_rect pipe_src;
1039
1040         /*
1041          * Pipe pixel rate, adjusted for
1042          * panel fitter/pipe scaler downscaling.
1043          */
1044         unsigned int pixel_rate;
1045
1046         /* Whether to set up the PCH/FDI. Note that we never allow sharing
1047          * between pch encoders and cpu encoders. */
1048         bool has_pch_encoder;
1049
1050         /* Are we sending infoframes on the attached port */
1051         bool has_infoframe;
1052
1053         /* CPU Transcoder for the pipe. Currently this can only differ from the
1054          * pipe on Haswell and later (where we have a special eDP transcoder)
1055          * and Broxton (where we have special DSI transcoders). */
1056         enum transcoder cpu_transcoder;
1057
1058         /*
1059          * Use reduced/limited/broadcast rbg range, compressing from the full
1060          * range fed into the crtcs.
1061          */
1062         bool limited_color_range;
1063
1064         /* Bitmask of encoder types (enum intel_output_type)
1065          * driven by the pipe.
1066          */
1067         unsigned int output_types;
1068
1069         /* Whether we should send NULL infoframes. Required for audio. */
1070         bool has_hdmi_sink;
1071
1072         /* Audio enabled on this pipe. Only valid if either has_hdmi_sink or
1073          * has_dp_encoder is set. */
1074         bool has_audio;
1075
1076         /*
1077          * Enable dithering, used when the selected pipe bpp doesn't match the
1078          * plane bpp.
1079          */
1080         bool dither;
1081
1082         /*
1083          * Dither gets enabled for 18bpp which causes CRC mismatch errors for
1084          * compliance video pattern tests.
1085          * Disable dither only if it is a compliance test request for
1086          * 18bpp.
1087          */
1088         bool dither_force_disable;
1089
1090         /* Controls for the clock computation, to override various stages. */
1091         bool clock_set;
1092
1093         /* SDVO TV has a bunch of special case. To make multifunction encoders
1094          * work correctly, we need to track this at runtime.*/
1095         bool sdvo_tv_clock;
1096
1097         /*
1098          * crtc bandwidth limit, don't increase pipe bpp or clock if not really
1099          * required. This is set in the 2nd loop of calling encoder's
1100          * ->compute_config if the first pick doesn't work out.
1101          */
1102         bool bw_constrained;
1103
1104         /* Settings for the intel dpll used on pretty much everything but
1105          * haswell. */
1106         struct dpll dpll;
1107
1108         /* Selected dpll when shared or NULL. */
1109         struct intel_shared_dpll *shared_dpll;
1110
1111         /* Actual register state of the dpll, for shared dpll cross-checking. */
1112         union {
1113                 struct intel_dpll_hw_state dpll_hw_state;
1114                 struct intel_mpllb_state mpllb_state;
1115         };
1116
1117         /*
1118          * ICL reserved DPLLs for the CRTC/port. The active PLL is selected by
1119          * setting shared_dpll and dpll_hw_state to one of these reserved ones.
1120          */
1121         struct icl_port_dpll {
1122                 struct intel_shared_dpll *pll;
1123                 struct intel_dpll_hw_state hw_state;
1124         } icl_port_dplls[ICL_PORT_DPLL_COUNT];
1125
1126         /* DSI PLL registers */
1127         struct {
1128                 u32 ctrl, div;
1129         } dsi_pll;
1130
1131         int pipe_bpp;
1132         struct intel_link_m_n dp_m_n;
1133
1134         /* m2_n2 for eDP downclock */
1135         struct intel_link_m_n dp_m2_n2;
1136         bool has_drrs;
1137         bool seamless_m_n;
1138
1139         /* PSR is supported but might not be enabled due the lack of enabled planes */
1140         bool has_psr;
1141         bool has_psr2;
1142         bool enable_psr2_sel_fetch;
1143         bool req_psr2_sdp_prior_scanline;
1144         u32 dc3co_exitline;
1145         u16 su_y_granularity;
1146         struct drm_dp_vsc_sdp psr_vsc;
1147
1148         /*
1149          * Frequence the dpll for the port should run at. Differs from the
1150          * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also
1151          * already multiplied by pixel_multiplier.
1152          */
1153         int port_clock;
1154
1155         /* Used by SDVO (and if we ever fix it, HDMI). */
1156         unsigned pixel_multiplier;
1157
1158         /* I915_MODE_FLAG_* */
1159         u8 mode_flags;
1160
1161         u8 lane_count;
1162
1163         /*
1164          * Used by platforms having DP/HDMI PHY with programmable lane
1165          * latency optimization.
1166          */
1167         u8 lane_lat_optim_mask;
1168
1169         /* minimum acceptable voltage level */
1170         u8 min_voltage_level;
1171
1172         /* Panel fitter controls for gen2-gen4 + VLV */
1173         struct {
1174                 u32 control;
1175                 u32 pgm_ratios;
1176                 u32 lvds_border_bits;
1177         } gmch_pfit;
1178
1179         /* Panel fitter placement and size for Ironlake+ */
1180         struct {
1181                 struct drm_rect dst;
1182                 bool enabled;
1183                 bool force_thru;
1184         } pch_pfit;
1185
1186         /* FDI configuration, only valid if has_pch_encoder is set. */
1187         int fdi_lanes;
1188         struct intel_link_m_n fdi_m_n;
1189
1190         bool ips_enabled;
1191
1192         bool crc_enabled;
1193
1194         bool double_wide;
1195
1196         int pbn;
1197
1198         struct intel_crtc_scaler_state scaler_state;
1199
1200         /* w/a for waiting 2 vblanks during crtc enable */
1201         enum pipe hsw_workaround_pipe;
1202
1203         /* IVB sprite scaling w/a (WaCxSRDisabledForSpriteScaling:ivb) */
1204         bool disable_lp_wm;
1205
1206         struct intel_crtc_wm_state wm;
1207
1208         int min_cdclk[I915_MAX_PLANES];
1209
1210         /* for packed/planar CbCr */
1211         u32 data_rate[I915_MAX_PLANES];
1212         /* for planar Y */
1213         u32 data_rate_y[I915_MAX_PLANES];
1214
1215         /* FIXME unify with data_rate[]? */
1216         u64 rel_data_rate[I915_MAX_PLANES];
1217         u64 rel_data_rate_y[I915_MAX_PLANES];
1218
1219         /* Gamma mode programmed on the pipe */
1220         u32 gamma_mode;
1221
1222         union {
1223                 /* CSC mode programmed on the pipe */
1224                 u32 csc_mode;
1225
1226                 /* CHV CGM mode */
1227                 u32 cgm_mode;
1228         };
1229
1230         /* bitmask of logically enabled planes (enum plane_id) */
1231         u8 enabled_planes;
1232
1233         /* bitmask of actually visible planes (enum plane_id) */
1234         u8 active_planes;
1235         u8 scaled_planes;
1236         u8 nv12_planes;
1237         u8 c8_planes;
1238
1239         /* bitmask of planes that will be updated during the commit */
1240         u8 update_planes;
1241
1242         u8 framestart_delay; /* 1-4 */
1243         u8 msa_timing_delay; /* 0-3 */
1244
1245         struct {
1246                 u32 enable;
1247                 u32 gcp;
1248                 union hdmi_infoframe avi;
1249                 union hdmi_infoframe spd;
1250                 union hdmi_infoframe hdmi;
1251                 union hdmi_infoframe drm;
1252                 struct drm_dp_vsc_sdp vsc;
1253         } infoframes;
1254
1255         /* HDMI scrambling status */
1256         bool hdmi_scrambling;
1257
1258         /* HDMI High TMDS char rate ratio */
1259         bool hdmi_high_tmds_clock_ratio;
1260
1261         /* Output format RGB/YCBCR etc */
1262         enum intel_output_format output_format;
1263
1264         /* enable pipe gamma? */
1265         bool gamma_enable;
1266
1267         /* enable pipe csc? */
1268         bool csc_enable;
1269
1270         /* big joiner pipe bitmask */
1271         u8 bigjoiner_pipes;
1272
1273         /* Display Stream compression state */
1274         struct {
1275                 bool compression_enable;
1276                 bool dsc_split;
1277                 u16 compressed_bpp;
1278                 u8 slice_count;
1279                 struct drm_dsc_config config;
1280         } dsc;
1281
1282         /* HSW+ linetime watermarks */
1283         u16 linetime;
1284         u16 ips_linetime;
1285
1286         /* Forward Error correction State */
1287         bool fec_enable;
1288
1289         /* Pointer to master transcoder in case of tiled displays */
1290         enum transcoder master_transcoder;
1291
1292         /* Bitmask to indicate slaves attached */
1293         u8 sync_mode_slaves_mask;
1294
1295         /* Only valid on TGL+ */
1296         enum transcoder mst_master_transcoder;
1297
1298         /* For DSB related info */
1299         struct intel_dsb *dsb;
1300
1301         u32 psr2_man_track_ctl;
1302
1303         /* Variable Refresh Rate state */
1304         struct {
1305                 bool enable;
1306                 u8 pipeline_full;
1307                 u16 flipline, vmin, vmax, guardband;
1308         } vrr;
1309
1310         /* Stream Splitter for eDP MSO */
1311         struct {
1312                 bool enable;
1313                 u8 link_count;
1314                 u8 pixel_overlap;
1315         } splitter;
1316
1317         /* for loading single buffered registers during vblank */
1318         struct drm_vblank_work vblank_work;
1319 };
1320
1321 enum intel_pipe_crc_source {
1322         INTEL_PIPE_CRC_SOURCE_NONE,
1323         INTEL_PIPE_CRC_SOURCE_PLANE1,
1324         INTEL_PIPE_CRC_SOURCE_PLANE2,
1325         INTEL_PIPE_CRC_SOURCE_PLANE3,
1326         INTEL_PIPE_CRC_SOURCE_PLANE4,
1327         INTEL_PIPE_CRC_SOURCE_PLANE5,
1328         INTEL_PIPE_CRC_SOURCE_PLANE6,
1329         INTEL_PIPE_CRC_SOURCE_PLANE7,
1330         INTEL_PIPE_CRC_SOURCE_PIPE,
1331         /* TV/DP on pre-gen5/vlv can't use the pipe source. */
1332         INTEL_PIPE_CRC_SOURCE_TV,
1333         INTEL_PIPE_CRC_SOURCE_DP_B,
1334         INTEL_PIPE_CRC_SOURCE_DP_C,
1335         INTEL_PIPE_CRC_SOURCE_DP_D,
1336         INTEL_PIPE_CRC_SOURCE_AUTO,
1337         INTEL_PIPE_CRC_SOURCE_MAX,
1338 };
1339
1340 enum drrs_refresh_rate {
1341         DRRS_REFRESH_RATE_HIGH,
1342         DRRS_REFRESH_RATE_LOW,
1343 };
1344
1345 #define INTEL_PIPE_CRC_ENTRIES_NR       128
1346 struct intel_pipe_crc {
1347         spinlock_t lock;
1348         int skipped;
1349         enum intel_pipe_crc_source source;
1350 };
1351
1352 struct intel_crtc {
1353         struct drm_crtc base;
1354         enum pipe pipe;
1355         /*
1356          * Whether the crtc and the connected output pipeline is active. Implies
1357          * that crtc->enabled is set, i.e. the current mode configuration has
1358          * some outputs connected to this crtc.
1359          */
1360         bool active;
1361         u8 plane_ids_mask;
1362
1363         /* I915_MODE_FLAG_* */
1364         u8 mode_flags;
1365
1366         u16 vmax_vblank_start;
1367
1368         struct intel_display_power_domain_set enabled_power_domains;
1369         struct intel_overlay *overlay;
1370
1371         struct intel_crtc_state *config;
1372
1373         /* Access to these should be protected by dev_priv->irq_lock. */
1374         bool cpu_fifo_underrun_disabled;
1375         bool pch_fifo_underrun_disabled;
1376
1377         /* per-pipe watermark state */
1378         struct {
1379                 /* watermarks currently being used  */
1380                 union {
1381                         struct intel_pipe_wm ilk;
1382                         struct vlv_wm_state vlv;
1383                         struct g4x_wm_state g4x;
1384                 } active;
1385         } wm;
1386
1387         struct {
1388                 struct mutex mutex;
1389                 struct delayed_work work;
1390                 enum drrs_refresh_rate refresh_rate;
1391                 unsigned int frontbuffer_bits;
1392                 unsigned int busy_frontbuffer_bits;
1393                 enum transcoder cpu_transcoder;
1394                 struct intel_link_m_n m_n, m2_n2;
1395         } drrs;
1396
1397         int scanline_offset;
1398
1399         struct {
1400                 unsigned start_vbl_count;
1401                 ktime_t start_vbl_time;
1402                 int min_vbl, max_vbl;
1403                 int scanline_start;
1404 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
1405                 struct {
1406                         u64 min;
1407                         u64 max;
1408                         u64 sum;
1409                         unsigned int over;
1410                         unsigned int times[17]; /* [1us, 16ms] */
1411                 } vbl;
1412 #endif
1413         } debug;
1414
1415         /* scalers available on this crtc */
1416         int num_scalers;
1417
1418         /* for loading single buffered registers during vblank */
1419         struct pm_qos_request vblank_pm_qos;
1420
1421 #ifdef CONFIG_DEBUG_FS
1422         struct intel_pipe_crc pipe_crc;
1423 #endif
1424 };
1425
1426 struct intel_plane {
1427         struct drm_plane base;
1428         enum i9xx_plane_id i9xx_plane;
1429         enum plane_id id;
1430         enum pipe pipe;
1431         bool need_async_flip_disable_wa;
1432         u32 frontbuffer_bit;
1433
1434         struct {
1435                 u32 base, cntl, size;
1436         } cursor;
1437
1438         struct intel_fbc *fbc;
1439
1440         /*
1441          * NOTE: Do not place new plane state fields here (e.g., when adding
1442          * new plane properties).  New runtime state should now be placed in
1443          * the intel_plane_state structure and accessed via plane_state.
1444          */
1445
1446         int (*min_width)(const struct drm_framebuffer *fb,
1447                          int color_plane,
1448                          unsigned int rotation);
1449         int (*max_width)(const struct drm_framebuffer *fb,
1450                          int color_plane,
1451                          unsigned int rotation);
1452         int (*max_height)(const struct drm_framebuffer *fb,
1453                           int color_plane,
1454                           unsigned int rotation);
1455         unsigned int (*max_stride)(struct intel_plane *plane,
1456                                    u32 pixel_format, u64 modifier,
1457                                    unsigned int rotation);
1458         /* Write all non-self arming plane registers */
1459         void (*update_noarm)(struct intel_plane *plane,
1460                              const struct intel_crtc_state *crtc_state,
1461                              const struct intel_plane_state *plane_state);
1462         /* Write all self-arming plane registers */
1463         void (*update_arm)(struct intel_plane *plane,
1464                            const struct intel_crtc_state *crtc_state,
1465                            const struct intel_plane_state *plane_state);
1466         /* Disable the plane, must arm */
1467         void (*disable_arm)(struct intel_plane *plane,
1468                             const struct intel_crtc_state *crtc_state);
1469         bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe);
1470         int (*check_plane)(struct intel_crtc_state *crtc_state,
1471                            struct intel_plane_state *plane_state);
1472         int (*min_cdclk)(const struct intel_crtc_state *crtc_state,
1473                          const struct intel_plane_state *plane_state);
1474         void (*async_flip)(struct intel_plane *plane,
1475                            const struct intel_crtc_state *crtc_state,
1476                            const struct intel_plane_state *plane_state,
1477                            bool async_flip);
1478         void (*enable_flip_done)(struct intel_plane *plane);
1479         void (*disable_flip_done)(struct intel_plane *plane);
1480 };
1481
1482 struct intel_watermark_params {
1483         u16 fifo_size;
1484         u16 max_wm;
1485         u8 default_wm;
1486         u8 guard_size;
1487         u8 cacheline_size;
1488 };
1489
1490 struct cxsr_latency {
1491         bool is_desktop : 1;
1492         bool is_ddr3 : 1;
1493         u16 fsb_freq;
1494         u16 mem_freq;
1495         u16 display_sr;
1496         u16 display_hpll_disable;
1497         u16 cursor_sr;
1498         u16 cursor_hpll_disable;
1499 };
1500
1501 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
1502 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
1503 #define to_intel_crtc_state(x) container_of(x, struct intel_crtc_state, uapi)
1504 #define to_intel_connector(x) container_of(x, struct intel_connector, base)
1505 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
1506 #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
1507 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
1508 #define to_intel_plane_state(x) container_of(x, struct intel_plane_state, uapi)
1509 #define intel_fb_obj(x) ((x) ? to_intel_bo((x)->obj[0]) : NULL)
1510
1511 struct intel_hdmi {
1512         i915_reg_t hdmi_reg;
1513         int ddc_bus;
1514         struct {
1515                 enum drm_dp_dual_mode_type type;
1516                 int max_tmds_clock;
1517         } dp_dual_mode;
1518         bool has_hdmi_sink;
1519         bool has_audio;
1520         struct intel_connector *attached_connector;
1521         struct cec_notifier *cec_notifier;
1522 };
1523
1524 struct intel_dp_mst_encoder;
1525
1526 struct intel_dp_compliance_data {
1527         unsigned long edid;
1528         u8 video_pattern;
1529         u16 hdisplay, vdisplay;
1530         u8 bpc;
1531         struct drm_dp_phy_test_params phytest;
1532 };
1533
1534 struct intel_dp_compliance {
1535         unsigned long test_type;
1536         struct intel_dp_compliance_data test_data;
1537         bool test_active;
1538         int test_link_rate;
1539         u8 test_lane_count;
1540 };
1541
1542 struct intel_dp_pcon_frl {
1543         bool is_trained;
1544         int trained_rate_gbps;
1545 };
1546
1547 struct intel_pps {
1548         int panel_power_up_delay;
1549         int panel_power_down_delay;
1550         int panel_power_cycle_delay;
1551         int backlight_on_delay;
1552         int backlight_off_delay;
1553         struct delayed_work panel_vdd_work;
1554         bool want_panel_vdd;
1555         bool initializing;
1556         unsigned long last_power_on;
1557         unsigned long last_backlight_off;
1558         ktime_t panel_power_off_time;
1559         intel_wakeref_t vdd_wakeref;
1560
1561         /*
1562          * Pipe whose power sequencer is currently locked into
1563          * this port. Only relevant on VLV/CHV.
1564          */
1565         enum pipe pps_pipe;
1566         /*
1567          * Pipe currently driving the port. Used for preventing
1568          * the use of the PPS for any pipe currentrly driving
1569          * external DP as that will mess things up on VLV.
1570          */
1571         enum pipe active_pipe;
1572         /*
1573          * Set if the sequencer may be reset due to a power transition,
1574          * requiring a reinitialization. Only relevant on BXT.
1575          */
1576         bool pps_reset;
1577         struct edp_power_seq pps_delays;
1578         struct edp_power_seq bios_pps_delays;
1579 };
1580
1581 struct intel_psr {
1582         /* Mutex for PSR state of the transcoder */
1583         struct mutex lock;
1584
1585 #define I915_PSR_DEBUG_MODE_MASK        0x0f
1586 #define I915_PSR_DEBUG_DEFAULT          0x00
1587 #define I915_PSR_DEBUG_DISABLE          0x01
1588 #define I915_PSR_DEBUG_ENABLE           0x02
1589 #define I915_PSR_DEBUG_FORCE_PSR1       0x03
1590 #define I915_PSR_DEBUG_ENABLE_SEL_FETCH 0x4
1591 #define I915_PSR_DEBUG_IRQ              0x10
1592
1593         u32 debug;
1594         bool sink_support;
1595         bool source_support;
1596         bool enabled;
1597         bool paused;
1598         enum pipe pipe;
1599         enum transcoder transcoder;
1600         bool active;
1601         struct work_struct work;
1602         unsigned int busy_frontbuffer_bits;
1603         bool sink_psr2_support;
1604         bool link_standby;
1605         bool colorimetry_support;
1606         bool psr2_enabled;
1607         bool psr2_sel_fetch_enabled;
1608         bool psr2_sel_fetch_cff_enabled;
1609         bool req_psr2_sdp_prior_scanline;
1610         u8 sink_sync_latency;
1611         ktime_t last_entry_attempt;
1612         ktime_t last_exit;
1613         bool sink_not_reliable;
1614         bool irq_aux_error;
1615         u16 su_w_granularity;
1616         u16 su_y_granularity;
1617         u32 dc3co_exitline;
1618         u32 dc3co_exit_delay;
1619         struct delayed_work dc3co_work;
1620 };
1621
1622 struct intel_dp {
1623         i915_reg_t output_reg;
1624         u32 DP;
1625         int link_rate;
1626         u8 lane_count;
1627         u8 sink_count;
1628         bool link_trained;
1629         bool has_hdmi_sink;
1630         bool has_audio;
1631         bool reset_link_params;
1632         bool use_max_params;
1633         u8 dpcd[DP_RECEIVER_CAP_SIZE];
1634         u8 psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
1635         u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
1636         u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
1637         u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE];
1638         u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE];
1639         u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT][DP_LTTPR_PHY_CAP_SIZE];
1640         u8 fec_capable;
1641         u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE];
1642         /* source rates */
1643         int num_source_rates;
1644         const int *source_rates;
1645         /* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */
1646         int num_sink_rates;
1647         int sink_rates[DP_MAX_SUPPORTED_RATES];
1648         bool use_rate_select;
1649         /* Max sink lane count as reported by DP_MAX_LANE_COUNT */
1650         int max_sink_lane_count;
1651         /* intersection of source and sink rates */
1652         int num_common_rates;
1653         int common_rates[DP_MAX_SUPPORTED_RATES];
1654         /* Max lane count for the current link */
1655         int max_link_lane_count;
1656         /* Max rate for the current link */
1657         int max_link_rate;
1658         int mso_link_count;
1659         int mso_pixel_overlap;
1660         /* sink or branch descriptor */
1661         struct drm_dp_desc desc;
1662         struct drm_dp_aux aux;
1663         u32 aux_busy_last_status;
1664         u8 train_set[4];
1665
1666         struct intel_pps pps;
1667
1668         bool is_mst;
1669         int active_mst_links;
1670
1671         /* connector directly attached - won't be use for modeset in mst world */
1672         struct intel_connector *attached_connector;
1673
1674         /* mst connector list */
1675         struct intel_dp_mst_encoder *mst_encoders[I915_MAX_PIPES];
1676         struct drm_dp_mst_topology_mgr mst_mgr;
1677
1678         u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index);
1679         /*
1680          * This function returns the value we have to program the AUX_CTL
1681          * register with to kick off an AUX transaction.
1682          */
1683         u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes,
1684                                 u32 aux_clock_divider);
1685
1686         i915_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp);
1687         i915_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index);
1688
1689         /* This is called before a link training is starterd */
1690         void (*prepare_link_retrain)(struct intel_dp *intel_dp,
1691                                      const struct intel_crtc_state *crtc_state);
1692         void (*set_link_train)(struct intel_dp *intel_dp,
1693                                const struct intel_crtc_state *crtc_state,
1694                                u8 dp_train_pat);
1695         void (*set_idle_link_train)(struct intel_dp *intel_dp,
1696                                     const struct intel_crtc_state *crtc_state);
1697
1698         u8 (*preemph_max)(struct intel_dp *intel_dp);
1699         u8 (*voltage_max)(struct intel_dp *intel_dp,
1700                           const struct intel_crtc_state *crtc_state);
1701
1702         /* Displayport compliance testing */
1703         struct intel_dp_compliance compliance;
1704
1705         /* Downstream facing port caps */
1706         struct {
1707                 int min_tmds_clock, max_tmds_clock;
1708                 int max_dotclock;
1709                 int pcon_max_frl_bw;
1710                 u8 max_bpc;
1711                 bool ycbcr_444_to_420;
1712                 bool rgb_to_ycbcr;
1713         } dfp;
1714
1715         /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
1716         struct pm_qos_request pm_qos;
1717
1718         /* Display stream compression testing */
1719         bool force_dsc_en;
1720         int force_dsc_bpc;
1721
1722         bool hobl_failed;
1723         bool hobl_active;
1724
1725         struct intel_dp_pcon_frl frl;
1726
1727         struct intel_psr psr;
1728
1729         /* When we last wrote the OUI for eDP */
1730         unsigned long last_oui_write;
1731 };
1732
1733 enum lspcon_vendor {
1734         LSPCON_VENDOR_MCA,
1735         LSPCON_VENDOR_PARADE
1736 };
1737
1738 struct intel_lspcon {
1739         bool active;
1740         bool hdr_supported;
1741         enum drm_lspcon_mode mode;
1742         enum lspcon_vendor vendor;
1743 };
1744
1745 struct intel_digital_port {
1746         struct intel_encoder base;
1747         u32 saved_port_bits;
1748         struct intel_dp dp;
1749         struct intel_hdmi hdmi;
1750         struct intel_lspcon lspcon;
1751         enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool);
1752         bool release_cl2_override;
1753         u8 max_lanes;
1754         /* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */
1755         enum aux_ch aux_ch;
1756         enum intel_display_power_domain ddi_io_power_domain;
1757         intel_wakeref_t ddi_io_wakeref;
1758         intel_wakeref_t aux_wakeref;
1759
1760         struct mutex tc_lock;   /* protects the TypeC port mode */
1761         intel_wakeref_t tc_lock_wakeref;
1762         enum intel_display_power_domain tc_lock_power_domain;
1763         struct delayed_work tc_disconnect_phy_work;
1764         int tc_link_refcount;
1765         bool tc_legacy_port:1;
1766         char tc_port_name[8];
1767         enum tc_port_mode tc_mode;
1768         enum phy_fia tc_phy_fia;
1769         u8 tc_phy_fia_idx;
1770
1771         /* protects num_hdcp_streams reference count, hdcp_port_data and hdcp_auth_status */
1772         struct mutex hdcp_mutex;
1773         /* the number of pipes using HDCP signalling out of this port */
1774         unsigned int num_hdcp_streams;
1775         /* port HDCP auth status */
1776         bool hdcp_auth_status;
1777         /* HDCP port data need to pass to security f/w */
1778         struct hdcp_port_data hdcp_port_data;
1779         /* Whether the MST topology supports HDCP Type 1 Content */
1780         bool hdcp_mst_type1_capable;
1781
1782         void (*write_infoframe)(struct intel_encoder *encoder,
1783                                 const struct intel_crtc_state *crtc_state,
1784                                 unsigned int type,
1785                                 const void *frame, ssize_t len);
1786         void (*read_infoframe)(struct intel_encoder *encoder,
1787                                const struct intel_crtc_state *crtc_state,
1788                                unsigned int type,
1789                                void *frame, ssize_t len);
1790         void (*set_infoframes)(struct intel_encoder *encoder,
1791                                bool enable,
1792                                const struct intel_crtc_state *crtc_state,
1793                                const struct drm_connector_state *conn_state);
1794         u32 (*infoframes_enabled)(struct intel_encoder *encoder,
1795                                   const struct intel_crtc_state *pipe_config);
1796         bool (*connected)(struct intel_encoder *encoder);
1797 };
1798
1799 struct intel_dp_mst_encoder {
1800         struct intel_encoder base;
1801         enum pipe pipe;
1802         struct intel_digital_port *primary;
1803         struct intel_connector *connector;
1804 };
1805
1806 static inline enum dpio_channel
1807 vlv_dig_port_to_channel(struct intel_digital_port *dig_port)
1808 {
1809         switch (dig_port->base.port) {
1810         default:
1811                 MISSING_CASE(dig_port->base.port);
1812                 fallthrough;
1813         case PORT_B:
1814         case PORT_D:
1815                 return DPIO_CH0;
1816         case PORT_C:
1817                 return DPIO_CH1;
1818         }
1819 }
1820
1821 static inline enum dpio_phy
1822 vlv_dig_port_to_phy(struct intel_digital_port *dig_port)
1823 {
1824         switch (dig_port->base.port) {
1825         default:
1826                 MISSING_CASE(dig_port->base.port);
1827                 fallthrough;
1828         case PORT_B:
1829         case PORT_C:
1830                 return DPIO_PHY0;
1831         case PORT_D:
1832                 return DPIO_PHY1;
1833         }
1834 }
1835
1836 static inline enum dpio_channel
1837 vlv_pipe_to_channel(enum pipe pipe)
1838 {
1839         switch (pipe) {
1840         default:
1841                 MISSING_CASE(pipe);
1842                 fallthrough;
1843         case PIPE_A:
1844         case PIPE_C:
1845                 return DPIO_CH0;
1846         case PIPE_B:
1847                 return DPIO_CH1;
1848         }
1849 }
1850
1851 struct intel_load_detect_pipe {
1852         struct drm_atomic_state *restore_state;
1853 };
1854
1855 static inline struct intel_encoder *
1856 intel_attached_encoder(struct intel_connector *connector)
1857 {
1858         return connector->encoder;
1859 }
1860
1861 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder)
1862 {
1863         switch (encoder->type) {
1864         case INTEL_OUTPUT_DDI:
1865         case INTEL_OUTPUT_DP:
1866         case INTEL_OUTPUT_EDP:
1867         case INTEL_OUTPUT_HDMI:
1868                 return true;
1869         default:
1870                 return false;
1871         }
1872 }
1873
1874 static inline bool intel_encoder_is_mst(struct intel_encoder *encoder)
1875 {
1876         return encoder->type == INTEL_OUTPUT_DP_MST;
1877 }
1878
1879 static inline struct intel_dp_mst_encoder *
1880 enc_to_mst(struct intel_encoder *encoder)
1881 {
1882         return container_of(&encoder->base, struct intel_dp_mst_encoder,
1883                             base.base);
1884 }
1885
1886 static inline struct intel_digital_port *
1887 enc_to_dig_port(struct intel_encoder *encoder)
1888 {
1889         struct intel_encoder *intel_encoder = encoder;
1890
1891         if (intel_encoder_is_dig_port(intel_encoder))
1892                 return container_of(&encoder->base, struct intel_digital_port,
1893                                     base.base);
1894         else if (intel_encoder_is_mst(intel_encoder))
1895                 return enc_to_mst(encoder)->primary;
1896         else
1897                 return NULL;
1898 }
1899
1900 static inline struct intel_digital_port *
1901 intel_attached_dig_port(struct intel_connector *connector)
1902 {
1903         return enc_to_dig_port(intel_attached_encoder(connector));
1904 }
1905
1906 static inline struct intel_hdmi *
1907 enc_to_intel_hdmi(struct intel_encoder *encoder)
1908 {
1909         return &enc_to_dig_port(encoder)->hdmi;
1910 }
1911
1912 static inline struct intel_hdmi *
1913 intel_attached_hdmi(struct intel_connector *connector)
1914 {
1915         return enc_to_intel_hdmi(intel_attached_encoder(connector));
1916 }
1917
1918 static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder)
1919 {
1920         return &enc_to_dig_port(encoder)->dp;
1921 }
1922
1923 static inline struct intel_dp *intel_attached_dp(struct intel_connector *connector)
1924 {
1925         return enc_to_intel_dp(intel_attached_encoder(connector));
1926 }
1927
1928 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder)
1929 {
1930         switch (encoder->type) {
1931         case INTEL_OUTPUT_DP:
1932         case INTEL_OUTPUT_EDP:
1933                 return true;
1934         case INTEL_OUTPUT_DDI:
1935                 /* Skip pure HDMI/DVI DDI encoders */
1936                 return i915_mmio_reg_valid(enc_to_intel_dp(encoder)->output_reg);
1937         default:
1938                 return false;
1939         }
1940 }
1941
1942 static inline struct intel_lspcon *
1943 enc_to_intel_lspcon(struct intel_encoder *encoder)
1944 {
1945         return &enc_to_dig_port(encoder)->lspcon;
1946 }
1947
1948 static inline struct intel_digital_port *
1949 dp_to_dig_port(struct intel_dp *intel_dp)
1950 {
1951         return container_of(intel_dp, struct intel_digital_port, dp);
1952 }
1953
1954 static inline struct intel_lspcon *
1955 dp_to_lspcon(struct intel_dp *intel_dp)
1956 {
1957         return &dp_to_dig_port(intel_dp)->lspcon;
1958 }
1959
1960 #define dp_to_i915(__intel_dp) to_i915(dp_to_dig_port(__intel_dp)->base.base.dev)
1961
1962 #define CAN_PSR(intel_dp) ((intel_dp)->psr.sink_support && \
1963                            (intel_dp)->psr.source_support)
1964
1965 static inline bool intel_encoder_can_psr(struct intel_encoder *encoder)
1966 {
1967         if (!intel_encoder_is_dp(encoder))
1968                 return false;
1969
1970         return CAN_PSR(enc_to_intel_dp(encoder));
1971 }
1972
1973 static inline struct intel_digital_port *
1974 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
1975 {
1976         return container_of(intel_hdmi, struct intel_digital_port, hdmi);
1977 }
1978
1979 static inline struct intel_plane_state *
1980 intel_atomic_get_plane_state(struct intel_atomic_state *state,
1981                                  struct intel_plane *plane)
1982 {
1983         struct drm_plane_state *ret =
1984                 drm_atomic_get_plane_state(&state->base, &plane->base);
1985
1986         if (IS_ERR(ret))
1987                 return ERR_CAST(ret);
1988
1989         return to_intel_plane_state(ret);
1990 }
1991
1992 static inline struct intel_plane_state *
1993 intel_atomic_get_old_plane_state(struct intel_atomic_state *state,
1994                                  struct intel_plane *plane)
1995 {
1996         return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base,
1997                                                                    &plane->base));
1998 }
1999
2000 static inline struct intel_plane_state *
2001 intel_atomic_get_new_plane_state(struct intel_atomic_state *state,
2002                                  struct intel_plane *plane)
2003 {
2004         return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base,
2005                                                                    &plane->base));
2006 }
2007
2008 static inline struct intel_crtc_state *
2009 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state,
2010                                 struct intel_crtc *crtc)
2011 {
2012         return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base,
2013                                                                  &crtc->base));
2014 }
2015
2016 static inline struct intel_crtc_state *
2017 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state,
2018                                 struct intel_crtc *crtc)
2019 {
2020         return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base,
2021                                                                  &crtc->base));
2022 }
2023
2024 static inline struct intel_digital_connector_state *
2025 intel_atomic_get_new_connector_state(struct intel_atomic_state *state,
2026                                      struct intel_connector *connector)
2027 {
2028         return to_intel_digital_connector_state(
2029                         drm_atomic_get_new_connector_state(&state->base,
2030                         &connector->base));
2031 }
2032
2033 static inline struct intel_digital_connector_state *
2034 intel_atomic_get_old_connector_state(struct intel_atomic_state *state,
2035                                      struct intel_connector *connector)
2036 {
2037         return to_intel_digital_connector_state(
2038                         drm_atomic_get_old_connector_state(&state->base,
2039                         &connector->base));
2040 }
2041
2042 /* intel_display.c */
2043 static inline bool
2044 intel_crtc_has_type(const struct intel_crtc_state *crtc_state,
2045                     enum intel_output_type type)
2046 {
2047         return crtc_state->output_types & BIT(type);
2048 }
2049
2050 static inline bool
2051 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state)
2052 {
2053         return crtc_state->output_types &
2054                 (BIT(INTEL_OUTPUT_DP) |
2055                  BIT(INTEL_OUTPUT_DP_MST) |
2056                  BIT(INTEL_OUTPUT_EDP));
2057 }
2058
2059 static inline bool
2060 intel_crtc_needs_modeset(const struct intel_crtc_state *crtc_state)
2061 {
2062         return drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
2063 }
2064
2065 static inline bool
2066 intel_crtc_needs_fastset(const struct intel_crtc_state *crtc_state)
2067 {
2068         return crtc_state->update_pipe;
2069 }
2070
2071 static inline bool
2072 intel_crtc_needs_color_update(const struct intel_crtc_state *crtc_state)
2073 {
2074         return crtc_state->uapi.color_mgmt_changed ||
2075                 intel_crtc_needs_fastset(crtc_state) ||
2076                 intel_crtc_needs_modeset(crtc_state);
2077 }
2078
2079 static inline u32 intel_plane_ggtt_offset(const struct intel_plane_state *plane_state)
2080 {
2081         return i915_ggtt_offset(plane_state->ggtt_vma);
2082 }
2083
2084 static inline struct intel_frontbuffer *
2085 to_intel_frontbuffer(struct drm_framebuffer *fb)
2086 {
2087         return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
2088 }
2089
2090 #endif /*  __INTEL_DISPLAY_TYPES_H__ */