1 /* 2 * Copyright © 2008 Intel Corporation 3 * 2014 Red Hat Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 */ 25 26 #include <drm/drm_atomic.h> 27 #include <drm/drm_atomic_helper.h> 28 #include <drm/drm_edid.h> 29 #include <drm/drm_fixed.h> 30 #include <drm/drm_probe_helper.h> 31 32 #include "i915_drv.h" 33 #include "i915_reg.h" 34 #include "intel_atomic.h" 35 #include "intel_audio.h" 36 #include "intel_connector.h" 37 #include "intel_crtc.h" 38 #include "intel_ddi.h" 39 #include "intel_de.h" 40 #include "intel_display_driver.h" 41 #include "intel_display_types.h" 42 #include "intel_dp.h" 43 #include "intel_dp_hdcp.h" 44 #include "intel_dp_link_training.h" 45 #include "intel_dp_mst.h" 46 #include "intel_dp_test.h" 47 #include "intel_dp_tunnel.h" 48 #include "intel_dpio_phy.h" 49 #include "intel_hdcp.h" 50 #include "intel_hotplug.h" 51 #include "intel_link_bw.h" 52 #include "intel_psr.h" 53 #include "intel_vdsc.h" 54 #include "skl_scaler.h" 55 56 static int intel_dp_mst_max_dpt_bpp(const struct intel_crtc_state *crtc_state, 57 bool dsc) 58 { 59 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 60 const struct drm_display_mode *adjusted_mode = 61 &crtc_state->hw.adjusted_mode; 62 63 if (!intel_dp_is_uhbr(crtc_state) || DISPLAY_VER(i915) >= 20 || !dsc) 64 return INT_MAX; 65 66 /* 67 * DSC->DPT interface width: 68 * ICL-MTL: 72 bits (each branch has 72 bits, only left branch is used) 69 * LNL+: 144 bits (not a bottleneck in any config) 70 * 71 * Bspec/49259 suggests that the FEC overhead needs to be 72 * applied here, though HW people claim that neither this FEC 73 * or any other overhead is applicable here (that is the actual 74 * available_bw is just symbol_clock * 72). However based on 75 * testing on MTL-P the 76 * - DELL U3224KBA display 77 * - Unigraf UCD-500 CTS test sink 78 * devices the 79 * - 5120x2880/995.59Mhz 80 * - 6016x3384/1357.23Mhz 81 * - 6144x3456/1413.39Mhz 82 * modes (all the ones having a DPT limit on the above devices), 83 * both the channel coding efficiency and an additional 3% 84 * overhead needs to be accounted for. 85 */ 86 return div64_u64(mul_u32_u32(intel_dp_link_symbol_clock(crtc_state->port_clock) * 72, 87 drm_dp_bw_channel_coding_efficiency(true)), 88 mul_u32_u32(adjusted_mode->crtc_clock, 1030000)); 89 } 90 91 static int intel_dp_mst_bw_overhead(const struct intel_crtc_state *crtc_state, 92 const struct intel_connector *connector, 93 bool ssc, bool dsc, int bpp_x16) 94 { 95 const struct drm_display_mode *adjusted_mode = 96 &crtc_state->hw.adjusted_mode; 97 unsigned long flags = DRM_DP_BW_OVERHEAD_MST; 98 int dsc_slice_count = 0; 99 int overhead; 100 101 flags |= intel_dp_is_uhbr(crtc_state) ? DRM_DP_BW_OVERHEAD_UHBR : 0; 102 flags |= ssc ? DRM_DP_BW_OVERHEAD_SSC_REF_CLK : 0; 103 flags |= crtc_state->fec_enable ? DRM_DP_BW_OVERHEAD_FEC : 0; 104 105 if (dsc) { 106 int num_joined_pipes = intel_crtc_num_joined_pipes(crtc_state); 107 108 flags |= DRM_DP_BW_OVERHEAD_DSC; 109 dsc_slice_count = intel_dp_dsc_get_slice_count(connector, 110 adjusted_mode->clock, 111 adjusted_mode->hdisplay, 112 num_joined_pipes); 113 } 114 115 overhead = drm_dp_bw_overhead(crtc_state->lane_count, 116 adjusted_mode->hdisplay, 117 dsc_slice_count, 118 bpp_x16, 119 flags); 120 121 /* 122 * TODO: clarify whether a minimum required by the fixed FEC overhead 123 * in the bspec audio programming sequence is required here. 124 */ 125 return max(overhead, intel_dp_bw_fec_overhead(crtc_state->fec_enable)); 126 } 127 128 static void intel_dp_mst_compute_m_n(const struct intel_crtc_state *crtc_state, 129 const struct intel_connector *connector, 130 int overhead, 131 int bpp_x16, 132 struct intel_link_m_n *m_n) 133 { 134 const struct drm_display_mode *adjusted_mode = 135 &crtc_state->hw.adjusted_mode; 136 137 /* TODO: Check WA 14013163432 to set data M/N for full BW utilization. */ 138 intel_link_compute_m_n(bpp_x16, crtc_state->lane_count, 139 adjusted_mode->crtc_clock, 140 crtc_state->port_clock, 141 overhead, 142 m_n); 143 144 m_n->tu = DIV_ROUND_UP_ULL(mul_u32_u32(m_n->data_m, 64), m_n->data_n); 145 } 146 147 static int intel_dp_mst_calc_pbn(int pixel_clock, int bpp_x16, int bw_overhead) 148 { 149 int effective_data_rate = 150 intel_dp_effective_data_rate(pixel_clock, bpp_x16, bw_overhead); 151 152 /* 153 * TODO: Use drm_dp_calc_pbn_mode() instead, once it's converted 154 * to calculate PBN with the BW overhead passed to it. 155 */ 156 return DIV_ROUND_UP(effective_data_rate * 64, 54 * 1000); 157 } 158 159 static int intel_dp_mst_find_vcpi_slots_for_bpp(struct intel_encoder *encoder, 160 struct intel_crtc_state *crtc_state, 161 int max_bpp, 162 int min_bpp, 163 struct link_config_limits *limits, 164 struct drm_connector_state *conn_state, 165 int step, 166 bool dsc) 167 { 168 struct drm_atomic_state *state = crtc_state->uapi.state; 169 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 170 struct intel_dp *intel_dp = &intel_mst->primary->dp; 171 struct drm_dp_mst_topology_state *mst_state; 172 struct intel_connector *connector = 173 to_intel_connector(conn_state->connector); 174 struct drm_i915_private *i915 = to_i915(connector->base.dev); 175 const struct drm_display_mode *adjusted_mode = 176 &crtc_state->hw.adjusted_mode; 177 int bpp, slots = -EINVAL; 178 int max_dpt_bpp; 179 int ret = 0; 180 181 mst_state = drm_atomic_get_mst_topology_state(state, &intel_dp->mst_mgr); 182 if (IS_ERR(mst_state)) 183 return PTR_ERR(mst_state); 184 185 crtc_state->lane_count = limits->max_lane_count; 186 crtc_state->port_clock = limits->max_rate; 187 188 if (dsc) { 189 if (!intel_dp_supports_fec(intel_dp, connector, crtc_state)) 190 return -EINVAL; 191 192 crtc_state->fec_enable = !intel_dp_is_uhbr(crtc_state); 193 } 194 195 mst_state->pbn_div = drm_dp_get_vc_payload_bw(&intel_dp->mst_mgr, 196 crtc_state->port_clock, 197 crtc_state->lane_count); 198 199 max_dpt_bpp = intel_dp_mst_max_dpt_bpp(crtc_state, dsc); 200 if (max_bpp > max_dpt_bpp) { 201 drm_dbg_kms(&i915->drm, "Limiting bpp to max DPT bpp (%d -> %d)\n", 202 max_bpp, max_dpt_bpp); 203 max_bpp = max_dpt_bpp; 204 } 205 206 drm_dbg_kms(&i915->drm, "Looking for slots in range min bpp %d max bpp %d\n", 207 min_bpp, max_bpp); 208 209 for (bpp = max_bpp; bpp >= min_bpp; bpp -= step) { 210 int local_bw_overhead; 211 int remote_bw_overhead; 212 int link_bpp_x16; 213 int remote_tu; 214 fixed20_12 pbn; 215 216 drm_dbg_kms(&i915->drm, "Trying bpp %d\n", bpp); 217 218 link_bpp_x16 = fxp_q4_from_int(dsc ? bpp : 219 intel_dp_output_bpp(crtc_state->output_format, bpp)); 220 221 local_bw_overhead = intel_dp_mst_bw_overhead(crtc_state, connector, 222 false, dsc, link_bpp_x16); 223 remote_bw_overhead = intel_dp_mst_bw_overhead(crtc_state, connector, 224 true, dsc, link_bpp_x16); 225 226 intel_dp_mst_compute_m_n(crtc_state, connector, 227 local_bw_overhead, 228 link_bpp_x16, 229 &crtc_state->dp_m_n); 230 231 /* 232 * The TU size programmed to the HW determines which slots in 233 * an MTP frame are used for this stream, which needs to match 234 * the payload size programmed to the first downstream branch 235 * device's payload table. 236 * 237 * Note that atm the payload's PBN value DRM core sends via 238 * the ALLOCATE_PAYLOAD side-band message matches the payload 239 * size (which it calculates from the PBN value) it programs 240 * to the first branch device's payload table. The allocation 241 * in the payload table could be reduced though (to 242 * crtc_state->dp_m_n.tu), provided that the driver doesn't 243 * enable SSC on the corresponding link. 244 */ 245 pbn.full = dfixed_const(intel_dp_mst_calc_pbn(adjusted_mode->crtc_clock, 246 link_bpp_x16, 247 remote_bw_overhead)); 248 remote_tu = DIV_ROUND_UP(pbn.full, mst_state->pbn_div.full); 249 250 /* 251 * Aligning the TUs ensures that symbols consisting of multiple 252 * (4) symbol cycles don't get split between two consecutive 253 * MTPs, as required by Bspec. 254 * TODO: remove the alignment restriction for 128b/132b links 255 * on some platforms, where Bspec allows this. 256 */ 257 remote_tu = ALIGN(remote_tu, 4 / crtc_state->lane_count); 258 259 /* 260 * Also align PBNs accordingly, since MST core will derive its 261 * own copy of TU from the PBN in drm_dp_atomic_find_time_slots(). 262 * The above comment about the difference between the PBN 263 * allocated for the whole path and the TUs allocated for the 264 * first branch device's link also applies here. 265 */ 266 pbn.full = remote_tu * mst_state->pbn_div.full; 267 crtc_state->pbn = dfixed_trunc(pbn); 268 269 drm_WARN_ON(&i915->drm, remote_tu < crtc_state->dp_m_n.tu); 270 crtc_state->dp_m_n.tu = remote_tu; 271 272 slots = drm_dp_atomic_find_time_slots(state, &intel_dp->mst_mgr, 273 connector->port, 274 crtc_state->pbn); 275 if (slots == -EDEADLK) 276 return slots; 277 278 if (slots >= 0) { 279 drm_WARN_ON(&i915->drm, slots != crtc_state->dp_m_n.tu); 280 281 break; 282 } 283 } 284 285 /* We failed to find a proper bpp/timeslots, return error */ 286 if (ret) 287 slots = ret; 288 289 if (slots < 0) { 290 drm_dbg_kms(&i915->drm, "failed finding vcpi slots:%d\n", 291 slots); 292 } else { 293 if (!dsc) 294 crtc_state->pipe_bpp = bpp; 295 else 296 crtc_state->dsc.compressed_bpp_x16 = fxp_q4_from_int(bpp); 297 drm_dbg_kms(&i915->drm, "Got %d slots for pipe bpp %d dsc %d\n", slots, bpp, dsc); 298 } 299 300 return slots; 301 } 302 303 static int intel_dp_mst_compute_link_config(struct intel_encoder *encoder, 304 struct intel_crtc_state *crtc_state, 305 struct drm_connector_state *conn_state, 306 struct link_config_limits *limits) 307 { 308 int slots = -EINVAL; 309 310 /* 311 * FIXME: allocate the BW according to link_bpp, which in the case of 312 * YUV420 is only half of the pipe bpp value. 313 */ 314 slots = intel_dp_mst_find_vcpi_slots_for_bpp(encoder, crtc_state, 315 fxp_q4_to_int(limits->link.max_bpp_x16), 316 fxp_q4_to_int(limits->link.min_bpp_x16), 317 limits, 318 conn_state, 2 * 3, false); 319 320 if (slots < 0) 321 return slots; 322 323 return 0; 324 } 325 326 static int intel_dp_dsc_mst_compute_link_config(struct intel_encoder *encoder, 327 struct intel_crtc_state *crtc_state, 328 struct drm_connector_state *conn_state, 329 struct link_config_limits *limits) 330 { 331 struct intel_connector *connector = 332 to_intel_connector(conn_state->connector); 333 struct drm_i915_private *i915 = to_i915(connector->base.dev); 334 int slots = -EINVAL; 335 int i, num_bpc; 336 u8 dsc_bpc[3] = {}; 337 int min_bpp, max_bpp, sink_min_bpp, sink_max_bpp; 338 u8 dsc_max_bpc; 339 int min_compressed_bpp, max_compressed_bpp; 340 341 /* Max DSC Input BPC for ICL is 10 and for TGL+ is 12 */ 342 if (DISPLAY_VER(i915) >= 12) 343 dsc_max_bpc = min_t(u8, 12, conn_state->max_requested_bpc); 344 else 345 dsc_max_bpc = min_t(u8, 10, conn_state->max_requested_bpc); 346 347 max_bpp = min_t(u8, dsc_max_bpc * 3, limits->pipe.max_bpp); 348 min_bpp = limits->pipe.min_bpp; 349 350 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(connector->dp.dsc_dpcd, 351 dsc_bpc); 352 353 drm_dbg_kms(&i915->drm, "DSC Source supported min bpp %d max bpp %d\n", 354 min_bpp, max_bpp); 355 356 sink_max_bpp = dsc_bpc[0] * 3; 357 sink_min_bpp = sink_max_bpp; 358 359 for (i = 1; i < num_bpc; i++) { 360 if (sink_min_bpp > dsc_bpc[i] * 3) 361 sink_min_bpp = dsc_bpc[i] * 3; 362 if (sink_max_bpp < dsc_bpc[i] * 3) 363 sink_max_bpp = dsc_bpc[i] * 3; 364 } 365 366 drm_dbg_kms(&i915->drm, "DSC Sink supported min bpp %d max bpp %d\n", 367 sink_min_bpp, sink_max_bpp); 368 369 if (min_bpp < sink_min_bpp) 370 min_bpp = sink_min_bpp; 371 372 if (max_bpp > sink_max_bpp) 373 max_bpp = sink_max_bpp; 374 375 crtc_state->pipe_bpp = max_bpp; 376 377 max_compressed_bpp = intel_dp_dsc_sink_max_compressed_bpp(connector, 378 crtc_state, 379 max_bpp / 3); 380 max_compressed_bpp = min(max_compressed_bpp, 381 fxp_q4_to_int(limits->link.max_bpp_x16)); 382 383 min_compressed_bpp = intel_dp_dsc_sink_min_compressed_bpp(crtc_state); 384 min_compressed_bpp = max(min_compressed_bpp, 385 fxp_q4_to_int_roundup(limits->link.min_bpp_x16)); 386 387 drm_dbg_kms(&i915->drm, "DSC Sink supported compressed min bpp %d compressed max bpp %d\n", 388 min_compressed_bpp, max_compressed_bpp); 389 390 /* Align compressed bpps according to our own constraints */ 391 max_compressed_bpp = intel_dp_dsc_nearest_valid_bpp(i915, max_compressed_bpp, 392 crtc_state->pipe_bpp); 393 min_compressed_bpp = intel_dp_dsc_nearest_valid_bpp(i915, min_compressed_bpp, 394 crtc_state->pipe_bpp); 395 396 slots = intel_dp_mst_find_vcpi_slots_for_bpp(encoder, crtc_state, max_compressed_bpp, 397 min_compressed_bpp, limits, 398 conn_state, 1, true); 399 400 if (slots < 0) 401 return slots; 402 403 return 0; 404 } 405 static int intel_dp_mst_update_slots(struct intel_encoder *encoder, 406 struct intel_crtc_state *crtc_state, 407 struct drm_connector_state *conn_state) 408 { 409 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 410 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 411 struct intel_dp *intel_dp = &intel_mst->primary->dp; 412 struct drm_dp_mst_topology_mgr *mgr = &intel_dp->mst_mgr; 413 struct drm_dp_mst_topology_state *topology_state; 414 u8 link_coding_cap = intel_dp_is_uhbr(crtc_state) ? 415 DP_CAP_ANSI_128B132B : DP_CAP_ANSI_8B10B; 416 417 topology_state = drm_atomic_get_mst_topology_state(conn_state->state, mgr); 418 if (IS_ERR(topology_state)) { 419 drm_dbg_kms(&i915->drm, "slot update failed\n"); 420 return PTR_ERR(topology_state); 421 } 422 423 drm_dp_mst_update_slots(topology_state, link_coding_cap); 424 425 return 0; 426 } 427 428 static int mode_hblank_period_ns(const struct drm_display_mode *mode) 429 { 430 return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(mode->htotal - mode->hdisplay, 431 NSEC_PER_SEC / 1000), 432 mode->crtc_clock); 433 } 434 435 static bool 436 hblank_expansion_quirk_needs_dsc(const struct intel_connector *connector, 437 const struct intel_crtc_state *crtc_state, 438 const struct link_config_limits *limits) 439 { 440 const struct drm_display_mode *adjusted_mode = 441 &crtc_state->hw.adjusted_mode; 442 bool is_uhbr_sink = connector->mst_port && 443 drm_dp_128b132b_supported(connector->mst_port->dpcd); 444 int hblank_limit = is_uhbr_sink ? 500 : 300; 445 446 if (!connector->dp.dsc_hblank_expansion_quirk) 447 return false; 448 449 if (is_uhbr_sink && !drm_dp_is_uhbr_rate(limits->max_rate)) 450 return false; 451 452 if (mode_hblank_period_ns(adjusted_mode) > hblank_limit) 453 return false; 454 455 return true; 456 } 457 458 static bool 459 adjust_limits_for_dsc_hblank_expansion_quirk(const struct intel_connector *connector, 460 const struct intel_crtc_state *crtc_state, 461 struct link_config_limits *limits, 462 bool dsc) 463 { 464 struct drm_i915_private *i915 = to_i915(connector->base.dev); 465 const struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 466 int min_bpp_x16 = limits->link.min_bpp_x16; 467 468 if (!hblank_expansion_quirk_needs_dsc(connector, crtc_state, limits)) 469 return true; 470 471 if (!dsc) { 472 if (intel_dp_supports_dsc(connector, crtc_state)) { 473 drm_dbg_kms(&i915->drm, 474 "[CRTC:%d:%s][CONNECTOR:%d:%s] DSC needed by hblank expansion quirk\n", 475 crtc->base.base.id, crtc->base.name, 476 connector->base.base.id, connector->base.name); 477 return false; 478 } 479 480 drm_dbg_kms(&i915->drm, 481 "[CRTC:%d:%s][CONNECTOR:%d:%s] Increasing link min bpp to 24 due to hblank expansion quirk\n", 482 crtc->base.base.id, crtc->base.name, 483 connector->base.base.id, connector->base.name); 484 485 if (limits->link.max_bpp_x16 < fxp_q4_from_int(24)) 486 return false; 487 488 limits->link.min_bpp_x16 = fxp_q4_from_int(24); 489 490 return true; 491 } 492 493 drm_WARN_ON(&i915->drm, limits->min_rate != limits->max_rate); 494 495 if (limits->max_rate < 540000) 496 min_bpp_x16 = fxp_q4_from_int(13); 497 else if (limits->max_rate < 810000) 498 min_bpp_x16 = fxp_q4_from_int(10); 499 500 if (limits->link.min_bpp_x16 >= min_bpp_x16) 501 return true; 502 503 drm_dbg_kms(&i915->drm, 504 "[CRTC:%d:%s][CONNECTOR:%d:%s] Increasing link min bpp to " FXP_Q4_FMT " in DSC mode due to hblank expansion quirk\n", 505 crtc->base.base.id, crtc->base.name, 506 connector->base.base.id, connector->base.name, 507 FXP_Q4_ARGS(min_bpp_x16)); 508 509 if (limits->link.max_bpp_x16 < min_bpp_x16) 510 return false; 511 512 limits->link.min_bpp_x16 = min_bpp_x16; 513 514 return true; 515 } 516 517 static bool 518 intel_dp_mst_compute_config_limits(struct intel_dp *intel_dp, 519 const struct intel_connector *connector, 520 struct intel_crtc_state *crtc_state, 521 bool dsc, 522 struct link_config_limits *limits) 523 { 524 /* 525 * for MST we always configure max link bw - the spec doesn't 526 * seem to suggest we should do otherwise. 527 */ 528 limits->min_rate = limits->max_rate = 529 intel_dp_max_link_rate(intel_dp); 530 531 limits->min_lane_count = limits->max_lane_count = 532 intel_dp_max_lane_count(intel_dp); 533 534 limits->pipe.min_bpp = intel_dp_min_bpp(crtc_state->output_format); 535 /* 536 * FIXME: If all the streams can't fit into the link with 537 * their current pipe_bpp we should reduce pipe_bpp across 538 * the board until things start to fit. Until then we 539 * limit to <= 8bpc since that's what was hardcoded for all 540 * MST streams previously. This hack should be removed once 541 * we have the proper retry logic in place. 542 */ 543 limits->pipe.max_bpp = min(crtc_state->pipe_bpp, 24); 544 545 intel_dp_test_compute_config(intel_dp, crtc_state, limits); 546 547 if (!intel_dp_compute_config_link_bpp_limits(intel_dp, 548 crtc_state, 549 dsc, 550 limits)) 551 return false; 552 553 return adjust_limits_for_dsc_hblank_expansion_quirk(connector, 554 crtc_state, 555 limits, 556 dsc); 557 } 558 559 static int intel_dp_mst_compute_config(struct intel_encoder *encoder, 560 struct intel_crtc_state *pipe_config, 561 struct drm_connector_state *conn_state) 562 { 563 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 564 struct intel_atomic_state *state = to_intel_atomic_state(conn_state->state); 565 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 566 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 567 struct intel_dp *intel_dp = &intel_mst->primary->dp; 568 struct intel_connector *connector = 569 to_intel_connector(conn_state->connector); 570 const struct drm_display_mode *adjusted_mode = 571 &pipe_config->hw.adjusted_mode; 572 struct link_config_limits limits; 573 bool dsc_needed, joiner_needs_dsc; 574 int num_joined_pipes; 575 int ret = 0; 576 577 if (pipe_config->fec_enable && 578 !intel_dp_supports_fec(intel_dp, connector, pipe_config)) 579 return -EINVAL; 580 581 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 582 return -EINVAL; 583 584 num_joined_pipes = intel_dp_num_joined_pipes(intel_dp, connector, 585 adjusted_mode->crtc_hdisplay, 586 adjusted_mode->crtc_clock); 587 if (num_joined_pipes > 1) 588 pipe_config->joiner_pipes = GENMASK(crtc->pipe + num_joined_pipes - 1, crtc->pipe); 589 590 pipe_config->sink_format = INTEL_OUTPUT_FORMAT_RGB; 591 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB; 592 pipe_config->has_pch_encoder = false; 593 594 joiner_needs_dsc = intel_dp_joiner_needs_dsc(dev_priv, num_joined_pipes); 595 596 dsc_needed = joiner_needs_dsc || intel_dp->force_dsc_en || 597 !intel_dp_mst_compute_config_limits(intel_dp, 598 connector, 599 pipe_config, 600 false, 601 &limits); 602 603 if (!dsc_needed) { 604 ret = intel_dp_mst_compute_link_config(encoder, pipe_config, 605 conn_state, &limits); 606 607 if (ret == -EDEADLK) 608 return ret; 609 610 if (ret) 611 dsc_needed = true; 612 } 613 614 /* enable compression if the mode doesn't fit available BW */ 615 if (dsc_needed) { 616 drm_dbg_kms(&dev_priv->drm, "Try DSC (fallback=%s, joiner=%s, force=%s)\n", 617 str_yes_no(ret), str_yes_no(joiner_needs_dsc), 618 str_yes_no(intel_dp->force_dsc_en)); 619 620 if (!intel_dp_supports_dsc(connector, pipe_config)) 621 return -EINVAL; 622 623 if (!intel_dp_mst_compute_config_limits(intel_dp, 624 connector, 625 pipe_config, 626 true, 627 &limits)) 628 return -EINVAL; 629 630 /* 631 * FIXME: As bpc is hardcoded to 8, as mentioned above, 632 * WARN and ignore the debug flag force_dsc_bpc for now. 633 */ 634 drm_WARN(&dev_priv->drm, intel_dp->force_dsc_bpc, "Cannot Force BPC for MST\n"); 635 /* 636 * Try to get at least some timeslots and then see, if 637 * we can fit there with DSC. 638 */ 639 drm_dbg_kms(&dev_priv->drm, "Trying to find VCPI slots in DSC mode\n"); 640 641 ret = intel_dp_dsc_mst_compute_link_config(encoder, pipe_config, 642 conn_state, &limits); 643 if (ret < 0) 644 return ret; 645 646 ret = intel_dp_dsc_compute_config(intel_dp, pipe_config, 647 conn_state, &limits, 648 pipe_config->dp_m_n.tu, false); 649 } 650 651 if (ret) 652 return ret; 653 654 ret = intel_dp_mst_update_slots(encoder, pipe_config, conn_state); 655 if (ret) 656 return ret; 657 658 pipe_config->limited_color_range = 659 intel_dp_limited_color_range(pipe_config, conn_state); 660 661 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) 662 pipe_config->lane_lat_optim_mask = 663 bxt_dpio_phy_calc_lane_lat_optim_mask(pipe_config->lane_count); 664 665 intel_dp_audio_compute_config(encoder, pipe_config, conn_state); 666 667 intel_ddi_compute_min_voltage_level(pipe_config); 668 669 intel_psr_compute_config(intel_dp, pipe_config, conn_state); 670 671 return intel_dp_tunnel_atomic_compute_stream_bw(state, intel_dp, connector, 672 pipe_config); 673 } 674 675 /* 676 * Iterate over all connectors and return a mask of 677 * all CPU transcoders streaming over the same DP link. 678 */ 679 static unsigned int 680 intel_dp_mst_transcoder_mask(struct intel_atomic_state *state, 681 struct intel_dp *mst_port) 682 { 683 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 684 const struct intel_digital_connector_state *conn_state; 685 struct intel_connector *connector; 686 u8 transcoders = 0; 687 int i; 688 689 if (DISPLAY_VER(dev_priv) < 12) 690 return 0; 691 692 for_each_new_intel_connector_in_state(state, connector, conn_state, i) { 693 const struct intel_crtc_state *crtc_state; 694 struct intel_crtc *crtc; 695 696 if (connector->mst_port != mst_port || !conn_state->base.crtc) 697 continue; 698 699 crtc = to_intel_crtc(conn_state->base.crtc); 700 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 701 702 if (!crtc_state->hw.active) 703 continue; 704 705 transcoders |= BIT(crtc_state->cpu_transcoder); 706 } 707 708 return transcoders; 709 } 710 711 static u8 get_pipes_downstream_of_mst_port(struct intel_atomic_state *state, 712 struct drm_dp_mst_topology_mgr *mst_mgr, 713 struct drm_dp_mst_port *parent_port) 714 { 715 const struct intel_digital_connector_state *conn_state; 716 struct intel_connector *connector; 717 u8 mask = 0; 718 int i; 719 720 for_each_new_intel_connector_in_state(state, connector, conn_state, i) { 721 if (!conn_state->base.crtc) 722 continue; 723 724 if (&connector->mst_port->mst_mgr != mst_mgr) 725 continue; 726 727 if (connector->port != parent_port && 728 !drm_dp_mst_port_downstream_of_parent(mst_mgr, 729 connector->port, 730 parent_port)) 731 continue; 732 733 mask |= BIT(to_intel_crtc(conn_state->base.crtc)->pipe); 734 } 735 736 return mask; 737 } 738 739 static int intel_dp_mst_check_fec_change(struct intel_atomic_state *state, 740 struct drm_dp_mst_topology_mgr *mst_mgr, 741 struct intel_link_bw_limits *limits) 742 { 743 struct drm_i915_private *i915 = to_i915(state->base.dev); 744 struct intel_crtc *crtc; 745 u8 mst_pipe_mask; 746 u8 fec_pipe_mask = 0; 747 int ret; 748 749 mst_pipe_mask = get_pipes_downstream_of_mst_port(state, mst_mgr, NULL); 750 751 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, mst_pipe_mask) { 752 struct intel_crtc_state *crtc_state = 753 intel_atomic_get_new_crtc_state(state, crtc); 754 755 /* Atomic connector check should've added all the MST CRTCs. */ 756 if (drm_WARN_ON(&i915->drm, !crtc_state)) 757 return -EINVAL; 758 759 if (crtc_state->fec_enable) 760 fec_pipe_mask |= BIT(crtc->pipe); 761 } 762 763 if (!fec_pipe_mask || mst_pipe_mask == fec_pipe_mask) 764 return 0; 765 766 limits->force_fec_pipes |= mst_pipe_mask; 767 768 ret = intel_modeset_pipes_in_mask_early(state, "MST FEC", 769 mst_pipe_mask); 770 771 return ret ? : -EAGAIN; 772 } 773 774 static int intel_dp_mst_check_bw(struct intel_atomic_state *state, 775 struct drm_dp_mst_topology_mgr *mst_mgr, 776 struct drm_dp_mst_topology_state *mst_state, 777 struct intel_link_bw_limits *limits) 778 { 779 struct drm_dp_mst_port *mst_port; 780 u8 mst_port_pipes; 781 int ret; 782 783 ret = drm_dp_mst_atomic_check_mgr(&state->base, mst_mgr, mst_state, &mst_port); 784 if (ret != -ENOSPC) 785 return ret; 786 787 mst_port_pipes = get_pipes_downstream_of_mst_port(state, mst_mgr, mst_port); 788 789 ret = intel_link_bw_reduce_bpp(state, limits, 790 mst_port_pipes, "MST link BW"); 791 792 return ret ? : -EAGAIN; 793 } 794 795 /** 796 * intel_dp_mst_atomic_check_link - check all modeset MST link configuration 797 * @state: intel atomic state 798 * @limits: link BW limits 799 * 800 * Check the link configuration for all modeset MST outputs. If the 801 * configuration is invalid @limits will be updated if possible to 802 * reduce the total BW, after which the configuration for all CRTCs in 803 * @state must be recomputed with the updated @limits. 804 * 805 * Returns: 806 * - 0 if the confugration is valid 807 * - %-EAGAIN, if the configuration is invalid and @limits got updated 808 * with fallback values with which the configuration of all CRTCs in 809 * @state must be recomputed 810 * - Other negative error, if the configuration is invalid without a 811 * fallback possibility, or the check failed for another reason 812 */ 813 int intel_dp_mst_atomic_check_link(struct intel_atomic_state *state, 814 struct intel_link_bw_limits *limits) 815 { 816 struct drm_dp_mst_topology_mgr *mgr; 817 struct drm_dp_mst_topology_state *mst_state; 818 int ret; 819 int i; 820 821 for_each_new_mst_mgr_in_state(&state->base, mgr, mst_state, i) { 822 ret = intel_dp_mst_check_fec_change(state, mgr, limits); 823 if (ret) 824 return ret; 825 826 ret = intel_dp_mst_check_bw(state, mgr, mst_state, 827 limits); 828 if (ret) 829 return ret; 830 } 831 832 return 0; 833 } 834 835 static int intel_dp_mst_compute_config_late(struct intel_encoder *encoder, 836 struct intel_crtc_state *crtc_state, 837 struct drm_connector_state *conn_state) 838 { 839 struct intel_atomic_state *state = to_intel_atomic_state(conn_state->state); 840 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 841 struct intel_dp *intel_dp = &intel_mst->primary->dp; 842 843 /* lowest numbered transcoder will be designated master */ 844 crtc_state->mst_master_transcoder = 845 ffs(intel_dp_mst_transcoder_mask(state, intel_dp)) - 1; 846 847 return 0; 848 } 849 850 /* 851 * If one of the connectors in a MST stream needs a modeset, mark all CRTCs 852 * that shares the same MST stream as mode changed, 853 * intel_modeset_pipe_config()+intel_crtc_check_fastset() will take care to do 854 * a fastset when possible. 855 * 856 * On TGL+ this is required since each stream go through a master transcoder, 857 * so if the master transcoder needs modeset, all other streams in the 858 * topology need a modeset. All platforms need to add the atomic state 859 * for all streams in the topology, since a modeset on one may require 860 * changing the MST link BW usage of the others, which in turn needs a 861 * recomputation of the corresponding CRTC states. 862 */ 863 static int 864 intel_dp_mst_atomic_topology_check(struct intel_connector *connector, 865 struct intel_atomic_state *state) 866 { 867 struct drm_i915_private *dev_priv = to_i915(state->base.dev); 868 struct drm_connector_list_iter connector_list_iter; 869 struct intel_connector *connector_iter; 870 int ret = 0; 871 872 if (!intel_connector_needs_modeset(state, &connector->base)) 873 return 0; 874 875 drm_connector_list_iter_begin(&dev_priv->drm, &connector_list_iter); 876 for_each_intel_connector_iter(connector_iter, &connector_list_iter) { 877 struct intel_digital_connector_state *conn_iter_state; 878 struct intel_crtc_state *crtc_state; 879 struct intel_crtc *crtc; 880 881 if (connector_iter->mst_port != connector->mst_port || 882 connector_iter == connector) 883 continue; 884 885 conn_iter_state = intel_atomic_get_digital_connector_state(state, 886 connector_iter); 887 if (IS_ERR(conn_iter_state)) { 888 ret = PTR_ERR(conn_iter_state); 889 break; 890 } 891 892 if (!conn_iter_state->base.crtc) 893 continue; 894 895 crtc = to_intel_crtc(conn_iter_state->base.crtc); 896 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 897 if (IS_ERR(crtc_state)) { 898 ret = PTR_ERR(crtc_state); 899 break; 900 } 901 902 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 903 if (ret) 904 break; 905 crtc_state->uapi.mode_changed = true; 906 } 907 drm_connector_list_iter_end(&connector_list_iter); 908 909 return ret; 910 } 911 912 static int 913 intel_dp_mst_atomic_check(struct drm_connector *connector, 914 struct drm_atomic_state *_state) 915 { 916 struct intel_atomic_state *state = to_intel_atomic_state(_state); 917 struct intel_connector *intel_connector = 918 to_intel_connector(connector); 919 int ret; 920 921 ret = intel_digital_connector_atomic_check(connector, &state->base); 922 if (ret) 923 return ret; 924 925 ret = intel_dp_mst_atomic_topology_check(intel_connector, state); 926 if (ret) 927 return ret; 928 929 if (intel_connector_needs_modeset(state, connector)) { 930 ret = intel_dp_tunnel_atomic_check_state(state, 931 intel_connector->mst_port, 932 intel_connector); 933 if (ret) 934 return ret; 935 } 936 937 return drm_dp_atomic_release_time_slots(&state->base, 938 &intel_connector->mst_port->mst_mgr, 939 intel_connector->port); 940 } 941 942 static void clear_act_sent(struct intel_encoder *encoder, 943 const struct intel_crtc_state *crtc_state) 944 { 945 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 946 947 intel_de_write(i915, dp_tp_status_reg(encoder, crtc_state), 948 DP_TP_STATUS_ACT_SENT); 949 } 950 951 static void wait_for_act_sent(struct intel_encoder *encoder, 952 const struct intel_crtc_state *crtc_state) 953 { 954 struct drm_i915_private *i915 = to_i915(encoder->base.dev); 955 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 956 struct intel_dp *intel_dp = &intel_mst->primary->dp; 957 958 if (intel_de_wait_for_set(i915, dp_tp_status_reg(encoder, crtc_state), 959 DP_TP_STATUS_ACT_SENT, 1)) 960 drm_err(&i915->drm, "Timed out waiting for ACT sent\n"); 961 962 drm_dp_check_act_status(&intel_dp->mst_mgr); 963 } 964 965 static void intel_mst_disable_dp(struct intel_atomic_state *state, 966 struct intel_encoder *encoder, 967 const struct intel_crtc_state *old_crtc_state, 968 const struct drm_connector_state *old_conn_state) 969 { 970 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 971 struct intel_digital_port *dig_port = intel_mst->primary; 972 struct intel_dp *intel_dp = &dig_port->dp; 973 struct intel_connector *connector = 974 to_intel_connector(old_conn_state->connector); 975 struct drm_i915_private *i915 = to_i915(connector->base.dev); 976 977 drm_dbg_kms(&i915->drm, "active links %d\n", 978 intel_dp->active_mst_links); 979 980 if (intel_dp->active_mst_links == 1) 981 intel_dp->link_trained = false; 982 983 intel_hdcp_disable(intel_mst->connector); 984 985 intel_dp_sink_disable_decompression(state, connector, old_crtc_state); 986 } 987 988 static void intel_mst_post_disable_dp(struct intel_atomic_state *state, 989 struct intel_encoder *encoder, 990 const struct intel_crtc_state *old_crtc_state, 991 const struct drm_connector_state *old_conn_state) 992 { 993 struct intel_display *display = to_intel_display(encoder); 994 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 995 struct intel_digital_port *dig_port = intel_mst->primary; 996 struct intel_dp *intel_dp = &dig_port->dp; 997 struct intel_connector *connector = 998 to_intel_connector(old_conn_state->connector); 999 struct drm_dp_mst_topology_state *old_mst_state = 1000 drm_atomic_get_old_mst_topology_state(&state->base, &intel_dp->mst_mgr); 1001 struct drm_dp_mst_topology_state *new_mst_state = 1002 drm_atomic_get_new_mst_topology_state(&state->base, &intel_dp->mst_mgr); 1003 const struct drm_dp_mst_atomic_payload *old_payload = 1004 drm_atomic_get_mst_payload_state(old_mst_state, connector->port); 1005 struct drm_dp_mst_atomic_payload *new_payload = 1006 drm_atomic_get_mst_payload_state(new_mst_state, connector->port); 1007 struct drm_i915_private *dev_priv = to_i915(connector->base.dev); 1008 struct intel_crtc *pipe_crtc; 1009 bool last_mst_stream; 1010 int i; 1011 1012 intel_dp->active_mst_links--; 1013 last_mst_stream = intel_dp->active_mst_links == 0; 1014 drm_WARN_ON(&dev_priv->drm, 1015 DISPLAY_VER(dev_priv) >= 12 && last_mst_stream && 1016 !intel_dp_mst_is_master_trans(old_crtc_state)); 1017 1018 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i) { 1019 const struct intel_crtc_state *old_pipe_crtc_state = 1020 intel_atomic_get_old_crtc_state(state, pipe_crtc); 1021 1022 intel_crtc_vblank_off(old_pipe_crtc_state); 1023 } 1024 1025 intel_disable_transcoder(old_crtc_state); 1026 1027 drm_dp_remove_payload_part1(&intel_dp->mst_mgr, new_mst_state, new_payload); 1028 1029 clear_act_sent(encoder, old_crtc_state); 1030 1031 intel_de_rmw(dev_priv, 1032 TRANS_DDI_FUNC_CTL(dev_priv, old_crtc_state->cpu_transcoder), 1033 TRANS_DDI_DP_VC_PAYLOAD_ALLOC, 0); 1034 1035 wait_for_act_sent(encoder, old_crtc_state); 1036 1037 drm_dp_remove_payload_part2(&intel_dp->mst_mgr, new_mst_state, 1038 old_payload, new_payload); 1039 1040 intel_ddi_disable_transcoder_func(old_crtc_state); 1041 1042 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i) { 1043 const struct intel_crtc_state *old_pipe_crtc_state = 1044 intel_atomic_get_old_crtc_state(state, pipe_crtc); 1045 1046 intel_dsc_disable(old_pipe_crtc_state); 1047 1048 if (DISPLAY_VER(dev_priv) >= 9) 1049 skl_scaler_disable(old_pipe_crtc_state); 1050 else 1051 ilk_pfit_disable(old_pipe_crtc_state); 1052 } 1053 1054 /* 1055 * Power down mst path before disabling the port, otherwise we end 1056 * up getting interrupts from the sink upon detecting link loss. 1057 */ 1058 drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port, 1059 false); 1060 1061 /* 1062 * BSpec 4287: disable DIP after the transcoder is disabled and before 1063 * the transcoder clock select is set to none. 1064 */ 1065 intel_dp_set_infoframes(&dig_port->base, false, 1066 old_crtc_state, NULL); 1067 /* 1068 * From TGL spec: "If multi-stream slave transcoder: Configure 1069 * Transcoder Clock Select to direct no clock to the transcoder" 1070 * 1071 * From older GENs spec: "Configure Transcoder Clock Select to direct 1072 * no clock to the transcoder" 1073 */ 1074 if (DISPLAY_VER(dev_priv) < 12 || !last_mst_stream) 1075 intel_ddi_disable_transcoder_clock(old_crtc_state); 1076 1077 1078 intel_mst->connector = NULL; 1079 if (last_mst_stream) 1080 dig_port->base.post_disable(state, &dig_port->base, 1081 old_crtc_state, NULL); 1082 1083 drm_dbg_kms(&dev_priv->drm, "active links %d\n", 1084 intel_dp->active_mst_links); 1085 } 1086 1087 static void intel_mst_post_pll_disable_dp(struct intel_atomic_state *state, 1088 struct intel_encoder *encoder, 1089 const struct intel_crtc_state *old_crtc_state, 1090 const struct drm_connector_state *old_conn_state) 1091 { 1092 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1093 struct intel_digital_port *dig_port = intel_mst->primary; 1094 struct intel_dp *intel_dp = &dig_port->dp; 1095 1096 if (intel_dp->active_mst_links == 0 && 1097 dig_port->base.post_pll_disable) 1098 dig_port->base.post_pll_disable(state, encoder, old_crtc_state, old_conn_state); 1099 } 1100 1101 static void intel_mst_pre_pll_enable_dp(struct intel_atomic_state *state, 1102 struct intel_encoder *encoder, 1103 const struct intel_crtc_state *pipe_config, 1104 const struct drm_connector_state *conn_state) 1105 { 1106 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1107 struct intel_digital_port *dig_port = intel_mst->primary; 1108 struct intel_dp *intel_dp = &dig_port->dp; 1109 1110 if (intel_dp->active_mst_links == 0) 1111 dig_port->base.pre_pll_enable(state, &dig_port->base, 1112 pipe_config, NULL); 1113 else 1114 /* 1115 * The port PLL state needs to get updated for secondary 1116 * streams as for the primary stream. 1117 */ 1118 intel_ddi_update_active_dpll(state, &dig_port->base, 1119 to_intel_crtc(pipe_config->uapi.crtc)); 1120 } 1121 1122 static bool intel_mst_probed_link_params_valid(struct intel_dp *intel_dp, 1123 int link_rate, int lane_count) 1124 { 1125 return intel_dp->link.mst_probed_rate == link_rate && 1126 intel_dp->link.mst_probed_lane_count == lane_count; 1127 } 1128 1129 static void intel_mst_set_probed_link_params(struct intel_dp *intel_dp, 1130 int link_rate, int lane_count) 1131 { 1132 intel_dp->link.mst_probed_rate = link_rate; 1133 intel_dp->link.mst_probed_lane_count = lane_count; 1134 } 1135 1136 static void intel_mst_reprobe_topology(struct intel_dp *intel_dp, 1137 const struct intel_crtc_state *crtc_state) 1138 { 1139 if (intel_mst_probed_link_params_valid(intel_dp, 1140 crtc_state->port_clock, crtc_state->lane_count)) 1141 return; 1142 1143 drm_dp_mst_topology_queue_probe(&intel_dp->mst_mgr); 1144 1145 intel_mst_set_probed_link_params(intel_dp, 1146 crtc_state->port_clock, crtc_state->lane_count); 1147 } 1148 1149 static void intel_mst_pre_enable_dp(struct intel_atomic_state *state, 1150 struct intel_encoder *encoder, 1151 const struct intel_crtc_state *pipe_config, 1152 const struct drm_connector_state *conn_state) 1153 { 1154 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1155 struct intel_digital_port *dig_port = intel_mst->primary; 1156 struct intel_dp *intel_dp = &dig_port->dp; 1157 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1158 struct intel_connector *connector = 1159 to_intel_connector(conn_state->connector); 1160 struct drm_dp_mst_topology_state *mst_state = 1161 drm_atomic_get_new_mst_topology_state(&state->base, &intel_dp->mst_mgr); 1162 int ret; 1163 bool first_mst_stream; 1164 1165 /* MST encoders are bound to a crtc, not to a connector, 1166 * force the mapping here for get_hw_state. 1167 */ 1168 connector->encoder = encoder; 1169 intel_mst->connector = connector; 1170 first_mst_stream = intel_dp->active_mst_links == 0; 1171 drm_WARN_ON(&dev_priv->drm, 1172 DISPLAY_VER(dev_priv) >= 12 && first_mst_stream && 1173 !intel_dp_mst_is_master_trans(pipe_config)); 1174 1175 drm_dbg_kms(&dev_priv->drm, "active links %d\n", 1176 intel_dp->active_mst_links); 1177 1178 if (first_mst_stream) 1179 intel_dp_set_power(intel_dp, DP_SET_POWER_D0); 1180 1181 drm_dp_send_power_updown_phy(&intel_dp->mst_mgr, connector->port, true); 1182 1183 intel_dp_sink_enable_decompression(state, connector, pipe_config); 1184 1185 if (first_mst_stream) { 1186 dig_port->base.pre_enable(state, &dig_port->base, 1187 pipe_config, NULL); 1188 1189 intel_mst_reprobe_topology(intel_dp, pipe_config); 1190 } 1191 1192 intel_dp->active_mst_links++; 1193 1194 ret = drm_dp_add_payload_part1(&intel_dp->mst_mgr, mst_state, 1195 drm_atomic_get_mst_payload_state(mst_state, connector->port)); 1196 if (ret < 0) 1197 intel_dp_queue_modeset_retry_for_link(state, &dig_port->base, pipe_config); 1198 1199 /* 1200 * Before Gen 12 this is not done as part of 1201 * dig_port->base.pre_enable() and should be done here. For 1202 * Gen 12+ the step in which this should be done is different for the 1203 * first MST stream, so it's done on the DDI for the first stream and 1204 * here for the following ones. 1205 */ 1206 if (DISPLAY_VER(dev_priv) < 12 || !first_mst_stream) 1207 intel_ddi_enable_transcoder_clock(encoder, pipe_config); 1208 1209 intel_dsc_dp_pps_write(&dig_port->base, pipe_config); 1210 intel_ddi_set_dp_msa(pipe_config, conn_state); 1211 } 1212 1213 static void enable_bs_jitter_was(const struct intel_crtc_state *crtc_state) 1214 { 1215 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev); 1216 u32 clear = 0; 1217 u32 set = 0; 1218 1219 if (!IS_ALDERLAKE_P(i915)) 1220 return; 1221 1222 if (!IS_DISPLAY_STEP(i915, STEP_D0, STEP_FOREVER)) 1223 return; 1224 1225 /* Wa_14013163432:adlp */ 1226 if (crtc_state->fec_enable || intel_dp_is_uhbr(crtc_state)) 1227 set |= DP_MST_FEC_BS_JITTER_WA(crtc_state->cpu_transcoder); 1228 1229 /* Wa_14014143976:adlp */ 1230 if (IS_DISPLAY_STEP(i915, STEP_E0, STEP_FOREVER)) { 1231 if (intel_dp_is_uhbr(crtc_state)) 1232 set |= DP_MST_SHORT_HBLANK_WA(crtc_state->cpu_transcoder); 1233 else if (crtc_state->fec_enable) 1234 clear |= DP_MST_SHORT_HBLANK_WA(crtc_state->cpu_transcoder); 1235 1236 if (crtc_state->fec_enable || intel_dp_is_uhbr(crtc_state)) 1237 set |= DP_MST_DPT_DPTP_ALIGN_WA(crtc_state->cpu_transcoder); 1238 } 1239 1240 if (!clear && !set) 1241 return; 1242 1243 intel_de_rmw(i915, CHICKEN_MISC_3, clear, set); 1244 } 1245 1246 static void intel_mst_enable_dp(struct intel_atomic_state *state, 1247 struct intel_encoder *encoder, 1248 const struct intel_crtc_state *pipe_config, 1249 const struct drm_connector_state *conn_state) 1250 { 1251 struct intel_display *display = to_intel_display(encoder); 1252 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1253 struct intel_digital_port *dig_port = intel_mst->primary; 1254 struct intel_dp *intel_dp = &dig_port->dp; 1255 struct intel_connector *connector = to_intel_connector(conn_state->connector); 1256 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1257 struct drm_dp_mst_topology_state *mst_state = 1258 drm_atomic_get_new_mst_topology_state(&state->base, &intel_dp->mst_mgr); 1259 enum transcoder trans = pipe_config->cpu_transcoder; 1260 bool first_mst_stream = intel_dp->active_mst_links == 1; 1261 struct intel_crtc *pipe_crtc; 1262 int ret, i; 1263 1264 drm_WARN_ON(&dev_priv->drm, pipe_config->has_pch_encoder); 1265 1266 if (intel_dp_is_uhbr(pipe_config)) { 1267 const struct drm_display_mode *adjusted_mode = 1268 &pipe_config->hw.adjusted_mode; 1269 u64 crtc_clock_hz = KHz(adjusted_mode->crtc_clock); 1270 1271 intel_de_write(dev_priv, TRANS_DP2_VFREQHIGH(pipe_config->cpu_transcoder), 1272 TRANS_DP2_VFREQ_PIXEL_CLOCK(crtc_clock_hz >> 24)); 1273 intel_de_write(dev_priv, TRANS_DP2_VFREQLOW(pipe_config->cpu_transcoder), 1274 TRANS_DP2_VFREQ_PIXEL_CLOCK(crtc_clock_hz & 0xffffff)); 1275 } 1276 1277 enable_bs_jitter_was(pipe_config); 1278 1279 intel_ddi_enable_transcoder_func(encoder, pipe_config); 1280 1281 clear_act_sent(encoder, pipe_config); 1282 1283 intel_de_rmw(dev_priv, TRANS_DDI_FUNC_CTL(dev_priv, trans), 0, 1284 TRANS_DDI_DP_VC_PAYLOAD_ALLOC); 1285 1286 drm_dbg_kms(&dev_priv->drm, "active links %d\n", 1287 intel_dp->active_mst_links); 1288 1289 wait_for_act_sent(encoder, pipe_config); 1290 1291 if (first_mst_stream) 1292 intel_ddi_wait_for_fec_status(encoder, pipe_config, true); 1293 1294 ret = drm_dp_add_payload_part2(&intel_dp->mst_mgr, 1295 drm_atomic_get_mst_payload_state(mst_state, 1296 connector->port)); 1297 if (ret < 0) 1298 intel_dp_queue_modeset_retry_for_link(state, &dig_port->base, pipe_config); 1299 1300 if (DISPLAY_VER(dev_priv) >= 12) 1301 intel_de_rmw(dev_priv, hsw_chicken_trans_reg(dev_priv, trans), 1302 FECSTALL_DIS_DPTSTREAM_DPTTG, 1303 pipe_config->fec_enable ? FECSTALL_DIS_DPTSTREAM_DPTTG : 0); 1304 1305 intel_audio_sdp_split_update(pipe_config); 1306 1307 intel_enable_transcoder(pipe_config); 1308 1309 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, pipe_config, i) { 1310 const struct intel_crtc_state *pipe_crtc_state = 1311 intel_atomic_get_new_crtc_state(state, pipe_crtc); 1312 1313 intel_crtc_vblank_on(pipe_crtc_state); 1314 } 1315 1316 intel_hdcp_enable(state, encoder, pipe_config, conn_state); 1317 } 1318 1319 static bool intel_dp_mst_enc_get_hw_state(struct intel_encoder *encoder, 1320 enum pipe *pipe) 1321 { 1322 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1323 *pipe = intel_mst->pipe; 1324 if (intel_mst->connector) 1325 return true; 1326 return false; 1327 } 1328 1329 static void intel_dp_mst_enc_get_config(struct intel_encoder *encoder, 1330 struct intel_crtc_state *pipe_config) 1331 { 1332 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1333 struct intel_digital_port *dig_port = intel_mst->primary; 1334 1335 dig_port->base.get_config(&dig_port->base, pipe_config); 1336 } 1337 1338 static bool intel_dp_mst_initial_fastset_check(struct intel_encoder *encoder, 1339 struct intel_crtc_state *crtc_state) 1340 { 1341 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(encoder); 1342 struct intel_digital_port *dig_port = intel_mst->primary; 1343 1344 return intel_dp_initial_fastset_check(&dig_port->base, crtc_state); 1345 } 1346 1347 static int intel_dp_mst_get_ddc_modes(struct drm_connector *connector) 1348 { 1349 struct intel_connector *intel_connector = to_intel_connector(connector); 1350 struct drm_i915_private *i915 = to_i915(intel_connector->base.dev); 1351 struct intel_dp *intel_dp = intel_connector->mst_port; 1352 const struct drm_edid *drm_edid; 1353 int ret; 1354 1355 if (drm_connector_is_unregistered(connector)) 1356 return intel_connector_update_modes(connector, NULL); 1357 1358 if (!intel_display_driver_check_access(i915)) 1359 return drm_edid_connector_add_modes(connector); 1360 1361 drm_edid = drm_dp_mst_edid_read(connector, &intel_dp->mst_mgr, intel_connector->port); 1362 1363 ret = intel_connector_update_modes(connector, drm_edid); 1364 1365 drm_edid_free(drm_edid); 1366 1367 return ret; 1368 } 1369 1370 static int 1371 intel_dp_mst_connector_late_register(struct drm_connector *connector) 1372 { 1373 struct intel_connector *intel_connector = to_intel_connector(connector); 1374 int ret; 1375 1376 ret = drm_dp_mst_connector_late_register(connector, 1377 intel_connector->port); 1378 if (ret < 0) 1379 return ret; 1380 1381 ret = intel_connector_register(connector); 1382 if (ret < 0) 1383 drm_dp_mst_connector_early_unregister(connector, 1384 intel_connector->port); 1385 1386 return ret; 1387 } 1388 1389 static void 1390 intel_dp_mst_connector_early_unregister(struct drm_connector *connector) 1391 { 1392 struct intel_connector *intel_connector = to_intel_connector(connector); 1393 1394 intel_connector_unregister(connector); 1395 drm_dp_mst_connector_early_unregister(connector, 1396 intel_connector->port); 1397 } 1398 1399 static const struct drm_connector_funcs intel_dp_mst_connector_funcs = { 1400 .fill_modes = drm_helper_probe_single_connector_modes, 1401 .atomic_get_property = intel_digital_connector_atomic_get_property, 1402 .atomic_set_property = intel_digital_connector_atomic_set_property, 1403 .late_register = intel_dp_mst_connector_late_register, 1404 .early_unregister = intel_dp_mst_connector_early_unregister, 1405 .destroy = intel_connector_destroy, 1406 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 1407 .atomic_duplicate_state = intel_digital_connector_duplicate_state, 1408 }; 1409 1410 static int intel_dp_mst_get_modes(struct drm_connector *connector) 1411 { 1412 return intel_dp_mst_get_ddc_modes(connector); 1413 } 1414 1415 static int 1416 intel_dp_mst_mode_valid_ctx(struct drm_connector *connector, 1417 struct drm_display_mode *mode, 1418 struct drm_modeset_acquire_ctx *ctx, 1419 enum drm_mode_status *status) 1420 { 1421 struct drm_i915_private *dev_priv = to_i915(connector->dev); 1422 struct intel_connector *intel_connector = to_intel_connector(connector); 1423 struct intel_dp *intel_dp = intel_connector->mst_port; 1424 struct drm_dp_mst_topology_mgr *mgr = &intel_dp->mst_mgr; 1425 struct drm_dp_mst_port *port = intel_connector->port; 1426 const int min_bpp = 18; 1427 int max_dotclk = to_i915(connector->dev)->display.cdclk.max_dotclk_freq; 1428 int max_rate, mode_rate, max_lanes, max_link_clock; 1429 int ret; 1430 bool dsc = false; 1431 u16 dsc_max_compressed_bpp = 0; 1432 u8 dsc_slice_count = 0; 1433 int target_clock = mode->clock; 1434 int num_joined_pipes; 1435 1436 if (drm_connector_is_unregistered(connector)) { 1437 *status = MODE_ERROR; 1438 return 0; 1439 } 1440 1441 *status = intel_cpu_transcoder_mode_valid(dev_priv, mode); 1442 if (*status != MODE_OK) 1443 return 0; 1444 1445 if (mode->flags & DRM_MODE_FLAG_DBLCLK) { 1446 *status = MODE_H_ILLEGAL; 1447 return 0; 1448 } 1449 1450 if (mode->clock < 10000) { 1451 *status = MODE_CLOCK_LOW; 1452 return 0; 1453 } 1454 1455 max_link_clock = intel_dp_max_link_rate(intel_dp); 1456 max_lanes = intel_dp_max_lane_count(intel_dp); 1457 1458 max_rate = intel_dp_max_link_data_rate(intel_dp, 1459 max_link_clock, max_lanes); 1460 mode_rate = intel_dp_link_required(mode->clock, min_bpp); 1461 1462 /* 1463 * TODO: 1464 * - Also check if compression would allow for the mode 1465 * - Calculate the overhead using drm_dp_bw_overhead() / 1466 * drm_dp_bw_channel_coding_efficiency(), similarly to the 1467 * compute config code, as drm_dp_calc_pbn_mode() doesn't 1468 * account with all the overheads. 1469 * - Check here and during compute config the BW reported by 1470 * DFP_Link_Available_Payload_Bandwidth_Number (or the 1471 * corresponding link capabilities of the sink) in case the 1472 * stream is uncompressed for it by the last branch device. 1473 */ 1474 num_joined_pipes = intel_dp_num_joined_pipes(intel_dp, intel_connector, 1475 mode->hdisplay, target_clock); 1476 max_dotclk *= num_joined_pipes; 1477 1478 ret = drm_modeset_lock(&mgr->base.lock, ctx); 1479 if (ret) 1480 return ret; 1481 1482 if (mode_rate > max_rate || mode->clock > max_dotclk || 1483 drm_dp_calc_pbn_mode(mode->clock, min_bpp << 4) > port->full_pbn) { 1484 *status = MODE_CLOCK_HIGH; 1485 return 0; 1486 } 1487 1488 if (intel_dp_has_dsc(intel_connector)) { 1489 /* 1490 * TBD pass the connector BPC, 1491 * for now U8_MAX so that max BPC on that platform would be picked 1492 */ 1493 int pipe_bpp = intel_dp_dsc_compute_max_bpp(intel_connector, U8_MAX); 1494 1495 if (drm_dp_sink_supports_fec(intel_connector->dp.fec_capability)) { 1496 dsc_max_compressed_bpp = 1497 intel_dp_dsc_get_max_compressed_bpp(dev_priv, 1498 max_link_clock, 1499 max_lanes, 1500 target_clock, 1501 mode->hdisplay, 1502 num_joined_pipes, 1503 INTEL_OUTPUT_FORMAT_RGB, 1504 pipe_bpp, 64); 1505 dsc_slice_count = 1506 intel_dp_dsc_get_slice_count(intel_connector, 1507 target_clock, 1508 mode->hdisplay, 1509 num_joined_pipes); 1510 } 1511 1512 dsc = dsc_max_compressed_bpp && dsc_slice_count; 1513 } 1514 1515 if (intel_dp_joiner_needs_dsc(dev_priv, num_joined_pipes) && !dsc) { 1516 *status = MODE_CLOCK_HIGH; 1517 return 0; 1518 } 1519 1520 if (mode_rate > max_rate && !dsc) { 1521 *status = MODE_CLOCK_HIGH; 1522 return 0; 1523 } 1524 1525 *status = intel_mode_valid_max_plane_size(dev_priv, mode, num_joined_pipes); 1526 return 0; 1527 } 1528 1529 static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector, 1530 struct drm_atomic_state *state) 1531 { 1532 struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, 1533 connector); 1534 struct intel_connector *intel_connector = to_intel_connector(connector); 1535 struct intel_dp *intel_dp = intel_connector->mst_port; 1536 struct intel_crtc *crtc = to_intel_crtc(connector_state->crtc); 1537 1538 return &intel_dp->mst_encoders[crtc->pipe]->base.base; 1539 } 1540 1541 static int 1542 intel_dp_mst_detect(struct drm_connector *connector, 1543 struct drm_modeset_acquire_ctx *ctx, bool force) 1544 { 1545 struct drm_i915_private *i915 = to_i915(connector->dev); 1546 struct intel_connector *intel_connector = to_intel_connector(connector); 1547 struct intel_dp *intel_dp = intel_connector->mst_port; 1548 1549 if (!intel_display_device_enabled(i915)) 1550 return connector_status_disconnected; 1551 1552 if (drm_connector_is_unregistered(connector)) 1553 return connector_status_disconnected; 1554 1555 if (!intel_display_driver_check_access(i915)) 1556 return connector->status; 1557 1558 return drm_dp_mst_detect_port(connector, ctx, &intel_dp->mst_mgr, 1559 intel_connector->port); 1560 } 1561 1562 static const struct drm_connector_helper_funcs intel_dp_mst_connector_helper_funcs = { 1563 .get_modes = intel_dp_mst_get_modes, 1564 .mode_valid_ctx = intel_dp_mst_mode_valid_ctx, 1565 .atomic_best_encoder = intel_mst_atomic_best_encoder, 1566 .atomic_check = intel_dp_mst_atomic_check, 1567 .detect_ctx = intel_dp_mst_detect, 1568 }; 1569 1570 static void intel_dp_mst_encoder_destroy(struct drm_encoder *encoder) 1571 { 1572 struct intel_dp_mst_encoder *intel_mst = enc_to_mst(to_intel_encoder(encoder)); 1573 1574 drm_encoder_cleanup(encoder); 1575 kfree(intel_mst); 1576 } 1577 1578 static const struct drm_encoder_funcs intel_dp_mst_enc_funcs = { 1579 .destroy = intel_dp_mst_encoder_destroy, 1580 }; 1581 1582 static bool intel_dp_mst_get_hw_state(struct intel_connector *connector) 1583 { 1584 if (intel_attached_encoder(connector) && connector->base.state->crtc) { 1585 enum pipe pipe; 1586 if (!intel_attached_encoder(connector)->get_hw_state(intel_attached_encoder(connector), &pipe)) 1587 return false; 1588 return true; 1589 } 1590 return false; 1591 } 1592 1593 static int intel_dp_mst_add_properties(struct intel_dp *intel_dp, 1594 struct drm_connector *connector, 1595 const char *pathprop) 1596 { 1597 struct drm_i915_private *i915 = to_i915(connector->dev); 1598 1599 drm_object_attach_property(&connector->base, 1600 i915->drm.mode_config.path_property, 0); 1601 drm_object_attach_property(&connector->base, 1602 i915->drm.mode_config.tile_property, 0); 1603 1604 intel_attach_force_audio_property(connector); 1605 intel_attach_broadcast_rgb_property(connector); 1606 1607 /* 1608 * Reuse the prop from the SST connector because we're 1609 * not allowed to create new props after device registration. 1610 */ 1611 connector->max_bpc_property = 1612 intel_dp->attached_connector->base.max_bpc_property; 1613 if (connector->max_bpc_property) 1614 drm_connector_attach_max_bpc_property(connector, 6, 12); 1615 1616 return drm_connector_set_path_property(connector, pathprop); 1617 } 1618 1619 static void 1620 intel_dp_mst_read_decompression_port_dsc_caps(struct intel_dp *intel_dp, 1621 struct intel_connector *connector) 1622 { 1623 u8 dpcd_caps[DP_RECEIVER_CAP_SIZE]; 1624 1625 if (!connector->dp.dsc_decompression_aux) 1626 return; 1627 1628 if (drm_dp_read_dpcd_caps(connector->dp.dsc_decompression_aux, dpcd_caps) < 0) 1629 return; 1630 1631 intel_dp_get_dsc_sink_cap(dpcd_caps[DP_DPCD_REV], connector); 1632 } 1633 1634 static bool detect_dsc_hblank_expansion_quirk(const struct intel_connector *connector) 1635 { 1636 struct drm_i915_private *i915 = to_i915(connector->base.dev); 1637 struct drm_dp_aux *aux = connector->dp.dsc_decompression_aux; 1638 struct drm_dp_desc desc; 1639 u8 dpcd[DP_RECEIVER_CAP_SIZE]; 1640 1641 if (!aux) 1642 return false; 1643 1644 /* 1645 * A logical port's OUI (at least for affected sinks) is all 0, so 1646 * instead of that the parent port's OUI is used for identification. 1647 */ 1648 if (drm_dp_mst_port_is_logical(connector->port)) { 1649 aux = drm_dp_mst_aux_for_parent(connector->port); 1650 if (!aux) 1651 aux = &connector->mst_port->aux; 1652 } 1653 1654 if (drm_dp_read_dpcd_caps(aux, dpcd) < 0) 1655 return false; 1656 1657 if (drm_dp_read_desc(aux, &desc, drm_dp_is_branch(dpcd)) < 0) 1658 return false; 1659 1660 if (!drm_dp_has_quirk(&desc, 1661 DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC)) 1662 return false; 1663 1664 /* 1665 * UHBR (MST sink) devices requiring this quirk don't advertise the 1666 * HBLANK expansion support. Presuming that they perform HBLANK 1667 * expansion internally, or are affected by this issue on modes with a 1668 * short HBLANK for other reasons. 1669 */ 1670 if (!drm_dp_128b132b_supported(dpcd) && 1671 !(dpcd[DP_RECEIVE_PORT_0_CAP_0] & DP_HBLANK_EXPANSION_CAPABLE)) 1672 return false; 1673 1674 drm_dbg_kms(&i915->drm, 1675 "[CONNECTOR:%d:%s] DSC HBLANK expansion quirk detected\n", 1676 connector->base.base.id, connector->base.name); 1677 1678 return true; 1679 } 1680 1681 static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topology_mgr *mgr, 1682 struct drm_dp_mst_port *port, 1683 const char *pathprop) 1684 { 1685 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); 1686 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 1687 struct drm_device *dev = dig_port->base.base.dev; 1688 struct drm_i915_private *dev_priv = to_i915(dev); 1689 struct intel_connector *intel_connector; 1690 struct drm_connector *connector; 1691 enum pipe pipe; 1692 int ret; 1693 1694 intel_connector = intel_connector_alloc(); 1695 if (!intel_connector) 1696 return NULL; 1697 1698 intel_connector->get_hw_state = intel_dp_mst_get_hw_state; 1699 intel_connector->sync_state = intel_dp_connector_sync_state; 1700 intel_connector->mst_port = intel_dp; 1701 intel_connector->port = port; 1702 drm_dp_mst_get_port_malloc(port); 1703 1704 intel_dp_init_modeset_retry_work(intel_connector); 1705 1706 intel_connector->dp.dsc_decompression_aux = drm_dp_mst_dsc_aux_for_port(port); 1707 intel_dp_mst_read_decompression_port_dsc_caps(intel_dp, intel_connector); 1708 intel_connector->dp.dsc_hblank_expansion_quirk = 1709 detect_dsc_hblank_expansion_quirk(intel_connector); 1710 1711 connector = &intel_connector->base; 1712 ret = drm_connector_init(dev, connector, &intel_dp_mst_connector_funcs, 1713 DRM_MODE_CONNECTOR_DisplayPort); 1714 if (ret) { 1715 drm_dp_mst_put_port_malloc(port); 1716 intel_connector_free(intel_connector); 1717 return NULL; 1718 } 1719 1720 drm_connector_helper_add(connector, &intel_dp_mst_connector_helper_funcs); 1721 1722 for_each_pipe(dev_priv, pipe) { 1723 struct drm_encoder *enc = 1724 &intel_dp->mst_encoders[pipe]->base.base; 1725 1726 ret = drm_connector_attach_encoder(&intel_connector->base, enc); 1727 if (ret) 1728 goto err; 1729 } 1730 1731 ret = intel_dp_mst_add_properties(intel_dp, connector, pathprop); 1732 if (ret) 1733 goto err; 1734 1735 ret = intel_dp_hdcp_init(dig_port, intel_connector); 1736 if (ret) 1737 drm_dbg_kms(&dev_priv->drm, "[%s:%d] HDCP MST init failed, skipping.\n", 1738 connector->name, connector->base.id); 1739 1740 return connector; 1741 1742 err: 1743 drm_connector_cleanup(connector); 1744 return NULL; 1745 } 1746 1747 static void 1748 intel_dp_mst_poll_hpd_irq(struct drm_dp_mst_topology_mgr *mgr) 1749 { 1750 struct intel_dp *intel_dp = container_of(mgr, struct intel_dp, mst_mgr); 1751 1752 intel_hpd_trigger_irq(dp_to_dig_port(intel_dp)); 1753 } 1754 1755 static const struct drm_dp_mst_topology_cbs mst_cbs = { 1756 .add_connector = intel_dp_add_mst_connector, 1757 .poll_hpd_irq = intel_dp_mst_poll_hpd_irq, 1758 }; 1759 1760 static struct intel_dp_mst_encoder * 1761 intel_dp_create_fake_mst_encoder(struct intel_digital_port *dig_port, enum pipe pipe) 1762 { 1763 struct intel_dp_mst_encoder *intel_mst; 1764 struct intel_encoder *intel_encoder; 1765 struct drm_device *dev = dig_port->base.base.dev; 1766 1767 intel_mst = kzalloc(sizeof(*intel_mst), GFP_KERNEL); 1768 1769 if (!intel_mst) 1770 return NULL; 1771 1772 intel_mst->pipe = pipe; 1773 intel_encoder = &intel_mst->base; 1774 intel_mst->primary = dig_port; 1775 1776 drm_encoder_init(dev, &intel_encoder->base, &intel_dp_mst_enc_funcs, 1777 DRM_MODE_ENCODER_DPMST, "DP-MST %c", pipe_name(pipe)); 1778 1779 intel_encoder->type = INTEL_OUTPUT_DP_MST; 1780 intel_encoder->power_domain = dig_port->base.power_domain; 1781 intel_encoder->port = dig_port->base.port; 1782 intel_encoder->cloneable = 0; 1783 /* 1784 * This is wrong, but broken userspace uses the intersection 1785 * of possible_crtcs of all the encoders of a given connector 1786 * to figure out which crtcs can drive said connector. What 1787 * should be used instead is the union of possible_crtcs. 1788 * To keep such userspace functioning we must misconfigure 1789 * this to make sure the intersection is not empty :( 1790 */ 1791 intel_encoder->pipe_mask = ~0; 1792 1793 intel_encoder->compute_config = intel_dp_mst_compute_config; 1794 intel_encoder->compute_config_late = intel_dp_mst_compute_config_late; 1795 intel_encoder->disable = intel_mst_disable_dp; 1796 intel_encoder->post_disable = intel_mst_post_disable_dp; 1797 intel_encoder->post_pll_disable = intel_mst_post_pll_disable_dp; 1798 intel_encoder->update_pipe = intel_ddi_update_pipe; 1799 intel_encoder->pre_pll_enable = intel_mst_pre_pll_enable_dp; 1800 intel_encoder->pre_enable = intel_mst_pre_enable_dp; 1801 intel_encoder->enable = intel_mst_enable_dp; 1802 intel_encoder->audio_enable = intel_audio_codec_enable; 1803 intel_encoder->audio_disable = intel_audio_codec_disable; 1804 intel_encoder->get_hw_state = intel_dp_mst_enc_get_hw_state; 1805 intel_encoder->get_config = intel_dp_mst_enc_get_config; 1806 intel_encoder->initial_fastset_check = intel_dp_mst_initial_fastset_check; 1807 1808 return intel_mst; 1809 1810 } 1811 1812 static bool 1813 intel_dp_create_fake_mst_encoders(struct intel_digital_port *dig_port) 1814 { 1815 struct intel_dp *intel_dp = &dig_port->dp; 1816 struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 1817 enum pipe pipe; 1818 1819 for_each_pipe(dev_priv, pipe) 1820 intel_dp->mst_encoders[pipe] = intel_dp_create_fake_mst_encoder(dig_port, pipe); 1821 return true; 1822 } 1823 1824 int 1825 intel_dp_mst_encoder_active_links(struct intel_digital_port *dig_port) 1826 { 1827 return dig_port->dp.active_mst_links; 1828 } 1829 1830 int 1831 intel_dp_mst_encoder_init(struct intel_digital_port *dig_port, int conn_base_id) 1832 { 1833 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev); 1834 struct intel_dp *intel_dp = &dig_port->dp; 1835 enum port port = dig_port->base.port; 1836 int ret; 1837 1838 if (!HAS_DP_MST(i915) || intel_dp_is_edp(intel_dp)) 1839 return 0; 1840 1841 if (DISPLAY_VER(i915) < 12 && port == PORT_A) 1842 return 0; 1843 1844 if (DISPLAY_VER(i915) < 11 && port == PORT_E) 1845 return 0; 1846 1847 intel_dp->mst_mgr.cbs = &mst_cbs; 1848 1849 /* create encoders */ 1850 intel_dp_create_fake_mst_encoders(dig_port); 1851 ret = drm_dp_mst_topology_mgr_init(&intel_dp->mst_mgr, &i915->drm, 1852 &intel_dp->aux, 16, 3, conn_base_id); 1853 if (ret) { 1854 intel_dp->mst_mgr.cbs = NULL; 1855 return ret; 1856 } 1857 1858 return 0; 1859 } 1860 1861 bool intel_dp_mst_source_support(struct intel_dp *intel_dp) 1862 { 1863 return intel_dp->mst_mgr.cbs; 1864 } 1865 1866 void 1867 intel_dp_mst_encoder_cleanup(struct intel_digital_port *dig_port) 1868 { 1869 struct intel_dp *intel_dp = &dig_port->dp; 1870 1871 if (!intel_dp_mst_source_support(intel_dp)) 1872 return; 1873 1874 drm_dp_mst_topology_mgr_destroy(&intel_dp->mst_mgr); 1875 /* encoders will get killed by normal cleanup */ 1876 1877 intel_dp->mst_mgr.cbs = NULL; 1878 } 1879 1880 bool intel_dp_mst_is_master_trans(const struct intel_crtc_state *crtc_state) 1881 { 1882 return crtc_state->mst_master_transcoder == crtc_state->cpu_transcoder; 1883 } 1884 1885 bool intel_dp_mst_is_slave_trans(const struct intel_crtc_state *crtc_state) 1886 { 1887 return crtc_state->mst_master_transcoder != INVALID_TRANSCODER && 1888 crtc_state->mst_master_transcoder != crtc_state->cpu_transcoder; 1889 } 1890 1891 /** 1892 * intel_dp_mst_add_topology_state_for_connector - add MST topology state for a connector 1893 * @state: atomic state 1894 * @connector: connector to add the state for 1895 * @crtc: the CRTC @connector is attached to 1896 * 1897 * Add the MST topology state for @connector to @state. 1898 * 1899 * Returns 0 on success, negative error code on failure. 1900 */ 1901 static int 1902 intel_dp_mst_add_topology_state_for_connector(struct intel_atomic_state *state, 1903 struct intel_connector *connector, 1904 struct intel_crtc *crtc) 1905 { 1906 struct drm_dp_mst_topology_state *mst_state; 1907 1908 if (!connector->mst_port) 1909 return 0; 1910 1911 mst_state = drm_atomic_get_mst_topology_state(&state->base, 1912 &connector->mst_port->mst_mgr); 1913 if (IS_ERR(mst_state)) 1914 return PTR_ERR(mst_state); 1915 1916 mst_state->pending_crtc_mask |= drm_crtc_mask(&crtc->base); 1917 1918 return 0; 1919 } 1920 1921 /** 1922 * intel_dp_mst_add_topology_state_for_crtc - add MST topology state for a CRTC 1923 * @state: atomic state 1924 * @crtc: CRTC to add the state for 1925 * 1926 * Add the MST topology state for @crtc to @state. 1927 * 1928 * Returns 0 on success, negative error code on failure. 1929 */ 1930 int intel_dp_mst_add_topology_state_for_crtc(struct intel_atomic_state *state, 1931 struct intel_crtc *crtc) 1932 { 1933 struct drm_connector *_connector; 1934 struct drm_connector_state *conn_state; 1935 int i; 1936 1937 for_each_new_connector_in_state(&state->base, _connector, conn_state, i) { 1938 struct intel_connector *connector = to_intel_connector(_connector); 1939 int ret; 1940 1941 if (conn_state->crtc != &crtc->base) 1942 continue; 1943 1944 ret = intel_dp_mst_add_topology_state_for_connector(state, connector, crtc); 1945 if (ret) 1946 return ret; 1947 } 1948 1949 return 0; 1950 } 1951 1952 static struct intel_connector * 1953 get_connector_in_state_for_crtc(struct intel_atomic_state *state, 1954 const struct intel_crtc *crtc) 1955 { 1956 struct drm_connector_state *old_conn_state; 1957 struct drm_connector_state *new_conn_state; 1958 struct drm_connector *_connector; 1959 int i; 1960 1961 for_each_oldnew_connector_in_state(&state->base, _connector, 1962 old_conn_state, new_conn_state, i) { 1963 struct intel_connector *connector = 1964 to_intel_connector(_connector); 1965 1966 if (old_conn_state->crtc == &crtc->base || 1967 new_conn_state->crtc == &crtc->base) 1968 return connector; 1969 } 1970 1971 return NULL; 1972 } 1973 1974 /** 1975 * intel_dp_mst_crtc_needs_modeset - check if changes in topology need to modeset the given CRTC 1976 * @state: atomic state 1977 * @crtc: CRTC for which to check the modeset requirement 1978 * 1979 * Check if any change in a MST topology requires a forced modeset on @crtc in 1980 * this topology. One such change is enabling/disabling the DSC decompression 1981 * state in the first branch device's UFP DPCD as required by one CRTC, while 1982 * the other @crtc in the same topology is still active, requiring a full modeset 1983 * on @crtc. 1984 */ 1985 bool intel_dp_mst_crtc_needs_modeset(struct intel_atomic_state *state, 1986 struct intel_crtc *crtc) 1987 { 1988 const struct intel_connector *crtc_connector; 1989 const struct drm_connector_state *conn_state; 1990 const struct drm_connector *_connector; 1991 int i; 1992 1993 if (!intel_crtc_has_type(intel_atomic_get_new_crtc_state(state, crtc), 1994 INTEL_OUTPUT_DP_MST)) 1995 return false; 1996 1997 crtc_connector = get_connector_in_state_for_crtc(state, crtc); 1998 1999 if (!crtc_connector) 2000 /* None of the connectors in the topology needs modeset */ 2001 return false; 2002 2003 for_each_new_connector_in_state(&state->base, _connector, conn_state, i) { 2004 const struct intel_connector *connector = 2005 to_intel_connector(_connector); 2006 const struct intel_crtc_state *new_crtc_state; 2007 const struct intel_crtc_state *old_crtc_state; 2008 struct intel_crtc *crtc_iter; 2009 2010 if (connector->mst_port != crtc_connector->mst_port || 2011 !conn_state->crtc) 2012 continue; 2013 2014 crtc_iter = to_intel_crtc(conn_state->crtc); 2015 2016 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc_iter); 2017 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc_iter); 2018 2019 if (!intel_crtc_needs_modeset(new_crtc_state)) 2020 continue; 2021 2022 if (old_crtc_state->dsc.compression_enable == 2023 new_crtc_state->dsc.compression_enable) 2024 continue; 2025 /* 2026 * Toggling the decompression flag because of this stream in 2027 * the first downstream branch device's UFP DPCD may reset the 2028 * whole branch device. To avoid the reset while other streams 2029 * are also active modeset the whole MST topology in this 2030 * case. 2031 */ 2032 if (connector->dp.dsc_decompression_aux == 2033 &connector->mst_port->aux) 2034 return true; 2035 } 2036 2037 return false; 2038 } 2039 2040 /** 2041 * intel_dp_mst_prepare_probe - Prepare an MST link for topology probing 2042 * @intel_dp: DP port object 2043 * 2044 * Prepare an MST link for topology probing, programming the target 2045 * link parameters to DPCD. This step is a requirement of the enumaration 2046 * of path resources during probing. 2047 */ 2048 void intel_dp_mst_prepare_probe(struct intel_dp *intel_dp) 2049 { 2050 int link_rate = intel_dp_max_link_rate(intel_dp); 2051 int lane_count = intel_dp_max_lane_count(intel_dp); 2052 u8 rate_select; 2053 u8 link_bw; 2054 2055 if (intel_dp->link_trained) 2056 return; 2057 2058 if (intel_mst_probed_link_params_valid(intel_dp, link_rate, lane_count)) 2059 return; 2060 2061 intel_dp_compute_rate(intel_dp, link_rate, &link_bw, &rate_select); 2062 2063 intel_dp_link_training_set_mode(intel_dp, link_rate, false); 2064 intel_dp_link_training_set_bw(intel_dp, link_bw, rate_select, lane_count, 2065 drm_dp_enhanced_frame_cap(intel_dp->dpcd)); 2066 2067 intel_mst_set_probed_link_params(intel_dp, link_rate, lane_count); 2068 } 2069 2070 /* 2071 * intel_dp_mst_verify_dpcd_state - verify the MST SW enabled state wrt. the DPCD 2072 * @intel_dp: DP port object 2073 * 2074 * Verify if @intel_dp's MST enabled SW state matches the corresponding DPCD 2075 * state. A long HPD pulse - not long enough to be detected as a disconnected 2076 * state - could've reset the DPCD state, which requires tearing 2077 * down/recreating the MST topology. 2078 * 2079 * Returns %true if the SW MST enabled and DPCD states match, %false 2080 * otherwise. 2081 */ 2082 bool intel_dp_mst_verify_dpcd_state(struct intel_dp *intel_dp) 2083 { 2084 struct intel_display *display = to_intel_display(intel_dp); 2085 struct intel_connector *connector = intel_dp->attached_connector; 2086 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 2087 struct intel_encoder *encoder = &dig_port->base; 2088 int ret; 2089 u8 val; 2090 2091 if (!intel_dp->is_mst) 2092 return true; 2093 2094 ret = drm_dp_dpcd_readb(intel_dp->mst_mgr.aux, DP_MSTM_CTRL, &val); 2095 2096 /* Adjust the expected register value for SST + SideBand. */ 2097 if (ret < 0 || val != (DP_MST_EN | DP_UP_REQ_EN | DP_UPSTREAM_IS_SRC)) { 2098 drm_dbg_kms(display->drm, 2099 "[CONNECTOR:%d:%s][ENCODER:%d:%s] MST mode got reset, removing topology (ret=%d, ctrl=0x%02x)\n", 2100 connector->base.base.id, connector->base.name, 2101 encoder->base.base.id, encoder->base.name, 2102 ret, val); 2103 2104 return false; 2105 } 2106 2107 return true; 2108 } 2109