1 /* 2 * Copyright © 2006-2007 Intel Corporation 3 * 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: 10 * 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 13 * Software. 14 * 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. 22 * 23 * Authors: 24 * Eric Anholt <eric@anholt.net> 25 */ 26 27 #include <acpi/video.h> 28 #include <linux/i2c.h> 29 #include <linux/input.h> 30 #include <linux/intel-iommu.h> 31 #include <linux/kernel.h> 32 #include <linux/module.h> 33 #include <linux/dma-resv.h> 34 #include <linux/slab.h> 35 #include <linux/string_helpers.h> 36 #include <linux/vga_switcheroo.h> 37 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/dp/drm_dp_helper.h> 43 #include <drm/drm_edid.h> 44 #include <drm/drm_fourcc.h> 45 #include <drm/drm_plane_helper.h> 46 #include <drm/drm_privacy_screen_consumer.h> 47 #include <drm/drm_probe_helper.h> 48 #include <drm/drm_rect.h> 49 50 #include "display/intel_audio.h" 51 #include "display/intel_crt.h" 52 #include "display/intel_ddi.h" 53 #include "display/intel_display_debugfs.h" 54 #include "display/intel_display_power.h" 55 #include "display/intel_dp.h" 56 #include "display/intel_dp_mst.h" 57 #include "display/intel_dpll.h" 58 #include "display/intel_dpll_mgr.h" 59 #include "display/intel_drrs.h" 60 #include "display/intel_dsi.h" 61 #include "display/intel_dvo.h" 62 #include "display/intel_fb.h" 63 #include "display/intel_gmbus.h" 64 #include "display/intel_hdmi.h" 65 #include "display/intel_lvds.h" 66 #include "display/intel_sdvo.h" 67 #include "display/intel_snps_phy.h" 68 #include "display/intel_tv.h" 69 #include "display/intel_vdsc.h" 70 #include "display/intel_vrr.h" 71 72 #include "gem/i915_gem_lmem.h" 73 #include "gem/i915_gem_object.h" 74 75 #include "gt/gen8_ppgtt.h" 76 77 #include "g4x_dp.h" 78 #include "g4x_hdmi.h" 79 #include "hsw_ips.h" 80 #include "i915_drv.h" 81 #include "i915_utils.h" 82 #include "icl_dsi.h" 83 #include "intel_acpi.h" 84 #include "intel_atomic.h" 85 #include "intel_atomic_plane.h" 86 #include "intel_bw.h" 87 #include "intel_cdclk.h" 88 #include "intel_color.h" 89 #include "intel_crtc.h" 90 #include "intel_de.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_overlay.h" 103 #include "intel_panel.h" 104 #include "intel_pch_display.h" 105 #include "intel_pch_refclk.h" 106 #include "intel_pcode.h" 107 #include "intel_pipe_crc.h" 108 #include "intel_plane_initial.h" 109 #include "intel_pm.h" 110 #include "intel_pps.h" 111 #include "intel_psr.h" 112 #include "intel_quirks.h" 113 #include "intel_sprite.h" 114 #include "intel_tc.h" 115 #include "intel_vga.h" 116 #include "i9xx_plane.h" 117 #include "skl_scaler.h" 118 #include "skl_universal_plane.h" 119 #include "vlv_dsi.h" 120 #include "vlv_dsi_pll.h" 121 #include "vlv_dsi_regs.h" 122 #include "vlv_sideband.h" 123 124 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state); 125 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); 126 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state); 127 static void ilk_set_pipeconf(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); 131 static void intel_modeset_setup_hw_state(struct drm_device *dev, 132 struct drm_modeset_acquire_ctx *ctx); 133 134 /** 135 * intel_update_watermarks - update FIFO watermark values based on current modes 136 * @dev_priv: i915 device 137 * 138 * Calculate watermark values for the various WM regs based on current mode 139 * and plane configuration. 140 * 141 * There are several cases to deal with here: 142 * - normal (i.e. non-self-refresh) 143 * - self-refresh (SR) mode 144 * - lines are large relative to FIFO size (buffer can hold up to 2) 145 * - lines are small relative to FIFO size (buffer can hold more than 2 146 * lines), so need to account for TLB latency 147 * 148 * The normal calculation is: 149 * watermark = dotclock * bytes per pixel * latency 150 * where latency is platform & configuration dependent (we assume pessimal 151 * values here). 152 * 153 * The SR calculation is: 154 * watermark = (trunc(latency/line time)+1) * surface width * 155 * bytes per pixel 156 * where 157 * line time = htotal / dotclock 158 * surface width = hdisplay for normal plane and 64 for cursor 159 * and latency is assumed to be high, as above. 160 * 161 * The final value programmed to the register should always be rounded up, 162 * and include an extra 2 entries to account for clock crossings. 163 * 164 * We don't use the sprite, so we can ignore that. And on Crestline we have 165 * to set the non-SR watermarks to 8. 166 */ 167 static void intel_update_watermarks(struct drm_i915_private *dev_priv) 168 { 169 if (dev_priv->wm_disp->update_wm) 170 dev_priv->wm_disp->update_wm(dev_priv); 171 } 172 173 static int intel_compute_pipe_wm(struct intel_atomic_state *state, 174 struct intel_crtc *crtc) 175 { 176 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 177 if (dev_priv->wm_disp->compute_pipe_wm) 178 return dev_priv->wm_disp->compute_pipe_wm(state, crtc); 179 return 0; 180 } 181 182 static int intel_compute_intermediate_wm(struct intel_atomic_state *state, 183 struct intel_crtc *crtc) 184 { 185 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 186 if (!dev_priv->wm_disp->compute_intermediate_wm) 187 return 0; 188 if (drm_WARN_ON(&dev_priv->drm, 189 !dev_priv->wm_disp->compute_pipe_wm)) 190 return 0; 191 return dev_priv->wm_disp->compute_intermediate_wm(state, crtc); 192 } 193 194 static bool intel_initial_watermarks(struct intel_atomic_state *state, 195 struct intel_crtc *crtc) 196 { 197 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 198 if (dev_priv->wm_disp->initial_watermarks) { 199 dev_priv->wm_disp->initial_watermarks(state, crtc); 200 return true; 201 } 202 return false; 203 } 204 205 static void intel_atomic_update_watermarks(struct intel_atomic_state *state, 206 struct intel_crtc *crtc) 207 { 208 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 209 if (dev_priv->wm_disp->atomic_update_watermarks) 210 dev_priv->wm_disp->atomic_update_watermarks(state, crtc); 211 } 212 213 static void intel_optimize_watermarks(struct intel_atomic_state *state, 214 struct intel_crtc *crtc) 215 { 216 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 217 if (dev_priv->wm_disp->optimize_watermarks) 218 dev_priv->wm_disp->optimize_watermarks(state, crtc); 219 } 220 221 static int intel_compute_global_watermarks(struct intel_atomic_state *state) 222 { 223 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 224 if (dev_priv->wm_disp->compute_global_watermarks) 225 return dev_priv->wm_disp->compute_global_watermarks(state); 226 return 0; 227 } 228 229 /* returns HPLL frequency in kHz */ 230 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv) 231 { 232 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; 233 234 /* Obtain SKU information */ 235 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & 236 CCK_FUSE_HPLL_FREQ_MASK; 237 238 return vco_freq[hpll_freq] * 1000; 239 } 240 241 int vlv_get_cck_clock(struct drm_i915_private *dev_priv, 242 const char *name, u32 reg, int ref_freq) 243 { 244 u32 val; 245 int divider; 246 247 val = vlv_cck_read(dev_priv, reg); 248 divider = val & CCK_FREQUENCY_VALUES; 249 250 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) != 251 (divider << CCK_FREQUENCY_STATUS_SHIFT), 252 "%s change in progress\n", name); 253 254 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); 255 } 256 257 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, 258 const char *name, u32 reg) 259 { 260 int hpll; 261 262 vlv_cck_get(dev_priv); 263 264 if (dev_priv->hpll_freq == 0) 265 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv); 266 267 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq); 268 269 vlv_cck_put(dev_priv); 270 271 return hpll; 272 } 273 274 static void intel_update_czclk(struct drm_i915_private *dev_priv) 275 { 276 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) 277 return; 278 279 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", 280 CCK_CZ_CLOCK_CONTROL); 281 282 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n", 283 dev_priv->czclk_freq); 284 } 285 286 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state) 287 { 288 return (crtc_state->active_planes & 289 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0; 290 } 291 292 /* WA Display #0827: Gen9:all */ 293 static void 294 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable) 295 { 296 if (enable) 297 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), 298 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DUPS1_GATING_DIS | DUPS2_GATING_DIS); 299 else 300 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), 301 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS)); 302 } 303 304 /* Wa_2006604312:icl,ehl */ 305 static void 306 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe, 307 bool enable) 308 { 309 if (enable) 310 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), 311 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) | DPFR_GATING_DIS); 312 else 313 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), 314 intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)) & ~DPFR_GATING_DIS); 315 } 316 317 /* Wa_1604331009:icl,jsl,ehl */ 318 static void 319 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe, 320 bool enable) 321 { 322 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe), CURSOR_GATING_DIS, 323 enable ? CURSOR_GATING_DIS : 0); 324 } 325 326 static bool 327 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state) 328 { 329 return crtc_state->master_transcoder != INVALID_TRANSCODER; 330 } 331 332 static bool 333 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state) 334 { 335 return crtc_state->sync_mode_slaves_mask != 0; 336 } 337 338 bool 339 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state) 340 { 341 return is_trans_port_sync_master(crtc_state) || 342 is_trans_port_sync_slave(crtc_state); 343 } 344 345 static enum pipe bigjoiner_master_pipe(const struct intel_crtc_state *crtc_state) 346 { 347 return ffs(crtc_state->bigjoiner_pipes) - 1; 348 } 349 350 u8 intel_crtc_bigjoiner_slave_pipes(const struct intel_crtc_state *crtc_state) 351 { 352 if (crtc_state->bigjoiner_pipes) 353 return crtc_state->bigjoiner_pipes & ~BIT(bigjoiner_master_pipe(crtc_state)); 354 else 355 return 0; 356 } 357 358 bool intel_crtc_is_bigjoiner_slave(const struct intel_crtc_state *crtc_state) 359 { 360 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 361 362 return crtc_state->bigjoiner_pipes && 363 crtc->pipe != bigjoiner_master_pipe(crtc_state); 364 } 365 366 bool intel_crtc_is_bigjoiner_master(const struct intel_crtc_state *crtc_state) 367 { 368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 369 370 return crtc_state->bigjoiner_pipes && 371 crtc->pipe == bigjoiner_master_pipe(crtc_state); 372 } 373 374 static int intel_bigjoiner_num_pipes(const struct intel_crtc_state *crtc_state) 375 { 376 return hweight8(crtc_state->bigjoiner_pipes); 377 } 378 379 struct intel_crtc *intel_master_crtc(const struct intel_crtc_state *crtc_state) 380 { 381 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 382 383 if (intel_crtc_is_bigjoiner_slave(crtc_state)) 384 return intel_crtc_for_pipe(i915, bigjoiner_master_pipe(crtc_state)); 385 else 386 return to_intel_crtc(crtc_state->uapi.crtc); 387 } 388 389 static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv, 390 enum pipe pipe) 391 { 392 i915_reg_t reg = PIPEDSL(pipe); 393 u32 line1, line2; 394 395 line1 = intel_de_read(dev_priv, reg) & PIPEDSL_LINE_MASK; 396 msleep(5); 397 line2 = intel_de_read(dev_priv, reg) & PIPEDSL_LINE_MASK; 398 399 return line1 != line2; 400 } 401 402 static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state) 403 { 404 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 405 enum pipe pipe = crtc->pipe; 406 407 /* Wait for the display line to settle/start moving */ 408 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100)) 409 drm_err(&dev_priv->drm, 410 "pipe %c scanline %s wait timed out\n", 411 pipe_name(pipe), str_on_off(state)); 412 } 413 414 static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc) 415 { 416 wait_for_pipe_scanline_moving(crtc, false); 417 } 418 419 static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc) 420 { 421 wait_for_pipe_scanline_moving(crtc, true); 422 } 423 424 static void 425 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state) 426 { 427 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 428 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 429 430 if (DISPLAY_VER(dev_priv) >= 4) { 431 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 432 433 /* Wait for the Pipe State to go off */ 434 if (intel_de_wait_for_clear(dev_priv, PIPECONF(cpu_transcoder), 435 PIPECONF_STATE_ENABLE, 100)) 436 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n"); 437 } else { 438 intel_wait_for_pipe_scanline_stopped(crtc); 439 } 440 } 441 442 void assert_transcoder(struct drm_i915_private *dev_priv, 443 enum transcoder cpu_transcoder, bool state) 444 { 445 bool cur_state; 446 enum intel_display_power_domain power_domain; 447 intel_wakeref_t wakeref; 448 449 /* we keep both pipes enabled on 830 */ 450 if (IS_I830(dev_priv)) 451 state = true; 452 453 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 454 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); 455 if (wakeref) { 456 u32 val = intel_de_read(dev_priv, PIPECONF(cpu_transcoder)); 457 cur_state = !!(val & PIPECONF_ENABLE); 458 459 intel_display_power_put(dev_priv, power_domain, wakeref); 460 } else { 461 cur_state = false; 462 } 463 464 I915_STATE_WARN(cur_state != state, 465 "transcoder %s assertion failure (expected %s, current %s)\n", 466 transcoder_name(cpu_transcoder), 467 str_on_off(state), str_on_off(cur_state)); 468 } 469 470 static void assert_plane(struct intel_plane *plane, bool state) 471 { 472 enum pipe pipe; 473 bool cur_state; 474 475 cur_state = plane->get_hw_state(plane, &pipe); 476 477 I915_STATE_WARN(cur_state != state, 478 "%s assertion failure (expected %s, current %s)\n", 479 plane->base.name, str_on_off(state), 480 str_on_off(cur_state)); 481 } 482 483 #define assert_plane_enabled(p) assert_plane(p, true) 484 #define assert_plane_disabled(p) assert_plane(p, false) 485 486 static void assert_planes_disabled(struct intel_crtc *crtc) 487 { 488 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 489 struct intel_plane *plane; 490 491 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) 492 assert_plane_disabled(plane); 493 } 494 495 void vlv_wait_port_ready(struct drm_i915_private *dev_priv, 496 struct intel_digital_port *dig_port, 497 unsigned int expected_mask) 498 { 499 u32 port_mask; 500 i915_reg_t dpll_reg; 501 502 switch (dig_port->base.port) { 503 default: 504 MISSING_CASE(dig_port->base.port); 505 fallthrough; 506 case PORT_B: 507 port_mask = DPLL_PORTB_READY_MASK; 508 dpll_reg = DPLL(0); 509 break; 510 case PORT_C: 511 port_mask = DPLL_PORTC_READY_MASK; 512 dpll_reg = DPLL(0); 513 expected_mask <<= 4; 514 break; 515 case PORT_D: 516 port_mask = DPLL_PORTD_READY_MASK; 517 dpll_reg = DPIO_PHY_STATUS; 518 break; 519 } 520 521 if (intel_de_wait_for_register(dev_priv, dpll_reg, 522 port_mask, expected_mask, 1000)) 523 drm_WARN(&dev_priv->drm, 1, 524 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n", 525 dig_port->base.base.base.id, dig_port->base.base.name, 526 intel_de_read(dev_priv, dpll_reg) & port_mask, 527 expected_mask); 528 } 529 530 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state) 531 { 532 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 533 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 534 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; 535 enum pipe pipe = crtc->pipe; 536 i915_reg_t reg; 537 u32 val; 538 539 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe)); 540 541 assert_planes_disabled(crtc); 542 543 /* 544 * A pipe without a PLL won't actually be able to drive bits from 545 * a plane. On ILK+ the pipe PLLs are integrated, so we don't 546 * need the check. 547 */ 548 if (HAS_GMCH(dev_priv)) { 549 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) 550 assert_dsi_pll_enabled(dev_priv); 551 else 552 assert_pll_enabled(dev_priv, pipe); 553 } else { 554 if (new_crtc_state->has_pch_encoder) { 555 /* if driving the PCH, we need FDI enabled */ 556 assert_fdi_rx_pll_enabled(dev_priv, 557 intel_crtc_pch_transcoder(crtc)); 558 assert_fdi_tx_pll_enabled(dev_priv, 559 (enum pipe) cpu_transcoder); 560 } 561 /* FIXME: assert CPU port conditions for SNB+ */ 562 } 563 564 /* Wa_22012358565:adl-p */ 565 if (DISPLAY_VER(dev_priv) == 13) 566 intel_de_rmw(dev_priv, PIPE_ARB_CTL(pipe), 567 0, PIPE_ARB_USE_PROG_SLOTS); 568 569 reg = PIPECONF(cpu_transcoder); 570 val = intel_de_read(dev_priv, reg); 571 if (val & PIPECONF_ENABLE) { 572 /* we keep both pipes enabled on 830 */ 573 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv)); 574 return; 575 } 576 577 intel_de_write(dev_priv, reg, val | PIPECONF_ENABLE); 578 intel_de_posting_read(dev_priv, reg); 579 580 /* 581 * Until the pipe starts PIPEDSL reads will return a stale value, 582 * which causes an apparent vblank timestamp jump when PIPEDSL 583 * resets to its proper value. That also messes up the frame count 584 * when it's derived from the timestamps. So let's wait for the 585 * pipe to start properly before we call drm_crtc_vblank_on() 586 */ 587 if (intel_crtc_max_vblank_count(new_crtc_state) == 0) 588 intel_wait_for_pipe_scanline_moving(crtc); 589 } 590 591 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state) 592 { 593 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 594 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 595 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 596 enum pipe pipe = crtc->pipe; 597 i915_reg_t reg; 598 u32 val; 599 600 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe)); 601 602 /* 603 * Make sure planes won't keep trying to pump pixels to us, 604 * or we might hang the display. 605 */ 606 assert_planes_disabled(crtc); 607 608 reg = PIPECONF(cpu_transcoder); 609 val = intel_de_read(dev_priv, reg); 610 if ((val & PIPECONF_ENABLE) == 0) 611 return; 612 613 /* 614 * Double wide has implications for planes 615 * so best keep it disabled when not needed. 616 */ 617 if (old_crtc_state->double_wide) 618 val &= ~PIPECONF_DOUBLE_WIDE; 619 620 /* Don't disable pipe or pipe PLLs if needed */ 621 if (!IS_I830(dev_priv)) 622 val &= ~PIPECONF_ENABLE; 623 624 if (DISPLAY_VER(dev_priv) >= 12) 625 intel_de_rmw(dev_priv, CHICKEN_TRANS(cpu_transcoder), 626 FECSTALL_DIS_DPTSTREAM_DPTTG, 0); 627 628 intel_de_write(dev_priv, reg, val); 629 if ((val & PIPECONF_ENABLE) == 0) 630 intel_wait_for_pipe_off(old_crtc_state); 631 } 632 633 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) 634 { 635 unsigned int size = 0; 636 int i; 637 638 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) 639 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width; 640 641 return size; 642 } 643 644 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info) 645 { 646 unsigned int size = 0; 647 int i; 648 649 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) { 650 unsigned int plane_size; 651 652 if (rem_info->plane[i].linear) 653 plane_size = rem_info->plane[i].size; 654 else 655 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height; 656 657 if (plane_size == 0) 658 continue; 659 660 if (rem_info->plane_alignment) 661 size = ALIGN(size, rem_info->plane_alignment); 662 663 size += plane_size; 664 } 665 666 return size; 667 } 668 669 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state) 670 { 671 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 672 struct drm_i915_private *dev_priv = to_i915(plane->base.dev); 673 674 return DISPLAY_VER(dev_priv) < 4 || 675 (plane->fbc && 676 plane_state->view.gtt.type == I915_GGTT_VIEW_NORMAL); 677 } 678 679 /* 680 * Convert the x/y offsets into a linear offset. 681 * Only valid with 0/180 degree rotation, which is fine since linear 682 * offset is only used with linear buffers on pre-hsw and tiled buffers 683 * with gen2/3, and 90/270 degree rotations isn't supported on any of them. 684 */ 685 u32 intel_fb_xy_to_linear(int x, int y, 686 const struct intel_plane_state *state, 687 int color_plane) 688 { 689 const struct drm_framebuffer *fb = state->hw.fb; 690 unsigned int cpp = fb->format->cpp[color_plane]; 691 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride; 692 693 return y * pitch + x * cpp; 694 } 695 696 /* 697 * Add the x/y offsets derived from fb->offsets[] to the user 698 * specified plane src x/y offsets. The resulting x/y offsets 699 * specify the start of scanout from the beginning of the gtt mapping. 700 */ 701 void intel_add_fb_offsets(int *x, int *y, 702 const struct intel_plane_state *state, 703 int color_plane) 704 705 { 706 *x += state->view.color_plane[color_plane].x; 707 *y += state->view.color_plane[color_plane].y; 708 } 709 710 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv, 711 u32 pixel_format, u64 modifier) 712 { 713 struct intel_crtc *crtc; 714 struct intel_plane *plane; 715 716 if (!HAS_DISPLAY(dev_priv)) 717 return 0; 718 719 /* 720 * We assume the primary plane for pipe A has 721 * the highest stride limits of them all, 722 * if in case pipe A is disabled, use the first pipe from pipe_mask. 723 */ 724 crtc = intel_first_crtc(dev_priv); 725 if (!crtc) 726 return 0; 727 728 plane = to_intel_plane(crtc->base.primary); 729 730 return plane->max_stride(plane, pixel_format, modifier, 731 DRM_MODE_ROTATE_0); 732 } 733 734 static void 735 intel_set_plane_visible(struct intel_crtc_state *crtc_state, 736 struct intel_plane_state *plane_state, 737 bool visible) 738 { 739 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 740 741 plane_state->uapi.visible = visible; 742 743 if (visible) 744 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base); 745 else 746 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base); 747 } 748 749 static void fixup_plane_bitmasks(struct intel_crtc_state *crtc_state) 750 { 751 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 752 struct drm_plane *plane; 753 754 /* 755 * Active_planes aliases if multiple "primary" or cursor planes 756 * have been used on the same (or wrong) pipe. plane_mask uses 757 * unique ids, hence we can use that to reconstruct active_planes. 758 */ 759 crtc_state->enabled_planes = 0; 760 crtc_state->active_planes = 0; 761 762 drm_for_each_plane_mask(plane, &dev_priv->drm, 763 crtc_state->uapi.plane_mask) { 764 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id); 765 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); 766 } 767 } 768 769 void intel_plane_disable_noatomic(struct intel_crtc *crtc, 770 struct intel_plane *plane) 771 { 772 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 773 struct intel_crtc_state *crtc_state = 774 to_intel_crtc_state(crtc->base.state); 775 struct intel_plane_state *plane_state = 776 to_intel_plane_state(plane->base.state); 777 778 drm_dbg_kms(&dev_priv->drm, 779 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", 780 plane->base.base.id, plane->base.name, 781 crtc->base.base.id, crtc->base.name); 782 783 intel_set_plane_visible(crtc_state, plane_state, false); 784 fixup_plane_bitmasks(crtc_state); 785 crtc_state->data_rate[plane->id] = 0; 786 crtc_state->data_rate_y[plane->id] = 0; 787 crtc_state->rel_data_rate[plane->id] = 0; 788 crtc_state->rel_data_rate_y[plane->id] = 0; 789 crtc_state->min_cdclk[plane->id] = 0; 790 791 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 && 792 hsw_ips_disable(crtc_state)) { 793 crtc_state->ips_enabled = false; 794 intel_crtc_wait_for_next_vblank(crtc); 795 } 796 797 /* 798 * Vblank time updates from the shadow to live plane control register 799 * are blocked if the memory self-refresh mode is active at that 800 * moment. So to make sure the plane gets truly disabled, disable 801 * first the self-refresh mode. The self-refresh enable bit in turn 802 * will be checked/applied by the HW only at the next frame start 803 * event which is after the vblank start event, so we need to have a 804 * wait-for-vblank between disabling the plane and the pipe. 805 */ 806 if (HAS_GMCH(dev_priv) && 807 intel_set_memory_cxsr(dev_priv, false)) 808 intel_crtc_wait_for_next_vblank(crtc); 809 810 /* 811 * Gen2 reports pipe underruns whenever all planes are disabled. 812 * So disable underrun reporting before all the planes get disabled. 813 */ 814 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes) 815 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false); 816 817 intel_plane_disable_arm(plane, crtc_state); 818 intel_crtc_wait_for_next_vblank(crtc); 819 } 820 821 unsigned int 822 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state) 823 { 824 int x = 0, y = 0; 825 826 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, 827 plane_state->view.color_plane[0].offset, 0); 828 829 return y; 830 } 831 832 static int 833 __intel_display_resume(struct drm_device *dev, 834 struct drm_atomic_state *state, 835 struct drm_modeset_acquire_ctx *ctx) 836 { 837 struct drm_crtc_state *crtc_state; 838 struct drm_crtc *crtc; 839 int i, ret; 840 841 intel_modeset_setup_hw_state(dev, ctx); 842 intel_vga_redisable(to_i915(dev)); 843 844 if (!state) 845 return 0; 846 847 /* 848 * We've duplicated the state, pointers to the old state are invalid. 849 * 850 * Don't attempt to use the old state until we commit the duplicated state. 851 */ 852 for_each_new_crtc_in_state(state, crtc, crtc_state, i) { 853 /* 854 * Force recalculation even if we restore 855 * current state. With fast modeset this may not result 856 * in a modeset when the state is compatible. 857 */ 858 crtc_state->mode_changed = true; 859 } 860 861 /* ignore any reset values/BIOS leftovers in the WM registers */ 862 if (!HAS_GMCH(to_i915(dev))) 863 to_intel_atomic_state(state)->skip_intermediate_wm = true; 864 865 ret = drm_atomic_helper_commit_duplicated_state(state, ctx); 866 867 drm_WARN_ON(dev, ret == -EDEADLK); 868 return ret; 869 } 870 871 static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) 872 { 873 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display && 874 intel_has_gpu_reset(to_gt(dev_priv))); 875 } 876 877 void intel_display_prepare_reset(struct drm_i915_private *dev_priv) 878 { 879 struct drm_device *dev = &dev_priv->drm; 880 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; 881 struct drm_atomic_state *state; 882 int ret; 883 884 if (!HAS_DISPLAY(dev_priv)) 885 return; 886 887 /* reset doesn't touch the display */ 888 if (!dev_priv->params.force_reset_modeset_test && 889 !gpu_reset_clobbers_display(dev_priv)) 890 return; 891 892 /* We have a modeset vs reset deadlock, defensively unbreak it. */ 893 set_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags); 894 smp_mb__after_atomic(); 895 wake_up_bit(&to_gt(dev_priv)->reset.flags, I915_RESET_MODESET); 896 897 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) { 898 drm_dbg_kms(&dev_priv->drm, 899 "Modeset potentially stuck, unbreaking through wedging\n"); 900 intel_gt_set_wedged(to_gt(dev_priv)); 901 } 902 903 /* 904 * Need mode_config.mutex so that we don't 905 * trample ongoing ->detect() and whatnot. 906 */ 907 mutex_lock(&dev->mode_config.mutex); 908 drm_modeset_acquire_init(ctx, 0); 909 while (1) { 910 ret = drm_modeset_lock_all_ctx(dev, ctx); 911 if (ret != -EDEADLK) 912 break; 913 914 drm_modeset_backoff(ctx); 915 } 916 /* 917 * Disabling the crtcs gracefully seems nicer. Also the 918 * g33 docs say we should at least disable all the planes. 919 */ 920 state = drm_atomic_helper_duplicate_state(dev, ctx); 921 if (IS_ERR(state)) { 922 ret = PTR_ERR(state); 923 drm_err(&dev_priv->drm, "Duplicating state failed with %i\n", 924 ret); 925 return; 926 } 927 928 ret = drm_atomic_helper_disable_all(dev, ctx); 929 if (ret) { 930 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n", 931 ret); 932 drm_atomic_state_put(state); 933 return; 934 } 935 936 dev_priv->modeset_restore_state = state; 937 state->acquire_ctx = ctx; 938 } 939 940 void intel_display_finish_reset(struct drm_i915_private *dev_priv) 941 { 942 struct drm_device *dev = &dev_priv->drm; 943 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; 944 struct drm_atomic_state *state; 945 int ret; 946 947 if (!HAS_DISPLAY(dev_priv)) 948 return; 949 950 /* reset doesn't touch the display */ 951 if (!test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags)) 952 return; 953 954 state = fetch_and_zero(&dev_priv->modeset_restore_state); 955 if (!state) 956 goto unlock; 957 958 /* reset doesn't touch the display */ 959 if (!gpu_reset_clobbers_display(dev_priv)) { 960 /* for testing only restore the display */ 961 ret = __intel_display_resume(dev, state, ctx); 962 if (ret) 963 drm_err(&dev_priv->drm, 964 "Restoring old state failed with %i\n", ret); 965 } else { 966 /* 967 * The display has been reset as well, 968 * so need a full re-initialization. 969 */ 970 intel_pps_unlock_regs_wa(dev_priv); 971 intel_modeset_init_hw(dev_priv); 972 intel_init_clock_gating(dev_priv); 973 intel_hpd_init(dev_priv); 974 975 ret = __intel_display_resume(dev, state, ctx); 976 if (ret) 977 drm_err(&dev_priv->drm, 978 "Restoring old state failed with %i\n", ret); 979 980 intel_hpd_poll_disable(dev_priv); 981 } 982 983 drm_atomic_state_put(state); 984 unlock: 985 drm_modeset_drop_locks(ctx); 986 drm_modeset_acquire_fini(ctx); 987 mutex_unlock(&dev->mode_config.mutex); 988 989 clear_bit_unlock(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags); 990 } 991 992 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state) 993 { 994 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 995 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 996 enum pipe pipe = crtc->pipe; 997 u32 tmp; 998 999 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe)); 1000 1001 /* 1002 * Display WA #1153: icl 1003 * enable hardware to bypass the alpha math 1004 * and rounding for per-pixel values 00 and 0xff 1005 */ 1006 tmp |= PER_PIXEL_ALPHA_BYPASS_EN; 1007 /* 1008 * Display WA # 1605353570: icl 1009 * Set the pixel rounding bit to 1 for allowing 1010 * passthrough of Frame buffer pixels unmodified 1011 * across pipe 1012 */ 1013 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU; 1014 1015 /* 1016 * Underrun recovery must always be disabled on display 13+. 1017 * DG2 chicken bit meaning is inverted compared to other platforms. 1018 */ 1019 if (IS_DG2(dev_priv)) 1020 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2; 1021 else if (DISPLAY_VER(dev_priv) >= 13) 1022 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP; 1023 1024 /* Wa_14010547955:dg2 */ 1025 if (IS_DG2_DISPLAY_STEP(dev_priv, STEP_B0, STEP_FOREVER)) 1026 tmp |= DG2_RENDER_CCSTAG_4_3_EN; 1027 1028 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp); 1029 } 1030 1031 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) 1032 { 1033 struct drm_crtc *crtc; 1034 bool cleanup_done; 1035 1036 drm_for_each_crtc(crtc, &dev_priv->drm) { 1037 struct drm_crtc_commit *commit; 1038 spin_lock(&crtc->commit_lock); 1039 commit = list_first_entry_or_null(&crtc->commit_list, 1040 struct drm_crtc_commit, commit_entry); 1041 cleanup_done = commit ? 1042 try_wait_for_completion(&commit->cleanup_done) : true; 1043 spin_unlock(&crtc->commit_lock); 1044 1045 if (cleanup_done) 1046 continue; 1047 1048 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc)); 1049 1050 return true; 1051 } 1052 1053 return false; 1054 } 1055 1056 /* 1057 * Finds the encoder associated with the given CRTC. This can only be 1058 * used when we know that the CRTC isn't feeding multiple encoders! 1059 */ 1060 struct intel_encoder * 1061 intel_get_crtc_new_encoder(const struct intel_atomic_state *state, 1062 const struct intel_crtc_state *crtc_state) 1063 { 1064 const struct drm_connector_state *connector_state; 1065 const struct drm_connector *connector; 1066 struct intel_encoder *encoder = NULL; 1067 struct intel_crtc *master_crtc; 1068 int num_encoders = 0; 1069 int i; 1070 1071 master_crtc = intel_master_crtc(crtc_state); 1072 1073 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 1074 if (connector_state->crtc != &master_crtc->base) 1075 continue; 1076 1077 encoder = to_intel_encoder(connector_state->best_encoder); 1078 num_encoders++; 1079 } 1080 1081 drm_WARN(encoder->base.dev, num_encoders != 1, 1082 "%d encoders for pipe %c\n", 1083 num_encoders, pipe_name(master_crtc->pipe)); 1084 1085 return encoder; 1086 } 1087 1088 static void cpt_verify_modeset(struct drm_i915_private *dev_priv, 1089 enum pipe pipe) 1090 { 1091 i915_reg_t dslreg = PIPEDSL(pipe); 1092 u32 temp; 1093 1094 temp = intel_de_read(dev_priv, dslreg); 1095 udelay(500); 1096 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) { 1097 if (wait_for(intel_de_read(dev_priv, dslreg) != temp, 5)) 1098 drm_err(&dev_priv->drm, 1099 "mode set failed: pipe %c stuck\n", 1100 pipe_name(pipe)); 1101 } 1102 } 1103 1104 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state) 1105 { 1106 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1107 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1108 const struct drm_rect *dst = &crtc_state->pch_pfit.dst; 1109 enum pipe pipe = crtc->pipe; 1110 int width = drm_rect_width(dst); 1111 int height = drm_rect_height(dst); 1112 int x = dst->x1; 1113 int y = dst->y1; 1114 1115 if (!crtc_state->pch_pfit.enabled) 1116 return; 1117 1118 /* Force use of hard-coded filter coefficients 1119 * as some pre-programmed values are broken, 1120 * e.g. x201. 1121 */ 1122 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) 1123 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE | 1124 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe)); 1125 else 1126 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE | 1127 PF_FILTER_MED_3x3); 1128 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), x << 16 | y); 1129 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), width << 16 | height); 1130 } 1131 1132 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc) 1133 { 1134 if (crtc->overlay) 1135 (void) intel_overlay_switch_off(crtc->overlay); 1136 1137 /* Let userspace switch the overlay on again. In most cases userspace 1138 * has to recompute where to put it anyway. 1139 */ 1140 } 1141 1142 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state) 1143 { 1144 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 1145 1146 if (!crtc_state->nv12_planes) 1147 return false; 1148 1149 /* WA Display #0827: Gen9:all */ 1150 if (DISPLAY_VER(dev_priv) == 9) 1151 return true; 1152 1153 return false; 1154 } 1155 1156 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state) 1157 { 1158 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 1159 1160 /* Wa_2006604312:icl,ehl */ 1161 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11) 1162 return true; 1163 1164 return false; 1165 } 1166 1167 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state) 1168 { 1169 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 1170 1171 /* Wa_1604331009:icl,jsl,ehl */ 1172 if (is_hdr_mode(crtc_state) && 1173 crtc_state->active_planes & BIT(PLANE_CURSOR) && 1174 DISPLAY_VER(dev_priv) == 11) 1175 return true; 1176 1177 return false; 1178 } 1179 1180 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915, 1181 enum pipe pipe, bool enable) 1182 { 1183 if (DISPLAY_VER(i915) == 9) { 1184 /* 1185 * "Plane N strech max must be programmed to 11b (x1) 1186 * when Async flips are enabled on that plane." 1187 */ 1188 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe), 1189 SKL_PLANE1_STRETCH_MAX_MASK, 1190 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8); 1191 } else { 1192 /* Also needed on HSW/BDW albeit undocumented */ 1193 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe), 1194 HSW_PRI_STRETCH_MAX_MASK, 1195 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8); 1196 } 1197 } 1198 1199 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state) 1200 { 1201 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 1202 1203 return crtc_state->uapi.async_flip && i915_vtd_active(i915) && 1204 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915)); 1205 } 1206 1207 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state, 1208 const struct intel_crtc_state *new_crtc_state) 1209 { 1210 return (!old_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)) && 1211 new_crtc_state->active_planes; 1212 } 1213 1214 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state, 1215 const struct intel_crtc_state *new_crtc_state) 1216 { 1217 return old_crtc_state->active_planes && 1218 (!new_crtc_state->active_planes || intel_crtc_needs_modeset(new_crtc_state)); 1219 } 1220 1221 static void intel_post_plane_update(struct intel_atomic_state *state, 1222 struct intel_crtc *crtc) 1223 { 1224 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 1225 const struct intel_crtc_state *old_crtc_state = 1226 intel_atomic_get_old_crtc_state(state, crtc); 1227 const struct intel_crtc_state *new_crtc_state = 1228 intel_atomic_get_new_crtc_state(state, crtc); 1229 enum pipe pipe = crtc->pipe; 1230 1231 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits); 1232 1233 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active) 1234 intel_update_watermarks(dev_priv); 1235 1236 hsw_ips_post_update(state, crtc); 1237 intel_fbc_post_update(state, crtc); 1238 1239 if (needs_async_flip_vtd_wa(old_crtc_state) && 1240 !needs_async_flip_vtd_wa(new_crtc_state)) 1241 intel_async_flip_vtd_wa(dev_priv, pipe, false); 1242 1243 if (needs_nv12_wa(old_crtc_state) && 1244 !needs_nv12_wa(new_crtc_state)) 1245 skl_wa_827(dev_priv, pipe, false); 1246 1247 if (needs_scalerclk_wa(old_crtc_state) && 1248 !needs_scalerclk_wa(new_crtc_state)) 1249 icl_wa_scalerclkgating(dev_priv, pipe, false); 1250 1251 if (needs_cursorclk_wa(old_crtc_state) && 1252 !needs_cursorclk_wa(new_crtc_state)) 1253 icl_wa_cursorclkgating(dev_priv, pipe, false); 1254 1255 intel_drrs_activate(new_crtc_state); 1256 } 1257 1258 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state, 1259 struct intel_crtc *crtc) 1260 { 1261 const struct intel_crtc_state *crtc_state = 1262 intel_atomic_get_new_crtc_state(state, crtc); 1263 u8 update_planes = crtc_state->update_planes; 1264 const struct intel_plane_state *plane_state; 1265 struct intel_plane *plane; 1266 int i; 1267 1268 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 1269 if (plane->pipe == crtc->pipe && 1270 update_planes & BIT(plane->id)) 1271 plane->enable_flip_done(plane); 1272 } 1273 } 1274 1275 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state, 1276 struct intel_crtc *crtc) 1277 { 1278 const struct intel_crtc_state *crtc_state = 1279 intel_atomic_get_new_crtc_state(state, crtc); 1280 u8 update_planes = crtc_state->update_planes; 1281 const struct intel_plane_state *plane_state; 1282 struct intel_plane *plane; 1283 int i; 1284 1285 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 1286 if (plane->pipe == crtc->pipe && 1287 update_planes & BIT(plane->id)) 1288 plane->disable_flip_done(plane); 1289 } 1290 } 1291 1292 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state, 1293 struct intel_crtc *crtc) 1294 { 1295 const struct intel_crtc_state *old_crtc_state = 1296 intel_atomic_get_old_crtc_state(state, crtc); 1297 const struct intel_crtc_state *new_crtc_state = 1298 intel_atomic_get_new_crtc_state(state, crtc); 1299 u8 update_planes = new_crtc_state->update_planes; 1300 const struct intel_plane_state *old_plane_state; 1301 struct intel_plane *plane; 1302 bool need_vbl_wait = false; 1303 int i; 1304 1305 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { 1306 if (plane->need_async_flip_disable_wa && 1307 plane->pipe == crtc->pipe && 1308 update_planes & BIT(plane->id)) { 1309 /* 1310 * Apart from the async flip bit we want to 1311 * preserve the old state for the plane. 1312 */ 1313 plane->async_flip(plane, old_crtc_state, 1314 old_plane_state, false); 1315 need_vbl_wait = true; 1316 } 1317 } 1318 1319 if (need_vbl_wait) 1320 intel_crtc_wait_for_next_vblank(crtc); 1321 } 1322 1323 static void intel_pre_plane_update(struct intel_atomic_state *state, 1324 struct intel_crtc *crtc) 1325 { 1326 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 1327 const struct intel_crtc_state *old_crtc_state = 1328 intel_atomic_get_old_crtc_state(state, crtc); 1329 const struct intel_crtc_state *new_crtc_state = 1330 intel_atomic_get_new_crtc_state(state, crtc); 1331 enum pipe pipe = crtc->pipe; 1332 1333 intel_drrs_deactivate(old_crtc_state); 1334 1335 intel_psr_pre_plane_update(state, crtc); 1336 1337 if (hsw_ips_pre_update(state, crtc)) 1338 intel_crtc_wait_for_next_vblank(crtc); 1339 1340 if (intel_fbc_pre_update(state, crtc)) 1341 intel_crtc_wait_for_next_vblank(crtc); 1342 1343 if (!needs_async_flip_vtd_wa(old_crtc_state) && 1344 needs_async_flip_vtd_wa(new_crtc_state)) 1345 intel_async_flip_vtd_wa(dev_priv, pipe, true); 1346 1347 /* Display WA 827 */ 1348 if (!needs_nv12_wa(old_crtc_state) && 1349 needs_nv12_wa(new_crtc_state)) 1350 skl_wa_827(dev_priv, pipe, true); 1351 1352 /* Wa_2006604312:icl,ehl */ 1353 if (!needs_scalerclk_wa(old_crtc_state) && 1354 needs_scalerclk_wa(new_crtc_state)) 1355 icl_wa_scalerclkgating(dev_priv, pipe, true); 1356 1357 /* Wa_1604331009:icl,jsl,ehl */ 1358 if (!needs_cursorclk_wa(old_crtc_state) && 1359 needs_cursorclk_wa(new_crtc_state)) 1360 icl_wa_cursorclkgating(dev_priv, pipe, true); 1361 1362 /* 1363 * Vblank time updates from the shadow to live plane control register 1364 * are blocked if the memory self-refresh mode is active at that 1365 * moment. So to make sure the plane gets truly disabled, disable 1366 * first the self-refresh mode. The self-refresh enable bit in turn 1367 * will be checked/applied by the HW only at the next frame start 1368 * event which is after the vblank start event, so we need to have a 1369 * wait-for-vblank between disabling the plane and the pipe. 1370 */ 1371 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active && 1372 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false)) 1373 intel_crtc_wait_for_next_vblank(crtc); 1374 1375 /* 1376 * IVB workaround: must disable low power watermarks for at least 1377 * one frame before enabling scaling. LP watermarks can be re-enabled 1378 * when scaling is disabled. 1379 * 1380 * WaCxSRDisabledForSpriteScaling:ivb 1381 */ 1382 if (old_crtc_state->hw.active && 1383 new_crtc_state->disable_lp_wm && ilk_disable_lp_wm(dev_priv)) 1384 intel_crtc_wait_for_next_vblank(crtc); 1385 1386 /* 1387 * If we're doing a modeset we don't need to do any 1388 * pre-vblank watermark programming here. 1389 */ 1390 if (!intel_crtc_needs_modeset(new_crtc_state)) { 1391 /* 1392 * For platforms that support atomic watermarks, program the 1393 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these 1394 * will be the intermediate values that are safe for both pre- and 1395 * post- vblank; when vblank happens, the 'active' values will be set 1396 * to the final 'target' values and we'll do this again to get the 1397 * optimal watermarks. For gen9+ platforms, the values we program here 1398 * will be the final target values which will get automatically latched 1399 * at vblank time; no further programming will be necessary. 1400 * 1401 * If a platform hasn't been transitioned to atomic watermarks yet, 1402 * we'll continue to update watermarks the old way, if flags tell 1403 * us to. 1404 */ 1405 if (!intel_initial_watermarks(state, crtc)) 1406 if (new_crtc_state->update_wm_pre) 1407 intel_update_watermarks(dev_priv); 1408 } 1409 1410 /* 1411 * Gen2 reports pipe underruns whenever all planes are disabled. 1412 * So disable underrun reporting before all the planes get disabled. 1413 * 1414 * We do this after .initial_watermarks() so that we have a 1415 * chance of catching underruns with the intermediate watermarks 1416 * vs. the old plane configuration. 1417 */ 1418 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state)) 1419 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); 1420 1421 /* 1422 * WA for platforms where async address update enable bit 1423 * is double buffered and only latched at start of vblank. 1424 */ 1425 if (old_crtc_state->uapi.async_flip && !new_crtc_state->uapi.async_flip) 1426 intel_crtc_async_flip_disable_wa(state, crtc); 1427 } 1428 1429 static void intel_crtc_disable_planes(struct intel_atomic_state *state, 1430 struct intel_crtc *crtc) 1431 { 1432 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1433 const struct intel_crtc_state *new_crtc_state = 1434 intel_atomic_get_new_crtc_state(state, crtc); 1435 unsigned int update_mask = new_crtc_state->update_planes; 1436 const struct intel_plane_state *old_plane_state; 1437 struct intel_plane *plane; 1438 unsigned fb_bits = 0; 1439 int i; 1440 1441 intel_crtc_dpms_overlay_disable(crtc); 1442 1443 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { 1444 if (crtc->pipe != plane->pipe || 1445 !(update_mask & BIT(plane->id))) 1446 continue; 1447 1448 intel_plane_disable_arm(plane, new_crtc_state); 1449 1450 if (old_plane_state->uapi.visible) 1451 fb_bits |= plane->frontbuffer_bit; 1452 } 1453 1454 intel_frontbuffer_flip(dev_priv, fb_bits); 1455 } 1456 1457 /* 1458 * intel_connector_primary_encoder - get the primary encoder for a connector 1459 * @connector: connector for which to return the encoder 1460 * 1461 * Returns the primary encoder for a connector. There is a 1:1 mapping from 1462 * all connectors to their encoder, except for DP-MST connectors which have 1463 * both a virtual and a primary encoder. These DP-MST primary encoders can be 1464 * pointed to by as many DP-MST connectors as there are pipes. 1465 */ 1466 static struct intel_encoder * 1467 intel_connector_primary_encoder(struct intel_connector *connector) 1468 { 1469 struct intel_encoder *encoder; 1470 1471 if (connector->mst_port) 1472 return &dp_to_dig_port(connector->mst_port)->base; 1473 1474 encoder = intel_attached_encoder(connector); 1475 drm_WARN_ON(connector->base.dev, !encoder); 1476 1477 return encoder; 1478 } 1479 1480 static void intel_encoders_update_prepare(struct intel_atomic_state *state) 1481 { 1482 struct drm_i915_private *i915 = to_i915(state->base.dev); 1483 struct intel_crtc_state *new_crtc_state, *old_crtc_state; 1484 struct intel_crtc *crtc; 1485 struct drm_connector_state *new_conn_state; 1486 struct drm_connector *connector; 1487 int i; 1488 1489 /* 1490 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits. 1491 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook. 1492 */ 1493 if (i915->dpll.mgr) { 1494 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 1495 if (intel_crtc_needs_modeset(new_crtc_state)) 1496 continue; 1497 1498 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll; 1499 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state; 1500 } 1501 } 1502 1503 if (!state->modeset) 1504 return; 1505 1506 for_each_new_connector_in_state(&state->base, connector, new_conn_state, 1507 i) { 1508 struct intel_connector *intel_connector; 1509 struct intel_encoder *encoder; 1510 struct intel_crtc *crtc; 1511 1512 if (!intel_connector_needs_modeset(state, connector)) 1513 continue; 1514 1515 intel_connector = to_intel_connector(connector); 1516 encoder = intel_connector_primary_encoder(intel_connector); 1517 if (!encoder->update_prepare) 1518 continue; 1519 1520 crtc = new_conn_state->crtc ? 1521 to_intel_crtc(new_conn_state->crtc) : NULL; 1522 encoder->update_prepare(state, encoder, crtc); 1523 } 1524 } 1525 1526 static void intel_encoders_update_complete(struct intel_atomic_state *state) 1527 { 1528 struct drm_connector_state *new_conn_state; 1529 struct drm_connector *connector; 1530 int i; 1531 1532 if (!state->modeset) 1533 return; 1534 1535 for_each_new_connector_in_state(&state->base, connector, new_conn_state, 1536 i) { 1537 struct intel_connector *intel_connector; 1538 struct intel_encoder *encoder; 1539 struct intel_crtc *crtc; 1540 1541 if (!intel_connector_needs_modeset(state, connector)) 1542 continue; 1543 1544 intel_connector = to_intel_connector(connector); 1545 encoder = intel_connector_primary_encoder(intel_connector); 1546 if (!encoder->update_complete) 1547 continue; 1548 1549 crtc = new_conn_state->crtc ? 1550 to_intel_crtc(new_conn_state->crtc) : NULL; 1551 encoder->update_complete(state, encoder, crtc); 1552 } 1553 } 1554 1555 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state, 1556 struct intel_crtc *crtc) 1557 { 1558 const struct intel_crtc_state *crtc_state = 1559 intel_atomic_get_new_crtc_state(state, crtc); 1560 const struct drm_connector_state *conn_state; 1561 struct drm_connector *conn; 1562 int i; 1563 1564 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1565 struct intel_encoder *encoder = 1566 to_intel_encoder(conn_state->best_encoder); 1567 1568 if (conn_state->crtc != &crtc->base) 1569 continue; 1570 1571 if (encoder->pre_pll_enable) 1572 encoder->pre_pll_enable(state, encoder, 1573 crtc_state, conn_state); 1574 } 1575 } 1576 1577 static void intel_encoders_pre_enable(struct intel_atomic_state *state, 1578 struct intel_crtc *crtc) 1579 { 1580 const struct intel_crtc_state *crtc_state = 1581 intel_atomic_get_new_crtc_state(state, crtc); 1582 const struct drm_connector_state *conn_state; 1583 struct drm_connector *conn; 1584 int i; 1585 1586 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1587 struct intel_encoder *encoder = 1588 to_intel_encoder(conn_state->best_encoder); 1589 1590 if (conn_state->crtc != &crtc->base) 1591 continue; 1592 1593 if (encoder->pre_enable) 1594 encoder->pre_enable(state, encoder, 1595 crtc_state, conn_state); 1596 } 1597 } 1598 1599 static void intel_encoders_enable(struct intel_atomic_state *state, 1600 struct intel_crtc *crtc) 1601 { 1602 const struct intel_crtc_state *crtc_state = 1603 intel_atomic_get_new_crtc_state(state, crtc); 1604 const struct drm_connector_state *conn_state; 1605 struct drm_connector *conn; 1606 int i; 1607 1608 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1609 struct intel_encoder *encoder = 1610 to_intel_encoder(conn_state->best_encoder); 1611 1612 if (conn_state->crtc != &crtc->base) 1613 continue; 1614 1615 if (encoder->enable) 1616 encoder->enable(state, encoder, 1617 crtc_state, conn_state); 1618 intel_opregion_notify_encoder(encoder, true); 1619 } 1620 } 1621 1622 static void intel_encoders_disable(struct intel_atomic_state *state, 1623 struct intel_crtc *crtc) 1624 { 1625 const struct intel_crtc_state *old_crtc_state = 1626 intel_atomic_get_old_crtc_state(state, crtc); 1627 const struct drm_connector_state *old_conn_state; 1628 struct drm_connector *conn; 1629 int i; 1630 1631 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1632 struct intel_encoder *encoder = 1633 to_intel_encoder(old_conn_state->best_encoder); 1634 1635 if (old_conn_state->crtc != &crtc->base) 1636 continue; 1637 1638 intel_opregion_notify_encoder(encoder, false); 1639 if (encoder->disable) 1640 encoder->disable(state, encoder, 1641 old_crtc_state, old_conn_state); 1642 } 1643 } 1644 1645 static void intel_encoders_post_disable(struct intel_atomic_state *state, 1646 struct intel_crtc *crtc) 1647 { 1648 const struct intel_crtc_state *old_crtc_state = 1649 intel_atomic_get_old_crtc_state(state, crtc); 1650 const struct drm_connector_state *old_conn_state; 1651 struct drm_connector *conn; 1652 int i; 1653 1654 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1655 struct intel_encoder *encoder = 1656 to_intel_encoder(old_conn_state->best_encoder); 1657 1658 if (old_conn_state->crtc != &crtc->base) 1659 continue; 1660 1661 if (encoder->post_disable) 1662 encoder->post_disable(state, encoder, 1663 old_crtc_state, old_conn_state); 1664 } 1665 } 1666 1667 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state, 1668 struct intel_crtc *crtc) 1669 { 1670 const struct intel_crtc_state *old_crtc_state = 1671 intel_atomic_get_old_crtc_state(state, crtc); 1672 const struct drm_connector_state *old_conn_state; 1673 struct drm_connector *conn; 1674 int i; 1675 1676 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1677 struct intel_encoder *encoder = 1678 to_intel_encoder(old_conn_state->best_encoder); 1679 1680 if (old_conn_state->crtc != &crtc->base) 1681 continue; 1682 1683 if (encoder->post_pll_disable) 1684 encoder->post_pll_disable(state, encoder, 1685 old_crtc_state, old_conn_state); 1686 } 1687 } 1688 1689 static void intel_encoders_update_pipe(struct intel_atomic_state *state, 1690 struct intel_crtc *crtc) 1691 { 1692 const struct intel_crtc_state *crtc_state = 1693 intel_atomic_get_new_crtc_state(state, crtc); 1694 const struct drm_connector_state *conn_state; 1695 struct drm_connector *conn; 1696 int i; 1697 1698 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1699 struct intel_encoder *encoder = 1700 to_intel_encoder(conn_state->best_encoder); 1701 1702 if (conn_state->crtc != &crtc->base) 1703 continue; 1704 1705 if (encoder->update_pipe) 1706 encoder->update_pipe(state, encoder, 1707 crtc_state, conn_state); 1708 } 1709 } 1710 1711 static void intel_disable_primary_plane(const struct intel_crtc_state *crtc_state) 1712 { 1713 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1714 struct intel_plane *plane = to_intel_plane(crtc->base.primary); 1715 1716 plane->disable_arm(plane, crtc_state); 1717 } 1718 1719 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 1720 { 1721 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1722 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1723 1724 if (crtc_state->has_pch_encoder) { 1725 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1726 &crtc_state->fdi_m_n); 1727 } else if (intel_crtc_has_dp_encoder(crtc_state)) { 1728 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1729 &crtc_state->dp_m_n); 1730 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 1731 &crtc_state->dp_m2_n2); 1732 } 1733 1734 intel_set_transcoder_timings(crtc_state); 1735 1736 ilk_set_pipeconf(crtc_state); 1737 } 1738 1739 static void ilk_crtc_enable(struct intel_atomic_state *state, 1740 struct intel_crtc *crtc) 1741 { 1742 const struct intel_crtc_state *new_crtc_state = 1743 intel_atomic_get_new_crtc_state(state, crtc); 1744 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1745 enum pipe pipe = crtc->pipe; 1746 1747 if (drm_WARN_ON(&dev_priv->drm, crtc->active)) 1748 return; 1749 1750 /* 1751 * Sometimes spurious CPU pipe underruns happen during FDI 1752 * training, at least with VGA+HDMI cloning. Suppress them. 1753 * 1754 * On ILK we get an occasional spurious CPU pipe underruns 1755 * between eDP port A enable and vdd enable. Also PCH port 1756 * enable seems to result in the occasional CPU pipe underrun. 1757 * 1758 * Spurious PCH underruns also occur during PCH enabling. 1759 */ 1760 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); 1761 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); 1762 1763 ilk_configure_cpu_transcoder(new_crtc_state); 1764 1765 intel_set_pipe_src_size(new_crtc_state); 1766 1767 crtc->active = true; 1768 1769 intel_encoders_pre_enable(state, crtc); 1770 1771 if (new_crtc_state->has_pch_encoder) { 1772 ilk_pch_pre_enable(state, crtc); 1773 } else { 1774 assert_fdi_tx_disabled(dev_priv, pipe); 1775 assert_fdi_rx_disabled(dev_priv, pipe); 1776 } 1777 1778 ilk_pfit_enable(new_crtc_state); 1779 1780 /* 1781 * On ILK+ LUT must be loaded before the pipe is running but with 1782 * clocks enabled 1783 */ 1784 intel_color_load_luts(new_crtc_state); 1785 intel_color_commit_noarm(new_crtc_state); 1786 intel_color_commit_arm(new_crtc_state); 1787 /* update DSPCNTR to configure gamma for pipe bottom color */ 1788 intel_disable_primary_plane(new_crtc_state); 1789 1790 intel_initial_watermarks(state, crtc); 1791 intel_enable_transcoder(new_crtc_state); 1792 1793 if (new_crtc_state->has_pch_encoder) 1794 ilk_pch_enable(state, crtc); 1795 1796 intel_crtc_vblank_on(new_crtc_state); 1797 1798 intel_encoders_enable(state, crtc); 1799 1800 if (HAS_PCH_CPT(dev_priv)) 1801 cpt_verify_modeset(dev_priv, pipe); 1802 1803 /* 1804 * Must wait for vblank to avoid spurious PCH FIFO underruns. 1805 * And a second vblank wait is needed at least on ILK with 1806 * some interlaced HDMI modes. Let's do the double wait always 1807 * in case there are more corner cases we don't know about. 1808 */ 1809 if (new_crtc_state->has_pch_encoder) { 1810 intel_crtc_wait_for_next_vblank(crtc); 1811 intel_crtc_wait_for_next_vblank(crtc); 1812 } 1813 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 1814 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); 1815 } 1816 1817 static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv, 1818 enum pipe pipe, bool apply) 1819 { 1820 u32 val = intel_de_read(dev_priv, CLKGATE_DIS_PSL(pipe)); 1821 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; 1822 1823 if (apply) 1824 val |= mask; 1825 else 1826 val &= ~mask; 1827 1828 intel_de_write(dev_priv, CLKGATE_DIS_PSL(pipe), val); 1829 } 1830 1831 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state) 1832 { 1833 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1834 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1835 1836 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe), 1837 HSW_LINETIME(crtc_state->linetime) | 1838 HSW_IPS_LINETIME(crtc_state->ips_linetime)); 1839 } 1840 1841 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state) 1842 { 1843 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1844 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1845 i915_reg_t reg = CHICKEN_TRANS(crtc_state->cpu_transcoder); 1846 u32 val; 1847 1848 val = intel_de_read(dev_priv, reg); 1849 val &= ~HSW_FRAME_START_DELAY_MASK; 1850 val |= HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1); 1851 intel_de_write(dev_priv, reg, val); 1852 } 1853 1854 static void icl_ddi_bigjoiner_pre_enable(struct intel_atomic_state *state, 1855 const struct intel_crtc_state *crtc_state) 1856 { 1857 struct intel_crtc *master_crtc = intel_master_crtc(crtc_state); 1858 1859 /* 1860 * Enable sequence steps 1-7 on bigjoiner master 1861 */ 1862 if (intel_crtc_is_bigjoiner_slave(crtc_state)) 1863 intel_encoders_pre_pll_enable(state, master_crtc); 1864 1865 if (crtc_state->shared_dpll) 1866 intel_enable_shared_dpll(crtc_state); 1867 1868 if (intel_crtc_is_bigjoiner_slave(crtc_state)) 1869 intel_encoders_pre_enable(state, master_crtc); 1870 } 1871 1872 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 1873 { 1874 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1875 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1876 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1877 1878 if (crtc_state->has_pch_encoder) { 1879 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1880 &crtc_state->fdi_m_n); 1881 } else if (intel_crtc_has_dp_encoder(crtc_state)) { 1882 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1883 &crtc_state->dp_m_n); 1884 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 1885 &crtc_state->dp_m2_n2); 1886 } 1887 1888 intel_set_transcoder_timings(crtc_state); 1889 1890 if (cpu_transcoder != TRANSCODER_EDP) 1891 intel_de_write(dev_priv, PIPE_MULT(cpu_transcoder), 1892 crtc_state->pixel_multiplier - 1); 1893 1894 hsw_set_frame_start_delay(crtc_state); 1895 1896 hsw_set_transconf(crtc_state); 1897 } 1898 1899 static void hsw_crtc_enable(struct intel_atomic_state *state, 1900 struct intel_crtc *crtc) 1901 { 1902 const struct intel_crtc_state *new_crtc_state = 1903 intel_atomic_get_new_crtc_state(state, crtc); 1904 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1905 enum pipe pipe = crtc->pipe, hsw_workaround_pipe; 1906 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; 1907 bool psl_clkgate_wa; 1908 1909 if (drm_WARN_ON(&dev_priv->drm, crtc->active)) 1910 return; 1911 1912 if (!new_crtc_state->bigjoiner_pipes) { 1913 intel_encoders_pre_pll_enable(state, crtc); 1914 1915 if (new_crtc_state->shared_dpll) 1916 intel_enable_shared_dpll(new_crtc_state); 1917 1918 intel_encoders_pre_enable(state, crtc); 1919 } else { 1920 icl_ddi_bigjoiner_pre_enable(state, new_crtc_state); 1921 } 1922 1923 intel_dsc_enable(new_crtc_state); 1924 1925 if (DISPLAY_VER(dev_priv) >= 13) 1926 intel_uncompressed_joiner_enable(new_crtc_state); 1927 1928 intel_set_pipe_src_size(new_crtc_state); 1929 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) 1930 bdw_set_pipemisc(new_crtc_state); 1931 1932 if (!intel_crtc_is_bigjoiner_slave(new_crtc_state) && 1933 !transcoder_is_dsi(cpu_transcoder)) 1934 hsw_configure_cpu_transcoder(new_crtc_state); 1935 1936 crtc->active = true; 1937 1938 /* Display WA #1180: WaDisableScalarClockGating: glk */ 1939 psl_clkgate_wa = DISPLAY_VER(dev_priv) == 10 && 1940 new_crtc_state->pch_pfit.enabled; 1941 if (psl_clkgate_wa) 1942 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true); 1943 1944 if (DISPLAY_VER(dev_priv) >= 9) 1945 skl_pfit_enable(new_crtc_state); 1946 else 1947 ilk_pfit_enable(new_crtc_state); 1948 1949 /* 1950 * On ILK+ LUT must be loaded before the pipe is running but with 1951 * clocks enabled 1952 */ 1953 intel_color_load_luts(new_crtc_state); 1954 intel_color_commit_noarm(new_crtc_state); 1955 intel_color_commit_arm(new_crtc_state); 1956 /* update DSPCNTR to configure gamma/csc for pipe bottom color */ 1957 if (DISPLAY_VER(dev_priv) < 9) 1958 intel_disable_primary_plane(new_crtc_state); 1959 1960 hsw_set_linetime_wm(new_crtc_state); 1961 1962 if (DISPLAY_VER(dev_priv) >= 11) 1963 icl_set_pipe_chicken(new_crtc_state); 1964 1965 intel_initial_watermarks(state, crtc); 1966 1967 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) 1968 intel_crtc_vblank_on(new_crtc_state); 1969 1970 intel_encoders_enable(state, crtc); 1971 1972 if (psl_clkgate_wa) { 1973 intel_crtc_wait_for_next_vblank(crtc); 1974 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false); 1975 } 1976 1977 /* If we change the relative order between pipe/planes enabling, we need 1978 * to change the workaround. */ 1979 hsw_workaround_pipe = new_crtc_state->hsw_workaround_pipe; 1980 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { 1981 struct intel_crtc *wa_crtc; 1982 1983 wa_crtc = intel_crtc_for_pipe(dev_priv, hsw_workaround_pipe); 1984 1985 intel_crtc_wait_for_next_vblank(wa_crtc); 1986 intel_crtc_wait_for_next_vblank(wa_crtc); 1987 } 1988 } 1989 1990 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state) 1991 { 1992 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 1993 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1994 enum pipe pipe = crtc->pipe; 1995 1996 /* To avoid upsetting the power well on haswell only disable the pfit if 1997 * it's in use. The hw state code will make sure we get this right. */ 1998 if (!old_crtc_state->pch_pfit.enabled) 1999 return; 2000 2001 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0); 2002 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0); 2003 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0); 2004 } 2005 2006 static void ilk_crtc_disable(struct intel_atomic_state *state, 2007 struct intel_crtc *crtc) 2008 { 2009 const struct intel_crtc_state *old_crtc_state = 2010 intel_atomic_get_old_crtc_state(state, crtc); 2011 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2012 enum pipe pipe = crtc->pipe; 2013 2014 /* 2015 * Sometimes spurious CPU pipe underruns happen when the 2016 * pipe is already disabled, but FDI RX/TX is still enabled. 2017 * Happens at least with VGA+HDMI cloning. Suppress them. 2018 */ 2019 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); 2020 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); 2021 2022 intel_encoders_disable(state, crtc); 2023 2024 intel_crtc_vblank_off(old_crtc_state); 2025 2026 intel_disable_transcoder(old_crtc_state); 2027 2028 ilk_pfit_disable(old_crtc_state); 2029 2030 if (old_crtc_state->has_pch_encoder) 2031 ilk_pch_disable(state, crtc); 2032 2033 intel_encoders_post_disable(state, crtc); 2034 2035 if (old_crtc_state->has_pch_encoder) 2036 ilk_pch_post_disable(state, crtc); 2037 2038 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 2039 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); 2040 } 2041 2042 static void hsw_crtc_disable(struct intel_atomic_state *state, 2043 struct intel_crtc *crtc) 2044 { 2045 const struct intel_crtc_state *old_crtc_state = 2046 intel_atomic_get_old_crtc_state(state, crtc); 2047 2048 /* 2049 * FIXME collapse everything to one hook. 2050 * Need care with mst->ddi interactions. 2051 */ 2052 if (!intel_crtc_is_bigjoiner_slave(old_crtc_state)) { 2053 intel_encoders_disable(state, crtc); 2054 intel_encoders_post_disable(state, crtc); 2055 } 2056 } 2057 2058 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state) 2059 { 2060 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2061 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2062 2063 if (!crtc_state->gmch_pfit.control) 2064 return; 2065 2066 /* 2067 * The panel fitter should only be adjusted whilst the pipe is disabled, 2068 * according to register description and PRM. 2069 */ 2070 drm_WARN_ON(&dev_priv->drm, 2071 intel_de_read(dev_priv, PFIT_CONTROL) & PFIT_ENABLE); 2072 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder); 2073 2074 intel_de_write(dev_priv, PFIT_PGM_RATIOS, 2075 crtc_state->gmch_pfit.pgm_ratios); 2076 intel_de_write(dev_priv, PFIT_CONTROL, crtc_state->gmch_pfit.control); 2077 2078 /* Border color in case we don't scale up to the full screen. Black by 2079 * default, change to something else for debugging. */ 2080 intel_de_write(dev_priv, BCLRPAT(crtc->pipe), 0); 2081 } 2082 2083 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy) 2084 { 2085 if (phy == PHY_NONE) 2086 return false; 2087 else if (IS_DG2(dev_priv)) 2088 /* 2089 * DG2 outputs labelled as "combo PHY" in the bspec use 2090 * SNPS PHYs with completely different programming, 2091 * hence we always return false here. 2092 */ 2093 return false; 2094 else if (IS_ALDERLAKE_S(dev_priv)) 2095 return phy <= PHY_E; 2096 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) 2097 return phy <= PHY_D; 2098 else if (IS_JSL_EHL(dev_priv)) 2099 return phy <= PHY_C; 2100 else if (DISPLAY_VER(dev_priv) >= 11) 2101 return phy <= PHY_B; 2102 else 2103 return false; 2104 } 2105 2106 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy) 2107 { 2108 if (IS_DG2(dev_priv)) 2109 /* DG2's "TC1" output uses a SNPS PHY */ 2110 return false; 2111 else if (IS_ALDERLAKE_P(dev_priv)) 2112 return phy >= PHY_F && phy <= PHY_I; 2113 else if (IS_TIGERLAKE(dev_priv)) 2114 return phy >= PHY_D && phy <= PHY_I; 2115 else if (IS_ICELAKE(dev_priv)) 2116 return phy >= PHY_C && phy <= PHY_F; 2117 else 2118 return false; 2119 } 2120 2121 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy) 2122 { 2123 if (phy == PHY_NONE) 2124 return false; 2125 else if (IS_DG2(dev_priv)) 2126 /* 2127 * All four "combo" ports and the TC1 port (PHY E) use 2128 * Synopsis PHYs. 2129 */ 2130 return phy <= PHY_E; 2131 2132 return false; 2133 } 2134 2135 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port) 2136 { 2137 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD) 2138 return PHY_D + port - PORT_D_XELPD; 2139 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1) 2140 return PHY_F + port - PORT_TC1; 2141 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1) 2142 return PHY_B + port - PORT_TC1; 2143 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1) 2144 return PHY_C + port - PORT_TC1; 2145 else if (IS_JSL_EHL(i915) && port == PORT_D) 2146 return PHY_A; 2147 2148 return PHY_A + port - PORT_A; 2149 } 2150 2151 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port) 2152 { 2153 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port))) 2154 return TC_PORT_NONE; 2155 2156 if (DISPLAY_VER(dev_priv) >= 12) 2157 return TC_PORT_1 + port - PORT_TC1; 2158 else 2159 return TC_PORT_1 + port - PORT_C; 2160 } 2161 2162 enum intel_display_power_domain 2163 intel_aux_power_domain(struct intel_digital_port *dig_port) 2164 { 2165 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); 2166 2167 if (intel_tc_port_in_tbt_alt_mode(dig_port)) 2168 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch); 2169 2170 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch); 2171 } 2172 2173 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state, 2174 struct intel_power_domain_mask *mask) 2175 { 2176 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2177 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2178 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2179 struct drm_encoder *encoder; 2180 enum pipe pipe = crtc->pipe; 2181 2182 bitmap_zero(mask->bits, POWER_DOMAIN_NUM); 2183 2184 if (!crtc_state->hw.active) 2185 return; 2186 2187 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits); 2188 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits); 2189 if (crtc_state->pch_pfit.enabled || 2190 crtc_state->pch_pfit.force_thru) 2191 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits); 2192 2193 drm_for_each_encoder_mask(encoder, &dev_priv->drm, 2194 crtc_state->uapi.encoder_mask) { 2195 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 2196 2197 set_bit(intel_encoder->power_domain, mask->bits); 2198 } 2199 2200 if (HAS_DDI(dev_priv) && crtc_state->has_audio) 2201 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits); 2202 2203 if (crtc_state->shared_dpll) 2204 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits); 2205 2206 if (crtc_state->dsc.compression_enable) 2207 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits); 2208 } 2209 2210 static void 2211 modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state, 2212 struct intel_power_domain_mask *old_domains) 2213 { 2214 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2215 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2216 enum intel_display_power_domain domain; 2217 struct intel_power_domain_mask domains, new_domains; 2218 2219 get_crtc_power_domains(crtc_state, &domains); 2220 2221 bitmap_andnot(new_domains.bits, 2222 domains.bits, 2223 crtc->enabled_power_domains.mask.bits, 2224 POWER_DOMAIN_NUM); 2225 bitmap_andnot(old_domains->bits, 2226 crtc->enabled_power_domains.mask.bits, 2227 domains.bits, 2228 POWER_DOMAIN_NUM); 2229 2230 for_each_power_domain(domain, &new_domains) 2231 intel_display_power_get_in_set(dev_priv, 2232 &crtc->enabled_power_domains, 2233 domain); 2234 } 2235 2236 static void modeset_put_crtc_power_domains(struct intel_crtc *crtc, 2237 struct intel_power_domain_mask *domains) 2238 { 2239 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev), 2240 &crtc->enabled_power_domains, 2241 domains); 2242 } 2243 2244 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 2245 { 2246 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2247 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2248 2249 if (intel_crtc_has_dp_encoder(crtc_state)) { 2250 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 2251 &crtc_state->dp_m_n); 2252 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 2253 &crtc_state->dp_m2_n2); 2254 } 2255 2256 intel_set_transcoder_timings(crtc_state); 2257 2258 i9xx_set_pipeconf(crtc_state); 2259 } 2260 2261 static void valleyview_crtc_enable(struct intel_atomic_state *state, 2262 struct intel_crtc *crtc) 2263 { 2264 const struct intel_crtc_state *new_crtc_state = 2265 intel_atomic_get_new_crtc_state(state, crtc); 2266 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2267 enum pipe pipe = crtc->pipe; 2268 2269 if (drm_WARN_ON(&dev_priv->drm, crtc->active)) 2270 return; 2271 2272 i9xx_configure_cpu_transcoder(new_crtc_state); 2273 2274 intel_set_pipe_src_size(new_crtc_state); 2275 2276 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { 2277 intel_de_write(dev_priv, CHV_BLEND(pipe), CHV_BLEND_LEGACY); 2278 intel_de_write(dev_priv, CHV_CANVAS(pipe), 0); 2279 } 2280 2281 crtc->active = true; 2282 2283 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 2284 2285 intel_encoders_pre_pll_enable(state, crtc); 2286 2287 if (IS_CHERRYVIEW(dev_priv)) 2288 chv_enable_pll(new_crtc_state); 2289 else 2290 vlv_enable_pll(new_crtc_state); 2291 2292 intel_encoders_pre_enable(state, crtc); 2293 2294 i9xx_pfit_enable(new_crtc_state); 2295 2296 intel_color_load_luts(new_crtc_state); 2297 intel_color_commit_noarm(new_crtc_state); 2298 intel_color_commit_arm(new_crtc_state); 2299 /* update DSPCNTR to configure gamma for pipe bottom color */ 2300 intel_disable_primary_plane(new_crtc_state); 2301 2302 intel_initial_watermarks(state, crtc); 2303 intel_enable_transcoder(new_crtc_state); 2304 2305 intel_crtc_vblank_on(new_crtc_state); 2306 2307 intel_encoders_enable(state, crtc); 2308 } 2309 2310 static void i9xx_crtc_enable(struct intel_atomic_state *state, 2311 struct intel_crtc *crtc) 2312 { 2313 const struct intel_crtc_state *new_crtc_state = 2314 intel_atomic_get_new_crtc_state(state, crtc); 2315 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2316 enum pipe pipe = crtc->pipe; 2317 2318 if (drm_WARN_ON(&dev_priv->drm, crtc->active)) 2319 return; 2320 2321 i9xx_configure_cpu_transcoder(new_crtc_state); 2322 2323 intel_set_pipe_src_size(new_crtc_state); 2324 2325 crtc->active = true; 2326 2327 if (DISPLAY_VER(dev_priv) != 2) 2328 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 2329 2330 intel_encoders_pre_enable(state, crtc); 2331 2332 i9xx_enable_pll(new_crtc_state); 2333 2334 i9xx_pfit_enable(new_crtc_state); 2335 2336 intel_color_load_luts(new_crtc_state); 2337 intel_color_commit_noarm(new_crtc_state); 2338 intel_color_commit_arm(new_crtc_state); 2339 /* update DSPCNTR to configure gamma for pipe bottom color */ 2340 intel_disable_primary_plane(new_crtc_state); 2341 2342 if (!intel_initial_watermarks(state, crtc)) 2343 intel_update_watermarks(dev_priv); 2344 intel_enable_transcoder(new_crtc_state); 2345 2346 intel_crtc_vblank_on(new_crtc_state); 2347 2348 intel_encoders_enable(state, crtc); 2349 2350 /* prevents spurious underruns */ 2351 if (DISPLAY_VER(dev_priv) == 2) 2352 intel_crtc_wait_for_next_vblank(crtc); 2353 } 2354 2355 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state) 2356 { 2357 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 2358 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2359 2360 if (!old_crtc_state->gmch_pfit.control) 2361 return; 2362 2363 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder); 2364 2365 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n", 2366 intel_de_read(dev_priv, PFIT_CONTROL)); 2367 intel_de_write(dev_priv, PFIT_CONTROL, 0); 2368 } 2369 2370 static void i9xx_crtc_disable(struct intel_atomic_state *state, 2371 struct intel_crtc *crtc) 2372 { 2373 struct intel_crtc_state *old_crtc_state = 2374 intel_atomic_get_old_crtc_state(state, crtc); 2375 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2376 enum pipe pipe = crtc->pipe; 2377 2378 /* 2379 * On gen2 planes are double buffered but the pipe isn't, so we must 2380 * wait for planes to fully turn off before disabling the pipe. 2381 */ 2382 if (DISPLAY_VER(dev_priv) == 2) 2383 intel_crtc_wait_for_next_vblank(crtc); 2384 2385 intel_encoders_disable(state, crtc); 2386 2387 intel_crtc_vblank_off(old_crtc_state); 2388 2389 intel_disable_transcoder(old_crtc_state); 2390 2391 i9xx_pfit_disable(old_crtc_state); 2392 2393 intel_encoders_post_disable(state, crtc); 2394 2395 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { 2396 if (IS_CHERRYVIEW(dev_priv)) 2397 chv_disable_pll(dev_priv, pipe); 2398 else if (IS_VALLEYVIEW(dev_priv)) 2399 vlv_disable_pll(dev_priv, pipe); 2400 else 2401 i9xx_disable_pll(old_crtc_state); 2402 } 2403 2404 intel_encoders_post_pll_disable(state, crtc); 2405 2406 if (DISPLAY_VER(dev_priv) != 2) 2407 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); 2408 2409 if (!dev_priv->wm_disp->initial_watermarks) 2410 intel_update_watermarks(dev_priv); 2411 2412 /* clock the pipe down to 640x480@60 to potentially save power */ 2413 if (IS_I830(dev_priv)) 2414 i830_enable_pipe(dev_priv, pipe); 2415 } 2416 2417 static void intel_crtc_disable_noatomic(struct intel_crtc *crtc, 2418 struct drm_modeset_acquire_ctx *ctx) 2419 { 2420 struct intel_encoder *encoder; 2421 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2422 struct intel_bw_state *bw_state = 2423 to_intel_bw_state(dev_priv->bw_obj.state); 2424 struct intel_cdclk_state *cdclk_state = 2425 to_intel_cdclk_state(dev_priv->cdclk.obj.state); 2426 struct intel_dbuf_state *dbuf_state = 2427 to_intel_dbuf_state(dev_priv->dbuf.obj.state); 2428 struct intel_crtc_state *crtc_state = 2429 to_intel_crtc_state(crtc->base.state); 2430 struct intel_plane *plane; 2431 struct drm_atomic_state *state; 2432 struct intel_crtc_state *temp_crtc_state; 2433 enum pipe pipe = crtc->pipe; 2434 int ret; 2435 2436 if (!crtc_state->hw.active) 2437 return; 2438 2439 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { 2440 const struct intel_plane_state *plane_state = 2441 to_intel_plane_state(plane->base.state); 2442 2443 if (plane_state->uapi.visible) 2444 intel_plane_disable_noatomic(crtc, plane); 2445 } 2446 2447 state = drm_atomic_state_alloc(&dev_priv->drm); 2448 if (!state) { 2449 drm_dbg_kms(&dev_priv->drm, 2450 "failed to disable [CRTC:%d:%s], out of memory", 2451 crtc->base.base.id, crtc->base.name); 2452 return; 2453 } 2454 2455 state->acquire_ctx = ctx; 2456 2457 /* Everything's already locked, -EDEADLK can't happen. */ 2458 temp_crtc_state = intel_atomic_get_crtc_state(state, crtc); 2459 ret = drm_atomic_add_affected_connectors(state, &crtc->base); 2460 2461 drm_WARN_ON(&dev_priv->drm, IS_ERR(temp_crtc_state) || ret); 2462 2463 dev_priv->display->crtc_disable(to_intel_atomic_state(state), crtc); 2464 2465 drm_atomic_state_put(state); 2466 2467 drm_dbg_kms(&dev_priv->drm, 2468 "[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", 2469 crtc->base.base.id, crtc->base.name); 2470 2471 crtc->active = false; 2472 crtc->base.enabled = false; 2473 2474 drm_WARN_ON(&dev_priv->drm, 2475 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, NULL) < 0); 2476 crtc_state->uapi.active = false; 2477 crtc_state->uapi.connector_mask = 0; 2478 crtc_state->uapi.encoder_mask = 0; 2479 intel_crtc_free_hw_state(crtc_state); 2480 memset(&crtc_state->hw, 0, sizeof(crtc_state->hw)); 2481 2482 for_each_encoder_on_crtc(&dev_priv->drm, &crtc->base, encoder) 2483 encoder->base.crtc = NULL; 2484 2485 intel_fbc_disable(crtc); 2486 intel_update_watermarks(dev_priv); 2487 intel_disable_shared_dpll(crtc_state); 2488 2489 intel_display_power_put_all_in_set(dev_priv, &crtc->enabled_power_domains); 2490 2491 cdclk_state->min_cdclk[pipe] = 0; 2492 cdclk_state->min_voltage_level[pipe] = 0; 2493 cdclk_state->active_pipes &= ~BIT(pipe); 2494 2495 dbuf_state->active_pipes &= ~BIT(pipe); 2496 2497 bw_state->data_rate[pipe] = 0; 2498 bw_state->num_active_planes[pipe] = 0; 2499 } 2500 2501 /* 2502 * turn all crtc's off, but do not adjust state 2503 * This has to be paired with a call to intel_modeset_setup_hw_state. 2504 */ 2505 int intel_display_suspend(struct drm_device *dev) 2506 { 2507 struct drm_i915_private *dev_priv = to_i915(dev); 2508 struct drm_atomic_state *state; 2509 int ret; 2510 2511 if (!HAS_DISPLAY(dev_priv)) 2512 return 0; 2513 2514 state = drm_atomic_helper_suspend(dev); 2515 ret = PTR_ERR_OR_ZERO(state); 2516 if (ret) 2517 drm_err(&dev_priv->drm, "Suspending crtc's failed with %i\n", 2518 ret); 2519 else 2520 dev_priv->modeset_restore_state = state; 2521 return ret; 2522 } 2523 2524 void intel_encoder_destroy(struct drm_encoder *encoder) 2525 { 2526 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 2527 2528 drm_encoder_cleanup(encoder); 2529 kfree(intel_encoder); 2530 } 2531 2532 /* Cross check the actual hw state with our own modeset state tracking (and it's 2533 * internal consistency). */ 2534 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state, 2535 struct drm_connector_state *conn_state) 2536 { 2537 struct intel_connector *connector = to_intel_connector(conn_state->connector); 2538 struct drm_i915_private *i915 = to_i915(connector->base.dev); 2539 2540 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n", 2541 connector->base.base.id, connector->base.name); 2542 2543 if (connector->get_hw_state(connector)) { 2544 struct intel_encoder *encoder = intel_attached_encoder(connector); 2545 2546 I915_STATE_WARN(!crtc_state, 2547 "connector enabled without attached crtc\n"); 2548 2549 if (!crtc_state) 2550 return; 2551 2552 I915_STATE_WARN(!crtc_state->hw.active, 2553 "connector is active, but attached crtc isn't\n"); 2554 2555 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) 2556 return; 2557 2558 I915_STATE_WARN(conn_state->best_encoder != &encoder->base, 2559 "atomic encoder doesn't match attached encoder\n"); 2560 2561 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, 2562 "attached encoder crtc differs from connector crtc\n"); 2563 } else { 2564 I915_STATE_WARN(crtc_state && crtc_state->hw.active, 2565 "attached crtc is active, but connector isn't\n"); 2566 I915_STATE_WARN(!crtc_state && conn_state->best_encoder, 2567 "best encoder set without crtc!\n"); 2568 } 2569 } 2570 2571 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) 2572 { 2573 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2574 2575 /* GDG double wide on either pipe, otherwise pipe A only */ 2576 return DISPLAY_VER(dev_priv) < 4 && 2577 (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); 2578 } 2579 2580 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state) 2581 { 2582 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock; 2583 struct drm_rect src; 2584 2585 /* 2586 * We only use IF-ID interlacing. If we ever use 2587 * PF-ID we'll need to adjust the pixel_rate here. 2588 */ 2589 2590 if (!crtc_state->pch_pfit.enabled) 2591 return pixel_rate; 2592 2593 drm_rect_init(&src, 0, 0, 2594 drm_rect_width(&crtc_state->pipe_src) << 16, 2595 drm_rect_height(&crtc_state->pipe_src) << 16); 2596 2597 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst, 2598 pixel_rate); 2599 } 2600 2601 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode, 2602 const struct drm_display_mode *timings) 2603 { 2604 mode->hdisplay = timings->crtc_hdisplay; 2605 mode->htotal = timings->crtc_htotal; 2606 mode->hsync_start = timings->crtc_hsync_start; 2607 mode->hsync_end = timings->crtc_hsync_end; 2608 2609 mode->vdisplay = timings->crtc_vdisplay; 2610 mode->vtotal = timings->crtc_vtotal; 2611 mode->vsync_start = timings->crtc_vsync_start; 2612 mode->vsync_end = timings->crtc_vsync_end; 2613 2614 mode->flags = timings->flags; 2615 mode->type = DRM_MODE_TYPE_DRIVER; 2616 2617 mode->clock = timings->crtc_clock; 2618 2619 drm_mode_set_name(mode); 2620 } 2621 2622 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) 2623 { 2624 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 2625 2626 if (HAS_GMCH(dev_priv)) 2627 /* FIXME calculate proper pipe pixel rate for GMCH pfit */ 2628 crtc_state->pixel_rate = 2629 crtc_state->hw.pipe_mode.crtc_clock; 2630 else 2631 crtc_state->pixel_rate = 2632 ilk_pipe_pixel_rate(crtc_state); 2633 } 2634 2635 static void intel_bigjoiner_adjust_timings(const struct intel_crtc_state *crtc_state, 2636 struct drm_display_mode *mode) 2637 { 2638 int num_pipes = intel_bigjoiner_num_pipes(crtc_state); 2639 2640 if (num_pipes < 2) 2641 return; 2642 2643 mode->crtc_clock /= num_pipes; 2644 mode->crtc_hdisplay /= num_pipes; 2645 mode->crtc_hblank_start /= num_pipes; 2646 mode->crtc_hblank_end /= num_pipes; 2647 mode->crtc_hsync_start /= num_pipes; 2648 mode->crtc_hsync_end /= num_pipes; 2649 mode->crtc_htotal /= num_pipes; 2650 } 2651 2652 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state, 2653 struct drm_display_mode *mode) 2654 { 2655 int overlap = crtc_state->splitter.pixel_overlap; 2656 int n = crtc_state->splitter.link_count; 2657 2658 if (!crtc_state->splitter.enable) 2659 return; 2660 2661 /* 2662 * eDP MSO uses segment timings from EDID for transcoder 2663 * timings, but full mode for everything else. 2664 * 2665 * h_full = (h_segment - pixel_overlap) * link_count 2666 */ 2667 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n; 2668 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n; 2669 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n; 2670 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n; 2671 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n; 2672 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n; 2673 mode->crtc_clock *= n; 2674 } 2675 2676 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state) 2677 { 2678 struct drm_display_mode *mode = &crtc_state->hw.mode; 2679 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; 2680 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2681 2682 /* 2683 * Start with the adjusted_mode crtc timings, which 2684 * have been filled with the transcoder timings. 2685 */ 2686 drm_mode_copy(pipe_mode, adjusted_mode); 2687 2688 /* Expand MSO per-segment transcoder timings to full */ 2689 intel_splitter_adjust_timings(crtc_state, pipe_mode); 2690 2691 /* 2692 * We want the full numbers in adjusted_mode normal timings, 2693 * adjusted_mode crtc timings are left with the raw transcoder 2694 * timings. 2695 */ 2696 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode); 2697 2698 /* Populate the "user" mode with full numbers */ 2699 drm_mode_copy(mode, pipe_mode); 2700 intel_mode_from_crtc_timings(mode, mode); 2701 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) * 2702 (intel_bigjoiner_num_pipes(crtc_state) ?: 1); 2703 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src); 2704 2705 /* Derive per-pipe timings in case bigjoiner is used */ 2706 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode); 2707 intel_mode_from_crtc_timings(pipe_mode, pipe_mode); 2708 2709 intel_crtc_compute_pixel_rate(crtc_state); 2710 } 2711 2712 static void intel_encoder_get_config(struct intel_encoder *encoder, 2713 struct intel_crtc_state *crtc_state) 2714 { 2715 encoder->get_config(encoder, crtc_state); 2716 2717 intel_crtc_readout_derived_state(crtc_state); 2718 } 2719 2720 static void intel_bigjoiner_compute_pipe_src(struct intel_crtc_state *crtc_state) 2721 { 2722 int num_pipes = intel_bigjoiner_num_pipes(crtc_state); 2723 int width, height; 2724 2725 if (num_pipes < 2) 2726 return; 2727 2728 width = drm_rect_width(&crtc_state->pipe_src); 2729 height = drm_rect_height(&crtc_state->pipe_src); 2730 2731 drm_rect_init(&crtc_state->pipe_src, 0, 0, 2732 width / num_pipes, height); 2733 } 2734 2735 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state) 2736 { 2737 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2738 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 2739 2740 intel_bigjoiner_compute_pipe_src(crtc_state); 2741 2742 /* 2743 * Pipe horizontal size must be even in: 2744 * - DVO ganged mode 2745 * - LVDS dual channel mode 2746 * - Double wide pipe 2747 */ 2748 if (drm_rect_width(&crtc_state->pipe_src) & 1) { 2749 if (crtc_state->double_wide) { 2750 drm_dbg_kms(&i915->drm, 2751 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n", 2752 crtc->base.base.id, crtc->base.name); 2753 return -EINVAL; 2754 } 2755 2756 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && 2757 intel_is_dual_link_lvds(i915)) { 2758 drm_dbg_kms(&i915->drm, 2759 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n", 2760 crtc->base.base.id, crtc->base.name); 2761 return -EINVAL; 2762 } 2763 } 2764 2765 return 0; 2766 } 2767 2768 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state) 2769 { 2770 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2771 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 2772 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2773 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; 2774 int clock_limit = i915->max_dotclk_freq; 2775 2776 /* 2777 * Start with the adjusted_mode crtc timings, which 2778 * have been filled with the transcoder timings. 2779 */ 2780 drm_mode_copy(pipe_mode, adjusted_mode); 2781 2782 /* Expand MSO per-segment transcoder timings to full */ 2783 intel_splitter_adjust_timings(crtc_state, pipe_mode); 2784 2785 /* Derive per-pipe timings in case bigjoiner is used */ 2786 intel_bigjoiner_adjust_timings(crtc_state, pipe_mode); 2787 intel_mode_from_crtc_timings(pipe_mode, pipe_mode); 2788 2789 if (DISPLAY_VER(i915) < 4) { 2790 clock_limit = i915->max_cdclk_freq * 9 / 10; 2791 2792 /* 2793 * Enable double wide mode when the dot clock 2794 * is > 90% of the (display) core speed. 2795 */ 2796 if (intel_crtc_supports_double_wide(crtc) && 2797 pipe_mode->crtc_clock > clock_limit) { 2798 clock_limit = i915->max_dotclk_freq; 2799 crtc_state->double_wide = true; 2800 } 2801 } 2802 2803 if (pipe_mode->crtc_clock > clock_limit) { 2804 drm_dbg_kms(&i915->drm, 2805 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", 2806 crtc->base.base.id, crtc->base.name, 2807 pipe_mode->crtc_clock, clock_limit, 2808 str_yes_no(crtc_state->double_wide)); 2809 return -EINVAL; 2810 } 2811 2812 return 0; 2813 } 2814 2815 static int intel_crtc_compute_config(struct intel_atomic_state *state, 2816 struct intel_crtc *crtc) 2817 { 2818 struct intel_crtc_state *crtc_state = 2819 intel_atomic_get_new_crtc_state(state, crtc); 2820 int ret; 2821 2822 ret = intel_crtc_compute_pipe_src(crtc_state); 2823 if (ret) 2824 return ret; 2825 2826 ret = intel_crtc_compute_pipe_mode(crtc_state); 2827 if (ret) 2828 return ret; 2829 2830 intel_crtc_compute_pixel_rate(crtc_state); 2831 2832 if (crtc_state->has_pch_encoder) 2833 return ilk_fdi_compute_config(crtc, crtc_state); 2834 2835 return 0; 2836 } 2837 2838 static void 2839 intel_reduce_m_n_ratio(u32 *num, u32 *den) 2840 { 2841 while (*num > DATA_LINK_M_N_MASK || 2842 *den > DATA_LINK_M_N_MASK) { 2843 *num >>= 1; 2844 *den >>= 1; 2845 } 2846 } 2847 2848 static void compute_m_n(unsigned int m, unsigned int n, 2849 u32 *ret_m, u32 *ret_n, 2850 bool constant_n) 2851 { 2852 /* 2853 * Several DP dongles in particular seem to be fussy about 2854 * too large link M/N values. Give N value as 0x8000 that 2855 * should be acceptable by specific devices. 0x8000 is the 2856 * specified fixed N value for asynchronous clock mode, 2857 * which the devices expect also in synchronous clock mode. 2858 */ 2859 if (constant_n) 2860 *ret_n = DP_LINK_CONSTANT_N_VALUE; 2861 else 2862 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); 2863 2864 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n); 2865 intel_reduce_m_n_ratio(ret_m, ret_n); 2866 } 2867 2868 void 2869 intel_link_compute_m_n(u16 bits_per_pixel, int nlanes, 2870 int pixel_clock, int link_clock, 2871 struct intel_link_m_n *m_n, 2872 bool constant_n, bool fec_enable) 2873 { 2874 u32 data_clock = bits_per_pixel * pixel_clock; 2875 2876 if (fec_enable) 2877 data_clock = intel_dp_mode_to_fec_clock(data_clock); 2878 2879 m_n->tu = 64; 2880 compute_m_n(data_clock, 2881 link_clock * nlanes * 8, 2882 &m_n->data_m, &m_n->data_n, 2883 constant_n); 2884 2885 compute_m_n(pixel_clock, link_clock, 2886 &m_n->link_m, &m_n->link_n, 2887 constant_n); 2888 } 2889 2890 static void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv) 2891 { 2892 /* 2893 * There may be no VBT; and if the BIOS enabled SSC we can 2894 * just keep using it to avoid unnecessary flicker. Whereas if the 2895 * BIOS isn't using it, don't assume it will work even if the VBT 2896 * indicates as much. 2897 */ 2898 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { 2899 bool bios_lvds_use_ssc = intel_de_read(dev_priv, 2900 PCH_DREF_CONTROL) & 2901 DREF_SSC1_ENABLE; 2902 2903 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { 2904 drm_dbg_kms(&dev_priv->drm, 2905 "SSC %s by BIOS, overriding VBT which says %s\n", 2906 str_enabled_disabled(bios_lvds_use_ssc), 2907 str_enabled_disabled(dev_priv->vbt.lvds_use_ssc)); 2908 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; 2909 } 2910 } 2911 } 2912 2913 void intel_zero_m_n(struct intel_link_m_n *m_n) 2914 { 2915 /* corresponds to 0 register value */ 2916 memset(m_n, 0, sizeof(*m_n)); 2917 m_n->tu = 1; 2918 } 2919 2920 void intel_set_m_n(struct drm_i915_private *i915, 2921 const struct intel_link_m_n *m_n, 2922 i915_reg_t data_m_reg, i915_reg_t data_n_reg, 2923 i915_reg_t link_m_reg, i915_reg_t link_n_reg) 2924 { 2925 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m); 2926 intel_de_write(i915, data_n_reg, m_n->data_n); 2927 intel_de_write(i915, link_m_reg, m_n->link_m); 2928 /* 2929 * On BDW+ writing LINK_N arms the double buffered update 2930 * of all the M/N registers, so it must be written last. 2931 */ 2932 intel_de_write(i915, link_n_reg, m_n->link_n); 2933 } 2934 2935 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv, 2936 enum transcoder transcoder) 2937 { 2938 if (IS_HASWELL(dev_priv)) 2939 return transcoder == TRANSCODER_EDP; 2940 2941 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv); 2942 } 2943 2944 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc, 2945 enum transcoder transcoder, 2946 const struct intel_link_m_n *m_n) 2947 { 2948 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2949 enum pipe pipe = crtc->pipe; 2950 2951 if (DISPLAY_VER(dev_priv) >= 5) 2952 intel_set_m_n(dev_priv, m_n, 2953 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder), 2954 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder)); 2955 else 2956 intel_set_m_n(dev_priv, m_n, 2957 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe), 2958 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe)); 2959 } 2960 2961 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc, 2962 enum transcoder transcoder, 2963 const struct intel_link_m_n *m_n) 2964 { 2965 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2966 2967 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder)) 2968 return; 2969 2970 intel_set_m_n(dev_priv, m_n, 2971 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder), 2972 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder)); 2973 } 2974 2975 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state) 2976 { 2977 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2978 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2979 enum pipe pipe = crtc->pipe; 2980 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2981 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2982 u32 crtc_vtotal, crtc_vblank_end; 2983 int vsyncshift = 0; 2984 2985 /* We need to be careful not to changed the adjusted mode, for otherwise 2986 * the hw state checker will get angry at the mismatch. */ 2987 crtc_vtotal = adjusted_mode->crtc_vtotal; 2988 crtc_vblank_end = adjusted_mode->crtc_vblank_end; 2989 2990 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { 2991 /* the chip adds 2 halflines automatically */ 2992 crtc_vtotal -= 1; 2993 crtc_vblank_end -= 1; 2994 2995 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 2996 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; 2997 else 2998 vsyncshift = adjusted_mode->crtc_hsync_start - 2999 adjusted_mode->crtc_htotal / 2; 3000 if (vsyncshift < 0) 3001 vsyncshift += adjusted_mode->crtc_htotal; 3002 } 3003 3004 if (DISPLAY_VER(dev_priv) > 3) 3005 intel_de_write(dev_priv, VSYNCSHIFT(cpu_transcoder), 3006 vsyncshift); 3007 3008 intel_de_write(dev_priv, HTOTAL(cpu_transcoder), 3009 (adjusted_mode->crtc_hdisplay - 1) | ((adjusted_mode->crtc_htotal - 1) << 16)); 3010 intel_de_write(dev_priv, HBLANK(cpu_transcoder), 3011 (adjusted_mode->crtc_hblank_start - 1) | ((adjusted_mode->crtc_hblank_end - 1) << 16)); 3012 intel_de_write(dev_priv, HSYNC(cpu_transcoder), 3013 (adjusted_mode->crtc_hsync_start - 1) | ((adjusted_mode->crtc_hsync_end - 1) << 16)); 3014 3015 intel_de_write(dev_priv, VTOTAL(cpu_transcoder), 3016 (adjusted_mode->crtc_vdisplay - 1) | ((crtc_vtotal - 1) << 16)); 3017 intel_de_write(dev_priv, VBLANK(cpu_transcoder), 3018 (adjusted_mode->crtc_vblank_start - 1) | ((crtc_vblank_end - 1) << 16)); 3019 intel_de_write(dev_priv, VSYNC(cpu_transcoder), 3020 (adjusted_mode->crtc_vsync_start - 1) | ((adjusted_mode->crtc_vsync_end - 1) << 16)); 3021 3022 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be 3023 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is 3024 * documented on the DDI_FUNC_CTL register description, EDP Input Select 3025 * bits. */ 3026 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && 3027 (pipe == PIPE_B || pipe == PIPE_C)) 3028 intel_de_write(dev_priv, VTOTAL(pipe), 3029 intel_de_read(dev_priv, VTOTAL(cpu_transcoder))); 3030 3031 } 3032 3033 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state) 3034 { 3035 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3036 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3037 int width = drm_rect_width(&crtc_state->pipe_src); 3038 int height = drm_rect_height(&crtc_state->pipe_src); 3039 enum pipe pipe = crtc->pipe; 3040 3041 /* pipesrc controls the size that is scaled from, which should 3042 * always be the user's requested size. 3043 */ 3044 intel_de_write(dev_priv, PIPESRC(pipe), 3045 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1)); 3046 } 3047 3048 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state) 3049 { 3050 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 3051 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 3052 3053 if (DISPLAY_VER(dev_priv) == 2) 3054 return false; 3055 3056 if (DISPLAY_VER(dev_priv) >= 9 || 3057 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) 3058 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK_HSW; 3059 else 3060 return intel_de_read(dev_priv, PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK; 3061 } 3062 3063 static void intel_get_transcoder_timings(struct intel_crtc *crtc, 3064 struct intel_crtc_state *pipe_config) 3065 { 3066 struct drm_device *dev = crtc->base.dev; 3067 struct drm_i915_private *dev_priv = to_i915(dev); 3068 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; 3069 u32 tmp; 3070 3071 tmp = intel_de_read(dev_priv, HTOTAL(cpu_transcoder)); 3072 pipe_config->hw.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; 3073 pipe_config->hw.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; 3074 3075 if (!transcoder_is_dsi(cpu_transcoder)) { 3076 tmp = intel_de_read(dev_priv, HBLANK(cpu_transcoder)); 3077 pipe_config->hw.adjusted_mode.crtc_hblank_start = 3078 (tmp & 0xffff) + 1; 3079 pipe_config->hw.adjusted_mode.crtc_hblank_end = 3080 ((tmp >> 16) & 0xffff) + 1; 3081 } 3082 tmp = intel_de_read(dev_priv, HSYNC(cpu_transcoder)); 3083 pipe_config->hw.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; 3084 pipe_config->hw.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; 3085 3086 tmp = intel_de_read(dev_priv, VTOTAL(cpu_transcoder)); 3087 pipe_config->hw.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; 3088 pipe_config->hw.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; 3089 3090 if (!transcoder_is_dsi(cpu_transcoder)) { 3091 tmp = intel_de_read(dev_priv, VBLANK(cpu_transcoder)); 3092 pipe_config->hw.adjusted_mode.crtc_vblank_start = 3093 (tmp & 0xffff) + 1; 3094 pipe_config->hw.adjusted_mode.crtc_vblank_end = 3095 ((tmp >> 16) & 0xffff) + 1; 3096 } 3097 tmp = intel_de_read(dev_priv, VSYNC(cpu_transcoder)); 3098 pipe_config->hw.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; 3099 pipe_config->hw.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; 3100 3101 if (intel_pipe_is_interlaced(pipe_config)) { 3102 pipe_config->hw.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; 3103 pipe_config->hw.adjusted_mode.crtc_vtotal += 1; 3104 pipe_config->hw.adjusted_mode.crtc_vblank_end += 1; 3105 } 3106 } 3107 3108 static void intel_bigjoiner_adjust_pipe_src(struct intel_crtc_state *crtc_state) 3109 { 3110 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3111 int num_pipes = intel_bigjoiner_num_pipes(crtc_state); 3112 enum pipe master_pipe, pipe = crtc->pipe; 3113 int width; 3114 3115 if (num_pipes < 2) 3116 return; 3117 3118 master_pipe = bigjoiner_master_pipe(crtc_state); 3119 width = drm_rect_width(&crtc_state->pipe_src); 3120 3121 drm_rect_translate_to(&crtc_state->pipe_src, 3122 (pipe - master_pipe) * width, 0); 3123 } 3124 3125 static void intel_get_pipe_src_size(struct intel_crtc *crtc, 3126 struct intel_crtc_state *pipe_config) 3127 { 3128 struct drm_device *dev = crtc->base.dev; 3129 struct drm_i915_private *dev_priv = to_i915(dev); 3130 u32 tmp; 3131 3132 tmp = intel_de_read(dev_priv, PIPESRC(crtc->pipe)); 3133 3134 drm_rect_init(&pipe_config->pipe_src, 0, 0, 3135 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1, 3136 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1); 3137 3138 intel_bigjoiner_adjust_pipe_src(pipe_config); 3139 } 3140 3141 static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) 3142 { 3143 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3144 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3145 u32 pipeconf = 0; 3146 3147 /* we keep both pipes enabled on 830 */ 3148 if (IS_I830(dev_priv)) 3149 pipeconf |= PIPECONF_ENABLE; 3150 3151 if (crtc_state->double_wide) 3152 pipeconf |= PIPECONF_DOUBLE_WIDE; 3153 3154 /* only g4x and later have fancy bpc/dither controls */ 3155 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 3156 IS_CHERRYVIEW(dev_priv)) { 3157 /* Bspec claims that we can't use dithering for 30bpp pipes. */ 3158 if (crtc_state->dither && crtc_state->pipe_bpp != 30) 3159 pipeconf |= PIPECONF_DITHER_EN | 3160 PIPECONF_DITHER_TYPE_SP; 3161 3162 switch (crtc_state->pipe_bpp) { 3163 default: 3164 /* Case prevented by intel_choose_pipe_bpp_dither. */ 3165 MISSING_CASE(crtc_state->pipe_bpp); 3166 fallthrough; 3167 case 18: 3168 pipeconf |= PIPECONF_BPC_6; 3169 break; 3170 case 24: 3171 pipeconf |= PIPECONF_BPC_8; 3172 break; 3173 case 30: 3174 pipeconf |= PIPECONF_BPC_10; 3175 break; 3176 } 3177 } 3178 3179 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { 3180 if (DISPLAY_VER(dev_priv) < 4 || 3181 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 3182 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; 3183 else 3184 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; 3185 } else { 3186 pipeconf |= PIPECONF_INTERLACE_PROGRESSIVE; 3187 } 3188 3189 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 3190 crtc_state->limited_color_range) 3191 pipeconf |= PIPECONF_COLOR_RANGE_SELECT; 3192 3193 pipeconf |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode); 3194 3195 pipeconf |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1); 3196 3197 intel_de_write(dev_priv, PIPECONF(crtc->pipe), pipeconf); 3198 intel_de_posting_read(dev_priv, PIPECONF(crtc->pipe)); 3199 } 3200 3201 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv) 3202 { 3203 if (IS_I830(dev_priv)) 3204 return false; 3205 3206 return DISPLAY_VER(dev_priv) >= 4 || 3207 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv); 3208 } 3209 3210 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state) 3211 { 3212 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3213 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3214 u32 tmp; 3215 3216 if (!i9xx_has_pfit(dev_priv)) 3217 return; 3218 3219 tmp = intel_de_read(dev_priv, PFIT_CONTROL); 3220 if (!(tmp & PFIT_ENABLE)) 3221 return; 3222 3223 /* Check whether the pfit is attached to our pipe. */ 3224 if (DISPLAY_VER(dev_priv) < 4) { 3225 if (crtc->pipe != PIPE_B) 3226 return; 3227 } else { 3228 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) 3229 return; 3230 } 3231 3232 crtc_state->gmch_pfit.control = tmp; 3233 crtc_state->gmch_pfit.pgm_ratios = 3234 intel_de_read(dev_priv, PFIT_PGM_RATIOS); 3235 } 3236 3237 static void vlv_crtc_clock_get(struct intel_crtc *crtc, 3238 struct intel_crtc_state *pipe_config) 3239 { 3240 struct drm_device *dev = crtc->base.dev; 3241 struct drm_i915_private *dev_priv = to_i915(dev); 3242 enum pipe pipe = crtc->pipe; 3243 struct dpll clock; 3244 u32 mdiv; 3245 int refclk = 100000; 3246 3247 /* In case of DSI, DPLL will not be used */ 3248 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) 3249 return; 3250 3251 vlv_dpio_get(dev_priv); 3252 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); 3253 vlv_dpio_put(dev_priv); 3254 3255 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; 3256 clock.m2 = mdiv & DPIO_M2DIV_MASK; 3257 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; 3258 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; 3259 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; 3260 3261 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); 3262 } 3263 3264 static void chv_crtc_clock_get(struct intel_crtc *crtc, 3265 struct intel_crtc_state *pipe_config) 3266 { 3267 struct drm_device *dev = crtc->base.dev; 3268 struct drm_i915_private *dev_priv = to_i915(dev); 3269 enum pipe pipe = crtc->pipe; 3270 enum dpio_channel port = vlv_pipe_to_channel(pipe); 3271 struct dpll clock; 3272 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; 3273 int refclk = 100000; 3274 3275 /* In case of DSI, DPLL will not be used */ 3276 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) 3277 return; 3278 3279 vlv_dpio_get(dev_priv); 3280 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); 3281 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); 3282 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); 3283 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); 3284 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); 3285 vlv_dpio_put(dev_priv); 3286 3287 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; 3288 clock.m2 = (pll_dw0 & 0xff) << 22; 3289 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) 3290 clock.m2 |= pll_dw2 & 0x3fffff; 3291 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; 3292 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; 3293 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; 3294 3295 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); 3296 } 3297 3298 static enum intel_output_format 3299 bdw_get_pipemisc_output_format(struct intel_crtc *crtc) 3300 { 3301 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3302 u32 tmp; 3303 3304 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe)); 3305 3306 if (tmp & PIPEMISC_YUV420_ENABLE) { 3307 /* We support 4:2:0 in full blend mode only */ 3308 drm_WARN_ON(&dev_priv->drm, 3309 (tmp & PIPEMISC_YUV420_MODE_FULL_BLEND) == 0); 3310 3311 return INTEL_OUTPUT_FORMAT_YCBCR420; 3312 } else if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) { 3313 return INTEL_OUTPUT_FORMAT_YCBCR444; 3314 } else { 3315 return INTEL_OUTPUT_FORMAT_RGB; 3316 } 3317 } 3318 3319 static void i9xx_get_pipe_color_config(struct intel_crtc_state *crtc_state) 3320 { 3321 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3322 struct intel_plane *plane = to_intel_plane(crtc->base.primary); 3323 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3324 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane; 3325 u32 tmp; 3326 3327 tmp = intel_de_read(dev_priv, DSPCNTR(i9xx_plane)); 3328 3329 if (tmp & DISP_PIPE_GAMMA_ENABLE) 3330 crtc_state->gamma_enable = true; 3331 3332 if (!HAS_GMCH(dev_priv) && 3333 tmp & DISP_PIPE_CSC_ENABLE) 3334 crtc_state->csc_enable = true; 3335 } 3336 3337 static bool i9xx_get_pipe_config(struct intel_crtc *crtc, 3338 struct intel_crtc_state *pipe_config) 3339 { 3340 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3341 enum intel_display_power_domain power_domain; 3342 intel_wakeref_t wakeref; 3343 u32 tmp; 3344 bool ret; 3345 3346 power_domain = POWER_DOMAIN_PIPE(crtc->pipe); 3347 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); 3348 if (!wakeref) 3349 return false; 3350 3351 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 3352 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; 3353 pipe_config->shared_dpll = NULL; 3354 3355 ret = false; 3356 3357 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe)); 3358 if (!(tmp & PIPECONF_ENABLE)) 3359 goto out; 3360 3361 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 3362 IS_CHERRYVIEW(dev_priv)) { 3363 switch (tmp & PIPECONF_BPC_MASK) { 3364 case PIPECONF_BPC_6: 3365 pipe_config->pipe_bpp = 18; 3366 break; 3367 case PIPECONF_BPC_8: 3368 pipe_config->pipe_bpp = 24; 3369 break; 3370 case PIPECONF_BPC_10: 3371 pipe_config->pipe_bpp = 30; 3372 break; 3373 default: 3374 MISSING_CASE(tmp); 3375 break; 3376 } 3377 } 3378 3379 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && 3380 (tmp & PIPECONF_COLOR_RANGE_SELECT)) 3381 pipe_config->limited_color_range = true; 3382 3383 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_I9XX, tmp); 3384 3385 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1; 3386 3387 if (IS_CHERRYVIEW(dev_priv)) 3388 pipe_config->cgm_mode = intel_de_read(dev_priv, 3389 CGM_PIPE_MODE(crtc->pipe)); 3390 3391 i9xx_get_pipe_color_config(pipe_config); 3392 intel_color_get_config(pipe_config); 3393 3394 if (DISPLAY_VER(dev_priv) < 4) 3395 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; 3396 3397 intel_get_transcoder_timings(crtc, pipe_config); 3398 intel_get_pipe_src_size(crtc, pipe_config); 3399 3400 i9xx_get_pfit_config(pipe_config); 3401 3402 if (DISPLAY_VER(dev_priv) >= 4) { 3403 /* No way to read it out on pipes B and C */ 3404 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) 3405 tmp = dev_priv->chv_dpll_md[crtc->pipe]; 3406 else 3407 tmp = intel_de_read(dev_priv, DPLL_MD(crtc->pipe)); 3408 pipe_config->pixel_multiplier = 3409 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) 3410 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; 3411 pipe_config->dpll_hw_state.dpll_md = tmp; 3412 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || 3413 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { 3414 tmp = intel_de_read(dev_priv, DPLL(crtc->pipe)); 3415 pipe_config->pixel_multiplier = 3416 ((tmp & SDVO_MULTIPLIER_MASK) 3417 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; 3418 } else { 3419 /* Note that on i915G/GM the pixel multiplier is in the sdvo 3420 * port and will be fixed up in the encoder->get_config 3421 * function. */ 3422 pipe_config->pixel_multiplier = 1; 3423 } 3424 pipe_config->dpll_hw_state.dpll = intel_de_read(dev_priv, 3425 DPLL(crtc->pipe)); 3426 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { 3427 pipe_config->dpll_hw_state.fp0 = intel_de_read(dev_priv, 3428 FP0(crtc->pipe)); 3429 pipe_config->dpll_hw_state.fp1 = intel_de_read(dev_priv, 3430 FP1(crtc->pipe)); 3431 } else { 3432 /* Mask out read-only status bits. */ 3433 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | 3434 DPLL_PORTC_READY_MASK | 3435 DPLL_PORTB_READY_MASK); 3436 } 3437 3438 if (IS_CHERRYVIEW(dev_priv)) 3439 chv_crtc_clock_get(crtc, pipe_config); 3440 else if (IS_VALLEYVIEW(dev_priv)) 3441 vlv_crtc_clock_get(crtc, pipe_config); 3442 else 3443 i9xx_crtc_clock_get(crtc, pipe_config); 3444 3445 /* 3446 * Normally the dotclock is filled in by the encoder .get_config() 3447 * but in case the pipe is enabled w/o any ports we need a sane 3448 * default. 3449 */ 3450 pipe_config->hw.adjusted_mode.crtc_clock = 3451 pipe_config->port_clock / pipe_config->pixel_multiplier; 3452 3453 ret = true; 3454 3455 out: 3456 intel_display_power_put(dev_priv, power_domain, wakeref); 3457 3458 return ret; 3459 } 3460 3461 static void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state) 3462 { 3463 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3464 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3465 enum pipe pipe = crtc->pipe; 3466 u32 val; 3467 3468 val = 0; 3469 3470 switch (crtc_state->pipe_bpp) { 3471 default: 3472 /* Case prevented by intel_choose_pipe_bpp_dither. */ 3473 MISSING_CASE(crtc_state->pipe_bpp); 3474 fallthrough; 3475 case 18: 3476 val |= PIPECONF_BPC_6; 3477 break; 3478 case 24: 3479 val |= PIPECONF_BPC_8; 3480 break; 3481 case 30: 3482 val |= PIPECONF_BPC_10; 3483 break; 3484 case 36: 3485 val |= PIPECONF_BPC_12; 3486 break; 3487 } 3488 3489 if (crtc_state->dither) 3490 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP; 3491 3492 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) 3493 val |= PIPECONF_INTERLACE_IF_ID_ILK; 3494 else 3495 val |= PIPECONF_INTERLACE_PF_PD_ILK; 3496 3497 /* 3498 * This would end up with an odd purple hue over 3499 * the entire display. Make sure we don't do it. 3500 */ 3501 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range && 3502 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB); 3503 3504 if (crtc_state->limited_color_range && 3505 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 3506 val |= PIPECONF_COLOR_RANGE_SELECT; 3507 3508 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 3509 val |= PIPECONF_OUTPUT_COLORSPACE_YUV709; 3510 3511 val |= PIPECONF_GAMMA_MODE(crtc_state->gamma_mode); 3512 3513 val |= PIPECONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1); 3514 val |= PIPECONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay); 3515 3516 intel_de_write(dev_priv, PIPECONF(pipe), val); 3517 intel_de_posting_read(dev_priv, PIPECONF(pipe)); 3518 } 3519 3520 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state) 3521 { 3522 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3523 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3524 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 3525 u32 val = 0; 3526 3527 if (IS_HASWELL(dev_priv) && crtc_state->dither) 3528 val |= PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP; 3529 3530 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) 3531 val |= PIPECONF_INTERLACE_IF_ID_ILK; 3532 else 3533 val |= PIPECONF_INTERLACE_PF_PD_ILK; 3534 3535 if (IS_HASWELL(dev_priv) && 3536 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 3537 val |= PIPECONF_OUTPUT_COLORSPACE_YUV_HSW; 3538 3539 intel_de_write(dev_priv, PIPECONF(cpu_transcoder), val); 3540 intel_de_posting_read(dev_priv, PIPECONF(cpu_transcoder)); 3541 } 3542 3543 static void bdw_set_pipemisc(const struct intel_crtc_state *crtc_state) 3544 { 3545 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3546 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3547 u32 val = 0; 3548 3549 switch (crtc_state->pipe_bpp) { 3550 case 18: 3551 val |= PIPEMISC_BPC_6; 3552 break; 3553 case 24: 3554 val |= PIPEMISC_BPC_8; 3555 break; 3556 case 30: 3557 val |= PIPEMISC_BPC_10; 3558 break; 3559 case 36: 3560 /* Port output 12BPC defined for ADLP+ */ 3561 if (DISPLAY_VER(dev_priv) > 12) 3562 val |= PIPEMISC_BPC_12_ADLP; 3563 break; 3564 default: 3565 MISSING_CASE(crtc_state->pipe_bpp); 3566 break; 3567 } 3568 3569 if (crtc_state->dither) 3570 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; 3571 3572 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || 3573 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) 3574 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV; 3575 3576 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 3577 val |= PIPEMISC_YUV420_ENABLE | 3578 PIPEMISC_YUV420_MODE_FULL_BLEND; 3579 3580 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state)) 3581 val |= PIPEMISC_HDR_MODE_PRECISION; 3582 3583 if (DISPLAY_VER(dev_priv) >= 12) 3584 val |= PIPEMISC_PIXEL_ROUNDING_TRUNC; 3585 3586 intel_de_write(dev_priv, PIPEMISC(crtc->pipe), val); 3587 } 3588 3589 int bdw_get_pipemisc_bpp(struct intel_crtc *crtc) 3590 { 3591 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3592 u32 tmp; 3593 3594 tmp = intel_de_read(dev_priv, PIPEMISC(crtc->pipe)); 3595 3596 switch (tmp & PIPEMISC_BPC_MASK) { 3597 case PIPEMISC_BPC_6: 3598 return 18; 3599 case PIPEMISC_BPC_8: 3600 return 24; 3601 case PIPEMISC_BPC_10: 3602 return 30; 3603 /* 3604 * PORT OUTPUT 12 BPC defined for ADLP+. 3605 * 3606 * TODO: 3607 * For previous platforms with DSI interface, bits 5:7 3608 * are used for storing pipe_bpp irrespective of dithering. 3609 * Since the value of 12 BPC is not defined for these bits 3610 * on older platforms, need to find a workaround for 12 BPC 3611 * MIPI DSI HW readout. 3612 */ 3613 case PIPEMISC_BPC_12_ADLP: 3614 if (DISPLAY_VER(dev_priv) > 12) 3615 return 36; 3616 fallthrough; 3617 default: 3618 MISSING_CASE(tmp); 3619 return 0; 3620 } 3621 } 3622 3623 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp) 3624 { 3625 /* 3626 * Account for spread spectrum to avoid 3627 * oversubscribing the link. Max center spread 3628 * is 2.5%; use 5% for safety's sake. 3629 */ 3630 u32 bps = target_clock * bpp * 21 / 20; 3631 return DIV_ROUND_UP(bps, link_bw * 8); 3632 } 3633 3634 void intel_get_m_n(struct drm_i915_private *i915, 3635 struct intel_link_m_n *m_n, 3636 i915_reg_t data_m_reg, i915_reg_t data_n_reg, 3637 i915_reg_t link_m_reg, i915_reg_t link_n_reg) 3638 { 3639 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK; 3640 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK; 3641 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK; 3642 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK; 3643 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1; 3644 } 3645 3646 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc, 3647 enum transcoder transcoder, 3648 struct intel_link_m_n *m_n) 3649 { 3650 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3651 enum pipe pipe = crtc->pipe; 3652 3653 if (DISPLAY_VER(dev_priv) >= 5) 3654 intel_get_m_n(dev_priv, m_n, 3655 PIPE_DATA_M1(transcoder), PIPE_DATA_N1(transcoder), 3656 PIPE_LINK_M1(transcoder), PIPE_LINK_N1(transcoder)); 3657 else 3658 intel_get_m_n(dev_priv, m_n, 3659 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe), 3660 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe)); 3661 } 3662 3663 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc, 3664 enum transcoder transcoder, 3665 struct intel_link_m_n *m_n) 3666 { 3667 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3668 3669 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder)) 3670 return; 3671 3672 intel_get_m_n(dev_priv, m_n, 3673 PIPE_DATA_M2(transcoder), PIPE_DATA_N2(transcoder), 3674 PIPE_LINK_M2(transcoder), PIPE_LINK_N2(transcoder)); 3675 } 3676 3677 static void ilk_get_pfit_pos_size(struct intel_crtc_state *crtc_state, 3678 u32 pos, u32 size) 3679 { 3680 drm_rect_init(&crtc_state->pch_pfit.dst, 3681 pos >> 16, pos & 0xffff, 3682 size >> 16, size & 0xffff); 3683 } 3684 3685 static void skl_get_pfit_config(struct intel_crtc_state *crtc_state) 3686 { 3687 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3688 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3689 struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; 3690 int id = -1; 3691 int i; 3692 3693 /* find scaler attached to this pipe */ 3694 for (i = 0; i < crtc->num_scalers; i++) { 3695 u32 ctl, pos, size; 3696 3697 ctl = intel_de_read(dev_priv, SKL_PS_CTRL(crtc->pipe, i)); 3698 if ((ctl & (PS_SCALER_EN | PS_PLANE_SEL_MASK)) != PS_SCALER_EN) 3699 continue; 3700 3701 id = i; 3702 crtc_state->pch_pfit.enabled = true; 3703 3704 pos = intel_de_read(dev_priv, SKL_PS_WIN_POS(crtc->pipe, i)); 3705 size = intel_de_read(dev_priv, SKL_PS_WIN_SZ(crtc->pipe, i)); 3706 3707 ilk_get_pfit_pos_size(crtc_state, pos, size); 3708 3709 scaler_state->scalers[i].in_use = true; 3710 break; 3711 } 3712 3713 scaler_state->scaler_id = id; 3714 if (id >= 0) 3715 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); 3716 else 3717 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); 3718 } 3719 3720 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state) 3721 { 3722 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3723 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3724 u32 ctl, pos, size; 3725 3726 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe)); 3727 if ((ctl & PF_ENABLE) == 0) 3728 return; 3729 3730 crtc_state->pch_pfit.enabled = true; 3731 3732 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe)); 3733 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe)); 3734 3735 ilk_get_pfit_pos_size(crtc_state, pos, size); 3736 3737 /* 3738 * We currently do not free assignements of panel fitters on 3739 * ivb/hsw (since we don't use the higher upscaling modes which 3740 * differentiates them) so just WARN about this case for now. 3741 */ 3742 drm_WARN_ON(&dev_priv->drm, DISPLAY_VER(dev_priv) == 7 && 3743 (ctl & PF_PIPE_SEL_MASK_IVB) != PF_PIPE_SEL_IVB(crtc->pipe)); 3744 } 3745 3746 static bool ilk_get_pipe_config(struct intel_crtc *crtc, 3747 struct intel_crtc_state *pipe_config) 3748 { 3749 struct drm_device *dev = crtc->base.dev; 3750 struct drm_i915_private *dev_priv = to_i915(dev); 3751 enum intel_display_power_domain power_domain; 3752 intel_wakeref_t wakeref; 3753 u32 tmp; 3754 bool ret; 3755 3756 power_domain = POWER_DOMAIN_PIPE(crtc->pipe); 3757 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); 3758 if (!wakeref) 3759 return false; 3760 3761 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; 3762 pipe_config->shared_dpll = NULL; 3763 3764 ret = false; 3765 tmp = intel_de_read(dev_priv, PIPECONF(crtc->pipe)); 3766 if (!(tmp & PIPECONF_ENABLE)) 3767 goto out; 3768 3769 switch (tmp & PIPECONF_BPC_MASK) { 3770 case PIPECONF_BPC_6: 3771 pipe_config->pipe_bpp = 18; 3772 break; 3773 case PIPECONF_BPC_8: 3774 pipe_config->pipe_bpp = 24; 3775 break; 3776 case PIPECONF_BPC_10: 3777 pipe_config->pipe_bpp = 30; 3778 break; 3779 case PIPECONF_BPC_12: 3780 pipe_config->pipe_bpp = 36; 3781 break; 3782 default: 3783 break; 3784 } 3785 3786 if (tmp & PIPECONF_COLOR_RANGE_SELECT) 3787 pipe_config->limited_color_range = true; 3788 3789 switch (tmp & PIPECONF_OUTPUT_COLORSPACE_MASK) { 3790 case PIPECONF_OUTPUT_COLORSPACE_YUV601: 3791 case PIPECONF_OUTPUT_COLORSPACE_YUV709: 3792 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 3793 break; 3794 default: 3795 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 3796 break; 3797 } 3798 3799 pipe_config->gamma_mode = REG_FIELD_GET(PIPECONF_GAMMA_MODE_MASK_ILK, tmp); 3800 3801 pipe_config->framestart_delay = REG_FIELD_GET(PIPECONF_FRAME_START_DELAY_MASK, tmp) + 1; 3802 3803 pipe_config->msa_timing_delay = REG_FIELD_GET(PIPECONF_MSA_TIMING_DELAY_MASK, tmp); 3804 3805 pipe_config->csc_mode = intel_de_read(dev_priv, 3806 PIPE_CSC_MODE(crtc->pipe)); 3807 3808 i9xx_get_pipe_color_config(pipe_config); 3809 intel_color_get_config(pipe_config); 3810 3811 pipe_config->pixel_multiplier = 1; 3812 3813 ilk_pch_get_config(pipe_config); 3814 3815 intel_get_transcoder_timings(crtc, pipe_config); 3816 intel_get_pipe_src_size(crtc, pipe_config); 3817 3818 ilk_get_pfit_config(pipe_config); 3819 3820 ret = true; 3821 3822 out: 3823 intel_display_power_put(dev_priv, power_domain, wakeref); 3824 3825 return ret; 3826 } 3827 3828 static u8 bigjoiner_pipes(struct drm_i915_private *i915) 3829 { 3830 if (DISPLAY_VER(i915) >= 12) 3831 return BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D); 3832 else if (DISPLAY_VER(i915) >= 11) 3833 return BIT(PIPE_B) | BIT(PIPE_C); 3834 else 3835 return 0; 3836 } 3837 3838 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv, 3839 enum transcoder cpu_transcoder) 3840 { 3841 enum intel_display_power_domain power_domain; 3842 intel_wakeref_t wakeref; 3843 u32 tmp = 0; 3844 3845 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 3846 3847 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) 3848 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3849 3850 return tmp & TRANS_DDI_FUNC_ENABLE; 3851 } 3852 3853 static void enabled_bigjoiner_pipes(struct drm_i915_private *dev_priv, 3854 u8 *master_pipes, u8 *slave_pipes) 3855 { 3856 struct intel_crtc *crtc; 3857 3858 *master_pipes = 0; 3859 *slave_pipes = 0; 3860 3861 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, crtc, 3862 bigjoiner_pipes(dev_priv)) { 3863 enum intel_display_power_domain power_domain; 3864 enum pipe pipe = crtc->pipe; 3865 intel_wakeref_t wakeref; 3866 3867 power_domain = intel_dsc_power_domain(crtc, (enum transcoder) pipe); 3868 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) { 3869 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe)); 3870 3871 if (!(tmp & BIG_JOINER_ENABLE)) 3872 continue; 3873 3874 if (tmp & MASTER_BIG_JOINER_ENABLE) 3875 *master_pipes |= BIT(pipe); 3876 else 3877 *slave_pipes |= BIT(pipe); 3878 } 3879 3880 if (DISPLAY_VER(dev_priv) < 13) 3881 continue; 3882 3883 power_domain = POWER_DOMAIN_PIPE(pipe); 3884 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) { 3885 u32 tmp = intel_de_read(dev_priv, ICL_PIPE_DSS_CTL1(pipe)); 3886 3887 if (tmp & UNCOMPRESSED_JOINER_MASTER) 3888 *master_pipes |= BIT(pipe); 3889 if (tmp & UNCOMPRESSED_JOINER_SLAVE) 3890 *slave_pipes |= BIT(pipe); 3891 } 3892 } 3893 3894 /* Bigjoiner pipes should always be consecutive master and slave */ 3895 drm_WARN(&dev_priv->drm, *slave_pipes != *master_pipes << 1, 3896 "Bigjoiner misconfigured (master pipes 0x%x, slave pipes 0x%x)\n", 3897 *master_pipes, *slave_pipes); 3898 } 3899 3900 static enum pipe get_bigjoiner_master_pipe(enum pipe pipe, u8 master_pipes, u8 slave_pipes) 3901 { 3902 if ((slave_pipes & BIT(pipe)) == 0) 3903 return pipe; 3904 3905 /* ignore everything above our pipe */ 3906 master_pipes &= ~GENMASK(7, pipe); 3907 3908 /* highest remaining bit should be our master pipe */ 3909 return fls(master_pipes) - 1; 3910 } 3911 3912 static u8 get_bigjoiner_slave_pipes(enum pipe pipe, u8 master_pipes, u8 slave_pipes) 3913 { 3914 enum pipe master_pipe, next_master_pipe; 3915 3916 master_pipe = get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes); 3917 3918 if ((master_pipes & BIT(master_pipe)) == 0) 3919 return 0; 3920 3921 /* ignore our master pipe and everything below it */ 3922 master_pipes &= ~GENMASK(master_pipe, 0); 3923 /* make sure a high bit is set for the ffs() */ 3924 master_pipes |= BIT(7); 3925 /* lowest remaining bit should be the next master pipe */ 3926 next_master_pipe = ffs(master_pipes) - 1; 3927 3928 return slave_pipes & GENMASK(next_master_pipe - 1, master_pipe); 3929 } 3930 3931 static u8 hsw_panel_transcoders(struct drm_i915_private *i915) 3932 { 3933 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP); 3934 3935 if (DISPLAY_VER(i915) >= 11) 3936 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); 3937 3938 return panel_transcoder_mask; 3939 } 3940 3941 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc) 3942 { 3943 struct drm_device *dev = crtc->base.dev; 3944 struct drm_i915_private *dev_priv = to_i915(dev); 3945 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv); 3946 enum transcoder cpu_transcoder; 3947 u8 master_pipes, slave_pipes; 3948 u8 enabled_transcoders = 0; 3949 3950 /* 3951 * XXX: Do intel_display_power_get_if_enabled before reading this (for 3952 * consistency and less surprising code; it's in always on power). 3953 */ 3954 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, 3955 panel_transcoder_mask) { 3956 enum intel_display_power_domain power_domain; 3957 intel_wakeref_t wakeref; 3958 enum pipe trans_pipe; 3959 u32 tmp = 0; 3960 3961 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 3962 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref) 3963 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3964 3965 if (!(tmp & TRANS_DDI_FUNC_ENABLE)) 3966 continue; 3967 3968 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 3969 default: 3970 drm_WARN(dev, 1, 3971 "unknown pipe linked to transcoder %s\n", 3972 transcoder_name(cpu_transcoder)); 3973 fallthrough; 3974 case TRANS_DDI_EDP_INPUT_A_ONOFF: 3975 case TRANS_DDI_EDP_INPUT_A_ON: 3976 trans_pipe = PIPE_A; 3977 break; 3978 case TRANS_DDI_EDP_INPUT_B_ONOFF: 3979 trans_pipe = PIPE_B; 3980 break; 3981 case TRANS_DDI_EDP_INPUT_C_ONOFF: 3982 trans_pipe = PIPE_C; 3983 break; 3984 case TRANS_DDI_EDP_INPUT_D_ONOFF: 3985 trans_pipe = PIPE_D; 3986 break; 3987 } 3988 3989 if (trans_pipe == crtc->pipe) 3990 enabled_transcoders |= BIT(cpu_transcoder); 3991 } 3992 3993 /* single pipe or bigjoiner master */ 3994 cpu_transcoder = (enum transcoder) crtc->pipe; 3995 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder)) 3996 enabled_transcoders |= BIT(cpu_transcoder); 3997 3998 /* bigjoiner slave -> consider the master pipe's transcoder as well */ 3999 enabled_bigjoiner_pipes(dev_priv, &master_pipes, &slave_pipes); 4000 if (slave_pipes & BIT(crtc->pipe)) { 4001 cpu_transcoder = (enum transcoder) 4002 get_bigjoiner_master_pipe(crtc->pipe, master_pipes, slave_pipes); 4003 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder)) 4004 enabled_transcoders |= BIT(cpu_transcoder); 4005 } 4006 4007 return enabled_transcoders; 4008 } 4009 4010 static bool has_edp_transcoders(u8 enabled_transcoders) 4011 { 4012 return enabled_transcoders & BIT(TRANSCODER_EDP); 4013 } 4014 4015 static bool has_dsi_transcoders(u8 enabled_transcoders) 4016 { 4017 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) | 4018 BIT(TRANSCODER_DSI_1)); 4019 } 4020 4021 static bool has_pipe_transcoders(u8 enabled_transcoders) 4022 { 4023 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) | 4024 BIT(TRANSCODER_DSI_0) | 4025 BIT(TRANSCODER_DSI_1)); 4026 } 4027 4028 static void assert_enabled_transcoders(struct drm_i915_private *i915, 4029 u8 enabled_transcoders) 4030 { 4031 /* Only one type of transcoder please */ 4032 drm_WARN_ON(&i915->drm, 4033 has_edp_transcoders(enabled_transcoders) + 4034 has_dsi_transcoders(enabled_transcoders) + 4035 has_pipe_transcoders(enabled_transcoders) > 1); 4036 4037 /* Only DSI transcoders can be ganged */ 4038 drm_WARN_ON(&i915->drm, 4039 !has_dsi_transcoders(enabled_transcoders) && 4040 !is_power_of_2(enabled_transcoders)); 4041 } 4042 4043 static bool hsw_get_transcoder_state(struct intel_crtc *crtc, 4044 struct intel_crtc_state *pipe_config, 4045 struct intel_display_power_domain_set *power_domain_set) 4046 { 4047 struct drm_device *dev = crtc->base.dev; 4048 struct drm_i915_private *dev_priv = to_i915(dev); 4049 unsigned long enabled_transcoders; 4050 u32 tmp; 4051 4052 enabled_transcoders = hsw_enabled_transcoders(crtc); 4053 if (!enabled_transcoders) 4054 return false; 4055 4056 assert_enabled_transcoders(dev_priv, enabled_transcoders); 4057 4058 /* 4059 * With the exception of DSI we should only ever have 4060 * a single enabled transcoder. With DSI let's just 4061 * pick the first one. 4062 */ 4063 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1; 4064 4065 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set, 4066 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) 4067 return false; 4068 4069 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) { 4070 tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); 4071 4072 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF) 4073 pipe_config->pch_pfit.force_thru = true; 4074 } 4075 4076 tmp = intel_de_read(dev_priv, PIPECONF(pipe_config->cpu_transcoder)); 4077 4078 return tmp & PIPECONF_ENABLE; 4079 } 4080 4081 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, 4082 struct intel_crtc_state *pipe_config, 4083 struct intel_display_power_domain_set *power_domain_set) 4084 { 4085 struct drm_device *dev = crtc->base.dev; 4086 struct drm_i915_private *dev_priv = to_i915(dev); 4087 enum transcoder cpu_transcoder; 4088 enum port port; 4089 u32 tmp; 4090 4091 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { 4092 if (port == PORT_A) 4093 cpu_transcoder = TRANSCODER_DSI_A; 4094 else 4095 cpu_transcoder = TRANSCODER_DSI_C; 4096 4097 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set, 4098 POWER_DOMAIN_TRANSCODER(cpu_transcoder))) 4099 continue; 4100 4101 /* 4102 * The PLL needs to be enabled with a valid divider 4103 * configuration, otherwise accessing DSI registers will hang 4104 * the machine. See BSpec North Display Engine 4105 * registers/MIPI[BXT]. We can break out here early, since we 4106 * need the same DSI PLL to be enabled for both DSI ports. 4107 */ 4108 if (!bxt_dsi_pll_is_enabled(dev_priv)) 4109 break; 4110 4111 /* XXX: this works for video mode only */ 4112 tmp = intel_de_read(dev_priv, BXT_MIPI_PORT_CTRL(port)); 4113 if (!(tmp & DPI_ENABLE)) 4114 continue; 4115 4116 tmp = intel_de_read(dev_priv, MIPI_CTRL(port)); 4117 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) 4118 continue; 4119 4120 pipe_config->cpu_transcoder = cpu_transcoder; 4121 break; 4122 } 4123 4124 return transcoder_is_dsi(pipe_config->cpu_transcoder); 4125 } 4126 4127 static void intel_bigjoiner_get_config(struct intel_crtc_state *crtc_state) 4128 { 4129 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 4130 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 4131 u8 master_pipes, slave_pipes; 4132 enum pipe pipe = crtc->pipe; 4133 4134 enabled_bigjoiner_pipes(i915, &master_pipes, &slave_pipes); 4135 4136 if (((master_pipes | slave_pipes) & BIT(pipe)) == 0) 4137 return; 4138 4139 crtc_state->bigjoiner_pipes = 4140 BIT(get_bigjoiner_master_pipe(pipe, master_pipes, slave_pipes)) | 4141 get_bigjoiner_slave_pipes(pipe, master_pipes, slave_pipes); 4142 } 4143 4144 static bool hsw_get_pipe_config(struct intel_crtc *crtc, 4145 struct intel_crtc_state *pipe_config) 4146 { 4147 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 4148 struct intel_display_power_domain_set power_domain_set = { }; 4149 bool active; 4150 u32 tmp; 4151 4152 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set, 4153 POWER_DOMAIN_PIPE(crtc->pipe))) 4154 return false; 4155 4156 pipe_config->shared_dpll = NULL; 4157 4158 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_set); 4159 4160 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) && 4161 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_set)) { 4162 drm_WARN_ON(&dev_priv->drm, active); 4163 active = true; 4164 } 4165 4166 if (!active) 4167 goto out; 4168 4169 intel_dsc_get_config(pipe_config); 4170 intel_bigjoiner_get_config(pipe_config); 4171 4172 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || 4173 DISPLAY_VER(dev_priv) >= 11) 4174 intel_get_transcoder_timings(crtc, pipe_config); 4175 4176 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder)) 4177 intel_vrr_get_config(crtc, pipe_config); 4178 4179 intel_get_pipe_src_size(crtc, pipe_config); 4180 4181 if (IS_HASWELL(dev_priv)) { 4182 u32 tmp = intel_de_read(dev_priv, 4183 PIPECONF(pipe_config->cpu_transcoder)); 4184 4185 if (tmp & PIPECONF_OUTPUT_COLORSPACE_YUV_HSW) 4186 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 4187 else 4188 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 4189 } else { 4190 pipe_config->output_format = 4191 bdw_get_pipemisc_output_format(crtc); 4192 } 4193 4194 pipe_config->gamma_mode = intel_de_read(dev_priv, 4195 GAMMA_MODE(crtc->pipe)); 4196 4197 pipe_config->csc_mode = intel_de_read(dev_priv, 4198 PIPE_CSC_MODE(crtc->pipe)); 4199 4200 if (DISPLAY_VER(dev_priv) >= 9) { 4201 tmp = intel_de_read(dev_priv, SKL_BOTTOM_COLOR(crtc->pipe)); 4202 4203 if (tmp & SKL_BOTTOM_COLOR_GAMMA_ENABLE) 4204 pipe_config->gamma_enable = true; 4205 4206 if (tmp & SKL_BOTTOM_COLOR_CSC_ENABLE) 4207 pipe_config->csc_enable = true; 4208 } else { 4209 i9xx_get_pipe_color_config(pipe_config); 4210 } 4211 4212 intel_color_get_config(pipe_config); 4213 4214 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe)); 4215 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp); 4216 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) 4217 pipe_config->ips_linetime = 4218 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp); 4219 4220 if (intel_display_power_get_in_set_if_enabled(dev_priv, &power_domain_set, 4221 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) { 4222 if (DISPLAY_VER(dev_priv) >= 9) 4223 skl_get_pfit_config(pipe_config); 4224 else 4225 ilk_get_pfit_config(pipe_config); 4226 } 4227 4228 hsw_ips_get_config(pipe_config); 4229 4230 if (pipe_config->cpu_transcoder != TRANSCODER_EDP && 4231 !transcoder_is_dsi(pipe_config->cpu_transcoder)) { 4232 pipe_config->pixel_multiplier = 4233 intel_de_read(dev_priv, 4234 PIPE_MULT(pipe_config->cpu_transcoder)) + 1; 4235 } else { 4236 pipe_config->pixel_multiplier = 1; 4237 } 4238 4239 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { 4240 tmp = intel_de_read(dev_priv, CHICKEN_TRANS(pipe_config->cpu_transcoder)); 4241 4242 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1; 4243 } else { 4244 /* no idea if this is correct */ 4245 pipe_config->framestart_delay = 1; 4246 } 4247 4248 out: 4249 intel_display_power_put_all_in_set(dev_priv, &power_domain_set); 4250 4251 return active; 4252 } 4253 4254 static bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state) 4255 { 4256 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 4257 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 4258 4259 if (!i915->display->get_pipe_config(crtc, crtc_state)) 4260 return false; 4261 4262 crtc_state->hw.active = true; 4263 4264 intel_crtc_readout_derived_state(crtc_state); 4265 4266 return true; 4267 } 4268 4269 /* VESA 640x480x72Hz mode to set on the pipe */ 4270 static const struct drm_display_mode load_detect_mode = { 4271 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, 4272 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), 4273 }; 4274 4275 static int intel_modeset_disable_planes(struct drm_atomic_state *state, 4276 struct drm_crtc *crtc) 4277 { 4278 struct drm_plane *plane; 4279 struct drm_plane_state *plane_state; 4280 int ret, i; 4281 4282 ret = drm_atomic_add_affected_planes(state, crtc); 4283 if (ret) 4284 return ret; 4285 4286 for_each_new_plane_in_state(state, plane, plane_state, i) { 4287 if (plane_state->crtc != crtc) 4288 continue; 4289 4290 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); 4291 if (ret) 4292 return ret; 4293 4294 drm_atomic_set_fb_for_plane(plane_state, NULL); 4295 } 4296 4297 return 0; 4298 } 4299 4300 int intel_get_load_detect_pipe(struct drm_connector *connector, 4301 struct intel_load_detect_pipe *old, 4302 struct drm_modeset_acquire_ctx *ctx) 4303 { 4304 struct intel_encoder *encoder = 4305 intel_attached_encoder(to_intel_connector(connector)); 4306 struct intel_crtc *possible_crtc; 4307 struct intel_crtc *crtc = NULL; 4308 struct drm_device *dev = encoder->base.dev; 4309 struct drm_i915_private *dev_priv = to_i915(dev); 4310 struct drm_mode_config *config = &dev->mode_config; 4311 struct drm_atomic_state *state = NULL, *restore_state = NULL; 4312 struct drm_connector_state *connector_state; 4313 struct intel_crtc_state *crtc_state; 4314 int ret; 4315 4316 drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 4317 connector->base.id, connector->name, 4318 encoder->base.base.id, encoder->base.name); 4319 4320 old->restore_state = NULL; 4321 4322 drm_WARN_ON(dev, !drm_modeset_is_locked(&config->connection_mutex)); 4323 4324 /* 4325 * Algorithm gets a little messy: 4326 * 4327 * - if the connector already has an assigned crtc, use it (but make 4328 * sure it's on first) 4329 * 4330 * - try to find the first unused crtc that can drive this connector, 4331 * and use that if we find one 4332 */ 4333 4334 /* See if we already have a CRTC for this connector */ 4335 if (connector->state->crtc) { 4336 crtc = to_intel_crtc(connector->state->crtc); 4337 4338 ret = drm_modeset_lock(&crtc->base.mutex, ctx); 4339 if (ret) 4340 goto fail; 4341 4342 /* Make sure the crtc and connector are running */ 4343 goto found; 4344 } 4345 4346 /* Find an unused one (if possible) */ 4347 for_each_intel_crtc(dev, possible_crtc) { 4348 if (!(encoder->base.possible_crtcs & 4349 drm_crtc_mask(&possible_crtc->base))) 4350 continue; 4351 4352 ret = drm_modeset_lock(&possible_crtc->base.mutex, ctx); 4353 if (ret) 4354 goto fail; 4355 4356 if (possible_crtc->base.state->enable) { 4357 drm_modeset_unlock(&possible_crtc->base.mutex); 4358 continue; 4359 } 4360 4361 crtc = possible_crtc; 4362 break; 4363 } 4364 4365 /* 4366 * If we didn't find an unused CRTC, don't use any. 4367 */ 4368 if (!crtc) { 4369 drm_dbg_kms(&dev_priv->drm, 4370 "no pipe available for load-detect\n"); 4371 ret = -ENODEV; 4372 goto fail; 4373 } 4374 4375 found: 4376 state = drm_atomic_state_alloc(dev); 4377 restore_state = drm_atomic_state_alloc(dev); 4378 if (!state || !restore_state) { 4379 ret = -ENOMEM; 4380 goto fail; 4381 } 4382 4383 state->acquire_ctx = ctx; 4384 restore_state->acquire_ctx = ctx; 4385 4386 connector_state = drm_atomic_get_connector_state(state, connector); 4387 if (IS_ERR(connector_state)) { 4388 ret = PTR_ERR(connector_state); 4389 goto fail; 4390 } 4391 4392 ret = drm_atomic_set_crtc_for_connector(connector_state, &crtc->base); 4393 if (ret) 4394 goto fail; 4395 4396 crtc_state = intel_atomic_get_crtc_state(state, crtc); 4397 if (IS_ERR(crtc_state)) { 4398 ret = PTR_ERR(crtc_state); 4399 goto fail; 4400 } 4401 4402 crtc_state->uapi.active = true; 4403 4404 ret = drm_atomic_set_mode_for_crtc(&crtc_state->uapi, 4405 &load_detect_mode); 4406 if (ret) 4407 goto fail; 4408 4409 ret = intel_modeset_disable_planes(state, &crtc->base); 4410 if (ret) 4411 goto fail; 4412 4413 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); 4414 if (!ret) 4415 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, &crtc->base)); 4416 if (!ret) 4417 ret = drm_atomic_add_affected_planes(restore_state, &crtc->base); 4418 if (ret) { 4419 drm_dbg_kms(&dev_priv->drm, 4420 "Failed to create a copy of old state to restore: %i\n", 4421 ret); 4422 goto fail; 4423 } 4424 4425 ret = drm_atomic_commit(state); 4426 if (ret) { 4427 drm_dbg_kms(&dev_priv->drm, 4428 "failed to set mode on load-detect pipe\n"); 4429 goto fail; 4430 } 4431 4432 old->restore_state = restore_state; 4433 drm_atomic_state_put(state); 4434 4435 /* let the connector get through one full cycle before testing */ 4436 intel_crtc_wait_for_next_vblank(crtc); 4437 4438 return true; 4439 4440 fail: 4441 if (state) { 4442 drm_atomic_state_put(state); 4443 state = NULL; 4444 } 4445 if (restore_state) { 4446 drm_atomic_state_put(restore_state); 4447 restore_state = NULL; 4448 } 4449 4450 if (ret == -EDEADLK) 4451 return ret; 4452 4453 return false; 4454 } 4455 4456 void intel_release_load_detect_pipe(struct drm_connector *connector, 4457 struct intel_load_detect_pipe *old, 4458 struct drm_modeset_acquire_ctx *ctx) 4459 { 4460 struct intel_encoder *intel_encoder = 4461 intel_attached_encoder(to_intel_connector(connector)); 4462 struct drm_i915_private *i915 = to_i915(intel_encoder->base.dev); 4463 struct drm_encoder *encoder = &intel_encoder->base; 4464 struct drm_atomic_state *state = old->restore_state; 4465 int ret; 4466 4467 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 4468 connector->base.id, connector->name, 4469 encoder->base.id, encoder->name); 4470 4471 if (!state) 4472 return; 4473 4474 ret = drm_atomic_helper_commit_duplicated_state(state, ctx); 4475 if (ret) 4476 drm_dbg_kms(&i915->drm, 4477 "Couldn't release load detect pipe: %i\n", ret); 4478 drm_atomic_state_put(state); 4479 } 4480 4481 static int i9xx_pll_refclk(struct drm_device *dev, 4482 const struct intel_crtc_state *pipe_config) 4483 { 4484 struct drm_i915_private *dev_priv = to_i915(dev); 4485 u32 dpll = pipe_config->dpll_hw_state.dpll; 4486 4487 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) 4488 return dev_priv->vbt.lvds_ssc_freq; 4489 else if (HAS_PCH_SPLIT(dev_priv)) 4490 return 120000; 4491 else if (DISPLAY_VER(dev_priv) != 2) 4492 return 96000; 4493 else 4494 return 48000; 4495 } 4496 4497 /* Returns the clock of the currently programmed mode of the given pipe. */ 4498 void i9xx_crtc_clock_get(struct intel_crtc *crtc, 4499 struct intel_crtc_state *pipe_config) 4500 { 4501 struct drm_device *dev = crtc->base.dev; 4502 struct drm_i915_private *dev_priv = to_i915(dev); 4503 u32 dpll = pipe_config->dpll_hw_state.dpll; 4504 u32 fp; 4505 struct dpll clock; 4506 int port_clock; 4507 int refclk = i9xx_pll_refclk(dev, pipe_config); 4508 4509 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) 4510 fp = pipe_config->dpll_hw_state.fp0; 4511 else 4512 fp = pipe_config->dpll_hw_state.fp1; 4513 4514 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; 4515 if (IS_PINEVIEW(dev_priv)) { 4516 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; 4517 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; 4518 } else { 4519 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; 4520 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; 4521 } 4522 4523 if (DISPLAY_VER(dev_priv) != 2) { 4524 if (IS_PINEVIEW(dev_priv)) 4525 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> 4526 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); 4527 else 4528 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> 4529 DPLL_FPA01_P1_POST_DIV_SHIFT); 4530 4531 switch (dpll & DPLL_MODE_MASK) { 4532 case DPLLB_MODE_DAC_SERIAL: 4533 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? 4534 5 : 10; 4535 break; 4536 case DPLLB_MODE_LVDS: 4537 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? 4538 7 : 14; 4539 break; 4540 default: 4541 drm_dbg_kms(&dev_priv->drm, 4542 "Unknown DPLL mode %08x in programmed " 4543 "mode\n", (int)(dpll & DPLL_MODE_MASK)); 4544 return; 4545 } 4546 4547 if (IS_PINEVIEW(dev_priv)) 4548 port_clock = pnv_calc_dpll_params(refclk, &clock); 4549 else 4550 port_clock = i9xx_calc_dpll_params(refclk, &clock); 4551 } else { 4552 enum pipe lvds_pipe; 4553 4554 if (IS_I85X(dev_priv) && 4555 intel_lvds_port_enabled(dev_priv, LVDS, &lvds_pipe) && 4556 lvds_pipe == crtc->pipe) { 4557 u32 lvds = intel_de_read(dev_priv, LVDS); 4558 4559 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> 4560 DPLL_FPA01_P1_POST_DIV_SHIFT); 4561 4562 if (lvds & LVDS_CLKB_POWER_UP) 4563 clock.p2 = 7; 4564 else 4565 clock.p2 = 14; 4566 } else { 4567 if (dpll & PLL_P1_DIVIDE_BY_TWO) 4568 clock.p1 = 2; 4569 else { 4570 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> 4571 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; 4572 } 4573 if (dpll & PLL_P2_DIVIDE_BY_4) 4574 clock.p2 = 4; 4575 else 4576 clock.p2 = 2; 4577 } 4578 4579 port_clock = i9xx_calc_dpll_params(refclk, &clock); 4580 } 4581 4582 /* 4583 * This value includes pixel_multiplier. We will use 4584 * port_clock to compute adjusted_mode.crtc_clock in the 4585 * encoder's get_config() function. 4586 */ 4587 pipe_config->port_clock = port_clock; 4588 } 4589 4590 int intel_dotclock_calculate(int link_freq, 4591 const struct intel_link_m_n *m_n) 4592 { 4593 /* 4594 * The calculation for the data clock is: 4595 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp 4596 * But we want to avoid losing precison if possible, so: 4597 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) 4598 * 4599 * and the link clock is simpler: 4600 * link_clock = (m * link_clock) / n 4601 */ 4602 4603 if (!m_n->link_n) 4604 return 0; 4605 4606 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n); 4607 } 4608 4609 /* Returns the currently programmed mode of the given encoder. */ 4610 struct drm_display_mode * 4611 intel_encoder_current_mode(struct intel_encoder *encoder) 4612 { 4613 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4614 struct intel_crtc_state *crtc_state; 4615 struct drm_display_mode *mode; 4616 struct intel_crtc *crtc; 4617 enum pipe pipe; 4618 4619 if (!encoder->get_hw_state(encoder, &pipe)) 4620 return NULL; 4621 4622 crtc = intel_crtc_for_pipe(dev_priv, pipe); 4623 4624 mode = kzalloc(sizeof(*mode), GFP_KERNEL); 4625 if (!mode) 4626 return NULL; 4627 4628 crtc_state = intel_crtc_state_alloc(crtc); 4629 if (!crtc_state) { 4630 kfree(mode); 4631 return NULL; 4632 } 4633 4634 if (!intel_crtc_get_pipe_config(crtc_state)) { 4635 kfree(crtc_state); 4636 kfree(mode); 4637 return NULL; 4638 } 4639 4640 intel_encoder_get_config(encoder, crtc_state); 4641 4642 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode); 4643 4644 kfree(crtc_state); 4645 4646 return mode; 4647 } 4648 4649 static bool encoders_cloneable(const struct intel_encoder *a, 4650 const struct intel_encoder *b) 4651 { 4652 /* masks could be asymmetric, so check both ways */ 4653 return a == b || (a->cloneable & (1 << b->type) && 4654 b->cloneable & (1 << a->type)); 4655 } 4656 4657 static bool check_single_encoder_cloning(struct intel_atomic_state *state, 4658 struct intel_crtc *crtc, 4659 struct intel_encoder *encoder) 4660 { 4661 struct intel_encoder *source_encoder; 4662 struct drm_connector *connector; 4663 struct drm_connector_state *connector_state; 4664 int i; 4665 4666 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 4667 if (connector_state->crtc != &crtc->base) 4668 continue; 4669 4670 source_encoder = 4671 to_intel_encoder(connector_state->best_encoder); 4672 if (!encoders_cloneable(encoder, source_encoder)) 4673 return false; 4674 } 4675 4676 return true; 4677 } 4678 4679 static int icl_add_linked_planes(struct intel_atomic_state *state) 4680 { 4681 struct intel_plane *plane, *linked; 4682 struct intel_plane_state *plane_state, *linked_plane_state; 4683 int i; 4684 4685 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 4686 linked = plane_state->planar_linked_plane; 4687 4688 if (!linked) 4689 continue; 4690 4691 linked_plane_state = intel_atomic_get_plane_state(state, linked); 4692 if (IS_ERR(linked_plane_state)) 4693 return PTR_ERR(linked_plane_state); 4694 4695 drm_WARN_ON(state->base.dev, 4696 linked_plane_state->planar_linked_plane != plane); 4697 drm_WARN_ON(state->base.dev, 4698 linked_plane_state->planar_slave == plane_state->planar_slave); 4699 } 4700 4701 return 0; 4702 } 4703 4704 static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state) 4705 { 4706 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 4707 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 4708 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->uapi.state); 4709 struct intel_plane *plane, *linked; 4710 struct intel_plane_state *plane_state; 4711 int i; 4712 4713 if (DISPLAY_VER(dev_priv) < 11) 4714 return 0; 4715 4716 /* 4717 * Destroy all old plane links and make the slave plane invisible 4718 * in the crtc_state->active_planes mask. 4719 */ 4720 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 4721 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane) 4722 continue; 4723 4724 plane_state->planar_linked_plane = NULL; 4725 if (plane_state->planar_slave && !plane_state->uapi.visible) { 4726 crtc_state->enabled_planes &= ~BIT(plane->id); 4727 crtc_state->active_planes &= ~BIT(plane->id); 4728 crtc_state->update_planes |= BIT(plane->id); 4729 crtc_state->data_rate[plane->id] = 0; 4730 crtc_state->rel_data_rate[plane->id] = 0; 4731 } 4732 4733 plane_state->planar_slave = false; 4734 } 4735 4736 if (!crtc_state->nv12_planes) 4737 return 0; 4738 4739 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 4740 struct intel_plane_state *linked_state = NULL; 4741 4742 if (plane->pipe != crtc->pipe || 4743 !(crtc_state->nv12_planes & BIT(plane->id))) 4744 continue; 4745 4746 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) { 4747 if (!icl_is_nv12_y_plane(dev_priv, linked->id)) 4748 continue; 4749 4750 if (crtc_state->active_planes & BIT(linked->id)) 4751 continue; 4752 4753 linked_state = intel_atomic_get_plane_state(state, linked); 4754 if (IS_ERR(linked_state)) 4755 return PTR_ERR(linked_state); 4756 4757 break; 4758 } 4759 4760 if (!linked_state) { 4761 drm_dbg_kms(&dev_priv->drm, 4762 "Need %d free Y planes for planar YUV\n", 4763 hweight8(crtc_state->nv12_planes)); 4764 4765 return -EINVAL; 4766 } 4767 4768 plane_state->planar_linked_plane = linked; 4769 4770 linked_state->planar_slave = true; 4771 linked_state->planar_linked_plane = plane; 4772 crtc_state->enabled_planes |= BIT(linked->id); 4773 crtc_state->active_planes |= BIT(linked->id); 4774 crtc_state->update_planes |= BIT(linked->id); 4775 crtc_state->data_rate[linked->id] = 4776 crtc_state->data_rate_y[plane->id]; 4777 crtc_state->rel_data_rate[linked->id] = 4778 crtc_state->rel_data_rate_y[plane->id]; 4779 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n", 4780 linked->base.name, plane->base.name); 4781 4782 /* Copy parameters to slave plane */ 4783 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE; 4784 linked_state->color_ctl = plane_state->color_ctl; 4785 linked_state->view = plane_state->view; 4786 linked_state->decrypt = plane_state->decrypt; 4787 4788 intel_plane_copy_hw_state(linked_state, plane_state); 4789 linked_state->uapi.src = plane_state->uapi.src; 4790 linked_state->uapi.dst = plane_state->uapi.dst; 4791 4792 if (icl_is_hdr_plane(dev_priv, plane->id)) { 4793 if (linked->id == PLANE_SPRITE5) 4794 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL; 4795 else if (linked->id == PLANE_SPRITE4) 4796 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL; 4797 else if (linked->id == PLANE_SPRITE3) 4798 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL; 4799 else if (linked->id == PLANE_SPRITE2) 4800 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL; 4801 else 4802 MISSING_CASE(linked->id); 4803 } 4804 } 4805 4806 return 0; 4807 } 4808 4809 static bool c8_planes_changed(const struct intel_crtc_state *new_crtc_state) 4810 { 4811 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 4812 struct intel_atomic_state *state = 4813 to_intel_atomic_state(new_crtc_state->uapi.state); 4814 const struct intel_crtc_state *old_crtc_state = 4815 intel_atomic_get_old_crtc_state(state, crtc); 4816 4817 return !old_crtc_state->c8_planes != !new_crtc_state->c8_planes; 4818 } 4819 4820 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state) 4821 { 4822 const struct drm_display_mode *pipe_mode = 4823 &crtc_state->hw.pipe_mode; 4824 int linetime_wm; 4825 4826 if (!crtc_state->hw.enable) 4827 return 0; 4828 4829 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8, 4830 pipe_mode->crtc_clock); 4831 4832 return min(linetime_wm, 0x1ff); 4833 } 4834 4835 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state, 4836 const struct intel_cdclk_state *cdclk_state) 4837 { 4838 const struct drm_display_mode *pipe_mode = 4839 &crtc_state->hw.pipe_mode; 4840 int linetime_wm; 4841 4842 if (!crtc_state->hw.enable) 4843 return 0; 4844 4845 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8, 4846 cdclk_state->logical.cdclk); 4847 4848 return min(linetime_wm, 0x1ff); 4849 } 4850 4851 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state) 4852 { 4853 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 4854 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 4855 const struct drm_display_mode *pipe_mode = 4856 &crtc_state->hw.pipe_mode; 4857 int linetime_wm; 4858 4859 if (!crtc_state->hw.enable) 4860 return 0; 4861 4862 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8, 4863 crtc_state->pixel_rate); 4864 4865 /* Display WA #1135: BXT:ALL GLK:ALL */ 4866 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) && 4867 dev_priv->ipc_enabled) 4868 linetime_wm /= 2; 4869 4870 return min(linetime_wm, 0x1ff); 4871 } 4872 4873 static int hsw_compute_linetime_wm(struct intel_atomic_state *state, 4874 struct intel_crtc *crtc) 4875 { 4876 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 4877 struct intel_crtc_state *crtc_state = 4878 intel_atomic_get_new_crtc_state(state, crtc); 4879 const struct intel_cdclk_state *cdclk_state; 4880 4881 if (DISPLAY_VER(dev_priv) >= 9) 4882 crtc_state->linetime = skl_linetime_wm(crtc_state); 4883 else 4884 crtc_state->linetime = hsw_linetime_wm(crtc_state); 4885 4886 if (!hsw_crtc_supports_ips(crtc)) 4887 return 0; 4888 4889 cdclk_state = intel_atomic_get_cdclk_state(state); 4890 if (IS_ERR(cdclk_state)) 4891 return PTR_ERR(cdclk_state); 4892 4893 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state, 4894 cdclk_state); 4895 4896 return 0; 4897 } 4898 4899 static int intel_crtc_atomic_check(struct intel_atomic_state *state, 4900 struct intel_crtc *crtc) 4901 { 4902 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 4903 struct intel_crtc_state *crtc_state = 4904 intel_atomic_get_new_crtc_state(state, crtc); 4905 bool mode_changed = intel_crtc_needs_modeset(crtc_state); 4906 int ret; 4907 4908 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) && 4909 mode_changed && !crtc_state->hw.active) 4910 crtc_state->update_wm_post = true; 4911 4912 if (mode_changed) { 4913 ret = intel_dpll_crtc_compute_clock(state, crtc); 4914 if (ret) 4915 return ret; 4916 4917 ret = intel_dpll_crtc_get_shared_dpll(state, crtc); 4918 if (ret) 4919 return ret; 4920 } 4921 4922 /* 4923 * May need to update pipe gamma enable bits 4924 * when C8 planes are getting enabled/disabled. 4925 */ 4926 if (c8_planes_changed(crtc_state)) 4927 crtc_state->uapi.color_mgmt_changed = true; 4928 4929 if (mode_changed || crtc_state->update_pipe || 4930 crtc_state->uapi.color_mgmt_changed) { 4931 ret = intel_color_check(crtc_state); 4932 if (ret) 4933 return ret; 4934 } 4935 4936 ret = intel_compute_pipe_wm(state, crtc); 4937 if (ret) { 4938 drm_dbg_kms(&dev_priv->drm, 4939 "Target pipe watermarks are invalid\n"); 4940 return ret; 4941 } 4942 4943 /* 4944 * Calculate 'intermediate' watermarks that satisfy both the 4945 * old state and the new state. We can program these 4946 * immediately. 4947 */ 4948 ret = intel_compute_intermediate_wm(state, crtc); 4949 if (ret) { 4950 drm_dbg_kms(&dev_priv->drm, 4951 "No valid intermediate pipe watermarks are possible\n"); 4952 return ret; 4953 } 4954 4955 if (DISPLAY_VER(dev_priv) >= 9) { 4956 if (mode_changed || crtc_state->update_pipe) { 4957 ret = skl_update_scaler_crtc(crtc_state); 4958 if (ret) 4959 return ret; 4960 } 4961 4962 ret = intel_atomic_setup_scalers(dev_priv, crtc, crtc_state); 4963 if (ret) 4964 return ret; 4965 } 4966 4967 if (HAS_IPS(dev_priv)) { 4968 ret = hsw_ips_compute_config(state, crtc); 4969 if (ret) 4970 return ret; 4971 } 4972 4973 if (DISPLAY_VER(dev_priv) >= 9 || 4974 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { 4975 ret = hsw_compute_linetime_wm(state, crtc); 4976 if (ret) 4977 return ret; 4978 4979 } 4980 4981 ret = intel_psr2_sel_fetch_update(state, crtc); 4982 if (ret) 4983 return ret; 4984 4985 return 0; 4986 } 4987 4988 static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) 4989 { 4990 struct intel_connector *connector; 4991 struct drm_connector_list_iter conn_iter; 4992 4993 drm_connector_list_iter_begin(dev, &conn_iter); 4994 for_each_intel_connector_iter(connector, &conn_iter) { 4995 struct drm_connector_state *conn_state = connector->base.state; 4996 struct intel_encoder *encoder = 4997 to_intel_encoder(connector->base.encoder); 4998 4999 if (conn_state->crtc) 5000 drm_connector_put(&connector->base); 5001 5002 if (encoder) { 5003 struct intel_crtc *crtc = 5004 to_intel_crtc(encoder->base.crtc); 5005 const struct intel_crtc_state *crtc_state = 5006 to_intel_crtc_state(crtc->base.state); 5007 5008 conn_state->best_encoder = &encoder->base; 5009 conn_state->crtc = &crtc->base; 5010 conn_state->max_bpc = (crtc_state->pipe_bpp ?: 24) / 3; 5011 5012 drm_connector_get(&connector->base); 5013 } else { 5014 conn_state->best_encoder = NULL; 5015 conn_state->crtc = NULL; 5016 } 5017 } 5018 drm_connector_list_iter_end(&conn_iter); 5019 } 5020 5021 static int 5022 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, 5023 struct intel_crtc_state *crtc_state) 5024 { 5025 struct drm_connector *connector = conn_state->connector; 5026 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 5027 const struct drm_display_info *info = &connector->display_info; 5028 int bpp; 5029 5030 switch (conn_state->max_bpc) { 5031 case 6 ... 7: 5032 bpp = 6 * 3; 5033 break; 5034 case 8 ... 9: 5035 bpp = 8 * 3; 5036 break; 5037 case 10 ... 11: 5038 bpp = 10 * 3; 5039 break; 5040 case 12 ... 16: 5041 bpp = 12 * 3; 5042 break; 5043 default: 5044 MISSING_CASE(conn_state->max_bpc); 5045 return -EINVAL; 5046 } 5047 5048 if (bpp < crtc_state->pipe_bpp) { 5049 drm_dbg_kms(&i915->drm, 5050 "[CONNECTOR:%d:%s] Limiting display bpp to %d " 5051 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n", 5052 connector->base.id, connector->name, 5053 bpp, 3 * info->bpc, 5054 3 * conn_state->max_requested_bpc, 5055 crtc_state->pipe_bpp); 5056 5057 crtc_state->pipe_bpp = bpp; 5058 } 5059 5060 return 0; 5061 } 5062 5063 static int 5064 compute_baseline_pipe_bpp(struct intel_atomic_state *state, 5065 struct intel_crtc *crtc) 5066 { 5067 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 5068 struct intel_crtc_state *crtc_state = 5069 intel_atomic_get_new_crtc_state(state, crtc); 5070 struct drm_connector *connector; 5071 struct drm_connector_state *connector_state; 5072 int bpp, i; 5073 5074 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 5075 IS_CHERRYVIEW(dev_priv))) 5076 bpp = 10*3; 5077 else if (DISPLAY_VER(dev_priv) >= 5) 5078 bpp = 12*3; 5079 else 5080 bpp = 8*3; 5081 5082 crtc_state->pipe_bpp = bpp; 5083 5084 /* Clamp display bpp to connector max bpp */ 5085 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 5086 int ret; 5087 5088 if (connector_state->crtc != &crtc->base) 5089 continue; 5090 5091 ret = compute_sink_pipe_bpp(connector_state, crtc_state); 5092 if (ret) 5093 return ret; 5094 } 5095 5096 return 0; 5097 } 5098 5099 static void intel_dump_crtc_timings(struct drm_i915_private *i915, 5100 const struct drm_display_mode *mode) 5101 { 5102 drm_dbg_kms(&i915->drm, "crtc timings: %d %d %d %d %d %d %d %d %d, " 5103 "type: 0x%x flags: 0x%x\n", 5104 mode->crtc_clock, 5105 mode->crtc_hdisplay, mode->crtc_hsync_start, 5106 mode->crtc_hsync_end, mode->crtc_htotal, 5107 mode->crtc_vdisplay, mode->crtc_vsync_start, 5108 mode->crtc_vsync_end, mode->crtc_vtotal, 5109 mode->type, mode->flags); 5110 } 5111 5112 static void 5113 intel_dump_m_n_config(const struct intel_crtc_state *pipe_config, 5114 const char *id, unsigned int lane_count, 5115 const struct intel_link_m_n *m_n) 5116 { 5117 struct drm_i915_private *i915 = to_i915(pipe_config->uapi.crtc->dev); 5118 5119 drm_dbg_kms(&i915->drm, 5120 "%s: lanes: %i; data_m: %u, data_n: %u, link_m: %u, link_n: %u, tu: %u\n", 5121 id, lane_count, 5122 m_n->data_m, m_n->data_n, 5123 m_n->link_m, m_n->link_n, m_n->tu); 5124 } 5125 5126 static void 5127 intel_dump_infoframe(struct drm_i915_private *dev_priv, 5128 const union hdmi_infoframe *frame) 5129 { 5130 if (!drm_debug_enabled(DRM_UT_KMS)) 5131 return; 5132 5133 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, frame); 5134 } 5135 5136 static void 5137 intel_dump_dp_vsc_sdp(struct drm_i915_private *dev_priv, 5138 const struct drm_dp_vsc_sdp *vsc) 5139 { 5140 if (!drm_debug_enabled(DRM_UT_KMS)) 5141 return; 5142 5143 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, vsc); 5144 } 5145 5146 #define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x 5147 5148 static const char * const output_type_str[] = { 5149 OUTPUT_TYPE(UNUSED), 5150 OUTPUT_TYPE(ANALOG), 5151 OUTPUT_TYPE(DVO), 5152 OUTPUT_TYPE(SDVO), 5153 OUTPUT_TYPE(LVDS), 5154 OUTPUT_TYPE(TVOUT), 5155 OUTPUT_TYPE(HDMI), 5156 OUTPUT_TYPE(DP), 5157 OUTPUT_TYPE(EDP), 5158 OUTPUT_TYPE(DSI), 5159 OUTPUT_TYPE(DDI), 5160 OUTPUT_TYPE(DP_MST), 5161 }; 5162 5163 #undef OUTPUT_TYPE 5164 5165 static void snprintf_output_types(char *buf, size_t len, 5166 unsigned int output_types) 5167 { 5168 char *str = buf; 5169 int i; 5170 5171 str[0] = '\0'; 5172 5173 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) { 5174 int r; 5175 5176 if ((output_types & BIT(i)) == 0) 5177 continue; 5178 5179 r = snprintf(str, len, "%s%s", 5180 str != buf ? "," : "", output_type_str[i]); 5181 if (r >= len) 5182 break; 5183 str += r; 5184 len -= r; 5185 5186 output_types &= ~BIT(i); 5187 } 5188 5189 WARN_ON_ONCE(output_types != 0); 5190 } 5191 5192 static const char * const output_format_str[] = { 5193 [INTEL_OUTPUT_FORMAT_RGB] = "RGB", 5194 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0", 5195 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4", 5196 }; 5197 5198 static const char *output_formats(enum intel_output_format format) 5199 { 5200 if (format >= ARRAY_SIZE(output_format_str)) 5201 return "invalid"; 5202 return output_format_str[format]; 5203 } 5204 5205 static void intel_dump_plane_state(const struct intel_plane_state *plane_state) 5206 { 5207 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 5208 struct drm_i915_private *i915 = to_i915(plane->base.dev); 5209 const struct drm_framebuffer *fb = plane_state->hw.fb; 5210 5211 if (!fb) { 5212 drm_dbg_kms(&i915->drm, 5213 "[PLANE:%d:%s] fb: [NOFB], visible: %s\n", 5214 plane->base.base.id, plane->base.name, 5215 str_yes_no(plane_state->uapi.visible)); 5216 return; 5217 } 5218 5219 drm_dbg_kms(&i915->drm, 5220 "[PLANE:%d:%s] fb: [FB:%d] %ux%u format = %p4cc modifier = 0x%llx, visible: %s\n", 5221 plane->base.base.id, plane->base.name, 5222 fb->base.id, fb->width, fb->height, &fb->format->format, 5223 fb->modifier, str_yes_no(plane_state->uapi.visible)); 5224 drm_dbg_kms(&i915->drm, "\trotation: 0x%x, scaler: %d\n", 5225 plane_state->hw.rotation, plane_state->scaler_id); 5226 if (plane_state->uapi.visible) 5227 drm_dbg_kms(&i915->drm, 5228 "\tsrc: " DRM_RECT_FP_FMT " dst: " DRM_RECT_FMT "\n", 5229 DRM_RECT_FP_ARG(&plane_state->uapi.src), 5230 DRM_RECT_ARG(&plane_state->uapi.dst)); 5231 } 5232 5233 static void intel_dump_pipe_config(const struct intel_crtc_state *pipe_config, 5234 struct intel_atomic_state *state, 5235 const char *context) 5236 { 5237 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 5238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 5239 const struct intel_plane_state *plane_state; 5240 struct intel_plane *plane; 5241 char buf[64]; 5242 int i; 5243 5244 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s] enable: %s %s\n", 5245 crtc->base.base.id, crtc->base.name, 5246 str_yes_no(pipe_config->hw.enable), context); 5247 5248 if (!pipe_config->hw.enable) 5249 goto dump_planes; 5250 5251 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types); 5252 drm_dbg_kms(&dev_priv->drm, 5253 "active: %s, output_types: %s (0x%x), output format: %s\n", 5254 str_yes_no(pipe_config->hw.active), 5255 buf, pipe_config->output_types, 5256 output_formats(pipe_config->output_format)); 5257 5258 drm_dbg_kms(&dev_priv->drm, 5259 "cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", 5260 transcoder_name(pipe_config->cpu_transcoder), 5261 pipe_config->pipe_bpp, pipe_config->dither); 5262 5263 drm_dbg_kms(&dev_priv->drm, "MST master transcoder: %s\n", 5264 transcoder_name(pipe_config->mst_master_transcoder)); 5265 5266 drm_dbg_kms(&dev_priv->drm, 5267 "port sync: master transcoder: %s, slave transcoder bitmask = 0x%x\n", 5268 transcoder_name(pipe_config->master_transcoder), 5269 pipe_config->sync_mode_slaves_mask); 5270 5271 drm_dbg_kms(&dev_priv->drm, "bigjoiner: %s, pipes: 0x%x\n", 5272 intel_crtc_is_bigjoiner_slave(pipe_config) ? "slave" : 5273 intel_crtc_is_bigjoiner_master(pipe_config) ? "master" : "no", 5274 pipe_config->bigjoiner_pipes); 5275 5276 drm_dbg_kms(&dev_priv->drm, "splitter: %s, link count %d, overlap %d\n", 5277 str_enabled_disabled(pipe_config->splitter.enable), 5278 pipe_config->splitter.link_count, 5279 pipe_config->splitter.pixel_overlap); 5280 5281 if (pipe_config->has_pch_encoder) 5282 intel_dump_m_n_config(pipe_config, "fdi", 5283 pipe_config->fdi_lanes, 5284 &pipe_config->fdi_m_n); 5285 5286 if (intel_crtc_has_dp_encoder(pipe_config)) { 5287 intel_dump_m_n_config(pipe_config, "dp m_n", 5288 pipe_config->lane_count, 5289 &pipe_config->dp_m_n); 5290 intel_dump_m_n_config(pipe_config, "dp m2_n2", 5291 pipe_config->lane_count, 5292 &pipe_config->dp_m2_n2); 5293 } 5294 5295 drm_dbg_kms(&dev_priv->drm, "framestart delay: %d, MSA timing delay: %d\n", 5296 pipe_config->framestart_delay, pipe_config->msa_timing_delay); 5297 5298 drm_dbg_kms(&dev_priv->drm, 5299 "audio: %i, infoframes: %i, infoframes enabled: 0x%x\n", 5300 pipe_config->has_audio, pipe_config->has_infoframe, 5301 pipe_config->infoframes.enable); 5302 5303 if (pipe_config->infoframes.enable & 5304 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GENERAL_CONTROL)) 5305 drm_dbg_kms(&dev_priv->drm, "GCP: 0x%x\n", 5306 pipe_config->infoframes.gcp); 5307 if (pipe_config->infoframes.enable & 5308 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_AVI)) 5309 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.avi); 5310 if (pipe_config->infoframes.enable & 5311 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_SPD)) 5312 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.spd); 5313 if (pipe_config->infoframes.enable & 5314 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_VENDOR)) 5315 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.hdmi); 5316 if (pipe_config->infoframes.enable & 5317 intel_hdmi_infoframe_enable(HDMI_INFOFRAME_TYPE_DRM)) 5318 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm); 5319 if (pipe_config->infoframes.enable & 5320 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA)) 5321 intel_dump_infoframe(dev_priv, &pipe_config->infoframes.drm); 5322 if (pipe_config->infoframes.enable & 5323 intel_hdmi_infoframe_enable(DP_SDP_VSC)) 5324 intel_dump_dp_vsc_sdp(dev_priv, &pipe_config->infoframes.vsc); 5325 5326 drm_dbg_kms(&dev_priv->drm, "vrr: %s, vmin: %d, vmax: %d, pipeline full: %d, guardband: %d flipline: %d, vmin vblank: %d, vmax vblank: %d\n", 5327 str_yes_no(pipe_config->vrr.enable), 5328 pipe_config->vrr.vmin, pipe_config->vrr.vmax, 5329 pipe_config->vrr.pipeline_full, pipe_config->vrr.guardband, 5330 pipe_config->vrr.flipline, 5331 intel_vrr_vmin_vblank_start(pipe_config), 5332 intel_vrr_vmax_vblank_start(pipe_config)); 5333 5334 drm_dbg_kms(&dev_priv->drm, "requested mode: " DRM_MODE_FMT "\n", 5335 DRM_MODE_ARG(&pipe_config->hw.mode)); 5336 drm_dbg_kms(&dev_priv->drm, "adjusted mode: " DRM_MODE_FMT "\n", 5337 DRM_MODE_ARG(&pipe_config->hw.adjusted_mode)); 5338 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.adjusted_mode); 5339 drm_dbg_kms(&dev_priv->drm, "pipe mode: " DRM_MODE_FMT "\n", 5340 DRM_MODE_ARG(&pipe_config->hw.pipe_mode)); 5341 intel_dump_crtc_timings(dev_priv, &pipe_config->hw.pipe_mode); 5342 drm_dbg_kms(&dev_priv->drm, 5343 "port clock: %d, pipe src: " DRM_RECT_FMT ", pixel rate %d\n", 5344 pipe_config->port_clock, DRM_RECT_ARG(&pipe_config->pipe_src), 5345 pipe_config->pixel_rate); 5346 5347 drm_dbg_kms(&dev_priv->drm, "linetime: %d, ips linetime: %d\n", 5348 pipe_config->linetime, pipe_config->ips_linetime); 5349 5350 if (DISPLAY_VER(dev_priv) >= 9) 5351 drm_dbg_kms(&dev_priv->drm, 5352 "num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", 5353 crtc->num_scalers, 5354 pipe_config->scaler_state.scaler_users, 5355 pipe_config->scaler_state.scaler_id); 5356 5357 if (HAS_GMCH(dev_priv)) 5358 drm_dbg_kms(&dev_priv->drm, 5359 "gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", 5360 pipe_config->gmch_pfit.control, 5361 pipe_config->gmch_pfit.pgm_ratios, 5362 pipe_config->gmch_pfit.lvds_border_bits); 5363 else 5364 drm_dbg_kms(&dev_priv->drm, 5365 "pch pfit: " DRM_RECT_FMT ", %s, force thru: %s\n", 5366 DRM_RECT_ARG(&pipe_config->pch_pfit.dst), 5367 str_enabled_disabled(pipe_config->pch_pfit.enabled), 5368 str_yes_no(pipe_config->pch_pfit.force_thru)); 5369 5370 drm_dbg_kms(&dev_priv->drm, "ips: %i, double wide: %i, drrs: %i\n", 5371 pipe_config->ips_enabled, pipe_config->double_wide, 5372 pipe_config->has_drrs); 5373 5374 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); 5375 5376 if (IS_CHERRYVIEW(dev_priv)) 5377 drm_dbg_kms(&dev_priv->drm, 5378 "cgm_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n", 5379 pipe_config->cgm_mode, pipe_config->gamma_mode, 5380 pipe_config->gamma_enable, pipe_config->csc_enable); 5381 else 5382 drm_dbg_kms(&dev_priv->drm, 5383 "csc_mode: 0x%x gamma_mode: 0x%x gamma_enable: %d csc_enable: %d\n", 5384 pipe_config->csc_mode, pipe_config->gamma_mode, 5385 pipe_config->gamma_enable, pipe_config->csc_enable); 5386 5387 drm_dbg_kms(&dev_priv->drm, "degamma lut: %d entries, gamma lut: %d entries\n", 5388 pipe_config->hw.degamma_lut ? 5389 drm_color_lut_size(pipe_config->hw.degamma_lut) : 0, 5390 pipe_config->hw.gamma_lut ? 5391 drm_color_lut_size(pipe_config->hw.gamma_lut) : 0); 5392 5393 dump_planes: 5394 if (!state) 5395 return; 5396 5397 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 5398 if (plane->pipe == crtc->pipe) 5399 intel_dump_plane_state(plane_state); 5400 } 5401 } 5402 5403 static bool check_digital_port_conflicts(struct intel_atomic_state *state) 5404 { 5405 struct drm_device *dev = state->base.dev; 5406 struct drm_connector *connector; 5407 struct drm_connector_list_iter conn_iter; 5408 unsigned int used_ports = 0; 5409 unsigned int used_mst_ports = 0; 5410 bool ret = true; 5411 5412 /* 5413 * We're going to peek into connector->state, 5414 * hence connection_mutex must be held. 5415 */ 5416 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex); 5417 5418 /* 5419 * Walk the connector list instead of the encoder 5420 * list to detect the problem on ddi platforms 5421 * where there's just one encoder per digital port. 5422 */ 5423 drm_connector_list_iter_begin(dev, &conn_iter); 5424 drm_for_each_connector_iter(connector, &conn_iter) { 5425 struct drm_connector_state *connector_state; 5426 struct intel_encoder *encoder; 5427 5428 connector_state = 5429 drm_atomic_get_new_connector_state(&state->base, 5430 connector); 5431 if (!connector_state) 5432 connector_state = connector->state; 5433 5434 if (!connector_state->best_encoder) 5435 continue; 5436 5437 encoder = to_intel_encoder(connector_state->best_encoder); 5438 5439 drm_WARN_ON(dev, !connector_state->crtc); 5440 5441 switch (encoder->type) { 5442 case INTEL_OUTPUT_DDI: 5443 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev)))) 5444 break; 5445 fallthrough; 5446 case INTEL_OUTPUT_DP: 5447 case INTEL_OUTPUT_HDMI: 5448 case INTEL_OUTPUT_EDP: 5449 /* the same port mustn't appear more than once */ 5450 if (used_ports & BIT(encoder->port)) 5451 ret = false; 5452 5453 used_ports |= BIT(encoder->port); 5454 break; 5455 case INTEL_OUTPUT_DP_MST: 5456 used_mst_ports |= 5457 1 << encoder->port; 5458 break; 5459 default: 5460 break; 5461 } 5462 } 5463 drm_connector_list_iter_end(&conn_iter); 5464 5465 /* can't mix MST and SST/HDMI on the same port */ 5466 if (used_ports & used_mst_ports) 5467 return false; 5468 5469 return ret; 5470 } 5471 5472 static void 5473 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state, 5474 struct intel_crtc *crtc) 5475 { 5476 struct intel_crtc_state *crtc_state = 5477 intel_atomic_get_new_crtc_state(state, crtc); 5478 5479 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state)); 5480 5481 drm_property_replace_blob(&crtc_state->hw.degamma_lut, 5482 crtc_state->uapi.degamma_lut); 5483 drm_property_replace_blob(&crtc_state->hw.gamma_lut, 5484 crtc_state->uapi.gamma_lut); 5485 drm_property_replace_blob(&crtc_state->hw.ctm, 5486 crtc_state->uapi.ctm); 5487 } 5488 5489 static void 5490 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state, 5491 struct intel_crtc *crtc) 5492 { 5493 struct intel_crtc_state *crtc_state = 5494 intel_atomic_get_new_crtc_state(state, crtc); 5495 5496 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state)); 5497 5498 crtc_state->hw.enable = crtc_state->uapi.enable; 5499 crtc_state->hw.active = crtc_state->uapi.active; 5500 drm_mode_copy(&crtc_state->hw.mode, 5501 &crtc_state->uapi.mode); 5502 drm_mode_copy(&crtc_state->hw.adjusted_mode, 5503 &crtc_state->uapi.adjusted_mode); 5504 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter; 5505 5506 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc); 5507 } 5508 5509 static void intel_crtc_copy_hw_to_uapi_state(struct intel_crtc_state *crtc_state) 5510 { 5511 if (intel_crtc_is_bigjoiner_slave(crtc_state)) 5512 return; 5513 5514 crtc_state->uapi.enable = crtc_state->hw.enable; 5515 crtc_state->uapi.active = crtc_state->hw.active; 5516 drm_WARN_ON(crtc_state->uapi.crtc->dev, 5517 drm_atomic_set_mode_for_crtc(&crtc_state->uapi, &crtc_state->hw.mode) < 0); 5518 5519 crtc_state->uapi.adjusted_mode = crtc_state->hw.adjusted_mode; 5520 crtc_state->uapi.scaling_filter = crtc_state->hw.scaling_filter; 5521 5522 drm_property_replace_blob(&crtc_state->uapi.degamma_lut, 5523 crtc_state->hw.degamma_lut); 5524 drm_property_replace_blob(&crtc_state->uapi.gamma_lut, 5525 crtc_state->hw.gamma_lut); 5526 drm_property_replace_blob(&crtc_state->uapi.ctm, 5527 crtc_state->hw.ctm); 5528 } 5529 5530 static void 5531 copy_bigjoiner_crtc_state_nomodeset(struct intel_atomic_state *state, 5532 struct intel_crtc *slave_crtc) 5533 { 5534 struct intel_crtc_state *slave_crtc_state = 5535 intel_atomic_get_new_crtc_state(state, slave_crtc); 5536 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state); 5537 const struct intel_crtc_state *master_crtc_state = 5538 intel_atomic_get_new_crtc_state(state, master_crtc); 5539 5540 drm_property_replace_blob(&slave_crtc_state->hw.degamma_lut, 5541 master_crtc_state->hw.degamma_lut); 5542 drm_property_replace_blob(&slave_crtc_state->hw.gamma_lut, 5543 master_crtc_state->hw.gamma_lut); 5544 drm_property_replace_blob(&slave_crtc_state->hw.ctm, 5545 master_crtc_state->hw.ctm); 5546 5547 slave_crtc_state->uapi.color_mgmt_changed = master_crtc_state->uapi.color_mgmt_changed; 5548 } 5549 5550 static int 5551 copy_bigjoiner_crtc_state_modeset(struct intel_atomic_state *state, 5552 struct intel_crtc *slave_crtc) 5553 { 5554 struct intel_crtc_state *slave_crtc_state = 5555 intel_atomic_get_new_crtc_state(state, slave_crtc); 5556 struct intel_crtc *master_crtc = intel_master_crtc(slave_crtc_state); 5557 const struct intel_crtc_state *master_crtc_state = 5558 intel_atomic_get_new_crtc_state(state, master_crtc); 5559 struct intel_crtc_state *saved_state; 5560 5561 WARN_ON(master_crtc_state->bigjoiner_pipes != 5562 slave_crtc_state->bigjoiner_pipes); 5563 5564 saved_state = kmemdup(master_crtc_state, sizeof(*saved_state), GFP_KERNEL); 5565 if (!saved_state) 5566 return -ENOMEM; 5567 5568 /* preserve some things from the slave's original crtc state */ 5569 saved_state->uapi = slave_crtc_state->uapi; 5570 saved_state->scaler_state = slave_crtc_state->scaler_state; 5571 saved_state->shared_dpll = slave_crtc_state->shared_dpll; 5572 saved_state->dpll_hw_state = slave_crtc_state->dpll_hw_state; 5573 saved_state->crc_enabled = slave_crtc_state->crc_enabled; 5574 5575 intel_crtc_free_hw_state(slave_crtc_state); 5576 memcpy(slave_crtc_state, saved_state, sizeof(*slave_crtc_state)); 5577 kfree(saved_state); 5578 5579 /* Re-init hw state */ 5580 memset(&slave_crtc_state->hw, 0, sizeof(slave_crtc_state->hw)); 5581 slave_crtc_state->hw.enable = master_crtc_state->hw.enable; 5582 slave_crtc_state->hw.active = master_crtc_state->hw.active; 5583 drm_mode_copy(&slave_crtc_state->hw.mode, 5584 &master_crtc_state->hw.mode); 5585 drm_mode_copy(&slave_crtc_state->hw.pipe_mode, 5586 &master_crtc_state->hw.pipe_mode); 5587 drm_mode_copy(&slave_crtc_state->hw.adjusted_mode, 5588 &master_crtc_state->hw.adjusted_mode); 5589 slave_crtc_state->hw.scaling_filter = master_crtc_state->hw.scaling_filter; 5590 5591 copy_bigjoiner_crtc_state_nomodeset(state, slave_crtc); 5592 5593 slave_crtc_state->uapi.mode_changed = master_crtc_state->uapi.mode_changed; 5594 slave_crtc_state->uapi.connectors_changed = master_crtc_state->uapi.connectors_changed; 5595 slave_crtc_state->uapi.active_changed = master_crtc_state->uapi.active_changed; 5596 5597 WARN_ON(master_crtc_state->bigjoiner_pipes != 5598 slave_crtc_state->bigjoiner_pipes); 5599 5600 return 0; 5601 } 5602 5603 static int 5604 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state, 5605 struct intel_crtc *crtc) 5606 { 5607 struct intel_crtc_state *crtc_state = 5608 intel_atomic_get_new_crtc_state(state, crtc); 5609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 5610 struct intel_crtc_state *saved_state; 5611 5612 saved_state = intel_crtc_state_alloc(crtc); 5613 if (!saved_state) 5614 return -ENOMEM; 5615 5616 /* free the old crtc_state->hw members */ 5617 intel_crtc_free_hw_state(crtc_state); 5618 5619 /* FIXME: before the switch to atomic started, a new pipe_config was 5620 * kzalloc'd. Code that depends on any field being zero should be 5621 * fixed, so that the crtc_state can be safely duplicated. For now, 5622 * only fields that are know to not cause problems are preserved. */ 5623 5624 saved_state->uapi = crtc_state->uapi; 5625 saved_state->scaler_state = crtc_state->scaler_state; 5626 saved_state->shared_dpll = crtc_state->shared_dpll; 5627 saved_state->dpll_hw_state = crtc_state->dpll_hw_state; 5628 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls, 5629 sizeof(saved_state->icl_port_dplls)); 5630 saved_state->crc_enabled = crtc_state->crc_enabled; 5631 if (IS_G4X(dev_priv) || 5632 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 5633 saved_state->wm = crtc_state->wm; 5634 5635 memcpy(crtc_state, saved_state, sizeof(*crtc_state)); 5636 kfree(saved_state); 5637 5638 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc); 5639 5640 return 0; 5641 } 5642 5643 static int 5644 intel_modeset_pipe_config(struct intel_atomic_state *state, 5645 struct intel_crtc *crtc) 5646 { 5647 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 5648 struct intel_crtc_state *crtc_state = 5649 intel_atomic_get_new_crtc_state(state, crtc); 5650 struct drm_connector *connector; 5651 struct drm_connector_state *connector_state; 5652 int pipe_src_w, pipe_src_h; 5653 int base_bpp, ret, i; 5654 bool retry = true; 5655 5656 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe; 5657 5658 crtc_state->framestart_delay = 1; 5659 5660 /* 5661 * Sanitize sync polarity flags based on requested ones. If neither 5662 * positive or negative polarity is requested, treat this as meaning 5663 * negative polarity. 5664 */ 5665 if (!(crtc_state->hw.adjusted_mode.flags & 5666 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) 5667 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; 5668 5669 if (!(crtc_state->hw.adjusted_mode.flags & 5670 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) 5671 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; 5672 5673 ret = compute_baseline_pipe_bpp(state, crtc); 5674 if (ret) 5675 return ret; 5676 5677 base_bpp = crtc_state->pipe_bpp; 5678 5679 /* 5680 * Determine the real pipe dimensions. Note that stereo modes can 5681 * increase the actual pipe size due to the frame doubling and 5682 * insertion of additional space for blanks between the frame. This 5683 * is stored in the crtc timings. We use the requested mode to do this 5684 * computation to clearly distinguish it from the adjusted mode, which 5685 * can be changed by the connectors in the below retry loop. 5686 */ 5687 drm_mode_get_hv_timing(&crtc_state->hw.mode, 5688 &pipe_src_w, &pipe_src_h); 5689 drm_rect_init(&crtc_state->pipe_src, 0, 0, 5690 pipe_src_w, pipe_src_h); 5691 5692 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 5693 struct intel_encoder *encoder = 5694 to_intel_encoder(connector_state->best_encoder); 5695 5696 if (connector_state->crtc != &crtc->base) 5697 continue; 5698 5699 if (!check_single_encoder_cloning(state, crtc, encoder)) { 5700 drm_dbg_kms(&i915->drm, 5701 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n", 5702 encoder->base.base.id, encoder->base.name); 5703 return -EINVAL; 5704 } 5705 5706 /* 5707 * Determine output_types before calling the .compute_config() 5708 * hooks so that the hooks can use this information safely. 5709 */ 5710 if (encoder->compute_output_type) 5711 crtc_state->output_types |= 5712 BIT(encoder->compute_output_type(encoder, crtc_state, 5713 connector_state)); 5714 else 5715 crtc_state->output_types |= BIT(encoder->type); 5716 } 5717 5718 encoder_retry: 5719 /* Ensure the port clock defaults are reset when retrying. */ 5720 crtc_state->port_clock = 0; 5721 crtc_state->pixel_multiplier = 1; 5722 5723 /* Fill in default crtc timings, allow encoders to overwrite them. */ 5724 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode, 5725 CRTC_STEREO_DOUBLE); 5726 5727 /* Pass our mode to the connectors and the CRTC to give them a chance to 5728 * adjust it according to limitations or connector properties, and also 5729 * a chance to reject the mode entirely. 5730 */ 5731 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 5732 struct intel_encoder *encoder = 5733 to_intel_encoder(connector_state->best_encoder); 5734 5735 if (connector_state->crtc != &crtc->base) 5736 continue; 5737 5738 ret = encoder->compute_config(encoder, crtc_state, 5739 connector_state); 5740 if (ret == -EDEADLK) 5741 return ret; 5742 if (ret < 0) { 5743 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n", 5744 encoder->base.base.id, encoder->base.name, ret); 5745 return ret; 5746 } 5747 } 5748 5749 /* Set default port clock if not overwritten by the encoder. Needs to be 5750 * done afterwards in case the encoder adjusts the mode. */ 5751 if (!crtc_state->port_clock) 5752 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock 5753 * crtc_state->pixel_multiplier; 5754 5755 ret = intel_crtc_compute_config(state, crtc); 5756 if (ret == -EDEADLK) 5757 return ret; 5758 if (ret == -EAGAIN) { 5759 if (drm_WARN(&i915->drm, !retry, 5760 "[CRTC:%d:%s] loop in pipe configuration computation\n", 5761 crtc->base.base.id, crtc->base.name)) 5762 return -EINVAL; 5763 5764 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] bw constrained, retrying\n", 5765 crtc->base.base.id, crtc->base.name); 5766 retry = false; 5767 goto encoder_retry; 5768 } 5769 if (ret < 0) { 5770 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n", 5771 crtc->base.base.id, crtc->base.name, ret); 5772 return ret; 5773 } 5774 5775 /* Dithering seems to not pass-through bits correctly when it should, so 5776 * only enable it on 6bpc panels and when its not a compliance 5777 * test requesting 6bpc video pattern. 5778 */ 5779 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) && 5780 !crtc_state->dither_force_disable; 5781 drm_dbg_kms(&i915->drm, 5782 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n", 5783 crtc->base.base.id, crtc->base.name, 5784 base_bpp, crtc_state->pipe_bpp, crtc_state->dither); 5785 5786 return 0; 5787 } 5788 5789 static int 5790 intel_modeset_pipe_config_late(struct intel_atomic_state *state, 5791 struct intel_crtc *crtc) 5792 { 5793 struct intel_crtc_state *crtc_state = 5794 intel_atomic_get_new_crtc_state(state, crtc); 5795 struct drm_connector_state *conn_state; 5796 struct drm_connector *connector; 5797 int i; 5798 5799 intel_bigjoiner_adjust_pipe_src(crtc_state); 5800 5801 for_each_new_connector_in_state(&state->base, connector, 5802 conn_state, i) { 5803 struct intel_encoder *encoder = 5804 to_intel_encoder(conn_state->best_encoder); 5805 int ret; 5806 5807 if (conn_state->crtc != &crtc->base || 5808 !encoder->compute_config_late) 5809 continue; 5810 5811 ret = encoder->compute_config_late(encoder, crtc_state, 5812 conn_state); 5813 if (ret) 5814 return ret; 5815 } 5816 5817 return 0; 5818 } 5819 5820 bool intel_fuzzy_clock_check(int clock1, int clock2) 5821 { 5822 int diff; 5823 5824 if (clock1 == clock2) 5825 return true; 5826 5827 if (!clock1 || !clock2) 5828 return false; 5829 5830 diff = abs(clock1 - clock2); 5831 5832 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) 5833 return true; 5834 5835 return false; 5836 } 5837 5838 static bool 5839 intel_compare_m_n(unsigned int m, unsigned int n, 5840 unsigned int m2, unsigned int n2, 5841 bool exact) 5842 { 5843 if (m == m2 && n == n2) 5844 return true; 5845 5846 if (exact || !m || !n || !m2 || !n2) 5847 return false; 5848 5849 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); 5850 5851 if (n > n2) { 5852 while (n > n2) { 5853 m2 <<= 1; 5854 n2 <<= 1; 5855 } 5856 } else if (n < n2) { 5857 while (n < n2) { 5858 m <<= 1; 5859 n <<= 1; 5860 } 5861 } 5862 5863 if (n != n2) 5864 return false; 5865 5866 return intel_fuzzy_clock_check(m, m2); 5867 } 5868 5869 static bool 5870 intel_compare_link_m_n(const struct intel_link_m_n *m_n, 5871 const struct intel_link_m_n *m2_n2, 5872 bool exact) 5873 { 5874 return m_n->tu == m2_n2->tu && 5875 intel_compare_m_n(m_n->data_m, m_n->data_n, 5876 m2_n2->data_m, m2_n2->data_n, exact) && 5877 intel_compare_m_n(m_n->link_m, m_n->link_n, 5878 m2_n2->link_m, m2_n2->link_n, exact); 5879 } 5880 5881 static bool 5882 intel_compare_infoframe(const union hdmi_infoframe *a, 5883 const union hdmi_infoframe *b) 5884 { 5885 return memcmp(a, b, sizeof(*a)) == 0; 5886 } 5887 5888 static bool 5889 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a, 5890 const struct drm_dp_vsc_sdp *b) 5891 { 5892 return memcmp(a, b, sizeof(*a)) == 0; 5893 } 5894 5895 static void 5896 pipe_config_infoframe_mismatch(struct drm_i915_private *dev_priv, 5897 bool fastset, const char *name, 5898 const union hdmi_infoframe *a, 5899 const union hdmi_infoframe *b) 5900 { 5901 if (fastset) { 5902 if (!drm_debug_enabled(DRM_UT_KMS)) 5903 return; 5904 5905 drm_dbg_kms(&dev_priv->drm, 5906 "fastset mismatch in %s infoframe\n", name); 5907 drm_dbg_kms(&dev_priv->drm, "expected:\n"); 5908 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, a); 5909 drm_dbg_kms(&dev_priv->drm, "found:\n"); 5910 hdmi_infoframe_log(KERN_DEBUG, dev_priv->drm.dev, b); 5911 } else { 5912 drm_err(&dev_priv->drm, "mismatch in %s infoframe\n", name); 5913 drm_err(&dev_priv->drm, "expected:\n"); 5914 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, a); 5915 drm_err(&dev_priv->drm, "found:\n"); 5916 hdmi_infoframe_log(KERN_ERR, dev_priv->drm.dev, b); 5917 } 5918 } 5919 5920 static void 5921 pipe_config_dp_vsc_sdp_mismatch(struct drm_i915_private *dev_priv, 5922 bool fastset, const char *name, 5923 const struct drm_dp_vsc_sdp *a, 5924 const struct drm_dp_vsc_sdp *b) 5925 { 5926 if (fastset) { 5927 if (!drm_debug_enabled(DRM_UT_KMS)) 5928 return; 5929 5930 drm_dbg_kms(&dev_priv->drm, 5931 "fastset mismatch in %s dp sdp\n", name); 5932 drm_dbg_kms(&dev_priv->drm, "expected:\n"); 5933 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, a); 5934 drm_dbg_kms(&dev_priv->drm, "found:\n"); 5935 drm_dp_vsc_sdp_log(KERN_DEBUG, dev_priv->drm.dev, b); 5936 } else { 5937 drm_err(&dev_priv->drm, "mismatch in %s dp sdp\n", name); 5938 drm_err(&dev_priv->drm, "expected:\n"); 5939 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, a); 5940 drm_err(&dev_priv->drm, "found:\n"); 5941 drm_dp_vsc_sdp_log(KERN_ERR, dev_priv->drm.dev, b); 5942 } 5943 } 5944 5945 static void __printf(4, 5) 5946 pipe_config_mismatch(bool fastset, const struct intel_crtc *crtc, 5947 const char *name, const char *format, ...) 5948 { 5949 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 5950 struct va_format vaf; 5951 va_list args; 5952 5953 va_start(args, format); 5954 vaf.fmt = format; 5955 vaf.va = &args; 5956 5957 if (fastset) 5958 drm_dbg_kms(&i915->drm, 5959 "[CRTC:%d:%s] fastset mismatch in %s %pV\n", 5960 crtc->base.base.id, crtc->base.name, name, &vaf); 5961 else 5962 drm_err(&i915->drm, "[CRTC:%d:%s] mismatch in %s %pV\n", 5963 crtc->base.base.id, crtc->base.name, name, &vaf); 5964 5965 va_end(args); 5966 } 5967 5968 static bool fastboot_enabled(struct drm_i915_private *dev_priv) 5969 { 5970 if (dev_priv->params.fastboot != -1) 5971 return dev_priv->params.fastboot; 5972 5973 /* Enable fastboot by default on Skylake and newer */ 5974 if (DISPLAY_VER(dev_priv) >= 9) 5975 return true; 5976 5977 /* Enable fastboot by default on VLV and CHV */ 5978 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 5979 return true; 5980 5981 /* Disabled by default on all others */ 5982 return false; 5983 } 5984 5985 static bool 5986 intel_pipe_config_compare(const struct intel_crtc_state *current_config, 5987 const struct intel_crtc_state *pipe_config, 5988 bool fastset) 5989 { 5990 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev); 5991 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 5992 bool ret = true; 5993 u32 bp_gamma = 0; 5994 bool fixup_inherited = fastset && 5995 current_config->inherited && !pipe_config->inherited; 5996 5997 if (fixup_inherited && !fastboot_enabled(dev_priv)) { 5998 drm_dbg_kms(&dev_priv->drm, 5999 "initial modeset and fastboot not set\n"); 6000 ret = false; 6001 } 6002 6003 #define PIPE_CONF_CHECK_X(name) do { \ 6004 if (current_config->name != pipe_config->name) { \ 6005 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6006 "(expected 0x%08x, found 0x%08x)", \ 6007 current_config->name, \ 6008 pipe_config->name); \ 6009 ret = false; \ 6010 } \ 6011 } while (0) 6012 6013 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \ 6014 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \ 6015 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6016 "(expected 0x%08x, found 0x%08x)", \ 6017 current_config->name & (mask), \ 6018 pipe_config->name & (mask)); \ 6019 ret = false; \ 6020 } \ 6021 } while (0) 6022 6023 #define PIPE_CONF_CHECK_I(name) do { \ 6024 if (current_config->name != pipe_config->name) { \ 6025 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6026 "(expected %i, found %i)", \ 6027 current_config->name, \ 6028 pipe_config->name); \ 6029 ret = false; \ 6030 } \ 6031 } while (0) 6032 6033 #define PIPE_CONF_CHECK_BOOL(name) do { \ 6034 if (current_config->name != pipe_config->name) { \ 6035 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6036 "(expected %s, found %s)", \ 6037 str_yes_no(current_config->name), \ 6038 str_yes_no(pipe_config->name)); \ 6039 ret = false; \ 6040 } \ 6041 } while (0) 6042 6043 /* 6044 * Checks state where we only read out the enabling, but not the entire 6045 * state itself (like full infoframes or ELD for audio). These states 6046 * require a full modeset on bootup to fix up. 6047 */ 6048 #define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \ 6049 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \ 6050 PIPE_CONF_CHECK_BOOL(name); \ 6051 } else { \ 6052 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6053 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)", \ 6054 str_yes_no(current_config->name), \ 6055 str_yes_no(pipe_config->name)); \ 6056 ret = false; \ 6057 } \ 6058 } while (0) 6059 6060 #define PIPE_CONF_CHECK_P(name) do { \ 6061 if (current_config->name != pipe_config->name) { \ 6062 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6063 "(expected %p, found %p)", \ 6064 current_config->name, \ 6065 pipe_config->name); \ 6066 ret = false; \ 6067 } \ 6068 } while (0) 6069 6070 #define PIPE_CONF_CHECK_M_N(name) do { \ 6071 if (!intel_compare_link_m_n(¤t_config->name, \ 6072 &pipe_config->name,\ 6073 !fastset)) { \ 6074 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6075 "(expected tu %i data %i/%i link %i/%i, " \ 6076 "found tu %i, data %i/%i link %i/%i)", \ 6077 current_config->name.tu, \ 6078 current_config->name.data_m, \ 6079 current_config->name.data_n, \ 6080 current_config->name.link_m, \ 6081 current_config->name.link_n, \ 6082 pipe_config->name.tu, \ 6083 pipe_config->name.data_m, \ 6084 pipe_config->name.data_n, \ 6085 pipe_config->name.link_m, \ 6086 pipe_config->name.link_n); \ 6087 ret = false; \ 6088 } \ 6089 } while (0) 6090 6091 #define PIPE_CONF_CHECK_TIMINGS(name) do { \ 6092 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \ 6093 PIPE_CONF_CHECK_I(name.crtc_htotal); \ 6094 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \ 6095 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \ 6096 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \ 6097 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \ 6098 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \ 6099 PIPE_CONF_CHECK_I(name.crtc_vtotal); \ 6100 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \ 6101 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \ 6102 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \ 6103 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \ 6104 } while (0) 6105 6106 #define PIPE_CONF_CHECK_RECT(name) do { \ 6107 PIPE_CONF_CHECK_I(name.x1); \ 6108 PIPE_CONF_CHECK_I(name.x2); \ 6109 PIPE_CONF_CHECK_I(name.y1); \ 6110 PIPE_CONF_CHECK_I(name.y2); \ 6111 } while (0) 6112 6113 /* This is required for BDW+ where there is only one set of registers for 6114 * switching between high and low RR. 6115 * This macro can be used whenever a comparison has to be made between one 6116 * hw state and multiple sw state variables. 6117 */ 6118 #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \ 6119 if (!intel_compare_link_m_n(¤t_config->name, \ 6120 &pipe_config->name, !fastset) && \ 6121 !intel_compare_link_m_n(¤t_config->alt_name, \ 6122 &pipe_config->name, !fastset)) { \ 6123 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6124 "(expected tu %i data %i/%i link %i/%i, " \ 6125 "or tu %i data %i/%i link %i/%i, " \ 6126 "found tu %i, data %i/%i link %i/%i)", \ 6127 current_config->name.tu, \ 6128 current_config->name.data_m, \ 6129 current_config->name.data_n, \ 6130 current_config->name.link_m, \ 6131 current_config->name.link_n, \ 6132 current_config->alt_name.tu, \ 6133 current_config->alt_name.data_m, \ 6134 current_config->alt_name.data_n, \ 6135 current_config->alt_name.link_m, \ 6136 current_config->alt_name.link_n, \ 6137 pipe_config->name.tu, \ 6138 pipe_config->name.data_m, \ 6139 pipe_config->name.data_n, \ 6140 pipe_config->name.link_m, \ 6141 pipe_config->name.link_n); \ 6142 ret = false; \ 6143 } \ 6144 } while (0) 6145 6146 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ 6147 if ((current_config->name ^ pipe_config->name) & (mask)) { \ 6148 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6149 "(%x) (expected %i, found %i)", \ 6150 (mask), \ 6151 current_config->name & (mask), \ 6152 pipe_config->name & (mask)); \ 6153 ret = false; \ 6154 } \ 6155 } while (0) 6156 6157 #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \ 6158 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ 6159 pipe_config_mismatch(fastset, crtc, __stringify(name), \ 6160 "(expected %i, found %i)", \ 6161 current_config->name, \ 6162 pipe_config->name); \ 6163 ret = false; \ 6164 } \ 6165 } while (0) 6166 6167 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \ 6168 if (!intel_compare_infoframe(¤t_config->infoframes.name, \ 6169 &pipe_config->infoframes.name)) { \ 6170 pipe_config_infoframe_mismatch(dev_priv, fastset, __stringify(name), \ 6171 ¤t_config->infoframes.name, \ 6172 &pipe_config->infoframes.name); \ 6173 ret = false; \ 6174 } \ 6175 } while (0) 6176 6177 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \ 6178 if (!current_config->has_psr && !pipe_config->has_psr && \ 6179 !intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \ 6180 &pipe_config->infoframes.name)) { \ 6181 pipe_config_dp_vsc_sdp_mismatch(dev_priv, fastset, __stringify(name), \ 6182 ¤t_config->infoframes.name, \ 6183 &pipe_config->infoframes.name); \ 6184 ret = false; \ 6185 } \ 6186 } while (0) 6187 6188 #define PIPE_CONF_CHECK_COLOR_LUT(name1, name2, bit_precision) do { \ 6189 if (current_config->name1 != pipe_config->name1) { \ 6190 pipe_config_mismatch(fastset, crtc, __stringify(name1), \ 6191 "(expected %i, found %i, won't compare lut values)", \ 6192 current_config->name1, \ 6193 pipe_config->name1); \ 6194 ret = false;\ 6195 } else { \ 6196 if (!intel_color_lut_equal(current_config->name2, \ 6197 pipe_config->name2, pipe_config->name1, \ 6198 bit_precision)) { \ 6199 pipe_config_mismatch(fastset, crtc, __stringify(name2), \ 6200 "hw_state doesn't match sw_state"); \ 6201 ret = false; \ 6202 } \ 6203 } \ 6204 } while (0) 6205 6206 #define PIPE_CONF_QUIRK(quirk) \ 6207 ((current_config->quirks | pipe_config->quirks) & (quirk)) 6208 6209 PIPE_CONF_CHECK_I(hw.enable); 6210 PIPE_CONF_CHECK_I(hw.active); 6211 6212 PIPE_CONF_CHECK_I(cpu_transcoder); 6213 PIPE_CONF_CHECK_I(mst_master_transcoder); 6214 6215 PIPE_CONF_CHECK_BOOL(has_pch_encoder); 6216 PIPE_CONF_CHECK_I(fdi_lanes); 6217 PIPE_CONF_CHECK_M_N(fdi_m_n); 6218 6219 PIPE_CONF_CHECK_I(lane_count); 6220 PIPE_CONF_CHECK_X(lane_lat_optim_mask); 6221 6222 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) { 6223 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2); 6224 } else { 6225 PIPE_CONF_CHECK_M_N(dp_m_n); 6226 PIPE_CONF_CHECK_M_N(dp_m2_n2); 6227 } 6228 6229 PIPE_CONF_CHECK_X(output_types); 6230 6231 PIPE_CONF_CHECK_I(framestart_delay); 6232 PIPE_CONF_CHECK_I(msa_timing_delay); 6233 6234 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode); 6235 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode); 6236 6237 PIPE_CONF_CHECK_I(pixel_multiplier); 6238 6239 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 6240 DRM_MODE_FLAG_INTERLACE); 6241 6242 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { 6243 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 6244 DRM_MODE_FLAG_PHSYNC); 6245 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 6246 DRM_MODE_FLAG_NHSYNC); 6247 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 6248 DRM_MODE_FLAG_PVSYNC); 6249 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 6250 DRM_MODE_FLAG_NVSYNC); 6251 } 6252 6253 PIPE_CONF_CHECK_I(output_format); 6254 PIPE_CONF_CHECK_BOOL(has_hdmi_sink); 6255 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || 6256 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 6257 PIPE_CONF_CHECK_BOOL(limited_color_range); 6258 6259 PIPE_CONF_CHECK_BOOL(hdmi_scrambling); 6260 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); 6261 PIPE_CONF_CHECK_BOOL(has_infoframe); 6262 PIPE_CONF_CHECK_BOOL(fec_enable); 6263 6264 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio); 6265 6266 PIPE_CONF_CHECK_X(gmch_pfit.control); 6267 /* pfit ratios are autocomputed by the hw on gen4+ */ 6268 if (DISPLAY_VER(dev_priv) < 4) 6269 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); 6270 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); 6271 6272 /* 6273 * Changing the EDP transcoder input mux 6274 * (A_ONOFF vs. A_ON) requires a full modeset. 6275 */ 6276 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru); 6277 6278 if (!fastset) { 6279 PIPE_CONF_CHECK_RECT(pipe_src); 6280 6281 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); 6282 PIPE_CONF_CHECK_RECT(pch_pfit.dst); 6283 6284 PIPE_CONF_CHECK_I(scaler_state.scaler_id); 6285 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate); 6286 6287 PIPE_CONF_CHECK_X(gamma_mode); 6288 if (IS_CHERRYVIEW(dev_priv)) 6289 PIPE_CONF_CHECK_X(cgm_mode); 6290 else 6291 PIPE_CONF_CHECK_X(csc_mode); 6292 PIPE_CONF_CHECK_BOOL(gamma_enable); 6293 PIPE_CONF_CHECK_BOOL(csc_enable); 6294 6295 PIPE_CONF_CHECK_I(linetime); 6296 PIPE_CONF_CHECK_I(ips_linetime); 6297 6298 bp_gamma = intel_color_get_gamma_bit_precision(pipe_config); 6299 if (bp_gamma) 6300 PIPE_CONF_CHECK_COLOR_LUT(gamma_mode, hw.gamma_lut, bp_gamma); 6301 6302 if (current_config->active_planes) { 6303 PIPE_CONF_CHECK_BOOL(has_psr); 6304 PIPE_CONF_CHECK_BOOL(has_psr2); 6305 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch); 6306 PIPE_CONF_CHECK_I(dc3co_exitline); 6307 } 6308 } 6309 6310 PIPE_CONF_CHECK_BOOL(double_wide); 6311 6312 if (dev_priv->dpll.mgr) { 6313 PIPE_CONF_CHECK_P(shared_dpll); 6314 6315 PIPE_CONF_CHECK_X(dpll_hw_state.dpll); 6316 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); 6317 PIPE_CONF_CHECK_X(dpll_hw_state.fp0); 6318 PIPE_CONF_CHECK_X(dpll_hw_state.fp1); 6319 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); 6320 PIPE_CONF_CHECK_X(dpll_hw_state.spll); 6321 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); 6322 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); 6323 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); 6324 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0); 6325 PIPE_CONF_CHECK_X(dpll_hw_state.div0); 6326 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0); 6327 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4); 6328 PIPE_CONF_CHECK_X(dpll_hw_state.pll0); 6329 PIPE_CONF_CHECK_X(dpll_hw_state.pll1); 6330 PIPE_CONF_CHECK_X(dpll_hw_state.pll2); 6331 PIPE_CONF_CHECK_X(dpll_hw_state.pll3); 6332 PIPE_CONF_CHECK_X(dpll_hw_state.pll6); 6333 PIPE_CONF_CHECK_X(dpll_hw_state.pll8); 6334 PIPE_CONF_CHECK_X(dpll_hw_state.pll9); 6335 PIPE_CONF_CHECK_X(dpll_hw_state.pll10); 6336 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12); 6337 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl); 6338 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1); 6339 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl); 6340 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0); 6341 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1); 6342 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf); 6343 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock); 6344 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc); 6345 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias); 6346 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias); 6347 } 6348 6349 PIPE_CONF_CHECK_X(dsi_pll.ctrl); 6350 PIPE_CONF_CHECK_X(dsi_pll.div); 6351 6352 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5) 6353 PIPE_CONF_CHECK_I(pipe_bpp); 6354 6355 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.pipe_mode.crtc_clock); 6356 PIPE_CONF_CHECK_CLOCK_FUZZY(hw.adjusted_mode.crtc_clock); 6357 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); 6358 6359 PIPE_CONF_CHECK_I(min_voltage_level); 6360 6361 if (current_config->has_psr || pipe_config->has_psr) 6362 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable, 6363 ~intel_hdmi_infoframe_enable(DP_SDP_VSC)); 6364 else 6365 PIPE_CONF_CHECK_X(infoframes.enable); 6366 6367 PIPE_CONF_CHECK_X(infoframes.gcp); 6368 PIPE_CONF_CHECK_INFOFRAME(avi); 6369 PIPE_CONF_CHECK_INFOFRAME(spd); 6370 PIPE_CONF_CHECK_INFOFRAME(hdmi); 6371 PIPE_CONF_CHECK_INFOFRAME(drm); 6372 PIPE_CONF_CHECK_DP_VSC_SDP(vsc); 6373 6374 PIPE_CONF_CHECK_X(sync_mode_slaves_mask); 6375 PIPE_CONF_CHECK_I(master_transcoder); 6376 PIPE_CONF_CHECK_X(bigjoiner_pipes); 6377 6378 PIPE_CONF_CHECK_I(dsc.compression_enable); 6379 PIPE_CONF_CHECK_I(dsc.dsc_split); 6380 PIPE_CONF_CHECK_I(dsc.compressed_bpp); 6381 6382 PIPE_CONF_CHECK_BOOL(splitter.enable); 6383 PIPE_CONF_CHECK_I(splitter.link_count); 6384 PIPE_CONF_CHECK_I(splitter.pixel_overlap); 6385 6386 PIPE_CONF_CHECK_BOOL(vrr.enable); 6387 PIPE_CONF_CHECK_I(vrr.vmin); 6388 PIPE_CONF_CHECK_I(vrr.vmax); 6389 PIPE_CONF_CHECK_I(vrr.flipline); 6390 PIPE_CONF_CHECK_I(vrr.pipeline_full); 6391 PIPE_CONF_CHECK_I(vrr.guardband); 6392 6393 #undef PIPE_CONF_CHECK_X 6394 #undef PIPE_CONF_CHECK_I 6395 #undef PIPE_CONF_CHECK_BOOL 6396 #undef PIPE_CONF_CHECK_BOOL_INCOMPLETE 6397 #undef PIPE_CONF_CHECK_P 6398 #undef PIPE_CONF_CHECK_FLAGS 6399 #undef PIPE_CONF_CHECK_CLOCK_FUZZY 6400 #undef PIPE_CONF_CHECK_COLOR_LUT 6401 #undef PIPE_CONF_CHECK_TIMINGS 6402 #undef PIPE_CONF_CHECK_RECT 6403 #undef PIPE_CONF_QUIRK 6404 6405 return ret; 6406 } 6407 6408 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, 6409 const struct intel_crtc_state *pipe_config) 6410 { 6411 if (pipe_config->has_pch_encoder) { 6412 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), 6413 &pipe_config->fdi_m_n); 6414 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock; 6415 6416 /* 6417 * FDI already provided one idea for the dotclock. 6418 * Yell if the encoder disagrees. 6419 */ 6420 drm_WARN(&dev_priv->drm, 6421 !intel_fuzzy_clock_check(fdi_dotclock, dotclock), 6422 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", 6423 fdi_dotclock, dotclock); 6424 } 6425 } 6426 6427 static void 6428 verify_connector_state(struct intel_atomic_state *state, 6429 struct intel_crtc *crtc) 6430 { 6431 struct drm_connector *connector; 6432 struct drm_connector_state *new_conn_state; 6433 int i; 6434 6435 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) { 6436 struct drm_encoder *encoder = connector->encoder; 6437 struct intel_crtc_state *crtc_state = NULL; 6438 6439 if (new_conn_state->crtc != &crtc->base) 6440 continue; 6441 6442 if (crtc) 6443 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 6444 6445 intel_connector_verify_state(crtc_state, new_conn_state); 6446 6447 I915_STATE_WARN(new_conn_state->best_encoder != encoder, 6448 "connector's atomic encoder doesn't match legacy encoder\n"); 6449 } 6450 } 6451 6452 static void 6453 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state) 6454 { 6455 struct intel_encoder *encoder; 6456 struct drm_connector *connector; 6457 struct drm_connector_state *old_conn_state, *new_conn_state; 6458 int i; 6459 6460 for_each_intel_encoder(&dev_priv->drm, encoder) { 6461 bool enabled = false, found = false; 6462 enum pipe pipe; 6463 6464 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n", 6465 encoder->base.base.id, 6466 encoder->base.name); 6467 6468 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state, 6469 new_conn_state, i) { 6470 if (old_conn_state->best_encoder == &encoder->base) 6471 found = true; 6472 6473 if (new_conn_state->best_encoder != &encoder->base) 6474 continue; 6475 found = enabled = true; 6476 6477 I915_STATE_WARN(new_conn_state->crtc != 6478 encoder->base.crtc, 6479 "connector's crtc doesn't match encoder crtc\n"); 6480 } 6481 6482 if (!found) 6483 continue; 6484 6485 I915_STATE_WARN(!!encoder->base.crtc != enabled, 6486 "encoder's enabled state mismatch " 6487 "(expected %i, found %i)\n", 6488 !!encoder->base.crtc, enabled); 6489 6490 if (!encoder->base.crtc) { 6491 bool active; 6492 6493 active = encoder->get_hw_state(encoder, &pipe); 6494 I915_STATE_WARN(active, 6495 "encoder detached but still enabled on pipe %c.\n", 6496 pipe_name(pipe)); 6497 } 6498 } 6499 } 6500 6501 static void 6502 verify_crtc_state(struct intel_crtc *crtc, 6503 struct intel_crtc_state *old_crtc_state, 6504 struct intel_crtc_state *new_crtc_state) 6505 { 6506 struct drm_device *dev = crtc->base.dev; 6507 struct drm_i915_private *dev_priv = to_i915(dev); 6508 struct intel_encoder *encoder; 6509 struct intel_crtc_state *pipe_config = old_crtc_state; 6510 struct drm_atomic_state *state = old_crtc_state->uapi.state; 6511 struct intel_crtc *master_crtc; 6512 6513 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi); 6514 intel_crtc_free_hw_state(old_crtc_state); 6515 intel_crtc_state_reset(old_crtc_state, crtc); 6516 old_crtc_state->uapi.state = state; 6517 6518 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id, 6519 crtc->base.name); 6520 6521 pipe_config->hw.enable = new_crtc_state->hw.enable; 6522 6523 intel_crtc_get_pipe_config(pipe_config); 6524 6525 /* we keep both pipes enabled on 830 */ 6526 if (IS_I830(dev_priv) && pipe_config->hw.active) 6527 pipe_config->hw.active = new_crtc_state->hw.active; 6528 6529 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active, 6530 "crtc active state doesn't match with hw state " 6531 "(expected %i, found %i)\n", 6532 new_crtc_state->hw.active, pipe_config->hw.active); 6533 6534 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active, 6535 "transitional active state does not match atomic hw state " 6536 "(expected %i, found %i)\n", 6537 new_crtc_state->hw.active, crtc->active); 6538 6539 master_crtc = intel_master_crtc(new_crtc_state); 6540 6541 for_each_encoder_on_crtc(dev, &master_crtc->base, encoder) { 6542 enum pipe pipe; 6543 bool active; 6544 6545 active = encoder->get_hw_state(encoder, &pipe); 6546 I915_STATE_WARN(active != new_crtc_state->hw.active, 6547 "[ENCODER:%i] active %i with crtc active %i\n", 6548 encoder->base.base.id, active, 6549 new_crtc_state->hw.active); 6550 6551 I915_STATE_WARN(active && master_crtc->pipe != pipe, 6552 "Encoder connected to wrong pipe %c\n", 6553 pipe_name(pipe)); 6554 6555 if (active) 6556 intel_encoder_get_config(encoder, pipe_config); 6557 } 6558 6559 if (!new_crtc_state->hw.active) 6560 return; 6561 6562 intel_pipe_config_sanity_check(dev_priv, pipe_config); 6563 6564 if (!intel_pipe_config_compare(new_crtc_state, 6565 pipe_config, false)) { 6566 I915_STATE_WARN(1, "pipe state doesn't match!\n"); 6567 intel_dump_pipe_config(pipe_config, NULL, "[hw state]"); 6568 intel_dump_pipe_config(new_crtc_state, NULL, "[sw state]"); 6569 } 6570 } 6571 6572 static void 6573 intel_verify_planes(struct intel_atomic_state *state) 6574 { 6575 struct intel_plane *plane; 6576 const struct intel_plane_state *plane_state; 6577 int i; 6578 6579 for_each_new_intel_plane_in_state(state, plane, 6580 plane_state, i) 6581 assert_plane(plane, plane_state->planar_slave || 6582 plane_state->uapi.visible); 6583 } 6584 6585 static void 6586 intel_modeset_verify_crtc(struct intel_crtc *crtc, 6587 struct intel_atomic_state *state, 6588 struct intel_crtc_state *old_crtc_state, 6589 struct intel_crtc_state *new_crtc_state) 6590 { 6591 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe) 6592 return; 6593 6594 intel_wm_state_verify(crtc, new_crtc_state); 6595 verify_connector_state(state, crtc); 6596 verify_crtc_state(crtc, old_crtc_state, new_crtc_state); 6597 intel_shared_dpll_state_verify(crtc, old_crtc_state, new_crtc_state); 6598 intel_mpllb_state_verify(state, new_crtc_state); 6599 } 6600 6601 static void 6602 intel_modeset_verify_disabled(struct drm_i915_private *dev_priv, 6603 struct intel_atomic_state *state) 6604 { 6605 verify_encoder_state(dev_priv, state); 6606 verify_connector_state(state, NULL); 6607 intel_shared_dpll_verify_disabled(dev_priv); 6608 } 6609 6610 int intel_modeset_all_pipes(struct intel_atomic_state *state) 6611 { 6612 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 6613 struct intel_crtc *crtc; 6614 6615 /* 6616 * Add all pipes to the state, and force 6617 * a modeset on all the active ones. 6618 */ 6619 for_each_intel_crtc(&dev_priv->drm, crtc) { 6620 struct intel_crtc_state *crtc_state; 6621 int ret; 6622 6623 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6624 if (IS_ERR(crtc_state)) 6625 return PTR_ERR(crtc_state); 6626 6627 if (!crtc_state->hw.active || 6628 drm_atomic_crtc_needs_modeset(&crtc_state->uapi)) 6629 continue; 6630 6631 crtc_state->uapi.mode_changed = true; 6632 6633 ret = drm_atomic_add_affected_connectors(&state->base, 6634 &crtc->base); 6635 if (ret) 6636 return ret; 6637 6638 ret = intel_atomic_add_affected_planes(state, crtc); 6639 if (ret) 6640 return ret; 6641 6642 crtc_state->update_planes |= crtc_state->active_planes; 6643 } 6644 6645 return 0; 6646 } 6647 6648 static void 6649 intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state) 6650 { 6651 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 6652 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 6653 struct drm_display_mode adjusted_mode; 6654 6655 drm_mode_init(&adjusted_mode, &crtc_state->hw.adjusted_mode); 6656 6657 if (crtc_state->vrr.enable) { 6658 adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax; 6659 adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax; 6660 adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state); 6661 crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state); 6662 } 6663 6664 drm_calc_timestamping_constants(&crtc->base, &adjusted_mode); 6665 6666 crtc->mode_flags = crtc_state->mode_flags; 6667 6668 /* 6669 * The scanline counter increments at the leading edge of hsync. 6670 * 6671 * On most platforms it starts counting from vtotal-1 on the 6672 * first active line. That means the scanline counter value is 6673 * always one less than what we would expect. Ie. just after 6674 * start of vblank, which also occurs at start of hsync (on the 6675 * last active line), the scanline counter will read vblank_start-1. 6676 * 6677 * On gen2 the scanline counter starts counting from 1 instead 6678 * of vtotal-1, so we have to subtract one (or rather add vtotal-1 6679 * to keep the value positive), instead of adding one. 6680 * 6681 * On HSW+ the behaviour of the scanline counter depends on the output 6682 * type. For DP ports it behaves like most other platforms, but on HDMI 6683 * there's an extra 1 line difference. So we need to add two instead of 6684 * one to the value. 6685 * 6686 * On VLV/CHV DSI the scanline counter would appear to increment 6687 * approx. 1/3 of a scanline before start of vblank. Unfortunately 6688 * that means we can't tell whether we're in vblank or not while 6689 * we're on that particular line. We must still set scanline_offset 6690 * to 1 so that the vblank timestamps come out correct when we query 6691 * the scanline counter from within the vblank interrupt handler. 6692 * However if queried just before the start of vblank we'll get an 6693 * answer that's slightly in the future. 6694 */ 6695 if (DISPLAY_VER(dev_priv) == 2) { 6696 int vtotal; 6697 6698 vtotal = adjusted_mode.crtc_vtotal; 6699 if (adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) 6700 vtotal /= 2; 6701 6702 crtc->scanline_offset = vtotal - 1; 6703 } else if (HAS_DDI(dev_priv) && 6704 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 6705 crtc->scanline_offset = 2; 6706 } else { 6707 crtc->scanline_offset = 1; 6708 } 6709 } 6710 6711 static void intel_modeset_clear_plls(struct intel_atomic_state *state) 6712 { 6713 struct intel_crtc_state *new_crtc_state; 6714 struct intel_crtc *crtc; 6715 int i; 6716 6717 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6718 if (!intel_crtc_needs_modeset(new_crtc_state)) 6719 continue; 6720 6721 intel_release_shared_dplls(state, crtc); 6722 } 6723 } 6724 6725 /* 6726 * This implements the workaround described in the "notes" section of the mode 6727 * set sequence documentation. When going from no pipes or single pipe to 6728 * multiple pipes, and planes are enabled after the pipe, we need to wait at 6729 * least 2 vblanks on the first pipe before enabling planes on the second pipe. 6730 */ 6731 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state) 6732 { 6733 struct intel_crtc_state *crtc_state; 6734 struct intel_crtc *crtc; 6735 struct intel_crtc_state *first_crtc_state = NULL; 6736 struct intel_crtc_state *other_crtc_state = NULL; 6737 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; 6738 int i; 6739 6740 /* look at all crtc's that are going to be enabled in during modeset */ 6741 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6742 if (!crtc_state->hw.active || 6743 !intel_crtc_needs_modeset(crtc_state)) 6744 continue; 6745 6746 if (first_crtc_state) { 6747 other_crtc_state = crtc_state; 6748 break; 6749 } else { 6750 first_crtc_state = crtc_state; 6751 first_pipe = crtc->pipe; 6752 } 6753 } 6754 6755 /* No workaround needed? */ 6756 if (!first_crtc_state) 6757 return 0; 6758 6759 /* w/a possibly needed, check how many crtc's are already enabled. */ 6760 for_each_intel_crtc(state->base.dev, crtc) { 6761 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6762 if (IS_ERR(crtc_state)) 6763 return PTR_ERR(crtc_state); 6764 6765 crtc_state->hsw_workaround_pipe = INVALID_PIPE; 6766 6767 if (!crtc_state->hw.active || 6768 intel_crtc_needs_modeset(crtc_state)) 6769 continue; 6770 6771 /* 2 or more enabled crtcs means no need for w/a */ 6772 if (enabled_pipe != INVALID_PIPE) 6773 return 0; 6774 6775 enabled_pipe = crtc->pipe; 6776 } 6777 6778 if (enabled_pipe != INVALID_PIPE) 6779 first_crtc_state->hsw_workaround_pipe = enabled_pipe; 6780 else if (other_crtc_state) 6781 other_crtc_state->hsw_workaround_pipe = first_pipe; 6782 6783 return 0; 6784 } 6785 6786 u8 intel_calc_active_pipes(struct intel_atomic_state *state, 6787 u8 active_pipes) 6788 { 6789 const struct intel_crtc_state *crtc_state; 6790 struct intel_crtc *crtc; 6791 int i; 6792 6793 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6794 if (crtc_state->hw.active) 6795 active_pipes |= BIT(crtc->pipe); 6796 else 6797 active_pipes &= ~BIT(crtc->pipe); 6798 } 6799 6800 return active_pipes; 6801 } 6802 6803 static int intel_modeset_checks(struct intel_atomic_state *state) 6804 { 6805 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 6806 6807 state->modeset = true; 6808 6809 if (IS_HASWELL(dev_priv)) 6810 return hsw_mode_set_planes_workaround(state); 6811 6812 return 0; 6813 } 6814 6815 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state, 6816 struct intel_crtc_state *new_crtc_state) 6817 { 6818 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true)) 6819 return; 6820 6821 new_crtc_state->uapi.mode_changed = false; 6822 new_crtc_state->update_pipe = true; 6823 } 6824 6825 static void intel_crtc_copy_fastset(const struct intel_crtc_state *old_crtc_state, 6826 struct intel_crtc_state *new_crtc_state) 6827 { 6828 /* 6829 * If we're not doing the full modeset we want to 6830 * keep the current M/N values as they may be 6831 * sufficiently different to the computed values 6832 * to cause problems. 6833 * 6834 * FIXME: should really copy more fuzzy state here 6835 */ 6836 new_crtc_state->fdi_m_n = old_crtc_state->fdi_m_n; 6837 new_crtc_state->dp_m_n = old_crtc_state->dp_m_n; 6838 new_crtc_state->dp_m2_n2 = old_crtc_state->dp_m2_n2; 6839 new_crtc_state->has_drrs = old_crtc_state->has_drrs; 6840 } 6841 6842 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state, 6843 struct intel_crtc *crtc, 6844 u8 plane_ids_mask) 6845 { 6846 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 6847 struct intel_plane *plane; 6848 6849 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { 6850 struct intel_plane_state *plane_state; 6851 6852 if ((plane_ids_mask & BIT(plane->id)) == 0) 6853 continue; 6854 6855 plane_state = intel_atomic_get_plane_state(state, plane); 6856 if (IS_ERR(plane_state)) 6857 return PTR_ERR(plane_state); 6858 } 6859 6860 return 0; 6861 } 6862 6863 int intel_atomic_add_affected_planes(struct intel_atomic_state *state, 6864 struct intel_crtc *crtc) 6865 { 6866 const struct intel_crtc_state *old_crtc_state = 6867 intel_atomic_get_old_crtc_state(state, crtc); 6868 const struct intel_crtc_state *new_crtc_state = 6869 intel_atomic_get_new_crtc_state(state, crtc); 6870 6871 return intel_crtc_add_planes_to_state(state, crtc, 6872 old_crtc_state->enabled_planes | 6873 new_crtc_state->enabled_planes); 6874 } 6875 6876 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv) 6877 { 6878 /* See {hsw,vlv,ivb}_plane_ratio() */ 6879 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) || 6880 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) || 6881 IS_IVYBRIDGE(dev_priv); 6882 } 6883 6884 static int intel_crtc_add_bigjoiner_planes(struct intel_atomic_state *state, 6885 struct intel_crtc *crtc, 6886 struct intel_crtc *other) 6887 { 6888 const struct intel_plane_state *plane_state; 6889 struct intel_plane *plane; 6890 u8 plane_ids = 0; 6891 int i; 6892 6893 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 6894 if (plane->pipe == crtc->pipe) 6895 plane_ids |= BIT(plane->id); 6896 } 6897 6898 return intel_crtc_add_planes_to_state(state, other, plane_ids); 6899 } 6900 6901 static int intel_bigjoiner_add_affected_planes(struct intel_atomic_state *state) 6902 { 6903 struct drm_i915_private *i915 = to_i915(state->base.dev); 6904 const struct intel_crtc_state *crtc_state; 6905 struct intel_crtc *crtc; 6906 int i; 6907 6908 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6909 struct intel_crtc *other; 6910 6911 for_each_intel_crtc_in_pipe_mask(&i915->drm, other, 6912 crtc_state->bigjoiner_pipes) { 6913 int ret; 6914 6915 if (crtc == other) 6916 continue; 6917 6918 ret = intel_crtc_add_bigjoiner_planes(state, crtc, other); 6919 if (ret) 6920 return ret; 6921 } 6922 } 6923 6924 return 0; 6925 } 6926 6927 static int intel_atomic_check_planes(struct intel_atomic_state *state) 6928 { 6929 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 6930 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 6931 struct intel_plane_state *plane_state; 6932 struct intel_plane *plane; 6933 struct intel_crtc *crtc; 6934 int i, ret; 6935 6936 ret = icl_add_linked_planes(state); 6937 if (ret) 6938 return ret; 6939 6940 ret = intel_bigjoiner_add_affected_planes(state); 6941 if (ret) 6942 return ret; 6943 6944 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 6945 ret = intel_plane_atomic_check(state, plane); 6946 if (ret) { 6947 drm_dbg_atomic(&dev_priv->drm, 6948 "[PLANE:%d:%s] atomic driver check failed\n", 6949 plane->base.base.id, plane->base.name); 6950 return ret; 6951 } 6952 } 6953 6954 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6955 new_crtc_state, i) { 6956 u8 old_active_planes, new_active_planes; 6957 6958 ret = icl_check_nv12_planes(new_crtc_state); 6959 if (ret) 6960 return ret; 6961 6962 /* 6963 * On some platforms the number of active planes affects 6964 * the planes' minimum cdclk calculation. Add such planes 6965 * to the state before we compute the minimum cdclk. 6966 */ 6967 if (!active_planes_affects_min_cdclk(dev_priv)) 6968 continue; 6969 6970 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR); 6971 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR); 6972 6973 if (hweight8(old_active_planes) == hweight8(new_active_planes)) 6974 continue; 6975 6976 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes); 6977 if (ret) 6978 return ret; 6979 } 6980 6981 return 0; 6982 } 6983 6984 static int intel_atomic_check_crtcs(struct intel_atomic_state *state) 6985 { 6986 struct intel_crtc_state *crtc_state; 6987 struct intel_crtc *crtc; 6988 int i; 6989 6990 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6991 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 6992 int ret; 6993 6994 ret = intel_crtc_atomic_check(state, crtc); 6995 if (ret) { 6996 drm_dbg_atomic(&i915->drm, 6997 "[CRTC:%d:%s] atomic driver check failed\n", 6998 crtc->base.base.id, crtc->base.name); 6999 return ret; 7000 } 7001 } 7002 7003 return 0; 7004 } 7005 7006 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state, 7007 u8 transcoders) 7008 { 7009 const struct intel_crtc_state *new_crtc_state; 7010 struct intel_crtc *crtc; 7011 int i; 7012 7013 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7014 if (new_crtc_state->hw.enable && 7015 transcoders & BIT(new_crtc_state->cpu_transcoder) && 7016 intel_crtc_needs_modeset(new_crtc_state)) 7017 return true; 7018 } 7019 7020 return false; 7021 } 7022 7023 static bool intel_pipes_need_modeset(struct intel_atomic_state *state, 7024 u8 pipes) 7025 { 7026 const struct intel_crtc_state *new_crtc_state; 7027 struct intel_crtc *crtc; 7028 int i; 7029 7030 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7031 if (new_crtc_state->hw.enable && 7032 pipes & BIT(crtc->pipe) && 7033 intel_crtc_needs_modeset(new_crtc_state)) 7034 return true; 7035 } 7036 7037 return false; 7038 } 7039 7040 static int intel_atomic_check_bigjoiner(struct intel_atomic_state *state, 7041 struct intel_crtc *master_crtc) 7042 { 7043 struct drm_i915_private *i915 = to_i915(state->base.dev); 7044 struct intel_crtc_state *master_crtc_state = 7045 intel_atomic_get_new_crtc_state(state, master_crtc); 7046 struct intel_crtc *slave_crtc; 7047 7048 if (!master_crtc_state->bigjoiner_pipes) 7049 return 0; 7050 7051 /* sanity check */ 7052 if (drm_WARN_ON(&i915->drm, 7053 master_crtc->pipe != bigjoiner_master_pipe(master_crtc_state))) 7054 return -EINVAL; 7055 7056 if (master_crtc_state->bigjoiner_pipes & ~bigjoiner_pipes(i915)) { 7057 drm_dbg_kms(&i915->drm, 7058 "[CRTC:%d:%s] Cannot act as big joiner master " 7059 "(need 0x%x as pipes, only 0x%x possible)\n", 7060 master_crtc->base.base.id, master_crtc->base.name, 7061 master_crtc_state->bigjoiner_pipes, bigjoiner_pipes(i915)); 7062 return -EINVAL; 7063 } 7064 7065 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc, 7066 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) { 7067 struct intel_crtc_state *slave_crtc_state; 7068 int ret; 7069 7070 slave_crtc_state = intel_atomic_get_crtc_state(&state->base, slave_crtc); 7071 if (IS_ERR(slave_crtc_state)) 7072 return PTR_ERR(slave_crtc_state); 7073 7074 /* master being enabled, slave was already configured? */ 7075 if (slave_crtc_state->uapi.enable) { 7076 drm_dbg_kms(&i915->drm, 7077 "[CRTC:%d:%s] Slave is enabled as normal CRTC, but " 7078 "[CRTC:%d:%s] claiming this CRTC for bigjoiner.\n", 7079 slave_crtc->base.base.id, slave_crtc->base.name, 7080 master_crtc->base.base.id, master_crtc->base.name); 7081 return -EINVAL; 7082 } 7083 7084 /* 7085 * The state copy logic assumes the master crtc gets processed 7086 * before the slave crtc during the main compute_config loop. 7087 * This works because the crtcs are created in pipe order, 7088 * and the hardware requires master pipe < slave pipe as well. 7089 * Should that change we need to rethink the logic. 7090 */ 7091 if (WARN_ON(drm_crtc_index(&master_crtc->base) > 7092 drm_crtc_index(&slave_crtc->base))) 7093 return -EINVAL; 7094 7095 drm_dbg_kms(&i915->drm, 7096 "[CRTC:%d:%s] Used as slave for big joiner master [CRTC:%d:%s]\n", 7097 slave_crtc->base.base.id, slave_crtc->base.name, 7098 master_crtc->base.base.id, master_crtc->base.name); 7099 7100 slave_crtc_state->bigjoiner_pipes = 7101 master_crtc_state->bigjoiner_pipes; 7102 7103 ret = copy_bigjoiner_crtc_state_modeset(state, slave_crtc); 7104 if (ret) 7105 return ret; 7106 } 7107 7108 return 0; 7109 } 7110 7111 static void kill_bigjoiner_slave(struct intel_atomic_state *state, 7112 struct intel_crtc *master_crtc) 7113 { 7114 struct drm_i915_private *i915 = to_i915(state->base.dev); 7115 struct intel_crtc_state *master_crtc_state = 7116 intel_atomic_get_new_crtc_state(state, master_crtc); 7117 struct intel_crtc *slave_crtc; 7118 7119 for_each_intel_crtc_in_pipe_mask(&i915->drm, slave_crtc, 7120 intel_crtc_bigjoiner_slave_pipes(master_crtc_state)) { 7121 struct intel_crtc_state *slave_crtc_state = 7122 intel_atomic_get_new_crtc_state(state, slave_crtc); 7123 7124 slave_crtc_state->bigjoiner_pipes = 0; 7125 7126 intel_crtc_copy_uapi_to_hw_state_modeset(state, slave_crtc); 7127 } 7128 7129 master_crtc_state->bigjoiner_pipes = 0; 7130 } 7131 7132 /** 7133 * DOC: asynchronous flip implementation 7134 * 7135 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC 7136 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL. 7137 * Correspondingly, support is currently added for primary plane only. 7138 * 7139 * Async flip can only change the plane surface address, so anything else 7140 * changing is rejected from the intel_async_flip_check_hw() function. 7141 * Once this check is cleared, flip done interrupt is enabled using 7142 * the intel_crtc_enable_flip_done() function. 7143 * 7144 * As soon as the surface address register is written, flip done interrupt is 7145 * generated and the requested events are sent to the usersapce in the interrupt 7146 * handler itself. The timestamp and sequence sent during the flip done event 7147 * correspond to the last vblank and have no relation to the actual time when 7148 * the flip done event was sent. 7149 */ 7150 static int intel_async_flip_check_uapi(struct intel_atomic_state *state, 7151 struct intel_crtc *crtc) 7152 { 7153 struct drm_i915_private *i915 = to_i915(state->base.dev); 7154 const struct intel_crtc_state *new_crtc_state = 7155 intel_atomic_get_new_crtc_state(state, crtc); 7156 const struct intel_plane_state *old_plane_state; 7157 struct intel_plane_state *new_plane_state; 7158 struct intel_plane *plane; 7159 int i; 7160 7161 if (!new_crtc_state->uapi.async_flip) 7162 return 0; 7163 7164 if (!new_crtc_state->uapi.active) { 7165 drm_dbg_kms(&i915->drm, 7166 "[CRTC:%d:%s] not active\n", 7167 crtc->base.base.id, crtc->base.name); 7168 return -EINVAL; 7169 } 7170 7171 if (intel_crtc_needs_modeset(new_crtc_state)) { 7172 drm_dbg_kms(&i915->drm, 7173 "[CRTC:%d:%s] modeset required\n", 7174 crtc->base.base.id, crtc->base.name); 7175 return -EINVAL; 7176 } 7177 7178 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 7179 new_plane_state, i) { 7180 if (plane->pipe != crtc->pipe) 7181 continue; 7182 7183 /* 7184 * TODO: Async flip is only supported through the page flip IOCTL 7185 * as of now. So support currently added for primary plane only. 7186 * Support for other planes on platforms on which supports 7187 * this(vlv/chv and icl+) should be added when async flip is 7188 * enabled in the atomic IOCTL path. 7189 */ 7190 if (!plane->async_flip) { 7191 drm_dbg_kms(&i915->drm, 7192 "[PLANE:%d:%s] async flip not supported\n", 7193 plane->base.base.id, plane->base.name); 7194 return -EINVAL; 7195 } 7196 7197 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) { 7198 drm_dbg_kms(&i915->drm, 7199 "[PLANE:%d:%s] no old or new framebuffer\n", 7200 plane->base.base.id, plane->base.name); 7201 return -EINVAL; 7202 } 7203 } 7204 7205 return 0; 7206 } 7207 7208 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc) 7209 { 7210 struct drm_i915_private *i915 = to_i915(state->base.dev); 7211 const struct intel_crtc_state *old_crtc_state, *new_crtc_state; 7212 const struct intel_plane_state *new_plane_state, *old_plane_state; 7213 struct intel_plane *plane; 7214 int i; 7215 7216 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc); 7217 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 7218 7219 if (!new_crtc_state->uapi.async_flip) 7220 return 0; 7221 7222 if (!new_crtc_state->hw.active) { 7223 drm_dbg_kms(&i915->drm, 7224 "[CRTC:%d:%s] not active\n", 7225 crtc->base.base.id, crtc->base.name); 7226 return -EINVAL; 7227 } 7228 7229 if (intel_crtc_needs_modeset(new_crtc_state)) { 7230 drm_dbg_kms(&i915->drm, 7231 "[CRTC:%d:%s] modeset required\n", 7232 crtc->base.base.id, crtc->base.name); 7233 return -EINVAL; 7234 } 7235 7236 if (old_crtc_state->active_planes != new_crtc_state->active_planes) { 7237 drm_dbg_kms(&i915->drm, 7238 "[CRTC:%d:%s] Active planes cannot be in async flip\n", 7239 crtc->base.base.id, crtc->base.name); 7240 return -EINVAL; 7241 } 7242 7243 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 7244 new_plane_state, i) { 7245 if (plane->pipe != crtc->pipe) 7246 continue; 7247 7248 /* 7249 * Only async flip capable planes should be in the state 7250 * if we're really about to ask the hardware to perform 7251 * an async flip. We should never get this far otherwise. 7252 */ 7253 if (drm_WARN_ON(&i915->drm, 7254 new_crtc_state->do_async_flip && !plane->async_flip)) 7255 return -EINVAL; 7256 7257 /* 7258 * Only check async flip capable planes other planes 7259 * may be involved in the initial commit due to 7260 * the wm0/ddb optimization. 7261 * 7262 * TODO maybe should track which planes actually 7263 * were requested to do the async flip... 7264 */ 7265 if (!plane->async_flip) 7266 continue; 7267 7268 /* 7269 * FIXME: This check is kept generic for all platforms. 7270 * Need to verify this for all gen9 platforms to enable 7271 * this selectively if required. 7272 */ 7273 switch (new_plane_state->hw.fb->modifier) { 7274 case I915_FORMAT_MOD_X_TILED: 7275 case I915_FORMAT_MOD_Y_TILED: 7276 case I915_FORMAT_MOD_Yf_TILED: 7277 case I915_FORMAT_MOD_4_TILED: 7278 break; 7279 default: 7280 drm_dbg_kms(&i915->drm, 7281 "[PLANE:%d:%s] Modifier does not support async flips\n", 7282 plane->base.base.id, plane->base.name); 7283 return -EINVAL; 7284 } 7285 7286 if (new_plane_state->hw.fb->format->num_planes > 1) { 7287 drm_dbg_kms(&i915->drm, 7288 "[PLANE:%d:%s] Planar formats do not support async flips\n", 7289 plane->base.base.id, plane->base.name); 7290 return -EINVAL; 7291 } 7292 7293 if (old_plane_state->view.color_plane[0].mapping_stride != 7294 new_plane_state->view.color_plane[0].mapping_stride) { 7295 drm_dbg_kms(&i915->drm, 7296 "[PLANE:%d:%s] Stride cannot be changed in async flip\n", 7297 plane->base.base.id, plane->base.name); 7298 return -EINVAL; 7299 } 7300 7301 if (old_plane_state->hw.fb->modifier != 7302 new_plane_state->hw.fb->modifier) { 7303 drm_dbg_kms(&i915->drm, 7304 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n", 7305 plane->base.base.id, plane->base.name); 7306 return -EINVAL; 7307 } 7308 7309 if (old_plane_state->hw.fb->format != 7310 new_plane_state->hw.fb->format) { 7311 drm_dbg_kms(&i915->drm, 7312 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n", 7313 plane->base.base.id, plane->base.name); 7314 return -EINVAL; 7315 } 7316 7317 if (old_plane_state->hw.rotation != 7318 new_plane_state->hw.rotation) { 7319 drm_dbg_kms(&i915->drm, 7320 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n", 7321 plane->base.base.id, plane->base.name); 7322 return -EINVAL; 7323 } 7324 7325 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) || 7326 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) { 7327 drm_dbg_kms(&i915->drm, 7328 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n", 7329 plane->base.base.id, plane->base.name); 7330 return -EINVAL; 7331 } 7332 7333 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) { 7334 drm_dbg_kms(&i915->drm, 7335 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n", 7336 plane->base.base.id, plane->base.name); 7337 return -EINVAL; 7338 } 7339 7340 if (old_plane_state->hw.pixel_blend_mode != 7341 new_plane_state->hw.pixel_blend_mode) { 7342 drm_dbg_kms(&i915->drm, 7343 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n", 7344 plane->base.base.id, plane->base.name); 7345 return -EINVAL; 7346 } 7347 7348 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) { 7349 drm_dbg_kms(&i915->drm, 7350 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n", 7351 plane->base.base.id, plane->base.name); 7352 return -EINVAL; 7353 } 7354 7355 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) { 7356 drm_dbg_kms(&i915->drm, 7357 "[PLANE:%d:%s] Color range cannot be changed in async flip\n", 7358 plane->base.base.id, plane->base.name); 7359 return -EINVAL; 7360 } 7361 7362 /* plane decryption is allow to change only in synchronous flips */ 7363 if (old_plane_state->decrypt != new_plane_state->decrypt) { 7364 drm_dbg_kms(&i915->drm, 7365 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n", 7366 plane->base.base.id, plane->base.name); 7367 return -EINVAL; 7368 } 7369 } 7370 7371 return 0; 7372 } 7373 7374 static int intel_bigjoiner_add_affected_crtcs(struct intel_atomic_state *state) 7375 { 7376 struct drm_i915_private *i915 = to_i915(state->base.dev); 7377 struct intel_crtc_state *crtc_state; 7378 struct intel_crtc *crtc; 7379 u8 affected_pipes = 0; 7380 u8 modeset_pipes = 0; 7381 int i; 7382 7383 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 7384 affected_pipes |= crtc_state->bigjoiner_pipes; 7385 if (intel_crtc_needs_modeset(crtc_state)) 7386 modeset_pipes |= crtc_state->bigjoiner_pipes; 7387 } 7388 7389 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) { 7390 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 7391 if (IS_ERR(crtc_state)) 7392 return PTR_ERR(crtc_state); 7393 } 7394 7395 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) { 7396 int ret; 7397 7398 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 7399 7400 crtc_state->uapi.mode_changed = true; 7401 7402 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base); 7403 if (ret) 7404 return ret; 7405 7406 ret = intel_atomic_add_affected_planes(state, crtc); 7407 if (ret) 7408 return ret; 7409 } 7410 7411 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 7412 /* Kill old bigjoiner link, we may re-establish afterwards */ 7413 if (intel_crtc_needs_modeset(crtc_state) && 7414 intel_crtc_is_bigjoiner_master(crtc_state)) 7415 kill_bigjoiner_slave(state, crtc); 7416 } 7417 7418 return 0; 7419 } 7420 7421 /** 7422 * intel_atomic_check - validate state object 7423 * @dev: drm device 7424 * @_state: state to validate 7425 */ 7426 static int intel_atomic_check(struct drm_device *dev, 7427 struct drm_atomic_state *_state) 7428 { 7429 struct drm_i915_private *dev_priv = to_i915(dev); 7430 struct intel_atomic_state *state = to_intel_atomic_state(_state); 7431 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 7432 struct intel_crtc *crtc; 7433 int ret, i; 7434 bool any_ms = false; 7435 7436 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7437 new_crtc_state, i) { 7438 if (new_crtc_state->inherited != old_crtc_state->inherited) 7439 new_crtc_state->uapi.mode_changed = true; 7440 7441 if (new_crtc_state->uapi.scaling_filter != 7442 old_crtc_state->uapi.scaling_filter) 7443 new_crtc_state->uapi.mode_changed = true; 7444 } 7445 7446 intel_vrr_check_modeset(state); 7447 7448 ret = drm_atomic_helper_check_modeset(dev, &state->base); 7449 if (ret) 7450 goto fail; 7451 7452 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7453 ret = intel_async_flip_check_uapi(state, crtc); 7454 if (ret) 7455 return ret; 7456 } 7457 7458 ret = intel_bigjoiner_add_affected_crtcs(state); 7459 if (ret) 7460 goto fail; 7461 7462 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7463 new_crtc_state, i) { 7464 if (!intel_crtc_needs_modeset(new_crtc_state)) { 7465 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) 7466 copy_bigjoiner_crtc_state_nomodeset(state, crtc); 7467 else 7468 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc); 7469 continue; 7470 } 7471 7472 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) { 7473 drm_WARN_ON(&dev_priv->drm, new_crtc_state->uapi.enable); 7474 continue; 7475 } 7476 7477 ret = intel_crtc_prepare_cleared_state(state, crtc); 7478 if (ret) 7479 goto fail; 7480 7481 if (!new_crtc_state->hw.enable) 7482 continue; 7483 7484 ret = intel_modeset_pipe_config(state, crtc); 7485 if (ret) 7486 goto fail; 7487 7488 ret = intel_atomic_check_bigjoiner(state, crtc); 7489 if (ret) 7490 goto fail; 7491 } 7492 7493 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7494 new_crtc_state, i) { 7495 if (!intel_crtc_needs_modeset(new_crtc_state)) 7496 continue; 7497 7498 ret = intel_modeset_pipe_config_late(state, crtc); 7499 if (ret) 7500 goto fail; 7501 7502 intel_crtc_check_fastset(old_crtc_state, new_crtc_state); 7503 } 7504 7505 /** 7506 * Check if fastset is allowed by external dependencies like other 7507 * pipes and transcoders. 7508 * 7509 * Right now it only forces a fullmodeset when the MST master 7510 * transcoder did not changed but the pipe of the master transcoder 7511 * needs a fullmodeset so all slaves also needs to do a fullmodeset or 7512 * in case of port synced crtcs, if one of the synced crtcs 7513 * needs a full modeset, all other synced crtcs should be 7514 * forced a full modeset. 7515 */ 7516 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7517 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state)) 7518 continue; 7519 7520 if (intel_dp_mst_is_slave_trans(new_crtc_state)) { 7521 enum transcoder master = new_crtc_state->mst_master_transcoder; 7522 7523 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) { 7524 new_crtc_state->uapi.mode_changed = true; 7525 new_crtc_state->update_pipe = false; 7526 } 7527 } 7528 7529 if (is_trans_port_sync_mode(new_crtc_state)) { 7530 u8 trans = new_crtc_state->sync_mode_slaves_mask; 7531 7532 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER) 7533 trans |= BIT(new_crtc_state->master_transcoder); 7534 7535 if (intel_cpu_transcoders_need_modeset(state, trans)) { 7536 new_crtc_state->uapi.mode_changed = true; 7537 new_crtc_state->update_pipe = false; 7538 } 7539 } 7540 7541 if (new_crtc_state->bigjoiner_pipes) { 7542 if (intel_pipes_need_modeset(state, new_crtc_state->bigjoiner_pipes)) { 7543 new_crtc_state->uapi.mode_changed = true; 7544 new_crtc_state->update_pipe = false; 7545 } 7546 } 7547 } 7548 7549 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7550 new_crtc_state, i) { 7551 if (intel_crtc_needs_modeset(new_crtc_state)) { 7552 any_ms = true; 7553 continue; 7554 } 7555 7556 if (!new_crtc_state->update_pipe) 7557 continue; 7558 7559 intel_crtc_copy_fastset(old_crtc_state, new_crtc_state); 7560 } 7561 7562 if (any_ms && !check_digital_port_conflicts(state)) { 7563 drm_dbg_kms(&dev_priv->drm, 7564 "rejecting conflicting digital port configuration\n"); 7565 ret = -EINVAL; 7566 goto fail; 7567 } 7568 7569 ret = drm_dp_mst_atomic_check(&state->base); 7570 if (ret) 7571 goto fail; 7572 7573 ret = intel_atomic_check_planes(state); 7574 if (ret) 7575 goto fail; 7576 7577 ret = intel_compute_global_watermarks(state); 7578 if (ret) 7579 goto fail; 7580 7581 ret = intel_bw_atomic_check(state); 7582 if (ret) 7583 goto fail; 7584 7585 ret = intel_cdclk_atomic_check(state, &any_ms); 7586 if (ret) 7587 goto fail; 7588 7589 if (intel_any_crtc_needs_modeset(state)) 7590 any_ms = true; 7591 7592 if (any_ms) { 7593 ret = intel_modeset_checks(state); 7594 if (ret) 7595 goto fail; 7596 7597 ret = intel_modeset_calc_cdclk(state); 7598 if (ret) 7599 return ret; 7600 7601 intel_modeset_clear_plls(state); 7602 } 7603 7604 ret = intel_atomic_check_crtcs(state); 7605 if (ret) 7606 goto fail; 7607 7608 ret = intel_fbc_atomic_check(state); 7609 if (ret) 7610 goto fail; 7611 7612 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7613 new_crtc_state, i) { 7614 ret = intel_async_flip_check_hw(state, crtc); 7615 if (ret) 7616 goto fail; 7617 7618 if (!intel_crtc_needs_modeset(new_crtc_state) && 7619 !new_crtc_state->update_pipe) 7620 continue; 7621 7622 intel_dump_pipe_config(new_crtc_state, state, 7623 intel_crtc_needs_modeset(new_crtc_state) ? 7624 "[modeset]" : "[fastset]"); 7625 } 7626 7627 return 0; 7628 7629 fail: 7630 if (ret == -EDEADLK) 7631 return ret; 7632 7633 /* 7634 * FIXME would probably be nice to know which crtc specifically 7635 * caused the failure, in cases where we can pinpoint it. 7636 */ 7637 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7638 new_crtc_state, i) 7639 intel_dump_pipe_config(new_crtc_state, state, "[failed]"); 7640 7641 return ret; 7642 } 7643 7644 static int intel_atomic_prepare_commit(struct intel_atomic_state *state) 7645 { 7646 struct intel_crtc_state *crtc_state; 7647 struct intel_crtc *crtc; 7648 int i, ret; 7649 7650 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base); 7651 if (ret < 0) 7652 return ret; 7653 7654 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 7655 bool mode_changed = intel_crtc_needs_modeset(crtc_state); 7656 7657 if (mode_changed || crtc_state->update_pipe || 7658 crtc_state->uapi.color_mgmt_changed) { 7659 intel_dsb_prepare(crtc_state); 7660 } 7661 } 7662 7663 return 0; 7664 } 7665 7666 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, 7667 struct intel_crtc_state *crtc_state) 7668 { 7669 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 7670 7671 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes) 7672 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); 7673 7674 if (crtc_state->has_pch_encoder) { 7675 enum pipe pch_transcoder = 7676 intel_crtc_pch_transcoder(crtc); 7677 7678 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true); 7679 } 7680 } 7681 7682 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state, 7683 const struct intel_crtc_state *new_crtc_state) 7684 { 7685 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 7686 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 7687 7688 /* 7689 * Update pipe size and adjust fitter if needed: the reason for this is 7690 * that in compute_mode_changes we check the native mode (not the pfit 7691 * mode) to see if we can flip rather than do a full mode set. In the 7692 * fastboot case, we'll flip, but if we don't update the pipesrc and 7693 * pfit state, we'll end up with a big fb scanned out into the wrong 7694 * sized surface. 7695 */ 7696 intel_set_pipe_src_size(new_crtc_state); 7697 7698 /* on skylake this is done by detaching scalers */ 7699 if (DISPLAY_VER(dev_priv) >= 9) { 7700 if (new_crtc_state->pch_pfit.enabled) 7701 skl_pfit_enable(new_crtc_state); 7702 } else if (HAS_PCH_SPLIT(dev_priv)) { 7703 if (new_crtc_state->pch_pfit.enabled) 7704 ilk_pfit_enable(new_crtc_state); 7705 else if (old_crtc_state->pch_pfit.enabled) 7706 ilk_pfit_disable(old_crtc_state); 7707 } 7708 7709 /* 7710 * The register is supposedly single buffered so perhaps 7711 * not 100% correct to do this here. But SKL+ calculate 7712 * this based on the adjust pixel rate so pfit changes do 7713 * affect it and so it must be updated for fastsets. 7714 * HSW/BDW only really need this here for fastboot, after 7715 * that the value should not change without a full modeset. 7716 */ 7717 if (DISPLAY_VER(dev_priv) >= 9 || 7718 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) 7719 hsw_set_linetime_wm(new_crtc_state); 7720 } 7721 7722 static void commit_pipe_pre_planes(struct intel_atomic_state *state, 7723 struct intel_crtc *crtc) 7724 { 7725 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 7726 const struct intel_crtc_state *old_crtc_state = 7727 intel_atomic_get_old_crtc_state(state, crtc); 7728 const struct intel_crtc_state *new_crtc_state = 7729 intel_atomic_get_new_crtc_state(state, crtc); 7730 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 7731 7732 /* 7733 * During modesets pipe configuration was programmed as the 7734 * CRTC was enabled. 7735 */ 7736 if (!modeset) { 7737 if (new_crtc_state->uapi.color_mgmt_changed || 7738 new_crtc_state->update_pipe) 7739 intel_color_commit_arm(new_crtc_state); 7740 7741 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) 7742 bdw_set_pipemisc(new_crtc_state); 7743 7744 if (new_crtc_state->update_pipe) 7745 intel_pipe_fastset(old_crtc_state, new_crtc_state); 7746 } 7747 7748 intel_psr2_program_trans_man_trk_ctl(new_crtc_state); 7749 7750 intel_atomic_update_watermarks(state, crtc); 7751 } 7752 7753 static void commit_pipe_post_planes(struct intel_atomic_state *state, 7754 struct intel_crtc *crtc) 7755 { 7756 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 7757 const struct intel_crtc_state *new_crtc_state = 7758 intel_atomic_get_new_crtc_state(state, crtc); 7759 7760 /* 7761 * Disable the scaler(s) after the plane(s) so that we don't 7762 * get a catastrophic underrun even if the two operations 7763 * end up happening in two different frames. 7764 */ 7765 if (DISPLAY_VER(dev_priv) >= 9 && 7766 !intel_crtc_needs_modeset(new_crtc_state)) 7767 skl_detach_scalers(new_crtc_state); 7768 } 7769 7770 static void intel_enable_crtc(struct intel_atomic_state *state, 7771 struct intel_crtc *crtc) 7772 { 7773 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 7774 const struct intel_crtc_state *new_crtc_state = 7775 intel_atomic_get_new_crtc_state(state, crtc); 7776 7777 if (!intel_crtc_needs_modeset(new_crtc_state)) 7778 return; 7779 7780 intel_crtc_update_active_timings(new_crtc_state); 7781 7782 dev_priv->display->crtc_enable(state, crtc); 7783 7784 if (intel_crtc_is_bigjoiner_slave(new_crtc_state)) 7785 return; 7786 7787 /* vblanks work again, re-enable pipe CRC. */ 7788 intel_crtc_enable_pipe_crc(crtc); 7789 } 7790 7791 static void intel_update_crtc(struct intel_atomic_state *state, 7792 struct intel_crtc *crtc) 7793 { 7794 struct drm_i915_private *i915 = to_i915(state->base.dev); 7795 const struct intel_crtc_state *old_crtc_state = 7796 intel_atomic_get_old_crtc_state(state, crtc); 7797 struct intel_crtc_state *new_crtc_state = 7798 intel_atomic_get_new_crtc_state(state, crtc); 7799 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 7800 7801 if (!modeset) { 7802 if (new_crtc_state->preload_luts && 7803 (new_crtc_state->uapi.color_mgmt_changed || 7804 new_crtc_state->update_pipe)) 7805 intel_color_load_luts(new_crtc_state); 7806 7807 intel_pre_plane_update(state, crtc); 7808 7809 if (new_crtc_state->update_pipe) 7810 intel_encoders_update_pipe(state, crtc); 7811 7812 if (DISPLAY_VER(i915) >= 11 && 7813 new_crtc_state->update_pipe) 7814 icl_set_pipe_chicken(new_crtc_state); 7815 } 7816 7817 intel_fbc_update(state, crtc); 7818 7819 if (!modeset && 7820 (new_crtc_state->uapi.color_mgmt_changed || 7821 new_crtc_state->update_pipe)) 7822 intel_color_commit_noarm(new_crtc_state); 7823 7824 intel_crtc_planes_update_noarm(state, crtc); 7825 7826 /* Perform vblank evasion around commit operation */ 7827 intel_pipe_update_start(new_crtc_state); 7828 7829 commit_pipe_pre_planes(state, crtc); 7830 7831 intel_crtc_planes_update_arm(state, crtc); 7832 7833 commit_pipe_post_planes(state, crtc); 7834 7835 intel_pipe_update_end(new_crtc_state); 7836 7837 /* 7838 * We usually enable FIFO underrun interrupts as part of the 7839 * CRTC enable sequence during modesets. But when we inherit a 7840 * valid pipe configuration from the BIOS we need to take care 7841 * of enabling them on the CRTC's first fastset. 7842 */ 7843 if (new_crtc_state->update_pipe && !modeset && 7844 old_crtc_state->inherited) 7845 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state); 7846 } 7847 7848 static void intel_old_crtc_state_disables(struct intel_atomic_state *state, 7849 struct intel_crtc_state *old_crtc_state, 7850 struct intel_crtc_state *new_crtc_state, 7851 struct intel_crtc *crtc) 7852 { 7853 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 7854 7855 /* 7856 * We need to disable pipe CRC before disabling the pipe, 7857 * or we race against vblank off. 7858 */ 7859 intel_crtc_disable_pipe_crc(crtc); 7860 7861 dev_priv->display->crtc_disable(state, crtc); 7862 crtc->active = false; 7863 intel_fbc_disable(crtc); 7864 intel_disable_shared_dpll(old_crtc_state); 7865 7866 /* FIXME unify this for all platforms */ 7867 if (!new_crtc_state->hw.active && 7868 !HAS_GMCH(dev_priv)) 7869 intel_initial_watermarks(state, crtc); 7870 } 7871 7872 static void intel_commit_modeset_disables(struct intel_atomic_state *state) 7873 { 7874 struct intel_crtc_state *new_crtc_state, *old_crtc_state; 7875 struct intel_crtc *crtc; 7876 u32 handled = 0; 7877 int i; 7878 7879 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7880 new_crtc_state, i) { 7881 if (!intel_crtc_needs_modeset(new_crtc_state)) 7882 continue; 7883 7884 if (!old_crtc_state->hw.active) 7885 continue; 7886 7887 intel_pre_plane_update(state, crtc); 7888 intel_crtc_disable_planes(state, crtc); 7889 } 7890 7891 /* Only disable port sync and MST slaves */ 7892 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7893 new_crtc_state, i) { 7894 if (!intel_crtc_needs_modeset(new_crtc_state)) 7895 continue; 7896 7897 if (!old_crtc_state->hw.active) 7898 continue; 7899 7900 /* In case of Transcoder port Sync master slave CRTCs can be 7901 * assigned in any order and we need to make sure that 7902 * slave CRTCs are disabled first and then master CRTC since 7903 * Slave vblanks are masked till Master Vblanks. 7904 */ 7905 if (!is_trans_port_sync_slave(old_crtc_state) && 7906 !intel_dp_mst_is_slave_trans(old_crtc_state) && 7907 !intel_crtc_is_bigjoiner_slave(old_crtc_state)) 7908 continue; 7909 7910 intel_old_crtc_state_disables(state, old_crtc_state, 7911 new_crtc_state, crtc); 7912 handled |= BIT(crtc->pipe); 7913 } 7914 7915 /* Disable everything else left on */ 7916 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7917 new_crtc_state, i) { 7918 if (!intel_crtc_needs_modeset(new_crtc_state) || 7919 (handled & BIT(crtc->pipe))) 7920 continue; 7921 7922 if (!old_crtc_state->hw.active) 7923 continue; 7924 7925 intel_old_crtc_state_disables(state, old_crtc_state, 7926 new_crtc_state, crtc); 7927 } 7928 } 7929 7930 static void intel_commit_modeset_enables(struct intel_atomic_state *state) 7931 { 7932 struct intel_crtc_state *new_crtc_state; 7933 struct intel_crtc *crtc; 7934 int i; 7935 7936 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7937 if (!new_crtc_state->hw.active) 7938 continue; 7939 7940 intel_enable_crtc(state, crtc); 7941 intel_update_crtc(state, crtc); 7942 } 7943 } 7944 7945 static void skl_commit_modeset_enables(struct intel_atomic_state *state) 7946 { 7947 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 7948 struct intel_crtc *crtc; 7949 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 7950 struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; 7951 u8 update_pipes = 0, modeset_pipes = 0; 7952 int i; 7953 7954 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 7955 enum pipe pipe = crtc->pipe; 7956 7957 if (!new_crtc_state->hw.active) 7958 continue; 7959 7960 /* ignore allocations for crtc's that have been turned off. */ 7961 if (!intel_crtc_needs_modeset(new_crtc_state)) { 7962 entries[pipe] = old_crtc_state->wm.skl.ddb; 7963 update_pipes |= BIT(pipe); 7964 } else { 7965 modeset_pipes |= BIT(pipe); 7966 } 7967 } 7968 7969 /* 7970 * Whenever the number of active pipes changes, we need to make sure we 7971 * update the pipes in the right order so that their ddb allocations 7972 * never overlap with each other between CRTC updates. Otherwise we'll 7973 * cause pipe underruns and other bad stuff. 7974 * 7975 * So first lets enable all pipes that do not need a fullmodeset as 7976 * those don't have any external dependency. 7977 */ 7978 while (update_pipes) { 7979 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7980 new_crtc_state, i) { 7981 enum pipe pipe = crtc->pipe; 7982 7983 if ((update_pipes & BIT(pipe)) == 0) 7984 continue; 7985 7986 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 7987 entries, I915_MAX_PIPES, pipe)) 7988 continue; 7989 7990 entries[pipe] = new_crtc_state->wm.skl.ddb; 7991 update_pipes &= ~BIT(pipe); 7992 7993 intel_update_crtc(state, crtc); 7994 7995 /* 7996 * If this is an already active pipe, it's DDB changed, 7997 * and this isn't the last pipe that needs updating 7998 * then we need to wait for a vblank to pass for the 7999 * new ddb allocation to take effect. 8000 */ 8001 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb, 8002 &old_crtc_state->wm.skl.ddb) && 8003 (update_pipes | modeset_pipes)) 8004 intel_crtc_wait_for_next_vblank(crtc); 8005 } 8006 } 8007 8008 update_pipes = modeset_pipes; 8009 8010 /* 8011 * Enable all pipes that needs a modeset and do not depends on other 8012 * pipes 8013 */ 8014 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8015 enum pipe pipe = crtc->pipe; 8016 8017 if ((modeset_pipes & BIT(pipe)) == 0) 8018 continue; 8019 8020 if (intel_dp_mst_is_slave_trans(new_crtc_state) || 8021 is_trans_port_sync_master(new_crtc_state) || 8022 intel_crtc_is_bigjoiner_master(new_crtc_state)) 8023 continue; 8024 8025 modeset_pipes &= ~BIT(pipe); 8026 8027 intel_enable_crtc(state, crtc); 8028 } 8029 8030 /* 8031 * Then we enable all remaining pipes that depend on other 8032 * pipes: MST slaves and port sync masters, big joiner master 8033 */ 8034 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8035 enum pipe pipe = crtc->pipe; 8036 8037 if ((modeset_pipes & BIT(pipe)) == 0) 8038 continue; 8039 8040 modeset_pipes &= ~BIT(pipe); 8041 8042 intel_enable_crtc(state, crtc); 8043 } 8044 8045 /* 8046 * Finally we do the plane updates/etc. for all pipes that got enabled. 8047 */ 8048 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8049 enum pipe pipe = crtc->pipe; 8050 8051 if ((update_pipes & BIT(pipe)) == 0) 8052 continue; 8053 8054 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 8055 entries, I915_MAX_PIPES, pipe)); 8056 8057 entries[pipe] = new_crtc_state->wm.skl.ddb; 8058 update_pipes &= ~BIT(pipe); 8059 8060 intel_update_crtc(state, crtc); 8061 } 8062 8063 drm_WARN_ON(&dev_priv->drm, modeset_pipes); 8064 drm_WARN_ON(&dev_priv->drm, update_pipes); 8065 } 8066 8067 static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv) 8068 { 8069 struct intel_atomic_state *state, *next; 8070 struct llist_node *freed; 8071 8072 freed = llist_del_all(&dev_priv->atomic_helper.free_list); 8073 llist_for_each_entry_safe(state, next, freed, freed) 8074 drm_atomic_state_put(&state->base); 8075 } 8076 8077 static void intel_atomic_helper_free_state_worker(struct work_struct *work) 8078 { 8079 struct drm_i915_private *dev_priv = 8080 container_of(work, typeof(*dev_priv), atomic_helper.free_work); 8081 8082 intel_atomic_helper_free_state(dev_priv); 8083 } 8084 8085 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) 8086 { 8087 struct wait_queue_entry wait_fence, wait_reset; 8088 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev); 8089 8090 init_wait_entry(&wait_fence, 0); 8091 init_wait_entry(&wait_reset, 0); 8092 for (;;) { 8093 prepare_to_wait(&intel_state->commit_ready.wait, 8094 &wait_fence, TASK_UNINTERRUPTIBLE); 8095 prepare_to_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags, 8096 I915_RESET_MODESET), 8097 &wait_reset, TASK_UNINTERRUPTIBLE); 8098 8099 8100 if (i915_sw_fence_done(&intel_state->commit_ready) || 8101 test_bit(I915_RESET_MODESET, &to_gt(dev_priv)->reset.flags)) 8102 break; 8103 8104 schedule(); 8105 } 8106 finish_wait(&intel_state->commit_ready.wait, &wait_fence); 8107 finish_wait(bit_waitqueue(&to_gt(dev_priv)->reset.flags, 8108 I915_RESET_MODESET), 8109 &wait_reset); 8110 } 8111 8112 static void intel_cleanup_dsbs(struct intel_atomic_state *state) 8113 { 8114 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 8115 struct intel_crtc *crtc; 8116 int i; 8117 8118 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 8119 new_crtc_state, i) 8120 intel_dsb_cleanup(old_crtc_state); 8121 } 8122 8123 static void intel_atomic_cleanup_work(struct work_struct *work) 8124 { 8125 struct intel_atomic_state *state = 8126 container_of(work, struct intel_atomic_state, base.commit_work); 8127 struct drm_i915_private *i915 = to_i915(state->base.dev); 8128 8129 intel_cleanup_dsbs(state); 8130 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base); 8131 drm_atomic_helper_commit_cleanup_done(&state->base); 8132 drm_atomic_state_put(&state->base); 8133 8134 intel_atomic_helper_free_state(i915); 8135 } 8136 8137 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state) 8138 { 8139 struct drm_i915_private *i915 = to_i915(state->base.dev); 8140 struct intel_plane *plane; 8141 struct intel_plane_state *plane_state; 8142 int i; 8143 8144 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 8145 struct drm_framebuffer *fb = plane_state->hw.fb; 8146 int cc_plane; 8147 int ret; 8148 8149 if (!fb) 8150 continue; 8151 8152 cc_plane = intel_fb_rc_ccs_cc_plane(fb); 8153 if (cc_plane < 0) 8154 continue; 8155 8156 /* 8157 * The layout of the fast clear color value expected by HW 8158 * (the DRM ABI requiring this value to be located in fb at 8159 * offset 0 of cc plane, plane #2 previous generations or 8160 * plane #1 for flat ccs): 8161 * - 4 x 4 bytes per-channel value 8162 * (in surface type specific float/int format provided by the fb user) 8163 * - 8 bytes native color value used by the display 8164 * (converted/written by GPU during a fast clear operation using the 8165 * above per-channel values) 8166 * 8167 * The commit's FB prepare hook already ensured that FB obj is pinned and the 8168 * caller made sure that the object is synced wrt. the related color clear value 8169 * GPU write on it. 8170 */ 8171 ret = i915_gem_object_read_from_page(intel_fb_obj(fb), 8172 fb->offsets[cc_plane] + 16, 8173 &plane_state->ccval, 8174 sizeof(plane_state->ccval)); 8175 /* The above could only fail if the FB obj has an unexpected backing store type. */ 8176 drm_WARN_ON(&i915->drm, ret); 8177 } 8178 } 8179 8180 static void intel_atomic_commit_tail(struct intel_atomic_state *state) 8181 { 8182 struct drm_device *dev = state->base.dev; 8183 struct drm_i915_private *dev_priv = to_i915(dev); 8184 struct intel_crtc_state *new_crtc_state, *old_crtc_state; 8185 struct intel_crtc *crtc; 8186 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {}; 8187 intel_wakeref_t wakeref = 0; 8188 int i; 8189 8190 intel_atomic_commit_fence_wait(state); 8191 8192 drm_atomic_helper_wait_for_dependencies(&state->base); 8193 8194 if (state->modeset) 8195 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); 8196 8197 intel_atomic_prepare_plane_clear_colors(state); 8198 8199 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 8200 new_crtc_state, i) { 8201 if (intel_crtc_needs_modeset(new_crtc_state) || 8202 new_crtc_state->update_pipe) { 8203 modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]); 8204 } 8205 } 8206 8207 intel_commit_modeset_disables(state); 8208 8209 /* FIXME: Eventually get rid of our crtc->config pointer */ 8210 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 8211 crtc->config = new_crtc_state; 8212 8213 if (state->modeset) { 8214 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base); 8215 8216 intel_set_cdclk_pre_plane_update(state); 8217 8218 intel_modeset_verify_disabled(dev_priv, state); 8219 } 8220 8221 intel_sagv_pre_plane_update(state); 8222 8223 /* Complete the events for pipes that have now been disabled */ 8224 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8225 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 8226 8227 /* Complete events for now disable pipes here. */ 8228 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) { 8229 spin_lock_irq(&dev->event_lock); 8230 drm_crtc_send_vblank_event(&crtc->base, 8231 new_crtc_state->uapi.event); 8232 spin_unlock_irq(&dev->event_lock); 8233 8234 new_crtc_state->uapi.event = NULL; 8235 } 8236 } 8237 8238 intel_encoders_update_prepare(state); 8239 8240 intel_dbuf_pre_plane_update(state); 8241 intel_mbus_dbox_update(state); 8242 8243 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8244 if (new_crtc_state->do_async_flip) 8245 intel_crtc_enable_flip_done(state, crtc); 8246 } 8247 8248 /* Now enable the clocks, plane, pipe, and connectors that we set up. */ 8249 dev_priv->display->commit_modeset_enables(state); 8250 8251 intel_encoders_update_complete(state); 8252 8253 if (state->modeset) 8254 intel_set_cdclk_post_plane_update(state); 8255 8256 intel_wait_for_vblank_workers(state); 8257 8258 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here 8259 * already, but still need the state for the delayed optimization. To 8260 * fix this: 8261 * - wrap the optimization/post_plane_update stuff into a per-crtc work. 8262 * - schedule that vblank worker _before_ calling hw_done 8263 * - at the start of commit_tail, cancel it _synchrously 8264 * - switch over to the vblank wait helper in the core after that since 8265 * we don't need out special handling any more. 8266 */ 8267 drm_atomic_helper_wait_for_flip_done(dev, &state->base); 8268 8269 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 8270 if (new_crtc_state->do_async_flip) 8271 intel_crtc_disable_flip_done(state, crtc); 8272 } 8273 8274 /* 8275 * Now that the vblank has passed, we can go ahead and program the 8276 * optimal watermarks on platforms that need two-step watermark 8277 * programming. 8278 * 8279 * TODO: Move this (and other cleanup) to an async worker eventually. 8280 */ 8281 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 8282 new_crtc_state, i) { 8283 /* 8284 * Gen2 reports pipe underruns whenever all planes are disabled. 8285 * So re-enable underrun reporting after some planes get enabled. 8286 * 8287 * We do this before .optimize_watermarks() so that we have a 8288 * chance of catching underruns with the intermediate watermarks 8289 * vs. the new plane configuration. 8290 */ 8291 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state)) 8292 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true); 8293 8294 intel_optimize_watermarks(state, crtc); 8295 } 8296 8297 intel_dbuf_post_plane_update(state); 8298 intel_psr_post_plane_update(state); 8299 8300 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 8301 intel_post_plane_update(state, crtc); 8302 8303 modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]); 8304 8305 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state); 8306 8307 /* 8308 * DSB cleanup is done in cleanup_work aligning with framebuffer 8309 * cleanup. So copy and reset the dsb structure to sync with 8310 * commit_done and later do dsb cleanup in cleanup_work. 8311 */ 8312 old_crtc_state->dsb = fetch_and_zero(&new_crtc_state->dsb); 8313 } 8314 8315 /* Underruns don't always raise interrupts, so check manually */ 8316 intel_check_cpu_fifo_underruns(dev_priv); 8317 intel_check_pch_fifo_underruns(dev_priv); 8318 8319 if (state->modeset) 8320 intel_verify_planes(state); 8321 8322 intel_sagv_post_plane_update(state); 8323 8324 drm_atomic_helper_commit_hw_done(&state->base); 8325 8326 if (state->modeset) { 8327 /* As one of the primary mmio accessors, KMS has a high 8328 * likelihood of triggering bugs in unclaimed access. After we 8329 * finish modesetting, see if an error has been flagged, and if 8330 * so enable debugging for the next modeset - and hope we catch 8331 * the culprit. 8332 */ 8333 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore); 8334 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref); 8335 } 8336 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref); 8337 8338 /* 8339 * Defer the cleanup of the old state to a separate worker to not 8340 * impede the current task (userspace for blocking modesets) that 8341 * are executed inline. For out-of-line asynchronous modesets/flips, 8342 * deferring to a new worker seems overkill, but we would place a 8343 * schedule point (cond_resched()) here anyway to keep latencies 8344 * down. 8345 */ 8346 INIT_WORK(&state->base.commit_work, intel_atomic_cleanup_work); 8347 queue_work(system_highpri_wq, &state->base.commit_work); 8348 } 8349 8350 static void intel_atomic_commit_work(struct work_struct *work) 8351 { 8352 struct intel_atomic_state *state = 8353 container_of(work, struct intel_atomic_state, base.commit_work); 8354 8355 intel_atomic_commit_tail(state); 8356 } 8357 8358 static int 8359 intel_atomic_commit_ready(struct i915_sw_fence *fence, 8360 enum i915_sw_fence_notify notify) 8361 { 8362 struct intel_atomic_state *state = 8363 container_of(fence, struct intel_atomic_state, commit_ready); 8364 8365 switch (notify) { 8366 case FENCE_COMPLETE: 8367 /* we do blocking waits in the worker, nothing to do here */ 8368 break; 8369 case FENCE_FREE: 8370 { 8371 struct intel_atomic_helper *helper = 8372 &to_i915(state->base.dev)->atomic_helper; 8373 8374 if (llist_add(&state->freed, &helper->free_list)) 8375 schedule_work(&helper->free_work); 8376 break; 8377 } 8378 } 8379 8380 return NOTIFY_DONE; 8381 } 8382 8383 static void intel_atomic_track_fbs(struct intel_atomic_state *state) 8384 { 8385 struct intel_plane_state *old_plane_state, *new_plane_state; 8386 struct intel_plane *plane; 8387 int i; 8388 8389 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 8390 new_plane_state, i) 8391 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb), 8392 to_intel_frontbuffer(new_plane_state->hw.fb), 8393 plane->frontbuffer_bit); 8394 } 8395 8396 static int intel_atomic_commit(struct drm_device *dev, 8397 struct drm_atomic_state *_state, 8398 bool nonblock) 8399 { 8400 struct intel_atomic_state *state = to_intel_atomic_state(_state); 8401 struct drm_i915_private *dev_priv = to_i915(dev); 8402 int ret = 0; 8403 8404 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm); 8405 8406 drm_atomic_state_get(&state->base); 8407 i915_sw_fence_init(&state->commit_ready, 8408 intel_atomic_commit_ready); 8409 8410 /* 8411 * The intel_legacy_cursor_update() fast path takes care 8412 * of avoiding the vblank waits for simple cursor 8413 * movement and flips. For cursor on/off and size changes, 8414 * we want to perform the vblank waits so that watermark 8415 * updates happen during the correct frames. Gen9+ have 8416 * double buffered watermarks and so shouldn't need this. 8417 * 8418 * Unset state->legacy_cursor_update before the call to 8419 * drm_atomic_helper_setup_commit() because otherwise 8420 * drm_atomic_helper_wait_for_flip_done() is a noop and 8421 * we get FIFO underruns because we didn't wait 8422 * for vblank. 8423 * 8424 * FIXME doing watermarks and fb cleanup from a vblank worker 8425 * (assuming we had any) would solve these problems. 8426 */ 8427 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) { 8428 struct intel_crtc_state *new_crtc_state; 8429 struct intel_crtc *crtc; 8430 int i; 8431 8432 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 8433 if (new_crtc_state->wm.need_postvbl_update || 8434 new_crtc_state->update_wm_post) 8435 state->base.legacy_cursor_update = false; 8436 } 8437 8438 ret = intel_atomic_prepare_commit(state); 8439 if (ret) { 8440 drm_dbg_atomic(&dev_priv->drm, 8441 "Preparing state failed with %i\n", ret); 8442 i915_sw_fence_commit(&state->commit_ready); 8443 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref); 8444 return ret; 8445 } 8446 8447 ret = drm_atomic_helper_setup_commit(&state->base, nonblock); 8448 if (!ret) 8449 ret = drm_atomic_helper_swap_state(&state->base, true); 8450 if (!ret) 8451 intel_atomic_swap_global_state(state); 8452 8453 if (ret) { 8454 struct intel_crtc_state *new_crtc_state; 8455 struct intel_crtc *crtc; 8456 int i; 8457 8458 i915_sw_fence_commit(&state->commit_ready); 8459 8460 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 8461 intel_dsb_cleanup(new_crtc_state); 8462 8463 drm_atomic_helper_cleanup_planes(dev, &state->base); 8464 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref); 8465 return ret; 8466 } 8467 intel_shared_dpll_swap_state(state); 8468 intel_atomic_track_fbs(state); 8469 8470 drm_atomic_state_get(&state->base); 8471 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work); 8472 8473 i915_sw_fence_commit(&state->commit_ready); 8474 if (nonblock && state->modeset) { 8475 queue_work(dev_priv->modeset_wq, &state->base.commit_work); 8476 } else if (nonblock) { 8477 queue_work(dev_priv->flip_wq, &state->base.commit_work); 8478 } else { 8479 if (state->modeset) 8480 flush_workqueue(dev_priv->modeset_wq); 8481 intel_atomic_commit_tail(state); 8482 } 8483 8484 return 0; 8485 } 8486 8487 /** 8488 * intel_plane_destroy - destroy a plane 8489 * @plane: plane to destroy 8490 * 8491 * Common destruction function for all types of planes (primary, cursor, 8492 * sprite). 8493 */ 8494 void intel_plane_destroy(struct drm_plane *plane) 8495 { 8496 drm_plane_cleanup(plane); 8497 kfree(to_intel_plane(plane)); 8498 } 8499 8500 static void intel_plane_possible_crtcs_init(struct drm_i915_private *dev_priv) 8501 { 8502 struct intel_plane *plane; 8503 8504 for_each_intel_plane(&dev_priv->drm, plane) { 8505 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, 8506 plane->pipe); 8507 8508 plane->base.possible_crtcs = drm_crtc_mask(&crtc->base); 8509 } 8510 } 8511 8512 8513 int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data, 8514 struct drm_file *file) 8515 { 8516 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; 8517 struct drm_crtc *drmmode_crtc; 8518 struct intel_crtc *crtc; 8519 8520 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id); 8521 if (!drmmode_crtc) 8522 return -ENOENT; 8523 8524 crtc = to_intel_crtc(drmmode_crtc); 8525 pipe_from_crtc_id->pipe = crtc->pipe; 8526 8527 return 0; 8528 } 8529 8530 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder) 8531 { 8532 struct drm_device *dev = encoder->base.dev; 8533 struct intel_encoder *source_encoder; 8534 u32 possible_clones = 0; 8535 8536 for_each_intel_encoder(dev, source_encoder) { 8537 if (encoders_cloneable(encoder, source_encoder)) 8538 possible_clones |= drm_encoder_mask(&source_encoder->base); 8539 } 8540 8541 return possible_clones; 8542 } 8543 8544 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder) 8545 { 8546 struct drm_device *dev = encoder->base.dev; 8547 struct intel_crtc *crtc; 8548 u32 possible_crtcs = 0; 8549 8550 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask) 8551 possible_crtcs |= drm_crtc_mask(&crtc->base); 8552 8553 return possible_crtcs; 8554 } 8555 8556 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv) 8557 { 8558 if (!IS_MOBILE(dev_priv)) 8559 return false; 8560 8561 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0) 8562 return false; 8563 8564 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE)) 8565 return false; 8566 8567 return true; 8568 } 8569 8570 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv) 8571 { 8572 if (DISPLAY_VER(dev_priv) >= 9) 8573 return false; 8574 8575 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) 8576 return false; 8577 8578 if (HAS_PCH_LPT_H(dev_priv) && 8579 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) 8580 return false; 8581 8582 /* DDI E can't be used if DDI A requires 4 lanes */ 8583 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) 8584 return false; 8585 8586 if (!dev_priv->vbt.int_crt_support) 8587 return false; 8588 8589 return true; 8590 } 8591 8592 static void intel_setup_outputs(struct drm_i915_private *dev_priv) 8593 { 8594 struct intel_encoder *encoder; 8595 bool dpd_is_edp = false; 8596 8597 intel_pps_unlock_regs_wa(dev_priv); 8598 8599 if (!HAS_DISPLAY(dev_priv)) 8600 return; 8601 8602 if (IS_DG2(dev_priv)) { 8603 intel_ddi_init(dev_priv, PORT_A); 8604 intel_ddi_init(dev_priv, PORT_B); 8605 intel_ddi_init(dev_priv, PORT_C); 8606 intel_ddi_init(dev_priv, PORT_D_XELPD); 8607 intel_ddi_init(dev_priv, PORT_TC1); 8608 } else if (IS_ALDERLAKE_P(dev_priv)) { 8609 intel_ddi_init(dev_priv, PORT_A); 8610 intel_ddi_init(dev_priv, PORT_B); 8611 intel_ddi_init(dev_priv, PORT_TC1); 8612 intel_ddi_init(dev_priv, PORT_TC2); 8613 intel_ddi_init(dev_priv, PORT_TC3); 8614 intel_ddi_init(dev_priv, PORT_TC4); 8615 icl_dsi_init(dev_priv); 8616 } else if (IS_ALDERLAKE_S(dev_priv)) { 8617 intel_ddi_init(dev_priv, PORT_A); 8618 intel_ddi_init(dev_priv, PORT_TC1); 8619 intel_ddi_init(dev_priv, PORT_TC2); 8620 intel_ddi_init(dev_priv, PORT_TC3); 8621 intel_ddi_init(dev_priv, PORT_TC4); 8622 } else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv)) { 8623 intel_ddi_init(dev_priv, PORT_A); 8624 intel_ddi_init(dev_priv, PORT_B); 8625 intel_ddi_init(dev_priv, PORT_TC1); 8626 intel_ddi_init(dev_priv, PORT_TC2); 8627 } else if (DISPLAY_VER(dev_priv) >= 12) { 8628 intel_ddi_init(dev_priv, PORT_A); 8629 intel_ddi_init(dev_priv, PORT_B); 8630 intel_ddi_init(dev_priv, PORT_TC1); 8631 intel_ddi_init(dev_priv, PORT_TC2); 8632 intel_ddi_init(dev_priv, PORT_TC3); 8633 intel_ddi_init(dev_priv, PORT_TC4); 8634 intel_ddi_init(dev_priv, PORT_TC5); 8635 intel_ddi_init(dev_priv, PORT_TC6); 8636 icl_dsi_init(dev_priv); 8637 } else if (IS_JSL_EHL(dev_priv)) { 8638 intel_ddi_init(dev_priv, PORT_A); 8639 intel_ddi_init(dev_priv, PORT_B); 8640 intel_ddi_init(dev_priv, PORT_C); 8641 intel_ddi_init(dev_priv, PORT_D); 8642 icl_dsi_init(dev_priv); 8643 } else if (DISPLAY_VER(dev_priv) == 11) { 8644 intel_ddi_init(dev_priv, PORT_A); 8645 intel_ddi_init(dev_priv, PORT_B); 8646 intel_ddi_init(dev_priv, PORT_C); 8647 intel_ddi_init(dev_priv, PORT_D); 8648 intel_ddi_init(dev_priv, PORT_E); 8649 intel_ddi_init(dev_priv, PORT_F); 8650 icl_dsi_init(dev_priv); 8651 } else if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) { 8652 intel_ddi_init(dev_priv, PORT_A); 8653 intel_ddi_init(dev_priv, PORT_B); 8654 intel_ddi_init(dev_priv, PORT_C); 8655 vlv_dsi_init(dev_priv); 8656 } else if (DISPLAY_VER(dev_priv) >= 9) { 8657 intel_ddi_init(dev_priv, PORT_A); 8658 intel_ddi_init(dev_priv, PORT_B); 8659 intel_ddi_init(dev_priv, PORT_C); 8660 intel_ddi_init(dev_priv, PORT_D); 8661 intel_ddi_init(dev_priv, PORT_E); 8662 } else if (HAS_DDI(dev_priv)) { 8663 u32 found; 8664 8665 if (intel_ddi_crt_present(dev_priv)) 8666 intel_crt_init(dev_priv); 8667 8668 /* Haswell uses DDI functions to detect digital outputs. */ 8669 found = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; 8670 if (found) 8671 intel_ddi_init(dev_priv, PORT_A); 8672 8673 found = intel_de_read(dev_priv, SFUSE_STRAP); 8674 if (found & SFUSE_STRAP_DDIB_DETECTED) 8675 intel_ddi_init(dev_priv, PORT_B); 8676 if (found & SFUSE_STRAP_DDIC_DETECTED) 8677 intel_ddi_init(dev_priv, PORT_C); 8678 if (found & SFUSE_STRAP_DDID_DETECTED) 8679 intel_ddi_init(dev_priv, PORT_D); 8680 if (found & SFUSE_STRAP_DDIF_DETECTED) 8681 intel_ddi_init(dev_priv, PORT_F); 8682 } else if (HAS_PCH_SPLIT(dev_priv)) { 8683 int found; 8684 8685 /* 8686 * intel_edp_init_connector() depends on this completing first, 8687 * to prevent the registration of both eDP and LVDS and the 8688 * incorrect sharing of the PPS. 8689 */ 8690 intel_lvds_init(dev_priv); 8691 intel_crt_init(dev_priv); 8692 8693 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D); 8694 8695 if (ilk_has_edp_a(dev_priv)) 8696 g4x_dp_init(dev_priv, DP_A, PORT_A); 8697 8698 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) { 8699 /* PCH SDVOB multiplex with HDMIB */ 8700 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); 8701 if (!found) 8702 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); 8703 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED)) 8704 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B); 8705 } 8706 8707 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED) 8708 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); 8709 8710 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED) 8711 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D); 8712 8713 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED) 8714 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C); 8715 8716 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED) 8717 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D); 8718 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 8719 bool has_edp, has_port; 8720 8721 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support) 8722 intel_crt_init(dev_priv); 8723 8724 /* 8725 * The DP_DETECTED bit is the latched state of the DDC 8726 * SDA pin at boot. However since eDP doesn't require DDC 8727 * (no way to plug in a DP->HDMI dongle) the DDC pins for 8728 * eDP ports may have been muxed to an alternate function. 8729 * Thus we can't rely on the DP_DETECTED bit alone to detect 8730 * eDP ports. Consult the VBT as well as DP_DETECTED to 8731 * detect eDP ports. 8732 * 8733 * Sadly the straps seem to be missing sometimes even for HDMI 8734 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap 8735 * and VBT for the presence of the port. Additionally we can't 8736 * trust the port type the VBT declares as we've seen at least 8737 * HDMI ports that the VBT claim are DP or eDP. 8738 */ 8739 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B); 8740 has_port = intel_bios_is_port_present(dev_priv, PORT_B); 8741 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port) 8742 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B); 8743 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) 8744 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); 8745 8746 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C); 8747 has_port = intel_bios_is_port_present(dev_priv, PORT_C); 8748 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port) 8749 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C); 8750 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) 8751 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); 8752 8753 if (IS_CHERRYVIEW(dev_priv)) { 8754 /* 8755 * eDP not supported on port D, 8756 * so no need to worry about it 8757 */ 8758 has_port = intel_bios_is_port_present(dev_priv, PORT_D); 8759 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port) 8760 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D); 8761 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port) 8762 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D); 8763 } 8764 8765 vlv_dsi_init(dev_priv); 8766 } else if (IS_PINEVIEW(dev_priv)) { 8767 intel_lvds_init(dev_priv); 8768 intel_crt_init(dev_priv); 8769 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) { 8770 bool found = false; 8771 8772 if (IS_MOBILE(dev_priv)) 8773 intel_lvds_init(dev_priv); 8774 8775 intel_crt_init(dev_priv); 8776 8777 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) { 8778 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n"); 8779 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); 8780 if (!found && IS_G4X(dev_priv)) { 8781 drm_dbg_kms(&dev_priv->drm, 8782 "probing HDMI on SDVOB\n"); 8783 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); 8784 } 8785 8786 if (!found && IS_G4X(dev_priv)) 8787 g4x_dp_init(dev_priv, DP_B, PORT_B); 8788 } 8789 8790 /* Before G4X SDVOC doesn't have its own detect register */ 8791 8792 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) { 8793 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n"); 8794 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); 8795 } 8796 8797 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) { 8798 8799 if (IS_G4X(dev_priv)) { 8800 drm_dbg_kms(&dev_priv->drm, 8801 "probing HDMI on SDVOC\n"); 8802 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); 8803 } 8804 if (IS_G4X(dev_priv)) 8805 g4x_dp_init(dev_priv, DP_C, PORT_C); 8806 } 8807 8808 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED)) 8809 g4x_dp_init(dev_priv, DP_D, PORT_D); 8810 8811 if (SUPPORTS_TV(dev_priv)) 8812 intel_tv_init(dev_priv); 8813 } else if (DISPLAY_VER(dev_priv) == 2) { 8814 if (IS_I85X(dev_priv)) 8815 intel_lvds_init(dev_priv); 8816 8817 intel_crt_init(dev_priv); 8818 intel_dvo_init(dev_priv); 8819 } 8820 8821 for_each_intel_encoder(&dev_priv->drm, encoder) { 8822 encoder->base.possible_crtcs = 8823 intel_encoder_possible_crtcs(encoder); 8824 encoder->base.possible_clones = 8825 intel_encoder_possible_clones(encoder); 8826 } 8827 8828 intel_init_pch_refclk(dev_priv); 8829 8830 drm_helper_move_panel_connectors_to_head(&dev_priv->drm); 8831 } 8832 8833 static enum drm_mode_status 8834 intel_mode_valid(struct drm_device *dev, 8835 const struct drm_display_mode *mode) 8836 { 8837 struct drm_i915_private *dev_priv = to_i915(dev); 8838 int hdisplay_max, htotal_max; 8839 int vdisplay_max, vtotal_max; 8840 8841 /* 8842 * Can't reject DBLSCAN here because Xorg ddxen can add piles 8843 * of DBLSCAN modes to the output's mode list when they detect 8844 * the scaling mode property on the connector. And they don't 8845 * ask the kernel to validate those modes in any way until 8846 * modeset time at which point the client gets a protocol error. 8847 * So in order to not upset those clients we silently ignore the 8848 * DBLSCAN flag on such connectors. For other connectors we will 8849 * reject modes with the DBLSCAN flag in encoder->compute_config(). 8850 * And we always reject DBLSCAN modes in connector->mode_valid() 8851 * as we never want such modes on the connector's mode list. 8852 */ 8853 8854 if (mode->vscan > 1) 8855 return MODE_NO_VSCAN; 8856 8857 if (mode->flags & DRM_MODE_FLAG_HSKEW) 8858 return MODE_H_ILLEGAL; 8859 8860 if (mode->flags & (DRM_MODE_FLAG_CSYNC | 8861 DRM_MODE_FLAG_NCSYNC | 8862 DRM_MODE_FLAG_PCSYNC)) 8863 return MODE_HSYNC; 8864 8865 if (mode->flags & (DRM_MODE_FLAG_BCAST | 8866 DRM_MODE_FLAG_PIXMUX | 8867 DRM_MODE_FLAG_CLKDIV2)) 8868 return MODE_BAD; 8869 8870 /* Transcoder timing limits */ 8871 if (DISPLAY_VER(dev_priv) >= 11) { 8872 hdisplay_max = 16384; 8873 vdisplay_max = 8192; 8874 htotal_max = 16384; 8875 vtotal_max = 8192; 8876 } else if (DISPLAY_VER(dev_priv) >= 9 || 8877 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) { 8878 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ 8879 vdisplay_max = 4096; 8880 htotal_max = 8192; 8881 vtotal_max = 8192; 8882 } else if (DISPLAY_VER(dev_priv) >= 3) { 8883 hdisplay_max = 4096; 8884 vdisplay_max = 4096; 8885 htotal_max = 8192; 8886 vtotal_max = 8192; 8887 } else { 8888 hdisplay_max = 2048; 8889 vdisplay_max = 2048; 8890 htotal_max = 4096; 8891 vtotal_max = 4096; 8892 } 8893 8894 if (mode->hdisplay > hdisplay_max || 8895 mode->hsync_start > htotal_max || 8896 mode->hsync_end > htotal_max || 8897 mode->htotal > htotal_max) 8898 return MODE_H_ILLEGAL; 8899 8900 if (mode->vdisplay > vdisplay_max || 8901 mode->vsync_start > vtotal_max || 8902 mode->vsync_end > vtotal_max || 8903 mode->vtotal > vtotal_max) 8904 return MODE_V_ILLEGAL; 8905 8906 if (DISPLAY_VER(dev_priv) >= 5) { 8907 if (mode->hdisplay < 64 || 8908 mode->htotal - mode->hdisplay < 32) 8909 return MODE_H_ILLEGAL; 8910 8911 if (mode->vtotal - mode->vdisplay < 5) 8912 return MODE_V_ILLEGAL; 8913 } else { 8914 if (mode->htotal - mode->hdisplay < 32) 8915 return MODE_H_ILLEGAL; 8916 8917 if (mode->vtotal - mode->vdisplay < 3) 8918 return MODE_V_ILLEGAL; 8919 } 8920 8921 /* 8922 * Cantiga+ cannot handle modes with a hsync front porch of 0. 8923 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. 8924 */ 8925 if ((DISPLAY_VER(dev_priv) > 4 || IS_G4X(dev_priv)) && 8926 mode->hsync_start == mode->hdisplay) 8927 return MODE_H_ILLEGAL; 8928 8929 return MODE_OK; 8930 } 8931 8932 enum drm_mode_status 8933 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv, 8934 const struct drm_display_mode *mode, 8935 bool bigjoiner) 8936 { 8937 int plane_width_max, plane_height_max; 8938 8939 /* 8940 * intel_mode_valid() should be 8941 * sufficient on older platforms. 8942 */ 8943 if (DISPLAY_VER(dev_priv) < 9) 8944 return MODE_OK; 8945 8946 /* 8947 * Most people will probably want a fullscreen 8948 * plane so let's not advertize modes that are 8949 * too big for that. 8950 */ 8951 if (DISPLAY_VER(dev_priv) >= 11) { 8952 plane_width_max = 5120 << bigjoiner; 8953 plane_height_max = 4320; 8954 } else { 8955 plane_width_max = 5120; 8956 plane_height_max = 4096; 8957 } 8958 8959 if (mode->hdisplay > plane_width_max) 8960 return MODE_H_ILLEGAL; 8961 8962 if (mode->vdisplay > plane_height_max) 8963 return MODE_V_ILLEGAL; 8964 8965 return MODE_OK; 8966 } 8967 8968 static const struct drm_mode_config_funcs intel_mode_funcs = { 8969 .fb_create = intel_user_framebuffer_create, 8970 .get_format_info = intel_fb_get_format_info, 8971 .output_poll_changed = intel_fbdev_output_poll_changed, 8972 .mode_valid = intel_mode_valid, 8973 .atomic_check = intel_atomic_check, 8974 .atomic_commit = intel_atomic_commit, 8975 .atomic_state_alloc = intel_atomic_state_alloc, 8976 .atomic_state_clear = intel_atomic_state_clear, 8977 .atomic_state_free = intel_atomic_state_free, 8978 }; 8979 8980 static const struct drm_i915_display_funcs skl_display_funcs = { 8981 .get_pipe_config = hsw_get_pipe_config, 8982 .crtc_enable = hsw_crtc_enable, 8983 .crtc_disable = hsw_crtc_disable, 8984 .commit_modeset_enables = skl_commit_modeset_enables, 8985 .get_initial_plane_config = skl_get_initial_plane_config, 8986 }; 8987 8988 static const struct drm_i915_display_funcs ddi_display_funcs = { 8989 .get_pipe_config = hsw_get_pipe_config, 8990 .crtc_enable = hsw_crtc_enable, 8991 .crtc_disable = hsw_crtc_disable, 8992 .commit_modeset_enables = intel_commit_modeset_enables, 8993 .get_initial_plane_config = i9xx_get_initial_plane_config, 8994 }; 8995 8996 static const struct drm_i915_display_funcs pch_split_display_funcs = { 8997 .get_pipe_config = ilk_get_pipe_config, 8998 .crtc_enable = ilk_crtc_enable, 8999 .crtc_disable = ilk_crtc_disable, 9000 .commit_modeset_enables = intel_commit_modeset_enables, 9001 .get_initial_plane_config = i9xx_get_initial_plane_config, 9002 }; 9003 9004 static const struct drm_i915_display_funcs vlv_display_funcs = { 9005 .get_pipe_config = i9xx_get_pipe_config, 9006 .crtc_enable = valleyview_crtc_enable, 9007 .crtc_disable = i9xx_crtc_disable, 9008 .commit_modeset_enables = intel_commit_modeset_enables, 9009 .get_initial_plane_config = i9xx_get_initial_plane_config, 9010 }; 9011 9012 static const struct drm_i915_display_funcs i9xx_display_funcs = { 9013 .get_pipe_config = i9xx_get_pipe_config, 9014 .crtc_enable = i9xx_crtc_enable, 9015 .crtc_disable = i9xx_crtc_disable, 9016 .commit_modeset_enables = intel_commit_modeset_enables, 9017 .get_initial_plane_config = i9xx_get_initial_plane_config, 9018 }; 9019 9020 /** 9021 * intel_init_display_hooks - initialize the display modesetting hooks 9022 * @dev_priv: device private 9023 */ 9024 void intel_init_display_hooks(struct drm_i915_private *dev_priv) 9025 { 9026 if (!HAS_DISPLAY(dev_priv)) 9027 return; 9028 9029 intel_init_cdclk_hooks(dev_priv); 9030 intel_audio_hooks_init(dev_priv); 9031 9032 intel_dpll_init_clock_hook(dev_priv); 9033 9034 if (DISPLAY_VER(dev_priv) >= 9) { 9035 dev_priv->display = &skl_display_funcs; 9036 } else if (HAS_DDI(dev_priv)) { 9037 dev_priv->display = &ddi_display_funcs; 9038 } else if (HAS_PCH_SPLIT(dev_priv)) { 9039 dev_priv->display = &pch_split_display_funcs; 9040 } else if (IS_CHERRYVIEW(dev_priv) || 9041 IS_VALLEYVIEW(dev_priv)) { 9042 dev_priv->display = &vlv_display_funcs; 9043 } else { 9044 dev_priv->display = &i9xx_display_funcs; 9045 } 9046 9047 intel_fdi_init_hook(dev_priv); 9048 } 9049 9050 void intel_modeset_init_hw(struct drm_i915_private *i915) 9051 { 9052 struct intel_cdclk_state *cdclk_state; 9053 9054 if (!HAS_DISPLAY(i915)) 9055 return; 9056 9057 cdclk_state = to_intel_cdclk_state(i915->cdclk.obj.state); 9058 9059 intel_update_cdclk(i915); 9060 intel_cdclk_dump_config(i915, &i915->cdclk.hw, "Current CDCLK"); 9061 cdclk_state->logical = cdclk_state->actual = i915->cdclk.hw; 9062 } 9063 9064 static int sanitize_watermarks_add_affected(struct drm_atomic_state *state) 9065 { 9066 struct drm_plane *plane; 9067 struct intel_crtc *crtc; 9068 9069 for_each_intel_crtc(state->dev, crtc) { 9070 struct intel_crtc_state *crtc_state; 9071 9072 crtc_state = intel_atomic_get_crtc_state(state, crtc); 9073 if (IS_ERR(crtc_state)) 9074 return PTR_ERR(crtc_state); 9075 9076 if (crtc_state->hw.active) { 9077 /* 9078 * Preserve the inherited flag to avoid 9079 * taking the full modeset path. 9080 */ 9081 crtc_state->inherited = true; 9082 } 9083 } 9084 9085 drm_for_each_plane(plane, state->dev) { 9086 struct drm_plane_state *plane_state; 9087 9088 plane_state = drm_atomic_get_plane_state(state, plane); 9089 if (IS_ERR(plane_state)) 9090 return PTR_ERR(plane_state); 9091 } 9092 9093 return 0; 9094 } 9095 9096 /* 9097 * Calculate what we think the watermarks should be for the state we've read 9098 * out of the hardware and then immediately program those watermarks so that 9099 * we ensure the hardware settings match our internal state. 9100 * 9101 * We can calculate what we think WM's should be by creating a duplicate of the 9102 * current state (which was constructed during hardware readout) and running it 9103 * through the atomic check code to calculate new watermark values in the 9104 * state object. 9105 */ 9106 static void sanitize_watermarks(struct drm_i915_private *dev_priv) 9107 { 9108 struct drm_atomic_state *state; 9109 struct intel_atomic_state *intel_state; 9110 struct intel_crtc *crtc; 9111 struct intel_crtc_state *crtc_state; 9112 struct drm_modeset_acquire_ctx ctx; 9113 int ret; 9114 int i; 9115 9116 /* Only supported on platforms that use atomic watermark design */ 9117 if (!dev_priv->wm_disp->optimize_watermarks) 9118 return; 9119 9120 state = drm_atomic_state_alloc(&dev_priv->drm); 9121 if (drm_WARN_ON(&dev_priv->drm, !state)) 9122 return; 9123 9124 intel_state = to_intel_atomic_state(state); 9125 9126 drm_modeset_acquire_init(&ctx, 0); 9127 9128 retry: 9129 state->acquire_ctx = &ctx; 9130 9131 /* 9132 * Hardware readout is the only time we don't want to calculate 9133 * intermediate watermarks (since we don't trust the current 9134 * watermarks). 9135 */ 9136 if (!HAS_GMCH(dev_priv)) 9137 intel_state->skip_intermediate_wm = true; 9138 9139 ret = sanitize_watermarks_add_affected(state); 9140 if (ret) 9141 goto fail; 9142 9143 ret = intel_atomic_check(&dev_priv->drm, state); 9144 if (ret) 9145 goto fail; 9146 9147 /* Write calculated watermark values back */ 9148 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) { 9149 crtc_state->wm.need_postvbl_update = true; 9150 intel_optimize_watermarks(intel_state, crtc); 9151 9152 to_intel_crtc_state(crtc->base.state)->wm = crtc_state->wm; 9153 } 9154 9155 fail: 9156 if (ret == -EDEADLK) { 9157 drm_atomic_state_clear(state); 9158 drm_modeset_backoff(&ctx); 9159 goto retry; 9160 } 9161 9162 /* 9163 * If we fail here, it means that the hardware appears to be 9164 * programmed in a way that shouldn't be possible, given our 9165 * understanding of watermark requirements. This might mean a 9166 * mistake in the hardware readout code or a mistake in the 9167 * watermark calculations for a given platform. Raise a WARN 9168 * so that this is noticeable. 9169 * 9170 * If this actually happens, we'll have to just leave the 9171 * BIOS-programmed watermarks untouched and hope for the best. 9172 */ 9173 drm_WARN(&dev_priv->drm, ret, 9174 "Could not determine valid watermarks for inherited state\n"); 9175 9176 drm_atomic_state_put(state); 9177 9178 drm_modeset_drop_locks(&ctx); 9179 drm_modeset_acquire_fini(&ctx); 9180 } 9181 9182 static int intel_initial_commit(struct drm_device *dev) 9183 { 9184 struct drm_atomic_state *state = NULL; 9185 struct drm_modeset_acquire_ctx ctx; 9186 struct intel_crtc *crtc; 9187 int ret = 0; 9188 9189 state = drm_atomic_state_alloc(dev); 9190 if (!state) 9191 return -ENOMEM; 9192 9193 drm_modeset_acquire_init(&ctx, 0); 9194 9195 retry: 9196 state->acquire_ctx = &ctx; 9197 9198 for_each_intel_crtc(dev, crtc) { 9199 struct intel_crtc_state *crtc_state = 9200 intel_atomic_get_crtc_state(state, crtc); 9201 9202 if (IS_ERR(crtc_state)) { 9203 ret = PTR_ERR(crtc_state); 9204 goto out; 9205 } 9206 9207 if (crtc_state->hw.active) { 9208 struct intel_encoder *encoder; 9209 9210 /* 9211 * We've not yet detected sink capabilities 9212 * (audio,infoframes,etc.) and thus we don't want to 9213 * force a full state recomputation yet. We want that to 9214 * happen only for the first real commit from userspace. 9215 * So preserve the inherited flag for the time being. 9216 */ 9217 crtc_state->inherited = true; 9218 9219 ret = drm_atomic_add_affected_planes(state, &crtc->base); 9220 if (ret) 9221 goto out; 9222 9223 /* 9224 * FIXME hack to force a LUT update to avoid the 9225 * plane update forcing the pipe gamma on without 9226 * having a proper LUT loaded. Remove once we 9227 * have readout for pipe gamma enable. 9228 */ 9229 crtc_state->uapi.color_mgmt_changed = true; 9230 9231 for_each_intel_encoder_mask(dev, encoder, 9232 crtc_state->uapi.encoder_mask) { 9233 if (encoder->initial_fastset_check && 9234 !encoder->initial_fastset_check(encoder, crtc_state)) { 9235 ret = drm_atomic_add_affected_connectors(state, 9236 &crtc->base); 9237 if (ret) 9238 goto out; 9239 } 9240 } 9241 } 9242 } 9243 9244 ret = drm_atomic_commit(state); 9245 9246 out: 9247 if (ret == -EDEADLK) { 9248 drm_atomic_state_clear(state); 9249 drm_modeset_backoff(&ctx); 9250 goto retry; 9251 } 9252 9253 drm_atomic_state_put(state); 9254 9255 drm_modeset_drop_locks(&ctx); 9256 drm_modeset_acquire_fini(&ctx); 9257 9258 return ret; 9259 } 9260 9261 static void intel_mode_config_init(struct drm_i915_private *i915) 9262 { 9263 struct drm_mode_config *mode_config = &i915->drm.mode_config; 9264 9265 drm_mode_config_init(&i915->drm); 9266 INIT_LIST_HEAD(&i915->global_obj_list); 9267 9268 mode_config->min_width = 0; 9269 mode_config->min_height = 0; 9270 9271 mode_config->preferred_depth = 24; 9272 mode_config->prefer_shadow = 1; 9273 9274 mode_config->funcs = &intel_mode_funcs; 9275 9276 mode_config->async_page_flip = HAS_ASYNC_FLIPS(i915); 9277 9278 /* 9279 * Maximum framebuffer dimensions, chosen to match 9280 * the maximum render engine surface size on gen4+. 9281 */ 9282 if (DISPLAY_VER(i915) >= 7) { 9283 mode_config->max_width = 16384; 9284 mode_config->max_height = 16384; 9285 } else if (DISPLAY_VER(i915) >= 4) { 9286 mode_config->max_width = 8192; 9287 mode_config->max_height = 8192; 9288 } else if (DISPLAY_VER(i915) == 3) { 9289 mode_config->max_width = 4096; 9290 mode_config->max_height = 4096; 9291 } else { 9292 mode_config->max_width = 2048; 9293 mode_config->max_height = 2048; 9294 } 9295 9296 if (IS_I845G(i915) || IS_I865G(i915)) { 9297 mode_config->cursor_width = IS_I845G(i915) ? 64 : 512; 9298 mode_config->cursor_height = 1023; 9299 } else if (IS_I830(i915) || IS_I85X(i915) || 9300 IS_I915G(i915) || IS_I915GM(i915)) { 9301 mode_config->cursor_width = 64; 9302 mode_config->cursor_height = 64; 9303 } else { 9304 mode_config->cursor_width = 256; 9305 mode_config->cursor_height = 256; 9306 } 9307 } 9308 9309 static void intel_mode_config_cleanup(struct drm_i915_private *i915) 9310 { 9311 intel_atomic_global_obj_cleanup(i915); 9312 drm_mode_config_cleanup(&i915->drm); 9313 } 9314 9315 /* part #1: call before irq install */ 9316 int intel_modeset_init_noirq(struct drm_i915_private *i915) 9317 { 9318 int ret; 9319 9320 if (i915_inject_probe_failure(i915)) 9321 return -ENODEV; 9322 9323 if (HAS_DISPLAY(i915)) { 9324 ret = drm_vblank_init(&i915->drm, 9325 INTEL_NUM_PIPES(i915)); 9326 if (ret) 9327 return ret; 9328 } 9329 9330 intel_bios_init(i915); 9331 9332 ret = intel_vga_register(i915); 9333 if (ret) 9334 goto cleanup_bios; 9335 9336 /* FIXME: completely on the wrong abstraction layer */ 9337 intel_power_domains_init_hw(i915, false); 9338 9339 if (!HAS_DISPLAY(i915)) 9340 return 0; 9341 9342 intel_dmc_ucode_init(i915); 9343 9344 i915->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0); 9345 i915->flip_wq = alloc_workqueue("i915_flip", WQ_HIGHPRI | 9346 WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE); 9347 9348 i915->window2_delay = 0; /* No DSB so no window2 delay */ 9349 9350 intel_mode_config_init(i915); 9351 9352 ret = intel_cdclk_init(i915); 9353 if (ret) 9354 goto cleanup_vga_client_pw_domain_dmc; 9355 9356 ret = intel_dbuf_init(i915); 9357 if (ret) 9358 goto cleanup_vga_client_pw_domain_dmc; 9359 9360 ret = intel_bw_init(i915); 9361 if (ret) 9362 goto cleanup_vga_client_pw_domain_dmc; 9363 9364 init_llist_head(&i915->atomic_helper.free_list); 9365 INIT_WORK(&i915->atomic_helper.free_work, 9366 intel_atomic_helper_free_state_worker); 9367 9368 intel_init_quirks(i915); 9369 9370 intel_fbc_init(i915); 9371 9372 return 0; 9373 9374 cleanup_vga_client_pw_domain_dmc: 9375 intel_dmc_ucode_fini(i915); 9376 intel_power_domains_driver_remove(i915); 9377 intel_vga_unregister(i915); 9378 cleanup_bios: 9379 intel_bios_driver_remove(i915); 9380 9381 return ret; 9382 } 9383 9384 /* part #2: call after irq install, but before gem init */ 9385 int intel_modeset_init_nogem(struct drm_i915_private *i915) 9386 { 9387 struct drm_device *dev = &i915->drm; 9388 enum pipe pipe; 9389 struct intel_crtc *crtc; 9390 int ret; 9391 9392 if (!HAS_DISPLAY(i915)) 9393 return 0; 9394 9395 intel_init_pm(i915); 9396 9397 intel_panel_sanitize_ssc(i915); 9398 9399 intel_pps_setup(i915); 9400 9401 intel_gmbus_setup(i915); 9402 9403 drm_dbg_kms(&i915->drm, "%d display pipe%s available.\n", 9404 INTEL_NUM_PIPES(i915), 9405 INTEL_NUM_PIPES(i915) > 1 ? "s" : ""); 9406 9407 for_each_pipe(i915, pipe) { 9408 ret = intel_crtc_init(i915, pipe); 9409 if (ret) { 9410 intel_mode_config_cleanup(i915); 9411 return ret; 9412 } 9413 } 9414 9415 intel_plane_possible_crtcs_init(i915); 9416 intel_shared_dpll_init(i915); 9417 intel_fdi_pll_freq_update(i915); 9418 9419 intel_update_czclk(i915); 9420 intel_modeset_init_hw(i915); 9421 intel_dpll_update_ref_clks(i915); 9422 9423 intel_hdcp_component_init(i915); 9424 9425 if (i915->max_cdclk_freq == 0) 9426 intel_update_max_cdclk(i915); 9427 9428 /* 9429 * If the platform has HTI, we need to find out whether it has reserved 9430 * any display resources before we create our display outputs. 9431 */ 9432 if (INTEL_INFO(i915)->display.has_hti) 9433 i915->hti_state = intel_de_read(i915, HDPORT_STATE); 9434 9435 /* Just disable it once at startup */ 9436 intel_vga_disable(i915); 9437 intel_setup_outputs(i915); 9438 9439 drm_modeset_lock_all(dev); 9440 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx); 9441 intel_acpi_assign_connector_fwnodes(i915); 9442 drm_modeset_unlock_all(dev); 9443 9444 for_each_intel_crtc(dev, crtc) { 9445 if (!to_intel_crtc_state(crtc->base.state)->uapi.active) 9446 continue; 9447 intel_crtc_initial_plane_config(crtc); 9448 } 9449 9450 /* 9451 * Make sure hardware watermarks really match the state we read out. 9452 * Note that we need to do this after reconstructing the BIOS fb's 9453 * since the watermark calculation done here will use pstate->fb. 9454 */ 9455 if (!HAS_GMCH(i915)) 9456 sanitize_watermarks(i915); 9457 9458 return 0; 9459 } 9460 9461 /* part #3: call after gem init */ 9462 int intel_modeset_init(struct drm_i915_private *i915) 9463 { 9464 int ret; 9465 9466 if (!HAS_DISPLAY(i915)) 9467 return 0; 9468 9469 /* 9470 * Force all active planes to recompute their states. So that on 9471 * mode_setcrtc after probe, all the intel_plane_state variables 9472 * are already calculated and there is no assert_plane warnings 9473 * during bootup. 9474 */ 9475 ret = intel_initial_commit(&i915->drm); 9476 if (ret) 9477 drm_dbg_kms(&i915->drm, "Initial modeset failed, %d\n", ret); 9478 9479 intel_overlay_setup(i915); 9480 9481 ret = intel_fbdev_init(&i915->drm); 9482 if (ret) 9483 return ret; 9484 9485 /* Only enable hotplug handling once the fbdev is fully set up. */ 9486 intel_hpd_init(i915); 9487 intel_hpd_poll_disable(i915); 9488 9489 intel_init_ipc(i915); 9490 9491 return 0; 9492 } 9493 9494 void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) 9495 { 9496 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe); 9497 /* 640x480@60Hz, ~25175 kHz */ 9498 struct dpll clock = { 9499 .m1 = 18, 9500 .m2 = 7, 9501 .p1 = 13, 9502 .p2 = 4, 9503 .n = 2, 9504 }; 9505 u32 dpll, fp; 9506 int i; 9507 9508 drm_WARN_ON(&dev_priv->drm, 9509 i9xx_calc_dpll_params(48000, &clock) != 25154); 9510 9511 drm_dbg_kms(&dev_priv->drm, 9512 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n", 9513 pipe_name(pipe), clock.vco, clock.dot); 9514 9515 fp = i9xx_dpll_compute_fp(&clock); 9516 dpll = DPLL_DVO_2X_MODE | 9517 DPLL_VGA_MODE_DIS | 9518 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | 9519 PLL_P2_DIVIDE_BY_4 | 9520 PLL_REF_INPUT_DREFCLK | 9521 DPLL_VCO_ENABLE; 9522 9523 intel_de_write(dev_priv, HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16)); 9524 intel_de_write(dev_priv, HBLANK(pipe), (640 - 1) | ((800 - 1) << 16)); 9525 intel_de_write(dev_priv, HSYNC(pipe), (656 - 1) | ((752 - 1) << 16)); 9526 intel_de_write(dev_priv, VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16)); 9527 intel_de_write(dev_priv, VBLANK(pipe), (480 - 1) | ((525 - 1) << 16)); 9528 intel_de_write(dev_priv, VSYNC(pipe), (490 - 1) | ((492 - 1) << 16)); 9529 intel_de_write(dev_priv, PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1)); 9530 9531 intel_de_write(dev_priv, FP0(pipe), fp); 9532 intel_de_write(dev_priv, FP1(pipe), fp); 9533 9534 /* 9535 * Apparently we need to have VGA mode enabled prior to changing 9536 * the P1/P2 dividers. Otherwise the DPLL will keep using the old 9537 * dividers, even though the register value does change. 9538 */ 9539 intel_de_write(dev_priv, DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS); 9540 intel_de_write(dev_priv, DPLL(pipe), dpll); 9541 9542 /* Wait for the clocks to stabilize. */ 9543 intel_de_posting_read(dev_priv, DPLL(pipe)); 9544 udelay(150); 9545 9546 /* The pixel multiplier can only be updated once the 9547 * DPLL is enabled and the clocks are stable. 9548 * 9549 * So write it again. 9550 */ 9551 intel_de_write(dev_priv, DPLL(pipe), dpll); 9552 9553 /* We do this three times for luck */ 9554 for (i = 0; i < 3 ; i++) { 9555 intel_de_write(dev_priv, DPLL(pipe), dpll); 9556 intel_de_posting_read(dev_priv, DPLL(pipe)); 9557 udelay(150); /* wait for warmup */ 9558 } 9559 9560 intel_de_write(dev_priv, PIPECONF(pipe), PIPECONF_ENABLE); 9561 intel_de_posting_read(dev_priv, PIPECONF(pipe)); 9562 9563 intel_wait_for_pipe_scanline_moving(crtc); 9564 } 9565 9566 void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe) 9567 { 9568 struct intel_crtc *crtc = intel_crtc_for_pipe(dev_priv, pipe); 9569 9570 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c due to force quirk\n", 9571 pipe_name(pipe)); 9572 9573 drm_WARN_ON(&dev_priv->drm, 9574 intel_de_read(dev_priv, DSPCNTR(PLANE_A)) & DISP_ENABLE); 9575 drm_WARN_ON(&dev_priv->drm, 9576 intel_de_read(dev_priv, DSPCNTR(PLANE_B)) & DISP_ENABLE); 9577 drm_WARN_ON(&dev_priv->drm, 9578 intel_de_read(dev_priv, DSPCNTR(PLANE_C)) & DISP_ENABLE); 9579 drm_WARN_ON(&dev_priv->drm, 9580 intel_de_read(dev_priv, CURCNTR(PIPE_A)) & MCURSOR_MODE_MASK); 9581 drm_WARN_ON(&dev_priv->drm, 9582 intel_de_read(dev_priv, CURCNTR(PIPE_B)) & MCURSOR_MODE_MASK); 9583 9584 intel_de_write(dev_priv, PIPECONF(pipe), 0); 9585 intel_de_posting_read(dev_priv, PIPECONF(pipe)); 9586 9587 intel_wait_for_pipe_scanline_stopped(crtc); 9588 9589 intel_de_write(dev_priv, DPLL(pipe), DPLL_VGA_MODE_DIS); 9590 intel_de_posting_read(dev_priv, DPLL(pipe)); 9591 } 9592 9593 static void 9594 intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv) 9595 { 9596 struct intel_crtc *crtc; 9597 9598 if (DISPLAY_VER(dev_priv) >= 4) 9599 return; 9600 9601 for_each_intel_crtc(&dev_priv->drm, crtc) { 9602 struct intel_plane *plane = 9603 to_intel_plane(crtc->base.primary); 9604 struct intel_crtc *plane_crtc; 9605 enum pipe pipe; 9606 9607 if (!plane->get_hw_state(plane, &pipe)) 9608 continue; 9609 9610 if (pipe == crtc->pipe) 9611 continue; 9612 9613 drm_dbg_kms(&dev_priv->drm, 9614 "[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n", 9615 plane->base.base.id, plane->base.name); 9616 9617 plane_crtc = intel_crtc_for_pipe(dev_priv, pipe); 9618 intel_plane_disable_noatomic(plane_crtc, plane); 9619 } 9620 } 9621 9622 static bool intel_crtc_has_encoders(struct intel_crtc *crtc) 9623 { 9624 struct drm_device *dev = crtc->base.dev; 9625 struct intel_encoder *encoder; 9626 9627 for_each_encoder_on_crtc(dev, &crtc->base, encoder) 9628 return true; 9629 9630 return false; 9631 } 9632 9633 static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) 9634 { 9635 struct drm_device *dev = encoder->base.dev; 9636 struct intel_connector *connector; 9637 9638 for_each_connector_on_encoder(dev, &encoder->base, connector) 9639 return connector; 9640 9641 return NULL; 9642 } 9643 9644 static void intel_sanitize_fifo_underrun_reporting(const struct intel_crtc_state *crtc_state) 9645 { 9646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 9647 struct drm_i915_private *i915 = to_i915(crtc->base.dev); 9648 9649 if (!crtc_state->hw.active && !HAS_GMCH(i915)) 9650 return; 9651 9652 /* 9653 * We start out with underrun reporting disabled to avoid races. 9654 * For correct bookkeeping mark this on active crtcs. 9655 * 9656 * Also on gmch platforms we dont have any hardware bits to 9657 * disable the underrun reporting. Which means we need to start 9658 * out with underrun reporting disabled also on inactive pipes, 9659 * since otherwise we'll complain about the garbage we read when 9660 * e.g. coming up after runtime pm. 9661 * 9662 * No protection against concurrent access is required - at 9663 * worst a fifo underrun happens which also sets this to false. 9664 */ 9665 crtc->cpu_fifo_underrun_disabled = true; 9666 9667 /* 9668 * We track the PCH trancoder underrun reporting state 9669 * within the crtc. With crtc for pipe A housing the underrun 9670 * reporting state for PCH transcoder A, crtc for pipe B housing 9671 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, 9672 * and marking underrun reporting as disabled for the non-existing 9673 * PCH transcoders B and C would prevent enabling the south 9674 * error interrupt (see cpt_can_enable_serr_int()). 9675 */ 9676 if (intel_has_pch_trancoder(i915, crtc->pipe)) 9677 crtc->pch_fifo_underrun_disabled = true; 9678 } 9679 9680 static void intel_sanitize_crtc(struct intel_crtc *crtc, 9681 struct drm_modeset_acquire_ctx *ctx) 9682 { 9683 struct drm_device *dev = crtc->base.dev; 9684 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); 9685 9686 if (crtc_state->hw.active) { 9687 struct intel_plane *plane; 9688 9689 /* Disable everything but the primary plane */ 9690 for_each_intel_plane_on_crtc(dev, crtc, plane) { 9691 const struct intel_plane_state *plane_state = 9692 to_intel_plane_state(plane->base.state); 9693 9694 if (plane_state->uapi.visible && 9695 plane->base.type != DRM_PLANE_TYPE_PRIMARY) 9696 intel_plane_disable_noatomic(crtc, plane); 9697 } 9698 9699 /* Disable any background color/etc. set by the BIOS */ 9700 intel_color_commit_noarm(crtc_state); 9701 intel_color_commit_arm(crtc_state); 9702 } 9703 9704 /* Adjust the state of the output pipe according to whether we 9705 * have active connectors/encoders. */ 9706 if (crtc_state->hw.active && !intel_crtc_has_encoders(crtc) && 9707 !intel_crtc_is_bigjoiner_slave(crtc_state)) 9708 intel_crtc_disable_noatomic(crtc, ctx); 9709 } 9710 9711 static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state) 9712 { 9713 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 9714 9715 /* 9716 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram 9717 * the hardware when a high res displays plugged in. DPLL P 9718 * divider is zero, and the pipe timings are bonkers. We'll 9719 * try to disable everything in that case. 9720 * 9721 * FIXME would be nice to be able to sanitize this state 9722 * without several WARNs, but for now let's take the easy 9723 * road. 9724 */ 9725 return IS_SANDYBRIDGE(dev_priv) && 9726 crtc_state->hw.active && 9727 crtc_state->shared_dpll && 9728 crtc_state->port_clock == 0; 9729 } 9730 9731 static void intel_sanitize_encoder(struct intel_encoder *encoder) 9732 { 9733 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 9734 struct intel_connector *connector; 9735 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc); 9736 struct intel_crtc_state *crtc_state = crtc ? 9737 to_intel_crtc_state(crtc->base.state) : NULL; 9738 9739 /* We need to check both for a crtc link (meaning that the 9740 * encoder is active and trying to read from a pipe) and the 9741 * pipe itself being active. */ 9742 bool has_active_crtc = crtc_state && 9743 crtc_state->hw.active; 9744 9745 if (crtc_state && has_bogus_dpll_config(crtc_state)) { 9746 drm_dbg_kms(&dev_priv->drm, 9747 "BIOS has misprogrammed the hardware. Disabling pipe %c\n", 9748 pipe_name(crtc->pipe)); 9749 has_active_crtc = false; 9750 } 9751 9752 connector = intel_encoder_find_connector(encoder); 9753 if (connector && !has_active_crtc) { 9754 drm_dbg_kms(&dev_priv->drm, 9755 "[ENCODER:%d:%s] has active connectors but no active pipe!\n", 9756 encoder->base.base.id, 9757 encoder->base.name); 9758 9759 /* Connector is active, but has no active pipe. This is 9760 * fallout from our resume register restoring. Disable 9761 * the encoder manually again. */ 9762 if (crtc_state) { 9763 struct drm_encoder *best_encoder; 9764 9765 drm_dbg_kms(&dev_priv->drm, 9766 "[ENCODER:%d:%s] manually disabled\n", 9767 encoder->base.base.id, 9768 encoder->base.name); 9769 9770 /* avoid oopsing in case the hooks consult best_encoder */ 9771 best_encoder = connector->base.state->best_encoder; 9772 connector->base.state->best_encoder = &encoder->base; 9773 9774 /* FIXME NULL atomic state passed! */ 9775 if (encoder->disable) 9776 encoder->disable(NULL, encoder, crtc_state, 9777 connector->base.state); 9778 if (encoder->post_disable) 9779 encoder->post_disable(NULL, encoder, crtc_state, 9780 connector->base.state); 9781 9782 connector->base.state->best_encoder = best_encoder; 9783 } 9784 encoder->base.crtc = NULL; 9785 9786 /* Inconsistent output/port/pipe state happens presumably due to 9787 * a bug in one of the get_hw_state functions. Or someplace else 9788 * in our code, like the register restore mess on resume. Clamp 9789 * things to off as a safer default. */ 9790 9791 connector->base.dpms = DRM_MODE_DPMS_OFF; 9792 connector->base.encoder = NULL; 9793 } 9794 9795 /* notify opregion of the sanitized encoder state */ 9796 intel_opregion_notify_encoder(encoder, connector && has_active_crtc); 9797 9798 if (HAS_DDI(dev_priv)) 9799 intel_ddi_sanitize_encoder_pll_mapping(encoder); 9800 } 9801 9802 /* FIXME read out full plane state for all planes */ 9803 static void readout_plane_state(struct drm_i915_private *dev_priv) 9804 { 9805 struct intel_plane *plane; 9806 struct intel_crtc *crtc; 9807 9808 for_each_intel_plane(&dev_priv->drm, plane) { 9809 struct intel_plane_state *plane_state = 9810 to_intel_plane_state(plane->base.state); 9811 struct intel_crtc_state *crtc_state; 9812 enum pipe pipe = PIPE_A; 9813 bool visible; 9814 9815 visible = plane->get_hw_state(plane, &pipe); 9816 9817 crtc = intel_crtc_for_pipe(dev_priv, pipe); 9818 crtc_state = to_intel_crtc_state(crtc->base.state); 9819 9820 intel_set_plane_visible(crtc_state, plane_state, visible); 9821 9822 drm_dbg_kms(&dev_priv->drm, 9823 "[PLANE:%d:%s] hw state readout: %s, pipe %c\n", 9824 plane->base.base.id, plane->base.name, 9825 str_enabled_disabled(visible), pipe_name(pipe)); 9826 } 9827 9828 for_each_intel_crtc(&dev_priv->drm, crtc) { 9829 struct intel_crtc_state *crtc_state = 9830 to_intel_crtc_state(crtc->base.state); 9831 9832 fixup_plane_bitmasks(crtc_state); 9833 } 9834 } 9835 9836 static void intel_modeset_readout_hw_state(struct drm_device *dev) 9837 { 9838 struct drm_i915_private *dev_priv = to_i915(dev); 9839 struct intel_cdclk_state *cdclk_state = 9840 to_intel_cdclk_state(dev_priv->cdclk.obj.state); 9841 struct intel_dbuf_state *dbuf_state = 9842 to_intel_dbuf_state(dev_priv->dbuf.obj.state); 9843 enum pipe pipe; 9844 struct intel_crtc *crtc; 9845 struct intel_encoder *encoder; 9846 struct intel_connector *connector; 9847 struct drm_connector_list_iter conn_iter; 9848 u8 active_pipes = 0; 9849 9850 for_each_intel_crtc(dev, crtc) { 9851 struct intel_crtc_state *crtc_state = 9852 to_intel_crtc_state(crtc->base.state); 9853 9854 __drm_atomic_helper_crtc_destroy_state(&crtc_state->uapi); 9855 intel_crtc_free_hw_state(crtc_state); 9856 intel_crtc_state_reset(crtc_state, crtc); 9857 9858 intel_crtc_get_pipe_config(crtc_state); 9859 9860 crtc_state->hw.enable = crtc_state->hw.active; 9861 9862 crtc->base.enabled = crtc_state->hw.enable; 9863 crtc->active = crtc_state->hw.active; 9864 9865 if (crtc_state->hw.active) 9866 active_pipes |= BIT(crtc->pipe); 9867 9868 drm_dbg_kms(&dev_priv->drm, 9869 "[CRTC:%d:%s] hw state readout: %s\n", 9870 crtc->base.base.id, crtc->base.name, 9871 str_enabled_disabled(crtc_state->hw.active)); 9872 } 9873 9874 cdclk_state->active_pipes = dbuf_state->active_pipes = active_pipes; 9875 9876 readout_plane_state(dev_priv); 9877 9878 for_each_intel_encoder(dev, encoder) { 9879 struct intel_crtc_state *crtc_state = NULL; 9880 9881 pipe = 0; 9882 9883 if (encoder->get_hw_state(encoder, &pipe)) { 9884 crtc = intel_crtc_for_pipe(dev_priv, pipe); 9885 crtc_state = to_intel_crtc_state(crtc->base.state); 9886 9887 encoder->base.crtc = &crtc->base; 9888 intel_encoder_get_config(encoder, crtc_state); 9889 9890 /* read out to slave crtc as well for bigjoiner */ 9891 if (crtc_state->bigjoiner_pipes) { 9892 struct intel_crtc *slave_crtc; 9893 9894 /* encoder should read be linked to bigjoiner master */ 9895 WARN_ON(intel_crtc_is_bigjoiner_slave(crtc_state)); 9896 9897 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, slave_crtc, 9898 intel_crtc_bigjoiner_slave_pipes(crtc_state)) { 9899 struct intel_crtc_state *slave_crtc_state; 9900 9901 slave_crtc_state = to_intel_crtc_state(slave_crtc->base.state); 9902 intel_encoder_get_config(encoder, slave_crtc_state); 9903 } 9904 } 9905 } else { 9906 encoder->base.crtc = NULL; 9907 } 9908 9909 if (encoder->sync_state) 9910 encoder->sync_state(encoder, crtc_state); 9911 9912 drm_dbg_kms(&dev_priv->drm, 9913 "[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", 9914 encoder->base.base.id, encoder->base.name, 9915 str_enabled_disabled(encoder->base.crtc), 9916 pipe_name(pipe)); 9917 } 9918 9919 intel_dpll_readout_hw_state(dev_priv); 9920 9921 drm_connector_list_iter_begin(dev, &conn_iter); 9922 for_each_intel_connector_iter(connector, &conn_iter) { 9923 if (connector->get_hw_state(connector)) { 9924 struct intel_crtc_state *crtc_state; 9925 struct intel_crtc *crtc; 9926 9927 connector->base.dpms = DRM_MODE_DPMS_ON; 9928 9929 encoder = intel_attached_encoder(connector); 9930 connector->base.encoder = &encoder->base; 9931 9932 crtc = to_intel_crtc(encoder->base.crtc); 9933 crtc_state = crtc ? to_intel_crtc_state(crtc->base.state) : NULL; 9934 9935 if (crtc_state && crtc_state->hw.active) { 9936 /* 9937 * This has to be done during hardware readout 9938 * because anything calling .crtc_disable may 9939 * rely on the connector_mask being accurate. 9940 */ 9941 crtc_state->uapi.connector_mask |= 9942 drm_connector_mask(&connector->base); 9943 crtc_state->uapi.encoder_mask |= 9944 drm_encoder_mask(&encoder->base); 9945 } 9946 } else { 9947 connector->base.dpms = DRM_MODE_DPMS_OFF; 9948 connector->base.encoder = NULL; 9949 } 9950 drm_dbg_kms(&dev_priv->drm, 9951 "[CONNECTOR:%d:%s] hw state readout: %s\n", 9952 connector->base.base.id, connector->base.name, 9953 str_enabled_disabled(connector->base.encoder)); 9954 } 9955 drm_connector_list_iter_end(&conn_iter); 9956 9957 for_each_intel_crtc(dev, crtc) { 9958 struct intel_bw_state *bw_state = 9959 to_intel_bw_state(dev_priv->bw_obj.state); 9960 struct intel_crtc_state *crtc_state = 9961 to_intel_crtc_state(crtc->base.state); 9962 struct intel_plane *plane; 9963 int min_cdclk = 0; 9964 9965 if (crtc_state->hw.active) { 9966 /* 9967 * The initial mode needs to be set in order to keep 9968 * the atomic core happy. It wants a valid mode if the 9969 * crtc's enabled, so we do the above call. 9970 * 9971 * But we don't set all the derived state fully, hence 9972 * set a flag to indicate that a full recalculation is 9973 * needed on the next commit. 9974 */ 9975 crtc_state->inherited = true; 9976 9977 intel_crtc_update_active_timings(crtc_state); 9978 9979 intel_crtc_copy_hw_to_uapi_state(crtc_state); 9980 } 9981 9982 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { 9983 const struct intel_plane_state *plane_state = 9984 to_intel_plane_state(plane->base.state); 9985 9986 /* 9987 * FIXME don't have the fb yet, so can't 9988 * use intel_plane_data_rate() :( 9989 */ 9990 if (plane_state->uapi.visible) 9991 crtc_state->data_rate[plane->id] = 9992 4 * crtc_state->pixel_rate; 9993 /* 9994 * FIXME don't have the fb yet, so can't 9995 * use plane->min_cdclk() :( 9996 */ 9997 if (plane_state->uapi.visible && plane->min_cdclk) { 9998 if (crtc_state->double_wide || DISPLAY_VER(dev_priv) >= 10) 9999 crtc_state->min_cdclk[plane->id] = 10000 DIV_ROUND_UP(crtc_state->pixel_rate, 2); 10001 else 10002 crtc_state->min_cdclk[plane->id] = 10003 crtc_state->pixel_rate; 10004 } 10005 drm_dbg_kms(&dev_priv->drm, 10006 "[PLANE:%d:%s] min_cdclk %d kHz\n", 10007 plane->base.base.id, plane->base.name, 10008 crtc_state->min_cdclk[plane->id]); 10009 } 10010 10011 if (crtc_state->hw.active) { 10012 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state); 10013 if (drm_WARN_ON(dev, min_cdclk < 0)) 10014 min_cdclk = 0; 10015 } 10016 10017 cdclk_state->min_cdclk[crtc->pipe] = min_cdclk; 10018 cdclk_state->min_voltage_level[crtc->pipe] = 10019 crtc_state->min_voltage_level; 10020 10021 intel_bw_crtc_update(bw_state, crtc_state); 10022 } 10023 } 10024 10025 static void 10026 get_encoder_power_domains(struct drm_i915_private *dev_priv) 10027 { 10028 struct intel_encoder *encoder; 10029 10030 for_each_intel_encoder(&dev_priv->drm, encoder) { 10031 struct intel_crtc_state *crtc_state; 10032 10033 if (!encoder->get_power_domains) 10034 continue; 10035 10036 /* 10037 * MST-primary and inactive encoders don't have a crtc state 10038 * and neither of these require any power domain references. 10039 */ 10040 if (!encoder->base.crtc) 10041 continue; 10042 10043 crtc_state = to_intel_crtc_state(encoder->base.crtc->state); 10044 encoder->get_power_domains(encoder, crtc_state); 10045 } 10046 } 10047 10048 static void intel_early_display_was(struct drm_i915_private *dev_priv) 10049 { 10050 /* 10051 * Display WA #1185 WaDisableDARBFClkGating:glk,icl,ehl,tgl 10052 * Also known as Wa_14010480278. 10053 */ 10054 if (IS_DISPLAY_VER(dev_priv, 10, 12)) 10055 intel_de_write(dev_priv, GEN9_CLKGATE_DIS_0, 10056 intel_de_read(dev_priv, GEN9_CLKGATE_DIS_0) | DARBF_GATING_DIS); 10057 10058 if (IS_HASWELL(dev_priv)) { 10059 /* 10060 * WaRsPkgCStateDisplayPMReq:hsw 10061 * System hang if this isn't done before disabling all planes! 10062 */ 10063 intel_de_write(dev_priv, CHICKEN_PAR1_1, 10064 intel_de_read(dev_priv, CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES); 10065 } 10066 10067 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) { 10068 /* Display WA #1142:kbl,cfl,cml */ 10069 intel_de_rmw(dev_priv, CHICKEN_PAR1_1, 10070 KBL_ARB_FILL_SPARE_22, KBL_ARB_FILL_SPARE_22); 10071 intel_de_rmw(dev_priv, CHICKEN_MISC_2, 10072 KBL_ARB_FILL_SPARE_13 | KBL_ARB_FILL_SPARE_14, 10073 KBL_ARB_FILL_SPARE_14); 10074 } 10075 } 10076 10077 10078 /* Scan out the current hw modeset state, 10079 * and sanitizes it to the current state 10080 */ 10081 static void 10082 intel_modeset_setup_hw_state(struct drm_device *dev, 10083 struct drm_modeset_acquire_ctx *ctx) 10084 { 10085 struct drm_i915_private *dev_priv = to_i915(dev); 10086 struct intel_encoder *encoder; 10087 struct intel_crtc *crtc; 10088 intel_wakeref_t wakeref; 10089 10090 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); 10091 10092 intel_early_display_was(dev_priv); 10093 intel_modeset_readout_hw_state(dev); 10094 10095 /* HW state is read out, now we need to sanitize this mess. */ 10096 get_encoder_power_domains(dev_priv); 10097 10098 intel_pch_sanitize(dev_priv); 10099 10100 /* 10101 * intel_sanitize_plane_mapping() may need to do vblank 10102 * waits, so we need vblank interrupts restored beforehand. 10103 */ 10104 for_each_intel_crtc(&dev_priv->drm, crtc) { 10105 struct intel_crtc_state *crtc_state = 10106 to_intel_crtc_state(crtc->base.state); 10107 10108 intel_sanitize_fifo_underrun_reporting(crtc_state); 10109 10110 drm_crtc_vblank_reset(&crtc->base); 10111 10112 if (crtc_state->hw.active) 10113 intel_crtc_vblank_on(crtc_state); 10114 } 10115 10116 intel_fbc_sanitize(dev_priv); 10117 10118 intel_sanitize_plane_mapping(dev_priv); 10119 10120 for_each_intel_encoder(dev, encoder) 10121 intel_sanitize_encoder(encoder); 10122 10123 for_each_intel_crtc(&dev_priv->drm, crtc) { 10124 struct intel_crtc_state *crtc_state = 10125 to_intel_crtc_state(crtc->base.state); 10126 10127 intel_sanitize_crtc(crtc, ctx); 10128 intel_dump_pipe_config(crtc_state, NULL, "[setup_hw_state]"); 10129 } 10130 10131 intel_modeset_update_connector_atomic_state(dev); 10132 10133 intel_dpll_sanitize_state(dev_priv); 10134 10135 if (IS_G4X(dev_priv)) { 10136 g4x_wm_get_hw_state(dev_priv); 10137 g4x_wm_sanitize(dev_priv); 10138 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { 10139 vlv_wm_get_hw_state(dev_priv); 10140 vlv_wm_sanitize(dev_priv); 10141 } else if (DISPLAY_VER(dev_priv) >= 9) { 10142 skl_wm_get_hw_state(dev_priv); 10143 skl_wm_sanitize(dev_priv); 10144 } else if (HAS_PCH_SPLIT(dev_priv)) { 10145 ilk_wm_get_hw_state(dev_priv); 10146 } 10147 10148 for_each_intel_crtc(dev, crtc) { 10149 struct intel_crtc_state *crtc_state = 10150 to_intel_crtc_state(crtc->base.state); 10151 struct intel_power_domain_mask put_domains; 10152 10153 modeset_get_crtc_power_domains(crtc_state, &put_domains); 10154 if (drm_WARN_ON(dev, !bitmap_empty(put_domains.bits, POWER_DOMAIN_NUM))) 10155 modeset_put_crtc_power_domains(crtc, &put_domains); 10156 } 10157 10158 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref); 10159 10160 intel_power_domains_sanitize_state(dev_priv); 10161 } 10162 10163 void intel_display_resume(struct drm_device *dev) 10164 { 10165 struct drm_i915_private *dev_priv = to_i915(dev); 10166 struct drm_atomic_state *state = dev_priv->modeset_restore_state; 10167 struct drm_modeset_acquire_ctx ctx; 10168 int ret; 10169 10170 if (!HAS_DISPLAY(dev_priv)) 10171 return; 10172 10173 dev_priv->modeset_restore_state = NULL; 10174 if (state) 10175 state->acquire_ctx = &ctx; 10176 10177 drm_modeset_acquire_init(&ctx, 0); 10178 10179 while (1) { 10180 ret = drm_modeset_lock_all_ctx(dev, &ctx); 10181 if (ret != -EDEADLK) 10182 break; 10183 10184 drm_modeset_backoff(&ctx); 10185 } 10186 10187 if (!ret) 10188 ret = __intel_display_resume(dev, state, &ctx); 10189 10190 intel_enable_ipc(dev_priv); 10191 drm_modeset_drop_locks(&ctx); 10192 drm_modeset_acquire_fini(&ctx); 10193 10194 if (ret) 10195 drm_err(&dev_priv->drm, 10196 "Restoring old state failed with %i\n", ret); 10197 if (state) 10198 drm_atomic_state_put(state); 10199 } 10200 10201 static void intel_hpd_poll_fini(struct drm_i915_private *i915) 10202 { 10203 struct intel_connector *connector; 10204 struct drm_connector_list_iter conn_iter; 10205 10206 /* Kill all the work that may have been queued by hpd. */ 10207 drm_connector_list_iter_begin(&i915->drm, &conn_iter); 10208 for_each_intel_connector_iter(connector, &conn_iter) { 10209 if (connector->modeset_retry_work.func) 10210 cancel_work_sync(&connector->modeset_retry_work); 10211 if (connector->hdcp.shim) { 10212 cancel_delayed_work_sync(&connector->hdcp.check_work); 10213 cancel_work_sync(&connector->hdcp.prop_work); 10214 } 10215 } 10216 drm_connector_list_iter_end(&conn_iter); 10217 } 10218 10219 /* part #1: call before irq uninstall */ 10220 void intel_modeset_driver_remove(struct drm_i915_private *i915) 10221 { 10222 if (!HAS_DISPLAY(i915)) 10223 return; 10224 10225 flush_workqueue(i915->flip_wq); 10226 flush_workqueue(i915->modeset_wq); 10227 10228 flush_work(&i915->atomic_helper.free_work); 10229 drm_WARN_ON(&i915->drm, !llist_empty(&i915->atomic_helper.free_list)); 10230 } 10231 10232 /* part #2: call after irq uninstall */ 10233 void intel_modeset_driver_remove_noirq(struct drm_i915_private *i915) 10234 { 10235 if (!HAS_DISPLAY(i915)) 10236 return; 10237 10238 /* 10239 * Due to the hpd irq storm handling the hotplug work can re-arm the 10240 * poll handlers. Hence disable polling after hpd handling is shut down. 10241 */ 10242 intel_hpd_poll_fini(i915); 10243 10244 /* 10245 * MST topology needs to be suspended so we don't have any calls to 10246 * fbdev after it's finalized. MST will be destroyed later as part of 10247 * drm_mode_config_cleanup() 10248 */ 10249 intel_dp_mst_suspend(i915); 10250 10251 /* poll work can call into fbdev, hence clean that up afterwards */ 10252 intel_fbdev_fini(i915); 10253 10254 intel_unregister_dsm_handler(); 10255 10256 /* flush any delayed tasks or pending work */ 10257 flush_scheduled_work(); 10258 10259 intel_hdcp_component_fini(i915); 10260 10261 intel_mode_config_cleanup(i915); 10262 10263 intel_overlay_cleanup(i915); 10264 10265 intel_gmbus_teardown(i915); 10266 10267 destroy_workqueue(i915->flip_wq); 10268 destroy_workqueue(i915->modeset_wq); 10269 10270 intel_fbc_cleanup(i915); 10271 } 10272 10273 /* part #3: call after gem init */ 10274 void intel_modeset_driver_remove_nogem(struct drm_i915_private *i915) 10275 { 10276 intel_dmc_ucode_fini(i915); 10277 10278 intel_power_domains_driver_remove(i915); 10279 10280 intel_vga_unregister(i915); 10281 10282 intel_bios_driver_remove(i915); 10283 } 10284 10285 bool intel_modeset_probe_defer(struct pci_dev *pdev) 10286 { 10287 struct drm_privacy_screen *privacy_screen; 10288 10289 /* 10290 * apple-gmux is needed on dual GPU MacBook Pro 10291 * to probe the panel if we're the inactive GPU. 10292 */ 10293 if (vga_switcheroo_client_probe_defer(pdev)) 10294 return true; 10295 10296 /* If the LCD panel has a privacy-screen, wait for it */ 10297 privacy_screen = drm_privacy_screen_get(&pdev->dev, NULL); 10298 if (IS_ERR(privacy_screen) && PTR_ERR(privacy_screen) == -EPROBE_DEFER) 10299 return true; 10300 10301 drm_privacy_screen_put(privacy_screen); 10302 10303 return false; 10304 } 10305 10306 void intel_display_driver_register(struct drm_i915_private *i915) 10307 { 10308 if (!HAS_DISPLAY(i915)) 10309 return; 10310 10311 intel_display_debugfs_register(i915); 10312 10313 /* Must be done after probing outputs */ 10314 intel_opregion_register(i915); 10315 acpi_video_register(); 10316 10317 intel_audio_init(i915); 10318 10319 /* 10320 * Some ports require correctly set-up hpd registers for 10321 * detection to work properly (leading to ghost connected 10322 * connector status), e.g. VGA on gm45. Hence we can only set 10323 * up the initial fbdev config after hpd irqs are fully 10324 * enabled. We do it last so that the async config cannot run 10325 * before the connectors are registered. 10326 */ 10327 intel_fbdev_initial_config_async(&i915->drm); 10328 10329 /* 10330 * We need to coordinate the hotplugs with the asynchronous 10331 * fbdev configuration, for which we use the 10332 * fbdev->async_cookie. 10333 */ 10334 drm_kms_helper_poll_init(&i915->drm); 10335 } 10336 10337 void intel_display_driver_unregister(struct drm_i915_private *i915) 10338 { 10339 if (!HAS_DISPLAY(i915)) 10340 return; 10341 10342 intel_fbdev_unregister(i915); 10343 intel_audio_deinit(i915); 10344 10345 /* 10346 * After flushing the fbdev (incl. a late async config which 10347 * will have delayed queuing of a hotplug event), then flush 10348 * the hotplug events. 10349 */ 10350 drm_kms_helper_poll_fini(&i915->drm); 10351 drm_atomic_helper_shutdown(&i915->drm); 10352 10353 acpi_video_unregister(); 10354 intel_opregion_unregister(i915); 10355 } 10356 10357 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915) 10358 { 10359 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915); 10360 } 10361