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