2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dma-resv.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/string_helpers.h>
35 #include <drm/display/drm_dp_helper.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_damage_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
45 #include "gem/i915_gem_lmem.h"
46 #include "gem/i915_gem_object.h"
51 #include "i915_config.h"
54 #include "i915_utils.h"
55 #include "i9xx_plane.h"
57 #include "intel_atomic.h"
58 #include "intel_atomic_plane.h"
59 #include "intel_audio.h"
61 #include "intel_cdclk.h"
62 #include "intel_clock_gating.h"
63 #include "intel_color.h"
64 #include "intel_crt.h"
65 #include "intel_crtc.h"
66 #include "intel_crtc_state_dump.h"
67 #include "intel_ddi.h"
69 #include "intel_display_driver.h"
70 #include "intel_display_power.h"
71 #include "intel_display_types.h"
72 #include "intel_dmc.h"
74 #include "intel_dp_link_training.h"
75 #include "intel_dp_mst.h"
76 #include "intel_dpll.h"
77 #include "intel_dpll_mgr.h"
78 #include "intel_dpt.h"
79 #include "intel_drrs.h"
80 #include "intel_dsb.h"
81 #include "intel_dsi.h"
82 #include "intel_dvo.h"
84 #include "intel_fbc.h"
85 #include "intel_fbdev.h"
86 #include "intel_fdi.h"
87 #include "intel_fifo_underrun.h"
88 #include "intel_frontbuffer.h"
89 #include "intel_hdmi.h"
90 #include "intel_hotplug.h"
91 #include "intel_link_bw.h"
92 #include "intel_lvds.h"
93 #include "intel_lvds_regs.h"
94 #include "intel_modeset_setup.h"
95 #include "intel_modeset_verify.h"
96 #include "intel_overlay.h"
97 #include "intel_panel.h"
98 #include "intel_pch_display.h"
99 #include "intel_pch_refclk.h"
100 #include "intel_pcode.h"
101 #include "intel_pipe_crc.h"
102 #include "intel_plane_initial.h"
103 #include "intel_pmdemand.h"
104 #include "intel_pps.h"
105 #include "intel_psr.h"
106 #include "intel_sdvo.h"
107 #include "intel_snps_phy.h"
108 #include "intel_tc.h"
109 #include "intel_tv.h"
110 #include "intel_vblank.h"
111 #include "intel_vdsc.h"
112 #include "intel_vdsc_regs.h"
113 #include "intel_vga.h"
114 #include "intel_vrr.h"
115 #include "intel_wm.h"
116 #include "skl_scaler.h"
117 #include "skl_universal_plane.h"
118 #include "skl_watermark.h"
120 #include "vlv_dsi_pll.h"
121 #include "vlv_dsi_regs.h"
122 #include "vlv_sideband.h"
124 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
125 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
126 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
127 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state);
129 /* returns HPLL frequency in kHz */
130 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
134 /* Obtain SKU information */
135 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
136 CCK_FUSE_HPLL_FREQ_MASK;
138 return vco_freq[hpll_freq] * 1000;
141 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
142 const char *name, u32 reg, int ref_freq)
147 val = vlv_cck_read(dev_priv, reg);
148 divider = val & CCK_FREQUENCY_VALUES;
150 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
151 (divider << CCK_FREQUENCY_STATUS_SHIFT),
152 "%s change in progress\n", name);
154 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
157 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
158 const char *name, u32 reg)
162 vlv_cck_get(dev_priv);
164 if (dev_priv->hpll_freq == 0)
165 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
167 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
169 vlv_cck_put(dev_priv);
174 void intel_update_czclk(struct drm_i915_private *dev_priv)
176 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
179 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
180 CCK_CZ_CLOCK_CONTROL);
182 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
183 dev_priv->czclk_freq);
186 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
188 return (crtc_state->active_planes &
189 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
192 /* WA Display #0827: Gen9:all */
194 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
196 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
197 DUPS1_GATING_DIS | DUPS2_GATING_DIS,
198 enable ? DUPS1_GATING_DIS | DUPS2_GATING_DIS : 0);
201 /* Wa_2006604312:icl,ehl */
203 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
206 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
208 enable ? DPFR_GATING_DIS : 0);
211 /* Wa_1604331009:icl,jsl,ehl */
213 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
216 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
218 enable ? CURSOR_GATING_DIS : 0);
222 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
224 return crtc_state->master_transcoder != INVALID_TRANSCODER;
228 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
230 return crtc_state->sync_mode_slaves_mask != 0;
234 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
236 return is_trans_port_sync_master(crtc_state) ||
237 is_trans_port_sync_slave(crtc_state);
240 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state)
242 return ffs(crtc_state->bigjoiner_pipes) - 1;
245 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state)
247 if (crtc_state->bigjoiner_pipes)
248 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state));
253 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state)
255 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
257 return crtc_state->bigjoiner_pipes &&
258 crtc->pipe != bigjoiner_master_pipe(crtc_state);
261 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state)
263 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
265 return crtc_state->bigjoiner_pipes &&
266 crtc->pipe == bigjoiner_master_pipe(crtc_state);
269 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state)
271 return hweight8(crtc_state->bigjoiner_pipes);
274 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state)
276 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
278 if (intel_crtc_is_bigjoiner_slave(crtc_state))
279 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state));
281 return to_intel_crtc(crtc_state->uapi.crtc);
285 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
287 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
288 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
290 if (DISPLAY_VER(dev_priv) >= 4) {
291 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
293 /* Wait for the Pipe State to go off */
294 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(cpu_transcoder),
295 TRANSCONF_STATE_ENABLE, 100))
296 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
298 intel_wait_for_pipe_scanline_stopped(crtc);
302 void assert_transcoder(struct drm_i915_private *dev_priv,
303 enum transcoder cpu_transcoder, bool state)
306 enum intel_display_power_domain power_domain;
307 intel_wakeref_t wakeref;
309 /* we keep both pipes enabled on 830 */
310 if (IS_I830(dev_priv))
313 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
314 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
316 u32 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
317 cur_state = !!(val & TRANSCONF_ENABLE);
319 intel_display_power_put(dev_priv, power_domain, wakeref);
324 I915_STATE_WARN(dev_priv, cur_state != state,
325 "transcoder %s assertion failure (expected %s, current %s)\n",
326 transcoder_name(cpu_transcoder), str_on_off(state),
327 str_on_off(cur_state));
330 static void assert_plane(struct intel_plane *plane, bool state)
332 struct drm_i915_private *i915 = to_i915(plane->base.dev);
336 cur_state = plane->get_hw_state(plane, &pipe);
338 I915_STATE_WARN(i915, cur_state != state,
339 "%s assertion failure (expected %s, current %s)\n",
340 plane->base.name, str_on_off(state),
341 str_on_off(cur_state));
344 #define assert_plane_enabled(p) assert_plane(p, true)
345 #define assert_plane_disabled(p) assert_plane(p, false)
347 static void assert_planes_disabled(struct intel_crtc *crtc)
349 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
350 struct intel_plane *plane;
352 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
353 assert_plane_disabled(plane);
356 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
357 struct intel_digital_port *dig_port,
358 unsigned int expected_mask)
363 switch (dig_port->base.port) {
365 MISSING_CASE(dig_port->base.port);
368 port_mask = DPLL_PORTB_READY_MASK;
372 port_mask = DPLL_PORTC_READY_MASK;
377 port_mask = DPLL_PORTD_READY_MASK;
378 dpll_reg = DPIO_PHY_STATUS;
382 if (intel_de_wait_for_register(dev_priv, dpll_reg,
383 port_mask, expected_mask, 1000))
384 drm_WARN(&dev_priv->drm, 1,
385 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
386 dig_port->base.base.base.id, dig_port->base.base.name,
387 intel_de_read(dev_priv, dpll_reg) & port_mask,
391 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
393 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
395 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
396 enum pipe pipe = crtc->pipe;
399 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
401 assert_planes_disabled(crtc);
404 * A pipe without a PLL won't actually be able to drive bits from
405 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
408 if (HAS_GMCH(dev_priv)) {
409 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
410 assert_dsi_pll_enabled(dev_priv);
412 assert_pll_enabled(dev_priv, pipe);
414 if (new_crtc_state->has_pch_encoder) {
415 /* if driving the PCH, we need FDI enabled */
416 assert_fdi_rx_pll_enabled(dev_priv,
417 intel_crtc_pch_transcoder(crtc));
418 assert_fdi_tx_pll_enabled(dev_priv,
419 (enum pipe) cpu_transcoder);
421 /* FIXME: assert CPU port conditions for SNB+ */
424 /* Wa_22012358565:adl-p */
425 if (DISPLAY_VER(dev_priv) == 13)
426 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
427 0, PIPE_ARB_USE_PROG_SLOTS);
429 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
430 if (val & TRANSCONF_ENABLE) {
431 /* we keep both pipes enabled on 830 */
432 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
436 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder),
437 val | TRANSCONF_ENABLE);
438 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
441 * Until the pipe starts PIPEDSL reads will return a stale value,
442 * which causes an apparent vblank timestamp jump when PIPEDSL
443 * resets to its proper value. That also messes up the frame count
444 * when it's derived from the timestamps. So let's wait for the
445 * pipe to start properly before we call drm_crtc_vblank_on()
447 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
448 intel_wait_for_pipe_scanline_moving(crtc);
451 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
453 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
454 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
455 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
456 enum pipe pipe = crtc->pipe;
459 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
462 * Make sure planes won't keep trying to pump pixels to us,
463 * or we might hang the display.
465 assert_planes_disabled(crtc);
467 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
468 if ((val & TRANSCONF_ENABLE) == 0)
472 * Double wide has implications for planes
473 * so best keep it disabled when not needed.
475 if (old_crtc_state->double_wide)
476 val &= ~TRANSCONF_DOUBLE_WIDE;
478 /* Don't disable pipe or pipe PLLs if needed */
479 if (!IS_I830(dev_priv))
480 val &= ~TRANSCONF_ENABLE;
482 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
484 if (DISPLAY_VER(dev_priv) >= 12)
485 intel_de_rmw(dev_priv, hsw_chicken_trans_reg(dev_priv, cpu_transcoder),
486 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
488 if ((val & TRANSCONF_ENABLE) == 0)
489 intel_wait_for_pipe_off(old_crtc_state);
492 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
494 unsigned int size = 0;
497 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
498 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
503 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
505 unsigned int size = 0;
508 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
509 unsigned int plane_size;
511 if (rem_info->plane[i].linear)
512 plane_size = rem_info->plane[i].size;
514 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
519 if (rem_info->plane_alignment)
520 size = ALIGN(size, rem_info->plane_alignment);
528 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
530 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
531 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
533 return DISPLAY_VER(dev_priv) < 4 ||
535 plane_state->view.gtt.type == I915_GTT_VIEW_NORMAL);
539 * Convert the x/y offsets into a linear offset.
540 * Only valid with 0/180 degree rotation, which is fine since linear
541 * offset is only used with linear buffers on pre-hsw and tiled buffers
542 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
544 u32 intel_fb_xy_to_linear(int x, int y,
545 const struct intel_plane_state *state,
548 const struct drm_framebuffer *fb = state->hw.fb;
549 unsigned int cpp = fb->format->cpp[color_plane];
550 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
552 return y * pitch + x * cpp;
556 * Add the x/y offsets derived from fb->offsets[] to the user
557 * specified plane src x/y offsets. The resulting x/y offsets
558 * specify the start of scanout from the beginning of the gtt mapping.
560 void intel_add_fb_offsets(int *x, int *y,
561 const struct intel_plane_state *state,
565 *x += state->view.color_plane[color_plane].x;
566 *y += state->view.color_plane[color_plane].y;
569 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
570 u32 pixel_format, u64 modifier)
572 struct intel_crtc *crtc;
573 struct intel_plane *plane;
575 if (!HAS_DISPLAY(dev_priv))
579 * We assume the primary plane for pipe A has
580 * the highest stride limits of them all,
581 * if in case pipe A is disabled, use the first pipe from pipe_mask.
583 crtc = intel_first_crtc(dev_priv);
587 plane = to_intel_plane(crtc->base.primary);
589 return plane->max_stride(plane, pixel_format, modifier,
593 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
594 struct intel_plane_state *plane_state,
597 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
599 plane_state->uapi.visible = visible;
602 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
604 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
607 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
609 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
610 struct drm_plane *plane;
613 * Active_planes aliases if multiple "primary" or cursor planes
614 * have been used on the same (or wrong) pipe. plane_mask uses
615 * unique ids, hence we can use that to reconstruct active_planes.
617 crtc_state->enabled_planes = 0;
618 crtc_state->active_planes = 0;
620 drm_for_each_plane_mask(plane, &dev_priv->drm,
621 crtc_state->uapi.plane_mask) {
622 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
623 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
627 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
628 struct intel_plane *plane)
630 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
631 struct intel_crtc_state *crtc_state =
632 to_intel_crtc_state(crtc->base.state);
633 struct intel_plane_state *plane_state =
634 to_intel_plane_state(plane->base.state);
636 drm_dbg_kms(&dev_priv->drm,
637 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
638 plane->base.base.id, plane->base.name,
639 crtc->base.base.id, crtc->base.name);
641 intel_set_plane_visible(crtc_state, plane_state, false);
642 intel_plane_fixup_bitmasks(crtc_state);
643 crtc_state->data_rate[plane->id] = 0;
644 crtc_state->data_rate_y[plane->id] = 0;
645 crtc_state->rel_data_rate[plane->id] = 0;
646 crtc_state->rel_data_rate_y[plane->id] = 0;
647 crtc_state->min_cdclk[plane->id] = 0;
649 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
650 hsw_ips_disable(crtc_state)) {
651 crtc_state->ips_enabled = false;
652 intel_crtc_wait_for_next_vblank(crtc);
656 * Vblank time updates from the shadow to live plane control register
657 * are blocked if the memory self-refresh mode is active at that
658 * moment. So to make sure the plane gets truly disabled, disable
659 * first the self-refresh mode. The self-refresh enable bit in turn
660 * will be checked/applied by the HW only at the next frame start
661 * event which is after the vblank start event, so we need to have a
662 * wait-for-vblank between disabling the plane and the pipe.
664 if (HAS_GMCH(dev_priv) &&
665 intel_set_memory_cxsr(dev_priv, false))
666 intel_crtc_wait_for_next_vblank(crtc);
669 * Gen2 reports pipe underruns whenever all planes are disabled.
670 * So disable underrun reporting before all the planes get disabled.
672 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
673 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
675 intel_plane_disable_arm(plane, crtc_state);
676 intel_crtc_wait_for_next_vblank(crtc);
680 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
684 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
685 plane_state->view.color_plane[0].offset, 0);
690 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
692 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
693 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
694 enum pipe pipe = crtc->pipe;
697 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
700 * Display WA #1153: icl
701 * enable hardware to bypass the alpha math
702 * and rounding for per-pixel values 00 and 0xff
704 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
706 * Display WA # 1605353570: icl
707 * Set the pixel rounding bit to 1 for allowing
708 * passthrough of Frame buffer pixels unmodified
711 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
714 * Underrun recovery must always be disabled on display 13+.
715 * DG2 chicken bit meaning is inverted compared to other platforms.
717 if (IS_DG2(dev_priv))
718 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
719 else if (DISPLAY_VER(dev_priv) >= 13)
720 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
722 /* Wa_14010547955:dg2 */
723 if (IS_DG2(dev_priv))
724 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
726 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
729 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
731 struct drm_crtc *crtc;
734 drm_for_each_crtc(crtc, &dev_priv->drm) {
735 struct drm_crtc_commit *commit;
736 spin_lock(&crtc->commit_lock);
737 commit = list_first_entry_or_null(&crtc->commit_list,
738 struct drm_crtc_commit, commit_entry);
739 cleanup_done = commit ?
740 try_wait_for_completion(&commit->cleanup_done) : true;
741 spin_unlock(&crtc->commit_lock);
746 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
755 * Finds the encoder associated with the given CRTC. This can only be
756 * used when we know that the CRTC isn't feeding multiple encoders!
758 struct intel_encoder *
759 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
760 const struct intel_crtc_state *crtc_state)
762 const struct drm_connector_state *connector_state;
763 const struct drm_connector *connector;
764 struct intel_encoder *encoder = NULL;
765 struct intel_crtc *master_crtc;
766 int num_encoders = 0;
769 master_crtc = intel_master_crtc(crtc_state);
771 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
772 if (connector_state->crtc != &master_crtc->base)
775 encoder = to_intel_encoder(connector_state->best_encoder);
779 drm_WARN(state->base.dev, num_encoders != 1,
780 "%d encoders for pipe %c\n",
781 num_encoders, pipe_name(master_crtc->pipe));
786 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
790 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
791 enum pipe pipe = crtc->pipe;
792 int width = drm_rect_width(dst);
793 int height = drm_rect_height(dst);
797 if (!crtc_state->pch_pfit.enabled)
800 /* Force use of hard-coded filter coefficients
801 * as some pre-programmed values are broken,
804 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
805 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
806 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
808 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
810 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe),
811 PF_WIN_XPOS(x) | PF_WIN_YPOS(y));
812 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe),
813 PF_WIN_XSIZE(width) | PF_WIN_YSIZE(height));
816 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
819 (void) intel_overlay_switch_off(crtc->overlay);
821 /* Let userspace switch the overlay on again. In most cases userspace
822 * has to recompute where to put it anyway.
826 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
828 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
830 if (!crtc_state->nv12_planes)
833 /* WA Display #0827: Gen9:all */
834 if (DISPLAY_VER(dev_priv) == 9)
840 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
842 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
844 /* Wa_2006604312:icl,ehl */
845 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
851 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
853 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
855 /* Wa_1604331009:icl,jsl,ehl */
856 if (is_hdr_mode(crtc_state) &&
857 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
858 DISPLAY_VER(dev_priv) == 11)
864 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
865 enum pipe pipe, bool enable)
867 if (DISPLAY_VER(i915) == 9) {
869 * "Plane N strech max must be programmed to 11b (x1)
870 * when Async flips are enabled on that plane."
872 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
873 SKL_PLANE1_STRETCH_MAX_MASK,
874 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
876 /* Also needed on HSW/BDW albeit undocumented */
877 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
878 HSW_PRI_STRETCH_MAX_MASK,
879 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
883 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
885 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
887 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
888 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
891 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
892 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
893 (new_crtc_state)->feature)
894 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
895 ((old_crtc_state)->feature && \
896 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
898 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
899 const struct intel_crtc_state *new_crtc_state)
901 if (!new_crtc_state->hw.active)
904 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
907 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
908 const struct intel_crtc_state *new_crtc_state)
910 if (!old_crtc_state->hw.active)
913 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
916 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state,
917 const struct intel_crtc_state *new_crtc_state)
919 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline ||
920 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin ||
921 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax ||
922 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband ||
923 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full;
926 static bool vrr_enabling(const struct intel_crtc_state *old_crtc_state,
927 const struct intel_crtc_state *new_crtc_state)
929 if (!new_crtc_state->hw.active)
932 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) ||
933 (new_crtc_state->vrr.enable &&
934 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
935 vrr_params_changed(old_crtc_state, new_crtc_state)));
938 static bool vrr_disabling(const struct intel_crtc_state *old_crtc_state,
939 const struct intel_crtc_state *new_crtc_state)
941 if (!old_crtc_state->hw.active)
944 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) ||
945 (old_crtc_state->vrr.enable &&
946 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
947 vrr_params_changed(old_crtc_state, new_crtc_state)));
953 static void intel_post_plane_update(struct intel_atomic_state *state,
954 struct intel_crtc *crtc)
956 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
957 const struct intel_crtc_state *old_crtc_state =
958 intel_atomic_get_old_crtc_state(state, crtc);
959 const struct intel_crtc_state *new_crtc_state =
960 intel_atomic_get_new_crtc_state(state, crtc);
961 enum pipe pipe = crtc->pipe;
963 intel_psr_post_plane_update(state, crtc);
965 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
967 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
968 intel_update_watermarks(dev_priv);
970 intel_fbc_post_update(state, crtc);
972 if (needs_async_flip_vtd_wa(old_crtc_state) &&
973 !needs_async_flip_vtd_wa(new_crtc_state))
974 intel_async_flip_vtd_wa(dev_priv, pipe, false);
976 if (needs_nv12_wa(old_crtc_state) &&
977 !needs_nv12_wa(new_crtc_state))
978 skl_wa_827(dev_priv, pipe, false);
980 if (needs_scalerclk_wa(old_crtc_state) &&
981 !needs_scalerclk_wa(new_crtc_state))
982 icl_wa_scalerclkgating(dev_priv, pipe, false);
984 if (needs_cursorclk_wa(old_crtc_state) &&
985 !needs_cursorclk_wa(new_crtc_state))
986 icl_wa_cursorclkgating(dev_priv, pipe, false);
988 if (intel_crtc_needs_color_update(new_crtc_state))
989 intel_color_post_update(new_crtc_state);
992 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
993 struct intel_crtc *crtc)
995 const struct intel_crtc_state *crtc_state =
996 intel_atomic_get_new_crtc_state(state, crtc);
997 u8 update_planes = crtc_state->update_planes;
998 const struct intel_plane_state __maybe_unused *plane_state;
999 struct intel_plane *plane;
1002 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1003 if (plane->pipe == crtc->pipe &&
1004 update_planes & BIT(plane->id))
1005 plane->enable_flip_done(plane);
1009 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1010 struct intel_crtc *crtc)
1012 const struct intel_crtc_state *crtc_state =
1013 intel_atomic_get_new_crtc_state(state, crtc);
1014 u8 update_planes = crtc_state->update_planes;
1015 const struct intel_plane_state __maybe_unused *plane_state;
1016 struct intel_plane *plane;
1019 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1020 if (plane->pipe == crtc->pipe &&
1021 update_planes & BIT(plane->id))
1022 plane->disable_flip_done(plane);
1026 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1027 struct intel_crtc *crtc)
1029 const struct intel_crtc_state *old_crtc_state =
1030 intel_atomic_get_old_crtc_state(state, crtc);
1031 const struct intel_crtc_state *new_crtc_state =
1032 intel_atomic_get_new_crtc_state(state, crtc);
1033 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1034 ~new_crtc_state->async_flip_planes;
1035 const struct intel_plane_state *old_plane_state;
1036 struct intel_plane *plane;
1037 bool need_vbl_wait = false;
1040 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1041 if (plane->need_async_flip_disable_wa &&
1042 plane->pipe == crtc->pipe &&
1043 disable_async_flip_planes & BIT(plane->id)) {
1045 * Apart from the async flip bit we want to
1046 * preserve the old state for the plane.
1048 plane->async_flip(plane, old_crtc_state,
1049 old_plane_state, false);
1050 need_vbl_wait = true;
1055 intel_crtc_wait_for_next_vblank(crtc);
1058 static void intel_pre_plane_update(struct intel_atomic_state *state,
1059 struct intel_crtc *crtc)
1061 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1062 const struct intel_crtc_state *old_crtc_state =
1063 intel_atomic_get_old_crtc_state(state, crtc);
1064 const struct intel_crtc_state *new_crtc_state =
1065 intel_atomic_get_new_crtc_state(state, crtc);
1066 enum pipe pipe = crtc->pipe;
1068 if (vrr_disabling(old_crtc_state, new_crtc_state)) {
1069 intel_vrr_disable(old_crtc_state);
1070 intel_crtc_update_active_timings(old_crtc_state, false);
1073 intel_drrs_deactivate(old_crtc_state);
1075 intel_psr_pre_plane_update(state, crtc);
1077 if (hsw_ips_pre_update(state, crtc))
1078 intel_crtc_wait_for_next_vblank(crtc);
1080 if (intel_fbc_pre_update(state, crtc))
1081 intel_crtc_wait_for_next_vblank(crtc);
1083 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1084 needs_async_flip_vtd_wa(new_crtc_state))
1085 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1087 /* Display WA 827 */
1088 if (!needs_nv12_wa(old_crtc_state) &&
1089 needs_nv12_wa(new_crtc_state))
1090 skl_wa_827(dev_priv, pipe, true);
1092 /* Wa_2006604312:icl,ehl */
1093 if (!needs_scalerclk_wa(old_crtc_state) &&
1094 needs_scalerclk_wa(new_crtc_state))
1095 icl_wa_scalerclkgating(dev_priv, pipe, true);
1097 /* Wa_1604331009:icl,jsl,ehl */
1098 if (!needs_cursorclk_wa(old_crtc_state) &&
1099 needs_cursorclk_wa(new_crtc_state))
1100 icl_wa_cursorclkgating(dev_priv, pipe, true);
1103 * Vblank time updates from the shadow to live plane control register
1104 * are blocked if the memory self-refresh mode is active at that
1105 * moment. So to make sure the plane gets truly disabled, disable
1106 * first the self-refresh mode. The self-refresh enable bit in turn
1107 * will be checked/applied by the HW only at the next frame start
1108 * event which is after the vblank start event, so we need to have a
1109 * wait-for-vblank between disabling the plane and the pipe.
1111 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1112 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1113 intel_crtc_wait_for_next_vblank(crtc);
1116 * IVB workaround: must disable low power watermarks for at least
1117 * one frame before enabling scaling. LP watermarks can be re-enabled
1118 * when scaling is disabled.
1120 * WaCxSRDisabledForSpriteScaling:ivb
1122 if (old_crtc_state->hw.active &&
1123 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
1124 intel_crtc_wait_for_next_vblank(crtc);
1127 * If we're doing a modeset we don't need to do any
1128 * pre-vblank watermark programming here.
1130 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1132 * For platforms that support atomic watermarks, program the
1133 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1134 * will be the intermediate values that are safe for both pre- and
1135 * post- vblank; when vblank happens, the 'active' values will be set
1136 * to the final 'target' values and we'll do this again to get the
1137 * optimal watermarks. For gen9+ platforms, the values we program here
1138 * will be the final target values which will get automatically latched
1139 * at vblank time; no further programming will be necessary.
1141 * If a platform hasn't been transitioned to atomic watermarks yet,
1142 * we'll continue to update watermarks the old way, if flags tell
1145 if (!intel_initial_watermarks(state, crtc))
1146 if (new_crtc_state->update_wm_pre)
1147 intel_update_watermarks(dev_priv);
1151 * Gen2 reports pipe underruns whenever all planes are disabled.
1152 * So disable underrun reporting before all the planes get disabled.
1154 * We do this after .initial_watermarks() so that we have a
1155 * chance of catching underruns with the intermediate watermarks
1156 * vs. the old plane configuration.
1158 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1159 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1162 * WA for platforms where async address update enable bit
1163 * is double buffered and only latched at start of vblank.
1165 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1166 intel_crtc_async_flip_disable_wa(state, crtc);
1169 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1170 struct intel_crtc *crtc)
1172 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1173 const struct intel_crtc_state *new_crtc_state =
1174 intel_atomic_get_new_crtc_state(state, crtc);
1175 unsigned int update_mask = new_crtc_state->update_planes;
1176 const struct intel_plane_state *old_plane_state;
1177 struct intel_plane *plane;
1178 unsigned fb_bits = 0;
1181 intel_crtc_dpms_overlay_disable(crtc);
1183 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1184 if (crtc->pipe != plane->pipe ||
1185 !(update_mask & BIT(plane->id)))
1188 intel_plane_disable_arm(plane, new_crtc_state);
1190 if (old_plane_state->uapi.visible)
1191 fb_bits |= plane->frontbuffer_bit;
1194 intel_frontbuffer_flip(dev_priv, fb_bits);
1197 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1199 struct drm_i915_private *i915 = to_i915(state->base.dev);
1200 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1201 struct intel_crtc *crtc;
1205 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1206 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1208 if (i915->display.dpll.mgr) {
1209 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1210 if (intel_crtc_needs_modeset(new_crtc_state))
1213 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1214 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1219 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1220 struct intel_crtc *crtc)
1222 const struct intel_crtc_state *crtc_state =
1223 intel_atomic_get_new_crtc_state(state, crtc);
1224 const struct drm_connector_state *conn_state;
1225 struct drm_connector *conn;
1228 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1229 struct intel_encoder *encoder =
1230 to_intel_encoder(conn_state->best_encoder);
1232 if (conn_state->crtc != &crtc->base)
1235 if (encoder->pre_pll_enable)
1236 encoder->pre_pll_enable(state, encoder,
1237 crtc_state, conn_state);
1241 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1242 struct intel_crtc *crtc)
1244 const struct intel_crtc_state *crtc_state =
1245 intel_atomic_get_new_crtc_state(state, crtc);
1246 const struct drm_connector_state *conn_state;
1247 struct drm_connector *conn;
1250 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1251 struct intel_encoder *encoder =
1252 to_intel_encoder(conn_state->best_encoder);
1254 if (conn_state->crtc != &crtc->base)
1257 if (encoder->pre_enable)
1258 encoder->pre_enable(state, encoder,
1259 crtc_state, conn_state);
1263 static void intel_encoders_enable(struct intel_atomic_state *state,
1264 struct intel_crtc *crtc)
1266 const struct intel_crtc_state *crtc_state =
1267 intel_atomic_get_new_crtc_state(state, crtc);
1268 const struct drm_connector_state *conn_state;
1269 struct drm_connector *conn;
1272 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1273 struct intel_encoder *encoder =
1274 to_intel_encoder(conn_state->best_encoder);
1276 if (conn_state->crtc != &crtc->base)
1279 if (encoder->enable)
1280 encoder->enable(state, encoder,
1281 crtc_state, conn_state);
1282 intel_opregion_notify_encoder(encoder, true);
1286 static void intel_encoders_disable(struct intel_atomic_state *state,
1287 struct intel_crtc *crtc)
1289 const struct intel_crtc_state *old_crtc_state =
1290 intel_atomic_get_old_crtc_state(state, crtc);
1291 const struct drm_connector_state *old_conn_state;
1292 struct drm_connector *conn;
1295 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1296 struct intel_encoder *encoder =
1297 to_intel_encoder(old_conn_state->best_encoder);
1299 if (old_conn_state->crtc != &crtc->base)
1302 intel_opregion_notify_encoder(encoder, false);
1303 if (encoder->disable)
1304 encoder->disable(state, encoder,
1305 old_crtc_state, old_conn_state);
1309 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1310 struct intel_crtc *crtc)
1312 const struct intel_crtc_state *old_crtc_state =
1313 intel_atomic_get_old_crtc_state(state, crtc);
1314 const struct drm_connector_state *old_conn_state;
1315 struct drm_connector *conn;
1318 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1319 struct intel_encoder *encoder =
1320 to_intel_encoder(old_conn_state->best_encoder);
1322 if (old_conn_state->crtc != &crtc->base)
1325 if (encoder->post_disable)
1326 encoder->post_disable(state, encoder,
1327 old_crtc_state, old_conn_state);
1331 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1332 struct intel_crtc *crtc)
1334 const struct intel_crtc_state *old_crtc_state =
1335 intel_atomic_get_old_crtc_state(state, crtc);
1336 const struct drm_connector_state *old_conn_state;
1337 struct drm_connector *conn;
1340 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1341 struct intel_encoder *encoder =
1342 to_intel_encoder(old_conn_state->best_encoder);
1344 if (old_conn_state->crtc != &crtc->base)
1347 if (encoder->post_pll_disable)
1348 encoder->post_pll_disable(state, encoder,
1349 old_crtc_state, old_conn_state);
1353 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1354 struct intel_crtc *crtc)
1356 const struct intel_crtc_state *crtc_state =
1357 intel_atomic_get_new_crtc_state(state, crtc);
1358 const struct drm_connector_state *conn_state;
1359 struct drm_connector *conn;
1362 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1363 struct intel_encoder *encoder =
1364 to_intel_encoder(conn_state->best_encoder);
1366 if (conn_state->crtc != &crtc->base)
1369 if (encoder->update_pipe)
1370 encoder->update_pipe(state, encoder,
1371 crtc_state, conn_state);
1375 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
1377 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1378 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1380 plane->disable_arm(plane, crtc_state);
1383 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1385 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1386 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1388 if (crtc_state->has_pch_encoder) {
1389 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1390 &crtc_state->fdi_m_n);
1391 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1392 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1393 &crtc_state->dp_m_n);
1394 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1395 &crtc_state->dp_m2_n2);
1398 intel_set_transcoder_timings(crtc_state);
1400 ilk_set_pipeconf(crtc_state);
1403 static void ilk_crtc_enable(struct intel_atomic_state *state,
1404 struct intel_crtc *crtc)
1406 const struct intel_crtc_state *new_crtc_state =
1407 intel_atomic_get_new_crtc_state(state, crtc);
1408 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1409 enum pipe pipe = crtc->pipe;
1411 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1415 * Sometimes spurious CPU pipe underruns happen during FDI
1416 * training, at least with VGA+HDMI cloning. Suppress them.
1418 * On ILK we get an occasional spurious CPU pipe underruns
1419 * between eDP port A enable and vdd enable. Also PCH port
1420 * enable seems to result in the occasional CPU pipe underrun.
1422 * Spurious PCH underruns also occur during PCH enabling.
1424 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1425 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1427 ilk_configure_cpu_transcoder(new_crtc_state);
1429 intel_set_pipe_src_size(new_crtc_state);
1431 crtc->active = true;
1433 intel_encoders_pre_enable(state, crtc);
1435 if (new_crtc_state->has_pch_encoder) {
1436 ilk_pch_pre_enable(state, crtc);
1438 assert_fdi_tx_disabled(dev_priv, pipe);
1439 assert_fdi_rx_disabled(dev_priv, pipe);
1442 ilk_pfit_enable(new_crtc_state);
1445 * On ILK+ LUT must be loaded before the pipe is running but with
1448 intel_color_load_luts(new_crtc_state);
1449 intel_color_commit_noarm(new_crtc_state);
1450 intel_color_commit_arm(new_crtc_state);
1451 /* update DSPCNTR to configure gamma for pipe bottom color */
1452 intel_disable_primary_plane(new_crtc_state);
1454 intel_initial_watermarks(state, crtc);
1455 intel_enable_transcoder(new_crtc_state);
1457 if (new_crtc_state->has_pch_encoder)
1458 ilk_pch_enable(state, crtc);
1460 intel_crtc_vblank_on(new_crtc_state);
1462 intel_encoders_enable(state, crtc);
1464 if (HAS_PCH_CPT(dev_priv))
1465 intel_wait_for_pipe_scanline_moving(crtc);
1468 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1469 * And a second vblank wait is needed at least on ILK with
1470 * some interlaced HDMI modes. Let's do the double wait always
1471 * in case there are more corner cases we don't know about.
1473 if (new_crtc_state->has_pch_encoder) {
1474 intel_crtc_wait_for_next_vblank(crtc);
1475 intel_crtc_wait_for_next_vblank(crtc);
1477 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1478 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1481 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
1482 enum pipe pipe, bool apply)
1484 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
1485 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1492 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
1495 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1497 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1498 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1500 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1501 HSW_LINETIME(crtc_state->linetime) |
1502 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1505 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1507 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1508 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1510 intel_de_rmw(i915, hsw_chicken_trans_reg(i915, crtc_state->cpu_transcoder),
1511 HSW_FRAME_START_DELAY_MASK,
1512 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1515 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
1516 const struct intel_crtc_state *crtc_state)
1518 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state);
1521 * Enable sequence steps 1-7 on bigjoiner master
1523 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1524 intel_encoders_pre_pll_enable(state, master_crtc);
1526 if (crtc_state->shared_dpll)
1527 intel_enable_shared_dpll(crtc_state);
1529 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1530 intel_encoders_pre_enable(state, master_crtc);
1533 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1535 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1536 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1537 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1539 if (crtc_state->has_pch_encoder) {
1540 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1541 &crtc_state->fdi_m_n);
1542 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1543 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1544 &crtc_state->dp_m_n);
1545 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1546 &crtc_state->dp_m2_n2);
1549 intel_set_transcoder_timings(crtc_state);
1550 if (HAS_VRR(dev_priv))
1551 intel_vrr_set_transcoder_timings(crtc_state);
1553 if (cpu_transcoder != TRANSCODER_EDP)
1554 intel_de_write(dev_priv, TRANS_MULT(cpu_transcoder),
1555 crtc_state->pixel_multiplier - 1);
1557 hsw_set_frame_start_delay(crtc_state);
1559 hsw_set_transconf(crtc_state);
1562 static void hsw_crtc_enable(struct intel_atomic_state *state,
1563 struct intel_crtc *crtc)
1565 const struct intel_crtc_state *new_crtc_state =
1566 intel_atomic_get_new_crtc_state(state, crtc);
1567 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1568 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
1569 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1570 bool psl_clkgate_wa;
1572 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1575 intel_dmc_enable_pipe(dev_priv, crtc->pipe);
1577 if (!new_crtc_state->bigjoiner_pipes) {
1578 intel_encoders_pre_pll_enable(state, crtc);
1580 if (new_crtc_state->shared_dpll)
1581 intel_enable_shared_dpll(new_crtc_state);
1583 intel_encoders_pre_enable(state, crtc);
1585 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
1588 intel_dsc_enable(new_crtc_state);
1590 if (DISPLAY_VER(dev_priv) >= 13)
1591 intel_uncompressed_joiner_enable(new_crtc_state);
1593 intel_set_pipe_src_size(new_crtc_state);
1594 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1595 bdw_set_pipe_misc(new_crtc_state);
1597 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) &&
1598 !transcoder_is_dsi(cpu_transcoder))
1599 hsw_configure_cpu_transcoder(new_crtc_state);
1601 crtc->active = true;
1603 /* Display WA #1180: WaDisableScalarClockGating: glk */
1604 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
1605 new_crtc_state->pch_pfit.enabled;
1607 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
1609 if (DISPLAY_VER(dev_priv) >= 9)
1610 skl_pfit_enable(new_crtc_state);
1612 ilk_pfit_enable(new_crtc_state);
1615 * On ILK+ LUT must be loaded before the pipe is running but with
1618 intel_color_load_luts(new_crtc_state);
1619 intel_color_commit_noarm(new_crtc_state);
1620 intel_color_commit_arm(new_crtc_state);
1621 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
1622 if (DISPLAY_VER(dev_priv) < 9)
1623 intel_disable_primary_plane(new_crtc_state);
1625 hsw_set_linetime_wm(new_crtc_state);
1627 if (DISPLAY_VER(dev_priv) >= 11)
1628 icl_set_pipe_chicken(new_crtc_state);
1630 intel_initial_watermarks(state, crtc);
1632 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
1633 intel_crtc_vblank_on(new_crtc_state);
1635 intel_encoders_enable(state, crtc);
1637 if (psl_clkgate_wa) {
1638 intel_crtc_wait_for_next_vblank(crtc);
1639 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
1642 /* If we change the relative order between pipe/planes enabling, we need
1643 * to change the workaround. */
1644 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
1645 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1646 struct intel_crtc *wa_crtc;
1648 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe);
1650 intel_crtc_wait_for_next_vblank(wa_crtc);
1651 intel_crtc_wait_for_next_vblank(wa_crtc);
1655 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1657 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1658 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1659 enum pipe pipe = crtc->pipe;
1661 /* To avoid upsetting the power well on haswell only disable the pfit if
1662 * it's in use. The hw state code will make sure we get this right. */
1663 if (!old_crtc_state->pch_pfit.enabled)
1666 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1667 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
1668 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
1671 static void ilk_crtc_disable(struct intel_atomic_state *state,
1672 struct intel_crtc *crtc)
1674 const struct intel_crtc_state *old_crtc_state =
1675 intel_atomic_get_old_crtc_state(state, crtc);
1676 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1677 enum pipe pipe = crtc->pipe;
1680 * Sometimes spurious CPU pipe underruns happen when the
1681 * pipe is already disabled, but FDI RX/TX is still enabled.
1682 * Happens at least with VGA+HDMI cloning. Suppress them.
1684 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1685 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1687 intel_encoders_disable(state, crtc);
1689 intel_crtc_vblank_off(old_crtc_state);
1691 intel_disable_transcoder(old_crtc_state);
1693 ilk_pfit_disable(old_crtc_state);
1695 if (old_crtc_state->has_pch_encoder)
1696 ilk_pch_disable(state, crtc);
1698 intel_encoders_post_disable(state, crtc);
1700 if (old_crtc_state->has_pch_encoder)
1701 ilk_pch_post_disable(state, crtc);
1703 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1704 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1706 intel_disable_shared_dpll(old_crtc_state);
1709 static void hsw_crtc_disable(struct intel_atomic_state *state,
1710 struct intel_crtc *crtc)
1712 const struct intel_crtc_state *old_crtc_state =
1713 intel_atomic_get_old_crtc_state(state, crtc);
1714 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1717 * FIXME collapse everything to one hook.
1718 * Need care with mst->ddi interactions.
1720 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1721 intel_encoders_disable(state, crtc);
1722 intel_encoders_post_disable(state, crtc);
1725 intel_disable_shared_dpll(old_crtc_state);
1727 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1728 struct intel_crtc *slave_crtc;
1730 intel_encoders_post_pll_disable(state, crtc);
1732 intel_dmc_disable_pipe(i915, crtc->pipe);
1734 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
1735 intel_crtc_bigjoiner_slave_pipes(old_crtc_state))
1736 intel_dmc_disable_pipe(i915, slave_crtc->pipe);
1740 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
1742 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1743 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1745 if (!crtc_state->gmch_pfit.control)
1749 * The panel fitter should only be adjusted whilst the pipe is disabled,
1750 * according to register description and PRM.
1752 drm_WARN_ON(&dev_priv->drm,
1753 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
1754 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1756 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
1757 crtc_state->gmch_pfit.pgm_ratios);
1758 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
1760 /* Border color in case we don't scale up to the full screen. Black by
1761 * default, change to something else for debugging. */
1762 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
1765 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
1767 if (phy == PHY_NONE)
1769 else if (IS_ALDERLAKE_S(dev_priv))
1770 return phy <= PHY_E;
1771 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
1772 return phy <= PHY_D;
1773 else if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv))
1774 return phy <= PHY_C;
1775 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
1776 return phy <= PHY_B;
1779 * DG2 outputs labelled as "combo PHY" in the bspec use
1780 * SNPS PHYs with completely different programming,
1781 * hence we always return false here.
1786 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
1789 * DG2's "TC1", although TC-capable output, doesn't share the same flow
1790 * as other platforms on the display engine side and rather rely on the
1791 * SNPS PHY, that is programmed separately
1793 if (IS_DG2(dev_priv))
1796 if (DISPLAY_VER(dev_priv) >= 13)
1797 return phy >= PHY_F && phy <= PHY_I;
1798 else if (IS_TIGERLAKE(dev_priv))
1799 return phy >= PHY_D && phy <= PHY_I;
1800 else if (IS_ICELAKE(dev_priv))
1801 return phy >= PHY_C && phy <= PHY_F;
1806 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
1809 * For DG2, and for DG2 only, all four "combo" ports and the TC1 port
1810 * (PHY E) use Synopsis PHYs. See intel_phy_is_tc().
1812 return IS_DG2(dev_priv) && phy > PHY_NONE && phy <= PHY_E;
1815 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
1817 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
1818 return PHY_D + port - PORT_D_XELPD;
1819 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
1820 return PHY_F + port - PORT_TC1;
1821 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
1822 return PHY_B + port - PORT_TC1;
1823 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
1824 return PHY_C + port - PORT_TC1;
1825 else if ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) &&
1829 return PHY_A + port - PORT_A;
1832 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
1834 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
1835 return TC_PORT_NONE;
1837 if (DISPLAY_VER(dev_priv) >= 12)
1838 return TC_PORT_1 + port - PORT_TC1;
1840 return TC_PORT_1 + port - PORT_C;
1843 enum intel_display_power_domain
1844 intel_aux_power_domain(struct intel_digital_port *dig_port)
1846 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
1848 if (intel_tc_port_in_tbt_alt_mode(dig_port))
1849 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
1851 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
1854 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1855 struct intel_power_domain_mask *mask)
1857 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1858 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1859 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1860 struct drm_encoder *encoder;
1861 enum pipe pipe = crtc->pipe;
1863 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
1865 if (!crtc_state->hw.active)
1868 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
1869 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
1870 if (crtc_state->pch_pfit.enabled ||
1871 crtc_state->pch_pfit.force_thru)
1872 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
1874 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
1875 crtc_state->uapi.encoder_mask) {
1876 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1878 set_bit(intel_encoder->power_domain, mask->bits);
1881 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
1882 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
1884 if (crtc_state->shared_dpll)
1885 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
1887 if (crtc_state->dsc.compression_enable)
1888 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
1891 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1892 struct intel_power_domain_mask *old_domains)
1894 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1895 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1896 enum intel_display_power_domain domain;
1897 struct intel_power_domain_mask domains, new_domains;
1899 get_crtc_power_domains(crtc_state, &domains);
1901 bitmap_andnot(new_domains.bits,
1903 crtc->enabled_power_domains.mask.bits,
1905 bitmap_andnot(old_domains->bits,
1906 crtc->enabled_power_domains.mask.bits,
1910 for_each_power_domain(domain, &new_domains)
1911 intel_display_power_get_in_set(dev_priv,
1912 &crtc->enabled_power_domains,
1916 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
1917 struct intel_power_domain_mask *domains)
1919 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
1920 &crtc->enabled_power_domains,
1924 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1926 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1927 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1929 if (intel_crtc_has_dp_encoder(crtc_state)) {
1930 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1931 &crtc_state->dp_m_n);
1932 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1933 &crtc_state->dp_m2_n2);
1936 intel_set_transcoder_timings(crtc_state);
1938 i9xx_set_pipeconf(crtc_state);
1941 static void valleyview_crtc_enable(struct intel_atomic_state *state,
1942 struct intel_crtc *crtc)
1944 const struct intel_crtc_state *new_crtc_state =
1945 intel_atomic_get_new_crtc_state(state, crtc);
1946 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1947 enum pipe pipe = crtc->pipe;
1949 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1952 i9xx_configure_cpu_transcoder(new_crtc_state);
1954 intel_set_pipe_src_size(new_crtc_state);
1956 intel_de_write(dev_priv, VLV_PIPE_MSA_MISC(pipe), 0);
1958 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1959 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
1960 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
1963 crtc->active = true;
1965 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1967 intel_encoders_pre_pll_enable(state, crtc);
1969 if (IS_CHERRYVIEW(dev_priv))
1970 chv_enable_pll(new_crtc_state);
1972 vlv_enable_pll(new_crtc_state);
1974 intel_encoders_pre_enable(state, crtc);
1976 i9xx_pfit_enable(new_crtc_state);
1978 intel_color_load_luts(new_crtc_state);
1979 intel_color_commit_noarm(new_crtc_state);
1980 intel_color_commit_arm(new_crtc_state);
1981 /* update DSPCNTR to configure gamma for pipe bottom color */
1982 intel_disable_primary_plane(new_crtc_state);
1984 intel_initial_watermarks(state, crtc);
1985 intel_enable_transcoder(new_crtc_state);
1987 intel_crtc_vblank_on(new_crtc_state);
1989 intel_encoders_enable(state, crtc);
1992 static void i9xx_crtc_enable(struct intel_atomic_state *state,
1993 struct intel_crtc *crtc)
1995 const struct intel_crtc_state *new_crtc_state =
1996 intel_atomic_get_new_crtc_state(state, crtc);
1997 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1998 enum pipe pipe = crtc->pipe;
2000 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2003 i9xx_configure_cpu_transcoder(new_crtc_state);
2005 intel_set_pipe_src_size(new_crtc_state);
2007 crtc->active = true;
2009 if (DISPLAY_VER(dev_priv) != 2)
2010 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2012 intel_encoders_pre_enable(state, crtc);
2014 i9xx_enable_pll(new_crtc_state);
2016 i9xx_pfit_enable(new_crtc_state);
2018 intel_color_load_luts(new_crtc_state);
2019 intel_color_commit_noarm(new_crtc_state);
2020 intel_color_commit_arm(new_crtc_state);
2021 /* update DSPCNTR to configure gamma for pipe bottom color */
2022 intel_disable_primary_plane(new_crtc_state);
2024 if (!intel_initial_watermarks(state, crtc))
2025 intel_update_watermarks(dev_priv);
2026 intel_enable_transcoder(new_crtc_state);
2028 intel_crtc_vblank_on(new_crtc_state);
2030 intel_encoders_enable(state, crtc);
2032 /* prevents spurious underruns */
2033 if (DISPLAY_VER(dev_priv) == 2)
2034 intel_crtc_wait_for_next_vblank(crtc);
2037 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2039 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2040 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2042 if (!old_crtc_state->gmch_pfit.control)
2045 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2047 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2048 intel_de_read(dev_priv, PFIT_CONTROL));
2049 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2052 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2053 struct intel_crtc *crtc)
2055 struct intel_crtc_state *old_crtc_state =
2056 intel_atomic_get_old_crtc_state(state, crtc);
2057 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2058 enum pipe pipe = crtc->pipe;
2061 * On gen2 planes are double buffered but the pipe isn't, so we must
2062 * wait for planes to fully turn off before disabling the pipe.
2064 if (DISPLAY_VER(dev_priv) == 2)
2065 intel_crtc_wait_for_next_vblank(crtc);
2067 intel_encoders_disable(state, crtc);
2069 intel_crtc_vblank_off(old_crtc_state);
2071 intel_disable_transcoder(old_crtc_state);
2073 i9xx_pfit_disable(old_crtc_state);
2075 intel_encoders_post_disable(state, crtc);
2077 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2078 if (IS_CHERRYVIEW(dev_priv))
2079 chv_disable_pll(dev_priv, pipe);
2080 else if (IS_VALLEYVIEW(dev_priv))
2081 vlv_disable_pll(dev_priv, pipe);
2083 i9xx_disable_pll(old_crtc_state);
2086 intel_encoders_post_pll_disable(state, crtc);
2088 if (DISPLAY_VER(dev_priv) != 2)
2089 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2091 if (!dev_priv->display.funcs.wm->initial_watermarks)
2092 intel_update_watermarks(dev_priv);
2094 /* clock the pipe down to 640x480@60 to potentially save power */
2095 if (IS_I830(dev_priv))
2096 i830_enable_pipe(dev_priv, pipe);
2099 void intel_encoder_destroy(struct drm_encoder *encoder)
2101 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2103 drm_encoder_cleanup(encoder);
2104 kfree(intel_encoder);
2107 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2109 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2111 /* GDG double wide on either pipe, otherwise pipe A only */
2112 return DISPLAY_VER(dev_priv) < 4 &&
2113 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2116 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2118 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2119 struct drm_rect src;
2122 * We only use IF-ID interlacing. If we ever use
2123 * PF-ID we'll need to adjust the pixel_rate here.
2126 if (!crtc_state->pch_pfit.enabled)
2129 drm_rect_init(&src, 0, 0,
2130 drm_rect_width(&crtc_state->pipe_src) << 16,
2131 drm_rect_height(&crtc_state->pipe_src) << 16);
2133 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2137 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2138 const struct drm_display_mode *timings)
2140 mode->hdisplay = timings->crtc_hdisplay;
2141 mode->htotal = timings->crtc_htotal;
2142 mode->hsync_start = timings->crtc_hsync_start;
2143 mode->hsync_end = timings->crtc_hsync_end;
2145 mode->vdisplay = timings->crtc_vdisplay;
2146 mode->vtotal = timings->crtc_vtotal;
2147 mode->vsync_start = timings->crtc_vsync_start;
2148 mode->vsync_end = timings->crtc_vsync_end;
2150 mode->flags = timings->flags;
2151 mode->type = DRM_MODE_TYPE_DRIVER;
2153 mode->clock = timings->crtc_clock;
2155 drm_mode_set_name(mode);
2158 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2160 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2162 if (HAS_GMCH(dev_priv))
2163 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2164 crtc_state->pixel_rate =
2165 crtc_state->hw.pipe_mode.crtc_clock;
2167 crtc_state->pixel_rate =
2168 ilk_pipe_pixel_rate(crtc_state);
2171 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2172 struct drm_display_mode *mode)
2174 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2179 mode->crtc_clock /= num_pipes;
2180 mode->crtc_hdisplay /= num_pipes;
2181 mode->crtc_hblank_start /= num_pipes;
2182 mode->crtc_hblank_end /= num_pipes;
2183 mode->crtc_hsync_start /= num_pipes;
2184 mode->crtc_hsync_end /= num_pipes;
2185 mode->crtc_htotal /= num_pipes;
2188 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2189 struct drm_display_mode *mode)
2191 int overlap = crtc_state->splitter.pixel_overlap;
2192 int n = crtc_state->splitter.link_count;
2194 if (!crtc_state->splitter.enable)
2198 * eDP MSO uses segment timings from EDID for transcoder
2199 * timings, but full mode for everything else.
2201 * h_full = (h_segment - pixel_overlap) * link_count
2203 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2204 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2205 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2206 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2207 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2208 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2209 mode->crtc_clock *= n;
2212 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2214 struct drm_display_mode *mode = &crtc_state->hw.mode;
2215 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2216 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2219 * Start with the adjusted_mode crtc timings, which
2220 * have been filled with the transcoder timings.
2222 drm_mode_copy(pipe_mode, adjusted_mode);
2224 /* Expand MSO per-segment transcoder timings to full */
2225 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2228 * We want the full numbers in adjusted_mode normal timings,
2229 * adjusted_mode crtc timings are left with the raw transcoder
2232 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2234 /* Populate the "user" mode with full numbers */
2235 drm_mode_copy(mode, pipe_mode);
2236 intel_mode_from_crtc_timings(mode, mode);
2237 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2238 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2239 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2241 /* Derive per-pipe timings in case bigjoiner is used */
2242 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2243 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2245 intel_crtc_compute_pixel_rate(crtc_state);
2248 void intel_encoder_get_config(struct intel_encoder *encoder,
2249 struct intel_crtc_state *crtc_state)
2251 encoder->get_config(encoder, crtc_state);
2253 intel_crtc_readout_derived_state(crtc_state);
2256 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2258 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2264 width = drm_rect_width(&crtc_state->pipe_src);
2265 height = drm_rect_height(&crtc_state->pipe_src);
2267 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2268 width / num_pipes, height);
2271 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2273 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2274 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2276 intel_bigjoiner_compute_pipe_src(crtc_state);
2279 * Pipe horizontal size must be even in:
2281 * - LVDS dual channel mode
2282 * - Double wide pipe
2284 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2285 if (crtc_state->double_wide) {
2286 drm_dbg_kms(&i915->drm,
2287 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2288 crtc->base.base.id, crtc->base.name);
2292 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2293 intel_is_dual_link_lvds(i915)) {
2294 drm_dbg_kms(&i915->drm,
2295 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2296 crtc->base.base.id, crtc->base.name);
2304 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2306 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2307 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2308 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2309 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2310 int clock_limit = i915->max_dotclk_freq;
2313 * Start with the adjusted_mode crtc timings, which
2314 * have been filled with the transcoder timings.
2316 drm_mode_copy(pipe_mode, adjusted_mode);
2318 /* Expand MSO per-segment transcoder timings to full */
2319 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2321 /* Derive per-pipe timings in case bigjoiner is used */
2322 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2323 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2325 if (DISPLAY_VER(i915) < 4) {
2326 clock_limit = i915->display.cdclk.max_cdclk_freq * 9 / 10;
2329 * Enable double wide mode when the dot clock
2330 * is > 90% of the (display) core speed.
2332 if (intel_crtc_supports_double_wide(crtc) &&
2333 pipe_mode->crtc_clock > clock_limit) {
2334 clock_limit = i915->max_dotclk_freq;
2335 crtc_state->double_wide = true;
2339 if (pipe_mode->crtc_clock > clock_limit) {
2340 drm_dbg_kms(&i915->drm,
2341 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2342 crtc->base.base.id, crtc->base.name,
2343 pipe_mode->crtc_clock, clock_limit,
2344 str_yes_no(crtc_state->double_wide));
2351 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2352 struct intel_crtc *crtc)
2354 struct intel_crtc_state *crtc_state =
2355 intel_atomic_get_new_crtc_state(state, crtc);
2358 ret = intel_dpll_crtc_compute_clock(state, crtc);
2362 ret = intel_crtc_compute_pipe_src(crtc_state);
2366 ret = intel_crtc_compute_pipe_mode(crtc_state);
2370 intel_crtc_compute_pixel_rate(crtc_state);
2372 if (crtc_state->has_pch_encoder)
2373 return ilk_fdi_compute_config(crtc, crtc_state);
2379 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2381 while (*num > DATA_LINK_M_N_MASK ||
2382 *den > DATA_LINK_M_N_MASK) {
2388 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2389 u32 m, u32 n, u32 constant_n)
2392 *ret_n = constant_n;
2394 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2396 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2397 intel_reduce_m_n_ratio(ret_m, ret_n);
2401 intel_link_compute_m_n(u16 bits_per_pixel_x16, int nlanes,
2402 int pixel_clock, int link_clock,
2404 struct intel_link_m_n *m_n)
2406 u32 link_symbol_clock = intel_dp_link_symbol_clock(link_clock);
2407 u32 data_m = intel_dp_effective_data_rate(pixel_clock, bits_per_pixel_x16,
2409 u32 data_n = intel_dp_max_data_rate(link_clock, nlanes);
2412 * Windows/BIOS uses fixed M/N values always. Follow suit.
2414 * Also several DP dongles in particular seem to be fussy
2415 * about too large link M/N values. Presumably the 20bit
2416 * value used by Windows/BIOS is acceptable to everyone.
2419 compute_m_n(&m_n->data_m, &m_n->data_n,
2423 compute_m_n(&m_n->link_m, &m_n->link_n,
2424 pixel_clock, link_symbol_clock,
2428 void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2431 * There may be no VBT; and if the BIOS enabled SSC we can
2432 * just keep using it to avoid unnecessary flicker. Whereas if the
2433 * BIOS isn't using it, don't assume it will work even if the VBT
2434 * indicates as much.
2436 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2437 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2441 if (dev_priv->display.vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2442 drm_dbg_kms(&dev_priv->drm,
2443 "SSC %s by BIOS, overriding VBT which says %s\n",
2444 str_enabled_disabled(bios_lvds_use_ssc),
2445 str_enabled_disabled(dev_priv->display.vbt.lvds_use_ssc));
2446 dev_priv->display.vbt.lvds_use_ssc = bios_lvds_use_ssc;
2451 void intel_zero_m_n(struct intel_link_m_n *m_n)
2453 /* corresponds to 0 register value */
2454 memset(m_n, 0, sizeof(*m_n));
2458 void intel_set_m_n(struct drm_i915_private *i915,
2459 const struct intel_link_m_n *m_n,
2460 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2461 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2463 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2464 intel_de_write(i915, data_n_reg, m_n->data_n);
2465 intel_de_write(i915, link_m_reg, m_n->link_m);
2467 * On BDW+ writing LINK_N arms the double buffered update
2468 * of all the M/N registers, so it must be written last.
2470 intel_de_write(i915, link_n_reg, m_n->link_n);
2473 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2474 enum transcoder transcoder)
2476 if (IS_HASWELL(dev_priv))
2477 return transcoder == TRANSCODER_EDP;
2479 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2482 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2483 enum transcoder transcoder,
2484 const struct intel_link_m_n *m_n)
2486 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2487 enum pipe pipe = crtc->pipe;
2489 if (DISPLAY_VER(dev_priv) >= 5)
2490 intel_set_m_n(dev_priv, m_n,
2491 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2492 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2494 intel_set_m_n(dev_priv, m_n,
2495 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2496 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2499 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2500 enum transcoder transcoder,
2501 const struct intel_link_m_n *m_n)
2503 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2505 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2508 intel_set_m_n(dev_priv, m_n,
2509 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2510 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2513 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2515 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2517 enum pipe pipe = crtc->pipe;
2518 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2519 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2520 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2523 /* We need to be careful not to changed the adjusted mode, for otherwise
2524 * the hw state checker will get angry at the mismatch. */
2525 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2526 crtc_vtotal = adjusted_mode->crtc_vtotal;
2527 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2528 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2530 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2531 /* the chip adds 2 halflines automatically */
2533 crtc_vblank_end -= 1;
2535 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2536 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2538 vsyncshift = adjusted_mode->crtc_hsync_start -
2539 adjusted_mode->crtc_htotal / 2;
2541 vsyncshift += adjusted_mode->crtc_htotal;
2545 * VBLANK_START no longer works on ADL+, instead we must use
2546 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2548 if (DISPLAY_VER(dev_priv) >= 13) {
2549 intel_de_write(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder),
2550 crtc_vblank_start - crtc_vdisplay);
2553 * VBLANK_START not used by hw, just clear it
2554 * to make it stand out in register dumps.
2556 crtc_vblank_start = 1;
2559 if (DISPLAY_VER(dev_priv) > 3)
2560 intel_de_write(dev_priv, TRANS_VSYNCSHIFT(cpu_transcoder),
2563 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
2564 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2565 HTOTAL(adjusted_mode->crtc_htotal - 1));
2566 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
2567 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2568 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2569 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
2570 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2571 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2573 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2574 VACTIVE(crtc_vdisplay - 1) |
2575 VTOTAL(crtc_vtotal - 1));
2576 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2577 VBLANK_START(crtc_vblank_start - 1) |
2578 VBLANK_END(crtc_vblank_end - 1));
2579 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
2580 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2581 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2583 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2584 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2585 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2587 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2588 (pipe == PIPE_B || pipe == PIPE_C))
2589 intel_de_write(dev_priv, TRANS_VTOTAL(pipe),
2590 VACTIVE(crtc_vdisplay - 1) |
2591 VTOTAL(crtc_vtotal - 1));
2594 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state)
2596 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2597 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2598 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2599 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2600 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2602 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2603 crtc_vtotal = adjusted_mode->crtc_vtotal;
2604 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2605 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2607 drm_WARN_ON(&dev_priv->drm, adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE);
2610 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode.
2611 * But let's write it anyway to keep the state checker happy.
2613 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2614 VBLANK_START(crtc_vblank_start - 1) |
2615 VBLANK_END(crtc_vblank_end - 1));
2617 * The double buffer latch point for TRANS_VTOTAL
2618 * is the transcoder's undelayed vblank.
2620 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2621 VACTIVE(crtc_vdisplay - 1) |
2622 VTOTAL(crtc_vtotal - 1));
2625 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2627 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2628 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2629 int width = drm_rect_width(&crtc_state->pipe_src);
2630 int height = drm_rect_height(&crtc_state->pipe_src);
2631 enum pipe pipe = crtc->pipe;
2633 /* pipesrc controls the size that is scaled from, which should
2634 * always be the user's requested size.
2636 intel_de_write(dev_priv, PIPESRC(pipe),
2637 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2640 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2642 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2643 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2645 if (DISPLAY_VER(dev_priv) == 2)
2648 if (DISPLAY_VER(dev_priv) >= 9 ||
2649 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2650 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2652 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2655 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2656 struct intel_crtc_state *pipe_config)
2658 struct drm_device *dev = crtc->base.dev;
2659 struct drm_i915_private *dev_priv = to_i915(dev);
2660 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2661 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2664 tmp = intel_de_read(dev_priv, TRANS_HTOTAL(cpu_transcoder));
2665 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2666 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2668 if (!transcoder_is_dsi(cpu_transcoder)) {
2669 tmp = intel_de_read(dev_priv, TRANS_HBLANK(cpu_transcoder));
2670 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2671 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2674 tmp = intel_de_read(dev_priv, TRANS_HSYNC(cpu_transcoder));
2675 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2676 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2678 tmp = intel_de_read(dev_priv, TRANS_VTOTAL(cpu_transcoder));
2679 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2680 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2682 /* FIXME TGL+ DSI transcoders have this! */
2683 if (!transcoder_is_dsi(cpu_transcoder)) {
2684 tmp = intel_de_read(dev_priv, TRANS_VBLANK(cpu_transcoder));
2685 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2686 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2688 tmp = intel_de_read(dev_priv, TRANS_VSYNC(cpu_transcoder));
2689 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2690 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2692 if (intel_pipe_is_interlaced(pipe_config)) {
2693 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2694 adjusted_mode->crtc_vtotal += 1;
2695 adjusted_mode->crtc_vblank_end += 1;
2698 if (DISPLAY_VER(dev_priv) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2699 adjusted_mode->crtc_vblank_start =
2700 adjusted_mode->crtc_vdisplay +
2701 intel_de_read(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder));
2704 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2706 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2707 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2708 enum pipe master_pipe, pipe = crtc->pipe;
2714 master_pipe = bigjoiner_master_pipe(crtc_state);
2715 width = drm_rect_width(&crtc_state->pipe_src);
2717 drm_rect_translate_to(&crtc_state->pipe_src,
2718 (pipe - master_pipe) * width, 0);
2721 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2722 struct intel_crtc_state *pipe_config)
2724 struct drm_device *dev = crtc->base.dev;
2725 struct drm_i915_private *dev_priv = to_i915(dev);
2728 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
2730 drm_rect_init(&pipe_config->pipe_src, 0, 0,
2731 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
2732 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
2734 intel_bigjoiner_adjust_pipe_src(pipe_config);
2737 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
2739 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2740 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2741 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2745 * - We keep both pipes enabled on 830
2746 * - During modeset the pipe is still disabled and must remain so
2747 * - During fastset the pipe is already enabled and must remain so
2749 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
2750 val |= TRANSCONF_ENABLE;
2752 if (crtc_state->double_wide)
2753 val |= TRANSCONF_DOUBLE_WIDE;
2755 /* only g4x and later have fancy bpc/dither controls */
2756 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2757 IS_CHERRYVIEW(dev_priv)) {
2758 /* Bspec claims that we can't use dithering for 30bpp pipes. */
2759 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
2760 val |= TRANSCONF_DITHER_EN |
2761 TRANSCONF_DITHER_TYPE_SP;
2763 switch (crtc_state->pipe_bpp) {
2765 /* Case prevented by intel_choose_pipe_bpp_dither. */
2766 MISSING_CASE(crtc_state->pipe_bpp);
2769 val |= TRANSCONF_BPC_6;
2772 val |= TRANSCONF_BPC_8;
2775 val |= TRANSCONF_BPC_10;
2780 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
2781 if (DISPLAY_VER(dev_priv) < 4 ||
2782 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2783 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
2785 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
2787 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
2790 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2791 crtc_state->limited_color_range)
2792 val |= TRANSCONF_COLOR_RANGE_SELECT;
2794 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
2796 if (crtc_state->wgc_enable)
2797 val |= TRANSCONF_WGC_ENABLE;
2799 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
2801 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
2802 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
2805 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
2807 if (IS_I830(dev_priv))
2810 return DISPLAY_VER(dev_priv) >= 4 ||
2811 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
2814 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
2816 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2817 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2821 if (!i9xx_has_pfit(dev_priv))
2824 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
2825 if (!(tmp & PFIT_ENABLE))
2828 /* Check whether the pfit is attached to our pipe. */
2829 if (DISPLAY_VER(dev_priv) >= 4)
2830 pipe = REG_FIELD_GET(PFIT_PIPE_MASK, tmp);
2834 if (pipe != crtc->pipe)
2837 crtc_state->gmch_pfit.control = tmp;
2838 crtc_state->gmch_pfit.pgm_ratios =
2839 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
2842 static enum intel_output_format
2843 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
2845 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2848 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
2850 if (tmp & PIPE_MISC_YUV420_ENABLE) {
2851 /* We support 4:2:0 in full blend mode only */
2852 drm_WARN_ON(&dev_priv->drm,
2853 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
2855 return INTEL_OUTPUT_FORMAT_YCBCR420;
2856 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
2857 return INTEL_OUTPUT_FORMAT_YCBCR444;
2859 return INTEL_OUTPUT_FORMAT_RGB;
2863 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
2864 struct intel_crtc_state *pipe_config)
2866 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2867 enum intel_display_power_domain power_domain;
2868 intel_wakeref_t wakeref;
2872 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
2873 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
2877 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2878 pipe_config->sink_format = pipe_config->output_format;
2879 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
2880 pipe_config->shared_dpll = NULL;
2884 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
2885 if (!(tmp & TRANSCONF_ENABLE))
2888 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2889 IS_CHERRYVIEW(dev_priv)) {
2890 switch (tmp & TRANSCONF_BPC_MASK) {
2891 case TRANSCONF_BPC_6:
2892 pipe_config->pipe_bpp = 18;
2894 case TRANSCONF_BPC_8:
2895 pipe_config->pipe_bpp = 24;
2897 case TRANSCONF_BPC_10:
2898 pipe_config->pipe_bpp = 30;
2906 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2907 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
2908 pipe_config->limited_color_range = true;
2910 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
2912 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
2914 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2915 (tmp & TRANSCONF_WGC_ENABLE))
2916 pipe_config->wgc_enable = true;
2918 intel_color_get_config(pipe_config);
2920 if (DISPLAY_VER(dev_priv) < 4)
2921 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
2923 intel_get_transcoder_timings(crtc, pipe_config);
2924 intel_get_pipe_src_size(crtc, pipe_config);
2926 i9xx_get_pfit_config(pipe_config);
2928 if (DISPLAY_VER(dev_priv) >= 4) {
2929 /* No way to read it out on pipes B and C */
2930 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
2931 tmp = dev_priv->display.state.chv_dpll_md[crtc->pipe];
2933 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
2934 pipe_config->pixel_multiplier =
2935 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
2936 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
2937 pipe_config->dpll_hw_state.dpll_md = tmp;
2938 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
2939 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
2940 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
2941 pipe_config->pixel_multiplier =
2942 ((tmp & SDVO_MULTIPLIER_MASK)
2943 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
2945 /* Note that on i915G/GM the pixel multiplier is in the sdvo
2946 * port and will be fixed up in the encoder->get_config
2948 pipe_config->pixel_multiplier = 1;
2950 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
2952 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
2953 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
2955 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
2958 /* Mask out read-only status bits. */
2959 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
2960 DPLL_PORTC_READY_MASK |
2961 DPLL_PORTB_READY_MASK);
2964 if (IS_CHERRYVIEW(dev_priv))
2965 chv_crtc_clock_get(crtc, pipe_config);
2966 else if (IS_VALLEYVIEW(dev_priv))
2967 vlv_crtc_clock_get(crtc, pipe_config);
2969 i9xx_crtc_clock_get(crtc, pipe_config);
2972 * Normally the dotclock is filled in by the encoder .get_config()
2973 * but in case the pipe is enabled w/o any ports we need a sane
2976 pipe_config->hw.adjusted_mode.crtc_clock =
2977 pipe_config->port_clock / pipe_config->pixel_multiplier;
2982 intel_display_power_put(dev_priv, power_domain, wakeref);
2987 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
2989 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2990 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2991 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2995 * - During modeset the pipe is still disabled and must remain so
2996 * - During fastset the pipe is already enabled and must remain so
2998 if (!intel_crtc_needs_modeset(crtc_state))
2999 val |= TRANSCONF_ENABLE;
3001 switch (crtc_state->pipe_bpp) {
3003 /* Case prevented by intel_choose_pipe_bpp_dither. */
3004 MISSING_CASE(crtc_state->pipe_bpp);
3007 val |= TRANSCONF_BPC_6;
3010 val |= TRANSCONF_BPC_8;
3013 val |= TRANSCONF_BPC_10;
3016 val |= TRANSCONF_BPC_12;
3020 if (crtc_state->dither)
3021 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3023 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3024 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3026 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3029 * This would end up with an odd purple hue over
3030 * the entire display. Make sure we don't do it.
3032 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3033 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3035 if (crtc_state->limited_color_range &&
3036 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3037 val |= TRANSCONF_COLOR_RANGE_SELECT;
3039 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3040 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3042 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3044 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3045 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3047 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3048 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3051 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3053 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3054 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3055 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3059 * - During modeset the pipe is still disabled and must remain so
3060 * - During fastset the pipe is already enabled and must remain so
3062 if (!intel_crtc_needs_modeset(crtc_state))
3063 val |= TRANSCONF_ENABLE;
3065 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3066 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3068 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3069 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3071 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3073 if (IS_HASWELL(dev_priv) &&
3074 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3075 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3077 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3078 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3081 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state)
3083 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3084 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3087 switch (crtc_state->pipe_bpp) {
3089 val |= PIPE_MISC_BPC_6;
3092 val |= PIPE_MISC_BPC_8;
3095 val |= PIPE_MISC_BPC_10;
3098 /* Port output 12BPC defined for ADLP+ */
3099 if (DISPLAY_VER(dev_priv) > 12)
3100 val |= PIPE_MISC_BPC_12_ADLP;
3103 MISSING_CASE(crtc_state->pipe_bpp);
3107 if (crtc_state->dither)
3108 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3110 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3111 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3112 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3114 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3115 val |= PIPE_MISC_YUV420_ENABLE |
3116 PIPE_MISC_YUV420_MODE_FULL_BLEND;
3118 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3119 val |= PIPE_MISC_HDR_MODE_PRECISION;
3121 if (DISPLAY_VER(dev_priv) >= 12)
3122 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3124 /* allow PSR with sprite enabled */
3125 if (IS_BROADWELL(dev_priv))
3126 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE;
3128 intel_de_write(dev_priv, PIPE_MISC(crtc->pipe), val);
3131 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3133 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3136 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3138 switch (tmp & PIPE_MISC_BPC_MASK) {
3139 case PIPE_MISC_BPC_6:
3141 case PIPE_MISC_BPC_8:
3143 case PIPE_MISC_BPC_10:
3146 * PORT OUTPUT 12 BPC defined for ADLP+.
3149 * For previous platforms with DSI interface, bits 5:7
3150 * are used for storing pipe_bpp irrespective of dithering.
3151 * Since the value of 12 BPC is not defined for these bits
3152 * on older platforms, need to find a workaround for 12 BPC
3153 * MIPI DSI HW readout.
3155 case PIPE_MISC_BPC_12_ADLP:
3156 if (DISPLAY_VER(dev_priv) > 12)
3165 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3168 * Account for spread spectrum to avoid
3169 * oversubscribing the link. Max center spread
3170 * is 2.5%; use 5% for safety's sake.
3172 u32 bps = target_clock * bpp * 21 / 20;
3173 return DIV_ROUND_UP(bps, link_bw * 8);
3176 void intel_get_m_n(struct drm_i915_private *i915,
3177 struct intel_link_m_n *m_n,
3178 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3179 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3181 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3182 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3183 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3184 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3185 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3188 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3189 enum transcoder transcoder,
3190 struct intel_link_m_n *m_n)
3192 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3193 enum pipe pipe = crtc->pipe;
3195 if (DISPLAY_VER(dev_priv) >= 5)
3196 intel_get_m_n(dev_priv, m_n,
3197 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3198 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3200 intel_get_m_n(dev_priv, m_n,
3201 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3202 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3205 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3206 enum transcoder transcoder,
3207 struct intel_link_m_n *m_n)
3209 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3211 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3214 intel_get_m_n(dev_priv, m_n,
3215 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3216 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3219 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3221 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3222 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3226 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3227 if ((ctl & PF_ENABLE) == 0)
3230 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
3231 pipe = REG_FIELD_GET(PF_PIPE_SEL_MASK_IVB, ctl);
3235 crtc_state->pch_pfit.enabled = true;
3237 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3238 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3240 drm_rect_init(&crtc_state->pch_pfit.dst,
3241 REG_FIELD_GET(PF_WIN_XPOS_MASK, pos),
3242 REG_FIELD_GET(PF_WIN_YPOS_MASK, pos),
3243 REG_FIELD_GET(PF_WIN_XSIZE_MASK, size),
3244 REG_FIELD_GET(PF_WIN_YSIZE_MASK, size));
3247 * We currently do not free assignements of panel fitters on
3248 * ivb/hsw (since we don't use the higher upscaling modes which
3249 * differentiates them) so just WARN about this case for now.
3251 drm_WARN_ON(&dev_priv->drm, pipe != crtc->pipe);
3254 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3255 struct intel_crtc_state *pipe_config)
3257 struct drm_device *dev = crtc->base.dev;
3258 struct drm_i915_private *dev_priv = to_i915(dev);
3259 enum intel_display_power_domain power_domain;
3260 intel_wakeref_t wakeref;
3264 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3265 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3269 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3270 pipe_config->shared_dpll = NULL;
3273 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3274 if (!(tmp & TRANSCONF_ENABLE))
3277 switch (tmp & TRANSCONF_BPC_MASK) {
3278 case TRANSCONF_BPC_6:
3279 pipe_config->pipe_bpp = 18;
3281 case TRANSCONF_BPC_8:
3282 pipe_config->pipe_bpp = 24;
3284 case TRANSCONF_BPC_10:
3285 pipe_config->pipe_bpp = 30;
3287 case TRANSCONF_BPC_12:
3288 pipe_config->pipe_bpp = 36;
3294 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3295 pipe_config->limited_color_range = true;
3297 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3298 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3299 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3300 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3303 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3307 pipe_config->sink_format = pipe_config->output_format;
3309 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3311 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3313 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3315 intel_color_get_config(pipe_config);
3317 pipe_config->pixel_multiplier = 1;
3319 ilk_pch_get_config(pipe_config);
3321 intel_get_transcoder_timings(crtc, pipe_config);
3322 intel_get_pipe_src_size(crtc, pipe_config);
3324 ilk_get_pfit_config(pipe_config);
3329 intel_display_power_put(dev_priv, power_domain, wakeref);
3334 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3338 if (DISPLAY_VER(i915) >= 12)
3339 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3340 else if (DISPLAY_VER(i915) >= 11)
3341 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3345 return pipes & DISPLAY_RUNTIME_INFO(i915)->pipe_mask;
3348 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3349 enum transcoder cpu_transcoder)
3351 enum intel_display_power_domain power_domain;
3352 intel_wakeref_t wakeref;
3355 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3357 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3358 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3360 return tmp & TRANS_DDI_FUNC_ENABLE;
3363 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3364 u8 *master_pipes, u8 *slave_pipes)
3366 struct intel_crtc *crtc;
3371 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3372 bigjoiner_pipes(dev_priv)) {
3373 enum intel_display_power_domain power_domain;
3374 enum pipe pipe = crtc->pipe;
3375 intel_wakeref_t wakeref;
3377 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3378 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3379 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3381 if (!(tmp & BIG_JOINER_ENABLE))
3384 if (tmp & MASTER_BIG_JOINER_ENABLE)
3385 *master_pipes |= BIT(pipe);
3387 *slave_pipes |= BIT(pipe);
3390 if (DISPLAY_VER(dev_priv) < 13)
3393 power_domain = POWER_DOMAIN_PIPE(pipe);
3394 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3395 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3397 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3398 *master_pipes |= BIT(pipe);
3399 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3400 *slave_pipes |= BIT(pipe);
3404 /* Bigjoiner pipes should always be consecutive master and slave */
3405 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3406 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3407 *master_pipes, *slave_pipes);
3410 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3412 if ((slave_pipes & BIT(pipe)) == 0)
3415 /* ignore everything above our pipe */
3416 master_pipes &= ~GENMASK(7, pipe);
3418 /* highest remaining bit should be our master pipe */
3419 return fls(master_pipes) - 1;
3422 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3424 enum pipe master_pipe, next_master_pipe;
3426 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3428 if ((master_pipes & BIT(master_pipe)) == 0)
3431 /* ignore our master pipe and everything below it */
3432 master_pipes &= ~GENMASK(master_pipe, 0);
3433 /* make sure a high bit is set for the ffs() */
3434 master_pipes |= BIT(7);
3435 /* lowest remaining bit should be the next master pipe */
3436 next_master_pipe = ffs(master_pipes) - 1;
3438 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3441 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3443 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3445 if (DISPLAY_VER(i915) >= 11)
3446 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3448 return panel_transcoder_mask;
3451 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3453 struct drm_device *dev = crtc->base.dev;
3454 struct drm_i915_private *dev_priv = to_i915(dev);
3455 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3456 enum transcoder cpu_transcoder;
3457 u8 master_pipes, slave_pipes;
3458 u8 enabled_transcoders = 0;
3461 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3462 * consistency and less surprising code; it's in always on power).
3464 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3465 panel_transcoder_mask) {
3466 enum intel_display_power_domain power_domain;
3467 intel_wakeref_t wakeref;
3468 enum pipe trans_pipe;
3471 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3472 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3473 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3475 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3478 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3481 "unknown pipe linked to transcoder %s\n",
3482 transcoder_name(cpu_transcoder));
3484 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3485 case TRANS_DDI_EDP_INPUT_A_ON:
3486 trans_pipe = PIPE_A;
3488 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3489 trans_pipe = PIPE_B;
3491 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3492 trans_pipe = PIPE_C;
3494 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3495 trans_pipe = PIPE_D;
3499 if (trans_pipe == crtc->pipe)
3500 enabled_transcoders |= BIT(cpu_transcoder);
3503 /* single pipe or bigjoiner master */
3504 cpu_transcoder = (enum transcoder) crtc->pipe;
3505 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3506 enabled_transcoders |= BIT(cpu_transcoder);
3508 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3509 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3510 if (slave_pipes & BIT(crtc->pipe)) {
3511 cpu_transcoder = (enum transcoder)
3512 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3513 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3514 enabled_transcoders |= BIT(cpu_transcoder);
3517 return enabled_transcoders;
3520 static bool has_edp_transcoders(u8 enabled_transcoders)
3522 return enabled_transcoders & BIT(TRANSCODER_EDP);
3525 static bool has_dsi_transcoders(u8 enabled_transcoders)
3527 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3528 BIT(TRANSCODER_DSI_1));
3531 static bool has_pipe_transcoders(u8 enabled_transcoders)
3533 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3534 BIT(TRANSCODER_DSI_0) |
3535 BIT(TRANSCODER_DSI_1));
3538 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3539 u8 enabled_transcoders)
3541 /* Only one type of transcoder please */
3542 drm_WARN_ON(&i915->drm,
3543 has_edp_transcoders(enabled_transcoders) +
3544 has_dsi_transcoders(enabled_transcoders) +
3545 has_pipe_transcoders(enabled_transcoders) > 1);
3547 /* Only DSI transcoders can be ganged */
3548 drm_WARN_ON(&i915->drm,
3549 !has_dsi_transcoders(enabled_transcoders) &&
3550 !is_power_of_2(enabled_transcoders));
3553 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3554 struct intel_crtc_state *pipe_config,
3555 struct intel_display_power_domain_set *power_domain_set)
3557 struct drm_device *dev = crtc->base.dev;
3558 struct drm_i915_private *dev_priv = to_i915(dev);
3559 unsigned long enabled_transcoders;
3562 enabled_transcoders = hsw_enabled_transcoders(crtc);
3563 if (!enabled_transcoders)
3566 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3569 * With the exception of DSI we should only ever have
3570 * a single enabled transcoder. With DSI let's just
3571 * pick the first one.
3573 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3575 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3576 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3579 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3580 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3582 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3583 pipe_config->pch_pfit.force_thru = true;
3586 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3588 return tmp & TRANSCONF_ENABLE;
3591 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3592 struct intel_crtc_state *pipe_config,
3593 struct intel_display_power_domain_set *power_domain_set)
3595 struct drm_device *dev = crtc->base.dev;
3596 struct drm_i915_private *dev_priv = to_i915(dev);
3597 enum transcoder cpu_transcoder;
3601 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3603 cpu_transcoder = TRANSCODER_DSI_A;
3605 cpu_transcoder = TRANSCODER_DSI_C;
3607 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3608 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3612 * The PLL needs to be enabled with a valid divider
3613 * configuration, otherwise accessing DSI registers will hang
3614 * the machine. See BSpec North Display Engine
3615 * registers/MIPI[BXT]. We can break out here early, since we
3616 * need the same DSI PLL to be enabled for both DSI ports.
3618 if (!bxt_dsi_pll_is_enabled(dev_priv))
3621 /* XXX: this works for video mode only */
3622 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
3623 if (!(tmp & DPI_ENABLE))
3626 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
3627 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
3630 pipe_config->cpu_transcoder = cpu_transcoder;
3634 return transcoder_is_dsi(pipe_config->cpu_transcoder);
3637 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
3639 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3640 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3641 u8 master_pipes, slave_pipes;
3642 enum pipe pipe = crtc->pipe;
3644 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
3646 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
3649 crtc_state->bigjoiner_pipes =
3650 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
3651 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
3654 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
3655 struct intel_crtc_state *pipe_config)
3657 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3661 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3662 POWER_DOMAIN_PIPE(crtc->pipe)))
3665 pipe_config->shared_dpll = NULL;
3667 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
3669 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
3670 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
3671 drm_WARN_ON(&dev_priv->drm, active);
3678 intel_dsc_get_config(pipe_config);
3679 intel_bigjoiner_get_config(pipe_config);
3681 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
3682 DISPLAY_VER(dev_priv) >= 11)
3683 intel_get_transcoder_timings(crtc, pipe_config);
3685 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
3686 intel_vrr_get_config(pipe_config);
3688 intel_get_pipe_src_size(crtc, pipe_config);
3690 if (IS_HASWELL(dev_priv)) {
3691 u32 tmp = intel_de_read(dev_priv,
3692 TRANSCONF(pipe_config->cpu_transcoder));
3694 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
3695 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3697 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3699 pipe_config->output_format =
3700 bdw_get_pipe_misc_output_format(crtc);
3703 pipe_config->sink_format = pipe_config->output_format;
3705 intel_color_get_config(pipe_config);
3707 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
3708 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
3709 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3710 pipe_config->ips_linetime =
3711 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
3713 if (intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3714 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
3715 if (DISPLAY_VER(dev_priv) >= 9)
3716 skl_scaler_get_config(pipe_config);
3718 ilk_get_pfit_config(pipe_config);
3721 hsw_ips_get_config(pipe_config);
3723 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
3724 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3725 pipe_config->pixel_multiplier =
3726 intel_de_read(dev_priv,
3727 TRANS_MULT(pipe_config->cpu_transcoder)) + 1;
3729 pipe_config->pixel_multiplier = 1;
3732 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3733 tmp = intel_de_read(dev_priv, hsw_chicken_trans_reg(dev_priv, pipe_config->cpu_transcoder));
3735 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
3737 /* no idea if this is correct */
3738 pipe_config->framestart_delay = 1;
3742 intel_display_power_put_all_in_set(dev_priv, &crtc->hw_readout_power_domains);
3747 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
3749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3750 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3752 if (!i915->display.funcs.display->get_pipe_config(crtc, crtc_state))
3755 crtc_state->hw.active = true;
3757 intel_crtc_readout_derived_state(crtc_state);
3762 int intel_dotclock_calculate(int link_freq,
3763 const struct intel_link_m_n *m_n)
3766 * The calculation for the data clock -> pixel clock is:
3767 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
3768 * But we want to avoid losing precison if possible, so:
3769 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
3771 * and for link freq (10kbs units) -> pixel clock it is:
3772 * link_symbol_clock = link_freq * 10 / link_symbol_size
3773 * pixel_clock = (m * link_symbol_clock) / n
3774 * or for more precision:
3775 * pixel_clock = (m * link_freq * 10) / (n * link_symbol_size)
3781 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq * 10),
3782 m_n->link_n * intel_dp_link_symbol_size(link_freq));
3785 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
3789 if (intel_crtc_has_dp_encoder(pipe_config))
3790 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
3791 &pipe_config->dp_m_n);
3792 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
3793 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
3794 pipe_config->pipe_bpp);
3796 dotclock = pipe_config->port_clock;
3798 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
3799 !intel_crtc_has_dp_encoder(pipe_config))
3802 if (pipe_config->pixel_multiplier)
3803 dotclock /= pipe_config->pixel_multiplier;
3808 /* Returns the currently programmed mode of the given encoder. */
3809 struct drm_display_mode *
3810 intel_encoder_current_mode(struct intel_encoder *encoder)
3812 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3813 struct intel_crtc_state *crtc_state;
3814 struct drm_display_mode *mode;
3815 struct intel_crtc *crtc;
3818 if (!encoder->get_hw_state(encoder, &pipe))
3821 crtc = intel_crtc_for_pipe(dev_priv, pipe);
3823 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
3827 crtc_state = intel_crtc_state_alloc(crtc);
3833 if (!intel_crtc_get_pipe_config(crtc_state)) {
3834 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
3839 intel_encoder_get_config(encoder, crtc_state);
3841 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
3843 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
3848 static bool encoders_cloneable(const struct intel_encoder *a,
3849 const struct intel_encoder *b)
3851 /* masks could be asymmetric, so check both ways */
3852 return a == b || (a->cloneable & BIT(b->type) &&
3853 b->cloneable & BIT(a->type));
3856 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
3857 struct intel_crtc *crtc,
3858 struct intel_encoder *encoder)
3860 struct intel_encoder *source_encoder;
3861 struct drm_connector *connector;
3862 struct drm_connector_state *connector_state;
3865 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
3866 if (connector_state->crtc != &crtc->base)
3870 to_intel_encoder(connector_state->best_encoder);
3871 if (!encoders_cloneable(encoder, source_encoder))
3878 static int icl_add_linked_planes(struct intel_atomic_state *state)
3880 struct intel_plane *plane, *linked;
3881 struct intel_plane_state *plane_state, *linked_plane_state;
3884 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
3885 linked = plane_state->planar_linked_plane;
3890 linked_plane_state = intel_atomic_get_plane_state(state, linked);
3891 if (IS_ERR(linked_plane_state))
3892 return PTR_ERR(linked_plane_state);
3894 drm_WARN_ON(state->base.dev,
3895 linked_plane_state->planar_linked_plane != plane);
3896 drm_WARN_ON(state->base.dev,
3897 linked_plane_state->planar_slave == plane_state->planar_slave);
3903 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
3905 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3906 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3907 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
3908 struct intel_plane *plane, *linked;
3909 struct intel_plane_state *plane_state;
3912 if (DISPLAY_VER(dev_priv) < 11)
3916 * Destroy all old plane links and make the slave plane invisible
3917 * in the crtc_state->active_planes mask.
3919 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
3920 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
3923 plane_state->planar_linked_plane = NULL;
3924 if (plane_state->planar_slave && !plane_state->uapi.visible) {
3925 crtc_state->enabled_planes &= ~BIT(plane->id);
3926 crtc_state->active_planes &= ~BIT(plane->id);
3927 crtc_state->update_planes |= BIT(plane->id);
3928 crtc_state->data_rate[plane->id] = 0;
3929 crtc_state->rel_data_rate[plane->id] = 0;
3932 plane_state->planar_slave = false;
3935 if (!crtc_state->nv12_planes)
3938 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
3939 struct intel_plane_state *linked_state = NULL;
3941 if (plane->pipe != crtc->pipe ||
3942 !(crtc_state->nv12_planes & BIT(plane->id)))
3945 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
3946 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
3949 if (crtc_state->active_planes & BIT(linked->id))
3952 linked_state = intel_atomic_get_plane_state(state, linked);
3953 if (IS_ERR(linked_state))
3954 return PTR_ERR(linked_state);
3959 if (!linked_state) {
3960 drm_dbg_kms(&dev_priv->drm,
3961 "Need %d free Y planes for planar YUV\n",
3962 hweight8(crtc_state->nv12_planes));
3967 plane_state->planar_linked_plane = linked;
3969 linked_state->planar_slave = true;
3970 linked_state->planar_linked_plane = plane;
3971 crtc_state->enabled_planes |= BIT(linked->id);
3972 crtc_state->active_planes |= BIT(linked->id);
3973 crtc_state->update_planes |= BIT(linked->id);
3974 crtc_state->data_rate[linked->id] =
3975 crtc_state->data_rate_y[plane->id];
3976 crtc_state->rel_data_rate[linked->id] =
3977 crtc_state->rel_data_rate_y[plane->id];
3978 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
3979 linked->base.name, plane->base.name);
3981 /* Copy parameters to slave plane */
3982 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
3983 linked_state->color_ctl = plane_state->color_ctl;
3984 linked_state->view = plane_state->view;
3985 linked_state->decrypt = plane_state->decrypt;
3987 intel_plane_copy_hw_state(linked_state, plane_state);
3988 linked_state->uapi.src = plane_state->uapi.src;
3989 linked_state->uapi.dst = plane_state->uapi.dst;
3991 if (icl_is_hdr_plane(dev_priv, plane->id)) {
3992 if (linked->id == PLANE_SPRITE5)
3993 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
3994 else if (linked->id == PLANE_SPRITE4)
3995 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
3996 else if (linked->id == PLANE_SPRITE3)
3997 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
3998 else if (linked->id == PLANE_SPRITE2)
3999 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4001 MISSING_CASE(linked->id);
4008 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4010 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4011 struct intel_atomic_state *state =
4012 to_intel_atomic_state(new_crtc_state->uapi.state);
4013 const struct intel_crtc_state *old_crtc_state =
4014 intel_atomic_get_old_crtc_state(state, crtc);
4016 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4019 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4021 const struct drm_display_mode *pipe_mode =
4022 &crtc_state->hw.pipe_mode;
4025 if (!crtc_state->hw.enable)
4028 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4029 pipe_mode->crtc_clock);
4031 return min(linetime_wm, 0x1ff);
4034 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4035 const struct intel_cdclk_state *cdclk_state)
4037 const struct drm_display_mode *pipe_mode =
4038 &crtc_state->hw.pipe_mode;
4041 if (!crtc_state->hw.enable)
4044 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4045 cdclk_state->logical.cdclk);
4047 return min(linetime_wm, 0x1ff);
4050 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4052 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4053 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4054 const struct drm_display_mode *pipe_mode =
4055 &crtc_state->hw.pipe_mode;
4058 if (!crtc_state->hw.enable)
4061 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4062 crtc_state->pixel_rate);
4064 /* Display WA #1135: BXT:ALL GLK:ALL */
4065 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4066 skl_watermark_ipc_enabled(dev_priv))
4069 return min(linetime_wm, 0x1ff);
4072 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4073 struct intel_crtc *crtc)
4075 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4076 struct intel_crtc_state *crtc_state =
4077 intel_atomic_get_new_crtc_state(state, crtc);
4078 const struct intel_cdclk_state *cdclk_state;
4080 if (DISPLAY_VER(dev_priv) >= 9)
4081 crtc_state->linetime = skl_linetime_wm(crtc_state);
4083 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4085 if (!hsw_crtc_supports_ips(crtc))
4088 cdclk_state = intel_atomic_get_cdclk_state(state);
4089 if (IS_ERR(cdclk_state))
4090 return PTR_ERR(cdclk_state);
4092 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4098 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4099 struct intel_crtc *crtc)
4101 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4102 struct intel_crtc_state *crtc_state =
4103 intel_atomic_get_new_crtc_state(state, crtc);
4106 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4107 intel_crtc_needs_modeset(crtc_state) &&
4108 !crtc_state->hw.active)
4109 crtc_state->update_wm_post = true;
4111 if (intel_crtc_needs_modeset(crtc_state)) {
4112 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4118 * May need to update pipe gamma enable bits
4119 * when C8 planes are getting enabled/disabled.
4121 if (c8_planes_changed(crtc_state))
4122 crtc_state->uapi.color_mgmt_changed = true;
4124 if (intel_crtc_needs_color_update(crtc_state)) {
4125 ret = intel_color_check(crtc_state);
4130 ret = intel_compute_pipe_wm(state, crtc);
4132 drm_dbg_kms(&dev_priv->drm,
4133 "Target pipe watermarks are invalid\n");
4138 * Calculate 'intermediate' watermarks that satisfy both the
4139 * old state and the new state. We can program these
4142 ret = intel_compute_intermediate_wm(state, crtc);
4144 drm_dbg_kms(&dev_priv->drm,
4145 "No valid intermediate pipe watermarks are possible\n");
4149 if (DISPLAY_VER(dev_priv) >= 9) {
4150 if (intel_crtc_needs_modeset(crtc_state) ||
4151 intel_crtc_needs_fastset(crtc_state)) {
4152 ret = skl_update_scaler_crtc(crtc_state);
4157 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4162 if (HAS_IPS(dev_priv)) {
4163 ret = hsw_ips_compute_config(state, crtc);
4168 if (DISPLAY_VER(dev_priv) >= 9 ||
4169 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4170 ret = hsw_compute_linetime_wm(state, crtc);
4176 ret = intel_psr2_sel_fetch_update(state, crtc);
4184 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4185 struct intel_crtc_state *crtc_state)
4187 struct drm_connector *connector = conn_state->connector;
4188 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4189 const struct drm_display_info *info = &connector->display_info;
4192 switch (conn_state->max_bpc) {
4206 MISSING_CASE(conn_state->max_bpc);
4210 if (bpp < crtc_state->pipe_bpp) {
4211 drm_dbg_kms(&i915->drm,
4212 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4213 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4214 connector->base.id, connector->name,
4216 3 * conn_state->max_requested_bpc,
4217 crtc_state->pipe_bpp);
4219 crtc_state->pipe_bpp = bpp;
4226 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4227 struct intel_crtc *crtc)
4229 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4230 struct intel_crtc_state *crtc_state =
4231 intel_atomic_get_new_crtc_state(state, crtc);
4232 struct drm_connector *connector;
4233 struct drm_connector_state *connector_state;
4236 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4237 IS_CHERRYVIEW(dev_priv)))
4239 else if (DISPLAY_VER(dev_priv) >= 5)
4244 crtc_state->pipe_bpp = bpp;
4246 /* Clamp display bpp to connector max bpp */
4247 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4250 if (connector_state->crtc != &crtc->base)
4253 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4261 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4263 struct drm_device *dev = state->base.dev;
4264 struct drm_connector *connector;
4265 struct drm_connector_list_iter conn_iter;
4266 unsigned int used_ports = 0;
4267 unsigned int used_mst_ports = 0;
4271 * We're going to peek into connector->state,
4272 * hence connection_mutex must be held.
4274 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4277 * Walk the connector list instead of the encoder
4278 * list to detect the problem on ddi platforms
4279 * where there's just one encoder per digital port.
4281 drm_connector_list_iter_begin(dev, &conn_iter);
4282 drm_for_each_connector_iter(connector, &conn_iter) {
4283 struct drm_connector_state *connector_state;
4284 struct intel_encoder *encoder;
4287 drm_atomic_get_new_connector_state(&state->base,
4289 if (!connector_state)
4290 connector_state = connector->state;
4292 if (!connector_state->best_encoder)
4295 encoder = to_intel_encoder(connector_state->best_encoder);
4297 drm_WARN_ON(dev, !connector_state->crtc);
4299 switch (encoder->type) {
4300 case INTEL_OUTPUT_DDI:
4301 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4304 case INTEL_OUTPUT_DP:
4305 case INTEL_OUTPUT_HDMI:
4306 case INTEL_OUTPUT_EDP:
4307 /* the same port mustn't appear more than once */
4308 if (used_ports & BIT(encoder->port))
4311 used_ports |= BIT(encoder->port);
4313 case INTEL_OUTPUT_DP_MST:
4321 drm_connector_list_iter_end(&conn_iter);
4323 /* can't mix MST and SST/HDMI on the same port */
4324 if (used_ports & used_mst_ports)
4331 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4332 struct intel_crtc *crtc)
4334 struct intel_crtc_state *crtc_state =
4335 intel_atomic_get_new_crtc_state(state, crtc);
4337 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4339 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4340 crtc_state->uapi.degamma_lut);
4341 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4342 crtc_state->uapi.gamma_lut);
4343 drm_property_replace_blob(&crtc_state->hw.ctm,
4344 crtc_state->uapi.ctm);
4348 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4349 struct intel_crtc *crtc)
4351 struct intel_crtc_state *crtc_state =
4352 intel_atomic_get_new_crtc_state(state, crtc);
4354 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4356 crtc_state->hw.enable = crtc_state->uapi.enable;
4357 crtc_state->hw.active = crtc_state->uapi.active;
4358 drm_mode_copy(&crtc_state->hw.mode,
4359 &crtc_state->uapi.mode);
4360 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4361 &crtc_state->uapi.adjusted_mode);
4362 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4364 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4368 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4369 struct intel_crtc *slave_crtc)
4371 struct intel_crtc_state *slave_crtc_state =
4372 intel_atomic_get_new_crtc_state(state, slave_crtc);
4373 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4374 const struct intel_crtc_state *master_crtc_state =
4375 intel_atomic_get_new_crtc_state(state, master_crtc);
4377 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
4378 master_crtc_state->hw.degamma_lut);
4379 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
4380 master_crtc_state->hw.gamma_lut);
4381 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
4382 master_crtc_state->hw.ctm);
4384 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
4388 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
4389 struct intel_crtc *slave_crtc)
4391 struct intel_crtc_state *slave_crtc_state =
4392 intel_atomic_get_new_crtc_state(state, slave_crtc);
4393 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4394 const struct intel_crtc_state *master_crtc_state =
4395 intel_atomic_get_new_crtc_state(state, master_crtc);
4396 struct intel_crtc_state *saved_state;
4398 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4399 slave_crtc_state->bigjoiner_pipes);
4401 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4405 /* preserve some things from the slave's original crtc state */
4406 saved_state->uapi = slave_crtc_state->uapi;
4407 saved_state->scaler_state = slave_crtc_state->scaler_state;
4408 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
4409 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
4411 intel_crtc_free_hw_state(slave_crtc_state);
4412 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
4415 /* Re-init hw state */
4416 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
4417 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
4418 slave_crtc_state->hw.active = master_crtc_state->hw.active;
4419 drm_mode_copy(&slave_crtc_state->hw.mode,
4420 &master_crtc_state->hw.mode);
4421 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
4422 &master_crtc_state->hw.pipe_mode);
4423 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
4424 &master_crtc_state->hw.adjusted_mode);
4425 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
4427 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
4429 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
4430 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
4431 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
4433 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4434 slave_crtc_state->bigjoiner_pipes);
4440 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4441 struct intel_crtc *crtc)
4443 struct intel_crtc_state *crtc_state =
4444 intel_atomic_get_new_crtc_state(state, crtc);
4445 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4446 struct intel_crtc_state *saved_state;
4448 saved_state = intel_crtc_state_alloc(crtc);
4452 /* free the old crtc_state->hw members */
4453 intel_crtc_free_hw_state(crtc_state);
4455 /* FIXME: before the switch to atomic started, a new pipe_config was
4456 * kzalloc'd. Code that depends on any field being zero should be
4457 * fixed, so that the crtc_state can be safely duplicated. For now,
4458 * only fields that are know to not cause problems are preserved. */
4460 saved_state->uapi = crtc_state->uapi;
4461 saved_state->inherited = crtc_state->inherited;
4462 saved_state->scaler_state = crtc_state->scaler_state;
4463 saved_state->shared_dpll = crtc_state->shared_dpll;
4464 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4465 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4466 sizeof(saved_state->icl_port_dplls));
4467 saved_state->crc_enabled = crtc_state->crc_enabled;
4468 if (IS_G4X(dev_priv) ||
4469 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4470 saved_state->wm = crtc_state->wm;
4472 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4475 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4481 intel_modeset_pipe_config(struct intel_atomic_state *state,
4482 struct intel_crtc *crtc,
4483 const struct intel_link_bw_limits *limits)
4485 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4486 struct intel_crtc_state *crtc_state =
4487 intel_atomic_get_new_crtc_state(state, crtc);
4488 struct drm_connector *connector;
4489 struct drm_connector_state *connector_state;
4490 int pipe_src_w, pipe_src_h;
4491 int base_bpp, ret, i;
4493 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4495 crtc_state->framestart_delay = 1;
4498 * Sanitize sync polarity flags based on requested ones. If neither
4499 * positive or negative polarity is requested, treat this as meaning
4500 * negative polarity.
4502 if (!(crtc_state->hw.adjusted_mode.flags &
4503 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4504 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4506 if (!(crtc_state->hw.adjusted_mode.flags &
4507 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4508 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4510 ret = compute_baseline_pipe_bpp(state, crtc);
4514 crtc_state->fec_enable = limits->force_fec_pipes & BIT(crtc->pipe);
4515 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe];
4517 if (crtc_state->pipe_bpp > to_bpp_int(crtc_state->max_link_bpp_x16)) {
4518 drm_dbg_kms(&i915->drm,
4519 "[CRTC:%d:%s] Link bpp limited to " BPP_X16_FMT "\n",
4520 crtc->base.base.id, crtc->base.name,
4521 BPP_X16_ARGS(crtc_state->max_link_bpp_x16));
4522 crtc_state->bw_constrained = true;
4525 base_bpp = crtc_state->pipe_bpp;
4528 * Determine the real pipe dimensions. Note that stereo modes can
4529 * increase the actual pipe size due to the frame doubling and
4530 * insertion of additional space for blanks between the frame. This
4531 * is stored in the crtc timings. We use the requested mode to do this
4532 * computation to clearly distinguish it from the adjusted mode, which
4533 * can be changed by the connectors in the below retry loop.
4535 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4536 &pipe_src_w, &pipe_src_h);
4537 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4538 pipe_src_w, pipe_src_h);
4540 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4541 struct intel_encoder *encoder =
4542 to_intel_encoder(connector_state->best_encoder);
4544 if (connector_state->crtc != &crtc->base)
4547 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4548 drm_dbg_kms(&i915->drm,
4549 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4550 encoder->base.base.id, encoder->base.name);
4555 * Determine output_types before calling the .compute_config()
4556 * hooks so that the hooks can use this information safely.
4558 if (encoder->compute_output_type)
4559 crtc_state->output_types |=
4560 BIT(encoder->compute_output_type(encoder, crtc_state,
4563 crtc_state->output_types |= BIT(encoder->type);
4566 /* Ensure the port clock defaults are reset when retrying. */
4567 crtc_state->port_clock = 0;
4568 crtc_state->pixel_multiplier = 1;
4570 /* Fill in default crtc timings, allow encoders to overwrite them. */
4571 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
4572 CRTC_STEREO_DOUBLE);
4574 /* Pass our mode to the connectors and the CRTC to give them a chance to
4575 * adjust it according to limitations or connector properties, and also
4576 * a chance to reject the mode entirely.
4578 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4579 struct intel_encoder *encoder =
4580 to_intel_encoder(connector_state->best_encoder);
4582 if (connector_state->crtc != &crtc->base)
4585 ret = encoder->compute_config(encoder, crtc_state,
4587 if (ret == -EDEADLK)
4590 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
4591 encoder->base.base.id, encoder->base.name, ret);
4596 /* Set default port clock if not overwritten by the encoder. Needs to be
4597 * done afterwards in case the encoder adjusts the mode. */
4598 if (!crtc_state->port_clock)
4599 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
4600 * crtc_state->pixel_multiplier;
4602 ret = intel_crtc_compute_config(state, crtc);
4603 if (ret == -EDEADLK)
4606 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
4607 crtc->base.base.id, crtc->base.name, ret);
4611 /* Dithering seems to not pass-through bits correctly when it should, so
4612 * only enable it on 6bpc panels and when its not a compliance
4613 * test requesting 6bpc video pattern.
4615 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
4616 !crtc_state->dither_force_disable;
4617 drm_dbg_kms(&i915->drm,
4618 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
4619 crtc->base.base.id, crtc->base.name,
4620 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
4626 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
4627 struct intel_crtc *crtc)
4629 struct intel_crtc_state *crtc_state =
4630 intel_atomic_get_new_crtc_state(state, crtc);
4631 struct drm_connector_state *conn_state;
4632 struct drm_connector *connector;
4635 intel_bigjoiner_adjust_pipe_src(crtc_state);
4637 for_each_new_connector_in_state(&state->base, connector,
4639 struct intel_encoder *encoder =
4640 to_intel_encoder(conn_state->best_encoder);
4643 if (conn_state->crtc != &crtc->base ||
4644 !encoder->compute_config_late)
4647 ret = encoder->compute_config_late(encoder, crtc_state,
4656 bool intel_fuzzy_clock_check(int clock1, int clock2)
4660 if (clock1 == clock2)
4663 if (!clock1 || !clock2)
4666 diff = abs(clock1 - clock2);
4668 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
4675 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
4676 const struct intel_link_m_n *m2_n2)
4678 return m_n->tu == m2_n2->tu &&
4679 m_n->data_m == m2_n2->data_m &&
4680 m_n->data_n == m2_n2->data_n &&
4681 m_n->link_m == m2_n2->link_m &&
4682 m_n->link_n == m2_n2->link_n;
4686 intel_compare_infoframe(const union hdmi_infoframe *a,
4687 const union hdmi_infoframe *b)
4689 return memcmp(a, b, sizeof(*a)) == 0;
4693 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
4694 const struct drm_dp_vsc_sdp *b)
4696 return memcmp(a, b, sizeof(*a)) == 0;
4700 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
4702 return memcmp(a, b, len) == 0;
4706 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
4707 bool fastset, const char *name,
4708 const union hdmi_infoframe *a,
4709 const union hdmi_infoframe *b)
4712 if (!drm_debug_enabled(DRM_UT_KMS))
4715 drm_dbg_kms(&dev_priv->drm,
4716 "fastset requirement not met in %s infoframe\n", name);
4717 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4718 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
4719 drm_dbg_kms(&dev_priv->drm, "found:\n");
4720 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
4722 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
4723 drm_err(&dev_priv->drm, "expected:\n");
4724 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
4725 drm_err(&dev_priv->drm, "found:\n");
4726 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
4731 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
4732 bool fastset, const char *name,
4733 const struct drm_dp_vsc_sdp *a,
4734 const struct drm_dp_vsc_sdp *b)
4737 if (!drm_debug_enabled(DRM_UT_KMS))
4740 drm_dbg_kms(&dev_priv->drm,
4741 "fastset requirement not met in %s dp sdp\n", name);
4742 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4743 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
4744 drm_dbg_kms(&dev_priv->drm, "found:\n");
4745 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
4747 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
4748 drm_err(&dev_priv->drm, "expected:\n");
4749 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
4750 drm_err(&dev_priv->drm, "found:\n");
4751 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
4755 /* Returns the length up to and including the last differing byte */
4757 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
4761 for (i = len - 1; i >= 0; i--) {
4770 pipe_config_buffer_mismatch(struct drm_i915_private *dev_priv,
4771 bool fastset, const char *name,
4772 const u8 *a, const u8 *b, size_t len)
4775 if (!drm_debug_enabled(DRM_UT_KMS))
4778 /* only dump up to the last difference */
4779 len = memcmp_diff_len(a, b, len);
4781 drm_dbg_kms(&dev_priv->drm,
4782 "fastset requirement not met in %s buffer\n", name);
4783 print_hex_dump(KERN_DEBUG, "expected: ", DUMP_PREFIX_NONE,
4784 16, 0, a, len, false);
4785 print_hex_dump(KERN_DEBUG, "found: ", DUMP_PREFIX_NONE,
4786 16, 0, b, len, false);
4788 /* only dump up to the last difference */
4789 len = memcmp_diff_len(a, b, len);
4791 drm_err(&dev_priv->drm, "mismatch in %s buffer\n", name);
4792 print_hex_dump(KERN_ERR, "expected: ", DUMP_PREFIX_NONE,
4793 16, 0, a, len, false);
4794 print_hex_dump(KERN_ERR, "found: ", DUMP_PREFIX_NONE,
4795 16, 0, b, len, false);
4799 static void __printf(4, 5)
4800 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
4801 const char *name, const char *format, ...)
4803 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4804 struct va_format vaf;
4807 va_start(args, format);
4812 drm_dbg_kms(&i915->drm,
4813 "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
4814 crtc->base.base.id, crtc->base.name, name, &vaf);
4816 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
4817 crtc->base.base.id, crtc->base.name, name, &vaf);
4822 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
4824 /* Enable fastboot by default on Skylake and newer */
4825 if (DISPLAY_VER(dev_priv) >= 9)
4828 /* Enable fastboot by default on VLV and CHV */
4829 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4832 /* Disabled by default on all others */
4837 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
4838 const struct intel_crtc_state *pipe_config,
4841 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
4842 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
4844 bool fixup_inherited = fastset &&
4845 current_config->inherited && !pipe_config->inherited;
4847 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
4848 drm_dbg_kms(&dev_priv->drm,
4849 "initial modeset and fastboot not set\n");
4853 #define PIPE_CONF_CHECK_X(name) do { \
4854 if (current_config->name != pipe_config->name) { \
4855 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4856 "(expected 0x%08x, found 0x%08x)", \
4857 current_config->name, \
4858 pipe_config->name); \
4863 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
4864 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
4865 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4866 "(expected 0x%08x, found 0x%08x)", \
4867 current_config->name & (mask), \
4868 pipe_config->name & (mask)); \
4873 #define PIPE_CONF_CHECK_I(name) do { \
4874 if (current_config->name != pipe_config->name) { \
4875 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4876 "(expected %i, found %i)", \
4877 current_config->name, \
4878 pipe_config->name); \
4883 #define PIPE_CONF_CHECK_BOOL(name) do { \
4884 if (current_config->name != pipe_config->name) { \
4885 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4886 "(expected %s, found %s)", \
4887 str_yes_no(current_config->name), \
4888 str_yes_no(pipe_config->name)); \
4894 * Checks state where we only read out the enabling, but not the entire
4895 * state itself (like full infoframes or ELD for audio). These states
4896 * require a full modeset on bootup to fix up.
4898 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
4899 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
4900 PIPE_CONF_CHECK_BOOL(name); \
4902 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4903 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
4904 str_yes_no(current_config->name), \
4905 str_yes_no(pipe_config->name)); \
4910 #define PIPE_CONF_CHECK_P(name) do { \
4911 if (current_config->name != pipe_config->name) { \
4912 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4913 "(expected %p, found %p)", \
4914 current_config->name, \
4915 pipe_config->name); \
4920 #define PIPE_CONF_CHECK_M_N(name) do { \
4921 if (!intel_compare_link_m_n(¤t_config->name, \
4922 &pipe_config->name)) { \
4923 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4924 "(expected tu %i data %i/%i link %i/%i, " \
4925 "found tu %i, data %i/%i link %i/%i)", \
4926 current_config->name.tu, \
4927 current_config->name.data_m, \
4928 current_config->name.data_n, \
4929 current_config->name.link_m, \
4930 current_config->name.link_n, \
4931 pipe_config->name.tu, \
4932 pipe_config->name.data_m, \
4933 pipe_config->name.data_n, \
4934 pipe_config->name.link_m, \
4935 pipe_config->name.link_n); \
4940 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
4941 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
4942 PIPE_CONF_CHECK_I(name.crtc_htotal); \
4943 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
4944 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
4945 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
4946 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
4947 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
4948 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
4949 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
4950 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
4951 if (!fastset || !pipe_config->update_lrr) { \
4952 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
4953 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
4957 #define PIPE_CONF_CHECK_RECT(name) do { \
4958 PIPE_CONF_CHECK_I(name.x1); \
4959 PIPE_CONF_CHECK_I(name.x2); \
4960 PIPE_CONF_CHECK_I(name.y1); \
4961 PIPE_CONF_CHECK_I(name.y2); \
4964 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
4965 if ((current_config->name ^ pipe_config->name) & (mask)) { \
4966 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4967 "(%x) (expected %i, found %i)", \
4969 current_config->name & (mask), \
4970 pipe_config->name & (mask)); \
4975 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
4976 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
4977 &pipe_config->infoframes.name)) { \
4978 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
4979 ¤t_config->infoframes.name, \
4980 &pipe_config->infoframes.name); \
4985 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
4986 if (!current_config->has_psr && !pipe_config->has_psr && \
4987 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
4988 &pipe_config->infoframes.name)) { \
4989 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
4990 ¤t_config->infoframes.name, \
4991 &pipe_config->infoframes.name); \
4996 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
4997 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
4998 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
4999 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5000 pipe_config_buffer_mismatch(dev_priv, fastset, __stringify(name), \
5001 current_config->name, \
5002 pipe_config->name, \
5008 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5009 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5010 !intel_color_lut_equal(current_config, \
5011 current_config->lut, pipe_config->lut, \
5012 is_pre_csc_lut)) { \
5013 pipe_config_mismatch(fastset, crtc, __stringify(lut), \
5014 "hw_state doesn't match sw_state"); \
5019 #define PIPE_CONF_CHECK_CSC(name) do { \
5020 PIPE_CONF_CHECK_X(name.preoff[0]); \
5021 PIPE_CONF_CHECK_X(name.preoff[1]); \
5022 PIPE_CONF_CHECK_X(name.preoff[2]); \
5023 PIPE_CONF_CHECK_X(name.coeff[0]); \
5024 PIPE_CONF_CHECK_X(name.coeff[1]); \
5025 PIPE_CONF_CHECK_X(name.coeff[2]); \
5026 PIPE_CONF_CHECK_X(name.coeff[3]); \
5027 PIPE_CONF_CHECK_X(name.coeff[4]); \
5028 PIPE_CONF_CHECK_X(name.coeff[5]); \
5029 PIPE_CONF_CHECK_X(name.coeff[6]); \
5030 PIPE_CONF_CHECK_X(name.coeff[7]); \
5031 PIPE_CONF_CHECK_X(name.coeff[8]); \
5032 PIPE_CONF_CHECK_X(name.postoff[0]); \
5033 PIPE_CONF_CHECK_X(name.postoff[1]); \
5034 PIPE_CONF_CHECK_X(name.postoff[2]); \
5037 #define PIPE_CONF_QUIRK(quirk) \
5038 ((current_config->quirks | pipe_config->quirks) & (quirk))
5040 PIPE_CONF_CHECK_I(hw.enable);
5041 PIPE_CONF_CHECK_I(hw.active);
5043 PIPE_CONF_CHECK_I(cpu_transcoder);
5044 PIPE_CONF_CHECK_I(mst_master_transcoder);
5046 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5047 PIPE_CONF_CHECK_I(fdi_lanes);
5048 PIPE_CONF_CHECK_M_N(fdi_m_n);
5050 PIPE_CONF_CHECK_I(lane_count);
5051 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5053 if (HAS_DOUBLE_BUFFERED_M_N(dev_priv)) {
5054 if (!fastset || !pipe_config->update_m_n)
5055 PIPE_CONF_CHECK_M_N(dp_m_n);
5057 PIPE_CONF_CHECK_M_N(dp_m_n);
5058 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5061 PIPE_CONF_CHECK_X(output_types);
5063 PIPE_CONF_CHECK_I(framestart_delay);
5064 PIPE_CONF_CHECK_I(msa_timing_delay);
5066 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5067 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5069 PIPE_CONF_CHECK_I(pixel_multiplier);
5071 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5072 DRM_MODE_FLAG_INTERLACE);
5074 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5075 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5076 DRM_MODE_FLAG_PHSYNC);
5077 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5078 DRM_MODE_FLAG_NHSYNC);
5079 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5080 DRM_MODE_FLAG_PVSYNC);
5081 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5082 DRM_MODE_FLAG_NVSYNC);
5085 PIPE_CONF_CHECK_I(output_format);
5086 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5087 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5088 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5089 PIPE_CONF_CHECK_BOOL(limited_color_range);
5091 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5092 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5093 PIPE_CONF_CHECK_BOOL(has_infoframe);
5094 PIPE_CONF_CHECK_BOOL(enhanced_framing);
5095 PIPE_CONF_CHECK_BOOL(fec_enable);
5097 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
5098 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5100 PIPE_CONF_CHECK_X(gmch_pfit.control);
5101 /* pfit ratios are autocomputed by the hw on gen4+ */
5102 if (DISPLAY_VER(dev_priv) < 4)
5103 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5104 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5107 * Changing the EDP transcoder input mux
5108 * (A_ONOFF vs. A_ON) requires a full modeset.
5110 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5113 PIPE_CONF_CHECK_RECT(pipe_src);
5115 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5116 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5118 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5119 PIPE_CONF_CHECK_I(pixel_rate);
5121 PIPE_CONF_CHECK_X(gamma_mode);
5122 if (IS_CHERRYVIEW(dev_priv))
5123 PIPE_CONF_CHECK_X(cgm_mode);
5125 PIPE_CONF_CHECK_X(csc_mode);
5126 PIPE_CONF_CHECK_BOOL(gamma_enable);
5127 PIPE_CONF_CHECK_BOOL(csc_enable);
5128 PIPE_CONF_CHECK_BOOL(wgc_enable);
5130 PIPE_CONF_CHECK_I(linetime);
5131 PIPE_CONF_CHECK_I(ips_linetime);
5133 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5134 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5136 PIPE_CONF_CHECK_CSC(csc);
5137 PIPE_CONF_CHECK_CSC(output_csc);
5139 if (current_config->active_planes) {
5140 PIPE_CONF_CHECK_BOOL(has_psr);
5141 PIPE_CONF_CHECK_BOOL(has_psr2);
5142 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5143 PIPE_CONF_CHECK_I(dc3co_exitline);
5147 PIPE_CONF_CHECK_BOOL(double_wide);
5149 if (dev_priv->display.dpll.mgr) {
5150 PIPE_CONF_CHECK_P(shared_dpll);
5152 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
5153 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
5154 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
5155 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
5156 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
5157 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
5158 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
5159 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
5160 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
5161 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
5162 PIPE_CONF_CHECK_X(dpll_hw_state.div0);
5163 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
5164 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
5165 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
5166 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
5167 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
5168 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
5169 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
5170 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
5171 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
5172 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
5173 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
5174 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
5175 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
5176 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
5177 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
5178 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
5179 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
5180 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
5181 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
5182 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
5183 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
5186 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5187 PIPE_CONF_CHECK_X(dsi_pll.div);
5189 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5190 PIPE_CONF_CHECK_I(pipe_bpp);
5192 if (!fastset || !pipe_config->update_m_n) {
5193 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5194 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5196 PIPE_CONF_CHECK_I(port_clock);
5198 PIPE_CONF_CHECK_I(min_voltage_level);
5200 if (current_config->has_psr || pipe_config->has_psr)
5201 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5202 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5204 PIPE_CONF_CHECK_X(infoframes.enable);
5206 PIPE_CONF_CHECK_X(infoframes.gcp);
5207 PIPE_CONF_CHECK_INFOFRAME(avi);
5208 PIPE_CONF_CHECK_INFOFRAME(spd);
5209 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5210 PIPE_CONF_CHECK_INFOFRAME(drm);
5211 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5213 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5214 PIPE_CONF_CHECK_I(master_transcoder);
5215 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5217 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable);
5218 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb);
5219 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422);
5220 PIPE_CONF_CHECK_BOOL(dsc.config.native_422);
5221 PIPE_CONF_CHECK_BOOL(dsc.config.native_420);
5222 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable);
5223 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth);
5224 PIPE_CONF_CHECK_I(dsc.config.bits_per_component);
5225 PIPE_CONF_CHECK_I(dsc.config.pic_width);
5226 PIPE_CONF_CHECK_I(dsc.config.pic_height);
5227 PIPE_CONF_CHECK_I(dsc.config.slice_width);
5228 PIPE_CONF_CHECK_I(dsc.config.slice_height);
5229 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay);
5230 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay);
5231 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval);
5232 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval);
5233 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value);
5234 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset);
5235 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp);
5236 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp);
5237 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset);
5238 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset);
5239 PIPE_CONF_CHECK_I(dsc.config.initial_offset);
5240 PIPE_CONF_CHECK_I(dsc.config.final_offset);
5241 PIPE_CONF_CHECK_I(dsc.config.rc_model_size);
5242 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0);
5243 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1);
5244 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size);
5245 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset);
5246 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset);
5248 PIPE_CONF_CHECK_I(dsc.compression_enable);
5249 PIPE_CONF_CHECK_I(dsc.dsc_split);
5250 PIPE_CONF_CHECK_I(dsc.compressed_bpp_x16);
5252 PIPE_CONF_CHECK_BOOL(splitter.enable);
5253 PIPE_CONF_CHECK_I(splitter.link_count);
5254 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5257 PIPE_CONF_CHECK_BOOL(vrr.enable);
5258 PIPE_CONF_CHECK_I(vrr.vmin);
5259 PIPE_CONF_CHECK_I(vrr.vmax);
5260 PIPE_CONF_CHECK_I(vrr.flipline);
5261 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5262 PIPE_CONF_CHECK_I(vrr.guardband);
5265 #undef PIPE_CONF_CHECK_X
5266 #undef PIPE_CONF_CHECK_I
5267 #undef PIPE_CONF_CHECK_BOOL
5268 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
5269 #undef PIPE_CONF_CHECK_P
5270 #undef PIPE_CONF_CHECK_FLAGS
5271 #undef PIPE_CONF_CHECK_COLOR_LUT
5272 #undef PIPE_CONF_CHECK_TIMINGS
5273 #undef PIPE_CONF_CHECK_RECT
5274 #undef PIPE_CONF_QUIRK
5280 intel_verify_planes(struct intel_atomic_state *state)
5282 struct intel_plane *plane;
5283 const struct intel_plane_state *plane_state;
5286 for_each_new_intel_plane_in_state(state, plane,
5288 assert_plane(plane, plane_state->planar_slave ||
5289 plane_state->uapi.visible);
5292 static int intel_modeset_pipe(struct intel_atomic_state *state,
5293 struct intel_crtc_state *crtc_state,
5296 struct drm_i915_private *i915 = to_i915(state->base.dev);
5297 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5300 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5301 crtc->base.base.id, crtc->base.name, reason);
5303 ret = drm_atomic_add_affected_connectors(&state->base,
5308 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5312 ret = intel_atomic_add_affected_planes(state, crtc);
5316 crtc_state->uapi.mode_changed = true;
5322 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes
5323 * @state: intel atomic state
5324 * @reason: the reason for the full modeset
5325 * @mask: mask of pipes to modeset
5327 * Add pipes in @mask to @state and force a full modeset on the enabled ones
5328 * due to the description in @reason.
5329 * This function can be called only before new plane states are computed.
5331 * Returns 0 in case of success, negative error code otherwise.
5333 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
5334 const char *reason, u8 mask)
5336 struct drm_i915_private *i915 = to_i915(state->base.dev);
5337 struct intel_crtc *crtc;
5339 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, mask) {
5340 struct intel_crtc_state *crtc_state;
5343 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5344 if (IS_ERR(crtc_state))
5345 return PTR_ERR(crtc_state);
5347 if (!crtc_state->hw.enable ||
5348 intel_crtc_needs_modeset(crtc_state))
5351 ret = intel_modeset_pipe(state, crtc_state, reason);
5360 intel_crtc_flag_modeset(struct intel_crtc_state *crtc_state)
5362 crtc_state->uapi.mode_changed = true;
5364 crtc_state->update_pipe = false;
5365 crtc_state->update_m_n = false;
5366 crtc_state->update_lrr = false;
5370 * intel_modeset_all_pipes_late - force a full modeset on all pipes
5371 * @state: intel atomic state
5372 * @reason: the reason for the full modeset
5374 * Add all pipes to @state and force a full modeset on the active ones due to
5375 * the description in @reason.
5376 * This function can be called only after new plane states are computed already.
5378 * Returns 0 in case of success, negative error code otherwise.
5380 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
5383 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5384 struct intel_crtc *crtc;
5386 for_each_intel_crtc(&dev_priv->drm, crtc) {
5387 struct intel_crtc_state *crtc_state;
5390 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5391 if (IS_ERR(crtc_state))
5392 return PTR_ERR(crtc_state);
5394 if (!crtc_state->hw.active ||
5395 intel_crtc_needs_modeset(crtc_state))
5398 ret = intel_modeset_pipe(state, crtc_state, reason);
5402 intel_crtc_flag_modeset(crtc_state);
5404 crtc_state->update_planes |= crtc_state->active_planes;
5405 crtc_state->async_flip_planes = 0;
5406 crtc_state->do_async_flip = false;
5413 * This implements the workaround described in the "notes" section of the mode
5414 * set sequence documentation. When going from no pipes or single pipe to
5415 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5416 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5418 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5420 struct intel_crtc_state *crtc_state;
5421 struct intel_crtc *crtc;
5422 struct intel_crtc_state *first_crtc_state = NULL;
5423 struct intel_crtc_state *other_crtc_state = NULL;
5424 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5427 /* look at all crtc's that are going to be enabled in during modeset */
5428 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5429 if (!crtc_state->hw.active ||
5430 !intel_crtc_needs_modeset(crtc_state))
5433 if (first_crtc_state) {
5434 other_crtc_state = crtc_state;
5437 first_crtc_state = crtc_state;
5438 first_pipe = crtc->pipe;
5442 /* No workaround needed? */
5443 if (!first_crtc_state)
5446 /* w/a possibly needed, check how many crtc's are already enabled. */
5447 for_each_intel_crtc(state->base.dev, crtc) {
5448 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5449 if (IS_ERR(crtc_state))
5450 return PTR_ERR(crtc_state);
5452 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5454 if (!crtc_state->hw.active ||
5455 intel_crtc_needs_modeset(crtc_state))
5458 /* 2 or more enabled crtcs means no need for w/a */
5459 if (enabled_pipe != INVALID_PIPE)
5462 enabled_pipe = crtc->pipe;
5465 if (enabled_pipe != INVALID_PIPE)
5466 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5467 else if (other_crtc_state)
5468 other_crtc_state->hsw_workaround_pipe = first_pipe;
5473 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
5476 const struct intel_crtc_state *crtc_state;
5477 struct intel_crtc *crtc;
5480 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5481 if (crtc_state->hw.active)
5482 active_pipes |= BIT(crtc->pipe);
5484 active_pipes &= ~BIT(crtc->pipe);
5487 return active_pipes;
5490 static int intel_modeset_checks(struct intel_atomic_state *state)
5492 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5494 state->modeset = true;
5496 if (IS_HASWELL(dev_priv))
5497 return hsw_mode_set_planes_workaround(state);
5502 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
5503 struct intel_crtc_state *new_crtc_state)
5505 struct drm_i915_private *i915 = to_i915(old_crtc_state->uapi.crtc->dev);
5507 /* only allow LRR when the timings stay within the VRR range */
5508 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range)
5509 new_crtc_state->update_lrr = false;
5511 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
5512 drm_dbg_kms(&i915->drm, "fastset requirement not met, forcing full modeset\n");
5514 new_crtc_state->uapi.mode_changed = false;
5516 if (intel_compare_link_m_n(&old_crtc_state->dp_m_n,
5517 &new_crtc_state->dp_m_n))
5518 new_crtc_state->update_m_n = false;
5520 if ((old_crtc_state->hw.adjusted_mode.crtc_vtotal == new_crtc_state->hw.adjusted_mode.crtc_vtotal &&
5521 old_crtc_state->hw.adjusted_mode.crtc_vblank_end == new_crtc_state->hw.adjusted_mode.crtc_vblank_end))
5522 new_crtc_state->update_lrr = false;
5524 if (intel_crtc_needs_modeset(new_crtc_state))
5525 intel_crtc_flag_modeset(new_crtc_state);
5527 new_crtc_state->update_pipe = true;
5530 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
5531 struct intel_crtc *crtc,
5534 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5535 struct intel_plane *plane;
5537 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5538 struct intel_plane_state *plane_state;
5540 if ((plane_ids_mask & BIT(plane->id)) == 0)
5543 plane_state = intel_atomic_get_plane_state(state, plane);
5544 if (IS_ERR(plane_state))
5545 return PTR_ERR(plane_state);
5551 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
5552 struct intel_crtc *crtc)
5554 const struct intel_crtc_state *old_crtc_state =
5555 intel_atomic_get_old_crtc_state(state, crtc);
5556 const struct intel_crtc_state *new_crtc_state =
5557 intel_atomic_get_new_crtc_state(state, crtc);
5559 return intel_crtc_add_planes_to_state(state, crtc,
5560 old_crtc_state->enabled_planes |
5561 new_crtc_state->enabled_planes);
5564 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
5566 /* See {hsw,vlv,ivb}_plane_ratio() */
5567 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
5568 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
5569 IS_IVYBRIDGE(dev_priv);
5572 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
5573 struct intel_crtc *crtc,
5574 struct intel_crtc *other)
5576 const struct intel_plane_state __maybe_unused *plane_state;
5577 struct intel_plane *plane;
5581 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5582 if (plane->pipe == crtc->pipe)
5583 plane_ids |= BIT(plane->id);
5586 return intel_crtc_add_planes_to_state(state, other, plane_ids);
5589 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
5591 struct drm_i915_private *i915 = to_i915(state->base.dev);
5592 const struct intel_crtc_state *crtc_state;
5593 struct intel_crtc *crtc;
5596 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5597 struct intel_crtc *other;
5599 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
5600 crtc_state->bigjoiner_pipes) {
5606 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
5615 static int intel_atomic_check_planes(struct intel_atomic_state *state)
5617 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5618 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5619 struct intel_plane_state __maybe_unused *plane_state;
5620 struct intel_plane *plane;
5621 struct intel_crtc *crtc;
5624 ret = icl_add_linked_planes(state);
5628 ret = intel_bigjoiner_add_affected_planes(state);
5632 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5633 ret = intel_plane_atomic_check(state, plane);
5635 drm_dbg_atomic(&dev_priv->drm,
5636 "[PLANE:%d:%s] atomic driver check failed\n",
5637 plane->base.base.id, plane->base.name);
5642 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5643 new_crtc_state, i) {
5644 u8 old_active_planes, new_active_planes;
5646 ret = icl_check_nv12_planes(new_crtc_state);
5651 * On some platforms the number of active planes affects
5652 * the planes' minimum cdclk calculation. Add such planes
5653 * to the state before we compute the minimum cdclk.
5655 if (!active_planes_affects_min_cdclk(dev_priv))
5658 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5659 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5661 if (hweight8(old_active_planes) == hweight8(new_active_planes))
5664 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
5672 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
5674 struct intel_crtc_state __maybe_unused *crtc_state;
5675 struct intel_crtc *crtc;
5678 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5679 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5682 ret = intel_crtc_atomic_check(state, crtc);
5684 drm_dbg_atomic(&i915->drm,
5685 "[CRTC:%d:%s] atomic driver check failed\n",
5686 crtc->base.base.id, crtc->base.name);
5694 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
5697 const struct intel_crtc_state *new_crtc_state;
5698 struct intel_crtc *crtc;
5701 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5702 if (new_crtc_state->hw.enable &&
5703 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
5704 intel_crtc_needs_modeset(new_crtc_state))
5711 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
5714 const struct intel_crtc_state *new_crtc_state;
5715 struct intel_crtc *crtc;
5718 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5719 if (new_crtc_state->hw.enable &&
5720 pipes & BIT(crtc->pipe) &&
5721 intel_crtc_needs_modeset(new_crtc_state))
5728 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
5729 struct intel_crtc *master_crtc)
5731 struct drm_i915_private *i915 = to_i915(state->base.dev);
5732 struct intel_crtc_state *master_crtc_state =
5733 intel_atomic_get_new_crtc_state(state, master_crtc);
5734 struct intel_crtc *slave_crtc;
5736 if (!master_crtc_state->bigjoiner_pipes)
5740 if (drm_WARN_ON(&i915->drm,
5741 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
5744 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
5745 drm_dbg_kms(&i915->drm,
5746 "[CRTC:%d:%s] Cannot act as big joiner master "
5747 "(need 0x%x as pipes, only 0x%x possible)\n",
5748 master_crtc->base.base.id, master_crtc->base.name,
5749 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
5753 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5754 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5755 struct intel_crtc_state *slave_crtc_state;
5758 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
5759 if (IS_ERR(slave_crtc_state))
5760 return PTR_ERR(slave_crtc_state);
5762 /* master being enabled, slave was already configured? */
5763 if (slave_crtc_state->uapi.enable) {
5764 drm_dbg_kms(&i915->drm,
5765 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
5766 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
5767 slave_crtc->base.base.id, slave_crtc->base.name,
5768 master_crtc->base.base.id, master_crtc->base.name);
5773 * The state copy logic assumes the master crtc gets processed
5774 * before the slave crtc during the main compute_config loop.
5775 * This works because the crtcs are created in pipe order,
5776 * and the hardware requires master pipe < slave pipe as well.
5777 * Should that change we need to rethink the logic.
5779 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
5780 drm_crtc_index(&slave_crtc->base)))
5783 drm_dbg_kms(&i915->drm,
5784 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
5785 slave_crtc->base.base.id, slave_crtc->base.name,
5786 master_crtc->base.base.id, master_crtc->base.name);
5788 slave_crtc_state->bigjoiner_pipes =
5789 master_crtc_state->bigjoiner_pipes;
5791 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
5799 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
5800 struct intel_crtc *master_crtc)
5802 struct drm_i915_private *i915 = to_i915(state->base.dev);
5803 struct intel_crtc_state *master_crtc_state =
5804 intel_atomic_get_new_crtc_state(state, master_crtc);
5805 struct intel_crtc *slave_crtc;
5807 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5808 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5809 struct intel_crtc_state *slave_crtc_state =
5810 intel_atomic_get_new_crtc_state(state, slave_crtc);
5812 slave_crtc_state->bigjoiner_pipes = 0;
5814 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
5817 master_crtc_state->bigjoiner_pipes = 0;
5821 * DOC: asynchronous flip implementation
5823 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
5824 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
5825 * Correspondingly, support is currently added for primary plane only.
5827 * Async flip can only change the plane surface address, so anything else
5828 * changing is rejected from the intel_async_flip_check_hw() function.
5829 * Once this check is cleared, flip done interrupt is enabled using
5830 * the intel_crtc_enable_flip_done() function.
5832 * As soon as the surface address register is written, flip done interrupt is
5833 * generated and the requested events are sent to the usersapce in the interrupt
5834 * handler itself. The timestamp and sequence sent during the flip done event
5835 * correspond to the last vblank and have no relation to the actual time when
5836 * the flip done event was sent.
5838 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
5839 struct intel_crtc *crtc)
5841 struct drm_i915_private *i915 = to_i915(state->base.dev);
5842 const struct intel_crtc_state *new_crtc_state =
5843 intel_atomic_get_new_crtc_state(state, crtc);
5844 const struct intel_plane_state *old_plane_state;
5845 struct intel_plane_state *new_plane_state;
5846 struct intel_plane *plane;
5849 if (!new_crtc_state->uapi.async_flip)
5852 if (!new_crtc_state->uapi.active) {
5853 drm_dbg_kms(&i915->drm,
5854 "[CRTC:%d:%s] not active\n",
5855 crtc->base.base.id, crtc->base.name);
5859 if (intel_crtc_needs_modeset(new_crtc_state)) {
5860 drm_dbg_kms(&i915->drm,
5861 "[CRTC:%d:%s] modeset required\n",
5862 crtc->base.base.id, crtc->base.name);
5866 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5867 new_plane_state, i) {
5868 if (plane->pipe != crtc->pipe)
5872 * TODO: Async flip is only supported through the page flip IOCTL
5873 * as of now. So support currently added for primary plane only.
5874 * Support for other planes on platforms on which supports
5875 * this(vlv/chv and icl+) should be added when async flip is
5876 * enabled in the atomic IOCTL path.
5878 if (!plane->async_flip) {
5879 drm_dbg_kms(&i915->drm,
5880 "[PLANE:%d:%s] async flip not supported\n",
5881 plane->base.base.id, plane->base.name);
5885 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
5886 drm_dbg_kms(&i915->drm,
5887 "[PLANE:%d:%s] no old or new framebuffer\n",
5888 plane->base.base.id, plane->base.name);
5896 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
5898 struct drm_i915_private *i915 = to_i915(state->base.dev);
5899 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5900 const struct intel_plane_state *new_plane_state, *old_plane_state;
5901 struct intel_plane *plane;
5904 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
5905 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
5907 if (!new_crtc_state->uapi.async_flip)
5910 if (!new_crtc_state->hw.active) {
5911 drm_dbg_kms(&i915->drm,
5912 "[CRTC:%d:%s] not active\n",
5913 crtc->base.base.id, crtc->base.name);
5917 if (intel_crtc_needs_modeset(new_crtc_state)) {
5918 drm_dbg_kms(&i915->drm,
5919 "[CRTC:%d:%s] modeset required\n",
5920 crtc->base.base.id, crtc->base.name);
5924 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
5925 drm_dbg_kms(&i915->drm,
5926 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
5927 crtc->base.base.id, crtc->base.name);
5931 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5932 new_plane_state, i) {
5933 if (plane->pipe != crtc->pipe)
5937 * Only async flip capable planes should be in the state
5938 * if we're really about to ask the hardware to perform
5939 * an async flip. We should never get this far otherwise.
5941 if (drm_WARN_ON(&i915->drm,
5942 new_crtc_state->do_async_flip && !plane->async_flip))
5946 * Only check async flip capable planes other planes
5947 * may be involved in the initial commit due to
5948 * the wm0/ddb optimization.
5950 * TODO maybe should track which planes actually
5951 * were requested to do the async flip...
5953 if (!plane->async_flip)
5957 * FIXME: This check is kept generic for all platforms.
5958 * Need to verify this for all gen9 platforms to enable
5959 * this selectively if required.
5961 switch (new_plane_state->hw.fb->modifier) {
5962 case DRM_FORMAT_MOD_LINEAR:
5964 * FIXME: Async on Linear buffer is supported on ICL as
5965 * but with additional alignment and fbc restrictions
5966 * need to be taken care of. These aren't applicable for
5969 if (DISPLAY_VER(i915) < 12) {
5970 drm_dbg_kms(&i915->drm,
5971 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip on display ver %d\n",
5972 plane->base.base.id, plane->base.name,
5973 new_plane_state->hw.fb->modifier, DISPLAY_VER(i915));
5978 case I915_FORMAT_MOD_X_TILED:
5979 case I915_FORMAT_MOD_Y_TILED:
5980 case I915_FORMAT_MOD_Yf_TILED:
5981 case I915_FORMAT_MOD_4_TILED:
5984 drm_dbg_kms(&i915->drm,
5985 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip\n",
5986 plane->base.base.id, plane->base.name,
5987 new_plane_state->hw.fb->modifier);
5991 if (new_plane_state->hw.fb->format->num_planes > 1) {
5992 drm_dbg_kms(&i915->drm,
5993 "[PLANE:%d:%s] Planar formats do not support async flips\n",
5994 plane->base.base.id, plane->base.name);
5998 if (old_plane_state->view.color_plane[0].mapping_stride !=
5999 new_plane_state->view.color_plane[0].mapping_stride) {
6000 drm_dbg_kms(&i915->drm,
6001 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6002 plane->base.base.id, plane->base.name);
6006 if (old_plane_state->hw.fb->modifier !=
6007 new_plane_state->hw.fb->modifier) {
6008 drm_dbg_kms(&i915->drm,
6009 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6010 plane->base.base.id, plane->base.name);
6014 if (old_plane_state->hw.fb->format !=
6015 new_plane_state->hw.fb->format) {
6016 drm_dbg_kms(&i915->drm,
6017 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6018 plane->base.base.id, plane->base.name);
6022 if (old_plane_state->hw.rotation !=
6023 new_plane_state->hw.rotation) {
6024 drm_dbg_kms(&i915->drm,
6025 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6026 plane->base.base.id, plane->base.name);
6030 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6031 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6032 drm_dbg_kms(&i915->drm,
6033 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6034 plane->base.base.id, plane->base.name);
6038 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6039 drm_dbg_kms(&i915->drm,
6040 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6041 plane->base.base.id, plane->base.name);
6045 if (old_plane_state->hw.pixel_blend_mode !=
6046 new_plane_state->hw.pixel_blend_mode) {
6047 drm_dbg_kms(&i915->drm,
6048 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6049 plane->base.base.id, plane->base.name);
6053 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6054 drm_dbg_kms(&i915->drm,
6055 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6056 plane->base.base.id, plane->base.name);
6060 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6061 drm_dbg_kms(&i915->drm,
6062 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6063 plane->base.base.id, plane->base.name);
6067 /* plane decryption is allow to change only in synchronous flips */
6068 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6069 drm_dbg_kms(&i915->drm,
6070 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6071 plane->base.base.id, plane->base.name);
6079 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6081 struct drm_i915_private *i915 = to_i915(state->base.dev);
6082 struct intel_crtc_state *crtc_state;
6083 struct intel_crtc *crtc;
6084 u8 affected_pipes = 0;
6085 u8 modeset_pipes = 0;
6088 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6089 affected_pipes |= crtc_state->bigjoiner_pipes;
6090 if (intel_crtc_needs_modeset(crtc_state))
6091 modeset_pipes |= crtc_state->bigjoiner_pipes;
6094 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6095 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6096 if (IS_ERR(crtc_state))
6097 return PTR_ERR(crtc_state);
6100 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6103 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6105 crtc_state->uapi.mode_changed = true;
6107 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6111 ret = intel_atomic_add_affected_planes(state, crtc);
6116 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6117 /* Kill old bigjoiner link, we may re-establish afterwards */
6118 if (intel_crtc_needs_modeset(crtc_state) &&
6119 intel_crtc_is_bigjoiner_master(crtc_state))
6120 kill_bigjoiner_slave(state, crtc);
6126 static int intel_atomic_check_config(struct intel_atomic_state *state,
6127 struct intel_link_bw_limits *limits,
6128 enum pipe *failed_pipe)
6130 struct drm_i915_private *i915 = to_i915(state->base.dev);
6131 struct intel_crtc_state *new_crtc_state;
6132 struct intel_crtc *crtc;
6136 *failed_pipe = INVALID_PIPE;
6138 ret = intel_bigjoiner_add_affected_crtcs(state);
6142 ret = intel_fdi_add_affected_crtcs(state);
6146 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6147 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6148 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6149 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6151 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6155 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6156 drm_WARN_ON(&i915->drm, new_crtc_state->uapi.enable);
6160 ret = intel_crtc_prepare_cleared_state(state, crtc);
6164 if (!new_crtc_state->hw.enable)
6167 ret = intel_modeset_pipe_config(state, crtc, limits);
6171 ret = intel_atomic_check_bigjoiner(state, crtc);
6177 *failed_pipe = crtc->pipe;
6182 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state)
6184 struct drm_i915_private *i915 = to_i915(state->base.dev);
6185 struct intel_link_bw_limits new_limits;
6186 struct intel_link_bw_limits old_limits;
6189 intel_link_bw_init_limits(i915, &new_limits);
6190 old_limits = new_limits;
6193 enum pipe failed_pipe;
6195 ret = intel_atomic_check_config(state, &new_limits,
6199 * The bpp limit for a pipe is below the minimum it supports, set the
6200 * limit to the minimum and recalculate the config.
6202 if (ret == -EINVAL &&
6203 intel_link_bw_set_bpp_limit_for_pipe(state,
6212 old_limits = new_limits;
6214 ret = intel_link_bw_atomic_check(state, &new_limits);
6222 * intel_atomic_check - validate state object
6224 * @_state: state to validate
6226 int intel_atomic_check(struct drm_device *dev,
6227 struct drm_atomic_state *_state)
6229 struct drm_i915_private *dev_priv = to_i915(dev);
6230 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6231 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6232 struct intel_crtc *crtc;
6234 bool any_ms = false;
6236 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6237 new_crtc_state, i) {
6239 * crtc's state no longer considered to be inherited
6240 * after the first userspace/client initiated commit.
6242 if (!state->internal)
6243 new_crtc_state->inherited = false;
6245 if (new_crtc_state->inherited != old_crtc_state->inherited)
6246 new_crtc_state->uapi.mode_changed = true;
6248 if (new_crtc_state->uapi.scaling_filter !=
6249 old_crtc_state->uapi.scaling_filter)
6250 new_crtc_state->uapi.mode_changed = true;
6253 intel_vrr_check_modeset(state);
6255 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6259 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6260 ret = intel_async_flip_check_uapi(state, crtc);
6265 ret = intel_atomic_check_config_and_link(state);
6269 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6270 new_crtc_state, i) {
6271 if (!intel_crtc_needs_modeset(new_crtc_state))
6274 if (new_crtc_state->hw.enable) {
6275 ret = intel_modeset_pipe_config_late(state, crtc);
6280 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6284 * Check if fastset is allowed by external dependencies like other
6285 * pipes and transcoders.
6287 * Right now it only forces a fullmodeset when the MST master
6288 * transcoder did not changed but the pipe of the master transcoder
6289 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6290 * in case of port synced crtcs, if one of the synced crtcs
6291 * needs a full modeset, all other synced crtcs should be
6292 * forced a full modeset.
6294 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6295 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6298 if (intel_dp_mst_crtc_needs_modeset(state, crtc))
6299 intel_crtc_flag_modeset(new_crtc_state);
6301 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6302 enum transcoder master = new_crtc_state->mst_master_transcoder;
6304 if (intel_cpu_transcoders_need_modeset(state, BIT(master)))
6305 intel_crtc_flag_modeset(new_crtc_state);
6308 if (is_trans_port_sync_mode(new_crtc_state)) {
6309 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6311 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6312 trans |= BIT(new_crtc_state->master_transcoder);
6314 if (intel_cpu_transcoders_need_modeset(state, trans))
6315 intel_crtc_flag_modeset(new_crtc_state);
6318 if (new_crtc_state->bigjoiner_pipes) {
6319 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes))
6320 intel_crtc_flag_modeset(new_crtc_state);
6324 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6325 new_crtc_state, i) {
6326 if (!intel_crtc_needs_modeset(new_crtc_state))
6331 intel_release_shared_dplls(state, crtc);
6334 if (any_ms && !check_digital_port_conflicts(state)) {
6335 drm_dbg_kms(&dev_priv->drm,
6336 "rejecting conflicting digital port configuration\n");
6341 ret = intel_atomic_check_planes(state);
6345 ret = intel_compute_global_watermarks(state);
6349 ret = intel_bw_atomic_check(state);
6353 ret = intel_cdclk_atomic_check(state, &any_ms);
6357 if (intel_any_crtc_needs_modeset(state))
6361 ret = intel_modeset_checks(state);
6365 ret = intel_modeset_calc_cdclk(state);
6370 ret = intel_pmdemand_atomic_check(state);
6374 ret = intel_atomic_check_crtcs(state);
6378 ret = intel_fbc_atomic_check(state);
6382 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6383 new_crtc_state, i) {
6384 intel_color_assert_luts(new_crtc_state);
6386 ret = intel_async_flip_check_hw(state, crtc);
6390 /* Either full modeset or fastset (or neither), never both */
6391 drm_WARN_ON(&dev_priv->drm,
6392 intel_crtc_needs_modeset(new_crtc_state) &&
6393 intel_crtc_needs_fastset(new_crtc_state));
6395 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6396 !intel_crtc_needs_fastset(new_crtc_state))
6399 intel_crtc_state_dump(new_crtc_state, state,
6400 intel_crtc_needs_modeset(new_crtc_state) ?
6401 "modeset" : "fastset");
6407 if (ret == -EDEADLK)
6411 * FIXME would probably be nice to know which crtc specifically
6412 * caused the failure, in cases where we can pinpoint it.
6414 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6416 intel_crtc_state_dump(new_crtc_state, state, "failed");
6421 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6423 struct intel_crtc_state *crtc_state;
6424 struct intel_crtc *crtc;
6427 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6431 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6432 if (intel_crtc_needs_color_update(crtc_state))
6433 intel_color_prepare_commit(crtc_state);
6439 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
6440 struct intel_crtc_state *crtc_state)
6442 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6444 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
6445 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
6447 if (crtc_state->has_pch_encoder) {
6448 enum pipe pch_transcoder =
6449 intel_crtc_pch_transcoder(crtc);
6451 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
6455 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
6456 const struct intel_crtc_state *new_crtc_state)
6458 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6459 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6462 * Update pipe size and adjust fitter if needed: the reason for this is
6463 * that in compute_mode_changes we check the native mode (not the pfit
6464 * mode) to see if we can flip rather than do a full mode set. In the
6465 * fastboot case, we'll flip, but if we don't update the pipesrc and
6466 * pfit state, we'll end up with a big fb scanned out into the wrong
6469 intel_set_pipe_src_size(new_crtc_state);
6471 /* on skylake this is done by detaching scalers */
6472 if (DISPLAY_VER(dev_priv) >= 9) {
6473 if (new_crtc_state->pch_pfit.enabled)
6474 skl_pfit_enable(new_crtc_state);
6475 } else if (HAS_PCH_SPLIT(dev_priv)) {
6476 if (new_crtc_state->pch_pfit.enabled)
6477 ilk_pfit_enable(new_crtc_state);
6478 else if (old_crtc_state->pch_pfit.enabled)
6479 ilk_pfit_disable(old_crtc_state);
6483 * The register is supposedly single buffered so perhaps
6484 * not 100% correct to do this here. But SKL+ calculate
6485 * this based on the adjust pixel rate so pfit changes do
6486 * affect it and so it must be updated for fastsets.
6487 * HSW/BDW only really need this here for fastboot, after
6488 * that the value should not change without a full modeset.
6490 if (DISPLAY_VER(dev_priv) >= 9 ||
6491 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
6492 hsw_set_linetime_wm(new_crtc_state);
6494 if (new_crtc_state->update_m_n)
6495 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
6496 &new_crtc_state->dp_m_n);
6498 if (new_crtc_state->update_lrr)
6499 intel_set_transcoder_timings_lrr(new_crtc_state);
6502 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
6503 struct intel_crtc *crtc)
6505 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6506 const struct intel_crtc_state *old_crtc_state =
6507 intel_atomic_get_old_crtc_state(state, crtc);
6508 const struct intel_crtc_state *new_crtc_state =
6509 intel_atomic_get_new_crtc_state(state, crtc);
6510 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6513 * During modesets pipe configuration was programmed as the
6517 if (intel_crtc_needs_color_update(new_crtc_state))
6518 intel_color_commit_arm(new_crtc_state);
6520 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6521 bdw_set_pipe_misc(new_crtc_state);
6523 if (intel_crtc_needs_fastset(new_crtc_state))
6524 intel_pipe_fastset(old_crtc_state, new_crtc_state);
6527 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
6529 intel_atomic_update_watermarks(state, crtc);
6532 static void commit_pipe_post_planes(struct intel_atomic_state *state,
6533 struct intel_crtc *crtc)
6535 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6536 const struct intel_crtc_state *old_crtc_state =
6537 intel_atomic_get_old_crtc_state(state, crtc);
6538 const struct intel_crtc_state *new_crtc_state =
6539 intel_atomic_get_new_crtc_state(state, crtc);
6542 * Disable the scaler(s) after the plane(s) so that we don't
6543 * get a catastrophic underrun even if the two operations
6544 * end up happening in two different frames.
6546 if (DISPLAY_VER(dev_priv) >= 9 &&
6547 !intel_crtc_needs_modeset(new_crtc_state))
6548 skl_detach_scalers(new_crtc_state);
6550 if (vrr_enabling(old_crtc_state, new_crtc_state))
6551 intel_vrr_enable(new_crtc_state);
6554 static void intel_enable_crtc(struct intel_atomic_state *state,
6555 struct intel_crtc *crtc)
6557 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6558 const struct intel_crtc_state *new_crtc_state =
6559 intel_atomic_get_new_crtc_state(state, crtc);
6561 if (!intel_crtc_needs_modeset(new_crtc_state))
6564 /* VRR will be enable later, if required */
6565 intel_crtc_update_active_timings(new_crtc_state, false);
6567 dev_priv->display.funcs.display->crtc_enable(state, crtc);
6569 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6572 /* vblanks work again, re-enable pipe CRC. */
6573 intel_crtc_enable_pipe_crc(crtc);
6576 static void intel_pre_update_crtc(struct intel_atomic_state *state,
6577 struct intel_crtc *crtc)
6579 struct drm_i915_private *i915 = to_i915(state->base.dev);
6580 const struct intel_crtc_state *old_crtc_state =
6581 intel_atomic_get_old_crtc_state(state, crtc);
6582 struct intel_crtc_state *new_crtc_state =
6583 intel_atomic_get_new_crtc_state(state, crtc);
6584 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6586 if (old_crtc_state->inherited ||
6587 intel_crtc_needs_modeset(new_crtc_state)) {
6589 intel_dpt_configure(crtc);
6593 if (new_crtc_state->preload_luts &&
6594 intel_crtc_needs_color_update(new_crtc_state))
6595 intel_color_load_luts(new_crtc_state);
6597 intel_pre_plane_update(state, crtc);
6599 if (intel_crtc_needs_fastset(new_crtc_state))
6600 intel_encoders_update_pipe(state, crtc);
6602 if (DISPLAY_VER(i915) >= 11 &&
6603 intel_crtc_needs_fastset(new_crtc_state))
6604 icl_set_pipe_chicken(new_crtc_state);
6606 if (vrr_params_changed(old_crtc_state, new_crtc_state))
6607 intel_vrr_set_transcoder_timings(new_crtc_state);
6610 intel_fbc_update(state, crtc);
6612 drm_WARN_ON(&i915->drm, !intel_display_power_is_enabled(i915, POWER_DOMAIN_DC_OFF));
6615 intel_crtc_needs_color_update(new_crtc_state))
6616 intel_color_commit_noarm(new_crtc_state);
6618 intel_crtc_planes_update_noarm(state, crtc);
6621 static void intel_update_crtc(struct intel_atomic_state *state,
6622 struct intel_crtc *crtc)
6624 const struct intel_crtc_state *old_crtc_state =
6625 intel_atomic_get_old_crtc_state(state, crtc);
6626 struct intel_crtc_state *new_crtc_state =
6627 intel_atomic_get_new_crtc_state(state, crtc);
6629 /* Perform vblank evasion around commit operation */
6630 intel_pipe_update_start(state, crtc);
6632 commit_pipe_pre_planes(state, crtc);
6634 intel_crtc_planes_update_arm(state, crtc);
6636 commit_pipe_post_planes(state, crtc);
6638 intel_pipe_update_end(state, crtc);
6641 * VRR/Seamless M/N update may need to update frame timings.
6643 * FIXME Should be synchronized with the start of vblank somehow...
6645 if (vrr_enabling(old_crtc_state, new_crtc_state) ||
6646 new_crtc_state->update_m_n || new_crtc_state->update_lrr)
6647 intel_crtc_update_active_timings(new_crtc_state,
6648 new_crtc_state->vrr.enable);
6651 * We usually enable FIFO underrun interrupts as part of the
6652 * CRTC enable sequence during modesets. But when we inherit a
6653 * valid pipe configuration from the BIOS we need to take care
6654 * of enabling them on the CRTC's first fastset.
6656 if (intel_crtc_needs_fastset(new_crtc_state) &&
6657 old_crtc_state->inherited)
6658 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
6661 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
6662 struct intel_crtc_state *old_crtc_state,
6663 struct intel_crtc_state *new_crtc_state,
6664 struct intel_crtc *crtc)
6666 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6669 * We need to disable pipe CRC before disabling the pipe,
6670 * or we race against vblank off.
6672 intel_crtc_disable_pipe_crc(crtc);
6674 dev_priv->display.funcs.display->crtc_disable(state, crtc);
6675 crtc->active = false;
6676 intel_fbc_disable(crtc);
6678 if (!new_crtc_state->hw.active)
6679 intel_initial_watermarks(state, crtc);
6682 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
6684 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6685 struct intel_crtc *crtc;
6689 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6690 new_crtc_state, i) {
6691 if (!intel_crtc_needs_modeset(new_crtc_state))
6694 intel_pre_plane_update(state, crtc);
6696 if (!old_crtc_state->hw.active)
6699 intel_crtc_disable_planes(state, crtc);
6702 /* Only disable port sync and MST slaves */
6703 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6704 new_crtc_state, i) {
6705 if (!intel_crtc_needs_modeset(new_crtc_state))
6708 if (!old_crtc_state->hw.active)
6711 /* In case of Transcoder port Sync master slave CRTCs can be
6712 * assigned in any order and we need to make sure that
6713 * slave CRTCs are disabled first and then master CRTC since
6714 * Slave vblanks are masked till Master Vblanks.
6716 if (!is_trans_port_sync_slave(old_crtc_state) &&
6717 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
6718 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
6721 intel_old_crtc_state_disables(state, old_crtc_state,
6722 new_crtc_state, crtc);
6723 handled |= BIT(crtc->pipe);
6726 /* Disable everything else left on */
6727 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6728 new_crtc_state, i) {
6729 if (!intel_crtc_needs_modeset(new_crtc_state) ||
6730 (handled & BIT(crtc->pipe)))
6733 if (!old_crtc_state->hw.active)
6736 intel_old_crtc_state_disables(state, old_crtc_state,
6737 new_crtc_state, crtc);
6741 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
6743 struct intel_crtc_state *new_crtc_state;
6744 struct intel_crtc *crtc;
6747 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6748 if (!new_crtc_state->hw.active)
6751 intel_enable_crtc(state, crtc);
6752 intel_pre_update_crtc(state, crtc);
6755 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6756 if (!new_crtc_state->hw.active)
6759 intel_update_crtc(state, crtc);
6763 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
6765 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6766 struct intel_crtc *crtc;
6767 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6768 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6769 u8 update_pipes = 0, modeset_pipes = 0;
6772 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
6773 enum pipe pipe = crtc->pipe;
6775 if (!new_crtc_state->hw.active)
6778 /* ignore allocations for crtc's that have been turned off. */
6779 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6780 entries[pipe] = old_crtc_state->wm.skl.ddb;
6781 update_pipes |= BIT(pipe);
6783 modeset_pipes |= BIT(pipe);
6788 * Whenever the number of active pipes changes, we need to make sure we
6789 * update the pipes in the right order so that their ddb allocations
6790 * never overlap with each other between CRTC updates. Otherwise we'll
6791 * cause pipe underruns and other bad stuff.
6793 * So first lets enable all pipes that do not need a fullmodeset as
6794 * those don't have any external dependency.
6796 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6797 enum pipe pipe = crtc->pipe;
6799 if ((update_pipes & BIT(pipe)) == 0)
6802 intel_pre_update_crtc(state, crtc);
6805 while (update_pipes) {
6806 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6807 new_crtc_state, i) {
6808 enum pipe pipe = crtc->pipe;
6810 if ((update_pipes & BIT(pipe)) == 0)
6813 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6814 entries, I915_MAX_PIPES, pipe))
6817 entries[pipe] = new_crtc_state->wm.skl.ddb;
6818 update_pipes &= ~BIT(pipe);
6820 intel_update_crtc(state, crtc);
6823 * If this is an already active pipe, it's DDB changed,
6824 * and this isn't the last pipe that needs updating
6825 * then we need to wait for a vblank to pass for the
6826 * new ddb allocation to take effect.
6828 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
6829 &old_crtc_state->wm.skl.ddb) &&
6830 (update_pipes | modeset_pipes))
6831 intel_crtc_wait_for_next_vblank(crtc);
6835 update_pipes = modeset_pipes;
6838 * Enable all pipes that needs a modeset and do not depends on other
6841 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6842 enum pipe pipe = crtc->pipe;
6844 if ((modeset_pipes & BIT(pipe)) == 0)
6847 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
6848 is_trans_port_sync_master(new_crtc_state) ||
6849 intel_crtc_is_bigjoiner_master(new_crtc_state))
6852 modeset_pipes &= ~BIT(pipe);
6854 intel_enable_crtc(state, crtc);
6858 * Then we enable all remaining pipes that depend on other
6859 * pipes: MST slaves and port sync masters, big joiner master
6861 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6862 enum pipe pipe = crtc->pipe;
6864 if ((modeset_pipes & BIT(pipe)) == 0)
6867 modeset_pipes &= ~BIT(pipe);
6869 intel_enable_crtc(state, crtc);
6873 * Finally we do the plane updates/etc. for all pipes that got enabled.
6875 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6876 enum pipe pipe = crtc->pipe;
6878 if ((update_pipes & BIT(pipe)) == 0)
6881 intel_pre_update_crtc(state, crtc);
6884 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6885 enum pipe pipe = crtc->pipe;
6887 if ((update_pipes & BIT(pipe)) == 0)
6890 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6891 entries, I915_MAX_PIPES, pipe));
6893 entries[pipe] = new_crtc_state->wm.skl.ddb;
6894 update_pipes &= ~BIT(pipe);
6896 intel_update_crtc(state, crtc);
6899 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
6900 drm_WARN_ON(&dev_priv->drm, update_pipes);
6903 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
6905 struct intel_atomic_state *state, *next;
6906 struct llist_node *freed;
6908 freed = llist_del_all(&dev_priv->display.atomic_helper.free_list);
6909 llist_for_each_entry_safe(state, next, freed, freed)
6910 drm_atomic_state_put(&state->base);
6913 void intel_atomic_helper_free_state_worker(struct work_struct *work)
6915 struct drm_i915_private *dev_priv =
6916 container_of(work, typeof(*dev_priv), display.atomic_helper.free_work);
6918 intel_atomic_helper_free_state(dev_priv);
6921 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
6923 struct drm_i915_private *i915 = to_i915(intel_state->base.dev);
6924 struct drm_plane *plane;
6925 struct drm_plane_state *new_plane_state;
6928 for_each_new_plane_in_state(&intel_state->base, plane, new_plane_state, i) {
6929 if (new_plane_state->fence) {
6930 ret = dma_fence_wait_timeout(new_plane_state->fence, false,
6931 i915_fence_timeout(i915));
6935 dma_fence_put(new_plane_state->fence);
6936 new_plane_state->fence = NULL;
6941 static void intel_atomic_cleanup_work(struct work_struct *work)
6943 struct intel_atomic_state *state =
6944 container_of(work, struct intel_atomic_state, base.commit_work);
6945 struct drm_i915_private *i915 = to_i915(state->base.dev);
6946 struct intel_crtc_state *old_crtc_state;
6947 struct intel_crtc *crtc;
6950 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
6951 intel_color_cleanup_commit(old_crtc_state);
6953 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
6954 drm_atomic_helper_commit_cleanup_done(&state->base);
6955 drm_atomic_state_put(&state->base);
6957 intel_atomic_helper_free_state(i915);
6960 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
6962 struct drm_i915_private *i915 = to_i915(state->base.dev);
6963 struct intel_plane *plane;
6964 struct intel_plane_state *plane_state;
6967 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6968 struct drm_framebuffer *fb = plane_state->hw.fb;
6975 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
6980 * The layout of the fast clear color value expected by HW
6981 * (the DRM ABI requiring this value to be located in fb at
6982 * offset 0 of cc plane, plane #2 previous generations or
6983 * plane #1 for flat ccs):
6984 * - 4 x 4 bytes per-channel value
6985 * (in surface type specific float/int format provided by the fb user)
6986 * - 8 bytes native color value used by the display
6987 * (converted/written by GPU during a fast clear operation using the
6988 * above per-channel values)
6990 * The commit's FB prepare hook already ensured that FB obj is pinned and the
6991 * caller made sure that the object is synced wrt. the related color clear value
6994 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
6995 fb->offsets[cc_plane] + 16,
6996 &plane_state->ccval,
6997 sizeof(plane_state->ccval));
6998 /* The above could only fail if the FB obj has an unexpected backing store type. */
6999 drm_WARN_ON(&i915->drm, ret);
7003 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7005 struct drm_device *dev = state->base.dev;
7006 struct drm_i915_private *dev_priv = to_i915(dev);
7007 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7008 struct intel_crtc *crtc;
7009 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7010 intel_wakeref_t wakeref = 0;
7013 intel_atomic_commit_fence_wait(state);
7015 drm_atomic_helper_wait_for_dependencies(&state->base);
7016 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
7019 * During full modesets we write a lot of registers, wait
7020 * for PLLs, etc. Doing that while DC states are enabled
7021 * is not a good idea.
7023 * During fastsets and other updates we also need to
7024 * disable DC states due to the following scenario:
7025 * 1. DC5 exit and PSR exit happen
7026 * 2. Some or all _noarm() registers are written
7027 * 3. Due to some long delay PSR is re-entered
7028 * 4. DC5 entry -> DMC saves the already written new
7029 * _noarm() registers and the old not yet written
7031 * 5. DC5 exit -> DMC restores a mixture of old and
7032 * new register values and arms the update
7033 * 6. PSR exit -> hardware latches a mixture of old and
7034 * new register values -> corrupted frame, or worse
7035 * 7. New _arm() registers are finally written
7036 * 8. Hardware finally latches a complete set of new
7037 * register values, and subsequent frames will be OK again
7039 * Also note that due to the pipe CSC hardware issues on
7040 * SKL/GLK DC states must remain off until the pipe CSC
7041 * state readout has happened. Otherwise we risk corrupting
7042 * the CSC latched register values with the readout (see
7043 * skl_read_csc() and skl_color_commit_noarm()).
7045 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DC_OFF);
7047 intel_atomic_prepare_plane_clear_colors(state);
7049 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7050 new_crtc_state, i) {
7051 if (intel_crtc_needs_modeset(new_crtc_state) ||
7052 intel_crtc_needs_fastset(new_crtc_state))
7053 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7056 intel_commit_modeset_disables(state);
7058 /* FIXME: Eventually get rid of our crtc->config pointer */
7059 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7060 crtc->config = new_crtc_state;
7063 * In XE_LPD+ Pmdemand combines many parameters such as voltage index,
7064 * plls, cdclk frequency, QGV point selection parameter etc. Voltage
7065 * index, cdclk/ddiclk frequencies are supposed to be configured before
7066 * the cdclk config is set.
7068 intel_pmdemand_pre_plane_update(state);
7070 if (state->modeset) {
7071 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7073 intel_set_cdclk_pre_plane_update(state);
7075 intel_modeset_verify_disabled(state);
7078 intel_sagv_pre_plane_update(state);
7080 /* Complete the events for pipes that have now been disabled */
7081 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7082 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7084 /* Complete events for now disable pipes here. */
7085 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7086 spin_lock_irq(&dev->event_lock);
7087 drm_crtc_send_vblank_event(&crtc->base,
7088 new_crtc_state->uapi.event);
7089 spin_unlock_irq(&dev->event_lock);
7091 new_crtc_state->uapi.event = NULL;
7095 intel_encoders_update_prepare(state);
7097 intel_dbuf_pre_plane_update(state);
7098 intel_mbus_dbox_update(state);
7100 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7101 if (new_crtc_state->do_async_flip)
7102 intel_crtc_enable_flip_done(state, crtc);
7105 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7106 dev_priv->display.funcs.display->commit_modeset_enables(state);
7109 intel_set_cdclk_post_plane_update(state);
7111 intel_wait_for_vblank_workers(state);
7113 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7114 * already, but still need the state for the delayed optimization. To
7116 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7117 * - schedule that vblank worker _before_ calling hw_done
7118 * - at the start of commit_tail, cancel it _synchrously
7119 * - switch over to the vblank wait helper in the core after that since
7120 * we don't need out special handling any more.
7122 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7124 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7125 if (new_crtc_state->do_async_flip)
7126 intel_crtc_disable_flip_done(state, crtc);
7128 intel_color_wait_commit(new_crtc_state);
7132 * Now that the vblank has passed, we can go ahead and program the
7133 * optimal watermarks on platforms that need two-step watermark
7136 * TODO: Move this (and other cleanup) to an async worker eventually.
7138 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7139 new_crtc_state, i) {
7141 * Gen2 reports pipe underruns whenever all planes are disabled.
7142 * So re-enable underrun reporting after some planes get enabled.
7144 * We do this before .optimize_watermarks() so that we have a
7145 * chance of catching underruns with the intermediate watermarks
7146 * vs. the new plane configuration.
7148 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7149 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7151 intel_optimize_watermarks(state, crtc);
7154 intel_dbuf_post_plane_update(state);
7156 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7157 intel_post_plane_update(state, crtc);
7159 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7161 intel_modeset_verify_crtc(state, crtc);
7163 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
7164 hsw_ips_post_update(state, crtc);
7167 * Activate DRRS after state readout to avoid
7168 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
7170 intel_drrs_activate(new_crtc_state);
7173 * DSB cleanup is done in cleanup_work aligning with framebuffer
7174 * cleanup. So copy and reset the dsb structure to sync with
7175 * commit_done and later do dsb cleanup in cleanup_work.
7177 * FIXME get rid of this funny new->old swapping
7179 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7182 /* Underruns don't always raise interrupts, so check manually */
7183 intel_check_cpu_fifo_underruns(dev_priv);
7184 intel_check_pch_fifo_underruns(dev_priv);
7187 intel_verify_planes(state);
7189 intel_sagv_post_plane_update(state);
7190 intel_pmdemand_post_plane_update(state);
7192 drm_atomic_helper_commit_hw_done(&state->base);
7194 if (state->modeset) {
7195 /* As one of the primary mmio accessors, KMS has a high
7196 * likelihood of triggering bugs in unclaimed access. After we
7197 * finish modesetting, see if an error has been flagged, and if
7198 * so enable debugging for the next modeset - and hope we catch
7201 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7204 * Delay re-enabling DC states by 17 ms to avoid the off->on->off
7205 * toggling overhead at and above 60 FPS.
7207 intel_display_power_put_async_delay(dev_priv, POWER_DOMAIN_DC_OFF, wakeref, 17);
7208 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7211 * Defer the cleanup of the old state to a separate worker to not
7212 * impede the current task (userspace for blocking modesets) that
7213 * are executed inline. For out-of-line asynchronous modesets/flips,
7214 * deferring to a new worker seems overkill, but we would place a
7215 * schedule point (cond_resched()) here anyway to keep latencies
7218 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7219 queue_work(system_highpri_wq, &state->base.commit_work);
7222 static void intel_atomic_commit_work(struct work_struct *work)
7224 struct intel_atomic_state *state =
7225 container_of(work, struct intel_atomic_state, base.commit_work);
7227 intel_atomic_commit_tail(state);
7230 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7232 struct intel_plane_state *old_plane_state, *new_plane_state;
7233 struct intel_plane *plane;
7236 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7238 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7239 to_intel_frontbuffer(new_plane_state->hw.fb),
7240 plane->frontbuffer_bit);
7243 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7246 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7247 struct drm_i915_private *dev_priv = to_i915(dev);
7250 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7253 * The intel_legacy_cursor_update() fast path takes care
7254 * of avoiding the vblank waits for simple cursor
7255 * movement and flips. For cursor on/off and size changes,
7256 * we want to perform the vblank waits so that watermark
7257 * updates happen during the correct frames. Gen9+ have
7258 * double buffered watermarks and so shouldn't need this.
7260 * Unset state->legacy_cursor_update before the call to
7261 * drm_atomic_helper_setup_commit() because otherwise
7262 * drm_atomic_helper_wait_for_flip_done() is a noop and
7263 * we get FIFO underruns because we didn't wait
7266 * FIXME doing watermarks and fb cleanup from a vblank worker
7267 * (assuming we had any) would solve these problems.
7269 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7270 struct intel_crtc_state *new_crtc_state;
7271 struct intel_crtc *crtc;
7274 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7275 if (new_crtc_state->wm.need_postvbl_update ||
7276 new_crtc_state->update_wm_post)
7277 state->base.legacy_cursor_update = false;
7280 ret = intel_atomic_prepare_commit(state);
7282 drm_dbg_atomic(&dev_priv->drm,
7283 "Preparing state failed with %i\n", ret);
7284 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7288 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7290 ret = drm_atomic_helper_swap_state(&state->base, true);
7292 intel_atomic_swap_global_state(state);
7295 struct intel_crtc_state *new_crtc_state;
7296 struct intel_crtc *crtc;
7299 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7300 intel_color_cleanup_commit(new_crtc_state);
7302 drm_atomic_helper_cleanup_planes(dev, &state->base);
7303 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7306 intel_shared_dpll_swap_state(state);
7307 intel_atomic_track_fbs(state);
7309 drm_atomic_state_get(&state->base);
7310 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7312 if (nonblock && state->modeset) {
7313 queue_work(dev_priv->display.wq.modeset, &state->base.commit_work);
7314 } else if (nonblock) {
7315 queue_work(dev_priv->display.wq.flip, &state->base.commit_work);
7318 flush_workqueue(dev_priv->display.wq.modeset);
7319 intel_atomic_commit_tail(state);
7326 * intel_plane_destroy - destroy a plane
7327 * @plane: plane to destroy
7329 * Common destruction function for all types of planes (primary, cursor,
7332 void intel_plane_destroy(struct drm_plane *plane)
7334 drm_plane_cleanup(plane);
7335 kfree(to_intel_plane(plane));
7338 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7339 struct drm_file *file)
7341 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7342 struct drm_crtc *drmmode_crtc;
7343 struct intel_crtc *crtc;
7345 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7349 crtc = to_intel_crtc(drmmode_crtc);
7350 pipe_from_crtc_id->pipe = crtc->pipe;
7355 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7357 struct drm_device *dev = encoder->base.dev;
7358 struct intel_encoder *source_encoder;
7359 u32 possible_clones = 0;
7361 for_each_intel_encoder(dev, source_encoder) {
7362 if (encoders_cloneable(encoder, source_encoder))
7363 possible_clones |= drm_encoder_mask(&source_encoder->base);
7366 return possible_clones;
7369 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7371 struct drm_device *dev = encoder->base.dev;
7372 struct intel_crtc *crtc;
7373 u32 possible_crtcs = 0;
7375 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7376 possible_crtcs |= drm_crtc_mask(&crtc->base);
7378 return possible_crtcs;
7381 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7383 if (!IS_MOBILE(dev_priv))
7386 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7389 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7395 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7397 if (DISPLAY_VER(dev_priv) >= 9)
7400 if (IS_HASWELL_ULT(dev_priv) || IS_BROADWELL_ULT(dev_priv))
7403 if (HAS_PCH_LPT_H(dev_priv) &&
7404 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7407 /* DDI E can't be used if DDI A requires 4 lanes */
7408 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7411 if (!dev_priv->display.vbt.int_crt_support)
7417 bool assert_port_valid(struct drm_i915_private *i915, enum port port)
7419 return !drm_WARN(&i915->drm, !(DISPLAY_RUNTIME_INFO(i915)->port_mask & BIT(port)),
7420 "Platform does not support port %c\n", port_name(port));
7423 void intel_setup_outputs(struct drm_i915_private *dev_priv)
7425 struct intel_encoder *encoder;
7426 bool dpd_is_edp = false;
7428 intel_pps_unlock_regs_wa(dev_priv);
7430 if (!HAS_DISPLAY(dev_priv))
7433 if (HAS_DDI(dev_priv)) {
7434 if (intel_ddi_crt_present(dev_priv))
7435 intel_crt_init(dev_priv);
7437 intel_bios_for_each_encoder(dev_priv, intel_ddi_init);
7439 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
7440 vlv_dsi_init(dev_priv);
7441 } else if (HAS_PCH_SPLIT(dev_priv)) {
7445 * intel_edp_init_connector() depends on this completing first,
7446 * to prevent the registration of both eDP and LVDS and the
7447 * incorrect sharing of the PPS.
7449 intel_lvds_init(dev_priv);
7450 intel_crt_init(dev_priv);
7452 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
7454 if (ilk_has_edp_a(dev_priv))
7455 g4x_dp_init(dev_priv, DP_A, PORT_A);
7457 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
7458 /* PCH SDVOB multiplex with HDMIB */
7459 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
7461 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
7462 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
7463 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
7466 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
7467 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
7469 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
7470 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
7472 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
7473 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
7475 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
7476 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
7477 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7478 bool has_edp, has_port;
7480 if (IS_VALLEYVIEW(dev_priv) && dev_priv->display.vbt.int_crt_support)
7481 intel_crt_init(dev_priv);
7484 * The DP_DETECTED bit is the latched state of the DDC
7485 * SDA pin at boot. However since eDP doesn't require DDC
7486 * (no way to plug in a DP->HDMI dongle) the DDC pins for
7487 * eDP ports may have been muxed to an alternate function.
7488 * Thus we can't rely on the DP_DETECTED bit alone to detect
7489 * eDP ports. Consult the VBT as well as DP_DETECTED to
7492 * Sadly the straps seem to be missing sometimes even for HDMI
7493 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
7494 * and VBT for the presence of the port. Additionally we can't
7495 * trust the port type the VBT declares as we've seen at least
7496 * HDMI ports that the VBT claim are DP or eDP.
7498 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
7499 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
7500 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
7501 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
7502 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
7503 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
7505 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
7506 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
7507 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
7508 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
7509 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
7510 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
7512 if (IS_CHERRYVIEW(dev_priv)) {
7514 * eDP not supported on port D,
7515 * so no need to worry about it
7517 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
7518 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
7519 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
7520 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
7521 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
7524 vlv_dsi_init(dev_priv);
7525 } else if (IS_PINEVIEW(dev_priv)) {
7526 intel_lvds_init(dev_priv);
7527 intel_crt_init(dev_priv);
7528 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
7531 if (IS_MOBILE(dev_priv))
7532 intel_lvds_init(dev_priv);
7534 intel_crt_init(dev_priv);
7536 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7537 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
7538 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
7539 if (!found && IS_G4X(dev_priv)) {
7540 drm_dbg_kms(&dev_priv->drm,
7541 "probing HDMI on SDVOB\n");
7542 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
7545 if (!found && IS_G4X(dev_priv))
7546 g4x_dp_init(dev_priv, DP_B, PORT_B);
7549 /* Before G4X SDVOC doesn't have its own detect register */
7551 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7552 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
7553 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
7556 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
7558 if (IS_G4X(dev_priv)) {
7559 drm_dbg_kms(&dev_priv->drm,
7560 "probing HDMI on SDVOC\n");
7561 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
7563 if (IS_G4X(dev_priv))
7564 g4x_dp_init(dev_priv, DP_C, PORT_C);
7567 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
7568 g4x_dp_init(dev_priv, DP_D, PORT_D);
7570 if (SUPPORTS_TV(dev_priv))
7571 intel_tv_init(dev_priv);
7572 } else if (DISPLAY_VER(dev_priv) == 2) {
7573 if (IS_I85X(dev_priv))
7574 intel_lvds_init(dev_priv);
7576 intel_crt_init(dev_priv);
7577 intel_dvo_init(dev_priv);
7580 for_each_intel_encoder(&dev_priv->drm, encoder) {
7581 encoder->base.possible_crtcs =
7582 intel_encoder_possible_crtcs(encoder);
7583 encoder->base.possible_clones =
7584 intel_encoder_possible_clones(encoder);
7587 intel_init_pch_refclk(dev_priv);
7589 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
7592 static int max_dotclock(struct drm_i915_private *i915)
7594 int max_dotclock = i915->max_dotclk_freq;
7596 /* icl+ might use bigjoiner */
7597 if (DISPLAY_VER(i915) >= 11)
7600 return max_dotclock;
7603 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
7604 const struct drm_display_mode *mode)
7606 struct drm_i915_private *dev_priv = to_i915(dev);
7607 int hdisplay_max, htotal_max;
7608 int vdisplay_max, vtotal_max;
7611 * Can't reject DBLSCAN here because Xorg ddxen can add piles
7612 * of DBLSCAN modes to the output's mode list when they detect
7613 * the scaling mode property on the connector. And they don't
7614 * ask the kernel to validate those modes in any way until
7615 * modeset time at which point the client gets a protocol error.
7616 * So in order to not upset those clients we silently ignore the
7617 * DBLSCAN flag on such connectors. For other connectors we will
7618 * reject modes with the DBLSCAN flag in encoder->compute_config().
7619 * And we always reject DBLSCAN modes in connector->mode_valid()
7620 * as we never want such modes on the connector's mode list.
7623 if (mode->vscan > 1)
7624 return MODE_NO_VSCAN;
7626 if (mode->flags & DRM_MODE_FLAG_HSKEW)
7627 return MODE_H_ILLEGAL;
7629 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
7630 DRM_MODE_FLAG_NCSYNC |
7631 DRM_MODE_FLAG_PCSYNC))
7634 if (mode->flags & (DRM_MODE_FLAG_BCAST |
7635 DRM_MODE_FLAG_PIXMUX |
7636 DRM_MODE_FLAG_CLKDIV2))
7640 * Reject clearly excessive dotclocks early to
7641 * avoid having to worry about huge integers later.
7643 if (mode->clock > max_dotclock(dev_priv))
7644 return MODE_CLOCK_HIGH;
7646 /* Transcoder timing limits */
7647 if (DISPLAY_VER(dev_priv) >= 11) {
7648 hdisplay_max = 16384;
7649 vdisplay_max = 8192;
7652 } else if (DISPLAY_VER(dev_priv) >= 9 ||
7653 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
7654 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
7655 vdisplay_max = 4096;
7658 } else if (DISPLAY_VER(dev_priv) >= 3) {
7659 hdisplay_max = 4096;
7660 vdisplay_max = 4096;
7664 hdisplay_max = 2048;
7665 vdisplay_max = 2048;
7670 if (mode->hdisplay > hdisplay_max ||
7671 mode->hsync_start > htotal_max ||
7672 mode->hsync_end > htotal_max ||
7673 mode->htotal > htotal_max)
7674 return MODE_H_ILLEGAL;
7676 if (mode->vdisplay > vdisplay_max ||
7677 mode->vsync_start > vtotal_max ||
7678 mode->vsync_end > vtotal_max ||
7679 mode->vtotal > vtotal_max)
7680 return MODE_V_ILLEGAL;
7682 if (DISPLAY_VER(dev_priv) >= 5) {
7683 if (mode->hdisplay < 64 ||
7684 mode->htotal - mode->hdisplay < 32)
7685 return MODE_H_ILLEGAL;
7687 if (mode->vtotal - mode->vdisplay < 5)
7688 return MODE_V_ILLEGAL;
7690 if (mode->htotal - mode->hdisplay < 32)
7691 return MODE_H_ILLEGAL;
7693 if (mode->vtotal - mode->vdisplay < 3)
7694 return MODE_V_ILLEGAL;
7698 * Cantiga+ cannot handle modes with a hsync front porch of 0.
7699 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7701 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7702 mode->hsync_start == mode->hdisplay)
7703 return MODE_H_ILLEGAL;
7708 enum drm_mode_status
7709 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
7710 const struct drm_display_mode *mode,
7713 int plane_width_max, plane_height_max;
7716 * intel_mode_valid() should be
7717 * sufficient on older platforms.
7719 if (DISPLAY_VER(dev_priv) < 9)
7723 * Most people will probably want a fullscreen
7724 * plane so let's not advertize modes that are
7727 if (DISPLAY_VER(dev_priv) >= 11) {
7728 plane_width_max = 5120 << bigjoiner;
7729 plane_height_max = 4320;
7731 plane_width_max = 5120;
7732 plane_height_max = 4096;
7735 if (mode->hdisplay > plane_width_max)
7736 return MODE_H_ILLEGAL;
7738 if (mode->vdisplay > plane_height_max)
7739 return MODE_V_ILLEGAL;
7744 static const struct intel_display_funcs skl_display_funcs = {
7745 .get_pipe_config = hsw_get_pipe_config,
7746 .crtc_enable = hsw_crtc_enable,
7747 .crtc_disable = hsw_crtc_disable,
7748 .commit_modeset_enables = skl_commit_modeset_enables,
7749 .get_initial_plane_config = skl_get_initial_plane_config,
7752 static const struct intel_display_funcs ddi_display_funcs = {
7753 .get_pipe_config = hsw_get_pipe_config,
7754 .crtc_enable = hsw_crtc_enable,
7755 .crtc_disable = hsw_crtc_disable,
7756 .commit_modeset_enables = intel_commit_modeset_enables,
7757 .get_initial_plane_config = i9xx_get_initial_plane_config,
7760 static const struct intel_display_funcs pch_split_display_funcs = {
7761 .get_pipe_config = ilk_get_pipe_config,
7762 .crtc_enable = ilk_crtc_enable,
7763 .crtc_disable = ilk_crtc_disable,
7764 .commit_modeset_enables = intel_commit_modeset_enables,
7765 .get_initial_plane_config = i9xx_get_initial_plane_config,
7768 static const struct intel_display_funcs vlv_display_funcs = {
7769 .get_pipe_config = i9xx_get_pipe_config,
7770 .crtc_enable = valleyview_crtc_enable,
7771 .crtc_disable = i9xx_crtc_disable,
7772 .commit_modeset_enables = intel_commit_modeset_enables,
7773 .get_initial_plane_config = i9xx_get_initial_plane_config,
7776 static const struct intel_display_funcs i9xx_display_funcs = {
7777 .get_pipe_config = i9xx_get_pipe_config,
7778 .crtc_enable = i9xx_crtc_enable,
7779 .crtc_disable = i9xx_crtc_disable,
7780 .commit_modeset_enables = intel_commit_modeset_enables,
7781 .get_initial_plane_config = i9xx_get_initial_plane_config,
7785 * intel_init_display_hooks - initialize the display modesetting hooks
7786 * @dev_priv: device private
7788 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
7790 if (DISPLAY_VER(dev_priv) >= 9) {
7791 dev_priv->display.funcs.display = &skl_display_funcs;
7792 } else if (HAS_DDI(dev_priv)) {
7793 dev_priv->display.funcs.display = &ddi_display_funcs;
7794 } else if (HAS_PCH_SPLIT(dev_priv)) {
7795 dev_priv->display.funcs.display = &pch_split_display_funcs;
7796 } else if (IS_CHERRYVIEW(dev_priv) ||
7797 IS_VALLEYVIEW(dev_priv)) {
7798 dev_priv->display.funcs.display = &vlv_display_funcs;
7800 dev_priv->display.funcs.display = &i9xx_display_funcs;
7804 int intel_initial_commit(struct drm_device *dev)
7806 struct drm_atomic_state *state = NULL;
7807 struct drm_modeset_acquire_ctx ctx;
7808 struct intel_crtc *crtc;
7811 state = drm_atomic_state_alloc(dev);
7815 drm_modeset_acquire_init(&ctx, 0);
7817 state->acquire_ctx = &ctx;
7818 to_intel_atomic_state(state)->internal = true;
7821 for_each_intel_crtc(dev, crtc) {
7822 struct intel_crtc_state *crtc_state =
7823 intel_atomic_get_crtc_state(state, crtc);
7825 if (IS_ERR(crtc_state)) {
7826 ret = PTR_ERR(crtc_state);
7830 if (crtc_state->hw.active) {
7831 struct intel_encoder *encoder;
7833 ret = drm_atomic_add_affected_planes(state, &crtc->base);
7838 * FIXME hack to force a LUT update to avoid the
7839 * plane update forcing the pipe gamma on without
7840 * having a proper LUT loaded. Remove once we
7841 * have readout for pipe gamma enable.
7843 crtc_state->uapi.color_mgmt_changed = true;
7845 for_each_intel_encoder_mask(dev, encoder,
7846 crtc_state->uapi.encoder_mask) {
7847 if (encoder->initial_fastset_check &&
7848 !encoder->initial_fastset_check(encoder, crtc_state)) {
7849 ret = drm_atomic_add_affected_connectors(state,
7858 ret = drm_atomic_commit(state);
7861 if (ret == -EDEADLK) {
7862 drm_atomic_state_clear(state);
7863 drm_modeset_backoff(&ctx);
7867 drm_atomic_state_put(state);
7869 drm_modeset_drop_locks(&ctx);
7870 drm_modeset_acquire_fini(&ctx);
7875 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
7877 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
7878 enum transcoder cpu_transcoder = (enum transcoder)pipe;
7879 /* 640x480@60Hz, ~25175 kHz */
7880 struct dpll clock = {
7890 drm_WARN_ON(&dev_priv->drm,
7891 i9xx_calc_dpll_params(48000, &clock) != 25154);
7893 drm_dbg_kms(&dev_priv->drm,
7894 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
7895 pipe_name(pipe), clock.vco, clock.dot);
7897 fp = i9xx_dpll_compute_fp(&clock);
7898 dpll = DPLL_DVO_2X_MODE |
7900 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
7901 PLL_P2_DIVIDE_BY_4 |
7902 PLL_REF_INPUT_DREFCLK |
7905 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
7906 HACTIVE(640 - 1) | HTOTAL(800 - 1));
7907 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
7908 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
7909 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
7910 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
7911 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
7912 VACTIVE(480 - 1) | VTOTAL(525 - 1));
7913 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
7914 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
7915 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
7916 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
7917 intel_de_write(dev_priv, PIPESRC(pipe),
7918 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
7920 intel_de_write(dev_priv, FP0(pipe), fp);
7921 intel_de_write(dev_priv, FP1(pipe), fp);
7924 * Apparently we need to have VGA mode enabled prior to changing
7925 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
7926 * dividers, even though the register value does change.
7928 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
7929 intel_de_write(dev_priv, DPLL(pipe), dpll);
7931 /* Wait for the clocks to stabilize. */
7932 intel_de_posting_read(dev_priv, DPLL(pipe));
7935 /* The pixel multiplier can only be updated once the
7936 * DPLL is enabled and the clocks are stable.
7938 * So write it again.
7940 intel_de_write(dev_priv, DPLL(pipe), dpll);
7942 /* We do this three times for luck */
7943 for (i = 0; i < 3 ; i++) {
7944 intel_de_write(dev_priv, DPLL(pipe), dpll);
7945 intel_de_posting_read(dev_priv, DPLL(pipe));
7946 udelay(150); /* wait for warmup */
7949 intel_de_write(dev_priv, TRANSCONF(pipe), TRANSCONF_ENABLE);
7950 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
7952 intel_wait_for_pipe_scanline_moving(crtc);
7955 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
7957 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
7959 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
7962 drm_WARN_ON(&dev_priv->drm,
7963 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
7964 drm_WARN_ON(&dev_priv->drm,
7965 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
7966 drm_WARN_ON(&dev_priv->drm,
7967 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
7968 drm_WARN_ON(&dev_priv->drm,
7969 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
7970 drm_WARN_ON(&dev_priv->drm,
7971 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
7973 intel_de_write(dev_priv, TRANSCONF(pipe), 0);
7974 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
7976 intel_wait_for_pipe_scanline_stopped(crtc);
7978 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
7979 intel_de_posting_read(dev_priv, DPLL(pipe));
7982 void intel_hpd_poll_fini(struct drm_i915_private *i915)
7984 struct intel_connector *connector;
7985 struct drm_connector_list_iter conn_iter;
7987 /* Kill all the work that may have been queued by hpd. */
7988 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
7989 for_each_intel_connector_iter(connector, &conn_iter) {
7990 if (connector->modeset_retry_work.func)
7991 cancel_work_sync(&connector->modeset_retry_work);
7992 if (connector->hdcp.shim) {
7993 cancel_delayed_work_sync(&connector->hdcp.check_work);
7994 cancel_work_sync(&connector->hdcp.prop_work);
7997 drm_connector_list_iter_end(&conn_iter);
8000 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
8002 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);