2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <acpi/video.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/intel-iommu.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/dma-resv.h>
34 #include <linux/slab.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_damage_helper.h>
40 #include <drm/drm_dp_helper.h>
41 #include <drm/drm_edid.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/drm_plane_helper.h>
44 #include <drm/drm_probe_helper.h>
45 #include <drm/drm_rect.h>
47 #include "display/intel_audio.h"
48 #include "display/intel_crt.h"
49 #include "display/intel_ddi.h"
50 #include "display/intel_display_debugfs.h"
51 #include "display/intel_dp.h"
52 #include "display/intel_dp_mst.h"
53 #include "display/intel_dpll.h"
54 #include "display/intel_dpll_mgr.h"
55 #include "display/intel_dsi.h"
56 #include "display/intel_dvo.h"
57 #include "display/intel_fb.h"
58 #include "display/intel_gmbus.h"
59 #include "display/intel_hdmi.h"
60 #include "display/intel_lvds.h"
61 #include "display/intel_sdvo.h"
62 #include "display/intel_tv.h"
63 #include "display/intel_vdsc.h"
64 #include "display/intel_vrr.h"
66 #include "gem/i915_gem_lmem.h"
67 #include "gem/i915_gem_object.h"
69 #include "gt/intel_rps.h"
70 #include "gt/gen8_ppgtt.h"
75 #include "intel_acpi.h"
76 #include "intel_atomic.h"
77 #include "intel_atomic_plane.h"
79 #include "intel_cdclk.h"
80 #include "intel_color.h"
81 #include "intel_crtc.h"
83 #include "intel_display_types.h"
84 #include "intel_dmc.h"
85 #include "intel_dp_link_training.h"
86 #include "intel_fbc.h"
87 #include "intel_fdi.h"
88 #include "intel_fbdev.h"
89 #include "intel_fifo_underrun.h"
90 #include "intel_frontbuffer.h"
91 #include "intel_hdcp.h"
92 #include "intel_hotplug.h"
93 #include "intel_overlay.h"
94 #include "intel_pipe_crc.h"
96 #include "intel_pps.h"
97 #include "intel_psr.h"
98 #include "intel_quirks.h"
99 #include "intel_sideband.h"
100 #include "intel_sprite.h"
101 #include "intel_tc.h"
102 #include "intel_vga.h"
103 #include "i9xx_plane.h"
104 #include "skl_scaler.h"
105 #include "skl_universal_plane.h"
107 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
108 struct intel_crtc_state *pipe_config);
109 static void ilk_pch_clock_get(struct intel_crtc *crtc,
110 struct intel_crtc_state *pipe_config);
112 static int intel_framebuffer_init(struct intel_framebuffer *ifb,
113 struct drm_i915_gem_object *obj,
114 struct drm_mode_fb_cmd2 *mode_cmd);
115 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
116 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
117 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
118 const struct intel_link_m_n *m_n,
119 const struct intel_link_m_n *m2_n2);
120 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
121 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state);
122 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state);
123 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
124 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
125 static void intel_modeset_setup_hw_state(struct drm_device *dev,
126 struct drm_modeset_acquire_ctx *ctx);
129 struct i915_address_space vm;
131 struct drm_i915_gem_object *obj;
132 struct i915_vma *vma;
136 #define i915_is_dpt(vm) ((vm)->is_dpt)
138 static inline struct i915_dpt *
139 i915_vm_to_dpt(struct i915_address_space *vm)
141 BUILD_BUG_ON(offsetof(struct i915_dpt, vm));
142 GEM_BUG_ON(!i915_is_dpt(vm));
143 return container_of(vm, struct i915_dpt, vm);
146 #define dpt_total_entries(dpt) ((dpt)->vm.total >> PAGE_SHIFT)
148 static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte)
153 static void dpt_insert_page(struct i915_address_space *vm,
156 enum i915_cache_level level,
159 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
160 gen8_pte_t __iomem *base = dpt->iomem;
162 gen8_set_pte(base + offset / I915_GTT_PAGE_SIZE,
163 vm->pte_encode(addr, level, flags));
166 static void dpt_insert_entries(struct i915_address_space *vm,
167 struct i915_vma *vma,
168 enum i915_cache_level level,
171 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
172 gen8_pte_t __iomem *base = dpt->iomem;
173 const gen8_pte_t pte_encode = vm->pte_encode(0, level, flags);
174 struct sgt_iter sgt_iter;
179 * Note that we ignore PTE_READ_ONLY here. The caller must be careful
180 * not to allow the user to override access to a read only page.
183 i = vma->node.start / I915_GTT_PAGE_SIZE;
184 for_each_sgt_daddr(addr, sgt_iter, vma->pages)
185 gen8_set_pte(&base[i++], pte_encode | addr);
188 static void dpt_clear_range(struct i915_address_space *vm,
189 u64 start, u64 length)
193 static void dpt_bind_vma(struct i915_address_space *vm,
194 struct i915_vm_pt_stash *stash,
195 struct i915_vma *vma,
196 enum i915_cache_level cache_level,
199 struct drm_i915_gem_object *obj = vma->obj;
202 /* Applicable to VLV (gen8+ do not support RO in the GGTT) */
204 if (vma->vm->has_read_only && i915_gem_object_is_readonly(obj))
205 pte_flags |= PTE_READ_ONLY;
206 if (i915_gem_object_is_lmem(obj))
209 vma->vm->insert_entries(vma->vm, vma, cache_level, pte_flags);
211 vma->page_sizes.gtt = I915_GTT_PAGE_SIZE;
214 * Without aliasing PPGTT there's no difference between
215 * GLOBAL/LOCAL_BIND, it's all the same ptes. Hence unconditionally
216 * upgrade to both bound if we bind either to avoid double-binding.
218 atomic_or(I915_VMA_GLOBAL_BIND | I915_VMA_LOCAL_BIND, &vma->flags);
221 static void dpt_unbind_vma(struct i915_address_space *vm, struct i915_vma *vma)
223 vm->clear_range(vm, vma->node.start, vma->size);
226 static void dpt_cleanup(struct i915_address_space *vm)
228 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
230 i915_gem_object_put(dpt->obj);
233 static struct i915_address_space *
234 intel_dpt_create(struct intel_framebuffer *fb)
236 struct drm_gem_object *obj = &intel_fb_obj(&fb->base)->base;
237 struct drm_i915_private *i915 = to_i915(obj->dev);
238 struct drm_i915_gem_object *dpt_obj;
239 struct i915_address_space *vm;
240 struct i915_dpt *dpt;
244 if (intel_fb_needs_pot_stride_remap(fb))
245 size = intel_remapped_info_size(&fb->remapped_view.gtt.remapped);
247 size = DIV_ROUND_UP_ULL(obj->size, I915_GTT_PAGE_SIZE);
249 size = round_up(size * sizeof(gen8_pte_t), I915_GTT_PAGE_SIZE);
252 dpt_obj = i915_gem_object_create_lmem(i915, size, 0);
254 dpt_obj = i915_gem_object_create_stolen(i915, size);
256 return ERR_CAST(dpt_obj);
258 ret = i915_gem_object_set_cache_level(dpt_obj, I915_CACHE_NONE);
260 i915_gem_object_put(dpt_obj);
264 dpt = kzalloc(sizeof(*dpt), GFP_KERNEL);
266 i915_gem_object_put(dpt_obj);
267 return ERR_PTR(-ENOMEM);
274 vm->dma = i915->drm.dev;
275 vm->total = (size / sizeof(gen8_pte_t)) * I915_GTT_PAGE_SIZE;
278 i915_address_space_init(vm, VM_CLASS_DPT);
280 vm->insert_page = dpt_insert_page;
281 vm->clear_range = dpt_clear_range;
282 vm->insert_entries = dpt_insert_entries;
283 vm->cleanup = dpt_cleanup;
285 vm->vma_ops.bind_vma = dpt_bind_vma;
286 vm->vma_ops.unbind_vma = dpt_unbind_vma;
287 vm->vma_ops.set_pages = ggtt_set_pages;
288 vm->vma_ops.clear_pages = clear_pages;
290 vm->pte_encode = gen8_ggtt_pte_encode;
297 static void intel_dpt_destroy(struct i915_address_space *vm)
299 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
301 i915_vm_close(&dpt->vm);
304 /* returns HPLL frequency in kHz */
305 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
307 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
309 /* Obtain SKU information */
310 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
311 CCK_FUSE_HPLL_FREQ_MASK;
313 return vco_freq[hpll_freq] * 1000;
316 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
317 const char *name, u32 reg, int ref_freq)
322 val = vlv_cck_read(dev_priv, reg);
323 divider = val & CCK_FREQUENCY_VALUES;
325 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
326 (divider << CCK_FREQUENCY_STATUS_SHIFT),
327 "%s change in progress\n", name);
329 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
332 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
333 const char *name, u32 reg)
337 vlv_cck_get(dev_priv);
339 if (dev_priv->hpll_freq == 0)
340 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
342 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
344 vlv_cck_put(dev_priv);
349 static void intel_update_czclk(struct drm_i915_private *dev_priv)
351 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
354 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
355 CCK_CZ_CLOCK_CONTROL);
357 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
358 dev_priv->czclk_freq);
361 /* WA Display #0827: Gen9:all */
363 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
366 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
367 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
369 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
370 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
373 /* Wa_2006604312:icl,ehl */
375 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
379 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
380 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
382 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
383 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
387 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
389 return crtc_state->master_transcoder != INVALID_TRANSCODER;
393 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
395 return crtc_state->sync_mode_slaves_mask != 0;
399 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
401 return is_trans_port_sync_master(crtc_state) ||
402 is_trans_port_sync_slave(crtc_state);
405 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
408 i915_reg_t reg = PIPEDSL(pipe);
412 if (DISPLAY_VER(dev_priv) == 2)
413 line_mask = DSL_LINEMASK_GEN2;
415 line_mask = DSL_LINEMASK_GEN3;
417 line1 = intel_de_read(dev_priv, reg) & line_mask;
419 line2 = intel_de_read(dev_priv, reg) & line_mask;
421 return line1 != line2;
424 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
426 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
427 enum pipe pipe = crtc->pipe;
429 /* Wait for the display line to settle/start moving */
430 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
431 drm_err(&dev_priv->drm,
432 "pipe %c scanline %s wait timed out\n",
433 pipe_name(pipe), onoff(state));
436 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
438 wait_for_pipe_scanline_moving(crtc, false);
441 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
443 wait_for_pipe_scanline_moving(crtc, true);
447 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
449 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
450 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
452 if (DISPLAY_VER(dev_priv) >= 4) {
453 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
454 i915_reg_t reg = PIPECONF(cpu_transcoder);
456 /* Wait for the Pipe State to go off */
457 if (intel_de_wait_for_clear(dev_priv, reg,
458 I965_PIPECONF_ACTIVE, 100))
459 drm_WARN(&dev_priv->drm, 1,
460 "pipe_off wait timed out\n");
462 intel_wait_for_pipe_scanline_stopped(crtc);
466 /* Only for pre-ILK configs */
467 void assert_pll(struct drm_i915_private *dev_priv,
468 enum pipe pipe, bool state)
473 val = intel_de_read(dev_priv, DPLL(pipe));
474 cur_state = !!(val & DPLL_VCO_ENABLE);
475 I915_STATE_WARN(cur_state != state,
476 "PLL state assertion failure (expected %s, current %s)\n",
477 onoff(state), onoff(cur_state));
480 /* XXX: the dsi pll is shared between MIPI DSI ports */
481 void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
486 vlv_cck_get(dev_priv);
487 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
488 vlv_cck_put(dev_priv);
490 cur_state = val & DSI_PLL_VCO_EN;
491 I915_STATE_WARN(cur_state != state,
492 "DSI PLL state assertion failure (expected %s, current %s)\n",
493 onoff(state), onoff(cur_state));
496 static void assert_fdi_tx(struct drm_i915_private *dev_priv,
497 enum pipe pipe, bool state)
501 if (HAS_DDI(dev_priv)) {
503 * DDI does not have a specific FDI_TX register.
505 * FDI is never fed from EDP transcoder
506 * so pipe->transcoder cast is fine here.
508 enum transcoder cpu_transcoder = (enum transcoder)pipe;
509 u32 val = intel_de_read(dev_priv,
510 TRANS_DDI_FUNC_CTL(cpu_transcoder));
511 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
513 u32 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
514 cur_state = !!(val & FDI_TX_ENABLE);
516 I915_STATE_WARN(cur_state != state,
517 "FDI TX state assertion failure (expected %s, current %s)\n",
518 onoff(state), onoff(cur_state));
520 #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
521 #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
523 static void assert_fdi_rx(struct drm_i915_private *dev_priv,
524 enum pipe pipe, bool state)
529 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
530 cur_state = !!(val & FDI_RX_ENABLE);
531 I915_STATE_WARN(cur_state != state,
532 "FDI RX state assertion failure (expected %s, current %s)\n",
533 onoff(state), onoff(cur_state));
535 #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
536 #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
538 static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
543 /* ILK FDI PLL is always enabled */
544 if (IS_IRONLAKE(dev_priv))
547 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
548 if (HAS_DDI(dev_priv))
551 val = intel_de_read(dev_priv, FDI_TX_CTL(pipe));
552 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
555 void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
556 enum pipe pipe, bool state)
561 val = intel_de_read(dev_priv, FDI_RX_CTL(pipe));
562 cur_state = !!(val & FDI_RX_PLL_ENABLE);
563 I915_STATE_WARN(cur_state != state,
564 "FDI RX PLL assertion failure (expected %s, current %s)\n",
565 onoff(state), onoff(cur_state));
568 void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
572 enum pipe panel_pipe = INVALID_PIPE;
575 if (drm_WARN_ON(&dev_priv->drm, HAS_DDI(dev_priv)))
578 if (HAS_PCH_SPLIT(dev_priv)) {
581 pp_reg = PP_CONTROL(0);
582 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
585 case PANEL_PORT_SELECT_LVDS:
586 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
588 case PANEL_PORT_SELECT_DPA:
589 g4x_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
591 case PANEL_PORT_SELECT_DPC:
592 g4x_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
594 case PANEL_PORT_SELECT_DPD:
595 g4x_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
598 MISSING_CASE(port_sel);
601 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
602 /* presumably write lock depends on pipe, not port select */
603 pp_reg = PP_CONTROL(pipe);
608 pp_reg = PP_CONTROL(0);
609 port_sel = intel_de_read(dev_priv, PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
611 drm_WARN_ON(&dev_priv->drm,
612 port_sel != PANEL_PORT_SELECT_LVDS);
613 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
616 val = intel_de_read(dev_priv, pp_reg);
617 if (!(val & PANEL_POWER_ON) ||
618 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
621 I915_STATE_WARN(panel_pipe == pipe && locked,
622 "panel assertion failure, pipe %c regs locked\n",
626 void assert_pipe(struct drm_i915_private *dev_priv,
627 enum transcoder cpu_transcoder, bool state)
630 enum intel_display_power_domain power_domain;
631 intel_wakeref_t wakeref;
633 /* we keep both pipes enabled on 830 */
634 if (IS_I830(dev_priv))
637 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
638 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
640 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
641 cur_state = !!(val & PIPECONF_ENABLE);
643 intel_display_power_put(dev_priv, power_domain, wakeref);
648 I915_STATE_WARN(cur_state != state,
649 "transcoder %s assertion failure (expected %s, current %s)\n",
650 transcoder_name(cpu_transcoder),
651 onoff(state), onoff(cur_state));
654 static void assert_plane(struct intel_plane *plane, bool state)
659 cur_state = plane->get_hw_state(plane, &pipe);
661 I915_STATE_WARN(cur_state != state,
662 "%s assertion failure (expected %s, current %s)\n",
663 plane->base.name, onoff(state), onoff(cur_state));
666 #define assert_plane_enabled(p) assert_plane(p, true)
667 #define assert_plane_disabled(p) assert_plane(p, false)
669 static void assert_planes_disabled(struct intel_crtc *crtc)
671 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
672 struct intel_plane *plane;
674 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
675 assert_plane_disabled(plane);
678 void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
684 val = intel_de_read(dev_priv, PCH_TRANSCONF(pipe));
685 enabled = !!(val & TRANS_ENABLE);
686 I915_STATE_WARN(enabled,
687 "transcoder assertion failed, should be off on pipe %c but is still active\n",
691 static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
692 enum pipe pipe, enum port port,
698 state = g4x_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
700 I915_STATE_WARN(state && port_pipe == pipe,
701 "PCH DP %c enabled on transcoder %c, should be disabled\n",
702 port_name(port), pipe_name(pipe));
704 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
705 "IBX PCH DP %c still using transcoder B\n",
709 static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
710 enum pipe pipe, enum port port,
716 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
718 I915_STATE_WARN(state && port_pipe == pipe,
719 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
720 port_name(port), pipe_name(pipe));
722 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
723 "IBX PCH HDMI %c still using transcoder B\n",
727 static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
732 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
733 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
734 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
736 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
738 "PCH VGA enabled on transcoder %c, should be disabled\n",
741 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
743 "PCH LVDS enabled on transcoder %c, should be disabled\n",
746 /* PCH SDVOB multiplex with HDMIB */
747 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
748 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
749 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
752 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
753 struct intel_digital_port *dig_port,
754 unsigned int expected_mask)
759 switch (dig_port->base.port) {
761 port_mask = DPLL_PORTB_READY_MASK;
765 port_mask = DPLL_PORTC_READY_MASK;
770 port_mask = DPLL_PORTD_READY_MASK;
771 dpll_reg = DPIO_PHY_STATUS;
777 if (intel_de_wait_for_register(dev_priv, dpll_reg,
778 port_mask, expected_mask, 1000))
779 drm_WARN(&dev_priv->drm, 1,
780 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
781 dig_port->base.base.base.id, dig_port->base.base.name,
782 intel_de_read(dev_priv, dpll_reg) & port_mask,
786 static void ilk_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
789 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
790 enum pipe pipe = crtc->pipe;
792 u32 val, pipeconf_val;
794 /* Make sure PCH DPLL is enabled */
795 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
797 /* FDI must be feeding us bits for PCH ports */
798 assert_fdi_tx_enabled(dev_priv, pipe);
799 assert_fdi_rx_enabled(dev_priv, pipe);
801 if (HAS_PCH_CPT(dev_priv)) {
802 reg = TRANS_CHICKEN2(pipe);
803 val = intel_de_read(dev_priv, reg);
805 * Workaround: Set the timing override bit
806 * before enabling the pch transcoder.
808 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
809 /* Configure frame start delay to match the CPU */
810 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
811 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
812 intel_de_write(dev_priv, reg, val);
815 reg = PCH_TRANSCONF(pipe);
816 val = intel_de_read(dev_priv, reg);
817 pipeconf_val = intel_de_read(dev_priv, PIPECONF(pipe));
819 if (HAS_PCH_IBX(dev_priv)) {
820 /* Configure frame start delay to match the CPU */
821 val &= ~TRANS_FRAME_START_DELAY_MASK;
822 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
825 * Make the BPC in transcoder be consistent with
826 * that in pipeconf reg. For HDMI we must use 8bpc
827 * here for both 8bpc and 12bpc.
829 val &= ~PIPECONF_BPC_MASK;
830 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
831 val |= PIPECONF_8BPC;
833 val |= pipeconf_val & PIPECONF_BPC_MASK;
836 val &= ~TRANS_INTERLACE_MASK;
837 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) {
838 if (HAS_PCH_IBX(dev_priv) &&
839 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
840 val |= TRANS_LEGACY_INTERLACED_ILK;
842 val |= TRANS_INTERLACED;
844 val |= TRANS_PROGRESSIVE;
847 intel_de_write(dev_priv, reg, val | TRANS_ENABLE);
848 if (intel_de_wait_for_set(dev_priv, reg, TRANS_STATE_ENABLE, 100))
849 drm_err(&dev_priv->drm, "failed to enable transcoder %c\n",
853 static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
854 enum transcoder cpu_transcoder)
856 u32 val, pipeconf_val;
858 /* FDI must be feeding us bits for PCH ports */
859 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
860 assert_fdi_rx_enabled(dev_priv, PIPE_A);
862 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
863 /* Workaround: set timing override bit. */
864 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
865 /* Configure frame start delay to match the CPU */
866 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
867 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
868 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
871 pipeconf_val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
873 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
874 PIPECONF_INTERLACED_ILK)
875 val |= TRANS_INTERLACED;
877 val |= TRANS_PROGRESSIVE;
879 intel_de_write(dev_priv, LPT_TRANSCONF, val);
880 if (intel_de_wait_for_set(dev_priv, LPT_TRANSCONF,
881 TRANS_STATE_ENABLE, 100))
882 drm_err(&dev_priv->drm, "Failed to enable PCH transcoder\n");
885 static void ilk_disable_pch_transcoder(struct drm_i915_private *dev_priv,
891 /* FDI relies on the transcoder */
892 assert_fdi_tx_disabled(dev_priv, pipe);
893 assert_fdi_rx_disabled(dev_priv, pipe);
895 /* Ports must be off as well */
896 assert_pch_ports_disabled(dev_priv, pipe);
898 reg = PCH_TRANSCONF(pipe);
899 val = intel_de_read(dev_priv, reg);
900 val &= ~TRANS_ENABLE;
901 intel_de_write(dev_priv, reg, val);
902 /* wait for PCH transcoder off, transcoder state */
903 if (intel_de_wait_for_clear(dev_priv, reg, TRANS_STATE_ENABLE, 50))
904 drm_err(&dev_priv->drm, "failed to disable transcoder %c\n",
907 if (HAS_PCH_CPT(dev_priv)) {
908 /* Workaround: Clear the timing override chicken bit again. */
909 reg = TRANS_CHICKEN2(pipe);
910 val = intel_de_read(dev_priv, reg);
911 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
912 intel_de_write(dev_priv, reg, val);
916 void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
920 val = intel_de_read(dev_priv, LPT_TRANSCONF);
921 val &= ~TRANS_ENABLE;
922 intel_de_write(dev_priv, LPT_TRANSCONF, val);
923 /* wait for PCH transcoder off, transcoder state */
924 if (intel_de_wait_for_clear(dev_priv, LPT_TRANSCONF,
925 TRANS_STATE_ENABLE, 50))
926 drm_err(&dev_priv->drm, "Failed to disable PCH transcoder\n");
928 /* Workaround: clear timing override bit. */
929 val = intel_de_read(dev_priv, TRANS_CHICKEN2(PIPE_A));
930 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
931 intel_de_write(dev_priv, TRANS_CHICKEN2(PIPE_A), val);
934 enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
936 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
938 if (HAS_PCH_LPT(dev_priv))
944 void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
946 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
947 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
948 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
949 enum pipe pipe = crtc->pipe;
953 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
955 assert_planes_disabled(crtc);
958 * A pipe without a PLL won't actually be able to drive bits from
959 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
962 if (HAS_GMCH(dev_priv)) {
963 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
964 assert_dsi_pll_enabled(dev_priv);
966 assert_pll_enabled(dev_priv, pipe);
968 if (new_crtc_state->has_pch_encoder) {
969 /* if driving the PCH, we need FDI enabled */
970 assert_fdi_rx_pll_enabled(dev_priv,
971 intel_crtc_pch_transcoder(crtc));
972 assert_fdi_tx_pll_enabled(dev_priv,
973 (enum pipe) cpu_transcoder);
975 /* FIXME: assert CPU port conditions for SNB+ */
978 /* Wa_22012358565:adlp */
979 if (DISPLAY_VER(dev_priv) == 13)
980 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
981 0, PIPE_ARB_USE_PROG_SLOTS);
983 reg = PIPECONF(cpu_transcoder);
984 val = intel_de_read(dev_priv, reg);
985 if (val & PIPECONF_ENABLE) {
986 /* we keep both pipes enabled on 830 */
987 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
991 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
992 intel_de_posting_read(dev_priv, reg);
995 * Until the pipe starts PIPEDSL reads will return a stale value,
996 * which causes an apparent vblank timestamp jump when PIPEDSL
997 * resets to its proper value. That also messes up the frame count
998 * when it's derived from the timestamps. So let's wait for the
999 * pipe to start properly before we call drm_crtc_vblank_on()
1001 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
1002 intel_wait_for_pipe_scanline_moving(crtc);
1005 void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
1007 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1009 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
1010 enum pipe pipe = crtc->pipe;
1014 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
1017 * Make sure planes won't keep trying to pump pixels to us,
1018 * or we might hang the display.
1020 assert_planes_disabled(crtc);
1022 reg = PIPECONF(cpu_transcoder);
1023 val = intel_de_read(dev_priv, reg);
1024 if ((val & PIPECONF_ENABLE) == 0)
1028 * Double wide has implications for planes
1029 * so best keep it disabled when not needed.
1031 if (old_crtc_state->double_wide)
1032 val &= ~PIPECONF_DOUBLE_WIDE;
1034 /* Don't disable pipe or pipe PLLs if needed */
1035 if (!IS_I830(dev_priv))
1036 val &= ~PIPECONF_ENABLE;
1038 intel_de_write(dev_priv, reg, val);
1039 if ((val & PIPECONF_ENABLE) == 0)
1040 intel_wait_for_pipe_off(old_crtc_state);
1044 intel_format_info_is_yuv_semiplanar(const struct drm_format_info *info,
1047 return info->is_yuv &&
1048 info->num_planes == (is_ccs_modifier(modifier) ? 4 : 2);
1052 intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
1054 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1055 unsigned int cpp = fb->format->cpp[color_plane];
1057 switch (fb->modifier) {
1058 case DRM_FORMAT_MOD_LINEAR:
1059 return intel_tile_size(dev_priv);
1060 case I915_FORMAT_MOD_X_TILED:
1061 if (DISPLAY_VER(dev_priv) == 2)
1065 case I915_FORMAT_MOD_Y_TILED_CCS:
1066 if (is_ccs_plane(fb, color_plane))
1069 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1070 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1071 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1072 if (is_ccs_plane(fb, color_plane))
1075 case I915_FORMAT_MOD_Y_TILED:
1076 if (DISPLAY_VER(dev_priv) == 2 || HAS_128_BYTE_Y_TILING(dev_priv))
1080 case I915_FORMAT_MOD_Yf_TILED_CCS:
1081 if (is_ccs_plane(fb, color_plane))
1084 case I915_FORMAT_MOD_Yf_TILED:
1100 MISSING_CASE(fb->modifier);
1106 intel_fb_align_height(const struct drm_framebuffer *fb,
1107 int color_plane, unsigned int height)
1109 unsigned int tile_height = intel_tile_height(fb, color_plane);
1111 return ALIGN(height, tile_height);
1114 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1116 unsigned int size = 0;
1119 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1120 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
1125 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
1127 unsigned int size = 0;
1130 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++)
1131 size += rem_info->plane[i].dst_stride * rem_info->plane[i].height;
1136 static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
1138 if (DISPLAY_VER(dev_priv) >= 9)
1140 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
1141 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
1143 else if (DISPLAY_VER(dev_priv) >= 4)
1149 static bool has_async_flips(struct drm_i915_private *i915)
1151 return DISPLAY_VER(i915) >= 5;
1154 unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
1157 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1159 if (intel_fb_uses_dpt(fb))
1162 /* AUX_DIST needs only 4K alignment */
1163 if (is_ccs_plane(fb, color_plane))
1166 if (is_semiplanar_uv_plane(fb, color_plane)) {
1168 * TODO: cross-check wrt. the bspec stride in bytes * 64 bytes
1169 * alignment for linear UV planes on all platforms.
1171 if (DISPLAY_VER(dev_priv) >= 12) {
1172 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
1173 return intel_linear_alignment(dev_priv);
1175 return intel_tile_row_size(fb, color_plane);
1181 drm_WARN_ON(&dev_priv->drm, color_plane != 0);
1183 switch (fb->modifier) {
1184 case DRM_FORMAT_MOD_LINEAR:
1185 return intel_linear_alignment(dev_priv);
1186 case I915_FORMAT_MOD_X_TILED:
1187 if (has_async_flips(dev_priv))
1190 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1191 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1192 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1194 case I915_FORMAT_MOD_Y_TILED_CCS:
1195 case I915_FORMAT_MOD_Yf_TILED_CCS:
1196 case I915_FORMAT_MOD_Y_TILED:
1197 case I915_FORMAT_MOD_Yf_TILED:
1198 return 1 * 1024 * 1024;
1200 MISSING_CASE(fb->modifier);
1205 static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
1207 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1208 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1210 return DISPLAY_VER(dev_priv) < 4 ||
1212 plane_state->view.gtt.type == I915_GGTT_VIEW_NORMAL);
1215 static struct i915_vma *
1216 intel_pin_fb_obj_dpt(struct drm_framebuffer *fb,
1217 const struct i915_ggtt_view *view,
1219 unsigned long *out_flags,
1220 struct i915_address_space *vm)
1222 struct drm_device *dev = fb->dev;
1223 struct drm_i915_private *dev_priv = to_i915(dev);
1224 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1225 struct i915_vma *vma;
1229 if (WARN_ON(!i915_gem_object_is_framebuffer(obj)))
1230 return ERR_PTR(-EINVAL);
1232 alignment = 4096 * 512;
1234 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
1236 ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
1242 vma = i915_vma_instance(obj, vm, view);
1246 if (i915_vma_misplaced(vma, 0, alignment, 0)) {
1247 ret = i915_vma_unbind(vma);
1254 ret = i915_vma_pin(vma, 0, alignment, PIN_GLOBAL);
1260 vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
1262 i915_gem_object_flush_if_display(obj);
1266 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
1272 intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
1274 const struct i915_ggtt_view *view,
1276 unsigned long *out_flags)
1278 struct drm_device *dev = fb->dev;
1279 struct drm_i915_private *dev_priv = to_i915(dev);
1280 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1281 intel_wakeref_t wakeref;
1282 struct i915_gem_ww_ctx ww;
1283 struct i915_vma *vma;
1284 unsigned int pinctl;
1288 if (drm_WARN_ON(dev, !i915_gem_object_is_framebuffer(obj)))
1289 return ERR_PTR(-EINVAL);
1292 alignment = intel_cursor_alignment(dev_priv);
1294 alignment = intel_surf_alignment(fb, 0);
1295 if (drm_WARN_ON(dev, alignment && !is_power_of_2(alignment)))
1296 return ERR_PTR(-EINVAL);
1298 /* Note that the w/a also requires 64 PTE of padding following the
1299 * bo. We currently fill all unused PTE with the shadow page and so
1300 * we should always have valid PTE following the scanout preventing
1303 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
1304 alignment = 256 * 1024;
1307 * Global gtt pte registers are special registers which actually forward
1308 * writes to a chunk of system memory. Which means that there is no risk
1309 * that the register values disappear as soon as we call
1310 * intel_runtime_pm_put(), so it is correct to wrap only the
1311 * pin/unpin/fence and not more.
1313 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
1315 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
1318 * Valleyview is definitely limited to scanning out the first
1319 * 512MiB. Lets presume this behaviour was inherited from the
1320 * g4x display engine and that all earlier gen are similarly
1321 * limited. Testing suggests that it is a little more
1322 * complicated than this. For example, Cherryview appears quite
1323 * happy to scanout from anywhere within its global aperture.
1326 if (HAS_GMCH(dev_priv))
1327 pinctl |= PIN_MAPPABLE;
1329 i915_gem_ww_ctx_init(&ww, true);
1331 ret = i915_gem_object_lock(obj, &ww);
1332 if (!ret && phys_cursor)
1333 ret = i915_gem_object_attach_phys(obj, alignment);
1335 ret = i915_gem_object_pin_pages(obj);
1340 vma = i915_gem_object_pin_to_display_plane(obj, &ww, alignment,
1348 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
1350 * Install a fence for tiled scan-out. Pre-i965 always needs a
1351 * fence, whereas 965+ only requires a fence if using
1352 * framebuffer compression. For simplicity, we always, when
1353 * possible, install a fence as the cost is not that onerous.
1355 * If we fail to fence the tiled scanout, then either the
1356 * modeset will reject the change (which is highly unlikely as
1357 * the affected systems, all but one, do not have unmappable
1358 * space) or we will not be able to enable full powersaving
1359 * techniques (also likely not to apply due to various limits
1360 * FBC and the like impose on the size of the buffer, which
1361 * presumably we violated anyway with this unmappable buffer).
1362 * Anyway, it is presumably better to stumble onwards with
1363 * something and try to run the system in a "less than optimal"
1364 * mode that matches the user configuration.
1366 ret = i915_vma_pin_fence(vma);
1367 if (ret != 0 && DISPLAY_VER(dev_priv) < 4) {
1368 i915_vma_unpin(vma);
1374 *out_flags |= PLANE_HAS_FENCE;
1380 i915_gem_object_unpin_pages(obj);
1382 if (ret == -EDEADLK) {
1383 ret = i915_gem_ww_ctx_backoff(&ww);
1387 i915_gem_ww_ctx_fini(&ww);
1391 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
1392 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
1396 void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
1398 if (flags & PLANE_HAS_FENCE)
1399 i915_vma_unpin_fence(vma);
1400 i915_vma_unpin(vma);
1405 * Convert the x/y offsets into a linear offset.
1406 * Only valid with 0/180 degree rotation, which is fine since linear
1407 * offset is only used with linear buffers on pre-hsw and tiled buffers
1408 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
1410 u32 intel_fb_xy_to_linear(int x, int y,
1411 const struct intel_plane_state *state,
1414 const struct drm_framebuffer *fb = state->hw.fb;
1415 unsigned int cpp = fb->format->cpp[color_plane];
1416 unsigned int pitch = state->view.color_plane[color_plane].stride;
1418 return y * pitch + x * cpp;
1422 * Add the x/y offsets derived from fb->offsets[] to the user
1423 * specified plane src x/y offsets. The resulting x/y offsets
1424 * specify the start of scanout from the beginning of the gtt mapping.
1426 void intel_add_fb_offsets(int *x, int *y,
1427 const struct intel_plane_state *state,
1431 *x += state->view.color_plane[color_plane].x;
1432 *y += state->view.color_plane[color_plane].y;
1435 static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
1437 switch (fb_modifier) {
1438 case I915_FORMAT_MOD_X_TILED:
1439 return I915_TILING_X;
1440 case I915_FORMAT_MOD_Y_TILED:
1441 case I915_FORMAT_MOD_Y_TILED_CCS:
1442 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1443 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1444 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1445 return I915_TILING_Y;
1447 return I915_TILING_NONE;
1452 * From the Sky Lake PRM:
1453 * "The Color Control Surface (CCS) contains the compression status of
1454 * the cache-line pairs. The compression state of the cache-line pair
1455 * is specified by 2 bits in the CCS. Each CCS cache-line represents
1456 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
1457 * cache-line-pairs. CCS is always Y tiled."
1459 * Since cache line pairs refers to horizontally adjacent cache lines,
1460 * each cache line in the CCS corresponds to an area of 32x16 cache
1461 * lines on the main surface. Since each pixel is 4 bytes, this gives
1462 * us a ratio of one byte in the CCS for each 8x16 pixels in the
1465 static const struct drm_format_info skl_ccs_formats[] = {
1466 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1467 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1468 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1469 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
1470 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1471 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1472 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1473 .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, .has_alpha = true, },
1477 * Gen-12 compression uses 4 bits of CCS data for each cache line pair in the
1478 * main surface. And each 64B CCS cache line represents an area of 4x1 Y-tiles
1479 * in the main surface. With 4 byte pixels and each Y-tile having dimensions of
1480 * 32x32 pixels, the ratio turns out to 1B in the CCS for every 2x32 pixels in
1483 static const struct drm_format_info gen12_ccs_formats[] = {
1484 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2,
1485 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1486 .hsub = 1, .vsub = 1, },
1487 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2,
1488 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1489 .hsub = 1, .vsub = 1, },
1490 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2,
1491 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1492 .hsub = 1, .vsub = 1, .has_alpha = true },
1493 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2,
1494 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1495 .hsub = 1, .vsub = 1, .has_alpha = true },
1496 { .format = DRM_FORMAT_YUYV, .num_planes = 2,
1497 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1498 .hsub = 2, .vsub = 1, .is_yuv = true },
1499 { .format = DRM_FORMAT_YVYU, .num_planes = 2,
1500 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1501 .hsub = 2, .vsub = 1, .is_yuv = true },
1502 { .format = DRM_FORMAT_UYVY, .num_planes = 2,
1503 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1504 .hsub = 2, .vsub = 1, .is_yuv = true },
1505 { .format = DRM_FORMAT_VYUY, .num_planes = 2,
1506 .char_per_block = { 2, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1507 .hsub = 2, .vsub = 1, .is_yuv = true },
1508 { .format = DRM_FORMAT_XYUV8888, .num_planes = 2,
1509 .char_per_block = { 4, 1 }, .block_w = { 1, 2 }, .block_h = { 1, 1 },
1510 .hsub = 1, .vsub = 1, .is_yuv = true },
1511 { .format = DRM_FORMAT_NV12, .num_planes = 4,
1512 .char_per_block = { 1, 2, 1, 1 }, .block_w = { 1, 1, 4, 4 }, .block_h = { 1, 1, 1, 1 },
1513 .hsub = 2, .vsub = 2, .is_yuv = true },
1514 { .format = DRM_FORMAT_P010, .num_planes = 4,
1515 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1516 .hsub = 2, .vsub = 2, .is_yuv = true },
1517 { .format = DRM_FORMAT_P012, .num_planes = 4,
1518 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1519 .hsub = 2, .vsub = 2, .is_yuv = true },
1520 { .format = DRM_FORMAT_P016, .num_planes = 4,
1521 .char_per_block = { 2, 4, 1, 1 }, .block_w = { 1, 1, 2, 2 }, .block_h = { 1, 1, 1, 1 },
1522 .hsub = 2, .vsub = 2, .is_yuv = true },
1526 * Same as gen12_ccs_formats[] above, but with additional surface used
1527 * to pass Clear Color information in plane 2 with 64 bits of data.
1529 static const struct drm_format_info gen12_ccs_cc_formats[] = {
1530 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 3,
1531 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1532 .hsub = 1, .vsub = 1, },
1533 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 3,
1534 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1535 .hsub = 1, .vsub = 1, },
1536 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 3,
1537 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1538 .hsub = 1, .vsub = 1, .has_alpha = true },
1539 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 3,
1540 .char_per_block = { 4, 1, 0 }, .block_w = { 1, 2, 2 }, .block_h = { 1, 1, 1 },
1541 .hsub = 1, .vsub = 1, .has_alpha = true },
1544 static const struct drm_format_info *
1545 lookup_format_info(const struct drm_format_info formats[],
1546 int num_formats, u32 format)
1550 for (i = 0; i < num_formats; i++) {
1551 if (formats[i].format == format)
1558 static const struct drm_format_info *
1559 intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
1561 switch (cmd->modifier[0]) {
1562 case I915_FORMAT_MOD_Y_TILED_CCS:
1563 case I915_FORMAT_MOD_Yf_TILED_CCS:
1564 return lookup_format_info(skl_ccs_formats,
1565 ARRAY_SIZE(skl_ccs_formats),
1567 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
1568 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
1569 return lookup_format_info(gen12_ccs_formats,
1570 ARRAY_SIZE(gen12_ccs_formats),
1572 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
1573 return lookup_format_info(gen12_ccs_cc_formats,
1574 ARRAY_SIZE(gen12_ccs_cc_formats),
1581 static int gen12_ccs_aux_stride(struct drm_framebuffer *fb, int ccs_plane)
1583 return DIV_ROUND_UP(fb->pitches[skl_ccs_to_main_plane(fb, ccs_plane)],
1587 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
1588 u32 pixel_format, u64 modifier)
1590 struct intel_crtc *crtc;
1591 struct intel_plane *plane;
1593 if (!HAS_DISPLAY(dev_priv))
1597 * We assume the primary plane for pipe A has
1598 * the highest stride limits of them all,
1599 * if in case pipe A is disabled, use the first pipe from pipe_mask.
1601 crtc = intel_get_first_crtc(dev_priv);
1605 plane = to_intel_plane(crtc->base.primary);
1607 return plane->max_stride(plane, pixel_format, modifier,
1612 u32 intel_fb_max_stride(struct drm_i915_private *dev_priv,
1613 u32 pixel_format, u64 modifier)
1616 * Arbitrary limit for gen4+ chosen to match the
1617 * render engine max stride.
1619 * The new CCS hash mode makes remapping impossible
1621 if (DISPLAY_VER(dev_priv) < 4 || is_ccs_modifier(modifier) ||
1622 intel_modifier_uses_dpt(dev_priv, modifier))
1623 return intel_plane_fb_max_stride(dev_priv, pixel_format, modifier);
1624 else if (DISPLAY_VER(dev_priv) >= 7)
1631 intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
1633 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1636 if (is_surface_linear(fb, color_plane)) {
1637 u32 max_stride = intel_plane_fb_max_stride(dev_priv,
1642 * To make remapping with linear generally feasible
1643 * we need the stride to be page aligned.
1645 if (fb->pitches[color_plane] > max_stride &&
1646 !is_ccs_modifier(fb->modifier))
1647 return intel_tile_size(dev_priv);
1652 tile_width = intel_tile_width_bytes(fb, color_plane);
1653 if (is_ccs_modifier(fb->modifier)) {
1655 * Display WA #0531: skl,bxt,kbl,glk
1657 * Render decompression and plane width > 3840
1658 * combined with horizontal panning requires the
1659 * plane stride to be a multiple of 4. We'll just
1660 * require the entire fb to accommodate that to avoid
1661 * potential runtime errors at plane configuration time.
1663 if ((DISPLAY_VER(dev_priv) == 9 || IS_GEMINILAKE(dev_priv)) &&
1664 color_plane == 0 && fb->width > 3840)
1667 * The main surface pitch must be padded to a multiple of four
1670 else if (DISPLAY_VER(dev_priv) >= 12)
1676 static struct i915_vma *
1677 initial_plane_vma(struct drm_i915_private *i915,
1678 struct intel_initial_plane_config *plane_config)
1680 struct drm_i915_gem_object *obj;
1681 struct i915_vma *vma;
1684 if (plane_config->size == 0)
1687 base = round_down(plane_config->base,
1688 I915_GTT_MIN_ALIGNMENT);
1689 size = round_up(plane_config->base + plane_config->size,
1690 I915_GTT_MIN_ALIGNMENT);
1694 * If the FB is too big, just don't use it since fbdev is not very
1695 * important and we should probably use that space with FBC or other
1698 if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE) &&
1699 size * 2 > i915->stolen_usable_size)
1702 obj = i915_gem_object_create_stolen_for_preallocated(i915, base, size);
1707 * Mark it WT ahead of time to avoid changing the
1708 * cache_level during fbdev initialization. The
1709 * unbind there would get stuck waiting for rcu.
1711 i915_gem_object_set_cache_coherency(obj, HAS_WT(i915) ?
1712 I915_CACHE_WT : I915_CACHE_NONE);
1714 switch (plane_config->tiling) {
1715 case I915_TILING_NONE:
1719 obj->tiling_and_stride =
1720 plane_config->fb->base.pitches[0] |
1721 plane_config->tiling;
1724 MISSING_CASE(plane_config->tiling);
1728 vma = i915_vma_instance(obj, &i915->ggtt.vm, NULL);
1732 if (i915_ggtt_pin(vma, NULL, 0, PIN_MAPPABLE | PIN_OFFSET_FIXED | base))
1735 if (i915_gem_object_is_tiled(obj) &&
1736 !i915_vma_is_map_and_fenceable(vma))
1742 i915_gem_object_put(obj);
1747 intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
1748 struct intel_initial_plane_config *plane_config)
1750 struct drm_device *dev = crtc->base.dev;
1751 struct drm_i915_private *dev_priv = to_i915(dev);
1752 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
1753 struct drm_framebuffer *fb = &plane_config->fb->base;
1754 struct i915_vma *vma;
1756 switch (fb->modifier) {
1757 case DRM_FORMAT_MOD_LINEAR:
1758 case I915_FORMAT_MOD_X_TILED:
1759 case I915_FORMAT_MOD_Y_TILED:
1762 drm_dbg(&dev_priv->drm,
1763 "Unsupported modifier for initial FB: 0x%llx\n",
1768 vma = initial_plane_vma(dev_priv, plane_config);
1772 mode_cmd.pixel_format = fb->format->format;
1773 mode_cmd.width = fb->width;
1774 mode_cmd.height = fb->height;
1775 mode_cmd.pitches[0] = fb->pitches[0];
1776 mode_cmd.modifier[0] = fb->modifier;
1777 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
1779 if (intel_framebuffer_init(to_intel_framebuffer(fb),
1780 vma->obj, &mode_cmd)) {
1781 drm_dbg_kms(&dev_priv->drm, "intel fb init failed\n");
1785 plane_config->vma = vma;
1794 intel_set_plane_visible(struct intel_crtc_state *crtc_state,
1795 struct intel_plane_state *plane_state,
1798 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1800 plane_state->uapi.visible = visible;
1803 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
1805 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
1808 static void fixup_plane_bitmasks(struct intel_crtc_state *crtc_state)
1810 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1811 struct drm_plane *plane;
1814 * Active_planes aliases if multiple "primary" or cursor planes
1815 * have been used on the same (or wrong) pipe. plane_mask uses
1816 * unique ids, hence we can use that to reconstruct active_planes.
1818 crtc_state->enabled_planes = 0;
1819 crtc_state->active_planes = 0;
1821 drm_for_each_plane_mask(plane, &dev_priv->drm,
1822 crtc_state->uapi.plane_mask) {
1823 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
1824 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
1828 static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
1829 struct intel_plane *plane)
1831 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1832 struct intel_crtc_state *crtc_state =
1833 to_intel_crtc_state(crtc->base.state);
1834 struct intel_plane_state *plane_state =
1835 to_intel_plane_state(plane->base.state);
1837 drm_dbg_kms(&dev_priv->drm,
1838 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
1839 plane->base.base.id, plane->base.name,
1840 crtc->base.base.id, crtc->base.name);
1842 intel_set_plane_visible(crtc_state, plane_state, false);
1843 fixup_plane_bitmasks(crtc_state);
1844 crtc_state->data_rate[plane->id] = 0;
1845 crtc_state->min_cdclk[plane->id] = 0;
1847 if (plane->id == PLANE_PRIMARY)
1848 hsw_disable_ips(crtc_state);
1851 * Vblank time updates from the shadow to live plane control register
1852 * are blocked if the memory self-refresh mode is active at that
1853 * moment. So to make sure the plane gets truly disabled, disable
1854 * first the self-refresh mode. The self-refresh enable bit in turn
1855 * will be checked/applied by the HW only at the next frame start
1856 * event which is after the vblank start event, so we need to have a
1857 * wait-for-vblank between disabling the plane and the pipe.
1859 if (HAS_GMCH(dev_priv) &&
1860 intel_set_memory_cxsr(dev_priv, false))
1861 intel_wait_for_vblank(dev_priv, crtc->pipe);
1864 * Gen2 reports pipe underruns whenever all planes are disabled.
1865 * So disable underrun reporting before all the planes get disabled.
1867 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
1868 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
1870 intel_disable_plane(plane, crtc_state);
1871 intel_wait_for_vblank(dev_priv, crtc->pipe);
1874 static struct i915_vma *intel_dpt_pin(struct i915_address_space *vm)
1876 struct drm_i915_private *i915 = vm->i915;
1877 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
1878 intel_wakeref_t wakeref;
1879 struct i915_vma *vma;
1880 void __iomem *iomem;
1882 wakeref = intel_runtime_pm_get(&i915->runtime_pm);
1883 atomic_inc(&i915->gpu_error.pending_fb_pin);
1885 vma = i915_gem_object_ggtt_pin(dpt->obj, NULL, 0, 4096,
1886 HAS_LMEM(i915) ? 0 : PIN_MAPPABLE);
1890 iomem = i915_vma_pin_iomap(vma);
1891 i915_vma_unpin(vma);
1892 if (IS_ERR(iomem)) {
1903 atomic_dec(&i915->gpu_error.pending_fb_pin);
1904 intel_runtime_pm_put(&i915->runtime_pm, wakeref);
1909 static void intel_dpt_unpin(struct i915_address_space *vm)
1911 struct i915_dpt *dpt = i915_vm_to_dpt(vm);
1913 i915_vma_unpin_iomap(dpt->vma);
1914 i915_vma_put(dpt->vma);
1918 intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
1919 struct intel_initial_plane_config *plane_config)
1921 struct drm_device *dev = intel_crtc->base.dev;
1922 struct drm_i915_private *dev_priv = to_i915(dev);
1924 struct drm_plane *primary = intel_crtc->base.primary;
1925 struct drm_plane_state *plane_state = primary->state;
1926 struct intel_plane *intel_plane = to_intel_plane(primary);
1927 struct intel_plane_state *intel_state =
1928 to_intel_plane_state(plane_state);
1929 struct intel_crtc_state *crtc_state =
1930 to_intel_crtc_state(intel_crtc->base.state);
1931 struct drm_framebuffer *fb;
1932 struct i915_vma *vma;
1936 * Disable planes if get_initial_plane_config() failed.
1937 * Make sure things work if the surface base is not page aligned.
1939 if (!plane_config->fb)
1942 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
1943 fb = &plane_config->fb->base;
1944 vma = plane_config->vma;
1949 * Failed to alloc the obj, check to see if we should share
1950 * an fb with another CRTC instead
1952 for_each_crtc(dev, c) {
1953 struct intel_plane_state *state;
1955 if (c == &intel_crtc->base)
1958 if (!to_intel_crtc_state(c->state)->uapi.active)
1961 state = to_intel_plane_state(c->primary->state);
1962 if (!state->ggtt_vma)
1965 if (intel_plane_ggtt_offset(state) == plane_config->base) {
1967 vma = state->ggtt_vma;
1973 * We've failed to reconstruct the BIOS FB. Current display state
1974 * indicates that the primary plane is visible, but has a NULL FB,
1975 * which will lead to problems later if we don't fix it up. The
1976 * simplest solution is to just disable the primary plane now and
1977 * pretend the BIOS never had it enabled.
1979 intel_plane_disable_noatomic(intel_crtc, intel_plane);
1980 if (crtc_state->bigjoiner) {
1981 struct intel_crtc *slave =
1982 crtc_state->bigjoiner_linked_crtc;
1983 intel_plane_disable_noatomic(slave, to_intel_plane(slave->base.primary));
1989 plane_state->rotation = plane_config->rotation;
1990 intel_fb_fill_view(to_intel_framebuffer(fb), plane_state->rotation,
1991 &intel_state->view);
1993 __i915_vma_pin(vma);
1994 intel_state->ggtt_vma = i915_vma_get(vma);
1995 if (intel_plane_uses_fence(intel_state) && i915_vma_pin_fence(vma) == 0)
1997 intel_state->flags |= PLANE_HAS_FENCE;
1999 plane_state->src_x = 0;
2000 plane_state->src_y = 0;
2001 plane_state->src_w = fb->width << 16;
2002 plane_state->src_h = fb->height << 16;
2004 plane_state->crtc_x = 0;
2005 plane_state->crtc_y = 0;
2006 plane_state->crtc_w = fb->width;
2007 plane_state->crtc_h = fb->height;
2009 if (plane_config->tiling)
2010 dev_priv->preserve_bios_swizzle = true;
2012 plane_state->fb = fb;
2013 drm_framebuffer_get(fb);
2015 plane_state->crtc = &intel_crtc->base;
2016 intel_plane_copy_uapi_to_hw_state(intel_state, intel_state,
2019 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
2021 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2022 &to_intel_frontbuffer(fb)->bits);
2026 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
2030 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
2031 plane_state->view.color_plane[0].offset, 0);
2037 __intel_display_resume(struct drm_device *dev,
2038 struct drm_atomic_state *state,
2039 struct drm_modeset_acquire_ctx *ctx)
2041 struct drm_crtc_state *crtc_state;
2042 struct drm_crtc *crtc;
2045 intel_modeset_setup_hw_state(dev, ctx);
2046 intel_vga_redisable(to_i915(dev));
2052 * We've duplicated the state, pointers to the old state are invalid.
2054 * Don't attempt to use the old state until we commit the duplicated state.
2056 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
2058 * Force recalculation even if we restore
2059 * current state. With fast modeset this may not result
2060 * in a modeset when the state is compatible.
2062 crtc_state->mode_changed = true;
2065 /* ignore any reset values/BIOS leftovers in the WM registers */
2066 if (!HAS_GMCH(to_i915(dev)))
2067 to_intel_atomic_state(state)->skip_intermediate_wm = true;
2069 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
2071 drm_WARN_ON(dev, ret == -EDEADLK);
2075 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
2077 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
2078 intel_has_gpu_reset(&dev_priv->gt));
2081 void intel_display_prepare_reset(struct drm_i915_private *dev_priv)
2083 struct drm_device *dev = &dev_priv->drm;
2084 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
2085 struct drm_atomic_state *state;
2088 if (!HAS_DISPLAY(dev_priv))
2091 /* reset doesn't touch the display */
2092 if (!dev_priv->params.force_reset_modeset_test &&
2093 !gpu_reset_clobbers_display(dev_priv))
2096 /* We have a modeset vs reset deadlock, defensively unbreak it. */
2097 set_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
2098 smp_mb__after_atomic();
2099 wake_up_bit(&dev_priv->gt.reset.flags, I915_RESET_MODESET);
2101 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
2102 drm_dbg_kms(&dev_priv->drm,
2103 "Modeset potentially stuck, unbreaking through wedging\n");
2104 intel_gt_set_wedged(&dev_priv->gt);
2108 * Need mode_config.mutex so that we don't
2109 * trample ongoing ->detect() and whatnot.
2111 mutex_lock(&dev->mode_config.mutex);
2112 drm_modeset_acquire_init(ctx, 0);
2114 ret = drm_modeset_lock_all_ctx(dev, ctx);
2115 if (ret != -EDEADLK)
2118 drm_modeset_backoff(ctx);
2121 * Disabling the crtcs gracefully seems nicer. Also the
2122 * g33 docs say we should at least disable all the planes.
2124 state = drm_atomic_helper_duplicate_state(dev, ctx);
2125 if (IS_ERR(state)) {
2126 ret = PTR_ERR(state);
2127 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
2132 ret = drm_atomic_helper_disable_all(dev, ctx);
2134 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
2136 drm_atomic_state_put(state);
2140 dev_priv->modeset_restore_state = state;
2141 state->acquire_ctx = ctx;
2144 void intel_display_finish_reset(struct drm_i915_private *dev_priv)
2146 struct drm_device *dev = &dev_priv->drm;
2147 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
2148 struct drm_atomic_state *state;
2151 if (!HAS_DISPLAY(dev_priv))
2154 /* reset doesn't touch the display */
2155 if (!test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
2158 state = fetch_and_zero(&dev_priv->modeset_restore_state);
2162 /* reset doesn't touch the display */
2163 if (!gpu_reset_clobbers_display(dev_priv)) {
2164 /* for testing only restore the display */
2165 ret = __intel_display_resume(dev, state, ctx);
2167 drm_err(&dev_priv->drm,
2168 "Restoring old state failed with %i\n", ret);
2171 * The display has been reset as well,
2172 * so need a full re-initialization.
2174 intel_pps_unlock_regs_wa(dev_priv);
2175 intel_modeset_init_hw(dev_priv);
2176 intel_init_clock_gating(dev_priv);
2177 intel_hpd_init(dev_priv);
2179 ret = __intel_display_resume(dev, state, ctx);
2181 drm_err(&dev_priv->drm,
2182 "Restoring old state failed with %i\n", ret);
2184 intel_hpd_poll_disable(dev_priv);
2187 drm_atomic_state_put(state);
2189 drm_modeset_drop_locks(ctx);
2190 drm_modeset_acquire_fini(ctx);
2191 mutex_unlock(&dev->mode_config.mutex);
2193 clear_bit_unlock(I915_RESET_MODESET, &dev_priv->gt.reset.flags);
2196 static void icl_set_pipe_chicken(struct intel_crtc *crtc)
2198 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2199 enum pipe pipe = crtc->pipe;
2202 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
2205 * Display WA #1153: icl
2206 * enable hardware to bypass the alpha math
2207 * and rounding for per-pixel values 00 and 0xff
2209 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
2211 * Display WA # 1605353570: icl
2212 * Set the pixel rounding bit to 1 for allowing
2213 * passthrough of Frame buffer pixels unmodified
2216 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
2219 * "The underrun recovery mechanism should be disabled
2220 * when the following is enabled for this pipe:
2222 * Downscaling (this includes YUV420 fullblend)
2227 * FIXME: enable whenever possible...
2229 if (IS_ALDERLAKE_P(dev_priv))
2230 tmp |= UNDERRUN_RECOVERY_DISABLE;
2232 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
2235 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
2237 struct drm_crtc *crtc;
2240 drm_for_each_crtc(crtc, &dev_priv->drm) {
2241 struct drm_crtc_commit *commit;
2242 spin_lock(&crtc->commit_lock);
2243 commit = list_first_entry_or_null(&crtc->commit_list,
2244 struct drm_crtc_commit, commit_entry);
2245 cleanup_done = commit ?
2246 try_wait_for_completion(&commit->cleanup_done) : true;
2247 spin_unlock(&crtc->commit_lock);
2252 drm_crtc_wait_one_vblank(crtc);
2260 void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
2264 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_GATE);
2266 mutex_lock(&dev_priv->sb_lock);
2268 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
2269 temp |= SBI_SSCCTL_DISABLE;
2270 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
2272 mutex_unlock(&dev_priv->sb_lock);
2275 /* Program iCLKIP clock to the desired frequency */
2276 static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
2278 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2279 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2280 int clock = crtc_state->hw.adjusted_mode.crtc_clock;
2281 u32 divsel, phaseinc, auxdiv, phasedir = 0;
2284 lpt_disable_iclkip(dev_priv);
2286 /* The iCLK virtual clock root frequency is in MHz,
2287 * but the adjusted_mode->crtc_clock in in KHz. To get the
2288 * divisors, it is necessary to divide one by another, so we
2289 * convert the virtual clock precision to KHz here for higher
2292 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
2293 u32 iclk_virtual_root_freq = 172800 * 1000;
2294 u32 iclk_pi_range = 64;
2295 u32 desired_divisor;
2297 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
2299 divsel = (desired_divisor / iclk_pi_range) - 2;
2300 phaseinc = desired_divisor % iclk_pi_range;
2303 * Near 20MHz is a corner case which is
2304 * out of range for the 7-bit divisor
2310 /* This should not happen with any sane values */
2311 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
2312 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
2313 drm_WARN_ON(&dev_priv->drm, SBI_SSCDIVINTPHASE_DIR(phasedir) &
2314 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
2316 drm_dbg_kms(&dev_priv->drm,
2317 "iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
2318 clock, auxdiv, divsel, phasedir, phaseinc);
2320 mutex_lock(&dev_priv->sb_lock);
2322 /* Program SSCDIVINTPHASE6 */
2323 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
2324 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
2325 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
2326 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
2327 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
2328 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
2329 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
2330 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
2332 /* Program SSCAUXDIV */
2333 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
2334 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
2335 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
2336 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
2338 /* Enable modulator and associated divider */
2339 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
2340 temp &= ~SBI_SSCCTL_DISABLE;
2341 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
2343 mutex_unlock(&dev_priv->sb_lock);
2345 /* Wait for initialization time */
2348 intel_de_write(dev_priv, PIXCLK_GATE, PIXCLK_GATE_UNGATE);
2351 int lpt_get_iclkip(struct drm_i915_private *dev_priv)
2353 u32 divsel, phaseinc, auxdiv;
2354 u32 iclk_virtual_root_freq = 172800 * 1000;
2355 u32 iclk_pi_range = 64;
2356 u32 desired_divisor;
2359 if ((intel_de_read(dev_priv, PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
2362 mutex_lock(&dev_priv->sb_lock);
2364 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
2365 if (temp & SBI_SSCCTL_DISABLE) {
2366 mutex_unlock(&dev_priv->sb_lock);
2370 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
2371 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
2372 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
2373 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
2374 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
2376 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
2377 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
2378 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
2380 mutex_unlock(&dev_priv->sb_lock);
2382 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
2384 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
2385 desired_divisor << auxdiv);
2388 static void ilk_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
2389 enum pipe pch_transcoder)
2391 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2392 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2393 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2395 intel_de_write(dev_priv, PCH_TRANS_HTOTAL(pch_transcoder),
2396 intel_de_read(dev_priv, HTOTAL(cpu_transcoder)));
2397 intel_de_write(dev_priv, PCH_TRANS_HBLANK(pch_transcoder),
2398 intel_de_read(dev_priv, HBLANK(cpu_transcoder)));
2399 intel_de_write(dev_priv, PCH_TRANS_HSYNC(pch_transcoder),
2400 intel_de_read(dev_priv, HSYNC(cpu_transcoder)));
2402 intel_de_write(dev_priv, PCH_TRANS_VTOTAL(pch_transcoder),
2403 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
2404 intel_de_write(dev_priv, PCH_TRANS_VBLANK(pch_transcoder),
2405 intel_de_read(dev_priv, VBLANK(cpu_transcoder)));
2406 intel_de_write(dev_priv, PCH_TRANS_VSYNC(pch_transcoder),
2407 intel_de_read(dev_priv, VSYNC(cpu_transcoder)));
2408 intel_de_write(dev_priv, PCH_TRANS_VSYNCSHIFT(pch_transcoder),
2409 intel_de_read(dev_priv, VSYNCSHIFT(cpu_transcoder)));
2412 static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
2416 temp = intel_de_read(dev_priv, SOUTH_CHICKEN1);
2417 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
2420 drm_WARN_ON(&dev_priv->drm,
2421 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_B)) &
2423 drm_WARN_ON(&dev_priv->drm,
2424 intel_de_read(dev_priv, FDI_RX_CTL(PIPE_C)) &
2427 temp &= ~FDI_BC_BIFURCATION_SELECT;
2429 temp |= FDI_BC_BIFURCATION_SELECT;
2431 drm_dbg_kms(&dev_priv->drm, "%sabling fdi C rx\n",
2432 enable ? "en" : "dis");
2433 intel_de_write(dev_priv, SOUTH_CHICKEN1, temp);
2434 intel_de_posting_read(dev_priv, SOUTH_CHICKEN1);
2437 static void ivb_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
2439 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2440 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2442 switch (crtc->pipe) {
2446 if (crtc_state->fdi_lanes > 2)
2447 cpt_set_fdi_bc_bifurcation(dev_priv, false);
2449 cpt_set_fdi_bc_bifurcation(dev_priv, true);
2453 cpt_set_fdi_bc_bifurcation(dev_priv, true);
2462 * Finds the encoder associated with the given CRTC. This can only be
2463 * used when we know that the CRTC isn't feeding multiple encoders!
2465 struct intel_encoder *
2466 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
2467 const struct intel_crtc_state *crtc_state)
2469 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2470 const struct drm_connector_state *connector_state;
2471 const struct drm_connector *connector;
2472 struct intel_encoder *encoder = NULL;
2473 int num_encoders = 0;
2476 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
2477 if (connector_state->crtc != &crtc->base)
2480 encoder = to_intel_encoder(connector_state->best_encoder);
2484 drm_WARN(encoder->base.dev, num_encoders != 1,
2485 "%d encoders for pipe %c\n",
2486 num_encoders, pipe_name(crtc->pipe));
2492 * Enable PCH resources required for PCH ports:
2494 * - FDI training & RX/TX
2495 * - update transcoder timings
2496 * - DP transcoding bits
2499 static void ilk_pch_enable(const struct intel_atomic_state *state,
2500 const struct intel_crtc_state *crtc_state)
2502 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2503 struct drm_device *dev = crtc->base.dev;
2504 struct drm_i915_private *dev_priv = to_i915(dev);
2505 enum pipe pipe = crtc->pipe;
2508 assert_pch_transcoder_disabled(dev_priv, pipe);
2510 if (IS_IVYBRIDGE(dev_priv))
2511 ivb_update_fdi_bc_bifurcation(crtc_state);
2513 /* Write the TU size bits before fdi link training, so that error
2514 * detection works. */
2515 intel_de_write(dev_priv, FDI_RX_TUSIZE1(pipe),
2516 intel_de_read(dev_priv, PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
2518 /* For PCH output, training FDI link */
2519 dev_priv->display.fdi_link_train(crtc, crtc_state);
2521 /* We need to program the right clock selection before writing the pixel
2522 * mutliplier into the DPLL. */
2523 if (HAS_PCH_CPT(dev_priv)) {
2526 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
2527 temp |= TRANS_DPLL_ENABLE(pipe);
2528 sel = TRANS_DPLLB_SEL(pipe);
2529 if (crtc_state->shared_dpll ==
2530 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
2534 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
2537 /* XXX: pch pll's can be enabled any time before we enable the PCH
2538 * transcoder, and we actually should do this to not upset any PCH
2539 * transcoder that already use the clock when we share it.
2541 * Note that enable_shared_dpll tries to do the right thing, but
2542 * get_shared_dpll unconditionally resets the pll - we need that to have
2543 * the right LVDS enable sequence. */
2544 intel_enable_shared_dpll(crtc_state);
2546 /* set transcoder timing, panel must allow it */
2547 assert_panel_unlocked(dev_priv, pipe);
2548 ilk_pch_transcoder_set_timings(crtc_state, pipe);
2550 intel_fdi_normal_train(crtc);
2552 /* For PCH DP, enable TRANS_DP_CTL */
2553 if (HAS_PCH_CPT(dev_priv) &&
2554 intel_crtc_has_dp_encoder(crtc_state)) {
2555 const struct drm_display_mode *adjusted_mode =
2556 &crtc_state->hw.adjusted_mode;
2557 u32 bpc = (intel_de_read(dev_priv, PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
2558 i915_reg_t reg = TRANS_DP_CTL(pipe);
2561 temp = intel_de_read(dev_priv, reg);
2562 temp &= ~(TRANS_DP_PORT_SEL_MASK |
2563 TRANS_DP_SYNC_MASK |
2565 temp |= TRANS_DP_OUTPUT_ENABLE;
2566 temp |= bpc << 9; /* same format but at 11:9 */
2568 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
2569 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
2570 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
2571 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
2573 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
2574 drm_WARN_ON(dev, port < PORT_B || port > PORT_D);
2575 temp |= TRANS_DP_PORT_SEL(port);
2577 intel_de_write(dev_priv, reg, temp);
2580 ilk_enable_pch_transcoder(crtc_state);
2583 void lpt_pch_enable(const struct intel_crtc_state *crtc_state)
2585 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2586 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2587 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2589 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
2591 lpt_program_iclkip(crtc_state);
2593 /* Set transcoder timing. */
2594 ilk_pch_transcoder_set_timings(crtc_state, PIPE_A);
2596 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
2599 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
2602 i915_reg_t dslreg = PIPEDSL(pipe);
2605 temp = intel_de_read(dev_priv, dslreg);
2607 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
2608 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
2609 drm_err(&dev_priv->drm,
2610 "mode set failed: pipe %c stuck\n",
2615 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
2617 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2618 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2619 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
2620 enum pipe pipe = crtc->pipe;
2621 int width = drm_rect_width(dst);
2622 int height = drm_rect_height(dst);
2626 if (!crtc_state->pch_pfit.enabled)
2629 /* Force use of hard-coded filter coefficients
2630 * as some pre-programmed values are broken,
2633 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
2634 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
2635 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
2637 intel_de_write(dev_priv, PF_CTL(pipe), PF_ENABLE |
2639 intel_de_write(dev_priv, PF_WIN_POS(pipe), x << 16 | y);
2640 intel_de_write(dev_priv, PF_WIN_SZ(pipe), width << 16 | height);
2643 void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
2645 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2646 struct drm_device *dev = crtc->base.dev;
2647 struct drm_i915_private *dev_priv = to_i915(dev);
2649 if (!crtc_state->ips_enabled)
2653 * We can only enable IPS after we enable a plane and wait for a vblank
2654 * This function is called from post_plane_update, which is run after
2657 drm_WARN_ON(dev, !(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
2659 if (IS_BROADWELL(dev_priv)) {
2660 drm_WARN_ON(dev, sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
2661 IPS_ENABLE | IPS_PCODE_CONTROL));
2662 /* Quoting Art Runyan: "its not safe to expect any particular
2663 * value in IPS_CTL bit 31 after enabling IPS through the
2664 * mailbox." Moreover, the mailbox may return a bogus state,
2665 * so we need to just enable it and continue on.
2668 intel_de_write(dev_priv, IPS_CTL, IPS_ENABLE);
2669 /* The bit only becomes 1 in the next vblank, so this wait here
2670 * is essentially intel_wait_for_vblank. If we don't have this
2671 * and don't wait for vblanks until the end of crtc_enable, then
2672 * the HW state readout code will complain that the expected
2673 * IPS_CTL value is not the one we read. */
2674 if (intel_de_wait_for_set(dev_priv, IPS_CTL, IPS_ENABLE, 50))
2675 drm_err(&dev_priv->drm,
2676 "Timed out waiting for IPS enable\n");
2680 void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
2682 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2683 struct drm_device *dev = crtc->base.dev;
2684 struct drm_i915_private *dev_priv = to_i915(dev);
2686 if (!crtc_state->ips_enabled)
2689 if (IS_BROADWELL(dev_priv)) {
2691 sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
2693 * Wait for PCODE to finish disabling IPS. The BSpec specified
2694 * 42ms timeout value leads to occasional timeouts so use 100ms
2697 if (intel_de_wait_for_clear(dev_priv, IPS_CTL, IPS_ENABLE, 100))
2698 drm_err(&dev_priv->drm,
2699 "Timed out waiting for IPS disable\n");
2701 intel_de_write(dev_priv, IPS_CTL, 0);
2702 intel_de_posting_read(dev_priv, IPS_CTL);
2705 /* We need to wait for a vblank before we can disable the plane. */
2706 intel_wait_for_vblank(dev_priv, crtc->pipe);
2709 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
2711 if (intel_crtc->overlay)
2712 (void) intel_overlay_switch_off(intel_crtc->overlay);
2714 /* Let userspace switch the overlay on again. In most cases userspace
2715 * has to recompute where to put it anyway.
2719 static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
2720 const struct intel_crtc_state *new_crtc_state)
2722 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
2723 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2725 if (!old_crtc_state->ips_enabled)
2728 if (intel_crtc_needs_modeset(new_crtc_state))
2732 * Workaround : Do not read or write the pipe palette/gamma data while
2733 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
2735 * Disable IPS before we program the LUT.
2737 if (IS_HASWELL(dev_priv) &&
2738 (new_crtc_state->uapi.color_mgmt_changed ||
2739 new_crtc_state->update_pipe) &&
2740 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
2743 return !new_crtc_state->ips_enabled;
2746 static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
2747 const struct intel_crtc_state *new_crtc_state)
2749 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
2750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2752 if (!new_crtc_state->ips_enabled)
2755 if (intel_crtc_needs_modeset(new_crtc_state))
2759 * Workaround : Do not read or write the pipe palette/gamma data while
2760 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
2762 * Re-enable IPS after the LUT has been programmed.
2764 if (IS_HASWELL(dev_priv) &&
2765 (new_crtc_state->uapi.color_mgmt_changed ||
2766 new_crtc_state->update_pipe) &&
2767 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
2771 * We can't read out IPS on broadwell, assume the worst and
2772 * forcibly enable IPS on the first fastset.
2774 if (new_crtc_state->update_pipe && old_crtc_state->inherited)
2777 return !old_crtc_state->ips_enabled;
2780 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
2782 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2784 if (!crtc_state->nv12_planes)
2787 /* WA Display #0827: Gen9:all */
2788 if (DISPLAY_VER(dev_priv) == 9)
2794 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
2796 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2798 /* Wa_2006604312:icl,ehl */
2799 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
2805 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
2806 const struct intel_crtc_state *new_crtc_state)
2808 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) &&
2809 new_crtc_state->active_planes;
2812 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
2813 const struct intel_crtc_state *new_crtc_state)
2815 return old_crtc_state->active_planes &&
2816 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state));
2819 static void intel_post_plane_update(struct intel_atomic_state *state,
2820 struct intel_crtc *crtc)
2822 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
2823 const struct intel_crtc_state *old_crtc_state =
2824 intel_atomic_get_old_crtc_state(state, crtc);
2825 const struct intel_crtc_state *new_crtc_state =
2826 intel_atomic_get_new_crtc_state(state, crtc);
2827 enum pipe pipe = crtc->pipe;
2829 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
2831 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
2832 intel_update_watermarks(crtc);
2834 if (hsw_post_update_enable_ips(old_crtc_state, new_crtc_state))
2835 hsw_enable_ips(new_crtc_state);
2837 intel_fbc_post_update(state, crtc);
2839 if (needs_nv12_wa(old_crtc_state) &&
2840 !needs_nv12_wa(new_crtc_state))
2841 skl_wa_827(dev_priv, pipe, false);
2843 if (needs_scalerclk_wa(old_crtc_state) &&
2844 !needs_scalerclk_wa(new_crtc_state))
2845 icl_wa_scalerclkgating(dev_priv, pipe, false);
2848 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
2849 struct intel_crtc *crtc)
2851 const struct intel_crtc_state *crtc_state =
2852 intel_atomic_get_new_crtc_state(state, crtc);
2853 u8 update_planes = crtc_state->update_planes;
2854 const struct intel_plane_state *plane_state;
2855 struct intel_plane *plane;
2858 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
2859 if (plane->enable_flip_done &&
2860 plane->pipe == crtc->pipe &&
2861 update_planes & BIT(plane->id))
2862 plane->enable_flip_done(plane);
2866 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
2867 struct intel_crtc *crtc)
2869 const struct intel_crtc_state *crtc_state =
2870 intel_atomic_get_new_crtc_state(state, crtc);
2871 u8 update_planes = crtc_state->update_planes;
2872 const struct intel_plane_state *plane_state;
2873 struct intel_plane *plane;
2876 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
2877 if (plane->disable_flip_done &&
2878 plane->pipe == crtc->pipe &&
2879 update_planes & BIT(plane->id))
2880 plane->disable_flip_done(plane);
2884 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
2885 struct intel_crtc *crtc)
2887 struct drm_i915_private *i915 = to_i915(state->base.dev);
2888 const struct intel_crtc_state *old_crtc_state =
2889 intel_atomic_get_old_crtc_state(state, crtc);
2890 const struct intel_crtc_state *new_crtc_state =
2891 intel_atomic_get_new_crtc_state(state, crtc);
2892 u8 update_planes = new_crtc_state->update_planes;
2893 const struct intel_plane_state *old_plane_state;
2894 struct intel_plane *plane;
2895 bool need_vbl_wait = false;
2898 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
2899 if (plane->need_async_flip_disable_wa &&
2900 plane->pipe == crtc->pipe &&
2901 update_planes & BIT(plane->id)) {
2903 * Apart from the async flip bit we want to
2904 * preserve the old state for the plane.
2906 plane->async_flip(plane, old_crtc_state,
2907 old_plane_state, false);
2908 need_vbl_wait = true;
2913 intel_wait_for_vblank(i915, crtc->pipe);
2916 static void intel_pre_plane_update(struct intel_atomic_state *state,
2917 struct intel_crtc *crtc)
2919 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
2920 const struct intel_crtc_state *old_crtc_state =
2921 intel_atomic_get_old_crtc_state(state, crtc);
2922 const struct intel_crtc_state *new_crtc_state =
2923 intel_atomic_get_new_crtc_state(state, crtc);
2924 enum pipe pipe = crtc->pipe;
2926 if (hsw_pre_update_disable_ips(old_crtc_state, new_crtc_state))
2927 hsw_disable_ips(old_crtc_state);
2929 if (intel_fbc_pre_update(state, crtc))
2930 intel_wait_for_vblank(dev_priv, pipe);
2932 /* Display WA 827 */
2933 if (!needs_nv12_wa(old_crtc_state) &&
2934 needs_nv12_wa(new_crtc_state))
2935 skl_wa_827(dev_priv, pipe, true);
2937 /* Wa_2006604312:icl,ehl */
2938 if (!needs_scalerclk_wa(old_crtc_state) &&
2939 needs_scalerclk_wa(new_crtc_state))
2940 icl_wa_scalerclkgating(dev_priv, pipe, true);
2943 * Vblank time updates from the shadow to live plane control register
2944 * are blocked if the memory self-refresh mode is active at that
2945 * moment. So to make sure the plane gets truly disabled, disable
2946 * first the self-refresh mode. The self-refresh enable bit in turn
2947 * will be checked/applied by the HW only at the next frame start
2948 * event which is after the vblank start event, so we need to have a
2949 * wait-for-vblank between disabling the plane and the pipe.
2951 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
2952 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
2953 intel_wait_for_vblank(dev_priv, pipe);
2956 * IVB workaround: must disable low power watermarks for at least
2957 * one frame before enabling scaling. LP watermarks can be re-enabled
2958 * when scaling is disabled.
2960 * WaCxSRDisabledForSpriteScaling:ivb
2962 if (old_crtc_state->hw.active &&
2963 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
2964 intel_wait_for_vblank(dev_priv, pipe);
2967 * If we're doing a modeset we don't need to do any
2968 * pre-vblank watermark programming here.
2970 if (!intel_crtc_needs_modeset(new_crtc_state)) {
2972 * For platforms that support atomic watermarks, program the
2973 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
2974 * will be the intermediate values that are safe for both pre- and
2975 * post- vblank; when vblank happens, the 'active' values will be set
2976 * to the final 'target' values and we'll do this again to get the
2977 * optimal watermarks. For gen9+ platforms, the values we program here
2978 * will be the final target values which will get automatically latched
2979 * at vblank time; no further programming will be necessary.
2981 * If a platform hasn't been transitioned to atomic watermarks yet,
2982 * we'll continue to update watermarks the old way, if flags tell
2985 if (dev_priv->display.initial_watermarks)
2986 dev_priv->display.initial_watermarks(state, crtc);
2987 else if (new_crtc_state->update_wm_pre)
2988 intel_update_watermarks(crtc);
2992 * Gen2 reports pipe underruns whenever all planes are disabled.
2993 * So disable underrun reporting before all the planes get disabled.
2995 * We do this after .initial_watermarks() so that we have a
2996 * chance of catching underruns with the intermediate watermarks
2997 * vs. the old plane configuration.
2999 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
3000 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
3003 * WA for platforms where async address update enable bit
3004 * is double buffered and only latched at start of vblank.
3006 if (old_crtc_state->uapi.async_flip && !new_crtc_state->uapi.async_flip)
3007 intel_crtc_async_flip_disable_wa(state, crtc);
3010 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
3011 struct intel_crtc *crtc)
3013 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3014 const struct intel_crtc_state *new_crtc_state =
3015 intel_atomic_get_new_crtc_state(state, crtc);
3016 unsigned int update_mask = new_crtc_state->update_planes;
3017 const struct intel_plane_state *old_plane_state;
3018 struct intel_plane *plane;
3019 unsigned fb_bits = 0;
3022 intel_crtc_dpms_overlay_disable(crtc);
3024 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
3025 if (crtc->pipe != plane->pipe ||
3026 !(update_mask & BIT(plane->id)))
3029 intel_disable_plane(plane, new_crtc_state);
3031 if (old_plane_state->uapi.visible)
3032 fb_bits |= plane->frontbuffer_bit;
3035 intel_frontbuffer_flip(dev_priv, fb_bits);
3039 * intel_connector_primary_encoder - get the primary encoder for a connector
3040 * @connector: connector for which to return the encoder
3042 * Returns the primary encoder for a connector. There is a 1:1 mapping from
3043 * all connectors to their encoder, except for DP-MST connectors which have
3044 * both a virtual and a primary encoder. These DP-MST primary encoders can be
3045 * pointed to by as many DP-MST connectors as there are pipes.
3047 static struct intel_encoder *
3048 intel_connector_primary_encoder(struct intel_connector *connector)
3050 struct intel_encoder *encoder;
3052 if (connector->mst_port)
3053 return &dp_to_dig_port(connector->mst_port)->base;
3055 encoder = intel_attached_encoder(connector);
3056 drm_WARN_ON(connector->base.dev, !encoder);
3061 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
3063 struct drm_connector_state *new_conn_state;
3064 struct drm_connector *connector;
3067 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
3069 struct intel_connector *intel_connector;
3070 struct intel_encoder *encoder;
3071 struct intel_crtc *crtc;
3073 if (!intel_connector_needs_modeset(state, connector))
3076 intel_connector = to_intel_connector(connector);
3077 encoder = intel_connector_primary_encoder(intel_connector);
3078 if (!encoder->update_prepare)
3081 crtc = new_conn_state->crtc ?
3082 to_intel_crtc(new_conn_state->crtc) : NULL;
3083 encoder->update_prepare(state, encoder, crtc);
3087 static void intel_encoders_update_complete(struct intel_atomic_state *state)
3089 struct drm_connector_state *new_conn_state;
3090 struct drm_connector *connector;
3093 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
3095 struct intel_connector *intel_connector;
3096 struct intel_encoder *encoder;
3097 struct intel_crtc *crtc;
3099 if (!intel_connector_needs_modeset(state, connector))
3102 intel_connector = to_intel_connector(connector);
3103 encoder = intel_connector_primary_encoder(intel_connector);
3104 if (!encoder->update_complete)
3107 crtc = new_conn_state->crtc ?
3108 to_intel_crtc(new_conn_state->crtc) : NULL;
3109 encoder->update_complete(state, encoder, crtc);
3113 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
3114 struct intel_crtc *crtc)
3116 const struct intel_crtc_state *crtc_state =
3117 intel_atomic_get_new_crtc_state(state, crtc);
3118 const struct drm_connector_state *conn_state;
3119 struct drm_connector *conn;
3122 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3123 struct intel_encoder *encoder =
3124 to_intel_encoder(conn_state->best_encoder);
3126 if (conn_state->crtc != &crtc->base)
3129 if (encoder->pre_pll_enable)
3130 encoder->pre_pll_enable(state, encoder,
3131 crtc_state, conn_state);
3135 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
3136 struct intel_crtc *crtc)
3138 const struct intel_crtc_state *crtc_state =
3139 intel_atomic_get_new_crtc_state(state, crtc);
3140 const struct drm_connector_state *conn_state;
3141 struct drm_connector *conn;
3144 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3145 struct intel_encoder *encoder =
3146 to_intel_encoder(conn_state->best_encoder);
3148 if (conn_state->crtc != &crtc->base)
3151 if (encoder->pre_enable)
3152 encoder->pre_enable(state, encoder,
3153 crtc_state, conn_state);
3157 static void intel_encoders_enable(struct intel_atomic_state *state,
3158 struct intel_crtc *crtc)
3160 const struct intel_crtc_state *crtc_state =
3161 intel_atomic_get_new_crtc_state(state, crtc);
3162 const struct drm_connector_state *conn_state;
3163 struct drm_connector *conn;
3166 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3167 struct intel_encoder *encoder =
3168 to_intel_encoder(conn_state->best_encoder);
3170 if (conn_state->crtc != &crtc->base)
3173 if (encoder->enable)
3174 encoder->enable(state, encoder,
3175 crtc_state, conn_state);
3176 intel_opregion_notify_encoder(encoder, true);
3180 static void intel_encoders_disable(struct intel_atomic_state *state,
3181 struct intel_crtc *crtc)
3183 const struct intel_crtc_state *old_crtc_state =
3184 intel_atomic_get_old_crtc_state(state, crtc);
3185 const struct drm_connector_state *old_conn_state;
3186 struct drm_connector *conn;
3189 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
3190 struct intel_encoder *encoder =
3191 to_intel_encoder(old_conn_state->best_encoder);
3193 if (old_conn_state->crtc != &crtc->base)
3196 intel_opregion_notify_encoder(encoder, false);
3197 if (encoder->disable)
3198 encoder->disable(state, encoder,
3199 old_crtc_state, old_conn_state);
3203 static void intel_encoders_post_disable(struct intel_atomic_state *state,
3204 struct intel_crtc *crtc)
3206 const struct intel_crtc_state *old_crtc_state =
3207 intel_atomic_get_old_crtc_state(state, crtc);
3208 const struct drm_connector_state *old_conn_state;
3209 struct drm_connector *conn;
3212 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
3213 struct intel_encoder *encoder =
3214 to_intel_encoder(old_conn_state->best_encoder);
3216 if (old_conn_state->crtc != &crtc->base)
3219 if (encoder->post_disable)
3220 encoder->post_disable(state, encoder,
3221 old_crtc_state, old_conn_state);
3225 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
3226 struct intel_crtc *crtc)
3228 const struct intel_crtc_state *old_crtc_state =
3229 intel_atomic_get_old_crtc_state(state, crtc);
3230 const struct drm_connector_state *old_conn_state;
3231 struct drm_connector *conn;
3234 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
3235 struct intel_encoder *encoder =
3236 to_intel_encoder(old_conn_state->best_encoder);
3238 if (old_conn_state->crtc != &crtc->base)
3241 if (encoder->post_pll_disable)
3242 encoder->post_pll_disable(state, encoder,
3243 old_crtc_state, old_conn_state);
3247 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
3248 struct intel_crtc *crtc)
3250 const struct intel_crtc_state *crtc_state =
3251 intel_atomic_get_new_crtc_state(state, crtc);
3252 const struct drm_connector_state *conn_state;
3253 struct drm_connector *conn;
3256 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3257 struct intel_encoder *encoder =
3258 to_intel_encoder(conn_state->best_encoder);
3260 if (conn_state->crtc != &crtc->base)
3263 if (encoder->update_pipe)
3264 encoder->update_pipe(state, encoder,
3265 crtc_state, conn_state);
3269 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
3271 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3272 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
3274 plane->disable_plane(plane, crtc_state);
3277 static void ilk_crtc_enable(struct intel_atomic_state *state,
3278 struct intel_crtc *crtc)
3280 const struct intel_crtc_state *new_crtc_state =
3281 intel_atomic_get_new_crtc_state(state, crtc);
3282 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3283 enum pipe pipe = crtc->pipe;
3285 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3289 * Sometimes spurious CPU pipe underruns happen during FDI
3290 * training, at least with VGA+HDMI cloning. Suppress them.
3292 * On ILK we get an occasional spurious CPU pipe underruns
3293 * between eDP port A enable and vdd enable. Also PCH port
3294 * enable seems to result in the occasional CPU pipe underrun.
3296 * Spurious PCH underruns also occur during PCH enabling.
3298 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
3299 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
3301 if (new_crtc_state->has_pch_encoder)
3302 intel_prepare_shared_dpll(new_crtc_state);
3304 if (intel_crtc_has_dp_encoder(new_crtc_state))
3305 intel_dp_set_m_n(new_crtc_state, M1_N1);
3307 intel_set_transcoder_timings(new_crtc_state);
3308 intel_set_pipe_src_size(new_crtc_state);
3310 if (new_crtc_state->has_pch_encoder)
3311 intel_cpu_transcoder_set_m_n(new_crtc_state,
3312 &new_crtc_state->fdi_m_n, NULL);
3314 ilk_set_pipeconf(new_crtc_state);
3316 crtc->active = true;
3318 intel_encoders_pre_enable(state, crtc);
3320 if (new_crtc_state->has_pch_encoder) {
3321 /* Note: FDI PLL enabling _must_ be done before we enable the
3322 * cpu pipes, hence this is separate from all the other fdi/pch
3324 ilk_fdi_pll_enable(new_crtc_state);
3326 assert_fdi_tx_disabled(dev_priv, pipe);
3327 assert_fdi_rx_disabled(dev_priv, pipe);
3330 ilk_pfit_enable(new_crtc_state);
3333 * On ILK+ LUT must be loaded before the pipe is running but with
3336 intel_color_load_luts(new_crtc_state);
3337 intel_color_commit(new_crtc_state);
3338 /* update DSPCNTR to configure gamma for pipe bottom color */
3339 intel_disable_primary_plane(new_crtc_state);
3341 if (dev_priv->display.initial_watermarks)
3342 dev_priv->display.initial_watermarks(state, crtc);
3343 intel_enable_pipe(new_crtc_state);
3345 if (new_crtc_state->has_pch_encoder)
3346 ilk_pch_enable(state, new_crtc_state);
3348 intel_crtc_vblank_on(new_crtc_state);
3350 intel_encoders_enable(state, crtc);
3352 if (HAS_PCH_CPT(dev_priv))
3353 cpt_verify_modeset(dev_priv, pipe);
3356 * Must wait for vblank to avoid spurious PCH FIFO underruns.
3357 * And a second vblank wait is needed at least on ILK with
3358 * some interlaced HDMI modes. Let's do the double wait always
3359 * in case there are more corner cases we don't know about.
3361 if (new_crtc_state->has_pch_encoder) {
3362 intel_wait_for_vblank(dev_priv, pipe);
3363 intel_wait_for_vblank(dev_priv, pipe);
3365 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3366 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
3369 /* IPS only exists on ULT machines and is tied to pipe A. */
3370 static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
3372 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
3375 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
3376 enum pipe pipe, bool apply)
3378 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
3379 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
3386 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
3389 static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
3391 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3392 enum pipe pipe = crtc->pipe;
3395 val = MBUS_DBOX_A_CREDIT(2);
3397 if (DISPLAY_VER(dev_priv) >= 12) {
3398 val |= MBUS_DBOX_BW_CREDIT(2);
3399 val |= MBUS_DBOX_B_CREDIT(12);
3401 val |= MBUS_DBOX_BW_CREDIT(1);
3402 val |= MBUS_DBOX_B_CREDIT(8);
3405 intel_de_write(dev_priv, PIPE_MBUS_DBOX_CTL(pipe), val);
3408 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
3410 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3411 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3413 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
3414 HSW_LINETIME(crtc_state->linetime) |
3415 HSW_IPS_LINETIME(crtc_state->ips_linetime));
3418 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
3420 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3421 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3422 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
3425 val = intel_de_read(dev_priv, reg);
3426 val &= ~HSW_FRAME_START_DELAY_MASK;
3427 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
3428 intel_de_write(dev_priv, reg, val);
3431 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
3432 const struct intel_crtc_state *crtc_state)
3434 struct intel_crtc *master = to_intel_crtc(crtc_state->uapi.crtc);
3435 struct drm_i915_private *dev_priv = to_i915(master->base.dev);
3436 struct intel_crtc_state *master_crtc_state;
3437 struct drm_connector_state *conn_state;
3438 struct drm_connector *conn;
3439 struct intel_encoder *encoder = NULL;
3442 if (crtc_state->bigjoiner_slave)
3443 master = crtc_state->bigjoiner_linked_crtc;
3445 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
3447 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
3448 if (conn_state->crtc != &master->base)
3451 encoder = to_intel_encoder(conn_state->best_encoder);
3455 if (!crtc_state->bigjoiner_slave) {
3456 /* need to enable VDSC, which we skipped in pre-enable */
3457 intel_dsc_enable(encoder, crtc_state);
3460 * Enable sequence steps 1-7 on bigjoiner master
3462 intel_encoders_pre_pll_enable(state, master);
3463 intel_enable_shared_dpll(master_crtc_state);
3464 intel_encoders_pre_enable(state, master);
3466 /* and DSC on slave */
3467 intel_dsc_enable(NULL, crtc_state);
3470 if (DISPLAY_VER(dev_priv) >= 13)
3471 intel_uncompressed_joiner_enable(crtc_state);
3474 static void hsw_crtc_enable(struct intel_atomic_state *state,
3475 struct intel_crtc *crtc)
3477 const struct intel_crtc_state *new_crtc_state =
3478 intel_atomic_get_new_crtc_state(state, crtc);
3479 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3480 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
3481 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
3482 bool psl_clkgate_wa;
3484 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3487 if (!new_crtc_state->bigjoiner) {
3488 intel_encoders_pre_pll_enable(state, crtc);
3490 if (new_crtc_state->shared_dpll)
3491 intel_enable_shared_dpll(new_crtc_state);
3493 intel_encoders_pre_enable(state, crtc);
3495 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
3498 intel_set_pipe_src_size(new_crtc_state);
3499 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
3500 bdw_set_pipemisc(new_crtc_state);
3502 if (!new_crtc_state->bigjoiner_slave && !transcoder_is_dsi(cpu_transcoder)) {
3503 intel_set_transcoder_timings(new_crtc_state);
3505 if (cpu_transcoder != TRANSCODER_EDP)
3506 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
3507 new_crtc_state->pixel_multiplier - 1);
3509 if (new_crtc_state->has_pch_encoder)
3510 intel_cpu_transcoder_set_m_n(new_crtc_state,
3511 &new_crtc_state->fdi_m_n, NULL);
3513 hsw_set_frame_start_delay(new_crtc_state);
3516 if (!transcoder_is_dsi(cpu_transcoder))
3517 hsw_set_pipeconf(new_crtc_state);
3519 crtc->active = true;
3521 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
3522 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
3523 new_crtc_state->pch_pfit.enabled;
3525 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
3527 if (DISPLAY_VER(dev_priv) >= 9)
3528 skl_pfit_enable(new_crtc_state);
3530 ilk_pfit_enable(new_crtc_state);
3533 * On ILK+ LUT must be loaded before the pipe is running but with
3536 intel_color_load_luts(new_crtc_state);
3537 intel_color_commit(new_crtc_state);
3538 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
3539 if (DISPLAY_VER(dev_priv) < 9)
3540 intel_disable_primary_plane(new_crtc_state);
3542 hsw_set_linetime_wm(new_crtc_state);
3544 if (DISPLAY_VER(dev_priv) >= 11)
3545 icl_set_pipe_chicken(crtc);
3547 if (dev_priv->display.initial_watermarks)
3548 dev_priv->display.initial_watermarks(state, crtc);
3550 if (DISPLAY_VER(dev_priv) >= 11)
3551 icl_pipe_mbus_enable(crtc);
3553 if (new_crtc_state->bigjoiner_slave)
3554 intel_crtc_vblank_on(new_crtc_state);
3556 intel_encoders_enable(state, crtc);
3558 if (psl_clkgate_wa) {
3559 intel_wait_for_vblank(dev_priv, pipe);
3560 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
3563 /* If we change the relative order between pipe/planes enabling, we need
3564 * to change the workaround. */
3565 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
3566 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
3567 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
3568 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
3572 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
3574 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
3575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3576 enum pipe pipe = crtc->pipe;
3578 /* To avoid upsetting the power well on haswell only disable the pfit if
3579 * it's in use. The hw state code will make sure we get this right. */
3580 if (!old_crtc_state->pch_pfit.enabled)
3583 intel_de_write(dev_priv, PF_CTL(pipe), 0);
3584 intel_de_write(dev_priv, PF_WIN_POS(pipe), 0);
3585 intel_de_write(dev_priv, PF_WIN_SZ(pipe), 0);
3588 static void ilk_crtc_disable(struct intel_atomic_state *state,
3589 struct intel_crtc *crtc)
3591 const struct intel_crtc_state *old_crtc_state =
3592 intel_atomic_get_old_crtc_state(state, crtc);
3593 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3594 enum pipe pipe = crtc->pipe;
3597 * Sometimes spurious CPU pipe underruns happen when the
3598 * pipe is already disabled, but FDI RX/TX is still enabled.
3599 * Happens at least with VGA+HDMI cloning. Suppress them.
3601 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
3602 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
3604 intel_encoders_disable(state, crtc);
3606 intel_crtc_vblank_off(old_crtc_state);
3608 intel_disable_pipe(old_crtc_state);
3610 ilk_pfit_disable(old_crtc_state);
3612 if (old_crtc_state->has_pch_encoder)
3613 ilk_fdi_disable(crtc);
3615 intel_encoders_post_disable(state, crtc);
3617 if (old_crtc_state->has_pch_encoder) {
3618 ilk_disable_pch_transcoder(dev_priv, pipe);
3620 if (HAS_PCH_CPT(dev_priv)) {
3624 /* disable TRANS_DP_CTL */
3625 reg = TRANS_DP_CTL(pipe);
3626 temp = intel_de_read(dev_priv, reg);
3627 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
3628 TRANS_DP_PORT_SEL_MASK);
3629 temp |= TRANS_DP_PORT_SEL_NONE;
3630 intel_de_write(dev_priv, reg, temp);
3632 /* disable DPLL_SEL */
3633 temp = intel_de_read(dev_priv, PCH_DPLL_SEL);
3634 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
3635 intel_de_write(dev_priv, PCH_DPLL_SEL, temp);
3638 ilk_fdi_pll_disable(crtc);
3641 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3642 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
3645 static void hsw_crtc_disable(struct intel_atomic_state *state,
3646 struct intel_crtc *crtc)
3649 * FIXME collapse everything to one hook.
3650 * Need care with mst->ddi interactions.
3652 intel_encoders_disable(state, crtc);
3653 intel_encoders_post_disable(state, crtc);
3656 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
3658 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3659 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3661 if (!crtc_state->gmch_pfit.control)
3665 * The panel fitter should only be adjusted whilst the pipe is disabled,
3666 * according to register description and PRM.
3668 drm_WARN_ON(&dev_priv->drm,
3669 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
3670 assert_pipe_disabled(dev_priv, crtc_state->cpu_transcoder);
3672 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
3673 crtc_state->gmch_pfit.pgm_ratios);
3674 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
3676 /* Border color in case we don't scale up to the full screen. Black by
3677 * default, change to something else for debugging. */
3678 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
3681 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
3683 if (phy == PHY_NONE)
3685 else if (IS_ALDERLAKE_S(dev_priv))
3686 return phy <= PHY_E;
3687 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
3688 return phy <= PHY_D;
3689 else if (IS_JSL_EHL(dev_priv))
3690 return phy <= PHY_C;
3691 else if (DISPLAY_VER(dev_priv) >= 11)
3692 return phy <= PHY_B;
3697 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
3699 if (IS_ALDERLAKE_P(dev_priv))
3700 return phy >= PHY_F && phy <= PHY_I;
3701 else if (IS_TIGERLAKE(dev_priv))
3702 return phy >= PHY_D && phy <= PHY_I;
3703 else if (IS_ICELAKE(dev_priv))
3704 return phy >= PHY_C && phy <= PHY_F;
3709 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
3711 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
3712 return PHY_D + port - PORT_D_XELPD;
3713 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
3714 return PHY_F + port - PORT_TC1;
3715 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
3716 return PHY_B + port - PORT_TC1;
3717 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
3718 return PHY_C + port - PORT_TC1;
3719 else if (IS_JSL_EHL(i915) && port == PORT_D)
3722 return PHY_A + port - PORT_A;
3725 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
3727 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
3728 return TC_PORT_NONE;
3730 if (DISPLAY_VER(dev_priv) >= 12)
3731 return TC_PORT_1 + port - PORT_TC1;
3733 return TC_PORT_1 + port - PORT_C;
3736 enum intel_display_power_domain intel_port_to_power_domain(enum port port)
3740 return POWER_DOMAIN_PORT_DDI_A_LANES;
3742 return POWER_DOMAIN_PORT_DDI_B_LANES;
3744 return POWER_DOMAIN_PORT_DDI_C_LANES;
3746 return POWER_DOMAIN_PORT_DDI_D_LANES;
3748 return POWER_DOMAIN_PORT_DDI_E_LANES;
3750 return POWER_DOMAIN_PORT_DDI_F_LANES;
3752 return POWER_DOMAIN_PORT_DDI_G_LANES;
3754 return POWER_DOMAIN_PORT_DDI_H_LANES;
3756 return POWER_DOMAIN_PORT_DDI_I_LANES;
3759 return POWER_DOMAIN_PORT_OTHER;
3763 enum intel_display_power_domain
3764 intel_aux_power_domain(struct intel_digital_port *dig_port)
3766 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
3767 enum phy phy = intel_port_to_phy(dev_priv, dig_port->base.port);
3769 if (intel_phy_is_tc(dev_priv, phy) &&
3770 dig_port->tc_mode == TC_PORT_TBT_ALT) {
3771 switch (dig_port->aux_ch) {
3773 return POWER_DOMAIN_AUX_C_TBT;
3775 return POWER_DOMAIN_AUX_D_TBT;
3777 return POWER_DOMAIN_AUX_E_TBT;
3779 return POWER_DOMAIN_AUX_F_TBT;
3781 return POWER_DOMAIN_AUX_G_TBT;
3783 return POWER_DOMAIN_AUX_H_TBT;
3785 return POWER_DOMAIN_AUX_I_TBT;
3787 MISSING_CASE(dig_port->aux_ch);
3788 return POWER_DOMAIN_AUX_C_TBT;
3792 return intel_legacy_aux_to_power_domain(dig_port->aux_ch);
3796 * Converts aux_ch to power_domain without caring about TBT ports for that use
3797 * intel_aux_power_domain()
3799 enum intel_display_power_domain
3800 intel_legacy_aux_to_power_domain(enum aux_ch aux_ch)
3804 return POWER_DOMAIN_AUX_A;
3806 return POWER_DOMAIN_AUX_B;
3808 return POWER_DOMAIN_AUX_C;
3810 return POWER_DOMAIN_AUX_D;
3812 return POWER_DOMAIN_AUX_E;
3814 return POWER_DOMAIN_AUX_F;
3816 return POWER_DOMAIN_AUX_G;
3818 return POWER_DOMAIN_AUX_H;
3820 return POWER_DOMAIN_AUX_I;
3822 MISSING_CASE(aux_ch);
3823 return POWER_DOMAIN_AUX_A;
3827 static u64 get_crtc_power_domains(struct intel_crtc_state *crtc_state)
3829 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3830 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3831 struct drm_encoder *encoder;
3832 enum pipe pipe = crtc->pipe;
3834 enum transcoder transcoder = crtc_state->cpu_transcoder;
3836 if (!crtc_state->hw.active)
3839 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
3840 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
3841 if (crtc_state->pch_pfit.enabled ||
3842 crtc_state->pch_pfit.force_thru)
3843 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
3845 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
3846 crtc_state->uapi.encoder_mask) {
3847 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
3849 mask |= BIT_ULL(intel_encoder->power_domain);
3852 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
3853 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
3855 if (crtc_state->shared_dpll)
3856 mask |= BIT_ULL(POWER_DOMAIN_DISPLAY_CORE);
3858 if (crtc_state->dsc.compression_enable)
3859 mask |= BIT_ULL(intel_dsc_power_domain(crtc_state));
3865 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state)
3867 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3868 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3869 enum intel_display_power_domain domain;
3870 u64 domains, new_domains, old_domains;
3872 domains = get_crtc_power_domains(crtc_state);
3874 new_domains = domains & ~crtc->enabled_power_domains.mask;
3875 old_domains = crtc->enabled_power_domains.mask & ~domains;
3877 for_each_power_domain(domain, new_domains)
3878 intel_display_power_get_in_set(dev_priv,
3879 &crtc->enabled_power_domains,
3885 static void modeset_put_crtc_power_domains(struct intel_crtc *crtc,
3888 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
3889 &crtc->enabled_power_domains,
3893 static void valleyview_crtc_enable(struct intel_atomic_state *state,
3894 struct intel_crtc *crtc)
3896 const struct intel_crtc_state *new_crtc_state =
3897 intel_atomic_get_new_crtc_state(state, crtc);
3898 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3899 enum pipe pipe = crtc->pipe;
3901 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3904 if (intel_crtc_has_dp_encoder(new_crtc_state))
3905 intel_dp_set_m_n(new_crtc_state, M1_N1);
3907 intel_set_transcoder_timings(new_crtc_state);
3908 intel_set_pipe_src_size(new_crtc_state);
3910 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3911 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
3912 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
3915 i9xx_set_pipeconf(new_crtc_state);
3917 crtc->active = true;
3919 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3921 intel_encoders_pre_pll_enable(state, crtc);
3923 if (IS_CHERRYVIEW(dev_priv)) {
3924 chv_prepare_pll(crtc, new_crtc_state);
3925 chv_enable_pll(crtc, new_crtc_state);
3927 vlv_prepare_pll(crtc, new_crtc_state);
3928 vlv_enable_pll(crtc, new_crtc_state);
3931 intel_encoders_pre_enable(state, crtc);
3933 i9xx_pfit_enable(new_crtc_state);
3935 intel_color_load_luts(new_crtc_state);
3936 intel_color_commit(new_crtc_state);
3937 /* update DSPCNTR to configure gamma for pipe bottom color */
3938 intel_disable_primary_plane(new_crtc_state);
3940 dev_priv->display.initial_watermarks(state, crtc);
3941 intel_enable_pipe(new_crtc_state);
3943 intel_crtc_vblank_on(new_crtc_state);
3945 intel_encoders_enable(state, crtc);
3948 static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
3950 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3951 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3953 intel_de_write(dev_priv, FP0(crtc->pipe),
3954 crtc_state->dpll_hw_state.fp0);
3955 intel_de_write(dev_priv, FP1(crtc->pipe),
3956 crtc_state->dpll_hw_state.fp1);
3959 static void i9xx_crtc_enable(struct intel_atomic_state *state,
3960 struct intel_crtc *crtc)
3962 const struct intel_crtc_state *new_crtc_state =
3963 intel_atomic_get_new_crtc_state(state, crtc);
3964 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3965 enum pipe pipe = crtc->pipe;
3967 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
3970 i9xx_set_pll_dividers(new_crtc_state);
3972 if (intel_crtc_has_dp_encoder(new_crtc_state))
3973 intel_dp_set_m_n(new_crtc_state, M1_N1);
3975 intel_set_transcoder_timings(new_crtc_state);
3976 intel_set_pipe_src_size(new_crtc_state);
3978 i9xx_set_pipeconf(new_crtc_state);
3980 crtc->active = true;
3982 if (DISPLAY_VER(dev_priv) != 2)
3983 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
3985 intel_encoders_pre_enable(state, crtc);
3987 i9xx_enable_pll(crtc, new_crtc_state);
3989 i9xx_pfit_enable(new_crtc_state);
3991 intel_color_load_luts(new_crtc_state);
3992 intel_color_commit(new_crtc_state);
3993 /* update DSPCNTR to configure gamma for pipe bottom color */
3994 intel_disable_primary_plane(new_crtc_state);
3996 if (dev_priv->display.initial_watermarks)
3997 dev_priv->display.initial_watermarks(state, crtc);
3999 intel_update_watermarks(crtc);
4000 intel_enable_pipe(new_crtc_state);
4002 intel_crtc_vblank_on(new_crtc_state);
4004 intel_encoders_enable(state, crtc);
4006 /* prevents spurious underruns */
4007 if (DISPLAY_VER(dev_priv) == 2)
4008 intel_wait_for_vblank(dev_priv, pipe);
4011 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
4013 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
4014 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4016 if (!old_crtc_state->gmch_pfit.control)
4019 assert_pipe_disabled(dev_priv, old_crtc_state->cpu_transcoder);
4021 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
4022 intel_de_read(dev_priv, PFIT_CONTROL));
4023 intel_de_write(dev_priv, PFIT_CONTROL, 0);
4026 static void i9xx_crtc_disable(struct intel_atomic_state *state,
4027 struct intel_crtc *crtc)
4029 struct intel_crtc_state *old_crtc_state =
4030 intel_atomic_get_old_crtc_state(state, crtc);
4031 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4032 enum pipe pipe = crtc->pipe;
4035 * On gen2 planes are double buffered but the pipe isn't, so we must
4036 * wait for planes to fully turn off before disabling the pipe.
4038 if (DISPLAY_VER(dev_priv) == 2)
4039 intel_wait_for_vblank(dev_priv, pipe);
4041 intel_encoders_disable(state, crtc);
4043 intel_crtc_vblank_off(old_crtc_state);
4045 intel_disable_pipe(old_crtc_state);
4047 i9xx_pfit_disable(old_crtc_state);
4049 intel_encoders_post_disable(state, crtc);
4051 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
4052 if (IS_CHERRYVIEW(dev_priv))
4053 chv_disable_pll(dev_priv, pipe);
4054 else if (IS_VALLEYVIEW(dev_priv))
4055 vlv_disable_pll(dev_priv, pipe);
4057 i9xx_disable_pll(old_crtc_state);
4060 intel_encoders_post_pll_disable(state, crtc);
4062 if (DISPLAY_VER(dev_priv) != 2)
4063 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
4065 if (!dev_priv->display.initial_watermarks)
4066 intel_update_watermarks(crtc);
4068 /* clock the pipe down to 640x480@60 to potentially save power */
4069 if (IS_I830(dev_priv))
4070 i830_enable_pipe(dev_priv, pipe);
4073 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc,
4074 struct drm_modeset_acquire_ctx *ctx)
4076 struct intel_encoder *encoder;
4077 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4078 struct intel_bw_state *bw_state =
4079 to_intel_bw_state(dev_priv->bw_obj.state);
4080 struct intel_cdclk_state *cdclk_state =
4081 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
4082 struct intel_dbuf_state *dbuf_state =
4083 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
4084 struct intel_crtc_state *crtc_state =
4085 to_intel_crtc_state(crtc->base.state);
4086 struct intel_plane *plane;
4087 struct drm_atomic_state *state;
4088 struct intel_crtc_state *temp_crtc_state;
4089 enum pipe pipe = crtc->pipe;
4092 if (!crtc_state->hw.active)
4095 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
4096 const struct intel_plane_state *plane_state =
4097 to_intel_plane_state(plane->base.state);
4099 if (plane_state->uapi.visible)
4100 intel_plane_disable_noatomic(crtc, plane);
4103 state = drm_atomic_state_alloc(&dev_priv->drm);
4105 drm_dbg_kms(&dev_priv->drm,
4106 "failed to disable [CRTC:%d:%s], out of memory",
4107 crtc->base.base.id, crtc->base.name);
4111 state->acquire_ctx = ctx;
4113 /* Everything's already locked, -EDEADLK can't happen. */
4114 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc);
4115 ret = drm_atomic_add_affected_connectors(state, &crtc->base);
4117 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret);
4119 dev_priv->display.crtc_disable(to_intel_atomic_state(state), crtc);
4121 drm_atomic_state_put(state);
4123 drm_dbg_kms(&dev_priv->drm,
4124 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
4125 crtc->base.base.id, crtc->base.name);
4127 crtc->active = false;
4128 crtc->base.enabled = false;
4130 drm_WARN_ON(&dev_priv->drm,
4131 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0);
4132 crtc_state->uapi.active = false;
4133 crtc_state->uapi.connector_mask = 0;
4134 crtc_state->uapi.encoder_mask = 0;
4135 intel_crtc_free_hw_state(crtc_state);
4136 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw));
4138 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder)
4139 encoder->base.crtc = NULL;
4141 intel_fbc_disable(crtc);
4142 intel_update_watermarks(crtc);
4143 intel_disable_shared_dpll(crtc_state);
4145 intel_display_power_put_all_in_set(dev_priv, &crtc->enabled_power_domains);
4147 dev_priv->active_pipes &= ~BIT(pipe);
4148 cdclk_state->min_cdclk[pipe] = 0;
4149 cdclk_state->min_voltage_level[pipe] = 0;
4150 cdclk_state->active_pipes &= ~BIT(pipe);
4152 dbuf_state->active_pipes &= ~BIT(pipe);
4154 bw_state->data_rate[pipe] = 0;
4155 bw_state->num_active_planes[pipe] = 0;
4159 * turn all crtc's off, but do not adjust state
4160 * This has to be paired with a call to intel_modeset_setup_hw_state.
4162 int intel_display_suspend(struct drm_device *dev)
4164 struct drm_i915_private *dev_priv = to_i915(dev);
4165 struct drm_atomic_state *state;
4168 if (!HAS_DISPLAY(dev_priv))
4171 state = drm_atomic_helper_suspend(dev);
4172 ret = PTR_ERR_OR_ZERO(state);
4174 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
4177 dev_priv->modeset_restore_state = state;
4181 void intel_encoder_destroy(struct drm_encoder *encoder)
4183 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
4185 drm_encoder_cleanup(encoder);
4186 kfree(intel_encoder);
4189 /* Cross check the actual hw state with our own modeset state tracking (and it's
4190 * internal consistency). */
4191 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
4192 struct drm_connector_state *conn_state)
4194 struct intel_connector *connector = to_intel_connector(conn_state->connector);
4195 struct drm_i915_private *i915 = to_i915(connector->base.dev);
4197 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
4198 connector->base.base.id, connector->base.name);
4200 if (connector->get_hw_state(connector)) {
4201 struct intel_encoder *encoder = intel_attached_encoder(connector);
4203 I915_STATE_WARN(!crtc_state,
4204 "connector enabled without attached crtc\n");
4209 I915_STATE_WARN(!crtc_state->hw.active,
4210 "connector is active, but attached crtc isn't\n");
4212 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
4215 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
4216 "atomic encoder doesn't match attached encoder\n");
4218 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
4219 "attached encoder crtc differs from connector crtc\n");
4221 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
4222 "attached crtc is active, but connector isn't\n");
4223 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
4224 "best encoder set without crtc!\n");
4228 bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
4230 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4231 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4233 /* IPS only exists on ULT machines and is tied to pipe A. */
4234 if (!hsw_crtc_supports_ips(crtc))
4237 if (!dev_priv->params.enable_ips)
4240 if (crtc_state->pipe_bpp > 24)
4244 * We compare against max which means we must take
4245 * the increased cdclk requirement into account when
4246 * calculating the new cdclk.
4248 * Should measure whether using a lower cdclk w/o IPS
4250 if (IS_BROADWELL(dev_priv) &&
4251 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
4257 static int hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
4259 struct drm_i915_private *dev_priv =
4260 to_i915(crtc_state->uapi.crtc->dev);
4261 struct intel_atomic_state *state =
4262 to_intel_atomic_state(crtc_state->uapi.state);
4264 crtc_state->ips_enabled = false;
4266 if (!hsw_crtc_state_ips_capable(crtc_state))
4270 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4271 * enabled and disabled dynamically based on package C states,
4272 * user space can't make reliable use of the CRCs, so let's just
4273 * completely disable it.
4275 if (crtc_state->crc_enabled)
4278 /* IPS should be fine as long as at least one plane is enabled. */
4279 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
4282 if (IS_BROADWELL(dev_priv)) {
4283 const struct intel_cdclk_state *cdclk_state;
4285 cdclk_state = intel_atomic_get_cdclk_state(state);
4286 if (IS_ERR(cdclk_state))
4287 return PTR_ERR(cdclk_state);
4289 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
4290 if (crtc_state->pixel_rate > cdclk_state->logical.cdclk * 95 / 100)
4294 crtc_state->ips_enabled = true;
4299 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
4301 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4303 /* GDG double wide on either pipe, otherwise pipe A only */
4304 return DISPLAY_VER(dev_priv) < 4 &&
4305 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
4308 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
4310 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
4311 struct drm_rect src;
4314 * We only use IF-ID interlacing. If we ever use
4315 * PF-ID we'll need to adjust the pixel_rate here.
4318 if (!crtc_state->pch_pfit.enabled)
4321 drm_rect_init(&src, 0, 0,
4322 crtc_state->pipe_src_w << 16,
4323 crtc_state->pipe_src_h << 16);
4325 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
4329 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
4330 const struct drm_display_mode *timings)
4332 mode->hdisplay = timings->crtc_hdisplay;
4333 mode->htotal = timings->crtc_htotal;
4334 mode->hsync_start = timings->crtc_hsync_start;
4335 mode->hsync_end = timings->crtc_hsync_end;
4337 mode->vdisplay = timings->crtc_vdisplay;
4338 mode->vtotal = timings->crtc_vtotal;
4339 mode->vsync_start = timings->crtc_vsync_start;
4340 mode->vsync_end = timings->crtc_vsync_end;
4342 mode->flags = timings->flags;
4343 mode->type = DRM_MODE_TYPE_DRIVER;
4345 mode->clock = timings->crtc_clock;
4347 drm_mode_set_name(mode);
4350 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
4352 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4354 if (HAS_GMCH(dev_priv))
4355 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
4356 crtc_state->pixel_rate =
4357 crtc_state->hw.pipe_mode.crtc_clock;
4359 crtc_state->pixel_rate =
4360 ilk_pipe_pixel_rate(crtc_state);
4363 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
4365 struct drm_display_mode *mode = &crtc_state->hw.mode;
4366 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
4367 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
4369 drm_mode_copy(pipe_mode, adjusted_mode);
4371 if (crtc_state->bigjoiner) {
4373 * transcoder is programmed to the full mode,
4374 * but pipe timings are half of the transcoder mode
4376 pipe_mode->crtc_hdisplay /= 2;
4377 pipe_mode->crtc_hblank_start /= 2;
4378 pipe_mode->crtc_hblank_end /= 2;
4379 pipe_mode->crtc_hsync_start /= 2;
4380 pipe_mode->crtc_hsync_end /= 2;
4381 pipe_mode->crtc_htotal /= 2;
4382 pipe_mode->crtc_clock /= 2;
4385 if (crtc_state->splitter.enable) {
4386 int n = crtc_state->splitter.link_count;
4387 int overlap = crtc_state->splitter.pixel_overlap;
4390 * eDP MSO uses segment timings from EDID for transcoder
4391 * timings, but full mode for everything else.
4393 * h_full = (h_segment - pixel_overlap) * link_count
4395 pipe_mode->crtc_hdisplay = (pipe_mode->crtc_hdisplay - overlap) * n;
4396 pipe_mode->crtc_hblank_start = (pipe_mode->crtc_hblank_start - overlap) * n;
4397 pipe_mode->crtc_hblank_end = (pipe_mode->crtc_hblank_end - overlap) * n;
4398 pipe_mode->crtc_hsync_start = (pipe_mode->crtc_hsync_start - overlap) * n;
4399 pipe_mode->crtc_hsync_end = (pipe_mode->crtc_hsync_end - overlap) * n;
4400 pipe_mode->crtc_htotal = (pipe_mode->crtc_htotal - overlap) * n;
4401 pipe_mode->crtc_clock *= n;
4403 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
4404 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
4406 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
4407 intel_mode_from_crtc_timings(adjusted_mode, adjusted_mode);
4410 intel_crtc_compute_pixel_rate(crtc_state);
4412 drm_mode_copy(mode, adjusted_mode);
4413 mode->hdisplay = crtc_state->pipe_src_w << crtc_state->bigjoiner;
4414 mode->vdisplay = crtc_state->pipe_src_h;
4417 static void intel_encoder_get_config(struct intel_encoder *encoder,
4418 struct intel_crtc_state *crtc_state)
4420 encoder->get_config(encoder, crtc_state);
4422 intel_crtc_readout_derived_state(crtc_state);
4425 static int intel_crtc_compute_config(struct intel_crtc *crtc,
4426 struct intel_crtc_state *pipe_config)
4428 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4429 struct drm_display_mode *pipe_mode = &pipe_config->hw.pipe_mode;
4430 int clock_limit = dev_priv->max_dotclk_freq;
4432 drm_mode_copy(pipe_mode, &pipe_config->hw.adjusted_mode);
4434 /* Adjust pipe_mode for bigjoiner, with half the horizontal mode */
4435 if (pipe_config->bigjoiner) {
4436 pipe_mode->crtc_clock /= 2;
4437 pipe_mode->crtc_hdisplay /= 2;
4438 pipe_mode->crtc_hblank_start /= 2;
4439 pipe_mode->crtc_hblank_end /= 2;
4440 pipe_mode->crtc_hsync_start /= 2;
4441 pipe_mode->crtc_hsync_end /= 2;
4442 pipe_mode->crtc_htotal /= 2;
4443 pipe_config->pipe_src_w /= 2;
4446 if (pipe_config->splitter.enable) {
4447 int n = pipe_config->splitter.link_count;
4448 int overlap = pipe_config->splitter.pixel_overlap;
4450 pipe_mode->crtc_hdisplay = (pipe_mode->crtc_hdisplay - overlap) * n;
4451 pipe_mode->crtc_hblank_start = (pipe_mode->crtc_hblank_start - overlap) * n;
4452 pipe_mode->crtc_hblank_end = (pipe_mode->crtc_hblank_end - overlap) * n;
4453 pipe_mode->crtc_hsync_start = (pipe_mode->crtc_hsync_start - overlap) * n;
4454 pipe_mode->crtc_hsync_end = (pipe_mode->crtc_hsync_end - overlap) * n;
4455 pipe_mode->crtc_htotal = (pipe_mode->crtc_htotal - overlap) * n;
4456 pipe_mode->crtc_clock *= n;
4459 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
4461 if (DISPLAY_VER(dev_priv) < 4) {
4462 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
4465 * Enable double wide mode when the dot clock
4466 * is > 90% of the (display) core speed.
4468 if (intel_crtc_supports_double_wide(crtc) &&
4469 pipe_mode->crtc_clock > clock_limit) {
4470 clock_limit = dev_priv->max_dotclk_freq;
4471 pipe_config->double_wide = true;
4475 if (pipe_mode->crtc_clock > clock_limit) {
4476 drm_dbg_kms(&dev_priv->drm,
4477 "requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
4478 pipe_mode->crtc_clock, clock_limit,
4479 yesno(pipe_config->double_wide));
4484 * Pipe horizontal size must be even in:
4486 * - LVDS dual channel mode
4487 * - Double wide pipe
4489 if (pipe_config->pipe_src_w & 1) {
4490 if (pipe_config->double_wide) {
4491 drm_dbg_kms(&dev_priv->drm,
4492 "Odd pipe source width not supported with double wide pipe\n");
4496 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
4497 intel_is_dual_link_lvds(dev_priv)) {
4498 drm_dbg_kms(&dev_priv->drm,
4499 "Odd pipe source width not supported with dual link LVDS\n");
4504 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
4505 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
4507 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
4508 pipe_mode->crtc_hsync_start == pipe_mode->crtc_hdisplay)
4511 intel_crtc_compute_pixel_rate(pipe_config);
4513 if (pipe_config->has_pch_encoder)
4514 return ilk_fdi_compute_config(crtc, pipe_config);
4520 intel_reduce_m_n_ratio(u32 *num, u32 *den)
4522 while (*num > DATA_LINK_M_N_MASK ||
4523 *den > DATA_LINK_M_N_MASK) {
4529 static void compute_m_n(unsigned int m, unsigned int n,
4530 u32 *ret_m, u32 *ret_n,
4534 * Several DP dongles in particular seem to be fussy about
4535 * too large link M/N values. Give N value as 0x8000 that
4536 * should be acceptable by specific devices. 0x8000 is the
4537 * specified fixed N value for asynchronous clock mode,
4538 * which the devices expect also in synchronous clock mode.
4541 *ret_n = DP_LINK_CONSTANT_N_VALUE;
4543 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
4545 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
4546 intel_reduce_m_n_ratio(ret_m, ret_n);
4550 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
4551 int pixel_clock, int link_clock,
4552 struct intel_link_m_n *m_n,
4553 bool constant_n, bool fec_enable)
4555 u32 data_clock = bits_per_pixel * pixel_clock;
4558 data_clock = intel_dp_mode_to_fec_clock(data_clock);
4561 compute_m_n(data_clock,
4562 link_clock * nlanes * 8,
4563 &m_n->gmch_m, &m_n->gmch_n,
4566 compute_m_n(pixel_clock, link_clock,
4567 &m_n->link_m, &m_n->link_n,
4571 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
4574 * There may be no VBT; and if the BIOS enabled SSC we can
4575 * just keep using it to avoid unnecessary flicker. Whereas if the
4576 * BIOS isn't using it, don't assume it will work even if the VBT
4577 * indicates as much.
4579 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
4580 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
4584 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
4585 drm_dbg_kms(&dev_priv->drm,
4586 "SSC %s by BIOS, overriding VBT which says %s\n",
4587 enableddisabled(bios_lvds_use_ssc),
4588 enableddisabled(dev_priv->vbt.lvds_use_ssc));
4589 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
4594 static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
4595 const struct intel_link_m_n *m_n)
4597 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4598 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4599 enum pipe pipe = crtc->pipe;
4601 intel_de_write(dev_priv, PCH_TRANS_DATA_M1(pipe),
4602 TU_SIZE(m_n->tu) | m_n->gmch_m);
4603 intel_de_write(dev_priv, PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
4604 intel_de_write(dev_priv, PCH_TRANS_LINK_M1(pipe), m_n->link_m);
4605 intel_de_write(dev_priv, PCH_TRANS_LINK_N1(pipe), m_n->link_n);
4608 static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
4609 enum transcoder transcoder)
4611 if (IS_HASWELL(dev_priv))
4612 return transcoder == TRANSCODER_EDP;
4615 * Strictly speaking some registers are available before
4616 * gen7, but we only support DRRS on gen7+
4618 return DISPLAY_VER(dev_priv) == 7 || IS_CHERRYVIEW(dev_priv);
4621 static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
4622 const struct intel_link_m_n *m_n,
4623 const struct intel_link_m_n *m2_n2)
4625 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4626 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4627 enum pipe pipe = crtc->pipe;
4628 enum transcoder transcoder = crtc_state->cpu_transcoder;
4630 if (DISPLAY_VER(dev_priv) >= 5) {
4631 intel_de_write(dev_priv, PIPE_DATA_M1(transcoder),
4632 TU_SIZE(m_n->tu) | m_n->gmch_m);
4633 intel_de_write(dev_priv, PIPE_DATA_N1(transcoder),
4635 intel_de_write(dev_priv, PIPE_LINK_M1(transcoder),
4637 intel_de_write(dev_priv, PIPE_LINK_N1(transcoder),
4640 * M2_N2 registers are set only if DRRS is supported
4641 * (to make sure the registers are not unnecessarily accessed).
4643 if (m2_n2 && crtc_state->has_drrs &&
4644 transcoder_has_m2_n2(dev_priv, transcoder)) {
4645 intel_de_write(dev_priv, PIPE_DATA_M2(transcoder),
4646 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
4647 intel_de_write(dev_priv, PIPE_DATA_N2(transcoder),
4649 intel_de_write(dev_priv, PIPE_LINK_M2(transcoder),
4651 intel_de_write(dev_priv, PIPE_LINK_N2(transcoder),
4655 intel_de_write(dev_priv, PIPE_DATA_M_G4X(pipe),
4656 TU_SIZE(m_n->tu) | m_n->gmch_m);
4657 intel_de_write(dev_priv, PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
4658 intel_de_write(dev_priv, PIPE_LINK_M_G4X(pipe), m_n->link_m);
4659 intel_de_write(dev_priv, PIPE_LINK_N_G4X(pipe), m_n->link_n);
4663 void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
4665 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
4666 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4669 dp_m_n = &crtc_state->dp_m_n;
4670 dp_m2_n2 = &crtc_state->dp_m2_n2;
4671 } else if (m_n == M2_N2) {
4674 * M2_N2 registers are not supported. Hence m2_n2 divider value
4675 * needs to be programmed into M1_N1.
4677 dp_m_n = &crtc_state->dp_m2_n2;
4679 drm_err(&i915->drm, "Unsupported divider value\n");
4683 if (crtc_state->has_pch_encoder)
4684 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
4686 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
4689 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
4691 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4692 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4693 enum pipe pipe = crtc->pipe;
4694 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4695 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
4696 u32 crtc_vtotal, crtc_vblank_end;
4699 /* We need to be careful not to changed the adjusted mode, for otherwise
4700 * the hw state checker will get angry at the mismatch. */
4701 crtc_vtotal = adjusted_mode->crtc_vtotal;
4702 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
4704 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
4705 /* the chip adds 2 halflines automatically */
4707 crtc_vblank_end -= 1;
4709 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
4710 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
4712 vsyncshift = adjusted_mode->crtc_hsync_start -
4713 adjusted_mode->crtc_htotal / 2;
4715 vsyncshift += adjusted_mode->crtc_htotal;
4718 if (DISPLAY_VER(dev_priv) > 3)
4719 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
4722 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
4723 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
4724 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
4725 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
4726 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
4727 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
4729 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
4730 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
4731 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
4732 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
4733 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
4734 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
4736 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
4737 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
4738 * documented on the DDI_FUNC_CTL register description, EDP Input Select
4740 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
4741 (pipe == PIPE_B || pipe == PIPE_C))
4742 intel_de_write(dev_priv, VTOTAL(pipe),
4743 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
4747 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
4749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4751 enum pipe pipe = crtc->pipe;
4753 /* pipesrc controls the size that is scaled from, which should
4754 * always be the user's requested size.
4756 intel_de_write(dev_priv, PIPESRC(pipe),
4757 ((crtc_state->pipe_src_w - 1) << 16) | (crtc_state->pipe_src_h - 1));
4760 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
4762 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4763 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
4765 if (DISPLAY_VER(dev_priv) == 2)
4768 if (DISPLAY_VER(dev_priv) >= 9 ||
4769 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
4770 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
4772 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
4775 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
4776 struct intel_crtc_state *pipe_config)
4778 struct drm_device *dev = crtc->base.dev;
4779 struct drm_i915_private *dev_priv = to_i915(dev);
4780 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
4783 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
4784 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
4785 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
4787 if (!transcoder_is_dsi(cpu_transcoder)) {
4788 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
4789 pipe_config->hw.adjusted_mode.crtc_hblank_start =
4791 pipe_config->hw.adjusted_mode.crtc_hblank_end =
4792 ((tmp >> 16) & 0xffff) + 1;
4794 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
4795 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
4796 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
4798 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
4799 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
4800 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
4802 if (!transcoder_is_dsi(cpu_transcoder)) {
4803 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
4804 pipe_config->hw.adjusted_mode.crtc_vblank_start =
4806 pipe_config->hw.adjusted_mode.crtc_vblank_end =
4807 ((tmp >> 16) & 0xffff) + 1;
4809 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
4810 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
4811 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
4813 if (intel_pipe_is_interlaced(pipe_config)) {
4814 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
4815 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
4816 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
4820 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
4821 struct intel_crtc_state *pipe_config)
4823 struct drm_device *dev = crtc->base.dev;
4824 struct drm_i915_private *dev_priv = to_i915(dev);
4827 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
4828 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
4829 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
4832 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
4834 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4835 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4840 /* we keep both pipes enabled on 830 */
4841 if (IS_I830(dev_priv))
4842 pipeconf |= intel_de_read(dev_priv, PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
4844 if (crtc_state->double_wide)
4845 pipeconf |= PIPECONF_DOUBLE_WIDE;
4847 /* only g4x and later have fancy bpc/dither controls */
4848 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4849 IS_CHERRYVIEW(dev_priv)) {
4850 /* Bspec claims that we can't use dithering for 30bpp pipes. */
4851 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
4852 pipeconf |= PIPECONF_DITHER_EN |
4853 PIPECONF_DITHER_TYPE_SP;
4855 switch (crtc_state->pipe_bpp) {
4857 pipeconf |= PIPECONF_6BPC;
4860 pipeconf |= PIPECONF_8BPC;
4863 pipeconf |= PIPECONF_10BPC;
4866 /* Case prevented by intel_choose_pipe_bpp_dither. */
4871 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
4872 if (DISPLAY_VER(dev_priv) < 4 ||
4873 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
4874 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
4876 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
4878 pipeconf |= PIPECONF_PROGRESSIVE;
4881 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
4882 crtc_state->limited_color_range)
4883 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
4885 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
4887 pipeconf |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
4889 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
4890 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
4893 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
4895 if (IS_I830(dev_priv))
4898 return DISPLAY_VER(dev_priv) >= 4 ||
4899 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
4902 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
4904 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4905 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4908 if (!i9xx_has_pfit(dev_priv))
4911 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
4912 if (!(tmp & PFIT_ENABLE))
4915 /* Check whether the pfit is attached to our pipe. */
4916 if (DISPLAY_VER(dev_priv) < 4) {
4917 if (crtc->pipe != PIPE_B)
4920 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
4924 crtc_state->gmch_pfit.control = tmp;
4925 crtc_state->gmch_pfit.pgm_ratios =
4926 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
4929 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
4930 struct intel_crtc_state *pipe_config)
4932 struct drm_device *dev = crtc->base.dev;
4933 struct drm_i915_private *dev_priv = to_i915(dev);
4934 enum pipe pipe = crtc->pipe;
4937 int refclk = 100000;
4939 /* In case of DSI, DPLL will not be used */
4940 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
4943 vlv_dpio_get(dev_priv);
4944 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
4945 vlv_dpio_put(dev_priv);
4947 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
4948 clock.m2 = mdiv & DPIO_M2DIV_MASK;
4949 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
4950 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
4951 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
4953 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
4956 static void chv_crtc_clock_get(struct intel_crtc *crtc,
4957 struct intel_crtc_state *pipe_config)
4959 struct drm_device *dev = crtc->base.dev;
4960 struct drm_i915_private *dev_priv = to_i915(dev);
4961 enum pipe pipe = crtc->pipe;
4962 enum dpio_channel port = vlv_pipe_to_channel(pipe);
4964 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
4965 int refclk = 100000;
4967 /* In case of DSI, DPLL will not be used */
4968 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
4971 vlv_dpio_get(dev_priv);
4972 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
4973 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
4974 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
4975 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
4976 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
4977 vlv_dpio_put(dev_priv);
4979 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
4980 clock.m2 = (pll_dw0 & 0xff) << 22;
4981 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
4982 clock.m2 |= pll_dw2 & 0x3fffff;
4983 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
4984 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
4985 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
4987 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
4990 static enum intel_output_format
4991 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
4993 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4996 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
4998 if (tmp & PIPEMISC_YUV420_ENABLE) {
4999 /* We support 4:2:0 in full blend mode only */
5000 drm_WARN_ON(&dev_priv->drm,
5001 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
5003 return INTEL_OUTPUT_FORMAT_YCBCR420;
5004 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
5005 return INTEL_OUTPUT_FORMAT_YCBCR444;
5007 return INTEL_OUTPUT_FORMAT_RGB;
5011 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
5013 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5014 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
5015 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5016 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
5019 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
5021 if (tmp & DISPPLANE_GAMMA_ENABLE)
5022 crtc_state->gamma_enable = true;
5024 if (!HAS_GMCH(dev_priv) &&
5025 tmp & DISPPLANE_PIPE_CSC_ENABLE)
5026 crtc_state->csc_enable = true;
5029 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
5030 struct intel_crtc_state *pipe_config)
5032 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5033 enum intel_display_power_domain power_domain;
5034 intel_wakeref_t wakeref;
5038 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
5039 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
5043 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
5044 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
5045 pipe_config->shared_dpll = NULL;
5049 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
5050 if (!(tmp & PIPECONF_ENABLE))
5053 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
5054 IS_CHERRYVIEW(dev_priv)) {
5055 switch (tmp & PIPECONF_BPC_MASK) {
5057 pipe_config->pipe_bpp = 18;
5060 pipe_config->pipe_bpp = 24;
5062 case PIPECONF_10BPC:
5063 pipe_config->pipe_bpp = 30;
5070 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
5071 (tmp & PIPECONF_COLOR_RANGE_SELECT))
5072 pipe_config->limited_color_range = true;
5074 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_I9XX) >>
5075 PIPECONF_GAMMA_MODE_SHIFT;
5077 if (IS_CHERRYVIEW(dev_priv))
5078 pipe_config->cgm_mode = intel_de_read(dev_priv,
5079 CGM_PIPE_MODE(crtc->pipe));
5081 i9xx_get_pipe_color_config(pipe_config);
5082 intel_color_get_config(pipe_config);
5084 if (DISPLAY_VER(dev_priv) < 4)
5085 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
5087 intel_get_transcoder_timings(crtc, pipe_config);
5088 intel_get_pipe_src_size(crtc, pipe_config);
5090 i9xx_get_pfit_config(pipe_config);
5092 if (DISPLAY_VER(dev_priv) >= 4) {
5093 /* No way to read it out on pipes B and C */
5094 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
5095 tmp = dev_priv->chv_dpll_md[crtc->pipe];
5097 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
5098 pipe_config->pixel_multiplier =
5099 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
5100 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
5101 pipe_config->dpll_hw_state.dpll_md = tmp;
5102 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
5103 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
5104 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
5105 pipe_config->pixel_multiplier =
5106 ((tmp & SDVO_MULTIPLIER_MASK)
5107 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
5109 /* Note that on i915G/GM the pixel multiplier is in the sdvo
5110 * port and will be fixed up in the encoder->get_config
5112 pipe_config->pixel_multiplier = 1;
5114 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
5116 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
5117 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
5119 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
5122 /* Mask out read-only status bits. */
5123 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
5124 DPLL_PORTC_READY_MASK |
5125 DPLL_PORTB_READY_MASK);
5128 if (IS_CHERRYVIEW(dev_priv))
5129 chv_crtc_clock_get(crtc, pipe_config);
5130 else if (IS_VALLEYVIEW(dev_priv))
5131 vlv_crtc_clock_get(crtc, pipe_config);
5133 i9xx_crtc_clock_get(crtc, pipe_config);
5136 * Normally the dotclock is filled in by the encoder .get_config()
5137 * but in case the pipe is enabled w/o any ports we need a sane
5140 pipe_config->hw.adjusted_mode.crtc_clock =
5141 pipe_config->port_clock / pipe_config->pixel_multiplier;
5146 intel_display_power_put(dev_priv, power_domain, wakeref);
5151 static void ilk_init_pch_refclk(struct drm_i915_private *dev_priv)
5153 struct intel_encoder *encoder;
5156 bool has_lvds = false;
5157 bool has_cpu_edp = false;
5158 bool has_panel = false;
5159 bool has_ck505 = false;
5160 bool can_ssc = false;
5161 bool using_ssc_source = false;
5163 /* We need to take the global config into account */
5164 for_each_intel_encoder(&dev_priv->drm, encoder) {
5165 switch (encoder->type) {
5166 case INTEL_OUTPUT_LVDS:
5170 case INTEL_OUTPUT_EDP:
5172 if (encoder->port == PORT_A)
5180 if (HAS_PCH_IBX(dev_priv)) {
5181 has_ck505 = dev_priv->vbt.display_clock_mode;
5182 can_ssc = has_ck505;
5188 /* Check if any DPLLs are using the SSC source */
5189 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++) {
5190 u32 temp = intel_de_read(dev_priv, PCH_DPLL(i));
5192 if (!(temp & DPLL_VCO_ENABLE))
5195 if ((temp & PLL_REF_INPUT_MASK) ==
5196 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
5197 using_ssc_source = true;
5202 drm_dbg_kms(&dev_priv->drm,
5203 "has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
5204 has_panel, has_lvds, has_ck505, using_ssc_source);
5206 /* Ironlake: try to setup display ref clock before DPLL
5207 * enabling. This is only under driver's control after
5208 * PCH B stepping, previous chipset stepping should be
5209 * ignoring this setting.
5211 val = intel_de_read(dev_priv, PCH_DREF_CONTROL);
5213 /* As we must carefully and slowly disable/enable each source in turn,
5214 * compute the final state we want first and check if we need to
5215 * make any changes at all.
5218 final &= ~DREF_NONSPREAD_SOURCE_MASK;
5220 final |= DREF_NONSPREAD_CK505_ENABLE;
5222 final |= DREF_NONSPREAD_SOURCE_ENABLE;
5224 final &= ~DREF_SSC_SOURCE_MASK;
5225 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
5226 final &= ~DREF_SSC1_ENABLE;
5229 final |= DREF_SSC_SOURCE_ENABLE;
5231 if (intel_panel_use_ssc(dev_priv) && can_ssc)
5232 final |= DREF_SSC1_ENABLE;
5235 if (intel_panel_use_ssc(dev_priv) && can_ssc)
5236 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
5238 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
5240 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
5241 } else if (using_ssc_source) {
5242 final |= DREF_SSC_SOURCE_ENABLE;
5243 final |= DREF_SSC1_ENABLE;
5249 /* Always enable nonspread source */
5250 val &= ~DREF_NONSPREAD_SOURCE_MASK;
5253 val |= DREF_NONSPREAD_CK505_ENABLE;
5255 val |= DREF_NONSPREAD_SOURCE_ENABLE;
5258 val &= ~DREF_SSC_SOURCE_MASK;
5259 val |= DREF_SSC_SOURCE_ENABLE;
5261 /* SSC must be turned on before enabling the CPU output */
5262 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
5263 drm_dbg_kms(&dev_priv->drm, "Using SSC on panel\n");
5264 val |= DREF_SSC1_ENABLE;
5266 val &= ~DREF_SSC1_ENABLE;
5268 /* Get SSC going before enabling the outputs */
5269 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
5270 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
5273 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
5275 /* Enable CPU source on CPU attached eDP */
5277 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
5278 drm_dbg_kms(&dev_priv->drm,
5279 "Using SSC on eDP\n");
5280 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
5282 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
5284 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
5286 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
5287 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
5290 drm_dbg_kms(&dev_priv->drm, "Disabling CPU source output\n");
5292 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
5294 /* Turn off CPU output */
5295 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
5297 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
5298 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
5301 if (!using_ssc_source) {
5302 drm_dbg_kms(&dev_priv->drm, "Disabling SSC source\n");
5304 /* Turn off the SSC source */
5305 val &= ~DREF_SSC_SOURCE_MASK;
5306 val |= DREF_SSC_SOURCE_DISABLE;
5309 val &= ~DREF_SSC1_ENABLE;
5311 intel_de_write(dev_priv, PCH_DREF_CONTROL, val);
5312 intel_de_posting_read(dev_priv, PCH_DREF_CONTROL);
5317 BUG_ON(val != final);
5320 static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
5324 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
5325 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
5326 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
5328 if (wait_for_us(intel_de_read(dev_priv, SOUTH_CHICKEN2) &
5329 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
5330 drm_err(&dev_priv->drm, "FDI mPHY reset assert timeout\n");
5332 tmp = intel_de_read(dev_priv, SOUTH_CHICKEN2);
5333 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
5334 intel_de_write(dev_priv, SOUTH_CHICKEN2, tmp);
5336 if (wait_for_us((intel_de_read(dev_priv, SOUTH_CHICKEN2) &
5337 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
5338 drm_err(&dev_priv->drm, "FDI mPHY reset de-assert timeout\n");
5341 /* WaMPhyProgramming:hsw */
5342 static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
5346 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
5347 tmp &= ~(0xFF << 24);
5348 tmp |= (0x12 << 24);
5349 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
5351 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
5353 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
5355 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
5357 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
5359 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
5360 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5361 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
5363 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
5364 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
5365 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
5367 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
5370 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
5372 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
5375 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
5377 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
5380 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
5382 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
5385 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
5387 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
5388 tmp &= ~(0xFF << 16);
5389 tmp |= (0x1C << 16);
5390 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
5392 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
5393 tmp &= ~(0xFF << 16);
5394 tmp |= (0x1C << 16);
5395 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
5397 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
5399 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
5401 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
5403 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
5405 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
5406 tmp &= ~(0xF << 28);
5408 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
5410 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
5411 tmp &= ~(0xF << 28);
5413 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
5416 /* Implements 3 different sequences from BSpec chapter "Display iCLK
5417 * Programming" based on the parameters passed:
5418 * - Sequence to enable CLKOUT_DP
5419 * - Sequence to enable CLKOUT_DP without spread
5420 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
5422 static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
5423 bool with_spread, bool with_fdi)
5427 if (drm_WARN(&dev_priv->drm, with_fdi && !with_spread,
5428 "FDI requires downspread\n"))
5430 if (drm_WARN(&dev_priv->drm, HAS_PCH_LPT_LP(dev_priv) &&
5431 with_fdi, "LP PCH doesn't have FDI\n"))
5434 mutex_lock(&dev_priv->sb_lock);
5436 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
5437 tmp &= ~SBI_SSCCTL_DISABLE;
5438 tmp |= SBI_SSCCTL_PATHALT;
5439 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
5444 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
5445 tmp &= ~SBI_SSCCTL_PATHALT;
5446 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
5449 lpt_reset_fdi_mphy(dev_priv);
5450 lpt_program_fdi_mphy(dev_priv);
5454 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
5455 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
5456 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
5457 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
5459 mutex_unlock(&dev_priv->sb_lock);
5462 /* Sequence to disable CLKOUT_DP */
5463 void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
5467 mutex_lock(&dev_priv->sb_lock);
5469 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
5470 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
5471 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
5472 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
5474 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
5475 if (!(tmp & SBI_SSCCTL_DISABLE)) {
5476 if (!(tmp & SBI_SSCCTL_PATHALT)) {
5477 tmp |= SBI_SSCCTL_PATHALT;
5478 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
5481 tmp |= SBI_SSCCTL_DISABLE;
5482 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
5485 mutex_unlock(&dev_priv->sb_lock);
5488 #define BEND_IDX(steps) ((50 + (steps)) / 5)
5490 static const u16 sscdivintphase[] = {
5491 [BEND_IDX( 50)] = 0x3B23,
5492 [BEND_IDX( 45)] = 0x3B23,
5493 [BEND_IDX( 40)] = 0x3C23,
5494 [BEND_IDX( 35)] = 0x3C23,
5495 [BEND_IDX( 30)] = 0x3D23,
5496 [BEND_IDX( 25)] = 0x3D23,
5497 [BEND_IDX( 20)] = 0x3E23,
5498 [BEND_IDX( 15)] = 0x3E23,
5499 [BEND_IDX( 10)] = 0x3F23,
5500 [BEND_IDX( 5)] = 0x3F23,
5501 [BEND_IDX( 0)] = 0x0025,
5502 [BEND_IDX( -5)] = 0x0025,
5503 [BEND_IDX(-10)] = 0x0125,
5504 [BEND_IDX(-15)] = 0x0125,
5505 [BEND_IDX(-20)] = 0x0225,
5506 [BEND_IDX(-25)] = 0x0225,
5507 [BEND_IDX(-30)] = 0x0325,
5508 [BEND_IDX(-35)] = 0x0325,
5509 [BEND_IDX(-40)] = 0x0425,
5510 [BEND_IDX(-45)] = 0x0425,
5511 [BEND_IDX(-50)] = 0x0525,
5516 * steps -50 to 50 inclusive, in steps of 5
5517 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
5518 * change in clock period = -(steps / 10) * 5.787 ps
5520 static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
5523 int idx = BEND_IDX(steps);
5525 if (drm_WARN_ON(&dev_priv->drm, steps % 5 != 0))
5528 if (drm_WARN_ON(&dev_priv->drm, idx >= ARRAY_SIZE(sscdivintphase)))
5531 mutex_lock(&dev_priv->sb_lock);
5533 if (steps % 10 != 0)
5537 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
5539 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
5541 tmp |= sscdivintphase[idx];
5542 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
5544 mutex_unlock(&dev_priv->sb_lock);
5549 static bool spll_uses_pch_ssc(struct drm_i915_private *dev_priv)
5551 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
5552 u32 ctl = intel_de_read(dev_priv, SPLL_CTL);
5554 if ((ctl & SPLL_PLL_ENABLE) == 0)
5557 if ((ctl & SPLL_REF_MASK) == SPLL_REF_MUXED_SSC &&
5558 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
5561 if (IS_BROADWELL(dev_priv) &&
5562 (ctl & SPLL_REF_MASK) == SPLL_REF_PCH_SSC_BDW)
5568 static bool wrpll_uses_pch_ssc(struct drm_i915_private *dev_priv,
5569 enum intel_dpll_id id)
5571 u32 fuse_strap = intel_de_read(dev_priv, FUSE_STRAP);
5572 u32 ctl = intel_de_read(dev_priv, WRPLL_CTL(id));
5574 if ((ctl & WRPLL_PLL_ENABLE) == 0)
5577 if ((ctl & WRPLL_REF_MASK) == WRPLL_REF_PCH_SSC)
5580 if ((IS_BROADWELL(dev_priv) || IS_HSW_ULT(dev_priv)) &&
5581 (ctl & WRPLL_REF_MASK) == WRPLL_REF_MUXED_SSC_BDW &&
5582 (fuse_strap & HSW_CPU_SSC_ENABLE) == 0)
5588 static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
5590 struct intel_encoder *encoder;
5591 bool has_fdi = false;
5593 for_each_intel_encoder(&dev_priv->drm, encoder) {
5594 switch (encoder->type) {
5595 case INTEL_OUTPUT_ANALOG:
5604 * The BIOS may have decided to use the PCH SSC
5605 * reference so we must not disable it until the
5606 * relevant PLLs have stopped relying on it. We'll
5607 * just leave the PCH SSC reference enabled in case
5608 * any active PLL is using it. It will get disabled
5609 * after runtime suspend if we don't have FDI.
5611 * TODO: Move the whole reference clock handling
5612 * to the modeset sequence proper so that we can
5613 * actually enable/disable/reconfigure these things
5614 * safely. To do that we need to introduce a real
5615 * clock hierarchy. That would also allow us to do
5616 * clock bending finally.
5618 dev_priv->pch_ssc_use = 0;
5620 if (spll_uses_pch_ssc(dev_priv)) {
5621 drm_dbg_kms(&dev_priv->drm, "SPLL using PCH SSC\n");
5622 dev_priv->pch_ssc_use |= BIT(DPLL_ID_SPLL);
5625 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL1)) {
5626 drm_dbg_kms(&dev_priv->drm, "WRPLL1 using PCH SSC\n");
5627 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL1);
5630 if (wrpll_uses_pch_ssc(dev_priv, DPLL_ID_WRPLL2)) {
5631 drm_dbg_kms(&dev_priv->drm, "WRPLL2 using PCH SSC\n");
5632 dev_priv->pch_ssc_use |= BIT(DPLL_ID_WRPLL2);
5635 if (dev_priv->pch_ssc_use)
5639 lpt_bend_clkout_dp(dev_priv, 0);
5640 lpt_enable_clkout_dp(dev_priv, true, true);
5642 lpt_disable_clkout_dp(dev_priv);
5647 * Initialize reference clocks when the driver loads
5649 void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
5651 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
5652 ilk_init_pch_refclk(dev_priv);
5653 else if (HAS_PCH_LPT(dev_priv))
5654 lpt_init_pch_refclk(dev_priv);
5657 static void ilk_set_pipeconf(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);
5661 enum pipe pipe = crtc->pipe;
5666 switch (crtc_state->pipe_bpp) {
5668 val |= PIPECONF_6BPC;
5671 val |= PIPECONF_8BPC;
5674 val |= PIPECONF_10BPC;
5677 val |= PIPECONF_12BPC;
5680 /* Case prevented by intel_choose_pipe_bpp_dither. */
5684 if (crtc_state->dither)
5685 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5687 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
5688 val |= PIPECONF_INTERLACED_ILK;
5690 val |= PIPECONF_PROGRESSIVE;
5693 * This would end up with an odd purple hue over
5694 * the entire display. Make sure we don't do it.
5696 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
5697 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
5699 if (crtc_state->limited_color_range &&
5700 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
5701 val |= PIPECONF_COLOR_RANGE_SELECT;
5703 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
5704 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
5706 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
5708 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
5710 intel_de_write(dev_priv, PIPECONF(pipe), val);
5711 intel_de_posting_read(dev_priv, PIPECONF(pipe));
5714 static void hsw_set_pipeconf(const struct intel_crtc_state *crtc_state)
5716 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5717 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5718 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
5721 if (IS_HASWELL(dev_priv) && crtc_state->dither)
5722 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
5724 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
5725 val |= PIPECONF_INTERLACED_ILK;
5727 val |= PIPECONF_PROGRESSIVE;
5729 if (IS_HASWELL(dev_priv) &&
5730 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
5731 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
5733 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
5734 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
5737 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
5739 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5740 const struct intel_crtc_scaler_state *scaler_state =
5741 &crtc_state->scaler_state;
5743 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5747 switch (crtc_state->pipe_bpp) {
5749 val |= PIPEMISC_6_BPC;
5752 val |= PIPEMISC_8_BPC;
5755 val |= PIPEMISC_10_BPC;
5758 /* Port output 12BPC defined for ADLP+ */
5759 if (DISPLAY_VER(dev_priv) > 12)
5760 val |= PIPEMISC_12_BPC_ADLP;
5763 MISSING_CASE(crtc_state->pipe_bpp);
5767 if (crtc_state->dither)
5768 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
5770 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
5771 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
5772 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
5774 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5775 val |= PIPEMISC_YUV420_ENABLE |
5776 PIPEMISC_YUV420_MODE_FULL_BLEND;
5778 if (DISPLAY_VER(dev_priv) >= 11 &&
5779 (crtc_state->active_planes & ~(icl_hdr_plane_mask() |
5780 BIT(PLANE_CURSOR))) == 0)
5781 val |= PIPEMISC_HDR_MODE_PRECISION;
5783 if (DISPLAY_VER(dev_priv) >= 12)
5784 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
5786 if (IS_ALDERLAKE_P(dev_priv)) {
5787 bool scaler_in_use = false;
5789 for (i = 0; i < crtc->num_scalers; i++) {
5790 if (!scaler_state->scalers[i].in_use)
5793 scaler_in_use = true;
5797 intel_de_rmw(dev_priv, PIPE_MISC2(crtc->pipe),
5798 PIPE_MISC2_UNDERRUN_BUBBLE_COUNTER_MASK,
5799 scaler_in_use ? PIPE_MISC2_BUBBLE_COUNTER_SCALER_EN :
5800 PIPE_MISC2_BUBBLE_COUNTER_SCALER_DIS);
5803 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
5806 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
5808 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5811 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
5813 switch (tmp & PIPEMISC_BPC_MASK) {
5814 case PIPEMISC_6_BPC:
5816 case PIPEMISC_8_BPC:
5818 case PIPEMISC_10_BPC:
5821 * PORT OUTPUT 12 BPC defined for ADLP+.
5824 * For previous platforms with DSI interface, bits 5:7
5825 * are used for storing pipe_bpp irrespective of dithering.
5826 * Since the value of 12 BPC is not defined for these bits
5827 * on older platforms, need to find a workaround for 12 BPC
5828 * MIPI DSI HW readout.
5830 case PIPEMISC_12_BPC_ADLP:
5831 if (DISPLAY_VER(dev_priv) > 12)
5840 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
5843 * Account for spread spectrum to avoid
5844 * oversubscribing the link. Max center spread
5845 * is 2.5%; use 5% for safety's sake.
5847 u32 bps = target_clock * bpp * 21 / 20;
5848 return DIV_ROUND_UP(bps, link_bw * 8);
5851 static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
5852 struct intel_link_m_n *m_n)
5854 struct drm_device *dev = crtc->base.dev;
5855 struct drm_i915_private *dev_priv = to_i915(dev);
5856 enum pipe pipe = crtc->pipe;
5858 m_n->link_m = intel_de_read(dev_priv, PCH_TRANS_LINK_M1(pipe));
5859 m_n->link_n = intel_de_read(dev_priv, PCH_TRANS_LINK_N1(pipe));
5860 m_n->gmch_m = intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
5862 m_n->gmch_n = intel_de_read(dev_priv, PCH_TRANS_DATA_N1(pipe));
5863 m_n->tu = ((intel_de_read(dev_priv, PCH_TRANS_DATA_M1(pipe))
5864 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5867 static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
5868 enum transcoder transcoder,
5869 struct intel_link_m_n *m_n,
5870 struct intel_link_m_n *m2_n2)
5872 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5873 enum pipe pipe = crtc->pipe;
5875 if (DISPLAY_VER(dev_priv) >= 5) {
5876 m_n->link_m = intel_de_read(dev_priv,
5877 PIPE_LINK_M1(transcoder));
5878 m_n->link_n = intel_de_read(dev_priv,
5879 PIPE_LINK_N1(transcoder));
5880 m_n->gmch_m = intel_de_read(dev_priv,
5881 PIPE_DATA_M1(transcoder))
5883 m_n->gmch_n = intel_de_read(dev_priv,
5884 PIPE_DATA_N1(transcoder));
5885 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M1(transcoder))
5886 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5888 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
5889 m2_n2->link_m = intel_de_read(dev_priv,
5890 PIPE_LINK_M2(transcoder));
5891 m2_n2->link_n = intel_de_read(dev_priv,
5892 PIPE_LINK_N2(transcoder));
5893 m2_n2->gmch_m = intel_de_read(dev_priv,
5894 PIPE_DATA_M2(transcoder))
5896 m2_n2->gmch_n = intel_de_read(dev_priv,
5897 PIPE_DATA_N2(transcoder));
5898 m2_n2->tu = ((intel_de_read(dev_priv, PIPE_DATA_M2(transcoder))
5899 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5902 m_n->link_m = intel_de_read(dev_priv, PIPE_LINK_M_G4X(pipe));
5903 m_n->link_n = intel_de_read(dev_priv, PIPE_LINK_N_G4X(pipe));
5904 m_n->gmch_m = intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
5906 m_n->gmch_n = intel_de_read(dev_priv, PIPE_DATA_N_G4X(pipe));
5907 m_n->tu = ((intel_de_read(dev_priv, PIPE_DATA_M_G4X(pipe))
5908 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
5912 void intel_dp_get_m_n(struct intel_crtc *crtc,
5913 struct intel_crtc_state *pipe_config)
5915 if (pipe_config->has_pch_encoder)
5916 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
5918 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
5919 &pipe_config->dp_m_n,
5920 &pipe_config->dp_m2_n2);
5923 static void ilk_get_fdi_m_n_config(struct intel_crtc *crtc,
5924 struct intel_crtc_state *pipe_config)
5926 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
5927 &pipe_config->fdi_m_n, NULL);
5930 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
5933 drm_rect_init(&crtc_state->pch_pfit.dst,
5934 pos >> 16, pos & 0xffff,
5935 size >> 16, size & 0xffff);
5938 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
5940 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5941 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5942 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
5946 /* find scaler attached to this pipe */
5947 for (i = 0; i < crtc->num_scalers; i++) {
5950 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
5951 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
5955 crtc_state->pch_pfit.enabled = true;
5957 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
5958 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
5960 ilk_get_pfit_pos_size(crtc_state, pos, size);
5962 scaler_state->scalers[i].in_use = true;
5966 scaler_state->scaler_id = id;
5968 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
5970 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
5973 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
5975 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5976 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5979 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
5980 if ((ctl & PF_ENABLE) == 0)
5983 crtc_state->pch_pfit.enabled = true;
5985 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
5986 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
5988 ilk_get_pfit_pos_size(crtc_state, pos, size);
5991 * We currently do not free assignements of panel fitters on
5992 * ivb/hsw (since we don't use the higher upscaling modes which
5993 * differentiates them) so just WARN about this case for now.
5995 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 7 &&
5996 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
5999 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
6000 struct intel_crtc_state *pipe_config)
6002 struct drm_device *dev = crtc->base.dev;
6003 struct drm_i915_private *dev_priv = to_i915(dev);
6004 enum intel_display_power_domain power_domain;
6005 intel_wakeref_t wakeref;
6009 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
6010 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
6014 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
6015 pipe_config->shared_dpll = NULL;
6018 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
6019 if (!(tmp & PIPECONF_ENABLE))
6022 switch (tmp & PIPECONF_BPC_MASK) {
6024 pipe_config->pipe_bpp = 18;
6027 pipe_config->pipe_bpp = 24;
6029 case PIPECONF_10BPC:
6030 pipe_config->pipe_bpp = 30;
6032 case PIPECONF_12BPC:
6033 pipe_config->pipe_bpp = 36;
6039 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
6040 pipe_config->limited_color_range = true;
6042 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
6043 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
6044 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
6045 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
6048 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
6052 pipe_config->gamma_mode = (tmp & PIPECONF_GAMMA_MODE_MASK_ILK) >>
6053 PIPECONF_GAMMA_MODE_SHIFT;
6055 pipe_config->csc_mode = intel_de_read(dev_priv,
6056 PIPE_CSC_MODE(crtc->pipe));
6058 i9xx_get_pipe_color_config(pipe_config);
6059 intel_color_get_config(pipe_config);
6061 if (intel_de_read(dev_priv, PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
6062 struct intel_shared_dpll *pll;
6063 enum intel_dpll_id pll_id;
6066 pipe_config->has_pch_encoder = true;
6068 tmp = intel_de_read(dev_priv, FDI_RX_CTL(crtc->pipe));
6069 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
6070 FDI_DP_PORT_WIDTH_SHIFT) + 1;
6072 ilk_get_fdi_m_n_config(crtc, pipe_config);
6074 if (HAS_PCH_IBX(dev_priv)) {
6076 * The pipe->pch transcoder and pch transcoder->pll
6079 pll_id = (enum intel_dpll_id) crtc->pipe;
6081 tmp = intel_de_read(dev_priv, PCH_DPLL_SEL);
6082 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
6083 pll_id = DPLL_ID_PCH_PLL_B;
6085 pll_id= DPLL_ID_PCH_PLL_A;
6088 pipe_config->shared_dpll =
6089 intel_get_shared_dpll_by_id(dev_priv, pll_id);
6090 pll = pipe_config->shared_dpll;
6092 pll_active = intel_dpll_get_hw_state(dev_priv, pll,
6093 &pipe_config->dpll_hw_state);
6094 drm_WARN_ON(dev, !pll_active);
6096 tmp = pipe_config->dpll_hw_state.dpll;
6097 pipe_config->pixel_multiplier =
6098 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
6099 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
6101 ilk_pch_clock_get(crtc, pipe_config);
6103 pipe_config->pixel_multiplier = 1;
6106 intel_get_transcoder_timings(crtc, pipe_config);
6107 intel_get_pipe_src_size(crtc, pipe_config);
6109 ilk_get_pfit_config(pipe_config);
6114 intel_display_power_put(dev_priv, power_domain, wakeref);
6119 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
6120 struct intel_crtc_state *pipe_config,
6121 struct intel_display_power_domain_set *power_domain_set)
6123 struct drm_device *dev = crtc->base.dev;
6124 struct drm_i915_private *dev_priv = to_i915(dev);
6125 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
6126 unsigned long enabled_panel_transcoders = 0;
6127 enum transcoder panel_transcoder;
6130 if (DISPLAY_VER(dev_priv) >= 11)
6131 panel_transcoder_mask |=
6132 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
6135 * The pipe->transcoder mapping is fixed with the exception of the eDP
6136 * and DSI transcoders handled below.
6138 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
6141 * XXX: Do intel_display_power_get_if_enabled before reading this (for
6142 * consistency and less surprising code; it's in always on power).
6144 for_each_cpu_transcoder_masked(dev_priv, panel_transcoder,
6145 panel_transcoder_mask) {
6146 bool force_thru = false;
6147 enum pipe trans_pipe;
6149 tmp = intel_de_read(dev_priv,
6150 TRANS_DDI_FUNC_CTL(panel_transcoder));
6151 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
6155 * Log all enabled ones, only use the first one.
6157 * FIXME: This won't work for two separate DSI displays.
6159 enabled_panel_transcoders |= BIT(panel_transcoder);
6160 if (enabled_panel_transcoders != BIT(panel_transcoder))
6163 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
6166 "unknown pipe linked to transcoder %s\n",
6167 transcoder_name(panel_transcoder));
6169 case TRANS_DDI_EDP_INPUT_A_ONOFF:
6172 case TRANS_DDI_EDP_INPUT_A_ON:
6173 trans_pipe = PIPE_A;
6175 case TRANS_DDI_EDP_INPUT_B_ONOFF:
6176 trans_pipe = PIPE_B;
6178 case TRANS_DDI_EDP_INPUT_C_ONOFF:
6179 trans_pipe = PIPE_C;
6181 case TRANS_DDI_EDP_INPUT_D_ONOFF:
6182 trans_pipe = PIPE_D;
6186 if (trans_pipe == crtc->pipe) {
6187 pipe_config->cpu_transcoder = panel_transcoder;
6188 pipe_config->pch_pfit.force_thru = force_thru;
6193 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
6195 drm_WARN_ON(dev, (enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
6196 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
6198 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
6199 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
6202 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
6204 return tmp & PIPECONF_ENABLE;
6207 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
6208 struct intel_crtc_state *pipe_config,
6209 struct intel_display_power_domain_set *power_domain_set)
6211 struct drm_device *dev = crtc->base.dev;
6212 struct drm_i915_private *dev_priv = to_i915(dev);
6213 enum transcoder cpu_transcoder;
6217 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
6219 cpu_transcoder = TRANSCODER_DSI_A;
6221 cpu_transcoder = TRANSCODER_DSI_C;
6223 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
6224 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
6228 * The PLL needs to be enabled with a valid divider
6229 * configuration, otherwise accessing DSI registers will hang
6230 * the machine. See BSpec North Display Engine
6231 * registers/MIPI[BXT]. We can break out here early, since we
6232 * need the same DSI PLL to be enabled for both DSI ports.
6234 if (!bxt_dsi_pll_is_enabled(dev_priv))
6237 /* XXX: this works for video mode only */
6238 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
6239 if (!(tmp & DPI_ENABLE))
6242 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
6243 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
6246 pipe_config->cpu_transcoder = cpu_transcoder;
6250 return transcoder_is_dsi(pipe_config->cpu_transcoder);
6253 static void hsw_get_ddi_port_state(struct intel_crtc *crtc,
6254 struct intel_crtc_state *pipe_config)
6256 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6257 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
6261 if (transcoder_is_dsi(cpu_transcoder)) {
6262 port = (cpu_transcoder == TRANSCODER_DSI_A) ?
6265 tmp = intel_de_read(dev_priv,
6266 TRANS_DDI_FUNC_CTL(cpu_transcoder));
6267 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
6269 if (DISPLAY_VER(dev_priv) >= 12)
6270 port = TGL_TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
6272 port = TRANS_DDI_FUNC_CTL_VAL_TO_PORT(tmp);
6276 * Haswell has only FDI/PCH transcoder A. It is which is connected to
6277 * DDI E. So just check whether this pipe is wired to DDI E and whether
6278 * the PCH transcoder is on.
6280 if (DISPLAY_VER(dev_priv) < 9 &&
6281 (port == PORT_E) && intel_de_read(dev_priv, LPT_TRANSCONF) & TRANS_ENABLE) {
6282 pipe_config->has_pch_encoder = true;
6284 tmp = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A));
6285 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
6286 FDI_DP_PORT_WIDTH_SHIFT) + 1;
6288 ilk_get_fdi_m_n_config(crtc, pipe_config);
6292 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
6293 struct intel_crtc_state *pipe_config)
6295 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6296 struct intel_display_power_domain_set power_domain_set = { };
6300 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
6301 POWER_DOMAIN_PIPE(crtc->pipe)))
6304 pipe_config->shared_dpll = NULL;
6306 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
6308 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
6309 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
6310 drm_WARN_ON(&dev_priv->drm, active);
6314 intel_dsc_get_config(pipe_config);
6315 if (DISPLAY_VER(dev_priv) >= 13 && !pipe_config->dsc.compression_enable)
6316 intel_uncompressed_joiner_get_config(pipe_config);
6319 /* bigjoiner slave doesn't enable transcoder */
6320 if (!pipe_config->bigjoiner_slave)
6324 pipe_config->pixel_multiplier = 1;
6326 /* we cannot read out most state, so don't bother.. */
6327 pipe_config->quirks |= PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE;
6328 } else if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
6329 DISPLAY_VER(dev_priv) >= 11) {
6330 hsw_get_ddi_port_state(crtc, pipe_config);
6331 intel_get_transcoder_timings(crtc, pipe_config);
6334 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
6335 intel_vrr_get_config(crtc, pipe_config);
6337 intel_get_pipe_src_size(crtc, pipe_config);
6339 if (IS_HASWELL(dev_priv)) {
6340 u32 tmp = intel_de_read(dev_priv,
6341 PIPECONF(pipe_config->cpu_transcoder));
6343 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
6344 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
6346 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
6348 pipe_config->output_format =
6349 bdw_get_pipemisc_output_format(crtc);
6352 pipe_config->gamma_mode = intel_de_read(dev_priv,
6353 GAMMA_MODE(crtc->pipe));
6355 pipe_config->csc_mode = intel_de_read(dev_priv,
6356 PIPE_CSC_MODE(crtc->pipe));
6358 if (DISPLAY_VER(dev_priv) >= 9) {
6359 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
6361 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
6362 pipe_config->gamma_enable = true;
6364 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
6365 pipe_config->csc_enable = true;
6367 i9xx_get_pipe_color_config(pipe_config);
6370 intel_color_get_config(pipe_config);
6372 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
6373 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
6374 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
6375 pipe_config->ips_linetime =
6376 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
6378 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
6379 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
6380 if (DISPLAY_VER(dev_priv) >= 9)
6381 skl_get_pfit_config(pipe_config);
6383 ilk_get_pfit_config(pipe_config);
6386 if (hsw_crtc_supports_ips(crtc)) {
6387 if (IS_HASWELL(dev_priv))
6388 pipe_config->ips_enabled = intel_de_read(dev_priv,
6389 IPS_CTL) & IPS_ENABLE;
6392 * We cannot readout IPS state on broadwell, set to
6393 * true so we can set it to a defined state on first
6396 pipe_config->ips_enabled = true;
6400 if (pipe_config->bigjoiner_slave) {
6401 /* Cannot be read out as a slave, set to 0. */
6402 pipe_config->pixel_multiplier = 0;
6403 } else if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
6404 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
6405 pipe_config->pixel_multiplier =
6406 intel_de_read(dev_priv,
6407 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
6409 pipe_config->pixel_multiplier = 1;
6413 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
6418 static bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
6420 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6421 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6423 if (!i915->display.get_pipe_config(crtc, crtc_state))
6426 crtc_state->hw.active = true;
6428 intel_crtc_readout_derived_state(crtc_state);
6433 /* VESA 640x480x72Hz mode to set on the pipe */
6434 static const struct drm_display_mode load_detect_mode = {
6435 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
6436 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
6439 struct drm_framebuffer *
6440 intel_framebuffer_create(struct drm_i915_gem_object *obj,
6441 struct drm_mode_fb_cmd2 *mode_cmd)
6443 struct intel_framebuffer *intel_fb;
6446 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
6448 return ERR_PTR(-ENOMEM);
6450 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
6454 return &intel_fb->base;
6458 return ERR_PTR(ret);
6461 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
6462 struct drm_crtc *crtc)
6464 struct drm_plane *plane;
6465 struct drm_plane_state *plane_state;
6468 ret = drm_atomic_add_affected_planes(state, crtc);
6472 for_each_new_plane_in_state(state, plane, plane_state, i) {
6473 if (plane_state->crtc != crtc)
6476 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
6480 drm_atomic_set_fb_for_plane(plane_state, NULL);
6486 int intel_get_load_detect_pipe(struct drm_connector *connector,
6487 struct intel_load_detect_pipe *old,
6488 struct drm_modeset_acquire_ctx *ctx)
6490 struct intel_crtc *intel_crtc;
6491 struct intel_encoder *intel_encoder =
6492 intel_attached_encoder(to_intel_connector(connector));
6493 struct drm_crtc *possible_crtc;
6494 struct drm_encoder *encoder = &intel_encoder->base;
6495 struct drm_crtc *crtc = NULL;
6496 struct drm_device *dev = encoder->dev;
6497 struct drm_i915_private *dev_priv = to_i915(dev);
6498 struct drm_mode_config *config = &dev->mode_config;
6499 struct drm_atomic_state *state = NULL, *restore_state = NULL;
6500 struct drm_connector_state *connector_state;
6501 struct intel_crtc_state *crtc_state;
6504 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6505 connector->base.id, connector->name,
6506 encoder->base.id, encoder->name);
6508 old->restore_state = NULL;
6510 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
6513 * Algorithm gets a little messy:
6515 * - if the connector already has an assigned crtc, use it (but make
6516 * sure it's on first)
6518 * - try to find the first unused crtc that can drive this connector,
6519 * and use that if we find one
6522 /* See if we already have a CRTC for this connector */
6523 if (connector->state->crtc) {
6524 crtc = connector->state->crtc;
6526 ret = drm_modeset_lock(&crtc->mutex, ctx);
6530 /* Make sure the crtc and connector are running */
6534 /* Find an unused one (if possible) */
6535 for_each_crtc(dev, possible_crtc) {
6537 if (!(encoder->possible_crtcs & (1 << i)))
6540 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
6544 if (possible_crtc->state->enable) {
6545 drm_modeset_unlock(&possible_crtc->mutex);
6549 crtc = possible_crtc;
6554 * If we didn't find an unused CRTC, don't use any.
6557 drm_dbg_kms(&dev_priv->drm,
6558 "no pipe available for load-detect\n");
6564 intel_crtc = to_intel_crtc(crtc);
6566 state = drm_atomic_state_alloc(dev);
6567 restore_state = drm_atomic_state_alloc(dev);
6568 if (!state || !restore_state) {
6573 state->acquire_ctx = ctx;
6574 restore_state->acquire_ctx = ctx;
6576 connector_state = drm_atomic_get_connector_state(state, connector);
6577 if (IS_ERR(connector_state)) {
6578 ret = PTR_ERR(connector_state);
6582 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
6586 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6587 if (IS_ERR(crtc_state)) {
6588 ret = PTR_ERR(crtc_state);
6592 crtc_state->uapi.active = true;
6594 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
6599 ret = intel_modeset_disable_planes(state, crtc);
6603 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
6605 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
6607 ret = drm_atomic_add_affected_planes(restore_state, crtc);
6609 drm_dbg_kms(&dev_priv->drm,
6610 "Failed to create a copy of old state to restore: %i\n",
6615 ret = drm_atomic_commit(state);
6617 drm_dbg_kms(&dev_priv->drm,
6618 "failed to set mode on load-detect pipe\n");
6622 old->restore_state = restore_state;
6623 drm_atomic_state_put(state);
6625 /* let the connector get through one full cycle before testing */
6626 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
6631 drm_atomic_state_put(state);
6634 if (restore_state) {
6635 drm_atomic_state_put(restore_state);
6636 restore_state = NULL;
6639 if (ret == -EDEADLK)
6645 void intel_release_load_detect_pipe(struct drm_connector *connector,
6646 struct intel_load_detect_pipe *old,
6647 struct drm_modeset_acquire_ctx *ctx)
6649 struct intel_encoder *intel_encoder =
6650 intel_attached_encoder(to_intel_connector(connector));
6651 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
6652 struct drm_encoder *encoder = &intel_encoder->base;
6653 struct drm_atomic_state *state = old->restore_state;
6656 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
6657 connector->base.id, connector->name,
6658 encoder->base.id, encoder->name);
6663 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
6665 drm_dbg_kms(&i915->drm,
6666 "Couldn't release load detect pipe: %i\n", ret);
6667 drm_atomic_state_put(state);
6670 static int i9xx_pll_refclk(struct drm_device *dev,
6671 const struct intel_crtc_state *pipe_config)
6673 struct drm_i915_private *dev_priv = to_i915(dev);
6674 u32 dpll = pipe_config->dpll_hw_state.dpll;
6676 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
6677 return dev_priv->vbt.lvds_ssc_freq;
6678 else if (HAS_PCH_SPLIT(dev_priv))
6680 else if (DISPLAY_VER(dev_priv) != 2)
6686 /* Returns the clock of the currently programmed mode of the given pipe. */
6687 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
6688 struct intel_crtc_state *pipe_config)
6690 struct drm_device *dev = crtc->base.dev;
6691 struct drm_i915_private *dev_priv = to_i915(dev);
6692 enum pipe pipe = crtc->pipe;
6693 u32 dpll = pipe_config->dpll_hw_state.dpll;
6697 int refclk = i9xx_pll_refclk(dev, pipe_config);
6699 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
6700 fp = pipe_config->dpll_hw_state.fp0;
6702 fp = pipe_config->dpll_hw_state.fp1;
6704 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
6705 if (IS_PINEVIEW(dev_priv)) {
6706 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
6707 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
6709 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
6710 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
6713 if (DISPLAY_VER(dev_priv) != 2) {
6714 if (IS_PINEVIEW(dev_priv))
6715 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
6716 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
6718 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
6719 DPLL_FPA01_P1_POST_DIV_SHIFT);
6721 switch (dpll & DPLL_MODE_MASK) {
6722 case DPLLB_MODE_DAC_SERIAL:
6723 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
6726 case DPLLB_MODE_LVDS:
6727 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
6731 drm_dbg_kms(&dev_priv->drm,
6732 "Unknown DPLL mode %08x in programmed "
6733 "mode\n", (int)(dpll & DPLL_MODE_MASK));
6737 if (IS_PINEVIEW(dev_priv))
6738 port_clock = pnv_calc_dpll_params(refclk, &clock);
6740 port_clock = i9xx_calc_dpll_params(refclk, &clock);
6742 u32 lvds = IS_I830(dev_priv) ? 0 : intel_de_read(dev_priv,
6744 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
6747 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
6748 DPLL_FPA01_P1_POST_DIV_SHIFT);
6750 if (lvds & LVDS_CLKB_POWER_UP)
6755 if (dpll & PLL_P1_DIVIDE_BY_TWO)
6758 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
6759 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
6761 if (dpll & PLL_P2_DIVIDE_BY_4)
6767 port_clock = i9xx_calc_dpll_params(refclk, &clock);
6771 * This value includes pixel_multiplier. We will use
6772 * port_clock to compute adjusted_mode.crtc_clock in the
6773 * encoder's get_config() function.
6775 pipe_config->port_clock = port_clock;
6778 int intel_dotclock_calculate(int link_freq,
6779 const struct intel_link_m_n *m_n)
6782 * The calculation for the data clock is:
6783 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
6784 * But we want to avoid losing precison if possible, so:
6785 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
6787 * and the link clock is simpler:
6788 * link_clock = (m * link_clock) / n
6794 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
6797 static void ilk_pch_clock_get(struct intel_crtc *crtc,
6798 struct intel_crtc_state *pipe_config)
6800 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6802 /* read out port_clock from the DPLL */
6803 i9xx_crtc_clock_get(crtc, pipe_config);
6806 * In case there is an active pipe without active ports,
6807 * we may need some idea for the dotclock anyway.
6808 * Calculate one based on the FDI configuration.
6810 pipe_config->hw.adjusted_mode.crtc_clock =
6811 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
6812 &pipe_config->fdi_m_n);
6815 /* Returns the currently programmed mode of the given encoder. */
6816 struct drm_display_mode *
6817 intel_encoder_current_mode(struct intel_encoder *encoder)
6819 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
6820 struct intel_crtc_state *crtc_state;
6821 struct drm_display_mode *mode;
6822 struct intel_crtc *crtc;
6825 if (!encoder->get_hw_state(encoder, &pipe))
6828 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
6830 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
6834 crtc_state = intel_crtc_state_alloc(crtc);
6840 if (!intel_crtc_get_pipe_config(crtc_state)) {
6846 intel_encoder_get_config(encoder, crtc_state);
6848 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
6856 * intel_wm_need_update - Check whether watermarks need updating
6857 * @cur: current plane state
6858 * @new: new plane state
6860 * Check current plane state versus the new one to determine whether
6861 * watermarks need to be recalculated.
6863 * Returns true or false.
6865 static bool intel_wm_need_update(const struct intel_plane_state *cur,
6866 struct intel_plane_state *new)
6868 /* Update watermarks on tiling or size changes. */
6869 if (new->uapi.visible != cur->uapi.visible)
6872 if (!cur->hw.fb || !new->hw.fb)
6875 if (cur->hw.fb->modifier != new->hw.fb->modifier ||
6876 cur->hw.rotation != new->hw.rotation ||
6877 drm_rect_width(&new->uapi.src) != drm_rect_width(&cur->uapi.src) ||
6878 drm_rect_height(&new->uapi.src) != drm_rect_height(&cur->uapi.src) ||
6879 drm_rect_width(&new->uapi.dst) != drm_rect_width(&cur->uapi.dst) ||
6880 drm_rect_height(&new->uapi.dst) != drm_rect_height(&cur->uapi.dst))
6886 static bool needs_scaling(const struct intel_plane_state *state)
6888 int src_w = drm_rect_width(&state->uapi.src) >> 16;
6889 int src_h = drm_rect_height(&state->uapi.src) >> 16;
6890 int dst_w = drm_rect_width(&state->uapi.dst);
6891 int dst_h = drm_rect_height(&state->uapi.dst);
6893 return (src_w != dst_w || src_h != dst_h);
6896 int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
6897 struct intel_crtc_state *crtc_state,
6898 const struct intel_plane_state *old_plane_state,
6899 struct intel_plane_state *plane_state)
6901 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6902 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
6903 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6904 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
6905 bool was_crtc_enabled = old_crtc_state->hw.active;
6906 bool is_crtc_enabled = crtc_state->hw.active;
6907 bool turn_off, turn_on, visible, was_visible;
6910 if (DISPLAY_VER(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
6911 ret = skl_update_scaler_plane(crtc_state, plane_state);
6916 was_visible = old_plane_state->uapi.visible;
6917 visible = plane_state->uapi.visible;
6919 if (!was_crtc_enabled && drm_WARN_ON(&dev_priv->drm, was_visible))
6920 was_visible = false;
6923 * Visibility is calculated as if the crtc was on, but
6924 * after scaler setup everything depends on it being off
6925 * when the crtc isn't active.
6927 * FIXME this is wrong for watermarks. Watermarks should also
6928 * be computed as if the pipe would be active. Perhaps move
6929 * per-plane wm computation to the .check_plane() hook, and
6930 * only combine the results from all planes in the current place?
6932 if (!is_crtc_enabled) {
6933 intel_plane_set_invisible(crtc_state, plane_state);
6937 if (!was_visible && !visible)
6940 turn_off = was_visible && (!visible || mode_changed);
6941 turn_on = visible && (!was_visible || mode_changed);
6943 drm_dbg_atomic(&dev_priv->drm,
6944 "[CRTC:%d:%s] with [PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
6945 crtc->base.base.id, crtc->base.name,
6946 plane->base.base.id, plane->base.name,
6947 was_visible, visible,
6948 turn_off, turn_on, mode_changed);
6951 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv))
6952 crtc_state->update_wm_pre = true;
6954 /* must disable cxsr around plane enable/disable */
6955 if (plane->id != PLANE_CURSOR)
6956 crtc_state->disable_cxsr = true;
6957 } else if (turn_off) {
6958 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv))
6959 crtc_state->update_wm_post = true;
6961 /* must disable cxsr around plane enable/disable */
6962 if (plane->id != PLANE_CURSOR)
6963 crtc_state->disable_cxsr = true;
6964 } else if (intel_wm_need_update(old_plane_state, plane_state)) {
6965 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv)) {
6966 /* FIXME bollocks */
6967 crtc_state->update_wm_pre = true;
6968 crtc_state->update_wm_post = true;
6972 if (visible || was_visible)
6973 crtc_state->fb_bits |= plane->frontbuffer_bit;
6976 * ILK/SNB DVSACNTR/Sprite Enable
6977 * IVB SPR_CTL/Sprite Enable
6978 * "When in Self Refresh Big FIFO mode, a write to enable the
6979 * plane will be internally buffered and delayed while Big FIFO
6982 * Which means that enabling the sprite can take an extra frame
6983 * when we start in big FIFO mode (LP1+). Thus we need to drop
6984 * down to LP0 and wait for vblank in order to make sure the
6985 * sprite gets enabled on the next vblank after the register write.
6986 * Doing otherwise would risk enabling the sprite one frame after
6987 * we've already signalled flip completion. We can resume LP1+
6988 * once the sprite has been enabled.
6991 * WaCxSRDisabledForSpriteScaling:ivb
6992 * IVB SPR_SCALE/Scaling Enable
6993 * "Low Power watermarks must be disabled for at least one
6994 * frame before enabling sprite scaling, and kept disabled
6995 * until sprite scaling is disabled."
6997 * ILK/SNB DVSASCALE/Scaling Enable
6998 * "When in Self Refresh Big FIFO mode, scaling enable will be
6999 * masked off while Big FIFO mode is exiting."
7001 * Despite the w/a only being listed for IVB we assume that
7002 * the ILK/SNB note has similar ramifications, hence we apply
7003 * the w/a on all three platforms.
7005 * With experimental results seems this is needed also for primary
7006 * plane, not only sprite plane.
7008 if (plane->id != PLANE_CURSOR &&
7009 (IS_IRONLAKE(dev_priv) || IS_SANDYBRIDGE(dev_priv) ||
7010 IS_IVYBRIDGE(dev_priv)) &&
7011 (turn_on || (!needs_scaling(old_plane_state) &&
7012 needs_scaling(plane_state))))
7013 crtc_state->disable_lp_wm = true;
7018 static bool encoders_cloneable(const struct intel_encoder *a,
7019 const struct intel_encoder *b)
7021 /* masks could be asymmetric, so check both ways */
7022 return a == b || (a->cloneable & (1 << b->type) &&
7023 b->cloneable & (1 << a->type));
7026 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
7027 struct intel_crtc *crtc,
7028 struct intel_encoder *encoder)
7030 struct intel_encoder *source_encoder;
7031 struct drm_connector *connector;
7032 struct drm_connector_state *connector_state;
7035 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
7036 if (connector_state->crtc != &crtc->base)
7040 to_intel_encoder(connector_state->best_encoder);
7041 if (!encoders_cloneable(encoder, source_encoder))
7048 static int icl_add_linked_planes(struct intel_atomic_state *state)
7050 struct intel_plane *plane, *linked;
7051 struct intel_plane_state *plane_state, *linked_plane_state;
7054 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7055 linked = plane_state->planar_linked_plane;
7060 linked_plane_state = intel_atomic_get_plane_state(state, linked);
7061 if (IS_ERR(linked_plane_state))
7062 return PTR_ERR(linked_plane_state);
7064 drm_WARN_ON(state->base.dev,
7065 linked_plane_state->planar_linked_plane != plane);
7066 drm_WARN_ON(state->base.dev,
7067 linked_plane_state->planar_slave == plane_state->planar_slave);
7073 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
7075 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7076 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7077 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
7078 struct intel_plane *plane, *linked;
7079 struct intel_plane_state *plane_state;
7082 if (DISPLAY_VER(dev_priv) < 11)
7086 * Destroy all old plane links and make the slave plane invisible
7087 * in the crtc_state->active_planes mask.
7089 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7090 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
7093 plane_state->planar_linked_plane = NULL;
7094 if (plane_state->planar_slave && !plane_state->uapi.visible) {
7095 crtc_state->enabled_planes &= ~BIT(plane->id);
7096 crtc_state->active_planes &= ~BIT(plane->id);
7097 crtc_state->update_planes |= BIT(plane->id);
7100 plane_state->planar_slave = false;
7103 if (!crtc_state->nv12_planes)
7106 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7107 struct intel_plane_state *linked_state = NULL;
7109 if (plane->pipe != crtc->pipe ||
7110 !(crtc_state->nv12_planes & BIT(plane->id)))
7113 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
7114 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
7117 if (crtc_state->active_planes & BIT(linked->id))
7120 linked_state = intel_atomic_get_plane_state(state, linked);
7121 if (IS_ERR(linked_state))
7122 return PTR_ERR(linked_state);
7127 if (!linked_state) {
7128 drm_dbg_kms(&dev_priv->drm,
7129 "Need %d free Y planes for planar YUV\n",
7130 hweight8(crtc_state->nv12_planes));
7135 plane_state->planar_linked_plane = linked;
7137 linked_state->planar_slave = true;
7138 linked_state->planar_linked_plane = plane;
7139 crtc_state->enabled_planes |= BIT(linked->id);
7140 crtc_state->active_planes |= BIT(linked->id);
7141 crtc_state->update_planes |= BIT(linked->id);
7142 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
7143 linked->base.name, plane->base.name);
7145 /* Copy parameters to slave plane */
7146 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
7147 linked_state->color_ctl = plane_state->color_ctl;
7148 linked_state->view = plane_state->view;
7150 intel_plane_copy_hw_state(linked_state, plane_state);
7151 linked_state->uapi.src = plane_state->uapi.src;
7152 linked_state->uapi.dst = plane_state->uapi.dst;
7154 if (icl_is_hdr_plane(dev_priv, plane->id)) {
7155 if (linked->id == PLANE_SPRITE5)
7156 plane_state->cus_ctl |= PLANE_CUS_PLANE_7;
7157 else if (linked->id == PLANE_SPRITE4)
7158 plane_state->cus_ctl |= PLANE_CUS_PLANE_6;
7159 else if (linked->id == PLANE_SPRITE3)
7160 plane_state->cus_ctl |= PLANE_CUS_PLANE_5_RKL;
7161 else if (linked->id == PLANE_SPRITE2)
7162 plane_state->cus_ctl |= PLANE_CUS_PLANE_4_RKL;
7164 MISSING_CASE(linked->id);
7171 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
7173 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
7174 struct intel_atomic_state *state =
7175 to_intel_atomic_state(new_crtc_state->uapi.state);
7176 const struct intel_crtc_state *old_crtc_state =
7177 intel_atomic_get_old_crtc_state(state, crtc);
7179 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
7182 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
7184 const struct drm_display_mode *pipe_mode =
7185 &crtc_state->hw.pipe_mode;
7188 if (!crtc_state->hw.enable)
7191 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
7192 pipe_mode->crtc_clock);
7194 return min(linetime_wm, 0x1ff);
7197 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
7198 const struct intel_cdclk_state *cdclk_state)
7200 const struct drm_display_mode *pipe_mode =
7201 &crtc_state->hw.pipe_mode;
7204 if (!crtc_state->hw.enable)
7207 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
7208 cdclk_state->logical.cdclk);
7210 return min(linetime_wm, 0x1ff);
7213 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
7215 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7216 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7217 const struct drm_display_mode *pipe_mode =
7218 &crtc_state->hw.pipe_mode;
7221 if (!crtc_state->hw.enable)
7224 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
7225 crtc_state->pixel_rate);
7227 /* Display WA #1135: BXT:ALL GLK:ALL */
7228 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
7229 dev_priv->ipc_enabled)
7232 return min(linetime_wm, 0x1ff);
7235 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
7236 struct intel_crtc *crtc)
7238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7239 struct intel_crtc_state *crtc_state =
7240 intel_atomic_get_new_crtc_state(state, crtc);
7241 const struct intel_cdclk_state *cdclk_state;
7243 if (DISPLAY_VER(dev_priv) >= 9)
7244 crtc_state->linetime = skl_linetime_wm(crtc_state);
7246 crtc_state->linetime = hsw_linetime_wm(crtc_state);
7248 if (!hsw_crtc_supports_ips(crtc))
7251 cdclk_state = intel_atomic_get_cdclk_state(state);
7252 if (IS_ERR(cdclk_state))
7253 return PTR_ERR(cdclk_state);
7255 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
7261 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
7262 struct intel_crtc *crtc)
7264 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7265 struct intel_crtc_state *crtc_state =
7266 intel_atomic_get_new_crtc_state(state, crtc);
7267 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
7270 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
7271 mode_changed && !crtc_state->hw.active)
7272 crtc_state->update_wm_post = true;
7274 if (mode_changed && crtc_state->hw.enable &&
7275 dev_priv->display.crtc_compute_clock &&
7276 !crtc_state->bigjoiner_slave &&
7277 !drm_WARN_ON(&dev_priv->drm, crtc_state->shared_dpll)) {
7278 ret = dev_priv->display.crtc_compute_clock(crtc, crtc_state);
7284 * May need to update pipe gamma enable bits
7285 * when C8 planes are getting enabled/disabled.
7287 if (c8_planes_changed(crtc_state))
7288 crtc_state->uapi.color_mgmt_changed = true;
7290 if (mode_changed || crtc_state->update_pipe ||
7291 crtc_state->uapi.color_mgmt_changed) {
7292 ret = intel_color_check(crtc_state);
7297 if (dev_priv->display.compute_pipe_wm) {
7298 ret = dev_priv->display.compute_pipe_wm(crtc_state);
7300 drm_dbg_kms(&dev_priv->drm,
7301 "Target pipe watermarks are invalid\n");
7306 if (dev_priv->display.compute_intermediate_wm) {
7307 if (drm_WARN_ON(&dev_priv->drm,
7308 !dev_priv->display.compute_pipe_wm))
7312 * Calculate 'intermediate' watermarks that satisfy both the
7313 * old state and the new state. We can program these
7316 ret = dev_priv->display.compute_intermediate_wm(crtc_state);
7318 drm_dbg_kms(&dev_priv->drm,
7319 "No valid intermediate pipe watermarks are possible\n");
7324 if (DISPLAY_VER(dev_priv) >= 9) {
7325 if (mode_changed || crtc_state->update_pipe) {
7326 ret = skl_update_scaler_crtc(crtc_state);
7331 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
7336 if (HAS_IPS(dev_priv)) {
7337 ret = hsw_compute_ips_config(crtc_state);
7342 if (DISPLAY_VER(dev_priv) >= 9 ||
7343 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
7344 ret = hsw_compute_linetime_wm(state, crtc);
7350 if (!mode_changed) {
7351 ret = intel_psr2_sel_fetch_update(state, crtc);
7359 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
7361 struct intel_connector *connector;
7362 struct drm_connector_list_iter conn_iter;
7364 drm_connector_list_iter_begin(dev, &conn_iter);
7365 for_each_intel_connector_iter(connector, &conn_iter) {
7366 struct drm_connector_state *conn_state = connector->base.state;
7367 struct intel_encoder *encoder =
7368 to_intel_encoder(connector->base.encoder);
7370 if (conn_state->crtc)
7371 drm_connector_put(&connector->base);
7374 struct intel_crtc *crtc =
7375 to_intel_crtc(encoder->base.crtc);
7376 const struct intel_crtc_state *crtc_state =
7377 to_intel_crtc_state(crtc->base.state);
7379 conn_state->best_encoder = &encoder->base;
7380 conn_state->crtc = &crtc->base;
7381 conn_state->max_bpc = (crtc_state->pipe_bpp ?: 24) / 3;
7383 drm_connector_get(&connector->base);
7385 conn_state->best_encoder = NULL;
7386 conn_state->crtc = NULL;
7389 drm_connector_list_iter_end(&conn_iter);
7393 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
7394 struct intel_crtc_state *pipe_config)
7396 struct drm_connector *connector = conn_state->connector;
7397 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
7398 const struct drm_display_info *info = &connector->display_info;
7401 switch (conn_state->max_bpc) {
7415 MISSING_CASE(conn_state->max_bpc);
7419 if (bpp < pipe_config->pipe_bpp) {
7420 drm_dbg_kms(&i915->drm,
7421 "[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
7422 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
7423 connector->base.id, connector->name,
7425 3 * conn_state->max_requested_bpc,
7426 pipe_config->pipe_bpp);
7428 pipe_config->pipe_bpp = bpp;
7435 compute_baseline_pipe_bpp(struct intel_crtc *crtc,
7436 struct intel_crtc_state *pipe_config)
7438 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7439 struct drm_atomic_state *state = pipe_config->uapi.state;
7440 struct drm_connector *connector;
7441 struct drm_connector_state *connector_state;
7444 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7445 IS_CHERRYVIEW(dev_priv)))
7447 else if (DISPLAY_VER(dev_priv) >= 5)
7452 pipe_config->pipe_bpp = bpp;
7454 /* Clamp display bpp to connector max bpp */
7455 for_each_new_connector_in_state(state, connector, connector_state, i) {
7458 if (connector_state->crtc != &crtc->base)
7461 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
7469 static void intel_dump_crtc_timings(struct drm_i915_private *i915,
7470 const struct drm_display_mode *mode)
7472 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, "
7473 "type: 0x%x flags: 0x%x\n",
7475 mode->crtc_hdisplay, mode->crtc_hsync_start,
7476 mode->crtc_hsync_end, mode->crtc_htotal,
7477 mode->crtc_vdisplay, mode->crtc_vsync_start,
7478 mode->crtc_vsync_end, mode->crtc_vtotal,
7479 mode->type, mode->flags);
7483 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config,
7484 const char *id, unsigned int lane_count,
7485 const struct intel_link_m_n *m_n)
7487 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
7489 drm_dbg_kms(&i915->drm,
7490 "%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
7492 m_n->gmch_m, m_n->gmch_n,
7493 m_n->link_m, m_n->link_n, m_n->tu);
7497 intel_dump_infoframe(struct drm_i915_private *dev_priv,
7498 const union hdmi_infoframe *frame)
7500 if (!drm_debug_enabled(DRM_UT_KMS))
7503 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame);
7507 intel_dump_dp_vsc_sdp(struct drm_i915_private *dev_priv,
7508 const struct drm_dp_vsc_sdp *vsc)
7510 if (!drm_debug_enabled(DRM_UT_KMS))
7513 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, vsc);
7516 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
7518 static const char * const output_type_str[] = {
7519 OUTPUT_TYPE(UNUSED),
7520 OUTPUT_TYPE(ANALOG),
7530 OUTPUT_TYPE(DP_MST),
7535 static void snprintf_output_types(char *buf, size_t len,
7536 unsigned int output_types)
7543 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
7546 if ((output_types & BIT(i)) == 0)
7549 r = snprintf(str, len, "%s%s",
7550 str != buf ? "," : "", output_type_str[i]);
7556 output_types &= ~BIT(i);
7559 WARN_ON_ONCE(output_types != 0);
7562 static const char * const output_format_str[] = {
7563 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
7564 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
7565 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
7568 static const char *output_formats(enum intel_output_format format)
7570 if (format >= ARRAY_SIZE(output_format_str))
7572 return output_format_str[format];
7575 static void intel_dump_plane_state(const struct intel_plane_state *plane_state)
7577 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
7578 struct drm_i915_private *i915 = to_i915(plane->base.dev);
7579 const struct drm_framebuffer *fb = plane_state->hw.fb;
7582 drm_dbg_kms(&i915->drm,
7583 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n",
7584 plane->base.base.id, plane->base.name,
7585 yesno(plane_state->uapi.visible));
7589 drm_dbg_kms(&i915->drm,
7590 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %p4cc modifier = 0x%llx, visible: %s\n",
7591 plane->base.base.id, plane->base.name,
7592 fb->base.id, fb->width, fb->height, &fb->format->format,
7593 fb->modifier, yesno(plane_state->uapi.visible));
7594 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n",
7595 plane_state->hw.rotation, plane_state->scaler_id);
7596 if (plane_state->uapi.visible)
7597 drm_dbg_kms(&i915->drm,
7598 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n",
7599 DRM_RECT_FP_ARG(&plane_state->uapi.src),
7600 DRM_RECT_ARG(&plane_state->uapi.dst));
7603 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config,
7604 struct intel_atomic_state *state,
7605 const char *context)
7607 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
7608 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7609 const struct intel_plane_state *plane_state;
7610 struct intel_plane *plane;
7614 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n",
7615 crtc->base.base.id, crtc->base.name,
7616 yesno(pipe_config->hw.enable), context);
7618 if (!pipe_config->hw.enable)
7621 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
7622 drm_dbg_kms(&dev_priv->drm,
7623 "active: %s, output_types: %s (0x%x), output format: %s\n",
7624 yesno(pipe_config->hw.active),
7625 buf, pipe_config->output_types,
7626 output_formats(pipe_config->output_format));
7628 drm_dbg_kms(&dev_priv->drm,
7629 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
7630 transcoder_name(pipe_config->cpu_transcoder),
7631 pipe_config->pipe_bpp, pipe_config->dither);
7633 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n",
7634 transcoder_name(pipe_config->mst_master_transcoder));
7636 drm_dbg_kms(&dev_priv->drm,
7637 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n",
7638 transcoder_name(pipe_config->master_transcoder),
7639 pipe_config->sync_mode_slaves_mask);
7641 drm_dbg_kms(&dev_priv->drm, "bigjoiner: %s\n",
7642 pipe_config->bigjoiner_slave ? "slave" :
7643 pipe_config->bigjoiner ? "master" : "no");
7645 drm_dbg_kms(&dev_priv->drm, "splitter: %s, link count %d, overlap %d\n",
7646 enableddisabled(pipe_config->splitter.enable),
7647 pipe_config->splitter.link_count,
7648 pipe_config->splitter.pixel_overlap);
7650 if (pipe_config->has_pch_encoder)
7651 intel_dump_m_n_config(pipe_config, "fdi",
7652 pipe_config->fdi_lanes,
7653 &pipe_config->fdi_m_n);
7655 if (intel_crtc_has_dp_encoder(pipe_config)) {
7656 intel_dump_m_n_config(pipe_config, "dp m_n",
7657 pipe_config->lane_count, &pipe_config->dp_m_n);
7658 if (pipe_config->has_drrs)
7659 intel_dump_m_n_config(pipe_config, "dp m2_n2",
7660 pipe_config->lane_count,
7661 &pipe_config->dp_m2_n2);
7664 drm_dbg_kms(&dev_priv->drm,
7665 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n",
7666 pipe_config->has_audio, pipe_config->has_infoframe,
7667 pipe_config->infoframes.enable);
7669 if (pipe_config->infoframes.enable &
7670 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL))
7671 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n",
7672 pipe_config->infoframes.gcp);
7673 if (pipe_config->infoframes.enable &
7674 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI))
7675 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi);
7676 if (pipe_config->infoframes.enable &
7677 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD))
7678 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd);
7679 if (pipe_config->infoframes.enable &
7680 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR))
7681 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi);
7682 if (pipe_config->infoframes.enable &
7683 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_DRM))
7684 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
7685 if (pipe_config->infoframes.enable &
7686 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA))
7687 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm);
7688 if (pipe_config->infoframes.enable &
7689 intel_hdmi_infoframe_enable(DP_SDP_VSC))
7690 intel_dump_dp_vsc_sdp(dev_priv, &pipe_config->infoframes.vsc);
7692 drm_dbg_kms(&dev_priv->drm, "vrr: %s, vmin: %d, vmax: %d, pipeline full: %d, guardband: %d flipline: %d, vmin vblank: %d, vmax vblank: %d\n",
7693 yesno(pipe_config->vrr.enable),
7694 pipe_config->vrr.vmin, pipe_config->vrr.vmax,
7695 pipe_config->vrr.pipeline_full, pipe_config->vrr.guardband,
7696 pipe_config->vrr.flipline,
7697 intel_vrr_vmin_vblank_start(pipe_config),
7698 intel_vrr_vmax_vblank_start(pipe_config));
7700 drm_dbg_kms(&dev_priv->drm, "requested mode:\n");
7701 drm_mode_debug_printmodeline(&pipe_config->hw.mode);
7702 drm_dbg_kms(&dev_priv->drm, "adjusted mode:\n");
7703 drm_mode_debug_printmodeline(&pipe_config->hw.adjusted_mode);
7704 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode);
7705 drm_dbg_kms(&dev_priv->drm, "pipe mode:\n");
7706 drm_mode_debug_printmodeline(&pipe_config->hw.pipe_mode);
7707 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.pipe_mode);
7708 drm_dbg_kms(&dev_priv->drm,
7709 "port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
7710 pipe_config->port_clock,
7711 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
7712 pipe_config->pixel_rate);
7714 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n",
7715 pipe_config->linetime, pipe_config->ips_linetime);
7717 if (DISPLAY_VER(dev_priv) >= 9)
7718 drm_dbg_kms(&dev_priv->drm,
7719 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
7721 pipe_config->scaler_state.scaler_users,
7722 pipe_config->scaler_state.scaler_id);
7724 if (HAS_GMCH(dev_priv))
7725 drm_dbg_kms(&dev_priv->drm,
7726 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
7727 pipe_config->gmch_pfit.control,
7728 pipe_config->gmch_pfit.pgm_ratios,
7729 pipe_config->gmch_pfit.lvds_border_bits);
7731 drm_dbg_kms(&dev_priv->drm,
7732 "pch pfit: " DRM_RECT_FMT ", %s, force thru: %s\n",
7733 DRM_RECT_ARG(&pipe_config->pch_pfit.dst),
7734 enableddisabled(pipe_config->pch_pfit.enabled),
7735 yesno(pipe_config->pch_pfit.force_thru));
7737 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i\n",
7738 pipe_config->ips_enabled, pipe_config->double_wide);
7740 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
7742 if (IS_CHERRYVIEW(dev_priv))
7743 drm_dbg_kms(&dev_priv->drm,
7744 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
7745 pipe_config->cgm_mode, pipe_config->gamma_mode,
7746 pipe_config->gamma_enable, pipe_config->csc_enable);
7748 drm_dbg_kms(&dev_priv->drm,
7749 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n",
7750 pipe_config->csc_mode, pipe_config->gamma_mode,
7751 pipe_config->gamma_enable, pipe_config->csc_enable);
7753 drm_dbg_kms(&dev_priv->drm, "degamma lut: %d entries, gamma lut: %d entries\n",
7754 pipe_config->hw.degamma_lut ?
7755 drm_color_lut_size(pipe_config->hw.degamma_lut) : 0,
7756 pipe_config->hw.gamma_lut ?
7757 drm_color_lut_size(pipe_config->hw.gamma_lut) : 0);
7763 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7764 if (plane->pipe == crtc->pipe)
7765 intel_dump_plane_state(plane_state);
7769 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
7771 struct drm_device *dev = state->base.dev;
7772 struct drm_connector *connector;
7773 struct drm_connector_list_iter conn_iter;
7774 unsigned int used_ports = 0;
7775 unsigned int used_mst_ports = 0;
7779 * We're going to peek into connector->state,
7780 * hence connection_mutex must be held.
7782 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
7785 * Walk the connector list instead of the encoder
7786 * list to detect the problem on ddi platforms
7787 * where there's just one encoder per digital port.
7789 drm_connector_list_iter_begin(dev, &conn_iter);
7790 drm_for_each_connector_iter(connector, &conn_iter) {
7791 struct drm_connector_state *connector_state;
7792 struct intel_encoder *encoder;
7795 drm_atomic_get_new_connector_state(&state->base,
7797 if (!connector_state)
7798 connector_state = connector->state;
7800 if (!connector_state->best_encoder)
7803 encoder = to_intel_encoder(connector_state->best_encoder);
7805 drm_WARN_ON(dev, !connector_state->crtc);
7807 switch (encoder->type) {
7808 case INTEL_OUTPUT_DDI:
7809 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
7812 case INTEL_OUTPUT_DP:
7813 case INTEL_OUTPUT_HDMI:
7814 case INTEL_OUTPUT_EDP:
7815 /* the same port mustn't appear more than once */
7816 if (used_ports & BIT(encoder->port))
7819 used_ports |= BIT(encoder->port);
7821 case INTEL_OUTPUT_DP_MST:
7829 drm_connector_list_iter_end(&conn_iter);
7831 /* can't mix MST and SST/HDMI on the same port */
7832 if (used_ports & used_mst_ports)
7839 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
7840 struct intel_crtc_state *crtc_state)
7842 const struct intel_crtc_state *from_crtc_state = crtc_state;
7844 if (crtc_state->bigjoiner_slave) {
7845 from_crtc_state = intel_atomic_get_new_crtc_state(state,
7846 crtc_state->bigjoiner_linked_crtc);
7848 /* No need to copy state if the master state is unchanged */
7849 if (!from_crtc_state)
7853 intel_crtc_copy_color_blobs(crtc_state, from_crtc_state);
7857 intel_crtc_copy_uapi_to_hw_state(struct intel_atomic_state *state,
7858 struct intel_crtc_state *crtc_state)
7860 crtc_state->hw.enable = crtc_state->uapi.enable;
7861 crtc_state->hw.active = crtc_state->uapi.active;
7862 crtc_state->hw.mode = crtc_state->uapi.mode;
7863 crtc_state->hw.adjusted_mode = crtc_state->uapi.adjusted_mode;
7864 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
7866 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc_state);
7869 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state)
7871 if (crtc_state->bigjoiner_slave)
7874 crtc_state->uapi.enable = crtc_state->hw.enable;
7875 crtc_state->uapi.active = crtc_state->hw.active;
7876 drm_WARN_ON(crtc_state->uapi.crtc->dev,
7877 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0);
7879 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode;
7880 crtc_state->uapi.scaling_filter = crtc_state->hw.scaling_filter;
7882 /* copy color blobs to uapi */
7883 drm_property_replace_blob(&crtc_state->uapi.degamma_lut,
7884 crtc_state->hw.degamma_lut);
7885 drm_property_replace_blob(&crtc_state->uapi.gamma_lut,
7886 crtc_state->hw.gamma_lut);
7887 drm_property_replace_blob(&crtc_state->uapi.ctm,
7888 crtc_state->hw.ctm);
7892 copy_bigjoiner_crtc_state(struct intel_crtc_state *crtc_state,
7893 const struct intel_crtc_state *from_crtc_state)
7895 struct intel_crtc_state *saved_state;
7896 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7898 saved_state = kmemdup(from_crtc_state, sizeof(*saved_state), GFP_KERNEL);
7902 saved_state->uapi = crtc_state->uapi;
7903 saved_state->scaler_state = crtc_state->scaler_state;
7904 saved_state->shared_dpll = crtc_state->shared_dpll;
7905 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
7906 saved_state->crc_enabled = crtc_state->crc_enabled;
7908 intel_crtc_free_hw_state(crtc_state);
7909 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
7912 /* Re-init hw state */
7913 memset(&crtc_state->hw, 0, sizeof(saved_state->hw));
7914 crtc_state->hw.enable = from_crtc_state->hw.enable;
7915 crtc_state->hw.active = from_crtc_state->hw.active;
7916 crtc_state->hw.pipe_mode = from_crtc_state->hw.pipe_mode;
7917 crtc_state->hw.adjusted_mode = from_crtc_state->hw.adjusted_mode;
7920 crtc_state->uapi.mode_changed = from_crtc_state->uapi.mode_changed;
7921 crtc_state->uapi.connectors_changed = from_crtc_state->uapi.connectors_changed;
7922 crtc_state->uapi.active_changed = from_crtc_state->uapi.active_changed;
7923 crtc_state->nv12_planes = crtc_state->c8_planes = crtc_state->update_planes = 0;
7924 crtc_state->bigjoiner_linked_crtc = to_intel_crtc(from_crtc_state->uapi.crtc);
7925 crtc_state->bigjoiner_slave = true;
7926 crtc_state->cpu_transcoder = (enum transcoder)crtc->pipe;
7927 crtc_state->has_audio = false;
7933 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
7934 struct intel_crtc_state *crtc_state)
7936 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
7937 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7938 struct intel_crtc_state *saved_state;
7940 saved_state = intel_crtc_state_alloc(crtc);
7944 /* free the old crtc_state->hw members */
7945 intel_crtc_free_hw_state(crtc_state);
7947 /* FIXME: before the switch to atomic started, a new pipe_config was
7948 * kzalloc'd. Code that depends on any field being zero should be
7949 * fixed, so that the crtc_state can be safely duplicated. For now,
7950 * only fields that are know to not cause problems are preserved. */
7952 saved_state->uapi = crtc_state->uapi;
7953 saved_state->scaler_state = crtc_state->scaler_state;
7954 saved_state->shared_dpll = crtc_state->shared_dpll;
7955 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
7956 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
7957 sizeof(saved_state->icl_port_dplls));
7958 saved_state->crc_enabled = crtc_state->crc_enabled;
7959 if (IS_G4X(dev_priv) ||
7960 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
7961 saved_state->wm = crtc_state->wm;
7963 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
7966 intel_crtc_copy_uapi_to_hw_state(state, crtc_state);
7972 intel_modeset_pipe_config(struct intel_atomic_state *state,
7973 struct intel_crtc_state *pipe_config)
7975 struct drm_crtc *crtc = pipe_config->uapi.crtc;
7976 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev);
7977 struct drm_connector *connector;
7978 struct drm_connector_state *connector_state;
7979 int base_bpp, ret, i;
7982 pipe_config->cpu_transcoder =
7983 (enum transcoder) to_intel_crtc(crtc)->pipe;
7986 * Sanitize sync polarity flags based on requested ones. If neither
7987 * positive or negative polarity is requested, treat this as meaning
7988 * negative polarity.
7990 if (!(pipe_config->hw.adjusted_mode.flags &
7991 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
7992 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
7994 if (!(pipe_config->hw.adjusted_mode.flags &
7995 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
7996 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
7998 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
8003 base_bpp = pipe_config->pipe_bpp;
8006 * Determine the real pipe dimensions. Note that stereo modes can
8007 * increase the actual pipe size due to the frame doubling and
8008 * insertion of additional space for blanks between the frame. This
8009 * is stored in the crtc timings. We use the requested mode to do this
8010 * computation to clearly distinguish it from the adjusted mode, which
8011 * can be changed by the connectors in the below retry loop.
8013 drm_mode_get_hv_timing(&pipe_config->hw.mode,
8014 &pipe_config->pipe_src_w,
8015 &pipe_config->pipe_src_h);
8017 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
8018 struct intel_encoder *encoder =
8019 to_intel_encoder(connector_state->best_encoder);
8021 if (connector_state->crtc != crtc)
8024 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
8025 drm_dbg_kms(&i915->drm,
8026 "rejecting invalid cloning configuration\n");
8031 * Determine output_types before calling the .compute_config()
8032 * hooks so that the hooks can use this information safely.
8034 if (encoder->compute_output_type)
8035 pipe_config->output_types |=
8036 BIT(encoder->compute_output_type(encoder, pipe_config,
8039 pipe_config->output_types |= BIT(encoder->type);
8043 /* Ensure the port clock defaults are reset when retrying. */
8044 pipe_config->port_clock = 0;
8045 pipe_config->pixel_multiplier = 1;
8047 /* Fill in default crtc timings, allow encoders to overwrite them. */
8048 drm_mode_set_crtcinfo(&pipe_config->hw.adjusted_mode,
8049 CRTC_STEREO_DOUBLE);
8051 /* Pass our mode to the connectors and the CRTC to give them a chance to
8052 * adjust it according to limitations or connector properties, and also
8053 * a chance to reject the mode entirely.
8055 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
8056 struct intel_encoder *encoder =
8057 to_intel_encoder(connector_state->best_encoder);
8059 if (connector_state->crtc != crtc)
8062 ret = encoder->compute_config(encoder, pipe_config,
8065 if (ret != -EDEADLK)
8066 drm_dbg_kms(&i915->drm,
8067 "Encoder config failure: %d\n",
8073 /* Set default port clock if not overwritten by the encoder. Needs to be
8074 * done afterwards in case the encoder adjusts the mode. */
8075 if (!pipe_config->port_clock)
8076 pipe_config->port_clock = pipe_config->hw.adjusted_mode.crtc_clock
8077 * pipe_config->pixel_multiplier;
8079 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
8080 if (ret == -EDEADLK)
8083 drm_dbg_kms(&i915->drm, "CRTC fixup failed\n");
8087 if (ret == I915_DISPLAY_CONFIG_RETRY) {
8088 if (drm_WARN(&i915->drm, !retry,
8089 "loop in pipe configuration computation\n"))
8092 drm_dbg_kms(&i915->drm, "CRTC bw constrained, retrying\n");
8097 /* Dithering seems to not pass-through bits correctly when it should, so
8098 * only enable it on 6bpc panels and when its not a compliance
8099 * test requesting 6bpc video pattern.
8101 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
8102 !pipe_config->dither_force_disable;
8103 drm_dbg_kms(&i915->drm,
8104 "hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
8105 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
8111 intel_modeset_pipe_config_late(struct intel_crtc_state *crtc_state)
8113 struct intel_atomic_state *state =
8114 to_intel_atomic_state(crtc_state->uapi.state);
8115 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
8116 struct drm_connector_state *conn_state;
8117 struct drm_connector *connector;
8120 for_each_new_connector_in_state(&state->base, connector,
8122 struct intel_encoder *encoder =
8123 to_intel_encoder(conn_state->best_encoder);
8126 if (conn_state->crtc != &crtc->base ||
8127 !encoder->compute_config_late)
8130 ret = encoder->compute_config_late(encoder, crtc_state,
8139 bool intel_fuzzy_clock_check(int clock1, int clock2)
8143 if (clock1 == clock2)
8146 if (!clock1 || !clock2)
8149 diff = abs(clock1 - clock2);
8151 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
8158 intel_compare_m_n(unsigned int m, unsigned int n,
8159 unsigned int m2, unsigned int n2,
8162 if (m == m2 && n == n2)
8165 if (exact || !m || !n || !m2 || !n2)
8168 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
8175 } else if (n < n2) {
8185 return intel_fuzzy_clock_check(m, m2);
8189 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
8190 const struct intel_link_m_n *m2_n2,
8193 return m_n->tu == m2_n2->tu &&
8194 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
8195 m2_n2->gmch_m, m2_n2->gmch_n, exact) &&
8196 intel_compare_m_n(m_n->link_m, m_n->link_n,
8197 m2_n2->link_m, m2_n2->link_n, exact);
8201 intel_compare_infoframe(const union hdmi_infoframe *a,
8202 const union hdmi_infoframe *b)
8204 return memcmp(a, b, sizeof(*a)) == 0;
8208 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
8209 const struct drm_dp_vsc_sdp *b)
8211 return memcmp(a, b, sizeof(*a)) == 0;
8215 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
8216 bool fastset, const char *name,
8217 const union hdmi_infoframe *a,
8218 const union hdmi_infoframe *b)
8221 if (!drm_debug_enabled(DRM_UT_KMS))
8224 drm_dbg_kms(&dev_priv->drm,
8225 "fastset mismatch in %s infoframe\n", name);
8226 drm_dbg_kms(&dev_priv->drm, "expected:\n");
8227 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
8228 drm_dbg_kms(&dev_priv->drm, "found:\n");
8229 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
8231 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
8232 drm_err(&dev_priv->drm, "expected:\n");
8233 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
8234 drm_err(&dev_priv->drm, "found:\n");
8235 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
8240 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
8241 bool fastset, const char *name,
8242 const struct drm_dp_vsc_sdp *a,
8243 const struct drm_dp_vsc_sdp *b)
8246 if (!drm_debug_enabled(DRM_UT_KMS))
8249 drm_dbg_kms(&dev_priv->drm,
8250 "fastset mismatch in %s dp sdp\n", name);
8251 drm_dbg_kms(&dev_priv->drm, "expected:\n");
8252 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
8253 drm_dbg_kms(&dev_priv->drm, "found:\n");
8254 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
8256 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
8257 drm_err(&dev_priv->drm, "expected:\n");
8258 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
8259 drm_err(&dev_priv->drm, "found:\n");
8260 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
8264 static void __printf(4, 5)
8265 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
8266 const char *name, const char *format, ...)
8268 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
8269 struct va_format vaf;
8272 va_start(args, format);
8277 drm_dbg_kms(&i915->drm,
8278 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
8279 crtc->base.base.id, crtc->base.name, name, &vaf);
8281 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
8282 crtc->base.base.id, crtc->base.name, name, &vaf);
8287 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
8289 if (dev_priv->params.fastboot != -1)
8290 return dev_priv->params.fastboot;
8292 /* Enable fastboot by default on Skylake and newer */
8293 if (DISPLAY_VER(dev_priv) >= 9)
8296 /* Enable fastboot by default on VLV and CHV */
8297 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
8300 /* Disabled by default on all others */
8305 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
8306 const struct intel_crtc_state *pipe_config,
8309 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
8310 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
8313 bool fixup_inherited = fastset &&
8314 current_config->inherited && !pipe_config->inherited;
8316 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
8317 drm_dbg_kms(&dev_priv->drm,
8318 "initial modeset and fastboot not set\n");
8322 #define PIPE_CONF_CHECK_X(name) do { \
8323 if (current_config->name != pipe_config->name) { \
8324 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8325 "(expected 0x%08x, found 0x%08x)", \
8326 current_config->name, \
8327 pipe_config->name); \
8332 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
8333 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
8334 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8335 "(expected 0x%08x, found 0x%08x)", \
8336 current_config->name & (mask), \
8337 pipe_config->name & (mask)); \
8342 #define PIPE_CONF_CHECK_I(name) do { \
8343 if (current_config->name != pipe_config->name) { \
8344 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8345 "(expected %i, found %i)", \
8346 current_config->name, \
8347 pipe_config->name); \
8352 #define PIPE_CONF_CHECK_BOOL(name) do { \
8353 if (current_config->name != pipe_config->name) { \
8354 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8355 "(expected %s, found %s)", \
8356 yesno(current_config->name), \
8357 yesno(pipe_config->name)); \
8363 * Checks state where we only read out the enabling, but not the entire
8364 * state itself (like full infoframes or ELD for audio). These states
8365 * require a full modeset on bootup to fix up.
8367 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
8368 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
8369 PIPE_CONF_CHECK_BOOL(name); \
8371 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8372 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
8373 yesno(current_config->name), \
8374 yesno(pipe_config->name)); \
8379 #define PIPE_CONF_CHECK_P(name) do { \
8380 if (current_config->name != pipe_config->name) { \
8381 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8382 "(expected %p, found %p)", \
8383 current_config->name, \
8384 pipe_config->name); \
8389 #define PIPE_CONF_CHECK_M_N(name) do { \
8390 if (!intel_compare_link_m_n(¤t_config->name, \
8391 &pipe_config->name,\
8393 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8394 "(expected tu %i gmch %i/%i link %i/%i, " \
8395 "found tu %i, gmch %i/%i link %i/%i)", \
8396 current_config->name.tu, \
8397 current_config->name.gmch_m, \
8398 current_config->name.gmch_n, \
8399 current_config->name.link_m, \
8400 current_config->name.link_n, \
8401 pipe_config->name.tu, \
8402 pipe_config->name.gmch_m, \
8403 pipe_config->name.gmch_n, \
8404 pipe_config->name.link_m, \
8405 pipe_config->name.link_n); \
8410 /* This is required for BDW+ where there is only one set of registers for
8411 * switching between high and low RR.
8412 * This macro can be used whenever a comparison has to be made between one
8413 * hw state and multiple sw state variables.
8415 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
8416 if (!intel_compare_link_m_n(¤t_config->name, \
8417 &pipe_config->name, !fastset) && \
8418 !intel_compare_link_m_n(¤t_config->alt_name, \
8419 &pipe_config->name, !fastset)) { \
8420 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8421 "(expected tu %i gmch %i/%i link %i/%i, " \
8422 "or tu %i gmch %i/%i link %i/%i, " \
8423 "found tu %i, gmch %i/%i link %i/%i)", \
8424 current_config->name.tu, \
8425 current_config->name.gmch_m, \
8426 current_config->name.gmch_n, \
8427 current_config->name.link_m, \
8428 current_config->name.link_n, \
8429 current_config->alt_name.tu, \
8430 current_config->alt_name.gmch_m, \
8431 current_config->alt_name.gmch_n, \
8432 current_config->alt_name.link_m, \
8433 current_config->alt_name.link_n, \
8434 pipe_config->name.tu, \
8435 pipe_config->name.gmch_m, \
8436 pipe_config->name.gmch_n, \
8437 pipe_config->name.link_m, \
8438 pipe_config->name.link_n); \
8443 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
8444 if ((current_config->name ^ pipe_config->name) & (mask)) { \
8445 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8446 "(%x) (expected %i, found %i)", \
8448 current_config->name & (mask), \
8449 pipe_config->name & (mask)); \
8454 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
8455 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
8456 pipe_config_mismatch(fastset, crtc, __stringify(name), \
8457 "(expected %i, found %i)", \
8458 current_config->name, \
8459 pipe_config->name); \
8464 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
8465 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
8466 &pipe_config->infoframes.name)) { \
8467 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
8468 ¤t_config->infoframes.name, \
8469 &pipe_config->infoframes.name); \
8474 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
8475 if (!current_config->has_psr && !pipe_config->has_psr && \
8476 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
8477 &pipe_config->infoframes.name)) { \
8478 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
8479 ¤t_config->infoframes.name, \
8480 &pipe_config->infoframes.name); \
8485 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
8486 if (current_config->name1 != pipe_config->name1) { \
8487 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
8488 "(expected %i, found %i, won't compare lut values)", \
8489 current_config->name1, \
8490 pipe_config->name1); \
8493 if (!intel_color_lut_equal(current_config->name2, \
8494 pipe_config->name2, pipe_config->name1, \
8496 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
8497 "hw_state doesn't match sw_state"); \
8503 #define PIPE_CONF_QUIRK(quirk) \
8504 ((current_config->quirks | pipe_config->quirks) & (quirk))
8506 PIPE_CONF_CHECK_I(cpu_transcoder);
8508 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
8509 PIPE_CONF_CHECK_I(fdi_lanes);
8510 PIPE_CONF_CHECK_M_N(fdi_m_n);
8512 PIPE_CONF_CHECK_I(lane_count);
8513 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
8515 if (DISPLAY_VER(dev_priv) < 8) {
8516 PIPE_CONF_CHECK_M_N(dp_m_n);
8518 if (current_config->has_drrs)
8519 PIPE_CONF_CHECK_M_N(dp_m2_n2);
8521 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
8523 PIPE_CONF_CHECK_X(output_types);
8525 /* FIXME do the readout properly and get rid of this quirk */
8526 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
8527 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hdisplay);
8528 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_htotal);
8529 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_start);
8530 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hblank_end);
8531 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_start);
8532 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_hsync_end);
8534 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vdisplay);
8535 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vtotal);
8536 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_start);
8537 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vblank_end);
8538 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_start);
8539 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_vsync_end);
8541 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hdisplay);
8542 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_htotal);
8543 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_start);
8544 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hblank_end);
8545 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_start);
8546 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_hsync_end);
8548 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vdisplay);
8549 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vtotal);
8550 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_start);
8551 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vblank_end);
8552 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_start);
8553 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_vsync_end);
8555 PIPE_CONF_CHECK_I(pixel_multiplier);
8557 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8558 DRM_MODE_FLAG_INTERLACE);
8560 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
8561 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8562 DRM_MODE_FLAG_PHSYNC);
8563 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8564 DRM_MODE_FLAG_NHSYNC);
8565 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8566 DRM_MODE_FLAG_PVSYNC);
8567 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
8568 DRM_MODE_FLAG_NVSYNC);
8572 PIPE_CONF_CHECK_I(output_format);
8573 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
8574 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
8575 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
8576 PIPE_CONF_CHECK_BOOL(limited_color_range);
8578 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
8579 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
8580 PIPE_CONF_CHECK_BOOL(has_infoframe);
8581 /* FIXME do the readout properly and get rid of this quirk */
8582 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
8583 PIPE_CONF_CHECK_BOOL(fec_enable);
8585 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
8587 PIPE_CONF_CHECK_X(gmch_pfit.control);
8588 /* pfit ratios are autocomputed by the hw on gen4+ */
8589 if (DISPLAY_VER(dev_priv) < 4)
8590 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
8591 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
8594 * Changing the EDP transcoder input mux
8595 * (A_ONOFF vs. A_ON) requires a full modeset.
8597 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
8600 PIPE_CONF_CHECK_I(pipe_src_w);
8601 PIPE_CONF_CHECK_I(pipe_src_h);
8603 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
8604 if (current_config->pch_pfit.enabled) {
8605 PIPE_CONF_CHECK_I(pch_pfit.dst.x1);
8606 PIPE_CONF_CHECK_I(pch_pfit.dst.y1);
8607 PIPE_CONF_CHECK_I(pch_pfit.dst.x2);
8608 PIPE_CONF_CHECK_I(pch_pfit.dst.y2);
8611 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
8612 /* FIXME do the readout properly and get rid of this quirk */
8613 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE))
8614 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
8616 PIPE_CONF_CHECK_X(gamma_mode);
8617 if (IS_CHERRYVIEW(dev_priv))
8618 PIPE_CONF_CHECK_X(cgm_mode);
8620 PIPE_CONF_CHECK_X(csc_mode);
8621 PIPE_CONF_CHECK_BOOL(gamma_enable);
8622 PIPE_CONF_CHECK_BOOL(csc_enable);
8624 PIPE_CONF_CHECK_I(linetime);
8625 PIPE_CONF_CHECK_I(ips_linetime);
8627 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
8629 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
8631 PIPE_CONF_CHECK_BOOL(has_psr);
8632 PIPE_CONF_CHECK_BOOL(has_psr2);
8633 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
8634 PIPE_CONF_CHECK_I(dc3co_exitline);
8637 PIPE_CONF_CHECK_BOOL(double_wide);
8639 PIPE_CONF_CHECK_P(shared_dpll);
8641 /* FIXME do the readout properly and get rid of this quirk */
8642 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_BIGJOINER_SLAVE)) {
8643 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
8644 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
8645 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
8646 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
8647 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
8648 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
8649 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
8650 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
8651 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
8652 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
8653 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
8654 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
8655 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
8656 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
8657 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
8658 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
8659 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
8660 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
8661 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
8662 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
8663 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
8664 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
8665 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
8666 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
8667 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
8668 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
8669 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
8670 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
8671 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
8672 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
8673 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
8675 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
8676 PIPE_CONF_CHECK_X(dsi_pll.div);
8678 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
8679 PIPE_CONF_CHECK_I(pipe_bpp);
8681 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
8682 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
8683 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
8685 PIPE_CONF_CHECK_I(min_voltage_level);
8688 if (fastset && (current_config->has_psr || pipe_config->has_psr))
8689 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
8690 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
8692 PIPE_CONF_CHECK_X(infoframes.enable);
8694 PIPE_CONF_CHECK_X(infoframes.gcp);
8695 PIPE_CONF_CHECK_INFOFRAME(avi);
8696 PIPE_CONF_CHECK_INFOFRAME(spd);
8697 PIPE_CONF_CHECK_INFOFRAME(hdmi);
8698 PIPE_CONF_CHECK_INFOFRAME(drm);
8699 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
8701 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
8702 PIPE_CONF_CHECK_I(master_transcoder);
8703 PIPE_CONF_CHECK_BOOL(bigjoiner);
8704 PIPE_CONF_CHECK_BOOL(bigjoiner_slave);
8705 PIPE_CONF_CHECK_P(bigjoiner_linked_crtc);
8707 PIPE_CONF_CHECK_I(dsc.compression_enable);
8708 PIPE_CONF_CHECK_I(dsc.dsc_split);
8709 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
8711 PIPE_CONF_CHECK_BOOL(splitter.enable);
8712 PIPE_CONF_CHECK_I(splitter.link_count);
8713 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
8715 PIPE_CONF_CHECK_I(mst_master_transcoder);
8717 PIPE_CONF_CHECK_BOOL(vrr.enable);
8718 PIPE_CONF_CHECK_I(vrr.vmin);
8719 PIPE_CONF_CHECK_I(vrr.vmax);
8720 PIPE_CONF_CHECK_I(vrr.flipline);
8721 PIPE_CONF_CHECK_I(vrr.pipeline_full);
8722 PIPE_CONF_CHECK_I(vrr.guardband);
8724 #undef PIPE_CONF_CHECK_X
8725 #undef PIPE_CONF_CHECK_I
8726 #undef PIPE_CONF_CHECK_BOOL
8727 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
8728 #undef PIPE_CONF_CHECK_P
8729 #undef PIPE_CONF_CHECK_FLAGS
8730 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
8731 #undef PIPE_CONF_CHECK_COLOR_LUT
8732 #undef PIPE_CONF_QUIRK
8737 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
8738 const struct intel_crtc_state *pipe_config)
8740 if (pipe_config->has_pch_encoder) {
8741 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
8742 &pipe_config->fdi_m_n);
8743 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
8746 * FDI already provided one idea for the dotclock.
8747 * Yell if the encoder disagrees.
8749 drm_WARN(&dev_priv->drm,
8750 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
8751 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
8752 fdi_dotclock, dotclock);
8756 static void verify_wm_state(struct intel_crtc *crtc,
8757 struct intel_crtc_state *new_crtc_state)
8759 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8760 struct skl_hw_state {
8761 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
8762 struct skl_ddb_entry ddb_uv[I915_MAX_PLANES];
8763 struct skl_pipe_wm wm;
8765 const struct skl_pipe_wm *sw_wm = &new_crtc_state->wm.skl.optimal;
8766 int level, max_level = ilk_wm_max_level(dev_priv);
8767 struct intel_plane *plane;
8768 u8 hw_enabled_slices;
8770 if (DISPLAY_VER(dev_priv) < 9 || !new_crtc_state->hw.active)
8773 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
8777 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
8779 skl_pipe_ddb_get_hw_state(crtc, hw->ddb_y, hw->ddb_uv);
8781 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
8783 if (DISPLAY_VER(dev_priv) >= 11 &&
8784 hw_enabled_slices != dev_priv->dbuf.enabled_slices)
8785 drm_err(&dev_priv->drm,
8786 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
8787 dev_priv->dbuf.enabled_slices,
8790 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
8791 const struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
8792 const struct skl_wm_level *hw_wm_level, *sw_wm_level;
8795 for (level = 0; level <= max_level; level++) {
8796 hw_wm_level = &hw->wm.planes[plane->id].wm[level];
8797 sw_wm_level = skl_plane_wm_level(sw_wm, plane->id, level);
8799 if (skl_wm_level_equals(hw_wm_level, sw_wm_level))
8802 drm_err(&dev_priv->drm,
8803 "[PLANE:%d:%s] mismatch in WM%d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8804 plane->base.base.id, plane->base.name, level,
8805 sw_wm_level->enable,
8806 sw_wm_level->blocks,
8808 hw_wm_level->enable,
8809 hw_wm_level->blocks,
8810 hw_wm_level->lines);
8813 hw_wm_level = &hw->wm.planes[plane->id].trans_wm;
8814 sw_wm_level = skl_plane_trans_wm(sw_wm, plane->id);
8816 if (!skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8817 drm_err(&dev_priv->drm,
8818 "[PLANE:%d:%s] mismatch in trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8819 plane->base.base.id, plane->base.name,
8820 sw_wm_level->enable,
8821 sw_wm_level->blocks,
8823 hw_wm_level->enable,
8824 hw_wm_level->blocks,
8825 hw_wm_level->lines);
8828 hw_wm_level = &hw->wm.planes[plane->id].sagv.wm0;
8829 sw_wm_level = &sw_wm->planes[plane->id].sagv.wm0;
8831 if (HAS_HW_SAGV_WM(dev_priv) &&
8832 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8833 drm_err(&dev_priv->drm,
8834 "[PLANE:%d:%s] mismatch in SAGV WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8835 plane->base.base.id, plane->base.name,
8836 sw_wm_level->enable,
8837 sw_wm_level->blocks,
8839 hw_wm_level->enable,
8840 hw_wm_level->blocks,
8841 hw_wm_level->lines);
8844 hw_wm_level = &hw->wm.planes[plane->id].sagv.trans_wm;
8845 sw_wm_level = &sw_wm->planes[plane->id].sagv.trans_wm;
8847 if (HAS_HW_SAGV_WM(dev_priv) &&
8848 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
8849 drm_err(&dev_priv->drm,
8850 "[PLANE:%d:%s] mismatch in SAGV trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
8851 plane->base.base.id, plane->base.name,
8852 sw_wm_level->enable,
8853 sw_wm_level->blocks,
8855 hw_wm_level->enable,
8856 hw_wm_level->blocks,
8857 hw_wm_level->lines);
8861 hw_ddb_entry = &hw->ddb_y[plane->id];
8862 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb_y[plane->id];
8864 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
8865 drm_err(&dev_priv->drm,
8866 "[PLANE:%d:%s] mismatch in DDB (expected (%u,%u), found (%u,%u))\n",
8867 plane->base.base.id, plane->base.name,
8868 sw_ddb_entry->start, sw_ddb_entry->end,
8869 hw_ddb_entry->start, hw_ddb_entry->end);
8877 verify_connector_state(struct intel_atomic_state *state,
8878 struct intel_crtc *crtc)
8880 struct drm_connector *connector;
8881 struct drm_connector_state *new_conn_state;
8884 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
8885 struct drm_encoder *encoder = connector->encoder;
8886 struct intel_crtc_state *crtc_state = NULL;
8888 if (new_conn_state->crtc != &crtc->base)
8892 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
8894 intel_connector_verify_state(crtc_state, new_conn_state);
8896 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
8897 "connector's atomic encoder doesn't match legacy encoder\n");
8902 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
8904 struct intel_encoder *encoder;
8905 struct drm_connector *connector;
8906 struct drm_connector_state *old_conn_state, *new_conn_state;
8909 for_each_intel_encoder(&dev_priv->drm, encoder) {
8910 bool enabled = false, found = false;
8913 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
8914 encoder->base.base.id,
8915 encoder->base.name);
8917 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
8918 new_conn_state, i) {
8919 if (old_conn_state->best_encoder == &encoder->base)
8922 if (new_conn_state->best_encoder != &encoder->base)
8924 found = enabled = true;
8926 I915_STATE_WARN(new_conn_state->crtc !=
8928 "connector's crtc doesn't match encoder crtc\n");
8934 I915_STATE_WARN(!!encoder->base.crtc != enabled,
8935 "encoder's enabled state mismatch "
8936 "(expected %i, found %i)\n",
8937 !!encoder->base.crtc, enabled);
8939 if (!encoder->base.crtc) {
8942 active = encoder->get_hw_state(encoder, &pipe);
8943 I915_STATE_WARN(active,
8944 "encoder detached but still enabled on pipe %c.\n",
8951 verify_crtc_state(struct intel_crtc *crtc,
8952 struct intel_crtc_state *old_crtc_state,
8953 struct intel_crtc_state *new_crtc_state)
8955 struct drm_device *dev = crtc->base.dev;
8956 struct drm_i915_private *dev_priv = to_i915(dev);
8957 struct intel_encoder *encoder;
8958 struct intel_crtc_state *pipe_config = old_crtc_state;
8959 struct drm_atomic_state *state = old_crtc_state->uapi.state;
8960 struct intel_crtc *master = crtc;
8962 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
8963 intel_crtc_free_hw_state(old_crtc_state);
8964 intel_crtc_state_reset(old_crtc_state, crtc);
8965 old_crtc_state->uapi.state = state;
8967 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
8970 pipe_config->hw.enable = new_crtc_state->hw.enable;
8972 intel_crtc_get_pipe_config(pipe_config);
8974 /* we keep both pipes enabled on 830 */
8975 if (IS_I830(dev_priv) && pipe_config->hw.active)
8976 pipe_config->hw.active = new_crtc_state->hw.active;
8978 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active,
8979 "crtc active state doesn't match with hw state "
8980 "(expected %i, found %i)\n",
8981 new_crtc_state->hw.active, pipe_config->hw.active);
8983 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
8984 "transitional active state does not match atomic hw state "
8985 "(expected %i, found %i)\n",
8986 new_crtc_state->hw.active, crtc->active);
8988 if (new_crtc_state->bigjoiner_slave)
8989 master = new_crtc_state->bigjoiner_linked_crtc;
8991 for_each_encoder_on_crtc(dev, &master->base, encoder) {
8995 active = encoder->get_hw_state(encoder, &pipe);
8996 I915_STATE_WARN(active != new_crtc_state->hw.active,
8997 "[ENCODER:%i] active %i with crtc active %i\n",
8998 encoder->base.base.id, active,
8999 new_crtc_state->hw.active);
9001 I915_STATE_WARN(active && master->pipe != pipe,
9002 "Encoder connected to wrong pipe %c\n",
9006 intel_encoder_get_config(encoder, pipe_config);
9009 if (!new_crtc_state->hw.active)
9012 intel_pipe_config_sanity_check(dev_priv, pipe_config);
9014 if (!intel_pipe_config_compare(new_crtc_state,
9015 pipe_config, false)) {
9016 I915_STATE_WARN(1, "pipe state doesn't match!\n");
9017 intel_dump_pipe_config(pipe_config, NULL, "[hw state]");
9018 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]");
9023 intel_verify_planes(struct intel_atomic_state *state)
9025 struct intel_plane *plane;
9026 const struct intel_plane_state *plane_state;
9029 for_each_new_intel_plane_in_state(state, plane,
9031 assert_plane(plane, plane_state->planar_slave ||
9032 plane_state->uapi.visible);
9036 verify_single_dpll_state(struct drm_i915_private *dev_priv,
9037 struct intel_shared_dpll *pll,
9038 struct intel_crtc *crtc,
9039 struct intel_crtc_state *new_crtc_state)
9041 struct intel_dpll_hw_state dpll_hw_state;
9045 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
9047 drm_dbg_kms(&dev_priv->drm, "%s\n", pll->info->name);
9049 active = intel_dpll_get_hw_state(dev_priv, pll, &dpll_hw_state);
9051 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
9052 I915_STATE_WARN(!pll->on && pll->active_mask,
9053 "pll in active use but not on in sw tracking\n");
9054 I915_STATE_WARN(pll->on && !pll->active_mask,
9055 "pll is on but not used by any active pipe\n");
9056 I915_STATE_WARN(pll->on != active,
9057 "pll on state mismatch (expected %i, found %i)\n",
9062 I915_STATE_WARN(pll->active_mask & ~pll->state.pipe_mask,
9063 "more active pll users than references: 0x%x vs 0x%x\n",
9064 pll->active_mask, pll->state.pipe_mask);
9069 pipe_mask = BIT(crtc->pipe);
9071 if (new_crtc_state->hw.active)
9072 I915_STATE_WARN(!(pll->active_mask & pipe_mask),
9073 "pll active mismatch (expected pipe %c in active mask 0x%x)\n",
9074 pipe_name(crtc->pipe), pll->active_mask);
9076 I915_STATE_WARN(pll->active_mask & pipe_mask,
9077 "pll active mismatch (didn't expect pipe %c in active mask 0x%x)\n",
9078 pipe_name(crtc->pipe), pll->active_mask);
9080 I915_STATE_WARN(!(pll->state.pipe_mask & pipe_mask),
9081 "pll enabled crtcs mismatch (expected 0x%x in 0x%x)\n",
9082 pipe_mask, pll->state.pipe_mask);
9084 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
9086 sizeof(dpll_hw_state)),
9087 "pll hw state mismatch\n");
9091 verify_shared_dpll_state(struct intel_crtc *crtc,
9092 struct intel_crtc_state *old_crtc_state,
9093 struct intel_crtc_state *new_crtc_state)
9095 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9097 if (new_crtc_state->shared_dpll)
9098 verify_single_dpll_state(dev_priv, new_crtc_state->shared_dpll, crtc, new_crtc_state);
9100 if (old_crtc_state->shared_dpll &&
9101 old_crtc_state->shared_dpll != new_crtc_state->shared_dpll) {
9102 u8 pipe_mask = BIT(crtc->pipe);
9103 struct intel_shared_dpll *pll = old_crtc_state->shared_dpll;
9105 I915_STATE_WARN(pll->active_mask & pipe_mask,
9106 "pll active mismatch (didn't expect pipe %c in active mask (0x%x))\n",
9107 pipe_name(crtc->pipe), pll->active_mask);
9108 I915_STATE_WARN(pll->state.pipe_mask & pipe_mask,
9109 "pll enabled crtcs mismatch (found %x in enabled mask (0x%x))\n",
9110 pipe_name(crtc->pipe), pll->state.pipe_mask);
9115 intel_modeset_verify_crtc(struct intel_crtc *crtc,
9116 struct intel_atomic_state *state,
9117 struct intel_crtc_state *old_crtc_state,
9118 struct intel_crtc_state *new_crtc_state)
9120 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
9123 verify_wm_state(crtc, new_crtc_state);
9124 verify_connector_state(state, crtc);
9125 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
9126 verify_shared_dpll_state(crtc, old_crtc_state, new_crtc_state);
9130 verify_disabled_dpll_state(struct drm_i915_private *dev_priv)
9134 for (i = 0; i < dev_priv->dpll.num_shared_dpll; i++)
9135 verify_single_dpll_state(dev_priv,
9136 &dev_priv->dpll.shared_dplls[i],
9141 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
9142 struct intel_atomic_state *state)
9144 verify_encoder_state(dev_priv, state);
9145 verify_connector_state(state, NULL);
9146 verify_disabled_dpll_state(dev_priv);
9149 int intel_modeset_all_pipes(struct intel_atomic_state *state)
9151 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9152 struct intel_crtc *crtc;
9155 * Add all pipes to the state, and force
9156 * a modeset on all the active ones.
9158 for_each_intel_crtc(&dev_priv->drm, crtc) {
9159 struct intel_crtc_state *crtc_state;
9162 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
9163 if (IS_ERR(crtc_state))
9164 return PTR_ERR(crtc_state);
9166 if (!crtc_state->hw.active ||
9167 drm_atomic_crtc_needs_modeset(&crtc_state->uapi))
9170 crtc_state->uapi.mode_changed = true;
9172 ret = drm_atomic_add_affected_connectors(&state->base,
9177 ret = intel_atomic_add_affected_planes(state, crtc);
9181 crtc_state->update_planes |= crtc_state->active_planes;
9188 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
9190 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
9191 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
9192 struct drm_display_mode adjusted_mode =
9193 crtc_state->hw.adjusted_mode;
9195 if (crtc_state->vrr.enable) {
9196 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax;
9197 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax;
9198 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state);
9199 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state);
9202 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
9204 crtc->mode_flags = crtc_state->mode_flags;
9207 * The scanline counter increments at the leading edge of hsync.
9209 * On most platforms it starts counting from vtotal-1 on the
9210 * first active line. That means the scanline counter value is
9211 * always one less than what we would expect. Ie. just after
9212 * start of vblank, which also occurs at start of hsync (on the
9213 * last active line), the scanline counter will read vblank_start-1.
9215 * On gen2 the scanline counter starts counting from 1 instead
9216 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
9217 * to keep the value positive), instead of adding one.
9219 * On HSW+ the behaviour of the scanline counter depends on the output
9220 * type. For DP ports it behaves like most other platforms, but on HDMI
9221 * there's an extra 1 line difference. So we need to add two instead of
9224 * On VLV/CHV DSI the scanline counter would appear to increment
9225 * approx. 1/3 of a scanline before start of vblank. Unfortunately
9226 * that means we can't tell whether we're in vblank or not while
9227 * we're on that particular line. We must still set scanline_offset
9228 * to 1 so that the vblank timestamps come out correct when we query
9229 * the scanline counter from within the vblank interrupt handler.
9230 * However if queried just before the start of vblank we'll get an
9231 * answer that's slightly in the future.
9233 if (DISPLAY_VER(dev_priv) == 2) {
9236 vtotal = adjusted_mode.crtc_vtotal;
9237 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
9240 crtc->scanline_offset = vtotal - 1;
9241 } else if (HAS_DDI(dev_priv) &&
9242 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
9243 crtc->scanline_offset = 2;
9245 crtc->scanline_offset = 1;
9249 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
9251 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9252 struct intel_crtc_state *new_crtc_state;
9253 struct intel_crtc *crtc;
9256 if (!dev_priv->display.crtc_compute_clock)
9259 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9260 if (!intel_crtc_needs_modeset(new_crtc_state))
9263 intel_release_shared_dplls(state, crtc);
9268 * This implements the workaround described in the "notes" section of the mode
9269 * set sequence documentation. When going from no pipes or single pipe to
9270 * multiple pipes, and planes are enabled after the pipe, we need to wait at
9271 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
9273 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
9275 struct intel_crtc_state *crtc_state;
9276 struct intel_crtc *crtc;
9277 struct intel_crtc_state *first_crtc_state = NULL;
9278 struct intel_crtc_state *other_crtc_state = NULL;
9279 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
9282 /* look at all crtc's that are going to be enabled in during modeset */
9283 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9284 if (!crtc_state->hw.active ||
9285 !intel_crtc_needs_modeset(crtc_state))
9288 if (first_crtc_state) {
9289 other_crtc_state = crtc_state;
9292 first_crtc_state = crtc_state;
9293 first_pipe = crtc->pipe;
9297 /* No workaround needed? */
9298 if (!first_crtc_state)
9301 /* w/a possibly needed, check how many crtc's are already enabled. */
9302 for_each_intel_crtc(state->base.dev, crtc) {
9303 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
9304 if (IS_ERR(crtc_state))
9305 return PTR_ERR(crtc_state);
9307 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
9309 if (!crtc_state->hw.active ||
9310 intel_crtc_needs_modeset(crtc_state))
9313 /* 2 or more enabled crtcs means no need for w/a */
9314 if (enabled_pipe != INVALID_PIPE)
9317 enabled_pipe = crtc->pipe;
9320 if (enabled_pipe != INVALID_PIPE)
9321 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
9322 else if (other_crtc_state)
9323 other_crtc_state->hsw_workaround_pipe = first_pipe;
9328 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
9331 const struct intel_crtc_state *crtc_state;
9332 struct intel_crtc *crtc;
9335 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9336 if (crtc_state->hw.active)
9337 active_pipes |= BIT(crtc->pipe);
9339 active_pipes &= ~BIT(crtc->pipe);
9342 return active_pipes;
9345 static int intel_modeset_checks(struct intel_atomic_state *state)
9347 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9349 state->modeset = true;
9351 if (IS_HASWELL(dev_priv))
9352 return hsw_mode_set_planes_workaround(state);
9358 * Handle calculation of various watermark data at the end of the atomic check
9359 * phase. The code here should be run after the per-crtc and per-plane 'check'
9360 * handlers to ensure that all derived state has been updated.
9362 static int calc_watermark_data(struct intel_atomic_state *state)
9364 struct drm_device *dev = state->base.dev;
9365 struct drm_i915_private *dev_priv = to_i915(dev);
9367 /* Is there platform-specific watermark information to calculate? */
9368 if (dev_priv->display.compute_global_watermarks)
9369 return dev_priv->display.compute_global_watermarks(state);
9374 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
9375 struct intel_crtc_state *new_crtc_state)
9377 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
9380 new_crtc_state->uapi.mode_changed = false;
9381 new_crtc_state->update_pipe = true;
9384 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
9385 struct intel_crtc_state *new_crtc_state)
9388 * If we're not doing the full modeset we want to
9389 * keep the current M/N values as they may be
9390 * sufficiently different to the computed values
9391 * to cause problems.
9393 * FIXME: should really copy more fuzzy state here
9395 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
9396 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
9397 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
9398 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
9401 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
9402 struct intel_crtc *crtc,
9405 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9406 struct intel_plane *plane;
9408 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
9409 struct intel_plane_state *plane_state;
9411 if ((plane_ids_mask & BIT(plane->id)) == 0)
9414 plane_state = intel_atomic_get_plane_state(state, plane);
9415 if (IS_ERR(plane_state))
9416 return PTR_ERR(plane_state);
9422 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
9423 struct intel_crtc *crtc)
9425 const struct intel_crtc_state *old_crtc_state =
9426 intel_atomic_get_old_crtc_state(state, crtc);
9427 const struct intel_crtc_state *new_crtc_state =
9428 intel_atomic_get_new_crtc_state(state, crtc);
9430 return intel_crtc_add_planes_to_state(state, crtc,
9431 old_crtc_state->enabled_planes |
9432 new_crtc_state->enabled_planes);
9435 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
9437 /* See {hsw,vlv,ivb}_plane_ratio() */
9438 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
9439 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
9440 IS_IVYBRIDGE(dev_priv);
9443 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
9444 struct intel_crtc *crtc,
9445 struct intel_crtc *other)
9447 const struct intel_plane_state *plane_state;
9448 struct intel_plane *plane;
9452 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9453 if (plane->pipe == crtc->pipe)
9454 plane_ids |= BIT(plane->id);
9457 return intel_crtc_add_planes_to_state(state, other, plane_ids);
9460 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
9462 const struct intel_crtc_state *crtc_state;
9463 struct intel_crtc *crtc;
9466 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9469 if (!crtc_state->bigjoiner)
9472 ret = intel_crtc_add_bigjoiner_planes(state, crtc,
9473 crtc_state->bigjoiner_linked_crtc);
9481 static int intel_atomic_check_planes(struct intel_atomic_state *state)
9483 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9484 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9485 struct intel_plane_state *plane_state;
9486 struct intel_plane *plane;
9487 struct intel_crtc *crtc;
9490 ret = icl_add_linked_planes(state);
9494 ret = intel_bigjoiner_add_affected_planes(state);
9498 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9499 ret = intel_plane_atomic_check(state, plane);
9501 drm_dbg_atomic(&dev_priv->drm,
9502 "[PLANE:%d:%s] atomic driver check failed\n",
9503 plane->base.base.id, plane->base.name);
9508 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9509 new_crtc_state, i) {
9510 u8 old_active_planes, new_active_planes;
9512 ret = icl_check_nv12_planes(new_crtc_state);
9517 * On some platforms the number of active planes affects
9518 * the planes' minimum cdclk calculation. Add such planes
9519 * to the state before we compute the minimum cdclk.
9521 if (!active_planes_affects_min_cdclk(dev_priv))
9524 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
9525 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
9527 if (hweight8(old_active_planes) == hweight8(new_active_planes))
9530 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
9538 static int intel_atomic_check_cdclk(struct intel_atomic_state *state,
9539 bool *need_cdclk_calc)
9541 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
9542 const struct intel_cdclk_state *old_cdclk_state;
9543 const struct intel_cdclk_state *new_cdclk_state;
9544 struct intel_plane_state *plane_state;
9545 struct intel_bw_state *new_bw_state;
9546 struct intel_plane *plane;
9552 * active_planes bitmask has been updated, and potentially
9553 * affected planes are part of the state. We can now
9554 * compute the minimum cdclk for each plane.
9556 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
9557 ret = intel_plane_calc_min_cdclk(state, plane, need_cdclk_calc);
9562 old_cdclk_state = intel_atomic_get_old_cdclk_state(state);
9563 new_cdclk_state = intel_atomic_get_new_cdclk_state(state);
9565 if (new_cdclk_state &&
9566 old_cdclk_state->force_min_cdclk != new_cdclk_state->force_min_cdclk)
9567 *need_cdclk_calc = true;
9569 ret = dev_priv->display.bw_calc_min_cdclk(state);
9573 new_bw_state = intel_atomic_get_new_bw_state(state);
9575 if (!new_cdclk_state || !new_bw_state)
9578 for_each_pipe(dev_priv, pipe) {
9579 min_cdclk = max(new_cdclk_state->min_cdclk[pipe], min_cdclk);
9582 * Currently do this change only if we need to increase
9584 if (new_bw_state->min_cdclk > min_cdclk)
9585 *need_cdclk_calc = true;
9591 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
9593 struct intel_crtc_state *crtc_state;
9594 struct intel_crtc *crtc;
9597 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9598 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
9601 ret = intel_crtc_atomic_check(state, crtc);
9603 drm_dbg_atomic(&i915->drm,
9604 "[CRTC:%d:%s] atomic driver check failed\n",
9605 crtc->base.base.id, crtc->base.name);
9613 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
9616 const struct intel_crtc_state *new_crtc_state;
9617 struct intel_crtc *crtc;
9620 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9621 if (new_crtc_state->hw.enable &&
9622 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
9623 intel_crtc_needs_modeset(new_crtc_state))
9630 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
9631 struct intel_crtc *crtc,
9632 struct intel_crtc_state *old_crtc_state,
9633 struct intel_crtc_state *new_crtc_state)
9635 struct intel_crtc_state *slave_crtc_state, *master_crtc_state;
9636 struct intel_crtc *slave, *master;
9638 /* slave being enabled, is master is still claiming this crtc? */
9639 if (old_crtc_state->bigjoiner_slave) {
9641 master = old_crtc_state->bigjoiner_linked_crtc;
9642 master_crtc_state = intel_atomic_get_new_crtc_state(state, master);
9643 if (!master_crtc_state || !intel_crtc_needs_modeset(master_crtc_state))
9647 if (!new_crtc_state->bigjoiner)
9650 slave = intel_dsc_get_bigjoiner_secondary(crtc);
9652 DRM_DEBUG_KMS("[CRTC:%d:%s] Big joiner configuration requires "
9653 "CRTC + 1 to be used, doesn't exist\n",
9654 crtc->base.base.id, crtc->base.name);
9658 new_crtc_state->bigjoiner_linked_crtc = slave;
9659 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave);
9661 if (IS_ERR(slave_crtc_state))
9662 return PTR_ERR(slave_crtc_state);
9664 /* master being enabled, slave was already configured? */
9665 if (slave_crtc_state->uapi.enable)
9668 DRM_DEBUG_KMS("[CRTC:%d:%s] Used as slave for big joiner\n",
9669 slave->base.base.id, slave->base.name);
9671 return copy_bigjoiner_crtc_state(slave_crtc_state, new_crtc_state);
9674 DRM_DEBUG_KMS("[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
9675 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
9676 slave->base.base.id, slave->base.name,
9677 master->base.base.id, master->base.name);
9681 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
9682 struct intel_crtc_state *master_crtc_state)
9684 struct intel_crtc_state *slave_crtc_state =
9685 intel_atomic_get_new_crtc_state(state, master_crtc_state->bigjoiner_linked_crtc);
9687 slave_crtc_state->bigjoiner = master_crtc_state->bigjoiner = false;
9688 slave_crtc_state->bigjoiner_slave = master_crtc_state->bigjoiner_slave = false;
9689 slave_crtc_state->bigjoiner_linked_crtc = master_crtc_state->bigjoiner_linked_crtc = NULL;
9690 intel_crtc_copy_uapi_to_hw_state(state, slave_crtc_state);
9694 * DOC: asynchronous flip implementation
9696 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
9697 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
9698 * Correspondingly, support is currently added for primary plane only.
9700 * Async flip can only change the plane surface address, so anything else
9701 * changing is rejected from the intel_atomic_check_async() function.
9702 * Once this check is cleared, flip done interrupt is enabled using
9703 * the intel_crtc_enable_flip_done() function.
9705 * As soon as the surface address register is written, flip done interrupt is
9706 * generated and the requested events are sent to the usersapce in the interrupt
9707 * handler itself. The timestamp and sequence sent during the flip done event
9708 * correspond to the last vblank and have no relation to the actual time when
9709 * the flip done event was sent.
9711 static int intel_atomic_check_async(struct intel_atomic_state *state)
9713 struct drm_i915_private *i915 = to_i915(state->base.dev);
9714 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9715 const struct intel_plane_state *new_plane_state, *old_plane_state;
9716 struct intel_crtc *crtc;
9717 struct intel_plane *plane;
9720 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9721 new_crtc_state, i) {
9722 if (intel_crtc_needs_modeset(new_crtc_state)) {
9723 drm_dbg_kms(&i915->drm, "Modeset Required. Async flip not supported\n");
9727 if (!new_crtc_state->hw.active) {
9728 drm_dbg_kms(&i915->drm, "CRTC inactive\n");
9731 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
9732 drm_dbg_kms(&i915->drm,
9733 "Active planes cannot be changed during async flip\n");
9738 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
9739 new_plane_state, i) {
9741 * TODO: Async flip is only supported through the page flip IOCTL
9742 * as of now. So support currently added for primary plane only.
9743 * Support for other planes on platforms on which supports
9744 * this(vlv/chv and icl+) should be added when async flip is
9745 * enabled in the atomic IOCTL path.
9747 if (!plane->async_flip)
9751 * FIXME: This check is kept generic for all platforms.
9752 * Need to verify this for all gen9 and gen10 platforms to enable
9753 * this selectively if required.
9755 switch (new_plane_state->hw.fb->modifier) {
9756 case I915_FORMAT_MOD_X_TILED:
9757 case I915_FORMAT_MOD_Y_TILED:
9758 case I915_FORMAT_MOD_Yf_TILED:
9761 drm_dbg_kms(&i915->drm,
9762 "Linear memory/CCS does not support async flips\n");
9766 if (old_plane_state->view.color_plane[0].stride !=
9767 new_plane_state->view.color_plane[0].stride) {
9768 drm_dbg_kms(&i915->drm, "Stride cannot be changed in async flip\n");
9772 if (old_plane_state->hw.fb->modifier !=
9773 new_plane_state->hw.fb->modifier) {
9774 drm_dbg_kms(&i915->drm,
9775 "Framebuffer modifiers cannot be changed in async flip\n");
9779 if (old_plane_state->hw.fb->format !=
9780 new_plane_state->hw.fb->format) {
9781 drm_dbg_kms(&i915->drm,
9782 "Framebuffer format cannot be changed in async flip\n");
9786 if (old_plane_state->hw.rotation !=
9787 new_plane_state->hw.rotation) {
9788 drm_dbg_kms(&i915->drm, "Rotation cannot be changed in async flip\n");
9792 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
9793 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
9794 drm_dbg_kms(&i915->drm,
9795 "Plane size/co-ordinates cannot be changed in async flip\n");
9799 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
9800 drm_dbg_kms(&i915->drm, "Alpha value cannot be changed in async flip\n");
9804 if (old_plane_state->hw.pixel_blend_mode !=
9805 new_plane_state->hw.pixel_blend_mode) {
9806 drm_dbg_kms(&i915->drm,
9807 "Pixel blend mode cannot be changed in async flip\n");
9811 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
9812 drm_dbg_kms(&i915->drm,
9813 "Color encoding cannot be changed in async flip\n");
9817 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
9818 drm_dbg_kms(&i915->drm, "Color range cannot be changed in async flip\n");
9826 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
9828 struct intel_crtc_state *crtc_state;
9829 struct intel_crtc *crtc;
9832 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9833 struct intel_crtc_state *linked_crtc_state;
9834 struct intel_crtc *linked_crtc;
9837 if (!crtc_state->bigjoiner)
9840 linked_crtc = crtc_state->bigjoiner_linked_crtc;
9841 linked_crtc_state = intel_atomic_get_crtc_state(&state->base, linked_crtc);
9842 if (IS_ERR(linked_crtc_state))
9843 return PTR_ERR(linked_crtc_state);
9845 if (!intel_crtc_needs_modeset(crtc_state))
9848 linked_crtc_state->uapi.mode_changed = true;
9850 ret = drm_atomic_add_affected_connectors(&state->base,
9851 &linked_crtc->base);
9855 ret = intel_atomic_add_affected_planes(state, linked_crtc);
9860 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
9861 /* Kill old bigjoiner link, we may re-establish afterwards */
9862 if (intel_crtc_needs_modeset(crtc_state) &&
9863 crtc_state->bigjoiner && !crtc_state->bigjoiner_slave)
9864 kill_bigjoiner_slave(state, crtc_state);
9871 * intel_atomic_check - validate state object
9873 * @_state: state to validate
9875 static int intel_atomic_check(struct drm_device *dev,
9876 struct drm_atomic_state *_state)
9878 struct drm_i915_private *dev_priv = to_i915(dev);
9879 struct intel_atomic_state *state = to_intel_atomic_state(_state);
9880 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
9881 struct intel_crtc *crtc;
9883 bool any_ms = false;
9885 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9886 new_crtc_state, i) {
9887 if (new_crtc_state->inherited != old_crtc_state->inherited)
9888 new_crtc_state->uapi.mode_changed = true;
9891 intel_vrr_check_modeset(state);
9893 ret = drm_atomic_helper_check_modeset(dev, &state->base);
9897 ret = intel_bigjoiner_add_affected_crtcs(state);
9901 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9902 new_crtc_state, i) {
9903 if (!intel_crtc_needs_modeset(new_crtc_state)) {
9905 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, new_crtc_state);
9910 if (!new_crtc_state->uapi.enable) {
9911 if (!new_crtc_state->bigjoiner_slave) {
9912 intel_crtc_copy_uapi_to_hw_state(state, new_crtc_state);
9918 ret = intel_crtc_prepare_cleared_state(state, new_crtc_state);
9922 ret = intel_modeset_pipe_config(state, new_crtc_state);
9926 ret = intel_atomic_check_bigjoiner(state, crtc, old_crtc_state,
9932 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9933 new_crtc_state, i) {
9934 if (!intel_crtc_needs_modeset(new_crtc_state))
9937 ret = intel_modeset_pipe_config_late(new_crtc_state);
9941 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
9945 * Check if fastset is allowed by external dependencies like other
9946 * pipes and transcoders.
9948 * Right now it only forces a fullmodeset when the MST master
9949 * transcoder did not changed but the pipe of the master transcoder
9950 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
9951 * in case of port synced crtcs, if one of the synced crtcs
9952 * needs a full modeset, all other synced crtcs should be
9953 * forced a full modeset.
9955 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
9956 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
9959 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
9960 enum transcoder master = new_crtc_state->mst_master_transcoder;
9962 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
9963 new_crtc_state->uapi.mode_changed = true;
9964 new_crtc_state->update_pipe = false;
9968 if (is_trans_port_sync_mode(new_crtc_state)) {
9969 u8 trans = new_crtc_state->sync_mode_slaves_mask;
9971 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
9972 trans |= BIT(new_crtc_state->master_transcoder);
9974 if (intel_cpu_transcoders_need_modeset(state, trans)) {
9975 new_crtc_state->uapi.mode_changed = true;
9976 new_crtc_state->update_pipe = false;
9980 if (new_crtc_state->bigjoiner) {
9981 struct intel_crtc_state *linked_crtc_state =
9982 intel_atomic_get_new_crtc_state(state, new_crtc_state->bigjoiner_linked_crtc);
9984 if (intel_crtc_needs_modeset(linked_crtc_state)) {
9985 new_crtc_state->uapi.mode_changed = true;
9986 new_crtc_state->update_pipe = false;
9991 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
9992 new_crtc_state, i) {
9993 if (intel_crtc_needs_modeset(new_crtc_state)) {
9998 if (!new_crtc_state->update_pipe)
10001 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
10004 if (any_ms && !check_digital_port_conflicts(state)) {
10005 drm_dbg_kms(&dev_priv->drm,
10006 "rejecting conflicting digital port configuration\n");
10011 ret = drm_dp_mst_atomic_check(&state->base);
10015 ret = intel_atomic_check_planes(state);
10019 intel_fbc_choose_crtc(dev_priv, state);
10020 ret = calc_watermark_data(state);
10024 ret = intel_bw_atomic_check(state);
10028 ret = intel_atomic_check_cdclk(state, &any_ms);
10032 if (intel_any_crtc_needs_modeset(state))
10036 ret = intel_modeset_checks(state);
10040 ret = intel_modeset_calc_cdclk(state);
10044 intel_modeset_clear_plls(state);
10047 ret = intel_atomic_check_crtcs(state);
10051 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10052 new_crtc_state, i) {
10053 if (new_crtc_state->uapi.async_flip) {
10054 ret = intel_atomic_check_async(state);
10059 if (!intel_crtc_needs_modeset(new_crtc_state) &&
10060 !new_crtc_state->update_pipe)
10063 intel_dump_pipe_config(new_crtc_state, state,
10064 intel_crtc_needs_modeset(new_crtc_state) ?
10065 "[modeset]" : "[fastset]");
10071 if (ret == -EDEADLK)
10075 * FIXME would probably be nice to know which crtc specifically
10076 * caused the failure, in cases where we can pinpoint it.
10078 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10080 intel_dump_pipe_config(new_crtc_state, state, "[failed]");
10085 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
10087 struct intel_crtc_state *crtc_state;
10088 struct intel_crtc *crtc;
10091 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
10095 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
10096 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
10098 if (mode_changed || crtc_state->update_pipe ||
10099 crtc_state->uapi.color_mgmt_changed) {
10100 intel_dsb_prepare(crtc_state);
10107 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
10108 struct intel_crtc_state *crtc_state)
10110 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10112 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
10113 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
10115 if (crtc_state->has_pch_encoder) {
10116 enum pipe pch_transcoder =
10117 intel_crtc_pch_transcoder(crtc);
10119 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
10123 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
10124 const struct intel_crtc_state *new_crtc_state)
10126 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
10127 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10130 * Update pipe size and adjust fitter if needed: the reason for this is
10131 * that in compute_mode_changes we check the native mode (not the pfit
10132 * mode) to see if we can flip rather than do a full mode set. In the
10133 * fastboot case, we'll flip, but if we don't update the pipesrc and
10134 * pfit state, we'll end up with a big fb scanned out into the wrong
10137 intel_set_pipe_src_size(new_crtc_state);
10139 /* on skylake this is done by detaching scalers */
10140 if (DISPLAY_VER(dev_priv) >= 9) {
10141 if (new_crtc_state->pch_pfit.enabled)
10142 skl_pfit_enable(new_crtc_state);
10143 } else if (HAS_PCH_SPLIT(dev_priv)) {
10144 if (new_crtc_state->pch_pfit.enabled)
10145 ilk_pfit_enable(new_crtc_state);
10146 else if (old_crtc_state->pch_pfit.enabled)
10147 ilk_pfit_disable(old_crtc_state);
10151 * The register is supposedly single buffered so perhaps
10152 * not 100% correct to do this here. But SKL+ calculate
10153 * this based on the adjust pixel rate so pfit changes do
10154 * affect it and so it must be updated for fastsets.
10155 * HSW/BDW only really need this here for fastboot, after
10156 * that the value should not change without a full modeset.
10158 if (DISPLAY_VER(dev_priv) >= 9 ||
10159 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
10160 hsw_set_linetime_wm(new_crtc_state);
10162 if (DISPLAY_VER(dev_priv) >= 11)
10163 icl_set_pipe_chicken(crtc);
10166 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
10167 struct intel_crtc *crtc)
10169 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10170 const struct intel_crtc_state *old_crtc_state =
10171 intel_atomic_get_old_crtc_state(state, crtc);
10172 const struct intel_crtc_state *new_crtc_state =
10173 intel_atomic_get_new_crtc_state(state, crtc);
10174 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
10177 * During modesets pipe configuration was programmed as the
10178 * CRTC was enabled.
10181 if (new_crtc_state->uapi.color_mgmt_changed ||
10182 new_crtc_state->update_pipe)
10183 intel_color_commit(new_crtc_state);
10185 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
10186 bdw_set_pipemisc(new_crtc_state);
10188 if (new_crtc_state->update_pipe)
10189 intel_pipe_fastset(old_crtc_state, new_crtc_state);
10191 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
10194 if (dev_priv->display.atomic_update_watermarks)
10195 dev_priv->display.atomic_update_watermarks(state, crtc);
10198 static void commit_pipe_post_planes(struct intel_atomic_state *state,
10199 struct intel_crtc *crtc)
10201 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10202 const struct intel_crtc_state *new_crtc_state =
10203 intel_atomic_get_new_crtc_state(state, crtc);
10206 * Disable the scaler(s) after the plane(s) so that we don't
10207 * get a catastrophic underrun even if the two operations
10208 * end up happening in two different frames.
10210 if (DISPLAY_VER(dev_priv) >= 9 &&
10211 !intel_crtc_needs_modeset(new_crtc_state))
10212 skl_detach_scalers(new_crtc_state);
10215 static void intel_enable_crtc(struct intel_atomic_state *state,
10216 struct intel_crtc *crtc)
10218 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10219 const struct intel_crtc_state *new_crtc_state =
10220 intel_atomic_get_new_crtc_state(state, crtc);
10222 if (!intel_crtc_needs_modeset(new_crtc_state))
10225 intel_crtc_update_active_timings(new_crtc_state);
10227 dev_priv->display.crtc_enable(state, crtc);
10229 if (new_crtc_state->bigjoiner_slave)
10232 /* vblanks work again, re-enable pipe CRC. */
10233 intel_crtc_enable_pipe_crc(crtc);
10236 static void intel_update_crtc(struct intel_atomic_state *state,
10237 struct intel_crtc *crtc)
10239 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10240 const struct intel_crtc_state *old_crtc_state =
10241 intel_atomic_get_old_crtc_state(state, crtc);
10242 struct intel_crtc_state *new_crtc_state =
10243 intel_atomic_get_new_crtc_state(state, crtc);
10244 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
10247 if (new_crtc_state->preload_luts &&
10248 (new_crtc_state->uapi.color_mgmt_changed ||
10249 new_crtc_state->update_pipe))
10250 intel_color_load_luts(new_crtc_state);
10252 intel_pre_plane_update(state, crtc);
10254 if (new_crtc_state->update_pipe)
10255 intel_encoders_update_pipe(state, crtc);
10258 if (new_crtc_state->update_pipe && !new_crtc_state->enable_fbc)
10259 intel_fbc_disable(crtc);
10261 intel_fbc_enable(state, crtc);
10263 /* Perform vblank evasion around commit operation */
10264 intel_pipe_update_start(new_crtc_state);
10266 commit_pipe_pre_planes(state, crtc);
10268 if (DISPLAY_VER(dev_priv) >= 9)
10269 skl_update_planes_on_crtc(state, crtc);
10271 i9xx_update_planes_on_crtc(state, crtc);
10273 commit_pipe_post_planes(state, crtc);
10275 intel_pipe_update_end(new_crtc_state);
10278 * We usually enable FIFO underrun interrupts as part of the
10279 * CRTC enable sequence during modesets. But when we inherit a
10280 * valid pipe configuration from the BIOS we need to take care
10281 * of enabling them on the CRTC's first fastset.
10283 if (new_crtc_state->update_pipe && !modeset &&
10284 old_crtc_state->inherited)
10285 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
10288 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
10289 struct intel_crtc_state *old_crtc_state,
10290 struct intel_crtc_state *new_crtc_state,
10291 struct intel_crtc *crtc)
10293 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10295 drm_WARN_ON(&dev_priv->drm, old_crtc_state->bigjoiner_slave);
10297 intel_crtc_disable_planes(state, crtc);
10300 * We still need special handling for disabling bigjoiner master
10301 * and slaves since for slave we do not have encoder or plls
10302 * so we dont need to disable those.
10304 if (old_crtc_state->bigjoiner) {
10305 intel_crtc_disable_planes(state,
10306 old_crtc_state->bigjoiner_linked_crtc);
10307 old_crtc_state->bigjoiner_linked_crtc->active = false;
10311 * We need to disable pipe CRC before disabling the pipe,
10312 * or we race against vblank off.
10314 intel_crtc_disable_pipe_crc(crtc);
10316 dev_priv->display.crtc_disable(state, crtc);
10317 crtc->active = false;
10318 intel_fbc_disable(crtc);
10319 intel_disable_shared_dpll(old_crtc_state);
10321 /* FIXME unify this for all platforms */
10322 if (!new_crtc_state->hw.active &&
10323 !HAS_GMCH(dev_priv) &&
10324 dev_priv->display.initial_watermarks)
10325 dev_priv->display.initial_watermarks(state, crtc);
10328 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
10330 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
10331 struct intel_crtc *crtc;
10335 /* Only disable port sync and MST slaves */
10336 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10337 new_crtc_state, i) {
10338 if (!intel_crtc_needs_modeset(new_crtc_state) || old_crtc_state->bigjoiner)
10341 if (!old_crtc_state->hw.active)
10344 /* In case of Transcoder port Sync master slave CRTCs can be
10345 * assigned in any order and we need to make sure that
10346 * slave CRTCs are disabled first and then master CRTC since
10347 * Slave vblanks are masked till Master Vblanks.
10349 if (!is_trans_port_sync_slave(old_crtc_state) &&
10350 !intel_dp_mst_is_slave_trans(old_crtc_state))
10353 intel_pre_plane_update(state, crtc);
10354 intel_old_crtc_state_disables(state, old_crtc_state,
10355 new_crtc_state, crtc);
10356 handled |= BIT(crtc->pipe);
10359 /* Disable everything else left on */
10360 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10361 new_crtc_state, i) {
10362 if (!intel_crtc_needs_modeset(new_crtc_state) ||
10363 (handled & BIT(crtc->pipe)) ||
10364 old_crtc_state->bigjoiner_slave)
10367 intel_pre_plane_update(state, crtc);
10368 if (old_crtc_state->bigjoiner) {
10369 struct intel_crtc *slave =
10370 old_crtc_state->bigjoiner_linked_crtc;
10372 intel_pre_plane_update(state, slave);
10375 if (old_crtc_state->hw.active)
10376 intel_old_crtc_state_disables(state, old_crtc_state,
10377 new_crtc_state, crtc);
10381 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
10383 struct intel_crtc_state *new_crtc_state;
10384 struct intel_crtc *crtc;
10387 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10388 if (!new_crtc_state->hw.active)
10391 intel_enable_crtc(state, crtc);
10392 intel_update_crtc(state, crtc);
10396 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
10398 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
10399 struct intel_crtc *crtc;
10400 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
10401 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
10402 u8 update_pipes = 0, modeset_pipes = 0;
10405 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10406 enum pipe pipe = crtc->pipe;
10408 if (!new_crtc_state->hw.active)
10411 /* ignore allocations for crtc's that have been turned off. */
10412 if (!intel_crtc_needs_modeset(new_crtc_state)) {
10413 entries[pipe] = old_crtc_state->wm.skl.ddb;
10414 update_pipes |= BIT(pipe);
10416 modeset_pipes |= BIT(pipe);
10421 * Whenever the number of active pipes changes, we need to make sure we
10422 * update the pipes in the right order so that their ddb allocations
10423 * never overlap with each other between CRTC updates. Otherwise we'll
10424 * cause pipe underruns and other bad stuff.
10426 * So first lets enable all pipes that do not need a fullmodeset as
10427 * those don't have any external dependency.
10429 while (update_pipes) {
10430 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10431 new_crtc_state, i) {
10432 enum pipe pipe = crtc->pipe;
10434 if ((update_pipes & BIT(pipe)) == 0)
10437 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
10438 entries, I915_MAX_PIPES, pipe))
10441 entries[pipe] = new_crtc_state->wm.skl.ddb;
10442 update_pipes &= ~BIT(pipe);
10444 intel_update_crtc(state, crtc);
10447 * If this is an already active pipe, it's DDB changed,
10448 * and this isn't the last pipe that needs updating
10449 * then we need to wait for a vblank to pass for the
10450 * new ddb allocation to take effect.
10452 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
10453 &old_crtc_state->wm.skl.ddb) &&
10454 (update_pipes | modeset_pipes))
10455 intel_wait_for_vblank(dev_priv, pipe);
10459 update_pipes = modeset_pipes;
10462 * Enable all pipes that needs a modeset and do not depends on other
10465 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10466 enum pipe pipe = crtc->pipe;
10468 if ((modeset_pipes & BIT(pipe)) == 0)
10471 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
10472 is_trans_port_sync_master(new_crtc_state) ||
10473 (new_crtc_state->bigjoiner && !new_crtc_state->bigjoiner_slave))
10476 modeset_pipes &= ~BIT(pipe);
10478 intel_enable_crtc(state, crtc);
10482 * Then we enable all remaining pipes that depend on other
10483 * pipes: MST slaves and port sync masters, big joiner master
10485 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10486 enum pipe pipe = crtc->pipe;
10488 if ((modeset_pipes & BIT(pipe)) == 0)
10491 modeset_pipes &= ~BIT(pipe);
10493 intel_enable_crtc(state, crtc);
10497 * Finally we do the plane updates/etc. for all pipes that got enabled.
10499 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10500 enum pipe pipe = crtc->pipe;
10502 if ((update_pipes & BIT(pipe)) == 0)
10505 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
10506 entries, I915_MAX_PIPES, pipe));
10508 entries[pipe] = new_crtc_state->wm.skl.ddb;
10509 update_pipes &= ~BIT(pipe);
10511 intel_update_crtc(state, crtc);
10514 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
10515 drm_WARN_ON(&dev_priv->drm, update_pipes);
10518 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
10520 struct intel_atomic_state *state, *next;
10521 struct llist_node *freed;
10523 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
10524 llist_for_each_entry_safe(state, next, freed, freed)
10525 drm_atomic_state_put(&state->base);
10528 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
10530 struct drm_i915_private *dev_priv =
10531 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
10533 intel_atomic_helper_free_state(dev_priv);
10536 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
10538 struct wait_queue_entry wait_fence, wait_reset;
10539 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
10541 init_wait_entry(&wait_fence, 0);
10542 init_wait_entry(&wait_reset, 0);
10544 prepare_to_wait(&intel_state->commit_ready.wait,
10545 &wait_fence, TASK_UNINTERRUPTIBLE);
10546 prepare_to_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
10547 I915_RESET_MODESET),
10548 &wait_reset, TASK_UNINTERRUPTIBLE);
10551 if (i915_sw_fence_done(&intel_state->commit_ready) ||
10552 test_bit(I915_RESET_MODESET, &dev_priv->gt.reset.flags))
10557 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
10558 finish_wait(bit_waitqueue(&dev_priv->gt.reset.flags,
10559 I915_RESET_MODESET),
10563 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
10565 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
10566 struct intel_crtc *crtc;
10569 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10571 intel_dsb_cleanup(old_crtc_state);
10574 static void intel_atomic_cleanup_work(struct work_struct *work)
10576 struct intel_atomic_state *state =
10577 container_of(work, struct intel_atomic_state, base.commit_work);
10578 struct drm_i915_private *i915 = to_i915(state->base.dev);
10580 intel_cleanup_dsbs(state);
10581 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
10582 drm_atomic_helper_commit_cleanup_done(&state->base);
10583 drm_atomic_state_put(&state->base);
10585 intel_atomic_helper_free_state(i915);
10588 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
10590 struct drm_i915_private *i915 = to_i915(state->base.dev);
10591 struct intel_plane *plane;
10592 struct intel_plane_state *plane_state;
10595 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10596 struct drm_framebuffer *fb = plane_state->hw.fb;
10600 fb->modifier != I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC)
10604 * The layout of the fast clear color value expected by HW
10605 * (the DRM ABI requiring this value to be located in fb at offset 0 of plane#2):
10606 * - 4 x 4 bytes per-channel value
10607 * (in surface type specific float/int format provided by the fb user)
10608 * - 8 bytes native color value used by the display
10609 * (converted/written by GPU during a fast clear operation using the
10610 * above per-channel values)
10612 * The commit's FB prepare hook already ensured that FB obj is pinned and the
10613 * caller made sure that the object is synced wrt. the related color clear value
10616 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
10617 fb->offsets[2] + 16,
10618 &plane_state->ccval,
10619 sizeof(plane_state->ccval));
10620 /* The above could only fail if the FB obj has an unexpected backing store type. */
10621 drm_WARN_ON(&i915->drm, ret);
10625 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
10627 struct drm_device *dev = state->base.dev;
10628 struct drm_i915_private *dev_priv = to_i915(dev);
10629 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
10630 struct intel_crtc *crtc;
10631 u64 put_domains[I915_MAX_PIPES] = {};
10632 intel_wakeref_t wakeref = 0;
10635 intel_atomic_commit_fence_wait(state);
10637 drm_atomic_helper_wait_for_dependencies(&state->base);
10639 if (state->modeset)
10640 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
10642 intel_atomic_prepare_plane_clear_colors(state);
10644 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10645 new_crtc_state, i) {
10646 if (intel_crtc_needs_modeset(new_crtc_state) ||
10647 new_crtc_state->update_pipe) {
10649 put_domains[crtc->pipe] =
10650 modeset_get_crtc_power_domains(new_crtc_state);
10654 intel_commit_modeset_disables(state);
10656 /* FIXME: Eventually get rid of our crtc->config pointer */
10657 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10658 crtc->config = new_crtc_state;
10660 if (state->modeset) {
10661 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
10663 intel_set_cdclk_pre_plane_update(state);
10665 intel_modeset_verify_disabled(dev_priv, state);
10668 intel_sagv_pre_plane_update(state);
10670 /* Complete the events for pipes that have now been disabled */
10671 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10672 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
10674 /* Complete events for now disable pipes here. */
10675 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
10676 spin_lock_irq(&dev->event_lock);
10677 drm_crtc_send_vblank_event(&crtc->base,
10678 new_crtc_state->uapi.event);
10679 spin_unlock_irq(&dev->event_lock);
10681 new_crtc_state->uapi.event = NULL;
10685 if (state->modeset)
10686 intel_encoders_update_prepare(state);
10688 intel_dbuf_pre_plane_update(state);
10690 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10691 if (new_crtc_state->uapi.async_flip)
10692 intel_crtc_enable_flip_done(state, crtc);
10695 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
10696 dev_priv->display.commit_modeset_enables(state);
10698 if (state->modeset) {
10699 intel_encoders_update_complete(state);
10701 intel_set_cdclk_post_plane_update(state);
10704 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
10705 * already, but still need the state for the delayed optimization. To
10707 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
10708 * - schedule that vblank worker _before_ calling hw_done
10709 * - at the start of commit_tail, cancel it _synchrously
10710 * - switch over to the vblank wait helper in the core after that since
10711 * we don't need out special handling any more.
10713 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
10715 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
10716 if (new_crtc_state->uapi.async_flip)
10717 intel_crtc_disable_flip_done(state, crtc);
10719 if (new_crtc_state->hw.active &&
10720 !intel_crtc_needs_modeset(new_crtc_state) &&
10721 !new_crtc_state->preload_luts &&
10722 (new_crtc_state->uapi.color_mgmt_changed ||
10723 new_crtc_state->update_pipe))
10724 intel_color_load_luts(new_crtc_state);
10728 * Now that the vblank has passed, we can go ahead and program the
10729 * optimal watermarks on platforms that need two-step watermark
10732 * TODO: Move this (and other cleanup) to an async worker eventually.
10734 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
10735 new_crtc_state, i) {
10737 * Gen2 reports pipe underruns whenever all planes are disabled.
10738 * So re-enable underrun reporting after some planes get enabled.
10740 * We do this before .optimize_watermarks() so that we have a
10741 * chance of catching underruns with the intermediate watermarks
10742 * vs. the new plane configuration.
10744 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
10745 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
10747 if (dev_priv->display.optimize_watermarks)
10748 dev_priv->display.optimize_watermarks(state, crtc);
10751 intel_dbuf_post_plane_update(state);
10753 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
10754 intel_post_plane_update(state, crtc);
10756 modeset_put_crtc_power_domains(crtc, put_domains[crtc->pipe]);
10758 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
10761 * DSB cleanup is done in cleanup_work aligning with framebuffer
10762 * cleanup. So copy and reset the dsb structure to sync with
10763 * commit_done and later do dsb cleanup in cleanup_work.
10765 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
10768 /* Underruns don't always raise interrupts, so check manually */
10769 intel_check_cpu_fifo_underruns(dev_priv);
10770 intel_check_pch_fifo_underruns(dev_priv);
10772 if (state->modeset)
10773 intel_verify_planes(state);
10775 intel_sagv_post_plane_update(state);
10777 drm_atomic_helper_commit_hw_done(&state->base);
10779 if (state->modeset) {
10780 /* As one of the primary mmio accessors, KMS has a high
10781 * likelihood of triggering bugs in unclaimed access. After we
10782 * finish modesetting, see if an error has been flagged, and if
10783 * so enable debugging for the next modeset - and hope we catch
10786 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
10787 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
10789 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10792 * Defer the cleanup of the old state to a separate worker to not
10793 * impede the current task (userspace for blocking modesets) that
10794 * are executed inline. For out-of-line asynchronous modesets/flips,
10795 * deferring to a new worker seems overkill, but we would place a
10796 * schedule point (cond_resched()) here anyway to keep latencies
10799 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
10800 queue_work(system_highpri_wq, &state->base.commit_work);
10803 static void intel_atomic_commit_work(struct work_struct *work)
10805 struct intel_atomic_state *state =
10806 container_of(work, struct intel_atomic_state, base.commit_work);
10808 intel_atomic_commit_tail(state);
10811 static int __i915_sw_fence_call
10812 intel_atomic_commit_ready(struct i915_sw_fence *fence,
10813 enum i915_sw_fence_notify notify)
10815 struct intel_atomic_state *state =
10816 container_of(fence, struct intel_atomic_state, commit_ready);
10819 case FENCE_COMPLETE:
10820 /* we do blocking waits in the worker, nothing to do here */
10824 struct intel_atomic_helper *helper =
10825 &to_i915(state->base.dev)->atomic_helper;
10827 if (llist_add(&state->freed, &helper->free_list))
10828 schedule_work(&helper->free_work);
10833 return NOTIFY_DONE;
10836 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
10838 struct intel_plane_state *old_plane_state, *new_plane_state;
10839 struct intel_plane *plane;
10842 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
10843 new_plane_state, i)
10844 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
10845 to_intel_frontbuffer(new_plane_state->hw.fb),
10846 plane->frontbuffer_bit);
10849 static int intel_atomic_commit(struct drm_device *dev,
10850 struct drm_atomic_state *_state,
10853 struct intel_atomic_state *state = to_intel_atomic_state(_state);
10854 struct drm_i915_private *dev_priv = to_i915(dev);
10857 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
10859 drm_atomic_state_get(&state->base);
10860 i915_sw_fence_init(&state->commit_ready,
10861 intel_atomic_commit_ready);
10864 * The intel_legacy_cursor_update() fast path takes care
10865 * of avoiding the vblank waits for simple cursor
10866 * movement and flips. For cursor on/off and size changes,
10867 * we want to perform the vblank waits so that watermark
10868 * updates happen during the correct frames. Gen9+ have
10869 * double buffered watermarks and so shouldn't need this.
10871 * Unset state->legacy_cursor_update before the call to
10872 * drm_atomic_helper_setup_commit() because otherwise
10873 * drm_atomic_helper_wait_for_flip_done() is a noop and
10874 * we get FIFO underruns because we didn't wait
10877 * FIXME doing watermarks and fb cleanup from a vblank worker
10878 * (assuming we had any) would solve these problems.
10880 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
10881 struct intel_crtc_state *new_crtc_state;
10882 struct intel_crtc *crtc;
10885 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10886 if (new_crtc_state->wm.need_postvbl_update ||
10887 new_crtc_state->update_wm_post)
10888 state->base.legacy_cursor_update = false;
10891 ret = intel_atomic_prepare_commit(state);
10893 drm_dbg_atomic(&dev_priv->drm,
10894 "Preparing state failed with %i\n", ret);
10895 i915_sw_fence_commit(&state->commit_ready);
10896 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10900 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
10902 ret = drm_atomic_helper_swap_state(&state->base, true);
10904 intel_atomic_swap_global_state(state);
10907 struct intel_crtc_state *new_crtc_state;
10908 struct intel_crtc *crtc;
10911 i915_sw_fence_commit(&state->commit_ready);
10913 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
10914 intel_dsb_cleanup(new_crtc_state);
10916 drm_atomic_helper_cleanup_planes(dev, &state->base);
10917 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
10920 intel_shared_dpll_swap_state(state);
10921 intel_atomic_track_fbs(state);
10923 drm_atomic_state_get(&state->base);
10924 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
10926 i915_sw_fence_commit(&state->commit_ready);
10927 if (nonblock && state->modeset) {
10928 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
10929 } else if (nonblock) {
10930 queue_work(dev_priv->flip_wq, &state->base.commit_work);
10932 if (state->modeset)
10933 flush_workqueue(dev_priv->modeset_wq);
10934 intel_atomic_commit_tail(state);
10940 struct wait_rps_boost {
10941 struct wait_queue_entry wait;
10943 struct drm_crtc *crtc;
10944 struct i915_request *request;
10947 static int do_rps_boost(struct wait_queue_entry *_wait,
10948 unsigned mode, int sync, void *key)
10950 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
10951 struct i915_request *rq = wait->request;
10954 * If we missed the vblank, but the request is already running it
10955 * is reasonable to assume that it will complete before the next
10956 * vblank without our intervention, so leave RPS alone.
10958 if (!i915_request_started(rq))
10959 intel_rps_boost(rq);
10960 i915_request_put(rq);
10962 drm_crtc_vblank_put(wait->crtc);
10964 list_del(&wait->wait.entry);
10969 static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
10970 struct dma_fence *fence)
10972 struct wait_rps_boost *wait;
10974 if (!dma_fence_is_i915(fence))
10977 if (DISPLAY_VER(to_i915(crtc->dev)) < 6)
10980 if (drm_crtc_vblank_get(crtc))
10983 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
10985 drm_crtc_vblank_put(crtc);
10989 wait->request = to_request(dma_fence_get(fence));
10992 wait->wait.func = do_rps_boost;
10993 wait->wait.flags = 0;
10995 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
10998 int intel_plane_pin_fb(struct intel_plane_state *plane_state)
11000 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
11001 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11002 struct drm_framebuffer *fb = plane_state->hw.fb;
11003 struct i915_vma *vma;
11005 plane->id == PLANE_CURSOR &&
11006 INTEL_INFO(dev_priv)->display.cursor_needs_physical;
11008 if (!intel_fb_uses_dpt(fb)) {
11009 vma = intel_pin_and_fence_fb_obj(fb, phys_cursor,
11010 &plane_state->view.gtt,
11011 intel_plane_uses_fence(plane_state),
11012 &plane_state->flags);
11014 return PTR_ERR(vma);
11016 plane_state->ggtt_vma = vma;
11018 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
11020 vma = intel_dpt_pin(intel_fb->dpt_vm);
11022 return PTR_ERR(vma);
11024 plane_state->ggtt_vma = vma;
11026 vma = intel_pin_fb_obj_dpt(fb, &plane_state->view.gtt, false,
11027 &plane_state->flags, intel_fb->dpt_vm);
11029 intel_dpt_unpin(intel_fb->dpt_vm);
11030 plane_state->ggtt_vma = NULL;
11031 return PTR_ERR(vma);
11034 plane_state->dpt_vma = vma;
11036 WARN_ON(plane_state->ggtt_vma == plane_state->dpt_vma);
11042 void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
11044 struct drm_framebuffer *fb = old_plane_state->hw.fb;
11045 struct i915_vma *vma;
11047 if (!intel_fb_uses_dpt(fb)) {
11048 vma = fetch_and_zero(&old_plane_state->ggtt_vma);
11050 intel_unpin_fb_vma(vma, old_plane_state->flags);
11052 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
11054 vma = fetch_and_zero(&old_plane_state->dpt_vma);
11056 intel_unpin_fb_vma(vma, old_plane_state->flags);
11058 vma = fetch_and_zero(&old_plane_state->ggtt_vma);
11060 intel_dpt_unpin(intel_fb->dpt_vm);
11065 * intel_prepare_plane_fb - Prepare fb for usage on plane
11066 * @_plane: drm plane to prepare for
11067 * @_new_plane_state: the plane state being prepared
11069 * Prepares a framebuffer for usage on a display plane. Generally this
11070 * involves pinning the underlying object and updating the frontbuffer tracking
11071 * bits. Some older platforms need special physical address handling for
11074 * Returns 0 on success, negative error code on failure.
11077 intel_prepare_plane_fb(struct drm_plane *_plane,
11078 struct drm_plane_state *_new_plane_state)
11080 struct i915_sched_attr attr = { .priority = I915_PRIORITY_DISPLAY };
11081 struct intel_plane *plane = to_intel_plane(_plane);
11082 struct intel_plane_state *new_plane_state =
11083 to_intel_plane_state(_new_plane_state);
11084 struct intel_atomic_state *state =
11085 to_intel_atomic_state(new_plane_state->uapi.state);
11086 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
11087 const struct intel_plane_state *old_plane_state =
11088 intel_atomic_get_old_plane_state(state, plane);
11089 struct drm_i915_gem_object *obj = intel_fb_obj(new_plane_state->hw.fb);
11090 struct drm_i915_gem_object *old_obj = intel_fb_obj(old_plane_state->hw.fb);
11094 const struct intel_crtc_state *crtc_state =
11095 intel_atomic_get_new_crtc_state(state,
11096 to_intel_crtc(old_plane_state->hw.crtc));
11098 /* Big Hammer, we also need to ensure that any pending
11099 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
11100 * current scanout is retired before unpinning the old
11101 * framebuffer. Note that we rely on userspace rendering
11102 * into the buffer attached to the pipe they are waiting
11103 * on. If not, userspace generates a GPU hang with IPEHR
11104 * point to the MI_WAIT_FOR_EVENT.
11106 * This should only fail upon a hung GPU, in which case we
11107 * can safely continue.
11109 if (intel_crtc_needs_modeset(crtc_state)) {
11110 ret = i915_sw_fence_await_reservation(&state->commit_ready,
11111 old_obj->base.resv, NULL,
11119 if (new_plane_state->uapi.fence) { /* explicit fencing */
11120 i915_gem_fence_wait_priority(new_plane_state->uapi.fence,
11122 ret = i915_sw_fence_await_dma_fence(&state->commit_ready,
11123 new_plane_state->uapi.fence,
11124 i915_fence_timeout(dev_priv),
11134 ret = intel_plane_pin_fb(new_plane_state);
11138 i915_gem_object_wait_priority(obj, 0, &attr);
11139 i915_gem_object_flush_frontbuffer(obj, ORIGIN_DIRTYFB);
11141 if (!new_plane_state->uapi.fence) { /* implicit fencing */
11142 struct dma_fence *fence;
11144 ret = i915_sw_fence_await_reservation(&state->commit_ready,
11145 obj->base.resv, NULL,
11147 i915_fence_timeout(dev_priv),
11152 fence = dma_resv_get_excl_unlocked(obj->base.resv);
11154 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
11156 dma_fence_put(fence);
11159 add_rps_boost_after_vblank(new_plane_state->hw.crtc,
11160 new_plane_state->uapi.fence);
11164 * We declare pageflips to be interactive and so merit a small bias
11165 * towards upclocking to deliver the frame on time. By only changing
11166 * the RPS thresholds to sample more regularly and aim for higher
11167 * clocks we can hopefully deliver low power workloads (like kodi)
11168 * that are not quite steady state without resorting to forcing
11169 * maximum clocks following a vblank miss (see do_rps_boost()).
11171 if (!state->rps_interactive) {
11172 intel_rps_mark_interactive(&dev_priv->gt.rps, true);
11173 state->rps_interactive = true;
11179 intel_plane_unpin_fb(new_plane_state);
11185 * intel_cleanup_plane_fb - Cleans up an fb after plane use
11186 * @plane: drm plane to clean up for
11187 * @_old_plane_state: the state from the previous modeset
11189 * Cleans up a framebuffer that has just been removed from a plane.
11192 intel_cleanup_plane_fb(struct drm_plane *plane,
11193 struct drm_plane_state *_old_plane_state)
11195 struct intel_plane_state *old_plane_state =
11196 to_intel_plane_state(_old_plane_state);
11197 struct intel_atomic_state *state =
11198 to_intel_atomic_state(old_plane_state->uapi.state);
11199 struct drm_i915_private *dev_priv = to_i915(plane->dev);
11200 struct drm_i915_gem_object *obj = intel_fb_obj(old_plane_state->hw.fb);
11205 if (state->rps_interactive) {
11206 intel_rps_mark_interactive(&dev_priv->gt.rps, false);
11207 state->rps_interactive = false;
11210 /* Should only be called after a successful intel_prepare_plane_fb()! */
11211 intel_plane_unpin_fb(old_plane_state);
11215 * intel_plane_destroy - destroy a plane
11216 * @plane: plane to destroy
11218 * Common destruction function for all types of planes (primary, cursor,
11221 void intel_plane_destroy(struct drm_plane *plane)
11223 drm_plane_cleanup(plane);
11224 kfree(to_intel_plane(plane));
11227 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
11229 struct intel_plane *plane;
11231 for_each_intel_plane(&dev_priv->drm, plane) {
11232 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv,
11235 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
11240 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
11241 struct drm_file *file)
11243 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
11244 struct drm_crtc *drmmode_crtc;
11245 struct intel_crtc *crtc;
11247 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
11251 crtc = to_intel_crtc(drmmode_crtc);
11252 pipe_from_crtc_id->pipe = crtc->pipe;
11257 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
11259 struct drm_device *dev = encoder->base.dev;
11260 struct intel_encoder *source_encoder;
11261 u32 possible_clones = 0;
11263 for_each_intel_encoder(dev, source_encoder) {
11264 if (encoders_cloneable(encoder, source_encoder))
11265 possible_clones |= drm_encoder_mask(&source_encoder->base);
11268 return possible_clones;
11271 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
11273 struct drm_device *dev = encoder->base.dev;
11274 struct intel_crtc *crtc;
11275 u32 possible_crtcs = 0;
11277 for_each_intel_crtc(dev, crtc) {
11278 if (encoder->pipe_mask & BIT(crtc->pipe))
11279 possible_crtcs |= drm_crtc_mask(&crtc->base);
11282 return possible_crtcs;
11285 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
11287 if (!IS_MOBILE(dev_priv))
11290 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
11293 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
11299 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
11301 if (DISPLAY_VER(dev_priv) >= 9)
11304 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
11307 if (HAS_PCH_LPT_H(dev_priv) &&
11308 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
11311 /* DDI E can't be used if DDI A requires 4 lanes */
11312 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
11315 if (!dev_priv->vbt.int_crt_support)
11321 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
11323 struct intel_encoder *encoder;
11324 bool dpd_is_edp = false;
11326 intel_pps_unlock_regs_wa(dev_priv);
11328 if (!HAS_DISPLAY(dev_priv))
11331 if (IS_ALDERLAKE_P(dev_priv)) {
11332 intel_ddi_init(dev_priv, PORT_A);
11333 intel_ddi_init(dev_priv, PORT_B);
11334 intel_ddi_init(dev_priv, PORT_TC1);
11335 intel_ddi_init(dev_priv, PORT_TC2);
11336 intel_ddi_init(dev_priv, PORT_TC3);
11337 intel_ddi_init(dev_priv, PORT_TC4);
11338 } else if (IS_ALDERLAKE_S(dev_priv)) {
11339 intel_ddi_init(dev_priv, PORT_A);
11340 intel_ddi_init(dev_priv, PORT_TC1);
11341 intel_ddi_init(dev_priv, PORT_TC2);
11342 intel_ddi_init(dev_priv, PORT_TC3);
11343 intel_ddi_init(dev_priv, PORT_TC4);
11344 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
11345 intel_ddi_init(dev_priv, PORT_A);
11346 intel_ddi_init(dev_priv, PORT_B);
11347 intel_ddi_init(dev_priv, PORT_TC1);
11348 intel_ddi_init(dev_priv, PORT_TC2);
11349 } else if (DISPLAY_VER(dev_priv) >= 12) {
11350 intel_ddi_init(dev_priv, PORT_A);
11351 intel_ddi_init(dev_priv, PORT_B);
11352 intel_ddi_init(dev_priv, PORT_TC1);
11353 intel_ddi_init(dev_priv, PORT_TC2);
11354 intel_ddi_init(dev_priv, PORT_TC3);
11355 intel_ddi_init(dev_priv, PORT_TC4);
11356 intel_ddi_init(dev_priv, PORT_TC5);
11357 intel_ddi_init(dev_priv, PORT_TC6);
11358 icl_dsi_init(dev_priv);
11359 } else if (IS_JSL_EHL(dev_priv)) {
11360 intel_ddi_init(dev_priv, PORT_A);
11361 intel_ddi_init(dev_priv, PORT_B);
11362 intel_ddi_init(dev_priv, PORT_C);
11363 intel_ddi_init(dev_priv, PORT_D);
11364 icl_dsi_init(dev_priv);
11365 } else if (DISPLAY_VER(dev_priv) == 11) {
11366 intel_ddi_init(dev_priv, PORT_A);
11367 intel_ddi_init(dev_priv, PORT_B);
11368 intel_ddi_init(dev_priv, PORT_C);
11369 intel_ddi_init(dev_priv, PORT_D);
11370 intel_ddi_init(dev_priv, PORT_E);
11371 intel_ddi_init(dev_priv, PORT_F);
11372 icl_dsi_init(dev_priv);
11373 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
11374 intel_ddi_init(dev_priv, PORT_A);
11375 intel_ddi_init(dev_priv, PORT_B);
11376 intel_ddi_init(dev_priv, PORT_C);
11377 vlv_dsi_init(dev_priv);
11378 } else if (DISPLAY_VER(dev_priv) == 10) {
11379 intel_ddi_init(dev_priv, PORT_A);
11380 intel_ddi_init(dev_priv, PORT_B);
11381 intel_ddi_init(dev_priv, PORT_C);
11382 intel_ddi_init(dev_priv, PORT_D);
11383 intel_ddi_init(dev_priv, PORT_E);
11384 intel_ddi_init(dev_priv, PORT_F);
11385 } else if (DISPLAY_VER(dev_priv) >= 9) {
11386 intel_ddi_init(dev_priv, PORT_A);
11387 intel_ddi_init(dev_priv, PORT_B);
11388 intel_ddi_init(dev_priv, PORT_C);
11389 intel_ddi_init(dev_priv, PORT_D);
11390 intel_ddi_init(dev_priv, PORT_E);
11391 } else if (HAS_DDI(dev_priv)) {
11394 if (intel_ddi_crt_present(dev_priv))
11395 intel_crt_init(dev_priv);
11397 /* Haswell uses DDI functions to detect digital outputs. */
11398 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
11400 intel_ddi_init(dev_priv, PORT_A);
11402 found = intel_de_read(dev_priv, SFUSE_STRAP);
11403 if (found & SFUSE_STRAP_DDIB_DETECTED)
11404 intel_ddi_init(dev_priv, PORT_B);
11405 if (found & SFUSE_STRAP_DDIC_DETECTED)
11406 intel_ddi_init(dev_priv, PORT_C);
11407 if (found & SFUSE_STRAP_DDID_DETECTED)
11408 intel_ddi_init(dev_priv, PORT_D);
11409 if (found & SFUSE_STRAP_DDIF_DETECTED)
11410 intel_ddi_init(dev_priv, PORT_F);
11411 } else if (HAS_PCH_SPLIT(dev_priv)) {
11415 * intel_edp_init_connector() depends on this completing first,
11416 * to prevent the registration of both eDP and LVDS and the
11417 * incorrect sharing of the PPS.
11419 intel_lvds_init(dev_priv);
11420 intel_crt_init(dev_priv);
11422 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
11424 if (ilk_has_edp_a(dev_priv))
11425 g4x_dp_init(dev_priv, DP_A, PORT_A);
11427 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
11428 /* PCH SDVOB multiplex with HDMIB */
11429 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
11431 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
11432 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
11433 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
11436 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
11437 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
11439 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
11440 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
11442 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
11443 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
11445 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
11446 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
11447 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
11448 bool has_edp, has_port;
11450 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
11451 intel_crt_init(dev_priv);
11454 * The DP_DETECTED bit is the latched state of the DDC
11455 * SDA pin at boot. However since eDP doesn't require DDC
11456 * (no way to plug in a DP->HDMI dongle) the DDC pins for
11457 * eDP ports may have been muxed to an alternate function.
11458 * Thus we can't rely on the DP_DETECTED bit alone to detect
11459 * eDP ports. Consult the VBT as well as DP_DETECTED to
11460 * detect eDP ports.
11462 * Sadly the straps seem to be missing sometimes even for HDMI
11463 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
11464 * and VBT for the presence of the port. Additionally we can't
11465 * trust the port type the VBT declares as we've seen at least
11466 * HDMI ports that the VBT claim are DP or eDP.
11468 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
11469 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
11470 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
11471 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
11472 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
11473 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
11475 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
11476 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
11477 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
11478 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
11479 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
11480 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
11482 if (IS_CHERRYVIEW(dev_priv)) {
11484 * eDP not supported on port D,
11485 * so no need to worry about it
11487 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
11488 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
11489 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
11490 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
11491 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
11494 vlv_dsi_init(dev_priv);
11495 } else if (IS_PINEVIEW(dev_priv)) {
11496 intel_lvds_init(dev_priv);
11497 intel_crt_init(dev_priv);
11498 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
11499 bool found = false;
11501 if (IS_MOBILE(dev_priv))
11502 intel_lvds_init(dev_priv);
11504 intel_crt_init(dev_priv);
11506 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
11507 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
11508 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
11509 if (!found && IS_G4X(dev_priv)) {
11510 drm_dbg_kms(&dev_priv->drm,
11511 "probing HDMI on SDVOB\n");
11512 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
11515 if (!found && IS_G4X(dev_priv))
11516 g4x_dp_init(dev_priv, DP_B, PORT_B);
11519 /* Before G4X SDVOC doesn't have its own detect register */
11521 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
11522 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
11523 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
11526 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
11528 if (IS_G4X(dev_priv)) {
11529 drm_dbg_kms(&dev_priv->drm,
11530 "probing HDMI on SDVOC\n");
11531 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
11533 if (IS_G4X(dev_priv))
11534 g4x_dp_init(dev_priv, DP_C, PORT_C);
11537 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
11538 g4x_dp_init(dev_priv, DP_D, PORT_D);
11540 if (SUPPORTS_TV(dev_priv))
11541 intel_tv_init(dev_priv);
11542 } else if (DISPLAY_VER(dev_priv) == 2) {
11543 if (IS_I85X(dev_priv))
11544 intel_lvds_init(dev_priv);
11546 intel_crt_init(dev_priv);
11547 intel_dvo_init(dev_priv);
11550 for_each_intel_encoder(&dev_priv->drm, encoder) {
11551 encoder->base.possible_crtcs =
11552 intel_encoder_possible_crtcs(encoder);
11553 encoder->base.possible_clones =
11554 intel_encoder_possible_clones(encoder);
11557 intel_init_pch_refclk(dev_priv);
11559 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
11562 static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
11564 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
11566 drm_framebuffer_cleanup(fb);
11568 if (intel_fb_uses_dpt(fb))
11569 intel_dpt_destroy(intel_fb->dpt_vm);
11571 intel_frontbuffer_put(intel_fb->frontbuffer);
11576 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
11577 struct drm_file *file,
11578 unsigned int *handle)
11580 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11581 struct drm_i915_private *i915 = to_i915(obj->base.dev);
11583 if (i915_gem_object_is_userptr(obj)) {
11584 drm_dbg(&i915->drm,
11585 "attempting to use a userptr for a framebuffer, denied\n");
11589 return drm_gem_handle_create(file, &obj->base, handle);
11592 static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
11593 struct drm_file *file,
11594 unsigned flags, unsigned color,
11595 struct drm_clip_rect *clips,
11596 unsigned num_clips)
11598 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11600 i915_gem_object_flush_if_display(obj);
11601 intel_frontbuffer_flush(to_intel_frontbuffer(fb), ORIGIN_DIRTYFB);
11606 static const struct drm_framebuffer_funcs intel_fb_funcs = {
11607 .destroy = intel_user_framebuffer_destroy,
11608 .create_handle = intel_user_framebuffer_create_handle,
11609 .dirty = intel_user_framebuffer_dirty,
11612 static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
11613 struct drm_i915_gem_object *obj,
11614 struct drm_mode_fb_cmd2 *mode_cmd)
11616 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
11617 struct drm_framebuffer *fb = &intel_fb->base;
11619 unsigned int tiling, stride;
11623 intel_fb->frontbuffer = intel_frontbuffer_get(obj);
11624 if (!intel_fb->frontbuffer)
11627 i915_gem_object_lock(obj, NULL);
11628 tiling = i915_gem_object_get_tiling(obj);
11629 stride = i915_gem_object_get_stride(obj);
11630 i915_gem_object_unlock(obj);
11632 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
11634 * If there's a fence, enforce that
11635 * the fb modifier and tiling mode match.
11637 if (tiling != I915_TILING_NONE &&
11638 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
11639 drm_dbg_kms(&dev_priv->drm,
11640 "tiling_mode doesn't match fb modifier\n");
11644 if (tiling == I915_TILING_X) {
11645 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
11646 } else if (tiling == I915_TILING_Y) {
11647 drm_dbg_kms(&dev_priv->drm,
11648 "No Y tiling for legacy addfb\n");
11653 if (!drm_any_plane_has_format(&dev_priv->drm,
11654 mode_cmd->pixel_format,
11655 mode_cmd->modifier[0])) {
11656 drm_dbg_kms(&dev_priv->drm,
11657 "unsupported pixel format %p4cc / modifier 0x%llx\n",
11658 &mode_cmd->pixel_format, mode_cmd->modifier[0]);
11663 * gen2/3 display engine uses the fence if present,
11664 * so the tiling mode must match the fb modifier exactly.
11666 if (DISPLAY_VER(dev_priv) < 4 &&
11667 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
11668 drm_dbg_kms(&dev_priv->drm,
11669 "tiling_mode must match fb modifier exactly on gen2/3\n");
11673 max_stride = intel_fb_max_stride(dev_priv, mode_cmd->pixel_format,
11674 mode_cmd->modifier[0]);
11675 if (mode_cmd->pitches[0] > max_stride) {
11676 drm_dbg_kms(&dev_priv->drm,
11677 "%s pitch (%u) must be at most %d\n",
11678 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
11679 "tiled" : "linear",
11680 mode_cmd->pitches[0], max_stride);
11685 * If there's a fence, enforce that
11686 * the fb pitch and fence stride match.
11688 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
11689 drm_dbg_kms(&dev_priv->drm,
11690 "pitch (%d) must match tiling stride (%d)\n",
11691 mode_cmd->pitches[0], stride);
11695 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
11696 if (mode_cmd->offsets[0] != 0) {
11697 drm_dbg_kms(&dev_priv->drm,
11698 "plane 0 offset (0x%08x) must be 0\n",
11699 mode_cmd->offsets[0]);
11703 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
11705 for (i = 0; i < fb->format->num_planes; i++) {
11706 u32 stride_alignment;
11708 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
11709 drm_dbg_kms(&dev_priv->drm, "bad plane %d handle\n",
11714 stride_alignment = intel_fb_stride_alignment(fb, i);
11715 if (fb->pitches[i] & (stride_alignment - 1)) {
11716 drm_dbg_kms(&dev_priv->drm,
11717 "plane %d pitch (%d) must be at least %u byte aligned\n",
11718 i, fb->pitches[i], stride_alignment);
11722 if (is_gen12_ccs_plane(fb, i) && !is_gen12_ccs_cc_plane(fb, i)) {
11723 int ccs_aux_stride = gen12_ccs_aux_stride(fb, i);
11725 if (fb->pitches[i] != ccs_aux_stride) {
11726 drm_dbg_kms(&dev_priv->drm,
11727 "ccs aux plane %d pitch (%d) must be %d\n",
11729 fb->pitches[i], ccs_aux_stride);
11734 /* TODO: Add POT stride remapping support for CCS formats as well. */
11735 if (IS_ALDERLAKE_P(dev_priv) &&
11736 mode_cmd->modifier[i] != DRM_FORMAT_MOD_LINEAR &&
11737 !intel_fb_needs_pot_stride_remap(intel_fb) &&
11738 !is_power_of_2(mode_cmd->pitches[i])) {
11739 drm_dbg_kms(&dev_priv->drm,
11740 "plane %d pitch (%d) must be power of two for tiled buffers\n",
11741 i, mode_cmd->pitches[i]);
11745 fb->obj[i] = &obj->base;
11748 ret = intel_fill_fb_info(dev_priv, intel_fb);
11752 if (intel_fb_uses_dpt(fb)) {
11753 struct i915_address_space *vm;
11755 vm = intel_dpt_create(intel_fb);
11761 intel_fb->dpt_vm = vm;
11764 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
11766 drm_err(&dev_priv->drm, "framebuffer init failed %d\n", ret);
11773 intel_frontbuffer_put(intel_fb->frontbuffer);
11777 static struct drm_framebuffer *
11778 intel_user_framebuffer_create(struct drm_device *dev,
11779 struct drm_file *filp,
11780 const struct drm_mode_fb_cmd2 *user_mode_cmd)
11782 struct drm_framebuffer *fb;
11783 struct drm_i915_gem_object *obj;
11784 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
11785 struct drm_i915_private *i915;
11787 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
11789 return ERR_PTR(-ENOENT);
11791 /* object is backed with LMEM for discrete */
11792 i915 = to_i915(obj->base.dev);
11793 if (HAS_LMEM(i915) && !i915_gem_object_is_lmem(obj)) {
11794 /* object is "remote", not in local memory */
11795 i915_gem_object_put(obj);
11796 return ERR_PTR(-EREMOTE);
11799 fb = intel_framebuffer_create(obj, &mode_cmd);
11800 i915_gem_object_put(obj);
11805 static enum drm_mode_status
11806 intel_mode_valid(struct drm_device *dev,
11807 const struct drm_display_mode *mode)
11809 struct drm_i915_private *dev_priv = to_i915(dev);
11810 int hdisplay_max, htotal_max;
11811 int vdisplay_max, vtotal_max;
11814 * Can't reject DBLSCAN here because Xorg ddxen can add piles
11815 * of DBLSCAN modes to the output's mode list when they detect
11816 * the scaling mode property on the connector. And they don't
11817 * ask the kernel to validate those modes in any way until
11818 * modeset time at which point the client gets a protocol error.
11819 * So in order to not upset those clients we silently ignore the
11820 * DBLSCAN flag on such connectors. For other connectors we will
11821 * reject modes with the DBLSCAN flag in encoder->compute_config().
11822 * And we always reject DBLSCAN modes in connector->mode_valid()
11823 * as we never want such modes on the connector's mode list.
11826 if (mode->vscan > 1)
11827 return MODE_NO_VSCAN;
11829 if (mode->flags & DRM_MODE_FLAG_HSKEW)
11830 return MODE_H_ILLEGAL;
11832 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
11833 DRM_MODE_FLAG_NCSYNC |
11834 DRM_MODE_FLAG_PCSYNC))
11837 if (mode->flags & (DRM_MODE_FLAG_BCAST |
11838 DRM_MODE_FLAG_PIXMUX |
11839 DRM_MODE_FLAG_CLKDIV2))
11842 /* Transcoder timing limits */
11843 if (DISPLAY_VER(dev_priv) >= 11) {
11844 hdisplay_max = 16384;
11845 vdisplay_max = 8192;
11846 htotal_max = 16384;
11848 } else if (DISPLAY_VER(dev_priv) >= 9 ||
11849 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
11850 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
11851 vdisplay_max = 4096;
11854 } else if (DISPLAY_VER(dev_priv) >= 3) {
11855 hdisplay_max = 4096;
11856 vdisplay_max = 4096;
11860 hdisplay_max = 2048;
11861 vdisplay_max = 2048;
11866 if (mode->hdisplay > hdisplay_max ||
11867 mode->hsync_start > htotal_max ||
11868 mode->hsync_end > htotal_max ||
11869 mode->htotal > htotal_max)
11870 return MODE_H_ILLEGAL;
11872 if (mode->vdisplay > vdisplay_max ||
11873 mode->vsync_start > vtotal_max ||
11874 mode->vsync_end > vtotal_max ||
11875 mode->vtotal > vtotal_max)
11876 return MODE_V_ILLEGAL;
11878 if (DISPLAY_VER(dev_priv) >= 5) {
11879 if (mode->hdisplay < 64 ||
11880 mode->htotal - mode->hdisplay < 32)
11881 return MODE_H_ILLEGAL;
11883 if (mode->vtotal - mode->vdisplay < 5)
11884 return MODE_V_ILLEGAL;
11886 if (mode->htotal - mode->hdisplay < 32)
11887 return MODE_H_ILLEGAL;
11889 if (mode->vtotal - mode->vdisplay < 3)
11890 return MODE_V_ILLEGAL;
11896 enum drm_mode_status
11897 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
11898 const struct drm_display_mode *mode,
11901 int plane_width_max, plane_height_max;
11904 * intel_mode_valid() should be
11905 * sufficient on older platforms.
11907 if (DISPLAY_VER(dev_priv) < 9)
11911 * Most people will probably want a fullscreen
11912 * plane so let's not advertize modes that are
11913 * too big for that.
11915 if (DISPLAY_VER(dev_priv) >= 11) {
11916 plane_width_max = 5120 << bigjoiner;
11917 plane_height_max = 4320;
11919 plane_width_max = 5120;
11920 plane_height_max = 4096;
11923 if (mode->hdisplay > plane_width_max)
11924 return MODE_H_ILLEGAL;
11926 if (mode->vdisplay > plane_height_max)
11927 return MODE_V_ILLEGAL;
11932 static const struct drm_mode_config_funcs intel_mode_funcs = {
11933 .fb_create = intel_user_framebuffer_create,
11934 .get_format_info = intel_get_format_info,
11935 .output_poll_changed = intel_fbdev_output_poll_changed,
11936 .mode_valid = intel_mode_valid,
11937 .atomic_check = intel_atomic_check,
11938 .atomic_commit = intel_atomic_commit,
11939 .atomic_state_alloc = intel_atomic_state_alloc,
11940 .atomic_state_clear = intel_atomic_state_clear,
11941 .atomic_state_free = intel_atomic_state_free,
11945 * intel_init_display_hooks - initialize the display modesetting hooks
11946 * @dev_priv: device private
11948 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
11950 if (!HAS_DISPLAY(dev_priv))
11953 intel_init_cdclk_hooks(dev_priv);
11954 intel_init_audio_hooks(dev_priv);
11956 intel_dpll_init_clock_hook(dev_priv);
11958 if (DISPLAY_VER(dev_priv) >= 9) {
11959 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
11960 dev_priv->display.crtc_enable = hsw_crtc_enable;
11961 dev_priv->display.crtc_disable = hsw_crtc_disable;
11962 } else if (HAS_DDI(dev_priv)) {
11963 dev_priv->display.get_pipe_config = hsw_get_pipe_config;
11964 dev_priv->display.crtc_enable = hsw_crtc_enable;
11965 dev_priv->display.crtc_disable = hsw_crtc_disable;
11966 } else if (HAS_PCH_SPLIT(dev_priv)) {
11967 dev_priv->display.get_pipe_config = ilk_get_pipe_config;
11968 dev_priv->display.crtc_enable = ilk_crtc_enable;
11969 dev_priv->display.crtc_disable = ilk_crtc_disable;
11970 } else if (IS_CHERRYVIEW(dev_priv) ||
11971 IS_VALLEYVIEW(dev_priv)) {
11972 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
11973 dev_priv->display.crtc_enable = valleyview_crtc_enable;
11974 dev_priv->display.crtc_disable = i9xx_crtc_disable;
11976 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
11977 dev_priv->display.crtc_enable = i9xx_crtc_enable;
11978 dev_priv->display.crtc_disable = i9xx_crtc_disable;
11981 intel_fdi_init_hook(dev_priv);
11983 if (DISPLAY_VER(dev_priv) >= 9) {
11984 dev_priv->display.commit_modeset_enables = skl_commit_modeset_enables;
11985 dev_priv->display.get_initial_plane_config = skl_get_initial_plane_config;
11987 dev_priv->display.commit_modeset_enables = intel_commit_modeset_enables;
11988 dev_priv->display.get_initial_plane_config = i9xx_get_initial_plane_config;
11993 void intel_modeset_init_hw(struct drm_i915_private *i915)
11995 struct intel_cdclk_state *cdclk_state;
11997 if (!HAS_DISPLAY(i915))
12000 cdclk_state = to_intel_cdclk_state(i915->cdclk.obj.state);
12002 intel_update_cdclk(i915);
12003 intel_dump_cdclk_config(&i915->cdclk.hw, "Current CDCLK");
12004 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
12007 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
12009 struct drm_plane *plane;
12010 struct intel_crtc *crtc;
12012 for_each_intel_crtc(state->dev, crtc) {
12013 struct intel_crtc_state *crtc_state;
12015 crtc_state = intel_atomic_get_crtc_state(state, crtc);
12016 if (IS_ERR(crtc_state))
12017 return PTR_ERR(crtc_state);
12019 if (crtc_state->hw.active) {
12021 * Preserve the inherited flag to avoid
12022 * taking the full modeset path.
12024 crtc_state->inherited = true;
12028 drm_for_each_plane(plane, state->dev) {
12029 struct drm_plane_state *plane_state;
12031 plane_state = drm_atomic_get_plane_state(state, plane);
12032 if (IS_ERR(plane_state))
12033 return PTR_ERR(plane_state);
12040 * Calculate what we think the watermarks should be for the state we've read
12041 * out of the hardware and then immediately program those watermarks so that
12042 * we ensure the hardware settings match our internal state.
12044 * We can calculate what we think WM's should be by creating a duplicate of the
12045 * current state (which was constructed during hardware readout) and running it
12046 * through the atomic check code to calculate new watermark values in the
12049 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
12051 struct drm_atomic_state *state;
12052 struct intel_atomic_state *intel_state;
12053 struct intel_crtc *crtc;
12054 struct intel_crtc_state *crtc_state;
12055 struct drm_modeset_acquire_ctx ctx;
12059 /* Only supported on platforms that use atomic watermark design */
12060 if (!dev_priv->display.optimize_watermarks)
12063 state = drm_atomic_state_alloc(&dev_priv->drm);
12064 if (drm_WARN_ON(&dev_priv->drm, !state))
12067 intel_state = to_intel_atomic_state(state);
12069 drm_modeset_acquire_init(&ctx, 0);
12072 state->acquire_ctx = &ctx;
12075 * Hardware readout is the only time we don't want to calculate
12076 * intermediate watermarks (since we don't trust the current
12079 if (!HAS_GMCH(dev_priv))
12080 intel_state->skip_intermediate_wm = true;
12082 ret = sanitize_watermarks_add_affected(state);
12086 ret = intel_atomic_check(&dev_priv->drm, state);
12090 /* Write calculated watermark values back */
12091 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
12092 crtc_state->wm.need_postvbl_update = true;
12093 dev_priv->display.optimize_watermarks(intel_state, crtc);
12095 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
12099 if (ret == -EDEADLK) {
12100 drm_atomic_state_clear(state);
12101 drm_modeset_backoff(&ctx);
12106 * If we fail here, it means that the hardware appears to be
12107 * programmed in a way that shouldn't be possible, given our
12108 * understanding of watermark requirements. This might mean a
12109 * mistake in the hardware readout code or a mistake in the
12110 * watermark calculations for a given platform. Raise a WARN
12111 * so that this is noticeable.
12113 * If this actually happens, we'll have to just leave the
12114 * BIOS-programmed watermarks untouched and hope for the best.
12116 drm_WARN(&dev_priv->drm, ret,
12117 "Could not determine valid watermarks for inherited state\n");
12119 drm_atomic_state_put(state);
12121 drm_modeset_drop_locks(&ctx);
12122 drm_modeset_acquire_fini(&ctx);
12125 static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
12127 if (IS_IRONLAKE(dev_priv)) {
12129 intel_de_read(dev_priv, FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
12131 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
12132 } else if (IS_SANDYBRIDGE(dev_priv) || IS_IVYBRIDGE(dev_priv)) {
12133 dev_priv->fdi_pll_freq = 270000;
12138 drm_dbg(&dev_priv->drm, "FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
12141 static int intel_initial_commit(struct drm_device *dev)
12143 struct drm_atomic_state *state = NULL;
12144 struct drm_modeset_acquire_ctx ctx;
12145 struct intel_crtc *crtc;
12148 state = drm_atomic_state_alloc(dev);
12152 drm_modeset_acquire_init(&ctx, 0);
12155 state->acquire_ctx = &ctx;
12157 for_each_intel_crtc(dev, crtc) {
12158 struct intel_crtc_state *crtc_state =
12159 intel_atomic_get_crtc_state(state, crtc);
12161 if (IS_ERR(crtc_state)) {
12162 ret = PTR_ERR(crtc_state);
12166 if (crtc_state->hw.active) {
12167 struct intel_encoder *encoder;
12170 * We've not yet detected sink capabilities
12171 * (audio,infoframes,etc.) and thus we don't want to
12172 * force a full state recomputation yet. We want that to
12173 * happen only for the first real commit from userspace.
12174 * So preserve the inherited flag for the time being.
12176 crtc_state->inherited = true;
12178 ret = drm_atomic_add_affected_planes(state, &crtc->base);
12183 * FIXME hack to force a LUT update to avoid the
12184 * plane update forcing the pipe gamma on without
12185 * having a proper LUT loaded. Remove once we
12186 * have readout for pipe gamma enable.
12188 crtc_state->uapi.color_mgmt_changed = true;
12190 for_each_intel_encoder_mask(dev, encoder,
12191 crtc_state->uapi.encoder_mask) {
12192 if (encoder->initial_fastset_check &&
12193 !encoder->initial_fastset_check(encoder, crtc_state)) {
12194 ret = drm_atomic_add_affected_connectors(state,
12203 ret = drm_atomic_commit(state);
12206 if (ret == -EDEADLK) {
12207 drm_atomic_state_clear(state);
12208 drm_modeset_backoff(&ctx);
12212 drm_atomic_state_put(state);
12214 drm_modeset_drop_locks(&ctx);
12215 drm_modeset_acquire_fini(&ctx);
12220 static void intel_mode_config_init(struct drm_i915_private *i915)
12222 struct drm_mode_config *mode_config = &i915->drm.mode_config;
12224 drm_mode_config_init(&i915->drm);
12225 INIT_LIST_HEAD(&i915->global_obj_list);
12227 mode_config->min_width = 0;
12228 mode_config->min_height = 0;
12230 mode_config->preferred_depth = 24;
12231 mode_config->prefer_shadow = 1;
12233 mode_config->funcs = &intel_mode_funcs;
12235 mode_config->async_page_flip = has_async_flips(i915);
12238 * Maximum framebuffer dimensions, chosen to match
12239 * the maximum render engine surface size on gen4+.
12241 if (DISPLAY_VER(i915) >= 7) {
12242 mode_config->max_width = 16384;
12243 mode_config->max_height = 16384;
12244 } else if (DISPLAY_VER(i915) >= 4) {
12245 mode_config->max_width = 8192;
12246 mode_config->max_height = 8192;
12247 } else if (DISPLAY_VER(i915) == 3) {
12248 mode_config->max_width = 4096;
12249 mode_config->max_height = 4096;
12251 mode_config->max_width = 2048;
12252 mode_config->max_height = 2048;
12255 if (IS_I845G(i915) || IS_I865G(i915)) {
12256 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
12257 mode_config->cursor_height = 1023;
12258 } else if (IS_I830(i915) || IS_I85X(i915) ||
12259 IS_I915G(i915) || IS_I915GM(i915)) {
12260 mode_config->cursor_width = 64;
12261 mode_config->cursor_height = 64;
12263 mode_config->cursor_width = 256;
12264 mode_config->cursor_height = 256;
12268 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
12270 intel_atomic_global_obj_cleanup(i915);
12271 drm_mode_config_cleanup(&i915->drm);
12274 static void plane_config_fini(struct intel_initial_plane_config *plane_config)
12276 if (plane_config->fb) {
12277 struct drm_framebuffer *fb = &plane_config->fb->base;
12279 /* We may only have the stub and not a full framebuffer */
12280 if (drm_framebuffer_read_refcount(fb))
12281 drm_framebuffer_put(fb);
12286 if (plane_config->vma)
12287 i915_vma_put(plane_config->vma);
12290 /* part #1: call before irq install */
12291 int intel_modeset_init_noirq(struct drm_i915_private *i915)
12295 if (i915_inject_probe_failure(i915))
12298 if (HAS_DISPLAY(i915)) {
12299 ret = drm_vblank_init(&i915->drm,
12300 INTEL_NUM_PIPES(i915));
12305 intel_bios_init(i915);
12307 ret = intel_vga_register(i915);
12311 /* FIXME: completely on the wrong abstraction layer */
12312 intel_power_domains_init_hw(i915, false);
12314 if (!HAS_DISPLAY(i915))
12317 intel_dmc_ucode_init(i915);
12319 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
12320 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
12321 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
12323 i915->framestart_delay = 1; /* 1-4 */
12325 i915->window2_delay = 0; /* No DSB so no window2 delay */
12327 intel_mode_config_init(i915);
12329 ret = intel_cdclk_init(i915);
12331 goto cleanup_vga_client_pw_domain_dmc;
12333 ret = intel_dbuf_init(i915);
12335 goto cleanup_vga_client_pw_domain_dmc;
12337 ret = intel_bw_init(i915);
12339 goto cleanup_vga_client_pw_domain_dmc;
12341 init_llist_head(&i915->atomic_helper.free_list);
12342 INIT_WORK(&i915->atomic_helper.free_work,
12343 intel_atomic_helper_free_state_worker);
12345 intel_init_quirks(i915);
12347 intel_fbc_init(i915);
12351 cleanup_vga_client_pw_domain_dmc:
12352 intel_dmc_ucode_fini(i915);
12353 intel_power_domains_driver_remove(i915);
12354 intel_vga_unregister(i915);
12356 intel_bios_driver_remove(i915);
12361 /* part #2: call after irq install, but before gem init */
12362 int intel_modeset_init_nogem(struct drm_i915_private *i915)
12364 struct drm_device *dev = &i915->drm;
12366 struct intel_crtc *crtc;
12369 if (!HAS_DISPLAY(i915))
12372 intel_init_pm(i915);
12374 intel_panel_sanitize_ssc(i915);
12376 intel_pps_setup(i915);
12378 intel_gmbus_setup(i915);
12380 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
12381 INTEL_NUM_PIPES(i915),
12382 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
12384 for_each_pipe(i915, pipe) {
12385 ret = intel_crtc_init(i915, pipe);
12387 intel_mode_config_cleanup(i915);
12392 intel_plane_possible_crtcs_init(i915);
12393 intel_shared_dpll_init(dev);
12394 intel_update_fdi_pll_freq(i915);
12396 intel_update_czclk(i915);
12397 intel_modeset_init_hw(i915);
12398 intel_dpll_update_ref_clks(i915);
12400 intel_hdcp_component_init(i915);
12402 if (i915->max_cdclk_freq == 0)
12403 intel_update_max_cdclk(i915);
12406 * If the platform has HTI, we need to find out whether it has reserved
12407 * any display resources before we create our display outputs.
12409 if (INTEL_INFO(i915)->display.has_hti)
12410 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
12412 /* Just disable it once at startup */
12413 intel_vga_disable(i915);
12414 intel_setup_outputs(i915);
12416 drm_modeset_lock_all(dev);
12417 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
12418 drm_modeset_unlock_all(dev);
12420 for_each_intel_crtc(dev, crtc) {
12421 struct intel_initial_plane_config plane_config = {};
12423 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
12427 * Note that reserving the BIOS fb up front prevents us
12428 * from stuffing other stolen allocations like the ring
12429 * on top. This prevents some ugliness at boot time, and
12430 * can even allow for smooth boot transitions if the BIOS
12431 * fb is large enough for the active pipe configuration.
12433 i915->display.get_initial_plane_config(crtc, &plane_config);
12436 * If the fb is shared between multiple heads, we'll
12437 * just get the first one.
12439 intel_find_initial_plane_obj(crtc, &plane_config);
12441 plane_config_fini(&plane_config);
12445 * Make sure hardware watermarks really match the state we read out.
12446 * Note that we need to do this after reconstructing the BIOS fb's
12447 * since the watermark calculation done here will use pstate->fb.
12449 if (!HAS_GMCH(i915))
12450 sanitize_watermarks(i915);
12455 /* part #3: call after gem init */
12456 int intel_modeset_init(struct drm_i915_private *i915)
12460 if (!HAS_DISPLAY(i915))
12464 * Force all active planes to recompute their states. So that on
12465 * mode_setcrtc after probe, all the intel_plane_state variables
12466 * are already calculated and there is no assert_plane warnings
12469 ret = intel_initial_commit(&i915->drm);
12471 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
12473 intel_overlay_setup(i915);
12475 ret = intel_fbdev_init(&i915->drm);
12479 /* Only enable hotplug handling once the fbdev is fully set up. */
12480 intel_hpd_init(i915);
12481 intel_hpd_poll_disable(i915);
12483 intel_init_ipc(i915);
12488 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
12490 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12491 /* 640x480@60Hz, ~25175 kHz */
12492 struct dpll clock = {
12502 drm_WARN_ON(&dev_priv->drm,
12503 i9xx_calc_dpll_params(48000, &clock) != 25154);
12505 drm_dbg_kms(&dev_priv->drm,
12506 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
12507 pipe_name(pipe), clock.vco, clock.dot);
12509 fp = i9xx_dpll_compute_fp(&clock);
12510 dpll = DPLL_DVO_2X_MODE |
12511 DPLL_VGA_MODE_DIS |
12512 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
12513 PLL_P2_DIVIDE_BY_4 |
12514 PLL_REF_INPUT_DREFCLK |
12517 intel_de_write(dev_priv, FP0(pipe), fp);
12518 intel_de_write(dev_priv, FP1(pipe), fp);
12520 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
12521 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
12522 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
12523 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
12524 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
12525 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
12526 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
12529 * Apparently we need to have VGA mode enabled prior to changing
12530 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
12531 * dividers, even though the register value does change.
12533 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
12534 intel_de_write(dev_priv, DPLL(pipe), dpll);
12536 /* Wait for the clocks to stabilize. */
12537 intel_de_posting_read(dev_priv, DPLL(pipe));
12540 /* The pixel multiplier can only be updated once the
12541 * DPLL is enabled and the clocks are stable.
12543 * So write it again.
12545 intel_de_write(dev_priv, DPLL(pipe), dpll);
12547 /* We do this three times for luck */
12548 for (i = 0; i < 3 ; i++) {
12549 intel_de_write(dev_priv, DPLL(pipe), dpll);
12550 intel_de_posting_read(dev_priv, DPLL(pipe));
12551 udelay(150); /* wait for warmup */
12554 intel_de_write(dev_priv, PIPECONF(pipe),
12555 PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
12556 intel_de_posting_read(dev_priv, PIPECONF(pipe));
12558 intel_wait_for_pipe_scanline_moving(crtc);
12561 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
12563 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12565 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
12568 drm_WARN_ON(&dev_priv->drm,
12569 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) &
12570 DISPLAY_PLANE_ENABLE);
12571 drm_WARN_ON(&dev_priv->drm,
12572 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) &
12573 DISPLAY_PLANE_ENABLE);
12574 drm_WARN_ON(&dev_priv->drm,
12575 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) &
12576 DISPLAY_PLANE_ENABLE);
12577 drm_WARN_ON(&dev_priv->drm,
12578 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE);
12579 drm_WARN_ON(&dev_priv->drm,
12580 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE);
12582 intel_de_write(dev_priv, PIPECONF(pipe), 0);
12583 intel_de_posting_read(dev_priv, PIPECONF(pipe));
12585 intel_wait_for_pipe_scanline_stopped(crtc);
12587 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
12588 intel_de_posting_read(dev_priv, DPLL(pipe));
12592 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
12594 struct intel_crtc *crtc;
12596 if (DISPLAY_VER(dev_priv) >= 4)
12599 for_each_intel_crtc(&dev_priv->drm, crtc) {
12600 struct intel_plane *plane =
12601 to_intel_plane(crtc->base.primary);
12602 struct intel_crtc *plane_crtc;
12605 if (!plane->get_hw_state(plane, &pipe))
12608 if (pipe == crtc->pipe)
12611 drm_dbg_kms(&dev_priv->drm,
12612 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
12613 plane->base.base.id, plane->base.name);
12615 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12616 intel_plane_disable_noatomic(plane_crtc, plane);
12620 static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
12622 struct drm_device *dev = crtc->base.dev;
12623 struct intel_encoder *encoder;
12625 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
12631 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
12633 struct drm_device *dev = encoder->base.dev;
12634 struct intel_connector *connector;
12636 for_each_connector_on_encoder(dev, &encoder->base, connector)
12642 static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
12643 enum pipe pch_transcoder)
12645 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
12646 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
12649 static void intel_sanitize_frame_start_delay(const struct intel_crtc_state *crtc_state)
12651 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
12652 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
12653 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
12655 if (DISPLAY_VER(dev_priv) >= 9 ||
12656 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
12657 i915_reg_t reg = CHICKEN_TRANS(cpu_transcoder);
12660 if (transcoder_is_dsi(cpu_transcoder))
12663 val = intel_de_read(dev_priv, reg);
12664 val &= ~HSW_FRAME_START_DELAY_MASK;
12665 val |= HSW_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
12666 intel_de_write(dev_priv, reg, val);
12668 i915_reg_t reg = PIPECONF(cpu_transcoder);
12671 val = intel_de_read(dev_priv, reg);
12672 val &= ~PIPECONF_FRAME_START_DELAY_MASK;
12673 val |= PIPECONF_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
12674 intel_de_write(dev_priv, reg, val);
12677 if (!crtc_state->has_pch_encoder)
12680 if (HAS_PCH_IBX(dev_priv)) {
12681 i915_reg_t reg = PCH_TRANSCONF(crtc->pipe);
12684 val = intel_de_read(dev_priv, reg);
12685 val &= ~TRANS_FRAME_START_DELAY_MASK;
12686 val |= TRANS_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
12687 intel_de_write(dev_priv, reg, val);
12689 enum pipe pch_transcoder = intel_crtc_pch_transcoder(crtc);
12690 i915_reg_t reg = TRANS_CHICKEN2(pch_transcoder);
12693 val = intel_de_read(dev_priv, reg);
12694 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
12695 val |= TRANS_CHICKEN2_FRAME_START_DELAY(dev_priv->framestart_delay - 1);
12696 intel_de_write(dev_priv, reg, val);
12700 static void intel_sanitize_crtc(struct intel_crtc *crtc,
12701 struct drm_modeset_acquire_ctx *ctx)
12703 struct drm_device *dev = crtc->base.dev;
12704 struct drm_i915_private *dev_priv = to_i915(dev);
12705 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
12707 if (crtc_state->hw.active) {
12708 struct intel_plane *plane;
12710 /* Clear any frame start delays used for debugging left by the BIOS */
12711 intel_sanitize_frame_start_delay(crtc_state);
12713 /* Disable everything but the primary plane */
12714 for_each_intel_plane_on_crtc(dev, crtc, plane) {
12715 const struct intel_plane_state *plane_state =
12716 to_intel_plane_state(plane->base.state);
12718 if (plane_state->uapi.visible &&
12719 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
12720 intel_plane_disable_noatomic(crtc, plane);
12724 * Disable any background color set by the BIOS, but enable the
12725 * gamma and CSC to match how we program our planes.
12727 if (DISPLAY_VER(dev_priv) >= 9)
12728 intel_de_write(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe),
12729 SKL_BOTTOM_COLOR_GAMMA_ENABLE | SKL_BOTTOM_COLOR_CSC_ENABLE);
12732 /* Adjust the state of the output pipe according to whether we
12733 * have active connectors/encoders. */
12734 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc) &&
12735 !crtc_state->bigjoiner_slave)
12736 intel_crtc_disable_noatomic(crtc, ctx);
12738 if (crtc_state->hw.active || HAS_GMCH(dev_priv)) {
12740 * We start out with underrun reporting disabled to avoid races.
12741 * For correct bookkeeping mark this on active crtcs.
12743 * Also on gmch platforms we dont have any hardware bits to
12744 * disable the underrun reporting. Which means we need to start
12745 * out with underrun reporting disabled also on inactive pipes,
12746 * since otherwise we'll complain about the garbage we read when
12747 * e.g. coming up after runtime pm.
12749 * No protection against concurrent access is required - at
12750 * worst a fifo underrun happens which also sets this to false.
12752 crtc->cpu_fifo_underrun_disabled = true;
12754 * We track the PCH trancoder underrun reporting state
12755 * within the crtc. With crtc for pipe A housing the underrun
12756 * reporting state for PCH transcoder A, crtc for pipe B housing
12757 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
12758 * and marking underrun reporting as disabled for the non-existing
12759 * PCH transcoders B and C would prevent enabling the south
12760 * error interrupt (see cpt_can_enable_serr_int()).
12762 if (has_pch_trancoder(dev_priv, crtc->pipe))
12763 crtc->pch_fifo_underrun_disabled = true;
12767 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
12769 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
12772 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
12773 * the hardware when a high res displays plugged in. DPLL P
12774 * divider is zero, and the pipe timings are bonkers. We'll
12775 * try to disable everything in that case.
12777 * FIXME would be nice to be able to sanitize this state
12778 * without several WARNs, but for now let's take the easy
12781 return IS_SANDYBRIDGE(dev_priv) &&
12782 crtc_state->hw.active &&
12783 crtc_state->shared_dpll &&
12784 crtc_state->port_clock == 0;
12787 static void intel_sanitize_encoder(struct intel_encoder *encoder)
12789 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
12790 struct intel_connector *connector;
12791 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
12792 struct intel_crtc_state *crtc_state = crtc ?
12793 to_intel_crtc_state(crtc->base.state) : NULL;
12795 /* We need to check both for a crtc link (meaning that the
12796 * encoder is active and trying to read from a pipe) and the
12797 * pipe itself being active. */
12798 bool has_active_crtc = crtc_state &&
12799 crtc_state->hw.active;
12801 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
12802 drm_dbg_kms(&dev_priv->drm,
12803 "BIOS has misprogrammed the hardware. Disabling pipe %c\n",
12804 pipe_name(crtc->pipe));
12805 has_active_crtc = false;
12808 connector = intel_encoder_find_connector(encoder);
12809 if (connector && !has_active_crtc) {
12810 drm_dbg_kms(&dev_priv->drm,
12811 "[ENCODER:%d:%s] has active connectors but no active pipe!\n",
12812 encoder->base.base.id,
12813 encoder->base.name);
12815 /* Connector is active, but has no active pipe. This is
12816 * fallout from our resume register restoring. Disable
12817 * the encoder manually again. */
12819 struct drm_encoder *best_encoder;
12821 drm_dbg_kms(&dev_priv->drm,
12822 "[ENCODER:%d:%s] manually disabled\n",
12823 encoder->base.base.id,
12824 encoder->base.name);
12826 /* avoid oopsing in case the hooks consult best_encoder */
12827 best_encoder = connector->base.state->best_encoder;
12828 connector->base.state->best_encoder = &encoder->base;
12830 /* FIXME NULL atomic state passed! */
12831 if (encoder->disable)
12832 encoder->disable(NULL, encoder, crtc_state,
12833 connector->base.state);
12834 if (encoder->post_disable)
12835 encoder->post_disable(NULL, encoder, crtc_state,
12836 connector->base.state);
12838 connector->base.state->best_encoder = best_encoder;
12840 encoder->base.crtc = NULL;
12842 /* Inconsistent output/port/pipe state happens presumably due to
12843 * a bug in one of the get_hw_state functions. Or someplace else
12844 * in our code, like the register restore mess on resume. Clamp
12845 * things to off as a safer default. */
12847 connector->base.dpms = DRM_MODE_DPMS_OFF;
12848 connector->base.encoder = NULL;
12851 /* notify opregion of the sanitized encoder state */
12852 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
12854 if (HAS_DDI(dev_priv))
12855 intel_ddi_sanitize_encoder_pll_mapping(encoder);
12858 /* FIXME read out full plane state for all planes */
12859 static void readout_plane_state(struct drm_i915_private *dev_priv)
12861 struct intel_plane *plane;
12862 struct intel_crtc *crtc;
12864 for_each_intel_plane(&dev_priv->drm, plane) {
12865 struct intel_plane_state *plane_state =
12866 to_intel_plane_state(plane->base.state);
12867 struct intel_crtc_state *crtc_state;
12868 enum pipe pipe = PIPE_A;
12871 visible = plane->get_hw_state(plane, &pipe);
12873 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12874 crtc_state = to_intel_crtc_state(crtc->base.state);
12876 intel_set_plane_visible(crtc_state, plane_state, visible);
12878 drm_dbg_kms(&dev_priv->drm,
12879 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
12880 plane->base.base.id, plane->base.name,
12881 enableddisabled(visible), pipe_name(pipe));
12884 for_each_intel_crtc(&dev_priv->drm, crtc) {
12885 struct intel_crtc_state *crtc_state =
12886 to_intel_crtc_state(crtc->base.state);
12888 fixup_plane_bitmasks(crtc_state);
12892 static void intel_modeset_readout_hw_state(struct drm_device *dev)
12894 struct drm_i915_private *dev_priv = to_i915(dev);
12895 struct intel_cdclk_state *cdclk_state =
12896 to_intel_cdclk_state(dev_priv->cdclk.obj.state);
12897 struct intel_dbuf_state *dbuf_state =
12898 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
12900 struct intel_crtc *crtc;
12901 struct intel_encoder *encoder;
12902 struct intel_connector *connector;
12903 struct drm_connector_list_iter conn_iter;
12904 u8 active_pipes = 0;
12906 for_each_intel_crtc(dev, crtc) {
12907 struct intel_crtc_state *crtc_state =
12908 to_intel_crtc_state(crtc->base.state);
12910 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi);
12911 intel_crtc_free_hw_state(crtc_state);
12912 intel_crtc_state_reset(crtc_state, crtc);
12914 intel_crtc_get_pipe_config(crtc_state);
12916 crtc_state->hw.enable = crtc_state->hw.active;
12918 crtc->base.enabled = crtc_state->hw.enable;
12919 crtc->active = crtc_state->hw.active;
12921 if (crtc_state->hw.active)
12922 active_pipes |= BIT(crtc->pipe);
12924 drm_dbg_kms(&dev_priv->drm,
12925 "[CRTC:%d:%s] hw state readout: %s\n",
12926 crtc->base.base.id, crtc->base.name,
12927 enableddisabled(crtc_state->hw.active));
12930 dev_priv->active_pipes = cdclk_state->active_pipes =
12931 dbuf_state->active_pipes = active_pipes;
12933 readout_plane_state(dev_priv);
12935 for_each_intel_encoder(dev, encoder) {
12938 if (encoder->get_hw_state(encoder, &pipe)) {
12939 struct intel_crtc_state *crtc_state;
12941 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
12942 crtc_state = to_intel_crtc_state(crtc->base.state);
12944 encoder->base.crtc = &crtc->base;
12945 intel_encoder_get_config(encoder, crtc_state);
12946 if (encoder->sync_state)
12947 encoder->sync_state(encoder, crtc_state);
12949 /* read out to slave crtc as well for bigjoiner */
12950 if (crtc_state->bigjoiner) {
12951 /* encoder should read be linked to bigjoiner master */
12952 WARN_ON(crtc_state->bigjoiner_slave);
12954 crtc = crtc_state->bigjoiner_linked_crtc;
12955 crtc_state = to_intel_crtc_state(crtc->base.state);
12956 intel_encoder_get_config(encoder, crtc_state);
12959 encoder->base.crtc = NULL;
12962 drm_dbg_kms(&dev_priv->drm,
12963 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
12964 encoder->base.base.id, encoder->base.name,
12965 enableddisabled(encoder->base.crtc),
12969 intel_dpll_readout_hw_state(dev_priv);
12971 drm_connector_list_iter_begin(dev, &conn_iter);
12972 for_each_intel_connector_iter(connector, &conn_iter) {
12973 if (connector->get_hw_state(connector)) {
12974 struct intel_crtc_state *crtc_state;
12975 struct intel_crtc *crtc;
12977 connector->base.dpms = DRM_MODE_DPMS_ON;
12979 encoder = intel_attached_encoder(connector);
12980 connector->base.encoder = &encoder->base;
12982 crtc = to_intel_crtc(encoder->base.crtc);
12983 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL;
12985 if (crtc_state && crtc_state->hw.active) {
12987 * This has to be done during hardware readout
12988 * because anything calling .crtc_disable may
12989 * rely on the connector_mask being accurate.
12991 crtc_state->uapi.connector_mask |=
12992 drm_connector_mask(&connector->base);
12993 crtc_state->uapi.encoder_mask |=
12994 drm_encoder_mask(&encoder->base);
12997 connector->base.dpms = DRM_MODE_DPMS_OFF;
12998 connector->base.encoder = NULL;
13000 drm_dbg_kms(&dev_priv->drm,
13001 "[CONNECTOR:%d:%s] hw state readout: %s\n",
13002 connector->base.base.id, connector->base.name,
13003 enableddisabled(connector->base.encoder));
13005 drm_connector_list_iter_end(&conn_iter);
13007 for_each_intel_crtc(dev, crtc) {
13008 struct intel_bw_state *bw_state =
13009 to_intel_bw_state(dev_priv->bw_obj.state);
13010 struct intel_crtc_state *crtc_state =
13011 to_intel_crtc_state(crtc->base.state);
13012 struct intel_plane *plane;
13015 if (crtc_state->bigjoiner_slave)
13018 if (crtc_state->hw.active) {
13020 * The initial mode needs to be set in order to keep
13021 * the atomic core happy. It wants a valid mode if the
13022 * crtc's enabled, so we do the above call.
13024 * But we don't set all the derived state fully, hence
13025 * set a flag to indicate that a full recalculation is
13026 * needed on the next commit.
13028 crtc_state->inherited = true;
13030 intel_crtc_update_active_timings(crtc_state);
13032 intel_crtc_copy_hw_to_uapi_state(crtc_state);
13035 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
13036 const struct intel_plane_state *plane_state =
13037 to_intel_plane_state(plane->base.state);
13040 * FIXME don't have the fb yet, so can't
13041 * use intel_plane_data_rate() :(
13043 if (plane_state->uapi.visible)
13044 crtc_state->data_rate[plane->id] =
13045 4 * crtc_state->pixel_rate;
13047 * FIXME don't have the fb yet, so can't
13048 * use plane->min_cdclk() :(
13050 if (plane_state->uapi.visible && plane->min_cdclk) {
13051 if (crtc_state->double_wide || DISPLAY_VER(dev_priv) >= 10)
13052 crtc_state->min_cdclk[plane->id] =
13053 DIV_ROUND_UP(crtc_state->pixel_rate, 2);
13055 crtc_state->min_cdclk[plane->id] =
13056 crtc_state->pixel_rate;
13058 drm_dbg_kms(&dev_priv->drm,
13059 "[PLANE:%d:%s] min_cdclk %d kHz\n",
13060 plane->base.base.id, plane->base.name,
13061 crtc_state->min_cdclk[plane->id]);
13064 if (crtc_state->hw.active) {
13065 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
13066 if (drm_WARN_ON(dev, min_cdclk < 0))
13070 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk;
13071 cdclk_state->min_voltage_level[crtc->pipe] =
13072 crtc_state->min_voltage_level;
13074 intel_bw_crtc_update(bw_state, crtc_state);
13076 intel_pipe_config_sanity_check(dev_priv, crtc_state);
13078 /* discard our incomplete slave state, copy it from master */
13079 if (crtc_state->bigjoiner && crtc_state->hw.active) {
13080 struct intel_crtc *slave = crtc_state->bigjoiner_linked_crtc;
13081 struct intel_crtc_state *slave_crtc_state =
13082 to_intel_crtc_state(slave->base.state);
13084 copy_bigjoiner_crtc_state(slave_crtc_state, crtc_state);
13085 slave->base.mode = crtc->base.mode;
13087 cdclk_state->min_cdclk[slave->pipe] = min_cdclk;
13088 cdclk_state->min_voltage_level[slave->pipe] =
13089 crtc_state->min_voltage_level;
13091 for_each_intel_plane_on_crtc(&dev_priv->drm, slave, plane) {
13092 const struct intel_plane_state *plane_state =
13093 to_intel_plane_state(plane->base.state);
13096 * FIXME don't have the fb yet, so can't
13097 * use intel_plane_data_rate() :(
13099 if (plane_state->uapi.visible)
13100 crtc_state->data_rate[plane->id] =
13101 4 * crtc_state->pixel_rate;
13103 crtc_state->data_rate[plane->id] = 0;
13106 intel_bw_crtc_update(bw_state, slave_crtc_state);
13107 drm_calc_timestamping_constants(&slave->base,
13108 &slave_crtc_state->hw.adjusted_mode);
13114 get_encoder_power_domains(struct drm_i915_private *dev_priv)
13116 struct intel_encoder *encoder;
13118 for_each_intel_encoder(&dev_priv->drm, encoder) {
13119 struct intel_crtc_state *crtc_state;
13121 if (!encoder->get_power_domains)
13125 * MST-primary and inactive encoders don't have a crtc state
13126 * and neither of these require any power domain references.
13128 if (!encoder->base.crtc)
13131 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
13132 encoder->get_power_domains(encoder, crtc_state);
13136 static void intel_early_display_was(struct drm_i915_private *dev_priv)
13139 * Display WA #1185 WaDisableDARBFClkGating:cnl,glk,icl,ehl,tgl
13140 * Also known as Wa_14010480278.
13142 if (IS_DISPLAY_VER(dev_priv, 10, 12))
13143 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0,
13144 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS);
13146 if (IS_HASWELL(dev_priv)) {
13148 * WaRsPkgCStateDisplayPMReq:hsw
13149 * System hang if this isn't done before disabling all planes!
13151 intel_de_write(dev_priv, CHICKEN_PAR1_1,
13152 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
13155 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) {
13156 /* Display WA #1142:kbl,cfl,cml */
13157 intel_de_rmw(dev_priv, CHICKEN_PAR1_1,
13158 KBL_ARB_FILL_SPARE_22, KBL_ARB_FILL_SPARE_22);
13159 intel_de_rmw(dev_priv, CHICKEN_MISC_2,
13160 KBL_ARB_FILL_SPARE_13 | KBL_ARB_FILL_SPARE_14,
13161 KBL_ARB_FILL_SPARE_14);
13165 static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
13166 enum port port, i915_reg_t hdmi_reg)
13168 u32 val = intel_de_read(dev_priv, hdmi_reg);
13170 if (val & SDVO_ENABLE ||
13171 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
13174 drm_dbg_kms(&dev_priv->drm,
13175 "Sanitizing transcoder select for HDMI %c\n",
13178 val &= ~SDVO_PIPE_SEL_MASK;
13179 val |= SDVO_PIPE_SEL(PIPE_A);
13181 intel_de_write(dev_priv, hdmi_reg, val);
13184 static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
13185 enum port port, i915_reg_t dp_reg)
13187 u32 val = intel_de_read(dev_priv, dp_reg);
13189 if (val & DP_PORT_EN ||
13190 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
13193 drm_dbg_kms(&dev_priv->drm,
13194 "Sanitizing transcoder select for DP %c\n",
13197 val &= ~DP_PIPE_SEL_MASK;
13198 val |= DP_PIPE_SEL(PIPE_A);
13200 intel_de_write(dev_priv, dp_reg, val);
13203 static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
13206 * The BIOS may select transcoder B on some of the PCH
13207 * ports even it doesn't enable the port. This would trip
13208 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
13209 * Sanitize the transcoder select bits to prevent that. We
13210 * assume that the BIOS never actually enabled the port,
13211 * because if it did we'd actually have to toggle the port
13212 * on and back off to make the transcoder A select stick
13213 * (see. intel_dp_link_down(), intel_disable_hdmi(),
13214 * intel_disable_sdvo()).
13216 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
13217 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
13218 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
13220 /* PCH SDVOB multiplex with HDMIB */
13221 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
13222 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
13223 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
13226 /* Scan out the current hw modeset state,
13227 * and sanitizes it to the current state
13230 intel_modeset_setup_hw_state(struct drm_device *dev,
13231 struct drm_modeset_acquire_ctx *ctx)
13233 struct drm_i915_private *dev_priv = to_i915(dev);
13234 struct intel_encoder *encoder;
13235 struct intel_crtc *crtc;
13236 intel_wakeref_t wakeref;
13238 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
13240 intel_early_display_was(dev_priv);
13241 intel_modeset_readout_hw_state(dev);
13243 /* HW state is read out, now we need to sanitize this mess. */
13245 /* Sanitize the TypeC port mode upfront, encoders depend on this */
13246 for_each_intel_encoder(dev, encoder) {
13247 enum phy phy = intel_port_to_phy(dev_priv, encoder->port);
13249 /* We need to sanitize only the MST primary port. */
13250 if (encoder->type != INTEL_OUTPUT_DP_MST &&
13251 intel_phy_is_tc(dev_priv, phy))
13252 intel_tc_port_sanitize(enc_to_dig_port(encoder));
13255 get_encoder_power_domains(dev_priv);
13257 if (HAS_PCH_IBX(dev_priv))
13258 ibx_sanitize_pch_ports(dev_priv);
13261 * intel_sanitize_plane_mapping() may need to do vblank
13262 * waits, so we need vblank interrupts restored beforehand.
13264 for_each_intel_crtc(&dev_priv->drm, crtc) {
13265 struct intel_crtc_state *crtc_state =
13266 to_intel_crtc_state(crtc->base.state);
13268 drm_crtc_vblank_reset(&crtc->base);
13270 if (crtc_state->hw.active)
13271 intel_crtc_vblank_on(crtc_state);
13274 intel_sanitize_plane_mapping(dev_priv);
13276 for_each_intel_encoder(dev, encoder)
13277 intel_sanitize_encoder(encoder);
13279 for_each_intel_crtc(&dev_priv->drm, crtc) {
13280 struct intel_crtc_state *crtc_state =
13281 to_intel_crtc_state(crtc->base.state);
13283 intel_sanitize_crtc(crtc, ctx);
13284 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]");
13287 intel_modeset_update_connector_atomic_state(dev);
13289 intel_dpll_sanitize_state(dev_priv);
13291 if (IS_G4X(dev_priv)) {
13292 g4x_wm_get_hw_state(dev_priv);
13293 g4x_wm_sanitize(dev_priv);
13294 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
13295 vlv_wm_get_hw_state(dev_priv);
13296 vlv_wm_sanitize(dev_priv);
13297 } else if (DISPLAY_VER(dev_priv) >= 9) {
13298 skl_wm_get_hw_state(dev_priv);
13299 } else if (HAS_PCH_SPLIT(dev_priv)) {
13300 ilk_wm_get_hw_state(dev_priv);
13303 for_each_intel_crtc(dev, crtc) {
13304 struct intel_crtc_state *crtc_state =
13305 to_intel_crtc_state(crtc->base.state);
13308 put_domains = modeset_get_crtc_power_domains(crtc_state);
13309 if (drm_WARN_ON(dev, put_domains))
13310 modeset_put_crtc_power_domains(crtc, put_domains);
13313 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
13316 void intel_display_resume(struct drm_device *dev)
13318 struct drm_i915_private *dev_priv = to_i915(dev);
13319 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
13320 struct drm_modeset_acquire_ctx ctx;
13323 if (!HAS_DISPLAY(dev_priv))
13326 dev_priv->modeset_restore_state = NULL;
13328 state->acquire_ctx = &ctx;
13330 drm_modeset_acquire_init(&ctx, 0);
13333 ret = drm_modeset_lock_all_ctx(dev, &ctx);
13334 if (ret != -EDEADLK)
13337 drm_modeset_backoff(&ctx);
13341 ret = __intel_display_resume(dev, state, &ctx);
13343 intel_enable_ipc(dev_priv);
13344 drm_modeset_drop_locks(&ctx);
13345 drm_modeset_acquire_fini(&ctx);
13348 drm_err(&dev_priv->drm,
13349 "Restoring old state failed with %i\n", ret);
13351 drm_atomic_state_put(state);
13354 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
13356 struct intel_connector *connector;
13357 struct drm_connector_list_iter conn_iter;
13359 /* Kill all the work that may have been queued by hpd. */
13360 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
13361 for_each_intel_connector_iter(connector, &conn_iter) {
13362 if (connector->modeset_retry_work.func)
13363 cancel_work_sync(&connector->modeset_retry_work);
13364 if (connector->hdcp.shim) {
13365 cancel_delayed_work_sync(&connector->hdcp.check_work);
13366 cancel_work_sync(&connector->hdcp.prop_work);
13369 drm_connector_list_iter_end(&conn_iter);
13372 /* part #1: call before irq uninstall */
13373 void intel_modeset_driver_remove(struct drm_i915_private *i915)
13375 if (!HAS_DISPLAY(i915))
13378 flush_workqueue(i915->flip_wq);
13379 flush_workqueue(i915->modeset_wq);
13381 flush_work(&i915->atomic_helper.free_work);
13382 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
13385 /* part #2: call after irq uninstall */
13386 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
13388 if (!HAS_DISPLAY(i915))
13392 * Due to the hpd irq storm handling the hotplug work can re-arm the
13393 * poll handlers. Hence disable polling after hpd handling is shut down.
13395 intel_hpd_poll_fini(i915);
13398 * MST topology needs to be suspended so we don't have any calls to
13399 * fbdev after it's finalized. MST will be destroyed later as part of
13400 * drm_mode_config_cleanup()
13402 intel_dp_mst_suspend(i915);
13404 /* poll work can call into fbdev, hence clean that up afterwards */
13405 intel_fbdev_fini(i915);
13407 intel_unregister_dsm_handler();
13409 intel_fbc_global_disable(i915);
13411 /* flush any delayed tasks or pending work */
13412 flush_scheduled_work();
13414 intel_hdcp_component_fini(i915);
13416 intel_mode_config_cleanup(i915);
13418 intel_overlay_cleanup(i915);
13420 intel_gmbus_teardown(i915);
13422 destroy_workqueue(i915->flip_wq);
13423 destroy_workqueue(i915->modeset_wq);
13425 intel_fbc_cleanup_cfb(i915);
13428 /* part #3: call after gem init */
13429 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
13431 intel_dmc_ucode_fini(i915);
13433 intel_power_domains_driver_remove(i915);
13435 intel_vga_unregister(i915);
13437 intel_bios_driver_remove(i915);
13440 void intel_display_driver_register(struct drm_i915_private *i915)
13442 if (!HAS_DISPLAY(i915))
13445 intel_display_debugfs_register(i915);
13447 /* Must be done after probing outputs */
13448 intel_opregion_register(i915);
13449 acpi_video_register();
13451 intel_audio_init(i915);
13454 * Some ports require correctly set-up hpd registers for
13455 * detection to work properly (leading to ghost connected
13456 * connector status), e.g. VGA on gm45. Hence we can only set
13457 * up the initial fbdev config after hpd irqs are fully
13458 * enabled. We do it last so that the async config cannot run
13459 * before the connectors are registered.
13461 intel_fbdev_initial_config_async(&i915->drm);
13464 * We need to coordinate the hotplugs with the asynchronous
13465 * fbdev configuration, for which we use the
13466 * fbdev->async_cookie.
13468 drm_kms_helper_poll_init(&i915->drm);
13471 void intel_display_driver_unregister(struct drm_i915_private *i915)
13473 if (!HAS_DISPLAY(i915))
13476 intel_fbdev_unregister(i915);
13477 intel_audio_deinit(i915);
13480 * After flushing the fbdev (incl. a late async config which
13481 * will have delayed queuing of a hotplug event), then flush
13482 * the hotplug events.
13484 drm_kms_helper_poll_fini(&i915->drm);
13485 drm_atomic_helper_shutdown(&i915->drm);
13487 acpi_video_unregister();
13488 intel_opregion_unregister(i915);