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