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