2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 #include <acpi/video.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/dma-resv.h>
33 #include <linux/slab.h>
34 #include <linux/string_helpers.h>
35 #include <linux/vga_switcheroo.h>
37 #include <drm/display/drm_dp_helper.h>
38 #include <drm/drm_atomic.h>
39 #include <drm/drm_atomic_helper.h>
40 #include <drm/drm_atomic_uapi.h>
41 #include <drm/drm_damage_helper.h>
42 #include <drm/drm_edid.h>
43 #include <drm/drm_fourcc.h>
44 #include <drm/drm_plane_helper.h>
45 #include <drm/drm_privacy_screen_consumer.h>
46 #include <drm/drm_probe_helper.h>
47 #include <drm/drm_rect.h>
49 #include "display/intel_audio.h"
50 #include "display/intel_crt.h"
51 #include "display/intel_ddi.h"
52 #include "display/intel_display_debugfs.h"
53 #include "display/intel_display_power.h"
54 #include "display/intel_dp.h"
55 #include "display/intel_dp_mst.h"
56 #include "display/intel_dpll.h"
57 #include "display/intel_dpll_mgr.h"
58 #include "display/intel_drrs.h"
59 #include "display/intel_dsi.h"
60 #include "display/intel_dvo.h"
61 #include "display/intel_fb.h"
62 #include "display/intel_gmbus.h"
63 #include "display/intel_hdmi.h"
64 #include "display/intel_lvds.h"
65 #include "display/intel_sdvo.h"
66 #include "display/intel_snps_phy.h"
67 #include "display/intel_tv.h"
68 #include "display/intel_vdsc.h"
69 #include "display/intel_vrr.h"
71 #include "gem/i915_gem_lmem.h"
72 #include "gem/i915_gem_object.h"
74 #include "gt/gen8_ppgtt.h"
80 #include "i915_utils.h"
82 #include "intel_acpi.h"
83 #include "intel_atomic.h"
84 #include "intel_atomic_plane.h"
86 #include "intel_cdclk.h"
87 #include "intel_color.h"
88 #include "intel_crtc.h"
89 #include "intel_crtc_state_dump.h"
91 #include "intel_display_types.h"
92 #include "intel_dmc.h"
93 #include "intel_dp_link_training.h"
94 #include "intel_dpt.h"
95 #include "intel_fbc.h"
96 #include "intel_fbdev.h"
97 #include "intel_fdi.h"
98 #include "intel_fifo_underrun.h"
99 #include "intel_frontbuffer.h"
100 #include "intel_hdcp.h"
101 #include "intel_hotplug.h"
102 #include "intel_modeset_verify.h"
103 #include "intel_modeset_setup.h"
104 #include "intel_overlay.h"
105 #include "intel_panel.h"
106 #include "intel_pch_display.h"
107 #include "intel_pch_refclk.h"
108 #include "intel_pcode.h"
109 #include "intel_pipe_crc.h"
110 #include "intel_plane_initial.h"
111 #include "intel_pm.h"
112 #include "intel_pps.h"
113 #include "intel_psr.h"
114 #include "intel_quirks.h"
115 #include "intel_sprite.h"
116 #include "intel_tc.h"
117 #include "intel_vga.h"
118 #include "i9xx_plane.h"
119 #include "skl_scaler.h"
120 #include "skl_universal_plane.h"
122 #include "vlv_dsi_pll.h"
123 #include "vlv_dsi_regs.h"
124 #include "vlv_sideband.h"
126 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
127 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
128 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
129 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state);
130 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state);
133 * intel_update_watermarks - update FIFO watermark values based on current modes
134 * @dev_priv: i915 device
136 * Calculate watermark values for the various WM regs based on current mode
137 * and plane configuration.
139 * There are several cases to deal with here:
140 * - normal (i.e. non-self-refresh)
141 * - self-refresh (SR) mode
142 * - lines are large relative to FIFO size (buffer can hold up to 2)
143 * - lines are small relative to FIFO size (buffer can hold more than 2
144 * lines), so need to account for TLB latency
146 * The normal calculation is:
147 * watermark = dotclock * bytes per pixel * latency
148 * where latency is platform & configuration dependent (we assume pessimal
151 * The SR calculation is:
152 * watermark = (trunc(latency/line time)+1) * surface width *
155 * line time = htotal / dotclock
156 * surface width = hdisplay for normal plane and 64 for cursor
157 * and latency is assumed to be high, as above.
159 * The final value programmed to the register should always be rounded up,
160 * and include an extra 2 entries to account for clock crossings.
162 * We don't use the sprite, so we can ignore that. And on Crestline we have
163 * to set the non-SR watermarks to 8.
165 void intel_update_watermarks(struct drm_i915_private *dev_priv)
167 if (dev_priv->display.funcs.wm->update_wm)
168 dev_priv->display.funcs.wm->update_wm(dev_priv);
171 static int intel_compute_pipe_wm(struct intel_atomic_state *state,
172 struct intel_crtc *crtc)
174 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
175 if (dev_priv->display.funcs.wm->compute_pipe_wm)
176 return dev_priv->display.funcs.wm->compute_pipe_wm(state, crtc);
180 static int intel_compute_intermediate_wm(struct intel_atomic_state *state,
181 struct intel_crtc *crtc)
183 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
184 if (!dev_priv->display.funcs.wm->compute_intermediate_wm)
186 if (drm_WARN_ON(&dev_priv->drm,
187 !dev_priv->display.funcs.wm->compute_pipe_wm))
189 return dev_priv->display.funcs.wm->compute_intermediate_wm(state, crtc);
192 static bool intel_initial_watermarks(struct intel_atomic_state *state,
193 struct intel_crtc *crtc)
195 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
196 if (dev_priv->display.funcs.wm->initial_watermarks) {
197 dev_priv->display.funcs.wm->initial_watermarks(state, crtc);
203 static void intel_atomic_update_watermarks(struct intel_atomic_state *state,
204 struct intel_crtc *crtc)
206 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
207 if (dev_priv->display.funcs.wm->atomic_update_watermarks)
208 dev_priv->display.funcs.wm->atomic_update_watermarks(state, crtc);
211 static void intel_optimize_watermarks(struct intel_atomic_state *state,
212 struct intel_crtc *crtc)
214 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
215 if (dev_priv->display.funcs.wm->optimize_watermarks)
216 dev_priv->display.funcs.wm->optimize_watermarks(state, crtc);
219 static int intel_compute_global_watermarks(struct intel_atomic_state *state)
221 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
222 if (dev_priv->display.funcs.wm->compute_global_watermarks)
223 return dev_priv->display.funcs.wm->compute_global_watermarks(state);
227 /* returns HPLL frequency in kHz */
228 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
230 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
232 /* Obtain SKU information */
233 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
234 CCK_FUSE_HPLL_FREQ_MASK;
236 return vco_freq[hpll_freq] * 1000;
239 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
240 const char *name, u32 reg, int ref_freq)
245 val = vlv_cck_read(dev_priv, reg);
246 divider = val & CCK_FREQUENCY_VALUES;
248 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
249 (divider << CCK_FREQUENCY_STATUS_SHIFT),
250 "%s change in progress\n", name);
252 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
255 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
256 const char *name, u32 reg)
260 vlv_cck_get(dev_priv);
262 if (dev_priv->hpll_freq == 0)
263 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
265 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
267 vlv_cck_put(dev_priv);
272 static void intel_update_czclk(struct drm_i915_private *dev_priv)
274 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
277 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
278 CCK_CZ_CLOCK_CONTROL);
280 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
281 dev_priv->czclk_freq);
284 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
286 return (crtc_state->active_planes &
287 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
290 /* WA Display #0827: Gen9:all */
292 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
295 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
296 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS);
298 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
299 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
302 /* Wa_2006604312:icl,ehl */
304 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
308 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
309 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS);
311 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe),
312 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS);
315 /* Wa_1604331009:icl,jsl,ehl */
317 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
320 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), CURSOR_GATING_DIS,
321 enable ? CURSOR_GATING_DIS : 0);
325 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
327 return crtc_state->master_transcoder != INVALID_TRANSCODER;
331 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
333 return crtc_state->sync_mode_slaves_mask != 0;
337 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
339 return is_trans_port_sync_master(crtc_state) ||
340 is_trans_port_sync_slave(crtc_state);
343 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state)
345 return ffs(crtc_state->bigjoiner_pipes) - 1;
348 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state)
350 if (crtc_state->bigjoiner_pipes)
351 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state));
356 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state)
358 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
360 return crtc_state->bigjoiner_pipes &&
361 crtc->pipe != bigjoiner_master_pipe(crtc_state);
364 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state)
366 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
368 return crtc_state->bigjoiner_pipes &&
369 crtc->pipe == bigjoiner_master_pipe(crtc_state);
372 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state)
374 return hweight8(crtc_state->bigjoiner_pipes);
377 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state)
379 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
381 if (intel_crtc_is_bigjoiner_slave(crtc_state))
382 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state));
384 return to_intel_crtc(crtc_state->uapi.crtc);
387 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
390 i915_reg_t reg = PIPEDSL(pipe);
393 line1 = intel_de_read(dev_priv, reg) & PIPEDSL_LINE_MASK;
395 line2 = intel_de_read(dev_priv, reg) & PIPEDSL_LINE_MASK;
397 return line1 != line2;
400 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
402 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
403 enum pipe pipe = crtc->pipe;
405 /* Wait for the display line to settle/start moving */
406 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
407 drm_err(&dev_priv->drm,
408 "pipe %c scanline %s wait timed out\n",
409 pipe_name(pipe), str_on_off(state));
412 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
414 wait_for_pipe_scanline_moving(crtc, false);
417 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
419 wait_for_pipe_scanline_moving(crtc, true);
423 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
425 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
426 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
428 if (DISPLAY_VER(dev_priv) >= 4) {
429 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
431 /* Wait for the Pipe State to go off */
432 if (intel_de_wait_for_clear(dev_priv, PIPECONF(cpu_transcoder),
433 PIPECONF_STATE_ENABLE, 100))
434 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
436 intel_wait_for_pipe_scanline_stopped(crtc);
440 void assert_transcoder(struct drm_i915_private *dev_priv,
441 enum transcoder cpu_transcoder, bool state)
444 enum intel_display_power_domain power_domain;
445 intel_wakeref_t wakeref;
447 /* we keep both pipes enabled on 830 */
448 if (IS_I830(dev_priv))
451 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
452 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
454 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder));
455 cur_state = !!(val & PIPECONF_ENABLE);
457 intel_display_power_put(dev_priv, power_domain, wakeref);
462 I915_STATE_WARN(cur_state != state,
463 "transcoder %s assertion failure (expected %s, current %s)\n",
464 transcoder_name(cpu_transcoder),
465 str_on_off(state), str_on_off(cur_state));
468 static void assert_plane(struct intel_plane *plane, bool state)
473 cur_state = plane->get_hw_state(plane, &pipe);
475 I915_STATE_WARN(cur_state != state,
476 "%s assertion failure (expected %s, current %s)\n",
477 plane->base.name, str_on_off(state),
478 str_on_off(cur_state));
481 #define assert_plane_enabled(p) assert_plane(p, true)
482 #define assert_plane_disabled(p) assert_plane(p, false)
484 static void assert_planes_disabled(struct intel_crtc *crtc)
486 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
487 struct intel_plane *plane;
489 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
490 assert_plane_disabled(plane);
493 void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
494 struct intel_digital_port *dig_port,
495 unsigned int expected_mask)
500 switch (dig_port->base.port) {
502 MISSING_CASE(dig_port->base.port);
505 port_mask = DPLL_PORTB_READY_MASK;
509 port_mask = DPLL_PORTC_READY_MASK;
514 port_mask = DPLL_PORTD_READY_MASK;
515 dpll_reg = DPIO_PHY_STATUS;
519 if (intel_de_wait_for_register(dev_priv, dpll_reg,
520 port_mask, expected_mask, 1000))
521 drm_WARN(&dev_priv->drm, 1,
522 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
523 dig_port->base.base.base.id, dig_port->base.base.name,
524 intel_de_read(dev_priv, dpll_reg) & port_mask,
528 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
530 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
531 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
532 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
533 enum pipe pipe = crtc->pipe;
537 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
539 assert_planes_disabled(crtc);
542 * A pipe without a PLL won't actually be able to drive bits from
543 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
546 if (HAS_GMCH(dev_priv)) {
547 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
548 assert_dsi_pll_enabled(dev_priv);
550 assert_pll_enabled(dev_priv, pipe);
552 if (new_crtc_state->has_pch_encoder) {
553 /* if driving the PCH, we need FDI enabled */
554 assert_fdi_rx_pll_enabled(dev_priv,
555 intel_crtc_pch_transcoder(crtc));
556 assert_fdi_tx_pll_enabled(dev_priv,
557 (enum pipe) cpu_transcoder);
559 /* FIXME: assert CPU port conditions for SNB+ */
562 /* Wa_22012358565:adl-p */
563 if (DISPLAY_VER(dev_priv) == 13)
564 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe),
565 0, PIPE_ARB_USE_PROG_SLOTS);
567 reg = PIPECONF(cpu_transcoder);
568 val = intel_de_read(dev_priv, reg);
569 if (val & PIPECONF_ENABLE) {
570 /* we keep both pipes enabled on 830 */
571 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
575 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE);
576 intel_de_posting_read(dev_priv, reg);
579 * Until the pipe starts PIPEDSL reads will return a stale value,
580 * which causes an apparent vblank timestamp jump when PIPEDSL
581 * resets to its proper value. That also messes up the frame count
582 * when it's derived from the timestamps. So let's wait for the
583 * pipe to start properly before we call drm_crtc_vblank_on()
585 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
586 intel_wait_for_pipe_scanline_moving(crtc);
589 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
591 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
592 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
593 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
594 enum pipe pipe = crtc->pipe;
598 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
601 * Make sure planes won't keep trying to pump pixels to us,
602 * or we might hang the display.
604 assert_planes_disabled(crtc);
606 reg = PIPECONF(cpu_transcoder);
607 val = intel_de_read(dev_priv, reg);
608 if ((val & PIPECONF_ENABLE) == 0)
612 * Double wide has implications for planes
613 * so best keep it disabled when not needed.
615 if (old_crtc_state->double_wide)
616 val &= ~PIPECONF_DOUBLE_WIDE;
618 /* Don't disable pipe or pipe PLLs if needed */
619 if (!IS_I830(dev_priv))
620 val &= ~PIPECONF_ENABLE;
622 if (DISPLAY_VER(dev_priv) >= 12)
623 intel_de_rmw(dev_priv, CHICKEN_TRANS(cpu_transcoder),
624 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
626 intel_de_write(dev_priv, reg, val);
627 if ((val & PIPECONF_ENABLE) == 0)
628 intel_wait_for_pipe_off(old_crtc_state);
631 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
633 unsigned int size = 0;
636 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
637 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
642 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
644 unsigned int size = 0;
647 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
648 unsigned int plane_size;
650 if (rem_info->plane[i].linear)
651 plane_size = rem_info->plane[i].size;
653 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
658 if (rem_info->plane_alignment)
659 size = ALIGN(size, rem_info->plane_alignment);
667 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
669 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
670 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
672 return DISPLAY_VER(dev_priv) < 4 ||
674 plane_state->view.gtt.type == I915_GGTT_VIEW_NORMAL);
678 * Convert the x/y offsets into a linear offset.
679 * Only valid with 0/180 degree rotation, which is fine since linear
680 * offset is only used with linear buffers on pre-hsw and tiled buffers
681 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
683 u32 intel_fb_xy_to_linear(int x, int y,
684 const struct intel_plane_state *state,
687 const struct drm_framebuffer *fb = state->hw.fb;
688 unsigned int cpp = fb->format->cpp[color_plane];
689 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
691 return y * pitch + x * cpp;
695 * Add the x/y offsets derived from fb->offsets[] to the user
696 * specified plane src x/y offsets. The resulting x/y offsets
697 * specify the start of scanout from the beginning of the gtt mapping.
699 void intel_add_fb_offsets(int *x, int *y,
700 const struct intel_plane_state *state,
704 *x += state->view.color_plane[color_plane].x;
705 *y += state->view.color_plane[color_plane].y;
708 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
709 u32 pixel_format, u64 modifier)
711 struct intel_crtc *crtc;
712 struct intel_plane *plane;
714 if (!HAS_DISPLAY(dev_priv))
718 * We assume the primary plane for pipe A has
719 * the highest stride limits of them all,
720 * if in case pipe A is disabled, use the first pipe from pipe_mask.
722 crtc = intel_first_crtc(dev_priv);
726 plane = to_intel_plane(crtc->base.primary);
728 return plane->max_stride(plane, pixel_format, modifier,
732 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
733 struct intel_plane_state *plane_state,
736 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
738 plane_state->uapi.visible = visible;
741 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
743 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
746 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
748 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
749 struct drm_plane *plane;
752 * Active_planes aliases if multiple "primary" or cursor planes
753 * have been used on the same (or wrong) pipe. plane_mask uses
754 * unique ids, hence we can use that to reconstruct active_planes.
756 crtc_state->enabled_planes = 0;
757 crtc_state->active_planes = 0;
759 drm_for_each_plane_mask(plane, &dev_priv->drm,
760 crtc_state->uapi.plane_mask) {
761 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
762 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
766 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
767 struct intel_plane *plane)
769 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
770 struct intel_crtc_state *crtc_state =
771 to_intel_crtc_state(crtc->base.state);
772 struct intel_plane_state *plane_state =
773 to_intel_plane_state(plane->base.state);
775 drm_dbg_kms(&dev_priv->drm,
776 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
777 plane->base.base.id, plane->base.name,
778 crtc->base.base.id, crtc->base.name);
780 intel_set_plane_visible(crtc_state, plane_state, false);
781 intel_plane_fixup_bitmasks(crtc_state);
782 crtc_state->data_rate[plane->id] = 0;
783 crtc_state->data_rate_y[plane->id] = 0;
784 crtc_state->rel_data_rate[plane->id] = 0;
785 crtc_state->rel_data_rate_y[plane->id] = 0;
786 crtc_state->min_cdclk[plane->id] = 0;
788 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
789 hsw_ips_disable(crtc_state)) {
790 crtc_state->ips_enabled = false;
791 intel_crtc_wait_for_next_vblank(crtc);
795 * Vblank time updates from the shadow to live plane control register
796 * are blocked if the memory self-refresh mode is active at that
797 * moment. So to make sure the plane gets truly disabled, disable
798 * first the self-refresh mode. The self-refresh enable bit in turn
799 * will be checked/applied by the HW only at the next frame start
800 * event which is after the vblank start event, so we need to have a
801 * wait-for-vblank between disabling the plane and the pipe.
803 if (HAS_GMCH(dev_priv) &&
804 intel_set_memory_cxsr(dev_priv, false))
805 intel_crtc_wait_for_next_vblank(crtc);
808 * Gen2 reports pipe underruns whenever all planes are disabled.
809 * So disable underrun reporting before all the planes get disabled.
811 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
812 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
814 intel_plane_disable_arm(plane, crtc_state);
815 intel_crtc_wait_for_next_vblank(crtc);
819 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
823 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
824 plane_state->view.color_plane[0].offset, 0);
830 __intel_display_resume(struct drm_i915_private *i915,
831 struct drm_atomic_state *state,
832 struct drm_modeset_acquire_ctx *ctx)
834 struct drm_crtc_state *crtc_state;
835 struct drm_crtc *crtc;
838 intel_modeset_setup_hw_state(i915, ctx);
839 intel_vga_redisable(i915);
845 * We've duplicated the state, pointers to the old state are invalid.
847 * Don't attempt to use the old state until we commit the duplicated state.
849 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
851 * Force recalculation even if we restore
852 * current state. With fast modeset this may not result
853 * in a modeset when the state is compatible.
855 crtc_state->mode_changed = true;
858 /* ignore any reset values/BIOS leftovers in the WM registers */
860 to_intel_atomic_state(state)->skip_intermediate_wm = true;
862 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
864 drm_WARN_ON(&i915->drm, ret == -EDEADLK);
869 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
871 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
872 intel_has_gpu_reset(to_gt(dev_priv)));
875 void intel_display_prepare_reset(struct drm_i915_private *dev_priv)
877 struct drm_device *dev = &dev_priv->drm;
878 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
879 struct drm_atomic_state *state;
882 if (!HAS_DISPLAY(dev_priv))
885 /* reset doesn't touch the display */
886 if (!dev_priv->params.force_reset_modeset_test &&
887 !gpu_reset_clobbers_display(dev_priv))
890 /* We have a modeset vs reset deadlock, defensively unbreak it. */
891 set_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags);
892 smp_mb__after_atomic();
893 wake_up_bit(&to_gt(dev_priv)->reset.flags, I915_RESET_MODESET);
895 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
896 drm_dbg_kms(&dev_priv->drm,
897 "Modeset potentially stuck, unbreaking through wedging\n");
898 intel_gt_set_wedged(to_gt(dev_priv));
902 * Need mode_config.mutex so that we don't
903 * trample ongoing ->detect() and whatnot.
905 mutex_lock(&dev->mode_config.mutex);
906 drm_modeset_acquire_init(ctx, 0);
908 ret = drm_modeset_lock_all_ctx(dev, ctx);
912 drm_modeset_backoff(ctx);
915 * Disabling the crtcs gracefully seems nicer. Also the
916 * g33 docs say we should at least disable all the planes.
918 state = drm_atomic_helper_duplicate_state(dev, ctx);
920 ret = PTR_ERR(state);
921 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n",
926 ret = drm_atomic_helper_disable_all(dev, ctx);
928 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
930 drm_atomic_state_put(state);
934 dev_priv->modeset_restore_state = state;
935 state->acquire_ctx = ctx;
938 void intel_display_finish_reset(struct drm_i915_private *i915)
940 struct drm_modeset_acquire_ctx *ctx = &i915->reset_ctx;
941 struct drm_atomic_state *state;
944 if (!HAS_DISPLAY(i915))
947 /* reset doesn't touch the display */
948 if (!test_bit(I915_RESET_MODESET, &to_gt(i915)->reset.flags))
951 state = fetch_and_zero(&i915->modeset_restore_state);
955 /* reset doesn't touch the display */
956 if (!gpu_reset_clobbers_display(i915)) {
957 /* for testing only restore the display */
958 ret = __intel_display_resume(i915, state, ctx);
961 "Restoring old state failed with %i\n", ret);
964 * The display has been reset as well,
965 * so need a full re-initialization.
967 intel_pps_unlock_regs_wa(i915);
968 intel_modeset_init_hw(i915);
969 intel_init_clock_gating(i915);
970 intel_hpd_init(i915);
972 ret = __intel_display_resume(i915, state, ctx);
975 "Restoring old state failed with %i\n", ret);
977 intel_hpd_poll_disable(i915);
980 drm_atomic_state_put(state);
982 drm_modeset_drop_locks(ctx);
983 drm_modeset_acquire_fini(ctx);
984 mutex_unlock(&i915->drm.mode_config.mutex);
986 clear_bit_unlock(I915_RESET_MODESET, &to_gt(i915)->reset.flags);
989 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
991 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
993 enum pipe pipe = crtc->pipe;
996 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
999 * Display WA #1153: icl
1000 * enable hardware to bypass the alpha math
1001 * and rounding for per-pixel values 00 and 0xff
1003 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
1005 * Display WA # 1605353570: icl
1006 * Set the pixel rounding bit to 1 for allowing
1007 * passthrough of Frame buffer pixels unmodified
1010 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
1013 * Underrun recovery must always be disabled on display 13+.
1014 * DG2 chicken bit meaning is inverted compared to other platforms.
1016 if (IS_DG2(dev_priv))
1017 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
1018 else if (DISPLAY_VER(dev_priv) >= 13)
1019 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
1021 /* Wa_14010547955:dg2 */
1022 if (IS_DG2_DISPLAY_STEP(dev_priv, STEP_B0, STEP_FOREVER))
1023 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
1025 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
1028 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
1030 struct drm_crtc *crtc;
1033 drm_for_each_crtc(crtc, &dev_priv->drm) {
1034 struct drm_crtc_commit *commit;
1035 spin_lock(&crtc->commit_lock);
1036 commit = list_first_entry_or_null(&crtc->commit_list,
1037 struct drm_crtc_commit, commit_entry);
1038 cleanup_done = commit ?
1039 try_wait_for_completion(&commit->cleanup_done) : true;
1040 spin_unlock(&crtc->commit_lock);
1045 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
1054 * Finds the encoder associated with the given CRTC. This can only be
1055 * used when we know that the CRTC isn't feeding multiple encoders!
1057 struct intel_encoder *
1058 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
1059 const struct intel_crtc_state *crtc_state)
1061 const struct drm_connector_state *connector_state;
1062 const struct drm_connector *connector;
1063 struct intel_encoder *encoder = NULL;
1064 struct intel_crtc *master_crtc;
1065 int num_encoders = 0;
1068 master_crtc = intel_master_crtc(crtc_state);
1070 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
1071 if (connector_state->crtc != &master_crtc->base)
1074 encoder = to_intel_encoder(connector_state->best_encoder);
1078 drm_WARN(encoder->base.dev, num_encoders != 1,
1079 "%d encoders for pipe %c\n",
1080 num_encoders, pipe_name(master_crtc->pipe));
1085 static void cpt_verify_modeset(struct drm_i915_private *dev_priv,
1088 i915_reg_t dslreg = PIPEDSL(pipe);
1091 temp = intel_de_read(dev_priv, dslreg);
1093 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) {
1094 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5))
1095 drm_err(&dev_priv->drm,
1096 "mode set failed: pipe %c stuck\n",
1101 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
1103 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1104 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1105 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
1106 enum pipe pipe = crtc->pipe;
1107 int width = drm_rect_width(dst);
1108 int height = drm_rect_height(dst);
1112 if (!crtc_state->pch_pfit.enabled)
1115 /* Force use of hard-coded filter coefficients
1116 * as some pre-programmed values are broken,
1119 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
1120 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
1121 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
1123 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
1125 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), x << 16 | y);
1126 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), width << 16 | height);
1129 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
1132 (void) intel_overlay_switch_off(crtc->overlay);
1134 /* Let userspace switch the overlay on again. In most cases userspace
1135 * has to recompute where to put it anyway.
1139 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
1141 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1143 if (!crtc_state->nv12_planes)
1146 /* WA Display #0827: Gen9:all */
1147 if (DISPLAY_VER(dev_priv) == 9)
1153 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
1155 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1157 /* Wa_2006604312:icl,ehl */
1158 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
1164 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
1166 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1168 /* Wa_1604331009:icl,jsl,ehl */
1169 if (is_hdr_mode(crtc_state) &&
1170 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
1171 DISPLAY_VER(dev_priv) == 11)
1177 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
1178 enum pipe pipe, bool enable)
1180 if (DISPLAY_VER(i915) == 9) {
1182 * "Plane N strech max must be programmed to 11b (x1)
1183 * when Async flips are enabled on that plane."
1185 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
1186 SKL_PLANE1_STRETCH_MAX_MASK,
1187 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
1189 /* Also needed on HSW/BDW albeit undocumented */
1190 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
1191 HSW_PRI_STRETCH_MAX_MASK,
1192 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
1196 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
1198 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
1200 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
1201 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
1204 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
1205 const struct intel_crtc_state *new_crtc_state)
1207 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) &&
1208 new_crtc_state->active_planes;
1211 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
1212 const struct intel_crtc_state *new_crtc_state)
1214 return old_crtc_state->active_planes &&
1215 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state));
1218 static void intel_post_plane_update(struct intel_atomic_state *state,
1219 struct intel_crtc *crtc)
1221 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1222 const struct intel_crtc_state *old_crtc_state =
1223 intel_atomic_get_old_crtc_state(state, crtc);
1224 const struct intel_crtc_state *new_crtc_state =
1225 intel_atomic_get_new_crtc_state(state, crtc);
1226 enum pipe pipe = crtc->pipe;
1228 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
1230 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
1231 intel_update_watermarks(dev_priv);
1233 hsw_ips_post_update(state, crtc);
1234 intel_fbc_post_update(state, crtc);
1236 if (needs_async_flip_vtd_wa(old_crtc_state) &&
1237 !needs_async_flip_vtd_wa(new_crtc_state))
1238 intel_async_flip_vtd_wa(dev_priv, pipe, false);
1240 if (needs_nv12_wa(old_crtc_state) &&
1241 !needs_nv12_wa(new_crtc_state))
1242 skl_wa_827(dev_priv, pipe, false);
1244 if (needs_scalerclk_wa(old_crtc_state) &&
1245 !needs_scalerclk_wa(new_crtc_state))
1246 icl_wa_scalerclkgating(dev_priv, pipe, false);
1248 if (needs_cursorclk_wa(old_crtc_state) &&
1249 !needs_cursorclk_wa(new_crtc_state))
1250 icl_wa_cursorclkgating(dev_priv, pipe, false);
1252 intel_drrs_activate(new_crtc_state);
1255 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
1256 struct intel_crtc *crtc)
1258 const struct intel_crtc_state *crtc_state =
1259 intel_atomic_get_new_crtc_state(state, crtc);
1260 u8 update_planes = crtc_state->update_planes;
1261 const struct intel_plane_state *plane_state;
1262 struct intel_plane *plane;
1265 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1266 if (plane->pipe == crtc->pipe &&
1267 update_planes & BIT(plane->id))
1268 plane->enable_flip_done(plane);
1272 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1273 struct intel_crtc *crtc)
1275 const struct intel_crtc_state *crtc_state =
1276 intel_atomic_get_new_crtc_state(state, crtc);
1277 u8 update_planes = crtc_state->update_planes;
1278 const struct intel_plane_state *plane_state;
1279 struct intel_plane *plane;
1282 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1283 if (plane->pipe == crtc->pipe &&
1284 update_planes & BIT(plane->id))
1285 plane->disable_flip_done(plane);
1289 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1290 struct intel_crtc *crtc)
1292 const struct intel_crtc_state *old_crtc_state =
1293 intel_atomic_get_old_crtc_state(state, crtc);
1294 const struct intel_crtc_state *new_crtc_state =
1295 intel_atomic_get_new_crtc_state(state, crtc);
1296 u8 update_planes = new_crtc_state->update_planes;
1297 const struct intel_plane_state *old_plane_state;
1298 struct intel_plane *plane;
1299 bool need_vbl_wait = false;
1302 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1303 if (plane->need_async_flip_disable_wa &&
1304 plane->pipe == crtc->pipe &&
1305 update_planes & BIT(plane->id)) {
1307 * Apart from the async flip bit we want to
1308 * preserve the old state for the plane.
1310 plane->async_flip(plane, old_crtc_state,
1311 old_plane_state, false);
1312 need_vbl_wait = true;
1317 intel_crtc_wait_for_next_vblank(crtc);
1320 static void intel_pre_plane_update(struct intel_atomic_state *state,
1321 struct intel_crtc *crtc)
1323 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1324 const struct intel_crtc_state *old_crtc_state =
1325 intel_atomic_get_old_crtc_state(state, crtc);
1326 const struct intel_crtc_state *new_crtc_state =
1327 intel_atomic_get_new_crtc_state(state, crtc);
1328 enum pipe pipe = crtc->pipe;
1330 intel_drrs_deactivate(old_crtc_state);
1332 intel_psr_pre_plane_update(state, crtc);
1334 if (hsw_ips_pre_update(state, crtc))
1335 intel_crtc_wait_for_next_vblank(crtc);
1337 if (intel_fbc_pre_update(state, crtc))
1338 intel_crtc_wait_for_next_vblank(crtc);
1340 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1341 needs_async_flip_vtd_wa(new_crtc_state))
1342 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1344 /* Display WA 827 */
1345 if (!needs_nv12_wa(old_crtc_state) &&
1346 needs_nv12_wa(new_crtc_state))
1347 skl_wa_827(dev_priv, pipe, true);
1349 /* Wa_2006604312:icl,ehl */
1350 if (!needs_scalerclk_wa(old_crtc_state) &&
1351 needs_scalerclk_wa(new_crtc_state))
1352 icl_wa_scalerclkgating(dev_priv, pipe, true);
1354 /* Wa_1604331009:icl,jsl,ehl */
1355 if (!needs_cursorclk_wa(old_crtc_state) &&
1356 needs_cursorclk_wa(new_crtc_state))
1357 icl_wa_cursorclkgating(dev_priv, pipe, true);
1360 * Vblank time updates from the shadow to live plane control register
1361 * are blocked if the memory self-refresh mode is active at that
1362 * moment. So to make sure the plane gets truly disabled, disable
1363 * first the self-refresh mode. The self-refresh enable bit in turn
1364 * will be checked/applied by the HW only at the next frame start
1365 * event which is after the vblank start event, so we need to have a
1366 * wait-for-vblank between disabling the plane and the pipe.
1368 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1369 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1370 intel_crtc_wait_for_next_vblank(crtc);
1373 * IVB workaround: must disable low power watermarks for at least
1374 * one frame before enabling scaling. LP watermarks can be re-enabled
1375 * when scaling is disabled.
1377 * WaCxSRDisabledForSpriteScaling:ivb
1379 if (old_crtc_state->hw.active &&
1380 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv))
1381 intel_crtc_wait_for_next_vblank(crtc);
1384 * If we're doing a modeset we don't need to do any
1385 * pre-vblank watermark programming here.
1387 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1389 * For platforms that support atomic watermarks, program the
1390 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1391 * will be the intermediate values that are safe for both pre- and
1392 * post- vblank; when vblank happens, the 'active' values will be set
1393 * to the final 'target' values and we'll do this again to get the
1394 * optimal watermarks. For gen9+ platforms, the values we program here
1395 * will be the final target values which will get automatically latched
1396 * at vblank time; no further programming will be necessary.
1398 * If a platform hasn't been transitioned to atomic watermarks yet,
1399 * we'll continue to update watermarks the old way, if flags tell
1402 if (!intel_initial_watermarks(state, crtc))
1403 if (new_crtc_state->update_wm_pre)
1404 intel_update_watermarks(dev_priv);
1408 * Gen2 reports pipe underruns whenever all planes are disabled.
1409 * So disable underrun reporting before all the planes get disabled.
1411 * We do this after .initial_watermarks() so that we have a
1412 * chance of catching underruns with the intermediate watermarks
1413 * vs. the old plane configuration.
1415 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1416 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1419 * WA for platforms where async address update enable bit
1420 * is double buffered and only latched at start of vblank.
1422 if (old_crtc_state->uapi.async_flip && !new_crtc_state->uapi.async_flip)
1423 intel_crtc_async_flip_disable_wa(state, crtc);
1426 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1427 struct intel_crtc *crtc)
1429 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1430 const struct intel_crtc_state *new_crtc_state =
1431 intel_atomic_get_new_crtc_state(state, crtc);
1432 unsigned int update_mask = new_crtc_state->update_planes;
1433 const struct intel_plane_state *old_plane_state;
1434 struct intel_plane *plane;
1435 unsigned fb_bits = 0;
1438 intel_crtc_dpms_overlay_disable(crtc);
1440 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1441 if (crtc->pipe != plane->pipe ||
1442 !(update_mask & BIT(plane->id)))
1445 intel_plane_disable_arm(plane, new_crtc_state);
1447 if (old_plane_state->uapi.visible)
1448 fb_bits |= plane->frontbuffer_bit;
1451 intel_frontbuffer_flip(dev_priv, fb_bits);
1455 * intel_connector_primary_encoder - get the primary encoder for a connector
1456 * @connector: connector for which to return the encoder
1458 * Returns the primary encoder for a connector. There is a 1:1 mapping from
1459 * all connectors to their encoder, except for DP-MST connectors which have
1460 * both a virtual and a primary encoder. These DP-MST primary encoders can be
1461 * pointed to by as many DP-MST connectors as there are pipes.
1463 static struct intel_encoder *
1464 intel_connector_primary_encoder(struct intel_connector *connector)
1466 struct intel_encoder *encoder;
1468 if (connector->mst_port)
1469 return &dp_to_dig_port(connector->mst_port)->base;
1471 encoder = intel_attached_encoder(connector);
1472 drm_WARN_ON(connector->base.dev, !encoder);
1477 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1479 struct drm_i915_private *i915 = to_i915(state->base.dev);
1480 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1481 struct intel_crtc *crtc;
1482 struct drm_connector_state *new_conn_state;
1483 struct drm_connector *connector;
1487 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1488 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1490 if (i915->display.dpll.mgr) {
1491 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1492 if (intel_crtc_needs_modeset(new_crtc_state))
1495 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1496 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1500 if (!state->modeset)
1503 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
1505 struct intel_connector *intel_connector;
1506 struct intel_encoder *encoder;
1507 struct intel_crtc *crtc;
1509 if (!intel_connector_needs_modeset(state, connector))
1512 intel_connector = to_intel_connector(connector);
1513 encoder = intel_connector_primary_encoder(intel_connector);
1514 if (!encoder->update_prepare)
1517 crtc = new_conn_state->crtc ?
1518 to_intel_crtc(new_conn_state->crtc) : NULL;
1519 encoder->update_prepare(state, encoder, crtc);
1523 static void intel_encoders_update_complete(struct intel_atomic_state *state)
1525 struct drm_connector_state *new_conn_state;
1526 struct drm_connector *connector;
1529 if (!state->modeset)
1532 for_each_new_connector_in_state(&state->base, connector, new_conn_state,
1534 struct intel_connector *intel_connector;
1535 struct intel_encoder *encoder;
1536 struct intel_crtc *crtc;
1538 if (!intel_connector_needs_modeset(state, connector))
1541 intel_connector = to_intel_connector(connector);
1542 encoder = intel_connector_primary_encoder(intel_connector);
1543 if (!encoder->update_complete)
1546 crtc = new_conn_state->crtc ?
1547 to_intel_crtc(new_conn_state->crtc) : NULL;
1548 encoder->update_complete(state, encoder, crtc);
1552 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1553 struct intel_crtc *crtc)
1555 const struct intel_crtc_state *crtc_state =
1556 intel_atomic_get_new_crtc_state(state, crtc);
1557 const struct drm_connector_state *conn_state;
1558 struct drm_connector *conn;
1561 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1562 struct intel_encoder *encoder =
1563 to_intel_encoder(conn_state->best_encoder);
1565 if (conn_state->crtc != &crtc->base)
1568 if (encoder->pre_pll_enable)
1569 encoder->pre_pll_enable(state, encoder,
1570 crtc_state, conn_state);
1574 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1575 struct intel_crtc *crtc)
1577 const struct intel_crtc_state *crtc_state =
1578 intel_atomic_get_new_crtc_state(state, crtc);
1579 const struct drm_connector_state *conn_state;
1580 struct drm_connector *conn;
1583 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1584 struct intel_encoder *encoder =
1585 to_intel_encoder(conn_state->best_encoder);
1587 if (conn_state->crtc != &crtc->base)
1590 if (encoder->pre_enable)
1591 encoder->pre_enable(state, encoder,
1592 crtc_state, conn_state);
1596 static void intel_encoders_enable(struct intel_atomic_state *state,
1597 struct intel_crtc *crtc)
1599 const struct intel_crtc_state *crtc_state =
1600 intel_atomic_get_new_crtc_state(state, crtc);
1601 const struct drm_connector_state *conn_state;
1602 struct drm_connector *conn;
1605 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1606 struct intel_encoder *encoder =
1607 to_intel_encoder(conn_state->best_encoder);
1609 if (conn_state->crtc != &crtc->base)
1612 if (encoder->enable)
1613 encoder->enable(state, encoder,
1614 crtc_state, conn_state);
1615 intel_opregion_notify_encoder(encoder, true);
1619 static void intel_encoders_disable(struct intel_atomic_state *state,
1620 struct intel_crtc *crtc)
1622 const struct intel_crtc_state *old_crtc_state =
1623 intel_atomic_get_old_crtc_state(state, crtc);
1624 const struct drm_connector_state *old_conn_state;
1625 struct drm_connector *conn;
1628 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1629 struct intel_encoder *encoder =
1630 to_intel_encoder(old_conn_state->best_encoder);
1632 if (old_conn_state->crtc != &crtc->base)
1635 intel_opregion_notify_encoder(encoder, false);
1636 if (encoder->disable)
1637 encoder->disable(state, encoder,
1638 old_crtc_state, old_conn_state);
1642 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1643 struct intel_crtc *crtc)
1645 const struct intel_crtc_state *old_crtc_state =
1646 intel_atomic_get_old_crtc_state(state, crtc);
1647 const struct drm_connector_state *old_conn_state;
1648 struct drm_connector *conn;
1651 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1652 struct intel_encoder *encoder =
1653 to_intel_encoder(old_conn_state->best_encoder);
1655 if (old_conn_state->crtc != &crtc->base)
1658 if (encoder->post_disable)
1659 encoder->post_disable(state, encoder,
1660 old_crtc_state, old_conn_state);
1664 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1665 struct intel_crtc *crtc)
1667 const struct intel_crtc_state *old_crtc_state =
1668 intel_atomic_get_old_crtc_state(state, crtc);
1669 const struct drm_connector_state *old_conn_state;
1670 struct drm_connector *conn;
1673 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1674 struct intel_encoder *encoder =
1675 to_intel_encoder(old_conn_state->best_encoder);
1677 if (old_conn_state->crtc != &crtc->base)
1680 if (encoder->post_pll_disable)
1681 encoder->post_pll_disable(state, encoder,
1682 old_crtc_state, old_conn_state);
1686 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1687 struct intel_crtc *crtc)
1689 const struct intel_crtc_state *crtc_state =
1690 intel_atomic_get_new_crtc_state(state, crtc);
1691 const struct drm_connector_state *conn_state;
1692 struct drm_connector *conn;
1695 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1696 struct intel_encoder *encoder =
1697 to_intel_encoder(conn_state->best_encoder);
1699 if (conn_state->crtc != &crtc->base)
1702 if (encoder->update_pipe)
1703 encoder->update_pipe(state, encoder,
1704 crtc_state, conn_state);
1708 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state)
1710 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1711 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1713 plane->disable_arm(plane, crtc_state);
1716 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1718 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1719 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1721 if (crtc_state->has_pch_encoder) {
1722 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1723 &crtc_state->fdi_m_n);
1724 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1725 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1726 &crtc_state->dp_m_n);
1727 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1728 &crtc_state->dp_m2_n2);
1731 intel_set_transcoder_timings(crtc_state);
1733 ilk_set_pipeconf(crtc_state);
1736 static void ilk_crtc_enable(struct intel_atomic_state *state,
1737 struct intel_crtc *crtc)
1739 const struct intel_crtc_state *new_crtc_state =
1740 intel_atomic_get_new_crtc_state(state, crtc);
1741 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1742 enum pipe pipe = crtc->pipe;
1744 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1748 * Sometimes spurious CPU pipe underruns happen during FDI
1749 * training, at least with VGA+HDMI cloning. Suppress them.
1751 * On ILK we get an occasional spurious CPU pipe underruns
1752 * between eDP port A enable and vdd enable. Also PCH port
1753 * enable seems to result in the occasional CPU pipe underrun.
1755 * Spurious PCH underruns also occur during PCH enabling.
1757 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1758 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1760 ilk_configure_cpu_transcoder(new_crtc_state);
1762 intel_set_pipe_src_size(new_crtc_state);
1764 crtc->active = true;
1766 intel_encoders_pre_enable(state, crtc);
1768 if (new_crtc_state->has_pch_encoder) {
1769 ilk_pch_pre_enable(state, crtc);
1771 assert_fdi_tx_disabled(dev_priv, pipe);
1772 assert_fdi_rx_disabled(dev_priv, pipe);
1775 ilk_pfit_enable(new_crtc_state);
1778 * On ILK+ LUT must be loaded before the pipe is running but with
1781 intel_color_load_luts(new_crtc_state);
1782 intel_color_commit_noarm(new_crtc_state);
1783 intel_color_commit_arm(new_crtc_state);
1784 /* update DSPCNTR to configure gamma for pipe bottom color */
1785 intel_disable_primary_plane(new_crtc_state);
1787 intel_initial_watermarks(state, crtc);
1788 intel_enable_transcoder(new_crtc_state);
1790 if (new_crtc_state->has_pch_encoder)
1791 ilk_pch_enable(state, crtc);
1793 intel_crtc_vblank_on(new_crtc_state);
1795 intel_encoders_enable(state, crtc);
1797 if (HAS_PCH_CPT(dev_priv))
1798 cpt_verify_modeset(dev_priv, pipe);
1801 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1802 * And a second vblank wait is needed at least on ILK with
1803 * some interlaced HDMI modes. Let's do the double wait always
1804 * in case there are more corner cases we don't know about.
1806 if (new_crtc_state->has_pch_encoder) {
1807 intel_crtc_wait_for_next_vblank(crtc);
1808 intel_crtc_wait_for_next_vblank(crtc);
1810 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1811 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1814 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
1815 enum pipe pipe, bool apply)
1817 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe));
1818 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1825 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val);
1828 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1830 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1831 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1833 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1834 HSW_LINETIME(crtc_state->linetime) |
1835 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1838 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1840 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1841 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1842 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder);
1845 val = intel_de_read(dev_priv, reg);
1846 val &= ~HSW_FRAME_START_DELAY_MASK;
1847 val |= HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
1848 intel_de_write(dev_priv, reg, val);
1851 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state,
1852 const struct intel_crtc_state *crtc_state)
1854 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state);
1857 * Enable sequence steps 1-7 on bigjoiner master
1859 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1860 intel_encoders_pre_pll_enable(state, master_crtc);
1862 if (crtc_state->shared_dpll)
1863 intel_enable_shared_dpll(crtc_state);
1865 if (intel_crtc_is_bigjoiner_slave(crtc_state))
1866 intel_encoders_pre_enable(state, master_crtc);
1869 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1871 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1872 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1873 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1875 if (crtc_state->has_pch_encoder) {
1876 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1877 &crtc_state->fdi_m_n);
1878 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1879 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1880 &crtc_state->dp_m_n);
1881 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1882 &crtc_state->dp_m2_n2);
1885 intel_set_transcoder_timings(crtc_state);
1887 if (cpu_transcoder != TRANSCODER_EDP)
1888 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder),
1889 crtc_state->pixel_multiplier - 1);
1891 hsw_set_frame_start_delay(crtc_state);
1893 hsw_set_transconf(crtc_state);
1896 static void hsw_crtc_enable(struct intel_atomic_state *state,
1897 struct intel_crtc *crtc)
1899 const struct intel_crtc_state *new_crtc_state =
1900 intel_atomic_get_new_crtc_state(state, crtc);
1901 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1902 enum pipe pipe = crtc->pipe, hsw_workaround_pipe;
1903 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1904 bool psl_clkgate_wa;
1906 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1909 if (!new_crtc_state->bigjoiner_pipes) {
1910 intel_encoders_pre_pll_enable(state, crtc);
1912 if (new_crtc_state->shared_dpll)
1913 intel_enable_shared_dpll(new_crtc_state);
1915 intel_encoders_pre_enable(state, crtc);
1917 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state);
1920 intel_dsc_enable(new_crtc_state);
1922 if (DISPLAY_VER(dev_priv) >= 13)
1923 intel_uncompressed_joiner_enable(new_crtc_state);
1925 intel_set_pipe_src_size(new_crtc_state);
1926 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1927 bdw_set_pipemisc(new_crtc_state);
1929 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) &&
1930 !transcoder_is_dsi(cpu_transcoder))
1931 hsw_configure_cpu_transcoder(new_crtc_state);
1933 crtc->active = true;
1935 /* Display WA #1180: WaDisableScalarClockGating: glk */
1936 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 &&
1937 new_crtc_state->pch_pfit.enabled;
1939 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
1941 if (DISPLAY_VER(dev_priv) >= 9)
1942 skl_pfit_enable(new_crtc_state);
1944 ilk_pfit_enable(new_crtc_state);
1947 * On ILK+ LUT must be loaded before the pipe is running but with
1950 intel_color_load_luts(new_crtc_state);
1951 intel_color_commit_noarm(new_crtc_state);
1952 intel_color_commit_arm(new_crtc_state);
1953 /* update DSPCNTR to configure gamma/csc for pipe bottom color */
1954 if (DISPLAY_VER(dev_priv) < 9)
1955 intel_disable_primary_plane(new_crtc_state);
1957 hsw_set_linetime_wm(new_crtc_state);
1959 if (DISPLAY_VER(dev_priv) >= 11)
1960 icl_set_pipe_chicken(new_crtc_state);
1962 intel_initial_watermarks(state, crtc);
1964 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
1965 intel_crtc_vblank_on(new_crtc_state);
1967 intel_encoders_enable(state, crtc);
1969 if (psl_clkgate_wa) {
1970 intel_crtc_wait_for_next_vblank(crtc);
1971 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
1974 /* If we change the relative order between pipe/planes enabling, we need
1975 * to change the workaround. */
1976 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe;
1977 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1978 struct intel_crtc *wa_crtc;
1980 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe);
1982 intel_crtc_wait_for_next_vblank(wa_crtc);
1983 intel_crtc_wait_for_next_vblank(wa_crtc);
1987 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1989 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1990 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1991 enum pipe pipe = crtc->pipe;
1993 /* To avoid upsetting the power well on haswell only disable the pfit if
1994 * it's in use. The hw state code will make sure we get this right. */
1995 if (!old_crtc_state->pch_pfit.enabled)
1998 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1999 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
2000 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
2003 static void ilk_crtc_disable(struct intel_atomic_state *state,
2004 struct intel_crtc *crtc)
2006 const struct intel_crtc_state *old_crtc_state =
2007 intel_atomic_get_old_crtc_state(state, crtc);
2008 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2009 enum pipe pipe = crtc->pipe;
2012 * Sometimes spurious CPU pipe underruns happen when the
2013 * pipe is already disabled, but FDI RX/TX is still enabled.
2014 * Happens at least with VGA+HDMI cloning. Suppress them.
2016 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2017 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
2019 intel_encoders_disable(state, crtc);
2021 intel_crtc_vblank_off(old_crtc_state);
2023 intel_disable_transcoder(old_crtc_state);
2025 ilk_pfit_disable(old_crtc_state);
2027 if (old_crtc_state->has_pch_encoder)
2028 ilk_pch_disable(state, crtc);
2030 intel_encoders_post_disable(state, crtc);
2032 if (old_crtc_state->has_pch_encoder)
2033 ilk_pch_post_disable(state, crtc);
2035 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2036 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
2039 static void hsw_crtc_disable(struct intel_atomic_state *state,
2040 struct intel_crtc *crtc)
2042 const struct intel_crtc_state *old_crtc_state =
2043 intel_atomic_get_old_crtc_state(state, crtc);
2046 * FIXME collapse everything to one hook.
2047 * Need care with mst->ddi interactions.
2049 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) {
2050 intel_encoders_disable(state, crtc);
2051 intel_encoders_post_disable(state, crtc);
2055 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
2057 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2058 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2060 if (!crtc_state->gmch_pfit.control)
2064 * The panel fitter should only be adjusted whilst the pipe is disabled,
2065 * according to register description and PRM.
2067 drm_WARN_ON(&dev_priv->drm,
2068 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE);
2069 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
2071 intel_de_write(dev_priv, PFIT_PGM_RATIOS,
2072 crtc_state->gmch_pfit.pgm_ratios);
2073 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control);
2075 /* Border color in case we don't scale up to the full screen. Black by
2076 * default, change to something else for debugging. */
2077 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0);
2080 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
2082 if (phy == PHY_NONE)
2084 else if (IS_ALDERLAKE_S(dev_priv))
2085 return phy <= PHY_E;
2086 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
2087 return phy <= PHY_D;
2088 else if (IS_JSL_EHL(dev_priv))
2089 return phy <= PHY_C;
2090 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
2091 return phy <= PHY_B;
2094 * DG2 outputs labelled as "combo PHY" in the bspec use
2095 * SNPS PHYs with completely different programming,
2096 * hence we always return false here.
2101 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
2103 if (IS_DG2(dev_priv))
2104 /* DG2's "TC1" output uses a SNPS PHY */
2106 else if (IS_ALDERLAKE_P(dev_priv))
2107 return phy >= PHY_F && phy <= PHY_I;
2108 else if (IS_TIGERLAKE(dev_priv))
2109 return phy >= PHY_D && phy <= PHY_I;
2110 else if (IS_ICELAKE(dev_priv))
2111 return phy >= PHY_C && phy <= PHY_F;
2116 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
2118 if (phy == PHY_NONE)
2120 else if (IS_DG2(dev_priv))
2122 * All four "combo" ports and the TC1 port (PHY E) use
2125 return phy <= PHY_E;
2130 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
2132 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
2133 return PHY_D + port - PORT_D_XELPD;
2134 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
2135 return PHY_F + port - PORT_TC1;
2136 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
2137 return PHY_B + port - PORT_TC1;
2138 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
2139 return PHY_C + port - PORT_TC1;
2140 else if (IS_JSL_EHL(i915) && port == PORT_D)
2143 return PHY_A + port - PORT_A;
2146 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
2148 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
2149 return TC_PORT_NONE;
2151 if (DISPLAY_VER(dev_priv) >= 12)
2152 return TC_PORT_1 + port - PORT_TC1;
2154 return TC_PORT_1 + port - PORT_C;
2157 enum intel_display_power_domain
2158 intel_aux_power_domain(struct intel_digital_port *dig_port)
2160 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
2162 if (intel_tc_port_in_tbt_alt_mode(dig_port))
2163 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
2165 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
2168 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2169 struct intel_power_domain_mask *mask)
2171 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2172 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2173 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2174 struct drm_encoder *encoder;
2175 enum pipe pipe = crtc->pipe;
2177 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
2179 if (!crtc_state->hw.active)
2182 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
2183 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
2184 if (crtc_state->pch_pfit.enabled ||
2185 crtc_state->pch_pfit.force_thru)
2186 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
2188 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
2189 crtc_state->uapi.encoder_mask) {
2190 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2192 set_bit(intel_encoder->power_domain, mask->bits);
2195 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
2196 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
2198 if (crtc_state->shared_dpll)
2199 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
2201 if (crtc_state->dsc.compression_enable)
2202 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
2205 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2206 struct intel_power_domain_mask *old_domains)
2208 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2209 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2210 enum intel_display_power_domain domain;
2211 struct intel_power_domain_mask domains, new_domains;
2213 get_crtc_power_domains(crtc_state, &domains);
2215 bitmap_andnot(new_domains.bits,
2217 crtc->enabled_power_domains.mask.bits,
2219 bitmap_andnot(old_domains->bits,
2220 crtc->enabled_power_domains.mask.bits,
2224 for_each_power_domain(domain, &new_domains)
2225 intel_display_power_get_in_set(dev_priv,
2226 &crtc->enabled_power_domains,
2230 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
2231 struct intel_power_domain_mask *domains)
2233 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
2234 &crtc->enabled_power_domains,
2238 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
2240 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2241 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2243 if (intel_crtc_has_dp_encoder(crtc_state)) {
2244 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
2245 &crtc_state->dp_m_n);
2246 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
2247 &crtc_state->dp_m2_n2);
2250 intel_set_transcoder_timings(crtc_state);
2252 i9xx_set_pipeconf(crtc_state);
2255 static void valleyview_crtc_enable(struct intel_atomic_state *state,
2256 struct intel_crtc *crtc)
2258 const struct intel_crtc_state *new_crtc_state =
2259 intel_atomic_get_new_crtc_state(state, crtc);
2260 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2261 enum pipe pipe = crtc->pipe;
2263 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2266 i9xx_configure_cpu_transcoder(new_crtc_state);
2268 intel_set_pipe_src_size(new_crtc_state);
2270 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
2271 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
2272 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
2275 crtc->active = true;
2277 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2279 intel_encoders_pre_pll_enable(state, crtc);
2281 if (IS_CHERRYVIEW(dev_priv))
2282 chv_enable_pll(new_crtc_state);
2284 vlv_enable_pll(new_crtc_state);
2286 intel_encoders_pre_enable(state, crtc);
2288 i9xx_pfit_enable(new_crtc_state);
2290 intel_color_load_luts(new_crtc_state);
2291 intel_color_commit_noarm(new_crtc_state);
2292 intel_color_commit_arm(new_crtc_state);
2293 /* update DSPCNTR to configure gamma for pipe bottom color */
2294 intel_disable_primary_plane(new_crtc_state);
2296 intel_initial_watermarks(state, crtc);
2297 intel_enable_transcoder(new_crtc_state);
2299 intel_crtc_vblank_on(new_crtc_state);
2301 intel_encoders_enable(state, crtc);
2304 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2305 struct intel_crtc *crtc)
2307 const struct intel_crtc_state *new_crtc_state =
2308 intel_atomic_get_new_crtc_state(state, crtc);
2309 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2310 enum pipe pipe = crtc->pipe;
2312 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2315 i9xx_configure_cpu_transcoder(new_crtc_state);
2317 intel_set_pipe_src_size(new_crtc_state);
2319 crtc->active = true;
2321 if (DISPLAY_VER(dev_priv) != 2)
2322 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2324 intel_encoders_pre_enable(state, crtc);
2326 i9xx_enable_pll(new_crtc_state);
2328 i9xx_pfit_enable(new_crtc_state);
2330 intel_color_load_luts(new_crtc_state);
2331 intel_color_commit_noarm(new_crtc_state);
2332 intel_color_commit_arm(new_crtc_state);
2333 /* update DSPCNTR to configure gamma for pipe bottom color */
2334 intel_disable_primary_plane(new_crtc_state);
2336 if (!intel_initial_watermarks(state, crtc))
2337 intel_update_watermarks(dev_priv);
2338 intel_enable_transcoder(new_crtc_state);
2340 intel_crtc_vblank_on(new_crtc_state);
2342 intel_encoders_enable(state, crtc);
2344 /* prevents spurious underruns */
2345 if (DISPLAY_VER(dev_priv) == 2)
2346 intel_crtc_wait_for_next_vblank(crtc);
2349 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2351 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2352 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2354 if (!old_crtc_state->gmch_pfit.control)
2357 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2359 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2360 intel_de_read(dev_priv, PFIT_CONTROL));
2361 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2364 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2365 struct intel_crtc *crtc)
2367 struct intel_crtc_state *old_crtc_state =
2368 intel_atomic_get_old_crtc_state(state, crtc);
2369 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2370 enum pipe pipe = crtc->pipe;
2373 * On gen2 planes are double buffered but the pipe isn't, so we must
2374 * wait for planes to fully turn off before disabling the pipe.
2376 if (DISPLAY_VER(dev_priv) == 2)
2377 intel_crtc_wait_for_next_vblank(crtc);
2379 intel_encoders_disable(state, crtc);
2381 intel_crtc_vblank_off(old_crtc_state);
2383 intel_disable_transcoder(old_crtc_state);
2385 i9xx_pfit_disable(old_crtc_state);
2387 intel_encoders_post_disable(state, crtc);
2389 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2390 if (IS_CHERRYVIEW(dev_priv))
2391 chv_disable_pll(dev_priv, pipe);
2392 else if (IS_VALLEYVIEW(dev_priv))
2393 vlv_disable_pll(dev_priv, pipe);
2395 i9xx_disable_pll(old_crtc_state);
2398 intel_encoders_post_pll_disable(state, crtc);
2400 if (DISPLAY_VER(dev_priv) != 2)
2401 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2403 if (!dev_priv->display.funcs.wm->initial_watermarks)
2404 intel_update_watermarks(dev_priv);
2406 /* clock the pipe down to 640x480@60 to potentially save power */
2407 if (IS_I830(dev_priv))
2408 i830_enable_pipe(dev_priv, pipe);
2413 * turn all crtc's off, but do not adjust state
2414 * This has to be paired with a call to intel_modeset_setup_hw_state.
2416 int intel_display_suspend(struct drm_device *dev)
2418 struct drm_i915_private *dev_priv = to_i915(dev);
2419 struct drm_atomic_state *state;
2422 if (!HAS_DISPLAY(dev_priv))
2425 state = drm_atomic_helper_suspend(dev);
2426 ret = PTR_ERR_OR_ZERO(state);
2428 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
2431 dev_priv->modeset_restore_state = state;
2435 void intel_encoder_destroy(struct drm_encoder *encoder)
2437 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2439 drm_encoder_cleanup(encoder);
2440 kfree(intel_encoder);
2443 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2445 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2447 /* GDG double wide on either pipe, otherwise pipe A only */
2448 return DISPLAY_VER(dev_priv) < 4 &&
2449 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2452 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2454 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2455 struct drm_rect src;
2458 * We only use IF-ID interlacing. If we ever use
2459 * PF-ID we'll need to adjust the pixel_rate here.
2462 if (!crtc_state->pch_pfit.enabled)
2465 drm_rect_init(&src, 0, 0,
2466 drm_rect_width(&crtc_state->pipe_src) << 16,
2467 drm_rect_height(&crtc_state->pipe_src) << 16);
2469 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2473 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2474 const struct drm_display_mode *timings)
2476 mode->hdisplay = timings->crtc_hdisplay;
2477 mode->htotal = timings->crtc_htotal;
2478 mode->hsync_start = timings->crtc_hsync_start;
2479 mode->hsync_end = timings->crtc_hsync_end;
2481 mode->vdisplay = timings->crtc_vdisplay;
2482 mode->vtotal = timings->crtc_vtotal;
2483 mode->vsync_start = timings->crtc_vsync_start;
2484 mode->vsync_end = timings->crtc_vsync_end;
2486 mode->flags = timings->flags;
2487 mode->type = DRM_MODE_TYPE_DRIVER;
2489 mode->clock = timings->crtc_clock;
2491 drm_mode_set_name(mode);
2494 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2496 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2498 if (HAS_GMCH(dev_priv))
2499 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2500 crtc_state->pixel_rate =
2501 crtc_state->hw.pipe_mode.crtc_clock;
2503 crtc_state->pixel_rate =
2504 ilk_pipe_pixel_rate(crtc_state);
2507 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2508 struct drm_display_mode *mode)
2510 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2515 mode->crtc_clock /= num_pipes;
2516 mode->crtc_hdisplay /= num_pipes;
2517 mode->crtc_hblank_start /= num_pipes;
2518 mode->crtc_hblank_end /= num_pipes;
2519 mode->crtc_hsync_start /= num_pipes;
2520 mode->crtc_hsync_end /= num_pipes;
2521 mode->crtc_htotal /= num_pipes;
2524 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2525 struct drm_display_mode *mode)
2527 int overlap = crtc_state->splitter.pixel_overlap;
2528 int n = crtc_state->splitter.link_count;
2530 if (!crtc_state->splitter.enable)
2534 * eDP MSO uses segment timings from EDID for transcoder
2535 * timings, but full mode for everything else.
2537 * h_full = (h_segment - pixel_overlap) * link_count
2539 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2540 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2541 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2542 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2543 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2544 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2545 mode->crtc_clock *= n;
2548 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2550 struct drm_display_mode *mode = &crtc_state->hw.mode;
2551 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2552 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2555 * Start with the adjusted_mode crtc timings, which
2556 * have been filled with the transcoder timings.
2558 drm_mode_copy(pipe_mode, adjusted_mode);
2560 /* Expand MSO per-segment transcoder timings to full */
2561 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2564 * We want the full numbers in adjusted_mode normal timings,
2565 * adjusted_mode crtc timings are left with the raw transcoder
2568 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2570 /* Populate the "user" mode with full numbers */
2571 drm_mode_copy(mode, pipe_mode);
2572 intel_mode_from_crtc_timings(mode, mode);
2573 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2574 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2575 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2577 /* Derive per-pipe timings in case bigjoiner is used */
2578 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2579 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2581 intel_crtc_compute_pixel_rate(crtc_state);
2584 void intel_encoder_get_config(struct intel_encoder *encoder,
2585 struct intel_crtc_state *crtc_state)
2587 encoder->get_config(encoder, crtc_state);
2589 intel_crtc_readout_derived_state(crtc_state);
2592 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2594 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2600 width = drm_rect_width(&crtc_state->pipe_src);
2601 height = drm_rect_height(&crtc_state->pipe_src);
2603 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2604 width / num_pipes, height);
2607 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2609 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2610 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2612 intel_bigjoiner_compute_pipe_src(crtc_state);
2615 * Pipe horizontal size must be even in:
2617 * - LVDS dual channel mode
2618 * - Double wide pipe
2620 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2621 if (crtc_state->double_wide) {
2622 drm_dbg_kms(&i915->drm,
2623 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2624 crtc->base.base.id, crtc->base.name);
2628 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2629 intel_is_dual_link_lvds(i915)) {
2630 drm_dbg_kms(&i915->drm,
2631 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2632 crtc->base.base.id, crtc->base.name);
2640 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2642 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2643 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2644 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2645 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2646 int clock_limit = i915->max_dotclk_freq;
2649 * Start with the adjusted_mode crtc timings, which
2650 * have been filled with the transcoder timings.
2652 drm_mode_copy(pipe_mode, adjusted_mode);
2654 /* Expand MSO per-segment transcoder timings to full */
2655 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2657 /* Derive per-pipe timings in case bigjoiner is used */
2658 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2659 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2661 if (DISPLAY_VER(i915) < 4) {
2662 clock_limit = i915->max_cdclk_freq * 9 / 10;
2665 * Enable double wide mode when the dot clock
2666 * is > 90% of the (display) core speed.
2668 if (intel_crtc_supports_double_wide(crtc) &&
2669 pipe_mode->crtc_clock > clock_limit) {
2670 clock_limit = i915->max_dotclk_freq;
2671 crtc_state->double_wide = true;
2675 if (pipe_mode->crtc_clock > clock_limit) {
2676 drm_dbg_kms(&i915->drm,
2677 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2678 crtc->base.base.id, crtc->base.name,
2679 pipe_mode->crtc_clock, clock_limit,
2680 str_yes_no(crtc_state->double_wide));
2687 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2688 struct intel_crtc *crtc)
2690 struct intel_crtc_state *crtc_state =
2691 intel_atomic_get_new_crtc_state(state, crtc);
2694 ret = intel_crtc_compute_pipe_src(crtc_state);
2698 ret = intel_crtc_compute_pipe_mode(crtc_state);
2702 intel_crtc_compute_pixel_rate(crtc_state);
2704 if (crtc_state->has_pch_encoder)
2705 return ilk_fdi_compute_config(crtc, crtc_state);
2711 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2713 while (*num > DATA_LINK_M_N_MASK ||
2714 *den > DATA_LINK_M_N_MASK) {
2720 static void compute_m_n(unsigned int m, unsigned int n,
2721 u32 *ret_m, u32 *ret_n,
2725 * Several DP dongles in particular seem to be fussy about
2726 * too large link M/N values. Give N value as 0x8000 that
2727 * should be acceptable by specific devices. 0x8000 is the
2728 * specified fixed N value for asynchronous clock mode,
2729 * which the devices expect also in synchronous clock mode.
2732 *ret_n = DP_LINK_CONSTANT_N_VALUE;
2734 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2736 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2737 intel_reduce_m_n_ratio(ret_m, ret_n);
2741 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
2742 int pixel_clock, int link_clock,
2743 struct intel_link_m_n *m_n,
2744 bool constant_n, bool fec_enable)
2746 u32 data_clock = bits_per_pixel * pixel_clock;
2749 data_clock = intel_dp_mode_to_fec_clock(data_clock);
2752 compute_m_n(data_clock,
2753 link_clock * nlanes * 8,
2754 &m_n->data_m, &m_n->data_n,
2757 compute_m_n(pixel_clock, link_clock,
2758 &m_n->link_m, &m_n->link_n,
2762 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2765 * There may be no VBT; and if the BIOS enabled SSC we can
2766 * just keep using it to avoid unnecessary flicker. Whereas if the
2767 * BIOS isn't using it, don't assume it will work even if the VBT
2768 * indicates as much.
2770 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2771 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2775 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2776 drm_dbg_kms(&dev_priv->drm,
2777 "SSC %s by BIOS, overriding VBT which says %s\n",
2778 str_enabled_disabled(bios_lvds_use_ssc),
2779 str_enabled_disabled(dev_priv->vbt.lvds_use_ssc));
2780 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
2785 void intel_zero_m_n(struct intel_link_m_n *m_n)
2787 /* corresponds to 0 register value */
2788 memset(m_n, 0, sizeof(*m_n));
2792 void intel_set_m_n(struct drm_i915_private *i915,
2793 const struct intel_link_m_n *m_n,
2794 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2795 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2797 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2798 intel_de_write(i915, data_n_reg, m_n->data_n);
2799 intel_de_write(i915, link_m_reg, m_n->link_m);
2801 * On BDW+ writing LINK_N arms the double buffered update
2802 * of all the M/N registers, so it must be written last.
2804 intel_de_write(i915, link_n_reg, m_n->link_n);
2807 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2808 enum transcoder transcoder)
2810 if (IS_HASWELL(dev_priv))
2811 return transcoder == TRANSCODER_EDP;
2813 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2816 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2817 enum transcoder transcoder,
2818 const struct intel_link_m_n *m_n)
2820 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2821 enum pipe pipe = crtc->pipe;
2823 if (DISPLAY_VER(dev_priv) >= 5)
2824 intel_set_m_n(dev_priv, m_n,
2825 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2826 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2828 intel_set_m_n(dev_priv, m_n,
2829 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2830 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2833 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2834 enum transcoder transcoder,
2835 const struct intel_link_m_n *m_n)
2837 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2839 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2842 intel_set_m_n(dev_priv, m_n,
2843 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2844 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2847 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2849 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2850 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2851 enum pipe pipe = crtc->pipe;
2852 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2853 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2854 u32 crtc_vtotal, crtc_vblank_end;
2857 /* We need to be careful not to changed the adjusted mode, for otherwise
2858 * the hw state checker will get angry at the mismatch. */
2859 crtc_vtotal = adjusted_mode->crtc_vtotal;
2860 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2862 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2863 /* the chip adds 2 halflines automatically */
2865 crtc_vblank_end -= 1;
2867 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2868 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2870 vsyncshift = adjusted_mode->crtc_hsync_start -
2871 adjusted_mode->crtc_htotal / 2;
2873 vsyncshift += adjusted_mode->crtc_htotal;
2876 if (DISPLAY_VER(dev_priv) > 3)
2877 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
2880 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
2881 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
2882 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
2883 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
2884 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
2885 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
2887 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
2888 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
2889 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
2890 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
2891 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
2892 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
2894 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2895 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2896 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2898 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2899 (pipe == PIPE_B || pipe == PIPE_C))
2900 intel_de_write(dev_priv, VTOTAL(pipe),
2901 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
2905 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2907 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2908 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2909 int width = drm_rect_width(&crtc_state->pipe_src);
2910 int height = drm_rect_height(&crtc_state->pipe_src);
2911 enum pipe pipe = crtc->pipe;
2913 /* pipesrc controls the size that is scaled from, which should
2914 * always be the user's requested size.
2916 intel_de_write(dev_priv, PIPESRC(pipe),
2917 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2920 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2922 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2923 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2925 if (DISPLAY_VER(dev_priv) == 2)
2928 if (DISPLAY_VER(dev_priv) >= 9 ||
2929 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2930 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
2932 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
2935 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2936 struct intel_crtc_state *pipe_config)
2938 struct drm_device *dev = crtc->base.dev;
2939 struct drm_i915_private *dev_priv = to_i915(dev);
2940 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2943 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
2944 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
2945 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
2947 if (!transcoder_is_dsi(cpu_transcoder)) {
2948 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
2949 pipe_config->hw.adjusted_mode.crtc_hblank_start =
2951 pipe_config->hw.adjusted_mode.crtc_hblank_end =
2952 ((tmp >> 16) & 0xffff) + 1;
2954 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
2955 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
2956 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
2958 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
2959 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
2960 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
2962 if (!transcoder_is_dsi(cpu_transcoder)) {
2963 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
2964 pipe_config->hw.adjusted_mode.crtc_vblank_start =
2966 pipe_config->hw.adjusted_mode.crtc_vblank_end =
2967 ((tmp >> 16) & 0xffff) + 1;
2969 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
2970 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
2971 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
2973 if (intel_pipe_is_interlaced(pipe_config)) {
2974 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
2975 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
2976 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
2980 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2982 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2983 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2984 enum pipe master_pipe, pipe = crtc->pipe;
2990 master_pipe = bigjoiner_master_pipe(crtc_state);
2991 width = drm_rect_width(&crtc_state->pipe_src);
2993 drm_rect_translate_to(&crtc_state->pipe_src,
2994 (pipe - master_pipe) * width, 0);
2997 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
2998 struct intel_crtc_state *pipe_config)
3000 struct drm_device *dev = crtc->base.dev;
3001 struct drm_i915_private *dev_priv = to_i915(dev);
3004 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
3006 drm_rect_init(&pipe_config->pipe_src, 0, 0,
3007 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
3008 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
3010 intel_bigjoiner_adjust_pipe_src(pipe_config);
3013 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
3015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3016 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3020 * - We keep both pipes enabled on 830
3021 * - During modeset the pipe is still disabled and must remain so
3022 * - During fastset the pipe is already enabled and must remain so
3024 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
3025 pipeconf |= PIPECONF_ENABLE;
3027 if (crtc_state->double_wide)
3028 pipeconf |= PIPECONF_DOUBLE_WIDE;
3030 /* only g4x and later have fancy bpc/dither controls */
3031 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3032 IS_CHERRYVIEW(dev_priv)) {
3033 /* Bspec claims that we can't use dithering for 30bpp pipes. */
3034 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
3035 pipeconf |= PIPECONF_DITHER_EN |
3036 PIPECONF_DITHER_TYPE_SP;
3038 switch (crtc_state->pipe_bpp) {
3040 /* Case prevented by intel_choose_pipe_bpp_dither. */
3041 MISSING_CASE(crtc_state->pipe_bpp);
3044 pipeconf |= PIPECONF_BPC_6;
3047 pipeconf |= PIPECONF_BPC_8;
3050 pipeconf |= PIPECONF_BPC_10;
3055 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
3056 if (DISPLAY_VER(dev_priv) < 4 ||
3057 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3058 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
3060 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
3062 pipeconf |= PIPECONF_INTERLACE_PROGRESSIVE;
3065 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3066 crtc_state->limited_color_range)
3067 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
3069 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
3071 pipeconf |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3073 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
3074 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
3077 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
3079 if (IS_I830(dev_priv))
3082 return DISPLAY_VER(dev_priv) >= 4 ||
3083 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
3086 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
3088 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3089 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3092 if (!i9xx_has_pfit(dev_priv))
3095 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
3096 if (!(tmp & PFIT_ENABLE))
3099 /* Check whether the pfit is attached to our pipe. */
3100 if (DISPLAY_VER(dev_priv) < 4) {
3101 if (crtc->pipe != PIPE_B)
3104 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
3108 crtc_state->gmch_pfit.control = tmp;
3109 crtc_state->gmch_pfit.pgm_ratios =
3110 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
3113 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
3114 struct intel_crtc_state *pipe_config)
3116 struct drm_device *dev = crtc->base.dev;
3117 struct drm_i915_private *dev_priv = to_i915(dev);
3118 enum pipe pipe = crtc->pipe;
3121 int refclk = 100000;
3123 /* In case of DSI, DPLL will not be used */
3124 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
3127 vlv_dpio_get(dev_priv);
3128 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
3129 vlv_dpio_put(dev_priv);
3131 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
3132 clock.m2 = mdiv & DPIO_M2DIV_MASK;
3133 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
3134 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
3135 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
3137 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
3140 static void chv_crtc_clock_get(struct intel_crtc *crtc,
3141 struct intel_crtc_state *pipe_config)
3143 struct drm_device *dev = crtc->base.dev;
3144 struct drm_i915_private *dev_priv = to_i915(dev);
3145 enum pipe pipe = crtc->pipe;
3146 enum dpio_channel port = vlv_pipe_to_channel(pipe);
3148 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
3149 int refclk = 100000;
3151 /* In case of DSI, DPLL will not be used */
3152 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
3155 vlv_dpio_get(dev_priv);
3156 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
3157 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
3158 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
3159 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
3160 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
3161 vlv_dpio_put(dev_priv);
3163 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
3164 clock.m2 = (pll_dw0 & 0xff) << 22;
3165 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
3166 clock.m2 |= pll_dw2 & 0x3fffff;
3167 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
3168 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
3169 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
3171 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
3174 static enum intel_output_format
3175 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
3177 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3180 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
3182 if (tmp & PIPEMISC_YUV420_ENABLE) {
3183 /* We support 4:2:0 in full blend mode only */
3184 drm_WARN_ON(&dev_priv->drm,
3185 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
3187 return INTEL_OUTPUT_FORMAT_YCBCR420;
3188 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
3189 return INTEL_OUTPUT_FORMAT_YCBCR444;
3191 return INTEL_OUTPUT_FORMAT_RGB;
3195 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
3197 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3198 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
3199 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3200 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3203 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
3205 if (tmp & DISP_PIPE_GAMMA_ENABLE)
3206 crtc_state->gamma_enable = true;
3208 if (!HAS_GMCH(dev_priv) &&
3209 tmp & DISP_PIPE_CSC_ENABLE)
3210 crtc_state->csc_enable = true;
3213 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
3214 struct intel_crtc_state *pipe_config)
3216 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3217 enum intel_display_power_domain power_domain;
3218 intel_wakeref_t wakeref;
3222 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3223 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3227 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3228 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3229 pipe_config->shared_dpll = NULL;
3233 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
3234 if (!(tmp & PIPECONF_ENABLE))
3237 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3238 IS_CHERRYVIEW(dev_priv)) {
3239 switch (tmp & PIPECONF_BPC_MASK) {
3240 case PIPECONF_BPC_6:
3241 pipe_config->pipe_bpp = 18;
3243 case PIPECONF_BPC_8:
3244 pipe_config->pipe_bpp = 24;
3246 case PIPECONF_BPC_10:
3247 pipe_config->pipe_bpp = 30;
3255 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3256 (tmp & PIPECONF_COLOR_RANGE_SELECT))
3257 pipe_config->limited_color_range = true;
3259 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_I9XX, tmp);
3261 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1;
3263 if (IS_CHERRYVIEW(dev_priv))
3264 pipe_config->cgm_mode = intel_de_read(dev_priv,
3265 CGM_PIPE_MODE(crtc->pipe));
3267 i9xx_get_pipe_color_config(pipe_config);
3268 intel_color_get_config(pipe_config);
3270 if (DISPLAY_VER(dev_priv) < 4)
3271 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
3273 intel_get_transcoder_timings(crtc, pipe_config);
3274 intel_get_pipe_src_size(crtc, pipe_config);
3276 i9xx_get_pfit_config(pipe_config);
3278 if (DISPLAY_VER(dev_priv) >= 4) {
3279 /* No way to read it out on pipes B and C */
3280 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
3281 tmp = dev_priv->chv_dpll_md[crtc->pipe];
3283 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
3284 pipe_config->pixel_multiplier =
3285 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3286 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3287 pipe_config->dpll_hw_state.dpll_md = tmp;
3288 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
3289 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
3290 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
3291 pipe_config->pixel_multiplier =
3292 ((tmp & SDVO_MULTIPLIER_MASK)
3293 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3295 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3296 * port and will be fixed up in the encoder->get_config
3298 pipe_config->pixel_multiplier = 1;
3300 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
3302 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
3303 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
3305 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
3308 /* Mask out read-only status bits. */
3309 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
3310 DPLL_PORTC_READY_MASK |
3311 DPLL_PORTB_READY_MASK);
3314 if (IS_CHERRYVIEW(dev_priv))
3315 chv_crtc_clock_get(crtc, pipe_config);
3316 else if (IS_VALLEYVIEW(dev_priv))
3317 vlv_crtc_clock_get(crtc, pipe_config);
3319 i9xx_crtc_clock_get(crtc, pipe_config);
3322 * Normally the dotclock is filled in by the encoder .get_config()
3323 * but in case the pipe is enabled w/o any ports we need a sane
3326 pipe_config->hw.adjusted_mode.crtc_clock =
3327 pipe_config->port_clock / pipe_config->pixel_multiplier;
3332 intel_display_power_put(dev_priv, power_domain, wakeref);
3337 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3339 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3340 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3341 enum pipe pipe = crtc->pipe;
3345 * - During modeset the pipe is still disabled and must remain so
3346 * - During fastset the pipe is already enabled and must remain so
3348 if (!intel_crtc_needs_modeset(crtc_state))
3349 val |= PIPECONF_ENABLE;
3351 switch (crtc_state->pipe_bpp) {
3353 /* Case prevented by intel_choose_pipe_bpp_dither. */
3354 MISSING_CASE(crtc_state->pipe_bpp);
3357 val |= PIPECONF_BPC_6;
3360 val |= PIPECONF_BPC_8;
3363 val |= PIPECONF_BPC_10;
3366 val |= PIPECONF_BPC_12;
3370 if (crtc_state->dither)
3371 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP;
3373 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3374 val |= PIPECONF_INTERLACE_IF_ID_ILK;
3376 val |= PIPECONF_INTERLACE_PF_PD_ILK;
3379 * This would end up with an odd purple hue over
3380 * the entire display. Make sure we don't do it.
3382 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3383 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3385 if (crtc_state->limited_color_range &&
3386 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3387 val |= PIPECONF_COLOR_RANGE_SELECT;
3389 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3390 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
3392 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
3394 val |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3395 val |= PIPECONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3397 intel_de_write(dev_priv, PIPECONF(pipe), val);
3398 intel_de_posting_read(dev_priv, PIPECONF(pipe));
3401 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3403 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3405 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3409 * - During modeset the pipe is still disabled and must remain so
3410 * - During fastset the pipe is already enabled and must remain so
3412 if (!intel_crtc_needs_modeset(crtc_state))
3413 val |= PIPECONF_ENABLE;
3415 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3416 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP;
3418 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3419 val |= PIPECONF_INTERLACE_IF_ID_ILK;
3421 val |= PIPECONF_INTERLACE_PF_PD_ILK;
3423 if (IS_HASWELL(dev_priv) &&
3424 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3425 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
3427 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
3428 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
3431 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
3433 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3437 switch (crtc_state->pipe_bpp) {
3439 val |= PIPEMISC_BPC_6;
3442 val |= PIPEMISC_BPC_8;
3445 val |= PIPEMISC_BPC_10;
3448 /* Port output 12BPC defined for ADLP+ */
3449 if (DISPLAY_VER(dev_priv) > 12)
3450 val |= PIPEMISC_BPC_12_ADLP;
3453 MISSING_CASE(crtc_state->pipe_bpp);
3457 if (crtc_state->dither)
3458 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
3460 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3461 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3462 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
3464 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3465 val |= PIPEMISC_YUV420_ENABLE |
3466 PIPEMISC_YUV420_MODE_FULL_BLEND;
3468 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3469 val |= PIPEMISC_HDR_MODE_PRECISION;
3471 if (DISPLAY_VER(dev_priv) >= 12)
3472 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
3474 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
3477 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
3479 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3482 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
3484 switch (tmp & PIPEMISC_BPC_MASK) {
3485 case PIPEMISC_BPC_6:
3487 case PIPEMISC_BPC_8:
3489 case PIPEMISC_BPC_10:
3492 * PORT OUTPUT 12 BPC defined for ADLP+.
3495 * For previous platforms with DSI interface, bits 5:7
3496 * are used for storing pipe_bpp irrespective of dithering.
3497 * Since the value of 12 BPC is not defined for these bits
3498 * on older platforms, need to find a workaround for 12 BPC
3499 * MIPI DSI HW readout.
3501 case PIPEMISC_BPC_12_ADLP:
3502 if (DISPLAY_VER(dev_priv) > 12)
3511 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3514 * Account for spread spectrum to avoid
3515 * oversubscribing the link. Max center spread
3516 * is 2.5%; use 5% for safety's sake.
3518 u32 bps = target_clock * bpp * 21 / 20;
3519 return DIV_ROUND_UP(bps, link_bw * 8);
3522 void intel_get_m_n(struct drm_i915_private *i915,
3523 struct intel_link_m_n *m_n,
3524 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3525 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3527 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3528 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3529 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3530 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3531 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3534 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3535 enum transcoder transcoder,
3536 struct intel_link_m_n *m_n)
3538 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3539 enum pipe pipe = crtc->pipe;
3541 if (DISPLAY_VER(dev_priv) >= 5)
3542 intel_get_m_n(dev_priv, m_n,
3543 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3544 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3546 intel_get_m_n(dev_priv, m_n,
3547 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3548 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3551 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3552 enum transcoder transcoder,
3553 struct intel_link_m_n *m_n)
3555 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3557 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3560 intel_get_m_n(dev_priv, m_n,
3561 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3562 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3565 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
3568 drm_rect_init(&crtc_state->pch_pfit.dst,
3569 pos >> 16, pos & 0xffff,
3570 size >> 16, size & 0xffff);
3573 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
3575 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3576 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3577 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
3581 /* find scaler attached to this pipe */
3582 for (i = 0; i < crtc->num_scalers; i++) {
3585 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
3586 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
3590 crtc_state->pch_pfit.enabled = true;
3592 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
3593 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
3595 ilk_get_pfit_pos_size(crtc_state, pos, size);
3597 scaler_state->scalers[i].in_use = true;
3601 scaler_state->scaler_id = id;
3603 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
3605 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
3608 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3610 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3611 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3614 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3615 if ((ctl & PF_ENABLE) == 0)
3618 crtc_state->pch_pfit.enabled = true;
3620 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3621 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3623 ilk_get_pfit_pos_size(crtc_state, pos, size);
3626 * We currently do not free assignements of panel fitters on
3627 * ivb/hsw (since we don't use the higher upscaling modes which
3628 * differentiates them) so just WARN about this case for now.
3630 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 7 &&
3631 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
3634 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3635 struct intel_crtc_state *pipe_config)
3637 struct drm_device *dev = crtc->base.dev;
3638 struct drm_i915_private *dev_priv = to_i915(dev);
3639 enum intel_display_power_domain power_domain;
3640 intel_wakeref_t wakeref;
3644 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3645 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3649 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3650 pipe_config->shared_dpll = NULL;
3653 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
3654 if (!(tmp & PIPECONF_ENABLE))
3657 switch (tmp & PIPECONF_BPC_MASK) {
3658 case PIPECONF_BPC_6:
3659 pipe_config->pipe_bpp = 18;
3661 case PIPECONF_BPC_8:
3662 pipe_config->pipe_bpp = 24;
3664 case PIPECONF_BPC_10:
3665 pipe_config->pipe_bpp = 30;
3667 case PIPECONF_BPC_12:
3668 pipe_config->pipe_bpp = 36;
3674 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
3675 pipe_config->limited_color_range = true;
3677 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
3678 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
3679 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
3680 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3683 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3687 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_ILK, tmp);
3689 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1;
3691 pipe_config->msa_timing_delay = REG_FIELD_GET(PIPECONF_MSA_TIMING_DELAY_MASK, tmp);
3693 pipe_config->csc_mode = intel_de_read(dev_priv,
3694 PIPE_CSC_MODE(crtc->pipe));
3696 i9xx_get_pipe_color_config(pipe_config);
3697 intel_color_get_config(pipe_config);
3699 pipe_config->pixel_multiplier = 1;
3701 ilk_pch_get_config(pipe_config);
3703 intel_get_transcoder_timings(crtc, pipe_config);
3704 intel_get_pipe_src_size(crtc, pipe_config);
3706 ilk_get_pfit_config(pipe_config);
3711 intel_display_power_put(dev_priv, power_domain, wakeref);
3716 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3718 if (DISPLAY_VER(i915) >= 12)
3719 return BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3720 else if (DISPLAY_VER(i915) >= 11)
3721 return BIT(PIPE_B) | BIT(PIPE_C);
3726 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3727 enum transcoder cpu_transcoder)
3729 enum intel_display_power_domain power_domain;
3730 intel_wakeref_t wakeref;
3733 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3735 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3736 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3738 return tmp & TRANS_DDI_FUNC_ENABLE;
3741 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3742 u8 *master_pipes, u8 *slave_pipes)
3744 struct intel_crtc *crtc;
3749 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3750 bigjoiner_pipes(dev_priv)) {
3751 enum intel_display_power_domain power_domain;
3752 enum pipe pipe = crtc->pipe;
3753 intel_wakeref_t wakeref;
3755 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3756 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3757 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3759 if (!(tmp & BIG_JOINER_ENABLE))
3762 if (tmp & MASTER_BIG_JOINER_ENABLE)
3763 *master_pipes |= BIT(pipe);
3765 *slave_pipes |= BIT(pipe);
3768 if (DISPLAY_VER(dev_priv) < 13)
3771 power_domain = POWER_DOMAIN_PIPE(pipe);
3772 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3773 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3775 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3776 *master_pipes |= BIT(pipe);
3777 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3778 *slave_pipes |= BIT(pipe);
3782 /* Bigjoiner pipes should always be consecutive master and slave */
3783 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3784 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3785 *master_pipes, *slave_pipes);
3788 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3790 if ((slave_pipes & BIT(pipe)) == 0)
3793 /* ignore everything above our pipe */
3794 master_pipes &= ~GENMASK(7, pipe);
3796 /* highest remaining bit should be our master pipe */
3797 return fls(master_pipes) - 1;
3800 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3802 enum pipe master_pipe, next_master_pipe;
3804 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3806 if ((master_pipes & BIT(master_pipe)) == 0)
3809 /* ignore our master pipe and everything below it */
3810 master_pipes &= ~GENMASK(master_pipe, 0);
3811 /* make sure a high bit is set for the ffs() */
3812 master_pipes |= BIT(7);
3813 /* lowest remaining bit should be the next master pipe */
3814 next_master_pipe = ffs(master_pipes) - 1;
3816 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3819 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3821 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3823 if (DISPLAY_VER(i915) >= 11)
3824 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3826 return panel_transcoder_mask;
3829 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3831 struct drm_device *dev = crtc->base.dev;
3832 struct drm_i915_private *dev_priv = to_i915(dev);
3833 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3834 enum transcoder cpu_transcoder;
3835 u8 master_pipes, slave_pipes;
3836 u8 enabled_transcoders = 0;
3839 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3840 * consistency and less surprising code; it's in always on power).
3842 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3843 panel_transcoder_mask) {
3844 enum intel_display_power_domain power_domain;
3845 intel_wakeref_t wakeref;
3846 enum pipe trans_pipe;
3849 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3850 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3851 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3853 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3856 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3859 "unknown pipe linked to transcoder %s\n",
3860 transcoder_name(cpu_transcoder));
3862 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3863 case TRANS_DDI_EDP_INPUT_A_ON:
3864 trans_pipe = PIPE_A;
3866 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3867 trans_pipe = PIPE_B;
3869 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3870 trans_pipe = PIPE_C;
3872 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3873 trans_pipe = PIPE_D;
3877 if (trans_pipe == crtc->pipe)
3878 enabled_transcoders |= BIT(cpu_transcoder);
3881 /* single pipe or bigjoiner master */
3882 cpu_transcoder = (enum transcoder) crtc->pipe;
3883 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3884 enabled_transcoders |= BIT(cpu_transcoder);
3886 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3887 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3888 if (slave_pipes & BIT(crtc->pipe)) {
3889 cpu_transcoder = (enum transcoder)
3890 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3891 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3892 enabled_transcoders |= BIT(cpu_transcoder);
3895 return enabled_transcoders;
3898 static bool has_edp_transcoders(u8 enabled_transcoders)
3900 return enabled_transcoders & BIT(TRANSCODER_EDP);
3903 static bool has_dsi_transcoders(u8 enabled_transcoders)
3905 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3906 BIT(TRANSCODER_DSI_1));
3909 static bool has_pipe_transcoders(u8 enabled_transcoders)
3911 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3912 BIT(TRANSCODER_DSI_0) |
3913 BIT(TRANSCODER_DSI_1));
3916 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3917 u8 enabled_transcoders)
3919 /* Only one type of transcoder please */
3920 drm_WARN_ON(&i915->drm,
3921 has_edp_transcoders(enabled_transcoders) +
3922 has_dsi_transcoders(enabled_transcoders) +
3923 has_pipe_transcoders(enabled_transcoders) > 1);
3925 /* Only DSI transcoders can be ganged */
3926 drm_WARN_ON(&i915->drm,
3927 !has_dsi_transcoders(enabled_transcoders) &&
3928 !is_power_of_2(enabled_transcoders));
3931 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3932 struct intel_crtc_state *pipe_config,
3933 struct intel_display_power_domain_set *power_domain_set)
3935 struct drm_device *dev = crtc->base.dev;
3936 struct drm_i915_private *dev_priv = to_i915(dev);
3937 unsigned long enabled_transcoders;
3940 enabled_transcoders = hsw_enabled_transcoders(crtc);
3941 if (!enabled_transcoders)
3944 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3947 * With the exception of DSI we should only ever have
3948 * a single enabled transcoder. With DSI let's just
3949 * pick the first one.
3951 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3953 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3954 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3957 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3958 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3960 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3961 pipe_config->pch_pfit.force_thru = true;
3964 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
3966 return tmp & PIPECONF_ENABLE;
3969 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3970 struct intel_crtc_state *pipe_config,
3971 struct intel_display_power_domain_set *power_domain_set)
3973 struct drm_device *dev = crtc->base.dev;
3974 struct drm_i915_private *dev_priv = to_i915(dev);
3975 enum transcoder cpu_transcoder;
3979 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3981 cpu_transcoder = TRANSCODER_DSI_A;
3983 cpu_transcoder = TRANSCODER_DSI_C;
3985 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3986 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3990 * The PLL needs to be enabled with a valid divider
3991 * configuration, otherwise accessing DSI registers will hang
3992 * the machine. See BSpec North Display Engine
3993 * registers/MIPI[BXT]. We can break out here early, since we
3994 * need the same DSI PLL to be enabled for both DSI ports.
3996 if (!bxt_dsi_pll_is_enabled(dev_priv))
3999 /* XXX: this works for video mode only */
4000 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
4001 if (!(tmp & DPI_ENABLE))
4004 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
4005 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
4008 pipe_config->cpu_transcoder = cpu_transcoder;
4012 return transcoder_is_dsi(pipe_config->cpu_transcoder);
4015 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
4017 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4018 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4019 u8 master_pipes, slave_pipes;
4020 enum pipe pipe = crtc->pipe;
4022 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
4024 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
4027 crtc_state->bigjoiner_pipes =
4028 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
4029 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
4032 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
4033 struct intel_crtc_state *pipe_config)
4035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4036 struct intel_display_power_domain_set power_domain_set = { };
4040 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
4041 POWER_DOMAIN_PIPE(crtc->pipe)))
4044 pipe_config->shared_dpll = NULL;
4046 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
4048 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4049 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
4050 drm_WARN_ON(&dev_priv->drm, active);
4057 intel_dsc_get_config(pipe_config);
4058 intel_bigjoiner_get_config(pipe_config);
4060 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
4061 DISPLAY_VER(dev_priv) >= 11)
4062 intel_get_transcoder_timings(crtc, pipe_config);
4064 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
4065 intel_vrr_get_config(crtc, pipe_config);
4067 intel_get_pipe_src_size(crtc, pipe_config);
4069 if (IS_HASWELL(dev_priv)) {
4070 u32 tmp = intel_de_read(dev_priv,
4071 PIPECONF(pipe_config->cpu_transcoder));
4073 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
4074 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
4076 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
4078 pipe_config->output_format =
4079 bdw_get_pipemisc_output_format(crtc);
4082 pipe_config->gamma_mode = intel_de_read(dev_priv,
4083 GAMMA_MODE(crtc->pipe));
4085 pipe_config->csc_mode = intel_de_read(dev_priv,
4086 PIPE_CSC_MODE(crtc->pipe));
4088 if (DISPLAY_VER(dev_priv) >= 9) {
4089 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
4091 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
4092 pipe_config->gamma_enable = true;
4094 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
4095 pipe_config->csc_enable = true;
4097 i9xx_get_pipe_color_config(pipe_config);
4100 intel_color_get_config(pipe_config);
4102 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
4103 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
4104 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
4105 pipe_config->ips_linetime =
4106 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
4108 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
4109 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
4110 if (DISPLAY_VER(dev_priv) >= 9)
4111 skl_get_pfit_config(pipe_config);
4113 ilk_get_pfit_config(pipe_config);
4116 hsw_ips_get_config(pipe_config);
4118 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
4119 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4120 pipe_config->pixel_multiplier =
4121 intel_de_read(dev_priv,
4122 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
4124 pipe_config->pixel_multiplier = 1;
4127 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4128 tmp = intel_de_read(dev_priv, CHICKEN_TRANS(pipe_config->cpu_transcoder));
4130 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
4132 /* no idea if this is correct */
4133 pipe_config->framestart_delay = 1;
4137 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
4142 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
4144 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4145 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4147 if (!i915->display.funcs.display->get_pipe_config(crtc, crtc_state))
4150 crtc_state->hw.active = true;
4152 intel_crtc_readout_derived_state(crtc_state);
4157 /* VESA 640x480x72Hz mode to set on the pipe */
4158 static const struct drm_display_mode load_detect_mode = {
4159 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
4160 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
4163 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
4164 struct drm_crtc *crtc)
4166 struct drm_plane *plane;
4167 struct drm_plane_state *plane_state;
4170 ret = drm_atomic_add_affected_planes(state, crtc);
4174 for_each_new_plane_in_state(state, plane, plane_state, i) {
4175 if (plane_state->crtc != crtc)
4178 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
4182 drm_atomic_set_fb_for_plane(plane_state, NULL);
4188 int intel_get_load_detect_pipe(struct drm_connector *connector,
4189 struct intel_load_detect_pipe *old,
4190 struct drm_modeset_acquire_ctx *ctx)
4192 struct intel_encoder *encoder =
4193 intel_attached_encoder(to_intel_connector(connector));
4194 struct intel_crtc *possible_crtc;
4195 struct intel_crtc *crtc = NULL;
4196 struct drm_device *dev = encoder->base.dev;
4197 struct drm_i915_private *dev_priv = to_i915(dev);
4198 struct drm_mode_config *config = &dev->mode_config;
4199 struct drm_atomic_state *state = NULL, *restore_state = NULL;
4200 struct drm_connector_state *connector_state;
4201 struct intel_crtc_state *crtc_state;
4204 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
4205 connector->base.id, connector->name,
4206 encoder->base.base.id, encoder->base.name);
4208 old->restore_state = NULL;
4210 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
4213 * Algorithm gets a little messy:
4215 * - if the connector already has an assigned crtc, use it (but make
4216 * sure it's on first)
4218 * - try to find the first unused crtc that can drive this connector,
4219 * and use that if we find one
4222 /* See if we already have a CRTC for this connector */
4223 if (connector->state->crtc) {
4224 crtc = to_intel_crtc(connector->state->crtc);
4226 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
4230 /* Make sure the crtc and connector are running */
4234 /* Find an unused one (if possible) */
4235 for_each_intel_crtc(dev, possible_crtc) {
4236 if (!(encoder->base.possible_crtcs &
4237 drm_crtc_mask(&possible_crtc->base)))
4240 ret = drm_modeset_lock(&possible_crtc->base.mutex, ctx);
4244 if (possible_crtc->base.state->enable) {
4245 drm_modeset_unlock(&possible_crtc->base.mutex);
4249 crtc = possible_crtc;
4254 * If we didn't find an unused CRTC, don't use any.
4257 drm_dbg_kms(&dev_priv->drm,
4258 "no pipe available for load-detect\n");
4264 state = drm_atomic_state_alloc(dev);
4265 restore_state = drm_atomic_state_alloc(dev);
4266 if (!state || !restore_state) {
4271 state->acquire_ctx = ctx;
4272 restore_state->acquire_ctx = ctx;
4274 connector_state = drm_atomic_get_connector_state(state, connector);
4275 if (IS_ERR(connector_state)) {
4276 ret = PTR_ERR(connector_state);
4280 ret = drm_atomic_set_crtc_for_connector(connector_state, &crtc->base);
4284 crtc_state = intel_atomic_get_crtc_state(state, crtc);
4285 if (IS_ERR(crtc_state)) {
4286 ret = PTR_ERR(crtc_state);
4290 crtc_state->uapi.active = true;
4292 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
4297 ret = intel_modeset_disable_planes(state, &crtc->base);
4301 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
4303 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, &crtc->base));
4305 ret = drm_atomic_add_affected_planes(restore_state, &crtc->base);
4307 drm_dbg_kms(&dev_priv->drm,
4308 "Failed to create a copy of old state to restore: %i\n",
4313 ret = drm_atomic_commit(state);
4315 drm_dbg_kms(&dev_priv->drm,
4316 "failed to set mode on load-detect pipe\n");
4320 old->restore_state = restore_state;
4321 drm_atomic_state_put(state);
4323 /* let the connector get through one full cycle before testing */
4324 intel_crtc_wait_for_next_vblank(crtc);
4330 drm_atomic_state_put(state);
4333 if (restore_state) {
4334 drm_atomic_state_put(restore_state);
4335 restore_state = NULL;
4338 if (ret == -EDEADLK)
4344 void intel_release_load_detect_pipe(struct drm_connector *connector,
4345 struct intel_load_detect_pipe *old,
4346 struct drm_modeset_acquire_ctx *ctx)
4348 struct intel_encoder *intel_encoder =
4349 intel_attached_encoder(to_intel_connector(connector));
4350 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
4351 struct drm_encoder *encoder = &intel_encoder->base;
4352 struct drm_atomic_state *state = old->restore_state;
4355 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
4356 connector->base.id, connector->name,
4357 encoder->base.id, encoder->name);
4362 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4364 drm_dbg_kms(&i915->drm,
4365 "Couldn't release load detect pipe: %i\n", ret);
4366 drm_atomic_state_put(state);
4369 static int i9xx_pll_refclk(struct drm_device *dev,
4370 const struct intel_crtc_state *pipe_config)
4372 struct drm_i915_private *dev_priv = to_i915(dev);
4373 u32 dpll = pipe_config->dpll_hw_state.dpll;
4375 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
4376 return dev_priv->vbt.lvds_ssc_freq;
4377 else if (HAS_PCH_SPLIT(dev_priv))
4379 else if (DISPLAY_VER(dev_priv) != 2)
4385 /* Returns the clock of the currently programmed mode of the given pipe. */
4386 void i9xx_crtc_clock_get(struct intel_crtc *crtc,
4387 struct intel_crtc_state *pipe_config)
4389 struct drm_device *dev = crtc->base.dev;
4390 struct drm_i915_private *dev_priv = to_i915(dev);
4391 u32 dpll = pipe_config->dpll_hw_state.dpll;
4395 int refclk = i9xx_pll_refclk(dev, pipe_config);
4397 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
4398 fp = pipe_config->dpll_hw_state.fp0;
4400 fp = pipe_config->dpll_hw_state.fp1;
4402 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
4403 if (IS_PINEVIEW(dev_priv)) {
4404 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
4405 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
4407 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
4408 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
4411 if (DISPLAY_VER(dev_priv) != 2) {
4412 if (IS_PINEVIEW(dev_priv))
4413 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
4414 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
4416 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
4417 DPLL_FPA01_P1_POST_DIV_SHIFT);
4419 switch (dpll & DPLL_MODE_MASK) {
4420 case DPLLB_MODE_DAC_SERIAL:
4421 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
4424 case DPLLB_MODE_LVDS:
4425 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
4429 drm_dbg_kms(&dev_priv->drm,
4430 "Unknown DPLL mode %08x in programmed "
4431 "mode\n", (int)(dpll & DPLL_MODE_MASK));
4435 if (IS_PINEVIEW(dev_priv))
4436 port_clock = pnv_calc_dpll_params(refclk, &clock);
4438 port_clock = i9xx_calc_dpll_params(refclk, &clock);
4440 enum pipe lvds_pipe;
4442 if (IS_I85X(dev_priv) &&
4443 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) &&
4444 lvds_pipe == crtc->pipe) {
4445 u32 lvds = intel_de_read(dev_priv, LVDS);
4447 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
4448 DPLL_FPA01_P1_POST_DIV_SHIFT);
4450 if (lvds & LVDS_CLKB_POWER_UP)
4455 if (dpll & PLL_P1_DIVIDE_BY_TWO)
4458 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
4459 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
4461 if (dpll & PLL_P2_DIVIDE_BY_4)
4467 port_clock = i9xx_calc_dpll_params(refclk, &clock);
4471 * This value includes pixel_multiplier. We will use
4472 * port_clock to compute adjusted_mode.crtc_clock in the
4473 * encoder's get_config() function.
4475 pipe_config->port_clock = port_clock;
4478 int intel_dotclock_calculate(int link_freq,
4479 const struct intel_link_m_n *m_n)
4482 * The calculation for the data clock is:
4483 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
4484 * But we want to avoid losing precison if possible, so:
4485 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
4487 * and the link clock is simpler:
4488 * link_clock = (m * link_clock) / n
4494 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
4497 /* Returns the currently programmed mode of the given encoder. */
4498 struct drm_display_mode *
4499 intel_encoder_current_mode(struct intel_encoder *encoder)
4501 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4502 struct intel_crtc_state *crtc_state;
4503 struct drm_display_mode *mode;
4504 struct intel_crtc *crtc;
4507 if (!encoder->get_hw_state(encoder, &pipe))
4510 crtc = intel_crtc_for_pipe(dev_priv, pipe);
4512 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
4516 crtc_state = intel_crtc_state_alloc(crtc);
4522 if (!intel_crtc_get_pipe_config(crtc_state)) {
4528 intel_encoder_get_config(encoder, crtc_state);
4530 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4537 static bool encoders_cloneable(const struct intel_encoder *a,
4538 const struct intel_encoder *b)
4540 /* masks could be asymmetric, so check both ways */
4541 return a == b || (a->cloneable & (1 << b->type) &&
4542 b->cloneable & (1 << a->type));
4545 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4546 struct intel_crtc *crtc,
4547 struct intel_encoder *encoder)
4549 struct intel_encoder *source_encoder;
4550 struct drm_connector *connector;
4551 struct drm_connector_state *connector_state;
4554 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4555 if (connector_state->crtc != &crtc->base)
4559 to_intel_encoder(connector_state->best_encoder);
4560 if (!encoders_cloneable(encoder, source_encoder))
4567 static int icl_add_linked_planes(struct intel_atomic_state *state)
4569 struct intel_plane *plane, *linked;
4570 struct intel_plane_state *plane_state, *linked_plane_state;
4573 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4574 linked = plane_state->planar_linked_plane;
4579 linked_plane_state = intel_atomic_get_plane_state(state, linked);
4580 if (IS_ERR(linked_plane_state))
4581 return PTR_ERR(linked_plane_state);
4583 drm_WARN_ON(state->base.dev,
4584 linked_plane_state->planar_linked_plane != plane);
4585 drm_WARN_ON(state->base.dev,
4586 linked_plane_state->planar_slave == plane_state->planar_slave);
4592 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
4594 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4595 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4596 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
4597 struct intel_plane *plane, *linked;
4598 struct intel_plane_state *plane_state;
4601 if (DISPLAY_VER(dev_priv) < 11)
4605 * Destroy all old plane links and make the slave plane invisible
4606 * in the crtc_state->active_planes mask.
4608 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4609 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
4612 plane_state->planar_linked_plane = NULL;
4613 if (plane_state->planar_slave && !plane_state->uapi.visible) {
4614 crtc_state->enabled_planes &= ~BIT(plane->id);
4615 crtc_state->active_planes &= ~BIT(plane->id);
4616 crtc_state->update_planes |= BIT(plane->id);
4617 crtc_state->data_rate[plane->id] = 0;
4618 crtc_state->rel_data_rate[plane->id] = 0;
4621 plane_state->planar_slave = false;
4624 if (!crtc_state->nv12_planes)
4627 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4628 struct intel_plane_state *linked_state = NULL;
4630 if (plane->pipe != crtc->pipe ||
4631 !(crtc_state->nv12_planes & BIT(plane->id)))
4634 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4635 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4638 if (crtc_state->active_planes & BIT(linked->id))
4641 linked_state = intel_atomic_get_plane_state(state, linked);
4642 if (IS_ERR(linked_state))
4643 return PTR_ERR(linked_state);
4648 if (!linked_state) {
4649 drm_dbg_kms(&dev_priv->drm,
4650 "Need %d free Y planes for planar YUV\n",
4651 hweight8(crtc_state->nv12_planes));
4656 plane_state->planar_linked_plane = linked;
4658 linked_state->planar_slave = true;
4659 linked_state->planar_linked_plane = plane;
4660 crtc_state->enabled_planes |= BIT(linked->id);
4661 crtc_state->active_planes |= BIT(linked->id);
4662 crtc_state->update_planes |= BIT(linked->id);
4663 crtc_state->data_rate[linked->id] =
4664 crtc_state->data_rate_y[plane->id];
4665 crtc_state->rel_data_rate[linked->id] =
4666 crtc_state->rel_data_rate_y[plane->id];
4667 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4668 linked->base.name, plane->base.name);
4670 /* Copy parameters to slave plane */
4671 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4672 linked_state->color_ctl = plane_state->color_ctl;
4673 linked_state->view = plane_state->view;
4674 linked_state->decrypt = plane_state->decrypt;
4676 intel_plane_copy_hw_state(linked_state, plane_state);
4677 linked_state->uapi.src = plane_state->uapi.src;
4678 linked_state->uapi.dst = plane_state->uapi.dst;
4680 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4681 if (linked->id == PLANE_SPRITE5)
4682 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4683 else if (linked->id == PLANE_SPRITE4)
4684 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4685 else if (linked->id == PLANE_SPRITE3)
4686 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4687 else if (linked->id == PLANE_SPRITE2)
4688 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4690 MISSING_CASE(linked->id);
4697 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4699 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4700 struct intel_atomic_state *state =
4701 to_intel_atomic_state(new_crtc_state->uapi.state);
4702 const struct intel_crtc_state *old_crtc_state =
4703 intel_atomic_get_old_crtc_state(state, crtc);
4705 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4708 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4710 const struct drm_display_mode *pipe_mode =
4711 &crtc_state->hw.pipe_mode;
4714 if (!crtc_state->hw.enable)
4717 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4718 pipe_mode->crtc_clock);
4720 return min(linetime_wm, 0x1ff);
4723 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4724 const struct intel_cdclk_state *cdclk_state)
4726 const struct drm_display_mode *pipe_mode =
4727 &crtc_state->hw.pipe_mode;
4730 if (!crtc_state->hw.enable)
4733 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4734 cdclk_state->logical.cdclk);
4736 return min(linetime_wm, 0x1ff);
4739 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4741 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4742 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4743 const struct drm_display_mode *pipe_mode =
4744 &crtc_state->hw.pipe_mode;
4747 if (!crtc_state->hw.enable)
4750 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4751 crtc_state->pixel_rate);
4753 /* Display WA #1135: BXT:ALL GLK:ALL */
4754 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4755 dev_priv->ipc_enabled)
4758 return min(linetime_wm, 0x1ff);
4761 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4762 struct intel_crtc *crtc)
4764 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4765 struct intel_crtc_state *crtc_state =
4766 intel_atomic_get_new_crtc_state(state, crtc);
4767 const struct intel_cdclk_state *cdclk_state;
4769 if (DISPLAY_VER(dev_priv) >= 9)
4770 crtc_state->linetime = skl_linetime_wm(crtc_state);
4772 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4774 if (!hsw_crtc_supports_ips(crtc))
4777 cdclk_state = intel_atomic_get_cdclk_state(state);
4778 if (IS_ERR(cdclk_state))
4779 return PTR_ERR(cdclk_state);
4781 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4787 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4788 struct intel_crtc *crtc)
4790 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4791 struct intel_crtc_state *crtc_state =
4792 intel_atomic_get_new_crtc_state(state, crtc);
4793 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
4796 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4797 mode_changed && !crtc_state->hw.active)
4798 crtc_state->update_wm_post = true;
4801 ret = intel_dpll_crtc_compute_clock(state, crtc);
4805 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4811 * May need to update pipe gamma enable bits
4812 * when C8 planes are getting enabled/disabled.
4814 if (c8_planes_changed(crtc_state))
4815 crtc_state->uapi.color_mgmt_changed = true;
4817 if (mode_changed || crtc_state->update_pipe ||
4818 crtc_state->uapi.color_mgmt_changed) {
4819 ret = intel_color_check(crtc_state);
4824 ret = intel_compute_pipe_wm(state, crtc);
4826 drm_dbg_kms(&dev_priv->drm,
4827 "Target pipe watermarks are invalid\n");
4832 * Calculate 'intermediate' watermarks that satisfy both the
4833 * old state and the new state. We can program these
4836 ret = intel_compute_intermediate_wm(state, crtc);
4838 drm_dbg_kms(&dev_priv->drm,
4839 "No valid intermediate pipe watermarks are possible\n");
4843 if (DISPLAY_VER(dev_priv) >= 9) {
4844 if (mode_changed || crtc_state->update_pipe) {
4845 ret = skl_update_scaler_crtc(crtc_state);
4850 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4855 if (HAS_IPS(dev_priv)) {
4856 ret = hsw_ips_compute_config(state, crtc);
4861 if (DISPLAY_VER(dev_priv) >= 9 ||
4862 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4863 ret = hsw_compute_linetime_wm(state, crtc);
4869 ret = intel_psr2_sel_fetch_update(state, crtc);
4877 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4878 struct intel_crtc_state *crtc_state)
4880 struct drm_connector *connector = conn_state->connector;
4881 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4882 const struct drm_display_info *info = &connector->display_info;
4885 switch (conn_state->max_bpc) {
4899 MISSING_CASE(conn_state->max_bpc);
4903 if (bpp < crtc_state->pipe_bpp) {
4904 drm_dbg_kms(&i915->drm,
4905 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4906 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4907 connector->base.id, connector->name,
4909 3 * conn_state->max_requested_bpc,
4910 crtc_state->pipe_bpp);
4912 crtc_state->pipe_bpp = bpp;
4919 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4920 struct intel_crtc *crtc)
4922 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4923 struct intel_crtc_state *crtc_state =
4924 intel_atomic_get_new_crtc_state(state, crtc);
4925 struct drm_connector *connector;
4926 struct drm_connector_state *connector_state;
4929 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4930 IS_CHERRYVIEW(dev_priv)))
4932 else if (DISPLAY_VER(dev_priv) >= 5)
4937 crtc_state->pipe_bpp = bpp;
4939 /* Clamp display bpp to connector max bpp */
4940 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4943 if (connector_state->crtc != &crtc->base)
4946 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4954 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4956 struct drm_device *dev = state->base.dev;
4957 struct drm_connector *connector;
4958 struct drm_connector_list_iter conn_iter;
4959 unsigned int used_ports = 0;
4960 unsigned int used_mst_ports = 0;
4964 * We're going to peek into connector->state,
4965 * hence connection_mutex must be held.
4967 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4970 * Walk the connector list instead of the encoder
4971 * list to detect the problem on ddi platforms
4972 * where there's just one encoder per digital port.
4974 drm_connector_list_iter_begin(dev, &conn_iter);
4975 drm_for_each_connector_iter(connector, &conn_iter) {
4976 struct drm_connector_state *connector_state;
4977 struct intel_encoder *encoder;
4980 drm_atomic_get_new_connector_state(&state->base,
4982 if (!connector_state)
4983 connector_state = connector->state;
4985 if (!connector_state->best_encoder)
4988 encoder = to_intel_encoder(connector_state->best_encoder);
4990 drm_WARN_ON(dev, !connector_state->crtc);
4992 switch (encoder->type) {
4993 case INTEL_OUTPUT_DDI:
4994 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4997 case INTEL_OUTPUT_DP:
4998 case INTEL_OUTPUT_HDMI:
4999 case INTEL_OUTPUT_EDP:
5000 /* the same port mustn't appear more than once */
5001 if (used_ports & BIT(encoder->port))
5004 used_ports |= BIT(encoder->port);
5006 case INTEL_OUTPUT_DP_MST:
5014 drm_connector_list_iter_end(&conn_iter);
5016 /* can't mix MST and SST/HDMI on the same port */
5017 if (used_ports & used_mst_ports)
5024 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
5025 struct intel_crtc *crtc)
5027 struct intel_crtc_state *crtc_state =
5028 intel_atomic_get_new_crtc_state(state, crtc);
5030 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
5032 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
5033 crtc_state->uapi.degamma_lut);
5034 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
5035 crtc_state->uapi.gamma_lut);
5036 drm_property_replace_blob(&crtc_state->hw.ctm,
5037 crtc_state->uapi.ctm);
5041 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
5042 struct intel_crtc *crtc)
5044 struct intel_crtc_state *crtc_state =
5045 intel_atomic_get_new_crtc_state(state, crtc);
5047 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
5049 crtc_state->hw.enable = crtc_state->uapi.enable;
5050 crtc_state->hw.active = crtc_state->uapi.active;
5051 drm_mode_copy(&crtc_state->hw.mode,
5052 &crtc_state->uapi.mode);
5053 drm_mode_copy(&crtc_state->hw.adjusted_mode,
5054 &crtc_state->uapi.adjusted_mode);
5055 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
5057 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
5061 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
5062 struct intel_crtc *slave_crtc)
5064 struct intel_crtc_state *slave_crtc_state =
5065 intel_atomic_get_new_crtc_state(state, slave_crtc);
5066 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
5067 const struct intel_crtc_state *master_crtc_state =
5068 intel_atomic_get_new_crtc_state(state, master_crtc);
5070 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
5071 master_crtc_state->hw.degamma_lut);
5072 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
5073 master_crtc_state->hw.gamma_lut);
5074 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
5075 master_crtc_state->hw.ctm);
5077 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
5081 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
5082 struct intel_crtc *slave_crtc)
5084 struct intel_crtc_state *slave_crtc_state =
5085 intel_atomic_get_new_crtc_state(state, slave_crtc);
5086 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
5087 const struct intel_crtc_state *master_crtc_state =
5088 intel_atomic_get_new_crtc_state(state, master_crtc);
5089 struct intel_crtc_state *saved_state;
5091 WARN_ON(master_crtc_state->bigjoiner_pipes !=
5092 slave_crtc_state->bigjoiner_pipes);
5094 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
5098 /* preserve some things from the slave's original crtc state */
5099 saved_state->uapi = slave_crtc_state->uapi;
5100 saved_state->scaler_state = slave_crtc_state->scaler_state;
5101 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
5102 saved_state->dpll_hw_state = slave_crtc_state->dpll_hw_state;
5103 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
5105 intel_crtc_free_hw_state(slave_crtc_state);
5106 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
5109 /* Re-init hw state */
5110 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
5111 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
5112 slave_crtc_state->hw.active = master_crtc_state->hw.active;
5113 drm_mode_copy(&slave_crtc_state->hw.mode,
5114 &master_crtc_state->hw.mode);
5115 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
5116 &master_crtc_state->hw.pipe_mode);
5117 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
5118 &master_crtc_state->hw.adjusted_mode);
5119 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
5121 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
5123 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
5124 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
5125 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
5127 WARN_ON(master_crtc_state->bigjoiner_pipes !=
5128 slave_crtc_state->bigjoiner_pipes);
5134 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
5135 struct intel_crtc *crtc)
5137 struct intel_crtc_state *crtc_state =
5138 intel_atomic_get_new_crtc_state(state, crtc);
5139 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5140 struct intel_crtc_state *saved_state;
5142 saved_state = intel_crtc_state_alloc(crtc);
5146 /* free the old crtc_state->hw members */
5147 intel_crtc_free_hw_state(crtc_state);
5149 /* FIXME: before the switch to atomic started, a new pipe_config was
5150 * kzalloc'd. Code that depends on any field being zero should be
5151 * fixed, so that the crtc_state can be safely duplicated. For now,
5152 * only fields that are know to not cause problems are preserved. */
5154 saved_state->uapi = crtc_state->uapi;
5155 saved_state->scaler_state = crtc_state->scaler_state;
5156 saved_state->shared_dpll = crtc_state->shared_dpll;
5157 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
5158 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
5159 sizeof(saved_state->icl_port_dplls));
5160 saved_state->crc_enabled = crtc_state->crc_enabled;
5161 if (IS_G4X(dev_priv) ||
5162 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5163 saved_state->wm = crtc_state->wm;
5165 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
5168 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
5174 intel_modeset_pipe_config(struct intel_atomic_state *state,
5175 struct intel_crtc *crtc)
5177 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5178 struct intel_crtc_state *crtc_state =
5179 intel_atomic_get_new_crtc_state(state, crtc);
5180 struct drm_connector *connector;
5181 struct drm_connector_state *connector_state;
5182 int pipe_src_w, pipe_src_h;
5183 int base_bpp, ret, i;
5186 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
5188 crtc_state->framestart_delay = 1;
5191 * Sanitize sync polarity flags based on requested ones. If neither
5192 * positive or negative polarity is requested, treat this as meaning
5193 * negative polarity.
5195 if (!(crtc_state->hw.adjusted_mode.flags &
5196 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
5197 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
5199 if (!(crtc_state->hw.adjusted_mode.flags &
5200 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
5201 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
5203 ret = compute_baseline_pipe_bpp(state, crtc);
5207 base_bpp = crtc_state->pipe_bpp;
5210 * Determine the real pipe dimensions. Note that stereo modes can
5211 * increase the actual pipe size due to the frame doubling and
5212 * insertion of additional space for blanks between the frame. This
5213 * is stored in the crtc timings. We use the requested mode to do this
5214 * computation to clearly distinguish it from the adjusted mode, which
5215 * can be changed by the connectors in the below retry loop.
5217 drm_mode_get_hv_timing(&crtc_state->hw.mode,
5218 &pipe_src_w, &pipe_src_h);
5219 drm_rect_init(&crtc_state->pipe_src, 0, 0,
5220 pipe_src_w, pipe_src_h);
5222 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5223 struct intel_encoder *encoder =
5224 to_intel_encoder(connector_state->best_encoder);
5226 if (connector_state->crtc != &crtc->base)
5229 if (!check_single_encoder_cloning(state, crtc, encoder)) {
5230 drm_dbg_kms(&i915->drm,
5231 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
5232 encoder->base.base.id, encoder->base.name);
5237 * Determine output_types before calling the .compute_config()
5238 * hooks so that the hooks can use this information safely.
5240 if (encoder->compute_output_type)
5241 crtc_state->output_types |=
5242 BIT(encoder->compute_output_type(encoder, crtc_state,
5245 crtc_state->output_types |= BIT(encoder->type);
5249 /* Ensure the port clock defaults are reset when retrying. */
5250 crtc_state->port_clock = 0;
5251 crtc_state->pixel_multiplier = 1;
5253 /* Fill in default crtc timings, allow encoders to overwrite them. */
5254 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
5255 CRTC_STEREO_DOUBLE);
5257 /* Pass our mode to the connectors and the CRTC to give them a chance to
5258 * adjust it according to limitations or connector properties, and also
5259 * a chance to reject the mode entirely.
5261 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5262 struct intel_encoder *encoder =
5263 to_intel_encoder(connector_state->best_encoder);
5265 if (connector_state->crtc != &crtc->base)
5268 ret = encoder->compute_config(encoder, crtc_state,
5270 if (ret == -EDEADLK)
5273 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
5274 encoder->base.base.id, encoder->base.name, ret);
5279 /* Set default port clock if not overwritten by the encoder. Needs to be
5280 * done afterwards in case the encoder adjusts the mode. */
5281 if (!crtc_state->port_clock)
5282 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
5283 * crtc_state->pixel_multiplier;
5285 ret = intel_crtc_compute_config(state, crtc);
5286 if (ret == -EDEADLK)
5288 if (ret == -EAGAIN) {
5289 if (drm_WARN(&i915->drm, !retry,
5290 "[CRTC:%d:%s] loop in pipe configuration computation\n",
5291 crtc->base.base.id, crtc->base.name))
5294 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] bw constrained, retrying\n",
5295 crtc->base.base.id, crtc->base.name);
5300 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
5301 crtc->base.base.id, crtc->base.name, ret);
5305 /* Dithering seems to not pass-through bits correctly when it should, so
5306 * only enable it on 6bpc panels and when its not a compliance
5307 * test requesting 6bpc video pattern.
5309 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
5310 !crtc_state->dither_force_disable;
5311 drm_dbg_kms(&i915->drm,
5312 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
5313 crtc->base.base.id, crtc->base.name,
5314 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
5320 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
5321 struct intel_crtc *crtc)
5323 struct intel_crtc_state *crtc_state =
5324 intel_atomic_get_new_crtc_state(state, crtc);
5325 struct drm_connector_state *conn_state;
5326 struct drm_connector *connector;
5329 intel_bigjoiner_adjust_pipe_src(crtc_state);
5331 for_each_new_connector_in_state(&state->base, connector,
5333 struct intel_encoder *encoder =
5334 to_intel_encoder(conn_state->best_encoder);
5337 if (conn_state->crtc != &crtc->base ||
5338 !encoder->compute_config_late)
5341 ret = encoder->compute_config_late(encoder, crtc_state,
5350 bool intel_fuzzy_clock_check(int clock1, int clock2)
5354 if (clock1 == clock2)
5357 if (!clock1 || !clock2)
5360 diff = abs(clock1 - clock2);
5362 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
5369 intel_compare_m_n(unsigned int m, unsigned int n,
5370 unsigned int m2, unsigned int n2,
5373 if (m == m2 && n == n2)
5376 if (exact || !m || !n || !m2 || !n2)
5379 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
5386 } else if (n < n2) {
5396 return intel_fuzzy_clock_check(m, m2);
5400 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
5401 const struct intel_link_m_n *m2_n2,
5404 return m_n->tu == m2_n2->tu &&
5405 intel_compare_m_n(m_n->data_m, m_n->data_n,
5406 m2_n2->data_m, m2_n2->data_n, exact) &&
5407 intel_compare_m_n(m_n->link_m, m_n->link_n,
5408 m2_n2->link_m, m2_n2->link_n, exact);
5412 intel_compare_infoframe(const union hdmi_infoframe *a,
5413 const union hdmi_infoframe *b)
5415 return memcmp(a, b, sizeof(*a)) == 0;
5419 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
5420 const struct drm_dp_vsc_sdp *b)
5422 return memcmp(a, b, sizeof(*a)) == 0;
5426 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
5427 bool fastset, const char *name,
5428 const union hdmi_infoframe *a,
5429 const union hdmi_infoframe *b)
5432 if (!drm_debug_enabled(DRM_UT_KMS))
5435 drm_dbg_kms(&dev_priv->drm,
5436 "fastset mismatch in %s infoframe\n", name);
5437 drm_dbg_kms(&dev_priv->drm, "expected:\n");
5438 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
5439 drm_dbg_kms(&dev_priv->drm, "found:\n");
5440 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
5442 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
5443 drm_err(&dev_priv->drm, "expected:\n");
5444 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
5445 drm_err(&dev_priv->drm, "found:\n");
5446 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
5451 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
5452 bool fastset, const char *name,
5453 const struct drm_dp_vsc_sdp *a,
5454 const struct drm_dp_vsc_sdp *b)
5457 if (!drm_debug_enabled(DRM_UT_KMS))
5460 drm_dbg_kms(&dev_priv->drm,
5461 "fastset mismatch in %s dp sdp\n", name);
5462 drm_dbg_kms(&dev_priv->drm, "expected:\n");
5463 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
5464 drm_dbg_kms(&dev_priv->drm, "found:\n");
5465 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
5467 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
5468 drm_err(&dev_priv->drm, "expected:\n");
5469 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
5470 drm_err(&dev_priv->drm, "found:\n");
5471 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
5475 static void __printf(4, 5)
5476 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
5477 const char *name, const char *format, ...)
5479 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5480 struct va_format vaf;
5483 va_start(args, format);
5488 drm_dbg_kms(&i915->drm,
5489 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
5490 crtc->base.base.id, crtc->base.name, name, &vaf);
5492 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
5493 crtc->base.base.id, crtc->base.name, name, &vaf);
5498 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
5500 if (dev_priv->params.fastboot != -1)
5501 return dev_priv->params.fastboot;
5503 /* Enable fastboot by default on Skylake and newer */
5504 if (DISPLAY_VER(dev_priv) >= 9)
5507 /* Enable fastboot by default on VLV and CHV */
5508 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5511 /* Disabled by default on all others */
5516 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
5517 const struct intel_crtc_state *pipe_config,
5520 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
5521 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
5524 bool fixup_inherited = fastset &&
5525 current_config->inherited && !pipe_config->inherited;
5527 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
5528 drm_dbg_kms(&dev_priv->drm,
5529 "initial modeset and fastboot not set\n");
5533 #define PIPE_CONF_CHECK_X(name) do { \
5534 if (current_config->name != pipe_config->name) { \
5535 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5536 "(expected 0x%08x, found 0x%08x)", \
5537 current_config->name, \
5538 pipe_config->name); \
5543 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5544 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5545 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5546 "(expected 0x%08x, found 0x%08x)", \
5547 current_config->name & (mask), \
5548 pipe_config->name & (mask)); \
5553 #define PIPE_CONF_CHECK_I(name) do { \
5554 if (current_config->name != pipe_config->name) { \
5555 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5556 "(expected %i, found %i)", \
5557 current_config->name, \
5558 pipe_config->name); \
5563 #define PIPE_CONF_CHECK_BOOL(name) do { \
5564 if (current_config->name != pipe_config->name) { \
5565 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5566 "(expected %s, found %s)", \
5567 str_yes_no(current_config->name), \
5568 str_yes_no(pipe_config->name)); \
5574 * Checks state where we only read out the enabling, but not the entire
5575 * state itself (like full infoframes or ELD for audio). These states
5576 * require a full modeset on bootup to fix up.
5578 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
5579 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
5580 PIPE_CONF_CHECK_BOOL(name); \
5582 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5583 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
5584 str_yes_no(current_config->name), \
5585 str_yes_no(pipe_config->name)); \
5590 #define PIPE_CONF_CHECK_P(name) do { \
5591 if (current_config->name != pipe_config->name) { \
5592 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5593 "(expected %p, found %p)", \
5594 current_config->name, \
5595 pipe_config->name); \
5600 #define PIPE_CONF_CHECK_M_N(name) do { \
5601 if (!intel_compare_link_m_n(¤t_config->name, \
5602 &pipe_config->name,\
5604 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5605 "(expected tu %i data %i/%i link %i/%i, " \
5606 "found tu %i, data %i/%i link %i/%i)", \
5607 current_config->name.tu, \
5608 current_config->name.data_m, \
5609 current_config->name.data_n, \
5610 current_config->name.link_m, \
5611 current_config->name.link_n, \
5612 pipe_config->name.tu, \
5613 pipe_config->name.data_m, \
5614 pipe_config->name.data_n, \
5615 pipe_config->name.link_m, \
5616 pipe_config->name.link_n); \
5621 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5622 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5623 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5624 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5625 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5626 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5627 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5628 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5629 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5630 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5631 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5632 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5633 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5636 #define PIPE_CONF_CHECK_RECT(name) do { \
5637 PIPE_CONF_CHECK_I(name.x1); \
5638 PIPE_CONF_CHECK_I(name.x2); \
5639 PIPE_CONF_CHECK_I(name.y1); \
5640 PIPE_CONF_CHECK_I(name.y2); \
5643 /* This is required for BDW+ where there is only one set of registers for
5644 * switching between high and low RR.
5645 * This macro can be used whenever a comparison has to be made between one
5646 * hw state and multiple sw state variables.
5648 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
5649 if (!intel_compare_link_m_n(¤t_config->name, \
5650 &pipe_config->name, !fastset) && \
5651 !intel_compare_link_m_n(¤t_config->alt_name, \
5652 &pipe_config->name, !fastset)) { \
5653 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5654 "(expected tu %i data %i/%i link %i/%i, " \
5655 "or tu %i data %i/%i link %i/%i, " \
5656 "found tu %i, data %i/%i link %i/%i)", \
5657 current_config->name.tu, \
5658 current_config->name.data_m, \
5659 current_config->name.data_n, \
5660 current_config->name.link_m, \
5661 current_config->name.link_n, \
5662 current_config->alt_name.tu, \
5663 current_config->alt_name.data_m, \
5664 current_config->alt_name.data_n, \
5665 current_config->alt_name.link_m, \
5666 current_config->alt_name.link_n, \
5667 pipe_config->name.tu, \
5668 pipe_config->name.data_m, \
5669 pipe_config->name.data_n, \
5670 pipe_config->name.link_m, \
5671 pipe_config->name.link_n); \
5676 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5677 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5678 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5679 "(%x) (expected %i, found %i)", \
5681 current_config->name & (mask), \
5682 pipe_config->name & (mask)); \
5687 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
5688 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
5689 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5690 "(expected %i, found %i)", \
5691 current_config->name, \
5692 pipe_config->name); \
5697 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5698 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5699 &pipe_config->infoframes.name)) { \
5700 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
5701 ¤t_config->infoframes.name, \
5702 &pipe_config->infoframes.name); \
5707 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5708 if (!current_config->has_psr && !pipe_config->has_psr && \
5709 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5710 &pipe_config->infoframes.name)) { \
5711 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
5712 ¤t_config->infoframes.name, \
5713 &pipe_config->infoframes.name); \
5718 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
5719 if (current_config->name1 != pipe_config->name1) { \
5720 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
5721 "(expected %i, found %i, won't compare lut values)", \
5722 current_config->name1, \
5723 pipe_config->name1); \
5726 if (!intel_color_lut_equal(current_config->name2, \
5727 pipe_config->name2, pipe_config->name1, \
5729 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
5730 "hw_state doesn't match sw_state"); \
5736 #define PIPE_CONF_QUIRK(quirk) \
5737 ((current_config->quirks | pipe_config->quirks) & (quirk))
5739 PIPE_CONF_CHECK_I(hw.enable);
5740 PIPE_CONF_CHECK_I(hw.active);
5742 PIPE_CONF_CHECK_I(cpu_transcoder);
5743 PIPE_CONF_CHECK_I(mst_master_transcoder);
5745 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5746 PIPE_CONF_CHECK_I(fdi_lanes);
5747 PIPE_CONF_CHECK_M_N(fdi_m_n);
5749 PIPE_CONF_CHECK_I(lane_count);
5750 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5752 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) {
5753 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
5755 PIPE_CONF_CHECK_M_N(dp_m_n);
5756 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5759 PIPE_CONF_CHECK_X(output_types);
5761 PIPE_CONF_CHECK_I(framestart_delay);
5762 PIPE_CONF_CHECK_I(msa_timing_delay);
5764 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5765 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5767 PIPE_CONF_CHECK_I(pixel_multiplier);
5769 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5770 DRM_MODE_FLAG_INTERLACE);
5772 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5773 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5774 DRM_MODE_FLAG_PHSYNC);
5775 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5776 DRM_MODE_FLAG_NHSYNC);
5777 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5778 DRM_MODE_FLAG_PVSYNC);
5779 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5780 DRM_MODE_FLAG_NVSYNC);
5783 PIPE_CONF_CHECK_I(output_format);
5784 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5785 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5786 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5787 PIPE_CONF_CHECK_BOOL(limited_color_range);
5789 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5790 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5791 PIPE_CONF_CHECK_BOOL(has_infoframe);
5792 PIPE_CONF_CHECK_BOOL(fec_enable);
5794 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
5796 PIPE_CONF_CHECK_X(gmch_pfit.control);
5797 /* pfit ratios are autocomputed by the hw on gen4+ */
5798 if (DISPLAY_VER(dev_priv) < 4)
5799 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5800 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5803 * Changing the EDP transcoder input mux
5804 * (A_ONOFF vs. A_ON) requires a full modeset.
5806 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5809 PIPE_CONF_CHECK_RECT(pipe_src);
5811 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5812 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5814 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5815 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
5817 PIPE_CONF_CHECK_X(gamma_mode);
5818 if (IS_CHERRYVIEW(dev_priv))
5819 PIPE_CONF_CHECK_X(cgm_mode);
5821 PIPE_CONF_CHECK_X(csc_mode);
5822 PIPE_CONF_CHECK_BOOL(gamma_enable);
5823 PIPE_CONF_CHECK_BOOL(csc_enable);
5825 PIPE_CONF_CHECK_I(linetime);
5826 PIPE_CONF_CHECK_I(ips_linetime);
5828 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
5830 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
5832 if (current_config->active_planes) {
5833 PIPE_CONF_CHECK_BOOL(has_psr);
5834 PIPE_CONF_CHECK_BOOL(has_psr2);
5835 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5836 PIPE_CONF_CHECK_I(dc3co_exitline);
5840 PIPE_CONF_CHECK_BOOL(double_wide);
5842 if (dev_priv->display.dpll.mgr) {
5843 PIPE_CONF_CHECK_P(shared_dpll);
5845 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
5846 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
5847 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
5848 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
5849 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
5850 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
5851 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
5852 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
5853 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
5854 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
5855 PIPE_CONF_CHECK_X(dpll_hw_state.div0);
5856 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
5857 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
5858 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
5859 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
5860 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
5861 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
5862 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
5863 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
5864 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
5865 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
5866 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
5867 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
5868 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
5869 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
5870 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
5871 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
5872 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
5873 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
5874 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
5875 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
5876 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
5879 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5880 PIPE_CONF_CHECK_X(dsi_pll.div);
5882 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5883 PIPE_CONF_CHECK_I(pipe_bpp);
5885 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
5886 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
5887 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
5889 PIPE_CONF_CHECK_I(min_voltage_level);
5891 if (current_config->has_psr || pipe_config->has_psr)
5892 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5893 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5895 PIPE_CONF_CHECK_X(infoframes.enable);
5897 PIPE_CONF_CHECK_X(infoframes.gcp);
5898 PIPE_CONF_CHECK_INFOFRAME(avi);
5899 PIPE_CONF_CHECK_INFOFRAME(spd);
5900 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5901 PIPE_CONF_CHECK_INFOFRAME(drm);
5902 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5904 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5905 PIPE_CONF_CHECK_I(master_transcoder);
5906 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5908 PIPE_CONF_CHECK_I(dsc.compression_enable);
5909 PIPE_CONF_CHECK_I(dsc.dsc_split);
5910 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
5912 PIPE_CONF_CHECK_BOOL(splitter.enable);
5913 PIPE_CONF_CHECK_I(splitter.link_count);
5914 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5916 PIPE_CONF_CHECK_BOOL(vrr.enable);
5917 PIPE_CONF_CHECK_I(vrr.vmin);
5918 PIPE_CONF_CHECK_I(vrr.vmax);
5919 PIPE_CONF_CHECK_I(vrr.flipline);
5920 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5921 PIPE_CONF_CHECK_I(vrr.guardband);
5923 #undef PIPE_CONF_CHECK_X
5924 #undef PIPE_CONF_CHECK_I
5925 #undef PIPE_CONF_CHECK_BOOL
5926 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
5927 #undef PIPE_CONF_CHECK_P
5928 #undef PIPE_CONF_CHECK_FLAGS
5929 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
5930 #undef PIPE_CONF_CHECK_COLOR_LUT
5931 #undef PIPE_CONF_CHECK_TIMINGS
5932 #undef PIPE_CONF_CHECK_RECT
5933 #undef PIPE_CONF_QUIRK
5939 intel_verify_planes(struct intel_atomic_state *state)
5941 struct intel_plane *plane;
5942 const struct intel_plane_state *plane_state;
5945 for_each_new_intel_plane_in_state(state, plane,
5947 assert_plane(plane, plane_state->planar_slave ||
5948 plane_state->uapi.visible);
5951 int intel_modeset_all_pipes(struct intel_atomic_state *state)
5953 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5954 struct intel_crtc *crtc;
5957 * Add all pipes to the state, and force
5958 * a modeset on all the active ones.
5960 for_each_intel_crtc(&dev_priv->drm, crtc) {
5961 struct intel_crtc_state *crtc_state;
5964 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5965 if (IS_ERR(crtc_state))
5966 return PTR_ERR(crtc_state);
5968 if (!crtc_state->hw.active ||
5969 drm_atomic_crtc_needs_modeset(&crtc_state->uapi))
5972 crtc_state->uapi.mode_changed = true;
5974 ret = drm_atomic_add_affected_connectors(&state->base,
5979 ret = intel_atomic_add_affected_planes(state, crtc);
5983 crtc_state->update_planes |= crtc_state->active_planes;
5989 void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
5991 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5993 struct drm_display_mode adjusted_mode;
5995 drm_mode_init(&adjusted_mode, &crtc_state->hw.adjusted_mode);
5997 if (crtc_state->vrr.enable) {
5998 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax;
5999 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax;
6000 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state);
6001 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state);
6004 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
6006 crtc->mode_flags = crtc_state->mode_flags;
6009 * The scanline counter increments at the leading edge of hsync.
6011 * On most platforms it starts counting from vtotal-1 on the
6012 * first active line. That means the scanline counter value is
6013 * always one less than what we would expect. Ie. just after
6014 * start of vblank, which also occurs at start of hsync (on the
6015 * last active line), the scanline counter will read vblank_start-1.
6017 * On gen2 the scanline counter starts counting from 1 instead
6018 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
6019 * to keep the value positive), instead of adding one.
6021 * On HSW+ the behaviour of the scanline counter depends on the output
6022 * type. For DP ports it behaves like most other platforms, but on HDMI
6023 * there's an extra 1 line difference. So we need to add two instead of
6026 * On VLV/CHV DSI the scanline counter would appear to increment
6027 * approx. 1/3 of a scanline before start of vblank. Unfortunately
6028 * that means we can't tell whether we're in vblank or not while
6029 * we're on that particular line. We must still set scanline_offset
6030 * to 1 so that the vblank timestamps come out correct when we query
6031 * the scanline counter from within the vblank interrupt handler.
6032 * However if queried just before the start of vblank we'll get an
6033 * answer that's slightly in the future.
6035 if (DISPLAY_VER(dev_priv) == 2) {
6038 vtotal = adjusted_mode.crtc_vtotal;
6039 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
6042 crtc->scanline_offset = vtotal - 1;
6043 } else if (HAS_DDI(dev_priv) &&
6044 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
6045 crtc->scanline_offset = 2;
6047 crtc->scanline_offset = 1;
6051 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
6053 struct intel_crtc_state *new_crtc_state;
6054 struct intel_crtc *crtc;
6057 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6058 if (!intel_crtc_needs_modeset(new_crtc_state))
6061 intel_release_shared_dplls(state, crtc);
6066 * This implements the workaround described in the "notes" section of the mode
6067 * set sequence documentation. When going from no pipes or single pipe to
6068 * multiple pipes, and planes are enabled after the pipe, we need to wait at
6069 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
6071 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
6073 struct intel_crtc_state *crtc_state;
6074 struct intel_crtc *crtc;
6075 struct intel_crtc_state *first_crtc_state = NULL;
6076 struct intel_crtc_state *other_crtc_state = NULL;
6077 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
6080 /* look at all crtc's that are going to be enabled in during modeset */
6081 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6082 if (!crtc_state->hw.active ||
6083 !intel_crtc_needs_modeset(crtc_state))
6086 if (first_crtc_state) {
6087 other_crtc_state = crtc_state;
6090 first_crtc_state = crtc_state;
6091 first_pipe = crtc->pipe;
6095 /* No workaround needed? */
6096 if (!first_crtc_state)
6099 /* w/a possibly needed, check how many crtc's are already enabled. */
6100 for_each_intel_crtc(state->base.dev, crtc) {
6101 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6102 if (IS_ERR(crtc_state))
6103 return PTR_ERR(crtc_state);
6105 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
6107 if (!crtc_state->hw.active ||
6108 intel_crtc_needs_modeset(crtc_state))
6111 /* 2 or more enabled crtcs means no need for w/a */
6112 if (enabled_pipe != INVALID_PIPE)
6115 enabled_pipe = crtc->pipe;
6118 if (enabled_pipe != INVALID_PIPE)
6119 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
6120 else if (other_crtc_state)
6121 other_crtc_state->hsw_workaround_pipe = first_pipe;
6126 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
6129 const struct intel_crtc_state *crtc_state;
6130 struct intel_crtc *crtc;
6133 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6134 if (crtc_state->hw.active)
6135 active_pipes |= BIT(crtc->pipe);
6137 active_pipes &= ~BIT(crtc->pipe);
6140 return active_pipes;
6143 static int intel_modeset_checks(struct intel_atomic_state *state)
6145 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6147 state->modeset = true;
6149 if (IS_HASWELL(dev_priv))
6150 return hsw_mode_set_planes_workaround(state);
6155 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
6156 struct intel_crtc_state *new_crtc_state)
6158 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
6161 new_crtc_state->uapi.mode_changed = false;
6162 new_crtc_state->update_pipe = true;
6165 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
6166 struct intel_crtc_state *new_crtc_state)
6169 * If we're not doing the full modeset we want to
6170 * keep the current M/N values as they may be
6171 * sufficiently different to the computed values
6172 * to cause problems.
6174 * FIXME: should really copy more fuzzy state here
6176 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
6177 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
6178 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
6179 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
6182 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
6183 struct intel_crtc *crtc,
6186 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6187 struct intel_plane *plane;
6189 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6190 struct intel_plane_state *plane_state;
6192 if ((plane_ids_mask & BIT(plane->id)) == 0)
6195 plane_state = intel_atomic_get_plane_state(state, plane);
6196 if (IS_ERR(plane_state))
6197 return PTR_ERR(plane_state);
6203 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
6204 struct intel_crtc *crtc)
6206 const struct intel_crtc_state *old_crtc_state =
6207 intel_atomic_get_old_crtc_state(state, crtc);
6208 const struct intel_crtc_state *new_crtc_state =
6209 intel_atomic_get_new_crtc_state(state, crtc);
6211 return intel_crtc_add_planes_to_state(state, crtc,
6212 old_crtc_state->enabled_planes |
6213 new_crtc_state->enabled_planes);
6216 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
6218 /* See {hsw,vlv,ivb}_plane_ratio() */
6219 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
6220 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
6221 IS_IVYBRIDGE(dev_priv);
6224 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
6225 struct intel_crtc *crtc,
6226 struct intel_crtc *other)
6228 const struct intel_plane_state *plane_state;
6229 struct intel_plane *plane;
6233 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6234 if (plane->pipe == crtc->pipe)
6235 plane_ids |= BIT(plane->id);
6238 return intel_crtc_add_planes_to_state(state, other, plane_ids);
6241 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
6243 struct drm_i915_private *i915 = to_i915(state->base.dev);
6244 const struct intel_crtc_state *crtc_state;
6245 struct intel_crtc *crtc;
6248 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6249 struct intel_crtc *other;
6251 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
6252 crtc_state->bigjoiner_pipes) {
6258 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
6267 static int intel_atomic_check_planes(struct intel_atomic_state *state)
6269 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6270 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6271 struct intel_plane_state *plane_state;
6272 struct intel_plane *plane;
6273 struct intel_crtc *crtc;
6276 ret = icl_add_linked_planes(state);
6280 ret = intel_bigjoiner_add_affected_planes(state);
6284 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6285 ret = intel_plane_atomic_check(state, plane);
6287 drm_dbg_atomic(&dev_priv->drm,
6288 "[PLANE:%d:%s] atomic driver check failed\n",
6289 plane->base.base.id, plane->base.name);
6294 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6295 new_crtc_state, i) {
6296 u8 old_active_planes, new_active_planes;
6298 ret = icl_check_nv12_planes(new_crtc_state);
6303 * On some platforms the number of active planes affects
6304 * the planes' minimum cdclk calculation. Add such planes
6305 * to the state before we compute the minimum cdclk.
6307 if (!active_planes_affects_min_cdclk(dev_priv))
6310 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6311 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6313 if (hweight8(old_active_planes) == hweight8(new_active_planes))
6316 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
6324 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
6326 struct intel_crtc_state *crtc_state;
6327 struct intel_crtc *crtc;
6330 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6331 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6334 ret = intel_crtc_atomic_check(state, crtc);
6336 drm_dbg_atomic(&i915->drm,
6337 "[CRTC:%d:%s] atomic driver check failed\n",
6338 crtc->base.base.id, crtc->base.name);
6346 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
6349 const struct intel_crtc_state *new_crtc_state;
6350 struct intel_crtc *crtc;
6353 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6354 if (new_crtc_state->hw.enable &&
6355 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
6356 intel_crtc_needs_modeset(new_crtc_state))
6363 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
6366 const struct intel_crtc_state *new_crtc_state;
6367 struct intel_crtc *crtc;
6370 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6371 if (new_crtc_state->hw.enable &&
6372 pipes & BIT(crtc->pipe) &&
6373 intel_crtc_needs_modeset(new_crtc_state))
6380 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
6381 struct intel_crtc *master_crtc)
6383 struct drm_i915_private *i915 = to_i915(state->base.dev);
6384 struct intel_crtc_state *master_crtc_state =
6385 intel_atomic_get_new_crtc_state(state, master_crtc);
6386 struct intel_crtc *slave_crtc;
6388 if (!master_crtc_state->bigjoiner_pipes)
6392 if (drm_WARN_ON(&i915->drm,
6393 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
6396 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
6397 drm_dbg_kms(&i915->drm,
6398 "[CRTC:%d:%s] Cannot act as big joiner master "
6399 "(need 0x%x as pipes, only 0x%x possible)\n",
6400 master_crtc->base.base.id, master_crtc->base.name,
6401 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
6405 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
6406 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
6407 struct intel_crtc_state *slave_crtc_state;
6410 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
6411 if (IS_ERR(slave_crtc_state))
6412 return PTR_ERR(slave_crtc_state);
6414 /* master being enabled, slave was already configured? */
6415 if (slave_crtc_state->uapi.enable) {
6416 drm_dbg_kms(&i915->drm,
6417 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
6418 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
6419 slave_crtc->base.base.id, slave_crtc->base.name,
6420 master_crtc->base.base.id, master_crtc->base.name);
6425 * The state copy logic assumes the master crtc gets processed
6426 * before the slave crtc during the main compute_config loop.
6427 * This works because the crtcs are created in pipe order,
6428 * and the hardware requires master pipe < slave pipe as well.
6429 * Should that change we need to rethink the logic.
6431 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
6432 drm_crtc_index(&slave_crtc->base)))
6435 drm_dbg_kms(&i915->drm,
6436 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
6437 slave_crtc->base.base.id, slave_crtc->base.name,
6438 master_crtc->base.base.id, master_crtc->base.name);
6440 slave_crtc_state->bigjoiner_pipes =
6441 master_crtc_state->bigjoiner_pipes;
6443 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
6451 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
6452 struct intel_crtc *master_crtc)
6454 struct drm_i915_private *i915 = to_i915(state->base.dev);
6455 struct intel_crtc_state *master_crtc_state =
6456 intel_atomic_get_new_crtc_state(state, master_crtc);
6457 struct intel_crtc *slave_crtc;
6459 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
6460 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
6461 struct intel_crtc_state *slave_crtc_state =
6462 intel_atomic_get_new_crtc_state(state, slave_crtc);
6464 slave_crtc_state->bigjoiner_pipes = 0;
6466 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
6469 master_crtc_state->bigjoiner_pipes = 0;
6473 * DOC: asynchronous flip implementation
6475 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
6476 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
6477 * Correspondingly, support is currently added for primary plane only.
6479 * Async flip can only change the plane surface address, so anything else
6480 * changing is rejected from the intel_async_flip_check_hw() function.
6481 * Once this check is cleared, flip done interrupt is enabled using
6482 * the intel_crtc_enable_flip_done() function.
6484 * As soon as the surface address register is written, flip done interrupt is
6485 * generated and the requested events are sent to the usersapce in the interrupt
6486 * handler itself. The timestamp and sequence sent during the flip done event
6487 * correspond to the last vblank and have no relation to the actual time when
6488 * the flip done event was sent.
6490 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
6491 struct intel_crtc *crtc)
6493 struct drm_i915_private *i915 = to_i915(state->base.dev);
6494 const struct intel_crtc_state *new_crtc_state =
6495 intel_atomic_get_new_crtc_state(state, crtc);
6496 const struct intel_plane_state *old_plane_state;
6497 struct intel_plane_state *new_plane_state;
6498 struct intel_plane *plane;
6501 if (!new_crtc_state->uapi.async_flip)
6504 if (!new_crtc_state->uapi.active) {
6505 drm_dbg_kms(&i915->drm,
6506 "[CRTC:%d:%s] not active\n",
6507 crtc->base.base.id, crtc->base.name);
6511 if (intel_crtc_needs_modeset(new_crtc_state)) {
6512 drm_dbg_kms(&i915->drm,
6513 "[CRTC:%d:%s] modeset required\n",
6514 crtc->base.base.id, crtc->base.name);
6518 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6519 new_plane_state, i) {
6520 if (plane->pipe != crtc->pipe)
6524 * TODO: Async flip is only supported through the page flip IOCTL
6525 * as of now. So support currently added for primary plane only.
6526 * Support for other planes on platforms on which supports
6527 * this(vlv/chv and icl+) should be added when async flip is
6528 * enabled in the atomic IOCTL path.
6530 if (!plane->async_flip) {
6531 drm_dbg_kms(&i915->drm,
6532 "[PLANE:%d:%s] async flip not supported\n",
6533 plane->base.base.id, plane->base.name);
6537 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
6538 drm_dbg_kms(&i915->drm,
6539 "[PLANE:%d:%s] no old or new framebuffer\n",
6540 plane->base.base.id, plane->base.name);
6548 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
6550 struct drm_i915_private *i915 = to_i915(state->base.dev);
6551 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6552 const struct intel_plane_state *new_plane_state, *old_plane_state;
6553 struct intel_plane *plane;
6556 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
6557 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6559 if (!new_crtc_state->uapi.async_flip)
6562 if (!new_crtc_state->hw.active) {
6563 drm_dbg_kms(&i915->drm,
6564 "[CRTC:%d:%s] not active\n",
6565 crtc->base.base.id, crtc->base.name);
6569 if (intel_crtc_needs_modeset(new_crtc_state)) {
6570 drm_dbg_kms(&i915->drm,
6571 "[CRTC:%d:%s] modeset required\n",
6572 crtc->base.base.id, crtc->base.name);
6576 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6577 drm_dbg_kms(&i915->drm,
6578 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6579 crtc->base.base.id, crtc->base.name);
6583 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6584 new_plane_state, i) {
6585 if (plane->pipe != crtc->pipe)
6589 * Only async flip capable planes should be in the state
6590 * if we're really about to ask the hardware to perform
6591 * an async flip. We should never get this far otherwise.
6593 if (drm_WARN_ON(&i915->drm,
6594 new_crtc_state->do_async_flip && !plane->async_flip))
6598 * Only check async flip capable planes other planes
6599 * may be involved in the initial commit due to
6600 * the wm0/ddb optimization.
6602 * TODO maybe should track which planes actually
6603 * were requested to do the async flip...
6605 if (!plane->async_flip)
6609 * FIXME: This check is kept generic for all platforms.
6610 * Need to verify this for all gen9 platforms to enable
6611 * this selectively if required.
6613 switch (new_plane_state->hw.fb->modifier) {
6614 case I915_FORMAT_MOD_X_TILED:
6615 case I915_FORMAT_MOD_Y_TILED:
6616 case I915_FORMAT_MOD_Yf_TILED:
6617 case I915_FORMAT_MOD_4_TILED:
6620 drm_dbg_kms(&i915->drm,
6621 "[PLANE:%d:%s] Modifier does not support async flips\n",
6622 plane->base.base.id, plane->base.name);
6626 if (new_plane_state->hw.fb->format->num_planes > 1) {
6627 drm_dbg_kms(&i915->drm,
6628 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6629 plane->base.base.id, plane->base.name);
6633 if (old_plane_state->view.color_plane[0].mapping_stride !=
6634 new_plane_state->view.color_plane[0].mapping_stride) {
6635 drm_dbg_kms(&i915->drm,
6636 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6637 plane->base.base.id, plane->base.name);
6641 if (old_plane_state->hw.fb->modifier !=
6642 new_plane_state->hw.fb->modifier) {
6643 drm_dbg_kms(&i915->drm,
6644 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6645 plane->base.base.id, plane->base.name);
6649 if (old_plane_state->hw.fb->format !=
6650 new_plane_state->hw.fb->format) {
6651 drm_dbg_kms(&i915->drm,
6652 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6653 plane->base.base.id, plane->base.name);
6657 if (old_plane_state->hw.rotation !=
6658 new_plane_state->hw.rotation) {
6659 drm_dbg_kms(&i915->drm,
6660 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6661 plane->base.base.id, plane->base.name);
6665 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6666 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6667 drm_dbg_kms(&i915->drm,
6668 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6669 plane->base.base.id, plane->base.name);
6673 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6674 drm_dbg_kms(&i915->drm,
6675 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6676 plane->base.base.id, plane->base.name);
6680 if (old_plane_state->hw.pixel_blend_mode !=
6681 new_plane_state->hw.pixel_blend_mode) {
6682 drm_dbg_kms(&i915->drm,
6683 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6684 plane->base.base.id, plane->base.name);
6688 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6689 drm_dbg_kms(&i915->drm,
6690 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6691 plane->base.base.id, plane->base.name);
6695 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6696 drm_dbg_kms(&i915->drm,
6697 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6698 plane->base.base.id, plane->base.name);
6702 /* plane decryption is allow to change only in synchronous flips */
6703 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6704 drm_dbg_kms(&i915->drm,
6705 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6706 plane->base.base.id, plane->base.name);
6714 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6716 struct drm_i915_private *i915 = to_i915(state->base.dev);
6717 struct intel_crtc_state *crtc_state;
6718 struct intel_crtc *crtc;
6719 u8 affected_pipes = 0;
6720 u8 modeset_pipes = 0;
6723 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6724 affected_pipes |= crtc_state->bigjoiner_pipes;
6725 if (intel_crtc_needs_modeset(crtc_state))
6726 modeset_pipes |= crtc_state->bigjoiner_pipes;
6729 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6730 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6731 if (IS_ERR(crtc_state))
6732 return PTR_ERR(crtc_state);
6735 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6738 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6740 crtc_state->uapi.mode_changed = true;
6742 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6746 ret = intel_atomic_add_affected_planes(state, crtc);
6751 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6752 /* Kill old bigjoiner link, we may re-establish afterwards */
6753 if (intel_crtc_needs_modeset(crtc_state) &&
6754 intel_crtc_is_bigjoiner_master(crtc_state))
6755 kill_bigjoiner_slave(state, crtc);
6762 * intel_atomic_check - validate state object
6764 * @_state: state to validate
6766 static int intel_atomic_check(struct drm_device *dev,
6767 struct drm_atomic_state *_state)
6769 struct drm_i915_private *dev_priv = to_i915(dev);
6770 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6771 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6772 struct intel_crtc *crtc;
6774 bool any_ms = false;
6776 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6777 new_crtc_state, i) {
6778 if (new_crtc_state->inherited != old_crtc_state->inherited)
6779 new_crtc_state->uapi.mode_changed = true;
6781 if (new_crtc_state->uapi.scaling_filter !=
6782 old_crtc_state->uapi.scaling_filter)
6783 new_crtc_state->uapi.mode_changed = true;
6786 intel_vrr_check_modeset(state);
6788 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6792 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6793 ret = intel_async_flip_check_uapi(state, crtc);
6798 ret = intel_bigjoiner_add_affected_crtcs(state);
6802 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6803 new_crtc_state, i) {
6804 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6805 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6806 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6808 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6812 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6813 drm_WARN_ON(&dev_priv->drm, new_crtc_state->uapi.enable);
6817 ret = intel_crtc_prepare_cleared_state(state, crtc);
6821 if (!new_crtc_state->hw.enable)
6824 ret = intel_modeset_pipe_config(state, crtc);
6828 ret = intel_atomic_check_bigjoiner(state, crtc);
6833 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6834 new_crtc_state, i) {
6835 if (!intel_crtc_needs_modeset(new_crtc_state))
6838 ret = intel_modeset_pipe_config_late(state, crtc);
6842 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6846 * Check if fastset is allowed by external dependencies like other
6847 * pipes and transcoders.
6849 * Right now it only forces a fullmodeset when the MST master
6850 * transcoder did not changed but the pipe of the master transcoder
6851 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6852 * in case of port synced crtcs, if one of the synced crtcs
6853 * needs a full modeset, all other synced crtcs should be
6854 * forced a full modeset.
6856 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6857 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6860 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6861 enum transcoder master = new_crtc_state->mst_master_transcoder;
6863 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
6864 new_crtc_state->uapi.mode_changed = true;
6865 new_crtc_state->update_pipe = false;
6869 if (is_trans_port_sync_mode(new_crtc_state)) {
6870 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6872 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6873 trans |= BIT(new_crtc_state->master_transcoder);
6875 if (intel_cpu_transcoders_need_modeset(state, trans)) {
6876 new_crtc_state->uapi.mode_changed = true;
6877 new_crtc_state->update_pipe = false;
6881 if (new_crtc_state->bigjoiner_pipes) {
6882 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes)) {
6883 new_crtc_state->uapi.mode_changed = true;
6884 new_crtc_state->update_pipe = false;
6889 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6890 new_crtc_state, i) {
6891 if (intel_crtc_needs_modeset(new_crtc_state)) {
6896 if (!new_crtc_state->update_pipe)
6899 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
6902 if (any_ms && !check_digital_port_conflicts(state)) {
6903 drm_dbg_kms(&dev_priv->drm,
6904 "rejecting conflicting digital port configuration\n");
6909 ret = drm_dp_mst_atomic_check(&state->base);
6913 ret = intel_atomic_check_planes(state);
6917 ret = intel_compute_global_watermarks(state);
6921 ret = intel_bw_atomic_check(state);
6925 ret = intel_cdclk_atomic_check(state, &any_ms);
6929 if (intel_any_crtc_needs_modeset(state))
6933 ret = intel_modeset_checks(state);
6937 ret = intel_modeset_calc_cdclk(state);
6941 intel_modeset_clear_plls(state);
6944 ret = intel_atomic_check_crtcs(state);
6948 ret = intel_fbc_atomic_check(state);
6952 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6953 new_crtc_state, i) {
6954 ret = intel_async_flip_check_hw(state, crtc);
6958 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6959 !new_crtc_state->update_pipe)
6962 intel_crtc_state_dump(new_crtc_state, state,
6963 intel_crtc_needs_modeset(new_crtc_state) ?
6964 "modeset" : "fastset");
6970 if (ret == -EDEADLK)
6974 * FIXME would probably be nice to know which crtc specifically
6975 * caused the failure, in cases where we can pinpoint it.
6977 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6979 intel_crtc_state_dump(new_crtc_state, state, "failed");
6984 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6986 struct intel_crtc_state *crtc_state;
6987 struct intel_crtc *crtc;
6990 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6994 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6995 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
6997 if (mode_changed || crtc_state->update_pipe ||
6998 crtc_state->uapi.color_mgmt_changed) {
6999 intel_dsb_prepare(crtc_state);
7006 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
7007 struct intel_crtc_state *crtc_state)
7009 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7011 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
7012 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7014 if (crtc_state->has_pch_encoder) {
7015 enum pipe pch_transcoder =
7016 intel_crtc_pch_transcoder(crtc);
7018 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
7022 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
7023 const struct intel_crtc_state *new_crtc_state)
7025 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
7026 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7029 * Update pipe size and adjust fitter if needed: the reason for this is
7030 * that in compute_mode_changes we check the native mode (not the pfit
7031 * mode) to see if we can flip rather than do a full mode set. In the
7032 * fastboot case, we'll flip, but if we don't update the pipesrc and
7033 * pfit state, we'll end up with a big fb scanned out into the wrong
7036 intel_set_pipe_src_size(new_crtc_state);
7038 /* on skylake this is done by detaching scalers */
7039 if (DISPLAY_VER(dev_priv) >= 9) {
7040 if (new_crtc_state->pch_pfit.enabled)
7041 skl_pfit_enable(new_crtc_state);
7042 } else if (HAS_PCH_SPLIT(dev_priv)) {
7043 if (new_crtc_state->pch_pfit.enabled)
7044 ilk_pfit_enable(new_crtc_state);
7045 else if (old_crtc_state->pch_pfit.enabled)
7046 ilk_pfit_disable(old_crtc_state);
7050 * The register is supposedly single buffered so perhaps
7051 * not 100% correct to do this here. But SKL+ calculate
7052 * this based on the adjust pixel rate so pfit changes do
7053 * affect it and so it must be updated for fastsets.
7054 * HSW/BDW only really need this here for fastboot, after
7055 * that the value should not change without a full modeset.
7057 if (DISPLAY_VER(dev_priv) >= 9 ||
7058 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
7059 hsw_set_linetime_wm(new_crtc_state);
7062 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
7063 struct intel_crtc *crtc)
7065 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7066 const struct intel_crtc_state *old_crtc_state =
7067 intel_atomic_get_old_crtc_state(state, crtc);
7068 const struct intel_crtc_state *new_crtc_state =
7069 intel_atomic_get_new_crtc_state(state, crtc);
7070 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7073 * During modesets pipe configuration was programmed as the
7077 if (new_crtc_state->uapi.color_mgmt_changed ||
7078 new_crtc_state->update_pipe)
7079 intel_color_commit_arm(new_crtc_state);
7081 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
7082 bdw_set_pipemisc(new_crtc_state);
7084 if (new_crtc_state->update_pipe)
7085 intel_pipe_fastset(old_crtc_state, new_crtc_state);
7088 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
7090 intel_atomic_update_watermarks(state, crtc);
7093 static void commit_pipe_post_planes(struct intel_atomic_state *state,
7094 struct intel_crtc *crtc)
7096 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7097 const struct intel_crtc_state *new_crtc_state =
7098 intel_atomic_get_new_crtc_state(state, crtc);
7101 * Disable the scaler(s) after the plane(s) so that we don't
7102 * get a catastrophic underrun even if the two operations
7103 * end up happening in two different frames.
7105 if (DISPLAY_VER(dev_priv) >= 9 &&
7106 !intel_crtc_needs_modeset(new_crtc_state))
7107 skl_detach_scalers(new_crtc_state);
7110 static void intel_enable_crtc(struct intel_atomic_state *state,
7111 struct intel_crtc *crtc)
7113 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7114 const struct intel_crtc_state *new_crtc_state =
7115 intel_atomic_get_new_crtc_state(state, crtc);
7117 if (!intel_crtc_needs_modeset(new_crtc_state))
7120 intel_crtc_update_active_timings(new_crtc_state);
7122 dev_priv->display.funcs.display->crtc_enable(state, crtc);
7124 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
7127 /* vblanks work again, re-enable pipe CRC. */
7128 intel_crtc_enable_pipe_crc(crtc);
7131 static void intel_update_crtc(struct intel_atomic_state *state,
7132 struct intel_crtc *crtc)
7134 struct drm_i915_private *i915 = to_i915(state->base.dev);
7135 const struct intel_crtc_state *old_crtc_state =
7136 intel_atomic_get_old_crtc_state(state, crtc);
7137 struct intel_crtc_state *new_crtc_state =
7138 intel_atomic_get_new_crtc_state(state, crtc);
7139 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7142 if (new_crtc_state->preload_luts &&
7143 (new_crtc_state->uapi.color_mgmt_changed ||
7144 new_crtc_state->update_pipe))
7145 intel_color_load_luts(new_crtc_state);
7147 intel_pre_plane_update(state, crtc);
7149 if (new_crtc_state->update_pipe)
7150 intel_encoders_update_pipe(state, crtc);
7152 if (DISPLAY_VER(i915) >= 11 &&
7153 new_crtc_state->update_pipe)
7154 icl_set_pipe_chicken(new_crtc_state);
7157 intel_fbc_update(state, crtc);
7160 (new_crtc_state->uapi.color_mgmt_changed ||
7161 new_crtc_state->update_pipe))
7162 intel_color_commit_noarm(new_crtc_state);
7164 intel_crtc_planes_update_noarm(state, crtc);
7166 /* Perform vblank evasion around commit operation */
7167 intel_pipe_update_start(new_crtc_state);
7169 commit_pipe_pre_planes(state, crtc);
7171 intel_crtc_planes_update_arm(state, crtc);
7173 commit_pipe_post_planes(state, crtc);
7175 intel_pipe_update_end(new_crtc_state);
7178 * We usually enable FIFO underrun interrupts as part of the
7179 * CRTC enable sequence during modesets. But when we inherit a
7180 * valid pipe configuration from the BIOS we need to take care
7181 * of enabling them on the CRTC's first fastset.
7183 if (new_crtc_state->update_pipe && !modeset &&
7184 old_crtc_state->inherited)
7185 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
7188 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
7189 struct intel_crtc_state *old_crtc_state,
7190 struct intel_crtc_state *new_crtc_state,
7191 struct intel_crtc *crtc)
7193 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7196 * We need to disable pipe CRC before disabling the pipe,
7197 * or we race against vblank off.
7199 intel_crtc_disable_pipe_crc(crtc);
7201 dev_priv->display.funcs.display->crtc_disable(state, crtc);
7202 crtc->active = false;
7203 intel_fbc_disable(crtc);
7204 intel_disable_shared_dpll(old_crtc_state);
7206 /* FIXME unify this for all platforms */
7207 if (!new_crtc_state->hw.active &&
7208 !HAS_GMCH(dev_priv))
7209 intel_initial_watermarks(state, crtc);
7212 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
7214 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7215 struct intel_crtc *crtc;
7219 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7220 new_crtc_state, i) {
7221 if (!intel_crtc_needs_modeset(new_crtc_state))
7224 if (!old_crtc_state->hw.active)
7227 intel_pre_plane_update(state, crtc);
7228 intel_crtc_disable_planes(state, crtc);
7231 /* Only disable port sync and MST slaves */
7232 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7233 new_crtc_state, i) {
7234 if (!intel_crtc_needs_modeset(new_crtc_state))
7237 if (!old_crtc_state->hw.active)
7240 /* In case of Transcoder port Sync master slave CRTCs can be
7241 * assigned in any order and we need to make sure that
7242 * slave CRTCs are disabled first and then master CRTC since
7243 * Slave vblanks are masked till Master Vblanks.
7245 if (!is_trans_port_sync_slave(old_crtc_state) &&
7246 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
7247 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
7250 intel_old_crtc_state_disables(state, old_crtc_state,
7251 new_crtc_state, crtc);
7252 handled |= BIT(crtc->pipe);
7255 /* Disable everything else left on */
7256 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7257 new_crtc_state, i) {
7258 if (!intel_crtc_needs_modeset(new_crtc_state) ||
7259 (handled & BIT(crtc->pipe)))
7262 if (!old_crtc_state->hw.active)
7265 intel_old_crtc_state_disables(state, old_crtc_state,
7266 new_crtc_state, crtc);
7270 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
7272 struct intel_crtc_state *new_crtc_state;
7273 struct intel_crtc *crtc;
7276 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7277 if (!new_crtc_state->hw.active)
7280 intel_enable_crtc(state, crtc);
7281 intel_update_crtc(state, crtc);
7285 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
7287 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7288 struct intel_crtc *crtc;
7289 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
7290 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
7291 u8 update_pipes = 0, modeset_pipes = 0;
7294 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7295 enum pipe pipe = crtc->pipe;
7297 if (!new_crtc_state->hw.active)
7300 /* ignore allocations for crtc's that have been turned off. */
7301 if (!intel_crtc_needs_modeset(new_crtc_state)) {
7302 entries[pipe] = old_crtc_state->wm.skl.ddb;
7303 update_pipes |= BIT(pipe);
7305 modeset_pipes |= BIT(pipe);
7310 * Whenever the number of active pipes changes, we need to make sure we
7311 * update the pipes in the right order so that their ddb allocations
7312 * never overlap with each other between CRTC updates. Otherwise we'll
7313 * cause pipe underruns and other bad stuff.
7315 * So first lets enable all pipes that do not need a fullmodeset as
7316 * those don't have any external dependency.
7318 while (update_pipes) {
7319 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7320 new_crtc_state, i) {
7321 enum pipe pipe = crtc->pipe;
7323 if ((update_pipes & BIT(pipe)) == 0)
7326 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7327 entries, I915_MAX_PIPES, pipe))
7330 entries[pipe] = new_crtc_state->wm.skl.ddb;
7331 update_pipes &= ~BIT(pipe);
7333 intel_update_crtc(state, crtc);
7336 * If this is an already active pipe, it's DDB changed,
7337 * and this isn't the last pipe that needs updating
7338 * then we need to wait for a vblank to pass for the
7339 * new ddb allocation to take effect.
7341 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
7342 &old_crtc_state->wm.skl.ddb) &&
7343 (update_pipes | modeset_pipes))
7344 intel_crtc_wait_for_next_vblank(crtc);
7348 update_pipes = modeset_pipes;
7351 * Enable all pipes that needs a modeset and do not depends on other
7354 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7355 enum pipe pipe = crtc->pipe;
7357 if ((modeset_pipes & BIT(pipe)) == 0)
7360 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
7361 is_trans_port_sync_master(new_crtc_state) ||
7362 intel_crtc_is_bigjoiner_master(new_crtc_state))
7365 modeset_pipes &= ~BIT(pipe);
7367 intel_enable_crtc(state, crtc);
7371 * Then we enable all remaining pipes that depend on other
7372 * pipes: MST slaves and port sync masters, big joiner master
7374 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7375 enum pipe pipe = crtc->pipe;
7377 if ((modeset_pipes & BIT(pipe)) == 0)
7380 modeset_pipes &= ~BIT(pipe);
7382 intel_enable_crtc(state, crtc);
7386 * Finally we do the plane updates/etc. for all pipes that got enabled.
7388 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7389 enum pipe pipe = crtc->pipe;
7391 if ((update_pipes & BIT(pipe)) == 0)
7394 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7395 entries, I915_MAX_PIPES, pipe));
7397 entries[pipe] = new_crtc_state->wm.skl.ddb;
7398 update_pipes &= ~BIT(pipe);
7400 intel_update_crtc(state, crtc);
7403 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
7404 drm_WARN_ON(&dev_priv->drm, update_pipes);
7407 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
7409 struct intel_atomic_state *state, *next;
7410 struct llist_node *freed;
7412 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
7413 llist_for_each_entry_safe(state, next, freed, freed)
7414 drm_atomic_state_put(&state->base);
7417 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
7419 struct drm_i915_private *dev_priv =
7420 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
7422 intel_atomic_helper_free_state(dev_priv);
7425 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
7427 struct wait_queue_entry wait_fence, wait_reset;
7428 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
7430 init_wait_entry(&wait_fence, 0);
7431 init_wait_entry(&wait_reset, 0);
7433 prepare_to_wait(&intel_state->commit_ready.wait,
7434 &wait_fence, TASK_UNINTERRUPTIBLE);
7435 prepare_to_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7436 I915_RESET_MODESET),
7437 &wait_reset, TASK_UNINTERRUPTIBLE);
7440 if (i915_sw_fence_done(&intel_state->commit_ready) ||
7441 test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags))
7446 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
7447 finish_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7448 I915_RESET_MODESET),
7452 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
7454 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
7455 struct intel_crtc *crtc;
7458 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7460 intel_dsb_cleanup(old_crtc_state);
7463 static void intel_atomic_cleanup_work(struct work_struct *work)
7465 struct intel_atomic_state *state =
7466 container_of(work, struct intel_atomic_state, base.commit_work);
7467 struct drm_i915_private *i915 = to_i915(state->base.dev);
7469 intel_cleanup_dsbs(state);
7470 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
7471 drm_atomic_helper_commit_cleanup_done(&state->base);
7472 drm_atomic_state_put(&state->base);
7474 intel_atomic_helper_free_state(i915);
7477 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7479 struct drm_i915_private *i915 = to_i915(state->base.dev);
7480 struct intel_plane *plane;
7481 struct intel_plane_state *plane_state;
7484 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7485 struct drm_framebuffer *fb = plane_state->hw.fb;
7492 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7497 * The layout of the fast clear color value expected by HW
7498 * (the DRM ABI requiring this value to be located in fb at
7499 * offset 0 of cc plane, plane #2 previous generations or
7500 * plane #1 for flat ccs):
7501 * - 4 x 4 bytes per-channel value
7502 * (in surface type specific float/int format provided by the fb user)
7503 * - 8 bytes native color value used by the display
7504 * (converted/written by GPU during a fast clear operation using the
7505 * above per-channel values)
7507 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7508 * caller made sure that the object is synced wrt. the related color clear value
7511 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
7512 fb->offsets[cc_plane] + 16,
7513 &plane_state->ccval,
7514 sizeof(plane_state->ccval));
7515 /* The above could only fail if the FB obj has an unexpected backing store type. */
7516 drm_WARN_ON(&i915->drm, ret);
7520 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7522 struct drm_device *dev = state->base.dev;
7523 struct drm_i915_private *dev_priv = to_i915(dev);
7524 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7525 struct intel_crtc *crtc;
7526 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7527 intel_wakeref_t wakeref = 0;
7530 intel_atomic_commit_fence_wait(state);
7532 drm_atomic_helper_wait_for_dependencies(&state->base);
7535 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
7537 intel_atomic_prepare_plane_clear_colors(state);
7539 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7540 new_crtc_state, i) {
7541 if (intel_crtc_needs_modeset(new_crtc_state) ||
7542 new_crtc_state->update_pipe) {
7543 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7547 intel_commit_modeset_disables(state);
7549 /* FIXME: Eventually get rid of our crtc->config pointer */
7550 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7551 crtc->config = new_crtc_state;
7553 if (state->modeset) {
7554 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7556 intel_set_cdclk_pre_plane_update(state);
7558 intel_modeset_verify_disabled(dev_priv, state);
7561 intel_sagv_pre_plane_update(state);
7563 /* Complete the events for pipes that have now been disabled */
7564 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7565 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7567 /* Complete events for now disable pipes here. */
7568 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7569 spin_lock_irq(&dev->event_lock);
7570 drm_crtc_send_vblank_event(&crtc->base,
7571 new_crtc_state->uapi.event);
7572 spin_unlock_irq(&dev->event_lock);
7574 new_crtc_state->uapi.event = NULL;
7578 intel_encoders_update_prepare(state);
7580 intel_dbuf_pre_plane_update(state);
7581 intel_mbus_dbox_update(state);
7583 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7584 if (new_crtc_state->do_async_flip)
7585 intel_crtc_enable_flip_done(state, crtc);
7588 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7589 dev_priv->display.funcs.display->commit_modeset_enables(state);
7591 intel_encoders_update_complete(state);
7594 intel_set_cdclk_post_plane_update(state);
7596 intel_wait_for_vblank_workers(state);
7598 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7599 * already, but still need the state for the delayed optimization. To
7601 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7602 * - schedule that vblank worker _before_ calling hw_done
7603 * - at the start of commit_tail, cancel it _synchrously
7604 * - switch over to the vblank wait helper in the core after that since
7605 * we don't need out special handling any more.
7607 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7609 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7610 if (new_crtc_state->do_async_flip)
7611 intel_crtc_disable_flip_done(state, crtc);
7615 * Now that the vblank has passed, we can go ahead and program the
7616 * optimal watermarks on platforms that need two-step watermark
7619 * TODO: Move this (and other cleanup) to an async worker eventually.
7621 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7622 new_crtc_state, i) {
7624 * Gen2 reports pipe underruns whenever all planes are disabled.
7625 * So re-enable underrun reporting after some planes get enabled.
7627 * We do this before .optimize_watermarks() so that we have a
7628 * chance of catching underruns with the intermediate watermarks
7629 * vs. the new plane configuration.
7631 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7632 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7634 intel_optimize_watermarks(state, crtc);
7637 intel_dbuf_post_plane_update(state);
7638 intel_psr_post_plane_update(state);
7640 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7641 intel_post_plane_update(state, crtc);
7643 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7645 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
7648 * DSB cleanup is done in cleanup_work aligning with framebuffer
7649 * cleanup. So copy and reset the dsb structure to sync with
7650 * commit_done and later do dsb cleanup in cleanup_work.
7652 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7655 /* Underruns don't always raise interrupts, so check manually */
7656 intel_check_cpu_fifo_underruns(dev_priv);
7657 intel_check_pch_fifo_underruns(dev_priv);
7660 intel_verify_planes(state);
7662 intel_sagv_post_plane_update(state);
7664 drm_atomic_helper_commit_hw_done(&state->base);
7666 if (state->modeset) {
7667 /* As one of the primary mmio accessors, KMS has a high
7668 * likelihood of triggering bugs in unclaimed access. After we
7669 * finish modesetting, see if an error has been flagged, and if
7670 * so enable debugging for the next modeset - and hope we catch
7673 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7674 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
7676 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7679 * Defer the cleanup of the old state to a separate worker to not
7680 * impede the current task (userspace for blocking modesets) that
7681 * are executed inline. For out-of-line asynchronous modesets/flips,
7682 * deferring to a new worker seems overkill, but we would place a
7683 * schedule point (cond_resched()) here anyway to keep latencies
7686 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7687 queue_work(system_highpri_wq, &state->base.commit_work);
7690 static void intel_atomic_commit_work(struct work_struct *work)
7692 struct intel_atomic_state *state =
7693 container_of(work, struct intel_atomic_state, base.commit_work);
7695 intel_atomic_commit_tail(state);
7699 intel_atomic_commit_ready(struct i915_sw_fence *fence,
7700 enum i915_sw_fence_notify notify)
7702 struct intel_atomic_state *state =
7703 container_of(fence, struct intel_atomic_state, commit_ready);
7706 case FENCE_COMPLETE:
7707 /* we do blocking waits in the worker, nothing to do here */
7711 struct intel_atomic_helper *helper =
7712 &to_i915(state->base.dev)->atomic_helper;
7714 if (llist_add(&state->freed, &helper->free_list))
7715 schedule_work(&helper->free_work);
7723 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7725 struct intel_plane_state *old_plane_state, *new_plane_state;
7726 struct intel_plane *plane;
7729 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7731 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7732 to_intel_frontbuffer(new_plane_state->hw.fb),
7733 plane->frontbuffer_bit);
7736 static int intel_atomic_commit(struct drm_device *dev,
7737 struct drm_atomic_state *_state,
7740 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7741 struct drm_i915_private *dev_priv = to_i915(dev);
7744 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7746 drm_atomic_state_get(&state->base);
7747 i915_sw_fence_init(&state->commit_ready,
7748 intel_atomic_commit_ready);
7751 * The intel_legacy_cursor_update() fast path takes care
7752 * of avoiding the vblank waits for simple cursor
7753 * movement and flips. For cursor on/off and size changes,
7754 * we want to perform the vblank waits so that watermark
7755 * updates happen during the correct frames. Gen9+ have
7756 * double buffered watermarks and so shouldn't need this.
7758 * Unset state->legacy_cursor_update before the call to
7759 * drm_atomic_helper_setup_commit() because otherwise
7760 * drm_atomic_helper_wait_for_flip_done() is a noop and
7761 * we get FIFO underruns because we didn't wait
7764 * FIXME doing watermarks and fb cleanup from a vblank worker
7765 * (assuming we had any) would solve these problems.
7767 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7768 struct intel_crtc_state *new_crtc_state;
7769 struct intel_crtc *crtc;
7772 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7773 if (new_crtc_state->wm.need_postvbl_update ||
7774 new_crtc_state->update_wm_post)
7775 state->base.legacy_cursor_update = false;
7778 ret = intel_atomic_prepare_commit(state);
7780 drm_dbg_atomic(&dev_priv->drm,
7781 "Preparing state failed with %i\n", ret);
7782 i915_sw_fence_commit(&state->commit_ready);
7783 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7787 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7789 ret = drm_atomic_helper_swap_state(&state->base, true);
7791 intel_atomic_swap_global_state(state);
7794 struct intel_crtc_state *new_crtc_state;
7795 struct intel_crtc *crtc;
7798 i915_sw_fence_commit(&state->commit_ready);
7800 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7801 intel_dsb_cleanup(new_crtc_state);
7803 drm_atomic_helper_cleanup_planes(dev, &state->base);
7804 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7807 intel_shared_dpll_swap_state(state);
7808 intel_atomic_track_fbs(state);
7810 drm_atomic_state_get(&state->base);
7811 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7813 i915_sw_fence_commit(&state->commit_ready);
7814 if (nonblock && state->modeset) {
7815 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
7816 } else if (nonblock) {
7817 queue_work(dev_priv->flip_wq, &state->base.commit_work);
7820 flush_workqueue(dev_priv->modeset_wq);
7821 intel_atomic_commit_tail(state);
7828 * intel_plane_destroy - destroy a plane
7829 * @plane: plane to destroy
7831 * Common destruction function for all types of planes (primary, cursor,
7834 void intel_plane_destroy(struct drm_plane *plane)
7836 drm_plane_cleanup(plane);
7837 kfree(to_intel_plane(plane));
7840 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
7842 struct intel_plane *plane;
7844 for_each_intel_plane(&dev_priv->drm, plane) {
7845 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv,
7848 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
7853 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7854 struct drm_file *file)
7856 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7857 struct drm_crtc *drmmode_crtc;
7858 struct intel_crtc *crtc;
7860 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7864 crtc = to_intel_crtc(drmmode_crtc);
7865 pipe_from_crtc_id->pipe = crtc->pipe;
7870 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7872 struct drm_device *dev = encoder->base.dev;
7873 struct intel_encoder *source_encoder;
7874 u32 possible_clones = 0;
7876 for_each_intel_encoder(dev, source_encoder) {
7877 if (encoders_cloneable(encoder, source_encoder))
7878 possible_clones |= drm_encoder_mask(&source_encoder->base);
7881 return possible_clones;
7884 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7886 struct drm_device *dev = encoder->base.dev;
7887 struct intel_crtc *crtc;
7888 u32 possible_crtcs = 0;
7890 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7891 possible_crtcs |= drm_crtc_mask(&crtc->base);
7893 return possible_crtcs;
7896 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7898 if (!IS_MOBILE(dev_priv))
7901 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7904 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7910 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7912 if (DISPLAY_VER(dev_priv) >= 9)
7915 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
7918 if (HAS_PCH_LPT_H(dev_priv) &&
7919 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7922 /* DDI E can't be used if DDI A requires 4 lanes */
7923 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7926 if (!dev_priv->vbt.int_crt_support)
7932 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
7934 struct intel_encoder *encoder;
7935 bool dpd_is_edp = false;
7937 intel_pps_unlock_regs_wa(dev_priv);
7939 if (!HAS_DISPLAY(dev_priv))
7942 if (IS_DG2(dev_priv)) {
7943 intel_ddi_init(dev_priv, PORT_A);
7944 intel_ddi_init(dev_priv, PORT_B);
7945 intel_ddi_init(dev_priv, PORT_C);
7946 intel_ddi_init(dev_priv, PORT_D_XELPD);
7947 intel_ddi_init(dev_priv, PORT_TC1);
7948 } else if (IS_ALDERLAKE_P(dev_priv)) {
7949 intel_ddi_init(dev_priv, PORT_A);
7950 intel_ddi_init(dev_priv, PORT_B);
7951 intel_ddi_init(dev_priv, PORT_TC1);
7952 intel_ddi_init(dev_priv, PORT_TC2);
7953 intel_ddi_init(dev_priv, PORT_TC3);
7954 intel_ddi_init(dev_priv, PORT_TC4);
7955 icl_dsi_init(dev_priv);
7956 } else if (IS_ALDERLAKE_S(dev_priv)) {
7957 intel_ddi_init(dev_priv, PORT_A);
7958 intel_ddi_init(dev_priv, PORT_TC1);
7959 intel_ddi_init(dev_priv, PORT_TC2);
7960 intel_ddi_init(dev_priv, PORT_TC3);
7961 intel_ddi_init(dev_priv, PORT_TC4);
7962 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
7963 intel_ddi_init(dev_priv, PORT_A);
7964 intel_ddi_init(dev_priv, PORT_B);
7965 intel_ddi_init(dev_priv, PORT_TC1);
7966 intel_ddi_init(dev_priv, PORT_TC2);
7967 } else if (DISPLAY_VER(dev_priv) >= 12) {
7968 intel_ddi_init(dev_priv, PORT_A);
7969 intel_ddi_init(dev_priv, PORT_B);
7970 intel_ddi_init(dev_priv, PORT_TC1);
7971 intel_ddi_init(dev_priv, PORT_TC2);
7972 intel_ddi_init(dev_priv, PORT_TC3);
7973 intel_ddi_init(dev_priv, PORT_TC4);
7974 intel_ddi_init(dev_priv, PORT_TC5);
7975 intel_ddi_init(dev_priv, PORT_TC6);
7976 icl_dsi_init(dev_priv);
7977 } else if (IS_JSL_EHL(dev_priv)) {
7978 intel_ddi_init(dev_priv, PORT_A);
7979 intel_ddi_init(dev_priv, PORT_B);
7980 intel_ddi_init(dev_priv, PORT_C);
7981 intel_ddi_init(dev_priv, PORT_D);
7982 icl_dsi_init(dev_priv);
7983 } else if (DISPLAY_VER(dev_priv) == 11) {
7984 intel_ddi_init(dev_priv, PORT_A);
7985 intel_ddi_init(dev_priv, PORT_B);
7986 intel_ddi_init(dev_priv, PORT_C);
7987 intel_ddi_init(dev_priv, PORT_D);
7988 intel_ddi_init(dev_priv, PORT_E);
7989 intel_ddi_init(dev_priv, PORT_F);
7990 icl_dsi_init(dev_priv);
7991 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
7992 intel_ddi_init(dev_priv, PORT_A);
7993 intel_ddi_init(dev_priv, PORT_B);
7994 intel_ddi_init(dev_priv, PORT_C);
7995 vlv_dsi_init(dev_priv);
7996 } else if (DISPLAY_VER(dev_priv) >= 9) {
7997 intel_ddi_init(dev_priv, PORT_A);
7998 intel_ddi_init(dev_priv, PORT_B);
7999 intel_ddi_init(dev_priv, PORT_C);
8000 intel_ddi_init(dev_priv, PORT_D);
8001 intel_ddi_init(dev_priv, PORT_E);
8002 } else if (HAS_DDI(dev_priv)) {
8005 if (intel_ddi_crt_present(dev_priv))
8006 intel_crt_init(dev_priv);
8008 /* Haswell uses DDI functions to detect digital outputs. */
8009 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
8011 intel_ddi_init(dev_priv, PORT_A);
8013 found = intel_de_read(dev_priv, SFUSE_STRAP);
8014 if (found & SFUSE_STRAP_DDIB_DETECTED)
8015 intel_ddi_init(dev_priv, PORT_B);
8016 if (found & SFUSE_STRAP_DDIC_DETECTED)
8017 intel_ddi_init(dev_priv, PORT_C);
8018 if (found & SFUSE_STRAP_DDID_DETECTED)
8019 intel_ddi_init(dev_priv, PORT_D);
8020 if (found & SFUSE_STRAP_DDIF_DETECTED)
8021 intel_ddi_init(dev_priv, PORT_F);
8022 } else if (HAS_PCH_SPLIT(dev_priv)) {
8026 * intel_edp_init_connector() depends on this completing first,
8027 * to prevent the registration of both eDP and LVDS and the
8028 * incorrect sharing of the PPS.
8030 intel_lvds_init(dev_priv);
8031 intel_crt_init(dev_priv);
8033 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
8035 if (ilk_has_edp_a(dev_priv))
8036 g4x_dp_init(dev_priv, DP_A, PORT_A);
8038 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
8039 /* PCH SDVOB multiplex with HDMIB */
8040 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
8042 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
8043 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
8044 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
8047 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
8048 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
8050 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
8051 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
8053 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
8054 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
8056 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
8057 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
8058 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
8059 bool has_edp, has_port;
8061 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
8062 intel_crt_init(dev_priv);
8065 * The DP_DETECTED bit is the latched state of the DDC
8066 * SDA pin at boot. However since eDP doesn't require DDC
8067 * (no way to plug in a DP->HDMI dongle) the DDC pins for
8068 * eDP ports may have been muxed to an alternate function.
8069 * Thus we can't rely on the DP_DETECTED bit alone to detect
8070 * eDP ports. Consult the VBT as well as DP_DETECTED to
8073 * Sadly the straps seem to be missing sometimes even for HDMI
8074 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
8075 * and VBT for the presence of the port. Additionally we can't
8076 * trust the port type the VBT declares as we've seen at least
8077 * HDMI ports that the VBT claim are DP or eDP.
8079 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
8080 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
8081 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
8082 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
8083 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
8084 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
8086 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
8087 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
8088 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
8089 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
8090 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
8091 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
8093 if (IS_CHERRYVIEW(dev_priv)) {
8095 * eDP not supported on port D,
8096 * so no need to worry about it
8098 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
8099 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
8100 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
8101 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
8102 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
8105 vlv_dsi_init(dev_priv);
8106 } else if (IS_PINEVIEW(dev_priv)) {
8107 intel_lvds_init(dev_priv);
8108 intel_crt_init(dev_priv);
8109 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
8112 if (IS_MOBILE(dev_priv))
8113 intel_lvds_init(dev_priv);
8115 intel_crt_init(dev_priv);
8117 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8118 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
8119 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
8120 if (!found && IS_G4X(dev_priv)) {
8121 drm_dbg_kms(&dev_priv->drm,
8122 "probing HDMI on SDVOB\n");
8123 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
8126 if (!found && IS_G4X(dev_priv))
8127 g4x_dp_init(dev_priv, DP_B, PORT_B);
8130 /* Before G4X SDVOC doesn't have its own detect register */
8132 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8133 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
8134 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
8137 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
8139 if (IS_G4X(dev_priv)) {
8140 drm_dbg_kms(&dev_priv->drm,
8141 "probing HDMI on SDVOC\n");
8142 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
8144 if (IS_G4X(dev_priv))
8145 g4x_dp_init(dev_priv, DP_C, PORT_C);
8148 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
8149 g4x_dp_init(dev_priv, DP_D, PORT_D);
8151 if (SUPPORTS_TV(dev_priv))
8152 intel_tv_init(dev_priv);
8153 } else if (DISPLAY_VER(dev_priv) == 2) {
8154 if (IS_I85X(dev_priv))
8155 intel_lvds_init(dev_priv);
8157 intel_crt_init(dev_priv);
8158 intel_dvo_init(dev_priv);
8161 for_each_intel_encoder(&dev_priv->drm, encoder) {
8162 encoder->base.possible_crtcs =
8163 intel_encoder_possible_crtcs(encoder);
8164 encoder->base.possible_clones =
8165 intel_encoder_possible_clones(encoder);
8168 intel_init_pch_refclk(dev_priv);
8170 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
8173 static enum drm_mode_status
8174 intel_mode_valid(struct drm_device *dev,
8175 const struct drm_display_mode *mode)
8177 struct drm_i915_private *dev_priv = to_i915(dev);
8178 int hdisplay_max, htotal_max;
8179 int vdisplay_max, vtotal_max;
8182 * Can't reject DBLSCAN here because Xorg ddxen can add piles
8183 * of DBLSCAN modes to the output's mode list when they detect
8184 * the scaling mode property on the connector. And they don't
8185 * ask the kernel to validate those modes in any way until
8186 * modeset time at which point the client gets a protocol error.
8187 * So in order to not upset those clients we silently ignore the
8188 * DBLSCAN flag on such connectors. For other connectors we will
8189 * reject modes with the DBLSCAN flag in encoder->compute_config().
8190 * And we always reject DBLSCAN modes in connector->mode_valid()
8191 * as we never want such modes on the connector's mode list.
8194 if (mode->vscan > 1)
8195 return MODE_NO_VSCAN;
8197 if (mode->flags & DRM_MODE_FLAG_HSKEW)
8198 return MODE_H_ILLEGAL;
8200 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
8201 DRM_MODE_FLAG_NCSYNC |
8202 DRM_MODE_FLAG_PCSYNC))
8205 if (mode->flags & (DRM_MODE_FLAG_BCAST |
8206 DRM_MODE_FLAG_PIXMUX |
8207 DRM_MODE_FLAG_CLKDIV2))
8210 /* Transcoder timing limits */
8211 if (DISPLAY_VER(dev_priv) >= 11) {
8212 hdisplay_max = 16384;
8213 vdisplay_max = 8192;
8216 } else if (DISPLAY_VER(dev_priv) >= 9 ||
8217 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
8218 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
8219 vdisplay_max = 4096;
8222 } else if (DISPLAY_VER(dev_priv) >= 3) {
8223 hdisplay_max = 4096;
8224 vdisplay_max = 4096;
8228 hdisplay_max = 2048;
8229 vdisplay_max = 2048;
8234 if (mode->hdisplay > hdisplay_max ||
8235 mode->hsync_start > htotal_max ||
8236 mode->hsync_end > htotal_max ||
8237 mode->htotal > htotal_max)
8238 return MODE_H_ILLEGAL;
8240 if (mode->vdisplay > vdisplay_max ||
8241 mode->vsync_start > vtotal_max ||
8242 mode->vsync_end > vtotal_max ||
8243 mode->vtotal > vtotal_max)
8244 return MODE_V_ILLEGAL;
8246 if (DISPLAY_VER(dev_priv) >= 5) {
8247 if (mode->hdisplay < 64 ||
8248 mode->htotal - mode->hdisplay < 32)
8249 return MODE_H_ILLEGAL;
8251 if (mode->vtotal - mode->vdisplay < 5)
8252 return MODE_V_ILLEGAL;
8254 if (mode->htotal - mode->hdisplay < 32)
8255 return MODE_H_ILLEGAL;
8257 if (mode->vtotal - mode->vdisplay < 3)
8258 return MODE_V_ILLEGAL;
8262 * Cantiga+ cannot handle modes with a hsync front porch of 0.
8263 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
8265 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
8266 mode->hsync_start == mode->hdisplay)
8267 return MODE_H_ILLEGAL;
8272 enum drm_mode_status
8273 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
8274 const struct drm_display_mode *mode,
8277 int plane_width_max, plane_height_max;
8280 * intel_mode_valid() should be
8281 * sufficient on older platforms.
8283 if (DISPLAY_VER(dev_priv) < 9)
8287 * Most people will probably want a fullscreen
8288 * plane so let's not advertize modes that are
8291 if (DISPLAY_VER(dev_priv) >= 11) {
8292 plane_width_max = 5120 << bigjoiner;
8293 plane_height_max = 4320;
8295 plane_width_max = 5120;
8296 plane_height_max = 4096;
8299 if (mode->hdisplay > plane_width_max)
8300 return MODE_H_ILLEGAL;
8302 if (mode->vdisplay > plane_height_max)
8303 return MODE_V_ILLEGAL;
8308 static const struct drm_mode_config_funcs intel_mode_funcs = {
8309 .fb_create = intel_user_framebuffer_create,
8310 .get_format_info = intel_fb_get_format_info,
8311 .output_poll_changed = intel_fbdev_output_poll_changed,
8312 .mode_valid = intel_mode_valid,
8313 .atomic_check = intel_atomic_check,
8314 .atomic_commit = intel_atomic_commit,
8315 .atomic_state_alloc = intel_atomic_state_alloc,
8316 .atomic_state_clear = intel_atomic_state_clear,
8317 .atomic_state_free = intel_atomic_state_free,
8320 static const struct intel_display_funcs skl_display_funcs = {
8321 .get_pipe_config = hsw_get_pipe_config,
8322 .crtc_enable = hsw_crtc_enable,
8323 .crtc_disable = hsw_crtc_disable,
8324 .commit_modeset_enables = skl_commit_modeset_enables,
8325 .get_initial_plane_config = skl_get_initial_plane_config,
8328 static const struct intel_display_funcs ddi_display_funcs = {
8329 .get_pipe_config = hsw_get_pipe_config,
8330 .crtc_enable = hsw_crtc_enable,
8331 .crtc_disable = hsw_crtc_disable,
8332 .commit_modeset_enables = intel_commit_modeset_enables,
8333 .get_initial_plane_config = i9xx_get_initial_plane_config,
8336 static const struct intel_display_funcs pch_split_display_funcs = {
8337 .get_pipe_config = ilk_get_pipe_config,
8338 .crtc_enable = ilk_crtc_enable,
8339 .crtc_disable = ilk_crtc_disable,
8340 .commit_modeset_enables = intel_commit_modeset_enables,
8341 .get_initial_plane_config = i9xx_get_initial_plane_config,
8344 static const struct intel_display_funcs vlv_display_funcs = {
8345 .get_pipe_config = i9xx_get_pipe_config,
8346 .crtc_enable = valleyview_crtc_enable,
8347 .crtc_disable = i9xx_crtc_disable,
8348 .commit_modeset_enables = intel_commit_modeset_enables,
8349 .get_initial_plane_config = i9xx_get_initial_plane_config,
8352 static const struct intel_display_funcs i9xx_display_funcs = {
8353 .get_pipe_config = i9xx_get_pipe_config,
8354 .crtc_enable = i9xx_crtc_enable,
8355 .crtc_disable = i9xx_crtc_disable,
8356 .commit_modeset_enables = intel_commit_modeset_enables,
8357 .get_initial_plane_config = i9xx_get_initial_plane_config,
8361 * intel_init_display_hooks - initialize the display modesetting hooks
8362 * @dev_priv: device private
8364 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
8366 if (!HAS_DISPLAY(dev_priv))
8369 intel_init_cdclk_hooks(dev_priv);
8370 intel_audio_hooks_init(dev_priv);
8372 intel_dpll_init_clock_hook(dev_priv);
8374 if (DISPLAY_VER(dev_priv) >= 9) {
8375 dev_priv->display.funcs.display = &skl_display_funcs;
8376 } else if (HAS_DDI(dev_priv)) {
8377 dev_priv->display.funcs.display = &ddi_display_funcs;
8378 } else if (HAS_PCH_SPLIT(dev_priv)) {
8379 dev_priv->display.funcs.display = &pch_split_display_funcs;
8380 } else if (IS_CHERRYVIEW(dev_priv) ||
8381 IS_VALLEYVIEW(dev_priv)) {
8382 dev_priv->display.funcs.display = &vlv_display_funcs;
8384 dev_priv->display.funcs.display = &i9xx_display_funcs;
8387 intel_fdi_init_hook(dev_priv);
8390 void intel_modeset_init_hw(struct drm_i915_private *i915)
8392 struct intel_cdclk_state *cdclk_state;
8394 if (!HAS_DISPLAY(i915))
8397 cdclk_state = to_intel_cdclk_state(i915->cdclk.obj.state);
8399 intel_update_cdclk(i915);
8400 intel_cdclk_dump_config(i915, &i915->cdclk.hw, "Current CDCLK");
8401 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
8404 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
8406 struct drm_plane *plane;
8407 struct intel_crtc *crtc;
8409 for_each_intel_crtc(state->dev, crtc) {
8410 struct intel_crtc_state *crtc_state;
8412 crtc_state = intel_atomic_get_crtc_state(state, crtc);
8413 if (IS_ERR(crtc_state))
8414 return PTR_ERR(crtc_state);
8416 if (crtc_state->hw.active) {
8418 * Preserve the inherited flag to avoid
8419 * taking the full modeset path.
8421 crtc_state->inherited = true;
8425 drm_for_each_plane(plane, state->dev) {
8426 struct drm_plane_state *plane_state;
8428 plane_state = drm_atomic_get_plane_state(state, plane);
8429 if (IS_ERR(plane_state))
8430 return PTR_ERR(plane_state);
8437 * Calculate what we think the watermarks should be for the state we've read
8438 * out of the hardware and then immediately program those watermarks so that
8439 * we ensure the hardware settings match our internal state.
8441 * We can calculate what we think WM's should be by creating a duplicate of the
8442 * current state (which was constructed during hardware readout) and running it
8443 * through the atomic check code to calculate new watermark values in the
8446 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
8448 struct drm_atomic_state *state;
8449 struct intel_atomic_state *intel_state;
8450 struct intel_crtc *crtc;
8451 struct intel_crtc_state *crtc_state;
8452 struct drm_modeset_acquire_ctx ctx;
8456 /* Only supported on platforms that use atomic watermark design */
8457 if (!dev_priv->display.funcs.wm->optimize_watermarks)
8460 state = drm_atomic_state_alloc(&dev_priv->drm);
8461 if (drm_WARN_ON(&dev_priv->drm, !state))
8464 intel_state = to_intel_atomic_state(state);
8466 drm_modeset_acquire_init(&ctx, 0);
8469 state->acquire_ctx = &ctx;
8472 * Hardware readout is the only time we don't want to calculate
8473 * intermediate watermarks (since we don't trust the current
8476 if (!HAS_GMCH(dev_priv))
8477 intel_state->skip_intermediate_wm = true;
8479 ret = sanitize_watermarks_add_affected(state);
8483 ret = intel_atomic_check(&dev_priv->drm, state);
8487 /* Write calculated watermark values back */
8488 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
8489 crtc_state->wm.need_postvbl_update = true;
8490 intel_optimize_watermarks(intel_state, crtc);
8492 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
8496 if (ret == -EDEADLK) {
8497 drm_atomic_state_clear(state);
8498 drm_modeset_backoff(&ctx);
8503 * If we fail here, it means that the hardware appears to be
8504 * programmed in a way that shouldn't be possible, given our
8505 * understanding of watermark requirements. This might mean a
8506 * mistake in the hardware readout code or a mistake in the
8507 * watermark calculations for a given platform. Raise a WARN
8508 * so that this is noticeable.
8510 * If this actually happens, we'll have to just leave the
8511 * BIOS-programmed watermarks untouched and hope for the best.
8513 drm_WARN(&dev_priv->drm, ret,
8514 "Could not determine valid watermarks for inherited state\n");
8516 drm_atomic_state_put(state);
8518 drm_modeset_drop_locks(&ctx);
8519 drm_modeset_acquire_fini(&ctx);
8522 static int intel_initial_commit(struct drm_device *dev)
8524 struct drm_atomic_state *state = NULL;
8525 struct drm_modeset_acquire_ctx ctx;
8526 struct intel_crtc *crtc;
8529 state = drm_atomic_state_alloc(dev);
8533 drm_modeset_acquire_init(&ctx, 0);
8536 state->acquire_ctx = &ctx;
8538 for_each_intel_crtc(dev, crtc) {
8539 struct intel_crtc_state *crtc_state =
8540 intel_atomic_get_crtc_state(state, crtc);
8542 if (IS_ERR(crtc_state)) {
8543 ret = PTR_ERR(crtc_state);
8547 if (crtc_state->hw.active) {
8548 struct intel_encoder *encoder;
8551 * We've not yet detected sink capabilities
8552 * (audio,infoframes,etc.) and thus we don't want to
8553 * force a full state recomputation yet. We want that to
8554 * happen only for the first real commit from userspace.
8555 * So preserve the inherited flag for the time being.
8557 crtc_state->inherited = true;
8559 ret = drm_atomic_add_affected_planes(state, &crtc->base);
8564 * FIXME hack to force a LUT update to avoid the
8565 * plane update forcing the pipe gamma on without
8566 * having a proper LUT loaded. Remove once we
8567 * have readout for pipe gamma enable.
8569 crtc_state->uapi.color_mgmt_changed = true;
8571 for_each_intel_encoder_mask(dev, encoder,
8572 crtc_state->uapi.encoder_mask) {
8573 if (encoder->initial_fastset_check &&
8574 !encoder->initial_fastset_check(encoder, crtc_state)) {
8575 ret = drm_atomic_add_affected_connectors(state,
8584 ret = drm_atomic_commit(state);
8587 if (ret == -EDEADLK) {
8588 drm_atomic_state_clear(state);
8589 drm_modeset_backoff(&ctx);
8593 drm_atomic_state_put(state);
8595 drm_modeset_drop_locks(&ctx);
8596 drm_modeset_acquire_fini(&ctx);
8601 static void intel_mode_config_init(struct drm_i915_private *i915)
8603 struct drm_mode_config *mode_config = &i915->drm.mode_config;
8605 drm_mode_config_init(&i915->drm);
8606 INIT_LIST_HEAD(&i915->global_obj_list);
8608 mode_config->min_width = 0;
8609 mode_config->min_height = 0;
8611 mode_config->preferred_depth = 24;
8612 mode_config->prefer_shadow = 1;
8614 mode_config->funcs = &intel_mode_funcs;
8616 mode_config->async_page_flip = HAS_ASYNC_FLIPS(i915);
8619 * Maximum framebuffer dimensions, chosen to match
8620 * the maximum render engine surface size on gen4+.
8622 if (DISPLAY_VER(i915) >= 7) {
8623 mode_config->max_width = 16384;
8624 mode_config->max_height = 16384;
8625 } else if (DISPLAY_VER(i915) >= 4) {
8626 mode_config->max_width = 8192;
8627 mode_config->max_height = 8192;
8628 } else if (DISPLAY_VER(i915) == 3) {
8629 mode_config->max_width = 4096;
8630 mode_config->max_height = 4096;
8632 mode_config->max_width = 2048;
8633 mode_config->max_height = 2048;
8636 if (IS_I845G(i915) || IS_I865G(i915)) {
8637 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
8638 mode_config->cursor_height = 1023;
8639 } else if (IS_I830(i915) || IS_I85X(i915) ||
8640 IS_I915G(i915) || IS_I915GM(i915)) {
8641 mode_config->cursor_width = 64;
8642 mode_config->cursor_height = 64;
8644 mode_config->cursor_width = 256;
8645 mode_config->cursor_height = 256;
8649 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
8651 intel_atomic_global_obj_cleanup(i915);
8652 drm_mode_config_cleanup(&i915->drm);
8655 /* part #1: call before irq install */
8656 int intel_modeset_init_noirq(struct drm_i915_private *i915)
8660 if (i915_inject_probe_failure(i915))
8663 if (HAS_DISPLAY(i915)) {
8664 ret = drm_vblank_init(&i915->drm,
8665 INTEL_NUM_PIPES(i915));
8670 intel_bios_init(i915);
8672 ret = intel_vga_register(i915);
8676 /* FIXME: completely on the wrong abstraction layer */
8677 intel_power_domains_init_hw(i915, false);
8679 if (!HAS_DISPLAY(i915))
8682 intel_dmc_ucode_init(i915);
8684 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
8685 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
8686 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
8688 intel_mode_config_init(i915);
8690 ret = intel_cdclk_init(i915);
8692 goto cleanup_vga_client_pw_domain_dmc;
8694 ret = intel_dbuf_init(i915);
8696 goto cleanup_vga_client_pw_domain_dmc;
8698 ret = intel_bw_init(i915);
8700 goto cleanup_vga_client_pw_domain_dmc;
8702 init_llist_head(&i915->atomic_helper.free_list);
8703 INIT_WORK(&i915->atomic_helper.free_work,
8704 intel_atomic_helper_free_state_worker);
8706 intel_init_quirks(i915);
8708 intel_fbc_init(i915);
8712 cleanup_vga_client_pw_domain_dmc:
8713 intel_dmc_ucode_fini(i915);
8714 intel_power_domains_driver_remove(i915);
8715 intel_vga_unregister(i915);
8717 intel_bios_driver_remove(i915);
8722 /* part #2: call after irq install, but before gem init */
8723 int intel_modeset_init_nogem(struct drm_i915_private *i915)
8725 struct drm_device *dev = &i915->drm;
8727 struct intel_crtc *crtc;
8730 if (!HAS_DISPLAY(i915))
8733 intel_init_pm(i915);
8735 intel_panel_sanitize_ssc(i915);
8737 intel_pps_setup(i915);
8739 intel_gmbus_setup(i915);
8741 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
8742 INTEL_NUM_PIPES(i915),
8743 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
8745 for_each_pipe(i915, pipe) {
8746 ret = intel_crtc_init(i915, pipe);
8748 intel_mode_config_cleanup(i915);
8753 intel_plane_possible_crtcs_init(i915);
8754 intel_shared_dpll_init(i915);
8755 intel_fdi_pll_freq_update(i915);
8757 intel_update_czclk(i915);
8758 intel_modeset_init_hw(i915);
8759 intel_dpll_update_ref_clks(i915);
8761 intel_hdcp_component_init(i915);
8763 if (i915->max_cdclk_freq == 0)
8764 intel_update_max_cdclk(i915);
8767 * If the platform has HTI, we need to find out whether it has reserved
8768 * any display resources before we create our display outputs.
8770 if (INTEL_INFO(i915)->display.has_hti)
8771 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
8773 /* Just disable it once at startup */
8774 intel_vga_disable(i915);
8775 intel_setup_outputs(i915);
8777 drm_modeset_lock_all(dev);
8778 intel_modeset_setup_hw_state(i915, dev->mode_config.acquire_ctx);
8779 intel_acpi_assign_connector_fwnodes(i915);
8780 drm_modeset_unlock_all(dev);
8782 for_each_intel_crtc(dev, crtc) {
8783 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
8785 intel_crtc_initial_plane_config(crtc);
8789 * Make sure hardware watermarks really match the state we read out.
8790 * Note that we need to do this after reconstructing the BIOS fb's
8791 * since the watermark calculation done here will use pstate->fb.
8793 if (!HAS_GMCH(i915))
8794 sanitize_watermarks(i915);
8799 /* part #3: call after gem init */
8800 int intel_modeset_init(struct drm_i915_private *i915)
8804 if (!HAS_DISPLAY(i915))
8808 * Force all active planes to recompute their states. So that on
8809 * mode_setcrtc after probe, all the intel_plane_state variables
8810 * are already calculated and there is no assert_plane warnings
8813 ret = intel_initial_commit(&i915->drm);
8815 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
8817 intel_overlay_setup(i915);
8819 ret = intel_fbdev_init(&i915->drm);
8823 /* Only enable hotplug handling once the fbdev is fully set up. */
8824 intel_hpd_init(i915);
8825 intel_hpd_poll_disable(i915);
8827 intel_init_ipc(i915);
8832 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8834 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8835 /* 640x480@60Hz, ~25175 kHz */
8836 struct dpll clock = {
8846 drm_WARN_ON(&dev_priv->drm,
8847 i9xx_calc_dpll_params(48000, &clock) != 25154);
8849 drm_dbg_kms(&dev_priv->drm,
8850 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8851 pipe_name(pipe), clock.vco, clock.dot);
8853 fp = i9xx_dpll_compute_fp(&clock);
8854 dpll = DPLL_DVO_2X_MODE |
8856 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8857 PLL_P2_DIVIDE_BY_4 |
8858 PLL_REF_INPUT_DREFCLK |
8861 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
8862 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
8863 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
8864 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
8865 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
8866 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
8867 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
8869 intel_de_write(dev_priv, FP0(pipe), fp);
8870 intel_de_write(dev_priv, FP1(pipe), fp);
8873 * Apparently we need to have VGA mode enabled prior to changing
8874 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8875 * dividers, even though the register value does change.
8877 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
8878 intel_de_write(dev_priv, DPLL(pipe), dpll);
8880 /* Wait for the clocks to stabilize. */
8881 intel_de_posting_read(dev_priv, DPLL(pipe));
8884 /* The pixel multiplier can only be updated once the
8885 * DPLL is enabled and the clocks are stable.
8887 * So write it again.
8889 intel_de_write(dev_priv, DPLL(pipe), dpll);
8891 /* We do this three times for luck */
8892 for (i = 0; i < 3 ; i++) {
8893 intel_de_write(dev_priv, DPLL(pipe), dpll);
8894 intel_de_posting_read(dev_priv, DPLL(pipe));
8895 udelay(150); /* wait for warmup */
8898 intel_de_write(dev_priv, PIPECONF(pipe), PIPECONF_ENABLE);
8899 intel_de_posting_read(dev_priv, PIPECONF(pipe));
8901 intel_wait_for_pipe_scanline_moving(crtc);
8904 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8906 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8908 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
8911 drm_WARN_ON(&dev_priv->drm,
8912 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
8913 drm_WARN_ON(&dev_priv->drm,
8914 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
8915 drm_WARN_ON(&dev_priv->drm,
8916 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
8917 drm_WARN_ON(&dev_priv->drm,
8918 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
8919 drm_WARN_ON(&dev_priv->drm,
8920 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
8922 intel_de_write(dev_priv, PIPECONF(pipe), 0);
8923 intel_de_posting_read(dev_priv, PIPECONF(pipe));
8925 intel_wait_for_pipe_scanline_stopped(crtc);
8927 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
8928 intel_de_posting_read(dev_priv, DPLL(pipe));
8931 void intel_display_resume(struct drm_device *dev)
8933 struct drm_i915_private *i915 = to_i915(dev);
8934 struct drm_atomic_state *state = i915->modeset_restore_state;
8935 struct drm_modeset_acquire_ctx ctx;
8938 if (!HAS_DISPLAY(i915))
8941 i915->modeset_restore_state = NULL;
8943 state->acquire_ctx = &ctx;
8945 drm_modeset_acquire_init(&ctx, 0);
8948 ret = drm_modeset_lock_all_ctx(dev, &ctx);
8949 if (ret != -EDEADLK)
8952 drm_modeset_backoff(&ctx);
8956 ret = __intel_display_resume(i915, state, &ctx);
8958 intel_enable_ipc(i915);
8959 drm_modeset_drop_locks(&ctx);
8960 drm_modeset_acquire_fini(&ctx);
8964 "Restoring old state failed with %i\n", ret);
8966 drm_atomic_state_put(state);
8969 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
8971 struct intel_connector *connector;
8972 struct drm_connector_list_iter conn_iter;
8974 /* Kill all the work that may have been queued by hpd. */
8975 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8976 for_each_intel_connector_iter(connector, &conn_iter) {
8977 if (connector->modeset_retry_work.func)
8978 cancel_work_sync(&connector->modeset_retry_work);
8979 if (connector->hdcp.shim) {
8980 cancel_delayed_work_sync(&connector->hdcp.check_work);
8981 cancel_work_sync(&connector->hdcp.prop_work);
8984 drm_connector_list_iter_end(&conn_iter);
8987 /* part #1: call before irq uninstall */
8988 void intel_modeset_driver_remove(struct drm_i915_private *i915)
8990 if (!HAS_DISPLAY(i915))
8993 flush_workqueue(i915->flip_wq);
8994 flush_workqueue(i915->modeset_wq);
8996 flush_work(&i915->atomic_helper.free_work);
8997 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
9000 /* part #2: call after irq uninstall */
9001 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
9003 if (!HAS_DISPLAY(i915))
9007 * Due to the hpd irq storm handling the hotplug work can re-arm the
9008 * poll handlers. Hence disable polling after hpd handling is shut down.
9010 intel_hpd_poll_fini(i915);
9013 * MST topology needs to be suspended so we don't have any calls to
9014 * fbdev after it's finalized. MST will be destroyed later as part of
9015 * drm_mode_config_cleanup()
9017 intel_dp_mst_suspend(i915);
9019 /* poll work can call into fbdev, hence clean that up afterwards */
9020 intel_fbdev_fini(i915);
9022 intel_unregister_dsm_handler();
9024 /* flush any delayed tasks or pending work */
9025 flush_scheduled_work();
9027 intel_hdcp_component_fini(i915);
9029 intel_mode_config_cleanup(i915);
9031 intel_overlay_cleanup(i915);
9033 intel_gmbus_teardown(i915);
9035 destroy_workqueue(i915->flip_wq);
9036 destroy_workqueue(i915->modeset_wq);
9038 intel_fbc_cleanup(i915);
9041 /* part #3: call after gem init */
9042 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
9044 intel_dmc_ucode_fini(i915);
9046 intel_power_domains_driver_remove(i915);
9048 intel_vga_unregister(i915);
9050 intel_bios_driver_remove(i915);
9053 bool intel_modeset_probe_defer(struct pci_dev *pdev)
9055 struct drm_privacy_screen *privacy_screen;
9058 * apple-gmux is needed on dual GPU MacBook Pro
9059 * to probe the panel if we're the inactive GPU.
9061 if (vga_switcheroo_client_probe_defer(pdev))
9064 /* If the LCD panel has a privacy-screen, wait for it */
9065 privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
9066 if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
9069 drm_privacy_screen_put(privacy_screen);
9074 void intel_display_driver_register(struct drm_i915_private *i915)
9076 if (!HAS_DISPLAY(i915))
9079 intel_display_debugfs_register(i915);
9081 /* Must be done after probing outputs */
9082 intel_opregion_register(i915);
9083 acpi_video_register();
9085 intel_audio_init(i915);
9088 * Some ports require correctly set-up hpd registers for
9089 * detection to work properly (leading to ghost connected
9090 * connector status), e.g. VGA on gm45. Hence we can only set
9091 * up the initial fbdev config after hpd irqs are fully
9092 * enabled. We do it last so that the async config cannot run
9093 * before the connectors are registered.
9095 intel_fbdev_initial_config_async(&i915->drm);
9098 * We need to coordinate the hotplugs with the asynchronous
9099 * fbdev configuration, for which we use the
9100 * fbdev->async_cookie.
9102 drm_kms_helper_poll_init(&i915->drm);
9105 void intel_display_driver_unregister(struct drm_i915_private *i915)
9107 if (!HAS_DISPLAY(i915))
9110 intel_fbdev_unregister(i915);
9111 intel_audio_deinit(i915);
9114 * After flushing the fbdev (incl. a late async config which
9115 * will have delayed queuing of a hotplug event), then flush
9116 * the hotplug events.
9118 drm_kms_helper_poll_fini(&i915->drm);
9119 drm_atomic_helper_shutdown(&i915->drm);
9121 acpi_video_unregister();
9122 intel_opregion_unregister(i915);
9125 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
9127 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);