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