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