xref: /linux/drivers/gpu/drm/i915/display/intel_display_types.h (revision 6812ce4e4379ffc99c52401ec28f0d7ffbc36206)
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 	/* Drop the stale selective fetch enable bits as selective fetch is turned off */
1191 	bool clear_psr2_sel_fetch;
1192 	bool req_psr2_sdp_prior_scanline;
1193 	bool has_panel_replay;
1194 	bool link_off_after_as_sdp_when_pr_active;
1195 	bool disable_as_sdp_when_pr_active;
1196 	bool wm_level_disabled;
1197 	bool pkg_c_latency_used;
1198 	/* Only used for state verification. */
1199 	enum intel_panel_replay_dsc_support panel_replay_dsc_support;
1200 	u16 su_y_granularity;
1201 	u8 active_non_psr_pipes;
1202 	u8 entry_setup_frames;
1203 	const char *no_psr_reason;
1204 
1205 	/*
1206 	 * Frequency the dpll for the port should run at. Differs from the
1207 	 * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also
1208 	 * already multiplied by pixel_multiplier.
1209 	 */
1210 	int port_clock;
1211 
1212 	/* Used by SDVO (and if we ever fix it, HDMI). */
1213 	unsigned pixel_multiplier;
1214 
1215 	/* I915_MODE_FLAG_* */
1216 	u8 mode_flags;
1217 
1218 	u8 lane_count;
1219 
1220 	/*
1221 	 * Used by platforms having DP/HDMI PHY with programmable lane
1222 	 * latency optimization.
1223 	 */
1224 	u8 lane_lat_optim_mask;
1225 
1226 	/* minimum acceptable voltage level */
1227 	u8 min_voltage_level;
1228 
1229 	/* Panel fitter controls for gen2-gen4 + VLV */
1230 	struct {
1231 		u32 control;
1232 		u32 pgm_ratios;
1233 		u32 lvds_border_bits;
1234 	} gmch_pfit;
1235 
1236 	/* Panel fitter placement and size for Ironlake+ */
1237 	struct {
1238 		struct intel_casf casf;
1239 		struct drm_rect dst;
1240 		bool enabled;
1241 		bool force_thru;
1242 	} pch_pfit;
1243 
1244 	/* FDI configuration, only valid if has_pch_encoder is set. */
1245 	int fdi_lanes;
1246 	struct intel_link_m_n fdi_m_n;
1247 
1248 	bool ips_enabled;
1249 
1250 	bool crc_enabled;
1251 
1252 	bool double_wide;
1253 
1254 	struct intel_crtc_scaler_state scaler_state;
1255 
1256 	/* w/a for waiting 2 vblanks during crtc enable */
1257 	enum pipe hsw_workaround_pipe;
1258 
1259 	struct intel_crtc_wm_state wm;
1260 
1261 	int min_cdclk;
1262 
1263 	int plane_min_cdclk[I915_MAX_PLANES];
1264 
1265 	/* for packed/planar CbCr */
1266 	u32 data_rate[I915_MAX_PLANES];
1267 	/* for planar Y */
1268 	u32 data_rate_y[I915_MAX_PLANES];
1269 
1270 	/* FIXME unify with data_rate[]? */
1271 	u64 rel_data_rate[I915_MAX_PLANES];
1272 	u64 rel_data_rate_y[I915_MAX_PLANES];
1273 
1274 	/* Gamma mode programmed on the pipe */
1275 	u32 gamma_mode;
1276 
1277 	union {
1278 		/* CSC mode programmed on the pipe */
1279 		u32 csc_mode;
1280 
1281 		/* CHV CGM mode */
1282 		u32 cgm_mode;
1283 	};
1284 
1285 	/* bitmask of logically enabled planes (enum plane_id) */
1286 	u8 enabled_planes;
1287 
1288 	/* bitmask of actually visible planes (enum plane_id) */
1289 	u8 active_planes;
1290 	u8 scaled_planes;
1291 	u8 nv12_planes;
1292 	u8 c8_planes;
1293 
1294 	/* bitmask of planes that will be updated during the commit */
1295 	u8 update_planes;
1296 
1297 	/* bitmask of planes with async flip active */
1298 	u8 async_flip_planes;
1299 
1300 	u8 framestart_delay; /* 1-4 */
1301 	u8 msa_timing_delay; /* 0-3 */
1302 
1303 	struct {
1304 		u32 enable;
1305 		u32 gcp;
1306 		union hdmi_infoframe avi;
1307 		union hdmi_infoframe spd;
1308 		union hdmi_infoframe hdmi;
1309 		union hdmi_infoframe drm;
1310 		struct drm_dp_vsc_sdp vsc;
1311 		struct drm_dp_as_sdp as_sdp;
1312 	} infoframes;
1313 
1314 	u8 eld[MAX_ELD_BYTES];
1315 
1316 	/* HDMI scrambling status */
1317 	bool hdmi_scrambling;
1318 
1319 	/* HDMI High TMDS char rate ratio */
1320 	bool hdmi_high_tmds_clock_ratio;
1321 
1322 	/*
1323 	 * Output format RGB/YCBCR etc., that is coming out
1324 	 * at the end of the pipe.
1325 	 */
1326 	enum intel_output_format output_format;
1327 
1328 	/*
1329 	 * Sink output format RGB/YCBCR etc., that is going
1330 	 * into the sink.
1331 	 */
1332 	enum intel_output_format sink_format;
1333 
1334 	/* enable pipe gamma? */
1335 	bool gamma_enable;
1336 
1337 	/* enable pipe csc? */
1338 	bool csc_enable;
1339 
1340 	/* enable vlv/chv wgc csc? */
1341 	bool wgc_enable;
1342 
1343 	/* joiner pipe bitmask */
1344 	u8 joiner_pipes;
1345 
1346 	/* Display Stream compression state */
1347 	struct {
1348 		/* Only used for state computation, not read out from the HW. */
1349 		bool compression_enabled_on_link;
1350 		bool compression_enable;
1351 		struct intel_dsc_slice_config {
1352 			int pipes_per_line;
1353 			int streams_per_pipe;
1354 			int slices_per_stream;
1355 		} slice_config;
1356 		/* Compressed Bpp in U6.4 format (first 4 bits for fractional part) */
1357 		u16 compressed_bpp_x16;
1358 		struct drm_dsc_config config;
1359 	} dsc;
1360 
1361 	/* DP tunnel used for BW allocation. */
1362 	struct drm_dp_tunnel_ref dp_tunnel_ref;
1363 
1364 	/* HSW+ linetime watermarks */
1365 	u16 linetime;
1366 	u16 ips_linetime;
1367 
1368 	bool enhanced_framing;
1369 
1370 	/*
1371 	 * Forward Error Correction.
1372 	 *
1373 	 * Note: This will be false for 128b/132b, which will always have FEC
1374 	 * enabled automatically.
1375 	 */
1376 	bool fec_enable;
1377 
1378 	bool sdp_split_enable;
1379 
1380 	/* Pointer to master transcoder in case of tiled displays */
1381 	enum transcoder master_transcoder;
1382 
1383 	/* Bitmask to indicate slaves attached */
1384 	u16 sync_mode_slaves_mask;
1385 
1386 	/* Only valid on TGL+ */
1387 	enum transcoder mst_master_transcoder;
1388 
1389 	/* For DSB based pipe updates */
1390 	struct intel_dsb *dsb_color, *dsb_commit;
1391 	bool use_dsb;
1392 	bool use_flipq;
1393 
1394 	u32 psr2_man_track_ctl;
1395 
1396 	u32 pipe_srcsz_early_tpt;
1397 
1398 	struct drm_rect psr2_su_area;
1399 
1400 	/* Variable Refresh Rate state */
1401 	struct {
1402 		bool enable, in_range;
1403 		u8 pipeline_full;
1404 		u16 flipline, vmin, vmax, guardband;
1405 		u32 vsync_end, vsync_start;
1406 		struct {
1407 			bool enable;
1408 			u16 vmin, vmax;
1409 			u16 guardband, slope;
1410 			u16 max_increase, max_decrease;
1411 			u16 vblank_target;
1412 		} dc_balance;
1413 	} vrr;
1414 
1415 	/* Content Match Refresh Rate state */
1416 	struct {
1417 		bool enable;
1418 		u64 cmrr_n, cmrr_m;
1419 	} cmrr;
1420 
1421 	/* Stream Splitter for eDP MSO */
1422 	struct {
1423 		bool enable;
1424 		u8 link_count;
1425 		u8 pixel_overlap;
1426 	} splitter;
1427 
1428 	/* for loading single buffered registers during vblank */
1429 	struct drm_vblank_work vblank_work;
1430 
1431 	/* LOBF flag */
1432 	bool has_lobf;
1433 
1434 	/* W2 window or 'set context latency' lines */
1435 	u16 set_context_latency;
1436 
1437 	struct {
1438 		u8 io_wake_lines;
1439 		u8 fast_wake_lines;
1440 
1441 		/* LNL and beyond */
1442 		u8 check_entry_lines;
1443 		u8 aux_less_wake_lines;
1444 		u8 silence_period_sym_clocks;
1445 		u8 lfps_half_cycle_num_of_syms;
1446 	} alpm_state;
1447 
1448 	/* to track changes in plane color blocks */
1449 	bool plane_color_changed;
1450 };
1451 
1452 enum intel_pipe_crc_source {
1453 	INTEL_PIPE_CRC_SOURCE_NONE,
1454 	INTEL_PIPE_CRC_SOURCE_PLANE1,
1455 	INTEL_PIPE_CRC_SOURCE_PLANE2,
1456 	INTEL_PIPE_CRC_SOURCE_PLANE3,
1457 	INTEL_PIPE_CRC_SOURCE_PLANE4,
1458 	INTEL_PIPE_CRC_SOURCE_PLANE5,
1459 	INTEL_PIPE_CRC_SOURCE_PLANE6,
1460 	INTEL_PIPE_CRC_SOURCE_PLANE7,
1461 	INTEL_PIPE_CRC_SOURCE_PIPE,
1462 	/* TV/DP on pre-gen5/vlv can't use the pipe source. */
1463 	INTEL_PIPE_CRC_SOURCE_TV,
1464 	INTEL_PIPE_CRC_SOURCE_DP_B,
1465 	INTEL_PIPE_CRC_SOURCE_DP_C,
1466 	INTEL_PIPE_CRC_SOURCE_DP_D,
1467 	INTEL_PIPE_CRC_SOURCE_AUTO,
1468 	INTEL_PIPE_CRC_SOURCE_MAX,
1469 };
1470 
1471 enum drrs_refresh_rate {
1472 	DRRS_REFRESH_RATE_HIGH,
1473 	DRRS_REFRESH_RATE_LOW,
1474 };
1475 
1476 #define INTEL_PIPE_CRC_ENTRIES_NR	128
1477 struct intel_pipe_crc {
1478 	spinlock_t lock;
1479 	int skipped;
1480 	enum intel_pipe_crc_source source;
1481 };
1482 
1483 enum intel_flipq_id {
1484 	INTEL_FLIPQ_PLANE_1,
1485 	INTEL_FLIPQ_PLANE_2,
1486 	INTEL_FLIPQ_PLANE_3,
1487 	INTEL_FLIPQ_GENERAL,
1488 	INTEL_FLIPQ_FAST,
1489 	MAX_INTEL_FLIPQ,
1490 };
1491 
1492 struct intel_flipq {
1493 	u32 start_mmioaddr;
1494 	enum intel_flipq_id flipq_id;
1495 	u8 tail;
1496 };
1497 
1498 struct intel_crtc {
1499 	struct drm_crtc base;
1500 	struct list_head pipe_head;
1501 	enum pipe pipe;
1502 	/*
1503 	 * Whether the crtc and the connected output pipeline is active. Implies
1504 	 * that crtc->enabled is set, i.e. the current mode configuration has
1505 	 * some outputs connected to this crtc.
1506 	 */
1507 	bool active;
1508 	u8 plane_ids_mask;
1509 
1510 	/* I915_MODE_FLAG_* */
1511 	u8 mode_flags;
1512 
1513 	u16 vmax_vblank_start;
1514 
1515 	struct intel_display_power_domain_set enabled_power_domains;
1516 	struct intel_display_power_domain_set hw_readout_power_domains;
1517 	struct intel_overlay *overlay;
1518 
1519 	struct intel_crtc_state *config;
1520 
1521 	/* armed event for async flip */
1522 	struct drm_pending_vblank_event *flip_done_event;
1523 	/* armed event for DSB based updates */
1524 	struct drm_pending_vblank_event *dsb_event;
1525 	/* armed event for flip queue based updates */
1526 	struct drm_pending_vblank_event *flipq_event;
1527 
1528 	/* Access to these should be protected by display->irq.lock. */
1529 	bool cpu_fifo_underrun_disabled;
1530 	bool pch_fifo_underrun_disabled;
1531 
1532 	struct intel_flipq flipq[MAX_INTEL_FLIPQ];
1533 
1534 	/* per-pipe watermark state */
1535 	struct {
1536 		/* watermarks currently being used  */
1537 		union {
1538 			struct intel_pipe_wm ilk;
1539 			struct vlv_wm_state vlv;
1540 			struct g4x_wm_state g4x;
1541 		} active;
1542 	} wm;
1543 
1544 	struct {
1545 		struct mutex mutex;
1546 		struct delayed_work work;
1547 		enum drrs_refresh_rate refresh_rate;
1548 		unsigned int frontbuffer_bits;
1549 		unsigned int busy_frontbuffer_bits;
1550 		enum transcoder cpu_transcoder;
1551 		struct intel_link_m_n m_n, m2_n2;
1552 	} drrs;
1553 
1554 	struct {
1555 		u64 flip_count;
1556 	} dc_balance;
1557 
1558 	int scanline_offset;
1559 
1560 	struct {
1561 		unsigned start_vbl_count;
1562 		ktime_t start_vbl_time;
1563 		int min_vbl, max_vbl;
1564 		int scanline_start;
1565 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
1566 		struct {
1567 			u64 min;
1568 			u64 max;
1569 			u64 sum;
1570 			unsigned int over;
1571 			unsigned int times[17]; /* [1us, 16ms] */
1572 		} vbl;
1573 #endif
1574 	} debug;
1575 
1576 	/* scalers available on this crtc */
1577 	int num_scalers;
1578 
1579 	/* for loading single buffered registers during vblank */
1580 	struct pm_qos_request vblank_pm_qos;
1581 
1582 #ifdef CONFIG_DEBUG_FS
1583 	struct intel_pipe_crc pipe_crc;
1584 #endif
1585 
1586 	bool vblank_psr_notify;
1587 
1588 	struct {
1589 		bool enabled;
1590 	} cmtg;
1591 };
1592 
1593 struct intel_plane_error {
1594 	u32 ctl, surf, surflive;
1595 };
1596 
1597 struct intel_plane {
1598 	struct drm_plane base;
1599 	enum i9xx_plane_id i9xx_plane;
1600 	enum plane_id id;
1601 	enum pipe pipe;
1602 	bool need_async_flip_toggle_wa;
1603 	u8 vtd_guard;
1604 	u32 frontbuffer_bit;
1605 
1606 	struct {
1607 		u32 base, cntl, size;
1608 	} cursor;
1609 
1610 	struct intel_fbc *fbc;
1611 
1612 	/*
1613 	 * NOTE: Do not place new plane state fields here (e.g., when adding
1614 	 * new plane properties).  New runtime state should now be placed in
1615 	 * the intel_plane_state structure and accessed via plane_state.
1616 	 */
1617 
1618 	int (*min_width)(const struct drm_framebuffer *fb,
1619 			 int color_plane,
1620 			 unsigned int rotation);
1621 	int (*max_width)(const struct drm_framebuffer *fb,
1622 			 int color_plane,
1623 			 unsigned int rotation);
1624 	int (*max_height)(const struct drm_framebuffer *fb,
1625 			  int color_plane,
1626 			  unsigned int rotation);
1627 	unsigned int (*min_alignment)(struct intel_plane *plane,
1628 				      const struct drm_framebuffer *fb,
1629 				      int color_plane);
1630 	unsigned int (*max_stride)(struct intel_plane *plane,
1631 				   const struct drm_format_info *info,
1632 				   u64 modifier, unsigned int rotation);
1633 	bool (*can_async_flip)(u64 modifier);
1634 	/* Write all non-self arming plane registers */
1635 	void (*update_noarm)(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 	/* Write all self-arming plane registers */
1640 	void (*update_arm)(struct intel_dsb *dsb,
1641 			   struct intel_plane *plane,
1642 			   const struct intel_crtc_state *crtc_state,
1643 			   const struct intel_plane_state *plane_state);
1644 	/* Disable the plane, must arm */
1645 	void (*disable_arm)(struct intel_dsb *dsb,
1646 			    struct intel_plane *plane,
1647 			    const struct intel_crtc_state *crtc_state);
1648 	void (*capture_error)(struct intel_crtc *crtc,
1649 			      struct intel_plane *plane,
1650 			      struct intel_plane_error *error);
1651 	bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe);
1652 	int (*check_plane)(struct intel_crtc_state *crtc_state,
1653 			   struct intel_plane_state *plane_state);
1654 	u32 (*surf_offset)(const struct intel_plane_state *plane_state);
1655 	int (*min_cdclk)(const struct intel_crtc_state *crtc_state,
1656 			 const struct intel_plane_state *plane_state);
1657 	void (*async_flip)(struct intel_dsb *dsb,
1658 			   struct intel_plane *plane,
1659 			   const struct intel_crtc_state *crtc_state,
1660 			   const struct intel_plane_state *plane_state,
1661 			   bool async_flip);
1662 	void (*enable_flip_done)(struct intel_plane *plane);
1663 	void (*disable_flip_done)(struct intel_plane *plane);
1664 	/* For drm_panic */
1665 	void (*disable_tiling)(struct intel_plane *plane);
1666 };
1667 
1668 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
1669 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
1670 #define to_intel_connector(x) container_of(x, struct intel_connector, base)
1671 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
1672 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
1673 
1674 #define to_intel_crtc_state(crtc_state) \
1675 	container_of_const((crtc_state), struct intel_crtc_state, uapi)
1676 #define to_intel_plane_state(plane_state) \
1677 	container_of_const((plane_state), struct intel_plane_state, uapi)
1678 #define to_intel_framebuffer(fb) \
1679 	container_of_const((fb), struct intel_framebuffer, base)
1680 
1681 struct intel_hdmi {
1682 	intel_reg_t hdmi_reg;
1683 	struct {
1684 		enum drm_dp_dual_mode_type type;
1685 		int max_tmds_clock;
1686 	} dp_dual_mode;
1687 	struct intel_connector *attached_connector;
1688 	struct cec_notifier *cec_notifier;
1689 };
1690 
1691 struct intel_dp_mst_encoder;
1692 
1693 struct intel_dp_compliance_data {
1694 	unsigned long edid;
1695 	u8 video_pattern;
1696 	u16 hdisplay, vdisplay;
1697 	u8 bpc;
1698 	struct drm_dp_phy_test_params phytest;
1699 };
1700 
1701 struct intel_dp_compliance {
1702 	unsigned long test_type;
1703 	struct intel_dp_compliance_data test_data;
1704 	bool test_active;
1705 	int test_link_rate;
1706 	u8 test_lane_count;
1707 };
1708 
1709 struct intel_dp_pcon_frl {
1710 	bool is_trained;
1711 	int trained_rate_gbps;
1712 };
1713 
1714 struct intel_pps {
1715 	int panel_power_up_delay;
1716 	int panel_power_down_delay;
1717 	int panel_power_cycle_delay;
1718 	int backlight_on_delay;
1719 	int backlight_off_delay;
1720 	struct delayed_work panel_vdd_work;
1721 	bool want_panel_vdd;
1722 	bool initializing;
1723 	unsigned long last_power_on;
1724 	unsigned long last_backlight_off;
1725 	ktime_t panel_power_off_time;
1726 	struct ref_tracker *vdd_wakeref;
1727 
1728 	union {
1729 		/*
1730 		 * Pipe whose power sequencer is currently locked into
1731 		 * this port. Only relevant on VLV/CHV.
1732 		 */
1733 		enum pipe vlv_pps_pipe;
1734 
1735 		/*
1736 		 * Power sequencer index. Only relevant on BXT+.
1737 		 */
1738 		int pps_idx;
1739 	};
1740 
1741 	/*
1742 	 * Pipe currently driving the port. Used for preventing
1743 	 * the use of the PPS for any pipe currentrly driving
1744 	 * external DP as that will mess things up on VLV.
1745 	 */
1746 	enum pipe vlv_active_pipe;
1747 	/*
1748 	 * Set if the sequencer may be reset due to a power transition,
1749 	 * requiring a reinitialization. Only relevant on BXT+.
1750 	 */
1751 	bool bxt_pps_reset;
1752 	struct intel_pps_delays pps_delays;
1753 	struct intel_pps_delays bios_pps_delays;
1754 };
1755 
1756 struct intel_psr {
1757 	/* Mutex for PSR state of the transcoder */
1758 	struct mutex lock;
1759 
1760 #define I915_PSR_DEBUG_MODE_MASK		0x0f
1761 #define I915_PSR_DEBUG_DEFAULT			0x00
1762 #define I915_PSR_DEBUG_DISABLE			0x01
1763 #define I915_PSR_DEBUG_ENABLE			0x02
1764 #define I915_PSR_DEBUG_FORCE_PSR1		0x03
1765 #define I915_PSR_DEBUG_ENABLE_SEL_FETCH		0x4
1766 #define I915_PSR_DEBUG_IRQ			0x10
1767 #define I915_PSR_DEBUG_SU_REGION_ET_DISABLE	0x20
1768 #define I915_PSR_DEBUG_PANEL_REPLAY_DISABLE	0x40
1769 
1770 	u32 debug;
1771 	bool sink_support;
1772 	bool source_support;
1773 	bool enabled;
1774 	int pause_counter;
1775 	enum pipe pipe;
1776 	enum transcoder transcoder;
1777 	bool active;
1778 	struct work_struct work;
1779 	unsigned int busy_frontbuffer_bits;
1780 	bool link_standby;
1781 	bool sel_update_enabled;
1782 	bool psr2_sel_fetch_enabled;
1783 	bool psr2_sel_fetch_cff_enabled;
1784 	bool su_region_et_enabled;
1785 	bool req_psr2_sdp_prior_scanline;
1786 	ktime_t last_entry_attempt;
1787 	ktime_t last_exit;
1788 	bool sink_not_reliable;
1789 	bool irq_aux_error;
1790 	/* DC3CO allowed used to control PSR configuration */
1791 	bool dc3co_allowed;
1792 	/* DC3CO disable work */
1793 	struct delayed_work dc3co_work;
1794 	u16 su_w_granularity;
1795 	u16 su_y_granularity;
1796 	bool source_panel_replay_support;
1797 	bool sink_panel_replay_support;
1798 	bool panel_replay_enabled;
1799 	u32 dc3co_exit_delay;
1800 	u8 entry_setup_frames;
1801 
1802 	u8 io_wake_lines;
1803 	u8 fast_wake_lines;
1804 
1805 	bool link_ok;
1806 	bool pkg_c_latency_used;
1807 
1808 	u8 active_non_psr_pipes;
1809 
1810 	const char *no_psr_reason;
1811 
1812 	struct ref_tracker *vblank_wakeref;
1813 };
1814 
1815 struct intel_dp_link_config {
1816 	int rate;
1817 	int lane_count;
1818 };
1819 
1820 #define INTEL_DP_LINK_CONFIG_NULL \
1821 	((struct intel_dp_link_config){})
1822 
1823 struct intel_dp {
1824 	intel_reg_t output_reg;
1825 	u32 DP;
1826 	int link_rate;
1827 	u8 lane_count;
1828 	u8 sink_count;
1829 	bool downstream_port_changed;
1830 	bool needs_modeset_retry;
1831 	bool use_max_params;
1832 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
1833 
1834 	u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
1835 	u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
1836 	u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE];
1837 	u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT][DP_LTTPR_PHY_CAP_SIZE];
1838 	u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE];
1839 	/* source rates */
1840 	int num_source_rates;
1841 	const int *source_rates;
1842 	/* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */
1843 	int num_sink_rates;
1844 	int sink_rates[DP_MAX_SUPPORTED_RATES];
1845 	bool use_rate_select;
1846 	/* Max sink lane count as reported by DP_MAX_LANE_COUNT */
1847 	int max_sink_lane_count;
1848 	struct {
1849 		/* TODO: move the rest of link specific fields to here */
1850 		bool active;
1851 		/*
1852 		 * Link parameters for which the MST topology was probed.
1853 		 * Tracking these ensures that the MST path resources are
1854 		 * re-enumerated whenever the link is retrained with new link
1855 		 * parameters, as required by the DP standard.
1856 		 */
1857 		int mst_probed_lane_count;
1858 		int mst_probed_rate;
1859 		struct intel_dp_link_training *training;
1860 		struct intel_dp_link_caps *caps;
1861 	} link;
1862 	bool reset_link_params;
1863 	int mso_link_count;
1864 	int mso_pixel_overlap;
1865 	/* sink or branch descriptor */
1866 	struct drm_dp_desc desc;
1867 	struct drm_dp_aux aux;
1868 	u32 aux_busy_last_status;
1869 	u8 train_set[4];
1870 
1871 	struct intel_pps pps;
1872 
1873 	bool is_mst;
1874 	enum drm_dp_mst_mode mst_detect;
1875 
1876 	/* connector directly attached - won't be use for modeset in mst world */
1877 	struct intel_connector *attached_connector;
1878 	bool as_sdp_supported;
1879 	bool as_sdp_v2_supported;
1880 
1881 	struct drm_dp_tunnel *tunnel;
1882 	bool tunnel_suspended:1;
1883 	u8 disabled_uhbr_lane_mask;
1884 
1885 	struct {
1886 		struct intel_dp_mst_encoder *stream_encoders[I915_MAX_PIPES];
1887 		struct drm_dp_mst_topology_mgr mgr;
1888 		int active_streams;
1889 	} mst;
1890 
1891 	u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index);
1892 	/*
1893 	 * This function returns the value we have to program the AUX_CTL
1894 	 * register with to kick off an AUX transaction.
1895 	 */
1896 	u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes,
1897 				u32 aux_clock_divider);
1898 
1899 	intel_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp);
1900 	intel_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index);
1901 
1902 	/* This is called before a link training is starterd */
1903 	void (*prepare_link_retrain)(struct intel_dp *intel_dp,
1904 				     const struct intel_crtc_state *crtc_state);
1905 	void (*set_link_train)(struct intel_dp *intel_dp,
1906 			       const struct intel_crtc_state *crtc_state,
1907 			       u8 dp_train_pat);
1908 	void (*set_idle_link_train)(struct intel_dp *intel_dp,
1909 				    const struct intel_crtc_state *crtc_state);
1910 
1911 	u8 (*preemph_max)(struct intel_dp *intel_dp);
1912 	u8 (*voltage_max)(struct intel_dp *intel_dp,
1913 			  const struct intel_crtc_state *crtc_state);
1914 
1915 	/* Displayport compliance testing */
1916 	struct intel_dp_compliance compliance;
1917 
1918 	/* Downstream facing port caps */
1919 	struct {
1920 		int min_tmds_clock, max_tmds_clock;
1921 		int max_dotclock;
1922 		int pcon_max_frl_bw;
1923 		u8 max_bpc;
1924 		bool ycbcr_444_to_420;
1925 		bool ycbcr420_passthrough;
1926 		bool rgb_to_ycbcr;
1927 	} dfp;
1928 
1929 	/* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
1930 	struct pm_qos_request pm_qos;
1931 
1932 	/* Display stream compression testing */
1933 	bool force_dsc_en;
1934 	int force_dsc_output_format;
1935 	bool force_dsc_fractional_bpp_en;
1936 	int force_dsc_bpc;
1937 
1938 	bool hobl_failed;
1939 	bool hobl_active;
1940 
1941 	struct intel_dp_pcon_frl frl;
1942 
1943 	struct intel_psr psr;
1944 
1945 	/* When we last wrote the OUI for eDP */
1946 	unsigned long last_oui_write;
1947 	bool oui_valid;
1948 
1949 	bool colorimetry_support;
1950 
1951 	bool sst_split_sdp_support;
1952 
1953 	struct {
1954 		enum transcoder transcoder;
1955 		struct mutex lock;
1956 
1957 		bool lobf_disable_debug;
1958 		bool sink_alpm_error;
1959 	} alpm;
1960 
1961 	u8 alpm_dpcd;
1962 
1963 	struct {
1964 		unsigned long mask;
1965 	} quirks;
1966 };
1967 
1968 enum lspcon_vendor {
1969 	LSPCON_VENDOR_MCA,
1970 	LSPCON_VENDOR_PARADE
1971 };
1972 
1973 struct intel_lspcon {
1974 	bool active;
1975 	bool hdr_supported;
1976 	enum drm_lspcon_mode mode;
1977 	enum lspcon_vendor vendor;
1978 };
1979 
1980 struct intel_digital_port {
1981 	struct intel_encoder base;
1982 	struct intel_dp dp;
1983 	struct intel_hdmi hdmi;
1984 	struct intel_lspcon lspcon;
1985 	enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool);
1986 
1987 	bool lane_reversal;
1988 	bool ddi_a_4_lanes;
1989 	bool release_cl2_override;
1990 	bool dedicated_external;
1991 	u8 max_lanes;
1992 	/* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */
1993 	enum aux_ch aux_ch;
1994 	enum intel_display_power_domain ddi_io_power_domain;
1995 	struct ref_tracker *ddi_io_wakeref;
1996 	struct ref_tracker *aux_wakeref;
1997 
1998 	struct intel_tc_port *tc;
1999 
2000 	struct {
2001 		/* protects num_streams reference count, port_data and auth_status */
2002 		struct mutex mutex;
2003 		/* the number of pipes using HDCP signalling out of this port */
2004 		unsigned int num_streams;
2005 		/* port HDCP auth status */
2006 		bool auth_status;
2007 		/* HDCP port data need to pass to security f/w */
2008 		struct hdcp_port_data port_data;
2009 		/* Whether the MST topology supports HDCP Type 1 Content */
2010 		bool mst_type1_capable;
2011 	} hdcp;
2012 
2013 	void (*write_infoframe)(struct intel_encoder *encoder,
2014 				const struct intel_crtc_state *crtc_state,
2015 				unsigned int type,
2016 				const void *frame, ssize_t len);
2017 	void (*read_infoframe)(struct intel_encoder *encoder,
2018 			       const struct intel_crtc_state *crtc_state,
2019 			       unsigned int type,
2020 			       void *frame, ssize_t len);
2021 	void (*set_infoframes)(struct intel_encoder *encoder,
2022 			       bool enable,
2023 			       const struct intel_crtc_state *crtc_state,
2024 			       const struct drm_connector_state *conn_state);
2025 	u32 (*infoframes_enabled)(struct intel_encoder *encoder,
2026 				  const struct intel_crtc_state *pipe_config);
2027 	bool (*connected)(struct intel_encoder *encoder);
2028 
2029 	void (*lock)(struct intel_digital_port *dig_port);
2030 	void (*unlock)(struct intel_digital_port *dig_port);
2031 };
2032 
2033 struct intel_dp_mst_encoder {
2034 	struct intel_encoder base;
2035 	enum pipe pipe;
2036 	struct intel_digital_port *primary;
2037 	struct intel_connector *connector;
2038 };
2039 
2040 struct intel_colorop {
2041 	struct drm_colorop base;
2042 	enum intel_color_block id;
2043 };
2044 
2045 static inline struct intel_encoder *
intel_attached_encoder(struct intel_connector * connector)2046 intel_attached_encoder(struct intel_connector *connector)
2047 {
2048 	return connector->encoder;
2049 }
2050 
intel_encoder_is_dig_port(struct intel_encoder * encoder)2051 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder)
2052 {
2053 	switch (encoder->type) {
2054 	case INTEL_OUTPUT_DDI:
2055 	case INTEL_OUTPUT_DP:
2056 	case INTEL_OUTPUT_EDP:
2057 	case INTEL_OUTPUT_HDMI:
2058 		return true;
2059 	default:
2060 		return false;
2061 	}
2062 }
2063 
intel_encoder_is_mst(struct intel_encoder * encoder)2064 static inline bool intel_encoder_is_mst(struct intel_encoder *encoder)
2065 {
2066 	return encoder->type == INTEL_OUTPUT_DP_MST;
2067 }
2068 
2069 static inline struct intel_dp_mst_encoder *
enc_to_mst(struct intel_encoder * encoder)2070 enc_to_mst(struct intel_encoder *encoder)
2071 {
2072 	return container_of(&encoder->base, struct intel_dp_mst_encoder,
2073 			    base.base);
2074 }
2075 
2076 static inline struct intel_digital_port *
enc_to_dig_port(struct intel_encoder * encoder)2077 enc_to_dig_port(struct intel_encoder *encoder)
2078 {
2079 	struct intel_encoder *intel_encoder = encoder;
2080 
2081 	if (intel_encoder_is_dig_port(intel_encoder))
2082 		return container_of(&encoder->base, struct intel_digital_port,
2083 				    base.base);
2084 	else if (intel_encoder_is_mst(intel_encoder))
2085 		return enc_to_mst(encoder)->primary;
2086 	else
2087 		return NULL;
2088 }
2089 
2090 static inline struct intel_digital_port *
intel_attached_dig_port(struct intel_connector * connector)2091 intel_attached_dig_port(struct intel_connector *connector)
2092 {
2093 	return enc_to_dig_port(intel_attached_encoder(connector));
2094 }
2095 
2096 static inline struct intel_hdmi *
enc_to_intel_hdmi(struct intel_encoder * encoder)2097 enc_to_intel_hdmi(struct intel_encoder *encoder)
2098 {
2099 	return &enc_to_dig_port(encoder)->hdmi;
2100 }
2101 
2102 static inline struct intel_hdmi *
intel_attached_hdmi(struct intel_connector * connector)2103 intel_attached_hdmi(struct intel_connector *connector)
2104 {
2105 	return enc_to_intel_hdmi(intel_attached_encoder(connector));
2106 }
2107 
enc_to_intel_dp(struct intel_encoder * encoder)2108 static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder)
2109 {
2110 	return &enc_to_dig_port(encoder)->dp;
2111 }
2112 
intel_attached_dp(struct intel_connector * connector)2113 static inline struct intel_dp *intel_attached_dp(struct intel_connector *connector)
2114 {
2115 	if (connector->mst.dp)
2116 		return connector->mst.dp;
2117 	else
2118 		return enc_to_intel_dp(intel_attached_encoder(connector));
2119 }
2120 
intel_encoder_is_dp(struct intel_encoder * encoder)2121 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder)
2122 {
2123 	switch (encoder->type) {
2124 	case INTEL_OUTPUT_DP:
2125 	case INTEL_OUTPUT_EDP:
2126 		return true;
2127 	case INTEL_OUTPUT_DDI:
2128 		/* Skip pure HDMI/DVI DDI encoders */
2129 		return intel_reg_valid(enc_to_intel_dp(encoder)->output_reg);
2130 	default:
2131 		return false;
2132 	}
2133 }
2134 
intel_encoder_is_hdmi(struct intel_encoder * encoder)2135 static inline bool intel_encoder_is_hdmi(struct intel_encoder *encoder)
2136 {
2137 	switch (encoder->type) {
2138 	case INTEL_OUTPUT_HDMI:
2139 		return true;
2140 	case INTEL_OUTPUT_DDI:
2141 		/* See if the HDMI encoder is valid. */
2142 		return intel_reg_valid(enc_to_intel_hdmi(encoder)->hdmi_reg);
2143 	default:
2144 		return false;
2145 	}
2146 }
2147 
2148 static inline struct intel_digital_port *
dp_to_dig_port(struct intel_dp * intel_dp)2149 dp_to_dig_port(struct intel_dp *intel_dp)
2150 {
2151 	return container_of(intel_dp, struct intel_digital_port, dp);
2152 }
2153 
2154 static inline struct intel_digital_port *
hdmi_to_dig_port(struct intel_hdmi * intel_hdmi)2155 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
2156 {
2157 	return container_of(intel_hdmi, struct intel_digital_port, hdmi);
2158 }
2159 
2160 static inline struct intel_plane_state *
intel_atomic_get_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2161 intel_atomic_get_plane_state(struct intel_atomic_state *state,
2162 				 struct intel_plane *plane)
2163 {
2164 	struct drm_plane_state *ret =
2165 		drm_atomic_get_plane_state(&state->base, &plane->base);
2166 
2167 	if (IS_ERR(ret))
2168 		return ERR_CAST(ret);
2169 
2170 	return to_intel_plane_state(ret);
2171 }
2172 
2173 static inline struct intel_plane_state *
intel_atomic_get_old_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2174 intel_atomic_get_old_plane_state(struct intel_atomic_state *state,
2175 				 struct intel_plane *plane)
2176 {
2177 	return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base,
2178 								   &plane->base));
2179 }
2180 
2181 static inline struct intel_plane_state *
intel_atomic_get_new_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)2182 intel_atomic_get_new_plane_state(struct intel_atomic_state *state,
2183 				 struct intel_plane *plane)
2184 {
2185 	return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base,
2186 								   &plane->base));
2187 }
2188 
2189 static inline struct intel_crtc_state *
intel_atomic_get_old_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)2190 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state,
2191 				struct intel_crtc *crtc)
2192 {
2193 	return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base,
2194 								 &crtc->base));
2195 }
2196 
2197 static inline struct intel_crtc_state *
intel_atomic_get_new_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)2198 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state,
2199 				struct intel_crtc *crtc)
2200 {
2201 	return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base,
2202 								 &crtc->base));
2203 }
2204 
2205 static inline struct intel_digital_connector_state *
intel_atomic_get_new_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)2206 intel_atomic_get_new_connector_state(struct intel_atomic_state *state,
2207 				     struct intel_connector *connector)
2208 {
2209 	return to_intel_digital_connector_state(
2210 			drm_atomic_get_new_connector_state(&state->base,
2211 			&connector->base));
2212 }
2213 
2214 static inline struct intel_digital_connector_state *
intel_atomic_get_old_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)2215 intel_atomic_get_old_connector_state(struct intel_atomic_state *state,
2216 				     struct intel_connector *connector)
2217 {
2218 	return to_intel_digital_connector_state(
2219 			drm_atomic_get_old_connector_state(&state->base,
2220 			&connector->base));
2221 }
2222 
2223 /* intel_display.c */
2224 static inline bool
intel_crtc_has_type(const struct intel_crtc_state * crtc_state,enum intel_output_type type)2225 intel_crtc_has_type(const struct intel_crtc_state *crtc_state,
2226 		    enum intel_output_type type)
2227 {
2228 	return crtc_state->output_types & BIT(type);
2229 }
2230 
2231 static inline bool
intel_crtc_has_dp_encoder(const struct intel_crtc_state * crtc_state)2232 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state)
2233 {
2234 	return crtc_state->output_types &
2235 		(BIT(INTEL_OUTPUT_DP) |
2236 		 BIT(INTEL_OUTPUT_DP_MST) |
2237 		 BIT(INTEL_OUTPUT_EDP));
2238 }
2239 
2240 static inline bool
intel_crtc_needs_modeset(const struct intel_crtc_state * crtc_state)2241 intel_crtc_needs_modeset(const struct intel_crtc_state *crtc_state)
2242 {
2243 	return drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
2244 }
2245 
2246 static inline bool
intel_crtc_needs_fastset(const struct intel_crtc_state * crtc_state)2247 intel_crtc_needs_fastset(const struct intel_crtc_state *crtc_state)
2248 {
2249 	return crtc_state->update_pipe;
2250 }
2251 
2252 static inline bool
intel_crtc_needs_color_update(const struct intel_crtc_state * crtc_state)2253 intel_crtc_needs_color_update(const struct intel_crtc_state *crtc_state)
2254 {
2255 	return crtc_state->uapi.color_mgmt_changed ||
2256 		intel_crtc_needs_fastset(crtc_state) ||
2257 		intel_crtc_needs_modeset(crtc_state);
2258 }
2259 
2260 static inline struct intel_frontbuffer *
to_intel_frontbuffer(struct drm_framebuffer * fb)2261 to_intel_frontbuffer(struct drm_framebuffer *fb)
2262 {
2263 	return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
2264 }
2265 
2266 /*
2267  * Conversion functions/macros from various pointer types to struct
2268  * intel_display pointer.
2269  */
2270 #define __drm_device_to_intel_display(p) \
2271 	((p) ? __drm_to_display(p) : NULL)
2272 #define __device_to_intel_display(p)				\
2273 	__drm_device_to_intel_display(dev_get_drvdata(p))
2274 #define __pci_dev_to_intel_display(p)				\
2275 	__drm_device_to_intel_display(pci_get_drvdata(p))
2276 #define __intel_atomic_state_to_intel_display(p)	\
2277 	__drm_device_to_intel_display((p)->base.dev)
2278 #define __intel_connector_to_intel_display(p)		\
2279 	__drm_device_to_intel_display((p)->base.dev)
2280 #define __intel_crtc_to_intel_display(p)		\
2281 	__drm_device_to_intel_display((p)->base.dev)
2282 #define __intel_crtc_state_to_intel_display(p)			\
2283 	__drm_device_to_intel_display((p)->uapi.crtc->dev)
2284 #define __intel_digital_port_to_intel_display(p)		\
2285 	__drm_device_to_intel_display((p)->base.base.dev)
2286 #define __intel_dp_to_intel_display(p)	\
2287 	__drm_device_to_intel_display(dp_to_dig_port(p)->base.base.dev)
2288 #define __intel_encoder_to_intel_display(p)		\
2289 	__drm_device_to_intel_display((p)->base.dev)
2290 #define __intel_hdmi_to_intel_display(p)	\
2291 	__drm_device_to_intel_display(hdmi_to_dig_port(p)->base.base.dev)
2292 #define __intel_plane_to_intel_display(p)		\
2293 	__drm_device_to_intel_display((p)->base.dev)
2294 #define __intel_plane_state_to_intel_display(p)			\
2295 	__drm_device_to_intel_display((p)->uapi.plane->dev)
2296 
2297 /* Helper for generic association. Map types to conversion functions/macros. */
2298 #define __assoc(type, p) \
2299 	struct type: __##type##_to_intel_display((struct type *)(p))
2300 
2301 /* Convert various pointer types to struct intel_display pointer. */
2302 #define to_intel_display(p)				\
2303 	_Generic(*p,					\
2304 		 __assoc(drm_device, p),		\
2305 		 __assoc(device, p),			\
2306 		 __assoc(pci_dev, p),			\
2307 		 __assoc(intel_atomic_state, p),	\
2308 		 __assoc(intel_connector, p),		\
2309 		 __assoc(intel_crtc, p),		\
2310 		 __assoc(intel_crtc_state, p),		\
2311 		 __assoc(intel_digital_port, p),	\
2312 		 __assoc(intel_dp, p),			\
2313 		 __assoc(intel_encoder, p),		\
2314 		 __assoc(intel_hdmi, p),		\
2315 		 __assoc(intel_plane, p),		\
2316 		 __assoc(intel_plane_state, p))
2317 
2318 #endif /*  __INTEL_DISPLAY_TYPES_H__ */
2319