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