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