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.
27 #include <linux/dma-resv.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/string_helpers.h>
35 #include <drm/display/drm_dp_helper.h>
36 #include <drm/drm_atomic.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_atomic_uapi.h>
39 #include <drm/drm_damage_helper.h>
40 #include <drm/drm_edid.h>
41 #include <drm/drm_fourcc.h>
42 #include <drm/drm_probe_helper.h>
43 #include <drm/drm_rect.h>
45 #include "gem/i915_gem_lmem.h"
46 #include "gem/i915_gem_object.h"
53 #include "i915_utils.h"
54 #include "i9xx_plane.h"
57 #include "intel_atomic.h"
58 #include "intel_atomic_plane.h"
59 #include "intel_audio.h"
61 #include "intel_cdclk.h"
62 #include "intel_clock_gating.h"
63 #include "intel_color.h"
64 #include "intel_crt.h"
65 #include "intel_crtc.h"
66 #include "intel_crtc_state_dump.h"
67 #include "intel_ddi.h"
69 #include "intel_display_driver.h"
70 #include "intel_display_power.h"
71 #include "intel_display_types.h"
72 #include "intel_dmc.h"
74 #include "intel_dp_link_training.h"
75 #include "intel_dp_mst.h"
76 #include "intel_dpio_phy.h"
77 #include "intel_dpll.h"
78 #include "intel_dpll_mgr.h"
79 #include "intel_dpt.h"
80 #include "intel_drrs.h"
81 #include "intel_dsi.h"
82 #include "intel_dvo.h"
84 #include "intel_fbc.h"
85 #include "intel_fbdev.h"
86 #include "intel_fdi.h"
87 #include "intel_fifo_underrun.h"
88 #include "intel_frontbuffer.h"
89 #include "intel_hdmi.h"
90 #include "intel_hotplug.h"
91 #include "intel_lvds.h"
92 #include "intel_lvds_regs.h"
93 #include "intel_modeset_setup.h"
94 #include "intel_modeset_verify.h"
95 #include "intel_overlay.h"
96 #include "intel_panel.h"
97 #include "intel_pch_display.h"
98 #include "intel_pch_refclk.h"
99 #include "intel_pcode.h"
100 #include "intel_pipe_crc.h"
101 #include "intel_plane_initial.h"
102 #include "intel_pps.h"
103 #include "intel_psr.h"
104 #include "intel_sdvo.h"
105 #include "intel_snps_phy.h"
106 #include "intel_tc.h"
107 #include "intel_tv.h"
108 #include "intel_vblank.h"
109 #include "intel_vdsc.h"
110 #include "intel_vdsc_regs.h"
111 #include "intel_vga.h"
112 #include "intel_vrr.h"
113 #include "intel_wm.h"
114 #include "skl_scaler.h"
115 #include "skl_universal_plane.h"
116 #include "skl_watermark.h"
118 #include "vlv_dsi_pll.h"
119 #include "vlv_dsi_regs.h"
120 #include "vlv_sideband.h"
122 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
123 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
124 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
125 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state);
127 /* returns HPLL frequency in kHz */
128 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
130 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
132 /* Obtain SKU information */
133 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
134 CCK_FUSE_HPLL_FREQ_MASK;
136 return vco_freq[hpll_freq] * 1000;
139 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
140 const char *name, u32 reg, int ref_freq)
145 val = vlv_cck_read(dev_priv, reg);
146 divider = val & CCK_FREQUENCY_VALUES;
148 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
149 (divider << CCK_FREQUENCY_STATUS_SHIFT),
150 "%s change in progress\n", name);
152 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
155 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
156 const char *name, u32 reg)
160 vlv_cck_get(dev_priv);
162 if (dev_priv->hpll_freq == 0)
163 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
165 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
167 vlv_cck_put(dev_priv);
172 void intel_update_czclk(struct drm_i915_private *dev_priv)
174 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
177 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
178 CCK_CZ_CLOCK_CONTROL);
180 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
181 dev_priv->czclk_freq);
184 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
186 return (crtc_state->active_planes &
187 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
190 /* WA Display #0827: Gen9:all */
192 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
195 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
196 0, DUPS1_GATING_DIS | DUPS2_GATING_DIS);
198 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
199 DUPS1_GATING_DIS | DUPS2_GATING_DIS, 0);
202 /* Wa_2006604312:icl,ehl */
204 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
208 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), 0, DPFR_GATING_DIS);
210 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), DPFR_GATING_DIS, 0);
213 /* Wa_1604331009:icl,jsl,ehl */
215 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
218 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), CURSOR_GATING_DIS,
219 enable ? CURSOR_GATING_DIS : 0);
223 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
225 return crtc_state->master_transcoder != INVALID_TRANSCODER;
229 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
231 return crtc_state->sync_mode_slaves_mask != 0;
235 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
237 return is_trans_port_sync_master(crtc_state) ||
238 is_trans_port_sync_slave(crtc_state);
241 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state)
243 return ffs(crtc_state->bigjoiner_pipes) - 1;
246 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state)
248 if (crtc_state->bigjoiner_pipes)
249 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state));
254 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state)
256 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
258 return crtc_state->bigjoiner_pipes &&
259 crtc->pipe != bigjoiner_master_pipe(crtc_state);
262 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state)
264 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
266 return crtc_state->bigjoiner_pipes &&
267 crtc->pipe == bigjoiner_master_pipe(crtc_state);
270 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state)
272 return hweight8(crtc_state->bigjoiner_pipes);
275 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state)
277 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
279 if (intel_crtc_is_bigjoiner_slave(crtc_state))
280 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state));
282 return to_intel_crtc(crtc_state->uapi.crtc);
286 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
288 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
289 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
291 if (DISPLAY_VER(dev_priv) >= 4) {
292 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
294 /* Wait for the Pipe State to go off */
295 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(cpu_transcoder),
296 TRANSCONF_STATE_ENABLE, 100))
297 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
299 intel_wait_for_pipe_scanline_stopped(crtc);
303 void assert_transcoder(struct drm_i915_private *dev_priv,
304 enum transcoder cpu_transcoder, bool state)
307 enum intel_display_power_domain power_domain;
308 intel_wakeref_t wakeref;
310 /* we keep both pipes enabled on 830 */
311 if (IS_I830(dev_priv))
314 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
315 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
317 u32 val = intel_de_read(dev_priv, TRANSCONF(cpu_transcoder));
318 cur_state = !!(val & TRANSCONF_ENABLE);
320 intel_display_power_put(dev_priv, power_domain, wakeref);
325 I915_STATE_WARN(dev_priv, cur_state != state,
326 "transcoder %s assertion failure (expected %s, current %s)\n",
327 transcoder_name(cpu_transcoder), str_on_off(state),
328 str_on_off(cur_state));
331 static void assert_plane(struct intel_plane *plane, bool state)
333 struct drm_i915_private *i915 = to_i915(plane->base.dev);
337 cur_state = plane->get_hw_state(plane, &pipe);
339 I915_STATE_WARN(i915, cur_state != state,
340 "%s assertion failure (expected %s, current %s)\n",
341 plane->base.name, str_on_off(state),
342 str_on_off(cur_state));
345 #define assert_plane_enabled(p) assert_plane(p, true)
346 #define assert_plane_disabled(p) assert_plane(p, false)
348 static void assert_planes_disabled(struct intel_crtc *crtc)
350 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
351 struct intel_plane *plane;
353 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
354 assert_plane_disabled(plane);
357 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
358 struct intel_digital_port *dig_port,
359 unsigned int expected_mask)
364 switch (dig_port->base.port) {
366 MISSING_CASE(dig_port->base.port);
369 port_mask = DPLL_PORTB_READY_MASK;
373 port_mask = DPLL_PORTC_READY_MASK;
378 port_mask = DPLL_PORTD_READY_MASK;
379 dpll_reg = DPIO_PHY_STATUS;
383 if (intel_de_wait_for_register(dev_priv, dpll_reg,
384 port_mask, expected_mask, 1000))
385 drm_WARN(&dev_priv->drm, 1,
386 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
387 dig_port->base.base.base.id, dig_port->base.base.name,
388 intel_de_read(dev_priv, dpll_reg) & port_mask,
392 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
394 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
395 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
396 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
397 enum pipe pipe = crtc->pipe;
401 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
403 assert_planes_disabled(crtc);
406 * A pipe without a PLL won't actually be able to drive bits from
407 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
410 if (HAS_GMCH(dev_priv)) {
411 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
412 assert_dsi_pll_enabled(dev_priv);
414 assert_pll_enabled(dev_priv, pipe);
416 if (new_crtc_state->has_pch_encoder) {
417 /* if driving the PCH, we need FDI enabled */
418 assert_fdi_rx_pll_enabled(dev_priv,
419 intel_crtc_pch_transcoder(crtc));
420 assert_fdi_tx_pll_enabled(dev_priv,
421 (enum pipe) cpu_transcoder);
423 /* FIXME: assert CPU port conditions for SNB+ */
426 /* Wa_22012358565:adl-p */
427 if (DISPLAY_VER(dev_priv) == 13)
428 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
429 0, PIPE_ARB_USE_PROG_SLOTS);
431 reg = TRANSCONF(cpu_transcoder);
432 val = intel_de_read(dev_priv, reg);
433 if (val & TRANSCONF_ENABLE) {
434 /* we keep both pipes enabled on 830 */
435 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
439 intel_de_write(dev_priv, reg, val | TRANSCONF_ENABLE);
440 intel_de_posting_read(dev_priv, reg);
443 * Until the pipe starts PIPEDSL reads will return a stale value,
444 * which causes an apparent vblank timestamp jump when PIPEDSL
445 * resets to its proper value. That also messes up the frame count
446 * when it's derived from the timestamps. So let's wait for the
447 * pipe to start properly before we call drm_crtc_vblank_on()
449 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
450 intel_wait_for_pipe_scanline_moving(crtc);
453 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
455 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
456 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
457 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
458 enum pipe pipe = crtc->pipe;
462 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
465 * Make sure planes won't keep trying to pump pixels to us,
466 * or we might hang the display.
468 assert_planes_disabled(crtc);
470 reg = TRANSCONF(cpu_transcoder);
471 val = intel_de_read(dev_priv, reg);
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 if (DISPLAY_VER(dev_priv) >= 14)
487 intel_de_rmw(dev_priv, MTL_CHICKEN_TRANS(cpu_transcoder),
488 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
489 else if (DISPLAY_VER(dev_priv) >= 12)
490 intel_de_rmw(dev_priv, CHICKEN_TRANS(cpu_transcoder),
491 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
493 intel_de_write(dev_priv, reg, val);
494 if ((val & TRANSCONF_ENABLE) == 0)
495 intel_wait_for_pipe_off(old_crtc_state);
498 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
500 unsigned int size = 0;
503 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
504 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
509 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
511 unsigned int size = 0;
514 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
515 unsigned int plane_size;
517 if (rem_info->plane[i].linear)
518 plane_size = rem_info->plane[i].size;
520 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
525 if (rem_info->plane_alignment)
526 size = ALIGN(size, rem_info->plane_alignment);
534 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
536 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
537 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
539 return DISPLAY_VER(dev_priv) < 4 ||
541 plane_state->view.gtt.type == I915_GTT_VIEW_NORMAL);
545 * Convert the x/y offsets into a linear offset.
546 * Only valid with 0/180 degree rotation, which is fine since linear
547 * offset is only used with linear buffers on pre-hsw and tiled buffers
548 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
550 u32 intel_fb_xy_to_linear(int x, int y,
551 const struct intel_plane_state *state,
554 const struct drm_framebuffer *fb = state->hw.fb;
555 unsigned int cpp = fb->format->cpp[color_plane];
556 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
558 return y * pitch + x * cpp;
562 * Add the x/y offsets derived from fb->offsets[] to the user
563 * specified plane src x/y offsets. The resulting x/y offsets
564 * specify the start of scanout from the beginning of the gtt mapping.
566 void intel_add_fb_offsets(int *x, int *y,
567 const struct intel_plane_state *state,
571 *x += state->view.color_plane[color_plane].x;
572 *y += state->view.color_plane[color_plane].y;
575 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
576 u32 pixel_format, u64 modifier)
578 struct intel_crtc *crtc;
579 struct intel_plane *plane;
581 if (!HAS_DISPLAY(dev_priv))
585 * We assume the primary plane for pipe A has
586 * the highest stride limits of them all,
587 * if in case pipe A is disabled, use the first pipe from pipe_mask.
589 crtc = intel_first_crtc(dev_priv);
593 plane = to_intel_plane(crtc->base.primary);
595 return plane->max_stride(plane, pixel_format, modifier,
599 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
600 struct intel_plane_state *plane_state,
603 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
605 plane_state->uapi.visible = visible;
608 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
610 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
613 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
615 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
616 struct drm_plane *plane;
619 * Active_planes aliases if multiple "primary" or cursor planes
620 * have been used on the same (or wrong) pipe. plane_mask uses
621 * unique ids, hence we can use that to reconstruct active_planes.
623 crtc_state->enabled_planes = 0;
624 crtc_state->active_planes = 0;
626 drm_for_each_plane_mask(plane, &dev_priv->drm,
627 crtc_state->uapi.plane_mask) {
628 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
629 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
633 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
634 struct intel_plane *plane)
636 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
637 struct intel_crtc_state *crtc_state =
638 to_intel_crtc_state(crtc->base.state);
639 struct intel_plane_state *plane_state =
640 to_intel_plane_state(plane->base.state);
642 drm_dbg_kms(&dev_priv->drm,
643 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
644 plane->base.base.id, plane->base.name,
645 crtc->base.base.id, crtc->base.name);
647 intel_set_plane_visible(crtc_state, plane_state, false);
648 intel_plane_fixup_bitmasks(crtc_state);
649 crtc_state->data_rate[plane->id] = 0;
650 crtc_state->data_rate_y[plane->id] = 0;
651 crtc_state->rel_data_rate[plane->id] = 0;
652 crtc_state->rel_data_rate_y[plane->id] = 0;
653 crtc_state->min_cdclk[plane->id] = 0;
655 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
656 hsw_ips_disable(crtc_state)) {
657 crtc_state->ips_enabled = false;
658 intel_crtc_wait_for_next_vblank(crtc);
662 * Vblank time updates from the shadow to live plane control register
663 * are blocked if the memory self-refresh mode is active at that
664 * moment. So to make sure the plane gets truly disabled, disable
665 * first the self-refresh mode. The self-refresh enable bit in turn
666 * will be checked/applied by the HW only at the next frame start
667 * event which is after the vblank start event, so we need to have a
668 * wait-for-vblank between disabling the plane and the pipe.
670 if (HAS_GMCH(dev_priv) &&
671 intel_set_memory_cxsr(dev_priv, false))
672 intel_crtc_wait_for_next_vblank(crtc);
675 * Gen2 reports pipe underruns whenever all planes are disabled.
676 * So disable underrun reporting before all the planes get disabled.
678 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
679 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
681 intel_plane_disable_arm(plane, crtc_state);
682 intel_crtc_wait_for_next_vblank(crtc);
686 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
690 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
691 plane_state->view.color_plane[0].offset, 0);
696 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
698 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
699 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
700 enum pipe pipe = crtc->pipe;
703 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
706 * Display WA #1153: icl
707 * enable hardware to bypass the alpha math
708 * and rounding for per-pixel values 00 and 0xff
710 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
712 * Display WA # 1605353570: icl
713 * Set the pixel rounding bit to 1 for allowing
714 * passthrough of Frame buffer pixels unmodified
717 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
720 * Underrun recovery must always be disabled on display 13+.
721 * DG2 chicken bit meaning is inverted compared to other platforms.
723 if (IS_DG2(dev_priv))
724 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
725 else if (DISPLAY_VER(dev_priv) >= 13)
726 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
728 /* Wa_14010547955:dg2 */
729 if (IS_DG2_DISPLAY_STEP(dev_priv, STEP_B0, STEP_FOREVER))
730 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
732 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
735 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
737 struct drm_crtc *crtc;
740 drm_for_each_crtc(crtc, &dev_priv->drm) {
741 struct drm_crtc_commit *commit;
742 spin_lock(&crtc->commit_lock);
743 commit = list_first_entry_or_null(&crtc->commit_list,
744 struct drm_crtc_commit, commit_entry);
745 cleanup_done = commit ?
746 try_wait_for_completion(&commit->cleanup_done) : true;
747 spin_unlock(&crtc->commit_lock);
752 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
761 * Finds the encoder associated with the given CRTC. This can only be
762 * used when we know that the CRTC isn't feeding multiple encoders!
764 struct intel_encoder *
765 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
766 const struct intel_crtc_state *crtc_state)
768 const struct drm_connector_state *connector_state;
769 const struct drm_connector *connector;
770 struct intel_encoder *encoder = NULL;
771 struct intel_crtc *master_crtc;
772 int num_encoders = 0;
775 master_crtc = intel_master_crtc(crtc_state);
777 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
778 if (connector_state->crtc != &master_crtc->base)
781 encoder = to_intel_encoder(connector_state->best_encoder);
785 drm_WARN(state->base.dev, num_encoders != 1,
786 "%d encoders for pipe %c\n",
787 num_encoders, pipe_name(master_crtc->pipe));
792 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
794 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
795 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
796 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
797 enum pipe pipe = crtc->pipe;
798 int width = drm_rect_width(dst);
799 int height = drm_rect_height(dst);
803 if (!crtc_state->pch_pfit.enabled)
806 /* Force use of hard-coded filter coefficients
807 * as some pre-programmed values are broken,
810 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
811 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
812 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
814 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
816 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe),
817 PF_WIN_XPOS(x) | PF_WIN_YPOS(y));
818 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe),
819 PF_WIN_XSIZE(width) | PF_WIN_YSIZE(height));
822 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
825 (void) intel_overlay_switch_off(crtc->overlay);
827 /* Let userspace switch the overlay on again. In most cases userspace
828 * has to recompute where to put it anyway.
832 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
834 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
836 if (!crtc_state->nv12_planes)
839 /* WA Display #0827: Gen9:all */
840 if (DISPLAY_VER(dev_priv) == 9)
846 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
848 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
850 /* Wa_2006604312:icl,ehl */
851 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
857 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
859 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
861 /* Wa_1604331009:icl,jsl,ehl */
862 if (is_hdr_mode(crtc_state) &&
863 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
864 DISPLAY_VER(dev_priv) == 11)
870 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
871 enum pipe pipe, bool enable)
873 if (DISPLAY_VER(i915) == 9) {
875 * "Plane N strech max must be programmed to 11b (x1)
876 * when Async flips are enabled on that plane."
878 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
879 SKL_PLANE1_STRETCH_MAX_MASK,
880 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
882 /* Also needed on HSW/BDW albeit undocumented */
883 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
884 HSW_PRI_STRETCH_MAX_MASK,
885 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
889 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
891 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
893 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
894 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
897 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
898 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
899 (new_crtc_state)->feature)
900 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
901 ((old_crtc_state)->feature && \
902 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
904 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
905 const struct intel_crtc_state *new_crtc_state)
907 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
910 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
911 const struct intel_crtc_state *new_crtc_state)
913 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
916 static bool vrr_enabling(const struct intel_crtc_state *old_crtc_state,
917 const struct intel_crtc_state *new_crtc_state)
919 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state);
922 static bool vrr_disabling(const struct intel_crtc_state *old_crtc_state,
923 const struct intel_crtc_state *new_crtc_state)
925 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state);
931 static void intel_post_plane_update(struct intel_atomic_state *state,
932 struct intel_crtc *crtc)
934 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
935 const struct intel_crtc_state *old_crtc_state =
936 intel_atomic_get_old_crtc_state(state, crtc);
937 const struct intel_crtc_state *new_crtc_state =
938 intel_atomic_get_new_crtc_state(state, crtc);
939 enum pipe pipe = crtc->pipe;
941 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
943 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
944 intel_update_watermarks(dev_priv);
946 intel_fbc_post_update(state, crtc);
948 if (needs_async_flip_vtd_wa(old_crtc_state) &&
949 !needs_async_flip_vtd_wa(new_crtc_state))
950 intel_async_flip_vtd_wa(dev_priv, pipe, false);
952 if (needs_nv12_wa(old_crtc_state) &&
953 !needs_nv12_wa(new_crtc_state))
954 skl_wa_827(dev_priv, pipe, false);
956 if (needs_scalerclk_wa(old_crtc_state) &&
957 !needs_scalerclk_wa(new_crtc_state))
958 icl_wa_scalerclkgating(dev_priv, pipe, false);
960 if (needs_cursorclk_wa(old_crtc_state) &&
961 !needs_cursorclk_wa(new_crtc_state))
962 icl_wa_cursorclkgating(dev_priv, pipe, false);
964 if (intel_crtc_needs_color_update(new_crtc_state))
965 intel_color_post_update(new_crtc_state);
968 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
969 struct intel_crtc *crtc)
971 const struct intel_crtc_state *crtc_state =
972 intel_atomic_get_new_crtc_state(state, crtc);
973 u8 update_planes = crtc_state->update_planes;
974 const struct intel_plane_state *plane_state;
975 struct intel_plane *plane;
978 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
979 if (plane->pipe == crtc->pipe &&
980 update_planes & BIT(plane->id))
981 plane->enable_flip_done(plane);
985 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
986 struct intel_crtc *crtc)
988 const struct intel_crtc_state *crtc_state =
989 intel_atomic_get_new_crtc_state(state, crtc);
990 u8 update_planes = crtc_state->update_planes;
991 const struct intel_plane_state *plane_state;
992 struct intel_plane *plane;
995 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
996 if (plane->pipe == crtc->pipe &&
997 update_planes & BIT(plane->id))
998 plane->disable_flip_done(plane);
1002 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1003 struct intel_crtc *crtc)
1005 const struct intel_crtc_state *old_crtc_state =
1006 intel_atomic_get_old_crtc_state(state, crtc);
1007 const struct intel_crtc_state *new_crtc_state =
1008 intel_atomic_get_new_crtc_state(state, crtc);
1009 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1010 ~new_crtc_state->async_flip_planes;
1011 const struct intel_plane_state *old_plane_state;
1012 struct intel_plane *plane;
1013 bool need_vbl_wait = false;
1016 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1017 if (plane->need_async_flip_disable_wa &&
1018 plane->pipe == crtc->pipe &&
1019 disable_async_flip_planes & BIT(plane->id)) {
1021 * Apart from the async flip bit we want to
1022 * preserve the old state for the plane.
1024 plane->async_flip(plane, old_crtc_state,
1025 old_plane_state, false);
1026 need_vbl_wait = true;
1031 intel_crtc_wait_for_next_vblank(crtc);
1034 static void intel_pre_plane_update(struct intel_atomic_state *state,
1035 struct intel_crtc *crtc)
1037 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1038 const struct intel_crtc_state *old_crtc_state =
1039 intel_atomic_get_old_crtc_state(state, crtc);
1040 const struct intel_crtc_state *new_crtc_state =
1041 intel_atomic_get_new_crtc_state(state, crtc);
1042 enum pipe pipe = crtc->pipe;
1044 if (vrr_disabling(old_crtc_state, new_crtc_state)) {
1045 intel_vrr_disable(old_crtc_state);
1046 intel_crtc_update_active_timings(old_crtc_state, false);
1049 intel_drrs_deactivate(old_crtc_state);
1051 intel_psr_pre_plane_update(state, crtc);
1053 if (hsw_ips_pre_update(state, crtc))
1054 intel_crtc_wait_for_next_vblank(crtc);
1056 if (intel_fbc_pre_update(state, crtc))
1057 intel_crtc_wait_for_next_vblank(crtc);
1059 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1060 needs_async_flip_vtd_wa(new_crtc_state))
1061 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1063 /* Display WA 827 */
1064 if (!needs_nv12_wa(old_crtc_state) &&
1065 needs_nv12_wa(new_crtc_state))
1066 skl_wa_827(dev_priv, pipe, true);
1068 /* Wa_2006604312:icl,ehl */
1069 if (!needs_scalerclk_wa(old_crtc_state) &&
1070 needs_scalerclk_wa(new_crtc_state))
1071 icl_wa_scalerclkgating(dev_priv, pipe, true);
1073 /* Wa_1604331009:icl,jsl,ehl */
1074 if (!needs_cursorclk_wa(old_crtc_state) &&
1075 needs_cursorclk_wa(new_crtc_state))
1076 icl_wa_cursorclkgating(dev_priv, pipe, true);
1079 * Vblank time updates from the shadow to live plane control register
1080 * are blocked if the memory self-refresh mode is active at that
1081 * moment. So to make sure the plane gets truly disabled, disable
1082 * first the self-refresh mode. The self-refresh enable bit in turn
1083 * will be checked/applied by the HW only at the next frame start
1084 * event which is after the vblank start event, so we need to have a
1085 * wait-for-vblank between disabling the plane and the pipe.
1087 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1088 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1089 intel_crtc_wait_for_next_vblank(crtc);
1092 * IVB workaround: must disable low power watermarks for at least
1093 * one frame before enabling scaling. LP watermarks can be re-enabled
1094 * when scaling is disabled.
1096 * WaCxSRDisabledForSpriteScaling:ivb
1098 if (old_crtc_state->hw.active &&
1099 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
1100 intel_crtc_wait_for_next_vblank(crtc);
1103 * If we're doing a modeset we don't need to do any
1104 * pre-vblank watermark programming here.
1106 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1108 * For platforms that support atomic watermarks, program the
1109 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1110 * will be the intermediate values that are safe for both pre- and
1111 * post- vblank; when vblank happens, the 'active' values will be set
1112 * to the final 'target' values and we'll do this again to get the
1113 * optimal watermarks. For gen9+ platforms, the values we program here
1114 * will be the final target values which will get automatically latched
1115 * at vblank time; no further programming will be necessary.
1117 * If a platform hasn't been transitioned to atomic watermarks yet,
1118 * we'll continue to update watermarks the old way, if flags tell
1121 if (!intel_initial_watermarks(state, crtc))
1122 if (new_crtc_state->update_wm_pre)
1123 intel_update_watermarks(dev_priv);
1127 * Gen2 reports pipe underruns whenever all planes are disabled.
1128 * So disable underrun reporting before all the planes get disabled.
1130 * We do this after .initial_watermarks() so that we have a
1131 * chance of catching underruns with the intermediate watermarks
1132 * vs. the old plane configuration.
1134 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1135 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1138 * WA for platforms where async address update enable bit
1139 * is double buffered and only latched at start of vblank.
1141 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1142 intel_crtc_async_flip_disable_wa(state, crtc);
1145 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1146 struct intel_crtc *crtc)
1148 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1149 const struct intel_crtc_state *new_crtc_state =
1150 intel_atomic_get_new_crtc_state(state, crtc);
1151 unsigned int update_mask = new_crtc_state->update_planes;
1152 const struct intel_plane_state *old_plane_state;
1153 struct intel_plane *plane;
1154 unsigned fb_bits = 0;
1157 intel_crtc_dpms_overlay_disable(crtc);
1159 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1160 if (crtc->pipe != plane->pipe ||
1161 !(update_mask & BIT(plane->id)))
1164 intel_plane_disable_arm(plane, new_crtc_state);
1166 if (old_plane_state->uapi.visible)
1167 fb_bits |= plane->frontbuffer_bit;
1170 intel_frontbuffer_flip(dev_priv, fb_bits);
1173 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1175 struct drm_i915_private *i915 = to_i915(state->base.dev);
1176 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1177 struct intel_crtc *crtc;
1181 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1182 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1184 if (i915->display.dpll.mgr) {
1185 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1186 if (intel_crtc_needs_modeset(new_crtc_state))
1189 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1190 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1195 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1196 struct intel_crtc *crtc)
1198 const struct intel_crtc_state *crtc_state =
1199 intel_atomic_get_new_crtc_state(state, crtc);
1200 const struct drm_connector_state *conn_state;
1201 struct drm_connector *conn;
1204 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1205 struct intel_encoder *encoder =
1206 to_intel_encoder(conn_state->best_encoder);
1208 if (conn_state->crtc != &crtc->base)
1211 if (encoder->pre_pll_enable)
1212 encoder->pre_pll_enable(state, encoder,
1213 crtc_state, conn_state);
1217 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1218 struct intel_crtc *crtc)
1220 const struct intel_crtc_state *crtc_state =
1221 intel_atomic_get_new_crtc_state(state, crtc);
1222 const struct drm_connector_state *conn_state;
1223 struct drm_connector *conn;
1226 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1227 struct intel_encoder *encoder =
1228 to_intel_encoder(conn_state->best_encoder);
1230 if (conn_state->crtc != &crtc->base)
1233 if (encoder->pre_enable)
1234 encoder->pre_enable(state, encoder,
1235 crtc_state, conn_state);
1239 static void intel_encoders_enable(struct intel_atomic_state *state,
1240 struct intel_crtc *crtc)
1242 const struct intel_crtc_state *crtc_state =
1243 intel_atomic_get_new_crtc_state(state, crtc);
1244 const struct drm_connector_state *conn_state;
1245 struct drm_connector *conn;
1248 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1249 struct intel_encoder *encoder =
1250 to_intel_encoder(conn_state->best_encoder);
1252 if (conn_state->crtc != &crtc->base)
1255 if (encoder->enable)
1256 encoder->enable(state, encoder,
1257 crtc_state, conn_state);
1258 intel_opregion_notify_encoder(encoder, true);
1262 static void intel_encoders_disable(struct intel_atomic_state *state,
1263 struct intel_crtc *crtc)
1265 const struct intel_crtc_state *old_crtc_state =
1266 intel_atomic_get_old_crtc_state(state, crtc);
1267 const struct drm_connector_state *old_conn_state;
1268 struct drm_connector *conn;
1271 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1272 struct intel_encoder *encoder =
1273 to_intel_encoder(old_conn_state->best_encoder);
1275 if (old_conn_state->crtc != &crtc->base)
1278 intel_opregion_notify_encoder(encoder, false);
1279 if (encoder->disable)
1280 encoder->disable(state, encoder,
1281 old_crtc_state, old_conn_state);
1285 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1286 struct intel_crtc *crtc)
1288 const struct intel_crtc_state *old_crtc_state =
1289 intel_atomic_get_old_crtc_state(state, crtc);
1290 const struct drm_connector_state *old_conn_state;
1291 struct drm_connector *conn;
1294 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1295 struct intel_encoder *encoder =
1296 to_intel_encoder(old_conn_state->best_encoder);
1298 if (old_conn_state->crtc != &crtc->base)
1301 if (encoder->post_disable)
1302 encoder->post_disable(state, encoder,
1303 old_crtc_state, old_conn_state);
1307 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1308 struct intel_crtc *crtc)
1310 const struct intel_crtc_state *old_crtc_state =
1311 intel_atomic_get_old_crtc_state(state, crtc);
1312 const struct drm_connector_state *old_conn_state;
1313 struct drm_connector *conn;
1316 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1317 struct intel_encoder *encoder =
1318 to_intel_encoder(old_conn_state->best_encoder);
1320 if (old_conn_state->crtc != &crtc->base)
1323 if (encoder->post_pll_disable)
1324 encoder->post_pll_disable(state, encoder,
1325 old_crtc_state, old_conn_state);
1329 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1330 struct intel_crtc *crtc)
1332 const struct intel_crtc_state *crtc_state =
1333 intel_atomic_get_new_crtc_state(state, crtc);
1334 const struct drm_connector_state *conn_state;
1335 struct drm_connector *conn;
1338 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1339 struct intel_encoder *encoder =
1340 to_intel_encoder(conn_state->best_encoder);
1342 if (conn_state->crtc != &crtc->base)
1345 if (encoder->update_pipe)
1346 encoder->update_pipe(state, encoder,
1347 crtc_state, conn_state);
1351 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
1353 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1354 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1356 plane->disable_arm(plane, crtc_state);
1359 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1361 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1362 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1364 if (crtc_state->has_pch_encoder) {
1365 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1366 &crtc_state->fdi_m_n);
1367 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1368 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1369 &crtc_state->dp_m_n);
1370 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1371 &crtc_state->dp_m2_n2);
1374 intel_set_transcoder_timings(crtc_state);
1376 ilk_set_pipeconf(crtc_state);
1379 static void ilk_crtc_enable(struct intel_atomic_state *state,
1380 struct intel_crtc *crtc)
1382 const struct intel_crtc_state *new_crtc_state =
1383 intel_atomic_get_new_crtc_state(state, crtc);
1384 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1385 enum pipe pipe = crtc->pipe;
1387 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1391 * Sometimes spurious CPU pipe underruns happen during FDI
1392 * training, at least with VGA+HDMI cloning. Suppress them.
1394 * On ILK we get an occasional spurious CPU pipe underruns
1395 * between eDP port A enable and vdd enable. Also PCH port
1396 * enable seems to result in the occasional CPU pipe underrun.
1398 * Spurious PCH underruns also occur during PCH enabling.
1400 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1401 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1403 ilk_configure_cpu_transcoder(new_crtc_state);
1405 intel_set_pipe_src_size(new_crtc_state);
1407 crtc->active = true;
1409 intel_encoders_pre_enable(state, crtc);
1411 if (new_crtc_state->has_pch_encoder) {
1412 ilk_pch_pre_enable(state, crtc);
1414 assert_fdi_tx_disabled(dev_priv, pipe);
1415 assert_fdi_rx_disabled(dev_priv, pipe);
1418 ilk_pfit_enable(new_crtc_state);
1421 * On ILK+ LUT must be loaded before the pipe is running but with
1424 intel_color_load_luts(new_crtc_state);
1425 intel_color_commit_noarm(new_crtc_state);
1426 intel_color_commit_arm(new_crtc_state);
1427 /* update DSPCNTR to configure gamma for pipe bottom color */
1428 intel_disable_primary_plane(new_crtc_state);
1430 intel_initial_watermarks(state, crtc);
1431 intel_enable_transcoder(new_crtc_state);
1433 if (new_crtc_state->has_pch_encoder)
1434 ilk_pch_enable(state, crtc);
1436 intel_crtc_vblank_on(new_crtc_state);
1438 intel_encoders_enable(state, crtc);
1440 if (HAS_PCH_CPT(dev_priv))
1441 intel_wait_for_pipe_scanline_moving(crtc);
1444 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1445 * And a second vblank wait is needed at least on ILK with
1446 * some interlaced HDMI modes. Let's do the double wait always
1447 * in case there are more corner cases we don't know about.
1449 if (new_crtc_state->has_pch_encoder) {
1450 intel_crtc_wait_for_next_vblank(crtc);
1451 intel_crtc_wait_for_next_vblank(crtc);
1453 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1454 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1457 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
1458 enum pipe pipe, bool apply)
1460 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
1461 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1468 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
1471 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1473 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1474 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1476 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1477 HSW_LINETIME(crtc_state->linetime) |
1478 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1481 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1483 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1484 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1485 enum transcoder transcoder = crtc_state->cpu_transcoder;
1486 i915_reg_t reg = DISPLAY_VER(dev_priv) >= 14 ? MTL_CHICKEN_TRANS(transcoder) :
1487 CHICKEN_TRANS(transcoder);
1489 intel_de_rmw(dev_priv, reg,
1490 HSW_FRAME_START_DELAY_MASK,
1491 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1494 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
1495 const struct intel_crtc_state *crtc_state)
1497 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state);
1500 * Enable sequence steps 1-7 on bigjoiner master
1502 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1503 intel_encoders_pre_pll_enable(state, master_crtc);
1505 if (crtc_state->shared_dpll)
1506 intel_enable_shared_dpll(crtc_state);
1508 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1509 intel_encoders_pre_enable(state, master_crtc);
1512 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1514 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1515 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1516 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1518 if (crtc_state->has_pch_encoder) {
1519 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1520 &crtc_state->fdi_m_n);
1521 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1522 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1523 &crtc_state->dp_m_n);
1524 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1525 &crtc_state->dp_m2_n2);
1528 intel_set_transcoder_timings(crtc_state);
1529 if (HAS_VRR(dev_priv))
1530 intel_vrr_set_transcoder_timings(crtc_state);
1532 if (cpu_transcoder != TRANSCODER_EDP)
1533 intel_de_write(dev_priv, TRANS_MULT(cpu_transcoder),
1534 crtc_state->pixel_multiplier - 1);
1536 hsw_set_frame_start_delay(crtc_state);
1538 hsw_set_transconf(crtc_state);
1541 static void hsw_crtc_enable(struct intel_atomic_state *state,
1542 struct intel_crtc *crtc)
1544 const struct intel_crtc_state *new_crtc_state =
1545 intel_atomic_get_new_crtc_state(state, crtc);
1546 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1547 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
1548 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1549 bool psl_clkgate_wa;
1551 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1554 intel_dmc_enable_pipe(dev_priv, crtc->pipe);
1556 if (!new_crtc_state->bigjoiner_pipes) {
1557 intel_encoders_pre_pll_enable(state, crtc);
1559 if (new_crtc_state->shared_dpll)
1560 intel_enable_shared_dpll(new_crtc_state);
1562 intel_encoders_pre_enable(state, crtc);
1564 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
1567 intel_dsc_enable(new_crtc_state);
1569 if (DISPLAY_VER(dev_priv) >= 13)
1570 intel_uncompressed_joiner_enable(new_crtc_state);
1572 intel_set_pipe_src_size(new_crtc_state);
1573 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1574 bdw_set_pipe_misc(new_crtc_state);
1576 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) &&
1577 !transcoder_is_dsi(cpu_transcoder))
1578 hsw_configure_cpu_transcoder(new_crtc_state);
1580 crtc->active = true;
1582 /* Display WA #1180: WaDisableScalarClockGating: glk */
1583 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
1584 new_crtc_state->pch_pfit.enabled;
1586 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
1588 if (DISPLAY_VER(dev_priv) >= 9)
1589 skl_pfit_enable(new_crtc_state);
1591 ilk_pfit_enable(new_crtc_state);
1594 * On ILK+ LUT must be loaded before the pipe is running but with
1597 intel_color_load_luts(new_crtc_state);
1598 intel_color_commit_noarm(new_crtc_state);
1599 intel_color_commit_arm(new_crtc_state);
1600 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
1601 if (DISPLAY_VER(dev_priv) < 9)
1602 intel_disable_primary_plane(new_crtc_state);
1604 hsw_set_linetime_wm(new_crtc_state);
1606 if (DISPLAY_VER(dev_priv) >= 11)
1607 icl_set_pipe_chicken(new_crtc_state);
1609 intel_initial_watermarks(state, crtc);
1611 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
1612 intel_crtc_vblank_on(new_crtc_state);
1614 intel_encoders_enable(state, crtc);
1616 if (psl_clkgate_wa) {
1617 intel_crtc_wait_for_next_vblank(crtc);
1618 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
1621 /* If we change the relative order between pipe/planes enabling, we need
1622 * to change the workaround. */
1623 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
1624 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1625 struct intel_crtc *wa_crtc;
1627 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe);
1629 intel_crtc_wait_for_next_vblank(wa_crtc);
1630 intel_crtc_wait_for_next_vblank(wa_crtc);
1634 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1636 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1637 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1638 enum pipe pipe = crtc->pipe;
1640 /* To avoid upsetting the power well on haswell only disable the pfit if
1641 * it's in use. The hw state code will make sure we get this right. */
1642 if (!old_crtc_state->pch_pfit.enabled)
1645 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1646 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
1647 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
1650 static void ilk_crtc_disable(struct intel_atomic_state *state,
1651 struct intel_crtc *crtc)
1653 const struct intel_crtc_state *old_crtc_state =
1654 intel_atomic_get_old_crtc_state(state, crtc);
1655 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1656 enum pipe pipe = crtc->pipe;
1659 * Sometimes spurious CPU pipe underruns happen when the
1660 * pipe is already disabled, but FDI RX/TX is still enabled.
1661 * Happens at least with VGA+HDMI cloning. Suppress them.
1663 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1664 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1666 intel_encoders_disable(state, crtc);
1668 intel_crtc_vblank_off(old_crtc_state);
1670 intel_disable_transcoder(old_crtc_state);
1672 ilk_pfit_disable(old_crtc_state);
1674 if (old_crtc_state->has_pch_encoder)
1675 ilk_pch_disable(state, crtc);
1677 intel_encoders_post_disable(state, crtc);
1679 if (old_crtc_state->has_pch_encoder)
1680 ilk_pch_post_disable(state, crtc);
1682 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1683 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1685 intel_disable_shared_dpll(old_crtc_state);
1688 static void hsw_crtc_disable(struct intel_atomic_state *state,
1689 struct intel_crtc *crtc)
1691 const struct intel_crtc_state *old_crtc_state =
1692 intel_atomic_get_old_crtc_state(state, crtc);
1693 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1696 * FIXME collapse everything to one hook.
1697 * Need care with mst->ddi interactions.
1699 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1700 intel_encoders_disable(state, crtc);
1701 intel_encoders_post_disable(state, crtc);
1704 intel_disable_shared_dpll(old_crtc_state);
1706 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
1707 struct intel_crtc *slave_crtc;
1709 intel_encoders_post_pll_disable(state, crtc);
1711 intel_dmc_disable_pipe(i915, crtc->pipe);
1713 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
1714 intel_crtc_bigjoiner_slave_pipes(old_crtc_state))
1715 intel_dmc_disable_pipe(i915, slave_crtc->pipe);
1719 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
1721 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1722 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1724 if (!crtc_state->gmch_pfit.control)
1728 * The panel fitter should only be adjusted whilst the pipe is disabled,
1729 * according to register description and PRM.
1731 drm_WARN_ON(&dev_priv->drm,
1732 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
1733 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1735 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
1736 crtc_state->gmch_pfit.pgm_ratios);
1737 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
1739 /* Border color in case we don't scale up to the full screen. Black by
1740 * default, change to something else for debugging. */
1741 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
1744 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
1746 if (phy == PHY_NONE)
1748 else if (IS_ALDERLAKE_S(dev_priv))
1749 return phy <= PHY_E;
1750 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
1751 return phy <= PHY_D;
1752 else if (IS_JSL_EHL(dev_priv))
1753 return phy <= PHY_C;
1754 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
1755 return phy <= PHY_B;
1758 * DG2 outputs labelled as "combo PHY" in the bspec use
1759 * SNPS PHYs with completely different programming,
1760 * hence we always return false here.
1765 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
1767 if (IS_DG2(dev_priv))
1768 /* DG2's "TC1" output uses a SNPS PHY */
1770 else if (IS_ALDERLAKE_P(dev_priv) || IS_METEORLAKE(dev_priv))
1771 return phy >= PHY_F && phy <= PHY_I;
1772 else if (IS_TIGERLAKE(dev_priv))
1773 return phy >= PHY_D && phy <= PHY_I;
1774 else if (IS_ICELAKE(dev_priv))
1775 return phy >= PHY_C && phy <= PHY_F;
1780 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
1782 if (phy == PHY_NONE)
1784 else if (IS_DG2(dev_priv))
1786 * All four "combo" ports and the TC1 port (PHY E) use
1789 return phy <= PHY_E;
1794 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
1796 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
1797 return PHY_D + port - PORT_D_XELPD;
1798 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
1799 return PHY_F + port - PORT_TC1;
1800 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
1801 return PHY_B + port - PORT_TC1;
1802 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
1803 return PHY_C + port - PORT_TC1;
1804 else if (IS_JSL_EHL(i915) && port == PORT_D)
1807 return PHY_A + port - PORT_A;
1810 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
1812 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
1813 return TC_PORT_NONE;
1815 if (DISPLAY_VER(dev_priv) >= 12)
1816 return TC_PORT_1 + port - PORT_TC1;
1818 return TC_PORT_1 + port - PORT_C;
1821 enum intel_display_power_domain
1822 intel_aux_power_domain(struct intel_digital_port *dig_port)
1824 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
1826 if (intel_tc_port_in_tbt_alt_mode(dig_port))
1827 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
1829 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
1832 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1833 struct intel_power_domain_mask *mask)
1835 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1836 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1837 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1838 struct drm_encoder *encoder;
1839 enum pipe pipe = crtc->pipe;
1841 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
1843 if (!crtc_state->hw.active)
1846 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
1847 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
1848 if (crtc_state->pch_pfit.enabled ||
1849 crtc_state->pch_pfit.force_thru)
1850 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
1852 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
1853 crtc_state->uapi.encoder_mask) {
1854 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
1856 set_bit(intel_encoder->power_domain, mask->bits);
1859 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
1860 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
1862 if (crtc_state->shared_dpll)
1863 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
1865 if (crtc_state->dsc.compression_enable)
1866 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
1869 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
1870 struct intel_power_domain_mask *old_domains)
1872 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1873 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1874 enum intel_display_power_domain domain;
1875 struct intel_power_domain_mask domains, new_domains;
1877 get_crtc_power_domains(crtc_state, &domains);
1879 bitmap_andnot(new_domains.bits,
1881 crtc->enabled_power_domains.mask.bits,
1883 bitmap_andnot(old_domains->bits,
1884 crtc->enabled_power_domains.mask.bits,
1888 for_each_power_domain(domain, &new_domains)
1889 intel_display_power_get_in_set(dev_priv,
1890 &crtc->enabled_power_domains,
1894 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
1895 struct intel_power_domain_mask *domains)
1897 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
1898 &crtc->enabled_power_domains,
1902 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1904 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1905 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1907 if (intel_crtc_has_dp_encoder(crtc_state)) {
1908 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1909 &crtc_state->dp_m_n);
1910 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1911 &crtc_state->dp_m2_n2);
1914 intel_set_transcoder_timings(crtc_state);
1916 i9xx_set_pipeconf(crtc_state);
1919 static void valleyview_crtc_enable(struct intel_atomic_state *state,
1920 struct intel_crtc *crtc)
1922 const struct intel_crtc_state *new_crtc_state =
1923 intel_atomic_get_new_crtc_state(state, crtc);
1924 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1925 enum pipe pipe = crtc->pipe;
1927 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1930 i9xx_configure_cpu_transcoder(new_crtc_state);
1932 intel_set_pipe_src_size(new_crtc_state);
1934 intel_de_write(dev_priv, VLV_PIPE_MSA_MISC(pipe), 0);
1936 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1937 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
1938 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
1941 crtc->active = true;
1943 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1945 intel_encoders_pre_pll_enable(state, crtc);
1947 if (IS_CHERRYVIEW(dev_priv))
1948 chv_enable_pll(new_crtc_state);
1950 vlv_enable_pll(new_crtc_state);
1952 intel_encoders_pre_enable(state, crtc);
1954 i9xx_pfit_enable(new_crtc_state);
1956 intel_color_load_luts(new_crtc_state);
1957 intel_color_commit_noarm(new_crtc_state);
1958 intel_color_commit_arm(new_crtc_state);
1959 /* update DSPCNTR to configure gamma for pipe bottom color */
1960 intel_disable_primary_plane(new_crtc_state);
1962 intel_initial_watermarks(state, crtc);
1963 intel_enable_transcoder(new_crtc_state);
1965 intel_crtc_vblank_on(new_crtc_state);
1967 intel_encoders_enable(state, crtc);
1970 static void i9xx_crtc_enable(struct intel_atomic_state *state,
1971 struct intel_crtc *crtc)
1973 const struct intel_crtc_state *new_crtc_state =
1974 intel_atomic_get_new_crtc_state(state, crtc);
1975 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1976 enum pipe pipe = crtc->pipe;
1978 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1981 i9xx_configure_cpu_transcoder(new_crtc_state);
1983 intel_set_pipe_src_size(new_crtc_state);
1985 crtc->active = true;
1987 if (DISPLAY_VER(dev_priv) != 2)
1988 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1990 intel_encoders_pre_enable(state, crtc);
1992 i9xx_enable_pll(new_crtc_state);
1994 i9xx_pfit_enable(new_crtc_state);
1996 intel_color_load_luts(new_crtc_state);
1997 intel_color_commit_noarm(new_crtc_state);
1998 intel_color_commit_arm(new_crtc_state);
1999 /* update DSPCNTR to configure gamma for pipe bottom color */
2000 intel_disable_primary_plane(new_crtc_state);
2002 if (!intel_initial_watermarks(state, crtc))
2003 intel_update_watermarks(dev_priv);
2004 intel_enable_transcoder(new_crtc_state);
2006 intel_crtc_vblank_on(new_crtc_state);
2008 intel_encoders_enable(state, crtc);
2010 /* prevents spurious underruns */
2011 if (DISPLAY_VER(dev_priv) == 2)
2012 intel_crtc_wait_for_next_vblank(crtc);
2015 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2017 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2018 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2020 if (!old_crtc_state->gmch_pfit.control)
2023 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2025 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2026 intel_de_read(dev_priv, PFIT_CONTROL));
2027 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2030 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2031 struct intel_crtc *crtc)
2033 struct intel_crtc_state *old_crtc_state =
2034 intel_atomic_get_old_crtc_state(state, crtc);
2035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2036 enum pipe pipe = crtc->pipe;
2039 * On gen2 planes are double buffered but the pipe isn't, so we must
2040 * wait for planes to fully turn off before disabling the pipe.
2042 if (DISPLAY_VER(dev_priv) == 2)
2043 intel_crtc_wait_for_next_vblank(crtc);
2045 intel_encoders_disable(state, crtc);
2047 intel_crtc_vblank_off(old_crtc_state);
2049 intel_disable_transcoder(old_crtc_state);
2051 i9xx_pfit_disable(old_crtc_state);
2053 intel_encoders_post_disable(state, crtc);
2055 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2056 if (IS_CHERRYVIEW(dev_priv))
2057 chv_disable_pll(dev_priv, pipe);
2058 else if (IS_VALLEYVIEW(dev_priv))
2059 vlv_disable_pll(dev_priv, pipe);
2061 i9xx_disable_pll(old_crtc_state);
2064 intel_encoders_post_pll_disable(state, crtc);
2066 if (DISPLAY_VER(dev_priv) != 2)
2067 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2069 if (!dev_priv->display.funcs.wm->initial_watermarks)
2070 intel_update_watermarks(dev_priv);
2072 /* clock the pipe down to 640x480@60 to potentially save power */
2073 if (IS_I830(dev_priv))
2074 i830_enable_pipe(dev_priv, pipe);
2077 void intel_encoder_destroy(struct drm_encoder *encoder)
2079 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2081 drm_encoder_cleanup(encoder);
2082 kfree(intel_encoder);
2085 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2087 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2089 /* GDG double wide on either pipe, otherwise pipe A only */
2090 return DISPLAY_VER(dev_priv) < 4 &&
2091 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2094 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2096 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2097 struct drm_rect src;
2100 * We only use IF-ID interlacing. If we ever use
2101 * PF-ID we'll need to adjust the pixel_rate here.
2104 if (!crtc_state->pch_pfit.enabled)
2107 drm_rect_init(&src, 0, 0,
2108 drm_rect_width(&crtc_state->pipe_src) << 16,
2109 drm_rect_height(&crtc_state->pipe_src) << 16);
2111 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2115 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2116 const struct drm_display_mode *timings)
2118 mode->hdisplay = timings->crtc_hdisplay;
2119 mode->htotal = timings->crtc_htotal;
2120 mode->hsync_start = timings->crtc_hsync_start;
2121 mode->hsync_end = timings->crtc_hsync_end;
2123 mode->vdisplay = timings->crtc_vdisplay;
2124 mode->vtotal = timings->crtc_vtotal;
2125 mode->vsync_start = timings->crtc_vsync_start;
2126 mode->vsync_end = timings->crtc_vsync_end;
2128 mode->flags = timings->flags;
2129 mode->type = DRM_MODE_TYPE_DRIVER;
2131 mode->clock = timings->crtc_clock;
2133 drm_mode_set_name(mode);
2136 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2138 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2140 if (HAS_GMCH(dev_priv))
2141 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2142 crtc_state->pixel_rate =
2143 crtc_state->hw.pipe_mode.crtc_clock;
2145 crtc_state->pixel_rate =
2146 ilk_pipe_pixel_rate(crtc_state);
2149 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2150 struct drm_display_mode *mode)
2152 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2157 mode->crtc_clock /= num_pipes;
2158 mode->crtc_hdisplay /= num_pipes;
2159 mode->crtc_hblank_start /= num_pipes;
2160 mode->crtc_hblank_end /= num_pipes;
2161 mode->crtc_hsync_start /= num_pipes;
2162 mode->crtc_hsync_end /= num_pipes;
2163 mode->crtc_htotal /= num_pipes;
2166 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2167 struct drm_display_mode *mode)
2169 int overlap = crtc_state->splitter.pixel_overlap;
2170 int n = crtc_state->splitter.link_count;
2172 if (!crtc_state->splitter.enable)
2176 * eDP MSO uses segment timings from EDID for transcoder
2177 * timings, but full mode for everything else.
2179 * h_full = (h_segment - pixel_overlap) * link_count
2181 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2182 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2183 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2184 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2185 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2186 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2187 mode->crtc_clock *= n;
2190 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2192 struct drm_display_mode *mode = &crtc_state->hw.mode;
2193 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2194 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2197 * Start with the adjusted_mode crtc timings, which
2198 * have been filled with the transcoder timings.
2200 drm_mode_copy(pipe_mode, adjusted_mode);
2202 /* Expand MSO per-segment transcoder timings to full */
2203 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2206 * We want the full numbers in adjusted_mode normal timings,
2207 * adjusted_mode crtc timings are left with the raw transcoder
2210 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2212 /* Populate the "user" mode with full numbers */
2213 drm_mode_copy(mode, pipe_mode);
2214 intel_mode_from_crtc_timings(mode, mode);
2215 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2216 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2217 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2219 /* Derive per-pipe timings in case bigjoiner is used */
2220 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2221 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2223 intel_crtc_compute_pixel_rate(crtc_state);
2226 void intel_encoder_get_config(struct intel_encoder *encoder,
2227 struct intel_crtc_state *crtc_state)
2229 encoder->get_config(encoder, crtc_state);
2231 intel_crtc_readout_derived_state(crtc_state);
2234 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2236 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2242 width = drm_rect_width(&crtc_state->pipe_src);
2243 height = drm_rect_height(&crtc_state->pipe_src);
2245 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2246 width / num_pipes, height);
2249 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2251 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2252 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2254 intel_bigjoiner_compute_pipe_src(crtc_state);
2257 * Pipe horizontal size must be even in:
2259 * - LVDS dual channel mode
2260 * - Double wide pipe
2262 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2263 if (crtc_state->double_wide) {
2264 drm_dbg_kms(&i915->drm,
2265 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2266 crtc->base.base.id, crtc->base.name);
2270 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2271 intel_is_dual_link_lvds(i915)) {
2272 drm_dbg_kms(&i915->drm,
2273 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2274 crtc->base.base.id, crtc->base.name);
2282 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2284 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2285 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2286 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2287 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2288 int clock_limit = i915->max_dotclk_freq;
2291 * Start with the adjusted_mode crtc timings, which
2292 * have been filled with the transcoder timings.
2294 drm_mode_copy(pipe_mode, adjusted_mode);
2296 /* Expand MSO per-segment transcoder timings to full */
2297 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2299 /* Derive per-pipe timings in case bigjoiner is used */
2300 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2301 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2303 if (DISPLAY_VER(i915) < 4) {
2304 clock_limit = i915->display.cdclk.max_cdclk_freq * 9 / 10;
2307 * Enable double wide mode when the dot clock
2308 * is > 90% of the (display) core speed.
2310 if (intel_crtc_supports_double_wide(crtc) &&
2311 pipe_mode->crtc_clock > clock_limit) {
2312 clock_limit = i915->max_dotclk_freq;
2313 crtc_state->double_wide = true;
2317 if (pipe_mode->crtc_clock > clock_limit) {
2318 drm_dbg_kms(&i915->drm,
2319 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2320 crtc->base.base.id, crtc->base.name,
2321 pipe_mode->crtc_clock, clock_limit,
2322 str_yes_no(crtc_state->double_wide));
2329 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2330 struct intel_crtc *crtc)
2332 struct intel_crtc_state *crtc_state =
2333 intel_atomic_get_new_crtc_state(state, crtc);
2336 ret = intel_dpll_crtc_compute_clock(state, crtc);
2340 ret = intel_crtc_compute_pipe_src(crtc_state);
2344 ret = intel_crtc_compute_pipe_mode(crtc_state);
2348 intel_crtc_compute_pixel_rate(crtc_state);
2350 if (crtc_state->has_pch_encoder)
2351 return ilk_fdi_compute_config(crtc, crtc_state);
2357 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2359 while (*num > DATA_LINK_M_N_MASK ||
2360 *den > DATA_LINK_M_N_MASK) {
2366 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2367 u32 m, u32 n, u32 constant_n)
2370 *ret_n = constant_n;
2372 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2374 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2375 intel_reduce_m_n_ratio(ret_m, ret_n);
2379 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
2380 int pixel_clock, int link_clock,
2381 struct intel_link_m_n *m_n,
2384 u32 data_clock = bits_per_pixel * pixel_clock;
2387 data_clock = intel_dp_mode_to_fec_clock(data_clock);
2390 * Windows/BIOS uses fixed M/N values always. Follow suit.
2392 * Also several DP dongles in particular seem to be fussy
2393 * about too large link M/N values. Presumably the 20bit
2394 * value used by Windows/BIOS is acceptable to everyone.
2397 compute_m_n(&m_n->data_m, &m_n->data_n,
2398 data_clock, link_clock * nlanes * 8,
2401 compute_m_n(&m_n->link_m, &m_n->link_n,
2402 pixel_clock, link_clock,
2406 void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2409 * There may be no VBT; and if the BIOS enabled SSC we can
2410 * just keep using it to avoid unnecessary flicker. Whereas if the
2411 * BIOS isn't using it, don't assume it will work even if the VBT
2412 * indicates as much.
2414 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2415 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2419 if (dev_priv->display.vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2420 drm_dbg_kms(&dev_priv->drm,
2421 "SSC %s by BIOS, overriding VBT which says %s\n",
2422 str_enabled_disabled(bios_lvds_use_ssc),
2423 str_enabled_disabled(dev_priv->display.vbt.lvds_use_ssc));
2424 dev_priv->display.vbt.lvds_use_ssc = bios_lvds_use_ssc;
2429 void intel_zero_m_n(struct intel_link_m_n *m_n)
2431 /* corresponds to 0 register value */
2432 memset(m_n, 0, sizeof(*m_n));
2436 void intel_set_m_n(struct drm_i915_private *i915,
2437 const struct intel_link_m_n *m_n,
2438 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2439 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2441 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2442 intel_de_write(i915, data_n_reg, m_n->data_n);
2443 intel_de_write(i915, link_m_reg, m_n->link_m);
2445 * On BDW+ writing LINK_N arms the double buffered update
2446 * of all the M/N registers, so it must be written last.
2448 intel_de_write(i915, link_n_reg, m_n->link_n);
2451 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2452 enum transcoder transcoder)
2454 if (IS_HASWELL(dev_priv))
2455 return transcoder == TRANSCODER_EDP;
2457 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2460 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2461 enum transcoder transcoder,
2462 const struct intel_link_m_n *m_n)
2464 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2465 enum pipe pipe = crtc->pipe;
2467 if (DISPLAY_VER(dev_priv) >= 5)
2468 intel_set_m_n(dev_priv, m_n,
2469 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2470 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2472 intel_set_m_n(dev_priv, m_n,
2473 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2474 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2477 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2478 enum transcoder transcoder,
2479 const struct intel_link_m_n *m_n)
2481 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2483 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2486 intel_set_m_n(dev_priv, m_n,
2487 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2488 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2491 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2493 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2494 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2495 enum pipe pipe = crtc->pipe;
2496 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2497 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2498 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2501 /* We need to be careful not to changed the adjusted mode, for otherwise
2502 * the hw state checker will get angry at the mismatch. */
2503 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2504 crtc_vtotal = adjusted_mode->crtc_vtotal;
2505 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2506 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2508 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2509 /* the chip adds 2 halflines automatically */
2511 crtc_vblank_end -= 1;
2513 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2514 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2516 vsyncshift = adjusted_mode->crtc_hsync_start -
2517 adjusted_mode->crtc_htotal / 2;
2519 vsyncshift += adjusted_mode->crtc_htotal;
2523 * VBLANK_START no longer works on ADL+, instead we must use
2524 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2526 if (DISPLAY_VER(dev_priv) >= 13) {
2527 intel_de_write(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder),
2528 crtc_vblank_start - crtc_vdisplay);
2531 * VBLANK_START not used by hw, just clear it
2532 * to make it stand out in register dumps.
2534 crtc_vblank_start = 1;
2537 if (DISPLAY_VER(dev_priv) > 3)
2538 intel_de_write(dev_priv, TRANS_VSYNCSHIFT(cpu_transcoder),
2541 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
2542 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2543 HTOTAL(adjusted_mode->crtc_htotal - 1));
2544 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
2545 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2546 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2547 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
2548 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2549 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2551 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
2552 VACTIVE(crtc_vdisplay - 1) |
2553 VTOTAL(crtc_vtotal - 1));
2554 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
2555 VBLANK_START(crtc_vblank_start - 1) |
2556 VBLANK_END(crtc_vblank_end - 1));
2557 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
2558 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2559 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2561 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2562 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2563 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2565 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2566 (pipe == PIPE_B || pipe == PIPE_C))
2567 intel_de_write(dev_priv, TRANS_VTOTAL(pipe),
2568 VACTIVE(crtc_vdisplay - 1) |
2569 VTOTAL(crtc_vtotal - 1));
2572 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2574 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2575 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2576 int width = drm_rect_width(&crtc_state->pipe_src);
2577 int height = drm_rect_height(&crtc_state->pipe_src);
2578 enum pipe pipe = crtc->pipe;
2580 /* pipesrc controls the size that is scaled from, which should
2581 * always be the user's requested size.
2583 intel_de_write(dev_priv, PIPESRC(pipe),
2584 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2587 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2589 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2590 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2592 if (DISPLAY_VER(dev_priv) == 2)
2595 if (DISPLAY_VER(dev_priv) >= 9 ||
2596 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2597 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2599 return intel_de_read(dev_priv, TRANSCONF(cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2602 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2603 struct intel_crtc_state *pipe_config)
2605 struct drm_device *dev = crtc->base.dev;
2606 struct drm_i915_private *dev_priv = to_i915(dev);
2607 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2608 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2611 tmp = intel_de_read(dev_priv, TRANS_HTOTAL(cpu_transcoder));
2612 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2613 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2615 if (!transcoder_is_dsi(cpu_transcoder)) {
2616 tmp = intel_de_read(dev_priv, TRANS_HBLANK(cpu_transcoder));
2617 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2618 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2621 tmp = intel_de_read(dev_priv, TRANS_HSYNC(cpu_transcoder));
2622 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2623 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2625 tmp = intel_de_read(dev_priv, TRANS_VTOTAL(cpu_transcoder));
2626 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2627 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2629 /* FIXME TGL+ DSI transcoders have this! */
2630 if (!transcoder_is_dsi(cpu_transcoder)) {
2631 tmp = intel_de_read(dev_priv, TRANS_VBLANK(cpu_transcoder));
2632 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2633 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2635 tmp = intel_de_read(dev_priv, TRANS_VSYNC(cpu_transcoder));
2636 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2637 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2639 if (intel_pipe_is_interlaced(pipe_config)) {
2640 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2641 adjusted_mode->crtc_vtotal += 1;
2642 adjusted_mode->crtc_vblank_end += 1;
2645 if (DISPLAY_VER(dev_priv) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2646 adjusted_mode->crtc_vblank_start =
2647 adjusted_mode->crtc_vdisplay +
2648 intel_de_read(dev_priv, TRANS_SET_CONTEXT_LATENCY(cpu_transcoder));
2651 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2653 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2654 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2655 enum pipe master_pipe, pipe = crtc->pipe;
2661 master_pipe = bigjoiner_master_pipe(crtc_state);
2662 width = drm_rect_width(&crtc_state->pipe_src);
2664 drm_rect_translate_to(&crtc_state->pipe_src,
2665 (pipe - master_pipe) * width, 0);
2668 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2669 struct intel_crtc_state *pipe_config)
2671 struct drm_device *dev = crtc->base.dev;
2672 struct drm_i915_private *dev_priv = to_i915(dev);
2675 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
2677 drm_rect_init(&pipe_config->pipe_src, 0, 0,
2678 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
2679 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
2681 intel_bigjoiner_adjust_pipe_src(pipe_config);
2684 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
2686 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2687 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2688 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2692 * - We keep both pipes enabled on 830
2693 * - During modeset the pipe is still disabled and must remain so
2694 * - During fastset the pipe is already enabled and must remain so
2696 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
2697 val |= TRANSCONF_ENABLE;
2699 if (crtc_state->double_wide)
2700 val |= TRANSCONF_DOUBLE_WIDE;
2702 /* only g4x and later have fancy bpc/dither controls */
2703 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2704 IS_CHERRYVIEW(dev_priv)) {
2705 /* Bspec claims that we can't use dithering for 30bpp pipes. */
2706 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
2707 val |= TRANSCONF_DITHER_EN |
2708 TRANSCONF_DITHER_TYPE_SP;
2710 switch (crtc_state->pipe_bpp) {
2712 /* Case prevented by intel_choose_pipe_bpp_dither. */
2713 MISSING_CASE(crtc_state->pipe_bpp);
2716 val |= TRANSCONF_BPC_6;
2719 val |= TRANSCONF_BPC_8;
2722 val |= TRANSCONF_BPC_10;
2727 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
2728 if (DISPLAY_VER(dev_priv) < 4 ||
2729 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2730 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
2732 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
2734 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
2737 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2738 crtc_state->limited_color_range)
2739 val |= TRANSCONF_COLOR_RANGE_SELECT;
2741 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
2743 if (crtc_state->wgc_enable)
2744 val |= TRANSCONF_WGC_ENABLE;
2746 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
2748 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
2749 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
2752 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
2754 if (IS_I830(dev_priv))
2757 return DISPLAY_VER(dev_priv) >= 4 ||
2758 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
2761 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
2763 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2764 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2768 if (!i9xx_has_pfit(dev_priv))
2771 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
2772 if (!(tmp & PFIT_ENABLE))
2775 /* Check whether the pfit is attached to our pipe. */
2776 if (DISPLAY_VER(dev_priv) >= 4)
2777 pipe = REG_FIELD_GET(PFIT_PIPE_MASK, tmp);
2781 if (pipe != crtc->pipe)
2784 crtc_state->gmch_pfit.control = tmp;
2785 crtc_state->gmch_pfit.pgm_ratios =
2786 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
2789 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
2790 struct intel_crtc_state *pipe_config)
2792 struct drm_device *dev = crtc->base.dev;
2793 struct drm_i915_private *dev_priv = to_i915(dev);
2794 enum pipe pipe = crtc->pipe;
2797 int refclk = 100000;
2799 /* In case of DSI, DPLL will not be used */
2800 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
2803 vlv_dpio_get(dev_priv);
2804 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
2805 vlv_dpio_put(dev_priv);
2807 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
2808 clock.m2 = mdiv & DPIO_M2DIV_MASK;
2809 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
2810 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
2811 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
2813 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
2816 static void chv_crtc_clock_get(struct intel_crtc *crtc,
2817 struct intel_crtc_state *pipe_config)
2819 struct drm_device *dev = crtc->base.dev;
2820 struct drm_i915_private *dev_priv = to_i915(dev);
2821 enum pipe pipe = crtc->pipe;
2822 enum dpio_channel port = vlv_pipe_to_channel(pipe);
2824 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
2825 int refclk = 100000;
2827 /* In case of DSI, DPLL will not be used */
2828 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
2831 vlv_dpio_get(dev_priv);
2832 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
2833 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
2834 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
2835 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
2836 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
2837 vlv_dpio_put(dev_priv);
2839 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
2840 clock.m2 = (pll_dw0 & 0xff) << 22;
2841 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
2842 clock.m2 |= pll_dw2 & 0x3fffff;
2843 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
2844 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
2845 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
2847 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
2850 static enum intel_output_format
2851 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
2853 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2856 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
2858 if (tmp & PIPE_MISC_YUV420_ENABLE) {
2859 /* We support 4:2:0 in full blend mode only */
2860 drm_WARN_ON(&dev_priv->drm,
2861 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
2863 return INTEL_OUTPUT_FORMAT_YCBCR420;
2864 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
2865 return INTEL_OUTPUT_FORMAT_YCBCR444;
2867 return INTEL_OUTPUT_FORMAT_RGB;
2871 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
2873 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2874 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
2875 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2876 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
2879 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
2881 if (tmp & DISP_PIPE_GAMMA_ENABLE)
2882 crtc_state->gamma_enable = true;
2884 if (!HAS_GMCH(dev_priv) &&
2885 tmp & DISP_PIPE_CSC_ENABLE)
2886 crtc_state->csc_enable = true;
2889 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
2890 struct intel_crtc_state *pipe_config)
2892 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2893 enum intel_display_power_domain power_domain;
2894 intel_wakeref_t wakeref;
2898 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
2899 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
2903 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
2904 pipe_config->sink_format = pipe_config->output_format;
2905 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
2906 pipe_config->shared_dpll = NULL;
2910 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
2911 if (!(tmp & TRANSCONF_ENABLE))
2914 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2915 IS_CHERRYVIEW(dev_priv)) {
2916 switch (tmp & TRANSCONF_BPC_MASK) {
2917 case TRANSCONF_BPC_6:
2918 pipe_config->pipe_bpp = 18;
2920 case TRANSCONF_BPC_8:
2921 pipe_config->pipe_bpp = 24;
2923 case TRANSCONF_BPC_10:
2924 pipe_config->pipe_bpp = 30;
2932 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2933 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
2934 pipe_config->limited_color_range = true;
2936 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
2938 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
2940 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2941 (tmp & TRANSCONF_WGC_ENABLE))
2942 pipe_config->wgc_enable = true;
2944 if (IS_CHERRYVIEW(dev_priv))
2945 pipe_config->cgm_mode = intel_de_read(dev_priv,
2946 CGM_PIPE_MODE(crtc->pipe));
2948 i9xx_get_pipe_color_config(pipe_config);
2949 intel_color_get_config(pipe_config);
2951 if (DISPLAY_VER(dev_priv) < 4)
2952 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
2954 intel_get_transcoder_timings(crtc, pipe_config);
2955 intel_get_pipe_src_size(crtc, pipe_config);
2957 i9xx_get_pfit_config(pipe_config);
2959 if (DISPLAY_VER(dev_priv) >= 4) {
2960 /* No way to read it out on pipes B and C */
2961 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
2962 tmp = dev_priv->display.state.chv_dpll_md[crtc->pipe];
2964 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
2965 pipe_config->pixel_multiplier =
2966 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
2967 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
2968 pipe_config->dpll_hw_state.dpll_md = tmp;
2969 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
2970 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
2971 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
2972 pipe_config->pixel_multiplier =
2973 ((tmp & SDVO_MULTIPLIER_MASK)
2974 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
2976 /* Note that on i915G/GM the pixel multiplier is in the sdvo
2977 * port and will be fixed up in the encoder->get_config
2979 pipe_config->pixel_multiplier = 1;
2981 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
2983 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
2984 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
2986 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
2989 /* Mask out read-only status bits. */
2990 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
2991 DPLL_PORTC_READY_MASK |
2992 DPLL_PORTB_READY_MASK);
2995 if (IS_CHERRYVIEW(dev_priv))
2996 chv_crtc_clock_get(crtc, pipe_config);
2997 else if (IS_VALLEYVIEW(dev_priv))
2998 vlv_crtc_clock_get(crtc, pipe_config);
3000 i9xx_crtc_clock_get(crtc, pipe_config);
3003 * Normally the dotclock is filled in by the encoder .get_config()
3004 * but in case the pipe is enabled w/o any ports we need a sane
3007 pipe_config->hw.adjusted_mode.crtc_clock =
3008 pipe_config->port_clock / pipe_config->pixel_multiplier;
3013 intel_display_power_put(dev_priv, power_domain, wakeref);
3018 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3020 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3021 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3022 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3026 * - During modeset the pipe is still disabled and must remain so
3027 * - During fastset the pipe is already enabled and must remain so
3029 if (!intel_crtc_needs_modeset(crtc_state))
3030 val |= TRANSCONF_ENABLE;
3032 switch (crtc_state->pipe_bpp) {
3034 /* Case prevented by intel_choose_pipe_bpp_dither. */
3035 MISSING_CASE(crtc_state->pipe_bpp);
3038 val |= TRANSCONF_BPC_6;
3041 val |= TRANSCONF_BPC_8;
3044 val |= TRANSCONF_BPC_10;
3047 val |= TRANSCONF_BPC_12;
3051 if (crtc_state->dither)
3052 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3054 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3055 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3057 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3060 * This would end up with an odd purple hue over
3061 * the entire display. Make sure we don't do it.
3063 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3064 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3066 if (crtc_state->limited_color_range &&
3067 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3068 val |= TRANSCONF_COLOR_RANGE_SELECT;
3070 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3071 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3073 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3075 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3076 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3078 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3079 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3082 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3084 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3085 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3086 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3090 * - During modeset the pipe is still disabled and must remain so
3091 * - During fastset the pipe is already enabled and must remain so
3093 if (!intel_crtc_needs_modeset(crtc_state))
3094 val |= TRANSCONF_ENABLE;
3096 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3097 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3099 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3100 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3102 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3104 if (IS_HASWELL(dev_priv) &&
3105 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3106 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3108 intel_de_write(dev_priv, TRANSCONF(cpu_transcoder), val);
3109 intel_de_posting_read(dev_priv, TRANSCONF(cpu_transcoder));
3112 static void bdw_set_pipe_misc(const struct intel_crtc_state *crtc_state)
3114 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3115 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3118 switch (crtc_state->pipe_bpp) {
3120 val |= PIPE_MISC_BPC_6;
3123 val |= PIPE_MISC_BPC_8;
3126 val |= PIPE_MISC_BPC_10;
3129 /* Port output 12BPC defined for ADLP+ */
3130 if (DISPLAY_VER(dev_priv) > 12)
3131 val |= PIPE_MISC_BPC_12_ADLP;
3134 MISSING_CASE(crtc_state->pipe_bpp);
3138 if (crtc_state->dither)
3139 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3141 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3142 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3143 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3145 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3146 val |= PIPE_MISC_YUV420_ENABLE |
3147 PIPE_MISC_YUV420_MODE_FULL_BLEND;
3149 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3150 val |= PIPE_MISC_HDR_MODE_PRECISION;
3152 if (DISPLAY_VER(dev_priv) >= 12)
3153 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3155 intel_de_write(dev_priv, PIPE_MISC(crtc->pipe), val);
3158 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3160 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3163 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3165 switch (tmp & PIPE_MISC_BPC_MASK) {
3166 case PIPE_MISC_BPC_6:
3168 case PIPE_MISC_BPC_8:
3170 case PIPE_MISC_BPC_10:
3173 * PORT OUTPUT 12 BPC defined for ADLP+.
3176 * For previous platforms with DSI interface, bits 5:7
3177 * are used for storing pipe_bpp irrespective of dithering.
3178 * Since the value of 12 BPC is not defined for these bits
3179 * on older platforms, need to find a workaround for 12 BPC
3180 * MIPI DSI HW readout.
3182 case PIPE_MISC_BPC_12_ADLP:
3183 if (DISPLAY_VER(dev_priv) > 12)
3192 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3195 * Account for spread spectrum to avoid
3196 * oversubscribing the link. Max center spread
3197 * is 2.5%; use 5% for safety's sake.
3199 u32 bps = target_clock * bpp * 21 / 20;
3200 return DIV_ROUND_UP(bps, link_bw * 8);
3203 void intel_get_m_n(struct drm_i915_private *i915,
3204 struct intel_link_m_n *m_n,
3205 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3206 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3208 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3209 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3210 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3211 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3212 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3215 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3216 enum transcoder transcoder,
3217 struct intel_link_m_n *m_n)
3219 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3220 enum pipe pipe = crtc->pipe;
3222 if (DISPLAY_VER(dev_priv) >= 5)
3223 intel_get_m_n(dev_priv, m_n,
3224 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3225 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3227 intel_get_m_n(dev_priv, m_n,
3228 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3229 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3232 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3233 enum transcoder transcoder,
3234 struct intel_link_m_n *m_n)
3236 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3238 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3241 intel_get_m_n(dev_priv, m_n,
3242 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3243 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3246 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3248 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3249 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3253 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3254 if ((ctl & PF_ENABLE) == 0)
3257 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
3258 pipe = REG_FIELD_GET(PF_PIPE_SEL_MASK_IVB, ctl);
3262 crtc_state->pch_pfit.enabled = true;
3264 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3265 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3267 drm_rect_init(&crtc_state->pch_pfit.dst,
3268 REG_FIELD_GET(PF_WIN_XPOS_MASK, pos),
3269 REG_FIELD_GET(PF_WIN_YPOS_MASK, pos),
3270 REG_FIELD_GET(PF_WIN_XSIZE_MASK, size),
3271 REG_FIELD_GET(PF_WIN_YSIZE_MASK, size));
3274 * We currently do not free assignements of panel fitters on
3275 * ivb/hsw (since we don't use the higher upscaling modes which
3276 * differentiates them) so just WARN about this case for now.
3278 drm_WARN_ON(&dev_priv->drm, pipe != crtc->pipe);
3281 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3282 struct intel_crtc_state *pipe_config)
3284 struct drm_device *dev = crtc->base.dev;
3285 struct drm_i915_private *dev_priv = to_i915(dev);
3286 enum intel_display_power_domain power_domain;
3287 intel_wakeref_t wakeref;
3291 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3292 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3296 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3297 pipe_config->shared_dpll = NULL;
3300 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3301 if (!(tmp & TRANSCONF_ENABLE))
3304 switch (tmp & TRANSCONF_BPC_MASK) {
3305 case TRANSCONF_BPC_6:
3306 pipe_config->pipe_bpp = 18;
3308 case TRANSCONF_BPC_8:
3309 pipe_config->pipe_bpp = 24;
3311 case TRANSCONF_BPC_10:
3312 pipe_config->pipe_bpp = 30;
3314 case TRANSCONF_BPC_12:
3315 pipe_config->pipe_bpp = 36;
3321 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3322 pipe_config->limited_color_range = true;
3324 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3325 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3326 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3327 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3330 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3334 pipe_config->sink_format = pipe_config->output_format;
3336 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3338 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3340 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3342 pipe_config->csc_mode = intel_de_read(dev_priv,
3343 PIPE_CSC_MODE(crtc->pipe));
3345 i9xx_get_pipe_color_config(pipe_config);
3346 intel_color_get_config(pipe_config);
3348 pipe_config->pixel_multiplier = 1;
3350 ilk_pch_get_config(pipe_config);
3352 intel_get_transcoder_timings(crtc, pipe_config);
3353 intel_get_pipe_src_size(crtc, pipe_config);
3355 ilk_get_pfit_config(pipe_config);
3360 intel_display_power_put(dev_priv, power_domain, wakeref);
3365 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3369 if (DISPLAY_VER(i915) >= 12)
3370 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3371 else if (DISPLAY_VER(i915) >= 11)
3372 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3376 return pipes & DISPLAY_RUNTIME_INFO(i915)->pipe_mask;
3379 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3380 enum transcoder cpu_transcoder)
3382 enum intel_display_power_domain power_domain;
3383 intel_wakeref_t wakeref;
3386 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3388 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3389 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3391 return tmp & TRANS_DDI_FUNC_ENABLE;
3394 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3395 u8 *master_pipes, u8 *slave_pipes)
3397 struct intel_crtc *crtc;
3402 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3403 bigjoiner_pipes(dev_priv)) {
3404 enum intel_display_power_domain power_domain;
3405 enum pipe pipe = crtc->pipe;
3406 intel_wakeref_t wakeref;
3408 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3409 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3410 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3412 if (!(tmp & BIG_JOINER_ENABLE))
3415 if (tmp & MASTER_BIG_JOINER_ENABLE)
3416 *master_pipes |= BIT(pipe);
3418 *slave_pipes |= BIT(pipe);
3421 if (DISPLAY_VER(dev_priv) < 13)
3424 power_domain = POWER_DOMAIN_PIPE(pipe);
3425 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3426 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3428 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3429 *master_pipes |= BIT(pipe);
3430 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3431 *slave_pipes |= BIT(pipe);
3435 /* Bigjoiner pipes should always be consecutive master and slave */
3436 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3437 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3438 *master_pipes, *slave_pipes);
3441 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3443 if ((slave_pipes & BIT(pipe)) == 0)
3446 /* ignore everything above our pipe */
3447 master_pipes &= ~GENMASK(7, pipe);
3449 /* highest remaining bit should be our master pipe */
3450 return fls(master_pipes) - 1;
3453 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3455 enum pipe master_pipe, next_master_pipe;
3457 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3459 if ((master_pipes & BIT(master_pipe)) == 0)
3462 /* ignore our master pipe and everything below it */
3463 master_pipes &= ~GENMASK(master_pipe, 0);
3464 /* make sure a high bit is set for the ffs() */
3465 master_pipes |= BIT(7);
3466 /* lowest remaining bit should be the next master pipe */
3467 next_master_pipe = ffs(master_pipes) - 1;
3469 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3472 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3474 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3476 if (DISPLAY_VER(i915) >= 11)
3477 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3479 return panel_transcoder_mask;
3482 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3484 struct drm_device *dev = crtc->base.dev;
3485 struct drm_i915_private *dev_priv = to_i915(dev);
3486 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3487 enum transcoder cpu_transcoder;
3488 u8 master_pipes, slave_pipes;
3489 u8 enabled_transcoders = 0;
3492 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3493 * consistency and less surprising code; it's in always on power).
3495 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3496 panel_transcoder_mask) {
3497 enum intel_display_power_domain power_domain;
3498 intel_wakeref_t wakeref;
3499 enum pipe trans_pipe;
3502 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3503 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3504 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3506 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3509 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3512 "unknown pipe linked to transcoder %s\n",
3513 transcoder_name(cpu_transcoder));
3515 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3516 case TRANS_DDI_EDP_INPUT_A_ON:
3517 trans_pipe = PIPE_A;
3519 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3520 trans_pipe = PIPE_B;
3522 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3523 trans_pipe = PIPE_C;
3525 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3526 trans_pipe = PIPE_D;
3530 if (trans_pipe == crtc->pipe)
3531 enabled_transcoders |= BIT(cpu_transcoder);
3534 /* single pipe or bigjoiner master */
3535 cpu_transcoder = (enum transcoder) crtc->pipe;
3536 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3537 enabled_transcoders |= BIT(cpu_transcoder);
3539 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3540 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3541 if (slave_pipes & BIT(crtc->pipe)) {
3542 cpu_transcoder = (enum transcoder)
3543 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3544 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3545 enabled_transcoders |= BIT(cpu_transcoder);
3548 return enabled_transcoders;
3551 static bool has_edp_transcoders(u8 enabled_transcoders)
3553 return enabled_transcoders & BIT(TRANSCODER_EDP);
3556 static bool has_dsi_transcoders(u8 enabled_transcoders)
3558 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3559 BIT(TRANSCODER_DSI_1));
3562 static bool has_pipe_transcoders(u8 enabled_transcoders)
3564 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3565 BIT(TRANSCODER_DSI_0) |
3566 BIT(TRANSCODER_DSI_1));
3569 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3570 u8 enabled_transcoders)
3572 /* Only one type of transcoder please */
3573 drm_WARN_ON(&i915->drm,
3574 has_edp_transcoders(enabled_transcoders) +
3575 has_dsi_transcoders(enabled_transcoders) +
3576 has_pipe_transcoders(enabled_transcoders) > 1);
3578 /* Only DSI transcoders can be ganged */
3579 drm_WARN_ON(&i915->drm,
3580 !has_dsi_transcoders(enabled_transcoders) &&
3581 !is_power_of_2(enabled_transcoders));
3584 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3585 struct intel_crtc_state *pipe_config,
3586 struct intel_display_power_domain_set *power_domain_set)
3588 struct drm_device *dev = crtc->base.dev;
3589 struct drm_i915_private *dev_priv = to_i915(dev);
3590 unsigned long enabled_transcoders;
3593 enabled_transcoders = hsw_enabled_transcoders(crtc);
3594 if (!enabled_transcoders)
3597 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3600 * With the exception of DSI we should only ever have
3601 * a single enabled transcoder. With DSI let's just
3602 * pick the first one.
3604 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3606 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3607 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3610 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3611 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3613 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3614 pipe_config->pch_pfit.force_thru = true;
3617 tmp = intel_de_read(dev_priv, TRANSCONF(pipe_config->cpu_transcoder));
3619 return tmp & TRANSCONF_ENABLE;
3622 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3623 struct intel_crtc_state *pipe_config,
3624 struct intel_display_power_domain_set *power_domain_set)
3626 struct drm_device *dev = crtc->base.dev;
3627 struct drm_i915_private *dev_priv = to_i915(dev);
3628 enum transcoder cpu_transcoder;
3632 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3634 cpu_transcoder = TRANSCODER_DSI_A;
3636 cpu_transcoder = TRANSCODER_DSI_C;
3638 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3639 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3643 * The PLL needs to be enabled with a valid divider
3644 * configuration, otherwise accessing DSI registers will hang
3645 * the machine. See BSpec North Display Engine
3646 * registers/MIPI[BXT]. We can break out here early, since we
3647 * need the same DSI PLL to be enabled for both DSI ports.
3649 if (!bxt_dsi_pll_is_enabled(dev_priv))
3652 /* XXX: this works for video mode only */
3653 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
3654 if (!(tmp & DPI_ENABLE))
3657 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
3658 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
3661 pipe_config->cpu_transcoder = cpu_transcoder;
3665 return transcoder_is_dsi(pipe_config->cpu_transcoder);
3668 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
3670 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3671 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3672 u8 master_pipes, slave_pipes;
3673 enum pipe pipe = crtc->pipe;
3675 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
3677 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
3680 crtc_state->bigjoiner_pipes =
3681 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
3682 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
3685 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
3686 struct intel_crtc_state *pipe_config)
3688 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3692 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3693 POWER_DOMAIN_PIPE(crtc->pipe)))
3696 pipe_config->shared_dpll = NULL;
3698 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
3700 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
3701 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
3702 drm_WARN_ON(&dev_priv->drm, active);
3709 intel_dsc_get_config(pipe_config);
3710 intel_bigjoiner_get_config(pipe_config);
3712 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
3713 DISPLAY_VER(dev_priv) >= 11)
3714 intel_get_transcoder_timings(crtc, pipe_config);
3716 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
3717 intel_vrr_get_config(pipe_config);
3719 intel_get_pipe_src_size(crtc, pipe_config);
3721 if (IS_HASWELL(dev_priv)) {
3722 u32 tmp = intel_de_read(dev_priv,
3723 TRANSCONF(pipe_config->cpu_transcoder));
3725 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
3726 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3728 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3730 pipe_config->output_format =
3731 bdw_get_pipe_misc_output_format(crtc);
3734 pipe_config->sink_format = pipe_config->output_format;
3736 pipe_config->gamma_mode = intel_de_read(dev_priv,
3737 GAMMA_MODE(crtc->pipe));
3739 pipe_config->csc_mode = intel_de_read(dev_priv,
3740 PIPE_CSC_MODE(crtc->pipe));
3742 if (DISPLAY_VER(dev_priv) >= 9) {
3743 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
3745 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
3746 pipe_config->gamma_enable = true;
3748 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
3749 pipe_config->csc_enable = true;
3751 i9xx_get_pipe_color_config(pipe_config);
3754 intel_color_get_config(pipe_config);
3756 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
3757 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
3758 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3759 pipe_config->ips_linetime =
3760 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
3762 if (intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
3763 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
3764 if (DISPLAY_VER(dev_priv) >= 9)
3765 skl_scaler_get_config(pipe_config);
3767 ilk_get_pfit_config(pipe_config);
3770 hsw_ips_get_config(pipe_config);
3772 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
3773 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3774 pipe_config->pixel_multiplier =
3775 intel_de_read(dev_priv,
3776 TRANS_MULT(pipe_config->cpu_transcoder)) + 1;
3778 pipe_config->pixel_multiplier = 1;
3781 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
3782 tmp = intel_de_read(dev_priv, DISPLAY_VER(dev_priv) >= 14 ?
3783 MTL_CHICKEN_TRANS(pipe_config->cpu_transcoder) :
3784 CHICKEN_TRANS(pipe_config->cpu_transcoder));
3786 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
3788 /* no idea if this is correct */
3789 pipe_config->framestart_delay = 1;
3793 intel_display_power_put_all_in_set(dev_priv, &crtc->hw_readout_power_domains);
3798 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
3800 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3801 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
3803 if (!i915->display.funcs.display->get_pipe_config(crtc, crtc_state))
3806 crtc_state->hw.active = true;
3808 intel_crtc_readout_derived_state(crtc_state);
3813 static int i9xx_pll_refclk(struct drm_device *dev,
3814 const struct intel_crtc_state *pipe_config)
3816 struct drm_i915_private *dev_priv = to_i915(dev);
3817 u32 dpll = pipe_config->dpll_hw_state.dpll;
3819 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
3820 return dev_priv->display.vbt.lvds_ssc_freq;
3821 else if (HAS_PCH_SPLIT(dev_priv))
3823 else if (DISPLAY_VER(dev_priv) != 2)
3829 /* Returns the clock of the currently programmed mode of the given pipe. */
3830 void i9xx_crtc_clock_get(struct intel_crtc *crtc,
3831 struct intel_crtc_state *pipe_config)
3833 struct drm_device *dev = crtc->base.dev;
3834 struct drm_i915_private *dev_priv = to_i915(dev);
3835 u32 dpll = pipe_config->dpll_hw_state.dpll;
3839 int refclk = i9xx_pll_refclk(dev, pipe_config);
3841 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
3842 fp = pipe_config->dpll_hw_state.fp0;
3844 fp = pipe_config->dpll_hw_state.fp1;
3846 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
3847 if (IS_PINEVIEW(dev_priv)) {
3848 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
3849 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
3851 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
3852 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
3855 if (DISPLAY_VER(dev_priv) != 2) {
3856 if (IS_PINEVIEW(dev_priv))
3857 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
3858 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
3860 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
3861 DPLL_FPA01_P1_POST_DIV_SHIFT);
3863 switch (dpll & DPLL_MODE_MASK) {
3864 case DPLLB_MODE_DAC_SERIAL:
3865 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
3868 case DPLLB_MODE_LVDS:
3869 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
3873 drm_dbg_kms(&dev_priv->drm,
3874 "Unknown DPLL mode %08x in programmed "
3875 "mode\n", (int)(dpll & DPLL_MODE_MASK));
3879 if (IS_PINEVIEW(dev_priv))
3880 port_clock = pnv_calc_dpll_params(refclk, &clock);
3882 port_clock = i9xx_calc_dpll_params(refclk, &clock);
3884 enum pipe lvds_pipe;
3886 if (IS_I85X(dev_priv) &&
3887 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) &&
3888 lvds_pipe == crtc->pipe) {
3889 u32 lvds = intel_de_read(dev_priv, LVDS);
3891 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
3892 DPLL_FPA01_P1_POST_DIV_SHIFT);
3894 if (lvds & LVDS_CLKB_POWER_UP)
3899 if (dpll & PLL_P1_DIVIDE_BY_TWO)
3902 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
3903 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
3905 if (dpll & PLL_P2_DIVIDE_BY_4)
3911 port_clock = i9xx_calc_dpll_params(refclk, &clock);
3915 * This value includes pixel_multiplier. We will use
3916 * port_clock to compute adjusted_mode.crtc_clock in the
3917 * encoder's get_config() function.
3919 pipe_config->port_clock = port_clock;
3922 int intel_dotclock_calculate(int link_freq,
3923 const struct intel_link_m_n *m_n)
3926 * The calculation for the data clock is:
3927 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
3928 * But we want to avoid losing precison if possible, so:
3929 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
3931 * and the link clock is simpler:
3932 * link_clock = (m * link_clock) / n
3938 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq),
3942 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
3946 if (intel_crtc_has_dp_encoder(pipe_config))
3947 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
3948 &pipe_config->dp_m_n);
3949 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
3950 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
3951 pipe_config->pipe_bpp);
3953 dotclock = pipe_config->port_clock;
3955 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
3956 !intel_crtc_has_dp_encoder(pipe_config))
3959 if (pipe_config->pixel_multiplier)
3960 dotclock /= pipe_config->pixel_multiplier;
3965 /* Returns the currently programmed mode of the given encoder. */
3966 struct drm_display_mode *
3967 intel_encoder_current_mode(struct intel_encoder *encoder)
3969 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
3970 struct intel_crtc_state *crtc_state;
3971 struct drm_display_mode *mode;
3972 struct intel_crtc *crtc;
3975 if (!encoder->get_hw_state(encoder, &pipe))
3978 crtc = intel_crtc_for_pipe(dev_priv, pipe);
3980 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
3984 crtc_state = intel_crtc_state_alloc(crtc);
3990 if (!intel_crtc_get_pipe_config(crtc_state)) {
3996 intel_encoder_get_config(encoder, crtc_state);
3998 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4005 static bool encoders_cloneable(const struct intel_encoder *a,
4006 const struct intel_encoder *b)
4008 /* masks could be asymmetric, so check both ways */
4009 return a == b || (a->cloneable & BIT(b->type) &&
4010 b->cloneable & BIT(a->type));
4013 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4014 struct intel_crtc *crtc,
4015 struct intel_encoder *encoder)
4017 struct intel_encoder *source_encoder;
4018 struct drm_connector *connector;
4019 struct drm_connector_state *connector_state;
4022 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4023 if (connector_state->crtc != &crtc->base)
4027 to_intel_encoder(connector_state->best_encoder);
4028 if (!encoders_cloneable(encoder, source_encoder))
4035 static int icl_add_linked_planes(struct intel_atomic_state *state)
4037 struct intel_plane *plane, *linked;
4038 struct intel_plane_state *plane_state, *linked_plane_state;
4041 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4042 linked = plane_state->planar_linked_plane;
4047 linked_plane_state = intel_atomic_get_plane_state(state, linked);
4048 if (IS_ERR(linked_plane_state))
4049 return PTR_ERR(linked_plane_state);
4051 drm_WARN_ON(state->base.dev,
4052 linked_plane_state->planar_linked_plane != plane);
4053 drm_WARN_ON(state->base.dev,
4054 linked_plane_state->planar_slave == plane_state->planar_slave);
4060 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
4062 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4063 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4064 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
4065 struct intel_plane *plane, *linked;
4066 struct intel_plane_state *plane_state;
4069 if (DISPLAY_VER(dev_priv) < 11)
4073 * Destroy all old plane links and make the slave plane invisible
4074 * in the crtc_state->active_planes mask.
4076 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4077 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
4080 plane_state->planar_linked_plane = NULL;
4081 if (plane_state->planar_slave && !plane_state->uapi.visible) {
4082 crtc_state->enabled_planes &= ~BIT(plane->id);
4083 crtc_state->active_planes &= ~BIT(plane->id);
4084 crtc_state->update_planes |= BIT(plane->id);
4085 crtc_state->data_rate[plane->id] = 0;
4086 crtc_state->rel_data_rate[plane->id] = 0;
4089 plane_state->planar_slave = false;
4092 if (!crtc_state->nv12_planes)
4095 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4096 struct intel_plane_state *linked_state = NULL;
4098 if (plane->pipe != crtc->pipe ||
4099 !(crtc_state->nv12_planes & BIT(plane->id)))
4102 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4103 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4106 if (crtc_state->active_planes & BIT(linked->id))
4109 linked_state = intel_atomic_get_plane_state(state, linked);
4110 if (IS_ERR(linked_state))
4111 return PTR_ERR(linked_state);
4116 if (!linked_state) {
4117 drm_dbg_kms(&dev_priv->drm,
4118 "Need %d free Y planes for planar YUV\n",
4119 hweight8(crtc_state->nv12_planes));
4124 plane_state->planar_linked_plane = linked;
4126 linked_state->planar_slave = true;
4127 linked_state->planar_linked_plane = plane;
4128 crtc_state->enabled_planes |= BIT(linked->id);
4129 crtc_state->active_planes |= BIT(linked->id);
4130 crtc_state->update_planes |= BIT(linked->id);
4131 crtc_state->data_rate[linked->id] =
4132 crtc_state->data_rate_y[plane->id];
4133 crtc_state->rel_data_rate[linked->id] =
4134 crtc_state->rel_data_rate_y[plane->id];
4135 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4136 linked->base.name, plane->base.name);
4138 /* Copy parameters to slave plane */
4139 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4140 linked_state->color_ctl = plane_state->color_ctl;
4141 linked_state->view = plane_state->view;
4142 linked_state->decrypt = plane_state->decrypt;
4144 intel_plane_copy_hw_state(linked_state, plane_state);
4145 linked_state->uapi.src = plane_state->uapi.src;
4146 linked_state->uapi.dst = plane_state->uapi.dst;
4148 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4149 if (linked->id == PLANE_SPRITE5)
4150 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4151 else if (linked->id == PLANE_SPRITE4)
4152 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4153 else if (linked->id == PLANE_SPRITE3)
4154 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4155 else if (linked->id == PLANE_SPRITE2)
4156 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4158 MISSING_CASE(linked->id);
4165 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4167 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4168 struct intel_atomic_state *state =
4169 to_intel_atomic_state(new_crtc_state->uapi.state);
4170 const struct intel_crtc_state *old_crtc_state =
4171 intel_atomic_get_old_crtc_state(state, crtc);
4173 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4176 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4178 const struct drm_display_mode *pipe_mode =
4179 &crtc_state->hw.pipe_mode;
4182 if (!crtc_state->hw.enable)
4185 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4186 pipe_mode->crtc_clock);
4188 return min(linetime_wm, 0x1ff);
4191 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4192 const struct intel_cdclk_state *cdclk_state)
4194 const struct drm_display_mode *pipe_mode =
4195 &crtc_state->hw.pipe_mode;
4198 if (!crtc_state->hw.enable)
4201 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4202 cdclk_state->logical.cdclk);
4204 return min(linetime_wm, 0x1ff);
4207 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4209 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4210 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4211 const struct drm_display_mode *pipe_mode =
4212 &crtc_state->hw.pipe_mode;
4215 if (!crtc_state->hw.enable)
4218 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4219 crtc_state->pixel_rate);
4221 /* Display WA #1135: BXT:ALL GLK:ALL */
4222 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4223 skl_watermark_ipc_enabled(dev_priv))
4226 return min(linetime_wm, 0x1ff);
4229 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4230 struct intel_crtc *crtc)
4232 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4233 struct intel_crtc_state *crtc_state =
4234 intel_atomic_get_new_crtc_state(state, crtc);
4235 const struct intel_cdclk_state *cdclk_state;
4237 if (DISPLAY_VER(dev_priv) >= 9)
4238 crtc_state->linetime = skl_linetime_wm(crtc_state);
4240 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4242 if (!hsw_crtc_supports_ips(crtc))
4245 cdclk_state = intel_atomic_get_cdclk_state(state);
4246 if (IS_ERR(cdclk_state))
4247 return PTR_ERR(cdclk_state);
4249 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4255 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4256 struct intel_crtc *crtc)
4258 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4259 struct intel_crtc_state *crtc_state =
4260 intel_atomic_get_new_crtc_state(state, crtc);
4263 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4264 intel_crtc_needs_modeset(crtc_state) &&
4265 !crtc_state->hw.active)
4266 crtc_state->update_wm_post = true;
4268 if (intel_crtc_needs_modeset(crtc_state)) {
4269 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4275 * May need to update pipe gamma enable bits
4276 * when C8 planes are getting enabled/disabled.
4278 if (c8_planes_changed(crtc_state))
4279 crtc_state->uapi.color_mgmt_changed = true;
4281 if (intel_crtc_needs_color_update(crtc_state)) {
4282 ret = intel_color_check(crtc_state);
4287 ret = intel_compute_pipe_wm(state, crtc);
4289 drm_dbg_kms(&dev_priv->drm,
4290 "Target pipe watermarks are invalid\n");
4295 * Calculate 'intermediate' watermarks that satisfy both the
4296 * old state and the new state. We can program these
4299 ret = intel_compute_intermediate_wm(state, crtc);
4301 drm_dbg_kms(&dev_priv->drm,
4302 "No valid intermediate pipe watermarks are possible\n");
4306 if (DISPLAY_VER(dev_priv) >= 9) {
4307 if (intel_crtc_needs_modeset(crtc_state) ||
4308 intel_crtc_needs_fastset(crtc_state)) {
4309 ret = skl_update_scaler_crtc(crtc_state);
4314 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4319 if (HAS_IPS(dev_priv)) {
4320 ret = hsw_ips_compute_config(state, crtc);
4325 if (DISPLAY_VER(dev_priv) >= 9 ||
4326 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4327 ret = hsw_compute_linetime_wm(state, crtc);
4333 ret = intel_psr2_sel_fetch_update(state, crtc);
4341 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4342 struct intel_crtc_state *crtc_state)
4344 struct drm_connector *connector = conn_state->connector;
4345 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4346 const struct drm_display_info *info = &connector->display_info;
4349 switch (conn_state->max_bpc) {
4363 MISSING_CASE(conn_state->max_bpc);
4367 if (bpp < crtc_state->pipe_bpp) {
4368 drm_dbg_kms(&i915->drm,
4369 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4370 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4371 connector->base.id, connector->name,
4373 3 * conn_state->max_requested_bpc,
4374 crtc_state->pipe_bpp);
4376 crtc_state->pipe_bpp = bpp;
4383 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4384 struct intel_crtc *crtc)
4386 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4387 struct intel_crtc_state *crtc_state =
4388 intel_atomic_get_new_crtc_state(state, crtc);
4389 struct drm_connector *connector;
4390 struct drm_connector_state *connector_state;
4393 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4394 IS_CHERRYVIEW(dev_priv)))
4396 else if (DISPLAY_VER(dev_priv) >= 5)
4401 crtc_state->pipe_bpp = bpp;
4403 /* Clamp display bpp to connector max bpp */
4404 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4407 if (connector_state->crtc != &crtc->base)
4410 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4418 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4420 struct drm_device *dev = state->base.dev;
4421 struct drm_connector *connector;
4422 struct drm_connector_list_iter conn_iter;
4423 unsigned int used_ports = 0;
4424 unsigned int used_mst_ports = 0;
4428 * We're going to peek into connector->state,
4429 * hence connection_mutex must be held.
4431 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4434 * Walk the connector list instead of the encoder
4435 * list to detect the problem on ddi platforms
4436 * where there's just one encoder per digital port.
4438 drm_connector_list_iter_begin(dev, &conn_iter);
4439 drm_for_each_connector_iter(connector, &conn_iter) {
4440 struct drm_connector_state *connector_state;
4441 struct intel_encoder *encoder;
4444 drm_atomic_get_new_connector_state(&state->base,
4446 if (!connector_state)
4447 connector_state = connector->state;
4449 if (!connector_state->best_encoder)
4452 encoder = to_intel_encoder(connector_state->best_encoder);
4454 drm_WARN_ON(dev, !connector_state->crtc);
4456 switch (encoder->type) {
4457 case INTEL_OUTPUT_DDI:
4458 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4461 case INTEL_OUTPUT_DP:
4462 case INTEL_OUTPUT_HDMI:
4463 case INTEL_OUTPUT_EDP:
4464 /* the same port mustn't appear more than once */
4465 if (used_ports & BIT(encoder->port))
4468 used_ports |= BIT(encoder->port);
4470 case INTEL_OUTPUT_DP_MST:
4478 drm_connector_list_iter_end(&conn_iter);
4480 /* can't mix MST and SST/HDMI on the same port */
4481 if (used_ports & used_mst_ports)
4488 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4489 struct intel_crtc *crtc)
4491 struct intel_crtc_state *crtc_state =
4492 intel_atomic_get_new_crtc_state(state, crtc);
4494 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4496 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4497 crtc_state->uapi.degamma_lut);
4498 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4499 crtc_state->uapi.gamma_lut);
4500 drm_property_replace_blob(&crtc_state->hw.ctm,
4501 crtc_state->uapi.ctm);
4505 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4506 struct intel_crtc *crtc)
4508 struct intel_crtc_state *crtc_state =
4509 intel_atomic_get_new_crtc_state(state, crtc);
4511 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
4513 crtc_state->hw.enable = crtc_state->uapi.enable;
4514 crtc_state->hw.active = crtc_state->uapi.active;
4515 drm_mode_copy(&crtc_state->hw.mode,
4516 &crtc_state->uapi.mode);
4517 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4518 &crtc_state->uapi.adjusted_mode);
4519 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4521 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4525 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4526 struct intel_crtc *slave_crtc)
4528 struct intel_crtc_state *slave_crtc_state =
4529 intel_atomic_get_new_crtc_state(state, slave_crtc);
4530 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4531 const struct intel_crtc_state *master_crtc_state =
4532 intel_atomic_get_new_crtc_state(state, master_crtc);
4534 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
4535 master_crtc_state->hw.degamma_lut);
4536 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
4537 master_crtc_state->hw.gamma_lut);
4538 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
4539 master_crtc_state->hw.ctm);
4541 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
4545 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
4546 struct intel_crtc *slave_crtc)
4548 struct intel_crtc_state *slave_crtc_state =
4549 intel_atomic_get_new_crtc_state(state, slave_crtc);
4550 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
4551 const struct intel_crtc_state *master_crtc_state =
4552 intel_atomic_get_new_crtc_state(state, master_crtc);
4553 struct intel_crtc_state *saved_state;
4555 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4556 slave_crtc_state->bigjoiner_pipes);
4558 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4562 /* preserve some things from the slave's original crtc state */
4563 saved_state->uapi = slave_crtc_state->uapi;
4564 saved_state->scaler_state = slave_crtc_state->scaler_state;
4565 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
4566 saved_state->dpll_hw_state = slave_crtc_state->dpll_hw_state;
4567 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
4569 intel_crtc_free_hw_state(slave_crtc_state);
4570 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
4573 /* Re-init hw state */
4574 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
4575 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
4576 slave_crtc_state->hw.active = master_crtc_state->hw.active;
4577 drm_mode_copy(&slave_crtc_state->hw.mode,
4578 &master_crtc_state->hw.mode);
4579 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
4580 &master_crtc_state->hw.pipe_mode);
4581 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
4582 &master_crtc_state->hw.adjusted_mode);
4583 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
4585 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
4587 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
4588 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
4589 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
4591 WARN_ON(master_crtc_state->bigjoiner_pipes !=
4592 slave_crtc_state->bigjoiner_pipes);
4598 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4599 struct intel_crtc *crtc)
4601 struct intel_crtc_state *crtc_state =
4602 intel_atomic_get_new_crtc_state(state, crtc);
4603 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4604 struct intel_crtc_state *saved_state;
4606 saved_state = intel_crtc_state_alloc(crtc);
4610 /* free the old crtc_state->hw members */
4611 intel_crtc_free_hw_state(crtc_state);
4613 /* FIXME: before the switch to atomic started, a new pipe_config was
4614 * kzalloc'd. Code that depends on any field being zero should be
4615 * fixed, so that the crtc_state can be safely duplicated. For now,
4616 * only fields that are know to not cause problems are preserved. */
4618 saved_state->uapi = crtc_state->uapi;
4619 saved_state->inherited = crtc_state->inherited;
4620 saved_state->scaler_state = crtc_state->scaler_state;
4621 saved_state->shared_dpll = crtc_state->shared_dpll;
4622 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4623 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4624 sizeof(saved_state->icl_port_dplls));
4625 saved_state->crc_enabled = crtc_state->crc_enabled;
4626 if (IS_G4X(dev_priv) ||
4627 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4628 saved_state->wm = crtc_state->wm;
4630 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4633 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4639 intel_modeset_pipe_config(struct intel_atomic_state *state,
4640 struct intel_crtc *crtc)
4642 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4643 struct intel_crtc_state *crtc_state =
4644 intel_atomic_get_new_crtc_state(state, crtc);
4645 struct drm_connector *connector;
4646 struct drm_connector_state *connector_state;
4647 int pipe_src_w, pipe_src_h;
4648 int base_bpp, ret, i;
4651 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4653 crtc_state->framestart_delay = 1;
4656 * Sanitize sync polarity flags based on requested ones. If neither
4657 * positive or negative polarity is requested, treat this as meaning
4658 * negative polarity.
4660 if (!(crtc_state->hw.adjusted_mode.flags &
4661 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4662 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4664 if (!(crtc_state->hw.adjusted_mode.flags &
4665 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4666 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4668 ret = compute_baseline_pipe_bpp(state, crtc);
4672 base_bpp = crtc_state->pipe_bpp;
4675 * Determine the real pipe dimensions. Note that stereo modes can
4676 * increase the actual pipe size due to the frame doubling and
4677 * insertion of additional space for blanks between the frame. This
4678 * is stored in the crtc timings. We use the requested mode to do this
4679 * computation to clearly distinguish it from the adjusted mode, which
4680 * can be changed by the connectors in the below retry loop.
4682 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4683 &pipe_src_w, &pipe_src_h);
4684 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4685 pipe_src_w, pipe_src_h);
4687 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4688 struct intel_encoder *encoder =
4689 to_intel_encoder(connector_state->best_encoder);
4691 if (connector_state->crtc != &crtc->base)
4694 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4695 drm_dbg_kms(&i915->drm,
4696 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4697 encoder->base.base.id, encoder->base.name);
4702 * Determine output_types before calling the .compute_config()
4703 * hooks so that the hooks can use this information safely.
4705 if (encoder->compute_output_type)
4706 crtc_state->output_types |=
4707 BIT(encoder->compute_output_type(encoder, crtc_state,
4710 crtc_state->output_types |= BIT(encoder->type);
4714 /* Ensure the port clock defaults are reset when retrying. */
4715 crtc_state->port_clock = 0;
4716 crtc_state->pixel_multiplier = 1;
4718 /* Fill in default crtc timings, allow encoders to overwrite them. */
4719 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
4720 CRTC_STEREO_DOUBLE);
4722 /* Pass our mode to the connectors and the CRTC to give them a chance to
4723 * adjust it according to limitations or connector properties, and also
4724 * a chance to reject the mode entirely.
4726 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4727 struct intel_encoder *encoder =
4728 to_intel_encoder(connector_state->best_encoder);
4730 if (connector_state->crtc != &crtc->base)
4733 ret = encoder->compute_config(encoder, crtc_state,
4735 if (ret == -EDEADLK)
4738 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
4739 encoder->base.base.id, encoder->base.name, ret);
4744 /* Set default port clock if not overwritten by the encoder. Needs to be
4745 * done afterwards in case the encoder adjusts the mode. */
4746 if (!crtc_state->port_clock)
4747 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
4748 * crtc_state->pixel_multiplier;
4750 ret = intel_crtc_compute_config(state, crtc);
4751 if (ret == -EDEADLK)
4753 if (ret == -EAGAIN) {
4754 if (drm_WARN(&i915->drm, !retry,
4755 "[CRTC:%d:%s] loop in pipe configuration computation\n",
4756 crtc->base.base.id, crtc->base.name))
4759 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] bw constrained, retrying\n",
4760 crtc->base.base.id, crtc->base.name);
4765 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
4766 crtc->base.base.id, crtc->base.name, ret);
4770 /* Dithering seems to not pass-through bits correctly when it should, so
4771 * only enable it on 6bpc panels and when its not a compliance
4772 * test requesting 6bpc video pattern.
4774 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
4775 !crtc_state->dither_force_disable;
4776 drm_dbg_kms(&i915->drm,
4777 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
4778 crtc->base.base.id, crtc->base.name,
4779 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
4785 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
4786 struct intel_crtc *crtc)
4788 struct intel_crtc_state *crtc_state =
4789 intel_atomic_get_new_crtc_state(state, crtc);
4790 struct drm_connector_state *conn_state;
4791 struct drm_connector *connector;
4794 intel_bigjoiner_adjust_pipe_src(crtc_state);
4796 for_each_new_connector_in_state(&state->base, connector,
4798 struct intel_encoder *encoder =
4799 to_intel_encoder(conn_state->best_encoder);
4802 if (conn_state->crtc != &crtc->base ||
4803 !encoder->compute_config_late)
4806 ret = encoder->compute_config_late(encoder, crtc_state,
4815 bool intel_fuzzy_clock_check(int clock1, int clock2)
4819 if (clock1 == clock2)
4822 if (!clock1 || !clock2)
4825 diff = abs(clock1 - clock2);
4827 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
4834 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
4835 const struct intel_link_m_n *m2_n2)
4837 return m_n->tu == m2_n2->tu &&
4838 m_n->data_m == m2_n2->data_m &&
4839 m_n->data_n == m2_n2->data_n &&
4840 m_n->link_m == m2_n2->link_m &&
4841 m_n->link_n == m2_n2->link_n;
4845 intel_compare_infoframe(const union hdmi_infoframe *a,
4846 const union hdmi_infoframe *b)
4848 return memcmp(a, b, sizeof(*a)) == 0;
4852 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
4853 const struct drm_dp_vsc_sdp *b)
4855 return memcmp(a, b, sizeof(*a)) == 0;
4859 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
4861 return memcmp(a, b, len) == 0;
4865 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
4866 bool fastset, const char *name,
4867 const union hdmi_infoframe *a,
4868 const union hdmi_infoframe *b)
4871 if (!drm_debug_enabled(DRM_UT_KMS))
4874 drm_dbg_kms(&dev_priv->drm,
4875 "fastset requirement not met in %s infoframe\n", name);
4876 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4877 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
4878 drm_dbg_kms(&dev_priv->drm, "found:\n");
4879 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
4881 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
4882 drm_err(&dev_priv->drm, "expected:\n");
4883 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
4884 drm_err(&dev_priv->drm, "found:\n");
4885 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
4890 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
4891 bool fastset, const char *name,
4892 const struct drm_dp_vsc_sdp *a,
4893 const struct drm_dp_vsc_sdp *b)
4896 if (!drm_debug_enabled(DRM_UT_KMS))
4899 drm_dbg_kms(&dev_priv->drm,
4900 "fastset requirement not met in %s dp sdp\n", name);
4901 drm_dbg_kms(&dev_priv->drm, "expected:\n");
4902 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
4903 drm_dbg_kms(&dev_priv->drm, "found:\n");
4904 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
4906 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
4907 drm_err(&dev_priv->drm, "expected:\n");
4908 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
4909 drm_err(&dev_priv->drm, "found:\n");
4910 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
4914 /* Returns the length up to and including the last differing byte */
4916 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
4920 for (i = len - 1; i >= 0; i--) {
4929 pipe_config_buffer_mismatch(struct drm_i915_private *dev_priv,
4930 bool fastset, const char *name,
4931 const u8 *a, const u8 *b, size_t len)
4934 if (!drm_debug_enabled(DRM_UT_KMS))
4937 /* only dump up to the last difference */
4938 len = memcmp_diff_len(a, b, len);
4940 drm_dbg_kms(&dev_priv->drm,
4941 "fastset requirement not met in %s buffer\n", name);
4942 print_hex_dump(KERN_DEBUG, "expected: ", DUMP_PREFIX_NONE,
4943 16, 0, a, len, false);
4944 print_hex_dump(KERN_DEBUG, "found: ", DUMP_PREFIX_NONE,
4945 16, 0, b, len, false);
4947 /* only dump up to the last difference */
4948 len = memcmp_diff_len(a, b, len);
4950 drm_err(&dev_priv->drm, "mismatch in %s buffer\n", name);
4951 print_hex_dump(KERN_ERR, "expected: ", DUMP_PREFIX_NONE,
4952 16, 0, a, len, false);
4953 print_hex_dump(KERN_ERR, "found: ", DUMP_PREFIX_NONE,
4954 16, 0, b, len, false);
4958 static void __printf(4, 5)
4959 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
4960 const char *name, const char *format, ...)
4962 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4963 struct va_format vaf;
4966 va_start(args, format);
4971 drm_dbg_kms(&i915->drm,
4972 "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
4973 crtc->base.base.id, crtc->base.name, name, &vaf);
4975 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
4976 crtc->base.base.id, crtc->base.name, name, &vaf);
4981 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
4983 if (dev_priv->params.fastboot != -1)
4984 return dev_priv->params.fastboot;
4986 /* Enable fastboot by default on Skylake and newer */
4987 if (DISPLAY_VER(dev_priv) >= 9)
4990 /* Enable fastboot by default on VLV and CHV */
4991 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4994 /* Disabled by default on all others */
4999 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
5000 const struct intel_crtc_state *pipe_config,
5003 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
5004 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
5006 bool fixup_inherited = fastset &&
5007 current_config->inherited && !pipe_config->inherited;
5009 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
5010 drm_dbg_kms(&dev_priv->drm,
5011 "initial modeset and fastboot not set\n");
5015 #define PIPE_CONF_CHECK_X(name) do { \
5016 if (current_config->name != pipe_config->name) { \
5017 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5018 "(expected 0x%08x, found 0x%08x)", \
5019 current_config->name, \
5020 pipe_config->name); \
5025 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5026 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5027 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5028 "(expected 0x%08x, found 0x%08x)", \
5029 current_config->name & (mask), \
5030 pipe_config->name & (mask)); \
5035 #define PIPE_CONF_CHECK_I(name) do { \
5036 if (current_config->name != pipe_config->name) { \
5037 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5038 "(expected %i, found %i)", \
5039 current_config->name, \
5040 pipe_config->name); \
5045 #define PIPE_CONF_CHECK_BOOL(name) do { \
5046 if (current_config->name != pipe_config->name) { \
5047 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5048 "(expected %s, found %s)", \
5049 str_yes_no(current_config->name), \
5050 str_yes_no(pipe_config->name)); \
5056 * Checks state where we only read out the enabling, but not the entire
5057 * state itself (like full infoframes or ELD for audio). These states
5058 * require a full modeset on bootup to fix up.
5060 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
5061 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
5062 PIPE_CONF_CHECK_BOOL(name); \
5064 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5065 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
5066 str_yes_no(current_config->name), \
5067 str_yes_no(pipe_config->name)); \
5072 #define PIPE_CONF_CHECK_P(name) do { \
5073 if (current_config->name != pipe_config->name) { \
5074 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5075 "(expected %p, found %p)", \
5076 current_config->name, \
5077 pipe_config->name); \
5082 #define PIPE_CONF_CHECK_M_N(name) do { \
5083 if (!intel_compare_link_m_n(¤t_config->name, \
5084 &pipe_config->name)) { \
5085 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5086 "(expected tu %i data %i/%i link %i/%i, " \
5087 "found tu %i, data %i/%i link %i/%i)", \
5088 current_config->name.tu, \
5089 current_config->name.data_m, \
5090 current_config->name.data_n, \
5091 current_config->name.link_m, \
5092 current_config->name.link_n, \
5093 pipe_config->name.tu, \
5094 pipe_config->name.data_m, \
5095 pipe_config->name.data_n, \
5096 pipe_config->name.link_m, \
5097 pipe_config->name.link_n); \
5102 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5103 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5104 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5105 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5106 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5107 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5108 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5109 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5110 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5111 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5112 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5113 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5114 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5117 #define PIPE_CONF_CHECK_RECT(name) do { \
5118 PIPE_CONF_CHECK_I(name.x1); \
5119 PIPE_CONF_CHECK_I(name.x2); \
5120 PIPE_CONF_CHECK_I(name.y1); \
5121 PIPE_CONF_CHECK_I(name.y2); \
5124 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5125 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5126 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5127 "(%x) (expected %i, found %i)", \
5129 current_config->name & (mask), \
5130 pipe_config->name & (mask)); \
5135 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5136 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5137 &pipe_config->infoframes.name)) { \
5138 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
5139 ¤t_config->infoframes.name, \
5140 &pipe_config->infoframes.name); \
5145 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5146 if (!current_config->has_psr && !pipe_config->has_psr && \
5147 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5148 &pipe_config->infoframes.name)) { \
5149 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
5150 ¤t_config->infoframes.name, \
5151 &pipe_config->infoframes.name); \
5156 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
5157 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
5158 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
5159 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5160 pipe_config_buffer_mismatch(dev_priv, fastset, __stringify(name), \
5161 current_config->name, \
5162 pipe_config->name, \
5168 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5169 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5170 !intel_color_lut_equal(current_config, \
5171 current_config->lut, pipe_config->lut, \
5172 is_pre_csc_lut)) { \
5173 pipe_config_mismatch(fastset, crtc, __stringify(lut), \
5174 "hw_state doesn't match sw_state"); \
5179 #define PIPE_CONF_CHECK_CSC(name) do { \
5180 PIPE_CONF_CHECK_X(name.preoff[0]); \
5181 PIPE_CONF_CHECK_X(name.preoff[1]); \
5182 PIPE_CONF_CHECK_X(name.preoff[2]); \
5183 PIPE_CONF_CHECK_X(name.coeff[0]); \
5184 PIPE_CONF_CHECK_X(name.coeff[1]); \
5185 PIPE_CONF_CHECK_X(name.coeff[2]); \
5186 PIPE_CONF_CHECK_X(name.coeff[3]); \
5187 PIPE_CONF_CHECK_X(name.coeff[4]); \
5188 PIPE_CONF_CHECK_X(name.coeff[5]); \
5189 PIPE_CONF_CHECK_X(name.coeff[6]); \
5190 PIPE_CONF_CHECK_X(name.coeff[7]); \
5191 PIPE_CONF_CHECK_X(name.coeff[8]); \
5192 PIPE_CONF_CHECK_X(name.postoff[0]); \
5193 PIPE_CONF_CHECK_X(name.postoff[1]); \
5194 PIPE_CONF_CHECK_X(name.postoff[2]); \
5197 #define PIPE_CONF_QUIRK(quirk) \
5198 ((current_config->quirks | pipe_config->quirks) & (quirk))
5200 PIPE_CONF_CHECK_I(hw.enable);
5201 PIPE_CONF_CHECK_I(hw.active);
5203 PIPE_CONF_CHECK_I(cpu_transcoder);
5204 PIPE_CONF_CHECK_I(mst_master_transcoder);
5206 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5207 PIPE_CONF_CHECK_I(fdi_lanes);
5208 PIPE_CONF_CHECK_M_N(fdi_m_n);
5210 PIPE_CONF_CHECK_I(lane_count);
5211 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5213 if (HAS_DOUBLE_BUFFERED_M_N(dev_priv)) {
5214 if (!fastset || !pipe_config->seamless_m_n)
5215 PIPE_CONF_CHECK_M_N(dp_m_n);
5217 PIPE_CONF_CHECK_M_N(dp_m_n);
5218 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5221 PIPE_CONF_CHECK_X(output_types);
5223 PIPE_CONF_CHECK_I(framestart_delay);
5224 PIPE_CONF_CHECK_I(msa_timing_delay);
5226 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5227 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5229 PIPE_CONF_CHECK_I(pixel_multiplier);
5231 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5232 DRM_MODE_FLAG_INTERLACE);
5234 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5235 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5236 DRM_MODE_FLAG_PHSYNC);
5237 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5238 DRM_MODE_FLAG_NHSYNC);
5239 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5240 DRM_MODE_FLAG_PVSYNC);
5241 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5242 DRM_MODE_FLAG_NVSYNC);
5245 PIPE_CONF_CHECK_I(output_format);
5246 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5247 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5248 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5249 PIPE_CONF_CHECK_BOOL(limited_color_range);
5251 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5252 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5253 PIPE_CONF_CHECK_BOOL(has_infoframe);
5254 PIPE_CONF_CHECK_BOOL(fec_enable);
5256 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
5257 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5259 PIPE_CONF_CHECK_X(gmch_pfit.control);
5260 /* pfit ratios are autocomputed by the hw on gen4+ */
5261 if (DISPLAY_VER(dev_priv) < 4)
5262 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5263 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5266 * Changing the EDP transcoder input mux
5267 * (A_ONOFF vs. A_ON) requires a full modeset.
5269 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5272 PIPE_CONF_CHECK_RECT(pipe_src);
5274 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5275 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5277 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5278 PIPE_CONF_CHECK_I(pixel_rate);
5280 PIPE_CONF_CHECK_X(gamma_mode);
5281 if (IS_CHERRYVIEW(dev_priv))
5282 PIPE_CONF_CHECK_X(cgm_mode);
5284 PIPE_CONF_CHECK_X(csc_mode);
5285 PIPE_CONF_CHECK_BOOL(gamma_enable);
5286 PIPE_CONF_CHECK_BOOL(csc_enable);
5287 PIPE_CONF_CHECK_BOOL(wgc_enable);
5289 PIPE_CONF_CHECK_I(linetime);
5290 PIPE_CONF_CHECK_I(ips_linetime);
5292 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5293 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5295 PIPE_CONF_CHECK_CSC(csc);
5296 PIPE_CONF_CHECK_CSC(output_csc);
5298 if (current_config->active_planes) {
5299 PIPE_CONF_CHECK_BOOL(has_psr);
5300 PIPE_CONF_CHECK_BOOL(has_psr2);
5301 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5302 PIPE_CONF_CHECK_I(dc3co_exitline);
5306 PIPE_CONF_CHECK_BOOL(double_wide);
5308 if (dev_priv->display.dpll.mgr) {
5309 PIPE_CONF_CHECK_P(shared_dpll);
5311 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
5312 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
5313 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
5314 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
5315 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
5316 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
5317 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
5318 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
5319 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
5320 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
5321 PIPE_CONF_CHECK_X(dpll_hw_state.div0);
5322 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
5323 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
5324 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
5325 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
5326 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
5327 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
5328 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
5329 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
5330 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
5331 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
5332 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
5333 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
5334 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
5335 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
5336 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
5337 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
5338 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
5339 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
5340 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
5341 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
5342 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
5345 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5346 PIPE_CONF_CHECK_X(dsi_pll.div);
5348 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5349 PIPE_CONF_CHECK_I(pipe_bpp);
5351 if (!fastset || !pipe_config->seamless_m_n) {
5352 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5353 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5355 PIPE_CONF_CHECK_I(port_clock);
5357 PIPE_CONF_CHECK_I(min_voltage_level);
5359 if (current_config->has_psr || pipe_config->has_psr)
5360 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5361 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5363 PIPE_CONF_CHECK_X(infoframes.enable);
5365 PIPE_CONF_CHECK_X(infoframes.gcp);
5366 PIPE_CONF_CHECK_INFOFRAME(avi);
5367 PIPE_CONF_CHECK_INFOFRAME(spd);
5368 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5369 PIPE_CONF_CHECK_INFOFRAME(drm);
5370 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5372 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5373 PIPE_CONF_CHECK_I(master_transcoder);
5374 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5376 PIPE_CONF_CHECK_I(dsc.compression_enable);
5377 PIPE_CONF_CHECK_I(dsc.dsc_split);
5378 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
5380 PIPE_CONF_CHECK_BOOL(splitter.enable);
5381 PIPE_CONF_CHECK_I(splitter.link_count);
5382 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5385 PIPE_CONF_CHECK_BOOL(vrr.enable);
5386 PIPE_CONF_CHECK_I(vrr.vmin);
5387 PIPE_CONF_CHECK_I(vrr.vmax);
5388 PIPE_CONF_CHECK_I(vrr.flipline);
5389 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5390 PIPE_CONF_CHECK_I(vrr.guardband);
5392 #undef PIPE_CONF_CHECK_X
5393 #undef PIPE_CONF_CHECK_I
5394 #undef PIPE_CONF_CHECK_BOOL
5395 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
5396 #undef PIPE_CONF_CHECK_P
5397 #undef PIPE_CONF_CHECK_FLAGS
5398 #undef PIPE_CONF_CHECK_COLOR_LUT
5399 #undef PIPE_CONF_CHECK_TIMINGS
5400 #undef PIPE_CONF_CHECK_RECT
5401 #undef PIPE_CONF_QUIRK
5407 intel_verify_planes(struct intel_atomic_state *state)
5409 struct intel_plane *plane;
5410 const struct intel_plane_state *plane_state;
5413 for_each_new_intel_plane_in_state(state, plane,
5415 assert_plane(plane, plane_state->planar_slave ||
5416 plane_state->uapi.visible);
5419 int intel_modeset_all_pipes(struct intel_atomic_state *state,
5422 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5423 struct intel_crtc *crtc;
5426 * Add all pipes to the state, and force
5427 * a modeset on all the active ones.
5429 for_each_intel_crtc(&dev_priv->drm, crtc) {
5430 struct intel_crtc_state *crtc_state;
5433 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5434 if (IS_ERR(crtc_state))
5435 return PTR_ERR(crtc_state);
5437 if (!crtc_state->hw.active ||
5438 intel_crtc_needs_modeset(crtc_state))
5441 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5442 crtc->base.base.id, crtc->base.name, reason);
5444 crtc_state->uapi.mode_changed = true;
5445 crtc_state->update_pipe = false;
5447 ret = drm_atomic_add_affected_connectors(&state->base,
5452 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5456 ret = intel_atomic_add_affected_planes(state, crtc);
5460 crtc_state->update_planes |= crtc_state->active_planes;
5461 crtc_state->async_flip_planes = 0;
5462 crtc_state->do_async_flip = false;
5469 * This implements the workaround described in the "notes" section of the mode
5470 * set sequence documentation. When going from no pipes or single pipe to
5471 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5472 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5474 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5476 struct intel_crtc_state *crtc_state;
5477 struct intel_crtc *crtc;
5478 struct intel_crtc_state *first_crtc_state = NULL;
5479 struct intel_crtc_state *other_crtc_state = NULL;
5480 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5483 /* look at all crtc's that are going to be enabled in during modeset */
5484 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5485 if (!crtc_state->hw.active ||
5486 !intel_crtc_needs_modeset(crtc_state))
5489 if (first_crtc_state) {
5490 other_crtc_state = crtc_state;
5493 first_crtc_state = crtc_state;
5494 first_pipe = crtc->pipe;
5498 /* No workaround needed? */
5499 if (!first_crtc_state)
5502 /* w/a possibly needed, check how many crtc's are already enabled. */
5503 for_each_intel_crtc(state->base.dev, crtc) {
5504 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5505 if (IS_ERR(crtc_state))
5506 return PTR_ERR(crtc_state);
5508 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5510 if (!crtc_state->hw.active ||
5511 intel_crtc_needs_modeset(crtc_state))
5514 /* 2 or more enabled crtcs means no need for w/a */
5515 if (enabled_pipe != INVALID_PIPE)
5518 enabled_pipe = crtc->pipe;
5521 if (enabled_pipe != INVALID_PIPE)
5522 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5523 else if (other_crtc_state)
5524 other_crtc_state->hsw_workaround_pipe = first_pipe;
5529 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
5532 const struct intel_crtc_state *crtc_state;
5533 struct intel_crtc *crtc;
5536 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5537 if (crtc_state->hw.active)
5538 active_pipes |= BIT(crtc->pipe);
5540 active_pipes &= ~BIT(crtc->pipe);
5543 return active_pipes;
5546 static int intel_modeset_checks(struct intel_atomic_state *state)
5548 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5550 state->modeset = true;
5552 if (IS_HASWELL(dev_priv))
5553 return hsw_mode_set_planes_workaround(state);
5558 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
5559 struct intel_crtc_state *new_crtc_state)
5561 struct drm_i915_private *i915 = to_i915(old_crtc_state->uapi.crtc->dev);
5563 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true)) {
5564 drm_dbg_kms(&i915->drm, "fastset requirement not met, forcing full modeset\n");
5569 new_crtc_state->uapi.mode_changed = false;
5570 if (!intel_crtc_needs_modeset(new_crtc_state))
5571 new_crtc_state->update_pipe = true;
5574 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
5575 struct intel_crtc *crtc,
5578 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5579 struct intel_plane *plane;
5581 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5582 struct intel_plane_state *plane_state;
5584 if ((plane_ids_mask & BIT(plane->id)) == 0)
5587 plane_state = intel_atomic_get_plane_state(state, plane);
5588 if (IS_ERR(plane_state))
5589 return PTR_ERR(plane_state);
5595 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
5596 struct intel_crtc *crtc)
5598 const struct intel_crtc_state *old_crtc_state =
5599 intel_atomic_get_old_crtc_state(state, crtc);
5600 const struct intel_crtc_state *new_crtc_state =
5601 intel_atomic_get_new_crtc_state(state, crtc);
5603 return intel_crtc_add_planes_to_state(state, crtc,
5604 old_crtc_state->enabled_planes |
5605 new_crtc_state->enabled_planes);
5608 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
5610 /* See {hsw,vlv,ivb}_plane_ratio() */
5611 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
5612 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
5613 IS_IVYBRIDGE(dev_priv);
5616 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
5617 struct intel_crtc *crtc,
5618 struct intel_crtc *other)
5620 const struct intel_plane_state *plane_state;
5621 struct intel_plane *plane;
5625 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5626 if (plane->pipe == crtc->pipe)
5627 plane_ids |= BIT(plane->id);
5630 return intel_crtc_add_planes_to_state(state, other, plane_ids);
5633 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
5635 struct drm_i915_private *i915 = to_i915(state->base.dev);
5636 const struct intel_crtc_state *crtc_state;
5637 struct intel_crtc *crtc;
5640 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5641 struct intel_crtc *other;
5643 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
5644 crtc_state->bigjoiner_pipes) {
5650 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
5659 static int intel_atomic_check_planes(struct intel_atomic_state *state)
5661 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5662 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5663 struct intel_plane_state *plane_state;
5664 struct intel_plane *plane;
5665 struct intel_crtc *crtc;
5668 ret = icl_add_linked_planes(state);
5672 ret = intel_bigjoiner_add_affected_planes(state);
5676 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5677 ret = intel_plane_atomic_check(state, plane);
5679 drm_dbg_atomic(&dev_priv->drm,
5680 "[PLANE:%d:%s] atomic driver check failed\n",
5681 plane->base.base.id, plane->base.name);
5686 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5687 new_crtc_state, i) {
5688 u8 old_active_planes, new_active_planes;
5690 ret = icl_check_nv12_planes(new_crtc_state);
5695 * On some platforms the number of active planes affects
5696 * the planes' minimum cdclk calculation. Add such planes
5697 * to the state before we compute the minimum cdclk.
5699 if (!active_planes_affects_min_cdclk(dev_priv))
5702 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5703 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
5705 if (hweight8(old_active_planes) == hweight8(new_active_planes))
5708 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
5716 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
5718 struct intel_crtc_state *crtc_state;
5719 struct intel_crtc *crtc;
5722 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5723 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5726 ret = intel_crtc_atomic_check(state, crtc);
5728 drm_dbg_atomic(&i915->drm,
5729 "[CRTC:%d:%s] atomic driver check failed\n",
5730 crtc->base.base.id, crtc->base.name);
5738 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
5741 const struct intel_crtc_state *new_crtc_state;
5742 struct intel_crtc *crtc;
5745 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5746 if (new_crtc_state->hw.enable &&
5747 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
5748 intel_crtc_needs_modeset(new_crtc_state))
5755 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
5758 const struct intel_crtc_state *new_crtc_state;
5759 struct intel_crtc *crtc;
5762 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
5763 if (new_crtc_state->hw.enable &&
5764 pipes & BIT(crtc->pipe) &&
5765 intel_crtc_needs_modeset(new_crtc_state))
5772 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
5773 struct intel_crtc *master_crtc)
5775 struct drm_i915_private *i915 = to_i915(state->base.dev);
5776 struct intel_crtc_state *master_crtc_state =
5777 intel_atomic_get_new_crtc_state(state, master_crtc);
5778 struct intel_crtc *slave_crtc;
5780 if (!master_crtc_state->bigjoiner_pipes)
5784 if (drm_WARN_ON(&i915->drm,
5785 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
5788 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
5789 drm_dbg_kms(&i915->drm,
5790 "[CRTC:%d:%s] Cannot act as big joiner master "
5791 "(need 0x%x as pipes, only 0x%x possible)\n",
5792 master_crtc->base.base.id, master_crtc->base.name,
5793 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
5797 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5798 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5799 struct intel_crtc_state *slave_crtc_state;
5802 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
5803 if (IS_ERR(slave_crtc_state))
5804 return PTR_ERR(slave_crtc_state);
5806 /* master being enabled, slave was already configured? */
5807 if (slave_crtc_state->uapi.enable) {
5808 drm_dbg_kms(&i915->drm,
5809 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
5810 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
5811 slave_crtc->base.base.id, slave_crtc->base.name,
5812 master_crtc->base.base.id, master_crtc->base.name);
5817 * The state copy logic assumes the master crtc gets processed
5818 * before the slave crtc during the main compute_config loop.
5819 * This works because the crtcs are created in pipe order,
5820 * and the hardware requires master pipe < slave pipe as well.
5821 * Should that change we need to rethink the logic.
5823 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
5824 drm_crtc_index(&slave_crtc->base)))
5827 drm_dbg_kms(&i915->drm,
5828 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
5829 slave_crtc->base.base.id, slave_crtc->base.name,
5830 master_crtc->base.base.id, master_crtc->base.name);
5832 slave_crtc_state->bigjoiner_pipes =
5833 master_crtc_state->bigjoiner_pipes;
5835 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
5843 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
5844 struct intel_crtc *master_crtc)
5846 struct drm_i915_private *i915 = to_i915(state->base.dev);
5847 struct intel_crtc_state *master_crtc_state =
5848 intel_atomic_get_new_crtc_state(state, master_crtc);
5849 struct intel_crtc *slave_crtc;
5851 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
5852 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
5853 struct intel_crtc_state *slave_crtc_state =
5854 intel_atomic_get_new_crtc_state(state, slave_crtc);
5856 slave_crtc_state->bigjoiner_pipes = 0;
5858 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
5861 master_crtc_state->bigjoiner_pipes = 0;
5865 * DOC: asynchronous flip implementation
5867 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
5868 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
5869 * Correspondingly, support is currently added for primary plane only.
5871 * Async flip can only change the plane surface address, so anything else
5872 * changing is rejected from the intel_async_flip_check_hw() function.
5873 * Once this check is cleared, flip done interrupt is enabled using
5874 * the intel_crtc_enable_flip_done() function.
5876 * As soon as the surface address register is written, flip done interrupt is
5877 * generated and the requested events are sent to the usersapce in the interrupt
5878 * handler itself. The timestamp and sequence sent during the flip done event
5879 * correspond to the last vblank and have no relation to the actual time when
5880 * the flip done event was sent.
5882 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
5883 struct intel_crtc *crtc)
5885 struct drm_i915_private *i915 = to_i915(state->base.dev);
5886 const struct intel_crtc_state *new_crtc_state =
5887 intel_atomic_get_new_crtc_state(state, crtc);
5888 const struct intel_plane_state *old_plane_state;
5889 struct intel_plane_state *new_plane_state;
5890 struct intel_plane *plane;
5893 if (!new_crtc_state->uapi.async_flip)
5896 if (!new_crtc_state->uapi.active) {
5897 drm_dbg_kms(&i915->drm,
5898 "[CRTC:%d:%s] not active\n",
5899 crtc->base.base.id, crtc->base.name);
5903 if (intel_crtc_needs_modeset(new_crtc_state)) {
5904 drm_dbg_kms(&i915->drm,
5905 "[CRTC:%d:%s] modeset required\n",
5906 crtc->base.base.id, crtc->base.name);
5910 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5911 new_plane_state, i) {
5912 if (plane->pipe != crtc->pipe)
5916 * TODO: Async flip is only supported through the page flip IOCTL
5917 * as of now. So support currently added for primary plane only.
5918 * Support for other planes on platforms on which supports
5919 * this(vlv/chv and icl+) should be added when async flip is
5920 * enabled in the atomic IOCTL path.
5922 if (!plane->async_flip) {
5923 drm_dbg_kms(&i915->drm,
5924 "[PLANE:%d:%s] async flip not supported\n",
5925 plane->base.base.id, plane->base.name);
5929 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
5930 drm_dbg_kms(&i915->drm,
5931 "[PLANE:%d:%s] no old or new framebuffer\n",
5932 plane->base.base.id, plane->base.name);
5940 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
5942 struct drm_i915_private *i915 = to_i915(state->base.dev);
5943 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
5944 const struct intel_plane_state *new_plane_state, *old_plane_state;
5945 struct intel_plane *plane;
5948 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
5949 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
5951 if (!new_crtc_state->uapi.async_flip)
5954 if (!new_crtc_state->hw.active) {
5955 drm_dbg_kms(&i915->drm,
5956 "[CRTC:%d:%s] not active\n",
5957 crtc->base.base.id, crtc->base.name);
5961 if (intel_crtc_needs_modeset(new_crtc_state)) {
5962 drm_dbg_kms(&i915->drm,
5963 "[CRTC:%d:%s] modeset required\n",
5964 crtc->base.base.id, crtc->base.name);
5968 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
5969 drm_dbg_kms(&i915->drm,
5970 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
5971 crtc->base.base.id, crtc->base.name);
5975 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
5976 new_plane_state, i) {
5977 if (plane->pipe != crtc->pipe)
5981 * Only async flip capable planes should be in the state
5982 * if we're really about to ask the hardware to perform
5983 * an async flip. We should never get this far otherwise.
5985 if (drm_WARN_ON(&i915->drm,
5986 new_crtc_state->do_async_flip && !plane->async_flip))
5990 * Only check async flip capable planes other planes
5991 * may be involved in the initial commit due to
5992 * the wm0/ddb optimization.
5994 * TODO maybe should track which planes actually
5995 * were requested to do the async flip...
5997 if (!plane->async_flip)
6001 * FIXME: This check is kept generic for all platforms.
6002 * Need to verify this for all gen9 platforms to enable
6003 * this selectively if required.
6005 switch (new_plane_state->hw.fb->modifier) {
6006 case DRM_FORMAT_MOD_LINEAR:
6008 * FIXME: Async on Linear buffer is supported on ICL as
6009 * but with additional alignment and fbc restrictions
6010 * need to be taken care of. These aren't applicable for
6013 if (DISPLAY_VER(i915) < 12) {
6014 drm_dbg_kms(&i915->drm,
6015 "[PLANE:%d:%s] Modifier does not support async flips\n",
6016 plane->base.base.id, plane->base.name);
6021 case I915_FORMAT_MOD_X_TILED:
6022 case I915_FORMAT_MOD_Y_TILED:
6023 case I915_FORMAT_MOD_Yf_TILED:
6024 case I915_FORMAT_MOD_4_TILED:
6027 drm_dbg_kms(&i915->drm,
6028 "[PLANE:%d:%s] Modifier does not support async flips\n",
6029 plane->base.base.id, plane->base.name);
6033 if (new_plane_state->hw.fb->format->num_planes > 1) {
6034 drm_dbg_kms(&i915->drm,
6035 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6036 plane->base.base.id, plane->base.name);
6040 if (old_plane_state->view.color_plane[0].mapping_stride !=
6041 new_plane_state->view.color_plane[0].mapping_stride) {
6042 drm_dbg_kms(&i915->drm,
6043 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6044 plane->base.base.id, plane->base.name);
6048 if (old_plane_state->hw.fb->modifier !=
6049 new_plane_state->hw.fb->modifier) {
6050 drm_dbg_kms(&i915->drm,
6051 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6052 plane->base.base.id, plane->base.name);
6056 if (old_plane_state->hw.fb->format !=
6057 new_plane_state->hw.fb->format) {
6058 drm_dbg_kms(&i915->drm,
6059 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6060 plane->base.base.id, plane->base.name);
6064 if (old_plane_state->hw.rotation !=
6065 new_plane_state->hw.rotation) {
6066 drm_dbg_kms(&i915->drm,
6067 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6068 plane->base.base.id, plane->base.name);
6072 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6073 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6074 drm_dbg_kms(&i915->drm,
6075 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6076 plane->base.base.id, plane->base.name);
6080 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6081 drm_dbg_kms(&i915->drm,
6082 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6083 plane->base.base.id, plane->base.name);
6087 if (old_plane_state->hw.pixel_blend_mode !=
6088 new_plane_state->hw.pixel_blend_mode) {
6089 drm_dbg_kms(&i915->drm,
6090 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6091 plane->base.base.id, plane->base.name);
6095 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6096 drm_dbg_kms(&i915->drm,
6097 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6098 plane->base.base.id, plane->base.name);
6102 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6103 drm_dbg_kms(&i915->drm,
6104 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6105 plane->base.base.id, plane->base.name);
6109 /* plane decryption is allow to change only in synchronous flips */
6110 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6111 drm_dbg_kms(&i915->drm,
6112 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6113 plane->base.base.id, plane->base.name);
6121 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6123 struct drm_i915_private *i915 = to_i915(state->base.dev);
6124 struct intel_crtc_state *crtc_state;
6125 struct intel_crtc *crtc;
6126 u8 affected_pipes = 0;
6127 u8 modeset_pipes = 0;
6130 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6131 affected_pipes |= crtc_state->bigjoiner_pipes;
6132 if (intel_crtc_needs_modeset(crtc_state))
6133 modeset_pipes |= crtc_state->bigjoiner_pipes;
6136 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6137 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6138 if (IS_ERR(crtc_state))
6139 return PTR_ERR(crtc_state);
6142 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6145 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6147 crtc_state->uapi.mode_changed = true;
6149 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6153 ret = intel_atomic_add_affected_planes(state, crtc);
6158 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6159 /* Kill old bigjoiner link, we may re-establish afterwards */
6160 if (intel_crtc_needs_modeset(crtc_state) &&
6161 intel_crtc_is_bigjoiner_master(crtc_state))
6162 kill_bigjoiner_slave(state, crtc);
6169 * intel_atomic_check - validate state object
6171 * @_state: state to validate
6173 int intel_atomic_check(struct drm_device *dev,
6174 struct drm_atomic_state *_state)
6176 struct drm_i915_private *dev_priv = to_i915(dev);
6177 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6178 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6179 struct intel_crtc *crtc;
6181 bool any_ms = false;
6183 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6184 new_crtc_state, i) {
6186 * crtc's state no longer considered to be inherited
6187 * after the first userspace/client initiated commit.
6189 if (!state->internal)
6190 new_crtc_state->inherited = false;
6192 if (new_crtc_state->inherited != old_crtc_state->inherited)
6193 new_crtc_state->uapi.mode_changed = true;
6195 if (new_crtc_state->uapi.scaling_filter !=
6196 old_crtc_state->uapi.scaling_filter)
6197 new_crtc_state->uapi.mode_changed = true;
6200 intel_vrr_check_modeset(state);
6202 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6206 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6207 ret = intel_async_flip_check_uapi(state, crtc);
6212 ret = intel_bigjoiner_add_affected_crtcs(state);
6216 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6217 new_crtc_state, i) {
6218 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6219 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6220 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6222 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6226 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6227 drm_WARN_ON(&dev_priv->drm, new_crtc_state->uapi.enable);
6231 ret = intel_crtc_prepare_cleared_state(state, crtc);
6235 if (!new_crtc_state->hw.enable)
6238 ret = intel_modeset_pipe_config(state, crtc);
6242 ret = intel_atomic_check_bigjoiner(state, crtc);
6247 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6248 new_crtc_state, i) {
6249 if (!intel_crtc_needs_modeset(new_crtc_state))
6252 if (new_crtc_state->hw.enable) {
6253 ret = intel_modeset_pipe_config_late(state, crtc);
6258 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6262 * Check if fastset is allowed by external dependencies like other
6263 * pipes and transcoders.
6265 * Right now it only forces a fullmodeset when the MST master
6266 * transcoder did not changed but the pipe of the master transcoder
6267 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6268 * in case of port synced crtcs, if one of the synced crtcs
6269 * needs a full modeset, all other synced crtcs should be
6270 * forced a full modeset.
6272 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6273 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6276 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6277 enum transcoder master = new_crtc_state->mst_master_transcoder;
6279 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
6280 new_crtc_state->uapi.mode_changed = true;
6281 new_crtc_state->update_pipe = false;
6285 if (is_trans_port_sync_mode(new_crtc_state)) {
6286 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6288 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6289 trans |= BIT(new_crtc_state->master_transcoder);
6291 if (intel_cpu_transcoders_need_modeset(state, trans)) {
6292 new_crtc_state->uapi.mode_changed = true;
6293 new_crtc_state->update_pipe = false;
6297 if (new_crtc_state->bigjoiner_pipes) {
6298 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes)) {
6299 new_crtc_state->uapi.mode_changed = true;
6300 new_crtc_state->update_pipe = false;
6305 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6306 new_crtc_state, i) {
6307 if (!intel_crtc_needs_modeset(new_crtc_state))
6312 intel_release_shared_dplls(state, crtc);
6315 if (any_ms && !check_digital_port_conflicts(state)) {
6316 drm_dbg_kms(&dev_priv->drm,
6317 "rejecting conflicting digital port configuration\n");
6322 ret = drm_dp_mst_atomic_check(&state->base);
6326 ret = intel_atomic_check_planes(state);
6330 ret = intel_compute_global_watermarks(state);
6334 ret = intel_bw_atomic_check(state);
6338 ret = intel_cdclk_atomic_check(state, &any_ms);
6342 if (intel_any_crtc_needs_modeset(state))
6346 ret = intel_modeset_checks(state);
6350 ret = intel_modeset_calc_cdclk(state);
6355 ret = intel_atomic_check_crtcs(state);
6359 ret = intel_fbc_atomic_check(state);
6363 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6364 new_crtc_state, i) {
6365 intel_color_assert_luts(new_crtc_state);
6367 ret = intel_async_flip_check_hw(state, crtc);
6371 /* Either full modeset or fastset (or neither), never both */
6372 drm_WARN_ON(&dev_priv->drm,
6373 intel_crtc_needs_modeset(new_crtc_state) &&
6374 intel_crtc_needs_fastset(new_crtc_state));
6376 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6377 !intel_crtc_needs_fastset(new_crtc_state))
6380 intel_crtc_state_dump(new_crtc_state, state,
6381 intel_crtc_needs_modeset(new_crtc_state) ?
6382 "modeset" : "fastset");
6388 if (ret == -EDEADLK)
6392 * FIXME would probably be nice to know which crtc specifically
6393 * caused the failure, in cases where we can pinpoint it.
6395 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6397 intel_crtc_state_dump(new_crtc_state, state, "failed");
6402 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6404 struct intel_crtc_state *crtc_state;
6405 struct intel_crtc *crtc;
6408 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6412 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6413 if (intel_crtc_needs_color_update(crtc_state))
6414 intel_color_prepare_commit(crtc_state);
6420 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
6421 struct intel_crtc_state *crtc_state)
6423 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6425 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
6426 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
6428 if (crtc_state->has_pch_encoder) {
6429 enum pipe pch_transcoder =
6430 intel_crtc_pch_transcoder(crtc);
6432 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
6436 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
6437 const struct intel_crtc_state *new_crtc_state)
6439 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6440 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6443 * Update pipe size and adjust fitter if needed: the reason for this is
6444 * that in compute_mode_changes we check the native mode (not the pfit
6445 * mode) to see if we can flip rather than do a full mode set. In the
6446 * fastboot case, we'll flip, but if we don't update the pipesrc and
6447 * pfit state, we'll end up with a big fb scanned out into the wrong
6450 intel_set_pipe_src_size(new_crtc_state);
6452 /* on skylake this is done by detaching scalers */
6453 if (DISPLAY_VER(dev_priv) >= 9) {
6454 if (new_crtc_state->pch_pfit.enabled)
6455 skl_pfit_enable(new_crtc_state);
6456 } else if (HAS_PCH_SPLIT(dev_priv)) {
6457 if (new_crtc_state->pch_pfit.enabled)
6458 ilk_pfit_enable(new_crtc_state);
6459 else if (old_crtc_state->pch_pfit.enabled)
6460 ilk_pfit_disable(old_crtc_state);
6464 * The register is supposedly single buffered so perhaps
6465 * not 100% correct to do this here. But SKL+ calculate
6466 * this based on the adjust pixel rate so pfit changes do
6467 * affect it and so it must be updated for fastsets.
6468 * HSW/BDW only really need this here for fastboot, after
6469 * that the value should not change without a full modeset.
6471 if (DISPLAY_VER(dev_priv) >= 9 ||
6472 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
6473 hsw_set_linetime_wm(new_crtc_state);
6475 if (new_crtc_state->seamless_m_n)
6476 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
6477 &new_crtc_state->dp_m_n);
6480 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
6481 struct intel_crtc *crtc)
6483 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6484 const struct intel_crtc_state *old_crtc_state =
6485 intel_atomic_get_old_crtc_state(state, crtc);
6486 const struct intel_crtc_state *new_crtc_state =
6487 intel_atomic_get_new_crtc_state(state, crtc);
6488 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6491 * During modesets pipe configuration was programmed as the
6495 if (intel_crtc_needs_color_update(new_crtc_state))
6496 intel_color_commit_arm(new_crtc_state);
6498 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
6499 bdw_set_pipe_misc(new_crtc_state);
6501 if (intel_crtc_needs_fastset(new_crtc_state))
6502 intel_pipe_fastset(old_crtc_state, new_crtc_state);
6505 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
6507 intel_atomic_update_watermarks(state, crtc);
6510 static void commit_pipe_post_planes(struct intel_atomic_state *state,
6511 struct intel_crtc *crtc)
6513 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6514 const struct intel_crtc_state *new_crtc_state =
6515 intel_atomic_get_new_crtc_state(state, crtc);
6518 * Disable the scaler(s) after the plane(s) so that we don't
6519 * get a catastrophic underrun even if the two operations
6520 * end up happening in two different frames.
6522 if (DISPLAY_VER(dev_priv) >= 9 &&
6523 !intel_crtc_needs_modeset(new_crtc_state))
6524 skl_detach_scalers(new_crtc_state);
6527 static void intel_enable_crtc(struct intel_atomic_state *state,
6528 struct intel_crtc *crtc)
6530 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6531 const struct intel_crtc_state *new_crtc_state =
6532 intel_atomic_get_new_crtc_state(state, crtc);
6534 if (!intel_crtc_needs_modeset(new_crtc_state))
6537 /* VRR will be enable later, if required */
6538 intel_crtc_update_active_timings(new_crtc_state, false);
6540 dev_priv->display.funcs.display->crtc_enable(state, crtc);
6542 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6545 /* vblanks work again, re-enable pipe CRC. */
6546 intel_crtc_enable_pipe_crc(crtc);
6549 static void intel_update_crtc(struct intel_atomic_state *state,
6550 struct intel_crtc *crtc)
6552 struct drm_i915_private *i915 = to_i915(state->base.dev);
6553 const struct intel_crtc_state *old_crtc_state =
6554 intel_atomic_get_old_crtc_state(state, crtc);
6555 struct intel_crtc_state *new_crtc_state =
6556 intel_atomic_get_new_crtc_state(state, crtc);
6557 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
6559 if (old_crtc_state->inherited ||
6560 intel_crtc_needs_modeset(new_crtc_state)) {
6562 intel_dpt_configure(crtc);
6565 if (vrr_enabling(old_crtc_state, new_crtc_state)) {
6566 intel_vrr_enable(new_crtc_state);
6567 intel_crtc_update_active_timings(new_crtc_state,
6568 new_crtc_state->vrr.enable);
6572 if (new_crtc_state->preload_luts &&
6573 intel_crtc_needs_color_update(new_crtc_state))
6574 intel_color_load_luts(new_crtc_state);
6576 intel_pre_plane_update(state, crtc);
6578 if (intel_crtc_needs_fastset(new_crtc_state))
6579 intel_encoders_update_pipe(state, crtc);
6581 if (DISPLAY_VER(i915) >= 11 &&
6582 intel_crtc_needs_fastset(new_crtc_state))
6583 icl_set_pipe_chicken(new_crtc_state);
6586 intel_fbc_update(state, crtc);
6588 drm_WARN_ON(&i915->drm, !intel_display_power_is_enabled(i915, POWER_DOMAIN_DC_OFF));
6591 intel_crtc_needs_color_update(new_crtc_state))
6592 intel_color_commit_noarm(new_crtc_state);
6594 intel_crtc_planes_update_noarm(state, crtc);
6596 /* Perform vblank evasion around commit operation */
6597 intel_pipe_update_start(new_crtc_state);
6599 commit_pipe_pre_planes(state, crtc);
6601 intel_crtc_planes_update_arm(state, crtc);
6603 commit_pipe_post_planes(state, crtc);
6605 intel_pipe_update_end(new_crtc_state);
6608 * We usually enable FIFO underrun interrupts as part of the
6609 * CRTC enable sequence during modesets. But when we inherit a
6610 * valid pipe configuration from the BIOS we need to take care
6611 * of enabling them on the CRTC's first fastset.
6613 if (intel_crtc_needs_fastset(new_crtc_state) && !modeset &&
6614 old_crtc_state->inherited)
6615 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
6618 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
6619 struct intel_crtc_state *old_crtc_state,
6620 struct intel_crtc_state *new_crtc_state,
6621 struct intel_crtc *crtc)
6623 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6626 * We need to disable pipe CRC before disabling the pipe,
6627 * or we race against vblank off.
6629 intel_crtc_disable_pipe_crc(crtc);
6631 dev_priv->display.funcs.display->crtc_disable(state, crtc);
6632 crtc->active = false;
6633 intel_fbc_disable(crtc);
6635 if (!new_crtc_state->hw.active)
6636 intel_initial_watermarks(state, crtc);
6639 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
6641 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6642 struct intel_crtc *crtc;
6646 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6647 new_crtc_state, i) {
6648 if (!intel_crtc_needs_modeset(new_crtc_state))
6651 if (!old_crtc_state->hw.active)
6654 intel_pre_plane_update(state, crtc);
6655 intel_crtc_disable_planes(state, crtc);
6658 /* Only disable port sync and MST slaves */
6659 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6660 new_crtc_state, i) {
6661 if (!intel_crtc_needs_modeset(new_crtc_state))
6664 if (!old_crtc_state->hw.active)
6667 /* In case of Transcoder port Sync master slave CRTCs can be
6668 * assigned in any order and we need to make sure that
6669 * slave CRTCs are disabled first and then master CRTC since
6670 * Slave vblanks are masked till Master Vblanks.
6672 if (!is_trans_port_sync_slave(old_crtc_state) &&
6673 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
6674 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
6677 intel_old_crtc_state_disables(state, old_crtc_state,
6678 new_crtc_state, crtc);
6679 handled |= BIT(crtc->pipe);
6682 /* Disable everything else left on */
6683 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6684 new_crtc_state, i) {
6685 if (!intel_crtc_needs_modeset(new_crtc_state) ||
6686 (handled & BIT(crtc->pipe)))
6689 if (!old_crtc_state->hw.active)
6692 intel_old_crtc_state_disables(state, old_crtc_state,
6693 new_crtc_state, crtc);
6697 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
6699 struct intel_crtc_state *new_crtc_state;
6700 struct intel_crtc *crtc;
6703 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6704 if (!new_crtc_state->hw.active)
6707 intel_enable_crtc(state, crtc);
6708 intel_update_crtc(state, crtc);
6712 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
6714 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6715 struct intel_crtc *crtc;
6716 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6717 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6718 u8 update_pipes = 0, modeset_pipes = 0;
6721 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
6722 enum pipe pipe = crtc->pipe;
6724 if (!new_crtc_state->hw.active)
6727 /* ignore allocations for crtc's that have been turned off. */
6728 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6729 entries[pipe] = old_crtc_state->wm.skl.ddb;
6730 update_pipes |= BIT(pipe);
6732 modeset_pipes |= BIT(pipe);
6737 * Whenever the number of active pipes changes, we need to make sure we
6738 * update the pipes in the right order so that their ddb allocations
6739 * never overlap with each other between CRTC updates. Otherwise we'll
6740 * cause pipe underruns and other bad stuff.
6742 * So first lets enable all pipes that do not need a fullmodeset as
6743 * those don't have any external dependency.
6745 while (update_pipes) {
6746 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6747 new_crtc_state, i) {
6748 enum pipe pipe = crtc->pipe;
6750 if ((update_pipes & BIT(pipe)) == 0)
6753 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6754 entries, I915_MAX_PIPES, pipe))
6757 entries[pipe] = new_crtc_state->wm.skl.ddb;
6758 update_pipes &= ~BIT(pipe);
6760 intel_update_crtc(state, crtc);
6763 * If this is an already active pipe, it's DDB changed,
6764 * and this isn't the last pipe that needs updating
6765 * then we need to wait for a vblank to pass for the
6766 * new ddb allocation to take effect.
6768 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
6769 &old_crtc_state->wm.skl.ddb) &&
6770 (update_pipes | modeset_pipes))
6771 intel_crtc_wait_for_next_vblank(crtc);
6775 update_pipes = modeset_pipes;
6778 * Enable all pipes that needs a modeset and do not depends on other
6781 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6782 enum pipe pipe = crtc->pipe;
6784 if ((modeset_pipes & BIT(pipe)) == 0)
6787 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
6788 is_trans_port_sync_master(new_crtc_state) ||
6789 intel_crtc_is_bigjoiner_master(new_crtc_state))
6792 modeset_pipes &= ~BIT(pipe);
6794 intel_enable_crtc(state, crtc);
6798 * Then we enable all remaining pipes that depend on other
6799 * pipes: MST slaves and port sync masters, big joiner master
6801 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6802 enum pipe pipe = crtc->pipe;
6804 if ((modeset_pipes & BIT(pipe)) == 0)
6807 modeset_pipes &= ~BIT(pipe);
6809 intel_enable_crtc(state, crtc);
6813 * Finally we do the plane updates/etc. for all pipes that got enabled.
6815 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6816 enum pipe pipe = crtc->pipe;
6818 if ((update_pipes & BIT(pipe)) == 0)
6821 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
6822 entries, I915_MAX_PIPES, pipe));
6824 entries[pipe] = new_crtc_state->wm.skl.ddb;
6825 update_pipes &= ~BIT(pipe);
6827 intel_update_crtc(state, crtc);
6830 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
6831 drm_WARN_ON(&dev_priv->drm, update_pipes);
6834 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
6836 struct intel_atomic_state *state, *next;
6837 struct llist_node *freed;
6839 freed = llist_del_all(&dev_priv->display.atomic_helper.free_list);
6840 llist_for_each_entry_safe(state, next, freed, freed)
6841 drm_atomic_state_put(&state->base);
6844 void intel_atomic_helper_free_state_worker(struct work_struct *work)
6846 struct drm_i915_private *dev_priv =
6847 container_of(work, typeof(*dev_priv), display.atomic_helper.free_work);
6849 intel_atomic_helper_free_state(dev_priv);
6852 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
6854 struct wait_queue_entry wait_fence, wait_reset;
6855 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
6857 init_wait_entry(&wait_fence, 0);
6858 init_wait_entry(&wait_reset, 0);
6860 prepare_to_wait(&intel_state->commit_ready.wait,
6861 &wait_fence, TASK_UNINTERRUPTIBLE);
6862 prepare_to_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
6863 I915_RESET_MODESET),
6864 &wait_reset, TASK_UNINTERRUPTIBLE);
6867 if (i915_sw_fence_done(&intel_state->commit_ready) ||
6868 test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags))
6873 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
6874 finish_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
6875 I915_RESET_MODESET),
6879 static void intel_atomic_cleanup_work(struct work_struct *work)
6881 struct intel_atomic_state *state =
6882 container_of(work, struct intel_atomic_state, base.commit_work);
6883 struct drm_i915_private *i915 = to_i915(state->base.dev);
6884 struct intel_crtc_state *old_crtc_state;
6885 struct intel_crtc *crtc;
6888 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
6889 intel_color_cleanup_commit(old_crtc_state);
6891 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
6892 drm_atomic_helper_commit_cleanup_done(&state->base);
6893 drm_atomic_state_put(&state->base);
6895 intel_atomic_helper_free_state(i915);
6898 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
6900 struct drm_i915_private *i915 = to_i915(state->base.dev);
6901 struct intel_plane *plane;
6902 struct intel_plane_state *plane_state;
6905 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6906 struct drm_framebuffer *fb = plane_state->hw.fb;
6913 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
6918 * The layout of the fast clear color value expected by HW
6919 * (the DRM ABI requiring this value to be located in fb at
6920 * offset 0 of cc plane, plane #2 previous generations or
6921 * plane #1 for flat ccs):
6922 * - 4 x 4 bytes per-channel value
6923 * (in surface type specific float/int format provided by the fb user)
6924 * - 8 bytes native color value used by the display
6925 * (converted/written by GPU during a fast clear operation using the
6926 * above per-channel values)
6928 * The commit's FB prepare hook already ensured that FB obj is pinned and the
6929 * caller made sure that the object is synced wrt. the related color clear value
6932 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
6933 fb->offsets[cc_plane] + 16,
6934 &plane_state->ccval,
6935 sizeof(plane_state->ccval));
6936 /* The above could only fail if the FB obj has an unexpected backing store type. */
6937 drm_WARN_ON(&i915->drm, ret);
6941 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
6943 struct drm_device *dev = state->base.dev;
6944 struct drm_i915_private *dev_priv = to_i915(dev);
6945 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
6946 struct intel_crtc *crtc;
6947 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
6948 intel_wakeref_t wakeref = 0;
6951 intel_atomic_commit_fence_wait(state);
6953 drm_atomic_helper_wait_for_dependencies(&state->base);
6954 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
6957 * During full modesets we write a lot of registers, wait
6958 * for PLLs, etc. Doing that while DC states are enabled
6959 * is not a good idea.
6961 * During fastsets and other updates we also need to
6962 * disable DC states due to the following scenario:
6963 * 1. DC5 exit and PSR exit happen
6964 * 2. Some or all _noarm() registers are written
6965 * 3. Due to some long delay PSR is re-entered
6966 * 4. DC5 entry -> DMC saves the already written new
6967 * _noarm() registers and the old not yet written
6969 * 5. DC5 exit -> DMC restores a mixture of old and
6970 * new register values and arms the update
6971 * 6. PSR exit -> hardware latches a mixture of old and
6972 * new register values -> corrupted frame, or worse
6973 * 7. New _arm() registers are finally written
6974 * 8. Hardware finally latches a complete set of new
6975 * register values, and subsequent frames will be OK again
6977 * Also note that due to the pipe CSC hardware issues on
6978 * SKL/GLK DC states must remain off until the pipe CSC
6979 * state readout has happened. Otherwise we risk corrupting
6980 * the CSC latched register values with the readout (see
6981 * skl_read_csc() and skl_color_commit_noarm()).
6983 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DC_OFF);
6985 intel_atomic_prepare_plane_clear_colors(state);
6987 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6988 new_crtc_state, i) {
6989 if (intel_crtc_needs_modeset(new_crtc_state) ||
6990 intel_crtc_needs_fastset(new_crtc_state))
6991 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
6994 intel_commit_modeset_disables(state);
6996 /* FIXME: Eventually get rid of our crtc->config pointer */
6997 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
6998 crtc->config = new_crtc_state;
7000 if (state->modeset) {
7001 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7003 intel_set_cdclk_pre_plane_update(state);
7005 intel_modeset_verify_disabled(dev_priv, state);
7008 intel_sagv_pre_plane_update(state);
7010 /* Complete the events for pipes that have now been disabled */
7011 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7012 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7014 /* Complete events for now disable pipes here. */
7015 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7016 spin_lock_irq(&dev->event_lock);
7017 drm_crtc_send_vblank_event(&crtc->base,
7018 new_crtc_state->uapi.event);
7019 spin_unlock_irq(&dev->event_lock);
7021 new_crtc_state->uapi.event = NULL;
7025 intel_encoders_update_prepare(state);
7027 intel_dbuf_pre_plane_update(state);
7028 intel_mbus_dbox_update(state);
7030 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7031 if (new_crtc_state->do_async_flip)
7032 intel_crtc_enable_flip_done(state, crtc);
7035 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7036 dev_priv->display.funcs.display->commit_modeset_enables(state);
7039 intel_set_cdclk_post_plane_update(state);
7041 intel_wait_for_vblank_workers(state);
7043 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7044 * already, but still need the state for the delayed optimization. To
7046 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7047 * - schedule that vblank worker _before_ calling hw_done
7048 * - at the start of commit_tail, cancel it _synchrously
7049 * - switch over to the vblank wait helper in the core after that since
7050 * we don't need out special handling any more.
7052 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7054 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7055 if (new_crtc_state->do_async_flip)
7056 intel_crtc_disable_flip_done(state, crtc);
7060 * Now that the vblank has passed, we can go ahead and program the
7061 * optimal watermarks on platforms that need two-step watermark
7064 * TODO: Move this (and other cleanup) to an async worker eventually.
7066 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7067 new_crtc_state, i) {
7069 * Gen2 reports pipe underruns whenever all planes are disabled.
7070 * So re-enable underrun reporting after some planes get enabled.
7072 * We do this before .optimize_watermarks() so that we have a
7073 * chance of catching underruns with the intermediate watermarks
7074 * vs. the new plane configuration.
7076 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7077 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7079 intel_optimize_watermarks(state, crtc);
7082 intel_dbuf_post_plane_update(state);
7083 intel_psr_post_plane_update(state);
7085 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7086 intel_post_plane_update(state, crtc);
7088 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7090 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
7092 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
7093 hsw_ips_post_update(state, crtc);
7096 * Activate DRRS after state readout to avoid
7097 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
7099 intel_drrs_activate(new_crtc_state);
7102 * DSB cleanup is done in cleanup_work aligning with framebuffer
7103 * cleanup. So copy and reset the dsb structure to sync with
7104 * commit_done and later do dsb cleanup in cleanup_work.
7106 * FIXME get rid of this funny new->old swapping
7108 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7111 /* Underruns don't always raise interrupts, so check manually */
7112 intel_check_cpu_fifo_underruns(dev_priv);
7113 intel_check_pch_fifo_underruns(dev_priv);
7116 intel_verify_planes(state);
7118 intel_sagv_post_plane_update(state);
7120 drm_atomic_helper_commit_hw_done(&state->base);
7122 if (state->modeset) {
7123 /* As one of the primary mmio accessors, KMS has a high
7124 * likelihood of triggering bugs in unclaimed access. After we
7125 * finish modesetting, see if an error has been flagged, and if
7126 * so enable debugging for the next modeset - and hope we catch
7129 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7131 intel_display_power_put(dev_priv, POWER_DOMAIN_DC_OFF, wakeref);
7132 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7135 * Defer the cleanup of the old state to a separate worker to not
7136 * impede the current task (userspace for blocking modesets) that
7137 * are executed inline. For out-of-line asynchronous modesets/flips,
7138 * deferring to a new worker seems overkill, but we would place a
7139 * schedule point (cond_resched()) here anyway to keep latencies
7142 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7143 queue_work(system_highpri_wq, &state->base.commit_work);
7146 static void intel_atomic_commit_work(struct work_struct *work)
7148 struct intel_atomic_state *state =
7149 container_of(work, struct intel_atomic_state, base.commit_work);
7151 intel_atomic_commit_tail(state);
7155 intel_atomic_commit_ready(struct i915_sw_fence *fence,
7156 enum i915_sw_fence_notify notify)
7158 struct intel_atomic_state *state =
7159 container_of(fence, struct intel_atomic_state, commit_ready);
7162 case FENCE_COMPLETE:
7163 /* we do blocking waits in the worker, nothing to do here */
7167 struct intel_atomic_helper *helper =
7168 &to_i915(state->base.dev)->display.atomic_helper;
7170 if (llist_add(&state->freed, &helper->free_list))
7171 schedule_work(&helper->free_work);
7179 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7181 struct intel_plane_state *old_plane_state, *new_plane_state;
7182 struct intel_plane *plane;
7185 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7187 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7188 to_intel_frontbuffer(new_plane_state->hw.fb),
7189 plane->frontbuffer_bit);
7192 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7195 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7196 struct drm_i915_private *dev_priv = to_i915(dev);
7199 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7201 drm_atomic_state_get(&state->base);
7202 i915_sw_fence_init(&state->commit_ready,
7203 intel_atomic_commit_ready);
7206 * The intel_legacy_cursor_update() fast path takes care
7207 * of avoiding the vblank waits for simple cursor
7208 * movement and flips. For cursor on/off and size changes,
7209 * we want to perform the vblank waits so that watermark
7210 * updates happen during the correct frames. Gen9+ have
7211 * double buffered watermarks and so shouldn't need this.
7213 * Unset state->legacy_cursor_update before the call to
7214 * drm_atomic_helper_setup_commit() because otherwise
7215 * drm_atomic_helper_wait_for_flip_done() is a noop and
7216 * we get FIFO underruns because we didn't wait
7219 * FIXME doing watermarks and fb cleanup from a vblank worker
7220 * (assuming we had any) would solve these problems.
7222 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7223 struct intel_crtc_state *new_crtc_state;
7224 struct intel_crtc *crtc;
7227 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7228 if (new_crtc_state->wm.need_postvbl_update ||
7229 new_crtc_state->update_wm_post)
7230 state->base.legacy_cursor_update = false;
7233 ret = intel_atomic_prepare_commit(state);
7235 drm_dbg_atomic(&dev_priv->drm,
7236 "Preparing state failed with %i\n", ret);
7237 i915_sw_fence_commit(&state->commit_ready);
7238 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7242 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7244 ret = drm_atomic_helper_swap_state(&state->base, true);
7246 intel_atomic_swap_global_state(state);
7249 struct intel_crtc_state *new_crtc_state;
7250 struct intel_crtc *crtc;
7253 i915_sw_fence_commit(&state->commit_ready);
7255 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7256 intel_color_cleanup_commit(new_crtc_state);
7258 drm_atomic_helper_cleanup_planes(dev, &state->base);
7259 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7262 intel_shared_dpll_swap_state(state);
7263 intel_atomic_track_fbs(state);
7265 drm_atomic_state_get(&state->base);
7266 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7268 i915_sw_fence_commit(&state->commit_ready);
7269 if (nonblock && state->modeset) {
7270 queue_work(dev_priv->display.wq.modeset, &state->base.commit_work);
7271 } else if (nonblock) {
7272 queue_work(dev_priv->display.wq.flip, &state->base.commit_work);
7275 flush_workqueue(dev_priv->display.wq.modeset);
7276 intel_atomic_commit_tail(state);
7283 * intel_plane_destroy - destroy a plane
7284 * @plane: plane to destroy
7286 * Common destruction function for all types of planes (primary, cursor,
7289 void intel_plane_destroy(struct drm_plane *plane)
7291 drm_plane_cleanup(plane);
7292 kfree(to_intel_plane(plane));
7295 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7296 struct drm_file *file)
7298 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7299 struct drm_crtc *drmmode_crtc;
7300 struct intel_crtc *crtc;
7302 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7306 crtc = to_intel_crtc(drmmode_crtc);
7307 pipe_from_crtc_id->pipe = crtc->pipe;
7312 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7314 struct drm_device *dev = encoder->base.dev;
7315 struct intel_encoder *source_encoder;
7316 u32 possible_clones = 0;
7318 for_each_intel_encoder(dev, source_encoder) {
7319 if (encoders_cloneable(encoder, source_encoder))
7320 possible_clones |= drm_encoder_mask(&source_encoder->base);
7323 return possible_clones;
7326 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7328 struct drm_device *dev = encoder->base.dev;
7329 struct intel_crtc *crtc;
7330 u32 possible_crtcs = 0;
7332 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7333 possible_crtcs |= drm_crtc_mask(&crtc->base);
7335 return possible_crtcs;
7338 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7340 if (!IS_MOBILE(dev_priv))
7343 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7346 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7352 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7354 if (DISPLAY_VER(dev_priv) >= 9)
7357 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
7360 if (HAS_PCH_LPT_H(dev_priv) &&
7361 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7364 /* DDI E can't be used if DDI A requires 4 lanes */
7365 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7368 if (!dev_priv->display.vbt.int_crt_support)
7374 void intel_setup_outputs(struct drm_i915_private *dev_priv)
7376 struct intel_encoder *encoder;
7377 bool dpd_is_edp = false;
7379 intel_pps_unlock_regs_wa(dev_priv);
7381 if (!HAS_DISPLAY(dev_priv))
7384 if (IS_METEORLAKE(dev_priv)) {
7385 intel_ddi_init(dev_priv, PORT_A);
7386 intel_ddi_init(dev_priv, PORT_B);
7387 intel_ddi_init(dev_priv, PORT_TC1);
7388 intel_ddi_init(dev_priv, PORT_TC2);
7389 intel_ddi_init(dev_priv, PORT_TC3);
7390 intel_ddi_init(dev_priv, PORT_TC4);
7391 } else if (IS_DG2(dev_priv)) {
7392 intel_ddi_init(dev_priv, PORT_A);
7393 intel_ddi_init(dev_priv, PORT_B);
7394 intel_ddi_init(dev_priv, PORT_C);
7395 intel_ddi_init(dev_priv, PORT_D_XELPD);
7396 intel_ddi_init(dev_priv, PORT_TC1);
7397 } else if (IS_ALDERLAKE_P(dev_priv)) {
7398 intel_ddi_init(dev_priv, PORT_A);
7399 intel_ddi_init(dev_priv, PORT_B);
7400 intel_ddi_init(dev_priv, PORT_TC1);
7401 intel_ddi_init(dev_priv, PORT_TC2);
7402 intel_ddi_init(dev_priv, PORT_TC3);
7403 intel_ddi_init(dev_priv, PORT_TC4);
7404 icl_dsi_init(dev_priv);
7405 } else if (IS_ALDERLAKE_S(dev_priv)) {
7406 intel_ddi_init(dev_priv, PORT_A);
7407 intel_ddi_init(dev_priv, PORT_TC1);
7408 intel_ddi_init(dev_priv, PORT_TC2);
7409 intel_ddi_init(dev_priv, PORT_TC3);
7410 intel_ddi_init(dev_priv, PORT_TC4);
7411 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
7412 intel_ddi_init(dev_priv, PORT_A);
7413 intel_ddi_init(dev_priv, PORT_B);
7414 intel_ddi_init(dev_priv, PORT_TC1);
7415 intel_ddi_init(dev_priv, PORT_TC2);
7416 } else if (DISPLAY_VER(dev_priv) >= 12) {
7417 intel_ddi_init(dev_priv, PORT_A);
7418 intel_ddi_init(dev_priv, PORT_B);
7419 intel_ddi_init(dev_priv, PORT_TC1);
7420 intel_ddi_init(dev_priv, PORT_TC2);
7421 intel_ddi_init(dev_priv, PORT_TC3);
7422 intel_ddi_init(dev_priv, PORT_TC4);
7423 intel_ddi_init(dev_priv, PORT_TC5);
7424 intel_ddi_init(dev_priv, PORT_TC6);
7425 icl_dsi_init(dev_priv);
7426 } else if (IS_JSL_EHL(dev_priv)) {
7427 intel_ddi_init(dev_priv, PORT_A);
7428 intel_ddi_init(dev_priv, PORT_B);
7429 intel_ddi_init(dev_priv, PORT_C);
7430 intel_ddi_init(dev_priv, PORT_D);
7431 icl_dsi_init(dev_priv);
7432 } else if (DISPLAY_VER(dev_priv) == 11) {
7433 intel_ddi_init(dev_priv, PORT_A);
7434 intel_ddi_init(dev_priv, PORT_B);
7435 intel_ddi_init(dev_priv, PORT_C);
7436 intel_ddi_init(dev_priv, PORT_D);
7437 intel_ddi_init(dev_priv, PORT_E);
7438 intel_ddi_init(dev_priv, PORT_F);
7439 icl_dsi_init(dev_priv);
7440 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
7441 intel_ddi_init(dev_priv, PORT_A);
7442 intel_ddi_init(dev_priv, PORT_B);
7443 intel_ddi_init(dev_priv, PORT_C);
7444 vlv_dsi_init(dev_priv);
7445 } else if (DISPLAY_VER(dev_priv) >= 9) {
7446 intel_ddi_init(dev_priv, PORT_A);
7447 intel_ddi_init(dev_priv, PORT_B);
7448 intel_ddi_init(dev_priv, PORT_C);
7449 intel_ddi_init(dev_priv, PORT_D);
7450 intel_ddi_init(dev_priv, PORT_E);
7451 } else if (HAS_DDI(dev_priv)) {
7454 if (intel_ddi_crt_present(dev_priv))
7455 intel_crt_init(dev_priv);
7457 /* Haswell uses DDI functions to detect digital outputs. */
7458 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
7460 intel_ddi_init(dev_priv, PORT_A);
7462 found = intel_de_read(dev_priv, SFUSE_STRAP);
7463 if (found & SFUSE_STRAP_DDIB_DETECTED)
7464 intel_ddi_init(dev_priv, PORT_B);
7465 if (found & SFUSE_STRAP_DDIC_DETECTED)
7466 intel_ddi_init(dev_priv, PORT_C);
7467 if (found & SFUSE_STRAP_DDID_DETECTED)
7468 intel_ddi_init(dev_priv, PORT_D);
7469 if (found & SFUSE_STRAP_DDIF_DETECTED)
7470 intel_ddi_init(dev_priv, PORT_F);
7471 } else if (HAS_PCH_SPLIT(dev_priv)) {
7475 * intel_edp_init_connector() depends on this completing first,
7476 * to prevent the registration of both eDP and LVDS and the
7477 * incorrect sharing of the PPS.
7479 intel_lvds_init(dev_priv);
7480 intel_crt_init(dev_priv);
7482 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
7484 if (ilk_has_edp_a(dev_priv))
7485 g4x_dp_init(dev_priv, DP_A, PORT_A);
7487 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
7488 /* PCH SDVOB multiplex with HDMIB */
7489 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
7491 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
7492 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
7493 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
7496 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
7497 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
7499 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
7500 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
7502 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
7503 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
7505 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
7506 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
7507 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7508 bool has_edp, has_port;
7510 if (IS_VALLEYVIEW(dev_priv) && dev_priv->display.vbt.int_crt_support)
7511 intel_crt_init(dev_priv);
7514 * The DP_DETECTED bit is the latched state of the DDC
7515 * SDA pin at boot. However since eDP doesn't require DDC
7516 * (no way to plug in a DP->HDMI dongle) the DDC pins for
7517 * eDP ports may have been muxed to an alternate function.
7518 * Thus we can't rely on the DP_DETECTED bit alone to detect
7519 * eDP ports. Consult the VBT as well as DP_DETECTED to
7522 * Sadly the straps seem to be missing sometimes even for HDMI
7523 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
7524 * and VBT for the presence of the port. Additionally we can't
7525 * trust the port type the VBT declares as we've seen at least
7526 * HDMI ports that the VBT claim are DP or eDP.
7528 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
7529 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
7530 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
7531 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
7532 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
7533 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
7535 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
7536 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
7537 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
7538 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
7539 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
7540 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
7542 if (IS_CHERRYVIEW(dev_priv)) {
7544 * eDP not supported on port D,
7545 * so no need to worry about it
7547 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
7548 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
7549 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
7550 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
7551 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
7554 vlv_dsi_init(dev_priv);
7555 } else if (IS_PINEVIEW(dev_priv)) {
7556 intel_lvds_init(dev_priv);
7557 intel_crt_init(dev_priv);
7558 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
7561 if (IS_MOBILE(dev_priv))
7562 intel_lvds_init(dev_priv);
7564 intel_crt_init(dev_priv);
7566 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7567 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
7568 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
7569 if (!found && IS_G4X(dev_priv)) {
7570 drm_dbg_kms(&dev_priv->drm,
7571 "probing HDMI on SDVOB\n");
7572 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
7575 if (!found && IS_G4X(dev_priv))
7576 g4x_dp_init(dev_priv, DP_B, PORT_B);
7579 /* Before G4X SDVOC doesn't have its own detect register */
7581 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
7582 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
7583 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
7586 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
7588 if (IS_G4X(dev_priv)) {
7589 drm_dbg_kms(&dev_priv->drm,
7590 "probing HDMI on SDVOC\n");
7591 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
7593 if (IS_G4X(dev_priv))
7594 g4x_dp_init(dev_priv, DP_C, PORT_C);
7597 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
7598 g4x_dp_init(dev_priv, DP_D, PORT_D);
7600 if (SUPPORTS_TV(dev_priv))
7601 intel_tv_init(dev_priv);
7602 } else if (DISPLAY_VER(dev_priv) == 2) {
7603 if (IS_I85X(dev_priv))
7604 intel_lvds_init(dev_priv);
7606 intel_crt_init(dev_priv);
7607 intel_dvo_init(dev_priv);
7610 for_each_intel_encoder(&dev_priv->drm, encoder) {
7611 encoder->base.possible_crtcs =
7612 intel_encoder_possible_crtcs(encoder);
7613 encoder->base.possible_clones =
7614 intel_encoder_possible_clones(encoder);
7617 intel_init_pch_refclk(dev_priv);
7619 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
7622 static int max_dotclock(struct drm_i915_private *i915)
7624 int max_dotclock = i915->max_dotclk_freq;
7626 /* icl+ might use bigjoiner */
7627 if (DISPLAY_VER(i915) >= 11)
7630 return max_dotclock;
7633 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
7634 const struct drm_display_mode *mode)
7636 struct drm_i915_private *dev_priv = to_i915(dev);
7637 int hdisplay_max, htotal_max;
7638 int vdisplay_max, vtotal_max;
7641 * Can't reject DBLSCAN here because Xorg ddxen can add piles
7642 * of DBLSCAN modes to the output's mode list when they detect
7643 * the scaling mode property on the connector. And they don't
7644 * ask the kernel to validate those modes in any way until
7645 * modeset time at which point the client gets a protocol error.
7646 * So in order to not upset those clients we silently ignore the
7647 * DBLSCAN flag on such connectors. For other connectors we will
7648 * reject modes with the DBLSCAN flag in encoder->compute_config().
7649 * And we always reject DBLSCAN modes in connector->mode_valid()
7650 * as we never want such modes on the connector's mode list.
7653 if (mode->vscan > 1)
7654 return MODE_NO_VSCAN;
7656 if (mode->flags & DRM_MODE_FLAG_HSKEW)
7657 return MODE_H_ILLEGAL;
7659 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
7660 DRM_MODE_FLAG_NCSYNC |
7661 DRM_MODE_FLAG_PCSYNC))
7664 if (mode->flags & (DRM_MODE_FLAG_BCAST |
7665 DRM_MODE_FLAG_PIXMUX |
7666 DRM_MODE_FLAG_CLKDIV2))
7670 * Reject clearly excessive dotclocks early to
7671 * avoid having to worry about huge integers later.
7673 if (mode->clock > max_dotclock(dev_priv))
7674 return MODE_CLOCK_HIGH;
7676 /* Transcoder timing limits */
7677 if (DISPLAY_VER(dev_priv) >= 11) {
7678 hdisplay_max = 16384;
7679 vdisplay_max = 8192;
7682 } else if (DISPLAY_VER(dev_priv) >= 9 ||
7683 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
7684 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
7685 vdisplay_max = 4096;
7688 } else if (DISPLAY_VER(dev_priv) >= 3) {
7689 hdisplay_max = 4096;
7690 vdisplay_max = 4096;
7694 hdisplay_max = 2048;
7695 vdisplay_max = 2048;
7700 if (mode->hdisplay > hdisplay_max ||
7701 mode->hsync_start > htotal_max ||
7702 mode->hsync_end > htotal_max ||
7703 mode->htotal > htotal_max)
7704 return MODE_H_ILLEGAL;
7706 if (mode->vdisplay > vdisplay_max ||
7707 mode->vsync_start > vtotal_max ||
7708 mode->vsync_end > vtotal_max ||
7709 mode->vtotal > vtotal_max)
7710 return MODE_V_ILLEGAL;
7712 if (DISPLAY_VER(dev_priv) >= 5) {
7713 if (mode->hdisplay < 64 ||
7714 mode->htotal - mode->hdisplay < 32)
7715 return MODE_H_ILLEGAL;
7717 if (mode->vtotal - mode->vdisplay < 5)
7718 return MODE_V_ILLEGAL;
7720 if (mode->htotal - mode->hdisplay < 32)
7721 return MODE_H_ILLEGAL;
7723 if (mode->vtotal - mode->vdisplay < 3)
7724 return MODE_V_ILLEGAL;
7728 * Cantiga+ cannot handle modes with a hsync front porch of 0.
7729 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
7731 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
7732 mode->hsync_start == mode->hdisplay)
7733 return MODE_H_ILLEGAL;
7738 enum drm_mode_status
7739 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
7740 const struct drm_display_mode *mode,
7743 int plane_width_max, plane_height_max;
7746 * intel_mode_valid() should be
7747 * sufficient on older platforms.
7749 if (DISPLAY_VER(dev_priv) < 9)
7753 * Most people will probably want a fullscreen
7754 * plane so let's not advertize modes that are
7757 if (DISPLAY_VER(dev_priv) >= 11) {
7758 plane_width_max = 5120 << bigjoiner;
7759 plane_height_max = 4320;
7761 plane_width_max = 5120;
7762 plane_height_max = 4096;
7765 if (mode->hdisplay > plane_width_max)
7766 return MODE_H_ILLEGAL;
7768 if (mode->vdisplay > plane_height_max)
7769 return MODE_V_ILLEGAL;
7774 static const struct intel_display_funcs skl_display_funcs = {
7775 .get_pipe_config = hsw_get_pipe_config,
7776 .crtc_enable = hsw_crtc_enable,
7777 .crtc_disable = hsw_crtc_disable,
7778 .commit_modeset_enables = skl_commit_modeset_enables,
7779 .get_initial_plane_config = skl_get_initial_plane_config,
7782 static const struct intel_display_funcs ddi_display_funcs = {
7783 .get_pipe_config = hsw_get_pipe_config,
7784 .crtc_enable = hsw_crtc_enable,
7785 .crtc_disable = hsw_crtc_disable,
7786 .commit_modeset_enables = intel_commit_modeset_enables,
7787 .get_initial_plane_config = i9xx_get_initial_plane_config,
7790 static const struct intel_display_funcs pch_split_display_funcs = {
7791 .get_pipe_config = ilk_get_pipe_config,
7792 .crtc_enable = ilk_crtc_enable,
7793 .crtc_disable = ilk_crtc_disable,
7794 .commit_modeset_enables = intel_commit_modeset_enables,
7795 .get_initial_plane_config = i9xx_get_initial_plane_config,
7798 static const struct intel_display_funcs vlv_display_funcs = {
7799 .get_pipe_config = i9xx_get_pipe_config,
7800 .crtc_enable = valleyview_crtc_enable,
7801 .crtc_disable = i9xx_crtc_disable,
7802 .commit_modeset_enables = intel_commit_modeset_enables,
7803 .get_initial_plane_config = i9xx_get_initial_plane_config,
7806 static const struct intel_display_funcs i9xx_display_funcs = {
7807 .get_pipe_config = i9xx_get_pipe_config,
7808 .crtc_enable = i9xx_crtc_enable,
7809 .crtc_disable = i9xx_crtc_disable,
7810 .commit_modeset_enables = intel_commit_modeset_enables,
7811 .get_initial_plane_config = i9xx_get_initial_plane_config,
7815 * intel_init_display_hooks - initialize the display modesetting hooks
7816 * @dev_priv: device private
7818 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
7820 if (DISPLAY_VER(dev_priv) >= 9) {
7821 dev_priv->display.funcs.display = &skl_display_funcs;
7822 } else if (HAS_DDI(dev_priv)) {
7823 dev_priv->display.funcs.display = &ddi_display_funcs;
7824 } else if (HAS_PCH_SPLIT(dev_priv)) {
7825 dev_priv->display.funcs.display = &pch_split_display_funcs;
7826 } else if (IS_CHERRYVIEW(dev_priv) ||
7827 IS_VALLEYVIEW(dev_priv)) {
7828 dev_priv->display.funcs.display = &vlv_display_funcs;
7830 dev_priv->display.funcs.display = &i9xx_display_funcs;
7834 int intel_initial_commit(struct drm_device *dev)
7836 struct drm_atomic_state *state = NULL;
7837 struct drm_modeset_acquire_ctx ctx;
7838 struct intel_crtc *crtc;
7841 state = drm_atomic_state_alloc(dev);
7845 drm_modeset_acquire_init(&ctx, 0);
7847 state->acquire_ctx = &ctx;
7848 to_intel_atomic_state(state)->internal = true;
7851 for_each_intel_crtc(dev, crtc) {
7852 struct intel_crtc_state *crtc_state =
7853 intel_atomic_get_crtc_state(state, crtc);
7855 if (IS_ERR(crtc_state)) {
7856 ret = PTR_ERR(crtc_state);
7860 if (crtc_state->hw.active) {
7861 struct intel_encoder *encoder;
7863 ret = drm_atomic_add_affected_planes(state, &crtc->base);
7868 * FIXME hack to force a LUT update to avoid the
7869 * plane update forcing the pipe gamma on without
7870 * having a proper LUT loaded. Remove once we
7871 * have readout for pipe gamma enable.
7873 crtc_state->uapi.color_mgmt_changed = true;
7875 for_each_intel_encoder_mask(dev, encoder,
7876 crtc_state->uapi.encoder_mask) {
7877 if (encoder->initial_fastset_check &&
7878 !encoder->initial_fastset_check(encoder, crtc_state)) {
7879 ret = drm_atomic_add_affected_connectors(state,
7888 ret = drm_atomic_commit(state);
7891 if (ret == -EDEADLK) {
7892 drm_atomic_state_clear(state);
7893 drm_modeset_backoff(&ctx);
7897 drm_atomic_state_put(state);
7899 drm_modeset_drop_locks(&ctx);
7900 drm_modeset_acquire_fini(&ctx);
7905 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
7907 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
7908 enum transcoder cpu_transcoder = (enum transcoder)pipe;
7909 /* 640x480@60Hz, ~25175 kHz */
7910 struct dpll clock = {
7920 drm_WARN_ON(&dev_priv->drm,
7921 i9xx_calc_dpll_params(48000, &clock) != 25154);
7923 drm_dbg_kms(&dev_priv->drm,
7924 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
7925 pipe_name(pipe), clock.vco, clock.dot);
7927 fp = i9xx_dpll_compute_fp(&clock);
7928 dpll = DPLL_DVO_2X_MODE |
7930 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
7931 PLL_P2_DIVIDE_BY_4 |
7932 PLL_REF_INPUT_DREFCLK |
7935 intel_de_write(dev_priv, TRANS_HTOTAL(cpu_transcoder),
7936 HACTIVE(640 - 1) | HTOTAL(800 - 1));
7937 intel_de_write(dev_priv, TRANS_HBLANK(cpu_transcoder),
7938 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
7939 intel_de_write(dev_priv, TRANS_HSYNC(cpu_transcoder),
7940 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
7941 intel_de_write(dev_priv, TRANS_VTOTAL(cpu_transcoder),
7942 VACTIVE(480 - 1) | VTOTAL(525 - 1));
7943 intel_de_write(dev_priv, TRANS_VBLANK(cpu_transcoder),
7944 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
7945 intel_de_write(dev_priv, TRANS_VSYNC(cpu_transcoder),
7946 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
7947 intel_de_write(dev_priv, PIPESRC(pipe),
7948 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
7950 intel_de_write(dev_priv, FP0(pipe), fp);
7951 intel_de_write(dev_priv, FP1(pipe), fp);
7954 * Apparently we need to have VGA mode enabled prior to changing
7955 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
7956 * dividers, even though the register value does change.
7958 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
7959 intel_de_write(dev_priv, DPLL(pipe), dpll);
7961 /* Wait for the clocks to stabilize. */
7962 intel_de_posting_read(dev_priv, DPLL(pipe));
7965 /* The pixel multiplier can only be updated once the
7966 * DPLL is enabled and the clocks are stable.
7968 * So write it again.
7970 intel_de_write(dev_priv, DPLL(pipe), dpll);
7972 /* We do this three times for luck */
7973 for (i = 0; i < 3 ; i++) {
7974 intel_de_write(dev_priv, DPLL(pipe), dpll);
7975 intel_de_posting_read(dev_priv, DPLL(pipe));
7976 udelay(150); /* wait for warmup */
7979 intel_de_write(dev_priv, TRANSCONF(pipe), TRANSCONF_ENABLE);
7980 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
7982 intel_wait_for_pipe_scanline_moving(crtc);
7985 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
7987 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
7989 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
7992 drm_WARN_ON(&dev_priv->drm,
7993 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
7994 drm_WARN_ON(&dev_priv->drm,
7995 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
7996 drm_WARN_ON(&dev_priv->drm,
7997 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
7998 drm_WARN_ON(&dev_priv->drm,
7999 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
8000 drm_WARN_ON(&dev_priv->drm,
8001 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
8003 intel_de_write(dev_priv, TRANSCONF(pipe), 0);
8004 intel_de_posting_read(dev_priv, TRANSCONF(pipe));
8006 intel_wait_for_pipe_scanline_stopped(crtc);
8008 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
8009 intel_de_posting_read(dev_priv, DPLL(pipe));
8012 void intel_hpd_poll_fini(struct drm_i915_private *i915)
8014 struct intel_connector *connector;
8015 struct drm_connector_list_iter conn_iter;
8017 /* Kill all the work that may have been queued by hpd. */
8018 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8019 for_each_intel_connector_iter(connector, &conn_iter) {
8020 if (connector->modeset_retry_work.func)
8021 cancel_work_sync(&connector->modeset_retry_work);
8022 if (connector->hdcp.shim) {
8023 cancel_delayed_work_sync(&connector->hdcp.check_work);
8024 cancel_work_sync(&connector->hdcp.prop_work);
8027 drm_connector_list_iter_end(&conn_iter);
8030 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
8032 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);