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