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