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/display/drm_dp_tunnel.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_atomic_helper.h>
39 #include <drm/drm_atomic_uapi.h>
40 #include <drm/drm_damage_helper.h>
41 #include <drm/drm_edid.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/drm_probe_helper.h>
44 #include <drm/drm_rect.h>
46 #include "gem/i915_gem_lmem.h"
47 #include "gem/i915_gem_object.h"
52 #include "i915_config.h"
55 #include "i915_utils.h"
56 #include "i9xx_plane.h"
58 #include "intel_atomic.h"
59 #include "intel_atomic_plane.h"
60 #include "intel_audio.h"
62 #include "intel_cdclk.h"
63 #include "intel_clock_gating.h"
64 #include "intel_color.h"
65 #include "intel_crt.h"
66 #include "intel_crtc.h"
67 #include "intel_crtc_state_dump.h"
68 #include "intel_ddi.h"
70 #include "intel_display_driver.h"
71 #include "intel_display_power.h"
72 #include "intel_display_types.h"
73 #include "intel_dmc.h"
75 #include "intel_dp_link_training.h"
76 #include "intel_dp_mst.h"
77 #include "intel_dp_tunnel.h"
78 #include "intel_dpll.h"
79 #include "intel_dpll_mgr.h"
80 #include "intel_dpt.h"
81 #include "intel_dpt_common.h"
82 #include "intel_drrs.h"
83 #include "intel_dsb.h"
84 #include "intel_dsi.h"
85 #include "intel_dvo.h"
87 #include "intel_fbc.h"
88 #include "intel_fbdev.h"
89 #include "intel_fdi.h"
90 #include "intel_fifo_underrun.h"
91 #include "intel_frontbuffer.h"
92 #include "intel_hdmi.h"
93 #include "intel_hotplug.h"
94 #include "intel_link_bw.h"
95 #include "intel_lvds.h"
96 #include "intel_lvds_regs.h"
97 #include "intel_modeset_setup.h"
98 #include "intel_modeset_verify.h"
99 #include "intel_overlay.h"
100 #include "intel_panel.h"
101 #include "intel_pch_display.h"
102 #include "intel_pch_refclk.h"
103 #include "intel_pcode.h"
104 #include "intel_pipe_crc.h"
105 #include "intel_plane_initial.h"
106 #include "intel_pmdemand.h"
107 #include "intel_pps.h"
108 #include "intel_psr.h"
109 #include "intel_psr_regs.h"
110 #include "intel_sdvo.h"
111 #include "intel_snps_phy.h"
112 #include "intel_tc.h"
113 #include "intel_tv.h"
114 #include "intel_vblank.h"
115 #include "intel_vdsc.h"
116 #include "intel_vdsc_regs.h"
117 #include "intel_vga.h"
118 #include "intel_vrr.h"
119 #include "intel_wm.h"
120 #include "skl_scaler.h"
121 #include "skl_universal_plane.h"
122 #include "skl_watermark.h"
124 #include "vlv_dsi_pll.h"
125 #include "vlv_dsi_regs.h"
126 #include "vlv_sideband.h"
128 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
129 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
130 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
131 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state);
133 /* returns HPLL frequency in kHz */
134 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
136 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
138 /* Obtain SKU information */
139 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
140 CCK_FUSE_HPLL_FREQ_MASK;
142 return vco_freq[hpll_freq] * 1000;
145 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
146 const char *name, u32 reg, int ref_freq)
151 val = vlv_cck_read(dev_priv, reg);
152 divider = val & CCK_FREQUENCY_VALUES;
154 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
155 (divider << CCK_FREQUENCY_STATUS_SHIFT),
156 "%s change in progress\n", name);
158 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
161 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
162 const char *name, u32 reg)
166 vlv_cck_get(dev_priv);
168 if (dev_priv->hpll_freq == 0)
169 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
171 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
173 vlv_cck_put(dev_priv);
178 void intel_update_czclk(struct drm_i915_private *dev_priv)
180 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
183 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
184 CCK_CZ_CLOCK_CONTROL);
186 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
187 dev_priv->czclk_freq);
190 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
192 return (crtc_state->active_planes &
193 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
196 /* WA Display #0827: Gen9:all */
198 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
200 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
201 DUPS1_GATING_DIS | DUPS2_GATING_DIS,
202 enable ? DUPS1_GATING_DIS | DUPS2_GATING_DIS : 0);
205 /* Wa_2006604312:icl,ehl */
207 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
210 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
212 enable ? 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),
222 enable ? CURSOR_GATING_DIS : 0);
226 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
228 return crtc_state->master_transcoder != INVALID_TRANSCODER;
232 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
234 return crtc_state->sync_mode_slaves_mask != 0;
238 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
240 return is_trans_port_sync_master(crtc_state) ||
241 is_trans_port_sync_slave(crtc_state);
244 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state)
246 return ffs(crtc_state->bigjoiner_pipes) - 1;
249 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state)
251 if (crtc_state->bigjoiner_pipes)
252 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state));
257 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state)
259 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
261 return crtc_state->bigjoiner_pipes &&
262 crtc->pipe != bigjoiner_master_pipe(crtc_state);
265 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state)
267 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
269 return crtc_state->bigjoiner_pipes &&
270 crtc->pipe == bigjoiner_master_pipe(crtc_state);
273 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state)
275 return hweight8(crtc_state->bigjoiner_pipes);
278 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state)
280 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
282 if (intel_crtc_is_bigjoiner_slave(crtc_state))
283 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state));
285 return to_intel_crtc(crtc_state->uapi.crtc);
289 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
291 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
292 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
294 if (DISPLAY_VER(dev_priv) >= 4) {
295 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
297 /* Wait for the Pipe State to go off */
298 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(cpu_transcoder),
299 TRANSCONF_STATE_ENABLE, 100))
300 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
302 intel_wait_for_pipe_scanline_stopped(crtc);
306 void assert_transcoder(struct drm_i915_private *dev_priv,
307 enum transcoder cpu_transcoder, bool state)
310 enum intel_display_power_domain power_domain;
311 intel_wakeref_t wakeref;
313 /* we keep both pipes enabled on 830 */
314 if (IS_I830(dev_priv))
317 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
318 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
320 u32 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
321 cur_state = !!(val & TRANSCONF_ENABLE);
323 intel_display_power_put(dev_priv, power_domain, wakeref);
328 I915_STATE_WARN(dev_priv, cur_state != state,
329 "transcoder %s assertion failure (expected %s, current %s)\n",
330 transcoder_name(cpu_transcoder), str_on_off(state),
331 str_on_off(cur_state));
334 static void assert_plane(struct intel_plane *plane, bool state)
336 struct drm_i915_private *i915 = to_i915(plane->base.dev);
340 cur_state = plane->get_hw_state(plane, &pipe);
342 I915_STATE_WARN(i915, cur_state != state,
343 "%s assertion failure (expected %s, current %s)\n",
344 plane->base.name, str_on_off(state),
345 str_on_off(cur_state));
348 #define assert_plane_enabled(p) assert_plane(p, true)
349 #define assert_plane_disabled(p) assert_plane(p, false)
351 static void assert_planes_disabled(struct intel_crtc *crtc)
353 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
354 struct intel_plane *plane;
356 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
357 assert_plane_disabled(plane);
360 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
361 struct intel_digital_port *dig_port,
362 unsigned int expected_mask)
367 switch (dig_port->base.port) {
369 MISSING_CASE(dig_port->base.port);
372 port_mask = DPLL_PORTB_READY_MASK;
376 port_mask = DPLL_PORTC_READY_MASK;
381 port_mask = DPLL_PORTD_READY_MASK;
382 dpll_reg = DPIO_PHY_STATUS;
386 if (intel_de_wait_for_register(dev_priv, dpll_reg,
387 port_mask, expected_mask, 1000))
388 drm_WARN(&dev_priv->drm, 1,
389 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
390 dig_port->base.base.base.id, dig_port->base.base.name,
391 intel_de_read(dev_priv, dpll_reg) & port_mask,
395 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
397 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
398 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
399 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
400 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 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
434 if (val & TRANSCONF_ENABLE) {
435 /* we keep both pipes enabled on 830 */
436 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
440 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder),
441 val | TRANSCONF_ENABLE);
442 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
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;
463 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
466 * Make sure planes won't keep trying to pump pixels to us,
467 * or we might hang the display.
469 assert_planes_disabled(crtc);
471 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
472 if ((val & TRANSCONF_ENABLE) == 0)
476 * Double wide has implications for planes
477 * so best keep it disabled when not needed.
479 if (old_crtc_state->double_wide)
480 val &= ~TRANSCONF_DOUBLE_WIDE;
482 /* Don't disable pipe or pipe PLLs if needed */
483 if (!IS_I830(dev_priv))
484 val &= ~TRANSCONF_ENABLE;
486 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
488 if (DISPLAY_VER(dev_priv) >= 12)
489 intel_de_rmw(dev_priv, hsw_chicken_trans_reg(dev_priv, cpu_transcoder),
490 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
492 if ((val & TRANSCONF_ENABLE) == 0)
493 intel_wait_for_pipe_off(old_crtc_state);
496 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
498 unsigned int size = 0;
501 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
502 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
507 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
509 unsigned int size = 0;
512 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
513 unsigned int plane_size;
515 if (rem_info->plane[i].linear)
516 plane_size = rem_info->plane[i].size;
518 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
523 if (rem_info->plane_alignment)
524 size = ALIGN(size, rem_info->plane_alignment);
532 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
534 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
535 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
537 return DISPLAY_VER(dev_priv) < 4 ||
539 plane_state->view.gtt.type == I915_GTT_VIEW_NORMAL);
543 * Convert the x/y offsets into a linear offset.
544 * Only valid with 0/180 degree rotation, which is fine since linear
545 * offset is only used with linear buffers on pre-hsw and tiled buffers
546 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
548 u32 intel_fb_xy_to_linear(int x, int y,
549 const struct intel_plane_state *state,
552 const struct drm_framebuffer *fb = state->hw.fb;
553 unsigned int cpp = fb->format->cpp[color_plane];
554 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
556 return y * pitch + x * cpp;
560 * Add the x/y offsets derived from fb->offsets[] to the user
561 * specified plane src x/y offsets. The resulting x/y offsets
562 * specify the start of scanout from the beginning of the gtt mapping.
564 void intel_add_fb_offsets(int *x, int *y,
565 const struct intel_plane_state *state,
569 *x += state->view.color_plane[color_plane].x;
570 *y += state->view.color_plane[color_plane].y;
573 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
574 u32 pixel_format, u64 modifier)
576 struct intel_crtc *crtc;
577 struct intel_plane *plane;
579 if (!HAS_DISPLAY(dev_priv))
583 * We assume the primary plane for pipe A has
584 * the highest stride limits of them all,
585 * if in case pipe A is disabled, use the first pipe from pipe_mask.
587 crtc = intel_first_crtc(dev_priv);
591 plane = to_intel_plane(crtc->base.primary);
593 return plane->max_stride(plane, pixel_format, modifier,
597 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
598 struct intel_plane_state *plane_state,
601 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
603 plane_state->uapi.visible = visible;
606 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
608 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
611 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
613 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
614 struct drm_plane *plane;
617 * Active_planes aliases if multiple "primary" or cursor planes
618 * have been used on the same (or wrong) pipe. plane_mask uses
619 * unique ids, hence we can use that to reconstruct active_planes.
621 crtc_state->enabled_planes = 0;
622 crtc_state->active_planes = 0;
624 drm_for_each_plane_mask(plane, &dev_priv->drm,
625 crtc_state->uapi.plane_mask) {
626 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
627 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
631 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
632 struct intel_plane *plane)
634 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
635 struct intel_crtc_state *crtc_state =
636 to_intel_crtc_state(crtc->base.state);
637 struct intel_plane_state *plane_state =
638 to_intel_plane_state(plane->base.state);
640 drm_dbg_kms(&dev_priv->drm,
641 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
642 plane->base.base.id, plane->base.name,
643 crtc->base.base.id, crtc->base.name);
645 intel_set_plane_visible(crtc_state, plane_state, false);
646 intel_plane_fixup_bitmasks(crtc_state);
647 crtc_state->data_rate[plane->id] = 0;
648 crtc_state->data_rate_y[plane->id] = 0;
649 crtc_state->rel_data_rate[plane->id] = 0;
650 crtc_state->rel_data_rate_y[plane->id] = 0;
651 crtc_state->min_cdclk[plane->id] = 0;
653 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
654 hsw_ips_disable(crtc_state)) {
655 crtc_state->ips_enabled = false;
656 intel_crtc_wait_for_next_vblank(crtc);
660 * Vblank time updates from the shadow to live plane control register
661 * are blocked if the memory self-refresh mode is active at that
662 * moment. So to make sure the plane gets truly disabled, disable
663 * first the self-refresh mode. The self-refresh enable bit in turn
664 * will be checked/applied by the HW only at the next frame start
665 * event which is after the vblank start event, so we need to have a
666 * wait-for-vblank between disabling the plane and the pipe.
668 if (HAS_GMCH(dev_priv) &&
669 intel_set_memory_cxsr(dev_priv, false))
670 intel_crtc_wait_for_next_vblank(crtc);
673 * Gen2 reports pipe underruns whenever all planes are disabled.
674 * So disable underrun reporting before all the planes get disabled.
676 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
677 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
679 intel_plane_disable_arm(plane, crtc_state);
680 intel_crtc_wait_for_next_vblank(crtc);
684 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
688 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
689 plane_state->view.color_plane[0].offset, 0);
694 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
696 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
697 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
698 enum pipe pipe = crtc->pipe;
701 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
704 * Display WA #1153: icl
705 * enable hardware to bypass the alpha math
706 * and rounding for per-pixel values 00 and 0xff
708 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
710 * Display WA # 1605353570: icl
711 * Set the pixel rounding bit to 1 for allowing
712 * passthrough of Frame buffer pixels unmodified
715 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
718 * Underrun recovery must always be disabled on display 13+.
719 * DG2 chicken bit meaning is inverted compared to other platforms.
721 if (IS_DG2(dev_priv))
722 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
723 else if (DISPLAY_VER(dev_priv) >= 13)
724 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
726 /* Wa_14010547955:dg2 */
727 if (IS_DG2(dev_priv))
728 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
730 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
733 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
735 struct drm_crtc *crtc;
738 drm_for_each_crtc(crtc, &dev_priv->drm) {
739 struct drm_crtc_commit *commit;
740 spin_lock(&crtc->commit_lock);
741 commit = list_first_entry_or_null(&crtc->commit_list,
742 struct drm_crtc_commit, commit_entry);
743 cleanup_done = commit ?
744 try_wait_for_completion(&commit->cleanup_done) : true;
745 spin_unlock(&crtc->commit_lock);
750 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
759 * Finds the encoder associated with the given CRTC. This can only be
760 * used when we know that the CRTC isn't feeding multiple encoders!
762 struct intel_encoder *
763 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
764 const struct intel_crtc_state *crtc_state)
766 const struct drm_connector_state *connector_state;
767 const struct drm_connector *connector;
768 struct intel_encoder *encoder = NULL;
769 struct intel_crtc *master_crtc;
770 int num_encoders = 0;
773 master_crtc = intel_master_crtc(crtc_state);
775 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
776 if (connector_state->crtc != &master_crtc->base)
779 encoder = to_intel_encoder(connector_state->best_encoder);
783 drm_WARN(state->base.dev, num_encoders != 1,
784 "%d encoders for pipe %c\n",
785 num_encoders, pipe_name(master_crtc->pipe));
790 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
792 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
793 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
794 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
795 enum pipe pipe = crtc->pipe;
796 int width = drm_rect_width(dst);
797 int height = drm_rect_height(dst);
801 if (!crtc_state->pch_pfit.enabled)
804 /* Force use of hard-coded filter coefficients
805 * as some pre-programmed values are broken,
808 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
809 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
810 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
812 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
814 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe),
815 PF_WIN_XPOS(x) | PF_WIN_YPOS(y));
816 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe),
817 PF_WIN_XSIZE(width) | PF_WIN_YSIZE(height));
820 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
823 (void) intel_overlay_switch_off(crtc->overlay);
825 /* Let userspace switch the overlay on again. In most cases userspace
826 * has to recompute where to put it anyway.
830 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
832 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
834 if (!crtc_state->nv12_planes)
837 /* WA Display #0827: Gen9:all */
838 if (DISPLAY_VER(dev_priv) == 9)
844 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
846 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
848 /* Wa_2006604312:icl,ehl */
849 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
855 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
857 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
859 /* Wa_1604331009:icl,jsl,ehl */
860 if (is_hdr_mode(crtc_state) &&
861 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
862 DISPLAY_VER(dev_priv) == 11)
868 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
869 enum pipe pipe, bool enable)
871 if (DISPLAY_VER(i915) == 9) {
873 * "Plane N strech max must be programmed to 11b (x1)
874 * when Async flips are enabled on that plane."
876 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
877 SKL_PLANE1_STRETCH_MAX_MASK,
878 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
880 /* Also needed on HSW/BDW albeit undocumented */
881 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
882 HSW_PRI_STRETCH_MAX_MASK,
883 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
887 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
889 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
891 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
892 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
895 static void intel_encoders_audio_enable(struct intel_atomic_state *state,
896 struct intel_crtc *crtc)
898 const struct intel_crtc_state *crtc_state =
899 intel_atomic_get_new_crtc_state(state, crtc);
900 const struct drm_connector_state *conn_state;
901 struct drm_connector *conn;
904 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
905 struct intel_encoder *encoder =
906 to_intel_encoder(conn_state->best_encoder);
908 if (conn_state->crtc != &crtc->base)
911 if (encoder->audio_enable)
912 encoder->audio_enable(encoder, crtc_state, conn_state);
916 static void intel_encoders_audio_disable(struct intel_atomic_state *state,
917 struct intel_crtc *crtc)
919 const struct intel_crtc_state *old_crtc_state =
920 intel_atomic_get_old_crtc_state(state, crtc);
921 const struct drm_connector_state *old_conn_state;
922 struct drm_connector *conn;
925 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
926 struct intel_encoder *encoder =
927 to_intel_encoder(old_conn_state->best_encoder);
929 if (old_conn_state->crtc != &crtc->base)
932 if (encoder->audio_disable)
933 encoder->audio_disable(encoder, old_crtc_state, old_conn_state);
937 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
938 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
939 (new_crtc_state)->feature)
940 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
941 ((old_crtc_state)->feature && \
942 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
944 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
945 const struct intel_crtc_state *new_crtc_state)
947 if (!new_crtc_state->hw.active)
950 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
953 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
954 const struct intel_crtc_state *new_crtc_state)
956 if (!old_crtc_state->hw.active)
959 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
962 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state,
963 const struct intel_crtc_state *new_crtc_state)
965 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline ||
966 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin ||
967 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax ||
968 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband ||
969 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full;
972 static bool vrr_enabling(const struct intel_crtc_state *old_crtc_state,
973 const struct intel_crtc_state *new_crtc_state)
975 if (!new_crtc_state->hw.active)
978 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) ||
979 (new_crtc_state->vrr.enable &&
980 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
981 vrr_params_changed(old_crtc_state, new_crtc_state)));
984 static bool vrr_disabling(const struct intel_crtc_state *old_crtc_state,
985 const struct intel_crtc_state *new_crtc_state)
987 if (!old_crtc_state->hw.active)
990 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) ||
991 (old_crtc_state->vrr.enable &&
992 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
993 vrr_params_changed(old_crtc_state, new_crtc_state)));
996 static bool audio_enabling(const struct intel_crtc_state *old_crtc_state,
997 const struct intel_crtc_state *new_crtc_state)
999 if (!new_crtc_state->hw.active)
1002 return is_enabling(has_audio, old_crtc_state, new_crtc_state) ||
1003 (new_crtc_state->has_audio &&
1004 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1007 static bool audio_disabling(const struct intel_crtc_state *old_crtc_state,
1008 const struct intel_crtc_state *new_crtc_state)
1010 if (!old_crtc_state->hw.active)
1013 return is_disabling(has_audio, old_crtc_state, new_crtc_state) ||
1014 (old_crtc_state->has_audio &&
1015 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1021 static void intel_post_plane_update(struct intel_atomic_state *state,
1022 struct intel_crtc *crtc)
1024 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1025 const struct intel_crtc_state *old_crtc_state =
1026 intel_atomic_get_old_crtc_state(state, crtc);
1027 const struct intel_crtc_state *new_crtc_state =
1028 intel_atomic_get_new_crtc_state(state, crtc);
1029 enum pipe pipe = crtc->pipe;
1031 intel_psr_post_plane_update(state, crtc);
1033 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
1035 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
1036 intel_update_watermarks(dev_priv);
1038 intel_fbc_post_update(state, crtc);
1040 if (needs_async_flip_vtd_wa(old_crtc_state) &&
1041 !needs_async_flip_vtd_wa(new_crtc_state))
1042 intel_async_flip_vtd_wa(dev_priv, pipe, false);
1044 if (needs_nv12_wa(old_crtc_state) &&
1045 !needs_nv12_wa(new_crtc_state))
1046 skl_wa_827(dev_priv, pipe, false);
1048 if (needs_scalerclk_wa(old_crtc_state) &&
1049 !needs_scalerclk_wa(new_crtc_state))
1050 icl_wa_scalerclkgating(dev_priv, pipe, false);
1052 if (needs_cursorclk_wa(old_crtc_state) &&
1053 !needs_cursorclk_wa(new_crtc_state))
1054 icl_wa_cursorclkgating(dev_priv, pipe, false);
1056 if (intel_crtc_needs_color_update(new_crtc_state))
1057 intel_color_post_update(new_crtc_state);
1059 if (audio_enabling(old_crtc_state, new_crtc_state))
1060 intel_encoders_audio_enable(state, crtc);
1063 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
1064 struct intel_crtc *crtc)
1066 const struct intel_crtc_state *crtc_state =
1067 intel_atomic_get_new_crtc_state(state, crtc);
1068 u8 update_planes = crtc_state->update_planes;
1069 const struct intel_plane_state __maybe_unused *plane_state;
1070 struct intel_plane *plane;
1073 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1074 if (plane->pipe == crtc->pipe &&
1075 update_planes & BIT(plane->id))
1076 plane->enable_flip_done(plane);
1080 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1081 struct intel_crtc *crtc)
1083 const struct intel_crtc_state *crtc_state =
1084 intel_atomic_get_new_crtc_state(state, crtc);
1085 u8 update_planes = crtc_state->update_planes;
1086 const struct intel_plane_state __maybe_unused *plane_state;
1087 struct intel_plane *plane;
1090 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1091 if (plane->pipe == crtc->pipe &&
1092 update_planes & BIT(plane->id))
1093 plane->disable_flip_done(plane);
1097 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1098 struct intel_crtc *crtc)
1100 const struct intel_crtc_state *old_crtc_state =
1101 intel_atomic_get_old_crtc_state(state, crtc);
1102 const struct intel_crtc_state *new_crtc_state =
1103 intel_atomic_get_new_crtc_state(state, crtc);
1104 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1105 ~new_crtc_state->async_flip_planes;
1106 const struct intel_plane_state *old_plane_state;
1107 struct intel_plane *plane;
1108 bool need_vbl_wait = false;
1111 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1112 if (plane->need_async_flip_disable_wa &&
1113 plane->pipe == crtc->pipe &&
1114 disable_async_flip_planes & BIT(plane->id)) {
1116 * Apart from the async flip bit we want to
1117 * preserve the old state for the plane.
1119 plane->async_flip(plane, old_crtc_state,
1120 old_plane_state, false);
1121 need_vbl_wait = true;
1126 intel_crtc_wait_for_next_vblank(crtc);
1129 static void intel_pre_plane_update(struct intel_atomic_state *state,
1130 struct intel_crtc *crtc)
1132 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1133 const struct intel_crtc_state *old_crtc_state =
1134 intel_atomic_get_old_crtc_state(state, crtc);
1135 const struct intel_crtc_state *new_crtc_state =
1136 intel_atomic_get_new_crtc_state(state, crtc);
1137 enum pipe pipe = crtc->pipe;
1139 if (vrr_disabling(old_crtc_state, new_crtc_state)) {
1140 intel_vrr_disable(old_crtc_state);
1141 intel_crtc_update_active_timings(old_crtc_state, false);
1144 if (audio_disabling(old_crtc_state, new_crtc_state))
1145 intel_encoders_audio_disable(state, crtc);
1147 intel_drrs_deactivate(old_crtc_state);
1149 intel_psr_pre_plane_update(state, crtc);
1151 if (hsw_ips_pre_update(state, crtc))
1152 intel_crtc_wait_for_next_vblank(crtc);
1154 if (intel_fbc_pre_update(state, crtc))
1155 intel_crtc_wait_for_next_vblank(crtc);
1157 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1158 needs_async_flip_vtd_wa(new_crtc_state))
1159 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1161 /* Display WA 827 */
1162 if (!needs_nv12_wa(old_crtc_state) &&
1163 needs_nv12_wa(new_crtc_state))
1164 skl_wa_827(dev_priv, pipe, true);
1166 /* Wa_2006604312:icl,ehl */
1167 if (!needs_scalerclk_wa(old_crtc_state) &&
1168 needs_scalerclk_wa(new_crtc_state))
1169 icl_wa_scalerclkgating(dev_priv, pipe, true);
1171 /* Wa_1604331009:icl,jsl,ehl */
1172 if (!needs_cursorclk_wa(old_crtc_state) &&
1173 needs_cursorclk_wa(new_crtc_state))
1174 icl_wa_cursorclkgating(dev_priv, pipe, true);
1177 * Vblank time updates from the shadow to live plane control register
1178 * are blocked if the memory self-refresh mode is active at that
1179 * moment. So to make sure the plane gets truly disabled, disable
1180 * first the self-refresh mode. The self-refresh enable bit in turn
1181 * will be checked/applied by the HW only at the next frame start
1182 * event which is after the vblank start event, so we need to have a
1183 * wait-for-vblank between disabling the plane and the pipe.
1185 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1186 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1187 intel_crtc_wait_for_next_vblank(crtc);
1190 * IVB workaround: must disable low power watermarks for at least
1191 * one frame before enabling scaling. LP watermarks can be re-enabled
1192 * when scaling is disabled.
1194 * WaCxSRDisabledForSpriteScaling:ivb
1196 if (old_crtc_state->hw.active &&
1197 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
1198 intel_crtc_wait_for_next_vblank(crtc);
1201 * If we're doing a modeset we don't need to do any
1202 * pre-vblank watermark programming here.
1204 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1206 * For platforms that support atomic watermarks, program the
1207 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1208 * will be the intermediate values that are safe for both pre- and
1209 * post- vblank; when vblank happens, the 'active' values will be set
1210 * to the final 'target' values and we'll do this again to get the
1211 * optimal watermarks. For gen9+ platforms, the values we program here
1212 * will be the final target values which will get automatically latched
1213 * at vblank time; no further programming will be necessary.
1215 * If a platform hasn't been transitioned to atomic watermarks yet,
1216 * we'll continue to update watermarks the old way, if flags tell
1219 if (!intel_initial_watermarks(state, crtc))
1220 if (new_crtc_state->update_wm_pre)
1221 intel_update_watermarks(dev_priv);
1225 * Gen2 reports pipe underruns whenever all planes are disabled.
1226 * So disable underrun reporting before all the planes get disabled.
1228 * We do this after .initial_watermarks() so that we have a
1229 * chance of catching underruns with the intermediate watermarks
1230 * vs. the old plane configuration.
1232 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1233 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1236 * WA for platforms where async address update enable bit
1237 * is double buffered and only latched at start of vblank.
1239 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1240 intel_crtc_async_flip_disable_wa(state, crtc);
1243 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1244 struct intel_crtc *crtc)
1246 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1247 const struct intel_crtc_state *new_crtc_state =
1248 intel_atomic_get_new_crtc_state(state, crtc);
1249 unsigned int update_mask = new_crtc_state->update_planes;
1250 const struct intel_plane_state *old_plane_state;
1251 struct intel_plane *plane;
1252 unsigned fb_bits = 0;
1255 intel_crtc_dpms_overlay_disable(crtc);
1257 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1258 if (crtc->pipe != plane->pipe ||
1259 !(update_mask & BIT(plane->id)))
1262 intel_plane_disable_arm(plane, new_crtc_state);
1264 if (old_plane_state->uapi.visible)
1265 fb_bits |= plane->frontbuffer_bit;
1268 intel_frontbuffer_flip(dev_priv, fb_bits);
1271 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1273 struct drm_i915_private *i915 = to_i915(state->base.dev);
1274 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1275 struct intel_crtc *crtc;
1279 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1280 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1282 if (i915->display.dpll.mgr) {
1283 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1284 if (intel_crtc_needs_modeset(new_crtc_state))
1287 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1288 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1293 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1294 struct intel_crtc *crtc)
1296 const struct intel_crtc_state *crtc_state =
1297 intel_atomic_get_new_crtc_state(state, crtc);
1298 const struct drm_connector_state *conn_state;
1299 struct drm_connector *conn;
1302 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1303 struct intel_encoder *encoder =
1304 to_intel_encoder(conn_state->best_encoder);
1306 if (conn_state->crtc != &crtc->base)
1309 if (encoder->pre_pll_enable)
1310 encoder->pre_pll_enable(state, encoder,
1311 crtc_state, conn_state);
1315 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1316 struct intel_crtc *crtc)
1318 const struct intel_crtc_state *crtc_state =
1319 intel_atomic_get_new_crtc_state(state, crtc);
1320 const struct drm_connector_state *conn_state;
1321 struct drm_connector *conn;
1324 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1325 struct intel_encoder *encoder =
1326 to_intel_encoder(conn_state->best_encoder);
1328 if (conn_state->crtc != &crtc->base)
1331 if (encoder->pre_enable)
1332 encoder->pre_enable(state, encoder,
1333 crtc_state, conn_state);
1337 static void intel_encoders_enable(struct intel_atomic_state *state,
1338 struct intel_crtc *crtc)
1340 const struct intel_crtc_state *crtc_state =
1341 intel_atomic_get_new_crtc_state(state, crtc);
1342 const struct drm_connector_state *conn_state;
1343 struct drm_connector *conn;
1346 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1347 struct intel_encoder *encoder =
1348 to_intel_encoder(conn_state->best_encoder);
1350 if (conn_state->crtc != &crtc->base)
1353 if (encoder->enable)
1354 encoder->enable(state, encoder,
1355 crtc_state, conn_state);
1356 intel_opregion_notify_encoder(encoder, true);
1360 static void intel_encoders_disable(struct intel_atomic_state *state,
1361 struct intel_crtc *crtc)
1363 const struct intel_crtc_state *old_crtc_state =
1364 intel_atomic_get_old_crtc_state(state, crtc);
1365 const struct drm_connector_state *old_conn_state;
1366 struct drm_connector *conn;
1369 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1370 struct intel_encoder *encoder =
1371 to_intel_encoder(old_conn_state->best_encoder);
1373 if (old_conn_state->crtc != &crtc->base)
1376 intel_opregion_notify_encoder(encoder, false);
1377 if (encoder->disable)
1378 encoder->disable(state, encoder,
1379 old_crtc_state, old_conn_state);
1383 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1384 struct intel_crtc *crtc)
1386 const struct intel_crtc_state *old_crtc_state =
1387 intel_atomic_get_old_crtc_state(state, crtc);
1388 const struct drm_connector_state *old_conn_state;
1389 struct drm_connector *conn;
1392 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1393 struct intel_encoder *encoder =
1394 to_intel_encoder(old_conn_state->best_encoder);
1396 if (old_conn_state->crtc != &crtc->base)
1399 if (encoder->post_disable)
1400 encoder->post_disable(state, encoder,
1401 old_crtc_state, old_conn_state);
1405 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1406 struct intel_crtc *crtc)
1408 const struct intel_crtc_state *old_crtc_state =
1409 intel_atomic_get_old_crtc_state(state, crtc);
1410 const struct drm_connector_state *old_conn_state;
1411 struct drm_connector *conn;
1414 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1415 struct intel_encoder *encoder =
1416 to_intel_encoder(old_conn_state->best_encoder);
1418 if (old_conn_state->crtc != &crtc->base)
1421 if (encoder->post_pll_disable)
1422 encoder->post_pll_disable(state, encoder,
1423 old_crtc_state, old_conn_state);
1427 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1428 struct intel_crtc *crtc)
1430 const struct intel_crtc_state *crtc_state =
1431 intel_atomic_get_new_crtc_state(state, crtc);
1432 const struct drm_connector_state *conn_state;
1433 struct drm_connector *conn;
1436 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1437 struct intel_encoder *encoder =
1438 to_intel_encoder(conn_state->best_encoder);
1440 if (conn_state->crtc != &crtc->base)
1443 if (encoder->update_pipe)
1444 encoder->update_pipe(state, encoder,
1445 crtc_state, conn_state);
1449 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
1451 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1452 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1454 plane->disable_arm(plane, crtc_state);
1457 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1459 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1460 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1462 if (crtc_state->has_pch_encoder) {
1463 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1464 &crtc_state->fdi_m_n);
1465 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1466 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1467 &crtc_state->dp_m_n);
1468 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1469 &crtc_state->dp_m2_n2);
1472 intel_set_transcoder_timings(crtc_state);
1474 ilk_set_pipeconf(crtc_state);
1477 static void ilk_crtc_enable(struct intel_atomic_state *state,
1478 struct intel_crtc *crtc)
1480 const struct intel_crtc_state *new_crtc_state =
1481 intel_atomic_get_new_crtc_state(state, crtc);
1482 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1483 enum pipe pipe = crtc->pipe;
1485 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1489 * Sometimes spurious CPU pipe underruns happen during FDI
1490 * training, at least with VGA+HDMI cloning. Suppress them.
1492 * On ILK we get an occasional spurious CPU pipe underruns
1493 * between eDP port A enable and vdd enable. Also PCH port
1494 * enable seems to result in the occasional CPU pipe underrun.
1496 * Spurious PCH underruns also occur during PCH enabling.
1498 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1499 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1501 ilk_configure_cpu_transcoder(new_crtc_state);
1503 intel_set_pipe_src_size(new_crtc_state);
1505 crtc->active = true;
1507 intel_encoders_pre_enable(state, crtc);
1509 if (new_crtc_state->has_pch_encoder) {
1510 ilk_pch_pre_enable(state, crtc);
1512 assert_fdi_tx_disabled(dev_priv, pipe);
1513 assert_fdi_rx_disabled(dev_priv, pipe);
1516 ilk_pfit_enable(new_crtc_state);
1519 * On ILK+ LUT must be loaded before the pipe is running but with
1522 intel_color_load_luts(new_crtc_state);
1523 intel_color_commit_noarm(new_crtc_state);
1524 intel_color_commit_arm(new_crtc_state);
1525 /* update DSPCNTR to configure gamma for pipe bottom color */
1526 intel_disable_primary_plane(new_crtc_state);
1528 intel_initial_watermarks(state, crtc);
1529 intel_enable_transcoder(new_crtc_state);
1531 if (new_crtc_state->has_pch_encoder)
1532 ilk_pch_enable(state, crtc);
1534 intel_crtc_vblank_on(new_crtc_state);
1536 intel_encoders_enable(state, crtc);
1538 if (HAS_PCH_CPT(dev_priv))
1539 intel_wait_for_pipe_scanline_moving(crtc);
1542 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1543 * And a second vblank wait is needed at least on ILK with
1544 * some interlaced HDMI modes. Let's do the double wait always
1545 * in case there are more corner cases we don't know about.
1547 if (new_crtc_state->has_pch_encoder) {
1548 intel_crtc_wait_for_next_vblank(crtc);
1549 intel_crtc_wait_for_next_vblank(crtc);
1551 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1552 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1555 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
1556 enum pipe pipe, bool apply)
1558 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
1559 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1566 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
1569 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1571 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1572 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1574 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1575 HSW_LINETIME(crtc_state->linetime) |
1576 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1579 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1581 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1582 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1584 intel_de_rmw(i915, hsw_chicken_trans_reg(i915, crtc_state->cpu_transcoder),
1585 HSW_FRAME_START_DELAY_MASK,
1586 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1589 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
1590 const struct intel_crtc_state *crtc_state)
1592 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state);
1595 * Enable sequence steps 1-7 on bigjoiner master
1597 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1598 intel_encoders_pre_pll_enable(state, master_crtc);
1600 if (crtc_state->shared_dpll)
1601 intel_enable_shared_dpll(crtc_state);
1603 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1604 intel_encoders_pre_enable(state, master_crtc);
1607 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1609 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1610 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1611 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1613 if (crtc_state->has_pch_encoder) {
1614 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1615 &crtc_state->fdi_m_n);
1616 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1617 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1618 &crtc_state->dp_m_n);
1619 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1620 &crtc_state->dp_m2_n2);
1623 intel_set_transcoder_timings(crtc_state);
1624 if (HAS_VRR(dev_priv))
1625 intel_vrr_set_transcoder_timings(crtc_state);
1627 if (cpu_transcoder != TRANSCODER_EDP)
1628 intel_de_write(dev_priv, TRANS_MULT(cpu_transcoder),
1629 crtc_state->pixel_multiplier - 1);
1631 hsw_set_frame_start_delay(crtc_state);
1633 hsw_set_transconf(crtc_state);
1636 static void hsw_crtc_enable(struct intel_atomic_state *state,
1637 struct intel_crtc *crtc)
1639 const struct intel_crtc_state *new_crtc_state =
1640 intel_atomic_get_new_crtc_state(state, crtc);
1641 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1642 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
1643 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1644 bool psl_clkgate_wa;
1646 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1649 intel_dmc_enable_pipe(dev_priv, crtc->pipe);
1651 if (!new_crtc_state->bigjoiner_pipes) {
1652 intel_encoders_pre_pll_enable(state, crtc);
1654 if (new_crtc_state->shared_dpll)
1655 intel_enable_shared_dpll(new_crtc_state);
1657 intel_encoders_pre_enable(state, crtc);
1659 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
1662 intel_dsc_enable(new_crtc_state);
1664 if (DISPLAY_VER(dev_priv) >= 13)
1665 intel_uncompressed_joiner_enable(new_crtc_state);
1667 intel_set_pipe_src_size(new_crtc_state);
1668 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1669 bdw_set_pipe_misc(new_crtc_state);
1671 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) &&
1672 !transcoder_is_dsi(cpu_transcoder))
1673 hsw_configure_cpu_transcoder(new_crtc_state);
1675 crtc->active = true;
1677 /* Display WA #1180: WaDisableScalarClockGating: glk */
1678 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
1679 new_crtc_state->pch_pfit.enabled;
1681 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
1683 if (DISPLAY_VER(dev_priv) >= 9)
1684 skl_pfit_enable(new_crtc_state);
1686 ilk_pfit_enable(new_crtc_state);
1689 * On ILK+ LUT must be loaded before the pipe is running but with
1692 intel_color_load_luts(new_crtc_state);
1693 intel_color_commit_noarm(new_crtc_state);
1694 intel_color_commit_arm(new_crtc_state);
1695 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
1696 if (DISPLAY_VER(dev_priv) < 9)
1697 intel_disable_primary_plane(new_crtc_state);
1699 hsw_set_linetime_wm(new_crtc_state);
1701 if (DISPLAY_VER(dev_priv) >= 11)
1702 icl_set_pipe_chicken(new_crtc_state);
1704 intel_initial_watermarks(state, crtc);
1706 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
1707 intel_crtc_vblank_on(new_crtc_state);
1709 intel_encoders_enable(state, crtc);
1711 if (psl_clkgate_wa) {
1712 intel_crtc_wait_for_next_vblank(crtc);
1713 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
1716 /* If we change the relative order between pipe/planes enabling, we need
1717 * to change the workaround. */
1718 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
1719 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1720 struct intel_crtc *wa_crtc;
1722 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe);
1724 intel_crtc_wait_for_next_vblank(wa_crtc);
1725 intel_crtc_wait_for_next_vblank(wa_crtc);
1729 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1731 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1732 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1733 enum pipe pipe = crtc->pipe;
1735 /* To avoid upsetting the power well on haswell only disable the pfit if
1736 * it's in use. The hw state code will make sure we get this right. */
1737 if (!old_crtc_state->pch_pfit.enabled)
1740 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1741 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
1742 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
1745 static void ilk_crtc_disable(struct intel_atomic_state *state,
1746 struct intel_crtc *crtc)
1748 const struct intel_crtc_state *old_crtc_state =
1749 intel_atomic_get_old_crtc_state(state, crtc);
1750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1751 enum pipe pipe = crtc->pipe;
1754 * Sometimes spurious CPU pipe underruns happen when the
1755 * pipe is already disabled, but FDI RX/TX is still enabled.
1756 * Happens at least with VGA+HDMI cloning. Suppress them.
1758 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1759 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1761 intel_encoders_disable(state, crtc);
1763 intel_crtc_vblank_off(old_crtc_state);
1765 intel_disable_transcoder(old_crtc_state);
1767 ilk_pfit_disable(old_crtc_state);
1769 if (old_crtc_state->has_pch_encoder)
1770 ilk_pch_disable(state, crtc);
1772 intel_encoders_post_disable(state, crtc);
1774 if (old_crtc_state->has_pch_encoder)
1775 ilk_pch_post_disable(state, crtc);
1777 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1778 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1780 intel_disable_shared_dpll(old_crtc_state);
1783 static void hsw_crtc_disable(struct intel_atomic_state *state,
1784 struct intel_crtc *crtc)
1786 const struct intel_crtc_state *old_crtc_state =
1787 intel_atomic_get_old_crtc_state(state, crtc);
1788 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1791 * FIXME collapse everything to one hook.
1792 * Need care with mst->ddi interactions.
1794 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1795 intel_encoders_disable(state, crtc);
1796 intel_encoders_post_disable(state, crtc);
1799 intel_disable_shared_dpll(old_crtc_state);
1801 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1802 struct intel_crtc *slave_crtc;
1804 intel_encoders_post_pll_disable(state, crtc);
1806 intel_dmc_disable_pipe(i915, crtc->pipe);
1808 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
1809 intel_crtc_bigjoiner_slave_pipes(old_crtc_state))
1810 intel_dmc_disable_pipe(i915, slave_crtc->pipe);
1814 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
1816 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1817 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1819 if (!crtc_state->gmch_pfit.control)
1823 * The panel fitter should only be adjusted whilst the pipe is disabled,
1824 * according to register description and PRM.
1826 drm_WARN_ON(&dev_priv->drm,
1827 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
1828 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1830 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
1831 crtc_state->gmch_pfit.pgm_ratios);
1832 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
1834 /* Border color in case we don't scale up to the full screen. Black by
1835 * default, change to something else for debugging. */
1836 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
1839 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
1841 if (phy == PHY_NONE)
1843 else if (IS_ALDERLAKE_S(dev_priv))
1844 return phy <= PHY_E;
1845 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
1846 return phy <= PHY_D;
1847 else if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv))
1848 return phy <= PHY_C;
1849 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
1850 return phy <= PHY_B;
1853 * DG2 outputs labelled as "combo PHY" in the bspec use
1854 * SNPS PHYs with completely different programming,
1855 * hence we always return false here.
1860 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
1863 * DG2's "TC1", although TC-capable output, doesn't share the same flow
1864 * as other platforms on the display engine side and rather rely on the
1865 * SNPS PHY, that is programmed separately
1867 if (IS_DG2(dev_priv))
1870 if (DISPLAY_VER(dev_priv) >= 13)
1871 return phy >= PHY_F && phy <= PHY_I;
1872 else if (IS_TIGERLAKE(dev_priv))
1873 return phy >= PHY_D && phy <= PHY_I;
1874 else if (IS_ICELAKE(dev_priv))
1875 return phy >= PHY_C && phy <= PHY_F;
1880 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
1883 * For DG2, and for DG2 only, all four "combo" ports and the TC1 port
1884 * (PHY E) use Synopsis PHYs. See intel_phy_is_tc().
1886 return IS_DG2(dev_priv) && phy > PHY_NONE && phy <= PHY_E;
1889 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
1891 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
1892 return PHY_D + port - PORT_D_XELPD;
1893 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
1894 return PHY_F + port - PORT_TC1;
1895 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
1896 return PHY_B + port - PORT_TC1;
1897 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
1898 return PHY_C + port - PORT_TC1;
1899 else if ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) &&
1903 return PHY_A + port - PORT_A;
1906 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
1908 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
1909 return TC_PORT_NONE;
1911 if (DISPLAY_VER(dev_priv) >= 12)
1912 return TC_PORT_1 + port - PORT_TC1;
1914 return TC_PORT_1 + port - PORT_C;
1917 enum intel_display_power_domain
1918 intel_aux_power_domain(struct intel_digital_port *dig_port)
1920 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
1922 if (intel_tc_port_in_tbt_alt_mode(dig_port))
1923 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
1925 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
1928 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1929 struct intel_power_domain_mask *mask)
1931 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1932 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1933 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1934 struct drm_encoder *encoder;
1935 enum pipe pipe = crtc->pipe;
1937 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
1939 if (!crtc_state->hw.active)
1942 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
1943 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
1944 if (crtc_state->pch_pfit.enabled ||
1945 crtc_state->pch_pfit.force_thru)
1946 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
1948 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
1949 crtc_state->uapi.encoder_mask) {
1950 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1952 set_bit(intel_encoder->power_domain, mask->bits);
1955 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
1956 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
1958 if (crtc_state->shared_dpll)
1959 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
1961 if (crtc_state->dsc.compression_enable)
1962 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
1965 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1966 struct intel_power_domain_mask *old_domains)
1968 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1969 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1970 enum intel_display_power_domain domain;
1971 struct intel_power_domain_mask domains, new_domains;
1973 get_crtc_power_domains(crtc_state, &domains);
1975 bitmap_andnot(new_domains.bits,
1977 crtc->enabled_power_domains.mask.bits,
1979 bitmap_andnot(old_domains->bits,
1980 crtc->enabled_power_domains.mask.bits,
1984 for_each_power_domain(domain, &new_domains)
1985 intel_display_power_get_in_set(dev_priv,
1986 &crtc->enabled_power_domains,
1990 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
1991 struct intel_power_domain_mask *domains)
1993 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
1994 &crtc->enabled_power_domains,
1998 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
2000 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2001 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2003 if (intel_crtc_has_dp_encoder(crtc_state)) {
2004 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
2005 &crtc_state->dp_m_n);
2006 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
2007 &crtc_state->dp_m2_n2);
2010 intel_set_transcoder_timings(crtc_state);
2012 i9xx_set_pipeconf(crtc_state);
2015 static void valleyview_crtc_enable(struct intel_atomic_state *state,
2016 struct intel_crtc *crtc)
2018 const struct intel_crtc_state *new_crtc_state =
2019 intel_atomic_get_new_crtc_state(state, crtc);
2020 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2021 enum pipe pipe = crtc->pipe;
2023 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2026 i9xx_configure_cpu_transcoder(new_crtc_state);
2028 intel_set_pipe_src_size(new_crtc_state);
2030 intel_de_write(dev_priv, VLV_PIPE_MSA_MISC(pipe), 0);
2032 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
2033 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
2034 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
2037 crtc->active = true;
2039 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2041 intel_encoders_pre_pll_enable(state, crtc);
2043 if (IS_CHERRYVIEW(dev_priv))
2044 chv_enable_pll(new_crtc_state);
2046 vlv_enable_pll(new_crtc_state);
2048 intel_encoders_pre_enable(state, crtc);
2050 i9xx_pfit_enable(new_crtc_state);
2052 intel_color_load_luts(new_crtc_state);
2053 intel_color_commit_noarm(new_crtc_state);
2054 intel_color_commit_arm(new_crtc_state);
2055 /* update DSPCNTR to configure gamma for pipe bottom color */
2056 intel_disable_primary_plane(new_crtc_state);
2058 intel_initial_watermarks(state, crtc);
2059 intel_enable_transcoder(new_crtc_state);
2061 intel_crtc_vblank_on(new_crtc_state);
2063 intel_encoders_enable(state, crtc);
2066 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2067 struct intel_crtc *crtc)
2069 const struct intel_crtc_state *new_crtc_state =
2070 intel_atomic_get_new_crtc_state(state, crtc);
2071 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2072 enum pipe pipe = crtc->pipe;
2074 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2077 i9xx_configure_cpu_transcoder(new_crtc_state);
2079 intel_set_pipe_src_size(new_crtc_state);
2081 crtc->active = true;
2083 if (DISPLAY_VER(dev_priv) != 2)
2084 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2086 intel_encoders_pre_enable(state, crtc);
2088 i9xx_enable_pll(new_crtc_state);
2090 i9xx_pfit_enable(new_crtc_state);
2092 intel_color_load_luts(new_crtc_state);
2093 intel_color_commit_noarm(new_crtc_state);
2094 intel_color_commit_arm(new_crtc_state);
2095 /* update DSPCNTR to configure gamma for pipe bottom color */
2096 intel_disable_primary_plane(new_crtc_state);
2098 if (!intel_initial_watermarks(state, crtc))
2099 intel_update_watermarks(dev_priv);
2100 intel_enable_transcoder(new_crtc_state);
2102 intel_crtc_vblank_on(new_crtc_state);
2104 intel_encoders_enable(state, crtc);
2106 /* prevents spurious underruns */
2107 if (DISPLAY_VER(dev_priv) == 2)
2108 intel_crtc_wait_for_next_vblank(crtc);
2111 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2113 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2114 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2116 if (!old_crtc_state->gmch_pfit.control)
2119 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2121 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2122 intel_de_read(dev_priv, PFIT_CONTROL));
2123 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2126 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2127 struct intel_crtc *crtc)
2129 struct intel_crtc_state *old_crtc_state =
2130 intel_atomic_get_old_crtc_state(state, crtc);
2131 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2132 enum pipe pipe = crtc->pipe;
2135 * On gen2 planes are double buffered but the pipe isn't, so we must
2136 * wait for planes to fully turn off before disabling the pipe.
2138 if (DISPLAY_VER(dev_priv) == 2)
2139 intel_crtc_wait_for_next_vblank(crtc);
2141 intel_encoders_disable(state, crtc);
2143 intel_crtc_vblank_off(old_crtc_state);
2145 intel_disable_transcoder(old_crtc_state);
2147 i9xx_pfit_disable(old_crtc_state);
2149 intel_encoders_post_disable(state, crtc);
2151 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2152 if (IS_CHERRYVIEW(dev_priv))
2153 chv_disable_pll(dev_priv, pipe);
2154 else if (IS_VALLEYVIEW(dev_priv))
2155 vlv_disable_pll(dev_priv, pipe);
2157 i9xx_disable_pll(old_crtc_state);
2160 intel_encoders_post_pll_disable(state, crtc);
2162 if (DISPLAY_VER(dev_priv) != 2)
2163 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2165 if (!dev_priv->display.funcs.wm->initial_watermarks)
2166 intel_update_watermarks(dev_priv);
2168 /* clock the pipe down to 640x480@60 to potentially save power */
2169 if (IS_I830(dev_priv))
2170 i830_enable_pipe(dev_priv, pipe);
2173 void intel_encoder_destroy(struct drm_encoder *encoder)
2175 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2177 drm_encoder_cleanup(encoder);
2178 kfree(intel_encoder);
2181 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2183 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2185 /* GDG double wide on either pipe, otherwise pipe A only */
2186 return DISPLAY_VER(dev_priv) < 4 &&
2187 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2190 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2192 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2193 struct drm_rect src;
2196 * We only use IF-ID interlacing. If we ever use
2197 * PF-ID we'll need to adjust the pixel_rate here.
2200 if (!crtc_state->pch_pfit.enabled)
2203 drm_rect_init(&src, 0, 0,
2204 drm_rect_width(&crtc_state->pipe_src) << 16,
2205 drm_rect_height(&crtc_state->pipe_src) << 16);
2207 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2211 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2212 const struct drm_display_mode *timings)
2214 mode->hdisplay = timings->crtc_hdisplay;
2215 mode->htotal = timings->crtc_htotal;
2216 mode->hsync_start = timings->crtc_hsync_start;
2217 mode->hsync_end = timings->crtc_hsync_end;
2219 mode->vdisplay = timings->crtc_vdisplay;
2220 mode->vtotal = timings->crtc_vtotal;
2221 mode->vsync_start = timings->crtc_vsync_start;
2222 mode->vsync_end = timings->crtc_vsync_end;
2224 mode->flags = timings->flags;
2225 mode->type = DRM_MODE_TYPE_DRIVER;
2227 mode->clock = timings->crtc_clock;
2229 drm_mode_set_name(mode);
2232 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2234 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2236 if (HAS_GMCH(dev_priv))
2237 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2238 crtc_state->pixel_rate =
2239 crtc_state->hw.pipe_mode.crtc_clock;
2241 crtc_state->pixel_rate =
2242 ilk_pipe_pixel_rate(crtc_state);
2245 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2246 struct drm_display_mode *mode)
2248 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2253 mode->crtc_clock /= num_pipes;
2254 mode->crtc_hdisplay /= num_pipes;
2255 mode->crtc_hblank_start /= num_pipes;
2256 mode->crtc_hblank_end /= num_pipes;
2257 mode->crtc_hsync_start /= num_pipes;
2258 mode->crtc_hsync_end /= num_pipes;
2259 mode->crtc_htotal /= num_pipes;
2262 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2263 struct drm_display_mode *mode)
2265 int overlap = crtc_state->splitter.pixel_overlap;
2266 int n = crtc_state->splitter.link_count;
2268 if (!crtc_state->splitter.enable)
2272 * eDP MSO uses segment timings from EDID for transcoder
2273 * timings, but full mode for everything else.
2275 * h_full = (h_segment - pixel_overlap) * link_count
2277 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2278 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2279 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2280 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2281 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2282 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2283 mode->crtc_clock *= n;
2286 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2288 struct drm_display_mode *mode = &crtc_state->hw.mode;
2289 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2290 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2293 * Start with the adjusted_mode crtc timings, which
2294 * have been filled with the transcoder timings.
2296 drm_mode_copy(pipe_mode, adjusted_mode);
2298 /* Expand MSO per-segment transcoder timings to full */
2299 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2302 * We want the full numbers in adjusted_mode normal timings,
2303 * adjusted_mode crtc timings are left with the raw transcoder
2306 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2308 /* Populate the "user" mode with full numbers */
2309 drm_mode_copy(mode, pipe_mode);
2310 intel_mode_from_crtc_timings(mode, mode);
2311 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2312 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2313 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2315 /* Derive per-pipe timings in case bigjoiner is used */
2316 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2317 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2319 intel_crtc_compute_pixel_rate(crtc_state);
2322 void intel_encoder_get_config(struct intel_encoder *encoder,
2323 struct intel_crtc_state *crtc_state)
2325 encoder->get_config(encoder, crtc_state);
2327 intel_crtc_readout_derived_state(crtc_state);
2330 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2332 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2338 width = drm_rect_width(&crtc_state->pipe_src);
2339 height = drm_rect_height(&crtc_state->pipe_src);
2341 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2342 width / num_pipes, height);
2345 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2347 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2348 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2350 intel_bigjoiner_compute_pipe_src(crtc_state);
2353 * Pipe horizontal size must be even in:
2355 * - LVDS dual channel mode
2356 * - Double wide pipe
2358 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2359 if (crtc_state->double_wide) {
2360 drm_dbg_kms(&i915->drm,
2361 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2362 crtc->base.base.id, crtc->base.name);
2366 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2367 intel_is_dual_link_lvds(i915)) {
2368 drm_dbg_kms(&i915->drm,
2369 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2370 crtc->base.base.id, crtc->base.name);
2378 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2380 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2381 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2382 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2383 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2384 int clock_limit = i915->max_dotclk_freq;
2387 * Start with the adjusted_mode crtc timings, which
2388 * have been filled with the transcoder timings.
2390 drm_mode_copy(pipe_mode, adjusted_mode);
2392 /* Expand MSO per-segment transcoder timings to full */
2393 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2395 /* Derive per-pipe timings in case bigjoiner is used */
2396 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2397 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2399 if (DISPLAY_VER(i915) < 4) {
2400 clock_limit = i915->display.cdclk.max_cdclk_freq * 9 / 10;
2403 * Enable double wide mode when the dot clock
2404 * is > 90% of the (display) core speed.
2406 if (intel_crtc_supports_double_wide(crtc) &&
2407 pipe_mode->crtc_clock > clock_limit) {
2408 clock_limit = i915->max_dotclk_freq;
2409 crtc_state->double_wide = true;
2413 if (pipe_mode->crtc_clock > clock_limit) {
2414 drm_dbg_kms(&i915->drm,
2415 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2416 crtc->base.base.id, crtc->base.name,
2417 pipe_mode->crtc_clock, clock_limit,
2418 str_yes_no(crtc_state->double_wide));
2425 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2426 struct intel_crtc *crtc)
2428 struct intel_crtc_state *crtc_state =
2429 intel_atomic_get_new_crtc_state(state, crtc);
2432 ret = intel_dpll_crtc_compute_clock(state, crtc);
2436 ret = intel_crtc_compute_pipe_src(crtc_state);
2440 ret = intel_crtc_compute_pipe_mode(crtc_state);
2444 intel_crtc_compute_pixel_rate(crtc_state);
2446 if (crtc_state->has_pch_encoder)
2447 return ilk_fdi_compute_config(crtc, crtc_state);
2453 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2455 while (*num > DATA_LINK_M_N_MASK ||
2456 *den > DATA_LINK_M_N_MASK) {
2462 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2463 u32 m, u32 n, u32 constant_n)
2466 *ret_n = constant_n;
2468 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2470 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2471 intel_reduce_m_n_ratio(ret_m, ret_n);
2475 intel_link_compute_m_n(u16 bits_per_pixel_x16, int nlanes,
2476 int pixel_clock, int link_clock,
2478 struct intel_link_m_n *m_n)
2480 u32 link_symbol_clock = intel_dp_link_symbol_clock(link_clock);
2481 u32 data_m = intel_dp_effective_data_rate(pixel_clock, bits_per_pixel_x16,
2483 u32 data_n = drm_dp_max_dprx_data_rate(link_clock, nlanes);
2486 * Windows/BIOS uses fixed M/N values always. Follow suit.
2488 * Also several DP dongles in particular seem to be fussy
2489 * about too large link M/N values. Presumably the 20bit
2490 * value used by Windows/BIOS is acceptable to everyone.
2493 compute_m_n(&m_n->data_m, &m_n->data_n,
2497 compute_m_n(&m_n->link_m, &m_n->link_n,
2498 pixel_clock, link_symbol_clock,
2502 void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2505 * There may be no VBT; and if the BIOS enabled SSC we can
2506 * just keep using it to avoid unnecessary flicker. Whereas if the
2507 * BIOS isn't using it, don't assume it will work even if the VBT
2508 * indicates as much.
2510 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2511 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2515 if (dev_priv->display.vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2516 drm_dbg_kms(&dev_priv->drm,
2517 "SSC %s by BIOS, overriding VBT which says %s\n",
2518 str_enabled_disabled(bios_lvds_use_ssc),
2519 str_enabled_disabled(dev_priv->display.vbt.lvds_use_ssc));
2520 dev_priv->display.vbt.lvds_use_ssc = bios_lvds_use_ssc;
2525 void intel_zero_m_n(struct intel_link_m_n *m_n)
2527 /* corresponds to 0 register value */
2528 memset(m_n, 0, sizeof(*m_n));
2532 void intel_set_m_n(struct drm_i915_private *i915,
2533 const struct intel_link_m_n *m_n,
2534 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2535 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2537 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2538 intel_de_write(i915, data_n_reg, m_n->data_n);
2539 intel_de_write(i915, link_m_reg, m_n->link_m);
2541 * On BDW+ writing LINK_N arms the double buffered update
2542 * of all the M/N registers, so it must be written last.
2544 intel_de_write(i915, link_n_reg, m_n->link_n);
2547 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2548 enum transcoder transcoder)
2550 if (IS_HASWELL(dev_priv))
2551 return transcoder == TRANSCODER_EDP;
2553 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2556 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2557 enum transcoder transcoder,
2558 const struct intel_link_m_n *m_n)
2560 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2561 enum pipe pipe = crtc->pipe;
2563 if (DISPLAY_VER(dev_priv) >= 5)
2564 intel_set_m_n(dev_priv, m_n,
2565 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2566 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2568 intel_set_m_n(dev_priv, m_n,
2569 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2570 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2573 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2574 enum transcoder transcoder,
2575 const struct intel_link_m_n *m_n)
2577 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2579 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2582 intel_set_m_n(dev_priv, m_n,
2583 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2584 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2587 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2589 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2590 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2591 enum pipe pipe = crtc->pipe;
2592 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2593 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2594 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2597 /* We need to be careful not to changed the adjusted mode, for otherwise
2598 * the hw state checker will get angry at the mismatch. */
2599 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2600 crtc_vtotal = adjusted_mode->crtc_vtotal;
2601 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2602 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2604 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2605 /* the chip adds 2 halflines automatically */
2607 crtc_vblank_end -= 1;
2609 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2610 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2612 vsyncshift = adjusted_mode->crtc_hsync_start -
2613 adjusted_mode->crtc_htotal / 2;
2615 vsyncshift += adjusted_mode->crtc_htotal;
2619 * VBLANK_START no longer works on ADL+, instead we must use
2620 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2622 if (DISPLAY_VER(dev_priv) >= 13) {
2623 intel_de_write(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder),
2624 crtc_vblank_start - crtc_vdisplay);
2627 * VBLANK_START not used by hw, just clear it
2628 * to make it stand out in register dumps.
2630 crtc_vblank_start = 1;
2633 if (DISPLAY_VER(dev_priv) >= 4)
2634 intel_de_write(dev_priv, TRANS_VSYNCSHIFT(cpu_transcoder),
2637 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
2638 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2639 HTOTAL(adjusted_mode->crtc_htotal - 1));
2640 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
2641 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2642 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2643 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
2644 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2645 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2647 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2648 VACTIVE(crtc_vdisplay - 1) |
2649 VTOTAL(crtc_vtotal - 1));
2650 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2651 VBLANK_START(crtc_vblank_start - 1) |
2652 VBLANK_END(crtc_vblank_end - 1));
2653 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
2654 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2655 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2657 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2658 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2659 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2661 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2662 (pipe == PIPE_B || pipe == PIPE_C))
2663 intel_de_write(dev_priv, TRANS_VTOTAL(pipe),
2664 VACTIVE(crtc_vdisplay - 1) |
2665 VTOTAL(crtc_vtotal - 1));
2668 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state)
2670 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2671 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2672 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2673 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2674 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2676 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2677 crtc_vtotal = adjusted_mode->crtc_vtotal;
2678 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2679 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2681 drm_WARN_ON(&dev_priv->drm, adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE);
2684 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode.
2685 * But let's write it anyway to keep the state checker happy.
2687 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2688 VBLANK_START(crtc_vblank_start - 1) |
2689 VBLANK_END(crtc_vblank_end - 1));
2691 * The double buffer latch point for TRANS_VTOTAL
2692 * is the transcoder's undelayed vblank.
2694 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2695 VACTIVE(crtc_vdisplay - 1) |
2696 VTOTAL(crtc_vtotal - 1));
2699 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2701 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2702 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2703 int width = drm_rect_width(&crtc_state->pipe_src);
2704 int height = drm_rect_height(&crtc_state->pipe_src);
2705 enum pipe pipe = crtc->pipe;
2707 /* pipesrc controls the size that is scaled from, which should
2708 * always be the user's requested size.
2710 intel_de_write(dev_priv, PIPESRC(pipe),
2711 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2714 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2716 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2717 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2719 if (DISPLAY_VER(dev_priv) == 2)
2722 if (DISPLAY_VER(dev_priv) >= 9 ||
2723 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2724 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2726 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2729 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2730 struct intel_crtc_state *pipe_config)
2732 struct drm_device *dev = crtc->base.dev;
2733 struct drm_i915_private *dev_priv = to_i915(dev);
2734 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2735 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2738 tmp = intel_de_read(dev_priv, TRANS_HTOTAL(cpu_transcoder));
2739 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2740 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2742 if (!transcoder_is_dsi(cpu_transcoder)) {
2743 tmp = intel_de_read(dev_priv, TRANS_HBLANK(cpu_transcoder));
2744 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2745 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2748 tmp = intel_de_read(dev_priv, TRANS_HSYNC(cpu_transcoder));
2749 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2750 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2752 tmp = intel_de_read(dev_priv, TRANS_VTOTAL(cpu_transcoder));
2753 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2754 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2756 /* FIXME TGL+ DSI transcoders have this! */
2757 if (!transcoder_is_dsi(cpu_transcoder)) {
2758 tmp = intel_de_read(dev_priv, TRANS_VBLANK(cpu_transcoder));
2759 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2760 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2762 tmp = intel_de_read(dev_priv, TRANS_VSYNC(cpu_transcoder));
2763 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2764 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2766 if (intel_pipe_is_interlaced(pipe_config)) {
2767 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2768 adjusted_mode->crtc_vtotal += 1;
2769 adjusted_mode->crtc_vblank_end += 1;
2772 if (DISPLAY_VER(dev_priv) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2773 adjusted_mode->crtc_vblank_start =
2774 adjusted_mode->crtc_vdisplay +
2775 intel_de_read(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder));
2778 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2780 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2781 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2782 enum pipe master_pipe, pipe = crtc->pipe;
2788 master_pipe = bigjoiner_master_pipe(crtc_state);
2789 width = drm_rect_width(&crtc_state->pipe_src);
2791 drm_rect_translate_to(&crtc_state->pipe_src,
2792 (pipe - master_pipe) * width, 0);
2795 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2796 struct intel_crtc_state *pipe_config)
2798 struct drm_device *dev = crtc->base.dev;
2799 struct drm_i915_private *dev_priv = to_i915(dev);
2802 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
2804 drm_rect_init(&pipe_config->pipe_src, 0, 0,
2805 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
2806 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
2808 intel_bigjoiner_adjust_pipe_src(pipe_config);
2811 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
2813 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2814 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2815 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2819 * - We keep both pipes enabled on 830
2820 * - During modeset the pipe is still disabled and must remain so
2821 * - During fastset the pipe is already enabled and must remain so
2823 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
2824 val |= TRANSCONF_ENABLE;
2826 if (crtc_state->double_wide)
2827 val |= TRANSCONF_DOUBLE_WIDE;
2829 /* only g4x and later have fancy bpc/dither controls */
2830 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2831 IS_CHERRYVIEW(dev_priv)) {
2832 /* Bspec claims that we can't use dithering for 30bpp pipes. */
2833 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
2834 val |= TRANSCONF_DITHER_EN |
2835 TRANSCONF_DITHER_TYPE_SP;
2837 switch (crtc_state->pipe_bpp) {
2839 /* Case prevented by intel_choose_pipe_bpp_dither. */
2840 MISSING_CASE(crtc_state->pipe_bpp);
2843 val |= TRANSCONF_BPC_6;
2846 val |= TRANSCONF_BPC_8;
2849 val |= TRANSCONF_BPC_10;
2854 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
2855 if (DISPLAY_VER(dev_priv) < 4 ||
2856 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2857 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
2859 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
2861 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
2864 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2865 crtc_state->limited_color_range)
2866 val |= TRANSCONF_COLOR_RANGE_SELECT;
2868 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
2870 if (crtc_state->wgc_enable)
2871 val |= TRANSCONF_WGC_ENABLE;
2873 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
2875 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
2876 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
2879 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
2881 if (IS_I830(dev_priv))
2884 return DISPLAY_VER(dev_priv) >= 4 ||
2885 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
2888 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
2890 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2891 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2895 if (!i9xx_has_pfit(dev_priv))
2898 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
2899 if (!(tmp & PFIT_ENABLE))
2902 /* Check whether the pfit is attached to our pipe. */
2903 if (DISPLAY_VER(dev_priv) >= 4)
2904 pipe = REG_FIELD_GET(PFIT_PIPE_MASK, tmp);
2908 if (pipe != crtc->pipe)
2911 crtc_state->gmch_pfit.control = tmp;
2912 crtc_state->gmch_pfit.pgm_ratios =
2913 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
2916 static enum intel_output_format
2917 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
2919 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2922 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
2924 if (tmp & PIPE_MISC_YUV420_ENABLE) {
2925 /* We support 4:2:0 in full blend mode only */
2926 drm_WARN_ON(&dev_priv->drm,
2927 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
2929 return INTEL_OUTPUT_FORMAT_YCBCR420;
2930 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
2931 return INTEL_OUTPUT_FORMAT_YCBCR444;
2933 return INTEL_OUTPUT_FORMAT_RGB;
2937 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
2938 struct intel_crtc_state *pipe_config)
2940 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2941 enum intel_display_power_domain power_domain;
2942 intel_wakeref_t wakeref;
2946 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
2947 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
2951 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2952 pipe_config->sink_format = pipe_config->output_format;
2953 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
2954 pipe_config->shared_dpll = NULL;
2958 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
2959 if (!(tmp & TRANSCONF_ENABLE))
2962 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2963 IS_CHERRYVIEW(dev_priv)) {
2964 switch (tmp & TRANSCONF_BPC_MASK) {
2965 case TRANSCONF_BPC_6:
2966 pipe_config->pipe_bpp = 18;
2968 case TRANSCONF_BPC_8:
2969 pipe_config->pipe_bpp = 24;
2971 case TRANSCONF_BPC_10:
2972 pipe_config->pipe_bpp = 30;
2980 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2981 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
2982 pipe_config->limited_color_range = true;
2984 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
2986 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
2988 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2989 (tmp & TRANSCONF_WGC_ENABLE))
2990 pipe_config->wgc_enable = true;
2992 intel_color_get_config(pipe_config);
2994 if (DISPLAY_VER(dev_priv) < 4)
2995 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
2997 intel_get_transcoder_timings(crtc, pipe_config);
2998 intel_get_pipe_src_size(crtc, pipe_config);
3000 i9xx_get_pfit_config(pipe_config);
3002 if (DISPLAY_VER(dev_priv) >= 4) {
3003 /* No way to read it out on pipes B and C */
3004 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
3005 tmp = dev_priv->display.state.chv_dpll_md[crtc->pipe];
3007 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
3008 pipe_config->pixel_multiplier =
3009 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3010 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3011 pipe_config->dpll_hw_state.dpll_md = tmp;
3012 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
3013 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
3014 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
3015 pipe_config->pixel_multiplier =
3016 ((tmp & SDVO_MULTIPLIER_MASK)
3017 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3019 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3020 * port and will be fixed up in the encoder->get_config
3022 pipe_config->pixel_multiplier = 1;
3024 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
3026 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
3027 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
3029 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
3032 /* Mask out read-only status bits. */
3033 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
3034 DPLL_PORTC_READY_MASK |
3035 DPLL_PORTB_READY_MASK);
3038 if (IS_CHERRYVIEW(dev_priv))
3039 chv_crtc_clock_get(crtc, pipe_config);
3040 else if (IS_VALLEYVIEW(dev_priv))
3041 vlv_crtc_clock_get(crtc, pipe_config);
3043 i9xx_crtc_clock_get(crtc, pipe_config);
3046 * Normally the dotclock is filled in by the encoder .get_config()
3047 * but in case the pipe is enabled w/o any ports we need a sane
3050 pipe_config->hw.adjusted_mode.crtc_clock =
3051 pipe_config->port_clock / pipe_config->pixel_multiplier;
3056 intel_display_power_put(dev_priv, power_domain, wakeref);
3061 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3063 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3064 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3065 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3069 * - During modeset the pipe is still disabled and must remain so
3070 * - During fastset the pipe is already enabled and must remain so
3072 if (!intel_crtc_needs_modeset(crtc_state))
3073 val |= TRANSCONF_ENABLE;
3075 switch (crtc_state->pipe_bpp) {
3077 /* Case prevented by intel_choose_pipe_bpp_dither. */
3078 MISSING_CASE(crtc_state->pipe_bpp);
3081 val |= TRANSCONF_BPC_6;
3084 val |= TRANSCONF_BPC_8;
3087 val |= TRANSCONF_BPC_10;
3090 val |= TRANSCONF_BPC_12;
3094 if (crtc_state->dither)
3095 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3097 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3098 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3100 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3103 * This would end up with an odd purple hue over
3104 * the entire display. Make sure we don't do it.
3106 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3107 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3109 if (crtc_state->limited_color_range &&
3110 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3111 val |= TRANSCONF_COLOR_RANGE_SELECT;
3113 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3114 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3116 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3118 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3119 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3121 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3122 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3125 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3127 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3128 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3129 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3133 * - During modeset the pipe is still disabled and must remain so
3134 * - During fastset the pipe is already enabled and must remain so
3136 if (!intel_crtc_needs_modeset(crtc_state))
3137 val |= TRANSCONF_ENABLE;
3139 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3140 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3142 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3143 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3145 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3147 if (IS_HASWELL(dev_priv) &&
3148 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3149 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3151 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3152 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3155 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state)
3157 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3158 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3161 switch (crtc_state->pipe_bpp) {
3163 val |= PIPE_MISC_BPC_6;
3166 val |= PIPE_MISC_BPC_8;
3169 val |= PIPE_MISC_BPC_10;
3172 /* Port output 12BPC defined for ADLP+ */
3173 if (DISPLAY_VER(dev_priv) >= 13)
3174 val |= PIPE_MISC_BPC_12_ADLP;
3177 MISSING_CASE(crtc_state->pipe_bpp);
3181 if (crtc_state->dither)
3182 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3184 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3185 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3186 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3188 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3189 val |= PIPE_MISC_YUV420_ENABLE |
3190 PIPE_MISC_YUV420_MODE_FULL_BLEND;
3192 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3193 val |= PIPE_MISC_HDR_MODE_PRECISION;
3195 if (DISPLAY_VER(dev_priv) >= 12)
3196 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3198 /* allow PSR with sprite enabled */
3199 if (IS_BROADWELL(dev_priv))
3200 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE;
3202 intel_de_write(dev_priv, PIPE_MISC(crtc->pipe), val);
3205 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3207 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3210 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3212 switch (tmp & PIPE_MISC_BPC_MASK) {
3213 case PIPE_MISC_BPC_6:
3215 case PIPE_MISC_BPC_8:
3217 case PIPE_MISC_BPC_10:
3220 * PORT OUTPUT 12 BPC defined for ADLP+.
3223 * For previous platforms with DSI interface, bits 5:7
3224 * are used for storing pipe_bpp irrespective of dithering.
3225 * Since the value of 12 BPC is not defined for these bits
3226 * on older platforms, need to find a workaround for 12 BPC
3227 * MIPI DSI HW readout.
3229 case PIPE_MISC_BPC_12_ADLP:
3230 if (DISPLAY_VER(dev_priv) >= 13)
3239 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3242 * Account for spread spectrum to avoid
3243 * oversubscribing the link. Max center spread
3244 * is 2.5%; use 5% for safety's sake.
3246 u32 bps = target_clock * bpp * 21 / 20;
3247 return DIV_ROUND_UP(bps, link_bw * 8);
3250 void intel_get_m_n(struct drm_i915_private *i915,
3251 struct intel_link_m_n *m_n,
3252 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3253 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3255 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3256 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3257 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3258 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3259 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3262 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3263 enum transcoder transcoder,
3264 struct intel_link_m_n *m_n)
3266 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3267 enum pipe pipe = crtc->pipe;
3269 if (DISPLAY_VER(dev_priv) >= 5)
3270 intel_get_m_n(dev_priv, m_n,
3271 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3272 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3274 intel_get_m_n(dev_priv, m_n,
3275 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3276 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3279 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3280 enum transcoder transcoder,
3281 struct intel_link_m_n *m_n)
3283 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3285 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3288 intel_get_m_n(dev_priv, m_n,
3289 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3290 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3293 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3295 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3296 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3300 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3301 if ((ctl & PF_ENABLE) == 0)
3304 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
3305 pipe = REG_FIELD_GET(PF_PIPE_SEL_MASK_IVB, ctl);
3309 crtc_state->pch_pfit.enabled = true;
3311 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3312 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3314 drm_rect_init(&crtc_state->pch_pfit.dst,
3315 REG_FIELD_GET(PF_WIN_XPOS_MASK, pos),
3316 REG_FIELD_GET(PF_WIN_YPOS_MASK, pos),
3317 REG_FIELD_GET(PF_WIN_XSIZE_MASK, size),
3318 REG_FIELD_GET(PF_WIN_YSIZE_MASK, size));
3321 * We currently do not free assignements of panel fitters on
3322 * ivb/hsw (since we don't use the higher upscaling modes which
3323 * differentiates them) so just WARN about this case for now.
3325 drm_WARN_ON(&dev_priv->drm, pipe != crtc->pipe);
3328 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3329 struct intel_crtc_state *pipe_config)
3331 struct drm_device *dev = crtc->base.dev;
3332 struct drm_i915_private *dev_priv = to_i915(dev);
3333 enum intel_display_power_domain power_domain;
3334 intel_wakeref_t wakeref;
3338 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3339 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3343 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3344 pipe_config->shared_dpll = NULL;
3347 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3348 if (!(tmp & TRANSCONF_ENABLE))
3351 switch (tmp & TRANSCONF_BPC_MASK) {
3352 case TRANSCONF_BPC_6:
3353 pipe_config->pipe_bpp = 18;
3355 case TRANSCONF_BPC_8:
3356 pipe_config->pipe_bpp = 24;
3358 case TRANSCONF_BPC_10:
3359 pipe_config->pipe_bpp = 30;
3361 case TRANSCONF_BPC_12:
3362 pipe_config->pipe_bpp = 36;
3368 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3369 pipe_config->limited_color_range = true;
3371 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3372 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3373 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3374 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3377 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3381 pipe_config->sink_format = pipe_config->output_format;
3383 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3385 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3387 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3389 intel_color_get_config(pipe_config);
3391 pipe_config->pixel_multiplier = 1;
3393 ilk_pch_get_config(pipe_config);
3395 intel_get_transcoder_timings(crtc, pipe_config);
3396 intel_get_pipe_src_size(crtc, pipe_config);
3398 ilk_get_pfit_config(pipe_config);
3403 intel_display_power_put(dev_priv, power_domain, wakeref);
3408 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3412 if (DISPLAY_VER(i915) >= 12)
3413 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3414 else if (DISPLAY_VER(i915) >= 11)
3415 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3419 return pipes & DISPLAY_RUNTIME_INFO(i915)->pipe_mask;
3422 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3423 enum transcoder cpu_transcoder)
3425 enum intel_display_power_domain power_domain;
3426 intel_wakeref_t wakeref;
3429 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3431 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3432 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3434 return tmp & TRANS_DDI_FUNC_ENABLE;
3437 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3438 u8 *master_pipes, u8 *slave_pipes)
3440 struct intel_crtc *crtc;
3445 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3446 bigjoiner_pipes(dev_priv)) {
3447 enum intel_display_power_domain power_domain;
3448 enum pipe pipe = crtc->pipe;
3449 intel_wakeref_t wakeref;
3451 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3452 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3453 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3455 if (!(tmp & BIG_JOINER_ENABLE))
3458 if (tmp & MASTER_BIG_JOINER_ENABLE)
3459 *master_pipes |= BIT(pipe);
3461 *slave_pipes |= BIT(pipe);
3464 if (DISPLAY_VER(dev_priv) < 13)
3467 power_domain = POWER_DOMAIN_PIPE(pipe);
3468 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3469 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3471 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3472 *master_pipes |= BIT(pipe);
3473 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3474 *slave_pipes |= BIT(pipe);
3478 /* Bigjoiner pipes should always be consecutive master and slave */
3479 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3480 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3481 *master_pipes, *slave_pipes);
3484 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3486 if ((slave_pipes & BIT(pipe)) == 0)
3489 /* ignore everything above our pipe */
3490 master_pipes &= ~GENMASK(7, pipe);
3492 /* highest remaining bit should be our master pipe */
3493 return fls(master_pipes) - 1;
3496 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3498 enum pipe master_pipe, next_master_pipe;
3500 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3502 if ((master_pipes & BIT(master_pipe)) == 0)
3505 /* ignore our master pipe and everything below it */
3506 master_pipes &= ~GENMASK(master_pipe, 0);
3507 /* make sure a high bit is set for the ffs() */
3508 master_pipes |= BIT(7);
3509 /* lowest remaining bit should be the next master pipe */
3510 next_master_pipe = ffs(master_pipes) - 1;
3512 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3515 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3517 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3519 if (DISPLAY_VER(i915) >= 11)
3520 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3522 return panel_transcoder_mask;
3525 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3527 struct drm_device *dev = crtc->base.dev;
3528 struct drm_i915_private *dev_priv = to_i915(dev);
3529 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3530 enum transcoder cpu_transcoder;
3531 u8 master_pipes, slave_pipes;
3532 u8 enabled_transcoders = 0;
3535 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3536 * consistency and less surprising code; it's in always on power).
3538 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3539 panel_transcoder_mask) {
3540 enum intel_display_power_domain power_domain;
3541 intel_wakeref_t wakeref;
3542 enum pipe trans_pipe;
3545 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3546 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3547 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3549 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3552 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3555 "unknown pipe linked to transcoder %s\n",
3556 transcoder_name(cpu_transcoder));
3558 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3559 case TRANS_DDI_EDP_INPUT_A_ON:
3560 trans_pipe = PIPE_A;
3562 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3563 trans_pipe = PIPE_B;
3565 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3566 trans_pipe = PIPE_C;
3568 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3569 trans_pipe = PIPE_D;
3573 if (trans_pipe == crtc->pipe)
3574 enabled_transcoders |= BIT(cpu_transcoder);
3577 /* single pipe or bigjoiner master */
3578 cpu_transcoder = (enum transcoder) crtc->pipe;
3579 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3580 enabled_transcoders |= BIT(cpu_transcoder);
3582 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3583 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3584 if (slave_pipes & BIT(crtc->pipe)) {
3585 cpu_transcoder = (enum transcoder)
3586 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3587 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3588 enabled_transcoders |= BIT(cpu_transcoder);
3591 return enabled_transcoders;
3594 static bool has_edp_transcoders(u8 enabled_transcoders)
3596 return enabled_transcoders & BIT(TRANSCODER_EDP);
3599 static bool has_dsi_transcoders(u8 enabled_transcoders)
3601 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3602 BIT(TRANSCODER_DSI_1));
3605 static bool has_pipe_transcoders(u8 enabled_transcoders)
3607 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3608 BIT(TRANSCODER_DSI_0) |
3609 BIT(TRANSCODER_DSI_1));
3612 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3613 u8 enabled_transcoders)
3615 /* Only one type of transcoder please */
3616 drm_WARN_ON(&i915->drm,
3617 has_edp_transcoders(enabled_transcoders) +
3618 has_dsi_transcoders(enabled_transcoders) +
3619 has_pipe_transcoders(enabled_transcoders) > 1);
3621 /* Only DSI transcoders can be ganged */
3622 drm_WARN_ON(&i915->drm,
3623 !has_dsi_transcoders(enabled_transcoders) &&
3624 !is_power_of_2(enabled_transcoders));
3627 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3628 struct intel_crtc_state *pipe_config,
3629 struct intel_display_power_domain_set *power_domain_set)
3631 struct drm_device *dev = crtc->base.dev;
3632 struct drm_i915_private *dev_priv = to_i915(dev);
3633 unsigned long enabled_transcoders;
3636 enabled_transcoders = hsw_enabled_transcoders(crtc);
3637 if (!enabled_transcoders)
3640 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3643 * With the exception of DSI we should only ever have
3644 * a single enabled transcoder. With DSI let's just
3645 * pick the first one.
3647 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3649 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3650 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3653 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3654 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3656 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3657 pipe_config->pch_pfit.force_thru = true;
3660 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3662 return tmp & TRANSCONF_ENABLE;
3665 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3666 struct intel_crtc_state *pipe_config,
3667 struct intel_display_power_domain_set *power_domain_set)
3669 struct drm_device *dev = crtc->base.dev;
3670 struct drm_i915_private *dev_priv = to_i915(dev);
3671 enum transcoder cpu_transcoder;
3675 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3677 cpu_transcoder = TRANSCODER_DSI_A;
3679 cpu_transcoder = TRANSCODER_DSI_C;
3681 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3682 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3686 * The PLL needs to be enabled with a valid divider
3687 * configuration, otherwise accessing DSI registers will hang
3688 * the machine. See BSpec North Display Engine
3689 * registers/MIPI[BXT]. We can break out here early, since we
3690 * need the same DSI PLL to be enabled for both DSI ports.
3692 if (!bxt_dsi_pll_is_enabled(dev_priv))
3695 /* XXX: this works for video mode only */
3696 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
3697 if (!(tmp & DPI_ENABLE))
3700 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
3701 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
3704 pipe_config->cpu_transcoder = cpu_transcoder;
3708 return transcoder_is_dsi(pipe_config->cpu_transcoder);
3711 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
3713 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3714 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3715 u8 master_pipes, slave_pipes;
3716 enum pipe pipe = crtc->pipe;
3718 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
3720 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
3723 crtc_state->bigjoiner_pipes =
3724 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
3725 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
3728 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
3729 struct intel_crtc_state *pipe_config)
3731 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3735 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3736 POWER_DOMAIN_PIPE(crtc->pipe)))
3739 pipe_config->shared_dpll = NULL;
3741 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
3743 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
3744 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
3745 drm_WARN_ON(&dev_priv->drm, active);
3752 intel_bigjoiner_get_config(pipe_config);
3753 intel_dsc_get_config(pipe_config);
3755 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
3756 DISPLAY_VER(dev_priv) >= 11)
3757 intel_get_transcoder_timings(crtc, pipe_config);
3759 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
3760 intel_vrr_get_config(pipe_config);
3762 intel_get_pipe_src_size(crtc, pipe_config);
3764 if (IS_HASWELL(dev_priv)) {
3765 u32 tmp = intel_de_read(dev_priv,
3766 TRANSCONF(pipe_config->cpu_transcoder));
3768 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
3769 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3771 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3773 pipe_config->output_format =
3774 bdw_get_pipe_misc_output_format(crtc);
3777 pipe_config->sink_format = pipe_config->output_format;
3779 intel_color_get_config(pipe_config);
3781 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
3782 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
3783 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3784 pipe_config->ips_linetime =
3785 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
3787 if (intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3788 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
3789 if (DISPLAY_VER(dev_priv) >= 9)
3790 skl_scaler_get_config(pipe_config);
3792 ilk_get_pfit_config(pipe_config);
3795 hsw_ips_get_config(pipe_config);
3797 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
3798 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3799 pipe_config->pixel_multiplier =
3800 intel_de_read(dev_priv,
3801 TRANS_MULT(pipe_config->cpu_transcoder)) + 1;
3803 pipe_config->pixel_multiplier = 1;
3806 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3807 tmp = intel_de_read(dev_priv, hsw_chicken_trans_reg(dev_priv, 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 int intel_dotclock_calculate(int link_freq,
3837 const struct intel_link_m_n *m_n)
3840 * The calculation for the data clock -> pixel clock is:
3841 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
3842 * But we want to avoid losing precison if possible, so:
3843 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
3845 * and for link freq (10kbs units) -> pixel clock it is:
3846 * link_symbol_clock = link_freq * 10 / link_symbol_size
3847 * pixel_clock = (m * link_symbol_clock) / n
3848 * or for more precision:
3849 * pixel_clock = (m * link_freq * 10) / (n * link_symbol_size)
3855 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq * 10),
3856 m_n->link_n * intel_dp_link_symbol_size(link_freq));
3859 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
3863 if (intel_crtc_has_dp_encoder(pipe_config))
3864 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
3865 &pipe_config->dp_m_n);
3866 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
3867 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
3868 pipe_config->pipe_bpp);
3870 dotclock = pipe_config->port_clock;
3872 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
3873 !intel_crtc_has_dp_encoder(pipe_config))
3876 if (pipe_config->pixel_multiplier)
3877 dotclock /= pipe_config->pixel_multiplier;
3882 /* Returns the currently programmed mode of the given encoder. */
3883 struct drm_display_mode *
3884 intel_encoder_current_mode(struct intel_encoder *encoder)
3886 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3887 struct intel_crtc_state *crtc_state;
3888 struct drm_display_mode *mode;
3889 struct intel_crtc *crtc;
3892 if (!encoder->get_hw_state(encoder, &pipe))
3895 crtc = intel_crtc_for_pipe(dev_priv, pipe);
3897 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
3901 crtc_state = intel_crtc_state_alloc(crtc);
3907 if (!intel_crtc_get_pipe_config(crtc_state)) {
3908 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
3913 intel_encoder_get_config(encoder, crtc_state);
3915 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
3917 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
3922 static bool encoders_cloneable(const struct intel_encoder *a,
3923 const struct intel_encoder *b)
3925 /* masks could be asymmetric, so check both ways */
3926 return a == b || (a->cloneable & BIT(b->type) &&
3927 b->cloneable & BIT(a->type));
3930 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
3931 struct intel_crtc *crtc,
3932 struct intel_encoder *encoder)
3934 struct intel_encoder *source_encoder;
3935 struct drm_connector *connector;
3936 struct drm_connector_state *connector_state;
3939 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
3940 if (connector_state->crtc != &crtc->base)
3944 to_intel_encoder(connector_state->best_encoder);
3945 if (!encoders_cloneable(encoder, source_encoder))
3952 static int icl_add_linked_planes(struct intel_atomic_state *state)
3954 struct intel_plane *plane, *linked;
3955 struct intel_plane_state *plane_state, *linked_plane_state;
3958 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
3959 linked = plane_state->planar_linked_plane;
3964 linked_plane_state = intel_atomic_get_plane_state(state, linked);
3965 if (IS_ERR(linked_plane_state))
3966 return PTR_ERR(linked_plane_state);
3968 drm_WARN_ON(state->base.dev,
3969 linked_plane_state->planar_linked_plane != plane);
3970 drm_WARN_ON(state->base.dev,
3971 linked_plane_state->planar_slave == plane_state->planar_slave);
3977 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
3979 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3980 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3981 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
3982 struct intel_plane *plane, *linked;
3983 struct intel_plane_state *plane_state;
3986 if (DISPLAY_VER(dev_priv) < 11)
3990 * Destroy all old plane links and make the slave plane invisible
3991 * in the crtc_state->active_planes mask.
3993 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
3994 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
3997 plane_state->planar_linked_plane = NULL;
3998 if (plane_state->planar_slave && !plane_state->uapi.visible) {
3999 crtc_state->enabled_planes &= ~BIT(plane->id);
4000 crtc_state->active_planes &= ~BIT(plane->id);
4001 crtc_state->update_planes |= BIT(plane->id);
4002 crtc_state->data_rate[plane->id] = 0;
4003 crtc_state->rel_data_rate[plane->id] = 0;
4006 plane_state->planar_slave = false;
4009 if (!crtc_state->nv12_planes)
4012 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4013 struct intel_plane_state *linked_state = NULL;
4015 if (plane->pipe != crtc->pipe ||
4016 !(crtc_state->nv12_planes & BIT(plane->id)))
4019 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4020 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4023 if (crtc_state->active_planes & BIT(linked->id))
4026 linked_state = intel_atomic_get_plane_state(state, linked);
4027 if (IS_ERR(linked_state))
4028 return PTR_ERR(linked_state);
4033 if (!linked_state) {
4034 drm_dbg_kms(&dev_priv->drm,
4035 "Need %d free Y planes for planar YUV\n",
4036 hweight8(crtc_state->nv12_planes));
4041 plane_state->planar_linked_plane = linked;
4043 linked_state->planar_slave = true;
4044 linked_state->planar_linked_plane = plane;
4045 crtc_state->enabled_planes |= BIT(linked->id);
4046 crtc_state->active_planes |= BIT(linked->id);
4047 crtc_state->update_planes |= BIT(linked->id);
4048 crtc_state->data_rate[linked->id] =
4049 crtc_state->data_rate_y[plane->id];
4050 crtc_state->rel_data_rate[linked->id] =
4051 crtc_state->rel_data_rate_y[plane->id];
4052 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4053 linked->base.name, plane->base.name);
4055 /* Copy parameters to slave plane */
4056 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4057 linked_state->color_ctl = plane_state->color_ctl;
4058 linked_state->view = plane_state->view;
4059 linked_state->decrypt = plane_state->decrypt;
4061 intel_plane_copy_hw_state(linked_state, plane_state);
4062 linked_state->uapi.src = plane_state->uapi.src;
4063 linked_state->uapi.dst = plane_state->uapi.dst;
4065 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4066 if (linked->id == PLANE_SPRITE5)
4067 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4068 else if (linked->id == PLANE_SPRITE4)
4069 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4070 else if (linked->id == PLANE_SPRITE3)
4071 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4072 else if (linked->id == PLANE_SPRITE2)
4073 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4075 MISSING_CASE(linked->id);
4082 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4084 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4085 struct intel_atomic_state *state =
4086 to_intel_atomic_state(new_crtc_state->uapi.state);
4087 const struct intel_crtc_state *old_crtc_state =
4088 intel_atomic_get_old_crtc_state(state, crtc);
4090 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4093 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4095 const struct drm_display_mode *pipe_mode =
4096 &crtc_state->hw.pipe_mode;
4099 if (!crtc_state->hw.enable)
4102 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4103 pipe_mode->crtc_clock);
4105 return min(linetime_wm, 0x1ff);
4108 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4109 const struct intel_cdclk_state *cdclk_state)
4111 const struct drm_display_mode *pipe_mode =
4112 &crtc_state->hw.pipe_mode;
4115 if (!crtc_state->hw.enable)
4118 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4119 cdclk_state->logical.cdclk);
4121 return min(linetime_wm, 0x1ff);
4124 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4126 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4127 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4128 const struct drm_display_mode *pipe_mode =
4129 &crtc_state->hw.pipe_mode;
4132 if (!crtc_state->hw.enable)
4135 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4136 crtc_state->pixel_rate);
4138 /* Display WA #1135: BXT:ALL GLK:ALL */
4139 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4140 skl_watermark_ipc_enabled(dev_priv))
4143 return min(linetime_wm, 0x1ff);
4146 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4147 struct intel_crtc *crtc)
4149 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4150 struct intel_crtc_state *crtc_state =
4151 intel_atomic_get_new_crtc_state(state, crtc);
4152 const struct intel_cdclk_state *cdclk_state;
4154 if (DISPLAY_VER(dev_priv) >= 9)
4155 crtc_state->linetime = skl_linetime_wm(crtc_state);
4157 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4159 if (!hsw_crtc_supports_ips(crtc))
4162 cdclk_state = intel_atomic_get_cdclk_state(state);
4163 if (IS_ERR(cdclk_state))
4164 return PTR_ERR(cdclk_state);
4166 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4172 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4173 struct intel_crtc *crtc)
4175 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4176 struct intel_crtc_state *crtc_state =
4177 intel_atomic_get_new_crtc_state(state, crtc);
4180 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4181 intel_crtc_needs_modeset(crtc_state) &&
4182 !crtc_state->hw.active)
4183 crtc_state->update_wm_post = true;
4185 if (intel_crtc_needs_modeset(crtc_state)) {
4186 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4192 * May need to update pipe gamma enable bits
4193 * when C8 planes are getting enabled/disabled.
4195 if (c8_planes_changed(crtc_state))
4196 crtc_state->uapi.color_mgmt_changed = true;
4198 if (intel_crtc_needs_color_update(crtc_state)) {
4199 ret = intel_color_check(crtc_state);
4204 ret = intel_compute_pipe_wm(state, crtc);
4206 drm_dbg_kms(&dev_priv->drm,
4207 "Target pipe watermarks are invalid\n");
4212 * Calculate 'intermediate' watermarks that satisfy both the
4213 * old state and the new state. We can program these
4216 ret = intel_compute_intermediate_wm(state, crtc);
4218 drm_dbg_kms(&dev_priv->drm,
4219 "No valid intermediate pipe watermarks are possible\n");
4223 if (DISPLAY_VER(dev_priv) >= 9) {
4224 if (intel_crtc_needs_modeset(crtc_state) ||
4225 intel_crtc_needs_fastset(crtc_state)) {
4226 ret = skl_update_scaler_crtc(crtc_state);
4231 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4236 if (HAS_IPS(dev_priv)) {
4237 ret = hsw_ips_compute_config(state, crtc);
4242 if (DISPLAY_VER(dev_priv) >= 9 ||
4243 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4244 ret = hsw_compute_linetime_wm(state, crtc);
4250 ret = intel_psr2_sel_fetch_update(state, crtc);
4258 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4259 struct intel_crtc_state *crtc_state)
4261 struct drm_connector *connector = conn_state->connector;
4262 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4263 const struct drm_display_info *info = &connector->display_info;
4266 switch (conn_state->max_bpc) {
4280 MISSING_CASE(conn_state->max_bpc);
4284 if (bpp < crtc_state->pipe_bpp) {
4285 drm_dbg_kms(&i915->drm,
4286 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4287 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4288 connector->base.id, connector->name,
4290 3 * conn_state->max_requested_bpc,
4291 crtc_state->pipe_bpp);
4293 crtc_state->pipe_bpp = bpp;
4300 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4301 struct intel_crtc *crtc)
4303 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4304 struct intel_crtc_state *crtc_state =
4305 intel_atomic_get_new_crtc_state(state, crtc);
4306 struct drm_connector *connector;
4307 struct drm_connector_state *connector_state;
4310 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4311 IS_CHERRYVIEW(dev_priv)))
4313 else if (DISPLAY_VER(dev_priv) >= 5)
4318 crtc_state->pipe_bpp = bpp;
4320 /* Clamp display bpp to connector max bpp */
4321 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4324 if (connector_state->crtc != &crtc->base)
4327 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4335 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4337 struct drm_device *dev = state->base.dev;
4338 struct drm_connector *connector;
4339 struct drm_connector_list_iter conn_iter;
4340 unsigned int used_ports = 0;
4341 unsigned int used_mst_ports = 0;
4345 * We're going to peek into connector->state,
4346 * hence connection_mutex must be held.
4348 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4351 * Walk the connector list instead of the encoder
4352 * list to detect the problem on ddi platforms
4353 * where there's just one encoder per digital port.
4355 drm_connector_list_iter_begin(dev, &conn_iter);
4356 drm_for_each_connector_iter(connector, &conn_iter) {
4357 struct drm_connector_state *connector_state;
4358 struct intel_encoder *encoder;
4361 drm_atomic_get_new_connector_state(&state->base,
4363 if (!connector_state)
4364 connector_state = connector->state;
4366 if (!connector_state->best_encoder)
4369 encoder = to_intel_encoder(connector_state->best_encoder);
4371 drm_WARN_ON(dev, !connector_state->crtc);
4373 switch (encoder->type) {
4374 case INTEL_OUTPUT_DDI:
4375 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4378 case INTEL_OUTPUT_DP:
4379 case INTEL_OUTPUT_HDMI:
4380 case INTEL_OUTPUT_EDP:
4381 /* the same port mustn't appear more than once */
4382 if (used_ports & BIT(encoder->port))
4385 used_ports |= BIT(encoder->port);
4387 case INTEL_OUTPUT_DP_MST:
4395 drm_connector_list_iter_end(&conn_iter);
4397 /* can't mix MST and SST/HDMI on the same port */
4398 if (used_ports & used_mst_ports)
4405 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4406 struct intel_crtc *crtc)
4408 struct intel_crtc_state *crtc_state =
4409 intel_atomic_get_new_crtc_state(state, crtc);
4411 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4413 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4414 crtc_state->uapi.degamma_lut);
4415 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4416 crtc_state->uapi.gamma_lut);
4417 drm_property_replace_blob(&crtc_state->hw.ctm,
4418 crtc_state->uapi.ctm);
4422 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4423 struct intel_crtc *crtc)
4425 struct intel_crtc_state *crtc_state =
4426 intel_atomic_get_new_crtc_state(state, crtc);
4428 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4430 crtc_state->hw.enable = crtc_state->uapi.enable;
4431 crtc_state->hw.active = crtc_state->uapi.active;
4432 drm_mode_copy(&crtc_state->hw.mode,
4433 &crtc_state->uapi.mode);
4434 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4435 &crtc_state->uapi.adjusted_mode);
4436 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4438 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4442 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4443 struct intel_crtc *slave_crtc)
4445 struct intel_crtc_state *slave_crtc_state =
4446 intel_atomic_get_new_crtc_state(state, slave_crtc);
4447 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4448 const struct intel_crtc_state *master_crtc_state =
4449 intel_atomic_get_new_crtc_state(state, master_crtc);
4451 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
4452 master_crtc_state->hw.degamma_lut);
4453 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
4454 master_crtc_state->hw.gamma_lut);
4455 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
4456 master_crtc_state->hw.ctm);
4458 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
4462 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
4463 struct intel_crtc *slave_crtc)
4465 struct intel_crtc_state *slave_crtc_state =
4466 intel_atomic_get_new_crtc_state(state, slave_crtc);
4467 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4468 const struct intel_crtc_state *master_crtc_state =
4469 intel_atomic_get_new_crtc_state(state, master_crtc);
4470 struct intel_crtc_state *saved_state;
4472 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4473 slave_crtc_state->bigjoiner_pipes);
4475 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4479 /* preserve some things from the slave's original crtc state */
4480 saved_state->uapi = slave_crtc_state->uapi;
4481 saved_state->scaler_state = slave_crtc_state->scaler_state;
4482 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
4483 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
4485 intel_crtc_free_hw_state(slave_crtc_state);
4486 if (slave_crtc_state->dp_tunnel_ref.tunnel)
4487 drm_dp_tunnel_ref_put(&slave_crtc_state->dp_tunnel_ref);
4488 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
4491 /* Re-init hw state */
4492 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
4493 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
4494 slave_crtc_state->hw.active = master_crtc_state->hw.active;
4495 drm_mode_copy(&slave_crtc_state->hw.mode,
4496 &master_crtc_state->hw.mode);
4497 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
4498 &master_crtc_state->hw.pipe_mode);
4499 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
4500 &master_crtc_state->hw.adjusted_mode);
4501 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
4503 if (master_crtc_state->dp_tunnel_ref.tunnel)
4504 drm_dp_tunnel_ref_get(master_crtc_state->dp_tunnel_ref.tunnel,
4505 &slave_crtc_state->dp_tunnel_ref);
4507 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
4509 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
4510 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
4511 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
4513 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4514 slave_crtc_state->bigjoiner_pipes);
4520 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4521 struct intel_crtc *crtc)
4523 struct intel_crtc_state *crtc_state =
4524 intel_atomic_get_new_crtc_state(state, crtc);
4525 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4526 struct intel_crtc_state *saved_state;
4528 saved_state = intel_crtc_state_alloc(crtc);
4532 /* free the old crtc_state->hw members */
4533 intel_crtc_free_hw_state(crtc_state);
4535 intel_dp_tunnel_atomic_clear_stream_bw(state, crtc_state);
4537 /* FIXME: before the switch to atomic started, a new pipe_config was
4538 * kzalloc'd. Code that depends on any field being zero should be
4539 * fixed, so that the crtc_state can be safely duplicated. For now,
4540 * only fields that are know to not cause problems are preserved. */
4542 saved_state->uapi = crtc_state->uapi;
4543 saved_state->inherited = crtc_state->inherited;
4544 saved_state->scaler_state = crtc_state->scaler_state;
4545 saved_state->shared_dpll = crtc_state->shared_dpll;
4546 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4547 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4548 sizeof(saved_state->icl_port_dplls));
4549 saved_state->crc_enabled = crtc_state->crc_enabled;
4550 if (IS_G4X(dev_priv) ||
4551 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4552 saved_state->wm = crtc_state->wm;
4554 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4557 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4563 intel_modeset_pipe_config(struct intel_atomic_state *state,
4564 struct intel_crtc *crtc,
4565 const struct intel_link_bw_limits *limits)
4567 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4568 struct intel_crtc_state *crtc_state =
4569 intel_atomic_get_new_crtc_state(state, crtc);
4570 struct drm_connector *connector;
4571 struct drm_connector_state *connector_state;
4572 int pipe_src_w, pipe_src_h;
4573 int base_bpp, ret, i;
4575 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4577 crtc_state->framestart_delay = 1;
4580 * Sanitize sync polarity flags based on requested ones. If neither
4581 * positive or negative polarity is requested, treat this as meaning
4582 * negative polarity.
4584 if (!(crtc_state->hw.adjusted_mode.flags &
4585 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4586 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4588 if (!(crtc_state->hw.adjusted_mode.flags &
4589 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4590 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4592 ret = compute_baseline_pipe_bpp(state, crtc);
4596 crtc_state->fec_enable = limits->force_fec_pipes & BIT(crtc->pipe);
4597 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe];
4599 if (crtc_state->pipe_bpp > to_bpp_int(crtc_state->max_link_bpp_x16)) {
4600 drm_dbg_kms(&i915->drm,
4601 "[CRTC:%d:%s] Link bpp limited to " BPP_X16_FMT "\n",
4602 crtc->base.base.id, crtc->base.name,
4603 BPP_X16_ARGS(crtc_state->max_link_bpp_x16));
4604 crtc_state->bw_constrained = true;
4607 base_bpp = crtc_state->pipe_bpp;
4610 * Determine the real pipe dimensions. Note that stereo modes can
4611 * increase the actual pipe size due to the frame doubling and
4612 * insertion of additional space for blanks between the frame. This
4613 * is stored in the crtc timings. We use the requested mode to do this
4614 * computation to clearly distinguish it from the adjusted mode, which
4615 * can be changed by the connectors in the below retry loop.
4617 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4618 &pipe_src_w, &pipe_src_h);
4619 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4620 pipe_src_w, pipe_src_h);
4622 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4623 struct intel_encoder *encoder =
4624 to_intel_encoder(connector_state->best_encoder);
4626 if (connector_state->crtc != &crtc->base)
4629 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4630 drm_dbg_kms(&i915->drm,
4631 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4632 encoder->base.base.id, encoder->base.name);
4637 * Determine output_types before calling the .compute_config()
4638 * hooks so that the hooks can use this information safely.
4640 if (encoder->compute_output_type)
4641 crtc_state->output_types |=
4642 BIT(encoder->compute_output_type(encoder, crtc_state,
4645 crtc_state->output_types |= BIT(encoder->type);
4648 /* Ensure the port clock defaults are reset when retrying. */
4649 crtc_state->port_clock = 0;
4650 crtc_state->pixel_multiplier = 1;
4652 /* Fill in default crtc timings, allow encoders to overwrite them. */
4653 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
4654 CRTC_STEREO_DOUBLE);
4656 /* Pass our mode to the connectors and the CRTC to give them a chance to
4657 * adjust it according to limitations or connector properties, and also
4658 * a chance to reject the mode entirely.
4660 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4661 struct intel_encoder *encoder =
4662 to_intel_encoder(connector_state->best_encoder);
4664 if (connector_state->crtc != &crtc->base)
4667 ret = encoder->compute_config(encoder, crtc_state,
4669 if (ret == -EDEADLK)
4672 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
4673 encoder->base.base.id, encoder->base.name, ret);
4678 /* Set default port clock if not overwritten by the encoder. Needs to be
4679 * done afterwards in case the encoder adjusts the mode. */
4680 if (!crtc_state->port_clock)
4681 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
4682 * crtc_state->pixel_multiplier;
4684 ret = intel_crtc_compute_config(state, crtc);
4685 if (ret == -EDEADLK)
4688 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
4689 crtc->base.base.id, crtc->base.name, ret);
4693 /* Dithering seems to not pass-through bits correctly when it should, so
4694 * only enable it on 6bpc panels and when its not a compliance
4695 * test requesting 6bpc video pattern.
4697 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
4698 !crtc_state->dither_force_disable;
4699 drm_dbg_kms(&i915->drm,
4700 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
4701 crtc->base.base.id, crtc->base.name,
4702 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
4708 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
4709 struct intel_crtc *crtc)
4711 struct intel_crtc_state *crtc_state =
4712 intel_atomic_get_new_crtc_state(state, crtc);
4713 struct drm_connector_state *conn_state;
4714 struct drm_connector *connector;
4717 intel_bigjoiner_adjust_pipe_src(crtc_state);
4719 for_each_new_connector_in_state(&state->base, connector,
4721 struct intel_encoder *encoder =
4722 to_intel_encoder(conn_state->best_encoder);
4725 if (conn_state->crtc != &crtc->base ||
4726 !encoder->compute_config_late)
4729 ret = encoder->compute_config_late(encoder, crtc_state,
4738 bool intel_fuzzy_clock_check(int clock1, int clock2)
4742 if (clock1 == clock2)
4745 if (!clock1 || !clock2)
4748 diff = abs(clock1 - clock2);
4750 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
4757 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
4758 const struct intel_link_m_n *m2_n2)
4760 return m_n->tu == m2_n2->tu &&
4761 m_n->data_m == m2_n2->data_m &&
4762 m_n->data_n == m2_n2->data_n &&
4763 m_n->link_m == m2_n2->link_m &&
4764 m_n->link_n == m2_n2->link_n;
4768 intel_compare_infoframe(const union hdmi_infoframe *a,
4769 const union hdmi_infoframe *b)
4771 return memcmp(a, b, sizeof(*a)) == 0;
4775 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
4776 const struct drm_dp_vsc_sdp *b)
4778 return a->pixelformat == b->pixelformat &&
4779 a->colorimetry == b->colorimetry &&
4781 a->dynamic_range == b->dynamic_range &&
4782 a->content_type == b->content_type;
4786 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
4788 return memcmp(a, b, len) == 0;
4792 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
4793 bool fastset, const char *name,
4794 const union hdmi_infoframe *a,
4795 const union hdmi_infoframe *b)
4798 if (!drm_debug_enabled(DRM_UT_KMS))
4801 drm_dbg_kms(&dev_priv->drm,
4802 "fastset requirement not met in %s infoframe\n", name);
4803 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4804 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
4805 drm_dbg_kms(&dev_priv->drm, "found:\n");
4806 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
4808 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
4809 drm_err(&dev_priv->drm, "expected:\n");
4810 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
4811 drm_err(&dev_priv->drm, "found:\n");
4812 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
4817 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *i915,
4818 bool fastset, const char *name,
4819 const struct drm_dp_vsc_sdp *a,
4820 const struct drm_dp_vsc_sdp *b)
4822 struct drm_printer p;
4825 p = drm_dbg_printer(&i915->drm, DRM_UT_KMS, NULL);
4827 drm_printf(&p, "fastset requirement not met in %s dp sdp\n", name);
4829 p = drm_err_printer(&i915->drm, NULL);
4831 drm_printf(&p, "mismatch in %s dp sdp\n", name);
4834 drm_printf(&p, "expected:\n");
4835 drm_dp_vsc_sdp_log(&p, a);
4836 drm_printf(&p, "found:\n");
4837 drm_dp_vsc_sdp_log(&p, b);
4840 /* Returns the length up to and including the last differing byte */
4842 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
4846 for (i = len - 1; i >= 0; i--) {
4855 pipe_config_buffer_mismatch(bool fastset, const struct intel_crtc *crtc,
4857 const u8 *a, const u8 *b, size_t len)
4859 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4862 if (!drm_debug_enabled(DRM_UT_KMS))
4865 /* only dump up to the last difference */
4866 len = memcmp_diff_len(a, b, len);
4868 drm_dbg_kms(&dev_priv->drm,
4869 "[CRTC:%d:%s] fastset requirement not met in %s buffer\n",
4870 crtc->base.base.id, crtc->base.name, name);
4871 print_hex_dump(KERN_DEBUG, "expected: ", DUMP_PREFIX_NONE,
4872 16, 0, a, len, false);
4873 print_hex_dump(KERN_DEBUG, "found: ", DUMP_PREFIX_NONE,
4874 16, 0, b, len, false);
4876 /* only dump up to the last difference */
4877 len = memcmp_diff_len(a, b, len);
4879 drm_err(&dev_priv->drm, "[CRTC:%d:%s] mismatch in %s buffer\n",
4880 crtc->base.base.id, crtc->base.name, name);
4881 print_hex_dump(KERN_ERR, "expected: ", DUMP_PREFIX_NONE,
4882 16, 0, a, len, false);
4883 print_hex_dump(KERN_ERR, "found: ", DUMP_PREFIX_NONE,
4884 16, 0, b, len, false);
4888 static void __printf(4, 5)
4889 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
4890 const char *name, const char *format, ...)
4892 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4893 struct va_format vaf;
4896 va_start(args, format);
4901 drm_dbg_kms(&i915->drm,
4902 "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
4903 crtc->base.base.id, crtc->base.name, name, &vaf);
4905 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
4906 crtc->base.base.id, crtc->base.name, name, &vaf);
4912 pipe_config_pll_mismatch(bool fastset,
4913 const struct intel_crtc *crtc,
4915 const struct intel_dpll_hw_state *a,
4916 const struct intel_dpll_hw_state *b)
4918 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4921 if (!drm_debug_enabled(DRM_UT_KMS))
4924 drm_dbg_kms(&i915->drm,
4925 "[CRTC:%d:%s] fastset requirement not met in %s\n",
4926 crtc->base.base.id, crtc->base.name, name);
4927 drm_dbg_kms(&i915->drm, "expected:\n");
4928 intel_dpll_dump_hw_state(i915, a);
4929 drm_dbg_kms(&i915->drm, "found:\n");
4930 intel_dpll_dump_hw_state(i915, b);
4932 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s buffer\n",
4933 crtc->base.base.id, crtc->base.name, name);
4934 drm_err(&i915->drm, "expected:\n");
4935 intel_dpll_dump_hw_state(i915, a);
4936 drm_err(&i915->drm, "found:\n");
4937 intel_dpll_dump_hw_state(i915, b);
4942 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
4943 const struct intel_crtc_state *pipe_config,
4946 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
4947 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
4950 #define PIPE_CONF_CHECK_X(name) do { \
4951 if (current_config->name != pipe_config->name) { \
4952 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
4953 __stringify(name) " is bool"); \
4954 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4955 "(expected 0x%08x, found 0x%08x)", \
4956 current_config->name, \
4957 pipe_config->name); \
4962 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
4963 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
4964 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
4965 __stringify(name) " is bool"); \
4966 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4967 "(expected 0x%08x, found 0x%08x)", \
4968 current_config->name & (mask), \
4969 pipe_config->name & (mask)); \
4974 #define PIPE_CONF_CHECK_I(name) do { \
4975 if (current_config->name != pipe_config->name) { \
4976 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
4977 __stringify(name) " is bool"); \
4978 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4979 "(expected %i, found %i)", \
4980 current_config->name, \
4981 pipe_config->name); \
4986 #define PIPE_CONF_CHECK_BOOL(name) do { \
4987 if (current_config->name != pipe_config->name) { \
4988 BUILD_BUG_ON_MSG(!__same_type(current_config->name, bool), \
4989 __stringify(name) " is not bool"); \
4990 pipe_config_mismatch(fastset, crtc, __stringify(name), \
4991 "(expected %s, found %s)", \
4992 str_yes_no(current_config->name), \
4993 str_yes_no(pipe_config->name)); \
4998 #define PIPE_CONF_CHECK_P(name) do { \
4999 if (current_config->name != pipe_config->name) { \
5000 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5001 "(expected %p, found %p)", \
5002 current_config->name, \
5003 pipe_config->name); \
5008 #define PIPE_CONF_CHECK_M_N(name) do { \
5009 if (!intel_compare_link_m_n(¤t_config->name, \
5010 &pipe_config->name)) { \
5011 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5012 "(expected tu %i data %i/%i link %i/%i, " \
5013 "found tu %i, data %i/%i link %i/%i)", \
5014 current_config->name.tu, \
5015 current_config->name.data_m, \
5016 current_config->name.data_n, \
5017 current_config->name.link_m, \
5018 current_config->name.link_n, \
5019 pipe_config->name.tu, \
5020 pipe_config->name.data_m, \
5021 pipe_config->name.data_n, \
5022 pipe_config->name.link_m, \
5023 pipe_config->name.link_n); \
5028 #define PIPE_CONF_CHECK_PLL(name) do { \
5029 if (!intel_dpll_compare_hw_state(dev_priv, ¤t_config->name, \
5030 &pipe_config->name)) { \
5031 pipe_config_pll_mismatch(fastset, crtc, __stringify(name), \
5032 ¤t_config->name, \
5033 &pipe_config->name); \
5038 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5039 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5040 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5041 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5042 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5043 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5044 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5045 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5046 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5047 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5048 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5049 if (!fastset || !pipe_config->update_lrr) { \
5050 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5051 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5055 #define PIPE_CONF_CHECK_RECT(name) do { \
5056 PIPE_CONF_CHECK_I(name.x1); \
5057 PIPE_CONF_CHECK_I(name.x2); \
5058 PIPE_CONF_CHECK_I(name.y1); \
5059 PIPE_CONF_CHECK_I(name.y2); \
5062 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5063 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5064 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5065 "(%x) (expected %i, found %i)", \
5067 current_config->name & (mask), \
5068 pipe_config->name & (mask)); \
5073 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5074 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5075 &pipe_config->infoframes.name)) { \
5076 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
5077 ¤t_config->infoframes.name, \
5078 &pipe_config->infoframes.name); \
5083 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5084 if (!intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5085 &pipe_config->infoframes.name)) { \
5086 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
5087 ¤t_config->infoframes.name, \
5088 &pipe_config->infoframes.name); \
5093 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
5094 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
5095 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
5096 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5097 pipe_config_buffer_mismatch(fastset, crtc, __stringify(name), \
5098 current_config->name, \
5099 pipe_config->name, \
5105 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5106 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5107 !intel_color_lut_equal(current_config, \
5108 current_config->lut, pipe_config->lut, \
5109 is_pre_csc_lut)) { \
5110 pipe_config_mismatch(fastset, crtc, __stringify(lut), \
5111 "hw_state doesn't match sw_state"); \
5116 #define PIPE_CONF_CHECK_CSC(name) do { \
5117 PIPE_CONF_CHECK_X(name.preoff[0]); \
5118 PIPE_CONF_CHECK_X(name.preoff[1]); \
5119 PIPE_CONF_CHECK_X(name.preoff[2]); \
5120 PIPE_CONF_CHECK_X(name.coeff[0]); \
5121 PIPE_CONF_CHECK_X(name.coeff[1]); \
5122 PIPE_CONF_CHECK_X(name.coeff[2]); \
5123 PIPE_CONF_CHECK_X(name.coeff[3]); \
5124 PIPE_CONF_CHECK_X(name.coeff[4]); \
5125 PIPE_CONF_CHECK_X(name.coeff[5]); \
5126 PIPE_CONF_CHECK_X(name.coeff[6]); \
5127 PIPE_CONF_CHECK_X(name.coeff[7]); \
5128 PIPE_CONF_CHECK_X(name.coeff[8]); \
5129 PIPE_CONF_CHECK_X(name.postoff[0]); \
5130 PIPE_CONF_CHECK_X(name.postoff[1]); \
5131 PIPE_CONF_CHECK_X(name.postoff[2]); \
5134 #define PIPE_CONF_QUIRK(quirk) \
5135 ((current_config->quirks | pipe_config->quirks) & (quirk))
5137 PIPE_CONF_CHECK_BOOL(hw.enable);
5138 PIPE_CONF_CHECK_BOOL(hw.active);
5140 PIPE_CONF_CHECK_I(cpu_transcoder);
5141 PIPE_CONF_CHECK_I(mst_master_transcoder);
5143 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5144 PIPE_CONF_CHECK_I(fdi_lanes);
5145 PIPE_CONF_CHECK_M_N(fdi_m_n);
5147 PIPE_CONF_CHECK_I(lane_count);
5148 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5150 if (HAS_DOUBLE_BUFFERED_M_N(dev_priv)) {
5151 if (!fastset || !pipe_config->update_m_n)
5152 PIPE_CONF_CHECK_M_N(dp_m_n);
5154 PIPE_CONF_CHECK_M_N(dp_m_n);
5155 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5158 PIPE_CONF_CHECK_X(output_types);
5160 PIPE_CONF_CHECK_I(framestart_delay);
5161 PIPE_CONF_CHECK_I(msa_timing_delay);
5163 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5164 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5166 PIPE_CONF_CHECK_I(pixel_multiplier);
5168 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5169 DRM_MODE_FLAG_INTERLACE);
5171 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5172 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5173 DRM_MODE_FLAG_PHSYNC);
5174 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5175 DRM_MODE_FLAG_NHSYNC);
5176 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5177 DRM_MODE_FLAG_PVSYNC);
5178 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5179 DRM_MODE_FLAG_NVSYNC);
5182 PIPE_CONF_CHECK_I(output_format);
5183 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5184 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5185 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5186 PIPE_CONF_CHECK_BOOL(limited_color_range);
5188 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5189 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5190 PIPE_CONF_CHECK_BOOL(has_infoframe);
5191 PIPE_CONF_CHECK_BOOL(enhanced_framing);
5192 PIPE_CONF_CHECK_BOOL(fec_enable);
5195 PIPE_CONF_CHECK_BOOL(has_audio);
5196 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5199 PIPE_CONF_CHECK_X(gmch_pfit.control);
5200 /* pfit ratios are autocomputed by the hw on gen4+ */
5201 if (DISPLAY_VER(dev_priv) < 4)
5202 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5203 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5206 * Changing the EDP transcoder input mux
5207 * (A_ONOFF vs. A_ON) requires a full modeset.
5209 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5212 PIPE_CONF_CHECK_RECT(pipe_src);
5214 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5215 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5217 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5218 PIPE_CONF_CHECK_I(pixel_rate);
5220 PIPE_CONF_CHECK_X(gamma_mode);
5221 if (IS_CHERRYVIEW(dev_priv))
5222 PIPE_CONF_CHECK_X(cgm_mode);
5224 PIPE_CONF_CHECK_X(csc_mode);
5225 PIPE_CONF_CHECK_BOOL(gamma_enable);
5226 PIPE_CONF_CHECK_BOOL(csc_enable);
5227 PIPE_CONF_CHECK_BOOL(wgc_enable);
5229 PIPE_CONF_CHECK_I(linetime);
5230 PIPE_CONF_CHECK_I(ips_linetime);
5232 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5233 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5235 PIPE_CONF_CHECK_CSC(csc);
5236 PIPE_CONF_CHECK_CSC(output_csc);
5239 PIPE_CONF_CHECK_BOOL(double_wide);
5241 if (dev_priv->display.dpll.mgr)
5242 PIPE_CONF_CHECK_P(shared_dpll);
5244 /* FIXME convert everything over the dpll_mgr */
5245 if (dev_priv->display.dpll.mgr || HAS_GMCH(dev_priv))
5246 PIPE_CONF_CHECK_PLL(dpll_hw_state);
5248 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5249 PIPE_CONF_CHECK_X(dsi_pll.div);
5251 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5252 PIPE_CONF_CHECK_I(pipe_bpp);
5254 if (!fastset || !pipe_config->update_m_n) {
5255 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5256 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5258 PIPE_CONF_CHECK_I(port_clock);
5260 PIPE_CONF_CHECK_I(min_voltage_level);
5262 if (current_config->has_psr || pipe_config->has_psr)
5263 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5264 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5266 PIPE_CONF_CHECK_X(infoframes.enable);
5268 PIPE_CONF_CHECK_X(infoframes.gcp);
5269 PIPE_CONF_CHECK_INFOFRAME(avi);
5270 PIPE_CONF_CHECK_INFOFRAME(spd);
5271 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5272 PIPE_CONF_CHECK_INFOFRAME(drm);
5273 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5275 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5276 PIPE_CONF_CHECK_I(master_transcoder);
5277 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5279 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable);
5280 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb);
5281 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422);
5282 PIPE_CONF_CHECK_BOOL(dsc.config.native_422);
5283 PIPE_CONF_CHECK_BOOL(dsc.config.native_420);
5284 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable);
5285 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth);
5286 PIPE_CONF_CHECK_I(dsc.config.bits_per_component);
5287 PIPE_CONF_CHECK_I(dsc.config.pic_width);
5288 PIPE_CONF_CHECK_I(dsc.config.pic_height);
5289 PIPE_CONF_CHECK_I(dsc.config.slice_width);
5290 PIPE_CONF_CHECK_I(dsc.config.slice_height);
5291 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay);
5292 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay);
5293 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval);
5294 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval);
5295 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value);
5296 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset);
5297 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp);
5298 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp);
5299 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset);
5300 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset);
5301 PIPE_CONF_CHECK_I(dsc.config.initial_offset);
5302 PIPE_CONF_CHECK_I(dsc.config.final_offset);
5303 PIPE_CONF_CHECK_I(dsc.config.rc_model_size);
5304 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0);
5305 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1);
5306 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size);
5307 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset);
5308 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset);
5310 PIPE_CONF_CHECK_BOOL(dsc.compression_enable);
5311 PIPE_CONF_CHECK_BOOL(dsc.dsc_split);
5312 PIPE_CONF_CHECK_I(dsc.compressed_bpp_x16);
5314 PIPE_CONF_CHECK_BOOL(splitter.enable);
5315 PIPE_CONF_CHECK_I(splitter.link_count);
5316 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5319 PIPE_CONF_CHECK_BOOL(vrr.enable);
5320 PIPE_CONF_CHECK_I(vrr.vmin);
5321 PIPE_CONF_CHECK_I(vrr.vmax);
5322 PIPE_CONF_CHECK_I(vrr.flipline);
5323 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5324 PIPE_CONF_CHECK_I(vrr.guardband);
5327 #undef PIPE_CONF_CHECK_X
5328 #undef PIPE_CONF_CHECK_I
5329 #undef PIPE_CONF_CHECK_BOOL
5330 #undef PIPE_CONF_CHECK_P
5331 #undef PIPE_CONF_CHECK_FLAGS
5332 #undef PIPE_CONF_CHECK_COLOR_LUT
5333 #undef PIPE_CONF_CHECK_TIMINGS
5334 #undef PIPE_CONF_CHECK_RECT
5335 #undef PIPE_CONF_QUIRK
5341 intel_verify_planes(struct intel_atomic_state *state)
5343 struct intel_plane *plane;
5344 const struct intel_plane_state *plane_state;
5347 for_each_new_intel_plane_in_state(state, plane,
5349 assert_plane(plane, plane_state->planar_slave ||
5350 plane_state->uapi.visible);
5353 static int intel_modeset_pipe(struct intel_atomic_state *state,
5354 struct intel_crtc_state *crtc_state,
5357 struct drm_i915_private *i915 = to_i915(state->base.dev);
5358 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5361 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5362 crtc->base.base.id, crtc->base.name, reason);
5364 ret = drm_atomic_add_affected_connectors(&state->base,
5369 ret = intel_dp_tunnel_atomic_add_state_for_crtc(state, crtc);
5373 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5377 ret = intel_atomic_add_affected_planes(state, crtc);
5381 crtc_state->uapi.mode_changed = true;
5387 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes
5388 * @state: intel atomic state
5389 * @reason: the reason for the full modeset
5390 * @mask: mask of pipes to modeset
5392 * Add pipes in @mask to @state and force a full modeset on the enabled ones
5393 * due to the description in @reason.
5394 * This function can be called only before new plane states are computed.
5396 * Returns 0 in case of success, negative error code otherwise.
5398 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
5399 const char *reason, u8 mask)
5401 struct drm_i915_private *i915 = to_i915(state->base.dev);
5402 struct intel_crtc *crtc;
5404 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, mask) {
5405 struct intel_crtc_state *crtc_state;
5408 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5409 if (IS_ERR(crtc_state))
5410 return PTR_ERR(crtc_state);
5412 if (!crtc_state->hw.enable ||
5413 intel_crtc_needs_modeset(crtc_state))
5416 ret = intel_modeset_pipe(state, crtc_state, reason);
5425 intel_crtc_flag_modeset(struct intel_crtc_state *crtc_state)
5427 crtc_state->uapi.mode_changed = true;
5429 crtc_state->update_pipe = false;
5430 crtc_state->update_m_n = false;
5431 crtc_state->update_lrr = false;
5435 * intel_modeset_all_pipes_late - force a full modeset on all pipes
5436 * @state: intel atomic state
5437 * @reason: the reason for the full modeset
5439 * Add all pipes to @state and force a full modeset on the active ones due to
5440 * the description in @reason.
5441 * This function can be called only after new plane states are computed already.
5443 * Returns 0 in case of success, negative error code otherwise.
5445 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
5448 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5449 struct intel_crtc *crtc;
5451 for_each_intel_crtc(&dev_priv->drm, crtc) {
5452 struct intel_crtc_state *crtc_state;
5455 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5456 if (IS_ERR(crtc_state))
5457 return PTR_ERR(crtc_state);
5459 if (!crtc_state->hw.active ||
5460 intel_crtc_needs_modeset(crtc_state))
5463 ret = intel_modeset_pipe(state, crtc_state, reason);
5467 intel_crtc_flag_modeset(crtc_state);
5469 crtc_state->update_planes |= crtc_state->active_planes;
5470 crtc_state->async_flip_planes = 0;
5471 crtc_state->do_async_flip = false;
5478 * This implements the workaround described in the "notes" section of the mode
5479 * set sequence documentation. When going from no pipes or single pipe to
5480 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5481 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5483 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5485 struct intel_crtc_state *crtc_state;
5486 struct intel_crtc *crtc;
5487 struct intel_crtc_state *first_crtc_state = NULL;
5488 struct intel_crtc_state *other_crtc_state = NULL;
5489 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5492 /* look at all crtc's that are going to be enabled in during modeset */
5493 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5494 if (!crtc_state->hw.active ||
5495 !intel_crtc_needs_modeset(crtc_state))
5498 if (first_crtc_state) {
5499 other_crtc_state = crtc_state;
5502 first_crtc_state = crtc_state;
5503 first_pipe = crtc->pipe;
5507 /* No workaround needed? */
5508 if (!first_crtc_state)
5511 /* w/a possibly needed, check how many crtc's are already enabled. */
5512 for_each_intel_crtc(state->base.dev, crtc) {
5513 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5514 if (IS_ERR(crtc_state))
5515 return PTR_ERR(crtc_state);
5517 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5519 if (!crtc_state->hw.active ||
5520 intel_crtc_needs_modeset(crtc_state))
5523 /* 2 or more enabled crtcs means no need for w/a */
5524 if (enabled_pipe != INVALID_PIPE)
5527 enabled_pipe = crtc->pipe;
5530 if (enabled_pipe != INVALID_PIPE)
5531 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5532 else if (other_crtc_state)
5533 other_crtc_state->hsw_workaround_pipe = first_pipe;
5538 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
5541 const struct intel_crtc_state *crtc_state;
5542 struct intel_crtc *crtc;
5545 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5546 if (crtc_state->hw.active)
5547 active_pipes |= BIT(crtc->pipe);
5549 active_pipes &= ~BIT(crtc->pipe);
5552 return active_pipes;
5555 static int intel_modeset_checks(struct intel_atomic_state *state)
5557 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5559 state->modeset = true;
5561 if (IS_HASWELL(dev_priv))
5562 return hsw_mode_set_planes_workaround(state);
5567 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
5568 struct intel_crtc_state *new_crtc_state)
5570 struct drm_i915_private *i915 = to_i915(old_crtc_state->uapi.crtc->dev);
5572 /* only allow LRR when the timings stay within the VRR range */
5573 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range)
5574 new_crtc_state->update_lrr = false;
5576 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
5577 drm_dbg_kms(&i915->drm, "fastset requirement not met, forcing full modeset\n");
5579 new_crtc_state->uapi.mode_changed = false;
5581 if (intel_compare_link_m_n(&old_crtc_state->dp_m_n,
5582 &new_crtc_state->dp_m_n))
5583 new_crtc_state->update_m_n = false;
5585 if ((old_crtc_state->hw.adjusted_mode.crtc_vtotal == new_crtc_state->hw.adjusted_mode.crtc_vtotal &&
5586 old_crtc_state->hw.adjusted_mode.crtc_vblank_end == new_crtc_state->hw.adjusted_mode.crtc_vblank_end))
5587 new_crtc_state->update_lrr = false;
5589 if (intel_crtc_needs_modeset(new_crtc_state))
5590 intel_crtc_flag_modeset(new_crtc_state);
5592 new_crtc_state->update_pipe = true;
5595 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
5596 struct intel_crtc *crtc,
5599 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5600 struct intel_plane *plane;
5602 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5603 struct intel_plane_state *plane_state;
5605 if ((plane_ids_mask & BIT(plane->id)) == 0)
5608 plane_state = intel_atomic_get_plane_state(state, plane);
5609 if (IS_ERR(plane_state))
5610 return PTR_ERR(plane_state);
5616 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
5617 struct intel_crtc *crtc)
5619 const struct intel_crtc_state *old_crtc_state =
5620 intel_atomic_get_old_crtc_state(state, crtc);
5621 const struct intel_crtc_state *new_crtc_state =
5622 intel_atomic_get_new_crtc_state(state, crtc);
5624 return intel_crtc_add_planes_to_state(state, crtc,
5625 old_crtc_state->enabled_planes |
5626 new_crtc_state->enabled_planes);
5629 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
5631 /* See {hsw,vlv,ivb}_plane_ratio() */
5632 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
5633 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
5634 IS_IVYBRIDGE(dev_priv);
5637 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
5638 struct intel_crtc *crtc,
5639 struct intel_crtc *other)
5641 const struct intel_plane_state __maybe_unused *plane_state;
5642 struct intel_plane *plane;
5646 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5647 if (plane->pipe == crtc->pipe)
5648 plane_ids |= BIT(plane->id);
5651 return intel_crtc_add_planes_to_state(state, other, plane_ids);
5654 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
5656 struct drm_i915_private *i915 = to_i915(state->base.dev);
5657 const struct intel_crtc_state *crtc_state;
5658 struct intel_crtc *crtc;
5661 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5662 struct intel_crtc *other;
5664 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
5665 crtc_state->bigjoiner_pipes) {
5671 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
5680 static int intel_atomic_check_planes(struct intel_atomic_state *state)
5682 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5683 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5684 struct intel_plane_state __maybe_unused *plane_state;
5685 struct intel_plane *plane;
5686 struct intel_crtc *crtc;
5689 ret = icl_add_linked_planes(state);
5693 ret = intel_bigjoiner_add_affected_planes(state);
5697 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5698 ret = intel_plane_atomic_check(state, plane);
5700 drm_dbg_atomic(&dev_priv->drm,
5701 "[PLANE:%d:%s] atomic driver check failed\n",
5702 plane->base.base.id, plane->base.name);
5707 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5708 new_crtc_state, i) {
5709 u8 old_active_planes, new_active_planes;
5711 ret = icl_check_nv12_planes(new_crtc_state);
5716 * On some platforms the number of active planes affects
5717 * the planes' minimum cdclk calculation. Add such planes
5718 * to the state before we compute the minimum cdclk.
5720 if (!active_planes_affects_min_cdclk(dev_priv))
5723 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5724 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5726 if (hweight8(old_active_planes) == hweight8(new_active_planes))
5729 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
5737 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
5739 struct intel_crtc_state __maybe_unused *crtc_state;
5740 struct intel_crtc *crtc;
5743 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5744 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5747 ret = intel_crtc_atomic_check(state, crtc);
5749 drm_dbg_atomic(&i915->drm,
5750 "[CRTC:%d:%s] atomic driver check failed\n",
5751 crtc->base.base.id, crtc->base.name);
5759 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
5762 const struct intel_crtc_state *new_crtc_state;
5763 struct intel_crtc *crtc;
5766 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5767 if (new_crtc_state->hw.enable &&
5768 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
5769 intel_crtc_needs_modeset(new_crtc_state))
5776 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
5779 const struct intel_crtc_state *new_crtc_state;
5780 struct intel_crtc *crtc;
5783 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5784 if (new_crtc_state->hw.enable &&
5785 pipes & BIT(crtc->pipe) &&
5786 intel_crtc_needs_modeset(new_crtc_state))
5793 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
5794 struct intel_crtc *master_crtc)
5796 struct drm_i915_private *i915 = to_i915(state->base.dev);
5797 struct intel_crtc_state *master_crtc_state =
5798 intel_atomic_get_new_crtc_state(state, master_crtc);
5799 struct intel_crtc *slave_crtc;
5801 if (!master_crtc_state->bigjoiner_pipes)
5805 if (drm_WARN_ON(&i915->drm,
5806 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
5809 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
5810 drm_dbg_kms(&i915->drm,
5811 "[CRTC:%d:%s] Cannot act as big joiner master "
5812 "(need 0x%x as pipes, only 0x%x possible)\n",
5813 master_crtc->base.base.id, master_crtc->base.name,
5814 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
5818 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5819 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5820 struct intel_crtc_state *slave_crtc_state;
5823 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
5824 if (IS_ERR(slave_crtc_state))
5825 return PTR_ERR(slave_crtc_state);
5827 /* master being enabled, slave was already configured? */
5828 if (slave_crtc_state->uapi.enable) {
5829 drm_dbg_kms(&i915->drm,
5830 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
5831 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
5832 slave_crtc->base.base.id, slave_crtc->base.name,
5833 master_crtc->base.base.id, master_crtc->base.name);
5838 * The state copy logic assumes the master crtc gets processed
5839 * before the slave crtc during the main compute_config loop.
5840 * This works because the crtcs are created in pipe order,
5841 * and the hardware requires master pipe < slave pipe as well.
5842 * Should that change we need to rethink the logic.
5844 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
5845 drm_crtc_index(&slave_crtc->base)))
5848 drm_dbg_kms(&i915->drm,
5849 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
5850 slave_crtc->base.base.id, slave_crtc->base.name,
5851 master_crtc->base.base.id, master_crtc->base.name);
5853 slave_crtc_state->bigjoiner_pipes =
5854 master_crtc_state->bigjoiner_pipes;
5856 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
5864 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
5865 struct intel_crtc *master_crtc)
5867 struct drm_i915_private *i915 = to_i915(state->base.dev);
5868 struct intel_crtc_state *master_crtc_state =
5869 intel_atomic_get_new_crtc_state(state, master_crtc);
5870 struct intel_crtc *slave_crtc;
5872 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5873 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5874 struct intel_crtc_state *slave_crtc_state =
5875 intel_atomic_get_new_crtc_state(state, slave_crtc);
5877 slave_crtc_state->bigjoiner_pipes = 0;
5879 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
5882 master_crtc_state->bigjoiner_pipes = 0;
5886 * DOC: asynchronous flip implementation
5888 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
5889 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
5890 * Correspondingly, support is currently added for primary plane only.
5892 * Async flip can only change the plane surface address, so anything else
5893 * changing is rejected from the intel_async_flip_check_hw() function.
5894 * Once this check is cleared, flip done interrupt is enabled using
5895 * the intel_crtc_enable_flip_done() function.
5897 * As soon as the surface address register is written, flip done interrupt is
5898 * generated and the requested events are sent to the usersapce in the interrupt
5899 * handler itself. The timestamp and sequence sent during the flip done event
5900 * correspond to the last vblank and have no relation to the actual time when
5901 * the flip done event was sent.
5903 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
5904 struct intel_crtc *crtc)
5906 struct drm_i915_private *i915 = to_i915(state->base.dev);
5907 const struct intel_crtc_state *new_crtc_state =
5908 intel_atomic_get_new_crtc_state(state, crtc);
5909 const struct intel_plane_state *old_plane_state;
5910 struct intel_plane_state *new_plane_state;
5911 struct intel_plane *plane;
5914 if (!new_crtc_state->uapi.async_flip)
5917 if (!new_crtc_state->uapi.active) {
5918 drm_dbg_kms(&i915->drm,
5919 "[CRTC:%d:%s] not active\n",
5920 crtc->base.base.id, crtc->base.name);
5924 if (intel_crtc_needs_modeset(new_crtc_state)) {
5925 drm_dbg_kms(&i915->drm,
5926 "[CRTC:%d:%s] modeset required\n",
5927 crtc->base.base.id, crtc->base.name);
5932 * FIXME: Bigjoiner+async flip is busted currently.
5933 * Remove this check once the issues are fixed.
5935 if (new_crtc_state->bigjoiner_pipes) {
5936 drm_dbg_kms(&i915->drm,
5937 "[CRTC:%d:%s] async flip disallowed with bigjoiner\n",
5938 crtc->base.base.id, crtc->base.name);
5942 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5943 new_plane_state, i) {
5944 if (plane->pipe != crtc->pipe)
5948 * TODO: Async flip is only supported through the page flip IOCTL
5949 * as of now. So support currently added for primary plane only.
5950 * Support for other planes on platforms on which supports
5951 * this(vlv/chv and icl+) should be added when async flip is
5952 * enabled in the atomic IOCTL path.
5954 if (!plane->async_flip) {
5955 drm_dbg_kms(&i915->drm,
5956 "[PLANE:%d:%s] async flip not supported\n",
5957 plane->base.base.id, plane->base.name);
5961 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
5962 drm_dbg_kms(&i915->drm,
5963 "[PLANE:%d:%s] no old or new framebuffer\n",
5964 plane->base.base.id, plane->base.name);
5972 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
5974 struct drm_i915_private *i915 = to_i915(state->base.dev);
5975 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5976 const struct intel_plane_state *new_plane_state, *old_plane_state;
5977 struct intel_plane *plane;
5980 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
5981 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
5983 if (!new_crtc_state->uapi.async_flip)
5986 if (!new_crtc_state->hw.active) {
5987 drm_dbg_kms(&i915->drm,
5988 "[CRTC:%d:%s] not active\n",
5989 crtc->base.base.id, crtc->base.name);
5993 if (intel_crtc_needs_modeset(new_crtc_state)) {
5994 drm_dbg_kms(&i915->drm,
5995 "[CRTC:%d:%s] modeset required\n",
5996 crtc->base.base.id, crtc->base.name);
6000 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6001 drm_dbg_kms(&i915->drm,
6002 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6003 crtc->base.base.id, crtc->base.name);
6007 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6008 new_plane_state, i) {
6009 if (plane->pipe != crtc->pipe)
6013 * Only async flip capable planes should be in the state
6014 * if we're really about to ask the hardware to perform
6015 * an async flip. We should never get this far otherwise.
6017 if (drm_WARN_ON(&i915->drm,
6018 new_crtc_state->do_async_flip && !plane->async_flip))
6022 * Only check async flip capable planes other planes
6023 * may be involved in the initial commit due to
6024 * the wm0/ddb optimization.
6026 * TODO maybe should track which planes actually
6027 * were requested to do the async flip...
6029 if (!plane->async_flip)
6033 * FIXME: This check is kept generic for all platforms.
6034 * Need to verify this for all gen9 platforms to enable
6035 * this selectively if required.
6037 switch (new_plane_state->hw.fb->modifier) {
6038 case DRM_FORMAT_MOD_LINEAR:
6040 * FIXME: Async on Linear buffer is supported on ICL as
6041 * but with additional alignment and fbc restrictions
6042 * need to be taken care of. These aren't applicable for
6045 if (DISPLAY_VER(i915) < 12) {
6046 drm_dbg_kms(&i915->drm,
6047 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip on display ver %d\n",
6048 plane->base.base.id, plane->base.name,
6049 new_plane_state->hw.fb->modifier, DISPLAY_VER(i915));
6054 case I915_FORMAT_MOD_X_TILED:
6055 case I915_FORMAT_MOD_Y_TILED:
6056 case I915_FORMAT_MOD_Yf_TILED:
6057 case I915_FORMAT_MOD_4_TILED:
6060 drm_dbg_kms(&i915->drm,
6061 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip\n",
6062 plane->base.base.id, plane->base.name,
6063 new_plane_state->hw.fb->modifier);
6067 if (new_plane_state->hw.fb->format->num_planes > 1) {
6068 drm_dbg_kms(&i915->drm,
6069 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6070 plane->base.base.id, plane->base.name);
6074 if (old_plane_state->view.color_plane[0].mapping_stride !=
6075 new_plane_state->view.color_plane[0].mapping_stride) {
6076 drm_dbg_kms(&i915->drm,
6077 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6078 plane->base.base.id, plane->base.name);
6082 if (old_plane_state->hw.fb->modifier !=
6083 new_plane_state->hw.fb->modifier) {
6084 drm_dbg_kms(&i915->drm,
6085 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6086 plane->base.base.id, plane->base.name);
6090 if (old_plane_state->hw.fb->format !=
6091 new_plane_state->hw.fb->format) {
6092 drm_dbg_kms(&i915->drm,
6093 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6094 plane->base.base.id, plane->base.name);
6098 if (old_plane_state->hw.rotation !=
6099 new_plane_state->hw.rotation) {
6100 drm_dbg_kms(&i915->drm,
6101 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6102 plane->base.base.id, plane->base.name);
6106 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6107 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6108 drm_dbg_kms(&i915->drm,
6109 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6110 plane->base.base.id, plane->base.name);
6114 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6115 drm_dbg_kms(&i915->drm,
6116 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6117 plane->base.base.id, plane->base.name);
6121 if (old_plane_state->hw.pixel_blend_mode !=
6122 new_plane_state->hw.pixel_blend_mode) {
6123 drm_dbg_kms(&i915->drm,
6124 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6125 plane->base.base.id, plane->base.name);
6129 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6130 drm_dbg_kms(&i915->drm,
6131 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6132 plane->base.base.id, plane->base.name);
6136 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6137 drm_dbg_kms(&i915->drm,
6138 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6139 plane->base.base.id, plane->base.name);
6143 /* plane decryption is allow to change only in synchronous flips */
6144 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6145 drm_dbg_kms(&i915->drm,
6146 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6147 plane->base.base.id, plane->base.name);
6155 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6157 struct drm_i915_private *i915 = to_i915(state->base.dev);
6158 struct intel_crtc_state *crtc_state;
6159 struct intel_crtc *crtc;
6160 u8 affected_pipes = 0;
6161 u8 modeset_pipes = 0;
6164 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6165 affected_pipes |= crtc_state->bigjoiner_pipes;
6166 if (intel_crtc_needs_modeset(crtc_state))
6167 modeset_pipes |= crtc_state->bigjoiner_pipes;
6170 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6171 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6172 if (IS_ERR(crtc_state))
6173 return PTR_ERR(crtc_state);
6176 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6179 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6181 crtc_state->uapi.mode_changed = true;
6183 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6187 ret = intel_atomic_add_affected_planes(state, crtc);
6192 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6193 /* Kill old bigjoiner link, we may re-establish afterwards */
6194 if (intel_crtc_needs_modeset(crtc_state) &&
6195 intel_crtc_is_bigjoiner_master(crtc_state))
6196 kill_bigjoiner_slave(state, crtc);
6202 static int intel_atomic_check_config(struct intel_atomic_state *state,
6203 struct intel_link_bw_limits *limits,
6204 enum pipe *failed_pipe)
6206 struct drm_i915_private *i915 = to_i915(state->base.dev);
6207 struct intel_crtc_state *new_crtc_state;
6208 struct intel_crtc *crtc;
6212 *failed_pipe = INVALID_PIPE;
6214 ret = intel_bigjoiner_add_affected_crtcs(state);
6218 ret = intel_fdi_add_affected_crtcs(state);
6222 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6223 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6224 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6225 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6227 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6231 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6232 drm_WARN_ON(&i915->drm, new_crtc_state->uapi.enable);
6236 ret = intel_crtc_prepare_cleared_state(state, crtc);
6240 if (!new_crtc_state->hw.enable)
6243 ret = intel_modeset_pipe_config(state, crtc, limits);
6247 ret = intel_atomic_check_bigjoiner(state, crtc);
6253 *failed_pipe = crtc->pipe;
6258 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state)
6260 struct intel_link_bw_limits new_limits;
6261 struct intel_link_bw_limits old_limits;
6264 intel_link_bw_init_limits(state, &new_limits);
6265 old_limits = new_limits;
6268 enum pipe failed_pipe;
6270 ret = intel_atomic_check_config(state, &new_limits,
6274 * The bpp limit for a pipe is below the minimum it supports, set the
6275 * limit to the minimum and recalculate the config.
6277 if (ret == -EINVAL &&
6278 intel_link_bw_set_bpp_limit_for_pipe(state,
6287 old_limits = new_limits;
6289 ret = intel_link_bw_atomic_check(state, &new_limits);
6297 * intel_atomic_check - validate state object
6299 * @_state: state to validate
6301 int intel_atomic_check(struct drm_device *dev,
6302 struct drm_atomic_state *_state)
6304 struct drm_i915_private *dev_priv = to_i915(dev);
6305 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6306 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6307 struct intel_crtc *crtc;
6309 bool any_ms = false;
6311 if (!intel_display_driver_check_access(dev_priv))
6314 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6315 new_crtc_state, i) {
6317 * crtc's state no longer considered to be inherited
6318 * after the first userspace/client initiated commit.
6320 if (!state->internal)
6321 new_crtc_state->inherited = false;
6323 if (new_crtc_state->inherited != old_crtc_state->inherited)
6324 new_crtc_state->uapi.mode_changed = true;
6326 if (new_crtc_state->uapi.scaling_filter !=
6327 old_crtc_state->uapi.scaling_filter)
6328 new_crtc_state->uapi.mode_changed = true;
6331 intel_vrr_check_modeset(state);
6333 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6337 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6338 ret = intel_async_flip_check_uapi(state, crtc);
6343 ret = intel_atomic_check_config_and_link(state);
6347 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6348 new_crtc_state, i) {
6349 if (!intel_crtc_needs_modeset(new_crtc_state))
6352 if (new_crtc_state->hw.enable) {
6353 ret = intel_modeset_pipe_config_late(state, crtc);
6358 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6362 * Check if fastset is allowed by external dependencies like other
6363 * pipes and transcoders.
6365 * Right now it only forces a fullmodeset when the MST master
6366 * transcoder did not changed but the pipe of the master transcoder
6367 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6368 * in case of port synced crtcs, if one of the synced crtcs
6369 * needs a full modeset, all other synced crtcs should be
6370 * forced a full modeset.
6372 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6373 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6376 if (intel_dp_mst_crtc_needs_modeset(state, crtc))
6377 intel_crtc_flag_modeset(new_crtc_state);
6379 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6380 enum transcoder master = new_crtc_state->mst_master_transcoder;
6382 if (intel_cpu_transcoders_need_modeset(state, BIT(master)))
6383 intel_crtc_flag_modeset(new_crtc_state);
6386 if (is_trans_port_sync_mode(new_crtc_state)) {
6387 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6389 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6390 trans |= BIT(new_crtc_state->master_transcoder);
6392 if (intel_cpu_transcoders_need_modeset(state, trans))
6393 intel_crtc_flag_modeset(new_crtc_state);
6396 if (new_crtc_state->bigjoiner_pipes) {
6397 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes))
6398 intel_crtc_flag_modeset(new_crtc_state);
6402 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6403 new_crtc_state, i) {
6404 if (!intel_crtc_needs_modeset(new_crtc_state))
6409 intel_release_shared_dplls(state, crtc);
6412 if (any_ms && !check_digital_port_conflicts(state)) {
6413 drm_dbg_kms(&dev_priv->drm,
6414 "rejecting conflicting digital port configuration\n");
6419 ret = intel_atomic_check_planes(state);
6423 ret = intel_compute_global_watermarks(state);
6427 ret = intel_bw_atomic_check(state);
6431 ret = intel_cdclk_atomic_check(state, &any_ms);
6435 if (intel_any_crtc_needs_modeset(state))
6439 ret = intel_modeset_checks(state);
6443 ret = intel_modeset_calc_cdclk(state);
6448 ret = intel_pmdemand_atomic_check(state);
6452 ret = intel_atomic_check_crtcs(state);
6456 ret = intel_fbc_atomic_check(state);
6460 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6461 new_crtc_state, i) {
6462 intel_color_assert_luts(new_crtc_state);
6464 ret = intel_async_flip_check_hw(state, crtc);
6468 /* Either full modeset or fastset (or neither), never both */
6469 drm_WARN_ON(&dev_priv->drm,
6470 intel_crtc_needs_modeset(new_crtc_state) &&
6471 intel_crtc_needs_fastset(new_crtc_state));
6473 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6474 !intel_crtc_needs_fastset(new_crtc_state))
6477 intel_crtc_state_dump(new_crtc_state, state,
6478 intel_crtc_needs_modeset(new_crtc_state) ?
6479 "modeset" : "fastset");
6485 if (ret == -EDEADLK)
6489 * FIXME would probably be nice to know which crtc specifically
6490 * caused the failure, in cases where we can pinpoint it.
6492 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6494 intel_crtc_state_dump(new_crtc_state, state, "failed");
6499 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6501 struct intel_crtc_state *crtc_state;
6502 struct intel_crtc *crtc;
6505 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6509 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6510 if (intel_crtc_needs_color_update(crtc_state))
6511 intel_color_prepare_commit(crtc_state);
6517 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
6518 struct intel_crtc_state *crtc_state)
6520 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6522 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
6523 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
6525 if (crtc_state->has_pch_encoder) {
6526 enum pipe pch_transcoder =
6527 intel_crtc_pch_transcoder(crtc);
6529 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
6533 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
6534 const struct intel_crtc_state *new_crtc_state)
6536 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6537 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6540 * Update pipe size and adjust fitter if needed: the reason for this is
6541 * that in compute_mode_changes we check the native mode (not the pfit
6542 * mode) to see if we can flip rather than do a full mode set. In the
6543 * fastboot case, we'll flip, but if we don't update the pipesrc and
6544 * pfit state, we'll end up with a big fb scanned out into the wrong
6547 intel_set_pipe_src_size(new_crtc_state);
6549 /* on skylake this is done by detaching scalers */
6550 if (DISPLAY_VER(dev_priv) >= 9) {
6551 if (new_crtc_state->pch_pfit.enabled)
6552 skl_pfit_enable(new_crtc_state);
6553 } else if (HAS_PCH_SPLIT(dev_priv)) {
6554 if (new_crtc_state->pch_pfit.enabled)
6555 ilk_pfit_enable(new_crtc_state);
6556 else if (old_crtc_state->pch_pfit.enabled)
6557 ilk_pfit_disable(old_crtc_state);
6561 * The register is supposedly single buffered so perhaps
6562 * not 100% correct to do this here. But SKL+ calculate
6563 * this based on the adjust pixel rate so pfit changes do
6564 * affect it and so it must be updated for fastsets.
6565 * HSW/BDW only really need this here for fastboot, after
6566 * that the value should not change without a full modeset.
6568 if (DISPLAY_VER(dev_priv) >= 9 ||
6569 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
6570 hsw_set_linetime_wm(new_crtc_state);
6572 if (new_crtc_state->update_m_n)
6573 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
6574 &new_crtc_state->dp_m_n);
6576 if (new_crtc_state->update_lrr)
6577 intel_set_transcoder_timings_lrr(new_crtc_state);
6580 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
6581 struct intel_crtc *crtc)
6583 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6584 const struct intel_crtc_state *old_crtc_state =
6585 intel_atomic_get_old_crtc_state(state, crtc);
6586 const struct intel_crtc_state *new_crtc_state =
6587 intel_atomic_get_new_crtc_state(state, crtc);
6588 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6591 * During modesets pipe configuration was programmed as the
6595 if (intel_crtc_needs_color_update(new_crtc_state))
6596 intel_color_commit_arm(new_crtc_state);
6598 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6599 bdw_set_pipe_misc(new_crtc_state);
6601 if (intel_crtc_needs_fastset(new_crtc_state))
6602 intel_pipe_fastset(old_crtc_state, new_crtc_state);
6605 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
6607 intel_atomic_update_watermarks(state, crtc);
6610 static void commit_pipe_post_planes(struct intel_atomic_state *state,
6611 struct intel_crtc *crtc)
6613 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6614 const struct intel_crtc_state *old_crtc_state =
6615 intel_atomic_get_old_crtc_state(state, crtc);
6616 const struct intel_crtc_state *new_crtc_state =
6617 intel_atomic_get_new_crtc_state(state, crtc);
6620 * Disable the scaler(s) after the plane(s) so that we don't
6621 * get a catastrophic underrun even if the two operations
6622 * end up happening in two different frames.
6624 if (DISPLAY_VER(dev_priv) >= 9 &&
6625 !intel_crtc_needs_modeset(new_crtc_state))
6626 skl_detach_scalers(new_crtc_state);
6628 if (vrr_enabling(old_crtc_state, new_crtc_state))
6629 intel_vrr_enable(new_crtc_state);
6632 static void intel_enable_crtc(struct intel_atomic_state *state,
6633 struct intel_crtc *crtc)
6635 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6636 const struct intel_crtc_state *new_crtc_state =
6637 intel_atomic_get_new_crtc_state(state, crtc);
6639 if (!intel_crtc_needs_modeset(new_crtc_state))
6642 /* VRR will be enable later, if required */
6643 intel_crtc_update_active_timings(new_crtc_state, false);
6645 dev_priv->display.funcs.display->crtc_enable(state, crtc);
6647 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6650 /* vblanks work again, re-enable pipe CRC. */
6651 intel_crtc_enable_pipe_crc(crtc);
6654 static void intel_pre_update_crtc(struct intel_atomic_state *state,
6655 struct intel_crtc *crtc)
6657 struct drm_i915_private *i915 = to_i915(state->base.dev);
6658 const struct intel_crtc_state *old_crtc_state =
6659 intel_atomic_get_old_crtc_state(state, crtc);
6660 struct intel_crtc_state *new_crtc_state =
6661 intel_atomic_get_new_crtc_state(state, crtc);
6662 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6664 if (old_crtc_state->inherited ||
6665 intel_crtc_needs_modeset(new_crtc_state)) {
6667 intel_dpt_configure(crtc);
6671 if (new_crtc_state->preload_luts &&
6672 intel_crtc_needs_color_update(new_crtc_state))
6673 intel_color_load_luts(new_crtc_state);
6675 intel_pre_plane_update(state, crtc);
6677 if (intel_crtc_needs_fastset(new_crtc_state))
6678 intel_encoders_update_pipe(state, crtc);
6680 if (DISPLAY_VER(i915) >= 11 &&
6681 intel_crtc_needs_fastset(new_crtc_state))
6682 icl_set_pipe_chicken(new_crtc_state);
6684 if (vrr_params_changed(old_crtc_state, new_crtc_state))
6685 intel_vrr_set_transcoder_timings(new_crtc_state);
6688 intel_fbc_update(state, crtc);
6690 drm_WARN_ON(&i915->drm, !intel_display_power_is_enabled(i915, POWER_DOMAIN_DC_OFF));
6693 intel_crtc_needs_color_update(new_crtc_state))
6694 intel_color_commit_noarm(new_crtc_state);
6696 intel_crtc_planes_update_noarm(state, crtc);
6699 static void intel_update_crtc(struct intel_atomic_state *state,
6700 struct intel_crtc *crtc)
6702 const struct intel_crtc_state *old_crtc_state =
6703 intel_atomic_get_old_crtc_state(state, crtc);
6704 struct intel_crtc_state *new_crtc_state =
6705 intel_atomic_get_new_crtc_state(state, crtc);
6707 /* Perform vblank evasion around commit operation */
6708 intel_pipe_update_start(state, crtc);
6710 commit_pipe_pre_planes(state, crtc);
6712 intel_crtc_planes_update_arm(state, crtc);
6714 commit_pipe_post_planes(state, crtc);
6716 intel_pipe_update_end(state, crtc);
6719 * VRR/Seamless M/N update may need to update frame timings.
6721 * FIXME Should be synchronized with the start of vblank somehow...
6723 if (vrr_enabling(old_crtc_state, new_crtc_state) ||
6724 new_crtc_state->update_m_n || new_crtc_state->update_lrr)
6725 intel_crtc_update_active_timings(new_crtc_state,
6726 new_crtc_state->vrr.enable);
6729 * We usually enable FIFO underrun interrupts as part of the
6730 * CRTC enable sequence during modesets. But when we inherit a
6731 * valid pipe configuration from the BIOS we need to take care
6732 * of enabling them on the CRTC's first fastset.
6734 if (intel_crtc_needs_fastset(new_crtc_state) &&
6735 old_crtc_state->inherited)
6736 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
6739 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
6740 struct intel_crtc_state *old_crtc_state,
6741 struct intel_crtc_state *new_crtc_state,
6742 struct intel_crtc *crtc)
6744 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6747 * We need to disable pipe CRC before disabling the pipe,
6748 * or we race against vblank off.
6750 intel_crtc_disable_pipe_crc(crtc);
6752 dev_priv->display.funcs.display->crtc_disable(state, crtc);
6753 crtc->active = false;
6754 intel_fbc_disable(crtc);
6756 if (!new_crtc_state->hw.active)
6757 intel_initial_watermarks(state, crtc);
6760 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
6762 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6763 struct intel_crtc *crtc;
6767 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6768 new_crtc_state, i) {
6769 if (!intel_crtc_needs_modeset(new_crtc_state))
6772 intel_pre_plane_update(state, crtc);
6774 if (!old_crtc_state->hw.active)
6777 intel_crtc_disable_planes(state, crtc);
6780 /* Only disable port sync and MST slaves */
6781 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6782 new_crtc_state, i) {
6783 if (!intel_crtc_needs_modeset(new_crtc_state))
6786 if (!old_crtc_state->hw.active)
6789 /* In case of Transcoder port Sync master slave CRTCs can be
6790 * assigned in any order and we need to make sure that
6791 * slave CRTCs are disabled first and then master CRTC since
6792 * Slave vblanks are masked till Master Vblanks.
6794 if (!is_trans_port_sync_slave(old_crtc_state) &&
6795 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
6796 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
6799 intel_old_crtc_state_disables(state, old_crtc_state,
6800 new_crtc_state, crtc);
6801 handled |= BIT(crtc->pipe);
6804 /* Disable everything else left on */
6805 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6806 new_crtc_state, i) {
6807 if (!intel_crtc_needs_modeset(new_crtc_state) ||
6808 (handled & BIT(crtc->pipe)))
6811 if (!old_crtc_state->hw.active)
6814 intel_old_crtc_state_disables(state, old_crtc_state,
6815 new_crtc_state, crtc);
6819 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
6821 struct intel_crtc_state *new_crtc_state;
6822 struct intel_crtc *crtc;
6825 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6826 if (!new_crtc_state->hw.active)
6829 intel_enable_crtc(state, crtc);
6830 intel_pre_update_crtc(state, crtc);
6833 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6834 if (!new_crtc_state->hw.active)
6837 intel_update_crtc(state, crtc);
6841 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
6843 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6844 struct intel_crtc *crtc;
6845 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6846 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6847 u8 update_pipes = 0, modeset_pipes = 0;
6850 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
6851 enum pipe pipe = crtc->pipe;
6853 if (!new_crtc_state->hw.active)
6856 /* ignore allocations for crtc's that have been turned off. */
6857 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6858 entries[pipe] = old_crtc_state->wm.skl.ddb;
6859 update_pipes |= BIT(pipe);
6861 modeset_pipes |= BIT(pipe);
6866 * Whenever the number of active pipes changes, we need to make sure we
6867 * update the pipes in the right order so that their ddb allocations
6868 * never overlap with each other between CRTC updates. Otherwise we'll
6869 * cause pipe underruns and other bad stuff.
6871 * So first lets enable all pipes that do not need a fullmodeset as
6872 * those don't have any external dependency.
6874 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6875 enum pipe pipe = crtc->pipe;
6877 if ((update_pipes & BIT(pipe)) == 0)
6880 intel_pre_update_crtc(state, crtc);
6883 while (update_pipes) {
6884 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6885 new_crtc_state, i) {
6886 enum pipe pipe = crtc->pipe;
6888 if ((update_pipes & BIT(pipe)) == 0)
6891 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6892 entries, I915_MAX_PIPES, pipe))
6895 entries[pipe] = new_crtc_state->wm.skl.ddb;
6896 update_pipes &= ~BIT(pipe);
6898 intel_update_crtc(state, crtc);
6901 * If this is an already active pipe, it's DDB changed,
6902 * and this isn't the last pipe that needs updating
6903 * then we need to wait for a vblank to pass for the
6904 * new ddb allocation to take effect.
6906 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
6907 &old_crtc_state->wm.skl.ddb) &&
6908 (update_pipes | modeset_pipes))
6909 intel_crtc_wait_for_next_vblank(crtc);
6913 update_pipes = modeset_pipes;
6916 * Enable all pipes that needs a modeset and do not depends on other
6919 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6920 enum pipe pipe = crtc->pipe;
6922 if ((modeset_pipes & BIT(pipe)) == 0)
6925 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
6926 is_trans_port_sync_master(new_crtc_state) ||
6927 intel_crtc_is_bigjoiner_master(new_crtc_state))
6930 modeset_pipes &= ~BIT(pipe);
6932 intel_enable_crtc(state, crtc);
6936 * Then we enable all remaining pipes that depend on other
6937 * pipes: MST slaves and port sync masters, big joiner master
6939 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6940 enum pipe pipe = crtc->pipe;
6942 if ((modeset_pipes & BIT(pipe)) == 0)
6945 modeset_pipes &= ~BIT(pipe);
6947 intel_enable_crtc(state, crtc);
6951 * Finally we do the plane updates/etc. for all pipes that got enabled.
6953 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6954 enum pipe pipe = crtc->pipe;
6956 if ((update_pipes & BIT(pipe)) == 0)
6959 intel_pre_update_crtc(state, crtc);
6962 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6963 enum pipe pipe = crtc->pipe;
6965 if ((update_pipes & BIT(pipe)) == 0)
6968 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6969 entries, I915_MAX_PIPES, pipe));
6971 entries[pipe] = new_crtc_state->wm.skl.ddb;
6972 update_pipes &= ~BIT(pipe);
6974 intel_update_crtc(state, crtc);
6977 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
6978 drm_WARN_ON(&dev_priv->drm, update_pipes);
6981 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
6983 struct drm_i915_private *i915 = to_i915(intel_state->base.dev);
6984 struct drm_plane *plane;
6985 struct drm_plane_state *new_plane_state;
6988 for_each_new_plane_in_state(&intel_state->base, plane, new_plane_state, i) {
6989 if (new_plane_state->fence) {
6990 ret = dma_fence_wait_timeout(new_plane_state->fence, false,
6991 i915_fence_timeout(i915));
6995 dma_fence_put(new_plane_state->fence);
6996 new_plane_state->fence = NULL;
7001 static void intel_atomic_cleanup_work(struct work_struct *work)
7003 struct intel_atomic_state *state =
7004 container_of(work, struct intel_atomic_state, base.commit_work);
7005 struct drm_i915_private *i915 = to_i915(state->base.dev);
7006 struct intel_crtc_state *old_crtc_state;
7007 struct intel_crtc *crtc;
7010 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
7011 intel_color_cleanup_commit(old_crtc_state);
7013 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
7014 drm_atomic_helper_commit_cleanup_done(&state->base);
7015 drm_atomic_state_put(&state->base);
7018 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7020 struct drm_i915_private *i915 = to_i915(state->base.dev);
7021 struct intel_plane *plane;
7022 struct intel_plane_state *plane_state;
7025 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7026 struct drm_framebuffer *fb = plane_state->hw.fb;
7033 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7038 * The layout of the fast clear color value expected by HW
7039 * (the DRM ABI requiring this value to be located in fb at
7040 * offset 0 of cc plane, plane #2 previous generations or
7041 * plane #1 for flat ccs):
7042 * - 4 x 4 bytes per-channel value
7043 * (in surface type specific float/int format provided by the fb user)
7044 * - 8 bytes native color value used by the display
7045 * (converted/written by GPU during a fast clear operation using the
7046 * above per-channel values)
7048 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7049 * caller made sure that the object is synced wrt. the related color clear value
7052 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
7053 fb->offsets[cc_plane] + 16,
7054 &plane_state->ccval,
7055 sizeof(plane_state->ccval));
7056 /* The above could only fail if the FB obj has an unexpected backing store type. */
7057 drm_WARN_ON(&i915->drm, ret);
7061 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7063 struct drm_device *dev = state->base.dev;
7064 struct drm_i915_private *dev_priv = to_i915(dev);
7065 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7066 struct intel_crtc *crtc;
7067 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7068 intel_wakeref_t wakeref = 0;
7071 intel_atomic_commit_fence_wait(state);
7073 drm_atomic_helper_wait_for_dependencies(&state->base);
7074 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
7075 intel_atomic_global_state_wait_for_dependencies(state);
7078 * During full modesets we write a lot of registers, wait
7079 * for PLLs, etc. Doing that while DC states are enabled
7080 * is not a good idea.
7082 * During fastsets and other updates we also need to
7083 * disable DC states due to the following scenario:
7084 * 1. DC5 exit and PSR exit happen
7085 * 2. Some or all _noarm() registers are written
7086 * 3. Due to some long delay PSR is re-entered
7087 * 4. DC5 entry -> DMC saves the already written new
7088 * _noarm() registers and the old not yet written
7090 * 5. DC5 exit -> DMC restores a mixture of old and
7091 * new register values and arms the update
7092 * 6. PSR exit -> hardware latches a mixture of old and
7093 * new register values -> corrupted frame, or worse
7094 * 7. New _arm() registers are finally written
7095 * 8. Hardware finally latches a complete set of new
7096 * register values, and subsequent frames will be OK again
7098 * Also note that due to the pipe CSC hardware issues on
7099 * SKL/GLK DC states must remain off until the pipe CSC
7100 * state readout has happened. Otherwise we risk corrupting
7101 * the CSC latched register values with the readout (see
7102 * skl_read_csc() and skl_color_commit_noarm()).
7104 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DC_OFF);
7106 intel_atomic_prepare_plane_clear_colors(state);
7108 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7109 new_crtc_state, i) {
7110 if (intel_crtc_needs_modeset(new_crtc_state) ||
7111 intel_crtc_needs_fastset(new_crtc_state))
7112 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7115 intel_commit_modeset_disables(state);
7117 intel_dp_tunnel_atomic_alloc_bw(state);
7119 /* FIXME: Eventually get rid of our crtc->config pointer */
7120 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7121 crtc->config = new_crtc_state;
7124 * In XE_LPD+ Pmdemand combines many parameters such as voltage index,
7125 * plls, cdclk frequency, QGV point selection parameter etc. Voltage
7126 * index, cdclk/ddiclk frequencies are supposed to be configured before
7127 * the cdclk config is set.
7129 intel_pmdemand_pre_plane_update(state);
7131 if (state->modeset) {
7132 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7134 intel_set_cdclk_pre_plane_update(state);
7136 intel_modeset_verify_disabled(state);
7139 intel_sagv_pre_plane_update(state);
7141 /* Complete the events for pipes that have now been disabled */
7142 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7143 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7145 /* Complete events for now disable pipes here. */
7146 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7147 spin_lock_irq(&dev->event_lock);
7148 drm_crtc_send_vblank_event(&crtc->base,
7149 new_crtc_state->uapi.event);
7150 spin_unlock_irq(&dev->event_lock);
7152 new_crtc_state->uapi.event = NULL;
7156 intel_encoders_update_prepare(state);
7158 intel_dbuf_pre_plane_update(state);
7159 intel_mbus_dbox_update(state);
7161 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7162 if (new_crtc_state->do_async_flip)
7163 intel_crtc_enable_flip_done(state, crtc);
7166 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7167 dev_priv->display.funcs.display->commit_modeset_enables(state);
7170 intel_set_cdclk_post_plane_update(state);
7172 intel_wait_for_vblank_workers(state);
7174 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7175 * already, but still need the state for the delayed optimization. To
7177 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7178 * - schedule that vblank worker _before_ calling hw_done
7179 * - at the start of commit_tail, cancel it _synchrously
7180 * - switch over to the vblank wait helper in the core after that since
7181 * we don't need out special handling any more.
7183 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7185 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7186 if (new_crtc_state->do_async_flip)
7187 intel_crtc_disable_flip_done(state, crtc);
7189 intel_color_wait_commit(new_crtc_state);
7193 * Now that the vblank has passed, we can go ahead and program the
7194 * optimal watermarks on platforms that need two-step watermark
7197 * TODO: Move this (and other cleanup) to an async worker eventually.
7199 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7200 new_crtc_state, i) {
7202 * Gen2 reports pipe underruns whenever all planes are disabled.
7203 * So re-enable underrun reporting after some planes get enabled.
7205 * We do this before .optimize_watermarks() so that we have a
7206 * chance of catching underruns with the intermediate watermarks
7207 * vs. the new plane configuration.
7209 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7210 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7212 intel_optimize_watermarks(state, crtc);
7215 intel_dbuf_post_plane_update(state);
7217 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7218 intel_post_plane_update(state, crtc);
7220 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7222 intel_modeset_verify_crtc(state, crtc);
7224 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
7225 hsw_ips_post_update(state, crtc);
7228 * Activate DRRS after state readout to avoid
7229 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
7231 intel_drrs_activate(new_crtc_state);
7234 * DSB cleanup is done in cleanup_work aligning with framebuffer
7235 * cleanup. So copy and reset the dsb structure to sync with
7236 * commit_done and later do dsb cleanup in cleanup_work.
7238 * FIXME get rid of this funny new->old swapping
7240 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7243 /* Underruns don't always raise interrupts, so check manually */
7244 intel_check_cpu_fifo_underruns(dev_priv);
7245 intel_check_pch_fifo_underruns(dev_priv);
7248 intel_verify_planes(state);
7250 intel_sagv_post_plane_update(state);
7251 intel_pmdemand_post_plane_update(state);
7253 drm_atomic_helper_commit_hw_done(&state->base);
7254 intel_atomic_global_state_commit_done(state);
7256 if (state->modeset) {
7257 /* As one of the primary mmio accessors, KMS has a high
7258 * likelihood of triggering bugs in unclaimed access. After we
7259 * finish modesetting, see if an error has been flagged, and if
7260 * so enable debugging for the next modeset - and hope we catch
7263 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7266 * Delay re-enabling DC states by 17 ms to avoid the off->on->off
7267 * toggling overhead at and above 60 FPS.
7269 intel_display_power_put_async_delay(dev_priv, POWER_DOMAIN_DC_OFF, wakeref, 17);
7270 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7273 * Defer the cleanup of the old state to a separate worker to not
7274 * impede the current task (userspace for blocking modesets) that
7275 * are executed inline. For out-of-line asynchronous modesets/flips,
7276 * deferring to a new worker seems overkill, but we would place a
7277 * schedule point (cond_resched()) here anyway to keep latencies
7280 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7281 queue_work(system_highpri_wq, &state->base.commit_work);
7284 static void intel_atomic_commit_work(struct work_struct *work)
7286 struct intel_atomic_state *state =
7287 container_of(work, struct intel_atomic_state, base.commit_work);
7289 intel_atomic_commit_tail(state);
7292 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7294 struct intel_plane_state *old_plane_state, *new_plane_state;
7295 struct intel_plane *plane;
7298 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7300 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7301 to_intel_frontbuffer(new_plane_state->hw.fb),
7302 plane->frontbuffer_bit);
7305 static int intel_atomic_setup_commit(struct intel_atomic_state *state, bool nonblock)
7309 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7313 ret = intel_atomic_global_state_setup_commit(state);
7320 static int intel_atomic_swap_state(struct intel_atomic_state *state)
7324 ret = drm_atomic_helper_swap_state(&state->base, true);
7328 intel_atomic_swap_global_state(state);
7330 intel_shared_dpll_swap_state(state);
7332 intel_atomic_track_fbs(state);
7337 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7340 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7341 struct drm_i915_private *dev_priv = to_i915(dev);
7344 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7347 * The intel_legacy_cursor_update() fast path takes care
7348 * of avoiding the vblank waits for simple cursor
7349 * movement and flips. For cursor on/off and size changes,
7350 * we want to perform the vblank waits so that watermark
7351 * updates happen during the correct frames. Gen9+ have
7352 * double buffered watermarks and so shouldn't need this.
7354 * Unset state->legacy_cursor_update before the call to
7355 * drm_atomic_helper_setup_commit() because otherwise
7356 * drm_atomic_helper_wait_for_flip_done() is a noop and
7357 * we get FIFO underruns because we didn't wait
7360 * FIXME doing watermarks and fb cleanup from a vblank worker
7361 * (assuming we had any) would solve these problems.
7363 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7364 struct intel_crtc_state *new_crtc_state;
7365 struct intel_crtc *crtc;
7368 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7369 if (new_crtc_state->wm.need_postvbl_update ||
7370 new_crtc_state->update_wm_post)
7371 state->base.legacy_cursor_update = false;
7374 ret = intel_atomic_prepare_commit(state);
7376 drm_dbg_atomic(&dev_priv->drm,
7377 "Preparing state failed with %i\n", ret);
7378 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7382 ret = intel_atomic_setup_commit(state, nonblock);
7384 ret = intel_atomic_swap_state(state);
7387 struct intel_crtc_state *new_crtc_state;
7388 struct intel_crtc *crtc;
7391 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7392 intel_color_cleanup_commit(new_crtc_state);
7394 drm_atomic_helper_unprepare_planes(dev, &state->base);
7395 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7399 drm_atomic_state_get(&state->base);
7400 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7402 if (nonblock && state->modeset) {
7403 queue_work(dev_priv->display.wq.modeset, &state->base.commit_work);
7404 } else if (nonblock) {
7405 queue_work(dev_priv->display.wq.flip, &state->base.commit_work);
7408 flush_workqueue(dev_priv->display.wq.modeset);
7409 intel_atomic_commit_tail(state);
7416 * intel_plane_destroy - destroy a plane
7417 * @plane: plane to destroy
7419 * Common destruction function for all types of planes (primary, cursor,
7422 void intel_plane_destroy(struct drm_plane *plane)
7424 drm_plane_cleanup(plane);
7425 kfree(to_intel_plane(plane));
7428 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7429 struct drm_file *file)
7431 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7432 struct drm_crtc *drmmode_crtc;
7433 struct intel_crtc *crtc;
7435 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7439 crtc = to_intel_crtc(drmmode_crtc);
7440 pipe_from_crtc_id->pipe = crtc->pipe;
7445 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7447 struct drm_device *dev = encoder->base.dev;
7448 struct intel_encoder *source_encoder;
7449 u32 possible_clones = 0;
7451 for_each_intel_encoder(dev, source_encoder) {
7452 if (encoders_cloneable(encoder, source_encoder))
7453 possible_clones |= drm_encoder_mask(&source_encoder->base);
7456 return possible_clones;
7459 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7461 struct drm_device *dev = encoder->base.dev;
7462 struct intel_crtc *crtc;
7463 u32 possible_crtcs = 0;
7465 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7466 possible_crtcs |= drm_crtc_mask(&crtc->base);
7468 return possible_crtcs;
7471 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7473 if (!IS_MOBILE(dev_priv))
7476 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7479 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7485 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7487 if (DISPLAY_VER(dev_priv) >= 9)
7490 if (IS_HASWELL_ULT(dev_priv) || IS_BROADWELL_ULT(dev_priv))
7493 if (HAS_PCH_LPT_H(dev_priv) &&
7494 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7497 /* DDI E can't be used if DDI A requires 4 lanes */
7498 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7501 if (!dev_priv->display.vbt.int_crt_support)
7507 bool assert_port_valid(struct drm_i915_private *i915, enum port port)
7509 return !drm_WARN(&i915->drm, !(DISPLAY_RUNTIME_INFO(i915)->port_mask & BIT(port)),
7510 "Platform does not support port %c\n", port_name(port));
7513 void intel_setup_outputs(struct drm_i915_private *dev_priv)
7515 struct intel_encoder *encoder;
7516 bool dpd_is_edp = false;
7518 intel_pps_unlock_regs_wa(dev_priv);
7520 if (!HAS_DISPLAY(dev_priv))
7523 if (HAS_DDI(dev_priv)) {
7524 if (intel_ddi_crt_present(dev_priv))
7525 intel_crt_init(dev_priv);
7527 intel_bios_for_each_encoder(dev_priv, intel_ddi_init);
7529 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
7530 vlv_dsi_init(dev_priv);
7531 } else if (HAS_PCH_SPLIT(dev_priv)) {
7535 * intel_edp_init_connector() depends on this completing first,
7536 * to prevent the registration of both eDP and LVDS and the
7537 * incorrect sharing of the PPS.
7539 intel_lvds_init(dev_priv);
7540 intel_crt_init(dev_priv);
7542 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
7544 if (ilk_has_edp_a(dev_priv))
7545 g4x_dp_init(dev_priv, DP_A, PORT_A);
7547 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
7548 /* PCH SDVOB multiplex with HDMIB */
7549 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
7551 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
7552 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
7553 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
7556 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
7557 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
7559 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
7560 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
7562 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
7563 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
7565 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
7566 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
7567 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7568 bool has_edp, has_port;
7570 if (IS_VALLEYVIEW(dev_priv) && dev_priv->display.vbt.int_crt_support)
7571 intel_crt_init(dev_priv);
7574 * The DP_DETECTED bit is the latched state of the DDC
7575 * SDA pin at boot. However since eDP doesn't require DDC
7576 * (no way to plug in a DP->HDMI dongle) the DDC pins for
7577 * eDP ports may have been muxed to an alternate function.
7578 * Thus we can't rely on the DP_DETECTED bit alone to detect
7579 * eDP ports. Consult the VBT as well as DP_DETECTED to
7582 * Sadly the straps seem to be missing sometimes even for HDMI
7583 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
7584 * and VBT for the presence of the port. Additionally we can't
7585 * trust the port type the VBT declares as we've seen at least
7586 * HDMI ports that the VBT claim are DP or eDP.
7588 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
7589 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
7590 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
7591 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
7592 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
7593 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
7595 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
7596 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
7597 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
7598 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
7599 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
7600 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
7602 if (IS_CHERRYVIEW(dev_priv)) {
7604 * eDP not supported on port D,
7605 * so no need to worry about it
7607 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
7608 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
7609 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
7610 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
7611 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
7614 vlv_dsi_init(dev_priv);
7615 } else if (IS_PINEVIEW(dev_priv)) {
7616 intel_lvds_init(dev_priv);
7617 intel_crt_init(dev_priv);
7618 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
7621 if (IS_MOBILE(dev_priv))
7622 intel_lvds_init(dev_priv);
7624 intel_crt_init(dev_priv);
7626 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7627 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
7628 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
7629 if (!found && IS_G4X(dev_priv)) {
7630 drm_dbg_kms(&dev_priv->drm,
7631 "probing HDMI on SDVOB\n");
7632 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
7635 if (!found && IS_G4X(dev_priv))
7636 g4x_dp_init(dev_priv, DP_B, PORT_B);
7639 /* Before G4X SDVOC doesn't have its own detect register */
7641 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7642 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
7643 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
7646 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
7648 if (IS_G4X(dev_priv)) {
7649 drm_dbg_kms(&dev_priv->drm,
7650 "probing HDMI on SDVOC\n");
7651 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
7653 if (IS_G4X(dev_priv))
7654 g4x_dp_init(dev_priv, DP_C, PORT_C);
7657 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
7658 g4x_dp_init(dev_priv, DP_D, PORT_D);
7660 if (SUPPORTS_TV(dev_priv))
7661 intel_tv_init(dev_priv);
7662 } else if (DISPLAY_VER(dev_priv) == 2) {
7663 if (IS_I85X(dev_priv))
7664 intel_lvds_init(dev_priv);
7666 intel_crt_init(dev_priv);
7667 intel_dvo_init(dev_priv);
7670 for_each_intel_encoder(&dev_priv->drm, encoder) {
7671 encoder->base.possible_crtcs =
7672 intel_encoder_possible_crtcs(encoder);
7673 encoder->base.possible_clones =
7674 intel_encoder_possible_clones(encoder);
7677 intel_init_pch_refclk(dev_priv);
7679 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
7682 static int max_dotclock(struct drm_i915_private *i915)
7684 int max_dotclock = i915->max_dotclk_freq;
7686 /* icl+ might use bigjoiner */
7687 if (DISPLAY_VER(i915) >= 11)
7690 return max_dotclock;
7693 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
7694 const struct drm_display_mode *mode)
7696 struct drm_i915_private *dev_priv = to_i915(dev);
7697 int hdisplay_max, htotal_max;
7698 int vdisplay_max, vtotal_max;
7701 * Can't reject DBLSCAN here because Xorg ddxen can add piles
7702 * of DBLSCAN modes to the output's mode list when they detect
7703 * the scaling mode property on the connector. And they don't
7704 * ask the kernel to validate those modes in any way until
7705 * modeset time at which point the client gets a protocol error.
7706 * So in order to not upset those clients we silently ignore the
7707 * DBLSCAN flag on such connectors. For other connectors we will
7708 * reject modes with the DBLSCAN flag in encoder->compute_config().
7709 * And we always reject DBLSCAN modes in connector->mode_valid()
7710 * as we never want such modes on the connector's mode list.
7713 if (mode->vscan > 1)
7714 return MODE_NO_VSCAN;
7716 if (mode->flags & DRM_MODE_FLAG_HSKEW)
7717 return MODE_H_ILLEGAL;
7719 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
7720 DRM_MODE_FLAG_NCSYNC |
7721 DRM_MODE_FLAG_PCSYNC))
7724 if (mode->flags & (DRM_MODE_FLAG_BCAST |
7725 DRM_MODE_FLAG_PIXMUX |
7726 DRM_MODE_FLAG_CLKDIV2))
7730 * Reject clearly excessive dotclocks early to
7731 * avoid having to worry about huge integers later.
7733 if (mode->clock > max_dotclock(dev_priv))
7734 return MODE_CLOCK_HIGH;
7736 /* Transcoder timing limits */
7737 if (DISPLAY_VER(dev_priv) >= 11) {
7738 hdisplay_max = 16384;
7739 vdisplay_max = 8192;
7742 } else if (DISPLAY_VER(dev_priv) >= 9 ||
7743 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
7744 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
7745 vdisplay_max = 4096;
7748 } else if (DISPLAY_VER(dev_priv) >= 3) {
7749 hdisplay_max = 4096;
7750 vdisplay_max = 4096;
7754 hdisplay_max = 2048;
7755 vdisplay_max = 2048;
7760 if (mode->hdisplay > hdisplay_max ||
7761 mode->hsync_start > htotal_max ||
7762 mode->hsync_end > htotal_max ||
7763 mode->htotal > htotal_max)
7764 return MODE_H_ILLEGAL;
7766 if (mode->vdisplay > vdisplay_max ||
7767 mode->vsync_start > vtotal_max ||
7768 mode->vsync_end > vtotal_max ||
7769 mode->vtotal > vtotal_max)
7770 return MODE_V_ILLEGAL;
7775 enum drm_mode_status intel_cpu_transcoder_mode_valid(struct drm_i915_private *dev_priv,
7776 const struct drm_display_mode *mode)
7779 * Additional transcoder timing limits,
7780 * excluding BXT/GLK DSI transcoders.
7782 if (DISPLAY_VER(dev_priv) >= 5) {
7783 if (mode->hdisplay < 64 ||
7784 mode->htotal - mode->hdisplay < 32)
7785 return MODE_H_ILLEGAL;
7787 if (mode->vtotal - mode->vdisplay < 5)
7788 return MODE_V_ILLEGAL;
7790 if (mode->htotal - mode->hdisplay < 32)
7791 return MODE_H_ILLEGAL;
7793 if (mode->vtotal - mode->vdisplay < 3)
7794 return MODE_V_ILLEGAL;
7798 * Cantiga+ cannot handle modes with a hsync front porch of 0.
7799 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7801 if ((DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv)) &&
7802 mode->hsync_start == mode->hdisplay)
7803 return MODE_H_ILLEGAL;
7808 enum drm_mode_status
7809 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
7810 const struct drm_display_mode *mode,
7813 int plane_width_max, plane_height_max;
7816 * intel_mode_valid() should be
7817 * sufficient on older platforms.
7819 if (DISPLAY_VER(dev_priv) < 9)
7823 * Most people will probably want a fullscreen
7824 * plane so let's not advertize modes that are
7827 if (DISPLAY_VER(dev_priv) >= 11) {
7828 plane_width_max = 5120 << bigjoiner;
7829 plane_height_max = 4320;
7831 plane_width_max = 5120;
7832 plane_height_max = 4096;
7835 if (mode->hdisplay > plane_width_max)
7836 return MODE_H_ILLEGAL;
7838 if (mode->vdisplay > plane_height_max)
7839 return MODE_V_ILLEGAL;
7844 static const struct intel_display_funcs skl_display_funcs = {
7845 .get_pipe_config = hsw_get_pipe_config,
7846 .crtc_enable = hsw_crtc_enable,
7847 .crtc_disable = hsw_crtc_disable,
7848 .commit_modeset_enables = skl_commit_modeset_enables,
7849 .get_initial_plane_config = skl_get_initial_plane_config,
7850 .fixup_initial_plane_config = skl_fixup_initial_plane_config,
7853 static const struct intel_display_funcs ddi_display_funcs = {
7854 .get_pipe_config = hsw_get_pipe_config,
7855 .crtc_enable = hsw_crtc_enable,
7856 .crtc_disable = hsw_crtc_disable,
7857 .commit_modeset_enables = intel_commit_modeset_enables,
7858 .get_initial_plane_config = i9xx_get_initial_plane_config,
7859 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
7862 static const struct intel_display_funcs pch_split_display_funcs = {
7863 .get_pipe_config = ilk_get_pipe_config,
7864 .crtc_enable = ilk_crtc_enable,
7865 .crtc_disable = ilk_crtc_disable,
7866 .commit_modeset_enables = intel_commit_modeset_enables,
7867 .get_initial_plane_config = i9xx_get_initial_plane_config,
7868 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
7871 static const struct intel_display_funcs vlv_display_funcs = {
7872 .get_pipe_config = i9xx_get_pipe_config,
7873 .crtc_enable = valleyview_crtc_enable,
7874 .crtc_disable = i9xx_crtc_disable,
7875 .commit_modeset_enables = intel_commit_modeset_enables,
7876 .get_initial_plane_config = i9xx_get_initial_plane_config,
7877 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
7880 static const struct intel_display_funcs i9xx_display_funcs = {
7881 .get_pipe_config = i9xx_get_pipe_config,
7882 .crtc_enable = i9xx_crtc_enable,
7883 .crtc_disable = i9xx_crtc_disable,
7884 .commit_modeset_enables = intel_commit_modeset_enables,
7885 .get_initial_plane_config = i9xx_get_initial_plane_config,
7886 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
7890 * intel_init_display_hooks - initialize the display modesetting hooks
7891 * @dev_priv: device private
7893 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
7895 if (DISPLAY_VER(dev_priv) >= 9) {
7896 dev_priv->display.funcs.display = &skl_display_funcs;
7897 } else if (HAS_DDI(dev_priv)) {
7898 dev_priv->display.funcs.display = &ddi_display_funcs;
7899 } else if (HAS_PCH_SPLIT(dev_priv)) {
7900 dev_priv->display.funcs.display = &pch_split_display_funcs;
7901 } else if (IS_CHERRYVIEW(dev_priv) ||
7902 IS_VALLEYVIEW(dev_priv)) {
7903 dev_priv->display.funcs.display = &vlv_display_funcs;
7905 dev_priv->display.funcs.display = &i9xx_display_funcs;
7909 int intel_initial_commit(struct drm_device *dev)
7911 struct drm_atomic_state *state = NULL;
7912 struct drm_modeset_acquire_ctx ctx;
7913 struct intel_crtc *crtc;
7916 state = drm_atomic_state_alloc(dev);
7920 drm_modeset_acquire_init(&ctx, 0);
7922 state->acquire_ctx = &ctx;
7923 to_intel_atomic_state(state)->internal = true;
7926 for_each_intel_crtc(dev, crtc) {
7927 struct intel_crtc_state *crtc_state =
7928 intel_atomic_get_crtc_state(state, crtc);
7930 if (IS_ERR(crtc_state)) {
7931 ret = PTR_ERR(crtc_state);
7935 if (crtc_state->hw.active) {
7936 struct intel_encoder *encoder;
7938 ret = drm_atomic_add_affected_planes(state, &crtc->base);
7943 * FIXME hack to force a LUT update to avoid the
7944 * plane update forcing the pipe gamma on without
7945 * having a proper LUT loaded. Remove once we
7946 * have readout for pipe gamma enable.
7948 crtc_state->uapi.color_mgmt_changed = true;
7950 for_each_intel_encoder_mask(dev, encoder,
7951 crtc_state->uapi.encoder_mask) {
7952 if (encoder->initial_fastset_check &&
7953 !encoder->initial_fastset_check(encoder, crtc_state)) {
7954 ret = drm_atomic_add_affected_connectors(state,
7963 ret = drm_atomic_commit(state);
7966 if (ret == -EDEADLK) {
7967 drm_atomic_state_clear(state);
7968 drm_modeset_backoff(&ctx);
7972 drm_atomic_state_put(state);
7974 drm_modeset_drop_locks(&ctx);
7975 drm_modeset_acquire_fini(&ctx);
7980 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
7982 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
7983 enum transcoder cpu_transcoder = (enum transcoder)pipe;
7984 /* 640x480@60Hz, ~25175 kHz */
7985 struct dpll clock = {
7995 drm_WARN_ON(&dev_priv->drm,
7996 i9xx_calc_dpll_params(48000, &clock) != 25154);
7998 drm_dbg_kms(&dev_priv->drm,
7999 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8000 pipe_name(pipe), clock.vco, clock.dot);
8002 fp = i9xx_dpll_compute_fp(&clock);
8003 dpll = DPLL_DVO_2X_MODE |
8005 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8006 PLL_P2_DIVIDE_BY_4 |
8007 PLL_REF_INPUT_DREFCLK |
8010 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
8011 HACTIVE(640 - 1) | HTOTAL(800 - 1));
8012 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
8013 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
8014 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
8015 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
8016 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
8017 VACTIVE(480 - 1) | VTOTAL(525 - 1));
8018 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
8019 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
8020 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
8021 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
8022 intel_de_write(dev_priv, PIPESRC(pipe),
8023 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
8025 intel_de_write(dev_priv, FP0(pipe), fp);
8026 intel_de_write(dev_priv, FP1(pipe), fp);
8029 * Apparently we need to have VGA mode enabled prior to changing
8030 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8031 * dividers, even though the register value does change.
8033 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
8034 intel_de_write(dev_priv, DPLL(pipe), dpll);
8036 /* Wait for the clocks to stabilize. */
8037 intel_de_posting_read(dev_priv, DPLL(pipe));
8040 /* The pixel multiplier can only be updated once the
8041 * DPLL is enabled and the clocks are stable.
8043 * So write it again.
8045 intel_de_write(dev_priv, DPLL(pipe), dpll);
8047 /* We do this three times for luck */
8048 for (i = 0; i < 3 ; i++) {
8049 intel_de_write(dev_priv, DPLL(pipe), dpll);
8050 intel_de_posting_read(dev_priv, DPLL(pipe));
8051 udelay(150); /* wait for warmup */
8054 intel_de_write(dev_priv, TRANSCONF(pipe), TRANSCONF_ENABLE);
8055 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
8057 intel_wait_for_pipe_scanline_moving(crtc);
8060 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8062 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8064 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
8067 drm_WARN_ON(&dev_priv->drm,
8068 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
8069 drm_WARN_ON(&dev_priv->drm,
8070 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
8071 drm_WARN_ON(&dev_priv->drm,
8072 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
8073 drm_WARN_ON(&dev_priv->drm,
8074 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
8075 drm_WARN_ON(&dev_priv->drm,
8076 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
8078 intel_de_write(dev_priv, TRANSCONF(pipe), 0);
8079 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
8081 intel_wait_for_pipe_scanline_stopped(crtc);
8083 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
8084 intel_de_posting_read(dev_priv, DPLL(pipe));
8087 void intel_hpd_poll_fini(struct drm_i915_private *i915)
8089 struct intel_connector *connector;
8090 struct drm_connector_list_iter conn_iter;
8092 /* Kill all the work that may have been queued by hpd. */
8093 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8094 for_each_intel_connector_iter(connector, &conn_iter) {
8095 if (connector->modeset_retry_work.func &&
8096 cancel_work_sync(&connector->modeset_retry_work))
8097 drm_connector_put(&connector->base);
8098 if (connector->hdcp.shim) {
8099 cancel_delayed_work_sync(&connector->hdcp.check_work);
8100 cancel_work_sync(&connector->hdcp.prop_work);
8103 drm_connector_list_iter_end(&conn_iter);
8106 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
8108 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);