2 * Copyright © 2006-2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
27 #include <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->wm_disp->update_wm)
168 dev_priv->wm_disp->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->wm_disp->compute_pipe_wm)
176 return dev_priv->wm_disp->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->wm_disp->compute_intermediate_wm)
186 if (drm_WARN_ON(&dev_priv->drm,
187 !dev_priv->wm_disp->compute_pipe_wm))
189 return dev_priv->wm_disp->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->wm_disp->initial_watermarks) {
197 dev_priv->wm_disp->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->wm_disp->atomic_update_watermarks)
208 dev_priv->wm_disp->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->wm_disp->optimize_watermarks)
216 dev_priv->wm_disp->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->wm_disp->compute_global_watermarks)
223 return dev_priv->wm_disp->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->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_DG2(dev_priv))
2086 * DG2 outputs labelled as "combo PHY" in the bspec use
2087 * SNPS PHYs with completely different programming,
2088 * hence we always return false here.
2091 else if (IS_ALDERLAKE_S(dev_priv))
2092 return phy <= PHY_E;
2093 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
2094 return phy <= PHY_D;
2095 else if (IS_JSL_EHL(dev_priv))
2096 return phy <= PHY_C;
2097 else if (DISPLAY_VER(dev_priv) >= 11)
2098 return phy <= PHY_B;
2103 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
2105 if (IS_DG2(dev_priv))
2106 /* DG2's "TC1" output uses a SNPS PHY */
2108 else if (IS_ALDERLAKE_P(dev_priv))
2109 return phy >= PHY_F && phy <= PHY_I;
2110 else if (IS_TIGERLAKE(dev_priv))
2111 return phy >= PHY_D && phy <= PHY_I;
2112 else if (IS_ICELAKE(dev_priv))
2113 return phy >= PHY_C && phy <= PHY_F;
2118 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
2120 if (phy == PHY_NONE)
2122 else if (IS_DG2(dev_priv))
2124 * All four "combo" ports and the TC1 port (PHY E) use
2127 return phy <= PHY_E;
2132 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
2134 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
2135 return PHY_D + port - PORT_D_XELPD;
2136 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
2137 return PHY_F + port - PORT_TC1;
2138 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
2139 return PHY_B + port - PORT_TC1;
2140 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
2141 return PHY_C + port - PORT_TC1;
2142 else if (IS_JSL_EHL(i915) && port == PORT_D)
2145 return PHY_A + port - PORT_A;
2148 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
2150 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
2151 return TC_PORT_NONE;
2153 if (DISPLAY_VER(dev_priv) >= 12)
2154 return TC_PORT_1 + port - PORT_TC1;
2156 return TC_PORT_1 + port - PORT_C;
2159 enum intel_display_power_domain
2160 intel_aux_power_domain(struct intel_digital_port *dig_port)
2162 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
2164 if (intel_tc_port_in_tbt_alt_mode(dig_port))
2165 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
2167 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
2170 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2171 struct intel_power_domain_mask *mask)
2173 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2174 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2175 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2176 struct drm_encoder *encoder;
2177 enum pipe pipe = crtc->pipe;
2179 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
2181 if (!crtc_state->hw.active)
2184 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
2185 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
2186 if (crtc_state->pch_pfit.enabled ||
2187 crtc_state->pch_pfit.force_thru)
2188 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
2190 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
2191 crtc_state->uapi.encoder_mask) {
2192 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2194 set_bit(intel_encoder->power_domain, mask->bits);
2197 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
2198 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
2200 if (crtc_state->shared_dpll)
2201 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
2203 if (crtc_state->dsc.compression_enable)
2204 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
2207 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2208 struct intel_power_domain_mask *old_domains)
2210 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2211 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2212 enum intel_display_power_domain domain;
2213 struct intel_power_domain_mask domains, new_domains;
2215 get_crtc_power_domains(crtc_state, &domains);
2217 bitmap_andnot(new_domains.bits,
2219 crtc->enabled_power_domains.mask.bits,
2221 bitmap_andnot(old_domains->bits,
2222 crtc->enabled_power_domains.mask.bits,
2226 for_each_power_domain(domain, &new_domains)
2227 intel_display_power_get_in_set(dev_priv,
2228 &crtc->enabled_power_domains,
2232 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
2233 struct intel_power_domain_mask *domains)
2235 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
2236 &crtc->enabled_power_domains,
2240 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
2242 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2243 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2245 if (intel_crtc_has_dp_encoder(crtc_state)) {
2246 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
2247 &crtc_state->dp_m_n);
2248 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
2249 &crtc_state->dp_m2_n2);
2252 intel_set_transcoder_timings(crtc_state);
2254 i9xx_set_pipeconf(crtc_state);
2257 static void valleyview_crtc_enable(struct intel_atomic_state *state,
2258 struct intel_crtc *crtc)
2260 const struct intel_crtc_state *new_crtc_state =
2261 intel_atomic_get_new_crtc_state(state, crtc);
2262 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2263 enum pipe pipe = crtc->pipe;
2265 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2268 i9xx_configure_cpu_transcoder(new_crtc_state);
2270 intel_set_pipe_src_size(new_crtc_state);
2272 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
2273 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY);
2274 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0);
2277 crtc->active = true;
2279 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2281 intel_encoders_pre_pll_enable(state, crtc);
2283 if (IS_CHERRYVIEW(dev_priv))
2284 chv_enable_pll(new_crtc_state);
2286 vlv_enable_pll(new_crtc_state);
2288 intel_encoders_pre_enable(state, crtc);
2290 i9xx_pfit_enable(new_crtc_state);
2292 intel_color_load_luts(new_crtc_state);
2293 intel_color_commit_noarm(new_crtc_state);
2294 intel_color_commit_arm(new_crtc_state);
2295 /* update DSPCNTR to configure gamma for pipe bottom color */
2296 intel_disable_primary_plane(new_crtc_state);
2298 intel_initial_watermarks(state, crtc);
2299 intel_enable_transcoder(new_crtc_state);
2301 intel_crtc_vblank_on(new_crtc_state);
2303 intel_encoders_enable(state, crtc);
2306 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2307 struct intel_crtc *crtc)
2309 const struct intel_crtc_state *new_crtc_state =
2310 intel_atomic_get_new_crtc_state(state, crtc);
2311 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2312 enum pipe pipe = crtc->pipe;
2314 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2317 i9xx_configure_cpu_transcoder(new_crtc_state);
2319 intel_set_pipe_src_size(new_crtc_state);
2321 crtc->active = true;
2323 if (DISPLAY_VER(dev_priv) != 2)
2324 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2326 intel_encoders_pre_enable(state, crtc);
2328 i9xx_enable_pll(new_crtc_state);
2330 i9xx_pfit_enable(new_crtc_state);
2332 intel_color_load_luts(new_crtc_state);
2333 intel_color_commit_noarm(new_crtc_state);
2334 intel_color_commit_arm(new_crtc_state);
2335 /* update DSPCNTR to configure gamma for pipe bottom color */
2336 intel_disable_primary_plane(new_crtc_state);
2338 if (!intel_initial_watermarks(state, crtc))
2339 intel_update_watermarks(dev_priv);
2340 intel_enable_transcoder(new_crtc_state);
2342 intel_crtc_vblank_on(new_crtc_state);
2344 intel_encoders_enable(state, crtc);
2346 /* prevents spurious underruns */
2347 if (DISPLAY_VER(dev_priv) == 2)
2348 intel_crtc_wait_for_next_vblank(crtc);
2351 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2353 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2354 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2356 if (!old_crtc_state->gmch_pfit.control)
2359 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2361 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2362 intel_de_read(dev_priv, PFIT_CONTROL));
2363 intel_de_write(dev_priv, PFIT_CONTROL, 0);
2366 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2367 struct intel_crtc *crtc)
2369 struct intel_crtc_state *old_crtc_state =
2370 intel_atomic_get_old_crtc_state(state, crtc);
2371 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2372 enum pipe pipe = crtc->pipe;
2375 * On gen2 planes are double buffered but the pipe isn't, so we must
2376 * wait for planes to fully turn off before disabling the pipe.
2378 if (DISPLAY_VER(dev_priv) == 2)
2379 intel_crtc_wait_for_next_vblank(crtc);
2381 intel_encoders_disable(state, crtc);
2383 intel_crtc_vblank_off(old_crtc_state);
2385 intel_disable_transcoder(old_crtc_state);
2387 i9xx_pfit_disable(old_crtc_state);
2389 intel_encoders_post_disable(state, crtc);
2391 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2392 if (IS_CHERRYVIEW(dev_priv))
2393 chv_disable_pll(dev_priv, pipe);
2394 else if (IS_VALLEYVIEW(dev_priv))
2395 vlv_disable_pll(dev_priv, pipe);
2397 i9xx_disable_pll(old_crtc_state);
2400 intel_encoders_post_pll_disable(state, crtc);
2402 if (DISPLAY_VER(dev_priv) != 2)
2403 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2405 if (!dev_priv->wm_disp->initial_watermarks)
2406 intel_update_watermarks(dev_priv);
2408 /* clock the pipe down to 640x480@60 to potentially save power */
2409 if (IS_I830(dev_priv))
2410 i830_enable_pipe(dev_priv, pipe);
2415 * turn all crtc's off, but do not adjust state
2416 * This has to be paired with a call to intel_modeset_setup_hw_state.
2418 int intel_display_suspend(struct drm_device *dev)
2420 struct drm_i915_private *dev_priv = to_i915(dev);
2421 struct drm_atomic_state *state;
2424 if (!HAS_DISPLAY(dev_priv))
2427 state = drm_atomic_helper_suspend(dev);
2428 ret = PTR_ERR_OR_ZERO(state);
2430 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n",
2433 dev_priv->modeset_restore_state = state;
2437 void intel_encoder_destroy(struct drm_encoder *encoder)
2439 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2441 drm_encoder_cleanup(encoder);
2442 kfree(intel_encoder);
2445 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2447 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2449 /* GDG double wide on either pipe, otherwise pipe A only */
2450 return DISPLAY_VER(dev_priv) < 4 &&
2451 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2454 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2456 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2457 struct drm_rect src;
2460 * We only use IF-ID interlacing. If we ever use
2461 * PF-ID we'll need to adjust the pixel_rate here.
2464 if (!crtc_state->pch_pfit.enabled)
2467 drm_rect_init(&src, 0, 0,
2468 drm_rect_width(&crtc_state->pipe_src) << 16,
2469 drm_rect_height(&crtc_state->pipe_src) << 16);
2471 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2475 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2476 const struct drm_display_mode *timings)
2478 mode->hdisplay = timings->crtc_hdisplay;
2479 mode->htotal = timings->crtc_htotal;
2480 mode->hsync_start = timings->crtc_hsync_start;
2481 mode->hsync_end = timings->crtc_hsync_end;
2483 mode->vdisplay = timings->crtc_vdisplay;
2484 mode->vtotal = timings->crtc_vtotal;
2485 mode->vsync_start = timings->crtc_vsync_start;
2486 mode->vsync_end = timings->crtc_vsync_end;
2488 mode->flags = timings->flags;
2489 mode->type = DRM_MODE_TYPE_DRIVER;
2491 mode->clock = timings->crtc_clock;
2493 drm_mode_set_name(mode);
2496 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2498 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2500 if (HAS_GMCH(dev_priv))
2501 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2502 crtc_state->pixel_rate =
2503 crtc_state->hw.pipe_mode.crtc_clock;
2505 crtc_state->pixel_rate =
2506 ilk_pipe_pixel_rate(crtc_state);
2509 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2510 struct drm_display_mode *mode)
2512 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2517 mode->crtc_clock /= num_pipes;
2518 mode->crtc_hdisplay /= num_pipes;
2519 mode->crtc_hblank_start /= num_pipes;
2520 mode->crtc_hblank_end /= num_pipes;
2521 mode->crtc_hsync_start /= num_pipes;
2522 mode->crtc_hsync_end /= num_pipes;
2523 mode->crtc_htotal /= num_pipes;
2526 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2527 struct drm_display_mode *mode)
2529 int overlap = crtc_state->splitter.pixel_overlap;
2530 int n = crtc_state->splitter.link_count;
2532 if (!crtc_state->splitter.enable)
2536 * eDP MSO uses segment timings from EDID for transcoder
2537 * timings, but full mode for everything else.
2539 * h_full = (h_segment - pixel_overlap) * link_count
2541 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2542 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2543 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2544 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2545 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2546 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2547 mode->crtc_clock *= n;
2550 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2552 struct drm_display_mode *mode = &crtc_state->hw.mode;
2553 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2554 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2557 * Start with the adjusted_mode crtc timings, which
2558 * have been filled with the transcoder timings.
2560 drm_mode_copy(pipe_mode, adjusted_mode);
2562 /* Expand MSO per-segment transcoder timings to full */
2563 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2566 * We want the full numbers in adjusted_mode normal timings,
2567 * adjusted_mode crtc timings are left with the raw transcoder
2570 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2572 /* Populate the "user" mode with full numbers */
2573 drm_mode_copy(mode, pipe_mode);
2574 intel_mode_from_crtc_timings(mode, mode);
2575 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2576 (intel_bigjoiner_num_pipes(crtc_state) ?: 1);
2577 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2579 /* Derive per-pipe timings in case bigjoiner is used */
2580 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2581 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2583 intel_crtc_compute_pixel_rate(crtc_state);
2586 void intel_encoder_get_config(struct intel_encoder *encoder,
2587 struct intel_crtc_state *crtc_state)
2589 encoder->get_config(encoder, crtc_state);
2591 intel_crtc_readout_derived_state(crtc_state);
2594 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2596 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2602 width = drm_rect_width(&crtc_state->pipe_src);
2603 height = drm_rect_height(&crtc_state->pipe_src);
2605 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2606 width / num_pipes, height);
2609 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2611 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2612 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2614 intel_bigjoiner_compute_pipe_src(crtc_state);
2617 * Pipe horizontal size must be even in:
2619 * - LVDS dual channel mode
2620 * - Double wide pipe
2622 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2623 if (crtc_state->double_wide) {
2624 drm_dbg_kms(&i915->drm,
2625 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2626 crtc->base.base.id, crtc->base.name);
2630 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2631 intel_is_dual_link_lvds(i915)) {
2632 drm_dbg_kms(&i915->drm,
2633 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2634 crtc->base.base.id, crtc->base.name);
2642 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2644 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2645 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2646 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2647 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2648 int clock_limit = i915->max_dotclk_freq;
2651 * Start with the adjusted_mode crtc timings, which
2652 * have been filled with the transcoder timings.
2654 drm_mode_copy(pipe_mode, adjusted_mode);
2656 /* Expand MSO per-segment transcoder timings to full */
2657 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2659 /* Derive per-pipe timings in case bigjoiner is used */
2660 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode);
2661 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2663 if (DISPLAY_VER(i915) < 4) {
2664 clock_limit = i915->max_cdclk_freq * 9 / 10;
2667 * Enable double wide mode when the dot clock
2668 * is > 90% of the (display) core speed.
2670 if (intel_crtc_supports_double_wide(crtc) &&
2671 pipe_mode->crtc_clock > clock_limit) {
2672 clock_limit = i915->max_dotclk_freq;
2673 crtc_state->double_wide = true;
2677 if (pipe_mode->crtc_clock > clock_limit) {
2678 drm_dbg_kms(&i915->drm,
2679 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2680 crtc->base.base.id, crtc->base.name,
2681 pipe_mode->crtc_clock, clock_limit,
2682 str_yes_no(crtc_state->double_wide));
2689 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2690 struct intel_crtc *crtc)
2692 struct intel_crtc_state *crtc_state =
2693 intel_atomic_get_new_crtc_state(state, crtc);
2696 ret = intel_crtc_compute_pipe_src(crtc_state);
2700 ret = intel_crtc_compute_pipe_mode(crtc_state);
2704 intel_crtc_compute_pixel_rate(crtc_state);
2706 if (crtc_state->has_pch_encoder)
2707 return ilk_fdi_compute_config(crtc, crtc_state);
2713 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2715 while (*num > DATA_LINK_M_N_MASK ||
2716 *den > DATA_LINK_M_N_MASK) {
2722 static void compute_m_n(unsigned int m, unsigned int n,
2723 u32 *ret_m, u32 *ret_n,
2727 * Several DP dongles in particular seem to be fussy about
2728 * too large link M/N values. Give N value as 0x8000 that
2729 * should be acceptable by specific devices. 0x8000 is the
2730 * specified fixed N value for asynchronous clock mode,
2731 * which the devices expect also in synchronous clock mode.
2734 *ret_n = DP_LINK_CONSTANT_N_VALUE;
2736 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2738 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2739 intel_reduce_m_n_ratio(ret_m, ret_n);
2743 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
2744 int pixel_clock, int link_clock,
2745 struct intel_link_m_n *m_n,
2746 bool constant_n, bool fec_enable)
2748 u32 data_clock = bits_per_pixel * pixel_clock;
2751 data_clock = intel_dp_mode_to_fec_clock(data_clock);
2754 compute_m_n(data_clock,
2755 link_clock * nlanes * 8,
2756 &m_n->data_m, &m_n->data_n,
2759 compute_m_n(pixel_clock, link_clock,
2760 &m_n->link_m, &m_n->link_n,
2764 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2767 * There may be no VBT; and if the BIOS enabled SSC we can
2768 * just keep using it to avoid unnecessary flicker. Whereas if the
2769 * BIOS isn't using it, don't assume it will work even if the VBT
2770 * indicates as much.
2772 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2773 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2777 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2778 drm_dbg_kms(&dev_priv->drm,
2779 "SSC %s by BIOS, overriding VBT which says %s\n",
2780 str_enabled_disabled(bios_lvds_use_ssc),
2781 str_enabled_disabled(dev_priv->vbt.lvds_use_ssc));
2782 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
2787 void intel_zero_m_n(struct intel_link_m_n *m_n)
2789 /* corresponds to 0 register value */
2790 memset(m_n, 0, sizeof(*m_n));
2794 void intel_set_m_n(struct drm_i915_private *i915,
2795 const struct intel_link_m_n *m_n,
2796 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2797 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2799 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2800 intel_de_write(i915, data_n_reg, m_n->data_n);
2801 intel_de_write(i915, link_m_reg, m_n->link_m);
2803 * On BDW+ writing LINK_N arms the double buffered update
2804 * of all the M/N registers, so it must be written last.
2806 intel_de_write(i915, link_n_reg, m_n->link_n);
2809 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2810 enum transcoder transcoder)
2812 if (IS_HASWELL(dev_priv))
2813 return transcoder == TRANSCODER_EDP;
2815 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2818 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2819 enum transcoder transcoder,
2820 const struct intel_link_m_n *m_n)
2822 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2823 enum pipe pipe = crtc->pipe;
2825 if (DISPLAY_VER(dev_priv) >= 5)
2826 intel_set_m_n(dev_priv, m_n,
2827 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
2828 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
2830 intel_set_m_n(dev_priv, m_n,
2831 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2832 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2835 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2836 enum transcoder transcoder,
2837 const struct intel_link_m_n *m_n)
2839 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2841 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2844 intel_set_m_n(dev_priv, m_n,
2845 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
2846 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
2849 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2851 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2852 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2853 enum pipe pipe = crtc->pipe;
2854 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2855 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2856 u32 crtc_vtotal, crtc_vblank_end;
2859 /* We need to be careful not to changed the adjusted mode, for otherwise
2860 * the hw state checker will get angry at the mismatch. */
2861 crtc_vtotal = adjusted_mode->crtc_vtotal;
2862 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2864 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2865 /* the chip adds 2 halflines automatically */
2867 crtc_vblank_end -= 1;
2869 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2870 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2872 vsyncshift = adjusted_mode->crtc_hsync_start -
2873 adjusted_mode->crtc_htotal / 2;
2875 vsyncshift += adjusted_mode->crtc_htotal;
2878 if (DISPLAY_VER(dev_priv) > 3)
2879 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder),
2882 intel_de_write(dev_priv, HTOTAL(cpu_transcoder),
2883 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16));
2884 intel_de_write(dev_priv, HBLANK(cpu_transcoder),
2885 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16));
2886 intel_de_write(dev_priv, HSYNC(cpu_transcoder),
2887 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16));
2889 intel_de_write(dev_priv, VTOTAL(cpu_transcoder),
2890 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16));
2891 intel_de_write(dev_priv, VBLANK(cpu_transcoder),
2892 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16));
2893 intel_de_write(dev_priv, VSYNC(cpu_transcoder),
2894 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16));
2896 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2897 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2898 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2900 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2901 (pipe == PIPE_B || pipe == PIPE_C))
2902 intel_de_write(dev_priv, VTOTAL(pipe),
2903 intel_de_read(dev_priv, VTOTAL(cpu_transcoder)));
2907 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2909 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2910 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2911 int width = drm_rect_width(&crtc_state->pipe_src);
2912 int height = drm_rect_height(&crtc_state->pipe_src);
2913 enum pipe pipe = crtc->pipe;
2915 /* pipesrc controls the size that is scaled from, which should
2916 * always be the user's requested size.
2918 intel_de_write(dev_priv, PIPESRC(pipe),
2919 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2922 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2924 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2925 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2927 if (DISPLAY_VER(dev_priv) == 2)
2930 if (DISPLAY_VER(dev_priv) >= 9 ||
2931 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2932 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW;
2934 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK;
2937 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2938 struct intel_crtc_state *pipe_config)
2940 struct drm_device *dev = crtc->base.dev;
2941 struct drm_i915_private *dev_priv = to_i915(dev);
2942 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2945 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder));
2946 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
2947 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
2949 if (!transcoder_is_dsi(cpu_transcoder)) {
2950 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder));
2951 pipe_config->hw.adjusted_mode.crtc_hblank_start =
2953 pipe_config->hw.adjusted_mode.crtc_hblank_end =
2954 ((tmp >> 16) & 0xffff) + 1;
2956 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder));
2957 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
2958 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
2960 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder));
2961 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
2962 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
2964 if (!transcoder_is_dsi(cpu_transcoder)) {
2965 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder));
2966 pipe_config->hw.adjusted_mode.crtc_vblank_start =
2968 pipe_config->hw.adjusted_mode.crtc_vblank_end =
2969 ((tmp >> 16) & 0xffff) + 1;
2971 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder));
2972 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
2973 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
2975 if (intel_pipe_is_interlaced(pipe_config)) {
2976 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
2977 pipe_config->hw.adjusted_mode.crtc_vtotal += 1;
2978 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1;
2982 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2984 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2985 int num_pipes = intel_bigjoiner_num_pipes(crtc_state);
2986 enum pipe master_pipe, pipe = crtc->pipe;
2992 master_pipe = bigjoiner_master_pipe(crtc_state);
2993 width = drm_rect_width(&crtc_state->pipe_src);
2995 drm_rect_translate_to(&crtc_state->pipe_src,
2996 (pipe - master_pipe) * width, 0);
2999 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
3000 struct intel_crtc_state *pipe_config)
3002 struct drm_device *dev = crtc->base.dev;
3003 struct drm_i915_private *dev_priv = to_i915(dev);
3006 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe));
3008 drm_rect_init(&pipe_config->pipe_src, 0, 0,
3009 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
3010 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
3012 intel_bigjoiner_adjust_pipe_src(pipe_config);
3015 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
3017 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3018 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3022 * - We keep both pipes enabled on 830
3023 * - During modeset the pipe is still disabled and must remain so
3024 * - During fastset the pipe is already enabled and must remain so
3026 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
3027 pipeconf |= PIPECONF_ENABLE;
3029 if (crtc_state->double_wide)
3030 pipeconf |= PIPECONF_DOUBLE_WIDE;
3032 /* only g4x and later have fancy bpc/dither controls */
3033 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3034 IS_CHERRYVIEW(dev_priv)) {
3035 /* Bspec claims that we can't use dithering for 30bpp pipes. */
3036 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
3037 pipeconf |= PIPECONF_DITHER_EN |
3038 PIPECONF_DITHER_TYPE_SP;
3040 switch (crtc_state->pipe_bpp) {
3042 /* Case prevented by intel_choose_pipe_bpp_dither. */
3043 MISSING_CASE(crtc_state->pipe_bpp);
3046 pipeconf |= PIPECONF_BPC_6;
3049 pipeconf |= PIPECONF_BPC_8;
3052 pipeconf |= PIPECONF_BPC_10;
3057 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
3058 if (DISPLAY_VER(dev_priv) < 4 ||
3059 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3060 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
3062 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
3064 pipeconf |= PIPECONF_INTERLACE_PROGRESSIVE;
3067 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3068 crtc_state->limited_color_range)
3069 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
3071 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
3073 pipeconf |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3075 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf);
3076 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe));
3079 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
3081 if (IS_I830(dev_priv))
3084 return DISPLAY_VER(dev_priv) >= 4 ||
3085 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
3088 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
3090 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3091 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3094 if (!i9xx_has_pfit(dev_priv))
3097 tmp = intel_de_read(dev_priv, PFIT_CONTROL);
3098 if (!(tmp & PFIT_ENABLE))
3101 /* Check whether the pfit is attached to our pipe. */
3102 if (DISPLAY_VER(dev_priv) < 4) {
3103 if (crtc->pipe != PIPE_B)
3106 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
3110 crtc_state->gmch_pfit.control = tmp;
3111 crtc_state->gmch_pfit.pgm_ratios =
3112 intel_de_read(dev_priv, PFIT_PGM_RATIOS);
3115 static void vlv_crtc_clock_get(struct intel_crtc *crtc,
3116 struct intel_crtc_state *pipe_config)
3118 struct drm_device *dev = crtc->base.dev;
3119 struct drm_i915_private *dev_priv = to_i915(dev);
3120 enum pipe pipe = crtc->pipe;
3123 int refclk = 100000;
3125 /* In case of DSI, DPLL will not be used */
3126 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
3129 vlv_dpio_get(dev_priv);
3130 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
3131 vlv_dpio_put(dev_priv);
3133 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
3134 clock.m2 = mdiv & DPIO_M2DIV_MASK;
3135 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
3136 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
3137 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
3139 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
3142 static void chv_crtc_clock_get(struct intel_crtc *crtc,
3143 struct intel_crtc_state *pipe_config)
3145 struct drm_device *dev = crtc->base.dev;
3146 struct drm_i915_private *dev_priv = to_i915(dev);
3147 enum pipe pipe = crtc->pipe;
3148 enum dpio_channel port = vlv_pipe_to_channel(pipe);
3150 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
3151 int refclk = 100000;
3153 /* In case of DSI, DPLL will not be used */
3154 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
3157 vlv_dpio_get(dev_priv);
3158 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
3159 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
3160 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
3161 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
3162 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
3163 vlv_dpio_put(dev_priv);
3165 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
3166 clock.m2 = (pll_dw0 & 0xff) << 22;
3167 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
3168 clock.m2 |= pll_dw2 & 0x3fffff;
3169 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
3170 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
3171 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
3173 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
3176 static enum intel_output_format
3177 bdw_get_pipemisc_output_format(struct intel_crtc *crtc)
3179 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3182 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
3184 if (tmp & PIPEMISC_YUV420_ENABLE) {
3185 /* We support 4:2:0 in full blend mode only */
3186 drm_WARN_ON(&dev_priv->drm,
3187 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0);
3189 return INTEL_OUTPUT_FORMAT_YCBCR420;
3190 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
3191 return INTEL_OUTPUT_FORMAT_YCBCR444;
3193 return INTEL_OUTPUT_FORMAT_RGB;
3197 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state)
3199 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3200 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
3201 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3202 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
3205 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
3207 if (tmp & DISP_PIPE_GAMMA_ENABLE)
3208 crtc_state->gamma_enable = true;
3210 if (!HAS_GMCH(dev_priv) &&
3211 tmp & DISP_PIPE_CSC_ENABLE)
3212 crtc_state->csc_enable = true;
3215 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
3216 struct intel_crtc_state *pipe_config)
3218 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3219 enum intel_display_power_domain power_domain;
3220 intel_wakeref_t wakeref;
3224 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3225 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3229 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3230 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3231 pipe_config->shared_dpll = NULL;
3235 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
3236 if (!(tmp & PIPECONF_ENABLE))
3239 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3240 IS_CHERRYVIEW(dev_priv)) {
3241 switch (tmp & PIPECONF_BPC_MASK) {
3242 case PIPECONF_BPC_6:
3243 pipe_config->pipe_bpp = 18;
3245 case PIPECONF_BPC_8:
3246 pipe_config->pipe_bpp = 24;
3248 case PIPECONF_BPC_10:
3249 pipe_config->pipe_bpp = 30;
3257 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3258 (tmp & PIPECONF_COLOR_RANGE_SELECT))
3259 pipe_config->limited_color_range = true;
3261 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_I9XX, tmp);
3263 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1;
3265 if (IS_CHERRYVIEW(dev_priv))
3266 pipe_config->cgm_mode = intel_de_read(dev_priv,
3267 CGM_PIPE_MODE(crtc->pipe));
3269 i9xx_get_pipe_color_config(pipe_config);
3270 intel_color_get_config(pipe_config);
3272 if (DISPLAY_VER(dev_priv) < 4)
3273 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
3275 intel_get_transcoder_timings(crtc, pipe_config);
3276 intel_get_pipe_src_size(crtc, pipe_config);
3278 i9xx_get_pfit_config(pipe_config);
3280 if (DISPLAY_VER(dev_priv) >= 4) {
3281 /* No way to read it out on pipes B and C */
3282 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
3283 tmp = dev_priv->chv_dpll_md[crtc->pipe];
3285 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe));
3286 pipe_config->pixel_multiplier =
3287 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3288 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3289 pipe_config->dpll_hw_state.dpll_md = tmp;
3290 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
3291 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
3292 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe));
3293 pipe_config->pixel_multiplier =
3294 ((tmp & SDVO_MULTIPLIER_MASK)
3295 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3297 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3298 * port and will be fixed up in the encoder->get_config
3300 pipe_config->pixel_multiplier = 1;
3302 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv,
3304 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
3305 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv,
3307 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv,
3310 /* Mask out read-only status bits. */
3311 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
3312 DPLL_PORTC_READY_MASK |
3313 DPLL_PORTB_READY_MASK);
3316 if (IS_CHERRYVIEW(dev_priv))
3317 chv_crtc_clock_get(crtc, pipe_config);
3318 else if (IS_VALLEYVIEW(dev_priv))
3319 vlv_crtc_clock_get(crtc, pipe_config);
3321 i9xx_crtc_clock_get(crtc, pipe_config);
3324 * Normally the dotclock is filled in by the encoder .get_config()
3325 * but in case the pipe is enabled w/o any ports we need a sane
3328 pipe_config->hw.adjusted_mode.crtc_clock =
3329 pipe_config->port_clock / pipe_config->pixel_multiplier;
3334 intel_display_power_put(dev_priv, power_domain, wakeref);
3339 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3341 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3342 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3343 enum pipe pipe = crtc->pipe;
3347 * - During modeset the pipe is still disabled and must remain so
3348 * - During fastset the pipe is already enabled and must remain so
3350 if (!intel_crtc_needs_modeset(crtc_state))
3351 val |= PIPECONF_ENABLE;
3353 switch (crtc_state->pipe_bpp) {
3355 /* Case prevented by intel_choose_pipe_bpp_dither. */
3356 MISSING_CASE(crtc_state->pipe_bpp);
3359 val |= PIPECONF_BPC_6;
3362 val |= PIPECONF_BPC_8;
3365 val |= PIPECONF_BPC_10;
3368 val |= PIPECONF_BPC_12;
3372 if (crtc_state->dither)
3373 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP;
3375 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3376 val |= PIPECONF_INTERLACE_IF_ID_ILK;
3378 val |= PIPECONF_INTERLACE_PF_PD_ILK;
3381 * This would end up with an odd purple hue over
3382 * the entire display. Make sure we don't do it.
3384 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3385 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3387 if (crtc_state->limited_color_range &&
3388 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3389 val |= PIPECONF_COLOR_RANGE_SELECT;
3391 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3392 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709;
3394 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode);
3396 val |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3397 val |= PIPECONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3399 intel_de_write(dev_priv, PIPECONF(pipe), val);
3400 intel_de_posting_read(dev_priv, PIPECONF(pipe));
3403 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3405 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3406 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3407 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3411 * - During modeset the pipe is still disabled and must remain so
3412 * - During fastset the pipe is already enabled and must remain so
3414 if (!intel_crtc_needs_modeset(crtc_state))
3415 val |= PIPECONF_ENABLE;
3417 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3418 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP;
3420 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3421 val |= PIPECONF_INTERLACE_IF_ID_ILK;
3423 val |= PIPECONF_INTERLACE_PF_PD_ILK;
3425 if (IS_HASWELL(dev_priv) &&
3426 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3427 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW;
3429 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val);
3430 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder));
3433 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state)
3435 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3436 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3439 switch (crtc_state->pipe_bpp) {
3441 val |= PIPEMISC_BPC_6;
3444 val |= PIPEMISC_BPC_8;
3447 val |= PIPEMISC_BPC_10;
3450 /* Port output 12BPC defined for ADLP+ */
3451 if (DISPLAY_VER(dev_priv) > 12)
3452 val |= PIPEMISC_BPC_12_ADLP;
3455 MISSING_CASE(crtc_state->pipe_bpp);
3459 if (crtc_state->dither)
3460 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
3462 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3463 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3464 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
3466 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3467 val |= PIPEMISC_YUV420_ENABLE |
3468 PIPEMISC_YUV420_MODE_FULL_BLEND;
3470 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3471 val |= PIPEMISC_HDR_MODE_PRECISION;
3473 if (DISPLAY_VER(dev_priv) >= 12)
3474 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC;
3476 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val);
3479 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc)
3481 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3484 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe));
3486 switch (tmp & PIPEMISC_BPC_MASK) {
3487 case PIPEMISC_BPC_6:
3489 case PIPEMISC_BPC_8:
3491 case PIPEMISC_BPC_10:
3494 * PORT OUTPUT 12 BPC defined for ADLP+.
3497 * For previous platforms with DSI interface, bits 5:7
3498 * are used for storing pipe_bpp irrespective of dithering.
3499 * Since the value of 12 BPC is not defined for these bits
3500 * on older platforms, need to find a workaround for 12 BPC
3501 * MIPI DSI HW readout.
3503 case PIPEMISC_BPC_12_ADLP:
3504 if (DISPLAY_VER(dev_priv) > 12)
3513 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3516 * Account for spread spectrum to avoid
3517 * oversubscribing the link. Max center spread
3518 * is 2.5%; use 5% for safety's sake.
3520 u32 bps = target_clock * bpp * 21 / 20;
3521 return DIV_ROUND_UP(bps, link_bw * 8);
3524 void intel_get_m_n(struct drm_i915_private *i915,
3525 struct intel_link_m_n *m_n,
3526 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3527 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3529 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3530 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3531 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3532 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3533 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3536 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3537 enum transcoder transcoder,
3538 struct intel_link_m_n *m_n)
3540 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3541 enum pipe pipe = crtc->pipe;
3543 if (DISPLAY_VER(dev_priv) >= 5)
3544 intel_get_m_n(dev_priv, m_n,
3545 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder),
3546 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder));
3548 intel_get_m_n(dev_priv, m_n,
3549 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3550 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3553 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3554 enum transcoder transcoder,
3555 struct intel_link_m_n *m_n)
3557 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3559 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3562 intel_get_m_n(dev_priv, m_n,
3563 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder),
3564 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder));
3567 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state,
3570 drm_rect_init(&crtc_state->pch_pfit.dst,
3571 pos >> 16, pos & 0xffff,
3572 size >> 16, size & 0xffff);
3575 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state)
3577 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3578 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3579 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state;
3583 /* find scaler attached to this pipe */
3584 for (i = 0; i < crtc->num_scalers; i++) {
3587 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i));
3588 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN)
3592 crtc_state->pch_pfit.enabled = true;
3594 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i));
3595 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i));
3597 ilk_get_pfit_pos_size(crtc_state, pos, size);
3599 scaler_state->scalers[i].in_use = true;
3603 scaler_state->scaler_id = id;
3605 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
3607 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
3610 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3612 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3613 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3616 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3617 if ((ctl & PF_ENABLE) == 0)
3620 crtc_state->pch_pfit.enabled = true;
3622 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3623 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3625 ilk_get_pfit_pos_size(crtc_state, pos, size);
3628 * We currently do not free assignements of panel fitters on
3629 * ivb/hsw (since we don't use the higher upscaling modes which
3630 * differentiates them) so just WARN about this case for now.
3632 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 7 &&
3633 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe));
3636 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3637 struct intel_crtc_state *pipe_config)
3639 struct drm_device *dev = crtc->base.dev;
3640 struct drm_i915_private *dev_priv = to_i915(dev);
3641 enum intel_display_power_domain power_domain;
3642 intel_wakeref_t wakeref;
3646 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3647 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3651 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3652 pipe_config->shared_dpll = NULL;
3655 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe));
3656 if (!(tmp & PIPECONF_ENABLE))
3659 switch (tmp & PIPECONF_BPC_MASK) {
3660 case PIPECONF_BPC_6:
3661 pipe_config->pipe_bpp = 18;
3663 case PIPECONF_BPC_8:
3664 pipe_config->pipe_bpp = 24;
3666 case PIPECONF_BPC_10:
3667 pipe_config->pipe_bpp = 30;
3669 case PIPECONF_BPC_12:
3670 pipe_config->pipe_bpp = 36;
3676 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
3677 pipe_config->limited_color_range = true;
3679 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) {
3680 case PIPECONF_OUTPUT_COLORSPACE_YUV601:
3681 case PIPECONF_OUTPUT_COLORSPACE_YUV709:
3682 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3685 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3689 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_ILK, tmp);
3691 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1;
3693 pipe_config->msa_timing_delay = REG_FIELD_GET(PIPECONF_MSA_TIMING_DELAY_MASK, tmp);
3695 pipe_config->csc_mode = intel_de_read(dev_priv,
3696 PIPE_CSC_MODE(crtc->pipe));
3698 i9xx_get_pipe_color_config(pipe_config);
3699 intel_color_get_config(pipe_config);
3701 pipe_config->pixel_multiplier = 1;
3703 ilk_pch_get_config(pipe_config);
3705 intel_get_transcoder_timings(crtc, pipe_config);
3706 intel_get_pipe_src_size(crtc, pipe_config);
3708 ilk_get_pfit_config(pipe_config);
3713 intel_display_power_put(dev_priv, power_domain, wakeref);
3718 static u8 bigjoiner_pipes(struct drm_i915_private *i915)
3720 if (DISPLAY_VER(i915) >= 12)
3721 return BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3722 else if (DISPLAY_VER(i915) >= 11)
3723 return BIT(PIPE_B) | BIT(PIPE_C);
3728 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3729 enum transcoder cpu_transcoder)
3731 enum intel_display_power_domain power_domain;
3732 intel_wakeref_t wakeref;
3735 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3737 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3738 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3740 return tmp & TRANS_DDI_FUNC_ENABLE;
3743 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv,
3744 u8 *master_pipes, u8 *slave_pipes)
3746 struct intel_crtc *crtc;
3751 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc,
3752 bigjoiner_pipes(dev_priv)) {
3753 enum intel_display_power_domain power_domain;
3754 enum pipe pipe = crtc->pipe;
3755 intel_wakeref_t wakeref;
3757 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe);
3758 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3759 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3761 if (!(tmp & BIG_JOINER_ENABLE))
3764 if (tmp & MASTER_BIG_JOINER_ENABLE)
3765 *master_pipes |= BIT(pipe);
3767 *slave_pipes |= BIT(pipe);
3770 if (DISPLAY_VER(dev_priv) < 13)
3773 power_domain = POWER_DOMAIN_PIPE(pipe);
3774 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) {
3775 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe));
3777 if (tmp & UNCOMPRESSED_JOINER_MASTER)
3778 *master_pipes |= BIT(pipe);
3779 if (tmp & UNCOMPRESSED_JOINER_SLAVE)
3780 *slave_pipes |= BIT(pipe);
3784 /* Bigjoiner pipes should always be consecutive master and slave */
3785 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1,
3786 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n",
3787 *master_pipes, *slave_pipes);
3790 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3792 if ((slave_pipes & BIT(pipe)) == 0)
3795 /* ignore everything above our pipe */
3796 master_pipes &= ~GENMASK(7, pipe);
3798 /* highest remaining bit should be our master pipe */
3799 return fls(master_pipes) - 1;
3802 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes)
3804 enum pipe master_pipe, next_master_pipe;
3806 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes);
3808 if ((master_pipes & BIT(master_pipe)) == 0)
3811 /* ignore our master pipe and everything below it */
3812 master_pipes &= ~GENMASK(master_pipe, 0);
3813 /* make sure a high bit is set for the ffs() */
3814 master_pipes |= BIT(7);
3815 /* lowest remaining bit should be the next master pipe */
3816 next_master_pipe = ffs(master_pipes) - 1;
3818 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe);
3821 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3823 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3825 if (DISPLAY_VER(i915) >= 11)
3826 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3828 return panel_transcoder_mask;
3831 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3833 struct drm_device *dev = crtc->base.dev;
3834 struct drm_i915_private *dev_priv = to_i915(dev);
3835 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3836 enum transcoder cpu_transcoder;
3837 u8 master_pipes, slave_pipes;
3838 u8 enabled_transcoders = 0;
3841 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3842 * consistency and less surprising code; it's in always on power).
3844 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3845 panel_transcoder_mask) {
3846 enum intel_display_power_domain power_domain;
3847 intel_wakeref_t wakeref;
3848 enum pipe trans_pipe;
3851 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3852 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3853 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder));
3855 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3858 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3861 "unknown pipe linked to transcoder %s\n",
3862 transcoder_name(cpu_transcoder));
3864 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3865 case TRANS_DDI_EDP_INPUT_A_ON:
3866 trans_pipe = PIPE_A;
3868 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3869 trans_pipe = PIPE_B;
3871 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3872 trans_pipe = PIPE_C;
3874 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3875 trans_pipe = PIPE_D;
3879 if (trans_pipe == crtc->pipe)
3880 enabled_transcoders |= BIT(cpu_transcoder);
3883 /* single pipe or bigjoiner master */
3884 cpu_transcoder = (enum transcoder) crtc->pipe;
3885 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3886 enabled_transcoders |= BIT(cpu_transcoder);
3888 /* bigjoiner slave -> consider the master pipe's transcoder as well */
3889 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes);
3890 if (slave_pipes & BIT(crtc->pipe)) {
3891 cpu_transcoder = (enum transcoder)
3892 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes);
3893 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3894 enabled_transcoders |= BIT(cpu_transcoder);
3897 return enabled_transcoders;
3900 static bool has_edp_transcoders(u8 enabled_transcoders)
3902 return enabled_transcoders & BIT(TRANSCODER_EDP);
3905 static bool has_dsi_transcoders(u8 enabled_transcoders)
3907 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3908 BIT(TRANSCODER_DSI_1));
3911 static bool has_pipe_transcoders(u8 enabled_transcoders)
3913 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3914 BIT(TRANSCODER_DSI_0) |
3915 BIT(TRANSCODER_DSI_1));
3918 static void assert_enabled_transcoders(struct drm_i915_private *i915,
3919 u8 enabled_transcoders)
3921 /* Only one type of transcoder please */
3922 drm_WARN_ON(&i915->drm,
3923 has_edp_transcoders(enabled_transcoders) +
3924 has_dsi_transcoders(enabled_transcoders) +
3925 has_pipe_transcoders(enabled_transcoders) > 1);
3927 /* Only DSI transcoders can be ganged */
3928 drm_WARN_ON(&i915->drm,
3929 !has_dsi_transcoders(enabled_transcoders) &&
3930 !is_power_of_2(enabled_transcoders));
3933 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
3934 struct intel_crtc_state *pipe_config,
3935 struct intel_display_power_domain_set *power_domain_set)
3937 struct drm_device *dev = crtc->base.dev;
3938 struct drm_i915_private *dev_priv = to_i915(dev);
3939 unsigned long enabled_transcoders;
3942 enabled_transcoders = hsw_enabled_transcoders(crtc);
3943 if (!enabled_transcoders)
3946 assert_enabled_transcoders(dev_priv, enabled_transcoders);
3949 * With the exception of DSI we should only ever have
3950 * a single enabled transcoder. With DSI let's just
3951 * pick the first one.
3953 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
3955 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3956 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
3959 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
3960 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
3962 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
3963 pipe_config->pch_pfit.force_thru = true;
3966 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder));
3968 return tmp & PIPECONF_ENABLE;
3971 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
3972 struct intel_crtc_state *pipe_config,
3973 struct intel_display_power_domain_set *power_domain_set)
3975 struct drm_device *dev = crtc->base.dev;
3976 struct drm_i915_private *dev_priv = to_i915(dev);
3977 enum transcoder cpu_transcoder;
3981 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
3983 cpu_transcoder = TRANSCODER_DSI_A;
3985 cpu_transcoder = TRANSCODER_DSI_C;
3987 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
3988 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
3992 * The PLL needs to be enabled with a valid divider
3993 * configuration, otherwise accessing DSI registers will hang
3994 * the machine. See BSpec North Display Engine
3995 * registers/MIPI[BXT]. We can break out here early, since we
3996 * need the same DSI PLL to be enabled for both DSI ports.
3998 if (!bxt_dsi_pll_is_enabled(dev_priv))
4001 /* XXX: this works for video mode only */
4002 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port));
4003 if (!(tmp & DPI_ENABLE))
4006 tmp = intel_de_read(dev_priv, MIPI_CTRL(port));
4007 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
4010 pipe_config->cpu_transcoder = cpu_transcoder;
4014 return transcoder_is_dsi(pipe_config->cpu_transcoder);
4017 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state)
4019 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4020 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4021 u8 master_pipes, slave_pipes;
4022 enum pipe pipe = crtc->pipe;
4024 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes);
4026 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0)
4029 crtc_state->bigjoiner_pipes =
4030 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) |
4031 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes);
4034 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
4035 struct intel_crtc_state *pipe_config)
4037 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4038 struct intel_display_power_domain_set power_domain_set = { };
4042 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
4043 POWER_DOMAIN_PIPE(crtc->pipe)))
4046 pipe_config->shared_dpll = NULL;
4048 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set);
4050 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4051 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) {
4052 drm_WARN_ON(&dev_priv->drm, active);
4059 intel_dsc_get_config(pipe_config);
4060 intel_bigjoiner_get_config(pipe_config);
4062 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
4063 DISPLAY_VER(dev_priv) >= 11)
4064 intel_get_transcoder_timings(crtc, pipe_config);
4066 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
4067 intel_vrr_get_config(crtc, pipe_config);
4069 intel_get_pipe_src_size(crtc, pipe_config);
4071 if (IS_HASWELL(dev_priv)) {
4072 u32 tmp = intel_de_read(dev_priv,
4073 PIPECONF(pipe_config->cpu_transcoder));
4075 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW)
4076 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
4078 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
4080 pipe_config->output_format =
4081 bdw_get_pipemisc_output_format(crtc);
4084 pipe_config->gamma_mode = intel_de_read(dev_priv,
4085 GAMMA_MODE(crtc->pipe));
4087 pipe_config->csc_mode = intel_de_read(dev_priv,
4088 PIPE_CSC_MODE(crtc->pipe));
4090 if (DISPLAY_VER(dev_priv) >= 9) {
4091 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe));
4093 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE)
4094 pipe_config->gamma_enable = true;
4096 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE)
4097 pipe_config->csc_enable = true;
4099 i9xx_get_pipe_color_config(pipe_config);
4102 intel_color_get_config(pipe_config);
4104 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
4105 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
4106 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
4107 pipe_config->ips_linetime =
4108 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
4110 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set,
4111 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
4112 if (DISPLAY_VER(dev_priv) >= 9)
4113 skl_get_pfit_config(pipe_config);
4115 ilk_get_pfit_config(pipe_config);
4118 hsw_ips_get_config(pipe_config);
4120 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
4121 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4122 pipe_config->pixel_multiplier =
4123 intel_de_read(dev_priv,
4124 PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
4126 pipe_config->pixel_multiplier = 1;
4129 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4130 tmp = intel_de_read(dev_priv, CHICKEN_TRANS(pipe_config->cpu_transcoder));
4132 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
4134 /* no idea if this is correct */
4135 pipe_config->framestart_delay = 1;
4139 intel_display_power_put_all_in_set(dev_priv, &power_domain_set);
4144 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
4146 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4147 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4149 if (!i915->display->get_pipe_config(crtc, crtc_state))
4152 crtc_state->hw.active = true;
4154 intel_crtc_readout_derived_state(crtc_state);
4159 /* VESA 640x480x72Hz mode to set on the pipe */
4160 static const struct drm_display_mode load_detect_mode = {
4161 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
4162 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
4165 static int intel_modeset_disable_planes(struct drm_atomic_state *state,
4166 struct drm_crtc *crtc)
4168 struct drm_plane *plane;
4169 struct drm_plane_state *plane_state;
4172 ret = drm_atomic_add_affected_planes(state, crtc);
4176 for_each_new_plane_in_state(state, plane, plane_state, i) {
4177 if (plane_state->crtc != crtc)
4180 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
4184 drm_atomic_set_fb_for_plane(plane_state, NULL);
4190 int intel_get_load_detect_pipe(struct drm_connector *connector,
4191 struct intel_load_detect_pipe *old,
4192 struct drm_modeset_acquire_ctx *ctx)
4194 struct intel_encoder *encoder =
4195 intel_attached_encoder(to_intel_connector(connector));
4196 struct intel_crtc *possible_crtc;
4197 struct intel_crtc *crtc = NULL;
4198 struct drm_device *dev = encoder->base.dev;
4199 struct drm_i915_private *dev_priv = to_i915(dev);
4200 struct drm_mode_config *config = &dev->mode_config;
4201 struct drm_atomic_state *state = NULL, *restore_state = NULL;
4202 struct drm_connector_state *connector_state;
4203 struct intel_crtc_state *crtc_state;
4206 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
4207 connector->base.id, connector->name,
4208 encoder->base.base.id, encoder->base.name);
4210 old->restore_state = NULL;
4212 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex));
4215 * Algorithm gets a little messy:
4217 * - if the connector already has an assigned crtc, use it (but make
4218 * sure it's on first)
4220 * - try to find the first unused crtc that can drive this connector,
4221 * and use that if we find one
4224 /* See if we already have a CRTC for this connector */
4225 if (connector->state->crtc) {
4226 crtc = to_intel_crtc(connector->state->crtc);
4228 ret = drm_modeset_lock(&crtc->base.mutex, ctx);
4232 /* Make sure the crtc and connector are running */
4236 /* Find an unused one (if possible) */
4237 for_each_intel_crtc(dev, possible_crtc) {
4238 if (!(encoder->base.possible_crtcs &
4239 drm_crtc_mask(&possible_crtc->base)))
4242 ret = drm_modeset_lock(&possible_crtc->base.mutex, ctx);
4246 if (possible_crtc->base.state->enable) {
4247 drm_modeset_unlock(&possible_crtc->base.mutex);
4251 crtc = possible_crtc;
4256 * If we didn't find an unused CRTC, don't use any.
4259 drm_dbg_kms(&dev_priv->drm,
4260 "no pipe available for load-detect\n");
4266 state = drm_atomic_state_alloc(dev);
4267 restore_state = drm_atomic_state_alloc(dev);
4268 if (!state || !restore_state) {
4273 state->acquire_ctx = ctx;
4274 restore_state->acquire_ctx = ctx;
4276 connector_state = drm_atomic_get_connector_state(state, connector);
4277 if (IS_ERR(connector_state)) {
4278 ret = PTR_ERR(connector_state);
4282 ret = drm_atomic_set_crtc_for_connector(connector_state, &crtc->base);
4286 crtc_state = intel_atomic_get_crtc_state(state, crtc);
4287 if (IS_ERR(crtc_state)) {
4288 ret = PTR_ERR(crtc_state);
4292 crtc_state->uapi.active = true;
4294 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi,
4299 ret = intel_modeset_disable_planes(state, &crtc->base);
4303 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
4305 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, &crtc->base));
4307 ret = drm_atomic_add_affected_planes(restore_state, &crtc->base);
4309 drm_dbg_kms(&dev_priv->drm,
4310 "Failed to create a copy of old state to restore: %i\n",
4315 ret = drm_atomic_commit(state);
4317 drm_dbg_kms(&dev_priv->drm,
4318 "failed to set mode on load-detect pipe\n");
4322 old->restore_state = restore_state;
4323 drm_atomic_state_put(state);
4325 /* let the connector get through one full cycle before testing */
4326 intel_crtc_wait_for_next_vblank(crtc);
4332 drm_atomic_state_put(state);
4335 if (restore_state) {
4336 drm_atomic_state_put(restore_state);
4337 restore_state = NULL;
4340 if (ret == -EDEADLK)
4346 void intel_release_load_detect_pipe(struct drm_connector *connector,
4347 struct intel_load_detect_pipe *old,
4348 struct drm_modeset_acquire_ctx *ctx)
4350 struct intel_encoder *intel_encoder =
4351 intel_attached_encoder(to_intel_connector(connector));
4352 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev);
4353 struct drm_encoder *encoder = &intel_encoder->base;
4354 struct drm_atomic_state *state = old->restore_state;
4357 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
4358 connector->base.id, connector->name,
4359 encoder->base.id, encoder->name);
4364 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
4366 drm_dbg_kms(&i915->drm,
4367 "Couldn't release load detect pipe: %i\n", ret);
4368 drm_atomic_state_put(state);
4371 static int i9xx_pll_refclk(struct drm_device *dev,
4372 const struct intel_crtc_state *pipe_config)
4374 struct drm_i915_private *dev_priv = to_i915(dev);
4375 u32 dpll = pipe_config->dpll_hw_state.dpll;
4377 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
4378 return dev_priv->vbt.lvds_ssc_freq;
4379 else if (HAS_PCH_SPLIT(dev_priv))
4381 else if (DISPLAY_VER(dev_priv) != 2)
4387 /* Returns the clock of the currently programmed mode of the given pipe. */
4388 void i9xx_crtc_clock_get(struct intel_crtc *crtc,
4389 struct intel_crtc_state *pipe_config)
4391 struct drm_device *dev = crtc->base.dev;
4392 struct drm_i915_private *dev_priv = to_i915(dev);
4393 u32 dpll = pipe_config->dpll_hw_state.dpll;
4397 int refclk = i9xx_pll_refclk(dev, pipe_config);
4399 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
4400 fp = pipe_config->dpll_hw_state.fp0;
4402 fp = pipe_config->dpll_hw_state.fp1;
4404 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
4405 if (IS_PINEVIEW(dev_priv)) {
4406 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
4407 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
4409 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
4410 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
4413 if (DISPLAY_VER(dev_priv) != 2) {
4414 if (IS_PINEVIEW(dev_priv))
4415 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
4416 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
4418 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
4419 DPLL_FPA01_P1_POST_DIV_SHIFT);
4421 switch (dpll & DPLL_MODE_MASK) {
4422 case DPLLB_MODE_DAC_SERIAL:
4423 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
4426 case DPLLB_MODE_LVDS:
4427 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
4431 drm_dbg_kms(&dev_priv->drm,
4432 "Unknown DPLL mode %08x in programmed "
4433 "mode\n", (int)(dpll & DPLL_MODE_MASK));
4437 if (IS_PINEVIEW(dev_priv))
4438 port_clock = pnv_calc_dpll_params(refclk, &clock);
4440 port_clock = i9xx_calc_dpll_params(refclk, &clock);
4442 enum pipe lvds_pipe;
4444 if (IS_I85X(dev_priv) &&
4445 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) &&
4446 lvds_pipe == crtc->pipe) {
4447 u32 lvds = intel_de_read(dev_priv, LVDS);
4449 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
4450 DPLL_FPA01_P1_POST_DIV_SHIFT);
4452 if (lvds & LVDS_CLKB_POWER_UP)
4457 if (dpll & PLL_P1_DIVIDE_BY_TWO)
4460 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
4461 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
4463 if (dpll & PLL_P2_DIVIDE_BY_4)
4469 port_clock = i9xx_calc_dpll_params(refclk, &clock);
4473 * This value includes pixel_multiplier. We will use
4474 * port_clock to compute adjusted_mode.crtc_clock in the
4475 * encoder's get_config() function.
4477 pipe_config->port_clock = port_clock;
4480 int intel_dotclock_calculate(int link_freq,
4481 const struct intel_link_m_n *m_n)
4484 * The calculation for the data clock is:
4485 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
4486 * But we want to avoid losing precison if possible, so:
4487 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
4489 * and the link clock is simpler:
4490 * link_clock = (m * link_clock) / n
4496 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
4499 /* Returns the currently programmed mode of the given encoder. */
4500 struct drm_display_mode *
4501 intel_encoder_current_mode(struct intel_encoder *encoder)
4503 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
4504 struct intel_crtc_state *crtc_state;
4505 struct drm_display_mode *mode;
4506 struct intel_crtc *crtc;
4509 if (!encoder->get_hw_state(encoder, &pipe))
4512 crtc = intel_crtc_for_pipe(dev_priv, pipe);
4514 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
4518 crtc_state = intel_crtc_state_alloc(crtc);
4524 if (!intel_crtc_get_pipe_config(crtc_state)) {
4530 intel_encoder_get_config(encoder, crtc_state);
4532 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4539 static bool encoders_cloneable(const struct intel_encoder *a,
4540 const struct intel_encoder *b)
4542 /* masks could be asymmetric, so check both ways */
4543 return a == b || (a->cloneable & (1 << b->type) &&
4544 b->cloneable & (1 << a->type));
4547 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4548 struct intel_crtc *crtc,
4549 struct intel_encoder *encoder)
4551 struct intel_encoder *source_encoder;
4552 struct drm_connector *connector;
4553 struct drm_connector_state *connector_state;
4556 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4557 if (connector_state->crtc != &crtc->base)
4561 to_intel_encoder(connector_state->best_encoder);
4562 if (!encoders_cloneable(encoder, source_encoder))
4569 static int icl_add_linked_planes(struct intel_atomic_state *state)
4571 struct intel_plane *plane, *linked;
4572 struct intel_plane_state *plane_state, *linked_plane_state;
4575 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4576 linked = plane_state->planar_linked_plane;
4581 linked_plane_state = intel_atomic_get_plane_state(state, linked);
4582 if (IS_ERR(linked_plane_state))
4583 return PTR_ERR(linked_plane_state);
4585 drm_WARN_ON(state->base.dev,
4586 linked_plane_state->planar_linked_plane != plane);
4587 drm_WARN_ON(state->base.dev,
4588 linked_plane_state->planar_slave == plane_state->planar_slave);
4594 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
4596 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4597 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4598 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state);
4599 struct intel_plane *plane, *linked;
4600 struct intel_plane_state *plane_state;
4603 if (DISPLAY_VER(dev_priv) < 11)
4607 * Destroy all old plane links and make the slave plane invisible
4608 * in the crtc_state->active_planes mask.
4610 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4611 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
4614 plane_state->planar_linked_plane = NULL;
4615 if (plane_state->planar_slave && !plane_state->uapi.visible) {
4616 crtc_state->enabled_planes &= ~BIT(plane->id);
4617 crtc_state->active_planes &= ~BIT(plane->id);
4618 crtc_state->update_planes |= BIT(plane->id);
4619 crtc_state->data_rate[plane->id] = 0;
4620 crtc_state->rel_data_rate[plane->id] = 0;
4623 plane_state->planar_slave = false;
4626 if (!crtc_state->nv12_planes)
4629 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4630 struct intel_plane_state *linked_state = NULL;
4632 if (plane->pipe != crtc->pipe ||
4633 !(crtc_state->nv12_planes & BIT(plane->id)))
4636 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4637 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4640 if (crtc_state->active_planes & BIT(linked->id))
4643 linked_state = intel_atomic_get_plane_state(state, linked);
4644 if (IS_ERR(linked_state))
4645 return PTR_ERR(linked_state);
4650 if (!linked_state) {
4651 drm_dbg_kms(&dev_priv->drm,
4652 "Need %d free Y planes for planar YUV\n",
4653 hweight8(crtc_state->nv12_planes));
4658 plane_state->planar_linked_plane = linked;
4660 linked_state->planar_slave = true;
4661 linked_state->planar_linked_plane = plane;
4662 crtc_state->enabled_planes |= BIT(linked->id);
4663 crtc_state->active_planes |= BIT(linked->id);
4664 crtc_state->update_planes |= BIT(linked->id);
4665 crtc_state->data_rate[linked->id] =
4666 crtc_state->data_rate_y[plane->id];
4667 crtc_state->rel_data_rate[linked->id] =
4668 crtc_state->rel_data_rate_y[plane->id];
4669 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4670 linked->base.name, plane->base.name);
4672 /* Copy parameters to slave plane */
4673 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4674 linked_state->color_ctl = plane_state->color_ctl;
4675 linked_state->view = plane_state->view;
4676 linked_state->decrypt = plane_state->decrypt;
4678 intel_plane_copy_hw_state(linked_state, plane_state);
4679 linked_state->uapi.src = plane_state->uapi.src;
4680 linked_state->uapi.dst = plane_state->uapi.dst;
4682 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4683 if (linked->id == PLANE_SPRITE5)
4684 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4685 else if (linked->id == PLANE_SPRITE4)
4686 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4687 else if (linked->id == PLANE_SPRITE3)
4688 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4689 else if (linked->id == PLANE_SPRITE2)
4690 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4692 MISSING_CASE(linked->id);
4699 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state)
4701 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
4702 struct intel_atomic_state *state =
4703 to_intel_atomic_state(new_crtc_state->uapi.state);
4704 const struct intel_crtc_state *old_crtc_state =
4705 intel_atomic_get_old_crtc_state(state, crtc);
4707 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes;
4710 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4712 const struct drm_display_mode *pipe_mode =
4713 &crtc_state->hw.pipe_mode;
4716 if (!crtc_state->hw.enable)
4719 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4720 pipe_mode->crtc_clock);
4722 return min(linetime_wm, 0x1ff);
4725 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4726 const struct intel_cdclk_state *cdclk_state)
4728 const struct drm_display_mode *pipe_mode =
4729 &crtc_state->hw.pipe_mode;
4732 if (!crtc_state->hw.enable)
4735 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4736 cdclk_state->logical.cdclk);
4738 return min(linetime_wm, 0x1ff);
4741 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4743 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4744 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4745 const struct drm_display_mode *pipe_mode =
4746 &crtc_state->hw.pipe_mode;
4749 if (!crtc_state->hw.enable)
4752 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4753 crtc_state->pixel_rate);
4755 /* Display WA #1135: BXT:ALL GLK:ALL */
4756 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4757 dev_priv->ipc_enabled)
4760 return min(linetime_wm, 0x1ff);
4763 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4764 struct intel_crtc *crtc)
4766 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4767 struct intel_crtc_state *crtc_state =
4768 intel_atomic_get_new_crtc_state(state, crtc);
4769 const struct intel_cdclk_state *cdclk_state;
4771 if (DISPLAY_VER(dev_priv) >= 9)
4772 crtc_state->linetime = skl_linetime_wm(crtc_state);
4774 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4776 if (!hsw_crtc_supports_ips(crtc))
4779 cdclk_state = intel_atomic_get_cdclk_state(state);
4780 if (IS_ERR(cdclk_state))
4781 return PTR_ERR(cdclk_state);
4783 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4789 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4790 struct intel_crtc *crtc)
4792 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4793 struct intel_crtc_state *crtc_state =
4794 intel_atomic_get_new_crtc_state(state, crtc);
4795 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
4798 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4799 mode_changed && !crtc_state->hw.active)
4800 crtc_state->update_wm_post = true;
4803 ret = intel_dpll_crtc_compute_clock(state, crtc);
4807 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4813 * May need to update pipe gamma enable bits
4814 * when C8 planes are getting enabled/disabled.
4816 if (c8_planes_changed(crtc_state))
4817 crtc_state->uapi.color_mgmt_changed = true;
4819 if (mode_changed || crtc_state->update_pipe ||
4820 crtc_state->uapi.color_mgmt_changed) {
4821 ret = intel_color_check(crtc_state);
4826 ret = intel_compute_pipe_wm(state, crtc);
4828 drm_dbg_kms(&dev_priv->drm,
4829 "Target pipe watermarks are invalid\n");
4834 * Calculate 'intermediate' watermarks that satisfy both the
4835 * old state and the new state. We can program these
4838 ret = intel_compute_intermediate_wm(state, crtc);
4840 drm_dbg_kms(&dev_priv->drm,
4841 "No valid intermediate pipe watermarks are possible\n");
4845 if (DISPLAY_VER(dev_priv) >= 9) {
4846 if (mode_changed || crtc_state->update_pipe) {
4847 ret = skl_update_scaler_crtc(crtc_state);
4852 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state);
4857 if (HAS_IPS(dev_priv)) {
4858 ret = hsw_ips_compute_config(state, crtc);
4863 if (DISPLAY_VER(dev_priv) >= 9 ||
4864 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4865 ret = hsw_compute_linetime_wm(state, crtc);
4871 ret = intel_psr2_sel_fetch_update(state, crtc);
4879 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4880 struct intel_crtc_state *crtc_state)
4882 struct drm_connector *connector = conn_state->connector;
4883 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4884 const struct drm_display_info *info = &connector->display_info;
4887 switch (conn_state->max_bpc) {
4901 MISSING_CASE(conn_state->max_bpc);
4905 if (bpp < crtc_state->pipe_bpp) {
4906 drm_dbg_kms(&i915->drm,
4907 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4908 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4909 connector->base.id, connector->name,
4911 3 * conn_state->max_requested_bpc,
4912 crtc_state->pipe_bpp);
4914 crtc_state->pipe_bpp = bpp;
4921 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4922 struct intel_crtc *crtc)
4924 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4925 struct intel_crtc_state *crtc_state =
4926 intel_atomic_get_new_crtc_state(state, crtc);
4927 struct drm_connector *connector;
4928 struct drm_connector_state *connector_state;
4931 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4932 IS_CHERRYVIEW(dev_priv)))
4934 else if (DISPLAY_VER(dev_priv) >= 5)
4939 crtc_state->pipe_bpp = bpp;
4941 /* Clamp display bpp to connector max bpp */
4942 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4945 if (connector_state->crtc != &crtc->base)
4948 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4956 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4958 struct drm_device *dev = state->base.dev;
4959 struct drm_connector *connector;
4960 struct drm_connector_list_iter conn_iter;
4961 unsigned int used_ports = 0;
4962 unsigned int used_mst_ports = 0;
4966 * We're going to peek into connector->state,
4967 * hence connection_mutex must be held.
4969 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4972 * Walk the connector list instead of the encoder
4973 * list to detect the problem on ddi platforms
4974 * where there's just one encoder per digital port.
4976 drm_connector_list_iter_begin(dev, &conn_iter);
4977 drm_for_each_connector_iter(connector, &conn_iter) {
4978 struct drm_connector_state *connector_state;
4979 struct intel_encoder *encoder;
4982 drm_atomic_get_new_connector_state(&state->base,
4984 if (!connector_state)
4985 connector_state = connector->state;
4987 if (!connector_state->best_encoder)
4990 encoder = to_intel_encoder(connector_state->best_encoder);
4992 drm_WARN_ON(dev, !connector_state->crtc);
4994 switch (encoder->type) {
4995 case INTEL_OUTPUT_DDI:
4996 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4999 case INTEL_OUTPUT_DP:
5000 case INTEL_OUTPUT_HDMI:
5001 case INTEL_OUTPUT_EDP:
5002 /* the same port mustn't appear more than once */
5003 if (used_ports & BIT(encoder->port))
5006 used_ports |= BIT(encoder->port);
5008 case INTEL_OUTPUT_DP_MST:
5016 drm_connector_list_iter_end(&conn_iter);
5018 /* can't mix MST and SST/HDMI on the same port */
5019 if (used_ports & used_mst_ports)
5026 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
5027 struct intel_crtc *crtc)
5029 struct intel_crtc_state *crtc_state =
5030 intel_atomic_get_new_crtc_state(state, crtc);
5032 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
5034 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
5035 crtc_state->uapi.degamma_lut);
5036 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
5037 crtc_state->uapi.gamma_lut);
5038 drm_property_replace_blob(&crtc_state->hw.ctm,
5039 crtc_state->uapi.ctm);
5043 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
5044 struct intel_crtc *crtc)
5046 struct intel_crtc_state *crtc_state =
5047 intel_atomic_get_new_crtc_state(state, crtc);
5049 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state));
5051 crtc_state->hw.enable = crtc_state->uapi.enable;
5052 crtc_state->hw.active = crtc_state->uapi.active;
5053 drm_mode_copy(&crtc_state->hw.mode,
5054 &crtc_state->uapi.mode);
5055 drm_mode_copy(&crtc_state->hw.adjusted_mode,
5056 &crtc_state->uapi.adjusted_mode);
5057 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
5059 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
5063 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state,
5064 struct intel_crtc *slave_crtc)
5066 struct intel_crtc_state *slave_crtc_state =
5067 intel_atomic_get_new_crtc_state(state, slave_crtc);
5068 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
5069 const struct intel_crtc_state *master_crtc_state =
5070 intel_atomic_get_new_crtc_state(state, master_crtc);
5072 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut,
5073 master_crtc_state->hw.degamma_lut);
5074 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut,
5075 master_crtc_state->hw.gamma_lut);
5076 drm_property_replace_blob(&slave_crtc_state->hw.ctm,
5077 master_crtc_state->hw.ctm);
5079 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed;
5083 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state,
5084 struct intel_crtc *slave_crtc)
5086 struct intel_crtc_state *slave_crtc_state =
5087 intel_atomic_get_new_crtc_state(state, slave_crtc);
5088 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state);
5089 const struct intel_crtc_state *master_crtc_state =
5090 intel_atomic_get_new_crtc_state(state, master_crtc);
5091 struct intel_crtc_state *saved_state;
5093 WARN_ON(master_crtc_state->bigjoiner_pipes !=
5094 slave_crtc_state->bigjoiner_pipes);
5096 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL);
5100 /* preserve some things from the slave's original crtc state */
5101 saved_state->uapi = slave_crtc_state->uapi;
5102 saved_state->scaler_state = slave_crtc_state->scaler_state;
5103 saved_state->shared_dpll = slave_crtc_state->shared_dpll;
5104 saved_state->dpll_hw_state = slave_crtc_state->dpll_hw_state;
5105 saved_state->crc_enabled = slave_crtc_state->crc_enabled;
5107 intel_crtc_free_hw_state(slave_crtc_state);
5108 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state));
5111 /* Re-init hw state */
5112 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw));
5113 slave_crtc_state->hw.enable = master_crtc_state->hw.enable;
5114 slave_crtc_state->hw.active = master_crtc_state->hw.active;
5115 drm_mode_copy(&slave_crtc_state->hw.mode,
5116 &master_crtc_state->hw.mode);
5117 drm_mode_copy(&slave_crtc_state->hw.pipe_mode,
5118 &master_crtc_state->hw.pipe_mode);
5119 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode,
5120 &master_crtc_state->hw.adjusted_mode);
5121 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter;
5123 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc);
5125 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed;
5126 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed;
5127 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed;
5129 WARN_ON(master_crtc_state->bigjoiner_pipes !=
5130 slave_crtc_state->bigjoiner_pipes);
5136 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
5137 struct intel_crtc *crtc)
5139 struct intel_crtc_state *crtc_state =
5140 intel_atomic_get_new_crtc_state(state, crtc);
5141 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5142 struct intel_crtc_state *saved_state;
5144 saved_state = intel_crtc_state_alloc(crtc);
5148 /* free the old crtc_state->hw members */
5149 intel_crtc_free_hw_state(crtc_state);
5151 /* FIXME: before the switch to atomic started, a new pipe_config was
5152 * kzalloc'd. Code that depends on any field being zero should be
5153 * fixed, so that the crtc_state can be safely duplicated. For now,
5154 * only fields that are know to not cause problems are preserved. */
5156 saved_state->uapi = crtc_state->uapi;
5157 saved_state->scaler_state = crtc_state->scaler_state;
5158 saved_state->shared_dpll = crtc_state->shared_dpll;
5159 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
5160 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
5161 sizeof(saved_state->icl_port_dplls));
5162 saved_state->crc_enabled = crtc_state->crc_enabled;
5163 if (IS_G4X(dev_priv) ||
5164 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5165 saved_state->wm = crtc_state->wm;
5167 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
5170 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
5176 intel_modeset_pipe_config(struct intel_atomic_state *state,
5177 struct intel_crtc *crtc)
5179 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5180 struct intel_crtc_state *crtc_state =
5181 intel_atomic_get_new_crtc_state(state, crtc);
5182 struct drm_connector *connector;
5183 struct drm_connector_state *connector_state;
5184 int pipe_src_w, pipe_src_h;
5185 int base_bpp, ret, i;
5188 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
5190 crtc_state->framestart_delay = 1;
5193 * Sanitize sync polarity flags based on requested ones. If neither
5194 * positive or negative polarity is requested, treat this as meaning
5195 * negative polarity.
5197 if (!(crtc_state->hw.adjusted_mode.flags &
5198 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
5199 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
5201 if (!(crtc_state->hw.adjusted_mode.flags &
5202 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
5203 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
5205 ret = compute_baseline_pipe_bpp(state, crtc);
5209 base_bpp = crtc_state->pipe_bpp;
5212 * Determine the real pipe dimensions. Note that stereo modes can
5213 * increase the actual pipe size due to the frame doubling and
5214 * insertion of additional space for blanks between the frame. This
5215 * is stored in the crtc timings. We use the requested mode to do this
5216 * computation to clearly distinguish it from the adjusted mode, which
5217 * can be changed by the connectors in the below retry loop.
5219 drm_mode_get_hv_timing(&crtc_state->hw.mode,
5220 &pipe_src_w, &pipe_src_h);
5221 drm_rect_init(&crtc_state->pipe_src, 0, 0,
5222 pipe_src_w, pipe_src_h);
5224 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5225 struct intel_encoder *encoder =
5226 to_intel_encoder(connector_state->best_encoder);
5228 if (connector_state->crtc != &crtc->base)
5231 if (!check_single_encoder_cloning(state, crtc, encoder)) {
5232 drm_dbg_kms(&i915->drm,
5233 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
5234 encoder->base.base.id, encoder->base.name);
5239 * Determine output_types before calling the .compute_config()
5240 * hooks so that the hooks can use this information safely.
5242 if (encoder->compute_output_type)
5243 crtc_state->output_types |=
5244 BIT(encoder->compute_output_type(encoder, crtc_state,
5247 crtc_state->output_types |= BIT(encoder->type);
5251 /* Ensure the port clock defaults are reset when retrying. */
5252 crtc_state->port_clock = 0;
5253 crtc_state->pixel_multiplier = 1;
5255 /* Fill in default crtc timings, allow encoders to overwrite them. */
5256 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
5257 CRTC_STEREO_DOUBLE);
5259 /* Pass our mode to the connectors and the CRTC to give them a chance to
5260 * adjust it according to limitations or connector properties, and also
5261 * a chance to reject the mode entirely.
5263 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5264 struct intel_encoder *encoder =
5265 to_intel_encoder(connector_state->best_encoder);
5267 if (connector_state->crtc != &crtc->base)
5270 ret = encoder->compute_config(encoder, crtc_state,
5272 if (ret == -EDEADLK)
5275 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
5276 encoder->base.base.id, encoder->base.name, ret);
5281 /* Set default port clock if not overwritten by the encoder. Needs to be
5282 * done afterwards in case the encoder adjusts the mode. */
5283 if (!crtc_state->port_clock)
5284 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
5285 * crtc_state->pixel_multiplier;
5287 ret = intel_crtc_compute_config(state, crtc);
5288 if (ret == -EDEADLK)
5290 if (ret == -EAGAIN) {
5291 if (drm_WARN(&i915->drm, !retry,
5292 "[CRTC:%d:%s] loop in pipe configuration computation\n",
5293 crtc->base.base.id, crtc->base.name))
5296 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] bw constrained, retrying\n",
5297 crtc->base.base.id, crtc->base.name);
5302 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
5303 crtc->base.base.id, crtc->base.name, ret);
5307 /* Dithering seems to not pass-through bits correctly when it should, so
5308 * only enable it on 6bpc panels and when its not a compliance
5309 * test requesting 6bpc video pattern.
5311 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
5312 !crtc_state->dither_force_disable;
5313 drm_dbg_kms(&i915->drm,
5314 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
5315 crtc->base.base.id, crtc->base.name,
5316 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
5322 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
5323 struct intel_crtc *crtc)
5325 struct intel_crtc_state *crtc_state =
5326 intel_atomic_get_new_crtc_state(state, crtc);
5327 struct drm_connector_state *conn_state;
5328 struct drm_connector *connector;
5331 intel_bigjoiner_adjust_pipe_src(crtc_state);
5333 for_each_new_connector_in_state(&state->base, connector,
5335 struct intel_encoder *encoder =
5336 to_intel_encoder(conn_state->best_encoder);
5339 if (conn_state->crtc != &crtc->base ||
5340 !encoder->compute_config_late)
5343 ret = encoder->compute_config_late(encoder, crtc_state,
5352 bool intel_fuzzy_clock_check(int clock1, int clock2)
5356 if (clock1 == clock2)
5359 if (!clock1 || !clock2)
5362 diff = abs(clock1 - clock2);
5364 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
5371 intel_compare_m_n(unsigned int m, unsigned int n,
5372 unsigned int m2, unsigned int n2,
5375 if (m == m2 && n == n2)
5378 if (exact || !m || !n || !m2 || !n2)
5381 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
5388 } else if (n < n2) {
5398 return intel_fuzzy_clock_check(m, m2);
5402 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
5403 const struct intel_link_m_n *m2_n2,
5406 return m_n->tu == m2_n2->tu &&
5407 intel_compare_m_n(m_n->data_m, m_n->data_n,
5408 m2_n2->data_m, m2_n2->data_n, exact) &&
5409 intel_compare_m_n(m_n->link_m, m_n->link_n,
5410 m2_n2->link_m, m2_n2->link_n, exact);
5414 intel_compare_infoframe(const union hdmi_infoframe *a,
5415 const union hdmi_infoframe *b)
5417 return memcmp(a, b, sizeof(*a)) == 0;
5421 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
5422 const struct drm_dp_vsc_sdp *b)
5424 return memcmp(a, b, sizeof(*a)) == 0;
5428 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv,
5429 bool fastset, const char *name,
5430 const union hdmi_infoframe *a,
5431 const union hdmi_infoframe *b)
5434 if (!drm_debug_enabled(DRM_UT_KMS))
5437 drm_dbg_kms(&dev_priv->drm,
5438 "fastset mismatch in %s infoframe\n", name);
5439 drm_dbg_kms(&dev_priv->drm, "expected:\n");
5440 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a);
5441 drm_dbg_kms(&dev_priv->drm, "found:\n");
5442 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b);
5444 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name);
5445 drm_err(&dev_priv->drm, "expected:\n");
5446 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a);
5447 drm_err(&dev_priv->drm, "found:\n");
5448 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b);
5453 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv,
5454 bool fastset, const char *name,
5455 const struct drm_dp_vsc_sdp *a,
5456 const struct drm_dp_vsc_sdp *b)
5459 if (!drm_debug_enabled(DRM_UT_KMS))
5462 drm_dbg_kms(&dev_priv->drm,
5463 "fastset mismatch in %s dp sdp\n", name);
5464 drm_dbg_kms(&dev_priv->drm, "expected:\n");
5465 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a);
5466 drm_dbg_kms(&dev_priv->drm, "found:\n");
5467 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b);
5469 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name);
5470 drm_err(&dev_priv->drm, "expected:\n");
5471 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a);
5472 drm_err(&dev_priv->drm, "found:\n");
5473 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b);
5477 static void __printf(4, 5)
5478 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc,
5479 const char *name, const char *format, ...)
5481 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5482 struct va_format vaf;
5485 va_start(args, format);
5490 drm_dbg_kms(&i915->drm,
5491 "[CRTC:%d:%s] fastset mismatch in %s %pV\n",
5492 crtc->base.base.id, crtc->base.name, name, &vaf);
5494 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n",
5495 crtc->base.base.id, crtc->base.name, name, &vaf);
5500 static bool fastboot_enabled(struct drm_i915_private *dev_priv)
5502 if (dev_priv->params.fastboot != -1)
5503 return dev_priv->params.fastboot;
5505 /* Enable fastboot by default on Skylake and newer */
5506 if (DISPLAY_VER(dev_priv) >= 9)
5509 /* Enable fastboot by default on VLV and CHV */
5510 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5513 /* Disabled by default on all others */
5518 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
5519 const struct intel_crtc_state *pipe_config,
5522 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
5523 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
5526 bool fixup_inherited = fastset &&
5527 current_config->inherited && !pipe_config->inherited;
5529 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
5530 drm_dbg_kms(&dev_priv->drm,
5531 "initial modeset and fastboot not set\n");
5535 #define PIPE_CONF_CHECK_X(name) do { \
5536 if (current_config->name != pipe_config->name) { \
5537 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5538 "(expected 0x%08x, found 0x%08x)", \
5539 current_config->name, \
5540 pipe_config->name); \
5545 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5546 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5547 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5548 "(expected 0x%08x, found 0x%08x)", \
5549 current_config->name & (mask), \
5550 pipe_config->name & (mask)); \
5555 #define PIPE_CONF_CHECK_I(name) do { \
5556 if (current_config->name != pipe_config->name) { \
5557 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5558 "(expected %i, found %i)", \
5559 current_config->name, \
5560 pipe_config->name); \
5565 #define PIPE_CONF_CHECK_BOOL(name) do { \
5566 if (current_config->name != pipe_config->name) { \
5567 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5568 "(expected %s, found %s)", \
5569 str_yes_no(current_config->name), \
5570 str_yes_no(pipe_config->name)); \
5576 * Checks state where we only read out the enabling, but not the entire
5577 * state itself (like full infoframes or ELD for audio). These states
5578 * require a full modeset on bootup to fix up.
5580 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
5581 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
5582 PIPE_CONF_CHECK_BOOL(name); \
5584 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5585 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \
5586 str_yes_no(current_config->name), \
5587 str_yes_no(pipe_config->name)); \
5592 #define PIPE_CONF_CHECK_P(name) do { \
5593 if (current_config->name != pipe_config->name) { \
5594 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5595 "(expected %p, found %p)", \
5596 current_config->name, \
5597 pipe_config->name); \
5602 #define PIPE_CONF_CHECK_M_N(name) do { \
5603 if (!intel_compare_link_m_n(¤t_config->name, \
5604 &pipe_config->name,\
5606 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5607 "(expected tu %i data %i/%i link %i/%i, " \
5608 "found tu %i, data %i/%i link %i/%i)", \
5609 current_config->name.tu, \
5610 current_config->name.data_m, \
5611 current_config->name.data_n, \
5612 current_config->name.link_m, \
5613 current_config->name.link_n, \
5614 pipe_config->name.tu, \
5615 pipe_config->name.data_m, \
5616 pipe_config->name.data_n, \
5617 pipe_config->name.link_m, \
5618 pipe_config->name.link_n); \
5623 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5624 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5625 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5626 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5627 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5628 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5629 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5630 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5631 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5632 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5633 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5634 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5635 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5638 #define PIPE_CONF_CHECK_RECT(name) do { \
5639 PIPE_CONF_CHECK_I(name.x1); \
5640 PIPE_CONF_CHECK_I(name.x2); \
5641 PIPE_CONF_CHECK_I(name.y1); \
5642 PIPE_CONF_CHECK_I(name.y2); \
5645 /* This is required for BDW+ where there is only one set of registers for
5646 * switching between high and low RR.
5647 * This macro can be used whenever a comparison has to be made between one
5648 * hw state and multiple sw state variables.
5650 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
5651 if (!intel_compare_link_m_n(¤t_config->name, \
5652 &pipe_config->name, !fastset) && \
5653 !intel_compare_link_m_n(¤t_config->alt_name, \
5654 &pipe_config->name, !fastset)) { \
5655 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5656 "(expected tu %i data %i/%i link %i/%i, " \
5657 "or tu %i data %i/%i link %i/%i, " \
5658 "found tu %i, data %i/%i link %i/%i)", \
5659 current_config->name.tu, \
5660 current_config->name.data_m, \
5661 current_config->name.data_n, \
5662 current_config->name.link_m, \
5663 current_config->name.link_n, \
5664 current_config->alt_name.tu, \
5665 current_config->alt_name.data_m, \
5666 current_config->alt_name.data_n, \
5667 current_config->alt_name.link_m, \
5668 current_config->alt_name.link_n, \
5669 pipe_config->name.tu, \
5670 pipe_config->name.data_m, \
5671 pipe_config->name.data_n, \
5672 pipe_config->name.link_m, \
5673 pipe_config->name.link_n); \
5678 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5679 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5680 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5681 "(%x) (expected %i, found %i)", \
5683 current_config->name & (mask), \
5684 pipe_config->name & (mask)); \
5689 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
5690 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
5691 pipe_config_mismatch(fastset, crtc, __stringify(name), \
5692 "(expected %i, found %i)", \
5693 current_config->name, \
5694 pipe_config->name); \
5699 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5700 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5701 &pipe_config->infoframes.name)) { \
5702 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \
5703 ¤t_config->infoframes.name, \
5704 &pipe_config->infoframes.name); \
5709 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5710 if (!current_config->has_psr && !pipe_config->has_psr && \
5711 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5712 &pipe_config->infoframes.name)) { \
5713 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \
5714 ¤t_config->infoframes.name, \
5715 &pipe_config->infoframes.name); \
5720 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \
5721 if (current_config->name1 != pipe_config->name1) { \
5722 pipe_config_mismatch(fastset, crtc, __stringify(name1), \
5723 "(expected %i, found %i, won't compare lut values)", \
5724 current_config->name1, \
5725 pipe_config->name1); \
5728 if (!intel_color_lut_equal(current_config->name2, \
5729 pipe_config->name2, pipe_config->name1, \
5731 pipe_config_mismatch(fastset, crtc, __stringify(name2), \
5732 "hw_state doesn't match sw_state"); \
5738 #define PIPE_CONF_QUIRK(quirk) \
5739 ((current_config->quirks | pipe_config->quirks) & (quirk))
5741 PIPE_CONF_CHECK_I(hw.enable);
5742 PIPE_CONF_CHECK_I(hw.active);
5744 PIPE_CONF_CHECK_I(cpu_transcoder);
5745 PIPE_CONF_CHECK_I(mst_master_transcoder);
5747 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5748 PIPE_CONF_CHECK_I(fdi_lanes);
5749 PIPE_CONF_CHECK_M_N(fdi_m_n);
5751 PIPE_CONF_CHECK_I(lane_count);
5752 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5754 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) {
5755 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
5757 PIPE_CONF_CHECK_M_N(dp_m_n);
5758 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5761 PIPE_CONF_CHECK_X(output_types);
5763 PIPE_CONF_CHECK_I(framestart_delay);
5764 PIPE_CONF_CHECK_I(msa_timing_delay);
5766 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5767 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5769 PIPE_CONF_CHECK_I(pixel_multiplier);
5771 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5772 DRM_MODE_FLAG_INTERLACE);
5774 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5775 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5776 DRM_MODE_FLAG_PHSYNC);
5777 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5778 DRM_MODE_FLAG_NHSYNC);
5779 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5780 DRM_MODE_FLAG_PVSYNC);
5781 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5782 DRM_MODE_FLAG_NVSYNC);
5785 PIPE_CONF_CHECK_I(output_format);
5786 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5787 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5788 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5789 PIPE_CONF_CHECK_BOOL(limited_color_range);
5791 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5792 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5793 PIPE_CONF_CHECK_BOOL(has_infoframe);
5794 PIPE_CONF_CHECK_BOOL(fec_enable);
5796 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
5798 PIPE_CONF_CHECK_X(gmch_pfit.control);
5799 /* pfit ratios are autocomputed by the hw on gen4+ */
5800 if (DISPLAY_VER(dev_priv) < 4)
5801 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5802 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5805 * Changing the EDP transcoder input mux
5806 * (A_ONOFF vs. A_ON) requires a full modeset.
5808 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5811 PIPE_CONF_CHECK_RECT(pipe_src);
5813 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5814 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5816 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5817 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
5819 PIPE_CONF_CHECK_X(gamma_mode);
5820 if (IS_CHERRYVIEW(dev_priv))
5821 PIPE_CONF_CHECK_X(cgm_mode);
5823 PIPE_CONF_CHECK_X(csc_mode);
5824 PIPE_CONF_CHECK_BOOL(gamma_enable);
5825 PIPE_CONF_CHECK_BOOL(csc_enable);
5827 PIPE_CONF_CHECK_I(linetime);
5828 PIPE_CONF_CHECK_I(ips_linetime);
5830 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config);
5832 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma);
5834 if (current_config->active_planes) {
5835 PIPE_CONF_CHECK_BOOL(has_psr);
5836 PIPE_CONF_CHECK_BOOL(has_psr2);
5837 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5838 PIPE_CONF_CHECK_I(dc3co_exitline);
5842 PIPE_CONF_CHECK_BOOL(double_wide);
5844 if (dev_priv->dpll.mgr) {
5845 PIPE_CONF_CHECK_P(shared_dpll);
5847 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
5848 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
5849 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
5850 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
5851 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
5852 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
5853 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
5854 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
5855 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
5856 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
5857 PIPE_CONF_CHECK_X(dpll_hw_state.div0);
5858 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
5859 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
5860 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
5861 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
5862 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
5863 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
5864 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
5865 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
5866 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
5867 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
5868 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
5869 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
5870 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
5871 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
5872 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
5873 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
5874 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
5875 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
5876 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
5877 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
5878 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
5881 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5882 PIPE_CONF_CHECK_X(dsi_pll.div);
5884 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5885 PIPE_CONF_CHECK_I(pipe_bpp);
5887 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock);
5888 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock);
5889 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
5891 PIPE_CONF_CHECK_I(min_voltage_level);
5893 if (current_config->has_psr || pipe_config->has_psr)
5894 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5895 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5897 PIPE_CONF_CHECK_X(infoframes.enable);
5899 PIPE_CONF_CHECK_X(infoframes.gcp);
5900 PIPE_CONF_CHECK_INFOFRAME(avi);
5901 PIPE_CONF_CHECK_INFOFRAME(spd);
5902 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5903 PIPE_CONF_CHECK_INFOFRAME(drm);
5904 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5906 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5907 PIPE_CONF_CHECK_I(master_transcoder);
5908 PIPE_CONF_CHECK_X(bigjoiner_pipes);
5910 PIPE_CONF_CHECK_I(dsc.compression_enable);
5911 PIPE_CONF_CHECK_I(dsc.dsc_split);
5912 PIPE_CONF_CHECK_I(dsc.compressed_bpp);
5914 PIPE_CONF_CHECK_BOOL(splitter.enable);
5915 PIPE_CONF_CHECK_I(splitter.link_count);
5916 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5918 PIPE_CONF_CHECK_BOOL(vrr.enable);
5919 PIPE_CONF_CHECK_I(vrr.vmin);
5920 PIPE_CONF_CHECK_I(vrr.vmax);
5921 PIPE_CONF_CHECK_I(vrr.flipline);
5922 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5923 PIPE_CONF_CHECK_I(vrr.guardband);
5925 #undef PIPE_CONF_CHECK_X
5926 #undef PIPE_CONF_CHECK_I
5927 #undef PIPE_CONF_CHECK_BOOL
5928 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
5929 #undef PIPE_CONF_CHECK_P
5930 #undef PIPE_CONF_CHECK_FLAGS
5931 #undef PIPE_CONF_CHECK_CLOCK_FUZZY
5932 #undef PIPE_CONF_CHECK_COLOR_LUT
5933 #undef PIPE_CONF_CHECK_TIMINGS
5934 #undef PIPE_CONF_CHECK_RECT
5935 #undef PIPE_CONF_QUIRK
5941 intel_verify_planes(struct intel_atomic_state *state)
5943 struct intel_plane *plane;
5944 const struct intel_plane_state *plane_state;
5947 for_each_new_intel_plane_in_state(state, plane,
5949 assert_plane(plane, plane_state->planar_slave ||
5950 plane_state->uapi.visible);
5953 int intel_modeset_all_pipes(struct intel_atomic_state *state)
5955 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5956 struct intel_crtc *crtc;
5959 * Add all pipes to the state, and force
5960 * a modeset on all the active ones.
5962 for_each_intel_crtc(&dev_priv->drm, crtc) {
5963 struct intel_crtc_state *crtc_state;
5966 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5967 if (IS_ERR(crtc_state))
5968 return PTR_ERR(crtc_state);
5970 if (!crtc_state->hw.active ||
5971 drm_atomic_crtc_needs_modeset(&crtc_state->uapi))
5974 crtc_state->uapi.mode_changed = true;
5976 ret = drm_atomic_add_affected_connectors(&state->base,
5981 ret = intel_atomic_add_affected_planes(state, crtc);
5985 crtc_state->update_planes |= crtc_state->active_planes;
5991 void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state)
5993 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5994 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5995 struct drm_display_mode adjusted_mode;
5997 drm_mode_init(&adjusted_mode, &crtc_state->hw.adjusted_mode);
5999 if (crtc_state->vrr.enable) {
6000 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax;
6001 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax;
6002 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state);
6003 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state);
6006 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode);
6008 crtc->mode_flags = crtc_state->mode_flags;
6011 * The scanline counter increments at the leading edge of hsync.
6013 * On most platforms it starts counting from vtotal-1 on the
6014 * first active line. That means the scanline counter value is
6015 * always one less than what we would expect. Ie. just after
6016 * start of vblank, which also occurs at start of hsync (on the
6017 * last active line), the scanline counter will read vblank_start-1.
6019 * On gen2 the scanline counter starts counting from 1 instead
6020 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
6021 * to keep the value positive), instead of adding one.
6023 * On HSW+ the behaviour of the scanline counter depends on the output
6024 * type. For DP ports it behaves like most other platforms, but on HDMI
6025 * there's an extra 1 line difference. So we need to add two instead of
6028 * On VLV/CHV DSI the scanline counter would appear to increment
6029 * approx. 1/3 of a scanline before start of vblank. Unfortunately
6030 * that means we can't tell whether we're in vblank or not while
6031 * we're on that particular line. We must still set scanline_offset
6032 * to 1 so that the vblank timestamps come out correct when we query
6033 * the scanline counter from within the vblank interrupt handler.
6034 * However if queried just before the start of vblank we'll get an
6035 * answer that's slightly in the future.
6037 if (DISPLAY_VER(dev_priv) == 2) {
6040 vtotal = adjusted_mode.crtc_vtotal;
6041 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
6044 crtc->scanline_offset = vtotal - 1;
6045 } else if (HAS_DDI(dev_priv) &&
6046 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
6047 crtc->scanline_offset = 2;
6049 crtc->scanline_offset = 1;
6053 static void intel_modeset_clear_plls(struct intel_atomic_state *state)
6055 struct intel_crtc_state *new_crtc_state;
6056 struct intel_crtc *crtc;
6059 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6060 if (!intel_crtc_needs_modeset(new_crtc_state))
6063 intel_release_shared_dplls(state, crtc);
6068 * This implements the workaround described in the "notes" section of the mode
6069 * set sequence documentation. When going from no pipes or single pipe to
6070 * multiple pipes, and planes are enabled after the pipe, we need to wait at
6071 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
6073 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
6075 struct intel_crtc_state *crtc_state;
6076 struct intel_crtc *crtc;
6077 struct intel_crtc_state *first_crtc_state = NULL;
6078 struct intel_crtc_state *other_crtc_state = NULL;
6079 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
6082 /* look at all crtc's that are going to be enabled in during modeset */
6083 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6084 if (!crtc_state->hw.active ||
6085 !intel_crtc_needs_modeset(crtc_state))
6088 if (first_crtc_state) {
6089 other_crtc_state = crtc_state;
6092 first_crtc_state = crtc_state;
6093 first_pipe = crtc->pipe;
6097 /* No workaround needed? */
6098 if (!first_crtc_state)
6101 /* w/a possibly needed, check how many crtc's are already enabled. */
6102 for_each_intel_crtc(state->base.dev, crtc) {
6103 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6104 if (IS_ERR(crtc_state))
6105 return PTR_ERR(crtc_state);
6107 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
6109 if (!crtc_state->hw.active ||
6110 intel_crtc_needs_modeset(crtc_state))
6113 /* 2 or more enabled crtcs means no need for w/a */
6114 if (enabled_pipe != INVALID_PIPE)
6117 enabled_pipe = crtc->pipe;
6120 if (enabled_pipe != INVALID_PIPE)
6121 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
6122 else if (other_crtc_state)
6123 other_crtc_state->hsw_workaround_pipe = first_pipe;
6128 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
6131 const struct intel_crtc_state *crtc_state;
6132 struct intel_crtc *crtc;
6135 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6136 if (crtc_state->hw.active)
6137 active_pipes |= BIT(crtc->pipe);
6139 active_pipes &= ~BIT(crtc->pipe);
6142 return active_pipes;
6145 static int intel_modeset_checks(struct intel_atomic_state *state)
6147 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6149 state->modeset = true;
6151 if (IS_HASWELL(dev_priv))
6152 return hsw_mode_set_planes_workaround(state);
6157 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
6158 struct intel_crtc_state *new_crtc_state)
6160 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
6163 new_crtc_state->uapi.mode_changed = false;
6164 new_crtc_state->update_pipe = true;
6167 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state,
6168 struct intel_crtc_state *new_crtc_state)
6171 * If we're not doing the full modeset we want to
6172 * keep the current M/N values as they may be
6173 * sufficiently different to the computed values
6174 * to cause problems.
6176 * FIXME: should really copy more fuzzy state here
6178 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n;
6179 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n;
6180 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2;
6181 new_crtc_state->has_drrs = old_crtc_state->has_drrs;
6184 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
6185 struct intel_crtc *crtc,
6188 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6189 struct intel_plane *plane;
6191 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6192 struct intel_plane_state *plane_state;
6194 if ((plane_ids_mask & BIT(plane->id)) == 0)
6197 plane_state = intel_atomic_get_plane_state(state, plane);
6198 if (IS_ERR(plane_state))
6199 return PTR_ERR(plane_state);
6205 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
6206 struct intel_crtc *crtc)
6208 const struct intel_crtc_state *old_crtc_state =
6209 intel_atomic_get_old_crtc_state(state, crtc);
6210 const struct intel_crtc_state *new_crtc_state =
6211 intel_atomic_get_new_crtc_state(state, crtc);
6213 return intel_crtc_add_planes_to_state(state, crtc,
6214 old_crtc_state->enabled_planes |
6215 new_crtc_state->enabled_planes);
6218 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
6220 /* See {hsw,vlv,ivb}_plane_ratio() */
6221 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
6222 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
6223 IS_IVYBRIDGE(dev_priv);
6226 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state,
6227 struct intel_crtc *crtc,
6228 struct intel_crtc *other)
6230 const struct intel_plane_state *plane_state;
6231 struct intel_plane *plane;
6235 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6236 if (plane->pipe == crtc->pipe)
6237 plane_ids |= BIT(plane->id);
6240 return intel_crtc_add_planes_to_state(state, other, plane_ids);
6243 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state)
6245 struct drm_i915_private *i915 = to_i915(state->base.dev);
6246 const struct intel_crtc_state *crtc_state;
6247 struct intel_crtc *crtc;
6250 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6251 struct intel_crtc *other;
6253 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
6254 crtc_state->bigjoiner_pipes) {
6260 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other);
6269 static int intel_atomic_check_planes(struct intel_atomic_state *state)
6271 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6272 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6273 struct intel_plane_state *plane_state;
6274 struct intel_plane *plane;
6275 struct intel_crtc *crtc;
6278 ret = icl_add_linked_planes(state);
6282 ret = intel_bigjoiner_add_affected_planes(state);
6286 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6287 ret = intel_plane_atomic_check(state, plane);
6289 drm_dbg_atomic(&dev_priv->drm,
6290 "[PLANE:%d:%s] atomic driver check failed\n",
6291 plane->base.base.id, plane->base.name);
6296 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6297 new_crtc_state, i) {
6298 u8 old_active_planes, new_active_planes;
6300 ret = icl_check_nv12_planes(new_crtc_state);
6305 * On some platforms the number of active planes affects
6306 * the planes' minimum cdclk calculation. Add such planes
6307 * to the state before we compute the minimum cdclk.
6309 if (!active_planes_affects_min_cdclk(dev_priv))
6312 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6313 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6315 if (hweight8(old_active_planes) == hweight8(new_active_planes))
6318 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
6326 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
6328 struct intel_crtc_state *crtc_state;
6329 struct intel_crtc *crtc;
6332 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6333 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6336 ret = intel_crtc_atomic_check(state, crtc);
6338 drm_dbg_atomic(&i915->drm,
6339 "[CRTC:%d:%s] atomic driver check failed\n",
6340 crtc->base.base.id, crtc->base.name);
6348 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
6351 const struct intel_crtc_state *new_crtc_state;
6352 struct intel_crtc *crtc;
6355 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6356 if (new_crtc_state->hw.enable &&
6357 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
6358 intel_crtc_needs_modeset(new_crtc_state))
6365 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
6368 const struct intel_crtc_state *new_crtc_state;
6369 struct intel_crtc *crtc;
6372 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6373 if (new_crtc_state->hw.enable &&
6374 pipes & BIT(crtc->pipe) &&
6375 intel_crtc_needs_modeset(new_crtc_state))
6382 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state,
6383 struct intel_crtc *master_crtc)
6385 struct drm_i915_private *i915 = to_i915(state->base.dev);
6386 struct intel_crtc_state *master_crtc_state =
6387 intel_atomic_get_new_crtc_state(state, master_crtc);
6388 struct intel_crtc *slave_crtc;
6390 if (!master_crtc_state->bigjoiner_pipes)
6394 if (drm_WARN_ON(&i915->drm,
6395 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state)))
6398 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) {
6399 drm_dbg_kms(&i915->drm,
6400 "[CRTC:%d:%s] Cannot act as big joiner master "
6401 "(need 0x%x as pipes, only 0x%x possible)\n",
6402 master_crtc->base.base.id, master_crtc->base.name,
6403 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915));
6407 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
6408 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
6409 struct intel_crtc_state *slave_crtc_state;
6412 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc);
6413 if (IS_ERR(slave_crtc_state))
6414 return PTR_ERR(slave_crtc_state);
6416 /* master being enabled, slave was already configured? */
6417 if (slave_crtc_state->uapi.enable) {
6418 drm_dbg_kms(&i915->drm,
6419 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but "
6420 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n",
6421 slave_crtc->base.base.id, slave_crtc->base.name,
6422 master_crtc->base.base.id, master_crtc->base.name);
6427 * The state copy logic assumes the master crtc gets processed
6428 * before the slave crtc during the main compute_config loop.
6429 * This works because the crtcs are created in pipe order,
6430 * and the hardware requires master pipe < slave pipe as well.
6431 * Should that change we need to rethink the logic.
6433 if (WARN_ON(drm_crtc_index(&master_crtc->base) >
6434 drm_crtc_index(&slave_crtc->base)))
6437 drm_dbg_kms(&i915->drm,
6438 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n",
6439 slave_crtc->base.base.id, slave_crtc->base.name,
6440 master_crtc->base.base.id, master_crtc->base.name);
6442 slave_crtc_state->bigjoiner_pipes =
6443 master_crtc_state->bigjoiner_pipes;
6445 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc);
6453 static void kill_bigjoiner_slave(struct intel_atomic_state *state,
6454 struct intel_crtc *master_crtc)
6456 struct drm_i915_private *i915 = to_i915(state->base.dev);
6457 struct intel_crtc_state *master_crtc_state =
6458 intel_atomic_get_new_crtc_state(state, master_crtc);
6459 struct intel_crtc *slave_crtc;
6461 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc,
6462 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) {
6463 struct intel_crtc_state *slave_crtc_state =
6464 intel_atomic_get_new_crtc_state(state, slave_crtc);
6466 slave_crtc_state->bigjoiner_pipes = 0;
6468 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc);
6471 master_crtc_state->bigjoiner_pipes = 0;
6475 * DOC: asynchronous flip implementation
6477 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
6478 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
6479 * Correspondingly, support is currently added for primary plane only.
6481 * Async flip can only change the plane surface address, so anything else
6482 * changing is rejected from the intel_async_flip_check_hw() function.
6483 * Once this check is cleared, flip done interrupt is enabled using
6484 * the intel_crtc_enable_flip_done() function.
6486 * As soon as the surface address register is written, flip done interrupt is
6487 * generated and the requested events are sent to the usersapce in the interrupt
6488 * handler itself. The timestamp and sequence sent during the flip done event
6489 * correspond to the last vblank and have no relation to the actual time when
6490 * the flip done event was sent.
6492 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
6493 struct intel_crtc *crtc)
6495 struct drm_i915_private *i915 = to_i915(state->base.dev);
6496 const struct intel_crtc_state *new_crtc_state =
6497 intel_atomic_get_new_crtc_state(state, crtc);
6498 const struct intel_plane_state *old_plane_state;
6499 struct intel_plane_state *new_plane_state;
6500 struct intel_plane *plane;
6503 if (!new_crtc_state->uapi.async_flip)
6506 if (!new_crtc_state->uapi.active) {
6507 drm_dbg_kms(&i915->drm,
6508 "[CRTC:%d:%s] not active\n",
6509 crtc->base.base.id, crtc->base.name);
6513 if (intel_crtc_needs_modeset(new_crtc_state)) {
6514 drm_dbg_kms(&i915->drm,
6515 "[CRTC:%d:%s] modeset required\n",
6516 crtc->base.base.id, crtc->base.name);
6520 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6521 new_plane_state, i) {
6522 if (plane->pipe != crtc->pipe)
6526 * TODO: Async flip is only supported through the page flip IOCTL
6527 * as of now. So support currently added for primary plane only.
6528 * Support for other planes on platforms on which supports
6529 * this(vlv/chv and icl+) should be added when async flip is
6530 * enabled in the atomic IOCTL path.
6532 if (!plane->async_flip) {
6533 drm_dbg_kms(&i915->drm,
6534 "[PLANE:%d:%s] async flip not supported\n",
6535 plane->base.base.id, plane->base.name);
6539 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
6540 drm_dbg_kms(&i915->drm,
6541 "[PLANE:%d:%s] no old or new framebuffer\n",
6542 plane->base.base.id, plane->base.name);
6550 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
6552 struct drm_i915_private *i915 = to_i915(state->base.dev);
6553 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6554 const struct intel_plane_state *new_plane_state, *old_plane_state;
6555 struct intel_plane *plane;
6558 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
6559 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6561 if (!new_crtc_state->uapi.async_flip)
6564 if (!new_crtc_state->hw.active) {
6565 drm_dbg_kms(&i915->drm,
6566 "[CRTC:%d:%s] not active\n",
6567 crtc->base.base.id, crtc->base.name);
6571 if (intel_crtc_needs_modeset(new_crtc_state)) {
6572 drm_dbg_kms(&i915->drm,
6573 "[CRTC:%d:%s] modeset required\n",
6574 crtc->base.base.id, crtc->base.name);
6578 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6579 drm_dbg_kms(&i915->drm,
6580 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6581 crtc->base.base.id, crtc->base.name);
6585 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6586 new_plane_state, i) {
6587 if (plane->pipe != crtc->pipe)
6591 * Only async flip capable planes should be in the state
6592 * if we're really about to ask the hardware to perform
6593 * an async flip. We should never get this far otherwise.
6595 if (drm_WARN_ON(&i915->drm,
6596 new_crtc_state->do_async_flip && !plane->async_flip))
6600 * Only check async flip capable planes other planes
6601 * may be involved in the initial commit due to
6602 * the wm0/ddb optimization.
6604 * TODO maybe should track which planes actually
6605 * were requested to do the async flip...
6607 if (!plane->async_flip)
6611 * FIXME: This check is kept generic for all platforms.
6612 * Need to verify this for all gen9 platforms to enable
6613 * this selectively if required.
6615 switch (new_plane_state->hw.fb->modifier) {
6616 case I915_FORMAT_MOD_X_TILED:
6617 case I915_FORMAT_MOD_Y_TILED:
6618 case I915_FORMAT_MOD_Yf_TILED:
6619 case I915_FORMAT_MOD_4_TILED:
6622 drm_dbg_kms(&i915->drm,
6623 "[PLANE:%d:%s] Modifier does not support async flips\n",
6624 plane->base.base.id, plane->base.name);
6628 if (new_plane_state->hw.fb->format->num_planes > 1) {
6629 drm_dbg_kms(&i915->drm,
6630 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6631 plane->base.base.id, plane->base.name);
6635 if (old_plane_state->view.color_plane[0].mapping_stride !=
6636 new_plane_state->view.color_plane[0].mapping_stride) {
6637 drm_dbg_kms(&i915->drm,
6638 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6639 plane->base.base.id, plane->base.name);
6643 if (old_plane_state->hw.fb->modifier !=
6644 new_plane_state->hw.fb->modifier) {
6645 drm_dbg_kms(&i915->drm,
6646 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6647 plane->base.base.id, plane->base.name);
6651 if (old_plane_state->hw.fb->format !=
6652 new_plane_state->hw.fb->format) {
6653 drm_dbg_kms(&i915->drm,
6654 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6655 plane->base.base.id, plane->base.name);
6659 if (old_plane_state->hw.rotation !=
6660 new_plane_state->hw.rotation) {
6661 drm_dbg_kms(&i915->drm,
6662 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6663 plane->base.base.id, plane->base.name);
6667 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6668 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6669 drm_dbg_kms(&i915->drm,
6670 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6671 plane->base.base.id, plane->base.name);
6675 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6676 drm_dbg_kms(&i915->drm,
6677 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6678 plane->base.base.id, plane->base.name);
6682 if (old_plane_state->hw.pixel_blend_mode !=
6683 new_plane_state->hw.pixel_blend_mode) {
6684 drm_dbg_kms(&i915->drm,
6685 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6686 plane->base.base.id, plane->base.name);
6690 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6691 drm_dbg_kms(&i915->drm,
6692 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6693 plane->base.base.id, plane->base.name);
6697 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6698 drm_dbg_kms(&i915->drm,
6699 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6700 plane->base.base.id, plane->base.name);
6704 /* plane decryption is allow to change only in synchronous flips */
6705 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6706 drm_dbg_kms(&i915->drm,
6707 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6708 plane->base.base.id, plane->base.name);
6716 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state)
6718 struct drm_i915_private *i915 = to_i915(state->base.dev);
6719 struct intel_crtc_state *crtc_state;
6720 struct intel_crtc *crtc;
6721 u8 affected_pipes = 0;
6722 u8 modeset_pipes = 0;
6725 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6726 affected_pipes |= crtc_state->bigjoiner_pipes;
6727 if (intel_crtc_needs_modeset(crtc_state))
6728 modeset_pipes |= crtc_state->bigjoiner_pipes;
6731 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6732 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6733 if (IS_ERR(crtc_state))
6734 return PTR_ERR(crtc_state);
6737 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6740 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6742 crtc_state->uapi.mode_changed = true;
6744 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6748 ret = intel_atomic_add_affected_planes(state, crtc);
6753 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6754 /* Kill old bigjoiner link, we may re-establish afterwards */
6755 if (intel_crtc_needs_modeset(crtc_state) &&
6756 intel_crtc_is_bigjoiner_master(crtc_state))
6757 kill_bigjoiner_slave(state, crtc);
6764 * intel_atomic_check - validate state object
6766 * @_state: state to validate
6768 static int intel_atomic_check(struct drm_device *dev,
6769 struct drm_atomic_state *_state)
6771 struct drm_i915_private *dev_priv = to_i915(dev);
6772 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6773 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6774 struct intel_crtc *crtc;
6776 bool any_ms = false;
6778 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6779 new_crtc_state, i) {
6780 if (new_crtc_state->inherited != old_crtc_state->inherited)
6781 new_crtc_state->uapi.mode_changed = true;
6783 if (new_crtc_state->uapi.scaling_filter !=
6784 old_crtc_state->uapi.scaling_filter)
6785 new_crtc_state->uapi.mode_changed = true;
6788 intel_vrr_check_modeset(state);
6790 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6794 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6795 ret = intel_async_flip_check_uapi(state, crtc);
6800 ret = intel_bigjoiner_add_affected_crtcs(state);
6804 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6805 new_crtc_state, i) {
6806 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6807 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
6808 copy_bigjoiner_crtc_state_nomodeset(state, crtc);
6810 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6814 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) {
6815 drm_WARN_ON(&dev_priv->drm, new_crtc_state->uapi.enable);
6819 ret = intel_crtc_prepare_cleared_state(state, crtc);
6823 if (!new_crtc_state->hw.enable)
6826 ret = intel_modeset_pipe_config(state, crtc);
6830 ret = intel_atomic_check_bigjoiner(state, crtc);
6835 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6836 new_crtc_state, i) {
6837 if (!intel_crtc_needs_modeset(new_crtc_state))
6840 ret = intel_modeset_pipe_config_late(state, crtc);
6844 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6848 * Check if fastset is allowed by external dependencies like other
6849 * pipes and transcoders.
6851 * Right now it only forces a fullmodeset when the MST master
6852 * transcoder did not changed but the pipe of the master transcoder
6853 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6854 * in case of port synced crtcs, if one of the synced crtcs
6855 * needs a full modeset, all other synced crtcs should be
6856 * forced a full modeset.
6858 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6859 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6862 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6863 enum transcoder master = new_crtc_state->mst_master_transcoder;
6865 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) {
6866 new_crtc_state->uapi.mode_changed = true;
6867 new_crtc_state->update_pipe = false;
6871 if (is_trans_port_sync_mode(new_crtc_state)) {
6872 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6874 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6875 trans |= BIT(new_crtc_state->master_transcoder);
6877 if (intel_cpu_transcoders_need_modeset(state, trans)) {
6878 new_crtc_state->uapi.mode_changed = true;
6879 new_crtc_state->update_pipe = false;
6883 if (new_crtc_state->bigjoiner_pipes) {
6884 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes)) {
6885 new_crtc_state->uapi.mode_changed = true;
6886 new_crtc_state->update_pipe = false;
6891 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6892 new_crtc_state, i) {
6893 if (intel_crtc_needs_modeset(new_crtc_state)) {
6898 if (!new_crtc_state->update_pipe)
6901 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state);
6904 if (any_ms && !check_digital_port_conflicts(state)) {
6905 drm_dbg_kms(&dev_priv->drm,
6906 "rejecting conflicting digital port configuration\n");
6911 ret = drm_dp_mst_atomic_check(&state->base);
6915 ret = intel_atomic_check_planes(state);
6919 ret = intel_compute_global_watermarks(state);
6923 ret = intel_bw_atomic_check(state);
6927 ret = intel_cdclk_atomic_check(state, &any_ms);
6931 if (intel_any_crtc_needs_modeset(state))
6935 ret = intel_modeset_checks(state);
6939 ret = intel_modeset_calc_cdclk(state);
6943 intel_modeset_clear_plls(state);
6946 ret = intel_atomic_check_crtcs(state);
6950 ret = intel_fbc_atomic_check(state);
6954 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6955 new_crtc_state, i) {
6956 ret = intel_async_flip_check_hw(state, crtc);
6960 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6961 !new_crtc_state->update_pipe)
6964 intel_crtc_state_dump(new_crtc_state, state,
6965 intel_crtc_needs_modeset(new_crtc_state) ?
6966 "modeset" : "fastset");
6972 if (ret == -EDEADLK)
6976 * FIXME would probably be nice to know which crtc specifically
6977 * caused the failure, in cases where we can pinpoint it.
6979 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6981 intel_crtc_state_dump(new_crtc_state, state, "failed");
6986 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
6988 struct intel_crtc_state *crtc_state;
6989 struct intel_crtc *crtc;
6992 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
6996 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6997 bool mode_changed = intel_crtc_needs_modeset(crtc_state);
6999 if (mode_changed || crtc_state->update_pipe ||
7000 crtc_state->uapi.color_mgmt_changed) {
7001 intel_dsb_prepare(crtc_state);
7008 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
7009 struct intel_crtc_state *crtc_state)
7011 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7013 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
7014 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7016 if (crtc_state->has_pch_encoder) {
7017 enum pipe pch_transcoder =
7018 intel_crtc_pch_transcoder(crtc);
7020 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
7024 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
7025 const struct intel_crtc_state *new_crtc_state)
7027 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
7028 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7031 * Update pipe size and adjust fitter if needed: the reason for this is
7032 * that in compute_mode_changes we check the native mode (not the pfit
7033 * mode) to see if we can flip rather than do a full mode set. In the
7034 * fastboot case, we'll flip, but if we don't update the pipesrc and
7035 * pfit state, we'll end up with a big fb scanned out into the wrong
7038 intel_set_pipe_src_size(new_crtc_state);
7040 /* on skylake this is done by detaching scalers */
7041 if (DISPLAY_VER(dev_priv) >= 9) {
7042 if (new_crtc_state->pch_pfit.enabled)
7043 skl_pfit_enable(new_crtc_state);
7044 } else if (HAS_PCH_SPLIT(dev_priv)) {
7045 if (new_crtc_state->pch_pfit.enabled)
7046 ilk_pfit_enable(new_crtc_state);
7047 else if (old_crtc_state->pch_pfit.enabled)
7048 ilk_pfit_disable(old_crtc_state);
7052 * The register is supposedly single buffered so perhaps
7053 * not 100% correct to do this here. But SKL+ calculate
7054 * this based on the adjust pixel rate so pfit changes do
7055 * affect it and so it must be updated for fastsets.
7056 * HSW/BDW only really need this here for fastboot, after
7057 * that the value should not change without a full modeset.
7059 if (DISPLAY_VER(dev_priv) >= 9 ||
7060 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
7061 hsw_set_linetime_wm(new_crtc_state);
7064 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
7065 struct intel_crtc *crtc)
7067 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7068 const struct intel_crtc_state *old_crtc_state =
7069 intel_atomic_get_old_crtc_state(state, crtc);
7070 const struct intel_crtc_state *new_crtc_state =
7071 intel_atomic_get_new_crtc_state(state, crtc);
7072 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7075 * During modesets pipe configuration was programmed as the
7079 if (new_crtc_state->uapi.color_mgmt_changed ||
7080 new_crtc_state->update_pipe)
7081 intel_color_commit_arm(new_crtc_state);
7083 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
7084 bdw_set_pipemisc(new_crtc_state);
7086 if (new_crtc_state->update_pipe)
7087 intel_pipe_fastset(old_crtc_state, new_crtc_state);
7090 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
7092 intel_atomic_update_watermarks(state, crtc);
7095 static void commit_pipe_post_planes(struct intel_atomic_state *state,
7096 struct intel_crtc *crtc)
7098 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7099 const struct intel_crtc_state *new_crtc_state =
7100 intel_atomic_get_new_crtc_state(state, crtc);
7103 * Disable the scaler(s) after the plane(s) so that we don't
7104 * get a catastrophic underrun even if the two operations
7105 * end up happening in two different frames.
7107 if (DISPLAY_VER(dev_priv) >= 9 &&
7108 !intel_crtc_needs_modeset(new_crtc_state))
7109 skl_detach_scalers(new_crtc_state);
7112 static void intel_enable_crtc(struct intel_atomic_state *state,
7113 struct intel_crtc *crtc)
7115 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7116 const struct intel_crtc_state *new_crtc_state =
7117 intel_atomic_get_new_crtc_state(state, crtc);
7119 if (!intel_crtc_needs_modeset(new_crtc_state))
7122 intel_crtc_update_active_timings(new_crtc_state);
7124 dev_priv->display->crtc_enable(state, crtc);
7126 if (intel_crtc_is_bigjoiner_slave(new_crtc_state))
7129 /* vblanks work again, re-enable pipe CRC. */
7130 intel_crtc_enable_pipe_crc(crtc);
7133 static void intel_update_crtc(struct intel_atomic_state *state,
7134 struct intel_crtc *crtc)
7136 struct drm_i915_private *i915 = to_i915(state->base.dev);
7137 const struct intel_crtc_state *old_crtc_state =
7138 intel_atomic_get_old_crtc_state(state, crtc);
7139 struct intel_crtc_state *new_crtc_state =
7140 intel_atomic_get_new_crtc_state(state, crtc);
7141 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7144 if (new_crtc_state->preload_luts &&
7145 (new_crtc_state->uapi.color_mgmt_changed ||
7146 new_crtc_state->update_pipe))
7147 intel_color_load_luts(new_crtc_state);
7149 intel_pre_plane_update(state, crtc);
7151 if (new_crtc_state->update_pipe)
7152 intel_encoders_update_pipe(state, crtc);
7154 if (DISPLAY_VER(i915) >= 11 &&
7155 new_crtc_state->update_pipe)
7156 icl_set_pipe_chicken(new_crtc_state);
7159 intel_fbc_update(state, crtc);
7162 (new_crtc_state->uapi.color_mgmt_changed ||
7163 new_crtc_state->update_pipe))
7164 intel_color_commit_noarm(new_crtc_state);
7166 intel_crtc_planes_update_noarm(state, crtc);
7168 /* Perform vblank evasion around commit operation */
7169 intel_pipe_update_start(new_crtc_state);
7171 commit_pipe_pre_planes(state, crtc);
7173 intel_crtc_planes_update_arm(state, crtc);
7175 commit_pipe_post_planes(state, crtc);
7177 intel_pipe_update_end(new_crtc_state);
7180 * We usually enable FIFO underrun interrupts as part of the
7181 * CRTC enable sequence during modesets. But when we inherit a
7182 * valid pipe configuration from the BIOS we need to take care
7183 * of enabling them on the CRTC's first fastset.
7185 if (new_crtc_state->update_pipe && !modeset &&
7186 old_crtc_state->inherited)
7187 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
7190 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
7191 struct intel_crtc_state *old_crtc_state,
7192 struct intel_crtc_state *new_crtc_state,
7193 struct intel_crtc *crtc)
7195 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7198 * We need to disable pipe CRC before disabling the pipe,
7199 * or we race against vblank off.
7201 intel_crtc_disable_pipe_crc(crtc);
7203 dev_priv->display->crtc_disable(state, crtc);
7204 crtc->active = false;
7205 intel_fbc_disable(crtc);
7206 intel_disable_shared_dpll(old_crtc_state);
7208 /* FIXME unify this for all platforms */
7209 if (!new_crtc_state->hw.active &&
7210 !HAS_GMCH(dev_priv))
7211 intel_initial_watermarks(state, crtc);
7214 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
7216 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7217 struct intel_crtc *crtc;
7221 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7222 new_crtc_state, i) {
7223 if (!intel_crtc_needs_modeset(new_crtc_state))
7226 if (!old_crtc_state->hw.active)
7229 intel_pre_plane_update(state, crtc);
7230 intel_crtc_disable_planes(state, crtc);
7233 /* Only disable port sync and MST slaves */
7234 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7235 new_crtc_state, i) {
7236 if (!intel_crtc_needs_modeset(new_crtc_state))
7239 if (!old_crtc_state->hw.active)
7242 /* In case of Transcoder port Sync master slave CRTCs can be
7243 * assigned in any order and we need to make sure that
7244 * slave CRTCs are disabled first and then master CRTC since
7245 * Slave vblanks are masked till Master Vblanks.
7247 if (!is_trans_port_sync_slave(old_crtc_state) &&
7248 !intel_dp_mst_is_slave_trans(old_crtc_state) &&
7249 !intel_crtc_is_bigjoiner_slave(old_crtc_state))
7252 intel_old_crtc_state_disables(state, old_crtc_state,
7253 new_crtc_state, crtc);
7254 handled |= BIT(crtc->pipe);
7257 /* Disable everything else left on */
7258 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7259 new_crtc_state, i) {
7260 if (!intel_crtc_needs_modeset(new_crtc_state) ||
7261 (handled & BIT(crtc->pipe)))
7264 if (!old_crtc_state->hw.active)
7267 intel_old_crtc_state_disables(state, old_crtc_state,
7268 new_crtc_state, crtc);
7272 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
7274 struct intel_crtc_state *new_crtc_state;
7275 struct intel_crtc *crtc;
7278 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7279 if (!new_crtc_state->hw.active)
7282 intel_enable_crtc(state, crtc);
7283 intel_update_crtc(state, crtc);
7287 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
7289 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7290 struct intel_crtc *crtc;
7291 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
7292 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
7293 u8 update_pipes = 0, modeset_pipes = 0;
7296 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7297 enum pipe pipe = crtc->pipe;
7299 if (!new_crtc_state->hw.active)
7302 /* ignore allocations for crtc's that have been turned off. */
7303 if (!intel_crtc_needs_modeset(new_crtc_state)) {
7304 entries[pipe] = old_crtc_state->wm.skl.ddb;
7305 update_pipes |= BIT(pipe);
7307 modeset_pipes |= BIT(pipe);
7312 * Whenever the number of active pipes changes, we need to make sure we
7313 * update the pipes in the right order so that their ddb allocations
7314 * never overlap with each other between CRTC updates. Otherwise we'll
7315 * cause pipe underruns and other bad stuff.
7317 * So first lets enable all pipes that do not need a fullmodeset as
7318 * those don't have any external dependency.
7320 while (update_pipes) {
7321 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7322 new_crtc_state, i) {
7323 enum pipe pipe = crtc->pipe;
7325 if ((update_pipes & BIT(pipe)) == 0)
7328 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7329 entries, I915_MAX_PIPES, pipe))
7332 entries[pipe] = new_crtc_state->wm.skl.ddb;
7333 update_pipes &= ~BIT(pipe);
7335 intel_update_crtc(state, crtc);
7338 * If this is an already active pipe, it's DDB changed,
7339 * and this isn't the last pipe that needs updating
7340 * then we need to wait for a vblank to pass for the
7341 * new ddb allocation to take effect.
7343 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
7344 &old_crtc_state->wm.skl.ddb) &&
7345 (update_pipes | modeset_pipes))
7346 intel_crtc_wait_for_next_vblank(crtc);
7350 update_pipes = modeset_pipes;
7353 * Enable all pipes that needs a modeset and do not depends on other
7356 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7357 enum pipe pipe = crtc->pipe;
7359 if ((modeset_pipes & BIT(pipe)) == 0)
7362 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
7363 is_trans_port_sync_master(new_crtc_state) ||
7364 intel_crtc_is_bigjoiner_master(new_crtc_state))
7367 modeset_pipes &= ~BIT(pipe);
7369 intel_enable_crtc(state, crtc);
7373 * Then we enable all remaining pipes that depend on other
7374 * pipes: MST slaves and port sync masters, big joiner master
7376 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7377 enum pipe pipe = crtc->pipe;
7379 if ((modeset_pipes & BIT(pipe)) == 0)
7382 modeset_pipes &= ~BIT(pipe);
7384 intel_enable_crtc(state, crtc);
7388 * Finally we do the plane updates/etc. for all pipes that got enabled.
7390 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7391 enum pipe pipe = crtc->pipe;
7393 if ((update_pipes & BIT(pipe)) == 0)
7396 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7397 entries, I915_MAX_PIPES, pipe));
7399 entries[pipe] = new_crtc_state->wm.skl.ddb;
7400 update_pipes &= ~BIT(pipe);
7402 intel_update_crtc(state, crtc);
7405 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
7406 drm_WARN_ON(&dev_priv->drm, update_pipes);
7409 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
7411 struct intel_atomic_state *state, *next;
7412 struct llist_node *freed;
7414 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
7415 llist_for_each_entry_safe(state, next, freed, freed)
7416 drm_atomic_state_put(&state->base);
7419 static void intel_atomic_helper_free_state_worker(struct work_struct *work)
7421 struct drm_i915_private *dev_priv =
7422 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
7424 intel_atomic_helper_free_state(dev_priv);
7427 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
7429 struct wait_queue_entry wait_fence, wait_reset;
7430 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
7432 init_wait_entry(&wait_fence, 0);
7433 init_wait_entry(&wait_reset, 0);
7435 prepare_to_wait(&intel_state->commit_ready.wait,
7436 &wait_fence, TASK_UNINTERRUPTIBLE);
7437 prepare_to_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7438 I915_RESET_MODESET),
7439 &wait_reset, TASK_UNINTERRUPTIBLE);
7442 if (i915_sw_fence_done(&intel_state->commit_ready) ||
7443 test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags))
7448 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
7449 finish_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags,
7450 I915_RESET_MODESET),
7454 static void intel_cleanup_dsbs(struct intel_atomic_state *state)
7456 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
7457 struct intel_crtc *crtc;
7460 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7462 intel_dsb_cleanup(old_crtc_state);
7465 static void intel_atomic_cleanup_work(struct work_struct *work)
7467 struct intel_atomic_state *state =
7468 container_of(work, struct intel_atomic_state, base.commit_work);
7469 struct drm_i915_private *i915 = to_i915(state->base.dev);
7471 intel_cleanup_dsbs(state);
7472 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
7473 drm_atomic_helper_commit_cleanup_done(&state->base);
7474 drm_atomic_state_put(&state->base);
7476 intel_atomic_helper_free_state(i915);
7479 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7481 struct drm_i915_private *i915 = to_i915(state->base.dev);
7482 struct intel_plane *plane;
7483 struct intel_plane_state *plane_state;
7486 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7487 struct drm_framebuffer *fb = plane_state->hw.fb;
7494 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7499 * The layout of the fast clear color value expected by HW
7500 * (the DRM ABI requiring this value to be located in fb at
7501 * offset 0 of cc plane, plane #2 previous generations or
7502 * plane #1 for flat ccs):
7503 * - 4 x 4 bytes per-channel value
7504 * (in surface type specific float/int format provided by the fb user)
7505 * - 8 bytes native color value used by the display
7506 * (converted/written by GPU during a fast clear operation using the
7507 * above per-channel values)
7509 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7510 * caller made sure that the object is synced wrt. the related color clear value
7513 ret = i915_gem_object_read_from_page(intel_fb_obj(fb),
7514 fb->offsets[cc_plane] + 16,
7515 &plane_state->ccval,
7516 sizeof(plane_state->ccval));
7517 /* The above could only fail if the FB obj has an unexpected backing store type. */
7518 drm_WARN_ON(&i915->drm, ret);
7522 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7524 struct drm_device *dev = state->base.dev;
7525 struct drm_i915_private *dev_priv = to_i915(dev);
7526 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7527 struct intel_crtc *crtc;
7528 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7529 intel_wakeref_t wakeref = 0;
7532 intel_atomic_commit_fence_wait(state);
7534 drm_atomic_helper_wait_for_dependencies(&state->base);
7537 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
7539 intel_atomic_prepare_plane_clear_colors(state);
7541 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7542 new_crtc_state, i) {
7543 if (intel_crtc_needs_modeset(new_crtc_state) ||
7544 new_crtc_state->update_pipe) {
7545 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7549 intel_commit_modeset_disables(state);
7551 /* FIXME: Eventually get rid of our crtc->config pointer */
7552 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7553 crtc->config = new_crtc_state;
7555 if (state->modeset) {
7556 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7558 intel_set_cdclk_pre_plane_update(state);
7560 intel_modeset_verify_disabled(dev_priv, state);
7563 intel_sagv_pre_plane_update(state);
7565 /* Complete the events for pipes that have now been disabled */
7566 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7567 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7569 /* Complete events for now disable pipes here. */
7570 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7571 spin_lock_irq(&dev->event_lock);
7572 drm_crtc_send_vblank_event(&crtc->base,
7573 new_crtc_state->uapi.event);
7574 spin_unlock_irq(&dev->event_lock);
7576 new_crtc_state->uapi.event = NULL;
7580 intel_encoders_update_prepare(state);
7582 intel_dbuf_pre_plane_update(state);
7583 intel_mbus_dbox_update(state);
7585 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7586 if (new_crtc_state->do_async_flip)
7587 intel_crtc_enable_flip_done(state, crtc);
7590 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7591 dev_priv->display->commit_modeset_enables(state);
7593 intel_encoders_update_complete(state);
7596 intel_set_cdclk_post_plane_update(state);
7598 intel_wait_for_vblank_workers(state);
7600 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7601 * already, but still need the state for the delayed optimization. To
7603 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7604 * - schedule that vblank worker _before_ calling hw_done
7605 * - at the start of commit_tail, cancel it _synchrously
7606 * - switch over to the vblank wait helper in the core after that since
7607 * we don't need out special handling any more.
7609 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7611 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7612 if (new_crtc_state->do_async_flip)
7613 intel_crtc_disable_flip_done(state, crtc);
7617 * Now that the vblank has passed, we can go ahead and program the
7618 * optimal watermarks on platforms that need two-step watermark
7621 * TODO: Move this (and other cleanup) to an async worker eventually.
7623 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7624 new_crtc_state, i) {
7626 * Gen2 reports pipe underruns whenever all planes are disabled.
7627 * So re-enable underrun reporting after some planes get enabled.
7629 * We do this before .optimize_watermarks() so that we have a
7630 * chance of catching underruns with the intermediate watermarks
7631 * vs. the new plane configuration.
7633 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7634 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7636 intel_optimize_watermarks(state, crtc);
7639 intel_dbuf_post_plane_update(state);
7640 intel_psr_post_plane_update(state);
7642 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7643 intel_post_plane_update(state, crtc);
7645 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7647 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
7650 * DSB cleanup is done in cleanup_work aligning with framebuffer
7651 * cleanup. So copy and reset the dsb structure to sync with
7652 * commit_done and later do dsb cleanup in cleanup_work.
7654 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb);
7657 /* Underruns don't always raise interrupts, so check manually */
7658 intel_check_cpu_fifo_underruns(dev_priv);
7659 intel_check_pch_fifo_underruns(dev_priv);
7662 intel_verify_planes(state);
7664 intel_sagv_post_plane_update(state);
7666 drm_atomic_helper_commit_hw_done(&state->base);
7668 if (state->modeset) {
7669 /* As one of the primary mmio accessors, KMS has a high
7670 * likelihood of triggering bugs in unclaimed access. After we
7671 * finish modesetting, see if an error has been flagged, and if
7672 * so enable debugging for the next modeset - and hope we catch
7675 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7676 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
7678 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7681 * Defer the cleanup of the old state to a separate worker to not
7682 * impede the current task (userspace for blocking modesets) that
7683 * are executed inline. For out-of-line asynchronous modesets/flips,
7684 * deferring to a new worker seems overkill, but we would place a
7685 * schedule point (cond_resched()) here anyway to keep latencies
7688 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work);
7689 queue_work(system_highpri_wq, &state->base.commit_work);
7692 static void intel_atomic_commit_work(struct work_struct *work)
7694 struct intel_atomic_state *state =
7695 container_of(work, struct intel_atomic_state, base.commit_work);
7697 intel_atomic_commit_tail(state);
7701 intel_atomic_commit_ready(struct i915_sw_fence *fence,
7702 enum i915_sw_fence_notify notify)
7704 struct intel_atomic_state *state =
7705 container_of(fence, struct intel_atomic_state, commit_ready);
7708 case FENCE_COMPLETE:
7709 /* we do blocking waits in the worker, nothing to do here */
7713 struct intel_atomic_helper *helper =
7714 &to_i915(state->base.dev)->atomic_helper;
7716 if (llist_add(&state->freed, &helper->free_list))
7717 schedule_work(&helper->free_work);
7725 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7727 struct intel_plane_state *old_plane_state, *new_plane_state;
7728 struct intel_plane *plane;
7731 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7733 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7734 to_intel_frontbuffer(new_plane_state->hw.fb),
7735 plane->frontbuffer_bit);
7738 static int intel_atomic_commit(struct drm_device *dev,
7739 struct drm_atomic_state *_state,
7742 struct intel_atomic_state *state = to_intel_atomic_state(_state);
7743 struct drm_i915_private *dev_priv = to_i915(dev);
7746 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
7748 drm_atomic_state_get(&state->base);
7749 i915_sw_fence_init(&state->commit_ready,
7750 intel_atomic_commit_ready);
7753 * The intel_legacy_cursor_update() fast path takes care
7754 * of avoiding the vblank waits for simple cursor
7755 * movement and flips. For cursor on/off and size changes,
7756 * we want to perform the vblank waits so that watermark
7757 * updates happen during the correct frames. Gen9+ have
7758 * double buffered watermarks and so shouldn't need this.
7760 * Unset state->legacy_cursor_update before the call to
7761 * drm_atomic_helper_setup_commit() because otherwise
7762 * drm_atomic_helper_wait_for_flip_done() is a noop and
7763 * we get FIFO underruns because we didn't wait
7766 * FIXME doing watermarks and fb cleanup from a vblank worker
7767 * (assuming we had any) would solve these problems.
7769 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
7770 struct intel_crtc_state *new_crtc_state;
7771 struct intel_crtc *crtc;
7774 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7775 if (new_crtc_state->wm.need_postvbl_update ||
7776 new_crtc_state->update_wm_post)
7777 state->base.legacy_cursor_update = false;
7780 ret = intel_atomic_prepare_commit(state);
7782 drm_dbg_atomic(&dev_priv->drm,
7783 "Preparing state failed with %i\n", ret);
7784 i915_sw_fence_commit(&state->commit_ready);
7785 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7789 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7791 ret = drm_atomic_helper_swap_state(&state->base, true);
7793 intel_atomic_swap_global_state(state);
7796 struct intel_crtc_state *new_crtc_state;
7797 struct intel_crtc *crtc;
7800 i915_sw_fence_commit(&state->commit_ready);
7802 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7803 intel_dsb_cleanup(new_crtc_state);
7805 drm_atomic_helper_cleanup_planes(dev, &state->base);
7806 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7809 intel_shared_dpll_swap_state(state);
7810 intel_atomic_track_fbs(state);
7812 drm_atomic_state_get(&state->base);
7813 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
7815 i915_sw_fence_commit(&state->commit_ready);
7816 if (nonblock && state->modeset) {
7817 queue_work(dev_priv->modeset_wq, &state->base.commit_work);
7818 } else if (nonblock) {
7819 queue_work(dev_priv->flip_wq, &state->base.commit_work);
7822 flush_workqueue(dev_priv->modeset_wq);
7823 intel_atomic_commit_tail(state);
7830 * intel_plane_destroy - destroy a plane
7831 * @plane: plane to destroy
7833 * Common destruction function for all types of planes (primary, cursor,
7836 void intel_plane_destroy(struct drm_plane *plane)
7838 drm_plane_cleanup(plane);
7839 kfree(to_intel_plane(plane));
7842 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv)
7844 struct intel_plane *plane;
7846 for_each_intel_plane(&dev_priv->drm, plane) {
7847 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv,
7850 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base);
7855 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
7856 struct drm_file *file)
7858 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
7859 struct drm_crtc *drmmode_crtc;
7860 struct intel_crtc *crtc;
7862 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
7866 crtc = to_intel_crtc(drmmode_crtc);
7867 pipe_from_crtc_id->pipe = crtc->pipe;
7872 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
7874 struct drm_device *dev = encoder->base.dev;
7875 struct intel_encoder *source_encoder;
7876 u32 possible_clones = 0;
7878 for_each_intel_encoder(dev, source_encoder) {
7879 if (encoders_cloneable(encoder, source_encoder))
7880 possible_clones |= drm_encoder_mask(&source_encoder->base);
7883 return possible_clones;
7886 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
7888 struct drm_device *dev = encoder->base.dev;
7889 struct intel_crtc *crtc;
7890 u32 possible_crtcs = 0;
7892 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
7893 possible_crtcs |= drm_crtc_mask(&crtc->base);
7895 return possible_crtcs;
7898 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
7900 if (!IS_MOBILE(dev_priv))
7903 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
7906 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
7912 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
7914 if (DISPLAY_VER(dev_priv) >= 9)
7917 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
7920 if (HAS_PCH_LPT_H(dev_priv) &&
7921 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
7924 /* DDI E can't be used if DDI A requires 4 lanes */
7925 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
7928 if (!dev_priv->vbt.int_crt_support)
7934 static void intel_setup_outputs(struct drm_i915_private *dev_priv)
7936 struct intel_encoder *encoder;
7937 bool dpd_is_edp = false;
7939 intel_pps_unlock_regs_wa(dev_priv);
7941 if (!HAS_DISPLAY(dev_priv))
7944 if (IS_DG2(dev_priv)) {
7945 intel_ddi_init(dev_priv, PORT_A);
7946 intel_ddi_init(dev_priv, PORT_B);
7947 intel_ddi_init(dev_priv, PORT_C);
7948 intel_ddi_init(dev_priv, PORT_D_XELPD);
7949 intel_ddi_init(dev_priv, PORT_TC1);
7950 } else if (IS_ALDERLAKE_P(dev_priv)) {
7951 intel_ddi_init(dev_priv, PORT_A);
7952 intel_ddi_init(dev_priv, PORT_B);
7953 intel_ddi_init(dev_priv, PORT_TC1);
7954 intel_ddi_init(dev_priv, PORT_TC2);
7955 intel_ddi_init(dev_priv, PORT_TC3);
7956 intel_ddi_init(dev_priv, PORT_TC4);
7957 icl_dsi_init(dev_priv);
7958 } else if (IS_ALDERLAKE_S(dev_priv)) {
7959 intel_ddi_init(dev_priv, PORT_A);
7960 intel_ddi_init(dev_priv, PORT_TC1);
7961 intel_ddi_init(dev_priv, PORT_TC2);
7962 intel_ddi_init(dev_priv, PORT_TC3);
7963 intel_ddi_init(dev_priv, PORT_TC4);
7964 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) {
7965 intel_ddi_init(dev_priv, PORT_A);
7966 intel_ddi_init(dev_priv, PORT_B);
7967 intel_ddi_init(dev_priv, PORT_TC1);
7968 intel_ddi_init(dev_priv, PORT_TC2);
7969 } else if (DISPLAY_VER(dev_priv) >= 12) {
7970 intel_ddi_init(dev_priv, PORT_A);
7971 intel_ddi_init(dev_priv, PORT_B);
7972 intel_ddi_init(dev_priv, PORT_TC1);
7973 intel_ddi_init(dev_priv, PORT_TC2);
7974 intel_ddi_init(dev_priv, PORT_TC3);
7975 intel_ddi_init(dev_priv, PORT_TC4);
7976 intel_ddi_init(dev_priv, PORT_TC5);
7977 intel_ddi_init(dev_priv, PORT_TC6);
7978 icl_dsi_init(dev_priv);
7979 } else if (IS_JSL_EHL(dev_priv)) {
7980 intel_ddi_init(dev_priv, PORT_A);
7981 intel_ddi_init(dev_priv, PORT_B);
7982 intel_ddi_init(dev_priv, PORT_C);
7983 intel_ddi_init(dev_priv, PORT_D);
7984 icl_dsi_init(dev_priv);
7985 } else if (DISPLAY_VER(dev_priv) == 11) {
7986 intel_ddi_init(dev_priv, PORT_A);
7987 intel_ddi_init(dev_priv, PORT_B);
7988 intel_ddi_init(dev_priv, PORT_C);
7989 intel_ddi_init(dev_priv, PORT_D);
7990 intel_ddi_init(dev_priv, PORT_E);
7991 intel_ddi_init(dev_priv, PORT_F);
7992 icl_dsi_init(dev_priv);
7993 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) {
7994 intel_ddi_init(dev_priv, PORT_A);
7995 intel_ddi_init(dev_priv, PORT_B);
7996 intel_ddi_init(dev_priv, PORT_C);
7997 vlv_dsi_init(dev_priv);
7998 } else if (DISPLAY_VER(dev_priv) >= 9) {
7999 intel_ddi_init(dev_priv, PORT_A);
8000 intel_ddi_init(dev_priv, PORT_B);
8001 intel_ddi_init(dev_priv, PORT_C);
8002 intel_ddi_init(dev_priv, PORT_D);
8003 intel_ddi_init(dev_priv, PORT_E);
8004 } else if (HAS_DDI(dev_priv)) {
8007 if (intel_ddi_crt_present(dev_priv))
8008 intel_crt_init(dev_priv);
8010 /* Haswell uses DDI functions to detect digital outputs. */
8011 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
8013 intel_ddi_init(dev_priv, PORT_A);
8015 found = intel_de_read(dev_priv, SFUSE_STRAP);
8016 if (found & SFUSE_STRAP_DDIB_DETECTED)
8017 intel_ddi_init(dev_priv, PORT_B);
8018 if (found & SFUSE_STRAP_DDIC_DETECTED)
8019 intel_ddi_init(dev_priv, PORT_C);
8020 if (found & SFUSE_STRAP_DDID_DETECTED)
8021 intel_ddi_init(dev_priv, PORT_D);
8022 if (found & SFUSE_STRAP_DDIF_DETECTED)
8023 intel_ddi_init(dev_priv, PORT_F);
8024 } else if (HAS_PCH_SPLIT(dev_priv)) {
8028 * intel_edp_init_connector() depends on this completing first,
8029 * to prevent the registration of both eDP and LVDS and the
8030 * incorrect sharing of the PPS.
8032 intel_lvds_init(dev_priv);
8033 intel_crt_init(dev_priv);
8035 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
8037 if (ilk_has_edp_a(dev_priv))
8038 g4x_dp_init(dev_priv, DP_A, PORT_A);
8040 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
8041 /* PCH SDVOB multiplex with HDMIB */
8042 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
8044 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
8045 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
8046 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
8049 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
8050 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
8052 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
8053 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
8055 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
8056 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
8058 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
8059 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
8060 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
8061 bool has_edp, has_port;
8063 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
8064 intel_crt_init(dev_priv);
8067 * The DP_DETECTED bit is the latched state of the DDC
8068 * SDA pin at boot. However since eDP doesn't require DDC
8069 * (no way to plug in a DP->HDMI dongle) the DDC pins for
8070 * eDP ports may have been muxed to an alternate function.
8071 * Thus we can't rely on the DP_DETECTED bit alone to detect
8072 * eDP ports. Consult the VBT as well as DP_DETECTED to
8075 * Sadly the straps seem to be missing sometimes even for HDMI
8076 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
8077 * and VBT for the presence of the port. Additionally we can't
8078 * trust the port type the VBT declares as we've seen at least
8079 * HDMI ports that the VBT claim are DP or eDP.
8081 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
8082 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
8083 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
8084 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
8085 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
8086 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
8088 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
8089 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
8090 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
8091 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
8092 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
8093 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
8095 if (IS_CHERRYVIEW(dev_priv)) {
8097 * eDP not supported on port D,
8098 * so no need to worry about it
8100 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
8101 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
8102 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
8103 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
8104 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
8107 vlv_dsi_init(dev_priv);
8108 } else if (IS_PINEVIEW(dev_priv)) {
8109 intel_lvds_init(dev_priv);
8110 intel_crt_init(dev_priv);
8111 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
8114 if (IS_MOBILE(dev_priv))
8115 intel_lvds_init(dev_priv);
8117 intel_crt_init(dev_priv);
8119 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8120 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
8121 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
8122 if (!found && IS_G4X(dev_priv)) {
8123 drm_dbg_kms(&dev_priv->drm,
8124 "probing HDMI on SDVOB\n");
8125 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
8128 if (!found && IS_G4X(dev_priv))
8129 g4x_dp_init(dev_priv, DP_B, PORT_B);
8132 /* Before G4X SDVOC doesn't have its own detect register */
8134 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8135 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
8136 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
8139 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
8141 if (IS_G4X(dev_priv)) {
8142 drm_dbg_kms(&dev_priv->drm,
8143 "probing HDMI on SDVOC\n");
8144 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
8146 if (IS_G4X(dev_priv))
8147 g4x_dp_init(dev_priv, DP_C, PORT_C);
8150 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
8151 g4x_dp_init(dev_priv, DP_D, PORT_D);
8153 if (SUPPORTS_TV(dev_priv))
8154 intel_tv_init(dev_priv);
8155 } else if (DISPLAY_VER(dev_priv) == 2) {
8156 if (IS_I85X(dev_priv))
8157 intel_lvds_init(dev_priv);
8159 intel_crt_init(dev_priv);
8160 intel_dvo_init(dev_priv);
8163 for_each_intel_encoder(&dev_priv->drm, encoder) {
8164 encoder->base.possible_crtcs =
8165 intel_encoder_possible_crtcs(encoder);
8166 encoder->base.possible_clones =
8167 intel_encoder_possible_clones(encoder);
8170 intel_init_pch_refclk(dev_priv);
8172 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
8175 static enum drm_mode_status
8176 intel_mode_valid(struct drm_device *dev,
8177 const struct drm_display_mode *mode)
8179 struct drm_i915_private *dev_priv = to_i915(dev);
8180 int hdisplay_max, htotal_max;
8181 int vdisplay_max, vtotal_max;
8184 * Can't reject DBLSCAN here because Xorg ddxen can add piles
8185 * of DBLSCAN modes to the output's mode list when they detect
8186 * the scaling mode property on the connector. And they don't
8187 * ask the kernel to validate those modes in any way until
8188 * modeset time at which point the client gets a protocol error.
8189 * So in order to not upset those clients we silently ignore the
8190 * DBLSCAN flag on such connectors. For other connectors we will
8191 * reject modes with the DBLSCAN flag in encoder->compute_config().
8192 * And we always reject DBLSCAN modes in connector->mode_valid()
8193 * as we never want such modes on the connector's mode list.
8196 if (mode->vscan > 1)
8197 return MODE_NO_VSCAN;
8199 if (mode->flags & DRM_MODE_FLAG_HSKEW)
8200 return MODE_H_ILLEGAL;
8202 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
8203 DRM_MODE_FLAG_NCSYNC |
8204 DRM_MODE_FLAG_PCSYNC))
8207 if (mode->flags & (DRM_MODE_FLAG_BCAST |
8208 DRM_MODE_FLAG_PIXMUX |
8209 DRM_MODE_FLAG_CLKDIV2))
8212 /* Transcoder timing limits */
8213 if (DISPLAY_VER(dev_priv) >= 11) {
8214 hdisplay_max = 16384;
8215 vdisplay_max = 8192;
8218 } else if (DISPLAY_VER(dev_priv) >= 9 ||
8219 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
8220 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
8221 vdisplay_max = 4096;
8224 } else if (DISPLAY_VER(dev_priv) >= 3) {
8225 hdisplay_max = 4096;
8226 vdisplay_max = 4096;
8230 hdisplay_max = 2048;
8231 vdisplay_max = 2048;
8236 if (mode->hdisplay > hdisplay_max ||
8237 mode->hsync_start > htotal_max ||
8238 mode->hsync_end > htotal_max ||
8239 mode->htotal > htotal_max)
8240 return MODE_H_ILLEGAL;
8242 if (mode->vdisplay > vdisplay_max ||
8243 mode->vsync_start > vtotal_max ||
8244 mode->vsync_end > vtotal_max ||
8245 mode->vtotal > vtotal_max)
8246 return MODE_V_ILLEGAL;
8248 if (DISPLAY_VER(dev_priv) >= 5) {
8249 if (mode->hdisplay < 64 ||
8250 mode->htotal - mode->hdisplay < 32)
8251 return MODE_H_ILLEGAL;
8253 if (mode->vtotal - mode->vdisplay < 5)
8254 return MODE_V_ILLEGAL;
8256 if (mode->htotal - mode->hdisplay < 32)
8257 return MODE_H_ILLEGAL;
8259 if (mode->vtotal - mode->vdisplay < 3)
8260 return MODE_V_ILLEGAL;
8264 * Cantiga+ cannot handle modes with a hsync front porch of 0.
8265 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
8267 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) &&
8268 mode->hsync_start == mode->hdisplay)
8269 return MODE_H_ILLEGAL;
8274 enum drm_mode_status
8275 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
8276 const struct drm_display_mode *mode,
8279 int plane_width_max, plane_height_max;
8282 * intel_mode_valid() should be
8283 * sufficient on older platforms.
8285 if (DISPLAY_VER(dev_priv) < 9)
8289 * Most people will probably want a fullscreen
8290 * plane so let's not advertize modes that are
8293 if (DISPLAY_VER(dev_priv) >= 11) {
8294 plane_width_max = 5120 << bigjoiner;
8295 plane_height_max = 4320;
8297 plane_width_max = 5120;
8298 plane_height_max = 4096;
8301 if (mode->hdisplay > plane_width_max)
8302 return MODE_H_ILLEGAL;
8304 if (mode->vdisplay > plane_height_max)
8305 return MODE_V_ILLEGAL;
8310 static const struct drm_mode_config_funcs intel_mode_funcs = {
8311 .fb_create = intel_user_framebuffer_create,
8312 .get_format_info = intel_fb_get_format_info,
8313 .output_poll_changed = intel_fbdev_output_poll_changed,
8314 .mode_valid = intel_mode_valid,
8315 .atomic_check = intel_atomic_check,
8316 .atomic_commit = intel_atomic_commit,
8317 .atomic_state_alloc = intel_atomic_state_alloc,
8318 .atomic_state_clear = intel_atomic_state_clear,
8319 .atomic_state_free = intel_atomic_state_free,
8322 static const struct drm_i915_display_funcs skl_display_funcs = {
8323 .get_pipe_config = hsw_get_pipe_config,
8324 .crtc_enable = hsw_crtc_enable,
8325 .crtc_disable = hsw_crtc_disable,
8326 .commit_modeset_enables = skl_commit_modeset_enables,
8327 .get_initial_plane_config = skl_get_initial_plane_config,
8330 static const struct drm_i915_display_funcs ddi_display_funcs = {
8331 .get_pipe_config = hsw_get_pipe_config,
8332 .crtc_enable = hsw_crtc_enable,
8333 .crtc_disable = hsw_crtc_disable,
8334 .commit_modeset_enables = intel_commit_modeset_enables,
8335 .get_initial_plane_config = i9xx_get_initial_plane_config,
8338 static const struct drm_i915_display_funcs pch_split_display_funcs = {
8339 .get_pipe_config = ilk_get_pipe_config,
8340 .crtc_enable = ilk_crtc_enable,
8341 .crtc_disable = ilk_crtc_disable,
8342 .commit_modeset_enables = intel_commit_modeset_enables,
8343 .get_initial_plane_config = i9xx_get_initial_plane_config,
8346 static const struct drm_i915_display_funcs vlv_display_funcs = {
8347 .get_pipe_config = i9xx_get_pipe_config,
8348 .crtc_enable = valleyview_crtc_enable,
8349 .crtc_disable = i9xx_crtc_disable,
8350 .commit_modeset_enables = intel_commit_modeset_enables,
8351 .get_initial_plane_config = i9xx_get_initial_plane_config,
8354 static const struct drm_i915_display_funcs i9xx_display_funcs = {
8355 .get_pipe_config = i9xx_get_pipe_config,
8356 .crtc_enable = i9xx_crtc_enable,
8357 .crtc_disable = i9xx_crtc_disable,
8358 .commit_modeset_enables = intel_commit_modeset_enables,
8359 .get_initial_plane_config = i9xx_get_initial_plane_config,
8363 * intel_init_display_hooks - initialize the display modesetting hooks
8364 * @dev_priv: device private
8366 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
8368 if (!HAS_DISPLAY(dev_priv))
8371 intel_init_cdclk_hooks(dev_priv);
8372 intel_audio_hooks_init(dev_priv);
8374 intel_dpll_init_clock_hook(dev_priv);
8376 if (DISPLAY_VER(dev_priv) >= 9) {
8377 dev_priv->display = &skl_display_funcs;
8378 } else if (HAS_DDI(dev_priv)) {
8379 dev_priv->display = &ddi_display_funcs;
8380 } else if (HAS_PCH_SPLIT(dev_priv)) {
8381 dev_priv->display = &pch_split_display_funcs;
8382 } else if (IS_CHERRYVIEW(dev_priv) ||
8383 IS_VALLEYVIEW(dev_priv)) {
8384 dev_priv->display = &vlv_display_funcs;
8386 dev_priv->display = &i9xx_display_funcs;
8389 intel_fdi_init_hook(dev_priv);
8392 void intel_modeset_init_hw(struct drm_i915_private *i915)
8394 struct intel_cdclk_state *cdclk_state;
8396 if (!HAS_DISPLAY(i915))
8399 cdclk_state = to_intel_cdclk_state(i915->cdclk.obj.state);
8401 intel_update_cdclk(i915);
8402 intel_cdclk_dump_config(i915, &i915->cdclk.hw, "Current CDCLK");
8403 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw;
8406 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state)
8408 struct drm_plane *plane;
8409 struct intel_crtc *crtc;
8411 for_each_intel_crtc(state->dev, crtc) {
8412 struct intel_crtc_state *crtc_state;
8414 crtc_state = intel_atomic_get_crtc_state(state, crtc);
8415 if (IS_ERR(crtc_state))
8416 return PTR_ERR(crtc_state);
8418 if (crtc_state->hw.active) {
8420 * Preserve the inherited flag to avoid
8421 * taking the full modeset path.
8423 crtc_state->inherited = true;
8427 drm_for_each_plane(plane, state->dev) {
8428 struct drm_plane_state *plane_state;
8430 plane_state = drm_atomic_get_plane_state(state, plane);
8431 if (IS_ERR(plane_state))
8432 return PTR_ERR(plane_state);
8439 * Calculate what we think the watermarks should be for the state we've read
8440 * out of the hardware and then immediately program those watermarks so that
8441 * we ensure the hardware settings match our internal state.
8443 * We can calculate what we think WM's should be by creating a duplicate of the
8444 * current state (which was constructed during hardware readout) and running it
8445 * through the atomic check code to calculate new watermark values in the
8448 static void sanitize_watermarks(struct drm_i915_private *dev_priv)
8450 struct drm_atomic_state *state;
8451 struct intel_atomic_state *intel_state;
8452 struct intel_crtc *crtc;
8453 struct intel_crtc_state *crtc_state;
8454 struct drm_modeset_acquire_ctx ctx;
8458 /* Only supported on platforms that use atomic watermark design */
8459 if (!dev_priv->wm_disp->optimize_watermarks)
8462 state = drm_atomic_state_alloc(&dev_priv->drm);
8463 if (drm_WARN_ON(&dev_priv->drm, !state))
8466 intel_state = to_intel_atomic_state(state);
8468 drm_modeset_acquire_init(&ctx, 0);
8471 state->acquire_ctx = &ctx;
8474 * Hardware readout is the only time we don't want to calculate
8475 * intermediate watermarks (since we don't trust the current
8478 if (!HAS_GMCH(dev_priv))
8479 intel_state->skip_intermediate_wm = true;
8481 ret = sanitize_watermarks_add_affected(state);
8485 ret = intel_atomic_check(&dev_priv->drm, state);
8489 /* Write calculated watermark values back */
8490 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
8491 crtc_state->wm.need_postvbl_update = true;
8492 intel_optimize_watermarks(intel_state, crtc);
8494 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm;
8498 if (ret == -EDEADLK) {
8499 drm_atomic_state_clear(state);
8500 drm_modeset_backoff(&ctx);
8505 * If we fail here, it means that the hardware appears to be
8506 * programmed in a way that shouldn't be possible, given our
8507 * understanding of watermark requirements. This might mean a
8508 * mistake in the hardware readout code or a mistake in the
8509 * watermark calculations for a given platform. Raise a WARN
8510 * so that this is noticeable.
8512 * If this actually happens, we'll have to just leave the
8513 * BIOS-programmed watermarks untouched and hope for the best.
8515 drm_WARN(&dev_priv->drm, ret,
8516 "Could not determine valid watermarks for inherited state\n");
8518 drm_atomic_state_put(state);
8520 drm_modeset_drop_locks(&ctx);
8521 drm_modeset_acquire_fini(&ctx);
8524 static int intel_initial_commit(struct drm_device *dev)
8526 struct drm_atomic_state *state = NULL;
8527 struct drm_modeset_acquire_ctx ctx;
8528 struct intel_crtc *crtc;
8531 state = drm_atomic_state_alloc(dev);
8535 drm_modeset_acquire_init(&ctx, 0);
8538 state->acquire_ctx = &ctx;
8540 for_each_intel_crtc(dev, crtc) {
8541 struct intel_crtc_state *crtc_state =
8542 intel_atomic_get_crtc_state(state, crtc);
8544 if (IS_ERR(crtc_state)) {
8545 ret = PTR_ERR(crtc_state);
8549 if (crtc_state->hw.active) {
8550 struct intel_encoder *encoder;
8553 * We've not yet detected sink capabilities
8554 * (audio,infoframes,etc.) and thus we don't want to
8555 * force a full state recomputation yet. We want that to
8556 * happen only for the first real commit from userspace.
8557 * So preserve the inherited flag for the time being.
8559 crtc_state->inherited = true;
8561 ret = drm_atomic_add_affected_planes(state, &crtc->base);
8566 * FIXME hack to force a LUT update to avoid the
8567 * plane update forcing the pipe gamma on without
8568 * having a proper LUT loaded. Remove once we
8569 * have readout for pipe gamma enable.
8571 crtc_state->uapi.color_mgmt_changed = true;
8573 for_each_intel_encoder_mask(dev, encoder,
8574 crtc_state->uapi.encoder_mask) {
8575 if (encoder->initial_fastset_check &&
8576 !encoder->initial_fastset_check(encoder, crtc_state)) {
8577 ret = drm_atomic_add_affected_connectors(state,
8586 ret = drm_atomic_commit(state);
8589 if (ret == -EDEADLK) {
8590 drm_atomic_state_clear(state);
8591 drm_modeset_backoff(&ctx);
8595 drm_atomic_state_put(state);
8597 drm_modeset_drop_locks(&ctx);
8598 drm_modeset_acquire_fini(&ctx);
8603 static void intel_mode_config_init(struct drm_i915_private *i915)
8605 struct drm_mode_config *mode_config = &i915->drm.mode_config;
8607 drm_mode_config_init(&i915->drm);
8608 INIT_LIST_HEAD(&i915->global_obj_list);
8610 mode_config->min_width = 0;
8611 mode_config->min_height = 0;
8613 mode_config->preferred_depth = 24;
8614 mode_config->prefer_shadow = 1;
8616 mode_config->funcs = &intel_mode_funcs;
8618 mode_config->async_page_flip = HAS_ASYNC_FLIPS(i915);
8621 * Maximum framebuffer dimensions, chosen to match
8622 * the maximum render engine surface size on gen4+.
8624 if (DISPLAY_VER(i915) >= 7) {
8625 mode_config->max_width = 16384;
8626 mode_config->max_height = 16384;
8627 } else if (DISPLAY_VER(i915) >= 4) {
8628 mode_config->max_width = 8192;
8629 mode_config->max_height = 8192;
8630 } else if (DISPLAY_VER(i915) == 3) {
8631 mode_config->max_width = 4096;
8632 mode_config->max_height = 4096;
8634 mode_config->max_width = 2048;
8635 mode_config->max_height = 2048;
8638 if (IS_I845G(i915) || IS_I865G(i915)) {
8639 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512;
8640 mode_config->cursor_height = 1023;
8641 } else if (IS_I830(i915) || IS_I85X(i915) ||
8642 IS_I915G(i915) || IS_I915GM(i915)) {
8643 mode_config->cursor_width = 64;
8644 mode_config->cursor_height = 64;
8646 mode_config->cursor_width = 256;
8647 mode_config->cursor_height = 256;
8651 static void intel_mode_config_cleanup(struct drm_i915_private *i915)
8653 intel_atomic_global_obj_cleanup(i915);
8654 drm_mode_config_cleanup(&i915->drm);
8657 /* part #1: call before irq install */
8658 int intel_modeset_init_noirq(struct drm_i915_private *i915)
8662 if (i915_inject_probe_failure(i915))
8665 if (HAS_DISPLAY(i915)) {
8666 ret = drm_vblank_init(&i915->drm,
8667 INTEL_NUM_PIPES(i915));
8672 intel_bios_init(i915);
8674 ret = intel_vga_register(i915);
8678 /* FIXME: completely on the wrong abstraction layer */
8679 intel_power_domains_init_hw(i915, false);
8681 if (!HAS_DISPLAY(i915))
8684 intel_dmc_ucode_init(i915);
8686 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
8687 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI |
8688 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE);
8690 i915->window2_delay = 0; /* No DSB so no window2 delay */
8692 intel_mode_config_init(i915);
8694 ret = intel_cdclk_init(i915);
8696 goto cleanup_vga_client_pw_domain_dmc;
8698 ret = intel_dbuf_init(i915);
8700 goto cleanup_vga_client_pw_domain_dmc;
8702 ret = intel_bw_init(i915);
8704 goto cleanup_vga_client_pw_domain_dmc;
8706 init_llist_head(&i915->atomic_helper.free_list);
8707 INIT_WORK(&i915->atomic_helper.free_work,
8708 intel_atomic_helper_free_state_worker);
8710 intel_init_quirks(i915);
8712 intel_fbc_init(i915);
8716 cleanup_vga_client_pw_domain_dmc:
8717 intel_dmc_ucode_fini(i915);
8718 intel_power_domains_driver_remove(i915);
8719 intel_vga_unregister(i915);
8721 intel_bios_driver_remove(i915);
8726 /* part #2: call after irq install, but before gem init */
8727 int intel_modeset_init_nogem(struct drm_i915_private *i915)
8729 struct drm_device *dev = &i915->drm;
8731 struct intel_crtc *crtc;
8734 if (!HAS_DISPLAY(i915))
8737 intel_init_pm(i915);
8739 intel_panel_sanitize_ssc(i915);
8741 intel_pps_setup(i915);
8743 intel_gmbus_setup(i915);
8745 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n",
8746 INTEL_NUM_PIPES(i915),
8747 INTEL_NUM_PIPES(i915) > 1 ? "s" : "");
8749 for_each_pipe(i915, pipe) {
8750 ret = intel_crtc_init(i915, pipe);
8752 intel_mode_config_cleanup(i915);
8757 intel_plane_possible_crtcs_init(i915);
8758 intel_shared_dpll_init(i915);
8759 intel_fdi_pll_freq_update(i915);
8761 intel_update_czclk(i915);
8762 intel_modeset_init_hw(i915);
8763 intel_dpll_update_ref_clks(i915);
8765 intel_hdcp_component_init(i915);
8767 if (i915->max_cdclk_freq == 0)
8768 intel_update_max_cdclk(i915);
8771 * If the platform has HTI, we need to find out whether it has reserved
8772 * any display resources before we create our display outputs.
8774 if (INTEL_INFO(i915)->display.has_hti)
8775 i915->hti_state = intel_de_read(i915, HDPORT_STATE);
8777 /* Just disable it once at startup */
8778 intel_vga_disable(i915);
8779 intel_setup_outputs(i915);
8781 drm_modeset_lock_all(dev);
8782 intel_modeset_setup_hw_state(i915, dev->mode_config.acquire_ctx);
8783 intel_acpi_assign_connector_fwnodes(i915);
8784 drm_modeset_unlock_all(dev);
8786 for_each_intel_crtc(dev, crtc) {
8787 if (!to_intel_crtc_state(crtc->base.state)->uapi.active)
8789 intel_crtc_initial_plane_config(crtc);
8793 * Make sure hardware watermarks really match the state we read out.
8794 * Note that we need to do this after reconstructing the BIOS fb's
8795 * since the watermark calculation done here will use pstate->fb.
8797 if (!HAS_GMCH(i915))
8798 sanitize_watermarks(i915);
8803 /* part #3: call after gem init */
8804 int intel_modeset_init(struct drm_i915_private *i915)
8808 if (!HAS_DISPLAY(i915))
8812 * Force all active planes to recompute their states. So that on
8813 * mode_setcrtc after probe, all the intel_plane_state variables
8814 * are already calculated and there is no assert_plane warnings
8817 ret = intel_initial_commit(&i915->drm);
8819 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret);
8821 intel_overlay_setup(i915);
8823 ret = intel_fbdev_init(&i915->drm);
8827 /* Only enable hotplug handling once the fbdev is fully set up. */
8828 intel_hpd_init(i915);
8829 intel_hpd_poll_disable(i915);
8831 intel_init_ipc(i915);
8836 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8838 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8839 /* 640x480@60Hz, ~25175 kHz */
8840 struct dpll clock = {
8850 drm_WARN_ON(&dev_priv->drm,
8851 i9xx_calc_dpll_params(48000, &clock) != 25154);
8853 drm_dbg_kms(&dev_priv->drm,
8854 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8855 pipe_name(pipe), clock.vco, clock.dot);
8857 fp = i9xx_dpll_compute_fp(&clock);
8858 dpll = DPLL_DVO_2X_MODE |
8860 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8861 PLL_P2_DIVIDE_BY_4 |
8862 PLL_REF_INPUT_DREFCLK |
8865 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
8866 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
8867 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
8868 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
8869 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
8870 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
8871 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
8873 intel_de_write(dev_priv, FP0(pipe), fp);
8874 intel_de_write(dev_priv, FP1(pipe), fp);
8877 * Apparently we need to have VGA mode enabled prior to changing
8878 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8879 * dividers, even though the register value does change.
8881 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
8882 intel_de_write(dev_priv, DPLL(pipe), dpll);
8884 /* Wait for the clocks to stabilize. */
8885 intel_de_posting_read(dev_priv, DPLL(pipe));
8888 /* The pixel multiplier can only be updated once the
8889 * DPLL is enabled and the clocks are stable.
8891 * So write it again.
8893 intel_de_write(dev_priv, DPLL(pipe), dpll);
8895 /* We do this three times for luck */
8896 for (i = 0; i < 3 ; i++) {
8897 intel_de_write(dev_priv, DPLL(pipe), dpll);
8898 intel_de_posting_read(dev_priv, DPLL(pipe));
8899 udelay(150); /* wait for warmup */
8902 intel_de_write(dev_priv, PIPECONF(pipe), PIPECONF_ENABLE);
8903 intel_de_posting_read(dev_priv, PIPECONF(pipe));
8905 intel_wait_for_pipe_scanline_moving(crtc);
8908 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
8910 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe);
8912 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n",
8915 drm_WARN_ON(&dev_priv->drm,
8916 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE);
8917 drm_WARN_ON(&dev_priv->drm,
8918 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE);
8919 drm_WARN_ON(&dev_priv->drm,
8920 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE);
8921 drm_WARN_ON(&dev_priv->drm,
8922 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK);
8923 drm_WARN_ON(&dev_priv->drm,
8924 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK);
8926 intel_de_write(dev_priv, PIPECONF(pipe), 0);
8927 intel_de_posting_read(dev_priv, PIPECONF(pipe));
8929 intel_wait_for_pipe_scanline_stopped(crtc);
8931 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS);
8932 intel_de_posting_read(dev_priv, DPLL(pipe));
8935 void intel_display_resume(struct drm_device *dev)
8937 struct drm_i915_private *i915 = to_i915(dev);
8938 struct drm_atomic_state *state = i915->modeset_restore_state;
8939 struct drm_modeset_acquire_ctx ctx;
8942 if (!HAS_DISPLAY(i915))
8945 i915->modeset_restore_state = NULL;
8947 state->acquire_ctx = &ctx;
8949 drm_modeset_acquire_init(&ctx, 0);
8952 ret = drm_modeset_lock_all_ctx(dev, &ctx);
8953 if (ret != -EDEADLK)
8956 drm_modeset_backoff(&ctx);
8960 ret = __intel_display_resume(i915, state, &ctx);
8962 intel_enable_ipc(i915);
8963 drm_modeset_drop_locks(&ctx);
8964 drm_modeset_acquire_fini(&ctx);
8968 "Restoring old state failed with %i\n", ret);
8970 drm_atomic_state_put(state);
8973 static void intel_hpd_poll_fini(struct drm_i915_private *i915)
8975 struct intel_connector *connector;
8976 struct drm_connector_list_iter conn_iter;
8978 /* Kill all the work that may have been queued by hpd. */
8979 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8980 for_each_intel_connector_iter(connector, &conn_iter) {
8981 if (connector->modeset_retry_work.func)
8982 cancel_work_sync(&connector->modeset_retry_work);
8983 if (connector->hdcp.shim) {
8984 cancel_delayed_work_sync(&connector->hdcp.check_work);
8985 cancel_work_sync(&connector->hdcp.prop_work);
8988 drm_connector_list_iter_end(&conn_iter);
8991 /* part #1: call before irq uninstall */
8992 void intel_modeset_driver_remove(struct drm_i915_private *i915)
8994 if (!HAS_DISPLAY(i915))
8997 flush_workqueue(i915->flip_wq);
8998 flush_workqueue(i915->modeset_wq);
9000 flush_work(&i915->atomic_helper.free_work);
9001 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list));
9004 /* part #2: call after irq uninstall */
9005 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915)
9007 if (!HAS_DISPLAY(i915))
9011 * Due to the hpd irq storm handling the hotplug work can re-arm the
9012 * poll handlers. Hence disable polling after hpd handling is shut down.
9014 intel_hpd_poll_fini(i915);
9017 * MST topology needs to be suspended so we don't have any calls to
9018 * fbdev after it's finalized. MST will be destroyed later as part of
9019 * drm_mode_config_cleanup()
9021 intel_dp_mst_suspend(i915);
9023 /* poll work can call into fbdev, hence clean that up afterwards */
9024 intel_fbdev_fini(i915);
9026 intel_unregister_dsm_handler();
9028 /* flush any delayed tasks or pending work */
9029 flush_scheduled_work();
9031 intel_hdcp_component_fini(i915);
9033 intel_mode_config_cleanup(i915);
9035 intel_overlay_cleanup(i915);
9037 intel_gmbus_teardown(i915);
9039 destroy_workqueue(i915->flip_wq);
9040 destroy_workqueue(i915->modeset_wq);
9042 intel_fbc_cleanup(i915);
9045 /* part #3: call after gem init */
9046 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915)
9048 intel_dmc_ucode_fini(i915);
9050 intel_power_domains_driver_remove(i915);
9052 intel_vga_unregister(i915);
9054 intel_bios_driver_remove(i915);
9057 bool intel_modeset_probe_defer(struct pci_dev *pdev)
9059 struct drm_privacy_screen *privacy_screen;
9062 * apple-gmux is needed on dual GPU MacBook Pro
9063 * to probe the panel if we're the inactive GPU.
9065 if (vga_switcheroo_client_probe_defer(pdev))
9068 /* If the LCD panel has a privacy-screen, wait for it */
9069 privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL);
9070 if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER)
9073 drm_privacy_screen_put(privacy_screen);
9078 void intel_display_driver_register(struct drm_i915_private *i915)
9080 if (!HAS_DISPLAY(i915))
9083 intel_display_debugfs_register(i915);
9085 /* Must be done after probing outputs */
9086 intel_opregion_register(i915);
9087 acpi_video_register();
9089 intel_audio_init(i915);
9092 * Some ports require correctly set-up hpd registers for
9093 * detection to work properly (leading to ghost connected
9094 * connector status), e.g. VGA on gm45. Hence we can only set
9095 * up the initial fbdev config after hpd irqs are fully
9096 * enabled. We do it last so that the async config cannot run
9097 * before the connectors are registered.
9099 intel_fbdev_initial_config_async(&i915->drm);
9102 * We need to coordinate the hotplugs with the asynchronous
9103 * fbdev configuration, for which we use the
9104 * fbdev->async_cookie.
9106 drm_kms_helper_poll_init(&i915->drm);
9109 void intel_display_driver_unregister(struct drm_i915_private *i915)
9111 if (!HAS_DISPLAY(i915))
9114 intel_fbdev_unregister(i915);
9115 intel_audio_deinit(i915);
9118 * After flushing the fbdev (incl. a late async config which
9119 * will have delayed queuing of a hotplug event), then flush
9120 * the hotplug events.
9122 drm_kms_helper_poll_fini(&i915->drm);
9123 drm_atomic_helper_shutdown(&i915->drm);
9125 acpi_video_unregister();
9126 intel_opregion_unregister(i915);
9129 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
9131 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);