2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <linux/dma-resv.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/string_helpers.h>
35 #include <drm/display/drm_dp_helper.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_damage_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
45 #include "gem/i915_gem_lmem.h"
46 #include "gem/i915_gem_object.h"
53 #include "i915_utils.h"
54 #include "i9xx_plane.h"
56 #include "intel_atomic.h"
57 #include "intel_atomic_plane.h"
58 #include "intel_audio.h"
60 #include "intel_cdclk.h"
61 #include "intel_clock_gating.h"
62 #include "intel_color.h"
63 #include "intel_crt.h"
64 #include "intel_crtc.h"
65 #include "intel_crtc_state_dump.h"
66 #include "intel_ddi.h"
68 #include "intel_display_driver.h"
69 #include "intel_display_power.h"
70 #include "intel_display_types.h"
71 #include "intel_dmc.h"
73 #include "intel_dp_link_training.h"
74 #include "intel_dp_mst.h"
75 #include "intel_dpio_phy.h"
76 #include "intel_dpll.h"
77 #include "intel_dpll_mgr.h"
78 #include "intel_dpt.h"
79 #include "intel_drrs.h"
80 #include "intel_dsb.h"
81 #include "intel_dsi.h"
82 #include "intel_dvo.h"
84 #include "intel_fbc.h"
85 #include "intel_fbdev.h"
86 #include "intel_fdi.h"
87 #include "intel_fifo_underrun.h"
88 #include "intel_frontbuffer.h"
89 #include "intel_hdmi.h"
90 #include "intel_hotplug.h"
91 #include "intel_link_bw.h"
92 #include "intel_lvds.h"
93 #include "intel_lvds_regs.h"
94 #include "intel_modeset_setup.h"
95 #include "intel_modeset_verify.h"
96 #include "intel_overlay.h"
97 #include "intel_panel.h"
98 #include "intel_pch_display.h"
99 #include "intel_pch_refclk.h"
100 #include "intel_pcode.h"
101 #include "intel_pipe_crc.h"
102 #include "intel_plane_initial.h"
103 #include "intel_pmdemand.h"
104 #include "intel_pps.h"
105 #include "intel_psr.h"
106 #include "intel_sdvo.h"
107 #include "intel_snps_phy.h"
108 #include "intel_tc.h"
109 #include "intel_tv.h"
110 #include "intel_vblank.h"
111 #include "intel_vdsc.h"
112 #include "intel_vdsc_regs.h"
113 #include "intel_vga.h"
114 #include "intel_vrr.h"
115 #include "intel_wm.h"
116 #include "skl_scaler.h"
117 #include "skl_universal_plane.h"
118 #include "skl_watermark.h"
120 #include "vlv_dsi_pll.h"
121 #include "vlv_dsi_regs.h"
122 #include "vlv_sideband.h"
124 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
125 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
126 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
127 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state);
129 /* returns HPLL frequency in kHz */
130 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
134 /* Obtain SKU information */
135 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
136 CCK_FUSE_HPLL_FREQ_MASK;
138 return vco_freq[hpll_freq] * 1000;
141 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
142 const char *name, u32 reg, int ref_freq)
147 val = vlv_cck_read(dev_priv, reg);
148 divider = val & CCK_FREQUENCY_VALUES;
150 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
151 (divider << CCK_FREQUENCY_STATUS_SHIFT),
152 "%s change in progress\n", name);
154 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
157 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
158 const char *name, u32 reg)
162 vlv_cck_get(dev_priv);
164 if (dev_priv->hpll_freq == 0)
165 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
167 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
169 vlv_cck_put(dev_priv);
174 void intel_update_czclk(struct drm_i915_private *dev_priv)
176 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
179 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
180 CCK_CZ_CLOCK_CONTROL);
182 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
183 dev_priv->czclk_freq);
186 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
188 return (crtc_state->active_planes &
189 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
192 /* WA Display #0827: Gen9:all */
194 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
197 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
198 0, DUPS1_GATING_DIS | DUPS2_GATING_DIS);
200 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
201 DUPS1_GATING_DIS | DUPS2_GATING_DIS, 0);
204 /* Wa_2006604312:icl,ehl */
206 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
210 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), 0, DPFR_GATING_DIS);
212 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), DPFR_GATING_DIS, 0);
215 /* Wa_1604331009:icl,jsl,ehl */
217 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
220 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), CURSOR_GATING_DIS,
221 enable ? CURSOR_GATING_DIS : 0);
225 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
227 return crtc_state->master_transcoder != INVALID_TRANSCODER;
231 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
233 return crtc_state->sync_mode_slaves_mask != 0;
237 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
239 return is_trans_port_sync_master(crtc_state) ||
240 is_trans_port_sync_slave(crtc_state);
243 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state)
245 return ffs(crtc_state->bigjoiner_pipes) - 1;
248 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state)
250 if (crtc_state->bigjoiner_pipes)
251 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state));
256 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state)
258 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
260 return crtc_state->bigjoiner_pipes &&
261 crtc->pipe != bigjoiner_master_pipe(crtc_state);
264 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state)
266 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
268 return crtc_state->bigjoiner_pipes &&
269 crtc->pipe == bigjoiner_master_pipe(crtc_state);
272 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state)
274 return hweight8(crtc_state->bigjoiner_pipes);
277 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state)
279 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
281 if (intel_crtc_is_bigjoiner_slave(crtc_state))
282 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state));
284 return to_intel_crtc(crtc_state->uapi.crtc);
288 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
290 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
291 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
293 if (DISPLAY_VER(dev_priv) >= 4) {
294 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
296 /* Wait for the Pipe State to go off */
297 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(cpu_transcoder),
298 TRANSCONF_STATE_ENABLE, 100))
299 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
301 intel_wait_for_pipe_scanline_stopped(crtc);
305 void assert_transcoder(struct drm_i915_private *dev_priv,
306 enum transcoder cpu_transcoder, bool state)
309 enum intel_display_power_domain power_domain;
310 intel_wakeref_t wakeref;
312 /* we keep both pipes enabled on 830 */
313 if (IS_I830(dev_priv))
316 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
317 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
319 u32 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
320 cur_state = !!(val & TRANSCONF_ENABLE);
322 intel_display_power_put(dev_priv, power_domain, wakeref);
327 I915_STATE_WARN(dev_priv, cur_state != state,
328 "transcoder %s assertion failure (expected %s, current %s)\n",
329 transcoder_name(cpu_transcoder), str_on_off(state),
330 str_on_off(cur_state));
333 static void assert_plane(struct intel_plane *plane, bool state)
335 struct drm_i915_private *i915 = to_i915(plane->base.dev);
339 cur_state = plane->get_hw_state(plane, &pipe);
341 I915_STATE_WARN(i915, cur_state != state,
342 "%s assertion failure (expected %s, current %s)\n",
343 plane->base.name, str_on_off(state),
344 str_on_off(cur_state));
347 #define assert_plane_enabled(p) assert_plane(p, true)
348 #define assert_plane_disabled(p) assert_plane(p, false)
350 static void assert_planes_disabled(struct intel_crtc *crtc)
352 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
353 struct intel_plane *plane;
355 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
356 assert_plane_disabled(plane);
359 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
360 struct intel_digital_port *dig_port,
361 unsigned int expected_mask)
366 switch (dig_port->base.port) {
368 MISSING_CASE(dig_port->base.port);
371 port_mask = DPLL_PORTB_READY_MASK;
375 port_mask = DPLL_PORTC_READY_MASK;
380 port_mask = DPLL_PORTD_READY_MASK;
381 dpll_reg = DPIO_PHY_STATUS;
385 if (intel_de_wait_for_register(dev_priv, dpll_reg,
386 port_mask, expected_mask, 1000))
387 drm_WARN(&dev_priv->drm, 1,
388 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
389 dig_port->base.base.base.id, dig_port->base.base.name,
390 intel_de_read(dev_priv, dpll_reg) & port_mask,
394 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
396 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
398 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
399 enum pipe pipe = crtc->pipe;
403 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
405 assert_planes_disabled(crtc);
408 * A pipe without a PLL won't actually be able to drive bits from
409 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
412 if (HAS_GMCH(dev_priv)) {
413 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
414 assert_dsi_pll_enabled(dev_priv);
416 assert_pll_enabled(dev_priv, pipe);
418 if (new_crtc_state->has_pch_encoder) {
419 /* if driving the PCH, we need FDI enabled */
420 assert_fdi_rx_pll_enabled(dev_priv,
421 intel_crtc_pch_transcoder(crtc));
422 assert_fdi_tx_pll_enabled(dev_priv,
423 (enum pipe) cpu_transcoder);
425 /* FIXME: assert CPU port conditions for SNB+ */
428 /* Wa_22012358565:adl-p */
429 if (DISPLAY_VER(dev_priv) == 13)
430 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
431 0, PIPE_ARB_USE_PROG_SLOTS);
433 reg = TRANSCONF(cpu_transcoder);
434 val = intel_de_read(dev_priv, reg);
435 if (val & TRANSCONF_ENABLE) {
436 /* we keep both pipes enabled on 830 */
437 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
441 intel_de_write(dev_priv, reg, val | TRANSCONF_ENABLE);
442 intel_de_posting_read(dev_priv, reg);
445 * Until the pipe starts PIPEDSL reads will return a stale value,
446 * which causes an apparent vblank timestamp jump when PIPEDSL
447 * resets to its proper value. That also messes up the frame count
448 * when it's derived from the timestamps. So let's wait for the
449 * pipe to start properly before we call drm_crtc_vblank_on()
451 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
452 intel_wait_for_pipe_scanline_moving(crtc);
455 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
457 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
459 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
460 enum pipe pipe = crtc->pipe;
464 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
467 * Make sure planes won't keep trying to pump pixels to us,
468 * or we might hang the display.
470 assert_planes_disabled(crtc);
472 reg = TRANSCONF(cpu_transcoder);
473 val = intel_de_read(dev_priv, reg);
474 if ((val & TRANSCONF_ENABLE) == 0)
478 * Double wide has implications for planes
479 * so best keep it disabled when not needed.
481 if (old_crtc_state->double_wide)
482 val &= ~TRANSCONF_DOUBLE_WIDE;
484 /* Don't disable pipe or pipe PLLs if needed */
485 if (!IS_I830(dev_priv))
486 val &= ~TRANSCONF_ENABLE;
488 if (DISPLAY_VER(dev_priv) >= 14)
489 intel_de_rmw(dev_priv, MTL_CHICKEN_TRANS(cpu_transcoder),
490 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
491 else if (DISPLAY_VER(dev_priv) >= 12)
492 intel_de_rmw(dev_priv, CHICKEN_TRANS(cpu_transcoder),
493 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
495 intel_de_write(dev_priv, reg, val);
496 if ((val & TRANSCONF_ENABLE) == 0)
497 intel_wait_for_pipe_off(old_crtc_state);
500 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
502 unsigned int size = 0;
505 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
506 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
511 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
513 unsigned int size = 0;
516 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
517 unsigned int plane_size;
519 if (rem_info->plane[i].linear)
520 plane_size = rem_info->plane[i].size;
522 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
527 if (rem_info->plane_alignment)
528 size = ALIGN(size, rem_info->plane_alignment);
536 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
538 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
539 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
541 return DISPLAY_VER(dev_priv) < 4 ||
543 plane_state->view.gtt.type == I915_GTT_VIEW_NORMAL);
547 * Convert the x/y offsets into a linear offset.
548 * Only valid with 0/180 degree rotation, which is fine since linear
549 * offset is only used with linear buffers on pre-hsw and tiled buffers
550 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
552 u32 intel_fb_xy_to_linear(int x, int y,
553 const struct intel_plane_state *state,
556 const struct drm_framebuffer *fb = state->hw.fb;
557 unsigned int cpp = fb->format->cpp[color_plane];
558 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
560 return y * pitch + x * cpp;
564 * Add the x/y offsets derived from fb->offsets[] to the user
565 * specified plane src x/y offsets. The resulting x/y offsets
566 * specify the start of scanout from the beginning of the gtt mapping.
568 void intel_add_fb_offsets(int *x, int *y,
569 const struct intel_plane_state *state,
573 *x += state->view.color_plane[color_plane].x;
574 *y += state->view.color_plane[color_plane].y;
577 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
578 u32 pixel_format, u64 modifier)
580 struct intel_crtc *crtc;
581 struct intel_plane *plane;
583 if (!HAS_DISPLAY(dev_priv))
587 * We assume the primary plane for pipe A has
588 * the highest stride limits of them all,
589 * if in case pipe A is disabled, use the first pipe from pipe_mask.
591 crtc = intel_first_crtc(dev_priv);
595 plane = to_intel_plane(crtc->base.primary);
597 return plane->max_stride(plane, pixel_format, modifier,
601 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
602 struct intel_plane_state *plane_state,
605 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
607 plane_state->uapi.visible = visible;
610 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
612 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
615 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
617 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
618 struct drm_plane *plane;
621 * Active_planes aliases if multiple "primary" or cursor planes
622 * have been used on the same (or wrong) pipe. plane_mask uses
623 * unique ids, hence we can use that to reconstruct active_planes.
625 crtc_state->enabled_planes = 0;
626 crtc_state->active_planes = 0;
628 drm_for_each_plane_mask(plane, &dev_priv->drm,
629 crtc_state->uapi.plane_mask) {
630 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
631 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
635 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
636 struct intel_plane *plane)
638 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
639 struct intel_crtc_state *crtc_state =
640 to_intel_crtc_state(crtc->base.state);
641 struct intel_plane_state *plane_state =
642 to_intel_plane_state(plane->base.state);
644 drm_dbg_kms(&dev_priv->drm,
645 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
646 plane->base.base.id, plane->base.name,
647 crtc->base.base.id, crtc->base.name);
649 intel_set_plane_visible(crtc_state, plane_state, false);
650 intel_plane_fixup_bitmasks(crtc_state);
651 crtc_state->data_rate[plane->id] = 0;
652 crtc_state->data_rate_y[plane->id] = 0;
653 crtc_state->rel_data_rate[plane->id] = 0;
654 crtc_state->rel_data_rate_y[plane->id] = 0;
655 crtc_state->min_cdclk[plane->id] = 0;
657 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
658 hsw_ips_disable(crtc_state)) {
659 crtc_state->ips_enabled = false;
660 intel_crtc_wait_for_next_vblank(crtc);
664 * Vblank time updates from the shadow to live plane control register
665 * are blocked if the memory self-refresh mode is active at that
666 * moment. So to make sure the plane gets truly disabled, disable
667 * first the self-refresh mode. The self-refresh enable bit in turn
668 * will be checked/applied by the HW only at the next frame start
669 * event which is after the vblank start event, so we need to have a
670 * wait-for-vblank between disabling the plane and the pipe.
672 if (HAS_GMCH(dev_priv) &&
673 intel_set_memory_cxsr(dev_priv, false))
674 intel_crtc_wait_for_next_vblank(crtc);
677 * Gen2 reports pipe underruns whenever all planes are disabled.
678 * So disable underrun reporting before all the planes get disabled.
680 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
681 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
683 intel_plane_disable_arm(plane, crtc_state);
684 intel_crtc_wait_for_next_vblank(crtc);
688 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
692 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
693 plane_state->view.color_plane[0].offset, 0);
698 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
700 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
701 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
702 enum pipe pipe = crtc->pipe;
705 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
708 * Display WA #1153: icl
709 * enable hardware to bypass the alpha math
710 * and rounding for per-pixel values 00 and 0xff
712 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
714 * Display WA # 1605353570: icl
715 * Set the pixel rounding bit to 1 for allowing
716 * passthrough of Frame buffer pixels unmodified
719 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
722 * Underrun recovery must always be disabled on display 13+.
723 * DG2 chicken bit meaning is inverted compared to other platforms.
725 if (IS_DG2(dev_priv))
726 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
727 else if (DISPLAY_VER(dev_priv) >= 13)
728 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
730 /* Wa_14010547955:dg2 */
731 if (IS_DG2(dev_priv))
732 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
734 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
737 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
739 struct drm_crtc *crtc;
742 drm_for_each_crtc(crtc, &dev_priv->drm) {
743 struct drm_crtc_commit *commit;
744 spin_lock(&crtc->commit_lock);
745 commit = list_first_entry_or_null(&crtc->commit_list,
746 struct drm_crtc_commit, commit_entry);
747 cleanup_done = commit ?
748 try_wait_for_completion(&commit->cleanup_done) : true;
749 spin_unlock(&crtc->commit_lock);
754 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
763 * Finds the encoder associated with the given CRTC. This can only be
764 * used when we know that the CRTC isn't feeding multiple encoders!
766 struct intel_encoder *
767 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
768 const struct intel_crtc_state *crtc_state)
770 const struct drm_connector_state *connector_state;
771 const struct drm_connector *connector;
772 struct intel_encoder *encoder = NULL;
773 struct intel_crtc *master_crtc;
774 int num_encoders = 0;
777 master_crtc = intel_master_crtc(crtc_state);
779 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
780 if (connector_state->crtc != &master_crtc->base)
783 encoder = to_intel_encoder(connector_state->best_encoder);
787 drm_WARN(state->base.dev, num_encoders != 1,
788 "%d encoders for pipe %c\n",
789 num_encoders, pipe_name(master_crtc->pipe));
794 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
796 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
797 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
798 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
799 enum pipe pipe = crtc->pipe;
800 int width = drm_rect_width(dst);
801 int height = drm_rect_height(dst);
805 if (!crtc_state->pch_pfit.enabled)
808 /* Force use of hard-coded filter coefficients
809 * as some pre-programmed values are broken,
812 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
813 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
814 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
816 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
818 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe),
819 PF_WIN_XPOS(x) | PF_WIN_YPOS(y));
820 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe),
821 PF_WIN_XSIZE(width) | PF_WIN_YSIZE(height));
824 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
827 (void) intel_overlay_switch_off(crtc->overlay);
829 /* Let userspace switch the overlay on again. In most cases userspace
830 * has to recompute where to put it anyway.
834 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
836 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
838 if (!crtc_state->nv12_planes)
841 /* WA Display #0827: Gen9:all */
842 if (DISPLAY_VER(dev_priv) == 9)
848 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
850 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
852 /* Wa_2006604312:icl,ehl */
853 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
859 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
861 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
863 /* Wa_1604331009:icl,jsl,ehl */
864 if (is_hdr_mode(crtc_state) &&
865 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
866 DISPLAY_VER(dev_priv) == 11)
872 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
873 enum pipe pipe, bool enable)
875 if (DISPLAY_VER(i915) == 9) {
877 * "Plane N strech max must be programmed to 11b (x1)
878 * when Async flips are enabled on that plane."
880 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
881 SKL_PLANE1_STRETCH_MAX_MASK,
882 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
884 /* Also needed on HSW/BDW albeit undocumented */
885 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
886 HSW_PRI_STRETCH_MAX_MASK,
887 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
891 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
893 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
895 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
896 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
899 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
900 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
901 (new_crtc_state)->feature)
902 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
903 ((old_crtc_state)->feature && \
904 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
906 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
907 const struct intel_crtc_state *new_crtc_state)
909 if (!new_crtc_state->hw.active)
912 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
915 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
916 const struct intel_crtc_state *new_crtc_state)
918 if (!old_crtc_state->hw.active)
921 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
924 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state,
925 const struct intel_crtc_state *new_crtc_state)
927 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline ||
928 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin ||
929 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax ||
930 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband ||
931 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full;
934 static bool vrr_enabling(const struct intel_crtc_state *old_crtc_state,
935 const struct intel_crtc_state *new_crtc_state)
937 if (!new_crtc_state->hw.active)
940 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) ||
941 (new_crtc_state->vrr.enable &&
942 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
943 vrr_params_changed(old_crtc_state, new_crtc_state)));
946 static bool vrr_disabling(const struct intel_crtc_state *old_crtc_state,
947 const struct intel_crtc_state *new_crtc_state)
949 if (!old_crtc_state->hw.active)
952 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) ||
953 (old_crtc_state->vrr.enable &&
954 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
955 vrr_params_changed(old_crtc_state, new_crtc_state)));
961 static void intel_post_plane_update(struct intel_atomic_state *state,
962 struct intel_crtc *crtc)
964 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
965 const struct intel_crtc_state *old_crtc_state =
966 intel_atomic_get_old_crtc_state(state, crtc);
967 const struct intel_crtc_state *new_crtc_state =
968 intel_atomic_get_new_crtc_state(state, crtc);
969 enum pipe pipe = crtc->pipe;
971 intel_psr_post_plane_update(state, crtc);
973 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
975 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
976 intel_update_watermarks(dev_priv);
978 intel_fbc_post_update(state, crtc);
980 if (needs_async_flip_vtd_wa(old_crtc_state) &&
981 !needs_async_flip_vtd_wa(new_crtc_state))
982 intel_async_flip_vtd_wa(dev_priv, pipe, false);
984 if (needs_nv12_wa(old_crtc_state) &&
985 !needs_nv12_wa(new_crtc_state))
986 skl_wa_827(dev_priv, pipe, false);
988 if (needs_scalerclk_wa(old_crtc_state) &&
989 !needs_scalerclk_wa(new_crtc_state))
990 icl_wa_scalerclkgating(dev_priv, pipe, false);
992 if (needs_cursorclk_wa(old_crtc_state) &&
993 !needs_cursorclk_wa(new_crtc_state))
994 icl_wa_cursorclkgating(dev_priv, pipe, false);
996 if (intel_crtc_needs_color_update(new_crtc_state))
997 intel_color_post_update(new_crtc_state);
1000 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
1001 struct intel_crtc *crtc)
1003 const struct intel_crtc_state *crtc_state =
1004 intel_atomic_get_new_crtc_state(state, crtc);
1005 u8 update_planes = crtc_state->update_planes;
1006 const struct intel_plane_state __maybe_unused *plane_state;
1007 struct intel_plane *plane;
1010 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1011 if (plane->pipe == crtc->pipe &&
1012 update_planes & BIT(plane->id))
1013 plane->enable_flip_done(plane);
1017 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1018 struct intel_crtc *crtc)
1020 const struct intel_crtc_state *crtc_state =
1021 intel_atomic_get_new_crtc_state(state, crtc);
1022 u8 update_planes = crtc_state->update_planes;
1023 const struct intel_plane_state __maybe_unused *plane_state;
1024 struct intel_plane *plane;
1027 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1028 if (plane->pipe == crtc->pipe &&
1029 update_planes & BIT(plane->id))
1030 plane->disable_flip_done(plane);
1034 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1035 struct intel_crtc *crtc)
1037 const struct intel_crtc_state *old_crtc_state =
1038 intel_atomic_get_old_crtc_state(state, crtc);
1039 const struct intel_crtc_state *new_crtc_state =
1040 intel_atomic_get_new_crtc_state(state, crtc);
1041 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1042 ~new_crtc_state->async_flip_planes;
1043 const struct intel_plane_state *old_plane_state;
1044 struct intel_plane *plane;
1045 bool need_vbl_wait = false;
1048 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1049 if (plane->need_async_flip_disable_wa &&
1050 plane->pipe == crtc->pipe &&
1051 disable_async_flip_planes & BIT(plane->id)) {
1053 * Apart from the async flip bit we want to
1054 * preserve the old state for the plane.
1056 plane->async_flip(plane, old_crtc_state,
1057 old_plane_state, false);
1058 need_vbl_wait = true;
1063 intel_crtc_wait_for_next_vblank(crtc);
1066 static void intel_pre_plane_update(struct intel_atomic_state *state,
1067 struct intel_crtc *crtc)
1069 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1070 const struct intel_crtc_state *old_crtc_state =
1071 intel_atomic_get_old_crtc_state(state, crtc);
1072 const struct intel_crtc_state *new_crtc_state =
1073 intel_atomic_get_new_crtc_state(state, crtc);
1074 enum pipe pipe = crtc->pipe;
1076 if (vrr_disabling(old_crtc_state, new_crtc_state)) {
1077 intel_vrr_disable(old_crtc_state);
1078 intel_crtc_update_active_timings(old_crtc_state, false);
1081 intel_drrs_deactivate(old_crtc_state);
1083 intel_psr_pre_plane_update(state, crtc);
1085 if (hsw_ips_pre_update(state, crtc))
1086 intel_crtc_wait_for_next_vblank(crtc);
1088 if (intel_fbc_pre_update(state, crtc))
1089 intel_crtc_wait_for_next_vblank(crtc);
1091 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1092 needs_async_flip_vtd_wa(new_crtc_state))
1093 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1095 /* Display WA 827 */
1096 if (!needs_nv12_wa(old_crtc_state) &&
1097 needs_nv12_wa(new_crtc_state))
1098 skl_wa_827(dev_priv, pipe, true);
1100 /* Wa_2006604312:icl,ehl */
1101 if (!needs_scalerclk_wa(old_crtc_state) &&
1102 needs_scalerclk_wa(new_crtc_state))
1103 icl_wa_scalerclkgating(dev_priv, pipe, true);
1105 /* Wa_1604331009:icl,jsl,ehl */
1106 if (!needs_cursorclk_wa(old_crtc_state) &&
1107 needs_cursorclk_wa(new_crtc_state))
1108 icl_wa_cursorclkgating(dev_priv, pipe, true);
1111 * Vblank time updates from the shadow to live plane control register
1112 * are blocked if the memory self-refresh mode is active at that
1113 * moment. So to make sure the plane gets truly disabled, disable
1114 * first the self-refresh mode. The self-refresh enable bit in turn
1115 * will be checked/applied by the HW only at the next frame start
1116 * event which is after the vblank start event, so we need to have a
1117 * wait-for-vblank between disabling the plane and the pipe.
1119 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1120 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1121 intel_crtc_wait_for_next_vblank(crtc);
1124 * IVB workaround: must disable low power watermarks for at least
1125 * one frame before enabling scaling. LP watermarks can be re-enabled
1126 * when scaling is disabled.
1128 * WaCxSRDisabledForSpriteScaling:ivb
1130 if (old_crtc_state->hw.active &&
1131 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
1132 intel_crtc_wait_for_next_vblank(crtc);
1135 * If we're doing a modeset we don't need to do any
1136 * pre-vblank watermark programming here.
1138 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1140 * For platforms that support atomic watermarks, program the
1141 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1142 * will be the intermediate values that are safe for both pre- and
1143 * post- vblank; when vblank happens, the 'active' values will be set
1144 * to the final 'target' values and we'll do this again to get the
1145 * optimal watermarks. For gen9+ platforms, the values we program here
1146 * will be the final target values which will get automatically latched
1147 * at vblank time; no further programming will be necessary.
1149 * If a platform hasn't been transitioned to atomic watermarks yet,
1150 * we'll continue to update watermarks the old way, if flags tell
1153 if (!intel_initial_watermarks(state, crtc))
1154 if (new_crtc_state->update_wm_pre)
1155 intel_update_watermarks(dev_priv);
1159 * Gen2 reports pipe underruns whenever all planes are disabled.
1160 * So disable underrun reporting before all the planes get disabled.
1162 * We do this after .initial_watermarks() so that we have a
1163 * chance of catching underruns with the intermediate watermarks
1164 * vs. the old plane configuration.
1166 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1167 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1170 * WA for platforms where async address update enable bit
1171 * is double buffered and only latched at start of vblank.
1173 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1174 intel_crtc_async_flip_disable_wa(state, crtc);
1177 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1178 struct intel_crtc *crtc)
1180 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1181 const struct intel_crtc_state *new_crtc_state =
1182 intel_atomic_get_new_crtc_state(state, crtc);
1183 unsigned int update_mask = new_crtc_state->update_planes;
1184 const struct intel_plane_state *old_plane_state;
1185 struct intel_plane *plane;
1186 unsigned fb_bits = 0;
1189 intel_crtc_dpms_overlay_disable(crtc);
1191 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1192 if (crtc->pipe != plane->pipe ||
1193 !(update_mask & BIT(plane->id)))
1196 intel_plane_disable_arm(plane, new_crtc_state);
1198 if (old_plane_state->uapi.visible)
1199 fb_bits |= plane->frontbuffer_bit;
1202 intel_frontbuffer_flip(dev_priv, fb_bits);
1205 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1207 struct drm_i915_private *i915 = to_i915(state->base.dev);
1208 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1209 struct intel_crtc *crtc;
1213 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1214 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1216 if (i915->display.dpll.mgr) {
1217 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1218 if (intel_crtc_needs_modeset(new_crtc_state))
1221 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1222 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1227 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1228 struct intel_crtc *crtc)
1230 const struct intel_crtc_state *crtc_state =
1231 intel_atomic_get_new_crtc_state(state, crtc);
1232 const struct drm_connector_state *conn_state;
1233 struct drm_connector *conn;
1236 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1237 struct intel_encoder *encoder =
1238 to_intel_encoder(conn_state->best_encoder);
1240 if (conn_state->crtc != &crtc->base)
1243 if (encoder->pre_pll_enable)
1244 encoder->pre_pll_enable(state, encoder,
1245 crtc_state, conn_state);
1249 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1250 struct intel_crtc *crtc)
1252 const struct intel_crtc_state *crtc_state =
1253 intel_atomic_get_new_crtc_state(state, crtc);
1254 const struct drm_connector_state *conn_state;
1255 struct drm_connector *conn;
1258 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1259 struct intel_encoder *encoder =
1260 to_intel_encoder(conn_state->best_encoder);
1262 if (conn_state->crtc != &crtc->base)
1265 if (encoder->pre_enable)
1266 encoder->pre_enable(state, encoder,
1267 crtc_state, conn_state);
1271 static void intel_encoders_enable(struct intel_atomic_state *state,
1272 struct intel_crtc *crtc)
1274 const struct intel_crtc_state *crtc_state =
1275 intel_atomic_get_new_crtc_state(state, crtc);
1276 const struct drm_connector_state *conn_state;
1277 struct drm_connector *conn;
1280 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1281 struct intel_encoder *encoder =
1282 to_intel_encoder(conn_state->best_encoder);
1284 if (conn_state->crtc != &crtc->base)
1287 if (encoder->enable)
1288 encoder->enable(state, encoder,
1289 crtc_state, conn_state);
1290 intel_opregion_notify_encoder(encoder, true);
1294 static void intel_encoders_disable(struct intel_atomic_state *state,
1295 struct intel_crtc *crtc)
1297 const struct intel_crtc_state *old_crtc_state =
1298 intel_atomic_get_old_crtc_state(state, crtc);
1299 const struct drm_connector_state *old_conn_state;
1300 struct drm_connector *conn;
1303 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1304 struct intel_encoder *encoder =
1305 to_intel_encoder(old_conn_state->best_encoder);
1307 if (old_conn_state->crtc != &crtc->base)
1310 intel_opregion_notify_encoder(encoder, false);
1311 if (encoder->disable)
1312 encoder->disable(state, encoder,
1313 old_crtc_state, old_conn_state);
1317 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1318 struct intel_crtc *crtc)
1320 const struct intel_crtc_state *old_crtc_state =
1321 intel_atomic_get_old_crtc_state(state, crtc);
1322 const struct drm_connector_state *old_conn_state;
1323 struct drm_connector *conn;
1326 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1327 struct intel_encoder *encoder =
1328 to_intel_encoder(old_conn_state->best_encoder);
1330 if (old_conn_state->crtc != &crtc->base)
1333 if (encoder->post_disable)
1334 encoder->post_disable(state, encoder,
1335 old_crtc_state, old_conn_state);
1339 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1340 struct intel_crtc *crtc)
1342 const struct intel_crtc_state *old_crtc_state =
1343 intel_atomic_get_old_crtc_state(state, crtc);
1344 const struct drm_connector_state *old_conn_state;
1345 struct drm_connector *conn;
1348 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1349 struct intel_encoder *encoder =
1350 to_intel_encoder(old_conn_state->best_encoder);
1352 if (old_conn_state->crtc != &crtc->base)
1355 if (encoder->post_pll_disable)
1356 encoder->post_pll_disable(state, encoder,
1357 old_crtc_state, old_conn_state);
1361 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1362 struct intel_crtc *crtc)
1364 const struct intel_crtc_state *crtc_state =
1365 intel_atomic_get_new_crtc_state(state, crtc);
1366 const struct drm_connector_state *conn_state;
1367 struct drm_connector *conn;
1370 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1371 struct intel_encoder *encoder =
1372 to_intel_encoder(conn_state->best_encoder);
1374 if (conn_state->crtc != &crtc->base)
1377 if (encoder->update_pipe)
1378 encoder->update_pipe(state, encoder,
1379 crtc_state, conn_state);
1383 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
1385 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1386 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1388 plane->disable_arm(plane, crtc_state);
1391 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1393 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1394 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1396 if (crtc_state->has_pch_encoder) {
1397 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1398 &crtc_state->fdi_m_n);
1399 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1400 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1401 &crtc_state->dp_m_n);
1402 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1403 &crtc_state->dp_m2_n2);
1406 intel_set_transcoder_timings(crtc_state);
1408 ilk_set_pipeconf(crtc_state);
1411 static void ilk_crtc_enable(struct intel_atomic_state *state,
1412 struct intel_crtc *crtc)
1414 const struct intel_crtc_state *new_crtc_state =
1415 intel_atomic_get_new_crtc_state(state, crtc);
1416 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1417 enum pipe pipe = crtc->pipe;
1419 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1423 * Sometimes spurious CPU pipe underruns happen during FDI
1424 * training, at least with VGA+HDMI cloning. Suppress them.
1426 * On ILK we get an occasional spurious CPU pipe underruns
1427 * between eDP port A enable and vdd enable. Also PCH port
1428 * enable seems to result in the occasional CPU pipe underrun.
1430 * Spurious PCH underruns also occur during PCH enabling.
1432 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1433 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1435 ilk_configure_cpu_transcoder(new_crtc_state);
1437 intel_set_pipe_src_size(new_crtc_state);
1439 crtc->active = true;
1441 intel_encoders_pre_enable(state, crtc);
1443 if (new_crtc_state->has_pch_encoder) {
1444 ilk_pch_pre_enable(state, crtc);
1446 assert_fdi_tx_disabled(dev_priv, pipe);
1447 assert_fdi_rx_disabled(dev_priv, pipe);
1450 ilk_pfit_enable(new_crtc_state);
1453 * On ILK+ LUT must be loaded before the pipe is running but with
1456 intel_color_load_luts(new_crtc_state);
1457 intel_color_commit_noarm(new_crtc_state);
1458 intel_color_commit_arm(new_crtc_state);
1459 /* update DSPCNTR to configure gamma for pipe bottom color */
1460 intel_disable_primary_plane(new_crtc_state);
1462 intel_initial_watermarks(state, crtc);
1463 intel_enable_transcoder(new_crtc_state);
1465 if (new_crtc_state->has_pch_encoder)
1466 ilk_pch_enable(state, crtc);
1468 intel_crtc_vblank_on(new_crtc_state);
1470 intel_encoders_enable(state, crtc);
1472 if (HAS_PCH_CPT(dev_priv))
1473 intel_wait_for_pipe_scanline_moving(crtc);
1476 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1477 * And a second vblank wait is needed at least on ILK with
1478 * some interlaced HDMI modes. Let's do the double wait always
1479 * in case there are more corner cases we don't know about.
1481 if (new_crtc_state->has_pch_encoder) {
1482 intel_crtc_wait_for_next_vblank(crtc);
1483 intel_crtc_wait_for_next_vblank(crtc);
1485 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1486 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1489 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
1490 enum pipe pipe, bool apply)
1492 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
1493 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1500 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
1503 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1505 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1506 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1508 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1509 HSW_LINETIME(crtc_state->linetime) |
1510 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1513 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1515 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1517 enum transcoder transcoder = crtc_state->cpu_transcoder;
1518 i915_reg_t reg = DISPLAY_VER(dev_priv) >= 14 ? MTL_CHICKEN_TRANS(transcoder) :
1519 CHICKEN_TRANS(transcoder);
1521 intel_de_rmw(dev_priv, reg,
1522 HSW_FRAME_START_DELAY_MASK,
1523 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1526 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
1527 const struct intel_crtc_state *crtc_state)
1529 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state);
1532 * Enable sequence steps 1-7 on bigjoiner master
1534 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1535 intel_encoders_pre_pll_enable(state, master_crtc);
1537 if (crtc_state->shared_dpll)
1538 intel_enable_shared_dpll(crtc_state);
1540 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1541 intel_encoders_pre_enable(state, master_crtc);
1544 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1546 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1547 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1548 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1550 if (crtc_state->has_pch_encoder) {
1551 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1552 &crtc_state->fdi_m_n);
1553 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1554 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1555 &crtc_state->dp_m_n);
1556 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1557 &crtc_state->dp_m2_n2);
1560 intel_set_transcoder_timings(crtc_state);
1561 if (HAS_VRR(dev_priv))
1562 intel_vrr_set_transcoder_timings(crtc_state);
1564 if (cpu_transcoder != TRANSCODER_EDP)
1565 intel_de_write(dev_priv, TRANS_MULT(cpu_transcoder),
1566 crtc_state->pixel_multiplier - 1);
1568 hsw_set_frame_start_delay(crtc_state);
1570 hsw_set_transconf(crtc_state);
1573 static void hsw_crtc_enable(struct intel_atomic_state *state,
1574 struct intel_crtc *crtc)
1576 const struct intel_crtc_state *new_crtc_state =
1577 intel_atomic_get_new_crtc_state(state, crtc);
1578 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1579 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
1580 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1581 bool psl_clkgate_wa;
1583 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1586 intel_dmc_enable_pipe(dev_priv, crtc->pipe);
1588 if (!new_crtc_state->bigjoiner_pipes) {
1589 intel_encoders_pre_pll_enable(state, crtc);
1591 if (new_crtc_state->shared_dpll)
1592 intel_enable_shared_dpll(new_crtc_state);
1594 intel_encoders_pre_enable(state, crtc);
1596 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
1599 intel_dsc_enable(new_crtc_state);
1601 if (DISPLAY_VER(dev_priv) >= 13)
1602 intel_uncompressed_joiner_enable(new_crtc_state);
1604 intel_set_pipe_src_size(new_crtc_state);
1605 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1606 bdw_set_pipe_misc(new_crtc_state);
1608 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) &&
1609 !transcoder_is_dsi(cpu_transcoder))
1610 hsw_configure_cpu_transcoder(new_crtc_state);
1612 crtc->active = true;
1614 /* Display WA #1180: WaDisableScalarClockGating: glk */
1615 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
1616 new_crtc_state->pch_pfit.enabled;
1618 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
1620 if (DISPLAY_VER(dev_priv) >= 9)
1621 skl_pfit_enable(new_crtc_state);
1623 ilk_pfit_enable(new_crtc_state);
1626 * On ILK+ LUT must be loaded before the pipe is running but with
1629 intel_color_load_luts(new_crtc_state);
1630 intel_color_commit_noarm(new_crtc_state);
1631 intel_color_commit_arm(new_crtc_state);
1632 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
1633 if (DISPLAY_VER(dev_priv) < 9)
1634 intel_disable_primary_plane(new_crtc_state);
1636 hsw_set_linetime_wm(new_crtc_state);
1638 if (DISPLAY_VER(dev_priv) >= 11)
1639 icl_set_pipe_chicken(new_crtc_state);
1641 intel_initial_watermarks(state, crtc);
1643 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
1644 intel_crtc_vblank_on(new_crtc_state);
1646 intel_encoders_enable(state, crtc);
1648 if (psl_clkgate_wa) {
1649 intel_crtc_wait_for_next_vblank(crtc);
1650 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
1653 /* If we change the relative order between pipe/planes enabling, we need
1654 * to change the workaround. */
1655 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
1656 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1657 struct intel_crtc *wa_crtc;
1659 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe);
1661 intel_crtc_wait_for_next_vblank(wa_crtc);
1662 intel_crtc_wait_for_next_vblank(wa_crtc);
1666 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1668 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1669 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1670 enum pipe pipe = crtc->pipe;
1672 /* To avoid upsetting the power well on haswell only disable the pfit if
1673 * it's in use. The hw state code will make sure we get this right. */
1674 if (!old_crtc_state->pch_pfit.enabled)
1677 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1678 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
1679 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
1682 static void ilk_crtc_disable(struct intel_atomic_state *state,
1683 struct intel_crtc *crtc)
1685 const struct intel_crtc_state *old_crtc_state =
1686 intel_atomic_get_old_crtc_state(state, crtc);
1687 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1688 enum pipe pipe = crtc->pipe;
1691 * Sometimes spurious CPU pipe underruns happen when the
1692 * pipe is already disabled, but FDI RX/TX is still enabled.
1693 * Happens at least with VGA+HDMI cloning. Suppress them.
1695 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1696 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1698 intel_encoders_disable(state, crtc);
1700 intel_crtc_vblank_off(old_crtc_state);
1702 intel_disable_transcoder(old_crtc_state);
1704 ilk_pfit_disable(old_crtc_state);
1706 if (old_crtc_state->has_pch_encoder)
1707 ilk_pch_disable(state, crtc);
1709 intel_encoders_post_disable(state, crtc);
1711 if (old_crtc_state->has_pch_encoder)
1712 ilk_pch_post_disable(state, crtc);
1714 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1715 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1717 intel_disable_shared_dpll(old_crtc_state);
1720 static void hsw_crtc_disable(struct intel_atomic_state *state,
1721 struct intel_crtc *crtc)
1723 const struct intel_crtc_state *old_crtc_state =
1724 intel_atomic_get_old_crtc_state(state, crtc);
1725 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1728 * FIXME collapse everything to one hook.
1729 * Need care with mst->ddi interactions.
1731 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1732 intel_encoders_disable(state, crtc);
1733 intel_encoders_post_disable(state, crtc);
1736 intel_disable_shared_dpll(old_crtc_state);
1738 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1739 struct intel_crtc *slave_crtc;
1741 intel_encoders_post_pll_disable(state, crtc);
1743 intel_dmc_disable_pipe(i915, crtc->pipe);
1745 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
1746 intel_crtc_bigjoiner_slave_pipes(old_crtc_state))
1747 intel_dmc_disable_pipe(i915, slave_crtc->pipe);
1751 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
1753 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1754 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1756 if (!crtc_state->gmch_pfit.control)
1760 * The panel fitter should only be adjusted whilst the pipe is disabled,
1761 * according to register description and PRM.
1763 drm_WARN_ON(&dev_priv->drm,
1764 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
1765 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1767 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
1768 crtc_state->gmch_pfit.pgm_ratios);
1769 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
1771 /* Border color in case we don't scale up to the full screen. Black by
1772 * default, change to something else for debugging. */
1773 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
1776 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
1778 if (phy == PHY_NONE)
1780 else if (IS_ALDERLAKE_S(dev_priv))
1781 return phy <= PHY_E;
1782 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
1783 return phy <= PHY_D;
1784 else if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv))
1785 return phy <= PHY_C;
1786 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
1787 return phy <= PHY_B;
1790 * DG2 outputs labelled as "combo PHY" in the bspec use
1791 * SNPS PHYs with completely different programming,
1792 * hence we always return false here.
1797 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
1799 if (IS_DG2(dev_priv))
1800 /* DG2's "TC1" output uses a SNPS PHY */
1802 else if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER_FULL(dev_priv) == IP_VER(14, 0))
1803 return phy >= PHY_F && phy <= PHY_I;
1804 else if (IS_TIGERLAKE(dev_priv))
1805 return phy >= PHY_D && phy <= PHY_I;
1806 else if (IS_ICELAKE(dev_priv))
1807 return phy >= PHY_C && phy <= PHY_F;
1812 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
1814 if (phy == PHY_NONE)
1816 else if (IS_DG2(dev_priv))
1818 * All four "combo" ports and the TC1 port (PHY E) use
1821 return phy <= PHY_E;
1826 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
1828 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
1829 return PHY_D + port - PORT_D_XELPD;
1830 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
1831 return PHY_F + port - PORT_TC1;
1832 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
1833 return PHY_B + port - PORT_TC1;
1834 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
1835 return PHY_C + port - PORT_TC1;
1836 else if ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) &&
1840 return PHY_A + port - PORT_A;
1843 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
1845 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
1846 return TC_PORT_NONE;
1848 if (DISPLAY_VER(dev_priv) >= 12)
1849 return TC_PORT_1 + port - PORT_TC1;
1851 return TC_PORT_1 + port - PORT_C;
1854 enum intel_display_power_domain
1855 intel_aux_power_domain(struct intel_digital_port *dig_port)
1857 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
1859 if (intel_tc_port_in_tbt_alt_mode(dig_port))
1860 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
1862 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
1865 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1866 struct intel_power_domain_mask *mask)
1868 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1869 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1870 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1871 struct drm_encoder *encoder;
1872 enum pipe pipe = crtc->pipe;
1874 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
1876 if (!crtc_state->hw.active)
1879 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
1880 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
1881 if (crtc_state->pch_pfit.enabled ||
1882 crtc_state->pch_pfit.force_thru)
1883 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
1885 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
1886 crtc_state->uapi.encoder_mask) {
1887 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1889 set_bit(intel_encoder->power_domain, mask->bits);
1892 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
1893 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
1895 if (crtc_state->shared_dpll)
1896 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
1898 if (crtc_state->dsc.compression_enable)
1899 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
1902 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1903 struct intel_power_domain_mask *old_domains)
1905 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1906 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1907 enum intel_display_power_domain domain;
1908 struct intel_power_domain_mask domains, new_domains;
1910 get_crtc_power_domains(crtc_state, &domains);
1912 bitmap_andnot(new_domains.bits,
1914 crtc->enabled_power_domains.mask.bits,
1916 bitmap_andnot(old_domains->bits,
1917 crtc->enabled_power_domains.mask.bits,
1921 for_each_power_domain(domain, &new_domains)
1922 intel_display_power_get_in_set(dev_priv,
1923 &crtc->enabled_power_domains,
1927 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
1928 struct intel_power_domain_mask *domains)
1930 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
1931 &crtc->enabled_power_domains,
1935 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1937 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1938 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1940 if (intel_crtc_has_dp_encoder(crtc_state)) {
1941 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1942 &crtc_state->dp_m_n);
1943 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1944 &crtc_state->dp_m2_n2);
1947 intel_set_transcoder_timings(crtc_state);
1949 i9xx_set_pipeconf(crtc_state);
1952 static void valleyview_crtc_enable(struct intel_atomic_state *state,
1953 struct intel_crtc *crtc)
1955 const struct intel_crtc_state *new_crtc_state =
1956 intel_atomic_get_new_crtc_state(state, crtc);
1957 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1958 enum pipe pipe = crtc->pipe;
1960 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1963 i9xx_configure_cpu_transcoder(new_crtc_state);
1965 intel_set_pipe_src_size(new_crtc_state);
1967 intel_de_write(dev_priv, VLV_PIPE_MSA_MISC(pipe), 0);
1969 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1970 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
1971 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
1974 crtc->active = true;
1976 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1978 intel_encoders_pre_pll_enable(state, crtc);
1980 if (IS_CHERRYVIEW(dev_priv))
1981 chv_enable_pll(new_crtc_state);
1983 vlv_enable_pll(new_crtc_state);
1985 intel_encoders_pre_enable(state, crtc);
1987 i9xx_pfit_enable(new_crtc_state);
1989 intel_color_load_luts(new_crtc_state);
1990 intel_color_commit_noarm(new_crtc_state);
1991 intel_color_commit_arm(new_crtc_state);
1992 /* update DSPCNTR to configure gamma for pipe bottom color */
1993 intel_disable_primary_plane(new_crtc_state);
1995 intel_initial_watermarks(state, crtc);
1996 intel_enable_transcoder(new_crtc_state);
1998 intel_crtc_vblank_on(new_crtc_state);
2000 intel_encoders_enable(state, crtc);
2003 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2004 struct intel_crtc *crtc)
2006 const struct intel_crtc_state *new_crtc_state =
2007 intel_atomic_get_new_crtc_state(state, crtc);
2008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2009 enum pipe pipe = crtc->pipe;
2011 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2014 i9xx_configure_cpu_transcoder(new_crtc_state);
2016 intel_set_pipe_src_size(new_crtc_state);
2018 crtc->active = true;
2020 if (DISPLAY_VER(dev_priv) != 2)
2021 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2023 intel_encoders_pre_enable(state, crtc);
2025 i9xx_enable_pll(new_crtc_state);
2027 i9xx_pfit_enable(new_crtc_state);
2029 intel_color_load_luts(new_crtc_state);
2030 intel_color_commit_noarm(new_crtc_state);
2031 intel_color_commit_arm(new_crtc_state);
2032 /* update DSPCNTR to configure gamma for pipe bottom color */
2033 intel_disable_primary_plane(new_crtc_state);
2035 if (!intel_initial_watermarks(state, crtc))
2036 intel_update_watermarks(dev_priv);
2037 intel_enable_transcoder(new_crtc_state);
2039 intel_crtc_vblank_on(new_crtc_state);
2041 intel_encoders_enable(state, crtc);
2043 /* prevents spurious underruns */
2044 if (DISPLAY_VER(dev_priv) == 2)
2045 intel_crtc_wait_for_next_vblank(crtc);
2048 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2050 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2051 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2053 if (!old_crtc_state->gmch_pfit.control)
2056 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2058 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2059 intel_de_read(dev_priv, PFIT_CONTROL));
2060 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2063 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2064 struct intel_crtc *crtc)
2066 struct intel_crtc_state *old_crtc_state =
2067 intel_atomic_get_old_crtc_state(state, crtc);
2068 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2069 enum pipe pipe = crtc->pipe;
2072 * On gen2 planes are double buffered but the pipe isn't, so we must
2073 * wait for planes to fully turn off before disabling the pipe.
2075 if (DISPLAY_VER(dev_priv) == 2)
2076 intel_crtc_wait_for_next_vblank(crtc);
2078 intel_encoders_disable(state, crtc);
2080 intel_crtc_vblank_off(old_crtc_state);
2082 intel_disable_transcoder(old_crtc_state);
2084 i9xx_pfit_disable(old_crtc_state);
2086 intel_encoders_post_disable(state, crtc);
2088 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2089 if (IS_CHERRYVIEW(dev_priv))
2090 chv_disable_pll(dev_priv, pipe);
2091 else if (IS_VALLEYVIEW(dev_priv))
2092 vlv_disable_pll(dev_priv, pipe);
2094 i9xx_disable_pll(old_crtc_state);
2097 intel_encoders_post_pll_disable(state, crtc);
2099 if (DISPLAY_VER(dev_priv) != 2)
2100 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2102 if (!dev_priv->display.funcs.wm->initial_watermarks)
2103 intel_update_watermarks(dev_priv);
2105 /* clock the pipe down to 640x480@60 to potentially save power */
2106 if (IS_I830(dev_priv))
2107 i830_enable_pipe(dev_priv, pipe);
2110 void intel_encoder_destroy(struct drm_encoder *encoder)
2112 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2114 drm_encoder_cleanup(encoder);
2115 kfree(intel_encoder);
2118 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2120 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2122 /* GDG double wide on either pipe, otherwise pipe A only */
2123 return DISPLAY_VER(dev_priv) < 4 &&
2124 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2127 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2129 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2130 struct drm_rect src;
2133 * We only use IF-ID interlacing. If we ever use
2134 * PF-ID we'll need to adjust the pixel_rate here.
2137 if (!crtc_state->pch_pfit.enabled)
2140 drm_rect_init(&src, 0, 0,
2141 drm_rect_width(&crtc_state->pipe_src) << 16,
2142 drm_rect_height(&crtc_state->pipe_src) << 16);
2144 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2148 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2149 const struct drm_display_mode *timings)
2151 mode->hdisplay = timings->crtc_hdisplay;
2152 mode->htotal = timings->crtc_htotal;
2153 mode->hsync_start = timings->crtc_hsync_start;
2154 mode->hsync_end = timings->crtc_hsync_end;
2156 mode->vdisplay = timings->crtc_vdisplay;
2157 mode->vtotal = timings->crtc_vtotal;
2158 mode->vsync_start = timings->crtc_vsync_start;
2159 mode->vsync_end = timings->crtc_vsync_end;
2161 mode->flags = timings->flags;
2162 mode->type = DRM_MODE_TYPE_DRIVER;
2164 mode->clock = timings->crtc_clock;
2166 drm_mode_set_name(mode);
2169 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2171 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2173 if (HAS_GMCH(dev_priv))
2174 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2175 crtc_state->pixel_rate =
2176 crtc_state->hw.pipe_mode.crtc_clock;
2178 crtc_state->pixel_rate =
2179 ilk_pipe_pixel_rate(crtc_state);
2182 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2183 struct drm_display_mode *mode)
2185 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2190 mode->crtc_clock /= num_pipes;
2191 mode->crtc_hdisplay /= num_pipes;
2192 mode->crtc_hblank_start /= num_pipes;
2193 mode->crtc_hblank_end /= num_pipes;
2194 mode->crtc_hsync_start /= num_pipes;
2195 mode->crtc_hsync_end /= num_pipes;
2196 mode->crtc_htotal /= num_pipes;
2199 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2200 struct drm_display_mode *mode)
2202 int overlap = crtc_state->splitter.pixel_overlap;
2203 int n = crtc_state->splitter.link_count;
2205 if (!crtc_state->splitter.enable)
2209 * eDP MSO uses segment timings from EDID for transcoder
2210 * timings, but full mode for everything else.
2212 * h_full = (h_segment - pixel_overlap) * link_count
2214 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2215 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2216 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2217 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2218 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2219 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2220 mode->crtc_clock *= n;
2223 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2225 struct drm_display_mode *mode = &crtc_state->hw.mode;
2226 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2227 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2230 * Start with the adjusted_mode crtc timings, which
2231 * have been filled with the transcoder timings.
2233 drm_mode_copy(pipe_mode, adjusted_mode);
2235 /* Expand MSO per-segment transcoder timings to full */
2236 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2239 * We want the full numbers in adjusted_mode normal timings,
2240 * adjusted_mode crtc timings are left with the raw transcoder
2243 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2245 /* Populate the "user" mode with full numbers */
2246 drm_mode_copy(mode, pipe_mode);
2247 intel_mode_from_crtc_timings(mode, mode);
2248 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2249 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2250 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2252 /* Derive per-pipe timings in case bigjoiner is used */
2253 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2254 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2256 intel_crtc_compute_pixel_rate(crtc_state);
2259 void intel_encoder_get_config(struct intel_encoder *encoder,
2260 struct intel_crtc_state *crtc_state)
2262 encoder->get_config(encoder, crtc_state);
2264 intel_crtc_readout_derived_state(crtc_state);
2267 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2269 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2275 width = drm_rect_width(&crtc_state->pipe_src);
2276 height = drm_rect_height(&crtc_state->pipe_src);
2278 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2279 width / num_pipes, height);
2282 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2284 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2285 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2287 intel_bigjoiner_compute_pipe_src(crtc_state);
2290 * Pipe horizontal size must be even in:
2292 * - LVDS dual channel mode
2293 * - Double wide pipe
2295 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2296 if (crtc_state->double_wide) {
2297 drm_dbg_kms(&i915->drm,
2298 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2299 crtc->base.base.id, crtc->base.name);
2303 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2304 intel_is_dual_link_lvds(i915)) {
2305 drm_dbg_kms(&i915->drm,
2306 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2307 crtc->base.base.id, crtc->base.name);
2315 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2317 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2318 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2319 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2320 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2321 int clock_limit = i915->max_dotclk_freq;
2324 * Start with the adjusted_mode crtc timings, which
2325 * have been filled with the transcoder timings.
2327 drm_mode_copy(pipe_mode, adjusted_mode);
2329 /* Expand MSO per-segment transcoder timings to full */
2330 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2332 /* Derive per-pipe timings in case bigjoiner is used */
2333 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2334 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2336 if (DISPLAY_VER(i915) < 4) {
2337 clock_limit = i915->display.cdclk.max_cdclk_freq * 9 / 10;
2340 * Enable double wide mode when the dot clock
2341 * is > 90% of the (display) core speed.
2343 if (intel_crtc_supports_double_wide(crtc) &&
2344 pipe_mode->crtc_clock > clock_limit) {
2345 clock_limit = i915->max_dotclk_freq;
2346 crtc_state->double_wide = true;
2350 if (pipe_mode->crtc_clock > clock_limit) {
2351 drm_dbg_kms(&i915->drm,
2352 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2353 crtc->base.base.id, crtc->base.name,
2354 pipe_mode->crtc_clock, clock_limit,
2355 str_yes_no(crtc_state->double_wide));
2362 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2363 struct intel_crtc *crtc)
2365 struct intel_crtc_state *crtc_state =
2366 intel_atomic_get_new_crtc_state(state, crtc);
2369 ret = intel_dpll_crtc_compute_clock(state, crtc);
2373 ret = intel_crtc_compute_pipe_src(crtc_state);
2377 ret = intel_crtc_compute_pipe_mode(crtc_state);
2381 intel_crtc_compute_pixel_rate(crtc_state);
2383 if (crtc_state->has_pch_encoder)
2384 return ilk_fdi_compute_config(crtc, crtc_state);
2390 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2392 while (*num > DATA_LINK_M_N_MASK ||
2393 *den > DATA_LINK_M_N_MASK) {
2399 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2400 u32 m, u32 n, u32 constant_n)
2403 *ret_n = constant_n;
2405 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2407 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2408 intel_reduce_m_n_ratio(ret_m, ret_n);
2412 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
2413 int pixel_clock, int link_clock,
2414 struct intel_link_m_n *m_n,
2417 u32 data_clock = bits_per_pixel * pixel_clock;
2420 data_clock = intel_dp_mode_to_fec_clock(data_clock);
2423 * Windows/BIOS uses fixed M/N values always. Follow suit.
2425 * Also several DP dongles in particular seem to be fussy
2426 * about too large link M/N values. Presumably the 20bit
2427 * value used by Windows/BIOS is acceptable to everyone.
2430 compute_m_n(&m_n->data_m, &m_n->data_n,
2431 data_clock, link_clock * nlanes * 8,
2434 compute_m_n(&m_n->link_m, &m_n->link_n,
2435 pixel_clock, link_clock,
2439 void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2442 * There may be no VBT; and if the BIOS enabled SSC we can
2443 * just keep using it to avoid unnecessary flicker. Whereas if the
2444 * BIOS isn't using it, don't assume it will work even if the VBT
2445 * indicates as much.
2447 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2448 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2452 if (dev_priv->display.vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2453 drm_dbg_kms(&dev_priv->drm,
2454 "SSC %s by BIOS, overriding VBT which says %s\n",
2455 str_enabled_disabled(bios_lvds_use_ssc),
2456 str_enabled_disabled(dev_priv->display.vbt.lvds_use_ssc));
2457 dev_priv->display.vbt.lvds_use_ssc = bios_lvds_use_ssc;
2462 void intel_zero_m_n(struct intel_link_m_n *m_n)
2464 /* corresponds to 0 register value */
2465 memset(m_n, 0, sizeof(*m_n));
2469 void intel_set_m_n(struct drm_i915_private *i915,
2470 const struct intel_link_m_n *m_n,
2471 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2472 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2474 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2475 intel_de_write(i915, data_n_reg, m_n->data_n);
2476 intel_de_write(i915, link_m_reg, m_n->link_m);
2478 * On BDW+ writing LINK_N arms the double buffered update
2479 * of all the M/N registers, so it must be written last.
2481 intel_de_write(i915, link_n_reg, m_n->link_n);
2484 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2485 enum transcoder transcoder)
2487 if (IS_HASWELL(dev_priv))
2488 return transcoder == TRANSCODER_EDP;
2490 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2493 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2494 enum transcoder transcoder,
2495 const struct intel_link_m_n *m_n)
2497 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2498 enum pipe pipe = crtc->pipe;
2500 if (DISPLAY_VER(dev_priv) >= 5)
2501 intel_set_m_n(dev_priv, m_n,
2502 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2503 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2505 intel_set_m_n(dev_priv, m_n,
2506 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2507 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2510 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2511 enum transcoder transcoder,
2512 const struct intel_link_m_n *m_n)
2514 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2516 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2519 intel_set_m_n(dev_priv, m_n,
2520 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2521 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2524 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2526 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2527 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2528 enum pipe pipe = crtc->pipe;
2529 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2530 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2531 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2534 /* We need to be careful not to changed the adjusted mode, for otherwise
2535 * the hw state checker will get angry at the mismatch. */
2536 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2537 crtc_vtotal = adjusted_mode->crtc_vtotal;
2538 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2539 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2541 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2542 /* the chip adds 2 halflines automatically */
2544 crtc_vblank_end -= 1;
2546 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2547 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2549 vsyncshift = adjusted_mode->crtc_hsync_start -
2550 adjusted_mode->crtc_htotal / 2;
2552 vsyncshift += adjusted_mode->crtc_htotal;
2556 * VBLANK_START no longer works on ADL+, instead we must use
2557 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2559 if (DISPLAY_VER(dev_priv) >= 13) {
2560 intel_de_write(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder),
2561 crtc_vblank_start - crtc_vdisplay);
2564 * VBLANK_START not used by hw, just clear it
2565 * to make it stand out in register dumps.
2567 crtc_vblank_start = 1;
2570 if (DISPLAY_VER(dev_priv) > 3)
2571 intel_de_write(dev_priv, TRANS_VSYNCSHIFT(cpu_transcoder),
2574 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
2575 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2576 HTOTAL(adjusted_mode->crtc_htotal - 1));
2577 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
2578 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2579 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2580 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
2581 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2582 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2584 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2585 VACTIVE(crtc_vdisplay - 1) |
2586 VTOTAL(crtc_vtotal - 1));
2587 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2588 VBLANK_START(crtc_vblank_start - 1) |
2589 VBLANK_END(crtc_vblank_end - 1));
2590 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
2591 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2592 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2594 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2595 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2596 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2598 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2599 (pipe == PIPE_B || pipe == PIPE_C))
2600 intel_de_write(dev_priv, TRANS_VTOTAL(pipe),
2601 VACTIVE(crtc_vdisplay - 1) |
2602 VTOTAL(crtc_vtotal - 1));
2605 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state)
2607 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2608 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2609 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2610 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2611 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2613 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2614 crtc_vtotal = adjusted_mode->crtc_vtotal;
2615 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2616 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2618 drm_WARN_ON(&dev_priv->drm, adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE);
2621 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode.
2622 * But let's write it anyway to keep the state checker happy.
2624 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2625 VBLANK_START(crtc_vblank_start - 1) |
2626 VBLANK_END(crtc_vblank_end - 1));
2628 * The double buffer latch point for TRANS_VTOTAL
2629 * is the transcoder's undelayed vblank.
2631 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2632 VACTIVE(crtc_vdisplay - 1) |
2633 VTOTAL(crtc_vtotal - 1));
2636 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2638 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2639 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2640 int width = drm_rect_width(&crtc_state->pipe_src);
2641 int height = drm_rect_height(&crtc_state->pipe_src);
2642 enum pipe pipe = crtc->pipe;
2644 /* pipesrc controls the size that is scaled from, which should
2645 * always be the user's requested size.
2647 intel_de_write(dev_priv, PIPESRC(pipe),
2648 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2651 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2653 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2654 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2656 if (DISPLAY_VER(dev_priv) == 2)
2659 if (DISPLAY_VER(dev_priv) >= 9 ||
2660 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2661 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2663 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2666 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2667 struct intel_crtc_state *pipe_config)
2669 struct drm_device *dev = crtc->base.dev;
2670 struct drm_i915_private *dev_priv = to_i915(dev);
2671 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2672 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2675 tmp = intel_de_read(dev_priv, TRANS_HTOTAL(cpu_transcoder));
2676 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2677 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2679 if (!transcoder_is_dsi(cpu_transcoder)) {
2680 tmp = intel_de_read(dev_priv, TRANS_HBLANK(cpu_transcoder));
2681 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2682 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2685 tmp = intel_de_read(dev_priv, TRANS_HSYNC(cpu_transcoder));
2686 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2687 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2689 tmp = intel_de_read(dev_priv, TRANS_VTOTAL(cpu_transcoder));
2690 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2691 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2693 /* FIXME TGL+ DSI transcoders have this! */
2694 if (!transcoder_is_dsi(cpu_transcoder)) {
2695 tmp = intel_de_read(dev_priv, TRANS_VBLANK(cpu_transcoder));
2696 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2697 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2699 tmp = intel_de_read(dev_priv, TRANS_VSYNC(cpu_transcoder));
2700 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2701 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2703 if (intel_pipe_is_interlaced(pipe_config)) {
2704 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2705 adjusted_mode->crtc_vtotal += 1;
2706 adjusted_mode->crtc_vblank_end += 1;
2709 if (DISPLAY_VER(dev_priv) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2710 adjusted_mode->crtc_vblank_start =
2711 adjusted_mode->crtc_vdisplay +
2712 intel_de_read(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder));
2715 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2717 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2718 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2719 enum pipe master_pipe, pipe = crtc->pipe;
2725 master_pipe = bigjoiner_master_pipe(crtc_state);
2726 width = drm_rect_width(&crtc_state->pipe_src);
2728 drm_rect_translate_to(&crtc_state->pipe_src,
2729 (pipe - master_pipe) * width, 0);
2732 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2733 struct intel_crtc_state *pipe_config)
2735 struct drm_device *dev = crtc->base.dev;
2736 struct drm_i915_private *dev_priv = to_i915(dev);
2739 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
2741 drm_rect_init(&pipe_config->pipe_src, 0, 0,
2742 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
2743 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
2745 intel_bigjoiner_adjust_pipe_src(pipe_config);
2748 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
2750 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2751 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2752 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2756 * - We keep both pipes enabled on 830
2757 * - During modeset the pipe is still disabled and must remain so
2758 * - During fastset the pipe is already enabled and must remain so
2760 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
2761 val |= TRANSCONF_ENABLE;
2763 if (crtc_state->double_wide)
2764 val |= TRANSCONF_DOUBLE_WIDE;
2766 /* only g4x and later have fancy bpc/dither controls */
2767 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2768 IS_CHERRYVIEW(dev_priv)) {
2769 /* Bspec claims that we can't use dithering for 30bpp pipes. */
2770 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
2771 val |= TRANSCONF_DITHER_EN |
2772 TRANSCONF_DITHER_TYPE_SP;
2774 switch (crtc_state->pipe_bpp) {
2776 /* Case prevented by intel_choose_pipe_bpp_dither. */
2777 MISSING_CASE(crtc_state->pipe_bpp);
2780 val |= TRANSCONF_BPC_6;
2783 val |= TRANSCONF_BPC_8;
2786 val |= TRANSCONF_BPC_10;
2791 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
2792 if (DISPLAY_VER(dev_priv) < 4 ||
2793 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2794 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
2796 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
2798 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
2801 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2802 crtc_state->limited_color_range)
2803 val |= TRANSCONF_COLOR_RANGE_SELECT;
2805 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
2807 if (crtc_state->wgc_enable)
2808 val |= TRANSCONF_WGC_ENABLE;
2810 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
2812 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
2813 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
2816 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
2818 if (IS_I830(dev_priv))
2821 return DISPLAY_VER(dev_priv) >= 4 ||
2822 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
2825 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
2827 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2828 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2832 if (!i9xx_has_pfit(dev_priv))
2835 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
2836 if (!(tmp & PFIT_ENABLE))
2839 /* Check whether the pfit is attached to our pipe. */
2840 if (DISPLAY_VER(dev_priv) >= 4)
2841 pipe = REG_FIELD_GET(PFIT_PIPE_MASK, tmp);
2845 if (pipe != crtc->pipe)
2848 crtc_state->gmch_pfit.control = tmp;
2849 crtc_state->gmch_pfit.pgm_ratios =
2850 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
2853 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
2854 struct intel_crtc_state *pipe_config)
2856 struct drm_device *dev = crtc->base.dev;
2857 struct drm_i915_private *dev_priv = to_i915(dev);
2858 enum pipe pipe = crtc->pipe;
2861 int refclk = 100000;
2863 /* In case of DSI, DPLL will not be used */
2864 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
2867 vlv_dpio_get(dev_priv);
2868 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
2869 vlv_dpio_put(dev_priv);
2871 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
2872 clock.m2 = mdiv & DPIO_M2DIV_MASK;
2873 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
2874 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
2875 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
2877 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
2880 static void chv_crtc_clock_get(struct intel_crtc *crtc,
2881 struct intel_crtc_state *pipe_config)
2883 struct drm_device *dev = crtc->base.dev;
2884 struct drm_i915_private *dev_priv = to_i915(dev);
2885 enum pipe pipe = crtc->pipe;
2886 enum dpio_channel port = vlv_pipe_to_channel(pipe);
2888 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
2889 int refclk = 100000;
2891 /* In case of DSI, DPLL will not be used */
2892 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
2895 vlv_dpio_get(dev_priv);
2896 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
2897 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
2898 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
2899 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
2900 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
2901 vlv_dpio_put(dev_priv);
2903 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
2904 clock.m2 = (pll_dw0 & 0xff) << 22;
2905 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
2906 clock.m2 |= pll_dw2 & 0x3fffff;
2907 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
2908 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
2909 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
2911 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
2914 static enum intel_output_format
2915 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
2917 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2920 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
2922 if (tmp & PIPE_MISC_YUV420_ENABLE) {
2923 /* We support 4:2:0 in full blend mode only */
2924 drm_WARN_ON(&dev_priv->drm,
2925 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
2927 return INTEL_OUTPUT_FORMAT_YCBCR420;
2928 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
2929 return INTEL_OUTPUT_FORMAT_YCBCR444;
2931 return INTEL_OUTPUT_FORMAT_RGB;
2935 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
2936 struct intel_crtc_state *pipe_config)
2938 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2939 enum intel_display_power_domain power_domain;
2940 intel_wakeref_t wakeref;
2944 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
2945 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
2949 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2950 pipe_config->sink_format = pipe_config->output_format;
2951 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
2952 pipe_config->shared_dpll = NULL;
2956 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
2957 if (!(tmp & TRANSCONF_ENABLE))
2960 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2961 IS_CHERRYVIEW(dev_priv)) {
2962 switch (tmp & TRANSCONF_BPC_MASK) {
2963 case TRANSCONF_BPC_6:
2964 pipe_config->pipe_bpp = 18;
2966 case TRANSCONF_BPC_8:
2967 pipe_config->pipe_bpp = 24;
2969 case TRANSCONF_BPC_10:
2970 pipe_config->pipe_bpp = 30;
2978 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2979 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
2980 pipe_config->limited_color_range = true;
2982 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
2984 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
2986 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2987 (tmp & TRANSCONF_WGC_ENABLE))
2988 pipe_config->wgc_enable = true;
2990 intel_color_get_config(pipe_config);
2992 if (DISPLAY_VER(dev_priv) < 4)
2993 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
2995 intel_get_transcoder_timings(crtc, pipe_config);
2996 intel_get_pipe_src_size(crtc, pipe_config);
2998 i9xx_get_pfit_config(pipe_config);
3000 if (DISPLAY_VER(dev_priv) >= 4) {
3001 /* No way to read it out on pipes B and C */
3002 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
3003 tmp = dev_priv->display.state.chv_dpll_md[crtc->pipe];
3005 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
3006 pipe_config->pixel_multiplier =
3007 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3008 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3009 pipe_config->dpll_hw_state.dpll_md = tmp;
3010 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
3011 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
3012 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
3013 pipe_config->pixel_multiplier =
3014 ((tmp & SDVO_MULTIPLIER_MASK)
3015 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3017 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3018 * port and will be fixed up in the encoder->get_config
3020 pipe_config->pixel_multiplier = 1;
3022 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
3024 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
3025 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
3027 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
3030 /* Mask out read-only status bits. */
3031 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
3032 DPLL_PORTC_READY_MASK |
3033 DPLL_PORTB_READY_MASK);
3036 if (IS_CHERRYVIEW(dev_priv))
3037 chv_crtc_clock_get(crtc, pipe_config);
3038 else if (IS_VALLEYVIEW(dev_priv))
3039 vlv_crtc_clock_get(crtc, pipe_config);
3041 i9xx_crtc_clock_get(crtc, pipe_config);
3044 * Normally the dotclock is filled in by the encoder .get_config()
3045 * but in case the pipe is enabled w/o any ports we need a sane
3048 pipe_config->hw.adjusted_mode.crtc_clock =
3049 pipe_config->port_clock / pipe_config->pixel_multiplier;
3054 intel_display_power_put(dev_priv, power_domain, wakeref);
3059 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3061 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3062 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3063 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3067 * - During modeset the pipe is still disabled and must remain so
3068 * - During fastset the pipe is already enabled and must remain so
3070 if (!intel_crtc_needs_modeset(crtc_state))
3071 val |= TRANSCONF_ENABLE;
3073 switch (crtc_state->pipe_bpp) {
3075 /* Case prevented by intel_choose_pipe_bpp_dither. */
3076 MISSING_CASE(crtc_state->pipe_bpp);
3079 val |= TRANSCONF_BPC_6;
3082 val |= TRANSCONF_BPC_8;
3085 val |= TRANSCONF_BPC_10;
3088 val |= TRANSCONF_BPC_12;
3092 if (crtc_state->dither)
3093 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3095 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3096 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3098 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3101 * This would end up with an odd purple hue over
3102 * the entire display. Make sure we don't do it.
3104 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3105 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3107 if (crtc_state->limited_color_range &&
3108 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3109 val |= TRANSCONF_COLOR_RANGE_SELECT;
3111 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3112 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3114 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3116 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3117 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3119 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3120 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3123 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3125 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3126 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3127 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3131 * - During modeset the pipe is still disabled and must remain so
3132 * - During fastset the pipe is already enabled and must remain so
3134 if (!intel_crtc_needs_modeset(crtc_state))
3135 val |= TRANSCONF_ENABLE;
3137 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3138 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3140 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3141 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3143 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3145 if (IS_HASWELL(dev_priv) &&
3146 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3147 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3149 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3150 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3153 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state)
3155 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3156 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3159 switch (crtc_state->pipe_bpp) {
3161 val |= PIPE_MISC_BPC_6;
3164 val |= PIPE_MISC_BPC_8;
3167 val |= PIPE_MISC_BPC_10;
3170 /* Port output 12BPC defined for ADLP+ */
3171 if (DISPLAY_VER(dev_priv) > 12)
3172 val |= PIPE_MISC_BPC_12_ADLP;
3175 MISSING_CASE(crtc_state->pipe_bpp);
3179 if (crtc_state->dither)
3180 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3182 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3183 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3184 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3186 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3187 val |= PIPE_MISC_YUV420_ENABLE |
3188 PIPE_MISC_YUV420_MODE_FULL_BLEND;
3190 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3191 val |= PIPE_MISC_HDR_MODE_PRECISION;
3193 if (DISPLAY_VER(dev_priv) >= 12)
3194 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3196 /* allow PSR with sprite enabled */
3197 if (IS_BROADWELL(dev_priv))
3198 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE;
3200 intel_de_write(dev_priv, PIPE_MISC(crtc->pipe), val);
3203 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3205 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3208 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3210 switch (tmp & PIPE_MISC_BPC_MASK) {
3211 case PIPE_MISC_BPC_6:
3213 case PIPE_MISC_BPC_8:
3215 case PIPE_MISC_BPC_10:
3218 * PORT OUTPUT 12 BPC defined for ADLP+.
3221 * For previous platforms with DSI interface, bits 5:7
3222 * are used for storing pipe_bpp irrespective of dithering.
3223 * Since the value of 12 BPC is not defined for these bits
3224 * on older platforms, need to find a workaround for 12 BPC
3225 * MIPI DSI HW readout.
3227 case PIPE_MISC_BPC_12_ADLP:
3228 if (DISPLAY_VER(dev_priv) > 12)
3237 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3240 * Account for spread spectrum to avoid
3241 * oversubscribing the link. Max center spread
3242 * is 2.5%; use 5% for safety's sake.
3244 u32 bps = target_clock * bpp * 21 / 20;
3245 return DIV_ROUND_UP(bps, link_bw * 8);
3248 void intel_get_m_n(struct drm_i915_private *i915,
3249 struct intel_link_m_n *m_n,
3250 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3251 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3253 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3254 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3255 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3256 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3257 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3260 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3261 enum transcoder transcoder,
3262 struct intel_link_m_n *m_n)
3264 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3265 enum pipe pipe = crtc->pipe;
3267 if (DISPLAY_VER(dev_priv) >= 5)
3268 intel_get_m_n(dev_priv, m_n,
3269 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3270 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3272 intel_get_m_n(dev_priv, m_n,
3273 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3274 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3277 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3278 enum transcoder transcoder,
3279 struct intel_link_m_n *m_n)
3281 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3283 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3286 intel_get_m_n(dev_priv, m_n,
3287 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3288 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3291 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3293 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3294 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3298 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3299 if ((ctl & PF_ENABLE) == 0)
3302 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
3303 pipe = REG_FIELD_GET(PF_PIPE_SEL_MASK_IVB, ctl);
3307 crtc_state->pch_pfit.enabled = true;
3309 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3310 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3312 drm_rect_init(&crtc_state->pch_pfit.dst,
3313 REG_FIELD_GET(PF_WIN_XPOS_MASK, pos),
3314 REG_FIELD_GET(PF_WIN_YPOS_MASK, pos),
3315 REG_FIELD_GET(PF_WIN_XSIZE_MASK, size),
3316 REG_FIELD_GET(PF_WIN_YSIZE_MASK, size));
3319 * We currently do not free assignements of panel fitters on
3320 * ivb/hsw (since we don't use the higher upscaling modes which
3321 * differentiates them) so just WARN about this case for now.
3323 drm_WARN_ON(&dev_priv->drm, pipe != crtc->pipe);
3326 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3327 struct intel_crtc_state *pipe_config)
3329 struct drm_device *dev = crtc->base.dev;
3330 struct drm_i915_private *dev_priv = to_i915(dev);
3331 enum intel_display_power_domain power_domain;
3332 intel_wakeref_t wakeref;
3336 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3337 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3341 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3342 pipe_config->shared_dpll = NULL;
3345 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3346 if (!(tmp & TRANSCONF_ENABLE))
3349 switch (tmp & TRANSCONF_BPC_MASK) {
3350 case TRANSCONF_BPC_6:
3351 pipe_config->pipe_bpp = 18;
3353 case TRANSCONF_BPC_8:
3354 pipe_config->pipe_bpp = 24;
3356 case TRANSCONF_BPC_10:
3357 pipe_config->pipe_bpp = 30;
3359 case TRANSCONF_BPC_12:
3360 pipe_config->pipe_bpp = 36;
3366 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3367 pipe_config->limited_color_range = true;
3369 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3370 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3371 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3372 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3375 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3379 pipe_config->sink_format = pipe_config->output_format;
3381 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3383 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3385 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3387 intel_color_get_config(pipe_config);
3389 pipe_config->pixel_multiplier = 1;
3391 ilk_pch_get_config(pipe_config);
3393 intel_get_transcoder_timings(crtc, pipe_config);
3394 intel_get_pipe_src_size(crtc, pipe_config);
3396 ilk_get_pfit_config(pipe_config);
3401 intel_display_power_put(dev_priv, power_domain, wakeref);
3406 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3410 if (DISPLAY_VER(i915) >= 12)
3411 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3412 else if (DISPLAY_VER(i915) >= 11)
3413 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3417 return pipes & DISPLAY_RUNTIME_INFO(i915)->pipe_mask;
3420 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3421 enum transcoder cpu_transcoder)
3423 enum intel_display_power_domain power_domain;
3424 intel_wakeref_t wakeref;
3427 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3429 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3430 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3432 return tmp & TRANS_DDI_FUNC_ENABLE;
3435 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3436 u8 *master_pipes, u8 *slave_pipes)
3438 struct intel_crtc *crtc;
3443 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3444 bigjoiner_pipes(dev_priv)) {
3445 enum intel_display_power_domain power_domain;
3446 enum pipe pipe = crtc->pipe;
3447 intel_wakeref_t wakeref;
3449 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3450 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3451 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3453 if (!(tmp & BIG_JOINER_ENABLE))
3456 if (tmp & MASTER_BIG_JOINER_ENABLE)
3457 *master_pipes |= BIT(pipe);
3459 *slave_pipes |= BIT(pipe);
3462 if (DISPLAY_VER(dev_priv) < 13)
3465 power_domain = POWER_DOMAIN_PIPE(pipe);
3466 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3467 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3469 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3470 *master_pipes |= BIT(pipe);
3471 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3472 *slave_pipes |= BIT(pipe);
3476 /* Bigjoiner pipes should always be consecutive master and slave */
3477 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3478 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3479 *master_pipes, *slave_pipes);
3482 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3484 if ((slave_pipes & BIT(pipe)) == 0)
3487 /* ignore everything above our pipe */
3488 master_pipes &= ~GENMASK(7, pipe);
3490 /* highest remaining bit should be our master pipe */
3491 return fls(master_pipes) - 1;
3494 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3496 enum pipe master_pipe, next_master_pipe;
3498 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3500 if ((master_pipes & BIT(master_pipe)) == 0)
3503 /* ignore our master pipe and everything below it */
3504 master_pipes &= ~GENMASK(master_pipe, 0);
3505 /* make sure a high bit is set for the ffs() */
3506 master_pipes |= BIT(7);
3507 /* lowest remaining bit should be the next master pipe */
3508 next_master_pipe = ffs(master_pipes) - 1;
3510 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3513 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3515 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3517 if (DISPLAY_VER(i915) >= 11)
3518 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3520 return panel_transcoder_mask;
3523 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3525 struct drm_device *dev = crtc->base.dev;
3526 struct drm_i915_private *dev_priv = to_i915(dev);
3527 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3528 enum transcoder cpu_transcoder;
3529 u8 master_pipes, slave_pipes;
3530 u8 enabled_transcoders = 0;
3533 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3534 * consistency and less surprising code; it's in always on power).
3536 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3537 panel_transcoder_mask) {
3538 enum intel_display_power_domain power_domain;
3539 intel_wakeref_t wakeref;
3540 enum pipe trans_pipe;
3543 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3544 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3545 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3547 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3550 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3553 "unknown pipe linked to transcoder %s\n",
3554 transcoder_name(cpu_transcoder));
3556 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3557 case TRANS_DDI_EDP_INPUT_A_ON:
3558 trans_pipe = PIPE_A;
3560 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3561 trans_pipe = PIPE_B;
3563 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3564 trans_pipe = PIPE_C;
3566 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3567 trans_pipe = PIPE_D;
3571 if (trans_pipe == crtc->pipe)
3572 enabled_transcoders |= BIT(cpu_transcoder);
3575 /* single pipe or bigjoiner master */
3576 cpu_transcoder = (enum transcoder) crtc->pipe;
3577 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3578 enabled_transcoders |= BIT(cpu_transcoder);
3580 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3581 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3582 if (slave_pipes & BIT(crtc->pipe)) {
3583 cpu_transcoder = (enum transcoder)
3584 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3585 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3586 enabled_transcoders |= BIT(cpu_transcoder);
3589 return enabled_transcoders;
3592 static bool has_edp_transcoders(u8 enabled_transcoders)
3594 return enabled_transcoders & BIT(TRANSCODER_EDP);
3597 static bool has_dsi_transcoders(u8 enabled_transcoders)
3599 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3600 BIT(TRANSCODER_DSI_1));
3603 static bool has_pipe_transcoders(u8 enabled_transcoders)
3605 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3606 BIT(TRANSCODER_DSI_0) |
3607 BIT(TRANSCODER_DSI_1));
3610 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3611 u8 enabled_transcoders)
3613 /* Only one type of transcoder please */
3614 drm_WARN_ON(&i915->drm,
3615 has_edp_transcoders(enabled_transcoders) +
3616 has_dsi_transcoders(enabled_transcoders) +
3617 has_pipe_transcoders(enabled_transcoders) > 1);
3619 /* Only DSI transcoders can be ganged */
3620 drm_WARN_ON(&i915->drm,
3621 !has_dsi_transcoders(enabled_transcoders) &&
3622 !is_power_of_2(enabled_transcoders));
3625 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3626 struct intel_crtc_state *pipe_config,
3627 struct intel_display_power_domain_set *power_domain_set)
3629 struct drm_device *dev = crtc->base.dev;
3630 struct drm_i915_private *dev_priv = to_i915(dev);
3631 unsigned long enabled_transcoders;
3634 enabled_transcoders = hsw_enabled_transcoders(crtc);
3635 if (!enabled_transcoders)
3638 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3641 * With the exception of DSI we should only ever have
3642 * a single enabled transcoder. With DSI let's just
3643 * pick the first one.
3645 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3647 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3648 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3651 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3652 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3654 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3655 pipe_config->pch_pfit.force_thru = true;
3658 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3660 return tmp & TRANSCONF_ENABLE;
3663 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3664 struct intel_crtc_state *pipe_config,
3665 struct intel_display_power_domain_set *power_domain_set)
3667 struct drm_device *dev = crtc->base.dev;
3668 struct drm_i915_private *dev_priv = to_i915(dev);
3669 enum transcoder cpu_transcoder;
3673 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3675 cpu_transcoder = TRANSCODER_DSI_A;
3677 cpu_transcoder = TRANSCODER_DSI_C;
3679 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3680 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3684 * The PLL needs to be enabled with a valid divider
3685 * configuration, otherwise accessing DSI registers will hang
3686 * the machine. See BSpec North Display Engine
3687 * registers/MIPI[BXT]. We can break out here early, since we
3688 * need the same DSI PLL to be enabled for both DSI ports.
3690 if (!bxt_dsi_pll_is_enabled(dev_priv))
3693 /* XXX: this works for video mode only */
3694 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
3695 if (!(tmp & DPI_ENABLE))
3698 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
3699 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
3702 pipe_config->cpu_transcoder = cpu_transcoder;
3706 return transcoder_is_dsi(pipe_config->cpu_transcoder);
3709 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
3711 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3712 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3713 u8 master_pipes, slave_pipes;
3714 enum pipe pipe = crtc->pipe;
3716 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
3718 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
3721 crtc_state->bigjoiner_pipes =
3722 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
3723 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
3726 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
3727 struct intel_crtc_state *pipe_config)
3729 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3733 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3734 POWER_DOMAIN_PIPE(crtc->pipe)))
3737 pipe_config->shared_dpll = NULL;
3739 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
3741 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
3742 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
3743 drm_WARN_ON(&dev_priv->drm, active);
3750 intel_dsc_get_config(pipe_config);
3751 intel_bigjoiner_get_config(pipe_config);
3753 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
3754 DISPLAY_VER(dev_priv) >= 11)
3755 intel_get_transcoder_timings(crtc, pipe_config);
3757 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
3758 intel_vrr_get_config(pipe_config);
3760 intel_get_pipe_src_size(crtc, pipe_config);
3762 if (IS_HASWELL(dev_priv)) {
3763 u32 tmp = intel_de_read(dev_priv,
3764 TRANSCONF(pipe_config->cpu_transcoder));
3766 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
3767 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3769 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3771 pipe_config->output_format =
3772 bdw_get_pipe_misc_output_format(crtc);
3775 pipe_config->sink_format = pipe_config->output_format;
3777 intel_color_get_config(pipe_config);
3779 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
3780 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
3781 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3782 pipe_config->ips_linetime =
3783 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
3785 if (intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3786 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
3787 if (DISPLAY_VER(dev_priv) >= 9)
3788 skl_scaler_get_config(pipe_config);
3790 ilk_get_pfit_config(pipe_config);
3793 hsw_ips_get_config(pipe_config);
3795 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
3796 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3797 pipe_config->pixel_multiplier =
3798 intel_de_read(dev_priv,
3799 TRANS_MULT(pipe_config->cpu_transcoder)) + 1;
3801 pipe_config->pixel_multiplier = 1;
3804 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3805 tmp = intel_de_read(dev_priv, DISPLAY_VER(dev_priv) >= 14 ?
3806 MTL_CHICKEN_TRANS(pipe_config->cpu_transcoder) :
3807 CHICKEN_TRANS(pipe_config->cpu_transcoder));
3809 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
3811 /* no idea if this is correct */
3812 pipe_config->framestart_delay = 1;
3816 intel_display_power_put_all_in_set(dev_priv, &crtc->hw_readout_power_domains);
3821 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
3823 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3824 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3826 if (!i915->display.funcs.display->get_pipe_config(crtc, crtc_state))
3829 crtc_state->hw.active = true;
3831 intel_crtc_readout_derived_state(crtc_state);
3836 static int i9xx_pll_refclk(struct drm_device *dev,
3837 const struct intel_crtc_state *pipe_config)
3839 struct drm_i915_private *dev_priv = to_i915(dev);
3840 u32 dpll = pipe_config->dpll_hw_state.dpll;
3842 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
3843 return dev_priv->display.vbt.lvds_ssc_freq;
3844 else if (HAS_PCH_SPLIT(dev_priv))
3846 else if (DISPLAY_VER(dev_priv) != 2)
3852 /* Returns the clock of the currently programmed mode of the given pipe. */
3853 void i9xx_crtc_clock_get(struct intel_crtc *crtc,
3854 struct intel_crtc_state *pipe_config)
3856 struct drm_device *dev = crtc->base.dev;
3857 struct drm_i915_private *dev_priv = to_i915(dev);
3858 u32 dpll = pipe_config->dpll_hw_state.dpll;
3862 int refclk = i9xx_pll_refclk(dev, pipe_config);
3864 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
3865 fp = pipe_config->dpll_hw_state.fp0;
3867 fp = pipe_config->dpll_hw_state.fp1;
3869 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
3870 if (IS_PINEVIEW(dev_priv)) {
3871 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
3872 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
3874 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
3875 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
3878 if (DISPLAY_VER(dev_priv) != 2) {
3879 if (IS_PINEVIEW(dev_priv))
3880 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
3881 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
3883 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
3884 DPLL_FPA01_P1_POST_DIV_SHIFT);
3886 switch (dpll & DPLL_MODE_MASK) {
3887 case DPLLB_MODE_DAC_SERIAL:
3888 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
3891 case DPLLB_MODE_LVDS:
3892 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
3896 drm_dbg_kms(&dev_priv->drm,
3897 "Unknown DPLL mode %08x in programmed "
3898 "mode\n", (int)(dpll & DPLL_MODE_MASK));
3902 if (IS_PINEVIEW(dev_priv))
3903 port_clock = pnv_calc_dpll_params(refclk, &clock);
3905 port_clock = i9xx_calc_dpll_params(refclk, &clock);
3907 enum pipe lvds_pipe;
3909 if (IS_I85X(dev_priv) &&
3910 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) &&
3911 lvds_pipe == crtc->pipe) {
3912 u32 lvds = intel_de_read(dev_priv, LVDS);
3914 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
3915 DPLL_FPA01_P1_POST_DIV_SHIFT);
3917 if (lvds & LVDS_CLKB_POWER_UP)
3922 if (dpll & PLL_P1_DIVIDE_BY_TWO)
3925 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
3926 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
3928 if (dpll & PLL_P2_DIVIDE_BY_4)
3934 port_clock = i9xx_calc_dpll_params(refclk, &clock);
3938 * This value includes pixel_multiplier. We will use
3939 * port_clock to compute adjusted_mode.crtc_clock in the
3940 * encoder's get_config() function.
3942 pipe_config->port_clock = port_clock;
3945 int intel_dotclock_calculate(int link_freq,
3946 const struct intel_link_m_n *m_n)
3949 * The calculation for the data clock is:
3950 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
3951 * But we want to avoid losing precison if possible, so:
3952 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
3954 * and the link clock is simpler:
3955 * link_clock = (m * link_clock) / n
3961 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq),
3965 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
3969 if (intel_crtc_has_dp_encoder(pipe_config))
3970 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
3971 &pipe_config->dp_m_n);
3972 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
3973 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
3974 pipe_config->pipe_bpp);
3976 dotclock = pipe_config->port_clock;
3978 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
3979 !intel_crtc_has_dp_encoder(pipe_config))
3982 if (pipe_config->pixel_multiplier)
3983 dotclock /= pipe_config->pixel_multiplier;
3988 /* Returns the currently programmed mode of the given encoder. */
3989 struct drm_display_mode *
3990 intel_encoder_current_mode(struct intel_encoder *encoder)
3992 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3993 struct intel_crtc_state *crtc_state;
3994 struct drm_display_mode *mode;
3995 struct intel_crtc *crtc;
3998 if (!encoder->get_hw_state(encoder, &pipe))
4001 crtc = intel_crtc_for_pipe(dev_priv, pipe);
4003 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
4007 crtc_state = intel_crtc_state_alloc(crtc);
4013 if (!intel_crtc_get_pipe_config(crtc_state)) {
4014 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4019 intel_encoder_get_config(encoder, crtc_state);
4021 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4023 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4028 static bool encoders_cloneable(const struct intel_encoder *a,
4029 const struct intel_encoder *b)
4031 /* masks could be asymmetric, so check both ways */
4032 return a == b || (a->cloneable & BIT(b->type) &&
4033 b->cloneable & BIT(a->type));
4036 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4037 struct intel_crtc *crtc,
4038 struct intel_encoder *encoder)
4040 struct intel_encoder *source_encoder;
4041 struct drm_connector *connector;
4042 struct drm_connector_state *connector_state;
4045 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4046 if (connector_state->crtc != &crtc->base)
4050 to_intel_encoder(connector_state->best_encoder);
4051 if (!encoders_cloneable(encoder, source_encoder))
4058 static int icl_add_linked_planes(struct intel_atomic_state *state)
4060 struct intel_plane *plane, *linked;
4061 struct intel_plane_state *plane_state, *linked_plane_state;
4064 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4065 linked = plane_state->planar_linked_plane;
4070 linked_plane_state = intel_atomic_get_plane_state(state, linked);
4071 if (IS_ERR(linked_plane_state))
4072 return PTR_ERR(linked_plane_state);
4074 drm_WARN_ON(state->base.dev,
4075 linked_plane_state->planar_linked_plane != plane);
4076 drm_WARN_ON(state->base.dev,
4077 linked_plane_state->planar_slave == plane_state->planar_slave);
4083 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
4085 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4086 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4087 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
4088 struct intel_plane *plane, *linked;
4089 struct intel_plane_state *plane_state;
4092 if (DISPLAY_VER(dev_priv) < 11)
4096 * Destroy all old plane links and make the slave plane invisible
4097 * in the crtc_state->active_planes mask.
4099 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4100 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
4103 plane_state->planar_linked_plane = NULL;
4104 if (plane_state->planar_slave && !plane_state->uapi.visible) {
4105 crtc_state->enabled_planes &= ~BIT(plane->id);
4106 crtc_state->active_planes &= ~BIT(plane->id);
4107 crtc_state->update_planes |= BIT(plane->id);
4108 crtc_state->data_rate[plane->id] = 0;
4109 crtc_state->rel_data_rate[plane->id] = 0;
4112 plane_state->planar_slave = false;
4115 if (!crtc_state->nv12_planes)
4118 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4119 struct intel_plane_state *linked_state = NULL;
4121 if (plane->pipe != crtc->pipe ||
4122 !(crtc_state->nv12_planes & BIT(plane->id)))
4125 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4126 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4129 if (crtc_state->active_planes & BIT(linked->id))
4132 linked_state = intel_atomic_get_plane_state(state, linked);
4133 if (IS_ERR(linked_state))
4134 return PTR_ERR(linked_state);
4139 if (!linked_state) {
4140 drm_dbg_kms(&dev_priv->drm,
4141 "Need %d free Y planes for planar YUV\n",
4142 hweight8(crtc_state->nv12_planes));
4147 plane_state->planar_linked_plane = linked;
4149 linked_state->planar_slave = true;
4150 linked_state->planar_linked_plane = plane;
4151 crtc_state->enabled_planes |= BIT(linked->id);
4152 crtc_state->active_planes |= BIT(linked->id);
4153 crtc_state->update_planes |= BIT(linked->id);
4154 crtc_state->data_rate[linked->id] =
4155 crtc_state->data_rate_y[plane->id];
4156 crtc_state->rel_data_rate[linked->id] =
4157 crtc_state->rel_data_rate_y[plane->id];
4158 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4159 linked->base.name, plane->base.name);
4161 /* Copy parameters to slave plane */
4162 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4163 linked_state->color_ctl = plane_state->color_ctl;
4164 linked_state->view = plane_state->view;
4165 linked_state->decrypt = plane_state->decrypt;
4167 intel_plane_copy_hw_state(linked_state, plane_state);
4168 linked_state->uapi.src = plane_state->uapi.src;
4169 linked_state->uapi.dst = plane_state->uapi.dst;
4171 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4172 if (linked->id == PLANE_SPRITE5)
4173 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4174 else if (linked->id == PLANE_SPRITE4)
4175 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4176 else if (linked->id == PLANE_SPRITE3)
4177 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4178 else if (linked->id == PLANE_SPRITE2)
4179 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4181 MISSING_CASE(linked->id);
4188 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4190 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4191 struct intel_atomic_state *state =
4192 to_intel_atomic_state(new_crtc_state->uapi.state);
4193 const struct intel_crtc_state *old_crtc_state =
4194 intel_atomic_get_old_crtc_state(state, crtc);
4196 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4199 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4201 const struct drm_display_mode *pipe_mode =
4202 &crtc_state->hw.pipe_mode;
4205 if (!crtc_state->hw.enable)
4208 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4209 pipe_mode->crtc_clock);
4211 return min(linetime_wm, 0x1ff);
4214 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4215 const struct intel_cdclk_state *cdclk_state)
4217 const struct drm_display_mode *pipe_mode =
4218 &crtc_state->hw.pipe_mode;
4221 if (!crtc_state->hw.enable)
4224 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4225 cdclk_state->logical.cdclk);
4227 return min(linetime_wm, 0x1ff);
4230 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4232 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4233 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4234 const struct drm_display_mode *pipe_mode =
4235 &crtc_state->hw.pipe_mode;
4238 if (!crtc_state->hw.enable)
4241 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4242 crtc_state->pixel_rate);
4244 /* Display WA #1135: BXT:ALL GLK:ALL */
4245 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4246 skl_watermark_ipc_enabled(dev_priv))
4249 return min(linetime_wm, 0x1ff);
4252 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4253 struct intel_crtc *crtc)
4255 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4256 struct intel_crtc_state *crtc_state =
4257 intel_atomic_get_new_crtc_state(state, crtc);
4258 const struct intel_cdclk_state *cdclk_state;
4260 if (DISPLAY_VER(dev_priv) >= 9)
4261 crtc_state->linetime = skl_linetime_wm(crtc_state);
4263 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4265 if (!hsw_crtc_supports_ips(crtc))
4268 cdclk_state = intel_atomic_get_cdclk_state(state);
4269 if (IS_ERR(cdclk_state))
4270 return PTR_ERR(cdclk_state);
4272 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4278 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4279 struct intel_crtc *crtc)
4281 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4282 struct intel_crtc_state *crtc_state =
4283 intel_atomic_get_new_crtc_state(state, crtc);
4286 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4287 intel_crtc_needs_modeset(crtc_state) &&
4288 !crtc_state->hw.active)
4289 crtc_state->update_wm_post = true;
4291 if (intel_crtc_needs_modeset(crtc_state)) {
4292 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4298 * May need to update pipe gamma enable bits
4299 * when C8 planes are getting enabled/disabled.
4301 if (c8_planes_changed(crtc_state))
4302 crtc_state->uapi.color_mgmt_changed = true;
4304 if (intel_crtc_needs_color_update(crtc_state)) {
4305 ret = intel_color_check(crtc_state);
4310 ret = intel_compute_pipe_wm(state, crtc);
4312 drm_dbg_kms(&dev_priv->drm,
4313 "Target pipe watermarks are invalid\n");
4318 * Calculate 'intermediate' watermarks that satisfy both the
4319 * old state and the new state. We can program these
4322 ret = intel_compute_intermediate_wm(state, crtc);
4324 drm_dbg_kms(&dev_priv->drm,
4325 "No valid intermediate pipe watermarks are possible\n");
4329 if (DISPLAY_VER(dev_priv) >= 9) {
4330 if (intel_crtc_needs_modeset(crtc_state) ||
4331 intel_crtc_needs_fastset(crtc_state)) {
4332 ret = skl_update_scaler_crtc(crtc_state);
4337 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4342 if (HAS_IPS(dev_priv)) {
4343 ret = hsw_ips_compute_config(state, crtc);
4348 if (DISPLAY_VER(dev_priv) >= 9 ||
4349 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4350 ret = hsw_compute_linetime_wm(state, crtc);
4356 ret = intel_psr2_sel_fetch_update(state, crtc);
4364 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4365 struct intel_crtc_state *crtc_state)
4367 struct drm_connector *connector = conn_state->connector;
4368 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4369 const struct drm_display_info *info = &connector->display_info;
4372 switch (conn_state->max_bpc) {
4386 MISSING_CASE(conn_state->max_bpc);
4390 if (bpp < crtc_state->pipe_bpp) {
4391 drm_dbg_kms(&i915->drm,
4392 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4393 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4394 connector->base.id, connector->name,
4396 3 * conn_state->max_requested_bpc,
4397 crtc_state->pipe_bpp);
4399 crtc_state->pipe_bpp = bpp;
4406 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4407 struct intel_crtc *crtc)
4409 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4410 struct intel_crtc_state *crtc_state =
4411 intel_atomic_get_new_crtc_state(state, crtc);
4412 struct drm_connector *connector;
4413 struct drm_connector_state *connector_state;
4416 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4417 IS_CHERRYVIEW(dev_priv)))
4419 else if (DISPLAY_VER(dev_priv) >= 5)
4424 crtc_state->pipe_bpp = bpp;
4426 /* Clamp display bpp to connector max bpp */
4427 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4430 if (connector_state->crtc != &crtc->base)
4433 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4441 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4443 struct drm_device *dev = state->base.dev;
4444 struct drm_connector *connector;
4445 struct drm_connector_list_iter conn_iter;
4446 unsigned int used_ports = 0;
4447 unsigned int used_mst_ports = 0;
4451 * We're going to peek into connector->state,
4452 * hence connection_mutex must be held.
4454 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4457 * Walk the connector list instead of the encoder
4458 * list to detect the problem on ddi platforms
4459 * where there's just one encoder per digital port.
4461 drm_connector_list_iter_begin(dev, &conn_iter);
4462 drm_for_each_connector_iter(connector, &conn_iter) {
4463 struct drm_connector_state *connector_state;
4464 struct intel_encoder *encoder;
4467 drm_atomic_get_new_connector_state(&state->base,
4469 if (!connector_state)
4470 connector_state = connector->state;
4472 if (!connector_state->best_encoder)
4475 encoder = to_intel_encoder(connector_state->best_encoder);
4477 drm_WARN_ON(dev, !connector_state->crtc);
4479 switch (encoder->type) {
4480 case INTEL_OUTPUT_DDI:
4481 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4484 case INTEL_OUTPUT_DP:
4485 case INTEL_OUTPUT_HDMI:
4486 case INTEL_OUTPUT_EDP:
4487 /* the same port mustn't appear more than once */
4488 if (used_ports & BIT(encoder->port))
4491 used_ports |= BIT(encoder->port);
4493 case INTEL_OUTPUT_DP_MST:
4501 drm_connector_list_iter_end(&conn_iter);
4503 /* can't mix MST and SST/HDMI on the same port */
4504 if (used_ports & used_mst_ports)
4511 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4512 struct intel_crtc *crtc)
4514 struct intel_crtc_state *crtc_state =
4515 intel_atomic_get_new_crtc_state(state, crtc);
4517 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4519 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4520 crtc_state->uapi.degamma_lut);
4521 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4522 crtc_state->uapi.gamma_lut);
4523 drm_property_replace_blob(&crtc_state->hw.ctm,
4524 crtc_state->uapi.ctm);
4528 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4529 struct intel_crtc *crtc)
4531 struct intel_crtc_state *crtc_state =
4532 intel_atomic_get_new_crtc_state(state, crtc);
4534 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4536 crtc_state->hw.enable = crtc_state->uapi.enable;
4537 crtc_state->hw.active = crtc_state->uapi.active;
4538 drm_mode_copy(&crtc_state->hw.mode,
4539 &crtc_state->uapi.mode);
4540 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4541 &crtc_state->uapi.adjusted_mode);
4542 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4544 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4548 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4549 struct intel_crtc *slave_crtc)
4551 struct intel_crtc_state *slave_crtc_state =
4552 intel_atomic_get_new_crtc_state(state, slave_crtc);
4553 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4554 const struct intel_crtc_state *master_crtc_state =
4555 intel_atomic_get_new_crtc_state(state, master_crtc);
4557 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
4558 master_crtc_state->hw.degamma_lut);
4559 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
4560 master_crtc_state->hw.gamma_lut);
4561 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
4562 master_crtc_state->hw.ctm);
4564 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
4568 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
4569 struct intel_crtc *slave_crtc)
4571 struct intel_crtc_state *slave_crtc_state =
4572 intel_atomic_get_new_crtc_state(state, slave_crtc);
4573 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4574 const struct intel_crtc_state *master_crtc_state =
4575 intel_atomic_get_new_crtc_state(state, master_crtc);
4576 struct intel_crtc_state *saved_state;
4578 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4579 slave_crtc_state->bigjoiner_pipes);
4581 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4585 /* preserve some things from the slave's original crtc state */
4586 saved_state->uapi = slave_crtc_state->uapi;
4587 saved_state->scaler_state = slave_crtc_state->scaler_state;
4588 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
4589 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
4591 intel_crtc_free_hw_state(slave_crtc_state);
4592 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
4595 /* Re-init hw state */
4596 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
4597 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
4598 slave_crtc_state->hw.active = master_crtc_state->hw.active;
4599 drm_mode_copy(&slave_crtc_state->hw.mode,
4600 &master_crtc_state->hw.mode);
4601 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
4602 &master_crtc_state->hw.pipe_mode);
4603 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
4604 &master_crtc_state->hw.adjusted_mode);
4605 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
4607 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
4609 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
4610 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
4611 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
4613 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4614 slave_crtc_state->bigjoiner_pipes);
4620 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4621 struct intel_crtc *crtc)
4623 struct intel_crtc_state *crtc_state =
4624 intel_atomic_get_new_crtc_state(state, crtc);
4625 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4626 struct intel_crtc_state *saved_state;
4628 saved_state = intel_crtc_state_alloc(crtc);
4632 /* free the old crtc_state->hw members */
4633 intel_crtc_free_hw_state(crtc_state);
4635 /* FIXME: before the switch to atomic started, a new pipe_config was
4636 * kzalloc'd. Code that depends on any field being zero should be
4637 * fixed, so that the crtc_state can be safely duplicated. For now,
4638 * only fields that are know to not cause problems are preserved. */
4640 saved_state->uapi = crtc_state->uapi;
4641 saved_state->inherited = crtc_state->inherited;
4642 saved_state->scaler_state = crtc_state->scaler_state;
4643 saved_state->shared_dpll = crtc_state->shared_dpll;
4644 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4645 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4646 sizeof(saved_state->icl_port_dplls));
4647 saved_state->crc_enabled = crtc_state->crc_enabled;
4648 if (IS_G4X(dev_priv) ||
4649 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4650 saved_state->wm = crtc_state->wm;
4652 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4655 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4661 intel_modeset_pipe_config(struct intel_atomic_state *state,
4662 struct intel_crtc *crtc,
4663 const struct intel_link_bw_limits *limits)
4665 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4666 struct intel_crtc_state *crtc_state =
4667 intel_atomic_get_new_crtc_state(state, crtc);
4668 struct drm_connector *connector;
4669 struct drm_connector_state *connector_state;
4670 int pipe_src_w, pipe_src_h;
4671 int base_bpp, ret, i;
4673 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4675 crtc_state->framestart_delay = 1;
4678 * Sanitize sync polarity flags based on requested ones. If neither
4679 * positive or negative polarity is requested, treat this as meaning
4680 * negative polarity.
4682 if (!(crtc_state->hw.adjusted_mode.flags &
4683 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4684 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4686 if (!(crtc_state->hw.adjusted_mode.flags &
4687 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4688 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4690 ret = compute_baseline_pipe_bpp(state, crtc);
4694 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe];
4696 if (crtc_state->pipe_bpp > to_bpp_int(crtc_state->max_link_bpp_x16)) {
4697 drm_dbg_kms(&i915->drm,
4698 "[CRTC:%d:%s] Link bpp limited to " BPP_X16_FMT "\n",
4699 crtc->base.base.id, crtc->base.name,
4700 BPP_X16_ARGS(crtc_state->max_link_bpp_x16));
4701 crtc_state->bw_constrained = true;
4704 base_bpp = crtc_state->pipe_bpp;
4707 * Determine the real pipe dimensions. Note that stereo modes can
4708 * increase the actual pipe size due to the frame doubling and
4709 * insertion of additional space for blanks between the frame. This
4710 * is stored in the crtc timings. We use the requested mode to do this
4711 * computation to clearly distinguish it from the adjusted mode, which
4712 * can be changed by the connectors in the below retry loop.
4714 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4715 &pipe_src_w, &pipe_src_h);
4716 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4717 pipe_src_w, pipe_src_h);
4719 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4720 struct intel_encoder *encoder =
4721 to_intel_encoder(connector_state->best_encoder);
4723 if (connector_state->crtc != &crtc->base)
4726 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4727 drm_dbg_kms(&i915->drm,
4728 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4729 encoder->base.base.id, encoder->base.name);
4734 * Determine output_types before calling the .compute_config()
4735 * hooks so that the hooks can use this information safely.
4737 if (encoder->compute_output_type)
4738 crtc_state->output_types |=
4739 BIT(encoder->compute_output_type(encoder, crtc_state,
4742 crtc_state->output_types |= BIT(encoder->type);
4745 /* Ensure the port clock defaults are reset when retrying. */
4746 crtc_state->port_clock = 0;
4747 crtc_state->pixel_multiplier = 1;
4749 /* Fill in default crtc timings, allow encoders to overwrite them. */
4750 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
4751 CRTC_STEREO_DOUBLE);
4753 /* Pass our mode to the connectors and the CRTC to give them a chance to
4754 * adjust it according to limitations or connector properties, and also
4755 * a chance to reject the mode entirely.
4757 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4758 struct intel_encoder *encoder =
4759 to_intel_encoder(connector_state->best_encoder);
4761 if (connector_state->crtc != &crtc->base)
4764 ret = encoder->compute_config(encoder, crtc_state,
4766 if (ret == -EDEADLK)
4769 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
4770 encoder->base.base.id, encoder->base.name, ret);
4775 /* Set default port clock if not overwritten by the encoder. Needs to be
4776 * done afterwards in case the encoder adjusts the mode. */
4777 if (!crtc_state->port_clock)
4778 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
4779 * crtc_state->pixel_multiplier;
4781 ret = intel_crtc_compute_config(state, crtc);
4782 if (ret == -EDEADLK)
4785 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
4786 crtc->base.base.id, crtc->base.name, ret);
4790 /* Dithering seems to not pass-through bits correctly when it should, so
4791 * only enable it on 6bpc panels and when its not a compliance
4792 * test requesting 6bpc video pattern.
4794 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
4795 !crtc_state->dither_force_disable;
4796 drm_dbg_kms(&i915->drm,
4797 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
4798 crtc->base.base.id, crtc->base.name,
4799 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
4805 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
4806 struct intel_crtc *crtc)
4808 struct intel_crtc_state *crtc_state =
4809 intel_atomic_get_new_crtc_state(state, crtc);
4810 struct drm_connector_state *conn_state;
4811 struct drm_connector *connector;
4814 intel_bigjoiner_adjust_pipe_src(crtc_state);
4816 for_each_new_connector_in_state(&state->base, connector,
4818 struct intel_encoder *encoder =
4819 to_intel_encoder(conn_state->best_encoder);
4822 if (conn_state->crtc != &crtc->base ||
4823 !encoder->compute_config_late)
4826 ret = encoder->compute_config_late(encoder, crtc_state,
4835 bool intel_fuzzy_clock_check(int clock1, int clock2)
4839 if (clock1 == clock2)
4842 if (!clock1 || !clock2)
4845 diff = abs(clock1 - clock2);
4847 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
4854 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
4855 const struct intel_link_m_n *m2_n2)
4857 return m_n->tu == m2_n2->tu &&
4858 m_n->data_m == m2_n2->data_m &&
4859 m_n->data_n == m2_n2->data_n &&
4860 m_n->link_m == m2_n2->link_m &&
4861 m_n->link_n == m2_n2->link_n;
4865 intel_compare_infoframe(const union hdmi_infoframe *a,
4866 const union hdmi_infoframe *b)
4868 return memcmp(a, b, sizeof(*a)) == 0;
4872 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
4873 const struct drm_dp_vsc_sdp *b)
4875 return memcmp(a, b, sizeof(*a)) == 0;
4879 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
4881 return memcmp(a, b, len) == 0;
4885 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
4886 bool fastset, const char *name,
4887 const union hdmi_infoframe *a,
4888 const union hdmi_infoframe *b)
4891 if (!drm_debug_enabled(DRM_UT_KMS))
4894 drm_dbg_kms(&dev_priv->drm,
4895 "fastset requirement not met in %s infoframe\n", name);
4896 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4897 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
4898 drm_dbg_kms(&dev_priv->drm, "found:\n");
4899 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
4901 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
4902 drm_err(&dev_priv->drm, "expected:\n");
4903 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
4904 drm_err(&dev_priv->drm, "found:\n");
4905 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
4910 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
4911 bool fastset, const char *name,
4912 const struct drm_dp_vsc_sdp *a,
4913 const struct drm_dp_vsc_sdp *b)
4916 if (!drm_debug_enabled(DRM_UT_KMS))
4919 drm_dbg_kms(&dev_priv->drm,
4920 "fastset requirement not met in %s dp sdp\n", name);
4921 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4922 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
4923 drm_dbg_kms(&dev_priv->drm, "found:\n");
4924 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
4926 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
4927 drm_err(&dev_priv->drm, "expected:\n");
4928 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
4929 drm_err(&dev_priv->drm, "found:\n");
4930 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
4934 /* Returns the length up to and including the last differing byte */
4936 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
4940 for (i = len - 1; i >= 0; i--) {
4949 pipe_config_buffer_mismatch(struct drm_i915_private *dev_priv,
4950 bool fastset, const char *name,
4951 const u8 *a, const u8 *b, size_t len)
4954 if (!drm_debug_enabled(DRM_UT_KMS))
4957 /* only dump up to the last difference */
4958 len = memcmp_diff_len(a, b, len);
4960 drm_dbg_kms(&dev_priv->drm,
4961 "fastset requirement not met in %s buffer\n", name);
4962 print_hex_dump(KERN_DEBUG, "expected: ", DUMP_PREFIX_NONE,
4963 16, 0, a, len, false);
4964 print_hex_dump(KERN_DEBUG, "found: ", DUMP_PREFIX_NONE,
4965 16, 0, b, len, false);
4967 /* only dump up to the last difference */
4968 len = memcmp_diff_len(a, b, len);
4970 drm_err(&dev_priv->drm, "mismatch in %s buffer\n", name);
4971 print_hex_dump(KERN_ERR, "expected: ", DUMP_PREFIX_NONE,
4972 16, 0, a, len, false);
4973 print_hex_dump(KERN_ERR, "found: ", DUMP_PREFIX_NONE,
4974 16, 0, b, len, false);
4978 static void __printf(4, 5)
4979 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
4980 const char *name, const char *format, ...)
4982 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4983 struct va_format vaf;
4986 va_start(args, format);
4991 drm_dbg_kms(&i915->drm,
4992 "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
4993 crtc->base.base.id, crtc->base.name, name, &vaf);
4995 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
4996 crtc->base.base.id, crtc->base.name, name, &vaf);
5001 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
5003 /* Enable fastboot by default on Skylake and newer */
5004 if (DISPLAY_VER(dev_priv) >= 9)
5007 /* Enable fastboot by default on VLV and CHV */
5008 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5011 /* Disabled by default on all others */
5016 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
5017 const struct intel_crtc_state *pipe_config,
5020 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
5021 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
5023 bool fixup_inherited = fastset &&
5024 current_config->inherited && !pipe_config->inherited;
5026 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
5027 drm_dbg_kms(&dev_priv->drm,
5028 "initial modeset and fastboot not set\n");
5032 #define PIPE_CONF_CHECK_X(name) do { \
5033 if (current_config->name != pipe_config->name) { \
5034 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5035 "(expected 0x%08x, found 0x%08x)", \
5036 current_config->name, \
5037 pipe_config->name); \
5042 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5043 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5044 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5045 "(expected 0x%08x, found 0x%08x)", \
5046 current_config->name & (mask), \
5047 pipe_config->name & (mask)); \
5052 #define PIPE_CONF_CHECK_I(name) do { \
5053 if (current_config->name != pipe_config->name) { \
5054 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5055 "(expected %i, found %i)", \
5056 current_config->name, \
5057 pipe_config->name); \
5062 #define PIPE_CONF_CHECK_BOOL(name) do { \
5063 if (current_config->name != pipe_config->name) { \
5064 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5065 "(expected %s, found %s)", \
5066 str_yes_no(current_config->name), \
5067 str_yes_no(pipe_config->name)); \
5073 * Checks state where we only read out the enabling, but not the entire
5074 * state itself (like full infoframes or ELD for audio). These states
5075 * require a full modeset on bootup to fix up.
5077 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
5078 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
5079 PIPE_CONF_CHECK_BOOL(name); \
5081 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5082 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
5083 str_yes_no(current_config->name), \
5084 str_yes_no(pipe_config->name)); \
5089 #define PIPE_CONF_CHECK_P(name) do { \
5090 if (current_config->name != pipe_config->name) { \
5091 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5092 "(expected %p, found %p)", \
5093 current_config->name, \
5094 pipe_config->name); \
5099 #define PIPE_CONF_CHECK_M_N(name) do { \
5100 if (!intel_compare_link_m_n(¤t_config->name, \
5101 &pipe_config->name)) { \
5102 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5103 "(expected tu %i data %i/%i link %i/%i, " \
5104 "found tu %i, data %i/%i link %i/%i)", \
5105 current_config->name.tu, \
5106 current_config->name.data_m, \
5107 current_config->name.data_n, \
5108 current_config->name.link_m, \
5109 current_config->name.link_n, \
5110 pipe_config->name.tu, \
5111 pipe_config->name.data_m, \
5112 pipe_config->name.data_n, \
5113 pipe_config->name.link_m, \
5114 pipe_config->name.link_n); \
5119 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5120 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5121 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5122 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5123 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5124 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5125 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5126 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5127 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5128 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5129 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5130 if (!fastset || !pipe_config->update_lrr) { \
5131 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5132 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5136 #define PIPE_CONF_CHECK_RECT(name) do { \
5137 PIPE_CONF_CHECK_I(name.x1); \
5138 PIPE_CONF_CHECK_I(name.x2); \
5139 PIPE_CONF_CHECK_I(name.y1); \
5140 PIPE_CONF_CHECK_I(name.y2); \
5143 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5144 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5145 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5146 "(%x) (expected %i, found %i)", \
5148 current_config->name & (mask), \
5149 pipe_config->name & (mask)); \
5154 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5155 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5156 &pipe_config->infoframes.name)) { \
5157 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
5158 ¤t_config->infoframes.name, \
5159 &pipe_config->infoframes.name); \
5164 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5165 if (!current_config->has_psr && !pipe_config->has_psr && \
5166 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5167 &pipe_config->infoframes.name)) { \
5168 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
5169 ¤t_config->infoframes.name, \
5170 &pipe_config->infoframes.name); \
5175 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
5176 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
5177 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
5178 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5179 pipe_config_buffer_mismatch(dev_priv, fastset, __stringify(name), \
5180 current_config->name, \
5181 pipe_config->name, \
5187 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5188 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5189 !intel_color_lut_equal(current_config, \
5190 current_config->lut, pipe_config->lut, \
5191 is_pre_csc_lut)) { \
5192 pipe_config_mismatch(fastset, crtc, __stringify(lut), \
5193 "hw_state doesn't match sw_state"); \
5198 #define PIPE_CONF_CHECK_CSC(name) do { \
5199 PIPE_CONF_CHECK_X(name.preoff[0]); \
5200 PIPE_CONF_CHECK_X(name.preoff[1]); \
5201 PIPE_CONF_CHECK_X(name.preoff[2]); \
5202 PIPE_CONF_CHECK_X(name.coeff[0]); \
5203 PIPE_CONF_CHECK_X(name.coeff[1]); \
5204 PIPE_CONF_CHECK_X(name.coeff[2]); \
5205 PIPE_CONF_CHECK_X(name.coeff[3]); \
5206 PIPE_CONF_CHECK_X(name.coeff[4]); \
5207 PIPE_CONF_CHECK_X(name.coeff[5]); \
5208 PIPE_CONF_CHECK_X(name.coeff[6]); \
5209 PIPE_CONF_CHECK_X(name.coeff[7]); \
5210 PIPE_CONF_CHECK_X(name.coeff[8]); \
5211 PIPE_CONF_CHECK_X(name.postoff[0]); \
5212 PIPE_CONF_CHECK_X(name.postoff[1]); \
5213 PIPE_CONF_CHECK_X(name.postoff[2]); \
5216 #define PIPE_CONF_QUIRK(quirk) \
5217 ((current_config->quirks | pipe_config->quirks) & (quirk))
5219 PIPE_CONF_CHECK_I(hw.enable);
5220 PIPE_CONF_CHECK_I(hw.active);
5222 PIPE_CONF_CHECK_I(cpu_transcoder);
5223 PIPE_CONF_CHECK_I(mst_master_transcoder);
5225 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5226 PIPE_CONF_CHECK_I(fdi_lanes);
5227 PIPE_CONF_CHECK_M_N(fdi_m_n);
5229 PIPE_CONF_CHECK_I(lane_count);
5230 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5232 if (HAS_DOUBLE_BUFFERED_M_N(dev_priv)) {
5233 if (!fastset || !pipe_config->update_m_n)
5234 PIPE_CONF_CHECK_M_N(dp_m_n);
5236 PIPE_CONF_CHECK_M_N(dp_m_n);
5237 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5240 PIPE_CONF_CHECK_X(output_types);
5242 PIPE_CONF_CHECK_I(framestart_delay);
5243 PIPE_CONF_CHECK_I(msa_timing_delay);
5245 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5246 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5248 PIPE_CONF_CHECK_I(pixel_multiplier);
5250 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5251 DRM_MODE_FLAG_INTERLACE);
5253 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5254 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5255 DRM_MODE_FLAG_PHSYNC);
5256 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5257 DRM_MODE_FLAG_NHSYNC);
5258 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5259 DRM_MODE_FLAG_PVSYNC);
5260 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5261 DRM_MODE_FLAG_NVSYNC);
5264 PIPE_CONF_CHECK_I(output_format);
5265 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5266 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5267 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5268 PIPE_CONF_CHECK_BOOL(limited_color_range);
5270 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5271 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5272 PIPE_CONF_CHECK_BOOL(has_infoframe);
5273 PIPE_CONF_CHECK_BOOL(enhanced_framing);
5274 PIPE_CONF_CHECK_BOOL(fec_enable);
5276 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
5277 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5279 PIPE_CONF_CHECK_X(gmch_pfit.control);
5280 /* pfit ratios are autocomputed by the hw on gen4+ */
5281 if (DISPLAY_VER(dev_priv) < 4)
5282 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5283 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5286 * Changing the EDP transcoder input mux
5287 * (A_ONOFF vs. A_ON) requires a full modeset.
5289 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5292 PIPE_CONF_CHECK_RECT(pipe_src);
5294 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5295 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5297 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5298 PIPE_CONF_CHECK_I(pixel_rate);
5300 PIPE_CONF_CHECK_X(gamma_mode);
5301 if (IS_CHERRYVIEW(dev_priv))
5302 PIPE_CONF_CHECK_X(cgm_mode);
5304 PIPE_CONF_CHECK_X(csc_mode);
5305 PIPE_CONF_CHECK_BOOL(gamma_enable);
5306 PIPE_CONF_CHECK_BOOL(csc_enable);
5307 PIPE_CONF_CHECK_BOOL(wgc_enable);
5309 PIPE_CONF_CHECK_I(linetime);
5310 PIPE_CONF_CHECK_I(ips_linetime);
5312 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5313 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5315 PIPE_CONF_CHECK_CSC(csc);
5316 PIPE_CONF_CHECK_CSC(output_csc);
5318 if (current_config->active_planes) {
5319 PIPE_CONF_CHECK_BOOL(has_psr);
5320 PIPE_CONF_CHECK_BOOL(has_psr2);
5321 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5322 PIPE_CONF_CHECK_I(dc3co_exitline);
5326 PIPE_CONF_CHECK_BOOL(double_wide);
5328 if (dev_priv->display.dpll.mgr) {
5329 PIPE_CONF_CHECK_P(shared_dpll);
5331 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
5332 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
5333 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
5334 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
5335 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
5336 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
5337 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
5338 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
5339 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
5340 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
5341 PIPE_CONF_CHECK_X(dpll_hw_state.div0);
5342 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
5343 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
5344 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
5345 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
5346 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
5347 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
5348 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
5349 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
5350 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
5351 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
5352 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
5353 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
5354 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
5355 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
5356 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
5357 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
5358 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
5359 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
5360 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
5361 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
5362 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
5365 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5366 PIPE_CONF_CHECK_X(dsi_pll.div);
5368 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5369 PIPE_CONF_CHECK_I(pipe_bpp);
5371 if (!fastset || !pipe_config->update_m_n) {
5372 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5373 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5375 PIPE_CONF_CHECK_I(port_clock);
5377 PIPE_CONF_CHECK_I(min_voltage_level);
5379 if (current_config->has_psr || pipe_config->has_psr)
5380 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5381 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5383 PIPE_CONF_CHECK_X(infoframes.enable);
5385 PIPE_CONF_CHECK_X(infoframes.gcp);
5386 PIPE_CONF_CHECK_INFOFRAME(avi);
5387 PIPE_CONF_CHECK_INFOFRAME(spd);
5388 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5389 PIPE_CONF_CHECK_INFOFRAME(drm);
5390 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5392 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5393 PIPE_CONF_CHECK_I(master_transcoder);
5394 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5396 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable);
5397 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb);
5398 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422);
5399 PIPE_CONF_CHECK_BOOL(dsc.config.native_422);
5400 PIPE_CONF_CHECK_BOOL(dsc.config.native_420);
5401 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable);
5402 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth);
5403 PIPE_CONF_CHECK_I(dsc.config.bits_per_component);
5404 PIPE_CONF_CHECK_I(dsc.config.pic_width);
5405 PIPE_CONF_CHECK_I(dsc.config.pic_height);
5406 PIPE_CONF_CHECK_I(dsc.config.slice_width);
5407 PIPE_CONF_CHECK_I(dsc.config.slice_height);
5408 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay);
5409 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay);
5410 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval);
5411 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval);
5412 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value);
5413 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset);
5414 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp);
5415 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp);
5416 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset);
5417 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset);
5418 PIPE_CONF_CHECK_I(dsc.config.initial_offset);
5419 PIPE_CONF_CHECK_I(dsc.config.final_offset);
5420 PIPE_CONF_CHECK_I(dsc.config.rc_model_size);
5421 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0);
5422 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1);
5423 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size);
5424 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset);
5425 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset);
5427 PIPE_CONF_CHECK_I(dsc.compression_enable);
5428 PIPE_CONF_CHECK_I(dsc.dsc_split);
5429 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
5431 PIPE_CONF_CHECK_BOOL(splitter.enable);
5432 PIPE_CONF_CHECK_I(splitter.link_count);
5433 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5436 PIPE_CONF_CHECK_BOOL(vrr.enable);
5437 PIPE_CONF_CHECK_I(vrr.vmin);
5438 PIPE_CONF_CHECK_I(vrr.vmax);
5439 PIPE_CONF_CHECK_I(vrr.flipline);
5440 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5441 PIPE_CONF_CHECK_I(vrr.guardband);
5444 #undef PIPE_CONF_CHECK_X
5445 #undef PIPE_CONF_CHECK_I
5446 #undef PIPE_CONF_CHECK_BOOL
5447 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
5448 #undef PIPE_CONF_CHECK_P
5449 #undef PIPE_CONF_CHECK_FLAGS
5450 #undef PIPE_CONF_CHECK_COLOR_LUT
5451 #undef PIPE_CONF_CHECK_TIMINGS
5452 #undef PIPE_CONF_CHECK_RECT
5453 #undef PIPE_CONF_QUIRK
5459 intel_verify_planes(struct intel_atomic_state *state)
5461 struct intel_plane *plane;
5462 const struct intel_plane_state *plane_state;
5465 for_each_new_intel_plane_in_state(state, plane,
5467 assert_plane(plane, plane_state->planar_slave ||
5468 plane_state->uapi.visible);
5471 static int intel_modeset_pipe(struct intel_atomic_state *state,
5472 struct intel_crtc_state *crtc_state,
5475 struct drm_i915_private *i915 = to_i915(state->base.dev);
5476 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5479 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5480 crtc->base.base.id, crtc->base.name, reason);
5482 ret = drm_atomic_add_affected_connectors(&state->base,
5487 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5491 ret = intel_atomic_add_affected_planes(state, crtc);
5495 crtc_state->uapi.mode_changed = true;
5501 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes
5502 * @state: intel atomic state
5503 * @reason: the reason for the full modeset
5504 * @mask: mask of pipes to modeset
5506 * Add pipes in @mask to @state and force a full modeset on the enabled ones
5507 * due to the description in @reason.
5508 * This function can be called only before new plane states are computed.
5510 * Returns 0 in case of success, negative error code otherwise.
5512 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
5513 const char *reason, u8 mask)
5515 struct drm_i915_private *i915 = to_i915(state->base.dev);
5516 struct intel_crtc *crtc;
5518 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, mask) {
5519 struct intel_crtc_state *crtc_state;
5522 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5523 if (IS_ERR(crtc_state))
5524 return PTR_ERR(crtc_state);
5526 if (!crtc_state->hw.enable ||
5527 intel_crtc_needs_modeset(crtc_state))
5530 ret = intel_modeset_pipe(state, crtc_state, reason);
5539 * intel_modeset_all_pipes_late - force a full modeset on all pipes
5540 * @state: intel atomic state
5541 * @reason: the reason for the full modeset
5543 * Add all pipes to @state and force a full modeset on the active ones due to
5544 * the description in @reason.
5545 * This function can be called only after new plane states are computed already.
5547 * Returns 0 in case of success, negative error code otherwise.
5549 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
5552 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5553 struct intel_crtc *crtc;
5555 for_each_intel_crtc(&dev_priv->drm, crtc) {
5556 struct intel_crtc_state *crtc_state;
5559 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5560 if (IS_ERR(crtc_state))
5561 return PTR_ERR(crtc_state);
5563 if (!crtc_state->hw.active ||
5564 intel_crtc_needs_modeset(crtc_state))
5567 ret = intel_modeset_pipe(state, crtc_state, reason);
5571 crtc_state->update_pipe = false;
5572 crtc_state->update_m_n = false;
5573 crtc_state->update_lrr = false;
5574 crtc_state->update_planes |= crtc_state->active_planes;
5575 crtc_state->async_flip_planes = 0;
5576 crtc_state->do_async_flip = false;
5583 * This implements the workaround described in the "notes" section of the mode
5584 * set sequence documentation. When going from no pipes or single pipe to
5585 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5586 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5588 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5590 struct intel_crtc_state *crtc_state;
5591 struct intel_crtc *crtc;
5592 struct intel_crtc_state *first_crtc_state = NULL;
5593 struct intel_crtc_state *other_crtc_state = NULL;
5594 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5597 /* look at all crtc's that are going to be enabled in during modeset */
5598 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5599 if (!crtc_state->hw.active ||
5600 !intel_crtc_needs_modeset(crtc_state))
5603 if (first_crtc_state) {
5604 other_crtc_state = crtc_state;
5607 first_crtc_state = crtc_state;
5608 first_pipe = crtc->pipe;
5612 /* No workaround needed? */
5613 if (!first_crtc_state)
5616 /* w/a possibly needed, check how many crtc's are already enabled. */
5617 for_each_intel_crtc(state->base.dev, crtc) {
5618 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5619 if (IS_ERR(crtc_state))
5620 return PTR_ERR(crtc_state);
5622 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5624 if (!crtc_state->hw.active ||
5625 intel_crtc_needs_modeset(crtc_state))
5628 /* 2 or more enabled crtcs means no need for w/a */
5629 if (enabled_pipe != INVALID_PIPE)
5632 enabled_pipe = crtc->pipe;
5635 if (enabled_pipe != INVALID_PIPE)
5636 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5637 else if (other_crtc_state)
5638 other_crtc_state->hsw_workaround_pipe = first_pipe;
5643 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
5646 const struct intel_crtc_state *crtc_state;
5647 struct intel_crtc *crtc;
5650 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5651 if (crtc_state->hw.active)
5652 active_pipes |= BIT(crtc->pipe);
5654 active_pipes &= ~BIT(crtc->pipe);
5657 return active_pipes;
5660 static int intel_modeset_checks(struct intel_atomic_state *state)
5662 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5664 state->modeset = true;
5666 if (IS_HASWELL(dev_priv))
5667 return hsw_mode_set_planes_workaround(state);
5672 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
5673 struct intel_crtc_state *new_crtc_state)
5675 struct drm_i915_private *i915 = to_i915(old_crtc_state->uapi.crtc->dev);
5677 /* only allow LRR when the timings stay within the VRR range */
5678 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range)
5679 new_crtc_state->update_lrr = false;
5681 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
5682 drm_dbg_kms(&i915->drm, "fastset requirement not met, forcing full modeset\n");
5684 new_crtc_state->uapi.mode_changed = false;
5686 if (intel_crtc_needs_modeset(new_crtc_state) ||
5687 intel_compare_link_m_n(&old_crtc_state->dp_m_n,
5688 &new_crtc_state->dp_m_n))
5689 new_crtc_state->update_m_n = false;
5691 if (intel_crtc_needs_modeset(new_crtc_state) ||
5692 (old_crtc_state->hw.adjusted_mode.crtc_vtotal == new_crtc_state->hw.adjusted_mode.crtc_vtotal &&
5693 old_crtc_state->hw.adjusted_mode.crtc_vblank_end == new_crtc_state->hw.adjusted_mode.crtc_vblank_end))
5694 new_crtc_state->update_lrr = false;
5696 if (!intel_crtc_needs_modeset(new_crtc_state))
5697 new_crtc_state->update_pipe = true;
5700 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
5701 struct intel_crtc *crtc,
5704 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5705 struct intel_plane *plane;
5707 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5708 struct intel_plane_state *plane_state;
5710 if ((plane_ids_mask & BIT(plane->id)) == 0)
5713 plane_state = intel_atomic_get_plane_state(state, plane);
5714 if (IS_ERR(plane_state))
5715 return PTR_ERR(plane_state);
5721 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
5722 struct intel_crtc *crtc)
5724 const struct intel_crtc_state *old_crtc_state =
5725 intel_atomic_get_old_crtc_state(state, crtc);
5726 const struct intel_crtc_state *new_crtc_state =
5727 intel_atomic_get_new_crtc_state(state, crtc);
5729 return intel_crtc_add_planes_to_state(state, crtc,
5730 old_crtc_state->enabled_planes |
5731 new_crtc_state->enabled_planes);
5734 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
5736 /* See {hsw,vlv,ivb}_plane_ratio() */
5737 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
5738 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
5739 IS_IVYBRIDGE(dev_priv);
5742 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
5743 struct intel_crtc *crtc,
5744 struct intel_crtc *other)
5746 const struct intel_plane_state __maybe_unused *plane_state;
5747 struct intel_plane *plane;
5751 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5752 if (plane->pipe == crtc->pipe)
5753 plane_ids |= BIT(plane->id);
5756 return intel_crtc_add_planes_to_state(state, other, plane_ids);
5759 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
5761 struct drm_i915_private *i915 = to_i915(state->base.dev);
5762 const struct intel_crtc_state *crtc_state;
5763 struct intel_crtc *crtc;
5766 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5767 struct intel_crtc *other;
5769 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
5770 crtc_state->bigjoiner_pipes) {
5776 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
5785 static int intel_atomic_check_planes(struct intel_atomic_state *state)
5787 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5788 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5789 struct intel_plane_state __maybe_unused *plane_state;
5790 struct intel_plane *plane;
5791 struct intel_crtc *crtc;
5794 ret = icl_add_linked_planes(state);
5798 ret = intel_bigjoiner_add_affected_planes(state);
5802 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5803 ret = intel_plane_atomic_check(state, plane);
5805 drm_dbg_atomic(&dev_priv->drm,
5806 "[PLANE:%d:%s] atomic driver check failed\n",
5807 plane->base.base.id, plane->base.name);
5812 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5813 new_crtc_state, i) {
5814 u8 old_active_planes, new_active_planes;
5816 ret = icl_check_nv12_planes(new_crtc_state);
5821 * On some platforms the number of active planes affects
5822 * the planes' minimum cdclk calculation. Add such planes
5823 * to the state before we compute the minimum cdclk.
5825 if (!active_planes_affects_min_cdclk(dev_priv))
5828 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5829 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5831 if (hweight8(old_active_planes) == hweight8(new_active_planes))
5834 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
5842 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
5844 struct intel_crtc_state __maybe_unused *crtc_state;
5845 struct intel_crtc *crtc;
5848 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5849 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5852 ret = intel_crtc_atomic_check(state, crtc);
5854 drm_dbg_atomic(&i915->drm,
5855 "[CRTC:%d:%s] atomic driver check failed\n",
5856 crtc->base.base.id, crtc->base.name);
5864 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
5867 const struct intel_crtc_state *new_crtc_state;
5868 struct intel_crtc *crtc;
5871 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5872 if (new_crtc_state->hw.enable &&
5873 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
5874 intel_crtc_needs_modeset(new_crtc_state))
5881 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
5884 const struct intel_crtc_state *new_crtc_state;
5885 struct intel_crtc *crtc;
5888 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5889 if (new_crtc_state->hw.enable &&
5890 pipes & BIT(crtc->pipe) &&
5891 intel_crtc_needs_modeset(new_crtc_state))
5898 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
5899 struct intel_crtc *master_crtc)
5901 struct drm_i915_private *i915 = to_i915(state->base.dev);
5902 struct intel_crtc_state *master_crtc_state =
5903 intel_atomic_get_new_crtc_state(state, master_crtc);
5904 struct intel_crtc *slave_crtc;
5906 if (!master_crtc_state->bigjoiner_pipes)
5910 if (drm_WARN_ON(&i915->drm,
5911 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
5914 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
5915 drm_dbg_kms(&i915->drm,
5916 "[CRTC:%d:%s] Cannot act as big joiner master "
5917 "(need 0x%x as pipes, only 0x%x possible)\n",
5918 master_crtc->base.base.id, master_crtc->base.name,
5919 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
5923 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5924 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5925 struct intel_crtc_state *slave_crtc_state;
5928 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
5929 if (IS_ERR(slave_crtc_state))
5930 return PTR_ERR(slave_crtc_state);
5932 /* master being enabled, slave was already configured? */
5933 if (slave_crtc_state->uapi.enable) {
5934 drm_dbg_kms(&i915->drm,
5935 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
5936 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
5937 slave_crtc->base.base.id, slave_crtc->base.name,
5938 master_crtc->base.base.id, master_crtc->base.name);
5943 * The state copy logic assumes the master crtc gets processed
5944 * before the slave crtc during the main compute_config loop.
5945 * This works because the crtcs are created in pipe order,
5946 * and the hardware requires master pipe < slave pipe as well.
5947 * Should that change we need to rethink the logic.
5949 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
5950 drm_crtc_index(&slave_crtc->base)))
5953 drm_dbg_kms(&i915->drm,
5954 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
5955 slave_crtc->base.base.id, slave_crtc->base.name,
5956 master_crtc->base.base.id, master_crtc->base.name);
5958 slave_crtc_state->bigjoiner_pipes =
5959 master_crtc_state->bigjoiner_pipes;
5961 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
5969 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
5970 struct intel_crtc *master_crtc)
5972 struct drm_i915_private *i915 = to_i915(state->base.dev);
5973 struct intel_crtc_state *master_crtc_state =
5974 intel_atomic_get_new_crtc_state(state, master_crtc);
5975 struct intel_crtc *slave_crtc;
5977 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5978 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5979 struct intel_crtc_state *slave_crtc_state =
5980 intel_atomic_get_new_crtc_state(state, slave_crtc);
5982 slave_crtc_state->bigjoiner_pipes = 0;
5984 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
5987 master_crtc_state->bigjoiner_pipes = 0;
5991 * DOC: asynchronous flip implementation
5993 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
5994 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
5995 * Correspondingly, support is currently added for primary plane only.
5997 * Async flip can only change the plane surface address, so anything else
5998 * changing is rejected from the intel_async_flip_check_hw() function.
5999 * Once this check is cleared, flip done interrupt is enabled using
6000 * the intel_crtc_enable_flip_done() function.
6002 * As soon as the surface address register is written, flip done interrupt is
6003 * generated and the requested events are sent to the usersapce in the interrupt
6004 * handler itself. The timestamp and sequence sent during the flip done event
6005 * correspond to the last vblank and have no relation to the actual time when
6006 * the flip done event was sent.
6008 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
6009 struct intel_crtc *crtc)
6011 struct drm_i915_private *i915 = to_i915(state->base.dev);
6012 const struct intel_crtc_state *new_crtc_state =
6013 intel_atomic_get_new_crtc_state(state, crtc);
6014 const struct intel_plane_state *old_plane_state;
6015 struct intel_plane_state *new_plane_state;
6016 struct intel_plane *plane;
6019 if (!new_crtc_state->uapi.async_flip)
6022 if (!new_crtc_state->uapi.active) {
6023 drm_dbg_kms(&i915->drm,
6024 "[CRTC:%d:%s] not active\n",
6025 crtc->base.base.id, crtc->base.name);
6029 if (intel_crtc_needs_modeset(new_crtc_state)) {
6030 drm_dbg_kms(&i915->drm,
6031 "[CRTC:%d:%s] modeset required\n",
6032 crtc->base.base.id, crtc->base.name);
6036 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6037 new_plane_state, i) {
6038 if (plane->pipe != crtc->pipe)
6042 * TODO: Async flip is only supported through the page flip IOCTL
6043 * as of now. So support currently added for primary plane only.
6044 * Support for other planes on platforms on which supports
6045 * this(vlv/chv and icl+) should be added when async flip is
6046 * enabled in the atomic IOCTL path.
6048 if (!plane->async_flip) {
6049 drm_dbg_kms(&i915->drm,
6050 "[PLANE:%d:%s] async flip not supported\n",
6051 plane->base.base.id, plane->base.name);
6055 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
6056 drm_dbg_kms(&i915->drm,
6057 "[PLANE:%d:%s] no old or new framebuffer\n",
6058 plane->base.base.id, plane->base.name);
6066 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
6068 struct drm_i915_private *i915 = to_i915(state->base.dev);
6069 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6070 const struct intel_plane_state *new_plane_state, *old_plane_state;
6071 struct intel_plane *plane;
6074 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
6075 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6077 if (!new_crtc_state->uapi.async_flip)
6080 if (!new_crtc_state->hw.active) {
6081 drm_dbg_kms(&i915->drm,
6082 "[CRTC:%d:%s] not active\n",
6083 crtc->base.base.id, crtc->base.name);
6087 if (intel_crtc_needs_modeset(new_crtc_state)) {
6088 drm_dbg_kms(&i915->drm,
6089 "[CRTC:%d:%s] modeset required\n",
6090 crtc->base.base.id, crtc->base.name);
6094 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6095 drm_dbg_kms(&i915->drm,
6096 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6097 crtc->base.base.id, crtc->base.name);
6101 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6102 new_plane_state, i) {
6103 if (plane->pipe != crtc->pipe)
6107 * Only async flip capable planes should be in the state
6108 * if we're really about to ask the hardware to perform
6109 * an async flip. We should never get this far otherwise.
6111 if (drm_WARN_ON(&i915->drm,
6112 new_crtc_state->do_async_flip && !plane->async_flip))
6116 * Only check async flip capable planes other planes
6117 * may be involved in the initial commit due to
6118 * the wm0/ddb optimization.
6120 * TODO maybe should track which planes actually
6121 * were requested to do the async flip...
6123 if (!plane->async_flip)
6127 * FIXME: This check is kept generic for all platforms.
6128 * Need to verify this for all gen9 platforms to enable
6129 * this selectively if required.
6131 switch (new_plane_state->hw.fb->modifier) {
6132 case DRM_FORMAT_MOD_LINEAR:
6134 * FIXME: Async on Linear buffer is supported on ICL as
6135 * but with additional alignment and fbc restrictions
6136 * need to be taken care of. These aren't applicable for
6139 if (DISPLAY_VER(i915) < 12) {
6140 drm_dbg_kms(&i915->drm,
6141 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip on display ver %d\n",
6142 plane->base.base.id, plane->base.name,
6143 new_plane_state->hw.fb->modifier, DISPLAY_VER(i915));
6148 case I915_FORMAT_MOD_X_TILED:
6149 case I915_FORMAT_MOD_Y_TILED:
6150 case I915_FORMAT_MOD_Yf_TILED:
6151 case I915_FORMAT_MOD_4_TILED:
6154 drm_dbg_kms(&i915->drm,
6155 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip\n",
6156 plane->base.base.id, plane->base.name,
6157 new_plane_state->hw.fb->modifier);
6161 if (new_plane_state->hw.fb->format->num_planes > 1) {
6162 drm_dbg_kms(&i915->drm,
6163 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6164 plane->base.base.id, plane->base.name);
6168 if (old_plane_state->view.color_plane[0].mapping_stride !=
6169 new_plane_state->view.color_plane[0].mapping_stride) {
6170 drm_dbg_kms(&i915->drm,
6171 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6172 plane->base.base.id, plane->base.name);
6176 if (old_plane_state->hw.fb->modifier !=
6177 new_plane_state->hw.fb->modifier) {
6178 drm_dbg_kms(&i915->drm,
6179 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6180 plane->base.base.id, plane->base.name);
6184 if (old_plane_state->hw.fb->format !=
6185 new_plane_state->hw.fb->format) {
6186 drm_dbg_kms(&i915->drm,
6187 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6188 plane->base.base.id, plane->base.name);
6192 if (old_plane_state->hw.rotation !=
6193 new_plane_state->hw.rotation) {
6194 drm_dbg_kms(&i915->drm,
6195 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6196 plane->base.base.id, plane->base.name);
6200 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6201 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6202 drm_dbg_kms(&i915->drm,
6203 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6204 plane->base.base.id, plane->base.name);
6208 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6209 drm_dbg_kms(&i915->drm,
6210 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6211 plane->base.base.id, plane->base.name);
6215 if (old_plane_state->hw.pixel_blend_mode !=
6216 new_plane_state->hw.pixel_blend_mode) {
6217 drm_dbg_kms(&i915->drm,
6218 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6219 plane->base.base.id, plane->base.name);
6223 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6224 drm_dbg_kms(&i915->drm,
6225 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6226 plane->base.base.id, plane->base.name);
6230 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6231 drm_dbg_kms(&i915->drm,
6232 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6233 plane->base.base.id, plane->base.name);
6237 /* plane decryption is allow to change only in synchronous flips */
6238 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6239 drm_dbg_kms(&i915->drm,
6240 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6241 plane->base.base.id, plane->base.name);
6249 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6251 struct drm_i915_private *i915 = to_i915(state->base.dev);
6252 struct intel_crtc_state *crtc_state;
6253 struct intel_crtc *crtc;
6254 u8 affected_pipes = 0;
6255 u8 modeset_pipes = 0;
6258 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6259 affected_pipes |= crtc_state->bigjoiner_pipes;
6260 if (intel_crtc_needs_modeset(crtc_state))
6261 modeset_pipes |= crtc_state->bigjoiner_pipes;
6264 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6265 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6266 if (IS_ERR(crtc_state))
6267 return PTR_ERR(crtc_state);
6270 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6273 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6275 crtc_state->uapi.mode_changed = true;
6277 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6281 ret = intel_atomic_add_affected_planes(state, crtc);
6286 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6287 /* Kill old bigjoiner link, we may re-establish afterwards */
6288 if (intel_crtc_needs_modeset(crtc_state) &&
6289 intel_crtc_is_bigjoiner_master(crtc_state))
6290 kill_bigjoiner_slave(state, crtc);
6296 static int intel_atomic_check_config(struct intel_atomic_state *state,
6297 struct intel_link_bw_limits *limits,
6298 enum pipe *failed_pipe)
6300 struct drm_i915_private *i915 = to_i915(state->base.dev);
6301 struct intel_crtc_state *new_crtc_state;
6302 struct intel_crtc *crtc;
6306 *failed_pipe = INVALID_PIPE;
6308 ret = intel_bigjoiner_add_affected_crtcs(state);
6312 ret = intel_fdi_add_affected_crtcs(state);
6316 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6317 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6318 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6319 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6321 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6325 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6326 drm_WARN_ON(&i915->drm, new_crtc_state->uapi.enable);
6330 ret = intel_crtc_prepare_cleared_state(state, crtc);
6334 if (!new_crtc_state->hw.enable)
6337 ret = intel_modeset_pipe_config(state, crtc, limits);
6341 ret = intel_atomic_check_bigjoiner(state, crtc);
6347 *failed_pipe = crtc->pipe;
6352 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state)
6354 struct drm_i915_private *i915 = to_i915(state->base.dev);
6355 struct intel_link_bw_limits new_limits;
6356 struct intel_link_bw_limits old_limits;
6359 intel_link_bw_init_limits(i915, &new_limits);
6360 old_limits = new_limits;
6363 enum pipe failed_pipe;
6365 ret = intel_atomic_check_config(state, &new_limits,
6369 * The bpp limit for a pipe is below the minimum it supports, set the
6370 * limit to the minimum and recalculate the config.
6372 if (ret == -EINVAL &&
6373 intel_link_bw_set_bpp_limit_for_pipe(state,
6382 old_limits = new_limits;
6384 ret = intel_link_bw_atomic_check(state, &new_limits);
6392 * intel_atomic_check - validate state object
6394 * @_state: state to validate
6396 int intel_atomic_check(struct drm_device *dev,
6397 struct drm_atomic_state *_state)
6399 struct drm_i915_private *dev_priv = to_i915(dev);
6400 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6401 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6402 struct intel_crtc *crtc;
6404 bool any_ms = false;
6406 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6407 new_crtc_state, i) {
6409 * crtc's state no longer considered to be inherited
6410 * after the first userspace/client initiated commit.
6412 if (!state->internal)
6413 new_crtc_state->inherited = false;
6415 if (new_crtc_state->inherited != old_crtc_state->inherited)
6416 new_crtc_state->uapi.mode_changed = true;
6418 if (new_crtc_state->uapi.scaling_filter !=
6419 old_crtc_state->uapi.scaling_filter)
6420 new_crtc_state->uapi.mode_changed = true;
6423 intel_vrr_check_modeset(state);
6425 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6429 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6430 ret = intel_async_flip_check_uapi(state, crtc);
6435 ret = intel_atomic_check_config_and_link(state);
6439 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6440 new_crtc_state, i) {
6441 if (!intel_crtc_needs_modeset(new_crtc_state))
6444 if (new_crtc_state->hw.enable) {
6445 ret = intel_modeset_pipe_config_late(state, crtc);
6450 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6454 * Check if fastset is allowed by external dependencies like other
6455 * pipes and transcoders.
6457 * Right now it only forces a fullmodeset when the MST master
6458 * transcoder did not changed but the pipe of the master transcoder
6459 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6460 * in case of port synced crtcs, if one of the synced crtcs
6461 * needs a full modeset, all other synced crtcs should be
6462 * forced a full modeset.
6464 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6465 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6468 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6469 enum transcoder master = new_crtc_state->mst_master_transcoder;
6471 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
6472 new_crtc_state->uapi.mode_changed = true;
6473 new_crtc_state->update_pipe = false;
6474 new_crtc_state->update_m_n = false;
6475 new_crtc_state->update_lrr = false;
6479 if (is_trans_port_sync_mode(new_crtc_state)) {
6480 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6482 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6483 trans |= BIT(new_crtc_state->master_transcoder);
6485 if (intel_cpu_transcoders_need_modeset(state, trans)) {
6486 new_crtc_state->uapi.mode_changed = true;
6487 new_crtc_state->update_pipe = false;
6488 new_crtc_state->update_m_n = false;
6489 new_crtc_state->update_lrr = false;
6493 if (new_crtc_state->bigjoiner_pipes) {
6494 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes)) {
6495 new_crtc_state->uapi.mode_changed = true;
6496 new_crtc_state->update_pipe = false;
6497 new_crtc_state->update_m_n = false;
6498 new_crtc_state->update_lrr = false;
6503 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6504 new_crtc_state, i) {
6505 if (!intel_crtc_needs_modeset(new_crtc_state))
6510 intel_release_shared_dplls(state, crtc);
6513 if (any_ms && !check_digital_port_conflicts(state)) {
6514 drm_dbg_kms(&dev_priv->drm,
6515 "rejecting conflicting digital port configuration\n");
6520 ret = drm_dp_mst_atomic_check(&state->base);
6524 ret = intel_atomic_check_planes(state);
6528 ret = intel_compute_global_watermarks(state);
6532 ret = intel_bw_atomic_check(state);
6536 ret = intel_cdclk_atomic_check(state, &any_ms);
6540 if (intel_any_crtc_needs_modeset(state))
6544 ret = intel_modeset_checks(state);
6548 ret = intel_modeset_calc_cdclk(state);
6553 ret = intel_pmdemand_atomic_check(state);
6557 ret = intel_atomic_check_crtcs(state);
6561 ret = intel_fbc_atomic_check(state);
6565 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6566 new_crtc_state, i) {
6567 intel_color_assert_luts(new_crtc_state);
6569 ret = intel_async_flip_check_hw(state, crtc);
6573 /* Either full modeset or fastset (or neither), never both */
6574 drm_WARN_ON(&dev_priv->drm,
6575 intel_crtc_needs_modeset(new_crtc_state) &&
6576 intel_crtc_needs_fastset(new_crtc_state));
6578 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6579 !intel_crtc_needs_fastset(new_crtc_state))
6582 intel_crtc_state_dump(new_crtc_state, state,
6583 intel_crtc_needs_modeset(new_crtc_state) ?
6584 "modeset" : "fastset");
6590 if (ret == -EDEADLK)
6594 * FIXME would probably be nice to know which crtc specifically
6595 * caused the failure, in cases where we can pinpoint it.
6597 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6599 intel_crtc_state_dump(new_crtc_state, state, "failed");
6604 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6606 struct intel_crtc_state *crtc_state;
6607 struct intel_crtc *crtc;
6610 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6614 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6615 if (intel_crtc_needs_color_update(crtc_state))
6616 intel_color_prepare_commit(crtc_state);
6622 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
6623 struct intel_crtc_state *crtc_state)
6625 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6627 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
6628 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
6630 if (crtc_state->has_pch_encoder) {
6631 enum pipe pch_transcoder =
6632 intel_crtc_pch_transcoder(crtc);
6634 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
6638 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
6639 const struct intel_crtc_state *new_crtc_state)
6641 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6642 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6645 * Update pipe size and adjust fitter if needed: the reason for this is
6646 * that in compute_mode_changes we check the native mode (not the pfit
6647 * mode) to see if we can flip rather than do a full mode set. In the
6648 * fastboot case, we'll flip, but if we don't update the pipesrc and
6649 * pfit state, we'll end up with a big fb scanned out into the wrong
6652 intel_set_pipe_src_size(new_crtc_state);
6654 /* on skylake this is done by detaching scalers */
6655 if (DISPLAY_VER(dev_priv) >= 9) {
6656 if (new_crtc_state->pch_pfit.enabled)
6657 skl_pfit_enable(new_crtc_state);
6658 } else if (HAS_PCH_SPLIT(dev_priv)) {
6659 if (new_crtc_state->pch_pfit.enabled)
6660 ilk_pfit_enable(new_crtc_state);
6661 else if (old_crtc_state->pch_pfit.enabled)
6662 ilk_pfit_disable(old_crtc_state);
6666 * The register is supposedly single buffered so perhaps
6667 * not 100% correct to do this here. But SKL+ calculate
6668 * this based on the adjust pixel rate so pfit changes do
6669 * affect it and so it must be updated for fastsets.
6670 * HSW/BDW only really need this here for fastboot, after
6671 * that the value should not change without a full modeset.
6673 if (DISPLAY_VER(dev_priv) >= 9 ||
6674 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
6675 hsw_set_linetime_wm(new_crtc_state);
6677 if (new_crtc_state->update_m_n)
6678 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
6679 &new_crtc_state->dp_m_n);
6681 if (new_crtc_state->update_lrr)
6682 intel_set_transcoder_timings_lrr(new_crtc_state);
6685 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
6686 struct intel_crtc *crtc)
6688 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6689 const struct intel_crtc_state *old_crtc_state =
6690 intel_atomic_get_old_crtc_state(state, crtc);
6691 const struct intel_crtc_state *new_crtc_state =
6692 intel_atomic_get_new_crtc_state(state, crtc);
6693 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6696 * During modesets pipe configuration was programmed as the
6700 if (intel_crtc_needs_color_update(new_crtc_state))
6701 intel_color_commit_arm(new_crtc_state);
6703 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6704 bdw_set_pipe_misc(new_crtc_state);
6706 if (intel_crtc_needs_fastset(new_crtc_state))
6707 intel_pipe_fastset(old_crtc_state, new_crtc_state);
6710 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
6712 intel_atomic_update_watermarks(state, crtc);
6715 static void commit_pipe_post_planes(struct intel_atomic_state *state,
6716 struct intel_crtc *crtc)
6718 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6719 const struct intel_crtc_state *old_crtc_state =
6720 intel_atomic_get_old_crtc_state(state, crtc);
6721 const struct intel_crtc_state *new_crtc_state =
6722 intel_atomic_get_new_crtc_state(state, crtc);
6725 * Disable the scaler(s) after the plane(s) so that we don't
6726 * get a catastrophic underrun even if the two operations
6727 * end up happening in two different frames.
6729 if (DISPLAY_VER(dev_priv) >= 9 &&
6730 !intel_crtc_needs_modeset(new_crtc_state))
6731 skl_detach_scalers(new_crtc_state);
6733 if (vrr_enabling(old_crtc_state, new_crtc_state))
6734 intel_vrr_enable(new_crtc_state);
6737 static void intel_enable_crtc(struct intel_atomic_state *state,
6738 struct intel_crtc *crtc)
6740 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6741 const struct intel_crtc_state *new_crtc_state =
6742 intel_atomic_get_new_crtc_state(state, crtc);
6744 if (!intel_crtc_needs_modeset(new_crtc_state))
6747 /* VRR will be enable later, if required */
6748 intel_crtc_update_active_timings(new_crtc_state, false);
6750 dev_priv->display.funcs.display->crtc_enable(state, crtc);
6752 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6755 /* vblanks work again, re-enable pipe CRC. */
6756 intel_crtc_enable_pipe_crc(crtc);
6759 static void intel_update_crtc(struct intel_atomic_state *state,
6760 struct intel_crtc *crtc)
6762 struct drm_i915_private *i915 = to_i915(state->base.dev);
6763 const struct intel_crtc_state *old_crtc_state =
6764 intel_atomic_get_old_crtc_state(state, crtc);
6765 struct intel_crtc_state *new_crtc_state =
6766 intel_atomic_get_new_crtc_state(state, crtc);
6767 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6769 if (old_crtc_state->inherited ||
6770 intel_crtc_needs_modeset(new_crtc_state)) {
6772 intel_dpt_configure(crtc);
6776 if (new_crtc_state->preload_luts &&
6777 intel_crtc_needs_color_update(new_crtc_state))
6778 intel_color_load_luts(new_crtc_state);
6780 intel_pre_plane_update(state, crtc);
6782 if (intel_crtc_needs_fastset(new_crtc_state))
6783 intel_encoders_update_pipe(state, crtc);
6785 if (DISPLAY_VER(i915) >= 11 &&
6786 intel_crtc_needs_fastset(new_crtc_state))
6787 icl_set_pipe_chicken(new_crtc_state);
6789 if (vrr_params_changed(old_crtc_state, new_crtc_state))
6790 intel_vrr_set_transcoder_timings(new_crtc_state);
6793 intel_fbc_update(state, crtc);
6795 drm_WARN_ON(&i915->drm, !intel_display_power_is_enabled(i915, POWER_DOMAIN_DC_OFF));
6798 intel_crtc_needs_color_update(new_crtc_state))
6799 intel_color_commit_noarm(new_crtc_state);
6801 intel_crtc_planes_update_noarm(state, crtc);
6803 /* Perform vblank evasion around commit operation */
6804 intel_pipe_update_start(state, crtc);
6806 commit_pipe_pre_planes(state, crtc);
6808 intel_crtc_planes_update_arm(state, crtc);
6810 commit_pipe_post_planes(state, crtc);
6812 intel_pipe_update_end(state, crtc);
6815 * VRR/Seamless M/N update may need to update frame timings.
6817 * FIXME Should be synchronized with the start of vblank somehow...
6819 if (vrr_enabling(old_crtc_state, new_crtc_state) ||
6820 new_crtc_state->update_m_n || new_crtc_state->update_lrr)
6821 intel_crtc_update_active_timings(new_crtc_state,
6822 new_crtc_state->vrr.enable);
6825 * We usually enable FIFO underrun interrupts as part of the
6826 * CRTC enable sequence during modesets. But when we inherit a
6827 * valid pipe configuration from the BIOS we need to take care
6828 * of enabling them on the CRTC's first fastset.
6830 if (intel_crtc_needs_fastset(new_crtc_state) && !modeset &&
6831 old_crtc_state->inherited)
6832 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
6835 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
6836 struct intel_crtc_state *old_crtc_state,
6837 struct intel_crtc_state *new_crtc_state,
6838 struct intel_crtc *crtc)
6840 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6843 * We need to disable pipe CRC before disabling the pipe,
6844 * or we race against vblank off.
6846 intel_crtc_disable_pipe_crc(crtc);
6848 dev_priv->display.funcs.display->crtc_disable(state, crtc);
6849 crtc->active = false;
6850 intel_fbc_disable(crtc);
6852 if (!new_crtc_state->hw.active)
6853 intel_initial_watermarks(state, crtc);
6856 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
6858 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6859 struct intel_crtc *crtc;
6863 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6864 new_crtc_state, i) {
6865 if (!intel_crtc_needs_modeset(new_crtc_state))
6868 intel_pre_plane_update(state, crtc);
6870 if (!old_crtc_state->hw.active)
6873 intel_crtc_disable_planes(state, crtc);
6876 /* Only disable port sync and MST slaves */
6877 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6878 new_crtc_state, i) {
6879 if (!intel_crtc_needs_modeset(new_crtc_state))
6882 if (!old_crtc_state->hw.active)
6885 /* In case of Transcoder port Sync master slave CRTCs can be
6886 * assigned in any order and we need to make sure that
6887 * slave CRTCs are disabled first and then master CRTC since
6888 * Slave vblanks are masked till Master Vblanks.
6890 if (!is_trans_port_sync_slave(old_crtc_state) &&
6891 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
6892 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
6895 intel_old_crtc_state_disables(state, old_crtc_state,
6896 new_crtc_state, crtc);
6897 handled |= BIT(crtc->pipe);
6900 /* Disable everything else left on */
6901 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6902 new_crtc_state, i) {
6903 if (!intel_crtc_needs_modeset(new_crtc_state) ||
6904 (handled & BIT(crtc->pipe)))
6907 if (!old_crtc_state->hw.active)
6910 intel_old_crtc_state_disables(state, old_crtc_state,
6911 new_crtc_state, crtc);
6915 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
6917 struct intel_crtc_state *new_crtc_state;
6918 struct intel_crtc *crtc;
6921 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6922 if (!new_crtc_state->hw.active)
6925 intel_enable_crtc(state, crtc);
6926 intel_update_crtc(state, crtc);
6930 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
6932 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6933 struct intel_crtc *crtc;
6934 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6935 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6936 u8 update_pipes = 0, modeset_pipes = 0;
6939 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
6940 enum pipe pipe = crtc->pipe;
6942 if (!new_crtc_state->hw.active)
6945 /* ignore allocations for crtc's that have been turned off. */
6946 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6947 entries[pipe] = old_crtc_state->wm.skl.ddb;
6948 update_pipes |= BIT(pipe);
6950 modeset_pipes |= BIT(pipe);
6955 * Whenever the number of active pipes changes, we need to make sure we
6956 * update the pipes in the right order so that their ddb allocations
6957 * never overlap with each other between CRTC updates. Otherwise we'll
6958 * cause pipe underruns and other bad stuff.
6960 * So first lets enable all pipes that do not need a fullmodeset as
6961 * those don't have any external dependency.
6963 while (update_pipes) {
6964 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6965 new_crtc_state, i) {
6966 enum pipe pipe = crtc->pipe;
6968 if ((update_pipes & BIT(pipe)) == 0)
6971 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6972 entries, I915_MAX_PIPES, pipe))
6975 entries[pipe] = new_crtc_state->wm.skl.ddb;
6976 update_pipes &= ~BIT(pipe);
6978 intel_update_crtc(state, crtc);
6981 * If this is an already active pipe, it's DDB changed,
6982 * and this isn't the last pipe that needs updating
6983 * then we need to wait for a vblank to pass for the
6984 * new ddb allocation to take effect.
6986 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
6987 &old_crtc_state->wm.skl.ddb) &&
6988 (update_pipes | modeset_pipes))
6989 intel_crtc_wait_for_next_vblank(crtc);
6993 update_pipes = modeset_pipes;
6996 * Enable all pipes that needs a modeset and do not depends on other
6999 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7000 enum pipe pipe = crtc->pipe;
7002 if ((modeset_pipes & BIT(pipe)) == 0)
7005 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
7006 is_trans_port_sync_master(new_crtc_state) ||
7007 intel_crtc_is_bigjoiner_master(new_crtc_state))
7010 modeset_pipes &= ~BIT(pipe);
7012 intel_enable_crtc(state, crtc);
7016 * Then we enable all remaining pipes that depend on other
7017 * pipes: MST slaves and port sync masters, big joiner master
7019 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7020 enum pipe pipe = crtc->pipe;
7022 if ((modeset_pipes & BIT(pipe)) == 0)
7025 modeset_pipes &= ~BIT(pipe);
7027 intel_enable_crtc(state, crtc);
7031 * Finally we do the plane updates/etc. for all pipes that got enabled.
7033 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7034 enum pipe pipe = crtc->pipe;
7036 if ((update_pipes & BIT(pipe)) == 0)
7039 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7040 entries, I915_MAX_PIPES, pipe));
7042 entries[pipe] = new_crtc_state->wm.skl.ddb;
7043 update_pipes &= ~BIT(pipe);
7045 intel_update_crtc(state, crtc);
7048 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
7049 drm_WARN_ON(&dev_priv->drm, update_pipes);
7052 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
7054 struct intel_atomic_state *state, *next;
7055 struct llist_node *freed;
7057 freed = llist_del_all(&dev_priv->display.atomic_helper.free_list);
7058 llist_for_each_entry_safe(state, next, freed, freed)
7059 drm_atomic_state_put(&state->base);
7062 void intel_atomic_helper_free_state_worker(struct work_struct *work)
7064 struct drm_i915_private *dev_priv =
7065 container_of(work, typeof(*dev_priv), display.atomic_helper.free_work);
7067 intel_atomic_helper_free_state(dev_priv);
7070 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
7072 struct wait_queue_entry wait_fence, wait_reset;
7073 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
7075 init_wait_entry(&wait_fence, 0);
7076 init_wait_entry(&wait_reset, 0);
7078 prepare_to_wait(&intel_state->commit_ready.wait,
7079 &wait_fence, TASK_UNINTERRUPTIBLE);
7080 prepare_to_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7081 I915_RESET_MODESET),
7082 &wait_reset, TASK_UNINTERRUPTIBLE);
7085 if (i915_sw_fence_done(&intel_state->commit_ready) ||
7086 test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags))
7091 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
7092 finish_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7093 I915_RESET_MODESET),
7097 static void intel_atomic_cleanup_work(struct work_struct *work)
7099 struct intel_atomic_state *state =
7100 container_of(work, struct intel_atomic_state, base.commit_work);
7101 struct drm_i915_private *i915 = to_i915(state->base.dev);
7102 struct intel_crtc_state *old_crtc_state;
7103 struct intel_crtc *crtc;
7106 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
7107 intel_color_cleanup_commit(old_crtc_state);
7109 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
7110 drm_atomic_helper_commit_cleanup_done(&state->base);
7111 drm_atomic_state_put(&state->base);
7113 intel_atomic_helper_free_state(i915);
7116 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7118 struct drm_i915_private *i915 = to_i915(state->base.dev);
7119 struct intel_plane *plane;
7120 struct intel_plane_state *plane_state;
7123 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7124 struct drm_framebuffer *fb = plane_state->hw.fb;
7131 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7136 * The layout of the fast clear color value expected by HW
7137 * (the DRM ABI requiring this value to be located in fb at
7138 * offset 0 of cc plane, plane #2 previous generations or
7139 * plane #1 for flat ccs):
7140 * - 4 x 4 bytes per-channel value
7141 * (in surface type specific float/int format provided by the fb user)
7142 * - 8 bytes native color value used by the display
7143 * (converted/written by GPU during a fast clear operation using the
7144 * above per-channel values)
7146 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7147 * caller made sure that the object is synced wrt. the related color clear value
7150 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
7151 fb->offsets[cc_plane] + 16,
7152 &plane_state->ccval,
7153 sizeof(plane_state->ccval));
7154 /* The above could only fail if the FB obj has an unexpected backing store type. */
7155 drm_WARN_ON(&i915->drm, ret);
7159 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7161 struct drm_device *dev = state->base.dev;
7162 struct drm_i915_private *dev_priv = to_i915(dev);
7163 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7164 struct intel_crtc *crtc;
7165 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7166 intel_wakeref_t wakeref = 0;
7169 intel_atomic_commit_fence_wait(state);
7171 drm_atomic_helper_wait_for_dependencies(&state->base);
7172 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
7175 * During full modesets we write a lot of registers, wait
7176 * for PLLs, etc. Doing that while DC states are enabled
7177 * is not a good idea.
7179 * During fastsets and other updates we also need to
7180 * disable DC states due to the following scenario:
7181 * 1. DC5 exit and PSR exit happen
7182 * 2. Some or all _noarm() registers are written
7183 * 3. Due to some long delay PSR is re-entered
7184 * 4. DC5 entry -> DMC saves the already written new
7185 * _noarm() registers and the old not yet written
7187 * 5. DC5 exit -> DMC restores a mixture of old and
7188 * new register values and arms the update
7189 * 6. PSR exit -> hardware latches a mixture of old and
7190 * new register values -> corrupted frame, or worse
7191 * 7. New _arm() registers are finally written
7192 * 8. Hardware finally latches a complete set of new
7193 * register values, and subsequent frames will be OK again
7195 * Also note that due to the pipe CSC hardware issues on
7196 * SKL/GLK DC states must remain off until the pipe CSC
7197 * state readout has happened. Otherwise we risk corrupting
7198 * the CSC latched register values with the readout (see
7199 * skl_read_csc() and skl_color_commit_noarm()).
7201 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DC_OFF);
7203 intel_atomic_prepare_plane_clear_colors(state);
7205 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7206 new_crtc_state, i) {
7207 if (intel_crtc_needs_modeset(new_crtc_state) ||
7208 intel_crtc_needs_fastset(new_crtc_state))
7209 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7212 intel_commit_modeset_disables(state);
7214 /* FIXME: Eventually get rid of our crtc->config pointer */
7215 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7216 crtc->config = new_crtc_state;
7219 * In XE_LPD+ Pmdemand combines many parameters such as voltage index,
7220 * plls, cdclk frequency, QGV point selection parameter etc. Voltage
7221 * index, cdclk/ddiclk frequencies are supposed to be configured before
7222 * the cdclk config is set.
7224 intel_pmdemand_pre_plane_update(state);
7226 if (state->modeset) {
7227 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7229 intel_set_cdclk_pre_plane_update(state);
7231 intel_modeset_verify_disabled(state);
7234 intel_sagv_pre_plane_update(state);
7236 /* Complete the events for pipes that have now been disabled */
7237 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7238 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7240 /* Complete events for now disable pipes here. */
7241 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7242 spin_lock_irq(&dev->event_lock);
7243 drm_crtc_send_vblank_event(&crtc->base,
7244 new_crtc_state->uapi.event);
7245 spin_unlock_irq(&dev->event_lock);
7247 new_crtc_state->uapi.event = NULL;
7251 intel_encoders_update_prepare(state);
7253 intel_dbuf_pre_plane_update(state);
7254 intel_mbus_dbox_update(state);
7256 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7257 if (new_crtc_state->do_async_flip)
7258 intel_crtc_enable_flip_done(state, crtc);
7261 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7262 dev_priv->display.funcs.display->commit_modeset_enables(state);
7265 intel_set_cdclk_post_plane_update(state);
7267 intel_wait_for_vblank_workers(state);
7269 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7270 * already, but still need the state for the delayed optimization. To
7272 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7273 * - schedule that vblank worker _before_ calling hw_done
7274 * - at the start of commit_tail, cancel it _synchrously
7275 * - switch over to the vblank wait helper in the core after that since
7276 * we don't need out special handling any more.
7278 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7280 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7281 if (new_crtc_state->do_async_flip)
7282 intel_crtc_disable_flip_done(state, crtc);
7284 intel_color_wait_commit(new_crtc_state);
7288 * Now that the vblank has passed, we can go ahead and program the
7289 * optimal watermarks on platforms that need two-step watermark
7292 * TODO: Move this (and other cleanup) to an async worker eventually.
7294 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7295 new_crtc_state, i) {
7297 * Gen2 reports pipe underruns whenever all planes are disabled.
7298 * So re-enable underrun reporting after some planes get enabled.
7300 * We do this before .optimize_watermarks() so that we have a
7301 * chance of catching underruns with the intermediate watermarks
7302 * vs. the new plane configuration.
7304 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7305 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7307 intel_optimize_watermarks(state, crtc);
7310 intel_dbuf_post_plane_update(state);
7312 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7313 intel_post_plane_update(state, crtc);
7315 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7317 intel_modeset_verify_crtc(state, crtc);
7319 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
7320 hsw_ips_post_update(state, crtc);
7323 * Activate DRRS after state readout to avoid
7324 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
7326 intel_drrs_activate(new_crtc_state);
7329 * DSB cleanup is done in cleanup_work aligning with framebuffer
7330 * cleanup. So copy and reset the dsb structure to sync with
7331 * commit_done and later do dsb cleanup in cleanup_work.
7333 * FIXME get rid of this funny new->old swapping
7335 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7338 /* Underruns don't always raise interrupts, so check manually */
7339 intel_check_cpu_fifo_underruns(dev_priv);
7340 intel_check_pch_fifo_underruns(dev_priv);
7343 intel_verify_planes(state);
7345 intel_sagv_post_plane_update(state);
7346 intel_pmdemand_post_plane_update(state);
7348 drm_atomic_helper_commit_hw_done(&state->base);
7350 if (state->modeset) {
7351 /* As one of the primary mmio accessors, KMS has a high
7352 * likelihood of triggering bugs in unclaimed access. After we
7353 * finish modesetting, see if an error has been flagged, and if
7354 * so enable debugging for the next modeset - and hope we catch
7357 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7360 * Delay re-enabling DC states by 17 ms to avoid the off->on->off
7361 * toggling overhead at and above 60 FPS.
7363 intel_display_power_put_async_delay(dev_priv, POWER_DOMAIN_DC_OFF, wakeref, 17);
7364 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7367 * Defer the cleanup of the old state to a separate worker to not
7368 * impede the current task (userspace for blocking modesets) that
7369 * are executed inline. For out-of-line asynchronous modesets/flips,
7370 * deferring to a new worker seems overkill, but we would place a
7371 * schedule point (cond_resched()) here anyway to keep latencies
7374 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7375 queue_work(system_highpri_wq, &state->base.commit_work);
7378 static void intel_atomic_commit_work(struct work_struct *work)
7380 struct intel_atomic_state *state =
7381 container_of(work, struct intel_atomic_state, base.commit_work);
7383 intel_atomic_commit_tail(state);
7387 intel_atomic_commit_ready(struct i915_sw_fence *fence,
7388 enum i915_sw_fence_notify notify)
7390 struct intel_atomic_state *state =
7391 container_of(fence, struct intel_atomic_state, commit_ready);
7394 case FENCE_COMPLETE:
7395 /* we do blocking waits in the worker, nothing to do here */
7399 struct drm_i915_private *i915 = to_i915(state->base.dev);
7400 struct intel_atomic_helper *helper =
7401 &i915->display.atomic_helper;
7403 if (llist_add(&state->freed, &helper->free_list))
7404 queue_work(i915->unordered_wq, &helper->free_work);
7412 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7414 struct intel_plane_state *old_plane_state, *new_plane_state;
7415 struct intel_plane *plane;
7418 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7420 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7421 to_intel_frontbuffer(new_plane_state->hw.fb),
7422 plane->frontbuffer_bit);
7425 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7428 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7429 struct drm_i915_private *dev_priv = to_i915(dev);
7432 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7434 drm_atomic_state_get(&state->base);
7435 i915_sw_fence_init(&state->commit_ready,
7436 intel_atomic_commit_ready);
7439 * The intel_legacy_cursor_update() fast path takes care
7440 * of avoiding the vblank waits for simple cursor
7441 * movement and flips. For cursor on/off and size changes,
7442 * we want to perform the vblank waits so that watermark
7443 * updates happen during the correct frames. Gen9+ have
7444 * double buffered watermarks and so shouldn't need this.
7446 * Unset state->legacy_cursor_update before the call to
7447 * drm_atomic_helper_setup_commit() because otherwise
7448 * drm_atomic_helper_wait_for_flip_done() is a noop and
7449 * we get FIFO underruns because we didn't wait
7452 * FIXME doing watermarks and fb cleanup from a vblank worker
7453 * (assuming we had any) would solve these problems.
7455 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7456 struct intel_crtc_state *new_crtc_state;
7457 struct intel_crtc *crtc;
7460 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7461 if (new_crtc_state->wm.need_postvbl_update ||
7462 new_crtc_state->update_wm_post)
7463 state->base.legacy_cursor_update = false;
7466 ret = intel_atomic_prepare_commit(state);
7468 drm_dbg_atomic(&dev_priv->drm,
7469 "Preparing state failed with %i\n", ret);
7470 i915_sw_fence_commit(&state->commit_ready);
7471 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7475 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7477 ret = drm_atomic_helper_swap_state(&state->base, true);
7479 intel_atomic_swap_global_state(state);
7482 struct intel_crtc_state *new_crtc_state;
7483 struct intel_crtc *crtc;
7486 i915_sw_fence_commit(&state->commit_ready);
7488 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7489 intel_color_cleanup_commit(new_crtc_state);
7491 drm_atomic_helper_unprepare_planes(dev, &state->base);
7492 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7495 intel_shared_dpll_swap_state(state);
7496 intel_atomic_track_fbs(state);
7498 drm_atomic_state_get(&state->base);
7499 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7501 i915_sw_fence_commit(&state->commit_ready);
7502 if (nonblock && state->modeset) {
7503 queue_work(dev_priv->display.wq.modeset, &state->base.commit_work);
7504 } else if (nonblock) {
7505 queue_work(dev_priv->display.wq.flip, &state->base.commit_work);
7508 flush_workqueue(dev_priv->display.wq.modeset);
7509 intel_atomic_commit_tail(state);
7516 * intel_plane_destroy - destroy a plane
7517 * @plane: plane to destroy
7519 * Common destruction function for all types of planes (primary, cursor,
7522 void intel_plane_destroy(struct drm_plane *plane)
7524 drm_plane_cleanup(plane);
7525 kfree(to_intel_plane(plane));
7528 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7529 struct drm_file *file)
7531 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7532 struct drm_crtc *drmmode_crtc;
7533 struct intel_crtc *crtc;
7535 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7539 crtc = to_intel_crtc(drmmode_crtc);
7540 pipe_from_crtc_id->pipe = crtc->pipe;
7545 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7547 struct drm_device *dev = encoder->base.dev;
7548 struct intel_encoder *source_encoder;
7549 u32 possible_clones = 0;
7551 for_each_intel_encoder(dev, source_encoder) {
7552 if (encoders_cloneable(encoder, source_encoder))
7553 possible_clones |= drm_encoder_mask(&source_encoder->base);
7556 return possible_clones;
7559 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7561 struct drm_device *dev = encoder->base.dev;
7562 struct intel_crtc *crtc;
7563 u32 possible_crtcs = 0;
7565 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7566 possible_crtcs |= drm_crtc_mask(&crtc->base);
7568 return possible_crtcs;
7571 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7573 if (!IS_MOBILE(dev_priv))
7576 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7579 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7585 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7587 if (DISPLAY_VER(dev_priv) >= 9)
7590 if (IS_HASWELL_ULT(dev_priv) || IS_BROADWELL_ULT(dev_priv))
7593 if (HAS_PCH_LPT_H(dev_priv) &&
7594 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7597 /* DDI E can't be used if DDI A requires 4 lanes */
7598 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7601 if (!dev_priv->display.vbt.int_crt_support)
7607 bool assert_port_valid(struct drm_i915_private *i915, enum port port)
7609 return !drm_WARN(&i915->drm, !(DISPLAY_RUNTIME_INFO(i915)->port_mask & BIT(port)),
7610 "Platform does not support port %c\n", port_name(port));
7613 void intel_setup_outputs(struct drm_i915_private *dev_priv)
7615 struct intel_encoder *encoder;
7616 bool dpd_is_edp = false;
7618 intel_pps_unlock_regs_wa(dev_priv);
7620 if (!HAS_DISPLAY(dev_priv))
7623 if (HAS_DDI(dev_priv)) {
7624 if (intel_ddi_crt_present(dev_priv))
7625 intel_crt_init(dev_priv);
7627 intel_bios_for_each_encoder(dev_priv, intel_ddi_init);
7629 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
7630 vlv_dsi_init(dev_priv);
7631 } else if (HAS_PCH_SPLIT(dev_priv)) {
7635 * intel_edp_init_connector() depends on this completing first,
7636 * to prevent the registration of both eDP and LVDS and the
7637 * incorrect sharing of the PPS.
7639 intel_lvds_init(dev_priv);
7640 intel_crt_init(dev_priv);
7642 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
7644 if (ilk_has_edp_a(dev_priv))
7645 g4x_dp_init(dev_priv, DP_A, PORT_A);
7647 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
7648 /* PCH SDVOB multiplex with HDMIB */
7649 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
7651 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
7652 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
7653 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
7656 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
7657 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
7659 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
7660 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
7662 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
7663 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
7665 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
7666 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
7667 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7668 bool has_edp, has_port;
7670 if (IS_VALLEYVIEW(dev_priv) && dev_priv->display.vbt.int_crt_support)
7671 intel_crt_init(dev_priv);
7674 * The DP_DETECTED bit is the latched state of the DDC
7675 * SDA pin at boot. However since eDP doesn't require DDC
7676 * (no way to plug in a DP->HDMI dongle) the DDC pins for
7677 * eDP ports may have been muxed to an alternate function.
7678 * Thus we can't rely on the DP_DETECTED bit alone to detect
7679 * eDP ports. Consult the VBT as well as DP_DETECTED to
7682 * Sadly the straps seem to be missing sometimes even for HDMI
7683 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
7684 * and VBT for the presence of the port. Additionally we can't
7685 * trust the port type the VBT declares as we've seen at least
7686 * HDMI ports that the VBT claim are DP or eDP.
7688 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
7689 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
7690 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
7691 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
7692 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
7693 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
7695 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
7696 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
7697 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
7698 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
7699 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
7700 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
7702 if (IS_CHERRYVIEW(dev_priv)) {
7704 * eDP not supported on port D,
7705 * so no need to worry about it
7707 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
7708 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
7709 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
7710 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
7711 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
7714 vlv_dsi_init(dev_priv);
7715 } else if (IS_PINEVIEW(dev_priv)) {
7716 intel_lvds_init(dev_priv);
7717 intel_crt_init(dev_priv);
7718 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
7721 if (IS_MOBILE(dev_priv))
7722 intel_lvds_init(dev_priv);
7724 intel_crt_init(dev_priv);
7726 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7727 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
7728 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
7729 if (!found && IS_G4X(dev_priv)) {
7730 drm_dbg_kms(&dev_priv->drm,
7731 "probing HDMI on SDVOB\n");
7732 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
7735 if (!found && IS_G4X(dev_priv))
7736 g4x_dp_init(dev_priv, DP_B, PORT_B);
7739 /* Before G4X SDVOC doesn't have its own detect register */
7741 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7742 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
7743 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
7746 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
7748 if (IS_G4X(dev_priv)) {
7749 drm_dbg_kms(&dev_priv->drm,
7750 "probing HDMI on SDVOC\n");
7751 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
7753 if (IS_G4X(dev_priv))
7754 g4x_dp_init(dev_priv, DP_C, PORT_C);
7757 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
7758 g4x_dp_init(dev_priv, DP_D, PORT_D);
7760 if (SUPPORTS_TV(dev_priv))
7761 intel_tv_init(dev_priv);
7762 } else if (DISPLAY_VER(dev_priv) == 2) {
7763 if (IS_I85X(dev_priv))
7764 intel_lvds_init(dev_priv);
7766 intel_crt_init(dev_priv);
7767 intel_dvo_init(dev_priv);
7770 for_each_intel_encoder(&dev_priv->drm, encoder) {
7771 encoder->base.possible_crtcs =
7772 intel_encoder_possible_crtcs(encoder);
7773 encoder->base.possible_clones =
7774 intel_encoder_possible_clones(encoder);
7777 intel_init_pch_refclk(dev_priv);
7779 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
7782 static int max_dotclock(struct drm_i915_private *i915)
7784 int max_dotclock = i915->max_dotclk_freq;
7786 /* icl+ might use bigjoiner */
7787 if (DISPLAY_VER(i915) >= 11)
7790 return max_dotclock;
7793 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
7794 const struct drm_display_mode *mode)
7796 struct drm_i915_private *dev_priv = to_i915(dev);
7797 int hdisplay_max, htotal_max;
7798 int vdisplay_max, vtotal_max;
7801 * Can't reject DBLSCAN here because Xorg ddxen can add piles
7802 * of DBLSCAN modes to the output's mode list when they detect
7803 * the scaling mode property on the connector. And they don't
7804 * ask the kernel to validate those modes in any way until
7805 * modeset time at which point the client gets a protocol error.
7806 * So in order to not upset those clients we silently ignore the
7807 * DBLSCAN flag on such connectors. For other connectors we will
7808 * reject modes with the DBLSCAN flag in encoder->compute_config().
7809 * And we always reject DBLSCAN modes in connector->mode_valid()
7810 * as we never want such modes on the connector's mode list.
7813 if (mode->vscan > 1)
7814 return MODE_NO_VSCAN;
7816 if (mode->flags & DRM_MODE_FLAG_HSKEW)
7817 return MODE_H_ILLEGAL;
7819 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
7820 DRM_MODE_FLAG_NCSYNC |
7821 DRM_MODE_FLAG_PCSYNC))
7824 if (mode->flags & (DRM_MODE_FLAG_BCAST |
7825 DRM_MODE_FLAG_PIXMUX |
7826 DRM_MODE_FLAG_CLKDIV2))
7830 * Reject clearly excessive dotclocks early to
7831 * avoid having to worry about huge integers later.
7833 if (mode->clock > max_dotclock(dev_priv))
7834 return MODE_CLOCK_HIGH;
7836 /* Transcoder timing limits */
7837 if (DISPLAY_VER(dev_priv) >= 11) {
7838 hdisplay_max = 16384;
7839 vdisplay_max = 8192;
7842 } else if (DISPLAY_VER(dev_priv) >= 9 ||
7843 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
7844 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
7845 vdisplay_max = 4096;
7848 } else if (DISPLAY_VER(dev_priv) >= 3) {
7849 hdisplay_max = 4096;
7850 vdisplay_max = 4096;
7854 hdisplay_max = 2048;
7855 vdisplay_max = 2048;
7860 if (mode->hdisplay > hdisplay_max ||
7861 mode->hsync_start > htotal_max ||
7862 mode->hsync_end > htotal_max ||
7863 mode->htotal > htotal_max)
7864 return MODE_H_ILLEGAL;
7866 if (mode->vdisplay > vdisplay_max ||
7867 mode->vsync_start > vtotal_max ||
7868 mode->vsync_end > vtotal_max ||
7869 mode->vtotal > vtotal_max)
7870 return MODE_V_ILLEGAL;
7875 enum drm_mode_status intel_cpu_transcoder_mode_valid(struct drm_i915_private *dev_priv,
7876 const struct drm_display_mode *mode)
7879 * Additional transcoder timing limits,
7880 * excluding BXT/GLK DSI transcoders.
7882 if (DISPLAY_VER(dev_priv) >= 5) {
7883 if (mode->hdisplay < 64 ||
7884 mode->htotal - mode->hdisplay < 32)
7885 return MODE_H_ILLEGAL;
7887 if (mode->vtotal - mode->vdisplay < 5)
7888 return MODE_V_ILLEGAL;
7890 if (mode->htotal - mode->hdisplay < 32)
7891 return MODE_H_ILLEGAL;
7893 if (mode->vtotal - mode->vdisplay < 3)
7894 return MODE_V_ILLEGAL;
7898 * Cantiga+ cannot handle modes with a hsync front porch of 0.
7899 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7901 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7902 mode->hsync_start == mode->hdisplay)
7903 return MODE_H_ILLEGAL;
7908 enum drm_mode_status
7909 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
7910 const struct drm_display_mode *mode,
7913 int plane_width_max, plane_height_max;
7916 * intel_mode_valid() should be
7917 * sufficient on older platforms.
7919 if (DISPLAY_VER(dev_priv) < 9)
7923 * Most people will probably want a fullscreen
7924 * plane so let's not advertize modes that are
7927 if (DISPLAY_VER(dev_priv) >= 11) {
7928 plane_width_max = 5120 << bigjoiner;
7929 plane_height_max = 4320;
7931 plane_width_max = 5120;
7932 plane_height_max = 4096;
7935 if (mode->hdisplay > plane_width_max)
7936 return MODE_H_ILLEGAL;
7938 if (mode->vdisplay > plane_height_max)
7939 return MODE_V_ILLEGAL;
7944 static const struct intel_display_funcs skl_display_funcs = {
7945 .get_pipe_config = hsw_get_pipe_config,
7946 .crtc_enable = hsw_crtc_enable,
7947 .crtc_disable = hsw_crtc_disable,
7948 .commit_modeset_enables = skl_commit_modeset_enables,
7949 .get_initial_plane_config = skl_get_initial_plane_config,
7952 static const struct intel_display_funcs ddi_display_funcs = {
7953 .get_pipe_config = hsw_get_pipe_config,
7954 .crtc_enable = hsw_crtc_enable,
7955 .crtc_disable = hsw_crtc_disable,
7956 .commit_modeset_enables = intel_commit_modeset_enables,
7957 .get_initial_plane_config = i9xx_get_initial_plane_config,
7960 static const struct intel_display_funcs pch_split_display_funcs = {
7961 .get_pipe_config = ilk_get_pipe_config,
7962 .crtc_enable = ilk_crtc_enable,
7963 .crtc_disable = ilk_crtc_disable,
7964 .commit_modeset_enables = intel_commit_modeset_enables,
7965 .get_initial_plane_config = i9xx_get_initial_plane_config,
7968 static const struct intel_display_funcs vlv_display_funcs = {
7969 .get_pipe_config = i9xx_get_pipe_config,
7970 .crtc_enable = valleyview_crtc_enable,
7971 .crtc_disable = i9xx_crtc_disable,
7972 .commit_modeset_enables = intel_commit_modeset_enables,
7973 .get_initial_plane_config = i9xx_get_initial_plane_config,
7976 static const struct intel_display_funcs i9xx_display_funcs = {
7977 .get_pipe_config = i9xx_get_pipe_config,
7978 .crtc_enable = i9xx_crtc_enable,
7979 .crtc_disable = i9xx_crtc_disable,
7980 .commit_modeset_enables = intel_commit_modeset_enables,
7981 .get_initial_plane_config = i9xx_get_initial_plane_config,
7985 * intel_init_display_hooks - initialize the display modesetting hooks
7986 * @dev_priv: device private
7988 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
7990 if (DISPLAY_VER(dev_priv) >= 9) {
7991 dev_priv->display.funcs.display = &skl_display_funcs;
7992 } else if (HAS_DDI(dev_priv)) {
7993 dev_priv->display.funcs.display = &ddi_display_funcs;
7994 } else if (HAS_PCH_SPLIT(dev_priv)) {
7995 dev_priv->display.funcs.display = &pch_split_display_funcs;
7996 } else if (IS_CHERRYVIEW(dev_priv) ||
7997 IS_VALLEYVIEW(dev_priv)) {
7998 dev_priv->display.funcs.display = &vlv_display_funcs;
8000 dev_priv->display.funcs.display = &i9xx_display_funcs;
8004 int intel_initial_commit(struct drm_device *dev)
8006 struct drm_atomic_state *state = NULL;
8007 struct drm_modeset_acquire_ctx ctx;
8008 struct intel_crtc *crtc;
8011 state = drm_atomic_state_alloc(dev);
8015 drm_modeset_acquire_init(&ctx, 0);
8017 state->acquire_ctx = &ctx;
8018 to_intel_atomic_state(state)->internal = true;
8021 for_each_intel_crtc(dev, crtc) {
8022 struct intel_crtc_state *crtc_state =
8023 intel_atomic_get_crtc_state(state, crtc);
8025 if (IS_ERR(crtc_state)) {
8026 ret = PTR_ERR(crtc_state);
8030 if (crtc_state->hw.active) {
8031 struct intel_encoder *encoder;
8033 ret = drm_atomic_add_affected_planes(state, &crtc->base);
8038 * FIXME hack to force a LUT update to avoid the
8039 * plane update forcing the pipe gamma on without
8040 * having a proper LUT loaded. Remove once we
8041 * have readout for pipe gamma enable.
8043 crtc_state->uapi.color_mgmt_changed = true;
8045 for_each_intel_encoder_mask(dev, encoder,
8046 crtc_state->uapi.encoder_mask) {
8047 if (encoder->initial_fastset_check &&
8048 !encoder->initial_fastset_check(encoder, crtc_state)) {
8049 ret = drm_atomic_add_affected_connectors(state,
8058 ret = drm_atomic_commit(state);
8061 if (ret == -EDEADLK) {
8062 drm_atomic_state_clear(state);
8063 drm_modeset_backoff(&ctx);
8067 drm_atomic_state_put(state);
8069 drm_modeset_drop_locks(&ctx);
8070 drm_modeset_acquire_fini(&ctx);
8075 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8077 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8078 enum transcoder cpu_transcoder = (enum transcoder)pipe;
8079 /* 640x480@60Hz, ~25175 kHz */
8080 struct dpll clock = {
8090 drm_WARN_ON(&dev_priv->drm,
8091 i9xx_calc_dpll_params(48000, &clock) != 25154);
8093 drm_dbg_kms(&dev_priv->drm,
8094 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8095 pipe_name(pipe), clock.vco, clock.dot);
8097 fp = i9xx_dpll_compute_fp(&clock);
8098 dpll = DPLL_DVO_2X_MODE |
8100 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8101 PLL_P2_DIVIDE_BY_4 |
8102 PLL_REF_INPUT_DREFCLK |
8105 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
8106 HACTIVE(640 - 1) | HTOTAL(800 - 1));
8107 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
8108 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
8109 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
8110 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
8111 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
8112 VACTIVE(480 - 1) | VTOTAL(525 - 1));
8113 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
8114 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
8115 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
8116 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
8117 intel_de_write(dev_priv, PIPESRC(pipe),
8118 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
8120 intel_de_write(dev_priv, FP0(pipe), fp);
8121 intel_de_write(dev_priv, FP1(pipe), fp);
8124 * Apparently we need to have VGA mode enabled prior to changing
8125 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8126 * dividers, even though the register value does change.
8128 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
8129 intel_de_write(dev_priv, DPLL(pipe), dpll);
8131 /* Wait for the clocks to stabilize. */
8132 intel_de_posting_read(dev_priv, DPLL(pipe));
8135 /* The pixel multiplier can only be updated once the
8136 * DPLL is enabled and the clocks are stable.
8138 * So write it again.
8140 intel_de_write(dev_priv, DPLL(pipe), dpll);
8142 /* We do this three times for luck */
8143 for (i = 0; i < 3 ; i++) {
8144 intel_de_write(dev_priv, DPLL(pipe), dpll);
8145 intel_de_posting_read(dev_priv, DPLL(pipe));
8146 udelay(150); /* wait for warmup */
8149 intel_de_write(dev_priv, TRANSCONF(pipe), TRANSCONF_ENABLE);
8150 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
8152 intel_wait_for_pipe_scanline_moving(crtc);
8155 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8157 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8159 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
8162 drm_WARN_ON(&dev_priv->drm,
8163 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
8164 drm_WARN_ON(&dev_priv->drm,
8165 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
8166 drm_WARN_ON(&dev_priv->drm,
8167 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
8168 drm_WARN_ON(&dev_priv->drm,
8169 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
8170 drm_WARN_ON(&dev_priv->drm,
8171 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
8173 intel_de_write(dev_priv, TRANSCONF(pipe), 0);
8174 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
8176 intel_wait_for_pipe_scanline_stopped(crtc);
8178 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
8179 intel_de_posting_read(dev_priv, DPLL(pipe));
8182 void intel_hpd_poll_fini(struct drm_i915_private *i915)
8184 struct intel_connector *connector;
8185 struct drm_connector_list_iter conn_iter;
8187 /* Kill all the work that may have been queued by hpd. */
8188 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8189 for_each_intel_connector_iter(connector, &conn_iter) {
8190 if (connector->modeset_retry_work.func)
8191 cancel_work_sync(&connector->modeset_retry_work);
8192 if (connector->hdcp.shim) {
8193 cancel_delayed_work_sync(&connector->hdcp.check_work);
8194 cancel_work_sync(&connector->hdcp.prop_work);
8197 drm_connector_list_iter_end(&conn_iter);
8200 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
8202 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);