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