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