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