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/i2c.h>
30 #include <linux/pm_qos.h>
31 #include <linux/pwm.h>
32 #include <linux/sched/clock.h>
33 
34 #include <drm/display/drm_dp_dual_mode_helper.h>
35 #include <drm/display/drm_dp_mst_helper.h>
36 #include <drm/display/drm_dsc.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_encoder.h>
40 #include <drm/drm_fourcc.h>
41 #include <drm/drm_probe_helper.h>
42 #include <drm/drm_rect.h>
43 #include <drm/drm_vblank.h>
44 #include <drm/drm_vblank_work.h>
45 #include <drm/i915_mei_hdcp_interface.h>
46 #include <media/cec-notifier.h>
47 
48 #include "i915_vma.h"
49 #include "i915_vma_types.h"
50 #include "intel_bios.h"
51 #include "intel_display.h"
52 #include "intel_display_power.h"
53 #include "intel_dpll_mgr.h"
54 #include "intel_pm_types.h"
55 
56 struct drm_printer;
57 struct __intel_global_objs_state;
58 struct intel_ddi_buf_trans;
59 struct intel_fbc;
60 struct intel_connector;
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_ggtt_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 
146 enum intel_hotplug_state {
147 	INTEL_HOTPLUG_UNCHANGED,
148 	INTEL_HOTPLUG_CHANGED,
149 	INTEL_HOTPLUG_RETRY,
150 };
151 
152 struct intel_encoder {
153 	struct drm_encoder base;
154 
155 	enum intel_output_type type;
156 	enum port port;
157 	u16 cloneable;
158 	u8 pipe_mask;
159 	enum intel_hotplug_state (*hotplug)(struct intel_encoder *encoder,
160 					    struct intel_connector *connector);
161 	enum intel_output_type (*compute_output_type)(struct intel_encoder *,
162 						      struct intel_crtc_state *,
163 						      struct drm_connector_state *);
164 	int (*compute_config)(struct intel_encoder *,
165 			      struct intel_crtc_state *,
166 			      struct drm_connector_state *);
167 	int (*compute_config_late)(struct intel_encoder *,
168 				   struct intel_crtc_state *,
169 				   struct drm_connector_state *);
170 	void (*update_prepare)(struct intel_atomic_state *,
171 			       struct intel_encoder *,
172 			       struct intel_crtc *);
173 	void (*pre_pll_enable)(struct intel_atomic_state *,
174 			       struct intel_encoder *,
175 			       const struct intel_crtc_state *,
176 			       const struct drm_connector_state *);
177 	void (*pre_enable)(struct intel_atomic_state *,
178 			   struct intel_encoder *,
179 			   const struct intel_crtc_state *,
180 			   const struct drm_connector_state *);
181 	void (*enable)(struct intel_atomic_state *,
182 		       struct intel_encoder *,
183 		       const struct intel_crtc_state *,
184 		       const struct drm_connector_state *);
185 	void (*update_complete)(struct intel_atomic_state *,
186 				struct intel_encoder *,
187 				struct intel_crtc *);
188 	void (*disable)(struct intel_atomic_state *,
189 			struct intel_encoder *,
190 			const struct intel_crtc_state *,
191 			const struct drm_connector_state *);
192 	void (*post_disable)(struct intel_atomic_state *,
193 			     struct intel_encoder *,
194 			     const struct intel_crtc_state *,
195 			     const struct drm_connector_state *);
196 	void (*post_pll_disable)(struct intel_atomic_state *,
197 				 struct intel_encoder *,
198 				 const struct intel_crtc_state *,
199 				 const struct drm_connector_state *);
200 	void (*update_pipe)(struct intel_atomic_state *,
201 			    struct intel_encoder *,
202 			    const struct intel_crtc_state *,
203 			    const struct drm_connector_state *);
204 	/* Read out the current hw state of this connector, returning true if
205 	 * the encoder is active. If the encoder is enabled it also set the pipe
206 	 * it is connected to in the pipe parameter. */
207 	bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
208 	/* Reconstructs the equivalent mode flags for the current hardware
209 	 * state. This must be called _after_ display->get_pipe_config has
210 	 * pre-filled the pipe config. Note that intel_encoder->base.crtc must
211 	 * be set correctly before calling this function. */
212 	void (*get_config)(struct intel_encoder *,
213 			   struct intel_crtc_state *pipe_config);
214 
215 	/*
216 	 * Optional hook called during init/resume to sync any state
217 	 * stored in the encoder (eg. DP link parameters) wrt. the HW state.
218 	 */
219 	void (*sync_state)(struct intel_encoder *encoder,
220 			   const struct intel_crtc_state *crtc_state);
221 
222 	/*
223 	 * Optional hook, returning true if this encoder allows a fastset
224 	 * during the initial commit, false otherwise.
225 	 */
226 	bool (*initial_fastset_check)(struct intel_encoder *encoder,
227 				      struct intel_crtc_state *crtc_state);
228 
229 	/*
230 	 * Acquires the power domains needed for an active encoder during
231 	 * hardware state readout.
232 	 */
233 	void (*get_power_domains)(struct intel_encoder *encoder,
234 				  struct intel_crtc_state *crtc_state);
235 	/*
236 	 * Called during system suspend after all pending requests for the
237 	 * encoder are flushed (for example for DP AUX transactions) and
238 	 * device interrupts are disabled.
239 	 */
240 	void (*suspend)(struct intel_encoder *);
241 	/*
242 	 * Called during system reboot/shutdown after all the
243 	 * encoders have been disabled and suspended.
244 	 */
245 	void (*shutdown)(struct intel_encoder *encoder);
246 	/*
247 	 * Enable/disable the clock to the port.
248 	 */
249 	void (*enable_clock)(struct intel_encoder *encoder,
250 			     const struct intel_crtc_state *crtc_state);
251 	void (*disable_clock)(struct intel_encoder *encoder);
252 	/*
253 	 * Returns whether the port clock is enabled or not.
254 	 */
255 	bool (*is_clock_enabled)(struct intel_encoder *encoder);
256 	const struct intel_ddi_buf_trans *(*get_buf_trans)(struct intel_encoder *encoder,
257 							   const struct intel_crtc_state *crtc_state,
258 							   int *n_entries);
259 	void (*set_signal_levels)(struct intel_encoder *encoder,
260 				  const struct intel_crtc_state *crtc_state);
261 
262 	enum hpd_pin hpd_pin;
263 	enum intel_display_power_domain power_domain;
264 	/* for communication with audio component; protected by av_mutex */
265 	const struct drm_connector *audio_connector;
266 
267 	/* VBT information for this encoder (may be NULL for older platforms) */
268 	const struct intel_bios_encoder_data *devdata;
269 };
270 
271 struct intel_panel_bl_funcs {
272 	/* Connector and platform specific backlight functions */
273 	int (*setup)(struct intel_connector *connector, enum pipe pipe);
274 	u32 (*get)(struct intel_connector *connector, enum pipe pipe);
275 	void (*set)(const struct drm_connector_state *conn_state, u32 level);
276 	void (*disable)(const struct drm_connector_state *conn_state, u32 level);
277 	void (*enable)(const struct intel_crtc_state *crtc_state,
278 		       const struct drm_connector_state *conn_state, u32 level);
279 	u32 (*hz_to_pwm)(struct intel_connector *connector, u32 hz);
280 };
281 
282 struct intel_panel {
283 	struct list_head fixed_modes;
284 
285 	/* backlight */
286 	struct {
287 		bool present;
288 		u32 level;
289 		u32 min;
290 		u32 max;
291 		bool enabled;
292 		bool combination_mode;	/* gen 2/4 only */
293 		bool active_low_pwm;
294 		bool alternate_pwm_increment;	/* lpt+ */
295 
296 		/* PWM chip */
297 		u32 pwm_level_min;
298 		u32 pwm_level_max;
299 		bool pwm_enabled;
300 		bool util_pin_active_low;	/* bxt+ */
301 		u8 controller;		/* bxt+ only */
302 		struct pwm_device *pwm;
303 		struct pwm_state pwm_state;
304 
305 		/* DPCD backlight */
306 		union {
307 			struct {
308 				struct drm_edp_backlight_info info;
309 			} vesa;
310 			struct {
311 				bool sdr_uses_aux;
312 			} intel;
313 		} edp;
314 
315 		struct backlight_device *device;
316 
317 		const struct intel_panel_bl_funcs *funcs;
318 		const struct intel_panel_bl_funcs *pwm_funcs;
319 		void (*power)(struct intel_connector *, bool enable);
320 	} backlight;
321 };
322 
323 struct intel_digital_port;
324 
325 enum check_link_response {
326 	HDCP_LINK_PROTECTED	= 0,
327 	HDCP_TOPOLOGY_CHANGE,
328 	HDCP_LINK_INTEGRITY_FAILURE,
329 	HDCP_REAUTH_REQUEST
330 };
331 
332 /*
333  * This structure serves as a translation layer between the generic HDCP code
334  * and the bus-specific code. What that means is that HDCP over HDMI differs
335  * from HDCP over DP, so to account for these differences, we need to
336  * communicate with the receiver through this shim.
337  *
338  * For completeness, the 2 buses differ in the following ways:
339  *	- DP AUX vs. DDC
340  *		HDCP registers on the receiver are set via DP AUX for DP, and
341  *		they are set via DDC for HDMI.
342  *	- Receiver register offsets
343  *		The offsets of the registers are different for DP vs. HDMI
344  *	- Receiver register masks/offsets
345  *		For instance, the ready bit for the KSV fifo is in a different
346  *		place on DP vs HDMI
347  *	- Receiver register names
348  *		Seriously. In the DP spec, the 16-bit register containing
349  *		downstream information is called BINFO, on HDMI it's called
350  *		BSTATUS. To confuse matters further, DP has a BSTATUS register
351  *		with a completely different definition.
352  *	- KSV FIFO
353  *		On HDMI, the ksv fifo is read all at once, whereas on DP it must
354  *		be read 3 keys at a time
355  *	- Aksv output
356  *		Since Aksv is hidden in hardware, there's different procedures
357  *		to send it over DP AUX vs DDC
358  */
359 struct intel_hdcp_shim {
360 	/* Outputs the transmitter's An and Aksv values to the receiver. */
361 	int (*write_an_aksv)(struct intel_digital_port *dig_port, u8 *an);
362 
363 	/* Reads the receiver's key selection vector */
364 	int (*read_bksv)(struct intel_digital_port *dig_port, u8 *bksv);
365 
366 	/*
367 	 * Reads BINFO from DP receivers and BSTATUS from HDMI receivers. The
368 	 * definitions are the same in the respective specs, but the names are
369 	 * different. Call it BSTATUS since that's the name the HDMI spec
370 	 * uses and it was there first.
371 	 */
372 	int (*read_bstatus)(struct intel_digital_port *dig_port,
373 			    u8 *bstatus);
374 
375 	/* Determines whether a repeater is present downstream */
376 	int (*repeater_present)(struct intel_digital_port *dig_port,
377 				bool *repeater_present);
378 
379 	/* Reads the receiver's Ri' value */
380 	int (*read_ri_prime)(struct intel_digital_port *dig_port, u8 *ri);
381 
382 	/* Determines if the receiver's KSV FIFO is ready for consumption */
383 	int (*read_ksv_ready)(struct intel_digital_port *dig_port,
384 			      bool *ksv_ready);
385 
386 	/* Reads the ksv fifo for num_downstream devices */
387 	int (*read_ksv_fifo)(struct intel_digital_port *dig_port,
388 			     int num_downstream, u8 *ksv_fifo);
389 
390 	/* Reads a 32-bit part of V' from the receiver */
391 	int (*read_v_prime_part)(struct intel_digital_port *dig_port,
392 				 int i, u32 *part);
393 
394 	/* Enables HDCP signalling on the port */
395 	int (*toggle_signalling)(struct intel_digital_port *dig_port,
396 				 enum transcoder cpu_transcoder,
397 				 bool enable);
398 
399 	/* Enable/Disable stream encryption on DP MST Transport Link */
400 	int (*stream_encryption)(struct intel_connector *connector,
401 				 bool enable);
402 
403 	/* Ensures the link is still protected */
404 	bool (*check_link)(struct intel_digital_port *dig_port,
405 			   struct intel_connector *connector);
406 
407 	/* Detects panel's hdcp capability. This is optional for HDMI. */
408 	int (*hdcp_capable)(struct intel_digital_port *dig_port,
409 			    bool *hdcp_capable);
410 
411 	/* HDCP adaptation(DP/HDMI) required on the port */
412 	enum hdcp_wired_protocol protocol;
413 
414 	/* Detects whether sink is HDCP2.2 capable */
415 	int (*hdcp_2_2_capable)(struct intel_digital_port *dig_port,
416 				bool *capable);
417 
418 	/* Write HDCP2.2 messages */
419 	int (*write_2_2_msg)(struct intel_digital_port *dig_port,
420 			     void *buf, size_t size);
421 
422 	/* Read HDCP2.2 messages */
423 	int (*read_2_2_msg)(struct intel_digital_port *dig_port,
424 			    u8 msg_id, void *buf, size_t size);
425 
426 	/*
427 	 * Implementation of DP HDCP2.2 Errata for the communication of stream
428 	 * type to Receivers. In DP HDCP2.2 Stream type is one of the input to
429 	 * the HDCP2.2 Cipher for En/De-Cryption. Not applicable for HDMI.
430 	 */
431 	int (*config_stream_type)(struct intel_digital_port *dig_port,
432 				  bool is_repeater, u8 type);
433 
434 	/* Enable/Disable HDCP 2.2 stream encryption on DP MST Transport Link */
435 	int (*stream_2_2_encryption)(struct intel_connector *connector,
436 				     bool enable);
437 
438 	/* HDCP2.2 Link Integrity Check */
439 	int (*check_2_2_link)(struct intel_digital_port *dig_port,
440 			      struct intel_connector *connector);
441 };
442 
443 struct intel_hdcp {
444 	const struct intel_hdcp_shim *shim;
445 	/* Mutex for hdcp state of the connector */
446 	struct mutex mutex;
447 	u64 value;
448 	struct delayed_work check_work;
449 	struct work_struct prop_work;
450 
451 	/* HDCP1.4 Encryption status */
452 	bool hdcp_encrypted;
453 
454 	/* HDCP2.2 related definitions */
455 	/* Flag indicates whether this connector supports HDCP2.2 or not. */
456 	bool hdcp2_supported;
457 
458 	/* HDCP2.2 Encryption status */
459 	bool hdcp2_encrypted;
460 
461 	/*
462 	 * Content Stream Type defined by content owner. TYPE0(0x0) content can
463 	 * flow in the link protected by HDCP2.2 or HDCP1.4, where as TYPE1(0x1)
464 	 * content can flow only through a link protected by HDCP2.2.
465 	 */
466 	u8 content_type;
467 
468 	bool is_paired;
469 	bool is_repeater;
470 
471 	/*
472 	 * Count of ReceiverID_List received. Initialized to 0 at AKE_INIT.
473 	 * Incremented after processing the RepeaterAuth_Send_ReceiverID_List.
474 	 * When it rolls over re-auth has to be triggered.
475 	 */
476 	u32 seq_num_v;
477 
478 	/*
479 	 * Count of RepeaterAuth_Stream_Manage msg propagated.
480 	 * Initialized to 0 on AKE_INIT. Incremented after every successful
481 	 * transmission of RepeaterAuth_Stream_Manage message. When it rolls
482 	 * over re-Auth has to be triggered.
483 	 */
484 	u32 seq_num_m;
485 
486 	/*
487 	 * Work queue to signal the CP_IRQ. Used for the waiters to read the
488 	 * available information from HDCP DP sink.
489 	 */
490 	wait_queue_head_t cp_irq_queue;
491 	atomic_t cp_irq_count;
492 	int cp_irq_count_cached;
493 
494 	/*
495 	 * HDCP register access for gen12+ need the transcoder associated.
496 	 * Transcoder attached to the connector could be changed at modeset.
497 	 * Hence caching the transcoder here.
498 	 */
499 	enum transcoder cpu_transcoder;
500 	/* Only used for DP MST stream encryption */
501 	enum transcoder stream_transcoder;
502 };
503 
504 struct intel_connector {
505 	struct drm_connector base;
506 	/*
507 	 * The fixed encoder this connector is connected to.
508 	 */
509 	struct intel_encoder *encoder;
510 
511 	/* ACPI device id for ACPI and driver cooperation */
512 	u32 acpi_device_id;
513 
514 	/* Reads out the current hw, returning true if the connector is enabled
515 	 * and active (i.e. dpms ON state). */
516 	bool (*get_hw_state)(struct intel_connector *);
517 
518 	/* Panel info for eDP and LVDS */
519 	struct intel_panel panel;
520 
521 	/* Cached EDID for eDP and LVDS. May hold ERR_PTR for invalid EDID. */
522 	struct edid *edid;
523 	struct edid *detect_edid;
524 
525 	/* Number of times hotplug detection was tried after an HPD interrupt */
526 	int hotplug_retries;
527 
528 	/* since POLL and HPD connectors may use the same HPD line keep the native
529 	   state of connector->polled in case hotplug storm detection changes it */
530 	u8 polled;
531 
532 	struct drm_dp_mst_port *port;
533 
534 	struct intel_dp *mst_port;
535 
536 	/* Work struct to schedule a uevent on link train failure */
537 	struct work_struct modeset_retry_work;
538 
539 	struct intel_hdcp hdcp;
540 };
541 
542 struct intel_digital_connector_state {
543 	struct drm_connector_state base;
544 
545 	enum hdmi_force_audio force_audio;
546 	int broadcast_rgb;
547 };
548 
549 #define to_intel_digital_connector_state(x) container_of(x, struct intel_digital_connector_state, base)
550 
551 struct dpll {
552 	/* given values */
553 	int n;
554 	int m1, m2;
555 	int p1, p2;
556 	/* derived values */
557 	int	dot;
558 	int	vco;
559 	int	m;
560 	int	p;
561 };
562 
563 struct intel_atomic_state {
564 	struct drm_atomic_state base;
565 
566 	intel_wakeref_t wakeref;
567 
568 	struct __intel_global_objs_state *global_objs;
569 	int num_global_objs;
570 
571 	bool dpll_set, modeset;
572 
573 	struct intel_shared_dpll_state shared_dpll[I915_NUM_PLLS];
574 
575 	/*
576 	 * Current watermarks can't be trusted during hardware readout, so
577 	 * don't bother calculating intermediate watermarks.
578 	 */
579 	bool skip_intermediate_wm;
580 
581 	bool rps_interactive;
582 
583 	struct i915_sw_fence commit_ready;
584 
585 	struct llist_node freed;
586 };
587 
588 struct intel_plane_state {
589 	struct drm_plane_state uapi;
590 
591 	/*
592 	 * actual hardware state, the state we program to the hardware.
593 	 * The following members are used to verify the hardware state:
594 	 * During initial hw readout, they need to be copied from uapi.
595 	 */
596 	struct {
597 		struct drm_crtc *crtc;
598 		struct drm_framebuffer *fb;
599 
600 		u16 alpha;
601 		u16 pixel_blend_mode;
602 		unsigned int rotation;
603 		enum drm_color_encoding color_encoding;
604 		enum drm_color_range color_range;
605 		enum drm_scaling_filter scaling_filter;
606 	} hw;
607 
608 	struct i915_vma *ggtt_vma;
609 	struct i915_vma *dpt_vma;
610 	unsigned long flags;
611 #define PLANE_HAS_FENCE BIT(0)
612 
613 	struct intel_fb_view view;
614 
615 	/* Plane pxp decryption state */
616 	bool decrypt;
617 
618 	/* Plane state to display black pixels when pxp is borked */
619 	bool force_black;
620 
621 	/* plane control register */
622 	u32 ctl;
623 
624 	/* plane color control register */
625 	u32 color_ctl;
626 
627 	/* chroma upsampler control register */
628 	u32 cus_ctl;
629 
630 	/*
631 	 * scaler_id
632 	 *    = -1 : not using a scaler
633 	 *    >=  0 : using a scalers
634 	 *
635 	 * plane requiring a scaler:
636 	 *   - During check_plane, its bit is set in
637 	 *     crtc_state->scaler_state.scaler_users by calling helper function
638 	 *     update_scaler_plane.
639 	 *   - scaler_id indicates the scaler it got assigned.
640 	 *
641 	 * plane doesn't require a scaler:
642 	 *   - this can happen when scaling is no more required or plane simply
643 	 *     got disabled.
644 	 *   - During check_plane, corresponding bit is reset in
645 	 *     crtc_state->scaler_state.scaler_users by calling helper function
646 	 *     update_scaler_plane.
647 	 */
648 	int scaler_id;
649 
650 	/*
651 	 * planar_linked_plane:
652 	 *
653 	 * ICL planar formats require 2 planes that are updated as pairs.
654 	 * This member is used to make sure the other plane is also updated
655 	 * when required, and for update_slave() to find the correct
656 	 * plane_state to pass as argument.
657 	 */
658 	struct intel_plane *planar_linked_plane;
659 
660 	/*
661 	 * planar_slave:
662 	 * If set don't update use the linked plane's state for updating
663 	 * this plane during atomic commit with the update_slave() callback.
664 	 *
665 	 * It's also used by the watermark code to ignore wm calculations on
666 	 * this plane. They're calculated by the linked plane's wm code.
667 	 */
668 	u32 planar_slave;
669 
670 	struct drm_intel_sprite_colorkey ckey;
671 
672 	struct drm_rect psr2_sel_fetch_area;
673 
674 	/* Clear Color Value */
675 	u64 ccval;
676 
677 	const char *no_fbc_reason;
678 };
679 
680 struct intel_initial_plane_config {
681 	struct intel_framebuffer *fb;
682 	struct i915_vma *vma;
683 	unsigned int tiling;
684 	int size;
685 	u32 base;
686 	u8 rotation;
687 };
688 
689 struct intel_scaler {
690 	int in_use;
691 	u32 mode;
692 };
693 
694 struct intel_crtc_scaler_state {
695 #define SKL_NUM_SCALERS 2
696 	struct intel_scaler scalers[SKL_NUM_SCALERS];
697 
698 	/*
699 	 * scaler_users: keeps track of users requesting scalers on this crtc.
700 	 *
701 	 *     If a bit is set, a user is using a scaler.
702 	 *     Here user can be a plane or crtc as defined below:
703 	 *       bits 0-30 - plane (bit position is index from drm_plane_index)
704 	 *       bit 31    - crtc
705 	 *
706 	 * Instead of creating a new index to cover planes and crtc, using
707 	 * existing drm_plane_index for planes which is well less than 31
708 	 * planes and bit 31 for crtc. This should be fine to cover all
709 	 * our platforms.
710 	 *
711 	 * intel_atomic_setup_scalers will setup available scalers to users
712 	 * requesting scalers. It will gracefully fail if request exceeds
713 	 * avilability.
714 	 */
715 #define SKL_CRTC_INDEX 31
716 	unsigned scaler_users;
717 
718 	/* scaler used by crtc for panel fitting purpose */
719 	int scaler_id;
720 };
721 
722 /* {crtc,crtc_state}->mode_flags */
723 /* Flag to get scanline using frame time stamps */
724 #define I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP (1<<1)
725 /* Flag to use the scanline counter instead of the pixel counter */
726 #define I915_MODE_FLAG_USE_SCANLINE_COUNTER (1<<2)
727 /*
728  * TE0 or TE1 flag is set if the crtc has a DSI encoder which
729  * is operating in command mode.
730  * Flag to use TE from DSI0 instead of VBI in command mode
731  */
732 #define I915_MODE_FLAG_DSI_USE_TE0 (1<<3)
733 /* Flag to use TE from DSI1 instead of VBI in command mode */
734 #define I915_MODE_FLAG_DSI_USE_TE1 (1<<4)
735 /* Flag to indicate mipi dsi periodic command mode where we do not get TE */
736 #define I915_MODE_FLAG_DSI_PERIODIC_CMD_MODE (1<<5)
737 /* Do tricks to make vblank timestamps sane with VRR? */
738 #define I915_MODE_FLAG_VRR (1<<6)
739 
740 struct intel_wm_level {
741 	bool enable;
742 	u32 pri_val;
743 	u32 spr_val;
744 	u32 cur_val;
745 	u32 fbc_val;
746 };
747 
748 struct intel_pipe_wm {
749 	struct intel_wm_level wm[5];
750 	bool fbc_wm_enabled;
751 	bool pipe_enabled;
752 	bool sprites_enabled;
753 	bool sprites_scaled;
754 };
755 
756 struct skl_wm_level {
757 	u16 min_ddb_alloc;
758 	u16 blocks;
759 	u8 lines;
760 	bool enable;
761 	bool ignore_lines;
762 	bool can_sagv;
763 };
764 
765 struct skl_plane_wm {
766 	struct skl_wm_level wm[8];
767 	struct skl_wm_level uv_wm[8];
768 	struct skl_wm_level trans_wm;
769 	struct {
770 		struct skl_wm_level wm0;
771 		struct skl_wm_level trans_wm;
772 	} sagv;
773 	bool is_planar;
774 };
775 
776 struct skl_pipe_wm {
777 	struct skl_plane_wm planes[I915_MAX_PLANES];
778 	bool use_sagv_wm;
779 };
780 
781 enum vlv_wm_level {
782 	VLV_WM_LEVEL_PM2,
783 	VLV_WM_LEVEL_PM5,
784 	VLV_WM_LEVEL_DDR_DVFS,
785 	NUM_VLV_WM_LEVELS,
786 };
787 
788 struct vlv_wm_state {
789 	struct g4x_pipe_wm wm[NUM_VLV_WM_LEVELS];
790 	struct g4x_sr_wm sr[NUM_VLV_WM_LEVELS];
791 	u8 num_levels;
792 	bool cxsr;
793 };
794 
795 struct vlv_fifo_state {
796 	u16 plane[I915_MAX_PLANES];
797 };
798 
799 enum g4x_wm_level {
800 	G4X_WM_LEVEL_NORMAL,
801 	G4X_WM_LEVEL_SR,
802 	G4X_WM_LEVEL_HPLL,
803 	NUM_G4X_WM_LEVELS,
804 };
805 
806 struct g4x_wm_state {
807 	struct g4x_pipe_wm wm;
808 	struct g4x_sr_wm sr;
809 	struct g4x_sr_wm hpll;
810 	bool cxsr;
811 	bool hpll_en;
812 	bool fbc_en;
813 };
814 
815 struct intel_crtc_wm_state {
816 	union {
817 		/*
818 		 * raw:
819 		 * The "raw" watermark values produced by the formula
820 		 * given the plane's current state. They do not consider
821 		 * how much FIFO is actually allocated for each plane.
822 		 *
823 		 * optimal:
824 		 * The "optimal" watermark values given the current
825 		 * state of the planes and the amount of FIFO
826 		 * allocated to each, ignoring any previous state
827 		 * of the planes.
828 		 *
829 		 * intermediate:
830 		 * The "intermediate" watermark values when transitioning
831 		 * between the old and new "optimal" values. Used when
832 		 * the watermark registers are single buffered and hence
833 		 * their state changes asynchronously with regards to the
834 		 * actual plane registers. These are essentially the
835 		 * worst case combination of the old and new "optimal"
836 		 * watermarks, which are therefore safe to use when the
837 		 * plane is in either its old or new state.
838 		 */
839 		struct {
840 			struct intel_pipe_wm intermediate;
841 			struct intel_pipe_wm optimal;
842 		} ilk;
843 
844 		struct {
845 			struct skl_pipe_wm raw;
846 			/* gen9+ only needs 1-step wm programming */
847 			struct skl_pipe_wm optimal;
848 			struct skl_ddb_entry ddb;
849 			/*
850 			 * pre-icl: for packed/planar CbCr
851 			 * icl+: for everything
852 			 */
853 			struct skl_ddb_entry plane_ddb[I915_MAX_PLANES];
854 			/* pre-icl: for planar Y */
855 			struct skl_ddb_entry plane_ddb_y[I915_MAX_PLANES];
856 		} skl;
857 
858 		struct {
859 			struct g4x_pipe_wm raw[NUM_VLV_WM_LEVELS]; /* not inverted */
860 			struct vlv_wm_state intermediate; /* inverted */
861 			struct vlv_wm_state optimal; /* inverted */
862 			struct vlv_fifo_state fifo_state;
863 		} vlv;
864 
865 		struct {
866 			struct g4x_pipe_wm raw[NUM_G4X_WM_LEVELS];
867 			struct g4x_wm_state intermediate;
868 			struct g4x_wm_state optimal;
869 		} g4x;
870 	};
871 
872 	/*
873 	 * Platforms with two-step watermark programming will need to
874 	 * update watermark programming post-vblank to switch from the
875 	 * safe intermediate watermarks to the optimal final
876 	 * watermarks.
877 	 */
878 	bool need_postvbl_update;
879 };
880 
881 enum intel_output_format {
882 	INTEL_OUTPUT_FORMAT_RGB,
883 	INTEL_OUTPUT_FORMAT_YCBCR420,
884 	INTEL_OUTPUT_FORMAT_YCBCR444,
885 };
886 
887 struct intel_mpllb_state {
888 	u32 clock; /* in KHz */
889 	u32 ref_control;
890 	u32 mpllb_cp;
891 	u32 mpllb_div;
892 	u32 mpllb_div2;
893 	u32 mpllb_fracn1;
894 	u32 mpllb_fracn2;
895 	u32 mpllb_sscen;
896 	u32 mpllb_sscstep;
897 };
898 
899 struct intel_crtc_state {
900 	/*
901 	 * uapi (drm) state. This is the software state shown to userspace.
902 	 * In particular, the following members are used for bookkeeping:
903 	 * - crtc
904 	 * - state
905 	 * - *_changed
906 	 * - event
907 	 * - commit
908 	 * - mode_blob
909 	 */
910 	struct drm_crtc_state uapi;
911 
912 	/*
913 	 * actual hardware state, the state we program to the hardware.
914 	 * The following members are used to verify the hardware state:
915 	 * - enable
916 	 * - active
917 	 * - mode / pipe_mode / adjusted_mode
918 	 * - color property blobs.
919 	 *
920 	 * During initial hw readout, they need to be copied to uapi.
921 	 *
922 	 * Bigjoiner will allow a transcoder mode that spans 2 pipes;
923 	 * Use the pipe_mode for calculations like watermarks, pipe
924 	 * scaler, and bandwidth.
925 	 *
926 	 * Use adjusted_mode for things that need to know the full
927 	 * mode on the transcoder, which spans all pipes.
928 	 */
929 	struct {
930 		bool active, enable;
931 		struct drm_property_blob *degamma_lut, *gamma_lut, *ctm;
932 		struct drm_display_mode mode, pipe_mode, adjusted_mode;
933 		enum drm_scaling_filter scaling_filter;
934 	} hw;
935 
936 	/**
937 	 * quirks - bitfield with hw state readout quirks
938 	 *
939 	 * For various reasons the hw state readout code might not be able to
940 	 * completely faithfully read out the current state. These cases are
941 	 * tracked with quirk flags so that fastboot and state checker can act
942 	 * accordingly.
943 	 */
944 #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS	(1<<0) /* unreliable sync mode.flags */
945 	unsigned long quirks;
946 
947 	unsigned fb_bits; /* framebuffers to flip */
948 	bool update_pipe; /* can a fast modeset be performed? */
949 	bool disable_cxsr;
950 	bool update_wm_pre, update_wm_post; /* watermarks are updated */
951 	bool fifo_changed; /* FIFO split is changed */
952 	bool preload_luts;
953 	bool inherited; /* state inherited from BIOS? */
954 
955 	/* Ask the hardware to actually async flip? */
956 	bool do_async_flip;
957 
958 	/* Pipe source size (ie. panel fitter input size)
959 	 * All planes will be positioned inside this space,
960 	 * and get clipped at the edges. */
961 	struct drm_rect pipe_src;
962 
963 	/*
964 	 * Pipe pixel rate, adjusted for
965 	 * panel fitter/pipe scaler downscaling.
966 	 */
967 	unsigned int pixel_rate;
968 
969 	/* Whether to set up the PCH/FDI. Note that we never allow sharing
970 	 * between pch encoders and cpu encoders. */
971 	bool has_pch_encoder;
972 
973 	/* Are we sending infoframes on the attached port */
974 	bool has_infoframe;
975 
976 	/* CPU Transcoder for the pipe. Currently this can only differ from the
977 	 * pipe on Haswell and later (where we have a special eDP transcoder)
978 	 * and Broxton (where we have special DSI transcoders). */
979 	enum transcoder cpu_transcoder;
980 
981 	/*
982 	 * Use reduced/limited/broadcast rbg range, compressing from the full
983 	 * range fed into the crtcs.
984 	 */
985 	bool limited_color_range;
986 
987 	/* Bitmask of encoder types (enum intel_output_type)
988 	 * driven by the pipe.
989 	 */
990 	unsigned int output_types;
991 
992 	/* Whether we should send NULL infoframes. Required for audio. */
993 	bool has_hdmi_sink;
994 
995 	/* Audio enabled on this pipe. Only valid if either has_hdmi_sink or
996 	 * has_dp_encoder is set. */
997 	bool has_audio;
998 
999 	/*
1000 	 * Enable dithering, used when the selected pipe bpp doesn't match the
1001 	 * plane bpp.
1002 	 */
1003 	bool dither;
1004 
1005 	/*
1006 	 * Dither gets enabled for 18bpp which causes CRC mismatch errors for
1007 	 * compliance video pattern tests.
1008 	 * Disable dither only if it is a compliance test request for
1009 	 * 18bpp.
1010 	 */
1011 	bool dither_force_disable;
1012 
1013 	/* Controls for the clock computation, to override various stages. */
1014 	bool clock_set;
1015 
1016 	/* SDVO TV has a bunch of special case. To make multifunction encoders
1017 	 * work correctly, we need to track this at runtime.*/
1018 	bool sdvo_tv_clock;
1019 
1020 	/*
1021 	 * crtc bandwidth limit, don't increase pipe bpp or clock if not really
1022 	 * required. This is set in the 2nd loop of calling encoder's
1023 	 * ->compute_config if the first pick doesn't work out.
1024 	 */
1025 	bool bw_constrained;
1026 
1027 	/* Settings for the intel dpll used on pretty much everything but
1028 	 * haswell. */
1029 	struct dpll dpll;
1030 
1031 	/* Selected dpll when shared or NULL. */
1032 	struct intel_shared_dpll *shared_dpll;
1033 
1034 	/* Actual register state of the dpll, for shared dpll cross-checking. */
1035 	union {
1036 		struct intel_dpll_hw_state dpll_hw_state;
1037 		struct intel_mpllb_state mpllb_state;
1038 	};
1039 
1040 	/*
1041 	 * ICL reserved DPLLs for the CRTC/port. The active PLL is selected by
1042 	 * setting shared_dpll and dpll_hw_state to one of these reserved ones.
1043 	 */
1044 	struct icl_port_dpll {
1045 		struct intel_shared_dpll *pll;
1046 		struct intel_dpll_hw_state hw_state;
1047 	} icl_port_dplls[ICL_PORT_DPLL_COUNT];
1048 
1049 	/* DSI PLL registers */
1050 	struct {
1051 		u32 ctrl, div;
1052 	} dsi_pll;
1053 
1054 	int pipe_bpp;
1055 	struct intel_link_m_n dp_m_n;
1056 
1057 	/* m2_n2 for eDP downclock */
1058 	struct intel_link_m_n dp_m2_n2;
1059 	bool has_drrs;
1060 
1061 	/* PSR is supported but might not be enabled due the lack of enabled planes */
1062 	bool has_psr;
1063 	bool has_psr2;
1064 	bool enable_psr2_sel_fetch;
1065 	bool req_psr2_sdp_prior_scanline;
1066 	u32 dc3co_exitline;
1067 	u16 su_y_granularity;
1068 	struct drm_dp_vsc_sdp psr_vsc;
1069 
1070 	/*
1071 	 * Frequence the dpll for the port should run at. Differs from the
1072 	 * adjusted dotclock e.g. for DP or 10/12bpc hdmi mode. This is also
1073 	 * already multiplied by pixel_multiplier.
1074 	 */
1075 	int port_clock;
1076 
1077 	/* Used by SDVO (and if we ever fix it, HDMI). */
1078 	unsigned pixel_multiplier;
1079 
1080 	/* I915_MODE_FLAG_* */
1081 	u8 mode_flags;
1082 
1083 	u8 lane_count;
1084 
1085 	/*
1086 	 * Used by platforms having DP/HDMI PHY with programmable lane
1087 	 * latency optimization.
1088 	 */
1089 	u8 lane_lat_optim_mask;
1090 
1091 	/* minimum acceptable voltage level */
1092 	u8 min_voltage_level;
1093 
1094 	/* Panel fitter controls for gen2-gen4 + VLV */
1095 	struct {
1096 		u32 control;
1097 		u32 pgm_ratios;
1098 		u32 lvds_border_bits;
1099 	} gmch_pfit;
1100 
1101 	/* Panel fitter placement and size for Ironlake+ */
1102 	struct {
1103 		struct drm_rect dst;
1104 		bool enabled;
1105 		bool force_thru;
1106 	} pch_pfit;
1107 
1108 	/* FDI configuration, only valid if has_pch_encoder is set. */
1109 	int fdi_lanes;
1110 	struct intel_link_m_n fdi_m_n;
1111 
1112 	bool ips_enabled;
1113 
1114 	bool crc_enabled;
1115 
1116 	bool double_wide;
1117 
1118 	int pbn;
1119 
1120 	struct intel_crtc_scaler_state scaler_state;
1121 
1122 	/* w/a for waiting 2 vblanks during crtc enable */
1123 	enum pipe hsw_workaround_pipe;
1124 
1125 	/* IVB sprite scaling w/a (WaCxSRDisabledForSpriteScaling:ivb) */
1126 	bool disable_lp_wm;
1127 
1128 	struct intel_crtc_wm_state wm;
1129 
1130 	int min_cdclk[I915_MAX_PLANES];
1131 
1132 	/* for packed/planar CbCr */
1133 	u32 data_rate[I915_MAX_PLANES];
1134 	/* for planar Y */
1135 	u32 data_rate_y[I915_MAX_PLANES];
1136 
1137 	/* FIXME unify with data_rate[]? */
1138 	u64 rel_data_rate[I915_MAX_PLANES];
1139 	u64 rel_data_rate_y[I915_MAX_PLANES];
1140 
1141 	/* Gamma mode programmed on the pipe */
1142 	u32 gamma_mode;
1143 
1144 	union {
1145 		/* CSC mode programmed on the pipe */
1146 		u32 csc_mode;
1147 
1148 		/* CHV CGM mode */
1149 		u32 cgm_mode;
1150 	};
1151 
1152 	/* bitmask of logically enabled planes (enum plane_id) */
1153 	u8 enabled_planes;
1154 
1155 	/* bitmask of actually visible planes (enum plane_id) */
1156 	u8 active_planes;
1157 	u8 scaled_planes;
1158 	u8 nv12_planes;
1159 	u8 c8_planes;
1160 
1161 	/* bitmask of planes that will be updated during the commit */
1162 	u8 update_planes;
1163 
1164 	u8 framestart_delay; /* 1-4 */
1165 	u8 msa_timing_delay; /* 0-3 */
1166 
1167 	struct {
1168 		u32 enable;
1169 		u32 gcp;
1170 		union hdmi_infoframe avi;
1171 		union hdmi_infoframe spd;
1172 		union hdmi_infoframe hdmi;
1173 		union hdmi_infoframe drm;
1174 		struct drm_dp_vsc_sdp vsc;
1175 	} infoframes;
1176 
1177 	/* HDMI scrambling status */
1178 	bool hdmi_scrambling;
1179 
1180 	/* HDMI High TMDS char rate ratio */
1181 	bool hdmi_high_tmds_clock_ratio;
1182 
1183 	/* Output format RGB/YCBCR etc */
1184 	enum intel_output_format output_format;
1185 
1186 	/* enable pipe gamma? */
1187 	bool gamma_enable;
1188 
1189 	/* enable pipe csc? */
1190 	bool csc_enable;
1191 
1192 	/* big joiner pipe bitmask */
1193 	u8 bigjoiner_pipes;
1194 
1195 	/* Display Stream compression state */
1196 	struct {
1197 		bool compression_enable;
1198 		bool dsc_split;
1199 		u16 compressed_bpp;
1200 		u8 slice_count;
1201 		struct drm_dsc_config config;
1202 	} dsc;
1203 
1204 	/* HSW+ linetime watermarks */
1205 	u16 linetime;
1206 	u16 ips_linetime;
1207 
1208 	/* Forward Error correction State */
1209 	bool fec_enable;
1210 
1211 	/* Pointer to master transcoder in case of tiled displays */
1212 	enum transcoder master_transcoder;
1213 
1214 	/* Bitmask to indicate slaves attached */
1215 	u8 sync_mode_slaves_mask;
1216 
1217 	/* Only valid on TGL+ */
1218 	enum transcoder mst_master_transcoder;
1219 
1220 	/* For DSB related info */
1221 	struct intel_dsb *dsb;
1222 
1223 	u32 psr2_man_track_ctl;
1224 
1225 	/* Variable Refresh Rate state */
1226 	struct {
1227 		bool enable;
1228 		u8 pipeline_full;
1229 		u16 flipline, vmin, vmax, guardband;
1230 	} vrr;
1231 
1232 	/* Stream Splitter for eDP MSO */
1233 	struct {
1234 		bool enable;
1235 		u8 link_count;
1236 		u8 pixel_overlap;
1237 	} splitter;
1238 
1239 	/* for loading single buffered registers during vblank */
1240 	struct drm_vblank_work vblank_work;
1241 };
1242 
1243 enum intel_pipe_crc_source {
1244 	INTEL_PIPE_CRC_SOURCE_NONE,
1245 	INTEL_PIPE_CRC_SOURCE_PLANE1,
1246 	INTEL_PIPE_CRC_SOURCE_PLANE2,
1247 	INTEL_PIPE_CRC_SOURCE_PLANE3,
1248 	INTEL_PIPE_CRC_SOURCE_PLANE4,
1249 	INTEL_PIPE_CRC_SOURCE_PLANE5,
1250 	INTEL_PIPE_CRC_SOURCE_PLANE6,
1251 	INTEL_PIPE_CRC_SOURCE_PLANE7,
1252 	INTEL_PIPE_CRC_SOURCE_PIPE,
1253 	/* TV/DP on pre-gen5/vlv can't use the pipe source. */
1254 	INTEL_PIPE_CRC_SOURCE_TV,
1255 	INTEL_PIPE_CRC_SOURCE_DP_B,
1256 	INTEL_PIPE_CRC_SOURCE_DP_C,
1257 	INTEL_PIPE_CRC_SOURCE_DP_D,
1258 	INTEL_PIPE_CRC_SOURCE_AUTO,
1259 	INTEL_PIPE_CRC_SOURCE_MAX,
1260 };
1261 
1262 enum drrs_refresh_rate {
1263 	DRRS_REFRESH_RATE_HIGH,
1264 	DRRS_REFRESH_RATE_LOW,
1265 };
1266 
1267 #define INTEL_PIPE_CRC_ENTRIES_NR	128
1268 struct intel_pipe_crc {
1269 	spinlock_t lock;
1270 	int skipped;
1271 	enum intel_pipe_crc_source source;
1272 };
1273 
1274 struct intel_crtc {
1275 	struct drm_crtc base;
1276 	enum pipe pipe;
1277 	/*
1278 	 * Whether the crtc and the connected output pipeline is active. Implies
1279 	 * that crtc->enabled is set, i.e. the current mode configuration has
1280 	 * some outputs connected to this crtc.
1281 	 */
1282 	bool active;
1283 	u8 plane_ids_mask;
1284 
1285 	/* I915_MODE_FLAG_* */
1286 	u8 mode_flags;
1287 
1288 	u16 vmax_vblank_start;
1289 
1290 	struct intel_display_power_domain_set enabled_power_domains;
1291 	struct intel_overlay *overlay;
1292 
1293 	struct intel_crtc_state *config;
1294 
1295 	/* Access to these should be protected by dev_priv->irq_lock. */
1296 	bool cpu_fifo_underrun_disabled;
1297 	bool pch_fifo_underrun_disabled;
1298 
1299 	/* per-pipe watermark state */
1300 	struct {
1301 		/* watermarks currently being used  */
1302 		union {
1303 			struct intel_pipe_wm ilk;
1304 			struct vlv_wm_state vlv;
1305 			struct g4x_wm_state g4x;
1306 		} active;
1307 	} wm;
1308 
1309 	struct {
1310 		struct mutex mutex;
1311 		struct delayed_work work;
1312 		enum drrs_refresh_rate refresh_rate;
1313 		unsigned int frontbuffer_bits;
1314 		unsigned int busy_frontbuffer_bits;
1315 		enum transcoder cpu_transcoder;
1316 		struct intel_link_m_n m_n, m2_n2;
1317 	} drrs;
1318 
1319 	int scanline_offset;
1320 
1321 	struct {
1322 		unsigned start_vbl_count;
1323 		ktime_t start_vbl_time;
1324 		int min_vbl, max_vbl;
1325 		int scanline_start;
1326 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
1327 		struct {
1328 			u64 min;
1329 			u64 max;
1330 			u64 sum;
1331 			unsigned int over;
1332 			unsigned int times[17]; /* [1us, 16ms] */
1333 		} vbl;
1334 #endif
1335 	} debug;
1336 
1337 	/* scalers available on this crtc */
1338 	int num_scalers;
1339 
1340 	/* for loading single buffered registers during vblank */
1341 	struct pm_qos_request vblank_pm_qos;
1342 
1343 #ifdef CONFIG_DEBUG_FS
1344 	struct intel_pipe_crc pipe_crc;
1345 #endif
1346 };
1347 
1348 struct intel_plane {
1349 	struct drm_plane base;
1350 	enum i9xx_plane_id i9xx_plane;
1351 	enum plane_id id;
1352 	enum pipe pipe;
1353 	bool need_async_flip_disable_wa;
1354 	u32 frontbuffer_bit;
1355 
1356 	struct {
1357 		u32 base, cntl, size;
1358 	} cursor;
1359 
1360 	struct intel_fbc *fbc;
1361 
1362 	/*
1363 	 * NOTE: Do not place new plane state fields here (e.g., when adding
1364 	 * new plane properties).  New runtime state should now be placed in
1365 	 * the intel_plane_state structure and accessed via plane_state.
1366 	 */
1367 
1368 	int (*min_width)(const struct drm_framebuffer *fb,
1369 			 int color_plane,
1370 			 unsigned int rotation);
1371 	int (*max_width)(const struct drm_framebuffer *fb,
1372 			 int color_plane,
1373 			 unsigned int rotation);
1374 	int (*max_height)(const struct drm_framebuffer *fb,
1375 			  int color_plane,
1376 			  unsigned int rotation);
1377 	unsigned int (*max_stride)(struct intel_plane *plane,
1378 				   u32 pixel_format, u64 modifier,
1379 				   unsigned int rotation);
1380 	/* Write all non-self arming plane registers */
1381 	void (*update_noarm)(struct intel_plane *plane,
1382 			     const struct intel_crtc_state *crtc_state,
1383 			     const struct intel_plane_state *plane_state);
1384 	/* Write all self-arming plane registers */
1385 	void (*update_arm)(struct intel_plane *plane,
1386 			   const struct intel_crtc_state *crtc_state,
1387 			   const struct intel_plane_state *plane_state);
1388 	/* Disable the plane, must arm */
1389 	void (*disable_arm)(struct intel_plane *plane,
1390 			    const struct intel_crtc_state *crtc_state);
1391 	bool (*get_hw_state)(struct intel_plane *plane, enum pipe *pipe);
1392 	int (*check_plane)(struct intel_crtc_state *crtc_state,
1393 			   struct intel_plane_state *plane_state);
1394 	int (*min_cdclk)(const struct intel_crtc_state *crtc_state,
1395 			 const struct intel_plane_state *plane_state);
1396 	void (*async_flip)(struct intel_plane *plane,
1397 			   const struct intel_crtc_state *crtc_state,
1398 			   const struct intel_plane_state *plane_state,
1399 			   bool async_flip);
1400 	void (*enable_flip_done)(struct intel_plane *plane);
1401 	void (*disable_flip_done)(struct intel_plane *plane);
1402 };
1403 
1404 struct intel_watermark_params {
1405 	u16 fifo_size;
1406 	u16 max_wm;
1407 	u8 default_wm;
1408 	u8 guard_size;
1409 	u8 cacheline_size;
1410 };
1411 
1412 struct cxsr_latency {
1413 	bool is_desktop : 1;
1414 	bool is_ddr3 : 1;
1415 	u16 fsb_freq;
1416 	u16 mem_freq;
1417 	u16 display_sr;
1418 	u16 display_hpll_disable;
1419 	u16 cursor_sr;
1420 	u16 cursor_hpll_disable;
1421 };
1422 
1423 #define to_intel_atomic_state(x) container_of(x, struct intel_atomic_state, base)
1424 #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
1425 #define to_intel_crtc_state(x) container_of(x, struct intel_crtc_state, uapi)
1426 #define to_intel_connector(x) container_of(x, struct intel_connector, base)
1427 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
1428 #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
1429 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
1430 #define to_intel_plane_state(x) container_of(x, struct intel_plane_state, uapi)
1431 #define intel_fb_obj(x) ((x) ? to_intel_bo((x)->obj[0]) : NULL)
1432 
1433 struct intel_hdmi {
1434 	i915_reg_t hdmi_reg;
1435 	int ddc_bus;
1436 	struct {
1437 		enum drm_dp_dual_mode_type type;
1438 		int max_tmds_clock;
1439 	} dp_dual_mode;
1440 	bool has_hdmi_sink;
1441 	bool has_audio;
1442 	struct intel_connector *attached_connector;
1443 	struct cec_notifier *cec_notifier;
1444 };
1445 
1446 struct intel_dp_mst_encoder;
1447 
1448 struct intel_dp_compliance_data {
1449 	unsigned long edid;
1450 	u8 video_pattern;
1451 	u16 hdisplay, vdisplay;
1452 	u8 bpc;
1453 	struct drm_dp_phy_test_params phytest;
1454 };
1455 
1456 struct intel_dp_compliance {
1457 	unsigned long test_type;
1458 	struct intel_dp_compliance_data test_data;
1459 	bool test_active;
1460 	int test_link_rate;
1461 	u8 test_lane_count;
1462 };
1463 
1464 struct intel_dp_pcon_frl {
1465 	bool is_trained;
1466 	int trained_rate_gbps;
1467 };
1468 
1469 struct intel_pps {
1470 	int panel_power_up_delay;
1471 	int panel_power_down_delay;
1472 	int panel_power_cycle_delay;
1473 	int backlight_on_delay;
1474 	int backlight_off_delay;
1475 	struct delayed_work panel_vdd_work;
1476 	bool want_panel_vdd;
1477 	unsigned long last_power_on;
1478 	unsigned long last_backlight_off;
1479 	ktime_t panel_power_off_time;
1480 	intel_wakeref_t vdd_wakeref;
1481 
1482 	/*
1483 	 * Pipe whose power sequencer is currently locked into
1484 	 * this port. Only relevant on VLV/CHV.
1485 	 */
1486 	enum pipe pps_pipe;
1487 	/*
1488 	 * Pipe currently driving the port. Used for preventing
1489 	 * the use of the PPS for any pipe currentrly driving
1490 	 * external DP as that will mess things up on VLV.
1491 	 */
1492 	enum pipe active_pipe;
1493 	/*
1494 	 * Set if the sequencer may be reset due to a power transition,
1495 	 * requiring a reinitialization. Only relevant on BXT.
1496 	 */
1497 	bool pps_reset;
1498 	struct edp_power_seq pps_delays;
1499 };
1500 
1501 struct intel_psr {
1502 	/* Mutex for PSR state of the transcoder */
1503 	struct mutex lock;
1504 
1505 #define I915_PSR_DEBUG_MODE_MASK	0x0f
1506 #define I915_PSR_DEBUG_DEFAULT		0x00
1507 #define I915_PSR_DEBUG_DISABLE		0x01
1508 #define I915_PSR_DEBUG_ENABLE		0x02
1509 #define I915_PSR_DEBUG_FORCE_PSR1	0x03
1510 #define I915_PSR_DEBUG_ENABLE_SEL_FETCH	0x4
1511 #define I915_PSR_DEBUG_IRQ		0x10
1512 
1513 	u32 debug;
1514 	bool sink_support;
1515 	bool source_support;
1516 	bool enabled;
1517 	bool paused;
1518 	enum pipe pipe;
1519 	enum transcoder transcoder;
1520 	bool active;
1521 	struct work_struct work;
1522 	unsigned int busy_frontbuffer_bits;
1523 	bool sink_psr2_support;
1524 	bool link_standby;
1525 	bool colorimetry_support;
1526 	bool psr2_enabled;
1527 	bool psr2_sel_fetch_enabled;
1528 	bool psr2_sel_fetch_cff_enabled;
1529 	bool req_psr2_sdp_prior_scanline;
1530 	u8 sink_sync_latency;
1531 	ktime_t last_entry_attempt;
1532 	ktime_t last_exit;
1533 	bool sink_not_reliable;
1534 	bool irq_aux_error;
1535 	u16 su_w_granularity;
1536 	u16 su_y_granularity;
1537 	u32 dc3co_exitline;
1538 	u32 dc3co_exit_delay;
1539 	struct delayed_work dc3co_work;
1540 };
1541 
1542 struct intel_dp {
1543 	i915_reg_t output_reg;
1544 	u32 DP;
1545 	int link_rate;
1546 	u8 lane_count;
1547 	u8 sink_count;
1548 	bool link_trained;
1549 	bool has_hdmi_sink;
1550 	bool has_audio;
1551 	bool reset_link_params;
1552 	bool use_max_params;
1553 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
1554 	u8 psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
1555 	u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
1556 	u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
1557 	u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE];
1558 	u8 lttpr_common_caps[DP_LTTPR_COMMON_CAP_SIZE];
1559 	u8 lttpr_phy_caps[DP_MAX_LTTPR_COUNT][DP_LTTPR_PHY_CAP_SIZE];
1560 	u8 fec_capable;
1561 	u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE];
1562 	/* source rates */
1563 	int num_source_rates;
1564 	const int *source_rates;
1565 	/* sink rates as reported by DP_MAX_LINK_RATE/DP_SUPPORTED_LINK_RATES */
1566 	int num_sink_rates;
1567 	int sink_rates[DP_MAX_SUPPORTED_RATES];
1568 	bool use_rate_select;
1569 	/* Max sink lane count as reported by DP_MAX_LANE_COUNT */
1570 	int max_sink_lane_count;
1571 	/* intersection of source and sink rates */
1572 	int num_common_rates;
1573 	int common_rates[DP_MAX_SUPPORTED_RATES];
1574 	/* Max lane count for the current link */
1575 	int max_link_lane_count;
1576 	/* Max rate for the current link */
1577 	int max_link_rate;
1578 	int mso_link_count;
1579 	int mso_pixel_overlap;
1580 	/* sink or branch descriptor */
1581 	struct drm_dp_desc desc;
1582 	struct drm_dp_aux aux;
1583 	u32 aux_busy_last_status;
1584 	u8 train_set[4];
1585 
1586 	struct intel_pps pps;
1587 
1588 	bool is_mst;
1589 	int active_mst_links;
1590 
1591 	/* connector directly attached - won't be use for modeset in mst world */
1592 	struct intel_connector *attached_connector;
1593 
1594 	/* mst connector list */
1595 	struct intel_dp_mst_encoder *mst_encoders[I915_MAX_PIPES];
1596 	struct drm_dp_mst_topology_mgr mst_mgr;
1597 
1598 	u32 (*get_aux_clock_divider)(struct intel_dp *dp, int index);
1599 	/*
1600 	 * This function returns the value we have to program the AUX_CTL
1601 	 * register with to kick off an AUX transaction.
1602 	 */
1603 	u32 (*get_aux_send_ctl)(struct intel_dp *dp, int send_bytes,
1604 				u32 aux_clock_divider);
1605 
1606 	i915_reg_t (*aux_ch_ctl_reg)(struct intel_dp *dp);
1607 	i915_reg_t (*aux_ch_data_reg)(struct intel_dp *dp, int index);
1608 
1609 	/* This is called before a link training is starterd */
1610 	void (*prepare_link_retrain)(struct intel_dp *intel_dp,
1611 				     const struct intel_crtc_state *crtc_state);
1612 	void (*set_link_train)(struct intel_dp *intel_dp,
1613 			       const struct intel_crtc_state *crtc_state,
1614 			       u8 dp_train_pat);
1615 	void (*set_idle_link_train)(struct intel_dp *intel_dp,
1616 				    const struct intel_crtc_state *crtc_state);
1617 
1618 	u8 (*preemph_max)(struct intel_dp *intel_dp);
1619 	u8 (*voltage_max)(struct intel_dp *intel_dp,
1620 			  const struct intel_crtc_state *crtc_state);
1621 
1622 	/* Displayport compliance testing */
1623 	struct intel_dp_compliance compliance;
1624 
1625 	/* Downstream facing port caps */
1626 	struct {
1627 		int min_tmds_clock, max_tmds_clock;
1628 		int max_dotclock;
1629 		int pcon_max_frl_bw;
1630 		u8 max_bpc;
1631 		bool ycbcr_444_to_420;
1632 		bool rgb_to_ycbcr;
1633 	} dfp;
1634 
1635 	/* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
1636 	struct pm_qos_request pm_qos;
1637 
1638 	/* Display stream compression testing */
1639 	bool force_dsc_en;
1640 	int force_dsc_bpp;
1641 
1642 	bool hobl_failed;
1643 	bool hobl_active;
1644 
1645 	struct intel_dp_pcon_frl frl;
1646 
1647 	struct intel_psr psr;
1648 
1649 	/* When we last wrote the OUI for eDP */
1650 	unsigned long last_oui_write;
1651 };
1652 
1653 enum lspcon_vendor {
1654 	LSPCON_VENDOR_MCA,
1655 	LSPCON_VENDOR_PARADE
1656 };
1657 
1658 struct intel_lspcon {
1659 	bool active;
1660 	bool hdr_supported;
1661 	enum drm_lspcon_mode mode;
1662 	enum lspcon_vendor vendor;
1663 };
1664 
1665 struct intel_digital_port {
1666 	struct intel_encoder base;
1667 	u32 saved_port_bits;
1668 	struct intel_dp dp;
1669 	struct intel_hdmi hdmi;
1670 	struct intel_lspcon lspcon;
1671 	enum irqreturn (*hpd_pulse)(struct intel_digital_port *, bool);
1672 	bool release_cl2_override;
1673 	u8 max_lanes;
1674 	/* Used for DP and ICL+ TypeC/DP and TypeC/HDMI ports. */
1675 	enum aux_ch aux_ch;
1676 	enum intel_display_power_domain ddi_io_power_domain;
1677 	intel_wakeref_t ddi_io_wakeref;
1678 	intel_wakeref_t aux_wakeref;
1679 
1680 	struct mutex tc_lock;	/* protects the TypeC port mode */
1681 	intel_wakeref_t tc_lock_wakeref;
1682 	enum intel_display_power_domain tc_lock_power_domain;
1683 	struct delayed_work tc_disconnect_phy_work;
1684 	int tc_link_refcount;
1685 	bool tc_legacy_port:1;
1686 	char tc_port_name[8];
1687 	enum tc_port_mode tc_mode;
1688 	enum phy_fia tc_phy_fia;
1689 	u8 tc_phy_fia_idx;
1690 
1691 	/* protects num_hdcp_streams reference count, hdcp_port_data and hdcp_auth_status */
1692 	struct mutex hdcp_mutex;
1693 	/* the number of pipes using HDCP signalling out of this port */
1694 	unsigned int num_hdcp_streams;
1695 	/* port HDCP auth status */
1696 	bool hdcp_auth_status;
1697 	/* HDCP port data need to pass to security f/w */
1698 	struct hdcp_port_data hdcp_port_data;
1699 	/* Whether the MST topology supports HDCP Type 1 Content */
1700 	bool hdcp_mst_type1_capable;
1701 
1702 	void (*write_infoframe)(struct intel_encoder *encoder,
1703 				const struct intel_crtc_state *crtc_state,
1704 				unsigned int type,
1705 				const void *frame, ssize_t len);
1706 	void (*read_infoframe)(struct intel_encoder *encoder,
1707 			       const struct intel_crtc_state *crtc_state,
1708 			       unsigned int type,
1709 			       void *frame, ssize_t len);
1710 	void (*set_infoframes)(struct intel_encoder *encoder,
1711 			       bool enable,
1712 			       const struct intel_crtc_state *crtc_state,
1713 			       const struct drm_connector_state *conn_state);
1714 	u32 (*infoframes_enabled)(struct intel_encoder *encoder,
1715 				  const struct intel_crtc_state *pipe_config);
1716 	bool (*connected)(struct intel_encoder *encoder);
1717 };
1718 
1719 struct intel_dp_mst_encoder {
1720 	struct intel_encoder base;
1721 	enum pipe pipe;
1722 	struct intel_digital_port *primary;
1723 	struct intel_connector *connector;
1724 };
1725 
1726 static inline enum dpio_channel
vlv_dig_port_to_channel(struct intel_digital_port * dig_port)1727 vlv_dig_port_to_channel(struct intel_digital_port *dig_port)
1728 {
1729 	switch (dig_port->base.port) {
1730 	case PORT_B:
1731 	case PORT_D:
1732 		return DPIO_CH0;
1733 	case PORT_C:
1734 		return DPIO_CH1;
1735 	default:
1736 		BUG();
1737 	}
1738 }
1739 
1740 static inline enum dpio_phy
vlv_dig_port_to_phy(struct intel_digital_port * dig_port)1741 vlv_dig_port_to_phy(struct intel_digital_port *dig_port)
1742 {
1743 	switch (dig_port->base.port) {
1744 	case PORT_B:
1745 	case PORT_C:
1746 		return DPIO_PHY0;
1747 	case PORT_D:
1748 		return DPIO_PHY1;
1749 	default:
1750 		BUG();
1751 	}
1752 }
1753 
1754 static inline enum dpio_channel
vlv_pipe_to_channel(enum pipe pipe)1755 vlv_pipe_to_channel(enum pipe pipe)
1756 {
1757 	switch (pipe) {
1758 	case PIPE_A:
1759 	case PIPE_C:
1760 		return DPIO_CH0;
1761 	case PIPE_B:
1762 		return DPIO_CH1;
1763 	default:
1764 		BUG();
1765 	}
1766 }
1767 
1768 struct intel_load_detect_pipe {
1769 	struct drm_atomic_state *restore_state;
1770 };
1771 
1772 static inline struct intel_encoder *
intel_attached_encoder(struct intel_connector * connector)1773 intel_attached_encoder(struct intel_connector *connector)
1774 {
1775 	return connector->encoder;
1776 }
1777 
intel_encoder_is_dig_port(struct intel_encoder * encoder)1778 static inline bool intel_encoder_is_dig_port(struct intel_encoder *encoder)
1779 {
1780 	switch (encoder->type) {
1781 	case INTEL_OUTPUT_DDI:
1782 	case INTEL_OUTPUT_DP:
1783 	case INTEL_OUTPUT_EDP:
1784 	case INTEL_OUTPUT_HDMI:
1785 		return true;
1786 	default:
1787 		return false;
1788 	}
1789 }
1790 
intel_encoder_is_mst(struct intel_encoder * encoder)1791 static inline bool intel_encoder_is_mst(struct intel_encoder *encoder)
1792 {
1793 	return encoder->type == INTEL_OUTPUT_DP_MST;
1794 }
1795 
1796 static inline struct intel_dp_mst_encoder *
enc_to_mst(struct intel_encoder * encoder)1797 enc_to_mst(struct intel_encoder *encoder)
1798 {
1799 	return container_of(&encoder->base, struct intel_dp_mst_encoder,
1800 			    base.base);
1801 }
1802 
1803 static inline struct intel_digital_port *
enc_to_dig_port(struct intel_encoder * encoder)1804 enc_to_dig_port(struct intel_encoder *encoder)
1805 {
1806 	struct intel_encoder *intel_encoder = encoder;
1807 
1808 	if (intel_encoder_is_dig_port(intel_encoder))
1809 		return container_of(&encoder->base, struct intel_digital_port,
1810 				    base.base);
1811 	else if (intel_encoder_is_mst(intel_encoder))
1812 		return enc_to_mst(encoder)->primary;
1813 	else
1814 		return NULL;
1815 }
1816 
1817 static inline struct intel_digital_port *
intel_attached_dig_port(struct intel_connector * connector)1818 intel_attached_dig_port(struct intel_connector *connector)
1819 {
1820 	return enc_to_dig_port(intel_attached_encoder(connector));
1821 }
1822 
1823 static inline struct intel_hdmi *
enc_to_intel_hdmi(struct intel_encoder * encoder)1824 enc_to_intel_hdmi(struct intel_encoder *encoder)
1825 {
1826 	return &enc_to_dig_port(encoder)->hdmi;
1827 }
1828 
1829 static inline struct intel_hdmi *
intel_attached_hdmi(struct intel_connector * connector)1830 intel_attached_hdmi(struct intel_connector *connector)
1831 {
1832 	return enc_to_intel_hdmi(intel_attached_encoder(connector));
1833 }
1834 
enc_to_intel_dp(struct intel_encoder * encoder)1835 static inline struct intel_dp *enc_to_intel_dp(struct intel_encoder *encoder)
1836 {
1837 	return &enc_to_dig_port(encoder)->dp;
1838 }
1839 
intel_attached_dp(struct intel_connector * connector)1840 static inline struct intel_dp *intel_attached_dp(struct intel_connector *connector)
1841 {
1842 	return enc_to_intel_dp(intel_attached_encoder(connector));
1843 }
1844 
intel_encoder_is_dp(struct intel_encoder * encoder)1845 static inline bool intel_encoder_is_dp(struct intel_encoder *encoder)
1846 {
1847 	switch (encoder->type) {
1848 	case INTEL_OUTPUT_DP:
1849 	case INTEL_OUTPUT_EDP:
1850 		return true;
1851 	case INTEL_OUTPUT_DDI:
1852 		/* Skip pure HDMI/DVI DDI encoders */
1853 		return i915_mmio_reg_valid(enc_to_intel_dp(encoder)->output_reg);
1854 	default:
1855 		return false;
1856 	}
1857 }
1858 
1859 static inline struct intel_lspcon *
enc_to_intel_lspcon(struct intel_encoder * encoder)1860 enc_to_intel_lspcon(struct intel_encoder *encoder)
1861 {
1862 	return &enc_to_dig_port(encoder)->lspcon;
1863 }
1864 
1865 static inline struct intel_digital_port *
dp_to_dig_port(struct intel_dp * intel_dp)1866 dp_to_dig_port(struct intel_dp *intel_dp)
1867 {
1868 	return container_of(intel_dp, struct intel_digital_port, dp);
1869 }
1870 
1871 static inline struct intel_lspcon *
dp_to_lspcon(struct intel_dp * intel_dp)1872 dp_to_lspcon(struct intel_dp *intel_dp)
1873 {
1874 	return &dp_to_dig_port(intel_dp)->lspcon;
1875 }
1876 
1877 #define dp_to_i915(__intel_dp) to_i915(dp_to_dig_port(__intel_dp)->base.base.dev)
1878 
1879 #define CAN_PSR(intel_dp) ((intel_dp)->psr.sink_support && \
1880 			   (intel_dp)->psr.source_support)
1881 
intel_encoder_can_psr(struct intel_encoder * encoder)1882 static inline bool intel_encoder_can_psr(struct intel_encoder *encoder)
1883 {
1884 	if (!intel_encoder_is_dp(encoder))
1885 		return false;
1886 
1887 	return CAN_PSR(enc_to_intel_dp(encoder));
1888 }
1889 
1890 static inline struct intel_digital_port *
hdmi_to_dig_port(struct intel_hdmi * intel_hdmi)1891 hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
1892 {
1893 	return container_of(intel_hdmi, struct intel_digital_port, hdmi);
1894 }
1895 
1896 static inline struct intel_plane_state *
intel_atomic_get_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)1897 intel_atomic_get_plane_state(struct intel_atomic_state *state,
1898 				 struct intel_plane *plane)
1899 {
1900 	struct drm_plane_state *ret =
1901 		drm_atomic_get_plane_state(&state->base, &plane->base);
1902 
1903 	if (IS_ERR(ret))
1904 		return ERR_CAST(ret);
1905 
1906 	return to_intel_plane_state(ret);
1907 }
1908 
1909 static inline struct intel_plane_state *
intel_atomic_get_old_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)1910 intel_atomic_get_old_plane_state(struct intel_atomic_state *state,
1911 				 struct intel_plane *plane)
1912 {
1913 	return to_intel_plane_state(drm_atomic_get_old_plane_state(&state->base,
1914 								   &plane->base));
1915 }
1916 
1917 static inline struct intel_plane_state *
intel_atomic_get_new_plane_state(struct intel_atomic_state * state,struct intel_plane * plane)1918 intel_atomic_get_new_plane_state(struct intel_atomic_state *state,
1919 				 struct intel_plane *plane)
1920 {
1921 	return to_intel_plane_state(drm_atomic_get_new_plane_state(&state->base,
1922 								   &plane->base));
1923 }
1924 
1925 static inline struct intel_crtc_state *
intel_atomic_get_old_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)1926 intel_atomic_get_old_crtc_state(struct intel_atomic_state *state,
1927 				struct intel_crtc *crtc)
1928 {
1929 	return to_intel_crtc_state(drm_atomic_get_old_crtc_state(&state->base,
1930 								 &crtc->base));
1931 }
1932 
1933 static inline struct intel_crtc_state *
intel_atomic_get_new_crtc_state(struct intel_atomic_state * state,struct intel_crtc * crtc)1934 intel_atomic_get_new_crtc_state(struct intel_atomic_state *state,
1935 				struct intel_crtc *crtc)
1936 {
1937 	return to_intel_crtc_state(drm_atomic_get_new_crtc_state(&state->base,
1938 								 &crtc->base));
1939 }
1940 
1941 static inline struct intel_digital_connector_state *
intel_atomic_get_new_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)1942 intel_atomic_get_new_connector_state(struct intel_atomic_state *state,
1943 				     struct intel_connector *connector)
1944 {
1945 	return to_intel_digital_connector_state(
1946 			drm_atomic_get_new_connector_state(&state->base,
1947 			&connector->base));
1948 }
1949 
1950 static inline struct intel_digital_connector_state *
intel_atomic_get_old_connector_state(struct intel_atomic_state * state,struct intel_connector * connector)1951 intel_atomic_get_old_connector_state(struct intel_atomic_state *state,
1952 				     struct intel_connector *connector)
1953 {
1954 	return to_intel_digital_connector_state(
1955 			drm_atomic_get_old_connector_state(&state->base,
1956 			&connector->base));
1957 }
1958 
1959 /* intel_display.c */
1960 static inline bool
intel_crtc_has_type(const struct intel_crtc_state * crtc_state,enum intel_output_type type)1961 intel_crtc_has_type(const struct intel_crtc_state *crtc_state,
1962 		    enum intel_output_type type)
1963 {
1964 	return crtc_state->output_types & (1 << type);
1965 }
1966 static inline bool
intel_crtc_has_dp_encoder(const struct intel_crtc_state * crtc_state)1967 intel_crtc_has_dp_encoder(const struct intel_crtc_state *crtc_state)
1968 {
1969 	return crtc_state->output_types &
1970 		((1 << INTEL_OUTPUT_DP) |
1971 		 (1 << INTEL_OUTPUT_DP_MST) |
1972 		 (1 << INTEL_OUTPUT_EDP));
1973 }
1974 
1975 static inline bool
intel_crtc_needs_modeset(const struct intel_crtc_state * crtc_state)1976 intel_crtc_needs_modeset(const struct intel_crtc_state *crtc_state)
1977 {
1978 	return drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
1979 }
1980 
intel_plane_ggtt_offset(const struct intel_plane_state * plane_state)1981 static inline u32 intel_plane_ggtt_offset(const struct intel_plane_state *plane_state)
1982 {
1983 	return i915_ggtt_offset(plane_state->ggtt_vma);
1984 }
1985 
1986 static inline struct intel_frontbuffer *
to_intel_frontbuffer(struct drm_framebuffer * fb)1987 to_intel_frontbuffer(struct drm_framebuffer *fb)
1988 {
1989 	return fb ? to_intel_framebuffer(fb)->frontbuffer : NULL;
1990 }
1991 
1992 #endif /*  __INTEL_DISPLAY_TYPES_H__ */
1993