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/pm_qos.h>
30 #include <linux/pwm.h>
31
32 #include <drm/display/drm_dp_dual_mode_helper.h>
33 #include <drm/display/drm_dp_mst_helper.h>
34 #include <drm/display/drm_dp_tunnel.h>
35 #include <drm/display/drm_dsc.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_colorop.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_encoder.h>
40 #include <drm/drm_framebuffer.h>
41 #include <drm/drm_panel.h>
42 #include <drm/drm_rect.h>
43 #include <drm/drm_vblank_work.h>
44 #include <drm/intel/i915_hdcp_interface.h>
45 #include <uapi/drm/i915_drm.h>
46
47 #include "i915_gtt_view_types.h"
48 #include "intel_bios.h"
49 #include "intel_display.h"
50 #include "intel_display_conversion.h"
51 #include "intel_display_limits.h"
52 #include "intel_display_power.h"
53 #include "intel_dpll_mgr.h"
54 #include "intel_dsi_vbt_defs.h"
55 #include "intel_wm_types.h"
56
57 struct cec_notifier;
58 struct drm_printer;
59 struct intel_connector;
60 struct intel_ddi_buf_trans;
61 struct intel_fbc;
62 struct intel_global_objs_state;
63 struct intel_hdcp_shim;
64 struct intel_panic;
65 struct intel_tc_port;
66
67 /*
68 * Display related stuff
69 */
70
71 /* these are outputs from the chip - integrated only
72 external chips are via DVO or SDVO output */
73 enum intel_output_type {
74 INTEL_OUTPUT_UNUSED = 0,
75 INTEL_OUTPUT_ANALOG = 1,
76 INTEL_OUTPUT_DVO = 2,
77 INTEL_OUTPUT_SDVO = 3,
78 INTEL_OUTPUT_LVDS = 4,
79 INTEL_OUTPUT_TVOUT = 5,
80 INTEL_OUTPUT_HDMI = 6,
81 INTEL_OUTPUT_DP = 7,
82 INTEL_OUTPUT_EDP = 8,
83 INTEL_OUTPUT_DSI = 9,
84 INTEL_OUTPUT_DDI = 10,
85 INTEL_OUTPUT_DP_MST = 11,
86 };
87
88 enum hdmi_force_audio {
89 HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
90 HDMI_AUDIO_OFF, /* force turn off HDMI audio */
91 HDMI_AUDIO_AUTO, /* trust EDID */
92 HDMI_AUDIO_ON, /* force turn on HDMI audio */
93 };
94
95 /* "Broadcast RGB" property */
96 enum intel_broadcast_rgb {
97 INTEL_BROADCAST_RGB_AUTO,
98 INTEL_BROADCAST_RGB_FULL,
99 INTEL_BROADCAST_RGB_LIMITED,
100 };
101
102 struct intel_fb_view {
103 /*
104 * The remap information used in the remapped and rotated views to
105 * create the DMA scatter-gather list for each FB color plane. This sg
106 * list is created along with the view type (gtt.type) specific
107 * i915_vma object and contains the list of FB object pages (reordered
108 * in the rotated view) that are visible in the view.
109 * In the normal view the FB object's backing store sg list is used
110 * directly and hence the remap information here is not used.
111 */
112 struct i915_gtt_view gtt;
113
114 /*
115 * The GTT view (gtt.type) specific information for each FB color
116 * plane. In the normal GTT view all formats (up to 4 color planes),
117 * in the rotated and remapped GTT view all no-CCS formats (up to 2
118 * color planes) are supported.
119 *
120 * The view information shared by all FB color planes in the FB,
121 * like dst x/y and src/dst width, is stored separately in
122 * intel_plane_state.
123 */
124 struct i915_color_plane_view {
125 u32 offset;
126 unsigned int x, y;
127 /*
128 * Plane stride in:
129 * bytes for 0/180 degree rotation
130 * pixels for 90/270 degree rotation
131 */
132 unsigned int mapping_stride;
133 unsigned int scanout_stride;
134 } color_plane[4];
135 };
136
137 struct intel_framebuffer {
138 struct drm_framebuffer base;
139 struct intel_frontbuffer *frontbuffer;
140
141 /* Params to remap the FB pages and program the plane registers in each view. */
142 struct intel_fb_view normal_view;
143 union {
144 struct intel_fb_view rotated_view;
145 struct intel_fb_view remapped_view;
146 };
147
148 struct intel_dpt *dpt;
149
150 unsigned int min_alignment;
151 unsigned int vtd_guard;
152
153 unsigned int (*panic_tiling)(unsigned int x, unsigned int y, unsigned int width);
154 struct intel_panic *panic;
155 };
156
157 enum intel_hotplug_state {
158 INTEL_HOTPLUG_UNCHANGED,
159 INTEL_HOTPLUG_CHANGED,
160 INTEL_HOTPLUG_RETRY,
161 };
162
163 struct intel_encoder {
164 struct drm_encoder base;
165
166 enum intel_output_type type;
167 enum port port;
168 u16 cloneable;
169 u8 pipe_mask;
170
171 /* Check and recover a bad link state. */
172 struct delayed_work link_check_work;
173 void (*link_check)(struct intel_encoder *encoder);
174
175 enum intel_hotplug_state (*hotplug)(struct intel_encoder *encoder,
176 struct intel_connector *connector);
177 enum intel_output_type (*compute_output_type)(struct intel_encoder *,
178 struct intel_crtc_state *,
179 struct drm_connector_state *);
180 int (*compute_config)(struct intel_encoder *,
181 struct intel_crtc_state *,
182 struct drm_connector_state *);
183 int (*compute_config_late)(struct intel_encoder *,
184 struct intel_crtc_state *,
185 struct drm_connector_state *);
186 void (*pre_pll_enable)(struct intel_atomic_state *,
187 struct intel_encoder *,
188 const struct intel_crtc_state *,
189 const struct drm_connector_state *);
190 void (*pre_enable)(struct intel_atomic_state *,
191 struct intel_encoder *,
192 const struct intel_crtc_state *,
193 const struct drm_connector_state *);
194 void (*enable)(struct intel_atomic_state *,
195 struct intel_encoder *,
196 const struct intel_crtc_state *,
197 const struct drm_connector_state *);
198 void (*disable)(struct intel_atomic_state *,
199 struct intel_encoder *,
200 const struct intel_crtc_state *,
201 const struct drm_connector_state *);
202 void (*post_disable)(struct intel_atomic_state *,
203 struct intel_encoder *,
204 const struct intel_crtc_state *,
205 const struct drm_connector_state *);
206 void (*post_pll_disable)(struct intel_atomic_state *,
207 struct intel_encoder *,
208 const struct intel_crtc_state *,
209 const struct drm_connector_state *);
210 void (*update_pipe)(struct intel_atomic_state *,
211 struct intel_encoder *,
212 const struct intel_crtc_state *,
213 const struct drm_connector_state *);
214 void (*audio_enable)(struct intel_encoder *encoder,
215 const struct intel_crtc_state *crtc_state,
216 const struct drm_connector_state *conn_state);
217 void (*audio_disable)(struct intel_encoder *encoder,
218 const struct intel_crtc_state *old_crtc_state,
219 const struct drm_connector_state *old_conn_state);
220 /* Read out the current hw state of this connector, returning true if
221 * the encoder is active. If the encoder is enabled it also set the pipe
222 * it is connected to in the pipe parameter. */
223 bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
224 /* Reconstructs the equivalent mode flags for the current hardware
225 * state. This must be called _after_ display->get_pipe_config has
226 * pre-filled the pipe config. Note that intel_encoder->base.crtc must
227 * be set correctly before calling this function. */
228 void (*get_config)(struct intel_encoder *,
229 struct intel_crtc_state *pipe_config);
230
231 /*
232 * Optional hook called during init/resume to sync any state
233 * stored in the encoder (eg. DP link parameters) wrt. the HW state.
234 */
235 void (*sync_state)(struct intel_encoder *encoder,
236 const struct intel_crtc_state *crtc_state);
237
238 /*
239 * Optional hook, returning true if this encoder allows a fastset
240 * during the initial commit, false otherwise.
241 */
242 bool (*initial_fastset_check)(struct intel_encoder *encoder,
243 struct intel_crtc_state *crtc_state);
244
245 /*
246 * Acquires the power domains needed for an active encoder during
247 * hardware state readout.
248 */
249 void (*get_power_domains)(struct intel_encoder *encoder,
250 struct intel_crtc_state *crtc_state);
251 /*
252 * Called during system suspend after all pending requests for the
253 * encoder are flushed (for example for DP AUX transactions) and
254 * device interrupts are disabled.
255 * All modeset locks are held while the hook is called.
256 */
257 void (*suspend)(struct intel_encoder *);
258 /*
259 * Called without the modeset locks held after the suspend() hook for
260 * all encoders have been called.
261 */
262 void (*suspend_complete)(struct intel_encoder *encoder);
263 /*
264 * Called during system reboot/shutdown after all the
265 * encoders have been disabled and suspended.
266 * All modeset locks are held while the hook is called.
267 */
268 void (*shutdown)(struct intel_encoder *encoder);
269 /*
270 * Called without the modeset locks held after the shutdown() hook for
271 * all encoders have been called.
272 */
273 void (*shutdown_complete)(struct intel_encoder *encoder);
274 /*
275 * Enable/disable the clock to the port.
276 */
277 void (*enable_clock)(struct intel_encoder *encoder,
278 const struct intel_crtc_state *crtc_state);
279 void (*disable_clock)(struct intel_encoder *encoder);
280 /*
281 * Returns whether the port clock is enabled or not.
282 */
283 bool (*is_clock_enabled)(struct intel_encoder *encoder);
284 /*
285 * Returns the PLL type the port uses.
286 */
287 enum icl_port_dpll_id (*port_pll_type)(struct intel_encoder *encoder,
288 const struct intel_crtc_state *crtc_state);
289 const struct intel_ddi_buf_trans *(*get_buf_trans)(struct intel_encoder *encoder,
290 const struct intel_crtc_state *crtc_state,
291 int *n_entries);
292 void (*set_signal_levels)(struct intel_encoder *encoder,
293 const struct intel_crtc_state *crtc_state);
294
295 enum hpd_pin hpd_pin;
296 enum intel_display_power_domain power_domain;
297
298 /* VBT information for this encoder (may be NULL for older platforms) */
299 const struct intel_bios_encoder_data *devdata;
300 };
301
302 struct intel_panel_bl_funcs {
303 /* Connector and platform specific backlight functions */
304 int (*setup)(struct intel_connector *connector, enum pipe pipe);
305 u32 (*get)(struct intel_connector *connector, enum pipe pipe);
306 void (*set)(const struct drm_connector_state *conn_state, u32 level);
307 void (*disable)(const struct drm_connector_state *conn_state, u32 level);
308 void (*enable)(const struct intel_crtc_state *crtc_state,
309 const struct drm_connector_state *conn_state, u32 level);
310 u32 (*hz_to_pwm)(struct intel_connector *connector, u32 hz);
311 };
312
313 /* in 100us units */
314 struct intel_pps_delays {
315 u16 power_up; /* eDP: T1+T3, LVDS: T1+T2 */
316 u16 backlight_on; /* eDP: T8, LVDS: T5 */
317 u16 backlight_off; /* eDP: T9, LVDS: T6/TX */
318 u16 power_down; /* eDP: T10, LVDS: T3 */
319 u16 power_cycle; /* eDP: T11+T12, LVDS: T7+T4 */
320 };
321
322 enum drrs_type {
323 DRRS_TYPE_NONE,
324 DRRS_TYPE_STATIC,
325 DRRS_TYPE_SEAMLESS,
326 };
327
328 struct intel_vbt_panel_data {
329 struct drm_display_mode *lfp_vbt_mode; /* if any */
330 struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
331
332 /* Feature bits */
333 int panel_type;
334 unsigned int lvds_dither:1;
335 unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
336
337 bool vrr;
338
339 u8 seamless_drrs_min_refresh_rate;
340 enum drrs_type drrs_type;
341
342 struct {
343 int max_link_rate;
344 int rate;
345 int lanes;
346 int preemphasis;
347 int vswing;
348 int bpp;
349 struct intel_pps_delays pps;
350 u8 drrs_msa_timing_delay;
351 bool low_vswing;
352 bool hobl;
353 bool dsc_disable;
354 bool pipe_joiner_enable;
355 } edp;
356
357 struct {
358 bool enable;
359 bool full_link;
360 bool require_aux_wakeup;
361 int idle_frames;
362 int tp1_wakeup_time_us;
363 int tp2_tp3_wakeup_time_us;
364 int psr2_tp2_tp3_wakeup_time_us;
365 } psr;
366
367 struct {
368 u16 pwm_freq_hz;
369 u16 brightness_precision_bits;
370 u16 hdr_dpcd_refresh_timeout;
371 bool present;
372 bool active_low_pwm;
373 u8 min_brightness; /* min_brightness/255 of max */
374 s8 controller; /* brightness controller number */
375 enum intel_backlight_type type;
376 } backlight;
377
378 /* MIPI DSI */
379 struct {
380 u16 panel_id;
381 struct mipi_config *config;
382 struct mipi_pps_data *pps;
383 u16 bl_ports;
384 u16 cabc_ports;
385 u8 seq_version;
386 u32 size;
387 u8 *data;
388 const u8 *sequence[MIPI_SEQ_MAX];
389 u8 *deassert_seq; /* Used by fixup_mipi_sequences() */
390 enum drm_panel_orientation orientation;
391 } dsi;
392 };
393
394 struct intel_panel {
395 /* Simple drm_panel */
396 struct drm_panel *base;
397
398 /* Fixed EDID for eDP and LVDS. May hold ERR_PTR for invalid EDID. */
399 const struct drm_edid *fixed_edid;
400
401 struct list_head fixed_modes;
402
403 /* backlight */
404 struct {
405 bool present;
406 u32 level;
407 u32 min;
408 u32 max;
409 bool enabled;
410 bool combination_mode; /* gen 2/4 only */
411 bool active_low_pwm;
412 bool alternate_pwm_increment; /* lpt+ */
413
414 /* PWM chip */
415 u32 pwm_level_min;
416 u32 pwm_level_max;
417 bool pwm_enabled;
418 bool util_pin_active_low; /* bxt+ */
419 u8 controller; /* bxt+ only */
420 struct pwm_device *pwm;
421 struct pwm_state pwm_state;
422
423 /* DPCD backlight */
424 union {
425 struct {
426 struct drm_edp_backlight_info info;
427 bool luminance_control_support;
428 } vesa;
429 struct {
430 bool sdr_uses_aux;
431 bool supports_2084_decode;
432 bool supports_2020_gamut;
433 bool supports_segmented_backlight;
434 bool supports_sdp_colorimetry;
435 bool supports_tone_mapping;
436 } intel_cap;
437 } edp;
438
439 struct backlight_device *device;
440
441 const struct intel_panel_bl_funcs *funcs;
442 const struct intel_panel_bl_funcs *pwm_funcs;
443 void (*power)(struct intel_connector *, bool enable);
444 } backlight;
445
446 struct intel_vbt_panel_data vbt;
447 };
448
449 struct intel_digital_port;
450
451 struct intel_hdcp {
452 const struct intel_hdcp_shim *shim;
453 /* Mutex for hdcp state of the connector */
454 struct mutex mutex;
455 u64 value;
456 struct delayed_work check_work;
457 struct work_struct prop_work;
458
459 /* HDCP1.4 Encryption status */
460 bool hdcp_encrypted;
461
462 /* HDCP2.2 related definitions */
463 /* Flag indicates whether this connector supports HDCP2.2 or not. */
464 bool hdcp2_supported;
465
466 /* HDCP2.2 Encryption status */
467 bool hdcp2_encrypted;
468
469 /*
470 * Content Stream Type defined by content owner. TYPE0(0x0) content can
471 * flow in the link protected by HDCP2.2 or HDCP1.4, where as TYPE1(0x1)
472 * content can flow only through a link protected by HDCP2.2.
473 */
474 u8 content_type;
475
476 bool is_paired;
477 bool is_repeater;
478
479 /*
480 * Count of ReceiverID_List received. Initialized to 0 at AKE_INIT.
481 * Incremented after processing the RepeaterAuth_Send_ReceiverID_List.
482 * When it rolls over re-auth has to be triggered.
483 */
484 u32 seq_num_v;
485
486 /*
487 * Count of RepeaterAuth_Stream_Manage msg propagated.
488 * Initialized to 0 on AKE_INIT. Incremented after every successful
489 * transmission of RepeaterAuth_Stream_Manage message. When it rolls
490 * over re-Auth has to be triggered.
491 */
492 u32 seq_num_m;
493
494 /*
495 * Work queue to signal the CP_IRQ. Used for the waiters to read the
496 * available information from HDCP DP sink.
497 */
498 wait_queue_head_t cp_irq_queue;
499 atomic_t cp_irq_count;
500 int cp_irq_count_cached;
501
502 /*
503 * HDCP register access for gen12+ need the transcoder associated.
504 * Transcoder attached to the connector could be changed at modeset.
505 * Hence caching the transcoder here.
506 */
507 enum transcoder cpu_transcoder;
508 /* Only used for DP MST stream encryption */
509 enum transcoder stream_transcoder;
510 /* Used to force HDCP 1.4 bypassing HDCP 2.x */
511 bool force_hdcp14;
512 };
513
514 enum intel_panel_replay_dsc_support {
515 INTEL_DP_PANEL_REPLAY_DSC_NOT_SUPPORTED,
516 INTEL_DP_PANEL_REPLAY_DSC_FULL_FRAME_ONLY,
517 INTEL_DP_PANEL_REPLAY_DSC_SELECTIVE_UPDATE,
518 };
519
520 struct intel_connector {
521 struct drm_connector base;
522 /*
523 * The fixed encoder this connector is connected to.
524 */
525 struct intel_encoder *encoder;
526
527 /* ACPI device id for ACPI and driver cooperation */
528 u32 acpi_device_id;
529
530 /* Reads out the current hw, returning true if the connector is enabled
531 * and active (i.e. dpms ON state). */
532 bool (*get_hw_state)(struct intel_connector *);
533
534 /*
535 * Optional hook called during init/resume to sync any state
536 * stored in the connector (eg. DSC state) wrt. the HW state.
537 */
538 void (*sync_state)(struct intel_connector *connector,
539 const struct intel_crtc_state *crtc_state);
540
541 /* Panel info for eDP and LVDS */
542 struct intel_panel panel;
543
544 /* Cached EDID for detect. */
545 const struct drm_edid *detect_edid;
546
547 /* Number of times hotplug detection was tried after an HPD interrupt */
548 int hotplug_retries;
549
550 /* since POLL and HPD connectors may use the same HPD line keep the native
551 state of connector->polled in case hotplug storm detection changes it */
552 u8 polled;
553
554 int force_joined_pipes;
555
556 struct {
557 struct drm_dp_aux *dsc_decompression_aux;
558 u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE];
559 u8 fec_capability;
560
561 u8 dsc_hblank_expansion_quirk:1;
562 u8 dsc_throughput_quirk:1;
563 u8 dsc_decompression_enabled:1;
564
565 struct {
566 struct {
567 int rgb_yuv444;
568 int yuv422_420;
569 } overall_throughput;
570 int max_line_width;
571 } dsc_branch_caps;
572
573 struct {
574 u8 dpcd[DP_PANEL_REPLAY_CAP_SIZE];
575 #define INTEL_PR_DPCD_INDEX(pr_dpcd_register) ((pr_dpcd_register) - DP_PANEL_REPLAY_CAP_SUPPORT)
576
577 bool support;
578 bool su_support;
579 enum intel_panel_replay_dsc_support dsc_support;
580
581 u16 su_w_granularity;
582 u16 su_y_granularity;
583 } panel_replay_caps;
584
585 struct {
586 u8 dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
587
588 bool support;
589 bool su_support;
590
591 u16 su_w_granularity;
592 u16 su_y_granularity;
593
594 u8 sync_latency;
595 } psr_caps;
596 } dp;
597
598 struct {
599 struct drm_dp_mst_port *port;
600 struct intel_dp *dp;
601 } mst;
602
603 struct {
604 int force_bpp_x16;
605 } link;
606
607 /* Work struct to schedule a uevent on link train failure */
608 struct work_struct modeset_retry_work;
609
610 struct intel_hdcp hdcp;
611 };
612
613 struct intel_digital_connector_state {
614 struct drm_connector_state base;
615
616 enum hdmi_force_audio force_audio;
617 int broadcast_rgb;
618 };
619
620 #define to_intel_digital_connector_state(conn_state) \
621 container_of_const((conn_state), struct intel_digital_connector_state, base)
622
623 struct dpll {
624 /* given values */
625 int n;
626 int m1, m2;
627 int p1, p2;
628 /* derived values */
629 int dot;
630 int vco;
631 int m;
632 int p;
633 };
634
635 struct intel_atomic_state {
636 struct drm_atomic_state base;
637
638 struct ref_tracker *wakeref;
639
640 struct intel_global_objs_state *global_objs;
641 int num_global_objs;
642
643 /* Internal commit, as opposed to userspace/client initiated one */
644 bool internal;
645
646 bool dpll_set, modeset;
647
648 struct intel_dpll_state dpll_state[I915_NUM_PLLS];
649
650 struct intel_dp_tunnel_inherited_state *inherited_dp_tunnels;
651
652 /*
653 * Current watermarks can't be trusted during hardware readout, so
654 * don't bother calculating intermediate watermarks.
655 */
656 bool skip_intermediate_wm;
657
658 bool rps_interactive;
659
660 struct work_struct cleanup_work;
661 };
662
663 struct intel_plane_state {
664 struct drm_plane_state uapi;
665
666 /*
667 * actual hardware state, the state we program to the hardware.
668 * The following members are used to verify the hardware state:
669 * During initial hw readout, they need to be copied from uapi.
670 */
671 struct {
672 struct drm_crtc *crtc;
673 struct drm_framebuffer *fb;
674
675 u16 alpha;
676 u16 pixel_blend_mode;
677 unsigned int rotation;
678 enum drm_color_encoding color_encoding;
679 enum drm_color_range color_range;
680 enum drm_scaling_filter scaling_filter;
681 struct drm_property_blob *ctm, *degamma_lut, *gamma_lut, *lut_3d;
682 } hw;
683
684 struct i915_vma *ggtt_vma;
685 struct i915_vma *dpt_vma;
686 unsigned long flags;
687 #define PLANE_HAS_FENCE BIT(0)
688
689 struct intel_fb_view view;
690
691 /* for legacy cursor fb unpin */
692 struct drm_vblank_work unpin_work;
693
694 /* Plane pxp decryption state */
695 bool decrypt;
696
697 /* Plane state to display black pixels when pxp is borked */
698 bool force_black;
699
700 /* Acting as Y plane for another UV plane? */
701 bool is_y_plane;
702
703 /* plane control register */
704 u32 ctl;
705
706 /* plane color control register */
707 u32 color_ctl;
708
709 /* chroma upsampler control register */
710 u32 cus_ctl;
711
712 /* surface address register */
713 u32 surf;
714
715 /*
716 * scaler_id
717 * = -1 : not using a scaler
718 * >= 0 : using a scalers
719 *
720 * plane requiring a scaler:
721 * - During check_plane, its bit is set in
722 * crtc_state->scaler_state.scaler_users by calling helper function
723 * update_scaler_plane.
724 * - scaler_id indicates the scaler it got assigned.
725 *
726 * plane doesn't require a scaler:
727 * - this can happen when scaling is no more required or plane simply
728 * got disabled.
729 * - During check_plane, corresponding bit is reset in
730 * crtc_state->scaler_state.scaler_users by calling helper function
731 * update_scaler_plane.
732 */
733 int scaler_id;
734
735 /*
736 * planar_linked_plane:
737 *
738 * ICL planar formats require 2 planes that are updated as pairs.
739 * This member is used to make sure the other plane is also updated
740 * when required, and for update_slave() to find the correct
741 * plane_state to pass as argument.
742 */
743 struct intel_plane *planar_linked_plane;
744
745 struct drm_intel_sprite_colorkey ckey;
746
747 struct drm_rect psr2_sel_fetch_area;
748
749 /* Clear Color Value */
750 u64 ccval;
751
752 const char *no_fbc_reason;
753
754 struct drm_rect damage;
755 };
756
757 struct intel_initial_plane_config {
758 struct intel_framebuffer *fb;
759 struct intel_memory_region *mem;
760 resource_size_t phys_base;
761 struct i915_vma *vma;
762 int size;
763 u32 base;
764 u8 rotation;
765 };
766
767 struct intel_scaler {
768 u32 mode;
769 bool in_use;
770 int hscale;
771 int vscale;
772 };
773
774 struct intel_crtc_scaler_state {
775 #define SKL_NUM_SCALERS 2
776 struct intel_scaler scalers[SKL_NUM_SCALERS];
777
778 /*
779 * scaler_users: keeps track of users requesting scalers on this crtc.
780 *
781 * If a bit is set, a user is using a scaler.
782 * Here user can be a plane or crtc as defined below:
783 * bits 0-30 - plane (bit position is index from drm_plane_index)
784 * bit 31 - crtc
785 *
786 * Instead of creating a new index to cover planes and crtc, using
787 * existing drm_plane_index for planes which is well less than 31
788 * planes and bit 31 for crtc. This should be fine to cover all
789 * our platforms.
790 *
791 * intel_atomic_setup_scalers will setup available scalers to users
792 * requesting scalers. It will gracefully fail if request exceeds
793 * availability.
794 */
795 #define SKL_CRTC_INDEX 31
796 unsigned scaler_users;
797
798 /* scaler used by crtc for panel fitting purpose */
799 int scaler_id;
800 };
801
802 /* {crtc,crtc_state}->mode_flags */
803 /* Flag to get scanline using frame time stamps */
804 #define I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP (1<<1)
805 /* Flag to use the scanline counter instead of the pixel counter */
806 #define I915_MODE_FLAG_USE_SCANLINE_COUNTER (1<<2)
807 /*
808 * TE0 or TE1 flag is set if the crtc has a DSI encoder which
809 * is operating in command mode.
810 * Flag to use TE from DSI0 instead of VBI in command mode
811 */
812 #define I915_MODE_FLAG_DSI_USE_TE0 (1<<3)
813 /* Flag to use TE from DSI1 instead of VBI in command mode */
814 #define I915_MODE_FLAG_DSI_USE_TE1 (1<<4)
815 /* Flag to indicate mipi dsi periodic command mode where we do not get TE */
816 #define I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE (1<<5)
817 /* Do tricks to make vblank timestamps sane with VRR? */
818 #define I915_MODE_FLAG_VRR (1<<6)
819
820 struct intel_wm_level {
821 bool enable;
822 u32 pri_val;
823 u32 spr_val;
824 u32 cur_val;
825 u32 fbc_val;
826 };
827
828 struct intel_pipe_wm {
829 struct intel_wm_level wm[5];
830 bool fbc_wm_enabled;
831 bool pipe_enabled;
832 bool sprites_enabled;
833 bool sprites_scaled;
834 };
835
836 struct skl_wm_level {
837 u16 min_ddb_alloc;
838 u16 min_ddb_alloc_uv; /* for pre-icl */
839 u16 blocks;
840 u8 lines;
841 bool enable;
842 bool ignore_lines;
843 bool auto_min_alloc_wm_enable;
844 bool can_sagv;
845 };
846
847 struct skl_plane_wm {
848 struct skl_wm_level wm[8];
849 struct skl_wm_level trans_wm;
850 struct {
851 struct skl_wm_level wm0;
852 struct skl_wm_level trans_wm;
853 } sagv;
854 };
855
856 struct skl_pipe_wm {
857 struct skl_plane_wm planes[I915_MAX_PLANES];
858 bool use_sagv_wm;
859 };
860
861 enum vlv_wm_level {
862 VLV_WM_LEVEL_PM2,
863 VLV_WM_LEVEL_PM5,
864 VLV_WM_LEVEL_DDR_DVFS,
865 NUM_VLV_WM_LEVELS,
866 };
867
868 struct vlv_wm_state {
869 struct g4x_pipe_wm wm[NUM_VLV_WM_LEVELS];
870 struct g4x_sr_wm sr[NUM_VLV_WM_LEVELS];
871 u8 num_levels;
872 bool cxsr;
873 };
874
875 struct vlv_fifo_state {
876 u16 plane[I915_MAX_PLANES];
877 };
878
879 enum g4x_wm_level {
880 G4X_WM_LEVEL_NORMAL,
881 G4X_WM_LEVEL_SR,
882 G4X_WM_LEVEL_HPLL,
883 NUM_G4X_WM_LEVELS,
884 };
885
886 struct g4x_wm_state {
887 struct g4x_pipe_wm wm;
888 struct g4x_sr_wm sr;
889 struct g4x_sr_wm hpll;
890 bool cxsr;
891 bool hpll_en;
892 bool fbc_en;
893 };
894
895 struct intel_crtc_wm_state {
896 union {
897 /*
898 * raw:
899 * The "raw" watermark values produced by the formula
900 * given the plane's current state. They do not consider
901 * how much FIFO is actually allocated for each plane.
902 *
903 * optimal:
904 * The "optimal" watermark values given the current
905 * state of the planes and the amount of FIFO
906 * allocated to each, ignoring any previous state
907 * of the planes.
908 *
909 * intermediate:
910 * The "intermediate" watermark values when transitioning
911 * between the old and new "optimal" values. Used when
912 * the watermark registers are single buffered and hence
913 * their state changes asynchronously with regards to the
914 * actual plane registers. These are essentially the
915 * worst case combination of the old and new "optimal"
916 * watermarks, which are therefore safe to use when the
917 * plane is in either its old or new state.
918 */
919 struct {
920 struct intel_pipe_wm intermediate;
921 struct intel_pipe_wm optimal;
922 } ilk;
923
924 struct {
925 struct skl_pipe_wm raw;
926 /* gen9+ only needs 1-step wm programming */
927 struct skl_pipe_wm optimal;
928 struct skl_ddb_entry ddb;
929 /*
930 * pre-icl: for packed/planar CbCr
931 * icl+: for everything
932 */
933 struct skl_ddb_entry plane_ddb[I915_MAX_PLANES];
934 /* pre-icl: for planar Y */
935 struct skl_ddb_entry plane_ddb_y[I915_MAX_PLANES];
936
937 /*
938 * xe3: Minimum amount of display blocks and minimum
939 * sagv allocation required for async flip
940 */
941 u16 plane_min_ddb[I915_MAX_PLANES];
942 u16 plane_interim_ddb[I915_MAX_PLANES];
943 } skl;
944
945 struct {
946 struct g4x_pipe_wm raw[NUM_VLV_WM_LEVELS]; /* not inverted */
947 struct vlv_wm_state intermediate; /* inverted */
948 struct vlv_wm_state optimal; /* inverted */
949 struct vlv_fifo_state fifo_state;
950 } vlv;
951
952 struct {
953 struct g4x_pipe_wm raw[NUM_G4X_WM_LEVELS];
954 struct g4x_wm_state intermediate;
955 struct g4x_wm_state optimal;
956 } g4x;
957 };
958
959 /*
960 * Platforms with two-step watermark programming will need to
961 * update watermark programming post-vblank to switch from the
962 * safe intermediate watermarks to the optimal final
963 * watermarks.
964 */
965 bool need_postvbl_update;
966 };
967
968 enum intel_output_format {
969 INTEL_OUTPUT_FORMAT_RGB,
970 INTEL_OUTPUT_FORMAT_YCBCR420,
971 INTEL_OUTPUT_FORMAT_YCBCR444,
972 };
973
974 /* Used by dp and fdi links */
975 struct intel_link_m_n {
976 u32 tu;
977 u32 data_m;
978 u32 data_n;
979 u32 link_m;
980 u32 link_n;
981 };
982
983 struct intel_csc_matrix {
984 u16 coeff[9];
985 u16 preoff[3];
986 u16 postoff[3];
987 };
988
989 struct scaler_filter_coeff {
990 u16 sign;
991 u16 exp;
992 u16 mantissa;
993 };
994
995 struct intel_casf {
996 #define SCALER_FILTER_NUM_TAPS 7
997 struct scaler_filter_coeff coeff[SCALER_FILTER_NUM_TAPS];
998 u8 strength;
999 u8 win_size;
1000 bool casf_enable;
1001 };
1002
1003 struct intel_crtc_state {
1004 /*
1005 * uapi (drm) state. This is the software state shown to userspace.
1006 * In particular, the following members are used for bookkeeping:
1007 * - crtc
1008 * - state
1009 * - *_changed
1010 * - event
1011 * - commit
1012 * - mode_blob
1013 */
1014 struct drm_crtc_state uapi;
1015
1016 /*
1017 * actual hardware state, the state we program to the hardware.
1018 * The following members are used to verify the hardware state:
1019 * - enable
1020 * - active
1021 * - mode / pipe_mode / adjusted_mode
1022 * - color property blobs.
1023 *
1024 * During initial hw readout, they need to be copied to uapi.
1025 *
1026 * Joiner will allow a transcoder mode that spans 2 pipes;
1027 * Use the pipe_mode for calculations like watermarks, pipe
1028 * scaler, and bandwidth.
1029 *
1030 * Use adjusted_mode for things that need to know the full
1031 * mode on the transcoder, which spans all pipes.
1032 */
1033 struct {
1034 bool active, enable;
1035 /* logical state of LUTs */
1036 struct drm_property_blob *degamma_lut, *gamma_lut, *ctm;
1037 struct drm_display_mode mode, pipe_mode, adjusted_mode;
1038 enum drm_scaling_filter scaling_filter;
1039 struct intel_casf casf_params;
1040 } hw;
1041
1042 /* actual state of LUTs */
1043 struct drm_property_blob *pre_csc_lut, *post_csc_lut;
1044
1045 struct intel_csc_matrix csc, output_csc;
1046
1047 /**
1048 * quirks - bitfield with hw state readout quirks
1049 *
1050 * For various reasons the hw state readout code might not be able to
1051 * completely faithfully read out the current state. These cases are
1052 * tracked with quirk flags so that fastboot and state checker can act
1053 * accordingly.
1054 */
1055 #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS (1<<0) /* unreliable sync mode.flags */
1056 unsigned long quirks;
1057
1058 unsigned fb_bits; /* framebuffers to flip */
1059 bool update_pipe; /* can a fast modeset be performed? */
1060 bool update_m_n; /* update M/N seamlessly during fastset? */
1061 bool update_lrr; /* update TRANS_VTOTAL/etc. during fastset? */
1062 bool disable_cxsr;
1063 bool update_wm_pre, update_wm_post; /* watermarks are updated */
1064 bool fifo_changed; /* FIFO split is changed */
1065 bool preload_luts;
1066 bool inherited; /* state inherited from BIOS? */
1067
1068 /* Ask the hardware to actually async flip? */
1069 bool do_async_flip;
1070
1071 /* Pipe source size (ie. panel fitter input size)
1072 * All planes will be positioned inside this space,
1073 * and get clipped at the edges. */
1074 struct drm_rect pipe_src;
1075
1076 /*
1077 * Pipe pixel rate, adjusted for
1078 * panel fitter/pipe scaler downscaling.
1079 */
1080 unsigned int pixel_rate;
1081
1082 /* Whether to set up the PCH/FDI. Note that we never allow sharing
1083 * between pch encoders and cpu encoders. */
1084 bool has_pch_encoder;
1085
1086 /* Are we sending infoframes on the attached port */
1087 bool has_infoframe;
1088
1089 /* CPU Transcoder for the pipe. Currently this can only differ from the
1090 * pipe on Haswell and later (where we have a special eDP transcoder)
1091 * and Broxton (where we have special DSI transcoders). */
1092 enum transcoder cpu_transcoder;
1093
1094 /*
1095 * Use reduced/limited/broadcast rbg range, compressing from the full
1096 * range fed into the crtcs.
1097 */
1098 bool limited_color_range;
1099
1100 /* Bitmask of encoder types (enum intel_output_type)
1101 * driven by the pipe.
1102 */
1103 unsigned int output_types;
1104
1105 /* Whether we should send NULL infoframes. Required for audio. */
1106 bool has_hdmi_sink;
1107
1108 /* Audio enabled on this pipe. Only valid if either has_hdmi_sink or
1109 * has_dp_encoder is set. */
1110 bool has_audio;
1111
1112 /*
1113 * Enable dithering, used when the selected pipe bpp doesn't match the
1114 * plane bpp.
1115 */
1116 bool dither;
1117
1118 /*
1119 * Dither gets enabled for 18bpp which causes CRC mismatch errors for
1120 * compliance video pattern tests.
1121 * Disable dither only if it is a compliance test request for
1122 * 18bpp.
1123 */
1124 bool dither_force_disable;
1125
1126 /* Controls for the clock computation, to override various stages. */
1127 bool clock_set;
1128
1129 /* SDVO TV has a bunch of special case. To make multifunction encoders
1130 * work correctly, we need to track this at runtime.*/
1131 bool sdvo_tv_clock;
1132
1133 /*
1134 * crtc bandwidth limit, don't increase pipe bpp or clock if not really
1135 * required. This is set in the 2nd loop of calling encoder's
1136 * ->compute_config if the first pick doesn't work out.
1137 */
1138 bool bw_constrained;
1139
1140 /* Settings for the intel dpll used on pretty much everything but
1141 * haswell. */
1142 struct dpll dpll;
1143
1144 /* Selected dpll or NULL. */
1145 struct intel_dpll *intel_dpll;
1146
1147 /* Actual register state of the dpll, for shared dpll cross-checking. */
1148 struct intel_dpll_hw_state dpll_hw_state;
1149
1150 /*
1151 * ICL reserved DPLLs for the CRTC/port. The active PLL is selected by
1152 * setting shared_dpll and dpll_hw_state to one of these reserved ones.
1153 */
1154 struct icl_port_dpll {
1155 struct intel_dpll *pll;
1156 struct intel_dpll_hw_state hw_state;
1157 } icl_port_dplls[ICL_PORT_DPLL_COUNT];
1158
1159 /* DSI PLL registers */
1160 struct {
1161 u32 ctrl, div;
1162 } dsi_pll;
1163
1164 int max_link_bpp_x16; /* in 1/16 bpp units */
1165 int max_pipe_bpp; /* in 1 bpp units */
1166 int pipe_bpp; /* in 1 bpp units */
1167 int min_hblank;
1168 struct intel_link_m_n dp_m_n;
1169
1170 /* m2_n2 for eDP downclock */
1171 struct intel_link_m_n dp_m2_n2;
1172 bool has_drrs;
1173
1174 /* PSR is supported but might not be enabled due the lack of enabled planes */
1175 bool has_psr;
1176 bool has_sel_update;
1177 bool enable_psr2_sel_fetch;
1178 bool enable_psr2_su_region_et;
1179 bool req_psr2_sdp_prior_scanline;
1180 bool has_panel_replay;
1181 bool link_off_after_as_sdp_when_pr_active;
1182 bool disable_as_sdp_when_pr_active;
1183 bool wm_level_disabled;
1184 bool pkg_c_latency_used;
1185 /* Only used for state verification. */
1186 enum intel_panel_replay_dsc_support panel_replay_dsc_support;
1187 u32 dc3co_exitline;
1188 u16 su_y_granularity;
1189 u8 active_non_psr_pipes;
1190 u8 entry_setup_frames;
1191 const char *no_psr_reason;
1192
1193 /*
1194 * Frequency the dpll for the port should run at. Differs from the
1195 * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also
1196 * already multiplied by pixel_multiplier.
1197 */
1198 int port_clock;
1199
1200 /* Used by SDVO (and if we ever fix it, HDMI). */
1201 unsigned pixel_multiplier;
1202
1203 /* I915_MODE_FLAG_* */
1204 u8 mode_flags;
1205
1206 u8 lane_count;
1207
1208 /*
1209 * Used by platforms having DP/HDMI PHY with programmable lane
1210 * latency optimization.
1211 */
1212 u8 lane_lat_optim_mask;
1213
1214 /* minimum acceptable voltage level */
1215 u8 min_voltage_level;
1216
1217 /* Panel fitter controls for gen2-gen4 + VLV */
1218 struct {
1219 u32 control;
1220 u32 pgm_ratios;
1221 u32 lvds_border_bits;
1222 } gmch_pfit;
1223
1224 /* Panel fitter placement and size for Ironlake+ */
1225 struct {
1226 struct drm_rect dst;
1227 bool enabled;
1228 bool force_thru;
1229 } pch_pfit;
1230
1231 /* FDI configuration, only valid if has_pch_encoder is set. */
1232 int fdi_lanes;
1233 struct intel_link_m_n fdi_m_n;
1234
1235 bool ips_enabled;
1236
1237 bool crc_enabled;
1238
1239 bool double_wide;
1240
1241 struct intel_crtc_scaler_state scaler_state;
1242
1243 /* w/a for waiting 2 vblanks during crtc enable */
1244 enum pipe hsw_workaround_pipe;
1245
1246 struct intel_crtc_wm_state wm;
1247
1248 int min_cdclk;
1249
1250 int plane_min_cdclk[I915_MAX_PLANES];
1251
1252 /* for packed/planar CbCr */
1253 u32 data_rate[I915_MAX_PLANES];
1254 /* for planar Y */
1255 u32 data_rate_y[I915_MAX_PLANES];
1256
1257 /* FIXME unify with data_rate[]? */
1258 u64 rel_data_rate[I915_MAX_PLANES];
1259 u64 rel_data_rate_y[I915_MAX_PLANES];
1260
1261 /* Gamma mode programmed on the pipe */
1262 u32 gamma_mode;
1263
1264 union {
1265 /* CSC mode programmed on the pipe */
1266 u32 csc_mode;
1267
1268 /* CHV CGM mode */
1269 u32 cgm_mode;
1270 };
1271
1272 /* bitmask of logically enabled planes (enum plane_id) */
1273 u8 enabled_planes;
1274
1275 /* bitmask of actually visible planes (enum plane_id) */
1276 u8 active_planes;
1277 u8 scaled_planes;
1278 u8 nv12_planes;
1279 u8 c8_planes;
1280
1281 /* bitmask of planes that will be updated during the commit */
1282 u8 update_planes;
1283
1284 /* bitmask of planes with async flip active */
1285 u8 async_flip_planes;
1286
1287 u8 framestart_delay; /* 1-4 */
1288 u8 msa_timing_delay; /* 0-3 */
1289
1290 struct {
1291 u32 enable;
1292 u32 gcp;
1293 union hdmi_infoframe avi;
1294 union hdmi_infoframe spd;
1295 union hdmi_infoframe hdmi;
1296 union hdmi_infoframe drm;
1297 struct drm_dp_vsc_sdp vsc;
1298 struct drm_dp_as_sdp as_sdp;
1299 } infoframes;
1300
1301 u8 eld[MAX_ELD_BYTES];
1302
1303 /* HDMI scrambling status */
1304 bool hdmi_scrambling;
1305
1306 /* HDMI High TMDS char rate ratio */
1307 bool hdmi_high_tmds_clock_ratio;
1308
1309 /*
1310 * Output format RGB/YCBCR etc., that is coming out
1311 * at the end of the pipe.
1312 */
1313 enum intel_output_format output_format;
1314
1315 /*
1316 * Sink output format RGB/YCBCR etc., that is going
1317 * into the sink.
1318 */
1319 enum intel_output_format sink_format;
1320
1321 /* enable pipe gamma? */
1322 bool gamma_enable;
1323
1324 /* enable pipe csc? */
1325 bool csc_enable;
1326
1327 /* enable vlv/chv wgc csc? */
1328 bool wgc_enable;
1329
1330 /* joiner pipe bitmask */
1331 u8 joiner_pipes;
1332
1333 /* Display Stream compression state */
1334 struct {
1335 /* Only used for state computation, not read out from the HW. */
1336 bool compression_enabled_on_link;
1337 bool compression_enable;
1338 struct intel_dsc_slice_config {
1339 int pipes_per_line;
1340 int streams_per_pipe;
1341 int slices_per_stream;
1342 } slice_config;
1343 /* Compressed Bpp in U6.4 format (first 4 bits for fractional part) */
1344 u16 compressed_bpp_x16;
1345 struct drm_dsc_config config;
1346 } dsc;
1347
1348 /* DP tunnel used for BW allocation. */
1349 struct drm_dp_tunnel_ref dp_tunnel_ref;
1350
1351 /* HSW+ linetime watermarks */
1352 u16 linetime;
1353 u16 ips_linetime;
1354
1355 bool enhanced_framing;
1356
1357 /*
1358 * Forward Error Correction.
1359 *
1360 * Note: This will be false for 128b/132b, which will always have FEC
1361 * enabled automatically.
1362 */
1363 bool fec_enable;
1364
1365 bool sdp_split_enable;
1366
1367 /* Pointer to master transcoder in case of tiled displays */
1368 enum transcoder master_transcoder;
1369
1370 /* Bitmask to indicate slaves attached */
1371 u8 sync_mode_slaves_mask;
1372
1373 /* Only valid on TGL+ */
1374 enum transcoder mst_master_transcoder;
1375
1376 /* For DSB based pipe updates */
1377 struct intel_dsb *dsb_color, *dsb_commit;
1378 bool use_dsb;
1379 bool use_flipq;
1380
1381 u32 psr2_man_track_ctl;
1382
1383 u32 pipe_srcsz_early_tpt;
1384
1385 struct drm_rect psr2_su_area;
1386
1387 /* Variable Refresh Rate state */
1388 struct {
1389 bool enable, in_range;
1390 u8 pipeline_full;
1391 u16 flipline, vmin, vmax, guardband;
1392 u32 vsync_end, vsync_start;
1393 struct {
1394 bool enable;
1395 u16 vmin, vmax;
1396 u16 guardband, slope;
1397 u16 max_increase, max_decrease;
1398 u16 vblank_target;
1399 } dc_balance;
1400 } vrr;
1401
1402 /* Content Match Refresh Rate state */
1403 struct {
1404 bool enable;
1405 u64 cmrr_n, cmrr_m;
1406 } cmrr;
1407
1408 /* Stream Splitter for eDP MSO */
1409 struct {
1410 bool enable;
1411 u8 link_count;
1412 u8 pixel_overlap;
1413 } splitter;
1414
1415 /* for loading single buffered registers during vblank */
1416 struct drm_vblank_work vblank_work;
1417
1418 /* LOBF flag */
1419 bool has_lobf;
1420
1421 /* W2 window or 'set context latency' lines */
1422 u16 set_context_latency;
1423
1424 struct {
1425 u8 io_wake_lines;
1426 u8 fast_wake_lines;
1427
1428 /* LNL and beyond */
1429 u8 check_entry_lines;
1430 u8 aux_less_wake_lines;
1431 u8 silence_period_sym_clocks;
1432 u8 lfps_half_cycle_num_of_syms;
1433 } alpm_state;
1434
1435 /* to track changes in plane color blocks */
1436 bool plane_color_changed;
1437 };
1438
1439 enum intel_pipe_crc_source {
1440 INTEL_PIPE_CRC_SOURCE_NONE,
1441 INTEL_PIPE_CRC_SOURCE_PLANE1,
1442 INTEL_PIPE_CRC_SOURCE_PLANE2,
1443 INTEL_PIPE_CRC_SOURCE_PLANE3,
1444 INTEL_PIPE_CRC_SOURCE_PLANE4,
1445 INTEL_PIPE_CRC_SOURCE_PLANE5,
1446 INTEL_PIPE_CRC_SOURCE_PLANE6,
1447 INTEL_PIPE_CRC_SOURCE_PLANE7,
1448 INTEL_PIPE_CRC_SOURCE_PIPE,
1449 /* TV/DP on pre-gen5/vlv can't use the pipe source. */
1450 INTEL_PIPE_CRC_SOURCE_TV,
1451 INTEL_PIPE_CRC_SOURCE_DP_B,
1452 INTEL_PIPE_CRC_SOURCE_DP_C,
1453 INTEL_PIPE_CRC_SOURCE_DP_D,
1454 INTEL_PIPE_CRC_SOURCE_AUTO,
1455 INTEL_PIPE_CRC_SOURCE_MAX,
1456 };
1457
1458 enum drrs_refresh_rate {
1459 DRRS_REFRESH_RATE_HIGH,
1460 DRRS_REFRESH_RATE_LOW,
1461 };
1462
1463 #define INTEL_PIPE_CRC_ENTRIES_NR 128
1464 struct intel_pipe_crc {
1465 spinlock_t lock;
1466 int skipped;
1467 enum intel_pipe_crc_source source;
1468 };
1469
1470 enum intel_flipq_id {
1471 INTEL_FLIPQ_PLANE_1,
1472 INTEL_FLIPQ_PLANE_2,
1473 INTEL_FLIPQ_PLANE_3,
1474 INTEL_FLIPQ_GENERAL,
1475 INTEL_FLIPQ_FAST,
1476 MAX_INTEL_FLIPQ,
1477 };
1478
1479 struct intel_flipq {
1480 u32 start_mmioaddr;
1481 enum intel_flipq_id flipq_id;
1482 u8 tail;
1483 };
1484
1485 struct intel_crtc {
1486 struct drm_crtc base;
1487 struct list_head pipe_head;
1488 enum pipe pipe;
1489 /*
1490 * Whether the crtc and the connected output pipeline is active. Implies
1491 * that crtc->enabled is set, i.e. the current mode configuration has
1492 * some outputs connected to this crtc.
1493 */
1494 bool active;
1495 u8 plane_ids_mask;
1496
1497 /* I915_MODE_FLAG_* */
1498 u8 mode_flags;
1499
1500 u16 vmax_vblank_start;
1501
1502 struct intel_display_power_domain_set enabled_power_domains;
1503 struct intel_display_power_domain_set hw_readout_power_domains;
1504 struct intel_overlay *overlay;
1505
1506 struct intel_crtc_state *config;
1507
1508 /* armed event for async flip */
1509 struct drm_pending_vblank_event *flip_done_event;
1510 /* armed event for DSB based updates */
1511 struct drm_pending_vblank_event *dsb_event;
1512 /* armed event for flip queue based updates */
1513 struct drm_pending_vblank_event *flipq_event;
1514
1515 /* Access to these should be protected by display->irq.lock. */
1516 bool cpu_fifo_underrun_disabled;
1517 bool pch_fifo_underrun_disabled;
1518
1519 struct intel_flipq flipq[MAX_INTEL_FLIPQ];
1520
1521 /* per-pipe watermark state */
1522 struct {
1523 /* watermarks currently being used */
1524 union {
1525 struct intel_pipe_wm ilk;
1526 struct vlv_wm_state vlv;
1527 struct g4x_wm_state g4x;
1528 } active;
1529 } wm;
1530
1531 struct {
1532 struct mutex mutex;
1533 struct delayed_work work;
1534 enum drrs_refresh_rate refresh_rate;
1535 unsigned int frontbuffer_bits;
1536 unsigned int busy_frontbuffer_bits;
1537 enum transcoder cpu_transcoder;
1538 struct intel_link_m_n m_n, m2_n2;
1539 } drrs;
1540
1541 struct {
1542 u64 flip_count;
1543 } dc_balance;
1544
1545 int scanline_offset;
1546
1547 struct {
1548 unsigned start_vbl_count;
1549 ktime_t start_vbl_time;
1550 int min_vbl, max_vbl;
1551 int scanline_start;
1552 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
1553 struct {
1554 u64 min;
1555 u64 max;
1556 u64 sum;
1557 unsigned int over;
1558 unsigned int times[17]; /* [1us, 16ms] */
1559 } vbl;
1560 #endif
1561 } debug;
1562
1563 /* scalers available on this crtc */
1564 int num_scalers;
1565
1566 /* for loading single buffered registers during vblank */
1567 struct pm_qos_request vblank_pm_qos;
1568
1569 #ifdef CONFIG_DEBUG_FS
1570 struct intel_pipe_crc pipe_crc;
1571 #endif
1572
1573 bool vblank_psr_notify;
1574 };
1575
1576 struct intel_plane_error {
1577 u32 ctl, surf, surflive;
1578 };
1579
1580 struct intel_plane {
1581 struct drm_plane base;
1582 enum i9xx_plane_id i9xx_plane;
1583 enum plane_id id;
1584 enum pipe pipe;
1585 bool need_async_flip_toggle_wa;
1586 u8 vtd_guard;
1587 u32 frontbuffer_bit;
1588
1589 struct {
1590 u32 base, cntl, size;
1591 } cursor;
1592
1593 struct intel_fbc *fbc;
1594
1595 /*
1596 * NOTE: Do not place new plane state fields here (e.g., when adding
1597 * new plane properties). New runtime state should now be placed in
1598 * the intel_plane_state structure and accessed via plane_state.
1599 */
1600
1601 int (*min_width)(const struct drm_framebuffer *fb,
1602 int color_plane,
1603 unsigned int rotation);
1604 int (*max_width)(const struct drm_framebuffer *fb,
1605 int color_plane,
1606 unsigned int rotation);
1607 int (*max_height)(const struct drm_framebuffer *fb,
1608 int color_plane,
1609 unsigned int rotation);
1610 unsigned int (*min_alignment)(struct intel_plane *plane,
1611 const struct drm_framebuffer *fb,
1612 int color_plane);
1613 unsigned int (*max_stride)(struct intel_plane *plane,
1614 const struct drm_format_info *info,
1615 u64 modifier, unsigned int rotation);
1616 bool (*can_async_flip)(u64 modifier);
1617 /* Write all non-self arming plane registers */
1618 void (*update_noarm)(struct intel_dsb *dsb,
1619 struct intel_plane *plane,
1620 const struct intel_crtc_state *crtc_state,
1621 const struct intel_plane_state *plane_state);
1622 /* Write all self-arming plane registers */
1623 void (*update_arm)(struct intel_dsb *dsb,
1624 struct intel_plane *plane,
1625 const struct intel_crtc_state *crtc_state,
1626 const struct intel_plane_state *plane_state);
1627 /* Disable the plane, must arm */
1628 void (*disable_arm)(struct intel_dsb *dsb,
1629 struct intel_plane *plane,
1630 const struct intel_crtc_state *crtc_state);
1631 void (*capture_error)(struct intel_crtc *crtc,
1632 struct intel_plane *plane,
1633 struct intel_plane_error *error);
1634 bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe);
1635 int (*check_plane)(struct intel_crtc_state *crtc_state,
1636 struct intel_plane_state *plane_state);
1637 u32 (*surf_offset)(const struct intel_plane_state *plane_state);
1638 int (*min_cdclk)(const struct intel_crtc_state *crtc_state,
1639 const struct intel_plane_state *plane_state);
1640 void (*async_flip)(struct intel_dsb *dsb,
1641 struct intel_plane *plane,
1642 const struct intel_crtc_state *crtc_state,
1643 const struct intel_plane_state *plane_state,
1644 bool async_flip);
1645 void (*enable_flip_done)(struct intel_plane *plane);
1646 void (*disable_flip_done)(struct intel_plane *plane);
1647 /* For drm_panic */
1648 void (*disable_tiling)(struct intel_plane *plane);
1649 };
1650
1651 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
1652 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
1653 #define to_intel_connector(x) container_of(x, struct intel_connector, base)
1654 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
1655 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
1656
1657 #define to_intel_crtc_state(crtc_state) \
1658 container_of_const((crtc_state), struct intel_crtc_state, uapi)
1659 #define to_intel_plane_state(plane_state) \
1660 container_of_const((plane_state), struct intel_plane_state, uapi)
1661 #define to_intel_framebuffer(fb) \
1662 container_of_const((fb), struct intel_framebuffer, base)
1663
1664 struct intel_hdmi {
1665 i915_reg_t hdmi_reg;
1666 struct {
1667 enum drm_dp_dual_mode_type type;
1668 int max_tmds_clock;
1669 } dp_dual_mode;
1670 struct intel_connector *attached_connector;
1671 struct cec_notifier *cec_notifier;
1672 };
1673
1674 struct intel_dp_mst_encoder;
1675
1676 struct intel_dp_compliance_data {
1677 unsigned long edid;
1678 u8 video_pattern;
1679 u16 hdisplay, vdisplay;
1680 u8 bpc;
1681 struct drm_dp_phy_test_params phytest;
1682 };
1683
1684 struct intel_dp_compliance {
1685 unsigned long test_type;
1686 struct intel_dp_compliance_data test_data;
1687 bool test_active;
1688 int test_link_rate;
1689 u8 test_lane_count;
1690 };
1691
1692 struct intel_dp_pcon_frl {
1693 bool is_trained;
1694 int trained_rate_gbps;
1695 };
1696
1697 struct intel_pps {
1698 int panel_power_up_delay;
1699 int panel_power_down_delay;
1700 int panel_power_cycle_delay;
1701 int backlight_on_delay;
1702 int backlight_off_delay;
1703 struct delayed_work panel_vdd_work;
1704 bool want_panel_vdd;
1705 bool initializing;
1706 unsigned long last_power_on;
1707 unsigned long last_backlight_off;
1708 ktime_t panel_power_off_time;
1709 struct ref_tracker *vdd_wakeref;
1710
1711 union {
1712 /*
1713 * Pipe whose power sequencer is currently locked into
1714 * this port. Only relevant on VLV/CHV.
1715 */
1716 enum pipe vlv_pps_pipe;
1717
1718 /*
1719 * Power sequencer index. Only relevant on BXT+.
1720 */
1721 int pps_idx;
1722 };
1723
1724 /*
1725 * Pipe currently driving the port. Used for preventing
1726 * the use of the PPS for any pipe currentrly driving
1727 * external DP as that will mess things up on VLV.
1728 */
1729 enum pipe vlv_active_pipe;
1730 /*
1731 * Set if the sequencer may be reset due to a power transition,
1732 * requiring a reinitialization. Only relevant on BXT+.
1733 */
1734 bool bxt_pps_reset;
1735 struct intel_pps_delays pps_delays;
1736 struct intel_pps_delays bios_pps_delays;
1737 };
1738
1739 struct intel_psr {
1740 /* Mutex for PSR state of the transcoder */
1741 struct mutex lock;
1742
1743 #define I915_PSR_DEBUG_MODE_MASK 0x0f
1744 #define I915_PSR_DEBUG_DEFAULT 0x00
1745 #define I915_PSR_DEBUG_DISABLE 0x01
1746 #define I915_PSR_DEBUG_ENABLE 0x02
1747 #define I915_PSR_DEBUG_FORCE_PSR1 0x03
1748 #define I915_PSR_DEBUG_ENABLE_SEL_FETCH 0x4
1749 #define I915_PSR_DEBUG_IRQ 0x10
1750 #define I915_PSR_DEBUG_SU_REGION_ET_DISABLE 0x20
1751 #define I915_PSR_DEBUG_PANEL_REPLAY_DISABLE 0x40
1752
1753 u32 debug;
1754 bool sink_support;
1755 bool source_support;
1756 bool enabled;
1757 int pause_counter;
1758 enum pipe pipe;
1759 enum transcoder transcoder;
1760 bool active;
1761 struct work_struct work;
1762 unsigned int busy_frontbuffer_bits;
1763 bool link_standby;
1764 bool sel_update_enabled;
1765 bool psr2_sel_fetch_enabled;
1766 bool psr2_sel_fetch_cff_enabled;
1767 bool su_region_et_enabled;
1768 bool req_psr2_sdp_prior_scanline;
1769 ktime_t last_entry_attempt;
1770 ktime_t last_exit;
1771 bool sink_not_reliable;
1772 bool irq_aux_error;
1773 u16 su_w_granularity;
1774 u16 su_y_granularity;
1775 bool source_panel_replay_support;
1776 bool sink_panel_replay_support;
1777 bool panel_replay_enabled;
1778 u32 dc3co_exitline;
1779 u32 dc3co_exit_delay;
1780 struct delayed_work dc3co_work;
1781 u8 entry_setup_frames;
1782
1783 u8 io_wake_lines;
1784 u8 fast_wake_lines;
1785
1786 bool link_ok;
1787 bool pkg_c_latency_used;
1788
1789 u8 active_non_psr_pipes;
1790
1791 const char *no_psr_reason;
1792 };
1793
1794 struct intel_dp {
1795 i915_reg_t output_reg;
1796 u32 DP;
1797 int link_rate;
1798 u8 lane_count;
1799 u8 sink_count;
1800 bool downstream_port_changed;
1801 bool needs_modeset_retry;
1802 bool use_max_params;
1803 u8 dpcd[DP_RECEIVER_CAP_SIZE];
1804
1805 u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
1806 u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
1807 u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE];
1808 u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT][DP_LTTPR_PHY_CAP_SIZE];
1809 u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE];
1810 /* source rates */
1811 int num_source_rates;
1812 const int *source_rates;
1813 /* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */
1814 int num_sink_rates;
1815 int sink_rates[DP_MAX_SUPPORTED_RATES];
1816 bool use_rate_select;
1817 /* Max sink lane count as reported by DP_MAX_LANE_COUNT */
1818 int max_sink_lane_count;
1819 /* intersection of source and sink rates */
1820 int num_common_rates;
1821 int common_rates[DP_MAX_SUPPORTED_RATES];
1822 struct {
1823 /* TODO: move the rest of link specific fields to here */
1824 bool active;
1825 /* common rate,lane_count configs in bw order */
1826 int num_configs;
1827 #define INTEL_DP_MAX_LANE_COUNT 4
1828 #define INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS (ilog2(INTEL_DP_MAX_LANE_COUNT) + 1)
1829 #define INTEL_DP_LANE_COUNT_EXP_BITS order_base_2(INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS)
1830 #define INTEL_DP_LINK_RATE_IDX_BITS (BITS_PER_TYPE(u8) - INTEL_DP_LANE_COUNT_EXP_BITS)
1831 #define INTEL_DP_MAX_LINK_CONFIGS (DP_MAX_SUPPORTED_RATES * \
1832 INTEL_DP_MAX_SUPPORTED_LANE_CONFIGS)
1833 struct intel_dp_link_config {
1834 u8 link_rate_idx:INTEL_DP_LINK_RATE_IDX_BITS;
1835 u8 lane_count_exp:INTEL_DP_LANE_COUNT_EXP_BITS;
1836 } configs[INTEL_DP_MAX_LINK_CONFIGS];
1837 /* Max lane count for the current link */
1838 int max_lane_count;
1839 /* Max rate for the current link */
1840 int max_rate;
1841 /*
1842 * Link parameters for which the MST topology was probed.
1843 * Tracking these ensures that the MST path resources are
1844 * re-enumerated whenever the link is retrained with new link
1845 * parameters, as required by the DP standard.
1846 */
1847 int mst_probed_lane_count;
1848 int mst_probed_rate;
1849 int force_lane_count;
1850 int force_rate;
1851 bool retrain_disabled;
1852 /* Sequential link training failures after a passing LT */
1853 int seq_train_failures;
1854 int force_train_failure;
1855 bool force_retrain;
1856 } link;
1857 bool reset_link_params;
1858 int mso_link_count;
1859 int mso_pixel_overlap;
1860 /* sink or branch descriptor */
1861 struct drm_dp_desc desc;
1862 struct drm_dp_aux aux;
1863 u32 aux_busy_last_status;
1864 u8 train_set[4];
1865
1866 struct intel_pps pps;
1867
1868 bool is_mst;
1869 enum drm_dp_mst_mode mst_detect;
1870
1871 /* connector directly attached - won't be use for modeset in mst world */
1872 struct intel_connector *attached_connector;
1873 bool as_sdp_supported;
1874
1875 struct drm_dp_tunnel *tunnel;
1876 bool tunnel_suspended:1;
1877
1878 struct {
1879 struct intel_dp_mst_encoder *stream_encoders[I915_MAX_PIPES];
1880 struct drm_dp_mst_topology_mgr mgr;
1881 int active_streams;
1882 } mst;
1883
1884 u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index);
1885 /*
1886 * This function returns the value we have to program the AUX_CTL
1887 * register with to kick off an AUX transaction.
1888 */
1889 u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes,
1890 u32 aux_clock_divider);
1891
1892 i915_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp);
1893 i915_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index);
1894
1895 /* This is called before a link training is starterd */
1896 void (*prepare_link_retrain)(struct intel_dp *intel_dp,
1897 const struct intel_crtc_state *crtc_state);
1898 void (*set_link_train)(struct intel_dp *intel_dp,
1899 const struct intel_crtc_state *crtc_state,
1900 u8 dp_train_pat);
1901 void (*set_idle_link_train)(struct intel_dp *intel_dp,
1902 const struct intel_crtc_state *crtc_state);
1903
1904 u8 (*preemph_max)(struct intel_dp *intel_dp);
1905 u8 (*voltage_max)(struct intel_dp *intel_dp,
1906 const struct intel_crtc_state *crtc_state);
1907
1908 /* Displayport compliance testing */
1909 struct intel_dp_compliance compliance;
1910
1911 /* Downstream facing port caps */
1912 struct {
1913 int min_tmds_clock, max_tmds_clock;
1914 int max_dotclock;
1915 int pcon_max_frl_bw;
1916 u8 max_bpc;
1917 bool ycbcr_444_to_420;
1918 bool ycbcr420_passthrough;
1919 bool rgb_to_ycbcr;
1920 } dfp;
1921
1922 /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
1923 struct pm_qos_request pm_qos;
1924
1925 /* Display stream compression testing */
1926 bool force_dsc_en;
1927 int force_dsc_output_format;
1928 bool force_dsc_fractional_bpp_en;
1929 int force_dsc_bpc;
1930
1931 bool hobl_failed;
1932 bool hobl_active;
1933
1934 struct intel_dp_pcon_frl frl;
1935
1936 struct intel_psr psr;
1937
1938 /* When we last wrote the OUI for eDP */
1939 unsigned long last_oui_write;
1940 bool oui_valid;
1941
1942 bool colorimetry_support;
1943
1944 struct {
1945 enum transcoder transcoder;
1946 struct mutex lock;
1947
1948 bool lobf_disable_debug;
1949 bool sink_alpm_error;
1950 } alpm;
1951
1952 u8 alpm_dpcd;
1953
1954 struct {
1955 unsigned long mask;
1956 } quirks;
1957 };
1958
1959 enum lspcon_vendor {
1960 LSPCON_VENDOR_MCA,
1961 LSPCON_VENDOR_PARADE
1962 };
1963
1964 struct intel_lspcon {
1965 bool active;
1966 bool hdr_supported;
1967 enum drm_lspcon_mode mode;
1968 enum lspcon_vendor vendor;
1969 };
1970
1971 struct intel_digital_port {
1972 struct intel_encoder base;
1973 struct intel_dp dp;
1974 struct intel_hdmi hdmi;
1975 struct intel_lspcon lspcon;
1976 enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool);
1977
1978 bool lane_reversal;
1979 bool ddi_a_4_lanes;
1980 bool release_cl2_override;
1981 bool dedicated_external;
1982 u8 max_lanes;
1983 /* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */
1984 enum aux_ch aux_ch;
1985 enum intel_display_power_domain ddi_io_power_domain;
1986 struct ref_tracker *ddi_io_wakeref;
1987 struct ref_tracker *aux_wakeref;
1988
1989 struct intel_tc_port *tc;
1990
1991 struct {
1992 /* protects num_streams reference count, port_data and auth_status */
1993 struct mutex mutex;
1994 /* the number of pipes using HDCP signalling out of this port */
1995 unsigned int num_streams;
1996 /* port HDCP auth status */
1997 bool auth_status;
1998 /* HDCP port data need to pass to security f/w */
1999 struct hdcp_port_data port_data;
2000 /* Whether the MST topology supports HDCP Type 1 Content */
2001 bool mst_type1_capable;
2002 } hdcp;
2003
2004 void (*write_infoframe)(struct intel_encoder *encoder,
2005 const struct intel_crtc_state *crtc_state,
2006 unsigned int type,
2007 const void *frame, ssize_t len);
2008 void (*read_infoframe)(struct intel_encoder *encoder,
2009 const struct intel_crtc_state *crtc_state,
2010 unsigned int type,
2011 void *frame, ssize_t len);
2012 void (*set_infoframes)(struct intel_encoder *encoder,
2013 bool enable,
2014 const struct intel_crtc_state *crtc_state,
2015 const struct drm_connector_state *conn_state);
2016 u32 (*infoframes_enabled)(struct intel_encoder *encoder,
2017 const struct intel_crtc_state *pipe_config);
2018 bool (*connected)(struct intel_encoder *encoder);
2019
2020 void (*lock)(struct intel_digital_port *dig_port);
2021 void (*unlock)(struct intel_digital_port *dig_port);
2022 };
2023
2024 struct intel_dp_mst_encoder {
2025 struct intel_encoder base;
2026 enum pipe pipe;
2027 struct intel_digital_port *primary;
2028 struct intel_connector *connector;
2029 };
2030
2031 struct intel_colorop {
2032 struct drm_colorop base;
2033 enum intel_color_block id;
2034 };
2035
2036 static inline struct intel_encoder *
intel_attached_encoder(struct intel_connector * connector)2037 intel_attached_encoder(struct intel_connector *connector)
2038 {
2039 return connector->encoder;
2040 }
2041
intel_encoder_is_dig_port(struct intel_encoder * encoder)2042 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder)
2043 {
2044 switch (encoder->type) {
2045 case INTEL_OUTPUT_DDI:
2046 case INTEL_OUTPUT_DP:
2047 case INTEL_OUTPUT_EDP:
2048 case INTEL_OUTPUT_HDMI:
2049 return true;
2050 default:
2051 return false;
2052 }
2053 }
2054
intel_encoder_is_mst(struct intel_encoder * encoder)2055 static inline bool intel_encoder_is_mst(struct intel_encoder *encoder)
2056 {
2057 return encoder->type == INTEL_OUTPUT_DP_MST;
2058 }
2059
2060 static inline struct intel_dp_mst_encoder *
enc_to_mst(struct intel_encoder * encoder)2061 enc_to_mst(struct intel_encoder *encoder)
2062 {
2063 return container_of(&encoder->base, struct intel_dp_mst_encoder,
2064 base.base);
2065 }
2066
2067 static inline struct intel_digital_port *
enc_to_dig_port(struct intel_encoder * encoder)2068 enc_to_dig_port(struct intel_encoder *encoder)
2069 {
2070 struct intel_encoder *intel_encoder = encoder;
2071
2072 if (intel_encoder_is_dig_port(intel_encoder))
2073 return container_of(&encoder->base, struct intel_digital_port,
2074 base.base);
2075 else if (intel_encoder_is_mst(intel_encoder))
2076 return enc_to_mst(encoder)->primary;
2077 else
2078 return NULL;
2079 }
2080
2081 static inline struct intel_digital_port *
intel_attached_dig_port(struct intel_connector * connector)2082 intel_attached_dig_port(struct intel_connector *connector)
2083 {
2084 return enc_to_dig_port(intel_attached_encoder(connector));
2085 }
2086
2087 static inline struct intel_hdmi *
enc_to_intel_hdmi(struct intel_encoder * encoder)2088 enc_to_intel_hdmi(struct intel_encoder *encoder)
2089 {
2090 return &enc_to_dig_port(encoder)->hdmi;
2091 }
2092
2093 static inline struct intel_hdmi *
intel_attached_hdmi(struct intel_connector * connector)2094 intel_attached_hdmi(struct intel_connector *connector)
2095 {
2096 return enc_to_intel_hdmi(intel_attached_encoder(connector));
2097 }
2098
enc_to_intel_dp(struct intel_encoder * encoder)2099 static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder)
2100 {
2101 return &enc_to_dig_port(encoder)->dp;
2102 }
2103
intel_attached_dp(struct intel_connector * connector)2104 static inline struct intel_dp *intel_attached_dp(struct intel_connector *connector)
2105 {
2106 if (connector->mst.dp)
2107 return connector->mst.dp;
2108 else
2109 return enc_to_intel_dp(intel_attached_encoder(connector));
2110 }
2111
intel_encoder_is_dp(struct intel_encoder * encoder)2112 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder)
2113 {
2114 switch (encoder->type) {
2115 case INTEL_OUTPUT_DP:
2116 case INTEL_OUTPUT_EDP:
2117 return true;
2118 case INTEL_OUTPUT_DDI:
2119 /* Skip pure HDMI/DVI DDI encoders */
2120 return i915_mmio_reg_valid(enc_to_intel_dp(encoder)->output_reg);
2121 default:
2122 return false;
2123 }
2124 }
2125
intel_encoder_is_hdmi(struct intel_encoder * encoder)2126 static inline bool intel_encoder_is_hdmi(struct intel_encoder *encoder)
2127 {
2128 switch (encoder->type) {
2129 case INTEL_OUTPUT_HDMI:
2130 return true;
2131 case INTEL_OUTPUT_DDI:
2132 /* See if the HDMI encoder is valid. */
2133 return i915_mmio_reg_valid(enc_to_intel_hdmi(encoder)->hdmi_reg);
2134 default:
2135 return false;
2136 }
2137 }
2138
2139 static inline struct intel_digital_port *
dp_to_dig_port(struct intel_dp * intel_dp)2140 dp_to_dig_port(struct intel_dp *intel_dp)
2141 {
2142 return container_of(intel_dp, struct intel_digital_port, dp);
2143 }
2144
2145 static inline struct intel_digital_port *
hdmi_to_dig_port(struct intel_hdmi * intel_hdmi)2146 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
2147 {
2148 return container_of(intel_hdmi, struct intel_digital_port, hdmi);
2149 }
2150
2151 static inline struct intel_plane_state *
intel_atomic_get_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2152 intel_atomic_get_plane_state(struct intel_atomic_state *state,
2153 struct intel_plane *plane)
2154 {
2155 struct drm_plane_state *ret =
2156 drm_atomic_get_plane_state(&state->base, &plane->base);
2157
2158 if (IS_ERR(ret))
2159 return ERR_CAST(ret);
2160
2161 return to_intel_plane_state(ret);
2162 }
2163
2164 static inline struct intel_plane_state *
intel_atomic_get_old_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2165 intel_atomic_get_old_plane_state(struct intel_atomic_state *state,
2166 struct intel_plane *plane)
2167 {
2168 return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base,
2169 &plane->base));
2170 }
2171
2172 static inline struct intel_plane_state *
intel_atomic_get_new_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2173 intel_atomic_get_new_plane_state(struct intel_atomic_state *state,
2174 struct intel_plane *plane)
2175 {
2176 return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base,
2177 &plane->base));
2178 }
2179
2180 static inline struct intel_crtc_state *
intel_atomic_get_old_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)2181 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state,
2182 struct intel_crtc *crtc)
2183 {
2184 return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base,
2185 &crtc->base));
2186 }
2187
2188 static inline struct intel_crtc_state *
intel_atomic_get_new_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)2189 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state,
2190 struct intel_crtc *crtc)
2191 {
2192 return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base,
2193 &crtc->base));
2194 }
2195
2196 static inline struct intel_digital_connector_state *
intel_atomic_get_new_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)2197 intel_atomic_get_new_connector_state(struct intel_atomic_state *state,
2198 struct intel_connector *connector)
2199 {
2200 return to_intel_digital_connector_state(
2201 drm_atomic_get_new_connector_state(&state->base,
2202 &connector->base));
2203 }
2204
2205 static inline struct intel_digital_connector_state *
intel_atomic_get_old_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)2206 intel_atomic_get_old_connector_state(struct intel_atomic_state *state,
2207 struct intel_connector *connector)
2208 {
2209 return to_intel_digital_connector_state(
2210 drm_atomic_get_old_connector_state(&state->base,
2211 &connector->base));
2212 }
2213
2214 /* intel_display.c */
2215 static inline bool
intel_crtc_has_type(const struct intel_crtc_state * crtc_state,enum intel_output_type type)2216 intel_crtc_has_type(const struct intel_crtc_state *crtc_state,
2217 enum intel_output_type type)
2218 {
2219 return crtc_state->output_types & BIT(type);
2220 }
2221
2222 static inline bool
intel_crtc_has_dp_encoder(const struct intel_crtc_state * crtc_state)2223 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state)
2224 {
2225 return crtc_state->output_types &
2226 (BIT(INTEL_OUTPUT_DP) |
2227 BIT(INTEL_OUTPUT_DP_MST) |
2228 BIT(INTEL_OUTPUT_EDP));
2229 }
2230
2231 static inline bool
intel_crtc_needs_modeset(const struct intel_crtc_state * crtc_state)2232 intel_crtc_needs_modeset(const struct intel_crtc_state *crtc_state)
2233 {
2234 return drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
2235 }
2236
2237 static inline bool
intel_crtc_needs_fastset(const struct intel_crtc_state * crtc_state)2238 intel_crtc_needs_fastset(const struct intel_crtc_state *crtc_state)
2239 {
2240 return crtc_state->update_pipe;
2241 }
2242
2243 static inline bool
intel_crtc_needs_color_update(const struct intel_crtc_state * crtc_state)2244 intel_crtc_needs_color_update(const struct intel_crtc_state *crtc_state)
2245 {
2246 return crtc_state->uapi.color_mgmt_changed ||
2247 intel_crtc_needs_fastset(crtc_state) ||
2248 intel_crtc_needs_modeset(crtc_state);
2249 }
2250
2251 static inline struct intel_frontbuffer *
to_intel_frontbuffer(struct drm_framebuffer * fb)2252 to_intel_frontbuffer(struct drm_framebuffer *fb)
2253 {
2254 return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
2255 }
2256
2257 /*
2258 * Conversion functions/macros from various pointer types to struct
2259 * intel_display pointer.
2260 */
2261 #define __drm_device_to_intel_display(p) \
2262 ((p) ? __drm_to_display(p) : NULL)
2263 #define __device_to_intel_display(p) \
2264 __drm_device_to_intel_display(dev_get_drvdata(p))
2265 #define __pci_dev_to_intel_display(p) \
2266 __drm_device_to_intel_display(pci_get_drvdata(p))
2267 #define __intel_atomic_state_to_intel_display(p) \
2268 __drm_device_to_intel_display((p)->base.dev)
2269 #define __intel_connector_to_intel_display(p) \
2270 __drm_device_to_intel_display((p)->base.dev)
2271 #define __intel_crtc_to_intel_display(p) \
2272 __drm_device_to_intel_display((p)->base.dev)
2273 #define __intel_crtc_state_to_intel_display(p) \
2274 __drm_device_to_intel_display((p)->uapi.crtc->dev)
2275 #define __intel_digital_port_to_intel_display(p) \
2276 __drm_device_to_intel_display((p)->base.base.dev)
2277 #define __intel_dp_to_intel_display(p) \
2278 __drm_device_to_intel_display(dp_to_dig_port(p)->base.base.dev)
2279 #define __intel_encoder_to_intel_display(p) \
2280 __drm_device_to_intel_display((p)->base.dev)
2281 #define __intel_hdmi_to_intel_display(p) \
2282 __drm_device_to_intel_display(hdmi_to_dig_port(p)->base.base.dev)
2283 #define __intel_plane_to_intel_display(p) \
2284 __drm_device_to_intel_display((p)->base.dev)
2285 #define __intel_plane_state_to_intel_display(p) \
2286 __drm_device_to_intel_display((p)->uapi.plane->dev)
2287
2288 /* Helper for generic association. Map types to conversion functions/macros. */
2289 #define __assoc(type, p) \
2290 struct type: __##type##_to_intel_display((struct type *)(p))
2291
2292 /* Convert various pointer types to struct intel_display pointer. */
2293 #define to_intel_display(p) \
2294 _Generic(*p, \
2295 __assoc(drm_device, p), \
2296 __assoc(device, p), \
2297 __assoc(pci_dev, p), \
2298 __assoc(intel_atomic_state, p), \
2299 __assoc(intel_connector, p), \
2300 __assoc(intel_crtc, p), \
2301 __assoc(intel_crtc_state, p), \
2302 __assoc(intel_digital_port, p), \
2303 __assoc(intel_dp, p), \
2304 __assoc(intel_encoder, p), \
2305 __assoc(intel_hdmi, p), \
2306 __assoc(intel_plane, p), \
2307 __assoc(intel_plane_state, p))
2308
2309 #endif /* __INTEL_DISPLAY_TYPES_H__ */
2310