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