bac40482a2aa44d6ef8e5efddd1575dd00afc48d
[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[2];
94         /* for each plane in the rotated GTT view */
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         unsigned int cloneable;
132         enum intel_hotplug_state (*hotplug)(struct intel_encoder *encoder,
133                                             struct intel_connector *connector,
134                                             bool irq_received);
135         enum intel_output_type (*compute_output_type)(struct intel_encoder *,
136                                                       struct intel_crtc_state *,
137                                                       struct drm_connector_state *);
138         int (*compute_config)(struct intel_encoder *,
139                               struct intel_crtc_state *,
140                               struct drm_connector_state *);
141         void (*update_prepare)(struct intel_atomic_state *,
142                                struct intel_encoder *,
143                                struct intel_crtc *);
144         void (*pre_pll_enable)(struct intel_encoder *,
145                                const struct intel_crtc_state *,
146                                const struct drm_connector_state *);
147         void (*pre_enable)(struct intel_encoder *,
148                            const struct intel_crtc_state *,
149                            const struct drm_connector_state *);
150         void (*enable)(struct intel_encoder *,
151                        const struct intel_crtc_state *,
152                        const struct drm_connector_state *);
153         void (*update_complete)(struct intel_atomic_state *,
154                                 struct intel_encoder *,
155                                 struct intel_crtc *);
156         void (*disable)(struct intel_encoder *,
157                         const struct intel_crtc_state *,
158                         const struct drm_connector_state *);
159         void (*post_disable)(struct intel_encoder *,
160                              const struct intel_crtc_state *,
161                              const struct drm_connector_state *);
162         void (*post_pll_disable)(struct intel_encoder *,
163                                  const struct intel_crtc_state *,
164                                  const struct drm_connector_state *);
165         void (*update_pipe)(struct intel_encoder *,
166                             const struct intel_crtc_state *,
167                             const struct drm_connector_state *);
168         /* Read out the current hw state of this connector, returning true if
169          * the encoder is active. If the encoder is enabled it also set the pipe
170          * it is connected to in the pipe parameter. */
171         bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
172         /* Reconstructs the equivalent mode flags for the current hardware
173          * state. This must be called _after_ display->get_pipe_config has
174          * pre-filled the pipe config. Note that intel_encoder->base.crtc must
175          * be set correctly before calling this function. */
176         void (*get_config)(struct intel_encoder *,
177                            struct intel_crtc_state *pipe_config);
178         /*
179          * Acquires the power domains needed for an active encoder during
180          * hardware state readout.
181          */
182         void (*get_power_domains)(struct intel_encoder *encoder,
183                                   struct intel_crtc_state *crtc_state);
184         /*
185          * Called during system suspend after all pending requests for the
186          * encoder are flushed (for example for DP AUX transactions) and
187          * device interrupts are disabled.
188          */
189         void (*suspend)(struct intel_encoder *);
190         int crtc_mask;
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         /* Gen9+ only */
510         struct skl_ddb_values wm_results;
511
512         struct i915_sw_fence commit_ready;
513
514         struct llist_node freed;
515 };
516
517 struct intel_plane_state {
518         struct drm_plane_state base;
519         struct i915_ggtt_view view;
520         struct i915_vma *vma;
521         unsigned long flags;
522 #define PLANE_HAS_FENCE BIT(0)
523
524         struct {
525                 u32 offset;
526                 /*
527                  * Plane stride in:
528                  * bytes for 0/180 degree rotation
529                  * pixels for 90/270 degree rotation
530                  */
531                 u32 stride;
532                 int x, y;
533         } color_plane[2];
534
535         /* plane control register */
536         u32 ctl;
537
538         /* plane color control register */
539         u32 color_ctl;
540
541         /*
542          * scaler_id
543          *    = -1 : not using a scaler
544          *    >=  0 : using a scalers
545          *
546          * plane requiring a scaler:
547          *   - During check_plane, its bit is set in
548          *     crtc_state->scaler_state.scaler_users by calling helper function
549          *     update_scaler_plane.
550          *   - scaler_id indicates the scaler it got assigned.
551          *
552          * plane doesn't require a scaler:
553          *   - this can happen when scaling is no more required or plane simply
554          *     got disabled.
555          *   - During check_plane, corresponding bit is reset in
556          *     crtc_state->scaler_state.scaler_users by calling helper function
557          *     update_scaler_plane.
558          */
559         int scaler_id;
560
561         /*
562          * planar_linked_plane:
563          *
564          * ICL planar formats require 2 planes that are updated as pairs.
565          * This member is used to make sure the other plane is also updated
566          * when required, and for update_slave() to find the correct
567          * plane_state to pass as argument.
568          */
569         struct intel_plane *planar_linked_plane;
570
571         /*
572          * planar_slave:
573          * If set don't update use the linked plane's state for updating
574          * this plane during atomic commit with the update_slave() callback.
575          *
576          * It's also used by the watermark code to ignore wm calculations on
577          * this plane. They're calculated by the linked plane's wm code.
578          */
579         u32 planar_slave;
580
581         struct drm_intel_sprite_colorkey ckey;
582 };
583
584 struct intel_initial_plane_config {
585         struct intel_framebuffer *fb;
586         unsigned int tiling;
587         int size;
588         u32 base;
589         u8 rotation;
590 };
591
592 struct intel_scaler {
593         int in_use;
594         u32 mode;
595 };
596
597 struct intel_crtc_scaler_state {
598 #define SKL_NUM_SCALERS 2
599         struct intel_scaler scalers[SKL_NUM_SCALERS];
600
601         /*
602          * scaler_users: keeps track of users requesting scalers on this crtc.
603          *
604          *     If a bit is set, a user is using a scaler.
605          *     Here user can be a plane or crtc as defined below:
606          *       bits 0-30 - plane (bit position is index from drm_plane_index)
607          *       bit 31    - crtc
608          *
609          * Instead of creating a new index to cover planes and crtc, using
610          * existing drm_plane_index for planes which is well less than 31
611          * planes and bit 31 for crtc. This should be fine to cover all
612          * our platforms.
613          *
614          * intel_atomic_setup_scalers will setup available scalers to users
615          * requesting scalers. It will gracefully fail if request exceeds
616          * avilability.
617          */
618 #define SKL_CRTC_INDEX 31
619         unsigned scaler_users;
620
621         /* scaler used by crtc for panel fitting purpose */
622         int scaler_id;
623 };
624
625 /* drm_mode->private_flags */
626 #define I915_MODE_FLAG_INHERITED (1<<0)
627 /* Flag to get scanline using frame time stamps */
628 #define I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP (1<<1)
629 /* Flag to use the scanline counter instead of the pixel counter */
630 #define I915_MODE_FLAG_USE_SCANLINE_COUNTER (1<<2)
631
632 struct intel_pipe_wm {
633         struct intel_wm_level wm[5];
634         u32 linetime;
635         bool fbc_wm_enabled;
636         bool pipe_enabled;
637         bool sprites_enabled;
638         bool sprites_scaled;
639 };
640
641 struct skl_plane_wm {
642         struct skl_wm_level wm[8];
643         struct skl_wm_level uv_wm[8];
644         struct skl_wm_level trans_wm;
645         bool is_planar;
646 };
647
648 struct skl_pipe_wm {
649         struct skl_plane_wm planes[I915_MAX_PLANES];
650         u32 linetime;
651 };
652
653 enum vlv_wm_level {
654         VLV_WM_LEVEL_PM2,
655         VLV_WM_LEVEL_PM5,
656         VLV_WM_LEVEL_DDR_DVFS,
657         NUM_VLV_WM_LEVELS,
658 };
659
660 struct vlv_wm_state {
661         struct g4x_pipe_wm wm[NUM_VLV_WM_LEVELS];
662         struct g4x_sr_wm sr[NUM_VLV_WM_LEVELS];
663         u8 num_levels;
664         bool cxsr;
665 };
666
667 struct vlv_fifo_state {
668         u16 plane[I915_MAX_PLANES];
669 };
670
671 enum g4x_wm_level {
672         G4X_WM_LEVEL_NORMAL,
673         G4X_WM_LEVEL_SR,
674         G4X_WM_LEVEL_HPLL,
675         NUM_G4X_WM_LEVELS,
676 };
677
678 struct g4x_wm_state {
679         struct g4x_pipe_wm wm;
680         struct g4x_sr_wm sr;
681         struct g4x_sr_wm hpll;
682         bool cxsr;
683         bool hpll_en;
684         bool fbc_en;
685 };
686
687 struct intel_crtc_wm_state {
688         union {
689                 struct {
690                         /*
691                          * Intermediate watermarks; these can be
692                          * programmed immediately since they satisfy
693                          * both the current configuration we're
694                          * switching away from and the new
695                          * configuration we're switching to.
696                          */
697                         struct intel_pipe_wm intermediate;
698
699                         /*
700                          * Optimal watermarks, programmed post-vblank
701                          * when this state is committed.
702                          */
703                         struct intel_pipe_wm optimal;
704                 } ilk;
705
706                 struct {
707                         /* gen9+ only needs 1-step wm programming */
708                         struct skl_pipe_wm optimal;
709                         struct skl_ddb_entry ddb;
710                         struct skl_ddb_entry plane_ddb_y[I915_MAX_PLANES];
711                         struct skl_ddb_entry plane_ddb_uv[I915_MAX_PLANES];
712                 } skl;
713
714                 struct {
715                         /* "raw" watermarks (not inverted) */
716                         struct g4x_pipe_wm raw[NUM_VLV_WM_LEVELS];
717                         /* intermediate watermarks (inverted) */
718                         struct vlv_wm_state intermediate;
719                         /* optimal watermarks (inverted) */
720                         struct vlv_wm_state optimal;
721                         /* display FIFO split */
722                         struct vlv_fifo_state fifo_state;
723                 } vlv;
724
725                 struct {
726                         /* "raw" watermarks */
727                         struct g4x_pipe_wm raw[NUM_G4X_WM_LEVELS];
728                         /* intermediate watermarks */
729                         struct g4x_wm_state intermediate;
730                         /* optimal watermarks */
731                         struct g4x_wm_state optimal;
732                 } g4x;
733         };
734
735         /*
736          * Platforms with two-step watermark programming will need to
737          * update watermark programming post-vblank to switch from the
738          * safe intermediate watermarks to the optimal final
739          * watermarks.
740          */
741         bool need_postvbl_update;
742 };
743
744 enum intel_output_format {
745         INTEL_OUTPUT_FORMAT_INVALID,
746         INTEL_OUTPUT_FORMAT_RGB,
747         INTEL_OUTPUT_FORMAT_YCBCR420,
748         INTEL_OUTPUT_FORMAT_YCBCR444,
749 };
750
751 struct intel_crtc_state {
752         struct drm_crtc_state base;
753
754         /**
755          * quirks - bitfield with hw state readout quirks
756          *
757          * For various reasons the hw state readout code might not be able to
758          * completely faithfully read out the current state. These cases are
759          * tracked with quirk flags so that fastboot and state checker can act
760          * accordingly.
761          */
762 #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS       (1<<0) /* unreliable sync mode.flags */
763         unsigned long quirks;
764
765         unsigned fb_bits; /* framebuffers to flip */
766         bool update_pipe; /* can a fast modeset be performed? */
767         bool disable_cxsr;
768         bool update_wm_pre, update_wm_post; /* watermarks are updated */
769         bool fifo_changed; /* FIFO split is changed */
770
771         /* Pipe source size (ie. panel fitter input size)
772          * All planes will be positioned inside this space,
773          * and get clipped at the edges. */
774         int pipe_src_w, pipe_src_h;
775
776         /*
777          * Pipe pixel rate, adjusted for
778          * panel fitter/pipe scaler downscaling.
779          */
780         unsigned int pixel_rate;
781
782         /* Whether to set up the PCH/FDI. Note that we never allow sharing
783          * between pch encoders and cpu encoders. */
784         bool has_pch_encoder;
785
786         /* Are we sending infoframes on the attached port */
787         bool has_infoframe;
788
789         /* CPU Transcoder for the pipe. Currently this can only differ from the
790          * pipe on Haswell and later (where we have a special eDP transcoder)
791          * and Broxton (where we have special DSI transcoders). */
792         enum transcoder cpu_transcoder;
793
794         /*
795          * Use reduced/limited/broadcast rbg range, compressing from the full
796          * range fed into the crtcs.
797          */
798         bool limited_color_range;
799
800         /* Bitmask of encoder types (enum intel_output_type)
801          * driven by the pipe.
802          */
803         unsigned int output_types;
804
805         /* Whether we should send NULL infoframes. Required for audio. */
806         bool has_hdmi_sink;
807
808         /* Audio enabled on this pipe. Only valid if either has_hdmi_sink or
809          * has_dp_encoder is set. */
810         bool has_audio;
811
812         /*
813          * Enable dithering, used when the selected pipe bpp doesn't match the
814          * plane bpp.
815          */
816         bool dither;
817
818         /*
819          * Dither gets enabled for 18bpp which causes CRC mismatch errors for
820          * compliance video pattern tests.
821          * Disable dither only if it is a compliance test request for
822          * 18bpp.
823          */
824         bool dither_force_disable;
825
826         /* Controls for the clock computation, to override various stages. */
827         bool clock_set;
828
829         /* SDVO TV has a bunch of special case. To make multifunction encoders
830          * work correctly, we need to track this at runtime.*/
831         bool sdvo_tv_clock;
832
833         /*
834          * crtc bandwidth limit, don't increase pipe bpp or clock if not really
835          * required. This is set in the 2nd loop of calling encoder's
836          * ->compute_config if the first pick doesn't work out.
837          */
838         bool bw_constrained;
839
840         /* Settings for the intel dpll used on pretty much everything but
841          * haswell. */
842         struct dpll dpll;
843
844         /* Selected dpll when shared or NULL. */
845         struct intel_shared_dpll *shared_dpll;
846
847         /* Actual register state of the dpll, for shared dpll cross-checking. */
848         struct intel_dpll_hw_state dpll_hw_state;
849
850         /*
851          * ICL reserved DPLLs for the CRTC/port. The active PLL is selected by
852          * setting shared_dpll and dpll_hw_state to one of these reserved ones.
853          */
854         struct icl_port_dpll {
855                 struct intel_shared_dpll *pll;
856                 struct intel_dpll_hw_state hw_state;
857         } icl_port_dplls[ICL_PORT_DPLL_COUNT];
858
859         /* DSI PLL registers */
860         struct {
861                 u32 ctrl, div;
862         } dsi_pll;
863
864         int pipe_bpp;
865         struct intel_link_m_n dp_m_n;
866
867         /* m2_n2 for eDP downclock */
868         struct intel_link_m_n dp_m2_n2;
869         bool has_drrs;
870
871         bool has_psr;
872         bool has_psr2;
873         u32 dc3co_exitline;
874
875         /*
876          * Frequence the dpll for the port should run at. Differs from the
877          * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also
878          * already multiplied by pixel_multiplier.
879          */
880         int port_clock;
881
882         /* Used by SDVO (and if we ever fix it, HDMI). */
883         unsigned pixel_multiplier;
884
885         u8 lane_count;
886
887         /*
888          * Used by platforms having DP/HDMI PHY with programmable lane
889          * latency optimization.
890          */
891         u8 lane_lat_optim_mask;
892
893         /* minimum acceptable voltage level */
894         u8 min_voltage_level;
895
896         /* Panel fitter controls for gen2-gen4 + VLV */
897         struct {
898                 u32 control;
899                 u32 pgm_ratios;
900                 u32 lvds_border_bits;
901         } gmch_pfit;
902
903         /* Panel fitter placement and size for Ironlake+ */
904         struct {
905                 u32 pos;
906                 u32 size;
907                 bool enabled;
908                 bool force_thru;
909         } pch_pfit;
910
911         /* FDI configuration, only valid if has_pch_encoder is set. */
912         int fdi_lanes;
913         struct intel_link_m_n fdi_m_n;
914
915         bool ips_enabled;
916
917         bool crc_enabled;
918
919         bool enable_fbc;
920
921         bool double_wide;
922
923         int pbn;
924
925         struct intel_crtc_scaler_state scaler_state;
926
927         /* w/a for waiting 2 vblanks during crtc enable */
928         enum pipe hsw_workaround_pipe;
929
930         /* IVB sprite scaling w/a (WaCxSRDisabledForSpriteScaling:ivb) */
931         bool disable_lp_wm;
932
933         struct intel_crtc_wm_state wm;
934
935         u32 data_rate[I915_MAX_PLANES];
936
937         /* Gamma mode programmed on the pipe */
938         u32 gamma_mode;
939
940         union {
941                 /* CSC mode programmed on the pipe */
942                 u32 csc_mode;
943
944                 /* CHV CGM mode */
945                 u32 cgm_mode;
946         };
947
948         /* bitmask of visible planes (enum plane_id) */
949         u8 active_planes;
950         u8 nv12_planes;
951         u8 c8_planes;
952
953         /* bitmask of planes that will be updated during the commit */
954         u8 update_planes;
955
956         struct {
957                 u32 enable;
958                 u32 gcp;
959                 union hdmi_infoframe avi;
960                 union hdmi_infoframe spd;
961                 union hdmi_infoframe hdmi;
962                 union hdmi_infoframe drm;
963         } infoframes;
964
965         /* HDMI scrambling status */
966         bool hdmi_scrambling;
967
968         /* HDMI High TMDS char rate ratio */
969         bool hdmi_high_tmds_clock_ratio;
970
971         /* Output format RGB/YCBCR etc */
972         enum intel_output_format output_format;
973
974         /* Output down scaling is done in LSPCON device */
975         bool lspcon_downsampling;
976
977         /* enable pipe gamma? */
978         bool gamma_enable;
979
980         /* enable pipe csc? */
981         bool csc_enable;
982
983         /* Display Stream compression state */
984         struct {
985                 bool compression_enable;
986                 bool dsc_split;
987                 u16 compressed_bpp;
988                 u8 slice_count;
989                 struct drm_dsc_config config;
990         } dsc;
991
992         /* Forward Error correction State */
993         bool fec_enable;
994
995         /* Pointer to master transcoder in case of tiled displays */
996         enum transcoder master_transcoder;
997
998         /* Bitmask to indicate slaves attached */
999         u8 sync_mode_slaves_mask;
1000 };
1001
1002 struct intel_crtc {
1003         struct drm_crtc base;
1004         enum pipe pipe;
1005         /*
1006          * Whether the crtc and the connected output pipeline is active. Implies
1007          * that crtc->enabled is set, i.e. the current mode configuration has
1008          * some outputs connected to this crtc.
1009          */
1010         bool active;
1011         u8 plane_ids_mask;
1012         unsigned long long enabled_power_domains;
1013         struct intel_overlay *overlay;
1014
1015         struct intel_crtc_state *config;
1016
1017         /* Access to these should be protected by dev_priv->irq_lock. */
1018         bool cpu_fifo_underrun_disabled;
1019         bool pch_fifo_underrun_disabled;
1020
1021         /* per-pipe watermark state */
1022         struct {
1023                 /* watermarks currently being used  */
1024                 union {
1025                         struct intel_pipe_wm ilk;
1026                         struct vlv_wm_state vlv;
1027                         struct g4x_wm_state g4x;
1028                 } active;
1029         } wm;
1030
1031         int scanline_offset;
1032
1033         struct {
1034                 unsigned start_vbl_count;
1035                 ktime_t start_vbl_time;
1036                 int min_vbl, max_vbl;
1037                 int scanline_start;
1038         } debug;
1039
1040         /* scalers available on this crtc */
1041         int num_scalers;
1042
1043         /* per pipe DSB related info */
1044         struct intel_dsb dsb;
1045 };
1046
1047 struct intel_plane {
1048         struct drm_plane base;
1049         enum i9xx_plane_id i9xx_plane;
1050         enum plane_id id;
1051         enum pipe pipe;
1052         bool has_fbc;
1053         bool has_ccs;
1054         u32 frontbuffer_bit;
1055
1056         struct {
1057                 u32 base, cntl, size;
1058         } cursor;
1059
1060         /*
1061          * NOTE: Do not place new plane state fields here (e.g., when adding
1062          * new plane properties).  New runtime state should now be placed in
1063          * the intel_plane_state structure and accessed via plane_state.
1064          */
1065
1066         unsigned int (*max_stride)(struct intel_plane *plane,
1067                                    u32 pixel_format, u64 modifier,
1068                                    unsigned int rotation);
1069         void (*update_plane)(struct intel_plane *plane,
1070                              const struct intel_crtc_state *crtc_state,
1071                              const struct intel_plane_state *plane_state);
1072         void (*update_slave)(struct intel_plane *plane,
1073                              const struct intel_crtc_state *crtc_state,
1074                              const struct intel_plane_state *plane_state);
1075         void (*disable_plane)(struct intel_plane *plane,
1076                               const struct intel_crtc_state *crtc_state);
1077         bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe);
1078         int (*check_plane)(struct intel_crtc_state *crtc_state,
1079                            struct intel_plane_state *plane_state);
1080 };
1081
1082 struct intel_watermark_params {
1083         u16 fifo_size;
1084         u16 max_wm;
1085         u8 default_wm;
1086         u8 guard_size;
1087         u8 cacheline_size;
1088 };
1089
1090 struct cxsr_latency {
1091         bool is_desktop : 1;
1092         bool is_ddr3 : 1;
1093         u16 fsb_freq;
1094         u16 mem_freq;
1095         u16 display_sr;
1096         u16 display_hpll_disable;
1097         u16 cursor_sr;
1098         u16 cursor_hpll_disable;
1099 };
1100
1101 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
1102 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
1103 #define to_intel_crtc_state(x) container_of(x, struct intel_crtc_state, base)
1104 #define to_intel_connector(x) container_of(x, struct intel_connector, base)
1105 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
1106 #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
1107 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
1108 #define to_intel_plane_state(x) container_of(x, struct intel_plane_state, base)
1109 #define intel_fb_obj(x) ((x) ? to_intel_bo((x)->obj[0]) : NULL)
1110
1111 struct intel_hdmi {
1112         i915_reg_t hdmi_reg;
1113         int ddc_bus;
1114         struct {
1115                 enum drm_dp_dual_mode_type type;
1116                 int max_tmds_clock;
1117         } dp_dual_mode;
1118         bool has_hdmi_sink;
1119         bool has_audio;
1120         struct intel_connector *attached_connector;
1121         struct cec_notifier *cec_notifier;
1122 };
1123
1124 struct intel_dp_mst_encoder;
1125 #define DP_MAX_DOWNSTREAM_PORTS         0x10
1126
1127 /*
1128  * enum link_m_n_set:
1129  *      When platform provides two set of M_N registers for dp, we can
1130  *      program them and switch between them incase of DRRS.
1131  *      But When only one such register is provided, we have to program the
1132  *      required divider value on that registers itself based on the DRRS state.
1133  *
1134  * M1_N1        : Program dp_m_n on M1_N1 registers
1135  *                        dp_m2_n2 on M2_N2 registers (If supported)
1136  *
1137  * M2_N2        : Program dp_m2_n2 on M1_N1 registers
1138  *                        M2_N2 registers are not supported
1139  */
1140
1141 enum link_m_n_set {
1142         /* Sets the m1_n1 and m2_n2 */
1143         M1_N1 = 0,
1144         M2_N2
1145 };
1146
1147 struct intel_dp_compliance_data {
1148         unsigned long edid;
1149         u8 video_pattern;
1150         u16 hdisplay, vdisplay;
1151         u8 bpc;
1152 };
1153
1154 struct intel_dp_compliance {
1155         unsigned long test_type;
1156         struct intel_dp_compliance_data test_data;
1157         bool test_active;
1158         int test_link_rate;
1159         u8 test_lane_count;
1160 };
1161
1162 struct intel_dp {
1163         i915_reg_t output_reg;
1164         u32 DP;
1165         int link_rate;
1166         u8 lane_count;
1167         u8 sink_count;
1168         bool link_mst;
1169         bool link_trained;
1170         bool has_audio;
1171         bool reset_link_params;
1172         u8 dpcd[DP_RECEIVER_CAP_SIZE];
1173         u8 psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
1174         u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
1175         u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
1176         u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE];
1177         u8 fec_capable;
1178         /* source rates */
1179         int num_source_rates;
1180         const int *source_rates;
1181         /* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */
1182         int num_sink_rates;
1183         int sink_rates[DP_MAX_SUPPORTED_RATES];
1184         bool use_rate_select;
1185         /* intersection of source and sink rates */
1186         int num_common_rates;
1187         int common_rates[DP_MAX_SUPPORTED_RATES];
1188         /* Max lane count for the current link */
1189         int max_link_lane_count;
1190         /* Max rate for the current link */
1191         int max_link_rate;
1192         /* sink or branch descriptor */
1193         struct drm_dp_desc desc;
1194         struct drm_dp_aux aux;
1195         u32 aux_busy_last_status;
1196         u8 train_set[4];
1197         int panel_power_up_delay;
1198         int panel_power_down_delay;
1199         int panel_power_cycle_delay;
1200         int backlight_on_delay;
1201         int backlight_off_delay;
1202         struct delayed_work panel_vdd_work;
1203         bool want_panel_vdd;
1204         unsigned long last_power_on;
1205         unsigned long last_backlight_off;
1206         ktime_t panel_power_off_time;
1207
1208         struct notifier_block edp_notifier;
1209
1210         /*
1211          * Pipe whose power sequencer is currently locked into
1212          * this port. Only relevant on VLV/CHV.
1213          */
1214         enum pipe pps_pipe;
1215         /*
1216          * Pipe currently driving the port. Used for preventing
1217          * the use of the PPS for any pipe currentrly driving
1218          * external DP as that will mess things up on VLV.
1219          */
1220         enum pipe active_pipe;
1221         /*
1222          * Set if the sequencer may be reset due to a power transition,
1223          * requiring a reinitialization. Only relevant on BXT.
1224          */
1225         bool pps_reset;
1226         struct edp_power_seq pps_delays;
1227
1228         bool can_mst; /* this port supports mst */
1229         bool is_mst;
1230         int active_mst_links;
1231
1232         /*
1233          * DP_TP_* registers may be either on port or transcoder register space.
1234          */
1235         struct {
1236                 i915_reg_t dp_tp_ctl;
1237                 i915_reg_t dp_tp_status;
1238         } regs;
1239
1240         /* connector directly attached - won't be use for modeset in mst world */
1241         struct intel_connector *attached_connector;
1242
1243         /* mst connector list */
1244         struct intel_dp_mst_encoder *mst_encoders[I915_MAX_PIPES];
1245         struct drm_dp_mst_topology_mgr mst_mgr;
1246
1247         u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index);
1248         /*
1249          * This function returns the value we have to program the AUX_CTL
1250          * register with to kick off an AUX transaction.
1251          */
1252         u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes,
1253                                 u32 aux_clock_divider);
1254
1255         i915_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp);
1256         i915_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index);
1257
1258         /* This is called before a link training is starterd */
1259         void (*prepare_link_retrain)(struct intel_dp *intel_dp);
1260
1261         /* Displayport compliance testing */
1262         struct intel_dp_compliance compliance;
1263
1264         /* Display stream compression testing */
1265         bool force_dsc_en;
1266 };
1267
1268 enum lspcon_vendor {
1269         LSPCON_VENDOR_MCA,
1270         LSPCON_VENDOR_PARADE
1271 };
1272
1273 struct intel_lspcon {
1274         bool active;
1275         enum drm_lspcon_mode mode;
1276         enum lspcon_vendor vendor;
1277 };
1278
1279 struct intel_digital_port {
1280         struct intel_encoder base;
1281         u32 saved_port_bits;
1282         struct intel_dp dp;
1283         struct intel_hdmi hdmi;
1284         struct intel_lspcon lspcon;
1285         enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool);
1286         bool release_cl2_override;
1287         u8 max_lanes;
1288         /* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */
1289         enum aux_ch aux_ch;
1290         enum intel_display_power_domain ddi_io_power_domain;
1291         struct mutex tc_lock;   /* protects the TypeC port mode */
1292         intel_wakeref_t tc_lock_wakeref;
1293         int tc_link_refcount;
1294         bool tc_legacy_port:1;
1295         char tc_port_name[8];
1296         enum tc_port_mode tc_mode;
1297         enum phy_fia tc_phy_fia;
1298         u8 tc_phy_fia_idx;
1299
1300         void (*write_infoframe)(struct intel_encoder *encoder,
1301                                 const struct intel_crtc_state *crtc_state,
1302                                 unsigned int type,
1303                                 const void *frame, ssize_t len);
1304         void (*read_infoframe)(struct intel_encoder *encoder,
1305                                const struct intel_crtc_state *crtc_state,
1306                                unsigned int type,
1307                                void *frame, ssize_t len);
1308         void (*set_infoframes)(struct intel_encoder *encoder,
1309                                bool enable,
1310                                const struct intel_crtc_state *crtc_state,
1311                                const struct drm_connector_state *conn_state);
1312         u32 (*infoframes_enabled)(struct intel_encoder *encoder,
1313                                   const struct intel_crtc_state *pipe_config);
1314 };
1315
1316 struct intel_dp_mst_encoder {
1317         struct intel_encoder base;
1318         enum pipe pipe;
1319         struct intel_digital_port *primary;
1320         struct intel_connector *connector;
1321 };
1322
1323 static inline enum dpio_channel
1324 vlv_dport_to_channel(struct intel_digital_port *dport)
1325 {
1326         switch (dport->base.port) {
1327         case PORT_B:
1328         case PORT_D:
1329                 return DPIO_CH0;
1330         case PORT_C:
1331                 return DPIO_CH1;
1332         default:
1333                 BUG();
1334         }
1335 }
1336
1337 static inline enum dpio_phy
1338 vlv_dport_to_phy(struct intel_digital_port *dport)
1339 {
1340         switch (dport->base.port) {
1341         case PORT_B:
1342         case PORT_C:
1343                 return DPIO_PHY0;
1344         case PORT_D:
1345                 return DPIO_PHY1;
1346         default:
1347                 BUG();
1348         }
1349 }
1350
1351 static inline enum dpio_channel
1352 vlv_pipe_to_channel(enum pipe pipe)
1353 {
1354         switch (pipe) {
1355         case PIPE_A:
1356         case PIPE_C:
1357                 return DPIO_CH0;
1358         case PIPE_B:
1359                 return DPIO_CH1;
1360         default:
1361                 BUG();
1362         }
1363 }
1364
1365 static inline struct intel_crtc *
1366 intel_get_crtc_for_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
1367 {
1368         return dev_priv->pipe_to_crtc_mapping[pipe];
1369 }
1370
1371 static inline struct intel_crtc *
1372 intel_get_crtc_for_plane(struct drm_i915_private *dev_priv, enum i9xx_plane_id plane)
1373 {
1374         return dev_priv->plane_to_crtc_mapping[plane];
1375 }
1376
1377 struct intel_load_detect_pipe {
1378         struct drm_atomic_state *restore_state;
1379 };
1380
1381 static inline struct intel_encoder *
1382 intel_attached_encoder(struct drm_connector *connector)
1383 {
1384         return to_intel_connector(connector)->encoder;
1385 }
1386
1387 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder)
1388 {
1389         switch (encoder->type) {
1390         case INTEL_OUTPUT_DDI:
1391         case INTEL_OUTPUT_DP:
1392         case INTEL_OUTPUT_EDP:
1393         case INTEL_OUTPUT_HDMI:
1394                 return true;
1395         default:
1396                 return false;
1397         }
1398 }
1399
1400 static inline struct intel_digital_port *
1401 enc_to_dig_port(struct drm_encoder *encoder)
1402 {
1403         struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1404
1405         if (intel_encoder_is_dig_port(intel_encoder))
1406                 return container_of(encoder, struct intel_digital_port,
1407                                     base.base);
1408         else
1409                 return NULL;
1410 }
1411
1412 static inline struct intel_digital_port *
1413 conn_to_dig_port(struct intel_connector *connector)
1414 {
1415         return enc_to_dig_port(&intel_attached_encoder(&connector->base)->base);
1416 }
1417
1418 static inline struct intel_dp_mst_encoder *
1419 enc_to_mst(struct drm_encoder *encoder)
1420 {
1421         return container_of(encoder, struct intel_dp_mst_encoder, base.base);
1422 }
1423
1424 static inline struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
1425 {
1426         return &enc_to_dig_port(encoder)->dp;
1427 }
1428
1429 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder)
1430 {
1431         switch (encoder->type) {
1432         case INTEL_OUTPUT_DP:
1433         case INTEL_OUTPUT_EDP:
1434                 return true;
1435         case INTEL_OUTPUT_DDI:
1436                 /* Skip pure HDMI/DVI DDI encoders */
1437                 return i915_mmio_reg_valid(enc_to_intel_dp(&encoder->base)->output_reg);
1438         default:
1439                 return false;
1440         }
1441 }
1442
1443 static inline struct intel_lspcon *
1444 enc_to_intel_lspcon(struct drm_encoder *encoder)
1445 {
1446         return &enc_to_dig_port(encoder)->lspcon;
1447 }
1448
1449 static inline struct intel_digital_port *
1450 dp_to_dig_port(struct intel_dp *intel_dp)
1451 {
1452         return container_of(intel_dp, struct intel_digital_port, dp);
1453 }
1454
1455 static inline struct intel_lspcon *
1456 dp_to_lspcon(struct intel_dp *intel_dp)
1457 {
1458         return &dp_to_dig_port(intel_dp)->lspcon;
1459 }
1460
1461 static inline struct drm_i915_private *
1462 dp_to_i915(struct intel_dp *intel_dp)
1463 {
1464         return to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
1465 }
1466
1467 static inline struct intel_digital_port *
1468 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
1469 {
1470         return container_of(intel_hdmi, struct intel_digital_port, hdmi);
1471 }
1472
1473 static inline struct intel_plane_state *
1474 intel_atomic_get_plane_state(struct intel_atomic_state *state,
1475                                  struct intel_plane *plane)
1476 {
1477         struct drm_plane_state *ret =
1478                 drm_atomic_get_plane_state(&state->base, &plane->base);
1479
1480         if (IS_ERR(ret))
1481                 return ERR_CAST(ret);
1482
1483         return to_intel_plane_state(ret);
1484 }
1485
1486 static inline struct intel_plane_state *
1487 intel_atomic_get_old_plane_state(struct intel_atomic_state *state,
1488                                  struct intel_plane *plane)
1489 {
1490         return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base,
1491                                                                    &plane->base));
1492 }
1493
1494 static inline struct intel_plane_state *
1495 intel_atomic_get_new_plane_state(struct intel_atomic_state *state,
1496                                  struct intel_plane *plane)
1497 {
1498         return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base,
1499                                                                    &plane->base));
1500 }
1501
1502 static inline struct intel_crtc_state *
1503 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state,
1504                                 struct intel_crtc *crtc)
1505 {
1506         return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base,
1507                                                                  &crtc->base));
1508 }
1509
1510 static inline struct intel_crtc_state *
1511 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state,
1512                                 struct intel_crtc *crtc)
1513 {
1514         return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base,
1515                                                                  &crtc->base));
1516 }
1517
1518 /* intel_display.c */
1519 static inline bool
1520 intel_crtc_has_type(const struct intel_crtc_state *crtc_state,
1521                     enum intel_output_type type)
1522 {
1523         return crtc_state->output_types & (1 << type);
1524 }
1525 static inline bool
1526 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state)
1527 {
1528         return crtc_state->output_types &
1529                 ((1 << INTEL_OUTPUT_DP) |
1530                  (1 << INTEL_OUTPUT_DP_MST) |
1531                  (1 << INTEL_OUTPUT_EDP));
1532 }
1533 static inline void
1534 intel_wait_for_vblank(struct drm_i915_private *dev_priv, enum pipe pipe)
1535 {
1536         drm_wait_one_vblank(&dev_priv->drm, pipe);
1537 }
1538 static inline void
1539 intel_wait_for_vblank_if_active(struct drm_i915_private *dev_priv, enum pipe pipe)
1540 {
1541         const struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1542
1543         if (crtc->active)
1544                 intel_wait_for_vblank(dev_priv, pipe);
1545 }
1546
1547 static inline u32 intel_plane_ggtt_offset(const struct intel_plane_state *state)
1548 {
1549         return i915_ggtt_offset(state->vma);
1550 }
1551
1552 #endif /*  __INTEL_DISPLAY_TYPES_H__ */