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 <linux/dma-resv.h> 28 #include <linux/i2c.h> 29 #include <linux/input.h> 30 #include <linux/kernel.h> 31 #include <linux/module.h> 32 #include <linux/slab.h> 33 #include <linux/string_helpers.h> 34 35 #include <drm/display/drm_dp_helper.h> 36 #include <drm/display/drm_dp_tunnel.h> 37 #include <drm/drm_atomic.h> 38 #include <drm/drm_atomic_helper.h> 39 #include <drm/drm_atomic_uapi.h> 40 #include <drm/drm_damage_helper.h> 41 #include <drm/drm_edid.h> 42 #include <drm/drm_fixed.h> 43 #include <drm/drm_fourcc.h> 44 #include <drm/drm_probe_helper.h> 45 #include <drm/drm_rect.h> 46 #include <drm/drm_vblank.h> 47 48 #include "g4x_dp.h" 49 #include "g4x_hdmi.h" 50 #include "hsw_ips.h" 51 #include "i915_config.h" 52 #include "i915_drv.h" 53 #include "i915_reg.h" 54 #include "i915_utils.h" 55 #include "i9xx_plane.h" 56 #include "i9xx_plane_regs.h" 57 #include "i9xx_wm.h" 58 #include "intel_alpm.h" 59 #include "intel_atomic.h" 60 #include "intel_audio.h" 61 #include "intel_bo.h" 62 #include "intel_bw.h" 63 #include "intel_cdclk.h" 64 #include "intel_clock_gating.h" 65 #include "intel_color.h" 66 #include "intel_crt.h" 67 #include "intel_crtc.h" 68 #include "intel_crtc_state_dump.h" 69 #include "intel_cursor.h" 70 #include "intel_cursor_regs.h" 71 #include "intel_cx0_phy.h" 72 #include "intel_ddi.h" 73 #include "intel_de.h" 74 #include "intel_display_driver.h" 75 #include "intel_display_power.h" 76 #include "intel_display_regs.h" 77 #include "intel_display_rpm.h" 78 #include "intel_display_types.h" 79 #include "intel_dmc.h" 80 #include "intel_dp.h" 81 #include "intel_dp_link_training.h" 82 #include "intel_dp_mst.h" 83 #include "intel_dp_tunnel.h" 84 #include "intel_dpll.h" 85 #include "intel_dpll_mgr.h" 86 #include "intel_dpt.h" 87 #include "intel_dpt_common.h" 88 #include "intel_drrs.h" 89 #include "intel_dsb.h" 90 #include "intel_dsi.h" 91 #include "intel_dvo.h" 92 #include "intel_fb.h" 93 #include "intel_fbc.h" 94 #include "intel_fdi.h" 95 #include "intel_fifo_underrun.h" 96 #include "intel_flipq.h" 97 #include "intel_frontbuffer.h" 98 #include "intel_hdmi.h" 99 #include "intel_hotplug.h" 100 #include "intel_link_bw.h" 101 #include "intel_lvds.h" 102 #include "intel_lvds_regs.h" 103 #include "intel_modeset_setup.h" 104 #include "intel_modeset_verify.h" 105 #include "intel_overlay.h" 106 #include "intel_panel.h" 107 #include "intel_pch_display.h" 108 #include "intel_pch_refclk.h" 109 #include "intel_pfit.h" 110 #include "intel_pipe_crc.h" 111 #include "intel_plane.h" 112 #include "intel_plane_initial.h" 113 #include "intel_pmdemand.h" 114 #include "intel_pps.h" 115 #include "intel_psr.h" 116 #include "intel_psr_regs.h" 117 #include "intel_sdvo.h" 118 #include "intel_snps_phy.h" 119 #include "intel_tc.h" 120 #include "intel_tdf.h" 121 #include "intel_tv.h" 122 #include "intel_vblank.h" 123 #include "intel_vdsc.h" 124 #include "intel_vdsc_regs.h" 125 #include "intel_vga.h" 126 #include "intel_vrr.h" 127 #include "intel_wm.h" 128 #include "skl_scaler.h" 129 #include "skl_universal_plane.h" 130 #include "skl_watermark.h" 131 #include "vlv_dpio_phy_regs.h" 132 #include "vlv_dsi.h" 133 #include "vlv_dsi_pll.h" 134 #include "vlv_dsi_regs.h" 135 #include "vlv_sideband.h" 136 137 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state); 138 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state); 139 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state); 140 static void bdw_set_pipe_misc(struct intel_dsb *dsb, 141 const struct intel_crtc_state *crtc_state); 142 143 /* returns HPLL frequency in kHz */ 144 int vlv_get_hpll_vco(struct drm_device *drm) 145 { 146 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; 147 148 /* Obtain SKU information */ 149 hpll_freq = vlv_cck_read(drm, CCK_FUSE_REG) & 150 CCK_FUSE_HPLL_FREQ_MASK; 151 152 return vco_freq[hpll_freq] * 1000; 153 } 154 155 int vlv_get_cck_clock(struct drm_device *drm, 156 const char *name, u32 reg, int ref_freq) 157 { 158 u32 val; 159 int divider; 160 161 val = vlv_cck_read(drm, reg); 162 divider = val & CCK_FREQUENCY_VALUES; 163 164 drm_WARN(drm, (val & CCK_FREQUENCY_STATUS) != 165 (divider << CCK_FREQUENCY_STATUS_SHIFT), 166 "%s change in progress\n", name); 167 168 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); 169 } 170 171 int vlv_get_cck_clock_hpll(struct drm_device *drm, 172 const char *name, u32 reg) 173 { 174 struct drm_i915_private *dev_priv = to_i915(drm); 175 int hpll; 176 177 vlv_cck_get(drm); 178 179 if (dev_priv->hpll_freq == 0) 180 dev_priv->hpll_freq = vlv_get_hpll_vco(drm); 181 182 hpll = vlv_get_cck_clock(drm, name, reg, dev_priv->hpll_freq); 183 184 vlv_cck_put(drm); 185 186 return hpll; 187 } 188 189 void intel_update_czclk(struct intel_display *display) 190 { 191 struct drm_i915_private *dev_priv = to_i915(display->drm); 192 193 if (!display->platform.valleyview && !display->platform.cherryview) 194 return; 195 196 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(display->drm, "czclk", 197 CCK_CZ_CLOCK_CONTROL); 198 199 drm_dbg_kms(display->drm, "CZ clock rate: %d kHz\n", dev_priv->czclk_freq); 200 } 201 202 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state) 203 { 204 return (crtc_state->active_planes & 205 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0; 206 } 207 208 /* WA Display #0827: Gen9:all */ 209 static void 210 skl_wa_827(struct intel_display *display, enum pipe pipe, bool enable) 211 { 212 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe), 213 DUPS1_GATING_DIS | DUPS2_GATING_DIS, 214 enable ? DUPS1_GATING_DIS | DUPS2_GATING_DIS : 0); 215 } 216 217 /* Wa_2006604312:icl,ehl */ 218 static void 219 icl_wa_scalerclkgating(struct intel_display *display, enum pipe pipe, 220 bool enable) 221 { 222 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe), 223 DPFR_GATING_DIS, 224 enable ? DPFR_GATING_DIS : 0); 225 } 226 227 /* Wa_1604331009:icl,jsl,ehl */ 228 static void 229 icl_wa_cursorclkgating(struct intel_display *display, enum pipe pipe, 230 bool enable) 231 { 232 intel_de_rmw(display, CLKGATE_DIS_PSL(pipe), 233 CURSOR_GATING_DIS, 234 enable ? CURSOR_GATING_DIS : 0); 235 } 236 237 static bool 238 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state) 239 { 240 return crtc_state->master_transcoder != INVALID_TRANSCODER; 241 } 242 243 bool 244 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state) 245 { 246 return crtc_state->sync_mode_slaves_mask != 0; 247 } 248 249 bool 250 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state) 251 { 252 return is_trans_port_sync_master(crtc_state) || 253 is_trans_port_sync_slave(crtc_state); 254 } 255 256 static enum pipe joiner_primary_pipe(const struct intel_crtc_state *crtc_state) 257 { 258 return ffs(crtc_state->joiner_pipes) - 1; 259 } 260 261 /* 262 * The following helper functions, despite being named for bigjoiner, 263 * are applicable to both bigjoiner and uncompressed joiner configurations. 264 */ 265 static bool is_bigjoiner(const struct intel_crtc_state *crtc_state) 266 { 267 return hweight8(crtc_state->joiner_pipes) >= 2; 268 } 269 270 static u8 bigjoiner_primary_pipes(const struct intel_crtc_state *crtc_state) 271 { 272 if (!is_bigjoiner(crtc_state)) 273 return 0; 274 275 return crtc_state->joiner_pipes & (0b01010101 << joiner_primary_pipe(crtc_state)); 276 } 277 278 static unsigned int bigjoiner_secondary_pipes(const struct intel_crtc_state *crtc_state) 279 { 280 if (!is_bigjoiner(crtc_state)) 281 return 0; 282 283 return crtc_state->joiner_pipes & (0b10101010 << joiner_primary_pipe(crtc_state)); 284 } 285 286 bool intel_crtc_is_bigjoiner_primary(const struct intel_crtc_state *crtc_state) 287 { 288 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 289 290 if (!is_bigjoiner(crtc_state)) 291 return false; 292 293 return BIT(crtc->pipe) & bigjoiner_primary_pipes(crtc_state); 294 } 295 296 bool intel_crtc_is_bigjoiner_secondary(const struct intel_crtc_state *crtc_state) 297 { 298 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 299 300 if (!is_bigjoiner(crtc_state)) 301 return false; 302 303 return BIT(crtc->pipe) & bigjoiner_secondary_pipes(crtc_state); 304 } 305 306 u8 _intel_modeset_primary_pipes(const struct intel_crtc_state *crtc_state) 307 { 308 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 309 310 if (!is_bigjoiner(crtc_state)) 311 return BIT(crtc->pipe); 312 313 return bigjoiner_primary_pipes(crtc_state); 314 } 315 316 u8 _intel_modeset_secondary_pipes(const struct intel_crtc_state *crtc_state) 317 { 318 return bigjoiner_secondary_pipes(crtc_state); 319 } 320 321 bool intel_crtc_is_ultrajoiner(const struct intel_crtc_state *crtc_state) 322 { 323 return intel_crtc_num_joined_pipes(crtc_state) >= 4; 324 } 325 326 static u8 ultrajoiner_primary_pipes(const struct intel_crtc_state *crtc_state) 327 { 328 if (!intel_crtc_is_ultrajoiner(crtc_state)) 329 return 0; 330 331 return crtc_state->joiner_pipes & (0b00010001 << joiner_primary_pipe(crtc_state)); 332 } 333 334 bool intel_crtc_is_ultrajoiner_primary(const struct intel_crtc_state *crtc_state) 335 { 336 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 337 338 return intel_crtc_is_ultrajoiner(crtc_state) && 339 BIT(crtc->pipe) & ultrajoiner_primary_pipes(crtc_state); 340 } 341 342 /* 343 * The ultrajoiner enable bit doesn't seem to follow primary/secondary logic or 344 * any other logic, so lets just add helper function to 345 * at least hide this hassle.. 346 */ 347 static u8 ultrajoiner_enable_pipes(const struct intel_crtc_state *crtc_state) 348 { 349 if (!intel_crtc_is_ultrajoiner(crtc_state)) 350 return 0; 351 352 return crtc_state->joiner_pipes & (0b01110111 << joiner_primary_pipe(crtc_state)); 353 } 354 355 bool intel_crtc_ultrajoiner_enable_needed(const struct intel_crtc_state *crtc_state) 356 { 357 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 358 359 return intel_crtc_is_ultrajoiner(crtc_state) && 360 BIT(crtc->pipe) & ultrajoiner_enable_pipes(crtc_state); 361 } 362 363 u8 intel_crtc_joiner_secondary_pipes(const struct intel_crtc_state *crtc_state) 364 { 365 if (crtc_state->joiner_pipes) 366 return crtc_state->joiner_pipes & ~BIT(joiner_primary_pipe(crtc_state)); 367 else 368 return 0; 369 } 370 371 bool intel_crtc_is_joiner_secondary(const struct intel_crtc_state *crtc_state) 372 { 373 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 374 375 return crtc_state->joiner_pipes && 376 crtc->pipe != joiner_primary_pipe(crtc_state); 377 } 378 379 bool intel_crtc_is_joiner_primary(const struct intel_crtc_state *crtc_state) 380 { 381 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 382 383 return crtc_state->joiner_pipes && 384 crtc->pipe == joiner_primary_pipe(crtc_state); 385 } 386 387 int intel_crtc_num_joined_pipes(const struct intel_crtc_state *crtc_state) 388 { 389 return hweight8(intel_crtc_joined_pipe_mask(crtc_state)); 390 } 391 392 u8 intel_crtc_joined_pipe_mask(const struct intel_crtc_state *crtc_state) 393 { 394 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 395 396 return BIT(crtc->pipe) | crtc_state->joiner_pipes; 397 } 398 399 struct intel_crtc *intel_primary_crtc(const struct intel_crtc_state *crtc_state) 400 { 401 struct intel_display *display = to_intel_display(crtc_state); 402 403 if (intel_crtc_is_joiner_secondary(crtc_state)) 404 return intel_crtc_for_pipe(display, joiner_primary_pipe(crtc_state)); 405 else 406 return to_intel_crtc(crtc_state->uapi.crtc); 407 } 408 409 static void 410 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state) 411 { 412 struct intel_display *display = to_intel_display(old_crtc_state); 413 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 414 415 if (DISPLAY_VER(display) >= 4) { 416 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 417 418 /* Wait for the Pipe State to go off */ 419 if (intel_de_wait_for_clear(display, TRANSCONF(display, cpu_transcoder), 420 TRANSCONF_STATE_ENABLE, 100)) 421 drm_WARN(display->drm, 1, "pipe_off wait timed out\n"); 422 } else { 423 intel_wait_for_pipe_scanline_stopped(crtc); 424 } 425 } 426 427 void assert_transcoder(struct intel_display *display, 428 enum transcoder cpu_transcoder, bool state) 429 { 430 bool cur_state; 431 enum intel_display_power_domain power_domain; 432 intel_wakeref_t wakeref; 433 434 /* we keep both pipes enabled on 830 */ 435 if (display->platform.i830) 436 state = true; 437 438 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 439 wakeref = intel_display_power_get_if_enabled(display, power_domain); 440 if (wakeref) { 441 u32 val = intel_de_read(display, 442 TRANSCONF(display, cpu_transcoder)); 443 cur_state = !!(val & TRANSCONF_ENABLE); 444 445 intel_display_power_put(display, power_domain, wakeref); 446 } else { 447 cur_state = false; 448 } 449 450 INTEL_DISPLAY_STATE_WARN(display, cur_state != state, 451 "transcoder %s assertion failure (expected %s, current %s)\n", 452 transcoder_name(cpu_transcoder), str_on_off(state), 453 str_on_off(cur_state)); 454 } 455 456 static void assert_plane(struct intel_plane *plane, bool state) 457 { 458 struct intel_display *display = to_intel_display(plane->base.dev); 459 enum pipe pipe; 460 bool cur_state; 461 462 cur_state = plane->get_hw_state(plane, &pipe); 463 464 INTEL_DISPLAY_STATE_WARN(display, cur_state != state, 465 "%s assertion failure (expected %s, current %s)\n", 466 plane->base.name, str_on_off(state), 467 str_on_off(cur_state)); 468 } 469 470 #define assert_plane_enabled(p) assert_plane(p, true) 471 #define assert_plane_disabled(p) assert_plane(p, false) 472 473 static void assert_planes_disabled(struct intel_crtc *crtc) 474 { 475 struct intel_display *display = to_intel_display(crtc); 476 struct intel_plane *plane; 477 478 for_each_intel_plane_on_crtc(display->drm, crtc, plane) 479 assert_plane_disabled(plane); 480 } 481 482 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state) 483 { 484 struct intel_display *display = to_intel_display(new_crtc_state); 485 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 486 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; 487 enum pipe pipe = crtc->pipe; 488 u32 val; 489 490 drm_dbg_kms(display->drm, "enabling pipe %c\n", pipe_name(pipe)); 491 492 assert_planes_disabled(crtc); 493 494 /* 495 * A pipe without a PLL won't actually be able to drive bits from 496 * a plane. On ILK+ the pipe PLLs are integrated, so we don't 497 * need the check. 498 */ 499 if (HAS_GMCH(display)) { 500 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI)) 501 assert_dsi_pll_enabled(display); 502 else 503 assert_pll_enabled(display, pipe); 504 } else { 505 if (new_crtc_state->has_pch_encoder) { 506 /* if driving the PCH, we need FDI enabled */ 507 assert_fdi_rx_pll_enabled(display, 508 intel_crtc_pch_transcoder(crtc)); 509 assert_fdi_tx_pll_enabled(display, 510 (enum pipe) cpu_transcoder); 511 } 512 /* FIXME: assert CPU port conditions for SNB+ */ 513 } 514 515 /* Wa_22012358565:adl-p */ 516 if (DISPLAY_VER(display) == 13) 517 intel_de_rmw(display, PIPE_ARB_CTL(display, pipe), 518 0, PIPE_ARB_USE_PROG_SLOTS); 519 520 if (DISPLAY_VER(display) >= 14) { 521 u32 clear = DP_DSC_INSERT_SF_AT_EOL_WA; 522 u32 set = 0; 523 524 if (DISPLAY_VER(display) == 14) 525 set |= DP_FEC_BS_JITTER_WA; 526 527 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder), 528 clear, set); 529 } 530 531 val = intel_de_read(display, TRANSCONF(display, cpu_transcoder)); 532 if (val & TRANSCONF_ENABLE) { 533 /* we keep both pipes enabled on 830 */ 534 drm_WARN_ON(display->drm, !display->platform.i830); 535 return; 536 } 537 538 /* Wa_1409098942:adlp+ */ 539 if (DISPLAY_VER(display) >= 13 && 540 new_crtc_state->dsc.compression_enable) { 541 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK; 542 val |= REG_FIELD_PREP(TRANSCONF_PIXEL_COUNT_SCALING_MASK, 543 TRANSCONF_PIXEL_COUNT_SCALING_X4); 544 } 545 546 intel_de_write(display, TRANSCONF(display, cpu_transcoder), 547 val | TRANSCONF_ENABLE); 548 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder)); 549 550 /* 551 * Until the pipe starts PIPEDSL reads will return a stale value, 552 * which causes an apparent vblank timestamp jump when PIPEDSL 553 * resets to its proper value. That also messes up the frame count 554 * when it's derived from the timestamps. So let's wait for the 555 * pipe to start properly before we call drm_crtc_vblank_on() 556 */ 557 if (intel_crtc_max_vblank_count(new_crtc_state) == 0) 558 intel_wait_for_pipe_scanline_moving(crtc); 559 } 560 561 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state) 562 { 563 struct intel_display *display = to_intel_display(old_crtc_state); 564 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 565 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 566 enum pipe pipe = crtc->pipe; 567 u32 val; 568 569 drm_dbg_kms(display->drm, "disabling pipe %c\n", pipe_name(pipe)); 570 571 /* 572 * Make sure planes won't keep trying to pump pixels to us, 573 * or we might hang the display. 574 */ 575 assert_planes_disabled(crtc); 576 577 val = intel_de_read(display, TRANSCONF(display, cpu_transcoder)); 578 if ((val & TRANSCONF_ENABLE) == 0) 579 return; 580 581 /* 582 * Double wide has implications for planes 583 * so best keep it disabled when not needed. 584 */ 585 if (old_crtc_state->double_wide) 586 val &= ~TRANSCONF_DOUBLE_WIDE; 587 588 /* Don't disable pipe or pipe PLLs if needed */ 589 if (!display->platform.i830) 590 val &= ~TRANSCONF_ENABLE; 591 592 /* Wa_1409098942:adlp+ */ 593 if (DISPLAY_VER(display) >= 13 && 594 old_crtc_state->dsc.compression_enable) 595 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK; 596 597 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val); 598 599 if (DISPLAY_VER(display) >= 12) 600 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder), 601 FECSTALL_DIS_DPTSTREAM_DPTTG, 0); 602 603 if ((val & TRANSCONF_ENABLE) == 0) 604 intel_wait_for_pipe_off(old_crtc_state); 605 } 606 607 u32 intel_plane_fb_max_stride(struct drm_device *drm, 608 u32 pixel_format, u64 modifier) 609 { 610 struct intel_display *display = to_intel_display(drm); 611 struct intel_crtc *crtc; 612 struct intel_plane *plane; 613 614 if (!HAS_DISPLAY(display)) 615 return 0; 616 617 /* 618 * We assume the primary plane for pipe A has 619 * the highest stride limits of them all, 620 * if in case pipe A is disabled, use the first pipe from pipe_mask. 621 */ 622 crtc = intel_first_crtc(display); 623 if (!crtc) 624 return 0; 625 626 plane = to_intel_plane(crtc->base.primary); 627 628 return plane->max_stride(plane, pixel_format, modifier, 629 DRM_MODE_ROTATE_0); 630 } 631 632 void intel_set_plane_visible(struct intel_crtc_state *crtc_state, 633 struct intel_plane_state *plane_state, 634 bool visible) 635 { 636 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); 637 638 plane_state->uapi.visible = visible; 639 640 if (visible) 641 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base); 642 else 643 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base); 644 } 645 646 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state) 647 { 648 struct intel_display *display = to_intel_display(crtc_state); 649 struct drm_plane *plane; 650 651 /* 652 * Active_planes aliases if multiple "primary" or cursor planes 653 * have been used on the same (or wrong) pipe. plane_mask uses 654 * unique ids, hence we can use that to reconstruct active_planes. 655 */ 656 crtc_state->enabled_planes = 0; 657 crtc_state->active_planes = 0; 658 659 drm_for_each_plane_mask(plane, display->drm, 660 crtc_state->uapi.plane_mask) { 661 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id); 662 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id); 663 } 664 } 665 666 void intel_plane_disable_noatomic(struct intel_crtc *crtc, 667 struct intel_plane *plane) 668 { 669 struct intel_display *display = to_intel_display(crtc); 670 struct intel_crtc_state *crtc_state = 671 to_intel_crtc_state(crtc->base.state); 672 struct intel_plane_state *plane_state = 673 to_intel_plane_state(plane->base.state); 674 675 drm_dbg_kms(display->drm, 676 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n", 677 plane->base.base.id, plane->base.name, 678 crtc->base.base.id, crtc->base.name); 679 680 intel_plane_set_invisible(crtc_state, plane_state); 681 intel_set_plane_visible(crtc_state, plane_state, false); 682 intel_plane_fixup_bitmasks(crtc_state); 683 684 skl_wm_plane_disable_noatomic(crtc, plane); 685 686 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 && 687 hsw_ips_disable(crtc_state)) { 688 crtc_state->ips_enabled = false; 689 intel_plane_initial_vblank_wait(crtc); 690 } 691 692 /* 693 * Vblank time updates from the shadow to live plane control register 694 * are blocked if the memory self-refresh mode is active at that 695 * moment. So to make sure the plane gets truly disabled, disable 696 * first the self-refresh mode. The self-refresh enable bit in turn 697 * will be checked/applied by the HW only at the next frame start 698 * event which is after the vblank start event, so we need to have a 699 * wait-for-vblank between disabling the plane and the pipe. 700 */ 701 if (HAS_GMCH(display) && 702 intel_set_memory_cxsr(display, false)) 703 intel_plane_initial_vblank_wait(crtc); 704 705 /* 706 * Gen2 reports pipe underruns whenever all planes are disabled. 707 * So disable underrun reporting before all the planes get disabled. 708 */ 709 if (DISPLAY_VER(display) == 2 && !crtc_state->active_planes) 710 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, false); 711 712 intel_plane_disable_arm(NULL, plane, crtc_state); 713 intel_plane_initial_vblank_wait(crtc); 714 } 715 716 unsigned int 717 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state) 718 { 719 int x = 0, y = 0; 720 721 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0, 722 plane_state->view.color_plane[0].offset, 0); 723 724 return y; 725 } 726 727 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state) 728 { 729 struct intel_display *display = to_intel_display(crtc_state); 730 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 731 enum pipe pipe = crtc->pipe; 732 u32 tmp; 733 734 tmp = intel_de_read(display, PIPE_CHICKEN(pipe)); 735 736 /* 737 * Display WA #1153: icl 738 * enable hardware to bypass the alpha math 739 * and rounding for per-pixel values 00 and 0xff 740 */ 741 tmp |= PER_PIXEL_ALPHA_BYPASS_EN; 742 /* 743 * Display WA # 1605353570: icl 744 * Set the pixel rounding bit to 1 for allowing 745 * passthrough of Frame buffer pixels unmodified 746 * across pipe 747 */ 748 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU; 749 750 /* 751 * Underrun recovery must always be disabled on display 13+. 752 * DG2 chicken bit meaning is inverted compared to other platforms. 753 */ 754 if (display->platform.dg2) 755 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2; 756 else if ((DISPLAY_VER(display) >= 13) && (DISPLAY_VER(display) < 30)) 757 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP; 758 759 /* Wa_14010547955:dg2 */ 760 if (display->platform.dg2) 761 tmp |= DG2_RENDER_CCSTAG_4_3_EN; 762 763 intel_de_write(display, PIPE_CHICKEN(pipe), tmp); 764 } 765 766 bool intel_has_pending_fb_unpin(struct intel_display *display) 767 { 768 struct drm_crtc *crtc; 769 bool cleanup_done; 770 771 drm_for_each_crtc(crtc, display->drm) { 772 struct drm_crtc_commit *commit; 773 spin_lock(&crtc->commit_lock); 774 commit = list_first_entry_or_null(&crtc->commit_list, 775 struct drm_crtc_commit, commit_entry); 776 cleanup_done = commit ? 777 try_wait_for_completion(&commit->cleanup_done) : true; 778 spin_unlock(&crtc->commit_lock); 779 780 if (cleanup_done) 781 continue; 782 783 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc)); 784 785 return true; 786 } 787 788 return false; 789 } 790 791 /* 792 * Finds the encoder associated with the given CRTC. This can only be 793 * used when we know that the CRTC isn't feeding multiple encoders! 794 */ 795 struct intel_encoder * 796 intel_get_crtc_new_encoder(const struct intel_atomic_state *state, 797 const struct intel_crtc_state *crtc_state) 798 { 799 const struct drm_connector_state *connector_state; 800 const struct drm_connector *connector; 801 struct intel_encoder *encoder = NULL; 802 struct intel_crtc *primary_crtc; 803 int num_encoders = 0; 804 int i; 805 806 primary_crtc = intel_primary_crtc(crtc_state); 807 808 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 809 if (connector_state->crtc != &primary_crtc->base) 810 continue; 811 812 encoder = to_intel_encoder(connector_state->best_encoder); 813 num_encoders++; 814 } 815 816 drm_WARN(state->base.dev, num_encoders != 1, 817 "%d encoders for pipe %c\n", 818 num_encoders, pipe_name(primary_crtc->pipe)); 819 820 return encoder; 821 } 822 823 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc) 824 { 825 if (crtc->overlay) 826 (void) intel_overlay_switch_off(crtc->overlay); 827 828 /* Let userspace switch the overlay on again. In most cases userspace 829 * has to recompute where to put it anyway. 830 */ 831 } 832 833 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state) 834 { 835 struct intel_display *display = to_intel_display(crtc_state); 836 837 if (!crtc_state->nv12_planes) 838 return false; 839 840 /* WA Display #0827: Gen9:all */ 841 if (DISPLAY_VER(display) == 9) 842 return true; 843 844 return false; 845 } 846 847 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state) 848 { 849 struct intel_display *display = to_intel_display(crtc_state); 850 851 /* Wa_2006604312:icl,ehl */ 852 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(display) == 11) 853 return true; 854 855 return false; 856 } 857 858 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state) 859 { 860 struct intel_display *display = to_intel_display(crtc_state); 861 862 /* Wa_1604331009:icl,jsl,ehl */ 863 if (is_hdr_mode(crtc_state) && 864 crtc_state->active_planes & BIT(PLANE_CURSOR) && 865 DISPLAY_VER(display) == 11) 866 return true; 867 868 return false; 869 } 870 871 static void intel_async_flip_vtd_wa(struct intel_display *display, 872 enum pipe pipe, bool enable) 873 { 874 if (DISPLAY_VER(display) == 9) { 875 /* 876 * "Plane N stretch max must be programmed to 11b (x1) 877 * when Async flips are enabled on that plane." 878 */ 879 intel_de_rmw(display, CHICKEN_PIPESL_1(pipe), 880 SKL_PLANE1_STRETCH_MAX_MASK, 881 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8); 882 } else { 883 /* Also needed on HSW/BDW albeit undocumented */ 884 intel_de_rmw(display, CHICKEN_PIPESL_1(pipe), 885 HSW_PRI_STRETCH_MAX_MASK, 886 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8); 887 } 888 } 889 890 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state) 891 { 892 struct intel_display *display = to_intel_display(crtc_state); 893 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 894 895 return crtc_state->uapi.async_flip && i915_vtd_active(i915) && 896 (DISPLAY_VER(display) == 9 || display->platform.broadwell || 897 display->platform.haswell); 898 } 899 900 static void intel_encoders_audio_enable(struct intel_atomic_state *state, 901 struct intel_crtc *crtc) 902 { 903 const struct intel_crtc_state *crtc_state = 904 intel_atomic_get_new_crtc_state(state, crtc); 905 const struct drm_connector_state *conn_state; 906 struct drm_connector *conn; 907 int i; 908 909 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 910 struct intel_encoder *encoder = 911 to_intel_encoder(conn_state->best_encoder); 912 913 if (conn_state->crtc != &crtc->base) 914 continue; 915 916 if (encoder->audio_enable) 917 encoder->audio_enable(encoder, crtc_state, conn_state); 918 } 919 } 920 921 static void intel_encoders_audio_disable(struct intel_atomic_state *state, 922 struct intel_crtc *crtc) 923 { 924 const struct intel_crtc_state *old_crtc_state = 925 intel_atomic_get_old_crtc_state(state, crtc); 926 const struct drm_connector_state *old_conn_state; 927 struct drm_connector *conn; 928 int i; 929 930 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 931 struct intel_encoder *encoder = 932 to_intel_encoder(old_conn_state->best_encoder); 933 934 if (old_conn_state->crtc != &crtc->base) 935 continue; 936 937 if (encoder->audio_disable) 938 encoder->audio_disable(encoder, old_crtc_state, old_conn_state); 939 } 940 } 941 942 #define is_enabling(feature, old_crtc_state, new_crtc_state) \ 943 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \ 944 (new_crtc_state)->feature) 945 #define is_disabling(feature, old_crtc_state, new_crtc_state) \ 946 ((old_crtc_state)->feature && \ 947 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state))) 948 949 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state, 950 const struct intel_crtc_state *new_crtc_state) 951 { 952 if (!new_crtc_state->hw.active) 953 return false; 954 955 return is_enabling(active_planes, old_crtc_state, new_crtc_state); 956 } 957 958 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state, 959 const struct intel_crtc_state *new_crtc_state) 960 { 961 if (!old_crtc_state->hw.active) 962 return false; 963 964 return is_disabling(active_planes, old_crtc_state, new_crtc_state); 965 } 966 967 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state, 968 const struct intel_crtc_state *new_crtc_state) 969 { 970 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline || 971 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin || 972 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax || 973 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband || 974 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full || 975 old_crtc_state->vrr.vsync_start != new_crtc_state->vrr.vsync_start || 976 old_crtc_state->vrr.vsync_end != new_crtc_state->vrr.vsync_end; 977 } 978 979 static bool cmrr_params_changed(const struct intel_crtc_state *old_crtc_state, 980 const struct intel_crtc_state *new_crtc_state) 981 { 982 return old_crtc_state->cmrr.cmrr_m != new_crtc_state->cmrr.cmrr_m || 983 old_crtc_state->cmrr.cmrr_n != new_crtc_state->cmrr.cmrr_n; 984 } 985 986 static bool intel_crtc_vrr_enabling(struct intel_atomic_state *state, 987 struct intel_crtc *crtc) 988 { 989 const struct intel_crtc_state *old_crtc_state = 990 intel_atomic_get_old_crtc_state(state, crtc); 991 const struct intel_crtc_state *new_crtc_state = 992 intel_atomic_get_new_crtc_state(state, crtc); 993 994 if (!new_crtc_state->hw.active) 995 return false; 996 997 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) || 998 (new_crtc_state->vrr.enable && 999 (new_crtc_state->update_m_n || new_crtc_state->update_lrr || 1000 vrr_params_changed(old_crtc_state, new_crtc_state))); 1001 } 1002 1003 bool intel_crtc_vrr_disabling(struct intel_atomic_state *state, 1004 struct intel_crtc *crtc) 1005 { 1006 const struct intel_crtc_state *old_crtc_state = 1007 intel_atomic_get_old_crtc_state(state, crtc); 1008 const struct intel_crtc_state *new_crtc_state = 1009 intel_atomic_get_new_crtc_state(state, crtc); 1010 1011 if (!old_crtc_state->hw.active) 1012 return false; 1013 1014 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) || 1015 (old_crtc_state->vrr.enable && 1016 (new_crtc_state->update_m_n || new_crtc_state->update_lrr || 1017 vrr_params_changed(old_crtc_state, new_crtc_state))); 1018 } 1019 1020 static bool audio_enabling(const struct intel_crtc_state *old_crtc_state, 1021 const struct intel_crtc_state *new_crtc_state) 1022 { 1023 if (!new_crtc_state->hw.active) 1024 return false; 1025 1026 return is_enabling(has_audio, old_crtc_state, new_crtc_state) || 1027 (new_crtc_state->has_audio && 1028 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0); 1029 } 1030 1031 static bool audio_disabling(const struct intel_crtc_state *old_crtc_state, 1032 const struct intel_crtc_state *new_crtc_state) 1033 { 1034 if (!old_crtc_state->hw.active) 1035 return false; 1036 1037 return is_disabling(has_audio, old_crtc_state, new_crtc_state) || 1038 (old_crtc_state->has_audio && 1039 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0); 1040 } 1041 1042 #undef is_disabling 1043 #undef is_enabling 1044 1045 static void intel_post_plane_update(struct intel_atomic_state *state, 1046 struct intel_crtc *crtc) 1047 { 1048 struct intel_display *display = to_intel_display(state); 1049 const struct intel_crtc_state *old_crtc_state = 1050 intel_atomic_get_old_crtc_state(state, crtc); 1051 const struct intel_crtc_state *new_crtc_state = 1052 intel_atomic_get_new_crtc_state(state, crtc); 1053 enum pipe pipe = crtc->pipe; 1054 1055 intel_frontbuffer_flip(display, new_crtc_state->fb_bits); 1056 1057 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active) 1058 intel_update_watermarks(display); 1059 1060 intel_fbc_post_update(state, crtc); 1061 1062 if (needs_async_flip_vtd_wa(old_crtc_state) && 1063 !needs_async_flip_vtd_wa(new_crtc_state)) 1064 intel_async_flip_vtd_wa(display, pipe, false); 1065 1066 if (needs_nv12_wa(old_crtc_state) && 1067 !needs_nv12_wa(new_crtc_state)) 1068 skl_wa_827(display, pipe, false); 1069 1070 if (needs_scalerclk_wa(old_crtc_state) && 1071 !needs_scalerclk_wa(new_crtc_state)) 1072 icl_wa_scalerclkgating(display, pipe, false); 1073 1074 if (needs_cursorclk_wa(old_crtc_state) && 1075 !needs_cursorclk_wa(new_crtc_state)) 1076 icl_wa_cursorclkgating(display, pipe, false); 1077 1078 if (intel_crtc_needs_color_update(new_crtc_state)) 1079 intel_color_post_update(new_crtc_state); 1080 1081 if (audio_enabling(old_crtc_state, new_crtc_state)) 1082 intel_encoders_audio_enable(state, crtc); 1083 1084 intel_alpm_post_plane_update(state, crtc); 1085 1086 intel_psr_post_plane_update(state, crtc); 1087 } 1088 1089 static void intel_post_plane_update_after_readout(struct intel_atomic_state *state, 1090 struct intel_crtc *crtc) 1091 { 1092 const struct intel_crtc_state *new_crtc_state = 1093 intel_atomic_get_new_crtc_state(state, crtc); 1094 1095 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */ 1096 hsw_ips_post_update(state, crtc); 1097 1098 /* 1099 * Activate DRRS after state readout to avoid 1100 * dp_m_n vs. dp_m2_n2 confusion on BDW+. 1101 */ 1102 intel_drrs_activate(new_crtc_state); 1103 } 1104 1105 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state, 1106 struct intel_crtc *crtc) 1107 { 1108 const struct intel_crtc_state *crtc_state = 1109 intel_atomic_get_new_crtc_state(state, crtc); 1110 u8 update_planes = crtc_state->update_planes; 1111 const struct intel_plane_state __maybe_unused *plane_state; 1112 struct intel_plane *plane; 1113 int i; 1114 1115 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 1116 if (plane->pipe == crtc->pipe && 1117 update_planes & BIT(plane->id)) 1118 plane->enable_flip_done(plane); 1119 } 1120 } 1121 1122 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state, 1123 struct intel_crtc *crtc) 1124 { 1125 const struct intel_crtc_state *crtc_state = 1126 intel_atomic_get_new_crtc_state(state, crtc); 1127 u8 update_planes = crtc_state->update_planes; 1128 const struct intel_plane_state __maybe_unused *plane_state; 1129 struct intel_plane *plane; 1130 int i; 1131 1132 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 1133 if (plane->pipe == crtc->pipe && 1134 update_planes & BIT(plane->id)) 1135 plane->disable_flip_done(plane); 1136 } 1137 } 1138 1139 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state, 1140 struct intel_crtc *crtc) 1141 { 1142 const struct intel_crtc_state *old_crtc_state = 1143 intel_atomic_get_old_crtc_state(state, crtc); 1144 const struct intel_crtc_state *new_crtc_state = 1145 intel_atomic_get_new_crtc_state(state, crtc); 1146 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes & 1147 ~new_crtc_state->async_flip_planes; 1148 const struct intel_plane_state *old_plane_state; 1149 struct intel_plane *plane; 1150 bool need_vbl_wait = false; 1151 int i; 1152 1153 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { 1154 if (plane->need_async_flip_toggle_wa && 1155 plane->pipe == crtc->pipe && 1156 disable_async_flip_planes & BIT(plane->id)) { 1157 /* 1158 * Apart from the async flip bit we want to 1159 * preserve the old state for the plane. 1160 */ 1161 intel_plane_async_flip(NULL, plane, 1162 old_crtc_state, old_plane_state, false); 1163 need_vbl_wait = true; 1164 } 1165 } 1166 1167 if (need_vbl_wait) 1168 intel_crtc_wait_for_next_vblank(crtc); 1169 } 1170 1171 static void intel_pre_plane_update(struct intel_atomic_state *state, 1172 struct intel_crtc *crtc) 1173 { 1174 struct intel_display *display = to_intel_display(state); 1175 const struct intel_crtc_state *old_crtc_state = 1176 intel_atomic_get_old_crtc_state(state, crtc); 1177 const struct intel_crtc_state *new_crtc_state = 1178 intel_atomic_get_new_crtc_state(state, crtc); 1179 enum pipe pipe = crtc->pipe; 1180 1181 intel_alpm_pre_plane_update(state, crtc); 1182 intel_psr_pre_plane_update(state, crtc); 1183 1184 if (intel_crtc_vrr_disabling(state, crtc)) { 1185 intel_vrr_disable(old_crtc_state); 1186 intel_crtc_update_active_timings(old_crtc_state, false); 1187 } 1188 1189 if (audio_disabling(old_crtc_state, new_crtc_state)) 1190 intel_encoders_audio_disable(state, crtc); 1191 1192 intel_drrs_deactivate(old_crtc_state); 1193 1194 if (hsw_ips_pre_update(state, crtc)) 1195 intel_crtc_wait_for_next_vblank(crtc); 1196 1197 if (intel_fbc_pre_update(state, crtc)) 1198 intel_crtc_wait_for_next_vblank(crtc); 1199 1200 if (!needs_async_flip_vtd_wa(old_crtc_state) && 1201 needs_async_flip_vtd_wa(new_crtc_state)) 1202 intel_async_flip_vtd_wa(display, pipe, true); 1203 1204 /* Display WA 827 */ 1205 if (!needs_nv12_wa(old_crtc_state) && 1206 needs_nv12_wa(new_crtc_state)) 1207 skl_wa_827(display, pipe, true); 1208 1209 /* Wa_2006604312:icl,ehl */ 1210 if (!needs_scalerclk_wa(old_crtc_state) && 1211 needs_scalerclk_wa(new_crtc_state)) 1212 icl_wa_scalerclkgating(display, pipe, true); 1213 1214 /* Wa_1604331009:icl,jsl,ehl */ 1215 if (!needs_cursorclk_wa(old_crtc_state) && 1216 needs_cursorclk_wa(new_crtc_state)) 1217 icl_wa_cursorclkgating(display, pipe, true); 1218 1219 /* 1220 * Vblank time updates from the shadow to live plane control register 1221 * are blocked if the memory self-refresh mode is active at that 1222 * moment. So to make sure the plane gets truly disabled, disable 1223 * first the self-refresh mode. The self-refresh enable bit in turn 1224 * will be checked/applied by the HW only at the next frame start 1225 * event which is after the vblank start event, so we need to have a 1226 * wait-for-vblank between disabling the plane and the pipe. 1227 */ 1228 if (HAS_GMCH(display) && old_crtc_state->hw.active && 1229 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(display, false)) 1230 intel_crtc_wait_for_next_vblank(crtc); 1231 1232 /* 1233 * IVB workaround: must disable low power watermarks for at least 1234 * one frame before enabling scaling. LP watermarks can be re-enabled 1235 * when scaling is disabled. 1236 * 1237 * WaCxSRDisabledForSpriteScaling:ivb 1238 */ 1239 if (!HAS_GMCH(display) && old_crtc_state->hw.active && 1240 new_crtc_state->disable_cxsr && ilk_disable_cxsr(display)) 1241 intel_crtc_wait_for_next_vblank(crtc); 1242 1243 /* 1244 * If we're doing a modeset we don't need to do any 1245 * pre-vblank watermark programming here. 1246 */ 1247 if (!intel_crtc_needs_modeset(new_crtc_state)) { 1248 /* 1249 * For platforms that support atomic watermarks, program the 1250 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these 1251 * will be the intermediate values that are safe for both pre- and 1252 * post- vblank; when vblank happens, the 'active' values will be set 1253 * to the final 'target' values and we'll do this again to get the 1254 * optimal watermarks. For gen9+ platforms, the values we program here 1255 * will be the final target values which will get automatically latched 1256 * at vblank time; no further programming will be necessary. 1257 * 1258 * If a platform hasn't been transitioned to atomic watermarks yet, 1259 * we'll continue to update watermarks the old way, if flags tell 1260 * us to. 1261 */ 1262 if (!intel_initial_watermarks(state, crtc)) 1263 if (new_crtc_state->update_wm_pre) 1264 intel_update_watermarks(display); 1265 } 1266 1267 /* 1268 * Gen2 reports pipe underruns whenever all planes are disabled. 1269 * So disable underrun reporting before all the planes get disabled. 1270 * 1271 * We do this after .initial_watermarks() so that we have a 1272 * chance of catching underruns with the intermediate watermarks 1273 * vs. the old plane configuration. 1274 */ 1275 if (DISPLAY_VER(display) == 2 && planes_disabling(old_crtc_state, new_crtc_state)) 1276 intel_set_cpu_fifo_underrun_reporting(display, pipe, false); 1277 1278 /* 1279 * WA for platforms where async address update enable bit 1280 * is double buffered and only latched at start of vblank. 1281 */ 1282 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes) 1283 intel_crtc_async_flip_disable_wa(state, crtc); 1284 } 1285 1286 static void intel_crtc_disable_planes(struct intel_atomic_state *state, 1287 struct intel_crtc *crtc) 1288 { 1289 struct intel_display *display = to_intel_display(state); 1290 const struct intel_crtc_state *new_crtc_state = 1291 intel_atomic_get_new_crtc_state(state, crtc); 1292 unsigned int update_mask = new_crtc_state->update_planes; 1293 const struct intel_plane_state *old_plane_state; 1294 struct intel_plane *plane; 1295 unsigned fb_bits = 0; 1296 int i; 1297 1298 intel_crtc_dpms_overlay_disable(crtc); 1299 1300 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) { 1301 if (crtc->pipe != plane->pipe || 1302 !(update_mask & BIT(plane->id))) 1303 continue; 1304 1305 intel_plane_disable_arm(NULL, plane, new_crtc_state); 1306 1307 if (old_plane_state->uapi.visible) 1308 fb_bits |= plane->frontbuffer_bit; 1309 } 1310 1311 intel_frontbuffer_flip(display, fb_bits); 1312 } 1313 1314 static void intel_encoders_update_prepare(struct intel_atomic_state *state) 1315 { 1316 struct intel_display *display = to_intel_display(state); 1317 struct intel_crtc_state *new_crtc_state, *old_crtc_state; 1318 struct intel_crtc *crtc; 1319 int i; 1320 1321 /* 1322 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits. 1323 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook. 1324 */ 1325 if (display->dpll.mgr) { 1326 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 1327 if (intel_crtc_needs_modeset(new_crtc_state)) 1328 continue; 1329 1330 new_crtc_state->intel_dpll = old_crtc_state->intel_dpll; 1331 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state; 1332 } 1333 } 1334 } 1335 1336 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state, 1337 struct intel_crtc *crtc) 1338 { 1339 const struct intel_crtc_state *crtc_state = 1340 intel_atomic_get_new_crtc_state(state, crtc); 1341 const struct drm_connector_state *conn_state; 1342 struct drm_connector *conn; 1343 int i; 1344 1345 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1346 struct intel_encoder *encoder = 1347 to_intel_encoder(conn_state->best_encoder); 1348 1349 if (conn_state->crtc != &crtc->base) 1350 continue; 1351 1352 if (encoder->pre_pll_enable) 1353 encoder->pre_pll_enable(state, encoder, 1354 crtc_state, conn_state); 1355 } 1356 } 1357 1358 static void intel_encoders_pre_enable(struct intel_atomic_state *state, 1359 struct intel_crtc *crtc) 1360 { 1361 const struct intel_crtc_state *crtc_state = 1362 intel_atomic_get_new_crtc_state(state, crtc); 1363 const struct drm_connector_state *conn_state; 1364 struct drm_connector *conn; 1365 int i; 1366 1367 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1368 struct intel_encoder *encoder = 1369 to_intel_encoder(conn_state->best_encoder); 1370 1371 if (conn_state->crtc != &crtc->base) 1372 continue; 1373 1374 if (encoder->pre_enable) 1375 encoder->pre_enable(state, encoder, 1376 crtc_state, conn_state); 1377 } 1378 } 1379 1380 static void intel_encoders_enable(struct intel_atomic_state *state, 1381 struct intel_crtc *crtc) 1382 { 1383 const struct intel_crtc_state *crtc_state = 1384 intel_atomic_get_new_crtc_state(state, crtc); 1385 const struct drm_connector_state *conn_state; 1386 struct drm_connector *conn; 1387 int i; 1388 1389 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1390 struct intel_encoder *encoder = 1391 to_intel_encoder(conn_state->best_encoder); 1392 1393 if (conn_state->crtc != &crtc->base) 1394 continue; 1395 1396 if (encoder->enable) 1397 encoder->enable(state, encoder, 1398 crtc_state, conn_state); 1399 intel_opregion_notify_encoder(encoder, true); 1400 } 1401 } 1402 1403 static void intel_encoders_disable(struct intel_atomic_state *state, 1404 struct intel_crtc *crtc) 1405 { 1406 const struct intel_crtc_state *old_crtc_state = 1407 intel_atomic_get_old_crtc_state(state, crtc); 1408 const struct drm_connector_state *old_conn_state; 1409 struct drm_connector *conn; 1410 int i; 1411 1412 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1413 struct intel_encoder *encoder = 1414 to_intel_encoder(old_conn_state->best_encoder); 1415 1416 if (old_conn_state->crtc != &crtc->base) 1417 continue; 1418 1419 intel_opregion_notify_encoder(encoder, false); 1420 if (encoder->disable) 1421 encoder->disable(state, encoder, 1422 old_crtc_state, old_conn_state); 1423 } 1424 } 1425 1426 static void intel_encoders_post_disable(struct intel_atomic_state *state, 1427 struct intel_crtc *crtc) 1428 { 1429 const struct intel_crtc_state *old_crtc_state = 1430 intel_atomic_get_old_crtc_state(state, crtc); 1431 const struct drm_connector_state *old_conn_state; 1432 struct drm_connector *conn; 1433 int i; 1434 1435 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1436 struct intel_encoder *encoder = 1437 to_intel_encoder(old_conn_state->best_encoder); 1438 1439 if (old_conn_state->crtc != &crtc->base) 1440 continue; 1441 1442 if (encoder->post_disable) 1443 encoder->post_disable(state, encoder, 1444 old_crtc_state, old_conn_state); 1445 } 1446 } 1447 1448 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state, 1449 struct intel_crtc *crtc) 1450 { 1451 const struct intel_crtc_state *old_crtc_state = 1452 intel_atomic_get_old_crtc_state(state, crtc); 1453 const struct drm_connector_state *old_conn_state; 1454 struct drm_connector *conn; 1455 int i; 1456 1457 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) { 1458 struct intel_encoder *encoder = 1459 to_intel_encoder(old_conn_state->best_encoder); 1460 1461 if (old_conn_state->crtc != &crtc->base) 1462 continue; 1463 1464 if (encoder->post_pll_disable) 1465 encoder->post_pll_disable(state, encoder, 1466 old_crtc_state, old_conn_state); 1467 } 1468 } 1469 1470 static void intel_encoders_update_pipe(struct intel_atomic_state *state, 1471 struct intel_crtc *crtc) 1472 { 1473 const struct intel_crtc_state *crtc_state = 1474 intel_atomic_get_new_crtc_state(state, crtc); 1475 const struct drm_connector_state *conn_state; 1476 struct drm_connector *conn; 1477 int i; 1478 1479 for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 1480 struct intel_encoder *encoder = 1481 to_intel_encoder(conn_state->best_encoder); 1482 1483 if (conn_state->crtc != &crtc->base) 1484 continue; 1485 1486 if (encoder->update_pipe) 1487 encoder->update_pipe(state, encoder, 1488 crtc_state, conn_state); 1489 } 1490 } 1491 1492 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 1493 { 1494 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1495 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1496 1497 if (crtc_state->has_pch_encoder) { 1498 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1499 &crtc_state->fdi_m_n); 1500 } else if (intel_crtc_has_dp_encoder(crtc_state)) { 1501 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1502 &crtc_state->dp_m_n); 1503 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 1504 &crtc_state->dp_m2_n2); 1505 } 1506 1507 intel_set_transcoder_timings(crtc_state); 1508 1509 ilk_set_pipeconf(crtc_state); 1510 } 1511 1512 static void ilk_crtc_enable(struct intel_atomic_state *state, 1513 struct intel_crtc *crtc) 1514 { 1515 struct intel_display *display = to_intel_display(crtc); 1516 const struct intel_crtc_state *new_crtc_state = 1517 intel_atomic_get_new_crtc_state(state, crtc); 1518 enum pipe pipe = crtc->pipe; 1519 1520 if (drm_WARN_ON(display->drm, crtc->active)) 1521 return; 1522 1523 /* 1524 * Sometimes spurious CPU pipe underruns happen during FDI 1525 * training, at least with VGA+HDMI cloning. Suppress them. 1526 * 1527 * On ILK we get an occasional spurious CPU pipe underruns 1528 * between eDP port A enable and vdd enable. Also PCH port 1529 * enable seems to result in the occasional CPU pipe underrun. 1530 * 1531 * Spurious PCH underruns also occur during PCH enabling. 1532 */ 1533 intel_set_cpu_fifo_underrun_reporting(display, pipe, false); 1534 intel_set_pch_fifo_underrun_reporting(display, pipe, false); 1535 1536 ilk_configure_cpu_transcoder(new_crtc_state); 1537 1538 intel_set_pipe_src_size(new_crtc_state); 1539 1540 crtc->active = true; 1541 1542 intel_encoders_pre_enable(state, crtc); 1543 1544 if (new_crtc_state->has_pch_encoder) { 1545 ilk_pch_pre_enable(state, crtc); 1546 } else { 1547 assert_fdi_tx_disabled(display, pipe); 1548 assert_fdi_rx_disabled(display, pipe); 1549 } 1550 1551 ilk_pfit_enable(new_crtc_state); 1552 1553 /* 1554 * On ILK+ LUT must be loaded before the pipe is running but with 1555 * clocks enabled 1556 */ 1557 intel_color_modeset(new_crtc_state); 1558 1559 intel_initial_watermarks(state, crtc); 1560 intel_enable_transcoder(new_crtc_state); 1561 1562 if (new_crtc_state->has_pch_encoder) 1563 ilk_pch_enable(state, crtc); 1564 1565 intel_crtc_vblank_on(new_crtc_state); 1566 1567 intel_encoders_enable(state, crtc); 1568 1569 if (HAS_PCH_CPT(display)) 1570 intel_wait_for_pipe_scanline_moving(crtc); 1571 1572 /* 1573 * Must wait for vblank to avoid spurious PCH FIFO underruns. 1574 * And a second vblank wait is needed at least on ILK with 1575 * some interlaced HDMI modes. Let's do the double wait always 1576 * in case there are more corner cases we don't know about. 1577 */ 1578 if (new_crtc_state->has_pch_encoder) { 1579 intel_crtc_wait_for_next_vblank(crtc); 1580 intel_crtc_wait_for_next_vblank(crtc); 1581 } 1582 intel_set_cpu_fifo_underrun_reporting(display, pipe, true); 1583 intel_set_pch_fifo_underrun_reporting(display, pipe, true); 1584 } 1585 1586 /* Display WA #1180: WaDisableScalarClockGating: glk */ 1587 static bool glk_need_scaler_clock_gating_wa(const struct intel_crtc_state *crtc_state) 1588 { 1589 struct intel_display *display = to_intel_display(crtc_state); 1590 1591 return DISPLAY_VER(display) == 10 && crtc_state->pch_pfit.enabled; 1592 } 1593 1594 static void glk_pipe_scaler_clock_gating_wa(struct intel_crtc *crtc, bool enable) 1595 { 1596 struct intel_display *display = to_intel_display(crtc); 1597 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS; 1598 1599 intel_de_rmw(display, CLKGATE_DIS_PSL(crtc->pipe), 1600 mask, enable ? mask : 0); 1601 } 1602 1603 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state) 1604 { 1605 struct intel_display *display = to_intel_display(crtc_state); 1606 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1607 1608 intel_de_write(display, WM_LINETIME(crtc->pipe), 1609 HSW_LINETIME(crtc_state->linetime) | 1610 HSW_IPS_LINETIME(crtc_state->ips_linetime)); 1611 } 1612 1613 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state) 1614 { 1615 struct intel_display *display = to_intel_display(crtc_state); 1616 1617 intel_de_rmw(display, CHICKEN_TRANS(display, crtc_state->cpu_transcoder), 1618 HSW_FRAME_START_DELAY_MASK, 1619 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1)); 1620 } 1621 1622 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 1623 { 1624 struct intel_display *display = to_intel_display(crtc_state); 1625 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1626 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1627 1628 if (crtc_state->has_pch_encoder) { 1629 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1630 &crtc_state->fdi_m_n); 1631 } else if (intel_crtc_has_dp_encoder(crtc_state)) { 1632 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 1633 &crtc_state->dp_m_n); 1634 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 1635 &crtc_state->dp_m2_n2); 1636 } 1637 1638 intel_set_transcoder_timings(crtc_state); 1639 if (HAS_VRR(display)) 1640 intel_vrr_set_transcoder_timings(crtc_state); 1641 1642 if (cpu_transcoder != TRANSCODER_EDP) 1643 intel_de_write(display, TRANS_MULT(display, cpu_transcoder), 1644 crtc_state->pixel_multiplier - 1); 1645 1646 hsw_set_frame_start_delay(crtc_state); 1647 1648 hsw_set_transconf(crtc_state); 1649 } 1650 1651 static void hsw_crtc_enable(struct intel_atomic_state *state, 1652 struct intel_crtc *crtc) 1653 { 1654 struct intel_display *display = to_intel_display(state); 1655 const struct intel_crtc_state *new_crtc_state = 1656 intel_atomic_get_new_crtc_state(state, crtc); 1657 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder; 1658 struct intel_crtc *pipe_crtc; 1659 int i; 1660 1661 if (drm_WARN_ON(display->drm, crtc->active)) 1662 return; 1663 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) { 1664 const struct intel_crtc_state *new_pipe_crtc_state = 1665 intel_atomic_get_new_crtc_state(state, pipe_crtc); 1666 1667 intel_dmc_enable_pipe(new_pipe_crtc_state); 1668 } 1669 1670 intel_encoders_pre_pll_enable(state, crtc); 1671 1672 if (new_crtc_state->intel_dpll) 1673 intel_dpll_enable(new_crtc_state); 1674 1675 intel_encoders_pre_enable(state, crtc); 1676 1677 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) { 1678 const struct intel_crtc_state *pipe_crtc_state = 1679 intel_atomic_get_new_crtc_state(state, pipe_crtc); 1680 1681 intel_dsc_enable(pipe_crtc_state); 1682 1683 if (HAS_UNCOMPRESSED_JOINER(display)) 1684 intel_uncompressed_joiner_enable(pipe_crtc_state); 1685 1686 intel_set_pipe_src_size(pipe_crtc_state); 1687 1688 if (DISPLAY_VER(display) >= 9 || display->platform.broadwell) 1689 bdw_set_pipe_misc(NULL, pipe_crtc_state); 1690 } 1691 1692 if (!transcoder_is_dsi(cpu_transcoder)) 1693 hsw_configure_cpu_transcoder(new_crtc_state); 1694 1695 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) { 1696 const struct intel_crtc_state *pipe_crtc_state = 1697 intel_atomic_get_new_crtc_state(state, pipe_crtc); 1698 1699 pipe_crtc->active = true; 1700 1701 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state)) 1702 glk_pipe_scaler_clock_gating_wa(pipe_crtc, true); 1703 1704 if (DISPLAY_VER(display) >= 9) 1705 skl_pfit_enable(pipe_crtc_state); 1706 else 1707 ilk_pfit_enable(pipe_crtc_state); 1708 1709 /* 1710 * On ILK+ LUT must be loaded before the pipe is running but with 1711 * clocks enabled 1712 */ 1713 intel_color_modeset(pipe_crtc_state); 1714 1715 hsw_set_linetime_wm(pipe_crtc_state); 1716 1717 if (DISPLAY_VER(display) >= 11) 1718 icl_set_pipe_chicken(pipe_crtc_state); 1719 1720 intel_initial_watermarks(state, pipe_crtc); 1721 } 1722 1723 intel_encoders_enable(state, crtc); 1724 1725 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) { 1726 const struct intel_crtc_state *pipe_crtc_state = 1727 intel_atomic_get_new_crtc_state(state, pipe_crtc); 1728 enum pipe hsw_workaround_pipe; 1729 1730 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state)) { 1731 intel_crtc_wait_for_next_vblank(pipe_crtc); 1732 glk_pipe_scaler_clock_gating_wa(pipe_crtc, false); 1733 } 1734 1735 /* 1736 * If we change the relative order between pipe/planes 1737 * enabling, we need to change the workaround. 1738 */ 1739 hsw_workaround_pipe = pipe_crtc_state->hsw_workaround_pipe; 1740 if (display->platform.haswell && hsw_workaround_pipe != INVALID_PIPE) { 1741 struct intel_crtc *wa_crtc = 1742 intel_crtc_for_pipe(display, hsw_workaround_pipe); 1743 1744 intel_crtc_wait_for_next_vblank(wa_crtc); 1745 intel_crtc_wait_for_next_vblank(wa_crtc); 1746 } 1747 } 1748 } 1749 1750 static void ilk_crtc_disable(struct intel_atomic_state *state, 1751 struct intel_crtc *crtc) 1752 { 1753 struct intel_display *display = to_intel_display(crtc); 1754 const struct intel_crtc_state *old_crtc_state = 1755 intel_atomic_get_old_crtc_state(state, crtc); 1756 enum pipe pipe = crtc->pipe; 1757 1758 /* 1759 * Sometimes spurious CPU pipe underruns happen when the 1760 * pipe is already disabled, but FDI RX/TX is still enabled. 1761 * Happens at least with VGA+HDMI cloning. Suppress them. 1762 */ 1763 intel_set_cpu_fifo_underrun_reporting(display, pipe, false); 1764 intel_set_pch_fifo_underrun_reporting(display, pipe, false); 1765 1766 intel_encoders_disable(state, crtc); 1767 1768 intel_crtc_vblank_off(old_crtc_state); 1769 1770 intel_disable_transcoder(old_crtc_state); 1771 1772 ilk_pfit_disable(old_crtc_state); 1773 1774 if (old_crtc_state->has_pch_encoder) 1775 ilk_pch_disable(state, crtc); 1776 1777 intel_encoders_post_disable(state, crtc); 1778 1779 if (old_crtc_state->has_pch_encoder) 1780 ilk_pch_post_disable(state, crtc); 1781 1782 intel_set_cpu_fifo_underrun_reporting(display, pipe, true); 1783 intel_set_pch_fifo_underrun_reporting(display, pipe, true); 1784 } 1785 1786 static void hsw_crtc_disable(struct intel_atomic_state *state, 1787 struct intel_crtc *crtc) 1788 { 1789 struct intel_display *display = to_intel_display(state); 1790 const struct intel_crtc_state *old_crtc_state = 1791 intel_atomic_get_old_crtc_state(state, crtc); 1792 struct intel_crtc *pipe_crtc; 1793 int i; 1794 1795 /* 1796 * FIXME collapse everything to one hook. 1797 * Need care with mst->ddi interactions. 1798 */ 1799 intel_encoders_disable(state, crtc); 1800 intel_encoders_post_disable(state, crtc); 1801 1802 intel_dpll_disable(old_crtc_state); 1803 1804 intel_encoders_post_pll_disable(state, crtc); 1805 1806 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i) { 1807 const struct intel_crtc_state *old_pipe_crtc_state = 1808 intel_atomic_get_old_crtc_state(state, pipe_crtc); 1809 1810 intel_dmc_disable_pipe(old_pipe_crtc_state); 1811 } 1812 } 1813 1814 /* Prefer intel_encoder_is_combo() */ 1815 bool intel_phy_is_combo(struct intel_display *display, enum phy phy) 1816 { 1817 if (phy == PHY_NONE) 1818 return false; 1819 else if (display->platform.alderlake_s) 1820 return phy <= PHY_E; 1821 else if (display->platform.dg1 || display->platform.rocketlake) 1822 return phy <= PHY_D; 1823 else if (display->platform.jasperlake || display->platform.elkhartlake) 1824 return phy <= PHY_C; 1825 else if (display->platform.alderlake_p || IS_DISPLAY_VER(display, 11, 12)) 1826 return phy <= PHY_B; 1827 else 1828 /* 1829 * DG2 outputs labelled as "combo PHY" in the bspec use 1830 * SNPS PHYs with completely different programming, 1831 * hence we always return false here. 1832 */ 1833 return false; 1834 } 1835 1836 /* Prefer intel_encoder_is_tc() */ 1837 bool intel_phy_is_tc(struct intel_display *display, enum phy phy) 1838 { 1839 /* 1840 * Discrete GPU phy's are not attached to FIA's to support TC 1841 * subsystem Legacy or non-legacy, and only support native DP/HDMI 1842 */ 1843 if (display->platform.dgfx) 1844 return false; 1845 1846 if (DISPLAY_VER(display) >= 13) 1847 return phy >= PHY_F && phy <= PHY_I; 1848 else if (display->platform.tigerlake) 1849 return phy >= PHY_D && phy <= PHY_I; 1850 else if (display->platform.icelake) 1851 return phy >= PHY_C && phy <= PHY_F; 1852 1853 return false; 1854 } 1855 1856 /* Prefer intel_encoder_is_snps() */ 1857 bool intel_phy_is_snps(struct intel_display *display, enum phy phy) 1858 { 1859 /* 1860 * For DG2, and for DG2 only, all four "combo" ports and the TC1 port 1861 * (PHY E) use Synopsis PHYs. See intel_phy_is_tc(). 1862 */ 1863 return display->platform.dg2 && phy > PHY_NONE && phy <= PHY_E; 1864 } 1865 1866 /* Prefer intel_encoder_to_phy() */ 1867 enum phy intel_port_to_phy(struct intel_display *display, enum port port) 1868 { 1869 if (DISPLAY_VER(display) >= 13 && port >= PORT_D_XELPD) 1870 return PHY_D + port - PORT_D_XELPD; 1871 else if (DISPLAY_VER(display) >= 13 && port >= PORT_TC1) 1872 return PHY_F + port - PORT_TC1; 1873 else if (display->platform.alderlake_s && port >= PORT_TC1) 1874 return PHY_B + port - PORT_TC1; 1875 else if ((display->platform.dg1 || display->platform.rocketlake) && port >= PORT_TC1) 1876 return PHY_C + port - PORT_TC1; 1877 else if ((display->platform.jasperlake || display->platform.elkhartlake) && 1878 port == PORT_D) 1879 return PHY_A; 1880 1881 return PHY_A + port - PORT_A; 1882 } 1883 1884 /* Prefer intel_encoder_to_tc() */ 1885 enum tc_port intel_port_to_tc(struct intel_display *display, enum port port) 1886 { 1887 if (!intel_phy_is_tc(display, intel_port_to_phy(display, port))) 1888 return TC_PORT_NONE; 1889 1890 if (DISPLAY_VER(display) >= 12) 1891 return TC_PORT_1 + port - PORT_TC1; 1892 else 1893 return TC_PORT_1 + port - PORT_C; 1894 } 1895 1896 enum phy intel_encoder_to_phy(struct intel_encoder *encoder) 1897 { 1898 struct intel_display *display = to_intel_display(encoder); 1899 1900 return intel_port_to_phy(display, encoder->port); 1901 } 1902 1903 bool intel_encoder_is_combo(struct intel_encoder *encoder) 1904 { 1905 struct intel_display *display = to_intel_display(encoder); 1906 1907 return intel_phy_is_combo(display, intel_encoder_to_phy(encoder)); 1908 } 1909 1910 bool intel_encoder_is_snps(struct intel_encoder *encoder) 1911 { 1912 struct intel_display *display = to_intel_display(encoder); 1913 1914 return intel_phy_is_snps(display, intel_encoder_to_phy(encoder)); 1915 } 1916 1917 bool intel_encoder_is_tc(struct intel_encoder *encoder) 1918 { 1919 struct intel_display *display = to_intel_display(encoder); 1920 1921 return intel_phy_is_tc(display, intel_encoder_to_phy(encoder)); 1922 } 1923 1924 enum tc_port intel_encoder_to_tc(struct intel_encoder *encoder) 1925 { 1926 struct intel_display *display = to_intel_display(encoder); 1927 1928 return intel_port_to_tc(display, encoder->port); 1929 } 1930 1931 enum intel_display_power_domain 1932 intel_aux_power_domain(struct intel_digital_port *dig_port) 1933 { 1934 struct intel_display *display = to_intel_display(dig_port); 1935 1936 if (intel_tc_port_in_tbt_alt_mode(dig_port)) 1937 return intel_display_power_tbt_aux_domain(display, dig_port->aux_ch); 1938 1939 return intel_display_power_legacy_aux_domain(display, dig_port->aux_ch); 1940 } 1941 1942 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state, 1943 struct intel_power_domain_mask *mask) 1944 { 1945 struct intel_display *display = to_intel_display(crtc_state); 1946 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1947 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1948 struct drm_encoder *encoder; 1949 enum pipe pipe = crtc->pipe; 1950 1951 bitmap_zero(mask->bits, POWER_DOMAIN_NUM); 1952 1953 if (!crtc_state->hw.active) 1954 return; 1955 1956 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits); 1957 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits); 1958 if (crtc_state->pch_pfit.enabled || 1959 crtc_state->pch_pfit.force_thru) 1960 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits); 1961 1962 drm_for_each_encoder_mask(encoder, display->drm, 1963 crtc_state->uapi.encoder_mask) { 1964 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 1965 1966 set_bit(intel_encoder->power_domain, mask->bits); 1967 } 1968 1969 if (HAS_DDI(display) && crtc_state->has_audio) 1970 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits); 1971 1972 if (crtc_state->intel_dpll) 1973 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits); 1974 1975 if (crtc_state->dsc.compression_enable) 1976 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits); 1977 } 1978 1979 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state, 1980 struct intel_power_domain_mask *old_domains) 1981 { 1982 struct intel_display *display = to_intel_display(crtc_state); 1983 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1984 enum intel_display_power_domain domain; 1985 struct intel_power_domain_mask domains, new_domains; 1986 1987 get_crtc_power_domains(crtc_state, &domains); 1988 1989 bitmap_andnot(new_domains.bits, 1990 domains.bits, 1991 crtc->enabled_power_domains.mask.bits, 1992 POWER_DOMAIN_NUM); 1993 bitmap_andnot(old_domains->bits, 1994 crtc->enabled_power_domains.mask.bits, 1995 domains.bits, 1996 POWER_DOMAIN_NUM); 1997 1998 for_each_power_domain(domain, &new_domains) 1999 intel_display_power_get_in_set(display, 2000 &crtc->enabled_power_domains, 2001 domain); 2002 } 2003 2004 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc, 2005 struct intel_power_domain_mask *domains) 2006 { 2007 struct intel_display *display = to_intel_display(crtc); 2008 2009 intel_display_power_put_mask_in_set(display, 2010 &crtc->enabled_power_domains, 2011 domains); 2012 } 2013 2014 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state) 2015 { 2016 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2017 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2018 2019 if (intel_crtc_has_dp_encoder(crtc_state)) { 2020 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder, 2021 &crtc_state->dp_m_n); 2022 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder, 2023 &crtc_state->dp_m2_n2); 2024 } 2025 2026 intel_set_transcoder_timings(crtc_state); 2027 2028 i9xx_set_pipeconf(crtc_state); 2029 } 2030 2031 static void valleyview_crtc_enable(struct intel_atomic_state *state, 2032 struct intel_crtc *crtc) 2033 { 2034 struct intel_display *display = to_intel_display(crtc); 2035 const struct intel_crtc_state *new_crtc_state = 2036 intel_atomic_get_new_crtc_state(state, crtc); 2037 enum pipe pipe = crtc->pipe; 2038 2039 if (drm_WARN_ON(display->drm, crtc->active)) 2040 return; 2041 2042 i9xx_configure_cpu_transcoder(new_crtc_state); 2043 2044 intel_set_pipe_src_size(new_crtc_state); 2045 2046 intel_de_write(display, VLV_PIPE_MSA_MISC(display, pipe), 0); 2047 2048 if (display->platform.cherryview && pipe == PIPE_B) { 2049 intel_de_write(display, CHV_BLEND(display, pipe), 2050 CHV_BLEND_LEGACY); 2051 intel_de_write(display, CHV_CANVAS(display, pipe), 0); 2052 } 2053 2054 crtc->active = true; 2055 2056 intel_set_cpu_fifo_underrun_reporting(display, pipe, true); 2057 2058 intel_encoders_pre_pll_enable(state, crtc); 2059 2060 if (display->platform.cherryview) 2061 chv_enable_pll(new_crtc_state); 2062 else 2063 vlv_enable_pll(new_crtc_state); 2064 2065 intel_encoders_pre_enable(state, crtc); 2066 2067 i9xx_pfit_enable(new_crtc_state); 2068 2069 intel_color_modeset(new_crtc_state); 2070 2071 intel_initial_watermarks(state, crtc); 2072 intel_enable_transcoder(new_crtc_state); 2073 2074 intel_crtc_vblank_on(new_crtc_state); 2075 2076 intel_encoders_enable(state, crtc); 2077 } 2078 2079 static void i9xx_crtc_enable(struct intel_atomic_state *state, 2080 struct intel_crtc *crtc) 2081 { 2082 struct intel_display *display = to_intel_display(crtc); 2083 const struct intel_crtc_state *new_crtc_state = 2084 intel_atomic_get_new_crtc_state(state, crtc); 2085 enum pipe pipe = crtc->pipe; 2086 2087 if (drm_WARN_ON(display->drm, crtc->active)) 2088 return; 2089 2090 i9xx_configure_cpu_transcoder(new_crtc_state); 2091 2092 intel_set_pipe_src_size(new_crtc_state); 2093 2094 crtc->active = true; 2095 2096 if (DISPLAY_VER(display) != 2) 2097 intel_set_cpu_fifo_underrun_reporting(display, pipe, true); 2098 2099 intel_encoders_pre_enable(state, crtc); 2100 2101 i9xx_enable_pll(new_crtc_state); 2102 2103 i9xx_pfit_enable(new_crtc_state); 2104 2105 intel_color_modeset(new_crtc_state); 2106 2107 if (!intel_initial_watermarks(state, crtc)) 2108 intel_update_watermarks(display); 2109 intel_enable_transcoder(new_crtc_state); 2110 2111 intel_crtc_vblank_on(new_crtc_state); 2112 2113 intel_encoders_enable(state, crtc); 2114 2115 /* prevents spurious underruns */ 2116 if (DISPLAY_VER(display) == 2) 2117 intel_crtc_wait_for_next_vblank(crtc); 2118 } 2119 2120 static void i9xx_crtc_disable(struct intel_atomic_state *state, 2121 struct intel_crtc *crtc) 2122 { 2123 struct intel_display *display = to_intel_display(state); 2124 struct intel_crtc_state *old_crtc_state = 2125 intel_atomic_get_old_crtc_state(state, crtc); 2126 enum pipe pipe = crtc->pipe; 2127 2128 /* 2129 * On gen2 planes are double buffered but the pipe isn't, so we must 2130 * wait for planes to fully turn off before disabling the pipe. 2131 */ 2132 if (DISPLAY_VER(display) == 2) 2133 intel_crtc_wait_for_next_vblank(crtc); 2134 2135 intel_encoders_disable(state, crtc); 2136 2137 intel_crtc_vblank_off(old_crtc_state); 2138 2139 intel_disable_transcoder(old_crtc_state); 2140 2141 i9xx_pfit_disable(old_crtc_state); 2142 2143 intel_encoders_post_disable(state, crtc); 2144 2145 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) { 2146 if (display->platform.cherryview) 2147 chv_disable_pll(display, pipe); 2148 else if (display->platform.valleyview) 2149 vlv_disable_pll(display, pipe); 2150 else 2151 i9xx_disable_pll(old_crtc_state); 2152 } 2153 2154 intel_encoders_post_pll_disable(state, crtc); 2155 2156 if (DISPLAY_VER(display) != 2) 2157 intel_set_cpu_fifo_underrun_reporting(display, pipe, false); 2158 2159 if (!display->funcs.wm->initial_watermarks) 2160 intel_update_watermarks(display); 2161 2162 /* clock the pipe down to 640x480@60 to potentially save power */ 2163 if (display->platform.i830) 2164 i830_enable_pipe(display, pipe); 2165 } 2166 2167 void intel_encoder_destroy(struct drm_encoder *encoder) 2168 { 2169 struct intel_encoder *intel_encoder = to_intel_encoder(encoder); 2170 2171 drm_encoder_cleanup(encoder); 2172 kfree(intel_encoder); 2173 } 2174 2175 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) 2176 { 2177 struct intel_display *display = to_intel_display(crtc); 2178 2179 /* GDG double wide on either pipe, otherwise pipe A only */ 2180 return HAS_DOUBLE_WIDE(display) && 2181 (crtc->pipe == PIPE_A || display->platform.i915g); 2182 } 2183 2184 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state) 2185 { 2186 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock; 2187 struct drm_rect src; 2188 2189 /* 2190 * We only use IF-ID interlacing. If we ever use 2191 * PF-ID we'll need to adjust the pixel_rate here. 2192 */ 2193 2194 if (!crtc_state->pch_pfit.enabled) 2195 return pixel_rate; 2196 2197 drm_rect_init(&src, 0, 0, 2198 drm_rect_width(&crtc_state->pipe_src) << 16, 2199 drm_rect_height(&crtc_state->pipe_src) << 16); 2200 2201 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst, 2202 pixel_rate); 2203 } 2204 2205 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode, 2206 const struct drm_display_mode *timings) 2207 { 2208 mode->hdisplay = timings->crtc_hdisplay; 2209 mode->htotal = timings->crtc_htotal; 2210 mode->hsync_start = timings->crtc_hsync_start; 2211 mode->hsync_end = timings->crtc_hsync_end; 2212 2213 mode->vdisplay = timings->crtc_vdisplay; 2214 mode->vtotal = timings->crtc_vtotal; 2215 mode->vsync_start = timings->crtc_vsync_start; 2216 mode->vsync_end = timings->crtc_vsync_end; 2217 2218 mode->flags = timings->flags; 2219 mode->type = DRM_MODE_TYPE_DRIVER; 2220 2221 mode->clock = timings->crtc_clock; 2222 2223 drm_mode_set_name(mode); 2224 } 2225 2226 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state) 2227 { 2228 struct intel_display *display = to_intel_display(crtc_state); 2229 2230 if (HAS_GMCH(display)) 2231 /* FIXME calculate proper pipe pixel rate for GMCH pfit */ 2232 crtc_state->pixel_rate = 2233 crtc_state->hw.pipe_mode.crtc_clock; 2234 else 2235 crtc_state->pixel_rate = 2236 ilk_pipe_pixel_rate(crtc_state); 2237 } 2238 2239 static void intel_joiner_adjust_timings(const struct intel_crtc_state *crtc_state, 2240 struct drm_display_mode *mode) 2241 { 2242 int num_pipes = intel_crtc_num_joined_pipes(crtc_state); 2243 2244 if (num_pipes == 1) 2245 return; 2246 2247 mode->crtc_clock /= num_pipes; 2248 mode->crtc_hdisplay /= num_pipes; 2249 mode->crtc_hblank_start /= num_pipes; 2250 mode->crtc_hblank_end /= num_pipes; 2251 mode->crtc_hsync_start /= num_pipes; 2252 mode->crtc_hsync_end /= num_pipes; 2253 mode->crtc_htotal /= num_pipes; 2254 } 2255 2256 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state, 2257 struct drm_display_mode *mode) 2258 { 2259 int overlap = crtc_state->splitter.pixel_overlap; 2260 int n = crtc_state->splitter.link_count; 2261 2262 if (!crtc_state->splitter.enable) 2263 return; 2264 2265 /* 2266 * eDP MSO uses segment timings from EDID for transcoder 2267 * timings, but full mode for everything else. 2268 * 2269 * h_full = (h_segment - pixel_overlap) * link_count 2270 */ 2271 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n; 2272 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n; 2273 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n; 2274 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n; 2275 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n; 2276 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n; 2277 mode->crtc_clock *= n; 2278 } 2279 2280 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state) 2281 { 2282 struct drm_display_mode *mode = &crtc_state->hw.mode; 2283 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; 2284 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2285 2286 /* 2287 * Start with the adjusted_mode crtc timings, which 2288 * have been filled with the transcoder timings. 2289 */ 2290 drm_mode_copy(pipe_mode, adjusted_mode); 2291 2292 /* Expand MSO per-segment transcoder timings to full */ 2293 intel_splitter_adjust_timings(crtc_state, pipe_mode); 2294 2295 /* 2296 * We want the full numbers in adjusted_mode normal timings, 2297 * adjusted_mode crtc timings are left with the raw transcoder 2298 * timings. 2299 */ 2300 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode); 2301 2302 /* Populate the "user" mode with full numbers */ 2303 drm_mode_copy(mode, pipe_mode); 2304 intel_mode_from_crtc_timings(mode, mode); 2305 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) * 2306 intel_crtc_num_joined_pipes(crtc_state); 2307 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src); 2308 2309 /* Derive per-pipe timings in case joiner is used */ 2310 intel_joiner_adjust_timings(crtc_state, pipe_mode); 2311 intel_mode_from_crtc_timings(pipe_mode, pipe_mode); 2312 2313 intel_crtc_compute_pixel_rate(crtc_state); 2314 } 2315 2316 void intel_encoder_get_config(struct intel_encoder *encoder, 2317 struct intel_crtc_state *crtc_state) 2318 { 2319 encoder->get_config(encoder, crtc_state); 2320 2321 intel_crtc_readout_derived_state(crtc_state); 2322 } 2323 2324 static void intel_joiner_compute_pipe_src(struct intel_crtc_state *crtc_state) 2325 { 2326 int num_pipes = intel_crtc_num_joined_pipes(crtc_state); 2327 int width, height; 2328 2329 if (num_pipes == 1) 2330 return; 2331 2332 width = drm_rect_width(&crtc_state->pipe_src); 2333 height = drm_rect_height(&crtc_state->pipe_src); 2334 2335 drm_rect_init(&crtc_state->pipe_src, 0, 0, 2336 width / num_pipes, height); 2337 } 2338 2339 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state) 2340 { 2341 struct intel_display *display = to_intel_display(crtc_state); 2342 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2343 2344 intel_joiner_compute_pipe_src(crtc_state); 2345 2346 /* 2347 * Pipe horizontal size must be even in: 2348 * - DVO ganged mode 2349 * - LVDS dual channel mode 2350 * - Double wide pipe 2351 */ 2352 if (drm_rect_width(&crtc_state->pipe_src) & 1) { 2353 if (crtc_state->double_wide) { 2354 drm_dbg_kms(display->drm, 2355 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n", 2356 crtc->base.base.id, crtc->base.name); 2357 return -EINVAL; 2358 } 2359 2360 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && 2361 intel_is_dual_link_lvds(display)) { 2362 drm_dbg_kms(display->drm, 2363 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n", 2364 crtc->base.base.id, crtc->base.name); 2365 return -EINVAL; 2366 } 2367 } 2368 2369 return 0; 2370 } 2371 2372 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state) 2373 { 2374 struct intel_display *display = to_intel_display(crtc_state); 2375 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2376 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2377 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; 2378 int clock_limit = display->cdclk.max_dotclk_freq; 2379 2380 /* 2381 * Start with the adjusted_mode crtc timings, which 2382 * have been filled with the transcoder timings. 2383 */ 2384 drm_mode_copy(pipe_mode, adjusted_mode); 2385 2386 /* Expand MSO per-segment transcoder timings to full */ 2387 intel_splitter_adjust_timings(crtc_state, pipe_mode); 2388 2389 /* Derive per-pipe timings in case joiner is used */ 2390 intel_joiner_adjust_timings(crtc_state, pipe_mode); 2391 intel_mode_from_crtc_timings(pipe_mode, pipe_mode); 2392 2393 if (DISPLAY_VER(display) < 4) { 2394 clock_limit = display->cdclk.max_cdclk_freq * 9 / 10; 2395 2396 /* 2397 * Enable double wide mode when the dot clock 2398 * is > 90% of the (display) core speed. 2399 */ 2400 if (intel_crtc_supports_double_wide(crtc) && 2401 pipe_mode->crtc_clock > clock_limit) { 2402 clock_limit = display->cdclk.max_dotclk_freq; 2403 crtc_state->double_wide = true; 2404 } 2405 } 2406 2407 if (pipe_mode->crtc_clock > clock_limit) { 2408 drm_dbg_kms(display->drm, 2409 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", 2410 crtc->base.base.id, crtc->base.name, 2411 pipe_mode->crtc_clock, clock_limit, 2412 str_yes_no(crtc_state->double_wide)); 2413 return -EINVAL; 2414 } 2415 2416 return 0; 2417 } 2418 2419 static int intel_crtc_vblank_delay(const struct intel_crtc_state *crtc_state) 2420 { 2421 struct intel_display *display = to_intel_display(crtc_state); 2422 int vblank_delay = 0; 2423 2424 if (!HAS_DSB(display)) 2425 return 0; 2426 2427 vblank_delay = max(vblank_delay, intel_psr_min_vblank_delay(crtc_state)); 2428 2429 return vblank_delay; 2430 } 2431 2432 static int intel_crtc_compute_vblank_delay(struct intel_atomic_state *state, 2433 struct intel_crtc *crtc) 2434 { 2435 struct intel_display *display = to_intel_display(state); 2436 struct intel_crtc_state *crtc_state = 2437 intel_atomic_get_new_crtc_state(state, crtc); 2438 struct drm_display_mode *adjusted_mode = 2439 &crtc_state->hw.adjusted_mode; 2440 int vblank_delay, max_vblank_delay; 2441 2442 vblank_delay = intel_crtc_vblank_delay(crtc_state); 2443 max_vblank_delay = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start - 1; 2444 2445 if (vblank_delay > max_vblank_delay) { 2446 drm_dbg_kms(display->drm, "[CRTC:%d:%s] vblank delay (%d) exceeds max (%d)\n", 2447 crtc->base.base.id, crtc->base.name, vblank_delay, max_vblank_delay); 2448 return -EINVAL; 2449 } 2450 2451 adjusted_mode->crtc_vblank_start += vblank_delay; 2452 2453 return 0; 2454 } 2455 2456 static int intel_crtc_compute_config(struct intel_atomic_state *state, 2457 struct intel_crtc *crtc) 2458 { 2459 struct intel_crtc_state *crtc_state = 2460 intel_atomic_get_new_crtc_state(state, crtc); 2461 int ret; 2462 2463 ret = intel_crtc_compute_vblank_delay(state, crtc); 2464 if (ret) 2465 return ret; 2466 2467 ret = intel_dpll_crtc_compute_clock(state, crtc); 2468 if (ret) 2469 return ret; 2470 2471 ret = intel_crtc_compute_pipe_src(crtc_state); 2472 if (ret) 2473 return ret; 2474 2475 ret = intel_crtc_compute_pipe_mode(crtc_state); 2476 if (ret) 2477 return ret; 2478 2479 intel_crtc_compute_pixel_rate(crtc_state); 2480 2481 if (crtc_state->has_pch_encoder) 2482 return ilk_fdi_compute_config(crtc, crtc_state); 2483 2484 return 0; 2485 } 2486 2487 static void 2488 intel_reduce_m_n_ratio(u32 *num, u32 *den) 2489 { 2490 while (*num > DATA_LINK_M_N_MASK || 2491 *den > DATA_LINK_M_N_MASK) { 2492 *num >>= 1; 2493 *den >>= 1; 2494 } 2495 } 2496 2497 static void compute_m_n(u32 *ret_m, u32 *ret_n, 2498 u32 m, u32 n, u32 constant_n) 2499 { 2500 if (constant_n) 2501 *ret_n = constant_n; 2502 else 2503 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); 2504 2505 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n); 2506 intel_reduce_m_n_ratio(ret_m, ret_n); 2507 } 2508 2509 void 2510 intel_link_compute_m_n(u16 bits_per_pixel_x16, int nlanes, 2511 int pixel_clock, int link_clock, 2512 int bw_overhead, 2513 struct intel_link_m_n *m_n) 2514 { 2515 u32 link_symbol_clock = intel_dp_link_symbol_clock(link_clock); 2516 u32 data_m = intel_dp_effective_data_rate(pixel_clock, bits_per_pixel_x16, 2517 bw_overhead); 2518 u32 data_n = drm_dp_max_dprx_data_rate(link_clock, nlanes); 2519 2520 /* 2521 * Windows/BIOS uses fixed M/N values always. Follow suit. 2522 * 2523 * Also several DP dongles in particular seem to be fussy 2524 * about too large link M/N values. Presumably the 20bit 2525 * value used by Windows/BIOS is acceptable to everyone. 2526 */ 2527 m_n->tu = 64; 2528 compute_m_n(&m_n->data_m, &m_n->data_n, 2529 data_m, data_n, 2530 0x8000000); 2531 2532 compute_m_n(&m_n->link_m, &m_n->link_n, 2533 pixel_clock, link_symbol_clock, 2534 0x80000); 2535 } 2536 2537 void intel_panel_sanitize_ssc(struct intel_display *display) 2538 { 2539 /* 2540 * There may be no VBT; and if the BIOS enabled SSC we can 2541 * just keep using it to avoid unnecessary flicker. Whereas if the 2542 * BIOS isn't using it, don't assume it will work even if the VBT 2543 * indicates as much. 2544 */ 2545 if (HAS_PCH_IBX(display) || HAS_PCH_CPT(display)) { 2546 bool bios_lvds_use_ssc = intel_de_read(display, 2547 PCH_DREF_CONTROL) & 2548 DREF_SSC1_ENABLE; 2549 2550 if (display->vbt.lvds_use_ssc != bios_lvds_use_ssc) { 2551 drm_dbg_kms(display->drm, 2552 "SSC %s by BIOS, overriding VBT which says %s\n", 2553 str_enabled_disabled(bios_lvds_use_ssc), 2554 str_enabled_disabled(display->vbt.lvds_use_ssc)); 2555 display->vbt.lvds_use_ssc = bios_lvds_use_ssc; 2556 } 2557 } 2558 } 2559 2560 void intel_zero_m_n(struct intel_link_m_n *m_n) 2561 { 2562 /* corresponds to 0 register value */ 2563 memset(m_n, 0, sizeof(*m_n)); 2564 m_n->tu = 1; 2565 } 2566 2567 void intel_set_m_n(struct intel_display *display, 2568 const struct intel_link_m_n *m_n, 2569 i915_reg_t data_m_reg, i915_reg_t data_n_reg, 2570 i915_reg_t link_m_reg, i915_reg_t link_n_reg) 2571 { 2572 intel_de_write(display, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m); 2573 intel_de_write(display, data_n_reg, m_n->data_n); 2574 intel_de_write(display, link_m_reg, m_n->link_m); 2575 /* 2576 * On BDW+ writing LINK_N arms the double buffered update 2577 * of all the M/N registers, so it must be written last. 2578 */ 2579 intel_de_write(display, link_n_reg, m_n->link_n); 2580 } 2581 2582 bool intel_cpu_transcoder_has_m2_n2(struct intel_display *display, 2583 enum transcoder transcoder) 2584 { 2585 if (display->platform.haswell) 2586 return transcoder == TRANSCODER_EDP; 2587 2588 return IS_DISPLAY_VER(display, 5, 7) || display->platform.cherryview; 2589 } 2590 2591 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc, 2592 enum transcoder transcoder, 2593 const struct intel_link_m_n *m_n) 2594 { 2595 struct intel_display *display = to_intel_display(crtc); 2596 enum pipe pipe = crtc->pipe; 2597 2598 if (DISPLAY_VER(display) >= 5) 2599 intel_set_m_n(display, m_n, 2600 PIPE_DATA_M1(display, transcoder), 2601 PIPE_DATA_N1(display, transcoder), 2602 PIPE_LINK_M1(display, transcoder), 2603 PIPE_LINK_N1(display, transcoder)); 2604 else 2605 intel_set_m_n(display, m_n, 2606 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe), 2607 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe)); 2608 } 2609 2610 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc, 2611 enum transcoder transcoder, 2612 const struct intel_link_m_n *m_n) 2613 { 2614 struct intel_display *display = to_intel_display(crtc); 2615 2616 if (!intel_cpu_transcoder_has_m2_n2(display, transcoder)) 2617 return; 2618 2619 intel_set_m_n(display, m_n, 2620 PIPE_DATA_M2(display, transcoder), 2621 PIPE_DATA_N2(display, transcoder), 2622 PIPE_LINK_M2(display, transcoder), 2623 PIPE_LINK_N2(display, transcoder)); 2624 } 2625 2626 static bool 2627 transcoder_has_vrr(const struct intel_crtc_state *crtc_state) 2628 { 2629 struct intel_display *display = to_intel_display(crtc_state); 2630 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2631 2632 return HAS_VRR(display) && !transcoder_is_dsi(cpu_transcoder); 2633 } 2634 2635 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state) 2636 { 2637 struct intel_display *display = to_intel_display(crtc_state); 2638 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2639 enum pipe pipe = crtc->pipe; 2640 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2641 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2642 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end; 2643 int vsyncshift = 0; 2644 2645 drm_WARN_ON(display->drm, transcoder_is_dsi(cpu_transcoder)); 2646 2647 /* We need to be careful not to changed the adjusted mode, for otherwise 2648 * the hw state checker will get angry at the mismatch. */ 2649 crtc_vdisplay = adjusted_mode->crtc_vdisplay; 2650 crtc_vtotal = adjusted_mode->crtc_vtotal; 2651 crtc_vblank_start = adjusted_mode->crtc_vblank_start; 2652 crtc_vblank_end = adjusted_mode->crtc_vblank_end; 2653 2654 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { 2655 /* the chip adds 2 halflines automatically */ 2656 crtc_vtotal -= 1; 2657 crtc_vblank_end -= 1; 2658 2659 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 2660 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; 2661 else 2662 vsyncshift = adjusted_mode->crtc_hsync_start - 2663 adjusted_mode->crtc_htotal / 2; 2664 if (vsyncshift < 0) 2665 vsyncshift += adjusted_mode->crtc_htotal; 2666 } 2667 2668 /* 2669 * VBLANK_START no longer works on ADL+, instead we must use 2670 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start. 2671 */ 2672 if (DISPLAY_VER(display) >= 13) { 2673 intel_de_write(display, 2674 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder), 2675 crtc_vblank_start - crtc_vdisplay); 2676 2677 /* 2678 * VBLANK_START not used by hw, just clear it 2679 * to make it stand out in register dumps. 2680 */ 2681 crtc_vblank_start = 1; 2682 } 2683 2684 if (DISPLAY_VER(display) >= 4) 2685 intel_de_write(display, 2686 TRANS_VSYNCSHIFT(display, cpu_transcoder), 2687 vsyncshift); 2688 2689 intel_de_write(display, TRANS_HTOTAL(display, cpu_transcoder), 2690 HACTIVE(adjusted_mode->crtc_hdisplay - 1) | 2691 HTOTAL(adjusted_mode->crtc_htotal - 1)); 2692 intel_de_write(display, TRANS_HBLANK(display, cpu_transcoder), 2693 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) | 2694 HBLANK_END(adjusted_mode->crtc_hblank_end - 1)); 2695 intel_de_write(display, TRANS_HSYNC(display, cpu_transcoder), 2696 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) | 2697 HSYNC_END(adjusted_mode->crtc_hsync_end - 1)); 2698 2699 /* 2700 * For platforms that always use VRR Timing Generator, the VTOTAL.Vtotal 2701 * bits are not required. Since the support for these bits is going to 2702 * be deprecated in upcoming platforms, avoid writing these bits for the 2703 * platforms that do not use legacy Timing Generator. 2704 */ 2705 if (intel_vrr_always_use_vrr_tg(display)) 2706 crtc_vtotal = 1; 2707 2708 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder), 2709 VACTIVE(crtc_vdisplay - 1) | 2710 VTOTAL(crtc_vtotal - 1)); 2711 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder), 2712 VBLANK_START(crtc_vblank_start - 1) | 2713 VBLANK_END(crtc_vblank_end - 1)); 2714 intel_de_write(display, TRANS_VSYNC(display, cpu_transcoder), 2715 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) | 2716 VSYNC_END(adjusted_mode->crtc_vsync_end - 1)); 2717 2718 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be 2719 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is 2720 * documented on the DDI_FUNC_CTL register description, EDP Input Select 2721 * bits. */ 2722 if (display->platform.haswell && cpu_transcoder == TRANSCODER_EDP && 2723 (pipe == PIPE_B || pipe == PIPE_C)) 2724 intel_de_write(display, TRANS_VTOTAL(display, pipe), 2725 VACTIVE(crtc_vdisplay - 1) | 2726 VTOTAL(crtc_vtotal - 1)); 2727 2728 if (DISPLAY_VER(display) >= 30) { 2729 /* 2730 * Address issues for resolutions with high refresh rate that 2731 * have small Hblank, specifically where Hblank is smaller than 2732 * one MTP. Simulations indicate this will address the 2733 * jitter issues that currently causes BS to be immediately 2734 * followed by BE which DPRX devices are unable to handle. 2735 * https://groups.vesa.org/wg/DP/document/20494 2736 */ 2737 intel_de_write(display, DP_MIN_HBLANK_CTL(cpu_transcoder), 2738 crtc_state->min_hblank); 2739 } 2740 } 2741 2742 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state) 2743 { 2744 struct intel_display *display = to_intel_display(crtc_state); 2745 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2746 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 2747 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end; 2748 2749 drm_WARN_ON(display->drm, transcoder_is_dsi(cpu_transcoder)); 2750 2751 crtc_vdisplay = adjusted_mode->crtc_vdisplay; 2752 crtc_vtotal = adjusted_mode->crtc_vtotal; 2753 crtc_vblank_start = adjusted_mode->crtc_vblank_start; 2754 crtc_vblank_end = adjusted_mode->crtc_vblank_end; 2755 2756 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { 2757 /* the chip adds 2 halflines automatically */ 2758 crtc_vtotal -= 1; 2759 crtc_vblank_end -= 1; 2760 } 2761 2762 if (DISPLAY_VER(display) >= 13) { 2763 intel_de_write(display, 2764 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder), 2765 crtc_vblank_start - crtc_vdisplay); 2766 2767 /* 2768 * VBLANK_START not used by hw, just clear it 2769 * to make it stand out in register dumps. 2770 */ 2771 crtc_vblank_start = 1; 2772 } 2773 2774 /* 2775 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode. 2776 * But let's write it anyway to keep the state checker happy. 2777 */ 2778 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder), 2779 VBLANK_START(crtc_vblank_start - 1) | 2780 VBLANK_END(crtc_vblank_end - 1)); 2781 /* 2782 * For platforms that always use VRR Timing Generator, the VTOTAL.Vtotal 2783 * bits are not required. Since the support for these bits is going to 2784 * be deprecated in upcoming platforms, avoid writing these bits for the 2785 * platforms that do not use legacy Timing Generator. 2786 */ 2787 if (intel_vrr_always_use_vrr_tg(display)) 2788 crtc_vtotal = 1; 2789 2790 /* 2791 * The double buffer latch point for TRANS_VTOTAL 2792 * is the transcoder's undelayed vblank. 2793 */ 2794 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder), 2795 VACTIVE(crtc_vdisplay - 1) | 2796 VTOTAL(crtc_vtotal - 1)); 2797 2798 intel_vrr_set_fixed_rr_timings(crtc_state); 2799 intel_vrr_transcoder_enable(crtc_state); 2800 } 2801 2802 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state) 2803 { 2804 struct intel_display *display = to_intel_display(crtc_state); 2805 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2806 int width = drm_rect_width(&crtc_state->pipe_src); 2807 int height = drm_rect_height(&crtc_state->pipe_src); 2808 enum pipe pipe = crtc->pipe; 2809 2810 /* pipesrc controls the size that is scaled from, which should 2811 * always be the user's requested size. 2812 */ 2813 intel_de_write(display, PIPESRC(display, pipe), 2814 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1)); 2815 } 2816 2817 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state) 2818 { 2819 struct intel_display *display = to_intel_display(crtc_state); 2820 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2821 2822 if (DISPLAY_VER(display) == 2) 2823 return false; 2824 2825 if (DISPLAY_VER(display) >= 9 || 2826 display->platform.broadwell || display->platform.haswell) 2827 return intel_de_read(display, 2828 TRANSCONF(display, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW; 2829 else 2830 return intel_de_read(display, 2831 TRANSCONF(display, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK; 2832 } 2833 2834 static void intel_get_transcoder_timings(struct intel_crtc *crtc, 2835 struct intel_crtc_state *pipe_config) 2836 { 2837 struct intel_display *display = to_intel_display(crtc); 2838 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; 2839 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 2840 u32 tmp; 2841 2842 tmp = intel_de_read(display, TRANS_HTOTAL(display, cpu_transcoder)); 2843 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1; 2844 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1; 2845 2846 if (!transcoder_is_dsi(cpu_transcoder)) { 2847 tmp = intel_de_read(display, 2848 TRANS_HBLANK(display, cpu_transcoder)); 2849 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1; 2850 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1; 2851 } 2852 2853 tmp = intel_de_read(display, TRANS_HSYNC(display, cpu_transcoder)); 2854 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1; 2855 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1; 2856 2857 tmp = intel_de_read(display, TRANS_VTOTAL(display, cpu_transcoder)); 2858 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1; 2859 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1; 2860 2861 /* FIXME TGL+ DSI transcoders have this! */ 2862 if (!transcoder_is_dsi(cpu_transcoder)) { 2863 tmp = intel_de_read(display, 2864 TRANS_VBLANK(display, cpu_transcoder)); 2865 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1; 2866 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1; 2867 } 2868 tmp = intel_de_read(display, TRANS_VSYNC(display, cpu_transcoder)); 2869 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1; 2870 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1; 2871 2872 if (intel_pipe_is_interlaced(pipe_config)) { 2873 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE; 2874 adjusted_mode->crtc_vtotal += 1; 2875 adjusted_mode->crtc_vblank_end += 1; 2876 } 2877 2878 if (DISPLAY_VER(display) >= 13 && !transcoder_is_dsi(cpu_transcoder)) 2879 adjusted_mode->crtc_vblank_start = 2880 adjusted_mode->crtc_vdisplay + 2881 intel_de_read(display, 2882 TRANS_SET_CONTEXT_LATENCY(display, cpu_transcoder)); 2883 2884 if (DISPLAY_VER(display) >= 30) 2885 pipe_config->min_hblank = intel_de_read(display, 2886 DP_MIN_HBLANK_CTL(cpu_transcoder)); 2887 } 2888 2889 static void intel_joiner_adjust_pipe_src(struct intel_crtc_state *crtc_state) 2890 { 2891 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2892 int num_pipes = intel_crtc_num_joined_pipes(crtc_state); 2893 enum pipe primary_pipe, pipe = crtc->pipe; 2894 int width; 2895 2896 if (num_pipes == 1) 2897 return; 2898 2899 primary_pipe = joiner_primary_pipe(crtc_state); 2900 width = drm_rect_width(&crtc_state->pipe_src); 2901 2902 drm_rect_translate_to(&crtc_state->pipe_src, 2903 (pipe - primary_pipe) * width, 0); 2904 } 2905 2906 static void intel_get_pipe_src_size(struct intel_crtc *crtc, 2907 struct intel_crtc_state *pipe_config) 2908 { 2909 struct intel_display *display = to_intel_display(crtc); 2910 u32 tmp; 2911 2912 tmp = intel_de_read(display, PIPESRC(display, crtc->pipe)); 2913 2914 drm_rect_init(&pipe_config->pipe_src, 0, 0, 2915 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1, 2916 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1); 2917 2918 intel_joiner_adjust_pipe_src(pipe_config); 2919 } 2920 2921 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state) 2922 { 2923 struct intel_display *display = to_intel_display(crtc_state); 2924 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2925 u32 val = 0; 2926 2927 /* 2928 * - We keep both pipes enabled on 830 2929 * - During modeset the pipe is still disabled and must remain so 2930 * - During fastset the pipe is already enabled and must remain so 2931 */ 2932 if (display->platform.i830 || !intel_crtc_needs_modeset(crtc_state)) 2933 val |= TRANSCONF_ENABLE; 2934 2935 if (crtc_state->double_wide) 2936 val |= TRANSCONF_DOUBLE_WIDE; 2937 2938 /* only g4x and later have fancy bpc/dither controls */ 2939 if (display->platform.g4x || display->platform.valleyview || 2940 display->platform.cherryview) { 2941 /* Bspec claims that we can't use dithering for 30bpp pipes. */ 2942 if (crtc_state->dither && crtc_state->pipe_bpp != 30) 2943 val |= TRANSCONF_DITHER_EN | 2944 TRANSCONF_DITHER_TYPE_SP; 2945 2946 switch (crtc_state->pipe_bpp) { 2947 default: 2948 /* Case prevented by intel_choose_pipe_bpp_dither. */ 2949 MISSING_CASE(crtc_state->pipe_bpp); 2950 fallthrough; 2951 case 18: 2952 val |= TRANSCONF_BPC_6; 2953 break; 2954 case 24: 2955 val |= TRANSCONF_BPC_8; 2956 break; 2957 case 30: 2958 val |= TRANSCONF_BPC_10; 2959 break; 2960 } 2961 } 2962 2963 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { 2964 if (DISPLAY_VER(display) < 4 || 2965 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 2966 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION; 2967 else 2968 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT; 2969 } else { 2970 val |= TRANSCONF_INTERLACE_PROGRESSIVE; 2971 } 2972 2973 if ((display->platform.valleyview || display->platform.cherryview) && 2974 crtc_state->limited_color_range) 2975 val |= TRANSCONF_COLOR_RANGE_SELECT; 2976 2977 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode); 2978 2979 if (crtc_state->wgc_enable) 2980 val |= TRANSCONF_WGC_ENABLE; 2981 2982 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1); 2983 2984 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val); 2985 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder)); 2986 } 2987 2988 static enum intel_output_format 2989 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc) 2990 { 2991 struct intel_display *display = to_intel_display(crtc); 2992 u32 tmp; 2993 2994 tmp = intel_de_read(display, PIPE_MISC(crtc->pipe)); 2995 2996 if (tmp & PIPE_MISC_YUV420_ENABLE) { 2997 /* 2998 * We support 4:2:0 in full blend mode only. 2999 * For xe3_lpd+ this is implied in YUV420 Enable bit. 3000 * Ensure the same for prior platforms in YUV420 Mode bit. 3001 */ 3002 if (DISPLAY_VER(display) < 30) 3003 drm_WARN_ON(display->drm, 3004 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0); 3005 3006 return INTEL_OUTPUT_FORMAT_YCBCR420; 3007 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) { 3008 return INTEL_OUTPUT_FORMAT_YCBCR444; 3009 } else { 3010 return INTEL_OUTPUT_FORMAT_RGB; 3011 } 3012 } 3013 3014 static bool i9xx_get_pipe_config(struct intel_crtc *crtc, 3015 struct intel_crtc_state *pipe_config) 3016 { 3017 struct intel_display *display = to_intel_display(crtc); 3018 enum intel_display_power_domain power_domain; 3019 enum transcoder cpu_transcoder = (enum transcoder)crtc->pipe; 3020 intel_wakeref_t wakeref; 3021 bool ret = false; 3022 u32 tmp; 3023 3024 power_domain = POWER_DOMAIN_PIPE(crtc->pipe); 3025 wakeref = intel_display_power_get_if_enabled(display, power_domain); 3026 if (!wakeref) 3027 return false; 3028 3029 tmp = intel_de_read(display, TRANSCONF(display, cpu_transcoder)); 3030 if (!(tmp & TRANSCONF_ENABLE)) 3031 goto out; 3032 3033 pipe_config->cpu_transcoder = cpu_transcoder; 3034 3035 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 3036 pipe_config->sink_format = pipe_config->output_format; 3037 3038 if (display->platform.g4x || display->platform.valleyview || 3039 display->platform.cherryview) { 3040 switch (tmp & TRANSCONF_BPC_MASK) { 3041 case TRANSCONF_BPC_6: 3042 pipe_config->pipe_bpp = 18; 3043 break; 3044 case TRANSCONF_BPC_8: 3045 pipe_config->pipe_bpp = 24; 3046 break; 3047 case TRANSCONF_BPC_10: 3048 pipe_config->pipe_bpp = 30; 3049 break; 3050 default: 3051 MISSING_CASE(tmp); 3052 break; 3053 } 3054 } 3055 3056 if ((display->platform.valleyview || display->platform.cherryview) && 3057 (tmp & TRANSCONF_COLOR_RANGE_SELECT)) 3058 pipe_config->limited_color_range = true; 3059 3060 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp); 3061 3062 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1; 3063 3064 if ((display->platform.valleyview || display->platform.cherryview) && 3065 (tmp & TRANSCONF_WGC_ENABLE)) 3066 pipe_config->wgc_enable = true; 3067 3068 intel_color_get_config(pipe_config); 3069 3070 if (HAS_DOUBLE_WIDE(display)) 3071 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE; 3072 3073 intel_get_transcoder_timings(crtc, pipe_config); 3074 intel_get_pipe_src_size(crtc, pipe_config); 3075 3076 i9xx_pfit_get_config(pipe_config); 3077 3078 i9xx_dpll_get_hw_state(crtc, &pipe_config->dpll_hw_state); 3079 3080 if (DISPLAY_VER(display) >= 4) { 3081 tmp = pipe_config->dpll_hw_state.i9xx.dpll_md; 3082 pipe_config->pixel_multiplier = 3083 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) 3084 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; 3085 } else if (display->platform.i945g || display->platform.i945gm || 3086 display->platform.g33 || display->platform.pineview) { 3087 tmp = pipe_config->dpll_hw_state.i9xx.dpll; 3088 pipe_config->pixel_multiplier = 3089 ((tmp & SDVO_MULTIPLIER_MASK) 3090 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; 3091 } else { 3092 /* Note that on i915G/GM the pixel multiplier is in the sdvo 3093 * port and will be fixed up in the encoder->get_config 3094 * function. */ 3095 pipe_config->pixel_multiplier = 1; 3096 } 3097 3098 if (display->platform.cherryview) 3099 chv_crtc_clock_get(pipe_config); 3100 else if (display->platform.valleyview) 3101 vlv_crtc_clock_get(pipe_config); 3102 else 3103 i9xx_crtc_clock_get(pipe_config); 3104 3105 /* 3106 * Normally the dotclock is filled in by the encoder .get_config() 3107 * but in case the pipe is enabled w/o any ports we need a sane 3108 * default. 3109 */ 3110 pipe_config->hw.adjusted_mode.crtc_clock = 3111 pipe_config->port_clock / pipe_config->pixel_multiplier; 3112 3113 ret = true; 3114 3115 out: 3116 intel_display_power_put(display, power_domain, wakeref); 3117 3118 return ret; 3119 } 3120 3121 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state) 3122 { 3123 struct intel_display *display = to_intel_display(crtc_state); 3124 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 3125 u32 val = 0; 3126 3127 /* 3128 * - During modeset the pipe is still disabled and must remain so 3129 * - During fastset the pipe is already enabled and must remain so 3130 */ 3131 if (!intel_crtc_needs_modeset(crtc_state)) 3132 val |= TRANSCONF_ENABLE; 3133 3134 switch (crtc_state->pipe_bpp) { 3135 default: 3136 /* Case prevented by intel_choose_pipe_bpp_dither. */ 3137 MISSING_CASE(crtc_state->pipe_bpp); 3138 fallthrough; 3139 case 18: 3140 val |= TRANSCONF_BPC_6; 3141 break; 3142 case 24: 3143 val |= TRANSCONF_BPC_8; 3144 break; 3145 case 30: 3146 val |= TRANSCONF_BPC_10; 3147 break; 3148 case 36: 3149 val |= TRANSCONF_BPC_12; 3150 break; 3151 } 3152 3153 if (crtc_state->dither) 3154 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP; 3155 3156 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) 3157 val |= TRANSCONF_INTERLACE_IF_ID_ILK; 3158 else 3159 val |= TRANSCONF_INTERLACE_PF_PD_ILK; 3160 3161 /* 3162 * This would end up with an odd purple hue over 3163 * the entire display. Make sure we don't do it. 3164 */ 3165 drm_WARN_ON(display->drm, crtc_state->limited_color_range && 3166 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB); 3167 3168 if (crtc_state->limited_color_range && 3169 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) 3170 val |= TRANSCONF_COLOR_RANGE_SELECT; 3171 3172 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 3173 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709; 3174 3175 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode); 3176 3177 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1); 3178 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay); 3179 3180 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val); 3181 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder)); 3182 } 3183 3184 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state) 3185 { 3186 struct intel_display *display = to_intel_display(crtc_state); 3187 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 3188 u32 val = 0; 3189 3190 /* 3191 * - During modeset the pipe is still disabled and must remain so 3192 * - During fastset the pipe is already enabled and must remain so 3193 */ 3194 if (!intel_crtc_needs_modeset(crtc_state)) 3195 val |= TRANSCONF_ENABLE; 3196 3197 if (display->platform.haswell && crtc_state->dither) 3198 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP; 3199 3200 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) 3201 val |= TRANSCONF_INTERLACE_IF_ID_ILK; 3202 else 3203 val |= TRANSCONF_INTERLACE_PF_PD_ILK; 3204 3205 if (display->platform.haswell && 3206 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 3207 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW; 3208 3209 intel_de_write(display, TRANSCONF(display, cpu_transcoder), val); 3210 intel_de_posting_read(display, TRANSCONF(display, cpu_transcoder)); 3211 } 3212 3213 static void bdw_set_pipe_misc(struct intel_dsb *dsb, 3214 const struct intel_crtc_state *crtc_state) 3215 { 3216 struct intel_display *display = to_intel_display(crtc_state); 3217 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3218 u32 val = 0; 3219 3220 switch (crtc_state->pipe_bpp) { 3221 case 18: 3222 val |= PIPE_MISC_BPC_6; 3223 break; 3224 case 24: 3225 val |= PIPE_MISC_BPC_8; 3226 break; 3227 case 30: 3228 val |= PIPE_MISC_BPC_10; 3229 break; 3230 case 36: 3231 /* Port output 12BPC defined for ADLP+ */ 3232 if (DISPLAY_VER(display) >= 13) 3233 val |= PIPE_MISC_BPC_12_ADLP; 3234 break; 3235 default: 3236 MISSING_CASE(crtc_state->pipe_bpp); 3237 break; 3238 } 3239 3240 if (crtc_state->dither) 3241 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP; 3242 3243 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 || 3244 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) 3245 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV; 3246 3247 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 3248 val |= DISPLAY_VER(display) >= 30 ? PIPE_MISC_YUV420_ENABLE : 3249 PIPE_MISC_YUV420_ENABLE | PIPE_MISC_YUV420_MODE_FULL_BLEND; 3250 3251 if (DISPLAY_VER(display) >= 11 && is_hdr_mode(crtc_state)) 3252 val |= PIPE_MISC_HDR_MODE_PRECISION; 3253 3254 if (DISPLAY_VER(display) >= 12) 3255 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC; 3256 3257 /* allow PSR with sprite enabled */ 3258 if (display->platform.broadwell) 3259 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE; 3260 3261 intel_de_write_dsb(display, dsb, PIPE_MISC(crtc->pipe), val); 3262 } 3263 3264 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc) 3265 { 3266 struct intel_display *display = to_intel_display(crtc); 3267 u32 tmp; 3268 3269 tmp = intel_de_read(display, PIPE_MISC(crtc->pipe)); 3270 3271 switch (tmp & PIPE_MISC_BPC_MASK) { 3272 case PIPE_MISC_BPC_6: 3273 return 18; 3274 case PIPE_MISC_BPC_8: 3275 return 24; 3276 case PIPE_MISC_BPC_10: 3277 return 30; 3278 /* 3279 * PORT OUTPUT 12 BPC defined for ADLP+. 3280 * 3281 * TODO: 3282 * For previous platforms with DSI interface, bits 5:7 3283 * are used for storing pipe_bpp irrespective of dithering. 3284 * Since the value of 12 BPC is not defined for these bits 3285 * on older platforms, need to find a workaround for 12 BPC 3286 * MIPI DSI HW readout. 3287 */ 3288 case PIPE_MISC_BPC_12_ADLP: 3289 if (DISPLAY_VER(display) >= 13) 3290 return 36; 3291 fallthrough; 3292 default: 3293 MISSING_CASE(tmp); 3294 return 0; 3295 } 3296 } 3297 3298 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp) 3299 { 3300 /* 3301 * Account for spread spectrum to avoid 3302 * oversubscribing the link. Max center spread 3303 * is 2.5%; use 5% for safety's sake. 3304 */ 3305 u32 bps = target_clock * bpp * 21 / 20; 3306 return DIV_ROUND_UP(bps, link_bw * 8); 3307 } 3308 3309 void intel_get_m_n(struct intel_display *display, 3310 struct intel_link_m_n *m_n, 3311 i915_reg_t data_m_reg, i915_reg_t data_n_reg, 3312 i915_reg_t link_m_reg, i915_reg_t link_n_reg) 3313 { 3314 m_n->link_m = intel_de_read(display, link_m_reg) & DATA_LINK_M_N_MASK; 3315 m_n->link_n = intel_de_read(display, link_n_reg) & DATA_LINK_M_N_MASK; 3316 m_n->data_m = intel_de_read(display, data_m_reg) & DATA_LINK_M_N_MASK; 3317 m_n->data_n = intel_de_read(display, data_n_reg) & DATA_LINK_M_N_MASK; 3318 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(display, data_m_reg)) + 1; 3319 } 3320 3321 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc, 3322 enum transcoder transcoder, 3323 struct intel_link_m_n *m_n) 3324 { 3325 struct intel_display *display = to_intel_display(crtc); 3326 enum pipe pipe = crtc->pipe; 3327 3328 if (DISPLAY_VER(display) >= 5) 3329 intel_get_m_n(display, m_n, 3330 PIPE_DATA_M1(display, transcoder), 3331 PIPE_DATA_N1(display, transcoder), 3332 PIPE_LINK_M1(display, transcoder), 3333 PIPE_LINK_N1(display, transcoder)); 3334 else 3335 intel_get_m_n(display, m_n, 3336 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe), 3337 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe)); 3338 } 3339 3340 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc, 3341 enum transcoder transcoder, 3342 struct intel_link_m_n *m_n) 3343 { 3344 struct intel_display *display = to_intel_display(crtc); 3345 3346 if (!intel_cpu_transcoder_has_m2_n2(display, transcoder)) 3347 return; 3348 3349 intel_get_m_n(display, m_n, 3350 PIPE_DATA_M2(display, transcoder), 3351 PIPE_DATA_N2(display, transcoder), 3352 PIPE_LINK_M2(display, transcoder), 3353 PIPE_LINK_N2(display, transcoder)); 3354 } 3355 3356 static bool ilk_get_pipe_config(struct intel_crtc *crtc, 3357 struct intel_crtc_state *pipe_config) 3358 { 3359 struct intel_display *display = to_intel_display(crtc); 3360 enum intel_display_power_domain power_domain; 3361 enum transcoder cpu_transcoder = (enum transcoder)crtc->pipe; 3362 intel_wakeref_t wakeref; 3363 bool ret = false; 3364 u32 tmp; 3365 3366 power_domain = POWER_DOMAIN_PIPE(crtc->pipe); 3367 wakeref = intel_display_power_get_if_enabled(display, power_domain); 3368 if (!wakeref) 3369 return false; 3370 3371 tmp = intel_de_read(display, TRANSCONF(display, cpu_transcoder)); 3372 if (!(tmp & TRANSCONF_ENABLE)) 3373 goto out; 3374 3375 pipe_config->cpu_transcoder = cpu_transcoder; 3376 3377 switch (tmp & TRANSCONF_BPC_MASK) { 3378 case TRANSCONF_BPC_6: 3379 pipe_config->pipe_bpp = 18; 3380 break; 3381 case TRANSCONF_BPC_8: 3382 pipe_config->pipe_bpp = 24; 3383 break; 3384 case TRANSCONF_BPC_10: 3385 pipe_config->pipe_bpp = 30; 3386 break; 3387 case TRANSCONF_BPC_12: 3388 pipe_config->pipe_bpp = 36; 3389 break; 3390 default: 3391 break; 3392 } 3393 3394 if (tmp & TRANSCONF_COLOR_RANGE_SELECT) 3395 pipe_config->limited_color_range = true; 3396 3397 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) { 3398 case TRANSCONF_OUTPUT_COLORSPACE_YUV601: 3399 case TRANSCONF_OUTPUT_COLORSPACE_YUV709: 3400 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 3401 break; 3402 default: 3403 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 3404 break; 3405 } 3406 3407 pipe_config->sink_format = pipe_config->output_format; 3408 3409 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp); 3410 3411 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1; 3412 3413 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp); 3414 3415 intel_color_get_config(pipe_config); 3416 3417 pipe_config->pixel_multiplier = 1; 3418 3419 ilk_pch_get_config(pipe_config); 3420 3421 intel_get_transcoder_timings(crtc, pipe_config); 3422 intel_get_pipe_src_size(crtc, pipe_config); 3423 3424 ilk_pfit_get_config(pipe_config); 3425 3426 ret = true; 3427 3428 out: 3429 intel_display_power_put(display, power_domain, wakeref); 3430 3431 return ret; 3432 } 3433 3434 static u8 joiner_pipes(struct intel_display *display) 3435 { 3436 u8 pipes; 3437 3438 if (DISPLAY_VER(display) >= 12) 3439 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D); 3440 else if (DISPLAY_VER(display) >= 11) 3441 pipes = BIT(PIPE_B) | BIT(PIPE_C); 3442 else 3443 pipes = 0; 3444 3445 return pipes & DISPLAY_RUNTIME_INFO(display)->pipe_mask; 3446 } 3447 3448 static bool transcoder_ddi_func_is_enabled(struct intel_display *display, 3449 enum transcoder cpu_transcoder) 3450 { 3451 enum intel_display_power_domain power_domain; 3452 intel_wakeref_t wakeref; 3453 u32 tmp = 0; 3454 3455 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 3456 3457 with_intel_display_power_if_enabled(display, power_domain, wakeref) 3458 tmp = intel_de_read(display, 3459 TRANS_DDI_FUNC_CTL(display, cpu_transcoder)); 3460 3461 return tmp & TRANS_DDI_FUNC_ENABLE; 3462 } 3463 3464 static void enabled_uncompressed_joiner_pipes(struct intel_display *display, 3465 u8 *primary_pipes, u8 *secondary_pipes) 3466 { 3467 struct intel_crtc *crtc; 3468 3469 *primary_pipes = 0; 3470 *secondary_pipes = 0; 3471 3472 if (!HAS_UNCOMPRESSED_JOINER(display)) 3473 return; 3474 3475 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, 3476 joiner_pipes(display)) { 3477 enum intel_display_power_domain power_domain; 3478 enum pipe pipe = crtc->pipe; 3479 intel_wakeref_t wakeref; 3480 3481 power_domain = POWER_DOMAIN_PIPE(pipe); 3482 with_intel_display_power_if_enabled(display, power_domain, wakeref) { 3483 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe)); 3484 3485 if (tmp & UNCOMPRESSED_JOINER_PRIMARY) 3486 *primary_pipes |= BIT(pipe); 3487 if (tmp & UNCOMPRESSED_JOINER_SECONDARY) 3488 *secondary_pipes |= BIT(pipe); 3489 } 3490 } 3491 } 3492 3493 static void enabled_bigjoiner_pipes(struct intel_display *display, 3494 u8 *primary_pipes, u8 *secondary_pipes) 3495 { 3496 struct intel_crtc *crtc; 3497 3498 *primary_pipes = 0; 3499 *secondary_pipes = 0; 3500 3501 if (!HAS_BIGJOINER(display)) 3502 return; 3503 3504 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, 3505 joiner_pipes(display)) { 3506 enum intel_display_power_domain power_domain; 3507 enum pipe pipe = crtc->pipe; 3508 intel_wakeref_t wakeref; 3509 3510 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe); 3511 with_intel_display_power_if_enabled(display, power_domain, wakeref) { 3512 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe)); 3513 3514 if (!(tmp & BIG_JOINER_ENABLE)) 3515 continue; 3516 3517 if (tmp & PRIMARY_BIG_JOINER_ENABLE) 3518 *primary_pipes |= BIT(pipe); 3519 else 3520 *secondary_pipes |= BIT(pipe); 3521 } 3522 } 3523 } 3524 3525 static u8 expected_secondary_pipes(u8 primary_pipes, int num_pipes) 3526 { 3527 u8 secondary_pipes = 0; 3528 3529 for (int i = 1; i < num_pipes; i++) 3530 secondary_pipes |= primary_pipes << i; 3531 3532 return secondary_pipes; 3533 } 3534 3535 static u8 expected_uncompressed_joiner_secondary_pipes(u8 uncompjoiner_primary_pipes) 3536 { 3537 return expected_secondary_pipes(uncompjoiner_primary_pipes, 2); 3538 } 3539 3540 static u8 expected_bigjoiner_secondary_pipes(u8 bigjoiner_primary_pipes) 3541 { 3542 return expected_secondary_pipes(bigjoiner_primary_pipes, 2); 3543 } 3544 3545 static u8 get_joiner_primary_pipe(enum pipe pipe, u8 primary_pipes) 3546 { 3547 primary_pipes &= GENMASK(pipe, 0); 3548 3549 return primary_pipes ? BIT(fls(primary_pipes) - 1) : 0; 3550 } 3551 3552 static u8 expected_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes) 3553 { 3554 return expected_secondary_pipes(ultrajoiner_primary_pipes, 4); 3555 } 3556 3557 static u8 fixup_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes, 3558 u8 ultrajoiner_secondary_pipes) 3559 { 3560 return ultrajoiner_secondary_pipes | ultrajoiner_primary_pipes << 3; 3561 } 3562 3563 static void enabled_ultrajoiner_pipes(struct intel_display *display, 3564 u8 *primary_pipes, u8 *secondary_pipes) 3565 { 3566 struct intel_crtc *crtc; 3567 3568 *primary_pipes = 0; 3569 *secondary_pipes = 0; 3570 3571 if (!HAS_ULTRAJOINER(display)) 3572 return; 3573 3574 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, 3575 joiner_pipes(display)) { 3576 enum intel_display_power_domain power_domain; 3577 enum pipe pipe = crtc->pipe; 3578 intel_wakeref_t wakeref; 3579 3580 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe); 3581 with_intel_display_power_if_enabled(display, power_domain, wakeref) { 3582 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe)); 3583 3584 if (!(tmp & ULTRA_JOINER_ENABLE)) 3585 continue; 3586 3587 if (tmp & PRIMARY_ULTRA_JOINER_ENABLE) 3588 *primary_pipes |= BIT(pipe); 3589 else 3590 *secondary_pipes |= BIT(pipe); 3591 } 3592 } 3593 } 3594 3595 static void enabled_joiner_pipes(struct intel_display *display, 3596 enum pipe pipe, 3597 u8 *primary_pipe, u8 *secondary_pipes) 3598 { 3599 u8 primary_ultrajoiner_pipes; 3600 u8 primary_uncompressed_joiner_pipes, primary_bigjoiner_pipes; 3601 u8 secondary_ultrajoiner_pipes; 3602 u8 secondary_uncompressed_joiner_pipes, secondary_bigjoiner_pipes; 3603 u8 ultrajoiner_pipes; 3604 u8 uncompressed_joiner_pipes, bigjoiner_pipes; 3605 3606 enabled_ultrajoiner_pipes(display, &primary_ultrajoiner_pipes, 3607 &secondary_ultrajoiner_pipes); 3608 /* 3609 * For some strange reason the last pipe in the set of four 3610 * shouldn't have ultrajoiner enable bit set in hardware. 3611 * Set the bit anyway to make life easier. 3612 */ 3613 drm_WARN_ON(display->drm, 3614 expected_secondary_pipes(primary_ultrajoiner_pipes, 3) != 3615 secondary_ultrajoiner_pipes); 3616 secondary_ultrajoiner_pipes = 3617 fixup_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes, 3618 secondary_ultrajoiner_pipes); 3619 3620 drm_WARN_ON(display->drm, (primary_ultrajoiner_pipes & secondary_ultrajoiner_pipes) != 0); 3621 3622 enabled_uncompressed_joiner_pipes(display, &primary_uncompressed_joiner_pipes, 3623 &secondary_uncompressed_joiner_pipes); 3624 3625 drm_WARN_ON(display->drm, 3626 (primary_uncompressed_joiner_pipes & secondary_uncompressed_joiner_pipes) != 0); 3627 3628 enabled_bigjoiner_pipes(display, &primary_bigjoiner_pipes, 3629 &secondary_bigjoiner_pipes); 3630 3631 drm_WARN_ON(display->drm, 3632 (primary_bigjoiner_pipes & secondary_bigjoiner_pipes) != 0); 3633 3634 ultrajoiner_pipes = primary_ultrajoiner_pipes | secondary_ultrajoiner_pipes; 3635 uncompressed_joiner_pipes = primary_uncompressed_joiner_pipes | 3636 secondary_uncompressed_joiner_pipes; 3637 bigjoiner_pipes = primary_bigjoiner_pipes | secondary_bigjoiner_pipes; 3638 3639 drm_WARN(display->drm, (ultrajoiner_pipes & bigjoiner_pipes) != ultrajoiner_pipes, 3640 "Ultrajoiner pipes(%#x) should be bigjoiner pipes(%#x)\n", 3641 ultrajoiner_pipes, bigjoiner_pipes); 3642 3643 drm_WARN(display->drm, secondary_ultrajoiner_pipes != 3644 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes), 3645 "Wrong secondary ultrajoiner pipes(expected %#x, current %#x)\n", 3646 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes), 3647 secondary_ultrajoiner_pipes); 3648 3649 drm_WARN(display->drm, (uncompressed_joiner_pipes & bigjoiner_pipes) != 0, 3650 "Uncompressed joiner pipes(%#x) and bigjoiner pipes(%#x) can't intersect\n", 3651 uncompressed_joiner_pipes, bigjoiner_pipes); 3652 3653 drm_WARN(display->drm, secondary_bigjoiner_pipes != 3654 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes), 3655 "Wrong secondary bigjoiner pipes(expected %#x, current %#x)\n", 3656 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes), 3657 secondary_bigjoiner_pipes); 3658 3659 drm_WARN(display->drm, secondary_uncompressed_joiner_pipes != 3660 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes), 3661 "Wrong secondary uncompressed joiner pipes(expected %#x, current %#x)\n", 3662 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes), 3663 secondary_uncompressed_joiner_pipes); 3664 3665 *primary_pipe = 0; 3666 *secondary_pipes = 0; 3667 3668 if (ultrajoiner_pipes & BIT(pipe)) { 3669 *primary_pipe = get_joiner_primary_pipe(pipe, primary_ultrajoiner_pipes); 3670 *secondary_pipes = secondary_ultrajoiner_pipes & 3671 expected_ultrajoiner_secondary_pipes(*primary_pipe); 3672 3673 drm_WARN(display->drm, 3674 expected_ultrajoiner_secondary_pipes(*primary_pipe) != 3675 *secondary_pipes, 3676 "Wrong ultrajoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n", 3677 *primary_pipe, 3678 expected_ultrajoiner_secondary_pipes(*primary_pipe), 3679 *secondary_pipes); 3680 return; 3681 } 3682 3683 if (uncompressed_joiner_pipes & BIT(pipe)) { 3684 *primary_pipe = get_joiner_primary_pipe(pipe, primary_uncompressed_joiner_pipes); 3685 *secondary_pipes = secondary_uncompressed_joiner_pipes & 3686 expected_uncompressed_joiner_secondary_pipes(*primary_pipe); 3687 3688 drm_WARN(display->drm, 3689 expected_uncompressed_joiner_secondary_pipes(*primary_pipe) != 3690 *secondary_pipes, 3691 "Wrong uncompressed joiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n", 3692 *primary_pipe, 3693 expected_uncompressed_joiner_secondary_pipes(*primary_pipe), 3694 *secondary_pipes); 3695 return; 3696 } 3697 3698 if (bigjoiner_pipes & BIT(pipe)) { 3699 *primary_pipe = get_joiner_primary_pipe(pipe, primary_bigjoiner_pipes); 3700 *secondary_pipes = secondary_bigjoiner_pipes & 3701 expected_bigjoiner_secondary_pipes(*primary_pipe); 3702 3703 drm_WARN(display->drm, 3704 expected_bigjoiner_secondary_pipes(*primary_pipe) != 3705 *secondary_pipes, 3706 "Wrong bigjoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n", 3707 *primary_pipe, 3708 expected_bigjoiner_secondary_pipes(*primary_pipe), 3709 *secondary_pipes); 3710 return; 3711 } 3712 } 3713 3714 static u8 hsw_panel_transcoders(struct intel_display *display) 3715 { 3716 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP); 3717 3718 if (DISPLAY_VER(display) >= 11) 3719 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1); 3720 3721 return panel_transcoder_mask; 3722 } 3723 3724 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc) 3725 { 3726 struct intel_display *display = to_intel_display(crtc); 3727 u8 panel_transcoder_mask = hsw_panel_transcoders(display); 3728 enum transcoder cpu_transcoder; 3729 u8 primary_pipe, secondary_pipes; 3730 u8 enabled_transcoders = 0; 3731 3732 /* 3733 * XXX: Do intel_display_power_get_if_enabled before reading this (for 3734 * consistency and less surprising code; it's in always on power). 3735 */ 3736 for_each_cpu_transcoder_masked(display, cpu_transcoder, 3737 panel_transcoder_mask) { 3738 enum intel_display_power_domain power_domain; 3739 intel_wakeref_t wakeref; 3740 enum pipe trans_pipe; 3741 u32 tmp = 0; 3742 3743 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 3744 with_intel_display_power_if_enabled(display, power_domain, wakeref) 3745 tmp = intel_de_read(display, 3746 TRANS_DDI_FUNC_CTL(display, cpu_transcoder)); 3747 3748 if (!(tmp & TRANS_DDI_FUNC_ENABLE)) 3749 continue; 3750 3751 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 3752 default: 3753 drm_WARN(display->drm, 1, 3754 "unknown pipe linked to transcoder %s\n", 3755 transcoder_name(cpu_transcoder)); 3756 fallthrough; 3757 case TRANS_DDI_EDP_INPUT_A_ONOFF: 3758 case TRANS_DDI_EDP_INPUT_A_ON: 3759 trans_pipe = PIPE_A; 3760 break; 3761 case TRANS_DDI_EDP_INPUT_B_ONOFF: 3762 trans_pipe = PIPE_B; 3763 break; 3764 case TRANS_DDI_EDP_INPUT_C_ONOFF: 3765 trans_pipe = PIPE_C; 3766 break; 3767 case TRANS_DDI_EDP_INPUT_D_ONOFF: 3768 trans_pipe = PIPE_D; 3769 break; 3770 } 3771 3772 if (trans_pipe == crtc->pipe) 3773 enabled_transcoders |= BIT(cpu_transcoder); 3774 } 3775 3776 /* single pipe or joiner primary */ 3777 cpu_transcoder = (enum transcoder) crtc->pipe; 3778 if (transcoder_ddi_func_is_enabled(display, cpu_transcoder)) 3779 enabled_transcoders |= BIT(cpu_transcoder); 3780 3781 /* joiner secondary -> consider the primary pipe's transcoder as well */ 3782 enabled_joiner_pipes(display, crtc->pipe, &primary_pipe, &secondary_pipes); 3783 if (secondary_pipes & BIT(crtc->pipe)) { 3784 cpu_transcoder = (enum transcoder)ffs(primary_pipe) - 1; 3785 if (transcoder_ddi_func_is_enabled(display, cpu_transcoder)) 3786 enabled_transcoders |= BIT(cpu_transcoder); 3787 } 3788 3789 return enabled_transcoders; 3790 } 3791 3792 static bool has_edp_transcoders(u8 enabled_transcoders) 3793 { 3794 return enabled_transcoders & BIT(TRANSCODER_EDP); 3795 } 3796 3797 static bool has_dsi_transcoders(u8 enabled_transcoders) 3798 { 3799 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) | 3800 BIT(TRANSCODER_DSI_1)); 3801 } 3802 3803 static bool has_pipe_transcoders(u8 enabled_transcoders) 3804 { 3805 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) | 3806 BIT(TRANSCODER_DSI_0) | 3807 BIT(TRANSCODER_DSI_1)); 3808 } 3809 3810 static void assert_enabled_transcoders(struct intel_display *display, 3811 u8 enabled_transcoders) 3812 { 3813 /* Only one type of transcoder please */ 3814 drm_WARN_ON(display->drm, 3815 has_edp_transcoders(enabled_transcoders) + 3816 has_dsi_transcoders(enabled_transcoders) + 3817 has_pipe_transcoders(enabled_transcoders) > 1); 3818 3819 /* Only DSI transcoders can be ganged */ 3820 drm_WARN_ON(display->drm, 3821 !has_dsi_transcoders(enabled_transcoders) && 3822 !is_power_of_2(enabled_transcoders)); 3823 } 3824 3825 static bool hsw_get_transcoder_state(struct intel_crtc *crtc, 3826 struct intel_crtc_state *pipe_config, 3827 struct intel_display_power_domain_set *power_domain_set) 3828 { 3829 struct intel_display *display = to_intel_display(crtc); 3830 unsigned long enabled_transcoders; 3831 u32 tmp; 3832 3833 enabled_transcoders = hsw_enabled_transcoders(crtc); 3834 if (!enabled_transcoders) 3835 return false; 3836 3837 assert_enabled_transcoders(display, enabled_transcoders); 3838 3839 /* 3840 * With the exception of DSI we should only ever have 3841 * a single enabled transcoder. With DSI let's just 3842 * pick the first one. 3843 */ 3844 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1; 3845 3846 if (!intel_display_power_get_in_set_if_enabled(display, power_domain_set, 3847 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) 3848 return false; 3849 3850 if (hsw_panel_transcoders(display) & BIT(pipe_config->cpu_transcoder)) { 3851 tmp = intel_de_read(display, 3852 TRANS_DDI_FUNC_CTL(display, pipe_config->cpu_transcoder)); 3853 3854 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF) 3855 pipe_config->pch_pfit.force_thru = true; 3856 } 3857 3858 tmp = intel_de_read(display, 3859 TRANSCONF(display, pipe_config->cpu_transcoder)); 3860 3861 return tmp & TRANSCONF_ENABLE; 3862 } 3863 3864 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, 3865 struct intel_crtc_state *pipe_config, 3866 struct intel_display_power_domain_set *power_domain_set) 3867 { 3868 struct intel_display *display = to_intel_display(crtc); 3869 enum transcoder cpu_transcoder; 3870 enum port port; 3871 u32 tmp; 3872 3873 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { 3874 if (port == PORT_A) 3875 cpu_transcoder = TRANSCODER_DSI_A; 3876 else 3877 cpu_transcoder = TRANSCODER_DSI_C; 3878 3879 if (!intel_display_power_get_in_set_if_enabled(display, power_domain_set, 3880 POWER_DOMAIN_TRANSCODER(cpu_transcoder))) 3881 continue; 3882 3883 /* 3884 * The PLL needs to be enabled with a valid divider 3885 * configuration, otherwise accessing DSI registers will hang 3886 * the machine. See BSpec North Display Engine 3887 * registers/MIPI[BXT]. We can break out here early, since we 3888 * need the same DSI PLL to be enabled for both DSI ports. 3889 */ 3890 if (!bxt_dsi_pll_is_enabled(display)) 3891 break; 3892 3893 /* XXX: this works for video mode only */ 3894 tmp = intel_de_read(display, BXT_MIPI_PORT_CTRL(port)); 3895 if (!(tmp & DPI_ENABLE)) 3896 continue; 3897 3898 tmp = intel_de_read(display, MIPI_CTRL(display, port)); 3899 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) 3900 continue; 3901 3902 pipe_config->cpu_transcoder = cpu_transcoder; 3903 break; 3904 } 3905 3906 return transcoder_is_dsi(pipe_config->cpu_transcoder); 3907 } 3908 3909 static void intel_joiner_get_config(struct intel_crtc_state *crtc_state) 3910 { 3911 struct intel_display *display = to_intel_display(crtc_state); 3912 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3913 u8 primary_pipe, secondary_pipes; 3914 enum pipe pipe = crtc->pipe; 3915 3916 enabled_joiner_pipes(display, pipe, &primary_pipe, &secondary_pipes); 3917 3918 if (((primary_pipe | secondary_pipes) & BIT(pipe)) == 0) 3919 return; 3920 3921 crtc_state->joiner_pipes = primary_pipe | secondary_pipes; 3922 } 3923 3924 static bool hsw_get_pipe_config(struct intel_crtc *crtc, 3925 struct intel_crtc_state *pipe_config) 3926 { 3927 struct intel_display *display = to_intel_display(crtc); 3928 bool active; 3929 u32 tmp; 3930 3931 if (!intel_display_power_get_in_set_if_enabled(display, &crtc->hw_readout_power_domains, 3932 POWER_DOMAIN_PIPE(crtc->pipe))) 3933 return false; 3934 3935 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains); 3936 3937 if ((display->platform.geminilake || display->platform.broxton) && 3938 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) { 3939 drm_WARN_ON(display->drm, active); 3940 active = true; 3941 } 3942 3943 if (!active) 3944 goto out; 3945 3946 intel_joiner_get_config(pipe_config); 3947 intel_dsc_get_config(pipe_config); 3948 3949 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) || 3950 DISPLAY_VER(display) >= 11) 3951 intel_get_transcoder_timings(crtc, pipe_config); 3952 3953 if (transcoder_has_vrr(pipe_config)) 3954 intel_vrr_get_config(pipe_config); 3955 3956 intel_get_pipe_src_size(crtc, pipe_config); 3957 3958 if (display->platform.haswell) { 3959 u32 tmp = intel_de_read(display, 3960 TRANSCONF(display, pipe_config->cpu_transcoder)); 3961 3962 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW) 3963 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 3964 else 3965 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 3966 } else { 3967 pipe_config->output_format = 3968 bdw_get_pipe_misc_output_format(crtc); 3969 } 3970 3971 pipe_config->sink_format = pipe_config->output_format; 3972 3973 intel_color_get_config(pipe_config); 3974 3975 tmp = intel_de_read(display, WM_LINETIME(crtc->pipe)); 3976 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp); 3977 if (display->platform.broadwell || display->platform.haswell) 3978 pipe_config->ips_linetime = 3979 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp); 3980 3981 if (intel_display_power_get_in_set_if_enabled(display, &crtc->hw_readout_power_domains, 3982 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) { 3983 if (DISPLAY_VER(display) >= 9) 3984 skl_scaler_get_config(pipe_config); 3985 else 3986 ilk_pfit_get_config(pipe_config); 3987 } 3988 3989 hsw_ips_get_config(pipe_config); 3990 3991 if (pipe_config->cpu_transcoder != TRANSCODER_EDP && 3992 !transcoder_is_dsi(pipe_config->cpu_transcoder)) { 3993 pipe_config->pixel_multiplier = 3994 intel_de_read(display, 3995 TRANS_MULT(display, pipe_config->cpu_transcoder)) + 1; 3996 } else { 3997 pipe_config->pixel_multiplier = 1; 3998 } 3999 4000 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { 4001 tmp = intel_de_read(display, CHICKEN_TRANS(display, pipe_config->cpu_transcoder)); 4002 4003 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1; 4004 } else { 4005 /* no idea if this is correct */ 4006 pipe_config->framestart_delay = 1; 4007 } 4008 4009 out: 4010 intel_display_power_put_all_in_set(display, &crtc->hw_readout_power_domains); 4011 4012 return active; 4013 } 4014 4015 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state) 4016 { 4017 struct intel_display *display = to_intel_display(crtc_state); 4018 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 4019 4020 if (!display->funcs.display->get_pipe_config(crtc, crtc_state)) 4021 return false; 4022 4023 crtc_state->hw.active = true; 4024 4025 intel_crtc_readout_derived_state(crtc_state); 4026 4027 return true; 4028 } 4029 4030 int intel_dotclock_calculate(int link_freq, 4031 const struct intel_link_m_n *m_n) 4032 { 4033 /* 4034 * The calculation for the data clock -> pixel clock is: 4035 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp 4036 * But we want to avoid losing precision if possible, so: 4037 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) 4038 * 4039 * and for link freq (10kbs units) -> pixel clock it is: 4040 * link_symbol_clock = link_freq * 10 / link_symbol_size 4041 * pixel_clock = (m * link_symbol_clock) / n 4042 * or for more precision: 4043 * pixel_clock = (m * link_freq * 10) / (n * link_symbol_size) 4044 */ 4045 4046 if (!m_n->link_n) 4047 return 0; 4048 4049 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq * 10), 4050 m_n->link_n * intel_dp_link_symbol_size(link_freq)); 4051 } 4052 4053 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config) 4054 { 4055 int dotclock; 4056 4057 if (intel_crtc_has_dp_encoder(pipe_config)) 4058 dotclock = intel_dotclock_calculate(pipe_config->port_clock, 4059 &pipe_config->dp_m_n); 4060 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24) 4061 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24, 4062 pipe_config->pipe_bpp); 4063 else 4064 dotclock = pipe_config->port_clock; 4065 4066 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 4067 !intel_crtc_has_dp_encoder(pipe_config)) 4068 dotclock *= 2; 4069 4070 if (pipe_config->pixel_multiplier) 4071 dotclock /= pipe_config->pixel_multiplier; 4072 4073 return dotclock; 4074 } 4075 4076 /* Returns the currently programmed mode of the given encoder. */ 4077 struct drm_display_mode * 4078 intel_encoder_current_mode(struct intel_encoder *encoder) 4079 { 4080 struct intel_display *display = to_intel_display(encoder); 4081 struct intel_crtc_state *crtc_state; 4082 struct drm_display_mode *mode; 4083 struct intel_crtc *crtc; 4084 enum pipe pipe; 4085 4086 if (!encoder->get_hw_state(encoder, &pipe)) 4087 return NULL; 4088 4089 crtc = intel_crtc_for_pipe(display, pipe); 4090 4091 mode = kzalloc(sizeof(*mode), GFP_KERNEL); 4092 if (!mode) 4093 return NULL; 4094 4095 crtc_state = intel_crtc_state_alloc(crtc); 4096 if (!crtc_state) { 4097 kfree(mode); 4098 return NULL; 4099 } 4100 4101 if (!intel_crtc_get_pipe_config(crtc_state)) { 4102 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi); 4103 kfree(mode); 4104 return NULL; 4105 } 4106 4107 intel_encoder_get_config(encoder, crtc_state); 4108 4109 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode); 4110 4111 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi); 4112 4113 return mode; 4114 } 4115 4116 static bool encoders_cloneable(const struct intel_encoder *a, 4117 const struct intel_encoder *b) 4118 { 4119 /* masks could be asymmetric, so check both ways */ 4120 return a == b || (a->cloneable & BIT(b->type) && 4121 b->cloneable & BIT(a->type)); 4122 } 4123 4124 static bool check_single_encoder_cloning(struct intel_atomic_state *state, 4125 struct intel_crtc *crtc, 4126 struct intel_encoder *encoder) 4127 { 4128 struct intel_encoder *source_encoder; 4129 struct drm_connector *connector; 4130 struct drm_connector_state *connector_state; 4131 int i; 4132 4133 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 4134 if (connector_state->crtc != &crtc->base) 4135 continue; 4136 4137 source_encoder = 4138 to_intel_encoder(connector_state->best_encoder); 4139 if (!encoders_cloneable(encoder, source_encoder)) 4140 return false; 4141 } 4142 4143 return true; 4144 } 4145 4146 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state) 4147 { 4148 const struct drm_display_mode *pipe_mode = 4149 &crtc_state->hw.pipe_mode; 4150 int linetime_wm; 4151 4152 if (!crtc_state->hw.enable) 4153 return 0; 4154 4155 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8, 4156 pipe_mode->crtc_clock); 4157 4158 return min(linetime_wm, 0x1ff); 4159 } 4160 4161 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state, 4162 const struct intel_cdclk_state *cdclk_state) 4163 { 4164 const struct drm_display_mode *pipe_mode = 4165 &crtc_state->hw.pipe_mode; 4166 int linetime_wm; 4167 4168 if (!crtc_state->hw.enable) 4169 return 0; 4170 4171 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8, 4172 intel_cdclk_logical(cdclk_state)); 4173 4174 return min(linetime_wm, 0x1ff); 4175 } 4176 4177 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state) 4178 { 4179 struct intel_display *display = to_intel_display(crtc_state); 4180 const struct drm_display_mode *pipe_mode = 4181 &crtc_state->hw.pipe_mode; 4182 int linetime_wm; 4183 4184 if (!crtc_state->hw.enable) 4185 return 0; 4186 4187 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8, 4188 crtc_state->pixel_rate); 4189 4190 /* Display WA #1135: BXT:ALL GLK:ALL */ 4191 if ((display->platform.geminilake || display->platform.broxton) && 4192 skl_watermark_ipc_enabled(display)) 4193 linetime_wm /= 2; 4194 4195 return min(linetime_wm, 0x1ff); 4196 } 4197 4198 static int hsw_compute_linetime_wm(struct intel_atomic_state *state, 4199 struct intel_crtc *crtc) 4200 { 4201 struct intel_display *display = to_intel_display(state); 4202 struct intel_crtc_state *crtc_state = 4203 intel_atomic_get_new_crtc_state(state, crtc); 4204 const struct intel_cdclk_state *cdclk_state; 4205 4206 if (DISPLAY_VER(display) >= 9) 4207 crtc_state->linetime = skl_linetime_wm(crtc_state); 4208 else 4209 crtc_state->linetime = hsw_linetime_wm(crtc_state); 4210 4211 if (!hsw_crtc_supports_ips(crtc)) 4212 return 0; 4213 4214 cdclk_state = intel_atomic_get_cdclk_state(state); 4215 if (IS_ERR(cdclk_state)) 4216 return PTR_ERR(cdclk_state); 4217 4218 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state, 4219 cdclk_state); 4220 4221 return 0; 4222 } 4223 4224 static int intel_crtc_atomic_check(struct intel_atomic_state *state, 4225 struct intel_crtc *crtc) 4226 { 4227 struct intel_display *display = to_intel_display(crtc); 4228 struct intel_crtc_state *crtc_state = 4229 intel_atomic_get_new_crtc_state(state, crtc); 4230 int ret; 4231 4232 if (DISPLAY_VER(display) < 5 && !display->platform.g4x && 4233 intel_crtc_needs_modeset(crtc_state) && 4234 !crtc_state->hw.active) 4235 crtc_state->update_wm_post = true; 4236 4237 if (intel_crtc_needs_modeset(crtc_state)) { 4238 ret = intel_dpll_crtc_get_dpll(state, crtc); 4239 if (ret) 4240 return ret; 4241 } 4242 4243 ret = intel_color_check(state, crtc); 4244 if (ret) 4245 return ret; 4246 4247 ret = intel_wm_compute(state, crtc); 4248 if (ret) { 4249 drm_dbg_kms(display->drm, 4250 "[CRTC:%d:%s] watermarks are invalid\n", 4251 crtc->base.base.id, crtc->base.name); 4252 return ret; 4253 } 4254 4255 if (DISPLAY_VER(display) >= 9) { 4256 if (intel_crtc_needs_modeset(crtc_state) || 4257 intel_crtc_needs_fastset(crtc_state)) { 4258 ret = skl_update_scaler_crtc(crtc_state); 4259 if (ret) 4260 return ret; 4261 } 4262 4263 ret = intel_atomic_setup_scalers(state, crtc); 4264 if (ret) 4265 return ret; 4266 } 4267 4268 if (HAS_IPS(display)) { 4269 ret = hsw_ips_compute_config(state, crtc); 4270 if (ret) 4271 return ret; 4272 } 4273 4274 if (DISPLAY_VER(display) >= 9 || 4275 display->platform.broadwell || display->platform.haswell) { 4276 ret = hsw_compute_linetime_wm(state, crtc); 4277 if (ret) 4278 return ret; 4279 4280 } 4281 4282 ret = intel_psr2_sel_fetch_update(state, crtc); 4283 if (ret) 4284 return ret; 4285 4286 return 0; 4287 } 4288 4289 static int 4290 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state, 4291 struct intel_crtc_state *crtc_state) 4292 { 4293 struct intel_display *display = to_intel_display(crtc_state); 4294 struct drm_connector *connector = conn_state->connector; 4295 const struct drm_display_info *info = &connector->display_info; 4296 int bpp; 4297 4298 switch (conn_state->max_bpc) { 4299 case 6 ... 7: 4300 bpp = 6 * 3; 4301 break; 4302 case 8 ... 9: 4303 bpp = 8 * 3; 4304 break; 4305 case 10 ... 11: 4306 bpp = 10 * 3; 4307 break; 4308 case 12 ... 16: 4309 bpp = 12 * 3; 4310 break; 4311 default: 4312 MISSING_CASE(conn_state->max_bpc); 4313 return -EINVAL; 4314 } 4315 4316 if (bpp < crtc_state->pipe_bpp) { 4317 drm_dbg_kms(display->drm, 4318 "[CONNECTOR:%d:%s] Limiting display bpp to %d " 4319 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n", 4320 connector->base.id, connector->name, 4321 bpp, 3 * info->bpc, 4322 3 * conn_state->max_requested_bpc, 4323 crtc_state->pipe_bpp); 4324 4325 crtc_state->pipe_bpp = bpp; 4326 } 4327 4328 return 0; 4329 } 4330 4331 int intel_display_min_pipe_bpp(void) 4332 { 4333 return 6 * 3; 4334 } 4335 4336 int intel_display_max_pipe_bpp(struct intel_display *display) 4337 { 4338 if (display->platform.g4x || display->platform.valleyview || 4339 display->platform.cherryview) 4340 return 10*3; 4341 else if (DISPLAY_VER(display) >= 5) 4342 return 12*3; 4343 else 4344 return 8*3; 4345 } 4346 4347 static int 4348 compute_baseline_pipe_bpp(struct intel_atomic_state *state, 4349 struct intel_crtc *crtc) 4350 { 4351 struct intel_display *display = to_intel_display(crtc); 4352 struct intel_crtc_state *crtc_state = 4353 intel_atomic_get_new_crtc_state(state, crtc); 4354 struct drm_connector *connector; 4355 struct drm_connector_state *connector_state; 4356 int i; 4357 4358 crtc_state->pipe_bpp = intel_display_max_pipe_bpp(display); 4359 4360 /* Clamp display bpp to connector max bpp */ 4361 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 4362 int ret; 4363 4364 if (connector_state->crtc != &crtc->base) 4365 continue; 4366 4367 ret = compute_sink_pipe_bpp(connector_state, crtc_state); 4368 if (ret) 4369 return ret; 4370 } 4371 4372 return 0; 4373 } 4374 4375 static bool check_digital_port_conflicts(struct intel_atomic_state *state) 4376 { 4377 struct intel_display *display = to_intel_display(state); 4378 struct drm_connector *connector; 4379 struct drm_connector_list_iter conn_iter; 4380 unsigned int used_ports = 0; 4381 unsigned int used_mst_ports = 0; 4382 bool ret = true; 4383 4384 /* 4385 * We're going to peek into connector->state, 4386 * hence connection_mutex must be held. 4387 */ 4388 drm_modeset_lock_assert_held(&display->drm->mode_config.connection_mutex); 4389 4390 /* 4391 * Walk the connector list instead of the encoder 4392 * list to detect the problem on ddi platforms 4393 * where there's just one encoder per digital port. 4394 */ 4395 drm_connector_list_iter_begin(display->drm, &conn_iter); 4396 drm_for_each_connector_iter(connector, &conn_iter) { 4397 struct drm_connector_state *connector_state; 4398 struct intel_encoder *encoder; 4399 4400 connector_state = 4401 drm_atomic_get_new_connector_state(&state->base, 4402 connector); 4403 if (!connector_state) 4404 connector_state = connector->state; 4405 4406 if (!connector_state->best_encoder) 4407 continue; 4408 4409 encoder = to_intel_encoder(connector_state->best_encoder); 4410 4411 drm_WARN_ON(display->drm, !connector_state->crtc); 4412 4413 switch (encoder->type) { 4414 case INTEL_OUTPUT_DDI: 4415 if (drm_WARN_ON(display->drm, !HAS_DDI(display))) 4416 break; 4417 fallthrough; 4418 case INTEL_OUTPUT_DP: 4419 case INTEL_OUTPUT_HDMI: 4420 case INTEL_OUTPUT_EDP: 4421 /* the same port mustn't appear more than once */ 4422 if (used_ports & BIT(encoder->port)) 4423 ret = false; 4424 4425 used_ports |= BIT(encoder->port); 4426 break; 4427 case INTEL_OUTPUT_DP_MST: 4428 used_mst_ports |= 4429 1 << encoder->port; 4430 break; 4431 default: 4432 break; 4433 } 4434 } 4435 drm_connector_list_iter_end(&conn_iter); 4436 4437 /* can't mix MST and SST/HDMI on the same port */ 4438 if (used_ports & used_mst_ports) 4439 return false; 4440 4441 return ret; 4442 } 4443 4444 static void 4445 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state, 4446 struct intel_crtc *crtc) 4447 { 4448 struct intel_crtc_state *crtc_state = 4449 intel_atomic_get_new_crtc_state(state, crtc); 4450 4451 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state)); 4452 4453 drm_property_replace_blob(&crtc_state->hw.degamma_lut, 4454 crtc_state->uapi.degamma_lut); 4455 drm_property_replace_blob(&crtc_state->hw.gamma_lut, 4456 crtc_state->uapi.gamma_lut); 4457 drm_property_replace_blob(&crtc_state->hw.ctm, 4458 crtc_state->uapi.ctm); 4459 } 4460 4461 static void 4462 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state, 4463 struct intel_crtc *crtc) 4464 { 4465 struct intel_crtc_state *crtc_state = 4466 intel_atomic_get_new_crtc_state(state, crtc); 4467 4468 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state)); 4469 4470 crtc_state->hw.enable = crtc_state->uapi.enable; 4471 crtc_state->hw.active = crtc_state->uapi.active; 4472 drm_mode_copy(&crtc_state->hw.mode, 4473 &crtc_state->uapi.mode); 4474 drm_mode_copy(&crtc_state->hw.adjusted_mode, 4475 &crtc_state->uapi.adjusted_mode); 4476 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter; 4477 4478 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc); 4479 } 4480 4481 static void 4482 copy_joiner_crtc_state_nomodeset(struct intel_atomic_state *state, 4483 struct intel_crtc *secondary_crtc) 4484 { 4485 struct intel_crtc_state *secondary_crtc_state = 4486 intel_atomic_get_new_crtc_state(state, secondary_crtc); 4487 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state); 4488 const struct intel_crtc_state *primary_crtc_state = 4489 intel_atomic_get_new_crtc_state(state, primary_crtc); 4490 4491 drm_property_replace_blob(&secondary_crtc_state->hw.degamma_lut, 4492 primary_crtc_state->hw.degamma_lut); 4493 drm_property_replace_blob(&secondary_crtc_state->hw.gamma_lut, 4494 primary_crtc_state->hw.gamma_lut); 4495 drm_property_replace_blob(&secondary_crtc_state->hw.ctm, 4496 primary_crtc_state->hw.ctm); 4497 4498 secondary_crtc_state->uapi.color_mgmt_changed = primary_crtc_state->uapi.color_mgmt_changed; 4499 } 4500 4501 static int 4502 copy_joiner_crtc_state_modeset(struct intel_atomic_state *state, 4503 struct intel_crtc *secondary_crtc) 4504 { 4505 struct intel_crtc_state *secondary_crtc_state = 4506 intel_atomic_get_new_crtc_state(state, secondary_crtc); 4507 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state); 4508 const struct intel_crtc_state *primary_crtc_state = 4509 intel_atomic_get_new_crtc_state(state, primary_crtc); 4510 struct intel_crtc_state *saved_state; 4511 4512 WARN_ON(primary_crtc_state->joiner_pipes != 4513 secondary_crtc_state->joiner_pipes); 4514 4515 saved_state = kmemdup(primary_crtc_state, sizeof(*saved_state), GFP_KERNEL); 4516 if (!saved_state) 4517 return -ENOMEM; 4518 4519 /* preserve some things from the slave's original crtc state */ 4520 saved_state->uapi = secondary_crtc_state->uapi; 4521 saved_state->scaler_state = secondary_crtc_state->scaler_state; 4522 saved_state->intel_dpll = secondary_crtc_state->intel_dpll; 4523 saved_state->crc_enabled = secondary_crtc_state->crc_enabled; 4524 4525 intel_crtc_free_hw_state(secondary_crtc_state); 4526 if (secondary_crtc_state->dp_tunnel_ref.tunnel) 4527 drm_dp_tunnel_ref_put(&secondary_crtc_state->dp_tunnel_ref); 4528 memcpy(secondary_crtc_state, saved_state, sizeof(*secondary_crtc_state)); 4529 kfree(saved_state); 4530 4531 /* Re-init hw state */ 4532 memset(&secondary_crtc_state->hw, 0, sizeof(secondary_crtc_state->hw)); 4533 secondary_crtc_state->hw.enable = primary_crtc_state->hw.enable; 4534 secondary_crtc_state->hw.active = primary_crtc_state->hw.active; 4535 drm_mode_copy(&secondary_crtc_state->hw.mode, 4536 &primary_crtc_state->hw.mode); 4537 drm_mode_copy(&secondary_crtc_state->hw.pipe_mode, 4538 &primary_crtc_state->hw.pipe_mode); 4539 drm_mode_copy(&secondary_crtc_state->hw.adjusted_mode, 4540 &primary_crtc_state->hw.adjusted_mode); 4541 secondary_crtc_state->hw.scaling_filter = primary_crtc_state->hw.scaling_filter; 4542 4543 if (primary_crtc_state->dp_tunnel_ref.tunnel) 4544 drm_dp_tunnel_ref_get(primary_crtc_state->dp_tunnel_ref.tunnel, 4545 &secondary_crtc_state->dp_tunnel_ref); 4546 4547 copy_joiner_crtc_state_nomodeset(state, secondary_crtc); 4548 4549 secondary_crtc_state->uapi.mode_changed = primary_crtc_state->uapi.mode_changed; 4550 secondary_crtc_state->uapi.connectors_changed = primary_crtc_state->uapi.connectors_changed; 4551 secondary_crtc_state->uapi.active_changed = primary_crtc_state->uapi.active_changed; 4552 4553 WARN_ON(primary_crtc_state->joiner_pipes != 4554 secondary_crtc_state->joiner_pipes); 4555 4556 return 0; 4557 } 4558 4559 static int 4560 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state, 4561 struct intel_crtc *crtc) 4562 { 4563 struct intel_display *display = to_intel_display(state); 4564 struct intel_crtc_state *crtc_state = 4565 intel_atomic_get_new_crtc_state(state, crtc); 4566 struct intel_crtc_state *saved_state; 4567 4568 saved_state = intel_crtc_state_alloc(crtc); 4569 if (!saved_state) 4570 return -ENOMEM; 4571 4572 /* free the old crtc_state->hw members */ 4573 intel_crtc_free_hw_state(crtc_state); 4574 4575 intel_dp_tunnel_atomic_clear_stream_bw(state, crtc_state); 4576 4577 /* FIXME: before the switch to atomic started, a new pipe_config was 4578 * kzalloc'd. Code that depends on any field being zero should be 4579 * fixed, so that the crtc_state can be safely duplicated. For now, 4580 * only fields that are know to not cause problems are preserved. */ 4581 4582 saved_state->uapi = crtc_state->uapi; 4583 saved_state->inherited = crtc_state->inherited; 4584 saved_state->scaler_state = crtc_state->scaler_state; 4585 saved_state->intel_dpll = crtc_state->intel_dpll; 4586 saved_state->dpll_hw_state = crtc_state->dpll_hw_state; 4587 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls, 4588 sizeof(saved_state->icl_port_dplls)); 4589 saved_state->crc_enabled = crtc_state->crc_enabled; 4590 if (display->platform.g4x || 4591 display->platform.valleyview || display->platform.cherryview) 4592 saved_state->wm = crtc_state->wm; 4593 4594 memcpy(crtc_state, saved_state, sizeof(*crtc_state)); 4595 kfree(saved_state); 4596 4597 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc); 4598 4599 return 0; 4600 } 4601 4602 static int 4603 intel_modeset_pipe_config(struct intel_atomic_state *state, 4604 struct intel_crtc *crtc, 4605 const struct intel_link_bw_limits *limits) 4606 { 4607 struct intel_display *display = to_intel_display(crtc); 4608 struct intel_crtc_state *crtc_state = 4609 intel_atomic_get_new_crtc_state(state, crtc); 4610 struct drm_connector *connector; 4611 struct drm_connector_state *connector_state; 4612 int pipe_src_w, pipe_src_h; 4613 int base_bpp, ret, i; 4614 4615 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe; 4616 4617 crtc_state->framestart_delay = 1; 4618 4619 /* 4620 * Sanitize sync polarity flags based on requested ones. If neither 4621 * positive or negative polarity is requested, treat this as meaning 4622 * negative polarity. 4623 */ 4624 if (!(crtc_state->hw.adjusted_mode.flags & 4625 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) 4626 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; 4627 4628 if (!(crtc_state->hw.adjusted_mode.flags & 4629 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) 4630 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; 4631 4632 ret = compute_baseline_pipe_bpp(state, crtc); 4633 if (ret) 4634 return ret; 4635 4636 crtc_state->fec_enable = limits->force_fec_pipes & BIT(crtc->pipe); 4637 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe]; 4638 4639 if (crtc_state->pipe_bpp > fxp_q4_to_int(crtc_state->max_link_bpp_x16)) { 4640 drm_dbg_kms(display->drm, 4641 "[CRTC:%d:%s] Link bpp limited to " FXP_Q4_FMT "\n", 4642 crtc->base.base.id, crtc->base.name, 4643 FXP_Q4_ARGS(crtc_state->max_link_bpp_x16)); 4644 crtc_state->bw_constrained = true; 4645 } 4646 4647 base_bpp = crtc_state->pipe_bpp; 4648 4649 /* 4650 * Determine the real pipe dimensions. Note that stereo modes can 4651 * increase the actual pipe size due to the frame doubling and 4652 * insertion of additional space for blanks between the frame. This 4653 * is stored in the crtc timings. We use the requested mode to do this 4654 * computation to clearly distinguish it from the adjusted mode, which 4655 * can be changed by the connectors in the below retry loop. 4656 */ 4657 drm_mode_get_hv_timing(&crtc_state->hw.mode, 4658 &pipe_src_w, &pipe_src_h); 4659 drm_rect_init(&crtc_state->pipe_src, 0, 0, 4660 pipe_src_w, pipe_src_h); 4661 4662 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 4663 struct intel_encoder *encoder = 4664 to_intel_encoder(connector_state->best_encoder); 4665 4666 if (connector_state->crtc != &crtc->base) 4667 continue; 4668 4669 if (!check_single_encoder_cloning(state, crtc, encoder)) { 4670 drm_dbg_kms(display->drm, 4671 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n", 4672 encoder->base.base.id, encoder->base.name); 4673 return -EINVAL; 4674 } 4675 4676 /* 4677 * Determine output_types before calling the .compute_config() 4678 * hooks so that the hooks can use this information safely. 4679 */ 4680 if (encoder->compute_output_type) 4681 crtc_state->output_types |= 4682 BIT(encoder->compute_output_type(encoder, crtc_state, 4683 connector_state)); 4684 else 4685 crtc_state->output_types |= BIT(encoder->type); 4686 } 4687 4688 /* Ensure the port clock defaults are reset when retrying. */ 4689 crtc_state->port_clock = 0; 4690 crtc_state->pixel_multiplier = 1; 4691 4692 /* Fill in default crtc timings, allow encoders to overwrite them. */ 4693 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode, 4694 CRTC_STEREO_DOUBLE); 4695 4696 /* Pass our mode to the connectors and the CRTC to give them a chance to 4697 * adjust it according to limitations or connector properties, and also 4698 * a chance to reject the mode entirely. 4699 */ 4700 for_each_new_connector_in_state(&state->base, connector, connector_state, i) { 4701 struct intel_encoder *encoder = 4702 to_intel_encoder(connector_state->best_encoder); 4703 4704 if (connector_state->crtc != &crtc->base) 4705 continue; 4706 4707 ret = encoder->compute_config(encoder, crtc_state, 4708 connector_state); 4709 if (ret == -EDEADLK) 4710 return ret; 4711 if (ret < 0) { 4712 drm_dbg_kms(display->drm, "[ENCODER:%d:%s] config failure: %d\n", 4713 encoder->base.base.id, encoder->base.name, ret); 4714 return ret; 4715 } 4716 } 4717 4718 /* Set default port clock if not overwritten by the encoder. Needs to be 4719 * done afterwards in case the encoder adjusts the mode. */ 4720 if (!crtc_state->port_clock) 4721 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock 4722 * crtc_state->pixel_multiplier; 4723 4724 ret = intel_crtc_compute_config(state, crtc); 4725 if (ret == -EDEADLK) 4726 return ret; 4727 if (ret < 0) { 4728 drm_dbg_kms(display->drm, "[CRTC:%d:%s] config failure: %d\n", 4729 crtc->base.base.id, crtc->base.name, ret); 4730 return ret; 4731 } 4732 4733 /* Dithering seems to not pass-through bits correctly when it should, so 4734 * only enable it on 6bpc panels and when its not a compliance 4735 * test requesting 6bpc video pattern. 4736 */ 4737 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) && 4738 !crtc_state->dither_force_disable; 4739 drm_dbg_kms(display->drm, 4740 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n", 4741 crtc->base.base.id, crtc->base.name, 4742 base_bpp, crtc_state->pipe_bpp, crtc_state->dither); 4743 4744 return 0; 4745 } 4746 4747 static int 4748 intel_modeset_pipe_config_late(struct intel_atomic_state *state, 4749 struct intel_crtc *crtc) 4750 { 4751 struct intel_crtc_state *crtc_state = 4752 intel_atomic_get_new_crtc_state(state, crtc); 4753 struct drm_connector_state *conn_state; 4754 struct drm_connector *connector; 4755 int i; 4756 4757 intel_vrr_compute_config_late(crtc_state); 4758 4759 for_each_new_connector_in_state(&state->base, connector, 4760 conn_state, i) { 4761 struct intel_encoder *encoder = 4762 to_intel_encoder(conn_state->best_encoder); 4763 int ret; 4764 4765 if (conn_state->crtc != &crtc->base || 4766 !encoder->compute_config_late) 4767 continue; 4768 4769 ret = encoder->compute_config_late(encoder, crtc_state, 4770 conn_state); 4771 if (ret) 4772 return ret; 4773 } 4774 4775 return 0; 4776 } 4777 4778 bool intel_fuzzy_clock_check(int clock1, int clock2) 4779 { 4780 int diff; 4781 4782 if (clock1 == clock2) 4783 return true; 4784 4785 if (!clock1 || !clock2) 4786 return false; 4787 4788 diff = abs(clock1 - clock2); 4789 4790 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) 4791 return true; 4792 4793 return false; 4794 } 4795 4796 static bool 4797 intel_compare_link_m_n(const struct intel_link_m_n *m_n, 4798 const struct intel_link_m_n *m2_n2) 4799 { 4800 return m_n->tu == m2_n2->tu && 4801 m_n->data_m == m2_n2->data_m && 4802 m_n->data_n == m2_n2->data_n && 4803 m_n->link_m == m2_n2->link_m && 4804 m_n->link_n == m2_n2->link_n; 4805 } 4806 4807 static bool 4808 intel_compare_infoframe(const union hdmi_infoframe *a, 4809 const union hdmi_infoframe *b) 4810 { 4811 return memcmp(a, b, sizeof(*a)) == 0; 4812 } 4813 4814 static bool 4815 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a, 4816 const struct drm_dp_vsc_sdp *b) 4817 { 4818 return a->pixelformat == b->pixelformat && 4819 a->colorimetry == b->colorimetry && 4820 a->bpc == b->bpc && 4821 a->dynamic_range == b->dynamic_range && 4822 a->content_type == b->content_type; 4823 } 4824 4825 static bool 4826 intel_compare_dp_as_sdp(const struct drm_dp_as_sdp *a, 4827 const struct drm_dp_as_sdp *b) 4828 { 4829 return a->vtotal == b->vtotal && 4830 a->target_rr == b->target_rr && 4831 a->duration_incr_ms == b->duration_incr_ms && 4832 a->duration_decr_ms == b->duration_decr_ms && 4833 a->mode == b->mode; 4834 } 4835 4836 static bool 4837 intel_compare_buffer(const u8 *a, const u8 *b, size_t len) 4838 { 4839 return memcmp(a, b, len) == 0; 4840 } 4841 4842 static void __printf(5, 6) 4843 pipe_config_mismatch(struct drm_printer *p, bool fastset, 4844 const struct intel_crtc *crtc, 4845 const char *name, const char *format, ...) 4846 { 4847 struct va_format vaf; 4848 va_list args; 4849 4850 va_start(args, format); 4851 vaf.fmt = format; 4852 vaf.va = &args; 4853 4854 if (fastset) 4855 drm_printf(p, "[CRTC:%d:%s] fastset requirement not met in %s %pV\n", 4856 crtc->base.base.id, crtc->base.name, name, &vaf); 4857 else 4858 drm_printf(p, "[CRTC:%d:%s] mismatch in %s %pV\n", 4859 crtc->base.base.id, crtc->base.name, name, &vaf); 4860 4861 va_end(args); 4862 } 4863 4864 static void 4865 pipe_config_infoframe_mismatch(struct drm_printer *p, bool fastset, 4866 const struct intel_crtc *crtc, 4867 const char *name, 4868 const union hdmi_infoframe *a, 4869 const union hdmi_infoframe *b) 4870 { 4871 struct intel_display *display = to_intel_display(crtc); 4872 const char *loglevel; 4873 4874 if (fastset) { 4875 if (!drm_debug_enabled(DRM_UT_KMS)) 4876 return; 4877 4878 loglevel = KERN_DEBUG; 4879 } else { 4880 loglevel = KERN_ERR; 4881 } 4882 4883 pipe_config_mismatch(p, fastset, crtc, name, "infoframe"); 4884 4885 drm_printf(p, "expected:\n"); 4886 hdmi_infoframe_log(loglevel, display->drm->dev, a); 4887 drm_printf(p, "found:\n"); 4888 hdmi_infoframe_log(loglevel, display->drm->dev, b); 4889 } 4890 4891 static void 4892 pipe_config_dp_vsc_sdp_mismatch(struct drm_printer *p, bool fastset, 4893 const struct intel_crtc *crtc, 4894 const char *name, 4895 const struct drm_dp_vsc_sdp *a, 4896 const struct drm_dp_vsc_sdp *b) 4897 { 4898 pipe_config_mismatch(p, fastset, crtc, name, "dp vsc sdp"); 4899 4900 drm_printf(p, "expected:\n"); 4901 drm_dp_vsc_sdp_log(p, a); 4902 drm_printf(p, "found:\n"); 4903 drm_dp_vsc_sdp_log(p, b); 4904 } 4905 4906 static void 4907 pipe_config_dp_as_sdp_mismatch(struct drm_printer *p, bool fastset, 4908 const struct intel_crtc *crtc, 4909 const char *name, 4910 const struct drm_dp_as_sdp *a, 4911 const struct drm_dp_as_sdp *b) 4912 { 4913 pipe_config_mismatch(p, fastset, crtc, name, "dp as sdp"); 4914 4915 drm_printf(p, "expected:\n"); 4916 drm_dp_as_sdp_log(p, a); 4917 drm_printf(p, "found:\n"); 4918 drm_dp_as_sdp_log(p, b); 4919 } 4920 4921 /* Returns the length up to and including the last differing byte */ 4922 static size_t 4923 memcmp_diff_len(const u8 *a, const u8 *b, size_t len) 4924 { 4925 int i; 4926 4927 for (i = len - 1; i >= 0; i--) { 4928 if (a[i] != b[i]) 4929 return i + 1; 4930 } 4931 4932 return 0; 4933 } 4934 4935 static void 4936 pipe_config_buffer_mismatch(struct drm_printer *p, bool fastset, 4937 const struct intel_crtc *crtc, 4938 const char *name, 4939 const u8 *a, const u8 *b, size_t len) 4940 { 4941 pipe_config_mismatch(p, fastset, crtc, name, "buffer"); 4942 4943 /* only dump up to the last difference */ 4944 len = memcmp_diff_len(a, b, len); 4945 4946 drm_print_hex_dump(p, "expected: ", a, len); 4947 drm_print_hex_dump(p, "found: ", b, len); 4948 } 4949 4950 static void 4951 pipe_config_pll_mismatch(struct drm_printer *p, bool fastset, 4952 const struct intel_crtc *crtc, 4953 const char *name, 4954 const struct intel_dpll_hw_state *a, 4955 const struct intel_dpll_hw_state *b) 4956 { 4957 struct intel_display *display = to_intel_display(crtc); 4958 4959 pipe_config_mismatch(p, fastset, crtc, name, " "); /* stupid -Werror=format-zero-length */ 4960 4961 drm_printf(p, "expected:\n"); 4962 intel_dpll_dump_hw_state(display, p, a); 4963 drm_printf(p, "found:\n"); 4964 intel_dpll_dump_hw_state(display, p, b); 4965 } 4966 4967 static void 4968 pipe_config_cx0pll_mismatch(struct drm_printer *p, bool fastset, 4969 const struct intel_crtc *crtc, 4970 const char *name, 4971 const struct intel_cx0pll_state *a, 4972 const struct intel_cx0pll_state *b) 4973 { 4974 struct intel_display *display = to_intel_display(crtc); 4975 char *chipname = a->use_c10 ? "C10" : "C20"; 4976 4977 pipe_config_mismatch(p, fastset, crtc, name, chipname); 4978 4979 drm_printf(p, "expected:\n"); 4980 intel_cx0pll_dump_hw_state(display, a); 4981 drm_printf(p, "found:\n"); 4982 intel_cx0pll_dump_hw_state(display, b); 4983 } 4984 4985 static bool allow_vblank_delay_fastset(const struct intel_crtc_state *old_crtc_state) 4986 { 4987 struct intel_display *display = to_intel_display(old_crtc_state); 4988 4989 /* 4990 * Allow fastboot to fix up vblank delay (handled via LRR 4991 * codepaths), a bit dodgy as the registers aren't 4992 * double buffered but seems to be working more or less... 4993 */ 4994 return HAS_LRR(display) && old_crtc_state->inherited && 4995 !intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI); 4996 } 4997 4998 bool 4999 intel_pipe_config_compare(const struct intel_crtc_state *current_config, 5000 const struct intel_crtc_state *pipe_config, 5001 bool fastset) 5002 { 5003 struct intel_display *display = to_intel_display(current_config); 5004 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 5005 struct drm_printer p; 5006 u32 exclude_infoframes = 0; 5007 bool ret = true; 5008 5009 if (fastset) 5010 p = drm_dbg_printer(display->drm, DRM_UT_KMS, NULL); 5011 else 5012 p = drm_err_printer(display->drm, NULL); 5013 5014 #define PIPE_CONF_CHECK_X(name) do { \ 5015 if (current_config->name != pipe_config->name) { \ 5016 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \ 5017 __stringify(name) " is bool"); \ 5018 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5019 "(expected 0x%08x, found 0x%08x)", \ 5020 current_config->name, \ 5021 pipe_config->name); \ 5022 ret = false; \ 5023 } \ 5024 } while (0) 5025 5026 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \ 5027 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \ 5028 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \ 5029 __stringify(name) " is bool"); \ 5030 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5031 "(expected 0x%08x, found 0x%08x)", \ 5032 current_config->name & (mask), \ 5033 pipe_config->name & (mask)); \ 5034 ret = false; \ 5035 } \ 5036 } while (0) 5037 5038 #define PIPE_CONF_CHECK_I(name) do { \ 5039 if (current_config->name != pipe_config->name) { \ 5040 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \ 5041 __stringify(name) " is bool"); \ 5042 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5043 "(expected %i, found %i)", \ 5044 current_config->name, \ 5045 pipe_config->name); \ 5046 ret = false; \ 5047 } \ 5048 } while (0) 5049 5050 #define PIPE_CONF_CHECK_LLI(name) do { \ 5051 if (current_config->name != pipe_config->name) { \ 5052 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5053 "(expected %lli, found %lli)", \ 5054 current_config->name, \ 5055 pipe_config->name); \ 5056 ret = false; \ 5057 } \ 5058 } while (0) 5059 5060 #define PIPE_CONF_CHECK_BOOL(name) do { \ 5061 if (current_config->name != pipe_config->name) { \ 5062 BUILD_BUG_ON_MSG(!__same_type(current_config->name, bool), \ 5063 __stringify(name) " is not bool"); \ 5064 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5065 "(expected %s, found %s)", \ 5066 str_yes_no(current_config->name), \ 5067 str_yes_no(pipe_config->name)); \ 5068 ret = false; \ 5069 } \ 5070 } while (0) 5071 5072 #define PIPE_CONF_CHECK_P(name) do { \ 5073 if (current_config->name != pipe_config->name) { \ 5074 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5075 "(expected %p, found %p)", \ 5076 current_config->name, \ 5077 pipe_config->name); \ 5078 ret = false; \ 5079 } \ 5080 } while (0) 5081 5082 #define PIPE_CONF_CHECK_M_N(name) do { \ 5083 if (!intel_compare_link_m_n(¤t_config->name, \ 5084 &pipe_config->name)) { \ 5085 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5086 "(expected tu %i data %i/%i link %i/%i, " \ 5087 "found tu %i, data %i/%i link %i/%i)", \ 5088 current_config->name.tu, \ 5089 current_config->name.data_m, \ 5090 current_config->name.data_n, \ 5091 current_config->name.link_m, \ 5092 current_config->name.link_n, \ 5093 pipe_config->name.tu, \ 5094 pipe_config->name.data_m, \ 5095 pipe_config->name.data_n, \ 5096 pipe_config->name.link_m, \ 5097 pipe_config->name.link_n); \ 5098 ret = false; \ 5099 } \ 5100 } while (0) 5101 5102 #define PIPE_CONF_CHECK_PLL(name) do { \ 5103 if (!intel_dpll_compare_hw_state(display, ¤t_config->name, \ 5104 &pipe_config->name)) { \ 5105 pipe_config_pll_mismatch(&p, fastset, crtc, __stringify(name), \ 5106 ¤t_config->name, \ 5107 &pipe_config->name); \ 5108 ret = false; \ 5109 } \ 5110 } while (0) 5111 5112 #define PIPE_CONF_CHECK_PLL_CX0(name) do { \ 5113 if (!intel_cx0pll_compare_hw_state(¤t_config->name, \ 5114 &pipe_config->name)) { \ 5115 pipe_config_cx0pll_mismatch(&p, fastset, crtc, __stringify(name), \ 5116 ¤t_config->name, \ 5117 &pipe_config->name); \ 5118 ret = false; \ 5119 } \ 5120 } while (0) 5121 5122 #define PIPE_CONF_CHECK_TIMINGS(name) do { \ 5123 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \ 5124 PIPE_CONF_CHECK_I(name.crtc_htotal); \ 5125 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \ 5126 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \ 5127 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \ 5128 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \ 5129 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \ 5130 if (!fastset || !allow_vblank_delay_fastset(current_config)) \ 5131 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \ 5132 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \ 5133 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \ 5134 if (!fastset || !pipe_config->update_lrr) { \ 5135 PIPE_CONF_CHECK_I(name.crtc_vtotal); \ 5136 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \ 5137 } \ 5138 } while (0) 5139 5140 #define PIPE_CONF_CHECK_RECT(name) do { \ 5141 PIPE_CONF_CHECK_I(name.x1); \ 5142 PIPE_CONF_CHECK_I(name.x2); \ 5143 PIPE_CONF_CHECK_I(name.y1); \ 5144 PIPE_CONF_CHECK_I(name.y2); \ 5145 } while (0) 5146 5147 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \ 5148 if ((current_config->name ^ pipe_config->name) & (mask)) { \ 5149 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \ 5150 "(%x) (expected %i, found %i)", \ 5151 (mask), \ 5152 current_config->name & (mask), \ 5153 pipe_config->name & (mask)); \ 5154 ret = false; \ 5155 } \ 5156 } while (0) 5157 5158 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \ 5159 if (!intel_compare_infoframe(¤t_config->infoframes.name, \ 5160 &pipe_config->infoframes.name)) { \ 5161 pipe_config_infoframe_mismatch(&p, fastset, crtc, __stringify(name), \ 5162 ¤t_config->infoframes.name, \ 5163 &pipe_config->infoframes.name); \ 5164 ret = false; \ 5165 } \ 5166 } while (0) 5167 5168 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \ 5169 if (!intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \ 5170 &pipe_config->infoframes.name)) { \ 5171 pipe_config_dp_vsc_sdp_mismatch(&p, fastset, crtc, __stringify(name), \ 5172 ¤t_config->infoframes.name, \ 5173 &pipe_config->infoframes.name); \ 5174 ret = false; \ 5175 } \ 5176 } while (0) 5177 5178 #define PIPE_CONF_CHECK_DP_AS_SDP(name) do { \ 5179 if (!intel_compare_dp_as_sdp(¤t_config->infoframes.name, \ 5180 &pipe_config->infoframes.name)) { \ 5181 pipe_config_dp_as_sdp_mismatch(&p, fastset, crtc, __stringify(name), \ 5182 ¤t_config->infoframes.name, \ 5183 &pipe_config->infoframes.name); \ 5184 ret = false; \ 5185 } \ 5186 } while (0) 5187 5188 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \ 5189 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \ 5190 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \ 5191 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \ 5192 pipe_config_buffer_mismatch(&p, fastset, crtc, __stringify(name), \ 5193 current_config->name, \ 5194 pipe_config->name, \ 5195 (len)); \ 5196 ret = false; \ 5197 } \ 5198 } while (0) 5199 5200 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \ 5201 if (current_config->gamma_mode == pipe_config->gamma_mode && \ 5202 !intel_color_lut_equal(current_config, \ 5203 current_config->lut, pipe_config->lut, \ 5204 is_pre_csc_lut)) { \ 5205 pipe_config_mismatch(&p, fastset, crtc, __stringify(lut), \ 5206 "hw_state doesn't match sw_state"); \ 5207 ret = false; \ 5208 } \ 5209 } while (0) 5210 5211 #define PIPE_CONF_CHECK_CSC(name) do { \ 5212 PIPE_CONF_CHECK_X(name.preoff[0]); \ 5213 PIPE_CONF_CHECK_X(name.preoff[1]); \ 5214 PIPE_CONF_CHECK_X(name.preoff[2]); \ 5215 PIPE_CONF_CHECK_X(name.coeff[0]); \ 5216 PIPE_CONF_CHECK_X(name.coeff[1]); \ 5217 PIPE_CONF_CHECK_X(name.coeff[2]); \ 5218 PIPE_CONF_CHECK_X(name.coeff[3]); \ 5219 PIPE_CONF_CHECK_X(name.coeff[4]); \ 5220 PIPE_CONF_CHECK_X(name.coeff[5]); \ 5221 PIPE_CONF_CHECK_X(name.coeff[6]); \ 5222 PIPE_CONF_CHECK_X(name.coeff[7]); \ 5223 PIPE_CONF_CHECK_X(name.coeff[8]); \ 5224 PIPE_CONF_CHECK_X(name.postoff[0]); \ 5225 PIPE_CONF_CHECK_X(name.postoff[1]); \ 5226 PIPE_CONF_CHECK_X(name.postoff[2]); \ 5227 } while (0) 5228 5229 #define PIPE_CONF_QUIRK(quirk) \ 5230 ((current_config->quirks | pipe_config->quirks) & (quirk)) 5231 5232 PIPE_CONF_CHECK_BOOL(hw.enable); 5233 PIPE_CONF_CHECK_BOOL(hw.active); 5234 5235 PIPE_CONF_CHECK_I(cpu_transcoder); 5236 PIPE_CONF_CHECK_I(mst_master_transcoder); 5237 5238 PIPE_CONF_CHECK_BOOL(has_pch_encoder); 5239 PIPE_CONF_CHECK_I(fdi_lanes); 5240 PIPE_CONF_CHECK_M_N(fdi_m_n); 5241 5242 PIPE_CONF_CHECK_I(lane_count); 5243 PIPE_CONF_CHECK_X(lane_lat_optim_mask); 5244 5245 PIPE_CONF_CHECK_I(min_hblank); 5246 5247 if (HAS_DOUBLE_BUFFERED_M_N(display)) { 5248 if (!fastset || !pipe_config->update_m_n) 5249 PIPE_CONF_CHECK_M_N(dp_m_n); 5250 } else { 5251 PIPE_CONF_CHECK_M_N(dp_m_n); 5252 PIPE_CONF_CHECK_M_N(dp_m2_n2); 5253 } 5254 5255 PIPE_CONF_CHECK_X(output_types); 5256 5257 PIPE_CONF_CHECK_I(framestart_delay); 5258 PIPE_CONF_CHECK_I(msa_timing_delay); 5259 5260 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode); 5261 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode); 5262 5263 PIPE_CONF_CHECK_I(pixel_multiplier); 5264 5265 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 5266 DRM_MODE_FLAG_INTERLACE); 5267 5268 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { 5269 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 5270 DRM_MODE_FLAG_PHSYNC); 5271 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 5272 DRM_MODE_FLAG_NHSYNC); 5273 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 5274 DRM_MODE_FLAG_PVSYNC); 5275 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags, 5276 DRM_MODE_FLAG_NVSYNC); 5277 } 5278 5279 PIPE_CONF_CHECK_I(output_format); 5280 PIPE_CONF_CHECK_BOOL(has_hdmi_sink); 5281 if ((DISPLAY_VER(display) < 8 && !display->platform.haswell) || 5282 display->platform.valleyview || display->platform.cherryview) 5283 PIPE_CONF_CHECK_BOOL(limited_color_range); 5284 5285 PIPE_CONF_CHECK_BOOL(hdmi_scrambling); 5286 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio); 5287 PIPE_CONF_CHECK_BOOL(has_infoframe); 5288 PIPE_CONF_CHECK_BOOL(enhanced_framing); 5289 PIPE_CONF_CHECK_BOOL(fec_enable); 5290 5291 if (!fastset) { 5292 PIPE_CONF_CHECK_BOOL(has_audio); 5293 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES); 5294 } 5295 5296 PIPE_CONF_CHECK_X(gmch_pfit.control); 5297 /* pfit ratios are autocomputed by the hw on gen4+ */ 5298 if (DISPLAY_VER(display) < 4) 5299 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); 5300 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); 5301 5302 /* 5303 * Changing the EDP transcoder input mux 5304 * (A_ONOFF vs. A_ON) requires a full modeset. 5305 */ 5306 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru); 5307 5308 if (!fastset) { 5309 PIPE_CONF_CHECK_RECT(pipe_src); 5310 5311 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled); 5312 PIPE_CONF_CHECK_RECT(pch_pfit.dst); 5313 5314 PIPE_CONF_CHECK_I(scaler_state.scaler_id); 5315 PIPE_CONF_CHECK_I(pixel_rate); 5316 5317 PIPE_CONF_CHECK_X(gamma_mode); 5318 if (display->platform.cherryview) 5319 PIPE_CONF_CHECK_X(cgm_mode); 5320 else 5321 PIPE_CONF_CHECK_X(csc_mode); 5322 PIPE_CONF_CHECK_BOOL(gamma_enable); 5323 PIPE_CONF_CHECK_BOOL(csc_enable); 5324 PIPE_CONF_CHECK_BOOL(wgc_enable); 5325 5326 PIPE_CONF_CHECK_I(linetime); 5327 PIPE_CONF_CHECK_I(ips_linetime); 5328 5329 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true); 5330 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false); 5331 5332 PIPE_CONF_CHECK_CSC(csc); 5333 PIPE_CONF_CHECK_CSC(output_csc); 5334 } 5335 5336 PIPE_CONF_CHECK_BOOL(double_wide); 5337 5338 if (display->dpll.mgr) 5339 PIPE_CONF_CHECK_P(intel_dpll); 5340 5341 /* FIXME convert everything over the dpll_mgr */ 5342 if (display->dpll.mgr || HAS_GMCH(display)) 5343 PIPE_CONF_CHECK_PLL(dpll_hw_state); 5344 5345 /* FIXME convert MTL+ platforms over to dpll_mgr */ 5346 if (DISPLAY_VER(display) >= 14) 5347 PIPE_CONF_CHECK_PLL_CX0(dpll_hw_state.cx0pll); 5348 5349 PIPE_CONF_CHECK_X(dsi_pll.ctrl); 5350 PIPE_CONF_CHECK_X(dsi_pll.div); 5351 5352 if (display->platform.g4x || DISPLAY_VER(display) >= 5) 5353 PIPE_CONF_CHECK_I(pipe_bpp); 5354 5355 if (!fastset || !pipe_config->update_m_n) { 5356 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock); 5357 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock); 5358 } 5359 PIPE_CONF_CHECK_I(port_clock); 5360 5361 PIPE_CONF_CHECK_I(min_voltage_level); 5362 5363 if (current_config->has_psr || pipe_config->has_psr) 5364 exclude_infoframes |= intel_hdmi_infoframe_enable(DP_SDP_VSC); 5365 5366 if (current_config->vrr.enable || pipe_config->vrr.enable) 5367 exclude_infoframes |= intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC); 5368 5369 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable, ~exclude_infoframes); 5370 PIPE_CONF_CHECK_X(infoframes.gcp); 5371 PIPE_CONF_CHECK_INFOFRAME(avi); 5372 PIPE_CONF_CHECK_INFOFRAME(spd); 5373 PIPE_CONF_CHECK_INFOFRAME(hdmi); 5374 if (!fastset) { 5375 PIPE_CONF_CHECK_INFOFRAME(drm); 5376 PIPE_CONF_CHECK_DP_AS_SDP(as_sdp); 5377 } 5378 PIPE_CONF_CHECK_DP_VSC_SDP(vsc); 5379 5380 PIPE_CONF_CHECK_X(sync_mode_slaves_mask); 5381 PIPE_CONF_CHECK_I(master_transcoder); 5382 PIPE_CONF_CHECK_X(joiner_pipes); 5383 5384 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable); 5385 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb); 5386 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422); 5387 PIPE_CONF_CHECK_BOOL(dsc.config.native_422); 5388 PIPE_CONF_CHECK_BOOL(dsc.config.native_420); 5389 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable); 5390 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth); 5391 PIPE_CONF_CHECK_I(dsc.config.bits_per_component); 5392 PIPE_CONF_CHECK_I(dsc.config.pic_width); 5393 PIPE_CONF_CHECK_I(dsc.config.pic_height); 5394 PIPE_CONF_CHECK_I(dsc.config.slice_width); 5395 PIPE_CONF_CHECK_I(dsc.config.slice_height); 5396 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay); 5397 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay); 5398 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval); 5399 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval); 5400 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value); 5401 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset); 5402 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp); 5403 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp); 5404 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset); 5405 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset); 5406 PIPE_CONF_CHECK_I(dsc.config.initial_offset); 5407 PIPE_CONF_CHECK_I(dsc.config.final_offset); 5408 PIPE_CONF_CHECK_I(dsc.config.rc_model_size); 5409 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0); 5410 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1); 5411 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size); 5412 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset); 5413 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset); 5414 5415 PIPE_CONF_CHECK_BOOL(dsc.compression_enable); 5416 PIPE_CONF_CHECK_I(dsc.num_streams); 5417 PIPE_CONF_CHECK_I(dsc.compressed_bpp_x16); 5418 5419 PIPE_CONF_CHECK_BOOL(splitter.enable); 5420 PIPE_CONF_CHECK_I(splitter.link_count); 5421 PIPE_CONF_CHECK_I(splitter.pixel_overlap); 5422 5423 if (!fastset) { 5424 PIPE_CONF_CHECK_BOOL(vrr.enable); 5425 PIPE_CONF_CHECK_I(vrr.vmin); 5426 PIPE_CONF_CHECK_I(vrr.vmax); 5427 PIPE_CONF_CHECK_I(vrr.flipline); 5428 PIPE_CONF_CHECK_I(vrr.vsync_start); 5429 PIPE_CONF_CHECK_I(vrr.vsync_end); 5430 PIPE_CONF_CHECK_LLI(cmrr.cmrr_m); 5431 PIPE_CONF_CHECK_LLI(cmrr.cmrr_n); 5432 PIPE_CONF_CHECK_BOOL(cmrr.enable); 5433 } 5434 5435 if (!fastset || intel_vrr_always_use_vrr_tg(display)) { 5436 PIPE_CONF_CHECK_I(vrr.pipeline_full); 5437 PIPE_CONF_CHECK_I(vrr.guardband); 5438 } 5439 5440 #undef PIPE_CONF_CHECK_X 5441 #undef PIPE_CONF_CHECK_I 5442 #undef PIPE_CONF_CHECK_LLI 5443 #undef PIPE_CONF_CHECK_BOOL 5444 #undef PIPE_CONF_CHECK_P 5445 #undef PIPE_CONF_CHECK_FLAGS 5446 #undef PIPE_CONF_CHECK_COLOR_LUT 5447 #undef PIPE_CONF_CHECK_TIMINGS 5448 #undef PIPE_CONF_CHECK_RECT 5449 #undef PIPE_CONF_QUIRK 5450 5451 return ret; 5452 } 5453 5454 static void 5455 intel_verify_planes(struct intel_atomic_state *state) 5456 { 5457 struct intel_plane *plane; 5458 const struct intel_plane_state *plane_state; 5459 int i; 5460 5461 for_each_new_intel_plane_in_state(state, plane, 5462 plane_state, i) 5463 assert_plane(plane, plane_state->is_y_plane || 5464 plane_state->uapi.visible); 5465 } 5466 5467 static int intel_modeset_pipe(struct intel_atomic_state *state, 5468 struct intel_crtc_state *crtc_state, 5469 const char *reason) 5470 { 5471 struct intel_display *display = to_intel_display(state); 5472 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 5473 int ret; 5474 5475 drm_dbg_kms(display->drm, "[CRTC:%d:%s] Full modeset due to %s\n", 5476 crtc->base.base.id, crtc->base.name, reason); 5477 5478 ret = drm_atomic_add_affected_connectors(&state->base, 5479 &crtc->base); 5480 if (ret) 5481 return ret; 5482 5483 ret = intel_dp_tunnel_atomic_add_state_for_crtc(state, crtc); 5484 if (ret) 5485 return ret; 5486 5487 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc); 5488 if (ret) 5489 return ret; 5490 5491 ret = intel_plane_add_affected(state, crtc); 5492 if (ret) 5493 return ret; 5494 5495 crtc_state->uapi.mode_changed = true; 5496 5497 return 0; 5498 } 5499 5500 /** 5501 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes 5502 * @state: intel atomic state 5503 * @reason: the reason for the full modeset 5504 * @mask: mask of pipes to modeset 5505 * 5506 * Add pipes in @mask to @state and force a full modeset on the enabled ones 5507 * due to the description in @reason. 5508 * This function can be called only before new plane states are computed. 5509 * 5510 * Returns 0 in case of success, negative error code otherwise. 5511 */ 5512 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state, 5513 const char *reason, u8 mask) 5514 { 5515 struct intel_display *display = to_intel_display(state); 5516 struct intel_crtc *crtc; 5517 5518 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, mask) { 5519 struct intel_crtc_state *crtc_state; 5520 int ret; 5521 5522 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 5523 if (IS_ERR(crtc_state)) 5524 return PTR_ERR(crtc_state); 5525 5526 if (!crtc_state->hw.enable || 5527 intel_crtc_needs_modeset(crtc_state)) 5528 continue; 5529 5530 ret = intel_modeset_pipe(state, crtc_state, reason); 5531 if (ret) 5532 return ret; 5533 } 5534 5535 return 0; 5536 } 5537 5538 static void 5539 intel_crtc_flag_modeset(struct intel_crtc_state *crtc_state) 5540 { 5541 crtc_state->uapi.mode_changed = true; 5542 5543 crtc_state->update_pipe = false; 5544 crtc_state->update_m_n = false; 5545 crtc_state->update_lrr = false; 5546 } 5547 5548 /** 5549 * intel_modeset_all_pipes_late - force a full modeset on all pipes 5550 * @state: intel atomic state 5551 * @reason: the reason for the full modeset 5552 * 5553 * Add all pipes to @state and force a full modeset on the active ones due to 5554 * the description in @reason. 5555 * This function can be called only after new plane states are computed already. 5556 * 5557 * Returns 0 in case of success, negative error code otherwise. 5558 */ 5559 int intel_modeset_all_pipes_late(struct intel_atomic_state *state, 5560 const char *reason) 5561 { 5562 struct intel_display *display = to_intel_display(state); 5563 struct intel_crtc *crtc; 5564 5565 for_each_intel_crtc(display->drm, crtc) { 5566 struct intel_crtc_state *crtc_state; 5567 int ret; 5568 5569 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 5570 if (IS_ERR(crtc_state)) 5571 return PTR_ERR(crtc_state); 5572 5573 if (!crtc_state->hw.active || 5574 intel_crtc_needs_modeset(crtc_state)) 5575 continue; 5576 5577 ret = intel_modeset_pipe(state, crtc_state, reason); 5578 if (ret) 5579 return ret; 5580 5581 intel_crtc_flag_modeset(crtc_state); 5582 5583 crtc_state->update_planes |= crtc_state->active_planes; 5584 crtc_state->async_flip_planes = 0; 5585 crtc_state->do_async_flip = false; 5586 } 5587 5588 return 0; 5589 } 5590 5591 int intel_modeset_commit_pipes(struct intel_display *display, 5592 u8 pipe_mask, 5593 struct drm_modeset_acquire_ctx *ctx) 5594 { 5595 struct drm_atomic_state *state; 5596 struct intel_crtc *crtc; 5597 int ret; 5598 5599 state = drm_atomic_state_alloc(display->drm); 5600 if (!state) 5601 return -ENOMEM; 5602 5603 state->acquire_ctx = ctx; 5604 to_intel_atomic_state(state)->internal = true; 5605 5606 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, pipe_mask) { 5607 struct intel_crtc_state *crtc_state = 5608 intel_atomic_get_crtc_state(state, crtc); 5609 5610 if (IS_ERR(crtc_state)) { 5611 ret = PTR_ERR(crtc_state); 5612 goto out; 5613 } 5614 5615 crtc_state->uapi.connectors_changed = true; 5616 } 5617 5618 ret = drm_atomic_commit(state); 5619 out: 5620 drm_atomic_state_put(state); 5621 5622 return ret; 5623 } 5624 5625 /* 5626 * This implements the workaround described in the "notes" section of the mode 5627 * set sequence documentation. When going from no pipes or single pipe to 5628 * multiple pipes, and planes are enabled after the pipe, we need to wait at 5629 * least 2 vblanks on the first pipe before enabling planes on the second pipe. 5630 */ 5631 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state) 5632 { 5633 struct intel_crtc_state *crtc_state; 5634 struct intel_crtc *crtc; 5635 struct intel_crtc_state *first_crtc_state = NULL; 5636 struct intel_crtc_state *other_crtc_state = NULL; 5637 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; 5638 int i; 5639 5640 /* look at all crtc's that are going to be enabled in during modeset */ 5641 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 5642 if (!crtc_state->hw.active || 5643 !intel_crtc_needs_modeset(crtc_state)) 5644 continue; 5645 5646 if (first_crtc_state) { 5647 other_crtc_state = crtc_state; 5648 break; 5649 } else { 5650 first_crtc_state = crtc_state; 5651 first_pipe = crtc->pipe; 5652 } 5653 } 5654 5655 /* No workaround needed? */ 5656 if (!first_crtc_state) 5657 return 0; 5658 5659 /* w/a possibly needed, check how many crtc's are already enabled. */ 5660 for_each_intel_crtc(state->base.dev, crtc) { 5661 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 5662 if (IS_ERR(crtc_state)) 5663 return PTR_ERR(crtc_state); 5664 5665 crtc_state->hsw_workaround_pipe = INVALID_PIPE; 5666 5667 if (!crtc_state->hw.active || 5668 intel_crtc_needs_modeset(crtc_state)) 5669 continue; 5670 5671 /* 2 or more enabled crtcs means no need for w/a */ 5672 if (enabled_pipe != INVALID_PIPE) 5673 return 0; 5674 5675 enabled_pipe = crtc->pipe; 5676 } 5677 5678 if (enabled_pipe != INVALID_PIPE) 5679 first_crtc_state->hsw_workaround_pipe = enabled_pipe; 5680 else if (other_crtc_state) 5681 other_crtc_state->hsw_workaround_pipe = first_pipe; 5682 5683 return 0; 5684 } 5685 5686 u8 intel_calc_active_pipes(struct intel_atomic_state *state, 5687 u8 active_pipes) 5688 { 5689 const struct intel_crtc_state *crtc_state; 5690 struct intel_crtc *crtc; 5691 int i; 5692 5693 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 5694 if (crtc_state->hw.active) 5695 active_pipes |= BIT(crtc->pipe); 5696 else 5697 active_pipes &= ~BIT(crtc->pipe); 5698 } 5699 5700 return active_pipes; 5701 } 5702 5703 static int intel_modeset_checks(struct intel_atomic_state *state) 5704 { 5705 struct intel_display *display = to_intel_display(state); 5706 5707 state->modeset = true; 5708 5709 if (display->platform.haswell) 5710 return hsw_mode_set_planes_workaround(state); 5711 5712 return 0; 5713 } 5714 5715 static bool lrr_params_changed(const struct drm_display_mode *old_adjusted_mode, 5716 const struct drm_display_mode *new_adjusted_mode) 5717 { 5718 return old_adjusted_mode->crtc_vblank_start != new_adjusted_mode->crtc_vblank_start || 5719 old_adjusted_mode->crtc_vblank_end != new_adjusted_mode->crtc_vblank_end || 5720 old_adjusted_mode->crtc_vtotal != new_adjusted_mode->crtc_vtotal; 5721 } 5722 5723 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state, 5724 struct intel_crtc_state *new_crtc_state) 5725 { 5726 struct intel_display *display = to_intel_display(new_crtc_state); 5727 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 5728 5729 /* only allow LRR when the timings stay within the VRR range */ 5730 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range) 5731 new_crtc_state->update_lrr = false; 5732 5733 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true)) { 5734 drm_dbg_kms(display->drm, "[CRTC:%d:%s] fastset requirement not met, forcing full modeset\n", 5735 crtc->base.base.id, crtc->base.name); 5736 } else { 5737 if (allow_vblank_delay_fastset(old_crtc_state)) 5738 new_crtc_state->update_lrr = true; 5739 new_crtc_state->uapi.mode_changed = false; 5740 } 5741 5742 if (intel_compare_link_m_n(&old_crtc_state->dp_m_n, 5743 &new_crtc_state->dp_m_n)) 5744 new_crtc_state->update_m_n = false; 5745 5746 if (!lrr_params_changed(&old_crtc_state->hw.adjusted_mode, 5747 &new_crtc_state->hw.adjusted_mode)) 5748 new_crtc_state->update_lrr = false; 5749 5750 if (intel_crtc_needs_modeset(new_crtc_state)) 5751 intel_crtc_flag_modeset(new_crtc_state); 5752 else 5753 new_crtc_state->update_pipe = true; 5754 } 5755 5756 static int intel_atomic_check_crtcs(struct intel_atomic_state *state) 5757 { 5758 struct intel_display *display = to_intel_display(state); 5759 struct intel_crtc_state __maybe_unused *crtc_state; 5760 struct intel_crtc *crtc; 5761 int i; 5762 5763 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 5764 int ret; 5765 5766 ret = intel_crtc_atomic_check(state, crtc); 5767 if (ret) { 5768 drm_dbg_atomic(display->drm, 5769 "[CRTC:%d:%s] atomic driver check failed\n", 5770 crtc->base.base.id, crtc->base.name); 5771 return ret; 5772 } 5773 } 5774 5775 return 0; 5776 } 5777 5778 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state, 5779 u8 transcoders) 5780 { 5781 const struct intel_crtc_state *new_crtc_state; 5782 struct intel_crtc *crtc; 5783 int i; 5784 5785 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 5786 if (new_crtc_state->hw.enable && 5787 transcoders & BIT(new_crtc_state->cpu_transcoder) && 5788 intel_crtc_needs_modeset(new_crtc_state)) 5789 return true; 5790 } 5791 5792 return false; 5793 } 5794 5795 static bool intel_pipes_need_modeset(struct intel_atomic_state *state, 5796 u8 pipes) 5797 { 5798 const struct intel_crtc_state *new_crtc_state; 5799 struct intel_crtc *crtc; 5800 int i; 5801 5802 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 5803 if (new_crtc_state->hw.enable && 5804 pipes & BIT(crtc->pipe) && 5805 intel_crtc_needs_modeset(new_crtc_state)) 5806 return true; 5807 } 5808 5809 return false; 5810 } 5811 5812 static int intel_atomic_check_joiner(struct intel_atomic_state *state, 5813 struct intel_crtc *primary_crtc) 5814 { 5815 struct intel_display *display = to_intel_display(state); 5816 struct intel_crtc_state *primary_crtc_state = 5817 intel_atomic_get_new_crtc_state(state, primary_crtc); 5818 struct intel_crtc *secondary_crtc; 5819 5820 if (!primary_crtc_state->joiner_pipes) 5821 return 0; 5822 5823 /* sanity check */ 5824 if (drm_WARN_ON(display->drm, 5825 primary_crtc->pipe != joiner_primary_pipe(primary_crtc_state))) 5826 return -EINVAL; 5827 5828 if (primary_crtc_state->joiner_pipes & ~joiner_pipes(display)) { 5829 drm_dbg_kms(display->drm, 5830 "[CRTC:%d:%s] Cannot act as joiner primary " 5831 "(need 0x%x as pipes, only 0x%x possible)\n", 5832 primary_crtc->base.base.id, primary_crtc->base.name, 5833 primary_crtc_state->joiner_pipes, joiner_pipes(display)); 5834 return -EINVAL; 5835 } 5836 5837 for_each_intel_crtc_in_pipe_mask(display->drm, secondary_crtc, 5838 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) { 5839 struct intel_crtc_state *secondary_crtc_state; 5840 int ret; 5841 5842 secondary_crtc_state = intel_atomic_get_crtc_state(&state->base, secondary_crtc); 5843 if (IS_ERR(secondary_crtc_state)) 5844 return PTR_ERR(secondary_crtc_state); 5845 5846 /* primary being enabled, secondary was already configured? */ 5847 if (secondary_crtc_state->uapi.enable) { 5848 drm_dbg_kms(display->drm, 5849 "[CRTC:%d:%s] secondary is enabled as normal CRTC, but " 5850 "[CRTC:%d:%s] claiming this CRTC for joiner.\n", 5851 secondary_crtc->base.base.id, secondary_crtc->base.name, 5852 primary_crtc->base.base.id, primary_crtc->base.name); 5853 return -EINVAL; 5854 } 5855 5856 /* 5857 * The state copy logic assumes the primary crtc gets processed 5858 * before the secondary crtc during the main compute_config loop. 5859 * This works because the crtcs are created in pipe order, 5860 * and the hardware requires primary pipe < secondary pipe as well. 5861 * Should that change we need to rethink the logic. 5862 */ 5863 if (WARN_ON(drm_crtc_index(&primary_crtc->base) > 5864 drm_crtc_index(&secondary_crtc->base))) 5865 return -EINVAL; 5866 5867 drm_dbg_kms(display->drm, 5868 "[CRTC:%d:%s] Used as secondary for joiner primary [CRTC:%d:%s]\n", 5869 secondary_crtc->base.base.id, secondary_crtc->base.name, 5870 primary_crtc->base.base.id, primary_crtc->base.name); 5871 5872 secondary_crtc_state->joiner_pipes = 5873 primary_crtc_state->joiner_pipes; 5874 5875 ret = copy_joiner_crtc_state_modeset(state, secondary_crtc); 5876 if (ret) 5877 return ret; 5878 } 5879 5880 return 0; 5881 } 5882 5883 static void kill_joiner_secondaries(struct intel_atomic_state *state, 5884 struct intel_crtc *primary_crtc) 5885 { 5886 struct intel_display *display = to_intel_display(state); 5887 struct intel_crtc_state *primary_crtc_state = 5888 intel_atomic_get_new_crtc_state(state, primary_crtc); 5889 struct intel_crtc *secondary_crtc; 5890 5891 for_each_intel_crtc_in_pipe_mask(display->drm, secondary_crtc, 5892 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) { 5893 struct intel_crtc_state *secondary_crtc_state = 5894 intel_atomic_get_new_crtc_state(state, secondary_crtc); 5895 5896 secondary_crtc_state->joiner_pipes = 0; 5897 5898 intel_crtc_copy_uapi_to_hw_state_modeset(state, secondary_crtc); 5899 } 5900 5901 primary_crtc_state->joiner_pipes = 0; 5902 } 5903 5904 /** 5905 * DOC: asynchronous flip implementation 5906 * 5907 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC 5908 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL. 5909 * Correspondingly, support is currently added for primary plane only. 5910 * 5911 * Async flip can only change the plane surface address, so anything else 5912 * changing is rejected from the intel_async_flip_check_hw() function. 5913 * Once this check is cleared, flip done interrupt is enabled using 5914 * the intel_crtc_enable_flip_done() function. 5915 * 5916 * As soon as the surface address register is written, flip done interrupt is 5917 * generated and the requested events are sent to the userspace in the interrupt 5918 * handler itself. The timestamp and sequence sent during the flip done event 5919 * correspond to the last vblank and have no relation to the actual time when 5920 * the flip done event was sent. 5921 */ 5922 static int intel_async_flip_check_uapi(struct intel_atomic_state *state, 5923 struct intel_crtc *crtc) 5924 { 5925 struct intel_display *display = to_intel_display(state); 5926 const struct intel_crtc_state *new_crtc_state = 5927 intel_atomic_get_new_crtc_state(state, crtc); 5928 const struct intel_plane_state *old_plane_state; 5929 struct intel_plane_state *new_plane_state; 5930 struct intel_plane *plane; 5931 int i; 5932 5933 if (!new_crtc_state->uapi.async_flip) 5934 return 0; 5935 5936 if (!new_crtc_state->uapi.active) { 5937 drm_dbg_kms(display->drm, 5938 "[CRTC:%d:%s] not active\n", 5939 crtc->base.base.id, crtc->base.name); 5940 return -EINVAL; 5941 } 5942 5943 if (intel_crtc_needs_modeset(new_crtc_state)) { 5944 drm_dbg_kms(display->drm, 5945 "[CRTC:%d:%s] modeset required\n", 5946 crtc->base.base.id, crtc->base.name); 5947 return -EINVAL; 5948 } 5949 5950 /* 5951 * FIXME: joiner+async flip is busted currently. 5952 * Remove this check once the issues are fixed. 5953 */ 5954 if (new_crtc_state->joiner_pipes) { 5955 drm_dbg_kms(display->drm, 5956 "[CRTC:%d:%s] async flip disallowed with joiner\n", 5957 crtc->base.base.id, crtc->base.name); 5958 return -EINVAL; 5959 } 5960 5961 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 5962 new_plane_state, i) { 5963 if (plane->pipe != crtc->pipe) 5964 continue; 5965 5966 /* 5967 * TODO: Async flip is only supported through the page flip IOCTL 5968 * as of now. So support currently added for primary plane only. 5969 * Support for other planes on platforms on which supports 5970 * this(vlv/chv and icl+) should be added when async flip is 5971 * enabled in the atomic IOCTL path. 5972 */ 5973 if (!plane->async_flip) { 5974 drm_dbg_kms(display->drm, 5975 "[PLANE:%d:%s] async flip not supported\n", 5976 plane->base.base.id, plane->base.name); 5977 return -EINVAL; 5978 } 5979 5980 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) { 5981 drm_dbg_kms(display->drm, 5982 "[PLANE:%d:%s] no old or new framebuffer\n", 5983 plane->base.base.id, plane->base.name); 5984 return -EINVAL; 5985 } 5986 } 5987 5988 return 0; 5989 } 5990 5991 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc) 5992 { 5993 struct intel_display *display = to_intel_display(state); 5994 const struct intel_crtc_state *old_crtc_state, *new_crtc_state; 5995 const struct intel_plane_state *new_plane_state, *old_plane_state; 5996 struct intel_plane *plane; 5997 int i; 5998 5999 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc); 6000 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 6001 6002 if (!new_crtc_state->uapi.async_flip) 6003 return 0; 6004 6005 if (!new_crtc_state->hw.active) { 6006 drm_dbg_kms(display->drm, 6007 "[CRTC:%d:%s] not active\n", 6008 crtc->base.base.id, crtc->base.name); 6009 return -EINVAL; 6010 } 6011 6012 if (intel_crtc_needs_modeset(new_crtc_state)) { 6013 drm_dbg_kms(display->drm, 6014 "[CRTC:%d:%s] modeset required\n", 6015 crtc->base.base.id, crtc->base.name); 6016 return -EINVAL; 6017 } 6018 6019 if (old_crtc_state->active_planes != new_crtc_state->active_planes) { 6020 drm_dbg_kms(display->drm, 6021 "[CRTC:%d:%s] Active planes cannot be in async flip\n", 6022 crtc->base.base.id, crtc->base.name); 6023 return -EINVAL; 6024 } 6025 6026 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 6027 new_plane_state, i) { 6028 if (plane->pipe != crtc->pipe) 6029 continue; 6030 6031 /* 6032 * Only async flip capable planes should be in the state 6033 * if we're really about to ask the hardware to perform 6034 * an async flip. We should never get this far otherwise. 6035 */ 6036 if (drm_WARN_ON(display->drm, 6037 new_crtc_state->do_async_flip && !plane->async_flip)) 6038 return -EINVAL; 6039 6040 /* 6041 * Only check async flip capable planes other planes 6042 * may be involved in the initial commit due to 6043 * the wm0/ddb optimization. 6044 * 6045 * TODO maybe should track which planes actually 6046 * were requested to do the async flip... 6047 */ 6048 if (!plane->async_flip) 6049 continue; 6050 6051 if (!intel_plane_can_async_flip(plane, new_plane_state->hw.fb->format->format, 6052 new_plane_state->hw.fb->modifier)) { 6053 drm_dbg_kms(display->drm, 6054 "[PLANE:%d:%s] pixel format %p4cc / modifier 0x%llx does not support async flip\n", 6055 plane->base.base.id, plane->base.name, 6056 &new_plane_state->hw.fb->format->format, 6057 new_plane_state->hw.fb->modifier); 6058 return -EINVAL; 6059 } 6060 6061 /* 6062 * We turn the first async flip request into a sync flip 6063 * so that we can reconfigure the plane (eg. change modifier). 6064 */ 6065 if (!new_crtc_state->do_async_flip) 6066 continue; 6067 6068 if (old_plane_state->view.color_plane[0].mapping_stride != 6069 new_plane_state->view.color_plane[0].mapping_stride) { 6070 drm_dbg_kms(display->drm, 6071 "[PLANE:%d:%s] Stride cannot be changed in async flip\n", 6072 plane->base.base.id, plane->base.name); 6073 return -EINVAL; 6074 } 6075 6076 if (old_plane_state->hw.fb->modifier != 6077 new_plane_state->hw.fb->modifier) { 6078 drm_dbg_kms(display->drm, 6079 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n", 6080 plane->base.base.id, plane->base.name); 6081 return -EINVAL; 6082 } 6083 6084 if (old_plane_state->hw.fb->format != 6085 new_plane_state->hw.fb->format) { 6086 drm_dbg_kms(display->drm, 6087 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n", 6088 plane->base.base.id, plane->base.name); 6089 return -EINVAL; 6090 } 6091 6092 if (old_plane_state->hw.rotation != 6093 new_plane_state->hw.rotation) { 6094 drm_dbg_kms(display->drm, 6095 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n", 6096 plane->base.base.id, plane->base.name); 6097 return -EINVAL; 6098 } 6099 6100 if (skl_plane_aux_dist(old_plane_state, 0) != 6101 skl_plane_aux_dist(new_plane_state, 0)) { 6102 drm_dbg_kms(display->drm, 6103 "[PLANE:%d:%s] AUX_DIST cannot be changed in async flip\n", 6104 plane->base.base.id, plane->base.name); 6105 return -EINVAL; 6106 } 6107 6108 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) || 6109 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) { 6110 drm_dbg_kms(display->drm, 6111 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n", 6112 plane->base.base.id, plane->base.name); 6113 return -EINVAL; 6114 } 6115 6116 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) { 6117 drm_dbg_kms(display->drm, 6118 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n", 6119 plane->base.base.id, plane->base.name); 6120 return -EINVAL; 6121 } 6122 6123 if (old_plane_state->hw.pixel_blend_mode != 6124 new_plane_state->hw.pixel_blend_mode) { 6125 drm_dbg_kms(display->drm, 6126 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n", 6127 plane->base.base.id, plane->base.name); 6128 return -EINVAL; 6129 } 6130 6131 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) { 6132 drm_dbg_kms(display->drm, 6133 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n", 6134 plane->base.base.id, plane->base.name); 6135 return -EINVAL; 6136 } 6137 6138 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) { 6139 drm_dbg_kms(display->drm, 6140 "[PLANE:%d:%s] Color range cannot be changed in async flip\n", 6141 plane->base.base.id, plane->base.name); 6142 return -EINVAL; 6143 } 6144 6145 /* plane decryption is allow to change only in synchronous flips */ 6146 if (old_plane_state->decrypt != new_plane_state->decrypt) { 6147 drm_dbg_kms(display->drm, 6148 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n", 6149 plane->base.base.id, plane->base.name); 6150 return -EINVAL; 6151 } 6152 } 6153 6154 return 0; 6155 } 6156 6157 static int intel_joiner_add_affected_crtcs(struct intel_atomic_state *state) 6158 { 6159 struct intel_display *display = to_intel_display(state); 6160 const struct intel_plane_state *plane_state; 6161 struct intel_crtc_state *crtc_state; 6162 struct intel_plane *plane; 6163 struct intel_crtc *crtc; 6164 u8 affected_pipes = 0; 6165 u8 modeset_pipes = 0; 6166 int i; 6167 6168 /* 6169 * Any plane which is in use by the joiner needs its crtc. 6170 * Pull those in first as this will not have happened yet 6171 * if the plane remains disabled according to uapi. 6172 */ 6173 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 6174 crtc = to_intel_crtc(plane_state->hw.crtc); 6175 if (!crtc) 6176 continue; 6177 6178 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6179 if (IS_ERR(crtc_state)) 6180 return PTR_ERR(crtc_state); 6181 } 6182 6183 /* Now pull in all joined crtcs */ 6184 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6185 affected_pipes |= crtc_state->joiner_pipes; 6186 if (intel_crtc_needs_modeset(crtc_state)) 6187 modeset_pipes |= crtc_state->joiner_pipes; 6188 } 6189 6190 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, affected_pipes) { 6191 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6192 if (IS_ERR(crtc_state)) 6193 return PTR_ERR(crtc_state); 6194 } 6195 6196 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, modeset_pipes) { 6197 int ret; 6198 6199 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 6200 6201 crtc_state->uapi.mode_changed = true; 6202 6203 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base); 6204 if (ret) 6205 return ret; 6206 6207 ret = intel_plane_add_affected(state, crtc); 6208 if (ret) 6209 return ret; 6210 } 6211 6212 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) { 6213 /* Kill old joiner link, we may re-establish afterwards */ 6214 if (intel_crtc_needs_modeset(crtc_state) && 6215 intel_crtc_is_joiner_primary(crtc_state)) 6216 kill_joiner_secondaries(state, crtc); 6217 } 6218 6219 return 0; 6220 } 6221 6222 static int intel_atomic_check_config(struct intel_atomic_state *state, 6223 struct intel_link_bw_limits *limits, 6224 enum pipe *failed_pipe) 6225 { 6226 struct intel_display *display = to_intel_display(state); 6227 struct intel_crtc_state *new_crtc_state; 6228 struct intel_crtc *crtc; 6229 int ret; 6230 int i; 6231 6232 *failed_pipe = INVALID_PIPE; 6233 6234 ret = intel_joiner_add_affected_crtcs(state); 6235 if (ret) 6236 return ret; 6237 6238 ret = intel_fdi_add_affected_crtcs(state); 6239 if (ret) 6240 return ret; 6241 6242 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6243 if (!intel_crtc_needs_modeset(new_crtc_state)) { 6244 if (intel_crtc_is_joiner_secondary(new_crtc_state)) 6245 copy_joiner_crtc_state_nomodeset(state, crtc); 6246 else 6247 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc); 6248 continue; 6249 } 6250 6251 if (drm_WARN_ON(display->drm, intel_crtc_is_joiner_secondary(new_crtc_state))) 6252 continue; 6253 6254 ret = intel_crtc_prepare_cleared_state(state, crtc); 6255 if (ret) 6256 goto fail; 6257 6258 if (!new_crtc_state->hw.enable) 6259 continue; 6260 6261 ret = intel_modeset_pipe_config(state, crtc, limits); 6262 if (ret) 6263 goto fail; 6264 } 6265 6266 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6267 if (!intel_crtc_needs_modeset(new_crtc_state)) 6268 continue; 6269 6270 if (drm_WARN_ON(display->drm, intel_crtc_is_joiner_secondary(new_crtc_state))) 6271 continue; 6272 6273 if (!new_crtc_state->hw.enable) 6274 continue; 6275 6276 ret = intel_modeset_pipe_config_late(state, crtc); 6277 if (ret) 6278 goto fail; 6279 } 6280 6281 fail: 6282 if (ret) 6283 *failed_pipe = crtc->pipe; 6284 6285 return ret; 6286 } 6287 6288 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state) 6289 { 6290 struct intel_link_bw_limits new_limits; 6291 struct intel_link_bw_limits old_limits; 6292 int ret; 6293 6294 intel_link_bw_init_limits(state, &new_limits); 6295 old_limits = new_limits; 6296 6297 while (true) { 6298 enum pipe failed_pipe; 6299 6300 ret = intel_atomic_check_config(state, &new_limits, 6301 &failed_pipe); 6302 if (ret) { 6303 /* 6304 * The bpp limit for a pipe is below the minimum it supports, set the 6305 * limit to the minimum and recalculate the config. 6306 */ 6307 if (ret == -EINVAL && 6308 intel_link_bw_set_bpp_limit_for_pipe(state, 6309 &old_limits, 6310 &new_limits, 6311 failed_pipe)) 6312 continue; 6313 6314 break; 6315 } 6316 6317 old_limits = new_limits; 6318 6319 ret = intel_link_bw_atomic_check(state, &new_limits); 6320 if (ret != -EAGAIN) 6321 break; 6322 } 6323 6324 return ret; 6325 } 6326 /** 6327 * intel_atomic_check - validate state object 6328 * @dev: drm device 6329 * @_state: state to validate 6330 */ 6331 int intel_atomic_check(struct drm_device *dev, 6332 struct drm_atomic_state *_state) 6333 { 6334 struct intel_display *display = to_intel_display(dev); 6335 struct intel_atomic_state *state = to_intel_atomic_state(_state); 6336 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 6337 struct intel_crtc *crtc; 6338 int ret, i; 6339 bool any_ms = false; 6340 6341 if (!intel_display_driver_check_access(display)) 6342 return -ENODEV; 6343 6344 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6345 new_crtc_state, i) { 6346 /* 6347 * crtc's state no longer considered to be inherited 6348 * after the first userspace/client initiated commit. 6349 */ 6350 if (!state->internal) 6351 new_crtc_state->inherited = false; 6352 6353 if (new_crtc_state->inherited != old_crtc_state->inherited) 6354 new_crtc_state->uapi.mode_changed = true; 6355 6356 if (new_crtc_state->uapi.scaling_filter != 6357 old_crtc_state->uapi.scaling_filter) 6358 new_crtc_state->uapi.mode_changed = true; 6359 } 6360 6361 intel_vrr_check_modeset(state); 6362 6363 ret = drm_atomic_helper_check_modeset(dev, &state->base); 6364 if (ret) 6365 goto fail; 6366 6367 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6368 ret = intel_async_flip_check_uapi(state, crtc); 6369 if (ret) 6370 return ret; 6371 } 6372 6373 ret = intel_atomic_check_config_and_link(state); 6374 if (ret) 6375 goto fail; 6376 6377 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6378 if (!intel_crtc_needs_modeset(new_crtc_state)) 6379 continue; 6380 6381 if (intel_crtc_is_joiner_secondary(new_crtc_state)) { 6382 drm_WARN_ON(display->drm, new_crtc_state->uapi.enable); 6383 continue; 6384 } 6385 6386 ret = intel_atomic_check_joiner(state, crtc); 6387 if (ret) 6388 goto fail; 6389 } 6390 6391 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6392 new_crtc_state, i) { 6393 if (!intel_crtc_needs_modeset(new_crtc_state)) 6394 continue; 6395 6396 intel_joiner_adjust_pipe_src(new_crtc_state); 6397 6398 intel_crtc_check_fastset(old_crtc_state, new_crtc_state); 6399 } 6400 6401 /** 6402 * Check if fastset is allowed by external dependencies like other 6403 * pipes and transcoders. 6404 * 6405 * Right now it only forces a fullmodeset when the MST master 6406 * transcoder did not changed but the pipe of the master transcoder 6407 * needs a fullmodeset so all slaves also needs to do a fullmodeset or 6408 * in case of port synced crtcs, if one of the synced crtcs 6409 * needs a full modeset, all other synced crtcs should be 6410 * forced a full modeset. 6411 */ 6412 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6413 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state)) 6414 continue; 6415 6416 if (intel_dp_mst_crtc_needs_modeset(state, crtc)) 6417 intel_crtc_flag_modeset(new_crtc_state); 6418 6419 if (intel_dp_mst_is_slave_trans(new_crtc_state)) { 6420 enum transcoder master = new_crtc_state->mst_master_transcoder; 6421 6422 if (intel_cpu_transcoders_need_modeset(state, BIT(master))) 6423 intel_crtc_flag_modeset(new_crtc_state); 6424 } 6425 6426 if (is_trans_port_sync_mode(new_crtc_state)) { 6427 u8 trans = new_crtc_state->sync_mode_slaves_mask; 6428 6429 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER) 6430 trans |= BIT(new_crtc_state->master_transcoder); 6431 6432 if (intel_cpu_transcoders_need_modeset(state, trans)) 6433 intel_crtc_flag_modeset(new_crtc_state); 6434 } 6435 6436 if (new_crtc_state->joiner_pipes) { 6437 if (intel_pipes_need_modeset(state, new_crtc_state->joiner_pipes)) 6438 intel_crtc_flag_modeset(new_crtc_state); 6439 } 6440 } 6441 6442 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6443 new_crtc_state, i) { 6444 if (!intel_crtc_needs_modeset(new_crtc_state)) 6445 continue; 6446 6447 any_ms = true; 6448 6449 intel_dpll_release(state, crtc); 6450 } 6451 6452 if (any_ms && !check_digital_port_conflicts(state)) { 6453 drm_dbg_kms(display->drm, 6454 "rejecting conflicting digital port configuration\n"); 6455 ret = -EINVAL; 6456 goto fail; 6457 } 6458 6459 ret = intel_plane_atomic_check(state); 6460 if (ret) 6461 goto fail; 6462 6463 ret = intel_compute_global_watermarks(state); 6464 if (ret) 6465 goto fail; 6466 6467 ret = intel_bw_atomic_check(state, any_ms); 6468 if (ret) 6469 goto fail; 6470 6471 ret = intel_cdclk_atomic_check(state, &any_ms); 6472 if (ret) 6473 goto fail; 6474 6475 if (intel_any_crtc_needs_modeset(state)) 6476 any_ms = true; 6477 6478 if (any_ms) { 6479 ret = intel_modeset_checks(state); 6480 if (ret) 6481 goto fail; 6482 6483 ret = intel_modeset_calc_cdclk(state); 6484 if (ret) 6485 return ret; 6486 } 6487 6488 ret = intel_pmdemand_atomic_check(state); 6489 if (ret) 6490 goto fail; 6491 6492 ret = intel_atomic_check_crtcs(state); 6493 if (ret) 6494 goto fail; 6495 6496 ret = intel_fbc_atomic_check(state); 6497 if (ret) 6498 goto fail; 6499 6500 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6501 new_crtc_state, i) { 6502 intel_color_assert_luts(new_crtc_state); 6503 6504 ret = intel_async_flip_check_hw(state, crtc); 6505 if (ret) 6506 goto fail; 6507 6508 /* Either full modeset or fastset (or neither), never both */ 6509 drm_WARN_ON(display->drm, 6510 intel_crtc_needs_modeset(new_crtc_state) && 6511 intel_crtc_needs_fastset(new_crtc_state)); 6512 6513 if (!intel_crtc_needs_modeset(new_crtc_state) && 6514 !intel_crtc_needs_fastset(new_crtc_state)) 6515 continue; 6516 6517 intel_crtc_state_dump(new_crtc_state, state, 6518 intel_crtc_needs_modeset(new_crtc_state) ? 6519 "modeset" : "fastset"); 6520 } 6521 6522 return 0; 6523 6524 fail: 6525 if (ret == -EDEADLK) 6526 return ret; 6527 6528 /* 6529 * FIXME would probably be nice to know which crtc specifically 6530 * caused the failure, in cases where we can pinpoint it. 6531 */ 6532 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6533 new_crtc_state, i) 6534 intel_crtc_state_dump(new_crtc_state, state, "failed"); 6535 6536 return ret; 6537 } 6538 6539 static int intel_atomic_prepare_commit(struct intel_atomic_state *state) 6540 { 6541 int ret; 6542 6543 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base); 6544 if (ret < 0) 6545 return ret; 6546 6547 return 0; 6548 } 6549 6550 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc, 6551 struct intel_crtc_state *crtc_state) 6552 { 6553 struct intel_display *display = to_intel_display(crtc); 6554 6555 if (DISPLAY_VER(display) != 2 || crtc_state->active_planes) 6556 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, true); 6557 6558 if (crtc_state->has_pch_encoder) { 6559 enum pipe pch_transcoder = 6560 intel_crtc_pch_transcoder(crtc); 6561 6562 intel_set_pch_fifo_underrun_reporting(display, pch_transcoder, true); 6563 } 6564 } 6565 6566 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state, 6567 const struct intel_crtc_state *new_crtc_state) 6568 { 6569 struct intel_display *display = to_intel_display(new_crtc_state); 6570 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc); 6571 6572 /* 6573 * Update pipe size and adjust fitter if needed: the reason for this is 6574 * that in compute_mode_changes we check the native mode (not the pfit 6575 * mode) to see if we can flip rather than do a full mode set. In the 6576 * fastboot case, we'll flip, but if we don't update the pipesrc and 6577 * pfit state, we'll end up with a big fb scanned out into the wrong 6578 * sized surface. 6579 */ 6580 intel_set_pipe_src_size(new_crtc_state); 6581 6582 /* on skylake this is done by detaching scalers */ 6583 if (DISPLAY_VER(display) >= 9) { 6584 if (new_crtc_state->pch_pfit.enabled) 6585 skl_pfit_enable(new_crtc_state); 6586 } else if (HAS_PCH_SPLIT(display)) { 6587 if (new_crtc_state->pch_pfit.enabled) 6588 ilk_pfit_enable(new_crtc_state); 6589 else if (old_crtc_state->pch_pfit.enabled) 6590 ilk_pfit_disable(old_crtc_state); 6591 } 6592 6593 /* 6594 * The register is supposedly single buffered so perhaps 6595 * not 100% correct to do this here. But SKL+ calculate 6596 * this based on the adjust pixel rate so pfit changes do 6597 * affect it and so it must be updated for fastsets. 6598 * HSW/BDW only really need this here for fastboot, after 6599 * that the value should not change without a full modeset. 6600 */ 6601 if (DISPLAY_VER(display) >= 9 || 6602 display->platform.broadwell || display->platform.haswell) 6603 hsw_set_linetime_wm(new_crtc_state); 6604 6605 if (new_crtc_state->update_m_n) 6606 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder, 6607 &new_crtc_state->dp_m_n); 6608 6609 if (new_crtc_state->update_lrr) 6610 intel_set_transcoder_timings_lrr(new_crtc_state); 6611 } 6612 6613 static void commit_pipe_pre_planes(struct intel_atomic_state *state, 6614 struct intel_crtc *crtc) 6615 { 6616 struct intel_display *display = to_intel_display(state); 6617 const struct intel_crtc_state *old_crtc_state = 6618 intel_atomic_get_old_crtc_state(state, crtc); 6619 const struct intel_crtc_state *new_crtc_state = 6620 intel_atomic_get_new_crtc_state(state, crtc); 6621 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 6622 6623 drm_WARN_ON(display->drm, new_crtc_state->use_dsb || new_crtc_state->use_flipq); 6624 6625 /* 6626 * During modesets pipe configuration was programmed as the 6627 * CRTC was enabled. 6628 */ 6629 if (!modeset) { 6630 if (intel_crtc_needs_color_update(new_crtc_state)) 6631 intel_color_commit_arm(NULL, new_crtc_state); 6632 6633 if (DISPLAY_VER(display) >= 9 || display->platform.broadwell) 6634 bdw_set_pipe_misc(NULL, new_crtc_state); 6635 6636 if (intel_crtc_needs_fastset(new_crtc_state)) 6637 intel_pipe_fastset(old_crtc_state, new_crtc_state); 6638 } 6639 6640 intel_psr2_program_trans_man_trk_ctl(NULL, new_crtc_state); 6641 6642 intel_atomic_update_watermarks(state, crtc); 6643 } 6644 6645 static void commit_pipe_post_planes(struct intel_atomic_state *state, 6646 struct intel_crtc *crtc) 6647 { 6648 struct intel_display *display = to_intel_display(state); 6649 const struct intel_crtc_state *new_crtc_state = 6650 intel_atomic_get_new_crtc_state(state, crtc); 6651 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 6652 6653 drm_WARN_ON(display->drm, new_crtc_state->use_dsb || new_crtc_state->use_flipq); 6654 6655 /* 6656 * Disable the scaler(s) after the plane(s) so that we don't 6657 * get a catastrophic underrun even if the two operations 6658 * end up happening in two different frames. 6659 */ 6660 if (DISPLAY_VER(display) >= 9 && !modeset) 6661 skl_detach_scalers(NULL, new_crtc_state); 6662 6663 if (!modeset && 6664 intel_crtc_needs_color_update(new_crtc_state) && 6665 !intel_color_uses_dsb(new_crtc_state) && 6666 HAS_DOUBLE_BUFFERED_LUT(display)) 6667 intel_color_load_luts(new_crtc_state); 6668 6669 if (intel_crtc_vrr_enabling(state, crtc)) 6670 intel_vrr_enable(new_crtc_state); 6671 } 6672 6673 static void intel_enable_crtc(struct intel_atomic_state *state, 6674 struct intel_crtc *crtc) 6675 { 6676 struct intel_display *display = to_intel_display(state); 6677 const struct intel_crtc_state *new_crtc_state = 6678 intel_atomic_get_new_crtc_state(state, crtc); 6679 struct intel_crtc *pipe_crtc; 6680 6681 if (!intel_crtc_needs_modeset(new_crtc_state)) 6682 return; 6683 6684 for_each_intel_crtc_in_pipe_mask_reverse(display->drm, pipe_crtc, 6685 intel_crtc_joined_pipe_mask(new_crtc_state)) { 6686 const struct intel_crtc_state *pipe_crtc_state = 6687 intel_atomic_get_new_crtc_state(state, pipe_crtc); 6688 6689 /* VRR will be enable later, if required */ 6690 intel_crtc_update_active_timings(pipe_crtc_state, false); 6691 } 6692 6693 intel_psr_notify_pipe_change(state, crtc, true); 6694 6695 display->funcs.display->crtc_enable(state, crtc); 6696 6697 /* vblanks work again, re-enable pipe CRC. */ 6698 intel_crtc_enable_pipe_crc(crtc); 6699 } 6700 6701 static void intel_pre_update_crtc(struct intel_atomic_state *state, 6702 struct intel_crtc *crtc) 6703 { 6704 struct intel_display *display = to_intel_display(state); 6705 const struct intel_crtc_state *old_crtc_state = 6706 intel_atomic_get_old_crtc_state(state, crtc); 6707 struct intel_crtc_state *new_crtc_state = 6708 intel_atomic_get_new_crtc_state(state, crtc); 6709 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 6710 6711 if (old_crtc_state->inherited || 6712 intel_crtc_needs_modeset(new_crtc_state)) { 6713 if (HAS_DPT(display)) 6714 intel_dpt_configure(crtc); 6715 } 6716 6717 if (!modeset) { 6718 if (new_crtc_state->preload_luts && 6719 intel_crtc_needs_color_update(new_crtc_state)) 6720 intel_color_load_luts(new_crtc_state); 6721 6722 intel_pre_plane_update(state, crtc); 6723 6724 if (intel_crtc_needs_fastset(new_crtc_state)) 6725 intel_encoders_update_pipe(state, crtc); 6726 6727 if (DISPLAY_VER(display) >= 11 && 6728 intel_crtc_needs_fastset(new_crtc_state)) 6729 icl_set_pipe_chicken(new_crtc_state); 6730 6731 if (vrr_params_changed(old_crtc_state, new_crtc_state) || 6732 cmrr_params_changed(old_crtc_state, new_crtc_state)) 6733 intel_vrr_set_transcoder_timings(new_crtc_state); 6734 } 6735 6736 intel_fbc_update(state, crtc); 6737 6738 drm_WARN_ON(display->drm, !intel_display_power_is_enabled(display, POWER_DOMAIN_DC_OFF)); 6739 6740 if (!modeset && 6741 intel_crtc_needs_color_update(new_crtc_state) && 6742 !new_crtc_state->use_dsb && !new_crtc_state->use_flipq) 6743 intel_color_commit_noarm(NULL, new_crtc_state); 6744 6745 if (!new_crtc_state->use_dsb && !new_crtc_state->use_flipq) 6746 intel_crtc_planes_update_noarm(NULL, state, crtc); 6747 } 6748 6749 static void intel_update_crtc(struct intel_atomic_state *state, 6750 struct intel_crtc *crtc) 6751 { 6752 const struct intel_crtc_state *old_crtc_state = 6753 intel_atomic_get_old_crtc_state(state, crtc); 6754 struct intel_crtc_state *new_crtc_state = 6755 intel_atomic_get_new_crtc_state(state, crtc); 6756 6757 if (new_crtc_state->use_flipq) { 6758 intel_flipq_enable(new_crtc_state); 6759 6760 intel_crtc_prepare_vblank_event(new_crtc_state, &crtc->flipq_event); 6761 6762 intel_flipq_add(crtc, INTEL_FLIPQ_PLANE_1, 0, INTEL_DSB_0, 6763 new_crtc_state->dsb_commit); 6764 } else if (new_crtc_state->use_dsb) { 6765 intel_crtc_prepare_vblank_event(new_crtc_state, &crtc->dsb_event); 6766 6767 intel_dsb_commit(new_crtc_state->dsb_commit); 6768 } else { 6769 /* Perform vblank evasion around commit operation */ 6770 intel_pipe_update_start(state, crtc); 6771 6772 if (new_crtc_state->dsb_commit) 6773 intel_dsb_commit(new_crtc_state->dsb_commit); 6774 6775 commit_pipe_pre_planes(state, crtc); 6776 6777 intel_crtc_planes_update_arm(NULL, state, crtc); 6778 6779 commit_pipe_post_planes(state, crtc); 6780 6781 intel_pipe_update_end(state, crtc); 6782 } 6783 6784 /* 6785 * VRR/Seamless M/N update may need to update frame timings. 6786 * 6787 * FIXME Should be synchronized with the start of vblank somehow... 6788 */ 6789 if (intel_crtc_vrr_enabling(state, crtc) || 6790 new_crtc_state->update_m_n || new_crtc_state->update_lrr) 6791 intel_crtc_update_active_timings(new_crtc_state, 6792 new_crtc_state->vrr.enable); 6793 6794 /* 6795 * We usually enable FIFO underrun interrupts as part of the 6796 * CRTC enable sequence during modesets. But when we inherit a 6797 * valid pipe configuration from the BIOS we need to take care 6798 * of enabling them on the CRTC's first fastset. 6799 */ 6800 if (intel_crtc_needs_fastset(new_crtc_state) && 6801 old_crtc_state->inherited) 6802 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state); 6803 } 6804 6805 static void intel_old_crtc_state_disables(struct intel_atomic_state *state, 6806 struct intel_crtc *crtc) 6807 { 6808 struct intel_display *display = to_intel_display(state); 6809 const struct intel_crtc_state *old_crtc_state = 6810 intel_atomic_get_old_crtc_state(state, crtc); 6811 struct intel_crtc *pipe_crtc; 6812 6813 /* 6814 * We need to disable pipe CRC before disabling the pipe, 6815 * or we race against vblank off. 6816 */ 6817 for_each_intel_crtc_in_pipe_mask(display->drm, pipe_crtc, 6818 intel_crtc_joined_pipe_mask(old_crtc_state)) 6819 intel_crtc_disable_pipe_crc(pipe_crtc); 6820 6821 intel_psr_notify_pipe_change(state, crtc, false); 6822 6823 display->funcs.display->crtc_disable(state, crtc); 6824 6825 for_each_intel_crtc_in_pipe_mask(display->drm, pipe_crtc, 6826 intel_crtc_joined_pipe_mask(old_crtc_state)) { 6827 const struct intel_crtc_state *new_pipe_crtc_state = 6828 intel_atomic_get_new_crtc_state(state, pipe_crtc); 6829 6830 pipe_crtc->active = false; 6831 intel_fbc_disable(pipe_crtc); 6832 6833 if (!new_pipe_crtc_state->hw.active) 6834 intel_initial_watermarks(state, pipe_crtc); 6835 } 6836 } 6837 6838 static void intel_commit_modeset_disables(struct intel_atomic_state *state) 6839 { 6840 struct intel_display *display = to_intel_display(state); 6841 const struct intel_crtc_state *new_crtc_state, *old_crtc_state; 6842 struct intel_crtc *crtc; 6843 u8 disable_pipes = 0; 6844 int i; 6845 6846 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 6847 new_crtc_state, i) { 6848 if (!intel_crtc_needs_modeset(new_crtc_state)) 6849 continue; 6850 6851 /* 6852 * Needs to be done even for pipes 6853 * that weren't enabled previously. 6854 */ 6855 intel_pre_plane_update(state, crtc); 6856 6857 if (!old_crtc_state->hw.active) 6858 continue; 6859 6860 disable_pipes |= BIT(crtc->pipe); 6861 } 6862 6863 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) { 6864 if ((disable_pipes & BIT(crtc->pipe)) == 0) 6865 continue; 6866 6867 intel_crtc_disable_planes(state, crtc); 6868 6869 drm_vblank_work_flush_all(&crtc->base); 6870 } 6871 6872 /* Only disable port sync and MST slaves */ 6873 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) { 6874 if ((disable_pipes & BIT(crtc->pipe)) == 0) 6875 continue; 6876 6877 if (intel_crtc_is_joiner_secondary(old_crtc_state)) 6878 continue; 6879 6880 /* In case of Transcoder port Sync master slave CRTCs can be 6881 * assigned in any order and we need to make sure that 6882 * slave CRTCs are disabled first and then master CRTC since 6883 * Slave vblanks are masked till Master Vblanks. 6884 */ 6885 if (!is_trans_port_sync_slave(old_crtc_state) && 6886 !intel_dp_mst_is_slave_trans(old_crtc_state)) 6887 continue; 6888 6889 intel_old_crtc_state_disables(state, crtc); 6890 6891 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state); 6892 } 6893 6894 /* Disable everything else left on */ 6895 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) { 6896 if ((disable_pipes & BIT(crtc->pipe)) == 0) 6897 continue; 6898 6899 if (intel_crtc_is_joiner_secondary(old_crtc_state)) 6900 continue; 6901 6902 intel_old_crtc_state_disables(state, crtc); 6903 6904 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state); 6905 } 6906 6907 drm_WARN_ON(display->drm, disable_pipes); 6908 } 6909 6910 static void intel_commit_modeset_enables(struct intel_atomic_state *state) 6911 { 6912 struct intel_crtc_state *new_crtc_state; 6913 struct intel_crtc *crtc; 6914 int i; 6915 6916 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6917 if (!new_crtc_state->hw.active) 6918 continue; 6919 6920 intel_enable_crtc(state, crtc); 6921 intel_pre_update_crtc(state, crtc); 6922 } 6923 6924 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6925 if (!new_crtc_state->hw.active) 6926 continue; 6927 6928 intel_update_crtc(state, crtc); 6929 } 6930 } 6931 6932 static void skl_commit_modeset_enables(struct intel_atomic_state *state) 6933 { 6934 struct intel_display *display = to_intel_display(state); 6935 struct intel_crtc *crtc; 6936 struct intel_crtc_state *old_crtc_state, *new_crtc_state; 6937 struct skl_ddb_entry entries[I915_MAX_PIPES] = {}; 6938 u8 update_pipes = 0, modeset_pipes = 0; 6939 int i; 6940 6941 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 6942 enum pipe pipe = crtc->pipe; 6943 6944 if (!new_crtc_state->hw.active) 6945 continue; 6946 6947 /* ignore allocations for crtc's that have been turned off. */ 6948 if (!intel_crtc_needs_modeset(new_crtc_state)) { 6949 entries[pipe] = old_crtc_state->wm.skl.ddb; 6950 update_pipes |= BIT(pipe); 6951 } else { 6952 modeset_pipes |= BIT(pipe); 6953 } 6954 } 6955 6956 /* 6957 * Whenever the number of active pipes changes, we need to make sure we 6958 * update the pipes in the right order so that their ddb allocations 6959 * never overlap with each other between CRTC updates. Otherwise we'll 6960 * cause pipe underruns and other bad stuff. 6961 * 6962 * So first lets enable all pipes that do not need a fullmodeset as 6963 * those don't have any external dependency. 6964 */ 6965 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 6966 enum pipe pipe = crtc->pipe; 6967 6968 if ((update_pipes & BIT(pipe)) == 0) 6969 continue; 6970 6971 intel_pre_update_crtc(state, crtc); 6972 } 6973 6974 intel_dbuf_mbus_pre_ddb_update(state); 6975 6976 while (update_pipes) { 6977 /* 6978 * Commit in reverse order to make joiner primary 6979 * send the uapi events after secondaries are done. 6980 */ 6981 for_each_oldnew_intel_crtc_in_state_reverse(state, crtc, old_crtc_state, 6982 new_crtc_state, i) { 6983 enum pipe pipe = crtc->pipe; 6984 6985 if ((update_pipes & BIT(pipe)) == 0) 6986 continue; 6987 6988 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 6989 entries, I915_MAX_PIPES, pipe)) 6990 continue; 6991 6992 entries[pipe] = new_crtc_state->wm.skl.ddb; 6993 update_pipes &= ~BIT(pipe); 6994 6995 intel_update_crtc(state, crtc); 6996 6997 /* 6998 * If this is an already active pipe, it's DDB changed, 6999 * and this isn't the last pipe that needs updating 7000 * then we need to wait for a vblank to pass for the 7001 * new ddb allocation to take effect. 7002 */ 7003 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb, 7004 &old_crtc_state->wm.skl.ddb) && 7005 (update_pipes | modeset_pipes)) 7006 intel_crtc_wait_for_next_vblank(crtc); 7007 } 7008 } 7009 7010 intel_dbuf_mbus_post_ddb_update(state); 7011 7012 update_pipes = modeset_pipes; 7013 7014 /* 7015 * Enable all pipes that needs a modeset and do not depends on other 7016 * pipes 7017 */ 7018 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7019 enum pipe pipe = crtc->pipe; 7020 7021 if ((modeset_pipes & BIT(pipe)) == 0) 7022 continue; 7023 7024 if (intel_crtc_is_joiner_secondary(new_crtc_state)) 7025 continue; 7026 7027 if (intel_dp_mst_is_slave_trans(new_crtc_state) || 7028 is_trans_port_sync_master(new_crtc_state)) 7029 continue; 7030 7031 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state); 7032 7033 intel_enable_crtc(state, crtc); 7034 } 7035 7036 /* 7037 * Then we enable all remaining pipes that depend on other 7038 * pipes: MST slaves and port sync masters 7039 */ 7040 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7041 enum pipe pipe = crtc->pipe; 7042 7043 if ((modeset_pipes & BIT(pipe)) == 0) 7044 continue; 7045 7046 if (intel_crtc_is_joiner_secondary(new_crtc_state)) 7047 continue; 7048 7049 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state); 7050 7051 intel_enable_crtc(state, crtc); 7052 } 7053 7054 /* 7055 * Finally we do the plane updates/etc. for all pipes that got enabled. 7056 */ 7057 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7058 enum pipe pipe = crtc->pipe; 7059 7060 if ((update_pipes & BIT(pipe)) == 0) 7061 continue; 7062 7063 intel_pre_update_crtc(state, crtc); 7064 } 7065 7066 /* 7067 * Commit in reverse order to make joiner primary 7068 * send the uapi events after secondaries are done. 7069 */ 7070 for_each_new_intel_crtc_in_state_reverse(state, crtc, new_crtc_state, i) { 7071 enum pipe pipe = crtc->pipe; 7072 7073 if ((update_pipes & BIT(pipe)) == 0) 7074 continue; 7075 7076 drm_WARN_ON(display->drm, 7077 skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb, 7078 entries, I915_MAX_PIPES, pipe)); 7079 7080 entries[pipe] = new_crtc_state->wm.skl.ddb; 7081 update_pipes &= ~BIT(pipe); 7082 7083 intel_update_crtc(state, crtc); 7084 } 7085 7086 drm_WARN_ON(display->drm, modeset_pipes); 7087 drm_WARN_ON(display->drm, update_pipes); 7088 } 7089 7090 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state) 7091 { 7092 struct drm_i915_private *i915 = to_i915(intel_state->base.dev); 7093 struct drm_plane *plane; 7094 struct drm_plane_state *new_plane_state; 7095 long ret; 7096 int i; 7097 7098 for_each_new_plane_in_state(&intel_state->base, plane, new_plane_state, i) { 7099 if (new_plane_state->fence) { 7100 ret = dma_fence_wait_timeout(new_plane_state->fence, false, 7101 i915_fence_timeout(i915)); 7102 if (ret <= 0) 7103 break; 7104 7105 dma_fence_put(new_plane_state->fence); 7106 new_plane_state->fence = NULL; 7107 } 7108 } 7109 } 7110 7111 static void intel_atomic_dsb_wait_commit(struct intel_crtc_state *crtc_state) 7112 { 7113 if (crtc_state->dsb_commit) 7114 intel_dsb_wait(crtc_state->dsb_commit); 7115 7116 intel_color_wait_commit(crtc_state); 7117 } 7118 7119 static void intel_atomic_dsb_cleanup(struct intel_crtc_state *crtc_state) 7120 { 7121 if (crtc_state->dsb_commit) { 7122 intel_dsb_cleanup(crtc_state->dsb_commit); 7123 crtc_state->dsb_commit = NULL; 7124 } 7125 7126 intel_color_cleanup_commit(crtc_state); 7127 } 7128 7129 static void intel_atomic_cleanup_work(struct work_struct *work) 7130 { 7131 struct intel_atomic_state *state = 7132 container_of(work, struct intel_atomic_state, cleanup_work); 7133 struct intel_display *display = to_intel_display(state); 7134 struct intel_crtc_state *old_crtc_state; 7135 struct intel_crtc *crtc; 7136 int i; 7137 7138 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) 7139 intel_atomic_dsb_cleanup(old_crtc_state); 7140 7141 drm_atomic_helper_cleanup_planes(display->drm, &state->base); 7142 drm_atomic_helper_commit_cleanup_done(&state->base); 7143 drm_atomic_state_put(&state->base); 7144 } 7145 7146 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state) 7147 { 7148 struct intel_display *display = to_intel_display(state); 7149 struct intel_plane *plane; 7150 struct intel_plane_state *plane_state; 7151 int i; 7152 7153 for_each_new_intel_plane_in_state(state, plane, plane_state, i) { 7154 struct drm_framebuffer *fb = plane_state->hw.fb; 7155 int cc_plane; 7156 int ret; 7157 7158 if (!fb) 7159 continue; 7160 7161 cc_plane = intel_fb_rc_ccs_cc_plane(fb); 7162 if (cc_plane < 0) 7163 continue; 7164 7165 /* 7166 * The layout of the fast clear color value expected by HW 7167 * (the DRM ABI requiring this value to be located in fb at 7168 * offset 0 of cc plane, plane #2 previous generations or 7169 * plane #1 for flat ccs): 7170 * - 4 x 4 bytes per-channel value 7171 * (in surface type specific float/int format provided by the fb user) 7172 * - 8 bytes native color value used by the display 7173 * (converted/written by GPU during a fast clear operation using the 7174 * above per-channel values) 7175 * 7176 * The commit's FB prepare hook already ensured that FB obj is pinned and the 7177 * caller made sure that the object is synced wrt. the related color clear value 7178 * GPU write on it. 7179 */ 7180 ret = intel_bo_read_from_page(intel_fb_bo(fb), 7181 fb->offsets[cc_plane] + 16, 7182 &plane_state->ccval, 7183 sizeof(plane_state->ccval)); 7184 /* The above could only fail if the FB obj has an unexpected backing store type. */ 7185 drm_WARN_ON(display->drm, ret); 7186 } 7187 } 7188 7189 static void intel_atomic_dsb_prepare(struct intel_atomic_state *state, 7190 struct intel_crtc *crtc) 7191 { 7192 struct intel_display *display = to_intel_display(state); 7193 struct intel_crtc_state *new_crtc_state = 7194 intel_atomic_get_new_crtc_state(state, crtc); 7195 7196 if (!new_crtc_state->hw.active) 7197 return; 7198 7199 if (state->base.legacy_cursor_update) 7200 return; 7201 7202 /* FIXME deal with everything */ 7203 new_crtc_state->use_flipq = 7204 intel_flipq_supported(display) && 7205 !new_crtc_state->do_async_flip && 7206 !new_crtc_state->vrr.enable && 7207 !new_crtc_state->has_psr && 7208 !intel_crtc_needs_modeset(new_crtc_state) && 7209 !intel_crtc_needs_fastset(new_crtc_state) && 7210 !intel_crtc_needs_color_update(new_crtc_state); 7211 7212 new_crtc_state->use_dsb = 7213 !new_crtc_state->use_flipq && 7214 !new_crtc_state->do_async_flip && 7215 (DISPLAY_VER(display) >= 20 || !new_crtc_state->has_psr) && 7216 !intel_crtc_needs_modeset(new_crtc_state) && 7217 !intel_crtc_needs_fastset(new_crtc_state); 7218 7219 intel_color_prepare_commit(state, crtc); 7220 } 7221 7222 static void intel_atomic_dsb_finish(struct intel_atomic_state *state, 7223 struct intel_crtc *crtc) 7224 { 7225 struct intel_display *display = to_intel_display(state); 7226 struct intel_crtc_state *new_crtc_state = 7227 intel_atomic_get_new_crtc_state(state, crtc); 7228 7229 if (!new_crtc_state->use_flipq && 7230 !new_crtc_state->use_dsb && 7231 !new_crtc_state->dsb_color) 7232 return; 7233 7234 /* 7235 * Rough estimate: 7236 * ~64 registers per each plane * 8 planes = 512 7237 * Double that for pipe stuff and other overhead. 7238 */ 7239 new_crtc_state->dsb_commit = intel_dsb_prepare(state, crtc, INTEL_DSB_0, 7240 new_crtc_state->use_dsb || 7241 new_crtc_state->use_flipq ? 1024 : 16); 7242 if (!new_crtc_state->dsb_commit) { 7243 new_crtc_state->use_flipq = false; 7244 new_crtc_state->use_dsb = false; 7245 intel_color_cleanup_commit(new_crtc_state); 7246 return; 7247 } 7248 7249 if (new_crtc_state->use_flipq || new_crtc_state->use_dsb) { 7250 /* Wa_18034343758 */ 7251 if (new_crtc_state->use_flipq) 7252 intel_flipq_wait_dmc_halt(new_crtc_state->dsb_commit, crtc); 7253 7254 if (intel_crtc_needs_color_update(new_crtc_state)) 7255 intel_color_commit_noarm(new_crtc_state->dsb_commit, 7256 new_crtc_state); 7257 intel_crtc_planes_update_noarm(new_crtc_state->dsb_commit, 7258 state, crtc); 7259 7260 /* 7261 * Ensure we have "Frame Change" event when PSR state is 7262 * SRDENT(PSR1) or DEEP_SLEEP(PSR2). Otherwise DSB vblank 7263 * evasion hangs as PIPEDSL is reading as 0. 7264 */ 7265 intel_psr_trigger_frame_change_event(new_crtc_state->dsb_commit, 7266 state, crtc); 7267 7268 if (new_crtc_state->use_dsb) 7269 intel_dsb_vblank_evade(state, new_crtc_state->dsb_commit); 7270 7271 if (intel_crtc_needs_color_update(new_crtc_state)) 7272 intel_color_commit_arm(new_crtc_state->dsb_commit, 7273 new_crtc_state); 7274 bdw_set_pipe_misc(new_crtc_state->dsb_commit, 7275 new_crtc_state); 7276 intel_psr2_program_trans_man_trk_ctl(new_crtc_state->dsb_commit, 7277 new_crtc_state); 7278 intel_crtc_planes_update_arm(new_crtc_state->dsb_commit, 7279 state, crtc); 7280 7281 if (DISPLAY_VER(display) >= 9) 7282 skl_detach_scalers(new_crtc_state->dsb_commit, 7283 new_crtc_state); 7284 7285 /* Wa_18034343758 */ 7286 if (new_crtc_state->use_flipq) 7287 intel_flipq_unhalt_dmc(new_crtc_state->dsb_commit, crtc); 7288 } 7289 7290 if (intel_color_uses_chained_dsb(new_crtc_state)) 7291 intel_dsb_chain(state, new_crtc_state->dsb_commit, 7292 new_crtc_state->dsb_color, true); 7293 else if (intel_color_uses_gosub_dsb(new_crtc_state)) 7294 intel_dsb_gosub(new_crtc_state->dsb_commit, 7295 new_crtc_state->dsb_color); 7296 7297 if (new_crtc_state->use_dsb && !intel_color_uses_chained_dsb(new_crtc_state)) { 7298 intel_dsb_wait_vblanks(new_crtc_state->dsb_commit, 1); 7299 7300 intel_vrr_send_push(new_crtc_state->dsb_commit, new_crtc_state); 7301 intel_dsb_wait_vblank_delay(state, new_crtc_state->dsb_commit); 7302 intel_vrr_check_push_sent(new_crtc_state->dsb_commit, 7303 new_crtc_state); 7304 intel_dsb_interrupt(new_crtc_state->dsb_commit); 7305 } 7306 7307 intel_dsb_finish(new_crtc_state->dsb_commit); 7308 } 7309 7310 static void intel_atomic_commit_tail(struct intel_atomic_state *state) 7311 { 7312 struct intel_display *display = to_intel_display(state); 7313 struct drm_i915_private __maybe_unused *dev_priv = to_i915(display->drm); 7314 struct intel_crtc_state *new_crtc_state, *old_crtc_state; 7315 struct intel_crtc *crtc; 7316 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {}; 7317 intel_wakeref_t wakeref = NULL; 7318 int i; 7319 7320 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 7321 intel_atomic_dsb_prepare(state, crtc); 7322 7323 intel_atomic_commit_fence_wait(state); 7324 7325 intel_td_flush(display); 7326 7327 intel_atomic_prepare_plane_clear_colors(state); 7328 7329 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 7330 intel_fbc_prepare_dirty_rect(state, crtc); 7331 7332 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 7333 intel_atomic_dsb_finish(state, crtc); 7334 7335 drm_atomic_helper_wait_for_dependencies(&state->base); 7336 drm_dp_mst_atomic_wait_for_dependencies(&state->base); 7337 intel_atomic_global_state_wait_for_dependencies(state); 7338 7339 /* 7340 * During full modesets we write a lot of registers, wait 7341 * for PLLs, etc. Doing that while DC states are enabled 7342 * is not a good idea. 7343 * 7344 * During fastsets and other updates we also need to 7345 * disable DC states due to the following scenario: 7346 * 1. DC5 exit and PSR exit happen 7347 * 2. Some or all _noarm() registers are written 7348 * 3. Due to some long delay PSR is re-entered 7349 * 4. DC5 entry -> DMC saves the already written new 7350 * _noarm() registers and the old not yet written 7351 * _arm() registers 7352 * 5. DC5 exit -> DMC restores a mixture of old and 7353 * new register values and arms the update 7354 * 6. PSR exit -> hardware latches a mixture of old and 7355 * new register values -> corrupted frame, or worse 7356 * 7. New _arm() registers are finally written 7357 * 8. Hardware finally latches a complete set of new 7358 * register values, and subsequent frames will be OK again 7359 * 7360 * Also note that due to the pipe CSC hardware issues on 7361 * SKL/GLK DC states must remain off until the pipe CSC 7362 * state readout has happened. Otherwise we risk corrupting 7363 * the CSC latched register values with the readout (see 7364 * skl_read_csc() and skl_color_commit_noarm()). 7365 */ 7366 wakeref = intel_display_power_get(display, POWER_DOMAIN_DC_OFF); 7367 7368 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7369 new_crtc_state, i) { 7370 if (intel_crtc_needs_modeset(new_crtc_state) || 7371 intel_crtc_needs_fastset(new_crtc_state)) 7372 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]); 7373 } 7374 7375 intel_commit_modeset_disables(state); 7376 7377 intel_dp_tunnel_atomic_alloc_bw(state); 7378 7379 /* FIXME: Eventually get rid of our crtc->config pointer */ 7380 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 7381 crtc->config = new_crtc_state; 7382 7383 /* 7384 * In XE_LPD+ Pmdemand combines many parameters such as voltage index, 7385 * plls, cdclk frequency, QGV point selection parameter etc. Voltage 7386 * index, cdclk/ddiclk frequencies are supposed to be configured before 7387 * the cdclk config is set. 7388 */ 7389 intel_pmdemand_pre_plane_update(state); 7390 7391 if (state->modeset) { 7392 drm_atomic_helper_update_legacy_modeset_state(display->drm, &state->base); 7393 7394 intel_set_cdclk_pre_plane_update(state); 7395 7396 intel_modeset_verify_disabled(state); 7397 } 7398 7399 intel_sagv_pre_plane_update(state); 7400 7401 /* Complete the events for pipes that have now been disabled */ 7402 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7403 bool modeset = intel_crtc_needs_modeset(new_crtc_state); 7404 7405 /* Complete events for now disable pipes here. */ 7406 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) { 7407 spin_lock_irq(&display->drm->event_lock); 7408 drm_crtc_send_vblank_event(&crtc->base, 7409 new_crtc_state->uapi.event); 7410 spin_unlock_irq(&display->drm->event_lock); 7411 7412 new_crtc_state->uapi.event = NULL; 7413 } 7414 } 7415 7416 intel_encoders_update_prepare(state); 7417 7418 intel_dbuf_pre_plane_update(state); 7419 7420 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7421 if (new_crtc_state->do_async_flip) 7422 intel_crtc_enable_flip_done(state, crtc); 7423 } 7424 7425 /* Now enable the clocks, plane, pipe, and connectors that we set up. */ 7426 display->funcs.display->commit_modeset_enables(state); 7427 7428 /* FIXME probably need to sequence this properly */ 7429 intel_program_dpkgc_latency(state); 7430 7431 intel_wait_for_vblank_workers(state); 7432 7433 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here 7434 * already, but still need the state for the delayed optimization. To 7435 * fix this: 7436 * - wrap the optimization/post_plane_update stuff into a per-crtc work. 7437 * - schedule that vblank worker _before_ calling hw_done 7438 * - at the start of commit_tail, cancel it _synchrously 7439 * - switch over to the vblank wait helper in the core after that since 7440 * we don't need out special handling any more. 7441 */ 7442 drm_atomic_helper_wait_for_flip_done(display->drm, &state->base); 7443 7444 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { 7445 if (new_crtc_state->do_async_flip) 7446 intel_crtc_disable_flip_done(state, crtc); 7447 7448 intel_atomic_dsb_wait_commit(new_crtc_state); 7449 7450 if (!state->base.legacy_cursor_update && !new_crtc_state->use_dsb) 7451 intel_vrr_check_push_sent(NULL, new_crtc_state); 7452 7453 if (new_crtc_state->use_flipq) 7454 intel_flipq_disable(new_crtc_state); 7455 } 7456 7457 /* 7458 * Now that the vblank has passed, we can go ahead and program the 7459 * optimal watermarks on platforms that need two-step watermark 7460 * programming. 7461 * 7462 * TODO: Move this (and other cleanup) to an async worker eventually. 7463 */ 7464 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, 7465 new_crtc_state, i) { 7466 /* 7467 * Gen2 reports pipe underruns whenever all planes are disabled. 7468 * So re-enable underrun reporting after some planes get enabled. 7469 * 7470 * We do this before .optimize_watermarks() so that we have a 7471 * chance of catching underruns with the intermediate watermarks 7472 * vs. the new plane configuration. 7473 */ 7474 if (DISPLAY_VER(display) == 2 && planes_enabling(old_crtc_state, new_crtc_state)) 7475 intel_set_cpu_fifo_underrun_reporting(display, crtc->pipe, true); 7476 7477 intel_optimize_watermarks(state, crtc); 7478 } 7479 7480 intel_dbuf_post_plane_update(state); 7481 7482 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { 7483 intel_post_plane_update(state, crtc); 7484 7485 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]); 7486 7487 intel_modeset_verify_crtc(state, crtc); 7488 7489 intel_post_plane_update_after_readout(state, crtc); 7490 7491 /* 7492 * DSB cleanup is done in cleanup_work aligning with framebuffer 7493 * cleanup. So copy and reset the dsb structure to sync with 7494 * commit_done and later do dsb cleanup in cleanup_work. 7495 * 7496 * FIXME get rid of this funny new->old swapping 7497 */ 7498 old_crtc_state->dsb_color = fetch_and_zero(&new_crtc_state->dsb_color); 7499 old_crtc_state->dsb_commit = fetch_and_zero(&new_crtc_state->dsb_commit); 7500 } 7501 7502 /* Underruns don't always raise interrupts, so check manually */ 7503 intel_check_cpu_fifo_underruns(display); 7504 intel_check_pch_fifo_underruns(display); 7505 7506 if (state->modeset) 7507 intel_verify_planes(state); 7508 7509 intel_sagv_post_plane_update(state); 7510 if (state->modeset) 7511 intel_set_cdclk_post_plane_update(state); 7512 intel_pmdemand_post_plane_update(state); 7513 7514 drm_atomic_helper_commit_hw_done(&state->base); 7515 intel_atomic_global_state_commit_done(state); 7516 7517 if (state->modeset) { 7518 /* As one of the primary mmio accessors, KMS has a high 7519 * likelihood of triggering bugs in unclaimed access. After we 7520 * finish modesetting, see if an error has been flagged, and if 7521 * so enable debugging for the next modeset - and hope we catch 7522 * the culprit. 7523 */ 7524 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore); 7525 } 7526 /* 7527 * Delay re-enabling DC states by 17 ms to avoid the off->on->off 7528 * toggling overhead at and above 60 FPS. 7529 */ 7530 intel_display_power_put_async_delay(display, POWER_DOMAIN_DC_OFF, wakeref, 17); 7531 intel_display_rpm_put(display, state->wakeref); 7532 7533 /* 7534 * Defer the cleanup of the old state to a separate worker to not 7535 * impede the current task (userspace for blocking modesets) that 7536 * are executed inline. For out-of-line asynchronous modesets/flips, 7537 * deferring to a new worker seems overkill, but we would place a 7538 * schedule point (cond_resched()) here anyway to keep latencies 7539 * down. 7540 */ 7541 INIT_WORK(&state->cleanup_work, intel_atomic_cleanup_work); 7542 queue_work(display->wq.cleanup, &state->cleanup_work); 7543 } 7544 7545 static void intel_atomic_commit_work(struct work_struct *work) 7546 { 7547 struct intel_atomic_state *state = 7548 container_of(work, struct intel_atomic_state, base.commit_work); 7549 7550 intel_atomic_commit_tail(state); 7551 } 7552 7553 static void intel_atomic_track_fbs(struct intel_atomic_state *state) 7554 { 7555 struct intel_plane_state *old_plane_state, *new_plane_state; 7556 struct intel_plane *plane; 7557 int i; 7558 7559 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state, 7560 new_plane_state, i) 7561 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb), 7562 to_intel_frontbuffer(new_plane_state->hw.fb), 7563 plane->frontbuffer_bit); 7564 } 7565 7566 static int intel_atomic_setup_commit(struct intel_atomic_state *state, bool nonblock) 7567 { 7568 int ret; 7569 7570 ret = drm_atomic_helper_setup_commit(&state->base, nonblock); 7571 if (ret) 7572 return ret; 7573 7574 ret = intel_atomic_global_state_setup_commit(state); 7575 if (ret) 7576 return ret; 7577 7578 return 0; 7579 } 7580 7581 static int intel_atomic_swap_state(struct intel_atomic_state *state) 7582 { 7583 int ret; 7584 7585 ret = drm_atomic_helper_swap_state(&state->base, true); 7586 if (ret) 7587 return ret; 7588 7589 intel_atomic_swap_global_state(state); 7590 7591 intel_dpll_swap_state(state); 7592 7593 intel_atomic_track_fbs(state); 7594 7595 return 0; 7596 } 7597 7598 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state, 7599 bool nonblock) 7600 { 7601 struct intel_display *display = to_intel_display(dev); 7602 struct intel_atomic_state *state = to_intel_atomic_state(_state); 7603 int ret = 0; 7604 7605 state->wakeref = intel_display_rpm_get(display); 7606 7607 /* 7608 * The intel_legacy_cursor_update() fast path takes care 7609 * of avoiding the vblank waits for simple cursor 7610 * movement and flips. For cursor on/off and size changes, 7611 * we want to perform the vblank waits so that watermark 7612 * updates happen during the correct frames. Gen9+ have 7613 * double buffered watermarks and so shouldn't need this. 7614 * 7615 * Unset state->legacy_cursor_update before the call to 7616 * drm_atomic_helper_setup_commit() because otherwise 7617 * drm_atomic_helper_wait_for_flip_done() is a noop and 7618 * we get FIFO underruns because we didn't wait 7619 * for vblank. 7620 * 7621 * FIXME doing watermarks and fb cleanup from a vblank worker 7622 * (assuming we had any) would solve these problems. 7623 */ 7624 if (DISPLAY_VER(display) < 9 && state->base.legacy_cursor_update) { 7625 struct intel_crtc_state *new_crtc_state; 7626 struct intel_crtc *crtc; 7627 int i; 7628 7629 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) 7630 if (new_crtc_state->wm.need_postvbl_update || 7631 new_crtc_state->update_wm_post) 7632 state->base.legacy_cursor_update = false; 7633 } 7634 7635 ret = intel_atomic_prepare_commit(state); 7636 if (ret) { 7637 drm_dbg_atomic(display->drm, 7638 "Preparing state failed with %i\n", ret); 7639 intel_display_rpm_put(display, state->wakeref); 7640 return ret; 7641 } 7642 7643 ret = intel_atomic_setup_commit(state, nonblock); 7644 if (!ret) 7645 ret = intel_atomic_swap_state(state); 7646 7647 if (ret) { 7648 drm_atomic_helper_unprepare_planes(dev, &state->base); 7649 intel_display_rpm_put(display, state->wakeref); 7650 return ret; 7651 } 7652 7653 drm_atomic_state_get(&state->base); 7654 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work); 7655 7656 if (nonblock && state->modeset) { 7657 queue_work(display->wq.modeset, &state->base.commit_work); 7658 } else if (nonblock) { 7659 queue_work(display->wq.flip, &state->base.commit_work); 7660 } else { 7661 if (state->modeset) 7662 flush_workqueue(display->wq.modeset); 7663 intel_atomic_commit_tail(state); 7664 } 7665 7666 return 0; 7667 } 7668 7669 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder) 7670 { 7671 struct intel_display *display = to_intel_display(encoder); 7672 struct intel_encoder *source_encoder; 7673 u32 possible_clones = 0; 7674 7675 for_each_intel_encoder(display->drm, source_encoder) { 7676 if (encoders_cloneable(encoder, source_encoder)) 7677 possible_clones |= drm_encoder_mask(&source_encoder->base); 7678 } 7679 7680 return possible_clones; 7681 } 7682 7683 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder) 7684 { 7685 struct intel_display *display = to_intel_display(encoder); 7686 struct intel_crtc *crtc; 7687 u32 possible_crtcs = 0; 7688 7689 for_each_intel_crtc_in_pipe_mask(display->drm, crtc, encoder->pipe_mask) 7690 possible_crtcs |= drm_crtc_mask(&crtc->base); 7691 7692 return possible_crtcs; 7693 } 7694 7695 static bool ilk_has_edp_a(struct intel_display *display) 7696 { 7697 if (!display->platform.mobile) 7698 return false; 7699 7700 if ((intel_de_read(display, DP_A) & DP_DETECTED) == 0) 7701 return false; 7702 7703 if (display->platform.ironlake && (intel_de_read(display, FUSE_STRAP) & ILK_eDP_A_DISABLE)) 7704 return false; 7705 7706 return true; 7707 } 7708 7709 static bool intel_ddi_crt_present(struct intel_display *display) 7710 { 7711 if (DISPLAY_VER(display) >= 9) 7712 return false; 7713 7714 if (display->platform.haswell_ult || display->platform.broadwell_ult) 7715 return false; 7716 7717 if (HAS_PCH_LPT_H(display) && 7718 intel_de_read(display, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) 7719 return false; 7720 7721 /* DDI E can't be used if DDI A requires 4 lanes */ 7722 if (intel_de_read(display, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) 7723 return false; 7724 7725 if (!display->vbt.int_crt_support) 7726 return false; 7727 7728 return true; 7729 } 7730 7731 bool assert_port_valid(struct intel_display *display, enum port port) 7732 { 7733 return !drm_WARN(display->drm, !(DISPLAY_RUNTIME_INFO(display)->port_mask & BIT(port)), 7734 "Platform does not support port %c\n", port_name(port)); 7735 } 7736 7737 void intel_setup_outputs(struct intel_display *display) 7738 { 7739 struct intel_encoder *encoder; 7740 bool dpd_is_edp = false; 7741 7742 intel_pps_unlock_regs_wa(display); 7743 7744 if (!HAS_DISPLAY(display)) 7745 return; 7746 7747 if (HAS_DDI(display)) { 7748 if (intel_ddi_crt_present(display)) 7749 intel_crt_init(display); 7750 7751 intel_bios_for_each_encoder(display, intel_ddi_init); 7752 7753 if (display->platform.geminilake || display->platform.broxton) 7754 vlv_dsi_init(display); 7755 } else if (HAS_PCH_SPLIT(display)) { 7756 int found; 7757 7758 /* 7759 * intel_edp_init_connector() depends on this completing first, 7760 * to prevent the registration of both eDP and LVDS and the 7761 * incorrect sharing of the PPS. 7762 */ 7763 intel_lvds_init(display); 7764 intel_crt_init(display); 7765 7766 dpd_is_edp = intel_dp_is_port_edp(display, PORT_D); 7767 7768 if (ilk_has_edp_a(display)) 7769 g4x_dp_init(display, DP_A, PORT_A); 7770 7771 if (intel_de_read(display, PCH_HDMIB) & SDVO_DETECTED) { 7772 /* PCH SDVOB multiplex with HDMIB */ 7773 found = intel_sdvo_init(display, PCH_SDVOB, PORT_B); 7774 if (!found) 7775 g4x_hdmi_init(display, PCH_HDMIB, PORT_B); 7776 if (!found && (intel_de_read(display, PCH_DP_B) & DP_DETECTED)) 7777 g4x_dp_init(display, PCH_DP_B, PORT_B); 7778 } 7779 7780 if (intel_de_read(display, PCH_HDMIC) & SDVO_DETECTED) 7781 g4x_hdmi_init(display, PCH_HDMIC, PORT_C); 7782 7783 if (!dpd_is_edp && intel_de_read(display, PCH_HDMID) & SDVO_DETECTED) 7784 g4x_hdmi_init(display, PCH_HDMID, PORT_D); 7785 7786 if (intel_de_read(display, PCH_DP_C) & DP_DETECTED) 7787 g4x_dp_init(display, PCH_DP_C, PORT_C); 7788 7789 if (intel_de_read(display, PCH_DP_D) & DP_DETECTED) 7790 g4x_dp_init(display, PCH_DP_D, PORT_D); 7791 } else if (display->platform.valleyview || display->platform.cherryview) { 7792 bool has_edp, has_port; 7793 7794 if (display->platform.valleyview && display->vbt.int_crt_support) 7795 intel_crt_init(display); 7796 7797 /* 7798 * The DP_DETECTED bit is the latched state of the DDC 7799 * SDA pin at boot. However since eDP doesn't require DDC 7800 * (no way to plug in a DP->HDMI dongle) the DDC pins for 7801 * eDP ports may have been muxed to an alternate function. 7802 * Thus we can't rely on the DP_DETECTED bit alone to detect 7803 * eDP ports. Consult the VBT as well as DP_DETECTED to 7804 * detect eDP ports. 7805 * 7806 * Sadly the straps seem to be missing sometimes even for HDMI 7807 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap 7808 * and VBT for the presence of the port. Additionally we can't 7809 * trust the port type the VBT declares as we've seen at least 7810 * HDMI ports that the VBT claim are DP or eDP. 7811 */ 7812 has_edp = intel_dp_is_port_edp(display, PORT_B); 7813 has_port = intel_bios_is_port_present(display, PORT_B); 7814 if (intel_de_read(display, VLV_DP_B) & DP_DETECTED || has_port) 7815 has_edp &= g4x_dp_init(display, VLV_DP_B, PORT_B); 7816 if ((intel_de_read(display, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) 7817 g4x_hdmi_init(display, VLV_HDMIB, PORT_B); 7818 7819 has_edp = intel_dp_is_port_edp(display, PORT_C); 7820 has_port = intel_bios_is_port_present(display, PORT_C); 7821 if (intel_de_read(display, VLV_DP_C) & DP_DETECTED || has_port) 7822 has_edp &= g4x_dp_init(display, VLV_DP_C, PORT_C); 7823 if ((intel_de_read(display, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) 7824 g4x_hdmi_init(display, VLV_HDMIC, PORT_C); 7825 7826 if (display->platform.cherryview) { 7827 /* 7828 * eDP not supported on port D, 7829 * so no need to worry about it 7830 */ 7831 has_port = intel_bios_is_port_present(display, PORT_D); 7832 if (intel_de_read(display, CHV_DP_D) & DP_DETECTED || has_port) 7833 g4x_dp_init(display, CHV_DP_D, PORT_D); 7834 if (intel_de_read(display, CHV_HDMID) & SDVO_DETECTED || has_port) 7835 g4x_hdmi_init(display, CHV_HDMID, PORT_D); 7836 } 7837 7838 vlv_dsi_init(display); 7839 } else if (display->platform.pineview) { 7840 intel_lvds_init(display); 7841 intel_crt_init(display); 7842 } else if (IS_DISPLAY_VER(display, 3, 4)) { 7843 bool found = false; 7844 7845 if (display->platform.mobile) 7846 intel_lvds_init(display); 7847 7848 intel_crt_init(display); 7849 7850 if (intel_de_read(display, GEN3_SDVOB) & SDVO_DETECTED) { 7851 drm_dbg_kms(display->drm, "probing SDVOB\n"); 7852 found = intel_sdvo_init(display, GEN3_SDVOB, PORT_B); 7853 if (!found && display->platform.g4x) { 7854 drm_dbg_kms(display->drm, 7855 "probing HDMI on SDVOB\n"); 7856 g4x_hdmi_init(display, GEN4_HDMIB, PORT_B); 7857 } 7858 7859 if (!found && display->platform.g4x) 7860 g4x_dp_init(display, DP_B, PORT_B); 7861 } 7862 7863 /* Before G4X SDVOC doesn't have its own detect register */ 7864 7865 if (intel_de_read(display, GEN3_SDVOB) & SDVO_DETECTED) { 7866 drm_dbg_kms(display->drm, "probing SDVOC\n"); 7867 found = intel_sdvo_init(display, GEN3_SDVOC, PORT_C); 7868 } 7869 7870 if (!found && (intel_de_read(display, GEN3_SDVOC) & SDVO_DETECTED)) { 7871 7872 if (display->platform.g4x) { 7873 drm_dbg_kms(display->drm, 7874 "probing HDMI on SDVOC\n"); 7875 g4x_hdmi_init(display, GEN4_HDMIC, PORT_C); 7876 } 7877 if (display->platform.g4x) 7878 g4x_dp_init(display, DP_C, PORT_C); 7879 } 7880 7881 if (display->platform.g4x && (intel_de_read(display, DP_D) & DP_DETECTED)) 7882 g4x_dp_init(display, DP_D, PORT_D); 7883 7884 if (SUPPORTS_TV(display)) 7885 intel_tv_init(display); 7886 } else if (DISPLAY_VER(display) == 2) { 7887 if (display->platform.i85x) 7888 intel_lvds_init(display); 7889 7890 intel_crt_init(display); 7891 intel_dvo_init(display); 7892 } 7893 7894 for_each_intel_encoder(display->drm, encoder) { 7895 encoder->base.possible_crtcs = 7896 intel_encoder_possible_crtcs(encoder); 7897 encoder->base.possible_clones = 7898 intel_encoder_possible_clones(encoder); 7899 } 7900 7901 intel_init_pch_refclk(display); 7902 7903 drm_helper_move_panel_connectors_to_head(display->drm); 7904 } 7905 7906 static int max_dotclock(struct intel_display *display) 7907 { 7908 int max_dotclock = display->cdclk.max_dotclk_freq; 7909 7910 if (HAS_ULTRAJOINER(display)) 7911 max_dotclock *= 4; 7912 else if (HAS_UNCOMPRESSED_JOINER(display) || HAS_BIGJOINER(display)) 7913 max_dotclock *= 2; 7914 7915 return max_dotclock; 7916 } 7917 7918 enum drm_mode_status intel_mode_valid(struct drm_device *dev, 7919 const struct drm_display_mode *mode) 7920 { 7921 struct intel_display *display = to_intel_display(dev); 7922 int hdisplay_max, htotal_max; 7923 int vdisplay_max, vtotal_max; 7924 7925 /* 7926 * Can't reject DBLSCAN here because Xorg ddxen can add piles 7927 * of DBLSCAN modes to the output's mode list when they detect 7928 * the scaling mode property on the connector. And they don't 7929 * ask the kernel to validate those modes in any way until 7930 * modeset time at which point the client gets a protocol error. 7931 * So in order to not upset those clients we silently ignore the 7932 * DBLSCAN flag on such connectors. For other connectors we will 7933 * reject modes with the DBLSCAN flag in encoder->compute_config(). 7934 * And we always reject DBLSCAN modes in connector->mode_valid() 7935 * as we never want such modes on the connector's mode list. 7936 */ 7937 7938 if (mode->vscan > 1) 7939 return MODE_NO_VSCAN; 7940 7941 if (mode->flags & DRM_MODE_FLAG_HSKEW) 7942 return MODE_H_ILLEGAL; 7943 7944 if (mode->flags & (DRM_MODE_FLAG_CSYNC | 7945 DRM_MODE_FLAG_NCSYNC | 7946 DRM_MODE_FLAG_PCSYNC)) 7947 return MODE_HSYNC; 7948 7949 if (mode->flags & (DRM_MODE_FLAG_BCAST | 7950 DRM_MODE_FLAG_PIXMUX | 7951 DRM_MODE_FLAG_CLKDIV2)) 7952 return MODE_BAD; 7953 7954 /* 7955 * Reject clearly excessive dotclocks early to 7956 * avoid having to worry about huge integers later. 7957 */ 7958 if (mode->clock > max_dotclock(display)) 7959 return MODE_CLOCK_HIGH; 7960 7961 /* Transcoder timing limits */ 7962 if (DISPLAY_VER(display) >= 11) { 7963 hdisplay_max = 16384; 7964 vdisplay_max = 8192; 7965 htotal_max = 16384; 7966 vtotal_max = 8192; 7967 } else if (DISPLAY_VER(display) >= 9 || 7968 display->platform.broadwell || display->platform.haswell) { 7969 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */ 7970 vdisplay_max = 4096; 7971 htotal_max = 8192; 7972 vtotal_max = 8192; 7973 } else if (DISPLAY_VER(display) >= 3) { 7974 hdisplay_max = 4096; 7975 vdisplay_max = 4096; 7976 htotal_max = 8192; 7977 vtotal_max = 8192; 7978 } else { 7979 hdisplay_max = 2048; 7980 vdisplay_max = 2048; 7981 htotal_max = 4096; 7982 vtotal_max = 4096; 7983 } 7984 7985 if (mode->hdisplay > hdisplay_max || 7986 mode->hsync_start > htotal_max || 7987 mode->hsync_end > htotal_max || 7988 mode->htotal > htotal_max) 7989 return MODE_H_ILLEGAL; 7990 7991 if (mode->vdisplay > vdisplay_max || 7992 mode->vsync_start > vtotal_max || 7993 mode->vsync_end > vtotal_max || 7994 mode->vtotal > vtotal_max) 7995 return MODE_V_ILLEGAL; 7996 7997 return MODE_OK; 7998 } 7999 8000 enum drm_mode_status intel_cpu_transcoder_mode_valid(struct intel_display *display, 8001 const struct drm_display_mode *mode) 8002 { 8003 /* 8004 * Additional transcoder timing limits, 8005 * excluding BXT/GLK DSI transcoders. 8006 */ 8007 if (DISPLAY_VER(display) >= 5) { 8008 if (mode->hdisplay < 64 || 8009 mode->htotal - mode->hdisplay < 32) 8010 return MODE_H_ILLEGAL; 8011 8012 if (mode->vtotal - mode->vdisplay < 5) 8013 return MODE_V_ILLEGAL; 8014 } else { 8015 if (mode->htotal - mode->hdisplay < 32) 8016 return MODE_H_ILLEGAL; 8017 8018 if (mode->vtotal - mode->vdisplay < 3) 8019 return MODE_V_ILLEGAL; 8020 } 8021 8022 /* 8023 * Cantiga+ cannot handle modes with a hsync front porch of 0. 8024 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. 8025 */ 8026 if ((DISPLAY_VER(display) >= 5 || display->platform.g4x) && 8027 mode->hsync_start == mode->hdisplay) 8028 return MODE_H_ILLEGAL; 8029 8030 return MODE_OK; 8031 } 8032 8033 enum drm_mode_status 8034 intel_mode_valid_max_plane_size(struct intel_display *display, 8035 const struct drm_display_mode *mode, 8036 int num_joined_pipes) 8037 { 8038 int plane_width_max, plane_height_max; 8039 8040 /* 8041 * intel_mode_valid() should be 8042 * sufficient on older platforms. 8043 */ 8044 if (DISPLAY_VER(display) < 9) 8045 return MODE_OK; 8046 8047 /* 8048 * Most people will probably want a fullscreen 8049 * plane so let's not advertize modes that are 8050 * too big for that. 8051 */ 8052 if (DISPLAY_VER(display) >= 30) { 8053 plane_width_max = 6144 * num_joined_pipes; 8054 plane_height_max = 4800; 8055 } else if (DISPLAY_VER(display) >= 11) { 8056 plane_width_max = 5120 * num_joined_pipes; 8057 plane_height_max = 4320; 8058 } else { 8059 plane_width_max = 5120; 8060 plane_height_max = 4096; 8061 } 8062 8063 if (mode->hdisplay > plane_width_max) 8064 return MODE_H_ILLEGAL; 8065 8066 if (mode->vdisplay > plane_height_max) 8067 return MODE_V_ILLEGAL; 8068 8069 return MODE_OK; 8070 } 8071 8072 static const struct intel_display_funcs skl_display_funcs = { 8073 .get_pipe_config = hsw_get_pipe_config, 8074 .crtc_enable = hsw_crtc_enable, 8075 .crtc_disable = hsw_crtc_disable, 8076 .commit_modeset_enables = skl_commit_modeset_enables, 8077 .get_initial_plane_config = skl_get_initial_plane_config, 8078 .fixup_initial_plane_config = skl_fixup_initial_plane_config, 8079 }; 8080 8081 static const struct intel_display_funcs ddi_display_funcs = { 8082 .get_pipe_config = hsw_get_pipe_config, 8083 .crtc_enable = hsw_crtc_enable, 8084 .crtc_disable = hsw_crtc_disable, 8085 .commit_modeset_enables = intel_commit_modeset_enables, 8086 .get_initial_plane_config = i9xx_get_initial_plane_config, 8087 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config, 8088 }; 8089 8090 static const struct intel_display_funcs pch_split_display_funcs = { 8091 .get_pipe_config = ilk_get_pipe_config, 8092 .crtc_enable = ilk_crtc_enable, 8093 .crtc_disable = ilk_crtc_disable, 8094 .commit_modeset_enables = intel_commit_modeset_enables, 8095 .get_initial_plane_config = i9xx_get_initial_plane_config, 8096 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config, 8097 }; 8098 8099 static const struct intel_display_funcs vlv_display_funcs = { 8100 .get_pipe_config = i9xx_get_pipe_config, 8101 .crtc_enable = valleyview_crtc_enable, 8102 .crtc_disable = i9xx_crtc_disable, 8103 .commit_modeset_enables = intel_commit_modeset_enables, 8104 .get_initial_plane_config = i9xx_get_initial_plane_config, 8105 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config, 8106 }; 8107 8108 static const struct intel_display_funcs i9xx_display_funcs = { 8109 .get_pipe_config = i9xx_get_pipe_config, 8110 .crtc_enable = i9xx_crtc_enable, 8111 .crtc_disable = i9xx_crtc_disable, 8112 .commit_modeset_enables = intel_commit_modeset_enables, 8113 .get_initial_plane_config = i9xx_get_initial_plane_config, 8114 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config, 8115 }; 8116 8117 /** 8118 * intel_init_display_hooks - initialize the display modesetting hooks 8119 * @display: display device private 8120 */ 8121 void intel_init_display_hooks(struct intel_display *display) 8122 { 8123 if (DISPLAY_VER(display) >= 9) { 8124 display->funcs.display = &skl_display_funcs; 8125 } else if (HAS_DDI(display)) { 8126 display->funcs.display = &ddi_display_funcs; 8127 } else if (HAS_PCH_SPLIT(display)) { 8128 display->funcs.display = &pch_split_display_funcs; 8129 } else if (display->platform.cherryview || 8130 display->platform.valleyview) { 8131 display->funcs.display = &vlv_display_funcs; 8132 } else { 8133 display->funcs.display = &i9xx_display_funcs; 8134 } 8135 } 8136 8137 int intel_initial_commit(struct intel_display *display) 8138 { 8139 struct drm_atomic_state *state = NULL; 8140 struct drm_modeset_acquire_ctx ctx; 8141 struct intel_crtc *crtc; 8142 int ret = 0; 8143 8144 state = drm_atomic_state_alloc(display->drm); 8145 if (!state) 8146 return -ENOMEM; 8147 8148 drm_modeset_acquire_init(&ctx, 0); 8149 8150 state->acquire_ctx = &ctx; 8151 to_intel_atomic_state(state)->internal = true; 8152 8153 retry: 8154 for_each_intel_crtc(display->drm, crtc) { 8155 struct intel_crtc_state *crtc_state = 8156 intel_atomic_get_crtc_state(state, crtc); 8157 8158 if (IS_ERR(crtc_state)) { 8159 ret = PTR_ERR(crtc_state); 8160 goto out; 8161 } 8162 8163 if (!crtc_state->hw.active) 8164 crtc_state->inherited = false; 8165 8166 if (crtc_state->hw.active) { 8167 struct intel_encoder *encoder; 8168 8169 ret = drm_atomic_add_affected_planes(state, &crtc->base); 8170 if (ret) 8171 goto out; 8172 8173 /* 8174 * FIXME hack to force a LUT update to avoid the 8175 * plane update forcing the pipe gamma on without 8176 * having a proper LUT loaded. Remove once we 8177 * have readout for pipe gamma enable. 8178 */ 8179 crtc_state->uapi.color_mgmt_changed = true; 8180 8181 for_each_intel_encoder_mask(display->drm, encoder, 8182 crtc_state->uapi.encoder_mask) { 8183 if (encoder->initial_fastset_check && 8184 !encoder->initial_fastset_check(encoder, crtc_state)) { 8185 ret = drm_atomic_add_affected_connectors(state, 8186 &crtc->base); 8187 if (ret) 8188 goto out; 8189 } 8190 } 8191 } 8192 } 8193 8194 ret = drm_atomic_commit(state); 8195 8196 out: 8197 if (ret == -EDEADLK) { 8198 drm_atomic_state_clear(state); 8199 drm_modeset_backoff(&ctx); 8200 goto retry; 8201 } 8202 8203 drm_atomic_state_put(state); 8204 8205 drm_modeset_drop_locks(&ctx); 8206 drm_modeset_acquire_fini(&ctx); 8207 8208 return ret; 8209 } 8210 8211 void i830_enable_pipe(struct intel_display *display, enum pipe pipe) 8212 { 8213 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 8214 enum transcoder cpu_transcoder = (enum transcoder)pipe; 8215 /* 640x480@60Hz, ~25175 kHz */ 8216 struct dpll clock = { 8217 .m1 = 18, 8218 .m2 = 7, 8219 .p1 = 13, 8220 .p2 = 4, 8221 .n = 2, 8222 }; 8223 u32 dpll, fp; 8224 int i; 8225 8226 drm_WARN_ON(display->drm, 8227 i9xx_calc_dpll_params(48000, &clock) != 25154); 8228 8229 drm_dbg_kms(display->drm, 8230 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n", 8231 pipe_name(pipe), clock.vco, clock.dot); 8232 8233 fp = i9xx_dpll_compute_fp(&clock); 8234 dpll = DPLL_DVO_2X_MODE | 8235 DPLL_VGA_MODE_DIS | 8236 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) | 8237 PLL_P2_DIVIDE_BY_4 | 8238 PLL_REF_INPUT_DREFCLK | 8239 DPLL_VCO_ENABLE; 8240 8241 intel_de_write(display, TRANS_HTOTAL(display, cpu_transcoder), 8242 HACTIVE(640 - 1) | HTOTAL(800 - 1)); 8243 intel_de_write(display, TRANS_HBLANK(display, cpu_transcoder), 8244 HBLANK_START(640 - 1) | HBLANK_END(800 - 1)); 8245 intel_de_write(display, TRANS_HSYNC(display, cpu_transcoder), 8246 HSYNC_START(656 - 1) | HSYNC_END(752 - 1)); 8247 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder), 8248 VACTIVE(480 - 1) | VTOTAL(525 - 1)); 8249 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder), 8250 VBLANK_START(480 - 1) | VBLANK_END(525 - 1)); 8251 intel_de_write(display, TRANS_VSYNC(display, cpu_transcoder), 8252 VSYNC_START(490 - 1) | VSYNC_END(492 - 1)); 8253 intel_de_write(display, PIPESRC(display, pipe), 8254 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1)); 8255 8256 intel_de_write(display, FP0(pipe), fp); 8257 intel_de_write(display, FP1(pipe), fp); 8258 8259 /* 8260 * Apparently we need to have VGA mode enabled prior to changing 8261 * the P1/P2 dividers. Otherwise the DPLL will keep using the old 8262 * dividers, even though the register value does change. 8263 */ 8264 intel_de_write(display, DPLL(display, pipe), 8265 dpll & ~DPLL_VGA_MODE_DIS); 8266 intel_de_write(display, DPLL(display, pipe), dpll); 8267 8268 /* Wait for the clocks to stabilize. */ 8269 intel_de_posting_read(display, DPLL(display, pipe)); 8270 udelay(150); 8271 8272 /* The pixel multiplier can only be updated once the 8273 * DPLL is enabled and the clocks are stable. 8274 * 8275 * So write it again. 8276 */ 8277 intel_de_write(display, DPLL(display, pipe), dpll); 8278 8279 /* We do this three times for luck */ 8280 for (i = 0; i < 3 ; i++) { 8281 intel_de_write(display, DPLL(display, pipe), dpll); 8282 intel_de_posting_read(display, DPLL(display, pipe)); 8283 udelay(150); /* wait for warmup */ 8284 } 8285 8286 intel_de_write(display, TRANSCONF(display, pipe), TRANSCONF_ENABLE); 8287 intel_de_posting_read(display, TRANSCONF(display, pipe)); 8288 8289 intel_wait_for_pipe_scanline_moving(crtc); 8290 } 8291 8292 void i830_disable_pipe(struct intel_display *display, enum pipe pipe) 8293 { 8294 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 8295 8296 drm_dbg_kms(display->drm, "disabling pipe %c due to force quirk\n", 8297 pipe_name(pipe)); 8298 8299 drm_WARN_ON(display->drm, 8300 intel_de_read(display, DSPCNTR(display, PLANE_A)) & DISP_ENABLE); 8301 drm_WARN_ON(display->drm, 8302 intel_de_read(display, DSPCNTR(display, PLANE_B)) & DISP_ENABLE); 8303 drm_WARN_ON(display->drm, 8304 intel_de_read(display, DSPCNTR(display, PLANE_C)) & DISP_ENABLE); 8305 drm_WARN_ON(display->drm, 8306 intel_de_read(display, CURCNTR(display, PIPE_A)) & MCURSOR_MODE_MASK); 8307 drm_WARN_ON(display->drm, 8308 intel_de_read(display, CURCNTR(display, PIPE_B)) & MCURSOR_MODE_MASK); 8309 8310 intel_de_write(display, TRANSCONF(display, pipe), 0); 8311 intel_de_posting_read(display, TRANSCONF(display, pipe)); 8312 8313 intel_wait_for_pipe_scanline_stopped(crtc); 8314 8315 intel_de_write(display, DPLL(display, pipe), DPLL_VGA_MODE_DIS); 8316 intel_de_posting_read(display, DPLL(display, pipe)); 8317 } 8318 8319 bool intel_scanout_needs_vtd_wa(struct intel_display *display) 8320 { 8321 struct drm_i915_private *i915 = to_i915(display->drm); 8322 8323 return IS_DISPLAY_VER(display, 6, 11) && i915_vtd_active(i915); 8324 } 8325