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