OSDN Git Service

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