2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/i2c.h>
28 #include <linux/input.h>
29 #include <linux/intel-iommu.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/dma-resv.h>
33 #include <linux/slab.h>
35 #include <drm/drm_atomic.h>
36 #include <drm/drm_atomic_helper.h>
37 #include <drm/drm_atomic_uapi.h>
38 #include <drm/drm_damage_helper.h>
39 #include <drm/drm_dp_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_plane_helper.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/drm_rect.h>
46 #include "display/intel_crt.h"
47 #include "display/intel_ddi.h"
48 #include "display/intel_display_debugfs.h"
49 #include "display/intel_dp.h"
50 #include "display/intel_dp_mst.h"
51 #include "display/intel_dpll.h"
52 #include "display/intel_dpll_mgr.h"
53 #include "display/intel_dsi.h"
54 #include "display/intel_dvo.h"
55 #include "display/intel_gmbus.h"
56 #include "display/intel_hdmi.h"
57 #include "display/intel_lvds.h"
58 #include "display/intel_sdvo.h"
59 #include "display/intel_tv.h"
60 #include "display/intel_vdsc.h"
61 #include "display/intel_vrr.h"
63 #include "gem/i915_gem_object.h"
65 #include "gt/intel_rps.h"
68 #include "i915_trace.h"
69 #include "intel_acpi.h"
70 #include "intel_atomic.h"
71 #include "intel_atomic_plane.h"
73 #include "intel_cdclk.h"
74 #include "intel_color.h"
75 #include "intel_crtc.h"
76 #include "intel_csr.h"
77 #include "intel_display_types.h"
78 #include "intel_dp_link_training.h"
79 #include "intel_fbc.h"
80 #include "intel_fdi.h"
81 #include "intel_fbdev.h"
82 #include "intel_fifo_underrun.h"
83 #include "intel_frontbuffer.h"
84 #include "intel_hdcp.h"
85 #include "intel_hotplug.h"
86 #include "intel_overlay.h"
87 #include "intel_pipe_crc.h"
89 #include "intel_pps.h"
90 #include "intel_psr.h"
91 #include "intel_quirks.h"
92 #include "intel_sideband.h"
93 #include "intel_sprite.h"
95 #include "intel_vga.h"
96 #include "i9xx_plane.h"
98 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
99 struct intel_crtc_state *pipe_config);
100 static void ilk_pch_clock_get(struct intel_crtc *crtc,
101 struct intel_crtc_state *pipe_config);
103 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
104 struct drm_i915_gem_object *obj,
105 struct drm_mode_fb_cmd2 *mode_cmd);
106 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
107 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
108 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
109 const struct intel_link_m_n *m_n,
110 const struct intel_link_m_n *m2_n2);
111 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
112 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
113 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state);
114 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
115 static void vlv_prepare_pll(struct intel_crtc *crtc,
116 const struct intel_crtc_state *pipe_config);
117 static void chv_prepare_pll(struct intel_crtc *crtc,
118 const struct intel_crtc_state *pipe_config);
119 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state);
120 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
121 static void intel_modeset_setup_hw_state(struct drm_device *dev,
122 struct drm_modeset_acquire_ctx *ctx);
124 /* returns HPLL frequency in kHz */
125 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
127 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
129 /* Obtain SKU information */
130 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
131 CCK_FUSE_HPLL_FREQ_MASK;
133 return vco_freq[hpll_freq] * 1000;
136 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
137 const char *name, u32 reg, int ref_freq)
142 val = vlv_cck_read(dev_priv, reg);
143 divider = val & CCK_FREQUENCY_VALUES;
145 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
146 (divider << CCK_FREQUENCY_STATUS_SHIFT),
147 "%s change in progress\n", name);
149 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
152 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
153 const char *name, u32 reg)
157 vlv_cck_get(dev_priv);
159 if (dev_priv->hpll_freq == 0)
160 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
162 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
164 vlv_cck_put(dev_priv);
169 static void intel_update_czclk(struct drm_i915_private *dev_priv)
171 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
174 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
175 CCK_CZ_CLOCK_CONTROL);
177 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
178 dev_priv->czclk_freq);
181 /* WA Display #0827: Gen9:all */
183 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
186 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
187 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
189 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
190 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
193 /* Wa_2006604312:icl,ehl */
195 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
199 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
200 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
202 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
203 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
207 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
209 return crtc_state->master_transcoder != INVALID_TRANSCODER;
213 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
215 return crtc_state->sync_mode_slaves_mask != 0;
219 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
221 return is_trans_port_sync_master(crtc_state) ||
222 is_trans_port_sync_slave(crtc_state);
225 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
228 i915_reg_t reg = PIPEDSL(pipe);
232 if (IS_GEN(dev_priv, 2))
233 line_mask = DSL_LINEMASK_GEN2;
235 line_mask = DSL_LINEMASK_GEN3;
237 line1 = intel_de_read(dev_priv, reg) & line_mask;
239 line2 = intel_de_read(dev_priv, reg) & line_mask;
241 return line1 != line2;
244 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
246 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
247 enum pipe pipe = crtc->pipe;
249 /* Wait for the display line to settle/start moving */
250 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
251 drm_err(&dev_priv->drm,
252 "pipe %c scanline %s wait timed out\n",
253 pipe_name(pipe), onoff(state));
256 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
258 wait_for_pipe_scanline_moving(crtc, false);
261 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
263 wait_for_pipe_scanline_moving(crtc, true);
267 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
269 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
270 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
272 if (INTEL_GEN(dev_priv) >= 4) {
273 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
274 i915_reg_t reg = PIPECONF(cpu_transcoder);
276 /* Wait for the Pipe State to go off */
277 if (intel_de_wait_for_clear(dev_priv, reg,
278 I965_PIPECONF_ACTIVE, 100))
279 drm_WARN(&dev_priv->drm, 1,
280 "pipe_off wait timed out\n");
282 intel_wait_for_pipe_scanline_stopped(crtc);
286 /* Only for pre-ILK configs */
287 void assert_pll(struct drm_i915_private *dev_priv,
288 enum pipe pipe, bool state)
293 val = intel_de_read(dev_priv, DPLL(pipe));
294 cur_state = !!(val & DPLL_VCO_ENABLE);
295 I915_STATE_WARN(cur_state != state,
296 "PLL state assertion failure (expected %s, current %s)\n",
297 onoff(state), onoff(cur_state));
300 /* XXX: the dsi pll is shared between MIPI DSI ports */
301 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
306 vlv_cck_get(dev_priv);
307 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
308 vlv_cck_put(dev_priv);
310 cur_state = val & DSI_PLL_VCO_EN;
311 I915_STATE_WARN(cur_state != state,
312 "DSI PLL state assertion failure (expected %s, current %s)\n",
313 onoff(state), onoff(cur_state));
316 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
317 enum pipe pipe, bool state)
321 if (HAS_DDI(dev_priv)) {
323 * DDI does not have a specific FDI_TX register.
325 * FDI is never fed from EDP transcoder
326 * so pipe->transcoder cast is fine here.
328 enum transcoder cpu_transcoder = (enum transcoder)pipe;
329 u32 val = intel_de_read(dev_priv,
330 TRANS_DDI_FUNC_CTL(cpu_transcoder));
331 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
333 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
334 cur_state = !!(val & FDI_TX_ENABLE);
336 I915_STATE_WARN(cur_state != state,
337 "FDI TX state assertion failure (expected %s, current %s)\n",
338 onoff(state), onoff(cur_state));
340 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
341 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
343 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
344 enum pipe pipe, bool state)
349 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
350 cur_state = !!(val & FDI_RX_ENABLE);
351 I915_STATE_WARN(cur_state != state,
352 "FDI RX state assertion failure (expected %s, current %s)\n",
353 onoff(state), onoff(cur_state));
355 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
356 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
358 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
363 /* ILK FDI PLL is always enabled */
364 if (IS_GEN(dev_priv, 5))
367 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
368 if (HAS_DDI(dev_priv))
371 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
372 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
375 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
376 enum pipe pipe, bool state)
381 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
382 cur_state = !!(val & FDI_RX_PLL_ENABLE);
383 I915_STATE_WARN(cur_state != state,
384 "FDI RX PLL assertion failure (expected %s, current %s)\n",
385 onoff(state), onoff(cur_state));
388 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
392 enum pipe panel_pipe = INVALID_PIPE;
395 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
398 if (HAS_PCH_SPLIT(dev_priv)) {
401 pp_reg = PP_CONTROL(0);
402 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
405 case PANEL_PORT_SELECT_LVDS:
406 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
408 case PANEL_PORT_SELECT_DPA:
409 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
411 case PANEL_PORT_SELECT_DPC:
412 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
414 case PANEL_PORT_SELECT_DPD:
415 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
418 MISSING_CASE(port_sel);
421 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
422 /* presumably write lock depends on pipe, not port select */
423 pp_reg = PP_CONTROL(pipe);
428 pp_reg = PP_CONTROL(0);
429 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
431 drm_WARN_ON(&dev_priv->drm,
432 port_sel != PANEL_PORT_SELECT_LVDS);
433 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
436 val = intel_de_read(dev_priv, pp_reg);
437 if (!(val & PANEL_POWER_ON) ||
438 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
441 I915_STATE_WARN(panel_pipe == pipe && locked,
442 "panel assertion failure, pipe %c regs locked\n",
446 void assert_pipe(struct drm_i915_private *dev_priv,
447 enum transcoder cpu_transcoder, bool state)
450 enum intel_display_power_domain power_domain;
451 intel_wakeref_t wakeref;
453 /* we keep both pipes enabled on 830 */
454 if (IS_I830(dev_priv))
457 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
458 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
460 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
461 cur_state = !!(val & PIPECONF_ENABLE);
463 intel_display_power_put(dev_priv, power_domain, wakeref);
468 I915_STATE_WARN(cur_state != state,
469 "transcoder %s assertion failure (expected %s, current %s)\n",
470 transcoder_name(cpu_transcoder),
471 onoff(state), onoff(cur_state));
474 static void assert_plane(struct intel_plane *plane, bool state)
479 cur_state = plane->get_hw_state(plane, &pipe);
481 I915_STATE_WARN(cur_state != state,
482 "%s assertion failure (expected %s, current %s)\n",
483 plane->base.name, onoff(state), onoff(cur_state));
486 #define assert_plane_enabled(p) assert_plane(p, true)
487 #define assert_plane_disabled(p) assert_plane(p, false)
489 static void assert_planes_disabled(struct intel_crtc *crtc)
491 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
492 struct intel_plane *plane;
494 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
495 assert_plane_disabled(plane);
498 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
504 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
505 enabled = !!(val & TRANS_ENABLE);
506 I915_STATE_WARN(enabled,
507 "transcoder assertion failed, should be off on pipe %c but is still active\n",
511 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
512 enum pipe pipe, enum port port,
518 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
520 I915_STATE_WARN(state && port_pipe == pipe,
521 "PCH DP %c enabled on transcoder %c, should be disabled\n",
522 port_name(port), pipe_name(pipe));
524 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
525 "IBX PCH DP %c still using transcoder B\n",
529 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
530 enum pipe pipe, enum port port,
536 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
538 I915_STATE_WARN(state && port_pipe == pipe,
539 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
540 port_name(port), pipe_name(pipe));
542 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
543 "IBX PCH HDMI %c still using transcoder B\n",
547 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
552 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
553 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
554 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
556 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
558 "PCH VGA enabled on transcoder %c, should be disabled\n",
561 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
563 "PCH LVDS enabled on transcoder %c, should be disabled\n",
566 /* PCH SDVOB multiplex with HDMIB */
567 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
568 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
569 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
572 static void _vlv_enable_pll(struct intel_crtc *crtc,
573 const struct intel_crtc_state *pipe_config)
575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
576 enum pipe pipe = crtc->pipe;
578 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
579 intel_de_posting_read(dev_priv, DPLL(pipe));
582 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
583 drm_err(&dev_priv->drm, "DPLL %d failed to lock\n", pipe);
586 static void vlv_enable_pll(struct intel_crtc *crtc,
587 const struct intel_crtc_state *pipe_config)
589 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
590 enum pipe pipe = crtc->pipe;
592 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
594 /* PLL is protected by panel, make sure we can write it */
595 assert_panel_unlocked(dev_priv, pipe);
597 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
598 _vlv_enable_pll(crtc, pipe_config);
600 intel_de_write(dev_priv, DPLL_MD(pipe),
601 pipe_config->dpll_hw_state.dpll_md);
602 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
606 static void _chv_enable_pll(struct intel_crtc *crtc,
607 const struct intel_crtc_state *pipe_config)
609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
610 enum pipe pipe = crtc->pipe;
611 enum dpio_channel port = vlv_pipe_to_channel(pipe);
614 vlv_dpio_get(dev_priv);
616 /* Enable back the 10bit clock to display controller */
617 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
618 tmp |= DPIO_DCLKP_EN;
619 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
621 vlv_dpio_put(dev_priv);
624 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
629 intel_de_write(dev_priv, DPLL(pipe), pipe_config->dpll_hw_state.dpll);
631 /* Check PLL is locked */
632 if (intel_de_wait_for_set(dev_priv, DPLL(pipe), DPLL_LOCK_VLV, 1))
633 drm_err(&dev_priv->drm, "PLL %d failed to lock\n", pipe);
636 static void chv_enable_pll(struct intel_crtc *crtc,
637 const struct intel_crtc_state *pipe_config)
639 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
640 enum pipe pipe = crtc->pipe;
642 assert_pipe_disabled(dev_priv, pipe_config->cpu_transcoder);
644 /* PLL is protected by panel, make sure we can write it */
645 assert_panel_unlocked(dev_priv, pipe);
647 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
648 _chv_enable_pll(crtc, pipe_config);
650 if (pipe != PIPE_A) {
652 * WaPixelRepeatModeFixForC0:chv
654 * DPLLCMD is AWOL. Use chicken bits to propagate
655 * the value from DPLLBMD to either pipe B or C.
657 intel_de_write(dev_priv, CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
658 intel_de_write(dev_priv, DPLL_MD(PIPE_B),
659 pipe_config->dpll_hw_state.dpll_md);
660 intel_de_write(dev_priv, CBR4_VLV, 0);
661 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
664 * DPLLB VGA mode also seems to cause problems.
665 * We should always have it disabled.
667 drm_WARN_ON(&dev_priv->drm,
668 (intel_de_read(dev_priv, DPLL(PIPE_B)) &
669 DPLL_VGA_MODE_DIS) == 0);
671 intel_de_write(dev_priv, DPLL_MD(pipe),
672 pipe_config->dpll_hw_state.dpll_md);
673 intel_de_posting_read(dev_priv, DPLL_MD(pipe));
677 static bool i9xx_has_pps(struct drm_i915_private *dev_priv)
679 if (IS_I830(dev_priv))
682 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
685 static void i9xx_enable_pll(struct intel_crtc *crtc,
686 const struct intel_crtc_state *crtc_state)
688 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
689 i915_reg_t reg = DPLL(crtc->pipe);
690 u32 dpll = crtc_state->dpll_hw_state.dpll;
693 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
695 /* PLL is protected by panel, make sure we can write it */
696 if (i9xx_has_pps(dev_priv))
697 assert_panel_unlocked(dev_priv, crtc->pipe);
700 * Apparently we need to have VGA mode enabled prior to changing
701 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
702 * dividers, even though the register value does change.
704 intel_de_write(dev_priv, reg, dpll & ~DPLL_VGA_MODE_DIS);
705 intel_de_write(dev_priv, reg, dpll);
707 /* Wait for the clocks to stabilize. */
708 intel_de_posting_read(dev_priv, reg);
711 if (INTEL_GEN(dev_priv) >= 4) {
712 intel_de_write(dev_priv, DPLL_MD(crtc->pipe),
713 crtc_state->dpll_hw_state.dpll_md);
715 /* The pixel multiplier can only be updated once the
716 * DPLL is enabled and the clocks are stable.
720 intel_de_write(dev_priv, reg, dpll);
723 /* We do this three times for luck */
724 for (i = 0; i < 3; i++) {
725 intel_de_write(dev_priv, reg, dpll);
726 intel_de_posting_read(dev_priv, reg);
727 udelay(150); /* wait for warmup */
731 static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
733 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
734 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
735 enum pipe pipe = crtc->pipe;
737 /* Don't disable pipe or pipe PLLs if needed */
738 if (IS_I830(dev_priv))
741 /* Make sure the pipe isn't still relying on us */
742 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
744 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
745 intel_de_posting_read(dev_priv, DPLL(pipe));
748 static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
752 /* Make sure the pipe isn't still relying on us */
753 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
755 val = DPLL_INTEGRATED_REF_CLK_VLV |
756 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
758 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
760 intel_de_write(dev_priv, DPLL(pipe), val);
761 intel_de_posting_read(dev_priv, DPLL(pipe));
764 static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
766 enum dpio_channel port = vlv_pipe_to_channel(pipe);
769 /* Make sure the pipe isn't still relying on us */
770 assert_pipe_disabled(dev_priv, (enum transcoder)pipe);
772 val = DPLL_SSC_REF_CLK_CHV |
773 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
775 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
777 intel_de_write(dev_priv, DPLL(pipe), val);
778 intel_de_posting_read(dev_priv, DPLL(pipe));
780 vlv_dpio_get(dev_priv);
782 /* Disable 10bit clock to display controller */
783 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
784 val &= ~DPIO_DCLKP_EN;
785 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
787 vlv_dpio_put(dev_priv);
790 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
791 struct intel_digital_port *dig_port,
792 unsigned int expected_mask)
797 switch (dig_port->base.port) {
799 port_mask = DPLL_PORTB_READY_MASK;
803 port_mask = DPLL_PORTC_READY_MASK;
808 port_mask = DPLL_PORTD_READY_MASK;
809 dpll_reg = DPIO_PHY_STATUS;
815 if (intel_de_wait_for_register(dev_priv, dpll_reg,
816 port_mask, expected_mask, 1000))
817 drm_WARN(&dev_priv->drm, 1,
818 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
819 dig_port->base.base.base.id, dig_port->base.base.name,
820 intel_de_read(dev_priv, dpll_reg) & port_mask,
824 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
826 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
827 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
828 enum pipe pipe = crtc->pipe;
830 u32 val, pipeconf_val;
832 /* Make sure PCH DPLL is enabled */
833 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
835 /* FDI must be feeding us bits for PCH ports */
836 assert_fdi_tx_enabled(dev_priv, pipe);
837 assert_fdi_rx_enabled(dev_priv, pipe);
839 if (HAS_PCH_CPT(dev_priv)) {
840 reg = TRANS_CHICKEN2(pipe);
841 val = intel_de_read(dev_priv, reg);
843 * Workaround: Set the timing override bit
844 * before enabling the pch transcoder.
846 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
847 /* Configure frame start delay to match the CPU */
848 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
849 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
850 intel_de_write(dev_priv, reg, val);
853 reg = PCH_TRANSCONF(pipe);
854 val = intel_de_read(dev_priv, reg);
855 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
857 if (HAS_PCH_IBX(dev_priv)) {
858 /* Configure frame start delay to match the CPU */
859 val &= ~TRANS_FRAME_START_DELAY_MASK;
860 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
863 * Make the BPC in transcoder be consistent with
864 * that in pipeconf reg. For HDMI we must use 8bpc
865 * here for both 8bpc and 12bpc.
867 val &= ~PIPECONF_BPC_MASK;
868 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
869 val |= PIPECONF_8BPC;
871 val |= pipeconf_val & PIPECONF_BPC_MASK;
874 val &= ~TRANS_INTERLACE_MASK;
875 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
876 if (HAS_PCH_IBX(dev_priv) &&
877 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
878 val |= TRANS_LEGACY_INTERLACED_ILK;
880 val |= TRANS_INTERLACED;
882 val |= TRANS_PROGRESSIVE;
885 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
886 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
887 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
891 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
892 enum transcoder cpu_transcoder)
894 u32 val, pipeconf_val;
896 /* FDI must be feeding us bits for PCH ports */
897 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
898 assert_fdi_rx_enabled(dev_priv, PIPE_A);
900 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
901 /* Workaround: set timing override bit. */
902 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
903 /* Configure frame start delay to match the CPU */
904 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
905 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
906 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
909 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
911 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
912 PIPECONF_INTERLACED_ILK)
913 val |= TRANS_INTERLACED;
915 val |= TRANS_PROGRESSIVE;
917 intel_de_write(dev_priv, LPT_TRANSCONF, val);
918 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
919 TRANS_STATE_ENABLE, 100))
920 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
923 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
929 /* FDI relies on the transcoder */
930 assert_fdi_tx_disabled(dev_priv, pipe);
931 assert_fdi_rx_disabled(dev_priv, pipe);
933 /* Ports must be off as well */
934 assert_pch_ports_disabled(dev_priv, pipe);
936 reg = PCH_TRANSCONF(pipe);
937 val = intel_de_read(dev_priv, reg);
938 val &= ~TRANS_ENABLE;
939 intel_de_write(dev_priv, reg, val);
940 /* wait for PCH transcoder off, transcoder state */
941 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
942 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
945 if (HAS_PCH_CPT(dev_priv)) {
946 /* Workaround: Clear the timing override chicken bit again. */
947 reg = TRANS_CHICKEN2(pipe);
948 val = intel_de_read(dev_priv, reg);
949 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
950 intel_de_write(dev_priv, reg, val);
954 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
958 val = intel_de_read(dev_priv, LPT_TRANSCONF);
959 val &= ~TRANS_ENABLE;
960 intel_de_write(dev_priv, LPT_TRANSCONF, val);
961 /* wait for PCH transcoder off, transcoder state */
962 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
963 TRANS_STATE_ENABLE, 50))
964 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
966 /* Workaround: clear timing override bit. */
967 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
968 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
969 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
972 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
974 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
976 if (HAS_PCH_LPT(dev_priv))
982 void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
984 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
985 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
986 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
987 enum pipe pipe = crtc->pipe;
991 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
993 assert_planes_disabled(crtc);
996 * A pipe without a PLL won't actually be able to drive bits from
997 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1000 if (HAS_GMCH(dev_priv)) {
1001 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
1002 assert_dsi_pll_enabled(dev_priv);
1004 assert_pll_enabled(dev_priv, pipe);
1006 if (new_crtc_state->has_pch_encoder) {
1007 /* if driving the PCH, we need FDI enabled */
1008 assert_fdi_rx_pll_enabled(dev_priv,
1009 intel_crtc_pch_transcoder(crtc));
1010 assert_fdi_tx_pll_enabled(dev_priv,
1011 (enum pipe) cpu_transcoder);
1013 /* FIXME: assert CPU port conditions for SNB+ */
1016 trace_intel_pipe_enable(crtc);
1018 reg = PIPECONF(cpu_transcoder);
1019 val = intel_de_read(dev_priv, reg);
1020 if (val & PIPECONF_ENABLE) {
1021 /* we keep both pipes enabled on 830 */
1022 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
1026 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
1027 intel_de_posting_read(dev_priv, reg);
1030 * Until the pipe starts PIPEDSL reads will return a stale value,
1031 * which causes an apparent vblank timestamp jump when PIPEDSL
1032 * resets to its proper value. That also messes up the frame count
1033 * when it's derived from the timestamps. So let's wait for the
1034 * pipe to start properly before we call drm_crtc_vblank_on()
1036 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1037 intel_wait_for_pipe_scanline_moving(crtc);
1040 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1042 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1043 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1044 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1045 enum pipe pipe = crtc->pipe;
1049 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
1052 * Make sure planes won't keep trying to pump pixels to us,
1053 * or we might hang the display.
1055 assert_planes_disabled(crtc);
1057 trace_intel_pipe_disable(crtc);
1059 reg = PIPECONF(cpu_transcoder);
1060 val = intel_de_read(dev_priv, reg);
1061 if ((val & PIPECONF_ENABLE) == 0)
1065 * Double wide has implications for planes
1066 * so best keep it disabled when not needed.
1068 if (old_crtc_state->double_wide)
1069 val &= ~PIPECONF_DOUBLE_WIDE;
1071 /* Don't disable pipe or pipe PLLs if needed */
1072 if (!IS_I830(dev_priv))
1073 val &= ~PIPECONF_ENABLE;
1075 intel_de_write(dev_priv, reg, val);
1076 if ((val & PIPECONF_ENABLE) == 0)
1077 intel_wait_for_pipe_off(old_crtc_state);
1080 static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1082 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
1085 static bool is_ccs_plane(const struct drm_framebuffer *fb, int plane)
1087 if (!is_ccs_modifier(fb->modifier))
1090 return plane >= fb->format->num_planes / 2;
1093 static bool is_gen12_ccs_modifier(u64 modifier)
1095 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
1096 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC ||
1097 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
1100 static bool is_gen12_ccs_plane(const struct drm_framebuffer *fb, int plane)
1102 return is_gen12_ccs_modifier(fb->modifier) && is_ccs_plane(fb, plane);
1105 static bool is_gen12_ccs_cc_plane(const struct drm_framebuffer *fb, int plane)
1107 return fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC &&
1111 static bool is_aux_plane(const struct drm_framebuffer *fb, int plane)
1113 if (is_ccs_modifier(fb->modifier))
1114 return is_ccs_plane(fb, plane);
1119 static int main_to_ccs_plane(const struct drm_framebuffer *fb, int main_plane)
1121 drm_WARN_ON(fb->dev, !is_ccs_modifier(fb->modifier) ||
1122 (main_plane && main_plane >= fb->format->num_planes / 2));
1124 return fb->format->num_planes / 2 + main_plane;
1127 static int ccs_to_main_plane(const struct drm_framebuffer *fb, int ccs_plane)
1129 drm_WARN_ON(fb->dev, !is_ccs_modifier(fb->modifier) ||
1130 ccs_plane < fb->format->num_planes / 2);
1132 if (is_gen12_ccs_cc_plane(fb, ccs_plane))
1135 return ccs_plane - fb->format->num_planes / 2;
1138 int intel_main_to_aux_plane(const struct drm_framebuffer *fb, int main_plane)
1140 struct drm_i915_private *i915 = to_i915(fb->dev);
1142 if (is_ccs_modifier(fb->modifier))
1143 return main_to_ccs_plane(fb, main_plane);
1144 else if (INTEL_GEN(i915) < 11 &&
1145 intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
1152 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1155 return info->is_yuv &&
1156 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
1159 static bool is_semiplanar_uv_plane(const struct drm_framebuffer *fb,
1162 return intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1167 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1169 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1170 unsigned int cpp = fb->format->cpp[color_plane];
1172 switch (fb->modifier) {
1173 case DRM_FORMAT_MOD_LINEAR:
1174 return intel_tile_size(dev_priv);
1175 case I915_FORMAT_MOD_X_TILED:
1176 if (IS_GEN(dev_priv, 2))
1180 case I915_FORMAT_MOD_Y_TILED_CCS:
1181 if (is_ccs_plane(fb, color_plane))
1184 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1185 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1186 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1187 if (is_ccs_plane(fb, color_plane))
1190 case I915_FORMAT_MOD_Y_TILED:
1191 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
1195 case I915_FORMAT_MOD_Yf_TILED_CCS:
1196 if (is_ccs_plane(fb, color_plane))
1199 case I915_FORMAT_MOD_Yf_TILED:
1215 MISSING_CASE(fb->modifier);
1221 intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
1223 if (is_gen12_ccs_plane(fb, color_plane))
1226 return intel_tile_size(to_i915(fb->dev)) /
1227 intel_tile_width_bytes(fb, color_plane);
1230 /* Return the tile dimensions in pixel units */
1231 static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
1232 unsigned int *tile_width,
1233 unsigned int *tile_height)
1235 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1236 unsigned int cpp = fb->format->cpp[color_plane];
1238 *tile_width = tile_width_bytes / cpp;
1239 *tile_height = intel_tile_height(fb, color_plane);
1242 static unsigned int intel_tile_row_size(const struct drm_framebuffer *fb,
1245 unsigned int tile_width, tile_height;
1247 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
1249 return fb->pitches[color_plane] * tile_height;
1253 intel_fb_align_height(const struct drm_framebuffer *fb,
1254 int color_plane, unsigned int height)
1256 unsigned int tile_height = intel_tile_height(fb, color_plane);
1258 return ALIGN(height, tile_height);
1261 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1263 unsigned int size = 0;
1266 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1267 size += rot_info->plane[i].width * rot_info->plane[i].height;
1272 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
1274 unsigned int size = 0;
1277 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
1278 size += rem_info->plane[i].width * rem_info->plane[i].height;
1284 intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1285 const struct drm_framebuffer *fb,
1286 unsigned int rotation)
1288 view->type = I915_GGTT_VIEW_NORMAL;
1289 if (drm_rotation_90_or_270(rotation)) {
1290 view->type = I915_GGTT_VIEW_ROTATED;
1291 view->rotated = to_intel_framebuffer(fb)->rot_info;
1295 static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1297 if (IS_I830(dev_priv))
1299 else if (IS_I85X(dev_priv))
1301 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1307 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
1309 if (INTEL_GEN(dev_priv) >= 9)
1311 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
1312 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1314 else if (INTEL_GEN(dev_priv) >= 4)
1320 static bool has_async_flips(struct drm_i915_private *i915)
1322 return INTEL_GEN(i915) >= 5;
1325 static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
1328 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1330 /* AUX_DIST needs only 4K alignment */
1331 if ((INTEL_GEN(dev_priv) < 12 && is_aux_plane(fb, color_plane)) ||
1332 is_ccs_plane(fb, color_plane))
1335 switch (fb->modifier) {
1336 case DRM_FORMAT_MOD_LINEAR:
1337 return intel_linear_alignment(dev_priv);
1338 case I915_FORMAT_MOD_X_TILED:
1339 if (has_async_flips(dev_priv))
1342 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1343 if (is_semiplanar_uv_plane(fb, color_plane))
1344 return intel_tile_row_size(fb, color_plane);
1346 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1347 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1349 case I915_FORMAT_MOD_Y_TILED_CCS:
1350 case I915_FORMAT_MOD_Yf_TILED_CCS:
1351 case I915_FORMAT_MOD_Y_TILED:
1352 if (INTEL_GEN(dev_priv) >= 12 &&
1353 is_semiplanar_uv_plane(fb, color_plane))
1354 return intel_tile_row_size(fb, color_plane);
1356 case I915_FORMAT_MOD_Yf_TILED:
1357 return 1 * 1024 * 1024;
1359 MISSING_CASE(fb->modifier);
1364 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
1366 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1367 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1369 return INTEL_GEN(dev_priv) < 4 ||
1371 plane_state->view.type == I915_GGTT_VIEW_NORMAL);
1375 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
1376 const struct i915_ggtt_view *view,
1378 unsigned long *out_flags)
1380 struct drm_device *dev = fb->dev;
1381 struct drm_i915_private *dev_priv = to_i915(dev);
1382 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1383 intel_wakeref_t wakeref;
1384 struct i915_vma *vma;
1385 unsigned int pinctl;
1388 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
1389 return ERR_PTR(-EINVAL);
1391 alignment = intel_surf_alignment(fb, 0);
1392 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
1393 return ERR_PTR(-EINVAL);
1395 /* Note that the w/a also requires 64 PTE of padding following the
1396 * bo. We currently fill all unused PTE with the shadow page and so
1397 * we should always have valid PTE following the scanout preventing
1400 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
1401 alignment = 256 * 1024;
1404 * Global gtt pte registers are special registers which actually forward
1405 * writes to a chunk of system memory. Which means that there is no risk
1406 * that the register values disappear as soon as we call
1407 * intel_runtime_pm_put(), so it is correct to wrap only the
1408 * pin/unpin/fence and not more.
1410 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
1412 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
1415 * Valleyview is definitely limited to scanning out the first
1416 * 512MiB. Lets presume this behaviour was inherited from the
1417 * g4x display engine and that all earlier gen are similarly
1418 * limited. Testing suggests that it is a little more
1419 * complicated than this. For example, Cherryview appears quite
1420 * happy to scanout from anywhere within its global aperture.
1423 if (HAS_GMCH(dev_priv))
1424 pinctl |= PIN_MAPPABLE;
1426 vma = i915_gem_object_pin_to_display_plane(obj,
1427 alignment, view, pinctl);
1431 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
1435 * Install a fence for tiled scan-out. Pre-i965 always needs a
1436 * fence, whereas 965+ only requires a fence if using
1437 * framebuffer compression. For simplicity, we always, when
1438 * possible, install a fence as the cost is not that onerous.
1440 * If we fail to fence the tiled scanout, then either the
1441 * modeset will reject the change (which is highly unlikely as
1442 * the affected systems, all but one, do not have unmappable
1443 * space) or we will not be able to enable full powersaving
1444 * techniques (also likely not to apply due to various limits
1445 * FBC and the like impose on the size of the buffer, which
1446 * presumably we violated anyway with this unmappable buffer).
1447 * Anyway, it is presumably better to stumble onwards with
1448 * something and try to run the system in a "less than optimal"
1449 * mode that matches the user configuration.
1451 ret = i915_vma_pin_fence(vma);
1452 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
1453 i915_gem_object_unpin_from_display_plane(vma);
1458 if (ret == 0 && vma->fence)
1459 *out_flags |= PLANE_HAS_FENCE;
1464 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
1465 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
1469 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
1471 i915_gem_object_lock(vma->obj, NULL);
1472 if (flags & PLANE_HAS_FENCE)
1473 i915_vma_unpin_fence(vma);
1474 i915_gem_object_unpin_from_display_plane(vma);
1475 i915_gem_object_unlock(vma->obj);
1480 static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
1481 unsigned int rotation)
1483 if (drm_rotation_90_or_270(rotation))
1484 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
1486 return fb->pitches[color_plane];
1490 * Convert the x/y offsets into a linear offset.
1491 * Only valid with 0/180 degree rotation, which is fine since linear
1492 * offset is only used with linear buffers on pre-hsw and tiled buffers
1493 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
1495 u32 intel_fb_xy_to_linear(int x, int y,
1496 const struct intel_plane_state *state,
1499 const struct drm_framebuffer *fb = state->hw.fb;
1500 unsigned int cpp = fb->format->cpp[color_plane];
1501 unsigned int pitch = state->color_plane[color_plane].stride;
1503 return y * pitch + x * cpp;
1507 * Add the x/y offsets derived from fb->offsets[] to the user
1508 * specified plane src x/y offsets. The resulting x/y offsets
1509 * specify the start of scanout from the beginning of the gtt mapping.
1511 void intel_add_fb_offsets(int *x, int *y,
1512 const struct intel_plane_state *state,
1516 *x += state->color_plane[color_plane].x;
1517 *y += state->color_plane[color_plane].y;
1520 static u32 intel_adjust_tile_offset(int *x, int *y,
1521 unsigned int tile_width,
1522 unsigned int tile_height,
1523 unsigned int tile_size,
1524 unsigned int pitch_tiles,
1528 unsigned int pitch_pixels = pitch_tiles * tile_width;
1531 WARN_ON(old_offset & (tile_size - 1));
1532 WARN_ON(new_offset & (tile_size - 1));
1533 WARN_ON(new_offset > old_offset);
1535 tiles = (old_offset - new_offset) / tile_size;
1537 *y += tiles / pitch_tiles * tile_height;
1538 *x += tiles % pitch_tiles * tile_width;
1540 /* minimize x in case it got needlessly big */
1541 *y += *x / pitch_pixels * tile_height;
1547 static bool is_surface_linear(const struct drm_framebuffer *fb, int color_plane)
1549 return fb->modifier == DRM_FORMAT_MOD_LINEAR ||
1550 is_gen12_ccs_plane(fb, color_plane);
1553 static u32 intel_adjust_aligned_offset(int *x, int *y,
1554 const struct drm_framebuffer *fb,
1556 unsigned int rotation,
1558 u32 old_offset, u32 new_offset)
1560 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1561 unsigned int cpp = fb->format->cpp[color_plane];
1563 drm_WARN_ON(&dev_priv->drm, new_offset > old_offset);
1565 if (!is_surface_linear(fb, color_plane)) {
1566 unsigned int tile_size, tile_width, tile_height;
1567 unsigned int pitch_tiles;
1569 tile_size = intel_tile_size(dev_priv);
1570 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
1572 if (drm_rotation_90_or_270(rotation)) {
1573 pitch_tiles = pitch / tile_height;
1574 swap(tile_width, tile_height);
1576 pitch_tiles = pitch / (tile_width * cpp);
1579 intel_adjust_tile_offset(x, y, tile_width, tile_height,
1580 tile_size, pitch_tiles,
1581 old_offset, new_offset);
1583 old_offset += *y * pitch + *x * cpp;
1585 *y = (old_offset - new_offset) / pitch;
1586 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
1593 * Adjust the tile offset by moving the difference into
1596 static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
1597 const struct intel_plane_state *state,
1599 u32 old_offset, u32 new_offset)
1601 return intel_adjust_aligned_offset(x, y, state->hw.fb, color_plane,
1603 state->color_plane[color_plane].stride,
1604 old_offset, new_offset);
1608 * Computes the aligned offset to the base tile and adjusts
1609 * x, y. bytes per pixel is assumed to be a power-of-two.
1611 * In the 90/270 rotated case, x and y are assumed
1612 * to be already rotated to match the rotated GTT view, and
1613 * pitch is the tile_height aligned framebuffer height.
1615 * This function is used when computing the derived information
1616 * under intel_framebuffer, so using any of that information
1617 * here is not allowed. Anything under drm_framebuffer can be
1618 * used. This is why the user has to pass in the pitch since it
1619 * is specified in the rotated orientation.
1621 static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
1623 const struct drm_framebuffer *fb,
1626 unsigned int rotation,
1629 unsigned int cpp = fb->format->cpp[color_plane];
1630 u32 offset, offset_aligned;
1632 if (!is_surface_linear(fb, color_plane)) {
1633 unsigned int tile_size, tile_width, tile_height;
1634 unsigned int tile_rows, tiles, pitch_tiles;
1636 tile_size = intel_tile_size(dev_priv);
1637 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
1639 if (drm_rotation_90_or_270(rotation)) {
1640 pitch_tiles = pitch / tile_height;
1641 swap(tile_width, tile_height);
1643 pitch_tiles = pitch / (tile_width * cpp);
1646 tile_rows = *y / tile_height;
1649 tiles = *x / tile_width;
1652 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
1654 offset_aligned = offset;
1656 offset_aligned = rounddown(offset_aligned, alignment);
1658 intel_adjust_tile_offset(x, y, tile_width, tile_height,
1659 tile_size, pitch_tiles,
1660 offset, offset_aligned);
1662 offset = *y * pitch + *x * cpp;
1663 offset_aligned = offset;
1665 offset_aligned = rounddown(offset_aligned, alignment);
1666 *y = (offset % alignment) / pitch;
1667 *x = ((offset % alignment) - *y * pitch) / cpp;
1673 return offset_aligned;
1676 u32 intel_plane_compute_aligned_offset(int *x, int *y,
1677 const struct intel_plane_state *state,
1680 struct intel_plane *intel_plane = to_intel_plane(state->uapi.plane);
1681 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
1682 const struct drm_framebuffer *fb = state->hw.fb;
1683 unsigned int rotation = state->hw.rotation;
1684 int pitch = state->color_plane[color_plane].stride;
1687 if (intel_plane->id == PLANE_CURSOR)
1688 alignment = intel_cursor_alignment(dev_priv);
1690 alignment = intel_surf_alignment(fb, color_plane);
1692 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
1693 pitch, rotation, alignment);
1696 /* Convert the fb->offset[] into x/y offsets */
1697 static int intel_fb_offset_to_xy(int *x, int *y,
1698 const struct drm_framebuffer *fb,
1701 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1702 unsigned int height;
1705 if (INTEL_GEN(dev_priv) >= 12 &&
1706 is_semiplanar_uv_plane(fb, color_plane))
1707 alignment = intel_tile_row_size(fb, color_plane);
1708 else if (fb->modifier != DRM_FORMAT_MOD_LINEAR)
1709 alignment = intel_tile_size(dev_priv);
1713 if (alignment != 0 && fb->offsets[color_plane] % alignment) {
1714 drm_dbg_kms(&dev_priv->drm,
1715 "Misaligned offset 0x%08x for color plane %d\n",
1716 fb->offsets[color_plane], color_plane);
1720 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
1721 height = ALIGN(height, intel_tile_height(fb, color_plane));
1723 /* Catch potential overflows early */
1724 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
1725 fb->offsets[color_plane])) {
1726 drm_dbg_kms(&dev_priv->drm,
1727 "Bad offset 0x%08x or pitch %d for color plane %d\n",
1728 fb->offsets[color_plane], fb->pitches[color_plane],
1736 intel_adjust_aligned_offset(x, y,
1737 fb, color_plane, DRM_MODE_ROTATE_0,
1738 fb->pitches[color_plane],
1739 fb->offsets[color_plane], 0);
1744 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
1746 switch (fb_modifier) {
1747 case I915_FORMAT_MOD_X_TILED:
1748 return I915_TILING_X;
1749 case I915_FORMAT_MOD_Y_TILED:
1750 case I915_FORMAT_MOD_Y_TILED_CCS:
1751 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1752 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1753 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1754 return I915_TILING_Y;
1756 return I915_TILING_NONE;
1761 * From the Sky Lake PRM:
1762 * "The Color Control Surface (CCS) contains the compression status of
1763 * the cache-line pairs. The compression state of the cache-line pair
1764 * is specified by 2 bits in the CCS. Each CCS cache-line represents
1765 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
1766 * cache-line-pairs. CCS is always Y tiled."
1768 * Since cache line pairs refers to horizontally adjacent cache lines,
1769 * each cache line in the CCS corresponds to an area of 32x16 cache
1770 * lines on the main surface. Since each pixel is 4 bytes, this gives
1771 * us a ratio of one byte in the CCS for each 8x16 pixels in the
1774 static const struct drm_format_info skl_ccs_formats[] = {
1775 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1776 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1777 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1778 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1779 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1780 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1781 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1782 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1786 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
1787 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
1788 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
1789 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
1792 static const struct drm_format_info gen12_ccs_formats[] = {
1793 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1794 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1795 .hsub = 1, .vsub = 1, },
1796 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1797 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1798 .hsub = 1, .vsub = 1, },
1799 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1800 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1801 .hsub = 1, .vsub = 1, .has_alpha = true },
1802 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1803 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1804 .hsub = 1, .vsub = 1, .has_alpha = true },
1805 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
1806 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1807 .hsub = 2, .vsub = 1, .is_yuv = true },
1808 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
1809 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1810 .hsub = 2, .vsub = 1, .is_yuv = true },
1811 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
1812 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1813 .hsub = 2, .vsub = 1, .is_yuv = true },
1814 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
1815 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1816 .hsub = 2, .vsub = 1, .is_yuv = true },
1817 { .format = DRM_FORMAT_NV12, .num_planes = 4,
1818 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
1819 .hsub = 2, .vsub = 2, .is_yuv = true },
1820 { .format = DRM_FORMAT_P010, .num_planes = 4,
1821 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1822 .hsub = 2, .vsub = 2, .is_yuv = true },
1823 { .format = DRM_FORMAT_P012, .num_planes = 4,
1824 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1825 .hsub = 2, .vsub = 2, .is_yuv = true },
1826 { .format = DRM_FORMAT_P016, .num_planes = 4,
1827 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1828 .hsub = 2, .vsub = 2, .is_yuv = true },
1832 * Same as gen12_ccs_formats[] above, but with additional surface used
1833 * to pass Clear Color information in plane 2 with 64 bits of data.
1835 static const struct drm_format_info gen12_ccs_cc_formats[] = {
1836 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 3,
1837 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1838 .hsub = 1, .vsub = 1, },
1839 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 3,
1840 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1841 .hsub = 1, .vsub = 1, },
1842 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 3,
1843 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1844 .hsub = 1, .vsub = 1, .has_alpha = true },
1845 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 3,
1846 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1847 .hsub = 1, .vsub = 1, .has_alpha = true },
1850 static const struct drm_format_info *
1851 lookup_format_info(const struct drm_format_info formats[],
1852 int num_formats, u32 format)
1856 for (i = 0; i < num_formats; i++) {
1857 if (formats[i].format == format)
1864 static const struct drm_format_info *
1865 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
1867 switch (cmd->modifier[0]) {
1868 case I915_FORMAT_MOD_Y_TILED_CCS:
1869 case I915_FORMAT_MOD_Yf_TILED_CCS:
1870 return lookup_format_info(skl_ccs_formats,
1871 ARRAY_SIZE(skl_ccs_formats),
1873 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1874 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1875 return lookup_format_info(gen12_ccs_formats,
1876 ARRAY_SIZE(gen12_ccs_formats),
1878 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1879 return lookup_format_info(gen12_ccs_cc_formats,
1880 ARRAY_SIZE(gen12_ccs_cc_formats),
1887 bool is_ccs_modifier(u64 modifier)
1889 return modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
1890 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC ||
1891 modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS ||
1892 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
1893 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
1896 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
1898 return DIV_ROUND_UP(fb->pitches[ccs_to_main_plane(fb, ccs_plane)],
1902 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
1903 u32 pixel_format, u64 modifier)
1905 struct intel_crtc *crtc;
1906 struct intel_plane *plane;
1909 * We assume the primary plane for pipe A has
1910 * the highest stride limits of them all,
1911 * if in case pipe A is disabled, use the first pipe from pipe_mask.
1913 crtc = intel_get_first_crtc(dev_priv);
1917 plane = to_intel_plane(crtc->base.primary);
1919 return plane->max_stride(plane, pixel_format, modifier,
1924 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
1925 u32 pixel_format, u64 modifier)
1928 * Arbitrary limit for gen4+ chosen to match the
1929 * render engine max stride.
1931 * The new CCS hash mode makes remapping impossible
1933 if (!is_ccs_modifier(modifier)) {
1934 if (INTEL_GEN(dev_priv) >= 7)
1936 else if (INTEL_GEN(dev_priv) >= 4)
1940 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
1944 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
1946 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1949 if (is_surface_linear(fb, color_plane)) {
1950 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
1955 * To make remapping with linear generally feasible
1956 * we need the stride to be page aligned.
1958 if (fb->pitches[color_plane] > max_stride &&
1959 !is_ccs_modifier(fb->modifier))
1960 return intel_tile_size(dev_priv);
1965 tile_width = intel_tile_width_bytes(fb, color_plane);
1966 if (is_ccs_modifier(fb->modifier)) {
1968 * Display WA #0531: skl,bxt,kbl,glk
1970 * Render decompression and plane width > 3840
1971 * combined with horizontal panning requires the
1972 * plane stride to be a multiple of 4. We'll just
1973 * require the entire fb to accommodate that to avoid
1974 * potential runtime errors at plane configuration time.
1976 if (IS_GEN(dev_priv, 9) && color_plane == 0 && fb->width > 3840)
1979 * The main surface pitch must be padded to a multiple of four
1982 else if (INTEL_GEN(dev_priv) >= 12)
1988 bool intel_plane_can_remap(const struct intel_plane_state *plane_state)
1990 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1991 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1992 const struct drm_framebuffer *fb = plane_state->hw.fb;
1995 /* We don't want to deal with remapping with cursors */
1996 if (plane->id == PLANE_CURSOR)
2000 * The display engine limits already match/exceed the
2001 * render engine limits, so not much point in remapping.
2002 * Would also need to deal with the fence POT alignment
2003 * and gen2 2KiB GTT tile size.
2005 if (INTEL_GEN(dev_priv) < 4)
2009 * The new CCS hash mode isn't compatible with remapping as
2010 * the virtual address of the pages affects the compressed data.
2012 if (is_ccs_modifier(fb->modifier))
2015 /* Linear needs a page aligned stride for remapping */
2016 if (fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2017 unsigned int alignment = intel_tile_size(dev_priv) - 1;
2019 for (i = 0; i < fb->format->num_planes; i++) {
2020 if (fb->pitches[i] & alignment)
2028 static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
2030 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2031 const struct drm_framebuffer *fb = plane_state->hw.fb;
2032 unsigned int rotation = plane_state->hw.rotation;
2033 u32 stride, max_stride;
2036 * No remapping for invisible planes since we don't have
2037 * an actual source viewport to remap.
2039 if (!plane_state->uapi.visible)
2042 if (!intel_plane_can_remap(plane_state))
2046 * FIXME: aux plane limits on gen9+ are
2047 * unclear in Bspec, for now no checking.
2049 stride = intel_fb_pitch(fb, 0, rotation);
2050 max_stride = plane->max_stride(plane, fb->format->format,
2051 fb->modifier, rotation);
2053 return stride > max_stride;
2057 intel_fb_plane_get_subsampling(int *hsub, int *vsub,
2058 const struct drm_framebuffer *fb,
2063 if (color_plane == 0) {
2071 * TODO: Deduct the subsampling from the char block for all CCS
2072 * formats and planes.
2074 if (!is_gen12_ccs_plane(fb, color_plane)) {
2075 *hsub = fb->format->hsub;
2076 *vsub = fb->format->vsub;
2081 main_plane = ccs_to_main_plane(fb, color_plane);
2082 *hsub = drm_format_info_block_width(fb->format, color_plane) /
2083 drm_format_info_block_width(fb->format, main_plane);
2086 * The min stride check in the core framebuffer_check() function
2087 * assumes that format->hsub applies to every plane except for the
2088 * first plane. That's incorrect for the CCS AUX plane of the first
2089 * plane, but for the above check to pass we must define the block
2090 * width with that subsampling applied to it. Adjust the width here
2091 * accordingly, so we can calculate the actual subsampling factor.
2093 if (main_plane == 0)
2094 *hsub *= fb->format->hsub;
2099 intel_fb_check_ccs_xy(struct drm_framebuffer *fb, int ccs_plane, int x, int y)
2101 struct drm_i915_private *i915 = to_i915(fb->dev);
2102 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2105 int tile_width, tile_height;
2109 if (!is_ccs_plane(fb, ccs_plane) || is_gen12_ccs_cc_plane(fb, ccs_plane))
2112 intel_tile_dims(fb, ccs_plane, &tile_width, &tile_height);
2113 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2116 tile_height *= vsub;
2118 ccs_x = (x * hsub) % tile_width;
2119 ccs_y = (y * vsub) % tile_height;
2121 main_plane = ccs_to_main_plane(fb, ccs_plane);
2122 main_x = intel_fb->normal[main_plane].x % tile_width;
2123 main_y = intel_fb->normal[main_plane].y % tile_height;
2126 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2127 * x/y offsets must match between CCS and the main surface.
2129 if (main_x != ccs_x || main_y != ccs_y) {
2130 drm_dbg_kms(&i915->drm,
2131 "Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2134 intel_fb->normal[main_plane].x,
2135 intel_fb->normal[main_plane].y,
2144 intel_fb_plane_dims(int *w, int *h, struct drm_framebuffer *fb, int color_plane)
2146 int main_plane = is_ccs_plane(fb, color_plane) ?
2147 ccs_to_main_plane(fb, color_plane) : 0;
2148 int main_hsub, main_vsub;
2151 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb, main_plane);
2152 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, color_plane);
2153 *w = fb->width / main_hsub / hsub;
2154 *h = fb->height / main_vsub / vsub;
2158 * Setup the rotated view for an FB plane and return the size the GTT mapping
2159 * requires for this view.
2162 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *plane_info,
2163 u32 gtt_offset_rotated, int x, int y,
2164 unsigned int width, unsigned int height,
2165 unsigned int tile_size,
2166 unsigned int tile_width, unsigned int tile_height,
2167 struct drm_framebuffer *fb)
2169 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2170 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
2171 unsigned int pitch_tiles;
2174 /* Y or Yf modifiers required for 90/270 rotation */
2175 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2176 fb->modifier != I915_FORMAT_MOD_Yf_TILED)
2179 if (drm_WARN_ON(fb->dev, plane >= ARRAY_SIZE(rot_info->plane)))
2182 rot_info->plane[plane] = *plane_info;
2184 intel_fb->rotated[plane].pitch = plane_info->height * tile_height;
2186 /* rotate the x/y offsets to match the GTT view */
2187 drm_rect_init(&r, x, y, width, height);
2189 plane_info->width * tile_width,
2190 plane_info->height * tile_height,
2191 DRM_MODE_ROTATE_270);
2195 /* rotate the tile dimensions to match the GTT view */
2196 pitch_tiles = intel_fb->rotated[plane].pitch / tile_height;
2197 swap(tile_width, tile_height);
2200 * We only keep the x/y offsets, so push all of the
2201 * gtt offset into the x/y offsets.
2203 intel_adjust_tile_offset(&x, &y,
2204 tile_width, tile_height,
2205 tile_size, pitch_tiles,
2206 gtt_offset_rotated * tile_size, 0);
2209 * First pixel of the framebuffer from
2210 * the start of the rotated gtt mapping.
2212 intel_fb->rotated[plane].x = x;
2213 intel_fb->rotated[plane].y = y;
2215 return plane_info->width * plane_info->height;
2219 intel_fill_fb_info(struct drm_i915_private *dev_priv,
2220 struct drm_framebuffer *fb)
2222 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2223 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
2224 u32 gtt_offset_rotated = 0;
2225 unsigned int max_size = 0;
2226 int i, num_planes = fb->format->num_planes;
2227 unsigned int tile_size = intel_tile_size(dev_priv);
2229 for (i = 0; i < num_planes; i++) {
2230 unsigned int width, height;
2231 unsigned int cpp, size;
2237 * Plane 2 of Render Compression with Clear Color fb modifier
2238 * is consumed by the driver and not passed to DE. Skip the
2239 * arithmetic related to alignment and offset calculation.
2241 if (is_gen12_ccs_cc_plane(fb, i)) {
2242 if (IS_ALIGNED(fb->offsets[i], PAGE_SIZE))
2248 cpp = fb->format->cpp[i];
2249 intel_fb_plane_dims(&width, &height, fb, i);
2251 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2253 drm_dbg_kms(&dev_priv->drm,
2254 "bad fb plane %d offset: 0x%x\n",
2259 ret = intel_fb_check_ccs_xy(fb, i, x, y);
2264 * The fence (if used) is aligned to the start of the object
2265 * so having the framebuffer wrap around across the edge of the
2266 * fenced region doesn't really work. We have no API to configure
2267 * the fence start offset within the object (nor could we probably
2268 * on gen2/3). So it's just easier if we just require that the
2269 * fb layout agrees with the fence layout. We already check that the
2270 * fb stride matches the fence stride elsewhere.
2272 if (i == 0 && i915_gem_object_is_tiled(obj) &&
2273 (x + width) * cpp > fb->pitches[i]) {
2274 drm_dbg_kms(&dev_priv->drm,
2275 "bad fb plane %d offset: 0x%x\n",
2281 * First pixel of the framebuffer from
2282 * the start of the normal gtt mapping.
2284 intel_fb->normal[i].x = x;
2285 intel_fb->normal[i].y = y;
2287 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2291 offset /= tile_size;
2293 if (!is_surface_linear(fb, i)) {
2294 struct intel_remapped_plane_info plane_info;
2295 unsigned int tile_width, tile_height;
2297 intel_tile_dims(fb, i, &tile_width, &tile_height);
2299 plane_info.offset = offset;
2300 plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
2302 plane_info.width = DIV_ROUND_UP(x + width, tile_width);
2303 plane_info.height = DIV_ROUND_UP(y + height,
2306 /* how many tiles does this plane need */
2307 size = plane_info.stride * plane_info.height;
2309 * If the plane isn't horizontally tile aligned,
2310 * we need one more tile.
2315 gtt_offset_rotated +=
2316 setup_fb_rotation(i, &plane_info,
2318 x, y, width, height,
2320 tile_width, tile_height,
2323 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2324 x * cpp, tile_size);
2327 /* how many tiles in total needed in the bo */
2328 max_size = max(max_size, offset + size);
2331 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2332 drm_dbg_kms(&dev_priv->drm,
2333 "fb too big for bo (need %llu bytes, have %zu bytes)\n",
2334 mul_u32_u32(max_size, tile_size), obj->base.size);
2342 intel_plane_remap_gtt(struct intel_plane_state *plane_state)
2344 struct drm_i915_private *dev_priv =
2345 to_i915(plane_state->uapi.plane->dev);
2346 struct drm_framebuffer *fb = plane_state->hw.fb;
2347 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2348 struct intel_rotation_info *info = &plane_state->view.rotated;
2349 unsigned int rotation = plane_state->hw.rotation;
2350 int i, num_planes = fb->format->num_planes;
2351 unsigned int tile_size = intel_tile_size(dev_priv);
2352 unsigned int src_x, src_y;
2353 unsigned int src_w, src_h;
2356 memset(&plane_state->view, 0, sizeof(plane_state->view));
2357 plane_state->view.type = drm_rotation_90_or_270(rotation) ?
2358 I915_GGTT_VIEW_ROTATED : I915_GGTT_VIEW_REMAPPED;
2360 src_x = plane_state->uapi.src.x1 >> 16;
2361 src_y = plane_state->uapi.src.y1 >> 16;
2362 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
2363 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
2365 drm_WARN_ON(&dev_priv->drm, is_ccs_modifier(fb->modifier));
2367 /* Make src coordinates relative to the viewport */
2368 drm_rect_translate(&plane_state->uapi.src,
2369 -(src_x << 16), -(src_y << 16));
2371 /* Rotate src coordinates to match rotated GTT view */
2372 if (drm_rotation_90_or_270(rotation))
2373 drm_rect_rotate(&plane_state->uapi.src,
2374 src_w << 16, src_h << 16,
2375 DRM_MODE_ROTATE_270);
2377 for (i = 0; i < num_planes; i++) {
2378 unsigned int hsub = i ? fb->format->hsub : 1;
2379 unsigned int vsub = i ? fb->format->vsub : 1;
2380 unsigned int cpp = fb->format->cpp[i];
2381 unsigned int tile_width, tile_height;
2382 unsigned int width, height;
2383 unsigned int pitch_tiles;
2387 intel_tile_dims(fb, i, &tile_width, &tile_height);
2391 width = src_w / hsub;
2392 height = src_h / vsub;
2395 * First pixel of the src viewport from the
2396 * start of the normal gtt mapping.
2398 x += intel_fb->normal[i].x;
2399 y += intel_fb->normal[i].y;
2401 offset = intel_compute_aligned_offset(dev_priv, &x, &y,
2402 fb, i, fb->pitches[i],
2403 DRM_MODE_ROTATE_0, tile_size);
2404 offset /= tile_size;
2406 drm_WARN_ON(&dev_priv->drm, i >= ARRAY_SIZE(info->plane));
2407 info->plane[i].offset = offset;
2408 info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i],
2410 info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2411 info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2413 if (drm_rotation_90_or_270(rotation)) {
2416 /* rotate the x/y offsets to match the GTT view */
2417 drm_rect_init(&r, x, y, width, height);
2419 info->plane[i].width * tile_width,
2420 info->plane[i].height * tile_height,
2421 DRM_MODE_ROTATE_270);
2425 pitch_tiles = info->plane[i].height;
2426 plane_state->color_plane[i].stride = pitch_tiles * tile_height;
2428 /* rotate the tile dimensions to match the GTT view */
2429 swap(tile_width, tile_height);
2431 pitch_tiles = info->plane[i].width;
2432 plane_state->color_plane[i].stride = pitch_tiles * tile_width * cpp;
2436 * We only keep the x/y offsets, so push all of the
2437 * gtt offset into the x/y offsets.
2439 intel_adjust_tile_offset(&x, &y,
2440 tile_width, tile_height,
2441 tile_size, pitch_tiles,
2442 gtt_offset * tile_size, 0);
2444 gtt_offset += info->plane[i].width * info->plane[i].height;
2446 plane_state->color_plane[i].offset = 0;
2447 plane_state->color_plane[i].x = x;
2448 plane_state->color_plane[i].y = y;
2453 intel_plane_compute_gtt(struct intel_plane_state *plane_state)
2455 const struct intel_framebuffer *fb =
2456 to_intel_framebuffer(plane_state->hw.fb);
2457 unsigned int rotation = plane_state->hw.rotation;
2463 num_planes = fb->base.format->num_planes;
2465 if (intel_plane_needs_remap(plane_state)) {
2466 intel_plane_remap_gtt(plane_state);
2469 * Sometimes even remapping can't overcome
2470 * the stride limitations :( Can happen with
2471 * big plane sizes and suitably misaligned
2474 return intel_plane_check_stride(plane_state);
2477 intel_fill_fb_ggtt_view(&plane_state->view, &fb->base, rotation);
2479 for (i = 0; i < num_planes; i++) {
2480 plane_state->color_plane[i].stride = intel_fb_pitch(&fb->base, i, rotation);
2481 plane_state->color_plane[i].offset = 0;
2483 if (drm_rotation_90_or_270(rotation)) {
2484 plane_state->color_plane[i].x = fb->rotated[i].x;
2485 plane_state->color_plane[i].y = fb->rotated[i].y;
2487 plane_state->color_plane[i].x = fb->normal[i].x;
2488 plane_state->color_plane[i].y = fb->normal[i].y;
2492 /* Rotate src coordinates to match rotated GTT view */
2493 if (drm_rotation_90_or_270(rotation))
2494 drm_rect_rotate(&plane_state->uapi.src,
2495 fb->base.width << 16, fb->base.height << 16,
2496 DRM_MODE_ROTATE_270);
2498 return intel_plane_check_stride(plane_state);
2501 static int i9xx_format_to_fourcc(int format)
2504 case DISPPLANE_8BPP:
2505 return DRM_FORMAT_C8;
2506 case DISPPLANE_BGRA555:
2507 return DRM_FORMAT_ARGB1555;
2508 case DISPPLANE_BGRX555:
2509 return DRM_FORMAT_XRGB1555;
2510 case DISPPLANE_BGRX565:
2511 return DRM_FORMAT_RGB565;
2513 case DISPPLANE_BGRX888:
2514 return DRM_FORMAT_XRGB8888;
2515 case DISPPLANE_RGBX888:
2516 return DRM_FORMAT_XBGR8888;
2517 case DISPPLANE_BGRA888:
2518 return DRM_FORMAT_ARGB8888;
2519 case DISPPLANE_RGBA888:
2520 return DRM_FORMAT_ABGR8888;
2521 case DISPPLANE_BGRX101010:
2522 return DRM_FORMAT_XRGB2101010;
2523 case DISPPLANE_RGBX101010:
2524 return DRM_FORMAT_XBGR2101010;
2525 case DISPPLANE_BGRA101010:
2526 return DRM_FORMAT_ARGB2101010;
2527 case DISPPLANE_RGBA101010:
2528 return DRM_FORMAT_ABGR2101010;
2529 case DISPPLANE_RGBX161616:
2530 return DRM_FORMAT_XBGR16161616F;
2534 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
2537 case PLANE_CTL_FORMAT_RGB_565:
2538 return DRM_FORMAT_RGB565;
2539 case PLANE_CTL_FORMAT_NV12:
2540 return DRM_FORMAT_NV12;
2541 case PLANE_CTL_FORMAT_XYUV:
2542 return DRM_FORMAT_XYUV8888;
2543 case PLANE_CTL_FORMAT_P010:
2544 return DRM_FORMAT_P010;
2545 case PLANE_CTL_FORMAT_P012:
2546 return DRM_FORMAT_P012;
2547 case PLANE_CTL_FORMAT_P016:
2548 return DRM_FORMAT_P016;
2549 case PLANE_CTL_FORMAT_Y210:
2550 return DRM_FORMAT_Y210;
2551 case PLANE_CTL_FORMAT_Y212:
2552 return DRM_FORMAT_Y212;
2553 case PLANE_CTL_FORMAT_Y216:
2554 return DRM_FORMAT_Y216;
2555 case PLANE_CTL_FORMAT_Y410:
2556 return DRM_FORMAT_XVYU2101010;
2557 case PLANE_CTL_FORMAT_Y412:
2558 return DRM_FORMAT_XVYU12_16161616;
2559 case PLANE_CTL_FORMAT_Y416:
2560 return DRM_FORMAT_XVYU16161616;
2562 case PLANE_CTL_FORMAT_XRGB_8888:
2565 return DRM_FORMAT_ABGR8888;
2567 return DRM_FORMAT_XBGR8888;
2570 return DRM_FORMAT_ARGB8888;
2572 return DRM_FORMAT_XRGB8888;
2574 case PLANE_CTL_FORMAT_XRGB_2101010:
2577 return DRM_FORMAT_ABGR2101010;
2579 return DRM_FORMAT_XBGR2101010;
2582 return DRM_FORMAT_ARGB2101010;
2584 return DRM_FORMAT_XRGB2101010;
2586 case PLANE_CTL_FORMAT_XRGB_16161616F:
2589 return DRM_FORMAT_ABGR16161616F;
2591 return DRM_FORMAT_XBGR16161616F;
2594 return DRM_FORMAT_ARGB16161616F;
2596 return DRM_FORMAT_XRGB16161616F;
2601 static struct i915_vma *
2602 initial_plane_vma(struct drm_i915_private *i915,
2603 struct intel_initial_plane_config *plane_config)
2605 struct drm_i915_gem_object *obj;
2606 struct i915_vma *vma;
2609 if (plane_config->size == 0)
2612 base = round_down(plane_config->base,
2613 I915_GTT_MIN_ALIGNMENT);
2614 size = round_up(plane_config->base + plane_config->size,
2615 I915_GTT_MIN_ALIGNMENT);
2619 * If the FB is too big, just don't use it since fbdev is not very
2620 * important and we should probably use that space with FBC or other
2623 if (size * 2 > i915->stolen_usable_size)
2626 obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
2631 * Mark it WT ahead of time to avoid changing the
2632 * cache_level during fbdev initialization. The
2633 * unbind there would get stuck waiting for rcu.
2635 i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
2636 I915_CACHE_WT : I915_CACHE_NONE);
2638 switch (plane_config->tiling) {
2639 case I915_TILING_NONE:
2643 obj->tiling_and_stride =
2644 plane_config->fb->base.pitches[0] |
2645 plane_config->tiling;
2648 MISSING_CASE(plane_config->tiling);
2652 vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
2656 if (i915_ggtt_pin(vma, NULL, 0, PIN_MAPPABLE | PIN_OFFSET_FIXED | base))
2659 if (i915_gem_object_is_tiled(obj) &&
2660 !i915_vma_is_map_and_fenceable(vma))
2666 i915_gem_object_put(obj);
2671 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2672 struct intel_initial_plane_config *plane_config)
2674 struct drm_device *dev = crtc->base.dev;
2675 struct drm_i915_private *dev_priv = to_i915(dev);
2676 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
2677 struct drm_framebuffer *fb = &plane_config->fb->base;
2678 struct i915_vma *vma;
2680 switch (fb->modifier) {
2681 case DRM_FORMAT_MOD_LINEAR:
2682 case I915_FORMAT_MOD_X_TILED:
2683 case I915_FORMAT_MOD_Y_TILED:
2686 drm_dbg(&dev_priv->drm,
2687 "Unsupported modifier for initial FB: 0x%llx\n",
2692 vma = initial_plane_vma(dev_priv, plane_config);
2696 mode_cmd.pixel_format = fb->format->format;
2697 mode_cmd.width = fb->width;
2698 mode_cmd.height = fb->height;
2699 mode_cmd.pitches[0] = fb->pitches[0];
2700 mode_cmd.modifier[0] = fb->modifier;
2701 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
2703 if (intel_framebuffer_init(to_intel_framebuffer(fb),
2704 vma->obj, &mode_cmd)) {
2705 drm_dbg_kms(&dev_priv->drm, "intel fb init failed\n");
2709 plane_config->vma = vma;
2718 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2719 struct intel_plane_state *plane_state,
2722 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2724 plane_state->uapi.visible = visible;
2727 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
2729 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
2732 static void fixup_plane_bitmasks(struct intel_crtc_state *crtc_state)
2734 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2735 struct drm_plane *plane;
2738 * Active_planes aliases if multiple "primary" or cursor planes
2739 * have been used on the same (or wrong) pipe. plane_mask uses
2740 * unique ids, hence we can use that to reconstruct active_planes.
2742 crtc_state->enabled_planes = 0;
2743 crtc_state->active_planes = 0;
2745 drm_for_each_plane_mask(plane, &dev_priv->drm,
2746 crtc_state->uapi.plane_mask) {
2747 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
2748 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2752 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2753 struct intel_plane *plane)
2755 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2756 struct intel_crtc_state *crtc_state =
2757 to_intel_crtc_state(crtc->base.state);
2758 struct intel_plane_state *plane_state =
2759 to_intel_plane_state(plane->base.state);
2761 drm_dbg_kms(&dev_priv->drm,
2762 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2763 plane->base.base.id, plane->base.name,
2764 crtc->base.base.id, crtc->base.name);
2766 intel_set_plane_visible(crtc_state, plane_state, false);
2767 fixup_plane_bitmasks(crtc_state);
2768 crtc_state->data_rate[plane->id] = 0;
2769 crtc_state->min_cdclk[plane->id] = 0;
2771 if (plane->id == PLANE_PRIMARY)
2772 hsw_disable_ips(crtc_state);
2775 * Vblank time updates from the shadow to live plane control register
2776 * are blocked if the memory self-refresh mode is active at that
2777 * moment. So to make sure the plane gets truly disabled, disable
2778 * first the self-refresh mode. The self-refresh enable bit in turn
2779 * will be checked/applied by the HW only at the next frame start
2780 * event which is after the vblank start event, so we need to have a
2781 * wait-for-vblank between disabling the plane and the pipe.
2783 if (HAS_GMCH(dev_priv) &&
2784 intel_set_memory_cxsr(dev_priv, false))
2785 intel_wait_for_vblank(dev_priv, crtc->pipe);
2788 * Gen2 reports pipe underruns whenever all planes are disabled.
2789 * So disable underrun reporting before all the planes get disabled.
2791 if (IS_GEN(dev_priv, 2) && !crtc_state->active_planes)
2792 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
2794 intel_disable_plane(plane, crtc_state);
2798 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2799 struct intel_initial_plane_config *plane_config)
2801 struct drm_device *dev = intel_crtc->base.dev;
2802 struct drm_i915_private *dev_priv = to_i915(dev);
2804 struct drm_plane *primary = intel_crtc->base.primary;
2805 struct drm_plane_state *plane_state = primary->state;
2806 struct intel_plane *intel_plane = to_intel_plane(primary);
2807 struct intel_plane_state *intel_state =
2808 to_intel_plane_state(plane_state);
2809 struct intel_crtc_state *crtc_state =
2810 to_intel_crtc_state(intel_crtc->base.state);
2811 struct drm_framebuffer *fb;
2812 struct i915_vma *vma;
2814 if (!plane_config->fb)
2817 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
2818 fb = &plane_config->fb->base;
2819 vma = plane_config->vma;
2824 * Failed to alloc the obj, check to see if we should share
2825 * an fb with another CRTC instead
2827 for_each_crtc(dev, c) {
2828 struct intel_plane_state *state;
2830 if (c == &intel_crtc->base)
2833 if (!to_intel_crtc_state(c->state)->uapi.active)
2836 state = to_intel_plane_state(c->primary->state);
2840 if (intel_plane_ggtt_offset(state) == plane_config->base) {
2848 * We've failed to reconstruct the BIOS FB. Current display state
2849 * indicates that the primary plane is visible, but has a NULL FB,
2850 * which will lead to problems later if we don't fix it up. The
2851 * simplest solution is to just disable the primary plane now and
2852 * pretend the BIOS never had it enabled.
2854 intel_plane_disable_noatomic(intel_crtc, intel_plane);
2855 if (crtc_state->bigjoiner) {
2856 struct intel_crtc *slave =
2857 crtc_state->bigjoiner_linked_crtc;
2858 intel_plane_disable_noatomic(slave, to_intel_plane(slave->base.primary));
2864 intel_state->hw.rotation = plane_config->rotation;
2865 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2866 intel_state->hw.rotation);
2867 intel_state->color_plane[0].stride =
2868 intel_fb_pitch(fb, 0, intel_state->hw.rotation);
2870 __i915_vma_pin(vma);
2871 intel_state->vma = i915_vma_get(vma);
2872 if (intel_plane_uses_fence(intel_state) && i915_vma_pin_fence(vma) == 0)
2874 intel_state->flags |= PLANE_HAS_FENCE;
2876 plane_state->src_x = 0;
2877 plane_state->src_y = 0;
2878 plane_state->src_w = fb->width << 16;
2879 plane_state->src_h = fb->height << 16;
2881 plane_state->crtc_x = 0;
2882 plane_state->crtc_y = 0;
2883 plane_state->crtc_w = fb->width;
2884 plane_state->crtc_h = fb->height;
2886 intel_state->uapi.src = drm_plane_state_src(plane_state);
2887 intel_state->uapi.dst = drm_plane_state_dest(plane_state);
2889 if (plane_config->tiling)
2890 dev_priv->preserve_bios_swizzle = true;
2892 plane_state->fb = fb;
2893 drm_framebuffer_get(fb);
2895 plane_state->crtc = &intel_crtc->base;
2896 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state,
2899 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
2901 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2902 &to_intel_frontbuffer(fb)->bits);
2907 skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2908 int main_x, int main_y, u32 main_offset,
2911 const struct drm_framebuffer *fb = plane_state->hw.fb;
2912 int aux_x = plane_state->color_plane[ccs_plane].x;
2913 int aux_y = plane_state->color_plane[ccs_plane].y;
2914 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
2915 u32 alignment = intel_surf_alignment(fb, ccs_plane);
2919 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
2920 while (aux_offset >= main_offset && aux_y <= main_y) {
2923 if (aux_x == main_x && aux_y == main_y)
2926 if (aux_offset == 0)
2931 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
2937 aux_x = x * hsub + aux_x % hsub;
2938 aux_y = y * vsub + aux_y % vsub;
2941 if (aux_x != main_x || aux_y != main_y)
2944 plane_state->color_plane[ccs_plane].offset = aux_offset;
2945 plane_state->color_plane[ccs_plane].x = aux_x;
2946 plane_state->color_plane[ccs_plane].y = aux_y;
2952 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
2956 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
2957 plane_state->color_plane[0].offset, 0);
2962 static int intel_plane_min_width(struct intel_plane *plane,
2963 const struct drm_framebuffer *fb,
2965 unsigned int rotation)
2967 if (plane->min_width)
2968 return plane->min_width(fb, color_plane, rotation);
2973 static int intel_plane_max_width(struct intel_plane *plane,
2974 const struct drm_framebuffer *fb,
2976 unsigned int rotation)
2978 if (plane->max_width)
2979 return plane->max_width(fb, color_plane, rotation);
2984 static int intel_plane_max_height(struct intel_plane *plane,
2985 const struct drm_framebuffer *fb,
2987 unsigned int rotation)
2989 if (plane->max_height)
2990 return plane->max_height(fb, color_plane, rotation);
2995 int skl_calc_main_surface_offset(const struct intel_plane_state *plane_state,
2996 int *x, int *y, u32 *offset)
2998 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2999 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3000 const struct drm_framebuffer *fb = plane_state->hw.fb;
3001 const int aux_plane = intel_main_to_aux_plane(fb, 0);
3002 const u32 aux_offset = plane_state->color_plane[aux_plane].offset;
3003 const u32 alignment = intel_surf_alignment(fb, 0);
3004 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3006 intel_add_fb_offsets(x, y, plane_state, 0);
3007 *offset = intel_plane_compute_aligned_offset(x, y, plane_state, 0);
3008 if (drm_WARN_ON(&dev_priv->drm, alignment && !is_power_of_2(alignment)))
3012 * AUX surface offset is specified as the distance from the
3013 * main surface offset, and it must be non-negative. Make
3014 * sure that is what we will get.
3016 if (aux_plane && *offset > aux_offset)
3017 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
3019 aux_offset & ~(alignment - 1));
3022 * When using an X-tiled surface, the plane blows up
3023 * if the x offset + width exceed the stride.
3025 * TODO: linear and Y-tiled seem fine, Yf untested,
3027 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
3028 int cpp = fb->format->cpp[0];
3030 while ((*x + w) * cpp > plane_state->color_plane[0].stride) {
3032 drm_dbg_kms(&dev_priv->drm,
3033 "Unable to find suitable display surface offset due to X-tiling\n");
3037 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
3039 *offset - alignment);
3046 static int skl_check_main_surface(struct intel_plane_state *plane_state)
3048 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3049 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3050 const struct drm_framebuffer *fb = plane_state->hw.fb;
3051 const unsigned int rotation = plane_state->hw.rotation;
3052 int x = plane_state->uapi.src.x1 >> 16;
3053 int y = plane_state->uapi.src.y1 >> 16;
3054 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
3055 const int h = drm_rect_height(&plane_state->uapi.src) >> 16;
3056 const int min_width = intel_plane_min_width(plane, fb, 0, rotation);
3057 const int max_width = intel_plane_max_width(plane, fb, 0, rotation);
3058 const int max_height = intel_plane_max_height(plane, fb, 0, rotation);
3059 const int aux_plane = intel_main_to_aux_plane(fb, 0);
3060 const u32 alignment = intel_surf_alignment(fb, 0);
3064 if (w > max_width || w < min_width || h > max_height) {
3065 drm_dbg_kms(&dev_priv->drm,
3066 "requested Y/RGB source size %dx%d outside limits (min: %dx1 max: %dx%d)\n",
3067 w, h, min_width, max_width, max_height);
3071 ret = skl_calc_main_surface_offset(plane_state, &x, &y, &offset);
3076 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3077 * they match with the main surface x/y offsets.
3079 if (is_ccs_modifier(fb->modifier)) {
3080 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3081 offset, aux_plane)) {
3085 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3086 offset, offset - alignment);
3089 if (x != plane_state->color_plane[aux_plane].x ||
3090 y != plane_state->color_plane[aux_plane].y) {
3091 drm_dbg_kms(&dev_priv->drm,
3092 "Unable to find suitable display surface offset due to CCS\n");
3097 drm_WARN_ON(&dev_priv->drm, x > 8191 || y > 8191);
3099 plane_state->color_plane[0].offset = offset;
3100 plane_state->color_plane[0].x = x;
3101 plane_state->color_plane[0].y = y;
3104 * Put the final coordinates back so that the src
3105 * coordinate checks will see the right values.
3107 drm_rect_translate_to(&plane_state->uapi.src,
3113 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3115 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3116 struct drm_i915_private *i915 = to_i915(plane->base.dev);
3117 const struct drm_framebuffer *fb = plane_state->hw.fb;
3118 unsigned int rotation = plane_state->hw.rotation;
3120 int max_width = intel_plane_max_width(plane, fb, uv_plane, rotation);
3121 int max_height = intel_plane_max_height(plane, fb, uv_plane, rotation);
3122 int x = plane_state->uapi.src.x1 >> 17;
3123 int y = plane_state->uapi.src.y1 >> 17;
3124 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
3125 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
3128 /* FIXME not quite sure how/if these apply to the chroma plane */
3129 if (w > max_width || h > max_height) {
3130 drm_dbg_kms(&i915->drm,
3131 "CbCr source size %dx%d too big (limit %dx%d)\n",
3132 w, h, max_width, max_height);
3136 intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
3137 offset = intel_plane_compute_aligned_offset(&x, &y,
3138 plane_state, uv_plane);
3140 if (is_ccs_modifier(fb->modifier)) {
3141 int ccs_plane = main_to_ccs_plane(fb, uv_plane);
3142 u32 aux_offset = plane_state->color_plane[ccs_plane].offset;
3143 u32 alignment = intel_surf_alignment(fb, uv_plane);
3145 if (offset > aux_offset)
3146 offset = intel_plane_adjust_aligned_offset(&x, &y,
3150 aux_offset & ~(alignment - 1));
3152 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
3153 offset, ccs_plane)) {
3157 offset = intel_plane_adjust_aligned_offset(&x, &y,
3160 offset, offset - alignment);
3163 if (x != plane_state->color_plane[ccs_plane].x ||
3164 y != plane_state->color_plane[ccs_plane].y) {
3165 drm_dbg_kms(&i915->drm,
3166 "Unable to find suitable display surface offset due to CCS\n");
3171 drm_WARN_ON(&i915->drm, x > 8191 || y > 8191);
3173 plane_state->color_plane[uv_plane].offset = offset;
3174 plane_state->color_plane[uv_plane].x = x;
3175 plane_state->color_plane[uv_plane].y = y;
3180 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3182 const struct drm_framebuffer *fb = plane_state->hw.fb;
3183 int src_x = plane_state->uapi.src.x1 >> 16;
3184 int src_y = plane_state->uapi.src.y1 >> 16;
3188 for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
3189 int main_hsub, main_vsub;
3193 if (!is_ccs_plane(fb, ccs_plane) ||
3194 is_gen12_ccs_cc_plane(fb, ccs_plane))
3197 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
3198 ccs_to_main_plane(fb, ccs_plane));
3199 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
3206 intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
3208 offset = intel_plane_compute_aligned_offset(&x, &y,
3212 plane_state->color_plane[ccs_plane].offset = offset;
3213 plane_state->color_plane[ccs_plane].x = (x * hsub +
3216 plane_state->color_plane[ccs_plane].y = (y * vsub +
3224 int skl_check_plane_surface(struct intel_plane_state *plane_state)
3226 const struct drm_framebuffer *fb = plane_state->hw.fb;
3229 ret = intel_plane_compute_gtt(plane_state);
3233 if (!plane_state->uapi.visible)
3237 * Handle the AUX surface first since the main surface setup depends on
3240 if (is_ccs_modifier(fb->modifier)) {
3241 ret = skl_check_ccs_aux_surface(plane_state);
3246 if (intel_format_info_is_yuv_semiplanar(fb->format,
3248 ret = skl_check_nv12_aux_surface(plane_state);
3253 for (i = fb->format->num_planes; i < ARRAY_SIZE(plane_state->color_plane); i++) {
3254 plane_state->color_plane[i].offset = 0;
3255 plane_state->color_plane[i].x = 0;
3256 plane_state->color_plane[i].y = 0;
3259 ret = skl_check_main_surface(plane_state);
3266 static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3268 struct drm_device *dev = intel_crtc->base.dev;
3269 struct drm_i915_private *dev_priv = to_i915(dev);
3270 unsigned long irqflags;
3272 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3274 intel_de_write_fw(dev_priv, SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3275 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3276 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
3278 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
3282 * This function detaches (aka. unbinds) unused scalers in hardware
3284 static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
3286 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
3287 const struct intel_crtc_scaler_state *scaler_state =
3288 &crtc_state->scaler_state;
3291 /* loop through and disable scalers that aren't in use */
3292 for (i = 0; i < intel_crtc->num_scalers; i++) {
3293 if (!scaler_state->scalers[i].in_use)
3294 skl_detach_scaler(intel_crtc, i);
3298 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3299 int color_plane, unsigned int rotation)
3302 * The stride is either expressed as a multiple of 64 bytes chunks for
3303 * linear buffers or in number of tiles for tiled buffers.
3305 if (is_surface_linear(fb, color_plane))
3307 else if (drm_rotation_90_or_270(rotation))
3308 return intel_tile_height(fb, color_plane);
3310 return intel_tile_width_bytes(fb, color_plane);
3313 u32 skl_plane_stride(const struct intel_plane_state *plane_state,
3316 const struct drm_framebuffer *fb = plane_state->hw.fb;
3317 unsigned int rotation = plane_state->hw.rotation;
3318 u32 stride = plane_state->color_plane[color_plane].stride;
3320 if (color_plane >= fb->format->num_planes)
3323 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
3326 static u32 skl_plane_ctl_format(u32 pixel_format)
3328 switch (pixel_format) {
3330 return PLANE_CTL_FORMAT_INDEXED;
3331 case DRM_FORMAT_RGB565:
3332 return PLANE_CTL_FORMAT_RGB_565;
3333 case DRM_FORMAT_XBGR8888:
3334 case DRM_FORMAT_ABGR8888:
3335 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
3336 case DRM_FORMAT_XRGB8888:
3337 case DRM_FORMAT_ARGB8888:
3338 return PLANE_CTL_FORMAT_XRGB_8888;
3339 case DRM_FORMAT_XBGR2101010:
3340 case DRM_FORMAT_ABGR2101010:
3341 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
3342 case DRM_FORMAT_XRGB2101010:
3343 case DRM_FORMAT_ARGB2101010:
3344 return PLANE_CTL_FORMAT_XRGB_2101010;
3345 case DRM_FORMAT_XBGR16161616F:
3346 case DRM_FORMAT_ABGR16161616F:
3347 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
3348 case DRM_FORMAT_XRGB16161616F:
3349 case DRM_FORMAT_ARGB16161616F:
3350 return PLANE_CTL_FORMAT_XRGB_16161616F;
3351 case DRM_FORMAT_XYUV8888:
3352 return PLANE_CTL_FORMAT_XYUV;
3353 case DRM_FORMAT_YUYV:
3354 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
3355 case DRM_FORMAT_YVYU:
3356 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
3357 case DRM_FORMAT_UYVY:
3358 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
3359 case DRM_FORMAT_VYUY:
3360 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
3361 case DRM_FORMAT_NV12:
3362 return PLANE_CTL_FORMAT_NV12;
3363 case DRM_FORMAT_P010:
3364 return PLANE_CTL_FORMAT_P010;
3365 case DRM_FORMAT_P012:
3366 return PLANE_CTL_FORMAT_P012;
3367 case DRM_FORMAT_P016:
3368 return PLANE_CTL_FORMAT_P016;
3369 case DRM_FORMAT_Y210:
3370 return PLANE_CTL_FORMAT_Y210;
3371 case DRM_FORMAT_Y212:
3372 return PLANE_CTL_FORMAT_Y212;
3373 case DRM_FORMAT_Y216:
3374 return PLANE_CTL_FORMAT_Y216;
3375 case DRM_FORMAT_XVYU2101010:
3376 return PLANE_CTL_FORMAT_Y410;
3377 case DRM_FORMAT_XVYU12_16161616:
3378 return PLANE_CTL_FORMAT_Y412;
3379 case DRM_FORMAT_XVYU16161616:
3380 return PLANE_CTL_FORMAT_Y416;
3382 MISSING_CASE(pixel_format);
3388 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
3390 if (!plane_state->hw.fb->format->has_alpha)
3391 return PLANE_CTL_ALPHA_DISABLE;
3393 switch (plane_state->hw.pixel_blend_mode) {
3394 case DRM_MODE_BLEND_PIXEL_NONE:
3395 return PLANE_CTL_ALPHA_DISABLE;
3396 case DRM_MODE_BLEND_PREMULTI:
3397 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
3398 case DRM_MODE_BLEND_COVERAGE:
3399 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
3401 MISSING_CASE(plane_state->hw.pixel_blend_mode);
3402 return PLANE_CTL_ALPHA_DISABLE;
3406 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
3408 if (!plane_state->hw.fb->format->has_alpha)
3409 return PLANE_COLOR_ALPHA_DISABLE;
3411 switch (plane_state->hw.pixel_blend_mode) {
3412 case DRM_MODE_BLEND_PIXEL_NONE:
3413 return PLANE_COLOR_ALPHA_DISABLE;
3414 case DRM_MODE_BLEND_PREMULTI:
3415 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
3416 case DRM_MODE_BLEND_COVERAGE:
3417 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
3419 MISSING_CASE(plane_state->hw.pixel_blend_mode);
3420 return PLANE_COLOR_ALPHA_DISABLE;
3424 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
3426 switch (fb_modifier) {
3427 case DRM_FORMAT_MOD_LINEAR:
3429 case I915_FORMAT_MOD_X_TILED:
3430 return PLANE_CTL_TILED_X;
3431 case I915_FORMAT_MOD_Y_TILED:
3432 return PLANE_CTL_TILED_Y;
3433 case I915_FORMAT_MOD_Y_TILED_CCS:
3434 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
3435 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3436 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
3437 return PLANE_CTL_TILED_Y |
3438 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
3439 PLANE_CTL_CLEAR_COLOR_DISABLE;
3440 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
3441 return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
3442 case I915_FORMAT_MOD_Yf_TILED:
3443 return PLANE_CTL_TILED_YF;
3444 case I915_FORMAT_MOD_Yf_TILED_CCS:
3445 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
3447 MISSING_CASE(fb_modifier);
3453 static u32 skl_plane_ctl_rotate(unsigned int rotate)
3456 case DRM_MODE_ROTATE_0:
3459 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
3460 * while i915 HW rotation is clockwise, thats why this swapping.
3462 case DRM_MODE_ROTATE_90:
3463 return PLANE_CTL_ROTATE_270;
3464 case DRM_MODE_ROTATE_180:
3465 return PLANE_CTL_ROTATE_180;
3466 case DRM_MODE_ROTATE_270:
3467 return PLANE_CTL_ROTATE_90;
3469 MISSING_CASE(rotate);
3475 static u32 cnl_plane_ctl_flip(unsigned int reflect)
3480 case DRM_MODE_REFLECT_X:
3481 return PLANE_CTL_FLIP_HORIZONTAL;
3482 case DRM_MODE_REFLECT_Y:
3484 MISSING_CASE(reflect);
3490 u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3492 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3495 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3498 if (crtc_state->gamma_enable)
3499 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
3501 if (crtc_state->csc_enable)
3502 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
3507 u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3508 const struct intel_plane_state *plane_state)
3510 struct drm_i915_private *dev_priv =
3511 to_i915(plane_state->uapi.plane->dev);
3512 const struct drm_framebuffer *fb = plane_state->hw.fb;
3513 unsigned int rotation = plane_state->hw.rotation;
3514 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
3517 plane_ctl = PLANE_CTL_ENABLE;
3519 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
3520 plane_ctl |= skl_plane_ctl_alpha(plane_state);
3521 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
3523 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
3524 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
3526 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3527 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
3530 plane_ctl |= skl_plane_ctl_format(fb->format->format);
3531 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
3532 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3534 if (INTEL_GEN(dev_priv) >= 10)
3535 plane_ctl |= cnl_plane_ctl_flip(rotation &
3536 DRM_MODE_REFLECT_MASK);
3538 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3539 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3540 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3541 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3546 u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
3548 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3549 u32 plane_color_ctl = 0;
3551 if (INTEL_GEN(dev_priv) >= 11)
3552 return plane_color_ctl;
3554 if (crtc_state->gamma_enable)
3555 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3557 if (crtc_state->csc_enable)
3558 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3560 return plane_color_ctl;
3563 u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3564 const struct intel_plane_state *plane_state)
3566 struct drm_i915_private *dev_priv =
3567 to_i915(plane_state->uapi.plane->dev);
3568 const struct drm_framebuffer *fb = plane_state->hw.fb;
3569 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
3570 u32 plane_color_ctl = 0;
3572 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
3573 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
3575 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
3576 switch (plane_state->hw.color_encoding) {
3577 case DRM_COLOR_YCBCR_BT709:
3578 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3580 case DRM_COLOR_YCBCR_BT2020:
3582 PLANE_COLOR_CSC_MODE_YUV2020_TO_RGB2020;
3586 PLANE_COLOR_CSC_MODE_YUV601_TO_RGB601;
3588 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3589 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3590 } else if (fb->format->is_yuv) {
3591 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
3592 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3593 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
3596 return plane_color_ctl;
3600 __intel_display_resume(struct drm_device *dev,
3601 struct drm_atomic_state *state,
3602 struct drm_modeset_acquire_ctx *ctx)
3604 struct drm_crtc_state *crtc_state;
3605 struct drm_crtc *crtc;
3608 intel_modeset_setup_hw_state(dev, ctx);
3609 intel_vga_redisable(to_i915(dev));
3615 * We've duplicated the state, pointers to the old state are invalid.
3617 * Don't attempt to use the old state until we commit the duplicated state.
3619 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
3621 * Force recalculation even if we restore
3622 * current state. With fast modeset this may not result
3623 * in a modeset when the state is compatible.
3625 crtc_state->mode_changed = true;
3628 /* ignore any reset values/BIOS leftovers in the WM registers */
3629 if (!HAS_GMCH(to_i915(dev)))
3630 to_intel_atomic_state(state)->skip_intermediate_wm = true;
3632 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
3634 drm_WARN_ON(dev, ret == -EDEADLK);
3638 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3640 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3641 intel_has_gpu_reset(&dev_priv->gt));
3644 void intel_display_prepare_reset(struct drm_i915_private *dev_priv)
3646 struct drm_device *dev = &dev_priv->drm;
3647 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3648 struct drm_atomic_state *state;
3651 if (!HAS_DISPLAY(dev_priv))
3654 /* reset doesn't touch the display */
3655 if (!dev_priv->params.force_reset_modeset_test &&
3656 !gpu_reset_clobbers_display(dev_priv))
3659 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3660 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
3661 smp_mb__after_atomic();
3662 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
3664 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3665 drm_dbg_kms(&dev_priv->drm,
3666 "Modeset potentially stuck, unbreaking through wedging\n");
3667 intel_gt_set_wedged(&dev_priv->gt);
3671 * Need mode_config.mutex so that we don't
3672 * trample ongoing ->detect() and whatnot.
3674 mutex_lock(&dev->mode_config.mutex);
3675 drm_modeset_acquire_init(ctx, 0);
3677 ret = drm_modeset_lock_all_ctx(dev, ctx);
3678 if (ret != -EDEADLK)
3681 drm_modeset_backoff(ctx);
3684 * Disabling the crtcs gracefully seems nicer. Also the
3685 * g33 docs say we should at least disable all the planes.
3687 state = drm_atomic_helper_duplicate_state(dev, ctx);
3688 if (IS_ERR(state)) {
3689 ret = PTR_ERR(state);
3690 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
3695 ret = drm_atomic_helper_disable_all(dev, ctx);
3697 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
3699 drm_atomic_state_put(state);
3703 dev_priv->modeset_restore_state = state;
3704 state->acquire_ctx = ctx;
3707 void intel_display_finish_reset(struct drm_i915_private *dev_priv)
3709 struct drm_device *dev = &dev_priv->drm;
3710 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3711 struct drm_atomic_state *state;
3714 if (!HAS_DISPLAY(dev_priv))
3717 /* reset doesn't touch the display */
3718 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
3721 state = fetch_and_zero(&dev_priv->modeset_restore_state);
3725 /* reset doesn't touch the display */
3726 if (!gpu_reset_clobbers_display(dev_priv)) {
3727 /* for testing only restore the display */
3728 ret = __intel_display_resume(dev, state, ctx);
3730 drm_err(&dev_priv->drm,
3731 "Restoring old state failed with %i\n", ret);
3734 * The display has been reset as well,
3735 * so need a full re-initialization.
3737 intel_pps_unlock_regs_wa(dev_priv);
3738 intel_modeset_init_hw(dev_priv);
3739 intel_init_clock_gating(dev_priv);
3740 intel_hpd_init(dev_priv);
3742 ret = __intel_display_resume(dev, state, ctx);
3744 drm_err(&dev_priv->drm,
3745 "Restoring old state failed with %i\n", ret);
3747 intel_hpd_poll_disable(dev_priv);
3750 drm_atomic_state_put(state);
3752 drm_modeset_drop_locks(ctx);
3753 drm_modeset_acquire_fini(ctx);
3754 mutex_unlock(&dev->mode_config.mutex);
3756 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
3759 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
3761 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3762 enum pipe pipe = crtc->pipe;
3765 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
3768 * Display WA #1153: icl
3769 * enable hardware to bypass the alpha math
3770 * and rounding for per-pixel values 00 and 0xff
3772 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
3774 * Display WA # 1605353570: icl
3775 * Set the pixel rounding bit to 1 for allowing
3776 * passthrough of Frame buffer pixels unmodified
3779 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
3780 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
3783 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
3785 struct drm_crtc *crtc;
3788 drm_for_each_crtc(crtc, &dev_priv->drm) {
3789 struct drm_crtc_commit *commit;
3790 spin_lock(&crtc->commit_lock);
3791 commit = list_first_entry_or_null(&crtc->commit_list,
3792 struct drm_crtc_commit, commit_entry);
3793 cleanup_done = commit ?
3794 try_wait_for_completion(&commit->cleanup_done) : true;
3795 spin_unlock(&crtc->commit_lock);
3800 drm_crtc_wait_one_vblank(crtc);
3808 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
3812 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
3814 mutex_lock(&dev_priv->sb_lock);
3816 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3817 temp |= SBI_SSCCTL_DISABLE;
3818 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3820 mutex_unlock(&dev_priv->sb_lock);
3823 /* Program iCLKIP clock to the desired frequency */
3824 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
3826 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3827 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3828 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
3829 u32 divsel, phaseinc, auxdiv, phasedir = 0;
3832 lpt_disable_iclkip(dev_priv);
3834 /* The iCLK virtual clock root frequency is in MHz,
3835 * but the adjusted_mode->crtc_clock in in KHz. To get the
3836 * divisors, it is necessary to divide one by another, so we
3837 * convert the virtual clock precision to KHz here for higher
3840 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
3841 u32 iclk_virtual_root_freq = 172800 * 1000;
3842 u32 iclk_pi_range = 64;
3843 u32 desired_divisor;
3845 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
3847 divsel = (desired_divisor / iclk_pi_range) - 2;
3848 phaseinc = desired_divisor % iclk_pi_range;
3851 * Near 20MHz is a corner case which is
3852 * out of range for the 7-bit divisor
3858 /* This should not happen with any sane values */
3859 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
3860 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
3861 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
3862 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
3864 drm_dbg_kms(&dev_priv->drm,
3865 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
3866 clock, auxdiv, divsel, phasedir, phaseinc);
3868 mutex_lock(&dev_priv->sb_lock);
3870 /* Program SSCDIVINTPHASE6 */
3871 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3872 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
3873 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
3874 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
3875 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
3876 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
3877 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
3878 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
3880 /* Program SSCAUXDIV */
3881 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3882 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
3883 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
3884 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
3886 /* Enable modulator and associated divider */
3887 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3888 temp &= ~SBI_SSCCTL_DISABLE;
3889 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
3891 mutex_unlock(&dev_priv->sb_lock);
3893 /* Wait for initialization time */
3896 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
3899 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
3901 u32 divsel, phaseinc, auxdiv;
3902 u32 iclk_virtual_root_freq = 172800 * 1000;
3903 u32 iclk_pi_range = 64;
3904 u32 desired_divisor;
3907 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
3910 mutex_lock(&dev_priv->sb_lock);
3912 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
3913 if (temp & SBI_SSCCTL_DISABLE) {
3914 mutex_unlock(&dev_priv->sb_lock);
3918 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
3919 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
3920 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
3921 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
3922 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
3924 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
3925 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
3926 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
3928 mutex_unlock(&dev_priv->sb_lock);
3930 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
3932 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
3933 desired_divisor << auxdiv);
3936 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
3937 enum pipe pch_transcoder)
3939 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3940 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3941 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3943 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
3944 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
3945 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
3946 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
3947 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
3948 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
3950 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
3951 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
3952 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
3953 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
3954 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
3955 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
3956 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
3957 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
3960 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
3964 temp = intel_de_read(dev_priv, SOUTH_CHICKEN1);
3965 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
3968 drm_WARN_ON(&dev_priv->drm,
3969 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_B)) &
3971 drm_WARN_ON(&dev_priv->drm,
3972 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_C)) &
3975 temp &= ~FDI_BC_BIFURCATION_SELECT;
3977 temp |= FDI_BC_BIFURCATION_SELECT;
3979 drm_dbg_kms(&dev_priv->drm, "%sabling fdi C rx\n",
3980 enable ? "en" : "dis");
3981 intel_de_write(dev_priv, SOUTH_CHICKEN1, temp);
3982 intel_de_posting_read(dev_priv, SOUTH_CHICKEN1);
3985 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
3987 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3988 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3990 switch (crtc->pipe) {
3994 if (crtc_state->fdi_lanes > 2)
3995 cpt_set_fdi_bc_bifurcation(dev_priv, false);
3997 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4001 cpt_set_fdi_bc_bifurcation(dev_priv, true);
4010 * Finds the encoder associated with the given CRTC. This can only be
4011 * used when we know that the CRTC isn't feeding multiple encoders!
4013 struct intel_encoder *
4014 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4015 const struct intel_crtc_state *crtc_state)
4017 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4018 const struct drm_connector_state *connector_state;
4019 const struct drm_connector *connector;
4020 struct intel_encoder *encoder = NULL;
4021 int num_encoders = 0;
4024 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4025 if (connector_state->crtc != &crtc->base)
4028 encoder = to_intel_encoder(connector_state->best_encoder);
4032 drm_WARN(encoder->base.dev, num_encoders != 1,
4033 "%d encoders for pipe %c\n",
4034 num_encoders, pipe_name(crtc->pipe));
4040 * Enable PCH resources required for PCH ports:
4042 * - FDI training & RX/TX
4043 * - update transcoder timings
4044 * - DP transcoding bits
4047 static void ilk_pch_enable(const struct intel_atomic_state *state,
4048 const struct intel_crtc_state *crtc_state)
4050 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4051 struct drm_device *dev = crtc->base.dev;
4052 struct drm_i915_private *dev_priv = to_i915(dev);
4053 enum pipe pipe = crtc->pipe;
4056 assert_pch_transcoder_disabled(dev_priv, pipe);
4058 if (IS_IVYBRIDGE(dev_priv))
4059 ivb_update_fdi_bc_bifurcation(crtc_state);
4061 /* Write the TU size bits before fdi link training, so that error
4062 * detection works. */
4063 intel_de_write(dev_priv, FDI_RX_TUSIZE1(pipe),
4064 intel_de_read(dev_priv, PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4066 /* For PCH output, training FDI link */
4067 dev_priv->display.fdi_link_train(crtc, crtc_state);
4069 /* We need to program the right clock selection before writing the pixel
4070 * mutliplier into the DPLL. */
4071 if (HAS_PCH_CPT(dev_priv)) {
4074 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
4075 temp |= TRANS_DPLL_ENABLE(pipe);
4076 sel = TRANS_DPLLB_SEL(pipe);
4077 if (crtc_state->shared_dpll ==
4078 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
4082 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
4085 /* XXX: pch pll's can be enabled any time before we enable the PCH
4086 * transcoder, and we actually should do this to not upset any PCH
4087 * transcoder that already use the clock when we share it.
4089 * Note that enable_shared_dpll tries to do the right thing, but
4090 * get_shared_dpll unconditionally resets the pll - we need that to have
4091 * the right LVDS enable sequence. */
4092 intel_enable_shared_dpll(crtc_state);
4094 /* set transcoder timing, panel must allow it */
4095 assert_panel_unlocked(dev_priv, pipe);
4096 ilk_pch_transcoder_set_timings(crtc_state, pipe);
4098 intel_fdi_normal_train(crtc);
4100 /* For PCH DP, enable TRANS_DP_CTL */
4101 if (HAS_PCH_CPT(dev_priv) &&
4102 intel_crtc_has_dp_encoder(crtc_state)) {
4103 const struct drm_display_mode *adjusted_mode =
4104 &crtc_state->hw.adjusted_mode;
4105 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
4106 i915_reg_t reg = TRANS_DP_CTL(pipe);
4109 temp = intel_de_read(dev_priv, reg);
4110 temp &= ~(TRANS_DP_PORT_SEL_MASK |
4111 TRANS_DP_SYNC_MASK |
4113 temp |= TRANS_DP_OUTPUT_ENABLE;
4114 temp |= bpc << 9; /* same format but at 11:9 */
4116 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
4117 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
4118 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
4119 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
4121 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
4122 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
4123 temp |= TRANS_DP_PORT_SEL(port);
4125 intel_de_write(dev_priv, reg, temp);
4128 ilk_enable_pch_transcoder(crtc_state);
4131 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
4133 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4134 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4135 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4137 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
4139 lpt_program_iclkip(crtc_state);
4141 /* Set transcoder timing. */
4142 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
4144 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
4147 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
4150 i915_reg_t dslreg = PIPEDSL(pipe);
4153 temp = intel_de_read(dev_priv, dslreg);
4155 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
4156 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
4157 drm_err(&dev_priv->drm,
4158 "mode set failed: pipe %c stuck\n",
4164 * The hardware phase 0.0 refers to the center of the pixel.
4165 * We want to start from the top/left edge which is phase
4166 * -0.5. That matches how the hardware calculates the scaling
4167 * factors (from top-left of the first pixel to bottom-right
4168 * of the last pixel, as opposed to the pixel centers).
4170 * For 4:2:0 subsampled chroma planes we obviously have to
4171 * adjust that so that the chroma sample position lands in
4174 * Note that for packed YCbCr 4:2:2 formats there is no way to
4175 * control chroma siting. The hardware simply replicates the
4176 * chroma samples for both of the luma samples, and thus we don't
4177 * actually get the expected MPEG2 chroma siting convention :(
4178 * The same behaviour is observed on pre-SKL platforms as well.
4180 * Theory behind the formula (note that we ignore sub-pixel
4181 * source coordinates):
4182 * s = source sample position
4183 * d = destination sample position
4188 * | | 1.5 (initial phase)
4196 * | -0.375 (initial phase)
4203 u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
4205 int phase = -0x8000;
4209 phase += (sub - 1) * 0x8000 / sub;
4211 phase += scale / (2 * sub);
4214 * Hardware initial phase limited to [-0.5:1.5].
4215 * Since the max hardware scale factor is 3.0, we
4216 * should never actually excdeed 1.0 here.
4218 WARN_ON(phase < -0x8000 || phase > 0x18000);
4221 phase = 0x10000 + phase;
4223 trip = PS_PHASE_TRIP;
4225 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4228 #define SKL_MIN_SRC_W 8
4229 #define SKL_MAX_SRC_W 4096
4230 #define SKL_MIN_SRC_H 8
4231 #define SKL_MAX_SRC_H 4096
4232 #define SKL_MIN_DST_W 8
4233 #define SKL_MAX_DST_W 4096
4234 #define SKL_MIN_DST_H 8
4235 #define SKL_MAX_DST_H 4096
4236 #define ICL_MAX_SRC_W 5120
4237 #define ICL_MAX_SRC_H 4096
4238 #define ICL_MAX_DST_W 5120
4239 #define ICL_MAX_DST_H 4096
4240 #define SKL_MIN_YUV_420_SRC_W 16
4241 #define SKL_MIN_YUV_420_SRC_H 16
4244 skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
4245 unsigned int scaler_user, int *scaler_id,
4246 int src_w, int src_h, int dst_w, int dst_h,
4247 const struct drm_format_info *format,
4248 u64 modifier, bool need_scaler)
4250 struct intel_crtc_scaler_state *scaler_state =
4251 &crtc_state->scaler_state;
4252 struct intel_crtc *intel_crtc =
4253 to_intel_crtc(crtc_state->uapi.crtc);
4254 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4255 const struct drm_display_mode *adjusted_mode =
4256 &crtc_state->hw.adjusted_mode;
4259 * Src coordinates are already rotated by 270 degrees for
4260 * the 90/270 degree plane rotation cases (to match the
4261 * GTT mapping), hence no need to account for rotation here.
4263 if (src_w != dst_w || src_h != dst_h)
4267 * Scaling/fitting not supported in IF-ID mode in GEN9+
4268 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4269 * Once NV12 is enabled, handle it here while allocating scaler
4272 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->hw.enable &&
4273 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4274 drm_dbg_kms(&dev_priv->drm,
4275 "Pipe/Plane scaling not supported with IF-ID mode\n");
4280 * if plane is being disabled or scaler is no more required or force detach
4281 * - free scaler binded to this plane/crtc
4282 * - in order to do this, update crtc->scaler_usage
4284 * Here scaler state in crtc_state is set free so that
4285 * scaler can be assigned to other user. Actual register
4286 * update to free the scaler is done in plane/panel-fit programming.
4287 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4289 if (force_detach || !need_scaler) {
4290 if (*scaler_id >= 0) {
4291 scaler_state->scaler_users &= ~(1 << scaler_user);
4292 scaler_state->scalers[*scaler_id].in_use = 0;
4294 drm_dbg_kms(&dev_priv->drm,
4295 "scaler_user index %u.%u: "
4296 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4297 intel_crtc->pipe, scaler_user, *scaler_id,
4298 scaler_state->scaler_users);
4304 if (format && intel_format_info_is_yuv_semiplanar(format, modifier) &&
4305 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
4306 drm_dbg_kms(&dev_priv->drm,
4307 "Planar YUV: src dimensions not met\n");
4312 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
4313 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
4314 (INTEL_GEN(dev_priv) >= 11 &&
4315 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4316 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
4317 (INTEL_GEN(dev_priv) < 11 &&
4318 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4319 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
4320 drm_dbg_kms(&dev_priv->drm,
4321 "scaler_user index %u.%u: src %ux%u dst %ux%u "
4322 "size is out of scaler range\n",
4323 intel_crtc->pipe, scaler_user, src_w, src_h,
4328 /* mark this plane as a scaler user in crtc_state */
4329 scaler_state->scaler_users |= (1 << scaler_user);
4330 drm_dbg_kms(&dev_priv->drm, "scaler_user index %u.%u: "
4331 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4332 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4333 scaler_state->scaler_users);
4338 static int skl_update_scaler_crtc(struct intel_crtc_state *crtc_state)
4340 const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
4343 if (crtc_state->pch_pfit.enabled) {
4344 width = drm_rect_width(&crtc_state->pch_pfit.dst);
4345 height = drm_rect_height(&crtc_state->pch_pfit.dst);
4347 width = pipe_mode->crtc_hdisplay;
4348 height = pipe_mode->crtc_vdisplay;
4350 return skl_update_scaler(crtc_state, !crtc_state->hw.active,
4352 &crtc_state->scaler_state.scaler_id,
4353 crtc_state->pipe_src_w, crtc_state->pipe_src_h,
4354 width, height, NULL, 0,
4355 crtc_state->pch_pfit.enabled);
4359 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
4360 * @crtc_state: crtc's scaler state
4361 * @plane_state: atomic plane state to update
4364 * 0 - scaler_usage updated successfully
4365 * error - requested scaling cannot be supported or other error condition
4367 static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4368 struct intel_plane_state *plane_state)
4370 struct intel_plane *intel_plane =
4371 to_intel_plane(plane_state->uapi.plane);
4372 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
4373 struct drm_framebuffer *fb = plane_state->hw.fb;
4375 bool force_detach = !fb || !plane_state->uapi.visible;
4376 bool need_scaler = false;
4378 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
4379 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
4380 fb && intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
4383 ret = skl_update_scaler(crtc_state, force_detach,
4384 drm_plane_index(&intel_plane->base),
4385 &plane_state->scaler_id,
4386 drm_rect_width(&plane_state->uapi.src) >> 16,
4387 drm_rect_height(&plane_state->uapi.src) >> 16,
4388 drm_rect_width(&plane_state->uapi.dst),
4389 drm_rect_height(&plane_state->uapi.dst),
4390 fb ? fb->format : NULL,
4391 fb ? fb->modifier : 0,
4394 if (ret || plane_state->scaler_id < 0)
4397 /* check colorkey */
4398 if (plane_state->ckey.flags) {
4399 drm_dbg_kms(&dev_priv->drm,
4400 "[PLANE:%d:%s] scaling with color key not allowed",
4401 intel_plane->base.base.id,
4402 intel_plane->base.name);
4406 /* Check src format */
4407 switch (fb->format->format) {
4408 case DRM_FORMAT_RGB565:
4409 case DRM_FORMAT_XBGR8888:
4410 case DRM_FORMAT_XRGB8888:
4411 case DRM_FORMAT_ABGR8888:
4412 case DRM_FORMAT_ARGB8888:
4413 case DRM_FORMAT_XRGB2101010:
4414 case DRM_FORMAT_XBGR2101010:
4415 case DRM_FORMAT_ARGB2101010:
4416 case DRM_FORMAT_ABGR2101010:
4417 case DRM_FORMAT_YUYV:
4418 case DRM_FORMAT_YVYU:
4419 case DRM_FORMAT_UYVY:
4420 case DRM_FORMAT_VYUY:
4421 case DRM_FORMAT_NV12:
4422 case DRM_FORMAT_XYUV8888:
4423 case DRM_FORMAT_P010:
4424 case DRM_FORMAT_P012:
4425 case DRM_FORMAT_P016:
4426 case DRM_FORMAT_Y210:
4427 case DRM_FORMAT_Y212:
4428 case DRM_FORMAT_Y216:
4429 case DRM_FORMAT_XVYU2101010:
4430 case DRM_FORMAT_XVYU12_16161616:
4431 case DRM_FORMAT_XVYU16161616:
4433 case DRM_FORMAT_XBGR16161616F:
4434 case DRM_FORMAT_ABGR16161616F:
4435 case DRM_FORMAT_XRGB16161616F:
4436 case DRM_FORMAT_ARGB16161616F:
4437 if (INTEL_GEN(dev_priv) >= 11)
4441 drm_dbg_kms(&dev_priv->drm,
4442 "[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
4443 intel_plane->base.base.id, intel_plane->base.name,
4444 fb->base.id, fb->format->format);
4451 void skl_scaler_disable(const struct intel_crtc_state *old_crtc_state)
4453 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
4456 for (i = 0; i < crtc->num_scalers; i++)
4457 skl_detach_scaler(crtc, i);
4460 static int cnl_coef_tap(int i)
4465 static u16 cnl_nearest_filter_coef(int t)
4467 return t == 3 ? 0x0800 : 0x3000;
4471 * Theory behind setting nearest-neighbor integer scaling:
4473 * 17 phase of 7 taps requires 119 coefficients in 60 dwords per set.
4474 * The letter represents the filter tap (D is the center tap) and the number
4475 * represents the coefficient set for a phase (0-16).
4477 * +------------+------------------------+------------------------+
4478 * |Index value | Data value coeffient 1 | Data value coeffient 2 |
4479 * +------------+------------------------+------------------------+
4481 * +------------+------------------------+------------------------+
4483 * +------------+------------------------+------------------------+
4485 * +------------+------------------------+------------------------+
4487 * +------------+------------------------+------------------------+
4489 * +------------+------------------------+------------------------+
4490 * | ... | ... | ... |
4491 * +------------+------------------------+------------------------+
4492 * | 38h | B16 | A16 |
4493 * +------------+------------------------+------------------------+
4494 * | 39h | D16 | C16 |
4495 * +------------+------------------------+------------------------+
4496 * | 3Ah | F16 | C16 |
4497 * +------------+------------------------+------------------------+
4498 * | 3Bh | Reserved | G16 |
4499 * +------------+------------------------+------------------------+
4501 * To enable nearest-neighbor scaling: program scaler coefficents with
4502 * the center tap (Dxx) values set to 1 and all other values set to 0 as per
4503 * SCALER_COEFFICIENT_FORMAT
4507 static void cnl_program_nearest_filter_coefs(struct drm_i915_private *dev_priv,
4508 enum pipe pipe, int id, int set)
4512 intel_de_write_fw(dev_priv, CNL_PS_COEF_INDEX_SET(pipe, id, set),
4513 PS_COEE_INDEX_AUTO_INC);
4515 for (i = 0; i < 17 * 7; i += 2) {
4519 t = cnl_coef_tap(i);
4520 tmp = cnl_nearest_filter_coef(t);
4522 t = cnl_coef_tap(i + 1);
4523 tmp |= cnl_nearest_filter_coef(t) << 16;
4525 intel_de_write_fw(dev_priv, CNL_PS_COEF_DATA_SET(pipe, id, set),
4529 intel_de_write_fw(dev_priv, CNL_PS_COEF_INDEX_SET(pipe, id, set), 0);
4532 u32 skl_scaler_get_filter_select(enum drm_scaling_filter filter, int set)
4534 if (filter == DRM_SCALING_FILTER_NEAREST_NEIGHBOR) {
4535 return (PS_FILTER_PROGRAMMED |
4536 PS_Y_VERT_FILTER_SELECT(set) |
4537 PS_Y_HORZ_FILTER_SELECT(set) |
4538 PS_UV_VERT_FILTER_SELECT(set) |
4539 PS_UV_HORZ_FILTER_SELECT(set));
4542 return PS_FILTER_MEDIUM;
4545 void skl_scaler_setup_filter(struct drm_i915_private *dev_priv, enum pipe pipe,
4546 int id, int set, enum drm_scaling_filter filter)
4549 case DRM_SCALING_FILTER_DEFAULT:
4551 case DRM_SCALING_FILTER_NEAREST_NEIGHBOR:
4552 cnl_program_nearest_filter_coefs(dev_priv, pipe, id, set);
4555 MISSING_CASE(filter);
4559 static void skl_pfit_enable(const struct intel_crtc_state *crtc_state)
4561 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4562 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4563 const struct intel_crtc_scaler_state *scaler_state =
4564 &crtc_state->scaler_state;
4565 struct drm_rect src = {
4566 .x2 = crtc_state->pipe_src_w << 16,
4567 .y2 = crtc_state->pipe_src_h << 16,
4569 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
4570 u16 uv_rgb_hphase, uv_rgb_vphase;
4571 enum pipe pipe = crtc->pipe;
4572 int width = drm_rect_width(dst);
4573 int height = drm_rect_height(dst);
4577 unsigned long irqflags;
4581 if (!crtc_state->pch_pfit.enabled)
4584 if (drm_WARN_ON(&dev_priv->drm,
4585 crtc_state->scaler_state.scaler_id < 0))
4588 hscale = drm_rect_calc_hscale(&src, dst, 0, INT_MAX);
4589 vscale = drm_rect_calc_vscale(&src, dst, 0, INT_MAX);
4591 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
4592 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
4594 id = scaler_state->scaler_id;
4596 ps_ctrl = skl_scaler_get_filter_select(crtc_state->hw.scaling_filter, 0);
4597 ps_ctrl |= PS_SCALER_EN | scaler_state->scalers[id].mode;
4599 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
4601 skl_scaler_setup_filter(dev_priv, pipe, id, 0,
4602 crtc_state->hw.scaling_filter);
4604 intel_de_write_fw(dev_priv, SKL_PS_CTRL(pipe, id), ps_ctrl);
4606 intel_de_write_fw(dev_priv, SKL_PS_VPHASE(pipe, id),
4607 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
4608 intel_de_write_fw(dev_priv, SKL_PS_HPHASE(pipe, id),
4609 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
4610 intel_de_write_fw(dev_priv, SKL_PS_WIN_POS(pipe, id),
4612 intel_de_write_fw(dev_priv, SKL_PS_WIN_SZ(pipe, id),
4613 width << 16 | height);
4615 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
4618 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
4620 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4621 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4622 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
4623 enum pipe pipe = crtc->pipe;
4624 int width = drm_rect_width(dst);
4625 int height = drm_rect_height(dst);
4629 if (!crtc_state->pch_pfit.enabled)
4632 /* Force use of hard-coded filter coefficients
4633 * as some pre-programmed values are broken,
4636 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
4637 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
4638 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
4640 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
4642 intel_de_write(dev_priv, PF_WIN_POS(pipe), x << 16 | y);
4643 intel_de_write(dev_priv, PF_WIN_SZ(pipe), width << 16 | height);
4646 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
4648 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4649 struct drm_device *dev = crtc->base.dev;
4650 struct drm_i915_private *dev_priv = to_i915(dev);
4652 if (!crtc_state->ips_enabled)
4656 * We can only enable IPS after we enable a plane and wait for a vblank
4657 * This function is called from post_plane_update, which is run after
4660 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
4662 if (IS_BROADWELL(dev_priv)) {
4663 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
4664 IPS_ENABLE | IPS_PCODE_CONTROL));
4665 /* Quoting Art Runyan: "its not safe to expect any particular
4666 * value in IPS_CTL bit 31 after enabling IPS through the
4667 * mailbox." Moreover, the mailbox may return a bogus state,
4668 * so we need to just enable it and continue on.
4671 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
4672 /* The bit only becomes 1 in the next vblank, so this wait here
4673 * is essentially intel_wait_for_vblank. If we don't have this
4674 * and don't wait for vblanks until the end of crtc_enable, then
4675 * the HW state readout code will complain that the expected
4676 * IPS_CTL value is not the one we read. */
4677 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
4678 drm_err(&dev_priv->drm,
4679 "Timed out waiting for IPS enable\n");
4683 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
4685 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4686 struct drm_device *dev = crtc->base.dev;
4687 struct drm_i915_private *dev_priv = to_i915(dev);
4689 if (!crtc_state->ips_enabled)
4692 if (IS_BROADWELL(dev_priv)) {
4694 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
4696 * Wait for PCODE to finish disabling IPS. The BSpec specified
4697 * 42ms timeout value leads to occasional timeouts so use 100ms
4700 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
4701 drm_err(&dev_priv->drm,
4702 "Timed out waiting for IPS disable\n");
4704 intel_de_write(dev_priv, IPS_CTL, 0);
4705 intel_de_posting_read(dev_priv, IPS_CTL);
4708 /* We need to wait for a vblank before we can disable the plane. */
4709 intel_wait_for_vblank(dev_priv, crtc->pipe);
4712 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
4714 if (intel_crtc->overlay)
4715 (void) intel_overlay_switch_off(intel_crtc->overlay);
4717 /* Let userspace switch the overlay on again. In most cases userspace
4718 * has to recompute where to put it anyway.
4722 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
4723 const struct intel_crtc_state *new_crtc_state)
4725 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4726 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4728 if (!old_crtc_state->ips_enabled)
4731 if (intel_crtc_needs_modeset(new_crtc_state))
4735 * Workaround : Do not read or write the pipe palette/gamma data while
4736 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4738 * Disable IPS before we program the LUT.
4740 if (IS_HASWELL(dev_priv) &&
4741 (new_crtc_state->uapi.color_mgmt_changed ||
4742 new_crtc_state->update_pipe) &&
4743 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
4746 return !new_crtc_state->ips_enabled;
4749 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
4750 const struct intel_crtc_state *new_crtc_state)
4752 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4753 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4755 if (!new_crtc_state->ips_enabled)
4758 if (intel_crtc_needs_modeset(new_crtc_state))
4762 * Workaround : Do not read or write the pipe palette/gamma data while
4763 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
4765 * Re-enable IPS after the LUT has been programmed.
4767 if (IS_HASWELL(dev_priv) &&
4768 (new_crtc_state->uapi.color_mgmt_changed ||
4769 new_crtc_state->update_pipe) &&
4770 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
4774 * We can't read out IPS on broadwell, assume the worst and
4775 * forcibly enable IPS on the first fastset.
4777 if (new_crtc_state->update_pipe && old_crtc_state->inherited)
4780 return !old_crtc_state->ips_enabled;
4783 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
4785 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4787 if (!crtc_state->nv12_planes)
4790 /* WA Display #0827: Gen9:all */
4791 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
4797 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
4799 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4801 /* Wa_2006604312:icl,ehl */
4802 if (crtc_state->scaler_state.scaler_users > 0 && IS_GEN(dev_priv, 11))
4808 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
4809 const struct intel_crtc_state *new_crtc_state)
4811 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) &&
4812 new_crtc_state->active_planes;
4815 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
4816 const struct intel_crtc_state *new_crtc_state)
4818 return old_crtc_state->active_planes &&
4819 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state));
4822 static void intel_post_plane_update(struct intel_atomic_state *state,
4823 struct intel_crtc *crtc)
4825 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
4826 const struct intel_crtc_state *old_crtc_state =
4827 intel_atomic_get_old_crtc_state(state, crtc);
4828 const struct intel_crtc_state *new_crtc_state =
4829 intel_atomic_get_new_crtc_state(state, crtc);
4830 enum pipe pipe = crtc->pipe;
4832 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
4834 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
4835 intel_update_watermarks(crtc);
4837 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
4838 hsw_enable_ips(new_crtc_state);
4840 intel_fbc_post_update(state, crtc);
4842 if (needs_nv12_wa(old_crtc_state) &&
4843 !needs_nv12_wa(new_crtc_state))
4844 skl_wa_827(dev_priv, pipe, false);
4846 if (needs_scalerclk_wa(old_crtc_state) &&
4847 !needs_scalerclk_wa(new_crtc_state))
4848 icl_wa_scalerclkgating(dev_priv, pipe, false);
4851 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
4852 struct intel_crtc *crtc)
4854 const struct intel_crtc_state *crtc_state =
4855 intel_atomic_get_new_crtc_state(state, crtc);
4856 u8 update_planes = crtc_state->update_planes;
4857 const struct intel_plane_state *plane_state;
4858 struct intel_plane *plane;
4861 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4862 if (plane->enable_flip_done &&
4863 plane->pipe == crtc->pipe &&
4864 update_planes & BIT(plane->id))
4865 plane->enable_flip_done(plane);
4869 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
4870 struct intel_crtc *crtc)
4872 const struct intel_crtc_state *crtc_state =
4873 intel_atomic_get_new_crtc_state(state, crtc);
4874 u8 update_planes = crtc_state->update_planes;
4875 const struct intel_plane_state *plane_state;
4876 struct intel_plane *plane;
4879 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4880 if (plane->disable_flip_done &&
4881 plane->pipe == crtc->pipe &&
4882 update_planes & BIT(plane->id))
4883 plane->disable_flip_done(plane);
4887 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
4888 struct intel_crtc *crtc)
4890 struct drm_i915_private *i915 = to_i915(state->base.dev);
4891 const struct intel_crtc_state *old_crtc_state =
4892 intel_atomic_get_old_crtc_state(state, crtc);
4893 const struct intel_crtc_state *new_crtc_state =
4894 intel_atomic_get_new_crtc_state(state, crtc);
4895 u8 update_planes = new_crtc_state->update_planes;
4896 const struct intel_plane_state *old_plane_state;
4897 struct intel_plane *plane;
4898 bool need_vbl_wait = false;
4901 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
4902 if (plane->need_async_flip_disable_wa &&
4903 plane->pipe == crtc->pipe &&
4904 update_planes & BIT(plane->id)) {
4906 * Apart from the async flip bit we want to
4907 * preserve the old state for the plane.
4909 plane->async_flip(plane, old_crtc_state,
4910 old_plane_state, false);
4911 need_vbl_wait = true;
4916 intel_wait_for_vblank(i915, crtc->pipe);
4919 static void intel_pre_plane_update(struct intel_atomic_state *state,
4920 struct intel_crtc *crtc)
4922 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
4923 const struct intel_crtc_state *old_crtc_state =
4924 intel_atomic_get_old_crtc_state(state, crtc);
4925 const struct intel_crtc_state *new_crtc_state =
4926 intel_atomic_get_new_crtc_state(state, crtc);
4927 enum pipe pipe = crtc->pipe;
4929 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
4930 hsw_disable_ips(old_crtc_state);
4932 if (intel_fbc_pre_update(state, crtc))
4933 intel_wait_for_vblank(dev_priv, pipe);
4935 /* Display WA 827 */
4936 if (!needs_nv12_wa(old_crtc_state) &&
4937 needs_nv12_wa(new_crtc_state))
4938 skl_wa_827(dev_priv, pipe, true);
4940 /* Wa_2006604312:icl,ehl */
4941 if (!needs_scalerclk_wa(old_crtc_state) &&
4942 needs_scalerclk_wa(new_crtc_state))
4943 icl_wa_scalerclkgating(dev_priv, pipe, true);
4946 * Vblank time updates from the shadow to live plane control register
4947 * are blocked if the memory self-refresh mode is active at that
4948 * moment. So to make sure the plane gets truly disabled, disable
4949 * first the self-refresh mode. The self-refresh enable bit in turn
4950 * will be checked/applied by the HW only at the next frame start
4951 * event which is after the vblank start event, so we need to have a
4952 * wait-for-vblank between disabling the plane and the pipe.
4954 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
4955 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
4956 intel_wait_for_vblank(dev_priv, pipe);
4959 * IVB workaround: must disable low power watermarks for at least
4960 * one frame before enabling scaling. LP watermarks can be re-enabled
4961 * when scaling is disabled.
4963 * WaCxSRDisabledForSpriteScaling:ivb
4965 if (old_crtc_state->hw.active &&
4966 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
4967 intel_wait_for_vblank(dev_priv, pipe);
4970 * If we're doing a modeset we don't need to do any
4971 * pre-vblank watermark programming here.
4973 if (!intel_crtc_needs_modeset(new_crtc_state)) {
4975 * For platforms that support atomic watermarks, program the
4976 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
4977 * will be the intermediate values that are safe for both pre- and
4978 * post- vblank; when vblank happens, the 'active' values will be set
4979 * to the final 'target' values and we'll do this again to get the
4980 * optimal watermarks. For gen9+ platforms, the values we program here
4981 * will be the final target values which will get automatically latched
4982 * at vblank time; no further programming will be necessary.
4984 * If a platform hasn't been transitioned to atomic watermarks yet,
4985 * we'll continue to update watermarks the old way, if flags tell
4988 if (dev_priv->display.initial_watermarks)
4989 dev_priv->display.initial_watermarks(state, crtc);
4990 else if (new_crtc_state->update_wm_pre)
4991 intel_update_watermarks(crtc);
4995 * Gen2 reports pipe underruns whenever all planes are disabled.
4996 * So disable underrun reporting before all the planes get disabled.
4998 * We do this after .initial_watermarks() so that we have a
4999 * chance of catching underruns with the intermediate watermarks
5000 * vs. the old plane configuration.
5002 if (IS_GEN(dev_priv, 2) && planes_disabling(old_crtc_state, new_crtc_state))
5003 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5006 * WA for platforms where async address update enable bit
5007 * is double buffered and only latched at start of vblank.
5009 if (old_crtc_state->uapi.async_flip && !new_crtc_state->uapi.async_flip)
5010 intel_crtc_async_flip_disable_wa(state, crtc);
5013 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5014 struct intel_crtc *crtc)
5016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5017 const struct intel_crtc_state *new_crtc_state =
5018 intel_atomic_get_new_crtc_state(state, crtc);
5019 unsigned int update_mask = new_crtc_state->update_planes;
5020 const struct intel_plane_state *old_plane_state;
5021 struct intel_plane *plane;
5022 unsigned fb_bits = 0;
5025 intel_crtc_dpms_overlay_disable(crtc);
5027 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5028 if (crtc->pipe != plane->pipe ||
5029 !(update_mask & BIT(plane->id)))
5032 intel_disable_plane(plane, new_crtc_state);
5034 if (old_plane_state->uapi.visible)
5035 fb_bits |= plane->frontbuffer_bit;
5038 intel_frontbuffer_flip(dev_priv, fb_bits);
5042 * intel_connector_primary_encoder - get the primary encoder for a connector
5043 * @connector: connector for which to return the encoder
5045 * Returns the primary encoder for a connector. There is a 1:1 mapping from
5046 * all connectors to their encoder, except for DP-MST connectors which have
5047 * both a virtual and a primary encoder. These DP-MST primary encoders can be
5048 * pointed to by as many DP-MST connectors as there are pipes.
5050 static struct intel_encoder *
5051 intel_connector_primary_encoder(struct intel_connector *connector)
5053 struct intel_encoder *encoder;
5055 if (connector->mst_port)
5056 return &dp_to_dig_port(connector->mst_port)->base;
5058 encoder = intel_attached_encoder(connector);
5059 drm_WARN_ON(connector->base.dev, !encoder);
5064 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
5066 struct drm_connector_state *new_conn_state;
5067 struct drm_connector *connector;
5070 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
5072 struct intel_connector *intel_connector;
5073 struct intel_encoder *encoder;
5074 struct intel_crtc *crtc;
5076 if (!intel_connector_needs_modeset(state, connector))
5079 intel_connector = to_intel_connector(connector);
5080 encoder = intel_connector_primary_encoder(intel_connector);
5081 if (!encoder->update_prepare)
5084 crtc = new_conn_state->crtc ?
5085 to_intel_crtc(new_conn_state->crtc) : NULL;
5086 encoder->update_prepare(state, encoder, crtc);
5090 static void intel_encoders_update_complete(struct intel_atomic_state *state)
5092 struct drm_connector_state *new_conn_state;
5093 struct drm_connector *connector;
5096 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
5098 struct intel_connector *intel_connector;
5099 struct intel_encoder *encoder;
5100 struct intel_crtc *crtc;
5102 if (!intel_connector_needs_modeset(state, connector))
5105 intel_connector = to_intel_connector(connector);
5106 encoder = intel_connector_primary_encoder(intel_connector);
5107 if (!encoder->update_complete)
5110 crtc = new_conn_state->crtc ?
5111 to_intel_crtc(new_conn_state->crtc) : NULL;
5112 encoder->update_complete(state, encoder, crtc);
5116 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
5117 struct intel_crtc *crtc)
5119 const struct intel_crtc_state *crtc_state =
5120 intel_atomic_get_new_crtc_state(state, crtc);
5121 const struct drm_connector_state *conn_state;
5122 struct drm_connector *conn;
5125 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
5126 struct intel_encoder *encoder =
5127 to_intel_encoder(conn_state->best_encoder);
5129 if (conn_state->crtc != &crtc->base)
5132 if (encoder->pre_pll_enable)
5133 encoder->pre_pll_enable(state, encoder,
5134 crtc_state, conn_state);
5138 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
5139 struct intel_crtc *crtc)
5141 const struct intel_crtc_state *crtc_state =
5142 intel_atomic_get_new_crtc_state(state, crtc);
5143 const struct drm_connector_state *conn_state;
5144 struct drm_connector *conn;
5147 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
5148 struct intel_encoder *encoder =
5149 to_intel_encoder(conn_state->best_encoder);
5151 if (conn_state->crtc != &crtc->base)
5154 if (encoder->pre_enable)
5155 encoder->pre_enable(state, encoder,
5156 crtc_state, conn_state);
5160 static void intel_encoders_enable(struct intel_atomic_state *state,
5161 struct intel_crtc *crtc)
5163 const struct intel_crtc_state *crtc_state =
5164 intel_atomic_get_new_crtc_state(state, crtc);
5165 const struct drm_connector_state *conn_state;
5166 struct drm_connector *conn;
5169 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
5170 struct intel_encoder *encoder =
5171 to_intel_encoder(conn_state->best_encoder);
5173 if (conn_state->crtc != &crtc->base)
5176 if (encoder->enable)
5177 encoder->enable(state, encoder,
5178 crtc_state, conn_state);
5179 intel_opregion_notify_encoder(encoder, true);
5183 static void intel_encoders_disable(struct intel_atomic_state *state,
5184 struct intel_crtc *crtc)
5186 const struct intel_crtc_state *old_crtc_state =
5187 intel_atomic_get_old_crtc_state(state, crtc);
5188 const struct drm_connector_state *old_conn_state;
5189 struct drm_connector *conn;
5192 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
5193 struct intel_encoder *encoder =
5194 to_intel_encoder(old_conn_state->best_encoder);
5196 if (old_conn_state->crtc != &crtc->base)
5199 intel_opregion_notify_encoder(encoder, false);
5200 if (encoder->disable)
5201 encoder->disable(state, encoder,
5202 old_crtc_state, old_conn_state);
5206 static void intel_encoders_post_disable(struct intel_atomic_state *state,
5207 struct intel_crtc *crtc)
5209 const struct intel_crtc_state *old_crtc_state =
5210 intel_atomic_get_old_crtc_state(state, crtc);
5211 const struct drm_connector_state *old_conn_state;
5212 struct drm_connector *conn;
5215 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
5216 struct intel_encoder *encoder =
5217 to_intel_encoder(old_conn_state->best_encoder);
5219 if (old_conn_state->crtc != &crtc->base)
5222 if (encoder->post_disable)
5223 encoder->post_disable(state, encoder,
5224 old_crtc_state, old_conn_state);
5228 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
5229 struct intel_crtc *crtc)
5231 const struct intel_crtc_state *old_crtc_state =
5232 intel_atomic_get_old_crtc_state(state, crtc);
5233 const struct drm_connector_state *old_conn_state;
5234 struct drm_connector *conn;
5237 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
5238 struct intel_encoder *encoder =
5239 to_intel_encoder(old_conn_state->best_encoder);
5241 if (old_conn_state->crtc != &crtc->base)
5244 if (encoder->post_pll_disable)
5245 encoder->post_pll_disable(state, encoder,
5246 old_crtc_state, old_conn_state);
5250 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
5251 struct intel_crtc *crtc)
5253 const struct intel_crtc_state *crtc_state =
5254 intel_atomic_get_new_crtc_state(state, crtc);
5255 const struct drm_connector_state *conn_state;
5256 struct drm_connector *conn;
5259 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
5260 struct intel_encoder *encoder =
5261 to_intel_encoder(conn_state->best_encoder);
5263 if (conn_state->crtc != &crtc->base)
5266 if (encoder->update_pipe)
5267 encoder->update_pipe(state, encoder,
5268 crtc_state, conn_state);
5272 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
5274 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5275 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
5277 plane->disable_plane(plane, crtc_state);
5280 static void ilk_crtc_enable(struct intel_atomic_state *state,
5281 struct intel_crtc *crtc)
5283 const struct intel_crtc_state *new_crtc_state =
5284 intel_atomic_get_new_crtc_state(state, crtc);
5285 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5286 enum pipe pipe = crtc->pipe;
5288 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
5292 * Sometimes spurious CPU pipe underruns happen during FDI
5293 * training, at least with VGA+HDMI cloning. Suppress them.
5295 * On ILK we get an occasional spurious CPU pipe underruns
5296 * between eDP port A enable and vdd enable. Also PCH port
5297 * enable seems to result in the occasional CPU pipe underrun.
5299 * Spurious PCH underruns also occur during PCH enabling.
5301 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5302 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5304 if (new_crtc_state->has_pch_encoder)
5305 intel_prepare_shared_dpll(new_crtc_state);
5307 if (intel_crtc_has_dp_encoder(new_crtc_state))
5308 intel_dp_set_m_n(new_crtc_state, M1_N1);
5310 intel_set_transcoder_timings(new_crtc_state);
5311 intel_set_pipe_src_size(new_crtc_state);
5313 if (new_crtc_state->has_pch_encoder)
5314 intel_cpu_transcoder_set_m_n(new_crtc_state,
5315 &new_crtc_state->fdi_m_n, NULL);
5317 ilk_set_pipeconf(new_crtc_state);
5319 crtc->active = true;
5321 intel_encoders_pre_enable(state, crtc);
5323 if (new_crtc_state->has_pch_encoder) {
5324 /* Note: FDI PLL enabling _must_ be done before we enable the
5325 * cpu pipes, hence this is separate from all the other fdi/pch
5327 ilk_fdi_pll_enable(new_crtc_state);
5329 assert_fdi_tx_disabled(dev_priv, pipe);
5330 assert_fdi_rx_disabled(dev_priv, pipe);
5333 ilk_pfit_enable(new_crtc_state);
5336 * On ILK+ LUT must be loaded before the pipe is running but with
5339 intel_color_load_luts(new_crtc_state);
5340 intel_color_commit(new_crtc_state);
5341 /* update DSPCNTR to configure gamma for pipe bottom color */
5342 intel_disable_primary_plane(new_crtc_state);
5344 if (dev_priv->display.initial_watermarks)
5345 dev_priv->display.initial_watermarks(state, crtc);
5346 intel_enable_pipe(new_crtc_state);
5348 if (new_crtc_state->has_pch_encoder)
5349 ilk_pch_enable(state, new_crtc_state);
5351 intel_crtc_vblank_on(new_crtc_state);
5353 intel_encoders_enable(state, crtc);
5355 if (HAS_PCH_CPT(dev_priv))
5356 cpt_verify_modeset(dev_priv, pipe);
5359 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5360 * And a second vblank wait is needed at least on ILK with
5361 * some interlaced HDMI modes. Let's do the double wait always
5362 * in case there are more corner cases we don't know about.
5364 if (new_crtc_state->has_pch_encoder) {
5365 intel_wait_for_vblank(dev_priv, pipe);
5366 intel_wait_for_vblank(dev_priv, pipe);
5368 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5369 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5372 /* IPS only exists on ULT machines and is tied to pipe A. */
5373 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5375 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
5378 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5379 enum pipe pipe, bool apply)
5381 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
5382 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5389 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
5392 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5395 enum pipe pipe = crtc->pipe;
5398 val = MBUS_DBOX_A_CREDIT(2);
5400 if (INTEL_GEN(dev_priv) >= 12) {
5401 val |= MBUS_DBOX_BW_CREDIT(2);
5402 val |= MBUS_DBOX_B_CREDIT(12);
5404 val |= MBUS_DBOX_BW_CREDIT(1);
5405 val |= MBUS_DBOX_B_CREDIT(8);
5408 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
5411 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
5413 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5414 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5416 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
5417 HSW_LINETIME(crtc_state->linetime) |
5418 HSW_IPS_LINETIME(crtc_state->ips_linetime));
5421 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
5423 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5425 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
5428 val = intel_de_read(dev_priv, reg);
5429 val &= ~HSW_FRAME_START_DELAY_MASK;
5430 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
5431 intel_de_write(dev_priv, reg, val);
5434 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
5435 const struct intel_crtc_state *crtc_state)
5437 struct intel_crtc *master = to_intel_crtc(crtc_state->uapi.crtc);
5438 struct intel_crtc_state *master_crtc_state;
5439 struct drm_connector_state *conn_state;
5440 struct drm_connector *conn;
5441 struct intel_encoder *encoder = NULL;
5444 if (crtc_state->bigjoiner_slave)
5445 master = crtc_state->bigjoiner_linked_crtc;
5447 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
5449 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
5450 if (conn_state->crtc != &master->base)
5453 encoder = to_intel_encoder(conn_state->best_encoder);
5457 if (!crtc_state->bigjoiner_slave) {
5458 /* need to enable VDSC, which we skipped in pre-enable */
5459 intel_dsc_enable(encoder, crtc_state);
5462 * Enable sequence steps 1-7 on bigjoiner master
5464 intel_encoders_pre_pll_enable(state, master);
5465 intel_enable_shared_dpll(master_crtc_state);
5466 intel_encoders_pre_enable(state, master);
5468 /* and DSC on slave */
5469 intel_dsc_enable(NULL, crtc_state);
5473 static void hsw_crtc_enable(struct intel_atomic_state *state,
5474 struct intel_crtc *crtc)
5476 const struct intel_crtc_state *new_crtc_state =
5477 intel_atomic_get_new_crtc_state(state, crtc);
5478 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5479 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
5480 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
5481 bool psl_clkgate_wa;
5483 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
5486 if (!new_crtc_state->bigjoiner) {
5487 intel_encoders_pre_pll_enable(state, crtc);
5489 if (new_crtc_state->shared_dpll)
5490 intel_enable_shared_dpll(new_crtc_state);
5492 intel_encoders_pre_enable(state, crtc);
5494 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
5497 intel_set_pipe_src_size(new_crtc_state);
5498 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
5499 bdw_set_pipemisc(new_crtc_state);
5501 if (!new_crtc_state->bigjoiner_slave && !transcoder_is_dsi(cpu_transcoder)) {
5502 intel_set_transcoder_timings(new_crtc_state);
5504 if (cpu_transcoder != TRANSCODER_EDP)
5505 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
5506 new_crtc_state->pixel_multiplier - 1);
5508 if (new_crtc_state->has_pch_encoder)
5509 intel_cpu_transcoder_set_m_n(new_crtc_state,
5510 &new_crtc_state->fdi_m_n, NULL);
5512 hsw_set_frame_start_delay(new_crtc_state);
5515 if (!transcoder_is_dsi(cpu_transcoder))
5516 hsw_set_pipeconf(new_crtc_state);
5518 crtc->active = true;
5520 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5521 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
5522 new_crtc_state->pch_pfit.enabled;
5524 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5526 if (INTEL_GEN(dev_priv) >= 9)
5527 skl_pfit_enable(new_crtc_state);
5529 ilk_pfit_enable(new_crtc_state);
5532 * On ILK+ LUT must be loaded before the pipe is running but with
5535 intel_color_load_luts(new_crtc_state);
5536 intel_color_commit(new_crtc_state);
5537 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
5538 if (INTEL_GEN(dev_priv) < 9)
5539 intel_disable_primary_plane(new_crtc_state);
5541 hsw_set_linetime_wm(new_crtc_state);
5543 if (INTEL_GEN(dev_priv) >= 11)
5544 icl_set_pipe_chicken(crtc);
5546 if (dev_priv->display.initial_watermarks)
5547 dev_priv->display.initial_watermarks(state, crtc);
5549 if (INTEL_GEN(dev_priv) >= 11)
5550 icl_pipe_mbus_enable(crtc);
5552 if (new_crtc_state->bigjoiner_slave) {
5553 trace_intel_pipe_enable(crtc);
5554 intel_crtc_vblank_on(new_crtc_state);
5557 intel_encoders_enable(state, crtc);
5559 if (psl_clkgate_wa) {
5560 intel_wait_for_vblank(dev_priv, pipe);
5561 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5564 /* If we change the relative order between pipe/planes enabling, we need
5565 * to change the workaround. */
5566 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
5567 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
5568 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5569 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5573 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
5575 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
5576 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5577 enum pipe pipe = crtc->pipe;
5579 /* To avoid upsetting the power well on haswell only disable the pfit if
5580 * it's in use. The hw state code will make sure we get this right. */
5581 if (!old_crtc_state->pch_pfit.enabled)
5584 intel_de_write(dev_priv, PF_CTL(pipe), 0);
5585 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
5586 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
5589 static void ilk_crtc_disable(struct intel_atomic_state *state,
5590 struct intel_crtc *crtc)
5592 const struct intel_crtc_state *old_crtc_state =
5593 intel_atomic_get_old_crtc_state(state, crtc);
5594 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5595 enum pipe pipe = crtc->pipe;
5598 * Sometimes spurious CPU pipe underruns happen when the
5599 * pipe is already disabled, but FDI RX/TX is still enabled.
5600 * Happens at least with VGA+HDMI cloning. Suppress them.
5602 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5603 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
5605 intel_encoders_disable(state, crtc);
5607 intel_crtc_vblank_off(old_crtc_state);
5609 intel_disable_pipe(old_crtc_state);
5611 ilk_pfit_disable(old_crtc_state);
5613 if (old_crtc_state->has_pch_encoder)
5614 ilk_fdi_disable(crtc);
5616 intel_encoders_post_disable(state, crtc);
5618 if (old_crtc_state->has_pch_encoder) {
5619 ilk_disable_pch_transcoder(dev_priv, pipe);
5621 if (HAS_PCH_CPT(dev_priv)) {
5625 /* disable TRANS_DP_CTL */
5626 reg = TRANS_DP_CTL(pipe);
5627 temp = intel_de_read(dev_priv, reg);
5628 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5629 TRANS_DP_PORT_SEL_MASK);
5630 temp |= TRANS_DP_PORT_SEL_NONE;
5631 intel_de_write(dev_priv, reg, temp);
5633 /* disable DPLL_SEL */
5634 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
5635 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
5636 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
5639 ilk_fdi_pll_disable(crtc);
5642 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5643 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
5646 static void hsw_crtc_disable(struct intel_atomic_state *state,
5647 struct intel_crtc *crtc)
5650 * FIXME collapse everything to one hook.
5651 * Need care with mst->ddi interactions.
5653 intel_encoders_disable(state, crtc);
5654 intel_encoders_post_disable(state, crtc);
5657 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
5659 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5660 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5662 if (!crtc_state->gmch_pfit.control)
5666 * The panel fitter should only be adjusted whilst the pipe is disabled,
5667 * according to register description and PRM.
5669 drm_WARN_ON(&dev_priv->drm,
5670 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
5671 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
5673 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
5674 crtc_state->gmch_pfit.pgm_ratios);
5675 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
5677 /* Border color in case we don't scale up to the full screen. Black by
5678 * default, change to something else for debugging. */
5679 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
5682 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
5684 if (phy == PHY_NONE)
5686 else if (IS_ALDERLAKE_S(dev_priv))
5687 return phy <= PHY_E;
5688 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
5689 return phy <= PHY_D;
5690 else if (IS_JSL_EHL(dev_priv))
5691 return phy <= PHY_C;
5692 else if (INTEL_GEN(dev_priv) >= 11)
5693 return phy <= PHY_B;
5698 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
5700 if (IS_TIGERLAKE(dev_priv))
5701 return phy >= PHY_D && phy <= PHY_I;
5702 else if (IS_ICELAKE(dev_priv))
5703 return phy >= PHY_C && phy <= PHY_F;
5708 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
5710 if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
5711 return PHY_B + port - PORT_TC1;
5712 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
5713 return PHY_C + port - PORT_TC1;
5714 else if (IS_JSL_EHL(i915) && port == PORT_D)
5717 return PHY_A + port - PORT_A;
5720 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5722 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
5723 return TC_PORT_NONE;
5725 if (INTEL_GEN(dev_priv) >= 12)
5726 return TC_PORT_1 + port - PORT_TC1;
5728 return TC_PORT_1 + port - PORT_C;
5731 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
5735 return POWER_DOMAIN_PORT_DDI_A_LANES;
5737 return POWER_DOMAIN_PORT_DDI_B_LANES;
5739 return POWER_DOMAIN_PORT_DDI_C_LANES;
5741 return POWER_DOMAIN_PORT_DDI_D_LANES;
5743 return POWER_DOMAIN_PORT_DDI_E_LANES;
5745 return POWER_DOMAIN_PORT_DDI_F_LANES;
5747 return POWER_DOMAIN_PORT_DDI_G_LANES;
5749 return POWER_DOMAIN_PORT_DDI_H_LANES;
5751 return POWER_DOMAIN_PORT_DDI_I_LANES;
5754 return POWER_DOMAIN_PORT_OTHER;
5758 enum intel_display_power_domain
5759 intel_aux_power_domain(struct intel_digital_port *dig_port)
5761 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
5762 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
5764 if (intel_phy_is_tc(dev_priv, phy) &&
5765 dig_port->tc_mode == TC_PORT_TBT_ALT) {
5766 switch (dig_port->aux_ch) {
5768 return POWER_DOMAIN_AUX_C_TBT;
5770 return POWER_DOMAIN_AUX_D_TBT;
5772 return POWER_DOMAIN_AUX_E_TBT;
5774 return POWER_DOMAIN_AUX_F_TBT;
5776 return POWER_DOMAIN_AUX_G_TBT;
5778 return POWER_DOMAIN_AUX_H_TBT;
5780 return POWER_DOMAIN_AUX_I_TBT;
5782 MISSING_CASE(dig_port->aux_ch);
5783 return POWER_DOMAIN_AUX_C_TBT;
5787 return intel_legacy_aux_to_power_domain(dig_port->aux_ch);
5791 * Converts aux_ch to power_domain without caring about TBT ports for that use
5792 * intel_aux_power_domain()
5794 enum intel_display_power_domain
5795 intel_legacy_aux_to_power_domain(enum aux_ch aux_ch)
5799 return POWER_DOMAIN_AUX_A;
5801 return POWER_DOMAIN_AUX_B;
5803 return POWER_DOMAIN_AUX_C;
5805 return POWER_DOMAIN_AUX_D;
5807 return POWER_DOMAIN_AUX_E;
5809 return POWER_DOMAIN_AUX_F;
5811 return POWER_DOMAIN_AUX_G;
5813 return POWER_DOMAIN_AUX_H;
5815 return POWER_DOMAIN_AUX_I;
5817 MISSING_CASE(aux_ch);
5818 return POWER_DOMAIN_AUX_A;
5822 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
5824 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5825 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5826 struct drm_encoder *encoder;
5827 enum pipe pipe = crtc->pipe;
5829 enum transcoder transcoder = crtc_state->cpu_transcoder;
5831 if (!crtc_state->hw.active)
5834 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
5835 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
5836 if (crtc_state->pch_pfit.enabled ||
5837 crtc_state->pch_pfit.force_thru)
5838 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
5840 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
5841 crtc_state->uapi.encoder_mask) {
5842 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
5844 mask |= BIT_ULL(intel_encoder->power_domain);
5847 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
5848 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
5850 if (crtc_state->shared_dpll)
5851 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
5853 if (crtc_state->dsc.compression_enable)
5854 mask |= BIT_ULL(intel_dsc_power_domain(crtc_state));
5860 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
5862 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5863 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5864 enum intel_display_power_domain domain;
5865 u64 domains, new_domains, old_domains;
5867 domains = get_crtc_power_domains(crtc_state);
5869 new_domains = domains & ~crtc->enabled_power_domains.mask;
5870 old_domains = crtc->enabled_power_domains.mask & ~domains;
5872 for_each_power_domain(domain, new_domains)
5873 intel_display_power_get_in_set(dev_priv,
5874 &crtc->enabled_power_domains,
5880 static void modeset_put_crtc_power_domains(struct intel_crtc *crtc,
5883 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
5884 &crtc->enabled_power_domains,
5888 static void valleyview_crtc_enable(struct intel_atomic_state *state,
5889 struct intel_crtc *crtc)
5891 const struct intel_crtc_state *new_crtc_state =
5892 intel_atomic_get_new_crtc_state(state, crtc);
5893 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5894 enum pipe pipe = crtc->pipe;
5896 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
5899 if (intel_crtc_has_dp_encoder(new_crtc_state))
5900 intel_dp_set_m_n(new_crtc_state, M1_N1);
5902 intel_set_transcoder_timings(new_crtc_state);
5903 intel_set_pipe_src_size(new_crtc_state);
5905 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
5906 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
5907 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
5910 i9xx_set_pipeconf(new_crtc_state);
5912 crtc->active = true;
5914 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5916 intel_encoders_pre_pll_enable(state, crtc);
5918 if (IS_CHERRYVIEW(dev_priv)) {
5919 chv_prepare_pll(crtc, new_crtc_state);
5920 chv_enable_pll(crtc, new_crtc_state);
5922 vlv_prepare_pll(crtc, new_crtc_state);
5923 vlv_enable_pll(crtc, new_crtc_state);
5926 intel_encoders_pre_enable(state, crtc);
5928 i9xx_pfit_enable(new_crtc_state);
5930 intel_color_load_luts(new_crtc_state);
5931 intel_color_commit(new_crtc_state);
5932 /* update DSPCNTR to configure gamma for pipe bottom color */
5933 intel_disable_primary_plane(new_crtc_state);
5935 dev_priv->display.initial_watermarks(state, crtc);
5936 intel_enable_pipe(new_crtc_state);
5938 intel_crtc_vblank_on(new_crtc_state);
5940 intel_encoders_enable(state, crtc);
5943 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
5945 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5946 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5948 intel_de_write(dev_priv, FP0(crtc->pipe),
5949 crtc_state->dpll_hw_state.fp0);
5950 intel_de_write(dev_priv, FP1(crtc->pipe),
5951 crtc_state->dpll_hw_state.fp1);
5954 static void i9xx_crtc_enable(struct intel_atomic_state *state,
5955 struct intel_crtc *crtc)
5957 const struct intel_crtc_state *new_crtc_state =
5958 intel_atomic_get_new_crtc_state(state, crtc);
5959 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5960 enum pipe pipe = crtc->pipe;
5962 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
5965 i9xx_set_pll_dividers(new_crtc_state);
5967 if (intel_crtc_has_dp_encoder(new_crtc_state))
5968 intel_dp_set_m_n(new_crtc_state, M1_N1);
5970 intel_set_transcoder_timings(new_crtc_state);
5971 intel_set_pipe_src_size(new_crtc_state);
5973 i9xx_set_pipeconf(new_crtc_state);
5975 crtc->active = true;
5977 if (!IS_GEN(dev_priv, 2))
5978 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5980 intel_encoders_pre_enable(state, crtc);
5982 i9xx_enable_pll(crtc, new_crtc_state);
5984 i9xx_pfit_enable(new_crtc_state);
5986 intel_color_load_luts(new_crtc_state);
5987 intel_color_commit(new_crtc_state);
5988 /* update DSPCNTR to configure gamma for pipe bottom color */
5989 intel_disable_primary_plane(new_crtc_state);
5991 if (dev_priv->display.initial_watermarks)
5992 dev_priv->display.initial_watermarks(state, crtc);
5994 intel_update_watermarks(crtc);
5995 intel_enable_pipe(new_crtc_state);
5997 intel_crtc_vblank_on(new_crtc_state);
5999 intel_encoders_enable(state, crtc);
6001 /* prevents spurious underruns */
6002 if (IS_GEN(dev_priv, 2))
6003 intel_wait_for_vblank(dev_priv, pipe);
6006 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
6008 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
6009 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6011 if (!old_crtc_state->gmch_pfit.control)
6014 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
6016 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
6017 intel_de_read(dev_priv, PFIT_CONTROL));
6018 intel_de_write(dev_priv, PFIT_CONTROL, 0);
6021 static void i9xx_crtc_disable(struct intel_atomic_state *state,
6022 struct intel_crtc *crtc)
6024 struct intel_crtc_state *old_crtc_state =
6025 intel_atomic_get_old_crtc_state(state, crtc);
6026 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6027 enum pipe pipe = crtc->pipe;
6030 * On gen2 planes are double buffered but the pipe isn't, so we must
6031 * wait for planes to fully turn off before disabling the pipe.
6033 if (IS_GEN(dev_priv, 2))
6034 intel_wait_for_vblank(dev_priv, pipe);
6036 intel_encoders_disable(state, crtc);
6038 intel_crtc_vblank_off(old_crtc_state);
6040 intel_disable_pipe(old_crtc_state);
6042 i9xx_pfit_disable(old_crtc_state);
6044 intel_encoders_post_disable(state, crtc);
6046 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
6047 if (IS_CHERRYVIEW(dev_priv))
6048 chv_disable_pll(dev_priv, pipe);
6049 else if (IS_VALLEYVIEW(dev_priv))
6050 vlv_disable_pll(dev_priv, pipe);
6052 i9xx_disable_pll(old_crtc_state);
6055 intel_encoders_post_pll_disable(state, crtc);
6057 if (!IS_GEN(dev_priv, 2))
6058 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6060 if (!dev_priv->display.initial_watermarks)
6061 intel_update_watermarks(crtc);
6063 /* clock the pipe down to 640x480@60 to potentially save power */
6064 if (IS_I830(dev_priv))
6065 i830_enable_pipe(dev_priv, pipe);
6068 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
6069 struct drm_modeset_acquire_ctx *ctx)
6071 struct intel_encoder *encoder;
6072 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6073 struct intel_bw_state *bw_state =
6074 to_intel_bw_state(dev_priv->bw_obj.state);
6075 struct intel_cdclk_state *cdclk_state =
6076 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
6077 struct intel_dbuf_state *dbuf_state =
6078 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
6079 struct intel_crtc_state *crtc_state =
6080 to_intel_crtc_state(crtc->base.state);
6081 struct intel_plane *plane;
6082 struct drm_atomic_state *state;
6083 struct intel_crtc_state *temp_crtc_state;
6084 enum pipe pipe = crtc->pipe;
6087 if (!crtc_state->hw.active)
6090 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6091 const struct intel_plane_state *plane_state =
6092 to_intel_plane_state(plane->base.state);
6094 if (plane_state->uapi.visible)
6095 intel_plane_disable_noatomic(crtc, plane);
6098 state = drm_atomic_state_alloc(&dev_priv->drm);
6100 drm_dbg_kms(&dev_priv->drm,
6101 "failed to disable [CRTC:%d:%s], out of memory",
6102 crtc->base.base.id, crtc->base.name);
6106 state->acquire_ctx = ctx;
6108 /* Everything's already locked, -EDEADLK can't happen. */
6109 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
6110 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
6112 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
6114 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
6116 drm_atomic_state_put(state);
6118 drm_dbg_kms(&dev_priv->drm,
6119 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6120 crtc->base.base.id, crtc->base.name);
6122 crtc->active = false;
6123 crtc->base.enabled = false;
6125 drm_WARN_ON(&dev_priv->drm,
6126 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
6127 crtc_state->uapi.active = false;
6128 crtc_state->uapi.connector_mask = 0;
6129 crtc_state->uapi.encoder_mask = 0;
6130 intel_crtc_free_hw_state(crtc_state);
6131 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
6133 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
6134 encoder->base.crtc = NULL;
6136 intel_fbc_disable(crtc);
6137 intel_update_watermarks(crtc);
6138 intel_disable_shared_dpll(crtc_state);
6140 intel_display_power_put_all_in_set(dev_priv, &crtc->enabled_power_domains);
6142 dev_priv->active_pipes &= ~BIT(pipe);
6143 cdclk_state->min_cdclk[pipe] = 0;
6144 cdclk_state->min_voltage_level[pipe] = 0;
6145 cdclk_state->active_pipes &= ~BIT(pipe);
6147 dbuf_state->active_pipes &= ~BIT(pipe);
6149 bw_state->data_rate[pipe] = 0;
6150 bw_state->num_active_planes[pipe] = 0;
6154 * turn all crtc's off, but do not adjust state
6155 * This has to be paired with a call to intel_modeset_setup_hw_state.
6157 int intel_display_suspend(struct drm_device *dev)
6159 struct drm_i915_private *dev_priv = to_i915(dev);
6160 struct drm_atomic_state *state;
6163 state = drm_atomic_helper_suspend(dev);
6164 ret = PTR_ERR_OR_ZERO(state);
6166 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
6169 dev_priv->modeset_restore_state = state;
6173 void intel_encoder_destroy(struct drm_encoder *encoder)
6175 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6177 drm_encoder_cleanup(encoder);
6178 kfree(intel_encoder);
6181 /* Cross check the actual hw state with our own modeset state tracking (and it's
6182 * internal consistency). */
6183 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
6184 struct drm_connector_state *conn_state)
6186 struct intel_connector *connector = to_intel_connector(conn_state->connector);
6187 struct drm_i915_private *i915 = to_i915(connector->base.dev);
6189 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
6190 connector->base.base.id, connector->base.name);
6192 if (connector->get_hw_state(connector)) {
6193 struct intel_encoder *encoder = intel_attached_encoder(connector);
6195 I915_STATE_WARN(!crtc_state,
6196 "connector enabled without attached crtc\n");
6201 I915_STATE_WARN(!crtc_state->hw.active,
6202 "connector is active, but attached crtc isn't\n");
6204 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
6207 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
6208 "atomic encoder doesn't match attached encoder\n");
6210 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
6211 "attached encoder crtc differs from connector crtc\n");
6213 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
6214 "attached crtc is active, but connector isn't\n");
6215 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
6216 "best encoder set without crtc!\n");
6220 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
6222 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6223 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6225 /* IPS only exists on ULT machines and is tied to pipe A. */
6226 if (!hsw_crtc_supports_ips(crtc))
6229 if (!dev_priv->params.enable_ips)
6232 if (crtc_state->pipe_bpp > 24)
6236 * We compare against max which means we must take
6237 * the increased cdclk requirement into account when
6238 * calculating the new cdclk.
6240 * Should measure whether using a lower cdclk w/o IPS
6242 if (IS_BROADWELL(dev_priv) &&
6243 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6249 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
6251 struct drm_i915_private *dev_priv =
6252 to_i915(crtc_state->uapi.crtc->dev);
6253 struct intel_atomic_state *state =
6254 to_intel_atomic_state(crtc_state->uapi.state);
6256 crtc_state->ips_enabled = false;
6258 if (!hsw_crtc_state_ips_capable(crtc_state))
6262 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
6263 * enabled and disabled dynamically based on package C states,
6264 * user space can't make reliable use of the CRCs, so let's just
6265 * completely disable it.
6267 if (crtc_state->crc_enabled)
6270 /* IPS should be fine as long as at least one plane is enabled. */
6271 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
6274 if (IS_BROADWELL(dev_priv)) {
6275 const struct intel_cdclk_state *cdclk_state;
6277 cdclk_state = intel_atomic_get_cdclk_state(state);
6278 if (IS_ERR(cdclk_state))
6279 return PTR_ERR(cdclk_state);
6281 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6282 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
6286 crtc_state->ips_enabled = true;
6291 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6293 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6295 /* GDG double wide on either pipe, otherwise pipe A only */
6296 return INTEL_GEN(dev_priv) < 4 &&
6297 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6300 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
6302 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
6303 unsigned int pipe_w, pipe_h, pfit_w, pfit_h;
6306 * We only use IF-ID interlacing. If we ever use
6307 * PF-ID we'll need to adjust the pixel_rate here.
6310 if (!crtc_state->pch_pfit.enabled)
6313 pipe_w = crtc_state->pipe_src_w;
6314 pipe_h = crtc_state->pipe_src_h;
6316 pfit_w = drm_rect_width(&crtc_state->pch_pfit.dst);
6317 pfit_h = drm_rect_height(&crtc_state->pch_pfit.dst);
6319 if (pipe_w < pfit_w)
6321 if (pipe_h < pfit_h)
6324 if (drm_WARN_ON(crtc_state->uapi.crtc->dev,
6325 !pfit_w || !pfit_h))
6328 return div_u64(mul_u32_u32(pixel_rate, pipe_w * pipe_h),
6332 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
6333 const struct drm_display_mode *timings)
6335 mode->hdisplay = timings->crtc_hdisplay;
6336 mode->htotal = timings->crtc_htotal;
6337 mode->hsync_start = timings->crtc_hsync_start;
6338 mode->hsync_end = timings->crtc_hsync_end;
6340 mode->vdisplay = timings->crtc_vdisplay;
6341 mode->vtotal = timings->crtc_vtotal;
6342 mode->vsync_start = timings->crtc_vsync_start;
6343 mode->vsync_end = timings->crtc_vsync_end;
6345 mode->flags = timings->flags;
6346 mode->type = DRM_MODE_TYPE_DRIVER;
6348 mode->clock = timings->crtc_clock;
6350 drm_mode_set_name(mode);
6353 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6355 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
6357 if (HAS_GMCH(dev_priv))
6358 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6359 crtc_state->pixel_rate =
6360 crtc_state->hw.pipe_mode.crtc_clock;
6362 crtc_state->pixel_rate =
6363 ilk_pipe_pixel_rate(crtc_state);
6366 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
6368 struct drm_display_mode *mode = &crtc_state->hw.mode;
6369 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
6370 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
6372 drm_mode_copy(pipe_mode, adjusted_mode);
6374 if (crtc_state->bigjoiner) {
6376 * transcoder is programmed to the full mode,
6377 * but pipe timings are half of the transcoder mode
6379 pipe_mode->crtc_hdisplay /= 2;
6380 pipe_mode->crtc_hblank_start /= 2;
6381 pipe_mode->crtc_hblank_end /= 2;
6382 pipe_mode->crtc_hsync_start /= 2;
6383 pipe_mode->crtc_hsync_end /= 2;
6384 pipe_mode->crtc_htotal /= 2;
6385 pipe_mode->crtc_clock /= 2;
6388 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
6389 intel_mode_from_crtc_timings(adjusted_mode, adjusted_mode);
6391 intel_crtc_compute_pixel_rate(crtc_state);
6393 drm_mode_copy(mode, adjusted_mode);
6394 mode->hdisplay = crtc_state->pipe_src_w << crtc_state->bigjoiner;
6395 mode->vdisplay = crtc_state->pipe_src_h;
6398 static void intel_encoder_get_config(struct intel_encoder *encoder,
6399 struct intel_crtc_state *crtc_state)
6401 encoder->get_config(encoder, crtc_state);
6403 intel_crtc_readout_derived_state(crtc_state);
6406 static int intel_crtc_compute_config(struct intel_crtc *crtc,
6407 struct intel_crtc_state *pipe_config)
6409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6410 struct drm_display_mode *pipe_mode = &pipe_config->hw.pipe_mode;
6411 int clock_limit = dev_priv->max_dotclk_freq;
6413 drm_mode_copy(pipe_mode, &pipe_config->hw.adjusted_mode);
6415 /* Adjust pipe_mode for bigjoiner, with half the horizontal mode */
6416 if (pipe_config->bigjoiner) {
6417 pipe_mode->crtc_clock /= 2;
6418 pipe_mode->crtc_hdisplay /= 2;
6419 pipe_mode->crtc_hblank_start /= 2;
6420 pipe_mode->crtc_hblank_end /= 2;
6421 pipe_mode->crtc_hsync_start /= 2;
6422 pipe_mode->crtc_hsync_end /= 2;
6423 pipe_mode->crtc_htotal /= 2;
6424 pipe_config->pipe_src_w /= 2;
6427 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
6429 if (INTEL_GEN(dev_priv) < 4) {
6430 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
6433 * Enable double wide mode when the dot clock
6434 * is > 90% of the (display) core speed.
6436 if (intel_crtc_supports_double_wide(crtc) &&
6437 pipe_mode->crtc_clock > clock_limit) {
6438 clock_limit = dev_priv->max_dotclk_freq;
6439 pipe_config->double_wide = true;
6443 if (pipe_mode->crtc_clock > clock_limit) {
6444 drm_dbg_kms(&dev_priv->drm,
6445 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6446 pipe_mode->crtc_clock, clock_limit,
6447 yesno(pipe_config->double_wide));
6452 * Pipe horizontal size must be even in:
6454 * - LVDS dual channel mode
6455 * - Double wide pipe
6457 if (pipe_config->pipe_src_w & 1) {
6458 if (pipe_config->double_wide) {
6459 drm_dbg_kms(&dev_priv->drm,
6460 "Odd pipe source width not supported with double wide pipe\n");
6464 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6465 intel_is_dual_link_lvds(dev_priv)) {
6466 drm_dbg_kms(&dev_priv->drm,
6467 "Odd pipe source width not supported with dual link LVDS\n");
6472 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6473 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
6475 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
6476 pipe_mode->crtc_hsync_start == pipe_mode->crtc_hdisplay)
6479 intel_crtc_compute_pixel_rate(pipe_config);
6481 if (pipe_config->has_pch_encoder)
6482 return ilk_fdi_compute_config(crtc, pipe_config);
6488 intel_reduce_m_n_ratio(u32 *num, u32 *den)
6490 while (*num > DATA_LINK_M_N_MASK ||
6491 *den > DATA_LINK_M_N_MASK) {
6497 static void compute_m_n(unsigned int m, unsigned int n,
6498 u32 *ret_m, u32 *ret_n,
6502 * Several DP dongles in particular seem to be fussy about
6503 * too large link M/N values. Give N value as 0x8000 that
6504 * should be acceptable by specific devices. 0x8000 is the
6505 * specified fixed N value for asynchronous clock mode,
6506 * which the devices expect also in synchronous clock mode.
6509 *ret_n = DP_LINK_CONSTANT_N_VALUE;
6511 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
6513 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
6514 intel_reduce_m_n_ratio(ret_m, ret_n);
6518 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
6519 int pixel_clock, int link_clock,
6520 struct intel_link_m_n *m_n,
6521 bool constant_n, bool fec_enable)
6523 u32 data_clock = bits_per_pixel * pixel_clock;
6526 data_clock = intel_dp_mode_to_fec_clock(data_clock);
6529 compute_m_n(data_clock,
6530 link_clock * nlanes * 8,
6531 &m_n->gmch_m, &m_n->gmch_n,
6534 compute_m_n(pixel_clock, link_clock,
6535 &m_n->link_m, &m_n->link_n,
6539 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
6542 * There may be no VBT; and if the BIOS enabled SSC we can
6543 * just keep using it to avoid unnecessary flicker. Whereas if the
6544 * BIOS isn't using it, don't assume it will work even if the VBT
6545 * indicates as much.
6547 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
6548 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
6552 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
6553 drm_dbg_kms(&dev_priv->drm,
6554 "SSC %s by BIOS, overriding VBT which says %s\n",
6555 enableddisabled(bios_lvds_use_ssc),
6556 enableddisabled(dev_priv->vbt.lvds_use_ssc));
6557 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
6562 static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6568 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6569 * and set it to a reasonable value instead.
6571 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6572 reg_val &= 0xffffff00;
6573 reg_val |= 0x00000030;
6574 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6576 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6577 reg_val &= 0x00ffffff;
6578 reg_val |= 0x8c000000;
6579 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6581 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
6582 reg_val &= 0xffffff00;
6583 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
6585 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
6586 reg_val &= 0x00ffffff;
6587 reg_val |= 0xb0000000;
6588 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
6591 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6592 const struct intel_link_m_n *m_n)
6594 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6595 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6596 enum pipe pipe = crtc->pipe;
6598 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
6599 TU_SIZE(m_n->tu) | m_n->gmch_m);
6600 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6601 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6602 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
6605 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6606 enum transcoder transcoder)
6608 if (IS_HASWELL(dev_priv))
6609 return transcoder == TRANSCODER_EDP;
6612 * Strictly speaking some registers are available before
6613 * gen7, but we only support DRRS on gen7+
6615 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
6618 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6619 const struct intel_link_m_n *m_n,
6620 const struct intel_link_m_n *m2_n2)
6622 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6623 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6624 enum pipe pipe = crtc->pipe;
6625 enum transcoder transcoder = crtc_state->cpu_transcoder;
6627 if (INTEL_GEN(dev_priv) >= 5) {
6628 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
6629 TU_SIZE(m_n->tu) | m_n->gmch_m);
6630 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
6632 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
6634 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
6637 * M2_N2 registers are set only if DRRS is supported
6638 * (to make sure the registers are not unnecessarily accessed).
6640 if (m2_n2 && crtc_state->has_drrs &&
6641 transcoder_has_m2_n2(dev_priv, transcoder)) {
6642 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
6643 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6644 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
6646 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
6648 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
6652 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
6653 TU_SIZE(m_n->tu) | m_n->gmch_m);
6654 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6655 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
6656 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
6660 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
6662 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
6663 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
6666 dp_m_n = &crtc_state->dp_m_n;
6667 dp_m2_n2 = &crtc_state->dp_m2_n2;
6668 } else if (m_n == M2_N2) {
6671 * M2_N2 registers are not supported. Hence m2_n2 divider value
6672 * needs to be programmed into M1_N1.
6674 dp_m_n = &crtc_state->dp_m2_n2;
6676 drm_err(&i915->drm, "Unsupported divider value\n");
6680 if (crtc_state->has_pch_encoder)
6681 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
6683 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
6686 static void vlv_prepare_pll(struct intel_crtc *crtc,
6687 const struct intel_crtc_state *pipe_config)
6689 struct drm_device *dev = crtc->base.dev;
6690 struct drm_i915_private *dev_priv = to_i915(dev);
6691 enum pipe pipe = crtc->pipe;
6693 u32 bestn, bestm1, bestm2, bestp1, bestp2;
6694 u32 coreclk, reg_val;
6697 intel_de_write(dev_priv, DPLL(pipe),
6698 pipe_config->dpll_hw_state.dpll & ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6700 /* No need to actually set up the DPLL with DSI */
6701 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6704 vlv_dpio_get(dev_priv);
6706 bestn = pipe_config->dpll.n;
6707 bestm1 = pipe_config->dpll.m1;
6708 bestm2 = pipe_config->dpll.m2;
6709 bestp1 = pipe_config->dpll.p1;
6710 bestp2 = pipe_config->dpll.p2;
6712 /* See eDP HDMI DPIO driver vbios notes doc */
6714 /* PLL B needs special handling */
6716 vlv_pllb_recal_opamp(dev_priv, pipe);
6718 /* Set up Tx target for periodic Rcomp update */
6719 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
6721 /* Disable target IRef on PLL */
6722 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
6723 reg_val &= 0x00ffffff;
6724 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
6726 /* Disable fast lock */
6727 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
6729 /* Set idtafcrecal before PLL is enabled */
6730 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
6731 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
6732 mdiv |= ((bestn << DPIO_N_SHIFT));
6733 mdiv |= (1 << DPIO_K_SHIFT);
6736 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
6737 * but we don't support that).
6738 * Note: don't use the DAC post divider as it seems unstable.
6740 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
6741 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6743 mdiv |= DPIO_ENABLE_CALIBRATION;
6744 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
6746 /* Set HBR and RBR LPF coefficients */
6747 if (pipe_config->port_clock == 162000 ||
6748 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
6749 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
6750 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6753 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
6756 if (intel_crtc_has_dp_encoder(pipe_config)) {
6757 /* Use SSC source */
6759 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6762 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6764 } else { /* HDMI or VGA */
6765 /* Use bend source */
6767 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6770 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
6774 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
6775 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
6776 if (intel_crtc_has_dp_encoder(pipe_config))
6777 coreclk |= 0x01000000;
6778 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
6780 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
6782 vlv_dpio_put(dev_priv);
6785 static void chv_prepare_pll(struct intel_crtc *crtc,
6786 const struct intel_crtc_state *pipe_config)
6788 struct drm_device *dev = crtc->base.dev;
6789 struct drm_i915_private *dev_priv = to_i915(dev);
6790 enum pipe pipe = crtc->pipe;
6791 enum dpio_channel port = vlv_pipe_to_channel(pipe);
6792 u32 loopfilter, tribuf_calcntr;
6793 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
6797 /* Enable Refclk and SSC */
6798 intel_de_write(dev_priv, DPLL(pipe),
6799 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
6801 /* No need to actually set up the DPLL with DSI */
6802 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6805 bestn = pipe_config->dpll.n;
6806 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
6807 bestm1 = pipe_config->dpll.m1;
6808 bestm2 = pipe_config->dpll.m2 >> 22;
6809 bestp1 = pipe_config->dpll.p1;
6810 bestp2 = pipe_config->dpll.p2;
6811 vco = pipe_config->dpll.vco;
6815 vlv_dpio_get(dev_priv);
6817 /* p1 and p2 divider */
6818 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
6819 5 << DPIO_CHV_S1_DIV_SHIFT |
6820 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
6821 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
6822 1 << DPIO_CHV_K_DIV_SHIFT);
6824 /* Feedback post-divider - m2 */
6825 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
6827 /* Feedback refclk divider - n and m1 */
6828 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
6829 DPIO_CHV_M1_DIV_BY_2 |
6830 1 << DPIO_CHV_N_DIV_SHIFT);
6832 /* M2 fraction division */
6833 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
6835 /* M2 fraction division enable */
6836 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
6837 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
6838 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
6840 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
6841 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
6843 /* Program digital lock detect threshold */
6844 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
6845 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
6846 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
6847 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
6849 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
6850 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
6853 if (vco == 5400000) {
6854 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
6855 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
6856 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
6857 tribuf_calcntr = 0x9;
6858 } else if (vco <= 6200000) {
6859 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
6860 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
6861 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6862 tribuf_calcntr = 0x9;
6863 } else if (vco <= 6480000) {
6864 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6865 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6866 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6867 tribuf_calcntr = 0x8;
6869 /* Not supported. Apply the same limits as in the max case */
6870 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
6871 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
6872 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
6875 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
6877 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
6878 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
6879 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
6880 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
6883 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
6884 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
6887 vlv_dpio_put(dev_priv);
6891 * vlv_force_pll_on - forcibly enable just the PLL
6892 * @dev_priv: i915 private structure
6893 * @pipe: pipe PLL to enable
6894 * @dpll: PLL configuration
6896 * Enable the PLL for @pipe using the supplied @dpll config. To be used
6897 * in cases where we need the PLL enabled even when @pipe is not going to
6900 int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
6901 const struct dpll *dpll)
6903 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
6904 struct intel_crtc_state *pipe_config;
6906 pipe_config = intel_crtc_state_alloc(crtc);
6910 pipe_config->cpu_transcoder = (enum transcoder)pipe;
6911 pipe_config->pixel_multiplier = 1;
6912 pipe_config->dpll = *dpll;
6914 if (IS_CHERRYVIEW(dev_priv)) {
6915 chv_compute_dpll(crtc, pipe_config);
6916 chv_prepare_pll(crtc, pipe_config);
6917 chv_enable_pll(crtc, pipe_config);
6919 vlv_compute_dpll(crtc, pipe_config);
6920 vlv_prepare_pll(crtc, pipe_config);
6921 vlv_enable_pll(crtc, pipe_config);
6930 * vlv_force_pll_off - forcibly disable just the PLL
6931 * @dev_priv: i915 private structure
6932 * @pipe: pipe PLL to disable
6934 * Disable the PLL for @pipe. To be used in cases where we need
6935 * the PLL enabled even when @pipe is not going to be enabled.
6937 void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
6939 if (IS_CHERRYVIEW(dev_priv))
6940 chv_disable_pll(dev_priv, pipe);
6942 vlv_disable_pll(dev_priv, pipe);
6947 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
6949 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6950 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6951 enum pipe pipe = crtc->pipe;
6952 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
6953 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
6954 u32 crtc_vtotal, crtc_vblank_end;
6957 /* We need to be careful not to changed the adjusted mode, for otherwise
6958 * the hw state checker will get angry at the mismatch. */
6959 crtc_vtotal = adjusted_mode->crtc_vtotal;
6960 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
6962 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
6963 /* the chip adds 2 halflines automatically */
6965 crtc_vblank_end -= 1;
6967 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
6968 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
6970 vsyncshift = adjusted_mode->crtc_hsync_start -
6971 adjusted_mode->crtc_htotal / 2;
6973 vsyncshift += adjusted_mode->crtc_htotal;
6976 if (INTEL_GEN(dev_priv) > 3)
6977 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
6980 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
6981 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
6982 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
6983 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
6984 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
6985 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
6987 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
6988 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
6989 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
6990 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
6991 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
6992 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
6994 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
6995 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
6996 * documented on the DDI_FUNC_CTL register description, EDP Input Select
6998 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
6999 (pipe == PIPE_B || pipe == PIPE_C))
7000 intel_de_write(dev_priv, VTOTAL(pipe),
7001 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
7005 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
7007 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7009 enum pipe pipe = crtc->pipe;
7011 /* pipesrc controls the size that is scaled from, which should
7012 * always be the user's requested size.
7014 intel_de_write(dev_priv, PIPESRC(pipe),
7015 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
7018 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
7020 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
7021 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7023 if (IS_GEN(dev_priv, 2))
7026 if (INTEL_GEN(dev_priv) >= 9 ||
7027 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
7028 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
7030 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
7033 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
7034 struct intel_crtc_state *pipe_config)
7036 struct drm_device *dev = crtc->base.dev;
7037 struct drm_i915_private *dev_priv = to_i915(dev);
7038 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7041 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
7042 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7043 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
7045 if (!transcoder_is_dsi(cpu_transcoder)) {
7046 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
7047 pipe_config->hw.adjusted_mode.crtc_hblank_start =
7049 pipe_config->hw.adjusted_mode.crtc_hblank_end =
7050 ((tmp >> 16) & 0xffff) + 1;
7052 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
7053 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7054 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
7056 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
7057 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7058 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
7060 if (!transcoder_is_dsi(cpu_transcoder)) {
7061 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
7062 pipe_config->hw.adjusted_mode.crtc_vblank_start =
7064 pipe_config->hw.adjusted_mode.crtc_vblank_end =
7065 ((tmp >> 16) & 0xffff) + 1;
7067 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
7068 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7069 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
7071 if (intel_pipe_is_interlaced(pipe_config)) {
7072 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7073 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
7074 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
7078 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7079 struct intel_crtc_state *pipe_config)
7081 struct drm_device *dev = crtc->base.dev;
7082 struct drm_i915_private *dev_priv = to_i915(dev);
7085 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
7086 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7087 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7090 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
7092 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7093 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7098 /* we keep both pipes enabled on 830 */
7099 if (IS_I830(dev_priv))
7100 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
7102 if (crtc_state->double_wide)
7103 pipeconf |= PIPECONF_DOUBLE_WIDE;
7105 /* only g4x and later have fancy bpc/dither controls */
7106 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7107 IS_CHERRYVIEW(dev_priv)) {
7108 /* Bspec claims that we can't use dithering for 30bpp pipes. */
7109 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
7110 pipeconf |= PIPECONF_DITHER_EN |
7111 PIPECONF_DITHER_TYPE_SP;
7113 switch (crtc_state->pipe_bpp) {
7115 pipeconf |= PIPECONF_6BPC;
7118 pipeconf |= PIPECONF_8BPC;
7121 pipeconf |= PIPECONF_10BPC;
7124 /* Case prevented by intel_choose_pipe_bpp_dither. */
7129 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
7130 if (INTEL_GEN(dev_priv) < 4 ||
7131 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
7132 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7134 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7136 pipeconf |= PIPECONF_PROGRESSIVE;
7139 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7140 crtc_state->limited_color_range)
7141 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
7143 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
7145 pipeconf |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
7147 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
7148 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
7151 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
7153 if (IS_I830(dev_priv))
7156 return INTEL_GEN(dev_priv) >= 4 ||
7157 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
7160 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
7162 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7163 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7166 if (!i9xx_has_pfit(dev_priv))
7169 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
7170 if (!(tmp & PFIT_ENABLE))
7173 /* Check whether the pfit is attached to our pipe. */
7174 if (INTEL_GEN(dev_priv) < 4) {
7175 if (crtc->pipe != PIPE_B)
7178 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7182 crtc_state->gmch_pfit.control = tmp;
7183 crtc_state->gmch_pfit.pgm_ratios =
7184 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
7187 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
7188 struct intel_crtc_state *pipe_config)
7190 struct drm_device *dev = crtc->base.dev;
7191 struct drm_i915_private *dev_priv = to_i915(dev);
7192 enum pipe pipe = crtc->pipe;
7195 int refclk = 100000;
7197 /* In case of DSI, DPLL will not be used */
7198 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7201 vlv_dpio_get(dev_priv);
7202 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
7203 vlv_dpio_put(dev_priv);
7205 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7206 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7207 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7208 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7209 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7211 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
7215 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7216 struct intel_initial_plane_config *plane_config)
7218 struct drm_device *dev = crtc->base.dev;
7219 struct drm_i915_private *dev_priv = to_i915(dev);
7220 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7221 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7223 u32 val, base, offset;
7224 int fourcc, pixel_format;
7225 unsigned int aligned_height;
7226 struct drm_framebuffer *fb;
7227 struct intel_framebuffer *intel_fb;
7229 if (!plane->get_hw_state(plane, &pipe))
7232 drm_WARN_ON(dev, pipe != crtc->pipe);
7234 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
7236 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
7240 fb = &intel_fb->base;
7244 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
7246 if (INTEL_GEN(dev_priv) >= 4) {
7247 if (val & DISPPLANE_TILED) {
7248 plane_config->tiling = I915_TILING_X;
7249 fb->modifier = I915_FORMAT_MOD_X_TILED;
7252 if (val & DISPPLANE_ROTATE_180)
7253 plane_config->rotation = DRM_MODE_ROTATE_180;
7256 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
7257 val & DISPPLANE_MIRROR)
7258 plane_config->rotation |= DRM_MODE_REFLECT_X;
7260 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
7261 fourcc = i9xx_format_to_fourcc(pixel_format);
7262 fb->format = drm_format_info(fourcc);
7264 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7265 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
7266 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
7267 } else if (INTEL_GEN(dev_priv) >= 4) {
7268 if (plane_config->tiling)
7269 offset = intel_de_read(dev_priv,
7270 DSPTILEOFF(i9xx_plane));
7272 offset = intel_de_read(dev_priv,
7273 DSPLINOFF(i9xx_plane));
7274 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
7276 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
7278 plane_config->base = base;
7280 val = intel_de_read(dev_priv, PIPESRC(pipe));
7281 fb->width = ((val >> 16) & 0xfff) + 1;
7282 fb->height = ((val >> 0) & 0xfff) + 1;
7284 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
7285 fb->pitches[0] = val & 0xffffffc0;
7287 aligned_height = intel_fb_align_height(fb, 0, fb->height);
7289 plane_config->size = fb->pitches[0] * aligned_height;
7291 drm_dbg_kms(&dev_priv->drm,
7292 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7293 crtc->base.name, plane->base.name, fb->width, fb->height,
7294 fb->format->cpp[0] * 8, base, fb->pitches[0],
7295 plane_config->size);
7297 plane_config->fb = intel_fb;
7300 static void chv_crtc_clock_get(struct intel_crtc *crtc,
7301 struct intel_crtc_state *pipe_config)
7303 struct drm_device *dev = crtc->base.dev;
7304 struct drm_i915_private *dev_priv = to_i915(dev);
7305 enum pipe pipe = crtc->pipe;
7306 enum dpio_channel port = vlv_pipe_to_channel(pipe);
7308 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
7309 int refclk = 100000;
7311 /* In case of DSI, DPLL will not be used */
7312 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7315 vlv_dpio_get(dev_priv);
7316 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7317 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7318 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7319 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
7320 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7321 vlv_dpio_put(dev_priv);
7323 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
7324 clock.m2 = (pll_dw0 & 0xff) << 22;
7325 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7326 clock.m2 |= pll_dw2 & 0x3fffff;
7327 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7328 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7329 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7331 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
7334 static enum intel_output_format
7335 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
7337 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7340 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
7342 if (tmp & PIPEMISC_YUV420_ENABLE) {
7343 /* We support 4:2:0 in full blend mode only */
7344 drm_WARN_ON(&dev_priv->drm,
7345 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
7347 return INTEL_OUTPUT_FORMAT_YCBCR420;
7348 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7349 return INTEL_OUTPUT_FORMAT_YCBCR444;
7351 return INTEL_OUTPUT_FORMAT_RGB;
7355 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
7357 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7358 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7360 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
7363 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
7365 if (tmp & DISPPLANE_GAMMA_ENABLE)
7366 crtc_state->gamma_enable = true;
7368 if (!HAS_GMCH(dev_priv) &&
7369 tmp & DISPPLANE_PIPE_CSC_ENABLE)
7370 crtc_state->csc_enable = true;
7373 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
7374 struct intel_crtc_state *pipe_config)
7376 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7377 enum intel_display_power_domain power_domain;
7378 intel_wakeref_t wakeref;
7382 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7383 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
7387 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
7388 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
7389 pipe_config->shared_dpll = NULL;
7393 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
7394 if (!(tmp & PIPECONF_ENABLE))
7397 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7398 IS_CHERRYVIEW(dev_priv)) {
7399 switch (tmp & PIPECONF_BPC_MASK) {
7401 pipe_config->pipe_bpp = 18;
7404 pipe_config->pipe_bpp = 24;
7406 case PIPECONF_10BPC:
7407 pipe_config->pipe_bpp = 30;
7414 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
7415 (tmp & PIPECONF_COLOR_RANGE_SELECT))
7416 pipe_config->limited_color_range = true;
7418 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
7419 PIPECONF_GAMMA_MODE_SHIFT;
7421 if (IS_CHERRYVIEW(dev_priv))
7422 pipe_config->cgm_mode = intel_de_read(dev_priv,
7423 CGM_PIPE_MODE(crtc->pipe));
7425 i9xx_get_pipe_color_config(pipe_config);
7426 intel_color_get_config(pipe_config);
7428 if (INTEL_GEN(dev_priv) < 4)
7429 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7431 intel_get_transcoder_timings(crtc, pipe_config);
7432 intel_get_pipe_src_size(crtc, pipe_config);
7434 i9xx_get_pfit_config(pipe_config);
7436 if (INTEL_GEN(dev_priv) >= 4) {
7437 /* No way to read it out on pipes B and C */
7438 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
7439 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7441 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
7442 pipe_config->pixel_multiplier =
7443 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
7444 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
7445 pipe_config->dpll_hw_state.dpll_md = tmp;
7446 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7447 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
7448 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
7449 pipe_config->pixel_multiplier =
7450 ((tmp & SDVO_MULTIPLIER_MASK)
7451 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
7453 /* Note that on i915G/GM the pixel multiplier is in the sdvo
7454 * port and will be fixed up in the encoder->get_config
7456 pipe_config->pixel_multiplier = 1;
7458 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
7460 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
7461 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
7463 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
7466 /* Mask out read-only status bits. */
7467 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
7468 DPLL_PORTC_READY_MASK |
7469 DPLL_PORTB_READY_MASK);
7472 if (IS_CHERRYVIEW(dev_priv))
7473 chv_crtc_clock_get(crtc, pipe_config);
7474 else if (IS_VALLEYVIEW(dev_priv))
7475 vlv_crtc_clock_get(crtc, pipe_config);
7477 i9xx_crtc_clock_get(crtc, pipe_config);
7480 * Normally the dotclock is filled in by the encoder .get_config()
7481 * but in case the pipe is enabled w/o any ports we need a sane
7484 pipe_config->hw.adjusted_mode.crtc_clock =
7485 pipe_config->port_clock / pipe_config->pixel_multiplier;
7490 intel_display_power_put(dev_priv, power_domain, wakeref);
7495 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
7497 struct intel_encoder *encoder;
7500 bool has_lvds = false;
7501 bool has_cpu_edp = false;
7502 bool has_panel = false;
7503 bool has_ck505 = false;
7504 bool can_ssc = false;
7505 bool using_ssc_source = false;
7507 /* We need to take the global config into account */
7508 for_each_intel_encoder(&dev_priv->drm, encoder) {
7509 switch (encoder->type) {
7510 case INTEL_OUTPUT_LVDS:
7514 case INTEL_OUTPUT_EDP:
7516 if (encoder->port == PORT_A)
7524 if (HAS_PCH_IBX(dev_priv)) {
7525 has_ck505 = dev_priv->vbt.display_clock_mode;
7526 can_ssc = has_ck505;
7532 /* Check if any DPLLs are using the SSC source */
7533 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
7534 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
7536 if (!(temp & DPLL_VCO_ENABLE))
7539 if ((temp & PLL_REF_INPUT_MASK) ==
7540 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
7541 using_ssc_source = true;
7546 drm_dbg_kms(&dev_priv->drm,
7547 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
7548 has_panel, has_lvds, has_ck505, using_ssc_source);
7550 /* Ironlake: try to setup display ref clock before DPLL
7551 * enabling. This is only under driver's control after
7552 * PCH B stepping, previous chipset stepping should be
7553 * ignoring this setting.
7555 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
7557 /* As we must carefully and slowly disable/enable each source in turn,
7558 * compute the final state we want first and check if we need to
7559 * make any changes at all.
7562 final &= ~DREF_NONSPREAD_SOURCE_MASK;
7564 final |= DREF_NONSPREAD_CK505_ENABLE;
7566 final |= DREF_NONSPREAD_SOURCE_ENABLE;
7568 final &= ~DREF_SSC_SOURCE_MASK;
7569 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7570 final &= ~DREF_SSC1_ENABLE;
7573 final |= DREF_SSC_SOURCE_ENABLE;
7575 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7576 final |= DREF_SSC1_ENABLE;
7579 if (intel_panel_use_ssc(dev_priv) && can_ssc)
7580 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7582 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7584 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7585 } else if (using_ssc_source) {
7586 final |= DREF_SSC_SOURCE_ENABLE;
7587 final |= DREF_SSC1_ENABLE;
7593 /* Always enable nonspread source */
7594 val &= ~DREF_NONSPREAD_SOURCE_MASK;
7597 val |= DREF_NONSPREAD_CK505_ENABLE;
7599 val |= DREF_NONSPREAD_SOURCE_ENABLE;
7602 val &= ~DREF_SSC_SOURCE_MASK;
7603 val |= DREF_SSC_SOURCE_ENABLE;
7605 /* SSC must be turned on before enabling the CPU output */
7606 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7607 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
7608 val |= DREF_SSC1_ENABLE;
7610 val &= ~DREF_SSC1_ENABLE;
7612 /* Get SSC going before enabling the outputs */
7613 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
7614 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
7617 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7619 /* Enable CPU source on CPU attached eDP */
7621 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
7622 drm_dbg_kms(&dev_priv->drm,
7623 "Using SSC on eDP\n");
7624 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
7626 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
7628 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7630 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
7631 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
7634 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
7636 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
7638 /* Turn off CPU output */
7639 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
7641 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
7642 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
7645 if (!using_ssc_source) {
7646 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
7648 /* Turn off the SSC source */
7649 val &= ~DREF_SSC_SOURCE_MASK;
7650 val |= DREF_SSC_SOURCE_DISABLE;
7653 val &= ~DREF_SSC1_ENABLE;
7655 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
7656 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
7661 BUG_ON(val != final);
7664 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
7668 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
7669 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
7670 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
7672 if (wait_for_us(intel_de_read(dev_priv, SOUTH_CHICKEN2) &
7673 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
7674 drm_err(&dev_priv->drm, "FDI mPHY reset assert timeout\n");
7676 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
7677 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
7678 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
7680 if (wait_for_us((intel_de_read(dev_priv, SOUTH_CHICKEN2) &
7681 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
7682 drm_err(&dev_priv->drm, "FDI mPHY reset de-assert timeout\n");
7685 /* WaMPhyProgramming:hsw */
7686 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
7690 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
7691 tmp &= ~(0xFF << 24);
7692 tmp |= (0x12 << 24);
7693 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
7695 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
7697 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
7699 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
7701 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
7703 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
7704 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7705 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
7707 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
7708 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
7709 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
7711 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
7714 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
7716 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
7719 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
7721 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
7724 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
7726 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
7729 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
7731 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
7732 tmp &= ~(0xFF << 16);
7733 tmp |= (0x1C << 16);
7734 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
7736 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
7737 tmp &= ~(0xFF << 16);
7738 tmp |= (0x1C << 16);
7739 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
7741 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
7743 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
7745 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
7747 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
7749 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
7750 tmp &= ~(0xF << 28);
7752 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
7754 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
7755 tmp &= ~(0xF << 28);
7757 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
7760 /* Implements 3 different sequences from BSpec chapter "Display iCLK
7761 * Programming" based on the parameters passed:
7762 * - Sequence to enable CLKOUT_DP
7763 * - Sequence to enable CLKOUT_DP without spread
7764 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
7766 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
7767 bool with_spread, bool with_fdi)
7771 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
7772 "FDI requires downspread\n"))
7774 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
7775 with_fdi, "LP PCH doesn't have FDI\n"))
7778 mutex_lock(&dev_priv->sb_lock);
7780 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7781 tmp &= ~SBI_SSCCTL_DISABLE;
7782 tmp |= SBI_SSCCTL_PATHALT;
7783 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7788 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7789 tmp &= ~SBI_SSCCTL_PATHALT;
7790 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7793 lpt_reset_fdi_mphy(dev_priv);
7794 lpt_program_fdi_mphy(dev_priv);
7798 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
7799 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
7800 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
7801 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
7803 mutex_unlock(&dev_priv->sb_lock);
7806 /* Sequence to disable CLKOUT_DP */
7807 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
7811 mutex_lock(&dev_priv->sb_lock);
7813 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
7814 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
7815 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
7816 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
7818 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
7819 if (!(tmp & SBI_SSCCTL_DISABLE)) {
7820 if (!(tmp & SBI_SSCCTL_PATHALT)) {
7821 tmp |= SBI_SSCCTL_PATHALT;
7822 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7825 tmp |= SBI_SSCCTL_DISABLE;
7826 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
7829 mutex_unlock(&dev_priv->sb_lock);
7832 #define BEND_IDX(steps) ((50 + (steps)) / 5)
7834 static const u16 sscdivintphase[] = {
7835 [BEND_IDX( 50)] = 0x3B23,
7836 [BEND_IDX( 45)] = 0x3B23,
7837 [BEND_IDX( 40)] = 0x3C23,
7838 [BEND_IDX( 35)] = 0x3C23,
7839 [BEND_IDX( 30)] = 0x3D23,
7840 [BEND_IDX( 25)] = 0x3D23,
7841 [BEND_IDX( 20)] = 0x3E23,
7842 [BEND_IDX( 15)] = 0x3E23,
7843 [BEND_IDX( 10)] = 0x3F23,
7844 [BEND_IDX( 5)] = 0x3F23,
7845 [BEND_IDX( 0)] = 0x0025,
7846 [BEND_IDX( -5)] = 0x0025,
7847 [BEND_IDX(-10)] = 0x0125,
7848 [BEND_IDX(-15)] = 0x0125,
7849 [BEND_IDX(-20)] = 0x0225,
7850 [BEND_IDX(-25)] = 0x0225,
7851 [BEND_IDX(-30)] = 0x0325,
7852 [BEND_IDX(-35)] = 0x0325,
7853 [BEND_IDX(-40)] = 0x0425,
7854 [BEND_IDX(-45)] = 0x0425,
7855 [BEND_IDX(-50)] = 0x0525,
7860 * steps -50 to 50 inclusive, in steps of 5
7861 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
7862 * change in clock period = -(steps / 10) * 5.787 ps
7864 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
7867 int idx = BEND_IDX(steps);
7869 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
7872 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
7875 mutex_lock(&dev_priv->sb_lock);
7877 if (steps % 10 != 0)
7881 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
7883 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
7885 tmp |= sscdivintphase[idx];
7886 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
7888 mutex_unlock(&dev_priv->sb_lock);
7893 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
7895 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
7896 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
7898 if ((ctl & SPLL_PLL_ENABLE) == 0)
7901 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
7902 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
7905 if (IS_BROADWELL(dev_priv) &&
7906 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
7912 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
7913 enum intel_dpll_id id)
7915 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
7916 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
7918 if ((ctl & WRPLL_PLL_ENABLE) == 0)
7921 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
7924 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
7925 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
7926 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
7932 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
7934 struct intel_encoder *encoder;
7935 bool has_fdi = false;
7937 for_each_intel_encoder(&dev_priv->drm, encoder) {
7938 switch (encoder->type) {
7939 case INTEL_OUTPUT_ANALOG:
7948 * The BIOS may have decided to use the PCH SSC
7949 * reference so we must not disable it until the
7950 * relevant PLLs have stopped relying on it. We'll
7951 * just leave the PCH SSC reference enabled in case
7952 * any active PLL is using it. It will get disabled
7953 * after runtime suspend if we don't have FDI.
7955 * TODO: Move the whole reference clock handling
7956 * to the modeset sequence proper so that we can
7957 * actually enable/disable/reconfigure these things
7958 * safely. To do that we need to introduce a real
7959 * clock hierarchy. That would also allow us to do
7960 * clock bending finally.
7962 dev_priv->pch_ssc_use = 0;
7964 if (spll_uses_pch_ssc(dev_priv)) {
7965 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
7966 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
7969 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
7970 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
7971 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
7974 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
7975 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
7976 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
7979 if (dev_priv->pch_ssc_use)
7983 lpt_bend_clkout_dp(dev_priv, 0);
7984 lpt_enable_clkout_dp(dev_priv, true, true);
7986 lpt_disable_clkout_dp(dev_priv);
7991 * Initialize reference clocks when the driver loads
7993 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
7995 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
7996 ilk_init_pch_refclk(dev_priv);
7997 else if (HAS_PCH_LPT(dev_priv))
7998 lpt_init_pch_refclk(dev_priv);
8001 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
8003 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8004 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8005 enum pipe pipe = crtc->pipe;
8010 switch (crtc_state->pipe_bpp) {
8012 val |= PIPECONF_6BPC;
8015 val |= PIPECONF_8BPC;
8018 val |= PIPECONF_10BPC;
8021 val |= PIPECONF_12BPC;
8024 /* Case prevented by intel_choose_pipe_bpp_dither. */
8028 if (crtc_state->dither)
8029 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8031 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8032 val |= PIPECONF_INTERLACED_ILK;
8034 val |= PIPECONF_PROGRESSIVE;
8037 * This would end up with an odd purple hue over
8038 * the entire display. Make sure we don't do it.
8040 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
8041 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
8043 if (crtc_state->limited_color_range &&
8044 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
8045 val |= PIPECONF_COLOR_RANGE_SELECT;
8047 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
8048 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
8050 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
8052 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
8054 intel_de_write(dev_priv, PIPECONF(pipe), val);
8055 intel_de_posting_read(dev_priv, PIPECONF(pipe));
8058 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
8060 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8061 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8062 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
8065 if (IS_HASWELL(dev_priv) && crtc_state->dither)
8066 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8068 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
8069 val |= PIPECONF_INTERLACED_ILK;
8071 val |= PIPECONF_PROGRESSIVE;
8073 if (IS_HASWELL(dev_priv) &&
8074 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
8075 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
8077 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
8078 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
8081 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
8083 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8084 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8087 switch (crtc_state->pipe_bpp) {
8089 val |= PIPEMISC_DITHER_6_BPC;
8092 val |= PIPEMISC_DITHER_8_BPC;
8095 val |= PIPEMISC_DITHER_10_BPC;
8098 val |= PIPEMISC_DITHER_12_BPC;
8101 MISSING_CASE(crtc_state->pipe_bpp);
8105 if (crtc_state->dither)
8106 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8108 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8109 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
8110 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
8112 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
8113 val |= PIPEMISC_YUV420_ENABLE |
8114 PIPEMISC_YUV420_MODE_FULL_BLEND;
8116 if (INTEL_GEN(dev_priv) >= 11 &&
8117 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
8118 BIT(PLANE_CURSOR))) == 0)
8119 val |= PIPEMISC_HDR_MODE_PRECISION;
8121 if (INTEL_GEN(dev_priv) >= 12)
8122 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
8124 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
8127 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
8129 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8132 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
8134 switch (tmp & PIPEMISC_DITHER_BPC_MASK) {
8135 case PIPEMISC_DITHER_6_BPC:
8137 case PIPEMISC_DITHER_8_BPC:
8139 case PIPEMISC_DITHER_10_BPC:
8141 case PIPEMISC_DITHER_12_BPC:
8149 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
8152 * Account for spread spectrum to avoid
8153 * oversubscribing the link. Max center spread
8154 * is 2.5%; use 5% for safety's sake.
8156 u32 bps = target_clock * bpp * 21 / 20;
8157 return DIV_ROUND_UP(bps, link_bw * 8);
8160 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8161 struct intel_link_m_n *m_n)
8163 struct drm_device *dev = crtc->base.dev;
8164 struct drm_i915_private *dev_priv = to_i915(dev);
8165 enum pipe pipe = crtc->pipe;
8167 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
8168 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
8169 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
8171 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
8172 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
8173 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8176 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8177 enum transcoder transcoder,
8178 struct intel_link_m_n *m_n,
8179 struct intel_link_m_n *m2_n2)
8181 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8182 enum pipe pipe = crtc->pipe;
8184 if (INTEL_GEN(dev_priv) >= 5) {
8185 m_n->link_m = intel_de_read(dev_priv,
8186 PIPE_LINK_M1(transcoder));
8187 m_n->link_n = intel_de_read(dev_priv,
8188 PIPE_LINK_N1(transcoder));
8189 m_n->gmch_m = intel_de_read(dev_priv,
8190 PIPE_DATA_M1(transcoder))
8192 m_n->gmch_n = intel_de_read(dev_priv,
8193 PIPE_DATA_N1(transcoder));
8194 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
8195 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8197 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
8198 m2_n2->link_m = intel_de_read(dev_priv,
8199 PIPE_LINK_M2(transcoder));
8200 m2_n2->link_n = intel_de_read(dev_priv,
8201 PIPE_LINK_N2(transcoder));
8202 m2_n2->gmch_m = intel_de_read(dev_priv,
8203 PIPE_DATA_M2(transcoder))
8205 m2_n2->gmch_n = intel_de_read(dev_priv,
8206 PIPE_DATA_N2(transcoder));
8207 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
8208 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8211 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
8212 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
8213 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
8215 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
8216 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
8217 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8221 void intel_dp_get_m_n(struct intel_crtc *crtc,
8222 struct intel_crtc_state *pipe_config)
8224 if (pipe_config->has_pch_encoder)
8225 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8227 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8228 &pipe_config->dp_m_n,
8229 &pipe_config->dp_m2_n2);
8232 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
8233 struct intel_crtc_state *pipe_config)
8235 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
8236 &pipe_config->fdi_m_n, NULL);
8239 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
8242 drm_rect_init(&crtc_state->pch_pfit.dst,
8243 pos >> 16, pos & 0xffff,
8244 size >> 16, size & 0xffff);
8247 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
8249 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8250 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8251 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
8255 /* find scaler attached to this pipe */
8256 for (i = 0; i < crtc->num_scalers; i++) {
8259 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
8260 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
8264 crtc_state->pch_pfit.enabled = true;
8266 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
8267 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
8269 ilk_get_pfit_pos_size(crtc_state, pos, size);
8271 scaler_state->scalers[i].in_use = true;
8275 scaler_state->scaler_id = id;
8277 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8279 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
8283 skl_get_initial_plane_config(struct intel_crtc *crtc,
8284 struct intel_initial_plane_config *plane_config)
8286 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
8287 struct drm_device *dev = crtc->base.dev;
8288 struct drm_i915_private *dev_priv = to_i915(dev);
8289 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8290 enum plane_id plane_id = plane->id;
8292 u32 val, base, offset, stride_mult, tiling, alpha;
8293 int fourcc, pixel_format;
8294 unsigned int aligned_height;
8295 struct drm_framebuffer *fb;
8296 struct intel_framebuffer *intel_fb;
8298 if (!plane->get_hw_state(plane, &pipe))
8301 drm_WARN_ON(dev, pipe != crtc->pipe);
8303 if (crtc_state->bigjoiner) {
8304 drm_dbg_kms(&dev_priv->drm,
8305 "Unsupported bigjoiner configuration for initial FB\n");
8309 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
8311 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
8315 fb = &intel_fb->base;
8319 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
8321 if (INTEL_GEN(dev_priv) >= 11)
8322 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8324 pixel_format = val & PLANE_CTL_FORMAT_MASK;
8326 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
8327 alpha = intel_de_read(dev_priv,
8328 PLANE_COLOR_CTL(pipe, plane_id));
8329 alpha &= PLANE_COLOR_ALPHA_MASK;
8331 alpha = val & PLANE_CTL_ALPHA_MASK;
8334 fourcc = skl_format_to_fourcc(pixel_format,
8335 val & PLANE_CTL_ORDER_RGBX, alpha);
8336 fb->format = drm_format_info(fourcc);
8338 tiling = val & PLANE_CTL_TILED_MASK;
8340 case PLANE_CTL_TILED_LINEAR:
8341 fb->modifier = DRM_FORMAT_MOD_LINEAR;
8343 case PLANE_CTL_TILED_X:
8344 plane_config->tiling = I915_TILING_X;
8345 fb->modifier = I915_FORMAT_MOD_X_TILED;
8347 case PLANE_CTL_TILED_Y:
8348 plane_config->tiling = I915_TILING_Y;
8349 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8350 fb->modifier = INTEL_GEN(dev_priv) >= 12 ?
8351 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
8352 I915_FORMAT_MOD_Y_TILED_CCS;
8353 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
8354 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
8356 fb->modifier = I915_FORMAT_MOD_Y_TILED;
8358 case PLANE_CTL_TILED_YF:
8359 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
8360 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8362 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
8365 MISSING_CASE(tiling);
8370 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
8371 * while i915 HW rotation is clockwise, thats why this swapping.
8373 switch (val & PLANE_CTL_ROTATE_MASK) {
8374 case PLANE_CTL_ROTATE_0:
8375 plane_config->rotation = DRM_MODE_ROTATE_0;
8377 case PLANE_CTL_ROTATE_90:
8378 plane_config->rotation = DRM_MODE_ROTATE_270;
8380 case PLANE_CTL_ROTATE_180:
8381 plane_config->rotation = DRM_MODE_ROTATE_180;
8383 case PLANE_CTL_ROTATE_270:
8384 plane_config->rotation = DRM_MODE_ROTATE_90;
8388 if (INTEL_GEN(dev_priv) >= 10 &&
8389 val & PLANE_CTL_FLIP_HORIZONTAL)
8390 plane_config->rotation |= DRM_MODE_REFLECT_X;
8392 /* 90/270 degree rotation would require extra work */
8393 if (drm_rotation_90_or_270(plane_config->rotation))
8396 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & 0xfffff000;
8397 plane_config->base = base;
8399 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
8401 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
8402 fb->height = ((val >> 16) & 0xffff) + 1;
8403 fb->width = ((val >> 0) & 0xffff) + 1;
8405 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
8406 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
8407 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8409 aligned_height = intel_fb_align_height(fb, 0, fb->height);
8411 plane_config->size = fb->pitches[0] * aligned_height;
8413 drm_dbg_kms(&dev_priv->drm,
8414 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8415 crtc->base.name, plane->base.name, fb->width, fb->height,
8416 fb->format->cpp[0] * 8, base, fb->pitches[0],
8417 plane_config->size);
8419 plane_config->fb = intel_fb;
8426 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
8428 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8429 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8432 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
8433 if ((ctl & PF_ENABLE) == 0)
8436 crtc_state->pch_pfit.enabled = true;
8438 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
8439 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
8441 ilk_get_pfit_pos_size(crtc_state, pos, size);
8444 * We currently do not free assignements of panel fitters on
8445 * ivb/hsw (since we don't use the higher upscaling modes which
8446 * differentiates them) so just WARN about this case for now.
8448 drm_WARN_ON(&dev_priv->drm, IS_GEN(dev_priv, 7) &&
8449 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
8452 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
8453 struct intel_crtc_state *pipe_config)
8455 struct drm_device *dev = crtc->base.dev;
8456 struct drm_i915_private *dev_priv = to_i915(dev);
8457 enum intel_display_power_domain power_domain;
8458 intel_wakeref_t wakeref;
8462 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
8463 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8467 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8468 pipe_config->shared_dpll = NULL;
8471 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
8472 if (!(tmp & PIPECONF_ENABLE))
8475 switch (tmp & PIPECONF_BPC_MASK) {
8477 pipe_config->pipe_bpp = 18;
8480 pipe_config->pipe_bpp = 24;
8482 case PIPECONF_10BPC:
8483 pipe_config->pipe_bpp = 30;
8485 case PIPECONF_12BPC:
8486 pipe_config->pipe_bpp = 36;
8492 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
8493 pipe_config->limited_color_range = true;
8495 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
8496 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
8497 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
8498 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
8501 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
8505 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
8506 PIPECONF_GAMMA_MODE_SHIFT;
8508 pipe_config->csc_mode = intel_de_read(dev_priv,
8509 PIPE_CSC_MODE(crtc->pipe));
8511 i9xx_get_pipe_color_config(pipe_config);
8512 intel_color_get_config(pipe_config);
8514 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
8515 struct intel_shared_dpll *pll;
8516 enum intel_dpll_id pll_id;
8519 pipe_config->has_pch_encoder = true;
8521 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
8522 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8523 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8525 ilk_get_fdi_m_n_config(crtc, pipe_config);
8527 if (HAS_PCH_IBX(dev_priv)) {
8529 * The pipe->pch transcoder and pch transcoder->pll
8532 pll_id = (enum intel_dpll_id) crtc->pipe;
8534 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
8535 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
8536 pll_id = DPLL_ID_PCH_PLL_B;
8538 pll_id= DPLL_ID_PCH_PLL_A;
8541 pipe_config->shared_dpll =
8542 intel_get_shared_dpll_by_id(dev_priv, pll_id);
8543 pll = pipe_config->shared_dpll;
8545 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8546 &pipe_config->dpll_hw_state);
8547 drm_WARN_ON(dev, !pll_active);
8549 tmp = pipe_config->dpll_hw_state.dpll;
8550 pipe_config->pixel_multiplier =
8551 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
8552 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
8554 ilk_pch_clock_get(crtc, pipe_config);
8556 pipe_config->pixel_multiplier = 1;
8559 intel_get_transcoder_timings(crtc, pipe_config);
8560 intel_get_pipe_src_size(crtc, pipe_config);
8562 ilk_get_pfit_config(pipe_config);
8567 intel_display_power_put(dev_priv, power_domain, wakeref);
8572 static void dg1_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
8573 struct intel_crtc_state *pipe_config)
8575 enum icl_port_dpll_id port_dpll_id = ICL_PORT_DPLL_DEFAULT;
8576 enum phy phy = intel_port_to_phy(dev_priv, port);
8577 struct icl_port_dpll *port_dpll;
8578 struct intel_shared_dpll *pll;
8579 enum intel_dpll_id id;
8583 clk_sel = intel_de_read(dev_priv, DG1_DPCLKA_CFGCR0(phy)) & DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
8584 id = DG1_DPCLKA_CFGCR0_DDI_CLK_SEL_DPLL_MAP(clk_sel, phy);
8586 if (WARN_ON(id > DPLL_ID_DG1_DPLL3))
8589 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8590 port_dpll = &pipe_config->icl_port_dplls[port_dpll_id];
8592 port_dpll->pll = pll;
8593 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8594 &port_dpll->hw_state);
8595 drm_WARN_ON(&dev_priv->drm, !pll_active);
8597 icl_set_active_port_dpll(pipe_config, port_dpll_id);
8600 static void icl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
8601 struct intel_crtc_state *pipe_config)
8603 enum phy phy = intel_port_to_phy(dev_priv, port);
8604 enum icl_port_dpll_id port_dpll_id;
8605 struct icl_port_dpll *port_dpll;
8606 struct intel_shared_dpll *pll;
8607 enum intel_dpll_id id;
8612 if (intel_phy_is_combo(dev_priv, phy)) {
8615 if (IS_ALDERLAKE_S(dev_priv)) {
8616 reg = ADLS_DPCLKA_CFGCR(phy);
8617 mask = ADLS_DPCLKA_CFGCR_DDI_CLK_SEL_MASK(phy);
8618 shift = ADLS_DPCLKA_CFGCR_DDI_SHIFT(phy);
8619 } else if (IS_ROCKETLAKE(dev_priv)) {
8620 reg = ICL_DPCLKA_CFGCR0;
8621 mask = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
8622 shift = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
8624 reg = ICL_DPCLKA_CFGCR0;
8625 mask = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy);
8626 shift = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(phy);
8629 temp = intel_de_read(dev_priv, reg) & mask;
8631 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
8632 } else if (intel_phy_is_tc(dev_priv, phy)) {
8633 u32 clk_sel = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK;
8635 if (clk_sel == DDI_CLK_SEL_MG) {
8636 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv,
8638 port_dpll_id = ICL_PORT_DPLL_MG_PHY;
8640 drm_WARN_ON(&dev_priv->drm,
8641 clk_sel < DDI_CLK_SEL_TBT_162);
8642 id = DPLL_ID_ICL_TBTPLL;
8643 port_dpll_id = ICL_PORT_DPLL_DEFAULT;
8646 drm_WARN(&dev_priv->drm, 1, "Invalid port %x\n", port);
8650 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8651 port_dpll = &pipe_config->icl_port_dplls[port_dpll_id];
8653 port_dpll->pll = pll;
8654 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8655 &port_dpll->hw_state);
8656 drm_WARN_ON(&dev_priv->drm, !pll_active);
8658 icl_set_active_port_dpll(pipe_config, port_dpll_id);
8661 static void cnl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
8662 struct intel_crtc_state *pipe_config)
8664 struct intel_shared_dpll *pll;
8665 enum intel_dpll_id id;
8669 temp = intel_de_read(dev_priv, DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
8670 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
8672 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL2))
8675 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8677 pipe_config->shared_dpll = pll;
8678 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8679 &pipe_config->dpll_hw_state);
8680 drm_WARN_ON(&dev_priv->drm, !pll_active);
8683 static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
8685 struct intel_crtc_state *pipe_config)
8687 struct intel_shared_dpll *pll;
8688 enum intel_dpll_id id;
8693 id = DPLL_ID_SKL_DPLL0;
8696 id = DPLL_ID_SKL_DPLL1;
8699 id = DPLL_ID_SKL_DPLL2;
8702 drm_err(&dev_priv->drm, "Incorrect port type\n");
8706 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8708 pipe_config->shared_dpll = pll;
8709 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8710 &pipe_config->dpll_hw_state);
8711 drm_WARN_ON(&dev_priv->drm, !pll_active);
8714 static void skl_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
8715 struct intel_crtc_state *pipe_config)
8717 struct intel_shared_dpll *pll;
8718 enum intel_dpll_id id;
8722 temp = intel_de_read(dev_priv, DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
8723 id = temp >> (port * 3 + 1);
8725 if (drm_WARN_ON(&dev_priv->drm, id < SKL_DPLL0 || id > SKL_DPLL3))
8728 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8730 pipe_config->shared_dpll = pll;
8731 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8732 &pipe_config->dpll_hw_state);
8733 drm_WARN_ON(&dev_priv->drm, !pll_active);
8736 static void hsw_get_ddi_pll(struct drm_i915_private *dev_priv, enum port port,
8737 struct intel_crtc_state *pipe_config)
8739 struct intel_shared_dpll *pll;
8740 enum intel_dpll_id id;
8741 u32 ddi_pll_sel = intel_de_read(dev_priv, PORT_CLK_SEL(port));
8744 switch (ddi_pll_sel) {
8745 case PORT_CLK_SEL_WRPLL1:
8746 id = DPLL_ID_WRPLL1;
8748 case PORT_CLK_SEL_WRPLL2:
8749 id = DPLL_ID_WRPLL2;
8751 case PORT_CLK_SEL_SPLL:
8754 case PORT_CLK_SEL_LCPLL_810:
8755 id = DPLL_ID_LCPLL_810;
8757 case PORT_CLK_SEL_LCPLL_1350:
8758 id = DPLL_ID_LCPLL_1350;
8760 case PORT_CLK_SEL_LCPLL_2700:
8761 id = DPLL_ID_LCPLL_2700;
8764 MISSING_CASE(ddi_pll_sel);
8766 case PORT_CLK_SEL_NONE:
8770 pll = intel_get_shared_dpll_by_id(dev_priv, id);
8772 pipe_config->shared_dpll = pll;
8773 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
8774 &pipe_config->dpll_hw_state);
8775 drm_WARN_ON(&dev_priv->drm, !pll_active);
8778 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
8779 struct intel_crtc_state *pipe_config,
8780 struct intel_display_power_domain_set *power_domain_set)
8782 struct drm_device *dev = crtc->base.dev;
8783 struct drm_i915_private *dev_priv = to_i915(dev);
8784 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
8785 unsigned long enabled_panel_transcoders = 0;
8786 enum transcoder panel_transcoder;
8789 if (INTEL_GEN(dev_priv) >= 11)
8790 panel_transcoder_mask |=
8791 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
8794 * The pipe->transcoder mapping is fixed with the exception of the eDP
8795 * and DSI transcoders handled below.
8797 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
8800 * XXX: Do intel_display_power_get_if_enabled before reading this (for
8801 * consistency and less surprising code; it's in always on power).
8803 for_each_cpu_transcoder_masked(dev_priv, panel_transcoder,
8804 panel_transcoder_mask) {
8805 bool force_thru = false;
8806 enum pipe trans_pipe;
8808 tmp = intel_de_read(dev_priv,
8809 TRANS_DDI_FUNC_CTL(panel_transcoder));
8810 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
8814 * Log all enabled ones, only use the first one.
8816 * FIXME: This won't work for two separate DSI displays.
8818 enabled_panel_transcoders |= BIT(panel_transcoder);
8819 if (enabled_panel_transcoders != BIT(panel_transcoder))
8822 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
8825 "unknown pipe linked to transcoder %s\n",
8826 transcoder_name(panel_transcoder));
8828 case TRANS_DDI_EDP_INPUT_A_ONOFF:
8831 case TRANS_DDI_EDP_INPUT_A_ON:
8832 trans_pipe = PIPE_A;
8834 case TRANS_DDI_EDP_INPUT_B_ONOFF:
8835 trans_pipe = PIPE_B;
8837 case TRANS_DDI_EDP_INPUT_C_ONOFF:
8838 trans_pipe = PIPE_C;
8840 case TRANS_DDI_EDP_INPUT_D_ONOFF:
8841 trans_pipe = PIPE_D;
8845 if (trans_pipe == crtc->pipe) {
8846 pipe_config->cpu_transcoder = panel_transcoder;
8847 pipe_config->pch_pfit.force_thru = force_thru;
8852 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
8854 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
8855 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
8857 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
8858 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
8861 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
8863 return tmp & PIPECONF_ENABLE;
8866 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
8867 struct intel_crtc_state *pipe_config,
8868 struct intel_display_power_domain_set *power_domain_set)
8870 struct drm_device *dev = crtc->base.dev;
8871 struct drm_i915_private *dev_priv = to_i915(dev);
8872 enum transcoder cpu_transcoder;
8876 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
8878 cpu_transcoder = TRANSCODER_DSI_A;
8880 cpu_transcoder = TRANSCODER_DSI_C;
8882 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
8883 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
8887 * The PLL needs to be enabled with a valid divider
8888 * configuration, otherwise accessing DSI registers will hang
8889 * the machine. See BSpec North Display Engine
8890 * registers/MIPI[BXT]. We can break out here early, since we
8891 * need the same DSI PLL to be enabled for both DSI ports.
8893 if (!bxt_dsi_pll_is_enabled(dev_priv))
8896 /* XXX: this works for video mode only */
8897 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
8898 if (!(tmp & DPI_ENABLE))
8901 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
8902 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
8905 pipe_config->cpu_transcoder = cpu_transcoder;
8909 return transcoder_is_dsi(pipe_config->cpu_transcoder);
8912 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
8913 struct intel_crtc_state *pipe_config)
8915 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8916 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
8920 if (transcoder_is_dsi(cpu_transcoder)) {
8921 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
8924 tmp = intel_de_read(dev_priv,
8925 TRANS_DDI_FUNC_CTL(cpu_transcoder));
8926 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
8928 if (INTEL_GEN(dev_priv) >= 12)
8929 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
8931 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
8934 if (IS_DG1(dev_priv))
8935 dg1_get_ddi_pll(dev_priv, port, pipe_config);
8936 else if (INTEL_GEN(dev_priv) >= 11)
8937 icl_get_ddi_pll(dev_priv, port, pipe_config);
8938 else if (IS_CANNONLAKE(dev_priv))
8939 cnl_get_ddi_pll(dev_priv, port, pipe_config);
8940 else if (IS_GEN9_LP(dev_priv))
8941 bxt_get_ddi_pll(dev_priv, port, pipe_config);
8942 else if (IS_GEN9_BC(dev_priv))
8943 skl_get_ddi_pll(dev_priv, port, pipe_config);
8945 hsw_get_ddi_pll(dev_priv, port, pipe_config);
8948 * Haswell has only FDI/PCH transcoder A. It is which is connected to
8949 * DDI E. So just check whether this pipe is wired to DDI E and whether
8950 * the PCH transcoder is on.
8952 if (INTEL_GEN(dev_priv) < 9 &&
8953 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
8954 pipe_config->has_pch_encoder = true;
8956 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
8957 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
8958 FDI_DP_PORT_WIDTH_SHIFT) + 1;
8960 ilk_get_fdi_m_n_config(crtc, pipe_config);
8964 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
8965 struct intel_crtc_state *pipe_config)
8967 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8968 struct intel_display_power_domain_set power_domain_set = { };
8972 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
8973 POWER_DOMAIN_PIPE(crtc->pipe)))
8976 pipe_config->shared_dpll = NULL;
8978 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
8980 if (IS_GEN9_LP(dev_priv) &&
8981 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
8982 drm_WARN_ON(&dev_priv->drm, active);
8986 intel_dsc_get_config(pipe_config);
8989 /* bigjoiner slave doesn't enable transcoder */
8990 if (!pipe_config->bigjoiner_slave)
8994 pipe_config->pixel_multiplier = 1;
8996 /* we cannot read out most state, so don't bother.. */
8997 pipe_config->quirks |= PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE;
8998 } else if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
8999 INTEL_GEN(dev_priv) >= 11) {
9000 hsw_get_ddi_port_state(crtc, pipe_config);
9001 intel_get_transcoder_timings(crtc, pipe_config);
9004 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
9005 intel_vrr_get_config(crtc, pipe_config);
9007 intel_get_pipe_src_size(crtc, pipe_config);
9009 if (IS_HASWELL(dev_priv)) {
9010 u32 tmp = intel_de_read(dev_priv,
9011 PIPECONF(pipe_config->cpu_transcoder));
9013 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
9014 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
9016 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
9018 pipe_config->output_format =
9019 bdw_get_pipemisc_output_format(crtc);
9022 pipe_config->gamma_mode = intel_de_read(dev_priv,
9023 GAMMA_MODE(crtc->pipe));
9025 pipe_config->csc_mode = intel_de_read(dev_priv,
9026 PIPE_CSC_MODE(crtc->pipe));
9028 if (INTEL_GEN(dev_priv) >= 9) {
9029 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
9031 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
9032 pipe_config->gamma_enable = true;
9034 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
9035 pipe_config->csc_enable = true;
9037 i9xx_get_pipe_color_config(pipe_config);
9040 intel_color_get_config(pipe_config);
9042 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
9043 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
9044 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
9045 pipe_config->ips_linetime =
9046 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
9048 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
9049 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
9050 if (INTEL_GEN(dev_priv) >= 9)
9051 skl_get_pfit_config(pipe_config);
9053 ilk_get_pfit_config(pipe_config);
9056 if (hsw_crtc_supports_ips(crtc)) {
9057 if (IS_HASWELL(dev_priv))
9058 pipe_config->ips_enabled = intel_de_read(dev_priv,
9059 IPS_CTL) & IPS_ENABLE;
9062 * We cannot readout IPS state on broadwell, set to
9063 * true so we can set it to a defined state on first
9066 pipe_config->ips_enabled = true;
9070 if (pipe_config->bigjoiner_slave) {
9071 /* Cannot be read out as a slave, set to 0. */
9072 pipe_config->pixel_multiplier = 0;
9073 } else if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9074 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
9075 pipe_config->pixel_multiplier =
9076 intel_de_read(dev_priv,
9077 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9079 pipe_config->pixel_multiplier = 1;
9083 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
9088 static bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
9090 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9091 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
9093 if (!i915->display.get_pipe_config(crtc, crtc_state))
9096 crtc_state->hw.active = true;
9098 intel_crtc_readout_derived_state(crtc_state);
9103 /* VESA 640x480x72Hz mode to set on the pipe */
9104 static const struct drm_display_mode load_detect_mode = {
9105 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
9106 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
9109 struct drm_framebuffer *
9110 intel_framebuffer_create(struct drm_i915_gem_object *obj,
9111 struct drm_mode_fb_cmd2 *mode_cmd)
9113 struct intel_framebuffer *intel_fb;
9116 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
9118 return ERR_PTR(-ENOMEM);
9120 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
9124 return &intel_fb->base;
9128 return ERR_PTR(ret);
9131 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
9132 struct drm_crtc *crtc)
9134 struct drm_plane *plane;
9135 struct drm_plane_state *plane_state;
9138 ret = drm_atomic_add_affected_planes(state, crtc);
9142 for_each_new_plane_in_state(state, plane, plane_state, i) {
9143 if (plane_state->crtc != crtc)
9146 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
9150 drm_atomic_set_fb_for_plane(plane_state, NULL);
9156 int intel_get_load_detect_pipe(struct drm_connector *connector,
9157 struct intel_load_detect_pipe *old,
9158 struct drm_modeset_acquire_ctx *ctx)
9160 struct intel_crtc *intel_crtc;
9161 struct intel_encoder *intel_encoder =
9162 intel_attached_encoder(to_intel_connector(connector));
9163 struct drm_crtc *possible_crtc;
9164 struct drm_encoder *encoder = &intel_encoder->base;
9165 struct drm_crtc *crtc = NULL;
9166 struct drm_device *dev = encoder->dev;
9167 struct drm_i915_private *dev_priv = to_i915(dev);
9168 struct drm_mode_config *config = &dev->mode_config;
9169 struct drm_atomic_state *state = NULL, *restore_state = NULL;
9170 struct drm_connector_state *connector_state;
9171 struct intel_crtc_state *crtc_state;
9174 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9175 connector->base.id, connector->name,
9176 encoder->base.id, encoder->name);
9178 old->restore_state = NULL;
9180 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
9183 * Algorithm gets a little messy:
9185 * - if the connector already has an assigned crtc, use it (but make
9186 * sure it's on first)
9188 * - try to find the first unused crtc that can drive this connector,
9189 * and use that if we find one
9192 /* See if we already have a CRTC for this connector */
9193 if (connector->state->crtc) {
9194 crtc = connector->state->crtc;
9196 ret = drm_modeset_lock(&crtc->mutex, ctx);
9200 /* Make sure the crtc and connector are running */
9204 /* Find an unused one (if possible) */
9205 for_each_crtc(dev, possible_crtc) {
9207 if (!(encoder->possible_crtcs & (1 << i)))
9210 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
9214 if (possible_crtc->state->enable) {
9215 drm_modeset_unlock(&possible_crtc->mutex);
9219 crtc = possible_crtc;
9224 * If we didn't find an unused CRTC, don't use any.
9227 drm_dbg_kms(&dev_priv->drm,
9228 "no pipe available for load-detect\n");
9234 intel_crtc = to_intel_crtc(crtc);
9236 state = drm_atomic_state_alloc(dev);
9237 restore_state = drm_atomic_state_alloc(dev);
9238 if (!state || !restore_state) {
9243 state->acquire_ctx = ctx;
9244 restore_state->acquire_ctx = ctx;
9246 connector_state = drm_atomic_get_connector_state(state, connector);
9247 if (IS_ERR(connector_state)) {
9248 ret = PTR_ERR(connector_state);
9252 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
9256 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
9257 if (IS_ERR(crtc_state)) {
9258 ret = PTR_ERR(crtc_state);
9262 crtc_state->uapi.active = true;
9264 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
9269 ret = intel_modeset_disable_planes(state, crtc);
9273 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
9275 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
9277 ret = drm_atomic_add_affected_planes(restore_state, crtc);
9279 drm_dbg_kms(&dev_priv->drm,
9280 "Failed to create a copy of old state to restore: %i\n",
9285 ret = drm_atomic_commit(state);
9287 drm_dbg_kms(&dev_priv->drm,
9288 "failed to set mode on load-detect pipe\n");
9292 old->restore_state = restore_state;
9293 drm_atomic_state_put(state);
9295 /* let the connector get through one full cycle before testing */
9296 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
9301 drm_atomic_state_put(state);
9304 if (restore_state) {
9305 drm_atomic_state_put(restore_state);
9306 restore_state = NULL;
9309 if (ret == -EDEADLK)
9315 void intel_release_load_detect_pipe(struct drm_connector *connector,
9316 struct intel_load_detect_pipe *old,
9317 struct drm_modeset_acquire_ctx *ctx)
9319 struct intel_encoder *intel_encoder =
9320 intel_attached_encoder(to_intel_connector(connector));
9321 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
9322 struct drm_encoder *encoder = &intel_encoder->base;
9323 struct drm_atomic_state *state = old->restore_state;
9326 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9327 connector->base.id, connector->name,
9328 encoder->base.id, encoder->name);
9333 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
9335 drm_dbg_kms(&i915->drm,
9336 "Couldn't release load detect pipe: %i\n", ret);
9337 drm_atomic_state_put(state);
9340 static int i9xx_pll_refclk(struct drm_device *dev,
9341 const struct intel_crtc_state *pipe_config)
9343 struct drm_i915_private *dev_priv = to_i915(dev);
9344 u32 dpll = pipe_config->dpll_hw_state.dpll;
9346 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
9347 return dev_priv->vbt.lvds_ssc_freq;
9348 else if (HAS_PCH_SPLIT(dev_priv))
9350 else if (!IS_GEN(dev_priv, 2))
9356 /* Returns the clock of the currently programmed mode of the given pipe. */
9357 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
9358 struct intel_crtc_state *pipe_config)
9360 struct drm_device *dev = crtc->base.dev;
9361 struct drm_i915_private *dev_priv = to_i915(dev);
9362 enum pipe pipe = crtc->pipe;
9363 u32 dpll = pipe_config->dpll_hw_state.dpll;
9367 int refclk = i9xx_pll_refclk(dev, pipe_config);
9369 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
9370 fp = pipe_config->dpll_hw_state.fp0;
9372 fp = pipe_config->dpll_hw_state.fp1;
9374 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
9375 if (IS_PINEVIEW(dev_priv)) {
9376 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
9377 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
9379 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
9380 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
9383 if (!IS_GEN(dev_priv, 2)) {
9384 if (IS_PINEVIEW(dev_priv))
9385 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
9386 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
9388 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
9389 DPLL_FPA01_P1_POST_DIV_SHIFT);
9391 switch (dpll & DPLL_MODE_MASK) {
9392 case DPLLB_MODE_DAC_SERIAL:
9393 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
9396 case DPLLB_MODE_LVDS:
9397 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
9401 drm_dbg_kms(&dev_priv->drm,
9402 "Unknown DPLL mode %08x in programmed "
9403 "mode\n", (int)(dpll & DPLL_MODE_MASK));
9407 if (IS_PINEVIEW(dev_priv))
9408 port_clock = pnv_calc_dpll_params(refclk, &clock);
9410 port_clock = i9xx_calc_dpll_params(refclk, &clock);
9412 u32 lvds = IS_I830(dev_priv) ? 0 : intel_de_read(dev_priv,
9414 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
9417 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
9418 DPLL_FPA01_P1_POST_DIV_SHIFT);
9420 if (lvds & LVDS_CLKB_POWER_UP)
9425 if (dpll & PLL_P1_DIVIDE_BY_TWO)
9428 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
9429 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
9431 if (dpll & PLL_P2_DIVIDE_BY_4)
9437 port_clock = i9xx_calc_dpll_params(refclk, &clock);
9441 * This value includes pixel_multiplier. We will use
9442 * port_clock to compute adjusted_mode.crtc_clock in the
9443 * encoder's get_config() function.
9445 pipe_config->port_clock = port_clock;
9448 int intel_dotclock_calculate(int link_freq,
9449 const struct intel_link_m_n *m_n)
9452 * The calculation for the data clock is:
9453 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
9454 * But we want to avoid losing precison if possible, so:
9455 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
9457 * and the link clock is simpler:
9458 * link_clock = (m * link_clock) / n
9464 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
9467 static void ilk_pch_clock_get(struct intel_crtc *crtc,
9468 struct intel_crtc_state *pipe_config)
9470 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9472 /* read out port_clock from the DPLL */
9473 i9xx_crtc_clock_get(crtc, pipe_config);
9476 * In case there is an active pipe without active ports,
9477 * we may need some idea for the dotclock anyway.
9478 * Calculate one based on the FDI configuration.
9480 pipe_config->hw.adjusted_mode.crtc_clock =
9481 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
9482 &pipe_config->fdi_m_n);
9485 /* Returns the currently programmed mode of the given encoder. */
9486 struct drm_display_mode *
9487 intel_encoder_current_mode(struct intel_encoder *encoder)
9489 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
9490 struct intel_crtc_state *crtc_state;
9491 struct drm_display_mode *mode;
9492 struct intel_crtc *crtc;
9495 if (!encoder->get_hw_state(encoder, &pipe))
9498 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
9500 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
9504 crtc_state = intel_crtc_state_alloc(crtc);
9510 if (!intel_crtc_get_pipe_config(crtc_state)) {
9516 intel_encoder_get_config(encoder, crtc_state);
9518 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
9526 * intel_wm_need_update - Check whether watermarks need updating
9527 * @cur: current plane state
9528 * @new: new plane state
9530 * Check current plane state versus the new one to determine whether
9531 * watermarks need to be recalculated.
9533 * Returns true or false.
9535 static bool intel_wm_need_update(const struct intel_plane_state *cur,
9536 struct intel_plane_state *new)
9538 /* Update watermarks on tiling or size changes. */
9539 if (new->uapi.visible != cur->uapi.visible)
9542 if (!cur->hw.fb || !new->hw.fb)
9545 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
9546 cur->hw.rotation != new->hw.rotation ||
9547 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
9548 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
9549 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
9550 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
9556 static bool needs_scaling(const struct intel_plane_state *state)
9558 int src_w = drm_rect_width(&state->uapi.src) >> 16;
9559 int src_h = drm_rect_height(&state->uapi.src) >> 16;
9560 int dst_w = drm_rect_width(&state->uapi.dst);
9561 int dst_h = drm_rect_height(&state->uapi.dst);
9563 return (src_w != dst_w || src_h != dst_h);
9566 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
9567 struct intel_crtc_state *crtc_state,
9568 const struct intel_plane_state *old_plane_state,
9569 struct intel_plane_state *plane_state)
9571 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9572 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
9573 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9574 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
9575 bool was_crtc_enabled = old_crtc_state->hw.active;
9576 bool is_crtc_enabled = crtc_state->hw.active;
9577 bool turn_off, turn_on, visible, was_visible;
9580 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
9581 ret = skl_update_scaler_plane(crtc_state, plane_state);
9586 was_visible = old_plane_state->uapi.visible;
9587 visible = plane_state->uapi.visible;
9589 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
9590 was_visible = false;
9593 * Visibility is calculated as if the crtc was on, but
9594 * after scaler setup everything depends on it being off
9595 * when the crtc isn't active.
9597 * FIXME this is wrong for watermarks. Watermarks should also
9598 * be computed as if the pipe would be active. Perhaps move
9599 * per-plane wm computation to the .check_plane() hook, and
9600 * only combine the results from all planes in the current place?
9602 if (!is_crtc_enabled) {
9603 intel_plane_set_invisible(crtc_state, plane_state);
9607 if (!was_visible && !visible)
9610 turn_off = was_visible && (!visible || mode_changed);
9611 turn_on = visible && (!was_visible || mode_changed);
9613 drm_dbg_atomic(&dev_priv->drm,
9614 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
9615 crtc->base.base.id, crtc->base.name,
9616 plane->base.base.id, plane->base.name,
9617 was_visible, visible,
9618 turn_off, turn_on, mode_changed);
9621 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9622 crtc_state->update_wm_pre = true;
9624 /* must disable cxsr around plane enable/disable */
9625 if (plane->id != PLANE_CURSOR)
9626 crtc_state->disable_cxsr = true;
9627 } else if (turn_off) {
9628 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
9629 crtc_state->update_wm_post = true;
9631 /* must disable cxsr around plane enable/disable */
9632 if (plane->id != PLANE_CURSOR)
9633 crtc_state->disable_cxsr = true;
9634 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
9635 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
9636 /* FIXME bollocks */
9637 crtc_state->update_wm_pre = true;
9638 crtc_state->update_wm_post = true;
9642 if (visible || was_visible)
9643 crtc_state->fb_bits |= plane->frontbuffer_bit;
9646 * ILK/SNB DVSACNTR/Sprite Enable
9647 * IVB SPR_CTL/Sprite Enable
9648 * "When in Self Refresh Big FIFO mode, a write to enable the
9649 * plane will be internally buffered and delayed while Big FIFO
9652 * Which means that enabling the sprite can take an extra frame
9653 * when we start in big FIFO mode (LP1+). Thus we need to drop
9654 * down to LP0 and wait for vblank in order to make sure the
9655 * sprite gets enabled on the next vblank after the register write.
9656 * Doing otherwise would risk enabling the sprite one frame after
9657 * we've already signalled flip completion. We can resume LP1+
9658 * once the sprite has been enabled.
9661 * WaCxSRDisabledForSpriteScaling:ivb
9662 * IVB SPR_SCALE/Scaling Enable
9663 * "Low Power watermarks must be disabled for at least one
9664 * frame before enabling sprite scaling, and kept disabled
9665 * until sprite scaling is disabled."
9667 * ILK/SNB DVSASCALE/Scaling Enable
9668 * "When in Self Refresh Big FIFO mode, scaling enable will be
9669 * masked off while Big FIFO mode is exiting."
9671 * Despite the w/a only being listed for IVB we assume that
9672 * the ILK/SNB note has similar ramifications, hence we apply
9673 * the w/a on all three platforms.
9675 * With experimental results seems this is needed also for primary
9676 * plane, not only sprite plane.
9678 if (plane->id != PLANE_CURSOR &&
9679 (IS_GEN_RANGE(dev_priv, 5, 6) ||
9680 IS_IVYBRIDGE(dev_priv)) &&
9681 (turn_on || (!needs_scaling(old_plane_state) &&
9682 needs_scaling(plane_state))))
9683 crtc_state->disable_lp_wm = true;
9688 static bool encoders_cloneable(const struct intel_encoder *a,
9689 const struct intel_encoder *b)
9691 /* masks could be asymmetric, so check both ways */
9692 return a == b || (a->cloneable & (1 << b->type) &&
9693 b->cloneable & (1 << a->type));
9696 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
9697 struct intel_crtc *crtc,
9698 struct intel_encoder *encoder)
9700 struct intel_encoder *source_encoder;
9701 struct drm_connector *connector;
9702 struct drm_connector_state *connector_state;
9705 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
9706 if (connector_state->crtc != &crtc->base)
9710 to_intel_encoder(connector_state->best_encoder);
9711 if (!encoders_cloneable(encoder, source_encoder))
9718 static int icl_add_linked_planes(struct intel_atomic_state *state)
9720 struct intel_plane *plane, *linked;
9721 struct intel_plane_state *plane_state, *linked_plane_state;
9724 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9725 linked = plane_state->planar_linked_plane;
9730 linked_plane_state = intel_atomic_get_plane_state(state, linked);
9731 if (IS_ERR(linked_plane_state))
9732 return PTR_ERR(linked_plane_state);
9734 drm_WARN_ON(state->base.dev,
9735 linked_plane_state->planar_linked_plane != plane);
9736 drm_WARN_ON(state->base.dev,
9737 linked_plane_state->planar_slave == plane_state->planar_slave);
9743 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
9745 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9746 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9747 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
9748 struct intel_plane *plane, *linked;
9749 struct intel_plane_state *plane_state;
9752 if (INTEL_GEN(dev_priv) < 11)
9756 * Destroy all old plane links and make the slave plane invisible
9757 * in the crtc_state->active_planes mask.
9759 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9760 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
9763 plane_state->planar_linked_plane = NULL;
9764 if (plane_state->planar_slave && !plane_state->uapi.visible) {
9765 crtc_state->enabled_planes &= ~BIT(plane->id);
9766 crtc_state->active_planes &= ~BIT(plane->id);
9767 crtc_state->update_planes |= BIT(plane->id);
9770 plane_state->planar_slave = false;
9773 if (!crtc_state->nv12_planes)
9776 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9777 struct intel_plane_state *linked_state = NULL;
9779 if (plane->pipe != crtc->pipe ||
9780 !(crtc_state->nv12_planes & BIT(plane->id)))
9783 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
9784 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
9787 if (crtc_state->active_planes & BIT(linked->id))
9790 linked_state = intel_atomic_get_plane_state(state, linked);
9791 if (IS_ERR(linked_state))
9792 return PTR_ERR(linked_state);
9797 if (!linked_state) {
9798 drm_dbg_kms(&dev_priv->drm,
9799 "Need %d free Y planes for planar YUV\n",
9800 hweight8(crtc_state->nv12_planes));
9805 plane_state->planar_linked_plane = linked;
9807 linked_state->planar_slave = true;
9808 linked_state->planar_linked_plane = plane;
9809 crtc_state->enabled_planes |= BIT(linked->id);
9810 crtc_state->active_planes |= BIT(linked->id);
9811 crtc_state->update_planes |= BIT(linked->id);
9812 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
9813 linked->base.name, plane->base.name);
9815 /* Copy parameters to slave plane */
9816 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
9817 linked_state->color_ctl = plane_state->color_ctl;
9818 linked_state->view = plane_state->view;
9819 memcpy(linked_state->color_plane, plane_state->color_plane,
9820 sizeof(linked_state->color_plane));
9822 intel_plane_copy_hw_state(linked_state, plane_state);
9823 linked_state->uapi.src = plane_state->uapi.src;
9824 linked_state->uapi.dst = plane_state->uapi.dst;
9826 if (icl_is_hdr_plane(dev_priv, plane->id)) {
9827 if (linked->id == PLANE_SPRITE5)
9828 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
9829 else if (linked->id == PLANE_SPRITE4)
9830 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
9831 else if (linked->id == PLANE_SPRITE3)
9832 plane_state->cus_ctl |= PLANE_CUS_PLANE_5_RKL;
9833 else if (linked->id == PLANE_SPRITE2)
9834 plane_state->cus_ctl |= PLANE_CUS_PLANE_4_RKL;
9836 MISSING_CASE(linked->id);
9843 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
9845 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
9846 struct intel_atomic_state *state =
9847 to_intel_atomic_state(new_crtc_state->uapi.state);
9848 const struct intel_crtc_state *old_crtc_state =
9849 intel_atomic_get_old_crtc_state(state, crtc);
9851 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
9854 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
9856 const struct drm_display_mode *pipe_mode =
9857 &crtc_state->hw.pipe_mode;
9860 if (!crtc_state->hw.enable)
9863 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
9864 pipe_mode->crtc_clock);
9866 return min(linetime_wm, 0x1ff);
9869 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
9870 const struct intel_cdclk_state *cdclk_state)
9872 const struct drm_display_mode *pipe_mode =
9873 &crtc_state->hw.pipe_mode;
9876 if (!crtc_state->hw.enable)
9879 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
9880 cdclk_state->logical.cdclk);
9882 return min(linetime_wm, 0x1ff);
9885 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
9887 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9888 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9889 const struct drm_display_mode *pipe_mode =
9890 &crtc_state->hw.pipe_mode;
9893 if (!crtc_state->hw.enable)
9896 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
9897 crtc_state->pixel_rate);
9899 /* Display WA #1135: BXT:ALL GLK:ALL */
9900 if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled)
9903 return min(linetime_wm, 0x1ff);
9906 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
9907 struct intel_crtc *crtc)
9909 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9910 struct intel_crtc_state *crtc_state =
9911 intel_atomic_get_new_crtc_state(state, crtc);
9912 const struct intel_cdclk_state *cdclk_state;
9914 if (INTEL_GEN(dev_priv) >= 9)
9915 crtc_state->linetime = skl_linetime_wm(crtc_state);
9917 crtc_state->linetime = hsw_linetime_wm(crtc_state);
9919 if (!hsw_crtc_supports_ips(crtc))
9922 cdclk_state = intel_atomic_get_cdclk_state(state);
9923 if (IS_ERR(cdclk_state))
9924 return PTR_ERR(cdclk_state);
9926 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
9932 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
9933 struct intel_crtc *crtc)
9935 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9936 struct intel_crtc_state *crtc_state =
9937 intel_atomic_get_new_crtc_state(state, crtc);
9938 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
9941 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
9942 mode_changed && !crtc_state->hw.active)
9943 crtc_state->update_wm_post = true;
9945 if (mode_changed && crtc_state->hw.enable &&
9946 dev_priv->display.crtc_compute_clock &&
9947 !crtc_state->bigjoiner_slave &&
9948 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
9949 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
9955 * May need to update pipe gamma enable bits
9956 * when C8 planes are getting enabled/disabled.
9958 if (c8_planes_changed(crtc_state))
9959 crtc_state->uapi.color_mgmt_changed = true;
9961 if (mode_changed || crtc_state->update_pipe ||
9962 crtc_state->uapi.color_mgmt_changed) {
9963 ret = intel_color_check(crtc_state);
9968 if (dev_priv->display.compute_pipe_wm) {
9969 ret = dev_priv->display.compute_pipe_wm(crtc_state);
9971 drm_dbg_kms(&dev_priv->drm,
9972 "Target pipe watermarks are invalid\n");
9977 if (dev_priv->display.compute_intermediate_wm) {
9978 if (drm_WARN_ON(&dev_priv->drm,
9979 !dev_priv->display.compute_pipe_wm))
9983 * Calculate 'intermediate' watermarks that satisfy both the
9984 * old state and the new state. We can program these
9987 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
9989 drm_dbg_kms(&dev_priv->drm,
9990 "No valid intermediate pipe watermarks are possible\n");
9995 if (INTEL_GEN(dev_priv) >= 9) {
9996 if (mode_changed || crtc_state->update_pipe) {
9997 ret = skl_update_scaler_crtc(crtc_state);
10002 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
10007 if (HAS_IPS(dev_priv)) {
10008 ret = hsw_compute_ips_config(crtc_state);
10013 if (INTEL_GEN(dev_priv) >= 9 ||
10014 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
10015 ret = hsw_compute_linetime_wm(state, crtc);
10021 if (!mode_changed) {
10022 ret = intel_psr2_sel_fetch_update(state, crtc);
10030 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
10032 struct intel_connector *connector;
10033 struct drm_connector_list_iter conn_iter;
10035 drm_connector_list_iter_begin(dev, &conn_iter);
10036 for_each_intel_connector_iter(connector, &conn_iter) {
10037 if (connector->base.state->crtc)
10038 drm_connector_put(&connector->base);
10040 if (connector->base.encoder) {
10041 connector->base.state->best_encoder =
10042 connector->base.encoder;
10043 connector->base.state->crtc =
10044 connector->base.encoder->crtc;
10046 drm_connector_get(&connector->base);
10048 connector->base.state->best_encoder = NULL;
10049 connector->base.state->crtc = NULL;
10052 drm_connector_list_iter_end(&conn_iter);
10056 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
10057 struct intel_crtc_state *pipe_config)
10059 struct drm_connector *connector = conn_state->connector;
10060 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
10061 const struct drm_display_info *info = &connector->display_info;
10064 switch (conn_state->max_bpc) {
10078 MISSING_CASE(conn_state->max_bpc);
10082 if (bpp < pipe_config->pipe_bpp) {
10083 drm_dbg_kms(&i915->drm,
10084 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
10085 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
10086 connector->base.id, connector->name,
10087 bpp, 3 * info->bpc,
10088 3 * conn_state->max_requested_bpc,
10089 pipe_config->pipe_bpp);
10091 pipe_config->pipe_bpp = bpp;
10098 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
10099 struct intel_crtc_state *pipe_config)
10101 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10102 struct drm_atomic_state *state = pipe_config->uapi.state;
10103 struct drm_connector *connector;
10104 struct drm_connector_state *connector_state;
10107 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
10108 IS_CHERRYVIEW(dev_priv)))
10110 else if (INTEL_GEN(dev_priv) >= 5)
10115 pipe_config->pipe_bpp = bpp;
10117 /* Clamp display bpp to connector max bpp */
10118 for_each_new_connector_in_state(state, connector, connector_state, i) {
10121 if (connector_state->crtc != &crtc->base)
10124 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
10132 static void intel_dump_crtc_timings(struct drm_i915_private *i915,
10133 const struct drm_display_mode *mode)
10135 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, "
10136 "type: 0x%x flags: 0x%x\n",
10138 mode->crtc_hdisplay, mode->crtc_hsync_start,
10139 mode->crtc_hsync_end, mode->crtc_htotal,
10140 mode->crtc_vdisplay, mode->crtc_vsync_start,
10141 mode->crtc_vsync_end, mode->crtc_vtotal,
10142 mode->type, mode->flags);
10146 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
10147 const char *id, unsigned int lane_count,
10148 const struct intel_link_m_n *m_n)
10150 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
10152 drm_dbg_kms(&i915->drm,
10153 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
10155 m_n->gmch_m, m_n->gmch_n,
10156 m_n->link_m, m_n->link_n, m_n->tu);
10160 intel_dump_infoframe(struct drm_i915_private *dev_priv,
10161 const union hdmi_infoframe *frame)
10163 if (!drm_debug_enabled(DRM_UT_KMS))
10166 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
10170 intel_dump_dp_vsc_sdp(struct drm_i915_private *dev_priv,
10171 const struct drm_dp_vsc_sdp *vsc)
10173 if (!drm_debug_enabled(DRM_UT_KMS))
10176 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, vsc);
10179 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
10181 static const char * const output_type_str[] = {
10182 OUTPUT_TYPE(UNUSED),
10183 OUTPUT_TYPE(ANALOG),
10187 OUTPUT_TYPE(TVOUT),
10193 OUTPUT_TYPE(DP_MST),
10198 static void snprintf_output_types(char *buf, size_t len,
10199 unsigned int output_types)
10206 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
10209 if ((output_types & BIT(i)) == 0)
10212 r = snprintf(str, len, "%s%s",
10213 str != buf ? "," : "", output_type_str[i]);
10219 output_types &= ~BIT(i);
10222 WARN_ON_ONCE(output_types != 0);
10225 static const char * const output_format_str[] = {
10226 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
10227 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
10228 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
10229 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
10232 static const char *output_formats(enum intel_output_format format)
10234 if (format >= ARRAY_SIZE(output_format_str))
10235 format = INTEL_OUTPUT_FORMAT_INVALID;
10236 return output_format_str[format];
10239 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
10241 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
10242 struct drm_i915_private *i915 = to_i915(plane->base.dev);
10243 const struct drm_framebuffer *fb = plane_state->hw.fb;
10244 struct drm_format_name_buf format_name;
10247 drm_dbg_kms(&i915->drm,
10248 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
10249 plane->base.base.id, plane->base.name,
10250 yesno(plane_state->uapi.visible));
10254 drm_dbg_kms(&i915->drm,
10255 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %s modifier = 0x%llx, visible: %s\n",
10256 plane->base.base.id, plane->base.name,
10257 fb->base.id, fb->width, fb->height,
10258 drm_get_format_name(fb->format->format, &format_name),
10259 fb->modifier, yesno(plane_state->uapi.visible));
10260 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
10261 plane_state->hw.rotation, plane_state->scaler_id);
10262 if (plane_state->uapi.visible)
10263 drm_dbg_kms(&i915->drm,
10264 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
10265 DRM_RECT_FP_ARG(&plane_state->uapi.src),
10266 DRM_RECT_ARG(&plane_state->uapi.dst));
10269 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
10270 struct intel_atomic_state *state,
10271 const char *context)
10273 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
10274 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10275 const struct intel_plane_state *plane_state;
10276 struct intel_plane *plane;
10280 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
10281 crtc->base.base.id, crtc->base.name,
10282 yesno(pipe_config->hw.enable), context);
10284 if (!pipe_config->hw.enable)
10287 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
10288 drm_dbg_kms(&dev_priv->drm,
10289 "active: %s, output_types: %s (0x%x), output format: %s\n",
10290 yesno(pipe_config->hw.active),
10291 buf, pipe_config->output_types,
10292 output_formats(pipe_config->output_format));
10294 drm_dbg_kms(&dev_priv->drm,
10295 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
10296 transcoder_name(pipe_config->cpu_transcoder),
10297 pipe_config->pipe_bpp, pipe_config->dither);
10299 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
10300 transcoder_name(pipe_config->mst_master_transcoder));
10302 drm_dbg_kms(&dev_priv->drm,
10303 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n",
10304 transcoder_name(pipe_config->master_transcoder),
10305 pipe_config->sync_mode_slaves_mask);
10307 drm_dbg_kms(&dev_priv->drm, "bigjoiner: %s\n",
10308 pipe_config->bigjoiner_slave ? "slave" :
10309 pipe_config->bigjoiner ? "master" : "no");
10311 if (pipe_config->has_pch_encoder)
10312 intel_dump_m_n_config(pipe_config, "fdi",
10313 pipe_config->fdi_lanes,
10314 &pipe_config->fdi_m_n);
10316 if (intel_crtc_has_dp_encoder(pipe_config)) {
10317 intel_dump_m_n_config(pipe_config, "dp m_n",
10318 pipe_config->lane_count, &pipe_config->dp_m_n);
10319 if (pipe_config->has_drrs)
10320 intel_dump_m_n_config(pipe_config, "dp m2_n2",
10321 pipe_config->lane_count,
10322 &pipe_config->dp_m2_n2);
10325 drm_dbg_kms(&dev_priv->drm,
10326 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
10327 pipe_config->has_audio, pipe_config->has_infoframe,
10328 pipe_config->infoframes.enable);
10330 if (pipe_config->infoframes.enable &
10331 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
10332 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
10333 pipe_config->infoframes.gcp);
10334 if (pipe_config->infoframes.enable &
10335 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
10336 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
10337 if (pipe_config->infoframes.enable &
10338 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
10339 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
10340 if (pipe_config->infoframes.enable &
10341 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
10342 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
10343 if (pipe_config->infoframes.enable &
10344 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_DRM))
10345 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
10346 if (pipe_config->infoframes.enable &
10347 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA))
10348 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
10349 if (pipe_config->infoframes.enable &
10350 intel_hdmi_infoframe_enable(DP_SDP_VSC))
10351 intel_dump_dp_vsc_sdp(dev_priv, &pipe_config->infoframes.vsc);
10353 drm_dbg_kms(&dev_priv->drm, "vrr: %s, vmin: %d, vmax: %d, pipeline full: %d, flipline: %d, vmin vblank: %d, vmax vblank: %d\n",
10354 yesno(pipe_config->vrr.enable),
10355 pipe_config->vrr.vmin, pipe_config->vrr.vmax,
10356 pipe_config->vrr.pipeline_full, pipe_config->vrr.flipline,
10357 intel_vrr_vmin_vblank_start(pipe_config),
10358 intel_vrr_vmax_vblank_start(pipe_config));
10360 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
10361 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
10362 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
10363 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
10364 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode);
10365 drm_dbg_kms(&dev_priv->drm, "pipe mode:\n");
10366 drm_mode_debug_printmodeline(&pipe_config->hw.pipe_mode);
10367 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.pipe_mode);
10368 drm_dbg_kms(&dev_priv->drm,
10369 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
10370 pipe_config->port_clock,
10371 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
10372 pipe_config->pixel_rate);
10374 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
10375 pipe_config->linetime, pipe_config->ips_linetime);
10377 if (INTEL_GEN(dev_priv) >= 9)
10378 drm_dbg_kms(&dev_priv->drm,
10379 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
10381 pipe_config->scaler_state.scaler_users,
10382 pipe_config->scaler_state.scaler_id);
10384 if (HAS_GMCH(dev_priv))
10385 drm_dbg_kms(&dev_priv->drm,
10386 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
10387 pipe_config->gmch_pfit.control,
10388 pipe_config->gmch_pfit.pgm_ratios,
10389 pipe_config->gmch_pfit.lvds_border_bits);
10391 drm_dbg_kms(&dev_priv->drm,
10392 "pch pfit: " DRM_RECT_FMT ", %s, force thru: %s\n",
10393 DRM_RECT_ARG(&pipe_config->pch_pfit.dst),
10394 enableddisabled(pipe_config->pch_pfit.enabled),
10395 yesno(pipe_config->pch_pfit.force_thru));
10397 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
10398 pipe_config->ips_enabled, pipe_config->double_wide);
10400 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
10402 if (IS_CHERRYVIEW(dev_priv))
10403 drm_dbg_kms(&dev_priv->drm,
10404 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
10405 pipe_config->cgm_mode, pipe_config->gamma_mode,
10406 pipe_config->gamma_enable, pipe_config->csc_enable);
10408 drm_dbg_kms(&dev_priv->drm,
10409 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
10410 pipe_config->csc_mode, pipe_config->gamma_mode,
10411 pipe_config->gamma_enable, pipe_config->csc_enable);
10413 drm_dbg_kms(&dev_priv->drm, "degamma lut: %d entries, gamma lut: %d entries\n",
10414 pipe_config->hw.degamma_lut ?
10415 drm_color_lut_size(pipe_config->hw.degamma_lut) : 0,
10416 pipe_config->hw.gamma_lut ?
10417 drm_color_lut_size(pipe_config->hw.gamma_lut) : 0);
10423 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10424 if (plane->pipe == crtc->pipe)
10425 intel_dump_plane_state(plane_state);
10429 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
10431 struct drm_device *dev = state->base.dev;
10432 struct drm_connector *connector;
10433 struct drm_connector_list_iter conn_iter;
10434 unsigned int used_ports = 0;
10435 unsigned int used_mst_ports = 0;
10439 * We're going to peek into connector->state,
10440 * hence connection_mutex must be held.
10442 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
10445 * Walk the connector list instead of the encoder
10446 * list to detect the problem on ddi platforms
10447 * where there's just one encoder per digital port.
10449 drm_connector_list_iter_begin(dev, &conn_iter);
10450 drm_for_each_connector_iter(connector, &conn_iter) {
10451 struct drm_connector_state *connector_state;
10452 struct intel_encoder *encoder;
10455 drm_atomic_get_new_connector_state(&state->base,
10457 if (!connector_state)
10458 connector_state = connector->state;
10460 if (!connector_state->best_encoder)
10463 encoder = to_intel_encoder(connector_state->best_encoder);
10465 drm_WARN_ON(dev, !connector_state->crtc);
10467 switch (encoder->type) {
10468 case INTEL_OUTPUT_DDI:
10469 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
10472 case INTEL_OUTPUT_DP:
10473 case INTEL_OUTPUT_HDMI:
10474 case INTEL_OUTPUT_EDP:
10475 /* the same port mustn't appear more than once */
10476 if (used_ports & BIT(encoder->port))
10479 used_ports |= BIT(encoder->port);
10481 case INTEL_OUTPUT_DP_MST:
10483 1 << encoder->port;
10489 drm_connector_list_iter_end(&conn_iter);
10491 /* can't mix MST and SST/HDMI on the same port */
10492 if (used_ports & used_mst_ports)
10499 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
10500 struct intel_crtc_state *crtc_state)
10502 const struct intel_crtc_state *from_crtc_state = crtc_state;
10504 if (crtc_state->bigjoiner_slave) {
10505 from_crtc_state = intel_atomic_get_new_crtc_state(state,
10506 crtc_state->bigjoiner_linked_crtc);
10508 /* No need to copy state if the master state is unchanged */
10509 if (!from_crtc_state)
10513 intel_crtc_copy_color_blobs(crtc_state, from_crtc_state);
10517 intel_crtc_copy_uapi_to_hw_state(struct intel_atomic_state *state,
10518 struct intel_crtc_state *crtc_state)
10520 crtc_state->hw.enable = crtc_state->uapi.enable;
10521 crtc_state->hw.active = crtc_state->uapi.active;
10522 crtc_state->hw.mode = crtc_state->uapi.mode;
10523 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
10524 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
10526 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc_state);
10529 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
10531 if (crtc_state->bigjoiner_slave)
10534 crtc_state->uapi.enable = crtc_state->hw.enable;
10535 crtc_state->uapi.active = crtc_state->hw.active;
10536 drm_WARN_ON(crtc_state->uapi.crtc->dev,
10537 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
10539 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
10540 crtc_state->uapi.scaling_filter = crtc_state->hw.scaling_filter;
10542 /* copy color blobs to uapi */
10543 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
10544 crtc_state->hw.degamma_lut);
10545 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
10546 crtc_state->hw.gamma_lut);
10547 drm_property_replace_blob(&crtc_state->uapi.ctm,
10548 crtc_state->hw.ctm);
10552 copy_bigjoiner_crtc_state(struct intel_crtc_state *crtc_state,
10553 const struct intel_crtc_state *from_crtc_state)
10555 struct intel_crtc_state *saved_state;
10556 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10558 saved_state = kmemdup(from_crtc_state, sizeof(*saved_state), GFP_KERNEL);
10562 saved_state->uapi = crtc_state->uapi;
10563 saved_state->scaler_state = crtc_state->scaler_state;
10564 saved_state->shared_dpll = crtc_state->shared_dpll;
10565 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
10566 saved_state->crc_enabled = crtc_state->crc_enabled;
10568 intel_crtc_free_hw_state(crtc_state);
10569 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
10570 kfree(saved_state);
10572 /* Re-init hw state */
10573 memset(&crtc_state->hw, 0, sizeof(saved_state->hw));
10574 crtc_state->hw.enable = from_crtc_state->hw.enable;
10575 crtc_state->hw.active = from_crtc_state->hw.active;
10576 crtc_state->hw.pipe_mode = from_crtc_state->hw.pipe_mode;
10577 crtc_state->hw.adjusted_mode = from_crtc_state->hw.adjusted_mode;
10580 crtc_state->uapi.mode_changed = from_crtc_state->uapi.mode_changed;
10581 crtc_state->uapi.connectors_changed = from_crtc_state->uapi.connectors_changed;
10582 crtc_state->uapi.active_changed = from_crtc_state->uapi.active_changed;
10583 crtc_state->nv12_planes = crtc_state->c8_planes = crtc_state->update_planes = 0;
10584 crtc_state->bigjoiner_linked_crtc = to_intel_crtc(from_crtc_state->uapi.crtc);
10585 crtc_state->bigjoiner_slave = true;
10586 crtc_state->cpu_transcoder = (enum transcoder)crtc->pipe;
10587 crtc_state->has_audio = false;
10593 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
10594 struct intel_crtc_state *crtc_state)
10596 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10597 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10598 struct intel_crtc_state *saved_state;
10600 saved_state = intel_crtc_state_alloc(crtc);
10604 /* free the old crtc_state->hw members */
10605 intel_crtc_free_hw_state(crtc_state);
10607 /* FIXME: before the switch to atomic started, a new pipe_config was
10608 * kzalloc'd. Code that depends on any field being zero should be
10609 * fixed, so that the crtc_state can be safely duplicated. For now,
10610 * only fields that are know to not cause problems are preserved. */
10612 saved_state->uapi = crtc_state->uapi;
10613 saved_state->scaler_state = crtc_state->scaler_state;
10614 saved_state->shared_dpll = crtc_state->shared_dpll;
10615 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
10616 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
10617 sizeof(saved_state->icl_port_dplls));
10618 saved_state->crc_enabled = crtc_state->crc_enabled;
10619 if (IS_G4X(dev_priv) ||
10620 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10621 saved_state->wm = crtc_state->wm;
10623 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
10624 kfree(saved_state);
10626 intel_crtc_copy_uapi_to_hw_state(state, crtc_state);
10632 intel_modeset_pipe_config(struct intel_atomic_state *state,
10633 struct intel_crtc_state *pipe_config)
10635 struct drm_crtc *crtc = pipe_config->uapi.crtc;
10636 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
10637 struct drm_connector *connector;
10638 struct drm_connector_state *connector_state;
10639 int base_bpp, ret, i;
10642 pipe_config->cpu_transcoder =
10643 (enum transcoder) to_intel_crtc(crtc)->pipe;
10646 * Sanitize sync polarity flags based on requested ones. If neither
10647 * positive or negative polarity is requested, treat this as meaning
10648 * negative polarity.
10650 if (!(pipe_config->hw.adjusted_mode.flags &
10651 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
10652 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
10654 if (!(pipe_config->hw.adjusted_mode.flags &
10655 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
10656 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
10658 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
10663 base_bpp = pipe_config->pipe_bpp;
10666 * Determine the real pipe dimensions. Note that stereo modes can
10667 * increase the actual pipe size due to the frame doubling and
10668 * insertion of additional space for blanks between the frame. This
10669 * is stored in the crtc timings. We use the requested mode to do this
10670 * computation to clearly distinguish it from the adjusted mode, which
10671 * can be changed by the connectors in the below retry loop.
10673 drm_mode_get_hv_timing(&pipe_config->hw.mode,
10674 &pipe_config->pipe_src_w,
10675 &pipe_config->pipe_src_h);
10677 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
10678 struct intel_encoder *encoder =
10679 to_intel_encoder(connector_state->best_encoder);
10681 if (connector_state->crtc != crtc)
10684 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
10685 drm_dbg_kms(&i915->drm,
10686 "rejecting invalid cloning configuration\n");
10691 * Determine output_types before calling the .compute_config()
10692 * hooks so that the hooks can use this information safely.
10694 if (encoder->compute_output_type)
10695 pipe_config->output_types |=
10696 BIT(encoder->compute_output_type(encoder, pipe_config,
10699 pipe_config->output_types |= BIT(encoder->type);
10703 /* Ensure the port clock defaults are reset when retrying. */
10704 pipe_config->port_clock = 0;
10705 pipe_config->pixel_multiplier = 1;
10707 /* Fill in default crtc timings, allow encoders to overwrite them. */
10708 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
10709 CRTC_STEREO_DOUBLE);
10711 /* Pass our mode to the connectors and the CRTC to give them a chance to
10712 * adjust it according to limitations or connector properties, and also
10713 * a chance to reject the mode entirely.
10715 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
10716 struct intel_encoder *encoder =
10717 to_intel_encoder(connector_state->best_encoder);
10719 if (connector_state->crtc != crtc)
10722 ret = encoder->compute_config(encoder, pipe_config,
10725 if (ret != -EDEADLK)
10726 drm_dbg_kms(&i915->drm,
10727 "Encoder config failure: %d\n",
10733 /* Set default port clock if not overwritten by the encoder. Needs to be
10734 * done afterwards in case the encoder adjusts the mode. */
10735 if (!pipe_config->port_clock)
10736 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
10737 * pipe_config->pixel_multiplier;
10739 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
10740 if (ret == -EDEADLK)
10743 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
10747 if (ret == I915_DISPLAY_CONFIG_RETRY) {
10748 if (drm_WARN(&i915->drm, !retry,
10749 "loop in pipe configuration computation\n"))
10752 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
10754 goto encoder_retry;
10757 /* Dithering seems to not pass-through bits correctly when it should, so
10758 * only enable it on 6bpc panels and when its not a compliance
10759 * test requesting 6bpc video pattern.
10761 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
10762 !pipe_config->dither_force_disable;
10763 drm_dbg_kms(&i915->drm,
10764 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
10765 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
10771 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
10773 struct intel_atomic_state *state =
10774 to_intel_atomic_state(crtc_state->uapi.state);
10775 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
10776 struct drm_connector_state *conn_state;
10777 struct drm_connector *connector;
10780 for_each_new_connector_in_state(&state->base, connector,
10782 struct intel_encoder *encoder =
10783 to_intel_encoder(conn_state->best_encoder);
10786 if (conn_state->crtc != &crtc->base ||
10787 !encoder->compute_config_late)
10790 ret = encoder->compute_config_late(encoder, crtc_state,
10799 bool intel_fuzzy_clock_check(int clock1, int clock2)
10803 if (clock1 == clock2)
10806 if (!clock1 || !clock2)
10809 diff = abs(clock1 - clock2);
10811 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
10818 intel_compare_m_n(unsigned int m, unsigned int n,
10819 unsigned int m2, unsigned int n2,
10822 if (m == m2 && n == n2)
10825 if (exact || !m || !n || !m2 || !n2)
10828 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
10835 } else if (n < n2) {
10845 return intel_fuzzy_clock_check(m, m2);
10849 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
10850 const struct intel_link_m_n *m2_n2,
10853 return m_n->tu == m2_n2->tu &&
10854 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
10855 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
10856 intel_compare_m_n(m_n->link_m, m_n->link_n,
10857 m2_n2->link_m, m2_n2->link_n, exact);
10861 intel_compare_infoframe(const union hdmi_infoframe *a,
10862 const union hdmi_infoframe *b)
10864 return memcmp(a, b, sizeof(*a)) == 0;
10868 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
10869 const struct drm_dp_vsc_sdp *b)
10871 return memcmp(a, b, sizeof(*a)) == 0;
10875 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
10876 bool fastset, const char *name,
10877 const union hdmi_infoframe *a,
10878 const union hdmi_infoframe *b)
10881 if (!drm_debug_enabled(DRM_UT_KMS))
10884 drm_dbg_kms(&dev_priv->drm,
10885 "fastset mismatch in %s infoframe\n", name);
10886 drm_dbg_kms(&dev_priv->drm, "expected:\n");
10887 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
10888 drm_dbg_kms(&dev_priv->drm, "found:\n");
10889 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
10891 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
10892 drm_err(&dev_priv->drm, "expected:\n");
10893 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
10894 drm_err(&dev_priv->drm, "found:\n");
10895 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
10900 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
10901 bool fastset, const char *name,
10902 const struct drm_dp_vsc_sdp *a,
10903 const struct drm_dp_vsc_sdp *b)
10906 if (!drm_debug_enabled(DRM_UT_KMS))
10909 drm_dbg_kms(&dev_priv->drm,
10910 "fastset mismatch in %s dp sdp\n", name);
10911 drm_dbg_kms(&dev_priv->drm, "expected:\n");
10912 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
10913 drm_dbg_kms(&dev_priv->drm, "found:\n");
10914 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
10916 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
10917 drm_err(&dev_priv->drm, "expected:\n");
10918 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
10919 drm_err(&dev_priv->drm, "found:\n");
10920 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
10924 static void __printf(4, 5)
10925 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
10926 const char *name, const char *format, ...)
10928 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
10929 struct va_format vaf;
10932 va_start(args, format);
10937 drm_dbg_kms(&i915->drm,
10938 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
10939 crtc->base.base.id, crtc->base.name, name, &vaf);
10941 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
10942 crtc->base.base.id, crtc->base.name, name, &vaf);
10947 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
10949 if (dev_priv->params.fastboot != -1)
10950 return dev_priv->params.fastboot;
10952 /* Enable fastboot by default on Skylake and newer */
10953 if (INTEL_GEN(dev_priv) >= 9)
10956 /* Enable fastboot by default on VLV and CHV */
10957 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
10960 /* Disabled by default on all others */
10965 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
10966 const struct intel_crtc_state *pipe_config,
10969 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
10970 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
10973 bool fixup_inherited = fastset &&
10974 current_config->inherited && !pipe_config->inherited;
10976 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
10977 drm_dbg_kms(&dev_priv->drm,
10978 "initial modeset and fastboot not set\n");
10982 #define PIPE_CONF_CHECK_X(name) do { \
10983 if (current_config->name != pipe_config->name) { \
10984 pipe_config_mismatch(fastset, crtc, __stringify(name), \
10985 "(expected 0x%08x, found 0x%08x)", \
10986 current_config->name, \
10987 pipe_config->name); \
10992 #define PIPE_CONF_CHECK_I(name) do { \
10993 if (current_config->name != pipe_config->name) { \
10994 pipe_config_mismatch(fastset, crtc, __stringify(name), \
10995 "(expected %i, found %i)", \
10996 current_config->name, \
10997 pipe_config->name); \
11002 #define PIPE_CONF_CHECK_BOOL(name) do { \
11003 if (current_config->name != pipe_config->name) { \
11004 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11005 "(expected %s, found %s)", \
11006 yesno(current_config->name), \
11007 yesno(pipe_config->name)); \
11013 * Checks state where we only read out the enabling, but not the entire
11014 * state itself (like full infoframes or ELD for audio). These states
11015 * require a full modeset on bootup to fix up.
11017 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
11018 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11019 PIPE_CONF_CHECK_BOOL(name); \
11021 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11022 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
11023 yesno(current_config->name), \
11024 yesno(pipe_config->name)); \
11029 #define PIPE_CONF_CHECK_P(name) do { \
11030 if (current_config->name != pipe_config->name) { \
11031 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11032 "(expected %p, found %p)", \
11033 current_config->name, \
11034 pipe_config->name); \
11039 #define PIPE_CONF_CHECK_M_N(name) do { \
11040 if (!intel_compare_link_m_n(¤t_config->name, \
11041 &pipe_config->name,\
11043 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11044 "(expected tu %i gmch %i/%i link %i/%i, " \
11045 "found tu %i, gmch %i/%i link %i/%i)", \
11046 current_config->name.tu, \
11047 current_config->name.gmch_m, \
11048 current_config->name.gmch_n, \
11049 current_config->name.link_m, \
11050 current_config->name.link_n, \
11051 pipe_config->name.tu, \
11052 pipe_config->name.gmch_m, \
11053 pipe_config->name.gmch_n, \
11054 pipe_config->name.link_m, \
11055 pipe_config->name.link_n); \
11060 /* This is required for BDW+ where there is only one set of registers for
11061 * switching between high and low RR.
11062 * This macro can be used whenever a comparison has to be made between one
11063 * hw state and multiple sw state variables.
11065 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
11066 if (!intel_compare_link_m_n(¤t_config->name, \
11067 &pipe_config->name, !fastset) && \
11068 !intel_compare_link_m_n(¤t_config->alt_name, \
11069 &pipe_config->name, !fastset)) { \
11070 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11071 "(expected tu %i gmch %i/%i link %i/%i, " \
11072 "or tu %i gmch %i/%i link %i/%i, " \
11073 "found tu %i, gmch %i/%i link %i/%i)", \
11074 current_config->name.tu, \
11075 current_config->name.gmch_m, \
11076 current_config->name.gmch_n, \
11077 current_config->name.link_m, \
11078 current_config->name.link_n, \
11079 current_config->alt_name.tu, \
11080 current_config->alt_name.gmch_m, \
11081 current_config->alt_name.gmch_n, \
11082 current_config->alt_name.link_m, \
11083 current_config->alt_name.link_n, \
11084 pipe_config->name.tu, \
11085 pipe_config->name.gmch_m, \
11086 pipe_config->name.gmch_n, \
11087 pipe_config->name.link_m, \
11088 pipe_config->name.link_n); \
11093 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
11094 if ((current_config->name ^ pipe_config->name) & (mask)) { \
11095 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11096 "(%x) (expected %i, found %i)", \
11098 current_config->name & (mask), \
11099 pipe_config->name & (mask)); \
11104 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
11105 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
11106 pipe_config_mismatch(fastset, crtc, __stringify(name), \
11107 "(expected %i, found %i)", \
11108 current_config->name, \
11109 pipe_config->name); \
11114 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
11115 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
11116 &pipe_config->infoframes.name)) { \
11117 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
11118 ¤t_config->infoframes.name, \
11119 &pipe_config->infoframes.name); \
11124 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
11125 if (!current_config->has_psr && !pipe_config->has_psr && \
11126 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
11127 &pipe_config->infoframes.name)) { \
11128 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
11129 ¤t_config->infoframes.name, \
11130 &pipe_config->infoframes.name); \
11135 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
11136 if (current_config->name1 != pipe_config->name1) { \
11137 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
11138 "(expected %i, found %i, won't compare lut values)", \
11139 current_config->name1, \
11140 pipe_config->name1); \
11143 if (!intel_color_lut_equal(current_config->name2, \
11144 pipe_config->name2, pipe_config->name1, \
11145 bit_precision)) { \
11146 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
11147 "hw_state doesn't match sw_state"); \
11153 #define PIPE_CONF_QUIRK(quirk) \
11154 ((current_config->quirks | pipe_config->quirks) & (quirk))
11156 PIPE_CONF_CHECK_I(cpu_transcoder);
11158 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
11159 PIPE_CONF_CHECK_I(fdi_lanes);
11160 PIPE_CONF_CHECK_M_N(fdi_m_n);
11162 PIPE_CONF_CHECK_I(lane_count);
11163 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
11165 if (INTEL_GEN(dev_priv) < 8) {
11166 PIPE_CONF_CHECK_M_N(dp_m_n);
11168 if (current_config->has_drrs)
11169 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11171 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
11173 PIPE_CONF_CHECK_X(output_types);
11175 /* FIXME do the readout properly and get rid of this quirk */
11176 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
11177 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hdisplay);
11178 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_htotal);
11179 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_start);
11180 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_end);
11181 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_start);
11182 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_end);
11184 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vdisplay);
11185 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vtotal);
11186 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_start);
11187 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_end);
11188 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_start);
11189 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_end);
11191 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
11192 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
11193 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
11194 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
11195 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
11196 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
11198 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
11199 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
11200 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
11201 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
11202 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
11203 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
11205 PIPE_CONF_CHECK_I(pixel_multiplier);
11207 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
11208 DRM_MODE_FLAG_INTERLACE);
11210 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
11211 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
11212 DRM_MODE_FLAG_PHSYNC);
11213 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
11214 DRM_MODE_FLAG_NHSYNC);
11215 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
11216 DRM_MODE_FLAG_PVSYNC);
11217 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
11218 DRM_MODE_FLAG_NVSYNC);
11222 PIPE_CONF_CHECK_I(output_format);
11223 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
11224 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
11225 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11226 PIPE_CONF_CHECK_BOOL(limited_color_range);
11228 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11229 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
11230 PIPE_CONF_CHECK_BOOL(has_infoframe);
11231 /* FIXME do the readout properly and get rid of this quirk */
11232 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
11233 PIPE_CONF_CHECK_BOOL(fec_enable);
11235 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
11237 PIPE_CONF_CHECK_X(gmch_pfit.control);
11238 /* pfit ratios are autocomputed by the hw on gen4+ */
11239 if (INTEL_GEN(dev_priv) < 4)
11240 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
11241 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
11244 * Changing the EDP transcoder input mux
11245 * (A_ONOFF vs. A_ON) requires a full modeset.
11247 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
11250 PIPE_CONF_CHECK_I(pipe_src_w);
11251 PIPE_CONF_CHECK_I(pipe_src_h);
11253 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
11254 if (current_config->pch_pfit.enabled) {
11255 PIPE_CONF_CHECK_I(pch_pfit.dst.x1);
11256 PIPE_CONF_CHECK_I(pch_pfit.dst.y1);
11257 PIPE_CONF_CHECK_I(pch_pfit.dst.x2);
11258 PIPE_CONF_CHECK_I(pch_pfit.dst.y2);
11261 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
11262 /* FIXME do the readout properly and get rid of this quirk */
11263 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
11264 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
11266 PIPE_CONF_CHECK_X(gamma_mode);
11267 if (IS_CHERRYVIEW(dev_priv))
11268 PIPE_CONF_CHECK_X(cgm_mode);
11270 PIPE_CONF_CHECK_X(csc_mode);
11271 PIPE_CONF_CHECK_BOOL(gamma_enable);
11272 PIPE_CONF_CHECK_BOOL(csc_enable);
11274 PIPE_CONF_CHECK_I(linetime);
11275 PIPE_CONF_CHECK_I(ips_linetime);
11277 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
11279 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
11282 PIPE_CONF_CHECK_BOOL(double_wide);
11284 PIPE_CONF_CHECK_P(shared_dpll);
11286 /* FIXME do the readout properly and get rid of this quirk */
11287 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
11288 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
11289 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
11290 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11291 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
11292 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
11293 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
11294 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11295 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11296 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
11297 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11298 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11299 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11300 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11301 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11302 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11303 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11304 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11305 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11306 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11307 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11308 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
11309 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11310 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11311 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11312 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11313 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11314 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11315 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11316 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11317 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11318 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
11320 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11321 PIPE_CONF_CHECK_X(dsi_pll.div);
11323 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
11324 PIPE_CONF_CHECK_I(pipe_bpp);
11326 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
11327 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
11328 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
11330 PIPE_CONF_CHECK_I(min_voltage_level);
11333 PIPE_CONF_CHECK_X(infoframes.enable);
11334 PIPE_CONF_CHECK_X(infoframes.gcp);
11335 PIPE_CONF_CHECK_INFOFRAME(avi);
11336 PIPE_CONF_CHECK_INFOFRAME(spd);
11337 PIPE_CONF_CHECK_INFOFRAME(hdmi);
11338 PIPE_CONF_CHECK_INFOFRAME(drm);
11339 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
11341 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
11342 PIPE_CONF_CHECK_I(master_transcoder);
11343 PIPE_CONF_CHECK_BOOL(bigjoiner);
11344 PIPE_CONF_CHECK_BOOL(bigjoiner_slave);
11345 PIPE_CONF_CHECK_P(bigjoiner_linked_crtc);
11347 PIPE_CONF_CHECK_I(dsc.compression_enable);
11348 PIPE_CONF_CHECK_I(dsc.dsc_split);
11349 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
11351 PIPE_CONF_CHECK_I(mst_master_transcoder);
11353 PIPE_CONF_CHECK_BOOL(vrr.enable);
11354 PIPE_CONF_CHECK_I(vrr.vmin);
11355 PIPE_CONF_CHECK_I(vrr.vmax);
11356 PIPE_CONF_CHECK_I(vrr.flipline);
11357 PIPE_CONF_CHECK_I(vrr.pipeline_full);
11359 #undef PIPE_CONF_CHECK_X
11360 #undef PIPE_CONF_CHECK_I
11361 #undef PIPE_CONF_CHECK_BOOL
11362 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
11363 #undef PIPE_CONF_CHECK_P
11364 #undef PIPE_CONF_CHECK_FLAGS
11365 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
11366 #undef PIPE_CONF_CHECK_COLOR_LUT
11367 #undef PIPE_CONF_QUIRK
11372 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11373 const struct intel_crtc_state *pipe_config)
11375 if (pipe_config->has_pch_encoder) {
11376 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
11377 &pipe_config->fdi_m_n);
11378 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
11381 * FDI already provided one idea for the dotclock.
11382 * Yell if the encoder disagrees.
11384 drm_WARN(&dev_priv->drm,
11385 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11386 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11387 fdi_dotclock, dotclock);
11391 static void verify_wm_state(struct intel_crtc *crtc,
11392 struct intel_crtc_state *new_crtc_state)
11394 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11395 struct skl_hw_state {
11396 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
11397 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
11398 struct skl_pipe_wm wm;
11400 struct skl_pipe_wm *sw_wm;
11401 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
11402 u8 hw_enabled_slices;
11403 const enum pipe pipe = crtc->pipe;
11404 int plane, level, max_level = ilk_wm_max_level(dev_priv);
11406 if (INTEL_GEN(dev_priv) < 9 || !new_crtc_state->hw.active)
11409 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
11413 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
11414 sw_wm = &new_crtc_state->wm.skl.optimal;
11416 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
11418 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
11420 if (INTEL_GEN(dev_priv) >= 11 &&
11421 hw_enabled_slices != dev_priv->dbuf.enabled_slices)
11422 drm_err(&dev_priv->drm,
11423 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
11424 dev_priv->dbuf.enabled_slices,
11425 hw_enabled_slices);
11428 for_each_universal_plane(dev_priv, pipe, plane) {
11429 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11431 hw_plane_wm = &hw->wm.planes[plane];
11432 sw_plane_wm = &sw_wm->planes[plane];
11435 for (level = 0; level <= max_level; level++) {
11436 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11437 &sw_plane_wm->wm[level]) ||
11438 (level == 0 && skl_wm_level_equals(&hw_plane_wm->wm[level],
11439 &sw_plane_wm->sagv_wm0)))
11442 drm_err(&dev_priv->drm,
11443 "mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11444 pipe_name(pipe), plane + 1, level,
11445 sw_plane_wm->wm[level].plane_en,
11446 sw_plane_wm->wm[level].plane_res_b,
11447 sw_plane_wm->wm[level].plane_res_l,
11448 hw_plane_wm->wm[level].plane_en,
11449 hw_plane_wm->wm[level].plane_res_b,
11450 hw_plane_wm->wm[level].plane_res_l);
11453 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11454 &sw_plane_wm->trans_wm)) {
11455 drm_err(&dev_priv->drm,
11456 "mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11457 pipe_name(pipe), plane + 1,
11458 sw_plane_wm->trans_wm.plane_en,
11459 sw_plane_wm->trans_wm.plane_res_b,
11460 sw_plane_wm->trans_wm.plane_res_l,
11461 hw_plane_wm->trans_wm.plane_en,
11462 hw_plane_wm->trans_wm.plane_res_b,
11463 hw_plane_wm->trans_wm.plane_res_l);
11467 hw_ddb_entry = &hw->ddb_y[plane];
11468 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane];
11470 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11471 drm_err(&dev_priv->drm,
11472 "mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
11473 pipe_name(pipe), plane + 1,
11474 sw_ddb_entry->start, sw_ddb_entry->end,
11475 hw_ddb_entry->start, hw_ddb_entry->end);
11481 * If the cursor plane isn't active, we may not have updated it's ddb
11482 * allocation. In that case since the ddb allocation will be updated
11483 * once the plane becomes visible, we can skip this check
11486 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11488 hw_plane_wm = &hw->wm.planes[PLANE_CURSOR];
11489 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
11492 for (level = 0; level <= max_level; level++) {
11493 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11494 &sw_plane_wm->wm[level]) ||
11495 (level == 0 && skl_wm_level_equals(&hw_plane_wm->wm[level],
11496 &sw_plane_wm->sagv_wm0)))
11499 drm_err(&dev_priv->drm,
11500 "mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11501 pipe_name(pipe), level,
11502 sw_plane_wm->wm[level].plane_en,
11503 sw_plane_wm->wm[level].plane_res_b,
11504 sw_plane_wm->wm[level].plane_res_l,
11505 hw_plane_wm->wm[level].plane_en,
11506 hw_plane_wm->wm[level].plane_res_b,
11507 hw_plane_wm->wm[level].plane_res_l);
11510 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11511 &sw_plane_wm->trans_wm)) {
11512 drm_err(&dev_priv->drm,
11513 "mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
11515 sw_plane_wm->trans_wm.plane_en,
11516 sw_plane_wm->trans_wm.plane_res_b,
11517 sw_plane_wm->trans_wm.plane_res_l,
11518 hw_plane_wm->trans_wm.plane_en,
11519 hw_plane_wm->trans_wm.plane_res_b,
11520 hw_plane_wm->trans_wm.plane_res_l);
11524 hw_ddb_entry = &hw->ddb_y[PLANE_CURSOR];
11525 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
11527 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
11528 drm_err(&dev_priv->drm,
11529 "mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
11531 sw_ddb_entry->start, sw_ddb_entry->end,
11532 hw_ddb_entry->start, hw_ddb_entry->end);
11540 verify_connector_state(struct intel_atomic_state *state,
11541 struct intel_crtc *crtc)
11543 struct drm_connector *connector;
11544 struct drm_connector_state *new_conn_state;
11547 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
11548 struct drm_encoder *encoder = connector->encoder;
11549 struct intel_crtc_state *crtc_state = NULL;
11551 if (new_conn_state->crtc != &crtc->base)
11555 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
11557 intel_connector_verify_state(crtc_state, new_conn_state);
11559 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
11560 "connector's atomic encoder doesn't match legacy encoder\n");
11565 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
11567 struct intel_encoder *encoder;
11568 struct drm_connector *connector;
11569 struct drm_connector_state *old_conn_state, *new_conn_state;
11572 for_each_intel_encoder(&dev_priv->drm, encoder) {
11573 bool enabled = false, found = false;
11576 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
11577 encoder->base.base.id,
11578 encoder->base.name);
11580 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
11581 new_conn_state, i) {
11582 if (old_conn_state->best_encoder == &encoder->base)
11585 if (new_conn_state->best_encoder != &encoder->base)
11587 found = enabled = true;
11589 I915_STATE_WARN(new_conn_state->crtc !=
11590 encoder->base.crtc,
11591 "connector's crtc doesn't match encoder crtc\n");
11597 I915_STATE_WARN(!!encoder->base.crtc != enabled,
11598 "encoder's enabled state mismatch "
11599 "(expected %i, found %i)\n",
11600 !!encoder->base.crtc, enabled);
11602 if (!encoder->base.crtc) {
11605 active = encoder->get_hw_state(encoder, &pipe);
11606 I915_STATE_WARN(active,
11607 "encoder detached but still enabled on pipe %c.\n",
11614 verify_crtc_state(struct intel_crtc *crtc,
11615 struct intel_crtc_state *old_crtc_state,
11616 struct intel_crtc_state *new_crtc_state)
11618 struct drm_device *dev = crtc->base.dev;
11619 struct drm_i915_private *dev_priv = to_i915(dev);
11620 struct intel_encoder *encoder;
11621 struct intel_crtc_state *pipe_config = old_crtc_state;
11622 struct drm_atomic_state *state = old_crtc_state->uapi.state;
11623 struct intel_crtc *master = crtc;
11625 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
11626 intel_crtc_free_hw_state(old_crtc_state);
11627 intel_crtc_state_reset(old_crtc_state, crtc);
11628 old_crtc_state->uapi.state = state;
11630 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
11633 pipe_config->hw.enable = new_crtc_state->hw.enable;
11635 intel_crtc_get_pipe_config(pipe_config);
11637 /* we keep both pipes enabled on 830 */
11638 if (IS_I830(dev_priv) && pipe_config->hw.active)
11639 pipe_config->hw.active = new_crtc_state->hw.active;
11641 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active,
11642 "crtc active state doesn't match with hw state "
11643 "(expected %i, found %i)\n",
11644 new_crtc_state->hw.active, pipe_config->hw.active);
11646 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
11647 "transitional active state does not match atomic hw state "
11648 "(expected %i, found %i)\n",
11649 new_crtc_state->hw.active, crtc->active);
11651 if (new_crtc_state->bigjoiner_slave)
11652 master = new_crtc_state->bigjoiner_linked_crtc;
11654 for_each_encoder_on_crtc(dev, &master->base, encoder) {
11658 active = encoder->get_hw_state(encoder, &pipe);
11659 I915_STATE_WARN(active != new_crtc_state->hw.active,
11660 "[ENCODER:%i] active %i with crtc active %i\n",
11661 encoder->base.base.id, active,
11662 new_crtc_state->hw.active);
11664 I915_STATE_WARN(active && master->pipe != pipe,
11665 "Encoder connected to wrong pipe %c\n",
11669 intel_encoder_get_config(encoder, pipe_config);
11672 if (!new_crtc_state->hw.active)
11675 intel_pipe_config_sanity_check(dev_priv, pipe_config);
11677 if (!intel_pipe_config_compare(new_crtc_state,
11678 pipe_config, false)) {
11679 I915_STATE_WARN(1, "pipe state doesn't match!\n");
11680 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
11681 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
11686 intel_verify_planes(struct intel_atomic_state *state)
11688 struct intel_plane *plane;
11689 const struct intel_plane_state *plane_state;
11692 for_each_new_intel_plane_in_state(state, plane,
11694 assert_plane(plane, plane_state->planar_slave ||
11695 plane_state->uapi.visible);
11699 verify_single_dpll_state(struct drm_i915_private *dev_priv,
11700 struct intel_shared_dpll *pll,
11701 struct intel_crtc *crtc,
11702 struct intel_crtc_state *new_crtc_state)
11704 struct intel_dpll_hw_state dpll_hw_state;
11705 unsigned int crtc_mask;
11708 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
11710 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
11712 active = intel_dpll_get_hw_state(dev_priv, pll, &dpll_hw_state);
11714 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
11715 I915_STATE_WARN(!pll->on && pll->active_mask,
11716 "pll in active use but not on in sw tracking\n");
11717 I915_STATE_WARN(pll->on && !pll->active_mask,
11718 "pll is on but not used by any active crtc\n");
11719 I915_STATE_WARN(pll->on != active,
11720 "pll on state mismatch (expected %i, found %i)\n",
11725 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
11726 "more active pll users than references: %x vs %x\n",
11727 pll->active_mask, pll->state.crtc_mask);
11732 crtc_mask = drm_crtc_mask(&crtc->base);
11734 if (new_crtc_state->hw.active)
11735 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
11736 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
11737 pipe_name(crtc->pipe), pll->active_mask);
11739 I915_STATE_WARN(pll->active_mask & crtc_mask,
11740 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
11741 pipe_name(crtc->pipe), pll->active_mask);
11743 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
11744 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
11745 crtc_mask, pll->state.crtc_mask);
11747 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
11749 sizeof(dpll_hw_state)),
11750 "pll hw state mismatch\n");
11754 verify_shared_dpll_state(struct intel_crtc *crtc,
11755 struct intel_crtc_state *old_crtc_state,
11756 struct intel_crtc_state *new_crtc_state)
11758 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11760 if (new_crtc_state->shared_dpll)
11761 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
11763 if (old_crtc_state->shared_dpll &&
11764 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
11765 unsigned int crtc_mask = drm_crtc_mask(&crtc->base);
11766 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
11768 I915_STATE_WARN(pll->active_mask & crtc_mask,
11769 "pll active mismatch (didn't expect pipe %c in active mask)\n",
11770 pipe_name(crtc->pipe));
11771 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
11772 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
11773 pipe_name(crtc->pipe));
11778 intel_modeset_verify_crtc(struct intel_crtc *crtc,
11779 struct intel_atomic_state *state,
11780 struct intel_crtc_state *old_crtc_state,
11781 struct intel_crtc_state *new_crtc_state)
11783 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
11786 verify_wm_state(crtc, new_crtc_state);
11787 verify_connector_state(state, crtc);
11788 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
11789 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
11793 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
11797 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
11798 verify_single_dpll_state(dev_priv,
11799 &dev_priv->dpll.shared_dplls[i],
11804 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
11805 struct intel_atomic_state *state)
11807 verify_encoder_state(dev_priv, state);
11808 verify_connector_state(state, NULL);
11809 verify_disabled_dpll_state(dev_priv);
11813 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
11815 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
11816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11817 struct drm_display_mode adjusted_mode =
11818 crtc_state->hw.adjusted_mode;
11820 if (crtc_state->vrr.enable) {
11821 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax;
11822 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax;
11823 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state);
11824 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state);
11827 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
11829 crtc->mode_flags = crtc_state->mode_flags;
11832 * The scanline counter increments at the leading edge of hsync.
11834 * On most platforms it starts counting from vtotal-1 on the
11835 * first active line. That means the scanline counter value is
11836 * always one less than what we would expect. Ie. just after
11837 * start of vblank, which also occurs at start of hsync (on the
11838 * last active line), the scanline counter will read vblank_start-1.
11840 * On gen2 the scanline counter starts counting from 1 instead
11841 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
11842 * to keep the value positive), instead of adding one.
11844 * On HSW+ the behaviour of the scanline counter depends on the output
11845 * type. For DP ports it behaves like most other platforms, but on HDMI
11846 * there's an extra 1 line difference. So we need to add two instead of
11847 * one to the value.
11849 * On VLV/CHV DSI the scanline counter would appear to increment
11850 * approx. 1/3 of a scanline before start of vblank. Unfortunately
11851 * that means we can't tell whether we're in vblank or not while
11852 * we're on that particular line. We must still set scanline_offset
11853 * to 1 so that the vblank timestamps come out correct when we query
11854 * the scanline counter from within the vblank interrupt handler.
11855 * However if queried just before the start of vblank we'll get an
11856 * answer that's slightly in the future.
11858 if (IS_GEN(dev_priv, 2)) {
11861 vtotal = adjusted_mode.crtc_vtotal;
11862 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
11865 crtc->scanline_offset = vtotal - 1;
11866 } else if (HAS_DDI(dev_priv) &&
11867 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
11868 crtc->scanline_offset = 2;
11870 crtc->scanline_offset = 1;
11874 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
11876 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
11877 struct intel_crtc_state *new_crtc_state;
11878 struct intel_crtc *crtc;
11881 if (!dev_priv->display.crtc_compute_clock)
11884 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
11885 if (!intel_crtc_needs_modeset(new_crtc_state))
11888 intel_release_shared_dplls(state, crtc);
11893 * This implements the workaround described in the "notes" section of the mode
11894 * set sequence documentation. When going from no pipes or single pipe to
11895 * multiple pipes, and planes are enabled after the pipe, we need to wait at
11896 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
11898 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
11900 struct intel_crtc_state *crtc_state;
11901 struct intel_crtc *crtc;
11902 struct intel_crtc_state *first_crtc_state = NULL;
11903 struct intel_crtc_state *other_crtc_state = NULL;
11904 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
11907 /* look at all crtc's that are going to be enabled in during modeset */
11908 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
11909 if (!crtc_state->hw.active ||
11910 !intel_crtc_needs_modeset(crtc_state))
11913 if (first_crtc_state) {
11914 other_crtc_state = crtc_state;
11917 first_crtc_state = crtc_state;
11918 first_pipe = crtc->pipe;
11922 /* No workaround needed? */
11923 if (!first_crtc_state)
11926 /* w/a possibly needed, check how many crtc's are already enabled. */
11927 for_each_intel_crtc(state->base.dev, crtc) {
11928 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
11929 if (IS_ERR(crtc_state))
11930 return PTR_ERR(crtc_state);
11932 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
11934 if (!crtc_state->hw.active ||
11935 intel_crtc_needs_modeset(crtc_state))
11938 /* 2 or more enabled crtcs means no need for w/a */
11939 if (enabled_pipe != INVALID_PIPE)
11942 enabled_pipe = crtc->pipe;
11945 if (enabled_pipe != INVALID_PIPE)
11946 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
11947 else if (other_crtc_state)
11948 other_crtc_state->hsw_workaround_pipe = first_pipe;
11953 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
11956 const struct intel_crtc_state *crtc_state;
11957 struct intel_crtc *crtc;
11960 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
11961 if (crtc_state->hw.active)
11962 active_pipes |= BIT(crtc->pipe);
11964 active_pipes &= ~BIT(crtc->pipe);
11967 return active_pipes;
11970 static int intel_modeset_checks(struct intel_atomic_state *state)
11972 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
11974 state->modeset = true;
11976 if (IS_HASWELL(dev_priv))
11977 return hsw_mode_set_planes_workaround(state);
11983 * Handle calculation of various watermark data at the end of the atomic check
11984 * phase. The code here should be run after the per-crtc and per-plane 'check'
11985 * handlers to ensure that all derived state has been updated.
11987 static int calc_watermark_data(struct intel_atomic_state *state)
11989 struct drm_device *dev = state->base.dev;
11990 struct drm_i915_private *dev_priv = to_i915(dev);
11992 /* Is there platform-specific watermark information to calculate? */
11993 if (dev_priv->display.compute_global_watermarks)
11994 return dev_priv->display.compute_global_watermarks(state);
11999 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
12000 struct intel_crtc_state *new_crtc_state)
12002 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
12005 new_crtc_state->uapi.mode_changed = false;
12006 new_crtc_state->update_pipe = true;
12009 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
12010 struct intel_crtc_state *new_crtc_state)
12013 * If we're not doing the full modeset we want to
12014 * keep the current M/N values as they may be
12015 * sufficiently different to the computed values
12016 * to cause problems.
12018 * FIXME: should really copy more fuzzy state here
12020 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
12021 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
12022 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
12023 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
12026 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
12027 struct intel_crtc *crtc,
12030 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12031 struct intel_plane *plane;
12033 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
12034 struct intel_plane_state *plane_state;
12036 if ((plane_ids_mask & BIT(plane->id)) == 0)
12039 plane_state = intel_atomic_get_plane_state(state, plane);
12040 if (IS_ERR(plane_state))
12041 return PTR_ERR(plane_state);
12047 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
12048 struct intel_crtc *crtc)
12050 const struct intel_crtc_state *old_crtc_state =
12051 intel_atomic_get_old_crtc_state(state, crtc);
12052 const struct intel_crtc_state *new_crtc_state =
12053 intel_atomic_get_new_crtc_state(state, crtc);
12055 return intel_crtc_add_planes_to_state(state, crtc,
12056 old_crtc_state->enabled_planes |
12057 new_crtc_state->enabled_planes);
12060 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
12062 /* See {hsw,vlv,ivb}_plane_ratio() */
12063 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
12064 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
12065 IS_IVYBRIDGE(dev_priv) || (INTEL_GEN(dev_priv) >= 11);
12068 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
12069 struct intel_crtc *crtc,
12070 struct intel_crtc *other)
12072 const struct intel_plane_state *plane_state;
12073 struct intel_plane *plane;
12077 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12078 if (plane->pipe == crtc->pipe)
12079 plane_ids |= BIT(plane->id);
12082 return intel_crtc_add_planes_to_state(state, other, plane_ids);
12085 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
12087 const struct intel_crtc_state *crtc_state;
12088 struct intel_crtc *crtc;
12091 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
12094 if (!crtc_state->bigjoiner)
12097 ret = intel_crtc_add_bigjoiner_planes(state, crtc,
12098 crtc_state->bigjoiner_linked_crtc);
12106 static int intel_atomic_check_planes(struct intel_atomic_state *state)
12108 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12109 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
12110 struct intel_plane_state *plane_state;
12111 struct intel_plane *plane;
12112 struct intel_crtc *crtc;
12115 ret = icl_add_linked_planes(state);
12119 ret = intel_bigjoiner_add_affected_planes(state);
12123 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12124 ret = intel_plane_atomic_check(state, plane);
12126 drm_dbg_atomic(&dev_priv->drm,
12127 "[PLANE:%d:%s] atomic driver check failed\n",
12128 plane->base.base.id, plane->base.name);
12133 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12134 new_crtc_state, i) {
12135 u8 old_active_planes, new_active_planes;
12137 ret = icl_check_nv12_planes(new_crtc_state);
12142 * On some platforms the number of active planes affects
12143 * the planes' minimum cdclk calculation. Add such planes
12144 * to the state before we compute the minimum cdclk.
12146 if (!active_planes_affects_min_cdclk(dev_priv))
12149 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
12150 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
12153 * Not only the number of planes, but if the plane configuration had
12154 * changed might already mean we need to recompute min CDCLK,
12155 * because different planes might consume different amount of Dbuf bandwidth
12156 * according to formula: Bw per plane = Pixel rate * bpp * pipe/plane scale factor
12158 if (old_active_planes == new_active_planes)
12161 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
12169 static int intel_atomic_check_cdclk(struct intel_atomic_state *state,
12170 bool *need_cdclk_calc)
12172 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12173 const struct intel_cdclk_state *old_cdclk_state;
12174 const struct intel_cdclk_state *new_cdclk_state;
12175 struct intel_plane_state *plane_state;
12176 struct intel_bw_state *new_bw_state;
12177 struct intel_plane *plane;
12183 * active_planes bitmask has been updated, and potentially
12184 * affected planes are part of the state. We can now
12185 * compute the minimum cdclk for each plane.
12187 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
12188 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
12193 old_cdclk_state = intel_atomic_get_old_cdclk_state(state);
12194 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
12196 if (new_cdclk_state &&
12197 old_cdclk_state->force_min_cdclk != new_cdclk_state->force_min_cdclk)
12198 *need_cdclk_calc = true;
12200 ret = dev_priv->display.bw_calc_min_cdclk(state);
12204 new_bw_state = intel_atomic_get_new_bw_state(state);
12206 if (!new_cdclk_state || !new_bw_state)
12209 for_each_pipe(dev_priv, pipe) {
12210 min_cdclk = max(new_cdclk_state->min_cdclk[pipe], min_cdclk);
12213 * Currently do this change only if we need to increase
12215 if (new_bw_state->min_cdclk > min_cdclk)
12216 *need_cdclk_calc = true;
12222 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
12224 struct intel_crtc_state *crtc_state;
12225 struct intel_crtc *crtc;
12228 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
12229 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
12232 ret = intel_crtc_atomic_check(state, crtc);
12234 drm_dbg_atomic(&i915->drm,
12235 "[CRTC:%d:%s] atomic driver check failed\n",
12236 crtc->base.base.id, crtc->base.name);
12244 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
12247 const struct intel_crtc_state *new_crtc_state;
12248 struct intel_crtc *crtc;
12251 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
12252 if (new_crtc_state->hw.enable &&
12253 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
12254 intel_crtc_needs_modeset(new_crtc_state))
12261 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
12262 struct intel_crtc *crtc,
12263 struct intel_crtc_state *old_crtc_state,
12264 struct intel_crtc_state *new_crtc_state)
12266 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12267 struct intel_crtc_state *slave_crtc_state, *master_crtc_state;
12268 struct intel_crtc *slave, *master;
12270 /* slave being enabled, is master is still claiming this crtc? */
12271 if (old_crtc_state->bigjoiner_slave) {
12273 master = old_crtc_state->bigjoiner_linked_crtc;
12274 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
12275 if (!master_crtc_state || !intel_crtc_needs_modeset(master_crtc_state))
12279 if (!new_crtc_state->bigjoiner)
12282 if (1 + crtc->pipe >= INTEL_NUM_PIPES(dev_priv)) {
12283 DRM_DEBUG_KMS("[CRTC:%d:%s] Big joiner configuration requires "
12284 "CRTC + 1 to be used, doesn't exist\n",
12285 crtc->base.base.id, crtc->base.name);
12289 slave = new_crtc_state->bigjoiner_linked_crtc =
12290 intel_get_crtc_for_pipe(dev_priv, crtc->pipe + 1);
12291 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave);
12293 if (IS_ERR(slave_crtc_state))
12294 return PTR_ERR(slave_crtc_state);
12296 /* master being enabled, slave was already configured? */
12297 if (slave_crtc_state->uapi.enable)
12300 DRM_DEBUG_KMS("[CRTC:%d:%s] Used as slave for big joiner\n",
12301 slave->base.base.id, slave->base.name);
12303 return copy_bigjoiner_crtc_state(slave_crtc_state, new_crtc_state);
12306 DRM_DEBUG_KMS("[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
12307 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
12308 slave->base.base.id, slave->base.name,
12309 master->base.base.id, master->base.name);
12313 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
12314 struct intel_crtc_state *master_crtc_state)
12316 struct intel_crtc_state *slave_crtc_state =
12317 intel_atomic_get_new_crtc_state(state, master_crtc_state->bigjoiner_linked_crtc);
12319 slave_crtc_state->bigjoiner = master_crtc_state->bigjoiner = false;
12320 slave_crtc_state->bigjoiner_slave = master_crtc_state->bigjoiner_slave = false;
12321 slave_crtc_state->bigjoiner_linked_crtc = master_crtc_state->bigjoiner_linked_crtc = NULL;
12322 intel_crtc_copy_uapi_to_hw_state(state, slave_crtc_state);
12326 * DOC: asynchronous flip implementation
12328 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
12329 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
12330 * Correspondingly, support is currently added for primary plane only.
12332 * Async flip can only change the plane surface address, so anything else
12333 * changing is rejected from the intel_atomic_check_async() function.
12334 * Once this check is cleared, flip done interrupt is enabled using
12335 * the intel_crtc_enable_flip_done() function.
12337 * As soon as the surface address register is written, flip done interrupt is
12338 * generated and the requested events are sent to the usersapce in the interrupt
12339 * handler itself. The timestamp and sequence sent during the flip done event
12340 * correspond to the last vblank and have no relation to the actual time when
12341 * the flip done event was sent.
12343 static int intel_atomic_check_async(struct intel_atomic_state *state)
12345 struct drm_i915_private *i915 = to_i915(state->base.dev);
12346 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
12347 const struct intel_plane_state *new_plane_state, *old_plane_state;
12348 struct intel_crtc *crtc;
12349 struct intel_plane *plane;
12352 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12353 new_crtc_state, i) {
12354 if (intel_crtc_needs_modeset(new_crtc_state)) {
12355 drm_dbg_kms(&i915->drm, "Modeset Required. Async flip not supported\n");
12359 if (!new_crtc_state->hw.active) {
12360 drm_dbg_kms(&i915->drm, "CRTC inactive\n");
12363 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
12364 drm_dbg_kms(&i915->drm,
12365 "Active planes cannot be changed during async flip\n");
12370 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
12371 new_plane_state, i) {
12373 * TODO: Async flip is only supported through the page flip IOCTL
12374 * as of now. So support currently added for primary plane only.
12375 * Support for other planes on platforms on which supports
12376 * this(vlv/chv and icl+) should be added when async flip is
12377 * enabled in the atomic IOCTL path.
12379 if (!plane->async_flip)
12383 * FIXME: This check is kept generic for all platforms.
12384 * Need to verify this for all gen9 and gen10 platforms to enable
12385 * this selectively if required.
12387 switch (new_plane_state->hw.fb->modifier) {
12388 case I915_FORMAT_MOD_X_TILED:
12389 case I915_FORMAT_MOD_Y_TILED:
12390 case I915_FORMAT_MOD_Yf_TILED:
12393 drm_dbg_kms(&i915->drm,
12394 "Linear memory/CCS does not support async flips\n");
12398 if (old_plane_state->color_plane[0].stride !=
12399 new_plane_state->color_plane[0].stride) {
12400 drm_dbg_kms(&i915->drm, "Stride cannot be changed in async flip\n");
12404 if (old_plane_state->hw.fb->modifier !=
12405 new_plane_state->hw.fb->modifier) {
12406 drm_dbg_kms(&i915->drm,
12407 "Framebuffer modifiers cannot be changed in async flip\n");
12411 if (old_plane_state->hw.fb->format !=
12412 new_plane_state->hw.fb->format) {
12413 drm_dbg_kms(&i915->drm,
12414 "Framebuffer format cannot be changed in async flip\n");
12418 if (old_plane_state->hw.rotation !=
12419 new_plane_state->hw.rotation) {
12420 drm_dbg_kms(&i915->drm, "Rotation cannot be changed in async flip\n");
12424 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
12425 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
12426 drm_dbg_kms(&i915->drm,
12427 "Plane size/co-ordinates cannot be changed in async flip\n");
12431 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
12432 drm_dbg_kms(&i915->drm, "Alpha value cannot be changed in async flip\n");
12436 if (old_plane_state->hw.pixel_blend_mode !=
12437 new_plane_state->hw.pixel_blend_mode) {
12438 drm_dbg_kms(&i915->drm,
12439 "Pixel blend mode cannot be changed in async flip\n");
12443 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
12444 drm_dbg_kms(&i915->drm,
12445 "Color encoding cannot be changed in async flip\n");
12449 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
12450 drm_dbg_kms(&i915->drm, "Color range cannot be changed in async flip\n");
12458 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
12460 struct intel_crtc_state *crtc_state;
12461 struct intel_crtc *crtc;
12464 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
12465 struct intel_crtc_state *linked_crtc_state;
12466 struct intel_crtc *linked_crtc;
12469 if (!crtc_state->bigjoiner)
12472 linked_crtc = crtc_state->bigjoiner_linked_crtc;
12473 linked_crtc_state = intel_atomic_get_crtc_state(&state->base, linked_crtc);
12474 if (IS_ERR(linked_crtc_state))
12475 return PTR_ERR(linked_crtc_state);
12477 if (!intel_crtc_needs_modeset(crtc_state))
12480 linked_crtc_state->uapi.mode_changed = true;
12482 ret = drm_atomic_add_affected_connectors(&state->base,
12483 &linked_crtc->base);
12487 ret = intel_atomic_add_affected_planes(state, linked_crtc);
12492 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
12493 /* Kill old bigjoiner link, we may re-establish afterwards */
12494 if (intel_crtc_needs_modeset(crtc_state) &&
12495 crtc_state->bigjoiner && !crtc_state->bigjoiner_slave)
12496 kill_bigjoiner_slave(state, crtc_state);
12503 * intel_atomic_check - validate state object
12505 * @_state: state to validate
12507 static int intel_atomic_check(struct drm_device *dev,
12508 struct drm_atomic_state *_state)
12510 struct drm_i915_private *dev_priv = to_i915(dev);
12511 struct intel_atomic_state *state = to_intel_atomic_state(_state);
12512 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
12513 struct intel_crtc *crtc;
12515 bool any_ms = false;
12517 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12518 new_crtc_state, i) {
12519 if (new_crtc_state->inherited != old_crtc_state->inherited)
12520 new_crtc_state->uapi.mode_changed = true;
12523 intel_vrr_check_modeset(state);
12525 ret = drm_atomic_helper_check_modeset(dev, &state->base);
12529 ret = intel_bigjoiner_add_affected_crtcs(state);
12533 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12534 new_crtc_state, i) {
12535 if (!intel_crtc_needs_modeset(new_crtc_state)) {
12537 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, new_crtc_state);
12542 if (!new_crtc_state->uapi.enable) {
12543 if (!new_crtc_state->bigjoiner_slave) {
12544 intel_crtc_copy_uapi_to_hw_state(state, new_crtc_state);
12550 ret = intel_crtc_prepare_cleared_state(state, new_crtc_state);
12554 ret = intel_modeset_pipe_config(state, new_crtc_state);
12558 ret = intel_atomic_check_bigjoiner(state, crtc, old_crtc_state,
12564 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12565 new_crtc_state, i) {
12566 if (!intel_crtc_needs_modeset(new_crtc_state))
12569 ret = intel_modeset_pipe_config_late(new_crtc_state);
12573 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
12577 * Check if fastset is allowed by external dependencies like other
12578 * pipes and transcoders.
12580 * Right now it only forces a fullmodeset when the MST master
12581 * transcoder did not changed but the pipe of the master transcoder
12582 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
12583 * in case of port synced crtcs, if one of the synced crtcs
12584 * needs a full modeset, all other synced crtcs should be
12585 * forced a full modeset.
12587 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
12588 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
12591 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
12592 enum transcoder master = new_crtc_state->mst_master_transcoder;
12594 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
12595 new_crtc_state->uapi.mode_changed = true;
12596 new_crtc_state->update_pipe = false;
12600 if (is_trans_port_sync_mode(new_crtc_state)) {
12601 u8 trans = new_crtc_state->sync_mode_slaves_mask;
12603 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
12604 trans |= BIT(new_crtc_state->master_transcoder);
12606 if (intel_cpu_transcoders_need_modeset(state, trans)) {
12607 new_crtc_state->uapi.mode_changed = true;
12608 new_crtc_state->update_pipe = false;
12612 if (new_crtc_state->bigjoiner) {
12613 struct intel_crtc_state *linked_crtc_state =
12614 intel_atomic_get_new_crtc_state(state, new_crtc_state->bigjoiner_linked_crtc);
12616 if (intel_crtc_needs_modeset(linked_crtc_state)) {
12617 new_crtc_state->uapi.mode_changed = true;
12618 new_crtc_state->update_pipe = false;
12623 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12624 new_crtc_state, i) {
12625 if (intel_crtc_needs_modeset(new_crtc_state)) {
12630 if (!new_crtc_state->update_pipe)
12633 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
12636 if (any_ms && !check_digital_port_conflicts(state)) {
12637 drm_dbg_kms(&dev_priv->drm,
12638 "rejecting conflicting digital port configuration\n");
12643 ret = drm_dp_mst_atomic_check(&state->base);
12647 ret = intel_atomic_check_planes(state);
12651 intel_fbc_choose_crtc(dev_priv, state);
12652 ret = calc_watermark_data(state);
12656 ret = intel_bw_atomic_check(state);
12660 ret = intel_atomic_check_cdclk(state, &any_ms);
12665 ret = intel_modeset_checks(state);
12669 ret = intel_modeset_calc_cdclk(state);
12673 intel_modeset_clear_plls(state);
12676 ret = intel_atomic_check_crtcs(state);
12680 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12681 new_crtc_state, i) {
12682 if (new_crtc_state->uapi.async_flip) {
12683 ret = intel_atomic_check_async(state);
12688 if (!intel_crtc_needs_modeset(new_crtc_state) &&
12689 !new_crtc_state->update_pipe)
12692 intel_dump_pipe_config(new_crtc_state, state,
12693 intel_crtc_needs_modeset(new_crtc_state) ?
12694 "[modeset]" : "[fastset]");
12700 if (ret == -EDEADLK)
12704 * FIXME would probably be nice to know which crtc specifically
12705 * caused the failure, in cases where we can pinpoint it.
12707 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12709 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
12714 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
12716 struct intel_crtc_state *crtc_state;
12717 struct intel_crtc *crtc;
12720 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
12724 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
12725 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
12727 if (mode_changed || crtc_state->update_pipe ||
12728 crtc_state->uapi.color_mgmt_changed) {
12729 intel_dsb_prepare(crtc_state);
12736 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
12737 struct intel_crtc_state *crtc_state)
12739 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12741 if (!IS_GEN(dev_priv, 2) || crtc_state->active_planes)
12742 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
12744 if (crtc_state->has_pch_encoder) {
12745 enum pipe pch_transcoder =
12746 intel_crtc_pch_transcoder(crtc);
12748 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
12752 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
12753 const struct intel_crtc_state *new_crtc_state)
12755 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
12756 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12759 * Update pipe size and adjust fitter if needed: the reason for this is
12760 * that in compute_mode_changes we check the native mode (not the pfit
12761 * mode) to see if we can flip rather than do a full mode set. In the
12762 * fastboot case, we'll flip, but if we don't update the pipesrc and
12763 * pfit state, we'll end up with a big fb scanned out into the wrong
12766 intel_set_pipe_src_size(new_crtc_state);
12768 /* on skylake this is done by detaching scalers */
12769 if (INTEL_GEN(dev_priv) >= 9) {
12770 skl_detach_scalers(new_crtc_state);
12772 if (new_crtc_state->pch_pfit.enabled)
12773 skl_pfit_enable(new_crtc_state);
12774 } else if (HAS_PCH_SPLIT(dev_priv)) {
12775 if (new_crtc_state->pch_pfit.enabled)
12776 ilk_pfit_enable(new_crtc_state);
12777 else if (old_crtc_state->pch_pfit.enabled)
12778 ilk_pfit_disable(old_crtc_state);
12782 * The register is supposedly single buffered so perhaps
12783 * not 100% correct to do this here. But SKL+ calculate
12784 * this based on the adjust pixel rate so pfit changes do
12785 * affect it and so it must be updated for fastsets.
12786 * HSW/BDW only really need this here for fastboot, after
12787 * that the value should not change without a full modeset.
12789 if (INTEL_GEN(dev_priv) >= 9 ||
12790 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
12791 hsw_set_linetime_wm(new_crtc_state);
12793 if (INTEL_GEN(dev_priv) >= 11)
12794 icl_set_pipe_chicken(crtc);
12797 static void commit_pipe_config(struct intel_atomic_state *state,
12798 struct intel_crtc *crtc)
12800 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12801 const struct intel_crtc_state *old_crtc_state =
12802 intel_atomic_get_old_crtc_state(state, crtc);
12803 const struct intel_crtc_state *new_crtc_state =
12804 intel_atomic_get_new_crtc_state(state, crtc);
12805 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
12808 * During modesets pipe configuration was programmed as the
12809 * CRTC was enabled.
12812 if (new_crtc_state->uapi.color_mgmt_changed ||
12813 new_crtc_state->update_pipe)
12814 intel_color_commit(new_crtc_state);
12816 if (INTEL_GEN(dev_priv) >= 9)
12817 skl_detach_scalers(new_crtc_state);
12819 if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
12820 bdw_set_pipemisc(new_crtc_state);
12822 if (new_crtc_state->update_pipe)
12823 intel_pipe_fastset(old_crtc_state, new_crtc_state);
12825 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
12828 if (dev_priv->display.atomic_update_watermarks)
12829 dev_priv->display.atomic_update_watermarks(state, crtc);
12832 static void intel_enable_crtc(struct intel_atomic_state *state,
12833 struct intel_crtc *crtc)
12835 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12836 const struct intel_crtc_state *new_crtc_state =
12837 intel_atomic_get_new_crtc_state(state, crtc);
12839 if (!intel_crtc_needs_modeset(new_crtc_state))
12842 intel_crtc_update_active_timings(new_crtc_state);
12844 dev_priv->display.crtc_enable(state, crtc);
12846 if (new_crtc_state->bigjoiner_slave)
12849 /* vblanks work again, re-enable pipe CRC. */
12850 intel_crtc_enable_pipe_crc(crtc);
12853 static void intel_update_crtc(struct intel_atomic_state *state,
12854 struct intel_crtc *crtc)
12856 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12857 const struct intel_crtc_state *old_crtc_state =
12858 intel_atomic_get_old_crtc_state(state, crtc);
12859 struct intel_crtc_state *new_crtc_state =
12860 intel_atomic_get_new_crtc_state(state, crtc);
12861 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
12864 if (new_crtc_state->preload_luts &&
12865 (new_crtc_state->uapi.color_mgmt_changed ||
12866 new_crtc_state->update_pipe))
12867 intel_color_load_luts(new_crtc_state);
12869 intel_pre_plane_update(state, crtc);
12871 if (new_crtc_state->update_pipe)
12872 intel_encoders_update_pipe(state, crtc);
12875 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
12876 intel_fbc_disable(crtc);
12878 intel_fbc_enable(state, crtc);
12880 /* Perform vblank evasion around commit operation */
12881 intel_pipe_update_start(new_crtc_state);
12883 commit_pipe_config(state, crtc);
12885 if (INTEL_GEN(dev_priv) >= 9)
12886 skl_update_planes_on_crtc(state, crtc);
12888 i9xx_update_planes_on_crtc(state, crtc);
12890 intel_pipe_update_end(new_crtc_state);
12893 * We usually enable FIFO underrun interrupts as part of the
12894 * CRTC enable sequence during modesets. But when we inherit a
12895 * valid pipe configuration from the BIOS we need to take care
12896 * of enabling them on the CRTC's first fastset.
12898 if (new_crtc_state->update_pipe && !modeset &&
12899 old_crtc_state->inherited)
12900 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
12903 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
12904 struct intel_crtc_state *old_crtc_state,
12905 struct intel_crtc_state *new_crtc_state,
12906 struct intel_crtc *crtc)
12908 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
12910 drm_WARN_ON(&dev_priv->drm, old_crtc_state->bigjoiner_slave);
12912 intel_crtc_disable_planes(state, crtc);
12915 * We still need special handling for disabling bigjoiner master
12916 * and slaves since for slave we do not have encoder or plls
12917 * so we dont need to disable those.
12919 if (old_crtc_state->bigjoiner) {
12920 intel_crtc_disable_planes(state,
12921 old_crtc_state->bigjoiner_linked_crtc);
12922 old_crtc_state->bigjoiner_linked_crtc->active = false;
12926 * We need to disable pipe CRC before disabling the pipe,
12927 * or we race against vblank off.
12929 intel_crtc_disable_pipe_crc(crtc);
12931 dev_priv->display.crtc_disable(state, crtc);
12932 crtc->active = false;
12933 intel_fbc_disable(crtc);
12934 intel_disable_shared_dpll(old_crtc_state);
12936 /* FIXME unify this for all platforms */
12937 if (!new_crtc_state->hw.active &&
12938 !HAS_GMCH(dev_priv) &&
12939 dev_priv->display.initial_watermarks)
12940 dev_priv->display.initial_watermarks(state, crtc);
12943 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
12945 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
12946 struct intel_crtc *crtc;
12950 /* Only disable port sync and MST slaves */
12951 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12952 new_crtc_state, i) {
12953 if (!intel_crtc_needs_modeset(new_crtc_state) || old_crtc_state->bigjoiner)
12956 if (!old_crtc_state->hw.active)
12959 /* In case of Transcoder port Sync master slave CRTCs can be
12960 * assigned in any order and we need to make sure that
12961 * slave CRTCs are disabled first and then master CRTC since
12962 * Slave vblanks are masked till Master Vblanks.
12964 if (!is_trans_port_sync_slave(old_crtc_state) &&
12965 !intel_dp_mst_is_slave_trans(old_crtc_state))
12968 intel_pre_plane_update(state, crtc);
12969 intel_old_crtc_state_disables(state, old_crtc_state,
12970 new_crtc_state, crtc);
12971 handled |= BIT(crtc->pipe);
12974 /* Disable everything else left on */
12975 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
12976 new_crtc_state, i) {
12977 if (!intel_crtc_needs_modeset(new_crtc_state) ||
12978 (handled & BIT(crtc->pipe)) ||
12979 old_crtc_state->bigjoiner_slave)
12982 intel_pre_plane_update(state, crtc);
12983 if (old_crtc_state->bigjoiner) {
12984 struct intel_crtc *slave =
12985 old_crtc_state->bigjoiner_linked_crtc;
12987 intel_pre_plane_update(state, slave);
12990 if (old_crtc_state->hw.active)
12991 intel_old_crtc_state_disables(state, old_crtc_state,
12992 new_crtc_state, crtc);
12996 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
12998 struct intel_crtc_state *new_crtc_state;
12999 struct intel_crtc *crtc;
13002 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13003 if (!new_crtc_state->hw.active)
13006 intel_enable_crtc(state, crtc);
13007 intel_update_crtc(state, crtc);
13011 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
13013 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
13014 struct intel_crtc *crtc;
13015 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13016 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
13017 u8 update_pipes = 0, modeset_pipes = 0;
13020 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13021 enum pipe pipe = crtc->pipe;
13023 if (!new_crtc_state->hw.active)
13026 /* ignore allocations for crtc's that have been turned off. */
13027 if (!intel_crtc_needs_modeset(new_crtc_state)) {
13028 entries[pipe] = old_crtc_state->wm.skl.ddb;
13029 update_pipes |= BIT(pipe);
13031 modeset_pipes |= BIT(pipe);
13036 * Whenever the number of active pipes changes, we need to make sure we
13037 * update the pipes in the right order so that their ddb allocations
13038 * never overlap with each other between CRTC updates. Otherwise we'll
13039 * cause pipe underruns and other bad stuff.
13041 * So first lets enable all pipes that do not need a fullmodeset as
13042 * those don't have any external dependency.
13044 while (update_pipes) {
13045 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13046 new_crtc_state, i) {
13047 enum pipe pipe = crtc->pipe;
13049 if ((update_pipes & BIT(pipe)) == 0)
13052 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
13053 entries, I915_MAX_PIPES, pipe))
13056 entries[pipe] = new_crtc_state->wm.skl.ddb;
13057 update_pipes &= ~BIT(pipe);
13059 intel_update_crtc(state, crtc);
13062 * If this is an already active pipe, it's DDB changed,
13063 * and this isn't the last pipe that needs updating
13064 * then we need to wait for a vblank to pass for the
13065 * new ddb allocation to take effect.
13067 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
13068 &old_crtc_state->wm.skl.ddb) &&
13069 (update_pipes | modeset_pipes))
13070 intel_wait_for_vblank(dev_priv, pipe);
13074 update_pipes = modeset_pipes;
13077 * Enable all pipes that needs a modeset and do not depends on other
13080 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13081 enum pipe pipe = crtc->pipe;
13083 if ((modeset_pipes & BIT(pipe)) == 0)
13086 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
13087 is_trans_port_sync_master(new_crtc_state) ||
13088 (new_crtc_state->bigjoiner && !new_crtc_state->bigjoiner_slave))
13091 modeset_pipes &= ~BIT(pipe);
13093 intel_enable_crtc(state, crtc);
13097 * Then we enable all remaining pipes that depend on other
13098 * pipes: MST slaves and port sync masters, big joiner master
13100 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13101 enum pipe pipe = crtc->pipe;
13103 if ((modeset_pipes & BIT(pipe)) == 0)
13106 modeset_pipes &= ~BIT(pipe);
13108 intel_enable_crtc(state, crtc);
13112 * Finally we do the plane updates/etc. for all pipes that got enabled.
13114 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13115 enum pipe pipe = crtc->pipe;
13117 if ((update_pipes & BIT(pipe)) == 0)
13120 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
13121 entries, I915_MAX_PIPES, pipe));
13123 entries[pipe] = new_crtc_state->wm.skl.ddb;
13124 update_pipes &= ~BIT(pipe);
13126 intel_update_crtc(state, crtc);
13129 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
13130 drm_WARN_ON(&dev_priv->drm, update_pipes);
13133 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13135 struct intel_atomic_state *state, *next;
13136 struct llist_node *freed;
13138 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13139 llist_for_each_entry_safe(state, next, freed, freed)
13140 drm_atomic_state_put(&state->base);
13143 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13145 struct drm_i915_private *dev_priv =
13146 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13148 intel_atomic_helper_free_state(dev_priv);
13151 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13153 struct wait_queue_entry wait_fence, wait_reset;
13154 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13156 init_wait_entry(&wait_fence, 0);
13157 init_wait_entry(&wait_reset, 0);
13159 prepare_to_wait(&intel_state->commit_ready.wait,
13160 &wait_fence, TASK_UNINTERRUPTIBLE);
13161 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13162 I915_RESET_MODESET),
13163 &wait_reset, TASK_UNINTERRUPTIBLE);
13166 if (i915_sw_fence_done(&intel_state->commit_ready) ||
13167 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
13172 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13173 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
13174 I915_RESET_MODESET),
13178 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
13180 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
13181 struct intel_crtc *crtc;
13184 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13186 intel_dsb_cleanup(old_crtc_state);
13189 static void intel_atomic_cleanup_work(struct work_struct *work)
13191 struct intel_atomic_state *state =
13192 container_of(work, struct intel_atomic_state, base.commit_work);
13193 struct drm_i915_private *i915 = to_i915(state->base.dev);
13195 intel_cleanup_dsbs(state);
13196 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
13197 drm_atomic_helper_commit_cleanup_done(&state->base);
13198 drm_atomic_state_put(&state->base);
13200 intel_atomic_helper_free_state(i915);
13203 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
13205 struct drm_i915_private *i915 = to_i915(state->base.dev);
13206 struct intel_plane *plane;
13207 struct intel_plane_state *plane_state;
13210 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
13211 struct drm_framebuffer *fb = plane_state->hw.fb;
13215 fb->modifier != I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC)
13219 * The layout of the fast clear color value expected by HW
13220 * (the DRM ABI requiring this value to be located in fb at offset 0 of plane#2):
13221 * - 4 x 4 bytes per-channel value
13222 * (in surface type specific float/int format provided by the fb user)
13223 * - 8 bytes native color value used by the display
13224 * (converted/written by GPU during a fast clear operation using the
13225 * above per-channel values)
13227 * The commit's FB prepare hook already ensured that FB obj is pinned and the
13228 * caller made sure that the object is synced wrt. the related color clear value
13231 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
13232 fb->offsets[2] + 16,
13233 &plane_state->ccval,
13234 sizeof(plane_state->ccval));
13235 /* The above could only fail if the FB obj has an unexpected backing store type. */
13236 drm_WARN_ON(&i915->drm, ret);
13240 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
13242 struct drm_device *dev = state->base.dev;
13243 struct drm_i915_private *dev_priv = to_i915(dev);
13244 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
13245 struct intel_crtc *crtc;
13246 u64 put_domains[I915_MAX_PIPES] = {};
13247 intel_wakeref_t wakeref = 0;
13250 intel_atomic_commit_fence_wait(state);
13252 drm_atomic_helper_wait_for_dependencies(&state->base);
13254 if (state->modeset)
13255 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
13257 intel_atomic_prepare_plane_clear_colors(state);
13259 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13260 new_crtc_state, i) {
13261 if (intel_crtc_needs_modeset(new_crtc_state) ||
13262 new_crtc_state->update_pipe) {
13264 put_domains[crtc->pipe] =
13265 modeset_get_crtc_power_domains(new_crtc_state);
13269 intel_commit_modeset_disables(state);
13271 /* FIXME: Eventually get rid of our crtc->config pointer */
13272 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13273 crtc->config = new_crtc_state;
13275 if (state->modeset) {
13276 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
13278 intel_set_cdclk_pre_plane_update(state);
13280 intel_modeset_verify_disabled(dev_priv, state);
13283 intel_sagv_pre_plane_update(state);
13285 /* Complete the events for pipes that have now been disabled */
13286 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13287 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
13289 /* Complete events for now disable pipes here. */
13290 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
13291 spin_lock_irq(&dev->event_lock);
13292 drm_crtc_send_vblank_event(&crtc->base,
13293 new_crtc_state->uapi.event);
13294 spin_unlock_irq(&dev->event_lock);
13296 new_crtc_state->uapi.event = NULL;
13300 if (state->modeset)
13301 intel_encoders_update_prepare(state);
13303 intel_dbuf_pre_plane_update(state);
13305 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13306 if (new_crtc_state->uapi.async_flip)
13307 intel_crtc_enable_flip_done(state, crtc);
13310 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
13311 dev_priv->display.commit_modeset_enables(state);
13313 if (state->modeset) {
13314 intel_encoders_update_complete(state);
13316 intel_set_cdclk_post_plane_update(state);
13319 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13320 * already, but still need the state for the delayed optimization. To
13322 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13323 * - schedule that vblank worker _before_ calling hw_done
13324 * - at the start of commit_tail, cancel it _synchrously
13325 * - switch over to the vblank wait helper in the core after that since
13326 * we don't need out special handling any more.
13328 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
13330 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
13331 if (new_crtc_state->uapi.async_flip)
13332 intel_crtc_disable_flip_done(state, crtc);
13334 if (new_crtc_state->hw.active &&
13335 !intel_crtc_needs_modeset(new_crtc_state) &&
13336 !new_crtc_state->preload_luts &&
13337 (new_crtc_state->uapi.color_mgmt_changed ||
13338 new_crtc_state->update_pipe))
13339 intel_color_load_luts(new_crtc_state);
13343 * Now that the vblank has passed, we can go ahead and program the
13344 * optimal watermarks on platforms that need two-step watermark
13347 * TODO: Move this (and other cleanup) to an async worker eventually.
13349 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
13350 new_crtc_state, i) {
13352 * Gen2 reports pipe underruns whenever all planes are disabled.
13353 * So re-enable underrun reporting after some planes get enabled.
13355 * We do this before .optimize_watermarks() so that we have a
13356 * chance of catching underruns with the intermediate watermarks
13357 * vs. the new plane configuration.
13359 if (IS_GEN(dev_priv, 2) && planes_enabling(old_crtc_state, new_crtc_state))
13360 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13362 if (dev_priv->display.optimize_watermarks)
13363 dev_priv->display.optimize_watermarks(state, crtc);
13366 intel_dbuf_post_plane_update(state);
13368 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13369 intel_post_plane_update(state, crtc);
13371 modeset_put_crtc_power_domains(crtc, put_domains[crtc->pipe]);
13373 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
13376 * DSB cleanup is done in cleanup_work aligning with framebuffer
13377 * cleanup. So copy and reset the dsb structure to sync with
13378 * commit_done and later do dsb cleanup in cleanup_work.
13380 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
13383 /* Underruns don't always raise interrupts, so check manually */
13384 intel_check_cpu_fifo_underruns(dev_priv);
13385 intel_check_pch_fifo_underruns(dev_priv);
13387 if (state->modeset)
13388 intel_verify_planes(state);
13390 intel_sagv_post_plane_update(state);
13392 drm_atomic_helper_commit_hw_done(&state->base);
13394 if (state->modeset) {
13395 /* As one of the primary mmio accessors, KMS has a high
13396 * likelihood of triggering bugs in unclaimed access. After we
13397 * finish modesetting, see if an error has been flagged, and if
13398 * so enable debugging for the next modeset - and hope we catch
13401 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
13402 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
13404 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
13407 * Defer the cleanup of the old state to a separate worker to not
13408 * impede the current task (userspace for blocking modesets) that
13409 * are executed inline. For out-of-line asynchronous modesets/flips,
13410 * deferring to a new worker seems overkill, but we would place a
13411 * schedule point (cond_resched()) here anyway to keep latencies
13414 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
13415 queue_work(system_highpri_wq, &state->base.commit_work);
13418 static void intel_atomic_commit_work(struct work_struct *work)
13420 struct intel_atomic_state *state =
13421 container_of(work, struct intel_atomic_state, base.commit_work);
13423 intel_atomic_commit_tail(state);
13426 static int __i915_sw_fence_call
13427 intel_atomic_commit_ready(struct i915_sw_fence *fence,
13428 enum i915_sw_fence_notify notify)
13430 struct intel_atomic_state *state =
13431 container_of(fence, struct intel_atomic_state, commit_ready);
13434 case FENCE_COMPLETE:
13435 /* we do blocking waits in the worker, nothing to do here */
13439 struct intel_atomic_helper *helper =
13440 &to_i915(state->base.dev)->atomic_helper;
13442 if (llist_add(&state->freed, &helper->free_list))
13443 schedule_work(&helper->free_work);
13448 return NOTIFY_DONE;
13451 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
13453 struct intel_plane_state *old_plane_state, *new_plane_state;
13454 struct intel_plane *plane;
13457 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
13458 new_plane_state, i)
13459 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
13460 to_intel_frontbuffer(new_plane_state->hw.fb),
13461 plane->frontbuffer_bit);
13464 static int intel_atomic_commit(struct drm_device *dev,
13465 struct drm_atomic_state *_state,
13468 struct intel_atomic_state *state = to_intel_atomic_state(_state);
13469 struct drm_i915_private *dev_priv = to_i915(dev);
13472 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
13474 drm_atomic_state_get(&state->base);
13475 i915_sw_fence_init(&state->commit_ready,
13476 intel_atomic_commit_ready);
13479 * The intel_legacy_cursor_update() fast path takes care
13480 * of avoiding the vblank waits for simple cursor
13481 * movement and flips. For cursor on/off and size changes,
13482 * we want to perform the vblank waits so that watermark
13483 * updates happen during the correct frames. Gen9+ have
13484 * double buffered watermarks and so shouldn't need this.
13486 * Unset state->legacy_cursor_update before the call to
13487 * drm_atomic_helper_setup_commit() because otherwise
13488 * drm_atomic_helper_wait_for_flip_done() is a noop and
13489 * we get FIFO underruns because we didn't wait
13492 * FIXME doing watermarks and fb cleanup from a vblank worker
13493 * (assuming we had any) would solve these problems.
13495 if (INTEL_GEN(dev_priv) < 9 && state->base.legacy_cursor_update) {
13496 struct intel_crtc_state *new_crtc_state;
13497 struct intel_crtc *crtc;
13500 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13501 if (new_crtc_state->wm.need_postvbl_update ||
13502 new_crtc_state->update_wm_post)
13503 state->base.legacy_cursor_update = false;
13506 ret = intel_atomic_prepare_commit(state);
13508 drm_dbg_atomic(&dev_priv->drm,
13509 "Preparing state failed with %i\n", ret);
13510 i915_sw_fence_commit(&state->commit_ready);
13511 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
13515 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
13517 ret = drm_atomic_helper_swap_state(&state->base, true);
13519 intel_atomic_swap_global_state(state);
13522 struct intel_crtc_state *new_crtc_state;
13523 struct intel_crtc *crtc;
13526 i915_sw_fence_commit(&state->commit_ready);
13528 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
13529 intel_dsb_cleanup(new_crtc_state);
13531 drm_atomic_helper_cleanup_planes(dev, &state->base);
13532 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
13535 intel_shared_dpll_swap_state(state);
13536 intel_atomic_track_fbs(state);
13538 drm_atomic_state_get(&state->base);
13539 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
13541 i915_sw_fence_commit(&state->commit_ready);
13542 if (nonblock && state->modeset) {
13543 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
13544 } else if (nonblock) {
13545 queue_work(dev_priv->flip_wq, &state->base.commit_work);
13547 if (state->modeset)
13548 flush_workqueue(dev_priv->modeset_wq);
13549 intel_atomic_commit_tail(state);
13555 struct wait_rps_boost {
13556 struct wait_queue_entry wait;
13558 struct drm_crtc *crtc;
13559 struct i915_request *request;
13562 static int do_rps_boost(struct wait_queue_entry *_wait,
13563 unsigned mode, int sync, void *key)
13565 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
13566 struct i915_request *rq = wait->request;
13569 * If we missed the vblank, but the request is already running it
13570 * is reasonable to assume that it will complete before the next
13571 * vblank without our intervention, so leave RPS alone.
13573 if (!i915_request_started(rq))
13574 intel_rps_boost(rq);
13575 i915_request_put(rq);
13577 drm_crtc_vblank_put(wait->crtc);
13579 list_del(&wait->wait.entry);
13584 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13585 struct dma_fence *fence)
13587 struct wait_rps_boost *wait;
13589 if (!dma_fence_is_i915(fence))
13592 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13595 if (drm_crtc_vblank_get(crtc))
13598 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13600 drm_crtc_vblank_put(crtc);
13604 wait->request = to_request(dma_fence_get(fence));
13607 wait->wait.func = do_rps_boost;
13608 wait->wait.flags = 0;
13610 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13613 int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13615 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
13616 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13617 struct drm_framebuffer *fb = plane_state->hw.fb;
13618 struct i915_vma *vma;
13620 if (plane->id == PLANE_CURSOR &&
13621 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
13622 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13623 const int align = intel_cursor_alignment(dev_priv);
13626 err = i915_gem_object_attach_phys(obj, align);
13631 vma = intel_pin_and_fence_fb_obj(fb,
13632 &plane_state->view,
13633 intel_plane_uses_fence(plane_state),
13634 &plane_state->flags);
13636 return PTR_ERR(vma);
13638 plane_state->vma = vma;
13643 void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13645 struct i915_vma *vma;
13647 vma = fetch_and_zero(&old_plane_state->vma);
13649 intel_unpin_fb_vma(vma, old_plane_state->flags);
13652 static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13654 struct i915_sched_attr attr = {
13655 .priority = I915_USER_PRIORITY(I915_PRIORITY_DISPLAY),
13658 i915_gem_object_wait_priority(obj, 0, &attr);
13662 * intel_prepare_plane_fb - Prepare fb for usage on plane
13663 * @_plane: drm plane to prepare for
13664 * @_new_plane_state: the plane state being prepared
13666 * Prepares a framebuffer for usage on a display plane. Generally this
13667 * involves pinning the underlying object and updating the frontbuffer tracking
13668 * bits. Some older platforms need special physical address handling for
13671 * Returns 0 on success, negative error code on failure.
13674 intel_prepare_plane_fb(struct drm_plane *_plane,
13675 struct drm_plane_state *_new_plane_state)
13677 struct intel_plane *plane = to_intel_plane(_plane);
13678 struct intel_plane_state *new_plane_state =
13679 to_intel_plane_state(_new_plane_state);
13680 struct intel_atomic_state *state =
13681 to_intel_atomic_state(new_plane_state->uapi.state);
13682 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13683 const struct intel_plane_state *old_plane_state =
13684 intel_atomic_get_old_plane_state(state, plane);
13685 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
13686 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
13690 const struct intel_crtc_state *crtc_state =
13691 intel_atomic_get_new_crtc_state(state,
13692 to_intel_crtc(old_plane_state->hw.crtc));
13694 /* Big Hammer, we also need to ensure that any pending
13695 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13696 * current scanout is retired before unpinning the old
13697 * framebuffer. Note that we rely on userspace rendering
13698 * into the buffer attached to the pipe they are waiting
13699 * on. If not, userspace generates a GPU hang with IPEHR
13700 * point to the MI_WAIT_FOR_EVENT.
13702 * This should only fail upon a hung GPU, in which case we
13703 * can safely continue.
13705 if (intel_crtc_needs_modeset(crtc_state)) {
13706 ret = i915_sw_fence_await_reservation(&state->commit_ready,
13707 old_obj->base.resv, NULL,
13715 if (new_plane_state->uapi.fence) { /* explicit fencing */
13716 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
13717 new_plane_state->uapi.fence,
13718 i915_fence_timeout(dev_priv),
13727 ret = i915_gem_object_pin_pages(obj);
13731 ret = intel_plane_pin_fb(new_plane_state);
13733 i915_gem_object_unpin_pages(obj);
13737 fb_obj_bump_render_priority(obj);
13738 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
13740 if (!new_plane_state->uapi.fence) { /* implicit fencing */
13741 struct dma_fence *fence;
13743 ret = i915_sw_fence_await_reservation(&state->commit_ready,
13744 obj->base.resv, NULL,
13746 i915_fence_timeout(dev_priv),
13751 fence = dma_resv_get_excl_rcu(obj->base.resv);
13753 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
13755 dma_fence_put(fence);
13758 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
13759 new_plane_state->uapi.fence);
13763 * We declare pageflips to be interactive and so merit a small bias
13764 * towards upclocking to deliver the frame on time. By only changing
13765 * the RPS thresholds to sample more regularly and aim for higher
13766 * clocks we can hopefully deliver low power workloads (like kodi)
13767 * that are not quite steady state without resorting to forcing
13768 * maximum clocks following a vblank miss (see do_rps_boost()).
13770 if (!state->rps_interactive) {
13771 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
13772 state->rps_interactive = true;
13778 intel_plane_unpin_fb(new_plane_state);
13784 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13785 * @plane: drm plane to clean up for
13786 * @_old_plane_state: the state from the previous modeset
13788 * Cleans up a framebuffer that has just been removed from a plane.
13791 intel_cleanup_plane_fb(struct drm_plane *plane,
13792 struct drm_plane_state *_old_plane_state)
13794 struct intel_plane_state *old_plane_state =
13795 to_intel_plane_state(_old_plane_state);
13796 struct intel_atomic_state *state =
13797 to_intel_atomic_state(old_plane_state->uapi.state);
13798 struct drm_i915_private *dev_priv = to_i915(plane->dev);
13799 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
13804 if (state->rps_interactive) {
13805 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
13806 state->rps_interactive = false;
13809 /* Should only be called after a successful intel_prepare_plane_fb()! */
13810 intel_plane_unpin_fb(old_plane_state);
13814 * intel_plane_destroy - destroy a plane
13815 * @plane: plane to destroy
13817 * Common destruction function for all types of planes (primary, cursor,
13820 void intel_plane_destroy(struct drm_plane *plane)
13822 drm_plane_cleanup(plane);
13823 kfree(to_intel_plane(plane));
13826 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
13828 struct intel_plane *plane;
13830 for_each_intel_plane(&dev_priv->drm, plane) {
13831 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
13834 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
13839 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
13840 struct drm_file *file)
13842 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
13843 struct drm_crtc *drmmode_crtc;
13844 struct intel_crtc *crtc;
13846 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
13850 crtc = to_intel_crtc(drmmode_crtc);
13851 pipe_from_crtc_id->pipe = crtc->pipe;
13856 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
13858 struct drm_device *dev = encoder->base.dev;
13859 struct intel_encoder *source_encoder;
13860 u32 possible_clones = 0;
13862 for_each_intel_encoder(dev, source_encoder) {
13863 if (encoders_cloneable(encoder, source_encoder))
13864 possible_clones |= drm_encoder_mask(&source_encoder->base);
13867 return possible_clones;
13870 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
13872 struct drm_device *dev = encoder->base.dev;
13873 struct intel_crtc *crtc;
13874 u32 possible_crtcs = 0;
13876 for_each_intel_crtc(dev, crtc) {
13877 if (encoder->pipe_mask & BIT(crtc->pipe))
13878 possible_crtcs |= drm_crtc_mask(&crtc->base);
13881 return possible_crtcs;
13884 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
13886 if (!IS_MOBILE(dev_priv))
13889 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
13892 if (IS_GEN(dev_priv, 5) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
13898 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
13900 if (INTEL_GEN(dev_priv) >= 9)
13903 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
13906 if (HAS_PCH_LPT_H(dev_priv) &&
13907 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
13910 /* DDI E can't be used if DDI A requires 4 lanes */
13911 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
13914 if (!dev_priv->vbt.int_crt_support)
13920 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
13922 struct intel_encoder *encoder;
13923 bool dpd_is_edp = false;
13925 intel_pps_unlock_regs_wa(dev_priv);
13927 if (!HAS_DISPLAY(dev_priv))
13930 if (IS_ALDERLAKE_S(dev_priv)) {
13931 intel_ddi_init(dev_priv, PORT_A);
13932 intel_ddi_init(dev_priv, PORT_TC1);
13933 intel_ddi_init(dev_priv, PORT_TC2);
13934 intel_ddi_init(dev_priv, PORT_TC3);
13935 intel_ddi_init(dev_priv, PORT_TC4);
13936 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
13937 intel_ddi_init(dev_priv, PORT_A);
13938 intel_ddi_init(dev_priv, PORT_B);
13939 intel_ddi_init(dev_priv, PORT_TC1);
13940 intel_ddi_init(dev_priv, PORT_TC2);
13941 } else if (INTEL_GEN(dev_priv) >= 12) {
13942 intel_ddi_init(dev_priv, PORT_A);
13943 intel_ddi_init(dev_priv, PORT_B);
13944 intel_ddi_init(dev_priv, PORT_TC1);
13945 intel_ddi_init(dev_priv, PORT_TC2);
13946 intel_ddi_init(dev_priv, PORT_TC3);
13947 intel_ddi_init(dev_priv, PORT_TC4);
13948 intel_ddi_init(dev_priv, PORT_TC5);
13949 intel_ddi_init(dev_priv, PORT_TC6);
13950 icl_dsi_init(dev_priv);
13951 } else if (IS_JSL_EHL(dev_priv)) {
13952 intel_ddi_init(dev_priv, PORT_A);
13953 intel_ddi_init(dev_priv, PORT_B);
13954 intel_ddi_init(dev_priv, PORT_C);
13955 intel_ddi_init(dev_priv, PORT_D);
13956 icl_dsi_init(dev_priv);
13957 } else if (IS_GEN(dev_priv, 11)) {
13958 intel_ddi_init(dev_priv, PORT_A);
13959 intel_ddi_init(dev_priv, PORT_B);
13960 intel_ddi_init(dev_priv, PORT_C);
13961 intel_ddi_init(dev_priv, PORT_D);
13962 intel_ddi_init(dev_priv, PORT_E);
13964 * On some ICL SKUs port F is not present. No strap bits for
13965 * this, so rely on VBT.
13966 * Work around broken VBTs on SKUs known to have no port F.
13968 if (IS_ICL_WITH_PORT_F(dev_priv) &&
13969 intel_bios_is_port_present(dev_priv, PORT_F))
13970 intel_ddi_init(dev_priv, PORT_F);
13972 icl_dsi_init(dev_priv);
13973 } else if (IS_GEN9_LP(dev_priv)) {
13975 * FIXME: Broxton doesn't support port detection via the
13976 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
13977 * detect the ports.
13979 intel_ddi_init(dev_priv, PORT_A);
13980 intel_ddi_init(dev_priv, PORT_B);
13981 intel_ddi_init(dev_priv, PORT_C);
13983 vlv_dsi_init(dev_priv);
13984 } else if (HAS_DDI(dev_priv)) {
13987 if (intel_ddi_crt_present(dev_priv))
13988 intel_crt_init(dev_priv);
13991 * Haswell uses DDI functions to detect digital outputs.
13992 * On SKL pre-D0 the strap isn't connected, so we assume
13995 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
13996 /* WaIgnoreDDIAStrap: skl */
13997 if (found || IS_GEN9_BC(dev_priv))
13998 intel_ddi_init(dev_priv, PORT_A);
14000 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
14002 found = intel_de_read(dev_priv, SFUSE_STRAP);
14004 if (found & SFUSE_STRAP_DDIB_DETECTED)
14005 intel_ddi_init(dev_priv, PORT_B);
14006 if (found & SFUSE_STRAP_DDIC_DETECTED)
14007 intel_ddi_init(dev_priv, PORT_C);
14008 if (found & SFUSE_STRAP_DDID_DETECTED)
14009 intel_ddi_init(dev_priv, PORT_D);
14010 if (found & SFUSE_STRAP_DDIF_DETECTED)
14011 intel_ddi_init(dev_priv, PORT_F);
14013 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14015 if (IS_GEN9_BC(dev_priv) &&
14016 intel_bios_is_port_present(dev_priv, PORT_E))
14017 intel_ddi_init(dev_priv, PORT_E);
14019 } else if (HAS_PCH_SPLIT(dev_priv)) {
14023 * intel_edp_init_connector() depends on this completing first,
14024 * to prevent the registration of both eDP and LVDS and the
14025 * incorrect sharing of the PPS.
14027 intel_lvds_init(dev_priv);
14028 intel_crt_init(dev_priv);
14030 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
14032 if (ilk_has_edp_a(dev_priv))
14033 intel_dp_init(dev_priv, DP_A, PORT_A);
14035 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
14036 /* PCH SDVOB multiplex with HDMIB */
14037 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
14039 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
14040 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
14041 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
14044 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
14045 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
14047 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
14048 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
14050 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
14051 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
14053 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
14054 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
14055 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
14056 bool has_edp, has_port;
14058 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
14059 intel_crt_init(dev_priv);
14062 * The DP_DETECTED bit is the latched state of the DDC
14063 * SDA pin at boot. However since eDP doesn't require DDC
14064 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14065 * eDP ports may have been muxed to an alternate function.
14066 * Thus we can't rely on the DP_DETECTED bit alone to detect
14067 * eDP ports. Consult the VBT as well as DP_DETECTED to
14068 * detect eDP ports.
14070 * Sadly the straps seem to be missing sometimes even for HDMI
14071 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14072 * and VBT for the presence of the port. Additionally we can't
14073 * trust the port type the VBT declares as we've seen at least
14074 * HDMI ports that the VBT claim are DP or eDP.
14076 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
14077 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14078 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
14079 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
14080 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
14081 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
14083 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
14084 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14085 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
14086 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
14087 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
14088 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
14090 if (IS_CHERRYVIEW(dev_priv)) {
14092 * eDP not supported on port D,
14093 * so no need to worry about it
14095 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14096 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
14097 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
14098 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
14099 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
14102 vlv_dsi_init(dev_priv);
14103 } else if (IS_PINEVIEW(dev_priv)) {
14104 intel_lvds_init(dev_priv);
14105 intel_crt_init(dev_priv);
14106 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
14107 bool found = false;
14109 if (IS_MOBILE(dev_priv))
14110 intel_lvds_init(dev_priv);
14112 intel_crt_init(dev_priv);
14114 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
14115 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
14116 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
14117 if (!found && IS_G4X(dev_priv)) {
14118 drm_dbg_kms(&dev_priv->drm,
14119 "probing HDMI on SDVOB\n");
14120 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
14123 if (!found && IS_G4X(dev_priv))
14124 intel_dp_init(dev_priv, DP_B, PORT_B);
14127 /* Before G4X SDVOC doesn't have its own detect register */
14129 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
14130 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
14131 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
14134 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
14136 if (IS_G4X(dev_priv)) {
14137 drm_dbg_kms(&dev_priv->drm,
14138 "probing HDMI on SDVOC\n");
14139 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
14141 if (IS_G4X(dev_priv))
14142 intel_dp_init(dev_priv, DP_C, PORT_C);
14145 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
14146 intel_dp_init(dev_priv, DP_D, PORT_D);
14148 if (SUPPORTS_TV(dev_priv))
14149 intel_tv_init(dev_priv);
14150 } else if (IS_GEN(dev_priv, 2)) {
14151 if (IS_I85X(dev_priv))
14152 intel_lvds_init(dev_priv);
14154 intel_crt_init(dev_priv);
14155 intel_dvo_init(dev_priv);
14158 for_each_intel_encoder(&dev_priv->drm, encoder) {
14159 encoder->base.possible_crtcs =
14160 intel_encoder_possible_crtcs(encoder);
14161 encoder->base.possible_clones =
14162 intel_encoder_possible_clones(encoder);
14165 intel_init_pch_refclk(dev_priv);
14167 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
14170 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14172 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
14174 drm_framebuffer_cleanup(fb);
14175 intel_frontbuffer_put(intel_fb->frontbuffer);
14180 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
14181 struct drm_file *file,
14182 unsigned int *handle)
14184 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14185 struct drm_i915_private *i915 = to_i915(obj->base.dev);
14187 if (obj->userptr.mm) {
14188 drm_dbg(&i915->drm,
14189 "attempting to use a userptr for a framebuffer, denied\n");
14193 return drm_gem_handle_create(file, &obj->base, handle);
14196 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14197 struct drm_file *file,
14198 unsigned flags, unsigned color,
14199 struct drm_clip_rect *clips,
14200 unsigned num_clips)
14202 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
14204 i915_gem_object_flush_if_display(obj);
14205 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
14210 static const struct drm_framebuffer_funcs intel_fb_funcs = {
14211 .destroy = intel_user_framebuffer_destroy,
14212 .create_handle = intel_user_framebuffer_create_handle,
14213 .dirty = intel_user_framebuffer_dirty,
14216 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14217 struct drm_i915_gem_object *obj,
14218 struct drm_mode_fb_cmd2 *mode_cmd)
14220 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
14221 struct drm_framebuffer *fb = &intel_fb->base;
14223 unsigned int tiling, stride;
14227 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
14228 if (!intel_fb->frontbuffer)
14231 i915_gem_object_lock(obj, NULL);
14232 tiling = i915_gem_object_get_tiling(obj);
14233 stride = i915_gem_object_get_stride(obj);
14234 i915_gem_object_unlock(obj);
14236 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
14238 * If there's a fence, enforce that
14239 * the fb modifier and tiling mode match.
14241 if (tiling != I915_TILING_NONE &&
14242 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14243 drm_dbg_kms(&dev_priv->drm,
14244 "tiling_mode doesn't match fb modifier\n");
14248 if (tiling == I915_TILING_X) {
14249 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
14250 } else if (tiling == I915_TILING_Y) {
14251 drm_dbg_kms(&dev_priv->drm,
14252 "No Y tiling for legacy addfb\n");
14257 if (!drm_any_plane_has_format(&dev_priv->drm,
14258 mode_cmd->pixel_format,
14259 mode_cmd->modifier[0])) {
14260 struct drm_format_name_buf format_name;
14262 drm_dbg_kms(&dev_priv->drm,
14263 "unsupported pixel format %s / modifier 0x%llx\n",
14264 drm_get_format_name(mode_cmd->pixel_format,
14266 mode_cmd->modifier[0]);
14271 * gen2/3 display engine uses the fence if present,
14272 * so the tiling mode must match the fb modifier exactly.
14274 if (INTEL_GEN(dev_priv) < 4 &&
14275 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
14276 drm_dbg_kms(&dev_priv->drm,
14277 "tiling_mode must match fb modifier exactly on gen2/3\n");
14281 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
14282 mode_cmd->modifier[0]);
14283 if (mode_cmd->pitches[0] > max_stride) {
14284 drm_dbg_kms(&dev_priv->drm,
14285 "%s pitch (%u) must be at most %d\n",
14286 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
14287 "tiled" : "linear",
14288 mode_cmd->pitches[0], max_stride);
14293 * If there's a fence, enforce that
14294 * the fb pitch and fence stride match.
14296 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14297 drm_dbg_kms(&dev_priv->drm,
14298 "pitch (%d) must match tiling stride (%d)\n",
14299 mode_cmd->pitches[0], stride);
14303 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14304 if (mode_cmd->offsets[0] != 0) {
14305 drm_dbg_kms(&dev_priv->drm,
14306 "plane 0 offset (0x%08x) must be 0\n",
14307 mode_cmd->offsets[0]);
14311 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
14313 for (i = 0; i < fb->format->num_planes; i++) {
14314 u32 stride_alignment;
14316 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14317 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
14322 stride_alignment = intel_fb_stride_alignment(fb, i);
14323 if (fb->pitches[i] & (stride_alignment - 1)) {
14324 drm_dbg_kms(&dev_priv->drm,
14325 "plane %d pitch (%d) must be at least %u byte aligned\n",
14326 i, fb->pitches[i], stride_alignment);
14330 if (is_gen12_ccs_plane(fb, i) && !is_gen12_ccs_cc_plane(fb, i)) {
14331 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
14333 if (fb->pitches[i] != ccs_aux_stride) {
14334 drm_dbg_kms(&dev_priv->drm,
14335 "ccs aux plane %d pitch (%d) must be %d\n",
14337 fb->pitches[i], ccs_aux_stride);
14342 fb->obj[i] = &obj->base;
14345 ret = intel_fill_fb_info(dev_priv, fb);
14349 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
14351 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
14358 intel_frontbuffer_put(intel_fb->frontbuffer);
14362 static struct drm_framebuffer *
14363 intel_user_framebuffer_create(struct drm_device *dev,
14364 struct drm_file *filp,
14365 const struct drm_mode_fb_cmd2 *user_mode_cmd)
14367 struct drm_framebuffer *fb;
14368 struct drm_i915_gem_object *obj;
14369 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
14371 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14373 return ERR_PTR(-ENOENT);
14375 fb = intel_framebuffer_create(obj, &mode_cmd);
14376 i915_gem_object_put(obj);
14381 static enum drm_mode_status
14382 intel_mode_valid(struct drm_device *dev,
14383 const struct drm_display_mode *mode)
14385 struct drm_i915_private *dev_priv = to_i915(dev);
14386 int hdisplay_max, htotal_max;
14387 int vdisplay_max, vtotal_max;
14390 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14391 * of DBLSCAN modes to the output's mode list when they detect
14392 * the scaling mode property on the connector. And they don't
14393 * ask the kernel to validate those modes in any way until
14394 * modeset time at which point the client gets a protocol error.
14395 * So in order to not upset those clients we silently ignore the
14396 * DBLSCAN flag on such connectors. For other connectors we will
14397 * reject modes with the DBLSCAN flag in encoder->compute_config().
14398 * And we always reject DBLSCAN modes in connector->mode_valid()
14399 * as we never want such modes on the connector's mode list.
14402 if (mode->vscan > 1)
14403 return MODE_NO_VSCAN;
14405 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14406 return MODE_H_ILLEGAL;
14408 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14409 DRM_MODE_FLAG_NCSYNC |
14410 DRM_MODE_FLAG_PCSYNC))
14413 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14414 DRM_MODE_FLAG_PIXMUX |
14415 DRM_MODE_FLAG_CLKDIV2))
14418 /* Transcoder timing limits */
14419 if (INTEL_GEN(dev_priv) >= 11) {
14420 hdisplay_max = 16384;
14421 vdisplay_max = 8192;
14422 htotal_max = 16384;
14424 } else if (INTEL_GEN(dev_priv) >= 9 ||
14425 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14426 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14427 vdisplay_max = 4096;
14430 } else if (INTEL_GEN(dev_priv) >= 3) {
14431 hdisplay_max = 4096;
14432 vdisplay_max = 4096;
14436 hdisplay_max = 2048;
14437 vdisplay_max = 2048;
14442 if (mode->hdisplay > hdisplay_max ||
14443 mode->hsync_start > htotal_max ||
14444 mode->hsync_end > htotal_max ||
14445 mode->htotal > htotal_max)
14446 return MODE_H_ILLEGAL;
14448 if (mode->vdisplay > vdisplay_max ||
14449 mode->vsync_start > vtotal_max ||
14450 mode->vsync_end > vtotal_max ||
14451 mode->vtotal > vtotal_max)
14452 return MODE_V_ILLEGAL;
14454 if (INTEL_GEN(dev_priv) >= 5) {
14455 if (mode->hdisplay < 64 ||
14456 mode->htotal - mode->hdisplay < 32)
14457 return MODE_H_ILLEGAL;
14459 if (mode->vtotal - mode->vdisplay < 5)
14460 return MODE_V_ILLEGAL;
14462 if (mode->htotal - mode->hdisplay < 32)
14463 return MODE_H_ILLEGAL;
14465 if (mode->vtotal - mode->vdisplay < 3)
14466 return MODE_V_ILLEGAL;
14472 enum drm_mode_status
14473 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
14474 const struct drm_display_mode *mode,
14477 int plane_width_max, plane_height_max;
14480 * intel_mode_valid() should be
14481 * sufficient on older platforms.
14483 if (INTEL_GEN(dev_priv) < 9)
14487 * Most people will probably want a fullscreen
14488 * plane so let's not advertize modes that are
14489 * too big for that.
14491 if (INTEL_GEN(dev_priv) >= 11) {
14492 plane_width_max = 5120 << bigjoiner;
14493 plane_height_max = 4320;
14495 plane_width_max = 5120;
14496 plane_height_max = 4096;
14499 if (mode->hdisplay > plane_width_max)
14500 return MODE_H_ILLEGAL;
14502 if (mode->vdisplay > plane_height_max)
14503 return MODE_V_ILLEGAL;
14508 static const struct drm_mode_config_funcs intel_mode_funcs = {
14509 .fb_create = intel_user_framebuffer_create,
14510 .get_format_info = intel_get_format_info,
14511 .output_poll_changed = intel_fbdev_output_poll_changed,
14512 .mode_valid = intel_mode_valid,
14513 .atomic_check = intel_atomic_check,
14514 .atomic_commit = intel_atomic_commit,
14515 .atomic_state_alloc = intel_atomic_state_alloc,
14516 .atomic_state_clear = intel_atomic_state_clear,
14517 .atomic_state_free = intel_atomic_state_free,
14521 * intel_init_display_hooks - initialize the display modesetting hooks
14522 * @dev_priv: device private
14524 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
14526 intel_init_cdclk_hooks(dev_priv);
14528 intel_dpll_init_clock_hook(dev_priv);
14530 if (INTEL_GEN(dev_priv) >= 9) {
14531 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
14532 dev_priv->display.crtc_enable = hsw_crtc_enable;
14533 dev_priv->display.crtc_disable = hsw_crtc_disable;
14534 } else if (HAS_DDI(dev_priv)) {
14535 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
14536 dev_priv->display.crtc_enable = hsw_crtc_enable;
14537 dev_priv->display.crtc_disable = hsw_crtc_disable;
14538 } else if (HAS_PCH_SPLIT(dev_priv)) {
14539 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
14540 dev_priv->display.crtc_enable = ilk_crtc_enable;
14541 dev_priv->display.crtc_disable = ilk_crtc_disable;
14542 } else if (IS_CHERRYVIEW(dev_priv) ||
14543 IS_VALLEYVIEW(dev_priv)) {
14544 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14545 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14546 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14548 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14549 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14550 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14553 intel_fdi_init_hook(dev_priv);
14555 if (INTEL_GEN(dev_priv) >= 9) {
14556 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
14557 dev_priv->display.get_initial_plane_config = skl_get_initial_plane_config;
14559 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
14560 dev_priv->display.get_initial_plane_config = i9xx_get_initial_plane_config;
14565 void intel_modeset_init_hw(struct drm_i915_private *i915)
14567 struct intel_cdclk_state *cdclk_state =
14568 to_intel_cdclk_state(i915->cdclk.obj.state);
14570 intel_update_cdclk(i915);
14571 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
14572 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
14575 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
14577 struct drm_plane *plane;
14578 struct intel_crtc *crtc;
14580 for_each_intel_crtc(state->dev, crtc) {
14581 struct intel_crtc_state *crtc_state;
14583 crtc_state = intel_atomic_get_crtc_state(state, crtc);
14584 if (IS_ERR(crtc_state))
14585 return PTR_ERR(crtc_state);
14587 if (crtc_state->hw.active) {
14589 * Preserve the inherited flag to avoid
14590 * taking the full modeset path.
14592 crtc_state->inherited = true;
14596 drm_for_each_plane(plane, state->dev) {
14597 struct drm_plane_state *plane_state;
14599 plane_state = drm_atomic_get_plane_state(state, plane);
14600 if (IS_ERR(plane_state))
14601 return PTR_ERR(plane_state);
14608 * Calculate what we think the watermarks should be for the state we've read
14609 * out of the hardware and then immediately program those watermarks so that
14610 * we ensure the hardware settings match our internal state.
14612 * We can calculate what we think WM's should be by creating a duplicate of the
14613 * current state (which was constructed during hardware readout) and running it
14614 * through the atomic check code to calculate new watermark values in the
14617 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
14619 struct drm_atomic_state *state;
14620 struct intel_atomic_state *intel_state;
14621 struct intel_crtc *crtc;
14622 struct intel_crtc_state *crtc_state;
14623 struct drm_modeset_acquire_ctx ctx;
14627 /* Only supported on platforms that use atomic watermark design */
14628 if (!dev_priv->display.optimize_watermarks)
14631 state = drm_atomic_state_alloc(&dev_priv->drm);
14632 if (drm_WARN_ON(&dev_priv->drm, !state))
14635 intel_state = to_intel_atomic_state(state);
14637 drm_modeset_acquire_init(&ctx, 0);
14640 state->acquire_ctx = &ctx;
14643 * Hardware readout is the only time we don't want to calculate
14644 * intermediate watermarks (since we don't trust the current
14647 if (!HAS_GMCH(dev_priv))
14648 intel_state->skip_intermediate_wm = true;
14650 ret = sanitize_watermarks_add_affected(state);
14654 ret = intel_atomic_check(&dev_priv->drm, state);
14658 /* Write calculated watermark values back */
14659 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
14660 crtc_state->wm.need_postvbl_update = true;
14661 dev_priv->display.optimize_watermarks(intel_state, crtc);
14663 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
14667 if (ret == -EDEADLK) {
14668 drm_atomic_state_clear(state);
14669 drm_modeset_backoff(&ctx);
14674 * If we fail here, it means that the hardware appears to be
14675 * programmed in a way that shouldn't be possible, given our
14676 * understanding of watermark requirements. This might mean a
14677 * mistake in the hardware readout code or a mistake in the
14678 * watermark calculations for a given platform. Raise a WARN
14679 * so that this is noticeable.
14681 * If this actually happens, we'll have to just leave the
14682 * BIOS-programmed watermarks untouched and hope for the best.
14684 drm_WARN(&dev_priv->drm, ret,
14685 "Could not determine valid watermarks for inherited state\n");
14687 drm_atomic_state_put(state);
14689 drm_modeset_drop_locks(&ctx);
14690 drm_modeset_acquire_fini(&ctx);
14693 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14695 if (IS_GEN(dev_priv, 5)) {
14697 intel_de_read(dev_priv, FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14699 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
14700 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
14701 dev_priv->fdi_pll_freq = 270000;
14706 drm_dbg(&dev_priv->drm, "FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14709 static int intel_initial_commit(struct drm_device *dev)
14711 struct drm_atomic_state *state = NULL;
14712 struct drm_modeset_acquire_ctx ctx;
14713 struct intel_crtc *crtc;
14716 state = drm_atomic_state_alloc(dev);
14720 drm_modeset_acquire_init(&ctx, 0);
14723 state->acquire_ctx = &ctx;
14725 for_each_intel_crtc(dev, crtc) {
14726 struct intel_crtc_state *crtc_state =
14727 intel_atomic_get_crtc_state(state, crtc);
14729 if (IS_ERR(crtc_state)) {
14730 ret = PTR_ERR(crtc_state);
14734 if (crtc_state->hw.active) {
14735 struct intel_encoder *encoder;
14738 * We've not yet detected sink capabilities
14739 * (audio,infoframes,etc.) and thus we don't want to
14740 * force a full state recomputation yet. We want that to
14741 * happen only for the first real commit from userspace.
14742 * So preserve the inherited flag for the time being.
14744 crtc_state->inherited = true;
14746 ret = drm_atomic_add_affected_planes(state, &crtc->base);
14751 * FIXME hack to force a LUT update to avoid the
14752 * plane update forcing the pipe gamma on without
14753 * having a proper LUT loaded. Remove once we
14754 * have readout for pipe gamma enable.
14756 crtc_state->uapi.color_mgmt_changed = true;
14758 for_each_intel_encoder_mask(dev, encoder,
14759 crtc_state->uapi.encoder_mask) {
14760 if (encoder->initial_fastset_check &&
14761 !encoder->initial_fastset_check(encoder, crtc_state)) {
14762 ret = drm_atomic_add_affected_connectors(state,
14771 ret = drm_atomic_commit(state);
14774 if (ret == -EDEADLK) {
14775 drm_atomic_state_clear(state);
14776 drm_modeset_backoff(&ctx);
14780 drm_atomic_state_put(state);
14782 drm_modeset_drop_locks(&ctx);
14783 drm_modeset_acquire_fini(&ctx);
14788 static void intel_mode_config_init(struct drm_i915_private *i915)
14790 struct drm_mode_config *mode_config = &i915->drm.mode_config;
14792 drm_mode_config_init(&i915->drm);
14793 INIT_LIST_HEAD(&i915->global_obj_list);
14795 mode_config->min_width = 0;
14796 mode_config->min_height = 0;
14798 mode_config->preferred_depth = 24;
14799 mode_config->prefer_shadow = 1;
14801 mode_config->allow_fb_modifiers = true;
14803 mode_config->funcs = &intel_mode_funcs;
14805 mode_config->async_page_flip = has_async_flips(i915);
14808 * Maximum framebuffer dimensions, chosen to match
14809 * the maximum render engine surface size on gen4+.
14811 if (INTEL_GEN(i915) >= 7) {
14812 mode_config->max_width = 16384;
14813 mode_config->max_height = 16384;
14814 } else if (INTEL_GEN(i915) >= 4) {
14815 mode_config->max_width = 8192;
14816 mode_config->max_height = 8192;
14817 } else if (IS_GEN(i915, 3)) {
14818 mode_config->max_width = 4096;
14819 mode_config->max_height = 4096;
14821 mode_config->max_width = 2048;
14822 mode_config->max_height = 2048;
14825 if (IS_I845G(i915) || IS_I865G(i915)) {
14826 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
14827 mode_config->cursor_height = 1023;
14828 } else if (IS_I830(i915) || IS_I85X(i915) ||
14829 IS_I915G(i915) || IS_I915GM(i915)) {
14830 mode_config->cursor_width = 64;
14831 mode_config->cursor_height = 64;
14833 mode_config->cursor_width = 256;
14834 mode_config->cursor_height = 256;
14838 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
14840 intel_atomic_global_obj_cleanup(i915);
14841 drm_mode_config_cleanup(&i915->drm);
14844 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
14846 if (plane_config->fb) {
14847 struct drm_framebuffer *fb = &plane_config->fb->base;
14849 /* We may only have the stub and not a full framebuffer */
14850 if (drm_framebuffer_read_refcount(fb))
14851 drm_framebuffer_put(fb);
14856 if (plane_config->vma)
14857 i915_vma_put(plane_config->vma);
14860 /* part #1: call before irq install */
14861 int intel_modeset_init_noirq(struct drm_i915_private *i915)
14865 if (i915_inject_probe_failure(i915))
14868 if (HAS_DISPLAY(i915)) {
14869 ret = drm_vblank_init(&i915->drm,
14870 INTEL_NUM_PIPES(i915));
14875 intel_bios_init(i915);
14877 ret = intel_vga_register(i915);
14881 /* FIXME: completely on the wrong abstraction layer */
14882 intel_power_domains_init_hw(i915, false);
14884 intel_csr_ucode_init(i915);
14886 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
14887 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
14888 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
14890 i915->framestart_delay = 1; /* 1-4 */
14892 intel_mode_config_init(i915);
14894 ret = intel_cdclk_init(i915);
14896 goto cleanup_vga_client_pw_domain_csr;
14898 ret = intel_dbuf_init(i915);
14900 goto cleanup_vga_client_pw_domain_csr;
14902 ret = intel_bw_init(i915);
14904 goto cleanup_vga_client_pw_domain_csr;
14906 init_llist_head(&i915->atomic_helper.free_list);
14907 INIT_WORK(&i915->atomic_helper.free_work,
14908 intel_atomic_helper_free_state_worker);
14910 intel_init_quirks(i915);
14912 intel_fbc_init(i915);
14916 cleanup_vga_client_pw_domain_csr:
14917 intel_csr_ucode_fini(i915);
14918 intel_power_domains_driver_remove(i915);
14919 intel_vga_unregister(i915);
14921 intel_bios_driver_remove(i915);
14926 /* part #2: call after irq install, but before gem init */
14927 int intel_modeset_init_nogem(struct drm_i915_private *i915)
14929 struct drm_device *dev = &i915->drm;
14931 struct intel_crtc *crtc;
14934 intel_init_pm(i915);
14936 intel_panel_sanitize_ssc(i915);
14938 intel_pps_setup(i915);
14940 intel_gmbus_setup(i915);
14942 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
14943 INTEL_NUM_PIPES(i915),
14944 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
14946 if (HAS_DISPLAY(i915)) {
14947 for_each_pipe(i915, pipe) {
14948 ret = intel_crtc_init(i915, pipe);
14950 intel_mode_config_cleanup(i915);
14956 intel_plane_possible_crtcs_init(i915);
14957 intel_shared_dpll_init(dev);
14958 intel_update_fdi_pll_freq(i915);
14960 intel_update_czclk(i915);
14961 intel_modeset_init_hw(i915);
14963 intel_hdcp_component_init(i915);
14965 if (i915->max_cdclk_freq == 0)
14966 intel_update_max_cdclk(i915);
14969 * If the platform has HTI, we need to find out whether it has reserved
14970 * any display resources before we create our display outputs.
14972 if (INTEL_INFO(i915)->display.has_hti)
14973 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
14975 /* Just disable it once at startup */
14976 intel_vga_disable(i915);
14977 intel_setup_outputs(i915);
14979 drm_modeset_lock_all(dev);
14980 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
14981 drm_modeset_unlock_all(dev);
14983 for_each_intel_crtc(dev, crtc) {
14984 struct intel_initial_plane_config plane_config = {};
14986 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
14990 * Note that reserving the BIOS fb up front prevents us
14991 * from stuffing other stolen allocations like the ring
14992 * on top. This prevents some ugliness at boot time, and
14993 * can even allow for smooth boot transitions if the BIOS
14994 * fb is large enough for the active pipe configuration.
14996 i915->display.get_initial_plane_config(crtc, &plane_config);
14999 * If the fb is shared between multiple heads, we'll
15000 * just get the first one.
15002 intel_find_initial_plane_obj(crtc, &plane_config);
15004 plane_config_fini(&plane_config);
15008 * Make sure hardware watermarks really match the state we read out.
15009 * Note that we need to do this after reconstructing the BIOS fb's
15010 * since the watermark calculation done here will use pstate->fb.
15012 if (!HAS_GMCH(i915))
15013 sanitize_watermarks(i915);
15018 /* part #3: call after gem init */
15019 int intel_modeset_init(struct drm_i915_private *i915)
15023 if (!HAS_DISPLAY(i915))
15027 * Force all active planes to recompute their states. So that on
15028 * mode_setcrtc after probe, all the intel_plane_state variables
15029 * are already calculated and there is no assert_plane warnings
15032 ret = intel_initial_commit(&i915->drm);
15034 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
15036 intel_overlay_setup(i915);
15038 ret = intel_fbdev_init(&i915->drm);
15042 /* Only enable hotplug handling once the fbdev is fully set up. */
15043 intel_hpd_init(i915);
15044 intel_hpd_poll_disable(i915);
15046 intel_init_ipc(i915);
15051 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15053 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15054 /* 640x480@60Hz, ~25175 kHz */
15055 struct dpll clock = {
15065 drm_WARN_ON(&dev_priv->drm,
15066 i9xx_calc_dpll_params(48000, &clock) != 25154);
15068 drm_dbg_kms(&dev_priv->drm,
15069 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15070 pipe_name(pipe), clock.vco, clock.dot);
15072 fp = i9xx_dpll_compute_fp(&clock);
15073 dpll = DPLL_DVO_2X_MODE |
15074 DPLL_VGA_MODE_DIS |
15075 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15076 PLL_P2_DIVIDE_BY_4 |
15077 PLL_REF_INPUT_DREFCLK |
15080 intel_de_write(dev_priv, FP0(pipe), fp);
15081 intel_de_write(dev_priv, FP1(pipe), fp);
15083 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15084 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15085 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15086 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15087 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15088 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15089 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15092 * Apparently we need to have VGA mode enabled prior to changing
15093 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15094 * dividers, even though the register value does change.
15096 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15097 intel_de_write(dev_priv, DPLL(pipe), dpll);
15099 /* Wait for the clocks to stabilize. */
15100 intel_de_posting_read(dev_priv, DPLL(pipe));
15103 /* The pixel multiplier can only be updated once the
15104 * DPLL is enabled and the clocks are stable.
15106 * So write it again.
15108 intel_de_write(dev_priv, DPLL(pipe), dpll);
15110 /* We do this three times for luck */
15111 for (i = 0; i < 3 ; i++) {
15112 intel_de_write(dev_priv, DPLL(pipe), dpll);
15113 intel_de_posting_read(dev_priv, DPLL(pipe));
15114 udelay(150); /* wait for warmup */
15117 intel_de_write(dev_priv, PIPECONF(pipe),
15118 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15119 intel_de_posting_read(dev_priv, PIPECONF(pipe));
15121 intel_wait_for_pipe_scanline_moving(crtc);
15124 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15126 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15128 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
15131 drm_WARN_ON(&dev_priv->drm,
15132 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
15133 DISPLAY_PLANE_ENABLE);
15134 drm_WARN_ON(&dev_priv->drm,
15135 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
15136 DISPLAY_PLANE_ENABLE);
15137 drm_WARN_ON(&dev_priv->drm,
15138 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
15139 DISPLAY_PLANE_ENABLE);
15140 drm_WARN_ON(&dev_priv->drm,
15141 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
15142 drm_WARN_ON(&dev_priv->drm,
15143 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
15145 intel_de_write(dev_priv, PIPECONF(pipe), 0);
15146 intel_de_posting_read(dev_priv, PIPECONF(pipe));
15148 intel_wait_for_pipe_scanline_stopped(crtc);
15150 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
15151 intel_de_posting_read(dev_priv, DPLL(pipe));
15155 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15157 struct intel_crtc *crtc;
15159 if (INTEL_GEN(dev_priv) >= 4)
15162 for_each_intel_crtc(&dev_priv->drm, crtc) {
15163 struct intel_plane *plane =
15164 to_intel_plane(crtc->base.primary);
15165 struct intel_crtc *plane_crtc;
15168 if (!plane->get_hw_state(plane, &pipe))
15171 if (pipe == crtc->pipe)
15174 drm_dbg_kms(&dev_priv->drm,
15175 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15176 plane->base.base.id, plane->base.name);
15178 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15179 intel_plane_disable_noatomic(plane_crtc, plane);
15183 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15185 struct drm_device *dev = crtc->base.dev;
15186 struct intel_encoder *encoder;
15188 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15194 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15196 struct drm_device *dev = encoder->base.dev;
15197 struct intel_connector *connector;
15199 for_each_connector_on_encoder(dev, &encoder->base, connector)
15205 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
15206 enum pipe pch_transcoder)
15208 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
15209 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
15212 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
15214 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
15215 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
15216 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
15218 if (INTEL_GEN(dev_priv) >= 9 ||
15219 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15220 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
15223 if (transcoder_is_dsi(cpu_transcoder))
15226 val = intel_de_read(dev_priv, reg);
15227 val &= ~HSW_FRAME_START_DELAY_MASK;
15228 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
15229 intel_de_write(dev_priv, reg, val);
15231 i915_reg_t reg = PIPECONF(cpu_transcoder);
15234 val = intel_de_read(dev_priv, reg);
15235 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
15236 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
15237 intel_de_write(dev_priv, reg, val);
15240 if (!crtc_state->has_pch_encoder)
15243 if (HAS_PCH_IBX(dev_priv)) {
15244 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
15247 val = intel_de_read(dev_priv, reg);
15248 val &= ~TRANS_FRAME_START_DELAY_MASK;
15249 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
15250 intel_de_write(dev_priv, reg, val);
15252 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
15253 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
15256 val = intel_de_read(dev_priv, reg);
15257 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
15258 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
15259 intel_de_write(dev_priv, reg, val);
15263 static void intel_sanitize_crtc(struct intel_crtc *crtc,
15264 struct drm_modeset_acquire_ctx *ctx)
15266 struct drm_device *dev = crtc->base.dev;
15267 struct drm_i915_private *dev_priv = to_i915(dev);
15268 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15270 if (crtc_state->hw.active) {
15271 struct intel_plane *plane;
15273 /* Clear any frame start delays used for debugging left by the BIOS */
15274 intel_sanitize_frame_start_delay(crtc_state);
15276 /* Disable everything but the primary plane */
15277 for_each_intel_plane_on_crtc(dev, crtc, plane) {
15278 const struct intel_plane_state *plane_state =
15279 to_intel_plane_state(plane->base.state);
15281 if (plane_state->uapi.visible &&
15282 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15283 intel_plane_disable_noatomic(crtc, plane);
15287 * Disable any background color set by the BIOS, but enable the
15288 * gamma and CSC to match how we program our planes.
15290 if (INTEL_GEN(dev_priv) >= 9)
15291 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
15292 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
15295 /* Adjust the state of the output pipe according to whether we
15296 * have active connectors/encoders. */
15297 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc) &&
15298 !crtc_state->bigjoiner_slave)
15299 intel_crtc_disable_noatomic(crtc, ctx);
15301 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
15303 * We start out with underrun reporting disabled to avoid races.
15304 * For correct bookkeeping mark this on active crtcs.
15306 * Also on gmch platforms we dont have any hardware bits to
15307 * disable the underrun reporting. Which means we need to start
15308 * out with underrun reporting disabled also on inactive pipes,
15309 * since otherwise we'll complain about the garbage we read when
15310 * e.g. coming up after runtime pm.
15312 * No protection against concurrent access is required - at
15313 * worst a fifo underrun happens which also sets this to false.
15315 crtc->cpu_fifo_underrun_disabled = true;
15317 * We track the PCH trancoder underrun reporting state
15318 * within the crtc. With crtc for pipe A housing the underrun
15319 * reporting state for PCH transcoder A, crtc for pipe B housing
15320 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15321 * and marking underrun reporting as disabled for the non-existing
15322 * PCH transcoders B and C would prevent enabling the south
15323 * error interrupt (see cpt_can_enable_serr_int()).
15325 if (has_pch_trancoder(dev_priv, crtc->pipe))
15326 crtc->pch_fifo_underrun_disabled = true;
15330 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
15332 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
15335 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
15336 * the hardware when a high res displays plugged in. DPLL P
15337 * divider is zero, and the pipe timings are bonkers. We'll
15338 * try to disable everything in that case.
15340 * FIXME would be nice to be able to sanitize this state
15341 * without several WARNs, but for now let's take the easy
15344 return IS_GEN(dev_priv, 6) &&
15345 crtc_state->hw.active &&
15346 crtc_state->shared_dpll &&
15347 crtc_state->port_clock == 0;
15350 static void intel_sanitize_encoder(struct intel_encoder *encoder)
15352 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
15353 struct intel_connector *connector;
15354 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
15355 struct intel_crtc_state *crtc_state = crtc ?
15356 to_intel_crtc_state(crtc->base.state) : NULL;
15358 /* We need to check both for a crtc link (meaning that the
15359 * encoder is active and trying to read from a pipe) and the
15360 * pipe itself being active. */
15361 bool has_active_crtc = crtc_state &&
15362 crtc_state->hw.active;
15364 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
15365 drm_dbg_kms(&dev_priv->drm,
15366 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
15367 pipe_name(crtc->pipe));
15368 has_active_crtc = false;
15371 connector = intel_encoder_find_connector(encoder);
15372 if (connector && !has_active_crtc) {
15373 drm_dbg_kms(&dev_priv->drm,
15374 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15375 encoder->base.base.id,
15376 encoder->base.name);
15378 /* Connector is active, but has no active pipe. This is
15379 * fallout from our resume register restoring. Disable
15380 * the encoder manually again. */
15382 struct drm_encoder *best_encoder;
15384 drm_dbg_kms(&dev_priv->drm,
15385 "[ENCODER:%d:%s] manually disabled\n",
15386 encoder->base.base.id,
15387 encoder->base.name);
15389 /* avoid oopsing in case the hooks consult best_encoder */
15390 best_encoder = connector->base.state->best_encoder;
15391 connector->base.state->best_encoder = &encoder->base;
15393 /* FIXME NULL atomic state passed! */
15394 if (encoder->disable)
15395 encoder->disable(NULL, encoder, crtc_state,
15396 connector->base.state);
15397 if (encoder->post_disable)
15398 encoder->post_disable(NULL, encoder, crtc_state,
15399 connector->base.state);
15401 connector->base.state->best_encoder = best_encoder;
15403 encoder->base.crtc = NULL;
15405 /* Inconsistent output/port/pipe state happens presumably due to
15406 * a bug in one of the get_hw_state functions. Or someplace else
15407 * in our code, like the register restore mess on resume. Clamp
15408 * things to off as a safer default. */
15410 connector->base.dpms = DRM_MODE_DPMS_OFF;
15411 connector->base.encoder = NULL;
15414 /* notify opregion of the sanitized encoder state */
15415 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
15417 if (INTEL_GEN(dev_priv) >= 11)
15418 icl_sanitize_encoder_pll_mapping(encoder);
15421 /* FIXME read out full plane state for all planes */
15422 static void readout_plane_state(struct drm_i915_private *dev_priv)
15424 struct intel_plane *plane;
15425 struct intel_crtc *crtc;
15427 for_each_intel_plane(&dev_priv->drm, plane) {
15428 struct intel_plane_state *plane_state =
15429 to_intel_plane_state(plane->base.state);
15430 struct intel_crtc_state *crtc_state;
15431 enum pipe pipe = PIPE_A;
15434 visible = plane->get_hw_state(plane, &pipe);
15436 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15437 crtc_state = to_intel_crtc_state(crtc->base.state);
15439 intel_set_plane_visible(crtc_state, plane_state, visible);
15441 drm_dbg_kms(&dev_priv->drm,
15442 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15443 plane->base.base.id, plane->base.name,
15444 enableddisabled(visible), pipe_name(pipe));
15447 for_each_intel_crtc(&dev_priv->drm, crtc) {
15448 struct intel_crtc_state *crtc_state =
15449 to_intel_crtc_state(crtc->base.state);
15451 fixup_plane_bitmasks(crtc_state);
15455 static void intel_modeset_readout_hw_state(struct drm_device *dev)
15457 struct drm_i915_private *dev_priv = to_i915(dev);
15458 struct intel_cdclk_state *cdclk_state =
15459 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
15460 struct intel_dbuf_state *dbuf_state =
15461 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
15463 struct intel_crtc *crtc;
15464 struct intel_encoder *encoder;
15465 struct intel_connector *connector;
15466 struct drm_connector_list_iter conn_iter;
15467 u8 active_pipes = 0;
15469 for_each_intel_crtc(dev, crtc) {
15470 struct intel_crtc_state *crtc_state =
15471 to_intel_crtc_state(crtc->base.state);
15473 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
15474 intel_crtc_free_hw_state(crtc_state);
15475 intel_crtc_state_reset(crtc_state, crtc);
15477 intel_crtc_get_pipe_config(crtc_state);
15479 crtc_state->hw.enable = crtc_state->hw.active;
15481 crtc->base.enabled = crtc_state->hw.enable;
15482 crtc->active = crtc_state->hw.active;
15484 if (crtc_state->hw.active)
15485 active_pipes |= BIT(crtc->pipe);
15487 drm_dbg_kms(&dev_priv->drm,
15488 "[CRTC:%d:%s] hw state readout: %s\n",
15489 crtc->base.base.id, crtc->base.name,
15490 enableddisabled(crtc_state->hw.active));
15493 dev_priv->active_pipes = cdclk_state->active_pipes =
15494 dbuf_state->active_pipes = active_pipes;
15496 readout_plane_state(dev_priv);
15498 intel_dpll_readout_hw_state(dev_priv);
15500 for_each_intel_encoder(dev, encoder) {
15503 if (encoder->get_hw_state(encoder, &pipe)) {
15504 struct intel_crtc_state *crtc_state;
15506 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15507 crtc_state = to_intel_crtc_state(crtc->base.state);
15509 encoder->base.crtc = &crtc->base;
15510 intel_encoder_get_config(encoder, crtc_state);
15511 if (encoder->sync_state)
15512 encoder->sync_state(encoder, crtc_state);
15514 /* read out to slave crtc as well for bigjoiner */
15515 if (crtc_state->bigjoiner) {
15516 /* encoder should read be linked to bigjoiner master */
15517 WARN_ON(crtc_state->bigjoiner_slave);
15519 crtc = crtc_state->bigjoiner_linked_crtc;
15520 crtc_state = to_intel_crtc_state(crtc->base.state);
15521 intel_encoder_get_config(encoder, crtc_state);
15524 encoder->base.crtc = NULL;
15527 drm_dbg_kms(&dev_priv->drm,
15528 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
15529 encoder->base.base.id, encoder->base.name,
15530 enableddisabled(encoder->base.crtc),
15534 drm_connector_list_iter_begin(dev, &conn_iter);
15535 for_each_intel_connector_iter(connector, &conn_iter) {
15536 if (connector->get_hw_state(connector)) {
15537 struct intel_crtc_state *crtc_state;
15538 struct intel_crtc *crtc;
15540 connector->base.dpms = DRM_MODE_DPMS_ON;
15542 encoder = intel_attached_encoder(connector);
15543 connector->base.encoder = &encoder->base;
15545 crtc = to_intel_crtc(encoder->base.crtc);
15546 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
15548 if (crtc_state && crtc_state->hw.active) {
15550 * This has to be done during hardware readout
15551 * because anything calling .crtc_disable may
15552 * rely on the connector_mask being accurate.
15554 crtc_state->uapi.connector_mask |=
15555 drm_connector_mask(&connector->base);
15556 crtc_state->uapi.encoder_mask |=
15557 drm_encoder_mask(&encoder->base);
15560 connector->base.dpms = DRM_MODE_DPMS_OFF;
15561 connector->base.encoder = NULL;
15563 drm_dbg_kms(&dev_priv->drm,
15564 "[CONNECTOR:%d:%s] hw state readout: %s\n",
15565 connector->base.base.id, connector->base.name,
15566 enableddisabled(connector->base.encoder));
15568 drm_connector_list_iter_end(&conn_iter);
15570 for_each_intel_crtc(dev, crtc) {
15571 struct intel_bw_state *bw_state =
15572 to_intel_bw_state(dev_priv->bw_obj.state);
15573 struct intel_crtc_state *crtc_state =
15574 to_intel_crtc_state(crtc->base.state);
15575 struct intel_plane *plane;
15578 if (crtc_state->bigjoiner_slave)
15581 if (crtc_state->hw.active) {
15583 * The initial mode needs to be set in order to keep
15584 * the atomic core happy. It wants a valid mode if the
15585 * crtc's enabled, so we do the above call.
15587 * But we don't set all the derived state fully, hence
15588 * set a flag to indicate that a full recalculation is
15589 * needed on the next commit.
15591 crtc_state->inherited = true;
15593 intel_crtc_update_active_timings(crtc_state);
15595 intel_crtc_copy_hw_to_uapi_state(crtc_state);
15598 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
15599 const struct intel_plane_state *plane_state =
15600 to_intel_plane_state(plane->base.state);
15603 * FIXME don't have the fb yet, so can't
15604 * use intel_plane_data_rate() :(
15606 if (plane_state->uapi.visible)
15607 crtc_state->data_rate[plane->id] =
15608 4 * crtc_state->pixel_rate;
15610 * FIXME don't have the fb yet, so can't
15611 * use plane->min_cdclk() :(
15613 if (plane_state->uapi.visible && plane->min_cdclk) {
15614 if (crtc_state->double_wide ||
15615 INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
15616 crtc_state->min_cdclk[plane->id] =
15617 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
15619 crtc_state->min_cdclk[plane->id] =
15620 crtc_state->pixel_rate;
15622 drm_dbg_kms(&dev_priv->drm,
15623 "[PLANE:%d:%s] min_cdclk %d kHz\n",
15624 plane->base.base.id, plane->base.name,
15625 crtc_state->min_cdclk[plane->id]);
15628 if (crtc_state->hw.active) {
15629 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
15630 if (drm_WARN_ON(dev, min_cdclk < 0))
15634 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
15635 cdclk_state->min_voltage_level[crtc->pipe] =
15636 crtc_state->min_voltage_level;
15638 intel_bw_crtc_update(bw_state, crtc_state);
15640 intel_pipe_config_sanity_check(dev_priv, crtc_state);
15642 /* discard our incomplete slave state, copy it from master */
15643 if (crtc_state->bigjoiner && crtc_state->hw.active) {
15644 struct intel_crtc *slave = crtc_state->bigjoiner_linked_crtc;
15645 struct intel_crtc_state *slave_crtc_state =
15646 to_intel_crtc_state(slave->base.state);
15648 copy_bigjoiner_crtc_state(slave_crtc_state, crtc_state);
15649 slave->base.mode = crtc->base.mode;
15651 cdclk_state->min_cdclk[slave->pipe] = min_cdclk;
15652 cdclk_state->min_voltage_level[slave->pipe] =
15653 crtc_state->min_voltage_level;
15655 for_each_intel_plane_on_crtc(&dev_priv->drm, slave, plane) {
15656 const struct intel_plane_state *plane_state =
15657 to_intel_plane_state(plane->base.state);
15660 * FIXME don't have the fb yet, so can't
15661 * use intel_plane_data_rate() :(
15663 if (plane_state->uapi.visible)
15664 crtc_state->data_rate[plane->id] =
15665 4 * crtc_state->pixel_rate;
15667 crtc_state->data_rate[plane->id] = 0;
15670 intel_bw_crtc_update(bw_state, slave_crtc_state);
15671 drm_calc_timestamping_constants(&slave->base,
15672 &slave_crtc_state->hw.adjusted_mode);
15678 get_encoder_power_domains(struct drm_i915_private *dev_priv)
15680 struct intel_encoder *encoder;
15682 for_each_intel_encoder(&dev_priv->drm, encoder) {
15683 struct intel_crtc_state *crtc_state;
15685 if (!encoder->get_power_domains)
15689 * MST-primary and inactive encoders don't have a crtc state
15690 * and neither of these require any power domain references.
15692 if (!encoder->base.crtc)
15695 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
15696 encoder->get_power_domains(encoder, crtc_state);
15700 static void intel_early_display_was(struct drm_i915_private *dev_priv)
15703 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
15704 * Also known as Wa_14010480278.
15706 if (IS_GEN_RANGE(dev_priv, 10, 12) || IS_GEMINILAKE(dev_priv))
15707 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
15708 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
15710 if (IS_HASWELL(dev_priv)) {
15712 * WaRsPkgCStateDisplayPMReq:hsw
15713 * System hang if this isn't done before disabling all planes!
15715 intel_de_write(dev_priv, CHICKEN_PAR1_1,
15716 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15719 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) {
15720 /* Display WA #1142:kbl,cfl,cml */
15721 intel_de_rmw(dev_priv, CHICKEN_PAR1_1,
15722 KBL_ARB_FILL_SPARE_22, KBL_ARB_FILL_SPARE_22);
15723 intel_de_rmw(dev_priv, CHICKEN_MISC_2,
15724 KBL_ARB_FILL_SPARE_13 | KBL_ARB_FILL_SPARE_14,
15725 KBL_ARB_FILL_SPARE_14);
15729 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
15730 enum port port, i915_reg_t hdmi_reg)
15732 u32 val = intel_de_read(dev_priv, hdmi_reg);
15734 if (val & SDVO_ENABLE ||
15735 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
15738 drm_dbg_kms(&dev_priv->drm,
15739 "Sanitizing transcoder select for HDMI %c\n",
15742 val &= ~SDVO_PIPE_SEL_MASK;
15743 val |= SDVO_PIPE_SEL(PIPE_A);
15745 intel_de_write(dev_priv, hdmi_reg, val);
15748 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
15749 enum port port, i915_reg_t dp_reg)
15751 u32 val = intel_de_read(dev_priv, dp_reg);
15753 if (val & DP_PORT_EN ||
15754 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
15757 drm_dbg_kms(&dev_priv->drm,
15758 "Sanitizing transcoder select for DP %c\n",
15761 val &= ~DP_PIPE_SEL_MASK;
15762 val |= DP_PIPE_SEL(PIPE_A);
15764 intel_de_write(dev_priv, dp_reg, val);
15767 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
15770 * The BIOS may select transcoder B on some of the PCH
15771 * ports even it doesn't enable the port. This would trip
15772 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
15773 * Sanitize the transcoder select bits to prevent that. We
15774 * assume that the BIOS never actually enabled the port,
15775 * because if it did we'd actually have to toggle the port
15776 * on and back off to make the transcoder A select stick
15777 * (see. intel_dp_link_down(), intel_disable_hdmi(),
15778 * intel_disable_sdvo()).
15780 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
15781 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
15782 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
15784 /* PCH SDVOB multiplex with HDMIB */
15785 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
15786 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
15787 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
15790 /* Scan out the current hw modeset state,
15791 * and sanitizes it to the current state
15794 intel_modeset_setup_hw_state(struct drm_device *dev,
15795 struct drm_modeset_acquire_ctx *ctx)
15797 struct drm_i915_private *dev_priv = to_i915(dev);
15798 struct intel_encoder *encoder;
15799 struct intel_crtc *crtc;
15800 intel_wakeref_t wakeref;
15802 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15804 intel_early_display_was(dev_priv);
15805 intel_modeset_readout_hw_state(dev);
15807 /* HW state is read out, now we need to sanitize this mess. */
15809 /* Sanitize the TypeC port mode upfront, encoders depend on this */
15810 for_each_intel_encoder(dev, encoder) {
15811 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
15813 /* We need to sanitize only the MST primary port. */
15814 if (encoder->type != INTEL_OUTPUT_DP_MST &&
15815 intel_phy_is_tc(dev_priv, phy))
15816 intel_tc_port_sanitize(enc_to_dig_port(encoder));
15819 get_encoder_power_domains(dev_priv);
15821 if (HAS_PCH_IBX(dev_priv))
15822 ibx_sanitize_pch_ports(dev_priv);
15825 * intel_sanitize_plane_mapping() may need to do vblank
15826 * waits, so we need vblank interrupts restored beforehand.
15828 for_each_intel_crtc(&dev_priv->drm, crtc) {
15829 struct intel_crtc_state *crtc_state =
15830 to_intel_crtc_state(crtc->base.state);
15832 drm_crtc_vblank_reset(&crtc->base);
15834 if (crtc_state->hw.active)
15835 intel_crtc_vblank_on(crtc_state);
15838 intel_sanitize_plane_mapping(dev_priv);
15840 for_each_intel_encoder(dev, encoder)
15841 intel_sanitize_encoder(encoder);
15843 for_each_intel_crtc(&dev_priv->drm, crtc) {
15844 struct intel_crtc_state *crtc_state =
15845 to_intel_crtc_state(crtc->base.state);
15847 intel_sanitize_crtc(crtc, ctx);
15848 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
15851 intel_modeset_update_connector_atomic_state(dev);
15853 intel_dpll_sanitize_state(dev_priv);
15855 if (IS_G4X(dev_priv)) {
15856 g4x_wm_get_hw_state(dev_priv);
15857 g4x_wm_sanitize(dev_priv);
15858 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
15859 vlv_wm_get_hw_state(dev_priv);
15860 vlv_wm_sanitize(dev_priv);
15861 } else if (INTEL_GEN(dev_priv) >= 9) {
15862 skl_wm_get_hw_state(dev_priv);
15863 } else if (HAS_PCH_SPLIT(dev_priv)) {
15864 ilk_wm_get_hw_state(dev_priv);
15867 for_each_intel_crtc(dev, crtc) {
15868 struct intel_crtc_state *crtc_state =
15869 to_intel_crtc_state(crtc->base.state);
15872 put_domains = modeset_get_crtc_power_domains(crtc_state);
15873 if (drm_WARN_ON(dev, put_domains))
15874 modeset_put_crtc_power_domains(crtc, put_domains);
15877 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
15880 void intel_display_resume(struct drm_device *dev)
15882 struct drm_i915_private *dev_priv = to_i915(dev);
15883 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15884 struct drm_modeset_acquire_ctx ctx;
15887 dev_priv->modeset_restore_state = NULL;
15889 state->acquire_ctx = &ctx;
15891 drm_modeset_acquire_init(&ctx, 0);
15894 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15895 if (ret != -EDEADLK)
15898 drm_modeset_backoff(&ctx);
15902 ret = __intel_display_resume(dev, state, &ctx);
15904 intel_enable_ipc(dev_priv);
15905 drm_modeset_drop_locks(&ctx);
15906 drm_modeset_acquire_fini(&ctx);
15909 drm_err(&dev_priv->drm,
15910 "Restoring old state failed with %i\n", ret);
15912 drm_atomic_state_put(state);
15915 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
15917 struct intel_connector *connector;
15918 struct drm_connector_list_iter conn_iter;
15920 /* Kill all the work that may have been queued by hpd. */
15921 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
15922 for_each_intel_connector_iter(connector, &conn_iter) {
15923 if (connector->modeset_retry_work.func)
15924 cancel_work_sync(&connector->modeset_retry_work);
15925 if (connector->hdcp.shim) {
15926 cancel_delayed_work_sync(&connector->hdcp.check_work);
15927 cancel_work_sync(&connector->hdcp.prop_work);
15930 drm_connector_list_iter_end(&conn_iter);
15933 /* part #1: call before irq uninstall */
15934 void intel_modeset_driver_remove(struct drm_i915_private *i915)
15936 flush_workqueue(i915->flip_wq);
15937 flush_workqueue(i915->modeset_wq);
15939 flush_work(&i915->atomic_helper.free_work);
15940 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
15943 /* part #2: call after irq uninstall */
15944 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
15947 * Due to the hpd irq storm handling the hotplug work can re-arm the
15948 * poll handlers. Hence disable polling after hpd handling is shut down.
15950 intel_hpd_poll_fini(i915);
15953 * MST topology needs to be suspended so we don't have any calls to
15954 * fbdev after it's finalized. MST will be destroyed later as part of
15955 * drm_mode_config_cleanup()
15957 intel_dp_mst_suspend(i915);
15959 /* poll work can call into fbdev, hence clean that up afterwards */
15960 intel_fbdev_fini(i915);
15962 intel_unregister_dsm_handler();
15964 intel_fbc_global_disable(i915);
15966 /* flush any delayed tasks or pending work */
15967 flush_scheduled_work();
15969 intel_hdcp_component_fini(i915);
15971 intel_mode_config_cleanup(i915);
15973 intel_overlay_cleanup(i915);
15975 intel_gmbus_teardown(i915);
15977 destroy_workqueue(i915->flip_wq);
15978 destroy_workqueue(i915->modeset_wq);
15980 intel_fbc_cleanup_cfb(i915);
15983 /* part #3: call after gem init */
15984 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
15986 intel_csr_ucode_fini(i915);
15988 intel_power_domains_driver_remove(i915);
15990 intel_vga_unregister(i915);
15992 intel_bios_driver_remove(i915);
15995 #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15997 struct intel_display_error_state {
15999 u32 power_well_driver;
16001 struct intel_cursor_error_state {
16006 } cursor[I915_MAX_PIPES];
16008 struct intel_pipe_error_state {
16009 bool power_domain_on;
16012 } pipe[I915_MAX_PIPES];
16014 struct intel_plane_error_state {
16022 } plane[I915_MAX_PIPES];
16024 struct intel_transcoder_error_state {
16026 bool power_domain_on;
16027 enum transcoder cpu_transcoder;
16040 struct intel_display_error_state *
16041 intel_display_capture_error_state(struct drm_i915_private *dev_priv)
16043 struct intel_display_error_state *error;
16044 int transcoders[] = {
16053 BUILD_BUG_ON(ARRAY_SIZE(transcoders) != ARRAY_SIZE(error->transcoder));
16055 if (!HAS_DISPLAY(dev_priv))
16058 error = kzalloc(sizeof(*error), GFP_ATOMIC);
16062 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16063 error->power_well_driver = intel_de_read(dev_priv,
16064 HSW_PWR_WELL_CTL2);
16066 for_each_pipe(dev_priv, i) {
16067 error->pipe[i].power_domain_on =
16068 __intel_display_power_is_enabled(dev_priv,
16069 POWER_DOMAIN_PIPE(i));
16070 if (!error->pipe[i].power_domain_on)
16073 error->cursor[i].control = intel_de_read(dev_priv, CURCNTR(i));
16074 error->cursor[i].position = intel_de_read(dev_priv, CURPOS(i));
16075 error->cursor[i].base = intel_de_read(dev_priv, CURBASE(i));
16077 error->plane[i].control = intel_de_read(dev_priv, DSPCNTR(i));
16078 error->plane[i].stride = intel_de_read(dev_priv, DSPSTRIDE(i));
16079 if (INTEL_GEN(dev_priv) <= 3) {
16080 error->plane[i].size = intel_de_read(dev_priv,
16082 error->plane[i].pos = intel_de_read(dev_priv,
16085 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16086 error->plane[i].addr = intel_de_read(dev_priv,
16088 if (INTEL_GEN(dev_priv) >= 4) {
16089 error->plane[i].surface = intel_de_read(dev_priv,
16091 error->plane[i].tile_offset = intel_de_read(dev_priv,
16095 error->pipe[i].source = intel_de_read(dev_priv, PIPESRC(i));
16097 if (HAS_GMCH(dev_priv))
16098 error->pipe[i].stat = intel_de_read(dev_priv,
16102 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
16103 enum transcoder cpu_transcoder = transcoders[i];
16105 if (!HAS_TRANSCODER(dev_priv, cpu_transcoder))
16108 error->transcoder[i].available = true;
16109 error->transcoder[i].power_domain_on =
16110 __intel_display_power_is_enabled(dev_priv,
16111 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
16112 if (!error->transcoder[i].power_domain_on)
16115 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16117 error->transcoder[i].conf = intel_de_read(dev_priv,
16118 PIPECONF(cpu_transcoder));
16119 error->transcoder[i].htotal = intel_de_read(dev_priv,
16120 HTOTAL(cpu_transcoder));
16121 error->transcoder[i].hblank = intel_de_read(dev_priv,
16122 HBLANK(cpu_transcoder));
16123 error->transcoder[i].hsync = intel_de_read(dev_priv,
16124 HSYNC(cpu_transcoder));
16125 error->transcoder[i].vtotal = intel_de_read(dev_priv,
16126 VTOTAL(cpu_transcoder));
16127 error->transcoder[i].vblank = intel_de_read(dev_priv,
16128 VBLANK(cpu_transcoder));
16129 error->transcoder[i].vsync = intel_de_read(dev_priv,
16130 VSYNC(cpu_transcoder));
16136 #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16139 intel_display_print_error_state(struct drm_i915_error_state_buf *m,
16140 struct intel_display_error_state *error)
16142 struct drm_i915_private *dev_priv = m->i915;
16148 err_printf(m, "Num Pipes: %d\n", INTEL_NUM_PIPES(dev_priv));
16149 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
16150 err_printf(m, "PWR_WELL_CTL2: %08x\n",
16151 error->power_well_driver);
16152 for_each_pipe(dev_priv, i) {
16153 err_printf(m, "Pipe [%d]:\n", i);
16154 err_printf(m, " Power: %s\n",
16155 onoff(error->pipe[i].power_domain_on));
16156 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
16157 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
16159 err_printf(m, "Plane [%d]:\n", i);
16160 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16161 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
16162 if (INTEL_GEN(dev_priv) <= 3) {
16163 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16164 err_printf(m, " POS: %08x\n", error->plane[i].pos);
16166 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
16167 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
16168 if (INTEL_GEN(dev_priv) >= 4) {
16169 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16170 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
16173 err_printf(m, "Cursor [%d]:\n", i);
16174 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16175 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16176 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
16179 for (i = 0; i < ARRAY_SIZE(error->transcoder); i++) {
16180 if (!error->transcoder[i].available)
16183 err_printf(m, "CPU transcoder: %s\n",
16184 transcoder_name(error->transcoder[i].cpu_transcoder));
16185 err_printf(m, " Power: %s\n",
16186 onoff(error->transcoder[i].power_domain_on));
16187 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16188 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16189 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16190 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16191 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16192 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16193 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);