1 /* 2 * Copyright © 2008 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * Authors: 24 * Keith Packard <keithp@keithp.com> 25 * 26 */ 27 28 #include <linux/export.h> 29 #include <linux/i2c.h> 30 #include <linux/iopoll.h> 31 #include <linux/log2.h> 32 #include <linux/math.h> 33 #include <linux/notifier.h> 34 #include <linux/seq_buf.h> 35 #include <linux/slab.h> 36 #include <linux/string_helpers.h> 37 #include <linux/timekeeping.h> 38 #include <linux/types.h> 39 #include <asm/byteorder.h> 40 41 #include <drm/display/drm_dp_helper.h> 42 #include <drm/display/drm_dp_tunnel.h> 43 #include <drm/display/drm_dsc_helper.h> 44 #include <drm/display/drm_hdmi_helper.h> 45 #include <drm/drm_atomic_helper.h> 46 #include <drm/drm_crtc.h> 47 #include <drm/drm_edid.h> 48 #include <drm/drm_fixed.h> 49 #include <drm/drm_print.h> 50 #include <drm/drm_probe_helper.h> 51 52 #include "g4x_dp.h" 53 #include "intel_alpm.h" 54 #include "intel_atomic.h" 55 #include "intel_audio.h" 56 #include "intel_backlight.h" 57 #include "intel_combo_phy_regs.h" 58 #include "intel_connector.h" 59 #include "intel_crtc.h" 60 #include "intel_crtc_state_dump.h" 61 #include "intel_cx0_phy.h" 62 #include "intel_ddi.h" 63 #include "intel_de.h" 64 #include "intel_display_driver.h" 65 #include "intel_display_jiffies.h" 66 #include "intel_display_utils.h" 67 #include "intel_display_regs.h" 68 #include "intel_display_rpm.h" 69 #include "intel_display_types.h" 70 #include "intel_dp.h" 71 #include "intel_dp_aux.h" 72 #include "intel_dp_hdcp.h" 73 #include "intel_dp_link_caps.h" 74 #include "intel_dp_link_training.h" 75 #include "intel_dp_mst.h" 76 #include "intel_dp_test.h" 77 #include "intel_dp_tunnel.h" 78 #include "intel_dpio_phy.h" 79 #include "intel_dpll.h" 80 #include "intel_drrs.h" 81 #include "intel_encoder.h" 82 #include "intel_fifo_underrun.h" 83 #include "intel_hdcp.h" 84 #include "intel_hdmi.h" 85 #include "intel_hotplug.h" 86 #include "intel_hotplug_irq.h" 87 #include "intel_lspcon.h" 88 #include "intel_lvds.h" 89 #include "intel_modeset_lock.h" 90 #include "intel_panel.h" 91 #include "intel_pch_display.h" 92 #include "intel_pfit.h" 93 #include "intel_pps.h" 94 #include "intel_psr.h" 95 #include "intel_quirks.h" 96 #include "intel_tc.h" 97 #include "intel_vblank.h" 98 #include "intel_vdsc.h" 99 #include "intel_vrr.h" 100 101 /* Max DSC line buffer depth supported by HW. */ 102 #define INTEL_DP_DSC_MAX_LINE_BUF_DEPTH 13 103 104 /* DP DSC FEC Overhead factor in ppm = 1/(0.972261) = 1.028530 */ 105 #define DP_DSC_FEC_OVERHEAD_FACTOR 1028530 106 107 /* Constants for DP DSC configurations */ 108 static const u8 valid_dsc_bpp[] = {6, 8, 10, 12, 15}; 109 110 /** 111 * intel_dp_is_edp - is the given port attached to an eDP panel (either CPU or PCH) 112 * @intel_dp: DP struct 113 * 114 * If a CPU or PCH DP output is attached to an eDP panel, this function 115 * will return true, and false otherwise. 116 * 117 * This function is not safe to use prior to encoder type being set. 118 */ 119 bool intel_dp_is_edp(struct intel_dp *intel_dp) 120 { 121 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 122 123 return dig_port->base.type == INTEL_OUTPUT_EDP; 124 } 125 126 static void intel_dp_unset_edid(struct intel_dp *intel_dp); 127 128 /* Is link rate UHBR and thus 128b/132b? */ 129 bool intel_dp_is_uhbr(const struct intel_crtc_state *crtc_state) 130 { 131 return drm_dp_is_uhbr_rate(crtc_state->port_clock); 132 } 133 134 /** 135 * intel_dp_link_symbol_size - get the link symbol size for a given link rate 136 * @rate: link rate in 10kbit/s units 137 * 138 * Returns the link symbol size in bits/symbol units depending on the link 139 * rate -> channel coding. 140 */ 141 int intel_dp_link_symbol_size(int rate) 142 { 143 return drm_dp_is_uhbr_rate(rate) ? 32 : 10; 144 } 145 146 /** 147 * intel_dp_link_symbol_clock - convert link rate to link symbol clock 148 * @rate: link rate in 10kbit/s units 149 * 150 * Returns the link symbol clock frequency in kHz units depending on the 151 * link rate and channel coding. 152 */ 153 int intel_dp_link_symbol_clock(int rate) 154 { 155 return DIV_ROUND_CLOSEST(rate * 10, intel_dp_link_symbol_size(rate)); 156 } 157 158 static int max_dprx_rate(struct intel_dp *intel_dp) 159 { 160 struct intel_display *display = to_intel_display(intel_dp); 161 int max_rate; 162 163 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 164 max_rate = drm_dp_tunnel_max_dprx_rate(intel_dp->tunnel); 165 else 166 max_rate = drm_dp_bw_code_to_link_rate(intel_dp->dpcd[DP_MAX_LINK_RATE]); 167 168 /* 169 * Some platforms + eDP panels may not reliably support HBR3 170 * due to signal integrity limitations, despite advertising it. 171 * Cap the link rate to HBR2 to avoid unstable configurations for the 172 * known machines. 173 */ 174 if (intel_dp_is_edp(intel_dp) && intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2)) 175 max_rate = min(max_rate, 540000); 176 177 return max_rate; 178 } 179 180 static int max_dprx_lane_count(struct intel_dp *intel_dp) 181 { 182 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 183 return drm_dp_tunnel_max_dprx_lane_count(intel_dp->tunnel); 184 185 return drm_dp_max_lane_count(intel_dp->dpcd); 186 } 187 188 static void intel_dp_set_default_sink_rates(struct intel_dp *intel_dp) 189 { 190 intel_dp->sink_rates[0] = 162000; 191 intel_dp->num_sink_rates = 1; 192 } 193 194 static bool dprx_supports_128b132b(struct intel_dp *intel_dp) 195 { 196 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 197 return drm_dp_tunnel_128b132b_supported(intel_dp->tunnel); 198 else 199 return drm_dp_128b132b_supported(intel_dp->dpcd); 200 } 201 202 static u8 dprx_128b132b_link_rates(struct intel_dp *intel_dp, u8 no_bwa_rates) 203 { 204 u8 ret; 205 206 if (!intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 207 return no_bwa_rates; 208 209 ret = drm_dp_tunnel_128b132b_dprx_rates(intel_dp->tunnel); 210 static_assert(DP_TUNNELING_10GBPS_PER_LANE_SUPPORT == DP_UHBR10 && 211 DP_TUNNELING_13_5GBPS_PER_LANE_SUPPORT == DP_UHBR13_5 && 212 DP_TUNNELING_20GBPS_PER_LANE_SUPPORT == DP_UHBR20); 213 214 return ret; 215 } 216 217 /* update sink rates from dpcd */ 218 static void intel_dp_set_dpcd_sink_rates(struct intel_dp *intel_dp) 219 { 220 static const int dp_rates[] = { 221 162000, 270000, 540000, 810000 222 }; 223 int i, max_rate; 224 int max_lttpr_rate; 225 u8 uhbr_rates = 0; 226 227 if (drm_dp_has_quirk(&intel_dp->desc, DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS)) { 228 /* Needed, e.g., for Apple MBP 2017, 15 inch eDP Retina panel */ 229 static const int quirk_rates[] = { 162000, 270000, 324000 }; 230 231 memcpy(intel_dp->sink_rates, quirk_rates, sizeof(quirk_rates)); 232 intel_dp->num_sink_rates = ARRAY_SIZE(quirk_rates); 233 234 return; 235 } 236 237 /* 238 * Sink rates for 8b/10b. 239 */ 240 max_rate = max_dprx_rate(intel_dp); 241 max_lttpr_rate = drm_dp_lttpr_max_link_rate(intel_dp->lttpr_common_caps); 242 if (max_lttpr_rate) 243 max_rate = min(max_rate, max_lttpr_rate); 244 245 for (i = 0; i < ARRAY_SIZE(dp_rates); i++) { 246 if (dp_rates[i] > max_rate) 247 break; 248 intel_dp->sink_rates[i] = dp_rates[i]; 249 } 250 251 /* 252 * The following register must be read unconditionally for the later 253 * DP tunnel 128b132b detection to work, see DP Standard v2.1 5.14.3 . 254 */ 255 drm_dp_dpcd_read_byte(&intel_dp->aux, DP_128B132B_SUPPORTED_LINK_RATES, &uhbr_rates); 256 257 /* 258 * Sink rates for 128b/132b. If set, sink should support all 8b/10b 259 * rates and 10 Gbps. 260 */ 261 if (dprx_supports_128b132b(intel_dp)) { 262 BUILD_BUG_ON(ARRAY_SIZE(intel_dp->sink_rates) < ARRAY_SIZE(dp_rates) + 3); 263 264 uhbr_rates = dprx_128b132b_link_rates(intel_dp, uhbr_rates); 265 266 if (drm_dp_lttpr_count(intel_dp->lttpr_common_caps)) { 267 /* We have a repeater */ 268 if (intel_dp->lttpr_common_caps[0] >= 0x20 && 269 intel_dp->lttpr_common_caps[DP_MAIN_LINK_CHANNEL_CODING_PHY_REPEATER - 270 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV] & 271 DP_PHY_REPEATER_128B132B_SUPPORTED) { 272 /* Repeater supports 128b/132b, valid UHBR rates */ 273 uhbr_rates &= intel_dp->lttpr_common_caps[DP_PHY_REPEATER_128B132B_RATES - 274 DP_LT_TUNABLE_PHY_REPEATER_FIELD_DATA_STRUCTURE_REV]; 275 } else { 276 /* Does not support 128b/132b */ 277 uhbr_rates = 0; 278 } 279 } 280 281 if (uhbr_rates & DP_UHBR10) 282 intel_dp->sink_rates[i++] = 1000000; 283 if (uhbr_rates & DP_UHBR13_5) 284 intel_dp->sink_rates[i++] = 1350000; 285 if (uhbr_rates & DP_UHBR20) 286 intel_dp->sink_rates[i++] = 2000000; 287 } 288 289 intel_dp->num_sink_rates = i; 290 } 291 292 static void intel_dp_set_sink_rates(struct intel_dp *intel_dp) 293 { 294 struct intel_display *display = to_intel_display(intel_dp); 295 struct intel_connector *connector = intel_dp->attached_connector; 296 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 297 struct intel_encoder *encoder = &intel_dig_port->base; 298 299 intel_dp_set_dpcd_sink_rates(intel_dp); 300 301 if (intel_dp->num_sink_rates) 302 return; 303 304 drm_err(display->drm, 305 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Invalid DPCD with no link rates, using defaults\n", 306 connector->base.base.id, connector->base.name, 307 encoder->base.base.id, encoder->base.name); 308 309 intel_dp_set_default_sink_rates(intel_dp); 310 } 311 312 static void intel_dp_set_default_max_sink_lane_count(struct intel_dp *intel_dp) 313 { 314 intel_dp->max_sink_lane_count = 1; 315 } 316 317 static void intel_dp_set_max_sink_lane_count(struct intel_dp *intel_dp) 318 { 319 struct intel_display *display = to_intel_display(intel_dp); 320 struct intel_connector *connector = intel_dp->attached_connector; 321 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 322 struct intel_encoder *encoder = &intel_dig_port->base; 323 324 intel_dp->max_sink_lane_count = max_dprx_lane_count(intel_dp); 325 326 switch (intel_dp->max_sink_lane_count) { 327 case 1: 328 case 2: 329 case 4: 330 return; 331 } 332 333 drm_err(display->drm, 334 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Invalid DPCD max lane count (%d), using default\n", 335 connector->base.base.id, connector->base.name, 336 encoder->base.base.id, encoder->base.name, 337 intel_dp->max_sink_lane_count); 338 339 intel_dp_set_default_max_sink_lane_count(intel_dp); 340 } 341 342 /* Get length of rates array potentially limited by max_rate. */ 343 int intel_dp_rate_limit_len(const int *rates, int len, int max_rate) 344 { 345 int i; 346 347 /* Limit results by potentially reduced max rate */ 348 for (i = 0; i < len; i++) { 349 if (rates[len - i - 1] <= max_rate) 350 return len - i; 351 } 352 353 return 0; 354 } 355 356 int intel_dp_max_source_lane_count(struct intel_digital_port *dig_port) 357 { 358 int vbt_max_lanes = intel_bios_dp_max_lane_count(dig_port->base.devdata); 359 int max_lanes = dig_port->max_lanes; 360 361 if (vbt_max_lanes) 362 max_lanes = min(max_lanes, vbt_max_lanes); 363 364 return max_lanes; 365 } 366 367 /* 368 * Theoretical max between source and sink. 369 */ 370 static int intel_dp_get_max_common_lane_count(struct intel_dp *intel_dp) 371 { 372 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 373 int source_max = intel_dp_max_source_lane_count(dig_port); 374 int sink_max = intel_dp->max_sink_lane_count; 375 int lane_max = intel_tc_port_max_lane_count(dig_port); 376 int lttpr_max = drm_dp_lttpr_max_lane_count(intel_dp->lttpr_common_caps); 377 378 if (lttpr_max) 379 sink_max = min(sink_max, lttpr_max); 380 381 return min3(source_max, sink_max, lane_max); 382 } 383 384 int intel_dp_link_bw_overhead(int link_clock, int lane_count, int hdisplay, 385 int dsc_slice_count, int bpp_x16, unsigned long flags) 386 { 387 int overhead; 388 389 WARN_ON(flags & ~(DRM_DP_BW_OVERHEAD_MST | DRM_DP_BW_OVERHEAD_SSC_REF_CLK | 390 DRM_DP_BW_OVERHEAD_FEC)); 391 392 if (drm_dp_is_uhbr_rate(link_clock)) 393 flags |= DRM_DP_BW_OVERHEAD_UHBR; 394 395 if (dsc_slice_count) 396 flags |= DRM_DP_BW_OVERHEAD_DSC; 397 398 overhead = drm_dp_bw_overhead(lane_count, hdisplay, 399 dsc_slice_count, 400 bpp_x16, 401 flags); 402 403 /* 404 * TODO: clarify whether a minimum required by the fixed FEC overhead 405 * in the bspec audio programming sequence is required here. 406 */ 407 return max(overhead, intel_dp_bw_fec_overhead(flags & DRM_DP_BW_OVERHEAD_FEC)); 408 } 409 410 /* 411 * The required data bandwidth for a mode with given pixel clock and bpp. This 412 * is the required net bandwidth independent of the data bandwidth efficiency. 413 */ 414 int intel_dp_link_required(int link_clock, int lane_count, 415 int mode_clock, int mode_hdisplay, 416 int link_bpp_x16, unsigned long bw_overhead_flags) 417 { 418 int bw_overhead = intel_dp_link_bw_overhead(link_clock, lane_count, mode_hdisplay, 419 0, link_bpp_x16, bw_overhead_flags); 420 421 return intel_dp_effective_data_rate(mode_clock, link_bpp_x16, bw_overhead); 422 } 423 424 /** 425 * intel_dp_effective_data_rate - Return the pixel data rate accounting for BW allocation overhead 426 * @pixel_clock: pixel clock in kHz 427 * @bpp_x16: bits per pixel .4 fixed point format 428 * @bw_overhead: BW allocation overhead in 1ppm units 429 * 430 * Return the effective pixel data rate in kB/sec units taking into account 431 * the provided SSC, FEC, DSC BW allocation overhead. 432 */ 433 int intel_dp_effective_data_rate(int pixel_clock, int bpp_x16, 434 int bw_overhead) 435 { 436 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_clock * bpp_x16, bw_overhead), 437 1000000 * 16 * 8); 438 } 439 440 /** 441 * intel_dp_max_link_data_rate: Calculate the maximum rate for the given link params 442 * @intel_dp: Intel DP object 443 * @max_dprx_rate: Maximum data rate of the DPRX 444 * @max_dprx_lanes: Maximum lane count of the DPRX 445 * 446 * Calculate the maximum data rate for the provided link parameters taking into 447 * account any BW limitations by a DP tunnel attached to @intel_dp. 448 * 449 * Returns the maximum data rate in kBps units. 450 */ 451 int intel_dp_max_link_data_rate(struct intel_dp *intel_dp, 452 int max_dprx_rate, int max_dprx_lanes) 453 { 454 int max_rate = drm_dp_max_dprx_data_rate(max_dprx_rate, max_dprx_lanes); 455 456 if (intel_dp_tunnel_bw_alloc_is_enabled(intel_dp)) 457 max_rate = min(max_rate, 458 drm_dp_tunnel_available_bw(intel_dp->tunnel)); 459 460 return max_rate; 461 } 462 463 bool intel_dp_has_joiner(struct intel_dp *intel_dp) 464 { 465 struct intel_display *display = to_intel_display(intel_dp); 466 struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 467 struct intel_encoder *encoder = &intel_dig_port->base; 468 struct intel_connector *connector = intel_dp->attached_connector; 469 470 /* eDP MSO is not compatible with joiner */ 471 if (intel_dp->mso_link_count) 472 return false; 473 474 if (intel_dp_is_edp(intel_dp) && 475 !connector->panel.vbt.edp.pipe_joiner_enable) 476 return false; 477 478 return DISPLAY_VER(display) >= 12 || 479 (DISPLAY_VER(display) == 11 && 480 encoder->port != PORT_A); 481 } 482 483 static int dg2_max_source_rate(struct intel_dp *intel_dp) 484 { 485 return intel_dp_is_edp(intel_dp) ? 810000 : 1350000; 486 } 487 488 static int icl_max_source_rate(struct intel_dp *intel_dp) 489 { 490 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 491 492 if (intel_encoder_is_combo(encoder) && !intel_dp_is_edp(intel_dp)) 493 return 540000; 494 495 return 810000; 496 } 497 498 static int ehl_max_source_rate(struct intel_dp *intel_dp) 499 { 500 if (intel_dp_is_edp(intel_dp)) 501 return 540000; 502 503 return 810000; 504 } 505 506 static int mtl_max_source_rate(struct intel_dp *intel_dp) 507 { 508 struct intel_display *display = to_intel_display(intel_dp); 509 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 510 511 if (intel_encoder_is_c10phy(encoder) || 512 display->platform.pantherlake_wildcatlake) 513 return 810000; 514 515 if (DISPLAY_VERx100(display) == 1401) 516 return 1350000; 517 518 return 2000000; 519 } 520 521 static int vbt_max_link_rate(struct intel_dp *intel_dp) 522 { 523 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 524 int max_rate; 525 526 max_rate = intel_bios_dp_max_link_rate(encoder->devdata); 527 528 if (intel_dp_is_edp(intel_dp)) { 529 struct intel_connector *connector = intel_dp->attached_connector; 530 int edp_max_rate = connector->panel.vbt.edp.max_link_rate; 531 532 if (max_rate && edp_max_rate) 533 max_rate = min(max_rate, edp_max_rate); 534 else if (edp_max_rate) 535 max_rate = edp_max_rate; 536 } 537 538 return max_rate; 539 } 540 541 static void 542 intel_dp_set_source_rates(struct intel_dp *intel_dp) 543 { 544 /* The values must be in increasing order */ 545 static const int bmg_rates[] = { 546 162000, 216000, 243000, 270000, 324000, 432000, 540000, 675000, 547 810000, 1000000, 1350000, 548 }; 549 static const int mtl_rates[] = { 550 162000, 216000, 243000, 270000, 324000, 432000, 540000, 675000, 551 810000, 1000000, 2000000, 552 }; 553 static const int icl_rates[] = { 554 162000, 216000, 270000, 324000, 432000, 540000, 648000, 810000, 555 1000000, 1350000, 556 }; 557 static const int bxt_rates[] = { 558 162000, 216000, 243000, 270000, 324000, 432000, 540000 559 }; 560 static const int skl_rates[] = { 561 162000, 216000, 270000, 324000, 432000, 540000 562 }; 563 static const int hsw_rates[] = { 564 162000, 270000, 540000 565 }; 566 static const int g4x_rates[] = { 567 162000, 270000 568 }; 569 struct intel_display *display = to_intel_display(intel_dp); 570 const int *source_rates; 571 int size, max_rate = 0, vbt_max_rate; 572 573 /* This should only be done once */ 574 drm_WARN_ON(display->drm, 575 intel_dp->source_rates || intel_dp->num_source_rates); 576 577 if (DISPLAY_VER(display) >= 14) { 578 if (display->platform.battlemage) { 579 source_rates = bmg_rates; 580 size = ARRAY_SIZE(bmg_rates); 581 } else { 582 source_rates = mtl_rates; 583 size = ARRAY_SIZE(mtl_rates); 584 } 585 max_rate = mtl_max_source_rate(intel_dp); 586 } else if (DISPLAY_VER(display) >= 11) { 587 source_rates = icl_rates; 588 size = ARRAY_SIZE(icl_rates); 589 if (display->platform.dg2) 590 max_rate = dg2_max_source_rate(intel_dp); 591 else if (display->platform.alderlake_p || display->platform.alderlake_s || 592 display->platform.dg1 || display->platform.rocketlake) 593 max_rate = 810000; 594 else if (display->platform.jasperlake || display->platform.elkhartlake) 595 max_rate = ehl_max_source_rate(intel_dp); 596 else 597 max_rate = icl_max_source_rate(intel_dp); 598 } else if (display->platform.geminilake || display->platform.broxton) { 599 source_rates = bxt_rates; 600 size = ARRAY_SIZE(bxt_rates); 601 } else if (DISPLAY_VER(display) == 9) { 602 source_rates = skl_rates; 603 size = ARRAY_SIZE(skl_rates); 604 } else if ((display->platform.haswell && !display->platform.haswell_ulx) || 605 display->platform.broadwell) { 606 source_rates = hsw_rates; 607 size = ARRAY_SIZE(hsw_rates); 608 } else { 609 source_rates = g4x_rates; 610 size = ARRAY_SIZE(g4x_rates); 611 } 612 613 vbt_max_rate = vbt_max_link_rate(intel_dp); 614 if (max_rate && vbt_max_rate) 615 max_rate = min(max_rate, vbt_max_rate); 616 else if (vbt_max_rate) 617 max_rate = vbt_max_rate; 618 619 if (max_rate) 620 size = intel_dp_rate_limit_len(source_rates, size, max_rate); 621 622 intel_dp->source_rates = source_rates; 623 intel_dp->num_source_rates = size; 624 } 625 626 static int intersect_rates(const int *source_rates, int source_len, 627 const int *sink_rates, int sink_len, 628 int *common_rates) 629 { 630 int i = 0, j = 0, k = 0; 631 632 while (i < source_len && j < sink_len) { 633 if (source_rates[i] == sink_rates[j]) { 634 if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES)) 635 return k; 636 common_rates[k] = source_rates[i]; 637 ++k; 638 ++i; 639 ++j; 640 } else if (source_rates[i] < sink_rates[j]) { 641 ++i; 642 } else { 643 ++j; 644 } 645 } 646 return k; 647 } 648 649 /* return index of rate in rates array, or -1 if not found */ 650 int intel_dp_rate_index(const int *rates, int len, int rate) 651 { 652 int i; 653 654 for (i = 0; i < len; i++) 655 if (rate == rates[i]) 656 return i; 657 658 return -1; 659 } 660 661 static void intel_dp_get_common_rates(struct intel_dp *intel_dp, 662 int common_rates[DP_MAX_SUPPORTED_RATES], 663 int *num_common_rates) 664 { 665 struct intel_display *display = to_intel_display(intel_dp); 666 667 drm_WARN_ON(display->drm, 668 !intel_dp->num_source_rates || !intel_dp->num_sink_rates); 669 670 *num_common_rates = intersect_rates(intel_dp->source_rates, 671 intel_dp->num_source_rates, 672 intel_dp->sink_rates, 673 intel_dp->num_sink_rates, 674 common_rates); 675 676 /* Paranoia, there should always be something in common. */ 677 if (drm_WARN_ON(display->drm, *num_common_rates == 0)) { 678 common_rates[0] = 162000; 679 *num_common_rates = 1; 680 } 681 } 682 683 /* Return %true if any common link param changed. */ 684 static bool intel_dp_set_common_link_params(struct intel_dp *intel_dp) 685 { 686 int num_common_rates; 687 int common_rates[DP_MAX_SUPPORTED_RATES]; 688 bool params_changed = false; 689 690 intel_dp_get_common_rates(intel_dp, common_rates, &num_common_rates); 691 if (intel_dp_link_caps_update(intel_dp->link.caps, 692 common_rates, num_common_rates, 693 intel_dp_get_max_common_lane_count(intel_dp), 694 intel_dp->reset_link_params)) 695 params_changed = true; 696 697 return params_changed; 698 } 699 700 u32 intel_dp_mode_to_fec_clock(u32 mode_clock) 701 { 702 return div_u64(mul_u32_u32(mode_clock, DP_DSC_FEC_OVERHEAD_FACTOR), 703 1000000U); 704 } 705 706 int intel_dp_bw_fec_overhead(bool fec_enabled) 707 { 708 /* 709 * TODO: Calculate the actual overhead for a given mode. 710 * The hard-coded 1/0.972261=2.853% overhead factor 711 * corresponds (for instance) to the 8b/10b DP FEC 2.4% + 712 * 0.453% DSC overhead. This is enough for a 3840 width mode, 713 * which has a DSC overhead of up to ~0.2%, but may not be 714 * enough for a 1024 width mode where this is ~0.8% (on a 4 715 * lane DP link, with 2 DSC slices and 8 bpp color depth). 716 */ 717 return fec_enabled ? DP_DSC_FEC_OVERHEAD_FACTOR : 1000000; 718 } 719 720 static int 721 small_joiner_ram_size_bits(struct intel_display *display) 722 { 723 if (DISPLAY_VER(display) >= 13) 724 return 17280 * 8; 725 else if (DISPLAY_VER(display) >= 11) 726 return 7680 * 8; 727 else 728 return 6144 * 8; 729 } 730 731 static int align_min_vesa_compressed_bpp_x16(int min_link_bpp_x16) 732 { 733 int i; 734 735 for (i = 0; i < ARRAY_SIZE(valid_dsc_bpp); i++) { 736 int vesa_bpp_x16 = fxp_q4_from_int(valid_dsc_bpp[i]); 737 738 if (vesa_bpp_x16 >= min_link_bpp_x16) 739 return vesa_bpp_x16; 740 } 741 742 return 0; 743 } 744 745 static int align_max_vesa_compressed_bpp_x16(int max_link_bpp_x16) 746 { 747 int i; 748 749 for (i = ARRAY_SIZE(valid_dsc_bpp) - 1; i >= 0; i--) { 750 int vesa_bpp_x16 = fxp_q4_from_int(valid_dsc_bpp[i]); 751 752 if (vesa_bpp_x16 <= max_link_bpp_x16) 753 return vesa_bpp_x16; 754 } 755 756 return 0; 757 } 758 759 static int bigjoiner_interface_bits(struct intel_display *display) 760 { 761 return DISPLAY_VER(display) >= 14 ? 36 : 24; 762 } 763 764 static u32 bigjoiner_bw_max_bpp(struct intel_display *display, u32 mode_clock, 765 int num_joined_pipes) 766 { 767 u32 max_bpp; 768 /* With bigjoiner multiple dsc engines are used in parallel so PPC is 2 */ 769 int ppc = 2; 770 int num_big_joiners = num_joined_pipes / 2; 771 772 max_bpp = display->cdclk.max_cdclk_freq * ppc * bigjoiner_interface_bits(display) / 773 intel_dp_mode_to_fec_clock(mode_clock); 774 775 max_bpp *= num_big_joiners; 776 777 return max_bpp; 778 779 } 780 781 static u32 small_joiner_ram_max_bpp(struct intel_display *display, 782 u32 mode_hdisplay, 783 int num_joined_pipes) 784 { 785 u32 max_bpp; 786 787 /* Small Joiner Check: output bpp <= joiner RAM (bits) / Horiz. width */ 788 max_bpp = small_joiner_ram_size_bits(display) / mode_hdisplay; 789 790 max_bpp *= num_joined_pipes; 791 792 return max_bpp; 793 } 794 795 static int ultrajoiner_ram_bits(void) 796 { 797 return 4 * 72 * 512; 798 } 799 800 static u32 ultrajoiner_ram_max_bpp(u32 mode_hdisplay) 801 { 802 return ultrajoiner_ram_bits() / mode_hdisplay; 803 } 804 805 /* TODO: return a bpp_x16 value */ 806 static 807 u32 get_max_compressed_bpp_with_joiner(struct intel_display *display, 808 u32 mode_clock, u32 mode_hdisplay, 809 int num_joined_pipes) 810 { 811 u32 max_bpp = small_joiner_ram_max_bpp(display, mode_hdisplay, num_joined_pipes); 812 813 if (num_joined_pipes > 1) 814 max_bpp = min(max_bpp, bigjoiner_bw_max_bpp(display, mode_clock, 815 num_joined_pipes)); 816 if (num_joined_pipes == 4) 817 max_bpp = min(max_bpp, ultrajoiner_ram_max_bpp(mode_hdisplay)); 818 819 return max_bpp; 820 } 821 822 static int intel_dp_dsc_min_slice_count(const struct intel_connector *connector, 823 int mode_clock, int mode_hdisplay) 824 { 825 struct intel_display *display = to_intel_display(connector); 826 bool is_edp = 827 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP; 828 int min_slice_count; 829 int max_slice_width; 830 int tp_rgb_yuv444; 831 int tp_yuv422_420; 832 833 /* 834 * TODO: allow using less than the maximum number of slices 835 * supported by the eDP sink, to allow using fewer DSC engines. 836 */ 837 if (is_edp) 838 return drm_dp_dsc_sink_max_slice_count(connector->dp.dsc_dpcd, true); 839 840 /* 841 * TODO: Use the throughput value specific to the actual RGB/YUV 842 * format of the output. 843 * The RGB/YUV444 throughput value should be always either equal 844 * or smaller than the YUV422/420 value, but let's not depend on 845 * this assumption. 846 */ 847 if (mode_clock > max(connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444, 848 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420)) 849 return 0; 850 851 if (mode_hdisplay > connector->dp.dsc_branch_caps.max_line_width) 852 return 0; 853 854 /* 855 * TODO: Pass the total pixel rate of all the streams transferred to 856 * an MST tiled display, calculate the total slice count for all tiles 857 * from this and the per-tile slice count from the total slice count. 858 */ 859 tp_rgb_yuv444 = drm_dp_dsc_sink_max_slice_throughput(connector->dp.dsc_dpcd, 860 mode_clock, true); 861 tp_yuv422_420 = drm_dp_dsc_sink_max_slice_throughput(connector->dp.dsc_dpcd, 862 mode_clock, false); 863 864 /* 865 * TODO: Use the throughput value specific to the actual RGB/YUV 866 * format of the output. 867 * For now use the smaller of these, which is ok, potentially 868 * resulting in a higher than required minimum slice count. 869 * The RGB/YUV444 throughput value should be always either equal 870 * or smaller than the YUV422/420 value, but let's not depend on 871 * this assumption. 872 */ 873 min_slice_count = DIV_ROUND_UP(mode_clock, min(tp_rgb_yuv444, tp_yuv422_420)); 874 875 /* 876 * Due to some DSC engine BW limitations, we need to enable second 877 * slice and VDSC engine, whenever we approach close enough to max CDCLK 878 */ 879 if (mode_clock >= ((display->cdclk.max_cdclk_freq * 85) / 100)) 880 min_slice_count = max(min_slice_count, 2); 881 882 max_slice_width = drm_dp_dsc_sink_max_slice_width(connector->dp.dsc_dpcd); 883 if (max_slice_width < DP_DSC_MIN_SLICE_WIDTH_VALUE) { 884 drm_dbg_kms(display->drm, 885 "Unsupported slice width %d by DP DSC Sink device\n", 886 max_slice_width); 887 return 0; 888 } 889 /* Also take into account max slice width */ 890 min_slice_count = max(min_slice_count, 891 DIV_ROUND_UP(mode_hdisplay, max_slice_width)); 892 893 return min_slice_count; 894 } 895 896 static bool 897 intel_dp_dsc_get_slice_config(const struct intel_connector *connector, 898 int mode_clock, int mode_hdisplay, 899 int num_joined_pipes, 900 struct intel_dsc_slice_config *config_ret) 901 { 902 struct intel_display *display = to_intel_display(connector); 903 int min_slice_count = 904 intel_dp_dsc_min_slice_count(connector, mode_clock, mode_hdisplay); 905 bool is_edp = 906 connector->base.connector_type == DRM_MODE_CONNECTOR_eDP; 907 u32 sink_slice_count_mask = 908 drm_dp_dsc_sink_slice_count_mask(connector->dp.dsc_dpcd, is_edp); 909 int slices_per_pipe; 910 911 /* 912 * Find the closest match to the valid slice count values 913 * 914 * Max HW DSC-per-pipe x slice-per-DSC (= slice-per-pipe) capability: 915 * ICL: 2x2 916 * BMG: 2x2, or for ultrajoined 4 pipes: 3x1 917 * TGL+: 2x4 (TODO: Add support for this) 918 * 919 * TODO: Explore if it's worth increasing the number of slices (from 1 920 * to 2 or 3), so that multiple VDSC engines can be used, thus 921 * reducing the minimum CDCLK requirement, which in turn is determined 922 * by the 1 pixel per clock VDSC engine throughput in 923 * intel_vdsc_min_cdclk(). 924 */ 925 for (slices_per_pipe = 1; slices_per_pipe <= 4; slices_per_pipe++) { 926 struct intel_dsc_slice_config config; 927 int slices_per_line; 928 929 if (!intel_dsc_get_slice_config(display, 930 num_joined_pipes, slices_per_pipe, 931 &config)) 932 continue; 933 934 slices_per_line = intel_dsc_line_slice_count(&config); 935 936 if (!(drm_dp_dsc_slice_count_to_mask(slices_per_line) & 937 sink_slice_count_mask)) 938 continue; 939 940 if (mode_hdisplay % slices_per_line) 941 continue; 942 943 if (min_slice_count <= slices_per_line) { 944 *config_ret = config; 945 946 return true; 947 } 948 } 949 950 /* Print slice count 1,2,4,..24 if bit#0,1,3,..23 is set in the mask. */ 951 sink_slice_count_mask <<= 1; 952 drm_dbg_kms(display->drm, 953 "[CONNECTOR:%d:%s] Unsupported slice count (min: %d, sink supported: %*pbl)\n", 954 connector->base.base.id, connector->base.name, 955 min_slice_count, 956 (int)BITS_PER_TYPE(sink_slice_count_mask), &sink_slice_count_mask); 957 958 return false; 959 } 960 961 u8 intel_dp_dsc_get_slice_count(const struct intel_connector *connector, 962 int mode_clock, int mode_hdisplay, 963 int num_joined_pipes) 964 { 965 struct intel_dsc_slice_config config; 966 967 if (!intel_dp_dsc_get_slice_config(connector, 968 mode_clock, mode_hdisplay, 969 num_joined_pipes, &config)) 970 return 0; 971 972 return intel_dsc_line_slice_count(&config); 973 } 974 975 static bool source_can_output(struct intel_dp *intel_dp, 976 enum intel_output_format format) 977 { 978 struct intel_display *display = to_intel_display(intel_dp); 979 980 switch (format) { 981 case INTEL_OUTPUT_FORMAT_RGB: 982 return true; 983 984 case INTEL_OUTPUT_FORMAT_YCBCR444: 985 /* 986 * No YCbCr output support on gmch platforms. 987 * Also, ILK doesn't seem capable of DP YCbCr output. 988 * The displayed image is severely corrupted. SNB+ is fine. 989 */ 990 return !HAS_GMCH(display) && !display->platform.ironlake; 991 992 case INTEL_OUTPUT_FORMAT_YCBCR420: 993 /* Platform < Gen 11 cannot output YCbCr420 format */ 994 return DISPLAY_VER(display) >= 11; 995 996 default: 997 MISSING_CASE(format); 998 return false; 999 } 1000 } 1001 1002 static bool 1003 dfp_can_convert_from_rgb(struct intel_dp *intel_dp, 1004 enum intel_output_format sink_format) 1005 { 1006 if (!drm_dp_is_branch(intel_dp->dpcd)) 1007 return false; 1008 1009 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR444) 1010 return intel_dp->dfp.rgb_to_ycbcr; 1011 1012 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1013 return intel_dp->dfp.rgb_to_ycbcr && 1014 intel_dp->dfp.ycbcr_444_to_420; 1015 1016 return false; 1017 } 1018 1019 static bool 1020 dfp_can_convert_from_ycbcr444(struct intel_dp *intel_dp, 1021 enum intel_output_format sink_format) 1022 { 1023 if (!drm_dp_is_branch(intel_dp->dpcd)) 1024 return false; 1025 1026 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1027 return intel_dp->dfp.ycbcr_444_to_420; 1028 1029 return false; 1030 } 1031 1032 static bool 1033 dfp_can_convert(struct intel_dp *intel_dp, 1034 enum intel_output_format output_format, 1035 enum intel_output_format sink_format) 1036 { 1037 switch (output_format) { 1038 case INTEL_OUTPUT_FORMAT_RGB: 1039 return dfp_can_convert_from_rgb(intel_dp, sink_format); 1040 case INTEL_OUTPUT_FORMAT_YCBCR444: 1041 return dfp_can_convert_from_ycbcr444(intel_dp, sink_format); 1042 default: 1043 MISSING_CASE(output_format); 1044 return false; 1045 } 1046 1047 return false; 1048 } 1049 1050 static enum intel_output_format 1051 intel_dp_output_format(struct intel_connector *connector, 1052 enum intel_output_format sink_format) 1053 { 1054 struct intel_display *display = to_intel_display(connector); 1055 struct intel_dp *intel_dp = intel_attached_dp(connector); 1056 enum intel_output_format force_dsc_output_format = 1057 intel_dp->force_dsc_output_format; 1058 enum intel_output_format output_format; 1059 if (force_dsc_output_format) { 1060 if (source_can_output(intel_dp, force_dsc_output_format) && 1061 (!drm_dp_is_branch(intel_dp->dpcd) || 1062 sink_format != force_dsc_output_format || 1063 dfp_can_convert(intel_dp, force_dsc_output_format, sink_format))) 1064 return force_dsc_output_format; 1065 1066 drm_dbg_kms(display->drm, "Cannot force DSC output format\n"); 1067 } 1068 1069 if (sink_format == INTEL_OUTPUT_FORMAT_RGB || 1070 dfp_can_convert_from_rgb(intel_dp, sink_format)) 1071 output_format = INTEL_OUTPUT_FORMAT_RGB; 1072 1073 else if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR444 || 1074 dfp_can_convert_from_ycbcr444(intel_dp, sink_format)) 1075 output_format = INTEL_OUTPUT_FORMAT_YCBCR444; 1076 1077 else 1078 output_format = INTEL_OUTPUT_FORMAT_YCBCR420; 1079 1080 drm_WARN_ON(display->drm, !source_can_output(intel_dp, output_format)); 1081 1082 return output_format; 1083 } 1084 1085 int intel_dp_min_bpp(enum intel_output_format output_format) 1086 { 1087 if (output_format == INTEL_OUTPUT_FORMAT_RGB) 1088 return intel_display_min_pipe_bpp(); 1089 else 1090 return 8 * 3; 1091 } 1092 1093 int intel_dp_output_format_link_bpp_x16(enum intel_output_format output_format, int pipe_bpp) 1094 { 1095 /* 1096 * bpp value was assumed to RGB format. And YCbCr 4:2:0 output 1097 * format of the number of bytes per pixel will be half the number 1098 * of bytes of RGB pixel. 1099 */ 1100 if (output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1101 pipe_bpp /= 2; 1102 1103 return fxp_q4_from_int(pipe_bpp); 1104 } 1105 1106 static int 1107 intel_dp_mode_min_link_bpp_x16(struct intel_connector *connector, 1108 const struct drm_display_mode *mode, 1109 enum intel_output_format output_format) 1110 { 1111 return intel_dp_output_format_link_bpp_x16(output_format, 1112 intel_dp_min_bpp(output_format)); 1113 } 1114 1115 static bool intel_dp_hdisplay_bad(struct intel_display *display, 1116 int hdisplay) 1117 { 1118 /* 1119 * Older platforms don't like hdisplay==4096 with DP. 1120 * 1121 * On ILK/SNB/IVB the pipe seems to be somewhat running (scanline 1122 * and frame counter increment), but we don't get vblank interrupts, 1123 * and the pipe underruns immediately. The link also doesn't seem 1124 * to get trained properly. 1125 * 1126 * On CHV the vblank interrupts don't seem to disappear but 1127 * otherwise the symptoms are similar. 1128 * 1129 * TODO: confirm the behaviour on HSW+ 1130 */ 1131 return hdisplay == 4096 && !HAS_DDI(display); 1132 } 1133 1134 static int intel_dp_max_tmds_clock(struct intel_dp *intel_dp) 1135 { 1136 struct intel_connector *connector = intel_dp->attached_connector; 1137 const struct drm_display_info *info = &connector->base.display_info; 1138 int max_tmds_clock = intel_dp->dfp.max_tmds_clock; 1139 1140 /* Only consider the sink's max TMDS clock if we know this is a HDMI DFP */ 1141 if (max_tmds_clock && info->max_tmds_clock) 1142 max_tmds_clock = min(max_tmds_clock, info->max_tmds_clock); 1143 1144 return max_tmds_clock; 1145 } 1146 1147 static enum drm_mode_status 1148 intel_dp_tmds_clock_valid(struct intel_dp *intel_dp, 1149 int clock, int bpc, 1150 enum intel_output_format sink_format, 1151 bool respect_downstream_limits) 1152 { 1153 int tmds_clock, min_tmds_clock, max_tmds_clock; 1154 1155 if (!respect_downstream_limits) 1156 return MODE_OK; 1157 1158 tmds_clock = intel_hdmi_tmds_clock(clock, bpc, sink_format); 1159 1160 min_tmds_clock = intel_dp->dfp.min_tmds_clock; 1161 max_tmds_clock = intel_dp_max_tmds_clock(intel_dp); 1162 1163 if (min_tmds_clock && tmds_clock < min_tmds_clock) 1164 return MODE_CLOCK_LOW; 1165 1166 if (max_tmds_clock && tmds_clock > max_tmds_clock) 1167 return MODE_CLOCK_HIGH; 1168 1169 return MODE_OK; 1170 } 1171 1172 static int frl_required_bw(int clock, int bpc, 1173 enum intel_output_format sink_format) 1174 { 1175 if (sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) 1176 clock /= 2; 1177 1178 return clock * bpc * 3; 1179 } 1180 1181 static enum drm_mode_status 1182 intel_dp_mode_valid_downstream(struct intel_connector *connector, 1183 const struct drm_display_mode *mode, 1184 int target_clock, 1185 enum intel_output_format sink_format) 1186 { 1187 struct intel_dp *intel_dp = intel_attached_dp(connector); 1188 1189 /* If PCON supports FRL MODE, check FRL bandwidth constraints */ 1190 if (intel_dp->dfp.pcon_max_frl_bw) { 1191 int target_bw, max_frl_bw; 1192 1193 /* Assume 8bpc for the FRL bandwidth check */ 1194 target_bw = frl_required_bw(target_clock, 8, sink_format); 1195 1196 max_frl_bw = intel_dp->dfp.pcon_max_frl_bw; 1197 1198 /* converting bw from Gbps to Kbps*/ 1199 max_frl_bw = max_frl_bw * 1000000; 1200 1201 if (target_bw > max_frl_bw) 1202 return MODE_CLOCK_HIGH; 1203 1204 return MODE_OK; 1205 } 1206 1207 if (intel_dp->dfp.max_dotclock && 1208 target_clock > intel_dp->dfp.max_dotclock) 1209 return MODE_CLOCK_HIGH; 1210 1211 /* Assume 8bpc for the DP++/HDMI/DVI TMDS clock check */ 1212 return intel_dp_tmds_clock_valid(intel_dp, target_clock, 1213 8, sink_format, true); 1214 } 1215 1216 static enum drm_mode_status 1217 intel_dp_sink_format_valid(struct intel_connector *connector, 1218 const struct drm_display_mode *mode, 1219 enum intel_output_format sink_format) 1220 { 1221 struct intel_dp *intel_dp = intel_attached_dp(connector); 1222 const struct drm_display_info *info = &connector->base.display_info; 1223 1224 switch (sink_format) { 1225 case INTEL_OUTPUT_FORMAT_YCBCR420: 1226 if (intel_dp->dfp.min_tmds_clock && 1227 !intel_dp_has_hdmi_sink(intel_dp)) 1228 return MODE_NO_420; 1229 1230 if (!connector->base.ycbcr_420_allowed || 1231 !drm_mode_is_420(info, mode)) 1232 return MODE_NO_420; 1233 1234 return MODE_OK; 1235 case INTEL_OUTPUT_FORMAT_RGB: 1236 return MODE_OK; 1237 default: 1238 MISSING_CASE(sink_format); 1239 return MODE_BAD; 1240 } 1241 } 1242 1243 int intel_dp_max_hdisplay_per_pipe(struct intel_display *display) 1244 { 1245 return DISPLAY_VER(display) >= 30 ? 6144 : 5120; 1246 } 1247 1248 bool intel_dp_has_dsc(const struct intel_connector *connector) 1249 { 1250 struct intel_display *display = to_intel_display(connector); 1251 1252 if (!HAS_DSC(display)) 1253 return false; 1254 1255 if (connector->mst.dp && !HAS_DSC_MST(display)) 1256 return false; 1257 1258 if (connector->base.connector_type == DRM_MODE_CONNECTOR_eDP && 1259 connector->panel.vbt.edp.dsc_disable) 1260 return false; 1261 1262 if (!drm_dp_sink_supports_dsc(connector->dp.dsc_dpcd)) 1263 return false; 1264 1265 return true; 1266 } 1267 1268 static 1269 bool intel_dp_can_join(struct intel_dp *intel_dp, 1270 int num_joined_pipes) 1271 { 1272 struct intel_display *display = to_intel_display(intel_dp); 1273 1274 if (num_joined_pipes > 1 && !intel_dp_has_joiner(intel_dp)) 1275 return false; 1276 1277 switch (num_joined_pipes) { 1278 case 1: 1279 return true; 1280 case 2: 1281 return HAS_BIGJOINER(display) || 1282 HAS_UNCOMPRESSED_JOINER(display); 1283 case 4: 1284 return HAS_ULTRAJOINER(display); 1285 default: 1286 return false; 1287 } 1288 } 1289 1290 bool intel_dp_dotclk_valid(struct intel_display *display, 1291 int target_clock, 1292 int htotal, 1293 int dsc_slice_count, 1294 int num_joined_pipes) 1295 { 1296 int max_dotclk = display->cdclk.max_dotclk_freq; 1297 int effective_dotclk_limit; 1298 1299 effective_dotclk_limit = max_dotclk * num_joined_pipes; 1300 1301 if (dsc_slice_count) 1302 target_clock = intel_dsc_get_pixel_rate_with_dsc_bubbles(display, 1303 target_clock, 1304 htotal, 1305 dsc_slice_count); 1306 else 1307 effective_dotclk_limit = 1308 intel_max_uncompressed_dotclock(display) * num_joined_pipes; 1309 1310 return target_clock <= effective_dotclk_limit; 1311 } 1312 1313 static enum drm_mode_status 1314 intel_dp_mode_valid_format(struct intel_connector *connector, 1315 const struct drm_display_mode *mode, 1316 int target_clock, 1317 enum intel_output_format sink_format) 1318 { 1319 struct intel_display *display = to_intel_display(connector); 1320 struct intel_dp *intel_dp = intel_attached_dp(connector); 1321 enum intel_output_format output_format; 1322 int max_rate, mode_rate, max_lanes, max_link_clock; 1323 struct intel_dp_link_config max_bw_config; 1324 u16 dsc_max_compressed_bpp = 0; 1325 enum drm_mode_status status; 1326 bool dsc = false; 1327 int num_joined_pipes; 1328 int link_bpp_x16; 1329 1330 status = intel_dp_sink_format_valid(connector, mode, sink_format); 1331 if (status != MODE_OK) 1332 return status; 1333 1334 output_format = intel_dp_output_format(connector, sink_format); 1335 1336 intel_dp_link_caps_get_max_bw_config(intel_dp->link.caps, &max_bw_config); 1337 max_link_clock = max_bw_config.rate; 1338 max_lanes = max_bw_config.lane_count; 1339 1340 max_rate = intel_dp_max_link_data_rate(intel_dp, max_link_clock, max_lanes); 1341 1342 link_bpp_x16 = intel_dp_mode_min_link_bpp_x16(connector, mode, 1343 output_format); 1344 mode_rate = intel_dp_link_required(max_link_clock, max_lanes, 1345 target_clock, mode->hdisplay, 1346 link_bpp_x16, 0); 1347 1348 /* 1349 * We cannot determine the required pipe‑join count before knowing whether 1350 * DSC is needed, nor can we determine DSC need without knowing the pipe 1351 * count. 1352 * Because of this dependency cycle, the only correct approach is to iterate 1353 * over candidate pipe counts and evaluate each combination. 1354 */ 1355 status = MODE_CLOCK_HIGH; 1356 for_each_joiner_candidate(connector, mode, num_joined_pipes) { 1357 int dsc_slice_count = 0; 1358 1359 status = intel_pfit_mode_valid(display, mode, output_format, num_joined_pipes); 1360 if (status != MODE_OK) 1361 continue; 1362 1363 if (intel_dp_has_dsc(connector)) { 1364 int pipe_bpp; 1365 1366 dsc_slice_count = intel_dp_dsc_get_slice_count(connector, 1367 target_clock, 1368 mode->hdisplay, 1369 num_joined_pipes); 1370 1371 /* 1372 * TBD pass the connector BPC, 1373 * for now U8_MAX so that max BPC on that platform would be picked 1374 */ 1375 pipe_bpp = intel_dp_dsc_compute_max_bpp(connector, U8_MAX); 1376 1377 /* 1378 * Output bpp is stored in 6.4 format so right shift by 4 to get the 1379 * integer value since we support only integer values of bpp. 1380 */ 1381 if (intel_dp_is_edp(intel_dp)) { 1382 dsc_max_compressed_bpp = 1383 drm_edp_dsc_sink_output_bpp(connector->dp.dsc_dpcd) >> 4; 1384 1385 dsc = dsc_max_compressed_bpp && dsc_slice_count; 1386 } else if (drm_dp_sink_supports_fec(connector->dp.fec_capability)) { 1387 unsigned long bw_overhead_flags = 0; 1388 1389 if (!drm_dp_is_uhbr_rate(max_link_clock)) 1390 bw_overhead_flags |= DRM_DP_BW_OVERHEAD_FEC; 1391 1392 dsc = intel_dp_mode_valid_with_dsc(connector, 1393 max_link_clock, max_lanes, 1394 target_clock, mode->hdisplay, 1395 num_joined_pipes, 1396 output_format, pipe_bpp, 1397 bw_overhead_flags); 1398 } 1399 } 1400 1401 if (intel_dp_joiner_needs_dsc(display, num_joined_pipes) && !dsc) { 1402 status = MODE_CLOCK_HIGH; 1403 continue; 1404 } 1405 1406 if (mode_rate > max_rate && !dsc) { 1407 status = MODE_CLOCK_HIGH; 1408 continue; 1409 } 1410 1411 status = intel_mode_valid_max_plane_size(display, mode, num_joined_pipes); 1412 if (status != MODE_OK) 1413 continue; 1414 1415 if (!dsc) 1416 dsc_slice_count = 0; 1417 1418 if (!intel_dp_dotclk_valid(display, 1419 target_clock, 1420 mode->htotal, 1421 dsc_slice_count, 1422 num_joined_pipes)) { 1423 status = MODE_CLOCK_HIGH; 1424 continue; 1425 } 1426 1427 break; 1428 } 1429 1430 if (status != MODE_OK) 1431 return status; 1432 1433 return intel_dp_mode_valid_downstream(connector, mode, 1434 target_clock, sink_format); 1435 } 1436 1437 static enum drm_mode_status 1438 intel_dp_mode_valid(struct drm_connector *_connector, 1439 const struct drm_display_mode *mode) 1440 { 1441 struct intel_display *display = to_intel_display(_connector->dev); 1442 struct intel_connector *connector = to_intel_connector(_connector); 1443 const struct drm_display_info *info = &connector->base.display_info; 1444 struct intel_dp *intel_dp = intel_attached_dp(connector); 1445 int target_clock = mode->clock; 1446 enum drm_mode_status status; 1447 1448 status = intel_cpu_transcoder_mode_valid(display, mode); 1449 if (status != MODE_OK) 1450 return status; 1451 1452 if (mode->flags & DRM_MODE_FLAG_DBLCLK) 1453 return MODE_H_ILLEGAL; 1454 1455 if (mode->clock < 10000) 1456 return MODE_CLOCK_LOW; 1457 1458 if (intel_dp_hdisplay_bad(display, mode->hdisplay)) 1459 return MODE_H_ILLEGAL; 1460 1461 if (intel_dp_is_edp(intel_dp)) { 1462 status = intel_panel_mode_valid(connector, mode, &target_clock); 1463 if (status != MODE_OK) 1464 return status; 1465 } 1466 1467 /* 1468 * TODO: Even when using a 4:2:0 sink_format intel_dp_output_format() 1469 * will always choose a 4:4:4 output_format if the DFP can do the 1470 * 4:4:4->4:2:0 conversion for us. Thus a mode may still be rejected 1471 * if we only have enough DP link bandwidth for 4:2:0 but not for 1472 * 4:4:4. Another attempt with an explicit 4:2:0 output_format might 1473 * be needed here. intel_dp_compute_config() would need the same 1474 * logic, or else the actual modeset would still fail. 1475 * 1476 * Also a lot of the checks only depend on output_format but not 1477 * sink_format, so we are potentially doing redundant work by 1478 * testing the same output_format for two different sink_formats. 1479 */ 1480 if (drm_mode_is_420_only(info, mode)) { 1481 status = intel_dp_mode_valid_format(connector, mode, target_clock, 1482 INTEL_OUTPUT_FORMAT_YCBCR420); 1483 } else { 1484 status = intel_dp_mode_valid_format(connector, mode, target_clock, 1485 INTEL_OUTPUT_FORMAT_RGB); 1486 1487 if (status != MODE_OK && drm_mode_is_420_also(info, mode)) 1488 status = intel_dp_mode_valid_format(connector, mode, target_clock, 1489 INTEL_OUTPUT_FORMAT_YCBCR420); 1490 } 1491 1492 return status; 1493 } 1494 1495 bool intel_dp_source_supports_tps3(struct intel_display *display) 1496 { 1497 return DISPLAY_VER(display) >= 9 || 1498 display->platform.broadwell || display->platform.haswell; 1499 } 1500 1501 bool intel_dp_source_supports_tps4(struct intel_display *display) 1502 { 1503 return DISPLAY_VER(display) >= 10; 1504 } 1505 1506 static void seq_buf_print_array(struct seq_buf *s, const int *array, int nelem) 1507 { 1508 int i; 1509 1510 for (i = 0; i < nelem; i++) 1511 seq_buf_printf(s, "%s%d", i ? ", " : "", array[i]); 1512 } 1513 1514 static void intel_dp_print_rates(struct intel_dp *intel_dp) 1515 { 1516 struct intel_display *display = to_intel_display(intel_dp); 1517 DECLARE_SEQ_BUF(s, 128); /* FIXME: too big for stack? */ 1518 1519 if (!drm_debug_enabled(DRM_UT_KMS)) 1520 return; 1521 1522 seq_buf_print_array(&s, intel_dp->source_rates, intel_dp->num_source_rates); 1523 drm_dbg_kms(display->drm, "source rates: %s\n", seq_buf_str(&s)); 1524 1525 seq_buf_clear(&s); 1526 seq_buf_print_array(&s, intel_dp->sink_rates, intel_dp->num_sink_rates); 1527 drm_dbg_kms(display->drm, "sink rates: %s\n", seq_buf_str(&s)); 1528 1529 intel_dp_link_caps_print_common_rates(intel_dp->link.caps); 1530 } 1531 1532 int intel_dp_rate_select(struct intel_dp *intel_dp, int rate) 1533 { 1534 struct intel_display *display = to_intel_display(intel_dp); 1535 int i = intel_dp_rate_index(intel_dp->sink_rates, 1536 intel_dp->num_sink_rates, rate); 1537 1538 if (drm_WARN_ON(display->drm, i < 0)) 1539 i = 0; 1540 1541 return i; 1542 } 1543 1544 void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock, 1545 u8 *link_bw, u8 *rate_select) 1546 { 1547 struct intel_display *display = to_intel_display(intel_dp); 1548 1549 /* FIXME g4x can't generate an exact 2.7GHz with the 96MHz non-SSC refclk */ 1550 if (display->platform.g4x && port_clock == 268800) 1551 port_clock = 270000; 1552 1553 /* eDP 1.4 rate select method. */ 1554 if (intel_dp->use_rate_select) { 1555 *link_bw = 0; 1556 *rate_select = 1557 intel_dp_rate_select(intel_dp, port_clock); 1558 } else { 1559 *link_bw = drm_dp_link_rate_to_bw_code(port_clock); 1560 *rate_select = 0; 1561 } 1562 } 1563 1564 bool intel_dp_has_hdmi_sink(struct intel_dp *intel_dp) 1565 { 1566 struct intel_connector *connector = intel_dp->attached_connector; 1567 1568 return connector->base.display_info.is_hdmi; 1569 } 1570 1571 static bool intel_dp_source_supports_fec(struct intel_dp *intel_dp, 1572 const struct intel_crtc_state *pipe_config) 1573 { 1574 struct intel_display *display = to_intel_display(intel_dp); 1575 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 1576 1577 if (DISPLAY_VER(display) >= 12) 1578 return true; 1579 1580 if (DISPLAY_VER(display) == 11 && encoder->port != PORT_A && 1581 !intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) 1582 return true; 1583 1584 return false; 1585 } 1586 1587 bool intel_dp_supports_fec(struct intel_dp *intel_dp, 1588 const struct intel_connector *connector, 1589 const struct intel_crtc_state *pipe_config) 1590 { 1591 return intel_dp_source_supports_fec(intel_dp, pipe_config) && 1592 drm_dp_sink_supports_fec(connector->dp.fec_capability); 1593 } 1594 1595 bool intel_dp_supports_dsc(struct intel_dp *intel_dp, 1596 const struct intel_connector *connector, 1597 const struct intel_crtc_state *crtc_state) 1598 { 1599 if (!intel_dp_has_dsc(connector)) 1600 return false; 1601 1602 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP) && 1603 !intel_dp_supports_fec(intel_dp, connector, crtc_state)) 1604 return false; 1605 1606 return intel_dsc_source_support(crtc_state); 1607 } 1608 1609 static int intel_dp_hdmi_compute_bpc(struct intel_dp *intel_dp, 1610 const struct intel_crtc_state *crtc_state, 1611 int bpc, bool respect_downstream_limits) 1612 { 1613 int clock = crtc_state->hw.adjusted_mode.crtc_clock; 1614 1615 /* 1616 * Current bpc could already be below 8bpc due to 1617 * FDI bandwidth constraints or other limits. 1618 * HDMI minimum is 8bpc however. 1619 */ 1620 bpc = max(bpc, 8); 1621 1622 /* 1623 * We will never exceed downstream TMDS clock limits while 1624 * attempting deep color. If the user insists on forcing an 1625 * out of spec mode they will have to be satisfied with 8bpc. 1626 */ 1627 if (!respect_downstream_limits) 1628 bpc = 8; 1629 1630 for (; bpc >= 8; bpc -= 2) { 1631 if (intel_hdmi_bpc_possible(crtc_state, bpc, 1632 intel_dp_has_hdmi_sink(intel_dp)) && 1633 intel_dp_tmds_clock_valid(intel_dp, clock, bpc, crtc_state->sink_format, 1634 respect_downstream_limits) == MODE_OK) 1635 return bpc; 1636 } 1637 1638 return -EINVAL; 1639 } 1640 1641 static int intel_dp_max_bpp(struct intel_dp *intel_dp, 1642 const struct intel_crtc_state *crtc_state, 1643 bool respect_downstream_limits) 1644 { 1645 struct intel_display *display = to_intel_display(intel_dp); 1646 struct intel_connector *connector = intel_dp->attached_connector; 1647 int bpp, bpc; 1648 1649 bpc = crtc_state->max_pipe_bpp / 3; 1650 1651 if (intel_dp->dfp.max_bpc) 1652 bpc = min_t(int, bpc, intel_dp->dfp.max_bpc); 1653 1654 if (intel_dp->dfp.min_tmds_clock) { 1655 int max_hdmi_bpc; 1656 1657 max_hdmi_bpc = intel_dp_hdmi_compute_bpc(intel_dp, crtc_state, bpc, 1658 respect_downstream_limits); 1659 if (max_hdmi_bpc < 0) 1660 return 0; 1661 1662 bpc = min(bpc, max_hdmi_bpc); 1663 } 1664 1665 bpp = bpc * 3; 1666 if (intel_dp_is_edp(intel_dp)) { 1667 /* Get bpp from vbt only for panels that dont have bpp in edid */ 1668 if (connector->base.display_info.bpc == 0 && 1669 connector->panel.vbt.edp.bpp && 1670 connector->panel.vbt.edp.bpp < bpp) { 1671 drm_dbg_kms(display->drm, 1672 "clamping bpp for eDP panel to BIOS-provided %i\n", 1673 connector->panel.vbt.edp.bpp); 1674 bpp = connector->panel.vbt.edp.bpp; 1675 } 1676 } 1677 1678 return bpp; 1679 } 1680 1681 static bool has_seamless_m_n(struct intel_connector *connector) 1682 { 1683 struct intel_display *display = to_intel_display(connector); 1684 1685 /* 1686 * Seamless M/N reprogramming only implemented 1687 * for BDW+ double buffered M/N registers so far. 1688 */ 1689 return HAS_DOUBLE_BUFFERED_M_N(display) && 1690 intel_panel_drrs_type(connector) == DRRS_TYPE_SEAMLESS; 1691 } 1692 1693 static int intel_dp_mode_clock(const struct intel_crtc_state *crtc_state, 1694 const struct drm_connector_state *conn_state) 1695 { 1696 struct intel_connector *connector = to_intel_connector(conn_state->connector); 1697 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 1698 1699 /* FIXME a bit of a mess wrt clock vs. crtc_clock */ 1700 if (has_seamless_m_n(connector)) 1701 return intel_panel_highest_mode(connector, adjusted_mode)->clock; 1702 else 1703 return adjusted_mode->crtc_clock; 1704 } 1705 1706 /* Optimize link config in order: max bpp, min clock, min lanes */ 1707 static int 1708 intel_dp_compute_link_config_wide(struct intel_dp *intel_dp, 1709 struct intel_crtc_state *pipe_config, 1710 const struct drm_connector_state *conn_state, 1711 const struct link_config_limits *limits) 1712 { 1713 struct intel_connector *connector = to_intel_connector(conn_state->connector); 1714 int bpp, clock = intel_dp_mode_clock(pipe_config, conn_state); 1715 struct intel_dp_link_caps *link_caps = intel_dp->link.caps; 1716 struct intel_dp_link_caps_order order = 1717 intel_dp_link_caps_connector_compute_order(connector); 1718 int err = -EINVAL; 1719 int link_avail; 1720 1721 for (bpp = fxp_q4_to_int(limits->link.max_bpp_x16); 1722 bpp >= fxp_q4_to_int(limits->link.min_bpp_x16); 1723 bpp -= 2 * 3) { 1724 int link_bpp_x16 = 1725 intel_dp_output_format_link_bpp_x16(pipe_config->output_format, bpp); 1726 struct intel_dp_link_config link_config; 1727 struct intel_dp_link_caps_iter iter; 1728 1729 intel_dp_link_caps_iter_start(&iter, link_caps, order, limits->link_config_filter); 1730 for_each_dp_link_config(&iter, &link_config) { 1731 const struct drm_display_mode *adjusted_mode = 1732 &pipe_config->hw.adjusted_mode; 1733 int mode_rate; 1734 1735 mode_rate = intel_dp_link_required(link_config.rate, 1736 link_config.lane_count, 1737 clock, adjusted_mode->hdisplay, 1738 link_bpp_x16, 0); 1739 1740 link_avail = intel_dp_max_link_data_rate(intel_dp, 1741 link_config.rate, 1742 link_config.lane_count); 1743 1744 if (mode_rate <= link_avail) { 1745 pipe_config->lane_count = link_config.lane_count; 1746 pipe_config->pipe_bpp = bpp; 1747 pipe_config->port_clock = link_config.rate; 1748 1749 err = 0; 1750 1751 break; 1752 } 1753 } 1754 intel_dp_link_caps_iter_end(&iter); 1755 1756 if (!err) 1757 break; 1758 } 1759 1760 return err; 1761 } 1762 1763 int intel_dp_dsc_max_src_input_bpc(struct intel_display *display) 1764 { 1765 /* Max DSC Input BPC for ICL is 10 and for TGL+ is 12 */ 1766 if (DISPLAY_VER(display) >= 12) 1767 return 12; 1768 if (DISPLAY_VER(display) == 11) 1769 return 10; 1770 1771 return intel_dp_dsc_min_src_input_bpc(); 1772 } 1773 1774 static int align_min_sink_dsc_input_bpp(const struct intel_connector *connector, 1775 int min_pipe_bpp) 1776 { 1777 u8 dsc_bpc[3]; 1778 int num_bpc; 1779 int i; 1780 1781 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(connector->dp.dsc_dpcd, 1782 dsc_bpc); 1783 for (i = num_bpc - 1; i >= 0; i--) { 1784 if (dsc_bpc[i] * 3 >= min_pipe_bpp) 1785 return dsc_bpc[i] * 3; 1786 } 1787 1788 return 0; 1789 } 1790 1791 static int align_max_sink_dsc_input_bpp(const struct intel_connector *connector, 1792 int max_pipe_bpp) 1793 { 1794 u8 dsc_bpc[3]; 1795 int num_bpc; 1796 int i; 1797 1798 num_bpc = drm_dp_dsc_sink_supported_input_bpcs(connector->dp.dsc_dpcd, 1799 dsc_bpc); 1800 for (i = 0; i < num_bpc; i++) { 1801 if (dsc_bpc[i] * 3 <= max_pipe_bpp) 1802 return dsc_bpc[i] * 3; 1803 } 1804 1805 return 0; 1806 } 1807 1808 int intel_dp_dsc_compute_max_bpp(const struct intel_connector *connector, 1809 u8 max_req_bpc) 1810 { 1811 struct intel_display *display = to_intel_display(connector); 1812 int dsc_max_bpc; 1813 1814 dsc_max_bpc = intel_dp_dsc_max_src_input_bpc(display); 1815 1816 if (!dsc_max_bpc) 1817 return dsc_max_bpc; 1818 1819 dsc_max_bpc = min(dsc_max_bpc, max_req_bpc); 1820 1821 return align_max_sink_dsc_input_bpp(connector, dsc_max_bpc * 3); 1822 } 1823 1824 static int intel_dp_source_dsc_version_minor(struct intel_display *display) 1825 { 1826 return DISPLAY_VER(display) >= 14 ? 2 : 1; 1827 } 1828 1829 static int intel_dp_sink_dsc_version_minor(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]) 1830 { 1831 return (dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] & DP_DSC_MINOR_MASK) >> 1832 DP_DSC_MINOR_SHIFT; 1833 } 1834 1835 static int intel_dp_get_slice_height(int vactive) 1836 { 1837 int slice_height; 1838 1839 /* 1840 * VDSC 1.2a spec in Section 3.8 Options for Slices implies that 108 1841 * lines is an optimal slice height, but any size can be used as long as 1842 * vertical active integer multiple and maximum vertical slice count 1843 * requirements are met. 1844 */ 1845 for (slice_height = 108; slice_height <= vactive; slice_height += 2) 1846 if (vactive % slice_height == 0) 1847 return slice_height; 1848 1849 /* 1850 * Highly unlikely we reach here as most of the resolutions will end up 1851 * finding appropriate slice_height in above loop but returning 1852 * slice_height as 2 here as it should work with all resolutions. 1853 */ 1854 return 2; 1855 } 1856 1857 static int intel_dp_dsc_compute_params(const struct intel_connector *connector, 1858 struct intel_crtc_state *crtc_state) 1859 { 1860 struct intel_display *display = to_intel_display(connector); 1861 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 1862 int ret; 1863 1864 /* 1865 * RC_MODEL_SIZE is currently a constant across all configurations. 1866 * 1867 * FIXME: Look into using sink defined DPCD DP_DSC_RC_BUF_BLK_SIZE and 1868 * DP_DSC_RC_BUF_SIZE for this. 1869 */ 1870 vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST; 1871 vdsc_cfg->pic_height = crtc_state->hw.adjusted_mode.crtc_vdisplay; 1872 1873 vdsc_cfg->slice_height = intel_dp_get_slice_height(vdsc_cfg->pic_height); 1874 1875 ret = intel_dsc_compute_params(crtc_state); 1876 if (ret) 1877 return ret; 1878 1879 vdsc_cfg->dsc_version_major = 1880 (connector->dp.dsc_dpcd[DP_DSC_REV - DP_DSC_SUPPORT] & 1881 DP_DSC_MAJOR_MASK) >> DP_DSC_MAJOR_SHIFT; 1882 vdsc_cfg->dsc_version_minor = 1883 min(intel_dp_source_dsc_version_minor(display), 1884 intel_dp_sink_dsc_version_minor(connector->dp.dsc_dpcd)); 1885 if (vdsc_cfg->convert_rgb) 1886 vdsc_cfg->convert_rgb = 1887 connector->dp.dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & 1888 DP_DSC_RGB; 1889 1890 vdsc_cfg->line_buf_depth = min(INTEL_DP_DSC_MAX_LINE_BUF_DEPTH, 1891 drm_dp_dsc_sink_line_buf_depth(connector->dp.dsc_dpcd)); 1892 if (!vdsc_cfg->line_buf_depth) { 1893 drm_dbg_kms(display->drm, 1894 "DSC Sink Line Buffer Depth invalid\n"); 1895 return -EINVAL; 1896 } 1897 1898 vdsc_cfg->block_pred_enable = 1899 connector->dp.dsc_dpcd[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] & 1900 DP_DSC_BLK_PREDICTION_IS_SUPPORTED; 1901 1902 return drm_dsc_compute_rc_parameters(vdsc_cfg); 1903 } 1904 1905 static bool intel_dp_dsc_supports_format(const struct intel_connector *connector, 1906 enum intel_output_format output_format) 1907 { 1908 struct intel_display *display = to_intel_display(connector); 1909 u8 sink_dsc_format; 1910 1911 switch (output_format) { 1912 case INTEL_OUTPUT_FORMAT_RGB: 1913 sink_dsc_format = DP_DSC_RGB; 1914 break; 1915 case INTEL_OUTPUT_FORMAT_YCBCR444: 1916 sink_dsc_format = DP_DSC_YCbCr444; 1917 break; 1918 case INTEL_OUTPUT_FORMAT_YCBCR420: 1919 if (min(intel_dp_source_dsc_version_minor(display), 1920 intel_dp_sink_dsc_version_minor(connector->dp.dsc_dpcd)) < 2) 1921 return false; 1922 sink_dsc_format = DP_DSC_YCbCr420_Native; 1923 break; 1924 default: 1925 return false; 1926 } 1927 1928 return drm_dp_dsc_sink_supports_format(connector->dp.dsc_dpcd, sink_dsc_format); 1929 } 1930 1931 static bool is_bw_sufficient_for_dsc_config(struct intel_dp *intel_dp, 1932 int link_clock, int lane_count, 1933 int mode_clock, int mode_hdisplay, 1934 int dsc_slice_count, int link_bpp_x16, 1935 unsigned long bw_overhead_flags) 1936 { 1937 int available_bw; 1938 int required_bw; 1939 1940 available_bw = intel_dp_max_link_data_rate(intel_dp, link_clock, lane_count); 1941 required_bw = intel_dp_link_required(link_clock, lane_count, 1942 mode_clock, mode_hdisplay, 1943 link_bpp_x16, bw_overhead_flags); 1944 1945 return available_bw >= required_bw; 1946 } 1947 1948 static int dsc_compute_link_config(struct intel_dp *intel_dp, 1949 struct intel_crtc_state *pipe_config, 1950 struct drm_connector_state *conn_state, 1951 const struct link_config_limits *limits, 1952 int dsc_bpp_x16) 1953 { 1954 const struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 1955 struct intel_connector *connector = to_intel_connector(conn_state->connector); 1956 struct intel_dp_link_caps *link_caps = intel_dp->link.caps; 1957 struct intel_dp_link_caps_order order = 1958 intel_dp_link_caps_connector_compute_order(connector); 1959 struct intel_dp_link_config link_config; 1960 struct intel_dp_link_caps_iter iter; 1961 int err = -EINVAL; 1962 1963 intel_dp_link_caps_iter_start(&iter, link_caps, order, limits->link_config_filter); 1964 for_each_dp_link_config(&iter, &link_config) { 1965 /* 1966 * FIXME: intel_dp_mtp_tu_compute_config() requires 1967 * ->lane_count and ->port_clock set before we know 1968 * they'll work. If we end up failing altogether, 1969 * they'll remain in crtc state. This shouldn't matter, 1970 * as we'd then bail out from compute config, but it's 1971 * just ugly. 1972 */ 1973 pipe_config->lane_count = link_config.lane_count; 1974 pipe_config->port_clock = link_config.rate; 1975 1976 if (drm_dp_is_uhbr_rate(link_config.rate)) { 1977 int ret; 1978 1979 ret = intel_dp_mtp_tu_compute_config(intel_dp, 1980 pipe_config, 1981 conn_state, 1982 dsc_bpp_x16, 1983 dsc_bpp_x16, 1984 0, true); 1985 if (ret) 1986 continue; 1987 } else { 1988 unsigned long bw_overhead_flags = 1989 pipe_config->fec_enable ? DRM_DP_BW_OVERHEAD_FEC : 0; 1990 int line_slice_count = 1991 intel_dsc_line_slice_count(&pipe_config->dsc.slice_config); 1992 1993 if (!is_bw_sufficient_for_dsc_config(intel_dp, 1994 link_config.rate, 1995 link_config.lane_count, 1996 adjusted_mode->crtc_clock, 1997 adjusted_mode->hdisplay, 1998 line_slice_count, 1999 dsc_bpp_x16, 2000 bw_overhead_flags)) 2001 continue; 2002 } 2003 2004 err = 0; 2005 2006 break; 2007 } 2008 intel_dp_link_caps_iter_end(&iter); 2009 2010 return err; 2011 } 2012 2013 static u16 intel_dp_dsc_max_delta_bppx16(const struct intel_connector *connector, 2014 enum intel_output_format output_format) 2015 { 2016 const u8 *dsc_dpcd = connector->dp.dsc_dpcd; 2017 u8 max_bpp_delta_v1 = dsc_dpcd[DP_DSC_MAX_BPP_DELTA_VERSION_1 - DP_DSC_SUPPORT]; 2018 int max_bpp; 2019 2020 if (!(dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] & 2021 DP_DSC_MAX_BPP_DELTA_AVAILABILITY)) 2022 return 0; 2023 2024 switch (output_format) { 2025 case INTEL_OUTPUT_FORMAT_RGB: 2026 case INTEL_OUTPUT_FORMAT_YCBCR444: 2027 max_bpp = max_bpp_delta_v1 & DP_DSC_RGB_YCbCr444_MAX_BPP_DELTA_MASK; 2028 if (max_bpp >= 1 && max_bpp <= 21) 2029 max_bpp = max_bpp + DP_DSC_BPP_DELTA_444 - 1; 2030 else 2031 max_bpp = 0; 2032 break; 2033 case INTEL_OUTPUT_FORMAT_YCBCR420: 2034 max_bpp = (max_bpp_delta_v1 & DP_DSC_NATIVE_YCbCr420_MAX_BPP_DELTA_MASK) >> 2035 DP_DSC_BPP_DELTA_SHIFT_420; 2036 if (max_bpp >= 1 && max_bpp <= 7) 2037 max_bpp = max_bpp + DP_DSC_BPP_DELTA_420 - 1; 2038 break; 2039 default: 2040 MISSING_CASE(output_format); 2041 return 0; 2042 } 2043 2044 return max_bpp << 4; 2045 } 2046 2047 static 2048 u16 intel_dp_dsc_max_sink_compressed_bppx16(const struct intel_connector *connector, 2049 enum intel_output_format output_format, 2050 int bpc) 2051 { 2052 u16 max_bppx16 = intel_dp_dsc_max_delta_bppx16(connector, output_format); 2053 2054 if (max_bppx16) 2055 return max_bppx16; 2056 2057 max_bppx16 = drm_edp_dsc_sink_output_bpp(connector->dp.dsc_dpcd); 2058 2059 if (max_bppx16) 2060 return max_bppx16; 2061 /* 2062 * If support not given in DPCD 67h, 68h, 6Eh, 6Fh use the Maximum Allowed bit rate 2063 * values as given in spec Table 2-157 DP v2.0 2064 */ 2065 switch (output_format) { 2066 case INTEL_OUTPUT_FORMAT_RGB: 2067 case INTEL_OUTPUT_FORMAT_YCBCR444: 2068 return (3 * bpc) << 4; 2069 case INTEL_OUTPUT_FORMAT_YCBCR420: 2070 return (3 * (bpc / 2)) << 4; 2071 default: 2072 MISSING_CASE(output_format); 2073 break; 2074 } 2075 2076 return 0; 2077 } 2078 2079 static int intel_dp_dsc_sink_min_compressed_bpp(enum intel_output_format output_format) 2080 { 2081 /* From Mandatory bit rate range Support Table 2-157 (DP v2.0) */ 2082 switch (output_format) { 2083 case INTEL_OUTPUT_FORMAT_RGB: 2084 case INTEL_OUTPUT_FORMAT_YCBCR444: 2085 return 8; 2086 case INTEL_OUTPUT_FORMAT_YCBCR420: 2087 return 6; 2088 default: 2089 MISSING_CASE(output_format); 2090 break; 2091 } 2092 2093 return 0; 2094 } 2095 2096 static int intel_dp_dsc_sink_max_compressed_bpp(const struct intel_connector *connector, 2097 enum intel_output_format output_format, 2098 int bpc) 2099 { 2100 return intel_dp_dsc_max_sink_compressed_bppx16(connector, 2101 output_format, bpc) >> 4; 2102 } 2103 2104 int intel_dp_dsc_min_src_compressed_bpp(void) 2105 { 2106 /* Min Compressed bpp supported by source is 8 */ 2107 return 8; 2108 } 2109 2110 static int dsc_src_max_compressed_bpp(struct intel_dp *intel_dp) 2111 { 2112 struct intel_display *display = to_intel_display(intel_dp); 2113 2114 /* 2115 * Forcing DSC and using the platform's max compressed bpp is seen to cause 2116 * underruns. Since DSC isn't needed in these cases, limit the 2117 * max compressed bpp to 18, which is a safe value across platforms with different 2118 * pipe bpps. 2119 */ 2120 if (intel_dp->force_dsc_en) 2121 return 18; 2122 2123 /* 2124 * Max Compressed bpp for Gen 13+ is 27bpp. 2125 * For earlier platform is 23bpp. (Bspec:49259). 2126 */ 2127 if (DISPLAY_VER(display) < 13) 2128 return 23; 2129 else 2130 return 27; 2131 } 2132 2133 /* 2134 * Note: for pre-13 display you still need to check the validity of each step. 2135 */ 2136 int intel_dp_dsc_bpp_step_x16(const struct intel_connector *connector) 2137 { 2138 struct intel_display *display = to_intel_display(connector); 2139 u8 incr = drm_dp_dsc_sink_bpp_incr(connector->dp.dsc_dpcd); 2140 2141 if (DISPLAY_VER(display) < 14 || !incr) 2142 return fxp_q4_from_int(1); 2143 2144 if (connector->mst.dp && 2145 !connector->link.force_bpp_x16 && !connector->mst.dp->force_dsc_fractional_bpp_en) 2146 return fxp_q4_from_int(1); 2147 2148 /* fxp q4 */ 2149 return fxp_q4_from_int(1) / incr; 2150 } 2151 2152 /* 2153 * Note: for bpp_x16 to be valid it must be also within the source/sink's 2154 * min..max bpp capability range. 2155 */ 2156 bool intel_dp_dsc_valid_compressed_bpp(struct intel_dp *intel_dp, int bpp_x16) 2157 { 2158 struct intel_display *display = to_intel_display(intel_dp); 2159 2160 if (DISPLAY_VER(display) >= 13) { 2161 if (intel_dp->force_dsc_fractional_bpp_en && !fxp_q4_to_frac(bpp_x16)) 2162 return false; 2163 2164 return true; 2165 } 2166 2167 if (fxp_q4_to_frac(bpp_x16)) 2168 return false; 2169 2170 return align_max_vesa_compressed_bpp_x16(bpp_x16) == bpp_x16; 2171 } 2172 2173 static int align_min_compressed_bpp_x16(const struct intel_connector *connector, int min_bpp_x16) 2174 { 2175 struct intel_display *display = to_intel_display(connector); 2176 2177 if (DISPLAY_VER(display) >= 13) { 2178 int bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2179 2180 drm_WARN_ON(display->drm, !is_power_of_2(bpp_step_x16)); 2181 2182 return round_up(min_bpp_x16, bpp_step_x16); 2183 } else { 2184 return align_min_vesa_compressed_bpp_x16(min_bpp_x16); 2185 } 2186 } 2187 2188 static int align_max_compressed_bpp_x16(const struct intel_connector *connector, 2189 enum intel_output_format output_format, 2190 int pipe_bpp, int max_bpp_x16) 2191 { 2192 struct intel_display *display = to_intel_display(connector); 2193 int link_bpp_x16 = intel_dp_output_format_link_bpp_x16(output_format, pipe_bpp); 2194 int bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2195 2196 max_bpp_x16 = min(max_bpp_x16, link_bpp_x16 - bpp_step_x16); 2197 2198 if (DISPLAY_VER(display) >= 13) { 2199 drm_WARN_ON(display->drm, !is_power_of_2(bpp_step_x16)); 2200 2201 return round_down(max_bpp_x16, bpp_step_x16); 2202 } else { 2203 return align_max_vesa_compressed_bpp_x16(max_bpp_x16); 2204 } 2205 } 2206 2207 /* 2208 * Find the max compressed BPP we can find a link configuration for. The BPPs to 2209 * try depend on the source (platform) and sink. 2210 */ 2211 static int dsc_compute_compressed_bpp(struct intel_dp *intel_dp, 2212 struct intel_crtc_state *pipe_config, 2213 struct drm_connector_state *conn_state, 2214 const struct link_config_limits *limits, 2215 int pipe_bpp) 2216 { 2217 struct intel_display *display = to_intel_display(intel_dp); 2218 struct intel_connector *connector = to_intel_connector(conn_state->connector); 2219 int min_bpp_x16, max_bpp_x16, bpp_step_x16; 2220 int bpp_x16; 2221 int ret; 2222 2223 min_bpp_x16 = limits->link.min_bpp_x16; 2224 max_bpp_x16 = limits->link.max_bpp_x16; 2225 bpp_step_x16 = intel_dp_dsc_bpp_step_x16(connector); 2226 2227 max_bpp_x16 = align_max_compressed_bpp_x16(connector, pipe_config->output_format, 2228 pipe_bpp, max_bpp_x16); 2229 if (intel_dp_is_edp(intel_dp)) { 2230 struct intel_dp_link_config max_link_config; 2231 2232 /* 2233 * FIXME: Clarify why eDP does not use the regular SST BW 2234 * check and instead always uses the maximum link config, 2235 * regardless of intel_dp::use_max_params. Then unify this eDP 2236 * path with the regular DP path. 2237 */ 2238 if (!intel_dp_get_connector_max_link_config(connector, limits, &max_link_config)) 2239 return -EINVAL; 2240 2241 pipe_config->port_clock = max_link_config.rate; 2242 pipe_config->lane_count = max_link_config.lane_count; 2243 2244 pipe_config->dsc.compressed_bpp_x16 = max_bpp_x16; 2245 2246 return 0; 2247 } 2248 2249 for (bpp_x16 = max_bpp_x16; bpp_x16 >= min_bpp_x16; bpp_x16 -= bpp_step_x16) { 2250 if (!intel_dp_dsc_valid_compressed_bpp(intel_dp, bpp_x16)) 2251 continue; 2252 2253 ret = dsc_compute_link_config(intel_dp, 2254 pipe_config, 2255 conn_state, 2256 limits, 2257 bpp_x16); 2258 if (ret == 0) { 2259 pipe_config->dsc.compressed_bpp_x16 = bpp_x16; 2260 if (intel_dp->force_dsc_fractional_bpp_en && 2261 fxp_q4_to_frac(bpp_x16)) 2262 drm_dbg_kms(display->drm, 2263 "Forcing DSC fractional bpp\n"); 2264 2265 return 0; 2266 } 2267 } 2268 2269 return -EINVAL; 2270 } 2271 2272 int intel_dp_dsc_min_src_input_bpc(void) 2273 { 2274 /* Min DSC Input BPC for ICL+ is 8 */ 2275 return 8; 2276 } 2277 2278 static 2279 bool is_dsc_pipe_bpp_sufficient(const struct link_config_limits *limits, 2280 int pipe_bpp) 2281 { 2282 return pipe_bpp >= limits->pipe.min_bpp && 2283 pipe_bpp <= limits->pipe.max_bpp; 2284 } 2285 2286 static 2287 int intel_dp_force_dsc_pipe_bpp(struct intel_dp *intel_dp, 2288 const struct link_config_limits *limits) 2289 { 2290 struct intel_display *display = to_intel_display(intel_dp); 2291 int forced_bpp; 2292 2293 if (!intel_dp->force_dsc_bpc) 2294 return 0; 2295 2296 forced_bpp = intel_dp->force_dsc_bpc * 3; 2297 2298 if (is_dsc_pipe_bpp_sufficient(limits, forced_bpp)) { 2299 drm_dbg_kms(display->drm, "Input DSC BPC forced to %d\n", 2300 intel_dp->force_dsc_bpc); 2301 return forced_bpp; 2302 } 2303 2304 drm_dbg_kms(display->drm, 2305 "Cannot force DSC BPC:%d, due to DSC BPC limits\n", 2306 intel_dp->force_dsc_bpc); 2307 2308 return 0; 2309 } 2310 2311 static int intel_dp_dsc_compute_pipe_bpp(struct intel_dp *intel_dp, 2312 struct intel_crtc_state *pipe_config, 2313 struct drm_connector_state *conn_state, 2314 const struct link_config_limits *limits) 2315 { 2316 int forced_bpp, pipe_bpp; 2317 int ret; 2318 2319 forced_bpp = intel_dp_force_dsc_pipe_bpp(intel_dp, limits); 2320 if (forced_bpp) 2321 pipe_bpp = forced_bpp; 2322 else 2323 pipe_bpp = limits->pipe.max_bpp; 2324 2325 ret = dsc_compute_compressed_bpp(intel_dp, pipe_config, conn_state, 2326 limits, pipe_bpp); 2327 if (ret) 2328 return -EINVAL; 2329 2330 pipe_config->pipe_bpp = pipe_bpp; 2331 2332 return 0; 2333 } 2334 2335 /* 2336 * Return whether FEC must be enabled for 8b10b SST or MST links. On 128b132b 2337 * links FEC is always enabled implicitly by the HW, so this function returns 2338 * false for that case. 2339 */ 2340 bool intel_dp_needs_8b10b_fec(const struct intel_crtc_state *crtc_state, 2341 bool dsc_enabled_on_crtc) 2342 { 2343 if (intel_dp_is_uhbr(crtc_state)) 2344 return false; 2345 2346 /* 2347 * Though eDP v1.5 supports FEC with DSC, unlike DP, it is optional. 2348 * Since, FEC is a bandwidth overhead, continue to not enable it for 2349 * eDP. Until, there is a good reason to do so. 2350 */ 2351 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) 2352 return false; 2353 2354 return dsc_enabled_on_crtc || intel_dsc_enabled_on_link(crtc_state); 2355 } 2356 2357 void intel_dp_dsc_reset_config(struct intel_crtc_state *crtc_state) 2358 { 2359 crtc_state->fec_enable = false; 2360 2361 crtc_state->dsc.compression_enable = false; 2362 crtc_state->dsc.compressed_bpp_x16 = 0; 2363 2364 memset(&crtc_state->dsc.slice_config, 0, sizeof(crtc_state->dsc.slice_config)); 2365 memset(&crtc_state->dsc.config, 0, sizeof(crtc_state->dsc.config)); 2366 } 2367 2368 int intel_dp_dsc_compute_config(struct intel_dp *intel_dp, 2369 struct intel_crtc_state *pipe_config, 2370 struct drm_connector_state *conn_state, 2371 const struct link_config_limits *limits, 2372 int timeslots) 2373 { 2374 struct intel_display *display = to_intel_display(intel_dp); 2375 const struct intel_connector *connector = 2376 to_intel_connector(conn_state->connector); 2377 const struct drm_display_mode *adjusted_mode = 2378 &pipe_config->hw.adjusted_mode; 2379 int num_joined_pipes = intel_crtc_num_joined_pipes(pipe_config); 2380 bool is_mst = intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST); 2381 int ret; 2382 2383 /* 2384 * FIXME: set the FEC enabled state once pipe_config->port_clock is 2385 * already known, so the UHBR/non-UHBR mode can be determined. 2386 */ 2387 pipe_config->fec_enable = intel_dp_needs_8b10b_fec(pipe_config, true); 2388 2389 if (!intel_dp_dsc_supports_format(connector, pipe_config->output_format)) 2390 return -EINVAL; 2391 2392 /* 2393 * Link parameters, pipe bpp and compressed bpp have already been 2394 * figured out for DP MST DSC. 2395 */ 2396 if (!is_mst) { 2397 ret = intel_dp_dsc_compute_pipe_bpp(intel_dp, pipe_config, 2398 conn_state, limits); 2399 if (ret) { 2400 drm_dbg_kms(display->drm, 2401 "No Valid pipe bpp for given mode ret = %d\n", ret); 2402 return ret; 2403 } 2404 } 2405 2406 if (!intel_dp_dsc_get_slice_config(connector, adjusted_mode->crtc_clock, 2407 adjusted_mode->crtc_hdisplay, num_joined_pipes, 2408 &pipe_config->dsc.slice_config)) 2409 return -EINVAL; 2410 2411 ret = intel_dp_dsc_compute_params(connector, pipe_config); 2412 if (ret < 0) { 2413 drm_dbg_kms(display->drm, 2414 "Cannot compute valid DSC parameters for Input Bpp = %d" 2415 "Compressed BPP = " FXP_Q4_FMT "\n", 2416 pipe_config->pipe_bpp, 2417 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16)); 2418 return ret; 2419 } 2420 2421 intel_dsc_enable_on_crtc(pipe_config); 2422 2423 drm_dbg_kms(display->drm, "DP DSC computed with Input Bpp = %d " 2424 "Compressed Bpp = " FXP_Q4_FMT " Slice Count = %d\n", 2425 pipe_config->pipe_bpp, 2426 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16), 2427 intel_dsc_line_slice_count(&pipe_config->dsc.slice_config)); 2428 2429 return 0; 2430 } 2431 2432 static int 2433 dsc_throughput_quirk_max_bpp_x16(const struct intel_connector *connector, 2434 int mode_clock) 2435 { 2436 if (!connector->dp.dsc_throughput_quirk) 2437 return INT_MAX; 2438 2439 /* 2440 * Synaptics Panamera branch devices have a problem decompressing a 2441 * stream with a compressed link-bpp higher than 12, if the pixel 2442 * clock is higher than ~50 % of the maximum overall throughput 2443 * reported by the branch device. Work around this by limiting the 2444 * maximum link bpp for such pixel clocks. 2445 * 2446 * TODO: Use the throughput value specific to the actual RGB/YUV 2447 * format of the output, after determining the pixel clock limit for 2448 * YUV modes. For now use the smaller of the throughput values, which 2449 * may result in limiting the link-bpp value already at a lower than 2450 * required mode clock in case of native YUV422/420 output formats. 2451 * The RGB/YUV444 throughput value should be always either equal or 2452 * smaller than the YUV422/420 value, but let's not depend on this 2453 * assumption. 2454 */ 2455 if (mode_clock < 2456 min(connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444, 2457 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420) / 2) 2458 return INT_MAX; 2459 2460 return fxp_q4_from_int(12); 2461 } 2462 2463 int intel_dp_compute_min_compressed_bpp_x16(struct intel_connector *connector, 2464 enum intel_output_format output_format) 2465 { 2466 int dsc_src_min_bpp, dsc_sink_min_bpp, dsc_min_bpp; 2467 int min_bpp_x16; 2468 2469 dsc_src_min_bpp = intel_dp_dsc_min_src_compressed_bpp(); 2470 dsc_sink_min_bpp = intel_dp_dsc_sink_min_compressed_bpp(output_format); 2471 dsc_min_bpp = max(dsc_src_min_bpp, dsc_sink_min_bpp); 2472 2473 min_bpp_x16 = fxp_q4_from_int(dsc_min_bpp); 2474 2475 min_bpp_x16 = align_min_compressed_bpp_x16(connector, min_bpp_x16); 2476 2477 return min_bpp_x16; 2478 } 2479 2480 static int compute_max_compressed_bpp_x16(struct intel_connector *connector, 2481 int mode_clock, int mode_hdisplay, 2482 int num_joined_pipes, 2483 enum intel_output_format output_format, 2484 int pipe_max_bpp, int max_link_bpp_x16) 2485 { 2486 struct intel_display *display = to_intel_display(connector); 2487 struct intel_dp *intel_dp = intel_attached_dp(connector); 2488 int dsc_src_max_bpp, dsc_sink_max_bpp, dsc_max_bpp; 2489 int throughput_max_bpp_x16; 2490 int joiner_max_bpp; 2491 2492 dsc_src_max_bpp = dsc_src_max_compressed_bpp(intel_dp); 2493 joiner_max_bpp = get_max_compressed_bpp_with_joiner(display, 2494 mode_clock, 2495 mode_hdisplay, 2496 num_joined_pipes); 2497 dsc_sink_max_bpp = intel_dp_dsc_sink_max_compressed_bpp(connector, 2498 output_format, 2499 pipe_max_bpp / 3); 2500 dsc_max_bpp = min(dsc_sink_max_bpp, dsc_src_max_bpp); 2501 dsc_max_bpp = min(dsc_max_bpp, joiner_max_bpp); 2502 2503 max_link_bpp_x16 = min(max_link_bpp_x16, fxp_q4_from_int(dsc_max_bpp)); 2504 2505 throughput_max_bpp_x16 = dsc_throughput_quirk_max_bpp_x16(connector, 2506 mode_clock); 2507 if (throughput_max_bpp_x16 < max_link_bpp_x16) { 2508 max_link_bpp_x16 = throughput_max_bpp_x16; 2509 2510 drm_dbg_kms(display->drm, 2511 "[CONNECTOR:%d:%s] Decreasing link max bpp to " FXP_Q4_FMT " due to DSC throughput quirk\n", 2512 connector->base.base.id, connector->base.name, 2513 FXP_Q4_ARGS(max_link_bpp_x16)); 2514 } 2515 2516 max_link_bpp_x16 = align_max_compressed_bpp_x16(connector, output_format, 2517 pipe_max_bpp, max_link_bpp_x16); 2518 2519 return max_link_bpp_x16; 2520 } 2521 2522 bool intel_dp_mode_valid_with_dsc(struct intel_connector *connector, 2523 int link_clock, int lane_count, 2524 int mode_clock, int mode_hdisplay, 2525 int num_joined_pipes, 2526 enum intel_output_format output_format, 2527 int pipe_bpp, unsigned long bw_overhead_flags) 2528 { 2529 struct intel_dp *intel_dp = intel_attached_dp(connector); 2530 int min_bpp_x16 = intel_dp_compute_min_compressed_bpp_x16(connector, 2531 output_format); 2532 int max_bpp_x16 = compute_max_compressed_bpp_x16(connector, 2533 mode_clock, mode_hdisplay, 2534 num_joined_pipes, 2535 output_format, 2536 pipe_bpp, INT_MAX); 2537 int dsc_slice_count = intel_dp_dsc_get_slice_count(connector, 2538 mode_clock, 2539 mode_hdisplay, 2540 num_joined_pipes); 2541 2542 if (min_bpp_x16 <= 0 || min_bpp_x16 > max_bpp_x16) 2543 return false; 2544 2545 if (dsc_slice_count == 0) 2546 return false; 2547 2548 return is_bw_sufficient_for_dsc_config(intel_dp, 2549 link_clock, lane_count, 2550 mode_clock, mode_hdisplay, 2551 dsc_slice_count, min_bpp_x16, 2552 bw_overhead_flags); 2553 } 2554 2555 bool 2556 intel_dp_get_connector_max_link_config(struct intel_connector *connector, 2557 const struct link_config_limits *limits, 2558 struct intel_dp_link_config *max_link_config) 2559 { 2560 struct intel_dp *intel_dp = intel_attached_dp(connector); 2561 struct intel_dp_link_caps *link_caps = intel_dp->link.caps; 2562 struct intel_dp_link_caps_order order = 2563 intel_dp_link_caps_connector_compute_order(connector); 2564 2565 return intel_dp_link_caps_get_max_config(link_caps, order.key, limits->link_config_filter, 2566 max_link_config); 2567 } 2568 2569 /* 2570 * Calculate the output link min, max bpp values in limits based on the pipe bpp 2571 * range, crtc_state and dsc mode. Return true on success. 2572 */ 2573 static bool 2574 intel_dp_compute_config_link_bpp_limits(struct intel_connector *connector, 2575 const struct intel_crtc_state *crtc_state, 2576 bool dsc, 2577 struct link_config_limits *limits) 2578 { 2579 struct intel_display *display = to_intel_display(connector); 2580 struct intel_dp *intel_dp = intel_attached_dp(connector); 2581 const struct drm_display_mode *adjusted_mode = 2582 &crtc_state->hw.adjusted_mode; 2583 const struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2584 const struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2585 struct intel_dp_link_config max_link_config; 2586 int max_link_bpp_x16; 2587 2588 max_link_bpp_x16 = min(crtc_state->max_link_bpp_x16, 2589 fxp_q4_from_int(limits->pipe.max_bpp)); 2590 2591 if (!dsc) { 2592 max_link_bpp_x16 = rounddown(max_link_bpp_x16, fxp_q4_from_int(2 * 3)); 2593 2594 if (max_link_bpp_x16 < fxp_q4_from_int(limits->pipe.min_bpp)) 2595 return false; 2596 2597 limits->link.min_bpp_x16 = fxp_q4_from_int(limits->pipe.min_bpp); 2598 } else { 2599 limits->link.min_bpp_x16 = 2600 intel_dp_compute_min_compressed_bpp_x16(connector, 2601 crtc_state->output_format); 2602 2603 max_link_bpp_x16 = 2604 compute_max_compressed_bpp_x16(connector, 2605 adjusted_mode->crtc_clock, 2606 adjusted_mode->hdisplay, 2607 intel_crtc_num_joined_pipes(crtc_state), 2608 crtc_state->output_format, 2609 limits->pipe.max_bpp, 2610 max_link_bpp_x16); 2611 } 2612 2613 limits->link.max_bpp_x16 = max_link_bpp_x16; 2614 2615 if (!intel_dp_get_connector_max_link_config(connector, limits, &max_link_config)) 2616 return false; 2617 2618 drm_dbg_kms(display->drm, 2619 "[ENCODER:%d:%s][CRTC:%d:%s] DP link limits: pixel clock %d kHz DSC %s max link %dx%d max pipe_bpp %d min link_bpp " FXP_Q4_FMT " max link_bpp " FXP_Q4_FMT "\n", 2620 encoder->base.base.id, encoder->base.name, 2621 crtc->base.base.id, crtc->base.name, 2622 adjusted_mode->crtc_clock, 2623 str_on_off(dsc), 2624 max_link_config.lane_count, 2625 max_link_config.rate, 2626 limits->pipe.max_bpp, 2627 FXP_Q4_ARGS(limits->link.min_bpp_x16), 2628 FXP_Q4_ARGS(limits->link.max_bpp_x16)); 2629 2630 if (limits->link.min_bpp_x16 <= 0 || 2631 limits->link.min_bpp_x16 > limits->link.max_bpp_x16) 2632 return false; 2633 2634 return true; 2635 } 2636 2637 static bool 2638 intel_dp_dsc_compute_pipe_bpp_limits(struct intel_connector *connector, 2639 struct link_config_limits *limits) 2640 { 2641 struct intel_display *display = to_intel_display(connector); 2642 const struct link_config_limits orig_limits = *limits; 2643 int dsc_min_bpc = intel_dp_dsc_min_src_input_bpc(); 2644 int dsc_max_bpc = intel_dp_dsc_max_src_input_bpc(display); 2645 2646 limits->pipe.min_bpp = max(limits->pipe.min_bpp, dsc_min_bpc * 3); 2647 limits->pipe.min_bpp = align_min_sink_dsc_input_bpp(connector, limits->pipe.min_bpp); 2648 2649 limits->pipe.max_bpp = min(limits->pipe.max_bpp, dsc_max_bpc * 3); 2650 limits->pipe.max_bpp = align_max_sink_dsc_input_bpp(connector, limits->pipe.max_bpp); 2651 2652 if (limits->pipe.min_bpp <= 0 || 2653 limits->pipe.min_bpp > limits->pipe.max_bpp) { 2654 drm_dbg_kms(display->drm, 2655 "[CONNECTOR:%d:%s] Invalid DSC src/sink input BPP (src:%d-%d pipe:%d-%d sink-align:%d-%d)\n", 2656 connector->base.base.id, connector->base.name, 2657 dsc_min_bpc * 3, dsc_max_bpc * 3, 2658 orig_limits.pipe.min_bpp, orig_limits.pipe.max_bpp, 2659 limits->pipe.min_bpp, limits->pipe.max_bpp); 2660 2661 return false; 2662 } 2663 2664 return true; 2665 } 2666 2667 bool 2668 intel_dp_compute_config_limits(struct intel_dp *intel_dp, 2669 struct drm_connector_state *conn_state, 2670 struct intel_crtc_state *crtc_state, 2671 bool respect_downstream_limits, 2672 bool dsc, 2673 struct link_config_limits *limits) 2674 { 2675 struct intel_display *display = to_intel_display(intel_dp); 2676 struct intel_dp_link_caps *link_caps = intel_dp->link.caps; 2677 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 2678 struct intel_connector *connector = 2679 to_intel_connector(conn_state->connector); 2680 2681 limits->link_config_filter = INTEL_DP_LINK_CAPS_FILTER_ALL; 2682 2683 limits->pipe.min_bpp = intel_dp_min_bpp(crtc_state->output_format); 2684 if (is_mst) { 2685 /* 2686 * FIXME: If all the streams can't fit into the link with their 2687 * current pipe_bpp we should reduce pipe_bpp across the board 2688 * until things start to fit. Until then we limit to <= 8bpc 2689 * since that's what was hardcoded for all MST streams 2690 * previously. This hack should be removed once we have the 2691 * proper retry logic in place. 2692 */ 2693 limits->pipe.max_bpp = min(crtc_state->max_pipe_bpp, 24); 2694 } else { 2695 limits->pipe.max_bpp = intel_dp_max_bpp(intel_dp, crtc_state, 2696 respect_downstream_limits); 2697 } 2698 2699 if (!dsc && intel_dp_in_hdr_mode(conn_state)) { 2700 if (intel_dp_supports_dsc(intel_dp, connector, crtc_state) && 2701 limits->pipe.max_bpp >= 30) 2702 limits->pipe.min_bpp = max(limits->pipe.min_bpp, 30); 2703 else 2704 drm_dbg_kms(display->drm, 2705 "[CONNECTOR:%d:%s] Can't force 30 bpp for HDR (pipe bpp: %d-%d DSC-support: %s)\n", 2706 connector->base.base.id, connector->base.name, 2707 limits->pipe.min_bpp, limits->pipe.max_bpp, 2708 str_yes_no(intel_dp_supports_dsc(intel_dp, connector, 2709 crtc_state))); 2710 } 2711 2712 /* 2713 * HDMI knows no 6 bpc transport format, and DSC with an at least 2714 * 8 bpc input provides a better output quality than a dithered 2715 * 6 bpc output. Prefer it for HDMI sinks, by failing the 2716 * uncompressed link config for modes which would fit only with a 2717 * 6 bpc pipe BPP. Honor a lower limit set via the max bpc 2718 * connector property. 2719 */ 2720 if (!dsc && intel_dp_has_hdmi_sink(intel_dp) && 2721 intel_dp_supports_dsc(intel_dp, connector, crtc_state) && 2722 limits->pipe.max_bpp >= 24 && 2723 crtc_state->pipe_bpp >= 24) 2724 limits->pipe.min_bpp = max(limits->pipe.min_bpp, 24); 2725 2726 if (limits->pipe.min_bpp <= 0 || 2727 limits->pipe.min_bpp > limits->pipe.max_bpp) { 2728 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s] Invalid pipe bpp range: %d-%d\n", 2729 connector->base.base.id, connector->base.name, 2730 limits->pipe.min_bpp, limits->pipe.max_bpp); 2731 2732 return false; 2733 } 2734 2735 if (dsc && !intel_dp_dsc_compute_pipe_bpp_limits(connector, limits)) 2736 return false; 2737 2738 /* 2739 * crtc_state->pipe_bpp is the non-DP specific baseline (platform / 2740 * EDID) maximum pipe BPP limited by the max-BPC connector property 2741 * request. Since by now pipe.max_bpp is <= the above baseline 2742 * maximum BPP, the only remaining reason for adjusting pipe.max_bpp 2743 * is the max-BPC connector property request. Adjust pipe.max_bpp to 2744 * this request within the current valid pipe.min_bpp .. pipe.max_bpp 2745 * range. 2746 */ 2747 limits->pipe.max_bpp = clamp(crtc_state->pipe_bpp, limits->pipe.min_bpp, 2748 limits->pipe.max_bpp); 2749 if (dsc) 2750 limits->pipe.max_bpp = align_max_sink_dsc_input_bpp(connector, 2751 limits->pipe.max_bpp); 2752 2753 if (limits->pipe.max_bpp != crtc_state->pipe_bpp) 2754 drm_dbg_kms(display->drm, 2755 "[CONNECTOR:%d:%s] Adjusting requested max pipe bpp %d -> %d\n", 2756 connector->base.base.id, connector->base.name, 2757 crtc_state->pipe_bpp, limits->pipe.max_bpp); 2758 2759 if (is_mst || intel_dp->use_max_params) { 2760 struct intel_dp_link_caps_filter new_filter = INTEL_DP_LINK_CAPS_FILTER_NONE; 2761 struct intel_dp_link_config max_config; 2762 2763 /* 2764 * For MST we always configure max link bw - the spec doesn't 2765 * seem to suggest we should do otherwise. 2766 * 2767 * Use the maximum clock and number of lanes the eDP panel 2768 * advertizes being capable of in case the initial fast 2769 * optimal params failed us. The panels are generally 2770 * designed to support only a single clock and lane 2771 * configuration, and typically on older panels these 2772 * values correspond to the native resolution of the panel. 2773 */ 2774 if (!intel_dp_get_connector_max_link_config(connector, limits, &max_config)) 2775 return false; 2776 2777 if (!intel_dp_link_caps_filter_add(link_caps, &new_filter, &max_config)) 2778 return false; 2779 2780 limits->link_config_filter = new_filter; 2781 } 2782 2783 if (!intel_dp_test_compute_config(connector, crtc_state, limits)) 2784 return false; 2785 2786 return intel_dp_compute_config_link_bpp_limits(connector, 2787 crtc_state, 2788 dsc, 2789 limits); 2790 } 2791 2792 int intel_dp_config_required_rate(const struct intel_crtc_state *crtc_state) 2793 { 2794 const struct drm_display_mode *adjusted_mode = 2795 &crtc_state->hw.adjusted_mode; 2796 int link_bpp_x16 = crtc_state->dsc.compression_enable ? 2797 crtc_state->dsc.compressed_bpp_x16 : 2798 fxp_q4_from_int(crtc_state->pipe_bpp); 2799 2800 return intel_dp_link_required(crtc_state->port_clock, crtc_state->lane_count, 2801 adjusted_mode->crtc_clock, adjusted_mode->hdisplay, 2802 link_bpp_x16, 0); 2803 } 2804 2805 bool intel_dp_joiner_needs_dsc(struct intel_display *display, 2806 int num_joined_pipes) 2807 { 2808 /* 2809 * Pipe joiner needs compression up to display 12 due to bandwidth 2810 * limitation. DG2 onwards pipe joiner can be enabled without 2811 * compression. 2812 * Ultrajoiner always needs compression. 2813 */ 2814 return (!HAS_UNCOMPRESSED_JOINER(display) && num_joined_pipes == 2) || 2815 num_joined_pipes == 4; 2816 } 2817 2818 static int 2819 intel_dp_compute_link_for_joined_pipes(struct intel_encoder *encoder, 2820 struct intel_crtc_state *pipe_config, 2821 struct drm_connector_state *conn_state, 2822 bool respect_downstream_limits) 2823 { 2824 struct intel_display *display = to_intel_display(encoder); 2825 int num_joined_pipes = intel_crtc_num_joined_pipes(pipe_config); 2826 struct intel_connector *connector = 2827 to_intel_connector(conn_state->connector); 2828 const struct drm_display_mode *adjusted_mode = 2829 &pipe_config->hw.adjusted_mode; 2830 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2831 struct link_config_limits limits; 2832 bool dsc_needed, joiner_needs_dsc; 2833 int ret = 0; 2834 2835 intel_dp_dsc_reset_config(pipe_config); 2836 2837 joiner_needs_dsc = intel_dp_joiner_needs_dsc(display, num_joined_pipes); 2838 2839 dsc_needed = joiner_needs_dsc || intel_dp->force_dsc_en || 2840 !intel_dp_compute_config_limits(intel_dp, conn_state, pipe_config, 2841 respect_downstream_limits, 2842 false, 2843 &limits); 2844 2845 if (!dsc_needed) { 2846 /* 2847 * Optimize for slow and wide for everything, because there are some 2848 * eDP 1.3 and 1.4 panels don't work well with fast and narrow. 2849 */ 2850 ret = intel_dp_compute_link_config_wide(intel_dp, pipe_config, 2851 conn_state, &limits); 2852 if (!ret && intel_dp_is_uhbr(pipe_config)) 2853 ret = intel_dp_mtp_tu_compute_config(intel_dp, 2854 pipe_config, 2855 conn_state, 2856 fxp_q4_from_int(pipe_config->pipe_bpp), 2857 fxp_q4_from_int(pipe_config->pipe_bpp), 2858 0, false); 2859 2860 if (ret || 2861 !intel_dp_dotclk_valid(display, 2862 adjusted_mode->crtc_clock, 2863 adjusted_mode->crtc_htotal, 2864 0, 2865 num_joined_pipes)) 2866 dsc_needed = true; 2867 } 2868 2869 if (dsc_needed && !intel_dp_supports_dsc(intel_dp, connector, pipe_config)) { 2870 drm_dbg_kms(display->drm, "DSC required but not available\n"); 2871 return -EINVAL; 2872 } 2873 2874 if (dsc_needed) { 2875 int dsc_slice_count; 2876 2877 drm_dbg_kms(display->drm, 2878 "Try DSC (fallback=%s, joiner=%s, force=%s)\n", 2879 str_yes_no(ret), str_yes_no(joiner_needs_dsc), 2880 str_yes_no(intel_dp->force_dsc_en)); 2881 2882 if (!intel_dp_compute_config_limits(intel_dp, conn_state, pipe_config, 2883 respect_downstream_limits, 2884 true, 2885 &limits)) 2886 return -EINVAL; 2887 2888 ret = intel_dp_dsc_compute_config(intel_dp, pipe_config, 2889 conn_state, &limits, 64); 2890 if (ret < 0) 2891 return ret; 2892 2893 dsc_slice_count = intel_dsc_line_slice_count(&pipe_config->dsc.slice_config); 2894 2895 if (!intel_dp_dotclk_valid(display, 2896 adjusted_mode->crtc_clock, 2897 adjusted_mode->crtc_htotal, 2898 dsc_slice_count, 2899 num_joined_pipes)) 2900 return -EINVAL; 2901 } 2902 2903 drm_dbg_kms(display->drm, 2904 "DP lane count %d clock %d bpp input %d compressed " FXP_Q4_FMT " HDR %s link rate required %d available %d\n", 2905 pipe_config->lane_count, pipe_config->port_clock, 2906 pipe_config->pipe_bpp, 2907 FXP_Q4_ARGS(pipe_config->dsc.compressed_bpp_x16), 2908 str_yes_no(intel_dp_in_hdr_mode(conn_state)), 2909 intel_dp_config_required_rate(pipe_config), 2910 intel_dp_max_link_data_rate(intel_dp, 2911 pipe_config->port_clock, 2912 pipe_config->lane_count)); 2913 2914 return 0; 2915 } 2916 2917 static int 2918 intel_dp_compute_link_config(struct intel_encoder *encoder, 2919 struct intel_crtc_state *crtc_state, 2920 struct drm_connector_state *conn_state, 2921 bool respect_downstream_limits) 2922 { 2923 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2924 struct intel_connector *connector = 2925 to_intel_connector(conn_state->connector); 2926 const struct drm_display_mode *adjusted_mode = 2927 &crtc_state->hw.adjusted_mode; 2928 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2929 int num_joined_pipes; 2930 int ret = -EINVAL; 2931 2932 if (crtc_state->fec_enable && 2933 !intel_dp_supports_fec(intel_dp, connector, crtc_state)) 2934 return -EINVAL; 2935 2936 for_each_joiner_candidate(connector, adjusted_mode, num_joined_pipes) { 2937 /* 2938 * NOTE: 2939 * The crtc_state->joiner_pipes should have been set at the end 2940 * only if all the conditions are met. However that would mean 2941 * that num_joined_pipes is passed around to all helpers and 2942 * make them use it instead of using crtc_state->joiner_pipes 2943 * directly or indirectly (via intel_crtc_num_joined_pipes()). 2944 * 2945 * For now, setting crtc_state->joiner_pipes to the candidate 2946 * value to avoid the above churn and resetting it to 0, in case 2947 * no joiner candidate is found to be suitable for the given 2948 * configuration. 2949 */ 2950 if (num_joined_pipes > 1) 2951 crtc_state->joiner_pipes = GENMASK(crtc->pipe + num_joined_pipes - 1, 2952 crtc->pipe); 2953 2954 ret = intel_dp_compute_link_for_joined_pipes(encoder, crtc_state, conn_state, 2955 respect_downstream_limits); 2956 if (ret == 0 || ret == -EDEADLK) 2957 break; 2958 } 2959 2960 if (ret < 0) 2961 crtc_state->joiner_pipes = 0; 2962 2963 return ret; 2964 } 2965 2966 bool intel_dp_limited_color_range(const struct intel_crtc_state *crtc_state, 2967 const struct drm_connector_state *conn_state) 2968 { 2969 const struct intel_digital_connector_state *intel_conn_state = 2970 to_intel_digital_connector_state(conn_state); 2971 const struct drm_display_mode *adjusted_mode = 2972 &crtc_state->hw.adjusted_mode; 2973 2974 /* 2975 * Our YCbCr output is always limited range. 2976 * crtc_state->limited_color_range only applies to RGB, 2977 * and it must never be set for YCbCr or we risk setting 2978 * some conflicting bits in TRANSCONF which will mess up 2979 * the colors on the monitor. 2980 */ 2981 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB) 2982 return false; 2983 2984 if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) { 2985 /* 2986 * See: 2987 * CEA-861-E - 5.1 Default Encoding Parameters 2988 * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry 2989 */ 2990 return crtc_state->pipe_bpp != 18 && 2991 drm_default_rgb_quant_range(adjusted_mode) == 2992 HDMI_QUANTIZATION_RANGE_LIMITED; 2993 } else { 2994 return intel_conn_state->broadcast_rgb == 2995 INTEL_BROADCAST_RGB_LIMITED; 2996 } 2997 } 2998 2999 static bool intel_dp_port_has_audio(struct intel_display *display, enum port port) 3000 { 3001 if (display->platform.g4x) 3002 return false; 3003 if (DISPLAY_VER(display) < 12 && port == PORT_A) 3004 return false; 3005 3006 return true; 3007 } 3008 3009 static void intel_dp_compute_vsc_colorimetry(const struct intel_crtc_state *crtc_state, 3010 const struct drm_connector_state *conn_state, 3011 struct drm_dp_vsc_sdp *vsc) 3012 { 3013 struct intel_display *display = to_intel_display(crtc_state); 3014 3015 if (crtc_state->has_panel_replay) { 3016 /* 3017 * Prepare VSC Header for SU as per DP 2.0 spec, Table 2-223 3018 * VSC SDP supporting 3D stereo, Panel Replay, and Pixel 3019 * Encoding/Colorimetry Format indication. 3020 */ 3021 vsc->revision = 0x7; 3022 } else { 3023 /* 3024 * Prepare VSC Header for SU as per DP 1.4 spec, Table 2-118 3025 * VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/ 3026 * Colorimetry Format indication. 3027 */ 3028 vsc->revision = 0x5; 3029 } 3030 3031 vsc->length = 0x13; 3032 3033 /* DP 1.4a spec, Table 2-120 */ 3034 switch (crtc_state->output_format) { 3035 case INTEL_OUTPUT_FORMAT_YCBCR444: 3036 vsc->pixelformat = DP_PIXELFORMAT_YUV444; 3037 break; 3038 case INTEL_OUTPUT_FORMAT_YCBCR420: 3039 vsc->pixelformat = DP_PIXELFORMAT_YUV420; 3040 break; 3041 case INTEL_OUTPUT_FORMAT_RGB: 3042 default: 3043 vsc->pixelformat = DP_PIXELFORMAT_RGB; 3044 } 3045 3046 switch (conn_state->colorspace) { 3047 case DRM_MODE_COLORIMETRY_BT709_YCC: 3048 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC; 3049 break; 3050 case DRM_MODE_COLORIMETRY_XVYCC_601: 3051 vsc->colorimetry = DP_COLORIMETRY_XVYCC_601; 3052 break; 3053 case DRM_MODE_COLORIMETRY_XVYCC_709: 3054 vsc->colorimetry = DP_COLORIMETRY_XVYCC_709; 3055 break; 3056 case DRM_MODE_COLORIMETRY_SYCC_601: 3057 vsc->colorimetry = DP_COLORIMETRY_SYCC_601; 3058 break; 3059 case DRM_MODE_COLORIMETRY_OPYCC_601: 3060 vsc->colorimetry = DP_COLORIMETRY_OPYCC_601; 3061 break; 3062 case DRM_MODE_COLORIMETRY_BT2020_CYCC: 3063 vsc->colorimetry = DP_COLORIMETRY_BT2020_CYCC; 3064 break; 3065 case DRM_MODE_COLORIMETRY_BT2020_RGB: 3066 vsc->colorimetry = DP_COLORIMETRY_BT2020_RGB; 3067 break; 3068 case DRM_MODE_COLORIMETRY_BT2020_YCC: 3069 vsc->colorimetry = DP_COLORIMETRY_BT2020_YCC; 3070 break; 3071 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65: 3072 case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER: 3073 vsc->colorimetry = DP_COLORIMETRY_DCI_P3_RGB; 3074 break; 3075 default: 3076 /* 3077 * RGB->YCBCR color conversion uses the BT.709 3078 * color space. 3079 */ 3080 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 3081 vsc->colorimetry = DP_COLORIMETRY_BT709_YCC; 3082 else 3083 vsc->colorimetry = DP_COLORIMETRY_DEFAULT; 3084 break; 3085 } 3086 3087 vsc->bpc = crtc_state->pipe_bpp / 3; 3088 3089 /* only RGB pixelformat supports 6 bpc */ 3090 drm_WARN_ON(display->drm, 3091 vsc->bpc == 6 && vsc->pixelformat != DP_PIXELFORMAT_RGB); 3092 3093 /* All YCbCr formats are always limited range. */ 3094 if (vsc->pixelformat == DP_PIXELFORMAT_RGB) 3095 vsc->dynamic_range = crtc_state->limited_color_range ? 3096 DP_DYNAMIC_RANGE_CTA : DP_DYNAMIC_RANGE_VESA; 3097 else 3098 vsc->dynamic_range = DP_DYNAMIC_RANGE_CTA; 3099 3100 vsc->content_type = DP_CONTENT_TYPE_NOT_DEFINED; 3101 } 3102 3103 static bool intel_dp_needs_as_sdp(struct intel_dp *intel_dp, 3104 struct intel_crtc_state *crtc_state) 3105 { 3106 if (!intel_dp->as_sdp_v2_supported) 3107 return false; 3108 3109 /* 3110 * #TODO: Add AS SDP v1 support for PCONs (DP branch devices). 3111 */ 3112 if (drm_dp_is_branch(intel_dp->dpcd)) 3113 return false; 3114 3115 if (intel_psr_needs_alpm_aux_less(intel_dp, crtc_state) && 3116 !intel_psr_pr_async_video_timing_supported(intel_dp)) 3117 return true; 3118 3119 return intel_vrr_possible(crtc_state); 3120 } 3121 3122 static void intel_dp_compute_as_sdp(struct intel_dp *intel_dp, 3123 struct intel_crtc_state *crtc_state) 3124 { 3125 struct drm_dp_as_sdp *as_sdp = &crtc_state->infoframes.as_sdp; 3126 const struct drm_display_mode *adjusted_mode = 3127 &crtc_state->hw.adjusted_mode; 3128 3129 /* 3130 * #FIXME: SDP/infoframe updates aren’t truly atomic, and with the new 3131 * cdclk->tc clock crossing we may transiently send a corrupted packet 3132 * if the update lands mid‑transmission. 3133 */ 3134 if (!intel_dp_needs_as_sdp(intel_dp, crtc_state)) 3135 return; 3136 3137 crtc_state->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC); 3138 3139 as_sdp->sdp_type = DP_SDP_ADAPTIVE_SYNC; 3140 as_sdp->length = 0x9; 3141 as_sdp->duration_incr_ms = 0; 3142 as_sdp->revision = 0x2; 3143 as_sdp->vtotal = intel_vrr_vmin_vtotal(crtc_state); 3144 3145 if (crtc_state->cmrr.enable) { 3146 as_sdp->mode = DP_AS_SDP_FAVT_TRR_REACHED; 3147 as_sdp->target_rr = drm_mode_vrefresh(adjusted_mode); 3148 as_sdp->target_rr_divider = true; 3149 } else if (crtc_state->vrr.enable) { 3150 as_sdp->mode = DP_AS_SDP_AVT_DYNAMIC_VTOTAL; 3151 } else { 3152 as_sdp->mode = DP_AS_SDP_AVT_FIXED_VTOTAL; 3153 } 3154 3155 /* 3156 * For Panel Replay with Async Video Timing support, the source can 3157 * disable sending the AS SDP during PR Active state. In that case, 3158 * the sink needs the coasting vtotal value to maintain the refresh 3159 * rate. The HW only samples this on PR_ALPM_CTL[AS SDP Transmission 3160 * in Active Disable], which we never program, so providing the value 3161 * unconditionally when the sink advertises the capability is safe. 3162 * 3163 * #TODO: 3164 * If we ever advertise support for coasting at other refresh targets, 3165 * this logic could be revisited. For now, use the minimum refresh rate 3166 * as the only safe coasting value. 3167 */ 3168 if (intel_psr_pr_async_video_timing_supported(intel_dp)) 3169 as_sdp->coasting_vtotal = crtc_state->vrr.vmax; 3170 } 3171 3172 static void intel_dp_compute_vsc_sdp(struct intel_dp *intel_dp, 3173 struct intel_crtc_state *crtc_state, 3174 const struct drm_connector_state *conn_state) 3175 { 3176 struct drm_dp_vsc_sdp *vsc; 3177 3178 if (!intel_dp_needs_vsc_colorimetry(crtc_state, conn_state) && 3179 !crtc_state->has_psr) 3180 return; 3181 3182 vsc = &crtc_state->infoframes.vsc; 3183 3184 crtc_state->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_VSC); 3185 vsc->sdp_type = DP_SDP_VSC; 3186 3187 if (intel_dp_needs_vsc_colorimetry(crtc_state, conn_state)) { 3188 intel_dp_compute_vsc_colorimetry(crtc_state, conn_state, 3189 vsc); 3190 } else if (crtc_state->has_panel_replay) { 3191 /* 3192 * [Panel Replay without colorimetry info] 3193 * Prepare VSC Header for SU as per DP 2.0 spec, Table 2-223 3194 * VSC SDP supporting 3D stereo + Panel Replay. 3195 */ 3196 vsc->revision = 0x6; 3197 vsc->length = 0x10; 3198 } else if (crtc_state->has_sel_update) { 3199 /* 3200 * [PSR2 without colorimetry] 3201 * Prepare VSC Header for SU as per eDP 1.4 spec, Table 6-11 3202 * 3D stereo + PSR/PSR2 + Y-coordinate. 3203 */ 3204 vsc->revision = 0x4; 3205 vsc->length = 0xe; 3206 } else { 3207 /* 3208 * [PSR1] 3209 * Prepare VSC Header for SU as per DP 1.4 spec, Table 2-118 3210 * VSC SDP supporting 3D stereo + PSR (applies to eDP v1.3 or 3211 * higher). 3212 */ 3213 vsc->revision = 0x2; 3214 vsc->length = 0x8; 3215 } 3216 } 3217 3218 bool 3219 intel_dp_in_hdr_mode(const struct drm_connector_state *conn_state) 3220 { 3221 struct hdr_output_metadata *hdr_metadata; 3222 3223 if (!conn_state->hdr_output_metadata) 3224 return false; 3225 3226 hdr_metadata = conn_state->hdr_output_metadata->data; 3227 3228 return hdr_metadata->hdmi_metadata_type1.eotf == HDMI_EOTF_SMPTE_ST2084; 3229 } 3230 3231 static void 3232 intel_dp_compute_hdr_metadata_infoframe_sdp(struct intel_dp *intel_dp, 3233 struct intel_crtc_state *crtc_state, 3234 const struct drm_connector_state *conn_state) 3235 { 3236 struct intel_display *display = to_intel_display(intel_dp); 3237 int ret; 3238 struct hdmi_drm_infoframe *drm_infoframe = &crtc_state->infoframes.drm.drm; 3239 3240 if (!conn_state->hdr_output_metadata) 3241 return; 3242 3243 ret = drm_hdmi_infoframe_set_hdr_metadata(drm_infoframe, conn_state); 3244 3245 if (ret) { 3246 drm_dbg_kms(display->drm, 3247 "couldn't set HDR metadata in infoframe\n"); 3248 return; 3249 } 3250 3251 crtc_state->infoframes.enable |= 3252 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA); 3253 } 3254 3255 static bool can_enable_drrs(struct intel_connector *connector, 3256 const struct intel_crtc_state *pipe_config, 3257 const struct drm_display_mode *downclock_mode) 3258 { 3259 struct intel_display *display = to_intel_display(connector); 3260 3261 if (pipe_config->vrr.enable) 3262 return false; 3263 3264 /* 3265 * DRRS and PSR can't be enable together, so giving preference to PSR 3266 * as it allows more power-savings by complete shutting down display, 3267 * so to guarantee this, intel_drrs_compute_config() must be called 3268 * after intel_psr_compute_config(). 3269 */ 3270 if (pipe_config->has_psr) 3271 return false; 3272 3273 /* FIXME missing FDI M2/N2 etc. */ 3274 if (pipe_config->has_pch_encoder) 3275 return false; 3276 3277 if (!intel_cpu_transcoder_has_drrs(display, pipe_config->cpu_transcoder)) 3278 return false; 3279 3280 return downclock_mode && 3281 intel_panel_drrs_type(connector) == DRRS_TYPE_SEAMLESS; 3282 } 3283 3284 static void 3285 intel_dp_drrs_compute_config(struct intel_connector *connector, 3286 struct intel_crtc_state *pipe_config, 3287 int link_bpp_x16) 3288 { 3289 struct intel_display *display = to_intel_display(connector); 3290 const struct drm_display_mode *downclock_mode = 3291 intel_panel_downclock_mode(connector, &pipe_config->hw.adjusted_mode); 3292 int pixel_clock; 3293 3294 /* 3295 * FIXME all joined pipes share the same transcoder. 3296 * Need to account for that when updating M/N live. 3297 */ 3298 if (has_seamless_m_n(connector) && !pipe_config->joiner_pipes) 3299 pipe_config->update_m_n = true; 3300 3301 if (!can_enable_drrs(connector, pipe_config, downclock_mode)) { 3302 if (intel_cpu_transcoder_has_m2_n2(display, pipe_config->cpu_transcoder)) 3303 intel_zero_m_n(&pipe_config->dp_m2_n2); 3304 return; 3305 } 3306 3307 if (display->platform.ironlake || display->platform.sandybridge || 3308 display->platform.ivybridge) 3309 pipe_config->msa_timing_delay = connector->panel.vbt.edp.drrs_msa_timing_delay; 3310 3311 pipe_config->has_drrs = true; 3312 3313 pixel_clock = downclock_mode->clock; 3314 if (pipe_config->splitter.enable) 3315 pixel_clock /= pipe_config->splitter.link_count; 3316 3317 intel_link_compute_m_n(link_bpp_x16, pipe_config->lane_count, pixel_clock, 3318 pipe_config->port_clock, 3319 intel_dp_bw_fec_overhead(pipe_config->fec_enable), 3320 &pipe_config->dp_m2_n2); 3321 3322 /* FIXME: abstract this better */ 3323 if (pipe_config->splitter.enable) 3324 pipe_config->dp_m2_n2.data_m *= pipe_config->splitter.link_count; 3325 } 3326 3327 static bool intel_dp_has_audio(struct intel_encoder *encoder, 3328 const struct drm_connector_state *conn_state) 3329 { 3330 struct intel_display *display = to_intel_display(encoder); 3331 const struct intel_digital_connector_state *intel_conn_state = 3332 to_intel_digital_connector_state(conn_state); 3333 struct intel_connector *connector = 3334 to_intel_connector(conn_state->connector); 3335 3336 if (!intel_dp_port_has_audio(display, encoder->port)) 3337 return false; 3338 3339 if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO) 3340 return connector->base.display_info.has_audio; 3341 else 3342 return intel_conn_state->force_audio == HDMI_AUDIO_ON; 3343 } 3344 3345 static int 3346 intel_dp_compute_output_format(struct intel_encoder *encoder, 3347 struct intel_crtc_state *crtc_state, 3348 struct drm_connector_state *conn_state, 3349 bool respect_downstream_limits, 3350 enum intel_output_format sink_format) 3351 { 3352 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3353 struct intel_connector *connector = intel_dp->attached_connector; 3354 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 3355 3356 if (intel_dp_sink_format_valid(connector, adjusted_mode, 3357 sink_format) != MODE_OK) 3358 return -EINVAL; 3359 3360 crtc_state->sink_format = sink_format; 3361 crtc_state->output_format = intel_dp_output_format(connector, crtc_state->sink_format); 3362 3363 return intel_dp_compute_link_config(encoder, crtc_state, conn_state, 3364 respect_downstream_limits); 3365 } 3366 3367 static int 3368 intel_dp_compute_formats(struct intel_encoder *encoder, 3369 struct intel_crtc_state *crtc_state, 3370 struct drm_connector_state *conn_state, 3371 bool respect_downstream_limits) 3372 { 3373 struct intel_display *display = to_intel_display(encoder); 3374 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3375 struct intel_connector *connector = intel_dp->attached_connector; 3376 const struct drm_display_info *info = &connector->base.display_info; 3377 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode; 3378 int ret; 3379 3380 if (drm_mode_is_420_only(info, adjusted_mode)) { 3381 ret = intel_dp_compute_output_format(encoder, crtc_state, conn_state, 3382 respect_downstream_limits, 3383 INTEL_OUTPUT_FORMAT_YCBCR420); 3384 3385 if (ret && !respect_downstream_limits) { 3386 drm_dbg_kms(display->drm, 3387 "YCbCr 4:2:0 mode but YCbCr 4:2:0 output not possible. Falling back to RGB.\n"); 3388 3389 ret = intel_dp_compute_output_format(encoder, crtc_state, conn_state, 3390 respect_downstream_limits, 3391 INTEL_OUTPUT_FORMAT_RGB); 3392 } 3393 } else { 3394 ret = intel_dp_compute_output_format(encoder, crtc_state, conn_state, 3395 respect_downstream_limits, 3396 INTEL_OUTPUT_FORMAT_RGB); 3397 3398 if (ret && drm_mode_is_420_also(info, adjusted_mode)) 3399 ret = intel_dp_compute_output_format(encoder, crtc_state, conn_state, 3400 respect_downstream_limits, 3401 INTEL_OUTPUT_FORMAT_YCBCR420); 3402 } 3403 3404 return ret; 3405 } 3406 3407 void 3408 intel_dp_audio_compute_config(struct intel_encoder *encoder, 3409 struct intel_crtc_state *pipe_config, 3410 struct drm_connector_state *conn_state) 3411 { 3412 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3413 3414 pipe_config->has_audio = 3415 intel_dp_has_audio(encoder, conn_state) && 3416 intel_audio_compute_config(encoder, pipe_config, conn_state); 3417 3418 pipe_config->sdp_split_enable = pipe_config->has_audio && 3419 intel_dp_is_uhbr(pipe_config); 3420 3421 /* 3422 * SDP splitting for UHBR audio requires explicit sink capability in 3423 * SST mode, whereas in MST mode it is inherently supported. 3424 */ 3425 if (pipe_config->sdp_split_enable && 3426 !intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST)) 3427 pipe_config->sdp_split_enable = intel_dp->sst_split_sdp_support; 3428 } 3429 3430 void 3431 intel_dp_queue_modeset_retry_for_link(struct intel_atomic_state *state, 3432 struct intel_encoder *encoder, 3433 const struct intel_crtc_state *crtc_state) 3434 { 3435 struct intel_connector *connector; 3436 struct intel_digital_connector_state *conn_state; 3437 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3438 int i; 3439 3440 if (intel_dp->needs_modeset_retry) 3441 return; 3442 3443 intel_dp->needs_modeset_retry = true; 3444 3445 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 3446 intel_connector_queue_modeset_retry_work(intel_dp->attached_connector); 3447 3448 return; 3449 } 3450 3451 for_each_new_intel_connector_in_state(state, connector, conn_state, i) { 3452 if (!conn_state->base.crtc) 3453 continue; 3454 3455 if (connector->mst.dp == intel_dp) 3456 intel_connector_queue_modeset_retry_work(connector); 3457 } 3458 } 3459 3460 int intel_dp_compute_min_hblank(struct intel_crtc_state *crtc_state, 3461 const struct drm_connector_state *conn_state) 3462 { 3463 struct intel_display *display = to_intel_display(crtc_state); 3464 const struct drm_display_mode *adjusted_mode = 3465 &crtc_state->hw.adjusted_mode; 3466 struct intel_connector *connector = to_intel_connector(conn_state->connector); 3467 int symbol_size = intel_dp_is_uhbr(crtc_state) ? 32 : 8; 3468 /* 3469 * min symbol cycles is 3(BS,VBID, BE) for 128b/132b and 3470 * 5(BS, VBID, MVID, MAUD, BE) for 8b/10b 3471 */ 3472 int min_sym_cycles = intel_dp_is_uhbr(crtc_state) ? 3 : 5; 3473 bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3474 int num_joined_pipes = intel_crtc_num_joined_pipes(crtc_state); 3475 int min_hblank; 3476 int max_lane_count = 4; 3477 int hactive_sym_cycles, htotal_sym_cycles; 3478 int dsc_slices = 0; 3479 int link_bpp_x16; 3480 3481 if (DISPLAY_VER(display) < 30) 3482 return 0; 3483 3484 /* MIN_HBLANK should be set only for 8b/10b MST or for 128b/132b SST/MST */ 3485 if (!is_mst && !intel_dp_is_uhbr(crtc_state)) 3486 return 0; 3487 3488 if (crtc_state->dsc.compression_enable) { 3489 dsc_slices = intel_dp_dsc_get_slice_count(connector, 3490 adjusted_mode->crtc_clock, 3491 adjusted_mode->crtc_hdisplay, 3492 num_joined_pipes); 3493 if (!dsc_slices) { 3494 drm_dbg(display->drm, "failed to calculate dsc slice count\n"); 3495 return -EINVAL; 3496 } 3497 } 3498 3499 if (crtc_state->dsc.compression_enable) 3500 link_bpp_x16 = crtc_state->dsc.compressed_bpp_x16; 3501 else 3502 link_bpp_x16 = intel_dp_output_format_link_bpp_x16(crtc_state->output_format, 3503 crtc_state->pipe_bpp); 3504 3505 /* Calculate min Hblank Link Layer Symbol Cycle Count for 8b/10b MST & 128b/132b */ 3506 hactive_sym_cycles = drm_dp_link_symbol_cycles(max_lane_count, 3507 adjusted_mode->hdisplay, 3508 dsc_slices, 3509 link_bpp_x16, 3510 symbol_size, is_mst); 3511 htotal_sym_cycles = adjusted_mode->htotal * hactive_sym_cycles / 3512 adjusted_mode->hdisplay; 3513 3514 min_hblank = htotal_sym_cycles - hactive_sym_cycles; 3515 /* minimum Hblank calculation: https://groups.vesa.org/wg/DP/document/20494 */ 3516 min_hblank = max(min_hblank, min_sym_cycles); 3517 3518 /* 3519 * adjust the BlankingStart/BlankingEnd framing control from 3520 * the calculated value 3521 */ 3522 min_hblank = min_hblank - 2; 3523 3524 /* 3525 * min_hblank formula is undergoing a change, to avoid underrun use the 3526 * recomended value in spec to compare with the calculated one and use the 3527 * minimum value 3528 */ 3529 if (intel_dp_is_uhbr(crtc_state)) { 3530 /* 3531 * Note: Bspec requires a min_hblank of 2 for YCBCR420 3532 * with compressed bpp 6, but the minimum compressed bpp 3533 * supported by the driver is 8. 3534 */ 3535 drm_WARN_ON(display->drm, 3536 (crtc_state->dsc.compression_enable && 3537 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 3538 crtc_state->dsc.compressed_bpp_x16 < fxp_q4_from_int(8))); 3539 min_hblank = min(3, min_hblank); 3540 } else { 3541 min_hblank = min(10, min_hblank); 3542 } 3543 3544 crtc_state->min_hblank = min_hblank; 3545 3546 return 0; 3547 } 3548 3549 int 3550 intel_dp_compute_config(struct intel_atomic_state *state, 3551 struct intel_encoder *encoder, 3552 struct intel_crtc_state *pipe_config, 3553 struct drm_connector_state *conn_state) 3554 { 3555 struct intel_display *display = to_intel_display(encoder); 3556 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode; 3557 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3558 struct intel_connector *connector = intel_dp->attached_connector; 3559 int ret = 0, link_bpp_x16; 3560 3561 if (intel_dp_is_edp(intel_dp)) { 3562 ret = intel_panel_compute_config(state, pipe_config, connector); 3563 if (ret) 3564 return ret; 3565 } 3566 3567 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN) 3568 return -EINVAL; 3569 3570 if (!connector->base.interlace_allowed && 3571 adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) 3572 return -EINVAL; 3573 3574 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) 3575 return -EINVAL; 3576 3577 if (intel_dp_hdisplay_bad(display, adjusted_mode->crtc_hdisplay)) 3578 return -EINVAL; 3579 3580 /* 3581 * Try to respect downstream TMDS clock limits first, if 3582 * that fails assume the user might know something we don't. 3583 */ 3584 ret = intel_dp_compute_formats(encoder, pipe_config, conn_state, true); 3585 if (ret) 3586 ret = intel_dp_compute_formats(encoder, pipe_config, conn_state, false); 3587 if (ret) 3588 return ret; 3589 3590 ret = intel_pfit_compute_config(pipe_config, conn_state); 3591 if (ret) 3592 return ret; 3593 3594 pipe_config->limited_color_range = 3595 intel_dp_limited_color_range(pipe_config, conn_state); 3596 3597 if (intel_dp_is_uhbr(pipe_config)) { 3598 /* 128b/132b SST also needs this */ 3599 pipe_config->mst_master_transcoder = pipe_config->cpu_transcoder; 3600 } else { 3601 pipe_config->enhanced_framing = 3602 drm_dp_enhanced_frame_cap(intel_dp->dpcd); 3603 } 3604 3605 if (pipe_config->dsc.compression_enable) 3606 link_bpp_x16 = pipe_config->dsc.compressed_bpp_x16; 3607 else 3608 link_bpp_x16 = intel_dp_output_format_link_bpp_x16(pipe_config->output_format, 3609 pipe_config->pipe_bpp); 3610 3611 if (intel_dp->mso_link_count) { 3612 int n = intel_dp->mso_link_count; 3613 int overlap = intel_dp->mso_pixel_overlap; 3614 3615 pipe_config->splitter.enable = true; 3616 pipe_config->splitter.link_count = n; 3617 pipe_config->splitter.pixel_overlap = overlap; 3618 3619 drm_dbg_kms(display->drm, 3620 "MSO link count %d, pixel overlap %d\n", 3621 n, overlap); 3622 3623 adjusted_mode->crtc_hdisplay = adjusted_mode->crtc_hdisplay / n + overlap; 3624 adjusted_mode->crtc_hblank_start = adjusted_mode->crtc_hblank_start / n + overlap; 3625 adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_end / n + overlap; 3626 adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hsync_start / n + overlap; 3627 adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_end / n + overlap; 3628 adjusted_mode->crtc_htotal = adjusted_mode->crtc_htotal / n + overlap; 3629 adjusted_mode->crtc_clock /= n; 3630 } 3631 3632 intel_dp_audio_compute_config(encoder, pipe_config, conn_state); 3633 3634 if (!intel_dp_is_uhbr(pipe_config)) { 3635 intel_link_compute_m_n(link_bpp_x16, 3636 pipe_config->lane_count, 3637 adjusted_mode->crtc_clock, 3638 pipe_config->port_clock, 3639 intel_dp_bw_fec_overhead(pipe_config->fec_enable), 3640 &pipe_config->dp_m_n); 3641 } 3642 3643 ret = intel_dp_compute_min_hblank(pipe_config, conn_state); 3644 if (ret) 3645 return ret; 3646 3647 /* FIXME: abstract this better */ 3648 if (pipe_config->splitter.enable) 3649 pipe_config->dp_m_n.data_m *= pipe_config->splitter.link_count; 3650 3651 intel_vrr_compute_config(pipe_config, conn_state); 3652 intel_psr_compute_config(intel_dp, pipe_config, conn_state); 3653 intel_dp_compute_as_sdp(intel_dp, pipe_config); 3654 intel_alpm_lobf_compute_config(intel_dp, pipe_config, conn_state); 3655 intel_dp_drrs_compute_config(connector, pipe_config, link_bpp_x16); 3656 intel_dp_compute_vsc_sdp(intel_dp, pipe_config, conn_state); 3657 intel_dp_compute_hdr_metadata_infoframe_sdp(intel_dp, pipe_config, conn_state); 3658 3659 return intel_dp_tunnel_atomic_compute_stream_bw(state, intel_dp, connector, 3660 pipe_config); 3661 } 3662 3663 void intel_dp_set_link_params(struct intel_dp *intel_dp, 3664 int link_rate, int lane_count) 3665 { 3666 memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set)); 3667 intel_dp->link.active = false; 3668 intel_dp->needs_modeset_retry = false; 3669 intel_dp->link_rate = link_rate; 3670 intel_dp->lane_count = lane_count; 3671 } 3672 3673 void intel_dp_reset_link_params(struct intel_dp *intel_dp) 3674 { 3675 /* 3676 * TODO: Remove the following reset of link capabilities, as 3677 * this isn't needed after intel_dp_link_caps_update(reset=true) 3678 * was called. 3679 */ 3680 intel_dp_link_caps_reset(intel_dp->link.caps); 3681 intel_dp_tunnel_uhbr_lanes_wa_apply(intel_dp); 3682 3683 intel_dp->link.mst_probed_lane_count = 0; 3684 intel_dp->link.mst_probed_rate = 0; 3685 intel_dp_link_training_reset(intel_dp->link.training); 3686 } 3687 3688 /* Enable backlight PWM and backlight PP control. */ 3689 void intel_edp_backlight_on(const struct intel_crtc_state *crtc_state, 3690 const struct drm_connector_state *conn_state) 3691 { 3692 struct intel_display *display = to_intel_display(crtc_state); 3693 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(conn_state->best_encoder)); 3694 3695 if (!intel_dp_is_edp(intel_dp)) 3696 return; 3697 3698 drm_dbg_kms(display->drm, "\n"); 3699 3700 intel_backlight_enable(crtc_state, conn_state); 3701 intel_pps_backlight_on(intel_dp); 3702 } 3703 3704 /* Disable backlight PP control and backlight PWM. */ 3705 void intel_edp_backlight_off(const struct drm_connector_state *old_conn_state) 3706 { 3707 struct intel_dp *intel_dp = enc_to_intel_dp(to_intel_encoder(old_conn_state->best_encoder)); 3708 struct intel_display *display = to_intel_display(intel_dp); 3709 3710 if (!intel_dp_is_edp(intel_dp)) 3711 return; 3712 3713 drm_dbg_kms(display->drm, "\n"); 3714 3715 intel_pps_backlight_off(intel_dp); 3716 intel_backlight_disable(old_conn_state); 3717 } 3718 3719 static bool downstream_hpd_needs_d0(struct intel_dp *intel_dp) 3720 { 3721 /* 3722 * DPCD 1.2+ should support BRANCH_DEVICE_CTRL, and thus 3723 * be capable of signalling downstream hpd with a long pulse. 3724 * Whether or not that means D3 is safe to use is not clear, 3725 * but let's assume so until proven otherwise. 3726 * 3727 * FIXME should really check all downstream ports... 3728 */ 3729 return intel_dp->dpcd[DP_DPCD_REV] == 0x11 && 3730 drm_dp_is_branch(intel_dp->dpcd) && 3731 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD; 3732 } 3733 3734 static int 3735 write_dsc_decompression_flag(struct drm_dp_aux *aux, u8 flag, bool set) 3736 { 3737 int err; 3738 u8 val; 3739 3740 err = drm_dp_dpcd_readb(aux, DP_DSC_ENABLE, &val); 3741 if (err < 0) 3742 return err; 3743 3744 if (set) 3745 val |= flag; 3746 else 3747 val &= ~flag; 3748 3749 return drm_dp_dpcd_writeb(aux, DP_DSC_ENABLE, val); 3750 } 3751 3752 static void 3753 intel_dp_sink_set_dsc_decompression(struct intel_connector *connector, 3754 bool enable) 3755 { 3756 struct intel_display *display = to_intel_display(connector); 3757 3758 if (write_dsc_decompression_flag(connector->dp.dsc_decompression_aux, 3759 DP_DECOMPRESSION_EN, enable) < 0) 3760 drm_dbg_kms(display->drm, 3761 "Failed to %s sink decompression state\n", 3762 str_enable_disable(enable)); 3763 } 3764 3765 static void 3766 intel_dp_sink_set_dsc_passthrough(const struct intel_connector *connector, 3767 bool enable) 3768 { 3769 struct intel_display *display = to_intel_display(connector); 3770 struct drm_dp_aux *aux = connector->mst.port ? 3771 connector->mst.port->passthrough_aux : NULL; 3772 3773 if (!aux) 3774 return; 3775 3776 if (write_dsc_decompression_flag(aux, 3777 DP_DSC_PASSTHROUGH_EN, enable) < 0) 3778 drm_dbg_kms(display->drm, 3779 "Failed to %s sink compression passthrough state\n", 3780 str_enable_disable(enable)); 3781 } 3782 3783 static int intel_dp_dsc_aux_ref_count(struct intel_atomic_state *state, 3784 const struct intel_connector *connector, 3785 bool for_get_ref) 3786 { 3787 struct intel_display *display = to_intel_display(state); 3788 struct drm_connector *_connector_iter; 3789 struct drm_connector_state *old_conn_state; 3790 struct drm_connector_state *new_conn_state; 3791 int ref_count = 0; 3792 int i; 3793 3794 /* 3795 * On SST the decompression AUX device won't be shared, each connector 3796 * uses for this its own AUX targeting the sink device. 3797 */ 3798 if (!connector->mst.dp) 3799 return connector->dp.dsc_decompression_enabled ? 1 : 0; 3800 3801 for_each_oldnew_connector_in_state(&state->base, _connector_iter, 3802 old_conn_state, new_conn_state, i) { 3803 const struct intel_connector * 3804 connector_iter = to_intel_connector(_connector_iter); 3805 3806 if (connector_iter->mst.dp != connector->mst.dp) 3807 continue; 3808 3809 if (!connector_iter->dp.dsc_decompression_enabled) 3810 continue; 3811 3812 drm_WARN_ON(display->drm, 3813 (for_get_ref && !new_conn_state->crtc) || 3814 (!for_get_ref && !old_conn_state->crtc)); 3815 3816 if (connector_iter->dp.dsc_decompression_aux == 3817 connector->dp.dsc_decompression_aux) 3818 ref_count++; 3819 } 3820 3821 return ref_count; 3822 } 3823 3824 static bool intel_dp_dsc_aux_get_ref(struct intel_atomic_state *state, 3825 struct intel_connector *connector) 3826 { 3827 bool ret = intel_dp_dsc_aux_ref_count(state, connector, true) == 0; 3828 3829 connector->dp.dsc_decompression_enabled = true; 3830 3831 return ret; 3832 } 3833 3834 static bool intel_dp_dsc_aux_put_ref(struct intel_atomic_state *state, 3835 struct intel_connector *connector) 3836 { 3837 connector->dp.dsc_decompression_enabled = false; 3838 3839 return intel_dp_dsc_aux_ref_count(state, connector, false) == 0; 3840 } 3841 3842 /** 3843 * intel_dp_sink_enable_decompression - Enable DSC decompression in sink/last branch device 3844 * @state: atomic state 3845 * @connector: connector to enable the decompression for 3846 * @new_crtc_state: new state for the CRTC driving @connector 3847 * 3848 * Enable the DSC decompression if required in the %DP_DSC_ENABLE DPCD 3849 * register of the appropriate sink/branch device. On SST this is always the 3850 * sink device, whereas on MST based on each device's DSC capabilities it's 3851 * either the last branch device (enabling decompression in it) or both the 3852 * last branch device (enabling passthrough in it) and the sink device 3853 * (enabling decompression in it). 3854 */ 3855 void intel_dp_sink_enable_decompression(struct intel_atomic_state *state, 3856 struct intel_connector *connector, 3857 const struct intel_crtc_state *new_crtc_state) 3858 { 3859 struct intel_display *display = to_intel_display(state); 3860 3861 if (!new_crtc_state->dsc.compression_enable) 3862 return; 3863 3864 if (drm_WARN_ON(display->drm, 3865 !connector->dp.dsc_decompression_aux || 3866 connector->dp.dsc_decompression_enabled)) 3867 return; 3868 3869 if (!intel_dp_dsc_aux_get_ref(state, connector)) 3870 return; 3871 3872 intel_dp_sink_set_dsc_passthrough(connector, true); 3873 intel_dp_sink_set_dsc_decompression(connector, true); 3874 } 3875 3876 /** 3877 * intel_dp_sink_disable_decompression - Disable DSC decompression in sink/last branch device 3878 * @state: atomic state 3879 * @connector: connector to disable the decompression for 3880 * @old_crtc_state: old state for the CRTC driving @connector 3881 * 3882 * Disable the DSC decompression if required in the %DP_DSC_ENABLE DPCD 3883 * register of the appropriate sink/branch device, corresponding to the 3884 * sequence in intel_dp_sink_enable_decompression(). 3885 */ 3886 void intel_dp_sink_disable_decompression(struct intel_atomic_state *state, 3887 struct intel_connector *connector, 3888 const struct intel_crtc_state *old_crtc_state) 3889 { 3890 struct intel_display *display = to_intel_display(state); 3891 3892 if (!old_crtc_state->dsc.compression_enable) 3893 return; 3894 3895 if (drm_WARN_ON(display->drm, 3896 !connector->dp.dsc_decompression_aux || 3897 !connector->dp.dsc_decompression_enabled)) 3898 return; 3899 3900 if (!intel_dp_dsc_aux_put_ref(state, connector)) 3901 return; 3902 3903 intel_dp_sink_set_dsc_decompression(connector, false); 3904 intel_dp_sink_set_dsc_passthrough(connector, false); 3905 } 3906 3907 static void 3908 intel_dp_init_source_oui(struct intel_dp *intel_dp) 3909 { 3910 struct intel_display *display = to_intel_display(intel_dp); 3911 u8 oui[] = { 0x00, 0xaa, 0x01 }; 3912 u8 buf[3] = {}; 3913 3914 if (READ_ONCE(intel_dp->oui_valid)) 3915 return; 3916 3917 WRITE_ONCE(intel_dp->oui_valid, true); 3918 3919 /* 3920 * During driver init, we want to be careful and avoid changing the source OUI if it's 3921 * already set to what we want, so as to avoid clearing any state by accident 3922 */ 3923 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SOURCE_OUI, buf, sizeof(buf)) < 0) 3924 drm_dbg_kms(display->drm, "Failed to read source OUI\n"); 3925 3926 if (memcmp(oui, buf, sizeof(oui)) == 0) { 3927 /* Assume the OUI was written now. */ 3928 intel_dp->last_oui_write = jiffies; 3929 return; 3930 } 3931 3932 if (drm_dp_dpcd_write(&intel_dp->aux, DP_SOURCE_OUI, oui, sizeof(oui)) < 0) { 3933 drm_dbg_kms(display->drm, "Failed to write source OUI\n"); 3934 WRITE_ONCE(intel_dp->oui_valid, false); 3935 } 3936 3937 intel_dp->last_oui_write = jiffies; 3938 } 3939 3940 void intel_dp_invalidate_source_oui(struct intel_dp *intel_dp) 3941 { 3942 WRITE_ONCE(intel_dp->oui_valid, false); 3943 } 3944 3945 void intel_dp_wait_source_oui(struct intel_dp *intel_dp) 3946 { 3947 struct intel_display *display = to_intel_display(intel_dp); 3948 struct intel_connector *connector = intel_dp->attached_connector; 3949 3950 drm_dbg_kms(display->drm, 3951 "[CONNECTOR:%d:%s] Performing OUI wait (%u ms)\n", 3952 connector->base.base.id, connector->base.name, 3953 connector->panel.vbt.backlight.hdr_dpcd_refresh_timeout); 3954 3955 wait_remaining_ms_from_jiffies(intel_dp->last_oui_write, 3956 connector->panel.vbt.backlight.hdr_dpcd_refresh_timeout); 3957 } 3958 3959 /* If the device supports it, try to set the power state appropriately */ 3960 void intel_dp_set_power(struct intel_dp *intel_dp, u8 mode) 3961 { 3962 struct intel_display *display = to_intel_display(intel_dp); 3963 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 3964 int ret, i; 3965 3966 /* Should have a valid DPCD by this point */ 3967 if (intel_dp->dpcd[DP_DPCD_REV] < 0x11) 3968 return; 3969 3970 if (mode != DP_SET_POWER_D0) { 3971 if (downstream_hpd_needs_d0(intel_dp)) 3972 return; 3973 3974 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, mode); 3975 } else { 3976 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 3977 3978 intel_lspcon_resume(dig_port); 3979 3980 /* Write the source OUI as early as possible */ 3981 intel_dp_init_source_oui(intel_dp); 3982 3983 /* 3984 * When turning on, we need to retry for 1ms to give the sink 3985 * time to wake up. 3986 */ 3987 for (i = 0; i < 3; i++) { 3988 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, mode); 3989 if (ret == 1) 3990 break; 3991 msleep(1); 3992 } 3993 3994 if (ret == 1 && intel_lspcon_active(dig_port)) 3995 intel_lspcon_wait_pcon_mode(dig_port); 3996 } 3997 3998 if (ret != 1) 3999 drm_dbg_kms(display->drm, 4000 "[ENCODER:%d:%s] Set power to %s failed\n", 4001 encoder->base.base.id, encoder->base.name, 4002 mode == DP_SET_POWER_D0 ? "D0" : "D3"); 4003 } 4004 4005 static bool 4006 intel_dp_get_dpcd(struct intel_dp *intel_dp); 4007 4008 /** 4009 * intel_dp_sync_state - sync the encoder state during init/resume 4010 * @encoder: intel encoder to sync 4011 * @crtc_state: state for the CRTC connected to the encoder 4012 * 4013 * Sync any state stored in the encoder wrt. HW state during driver init 4014 * and system resume. 4015 */ 4016 void intel_dp_sync_state(struct intel_encoder *encoder, 4017 const struct intel_crtc_state *crtc_state) 4018 { 4019 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4020 bool dpcd_updated = false; 4021 4022 /* 4023 * Don't clobber DPCD if it's been already read out during output 4024 * setup (eDP) or detect. 4025 */ 4026 if (crtc_state && intel_dp->dpcd[DP_DPCD_REV] == 0) { 4027 intel_dp_get_dpcd(intel_dp); 4028 dpcd_updated = true; 4029 } 4030 4031 intel_dp_tunnel_resume(intel_dp, crtc_state, dpcd_updated); 4032 4033 if (crtc_state) { 4034 intel_dp_reset_link_params(intel_dp); 4035 intel_dp_set_link_params(intel_dp, crtc_state->port_clock, crtc_state->lane_count); 4036 intel_dp->link.active = true; 4037 } 4038 } 4039 4040 bool intel_dp_initial_fastset_check(struct intel_encoder *encoder, 4041 struct intel_crtc_state *crtc_state) 4042 { 4043 struct intel_display *display = to_intel_display(encoder); 4044 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4045 bool fastset = true; 4046 4047 /* 4048 * If BIOS has set an unsupported or non-standard link rate for some 4049 * reason force an encoder recompute and full modeset. 4050 */ 4051 if (intel_dp_rate_index(intel_dp->source_rates, intel_dp->num_source_rates, 4052 crtc_state->port_clock) < 0) { 4053 drm_dbg_kms(display->drm, 4054 "[ENCODER:%d:%s] Forcing full modeset due to unsupported link rate\n", 4055 encoder->base.base.id, encoder->base.name); 4056 crtc_state->uapi.connectors_changed = true; 4057 fastset = false; 4058 } 4059 4060 /* 4061 * FIXME hack to force full modeset when DSC is being used. 4062 * 4063 * As long as we do not have full state readout and config comparison 4064 * of crtc_state->dsc, we have no way to ensure reliable fastset. 4065 * Remove once we have readout for DSC. 4066 */ 4067 if (crtc_state->dsc.compression_enable) { 4068 drm_dbg_kms(display->drm, 4069 "[ENCODER:%d:%s] Forcing full modeset due to DSC being enabled\n", 4070 encoder->base.base.id, encoder->base.name); 4071 crtc_state->uapi.mode_changed = true; 4072 fastset = false; 4073 } 4074 4075 if (CAN_PANEL_REPLAY(intel_dp)) { 4076 drm_dbg_kms(display->drm, 4077 "[ENCODER:%d:%s] Forcing full modeset to compute panel replay state\n", 4078 encoder->base.base.id, encoder->base.name); 4079 crtc_state->uapi.mode_changed = true; 4080 fastset = false; 4081 } 4082 4083 return fastset; 4084 } 4085 4086 static void intel_dp_get_pcon_dsc_cap(struct intel_dp *intel_dp) 4087 { 4088 struct intel_display *display = to_intel_display(intel_dp); 4089 4090 /* Clear the cached register set to avoid using stale values */ 4091 4092 memset(intel_dp->pcon_dsc_dpcd, 0, sizeof(intel_dp->pcon_dsc_dpcd)); 4093 4094 if (!drm_dp_is_branch(intel_dp->dpcd)) 4095 return; 4096 4097 if (drm_dp_dpcd_read(&intel_dp->aux, DP_PCON_DSC_ENCODER, 4098 intel_dp->pcon_dsc_dpcd, 4099 sizeof(intel_dp->pcon_dsc_dpcd)) < 0) 4100 drm_err(display->drm, "Failed to read DPCD register 0x%x\n", 4101 DP_PCON_DSC_ENCODER); 4102 4103 drm_dbg_kms(display->drm, "PCON ENCODER DSC DPCD: %*ph\n", 4104 (int)sizeof(intel_dp->pcon_dsc_dpcd), intel_dp->pcon_dsc_dpcd); 4105 } 4106 4107 static int intel_dp_pcon_get_frl_mask(u8 frl_bw_mask) 4108 { 4109 static const int bw_gbps[] = {9, 18, 24, 32, 40, 48}; 4110 int i; 4111 4112 for (i = ARRAY_SIZE(bw_gbps) - 1; i >= 0; i--) { 4113 if (frl_bw_mask & (1 << i)) 4114 return bw_gbps[i]; 4115 } 4116 return 0; 4117 } 4118 4119 static int intel_dp_pcon_set_frl_mask(int max_frl) 4120 { 4121 switch (max_frl) { 4122 case 48: 4123 return DP_PCON_FRL_BW_MASK_48GBPS; 4124 case 40: 4125 return DP_PCON_FRL_BW_MASK_40GBPS; 4126 case 32: 4127 return DP_PCON_FRL_BW_MASK_32GBPS; 4128 case 24: 4129 return DP_PCON_FRL_BW_MASK_24GBPS; 4130 case 18: 4131 return DP_PCON_FRL_BW_MASK_18GBPS; 4132 case 9: 4133 return DP_PCON_FRL_BW_MASK_9GBPS; 4134 } 4135 4136 return 0; 4137 } 4138 4139 static int intel_dp_hdmi_sink_max_frl(struct intel_dp *intel_dp) 4140 { 4141 struct intel_connector *connector = intel_dp->attached_connector; 4142 const struct drm_display_info *info = &connector->base.display_info; 4143 int max_frl_rate; 4144 int max_lanes, rate_per_lane; 4145 int max_dsc_lanes, dsc_rate_per_lane; 4146 4147 max_lanes = info->hdmi.max_lanes; 4148 rate_per_lane = info->hdmi.max_frl_rate_per_lane; 4149 max_frl_rate = max_lanes * rate_per_lane; 4150 4151 /* 4152 * The sink's DSC max FRL rate only applies to compressed video 4153 * transport, which requires a DSC 1.2 encoder in the PCON. Without 4154 * one the HDMI link always carries uncompressed video, for which 4155 * the regular max FRL rate is the limit. 4156 */ 4157 if (drm_dp_pcon_enc_is_dsc_1_2(intel_dp->pcon_dsc_dpcd) && 4158 info->hdmi.dsc_cap.v_1p2) { 4159 max_dsc_lanes = info->hdmi.dsc_cap.max_lanes; 4160 dsc_rate_per_lane = info->hdmi.dsc_cap.max_frl_rate_per_lane; 4161 if (max_dsc_lanes && dsc_rate_per_lane) 4162 max_frl_rate = min(max_frl_rate, max_dsc_lanes * dsc_rate_per_lane); 4163 } 4164 4165 return max_frl_rate; 4166 } 4167 4168 static bool 4169 intel_dp_pcon_is_frl_trained(struct intel_dp *intel_dp, 4170 u8 max_frl_bw_mask, u8 *frl_trained_mask) 4171 { 4172 if (drm_dp_pcon_hdmi_link_active(&intel_dp->aux) && 4173 drm_dp_pcon_hdmi_link_mode(&intel_dp->aux, frl_trained_mask) == DP_PCON_HDMI_MODE_FRL && 4174 *frl_trained_mask >= max_frl_bw_mask) 4175 return true; 4176 4177 return false; 4178 } 4179 4180 static int intel_dp_pcon_start_frl_training(struct intel_dp *intel_dp) 4181 { 4182 struct intel_display *display = to_intel_display(intel_dp); 4183 #define TIMEOUT_FRL_READY_MS 500 4184 #define TIMEOUT_HDMI_LINK_ACTIVE_MS 1000 4185 int max_frl_bw, max_pcon_frl_bw, max_edid_frl_bw, ret; 4186 u8 max_frl_bw_mask = 0, frl_trained_mask; 4187 bool is_active; 4188 4189 max_pcon_frl_bw = intel_dp->dfp.pcon_max_frl_bw; 4190 drm_dbg(display->drm, "PCON max rate = %d Gbps\n", max_pcon_frl_bw); 4191 4192 max_edid_frl_bw = intel_dp_hdmi_sink_max_frl(intel_dp); 4193 drm_dbg(display->drm, "Sink max rate from EDID = %d Gbps\n", 4194 max_edid_frl_bw); 4195 4196 max_frl_bw = min(max_edid_frl_bw, max_pcon_frl_bw); 4197 4198 if (max_frl_bw <= 0) 4199 return -EINVAL; 4200 4201 max_frl_bw_mask = intel_dp_pcon_set_frl_mask(max_frl_bw); 4202 drm_dbg(display->drm, "MAX_FRL_BW_MASK = %u\n", max_frl_bw_mask); 4203 4204 if (intel_dp_pcon_is_frl_trained(intel_dp, max_frl_bw_mask, &frl_trained_mask)) 4205 goto frl_trained; 4206 4207 ret = drm_dp_pcon_frl_prepare(&intel_dp->aux, false); 4208 if (ret < 0) 4209 return ret; 4210 /* Wait for PCON to be FRL Ready */ 4211 ret = poll_timeout_us(is_active = drm_dp_pcon_is_frl_ready(&intel_dp->aux), 4212 is_active, 4213 1000, TIMEOUT_FRL_READY_MS * 1000, false); 4214 if (ret) 4215 return ret; 4216 4217 ret = drm_dp_pcon_frl_configure_1(&intel_dp->aux, max_frl_bw, 4218 DP_PCON_ENABLE_SEQUENTIAL_LINK); 4219 if (ret < 0) 4220 return ret; 4221 ret = drm_dp_pcon_frl_configure_2(&intel_dp->aux, max_frl_bw_mask, 4222 DP_PCON_FRL_LINK_TRAIN_NORMAL); 4223 if (ret < 0) 4224 return ret; 4225 ret = drm_dp_pcon_frl_enable(&intel_dp->aux); 4226 if (ret < 0) 4227 return ret; 4228 /* 4229 * Wait for FRL to be completed 4230 * Check if the HDMI Link is up and active. 4231 */ 4232 ret = poll_timeout_us(is_active = intel_dp_pcon_is_frl_trained(intel_dp, max_frl_bw_mask, &frl_trained_mask), 4233 is_active, 4234 1000, TIMEOUT_HDMI_LINK_ACTIVE_MS * 1000, false); 4235 if (ret) 4236 return ret; 4237 4238 frl_trained: 4239 drm_dbg(display->drm, "FRL_TRAINED_MASK = %u\n", frl_trained_mask); 4240 intel_dp->frl.trained_rate_gbps = intel_dp_pcon_get_frl_mask(frl_trained_mask); 4241 intel_dp->frl.is_trained = true; 4242 drm_dbg(display->drm, "FRL trained with : %d Gbps\n", 4243 intel_dp->frl.trained_rate_gbps); 4244 4245 return 0; 4246 } 4247 4248 static bool intel_dp_is_hdmi_2_1_sink(struct intel_dp *intel_dp) 4249 { 4250 if (drm_dp_is_branch(intel_dp->dpcd) && 4251 intel_dp_has_hdmi_sink(intel_dp) && 4252 intel_dp_hdmi_sink_max_frl(intel_dp) > 0) 4253 return true; 4254 4255 return false; 4256 } 4257 4258 static 4259 int intel_dp_pcon_set_tmds_mode(struct intel_dp *intel_dp) 4260 { 4261 int ret; 4262 u8 buf = 0; 4263 4264 /* Set PCON source control mode */ 4265 buf |= DP_PCON_ENABLE_SOURCE_CTL_MODE; 4266 4267 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf); 4268 if (ret < 0) 4269 return ret; 4270 4271 /* Set HDMI LINK ENABLE */ 4272 buf |= DP_PCON_ENABLE_HDMI_LINK; 4273 ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf); 4274 if (ret < 0) 4275 return ret; 4276 4277 return 0; 4278 } 4279 4280 void intel_dp_check_frl_training(struct intel_dp *intel_dp) 4281 { 4282 struct intel_display *display = to_intel_display(intel_dp); 4283 4284 /* 4285 * Always go for FRL training if: 4286 * -PCON supports SRC_CTL_MODE (VESA DP2.0-HDMI2.1 PCON Spec Draft-1 Sec-7) 4287 * -sink is HDMI2.1 4288 */ 4289 if (!(intel_dp->downstream_ports[2] & DP_PCON_SOURCE_CTL_MODE) || 4290 !intel_dp_is_hdmi_2_1_sink(intel_dp) || 4291 intel_dp->frl.is_trained) 4292 return; 4293 4294 if (intel_dp_pcon_start_frl_training(intel_dp) < 0) { 4295 int ret, mode; 4296 4297 drm_dbg(display->drm, 4298 "Couldn't set FRL mode, continuing with TMDS mode\n"); 4299 ret = intel_dp_pcon_set_tmds_mode(intel_dp); 4300 mode = drm_dp_pcon_hdmi_link_mode(&intel_dp->aux, NULL); 4301 4302 if (ret < 0 || mode != DP_PCON_HDMI_MODE_TMDS) 4303 drm_dbg(display->drm, 4304 "Issue with PCON, cannot set TMDS mode\n"); 4305 } else { 4306 drm_dbg(display->drm, "FRL training Completed\n"); 4307 } 4308 } 4309 4310 static int 4311 intel_dp_pcon_dsc_enc_slice_height(const struct intel_crtc_state *crtc_state) 4312 { 4313 int vactive = crtc_state->hw.adjusted_mode.vdisplay; 4314 4315 return intel_hdmi_dsc_get_slice_height(vactive); 4316 } 4317 4318 static int 4319 intel_dp_pcon_dsc_enc_slices(struct intel_dp *intel_dp, 4320 const struct intel_crtc_state *crtc_state) 4321 { 4322 struct intel_connector *connector = intel_dp->attached_connector; 4323 const struct drm_display_info *info = &connector->base.display_info; 4324 int hdmi_throughput = info->hdmi.dsc_cap.clk_per_slice; 4325 int hdmi_max_slices = info->hdmi.dsc_cap.max_slices; 4326 int pcon_max_slices = drm_dp_pcon_dsc_max_slices(intel_dp->pcon_dsc_dpcd); 4327 int pcon_max_slice_width = drm_dp_pcon_dsc_max_slice_width(intel_dp->pcon_dsc_dpcd); 4328 4329 return intel_hdmi_dsc_get_num_slices(crtc_state, pcon_max_slices, 4330 pcon_max_slice_width, 4331 hdmi_max_slices, hdmi_throughput); 4332 } 4333 4334 static int 4335 intel_dp_pcon_dsc_enc_bpp(struct intel_dp *intel_dp, 4336 const struct intel_crtc_state *crtc_state, 4337 int num_slices, int slice_width) 4338 { 4339 struct intel_connector *connector = intel_dp->attached_connector; 4340 const struct drm_display_info *info = &connector->base.display_info; 4341 int output_format = crtc_state->output_format; 4342 bool hdmi_all_bpp = info->hdmi.dsc_cap.all_bpp; 4343 int pcon_fractional_bpp = drm_dp_pcon_dsc_bpp_incr(intel_dp->pcon_dsc_dpcd); 4344 int hdmi_max_chunk_bytes = 4345 info->hdmi.dsc_cap.total_chunk_kbytes * 1024; 4346 4347 return intel_hdmi_dsc_get_bpp(pcon_fractional_bpp, slice_width, 4348 num_slices, output_format, hdmi_all_bpp, 4349 hdmi_max_chunk_bytes); 4350 } 4351 4352 void 4353 intel_dp_pcon_dsc_configure(struct intel_dp *intel_dp, 4354 const struct intel_crtc_state *crtc_state) 4355 { 4356 struct intel_display *display = to_intel_display(intel_dp); 4357 struct intel_connector *connector = intel_dp->attached_connector; 4358 const struct drm_display_info *info; 4359 u8 pps_param[6]; 4360 int slice_height; 4361 int slice_width; 4362 int num_slices; 4363 int bits_per_pixel; 4364 int ret; 4365 bool hdmi_is_dsc_1_2; 4366 4367 if (!intel_dp_is_hdmi_2_1_sink(intel_dp)) 4368 return; 4369 4370 if (!connector) 4371 return; 4372 4373 info = &connector->base.display_info; 4374 4375 hdmi_is_dsc_1_2 = info->hdmi.dsc_cap.v_1p2; 4376 4377 if (!drm_dp_pcon_enc_is_dsc_1_2(intel_dp->pcon_dsc_dpcd) || 4378 !hdmi_is_dsc_1_2) 4379 return; 4380 4381 slice_height = intel_dp_pcon_dsc_enc_slice_height(crtc_state); 4382 if (!slice_height) 4383 return; 4384 4385 num_slices = intel_dp_pcon_dsc_enc_slices(intel_dp, crtc_state); 4386 if (!num_slices) 4387 return; 4388 4389 slice_width = DIV_ROUND_UP(crtc_state->hw.adjusted_mode.hdisplay, 4390 num_slices); 4391 4392 bits_per_pixel = intel_dp_pcon_dsc_enc_bpp(intel_dp, crtc_state, 4393 num_slices, slice_width); 4394 if (!bits_per_pixel) 4395 return; 4396 4397 pps_param[0] = slice_height & 0xFF; 4398 pps_param[1] = slice_height >> 8; 4399 pps_param[2] = slice_width & 0xFF; 4400 pps_param[3] = slice_width >> 8; 4401 pps_param[4] = bits_per_pixel & 0xFF; 4402 pps_param[5] = (bits_per_pixel >> 8) & 0x3; 4403 4404 ret = drm_dp_pcon_pps_override_param(&intel_dp->aux, pps_param); 4405 if (ret < 0) 4406 drm_dbg_kms(display->drm, "Failed to set pcon DSC\n"); 4407 } 4408 4409 void intel_dp_configure_protocol_converter(struct intel_dp *intel_dp, 4410 const struct intel_crtc_state *crtc_state) 4411 { 4412 struct intel_display *display = to_intel_display(intel_dp); 4413 bool ycbcr444_to_420 = false; 4414 bool rgb_to_ycbcr = false; 4415 u8 tmp; 4416 4417 if (intel_dp->dpcd[DP_DPCD_REV] < 0x13) 4418 return; 4419 4420 if (!drm_dp_is_branch(intel_dp->dpcd)) 4421 return; 4422 4423 tmp = intel_dp_has_hdmi_sink(intel_dp) ? DP_HDMI_DVI_OUTPUT_CONFIG : 0; 4424 4425 if (drm_dp_dpcd_writeb(&intel_dp->aux, 4426 DP_PROTOCOL_CONVERTER_CONTROL_0, tmp) != 1) 4427 drm_dbg_kms(display->drm, 4428 "Failed to %s protocol converter HDMI mode\n", 4429 str_enable_disable(intel_dp_has_hdmi_sink(intel_dp))); 4430 4431 if (crtc_state->sink_format == INTEL_OUTPUT_FORMAT_YCBCR420) { 4432 switch (crtc_state->output_format) { 4433 case INTEL_OUTPUT_FORMAT_YCBCR420: 4434 break; 4435 case INTEL_OUTPUT_FORMAT_YCBCR444: 4436 ycbcr444_to_420 = true; 4437 break; 4438 case INTEL_OUTPUT_FORMAT_RGB: 4439 rgb_to_ycbcr = true; 4440 ycbcr444_to_420 = true; 4441 break; 4442 default: 4443 MISSING_CASE(crtc_state->output_format); 4444 break; 4445 } 4446 } else if (crtc_state->sink_format == INTEL_OUTPUT_FORMAT_YCBCR444) { 4447 switch (crtc_state->output_format) { 4448 case INTEL_OUTPUT_FORMAT_YCBCR444: 4449 break; 4450 case INTEL_OUTPUT_FORMAT_RGB: 4451 rgb_to_ycbcr = true; 4452 break; 4453 default: 4454 MISSING_CASE(crtc_state->output_format); 4455 break; 4456 } 4457 } 4458 4459 tmp = ycbcr444_to_420 ? DP_CONVERSION_TO_YCBCR420_ENABLE : 0; 4460 4461 if (drm_dp_dpcd_writeb(&intel_dp->aux, 4462 DP_PROTOCOL_CONVERTER_CONTROL_1, tmp) != 1) 4463 drm_dbg_kms(display->drm, 4464 "Failed to %s protocol converter YCbCr 4:2:0 conversion mode\n", 4465 str_enable_disable(intel_dp->dfp.ycbcr_444_to_420)); 4466 4467 tmp = rgb_to_ycbcr ? DP_CONVERSION_BT709_RGB_YCBCR_ENABLE : 0; 4468 4469 if (drm_dp_pcon_convert_rgb_to_ycbcr(&intel_dp->aux, tmp) < 0) 4470 drm_dbg_kms(display->drm, 4471 "Failed to %s protocol converter RGB->YCbCr conversion mode\n", 4472 str_enable_disable(tmp)); 4473 } 4474 4475 static u8 intel_dp_read_dprx_feature_enum(struct intel_dp *intel_dp) 4476 { 4477 u8 dprx = 0; 4478 4479 drm_dp_dpcd_read_data(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST, 4480 &dprx, sizeof(dprx)); 4481 return dprx; 4482 } 4483 4484 static bool intel_dp_get_colorimetry_status(u8 dprx) 4485 { 4486 return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED; 4487 } 4488 4489 static bool intel_dp_get_sst_split_sdp_status(u8 dprx) 4490 { 4491 return dprx & DP_SST_SPLIT_SDP_CAP; 4492 } 4493 4494 static int intel_dp_read_dsc_dpcd(struct drm_dp_aux *aux, 4495 u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]) 4496 { 4497 int ret; 4498 4499 ret = drm_dp_dpcd_read_data(aux, DP_DSC_SUPPORT, dsc_dpcd, 4500 DP_DSC_RECEIVER_CAP_SIZE); 4501 if (ret) { 4502 drm_dbg_kms(aux->drm_dev, 4503 "Could not read DSC DPCD register 0x%x Error: %pe\n", 4504 DP_DSC_SUPPORT, ERR_PTR(ret)); 4505 return ret; 4506 } 4507 4508 drm_dbg_kms(aux->drm_dev, "DSC DPCD: %*ph\n", 4509 DP_DSC_RECEIVER_CAP_SIZE, 4510 dsc_dpcd); 4511 return 0; 4512 } 4513 4514 static void init_dsc_overall_throughput_limits(struct intel_connector *connector, bool is_branch) 4515 { 4516 u8 branch_caps[DP_DSC_BRANCH_CAP_SIZE]; 4517 int line_width; 4518 4519 connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444 = INT_MAX; 4520 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420 = INT_MAX; 4521 connector->dp.dsc_branch_caps.max_line_width = INT_MAX; 4522 4523 if (!is_branch) 4524 return; 4525 4526 if (drm_dp_dpcd_read_data(connector->dp.dsc_decompression_aux, 4527 DP_DSC_BRANCH_OVERALL_THROUGHPUT_0, branch_caps, 4528 sizeof(branch_caps)) != 0) 4529 return; 4530 4531 connector->dp.dsc_branch_caps.overall_throughput.rgb_yuv444 = 4532 drm_dp_dsc_branch_max_overall_throughput(branch_caps, true) ? : INT_MAX; 4533 4534 connector->dp.dsc_branch_caps.overall_throughput.yuv422_420 = 4535 drm_dp_dsc_branch_max_overall_throughput(branch_caps, false) ? : INT_MAX; 4536 4537 line_width = drm_dp_dsc_branch_max_line_width(branch_caps); 4538 connector->dp.dsc_branch_caps.max_line_width = line_width > 0 ? line_width : INT_MAX; 4539 } 4540 4541 void intel_dp_get_dsc_sink_cap(u8 dpcd_rev, 4542 const struct drm_dp_desc *desc, bool is_branch, 4543 struct intel_connector *connector) 4544 { 4545 struct intel_display *display = to_intel_display(connector); 4546 4547 /* 4548 * Clear the cached register set to avoid using stale values 4549 * for the sinks that do not support DSC. 4550 */ 4551 memset(connector->dp.dsc_dpcd, 0, sizeof(connector->dp.dsc_dpcd)); 4552 4553 /* Clear fec_capable to avoid using stale values */ 4554 connector->dp.fec_capability = 0; 4555 4556 memset(&connector->dp.dsc_branch_caps, 0, sizeof(connector->dp.dsc_branch_caps)); 4557 connector->dp.dsc_throughput_quirk = false; 4558 4559 if (dpcd_rev < DP_DPCD_REV_14) 4560 return; 4561 4562 if (intel_dp_read_dsc_dpcd(connector->dp.dsc_decompression_aux, 4563 connector->dp.dsc_dpcd) < 0) 4564 return; 4565 4566 if (drm_dp_dpcd_readb(connector->dp.dsc_decompression_aux, DP_FEC_CAPABILITY, 4567 &connector->dp.fec_capability) < 0) { 4568 drm_dbg_kms(display->drm, "Could not read FEC DPCD register\n"); 4569 return; 4570 } 4571 4572 drm_dbg_kms(display->drm, "FEC CAPABILITY: %x\n", 4573 connector->dp.fec_capability); 4574 4575 if (!(connector->dp.dsc_dpcd[0] & DP_DSC_DECOMPRESSION_IS_SUPPORTED)) 4576 return; 4577 4578 init_dsc_overall_throughput_limits(connector, is_branch); 4579 4580 /* 4581 * TODO: Move the HW rev check as well to the DRM core quirk table if 4582 * that's required after clarifying the list of affected devices. 4583 */ 4584 if (drm_dp_has_quirk(desc, DP_DPCD_QUIRK_DSC_THROUGHPUT_BPP_LIMIT) && 4585 desc->ident.hw_rev == 0x10) 4586 connector->dp.dsc_throughput_quirk = true; 4587 } 4588 4589 static void intel_edp_get_dsc_sink_cap(u8 edp_dpcd_rev, struct intel_connector *connector) 4590 { 4591 if (edp_dpcd_rev < DP_EDP_14) 4592 return; 4593 4594 if (intel_dp_read_dsc_dpcd(connector->dp.dsc_decompression_aux, 4595 connector->dp.dsc_dpcd) < 0) 4596 return; 4597 4598 if (connector->dp.dsc_dpcd[0] & DP_DSC_DECOMPRESSION_IS_SUPPORTED) 4599 init_dsc_overall_throughput_limits(connector, false); 4600 } 4601 4602 static void 4603 intel_dp_detect_dsc_caps(struct intel_dp *intel_dp, struct intel_connector *connector) 4604 { 4605 struct intel_display *display = to_intel_display(intel_dp); 4606 4607 /* Read DP Sink DSC Cap DPCD regs for DP v1.4 */ 4608 if (!HAS_DSC(display)) 4609 return; 4610 4611 if (intel_dp_is_edp(intel_dp)) 4612 intel_edp_get_dsc_sink_cap(intel_dp->edp_dpcd[0], 4613 connector); 4614 else 4615 intel_dp_get_dsc_sink_cap(intel_dp->dpcd[DP_DPCD_REV], 4616 &intel_dp->desc, drm_dp_is_branch(intel_dp->dpcd), 4617 connector); 4618 } 4619 4620 static void intel_edp_mso_mode_fixup(struct intel_connector *connector, 4621 struct drm_display_mode *mode) 4622 { 4623 struct intel_display *display = to_intel_display(connector); 4624 struct intel_dp *intel_dp = intel_attached_dp(connector); 4625 int n = intel_dp->mso_link_count; 4626 int overlap = intel_dp->mso_pixel_overlap; 4627 4628 if (!mode || !n) 4629 return; 4630 4631 mode->hdisplay = (mode->hdisplay - overlap) * n; 4632 mode->hsync_start = (mode->hsync_start - overlap) * n; 4633 mode->hsync_end = (mode->hsync_end - overlap) * n; 4634 mode->htotal = (mode->htotal - overlap) * n; 4635 mode->clock *= n; 4636 4637 drm_mode_set_name(mode); 4638 4639 drm_dbg_kms(display->drm, 4640 "[CONNECTOR:%d:%s] using generated MSO mode: " DRM_MODE_FMT "\n", 4641 connector->base.base.id, connector->base.name, 4642 DRM_MODE_ARG(mode)); 4643 } 4644 4645 void intel_edp_fixup_vbt_bpp(struct intel_encoder *encoder, int pipe_bpp) 4646 { 4647 struct intel_display *display = to_intel_display(encoder); 4648 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4649 struct intel_connector *connector = intel_dp->attached_connector; 4650 4651 if (connector->panel.vbt.edp.bpp && pipe_bpp > connector->panel.vbt.edp.bpp) { 4652 /* 4653 * This is a big fat ugly hack. 4654 * 4655 * Some machines in UEFI boot mode provide us a VBT that has 18 4656 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons 4657 * unknown we fail to light up. Yet the same BIOS boots up with 4658 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as 4659 * max, not what it tells us to use. 4660 * 4661 * Note: This will still be broken if the eDP panel is not lit 4662 * up by the BIOS, and thus we can't get the mode at module 4663 * load. 4664 */ 4665 drm_dbg_kms(display->drm, 4666 "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", 4667 pipe_bpp, connector->panel.vbt.edp.bpp); 4668 connector->panel.vbt.edp.bpp = pipe_bpp; 4669 } 4670 } 4671 4672 static void intel_edp_mso_init(struct intel_dp *intel_dp) 4673 { 4674 struct intel_display *display = to_intel_display(intel_dp); 4675 struct intel_connector *connector = intel_dp->attached_connector; 4676 struct drm_display_info *info = &connector->base.display_info; 4677 u8 mso; 4678 4679 if (intel_dp->edp_dpcd[0] < DP_EDP_14) 4680 return; 4681 4682 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_EDP_MSO_LINK_CAPABILITIES, &mso) != 1) { 4683 drm_err(display->drm, "Failed to read MSO cap\n"); 4684 return; 4685 } 4686 4687 /* Valid configurations are SST or MSO 2x1, 2x2, 4x1 */ 4688 mso &= DP_EDP_MSO_NUMBER_OF_LINKS_MASK; 4689 if (mso % 2 || mso > drm_dp_max_lane_count(intel_dp->dpcd)) { 4690 drm_err(display->drm, "Invalid MSO link count cap %u\n", mso); 4691 mso = 0; 4692 } 4693 4694 if (mso) { 4695 drm_dbg_kms(display->drm, 4696 "Sink MSO %ux%u configuration, pixel overlap %u\n", 4697 mso, drm_dp_max_lane_count(intel_dp->dpcd) / mso, 4698 info->mso_pixel_overlap); 4699 if (!HAS_MSO(display)) { 4700 drm_err(display->drm, 4701 "No source MSO support, disabling\n"); 4702 mso = 0; 4703 } 4704 } 4705 4706 intel_dp->mso_link_count = mso; 4707 intel_dp->mso_pixel_overlap = mso ? info->mso_pixel_overlap : 0; 4708 } 4709 4710 static void 4711 intel_edp_set_data_override_rates(struct intel_dp *intel_dp) 4712 { 4713 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 4714 int *sink_rates = intel_dp->sink_rates; 4715 int i, count = 0; 4716 4717 for (i = 0; i < intel_dp->num_sink_rates; i++) { 4718 if (intel_bios_encoder_reject_edp_rate(encoder->devdata, 4719 intel_dp->sink_rates[i])) 4720 continue; 4721 4722 sink_rates[count++] = intel_dp->sink_rates[i]; 4723 } 4724 intel_dp->num_sink_rates = count; 4725 } 4726 4727 static void 4728 intel_edp_set_sink_rates(struct intel_dp *intel_dp) 4729 { 4730 struct intel_display *display = to_intel_display(intel_dp); 4731 4732 intel_dp->num_sink_rates = 0; 4733 4734 if (intel_dp->edp_dpcd[0] >= DP_EDP_14) { 4735 __le16 sink_rates[DP_MAX_SUPPORTED_RATES]; 4736 int ret; 4737 int i; 4738 4739 ret = drm_dp_dpcd_read_data(&intel_dp->aux, 4740 DP_SUPPORTED_LINK_RATES, 4741 sink_rates, sizeof(sink_rates)); 4742 if (ret < 0) { 4743 drm_dbg_kms(display->drm, 4744 "Unable to read eDP supported link rates, using default rates\n"); 4745 memset(sink_rates, 0, sizeof(sink_rates)); 4746 } 4747 4748 for (i = 0; i < ARRAY_SIZE(sink_rates); i++) { 4749 int rate; 4750 4751 /* Value read multiplied by 200kHz gives the per-lane 4752 * link rate in kHz. The source rates are, however, 4753 * stored in terms of LS_Clk kHz. The full conversion 4754 * back to symbols is 4755 * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte) 4756 */ 4757 rate = le16_to_cpu(sink_rates[i]) * 200 / 10; 4758 4759 if (rate == 0) 4760 break; 4761 4762 /* 4763 * Some platforms cannot reliably drive HBR3 rates due to PHY limitations, 4764 * even if the sink advertises support. Reject any sink rates above HBR2 on 4765 * the known machines for stable output. 4766 */ 4767 if (rate > 540000 && 4768 intel_has_quirk(display, QUIRK_EDP_LIMIT_RATE_HBR2)) 4769 break; 4770 4771 intel_dp->sink_rates[i] = rate; 4772 } 4773 intel_dp->num_sink_rates = i; 4774 } 4775 4776 /* 4777 * Use DP_LINK_RATE_SET if DP_SUPPORTED_LINK_RATES are available, 4778 * default to DP_MAX_LINK_RATE and DP_LINK_BW_SET otherwise. 4779 */ 4780 if (intel_dp->num_sink_rates) 4781 intel_dp->use_rate_select = true; 4782 else 4783 intel_dp_set_sink_rates(intel_dp); 4784 4785 intel_edp_set_data_override_rates(intel_dp); 4786 } 4787 4788 static bool 4789 intel_edp_init_dpcd(struct intel_dp *intel_dp, struct intel_connector *connector) 4790 { 4791 struct intel_display *display = to_intel_display(intel_dp); 4792 int ret; 4793 u8 dprx; 4794 4795 /* this function is meant to be called only once */ 4796 drm_WARN_ON(display->drm, intel_dp->dpcd[DP_DPCD_REV] != 0); 4797 4798 if (drm_dp_read_dpcd_caps(&intel_dp->aux, intel_dp->dpcd) != 0) 4799 return false; 4800 4801 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, 4802 drm_dp_is_branch(intel_dp->dpcd)); 4803 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident); 4804 4805 dprx = intel_dp_read_dprx_feature_enum(intel_dp); 4806 4807 intel_dp->colorimetry_support = 4808 intel_dp_get_colorimetry_status(dprx); 4809 4810 intel_dp->sst_split_sdp_support = 4811 intel_dp_get_sst_split_sdp_status(dprx); 4812 4813 /* 4814 * Read the eDP display control registers. 4815 * 4816 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in 4817 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it 4818 * set, but require eDP 1.4+ detection (e.g. for supported link rates 4819 * method). The display control registers should read zero if they're 4820 * not supported anyway. 4821 */ 4822 if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV, 4823 intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) == 4824 sizeof(intel_dp->edp_dpcd)) { 4825 drm_dbg_kms(display->drm, "eDP DPCD: %*ph\n", 4826 (int)sizeof(intel_dp->edp_dpcd), 4827 intel_dp->edp_dpcd); 4828 4829 intel_dp->use_max_params = intel_dp->edp_dpcd[0] < DP_EDP_14; 4830 } 4831 4832 /* 4833 * If needed, program our source OUI so we can make various Intel-specific AUX services 4834 * available (such as HDR backlight controls) 4835 */ 4836 intel_dp_init_source_oui(intel_dp); 4837 4838 /* Read the ALPM DPCD caps */ 4839 ret = drm_dp_dpcd_read_byte(&intel_dp->aux, DP_RECEIVER_ALPM_CAP, 4840 &intel_dp->alpm_dpcd); 4841 if (ret < 0) 4842 return false; 4843 4844 /* 4845 * This has to be called after intel_dp->edp_dpcd is filled, PSR checks 4846 * for SET_POWER_CAPABLE bit in intel_dp->edp_dpcd[1] 4847 */ 4848 intel_psr_init_dpcd(intel_dp, connector); 4849 4850 intel_edp_set_sink_rates(intel_dp); 4851 intel_dp_set_max_sink_lane_count(intel_dp); 4852 4853 /* Read the eDP DSC DPCD registers */ 4854 intel_dp_detect_dsc_caps(intel_dp, connector); 4855 4856 return true; 4857 } 4858 4859 static bool 4860 intel_dp_has_sink_count(struct intel_dp *intel_dp) 4861 { 4862 if (!intel_dp->attached_connector) 4863 return false; 4864 4865 return drm_dp_read_sink_count_cap(&intel_dp->attached_connector->base, 4866 intel_dp->dpcd, 4867 &intel_dp->desc); 4868 } 4869 4870 void intel_dp_update_sink_caps(struct intel_dp *intel_dp) 4871 { 4872 struct intel_display *display = to_intel_display(intel_dp); 4873 4874 intel_dp_set_sink_rates(intel_dp); 4875 intel_dp_set_max_sink_lane_count(intel_dp); 4876 /* 4877 * Handle unexpected sink cap changes, or a race between setting 4878 * the deferred link params flag in the HPD IRQ handler and 4879 * clearing the flag during connector detect. 4880 */ 4881 if (intel_dp_set_common_link_params(intel_dp) && 4882 !intel_dp->reset_link_params) { 4883 drm_dbg_kms(display->drm, 4884 "DPRX capabilities changed before long HPD or RX_CAP_CHANGED signal\n"); 4885 intel_dp->reset_link_params = true; 4886 } 4887 } 4888 4889 static bool 4890 intel_dp_get_dpcd(struct intel_dp *intel_dp) 4891 { 4892 int ret; 4893 4894 if (intel_dp_init_lttpr_and_dprx_caps(intel_dp) < 0) 4895 return false; 4896 4897 /* 4898 * Don't clobber cached eDP rates. Also skip re-reading 4899 * the OUI/ID since we know it won't change. 4900 */ 4901 if (!intel_dp_is_edp(intel_dp)) { 4902 u8 dprx; 4903 4904 drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc, 4905 drm_dp_is_branch(intel_dp->dpcd)); 4906 4907 intel_init_dpcd_quirks(intel_dp, &intel_dp->desc.ident); 4908 4909 dprx = intel_dp_read_dprx_feature_enum(intel_dp); 4910 4911 intel_dp->colorimetry_support = 4912 intel_dp_get_colorimetry_status(dprx); 4913 4914 intel_dp->sst_split_sdp_support = 4915 intel_dp_get_sst_split_sdp_status(dprx); 4916 4917 intel_dp_update_sink_caps(intel_dp); 4918 } 4919 4920 if (intel_dp_has_sink_count(intel_dp)) { 4921 ret = drm_dp_read_sink_count(&intel_dp->aux); 4922 if (ret < 0) 4923 return false; 4924 4925 /* 4926 * Sink count can change between short pulse hpd hence 4927 * a member variable in intel_dp will track any changes 4928 * between short pulse interrupts. 4929 */ 4930 intel_dp->sink_count = ret; 4931 4932 /* 4933 * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that 4934 * a dongle is present but no display. Unless we require to know 4935 * if a dongle is present or not, we don't need to update 4936 * downstream port information. So, an early return here saves 4937 * time from performing other operations which are not required. 4938 */ 4939 if (!intel_dp->sink_count) 4940 return false; 4941 } 4942 4943 return drm_dp_read_downstream_info(&intel_dp->aux, intel_dp->dpcd, 4944 intel_dp->downstream_ports) == 0; 4945 } 4946 4947 static const char *intel_dp_mst_mode_str(enum drm_dp_mst_mode mst_mode) 4948 { 4949 if (mst_mode == DRM_DP_MST) 4950 return "MST"; 4951 else if (mst_mode == DRM_DP_SST_SIDEBAND_MSG) 4952 return "SST w/ sideband messaging"; 4953 else 4954 return "SST"; 4955 } 4956 4957 static enum drm_dp_mst_mode 4958 intel_dp_mst_mode_choose(struct intel_dp *intel_dp, 4959 enum drm_dp_mst_mode sink_mst_mode) 4960 { 4961 struct intel_display *display = to_intel_display(intel_dp); 4962 4963 if (!display->params.enable_dp_mst) 4964 return DRM_DP_SST; 4965 4966 if (!intel_dp_mst_source_support(intel_dp)) 4967 return DRM_DP_SST; 4968 4969 if (sink_mst_mode == DRM_DP_SST_SIDEBAND_MSG && 4970 !(intel_dp->dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_128B132B)) 4971 return DRM_DP_SST; 4972 4973 return sink_mst_mode; 4974 } 4975 4976 static enum drm_dp_mst_mode 4977 intel_dp_mst_detect(struct intel_dp *intel_dp) 4978 { 4979 struct intel_display *display = to_intel_display(intel_dp); 4980 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 4981 enum drm_dp_mst_mode sink_mst_mode; 4982 enum drm_dp_mst_mode mst_detect; 4983 4984 sink_mst_mode = drm_dp_read_mst_cap(&intel_dp->aux, intel_dp->dpcd); 4985 4986 mst_detect = intel_dp_mst_mode_choose(intel_dp, sink_mst_mode); 4987 4988 drm_dbg_kms(display->drm, 4989 "[ENCODER:%d:%s] MST support: port: %s, sink: %s, modparam: %s -> enable: %s\n", 4990 encoder->base.base.id, encoder->base.name, 4991 str_yes_no(intel_dp_mst_source_support(intel_dp)), 4992 intel_dp_mst_mode_str(sink_mst_mode), 4993 str_yes_no(display->params.enable_dp_mst), 4994 intel_dp_mst_mode_str(mst_detect)); 4995 4996 return mst_detect; 4997 } 4998 4999 static void 5000 intel_dp_mst_configure(struct intel_dp *intel_dp) 5001 { 5002 if (!intel_dp_mst_source_support(intel_dp)) 5003 return; 5004 5005 intel_dp->is_mst = intel_dp->mst_detect != DRM_DP_SST; 5006 5007 if (intel_dp->is_mst) 5008 intel_dp_mst_prepare_probe(intel_dp); 5009 5010 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, intel_dp->is_mst); 5011 5012 /* Avoid stale info on the next detect cycle. */ 5013 intel_dp->mst_detect = DRM_DP_SST; 5014 } 5015 5016 static void 5017 intel_dp_mst_disconnect(struct intel_dp *intel_dp) 5018 { 5019 struct intel_display *display = to_intel_display(intel_dp); 5020 5021 if (!intel_dp->is_mst) 5022 return; 5023 5024 drm_dbg_kms(display->drm, 5025 "MST device may have disappeared %d vs %d\n", 5026 intel_dp->is_mst, intel_dp->mst.mgr.mst_state); 5027 intel_dp->is_mst = false; 5028 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, intel_dp->is_mst); 5029 } 5030 5031 #define INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST (DP_AUTOMATED_TEST_REQUEST | \ 5032 DP_CP_IRQ | \ 5033 DP_SINK_SPECIFIC_IRQ) 5034 5035 #define INTEL_DP_DEVICE_SERVICE_IRQ_MASK_MST (DP_CP_IRQ | \ 5036 DP_DOWN_REP_MSG_RDY | \ 5037 DP_UP_REQ_MSG_RDY) 5038 5039 #define INTEL_DP_LINK_SERVICE_IRQ_MASK_SST (RX_CAP_CHANGED | \ 5040 LINK_STATUS_CHANGED | \ 5041 HDMI_LINK_STATUS_CHANGED | \ 5042 CONNECTED_OFF_ENTRY_REQUESTED | \ 5043 DP_TUNNELING_IRQ) 5044 5045 #define INTEL_DP_LINK_SERVICE_IRQ_MASK_MST (RX_CAP_CHANGED | \ 5046 LINK_STATUS_CHANGED | \ 5047 DP_TUNNELING_IRQ) 5048 5049 static bool 5050 intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *esi) 5051 { 5052 struct intel_display *display = to_intel_display(intel_dp); 5053 5054 /* 5055 * Display WA for HSD #13013007775: mtl/arl/lnl 5056 * Read the sink count and link service IRQ registers in separate 5057 * transactions to prevent disconnecting the sink on a TBT link 5058 * inadvertently. 5059 */ 5060 if (IS_DISPLAY_VER(display, 14, 20) && !display->platform.battlemage) { 5061 if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, esi, 3) != 3) 5062 return false; 5063 5064 /* DP_SINK_COUNT_ESI + 3 == DP_LINK_SERVICE_IRQ_VECTOR_ESI0 */ 5065 return drm_dp_dpcd_readb(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, 5066 &esi[3]) == 1; 5067 } 5068 5069 return drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT_ESI, esi, 4) == 4; 5070 } 5071 5072 static bool intel_dp_ack_sink_irq_esi(struct intel_dp *intel_dp, u8 esi[4]) 5073 { 5074 int retry; 5075 5076 for (retry = 0; retry < 3; retry++) { 5077 if (drm_dp_dpcd_write(&intel_dp->aux, DP_SINK_COUNT_ESI + 1, 5078 &esi[1], 3) == 3) 5079 return true; 5080 } 5081 5082 return false; 5083 } 5084 5085 /* Return %true if reading the ESI vector succeeded, %false otherwise. */ 5086 static bool intel_dp_get_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5087 { 5088 memset(esi, 0, 4); 5089 5090 /* 5091 * TODO: For DP_DPCD_REV >= 0x12 read 5092 * DP_SINK_COUNT_ESI and DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0. 5093 */ 5094 if (drm_dp_dpcd_read_data(&intel_dp->aux, DP_SINK_COUNT, esi, 2) != 0) 5095 return false; 5096 5097 if (intel_dp->dpcd[DP_DPCD_REV] < DP_DPCD_REV_12) 5098 return true; 5099 5100 /* TODO: Read DP_DEVICE_SERVICE_IRQ_VECTOR_ESI1 as well */ 5101 if (drm_dp_dpcd_read_byte(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, &esi[3]) != 0) 5102 return false; 5103 5104 return true; 5105 } 5106 5107 /* Return %true if acking the ESI vector IRQ events succeeded, %false otherwise. */ 5108 static bool intel_dp_ack_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5109 { 5110 /* 5111 * TODO: For DP_DPCD_REV >= 0x12 write 5112 * DP_DEVICE_SERVICE_IRQ_VECTOR_ESI0 5113 */ 5114 if (drm_dp_dpcd_write_byte(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR, esi[1]) != 0) 5115 return false; 5116 5117 if (intel_dp->dpcd[DP_DPCD_REV] < DP_DPCD_REV_12) 5118 return true; 5119 5120 /* TODO: Read DP_DEVICE_SERVICE_IRQ_VECTOR_ESI1 as well */ 5121 if (drm_dp_dpcd_write_byte(&intel_dp->aux, DP_LINK_SERVICE_IRQ_VECTOR_ESI0, esi[3]) != 0) 5122 return false; 5123 5124 return true; 5125 } 5126 5127 /* 5128 * Return %true if reading the ESI vector and acking the ESI IRQ events succeeded, 5129 * %false otherwise. 5130 */ 5131 static bool intel_dp_get_and_ack_sink_irq_esi_sst(struct intel_dp *intel_dp, u8 esi[4]) 5132 { 5133 struct intel_display *display = to_intel_display(intel_dp); 5134 struct intel_connector *connector = intel_dp->attached_connector; 5135 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 5136 5137 if (!intel_dp_get_sink_irq_esi_sst(intel_dp, esi)) 5138 return false; 5139 5140 drm_dbg_kms(display->drm, 5141 "[CONNECTOR:%d:%s][ENCODER:%d:%s] DPRX ESI: %4ph\n", 5142 connector->base.base.id, connector->base.name, 5143 encoder->base.base.id, encoder->base.name, 5144 esi); 5145 5146 esi[1] &= INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST; 5147 esi[3] &= INTEL_DP_LINK_SERVICE_IRQ_MASK_SST; 5148 5149 if (mem_is_zero(&esi[1], 3)) 5150 return true; 5151 5152 if (!intel_dp_ack_sink_irq_esi_sst(intel_dp, esi)) 5153 return false; 5154 5155 return true; 5156 } 5157 5158 bool 5159 intel_dp_needs_vsc_colorimetry(const struct intel_crtc_state *crtc_state, 5160 const struct drm_connector_state *conn_state) 5161 { 5162 struct intel_dp *intel_dp = 5163 enc_to_intel_dp(to_intel_encoder(conn_state->best_encoder)); 5164 5165 /* 5166 * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication 5167 * of Color Encoding Format and Content Color Gamut], in order to 5168 * send YCBCR 420 or HDR BT.2020 signals we should use DP VSC SDP. 5169 * Only signal this when the sink advertises VSC SDP colorimetry 5170 * support. 5171 */ 5172 if (!intel_dp->colorimetry_support) 5173 return false; 5174 5175 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420) 5176 return true; 5177 5178 switch (conn_state->colorspace) { 5179 case DRM_MODE_COLORIMETRY_SYCC_601: 5180 case DRM_MODE_COLORIMETRY_OPYCC_601: 5181 case DRM_MODE_COLORIMETRY_BT2020_YCC: 5182 case DRM_MODE_COLORIMETRY_BT2020_RGB: 5183 case DRM_MODE_COLORIMETRY_BT2020_CYCC: 5184 return true; 5185 default: 5186 break; 5187 } 5188 5189 return false; 5190 } 5191 5192 static ssize_t intel_dp_as_sdp_pack(const struct drm_dp_as_sdp *as_sdp, 5193 struct dp_sdp *sdp, size_t size) 5194 { 5195 size_t length = sizeof(struct dp_sdp); 5196 5197 if (size < length) 5198 return -ENOSPC; 5199 5200 memset(sdp, 0, size); 5201 5202 /* Prepare AS (Adaptive Sync) SDP Header */ 5203 sdp->sdp_header.HB0 = 0; 5204 sdp->sdp_header.HB1 = as_sdp->sdp_type; 5205 sdp->sdp_header.HB2 = as_sdp->revision; 5206 sdp->sdp_header.HB3 = as_sdp->length; 5207 5208 /* Fill AS (Adaptive Sync) SDP Payload */ 5209 sdp->db[0] = as_sdp->mode; 5210 sdp->db[1] = as_sdp->vtotal & 0xFF; 5211 sdp->db[2] = (as_sdp->vtotal >> 8) & 0xFF; 5212 sdp->db[3] = as_sdp->target_rr & 0xFF; 5213 sdp->db[4] = (as_sdp->target_rr >> 8) & 0x3; 5214 5215 if (as_sdp->target_rr_divider) 5216 sdp->db[4] |= 0x20; 5217 5218 sdp->db[7] = as_sdp->coasting_vtotal & 0xFF; 5219 sdp->db[8] = (as_sdp->coasting_vtotal >> 8) & 0xFF; 5220 5221 return length; 5222 } 5223 5224 static ssize_t 5225 intel_dp_hdr_metadata_infoframe_sdp_pack(struct intel_display *display, 5226 const struct hdmi_drm_infoframe *drm_infoframe, 5227 struct dp_sdp *sdp, 5228 size_t size) 5229 { 5230 size_t length = sizeof(struct dp_sdp); 5231 const int infoframe_size = HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE; 5232 unsigned char buf[HDMI_INFOFRAME_HEADER_SIZE + HDMI_DRM_INFOFRAME_SIZE]; 5233 ssize_t len; 5234 5235 if (size < length) 5236 return -ENOSPC; 5237 5238 memset(sdp, 0, size); 5239 5240 len = hdmi_drm_infoframe_pack_only(drm_infoframe, buf, sizeof(buf)); 5241 if (len < 0) { 5242 drm_dbg_kms(display->drm, 5243 "buffer size is smaller than hdr metadata infoframe\n"); 5244 return -ENOSPC; 5245 } 5246 5247 if (len != infoframe_size) { 5248 drm_dbg_kms(display->drm, "wrong static hdr metadata size\n"); 5249 return -ENOSPC; 5250 } 5251 5252 /* 5253 * Set up the infoframe sdp packet for HDR static metadata. 5254 * Prepare VSC Header for SU as per DP 1.4a spec, 5255 * Table 2-100 and Table 2-101 5256 */ 5257 5258 /* Secondary-Data Packet ID, 00h for non-Audio INFOFRAME */ 5259 sdp->sdp_header.HB0 = 0; 5260 /* 5261 * Packet Type 80h + Non-audio INFOFRAME Type value 5262 * HDMI_INFOFRAME_TYPE_DRM: 0x87 5263 * - 80h + Non-audio INFOFRAME Type value 5264 * - InfoFrame Type: 0x07 5265 * [CTA-861-G Table-42 Dynamic Range and Mastering InfoFrame] 5266 */ 5267 sdp->sdp_header.HB1 = drm_infoframe->type; 5268 /* 5269 * Least Significant Eight Bits of (Data Byte Count – 1) 5270 * infoframe_size - 1 5271 */ 5272 sdp->sdp_header.HB2 = 0x1D; 5273 /* INFOFRAME SDP Version Number */ 5274 sdp->sdp_header.HB3 = (0x13 << 2); 5275 /* CTA Header Byte 2 (INFOFRAME Version Number) */ 5276 sdp->db[0] = drm_infoframe->version; 5277 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */ 5278 sdp->db[1] = drm_infoframe->length; 5279 /* 5280 * Copy HDMI_DRM_INFOFRAME_SIZE size from a buffer after 5281 * HDMI_INFOFRAME_HEADER_SIZE 5282 */ 5283 BUILD_BUG_ON(sizeof(sdp->db) < HDMI_DRM_INFOFRAME_SIZE + 2); 5284 memcpy(&sdp->db[2], &buf[HDMI_INFOFRAME_HEADER_SIZE], 5285 HDMI_DRM_INFOFRAME_SIZE); 5286 5287 /* 5288 * Size of DP infoframe sdp packet for HDR static metadata consists of 5289 * - DP SDP Header(struct dp_sdp_header): 4 bytes 5290 * - Two Data Blocks: 2 bytes 5291 * CTA Header Byte2 (INFOFRAME Version Number) 5292 * CTA Header Byte3 (Length of INFOFRAME) 5293 * - HDMI_DRM_INFOFRAME_SIZE: 26 bytes 5294 * 5295 * Prior to GEN11's GMP register size is identical to DP HDR static metadata 5296 * infoframe size. But GEN11+ has larger than that size, write_infoframe 5297 * will pad rest of the size. 5298 */ 5299 return sizeof(struct dp_sdp_header) + 2 + HDMI_DRM_INFOFRAME_SIZE; 5300 } 5301 5302 static void intel_write_dp_sdp(struct intel_encoder *encoder, 5303 const struct intel_crtc_state *crtc_state, 5304 unsigned int type) 5305 { 5306 struct intel_display *display = to_intel_display(encoder); 5307 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5308 struct dp_sdp sdp = {}; 5309 ssize_t len; 5310 5311 if ((crtc_state->infoframes.enable & 5312 intel_hdmi_infoframe_enable(type)) == 0) 5313 return; 5314 5315 switch (type) { 5316 case DP_SDP_VSC: 5317 len = drm_dp_vsc_sdp_pack(&crtc_state->infoframes.vsc, &sdp); 5318 break; 5319 case HDMI_PACKET_TYPE_GAMUT_METADATA: 5320 len = intel_dp_hdr_metadata_infoframe_sdp_pack(display, 5321 &crtc_state->infoframes.drm.drm, 5322 &sdp, sizeof(sdp)); 5323 break; 5324 case DP_SDP_ADAPTIVE_SYNC: 5325 len = intel_dp_as_sdp_pack(&crtc_state->infoframes.as_sdp, &sdp, 5326 sizeof(sdp)); 5327 break; 5328 default: 5329 MISSING_CASE(type); 5330 return; 5331 } 5332 5333 if (drm_WARN_ON(display->drm, len < 0)) 5334 return; 5335 5336 dig_port->write_infoframe(encoder, crtc_state, type, &sdp, len); 5337 } 5338 5339 void intel_dp_set_infoframes(struct intel_encoder *encoder, 5340 bool enable, 5341 const struct intel_crtc_state *crtc_state, 5342 const struct drm_connector_state *conn_state) 5343 { 5344 struct intel_display *display = to_intel_display(encoder); 5345 intel_reg_t reg = HSW_TVIDEO_DIP_CTL(display, crtc_state->cpu_transcoder); 5346 u32 dip_enable = VIDEO_DIP_ENABLE_AVI_HSW | VIDEO_DIP_ENABLE_GCP_HSW | 5347 VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW | 5348 VIDEO_DIP_ENABLE_SPD_HSW | VIDEO_DIP_ENABLE_DRM_GLK; 5349 5350 if (HAS_AS_SDP(display)) 5351 dip_enable |= VIDEO_DIP_ENABLE_AS_ADL; 5352 5353 u32 val = intel_de_read(display, reg) & ~dip_enable; 5354 5355 /* TODO: Sanitize DSC enabling wrt. intel_dsc_dp_pps_write(). */ 5356 if (!enable && HAS_DSC(display)) 5357 val &= ~VDIP_ENABLE_PPS; 5358 5359 /* 5360 * This routine disables VSC DIP if the function is called 5361 * to disable SDP or if it does not have PSR 5362 */ 5363 if (!enable || !crtc_state->has_psr) 5364 val &= ~VIDEO_DIP_ENABLE_VSC_HSW; 5365 5366 intel_de_write(display, reg, val); 5367 intel_de_posting_read(display, reg); 5368 5369 if (!enable) 5370 return; 5371 5372 intel_write_dp_sdp(encoder, crtc_state, DP_SDP_VSC); 5373 intel_write_dp_sdp(encoder, crtc_state, DP_SDP_ADAPTIVE_SYNC); 5374 5375 intel_write_dp_sdp(encoder, crtc_state, HDMI_PACKET_TYPE_GAMUT_METADATA); 5376 } 5377 5378 static 5379 int intel_dp_as_sdp_unpack(struct drm_dp_as_sdp *as_sdp, 5380 const void *buffer, size_t size) 5381 { 5382 const struct dp_sdp *sdp = buffer; 5383 5384 if (size < sizeof(struct dp_sdp)) 5385 return -EINVAL; 5386 5387 memset(as_sdp, 0, sizeof(*as_sdp)); 5388 5389 if (sdp->sdp_header.HB0 != 0) 5390 return -EINVAL; 5391 5392 if (sdp->sdp_header.HB1 != DP_SDP_ADAPTIVE_SYNC) 5393 return -EINVAL; 5394 5395 if ((sdp->sdp_header.HB3 & 0x3F) != 9) 5396 return -EINVAL; 5397 5398 as_sdp->sdp_type = sdp->sdp_header.HB1; 5399 as_sdp->length = sdp->sdp_header.HB3 & DP_AS_SDP_LENGTH_MASK; 5400 as_sdp->revision = sdp->sdp_header.HB2; 5401 as_sdp->mode = sdp->db[0] & DP_AS_SDP_OPERATION_MODE_MASK; 5402 as_sdp->vtotal = (sdp->db[2] << 8) | sdp->db[1]; 5403 as_sdp->target_rr = ((sdp->db[4] & 0x3) << 8) | sdp->db[3]; 5404 as_sdp->target_rr_divider = sdp->db[4] & 0x20 ? true : false; 5405 as_sdp->coasting_vtotal = (sdp->db[8] << 8) | sdp->db[7]; 5406 5407 return 0; 5408 } 5409 5410 static int intel_dp_vsc_sdp_unpack(struct drm_dp_vsc_sdp *vsc, 5411 const void *buffer, size_t size) 5412 { 5413 const struct dp_sdp *sdp = buffer; 5414 5415 if (size < sizeof(struct dp_sdp)) 5416 return -EINVAL; 5417 5418 memset(vsc, 0, sizeof(*vsc)); 5419 5420 if (sdp->sdp_header.HB0 != 0) 5421 return -EINVAL; 5422 5423 if (sdp->sdp_header.HB1 != DP_SDP_VSC) 5424 return -EINVAL; 5425 5426 vsc->sdp_type = sdp->sdp_header.HB1; 5427 vsc->revision = sdp->sdp_header.HB2; 5428 vsc->length = sdp->sdp_header.HB3; 5429 5430 if ((sdp->sdp_header.HB2 == 0x2 && sdp->sdp_header.HB3 == 0x8) || 5431 (sdp->sdp_header.HB2 == 0x4 && sdp->sdp_header.HB3 == 0xe) || 5432 (sdp->sdp_header.HB2 == 0x6 && sdp->sdp_header.HB3 == 0x10)) { 5433 /* 5434 * - HB2 = 0x2, HB3 = 0x8 5435 * VSC SDP supporting 3D stereo + PSR 5436 * - HB2 = 0x4, HB3 = 0xe 5437 * VSC SDP supporting 3D stereo + PSR2 with Y-coordinate of 5438 * first scan line of the SU region (applies to eDP v1.4b 5439 * and higher). 5440 * - HB2 = 0x6, HB3 = 0x10 5441 * VSC SDP supporting 3D stereo + Panel Replay. 5442 */ 5443 return 0; 5444 } else if (sdp->sdp_header.HB2 == 0x5 && sdp->sdp_header.HB3 == 0x13) { 5445 /* 5446 * - HB2 = 0x5, HB3 = 0x13 5447 * VSC SDP supporting 3D stereo + PSR2 + Pixel Encoding/Colorimetry 5448 * Format. 5449 */ 5450 vsc->pixelformat = (sdp->db[16] >> 4) & 0xf; 5451 vsc->colorimetry = sdp->db[16] & 0xf; 5452 vsc->dynamic_range = (sdp->db[17] >> 7) & 0x1; 5453 5454 switch (sdp->db[17] & 0x7) { 5455 case 0x0: 5456 vsc->bpc = 6; 5457 break; 5458 case 0x1: 5459 vsc->bpc = 8; 5460 break; 5461 case 0x2: 5462 vsc->bpc = 10; 5463 break; 5464 case 0x3: 5465 vsc->bpc = 12; 5466 break; 5467 case 0x4: 5468 vsc->bpc = 16; 5469 break; 5470 default: 5471 MISSING_CASE(sdp->db[17] & 0x7); 5472 return -EINVAL; 5473 } 5474 5475 vsc->content_type = sdp->db[18] & 0x7; 5476 } else { 5477 return -EINVAL; 5478 } 5479 5480 return 0; 5481 } 5482 5483 static void 5484 intel_read_dp_as_sdp(struct intel_encoder *encoder, 5485 struct intel_crtc_state *crtc_state, 5486 struct drm_dp_as_sdp *as_sdp) 5487 { 5488 struct intel_display *display = to_intel_display(encoder); 5489 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5490 unsigned int type = DP_SDP_ADAPTIVE_SYNC; 5491 struct dp_sdp sdp = {}; 5492 int ret; 5493 5494 if ((crtc_state->infoframes.enable & 5495 intel_hdmi_infoframe_enable(type)) == 0) 5496 return; 5497 5498 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, 5499 sizeof(sdp)); 5500 5501 ret = intel_dp_as_sdp_unpack(as_sdp, &sdp, sizeof(sdp)); 5502 if (ret) 5503 drm_dbg_kms(display->drm, "Failed to unpack DP AS SDP\n"); 5504 } 5505 5506 static int 5507 intel_dp_hdr_metadata_infoframe_sdp_unpack(struct hdmi_drm_infoframe *drm_infoframe, 5508 const void *buffer, size_t size) 5509 { 5510 int ret; 5511 5512 const struct dp_sdp *sdp = buffer; 5513 5514 if (size < sizeof(struct dp_sdp)) 5515 return -EINVAL; 5516 5517 if (sdp->sdp_header.HB0 != 0) 5518 return -EINVAL; 5519 5520 if (sdp->sdp_header.HB1 != HDMI_INFOFRAME_TYPE_DRM) 5521 return -EINVAL; 5522 5523 /* 5524 * Least Significant Eight Bits of (Data Byte Count – 1) 5525 * 1Dh (i.e., Data Byte Count = 30 bytes). 5526 */ 5527 if (sdp->sdp_header.HB2 != 0x1D) 5528 return -EINVAL; 5529 5530 /* Most Significant Two Bits of (Data Byte Count – 1), Clear to 00b. */ 5531 if ((sdp->sdp_header.HB3 & 0x3) != 0) 5532 return -EINVAL; 5533 5534 /* INFOFRAME SDP Version Number */ 5535 if (((sdp->sdp_header.HB3 >> 2) & 0x3f) != 0x13) 5536 return -EINVAL; 5537 5538 /* CTA Header Byte 2 (INFOFRAME Version Number) */ 5539 if (sdp->db[0] != 1) 5540 return -EINVAL; 5541 5542 /* CTA Header Byte 3 (Length of INFOFRAME): HDMI_DRM_INFOFRAME_SIZE */ 5543 if (sdp->db[1] != HDMI_DRM_INFOFRAME_SIZE) 5544 return -EINVAL; 5545 5546 ret = hdmi_drm_infoframe_unpack_only(drm_infoframe, &sdp->db[2], 5547 HDMI_DRM_INFOFRAME_SIZE); 5548 5549 return ret; 5550 } 5551 5552 static void intel_read_dp_vsc_sdp(struct intel_encoder *encoder, 5553 struct intel_crtc_state *crtc_state, 5554 struct drm_dp_vsc_sdp *vsc) 5555 { 5556 struct intel_display *display = to_intel_display(encoder); 5557 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5558 unsigned int type = DP_SDP_VSC; 5559 struct dp_sdp sdp = {}; 5560 int ret; 5561 5562 if ((crtc_state->infoframes.enable & 5563 intel_hdmi_infoframe_enable(type)) == 0) 5564 return; 5565 5566 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, sizeof(sdp)); 5567 5568 ret = intel_dp_vsc_sdp_unpack(vsc, &sdp, sizeof(sdp)); 5569 5570 if (ret) 5571 drm_dbg_kms(display->drm, "Failed to unpack DP VSC SDP\n"); 5572 } 5573 5574 static void intel_read_dp_hdr_metadata_infoframe_sdp(struct intel_encoder *encoder, 5575 struct intel_crtc_state *crtc_state, 5576 struct hdmi_drm_infoframe *drm_infoframe) 5577 { 5578 struct intel_display *display = to_intel_display(encoder); 5579 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 5580 unsigned int type = HDMI_PACKET_TYPE_GAMUT_METADATA; 5581 struct dp_sdp sdp = {}; 5582 int ret; 5583 5584 if ((crtc_state->infoframes.enable & 5585 intel_hdmi_infoframe_enable(type)) == 0) 5586 return; 5587 5588 dig_port->read_infoframe(encoder, crtc_state, type, &sdp, 5589 sizeof(sdp)); 5590 5591 ret = intel_dp_hdr_metadata_infoframe_sdp_unpack(drm_infoframe, &sdp, 5592 sizeof(sdp)); 5593 5594 if (ret) 5595 drm_dbg_kms(display->drm, 5596 "Failed to unpack DP HDR Metadata Infoframe SDP\n"); 5597 } 5598 5599 void intel_read_dp_sdp(struct intel_encoder *encoder, 5600 struct intel_crtc_state *crtc_state, 5601 unsigned int type) 5602 { 5603 switch (type) { 5604 case DP_SDP_VSC: 5605 intel_read_dp_vsc_sdp(encoder, crtc_state, 5606 &crtc_state->infoframes.vsc); 5607 break; 5608 case HDMI_PACKET_TYPE_GAMUT_METADATA: 5609 intel_read_dp_hdr_metadata_infoframe_sdp(encoder, crtc_state, 5610 &crtc_state->infoframes.drm.drm); 5611 break; 5612 case DP_SDP_ADAPTIVE_SYNC: 5613 intel_read_dp_as_sdp(encoder, crtc_state, 5614 &crtc_state->infoframes.as_sdp); 5615 break; 5616 default: 5617 MISSING_CASE(type); 5618 break; 5619 } 5620 } 5621 5622 static void 5623 intel_dp_mst_hpd_irq(struct intel_dp *intel_dp, u8 *esi, u8 *ack) 5624 { 5625 bool handled = false; 5626 5627 drm_dp_mst_hpd_irq_handle_event(&intel_dp->mst.mgr, esi, ack, &handled); 5628 5629 if (esi[1] & DP_CP_IRQ) { 5630 intel_hdcp_handle_cp_irq(intel_dp->attached_connector); 5631 ack[1] |= DP_CP_IRQ; 5632 } 5633 } 5634 5635 static bool intel_dp_handle_link_service_irq(struct intel_dp *intel_dp, u8 irq_mask); 5636 5637 /** 5638 * intel_dp_check_mst_status - service any pending MST interrupts, check link status 5639 * @intel_dp: Intel DP struct 5640 * 5641 * Read any pending MST interrupts, call MST core to handle these and ack the 5642 * interrupts. Check if the main and AUX link state is ok. 5643 * 5644 * Returns: 5645 * - %true if pending interrupts were serviced (or no interrupts were 5646 * pending) w/o detecting an error condition. 5647 * - %false if an error condition - like AUX failure or a loss of link - is 5648 * detected, or another condition - like a DP tunnel BW state change - needs 5649 * servicing from the hotplug work. 5650 */ 5651 static bool 5652 intel_dp_check_mst_status(struct intel_dp *intel_dp) 5653 { 5654 struct intel_display *display = to_intel_display(intel_dp); 5655 bool force_retrain = intel_dp_link_training_get_force_retrain(intel_dp->link.training); 5656 bool reprobe_needed = false; 5657 int tries = 33; 5658 5659 while (--tries) { 5660 u8 esi[4] = {}; 5661 u8 ack[4] = {}; 5662 bool new_irqs; 5663 5664 if (!intel_dp_get_sink_irq_esi(intel_dp, esi)) { 5665 drm_dbg_kms(display->drm, 5666 "failed to get ESI - device may have failed\n"); 5667 reprobe_needed = true; 5668 5669 break; 5670 } 5671 5672 drm_dbg_kms(display->drm, "DPRX ESI: %4ph\n", esi); 5673 5674 ack[3] |= esi[3] & INTEL_DP_LINK_SERVICE_IRQ_MASK_MST; 5675 5676 intel_dp_mst_hpd_irq(intel_dp, esi, ack); 5677 5678 new_irqs = !mem_is_zero(ack, sizeof(ack)); 5679 5680 drm_WARN_ON(display->drm, ack[1] & ~INTEL_DP_DEVICE_SERVICE_IRQ_MASK_MST); 5681 drm_WARN_ON(display->drm, ack[3] & ~INTEL_DP_LINK_SERVICE_IRQ_MASK_MST); 5682 5683 if (new_irqs && !intel_dp_ack_sink_irq_esi(intel_dp, ack)) 5684 drm_dbg_kms(display->drm, "Failed to ack ESI\n"); 5685 5686 if (ack[1] & (DP_DOWN_REP_MSG_RDY | DP_UP_REQ_MSG_RDY)) 5687 drm_dp_mst_hpd_irq_send_new_request(&intel_dp->mst.mgr); 5688 5689 if (force_retrain) { 5690 /* Defer forced retraining to the regular link status check. */ 5691 ack[3] |= LINK_STATUS_CHANGED; 5692 force_retrain = false; 5693 } 5694 5695 if (intel_dp_handle_link_service_irq(intel_dp, ack[3])) 5696 reprobe_needed = true; 5697 5698 if (!new_irqs) 5699 break; 5700 } 5701 5702 if (!tries) { 5703 drm_dbg_kms(display->drm, "DPRX ESI not clearing, device may be stuck\n"); 5704 reprobe_needed = true; 5705 } 5706 5707 return !reprobe_needed; 5708 } 5709 5710 static void 5711 intel_dp_handle_hdmi_link_status_change(struct intel_dp *intel_dp) 5712 { 5713 bool is_active; 5714 u8 buf = 0; 5715 5716 is_active = drm_dp_pcon_hdmi_link_active(&intel_dp->aux); 5717 if (intel_dp->frl.is_trained && !is_active) { 5718 if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, &buf) < 0) 5719 return; 5720 5721 buf &= ~DP_PCON_ENABLE_HDMI_LINK; 5722 if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_PCON_HDMI_LINK_CONFIG_1, buf) < 0) 5723 return; 5724 5725 drm_dp_pcon_hdmi_frl_link_error_count(&intel_dp->aux, &intel_dp->attached_connector->base); 5726 5727 intel_dp->frl.is_trained = false; 5728 5729 /* Restart FRL training or fall back to TMDS mode */ 5730 intel_dp_check_frl_training(intel_dp); 5731 } 5732 } 5733 5734 bool intel_dp_has_connector(struct intel_dp *intel_dp, 5735 const struct drm_connector_state *conn_state) 5736 { 5737 struct intel_display *display = to_intel_display(intel_dp); 5738 struct intel_encoder *encoder; 5739 enum pipe pipe; 5740 5741 if (!conn_state->best_encoder) 5742 return false; 5743 5744 /* SST */ 5745 encoder = &dp_to_dig_port(intel_dp)->base; 5746 if (conn_state->best_encoder == &encoder->base) 5747 return true; 5748 5749 /* MST */ 5750 for_each_pipe(display, pipe) { 5751 encoder = &intel_dp->mst.stream_encoders[pipe]->base; 5752 if (conn_state->best_encoder == &encoder->base) 5753 return true; 5754 } 5755 5756 return false; 5757 } 5758 5759 static void wait_for_connector_hw_done(const struct drm_connector_state *conn_state) 5760 { 5761 struct intel_connector *connector = to_intel_connector(conn_state->connector); 5762 struct intel_display *display = to_intel_display(connector); 5763 5764 drm_modeset_lock_assert_held(&display->drm->mode_config.connection_mutex); 5765 5766 if (!conn_state->commit) 5767 return; 5768 5769 drm_WARN_ON(display->drm, 5770 !wait_for_completion_timeout(&conn_state->commit->hw_done, 5771 msecs_to_jiffies(5000))); 5772 } 5773 5774 int intel_dp_get_active_pipes(struct intel_dp *intel_dp, 5775 struct drm_modeset_acquire_ctx *ctx, 5776 u8 *pipe_mask) 5777 { 5778 struct intel_display *display = to_intel_display(intel_dp); 5779 struct drm_connector_list_iter conn_iter; 5780 struct intel_connector *connector; 5781 int ret = 0; 5782 5783 *pipe_mask = 0; 5784 5785 drm_connector_list_iter_begin(display->drm, &conn_iter); 5786 for_each_intel_connector_iter(connector, &conn_iter) { 5787 struct drm_connector_state *conn_state = 5788 connector->base.state; 5789 struct intel_crtc_state *crtc_state; 5790 struct intel_crtc *crtc; 5791 5792 if (!intel_dp_has_connector(intel_dp, conn_state)) 5793 continue; 5794 5795 crtc = to_intel_crtc(conn_state->crtc); 5796 if (!crtc) 5797 continue; 5798 5799 ret = drm_modeset_lock(&crtc->base.mutex, ctx); 5800 if (ret) 5801 break; 5802 5803 crtc_state = to_intel_crtc_state(crtc->base.state); 5804 5805 drm_WARN_ON(display->drm, 5806 !intel_crtc_has_dp_encoder(crtc_state)); 5807 5808 if (!crtc_state->hw.active) 5809 continue; 5810 5811 wait_for_connector_hw_done(conn_state); 5812 5813 *pipe_mask |= BIT(crtc->pipe); 5814 } 5815 drm_connector_list_iter_end(&conn_iter); 5816 5817 return ret; 5818 } 5819 5820 void intel_dp_flush_connector_commits(struct intel_connector *connector) 5821 { 5822 wait_for_connector_hw_done(connector->base.state); 5823 } 5824 5825 static void intel_dp_handle_device_service_irq(struct intel_dp *intel_dp, u8 irq_mask) 5826 { 5827 struct intel_display *display = to_intel_display(intel_dp); 5828 5829 drm_WARN_ON(display->drm, irq_mask & ~INTEL_DP_DEVICE_SERVICE_IRQ_MASK_SST); 5830 5831 if (irq_mask & DP_AUTOMATED_TEST_REQUEST) 5832 intel_dp_test_request(intel_dp); 5833 5834 if (irq_mask & DP_CP_IRQ) 5835 intel_hdcp_handle_cp_irq(intel_dp->attached_connector); 5836 5837 if (irq_mask & DP_SINK_SPECIFIC_IRQ) 5838 drm_dbg_kms(display->drm, "Sink specific irq unhandled\n"); 5839 } 5840 5841 5842 /* 5843 * Return %true if a full connector reprobe is required after handling a link 5844 * service IRQ event. 5845 */ 5846 static bool intel_dp_handle_link_service_irq(struct intel_dp *intel_dp, u8 irq_mask) 5847 { 5848 struct intel_display *display = to_intel_display(intel_dp); 5849 struct intel_connector *connector = intel_dp->attached_connector; 5850 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 5851 bool reprobe_needed = false; 5852 5853 drm_WARN_ON(display->drm, irq_mask & ~(INTEL_DP_LINK_SERVICE_IRQ_MASK_SST | 5854 INTEL_DP_LINK_SERVICE_IRQ_MASK_MST)); 5855 5856 if (irq_mask & RX_CAP_CHANGED) { 5857 intel_dp->reset_link_params = true; 5858 reprobe_needed = true; 5859 } 5860 5861 if (irq_mask & LINK_STATUS_CHANGED) 5862 intel_dp_check_link_state(intel_dp); 5863 5864 if (irq_mask & HDMI_LINK_STATUS_CHANGED) 5865 intel_dp_handle_hdmi_link_status_change(intel_dp); 5866 5867 if (irq_mask & CONNECTED_OFF_ENTRY_REQUESTED) 5868 drm_dbg_kms(display->drm, 5869 "[CONNECTOR:%d:%s][ENCODER:%d:%s] Allowing connected off request\n", 5870 connector->base.base.id, connector->base.name, 5871 encoder->base.base.id, encoder->base.name); 5872 5873 if ((irq_mask & DP_TUNNELING_IRQ) && 5874 drm_dp_tunnel_handle_irq(display->dp_tunnel_mgr, 5875 &intel_dp->aux)) 5876 reprobe_needed = true; 5877 5878 return reprobe_needed; 5879 } 5880 5881 /* 5882 * According to DP spec 5883 * 5.1.2: 5884 * 1. Read DPCD 5885 * 2. Configure link according to Receiver Capabilities 5886 * 3. Use Link Training from 2.5.3.3 and 3.5.1.3 5887 * 4. Check link status on receipt of hot-plug interrupt 5888 * 5889 * intel_dp_short_pulse - handles short pulse interrupts 5890 * when full detection is not required. 5891 * Returns %true if short pulse is handled and full detection 5892 * is NOT required and %false otherwise. 5893 */ 5894 static bool 5895 intel_dp_short_pulse(struct intel_dp *intel_dp) 5896 { 5897 bool reprobe_needed = false; 5898 u8 esi[4] = {}; 5899 5900 intel_dp_test_reset(intel_dp); 5901 5902 if (!intel_dp_get_and_ack_sink_irq_esi_sst(intel_dp, esi)) 5903 return false; 5904 5905 /* 5906 * If the current value of sink count doesn't match with 5907 * the value that was stored earlier we need to do full 5908 * detection. 5909 */ 5910 if (intel_dp_has_sink_count(intel_dp) && 5911 DP_GET_SINK_COUNT(esi[0]) != intel_dp->sink_count) 5912 /* No need to proceed if we are going to do full detect */ 5913 return false; 5914 5915 intel_dp_handle_device_service_irq(intel_dp, esi[1]); 5916 5917 /* 5918 * Force checking the link status for DPCD_REV < 1.2 5919 * TODO: let the link status check depend on LINK_STATUS_CHANGED 5920 * or intel_dp->link.training.force_retrain for DPCD_REV >= 1.2 5921 */ 5922 esi[3] |= LINK_STATUS_CHANGED; 5923 if (intel_dp_handle_link_service_irq(intel_dp, esi[3])) 5924 reprobe_needed = true; 5925 5926 /* Handle CEC interrupts, if any */ 5927 drm_dp_cec_irq(&intel_dp->aux); 5928 5929 if (READ_ONCE(intel_dp->downstream_port_changed)) { 5930 WRITE_ONCE(intel_dp->downstream_port_changed, false); 5931 reprobe_needed = true; 5932 } 5933 5934 intel_psr_short_pulse(intel_dp); 5935 5936 if (intel_alpm_get_error(intel_dp)) { 5937 intel_alpm_disable(intel_dp); 5938 intel_dp->alpm.sink_alpm_error = true; 5939 } 5940 5941 if (intel_dp_test_short_pulse(intel_dp)) 5942 reprobe_needed = true; 5943 5944 return !reprobe_needed; 5945 } 5946 5947 /* XXX this is probably wrong for multiple downstream ports */ 5948 static enum drm_connector_status 5949 intel_dp_detect_dpcd(struct intel_dp *intel_dp) 5950 { 5951 struct intel_display *display = to_intel_display(intel_dp); 5952 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 5953 u8 *dpcd = intel_dp->dpcd; 5954 u8 type; 5955 5956 if (drm_WARN_ON(display->drm, intel_dp_is_edp(intel_dp))) 5957 return connector_status_connected; 5958 5959 WRITE_ONCE(intel_dp->downstream_port_changed, false); 5960 5961 intel_lspcon_resume(dig_port); 5962 5963 if (!intel_dp_get_dpcd(intel_dp)) 5964 return connector_status_disconnected; 5965 5966 intel_dp->mst_detect = intel_dp_mst_detect(intel_dp); 5967 5968 /* if there's no downstream port, we're done */ 5969 if (!drm_dp_is_branch(dpcd)) 5970 return connector_status_connected; 5971 5972 /* If we're HPD-aware, SINK_COUNT changes dynamically */ 5973 if (intel_dp_has_sink_count(intel_dp) && 5974 intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) { 5975 return intel_dp->sink_count ? 5976 connector_status_connected : connector_status_disconnected; 5977 } 5978 5979 if (intel_dp->mst_detect == DRM_DP_MST) 5980 return connector_status_connected; 5981 5982 /* If no HPD, poke DDC gently */ 5983 if (drm_probe_ddc(&intel_dp->aux.ddc)) 5984 return connector_status_connected; 5985 5986 /* Well we tried, say unknown for unreliable port types */ 5987 if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) { 5988 type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK; 5989 if (type == DP_DS_PORT_TYPE_VGA || 5990 type == DP_DS_PORT_TYPE_NON_EDID) 5991 return connector_status_unknown; 5992 } else { 5993 type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & 5994 DP_DWN_STRM_PORT_TYPE_MASK; 5995 if (type == DP_DWN_STRM_PORT_TYPE_ANALOG || 5996 type == DP_DWN_STRM_PORT_TYPE_OTHER) 5997 return connector_status_unknown; 5998 } 5999 6000 /* Anything else is out of spec, warn and ignore */ 6001 drm_dbg_kms(display->drm, "Broken DP branch device, ignoring\n"); 6002 return connector_status_disconnected; 6003 } 6004 6005 static enum drm_connector_status 6006 edp_detect(struct intel_dp *intel_dp) 6007 { 6008 return connector_status_connected; 6009 } 6010 6011 void intel_digital_port_lock(struct intel_encoder *encoder) 6012 { 6013 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6014 6015 if (dig_port->lock) 6016 dig_port->lock(dig_port); 6017 } 6018 6019 void intel_digital_port_unlock(struct intel_encoder *encoder) 6020 { 6021 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6022 6023 if (dig_port->unlock) 6024 dig_port->unlock(dig_port); 6025 } 6026 6027 /* 6028 * intel_digital_port_connected_locked - is the specified port connected? 6029 * @encoder: intel_encoder 6030 * 6031 * In cases where there's a connector physically connected but it can't be used 6032 * by our hardware we also return false, since the rest of the driver should 6033 * pretty much treat the port as disconnected. This is relevant for type-C 6034 * (starting on ICL) where there's ownership involved. 6035 * 6036 * The caller must hold the lock acquired by calling intel_digital_port_lock() 6037 * when calling this function. 6038 * 6039 * Return %true if port is connected, %false otherwise. 6040 */ 6041 bool intel_digital_port_connected_locked(struct intel_encoder *encoder) 6042 { 6043 struct intel_display *display = to_intel_display(encoder); 6044 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6045 bool is_glitch_free = intel_tc_port_handles_hpd_glitches(dig_port); 6046 bool is_connected = false; 6047 6048 with_intel_display_power(display, POWER_DOMAIN_DISPLAY_CORE) { 6049 poll_timeout_us(is_connected = dig_port->connected(encoder), 6050 is_connected || is_glitch_free, 6051 30, 4000, false); 6052 } 6053 6054 return is_connected; 6055 } 6056 6057 bool intel_digital_port_connected(struct intel_encoder *encoder) 6058 { 6059 bool ret; 6060 6061 intel_digital_port_lock(encoder); 6062 ret = intel_digital_port_connected_locked(encoder); 6063 intel_digital_port_unlock(encoder); 6064 6065 return ret; 6066 } 6067 6068 static const struct drm_edid * 6069 intel_dp_get_edid(struct intel_dp *intel_dp) 6070 { 6071 struct intel_connector *connector = intel_dp->attached_connector; 6072 const struct drm_edid *fixed_edid = connector->panel.fixed_edid; 6073 6074 /* Use panel fixed edid if we have one */ 6075 if (fixed_edid) { 6076 /* invalid edid */ 6077 if (IS_ERR(fixed_edid)) 6078 return NULL; 6079 6080 return drm_edid_dup(fixed_edid); 6081 } 6082 6083 return drm_edid_read_ddc(&connector->base, &intel_dp->aux.ddc); 6084 } 6085 6086 static void 6087 intel_dp_update_dfp(struct intel_dp *intel_dp, 6088 const struct drm_edid *drm_edid) 6089 { 6090 struct intel_display *display = to_intel_display(intel_dp); 6091 struct intel_connector *connector = intel_dp->attached_connector; 6092 6093 intel_dp->dfp.max_bpc = 6094 drm_dp_downstream_max_bpc(intel_dp->dpcd, 6095 intel_dp->downstream_ports, drm_edid); 6096 6097 intel_dp->dfp.max_dotclock = 6098 drm_dp_downstream_max_dotclock(intel_dp->dpcd, 6099 intel_dp->downstream_ports); 6100 6101 intel_dp->dfp.min_tmds_clock = 6102 drm_dp_downstream_min_tmds_clock(intel_dp->dpcd, 6103 intel_dp->downstream_ports, 6104 drm_edid); 6105 intel_dp->dfp.max_tmds_clock = 6106 drm_dp_downstream_max_tmds_clock(intel_dp->dpcd, 6107 intel_dp->downstream_ports, 6108 drm_edid); 6109 6110 intel_dp->dfp.pcon_max_frl_bw = 6111 drm_dp_get_pcon_max_frl_bw(intel_dp->dpcd, 6112 intel_dp->downstream_ports); 6113 6114 drm_dbg_kms(display->drm, 6115 "[CONNECTOR:%d:%s] DFP max bpc %d, max dotclock %d, TMDS clock %d-%d, PCON Max FRL BW %dGbps\n", 6116 connector->base.base.id, connector->base.name, 6117 intel_dp->dfp.max_bpc, 6118 intel_dp->dfp.max_dotclock, 6119 intel_dp->dfp.min_tmds_clock, 6120 intel_dp->dfp.max_tmds_clock, 6121 intel_dp->dfp.pcon_max_frl_bw); 6122 6123 intel_dp_get_pcon_dsc_cap(intel_dp); 6124 } 6125 6126 static bool 6127 intel_dp_can_ycbcr420(struct intel_dp *intel_dp) 6128 { 6129 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420) && 6130 (!drm_dp_is_branch(intel_dp->dpcd) || intel_dp->dfp.ycbcr420_passthrough)) 6131 return true; 6132 6133 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_RGB) && 6134 dfp_can_convert_from_rgb(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420)) 6135 return true; 6136 6137 if (source_can_output(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR444) && 6138 dfp_can_convert_from_ycbcr444(intel_dp, INTEL_OUTPUT_FORMAT_YCBCR420)) 6139 return true; 6140 6141 return false; 6142 } 6143 6144 static void 6145 intel_dp_update_420(struct intel_dp *intel_dp) 6146 { 6147 struct intel_display *display = to_intel_display(intel_dp); 6148 struct intel_connector *connector = intel_dp->attached_connector; 6149 6150 intel_dp->dfp.ycbcr420_passthrough = 6151 drm_dp_downstream_420_passthrough(intel_dp->dpcd, 6152 intel_dp->downstream_ports); 6153 /* on-board LSPCON always assumed to support 4:4:4->4:2:0 conversion */ 6154 intel_dp->dfp.ycbcr_444_to_420 = 6155 intel_lspcon_active(dp_to_dig_port(intel_dp)) || 6156 drm_dp_downstream_444_to_420_conversion(intel_dp->dpcd, 6157 intel_dp->downstream_ports); 6158 intel_dp->dfp.rgb_to_ycbcr = 6159 drm_dp_downstream_rgb_to_ycbcr_conversion(intel_dp->dpcd, 6160 intel_dp->downstream_ports, 6161 DP_DS_HDMI_BT709_RGB_YCBCR_CONV); 6162 6163 connector->base.ycbcr_420_allowed = intel_dp_can_ycbcr420(intel_dp); 6164 6165 drm_dbg_kms(display->drm, 6166 "[CONNECTOR:%d:%s] RGB->YcbCr conversion? %s, YCbCr 4:2:0 allowed? %s, YCbCr 4:4:4->4:2:0 conversion? %s\n", 6167 connector->base.base.id, connector->base.name, 6168 str_yes_no(intel_dp->dfp.rgb_to_ycbcr), 6169 str_yes_no(connector->base.ycbcr_420_allowed), 6170 str_yes_no(intel_dp->dfp.ycbcr_444_to_420)); 6171 } 6172 6173 static void 6174 intel_dp_set_edid(struct intel_dp *intel_dp) 6175 { 6176 struct intel_display *display = to_intel_display(intel_dp); 6177 struct intel_connector *connector = intel_dp->attached_connector; 6178 const struct drm_edid *drm_edid; 6179 bool vrr_capable; 6180 6181 intel_dp_unset_edid(intel_dp); 6182 drm_edid = intel_dp_get_edid(intel_dp); 6183 connector->detect_edid = drm_edid; 6184 6185 /* Below we depend on display info having been updated */ 6186 drm_edid_connector_update(&connector->base, drm_edid); 6187 6188 vrr_capable = intel_vrr_is_capable(connector); 6189 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s] VRR capable: %s\n", 6190 connector->base.base.id, connector->base.name, str_yes_no(vrr_capable)); 6191 drm_connector_set_vrr_capable_property(&connector->base, vrr_capable); 6192 6193 intel_dp_update_dfp(intel_dp, drm_edid); 6194 intel_dp_update_420(intel_dp); 6195 6196 drm_dp_cec_attach(&intel_dp->aux, 6197 connector->base.display_info.source_physical_address); 6198 } 6199 6200 static void 6201 intel_dp_unset_edid(struct intel_dp *intel_dp) 6202 { 6203 struct intel_connector *connector = intel_dp->attached_connector; 6204 6205 drm_dp_cec_unset_edid(&intel_dp->aux); 6206 drm_edid_free(connector->detect_edid); 6207 connector->detect_edid = NULL; 6208 6209 intel_dp->dfp.max_bpc = 0; 6210 intel_dp->dfp.max_dotclock = 0; 6211 intel_dp->dfp.min_tmds_clock = 0; 6212 intel_dp->dfp.max_tmds_clock = 0; 6213 6214 intel_dp->dfp.pcon_max_frl_bw = 0; 6215 6216 intel_dp->dfp.ycbcr_444_to_420 = false; 6217 connector->base.ycbcr_420_allowed = false; 6218 6219 drm_connector_set_vrr_capable_property(&connector->base, 6220 false); 6221 } 6222 6223 static bool 6224 intel_dp_sink_supports_as_sdp_v2(struct intel_dp *intel_dp) 6225 { 6226 u8 rx_features; 6227 6228 /* 6229 * The DP spec does not explicitly provide the AS SDP v2 capability. 6230 * So based on the DP v2.1 SCR, we infer it from the following bits: 6231 * 6232 * DP_AS_SDP_FAVT_PAYLOAD_FIELDS_PARSING_SUPPORTED indicates support for 6233 * FAVT, which is explicitly defined to use AS SDP v2. 6234 * 6235 * DP_ASYNC_VIDEO_TIMING_NOT_SUPPORTED_IN_PR indicates that the sink 6236 * does not support asynchronous video timing while in PR Active, 6237 * requiring the source to keep transmitting Adaptive-Sync SDPs. The 6238 * spec mandates that such sinks shall support AS SDP v2. 6239 * 6240 * #TODO: Check the Adaptive-Sync DisplayID 2.1 block once DisplayID 6241 * parsing is available. This may help detect AS SDP v2 support for 6242 * native DP 2.1 sinks that do not expose FAVT or PR-based capability 6243 * bits. 6244 * 6245 * In the presence of PCONs, check PCON support from DPCD and sink 6246 * support from Display ID. 6247 */ 6248 6249 if (drm_dp_dpcd_read_byte(&intel_dp->aux, 6250 DP_DPRX_FEATURE_ENUMERATION_LIST_CONT_1, 6251 &rx_features) == 1) { 6252 if (rx_features & DP_AS_SDP_FAVT_PAYLOAD_FIELDS_PARSING_SUPPORTED) 6253 return true; 6254 } 6255 6256 if (intel_dp->psr.sink_panel_replay_support && 6257 !intel_psr_pr_async_video_timing_supported(intel_dp)) 6258 return true; 6259 6260 return false; 6261 } 6262 6263 static void 6264 intel_dp_detect_sdp_caps(struct intel_dp *intel_dp) 6265 { 6266 struct intel_display *display = to_intel_display(intel_dp); 6267 6268 intel_dp->as_sdp_supported = HAS_AS_SDP(display) && 6269 drm_dp_as_sdp_supported(&intel_dp->aux, intel_dp->dpcd); 6270 6271 if (!intel_dp->as_sdp_supported) 6272 return; 6273 6274 /* eDP Adaptive-Sync SDP always uses AS SDP v2 */ 6275 if (intel_dp_is_edp(intel_dp)) 6276 intel_dp->as_sdp_v2_supported = true; 6277 else 6278 intel_dp->as_sdp_v2_supported = intel_dp_sink_supports_as_sdp_v2(intel_dp); 6279 } 6280 6281 static bool intel_dp_needs_dpcd_probe(struct intel_dp *intel_dp, bool force_on_external) 6282 { 6283 struct intel_connector *connector = intel_dp->attached_connector; 6284 6285 if (intel_dp_is_edp(intel_dp)) 6286 return false; 6287 6288 if (force_on_external) 6289 return true; 6290 6291 if (intel_dp->is_mst) 6292 return false; 6293 6294 return drm_edid_has_quirk(&connector->base, DRM_EDID_QUIRK_DP_DPCD_PROBE); 6295 } 6296 6297 void intel_dp_dpcd_set_probe(struct intel_dp *intel_dp, bool force_on_external) 6298 { 6299 drm_dp_dpcd_set_probe(&intel_dp->aux, 6300 intel_dp_needs_dpcd_probe(intel_dp, force_on_external)); 6301 } 6302 6303 static int 6304 intel_dp_detect(struct drm_connector *_connector, 6305 struct drm_modeset_acquire_ctx *ctx, 6306 bool force) 6307 { 6308 struct intel_display *display = to_intel_display(_connector->dev); 6309 struct intel_connector *connector = to_intel_connector(_connector); 6310 struct intel_dp *intel_dp = intel_attached_dp(connector); 6311 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 6312 struct intel_encoder *encoder = &dig_port->base; 6313 enum drm_connector_status status; 6314 int ret; 6315 6316 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s]\n", 6317 connector->base.base.id, connector->base.name); 6318 drm_WARN_ON(display->drm, 6319 !drm_modeset_is_locked(&display->drm->mode_config.connection_mutex)); 6320 6321 if (!intel_display_device_enabled(display)) 6322 return connector_status_disconnected; 6323 6324 if (!intel_display_driver_check_access(display)) 6325 return connector->base.status; 6326 6327 intel_dp_flush_connector_commits(connector); 6328 6329 intel_pps_vdd_on(intel_dp); 6330 6331 /* Can't disconnect eDP */ 6332 if (intel_dp_is_edp(intel_dp)) 6333 status = edp_detect(intel_dp); 6334 else if (intel_digital_port_connected(encoder)) 6335 status = intel_dp_detect_dpcd(intel_dp); 6336 else 6337 status = connector_status_disconnected; 6338 6339 if (status != connector_status_disconnected && 6340 !intel_dp_mst_verify_dpcd_state(intel_dp)) 6341 /* 6342 * This requires retrying detection for instance to re-enable 6343 * the MST mode that got reset via a long HPD pulse. The retry 6344 * will happen either via the hotplug handler's retry logic, 6345 * ensured by setting the connector here to SST/disconnected, 6346 * or via a userspace connector probing in response to the 6347 * hotplug uevent sent when removing the MST connectors. 6348 */ 6349 status = connector_status_disconnected; 6350 6351 if (status == connector_status_disconnected) { 6352 intel_dp_test_reset(intel_dp); 6353 /* 6354 * FIXME: Resetting these caps here cause 6355 * state computation fail if the connector need to be 6356 * modeset after sink disconnect. Move resetting them 6357 * to where new sink is connected. 6358 */ 6359 memset(connector->dp.dsc_dpcd, 0, sizeof(connector->dp.dsc_dpcd)); 6360 memset(connector->dp.panel_replay_caps.dpcd, 0, 6361 sizeof(connector->dp.panel_replay_caps.dpcd)); 6362 intel_dp->psr.sink_panel_replay_support = false; 6363 connector->dp.panel_replay_caps.support = false; 6364 connector->dp.panel_replay_caps.su_support = false; 6365 connector->dp.panel_replay_caps.dsc_support = 6366 INTEL_DP_PANEL_REPLAY_DSC_NOT_SUPPORTED; 6367 6368 intel_dp_mst_disconnect(intel_dp); 6369 6370 intel_dp_tunnel_disconnect(intel_dp); 6371 6372 intel_dp_tunnel_uhbr_lanes_wa_reset(intel_dp); 6373 6374 goto out_unset_edid; 6375 } 6376 6377 intel_dp_init_source_oui(intel_dp); 6378 6379 ret = intel_dp_tunnel_detect(intel_dp, ctx); 6380 if (ret == -EDEADLK) { 6381 status = ret; 6382 6383 goto out_vdd_off; 6384 } 6385 6386 if (ret == 1) 6387 connector->base.epoch_counter++; 6388 6389 if (!intel_dp_is_edp(intel_dp)) 6390 intel_psr_init_dpcd(intel_dp, connector); 6391 6392 intel_dp_detect_dsc_caps(intel_dp, connector); 6393 6394 intel_dp_detect_sdp_caps(intel_dp); 6395 6396 if (intel_dp->reset_link_params) { 6397 intel_dp_reset_link_params(intel_dp); 6398 intel_dp->reset_link_params = false; 6399 } 6400 6401 intel_dp_mst_configure(intel_dp); 6402 6403 intel_dp_print_rates(intel_dp); 6404 6405 if (intel_dp->is_mst) { 6406 /* 6407 * If we are in MST mode then this connector 6408 * won't appear connected or have anything 6409 * with EDID on it 6410 */ 6411 status = connector_status_disconnected; 6412 goto out_unset_edid; 6413 } 6414 6415 /* 6416 * Some external monitors do not signal loss of link synchronization 6417 * with an IRQ_HPD, so force a link status check. 6418 * 6419 * TODO: this probably became redundant, so remove it: the link state 6420 * is rechecked/recovered now after modesets, where the loss of 6421 * synchronization tends to occur. 6422 */ 6423 if (!intel_dp_is_edp(intel_dp)) 6424 intel_dp_check_link_state(intel_dp); 6425 6426 /* 6427 * Clearing NACK and defer counts to get their exact values 6428 * while reading EDID which are required by Compliance tests 6429 * 4.2.2.4 and 4.2.2.5 6430 */ 6431 intel_dp->aux.i2c_nack_count = 0; 6432 intel_dp->aux.i2c_defer_count = 0; 6433 6434 intel_dp_set_edid(intel_dp); 6435 if (intel_dp_is_edp(intel_dp) || connector->detect_edid) 6436 status = connector_status_connected; 6437 6438 if (intel_dp_tunnel_uhbr_lanes_wa_setup(intel_dp)) 6439 intel_dp_tunnel_uhbr_lanes_wa_apply(intel_dp); 6440 6441 out_unset_edid: 6442 if (status != connector_status_connected && !intel_dp->is_mst) 6443 intel_dp_unset_edid(intel_dp); 6444 6445 intel_dp_dpcd_set_probe(intel_dp, false); 6446 6447 if (!intel_dp_is_edp(intel_dp)) 6448 drm_dp_set_subconnector_property(&connector->base, 6449 status, 6450 intel_dp->dpcd, 6451 intel_dp->downstream_ports); 6452 out_vdd_off: 6453 intel_pps_vdd_off(intel_dp); 6454 6455 return status; 6456 } 6457 6458 static void 6459 intel_dp_force(struct drm_connector *_connector) 6460 { 6461 struct intel_connector *connector = to_intel_connector(_connector); 6462 struct intel_display *display = to_intel_display(connector); 6463 struct intel_dp *intel_dp = intel_attached_dp(connector); 6464 6465 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s]\n", 6466 connector->base.base.id, connector->base.name); 6467 6468 if (!intel_display_driver_check_access(display)) 6469 return; 6470 6471 intel_dp_unset_edid(intel_dp); 6472 6473 if (connector->base.status != connector_status_connected) 6474 return; 6475 6476 intel_dp_set_edid(intel_dp); 6477 6478 intel_dp_dpcd_set_probe(intel_dp, false); 6479 } 6480 6481 static int intel_dp_get_modes(struct drm_connector *_connector) 6482 { 6483 struct intel_display *display = to_intel_display(_connector->dev); 6484 struct intel_connector *connector = to_intel_connector(_connector); 6485 struct intel_dp *intel_dp = intel_attached_dp(connector); 6486 int num_modes; 6487 6488 /* drm_edid_connector_update() done in ->detect() or ->force() */ 6489 num_modes = drm_edid_connector_add_modes(&connector->base); 6490 6491 /* Also add fixed mode, which may or may not be present in EDID */ 6492 if (intel_dp_is_edp(intel_dp)) 6493 num_modes += intel_panel_get_modes(connector); 6494 6495 if (num_modes) 6496 return num_modes; 6497 6498 if (!connector->detect_edid) { 6499 struct drm_display_mode *mode; 6500 6501 mode = drm_dp_downstream_mode(display->drm, 6502 intel_dp->dpcd, 6503 intel_dp->downstream_ports); 6504 if (mode) { 6505 drm_mode_probed_add(&connector->base, mode); 6506 num_modes++; 6507 } 6508 } 6509 6510 return num_modes; 6511 } 6512 6513 static int 6514 intel_dp_connector_register(struct drm_connector *_connector) 6515 { 6516 struct intel_connector *connector = to_intel_connector(_connector); 6517 struct intel_display *display = to_intel_display(connector); 6518 struct intel_dp *intel_dp = intel_attached_dp(connector); 6519 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 6520 int ret; 6521 6522 ret = intel_connector_register(&connector->base); 6523 if (ret) 6524 return ret; 6525 6526 drm_dbg_kms(display->drm, "registering %s bus for %s\n", 6527 intel_dp->aux.name, connector->base.kdev->kobj.name); 6528 6529 intel_dp->aux.dev = connector->base.kdev; 6530 ret = drm_dp_aux_register(&intel_dp->aux); 6531 if (!ret) 6532 drm_dp_cec_register_connector(&intel_dp->aux, &connector->base); 6533 6534 if (!intel_bios_encoder_is_lspcon(dig_port->base.devdata)) 6535 return ret; 6536 6537 /* 6538 * ToDo: Clean this up to handle lspcon init and resume more 6539 * efficiently and streamlined. 6540 */ 6541 if (intel_lspcon_init(dig_port)) { 6542 if (intel_lspcon_detect_hdr_capability(dig_port)) 6543 drm_connector_attach_hdr_output_metadata_property(&connector->base); 6544 } 6545 6546 return ret; 6547 } 6548 6549 static void 6550 intel_dp_connector_unregister(struct drm_connector *_connector) 6551 { 6552 struct intel_connector *connector = to_intel_connector(_connector); 6553 struct intel_dp *intel_dp = intel_attached_dp(connector); 6554 6555 drm_dp_cec_unregister_connector(&intel_dp->aux); 6556 drm_dp_aux_unregister(&intel_dp->aux); 6557 intel_connector_unregister(&connector->base); 6558 } 6559 6560 void intel_dp_connector_sync_state(struct intel_connector *connector, 6561 const struct intel_crtc_state *crtc_state) 6562 { 6563 struct intel_display *display = to_intel_display(connector); 6564 6565 if (crtc_state && crtc_state->dsc.compression_enable) { 6566 drm_WARN_ON(display->drm, 6567 !connector->dp.dsc_decompression_aux); 6568 connector->dp.dsc_decompression_enabled = true; 6569 } else { 6570 connector->dp.dsc_decompression_enabled = false; 6571 } 6572 } 6573 6574 void intel_dp_encoder_flush_work(struct drm_encoder *_encoder) 6575 { 6576 struct intel_encoder *encoder = to_intel_encoder(_encoder); 6577 struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 6578 struct intel_dp *intel_dp = &dig_port->dp; 6579 6580 intel_encoder_link_check_flush_work(encoder); 6581 6582 intel_dp_mst_encoder_cleanup(dig_port); 6583 6584 intel_dp_tunnel_destroy(intel_dp); 6585 6586 intel_pps_vdd_off_sync(intel_dp); 6587 6588 /* 6589 * Ensure power off delay is respected on module remove, so that we can 6590 * reduce delays at driver probe. See pps_init_timestamps(). 6591 */ 6592 intel_pps_wait_power_cycle(intel_dp); 6593 6594 intel_dp_aux_fini(intel_dp); 6595 } 6596 6597 void intel_dp_encoder_suspend(struct intel_encoder *encoder) 6598 { 6599 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 6600 6601 intel_pps_vdd_off_sync(intel_dp); 6602 6603 intel_dp_tunnel_suspend(intel_dp); 6604 } 6605 6606 void intel_dp_encoder_shutdown(struct intel_encoder *encoder) 6607 { 6608 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 6609 6610 intel_pps_wait_power_cycle(intel_dp); 6611 } 6612 6613 static int intel_modeset_tile_group(struct intel_atomic_state *state, 6614 int tile_group_id) 6615 { 6616 struct intel_display *display = to_intel_display(state); 6617 struct drm_connector_list_iter conn_iter; 6618 struct intel_connector *connector; 6619 int ret = 0; 6620 6621 drm_connector_list_iter_begin(display->drm, &conn_iter); 6622 for_each_intel_connector_iter(connector, &conn_iter) { 6623 struct drm_connector_state *conn_state; 6624 struct intel_crtc_state *crtc_state; 6625 struct intel_crtc *crtc; 6626 6627 if (!connector->base.has_tile || 6628 connector->base.tile_group->id != tile_group_id) 6629 continue; 6630 6631 conn_state = drm_atomic_get_connector_state(&state->base, 6632 &connector->base); 6633 if (IS_ERR(conn_state)) { 6634 ret = PTR_ERR(conn_state); 6635 break; 6636 } 6637 6638 crtc = to_intel_crtc(conn_state->crtc); 6639 6640 if (!crtc) 6641 continue; 6642 6643 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 6644 crtc_state->uapi.mode_changed = true; 6645 6646 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 6647 if (ret) 6648 break; 6649 } 6650 drm_connector_list_iter_end(&conn_iter); 6651 6652 return ret; 6653 } 6654 6655 static int intel_modeset_affected_transcoders(struct intel_atomic_state *state, u16 transcoders) 6656 { 6657 struct intel_display *display = to_intel_display(state); 6658 struct intel_crtc *crtc; 6659 6660 if (transcoders == 0) 6661 return 0; 6662 6663 for_each_intel_crtc(display, crtc) { 6664 struct intel_crtc_state *crtc_state; 6665 int ret; 6666 6667 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); 6668 if (IS_ERR(crtc_state)) 6669 return PTR_ERR(crtc_state); 6670 6671 if (!crtc_state->hw.enable) 6672 continue; 6673 6674 if (!(transcoders & BIT(crtc_state->cpu_transcoder))) 6675 continue; 6676 6677 crtc_state->uapi.mode_changed = true; 6678 6679 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base); 6680 if (ret) 6681 return ret; 6682 6683 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base); 6684 if (ret) 6685 return ret; 6686 6687 transcoders &= ~BIT(crtc_state->cpu_transcoder); 6688 } 6689 6690 drm_WARN_ON(display->drm, transcoders != 0); 6691 6692 return 0; 6693 } 6694 6695 static int intel_modeset_synced_crtcs(struct intel_atomic_state *state, 6696 struct drm_connector *_connector) 6697 { 6698 struct intel_connector *connector = to_intel_connector(_connector); 6699 const struct drm_connector_state *old_conn_state = 6700 drm_atomic_get_old_connector_state(&state->base, &connector->base); 6701 const struct intel_crtc_state *old_crtc_state; 6702 struct intel_crtc *crtc; 6703 u16 transcoders; 6704 6705 crtc = to_intel_crtc(old_conn_state->crtc); 6706 if (!crtc) 6707 return 0; 6708 6709 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc); 6710 6711 if (!old_crtc_state->hw.active) 6712 return 0; 6713 6714 transcoders = old_crtc_state->sync_mode_slaves_mask; 6715 if (old_crtc_state->master_transcoder != INVALID_TRANSCODER) 6716 transcoders |= BIT(old_crtc_state->master_transcoder); 6717 6718 return intel_modeset_affected_transcoders(state, 6719 transcoders); 6720 } 6721 6722 static int intel_dp_connector_atomic_check(struct drm_connector *_connector, 6723 struct drm_atomic_commit *_state) 6724 { 6725 struct intel_connector *connector = to_intel_connector(_connector); 6726 struct intel_display *display = to_intel_display(connector); 6727 struct intel_atomic_state *state = to_intel_atomic_state(_state); 6728 struct drm_connector_state *conn_state = 6729 drm_atomic_get_new_connector_state(_state, &connector->base); 6730 struct intel_dp *intel_dp = enc_to_intel_dp(connector->encoder); 6731 int ret; 6732 6733 ret = intel_digital_connector_atomic_check(&connector->base, &state->base); 6734 if (ret) 6735 return ret; 6736 6737 if (intel_dp_mst_source_support(intel_dp)) { 6738 ret = drm_dp_mst_root_conn_atomic_check(conn_state, &intel_dp->mst.mgr); 6739 if (ret) 6740 return ret; 6741 } 6742 6743 if (!intel_connector_needs_modeset(state, &connector->base)) 6744 return 0; 6745 6746 ret = intel_dp_tunnel_atomic_check_state(state, 6747 intel_dp, 6748 connector); 6749 if (ret) 6750 return ret; 6751 6752 /* 6753 * We don't enable port sync on BDW due to missing w/as and 6754 * due to not having adjusted the modeset sequence appropriately. 6755 */ 6756 if (DISPLAY_VER(display) < 9) 6757 return 0; 6758 6759 if (connector->base.has_tile) { 6760 ret = intel_modeset_tile_group(state, connector->base.tile_group->id); 6761 if (ret) 6762 return ret; 6763 } 6764 6765 return intel_modeset_synced_crtcs(state, &connector->base); 6766 } 6767 6768 static void intel_dp_oob_hotplug_event(struct drm_connector *_connector, 6769 enum drm_connector_status hpd_state) 6770 { 6771 struct intel_connector *connector = to_intel_connector(_connector); 6772 struct intel_display *display = to_intel_display(connector); 6773 struct intel_encoder *encoder = intel_attached_encoder(connector); 6774 bool hpd_high = hpd_state == connector_status_connected; 6775 unsigned int hpd_pin = encoder->hpd_pin; 6776 bool need_work = false; 6777 6778 spin_lock_irq(&display->irq.lock); 6779 if (hpd_high != test_bit(hpd_pin, &display->hotplug.oob_hotplug_last_state)) { 6780 display->hotplug.event_bits |= BIT(hpd_pin); 6781 6782 __assign_bit(hpd_pin, 6783 &display->hotplug.oob_hotplug_last_state, 6784 hpd_high); 6785 need_work = true; 6786 } 6787 spin_unlock_irq(&display->irq.lock); 6788 6789 if (need_work) 6790 intel_hpd_schedule_detection(display); 6791 } 6792 6793 static const struct drm_connector_funcs intel_dp_connector_funcs = { 6794 .force = intel_dp_force, 6795 .fill_modes = drm_helper_probe_single_connector_modes, 6796 .atomic_get_property = intel_digital_connector_atomic_get_property, 6797 .atomic_set_property = intel_digital_connector_atomic_set_property, 6798 .late_register = intel_dp_connector_register, 6799 .early_unregister = intel_dp_connector_unregister, 6800 .destroy = intel_connector_destroy, 6801 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 6802 .atomic_duplicate_state = intel_digital_connector_duplicate_state, 6803 .oob_hotplug_event = intel_dp_oob_hotplug_event, 6804 }; 6805 6806 static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { 6807 .detect_ctx = intel_dp_detect, 6808 .get_modes = intel_dp_get_modes, 6809 .mode_valid = intel_dp_mode_valid, 6810 .atomic_check = intel_dp_connector_atomic_check, 6811 }; 6812 6813 enum irqreturn 6814 intel_dp_hpd_pulse(struct intel_digital_port *dig_port, bool long_hpd) 6815 { 6816 struct intel_display *display = to_intel_display(dig_port); 6817 struct intel_dp *intel_dp = &dig_port->dp; 6818 u8 dpcd[DP_RECEIVER_CAP_SIZE]; 6819 6820 if (dig_port->base.type == INTEL_OUTPUT_EDP && 6821 (long_hpd || 6822 intel_display_rpm_suspended(display) || 6823 !intel_pps_have_panel_power_or_vdd(intel_dp))) { 6824 /* 6825 * vdd off can generate a long/short pulse on eDP which 6826 * would require vdd on to handle it, and thus we 6827 * would end up in an endless cycle of 6828 * "vdd off -> long/short hpd -> vdd on -> detect -> vdd off -> ..." 6829 */ 6830 drm_dbg_kms(display->drm, 6831 "ignoring %s hpd on eDP [ENCODER:%d:%s]\n", 6832 long_hpd ? "long" : "short", 6833 dig_port->base.base.base.id, 6834 dig_port->base.base.name); 6835 return IRQ_HANDLED; 6836 } 6837 6838 drm_dbg_kms(display->drm, "got hpd irq on [ENCODER:%d:%s] - %s\n", 6839 dig_port->base.base.base.id, 6840 dig_port->base.base.name, 6841 long_hpd ? "long" : "short"); 6842 6843 /* 6844 * TBT DP tunnels require the GFX driver to read out the DPRX caps in 6845 * response to long HPD pulses. The DP hotplug handler does that, 6846 * however the hotplug handler may be blocked by another 6847 * connector's/encoder's hotplug handler. Since the TBT CM may not 6848 * complete the DP tunnel BW request for the latter connector/encoder 6849 * waiting for this encoder's DPRX read, perform a dummy read here. 6850 */ 6851 if (long_hpd) { 6852 intel_dp_dpcd_set_probe(intel_dp, true); 6853 6854 intel_dp_read_dprx_caps(intel_dp, dpcd); 6855 6856 intel_dp->reset_link_params = true; 6857 intel_dp_invalidate_source_oui(intel_dp); 6858 6859 return IRQ_NONE; 6860 } 6861 6862 if (intel_dp->is_mst) { 6863 if (!intel_dp_check_mst_status(intel_dp)) 6864 return IRQ_NONE; 6865 } else if (!intel_dp_short_pulse(intel_dp)) { 6866 return IRQ_NONE; 6867 } 6868 6869 return IRQ_HANDLED; 6870 } 6871 6872 static bool _intel_dp_is_port_edp(struct intel_display *display, 6873 const struct intel_bios_encoder_data *devdata, 6874 enum port port) 6875 { 6876 /* 6877 * eDP not supported on g4x. so bail out early just 6878 * for a bit extra safety in case the VBT is bonkers. 6879 */ 6880 if (DISPLAY_VER(display) < 5) 6881 return false; 6882 6883 if (DISPLAY_VER(display) < 9 && port == PORT_A) 6884 return true; 6885 6886 return devdata && intel_bios_encoder_supports_edp(devdata); 6887 } 6888 6889 bool intel_dp_is_port_edp(struct intel_display *display, enum port port) 6890 { 6891 const struct intel_bios_encoder_data *devdata = 6892 intel_bios_encoder_data_lookup(display, port); 6893 6894 return _intel_dp_is_port_edp(display, devdata, port); 6895 } 6896 6897 bool 6898 intel_dp_has_gamut_metadata_dip(struct intel_encoder *encoder) 6899 { 6900 struct intel_display *display = to_intel_display(encoder); 6901 enum port port = encoder->port; 6902 6903 if (intel_bios_encoder_is_lspcon(encoder->devdata)) 6904 return false; 6905 6906 if (DISPLAY_VER(display) >= 11) 6907 return true; 6908 6909 if (port == PORT_A) 6910 return false; 6911 6912 if (display->platform.haswell || display->platform.broadwell || 6913 DISPLAY_VER(display) >= 9) 6914 return true; 6915 6916 return false; 6917 } 6918 6919 static void 6920 intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *_connector) 6921 { 6922 struct intel_connector *connector = to_intel_connector(_connector); 6923 struct intel_display *display = to_intel_display(intel_dp); 6924 enum port port = dp_to_dig_port(intel_dp)->base.port; 6925 6926 if (!intel_dp_is_edp(intel_dp)) 6927 drm_connector_attach_dp_subconnector_property(&connector->base); 6928 6929 if (!display->platform.g4x && port != PORT_A) 6930 intel_attach_force_audio_property(&connector->base); 6931 6932 intel_attach_broadcast_rgb_property(&connector->base); 6933 if (HAS_GMCH(display)) 6934 drm_connector_attach_max_bpc_property(&connector->base, 6, 10); 6935 else if (DISPLAY_VER(display) >= 5) 6936 drm_connector_attach_max_bpc_property(&connector->base, 6, 12); 6937 6938 /* Register HDMI colorspace for case of lspcon */ 6939 if (intel_bios_encoder_is_lspcon(dp_to_dig_port(intel_dp)->base.devdata)) { 6940 drm_connector_attach_content_type_property(&connector->base); 6941 intel_attach_hdmi_colorspace_property(&connector->base); 6942 } else { 6943 intel_attach_dp_colorspace_property(&connector->base); 6944 } 6945 6946 if (intel_dp_has_gamut_metadata_dip(&dp_to_dig_port(intel_dp)->base)) 6947 drm_connector_attach_hdr_output_metadata_property(&connector->base); 6948 6949 if (HAS_VRR(display)) 6950 drm_connector_attach_vrr_capable_property(&connector->base); 6951 } 6952 6953 static void 6954 intel_edp_add_properties(struct intel_dp *intel_dp) 6955 { 6956 struct intel_display *display = to_intel_display(intel_dp); 6957 struct intel_connector *connector = intel_dp->attached_connector; 6958 const struct drm_display_mode *fixed_mode = 6959 intel_panel_preferred_fixed_mode(connector); 6960 6961 intel_attach_scaling_mode_property(&connector->base); 6962 6963 drm_connector_set_panel_orientation_with_quirk(&connector->base, 6964 display->vbt.orientation, 6965 fixed_mode->hdisplay, 6966 fixed_mode->vdisplay); 6967 } 6968 6969 static void intel_edp_backlight_setup(struct intel_dp *intel_dp, 6970 struct intel_connector *connector) 6971 { 6972 struct intel_display *display = to_intel_display(intel_dp); 6973 enum pipe pipe = INVALID_PIPE; 6974 6975 if (display->platform.valleyview || display->platform.cherryview) 6976 pipe = vlv_pps_backlight_initial_pipe(intel_dp); 6977 6978 intel_backlight_setup(connector, pipe); 6979 } 6980 6981 static bool intel_edp_init_connector(struct intel_dp *intel_dp, 6982 struct intel_connector *connector) 6983 { 6984 struct intel_display *display = to_intel_display(intel_dp); 6985 struct drm_display_mode *fixed_mode; 6986 struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 6987 bool has_dpcd; 6988 const struct drm_edid *drm_edid; 6989 6990 if (!intel_dp_is_edp(intel_dp)) 6991 return true; 6992 6993 /* 6994 * On IBX/CPT we may get here with LVDS already registered. Since the 6995 * driver uses the only internal power sequencer available for both 6996 * eDP and LVDS bail out early in this case to prevent interfering 6997 * with an already powered-on LVDS power sequencer. 6998 */ 6999 if (intel_get_lvds_encoder(display)) { 7000 drm_WARN_ON(display->drm, 7001 !(HAS_PCH_IBX(display) || HAS_PCH_CPT(display))); 7002 drm_info(display->drm, 7003 "LVDS was detected, not registering eDP\n"); 7004 7005 return false; 7006 } 7007 7008 intel_bios_init_panel_early(display, &connector->panel, 7009 encoder->devdata); 7010 7011 if (!intel_pps_init(intel_dp)) { 7012 drm_info(display->drm, 7013 "[ENCODER:%d:%s] unusable PPS, disabling eDP\n", 7014 encoder->base.base.id, encoder->base.name); 7015 /* 7016 * The BIOS may have still enabled VDD on the PPS even 7017 * though it's unusable. Make sure we turn it back off 7018 * and to release the power domain references/etc. 7019 */ 7020 goto out_vdd_off; 7021 } 7022 7023 /* 7024 * Enable HPD sense for live status check. 7025 * intel_hpd_irq_setup() will turn it off again 7026 * if it's no longer needed later. 7027 * 7028 * The DPCD probe below will make sure VDD is on. 7029 */ 7030 intel_hpd_enable_detection(encoder); 7031 7032 intel_alpm_init(intel_dp); 7033 7034 /* Cache DPCD and EDID for edp. */ 7035 has_dpcd = intel_edp_init_dpcd(intel_dp, connector); 7036 7037 if (!has_dpcd) { 7038 /* if this fails, presume the device is a ghost */ 7039 drm_info(display->drm, 7040 "[ENCODER:%d:%s] failed to retrieve link info, disabling eDP\n", 7041 encoder->base.base.id, encoder->base.name); 7042 goto out_vdd_off; 7043 } 7044 7045 /* 7046 * VBT and straps are liars. Also check HPD as that seems 7047 * to be the most reliable piece of information available. 7048 * 7049 * ... expect on devices that forgot to hook HPD up for eDP 7050 * (eg. Acer Chromebook C710), so we'll check it only if multiple 7051 * ports are attempting to use the same AUX CH, according to VBT. 7052 */ 7053 if (intel_bios_dp_has_shared_aux_ch(encoder->devdata)) { 7054 /* 7055 * If this fails, presume the DPCD answer came 7056 * from some other port using the same AUX CH. 7057 * 7058 * FIXME maybe cleaner to check this before the 7059 * DPCD read? Would need sort out the VDD handling... 7060 */ 7061 if (!intel_digital_port_connected(encoder)) { 7062 drm_info(display->drm, 7063 "[ENCODER:%d:%s] HPD is down, disabling eDP\n", 7064 encoder->base.base.id, encoder->base.name); 7065 goto out_vdd_off; 7066 } 7067 7068 /* 7069 * Unfortunately even the HPD based detection fails on 7070 * eg. Asus B360M-A (CFL+CNP), so as a last resort fall 7071 * back to checking for a VGA branch device. Only do this 7072 * on known affected platforms to minimize false positives. 7073 */ 7074 if (DISPLAY_VER(display) == 9 && drm_dp_is_branch(intel_dp->dpcd) && 7075 (intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_TYPE_MASK) == 7076 DP_DWN_STRM_PORT_TYPE_ANALOG) { 7077 drm_info(display->drm, 7078 "[ENCODER:%d:%s] VGA converter detected, disabling eDP\n", 7079 encoder->base.base.id, encoder->base.name); 7080 goto out_vdd_off; 7081 } 7082 } 7083 7084 mutex_lock(&display->drm->mode_config.mutex); 7085 drm_edid = drm_edid_read_ddc(&connector->base, connector->base.ddc); 7086 if (!drm_edid) { 7087 /* Fallback to EDID from ACPI OpRegion, if any */ 7088 drm_edid = intel_opregion_get_edid(connector); 7089 if (drm_edid) 7090 drm_dbg_kms(display->drm, 7091 "[CONNECTOR:%d:%s] Using OpRegion EDID\n", 7092 connector->base.base.id, connector->base.name); 7093 } 7094 if (drm_edid) { 7095 if (drm_edid_connector_update(&connector->base, drm_edid) || 7096 !drm_edid_connector_add_modes(&connector->base)) { 7097 drm_edid_connector_update(&connector->base, NULL); 7098 drm_edid_free(drm_edid); 7099 drm_edid = ERR_PTR(-EINVAL); 7100 } 7101 } else { 7102 drm_edid = ERR_PTR(-ENOENT); 7103 } 7104 7105 intel_bios_init_panel_late(display, &connector->panel, encoder->devdata, 7106 IS_ERR(drm_edid) ? NULL : drm_edid); 7107 7108 intel_panel_add_edid_fixed_modes(connector, true); 7109 7110 /* MSO requires information from the EDID */ 7111 intel_edp_mso_init(intel_dp); 7112 7113 /* multiply the mode clock and horizontal timings for MSO */ 7114 list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) 7115 intel_edp_mso_mode_fixup(connector, fixed_mode); 7116 7117 /* fallback to VBT if available for eDP */ 7118 if (!intel_panel_preferred_fixed_mode(connector)) 7119 intel_panel_add_vbt_lfp_fixed_mode(connector); 7120 7121 mutex_unlock(&display->drm->mode_config.mutex); 7122 7123 if (!intel_panel_preferred_fixed_mode(connector)) { 7124 drm_info(display->drm, 7125 "[ENCODER:%d:%s] failed to find fixed mode for the panel, disabling eDP\n", 7126 encoder->base.base.id, encoder->base.name); 7127 goto out_vdd_off; 7128 } 7129 7130 intel_panel_init(connector, drm_edid); 7131 7132 intel_edp_backlight_setup(intel_dp, connector); 7133 7134 intel_edp_add_properties(intel_dp); 7135 7136 intel_pps_init_late(intel_dp); 7137 7138 return true; 7139 7140 out_vdd_off: 7141 intel_pps_vdd_off_sync(intel_dp); 7142 intel_bios_fini_panel(&connector->panel); 7143 7144 return false; 7145 } 7146 7147 bool 7148 intel_dp_init_connector(struct intel_digital_port *dig_port, 7149 struct intel_connector *connector) 7150 { 7151 struct intel_display *display = to_intel_display(dig_port); 7152 struct intel_dp *intel_dp = &dig_port->dp; 7153 struct intel_encoder *encoder = &dig_port->base; 7154 struct drm_device *dev = encoder->base.dev; 7155 enum port port = encoder->port; 7156 int type; 7157 7158 if (drm_WARN(dev, dig_port->max_lanes < 1, 7159 "Not enough lanes (%d) for DP on [ENCODER:%d:%s]\n", 7160 dig_port->max_lanes, encoder->base.base.id, 7161 encoder->base.name)) 7162 return false; 7163 7164 intel_dp->reset_link_params = true; 7165 7166 /* Preserve the current hw state. */ 7167 intel_dp->DP = intel_de_read(display, intel_dp->output_reg); 7168 intel_dp->attached_connector = connector; 7169 7170 if (_intel_dp_is_port_edp(display, encoder->devdata, port)) { 7171 /* 7172 * Currently we don't support eDP on TypeC ports for DISPLAY_VER < 30, 7173 * although in theory it could work on TypeC legacy ports. 7174 */ 7175 drm_WARN_ON(dev, intel_encoder_is_tc(encoder) && 7176 DISPLAY_VER(display) < 30); 7177 type = DRM_MODE_CONNECTOR_eDP; 7178 encoder->type = INTEL_OUTPUT_EDP; 7179 7180 /* eDP only on port B and/or C on vlv/chv */ 7181 if (drm_WARN_ON(dev, (display->platform.valleyview || 7182 display->platform.cherryview) && 7183 port != PORT_B && port != PORT_C)) 7184 return false; 7185 } else { 7186 type = DRM_MODE_CONNECTOR_DisplayPort; 7187 } 7188 7189 intel_dp_set_default_sink_rates(intel_dp); 7190 intel_dp_set_default_max_sink_lane_count(intel_dp); 7191 7192 if (display->platform.valleyview || display->platform.cherryview) 7193 vlv_pps_pipe_init(intel_dp); 7194 7195 intel_dp_aux_init(intel_dp); 7196 connector->dp.dsc_decompression_aux = &intel_dp->aux; 7197 7198 drm_dbg_kms(display->drm, 7199 "Adding %s connector on [ENCODER:%d:%s]\n", 7200 type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP", 7201 encoder->base.base.id, encoder->base.name); 7202 7203 drm_connector_init_with_ddc(dev, &connector->base, &intel_dp_connector_funcs, 7204 type, &intel_dp->aux.ddc); 7205 drm_connector_helper_add(&connector->base, &intel_dp_connector_helper_funcs); 7206 7207 if (!HAS_GMCH(display) && DISPLAY_VER(display) < 12) 7208 connector->base.interlace_allowed = true; 7209 7210 if (type != DRM_MODE_CONNECTOR_eDP) 7211 connector->polled = DRM_CONNECTOR_POLL_HPD; 7212 connector->base.polled = connector->polled; 7213 7214 intel_connector_attach_encoder(connector, encoder); 7215 7216 if (HAS_DDI(display)) 7217 connector->get_hw_state = intel_ddi_connector_get_hw_state; 7218 else 7219 connector->get_hw_state = intel_connector_get_hw_state; 7220 connector->sync_state = intel_dp_connector_sync_state; 7221 7222 if (!intel_edp_init_connector(intel_dp, connector)) { 7223 intel_dp_aux_fini(intel_dp); 7224 goto fail; 7225 } 7226 7227 intel_dp_set_source_rates(intel_dp); 7228 intel_dp_set_common_link_params(intel_dp); 7229 intel_dp_reset_link_params(intel_dp); 7230 7231 /* init MST on ports that can support it */ 7232 intel_dp_mst_encoder_init(dig_port, connector->base.base.id); 7233 7234 intel_dp_add_properties(intel_dp, &connector->base); 7235 7236 if (is_hdcp_supported(display, port) && !intel_dp_is_edp(intel_dp)) { 7237 int ret = intel_dp_hdcp_init(dig_port, connector); 7238 if (ret) 7239 drm_dbg_kms(display->drm, 7240 "HDCP init failed, skipping.\n"); 7241 } 7242 7243 intel_dp->frl.is_trained = false; 7244 intel_dp->frl.trained_rate_gbps = 0; 7245 7246 intel_psr_init(intel_dp); 7247 7248 return true; 7249 7250 fail: 7251 intel_display_power_flush_work(display); 7252 drm_connector_cleanup(&connector->base); 7253 7254 return false; 7255 } 7256 7257 void intel_dp_cleanup_connector(struct intel_digital_port *dig_port, 7258 struct intel_connector *connector) 7259 { 7260 struct intel_display *display = to_intel_display(connector); 7261 struct intel_dp *intel_dp = &dig_port->dp; 7262 7263 intel_display_power_flush_work(display); 7264 7265 intel_dp_mst_encoder_cleanup(dig_port); 7266 intel_dp_aux_fini(intel_dp); 7267 drm_connector_cleanup(&connector->base); 7268 } 7269 7270 void intel_dp_mst_suspend(struct intel_display *display) 7271 { 7272 struct intel_encoder *encoder; 7273 7274 if (!HAS_DISPLAY(display)) 7275 return; 7276 7277 for_each_intel_encoder(display->drm, encoder) { 7278 struct intel_dp *intel_dp; 7279 7280 if (encoder->type != INTEL_OUTPUT_DDI) 7281 continue; 7282 7283 intel_dp = enc_to_intel_dp(encoder); 7284 7285 if (!intel_dp_mst_source_support(intel_dp)) 7286 continue; 7287 7288 if (intel_dp->is_mst) 7289 drm_dp_mst_topology_mgr_suspend(&intel_dp->mst.mgr); 7290 } 7291 } 7292 7293 void intel_dp_mst_resume(struct intel_display *display) 7294 { 7295 struct intel_encoder *encoder; 7296 7297 if (!HAS_DISPLAY(display)) 7298 return; 7299 7300 for_each_intel_encoder(display->drm, encoder) { 7301 struct intel_dp *intel_dp; 7302 int ret; 7303 7304 if (encoder->type != INTEL_OUTPUT_DDI) 7305 continue; 7306 7307 intel_dp = enc_to_intel_dp(encoder); 7308 7309 if (!intel_dp_mst_source_support(intel_dp)) 7310 continue; 7311 7312 ret = drm_dp_mst_topology_mgr_resume(&intel_dp->mst.mgr, true); 7313 if (ret) { 7314 intel_dp->is_mst = false; 7315 drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst.mgr, false); 7316 } 7317 } 7318 } 7319 7320 static 7321 int intel_dp_sdp_compute_config_late(struct intel_crtc_state *crtc_state) 7322 { 7323 struct intel_display *display = to_intel_display(crtc_state); 7324 int guardband = intel_crtc_vblank_length(crtc_state); 7325 int min_sdp_guardband = intel_dp_sdp_min_guardband(crtc_state, false); 7326 7327 if (guardband < min_sdp_guardband) { 7328 drm_dbg_kms(display->drm, "guardband %d < min sdp guardband %d\n", 7329 guardband, min_sdp_guardband); 7330 return -EINVAL; 7331 } 7332 7333 return 0; 7334 } 7335 7336 int intel_dp_compute_config_late(struct intel_encoder *encoder, 7337 struct intel_crtc_state *crtc_state, 7338 struct drm_connector_state *conn_state) 7339 { 7340 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 7341 int ret; 7342 7343 intel_psr_compute_config_late(intel_dp, crtc_state); 7344 7345 ret = intel_dp_sdp_compute_config_late(crtc_state); 7346 if (ret) 7347 return ret; 7348 7349 intel_alpm_lobf_compute_config_late(intel_dp, crtc_state); 7350 7351 return 0; 7352 } 7353 7354 static 7355 int intel_dp_get_lines_for_sdp(const struct intel_crtc_state *crtc_state, u32 type) 7356 { 7357 switch (type) { 7358 case DP_SDP_VSC_EXT_VESA: 7359 case DP_SDP_VSC_EXT_CEA: 7360 return 10; 7361 case HDMI_PACKET_TYPE_GAMUT_METADATA: 7362 return 8; 7363 case DP_SDP_PPS: 7364 return 7; 7365 case DP_SDP_ADAPTIVE_SYNC: 7366 return crtc_state->vrr.vsync_start + 1; 7367 default: 7368 break; 7369 } 7370 7371 return 0; 7372 } 7373 7374 int intel_dp_sdp_min_guardband(const struct intel_crtc_state *crtc_state, 7375 bool assume_all_enabled) 7376 { 7377 int sdp_guardband = 0; 7378 7379 if (assume_all_enabled || 7380 crtc_state->infoframes.enable & 7381 intel_hdmi_infoframe_enable(HDMI_PACKET_TYPE_GAMUT_METADATA)) 7382 sdp_guardband = max(sdp_guardband, 7383 intel_dp_get_lines_for_sdp(crtc_state, 7384 HDMI_PACKET_TYPE_GAMUT_METADATA)); 7385 7386 if (assume_all_enabled || 7387 crtc_state->dsc.compression_enable) 7388 sdp_guardband = max(sdp_guardband, 7389 intel_dp_get_lines_for_sdp(crtc_state, DP_SDP_PPS)); 7390 7391 if (crtc_state->infoframes.enable & 7392 intel_hdmi_infoframe_enable(DP_SDP_ADAPTIVE_SYNC)) 7393 sdp_guardband = max(sdp_guardband, 7394 intel_dp_get_lines_for_sdp(crtc_state, DP_SDP_ADAPTIVE_SYNC)); 7395 7396 return sdp_guardband; 7397 } 7398 7399 bool intel_dp_joiner_candidate_valid(struct intel_connector *connector, 7400 int hdisplay, 7401 int num_joined_pipes) 7402 { 7403 struct intel_display *display = to_intel_display(connector); 7404 struct intel_dp *intel_dp = intel_attached_dp(connector); 7405 7406 if (!intel_dp_can_join(intel_dp, num_joined_pipes)) 7407 return false; 7408 7409 if (hdisplay > num_joined_pipes * intel_dp_max_hdisplay_per_pipe(display)) 7410 return false; 7411 7412 if (connector->force_joined_pipes && connector->force_joined_pipes != num_joined_pipes) 7413 return false; 7414 7415 return true; 7416 } 7417 7418 u8 intel_dp_as_sdp_transmission_time(void) 7419 { 7420 /* 7421 * DP allows AS SDP position to move during PR active in some cases, but 7422 * software-controlled refresh rate changes with DC6v / ALPM require the 7423 * AS SDP to remain at T1. Use T1 unconditionally for now. 7424 */ 7425 7426 return DP_PR_AS_SDP_SETUP_TIME_T1; 7427 } 7428 7429 int intel_dp_link_init(struct intel_dp *intel_dp) 7430 { 7431 intel_dp->link.training = intel_dp_link_training_init(intel_dp); 7432 if (!intel_dp->link.training) 7433 return -ENOMEM; 7434 7435 intel_dp->link.caps = intel_dp_link_caps_init(intel_dp); 7436 if (!intel_dp->link.caps) { 7437 intel_dp_link_training_cleanup(intel_dp->link.training); 7438 7439 return -ENOMEM; 7440 } 7441 7442 return 0; 7443 } 7444 7445 void intel_dp_link_cleanup(struct intel_dp *intel_dp) 7446 { 7447 intel_dp_link_caps_cleanup(intel_dp->link.caps); 7448 intel_dp_link_training_cleanup(intel_dp->link.training); 7449 } 7450