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