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 <acpi/video.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/intel-iommu.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/dma-resv.h>
34 #include <linux/slab.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_dp_helper.h>
41 #include <drm/drm_edid.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/drm_plane_helper.h>
44 #include <drm/drm_probe_helper.h>
45 #include <drm/drm_rect.h>
47 #include "display/intel_audio.h"
48 #include "display/intel_crt.h"
49 #include "display/intel_ddi.h"
50 #include "display/intel_display_debugfs.h"
51 #include "display/intel_dp.h"
52 #include "display/intel_dp_mst.h"
53 #include "display/intel_dpll.h"
54 #include "display/intel_dpll_mgr.h"
55 #include "display/intel_drrs.h"
56 #include "display/intel_dsi.h"
57 #include "display/intel_dvo.h"
58 #include "display/intel_fb.h"
59 #include "display/intel_gmbus.h"
60 #include "display/intel_hdmi.h"
61 #include "display/intel_lvds.h"
62 #include "display/intel_sdvo.h"
63 #include "display/intel_snps_phy.h"
64 #include "display/intel_tv.h"
65 #include "display/intel_vdsc.h"
66 #include "display/intel_vrr.h"
68 #include "gem/i915_gem_lmem.h"
69 #include "gem/i915_gem_object.h"
71 #include "gt/intel_rps.h"
72 #include "gt/gen8_ppgtt.h"
77 #include "intel_acpi.h"
78 #include "intel_atomic.h"
79 #include "intel_atomic_plane.h"
81 #include "intel_cdclk.h"
82 #include "intel_color.h"
83 #include "intel_crtc.h"
85 #include "intel_display_types.h"
86 #include "intel_dmc.h"
87 #include "intel_dp_link_training.h"
88 #include "intel_dpt.h"
89 #include "intel_fbc.h"
90 #include "intel_fdi.h"
91 #include "intel_fbdev.h"
92 #include "intel_fifo_underrun.h"
93 #include "intel_frontbuffer.h"
94 #include "intel_hdcp.h"
95 #include "intel_hotplug.h"
96 #include "intel_overlay.h"
97 #include "intel_panel.h"
98 #include "intel_pipe_crc.h"
100 #include "intel_pps.h"
101 #include "intel_psr.h"
102 #include "intel_quirks.h"
103 #include "intel_sideband.h"
104 #include "intel_sprite.h"
105 #include "intel_tc.h"
106 #include "intel_vga.h"
107 #include "i9xx_plane.h"
108 #include "skl_scaler.h"
109 #include "skl_universal_plane.h"
111 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
112 struct intel_crtc_state *pipe_config);
113 static void ilk_pch_clock_get(struct intel_crtc *crtc,
114 struct intel_crtc_state *pipe_config);
116 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
117 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
118 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
119 const struct intel_link_m_n *m_n,
120 const struct intel_link_m_n *m2_n2);
121 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
122 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
123 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
124 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
125 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
126 static void intel_modeset_setup_hw_state(struct drm_device *dev,
127 struct drm_modeset_acquire_ctx *ctx);
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 static 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)
197 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
198 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
200 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
201 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
204 /* Wa_2006604312:icl,ehl */
206 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
210 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
211 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
213 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
214 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
218 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
220 return crtc_state->master_transcoder != INVALID_TRANSCODER;
224 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
226 return crtc_state->sync_mode_slaves_mask != 0;
230 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
232 return is_trans_port_sync_master(crtc_state) ||
233 is_trans_port_sync_slave(crtc_state);
236 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
239 i915_reg_t reg = PIPEDSL(pipe);
243 if (DISPLAY_VER(dev_priv) == 2)
244 line_mask = DSL_LINEMASK_GEN2;
246 line_mask = DSL_LINEMASK_GEN3;
248 line1 = intel_de_read(dev_priv, reg) & line_mask;
250 line2 = intel_de_read(dev_priv, reg) & line_mask;
252 return line1 != line2;
255 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
257 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
258 enum pipe pipe = crtc->pipe;
260 /* Wait for the display line to settle/start moving */
261 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
262 drm_err(&dev_priv->drm,
263 "pipe %c scanline %s wait timed out\n",
264 pipe_name(pipe), onoff(state));
267 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
269 wait_for_pipe_scanline_moving(crtc, false);
272 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
274 wait_for_pipe_scanline_moving(crtc, true);
278 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
280 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
281 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
283 if (DISPLAY_VER(dev_priv) >= 4) {
284 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
285 i915_reg_t reg = PIPECONF(cpu_transcoder);
287 /* Wait for the Pipe State to go off */
288 if (intel_de_wait_for_clear(dev_priv, reg,
289 I965_PIPECONF_ACTIVE, 100))
290 drm_WARN(&dev_priv->drm, 1,
291 "pipe_off wait timed out\n");
293 intel_wait_for_pipe_scanline_stopped(crtc);
297 /* Only for pre-ILK configs */
298 void assert_pll(struct drm_i915_private *dev_priv,
299 enum pipe pipe, bool state)
304 val = intel_de_read(dev_priv, DPLL(pipe));
305 cur_state = !!(val & DPLL_VCO_ENABLE);
306 I915_STATE_WARN(cur_state != state,
307 "PLL state assertion failure (expected %s, current %s)\n",
308 onoff(state), onoff(cur_state));
311 /* XXX: the dsi pll is shared between MIPI DSI ports */
312 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
317 vlv_cck_get(dev_priv);
318 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
319 vlv_cck_put(dev_priv);
321 cur_state = val & DSI_PLL_VCO_EN;
322 I915_STATE_WARN(cur_state != state,
323 "DSI PLL state assertion failure (expected %s, current %s)\n",
324 onoff(state), onoff(cur_state));
327 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
328 enum pipe pipe, bool state)
332 if (HAS_DDI(dev_priv)) {
334 * DDI does not have a specific FDI_TX register.
336 * FDI is never fed from EDP transcoder
337 * so pipe->transcoder cast is fine here.
339 enum transcoder cpu_transcoder = (enum transcoder)pipe;
340 u32 val = intel_de_read(dev_priv,
341 TRANS_DDI_FUNC_CTL(cpu_transcoder));
342 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
344 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
345 cur_state = !!(val & FDI_TX_ENABLE);
347 I915_STATE_WARN(cur_state != state,
348 "FDI TX state assertion failure (expected %s, current %s)\n",
349 onoff(state), onoff(cur_state));
351 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
352 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
354 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
355 enum pipe pipe, bool state)
360 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
361 cur_state = !!(val & FDI_RX_ENABLE);
362 I915_STATE_WARN(cur_state != state,
363 "FDI RX state assertion failure (expected %s, current %s)\n",
364 onoff(state), onoff(cur_state));
366 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
367 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
369 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
374 /* ILK FDI PLL is always enabled */
375 if (IS_IRONLAKE(dev_priv))
378 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
379 if (HAS_DDI(dev_priv))
382 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
383 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
386 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
387 enum pipe pipe, bool state)
392 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
393 cur_state = !!(val & FDI_RX_PLL_ENABLE);
394 I915_STATE_WARN(cur_state != state,
395 "FDI RX PLL assertion failure (expected %s, current %s)\n",
396 onoff(state), onoff(cur_state));
399 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
403 enum pipe panel_pipe = INVALID_PIPE;
406 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
409 if (HAS_PCH_SPLIT(dev_priv)) {
412 pp_reg = PP_CONTROL(0);
413 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
416 case PANEL_PORT_SELECT_LVDS:
417 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
419 case PANEL_PORT_SELECT_DPA:
420 g4x_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
422 case PANEL_PORT_SELECT_DPC:
423 g4x_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
425 case PANEL_PORT_SELECT_DPD:
426 g4x_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
429 MISSING_CASE(port_sel);
432 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
433 /* presumably write lock depends on pipe, not port select */
434 pp_reg = PP_CONTROL(pipe);
439 pp_reg = PP_CONTROL(0);
440 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
442 drm_WARN_ON(&dev_priv->drm,
443 port_sel != PANEL_PORT_SELECT_LVDS);
444 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
447 val = intel_de_read(dev_priv, pp_reg);
448 if (!(val & PANEL_POWER_ON) ||
449 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
452 I915_STATE_WARN(panel_pipe == pipe && locked,
453 "panel assertion failure, pipe %c regs locked\n",
457 void assert_transcoder(struct drm_i915_private *dev_priv,
458 enum transcoder cpu_transcoder, bool state)
461 enum intel_display_power_domain power_domain;
462 intel_wakeref_t wakeref;
464 /* we keep both pipes enabled on 830 */
465 if (IS_I830(dev_priv))
468 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
469 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
471 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
472 cur_state = !!(val & PIPECONF_ENABLE);
474 intel_display_power_put(dev_priv, power_domain, wakeref);
479 I915_STATE_WARN(cur_state != state,
480 "transcoder %s assertion failure (expected %s, current %s)\n",
481 transcoder_name(cpu_transcoder),
482 onoff(state), onoff(cur_state));
485 static void assert_plane(struct intel_plane *plane, bool state)
490 cur_state = plane->get_hw_state(plane, &pipe);
492 I915_STATE_WARN(cur_state != state,
493 "%s assertion failure (expected %s, current %s)\n",
494 plane->base.name, onoff(state), onoff(cur_state));
497 #define assert_plane_enabled(p) assert_plane(p, true)
498 #define assert_plane_disabled(p) assert_plane(p, false)
500 static void assert_planes_disabled(struct intel_crtc *crtc)
502 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
503 struct intel_plane *plane;
505 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
506 assert_plane_disabled(plane);
509 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
515 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
516 enabled = !!(val & TRANS_ENABLE);
517 I915_STATE_WARN(enabled,
518 "transcoder assertion failed, should be off on pipe %c but is still active\n",
522 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
523 enum pipe pipe, enum port port,
529 state = g4x_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
531 I915_STATE_WARN(state && port_pipe == pipe,
532 "PCH DP %c enabled on transcoder %c, should be disabled\n",
533 port_name(port), pipe_name(pipe));
535 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
536 "IBX PCH DP %c still using transcoder B\n",
540 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
541 enum pipe pipe, enum port port,
547 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
549 I915_STATE_WARN(state && port_pipe == pipe,
550 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
551 port_name(port), pipe_name(pipe));
553 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
554 "IBX PCH HDMI %c still using transcoder B\n",
558 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
563 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
564 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
565 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
567 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
569 "PCH VGA enabled on transcoder %c, should be disabled\n",
572 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
574 "PCH LVDS enabled on transcoder %c, should be disabled\n",
577 /* PCH SDVOB multiplex with HDMIB */
578 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
579 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
580 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
583 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
584 struct intel_digital_port *dig_port,
585 unsigned int expected_mask)
590 switch (dig_port->base.port) {
592 port_mask = DPLL_PORTB_READY_MASK;
596 port_mask = DPLL_PORTC_READY_MASK;
601 port_mask = DPLL_PORTD_READY_MASK;
602 dpll_reg = DPIO_PHY_STATUS;
608 if (intel_de_wait_for_register(dev_priv, dpll_reg,
609 port_mask, expected_mask, 1000))
610 drm_WARN(&dev_priv->drm, 1,
611 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
612 dig_port->base.base.base.id, dig_port->base.base.name,
613 intel_de_read(dev_priv, dpll_reg) & port_mask,
617 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
619 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
620 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
621 enum pipe pipe = crtc->pipe;
623 u32 val, pipeconf_val;
625 /* Make sure PCH DPLL is enabled */
626 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
628 /* FDI must be feeding us bits for PCH ports */
629 assert_fdi_tx_enabled(dev_priv, pipe);
630 assert_fdi_rx_enabled(dev_priv, pipe);
632 if (HAS_PCH_CPT(dev_priv)) {
633 reg = TRANS_CHICKEN2(pipe);
634 val = intel_de_read(dev_priv, reg);
636 * Workaround: Set the timing override bit
637 * before enabling the pch transcoder.
639 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
640 /* Configure frame start delay to match the CPU */
641 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
642 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
643 intel_de_write(dev_priv, reg, val);
646 reg = PCH_TRANSCONF(pipe);
647 val = intel_de_read(dev_priv, reg);
648 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
650 if (HAS_PCH_IBX(dev_priv)) {
651 /* Configure frame start delay to match the CPU */
652 val &= ~TRANS_FRAME_START_DELAY_MASK;
653 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
656 * Make the BPC in transcoder be consistent with
657 * that in pipeconf reg. For HDMI we must use 8bpc
658 * here for both 8bpc and 12bpc.
660 val &= ~PIPECONF_BPC_MASK;
661 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
662 val |= PIPECONF_8BPC;
664 val |= pipeconf_val & PIPECONF_BPC_MASK;
667 val &= ~TRANS_INTERLACE_MASK;
668 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
669 if (HAS_PCH_IBX(dev_priv) &&
670 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
671 val |= TRANS_LEGACY_INTERLACED_ILK;
673 val |= TRANS_INTERLACED;
675 val |= TRANS_PROGRESSIVE;
678 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
679 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
680 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
684 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
685 enum transcoder cpu_transcoder)
687 u32 val, pipeconf_val;
689 /* FDI must be feeding us bits for PCH ports */
690 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
691 assert_fdi_rx_enabled(dev_priv, PIPE_A);
693 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
694 /* Workaround: set timing override bit. */
695 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
696 /* Configure frame start delay to match the CPU */
697 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
698 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
699 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
702 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
704 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
705 PIPECONF_INTERLACED_ILK)
706 val |= TRANS_INTERLACED;
708 val |= TRANS_PROGRESSIVE;
710 intel_de_write(dev_priv, LPT_TRANSCONF, val);
711 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
712 TRANS_STATE_ENABLE, 100))
713 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
716 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
722 /* FDI relies on the transcoder */
723 assert_fdi_tx_disabled(dev_priv, pipe);
724 assert_fdi_rx_disabled(dev_priv, pipe);
726 /* Ports must be off as well */
727 assert_pch_ports_disabled(dev_priv, pipe);
729 reg = PCH_TRANSCONF(pipe);
730 val = intel_de_read(dev_priv, reg);
731 val &= ~TRANS_ENABLE;
732 intel_de_write(dev_priv, reg, val);
733 /* wait for PCH transcoder off, transcoder state */
734 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
735 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
738 if (HAS_PCH_CPT(dev_priv)) {
739 /* Workaround: Clear the timing override chicken bit again. */
740 reg = TRANS_CHICKEN2(pipe);
741 val = intel_de_read(dev_priv, reg);
742 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
743 intel_de_write(dev_priv, reg, val);
747 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
751 val = intel_de_read(dev_priv, LPT_TRANSCONF);
752 val &= ~TRANS_ENABLE;
753 intel_de_write(dev_priv, LPT_TRANSCONF, val);
754 /* wait for PCH transcoder off, transcoder state */
755 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
756 TRANS_STATE_ENABLE, 50))
757 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
759 /* Workaround: clear timing override bit. */
760 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
761 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
762 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
765 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
767 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
769 if (HAS_PCH_LPT(dev_priv))
775 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
777 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
778 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
779 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
780 enum pipe pipe = crtc->pipe;
784 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
786 assert_planes_disabled(crtc);
789 * A pipe without a PLL won't actually be able to drive bits from
790 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
793 if (HAS_GMCH(dev_priv)) {
794 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
795 assert_dsi_pll_enabled(dev_priv);
797 assert_pll_enabled(dev_priv, pipe);
799 if (new_crtc_state->has_pch_encoder) {
800 /* if driving the PCH, we need FDI enabled */
801 assert_fdi_rx_pll_enabled(dev_priv,
802 intel_crtc_pch_transcoder(crtc));
803 assert_fdi_tx_pll_enabled(dev_priv,
804 (enum pipe) cpu_transcoder);
806 /* FIXME: assert CPU port conditions for SNB+ */
809 /* Wa_22012358565:adl-p */
810 if (DISPLAY_VER(dev_priv) == 13)
811 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
812 0, PIPE_ARB_USE_PROG_SLOTS);
814 reg = PIPECONF(cpu_transcoder);
815 val = intel_de_read(dev_priv, reg);
816 if (val & PIPECONF_ENABLE) {
817 /* we keep both pipes enabled on 830 */
818 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
822 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
823 intel_de_posting_read(dev_priv, reg);
826 * Until the pipe starts PIPEDSL reads will return a stale value,
827 * which causes an apparent vblank timestamp jump when PIPEDSL
828 * resets to its proper value. That also messes up the frame count
829 * when it's derived from the timestamps. So let's wait for the
830 * pipe to start properly before we call drm_crtc_vblank_on()
832 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
833 intel_wait_for_pipe_scanline_moving(crtc);
836 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
838 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
839 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
840 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
841 enum pipe pipe = crtc->pipe;
845 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
848 * Make sure planes won't keep trying to pump pixels to us,
849 * or we might hang the display.
851 assert_planes_disabled(crtc);
853 reg = PIPECONF(cpu_transcoder);
854 val = intel_de_read(dev_priv, reg);
855 if ((val & PIPECONF_ENABLE) == 0)
859 * Double wide has implications for planes
860 * so best keep it disabled when not needed.
862 if (old_crtc_state->double_wide)
863 val &= ~PIPECONF_DOUBLE_WIDE;
865 /* Don't disable pipe or pipe PLLs if needed */
866 if (!IS_I830(dev_priv))
867 val &= ~PIPECONF_ENABLE;
869 if (DISPLAY_VER(dev_priv) >= 12)
870 intel_de_rmw(dev_priv, CHICKEN_TRANS(cpu_transcoder),
871 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
873 intel_de_write(dev_priv, reg, val);
874 if ((val & PIPECONF_ENABLE) == 0)
875 intel_wait_for_pipe_off(old_crtc_state);
879 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
882 return info->is_yuv &&
883 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
886 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
888 unsigned int size = 0;
891 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
892 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
897 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
899 unsigned int size = 0;
902 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
903 if (rem_info->plane_alignment)
904 size = ALIGN(size, rem_info->plane_alignment);
905 size += rem_info->plane[i].dst_stride * rem_info->plane[i].height;
911 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
913 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
914 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
916 return DISPLAY_VER(dev_priv) < 4 ||
918 plane_state->view.gtt.type == I915_GGTT_VIEW_NORMAL);
921 static struct i915_vma *
922 intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
923 const struct i915_ggtt_view *view,
925 unsigned long *out_flags,
926 struct i915_address_space *vm)
928 struct drm_device *dev = fb->dev;
929 struct drm_i915_private *dev_priv = to_i915(dev);
930 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
931 struct i915_vma *vma;
935 if (WARN_ON(!i915_gem_object_is_framebuffer(obj)))
936 return ERR_PTR(-EINVAL);
938 alignment = 4096 * 512;
940 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
942 ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
948 vma = i915_vma_instance(obj, vm, view);
952 if (i915_vma_misplaced(vma, 0, alignment, 0)) {
953 ret = i915_vma_unbind(vma);
960 ret = i915_vma_pin(vma, 0, alignment, PIN_GLOBAL);
966 vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
968 i915_gem_object_flush_if_display(obj);
972 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
978 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
980 const struct i915_ggtt_view *view,
982 unsigned long *out_flags)
984 struct drm_device *dev = fb->dev;
985 struct drm_i915_private *dev_priv = to_i915(dev);
986 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
987 intel_wakeref_t wakeref;
988 struct i915_gem_ww_ctx ww;
989 struct i915_vma *vma;
994 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
995 return ERR_PTR(-EINVAL);
998 alignment = intel_cursor_alignment(dev_priv);
1000 alignment = intel_surf_alignment(fb, 0);
1001 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
1002 return ERR_PTR(-EINVAL);
1004 /* Note that the w/a also requires 64 PTE of padding following the
1005 * bo. We currently fill all unused PTE with the shadow page and so
1006 * we should always have valid PTE following the scanout preventing
1009 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
1010 alignment = 256 * 1024;
1013 * Global gtt pte registers are special registers which actually forward
1014 * writes to a chunk of system memory. Which means that there is no risk
1015 * that the register values disappear as soon as we call
1016 * intel_runtime_pm_put(), so it is correct to wrap only the
1017 * pin/unpin/fence and not more.
1019 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
1021 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
1024 * Valleyview is definitely limited to scanning out the first
1025 * 512MiB. Lets presume this behaviour was inherited from the
1026 * g4x display engine and that all earlier gen are similarly
1027 * limited. Testing suggests that it is a little more
1028 * complicated than this. For example, Cherryview appears quite
1029 * happy to scanout from anywhere within its global aperture.
1032 if (HAS_GMCH(dev_priv))
1033 pinctl |= PIN_MAPPABLE;
1035 i915_gem_ww_ctx_init(&ww, true);
1037 ret = i915_gem_object_lock(obj, &ww);
1038 if (!ret && phys_cursor)
1039 ret = i915_gem_object_attach_phys(obj, alignment);
1040 else if (!ret && HAS_LMEM(dev_priv))
1041 ret = i915_gem_object_migrate(obj, &ww, INTEL_REGION_LMEM);
1042 /* TODO: Do we need to sync when migration becomes async? */
1044 ret = i915_gem_object_pin_pages(obj);
1049 vma = i915_gem_object_pin_to_display_plane(obj, &ww, alignment,
1057 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
1059 * Install a fence for tiled scan-out. Pre-i965 always needs a
1060 * fence, whereas 965+ only requires a fence if using
1061 * framebuffer compression. For simplicity, we always, when
1062 * possible, install a fence as the cost is not that onerous.
1064 * If we fail to fence the tiled scanout, then either the
1065 * modeset will reject the change (which is highly unlikely as
1066 * the affected systems, all but one, do not have unmappable
1067 * space) or we will not be able to enable full powersaving
1068 * techniques (also likely not to apply due to various limits
1069 * FBC and the like impose on the size of the buffer, which
1070 * presumably we violated anyway with this unmappable buffer).
1071 * Anyway, it is presumably better to stumble onwards with
1072 * something and try to run the system in a "less than optimal"
1073 * mode that matches the user configuration.
1075 ret = i915_vma_pin_fence(vma);
1076 if (ret != 0 && DISPLAY_VER(dev_priv) < 4) {
1077 i915_vma_unpin(vma);
1083 *out_flags |= PLANE_HAS_FENCE;
1089 i915_gem_object_unpin_pages(obj);
1091 if (ret == -EDEADLK) {
1092 ret = i915_gem_ww_ctx_backoff(&ww);
1096 i915_gem_ww_ctx_fini(&ww);
1100 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
1101 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
1105 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
1107 if (flags & PLANE_HAS_FENCE)
1108 i915_vma_unpin_fence(vma);
1109 i915_vma_unpin(vma);
1114 * Convert the x/y offsets into a linear offset.
1115 * Only valid with 0/180 degree rotation, which is fine since linear
1116 * offset is only used with linear buffers on pre-hsw and tiled buffers
1117 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
1119 u32 intel_fb_xy_to_linear(int x, int y,
1120 const struct intel_plane_state *state,
1123 const struct drm_framebuffer *fb = state->hw.fb;
1124 unsigned int cpp = fb->format->cpp[color_plane];
1125 unsigned int pitch = state->view.color_plane[color_plane].stride;
1127 return y * pitch + x * cpp;
1131 * Add the x/y offsets derived from fb->offsets[] to the user
1132 * specified plane src x/y offsets. The resulting x/y offsets
1133 * specify the start of scanout from the beginning of the gtt mapping.
1135 void intel_add_fb_offsets(int *x, int *y,
1136 const struct intel_plane_state *state,
1140 *x += state->view.color_plane[color_plane].x;
1141 *y += state->view.color_plane[color_plane].y;
1145 * From the Sky Lake PRM:
1146 * "The Color Control Surface (CCS) contains the compression status of
1147 * the cache-line pairs. The compression state of the cache-line pair
1148 * is specified by 2 bits in the CCS. Each CCS cache-line represents
1149 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
1150 * cache-line-pairs. CCS is always Y tiled."
1152 * Since cache line pairs refers to horizontally adjacent cache lines,
1153 * each cache line in the CCS corresponds to an area of 32x16 cache
1154 * lines on the main surface. Since each pixel is 4 bytes, this gives
1155 * us a ratio of one byte in the CCS for each 8x16 pixels in the
1158 static const struct drm_format_info skl_ccs_formats[] = {
1159 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1160 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1161 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1162 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1163 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1164 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1165 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1166 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1170 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
1171 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
1172 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
1173 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
1176 static const struct drm_format_info gen12_ccs_formats[] = {
1177 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1178 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1179 .hsub = 1, .vsub = 1, },
1180 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1181 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1182 .hsub = 1, .vsub = 1, },
1183 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1184 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1185 .hsub = 1, .vsub = 1, .has_alpha = true },
1186 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1187 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1188 .hsub = 1, .vsub = 1, .has_alpha = true },
1189 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
1190 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1191 .hsub = 2, .vsub = 1, .is_yuv = true },
1192 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
1193 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1194 .hsub = 2, .vsub = 1, .is_yuv = true },
1195 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
1196 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1197 .hsub = 2, .vsub = 1, .is_yuv = true },
1198 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
1199 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1200 .hsub = 2, .vsub = 1, .is_yuv = true },
1201 { .format = DRM_FORMAT_XYUV8888, .num_planes = 2,
1202 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1203 .hsub = 1, .vsub = 1, .is_yuv = true },
1204 { .format = DRM_FORMAT_NV12, .num_planes = 4,
1205 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
1206 .hsub = 2, .vsub = 2, .is_yuv = true },
1207 { .format = DRM_FORMAT_P010, .num_planes = 4,
1208 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1209 .hsub = 2, .vsub = 2, .is_yuv = true },
1210 { .format = DRM_FORMAT_P012, .num_planes = 4,
1211 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1212 .hsub = 2, .vsub = 2, .is_yuv = true },
1213 { .format = DRM_FORMAT_P016, .num_planes = 4,
1214 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1215 .hsub = 2, .vsub = 2, .is_yuv = true },
1219 * Same as gen12_ccs_formats[] above, but with additional surface used
1220 * to pass Clear Color information in plane 2 with 64 bits of data.
1222 static const struct drm_format_info gen12_ccs_cc_formats[] = {
1223 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 3,
1224 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1225 .hsub = 1, .vsub = 1, },
1226 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 3,
1227 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1228 .hsub = 1, .vsub = 1, },
1229 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 3,
1230 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1231 .hsub = 1, .vsub = 1, .has_alpha = true },
1232 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 3,
1233 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1234 .hsub = 1, .vsub = 1, .has_alpha = true },
1237 static const struct drm_format_info *
1238 lookup_format_info(const struct drm_format_info formats[],
1239 int num_formats, u32 format)
1243 for (i = 0; i < num_formats; i++) {
1244 if (formats[i].format == format)
1251 static const struct drm_format_info *
1252 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
1254 switch (cmd->modifier[0]) {
1255 case I915_FORMAT_MOD_Y_TILED_CCS:
1256 case I915_FORMAT_MOD_Yf_TILED_CCS:
1257 return lookup_format_info(skl_ccs_formats,
1258 ARRAY_SIZE(skl_ccs_formats),
1260 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1261 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1262 return lookup_format_info(gen12_ccs_formats,
1263 ARRAY_SIZE(gen12_ccs_formats),
1265 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1266 return lookup_format_info(gen12_ccs_cc_formats,
1267 ARRAY_SIZE(gen12_ccs_cc_formats),
1274 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
1275 u32 pixel_format, u64 modifier)
1277 struct intel_crtc *crtc;
1278 struct intel_plane *plane;
1280 if (!HAS_DISPLAY(dev_priv))
1284 * We assume the primary plane for pipe A has
1285 * the highest stride limits of them all,
1286 * if in case pipe A is disabled, use the first pipe from pipe_mask.
1288 crtc = intel_get_first_crtc(dev_priv);
1292 plane = to_intel_plane(crtc->base.primary);
1294 return plane->max_stride(plane, pixel_format, modifier,
1298 static struct i915_vma *
1299 initial_plane_vma(struct drm_i915_private *i915,
1300 struct intel_initial_plane_config *plane_config)
1302 struct drm_i915_gem_object *obj;
1303 struct i915_vma *vma;
1306 if (plane_config->size == 0)
1309 base = round_down(plane_config->base,
1310 I915_GTT_MIN_ALIGNMENT);
1311 size = round_up(plane_config->base + plane_config->size,
1312 I915_GTT_MIN_ALIGNMENT);
1316 * If the FB is too big, just don't use it since fbdev is not very
1317 * important and we should probably use that space with FBC or other
1320 if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE) &&
1321 size * 2 > i915->stolen_usable_size)
1324 obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
1329 * Mark it WT ahead of time to avoid changing the
1330 * cache_level during fbdev initialization. The
1331 * unbind there would get stuck waiting for rcu.
1333 i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
1334 I915_CACHE_WT : I915_CACHE_NONE);
1336 switch (plane_config->tiling) {
1337 case I915_TILING_NONE:
1341 obj->tiling_and_stride =
1342 plane_config->fb->base.pitches[0] |
1343 plane_config->tiling;
1346 MISSING_CASE(plane_config->tiling);
1350 vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
1354 if (i915_ggtt_pin(vma, NULL, 0, PIN_MAPPABLE | PIN_OFFSET_FIXED | base))
1357 if (i915_gem_object_is_tiled(obj) &&
1358 !i915_vma_is_map_and_fenceable(vma))
1364 i915_gem_object_put(obj);
1369 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
1370 struct intel_initial_plane_config *plane_config)
1372 struct drm_device *dev = crtc->base.dev;
1373 struct drm_i915_private *dev_priv = to_i915(dev);
1374 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
1375 struct drm_framebuffer *fb = &plane_config->fb->base;
1376 struct i915_vma *vma;
1378 switch (fb->modifier) {
1379 case DRM_FORMAT_MOD_LINEAR:
1380 case I915_FORMAT_MOD_X_TILED:
1381 case I915_FORMAT_MOD_Y_TILED:
1384 drm_dbg(&dev_priv->drm,
1385 "Unsupported modifier for initial FB: 0x%llx\n",
1390 vma = initial_plane_vma(dev_priv, plane_config);
1394 mode_cmd.pixel_format = fb->format->format;
1395 mode_cmd.width = fb->width;
1396 mode_cmd.height = fb->height;
1397 mode_cmd.pitches[0] = fb->pitches[0];
1398 mode_cmd.modifier[0] = fb->modifier;
1399 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
1401 if (intel_framebuffer_init(to_intel_framebuffer(fb),
1402 vma->obj, &mode_cmd)) {
1403 drm_dbg_kms(&dev_priv->drm, "intel fb init failed\n");
1407 plane_config->vma = vma;
1416 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
1417 struct intel_plane_state *plane_state,
1420 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1422 plane_state->uapi.visible = visible;
1425 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
1427 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
1430 static void fixup_plane_bitmasks(struct intel_crtc_state *crtc_state)
1432 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1433 struct drm_plane *plane;
1436 * Active_planes aliases if multiple "primary" or cursor planes
1437 * have been used on the same (or wrong) pipe. plane_mask uses
1438 * unique ids, hence we can use that to reconstruct active_planes.
1440 crtc_state->enabled_planes = 0;
1441 crtc_state->active_planes = 0;
1443 drm_for_each_plane_mask(plane, &dev_priv->drm,
1444 crtc_state->uapi.plane_mask) {
1445 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
1446 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
1450 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
1451 struct intel_plane *plane)
1453 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1454 struct intel_crtc_state *crtc_state =
1455 to_intel_crtc_state(crtc->base.state);
1456 struct intel_plane_state *plane_state =
1457 to_intel_plane_state(plane->base.state);
1459 drm_dbg_kms(&dev_priv->drm,
1460 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
1461 plane->base.base.id, plane->base.name,
1462 crtc->base.base.id, crtc->base.name);
1464 intel_set_plane_visible(crtc_state, plane_state, false);
1465 fixup_plane_bitmasks(crtc_state);
1466 crtc_state->data_rate[plane->id] = 0;
1467 crtc_state->min_cdclk[plane->id] = 0;
1469 if (plane->id == PLANE_PRIMARY)
1470 hsw_disable_ips(crtc_state);
1473 * Vblank time updates from the shadow to live plane control register
1474 * are blocked if the memory self-refresh mode is active at that
1475 * moment. So to make sure the plane gets truly disabled, disable
1476 * first the self-refresh mode. The self-refresh enable bit in turn
1477 * will be checked/applied by the HW only at the next frame start
1478 * event which is after the vblank start event, so we need to have a
1479 * wait-for-vblank between disabling the plane and the pipe.
1481 if (HAS_GMCH(dev_priv) &&
1482 intel_set_memory_cxsr(dev_priv, false))
1483 intel_wait_for_vblank(dev_priv, crtc->pipe);
1486 * Gen2 reports pipe underruns whenever all planes are disabled.
1487 * So disable underrun reporting before all the planes get disabled.
1489 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
1490 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
1492 intel_disable_plane(plane, crtc_state);
1493 intel_wait_for_vblank(dev_priv, crtc->pipe);
1497 intel_reuse_initial_plane_obj(struct drm_i915_private *i915,
1498 const struct intel_initial_plane_config *plane_config,
1499 struct drm_framebuffer **fb,
1500 struct i915_vma **vma)
1502 struct intel_crtc *crtc;
1504 for_each_intel_crtc(&i915->drm, crtc) {
1505 struct intel_crtc_state *crtc_state =
1506 to_intel_crtc_state(crtc->base.state);
1507 struct intel_plane *plane =
1508 to_intel_plane(crtc->base.primary);
1509 struct intel_plane_state *plane_state =
1510 to_intel_plane_state(plane->base.state);
1512 if (!crtc_state->uapi.active)
1515 if (!plane_state->ggtt_vma)
1518 if (intel_plane_ggtt_offset(plane_state) == plane_config->base) {
1519 *fb = plane_state->hw.fb;
1520 *vma = plane_state->ggtt_vma;
1529 intel_find_initial_plane_obj(struct intel_crtc *crtc,
1530 struct intel_initial_plane_config *plane_config)
1532 struct drm_device *dev = crtc->base.dev;
1533 struct drm_i915_private *dev_priv = to_i915(dev);
1534 struct intel_crtc_state *crtc_state =
1535 to_intel_crtc_state(crtc->base.state);
1536 struct intel_plane *plane =
1537 to_intel_plane(crtc->base.primary);
1538 struct intel_plane_state *plane_state =
1539 to_intel_plane_state(plane->base.state);
1540 struct drm_framebuffer *fb;
1541 struct i915_vma *vma;
1545 * Disable planes if get_initial_plane_config() failed.
1546 * Make sure things work if the surface base is not page aligned.
1548 if (!plane_config->fb)
1551 if (intel_alloc_initial_plane_obj(crtc, plane_config)) {
1552 fb = &plane_config->fb->base;
1553 vma = plane_config->vma;
1558 * Failed to alloc the obj, check to see if we should share
1559 * an fb with another CRTC instead
1561 if (intel_reuse_initial_plane_obj(dev_priv, plane_config, &fb, &vma))
1565 * We've failed to reconstruct the BIOS FB. Current display state
1566 * indicates that the primary plane is visible, but has a NULL FB,
1567 * which will lead to problems later if we don't fix it up. The
1568 * simplest solution is to just disable the primary plane now and
1569 * pretend the BIOS never had it enabled.
1571 intel_plane_disable_noatomic(crtc, plane);
1572 if (crtc_state->bigjoiner) {
1573 struct intel_crtc *slave =
1574 crtc_state->bigjoiner_linked_crtc;
1575 intel_plane_disable_noatomic(slave, to_intel_plane(slave->base.primary));
1581 plane_state->uapi.rotation = plane_config->rotation;
1582 intel_fb_fill_view(to_intel_framebuffer(fb),
1583 plane_state->uapi.rotation, &plane_state->view);
1585 __i915_vma_pin(vma);
1586 plane_state->ggtt_vma = i915_vma_get(vma);
1587 if (intel_plane_uses_fence(plane_state) &&
1588 i915_vma_pin_fence(vma) == 0 && vma->fence)
1589 plane_state->flags |= PLANE_HAS_FENCE;
1591 plane_state->uapi.src_x = 0;
1592 plane_state->uapi.src_y = 0;
1593 plane_state->uapi.src_w = fb->width << 16;
1594 plane_state->uapi.src_h = fb->height << 16;
1596 plane_state->uapi.crtc_x = 0;
1597 plane_state->uapi.crtc_y = 0;
1598 plane_state->uapi.crtc_w = fb->width;
1599 plane_state->uapi.crtc_h = fb->height;
1601 if (plane_config->tiling)
1602 dev_priv->preserve_bios_swizzle = true;
1604 plane_state->uapi.fb = fb;
1605 drm_framebuffer_get(fb);
1607 plane_state->uapi.crtc = &crtc->base;
1608 intel_plane_copy_uapi_to_hw_state(plane_state, plane_state, crtc);
1610 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
1612 atomic_or(plane->frontbuffer_bit, &to_intel_frontbuffer(fb)->bits);
1616 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
1620 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
1621 plane_state->view.color_plane[0].offset, 0);
1627 __intel_display_resume(struct drm_device *dev,
1628 struct drm_atomic_state *state,
1629 struct drm_modeset_acquire_ctx *ctx)
1631 struct drm_crtc_state *crtc_state;
1632 struct drm_crtc *crtc;
1635 intel_modeset_setup_hw_state(dev, ctx);
1636 intel_vga_redisable(to_i915(dev));
1642 * We've duplicated the state, pointers to the old state are invalid.
1644 * Don't attempt to use the old state until we commit the duplicated state.
1646 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
1648 * Force recalculation even if we restore
1649 * current state. With fast modeset this may not result
1650 * in a modeset when the state is compatible.
1652 crtc_state->mode_changed = true;
1655 /* ignore any reset values/BIOS leftovers in the WM registers */
1656 if (!HAS_GMCH(to_i915(dev)))
1657 to_intel_atomic_state(state)->skip_intermediate_wm = true;
1659 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
1661 drm_WARN_ON(dev, ret == -EDEADLK);
1665 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
1667 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
1668 intel_has_gpu_reset(&dev_priv->gt));
1671 void intel_display_prepare_reset(struct drm_i915_private *dev_priv)
1673 struct drm_device *dev = &dev_priv->drm;
1674 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
1675 struct drm_atomic_state *state;
1678 if (!HAS_DISPLAY(dev_priv))
1681 /* reset doesn't touch the display */
1682 if (!dev_priv->params.force_reset_modeset_test &&
1683 !gpu_reset_clobbers_display(dev_priv))
1686 /* We have a modeset vs reset deadlock, defensively unbreak it. */
1687 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
1688 smp_mb__after_atomic();
1689 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
1691 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
1692 drm_dbg_kms(&dev_priv->drm,
1693 "Modeset potentially stuck, unbreaking through wedging\n");
1694 intel_gt_set_wedged(&dev_priv->gt);
1698 * Need mode_config.mutex so that we don't
1699 * trample ongoing ->detect() and whatnot.
1701 mutex_lock(&dev->mode_config.mutex);
1702 drm_modeset_acquire_init(ctx, 0);
1704 ret = drm_modeset_lock_all_ctx(dev, ctx);
1705 if (ret != -EDEADLK)
1708 drm_modeset_backoff(ctx);
1711 * Disabling the crtcs gracefully seems nicer. Also the
1712 * g33 docs say we should at least disable all the planes.
1714 state = drm_atomic_helper_duplicate_state(dev, ctx);
1715 if (IS_ERR(state)) {
1716 ret = PTR_ERR(state);
1717 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
1722 ret = drm_atomic_helper_disable_all(dev, ctx);
1724 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
1726 drm_atomic_state_put(state);
1730 dev_priv->modeset_restore_state = state;
1731 state->acquire_ctx = ctx;
1734 void intel_display_finish_reset(struct drm_i915_private *dev_priv)
1736 struct drm_device *dev = &dev_priv->drm;
1737 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
1738 struct drm_atomic_state *state;
1741 if (!HAS_DISPLAY(dev_priv))
1744 /* reset doesn't touch the display */
1745 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
1748 state = fetch_and_zero(&dev_priv->modeset_restore_state);
1752 /* reset doesn't touch the display */
1753 if (!gpu_reset_clobbers_display(dev_priv)) {
1754 /* for testing only restore the display */
1755 ret = __intel_display_resume(dev, state, ctx);
1757 drm_err(&dev_priv->drm,
1758 "Restoring old state failed with %i\n", ret);
1761 * The display has been reset as well,
1762 * so need a full re-initialization.
1764 intel_pps_unlock_regs_wa(dev_priv);
1765 intel_modeset_init_hw(dev_priv);
1766 intel_init_clock_gating(dev_priv);
1767 intel_hpd_init(dev_priv);
1769 ret = __intel_display_resume(dev, state, ctx);
1771 drm_err(&dev_priv->drm,
1772 "Restoring old state failed with %i\n", ret);
1774 intel_hpd_poll_disable(dev_priv);
1777 drm_atomic_state_put(state);
1779 drm_modeset_drop_locks(ctx);
1780 drm_modeset_acquire_fini(ctx);
1781 mutex_unlock(&dev->mode_config.mutex);
1783 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
1786 static bool underrun_recovery_supported(const struct intel_crtc_state *crtc_state)
1788 if (crtc_state->pch_pfit.enabled &&
1789 (crtc_state->pipe_src_w > drm_rect_width(&crtc_state->pch_pfit.dst) ||
1790 crtc_state->pipe_src_h > drm_rect_height(&crtc_state->pch_pfit.dst) ||
1791 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420))
1794 if (crtc_state->dsc.compression_enable)
1797 if (crtc_state->has_psr2)
1800 if (crtc_state->splitter.enable)
1806 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
1808 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1809 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1810 enum pipe pipe = crtc->pipe;
1813 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
1816 * Display WA #1153: icl
1817 * enable hardware to bypass the alpha math
1818 * and rounding for per-pixel values 00 and 0xff
1820 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
1822 * Display WA # 1605353570: icl
1823 * Set the pixel rounding bit to 1 for allowing
1824 * passthrough of Frame buffer pixels unmodified
1827 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
1829 if (IS_DG2(dev_priv)) {
1831 * Underrun recovery must always be disabled on DG2. However
1832 * the chicken bit meaning is inverted compared to other
1835 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
1836 } else if (DISPLAY_VER(dev_priv) >= 13) {
1837 if (underrun_recovery_supported(crtc_state))
1838 tmp &= ~UNDERRUN_RECOVERY_DISABLE_ADLP;
1840 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
1843 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
1846 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
1848 struct drm_crtc *crtc;
1851 drm_for_each_crtc(crtc, &dev_priv->drm) {
1852 struct drm_crtc_commit *commit;
1853 spin_lock(&crtc->commit_lock);
1854 commit = list_first_entry_or_null(&crtc->commit_list,
1855 struct drm_crtc_commit, commit_entry);
1856 cleanup_done = commit ?
1857 try_wait_for_completion(&commit->cleanup_done) : true;
1858 spin_unlock(&crtc->commit_lock);
1863 drm_crtc_wait_one_vblank(crtc);
1871 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
1875 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
1877 mutex_lock(&dev_priv->sb_lock);
1879 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
1880 temp |= SBI_SSCCTL_DISABLE;
1881 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
1883 mutex_unlock(&dev_priv->sb_lock);
1886 /* Program iCLKIP clock to the desired frequency */
1887 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
1889 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1890 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1891 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
1892 u32 divsel, phaseinc, auxdiv, phasedir = 0;
1895 lpt_disable_iclkip(dev_priv);
1897 /* The iCLK virtual clock root frequency is in MHz,
1898 * but the adjusted_mode->crtc_clock in in KHz. To get the
1899 * divisors, it is necessary to divide one by another, so we
1900 * convert the virtual clock precision to KHz here for higher
1903 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
1904 u32 iclk_virtual_root_freq = 172800 * 1000;
1905 u32 iclk_pi_range = 64;
1906 u32 desired_divisor;
1908 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
1910 divsel = (desired_divisor / iclk_pi_range) - 2;
1911 phaseinc = desired_divisor % iclk_pi_range;
1914 * Near 20MHz is a corner case which is
1915 * out of range for the 7-bit divisor
1921 /* This should not happen with any sane values */
1922 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
1923 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
1924 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
1925 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
1927 drm_dbg_kms(&dev_priv->drm,
1928 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
1929 clock, auxdiv, divsel, phasedir, phaseinc);
1931 mutex_lock(&dev_priv->sb_lock);
1933 /* Program SSCDIVINTPHASE6 */
1934 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
1935 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
1936 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
1937 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
1938 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
1939 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
1940 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
1941 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
1943 /* Program SSCAUXDIV */
1944 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
1945 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
1946 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
1947 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
1949 /* Enable modulator and associated divider */
1950 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
1951 temp &= ~SBI_SSCCTL_DISABLE;
1952 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
1954 mutex_unlock(&dev_priv->sb_lock);
1956 /* Wait for initialization time */
1959 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
1962 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
1964 u32 divsel, phaseinc, auxdiv;
1965 u32 iclk_virtual_root_freq = 172800 * 1000;
1966 u32 iclk_pi_range = 64;
1967 u32 desired_divisor;
1970 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
1973 mutex_lock(&dev_priv->sb_lock);
1975 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
1976 if (temp & SBI_SSCCTL_DISABLE) {
1977 mutex_unlock(&dev_priv->sb_lock);
1981 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
1982 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
1983 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
1984 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
1985 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
1987 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
1988 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
1989 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
1991 mutex_unlock(&dev_priv->sb_lock);
1993 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
1995 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
1996 desired_divisor << auxdiv);
1999 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
2000 enum pipe pch_transcoder)
2002 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2003 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2004 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2006 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
2007 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
2008 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
2009 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
2010 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
2011 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
2013 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
2014 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
2015 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
2016 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
2017 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
2018 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
2019 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
2020 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
2024 * Finds the encoder associated with the given CRTC. This can only be
2025 * used when we know that the CRTC isn't feeding multiple encoders!
2027 struct intel_encoder *
2028 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
2029 const struct intel_crtc_state *crtc_state)
2031 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2032 const struct drm_connector_state *connector_state;
2033 const struct drm_connector *connector;
2034 struct intel_encoder *encoder = NULL;
2035 int num_encoders = 0;
2038 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
2039 if (connector_state->crtc != &crtc->base)
2042 encoder = to_intel_encoder(connector_state->best_encoder);
2046 drm_WARN(encoder->base.dev, num_encoders != 1,
2047 "%d encoders for pipe %c\n",
2048 num_encoders, pipe_name(crtc->pipe));
2054 * Enable PCH resources required for PCH ports:
2056 * - FDI training & RX/TX
2057 * - update transcoder timings
2058 * - DP transcoding bits
2061 static void ilk_pch_enable(const struct intel_atomic_state *state,
2062 const struct intel_crtc_state *crtc_state)
2064 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2065 struct drm_device *dev = crtc->base.dev;
2066 struct drm_i915_private *dev_priv = to_i915(dev);
2067 enum pipe pipe = crtc->pipe;
2070 assert_pch_transcoder_disabled(dev_priv, pipe);
2072 /* For PCH output, training FDI link */
2073 dev_priv->display.fdi_link_train(crtc, crtc_state);
2075 /* We need to program the right clock selection before writing the pixel
2076 * mutliplier into the DPLL. */
2077 if (HAS_PCH_CPT(dev_priv)) {
2080 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
2081 temp |= TRANS_DPLL_ENABLE(pipe);
2082 sel = TRANS_DPLLB_SEL(pipe);
2083 if (crtc_state->shared_dpll ==
2084 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
2088 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
2091 /* XXX: pch pll's can be enabled any time before we enable the PCH
2092 * transcoder, and we actually should do this to not upset any PCH
2093 * transcoder that already use the clock when we share it.
2095 * Note that enable_shared_dpll tries to do the right thing, but
2096 * get_shared_dpll unconditionally resets the pll - we need that to have
2097 * the right LVDS enable sequence. */
2098 intel_enable_shared_dpll(crtc_state);
2100 /* set transcoder timing, panel must allow it */
2101 assert_panel_unlocked(dev_priv, pipe);
2102 ilk_pch_transcoder_set_timings(crtc_state, pipe);
2104 intel_fdi_normal_train(crtc);
2106 /* For PCH DP, enable TRANS_DP_CTL */
2107 if (HAS_PCH_CPT(dev_priv) &&
2108 intel_crtc_has_dp_encoder(crtc_state)) {
2109 const struct drm_display_mode *adjusted_mode =
2110 &crtc_state->hw.adjusted_mode;
2111 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
2112 i915_reg_t reg = TRANS_DP_CTL(pipe);
2115 temp = intel_de_read(dev_priv, reg);
2116 temp &= ~(TRANS_DP_PORT_SEL_MASK |
2117 TRANS_DP_SYNC_MASK |
2119 temp |= TRANS_DP_OUTPUT_ENABLE;
2120 temp |= bpc << 9; /* same format but at 11:9 */
2122 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2123 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
2124 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2125 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
2127 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
2128 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
2129 temp |= TRANS_DP_PORT_SEL(port);
2131 intel_de_write(dev_priv, reg, temp);
2134 ilk_enable_pch_transcoder(crtc_state);
2137 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
2139 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2140 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2141 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2143 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
2145 lpt_program_iclkip(crtc_state);
2147 /* Set transcoder timing. */
2148 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
2150 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
2153 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
2156 i915_reg_t dslreg = PIPEDSL(pipe);
2159 temp = intel_de_read(dev_priv, dslreg);
2161 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
2162 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
2163 drm_err(&dev_priv->drm,
2164 "mode set failed: pipe %c stuck\n",
2169 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
2171 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2172 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2173 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
2174 enum pipe pipe = crtc->pipe;
2175 int width = drm_rect_width(dst);
2176 int height = drm_rect_height(dst);
2180 if (!crtc_state->pch_pfit.enabled)
2183 /* Force use of hard-coded filter coefficients
2184 * as some pre-programmed values are broken,
2187 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
2188 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
2189 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
2191 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
2193 intel_de_write(dev_priv, PF_WIN_POS(pipe), x << 16 | y);
2194 intel_de_write(dev_priv, PF_WIN_SZ(pipe), width << 16 | height);
2197 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
2199 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2200 struct drm_device *dev = crtc->base.dev;
2201 struct drm_i915_private *dev_priv = to_i915(dev);
2203 if (!crtc_state->ips_enabled)
2207 * We can only enable IPS after we enable a plane and wait for a vblank
2208 * This function is called from post_plane_update, which is run after
2211 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
2213 if (IS_BROADWELL(dev_priv)) {
2214 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
2215 IPS_ENABLE | IPS_PCODE_CONTROL));
2216 /* Quoting Art Runyan: "its not safe to expect any particular
2217 * value in IPS_CTL bit 31 after enabling IPS through the
2218 * mailbox." Moreover, the mailbox may return a bogus state,
2219 * so we need to just enable it and continue on.
2222 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
2223 /* The bit only becomes 1 in the next vblank, so this wait here
2224 * is essentially intel_wait_for_vblank. If we don't have this
2225 * and don't wait for vblanks until the end of crtc_enable, then
2226 * the HW state readout code will complain that the expected
2227 * IPS_CTL value is not the one we read. */
2228 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
2229 drm_err(&dev_priv->drm,
2230 "Timed out waiting for IPS enable\n");
2234 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
2236 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2237 struct drm_device *dev = crtc->base.dev;
2238 struct drm_i915_private *dev_priv = to_i915(dev);
2240 if (!crtc_state->ips_enabled)
2243 if (IS_BROADWELL(dev_priv)) {
2245 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
2247 * Wait for PCODE to finish disabling IPS. The BSpec specified
2248 * 42ms timeout value leads to occasional timeouts so use 100ms
2251 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
2252 drm_err(&dev_priv->drm,
2253 "Timed out waiting for IPS disable\n");
2255 intel_de_write(dev_priv, IPS_CTL, 0);
2256 intel_de_posting_read(dev_priv, IPS_CTL);
2259 /* We need to wait for a vblank before we can disable the plane. */
2260 intel_wait_for_vblank(dev_priv, crtc->pipe);
2263 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
2266 (void) intel_overlay_switch_off(crtc->overlay);
2268 /* Let userspace switch the overlay on again. In most cases userspace
2269 * has to recompute where to put it anyway.
2273 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
2274 const struct intel_crtc_state *new_crtc_state)
2276 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
2277 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2279 if (!old_crtc_state->ips_enabled)
2282 if (intel_crtc_needs_modeset(new_crtc_state))
2286 * Workaround : Do not read or write the pipe palette/gamma data while
2287 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
2289 * Disable IPS before we program the LUT.
2291 if (IS_HASWELL(dev_priv) &&
2292 (new_crtc_state->uapi.color_mgmt_changed ||
2293 new_crtc_state->update_pipe) &&
2294 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
2297 return !new_crtc_state->ips_enabled;
2300 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
2301 const struct intel_crtc_state *new_crtc_state)
2303 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
2304 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2306 if (!new_crtc_state->ips_enabled)
2309 if (intel_crtc_needs_modeset(new_crtc_state))
2313 * Workaround : Do not read or write the pipe palette/gamma data while
2314 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
2316 * Re-enable IPS after the LUT has been programmed.
2318 if (IS_HASWELL(dev_priv) &&
2319 (new_crtc_state->uapi.color_mgmt_changed ||
2320 new_crtc_state->update_pipe) &&
2321 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
2325 * We can't read out IPS on broadwell, assume the worst and
2326 * forcibly enable IPS on the first fastset.
2328 if (new_crtc_state->update_pipe && old_crtc_state->inherited)
2331 return !old_crtc_state->ips_enabled;
2334 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
2336 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2338 if (!crtc_state->nv12_planes)
2341 /* WA Display #0827: Gen9:all */
2342 if (DISPLAY_VER(dev_priv) == 9)
2348 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
2350 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2352 /* Wa_2006604312:icl,ehl */
2353 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
2359 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
2360 const struct intel_crtc_state *new_crtc_state)
2362 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) &&
2363 new_crtc_state->active_planes;
2366 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
2367 const struct intel_crtc_state *new_crtc_state)
2369 return old_crtc_state->active_planes &&
2370 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state));
2373 static void intel_post_plane_update(struct intel_atomic_state *state,
2374 struct intel_crtc *crtc)
2376 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
2377 const struct intel_crtc_state *old_crtc_state =
2378 intel_atomic_get_old_crtc_state(state, crtc);
2379 const struct intel_crtc_state *new_crtc_state =
2380 intel_atomic_get_new_crtc_state(state, crtc);
2381 enum pipe pipe = crtc->pipe;
2383 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
2385 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
2386 intel_update_watermarks(crtc);
2388 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
2389 hsw_enable_ips(new_crtc_state);
2391 intel_fbc_post_update(state, crtc);
2392 intel_drrs_page_flip(state, crtc);
2394 if (needs_nv12_wa(old_crtc_state) &&
2395 !needs_nv12_wa(new_crtc_state))
2396 skl_wa_827(dev_priv, pipe, false);
2398 if (needs_scalerclk_wa(old_crtc_state) &&
2399 !needs_scalerclk_wa(new_crtc_state))
2400 icl_wa_scalerclkgating(dev_priv, pipe, false);
2403 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
2404 struct intel_crtc *crtc)
2406 const struct intel_crtc_state *crtc_state =
2407 intel_atomic_get_new_crtc_state(state, crtc);
2408 u8 update_planes = crtc_state->update_planes;
2409 const struct intel_plane_state *plane_state;
2410 struct intel_plane *plane;
2413 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
2414 if (plane->enable_flip_done &&
2415 plane->pipe == crtc->pipe &&
2416 update_planes & BIT(plane->id))
2417 plane->enable_flip_done(plane);
2421 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
2422 struct intel_crtc *crtc)
2424 const struct intel_crtc_state *crtc_state =
2425 intel_atomic_get_new_crtc_state(state, crtc);
2426 u8 update_planes = crtc_state->update_planes;
2427 const struct intel_plane_state *plane_state;
2428 struct intel_plane *plane;
2431 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
2432 if (plane->disable_flip_done &&
2433 plane->pipe == crtc->pipe &&
2434 update_planes & BIT(plane->id))
2435 plane->disable_flip_done(plane);
2439 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
2440 struct intel_crtc *crtc)
2442 struct drm_i915_private *i915 = to_i915(state->base.dev);
2443 const struct intel_crtc_state *old_crtc_state =
2444 intel_atomic_get_old_crtc_state(state, crtc);
2445 const struct intel_crtc_state *new_crtc_state =
2446 intel_atomic_get_new_crtc_state(state, crtc);
2447 u8 update_planes = new_crtc_state->update_planes;
2448 const struct intel_plane_state *old_plane_state;
2449 struct intel_plane *plane;
2450 bool need_vbl_wait = false;
2453 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
2454 if (plane->need_async_flip_disable_wa &&
2455 plane->pipe == crtc->pipe &&
2456 update_planes & BIT(plane->id)) {
2458 * Apart from the async flip bit we want to
2459 * preserve the old state for the plane.
2461 plane->async_flip(plane, old_crtc_state,
2462 old_plane_state, false);
2463 need_vbl_wait = true;
2468 intel_wait_for_vblank(i915, crtc->pipe);
2471 static void intel_pre_plane_update(struct intel_atomic_state *state,
2472 struct intel_crtc *crtc)
2474 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
2475 const struct intel_crtc_state *old_crtc_state =
2476 intel_atomic_get_old_crtc_state(state, crtc);
2477 const struct intel_crtc_state *new_crtc_state =
2478 intel_atomic_get_new_crtc_state(state, crtc);
2479 enum pipe pipe = crtc->pipe;
2481 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
2482 hsw_disable_ips(old_crtc_state);
2484 if (intel_fbc_pre_update(state, crtc))
2485 intel_wait_for_vblank(dev_priv, pipe);
2487 /* Display WA 827 */
2488 if (!needs_nv12_wa(old_crtc_state) &&
2489 needs_nv12_wa(new_crtc_state))
2490 skl_wa_827(dev_priv, pipe, true);
2492 /* Wa_2006604312:icl,ehl */
2493 if (!needs_scalerclk_wa(old_crtc_state) &&
2494 needs_scalerclk_wa(new_crtc_state))
2495 icl_wa_scalerclkgating(dev_priv, pipe, true);
2498 * Vblank time updates from the shadow to live plane control register
2499 * are blocked if the memory self-refresh mode is active at that
2500 * moment. So to make sure the plane gets truly disabled, disable
2501 * first the self-refresh mode. The self-refresh enable bit in turn
2502 * will be checked/applied by the HW only at the next frame start
2503 * event which is after the vblank start event, so we need to have a
2504 * wait-for-vblank between disabling the plane and the pipe.
2506 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
2507 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
2508 intel_wait_for_vblank(dev_priv, pipe);
2511 * IVB workaround: must disable low power watermarks for at least
2512 * one frame before enabling scaling. LP watermarks can be re-enabled
2513 * when scaling is disabled.
2515 * WaCxSRDisabledForSpriteScaling:ivb
2517 if (old_crtc_state->hw.active &&
2518 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
2519 intel_wait_for_vblank(dev_priv, pipe);
2522 * If we're doing a modeset we don't need to do any
2523 * pre-vblank watermark programming here.
2525 if (!intel_crtc_needs_modeset(new_crtc_state)) {
2527 * For platforms that support atomic watermarks, program the
2528 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
2529 * will be the intermediate values that are safe for both pre- and
2530 * post- vblank; when vblank happens, the 'active' values will be set
2531 * to the final 'target' values and we'll do this again to get the
2532 * optimal watermarks. For gen9+ platforms, the values we program here
2533 * will be the final target values which will get automatically latched
2534 * at vblank time; no further programming will be necessary.
2536 * If a platform hasn't been transitioned to atomic watermarks yet,
2537 * we'll continue to update watermarks the old way, if flags tell
2540 if (dev_priv->display.initial_watermarks)
2541 dev_priv->display.initial_watermarks(state, crtc);
2542 else if (new_crtc_state->update_wm_pre)
2543 intel_update_watermarks(crtc);
2547 * Gen2 reports pipe underruns whenever all planes are disabled.
2548 * So disable underrun reporting before all the planes get disabled.
2550 * We do this after .initial_watermarks() so that we have a
2551 * chance of catching underruns with the intermediate watermarks
2552 * vs. the old plane configuration.
2554 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
2555 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2558 * WA for platforms where async address update enable bit
2559 * is double buffered and only latched at start of vblank.
2561 if (old_crtc_state->uapi.async_flip && !new_crtc_state->uapi.async_flip)
2562 intel_crtc_async_flip_disable_wa(state, crtc);
2565 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
2566 struct intel_crtc *crtc)
2568 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2569 const struct intel_crtc_state *new_crtc_state =
2570 intel_atomic_get_new_crtc_state(state, crtc);
2571 unsigned int update_mask = new_crtc_state->update_planes;
2572 const struct intel_plane_state *old_plane_state;
2573 struct intel_plane *plane;
2574 unsigned fb_bits = 0;
2577 intel_crtc_dpms_overlay_disable(crtc);
2579 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
2580 if (crtc->pipe != plane->pipe ||
2581 !(update_mask & BIT(plane->id)))
2584 intel_disable_plane(plane, new_crtc_state);
2586 if (old_plane_state->uapi.visible)
2587 fb_bits |= plane->frontbuffer_bit;
2590 intel_frontbuffer_flip(dev_priv, fb_bits);
2594 * intel_connector_primary_encoder - get the primary encoder for a connector
2595 * @connector: connector for which to return the encoder
2597 * Returns the primary encoder for a connector. There is a 1:1 mapping from
2598 * all connectors to their encoder, except for DP-MST connectors which have
2599 * both a virtual and a primary encoder. These DP-MST primary encoders can be
2600 * pointed to by as many DP-MST connectors as there are pipes.
2602 static struct intel_encoder *
2603 intel_connector_primary_encoder(struct intel_connector *connector)
2605 struct intel_encoder *encoder;
2607 if (connector->mst_port)
2608 return &dp_to_dig_port(connector->mst_port)->base;
2610 encoder = intel_attached_encoder(connector);
2611 drm_WARN_ON(connector->base.dev, !encoder);
2616 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
2618 struct drm_connector_state *new_conn_state;
2619 struct drm_connector *connector;
2622 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
2624 struct intel_connector *intel_connector;
2625 struct intel_encoder *encoder;
2626 struct intel_crtc *crtc;
2628 if (!intel_connector_needs_modeset(state, connector))
2631 intel_connector = to_intel_connector(connector);
2632 encoder = intel_connector_primary_encoder(intel_connector);
2633 if (!encoder->update_prepare)
2636 crtc = new_conn_state->crtc ?
2637 to_intel_crtc(new_conn_state->crtc) : NULL;
2638 encoder->update_prepare(state, encoder, crtc);
2642 static void intel_encoders_update_complete(struct intel_atomic_state *state)
2644 struct drm_connector_state *new_conn_state;
2645 struct drm_connector *connector;
2648 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
2650 struct intel_connector *intel_connector;
2651 struct intel_encoder *encoder;
2652 struct intel_crtc *crtc;
2654 if (!intel_connector_needs_modeset(state, connector))
2657 intel_connector = to_intel_connector(connector);
2658 encoder = intel_connector_primary_encoder(intel_connector);
2659 if (!encoder->update_complete)
2662 crtc = new_conn_state->crtc ?
2663 to_intel_crtc(new_conn_state->crtc) : NULL;
2664 encoder->update_complete(state, encoder, crtc);
2668 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
2669 struct intel_crtc *crtc)
2671 const struct intel_crtc_state *crtc_state =
2672 intel_atomic_get_new_crtc_state(state, crtc);
2673 const struct drm_connector_state *conn_state;
2674 struct drm_connector *conn;
2677 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
2678 struct intel_encoder *encoder =
2679 to_intel_encoder(conn_state->best_encoder);
2681 if (conn_state->crtc != &crtc->base)
2684 if (encoder->pre_pll_enable)
2685 encoder->pre_pll_enable(state, encoder,
2686 crtc_state, conn_state);
2690 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
2691 struct intel_crtc *crtc)
2693 const struct intel_crtc_state *crtc_state =
2694 intel_atomic_get_new_crtc_state(state, crtc);
2695 const struct drm_connector_state *conn_state;
2696 struct drm_connector *conn;
2699 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
2700 struct intel_encoder *encoder =
2701 to_intel_encoder(conn_state->best_encoder);
2703 if (conn_state->crtc != &crtc->base)
2706 if (encoder->pre_enable)
2707 encoder->pre_enable(state, encoder,
2708 crtc_state, conn_state);
2712 static void intel_encoders_enable(struct intel_atomic_state *state,
2713 struct intel_crtc *crtc)
2715 const struct intel_crtc_state *crtc_state =
2716 intel_atomic_get_new_crtc_state(state, crtc);
2717 const struct drm_connector_state *conn_state;
2718 struct drm_connector *conn;
2721 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
2722 struct intel_encoder *encoder =
2723 to_intel_encoder(conn_state->best_encoder);
2725 if (conn_state->crtc != &crtc->base)
2728 if (encoder->enable)
2729 encoder->enable(state, encoder,
2730 crtc_state, conn_state);
2731 intel_opregion_notify_encoder(encoder, true);
2735 static void intel_encoders_pre_disable(struct intel_atomic_state *state,
2736 struct intel_crtc *crtc)
2738 const struct intel_crtc_state *old_crtc_state =
2739 intel_atomic_get_old_crtc_state(state, crtc);
2740 const struct drm_connector_state *old_conn_state;
2741 struct drm_connector *conn;
2744 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
2745 struct intel_encoder *encoder =
2746 to_intel_encoder(old_conn_state->best_encoder);
2748 if (old_conn_state->crtc != &crtc->base)
2751 if (encoder->pre_disable)
2752 encoder->pre_disable(state, encoder, old_crtc_state,
2757 static void intel_encoders_disable(struct intel_atomic_state *state,
2758 struct intel_crtc *crtc)
2760 const struct intel_crtc_state *old_crtc_state =
2761 intel_atomic_get_old_crtc_state(state, crtc);
2762 const struct drm_connector_state *old_conn_state;
2763 struct drm_connector *conn;
2766 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
2767 struct intel_encoder *encoder =
2768 to_intel_encoder(old_conn_state->best_encoder);
2770 if (old_conn_state->crtc != &crtc->base)
2773 intel_opregion_notify_encoder(encoder, false);
2774 if (encoder->disable)
2775 encoder->disable(state, encoder,
2776 old_crtc_state, old_conn_state);
2780 static void intel_encoders_post_disable(struct intel_atomic_state *state,
2781 struct intel_crtc *crtc)
2783 const struct intel_crtc_state *old_crtc_state =
2784 intel_atomic_get_old_crtc_state(state, crtc);
2785 const struct drm_connector_state *old_conn_state;
2786 struct drm_connector *conn;
2789 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
2790 struct intel_encoder *encoder =
2791 to_intel_encoder(old_conn_state->best_encoder);
2793 if (old_conn_state->crtc != &crtc->base)
2796 if (encoder->post_disable)
2797 encoder->post_disable(state, encoder,
2798 old_crtc_state, old_conn_state);
2802 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
2803 struct intel_crtc *crtc)
2805 const struct intel_crtc_state *old_crtc_state =
2806 intel_atomic_get_old_crtc_state(state, crtc);
2807 const struct drm_connector_state *old_conn_state;
2808 struct drm_connector *conn;
2811 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
2812 struct intel_encoder *encoder =
2813 to_intel_encoder(old_conn_state->best_encoder);
2815 if (old_conn_state->crtc != &crtc->base)
2818 if (encoder->post_pll_disable)
2819 encoder->post_pll_disable(state, encoder,
2820 old_crtc_state, old_conn_state);
2824 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
2825 struct intel_crtc *crtc)
2827 const struct intel_crtc_state *crtc_state =
2828 intel_atomic_get_new_crtc_state(state, crtc);
2829 const struct drm_connector_state *conn_state;
2830 struct drm_connector *conn;
2833 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
2834 struct intel_encoder *encoder =
2835 to_intel_encoder(conn_state->best_encoder);
2837 if (conn_state->crtc != &crtc->base)
2840 if (encoder->update_pipe)
2841 encoder->update_pipe(state, encoder,
2842 crtc_state, conn_state);
2846 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
2848 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2849 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
2851 plane->disable_plane(plane, crtc_state);
2854 static void ilk_crtc_enable(struct intel_atomic_state *state,
2855 struct intel_crtc *crtc)
2857 const struct intel_crtc_state *new_crtc_state =
2858 intel_atomic_get_new_crtc_state(state, crtc);
2859 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2860 enum pipe pipe = crtc->pipe;
2862 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2866 * Sometimes spurious CPU pipe underruns happen during FDI
2867 * training, at least with VGA+HDMI cloning. Suppress them.
2869 * On ILK we get an occasional spurious CPU pipe underruns
2870 * between eDP port A enable and vdd enable. Also PCH port
2871 * enable seems to result in the occasional CPU pipe underrun.
2873 * Spurious PCH underruns also occur during PCH enabling.
2875 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2876 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
2878 if (intel_crtc_has_dp_encoder(new_crtc_state))
2879 intel_dp_set_m_n(new_crtc_state, M1_N1);
2881 intel_set_transcoder_timings(new_crtc_state);
2882 intel_set_pipe_src_size(new_crtc_state);
2884 if (new_crtc_state->has_pch_encoder)
2885 intel_cpu_transcoder_set_m_n(new_crtc_state,
2886 &new_crtc_state->fdi_m_n, NULL);
2888 ilk_set_pipeconf(new_crtc_state);
2890 crtc->active = true;
2892 intel_encoders_pre_enable(state, crtc);
2894 if (new_crtc_state->has_pch_encoder) {
2895 /* Note: FDI PLL enabling _must_ be done before we enable the
2896 * cpu pipes, hence this is separate from all the other fdi/pch
2898 ilk_fdi_pll_enable(new_crtc_state);
2900 assert_fdi_tx_disabled(dev_priv, pipe);
2901 assert_fdi_rx_disabled(dev_priv, pipe);
2904 ilk_pfit_enable(new_crtc_state);
2907 * On ILK+ LUT must be loaded before the pipe is running but with
2910 intel_color_load_luts(new_crtc_state);
2911 intel_color_commit(new_crtc_state);
2912 /* update DSPCNTR to configure gamma for pipe bottom color */
2913 intel_disable_primary_plane(new_crtc_state);
2915 if (dev_priv->display.initial_watermarks)
2916 dev_priv->display.initial_watermarks(state, crtc);
2917 intel_enable_transcoder(new_crtc_state);
2919 if (new_crtc_state->has_pch_encoder)
2920 ilk_pch_enable(state, new_crtc_state);
2922 intel_crtc_vblank_on(new_crtc_state);
2924 intel_encoders_enable(state, crtc);
2926 if (HAS_PCH_CPT(dev_priv))
2927 cpt_verify_modeset(dev_priv, pipe);
2930 * Must wait for vblank to avoid spurious PCH FIFO underruns.
2931 * And a second vblank wait is needed at least on ILK with
2932 * some interlaced HDMI modes. Let's do the double wait always
2933 * in case there are more corner cases we don't know about.
2935 if (new_crtc_state->has_pch_encoder) {
2936 intel_wait_for_vblank(dev_priv, pipe);
2937 intel_wait_for_vblank(dev_priv, pipe);
2939 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2940 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
2943 /* IPS only exists on ULT machines and is tied to pipe A. */
2944 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
2946 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
2949 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
2950 enum pipe pipe, bool apply)
2952 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
2953 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
2960 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
2963 static void icl_pipe_mbus_enable(struct intel_crtc *crtc, bool joined_mbus)
2965 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2966 enum pipe pipe = crtc->pipe;
2969 /* Wa_22010947358:adl-p */
2970 if (IS_ALDERLAKE_P(dev_priv))
2971 val = joined_mbus ? MBUS_DBOX_A_CREDIT(6) : MBUS_DBOX_A_CREDIT(4);
2973 val = MBUS_DBOX_A_CREDIT(2);
2975 if (DISPLAY_VER(dev_priv) >= 12) {
2976 val |= MBUS_DBOX_BW_CREDIT(2);
2977 val |= MBUS_DBOX_B_CREDIT(12);
2979 val |= MBUS_DBOX_BW_CREDIT(1);
2980 val |= MBUS_DBOX_B_CREDIT(8);
2983 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
2986 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
2988 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2989 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2991 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
2992 HSW_LINETIME(crtc_state->linetime) |
2993 HSW_IPS_LINETIME(crtc_state->ips_linetime));
2996 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
2998 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2999 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3000 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
3003 val = intel_de_read(dev_priv, reg);
3004 val &= ~HSW_FRAME_START_DELAY_MASK;
3005 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
3006 intel_de_write(dev_priv, reg, val);
3009 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
3010 const struct intel_crtc_state *crtc_state)
3012 struct intel_crtc *master = to_intel_crtc(crtc_state->uapi.crtc);
3013 struct drm_i915_private *dev_priv = to_i915(master->base.dev);
3014 struct intel_crtc_state *master_crtc_state;
3015 struct drm_connector_state *conn_state;
3016 struct drm_connector *conn;
3017 struct intel_encoder *encoder = NULL;
3020 if (crtc_state->bigjoiner_slave)
3021 master = crtc_state->bigjoiner_linked_crtc;
3023 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
3025 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3026 if (conn_state->crtc != &master->base)
3029 encoder = to_intel_encoder(conn_state->best_encoder);
3033 if (!crtc_state->bigjoiner_slave) {
3034 /* need to enable VDSC, which we skipped in pre-enable */
3035 intel_dsc_enable(encoder, crtc_state);
3038 * Enable sequence steps 1-7 on bigjoiner master
3040 intel_encoders_pre_pll_enable(state, master);
3041 if (master_crtc_state->shared_dpll)
3042 intel_enable_shared_dpll(master_crtc_state);
3043 intel_encoders_pre_enable(state, master);
3045 /* and DSC on slave */
3046 intel_dsc_enable(NULL, crtc_state);
3049 if (DISPLAY_VER(dev_priv) >= 13)
3050 intel_uncompressed_joiner_enable(crtc_state);
3053 static void hsw_crtc_enable(struct intel_atomic_state *state,
3054 struct intel_crtc *crtc)
3056 const struct intel_crtc_state *new_crtc_state =
3057 intel_atomic_get_new_crtc_state(state, crtc);
3058 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3059 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
3060 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
3061 bool psl_clkgate_wa;
3063 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3066 if (!new_crtc_state->bigjoiner) {
3067 intel_encoders_pre_pll_enable(state, crtc);
3069 if (new_crtc_state->shared_dpll)
3070 intel_enable_shared_dpll(new_crtc_state);
3072 intel_encoders_pre_enable(state, crtc);
3074 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
3077 intel_set_pipe_src_size(new_crtc_state);
3078 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
3079 bdw_set_pipemisc(new_crtc_state);
3081 if (!new_crtc_state->bigjoiner_slave && !transcoder_is_dsi(cpu_transcoder)) {
3082 intel_set_transcoder_timings(new_crtc_state);
3084 if (cpu_transcoder != TRANSCODER_EDP)
3085 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
3086 new_crtc_state->pixel_multiplier - 1);
3088 if (new_crtc_state->has_pch_encoder)
3089 intel_cpu_transcoder_set_m_n(new_crtc_state,
3090 &new_crtc_state->fdi_m_n, NULL);
3092 hsw_set_frame_start_delay(new_crtc_state);
3095 if (!transcoder_is_dsi(cpu_transcoder))
3096 hsw_set_transconf(new_crtc_state);
3098 crtc->active = true;
3100 /* Display WA #1180: WaDisableScalarClockGating: glk */
3101 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
3102 new_crtc_state->pch_pfit.enabled;
3104 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
3106 if (DISPLAY_VER(dev_priv) >= 9)
3107 skl_pfit_enable(new_crtc_state);
3109 ilk_pfit_enable(new_crtc_state);
3112 * On ILK+ LUT must be loaded before the pipe is running but with
3115 intel_color_load_luts(new_crtc_state);
3116 intel_color_commit(new_crtc_state);
3117 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
3118 if (DISPLAY_VER(dev_priv) < 9)
3119 intel_disable_primary_plane(new_crtc_state);
3121 hsw_set_linetime_wm(new_crtc_state);
3123 if (DISPLAY_VER(dev_priv) >= 11)
3124 icl_set_pipe_chicken(new_crtc_state);
3126 if (dev_priv->display.initial_watermarks)
3127 dev_priv->display.initial_watermarks(state, crtc);
3129 if (DISPLAY_VER(dev_priv) >= 11) {
3130 const struct intel_dbuf_state *dbuf_state =
3131 intel_atomic_get_new_dbuf_state(state);
3133 icl_pipe_mbus_enable(crtc, dbuf_state->joined_mbus);
3136 if (new_crtc_state->bigjoiner_slave)
3137 intel_crtc_vblank_on(new_crtc_state);
3139 intel_encoders_enable(state, crtc);
3141 if (psl_clkgate_wa) {
3142 intel_wait_for_vblank(dev_priv, pipe);
3143 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
3146 /* If we change the relative order between pipe/planes enabling, we need
3147 * to change the workaround. */
3148 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
3149 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
3150 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
3151 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
3155 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
3157 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
3158 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3159 enum pipe pipe = crtc->pipe;
3161 /* To avoid upsetting the power well on haswell only disable the pfit if
3162 * it's in use. The hw state code will make sure we get this right. */
3163 if (!old_crtc_state->pch_pfit.enabled)
3166 intel_de_write(dev_priv, PF_CTL(pipe), 0);
3167 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
3168 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
3171 static void ilk_crtc_disable(struct intel_atomic_state *state,
3172 struct intel_crtc *crtc)
3174 const struct intel_crtc_state *old_crtc_state =
3175 intel_atomic_get_old_crtc_state(state, crtc);
3176 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3177 enum pipe pipe = crtc->pipe;
3180 * Sometimes spurious CPU pipe underruns happen when the
3181 * pipe is already disabled, but FDI RX/TX is still enabled.
3182 * Happens at least with VGA+HDMI cloning. Suppress them.
3184 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
3185 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
3187 intel_encoders_disable(state, crtc);
3189 intel_crtc_vblank_off(old_crtc_state);
3191 intel_disable_transcoder(old_crtc_state);
3193 ilk_pfit_disable(old_crtc_state);
3195 if (old_crtc_state->has_pch_encoder)
3196 ilk_fdi_disable(crtc);
3198 intel_encoders_post_disable(state, crtc);
3200 if (old_crtc_state->has_pch_encoder) {
3201 ilk_disable_pch_transcoder(dev_priv, pipe);
3203 if (HAS_PCH_CPT(dev_priv)) {
3207 /* disable TRANS_DP_CTL */
3208 reg = TRANS_DP_CTL(pipe);
3209 temp = intel_de_read(dev_priv, reg);
3210 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
3211 TRANS_DP_PORT_SEL_MASK);
3212 temp |= TRANS_DP_PORT_SEL_NONE;
3213 intel_de_write(dev_priv, reg, temp);
3215 /* disable DPLL_SEL */
3216 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
3217 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
3218 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
3221 ilk_fdi_pll_disable(crtc);
3224 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3225 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
3228 static void hsw_crtc_disable(struct intel_atomic_state *state,
3229 struct intel_crtc *crtc)
3232 * FIXME collapse everything to one hook.
3233 * Need care with mst->ddi interactions.
3235 intel_encoders_disable(state, crtc);
3236 intel_encoders_post_disable(state, crtc);
3239 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
3241 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3242 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3244 if (!crtc_state->gmch_pfit.control)
3248 * The panel fitter should only be adjusted whilst the pipe is disabled,
3249 * according to register description and PRM.
3251 drm_WARN_ON(&dev_priv->drm,
3252 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
3253 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
3255 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
3256 crtc_state->gmch_pfit.pgm_ratios);
3257 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
3259 /* Border color in case we don't scale up to the full screen. Black by
3260 * default, change to something else for debugging. */
3261 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
3264 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
3266 if (phy == PHY_NONE)
3268 else if (IS_DG2(dev_priv))
3270 * DG2 outputs labelled as "combo PHY" in the bspec use
3271 * SNPS PHYs with completely different programming,
3272 * hence we always return false here.
3275 else if (IS_ALDERLAKE_S(dev_priv))
3276 return phy <= PHY_E;
3277 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
3278 return phy <= PHY_D;
3279 else if (IS_JSL_EHL(dev_priv))
3280 return phy <= PHY_C;
3281 else if (DISPLAY_VER(dev_priv) >= 11)
3282 return phy <= PHY_B;
3287 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
3289 if (IS_DG2(dev_priv))
3290 /* DG2's "TC1" output uses a SNPS PHY */
3292 else if (IS_ALDERLAKE_P(dev_priv))
3293 return phy >= PHY_F && phy <= PHY_I;
3294 else if (IS_TIGERLAKE(dev_priv))
3295 return phy >= PHY_D && phy <= PHY_I;
3296 else if (IS_ICELAKE(dev_priv))
3297 return phy >= PHY_C && phy <= PHY_F;
3302 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
3304 if (phy == PHY_NONE)
3306 else if (IS_DG2(dev_priv))
3308 * All four "combo" ports and the TC1 port (PHY E) use
3311 return phy <= PHY_E;
3316 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
3318 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
3319 return PHY_D + port - PORT_D_XELPD;
3320 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
3321 return PHY_F + port - PORT_TC1;
3322 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
3323 return PHY_B + port - PORT_TC1;
3324 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
3325 return PHY_C + port - PORT_TC1;
3326 else if (IS_JSL_EHL(i915) && port == PORT_D)
3329 return PHY_A + port - PORT_A;
3332 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
3334 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
3335 return TC_PORT_NONE;
3337 if (DISPLAY_VER(dev_priv) >= 12)
3338 return TC_PORT_1 + port - PORT_TC1;
3340 return TC_PORT_1 + port - PORT_C;
3343 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
3347 return POWER_DOMAIN_PORT_DDI_A_LANES;
3349 return POWER_DOMAIN_PORT_DDI_B_LANES;
3351 return POWER_DOMAIN_PORT_DDI_C_LANES;
3353 return POWER_DOMAIN_PORT_DDI_D_LANES;
3355 return POWER_DOMAIN_PORT_DDI_E_LANES;
3357 return POWER_DOMAIN_PORT_DDI_F_LANES;
3359 return POWER_DOMAIN_PORT_DDI_G_LANES;
3361 return POWER_DOMAIN_PORT_DDI_H_LANES;
3363 return POWER_DOMAIN_PORT_DDI_I_LANES;
3366 return POWER_DOMAIN_PORT_OTHER;
3370 enum intel_display_power_domain
3371 intel_aux_power_domain(struct intel_digital_port *dig_port)
3373 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3374 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
3376 if (intel_phy_is_tc(dev_priv, phy) &&
3377 dig_port->tc_mode == TC_PORT_TBT_ALT) {
3378 switch (dig_port->aux_ch) {
3380 return POWER_DOMAIN_AUX_C_TBT;
3382 return POWER_DOMAIN_AUX_D_TBT;
3384 return POWER_DOMAIN_AUX_E_TBT;
3386 return POWER_DOMAIN_AUX_F_TBT;
3388 return POWER_DOMAIN_AUX_G_TBT;
3390 return POWER_DOMAIN_AUX_H_TBT;
3392 return POWER_DOMAIN_AUX_I_TBT;
3394 MISSING_CASE(dig_port->aux_ch);
3395 return POWER_DOMAIN_AUX_C_TBT;
3399 return intel_legacy_aux_to_power_domain(dig_port->aux_ch);
3403 * Converts aux_ch to power_domain without caring about TBT ports for that use
3404 * intel_aux_power_domain()
3406 enum intel_display_power_domain
3407 intel_legacy_aux_to_power_domain(enum aux_ch aux_ch)
3411 return POWER_DOMAIN_AUX_A;
3413 return POWER_DOMAIN_AUX_B;
3415 return POWER_DOMAIN_AUX_C;
3417 return POWER_DOMAIN_AUX_D;
3419 return POWER_DOMAIN_AUX_E;
3421 return POWER_DOMAIN_AUX_F;
3423 return POWER_DOMAIN_AUX_G;
3425 return POWER_DOMAIN_AUX_H;
3427 return POWER_DOMAIN_AUX_I;
3429 MISSING_CASE(aux_ch);
3430 return POWER_DOMAIN_AUX_A;
3434 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
3436 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3437 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3438 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3439 struct drm_encoder *encoder;
3440 enum pipe pipe = crtc->pipe;
3443 if (!crtc_state->hw.active)
3446 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
3447 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(cpu_transcoder));
3448 if (crtc_state->pch_pfit.enabled ||
3449 crtc_state->pch_pfit.force_thru)
3450 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
3452 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
3453 crtc_state->uapi.encoder_mask) {
3454 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3456 mask |= BIT_ULL(intel_encoder->power_domain);
3459 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
3460 mask |= BIT_ULL(POWER_DOMAIN_AUDIO_MMIO);
3462 if (crtc_state->shared_dpll)
3463 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
3465 if (crtc_state->dsc.compression_enable)
3466 mask |= BIT_ULL(intel_dsc_power_domain(crtc, cpu_transcoder));
3472 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
3474 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3475 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3476 enum intel_display_power_domain domain;
3477 u64 domains, new_domains, old_domains;
3479 domains = get_crtc_power_domains(crtc_state);
3481 new_domains = domains & ~crtc->enabled_power_domains.mask;
3482 old_domains = crtc->enabled_power_domains.mask & ~domains;
3484 for_each_power_domain(domain, new_domains)
3485 intel_display_power_get_in_set(dev_priv,
3486 &crtc->enabled_power_domains,
3492 static void modeset_put_crtc_power_domains(struct intel_crtc *crtc,
3495 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
3496 &crtc->enabled_power_domains,
3500 static void valleyview_crtc_enable(struct intel_atomic_state *state,
3501 struct intel_crtc *crtc)
3503 const struct intel_crtc_state *new_crtc_state =
3504 intel_atomic_get_new_crtc_state(state, crtc);
3505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3506 enum pipe pipe = crtc->pipe;
3508 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3511 if (intel_crtc_has_dp_encoder(new_crtc_state))
3512 intel_dp_set_m_n(new_crtc_state, M1_N1);
3514 intel_set_transcoder_timings(new_crtc_state);
3515 intel_set_pipe_src_size(new_crtc_state);
3517 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3518 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
3519 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
3522 i9xx_set_pipeconf(new_crtc_state);
3524 crtc->active = true;
3526 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3528 intel_encoders_pre_pll_enable(state, crtc);
3530 if (IS_CHERRYVIEW(dev_priv))
3531 chv_enable_pll(new_crtc_state);
3533 vlv_enable_pll(new_crtc_state);
3535 intel_encoders_pre_enable(state, crtc);
3537 i9xx_pfit_enable(new_crtc_state);
3539 intel_color_load_luts(new_crtc_state);
3540 intel_color_commit(new_crtc_state);
3541 /* update DSPCNTR to configure gamma for pipe bottom color */
3542 intel_disable_primary_plane(new_crtc_state);
3544 dev_priv->display.initial_watermarks(state, crtc);
3545 intel_enable_transcoder(new_crtc_state);
3547 intel_crtc_vblank_on(new_crtc_state);
3549 intel_encoders_enable(state, crtc);
3552 static void i9xx_crtc_enable(struct intel_atomic_state *state,
3553 struct intel_crtc *crtc)
3555 const struct intel_crtc_state *new_crtc_state =
3556 intel_atomic_get_new_crtc_state(state, crtc);
3557 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3558 enum pipe pipe = crtc->pipe;
3560 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3563 if (intel_crtc_has_dp_encoder(new_crtc_state))
3564 intel_dp_set_m_n(new_crtc_state, M1_N1);
3566 intel_set_transcoder_timings(new_crtc_state);
3567 intel_set_pipe_src_size(new_crtc_state);
3569 i9xx_set_pipeconf(new_crtc_state);
3571 crtc->active = true;
3573 if (DISPLAY_VER(dev_priv) != 2)
3574 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3576 intel_encoders_pre_enable(state, crtc);
3578 i9xx_enable_pll(new_crtc_state);
3580 i9xx_pfit_enable(new_crtc_state);
3582 intel_color_load_luts(new_crtc_state);
3583 intel_color_commit(new_crtc_state);
3584 /* update DSPCNTR to configure gamma for pipe bottom color */
3585 intel_disable_primary_plane(new_crtc_state);
3587 if (dev_priv->display.initial_watermarks)
3588 dev_priv->display.initial_watermarks(state, crtc);
3590 intel_update_watermarks(crtc);
3591 intel_enable_transcoder(new_crtc_state);
3593 intel_crtc_vblank_on(new_crtc_state);
3595 intel_encoders_enable(state, crtc);
3597 /* prevents spurious underruns */
3598 if (DISPLAY_VER(dev_priv) == 2)
3599 intel_wait_for_vblank(dev_priv, pipe);
3602 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
3604 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
3605 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3607 if (!old_crtc_state->gmch_pfit.control)
3610 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
3612 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
3613 intel_de_read(dev_priv, PFIT_CONTROL));
3614 intel_de_write(dev_priv, PFIT_CONTROL, 0);
3617 static void i9xx_crtc_disable(struct intel_atomic_state *state,
3618 struct intel_crtc *crtc)
3620 struct intel_crtc_state *old_crtc_state =
3621 intel_atomic_get_old_crtc_state(state, crtc);
3622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3623 enum pipe pipe = crtc->pipe;
3626 * On gen2 planes are double buffered but the pipe isn't, so we must
3627 * wait for planes to fully turn off before disabling the pipe.
3629 if (DISPLAY_VER(dev_priv) == 2)
3630 intel_wait_for_vblank(dev_priv, pipe);
3632 intel_encoders_disable(state, crtc);
3634 intel_crtc_vblank_off(old_crtc_state);
3636 intel_disable_transcoder(old_crtc_state);
3638 i9xx_pfit_disable(old_crtc_state);
3640 intel_encoders_post_disable(state, crtc);
3642 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
3643 if (IS_CHERRYVIEW(dev_priv))
3644 chv_disable_pll(dev_priv, pipe);
3645 else if (IS_VALLEYVIEW(dev_priv))
3646 vlv_disable_pll(dev_priv, pipe);
3648 i9xx_disable_pll(old_crtc_state);
3651 intel_encoders_post_pll_disable(state, crtc);
3653 if (DISPLAY_VER(dev_priv) != 2)
3654 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
3656 if (!dev_priv->display.initial_watermarks)
3657 intel_update_watermarks(crtc);
3659 /* clock the pipe down to 640x480@60 to potentially save power */
3660 if (IS_I830(dev_priv))
3661 i830_enable_pipe(dev_priv, pipe);
3664 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
3665 struct drm_modeset_acquire_ctx *ctx)
3667 struct intel_encoder *encoder;
3668 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3669 struct intel_bw_state *bw_state =
3670 to_intel_bw_state(dev_priv->bw_obj.state);
3671 struct intel_cdclk_state *cdclk_state =
3672 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
3673 struct intel_dbuf_state *dbuf_state =
3674 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
3675 struct intel_crtc_state *crtc_state =
3676 to_intel_crtc_state(crtc->base.state);
3677 struct intel_plane *plane;
3678 struct drm_atomic_state *state;
3679 struct intel_crtc_state *temp_crtc_state;
3680 enum pipe pipe = crtc->pipe;
3683 if (!crtc_state->hw.active)
3686 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
3687 const struct intel_plane_state *plane_state =
3688 to_intel_plane_state(plane->base.state);
3690 if (plane_state->uapi.visible)
3691 intel_plane_disable_noatomic(crtc, plane);
3694 state = drm_atomic_state_alloc(&dev_priv->drm);
3696 drm_dbg_kms(&dev_priv->drm,
3697 "failed to disable [CRTC:%d:%s], out of memory",
3698 crtc->base.base.id, crtc->base.name);
3702 state->acquire_ctx = ctx;
3704 /* Everything's already locked, -EDEADLK can't happen. */
3705 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
3706 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
3708 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
3710 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
3712 drm_atomic_state_put(state);
3714 drm_dbg_kms(&dev_priv->drm,
3715 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
3716 crtc->base.base.id, crtc->base.name);
3718 crtc->active = false;
3719 crtc->base.enabled = false;
3721 drm_WARN_ON(&dev_priv->drm,
3722 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
3723 crtc_state->uapi.active = false;
3724 crtc_state->uapi.connector_mask = 0;
3725 crtc_state->uapi.encoder_mask = 0;
3726 intel_crtc_free_hw_state(crtc_state);
3727 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
3729 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
3730 encoder->base.crtc = NULL;
3732 intel_fbc_disable(crtc);
3733 intel_update_watermarks(crtc);
3734 intel_disable_shared_dpll(crtc_state);
3736 intel_display_power_put_all_in_set(dev_priv, &crtc->enabled_power_domains);
3738 cdclk_state->min_cdclk[pipe] = 0;
3739 cdclk_state->min_voltage_level[pipe] = 0;
3740 cdclk_state->active_pipes &= ~BIT(pipe);
3742 dbuf_state->active_pipes &= ~BIT(pipe);
3744 bw_state->data_rate[pipe] = 0;
3745 bw_state->num_active_planes[pipe] = 0;
3749 * turn all crtc's off, but do not adjust state
3750 * This has to be paired with a call to intel_modeset_setup_hw_state.
3752 int intel_display_suspend(struct drm_device *dev)
3754 struct drm_i915_private *dev_priv = to_i915(dev);
3755 struct drm_atomic_state *state;
3758 if (!HAS_DISPLAY(dev_priv))
3761 state = drm_atomic_helper_suspend(dev);
3762 ret = PTR_ERR_OR_ZERO(state);
3764 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
3767 dev_priv->modeset_restore_state = state;
3771 void intel_encoder_destroy(struct drm_encoder *encoder)
3773 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3775 drm_encoder_cleanup(encoder);
3776 kfree(intel_encoder);
3779 /* Cross check the actual hw state with our own modeset state tracking (and it's
3780 * internal consistency). */
3781 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
3782 struct drm_connector_state *conn_state)
3784 struct intel_connector *connector = to_intel_connector(conn_state->connector);
3785 struct drm_i915_private *i915 = to_i915(connector->base.dev);
3787 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
3788 connector->base.base.id, connector->base.name);
3790 if (connector->get_hw_state(connector)) {
3791 struct intel_encoder *encoder = intel_attached_encoder(connector);
3793 I915_STATE_WARN(!crtc_state,
3794 "connector enabled without attached crtc\n");
3799 I915_STATE_WARN(!crtc_state->hw.active,
3800 "connector is active, but attached crtc isn't\n");
3802 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
3805 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
3806 "atomic encoder doesn't match attached encoder\n");
3808 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
3809 "attached encoder crtc differs from connector crtc\n");
3811 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
3812 "attached crtc is active, but connector isn't\n");
3813 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
3814 "best encoder set without crtc!\n");
3818 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
3820 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3821 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3823 /* IPS only exists on ULT machines and is tied to pipe A. */
3824 if (!hsw_crtc_supports_ips(crtc))
3827 if (!dev_priv->params.enable_ips)
3830 if (crtc_state->pipe_bpp > 24)
3834 * We compare against max which means we must take
3835 * the increased cdclk requirement into account when
3836 * calculating the new cdclk.
3838 * Should measure whether using a lower cdclk w/o IPS
3840 if (IS_BROADWELL(dev_priv) &&
3841 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
3847 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
3849 struct drm_i915_private *dev_priv =
3850 to_i915(crtc_state->uapi.crtc->dev);
3851 struct intel_atomic_state *state =
3852 to_intel_atomic_state(crtc_state->uapi.state);
3854 crtc_state->ips_enabled = false;
3856 if (!hsw_crtc_state_ips_capable(crtc_state))
3860 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3861 * enabled and disabled dynamically based on package C states,
3862 * user space can't make reliable use of the CRCs, so let's just
3863 * completely disable it.
3865 if (crtc_state->crc_enabled)
3868 /* IPS should be fine as long as at least one plane is enabled. */
3869 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
3872 if (IS_BROADWELL(dev_priv)) {
3873 const struct intel_cdclk_state *cdclk_state;
3875 cdclk_state = intel_atomic_get_cdclk_state(state);
3876 if (IS_ERR(cdclk_state))
3877 return PTR_ERR(cdclk_state);
3879 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
3880 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
3884 crtc_state->ips_enabled = true;
3889 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
3891 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3893 /* GDG double wide on either pipe, otherwise pipe A only */
3894 return DISPLAY_VER(dev_priv) < 4 &&
3895 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
3898 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
3900 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
3901 struct drm_rect src;
3904 * We only use IF-ID interlacing. If we ever use
3905 * PF-ID we'll need to adjust the pixel_rate here.
3908 if (!crtc_state->pch_pfit.enabled)
3911 drm_rect_init(&src, 0, 0,
3912 crtc_state->pipe_src_w << 16,
3913 crtc_state->pipe_src_h << 16);
3915 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
3919 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
3920 const struct drm_display_mode *timings)
3922 mode->hdisplay = timings->crtc_hdisplay;
3923 mode->htotal = timings->crtc_htotal;
3924 mode->hsync_start = timings->crtc_hsync_start;
3925 mode->hsync_end = timings->crtc_hsync_end;
3927 mode->vdisplay = timings->crtc_vdisplay;
3928 mode->vtotal = timings->crtc_vtotal;
3929 mode->vsync_start = timings->crtc_vsync_start;
3930 mode->vsync_end = timings->crtc_vsync_end;
3932 mode->flags = timings->flags;
3933 mode->type = DRM_MODE_TYPE_DRIVER;
3935 mode->clock = timings->crtc_clock;
3937 drm_mode_set_name(mode);
3940 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
3942 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3944 if (HAS_GMCH(dev_priv))
3945 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
3946 crtc_state->pixel_rate =
3947 crtc_state->hw.pipe_mode.crtc_clock;
3949 crtc_state->pixel_rate =
3950 ilk_pipe_pixel_rate(crtc_state);
3953 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
3955 struct drm_display_mode *mode = &crtc_state->hw.mode;
3956 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
3957 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
3959 drm_mode_copy(pipe_mode, adjusted_mode);
3961 if (crtc_state->bigjoiner) {
3963 * transcoder is programmed to the full mode,
3964 * but pipe timings are half of the transcoder mode
3966 pipe_mode->crtc_hdisplay /= 2;
3967 pipe_mode->crtc_hblank_start /= 2;
3968 pipe_mode->crtc_hblank_end /= 2;
3969 pipe_mode->crtc_hsync_start /= 2;
3970 pipe_mode->crtc_hsync_end /= 2;
3971 pipe_mode->crtc_htotal /= 2;
3972 pipe_mode->crtc_clock /= 2;
3975 if (crtc_state->splitter.enable) {
3976 int n = crtc_state->splitter.link_count;
3977 int overlap = crtc_state->splitter.pixel_overlap;
3980 * eDP MSO uses segment timings from EDID for transcoder
3981 * timings, but full mode for everything else.
3983 * h_full = (h_segment - pixel_overlap) * link_count
3985 pipe_mode->crtc_hdisplay = (pipe_mode->crtc_hdisplay - overlap) * n;
3986 pipe_mode->crtc_hblank_start = (pipe_mode->crtc_hblank_start - overlap) * n;
3987 pipe_mode->crtc_hblank_end = (pipe_mode->crtc_hblank_end - overlap) * n;
3988 pipe_mode->crtc_hsync_start = (pipe_mode->crtc_hsync_start - overlap) * n;
3989 pipe_mode->crtc_hsync_end = (pipe_mode->crtc_hsync_end - overlap) * n;
3990 pipe_mode->crtc_htotal = (pipe_mode->crtc_htotal - overlap) * n;
3991 pipe_mode->crtc_clock *= n;
3993 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
3994 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
3996 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
3997 intel_mode_from_crtc_timings(adjusted_mode, adjusted_mode);
4000 intel_crtc_compute_pixel_rate(crtc_state);
4002 drm_mode_copy(mode, adjusted_mode);
4003 mode->hdisplay = crtc_state->pipe_src_w << crtc_state->bigjoiner;
4004 mode->vdisplay = crtc_state->pipe_src_h;
4007 static void intel_encoder_get_config(struct intel_encoder *encoder,
4008 struct intel_crtc_state *crtc_state)
4010 encoder->get_config(encoder, crtc_state);
4012 intel_crtc_readout_derived_state(crtc_state);
4015 static int intel_crtc_compute_config(struct intel_crtc *crtc,
4016 struct intel_crtc_state *pipe_config)
4018 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4019 struct drm_display_mode *pipe_mode = &pipe_config->hw.pipe_mode;
4020 int clock_limit = dev_priv->max_dotclk_freq;
4022 drm_mode_copy(pipe_mode, &pipe_config->hw.adjusted_mode);
4024 /* Adjust pipe_mode for bigjoiner, with half the horizontal mode */
4025 if (pipe_config->bigjoiner) {
4026 pipe_mode->crtc_clock /= 2;
4027 pipe_mode->crtc_hdisplay /= 2;
4028 pipe_mode->crtc_hblank_start /= 2;
4029 pipe_mode->crtc_hblank_end /= 2;
4030 pipe_mode->crtc_hsync_start /= 2;
4031 pipe_mode->crtc_hsync_end /= 2;
4032 pipe_mode->crtc_htotal /= 2;
4033 pipe_config->pipe_src_w /= 2;
4036 if (pipe_config->splitter.enable) {
4037 int n = pipe_config->splitter.link_count;
4038 int overlap = pipe_config->splitter.pixel_overlap;
4040 pipe_mode->crtc_hdisplay = (pipe_mode->crtc_hdisplay - overlap) * n;
4041 pipe_mode->crtc_hblank_start = (pipe_mode->crtc_hblank_start - overlap) * n;
4042 pipe_mode->crtc_hblank_end = (pipe_mode->crtc_hblank_end - overlap) * n;
4043 pipe_mode->crtc_hsync_start = (pipe_mode->crtc_hsync_start - overlap) * n;
4044 pipe_mode->crtc_hsync_end = (pipe_mode->crtc_hsync_end - overlap) * n;
4045 pipe_mode->crtc_htotal = (pipe_mode->crtc_htotal - overlap) * n;
4046 pipe_mode->crtc_clock *= n;
4049 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
4051 if (DISPLAY_VER(dev_priv) < 4) {
4052 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
4055 * Enable double wide mode when the dot clock
4056 * is > 90% of the (display) core speed.
4058 if (intel_crtc_supports_double_wide(crtc) &&
4059 pipe_mode->crtc_clock > clock_limit) {
4060 clock_limit = dev_priv->max_dotclk_freq;
4061 pipe_config->double_wide = true;
4065 if (pipe_mode->crtc_clock > clock_limit) {
4066 drm_dbg_kms(&dev_priv->drm,
4067 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
4068 pipe_mode->crtc_clock, clock_limit,
4069 yesno(pipe_config->double_wide));
4074 * Pipe horizontal size must be even in:
4076 * - LVDS dual channel mode
4077 * - Double wide pipe
4079 if (pipe_config->pipe_src_w & 1) {
4080 if (pipe_config->double_wide) {
4081 drm_dbg_kms(&dev_priv->drm,
4082 "Odd pipe source width not supported with double wide pipe\n");
4086 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
4087 intel_is_dual_link_lvds(dev_priv)) {
4088 drm_dbg_kms(&dev_priv->drm,
4089 "Odd pipe source width not supported with dual link LVDS\n");
4094 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
4095 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
4097 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
4098 pipe_mode->crtc_hsync_start == pipe_mode->crtc_hdisplay)
4101 intel_crtc_compute_pixel_rate(pipe_config);
4103 if (pipe_config->has_pch_encoder)
4104 return ilk_fdi_compute_config(crtc, pipe_config);
4110 intel_reduce_m_n_ratio(u32 *num, u32 *den)
4112 while (*num > DATA_LINK_M_N_MASK ||
4113 *den > DATA_LINK_M_N_MASK) {
4119 static void compute_m_n(unsigned int m, unsigned int n,
4120 u32 *ret_m, u32 *ret_n,
4124 * Several DP dongles in particular seem to be fussy about
4125 * too large link M/N values. Give N value as 0x8000 that
4126 * should be acceptable by specific devices. 0x8000 is the
4127 * specified fixed N value for asynchronous clock mode,
4128 * which the devices expect also in synchronous clock mode.
4131 *ret_n = DP_LINK_CONSTANT_N_VALUE;
4133 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
4135 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
4136 intel_reduce_m_n_ratio(ret_m, ret_n);
4140 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
4141 int pixel_clock, int link_clock,
4142 struct intel_link_m_n *m_n,
4143 bool constant_n, bool fec_enable)
4145 u32 data_clock = bits_per_pixel * pixel_clock;
4148 data_clock = intel_dp_mode_to_fec_clock(data_clock);
4151 compute_m_n(data_clock,
4152 link_clock * nlanes * 8,
4153 &m_n->gmch_m, &m_n->gmch_n,
4156 compute_m_n(pixel_clock, link_clock,
4157 &m_n->link_m, &m_n->link_n,
4161 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
4164 * There may be no VBT; and if the BIOS enabled SSC we can
4165 * just keep using it to avoid unnecessary flicker. Whereas if the
4166 * BIOS isn't using it, don't assume it will work even if the VBT
4167 * indicates as much.
4169 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
4170 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
4174 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
4175 drm_dbg_kms(&dev_priv->drm,
4176 "SSC %s by BIOS, overriding VBT which says %s\n",
4177 enableddisabled(bios_lvds_use_ssc),
4178 enableddisabled(dev_priv->vbt.lvds_use_ssc));
4179 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
4184 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
4185 const struct intel_link_m_n *m_n)
4187 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4188 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4189 enum pipe pipe = crtc->pipe;
4191 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
4192 TU_SIZE(m_n->tu) | m_n->gmch_m);
4193 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
4194 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
4195 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
4198 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
4199 enum transcoder transcoder)
4201 if (IS_HASWELL(dev_priv))
4202 return transcoder == TRANSCODER_EDP;
4205 * Strictly speaking some registers are available before
4206 * gen7, but we only support DRRS on gen7+
4208 return DISPLAY_VER(dev_priv) == 7 || IS_CHERRYVIEW(dev_priv);
4211 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
4212 const struct intel_link_m_n *m_n,
4213 const struct intel_link_m_n *m2_n2)
4215 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4216 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4217 enum pipe pipe = crtc->pipe;
4218 enum transcoder transcoder = crtc_state->cpu_transcoder;
4220 if (DISPLAY_VER(dev_priv) >= 5) {
4221 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
4222 TU_SIZE(m_n->tu) | m_n->gmch_m);
4223 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
4225 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
4227 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
4230 * M2_N2 registers are set only if DRRS is supported
4231 * (to make sure the registers are not unnecessarily accessed).
4233 if (m2_n2 && crtc_state->has_drrs &&
4234 transcoder_has_m2_n2(dev_priv, transcoder)) {
4235 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
4236 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
4237 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
4239 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
4241 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
4245 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
4246 TU_SIZE(m_n->tu) | m_n->gmch_m);
4247 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
4248 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
4249 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
4253 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
4255 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
4256 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4259 dp_m_n = &crtc_state->dp_m_n;
4260 dp_m2_n2 = &crtc_state->dp_m2_n2;
4261 } else if (m_n == M2_N2) {
4264 * M2_N2 registers are not supported. Hence m2_n2 divider value
4265 * needs to be programmed into M1_N1.
4267 dp_m_n = &crtc_state->dp_m2_n2;
4269 drm_err(&i915->drm, "Unsupported divider value\n");
4273 if (crtc_state->has_pch_encoder)
4274 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
4276 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
4279 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
4281 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4282 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4283 enum pipe pipe = crtc->pipe;
4284 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4285 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
4286 u32 crtc_vtotal, crtc_vblank_end;
4289 /* We need to be careful not to changed the adjusted mode, for otherwise
4290 * the hw state checker will get angry at the mismatch. */
4291 crtc_vtotal = adjusted_mode->crtc_vtotal;
4292 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
4294 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4295 /* the chip adds 2 halflines automatically */
4297 crtc_vblank_end -= 1;
4299 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
4300 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
4302 vsyncshift = adjusted_mode->crtc_hsync_start -
4303 adjusted_mode->crtc_htotal / 2;
4305 vsyncshift += adjusted_mode->crtc_htotal;
4308 if (DISPLAY_VER(dev_priv) > 3)
4309 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
4312 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
4313 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
4314 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
4315 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
4316 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
4317 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
4319 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
4320 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
4321 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
4322 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
4323 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
4324 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
4326 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4327 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4328 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4330 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
4331 (pipe == PIPE_B || pipe == PIPE_C))
4332 intel_de_write(dev_priv, VTOTAL(pipe),
4333 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
4337 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
4339 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4340 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4341 enum pipe pipe = crtc->pipe;
4343 /* pipesrc controls the size that is scaled from, which should
4344 * always be the user's requested size.
4346 intel_de_write(dev_priv, PIPESRC(pipe),
4347 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
4350 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
4352 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4353 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4355 if (DISPLAY_VER(dev_priv) == 2)
4358 if (DISPLAY_VER(dev_priv) >= 9 ||
4359 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
4360 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
4362 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
4365 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
4366 struct intel_crtc_state *pipe_config)
4368 struct drm_device *dev = crtc->base.dev;
4369 struct drm_i915_private *dev_priv = to_i915(dev);
4370 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
4373 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
4374 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
4375 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
4377 if (!transcoder_is_dsi(cpu_transcoder)) {
4378 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
4379 pipe_config->hw.adjusted_mode.crtc_hblank_start =
4381 pipe_config->hw.adjusted_mode.crtc_hblank_end =
4382 ((tmp >> 16) & 0xffff) + 1;
4384 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
4385 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
4386 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
4388 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
4389 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
4390 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
4392 if (!transcoder_is_dsi(cpu_transcoder)) {
4393 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
4394 pipe_config->hw.adjusted_mode.crtc_vblank_start =
4396 pipe_config->hw.adjusted_mode.crtc_vblank_end =
4397 ((tmp >> 16) & 0xffff) + 1;
4399 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
4400 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
4401 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
4403 if (intel_pipe_is_interlaced(pipe_config)) {
4404 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
4405 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
4406 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
4410 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
4411 struct intel_crtc_state *pipe_config)
4413 struct drm_device *dev = crtc->base.dev;
4414 struct drm_i915_private *dev_priv = to_i915(dev);
4417 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
4418 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
4419 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
4422 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
4424 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4425 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4430 /* we keep both pipes enabled on 830 */
4431 if (IS_I830(dev_priv))
4432 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
4434 if (crtc_state->double_wide)
4435 pipeconf |= PIPECONF_DOUBLE_WIDE;
4437 /* only g4x and later have fancy bpc/dither controls */
4438 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4439 IS_CHERRYVIEW(dev_priv)) {
4440 /* Bspec claims that we can't use dithering for 30bpp pipes. */
4441 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
4442 pipeconf |= PIPECONF_DITHER_EN |
4443 PIPECONF_DITHER_TYPE_SP;
4445 switch (crtc_state->pipe_bpp) {
4447 pipeconf |= PIPECONF_6BPC;
4450 pipeconf |= PIPECONF_8BPC;
4453 pipeconf |= PIPECONF_10BPC;
4456 /* Case prevented by intel_choose_pipe_bpp_dither. */
4461 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
4462 if (DISPLAY_VER(dev_priv) < 4 ||
4463 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
4464 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4466 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
4468 pipeconf |= PIPECONF_PROGRESSIVE;
4471 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
4472 crtc_state->limited_color_range)
4473 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
4475 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
4477 pipeconf |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
4479 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
4480 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
4483 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
4485 if (IS_I830(dev_priv))
4488 return DISPLAY_VER(dev_priv) >= 4 ||
4489 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
4492 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
4494 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4495 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4498 if (!i9xx_has_pfit(dev_priv))
4501 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
4502 if (!(tmp & PFIT_ENABLE))
4505 /* Check whether the pfit is attached to our pipe. */
4506 if (DISPLAY_VER(dev_priv) < 4) {
4507 if (crtc->pipe != PIPE_B)
4510 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
4514 crtc_state->gmch_pfit.control = tmp;
4515 crtc_state->gmch_pfit.pgm_ratios =
4516 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
4519 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
4520 struct intel_crtc_state *pipe_config)
4522 struct drm_device *dev = crtc->base.dev;
4523 struct drm_i915_private *dev_priv = to_i915(dev);
4524 enum pipe pipe = crtc->pipe;
4527 int refclk = 100000;
4529 /* In case of DSI, DPLL will not be used */
4530 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
4533 vlv_dpio_get(dev_priv);
4534 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
4535 vlv_dpio_put(dev_priv);
4537 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
4538 clock.m2 = mdiv & DPIO_M2DIV_MASK;
4539 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
4540 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
4541 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
4543 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
4546 static void chv_crtc_clock_get(struct intel_crtc *crtc,
4547 struct intel_crtc_state *pipe_config)
4549 struct drm_device *dev = crtc->base.dev;
4550 struct drm_i915_private *dev_priv = to_i915(dev);
4551 enum pipe pipe = crtc->pipe;
4552 enum dpio_channel port = vlv_pipe_to_channel(pipe);
4554 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
4555 int refclk = 100000;
4557 /* In case of DSI, DPLL will not be used */
4558 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
4561 vlv_dpio_get(dev_priv);
4562 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
4563 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
4564 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
4565 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
4566 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
4567 vlv_dpio_put(dev_priv);
4569 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
4570 clock.m2 = (pll_dw0 & 0xff) << 22;
4571 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
4572 clock.m2 |= pll_dw2 & 0x3fffff;
4573 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
4574 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
4575 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
4577 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
4580 static enum intel_output_format
4581 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
4583 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4586 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
4588 if (tmp & PIPEMISC_YUV420_ENABLE) {
4589 /* We support 4:2:0 in full blend mode only */
4590 drm_WARN_ON(&dev_priv->drm,
4591 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
4593 return INTEL_OUTPUT_FORMAT_YCBCR420;
4594 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
4595 return INTEL_OUTPUT_FORMAT_YCBCR444;
4597 return INTEL_OUTPUT_FORMAT_RGB;
4601 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
4603 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4604 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
4605 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4606 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
4609 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
4611 if (tmp & DISPPLANE_GAMMA_ENABLE)
4612 crtc_state->gamma_enable = true;
4614 if (!HAS_GMCH(dev_priv) &&
4615 tmp & DISPPLANE_PIPE_CSC_ENABLE)
4616 crtc_state->csc_enable = true;
4619 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
4620 struct intel_crtc_state *pipe_config)
4622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4623 enum intel_display_power_domain power_domain;
4624 intel_wakeref_t wakeref;
4628 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
4629 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4633 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
4634 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
4635 pipe_config->shared_dpll = NULL;
4639 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
4640 if (!(tmp & PIPECONF_ENABLE))
4643 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4644 IS_CHERRYVIEW(dev_priv)) {
4645 switch (tmp & PIPECONF_BPC_MASK) {
4647 pipe_config->pipe_bpp = 18;
4650 pipe_config->pipe_bpp = 24;
4652 case PIPECONF_10BPC:
4653 pipe_config->pipe_bpp = 30;
4660 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
4661 (tmp & PIPECONF_COLOR_RANGE_SELECT))
4662 pipe_config->limited_color_range = true;
4664 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
4665 PIPECONF_GAMMA_MODE_SHIFT;
4667 if (IS_CHERRYVIEW(dev_priv))
4668 pipe_config->cgm_mode = intel_de_read(dev_priv,
4669 CGM_PIPE_MODE(crtc->pipe));
4671 i9xx_get_pipe_color_config(pipe_config);
4672 intel_color_get_config(pipe_config);
4674 if (DISPLAY_VER(dev_priv) < 4)
4675 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
4677 intel_get_transcoder_timings(crtc, pipe_config);
4678 intel_get_pipe_src_size(crtc, pipe_config);
4680 i9xx_get_pfit_config(pipe_config);
4682 if (DISPLAY_VER(dev_priv) >= 4) {
4683 /* No way to read it out on pipes B and C */
4684 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
4685 tmp = dev_priv->chv_dpll_md[crtc->pipe];
4687 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
4688 pipe_config->pixel_multiplier =
4689 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
4690 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
4691 pipe_config->dpll_hw_state.dpll_md = tmp;
4692 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
4693 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
4694 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
4695 pipe_config->pixel_multiplier =
4696 ((tmp & SDVO_MULTIPLIER_MASK)
4697 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
4699 /* Note that on i915G/GM the pixel multiplier is in the sdvo
4700 * port and will be fixed up in the encoder->get_config
4702 pipe_config->pixel_multiplier = 1;
4704 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
4706 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
4707 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
4709 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
4712 /* Mask out read-only status bits. */
4713 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
4714 DPLL_PORTC_READY_MASK |
4715 DPLL_PORTB_READY_MASK);
4718 if (IS_CHERRYVIEW(dev_priv))
4719 chv_crtc_clock_get(crtc, pipe_config);
4720 else if (IS_VALLEYVIEW(dev_priv))
4721 vlv_crtc_clock_get(crtc, pipe_config);
4723 i9xx_crtc_clock_get(crtc, pipe_config);
4726 * Normally the dotclock is filled in by the encoder .get_config()
4727 * but in case the pipe is enabled w/o any ports we need a sane
4730 pipe_config->hw.adjusted_mode.crtc_clock =
4731 pipe_config->port_clock / pipe_config->pixel_multiplier;
4736 intel_display_power_put(dev_priv, power_domain, wakeref);
4741 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
4743 struct intel_encoder *encoder;
4746 bool has_lvds = false;
4747 bool has_cpu_edp = false;
4748 bool has_panel = false;
4749 bool has_ck505 = false;
4750 bool can_ssc = false;
4751 bool using_ssc_source = false;
4753 /* We need to take the global config into account */
4754 for_each_intel_encoder(&dev_priv->drm, encoder) {
4755 switch (encoder->type) {
4756 case INTEL_OUTPUT_LVDS:
4760 case INTEL_OUTPUT_EDP:
4762 if (encoder->port == PORT_A)
4770 if (HAS_PCH_IBX(dev_priv)) {
4771 has_ck505 = dev_priv->vbt.display_clock_mode;
4772 can_ssc = has_ck505;
4778 /* Check if any DPLLs are using the SSC source */
4779 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
4780 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
4782 if (!(temp & DPLL_VCO_ENABLE))
4785 if ((temp & PLL_REF_INPUT_MASK) ==
4786 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
4787 using_ssc_source = true;
4792 drm_dbg_kms(&dev_priv->drm,
4793 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
4794 has_panel, has_lvds, has_ck505, using_ssc_source);
4796 /* Ironlake: try to setup display ref clock before DPLL
4797 * enabling. This is only under driver's control after
4798 * PCH B stepping, previous chipset stepping should be
4799 * ignoring this setting.
4801 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
4803 /* As we must carefully and slowly disable/enable each source in turn,
4804 * compute the final state we want first and check if we need to
4805 * make any changes at all.
4808 final &= ~DREF_NONSPREAD_SOURCE_MASK;
4810 final |= DREF_NONSPREAD_CK505_ENABLE;
4812 final |= DREF_NONSPREAD_SOURCE_ENABLE;
4814 final &= ~DREF_SSC_SOURCE_MASK;
4815 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4816 final &= ~DREF_SSC1_ENABLE;
4819 final |= DREF_SSC_SOURCE_ENABLE;
4821 if (intel_panel_use_ssc(dev_priv) && can_ssc)
4822 final |= DREF_SSC1_ENABLE;
4825 if (intel_panel_use_ssc(dev_priv) && can_ssc)
4826 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4828 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4830 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4831 } else if (using_ssc_source) {
4832 final |= DREF_SSC_SOURCE_ENABLE;
4833 final |= DREF_SSC1_ENABLE;
4839 /* Always enable nonspread source */
4840 val &= ~DREF_NONSPREAD_SOURCE_MASK;
4843 val |= DREF_NONSPREAD_CK505_ENABLE;
4845 val |= DREF_NONSPREAD_SOURCE_ENABLE;
4848 val &= ~DREF_SSC_SOURCE_MASK;
4849 val |= DREF_SSC_SOURCE_ENABLE;
4851 /* SSC must be turned on before enabling the CPU output */
4852 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4853 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
4854 val |= DREF_SSC1_ENABLE;
4856 val &= ~DREF_SSC1_ENABLE;
4858 /* Get SSC going before enabling the outputs */
4859 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
4860 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
4863 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4865 /* Enable CPU source on CPU attached eDP */
4867 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
4868 drm_dbg_kms(&dev_priv->drm,
4869 "Using SSC on eDP\n");
4870 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
4872 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
4874 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4876 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
4877 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
4880 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
4882 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
4884 /* Turn off CPU output */
4885 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
4887 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
4888 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
4891 if (!using_ssc_source) {
4892 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
4894 /* Turn off the SSC source */
4895 val &= ~DREF_SSC_SOURCE_MASK;
4896 val |= DREF_SSC_SOURCE_DISABLE;
4899 val &= ~DREF_SSC1_ENABLE;
4901 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
4902 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
4907 BUG_ON(val != final);
4910 /* Implements 3 different sequences from BSpec chapter "Display iCLK
4911 * Programming" based on the parameters passed:
4912 * - Sequence to enable CLKOUT_DP
4913 * - Sequence to enable CLKOUT_DP without spread
4914 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
4916 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
4917 bool with_spread, bool with_fdi)
4921 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
4922 "FDI requires downspread\n"))
4924 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
4925 with_fdi, "LP PCH doesn't have FDI\n"))
4928 mutex_lock(&dev_priv->sb_lock);
4930 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4931 tmp &= ~SBI_SSCCTL_DISABLE;
4932 tmp |= SBI_SSCCTL_PATHALT;
4933 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4938 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4939 tmp &= ~SBI_SSCCTL_PATHALT;
4940 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4943 lpt_fdi_program_mphy(dev_priv);
4946 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
4947 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
4948 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
4949 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
4951 mutex_unlock(&dev_priv->sb_lock);
4954 /* Sequence to disable CLKOUT_DP */
4955 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
4959 mutex_lock(&dev_priv->sb_lock);
4961 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
4962 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
4963 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
4964 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
4966 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
4967 if (!(tmp & SBI_SSCCTL_DISABLE)) {
4968 if (!(tmp & SBI_SSCCTL_PATHALT)) {
4969 tmp |= SBI_SSCCTL_PATHALT;
4970 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4973 tmp |= SBI_SSCCTL_DISABLE;
4974 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
4977 mutex_unlock(&dev_priv->sb_lock);
4980 #define BEND_IDX(steps) ((50 + (steps)) / 5)
4982 static const u16 sscdivintphase[] = {
4983 [BEND_IDX( 50)] = 0x3B23,
4984 [BEND_IDX( 45)] = 0x3B23,
4985 [BEND_IDX( 40)] = 0x3C23,
4986 [BEND_IDX( 35)] = 0x3C23,
4987 [BEND_IDX( 30)] = 0x3D23,
4988 [BEND_IDX( 25)] = 0x3D23,
4989 [BEND_IDX( 20)] = 0x3E23,
4990 [BEND_IDX( 15)] = 0x3E23,
4991 [BEND_IDX( 10)] = 0x3F23,
4992 [BEND_IDX( 5)] = 0x3F23,
4993 [BEND_IDX( 0)] = 0x0025,
4994 [BEND_IDX( -5)] = 0x0025,
4995 [BEND_IDX(-10)] = 0x0125,
4996 [BEND_IDX(-15)] = 0x0125,
4997 [BEND_IDX(-20)] = 0x0225,
4998 [BEND_IDX(-25)] = 0x0225,
4999 [BEND_IDX(-30)] = 0x0325,
5000 [BEND_IDX(-35)] = 0x0325,
5001 [BEND_IDX(-40)] = 0x0425,
5002 [BEND_IDX(-45)] = 0x0425,
5003 [BEND_IDX(-50)] = 0x0525,
5008 * steps -50 to 50 inclusive, in steps of 5
5009 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
5010 * change in clock period = -(steps / 10) * 5.787 ps
5012 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
5015 int idx = BEND_IDX(steps);
5017 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
5020 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
5023 mutex_lock(&dev_priv->sb_lock);
5025 if (steps % 10 != 0)
5029 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
5031 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
5033 tmp |= sscdivintphase[idx];
5034 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
5036 mutex_unlock(&dev_priv->sb_lock);
5041 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
5043 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
5044 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
5046 if ((ctl & SPLL_PLL_ENABLE) == 0)
5049 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
5050 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
5053 if (IS_BROADWELL(dev_priv) &&
5054 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
5060 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
5061 enum intel_dpll_id id)
5063 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
5064 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
5066 if ((ctl & WRPLL_PLL_ENABLE) == 0)
5069 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
5072 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
5073 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
5074 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
5080 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
5082 struct intel_encoder *encoder;
5083 bool has_fdi = false;
5085 for_each_intel_encoder(&dev_priv->drm, encoder) {
5086 switch (encoder->type) {
5087 case INTEL_OUTPUT_ANALOG:
5096 * The BIOS may have decided to use the PCH SSC
5097 * reference so we must not disable it until the
5098 * relevant PLLs have stopped relying on it. We'll
5099 * just leave the PCH SSC reference enabled in case
5100 * any active PLL is using it. It will get disabled
5101 * after runtime suspend if we don't have FDI.
5103 * TODO: Move the whole reference clock handling
5104 * to the modeset sequence proper so that we can
5105 * actually enable/disable/reconfigure these things
5106 * safely. To do that we need to introduce a real
5107 * clock hierarchy. That would also allow us to do
5108 * clock bending finally.
5110 dev_priv->pch_ssc_use = 0;
5112 if (spll_uses_pch_ssc(dev_priv)) {
5113 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
5114 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
5117 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
5118 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
5119 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
5122 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
5123 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
5124 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
5127 if (dev_priv->pch_ssc_use)
5131 lpt_bend_clkout_dp(dev_priv, 0);
5132 lpt_enable_clkout_dp(dev_priv, true, true);
5134 lpt_disable_clkout_dp(dev_priv);
5139 * Initialize reference clocks when the driver loads
5141 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
5143 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
5144 ilk_init_pch_refclk(dev_priv);
5145 else if (HAS_PCH_LPT(dev_priv))
5146 lpt_init_pch_refclk(dev_priv);
5149 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
5151 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5152 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5153 enum pipe pipe = crtc->pipe;
5158 switch (crtc_state->pipe_bpp) {
5160 val |= PIPECONF_6BPC;
5163 val |= PIPECONF_8BPC;
5166 val |= PIPECONF_10BPC;
5169 val |= PIPECONF_12BPC;
5172 /* Case prevented by intel_choose_pipe_bpp_dither. */
5176 if (crtc_state->dither)
5177 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5179 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
5180 val |= PIPECONF_INTERLACED_ILK;
5182 val |= PIPECONF_PROGRESSIVE;
5185 * This would end up with an odd purple hue over
5186 * the entire display. Make sure we don't do it.
5188 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
5189 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
5191 if (crtc_state->limited_color_range &&
5192 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
5193 val |= PIPECONF_COLOR_RANGE_SELECT;
5195 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
5196 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
5198 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
5200 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
5202 intel_de_write(dev_priv, PIPECONF(pipe), val);
5203 intel_de_posting_read(dev_priv, PIPECONF(pipe));
5206 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
5208 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5209 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5210 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5213 if (IS_HASWELL(dev_priv) && crtc_state->dither)
5214 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5216 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
5217 val |= PIPECONF_INTERLACED_ILK;
5219 val |= PIPECONF_PROGRESSIVE;
5221 if (IS_HASWELL(dev_priv) &&
5222 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
5223 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
5225 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
5226 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
5229 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
5231 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5232 const struct intel_crtc_scaler_state *scaler_state =
5233 &crtc_state->scaler_state;
5235 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5239 switch (crtc_state->pipe_bpp) {
5241 val |= PIPEMISC_6_BPC;
5244 val |= PIPEMISC_8_BPC;
5247 val |= PIPEMISC_10_BPC;
5250 /* Port output 12BPC defined for ADLP+ */
5251 if (DISPLAY_VER(dev_priv) > 12)
5252 val |= PIPEMISC_12_BPC_ADLP;
5255 MISSING_CASE(crtc_state->pipe_bpp);
5259 if (crtc_state->dither)
5260 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
5262 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
5263 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
5264 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
5266 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5267 val |= PIPEMISC_YUV420_ENABLE |
5268 PIPEMISC_YUV420_MODE_FULL_BLEND;
5270 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
5271 val |= PIPEMISC_HDR_MODE_PRECISION;
5273 if (DISPLAY_VER(dev_priv) >= 12)
5274 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
5276 if (IS_ALDERLAKE_P(dev_priv)) {
5277 bool scaler_in_use = false;
5279 for (i = 0; i < crtc->num_scalers; i++) {
5280 if (!scaler_state->scalers[i].in_use)
5283 scaler_in_use = true;
5287 intel_de_rmw(dev_priv, PIPE_MISC2(crtc->pipe),
5288 PIPE_MISC2_UNDERRUN_BUBBLE_COUNTER_MASK,
5289 scaler_in_use ? PIPE_MISC2_BUBBLE_COUNTER_SCALER_EN :
5290 PIPE_MISC2_BUBBLE_COUNTER_SCALER_DIS);
5293 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
5296 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
5298 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5301 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
5303 switch (tmp & PIPEMISC_BPC_MASK) {
5304 case PIPEMISC_6_BPC:
5306 case PIPEMISC_8_BPC:
5308 case PIPEMISC_10_BPC:
5311 * PORT OUTPUT 12 BPC defined for ADLP+.
5314 * For previous platforms with DSI interface, bits 5:7
5315 * are used for storing pipe_bpp irrespective of dithering.
5316 * Since the value of 12 BPC is not defined for these bits
5317 * on older platforms, need to find a workaround for 12 BPC
5318 * MIPI DSI HW readout.
5320 case PIPEMISC_12_BPC_ADLP:
5321 if (DISPLAY_VER(dev_priv) > 12)
5330 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
5333 * Account for spread spectrum to avoid
5334 * oversubscribing the link. Max center spread
5335 * is 2.5%; use 5% for safety's sake.
5337 u32 bps = target_clock * bpp * 21 / 20;
5338 return DIV_ROUND_UP(bps, link_bw * 8);
5341 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
5342 struct intel_link_m_n *m_n)
5344 struct drm_device *dev = crtc->base.dev;
5345 struct drm_i915_private *dev_priv = to_i915(dev);
5346 enum pipe pipe = crtc->pipe;
5348 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
5349 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
5350 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
5352 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
5353 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
5354 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5357 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
5358 enum transcoder transcoder,
5359 struct intel_link_m_n *m_n,
5360 struct intel_link_m_n *m2_n2)
5362 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5363 enum pipe pipe = crtc->pipe;
5365 if (DISPLAY_VER(dev_priv) >= 5) {
5366 m_n->link_m = intel_de_read(dev_priv,
5367 PIPE_LINK_M1(transcoder));
5368 m_n->link_n = intel_de_read(dev_priv,
5369 PIPE_LINK_N1(transcoder));
5370 m_n->gmch_m = intel_de_read(dev_priv,
5371 PIPE_DATA_M1(transcoder))
5373 m_n->gmch_n = intel_de_read(dev_priv,
5374 PIPE_DATA_N1(transcoder));
5375 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
5376 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5378 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
5379 m2_n2->link_m = intel_de_read(dev_priv,
5380 PIPE_LINK_M2(transcoder));
5381 m2_n2->link_n = intel_de_read(dev_priv,
5382 PIPE_LINK_N2(transcoder));
5383 m2_n2->gmch_m = intel_de_read(dev_priv,
5384 PIPE_DATA_M2(transcoder))
5386 m2_n2->gmch_n = intel_de_read(dev_priv,
5387 PIPE_DATA_N2(transcoder));
5388 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
5389 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5392 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
5393 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
5394 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
5396 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
5397 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
5398 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5402 void intel_dp_get_m_n(struct intel_crtc *crtc,
5403 struct intel_crtc_state *pipe_config)
5405 if (pipe_config->has_pch_encoder)
5406 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
5408 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
5409 &pipe_config->dp_m_n,
5410 &pipe_config->dp_m2_n2);
5413 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
5414 struct intel_crtc_state *pipe_config)
5416 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
5417 &pipe_config->fdi_m_n, NULL);
5420 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
5423 drm_rect_init(&crtc_state->pch_pfit.dst,
5424 pos >> 16, pos & 0xffff,
5425 size >> 16, size & 0xffff);
5428 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
5430 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5431 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5432 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
5436 /* find scaler attached to this pipe */
5437 for (i = 0; i < crtc->num_scalers; i++) {
5440 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
5441 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
5445 crtc_state->pch_pfit.enabled = true;
5447 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
5448 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
5450 ilk_get_pfit_pos_size(crtc_state, pos, size);
5452 scaler_state->scalers[i].in_use = true;
5456 scaler_state->scaler_id = id;
5458 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
5460 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
5463 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
5465 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5466 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5469 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
5470 if ((ctl & PF_ENABLE) == 0)
5473 crtc_state->pch_pfit.enabled = true;
5475 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
5476 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
5478 ilk_get_pfit_pos_size(crtc_state, pos, size);
5481 * We currently do not free assignements of panel fitters on
5482 * ivb/hsw (since we don't use the higher upscaling modes which
5483 * differentiates them) so just WARN about this case for now.
5485 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 7 &&
5486 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
5489 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
5490 struct intel_crtc_state *pipe_config)
5492 struct drm_device *dev = crtc->base.dev;
5493 struct drm_i915_private *dev_priv = to_i915(dev);
5494 enum intel_display_power_domain power_domain;
5495 intel_wakeref_t wakeref;
5499 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
5500 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
5504 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
5505 pipe_config->shared_dpll = NULL;
5508 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
5509 if (!(tmp & PIPECONF_ENABLE))
5512 switch (tmp & PIPECONF_BPC_MASK) {
5514 pipe_config->pipe_bpp = 18;
5517 pipe_config->pipe_bpp = 24;
5519 case PIPECONF_10BPC:
5520 pipe_config->pipe_bpp = 30;
5522 case PIPECONF_12BPC:
5523 pipe_config->pipe_bpp = 36;
5529 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
5530 pipe_config->limited_color_range = true;
5532 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
5533 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
5534 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
5535 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
5538 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
5542 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
5543 PIPECONF_GAMMA_MODE_SHIFT;
5545 pipe_config->csc_mode = intel_de_read(dev_priv,
5546 PIPE_CSC_MODE(crtc->pipe));
5548 i9xx_get_pipe_color_config(pipe_config);
5549 intel_color_get_config(pipe_config);
5551 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
5552 struct intel_shared_dpll *pll;
5553 enum intel_dpll_id pll_id;
5556 pipe_config->has_pch_encoder = true;
5558 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
5559 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
5560 FDI_DP_PORT_WIDTH_SHIFT) + 1;
5562 ilk_get_fdi_m_n_config(crtc, pipe_config);
5564 if (HAS_PCH_IBX(dev_priv)) {
5566 * The pipe->pch transcoder and pch transcoder->pll
5569 pll_id = (enum intel_dpll_id) crtc->pipe;
5571 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
5572 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
5573 pll_id = DPLL_ID_PCH_PLL_B;
5575 pll_id= DPLL_ID_PCH_PLL_A;
5578 pipe_config->shared_dpll =
5579 intel_get_shared_dpll_by_id(dev_priv, pll_id);
5580 pll = pipe_config->shared_dpll;
5582 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
5583 &pipe_config->dpll_hw_state);
5584 drm_WARN_ON(dev, !pll_active);
5586 tmp = pipe_config->dpll_hw_state.dpll;
5587 pipe_config->pixel_multiplier =
5588 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
5589 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
5591 ilk_pch_clock_get(crtc, pipe_config);
5593 pipe_config->pixel_multiplier = 1;
5596 intel_get_transcoder_timings(crtc, pipe_config);
5597 intel_get_pipe_src_size(crtc, pipe_config);
5599 ilk_get_pfit_config(pipe_config);
5604 intel_display_power_put(dev_priv, power_domain, wakeref);
5609 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
5611 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
5613 if (DISPLAY_VER(i915) >= 11)
5614 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
5616 return panel_transcoder_mask;
5619 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
5620 struct intel_crtc_state *pipe_config,
5621 struct intel_display_power_domain_set *power_domain_set)
5623 struct drm_device *dev = crtc->base.dev;
5624 struct drm_i915_private *dev_priv = to_i915(dev);
5625 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
5626 unsigned long enabled_panel_transcoders = 0;
5627 enum transcoder panel_transcoder;
5631 * The pipe->transcoder mapping is fixed with the exception of the eDP
5632 * and DSI transcoders handled below.
5634 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
5637 * XXX: Do intel_display_power_get_if_enabled before reading this (for
5638 * consistency and less surprising code; it's in always on power).
5640 for_each_cpu_transcoder_masked(dev_priv, panel_transcoder,
5641 panel_transcoder_mask) {
5642 bool force_thru = false;
5643 enum pipe trans_pipe;
5645 tmp = intel_de_read(dev_priv,
5646 TRANS_DDI_FUNC_CTL(panel_transcoder));
5647 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
5651 * Log all enabled ones, only use the first one.
5653 * FIXME: This won't work for two separate DSI displays.
5655 enabled_panel_transcoders |= BIT(panel_transcoder);
5656 if (enabled_panel_transcoders != BIT(panel_transcoder))
5659 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
5662 "unknown pipe linked to transcoder %s\n",
5663 transcoder_name(panel_transcoder));
5665 case TRANS_DDI_EDP_INPUT_A_ONOFF:
5668 case TRANS_DDI_EDP_INPUT_A_ON:
5669 trans_pipe = PIPE_A;
5671 case TRANS_DDI_EDP_INPUT_B_ONOFF:
5672 trans_pipe = PIPE_B;
5674 case TRANS_DDI_EDP_INPUT_C_ONOFF:
5675 trans_pipe = PIPE_C;
5677 case TRANS_DDI_EDP_INPUT_D_ONOFF:
5678 trans_pipe = PIPE_D;
5682 if (trans_pipe == crtc->pipe) {
5683 pipe_config->cpu_transcoder = panel_transcoder;
5684 pipe_config->pch_pfit.force_thru = force_thru;
5689 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
5691 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
5692 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
5694 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
5695 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
5698 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
5700 return tmp & PIPECONF_ENABLE;
5703 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
5704 struct intel_crtc_state *pipe_config,
5705 struct intel_display_power_domain_set *power_domain_set)
5707 struct drm_device *dev = crtc->base.dev;
5708 struct drm_i915_private *dev_priv = to_i915(dev);
5709 enum transcoder cpu_transcoder;
5713 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
5715 cpu_transcoder = TRANSCODER_DSI_A;
5717 cpu_transcoder = TRANSCODER_DSI_C;
5719 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
5720 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
5724 * The PLL needs to be enabled with a valid divider
5725 * configuration, otherwise accessing DSI registers will hang
5726 * the machine. See BSpec North Display Engine
5727 * registers/MIPI[BXT]. We can break out here early, since we
5728 * need the same DSI PLL to be enabled for both DSI ports.
5730 if (!bxt_dsi_pll_is_enabled(dev_priv))
5733 /* XXX: this works for video mode only */
5734 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
5735 if (!(tmp & DPI_ENABLE))
5738 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
5739 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
5742 pipe_config->cpu_transcoder = cpu_transcoder;
5746 return transcoder_is_dsi(pipe_config->cpu_transcoder);
5749 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
5750 struct intel_crtc_state *pipe_config)
5752 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5753 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
5757 if (transcoder_is_dsi(cpu_transcoder)) {
5758 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
5761 tmp = intel_de_read(dev_priv,
5762 TRANS_DDI_FUNC_CTL(cpu_transcoder));
5763 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
5765 if (DISPLAY_VER(dev_priv) >= 12)
5766 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
5768 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
5772 * Haswell has only FDI/PCH transcoder A. It is which is connected to
5773 * DDI E. So just check whether this pipe is wired to DDI E and whether
5774 * the PCH transcoder is on.
5776 if (DISPLAY_VER(dev_priv) < 9 &&
5777 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
5778 pipe_config->has_pch_encoder = true;
5780 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
5781 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
5782 FDI_DP_PORT_WIDTH_SHIFT) + 1;
5784 ilk_get_fdi_m_n_config(crtc, pipe_config);
5788 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
5789 struct intel_crtc_state *pipe_config)
5791 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5792 struct intel_display_power_domain_set power_domain_set = { };
5796 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
5797 POWER_DOMAIN_PIPE(crtc->pipe)))
5800 pipe_config->shared_dpll = NULL;
5802 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
5804 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
5805 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
5806 drm_WARN_ON(&dev_priv->drm, active);
5810 intel_dsc_get_config(pipe_config);
5811 if (DISPLAY_VER(dev_priv) >= 13 && !pipe_config->dsc.compression_enable)
5812 intel_uncompressed_joiner_get_config(pipe_config);
5815 /* bigjoiner slave doesn't enable transcoder */
5816 if (!pipe_config->bigjoiner_slave)
5820 pipe_config->pixel_multiplier = 1;
5822 /* we cannot read out most state, so don't bother.. */
5823 pipe_config->quirks |= PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE;
5824 } else if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
5825 DISPLAY_VER(dev_priv) >= 11) {
5826 hsw_get_ddi_port_state(crtc, pipe_config);
5827 intel_get_transcoder_timings(crtc, pipe_config);
5830 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
5831 intel_vrr_get_config(crtc, pipe_config);
5833 intel_get_pipe_src_size(crtc, pipe_config);
5835 if (IS_HASWELL(dev_priv)) {
5836 u32 tmp = intel_de_read(dev_priv,
5837 PIPECONF(pipe_config->cpu_transcoder));
5839 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
5840 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
5842 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
5844 pipe_config->output_format =
5845 bdw_get_pipemisc_output_format(crtc);
5848 pipe_config->gamma_mode = intel_de_read(dev_priv,
5849 GAMMA_MODE(crtc->pipe));
5851 pipe_config->csc_mode = intel_de_read(dev_priv,
5852 PIPE_CSC_MODE(crtc->pipe));
5854 if (DISPLAY_VER(dev_priv) >= 9) {
5855 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
5857 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
5858 pipe_config->gamma_enable = true;
5860 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
5861 pipe_config->csc_enable = true;
5863 i9xx_get_pipe_color_config(pipe_config);
5866 intel_color_get_config(pipe_config);
5868 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
5869 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
5870 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
5871 pipe_config->ips_linetime =
5872 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
5874 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
5875 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
5876 if (DISPLAY_VER(dev_priv) >= 9)
5877 skl_get_pfit_config(pipe_config);
5879 ilk_get_pfit_config(pipe_config);
5882 if (hsw_crtc_supports_ips(crtc)) {
5883 if (IS_HASWELL(dev_priv))
5884 pipe_config->ips_enabled = intel_de_read(dev_priv,
5885 IPS_CTL) & IPS_ENABLE;
5888 * We cannot readout IPS state on broadwell, set to
5889 * true so we can set it to a defined state on first
5892 pipe_config->ips_enabled = true;
5896 if (pipe_config->bigjoiner_slave) {
5897 /* Cannot be read out as a slave, set to 0. */
5898 pipe_config->pixel_multiplier = 0;
5899 } else if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
5900 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
5901 pipe_config->pixel_multiplier =
5902 intel_de_read(dev_priv,
5903 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
5905 pipe_config->pixel_multiplier = 1;
5909 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
5914 static bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
5916 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5917 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5919 if (!i915->display.get_pipe_config(crtc, crtc_state))
5922 crtc_state->hw.active = true;
5924 intel_crtc_readout_derived_state(crtc_state);
5929 /* VESA 640x480x72Hz mode to set on the pipe */
5930 static const struct drm_display_mode load_detect_mode = {
5931 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
5932 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
5935 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
5936 struct drm_crtc *crtc)
5938 struct drm_plane *plane;
5939 struct drm_plane_state *plane_state;
5942 ret = drm_atomic_add_affected_planes(state, crtc);
5946 for_each_new_plane_in_state(state, plane, plane_state, i) {
5947 if (plane_state->crtc != crtc)
5950 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
5954 drm_atomic_set_fb_for_plane(plane_state, NULL);
5960 int intel_get_load_detect_pipe(struct drm_connector *connector,
5961 struct intel_load_detect_pipe *old,
5962 struct drm_modeset_acquire_ctx *ctx)
5964 struct intel_encoder *encoder =
5965 intel_attached_encoder(to_intel_connector(connector));
5966 struct intel_crtc *possible_crtc;
5967 struct intel_crtc *crtc = NULL;
5968 struct drm_device *dev = encoder->base.dev;
5969 struct drm_i915_private *dev_priv = to_i915(dev);
5970 struct drm_mode_config *config = &dev->mode_config;
5971 struct drm_atomic_state *state = NULL, *restore_state = NULL;
5972 struct drm_connector_state *connector_state;
5973 struct intel_crtc_state *crtc_state;
5976 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
5977 connector->base.id, connector->name,
5978 encoder->base.base.id, encoder->base.name);
5980 old->restore_state = NULL;
5982 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
5985 * Algorithm gets a little messy:
5987 * - if the connector already has an assigned crtc, use it (but make
5988 * sure it's on first)
5990 * - try to find the first unused crtc that can drive this connector,
5991 * and use that if we find one
5994 /* See if we already have a CRTC for this connector */
5995 if (connector->state->crtc) {
5996 crtc = to_intel_crtc(connector->state->crtc);
5998 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
6002 /* Make sure the crtc and connector are running */
6006 /* Find an unused one (if possible) */
6007 for_each_intel_crtc(dev, possible_crtc) {
6008 if (!(encoder->base.possible_crtcs &
6009 drm_crtc_mask(&possible_crtc->base)))
6012 ret = drm_modeset_lock(&possible_crtc->base.mutex, ctx);
6016 if (possible_crtc->base.state->enable) {
6017 drm_modeset_unlock(&possible_crtc->base.mutex);
6021 crtc = possible_crtc;
6026 * If we didn't find an unused CRTC, don't use any.
6029 drm_dbg_kms(&dev_priv->drm,
6030 "no pipe available for load-detect\n");
6036 state = drm_atomic_state_alloc(dev);
6037 restore_state = drm_atomic_state_alloc(dev);
6038 if (!state || !restore_state) {
6043 state->acquire_ctx = ctx;
6044 restore_state->acquire_ctx = ctx;
6046 connector_state = drm_atomic_get_connector_state(state, connector);
6047 if (IS_ERR(connector_state)) {
6048 ret = PTR_ERR(connector_state);
6052 ret = drm_atomic_set_crtc_for_connector(connector_state, &crtc->base);
6056 crtc_state = intel_atomic_get_crtc_state(state, crtc);
6057 if (IS_ERR(crtc_state)) {
6058 ret = PTR_ERR(crtc_state);
6062 crtc_state->uapi.active = true;
6064 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
6069 ret = intel_modeset_disable_planes(state, &crtc->base);
6073 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
6075 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, &crtc->base));
6077 ret = drm_atomic_add_affected_planes(restore_state, &crtc->base);
6079 drm_dbg_kms(&dev_priv->drm,
6080 "Failed to create a copy of old state to restore: %i\n",
6085 ret = drm_atomic_commit(state);
6087 drm_dbg_kms(&dev_priv->drm,
6088 "failed to set mode on load-detect pipe\n");
6092 old->restore_state = restore_state;
6093 drm_atomic_state_put(state);
6095 /* let the connector get through one full cycle before testing */
6096 intel_wait_for_vblank(dev_priv, crtc->pipe);
6101 drm_atomic_state_put(state);
6104 if (restore_state) {
6105 drm_atomic_state_put(restore_state);
6106 restore_state = NULL;
6109 if (ret == -EDEADLK)
6115 void intel_release_load_detect_pipe(struct drm_connector *connector,
6116 struct intel_load_detect_pipe *old,
6117 struct drm_modeset_acquire_ctx *ctx)
6119 struct intel_encoder *intel_encoder =
6120 intel_attached_encoder(to_intel_connector(connector));
6121 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
6122 struct drm_encoder *encoder = &intel_encoder->base;
6123 struct drm_atomic_state *state = old->restore_state;
6126 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6127 connector->base.id, connector->name,
6128 encoder->base.id, encoder->name);
6133 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
6135 drm_dbg_kms(&i915->drm,
6136 "Couldn't release load detect pipe: %i\n", ret);
6137 drm_atomic_state_put(state);
6140 static int i9xx_pll_refclk(struct drm_device *dev,
6141 const struct intel_crtc_state *pipe_config)
6143 struct drm_i915_private *dev_priv = to_i915(dev);
6144 u32 dpll = pipe_config->dpll_hw_state.dpll;
6146 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
6147 return dev_priv->vbt.lvds_ssc_freq;
6148 else if (HAS_PCH_SPLIT(dev_priv))
6150 else if (DISPLAY_VER(dev_priv) != 2)
6156 /* Returns the clock of the currently programmed mode of the given pipe. */
6157 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
6158 struct intel_crtc_state *pipe_config)
6160 struct drm_device *dev = crtc->base.dev;
6161 struct drm_i915_private *dev_priv = to_i915(dev);
6162 u32 dpll = pipe_config->dpll_hw_state.dpll;
6166 int refclk = i9xx_pll_refclk(dev, pipe_config);
6168 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
6169 fp = pipe_config->dpll_hw_state.fp0;
6171 fp = pipe_config->dpll_hw_state.fp1;
6173 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
6174 if (IS_PINEVIEW(dev_priv)) {
6175 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
6176 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
6178 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
6179 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
6182 if (DISPLAY_VER(dev_priv) != 2) {
6183 if (IS_PINEVIEW(dev_priv))
6184 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
6185 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
6187 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
6188 DPLL_FPA01_P1_POST_DIV_SHIFT);
6190 switch (dpll & DPLL_MODE_MASK) {
6191 case DPLLB_MODE_DAC_SERIAL:
6192 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
6195 case DPLLB_MODE_LVDS:
6196 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
6200 drm_dbg_kms(&dev_priv->drm,
6201 "Unknown DPLL mode %08x in programmed "
6202 "mode\n", (int)(dpll & DPLL_MODE_MASK));
6206 if (IS_PINEVIEW(dev_priv))
6207 port_clock = pnv_calc_dpll_params(refclk, &clock);
6209 port_clock = i9xx_calc_dpll_params(refclk, &clock);
6211 enum pipe lvds_pipe;
6213 if (IS_I85X(dev_priv) &&
6214 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) &&
6215 lvds_pipe == crtc->pipe) {
6216 u32 lvds = intel_de_read(dev_priv, LVDS);
6218 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
6219 DPLL_FPA01_P1_POST_DIV_SHIFT);
6221 if (lvds & LVDS_CLKB_POWER_UP)
6226 if (dpll & PLL_P1_DIVIDE_BY_TWO)
6229 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
6230 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
6232 if (dpll & PLL_P2_DIVIDE_BY_4)
6238 port_clock = i9xx_calc_dpll_params(refclk, &clock);
6242 * This value includes pixel_multiplier. We will use
6243 * port_clock to compute adjusted_mode.crtc_clock in the
6244 * encoder's get_config() function.
6246 pipe_config->port_clock = port_clock;
6249 int intel_dotclock_calculate(int link_freq,
6250 const struct intel_link_m_n *m_n)
6253 * The calculation for the data clock is:
6254 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
6255 * But we want to avoid losing precison if possible, so:
6256 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
6258 * and the link clock is simpler:
6259 * link_clock = (m * link_clock) / n
6265 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
6268 static void ilk_pch_clock_get(struct intel_crtc *crtc,
6269 struct intel_crtc_state *pipe_config)
6271 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6273 /* read out port_clock from the DPLL */
6274 i9xx_crtc_clock_get(crtc, pipe_config);
6277 * In case there is an active pipe without active ports,
6278 * we may need some idea for the dotclock anyway.
6279 * Calculate one based on the FDI configuration.
6281 pipe_config->hw.adjusted_mode.crtc_clock =
6282 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
6283 &pipe_config->fdi_m_n);
6286 /* Returns the currently programmed mode of the given encoder. */
6287 struct drm_display_mode *
6288 intel_encoder_current_mode(struct intel_encoder *encoder)
6290 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6291 struct intel_crtc_state *crtc_state;
6292 struct drm_display_mode *mode;
6293 struct intel_crtc *crtc;
6296 if (!encoder->get_hw_state(encoder, &pipe))
6299 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
6301 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
6305 crtc_state = intel_crtc_state_alloc(crtc);
6311 if (!intel_crtc_get_pipe_config(crtc_state)) {
6317 intel_encoder_get_config(encoder, crtc_state);
6319 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
6327 * intel_wm_need_update - Check whether watermarks need updating
6328 * @cur: current plane state
6329 * @new: new plane state
6331 * Check current plane state versus the new one to determine whether
6332 * watermarks need to be recalculated.
6334 * Returns true or false.
6336 static bool intel_wm_need_update(const struct intel_plane_state *cur,
6337 struct intel_plane_state *new)
6339 /* Update watermarks on tiling or size changes. */
6340 if (new->uapi.visible != cur->uapi.visible)
6343 if (!cur->hw.fb || !new->hw.fb)
6346 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
6347 cur->hw.rotation != new->hw.rotation ||
6348 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
6349 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
6350 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
6351 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
6357 static bool needs_scaling(const struct intel_plane_state *state)
6359 int src_w = drm_rect_width(&state->uapi.src) >> 16;
6360 int src_h = drm_rect_height(&state->uapi.src) >> 16;
6361 int dst_w = drm_rect_width(&state->uapi.dst);
6362 int dst_h = drm_rect_height(&state->uapi.dst);
6364 return (src_w != dst_w || src_h != dst_h);
6367 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
6368 struct intel_crtc_state *new_crtc_state,
6369 const struct intel_plane_state *old_plane_state,
6370 struct intel_plane_state *new_plane_state)
6372 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6373 struct intel_plane *plane = to_intel_plane(new_plane_state->uapi.plane);
6374 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6375 bool mode_changed = intel_crtc_needs_modeset(new_crtc_state);
6376 bool was_crtc_enabled = old_crtc_state->hw.active;
6377 bool is_crtc_enabled = new_crtc_state->hw.active;
6378 bool turn_off, turn_on, visible, was_visible;
6381 if (DISPLAY_VER(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
6382 ret = skl_update_scaler_plane(new_crtc_state, new_plane_state);
6387 was_visible = old_plane_state->uapi.visible;
6388 visible = new_plane_state->uapi.visible;
6390 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
6391 was_visible = false;
6394 * Visibility is calculated as if the crtc was on, but
6395 * after scaler setup everything depends on it being off
6396 * when the crtc isn't active.
6398 * FIXME this is wrong for watermarks. Watermarks should also
6399 * be computed as if the pipe would be active. Perhaps move
6400 * per-plane wm computation to the .check_plane() hook, and
6401 * only combine the results from all planes in the current place?
6403 if (!is_crtc_enabled) {
6404 intel_plane_set_invisible(new_crtc_state, new_plane_state);
6408 if (!was_visible && !visible)
6411 turn_off = was_visible && (!visible || mode_changed);
6412 turn_on = visible && (!was_visible || mode_changed);
6414 drm_dbg_atomic(&dev_priv->drm,
6415 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
6416 crtc->base.base.id, crtc->base.name,
6417 plane->base.base.id, plane->base.name,
6418 was_visible, visible,
6419 turn_off, turn_on, mode_changed);
6422 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv))
6423 new_crtc_state->update_wm_pre = true;
6425 /* must disable cxsr around plane enable/disable */
6426 if (plane->id != PLANE_CURSOR)
6427 new_crtc_state->disable_cxsr = true;
6428 } else if (turn_off) {
6429 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv))
6430 new_crtc_state->update_wm_post = true;
6432 /* must disable cxsr around plane enable/disable */
6433 if (plane->id != PLANE_CURSOR)
6434 new_crtc_state->disable_cxsr = true;
6435 } else if (intel_wm_need_update(old_plane_state, new_plane_state)) {
6436 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv)) {
6437 /* FIXME bollocks */
6438 new_crtc_state->update_wm_pre = true;
6439 new_crtc_state->update_wm_post = true;
6443 if (visible || was_visible)
6444 new_crtc_state->fb_bits |= plane->frontbuffer_bit;
6447 * ILK/SNB DVSACNTR/Sprite Enable
6448 * IVB SPR_CTL/Sprite Enable
6449 * "When in Self Refresh Big FIFO mode, a write to enable the
6450 * plane will be internally buffered and delayed while Big FIFO
6453 * Which means that enabling the sprite can take an extra frame
6454 * when we start in big FIFO mode (LP1+). Thus we need to drop
6455 * down to LP0 and wait for vblank in order to make sure the
6456 * sprite gets enabled on the next vblank after the register write.
6457 * Doing otherwise would risk enabling the sprite one frame after
6458 * we've already signalled flip completion. We can resume LP1+
6459 * once the sprite has been enabled.
6462 * WaCxSRDisabledForSpriteScaling:ivb
6463 * IVB SPR_SCALE/Scaling Enable
6464 * "Low Power watermarks must be disabled for at least one
6465 * frame before enabling sprite scaling, and kept disabled
6466 * until sprite scaling is disabled."
6468 * ILK/SNB DVSASCALE/Scaling Enable
6469 * "When in Self Refresh Big FIFO mode, scaling enable will be
6470 * masked off while Big FIFO mode is exiting."
6472 * Despite the w/a only being listed for IVB we assume that
6473 * the ILK/SNB note has similar ramifications, hence we apply
6474 * the w/a on all three platforms.
6476 * With experimental results seems this is needed also for primary
6477 * plane, not only sprite plane.
6479 if (plane->id != PLANE_CURSOR &&
6480 (IS_IRONLAKE(dev_priv) || IS_SANDYBRIDGE(dev_priv) ||
6481 IS_IVYBRIDGE(dev_priv)) &&
6482 (turn_on || (!needs_scaling(old_plane_state) &&
6483 needs_scaling(new_plane_state))))
6484 new_crtc_state->disable_lp_wm = true;
6489 static bool encoders_cloneable(const struct intel_encoder *a,
6490 const struct intel_encoder *b)
6492 /* masks could be asymmetric, so check both ways */
6493 return a == b || (a->cloneable & (1 << b->type) &&
6494 b->cloneable & (1 << a->type));
6497 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
6498 struct intel_crtc *crtc,
6499 struct intel_encoder *encoder)
6501 struct intel_encoder *source_encoder;
6502 struct drm_connector *connector;
6503 struct drm_connector_state *connector_state;
6506 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
6507 if (connector_state->crtc != &crtc->base)
6511 to_intel_encoder(connector_state->best_encoder);
6512 if (!encoders_cloneable(encoder, source_encoder))
6519 static int icl_add_linked_planes(struct intel_atomic_state *state)
6521 struct intel_plane *plane, *linked;
6522 struct intel_plane_state *plane_state, *linked_plane_state;
6525 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6526 linked = plane_state->planar_linked_plane;
6531 linked_plane_state = intel_atomic_get_plane_state(state, linked);
6532 if (IS_ERR(linked_plane_state))
6533 return PTR_ERR(linked_plane_state);
6535 drm_WARN_ON(state->base.dev,
6536 linked_plane_state->planar_linked_plane != plane);
6537 drm_WARN_ON(state->base.dev,
6538 linked_plane_state->planar_slave == plane_state->planar_slave);
6544 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
6546 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6547 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6548 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
6549 struct intel_plane *plane, *linked;
6550 struct intel_plane_state *plane_state;
6553 if (DISPLAY_VER(dev_priv) < 11)
6557 * Destroy all old plane links and make the slave plane invisible
6558 * in the crtc_state->active_planes mask.
6560 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6561 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
6564 plane_state->planar_linked_plane = NULL;
6565 if (plane_state->planar_slave && !plane_state->uapi.visible) {
6566 crtc_state->enabled_planes &= ~BIT(plane->id);
6567 crtc_state->active_planes &= ~BIT(plane->id);
6568 crtc_state->update_planes |= BIT(plane->id);
6571 plane_state->planar_slave = false;
6574 if (!crtc_state->nv12_planes)
6577 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6578 struct intel_plane_state *linked_state = NULL;
6580 if (plane->pipe != crtc->pipe ||
6581 !(crtc_state->nv12_planes & BIT(plane->id)))
6584 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
6585 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
6588 if (crtc_state->active_planes & BIT(linked->id))
6591 linked_state = intel_atomic_get_plane_state(state, linked);
6592 if (IS_ERR(linked_state))
6593 return PTR_ERR(linked_state);
6598 if (!linked_state) {
6599 drm_dbg_kms(&dev_priv->drm,
6600 "Need %d free Y planes for planar YUV\n",
6601 hweight8(crtc_state->nv12_planes));
6606 plane_state->planar_linked_plane = linked;
6608 linked_state->planar_slave = true;
6609 linked_state->planar_linked_plane = plane;
6610 crtc_state->enabled_planes |= BIT(linked->id);
6611 crtc_state->active_planes |= BIT(linked->id);
6612 crtc_state->update_planes |= BIT(linked->id);
6613 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
6614 linked->base.name, plane->base.name);
6616 /* Copy parameters to slave plane */
6617 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
6618 linked_state->color_ctl = plane_state->color_ctl;
6619 linked_state->view = plane_state->view;
6621 intel_plane_copy_hw_state(linked_state, plane_state);
6622 linked_state->uapi.src = plane_state->uapi.src;
6623 linked_state->uapi.dst = plane_state->uapi.dst;
6625 if (icl_is_hdr_plane(dev_priv, plane->id)) {
6626 if (linked->id == PLANE_SPRITE5)
6627 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
6628 else if (linked->id == PLANE_SPRITE4)
6629 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
6630 else if (linked->id == PLANE_SPRITE3)
6631 plane_state->cus_ctl |= PLANE_CUS_PLANE_5_RKL;
6632 else if (linked->id == PLANE_SPRITE2)
6633 plane_state->cus_ctl |= PLANE_CUS_PLANE_4_RKL;
6635 MISSING_CASE(linked->id);
6642 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
6644 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6645 struct intel_atomic_state *state =
6646 to_intel_atomic_state(new_crtc_state->uapi.state);
6647 const struct intel_crtc_state *old_crtc_state =
6648 intel_atomic_get_old_crtc_state(state, crtc);
6650 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
6653 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
6655 const struct drm_display_mode *pipe_mode =
6656 &crtc_state->hw.pipe_mode;
6659 if (!crtc_state->hw.enable)
6662 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
6663 pipe_mode->crtc_clock);
6665 return min(linetime_wm, 0x1ff);
6668 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
6669 const struct intel_cdclk_state *cdclk_state)
6671 const struct drm_display_mode *pipe_mode =
6672 &crtc_state->hw.pipe_mode;
6675 if (!crtc_state->hw.enable)
6678 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
6679 cdclk_state->logical.cdclk);
6681 return min(linetime_wm, 0x1ff);
6684 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
6686 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6687 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6688 const struct drm_display_mode *pipe_mode =
6689 &crtc_state->hw.pipe_mode;
6692 if (!crtc_state->hw.enable)
6695 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
6696 crtc_state->pixel_rate);
6698 /* Display WA #1135: BXT:ALL GLK:ALL */
6699 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
6700 dev_priv->ipc_enabled)
6703 return min(linetime_wm, 0x1ff);
6706 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
6707 struct intel_crtc *crtc)
6709 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6710 struct intel_crtc_state *crtc_state =
6711 intel_atomic_get_new_crtc_state(state, crtc);
6712 const struct intel_cdclk_state *cdclk_state;
6714 if (DISPLAY_VER(dev_priv) >= 9)
6715 crtc_state->linetime = skl_linetime_wm(crtc_state);
6717 crtc_state->linetime = hsw_linetime_wm(crtc_state);
6719 if (!hsw_crtc_supports_ips(crtc))
6722 cdclk_state = intel_atomic_get_cdclk_state(state);
6723 if (IS_ERR(cdclk_state))
6724 return PTR_ERR(cdclk_state);
6726 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
6732 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
6733 struct intel_crtc *crtc)
6735 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6736 struct intel_crtc_state *crtc_state =
6737 intel_atomic_get_new_crtc_state(state, crtc);
6738 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
6741 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
6742 mode_changed && !crtc_state->hw.active)
6743 crtc_state->update_wm_post = true;
6745 if (mode_changed && crtc_state->hw.enable &&
6746 dev_priv->display.crtc_compute_clock &&
6747 !crtc_state->bigjoiner_slave &&
6748 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
6749 ret = dev_priv->display.crtc_compute_clock(crtc_state);
6755 * May need to update pipe gamma enable bits
6756 * when C8 planes are getting enabled/disabled.
6758 if (c8_planes_changed(crtc_state))
6759 crtc_state->uapi.color_mgmt_changed = true;
6761 if (mode_changed || crtc_state->update_pipe ||
6762 crtc_state->uapi.color_mgmt_changed) {
6763 ret = intel_color_check(crtc_state);
6768 if (dev_priv->display.compute_pipe_wm) {
6769 ret = dev_priv->display.compute_pipe_wm(state, crtc);
6771 drm_dbg_kms(&dev_priv->drm,
6772 "Target pipe watermarks are invalid\n");
6778 if (dev_priv->display.compute_intermediate_wm) {
6779 if (drm_WARN_ON(&dev_priv->drm,
6780 !dev_priv->display.compute_pipe_wm))
6784 * Calculate 'intermediate' watermarks that satisfy both the
6785 * old state and the new state. We can program these
6788 ret = dev_priv->display.compute_intermediate_wm(state, crtc);
6790 drm_dbg_kms(&dev_priv->drm,
6791 "No valid intermediate pipe watermarks are possible\n");
6796 if (DISPLAY_VER(dev_priv) >= 9) {
6797 if (mode_changed || crtc_state->update_pipe) {
6798 ret = skl_update_scaler_crtc(crtc_state);
6803 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
6808 if (HAS_IPS(dev_priv)) {
6809 ret = hsw_compute_ips_config(crtc_state);
6814 if (DISPLAY_VER(dev_priv) >= 9 ||
6815 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
6816 ret = hsw_compute_linetime_wm(state, crtc);
6822 ret = intel_psr2_sel_fetch_update(state, crtc);
6829 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
6831 struct intel_connector *connector;
6832 struct drm_connector_list_iter conn_iter;
6834 drm_connector_list_iter_begin(dev, &conn_iter);
6835 for_each_intel_connector_iter(connector, &conn_iter) {
6836 struct drm_connector_state *conn_state = connector->base.state;
6837 struct intel_encoder *encoder =
6838 to_intel_encoder(connector->base.encoder);
6840 if (conn_state->crtc)
6841 drm_connector_put(&connector->base);
6844 struct intel_crtc *crtc =
6845 to_intel_crtc(encoder->base.crtc);
6846 const struct intel_crtc_state *crtc_state =
6847 to_intel_crtc_state(crtc->base.state);
6849 conn_state->best_encoder = &encoder->base;
6850 conn_state->crtc = &crtc->base;
6851 conn_state->max_bpc = (crtc_state->pipe_bpp ?: 24) / 3;
6853 drm_connector_get(&connector->base);
6855 conn_state->best_encoder = NULL;
6856 conn_state->crtc = NULL;
6859 drm_connector_list_iter_end(&conn_iter);
6863 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
6864 struct intel_crtc_state *pipe_config)
6866 struct drm_connector *connector = conn_state->connector;
6867 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
6868 const struct drm_display_info *info = &connector->display_info;
6871 switch (conn_state->max_bpc) {
6885 MISSING_CASE(conn_state->max_bpc);
6889 if (bpp < pipe_config->pipe_bpp) {
6890 drm_dbg_kms(&i915->drm,
6891 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
6892 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
6893 connector->base.id, connector->name,
6895 3 * conn_state->max_requested_bpc,
6896 pipe_config->pipe_bpp);
6898 pipe_config->pipe_bpp = bpp;
6905 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
6906 struct intel_crtc_state *pipe_config)
6908 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6909 struct drm_atomic_state *state = pipe_config->uapi.state;
6910 struct drm_connector *connector;
6911 struct drm_connector_state *connector_state;
6914 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
6915 IS_CHERRYVIEW(dev_priv)))
6917 else if (DISPLAY_VER(dev_priv) >= 5)
6922 pipe_config->pipe_bpp = bpp;
6924 /* Clamp display bpp to connector max bpp */
6925 for_each_new_connector_in_state(state, connector, connector_state, i) {
6928 if (connector_state->crtc != &crtc->base)
6931 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
6939 static void intel_dump_crtc_timings(struct drm_i915_private *i915,
6940 const struct drm_display_mode *mode)
6942 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, "
6943 "type: 0x%x flags: 0x%x\n",
6945 mode->crtc_hdisplay, mode->crtc_hsync_start,
6946 mode->crtc_hsync_end, mode->crtc_htotal,
6947 mode->crtc_vdisplay, mode->crtc_vsync_start,
6948 mode->crtc_vsync_end, mode->crtc_vtotal,
6949 mode->type, mode->flags);
6953 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
6954 const char *id, unsigned int lane_count,
6955 const struct intel_link_m_n *m_n)
6957 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
6959 drm_dbg_kms(&i915->drm,
6960 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
6962 m_n->gmch_m, m_n->gmch_n,
6963 m_n->link_m, m_n->link_n, m_n->tu);
6967 intel_dump_infoframe(struct drm_i915_private *dev_priv,
6968 const union hdmi_infoframe *frame)
6970 if (!drm_debug_enabled(DRM_UT_KMS))
6973 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
6977 intel_dump_dp_vsc_sdp(struct drm_i915_private *dev_priv,
6978 const struct drm_dp_vsc_sdp *vsc)
6980 if (!drm_debug_enabled(DRM_UT_KMS))
6983 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, vsc);
6986 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
6988 static const char * const output_type_str[] = {
6989 OUTPUT_TYPE(UNUSED),
6990 OUTPUT_TYPE(ANALOG),
7000 OUTPUT_TYPE(DP_MST),
7005 static void snprintf_output_types(char *buf, size_t len,
7006 unsigned int output_types)
7013 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
7016 if ((output_types & BIT(i)) == 0)
7019 r = snprintf(str, len, "%s%s",
7020 str != buf ? "," : "", output_type_str[i]);
7026 output_types &= ~BIT(i);
7029 WARN_ON_ONCE(output_types != 0);
7032 static const char * const output_format_str[] = {
7033 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
7034 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
7035 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
7038 static const char *output_formats(enum intel_output_format format)
7040 if (format >= ARRAY_SIZE(output_format_str))
7042 return output_format_str[format];
7045 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
7047 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
7048 struct drm_i915_private *i915 = to_i915(plane->base.dev);
7049 const struct drm_framebuffer *fb = plane_state->hw.fb;
7052 drm_dbg_kms(&i915->drm,
7053 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
7054 plane->base.base.id, plane->base.name,
7055 yesno(plane_state->uapi.visible));
7059 drm_dbg_kms(&i915->drm,
7060 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %p4cc modifier = 0x%llx, visible: %s\n",
7061 plane->base.base.id, plane->base.name,
7062 fb->base.id, fb->width, fb->height, &fb->format->format,
7063 fb->modifier, yesno(plane_state->uapi.visible));
7064 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
7065 plane_state->hw.rotation, plane_state->scaler_id);
7066 if (plane_state->uapi.visible)
7067 drm_dbg_kms(&i915->drm,
7068 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
7069 DRM_RECT_FP_ARG(&plane_state->uapi.src),
7070 DRM_RECT_ARG(&plane_state->uapi.dst));
7073 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
7074 struct intel_atomic_state *state,
7075 const char *context)
7077 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
7078 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7079 const struct intel_plane_state *plane_state;
7080 struct intel_plane *plane;
7084 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
7085 crtc->base.base.id, crtc->base.name,
7086 yesno(pipe_config->hw.enable), context);
7088 if (!pipe_config->hw.enable)
7091 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
7092 drm_dbg_kms(&dev_priv->drm,
7093 "active: %s, output_types: %s (0x%x), output format: %s\n",
7094 yesno(pipe_config->hw.active),
7095 buf, pipe_config->output_types,
7096 output_formats(pipe_config->output_format));
7098 drm_dbg_kms(&dev_priv->drm,
7099 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
7100 transcoder_name(pipe_config->cpu_transcoder),
7101 pipe_config->pipe_bpp, pipe_config->dither);
7103 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
7104 transcoder_name(pipe_config->mst_master_transcoder));
7106 drm_dbg_kms(&dev_priv->drm,
7107 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n",
7108 transcoder_name(pipe_config->master_transcoder),
7109 pipe_config->sync_mode_slaves_mask);
7111 drm_dbg_kms(&dev_priv->drm, "bigjoiner: %s\n",
7112 pipe_config->bigjoiner_slave ? "slave" :
7113 pipe_config->bigjoiner ? "master" : "no");
7115 drm_dbg_kms(&dev_priv->drm, "splitter: %s, link count %d, overlap %d\n",
7116 enableddisabled(pipe_config->splitter.enable),
7117 pipe_config->splitter.link_count,
7118 pipe_config->splitter.pixel_overlap);
7120 if (pipe_config->has_pch_encoder)
7121 intel_dump_m_n_config(pipe_config, "fdi",
7122 pipe_config->fdi_lanes,
7123 &pipe_config->fdi_m_n);
7125 if (intel_crtc_has_dp_encoder(pipe_config)) {
7126 intel_dump_m_n_config(pipe_config, "dp m_n",
7127 pipe_config->lane_count, &pipe_config->dp_m_n);
7128 if (pipe_config->has_drrs)
7129 intel_dump_m_n_config(pipe_config, "dp m2_n2",
7130 pipe_config->lane_count,
7131 &pipe_config->dp_m2_n2);
7134 drm_dbg_kms(&dev_priv->drm,
7135 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
7136 pipe_config->has_audio, pipe_config->has_infoframe,
7137 pipe_config->infoframes.enable);
7139 if (pipe_config->infoframes.enable &
7140 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
7141 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
7142 pipe_config->infoframes.gcp);
7143 if (pipe_config->infoframes.enable &
7144 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
7145 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
7146 if (pipe_config->infoframes.enable &
7147 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
7148 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
7149 if (pipe_config->infoframes.enable &
7150 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
7151 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
7152 if (pipe_config->infoframes.enable &
7153 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_DRM))
7154 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
7155 if (pipe_config->infoframes.enable &
7156 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA))
7157 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
7158 if (pipe_config->infoframes.enable &
7159 intel_hdmi_infoframe_enable(DP_SDP_VSC))
7160 intel_dump_dp_vsc_sdp(dev_priv, &pipe_config->infoframes.vsc);
7162 drm_dbg_kms(&dev_priv->drm, "vrr: %s, vmin: %d, vmax: %d, pipeline full: %d, guardband: %d flipline: %d, vmin vblank: %d, vmax vblank: %d\n",
7163 yesno(pipe_config->vrr.enable),
7164 pipe_config->vrr.vmin, pipe_config->vrr.vmax,
7165 pipe_config->vrr.pipeline_full, pipe_config->vrr.guardband,
7166 pipe_config->vrr.flipline,
7167 intel_vrr_vmin_vblank_start(pipe_config),
7168 intel_vrr_vmax_vblank_start(pipe_config));
7170 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
7171 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
7172 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
7173 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
7174 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode);
7175 drm_dbg_kms(&dev_priv->drm, "pipe mode:\n");
7176 drm_mode_debug_printmodeline(&pipe_config->hw.pipe_mode);
7177 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.pipe_mode);
7178 drm_dbg_kms(&dev_priv->drm,
7179 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
7180 pipe_config->port_clock,
7181 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
7182 pipe_config->pixel_rate);
7184 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
7185 pipe_config->linetime, pipe_config->ips_linetime);
7187 if (DISPLAY_VER(dev_priv) >= 9)
7188 drm_dbg_kms(&dev_priv->drm,
7189 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
7191 pipe_config->scaler_state.scaler_users,
7192 pipe_config->scaler_state.scaler_id);
7194 if (HAS_GMCH(dev_priv))
7195 drm_dbg_kms(&dev_priv->drm,
7196 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
7197 pipe_config->gmch_pfit.control,
7198 pipe_config->gmch_pfit.pgm_ratios,
7199 pipe_config->gmch_pfit.lvds_border_bits);
7201 drm_dbg_kms(&dev_priv->drm,
7202 "pch pfit: " DRM_RECT_FMT ", %s, force thru: %s\n",
7203 DRM_RECT_ARG(&pipe_config->pch_pfit.dst),
7204 enableddisabled(pipe_config->pch_pfit.enabled),
7205 yesno(pipe_config->pch_pfit.force_thru));
7207 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
7208 pipe_config->ips_enabled, pipe_config->double_wide);
7210 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
7212 if (IS_CHERRYVIEW(dev_priv))
7213 drm_dbg_kms(&dev_priv->drm,
7214 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
7215 pipe_config->cgm_mode, pipe_config->gamma_mode,
7216 pipe_config->gamma_enable, pipe_config->csc_enable);
7218 drm_dbg_kms(&dev_priv->drm,
7219 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
7220 pipe_config->csc_mode, pipe_config->gamma_mode,
7221 pipe_config->gamma_enable, pipe_config->csc_enable);
7223 drm_dbg_kms(&dev_priv->drm, "degamma lut: %d entries, gamma lut: %d entries\n",
7224 pipe_config->hw.degamma_lut ?
7225 drm_color_lut_size(pipe_config->hw.degamma_lut) : 0,
7226 pipe_config->hw.gamma_lut ?
7227 drm_color_lut_size(pipe_config->hw.gamma_lut) : 0);
7233 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7234 if (plane->pipe == crtc->pipe)
7235 intel_dump_plane_state(plane_state);
7239 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
7241 struct drm_device *dev = state->base.dev;
7242 struct drm_connector *connector;
7243 struct drm_connector_list_iter conn_iter;
7244 unsigned int used_ports = 0;
7245 unsigned int used_mst_ports = 0;
7249 * We're going to peek into connector->state,
7250 * hence connection_mutex must be held.
7252 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
7255 * Walk the connector list instead of the encoder
7256 * list to detect the problem on ddi platforms
7257 * where there's just one encoder per digital port.
7259 drm_connector_list_iter_begin(dev, &conn_iter);
7260 drm_for_each_connector_iter(connector, &conn_iter) {
7261 struct drm_connector_state *connector_state;
7262 struct intel_encoder *encoder;
7265 drm_atomic_get_new_connector_state(&state->base,
7267 if (!connector_state)
7268 connector_state = connector->state;
7270 if (!connector_state->best_encoder)
7273 encoder = to_intel_encoder(connector_state->best_encoder);
7275 drm_WARN_ON(dev, !connector_state->crtc);
7277 switch (encoder->type) {
7278 case INTEL_OUTPUT_DDI:
7279 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
7282 case INTEL_OUTPUT_DP:
7283 case INTEL_OUTPUT_HDMI:
7284 case INTEL_OUTPUT_EDP:
7285 /* the same port mustn't appear more than once */
7286 if (used_ports & BIT(encoder->port))
7289 used_ports |= BIT(encoder->port);
7291 case INTEL_OUTPUT_DP_MST:
7299 drm_connector_list_iter_end(&conn_iter);
7301 /* can't mix MST and SST/HDMI on the same port */
7302 if (used_ports & used_mst_ports)
7309 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
7310 struct intel_crtc_state *crtc_state)
7312 const struct intel_crtc_state *from_crtc_state = crtc_state;
7314 if (crtc_state->bigjoiner_slave) {
7315 from_crtc_state = intel_atomic_get_new_crtc_state(state,
7316 crtc_state->bigjoiner_linked_crtc);
7318 /* No need to copy state if the master state is unchanged */
7319 if (!from_crtc_state)
7323 intel_crtc_copy_color_blobs(crtc_state, from_crtc_state);
7327 intel_crtc_copy_uapi_to_hw_state(struct intel_atomic_state *state,
7328 struct intel_crtc_state *crtc_state)
7330 crtc_state->hw.enable = crtc_state->uapi.enable;
7331 crtc_state->hw.active = crtc_state->uapi.active;
7332 crtc_state->hw.mode = crtc_state->uapi.mode;
7333 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
7334 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
7336 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc_state);
7339 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
7341 if (crtc_state->bigjoiner_slave)
7344 crtc_state->uapi.enable = crtc_state->hw.enable;
7345 crtc_state->uapi.active = crtc_state->hw.active;
7346 drm_WARN_ON(crtc_state->uapi.crtc->dev,
7347 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
7349 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
7350 crtc_state->uapi.scaling_filter = crtc_state->hw.scaling_filter;
7352 /* copy color blobs to uapi */
7353 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
7354 crtc_state->hw.degamma_lut);
7355 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
7356 crtc_state->hw.gamma_lut);
7357 drm_property_replace_blob(&crtc_state->uapi.ctm,
7358 crtc_state->hw.ctm);
7362 copy_bigjoiner_crtc_state(struct intel_crtc_state *crtc_state,
7363 const struct intel_crtc_state *from_crtc_state)
7365 struct intel_crtc_state *saved_state;
7366 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7368 saved_state = kmemdup(from_crtc_state, sizeof(*saved_state), GFP_KERNEL);
7372 saved_state->uapi = crtc_state->uapi;
7373 saved_state->scaler_state = crtc_state->scaler_state;
7374 saved_state->shared_dpll = crtc_state->shared_dpll;
7375 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
7376 saved_state->crc_enabled = crtc_state->crc_enabled;
7378 intel_crtc_free_hw_state(crtc_state);
7379 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
7382 /* Re-init hw state */
7383 memset(&crtc_state->hw, 0, sizeof(saved_state->hw));
7384 crtc_state->hw.enable = from_crtc_state->hw.enable;
7385 crtc_state->hw.active = from_crtc_state->hw.active;
7386 crtc_state->hw.pipe_mode = from_crtc_state->hw.pipe_mode;
7387 crtc_state->hw.adjusted_mode = from_crtc_state->hw.adjusted_mode;
7390 crtc_state->uapi.mode_changed = from_crtc_state->uapi.mode_changed;
7391 crtc_state->uapi.connectors_changed = from_crtc_state->uapi.connectors_changed;
7392 crtc_state->uapi.active_changed = from_crtc_state->uapi.active_changed;
7393 crtc_state->nv12_planes = crtc_state->c8_planes = crtc_state->update_planes = 0;
7394 crtc_state->bigjoiner_linked_crtc = to_intel_crtc(from_crtc_state->uapi.crtc);
7395 crtc_state->bigjoiner_slave = true;
7396 crtc_state->cpu_transcoder = (enum transcoder)crtc->pipe;
7397 crtc_state->has_audio = false;
7403 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
7404 struct intel_crtc_state *crtc_state)
7406 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7407 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7408 struct intel_crtc_state *saved_state;
7410 saved_state = intel_crtc_state_alloc(crtc);
7414 /* free the old crtc_state->hw members */
7415 intel_crtc_free_hw_state(crtc_state);
7417 /* FIXME: before the switch to atomic started, a new pipe_config was
7418 * kzalloc'd. Code that depends on any field being zero should be
7419 * fixed, so that the crtc_state can be safely duplicated. For now,
7420 * only fields that are know to not cause problems are preserved. */
7422 saved_state->uapi = crtc_state->uapi;
7423 saved_state->scaler_state = crtc_state->scaler_state;
7424 saved_state->shared_dpll = crtc_state->shared_dpll;
7425 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
7426 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
7427 sizeof(saved_state->icl_port_dplls));
7428 saved_state->crc_enabled = crtc_state->crc_enabled;
7429 if (IS_G4X(dev_priv) ||
7430 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7431 saved_state->wm = crtc_state->wm;
7433 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
7436 intel_crtc_copy_uapi_to_hw_state(state, crtc_state);
7442 intel_modeset_pipe_config(struct intel_atomic_state *state,
7443 struct intel_crtc_state *pipe_config)
7445 struct drm_crtc *crtc = pipe_config->uapi.crtc;
7446 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
7447 struct drm_connector *connector;
7448 struct drm_connector_state *connector_state;
7449 int base_bpp, ret, i;
7452 pipe_config->cpu_transcoder =
7453 (enum transcoder) to_intel_crtc(crtc)->pipe;
7456 * Sanitize sync polarity flags based on requested ones. If neither
7457 * positive or negative polarity is requested, treat this as meaning
7458 * negative polarity.
7460 if (!(pipe_config->hw.adjusted_mode.flags &
7461 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
7462 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
7464 if (!(pipe_config->hw.adjusted_mode.flags &
7465 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
7466 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
7468 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
7473 base_bpp = pipe_config->pipe_bpp;
7476 * Determine the real pipe dimensions. Note that stereo modes can
7477 * increase the actual pipe size due to the frame doubling and
7478 * insertion of additional space for blanks between the frame. This
7479 * is stored in the crtc timings. We use the requested mode to do this
7480 * computation to clearly distinguish it from the adjusted mode, which
7481 * can be changed by the connectors in the below retry loop.
7483 drm_mode_get_hv_timing(&pipe_config->hw.mode,
7484 &pipe_config->pipe_src_w,
7485 &pipe_config->pipe_src_h);
7487 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
7488 struct intel_encoder *encoder =
7489 to_intel_encoder(connector_state->best_encoder);
7491 if (connector_state->crtc != crtc)
7494 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
7495 drm_dbg_kms(&i915->drm,
7496 "rejecting invalid cloning configuration\n");
7501 * Determine output_types before calling the .compute_config()
7502 * hooks so that the hooks can use this information safely.
7504 if (encoder->compute_output_type)
7505 pipe_config->output_types |=
7506 BIT(encoder->compute_output_type(encoder, pipe_config,
7509 pipe_config->output_types |= BIT(encoder->type);
7513 /* Ensure the port clock defaults are reset when retrying. */
7514 pipe_config->port_clock = 0;
7515 pipe_config->pixel_multiplier = 1;
7517 /* Fill in default crtc timings, allow encoders to overwrite them. */
7518 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
7519 CRTC_STEREO_DOUBLE);
7521 /* Pass our mode to the connectors and the CRTC to give them a chance to
7522 * adjust it according to limitations or connector properties, and also
7523 * a chance to reject the mode entirely.
7525 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
7526 struct intel_encoder *encoder =
7527 to_intel_encoder(connector_state->best_encoder);
7529 if (connector_state->crtc != crtc)
7532 ret = encoder->compute_config(encoder, pipe_config,
7535 if (ret != -EDEADLK)
7536 drm_dbg_kms(&i915->drm,
7537 "Encoder config failure: %d\n",
7543 /* Set default port clock if not overwritten by the encoder. Needs to be
7544 * done afterwards in case the encoder adjusts the mode. */
7545 if (!pipe_config->port_clock)
7546 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
7547 * pipe_config->pixel_multiplier;
7549 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
7550 if (ret == -EDEADLK)
7553 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
7557 if (ret == I915_DISPLAY_CONFIG_RETRY) {
7558 if (drm_WARN(&i915->drm, !retry,
7559 "loop in pipe configuration computation\n"))
7562 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
7567 /* Dithering seems to not pass-through bits correctly when it should, so
7568 * only enable it on 6bpc panels and when its not a compliance
7569 * test requesting 6bpc video pattern.
7571 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
7572 !pipe_config->dither_force_disable;
7573 drm_dbg_kms(&i915->drm,
7574 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
7575 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
7581 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
7583 struct intel_atomic_state *state =
7584 to_intel_atomic_state(crtc_state->uapi.state);
7585 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7586 struct drm_connector_state *conn_state;
7587 struct drm_connector *connector;
7590 for_each_new_connector_in_state(&state->base, connector,
7592 struct intel_encoder *encoder =
7593 to_intel_encoder(conn_state->best_encoder);
7596 if (conn_state->crtc != &crtc->base ||
7597 !encoder->compute_config_late)
7600 ret = encoder->compute_config_late(encoder, crtc_state,
7609 bool intel_fuzzy_clock_check(int clock1, int clock2)
7613 if (clock1 == clock2)
7616 if (!clock1 || !clock2)
7619 diff = abs(clock1 - clock2);
7621 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
7628 intel_compare_m_n(unsigned int m, unsigned int n,
7629 unsigned int m2, unsigned int n2,
7632 if (m == m2 && n == n2)
7635 if (exact || !m || !n || !m2 || !n2)
7638 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
7645 } else if (n < n2) {
7655 return intel_fuzzy_clock_check(m, m2);
7659 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
7660 const struct intel_link_m_n *m2_n2,
7663 return m_n->tu == m2_n2->tu &&
7664 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
7665 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
7666 intel_compare_m_n(m_n->link_m, m_n->link_n,
7667 m2_n2->link_m, m2_n2->link_n, exact);
7671 intel_compare_infoframe(const union hdmi_infoframe *a,
7672 const union hdmi_infoframe *b)
7674 return memcmp(a, b, sizeof(*a)) == 0;
7678 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
7679 const struct drm_dp_vsc_sdp *b)
7681 return memcmp(a, b, sizeof(*a)) == 0;
7685 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
7686 bool fastset, const char *name,
7687 const union hdmi_infoframe *a,
7688 const union hdmi_infoframe *b)
7691 if (!drm_debug_enabled(DRM_UT_KMS))
7694 drm_dbg_kms(&dev_priv->drm,
7695 "fastset mismatch in %s infoframe\n", name);
7696 drm_dbg_kms(&dev_priv->drm, "expected:\n");
7697 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
7698 drm_dbg_kms(&dev_priv->drm, "found:\n");
7699 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
7701 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
7702 drm_err(&dev_priv->drm, "expected:\n");
7703 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
7704 drm_err(&dev_priv->drm, "found:\n");
7705 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
7710 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
7711 bool fastset, const char *name,
7712 const struct drm_dp_vsc_sdp *a,
7713 const struct drm_dp_vsc_sdp *b)
7716 if (!drm_debug_enabled(DRM_UT_KMS))
7719 drm_dbg_kms(&dev_priv->drm,
7720 "fastset mismatch in %s dp sdp\n", name);
7721 drm_dbg_kms(&dev_priv->drm, "expected:\n");
7722 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
7723 drm_dbg_kms(&dev_priv->drm, "found:\n");
7724 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
7726 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
7727 drm_err(&dev_priv->drm, "expected:\n");
7728 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
7729 drm_err(&dev_priv->drm, "found:\n");
7730 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
7734 static void __printf(4, 5)
7735 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
7736 const char *name, const char *format, ...)
7738 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
7739 struct va_format vaf;
7742 va_start(args, format);
7747 drm_dbg_kms(&i915->drm,
7748 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
7749 crtc->base.base.id, crtc->base.name, name, &vaf);
7751 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
7752 crtc->base.base.id, crtc->base.name, name, &vaf);
7757 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
7759 if (dev_priv->params.fastboot != -1)
7760 return dev_priv->params.fastboot;
7762 /* Enable fastboot by default on Skylake and newer */
7763 if (DISPLAY_VER(dev_priv) >= 9)
7766 /* Enable fastboot by default on VLV and CHV */
7767 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7770 /* Disabled by default on all others */
7775 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
7776 const struct intel_crtc_state *pipe_config,
7779 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
7780 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
7783 bool fixup_inherited = fastset &&
7784 current_config->inherited && !pipe_config->inherited;
7786 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
7787 drm_dbg_kms(&dev_priv->drm,
7788 "initial modeset and fastboot not set\n");
7792 #define PIPE_CONF_CHECK_X(name) do { \
7793 if (current_config->name != pipe_config->name) { \
7794 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7795 "(expected 0x%08x, found 0x%08x)", \
7796 current_config->name, \
7797 pipe_config->name); \
7802 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
7803 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
7804 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7805 "(expected 0x%08x, found 0x%08x)", \
7806 current_config->name & (mask), \
7807 pipe_config->name & (mask)); \
7812 #define PIPE_CONF_CHECK_I(name) do { \
7813 if (current_config->name != pipe_config->name) { \
7814 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7815 "(expected %i, found %i)", \
7816 current_config->name, \
7817 pipe_config->name); \
7822 #define PIPE_CONF_CHECK_BOOL(name) do { \
7823 if (current_config->name != pipe_config->name) { \
7824 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7825 "(expected %s, found %s)", \
7826 yesno(current_config->name), \
7827 yesno(pipe_config->name)); \
7833 * Checks state where we only read out the enabling, but not the entire
7834 * state itself (like full infoframes or ELD for audio). These states
7835 * require a full modeset on bootup to fix up.
7837 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
7838 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
7839 PIPE_CONF_CHECK_BOOL(name); \
7841 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7842 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
7843 yesno(current_config->name), \
7844 yesno(pipe_config->name)); \
7849 #define PIPE_CONF_CHECK_P(name) do { \
7850 if (current_config->name != pipe_config->name) { \
7851 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7852 "(expected %p, found %p)", \
7853 current_config->name, \
7854 pipe_config->name); \
7859 #define PIPE_CONF_CHECK_M_N(name) do { \
7860 if (!intel_compare_link_m_n(¤t_config->name, \
7861 &pipe_config->name,\
7863 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7864 "(expected tu %i gmch %i/%i link %i/%i, " \
7865 "found tu %i, gmch %i/%i link %i/%i)", \
7866 current_config->name.tu, \
7867 current_config->name.gmch_m, \
7868 current_config->name.gmch_n, \
7869 current_config->name.link_m, \
7870 current_config->name.link_n, \
7871 pipe_config->name.tu, \
7872 pipe_config->name.gmch_m, \
7873 pipe_config->name.gmch_n, \
7874 pipe_config->name.link_m, \
7875 pipe_config->name.link_n); \
7880 /* This is required for BDW+ where there is only one set of registers for
7881 * switching between high and low RR.
7882 * This macro can be used whenever a comparison has to be made between one
7883 * hw state and multiple sw state variables.
7885 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
7886 if (!intel_compare_link_m_n(¤t_config->name, \
7887 &pipe_config->name, !fastset) && \
7888 !intel_compare_link_m_n(¤t_config->alt_name, \
7889 &pipe_config->name, !fastset)) { \
7890 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7891 "(expected tu %i gmch %i/%i link %i/%i, " \
7892 "or tu %i gmch %i/%i link %i/%i, " \
7893 "found tu %i, gmch %i/%i link %i/%i)", \
7894 current_config->name.tu, \
7895 current_config->name.gmch_m, \
7896 current_config->name.gmch_n, \
7897 current_config->name.link_m, \
7898 current_config->name.link_n, \
7899 current_config->alt_name.tu, \
7900 current_config->alt_name.gmch_m, \
7901 current_config->alt_name.gmch_n, \
7902 current_config->alt_name.link_m, \
7903 current_config->alt_name.link_n, \
7904 pipe_config->name.tu, \
7905 pipe_config->name.gmch_m, \
7906 pipe_config->name.gmch_n, \
7907 pipe_config->name.link_m, \
7908 pipe_config->name.link_n); \
7913 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
7914 if ((current_config->name ^ pipe_config->name) & (mask)) { \
7915 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7916 "(%x) (expected %i, found %i)", \
7918 current_config->name & (mask), \
7919 pipe_config->name & (mask)); \
7924 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
7925 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
7926 pipe_config_mismatch(fastset, crtc, __stringify(name), \
7927 "(expected %i, found %i)", \
7928 current_config->name, \
7929 pipe_config->name); \
7934 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
7935 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
7936 &pipe_config->infoframes.name)) { \
7937 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
7938 ¤t_config->infoframes.name, \
7939 &pipe_config->infoframes.name); \
7944 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
7945 if (!current_config->has_psr && !pipe_config->has_psr && \
7946 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
7947 &pipe_config->infoframes.name)) { \
7948 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
7949 ¤t_config->infoframes.name, \
7950 &pipe_config->infoframes.name); \
7955 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
7956 if (current_config->name1 != pipe_config->name1) { \
7957 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
7958 "(expected %i, found %i, won't compare lut values)", \
7959 current_config->name1, \
7960 pipe_config->name1); \
7963 if (!intel_color_lut_equal(current_config->name2, \
7964 pipe_config->name2, pipe_config->name1, \
7966 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
7967 "hw_state doesn't match sw_state"); \
7973 #define PIPE_CONF_QUIRK(quirk) \
7974 ((current_config->quirks | pipe_config->quirks) & (quirk))
7976 PIPE_CONF_CHECK_I(cpu_transcoder);
7978 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
7979 PIPE_CONF_CHECK_I(fdi_lanes);
7980 PIPE_CONF_CHECK_M_N(fdi_m_n);
7982 PIPE_CONF_CHECK_I(lane_count);
7983 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
7985 if (DISPLAY_VER(dev_priv) < 8) {
7986 PIPE_CONF_CHECK_M_N(dp_m_n);
7988 if (current_config->has_drrs)
7989 PIPE_CONF_CHECK_M_N(dp_m2_n2);
7991 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
7993 PIPE_CONF_CHECK_X(output_types);
7995 /* FIXME do the readout properly and get rid of this quirk */
7996 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
7997 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hdisplay);
7998 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_htotal);
7999 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_start);
8000 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_end);
8001 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_start);
8002 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_end);
8004 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vdisplay);
8005 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vtotal);
8006 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_start);
8007 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_end);
8008 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_start);
8009 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_end);
8011 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
8012 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
8013 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
8014 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
8015 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
8016 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
8018 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
8019 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
8020 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
8021 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
8022 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
8023 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
8025 PIPE_CONF_CHECK_I(pixel_multiplier);
8027 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8028 DRM_MODE_FLAG_INTERLACE);
8030 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
8031 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8032 DRM_MODE_FLAG_PHSYNC);
8033 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8034 DRM_MODE_FLAG_NHSYNC);
8035 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8036 DRM_MODE_FLAG_PVSYNC);
8037 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8038 DRM_MODE_FLAG_NVSYNC);
8042 PIPE_CONF_CHECK_I(output_format);
8043 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
8044 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
8045 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
8046 PIPE_CONF_CHECK_BOOL(limited_color_range);
8048 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
8049 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
8050 PIPE_CONF_CHECK_BOOL(has_infoframe);
8051 /* FIXME do the readout properly and get rid of this quirk */
8052 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
8053 PIPE_CONF_CHECK_BOOL(fec_enable);
8055 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
8057 PIPE_CONF_CHECK_X(gmch_pfit.control);
8058 /* pfit ratios are autocomputed by the hw on gen4+ */
8059 if (DISPLAY_VER(dev_priv) < 4)
8060 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
8061 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
8064 * Changing the EDP transcoder input mux
8065 * (A_ONOFF vs. A_ON) requires a full modeset.
8067 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
8070 PIPE_CONF_CHECK_I(pipe_src_w);
8071 PIPE_CONF_CHECK_I(pipe_src_h);
8073 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
8074 if (current_config->pch_pfit.enabled) {
8075 PIPE_CONF_CHECK_I(pch_pfit.dst.x1);
8076 PIPE_CONF_CHECK_I(pch_pfit.dst.y1);
8077 PIPE_CONF_CHECK_I(pch_pfit.dst.x2);
8078 PIPE_CONF_CHECK_I(pch_pfit.dst.y2);
8081 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
8082 /* FIXME do the readout properly and get rid of this quirk */
8083 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
8084 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
8086 PIPE_CONF_CHECK_X(gamma_mode);
8087 if (IS_CHERRYVIEW(dev_priv))
8088 PIPE_CONF_CHECK_X(cgm_mode);
8090 PIPE_CONF_CHECK_X(csc_mode);
8091 PIPE_CONF_CHECK_BOOL(gamma_enable);
8092 PIPE_CONF_CHECK_BOOL(csc_enable);
8094 PIPE_CONF_CHECK_I(linetime);
8095 PIPE_CONF_CHECK_I(ips_linetime);
8097 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
8099 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
8101 if (current_config->active_planes) {
8102 PIPE_CONF_CHECK_BOOL(has_psr);
8103 PIPE_CONF_CHECK_BOOL(has_psr2);
8104 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
8105 PIPE_CONF_CHECK_I(dc3co_exitline);
8109 PIPE_CONF_CHECK_BOOL(double_wide);
8111 if (dev_priv->dpll.mgr)
8112 PIPE_CONF_CHECK_P(shared_dpll);
8114 /* FIXME do the readout properly and get rid of this quirk */
8115 if (dev_priv->dpll.mgr && !PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
8116 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
8117 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
8118 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
8119 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
8120 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
8121 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
8122 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
8123 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
8124 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
8125 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
8126 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
8127 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
8128 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
8129 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
8130 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
8131 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
8132 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
8133 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
8134 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
8135 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
8136 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
8137 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
8138 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
8139 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
8140 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
8141 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
8142 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
8143 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
8144 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
8145 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
8146 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
8149 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
8150 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
8151 PIPE_CONF_CHECK_X(dsi_pll.div);
8153 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
8154 PIPE_CONF_CHECK_I(pipe_bpp);
8156 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
8157 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
8158 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
8160 PIPE_CONF_CHECK_I(min_voltage_level);
8163 if (current_config->has_psr || pipe_config->has_psr)
8164 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
8165 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
8167 PIPE_CONF_CHECK_X(infoframes.enable);
8169 PIPE_CONF_CHECK_X(infoframes.gcp);
8170 PIPE_CONF_CHECK_INFOFRAME(avi);
8171 PIPE_CONF_CHECK_INFOFRAME(spd);
8172 PIPE_CONF_CHECK_INFOFRAME(hdmi);
8173 PIPE_CONF_CHECK_INFOFRAME(drm);
8174 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
8176 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
8177 PIPE_CONF_CHECK_I(master_transcoder);
8178 PIPE_CONF_CHECK_BOOL(bigjoiner);
8179 PIPE_CONF_CHECK_BOOL(bigjoiner_slave);
8180 PIPE_CONF_CHECK_P(bigjoiner_linked_crtc);
8182 PIPE_CONF_CHECK_I(dsc.compression_enable);
8183 PIPE_CONF_CHECK_I(dsc.dsc_split);
8184 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
8186 PIPE_CONF_CHECK_BOOL(splitter.enable);
8187 PIPE_CONF_CHECK_I(splitter.link_count);
8188 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
8190 PIPE_CONF_CHECK_I(mst_master_transcoder);
8192 PIPE_CONF_CHECK_BOOL(vrr.enable);
8193 PIPE_CONF_CHECK_I(vrr.vmin);
8194 PIPE_CONF_CHECK_I(vrr.vmax);
8195 PIPE_CONF_CHECK_I(vrr.flipline);
8196 PIPE_CONF_CHECK_I(vrr.pipeline_full);
8197 PIPE_CONF_CHECK_I(vrr.guardband);
8199 #undef PIPE_CONF_CHECK_X
8200 #undef PIPE_CONF_CHECK_I
8201 #undef PIPE_CONF_CHECK_BOOL
8202 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
8203 #undef PIPE_CONF_CHECK_P
8204 #undef PIPE_CONF_CHECK_FLAGS
8205 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
8206 #undef PIPE_CONF_CHECK_COLOR_LUT
8207 #undef PIPE_CONF_QUIRK
8212 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
8213 const struct intel_crtc_state *pipe_config)
8215 if (pipe_config->has_pch_encoder) {
8216 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
8217 &pipe_config->fdi_m_n);
8218 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
8221 * FDI already provided one idea for the dotclock.
8222 * Yell if the encoder disagrees.
8224 drm_WARN(&dev_priv->drm,
8225 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
8226 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
8227 fdi_dotclock, dotclock);
8231 static void verify_wm_state(struct intel_crtc *crtc,
8232 struct intel_crtc_state *new_crtc_state)
8234 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8235 struct skl_hw_state {
8236 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
8237 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
8238 struct skl_pipe_wm wm;
8240 const struct skl_pipe_wm *sw_wm = &new_crtc_state->wm.skl.optimal;
8241 int level, max_level = ilk_wm_max_level(dev_priv);
8242 struct intel_plane *plane;
8243 u8 hw_enabled_slices;
8245 if (DISPLAY_VER(dev_priv) < 9 || !new_crtc_state->hw.active)
8248 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
8252 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
8254 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
8256 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
8258 if (DISPLAY_VER(dev_priv) >= 11 &&
8259 hw_enabled_slices != dev_priv->dbuf.enabled_slices)
8260 drm_err(&dev_priv->drm,
8261 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
8262 dev_priv->dbuf.enabled_slices,
8265 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
8266 const struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
8267 const struct skl_wm_level *hw_wm_level, *sw_wm_level;
8270 for (level = 0; level <= max_level; level++) {
8271 hw_wm_level = &hw->wm.planes[plane->id].wm[level];
8272 sw_wm_level = skl_plane_wm_level(sw_wm, plane->id, level);
8274 if (skl_wm_level_equals(hw_wm_level, sw_wm_level))
8277 drm_err(&dev_priv->drm,
8278 "[PLANE:%d:%s] mismatch in WM%d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8279 plane->base.base.id, plane->base.name, level,
8280 sw_wm_level->enable,
8281 sw_wm_level->blocks,
8283 hw_wm_level->enable,
8284 hw_wm_level->blocks,
8285 hw_wm_level->lines);
8288 hw_wm_level = &hw->wm.planes[plane->id].trans_wm;
8289 sw_wm_level = skl_plane_trans_wm(sw_wm, plane->id);
8291 if (!skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8292 drm_err(&dev_priv->drm,
8293 "[PLANE:%d:%s] mismatch in trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8294 plane->base.base.id, plane->base.name,
8295 sw_wm_level->enable,
8296 sw_wm_level->blocks,
8298 hw_wm_level->enable,
8299 hw_wm_level->blocks,
8300 hw_wm_level->lines);
8303 hw_wm_level = &hw->wm.planes[plane->id].sagv.wm0;
8304 sw_wm_level = &sw_wm->planes[plane->id].sagv.wm0;
8306 if (HAS_HW_SAGV_WM(dev_priv) &&
8307 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8308 drm_err(&dev_priv->drm,
8309 "[PLANE:%d:%s] mismatch in SAGV WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8310 plane->base.base.id, plane->base.name,
8311 sw_wm_level->enable,
8312 sw_wm_level->blocks,
8314 hw_wm_level->enable,
8315 hw_wm_level->blocks,
8316 hw_wm_level->lines);
8319 hw_wm_level = &hw->wm.planes[plane->id].sagv.trans_wm;
8320 sw_wm_level = &sw_wm->planes[plane->id].sagv.trans_wm;
8322 if (HAS_HW_SAGV_WM(dev_priv) &&
8323 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8324 drm_err(&dev_priv->drm,
8325 "[PLANE:%d:%s] mismatch in SAGV trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8326 plane->base.base.id, plane->base.name,
8327 sw_wm_level->enable,
8328 sw_wm_level->blocks,
8330 hw_wm_level->enable,
8331 hw_wm_level->blocks,
8332 hw_wm_level->lines);
8336 hw_ddb_entry = &hw->ddb_y[plane->id];
8337 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane->id];
8339 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
8340 drm_err(&dev_priv->drm,
8341 "[PLANE:%d:%s] mismatch in DDB (expected (%u,%u), found (%u,%u))\n",
8342 plane->base.base.id, plane->base.name,
8343 sw_ddb_entry->start, sw_ddb_entry->end,
8344 hw_ddb_entry->start, hw_ddb_entry->end);
8352 verify_connector_state(struct intel_atomic_state *state,
8353 struct intel_crtc *crtc)
8355 struct drm_connector *connector;
8356 struct drm_connector_state *new_conn_state;
8359 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
8360 struct drm_encoder *encoder = connector->encoder;
8361 struct intel_crtc_state *crtc_state = NULL;
8363 if (new_conn_state->crtc != &crtc->base)
8367 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
8369 intel_connector_verify_state(crtc_state, new_conn_state);
8371 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
8372 "connector's atomic encoder doesn't match legacy encoder\n");
8377 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
8379 struct intel_encoder *encoder;
8380 struct drm_connector *connector;
8381 struct drm_connector_state *old_conn_state, *new_conn_state;
8384 for_each_intel_encoder(&dev_priv->drm, encoder) {
8385 bool enabled = false, found = false;
8388 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
8389 encoder->base.base.id,
8390 encoder->base.name);
8392 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
8393 new_conn_state, i) {
8394 if (old_conn_state->best_encoder == &encoder->base)
8397 if (new_conn_state->best_encoder != &encoder->base)
8399 found = enabled = true;
8401 I915_STATE_WARN(new_conn_state->crtc !=
8403 "connector's crtc doesn't match encoder crtc\n");
8409 I915_STATE_WARN(!!encoder->base.crtc != enabled,
8410 "encoder's enabled state mismatch "
8411 "(expected %i, found %i)\n",
8412 !!encoder->base.crtc, enabled);
8414 if (!encoder->base.crtc) {
8417 active = encoder->get_hw_state(encoder, &pipe);
8418 I915_STATE_WARN(active,
8419 "encoder detached but still enabled on pipe %c.\n",
8426 verify_crtc_state(struct intel_crtc *crtc,
8427 struct intel_crtc_state *old_crtc_state,
8428 struct intel_crtc_state *new_crtc_state)
8430 struct drm_device *dev = crtc->base.dev;
8431 struct drm_i915_private *dev_priv = to_i915(dev);
8432 struct intel_encoder *encoder;
8433 struct intel_crtc_state *pipe_config = old_crtc_state;
8434 struct drm_atomic_state *state = old_crtc_state->uapi.state;
8435 struct intel_crtc *master = crtc;
8437 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
8438 intel_crtc_free_hw_state(old_crtc_state);
8439 intel_crtc_state_reset(old_crtc_state, crtc);
8440 old_crtc_state->uapi.state = state;
8442 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
8445 pipe_config->hw.enable = new_crtc_state->hw.enable;
8447 intel_crtc_get_pipe_config(pipe_config);
8449 /* we keep both pipes enabled on 830 */
8450 if (IS_I830(dev_priv) && pipe_config->hw.active)
8451 pipe_config->hw.active = new_crtc_state->hw.active;
8453 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active,
8454 "crtc active state doesn't match with hw state "
8455 "(expected %i, found %i)\n",
8456 new_crtc_state->hw.active, pipe_config->hw.active);
8458 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
8459 "transitional active state does not match atomic hw state "
8460 "(expected %i, found %i)\n",
8461 new_crtc_state->hw.active, crtc->active);
8463 if (new_crtc_state->bigjoiner_slave)
8464 master = new_crtc_state->bigjoiner_linked_crtc;
8466 for_each_encoder_on_crtc(dev, &master->base, encoder) {
8470 active = encoder->get_hw_state(encoder, &pipe);
8471 I915_STATE_WARN(active != new_crtc_state->hw.active,
8472 "[ENCODER:%i] active %i with crtc active %i\n",
8473 encoder->base.base.id, active,
8474 new_crtc_state->hw.active);
8476 I915_STATE_WARN(active && master->pipe != pipe,
8477 "Encoder connected to wrong pipe %c\n",
8481 intel_encoder_get_config(encoder, pipe_config);
8484 if (!new_crtc_state->hw.active)
8487 if (new_crtc_state->bigjoiner_slave)
8488 /* No PLLs set for slave */
8489 pipe_config->shared_dpll = NULL;
8491 intel_pipe_config_sanity_check(dev_priv, pipe_config);
8493 if (!intel_pipe_config_compare(new_crtc_state,
8494 pipe_config, false)) {
8495 I915_STATE_WARN(1, "pipe state doesn't match!\n");
8496 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
8497 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
8502 intel_verify_planes(struct intel_atomic_state *state)
8504 struct intel_plane *plane;
8505 const struct intel_plane_state *plane_state;
8508 for_each_new_intel_plane_in_state(state, plane,
8510 assert_plane(plane, plane_state->planar_slave ||
8511 plane_state->uapi.visible);
8515 verify_single_dpll_state(struct drm_i915_private *dev_priv,
8516 struct intel_shared_dpll *pll,
8517 struct intel_crtc *crtc,
8518 struct intel_crtc_state *new_crtc_state)
8520 struct intel_dpll_hw_state dpll_hw_state;
8524 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
8526 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
8528 active = intel_dpll_get_hw_state(dev_priv, pll, &dpll_hw_state);
8530 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
8531 I915_STATE_WARN(!pll->on && pll->active_mask,
8532 "pll in active use but not on in sw tracking\n");
8533 I915_STATE_WARN(pll->on && !pll->active_mask,
8534 "pll is on but not used by any active pipe\n");
8535 I915_STATE_WARN(pll->on != active,
8536 "pll on state mismatch (expected %i, found %i)\n",
8541 I915_STATE_WARN(pll->active_mask & ~pll->state.pipe_mask,
8542 "more active pll users than references: 0x%x vs 0x%x\n",
8543 pll->active_mask, pll->state.pipe_mask);
8548 pipe_mask = BIT(crtc->pipe);
8550 if (new_crtc_state->hw.active)
8551 I915_STATE_WARN(!(pll->active_mask & pipe_mask),
8552 "pll active mismatch (expected pipe %c in active mask 0x%x)\n",
8553 pipe_name(crtc->pipe), pll->active_mask);
8555 I915_STATE_WARN(pll->active_mask & pipe_mask,
8556 "pll active mismatch (didn't expect pipe %c in active mask 0x%x)\n",
8557 pipe_name(crtc->pipe), pll->active_mask);
8559 I915_STATE_WARN(!(pll->state.pipe_mask & pipe_mask),
8560 "pll enabled crtcs mismatch (expected 0x%x in 0x%x)\n",
8561 pipe_mask, pll->state.pipe_mask);
8563 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
8565 sizeof(dpll_hw_state)),
8566 "pll hw state mismatch\n");
8570 verify_shared_dpll_state(struct intel_crtc *crtc,
8571 struct intel_crtc_state *old_crtc_state,
8572 struct intel_crtc_state *new_crtc_state)
8574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8576 if (new_crtc_state->shared_dpll)
8577 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
8579 if (old_crtc_state->shared_dpll &&
8580 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
8581 u8 pipe_mask = BIT(crtc->pipe);
8582 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
8584 I915_STATE_WARN(pll->active_mask & pipe_mask,
8585 "pll active mismatch (didn't expect pipe %c in active mask (0x%x))\n",
8586 pipe_name(crtc->pipe), pll->active_mask);
8587 I915_STATE_WARN(pll->state.pipe_mask & pipe_mask,
8588 "pll enabled crtcs mismatch (found %x in enabled mask (0x%x))\n",
8589 pipe_name(crtc->pipe), pll->state.pipe_mask);
8594 verify_mpllb_state(struct intel_atomic_state *state,
8595 struct intel_crtc_state *new_crtc_state)
8597 struct drm_i915_private *i915 = to_i915(state->base.dev);
8598 struct intel_mpllb_state mpllb_hw_state = { 0 };
8599 struct intel_mpllb_state *mpllb_sw_state = &new_crtc_state->mpllb_state;
8600 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
8601 struct intel_encoder *encoder;
8606 if (!new_crtc_state->hw.active)
8609 if (new_crtc_state->bigjoiner_slave)
8612 encoder = intel_get_crtc_new_encoder(state, new_crtc_state);
8613 intel_mpllb_readout_hw_state(encoder, &mpllb_hw_state);
8615 #define MPLLB_CHECK(name) do { \
8616 if (mpllb_sw_state->name != mpllb_hw_state.name) { \
8617 pipe_config_mismatch(false, crtc, "MPLLB:" __stringify(name), \
8618 "(expected 0x%08x, found 0x%08x)", \
8619 mpllb_sw_state->name, \
8620 mpllb_hw_state.name); \
8624 MPLLB_CHECK(mpllb_cp);
8625 MPLLB_CHECK(mpllb_div);
8626 MPLLB_CHECK(mpllb_div2);
8627 MPLLB_CHECK(mpllb_fracn1);
8628 MPLLB_CHECK(mpllb_fracn2);
8629 MPLLB_CHECK(mpllb_sscen);
8630 MPLLB_CHECK(mpllb_sscstep);
8633 * ref_control is handled by the hardware/firemware and never
8634 * programmed by the software, but the proper values are supplied
8635 * in the bspec for verification purposes.
8637 MPLLB_CHECK(ref_control);
8643 intel_modeset_verify_crtc(struct intel_crtc *crtc,
8644 struct intel_atomic_state *state,
8645 struct intel_crtc_state *old_crtc_state,
8646 struct intel_crtc_state *new_crtc_state)
8648 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
8651 verify_wm_state(crtc, new_crtc_state);
8652 verify_connector_state(state, crtc);
8653 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
8654 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
8655 verify_mpllb_state(state, new_crtc_state);
8659 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
8663 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
8664 verify_single_dpll_state(dev_priv,
8665 &dev_priv->dpll.shared_dplls[i],
8670 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
8671 struct intel_atomic_state *state)
8673 verify_encoder_state(dev_priv, state);
8674 verify_connector_state(state, NULL);
8675 verify_disabled_dpll_state(dev_priv);
8678 int intel_modeset_all_pipes(struct intel_atomic_state *state)
8680 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8681 struct intel_crtc *crtc;
8684 * Add all pipes to the state, and force
8685 * a modeset on all the active ones.
8687 for_each_intel_crtc(&dev_priv->drm, crtc) {
8688 struct intel_crtc_state *crtc_state;
8691 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
8692 if (IS_ERR(crtc_state))
8693 return PTR_ERR(crtc_state);
8695 if (!crtc_state->hw.active ||
8696 drm_atomic_crtc_needs_modeset(&crtc_state->uapi))
8699 crtc_state->uapi.mode_changed = true;
8701 ret = drm_atomic_add_affected_connectors(&state->base,
8706 ret = intel_atomic_add_affected_planes(state, crtc);
8710 crtc_state->update_planes |= crtc_state->active_planes;
8717 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
8719 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8720 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8721 struct drm_display_mode adjusted_mode =
8722 crtc_state->hw.adjusted_mode;
8724 if (crtc_state->vrr.enable) {
8725 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax;
8726 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax;
8727 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state);
8728 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state);
8731 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
8733 crtc->mode_flags = crtc_state->mode_flags;
8736 * The scanline counter increments at the leading edge of hsync.
8738 * On most platforms it starts counting from vtotal-1 on the
8739 * first active line. That means the scanline counter value is
8740 * always one less than what we would expect. Ie. just after
8741 * start of vblank, which also occurs at start of hsync (on the
8742 * last active line), the scanline counter will read vblank_start-1.
8744 * On gen2 the scanline counter starts counting from 1 instead
8745 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
8746 * to keep the value positive), instead of adding one.
8748 * On HSW+ the behaviour of the scanline counter depends on the output
8749 * type. For DP ports it behaves like most other platforms, but on HDMI
8750 * there's an extra 1 line difference. So we need to add two instead of
8753 * On VLV/CHV DSI the scanline counter would appear to increment
8754 * approx. 1/3 of a scanline before start of vblank. Unfortunately
8755 * that means we can't tell whether we're in vblank or not while
8756 * we're on that particular line. We must still set scanline_offset
8757 * to 1 so that the vblank timestamps come out correct when we query
8758 * the scanline counter from within the vblank interrupt handler.
8759 * However if queried just before the start of vblank we'll get an
8760 * answer that's slightly in the future.
8762 if (DISPLAY_VER(dev_priv) == 2) {
8765 vtotal = adjusted_mode.crtc_vtotal;
8766 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8769 crtc->scanline_offset = vtotal - 1;
8770 } else if (HAS_DDI(dev_priv) &&
8771 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
8772 crtc->scanline_offset = 2;
8774 crtc->scanline_offset = 1;
8778 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
8780 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8781 struct intel_crtc_state *new_crtc_state;
8782 struct intel_crtc *crtc;
8785 if (!dev_priv->display.crtc_compute_clock)
8788 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
8789 if (!intel_crtc_needs_modeset(new_crtc_state))
8792 intel_release_shared_dplls(state, crtc);
8797 * This implements the workaround described in the "notes" section of the mode
8798 * set sequence documentation. When going from no pipes or single pipe to
8799 * multiple pipes, and planes are enabled after the pipe, we need to wait at
8800 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
8802 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
8804 struct intel_crtc_state *crtc_state;
8805 struct intel_crtc *crtc;
8806 struct intel_crtc_state *first_crtc_state = NULL;
8807 struct intel_crtc_state *other_crtc_state = NULL;
8808 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
8811 /* look at all crtc's that are going to be enabled in during modeset */
8812 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
8813 if (!crtc_state->hw.active ||
8814 !intel_crtc_needs_modeset(crtc_state))
8817 if (first_crtc_state) {
8818 other_crtc_state = crtc_state;
8821 first_crtc_state = crtc_state;
8822 first_pipe = crtc->pipe;
8826 /* No workaround needed? */
8827 if (!first_crtc_state)
8830 /* w/a possibly needed, check how many crtc's are already enabled. */
8831 for_each_intel_crtc(state->base.dev, crtc) {
8832 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
8833 if (IS_ERR(crtc_state))
8834 return PTR_ERR(crtc_state);
8836 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
8838 if (!crtc_state->hw.active ||
8839 intel_crtc_needs_modeset(crtc_state))
8842 /* 2 or more enabled crtcs means no need for w/a */
8843 if (enabled_pipe != INVALID_PIPE)
8846 enabled_pipe = crtc->pipe;
8849 if (enabled_pipe != INVALID_PIPE)
8850 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
8851 else if (other_crtc_state)
8852 other_crtc_state->hsw_workaround_pipe = first_pipe;
8857 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
8860 const struct intel_crtc_state *crtc_state;
8861 struct intel_crtc *crtc;
8864 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
8865 if (crtc_state->hw.active)
8866 active_pipes |= BIT(crtc->pipe);
8868 active_pipes &= ~BIT(crtc->pipe);
8871 return active_pipes;
8874 static int intel_modeset_checks(struct intel_atomic_state *state)
8876 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8878 state->modeset = true;
8880 if (IS_HASWELL(dev_priv))
8881 return hsw_mode_set_planes_workaround(state);
8887 * Handle calculation of various watermark data at the end of the atomic check
8888 * phase. The code here should be run after the per-crtc and per-plane 'check'
8889 * handlers to ensure that all derived state has been updated.
8891 static int calc_watermark_data(struct intel_atomic_state *state)
8893 struct drm_device *dev = state->base.dev;
8894 struct drm_i915_private *dev_priv = to_i915(dev);
8896 /* Is there platform-specific watermark information to calculate? */
8897 if (dev_priv->display.compute_global_watermarks)
8898 return dev_priv->display.compute_global_watermarks(state);
8903 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
8904 struct intel_crtc_state *new_crtc_state)
8906 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
8909 new_crtc_state->uapi.mode_changed = false;
8910 new_crtc_state->update_pipe = true;
8913 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
8914 struct intel_crtc_state *new_crtc_state)
8917 * If we're not doing the full modeset we want to
8918 * keep the current M/N values as they may be
8919 * sufficiently different to the computed values
8920 * to cause problems.
8922 * FIXME: should really copy more fuzzy state here
8924 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
8925 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
8926 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
8927 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
8930 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
8931 struct intel_crtc *crtc,
8934 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8935 struct intel_plane *plane;
8937 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
8938 struct intel_plane_state *plane_state;
8940 if ((plane_ids_mask & BIT(plane->id)) == 0)
8943 plane_state = intel_atomic_get_plane_state(state, plane);
8944 if (IS_ERR(plane_state))
8945 return PTR_ERR(plane_state);
8951 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
8952 struct intel_crtc *crtc)
8954 const struct intel_crtc_state *old_crtc_state =
8955 intel_atomic_get_old_crtc_state(state, crtc);
8956 const struct intel_crtc_state *new_crtc_state =
8957 intel_atomic_get_new_crtc_state(state, crtc);
8959 return intel_crtc_add_planes_to_state(state, crtc,
8960 old_crtc_state->enabled_planes |
8961 new_crtc_state->enabled_planes);
8964 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
8966 /* See {hsw,vlv,ivb}_plane_ratio() */
8967 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
8968 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8969 IS_IVYBRIDGE(dev_priv);
8972 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
8973 struct intel_crtc *crtc,
8974 struct intel_crtc *other)
8976 const struct intel_plane_state *plane_state;
8977 struct intel_plane *plane;
8981 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
8982 if (plane->pipe == crtc->pipe)
8983 plane_ids |= BIT(plane->id);
8986 return intel_crtc_add_planes_to_state(state, other, plane_ids);
8989 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
8991 const struct intel_crtc_state *crtc_state;
8992 struct intel_crtc *crtc;
8995 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
8998 if (!crtc_state->bigjoiner)
9001 ret = intel_crtc_add_bigjoiner_planes(state, crtc,
9002 crtc_state->bigjoiner_linked_crtc);
9010 static int intel_atomic_check_planes(struct intel_atomic_state *state)
9012 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9013 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9014 struct intel_plane_state *plane_state;
9015 struct intel_plane *plane;
9016 struct intel_crtc *crtc;
9019 ret = icl_add_linked_planes(state);
9023 ret = intel_bigjoiner_add_affected_planes(state);
9027 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9028 ret = intel_plane_atomic_check(state, plane);
9030 drm_dbg_atomic(&dev_priv->drm,
9031 "[PLANE:%d:%s] atomic driver check failed\n",
9032 plane->base.base.id, plane->base.name);
9037 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9038 new_crtc_state, i) {
9039 u8 old_active_planes, new_active_planes;
9041 ret = icl_check_nv12_planes(new_crtc_state);
9046 * On some platforms the number of active planes affects
9047 * the planes' minimum cdclk calculation. Add such planes
9048 * to the state before we compute the minimum cdclk.
9050 if (!active_planes_affects_min_cdclk(dev_priv))
9053 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
9054 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
9056 if (hweight8(old_active_planes) == hweight8(new_active_planes))
9059 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
9067 static int intel_atomic_check_cdclk(struct intel_atomic_state *state,
9068 bool *need_cdclk_calc)
9070 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9071 const struct intel_cdclk_state *old_cdclk_state;
9072 const struct intel_cdclk_state *new_cdclk_state;
9073 struct intel_plane_state *plane_state;
9074 struct intel_bw_state *new_bw_state;
9075 struct intel_plane *plane;
9081 * active_planes bitmask has been updated, and potentially
9082 * affected planes are part of the state. We can now
9083 * compute the minimum cdclk for each plane.
9085 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9086 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
9091 old_cdclk_state = intel_atomic_get_old_cdclk_state(state);
9092 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
9094 if (new_cdclk_state &&
9095 old_cdclk_state->force_min_cdclk != new_cdclk_state->force_min_cdclk)
9096 *need_cdclk_calc = true;
9098 ret = dev_priv->display.bw_calc_min_cdclk(state);
9102 new_bw_state = intel_atomic_get_new_bw_state(state);
9104 if (!new_cdclk_state || !new_bw_state)
9107 for_each_pipe(dev_priv, pipe) {
9108 min_cdclk = max(new_cdclk_state->min_cdclk[pipe], min_cdclk);
9111 * Currently do this change only if we need to increase
9113 if (new_bw_state->min_cdclk > min_cdclk)
9114 *need_cdclk_calc = true;
9120 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
9122 struct intel_crtc_state *crtc_state;
9123 struct intel_crtc *crtc;
9126 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9127 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
9130 ret = intel_crtc_atomic_check(state, crtc);
9132 drm_dbg_atomic(&i915->drm,
9133 "[CRTC:%d:%s] atomic driver check failed\n",
9134 crtc->base.base.id, crtc->base.name);
9142 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
9145 const struct intel_crtc_state *new_crtc_state;
9146 struct intel_crtc *crtc;
9149 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9150 if (new_crtc_state->hw.enable &&
9151 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
9152 intel_crtc_needs_modeset(new_crtc_state))
9159 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
9160 struct intel_crtc *crtc,
9161 struct intel_crtc_state *old_crtc_state,
9162 struct intel_crtc_state *new_crtc_state)
9164 struct intel_crtc_state *slave_crtc_state, *master_crtc_state;
9165 struct intel_crtc *slave, *master;
9167 /* slave being enabled, is master is still claiming this crtc? */
9168 if (old_crtc_state->bigjoiner_slave) {
9170 master = old_crtc_state->bigjoiner_linked_crtc;
9171 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
9172 if (!master_crtc_state || !intel_crtc_needs_modeset(master_crtc_state))
9176 if (!new_crtc_state->bigjoiner)
9179 slave = intel_dsc_get_bigjoiner_secondary(crtc);
9181 DRM_DEBUG_KMS("[CRTC:%d:%s] Big joiner configuration requires "
9182 "CRTC + 1 to be used, doesn't exist\n",
9183 crtc->base.base.id, crtc->base.name);
9187 new_crtc_state->bigjoiner_linked_crtc = slave;
9188 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave);
9190 if (IS_ERR(slave_crtc_state))
9191 return PTR_ERR(slave_crtc_state);
9193 /* master being enabled, slave was already configured? */
9194 if (slave_crtc_state->uapi.enable)
9197 DRM_DEBUG_KMS("[CRTC:%d:%s] Used as slave for big joiner\n",
9198 slave->base.base.id, slave->base.name);
9200 return copy_bigjoiner_crtc_state(slave_crtc_state, new_crtc_state);
9203 DRM_DEBUG_KMS("[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
9204 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
9205 slave->base.base.id, slave->base.name,
9206 master->base.base.id, master->base.name);
9210 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
9211 struct intel_crtc_state *master_crtc_state)
9213 struct intel_crtc_state *slave_crtc_state =
9214 intel_atomic_get_new_crtc_state(state, master_crtc_state->bigjoiner_linked_crtc);
9216 slave_crtc_state->bigjoiner = master_crtc_state->bigjoiner = false;
9217 slave_crtc_state->bigjoiner_slave = master_crtc_state->bigjoiner_slave = false;
9218 slave_crtc_state->bigjoiner_linked_crtc = master_crtc_state->bigjoiner_linked_crtc = NULL;
9219 intel_crtc_copy_uapi_to_hw_state(state, slave_crtc_state);
9223 * DOC: asynchronous flip implementation
9225 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
9226 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
9227 * Correspondingly, support is currently added for primary plane only.
9229 * Async flip can only change the plane surface address, so anything else
9230 * changing is rejected from the intel_atomic_check_async() function.
9231 * Once this check is cleared, flip done interrupt is enabled using
9232 * the intel_crtc_enable_flip_done() function.
9234 * As soon as the surface address register is written, flip done interrupt is
9235 * generated and the requested events are sent to the usersapce in the interrupt
9236 * handler itself. The timestamp and sequence sent during the flip done event
9237 * correspond to the last vblank and have no relation to the actual time when
9238 * the flip done event was sent.
9240 static int intel_atomic_check_async(struct intel_atomic_state *state)
9242 struct drm_i915_private *i915 = to_i915(state->base.dev);
9243 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9244 const struct intel_plane_state *new_plane_state, *old_plane_state;
9245 struct intel_crtc *crtc;
9246 struct intel_plane *plane;
9249 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9250 new_crtc_state, i) {
9251 if (intel_crtc_needs_modeset(new_crtc_state)) {
9252 drm_dbg_kms(&i915->drm, "Modeset Required. Async flip not supported\n");
9256 if (!new_crtc_state->hw.active) {
9257 drm_dbg_kms(&i915->drm, "CRTC inactive\n");
9260 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
9261 drm_dbg_kms(&i915->drm,
9262 "Active planes cannot be changed during async flip\n");
9267 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
9268 new_plane_state, i) {
9270 * TODO: Async flip is only supported through the page flip IOCTL
9271 * as of now. So support currently added for primary plane only.
9272 * Support for other planes on platforms on which supports
9273 * this(vlv/chv and icl+) should be added when async flip is
9274 * enabled in the atomic IOCTL path.
9276 if (!plane->async_flip)
9280 * FIXME: This check is kept generic for all platforms.
9281 * Need to verify this for all gen9 platforms to enable
9282 * this selectively if required.
9284 switch (new_plane_state->hw.fb->modifier) {
9285 case I915_FORMAT_MOD_X_TILED:
9286 case I915_FORMAT_MOD_Y_TILED:
9287 case I915_FORMAT_MOD_Yf_TILED:
9290 drm_dbg_kms(&i915->drm,
9291 "Linear memory/CCS does not support async flips\n");
9295 if (old_plane_state->view.color_plane[0].stride !=
9296 new_plane_state->view.color_plane[0].stride) {
9297 drm_dbg_kms(&i915->drm, "Stride cannot be changed in async flip\n");
9301 if (old_plane_state->hw.fb->modifier !=
9302 new_plane_state->hw.fb->modifier) {
9303 drm_dbg_kms(&i915->drm,
9304 "Framebuffer modifiers cannot be changed in async flip\n");
9308 if (old_plane_state->hw.fb->format !=
9309 new_plane_state->hw.fb->format) {
9310 drm_dbg_kms(&i915->drm,
9311 "Framebuffer format cannot be changed in async flip\n");
9315 if (old_plane_state->hw.rotation !=
9316 new_plane_state->hw.rotation) {
9317 drm_dbg_kms(&i915->drm, "Rotation cannot be changed in async flip\n");
9321 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
9322 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
9323 drm_dbg_kms(&i915->drm,
9324 "Plane size/co-ordinates cannot be changed in async flip\n");
9328 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
9329 drm_dbg_kms(&i915->drm, "Alpha value cannot be changed in async flip\n");
9333 if (old_plane_state->hw.pixel_blend_mode !=
9334 new_plane_state->hw.pixel_blend_mode) {
9335 drm_dbg_kms(&i915->drm,
9336 "Pixel blend mode cannot be changed in async flip\n");
9340 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
9341 drm_dbg_kms(&i915->drm,
9342 "Color encoding cannot be changed in async flip\n");
9346 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
9347 drm_dbg_kms(&i915->drm, "Color range cannot be changed in async flip\n");
9355 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
9357 struct intel_crtc_state *crtc_state;
9358 struct intel_crtc *crtc;
9361 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9362 struct intel_crtc_state *linked_crtc_state;
9363 struct intel_crtc *linked_crtc;
9366 if (!crtc_state->bigjoiner)
9369 linked_crtc = crtc_state->bigjoiner_linked_crtc;
9370 linked_crtc_state = intel_atomic_get_crtc_state(&state->base, linked_crtc);
9371 if (IS_ERR(linked_crtc_state))
9372 return PTR_ERR(linked_crtc_state);
9374 if (!intel_crtc_needs_modeset(crtc_state))
9377 linked_crtc_state->uapi.mode_changed = true;
9379 ret = drm_atomic_add_affected_connectors(&state->base,
9380 &linked_crtc->base);
9384 ret = intel_atomic_add_affected_planes(state, linked_crtc);
9389 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9390 /* Kill old bigjoiner link, we may re-establish afterwards */
9391 if (intel_crtc_needs_modeset(crtc_state) &&
9392 crtc_state->bigjoiner && !crtc_state->bigjoiner_slave)
9393 kill_bigjoiner_slave(state, crtc_state);
9400 * intel_atomic_check - validate state object
9402 * @_state: state to validate
9404 static int intel_atomic_check(struct drm_device *dev,
9405 struct drm_atomic_state *_state)
9407 struct drm_i915_private *dev_priv = to_i915(dev);
9408 struct intel_atomic_state *state = to_intel_atomic_state(_state);
9409 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9410 struct intel_crtc *crtc;
9412 bool any_ms = false;
9414 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9415 new_crtc_state, i) {
9416 if (new_crtc_state->inherited != old_crtc_state->inherited)
9417 new_crtc_state->uapi.mode_changed = true;
9420 intel_vrr_check_modeset(state);
9422 ret = drm_atomic_helper_check_modeset(dev, &state->base);
9426 ret = intel_bigjoiner_add_affected_crtcs(state);
9430 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9431 new_crtc_state, i) {
9432 if (!intel_crtc_needs_modeset(new_crtc_state)) {
9434 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, new_crtc_state);
9439 if (!new_crtc_state->uapi.enable) {
9440 if (!new_crtc_state->bigjoiner_slave) {
9441 intel_crtc_copy_uapi_to_hw_state(state, new_crtc_state);
9447 ret = intel_crtc_prepare_cleared_state(state, new_crtc_state);
9451 ret = intel_modeset_pipe_config(state, new_crtc_state);
9455 ret = intel_atomic_check_bigjoiner(state, crtc, old_crtc_state,
9461 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9462 new_crtc_state, i) {
9463 if (!intel_crtc_needs_modeset(new_crtc_state))
9466 ret = intel_modeset_pipe_config_late(new_crtc_state);
9470 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
9474 * Check if fastset is allowed by external dependencies like other
9475 * pipes and transcoders.
9477 * Right now it only forces a fullmodeset when the MST master
9478 * transcoder did not changed but the pipe of the master transcoder
9479 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
9480 * in case of port synced crtcs, if one of the synced crtcs
9481 * needs a full modeset, all other synced crtcs should be
9482 * forced a full modeset.
9484 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9485 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
9488 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
9489 enum transcoder master = new_crtc_state->mst_master_transcoder;
9491 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
9492 new_crtc_state->uapi.mode_changed = true;
9493 new_crtc_state->update_pipe = false;
9497 if (is_trans_port_sync_mode(new_crtc_state)) {
9498 u8 trans = new_crtc_state->sync_mode_slaves_mask;
9500 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
9501 trans |= BIT(new_crtc_state->master_transcoder);
9503 if (intel_cpu_transcoders_need_modeset(state, trans)) {
9504 new_crtc_state->uapi.mode_changed = true;
9505 new_crtc_state->update_pipe = false;
9509 if (new_crtc_state->bigjoiner) {
9510 struct intel_crtc_state *linked_crtc_state =
9511 intel_atomic_get_new_crtc_state(state, new_crtc_state->bigjoiner_linked_crtc);
9513 if (intel_crtc_needs_modeset(linked_crtc_state)) {
9514 new_crtc_state->uapi.mode_changed = true;
9515 new_crtc_state->update_pipe = false;
9520 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9521 new_crtc_state, i) {
9522 if (intel_crtc_needs_modeset(new_crtc_state)) {
9527 if (!new_crtc_state->update_pipe)
9530 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
9533 if (any_ms && !check_digital_port_conflicts(state)) {
9534 drm_dbg_kms(&dev_priv->drm,
9535 "rejecting conflicting digital port configuration\n");
9540 ret = drm_dp_mst_atomic_check(&state->base);
9544 ret = intel_atomic_check_planes(state);
9548 intel_fbc_choose_crtc(dev_priv, state);
9549 ret = calc_watermark_data(state);
9553 ret = intel_bw_atomic_check(state);
9557 ret = intel_atomic_check_cdclk(state, &any_ms);
9561 if (intel_any_crtc_needs_modeset(state))
9565 ret = intel_modeset_checks(state);
9569 ret = intel_modeset_calc_cdclk(state);
9573 intel_modeset_clear_plls(state);
9576 ret = intel_atomic_check_crtcs(state);
9580 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9581 new_crtc_state, i) {
9582 if (new_crtc_state->uapi.async_flip) {
9583 ret = intel_atomic_check_async(state);
9588 if (!intel_crtc_needs_modeset(new_crtc_state) &&
9589 !new_crtc_state->update_pipe)
9592 intel_dump_pipe_config(new_crtc_state, state,
9593 intel_crtc_needs_modeset(new_crtc_state) ?
9594 "[modeset]" : "[fastset]");
9600 if (ret == -EDEADLK)
9604 * FIXME would probably be nice to know which crtc specifically
9605 * caused the failure, in cases where we can pinpoint it.
9607 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9609 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
9614 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
9616 struct intel_crtc_state *crtc_state;
9617 struct intel_crtc *crtc;
9620 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
9624 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9625 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
9627 if (mode_changed || crtc_state->update_pipe ||
9628 crtc_state->uapi.color_mgmt_changed) {
9629 intel_dsb_prepare(crtc_state);
9636 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
9637 struct intel_crtc_state *crtc_state)
9639 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9641 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
9642 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
9644 if (crtc_state->has_pch_encoder) {
9645 enum pipe pch_transcoder =
9646 intel_crtc_pch_transcoder(crtc);
9648 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
9652 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
9653 const struct intel_crtc_state *new_crtc_state)
9655 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
9656 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9659 * Update pipe size and adjust fitter if needed: the reason for this is
9660 * that in compute_mode_changes we check the native mode (not the pfit
9661 * mode) to see if we can flip rather than do a full mode set. In the
9662 * fastboot case, we'll flip, but if we don't update the pipesrc and
9663 * pfit state, we'll end up with a big fb scanned out into the wrong
9666 intel_set_pipe_src_size(new_crtc_state);
9668 /* on skylake this is done by detaching scalers */
9669 if (DISPLAY_VER(dev_priv) >= 9) {
9670 if (new_crtc_state->pch_pfit.enabled)
9671 skl_pfit_enable(new_crtc_state);
9672 } else if (HAS_PCH_SPLIT(dev_priv)) {
9673 if (new_crtc_state->pch_pfit.enabled)
9674 ilk_pfit_enable(new_crtc_state);
9675 else if (old_crtc_state->pch_pfit.enabled)
9676 ilk_pfit_disable(old_crtc_state);
9680 * The register is supposedly single buffered so perhaps
9681 * not 100% correct to do this here. But SKL+ calculate
9682 * this based on the adjust pixel rate so pfit changes do
9683 * affect it and so it must be updated for fastsets.
9684 * HSW/BDW only really need this here for fastboot, after
9685 * that the value should not change without a full modeset.
9687 if (DISPLAY_VER(dev_priv) >= 9 ||
9688 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
9689 hsw_set_linetime_wm(new_crtc_state);
9691 if (DISPLAY_VER(dev_priv) >= 11)
9692 icl_set_pipe_chicken(new_crtc_state);
9695 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
9696 struct intel_crtc *crtc)
9698 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9699 const struct intel_crtc_state *old_crtc_state =
9700 intel_atomic_get_old_crtc_state(state, crtc);
9701 const struct intel_crtc_state *new_crtc_state =
9702 intel_atomic_get_new_crtc_state(state, crtc);
9703 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
9706 * During modesets pipe configuration was programmed as the
9710 if (new_crtc_state->uapi.color_mgmt_changed ||
9711 new_crtc_state->update_pipe)
9712 intel_color_commit(new_crtc_state);
9714 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
9715 bdw_set_pipemisc(new_crtc_state);
9717 if (new_crtc_state->update_pipe)
9718 intel_pipe_fastset(old_crtc_state, new_crtc_state);
9721 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
9723 if (dev_priv->display.atomic_update_watermarks)
9724 dev_priv->display.atomic_update_watermarks(state, crtc);
9727 static void commit_pipe_post_planes(struct intel_atomic_state *state,
9728 struct intel_crtc *crtc)
9730 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9731 const struct intel_crtc_state *new_crtc_state =
9732 intel_atomic_get_new_crtc_state(state, crtc);
9735 * Disable the scaler(s) after the plane(s) so that we don't
9736 * get a catastrophic underrun even if the two operations
9737 * end up happening in two different frames.
9739 if (DISPLAY_VER(dev_priv) >= 9 &&
9740 !intel_crtc_needs_modeset(new_crtc_state))
9741 skl_detach_scalers(new_crtc_state);
9744 static void intel_enable_crtc(struct intel_atomic_state *state,
9745 struct intel_crtc *crtc)
9747 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9748 const struct intel_crtc_state *new_crtc_state =
9749 intel_atomic_get_new_crtc_state(state, crtc);
9751 if (!intel_crtc_needs_modeset(new_crtc_state))
9754 intel_crtc_update_active_timings(new_crtc_state);
9756 dev_priv->display.crtc_enable(state, crtc);
9758 if (new_crtc_state->bigjoiner_slave)
9761 /* vblanks work again, re-enable pipe CRC. */
9762 intel_crtc_enable_pipe_crc(crtc);
9765 static void intel_update_crtc(struct intel_atomic_state *state,
9766 struct intel_crtc *crtc)
9768 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9769 const struct intel_crtc_state *old_crtc_state =
9770 intel_atomic_get_old_crtc_state(state, crtc);
9771 struct intel_crtc_state *new_crtc_state =
9772 intel_atomic_get_new_crtc_state(state, crtc);
9773 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
9776 if (new_crtc_state->preload_luts &&
9777 (new_crtc_state->uapi.color_mgmt_changed ||
9778 new_crtc_state->update_pipe))
9779 intel_color_load_luts(new_crtc_state);
9781 intel_pre_plane_update(state, crtc);
9783 if (new_crtc_state->update_pipe)
9784 intel_encoders_update_pipe(state, crtc);
9787 intel_fbc_update(state, crtc);
9789 /* Perform vblank evasion around commit operation */
9790 intel_pipe_update_start(new_crtc_state);
9792 commit_pipe_pre_planes(state, crtc);
9794 if (DISPLAY_VER(dev_priv) >= 9)
9795 skl_update_planes_on_crtc(state, crtc);
9797 i9xx_update_planes_on_crtc(state, crtc);
9799 commit_pipe_post_planes(state, crtc);
9801 intel_pipe_update_end(new_crtc_state);
9804 * We usually enable FIFO underrun interrupts as part of the
9805 * CRTC enable sequence during modesets. But when we inherit a
9806 * valid pipe configuration from the BIOS we need to take care
9807 * of enabling them on the CRTC's first fastset.
9809 if (new_crtc_state->update_pipe && !modeset &&
9810 old_crtc_state->inherited)
9811 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
9814 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
9815 struct intel_crtc_state *old_crtc_state,
9816 struct intel_crtc_state *new_crtc_state,
9817 struct intel_crtc *crtc)
9819 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9821 drm_WARN_ON(&dev_priv->drm, old_crtc_state->bigjoiner_slave);
9823 intel_encoders_pre_disable(state, crtc);
9825 intel_crtc_disable_planes(state, crtc);
9828 * We still need special handling for disabling bigjoiner master
9829 * and slaves since for slave we do not have encoder or plls
9830 * so we dont need to disable those.
9832 if (old_crtc_state->bigjoiner) {
9833 intel_crtc_disable_planes(state,
9834 old_crtc_state->bigjoiner_linked_crtc);
9835 old_crtc_state->bigjoiner_linked_crtc->active = false;
9839 * We need to disable pipe CRC before disabling the pipe,
9840 * or we race against vblank off.
9842 intel_crtc_disable_pipe_crc(crtc);
9844 dev_priv->display.crtc_disable(state, crtc);
9845 crtc->active = false;
9846 intel_fbc_disable(crtc);
9847 intel_disable_shared_dpll(old_crtc_state);
9849 /* FIXME unify this for all platforms */
9850 if (!new_crtc_state->hw.active &&
9851 !HAS_GMCH(dev_priv) &&
9852 dev_priv->display.initial_watermarks)
9853 dev_priv->display.initial_watermarks(state, crtc);
9856 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
9858 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
9859 struct intel_crtc *crtc;
9863 /* Only disable port sync and MST slaves */
9864 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9865 new_crtc_state, i) {
9866 if (!intel_crtc_needs_modeset(new_crtc_state) || old_crtc_state->bigjoiner)
9869 if (!old_crtc_state->hw.active)
9872 /* In case of Transcoder port Sync master slave CRTCs can be
9873 * assigned in any order and we need to make sure that
9874 * slave CRTCs are disabled first and then master CRTC since
9875 * Slave vblanks are masked till Master Vblanks.
9877 if (!is_trans_port_sync_slave(old_crtc_state) &&
9878 !intel_dp_mst_is_slave_trans(old_crtc_state))
9881 intel_pre_plane_update(state, crtc);
9882 intel_old_crtc_state_disables(state, old_crtc_state,
9883 new_crtc_state, crtc);
9884 handled |= BIT(crtc->pipe);
9887 /* Disable everything else left on */
9888 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9889 new_crtc_state, i) {
9890 if (!intel_crtc_needs_modeset(new_crtc_state) ||
9891 (handled & BIT(crtc->pipe)) ||
9892 old_crtc_state->bigjoiner_slave)
9895 intel_pre_plane_update(state, crtc);
9896 if (old_crtc_state->bigjoiner) {
9897 struct intel_crtc *slave =
9898 old_crtc_state->bigjoiner_linked_crtc;
9900 intel_pre_plane_update(state, slave);
9903 if (old_crtc_state->hw.active)
9904 intel_old_crtc_state_disables(state, old_crtc_state,
9905 new_crtc_state, crtc);
9909 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
9911 struct intel_crtc_state *new_crtc_state;
9912 struct intel_crtc *crtc;
9915 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9916 if (!new_crtc_state->hw.active)
9919 intel_enable_crtc(state, crtc);
9920 intel_update_crtc(state, crtc);
9924 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
9926 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9927 struct intel_crtc *crtc;
9928 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9929 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
9930 u8 update_pipes = 0, modeset_pipes = 0;
9933 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
9934 enum pipe pipe = crtc->pipe;
9936 if (!new_crtc_state->hw.active)
9939 /* ignore allocations for crtc's that have been turned off. */
9940 if (!intel_crtc_needs_modeset(new_crtc_state)) {
9941 entries[pipe] = old_crtc_state->wm.skl.ddb;
9942 update_pipes |= BIT(pipe);
9944 modeset_pipes |= BIT(pipe);
9949 * Whenever the number of active pipes changes, we need to make sure we
9950 * update the pipes in the right order so that their ddb allocations
9951 * never overlap with each other between CRTC updates. Otherwise we'll
9952 * cause pipe underruns and other bad stuff.
9954 * So first lets enable all pipes that do not need a fullmodeset as
9955 * those don't have any external dependency.
9957 while (update_pipes) {
9958 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9959 new_crtc_state, i) {
9960 enum pipe pipe = crtc->pipe;
9962 if ((update_pipes & BIT(pipe)) == 0)
9965 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
9966 entries, I915_MAX_PIPES, pipe))
9969 entries[pipe] = new_crtc_state->wm.skl.ddb;
9970 update_pipes &= ~BIT(pipe);
9972 intel_update_crtc(state, crtc);
9975 * If this is an already active pipe, it's DDB changed,
9976 * and this isn't the last pipe that needs updating
9977 * then we need to wait for a vblank to pass for the
9978 * new ddb allocation to take effect.
9980 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
9981 &old_crtc_state->wm.skl.ddb) &&
9982 (update_pipes | modeset_pipes))
9983 intel_wait_for_vblank(dev_priv, pipe);
9987 update_pipes = modeset_pipes;
9990 * Enable all pipes that needs a modeset and do not depends on other
9993 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9994 enum pipe pipe = crtc->pipe;
9996 if ((modeset_pipes & BIT(pipe)) == 0)
9999 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
10000 is_trans_port_sync_master(new_crtc_state) ||
10001 (new_crtc_state->bigjoiner && !new_crtc_state->bigjoiner_slave))
10004 modeset_pipes &= ~BIT(pipe);
10006 intel_enable_crtc(state, crtc);
10010 * Then we enable all remaining pipes that depend on other
10011 * pipes: MST slaves and port sync masters, big joiner master
10013 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10014 enum pipe pipe = crtc->pipe;
10016 if ((modeset_pipes & BIT(pipe)) == 0)
10019 modeset_pipes &= ~BIT(pipe);
10021 intel_enable_crtc(state, crtc);
10025 * Finally we do the plane updates/etc. for all pipes that got enabled.
10027 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10028 enum pipe pipe = crtc->pipe;
10030 if ((update_pipes & BIT(pipe)) == 0)
10033 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
10034 entries, I915_MAX_PIPES, pipe));
10036 entries[pipe] = new_crtc_state->wm.skl.ddb;
10037 update_pipes &= ~BIT(pipe);
10039 intel_update_crtc(state, crtc);
10042 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
10043 drm_WARN_ON(&dev_priv->drm, update_pipes);
10046 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
10048 struct intel_atomic_state *state, *next;
10049 struct llist_node *freed;
10051 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
10052 llist_for_each_entry_safe(state, next, freed, freed)
10053 drm_atomic_state_put(&state->base);
10056 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
10058 struct drm_i915_private *dev_priv =
10059 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
10061 intel_atomic_helper_free_state(dev_priv);
10064 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
10066 struct wait_queue_entry wait_fence, wait_reset;
10067 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
10069 init_wait_entry(&wait_fence, 0);
10070 init_wait_entry(&wait_reset, 0);
10072 prepare_to_wait(&intel_state->commit_ready.wait,
10073 &wait_fence, TASK_UNINTERRUPTIBLE);
10074 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
10075 I915_RESET_MODESET),
10076 &wait_reset, TASK_UNINTERRUPTIBLE);
10079 if (i915_sw_fence_done(&intel_state->commit_ready) ||
10080 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
10085 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
10086 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
10087 I915_RESET_MODESET),
10091 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
10093 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
10094 struct intel_crtc *crtc;
10097 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10099 intel_dsb_cleanup(old_crtc_state);
10102 static void intel_atomic_cleanup_work(struct work_struct *work)
10104 struct intel_atomic_state *state =
10105 container_of(work, struct intel_atomic_state, base.commit_work);
10106 struct drm_i915_private *i915 = to_i915(state->base.dev);
10108 intel_cleanup_dsbs(state);
10109 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
10110 drm_atomic_helper_commit_cleanup_done(&state->base);
10111 drm_atomic_state_put(&state->base);
10113 intel_atomic_helper_free_state(i915);
10116 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
10118 struct drm_i915_private *i915 = to_i915(state->base.dev);
10119 struct intel_plane *plane;
10120 struct intel_plane_state *plane_state;
10123 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10124 struct drm_framebuffer *fb = plane_state->hw.fb;
10128 fb->modifier != I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC)
10132 * The layout of the fast clear color value expected by HW
10133 * (the DRM ABI requiring this value to be located in fb at offset 0 of plane#2):
10134 * - 4 x 4 bytes per-channel value
10135 * (in surface type specific float/int format provided by the fb user)
10136 * - 8 bytes native color value used by the display
10137 * (converted/written by GPU during a fast clear operation using the
10138 * above per-channel values)
10140 * The commit's FB prepare hook already ensured that FB obj is pinned and the
10141 * caller made sure that the object is synced wrt. the related color clear value
10144 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
10145 fb->offsets[2] + 16,
10146 &plane_state->ccval,
10147 sizeof(plane_state->ccval));
10148 /* The above could only fail if the FB obj has an unexpected backing store type. */
10149 drm_WARN_ON(&i915->drm, ret);
10153 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
10155 struct drm_device *dev = state->base.dev;
10156 struct drm_i915_private *dev_priv = to_i915(dev);
10157 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
10158 struct intel_crtc *crtc;
10159 u64 put_domains[I915_MAX_PIPES] = {};
10160 intel_wakeref_t wakeref = 0;
10163 intel_atomic_commit_fence_wait(state);
10165 drm_atomic_helper_wait_for_dependencies(&state->base);
10167 if (state->modeset)
10168 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
10170 intel_atomic_prepare_plane_clear_colors(state);
10172 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10173 new_crtc_state, i) {
10174 if (intel_crtc_needs_modeset(new_crtc_state) ||
10175 new_crtc_state->update_pipe) {
10177 put_domains[crtc->pipe] =
10178 modeset_get_crtc_power_domains(new_crtc_state);
10182 intel_commit_modeset_disables(state);
10184 /* FIXME: Eventually get rid of our crtc->config pointer */
10185 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10186 crtc->config = new_crtc_state;
10188 if (state->modeset) {
10189 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
10191 intel_set_cdclk_pre_plane_update(state);
10193 intel_modeset_verify_disabled(dev_priv, state);
10196 intel_sagv_pre_plane_update(state);
10198 /* Complete the events for pipes that have now been disabled */
10199 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10200 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
10202 /* Complete events for now disable pipes here. */
10203 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
10204 spin_lock_irq(&dev->event_lock);
10205 drm_crtc_send_vblank_event(&crtc->base,
10206 new_crtc_state->uapi.event);
10207 spin_unlock_irq(&dev->event_lock);
10209 new_crtc_state->uapi.event = NULL;
10213 if (state->modeset)
10214 intel_encoders_update_prepare(state);
10216 intel_dbuf_pre_plane_update(state);
10217 intel_psr_pre_plane_update(state);
10219 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10220 if (new_crtc_state->uapi.async_flip)
10221 intel_crtc_enable_flip_done(state, crtc);
10224 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10225 dev_priv->display.commit_modeset_enables(state);
10227 if (state->modeset) {
10228 intel_encoders_update_complete(state);
10230 intel_set_cdclk_post_plane_update(state);
10233 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
10234 * already, but still need the state for the delayed optimization. To
10236 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
10237 * - schedule that vblank worker _before_ calling hw_done
10238 * - at the start of commit_tail, cancel it _synchrously
10239 * - switch over to the vblank wait helper in the core after that since
10240 * we don't need out special handling any more.
10242 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
10244 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10245 if (new_crtc_state->uapi.async_flip)
10246 intel_crtc_disable_flip_done(state, crtc);
10248 if (new_crtc_state->hw.active &&
10249 !intel_crtc_needs_modeset(new_crtc_state) &&
10250 !new_crtc_state->preload_luts &&
10251 (new_crtc_state->uapi.color_mgmt_changed ||
10252 new_crtc_state->update_pipe))
10253 intel_color_load_luts(new_crtc_state);
10257 * Now that the vblank has passed, we can go ahead and program the
10258 * optimal watermarks on platforms that need two-step watermark
10261 * TODO: Move this (and other cleanup) to an async worker eventually.
10263 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10264 new_crtc_state, i) {
10266 * Gen2 reports pipe underruns whenever all planes are disabled.
10267 * So re-enable underrun reporting after some planes get enabled.
10269 * We do this before .optimize_watermarks() so that we have a
10270 * chance of catching underruns with the intermediate watermarks
10271 * vs. the new plane configuration.
10273 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
10274 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
10276 if (dev_priv->display.optimize_watermarks)
10277 dev_priv->display.optimize_watermarks(state, crtc);
10280 intel_dbuf_post_plane_update(state);
10281 intel_psr_post_plane_update(state);
10283 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10284 intel_post_plane_update(state, crtc);
10286 modeset_put_crtc_power_domains(crtc, put_domains[crtc->pipe]);
10288 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
10291 * DSB cleanup is done in cleanup_work aligning with framebuffer
10292 * cleanup. So copy and reset the dsb structure to sync with
10293 * commit_done and later do dsb cleanup in cleanup_work.
10295 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
10298 /* Underruns don't always raise interrupts, so check manually */
10299 intel_check_cpu_fifo_underruns(dev_priv);
10300 intel_check_pch_fifo_underruns(dev_priv);
10302 if (state->modeset)
10303 intel_verify_planes(state);
10305 intel_sagv_post_plane_update(state);
10307 drm_atomic_helper_commit_hw_done(&state->base);
10309 if (state->modeset) {
10310 /* As one of the primary mmio accessors, KMS has a high
10311 * likelihood of triggering bugs in unclaimed access. After we
10312 * finish modesetting, see if an error has been flagged, and if
10313 * so enable debugging for the next modeset - and hope we catch
10316 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
10317 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
10319 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10322 * Defer the cleanup of the old state to a separate worker to not
10323 * impede the current task (userspace for blocking modesets) that
10324 * are executed inline. For out-of-line asynchronous modesets/flips,
10325 * deferring to a new worker seems overkill, but we would place a
10326 * schedule point (cond_resched()) here anyway to keep latencies
10329 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
10330 queue_work(system_highpri_wq, &state->base.commit_work);
10333 static void intel_atomic_commit_work(struct work_struct *work)
10335 struct intel_atomic_state *state =
10336 container_of(work, struct intel_atomic_state, base.commit_work);
10338 intel_atomic_commit_tail(state);
10341 static int __i915_sw_fence_call
10342 intel_atomic_commit_ready(struct i915_sw_fence *fence,
10343 enum i915_sw_fence_notify notify)
10345 struct intel_atomic_state *state =
10346 container_of(fence, struct intel_atomic_state, commit_ready);
10349 case FENCE_COMPLETE:
10350 /* we do blocking waits in the worker, nothing to do here */
10354 struct intel_atomic_helper *helper =
10355 &to_i915(state->base.dev)->atomic_helper;
10357 if (llist_add(&state->freed, &helper->free_list))
10358 schedule_work(&helper->free_work);
10363 return NOTIFY_DONE;
10366 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
10368 struct intel_plane_state *old_plane_state, *new_plane_state;
10369 struct intel_plane *plane;
10372 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
10373 new_plane_state, i)
10374 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
10375 to_intel_frontbuffer(new_plane_state->hw.fb),
10376 plane->frontbuffer_bit);
10379 static int intel_atomic_commit(struct drm_device *dev,
10380 struct drm_atomic_state *_state,
10383 struct intel_atomic_state *state = to_intel_atomic_state(_state);
10384 struct drm_i915_private *dev_priv = to_i915(dev);
10387 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
10389 drm_atomic_state_get(&state->base);
10390 i915_sw_fence_init(&state->commit_ready,
10391 intel_atomic_commit_ready);
10394 * The intel_legacy_cursor_update() fast path takes care
10395 * of avoiding the vblank waits for simple cursor
10396 * movement and flips. For cursor on/off and size changes,
10397 * we want to perform the vblank waits so that watermark
10398 * updates happen during the correct frames. Gen9+ have
10399 * double buffered watermarks and so shouldn't need this.
10401 * Unset state->legacy_cursor_update before the call to
10402 * drm_atomic_helper_setup_commit() because otherwise
10403 * drm_atomic_helper_wait_for_flip_done() is a noop and
10404 * we get FIFO underruns because we didn't wait
10407 * FIXME doing watermarks and fb cleanup from a vblank worker
10408 * (assuming we had any) would solve these problems.
10410 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
10411 struct intel_crtc_state *new_crtc_state;
10412 struct intel_crtc *crtc;
10415 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10416 if (new_crtc_state->wm.need_postvbl_update ||
10417 new_crtc_state->update_wm_post)
10418 state->base.legacy_cursor_update = false;
10421 ret = intel_atomic_prepare_commit(state);
10423 drm_dbg_atomic(&dev_priv->drm,
10424 "Preparing state failed with %i\n", ret);
10425 i915_sw_fence_commit(&state->commit_ready);
10426 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10430 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
10432 ret = drm_atomic_helper_swap_state(&state->base, true);
10434 intel_atomic_swap_global_state(state);
10437 struct intel_crtc_state *new_crtc_state;
10438 struct intel_crtc *crtc;
10441 i915_sw_fence_commit(&state->commit_ready);
10443 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10444 intel_dsb_cleanup(new_crtc_state);
10446 drm_atomic_helper_cleanup_planes(dev, &state->base);
10447 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10450 intel_shared_dpll_swap_state(state);
10451 intel_atomic_track_fbs(state);
10453 drm_atomic_state_get(&state->base);
10454 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
10456 i915_sw_fence_commit(&state->commit_ready);
10457 if (nonblock && state->modeset) {
10458 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
10459 } else if (nonblock) {
10460 queue_work(dev_priv->flip_wq, &state->base.commit_work);
10462 if (state->modeset)
10463 flush_workqueue(dev_priv->modeset_wq);
10464 intel_atomic_commit_tail(state);
10470 struct wait_rps_boost {
10471 struct wait_queue_entry wait;
10473 struct drm_crtc *crtc;
10474 struct i915_request *request;
10477 static int do_rps_boost(struct wait_queue_entry *_wait,
10478 unsigned mode, int sync, void *key)
10480 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
10481 struct i915_request *rq = wait->request;
10484 * If we missed the vblank, but the request is already running it
10485 * is reasonable to assume that it will complete before the next
10486 * vblank without our intervention, so leave RPS alone.
10488 if (!i915_request_started(rq))
10489 intel_rps_boost(rq);
10490 i915_request_put(rq);
10492 drm_crtc_vblank_put(wait->crtc);
10494 list_del(&wait->wait.entry);
10499 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
10500 struct dma_fence *fence)
10502 struct wait_rps_boost *wait;
10504 if (!dma_fence_is_i915(fence))
10507 if (DISPLAY_VER(to_i915(crtc->dev)) < 6)
10510 if (drm_crtc_vblank_get(crtc))
10513 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
10515 drm_crtc_vblank_put(crtc);
10519 wait->request = to_request(dma_fence_get(fence));
10522 wait->wait.func = do_rps_boost;
10523 wait->wait.flags = 0;
10525 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
10528 int intel_plane_pin_fb(struct intel_plane_state *plane_state)
10530 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
10531 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10532 struct drm_framebuffer *fb = plane_state->hw.fb;
10533 struct i915_vma *vma;
10535 plane->id == PLANE_CURSOR &&
10536 INTEL_INFO(dev_priv)->display.cursor_needs_physical;
10538 if (!intel_fb_uses_dpt(fb)) {
10539 vma = intel_pin_and_fence_fb_obj(fb, phys_cursor,
10540 &plane_state->view.gtt,
10541 intel_plane_uses_fence(plane_state),
10542 &plane_state->flags);
10544 return PTR_ERR(vma);
10546 plane_state->ggtt_vma = vma;
10548 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
10550 vma = intel_dpt_pin(intel_fb->dpt_vm);
10552 return PTR_ERR(vma);
10554 plane_state->ggtt_vma = vma;
10556 vma = intel_pin_fb_obj_dpt(fb, &plane_state->view.gtt, false,
10557 &plane_state->flags, intel_fb->dpt_vm);
10559 intel_dpt_unpin(intel_fb->dpt_vm);
10560 plane_state->ggtt_vma = NULL;
10561 return PTR_ERR(vma);
10564 plane_state->dpt_vma = vma;
10566 WARN_ON(plane_state->ggtt_vma == plane_state->dpt_vma);
10572 void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
10574 struct drm_framebuffer *fb = old_plane_state->hw.fb;
10575 struct i915_vma *vma;
10577 if (!intel_fb_uses_dpt(fb)) {
10578 vma = fetch_and_zero(&old_plane_state->ggtt_vma);
10580 intel_unpin_fb_vma(vma, old_plane_state->flags);
10582 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
10584 vma = fetch_and_zero(&old_plane_state->dpt_vma);
10586 intel_unpin_fb_vma(vma, old_plane_state->flags);
10588 vma = fetch_and_zero(&old_plane_state->ggtt_vma);
10590 intel_dpt_unpin(intel_fb->dpt_vm);
10595 * intel_prepare_plane_fb - Prepare fb for usage on plane
10596 * @_plane: drm plane to prepare for
10597 * @_new_plane_state: the plane state being prepared
10599 * Prepares a framebuffer for usage on a display plane. Generally this
10600 * involves pinning the underlying object and updating the frontbuffer tracking
10601 * bits. Some older platforms need special physical address handling for
10604 * Returns 0 on success, negative error code on failure.
10607 intel_prepare_plane_fb(struct drm_plane *_plane,
10608 struct drm_plane_state *_new_plane_state)
10610 struct i915_sched_attr attr = { .priority = I915_PRIORITY_DISPLAY };
10611 struct intel_plane *plane = to_intel_plane(_plane);
10612 struct intel_plane_state *new_plane_state =
10613 to_intel_plane_state(_new_plane_state);
10614 struct intel_atomic_state *state =
10615 to_intel_atomic_state(new_plane_state->uapi.state);
10616 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10617 const struct intel_plane_state *old_plane_state =
10618 intel_atomic_get_old_plane_state(state, plane);
10619 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
10620 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
10624 const struct intel_crtc_state *crtc_state =
10625 intel_atomic_get_new_crtc_state(state,
10626 to_intel_crtc(old_plane_state->hw.crtc));
10628 /* Big Hammer, we also need to ensure that any pending
10629 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
10630 * current scanout is retired before unpinning the old
10631 * framebuffer. Note that we rely on userspace rendering
10632 * into the buffer attached to the pipe they are waiting
10633 * on. If not, userspace generates a GPU hang with IPEHR
10634 * point to the MI_WAIT_FOR_EVENT.
10636 * This should only fail upon a hung GPU, in which case we
10637 * can safely continue.
10639 if (intel_crtc_needs_modeset(crtc_state)) {
10640 ret = i915_sw_fence_await_reservation(&state->commit_ready,
10641 old_obj->base.resv, NULL,
10649 if (new_plane_state->uapi.fence) { /* explicit fencing */
10650 i915_gem_fence_wait_priority(new_plane_state->uapi.fence,
10652 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
10653 new_plane_state->uapi.fence,
10654 i915_fence_timeout(dev_priv),
10664 ret = intel_plane_pin_fb(new_plane_state);
10668 i915_gem_object_wait_priority(obj, 0, &attr);
10669 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
10671 if (!new_plane_state->uapi.fence) { /* implicit fencing */
10672 struct dma_fence *fence;
10674 ret = i915_sw_fence_await_reservation(&state->commit_ready,
10675 obj->base.resv, NULL,
10677 i915_fence_timeout(dev_priv),
10682 fence = dma_resv_get_excl_unlocked(obj->base.resv);
10684 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
10686 dma_fence_put(fence);
10689 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
10690 new_plane_state->uapi.fence);
10694 * We declare pageflips to be interactive and so merit a small bias
10695 * towards upclocking to deliver the frame on time. By only changing
10696 * the RPS thresholds to sample more regularly and aim for higher
10697 * clocks we can hopefully deliver low power workloads (like kodi)
10698 * that are not quite steady state without resorting to forcing
10699 * maximum clocks following a vblank miss (see do_rps_boost()).
10701 if (!state->rps_interactive) {
10702 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
10703 state->rps_interactive = true;
10709 intel_plane_unpin_fb(new_plane_state);
10715 * intel_cleanup_plane_fb - Cleans up an fb after plane use
10716 * @plane: drm plane to clean up for
10717 * @_old_plane_state: the state from the previous modeset
10719 * Cleans up a framebuffer that has just been removed from a plane.
10722 intel_cleanup_plane_fb(struct drm_plane *plane,
10723 struct drm_plane_state *_old_plane_state)
10725 struct intel_plane_state *old_plane_state =
10726 to_intel_plane_state(_old_plane_state);
10727 struct intel_atomic_state *state =
10728 to_intel_atomic_state(old_plane_state->uapi.state);
10729 struct drm_i915_private *dev_priv = to_i915(plane->dev);
10730 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
10735 if (state->rps_interactive) {
10736 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
10737 state->rps_interactive = false;
10740 /* Should only be called after a successful intel_prepare_plane_fb()! */
10741 intel_plane_unpin_fb(old_plane_state);
10745 * intel_plane_destroy - destroy a plane
10746 * @plane: plane to destroy
10748 * Common destruction function for all types of planes (primary, cursor,
10751 void intel_plane_destroy(struct drm_plane *plane)
10753 drm_plane_cleanup(plane);
10754 kfree(to_intel_plane(plane));
10757 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
10759 struct intel_plane *plane;
10761 for_each_intel_plane(&dev_priv->drm, plane) {
10762 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
10765 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
10770 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
10771 struct drm_file *file)
10773 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
10774 struct drm_crtc *drmmode_crtc;
10775 struct intel_crtc *crtc;
10777 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
10781 crtc = to_intel_crtc(drmmode_crtc);
10782 pipe_from_crtc_id->pipe = crtc->pipe;
10787 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
10789 struct drm_device *dev = encoder->base.dev;
10790 struct intel_encoder *source_encoder;
10791 u32 possible_clones = 0;
10793 for_each_intel_encoder(dev, source_encoder) {
10794 if (encoders_cloneable(encoder, source_encoder))
10795 possible_clones |= drm_encoder_mask(&source_encoder->base);
10798 return possible_clones;
10801 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
10803 struct drm_device *dev = encoder->base.dev;
10804 struct intel_crtc *crtc;
10805 u32 possible_crtcs = 0;
10807 for_each_intel_crtc(dev, crtc) {
10808 if (encoder->pipe_mask & BIT(crtc->pipe))
10809 possible_crtcs |= drm_crtc_mask(&crtc->base);
10812 return possible_crtcs;
10815 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
10817 if (!IS_MOBILE(dev_priv))
10820 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
10823 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
10829 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
10831 if (DISPLAY_VER(dev_priv) >= 9)
10834 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
10837 if (HAS_PCH_LPT_H(dev_priv) &&
10838 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
10841 /* DDI E can't be used if DDI A requires 4 lanes */
10842 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
10845 if (!dev_priv->vbt.int_crt_support)
10851 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
10853 struct intel_encoder *encoder;
10854 bool dpd_is_edp = false;
10856 intel_pps_unlock_regs_wa(dev_priv);
10858 if (!HAS_DISPLAY(dev_priv))
10861 if (IS_DG2(dev_priv)) {
10862 intel_ddi_init(dev_priv, PORT_A);
10863 intel_ddi_init(dev_priv, PORT_B);
10864 intel_ddi_init(dev_priv, PORT_C);
10865 intel_ddi_init(dev_priv, PORT_D_XELPD);
10866 } else if (IS_ALDERLAKE_P(dev_priv)) {
10867 intel_ddi_init(dev_priv, PORT_A);
10868 intel_ddi_init(dev_priv, PORT_B);
10869 intel_ddi_init(dev_priv, PORT_TC1);
10870 intel_ddi_init(dev_priv, PORT_TC2);
10871 intel_ddi_init(dev_priv, PORT_TC3);
10872 intel_ddi_init(dev_priv, PORT_TC4);
10873 icl_dsi_init(dev_priv);
10874 } else if (IS_ALDERLAKE_S(dev_priv)) {
10875 intel_ddi_init(dev_priv, PORT_A);
10876 intel_ddi_init(dev_priv, PORT_TC1);
10877 intel_ddi_init(dev_priv, PORT_TC2);
10878 intel_ddi_init(dev_priv, PORT_TC3);
10879 intel_ddi_init(dev_priv, PORT_TC4);
10880 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
10881 intel_ddi_init(dev_priv, PORT_A);
10882 intel_ddi_init(dev_priv, PORT_B);
10883 intel_ddi_init(dev_priv, PORT_TC1);
10884 intel_ddi_init(dev_priv, PORT_TC2);
10885 } else if (DISPLAY_VER(dev_priv) >= 12) {
10886 intel_ddi_init(dev_priv, PORT_A);
10887 intel_ddi_init(dev_priv, PORT_B);
10888 intel_ddi_init(dev_priv, PORT_TC1);
10889 intel_ddi_init(dev_priv, PORT_TC2);
10890 intel_ddi_init(dev_priv, PORT_TC3);
10891 intel_ddi_init(dev_priv, PORT_TC4);
10892 intel_ddi_init(dev_priv, PORT_TC5);
10893 intel_ddi_init(dev_priv, PORT_TC6);
10894 icl_dsi_init(dev_priv);
10895 } else if (IS_JSL_EHL(dev_priv)) {
10896 intel_ddi_init(dev_priv, PORT_A);
10897 intel_ddi_init(dev_priv, PORT_B);
10898 intel_ddi_init(dev_priv, PORT_C);
10899 intel_ddi_init(dev_priv, PORT_D);
10900 icl_dsi_init(dev_priv);
10901 } else if (DISPLAY_VER(dev_priv) == 11) {
10902 intel_ddi_init(dev_priv, PORT_A);
10903 intel_ddi_init(dev_priv, PORT_B);
10904 intel_ddi_init(dev_priv, PORT_C);
10905 intel_ddi_init(dev_priv, PORT_D);
10906 intel_ddi_init(dev_priv, PORT_E);
10907 intel_ddi_init(dev_priv, PORT_F);
10908 icl_dsi_init(dev_priv);
10909 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
10910 intel_ddi_init(dev_priv, PORT_A);
10911 intel_ddi_init(dev_priv, PORT_B);
10912 intel_ddi_init(dev_priv, PORT_C);
10913 vlv_dsi_init(dev_priv);
10914 } else if (DISPLAY_VER(dev_priv) >= 9) {
10915 intel_ddi_init(dev_priv, PORT_A);
10916 intel_ddi_init(dev_priv, PORT_B);
10917 intel_ddi_init(dev_priv, PORT_C);
10918 intel_ddi_init(dev_priv, PORT_D);
10919 intel_ddi_init(dev_priv, PORT_E);
10920 } else if (HAS_DDI(dev_priv)) {
10923 if (intel_ddi_crt_present(dev_priv))
10924 intel_crt_init(dev_priv);
10926 /* Haswell uses DDI functions to detect digital outputs. */
10927 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
10929 intel_ddi_init(dev_priv, PORT_A);
10931 found = intel_de_read(dev_priv, SFUSE_STRAP);
10932 if (found & SFUSE_STRAP_DDIB_DETECTED)
10933 intel_ddi_init(dev_priv, PORT_B);
10934 if (found & SFUSE_STRAP_DDIC_DETECTED)
10935 intel_ddi_init(dev_priv, PORT_C);
10936 if (found & SFUSE_STRAP_DDID_DETECTED)
10937 intel_ddi_init(dev_priv, PORT_D);
10938 if (found & SFUSE_STRAP_DDIF_DETECTED)
10939 intel_ddi_init(dev_priv, PORT_F);
10940 } else if (HAS_PCH_SPLIT(dev_priv)) {
10944 * intel_edp_init_connector() depends on this completing first,
10945 * to prevent the registration of both eDP and LVDS and the
10946 * incorrect sharing of the PPS.
10948 intel_lvds_init(dev_priv);
10949 intel_crt_init(dev_priv);
10951 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
10953 if (ilk_has_edp_a(dev_priv))
10954 g4x_dp_init(dev_priv, DP_A, PORT_A);
10956 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
10957 /* PCH SDVOB multiplex with HDMIB */
10958 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
10960 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
10961 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
10962 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
10965 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
10966 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
10968 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
10969 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
10971 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
10972 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
10974 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
10975 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
10976 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
10977 bool has_edp, has_port;
10979 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
10980 intel_crt_init(dev_priv);
10983 * The DP_DETECTED bit is the latched state of the DDC
10984 * SDA pin at boot. However since eDP doesn't require DDC
10985 * (no way to plug in a DP->HDMI dongle) the DDC pins for
10986 * eDP ports may have been muxed to an alternate function.
10987 * Thus we can't rely on the DP_DETECTED bit alone to detect
10988 * eDP ports. Consult the VBT as well as DP_DETECTED to
10989 * detect eDP ports.
10991 * Sadly the straps seem to be missing sometimes even for HDMI
10992 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
10993 * and VBT for the presence of the port. Additionally we can't
10994 * trust the port type the VBT declares as we've seen at least
10995 * HDMI ports that the VBT claim are DP or eDP.
10997 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
10998 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
10999 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
11000 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
11001 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
11002 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
11004 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
11005 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
11006 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
11007 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
11008 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
11009 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
11011 if (IS_CHERRYVIEW(dev_priv)) {
11013 * eDP not supported on port D,
11014 * so no need to worry about it
11016 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
11017 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
11018 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
11019 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
11020 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
11023 vlv_dsi_init(dev_priv);
11024 } else if (IS_PINEVIEW(dev_priv)) {
11025 intel_lvds_init(dev_priv);
11026 intel_crt_init(dev_priv);
11027 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
11028 bool found = false;
11030 if (IS_MOBILE(dev_priv))
11031 intel_lvds_init(dev_priv);
11033 intel_crt_init(dev_priv);
11035 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
11036 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
11037 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
11038 if (!found && IS_G4X(dev_priv)) {
11039 drm_dbg_kms(&dev_priv->drm,
11040 "probing HDMI on SDVOB\n");
11041 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
11044 if (!found && IS_G4X(dev_priv))
11045 g4x_dp_init(dev_priv, DP_B, PORT_B);
11048 /* Before G4X SDVOC doesn't have its own detect register */
11050 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
11051 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
11052 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
11055 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
11057 if (IS_G4X(dev_priv)) {
11058 drm_dbg_kms(&dev_priv->drm,
11059 "probing HDMI on SDVOC\n");
11060 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
11062 if (IS_G4X(dev_priv))
11063 g4x_dp_init(dev_priv, DP_C, PORT_C);
11066 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
11067 g4x_dp_init(dev_priv, DP_D, PORT_D);
11069 if (SUPPORTS_TV(dev_priv))
11070 intel_tv_init(dev_priv);
11071 } else if (DISPLAY_VER(dev_priv) == 2) {
11072 if (IS_I85X(dev_priv))
11073 intel_lvds_init(dev_priv);
11075 intel_crt_init(dev_priv);
11076 intel_dvo_init(dev_priv);
11079 for_each_intel_encoder(&dev_priv->drm, encoder) {
11080 encoder->base.possible_crtcs =
11081 intel_encoder_possible_crtcs(encoder);
11082 encoder->base.possible_clones =
11083 intel_encoder_possible_clones(encoder);
11086 intel_init_pch_refclk(dev_priv);
11088 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
11091 static enum drm_mode_status
11092 intel_mode_valid(struct drm_device *dev,
11093 const struct drm_display_mode *mode)
11095 struct drm_i915_private *dev_priv = to_i915(dev);
11096 int hdisplay_max, htotal_max;
11097 int vdisplay_max, vtotal_max;
11100 * Can't reject DBLSCAN here because Xorg ddxen can add piles
11101 * of DBLSCAN modes to the output's mode list when they detect
11102 * the scaling mode property on the connector. And they don't
11103 * ask the kernel to validate those modes in any way until
11104 * modeset time at which point the client gets a protocol error.
11105 * So in order to not upset those clients we silently ignore the
11106 * DBLSCAN flag on such connectors. For other connectors we will
11107 * reject modes with the DBLSCAN flag in encoder->compute_config().
11108 * And we always reject DBLSCAN modes in connector->mode_valid()
11109 * as we never want such modes on the connector's mode list.
11112 if (mode->vscan > 1)
11113 return MODE_NO_VSCAN;
11115 if (mode->flags & DRM_MODE_FLAG_HSKEW)
11116 return MODE_H_ILLEGAL;
11118 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
11119 DRM_MODE_FLAG_NCSYNC |
11120 DRM_MODE_FLAG_PCSYNC))
11123 if (mode->flags & (DRM_MODE_FLAG_BCAST |
11124 DRM_MODE_FLAG_PIXMUX |
11125 DRM_MODE_FLAG_CLKDIV2))
11128 /* Transcoder timing limits */
11129 if (DISPLAY_VER(dev_priv) >= 11) {
11130 hdisplay_max = 16384;
11131 vdisplay_max = 8192;
11132 htotal_max = 16384;
11134 } else if (DISPLAY_VER(dev_priv) >= 9 ||
11135 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
11136 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
11137 vdisplay_max = 4096;
11140 } else if (DISPLAY_VER(dev_priv) >= 3) {
11141 hdisplay_max = 4096;
11142 vdisplay_max = 4096;
11146 hdisplay_max = 2048;
11147 vdisplay_max = 2048;
11152 if (mode->hdisplay > hdisplay_max ||
11153 mode->hsync_start > htotal_max ||
11154 mode->hsync_end > htotal_max ||
11155 mode->htotal > htotal_max)
11156 return MODE_H_ILLEGAL;
11158 if (mode->vdisplay > vdisplay_max ||
11159 mode->vsync_start > vtotal_max ||
11160 mode->vsync_end > vtotal_max ||
11161 mode->vtotal > vtotal_max)
11162 return MODE_V_ILLEGAL;
11164 if (DISPLAY_VER(dev_priv) >= 5) {
11165 if (mode->hdisplay < 64 ||
11166 mode->htotal - mode->hdisplay < 32)
11167 return MODE_H_ILLEGAL;
11169 if (mode->vtotal - mode->vdisplay < 5)
11170 return MODE_V_ILLEGAL;
11172 if (mode->htotal - mode->hdisplay < 32)
11173 return MODE_H_ILLEGAL;
11175 if (mode->vtotal - mode->vdisplay < 3)
11176 return MODE_V_ILLEGAL;
11182 enum drm_mode_status
11183 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
11184 const struct drm_display_mode *mode,
11187 int plane_width_max, plane_height_max;
11190 * intel_mode_valid() should be
11191 * sufficient on older platforms.
11193 if (DISPLAY_VER(dev_priv) < 9)
11197 * Most people will probably want a fullscreen
11198 * plane so let's not advertize modes that are
11199 * too big for that.
11201 if (DISPLAY_VER(dev_priv) >= 11) {
11202 plane_width_max = 5120 << bigjoiner;
11203 plane_height_max = 4320;
11205 plane_width_max = 5120;
11206 plane_height_max = 4096;
11209 if (mode->hdisplay > plane_width_max)
11210 return MODE_H_ILLEGAL;
11212 if (mode->vdisplay > plane_height_max)
11213 return MODE_V_ILLEGAL;
11218 static const struct drm_mode_config_funcs intel_mode_funcs = {
11219 .fb_create = intel_user_framebuffer_create,
11220 .get_format_info = intel_get_format_info,
11221 .output_poll_changed = intel_fbdev_output_poll_changed,
11222 .mode_valid = intel_mode_valid,
11223 .atomic_check = intel_atomic_check,
11224 .atomic_commit = intel_atomic_commit,
11225 .atomic_state_alloc = intel_atomic_state_alloc,
11226 .atomic_state_clear = intel_atomic_state_clear,
11227 .atomic_state_free = intel_atomic_state_free,
11231 * intel_init_display_hooks - initialize the display modesetting hooks
11232 * @dev_priv: device private
11234 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
11236 if (!HAS_DISPLAY(dev_priv))
11239 intel_init_cdclk_hooks(dev_priv);
11240 intel_init_audio_hooks(dev_priv);
11242 intel_dpll_init_clock_hook(dev_priv);
11244 if (DISPLAY_VER(dev_priv) >= 9) {
11245 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
11246 dev_priv->display.crtc_enable = hsw_crtc_enable;
11247 dev_priv->display.crtc_disable = hsw_crtc_disable;
11248 } else if (HAS_DDI(dev_priv)) {
11249 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
11250 dev_priv->display.crtc_enable = hsw_crtc_enable;
11251 dev_priv->display.crtc_disable = hsw_crtc_disable;
11252 } else if (HAS_PCH_SPLIT(dev_priv)) {
11253 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
11254 dev_priv->display.crtc_enable = ilk_crtc_enable;
11255 dev_priv->display.crtc_disable = ilk_crtc_disable;
11256 } else if (IS_CHERRYVIEW(dev_priv) ||
11257 IS_VALLEYVIEW(dev_priv)) {
11258 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
11259 dev_priv->display.crtc_enable = valleyview_crtc_enable;
11260 dev_priv->display.crtc_disable = i9xx_crtc_disable;
11262 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
11263 dev_priv->display.crtc_enable = i9xx_crtc_enable;
11264 dev_priv->display.crtc_disable = i9xx_crtc_disable;
11267 intel_fdi_init_hook(dev_priv);
11269 if (DISPLAY_VER(dev_priv) >= 9) {
11270 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
11271 dev_priv->display.get_initial_plane_config = skl_get_initial_plane_config;
11273 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
11274 dev_priv->display.get_initial_plane_config = i9xx_get_initial_plane_config;
11279 void intel_modeset_init_hw(struct drm_i915_private *i915)
11281 struct intel_cdclk_state *cdclk_state;
11283 if (!HAS_DISPLAY(i915))
11286 cdclk_state = to_intel_cdclk_state(i915->cdclk.obj.state);
11288 intel_update_cdclk(i915);
11289 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
11290 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
11293 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
11295 struct drm_plane *plane;
11296 struct intel_crtc *crtc;
11298 for_each_intel_crtc(state->dev, crtc) {
11299 struct intel_crtc_state *crtc_state;
11301 crtc_state = intel_atomic_get_crtc_state(state, crtc);
11302 if (IS_ERR(crtc_state))
11303 return PTR_ERR(crtc_state);
11305 if (crtc_state->hw.active) {
11307 * Preserve the inherited flag to avoid
11308 * taking the full modeset path.
11310 crtc_state->inherited = true;
11314 drm_for_each_plane(plane, state->dev) {
11315 struct drm_plane_state *plane_state;
11317 plane_state = drm_atomic_get_plane_state(state, plane);
11318 if (IS_ERR(plane_state))
11319 return PTR_ERR(plane_state);
11326 * Calculate what we think the watermarks should be for the state we've read
11327 * out of the hardware and then immediately program those watermarks so that
11328 * we ensure the hardware settings match our internal state.
11330 * We can calculate what we think WM's should be by creating a duplicate of the
11331 * current state (which was constructed during hardware readout) and running it
11332 * through the atomic check code to calculate new watermark values in the
11335 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
11337 struct drm_atomic_state *state;
11338 struct intel_atomic_state *intel_state;
11339 struct intel_crtc *crtc;
11340 struct intel_crtc_state *crtc_state;
11341 struct drm_modeset_acquire_ctx ctx;
11345 /* Only supported on platforms that use atomic watermark design */
11346 if (!dev_priv->display.optimize_watermarks)
11349 state = drm_atomic_state_alloc(&dev_priv->drm);
11350 if (drm_WARN_ON(&dev_priv->drm, !state))
11353 intel_state = to_intel_atomic_state(state);
11355 drm_modeset_acquire_init(&ctx, 0);
11358 state->acquire_ctx = &ctx;
11361 * Hardware readout is the only time we don't want to calculate
11362 * intermediate watermarks (since we don't trust the current
11365 if (!HAS_GMCH(dev_priv))
11366 intel_state->skip_intermediate_wm = true;
11368 ret = sanitize_watermarks_add_affected(state);
11372 ret = intel_atomic_check(&dev_priv->drm, state);
11376 /* Write calculated watermark values back */
11377 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
11378 crtc_state->wm.need_postvbl_update = true;
11379 dev_priv->display.optimize_watermarks(intel_state, crtc);
11381 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
11385 if (ret == -EDEADLK) {
11386 drm_atomic_state_clear(state);
11387 drm_modeset_backoff(&ctx);
11392 * If we fail here, it means that the hardware appears to be
11393 * programmed in a way that shouldn't be possible, given our
11394 * understanding of watermark requirements. This might mean a
11395 * mistake in the hardware readout code or a mistake in the
11396 * watermark calculations for a given platform. Raise a WARN
11397 * so that this is noticeable.
11399 * If this actually happens, we'll have to just leave the
11400 * BIOS-programmed watermarks untouched and hope for the best.
11402 drm_WARN(&dev_priv->drm, ret,
11403 "Could not determine valid watermarks for inherited state\n");
11405 drm_atomic_state_put(state);
11407 drm_modeset_drop_locks(&ctx);
11408 drm_modeset_acquire_fini(&ctx);
11411 static int intel_initial_commit(struct drm_device *dev)
11413 struct drm_atomic_state *state = NULL;
11414 struct drm_modeset_acquire_ctx ctx;
11415 struct intel_crtc *crtc;
11418 state = drm_atomic_state_alloc(dev);
11422 drm_modeset_acquire_init(&ctx, 0);
11425 state->acquire_ctx = &ctx;
11427 for_each_intel_crtc(dev, crtc) {
11428 struct intel_crtc_state *crtc_state =
11429 intel_atomic_get_crtc_state(state, crtc);
11431 if (IS_ERR(crtc_state)) {
11432 ret = PTR_ERR(crtc_state);
11436 if (crtc_state->hw.active) {
11437 struct intel_encoder *encoder;
11440 * We've not yet detected sink capabilities
11441 * (audio,infoframes,etc.) and thus we don't want to
11442 * force a full state recomputation yet. We want that to
11443 * happen only for the first real commit from userspace.
11444 * So preserve the inherited flag for the time being.
11446 crtc_state->inherited = true;
11448 ret = drm_atomic_add_affected_planes(state, &crtc->base);
11453 * FIXME hack to force a LUT update to avoid the
11454 * plane update forcing the pipe gamma on without
11455 * having a proper LUT loaded. Remove once we
11456 * have readout for pipe gamma enable.
11458 crtc_state->uapi.color_mgmt_changed = true;
11460 for_each_intel_encoder_mask(dev, encoder,
11461 crtc_state->uapi.encoder_mask) {
11462 if (encoder->initial_fastset_check &&
11463 !encoder->initial_fastset_check(encoder, crtc_state)) {
11464 ret = drm_atomic_add_affected_connectors(state,
11473 ret = drm_atomic_commit(state);
11476 if (ret == -EDEADLK) {
11477 drm_atomic_state_clear(state);
11478 drm_modeset_backoff(&ctx);
11482 drm_atomic_state_put(state);
11484 drm_modeset_drop_locks(&ctx);
11485 drm_modeset_acquire_fini(&ctx);
11490 static void intel_mode_config_init(struct drm_i915_private *i915)
11492 struct drm_mode_config *mode_config = &i915->drm.mode_config;
11494 drm_mode_config_init(&i915->drm);
11495 INIT_LIST_HEAD(&i915->global_obj_list);
11497 mode_config->min_width = 0;
11498 mode_config->min_height = 0;
11500 mode_config->preferred_depth = 24;
11501 mode_config->prefer_shadow = 1;
11503 mode_config->funcs = &intel_mode_funcs;
11505 mode_config->async_page_flip = HAS_ASYNC_FLIPS(i915);
11508 * Maximum framebuffer dimensions, chosen to match
11509 * the maximum render engine surface size on gen4+.
11511 if (DISPLAY_VER(i915) >= 7) {
11512 mode_config->max_width = 16384;
11513 mode_config->max_height = 16384;
11514 } else if (DISPLAY_VER(i915) >= 4) {
11515 mode_config->max_width = 8192;
11516 mode_config->max_height = 8192;
11517 } else if (DISPLAY_VER(i915) == 3) {
11518 mode_config->max_width = 4096;
11519 mode_config->max_height = 4096;
11521 mode_config->max_width = 2048;
11522 mode_config->max_height = 2048;
11525 if (IS_I845G(i915) || IS_I865G(i915)) {
11526 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
11527 mode_config->cursor_height = 1023;
11528 } else if (IS_I830(i915) || IS_I85X(i915) ||
11529 IS_I915G(i915) || IS_I915GM(i915)) {
11530 mode_config->cursor_width = 64;
11531 mode_config->cursor_height = 64;
11533 mode_config->cursor_width = 256;
11534 mode_config->cursor_height = 256;
11538 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
11540 intel_atomic_global_obj_cleanup(i915);
11541 drm_mode_config_cleanup(&i915->drm);
11544 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
11546 if (plane_config->fb) {
11547 struct drm_framebuffer *fb = &plane_config->fb->base;
11549 /* We may only have the stub and not a full framebuffer */
11550 if (drm_framebuffer_read_refcount(fb))
11551 drm_framebuffer_put(fb);
11556 if (plane_config->vma)
11557 i915_vma_put(plane_config->vma);
11560 /* part #1: call before irq install */
11561 int intel_modeset_init_noirq(struct drm_i915_private *i915)
11565 if (i915_inject_probe_failure(i915))
11568 if (HAS_DISPLAY(i915)) {
11569 ret = drm_vblank_init(&i915->drm,
11570 INTEL_NUM_PIPES(i915));
11575 intel_bios_init(i915);
11577 ret = intel_vga_register(i915);
11581 /* FIXME: completely on the wrong abstraction layer */
11582 intel_power_domains_init_hw(i915, false);
11584 if (!HAS_DISPLAY(i915))
11587 intel_dmc_ucode_init(i915);
11589 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
11590 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
11591 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
11593 i915->framestart_delay = 1; /* 1-4 */
11595 i915->window2_delay = 0; /* No DSB so no window2 delay */
11597 intel_mode_config_init(i915);
11599 ret = intel_cdclk_init(i915);
11601 goto cleanup_vga_client_pw_domain_dmc;
11603 ret = intel_dbuf_init(i915);
11605 goto cleanup_vga_client_pw_domain_dmc;
11607 ret = intel_bw_init(i915);
11609 goto cleanup_vga_client_pw_domain_dmc;
11611 init_llist_head(&i915->atomic_helper.free_list);
11612 INIT_WORK(&i915->atomic_helper.free_work,
11613 intel_atomic_helper_free_state_worker);
11615 intel_init_quirks(i915);
11617 intel_fbc_init(i915);
11621 cleanup_vga_client_pw_domain_dmc:
11622 intel_dmc_ucode_fini(i915);
11623 intel_power_domains_driver_remove(i915);
11624 intel_vga_unregister(i915);
11626 intel_bios_driver_remove(i915);
11631 /* part #2: call after irq install, but before gem init */
11632 int intel_modeset_init_nogem(struct drm_i915_private *i915)
11634 struct drm_device *dev = &i915->drm;
11636 struct intel_crtc *crtc;
11639 if (!HAS_DISPLAY(i915))
11642 intel_init_pm(i915);
11644 intel_panel_sanitize_ssc(i915);
11646 intel_pps_setup(i915);
11648 intel_gmbus_setup(i915);
11650 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
11651 INTEL_NUM_PIPES(i915),
11652 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
11654 for_each_pipe(i915, pipe) {
11655 ret = intel_crtc_init(i915, pipe);
11657 intel_mode_config_cleanup(i915);
11662 intel_plane_possible_crtcs_init(i915);
11663 intel_shared_dpll_init(dev);
11664 intel_fdi_pll_freq_update(i915);
11666 intel_update_czclk(i915);
11667 intel_modeset_init_hw(i915);
11668 intel_dpll_update_ref_clks(i915);
11670 intel_hdcp_component_init(i915);
11672 if (i915->max_cdclk_freq == 0)
11673 intel_update_max_cdclk(i915);
11676 * If the platform has HTI, we need to find out whether it has reserved
11677 * any display resources before we create our display outputs.
11679 if (INTEL_INFO(i915)->display.has_hti)
11680 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
11682 /* Just disable it once at startup */
11683 intel_vga_disable(i915);
11684 intel_setup_outputs(i915);
11686 drm_modeset_lock_all(dev);
11687 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
11688 intel_acpi_assign_connector_fwnodes(i915);
11689 drm_modeset_unlock_all(dev);
11691 for_each_intel_crtc(dev, crtc) {
11692 struct intel_initial_plane_config plane_config = {};
11694 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
11698 * Note that reserving the BIOS fb up front prevents us
11699 * from stuffing other stolen allocations like the ring
11700 * on top. This prevents some ugliness at boot time, and
11701 * can even allow for smooth boot transitions if the BIOS
11702 * fb is large enough for the active pipe configuration.
11704 i915->display.get_initial_plane_config(crtc, &plane_config);
11707 * If the fb is shared between multiple heads, we'll
11708 * just get the first one.
11710 intel_find_initial_plane_obj(crtc, &plane_config);
11712 plane_config_fini(&plane_config);
11716 * Make sure hardware watermarks really match the state we read out.
11717 * Note that we need to do this after reconstructing the BIOS fb's
11718 * since the watermark calculation done here will use pstate->fb.
11720 if (!HAS_GMCH(i915))
11721 sanitize_watermarks(i915);
11726 /* part #3: call after gem init */
11727 int intel_modeset_init(struct drm_i915_private *i915)
11731 if (!HAS_DISPLAY(i915))
11735 * Force all active planes to recompute their states. So that on
11736 * mode_setcrtc after probe, all the intel_plane_state variables
11737 * are already calculated and there is no assert_plane warnings
11740 ret = intel_initial_commit(&i915->drm);
11742 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
11744 intel_overlay_setup(i915);
11746 ret = intel_fbdev_init(&i915->drm);
11750 /* Only enable hotplug handling once the fbdev is fully set up. */
11751 intel_hpd_init(i915);
11752 intel_hpd_poll_disable(i915);
11754 intel_init_ipc(i915);
11759 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
11761 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11762 /* 640x480@60Hz, ~25175 kHz */
11763 struct dpll clock = {
11773 drm_WARN_ON(&dev_priv->drm,
11774 i9xx_calc_dpll_params(48000, &clock) != 25154);
11776 drm_dbg_kms(&dev_priv->drm,
11777 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
11778 pipe_name(pipe), clock.vco, clock.dot);
11780 fp = i9xx_dpll_compute_fp(&clock);
11781 dpll = DPLL_DVO_2X_MODE |
11782 DPLL_VGA_MODE_DIS |
11783 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
11784 PLL_P2_DIVIDE_BY_4 |
11785 PLL_REF_INPUT_DREFCLK |
11788 intel_de_write(dev_priv, FP0(pipe), fp);
11789 intel_de_write(dev_priv, FP1(pipe), fp);
11791 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
11792 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
11793 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
11794 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
11795 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
11796 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
11797 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
11800 * Apparently we need to have VGA mode enabled prior to changing
11801 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
11802 * dividers, even though the register value does change.
11804 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
11805 intel_de_write(dev_priv, DPLL(pipe), dpll);
11807 /* Wait for the clocks to stabilize. */
11808 intel_de_posting_read(dev_priv, DPLL(pipe));
11811 /* The pixel multiplier can only be updated once the
11812 * DPLL is enabled and the clocks are stable.
11814 * So write it again.
11816 intel_de_write(dev_priv, DPLL(pipe), dpll);
11818 /* We do this three times for luck */
11819 for (i = 0; i < 3 ; i++) {
11820 intel_de_write(dev_priv, DPLL(pipe), dpll);
11821 intel_de_posting_read(dev_priv, DPLL(pipe));
11822 udelay(150); /* wait for warmup */
11825 intel_de_write(dev_priv, PIPECONF(pipe),
11826 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
11827 intel_de_posting_read(dev_priv, PIPECONF(pipe));
11829 intel_wait_for_pipe_scanline_moving(crtc);
11832 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
11834 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11836 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
11839 drm_WARN_ON(&dev_priv->drm,
11840 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
11841 DISPLAY_PLANE_ENABLE);
11842 drm_WARN_ON(&dev_priv->drm,
11843 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
11844 DISPLAY_PLANE_ENABLE);
11845 drm_WARN_ON(&dev_priv->drm,
11846 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
11847 DISPLAY_PLANE_ENABLE);
11848 drm_WARN_ON(&dev_priv->drm,
11849 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
11850 drm_WARN_ON(&dev_priv->drm,
11851 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
11853 intel_de_write(dev_priv, PIPECONF(pipe), 0);
11854 intel_de_posting_read(dev_priv, PIPECONF(pipe));
11856 intel_wait_for_pipe_scanline_stopped(crtc);
11858 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
11859 intel_de_posting_read(dev_priv, DPLL(pipe));
11863 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
11865 struct intel_crtc *crtc;
11867 if (DISPLAY_VER(dev_priv) >= 4)
11870 for_each_intel_crtc(&dev_priv->drm, crtc) {
11871 struct intel_plane *plane =
11872 to_intel_plane(crtc->base.primary);
11873 struct intel_crtc *plane_crtc;
11876 if (!plane->get_hw_state(plane, &pipe))
11879 if (pipe == crtc->pipe)
11882 drm_dbg_kms(&dev_priv->drm,
11883 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
11884 plane->base.base.id, plane->base.name);
11886 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
11887 intel_plane_disable_noatomic(plane_crtc, plane);
11891 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
11893 struct drm_device *dev = crtc->base.dev;
11894 struct intel_encoder *encoder;
11896 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
11902 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
11904 struct drm_device *dev = encoder->base.dev;
11905 struct intel_connector *connector;
11907 for_each_connector_on_encoder(dev, &encoder->base, connector)
11913 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
11914 enum pipe pch_transcoder)
11916 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
11917 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
11920 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
11922 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11923 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11924 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
11926 if (DISPLAY_VER(dev_priv) >= 9 ||
11927 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
11928 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
11931 if (transcoder_is_dsi(cpu_transcoder))
11934 val = intel_de_read(dev_priv, reg);
11935 val &= ~HSW_FRAME_START_DELAY_MASK;
11936 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
11937 intel_de_write(dev_priv, reg, val);
11939 i915_reg_t reg = PIPECONF(cpu_transcoder);
11942 val = intel_de_read(dev_priv, reg);
11943 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
11944 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
11945 intel_de_write(dev_priv, reg, val);
11948 if (!crtc_state->has_pch_encoder)
11951 if (HAS_PCH_IBX(dev_priv)) {
11952 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
11955 val = intel_de_read(dev_priv, reg);
11956 val &= ~TRANS_FRAME_START_DELAY_MASK;
11957 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
11958 intel_de_write(dev_priv, reg, val);
11960 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
11961 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
11964 val = intel_de_read(dev_priv, reg);
11965 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
11966 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
11967 intel_de_write(dev_priv, reg, val);
11971 static void intel_sanitize_crtc(struct intel_crtc *crtc,
11972 struct drm_modeset_acquire_ctx *ctx)
11974 struct drm_device *dev = crtc->base.dev;
11975 struct drm_i915_private *dev_priv = to_i915(dev);
11976 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
11978 if (crtc_state->hw.active) {
11979 struct intel_plane *plane;
11981 /* Clear any frame start delays used for debugging left by the BIOS */
11982 intel_sanitize_frame_start_delay(crtc_state);
11984 /* Disable everything but the primary plane */
11985 for_each_intel_plane_on_crtc(dev, crtc, plane) {
11986 const struct intel_plane_state *plane_state =
11987 to_intel_plane_state(plane->base.state);
11989 if (plane_state->uapi.visible &&
11990 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
11991 intel_plane_disable_noatomic(crtc, plane);
11995 * Disable any background color set by the BIOS, but enable the
11996 * gamma and CSC to match how we program our planes.
11998 if (DISPLAY_VER(dev_priv) >= 9)
11999 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
12000 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
12003 /* Adjust the state of the output pipe according to whether we
12004 * have active connectors/encoders. */
12005 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc) &&
12006 !crtc_state->bigjoiner_slave)
12007 intel_crtc_disable_noatomic(crtc, ctx);
12009 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
12011 * We start out with underrun reporting disabled to avoid races.
12012 * For correct bookkeeping mark this on active crtcs.
12014 * Also on gmch platforms we dont have any hardware bits to
12015 * disable the underrun reporting. Which means we need to start
12016 * out with underrun reporting disabled also on inactive pipes,
12017 * since otherwise we'll complain about the garbage we read when
12018 * e.g. coming up after runtime pm.
12020 * No protection against concurrent access is required - at
12021 * worst a fifo underrun happens which also sets this to false.
12023 crtc->cpu_fifo_underrun_disabled = true;
12025 * We track the PCH trancoder underrun reporting state
12026 * within the crtc. With crtc for pipe A housing the underrun
12027 * reporting state for PCH transcoder A, crtc for pipe B housing
12028 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
12029 * and marking underrun reporting as disabled for the non-existing
12030 * PCH transcoders B and C would prevent enabling the south
12031 * error interrupt (see cpt_can_enable_serr_int()).
12033 if (has_pch_trancoder(dev_priv, crtc->pipe))
12034 crtc->pch_fifo_underrun_disabled = true;
12038 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
12040 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
12043 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
12044 * the hardware when a high res displays plugged in. DPLL P
12045 * divider is zero, and the pipe timings are bonkers. We'll
12046 * try to disable everything in that case.
12048 * FIXME would be nice to be able to sanitize this state
12049 * without several WARNs, but for now let's take the easy
12052 return IS_SANDYBRIDGE(dev_priv) &&
12053 crtc_state->hw.active &&
12054 crtc_state->shared_dpll &&
12055 crtc_state->port_clock == 0;
12058 static void intel_sanitize_encoder(struct intel_encoder *encoder)
12060 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12061 struct intel_connector *connector;
12062 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
12063 struct intel_crtc_state *crtc_state = crtc ?
12064 to_intel_crtc_state(crtc->base.state) : NULL;
12066 /* We need to check both for a crtc link (meaning that the
12067 * encoder is active and trying to read from a pipe) and the
12068 * pipe itself being active. */
12069 bool has_active_crtc = crtc_state &&
12070 crtc_state->hw.active;
12072 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
12073 drm_dbg_kms(&dev_priv->drm,
12074 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
12075 pipe_name(crtc->pipe));
12076 has_active_crtc = false;
12079 connector = intel_encoder_find_connector(encoder);
12080 if (connector && !has_active_crtc) {
12081 drm_dbg_kms(&dev_priv->drm,
12082 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12083 encoder->base.base.id,
12084 encoder->base.name);
12086 /* Connector is active, but has no active pipe. This is
12087 * fallout from our resume register restoring. Disable
12088 * the encoder manually again. */
12090 struct drm_encoder *best_encoder;
12092 drm_dbg_kms(&dev_priv->drm,
12093 "[ENCODER:%d:%s] manually disabled\n",
12094 encoder->base.base.id,
12095 encoder->base.name);
12097 /* avoid oopsing in case the hooks consult best_encoder */
12098 best_encoder = connector->base.state->best_encoder;
12099 connector->base.state->best_encoder = &encoder->base;
12101 /* FIXME NULL atomic state passed! */
12102 if (encoder->disable)
12103 encoder->disable(NULL, encoder, crtc_state,
12104 connector->base.state);
12105 if (encoder->post_disable)
12106 encoder->post_disable(NULL, encoder, crtc_state,
12107 connector->base.state);
12109 connector->base.state->best_encoder = best_encoder;
12111 encoder->base.crtc = NULL;
12113 /* Inconsistent output/port/pipe state happens presumably due to
12114 * a bug in one of the get_hw_state functions. Or someplace else
12115 * in our code, like the register restore mess on resume. Clamp
12116 * things to off as a safer default. */
12118 connector->base.dpms = DRM_MODE_DPMS_OFF;
12119 connector->base.encoder = NULL;
12122 /* notify opregion of the sanitized encoder state */
12123 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
12125 if (HAS_DDI(dev_priv))
12126 intel_ddi_sanitize_encoder_pll_mapping(encoder);
12129 /* FIXME read out full plane state for all planes */
12130 static void readout_plane_state(struct drm_i915_private *dev_priv)
12132 struct intel_plane *plane;
12133 struct intel_crtc *crtc;
12135 for_each_intel_plane(&dev_priv->drm, plane) {
12136 struct intel_plane_state *plane_state =
12137 to_intel_plane_state(plane->base.state);
12138 struct intel_crtc_state *crtc_state;
12139 enum pipe pipe = PIPE_A;
12142 visible = plane->get_hw_state(plane, &pipe);
12144 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12145 crtc_state = to_intel_crtc_state(crtc->base.state);
12147 intel_set_plane_visible(crtc_state, plane_state, visible);
12149 drm_dbg_kms(&dev_priv->drm,
12150 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
12151 plane->base.base.id, plane->base.name,
12152 enableddisabled(visible), pipe_name(pipe));
12155 for_each_intel_crtc(&dev_priv->drm, crtc) {
12156 struct intel_crtc_state *crtc_state =
12157 to_intel_crtc_state(crtc->base.state);
12159 fixup_plane_bitmasks(crtc_state);
12163 static void intel_modeset_readout_hw_state(struct drm_device *dev)
12165 struct drm_i915_private *dev_priv = to_i915(dev);
12166 struct intel_cdclk_state *cdclk_state =
12167 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
12168 struct intel_dbuf_state *dbuf_state =
12169 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
12171 struct intel_crtc *crtc;
12172 struct intel_encoder *encoder;
12173 struct intel_connector *connector;
12174 struct drm_connector_list_iter conn_iter;
12175 u8 active_pipes = 0;
12177 for_each_intel_crtc(dev, crtc) {
12178 struct intel_crtc_state *crtc_state =
12179 to_intel_crtc_state(crtc->base.state);
12181 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
12182 intel_crtc_free_hw_state(crtc_state);
12183 intel_crtc_state_reset(crtc_state, crtc);
12185 intel_crtc_get_pipe_config(crtc_state);
12187 crtc_state->hw.enable = crtc_state->hw.active;
12189 crtc->base.enabled = crtc_state->hw.enable;
12190 crtc->active = crtc_state->hw.active;
12192 if (crtc_state->hw.active)
12193 active_pipes |= BIT(crtc->pipe);
12195 drm_dbg_kms(&dev_priv->drm,
12196 "[CRTC:%d:%s] hw state readout: %s\n",
12197 crtc->base.base.id, crtc->base.name,
12198 enableddisabled(crtc_state->hw.active));
12201 cdclk_state->active_pipes = dbuf_state->active_pipes = active_pipes;
12203 readout_plane_state(dev_priv);
12205 for_each_intel_encoder(dev, encoder) {
12208 if (encoder->get_hw_state(encoder, &pipe)) {
12209 struct intel_crtc_state *crtc_state;
12211 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12212 crtc_state = to_intel_crtc_state(crtc->base.state);
12214 encoder->base.crtc = &crtc->base;
12215 intel_encoder_get_config(encoder, crtc_state);
12216 if (encoder->sync_state)
12217 encoder->sync_state(encoder, crtc_state);
12219 /* read out to slave crtc as well for bigjoiner */
12220 if (crtc_state->bigjoiner) {
12221 /* encoder should read be linked to bigjoiner master */
12222 WARN_ON(crtc_state->bigjoiner_slave);
12224 crtc = crtc_state->bigjoiner_linked_crtc;
12225 crtc_state = to_intel_crtc_state(crtc->base.state);
12226 intel_encoder_get_config(encoder, crtc_state);
12229 encoder->base.crtc = NULL;
12232 drm_dbg_kms(&dev_priv->drm,
12233 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
12234 encoder->base.base.id, encoder->base.name,
12235 enableddisabled(encoder->base.crtc),
12239 intel_dpll_readout_hw_state(dev_priv);
12241 drm_connector_list_iter_begin(dev, &conn_iter);
12242 for_each_intel_connector_iter(connector, &conn_iter) {
12243 if (connector->get_hw_state(connector)) {
12244 struct intel_crtc_state *crtc_state;
12245 struct intel_crtc *crtc;
12247 connector->base.dpms = DRM_MODE_DPMS_ON;
12249 encoder = intel_attached_encoder(connector);
12250 connector->base.encoder = &encoder->base;
12252 crtc = to_intel_crtc(encoder->base.crtc);
12253 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
12255 if (crtc_state && crtc_state->hw.active) {
12257 * This has to be done during hardware readout
12258 * because anything calling .crtc_disable may
12259 * rely on the connector_mask being accurate.
12261 crtc_state->uapi.connector_mask |=
12262 drm_connector_mask(&connector->base);
12263 crtc_state->uapi.encoder_mask |=
12264 drm_encoder_mask(&encoder->base);
12267 connector->base.dpms = DRM_MODE_DPMS_OFF;
12268 connector->base.encoder = NULL;
12270 drm_dbg_kms(&dev_priv->drm,
12271 "[CONNECTOR:%d:%s] hw state readout: %s\n",
12272 connector->base.base.id, connector->base.name,
12273 enableddisabled(connector->base.encoder));
12275 drm_connector_list_iter_end(&conn_iter);
12277 for_each_intel_crtc(dev, crtc) {
12278 struct intel_bw_state *bw_state =
12279 to_intel_bw_state(dev_priv->bw_obj.state);
12280 struct intel_crtc_state *crtc_state =
12281 to_intel_crtc_state(crtc->base.state);
12282 struct intel_plane *plane;
12285 if (crtc_state->bigjoiner_slave)
12288 if (crtc_state->hw.active) {
12290 * The initial mode needs to be set in order to keep
12291 * the atomic core happy. It wants a valid mode if the
12292 * crtc's enabled, so we do the above call.
12294 * But we don't set all the derived state fully, hence
12295 * set a flag to indicate that a full recalculation is
12296 * needed on the next commit.
12298 crtc_state->inherited = true;
12300 intel_crtc_update_active_timings(crtc_state);
12302 intel_crtc_copy_hw_to_uapi_state(crtc_state);
12305 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
12306 const struct intel_plane_state *plane_state =
12307 to_intel_plane_state(plane->base.state);
12310 * FIXME don't have the fb yet, so can't
12311 * use intel_plane_data_rate() :(
12313 if (plane_state->uapi.visible)
12314 crtc_state->data_rate[plane->id] =
12315 4 * crtc_state->pixel_rate;
12317 * FIXME don't have the fb yet, so can't
12318 * use plane->min_cdclk() :(
12320 if (plane_state->uapi.visible && plane->min_cdclk) {
12321 if (crtc_state->double_wide || DISPLAY_VER(dev_priv) >= 10)
12322 crtc_state->min_cdclk[plane->id] =
12323 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
12325 crtc_state->min_cdclk[plane->id] =
12326 crtc_state->pixel_rate;
12328 drm_dbg_kms(&dev_priv->drm,
12329 "[PLANE:%d:%s] min_cdclk %d kHz\n",
12330 plane->base.base.id, plane->base.name,
12331 crtc_state->min_cdclk[plane->id]);
12334 if (crtc_state->hw.active) {
12335 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
12336 if (drm_WARN_ON(dev, min_cdclk < 0))
12340 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
12341 cdclk_state->min_voltage_level[crtc->pipe] =
12342 crtc_state->min_voltage_level;
12344 intel_bw_crtc_update(bw_state, crtc_state);
12346 intel_pipe_config_sanity_check(dev_priv, crtc_state);
12348 /* discard our incomplete slave state, copy it from master */
12349 if (crtc_state->bigjoiner && crtc_state->hw.active) {
12350 struct intel_crtc *slave = crtc_state->bigjoiner_linked_crtc;
12351 struct intel_crtc_state *slave_crtc_state =
12352 to_intel_crtc_state(slave->base.state);
12354 copy_bigjoiner_crtc_state(slave_crtc_state, crtc_state);
12355 slave->base.mode = crtc->base.mode;
12357 cdclk_state->min_cdclk[slave->pipe] = min_cdclk;
12358 cdclk_state->min_voltage_level[slave->pipe] =
12359 crtc_state->min_voltage_level;
12361 for_each_intel_plane_on_crtc(&dev_priv->drm, slave, plane) {
12362 const struct intel_plane_state *plane_state =
12363 to_intel_plane_state(plane->base.state);
12366 * FIXME don't have the fb yet, so can't
12367 * use intel_plane_data_rate() :(
12369 if (plane_state->uapi.visible)
12370 crtc_state->data_rate[plane->id] =
12371 4 * crtc_state->pixel_rate;
12373 crtc_state->data_rate[plane->id] = 0;
12376 intel_bw_crtc_update(bw_state, slave_crtc_state);
12377 drm_calc_timestamping_constants(&slave->base,
12378 &slave_crtc_state->hw.adjusted_mode);
12384 get_encoder_power_domains(struct drm_i915_private *dev_priv)
12386 struct intel_encoder *encoder;
12388 for_each_intel_encoder(&dev_priv->drm, encoder) {
12389 struct intel_crtc_state *crtc_state;
12391 if (!encoder->get_power_domains)
12395 * MST-primary and inactive encoders don't have a crtc state
12396 * and neither of these require any power domain references.
12398 if (!encoder->base.crtc)
12401 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
12402 encoder->get_power_domains(encoder, crtc_state);
12406 static void intel_early_display_was(struct drm_i915_private *dev_priv)
12409 * Display WA #1185 WaDisableDARBFClkGating:glk,icl,ehl,tgl
12410 * Also known as Wa_14010480278.
12412 if (IS_DISPLAY_VER(dev_priv, 10, 12))
12413 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
12414 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
12416 if (IS_HASWELL(dev_priv)) {
12418 * WaRsPkgCStateDisplayPMReq:hsw
12419 * System hang if this isn't done before disabling all planes!
12421 intel_de_write(dev_priv, CHICKEN_PAR1_1,
12422 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
12425 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) {
12426 /* Display WA #1142:kbl,cfl,cml */
12427 intel_de_rmw(dev_priv, CHICKEN_PAR1_1,
12428 KBL_ARB_FILL_SPARE_22, KBL_ARB_FILL_SPARE_22);
12429 intel_de_rmw(dev_priv, CHICKEN_MISC_2,
12430 KBL_ARB_FILL_SPARE_13 | KBL_ARB_FILL_SPARE_14,
12431 KBL_ARB_FILL_SPARE_14);
12435 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
12436 enum port port, i915_reg_t hdmi_reg)
12438 u32 val = intel_de_read(dev_priv, hdmi_reg);
12440 if (val & SDVO_ENABLE ||
12441 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
12444 drm_dbg_kms(&dev_priv->drm,
12445 "Sanitizing transcoder select for HDMI %c\n",
12448 val &= ~SDVO_PIPE_SEL_MASK;
12449 val |= SDVO_PIPE_SEL(PIPE_A);
12451 intel_de_write(dev_priv, hdmi_reg, val);
12454 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
12455 enum port port, i915_reg_t dp_reg)
12457 u32 val = intel_de_read(dev_priv, dp_reg);
12459 if (val & DP_PORT_EN ||
12460 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
12463 drm_dbg_kms(&dev_priv->drm,
12464 "Sanitizing transcoder select for DP %c\n",
12467 val &= ~DP_PIPE_SEL_MASK;
12468 val |= DP_PIPE_SEL(PIPE_A);
12470 intel_de_write(dev_priv, dp_reg, val);
12473 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
12476 * The BIOS may select transcoder B on some of the PCH
12477 * ports even it doesn't enable the port. This would trip
12478 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
12479 * Sanitize the transcoder select bits to prevent that. We
12480 * assume that the BIOS never actually enabled the port,
12481 * because if it did we'd actually have to toggle the port
12482 * on and back off to make the transcoder A select stick
12483 * (see. intel_dp_link_down(), intel_disable_hdmi(),
12484 * intel_disable_sdvo()).
12486 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
12487 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
12488 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
12490 /* PCH SDVOB multiplex with HDMIB */
12491 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
12492 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
12493 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
12496 /* Scan out the current hw modeset state,
12497 * and sanitizes it to the current state
12500 intel_modeset_setup_hw_state(struct drm_device *dev,
12501 struct drm_modeset_acquire_ctx *ctx)
12503 struct drm_i915_private *dev_priv = to_i915(dev);
12504 struct intel_encoder *encoder;
12505 struct intel_crtc *crtc;
12506 intel_wakeref_t wakeref;
12508 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
12510 intel_early_display_was(dev_priv);
12511 intel_modeset_readout_hw_state(dev);
12513 /* HW state is read out, now we need to sanitize this mess. */
12515 /* Sanitize the TypeC port mode upfront, encoders depend on this */
12516 for_each_intel_encoder(dev, encoder) {
12517 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
12519 /* We need to sanitize only the MST primary port. */
12520 if (encoder->type != INTEL_OUTPUT_DP_MST &&
12521 intel_phy_is_tc(dev_priv, phy))
12522 intel_tc_port_sanitize(enc_to_dig_port(encoder));
12525 get_encoder_power_domains(dev_priv);
12527 if (HAS_PCH_IBX(dev_priv))
12528 ibx_sanitize_pch_ports(dev_priv);
12531 * intel_sanitize_plane_mapping() may need to do vblank
12532 * waits, so we need vblank interrupts restored beforehand.
12534 for_each_intel_crtc(&dev_priv->drm, crtc) {
12535 struct intel_crtc_state *crtc_state =
12536 to_intel_crtc_state(crtc->base.state);
12538 drm_crtc_vblank_reset(&crtc->base);
12540 if (crtc_state->hw.active)
12541 intel_crtc_vblank_on(crtc_state);
12544 intel_sanitize_plane_mapping(dev_priv);
12546 for_each_intel_encoder(dev, encoder)
12547 intel_sanitize_encoder(encoder);
12549 for_each_intel_crtc(&dev_priv->drm, crtc) {
12550 struct intel_crtc_state *crtc_state =
12551 to_intel_crtc_state(crtc->base.state);
12553 intel_sanitize_crtc(crtc, ctx);
12554 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
12557 intel_modeset_update_connector_atomic_state(dev);
12559 intel_dpll_sanitize_state(dev_priv);
12561 if (IS_G4X(dev_priv)) {
12562 g4x_wm_get_hw_state(dev_priv);
12563 g4x_wm_sanitize(dev_priv);
12564 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
12565 vlv_wm_get_hw_state(dev_priv);
12566 vlv_wm_sanitize(dev_priv);
12567 } else if (DISPLAY_VER(dev_priv) >= 9) {
12568 skl_wm_get_hw_state(dev_priv);
12569 } else if (HAS_PCH_SPLIT(dev_priv)) {
12570 ilk_wm_get_hw_state(dev_priv);
12573 for_each_intel_crtc(dev, crtc) {
12574 struct intel_crtc_state *crtc_state =
12575 to_intel_crtc_state(crtc->base.state);
12578 put_domains = modeset_get_crtc_power_domains(crtc_state);
12579 if (drm_WARN_ON(dev, put_domains))
12580 modeset_put_crtc_power_domains(crtc, put_domains);
12583 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
12586 void intel_display_resume(struct drm_device *dev)
12588 struct drm_i915_private *dev_priv = to_i915(dev);
12589 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
12590 struct drm_modeset_acquire_ctx ctx;
12593 if (!HAS_DISPLAY(dev_priv))
12596 dev_priv->modeset_restore_state = NULL;
12598 state->acquire_ctx = &ctx;
12600 drm_modeset_acquire_init(&ctx, 0);
12603 ret = drm_modeset_lock_all_ctx(dev, &ctx);
12604 if (ret != -EDEADLK)
12607 drm_modeset_backoff(&ctx);
12611 ret = __intel_display_resume(dev, state, &ctx);
12613 intel_enable_ipc(dev_priv);
12614 drm_modeset_drop_locks(&ctx);
12615 drm_modeset_acquire_fini(&ctx);
12618 drm_err(&dev_priv->drm,
12619 "Restoring old state failed with %i\n", ret);
12621 drm_atomic_state_put(state);
12624 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
12626 struct intel_connector *connector;
12627 struct drm_connector_list_iter conn_iter;
12629 /* Kill all the work that may have been queued by hpd. */
12630 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
12631 for_each_intel_connector_iter(connector, &conn_iter) {
12632 if (connector->modeset_retry_work.func)
12633 cancel_work_sync(&connector->modeset_retry_work);
12634 if (connector->hdcp.shim) {
12635 cancel_delayed_work_sync(&connector->hdcp.check_work);
12636 cancel_work_sync(&connector->hdcp.prop_work);
12639 drm_connector_list_iter_end(&conn_iter);
12642 /* part #1: call before irq uninstall */
12643 void intel_modeset_driver_remove(struct drm_i915_private *i915)
12645 if (!HAS_DISPLAY(i915))
12648 flush_workqueue(i915->flip_wq);
12649 flush_workqueue(i915->modeset_wq);
12651 flush_work(&i915->atomic_helper.free_work);
12652 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
12655 /* part #2: call after irq uninstall */
12656 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
12658 if (!HAS_DISPLAY(i915))
12662 * Due to the hpd irq storm handling the hotplug work can re-arm the
12663 * poll handlers. Hence disable polling after hpd handling is shut down.
12665 intel_hpd_poll_fini(i915);
12668 * MST topology needs to be suspended so we don't have any calls to
12669 * fbdev after it's finalized. MST will be destroyed later as part of
12670 * drm_mode_config_cleanup()
12672 intel_dp_mst_suspend(i915);
12674 /* poll work can call into fbdev, hence clean that up afterwards */
12675 intel_fbdev_fini(i915);
12677 intel_unregister_dsm_handler();
12679 intel_fbc_global_disable(i915);
12681 /* flush any delayed tasks or pending work */
12682 flush_scheduled_work();
12684 intel_hdcp_component_fini(i915);
12686 intel_mode_config_cleanup(i915);
12688 intel_overlay_cleanup(i915);
12690 intel_gmbus_teardown(i915);
12692 destroy_workqueue(i915->flip_wq);
12693 destroy_workqueue(i915->modeset_wq);
12695 intel_fbc_cleanup_cfb(i915);
12698 /* part #3: call after gem init */
12699 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
12701 intel_dmc_ucode_fini(i915);
12703 intel_power_domains_driver_remove(i915);
12705 intel_vga_unregister(i915);
12707 intel_bios_driver_remove(i915);
12710 void intel_display_driver_register(struct drm_i915_private *i915)
12712 if (!HAS_DISPLAY(i915))
12715 intel_display_debugfs_register(i915);
12717 /* Must be done after probing outputs */
12718 intel_opregion_register(i915);
12719 acpi_video_register();
12721 intel_audio_init(i915);
12724 * Some ports require correctly set-up hpd registers for
12725 * detection to work properly (leading to ghost connected
12726 * connector status), e.g. VGA on gm45. Hence we can only set
12727 * up the initial fbdev config after hpd irqs are fully
12728 * enabled. We do it last so that the async config cannot run
12729 * before the connectors are registered.
12731 intel_fbdev_initial_config_async(&i915->drm);
12734 * We need to coordinate the hotplugs with the asynchronous
12735 * fbdev configuration, for which we use the
12736 * fbdev->async_cookie.
12738 drm_kms_helper_poll_init(&i915->drm);
12741 void intel_display_driver_unregister(struct drm_i915_private *i915)
12743 if (!HAS_DISPLAY(i915))
12746 intel_fbdev_unregister(i915);
12747 intel_audio_deinit(i915);
12750 * After flushing the fbdev (incl. a late async config which
12751 * will have delayed queuing of a hotplug event), then flush
12752 * the hotplug events.
12754 drm_kms_helper_poll_fini(&i915->drm);
12755 drm_atomic_helper_shutdown(&i915->drm);
12757 acpi_video_unregister();
12758 intel_opregion_unregister(i915);