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