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