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