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