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