1 /* 2 * Copyright 2023 Advanced Micro Devices, Inc. 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 shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 /* FILE POLICY AND INTENDED USAGE: 27 * This file owns timing validation against various link limitations. (ex. 28 * link bandwidth, receiver capability or our hardware capability) It also 29 * provides helper functions exposing bandwidth formulas used in validation. 30 */ 31 #include "link_validation.h" 32 #include "protocols/link_dp_capability.h" 33 #include "protocols/link_dp_dpia_bw.h" 34 #include "resource.h" 35 36 #define DC_LOGGER_INIT(logger) 37 38 static uint32_t get_tmds_output_pixel_clock_100hz(const struct dc_crtc_timing *timing) 39 { 40 41 uint32_t pxl_clk = timing->pix_clk_100hz; 42 43 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) 44 pxl_clk /= 2; 45 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) 46 pxl_clk = pxl_clk * 2 / 3; 47 48 if (timing->display_color_depth == COLOR_DEPTH_101010) 49 pxl_clk = pxl_clk * 10 / 8; 50 else if (timing->display_color_depth == COLOR_DEPTH_121212) 51 pxl_clk = pxl_clk * 12 / 8; 52 53 return pxl_clk; 54 } 55 56 static bool dp_active_dongle_validate_timing( 57 const struct dc_crtc_timing *timing, 58 const struct dpcd_caps *dpcd_caps) 59 { 60 const struct dc_dongle_caps *dongle_caps = &dpcd_caps->dongle_caps; 61 62 switch (dpcd_caps->dongle_type) { 63 case DISPLAY_DONGLE_DP_VGA_CONVERTER: 64 case DISPLAY_DONGLE_DP_DVI_CONVERTER: 65 case DISPLAY_DONGLE_DP_DVI_DONGLE: 66 if (timing->pixel_encoding == PIXEL_ENCODING_RGB) 67 return true; 68 else 69 return false; 70 default: 71 break; 72 } 73 74 if (dpcd_caps->dongle_type == DISPLAY_DONGLE_DP_HDMI_CONVERTER && 75 dongle_caps->extendedCapValid == true) { 76 /* Check Pixel Encoding */ 77 switch (timing->pixel_encoding) { 78 case PIXEL_ENCODING_RGB: 79 case PIXEL_ENCODING_YCBCR444: 80 break; 81 case PIXEL_ENCODING_YCBCR422: 82 if (!dongle_caps->is_dp_hdmi_ycbcr422_pass_through) 83 return false; 84 break; 85 case PIXEL_ENCODING_YCBCR420: 86 if (!dongle_caps->is_dp_hdmi_ycbcr420_pass_through) 87 return false; 88 break; 89 case PIXEL_ENCODING_UNDEFINED: 90 /* These color depths are currently not supported */ 91 ASSERT(false); 92 break; 93 default: 94 /* Invalid Pixel Encoding*/ 95 return false; 96 } 97 98 switch (timing->display_color_depth) { 99 case COLOR_DEPTH_666: 100 case COLOR_DEPTH_888: 101 /*888 and 666 should always be supported*/ 102 break; 103 case COLOR_DEPTH_101010: 104 if (dongle_caps->dp_hdmi_max_bpc < 10) 105 return false; 106 break; 107 case COLOR_DEPTH_121212: 108 if (dongle_caps->dp_hdmi_max_bpc < 12) 109 return false; 110 break; 111 case COLOR_DEPTH_UNDEFINED: 112 /* These color depths are currently not supported */ 113 ASSERT(false); 114 break; 115 case COLOR_DEPTH_141414: 116 case COLOR_DEPTH_161616: 117 default: 118 /* These color depths are currently not supported */ 119 return false; 120 } 121 122 /* Check 3D format */ 123 switch (timing->timing_3d_format) { 124 case TIMING_3D_FORMAT_NONE: 125 case TIMING_3D_FORMAT_FRAME_ALTERNATE: 126 /*Only frame alternate 3D is supported on active dongle*/ 127 break; 128 default: 129 /*other 3D formats are not supported due to bad infoframe translation */ 130 return false; 131 } 132 133 if (dongle_caps->dp_hdmi_frl_max_link_bw_in_kbps > 0) { // DP to HDMI FRL converter 134 struct dc_crtc_timing outputTiming = *timing; 135 136 if (timing->flags.DSC && !timing->dsc_cfg.is_frl) 137 /* DP input has DSC, HDMI FRL output doesn't have DSC, remove DSC from output timing */ 138 outputTiming.flags.DSC = 0; 139 if (dc_bandwidth_in_kbps_from_timing(&outputTiming, DC_LINK_ENCODING_HDMI_FRL) > 140 dongle_caps->dp_hdmi_frl_max_link_bw_in_kbps) 141 return false; 142 } else { // DP to HDMI TMDS converter 143 if (get_tmds_output_pixel_clock_100hz(timing) > (dongle_caps->dp_hdmi_max_pixel_clk_in_khz * 10)) 144 return false; 145 } 146 } 147 148 if (dpcd_caps->channel_coding_cap.bits.DP_128b_132b_SUPPORTED == 0 && 149 dpcd_caps->dsc_caps.dsc_basic_caps.fields.dsc_support.DSC_PASSTHROUGH_SUPPORT == 0 && 150 dongle_caps->dfp_cap_ext.supported) { 151 152 if (dongle_caps->dfp_cap_ext.max_pixel_rate_in_mps < (timing->pix_clk_100hz / 10000)) 153 return false; 154 155 if (dongle_caps->dfp_cap_ext.max_video_h_active_width < timing->h_addressable) 156 return false; 157 158 if (dongle_caps->dfp_cap_ext.max_video_v_active_height < timing->v_addressable) 159 return false; 160 161 if (timing->pixel_encoding == PIXEL_ENCODING_RGB) { 162 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb) 163 return false; 164 if (timing->display_color_depth == COLOR_DEPTH_666 && 165 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_6bpc) 166 return false; 167 else if (timing->display_color_depth == COLOR_DEPTH_888 && 168 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_8bpc) 169 return false; 170 else if (timing->display_color_depth == COLOR_DEPTH_101010 && 171 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_10bpc) 172 return false; 173 else if (timing->display_color_depth == COLOR_DEPTH_121212 && 174 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_12bpc) 175 return false; 176 else if (timing->display_color_depth == COLOR_DEPTH_161616 && 177 !dongle_caps->dfp_cap_ext.rgb_color_depth_caps.support_16bpc) 178 return false; 179 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) { 180 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb) 181 return false; 182 if (timing->display_color_depth == COLOR_DEPTH_888 && 183 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_8bpc) 184 return false; 185 else if (timing->display_color_depth == COLOR_DEPTH_101010 && 186 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_10bpc) 187 return false; 188 else if (timing->display_color_depth == COLOR_DEPTH_121212 && 189 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_12bpc) 190 return false; 191 else if (timing->display_color_depth == COLOR_DEPTH_161616 && 192 !dongle_caps->dfp_cap_ext.ycbcr444_color_depth_caps.support_16bpc) 193 return false; 194 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) { 195 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb) 196 return false; 197 if (timing->display_color_depth == COLOR_DEPTH_888 && 198 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_8bpc) 199 return false; 200 else if (timing->display_color_depth == COLOR_DEPTH_101010 && 201 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_10bpc) 202 return false; 203 else if (timing->display_color_depth == COLOR_DEPTH_121212 && 204 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_12bpc) 205 return false; 206 else if (timing->display_color_depth == COLOR_DEPTH_161616 && 207 !dongle_caps->dfp_cap_ext.ycbcr422_color_depth_caps.support_16bpc) 208 return false; 209 } else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) { 210 if (!dongle_caps->dfp_cap_ext.encoding_format_caps.support_rgb) 211 return false; 212 if (timing->display_color_depth == COLOR_DEPTH_888 && 213 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_8bpc) 214 return false; 215 else if (timing->display_color_depth == COLOR_DEPTH_101010 && 216 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_10bpc) 217 return false; 218 else if (timing->display_color_depth == COLOR_DEPTH_121212 && 219 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_12bpc) 220 return false; 221 else if (timing->display_color_depth == COLOR_DEPTH_161616 && 222 !dongle_caps->dfp_cap_ext.ycbcr420_color_depth_caps.support_16bpc) 223 return false; 224 } 225 } 226 227 return true; 228 } 229 230 uint32_t dp_link_bandwidth_kbps( 231 const struct dc_link *link, 232 const struct dc_link_settings *link_settings) 233 { 234 uint32_t total_data_bw_efficiency_x10000 = 0; 235 uint32_t link_rate_per_lane_kbps = 0; 236 237 switch (link_dp_get_encoding_format(link_settings)) { 238 case DP_8b_10b_ENCODING: 239 /* For 8b/10b encoding: 240 * link rate is defined in the unit of LINK_RATE_REF_FREQ_IN_KHZ per DP byte per lane. 241 * data bandwidth efficiency is 80% with additional 3% overhead if FEC is supported. 242 */ 243 link_rate_per_lane_kbps = link_settings->link_rate * LINK_RATE_REF_FREQ_IN_KHZ * BITS_PER_DP_BYTE; 244 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_8b_10b_x10000; 245 if (dp_should_enable_fec(link)) { 246 total_data_bw_efficiency_x10000 /= 100; 247 total_data_bw_efficiency_x10000 *= DATA_EFFICIENCY_8b_10b_FEC_EFFICIENCY_x100; 248 } 249 break; 250 case DP_128b_132b_ENCODING: 251 /* For 128b/132b encoding: 252 * link rate is defined in the unit of 10mbps per lane. 253 * total data bandwidth efficiency is always 96.71%. 254 */ 255 link_rate_per_lane_kbps = link_settings->link_rate * 10000; 256 total_data_bw_efficiency_x10000 = DATA_EFFICIENCY_128b_132b_x10000; 257 break; 258 default: 259 break; 260 } 261 262 /* overall effective link bandwidth = link rate per lane * lane count * total data bandwidth efficiency */ 263 return link_rate_per_lane_kbps * link_settings->lane_count / 10000 * total_data_bw_efficiency_x10000; 264 } 265 266 static bool dp_validate_mode_timing( 267 struct dc_link *link, 268 const struct dc_crtc_timing *timing) 269 { 270 uint32_t req_bw; 271 uint32_t max_bw; 272 273 const struct dc_link_settings *link_setting; 274 275 /* According to spec, VSC SDP should be used if pixel format is YCbCr420 */ 276 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 && 277 !link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED && 278 dal_graphics_object_id_get_connector_id(link->link_id) != CONNECTOR_ID_VIRTUAL) 279 return false; 280 281 /*always DP fail safe mode*/ 282 if ((timing->pix_clk_100hz / 10) == (uint32_t) 25175 && 283 timing->h_addressable == (uint32_t) 640 && 284 timing->v_addressable == (uint32_t) 480) 285 return true; 286 287 link_setting = dp_get_verified_link_cap(link); 288 289 /* TODO: DYNAMIC_VALIDATION needs to be implemented */ 290 /*if (flags.DYNAMIC_VALIDATION == 1 && 291 link->verified_link_cap.lane_count != LANE_COUNT_UNKNOWN) 292 link_setting = &link->verified_link_cap; 293 */ 294 295 req_bw = dc_bandwidth_in_kbps_from_timing(timing, dc_link_get_highest_encoding_format(link)); 296 max_bw = dp_link_bandwidth_kbps(link, link_setting); 297 298 bool is_max_uncompressed_pixel_rate_exceeded = link->dpcd_caps.max_uncompressed_pixel_rate_cap.bits.valid && 299 timing->pix_clk_100hz > link->dpcd_caps.max_uncompressed_pixel_rate_cap.bits.max_uncompressed_pixel_rate_cap * 10000; 300 301 if (is_max_uncompressed_pixel_rate_exceeded && !timing->flags.DSC) { 302 return false; 303 } 304 305 if (req_bw <= max_bw) { 306 /* remember the biggest mode here, during 307 * initial link training (to get 308 * verified_link_cap), LS sends event about 309 * cannot train at reported cap to upper 310 * layer and upper layer will re-enumerate modes. 311 * this is not necessary if the lower 312 * verified_link_cap is enough to drive 313 * all the modes */ 314 315 /* TODO: DYNAMIC_VALIDATION needs to be implemented */ 316 /* if (flags.DYNAMIC_VALIDATION == 1) 317 dpsst->max_req_bw_for_verified_linkcap = dal_max( 318 dpsst->max_req_bw_for_verified_linkcap, req_bw); */ 319 return true; 320 } else 321 return false; 322 } 323 324 enum dc_status link_validate_mode_timing( 325 const struct dc_stream_state *stream, 326 struct dc_link *link, 327 const struct dc_crtc_timing *timing) 328 { 329 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10; 330 struct dpcd_caps *dpcd_caps = &link->dpcd_caps; 331 332 /* A hack to avoid failing any modes for EDID override feature on 333 * topology change such as lower quality cable for DP or different dongle 334 */ 335 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL) 336 return DC_OK; 337 338 /* Passive Dongle */ 339 if (max_pix_clk != 0 && get_tmds_output_pixel_clock_100hz(timing) > max_pix_clk) 340 return DC_EXCEED_DONGLE_CAP; 341 342 /* Active Dongle*/ 343 if (!dp_active_dongle_validate_timing(timing, dpcd_caps)) 344 return DC_EXCEED_DONGLE_CAP; 345 346 switch (stream->signal) { 347 case SIGNAL_TYPE_EDP: 348 case SIGNAL_TYPE_DISPLAY_PORT: 349 if (!dp_validate_mode_timing( 350 link, 351 timing)) 352 return DC_NO_DP_LINK_BANDWIDTH; 353 break; 354 355 default: 356 break; 357 } 358 359 return DC_OK; 360 } 361 362 /* 363 * This function calculates the bandwidth required for the stream timing 364 * and aggregates the stream bandwidth for the respective dpia link 365 * 366 * @stream: pointer to the dc_stream_state struct instance 367 * @num_streams: number of streams to be validated 368 * 369 * return: true if validation is succeeded 370 */ 371 bool link_validate_dpia_bandwidth(const struct dc_stream_state *stream, const unsigned int num_streams) 372 { 373 int bw_needed[MAX_DPIA_NUM] = {0}; 374 struct dc_link *dpia_link[MAX_DPIA_NUM] = {0}; 375 int num_dpias = 0; 376 377 for (unsigned int i = 0; i < num_streams; ++i) { 378 if (stream[i].signal == SIGNAL_TYPE_DISPLAY_PORT) { 379 /* new dpia sst stream, check whether it exceeds max dpia */ 380 if (num_dpias >= MAX_DPIA_NUM) 381 return false; 382 383 dpia_link[num_dpias] = stream[i].link; 384 bw_needed[num_dpias] = dc_bandwidth_in_kbps_from_timing(&stream[i].timing, 385 dc_link_get_highest_encoding_format(dpia_link[num_dpias])); 386 num_dpias++; 387 } else if (stream[i].signal == SIGNAL_TYPE_DISPLAY_PORT_MST) { 388 uint8_t j = 0; 389 /* check whether its a known dpia link */ 390 for (; j < num_dpias; ++j) { 391 if (dpia_link[j] == stream[i].link) 392 break; 393 } 394 395 if (j == num_dpias) { 396 /* new dpia mst stream, check whether it exceeds max dpia */ 397 if (num_dpias >= MAX_DPIA_NUM) 398 return false; 399 else { 400 dpia_link[j] = stream[i].link; 401 num_dpias++; 402 } 403 } 404 405 bw_needed[j] += dc_bandwidth_in_kbps_from_timing(&stream[i].timing, 406 dc_link_get_highest_encoding_format(dpia_link[j])); 407 } 408 } 409 410 /* Include dp overheads */ 411 for (uint8_t i = 0; i < num_dpias; ++i) { 412 int dp_overhead = 0; 413 414 dp_overhead = link_dp_dpia_get_dp_overhead_in_dp_tunneling(dpia_link[i]); 415 bw_needed[i] += dp_overhead; 416 } 417 418 return dpia_validate_usb4_bw(dpia_link, bw_needed, num_dpias); 419 } 420 421 struct dp_audio_layout_config { 422 uint8_t layouts_per_sample_denom; 423 uint8_t symbols_per_layout; 424 uint8_t max_layouts_per_audio_sdp; 425 }; 426 427 static void get_audio_layout_config( 428 uint32_t channel_count, 429 enum dp_link_encoding encoding, 430 struct dp_audio_layout_config *output) 431 { 432 memset(output, 0, sizeof(struct dp_audio_layout_config)); 433 434 /* Assuming L-PCM audio. Current implementation uses max 1 layout per SDP, 435 * with each layout being the same size (8ch layout). 436 */ 437 if (encoding == DP_8b_10b_ENCODING) { 438 if (channel_count == 2) { 439 output->layouts_per_sample_denom = 4; 440 output->symbols_per_layout = 40; 441 output->max_layouts_per_audio_sdp = 1; 442 } else if (channel_count == 8 || channel_count == 6) { 443 output->layouts_per_sample_denom = 1; 444 output->symbols_per_layout = 40; 445 output->max_layouts_per_audio_sdp = 1; 446 } 447 } else if (encoding == DP_128b_132b_ENCODING) { 448 if (channel_count == 2) { 449 output->layouts_per_sample_denom = 4; 450 output->symbols_per_layout = 10; 451 output->max_layouts_per_audio_sdp = 1; 452 } else if (channel_count == 8 || channel_count == 6) { 453 output->layouts_per_sample_denom = 1; 454 output->symbols_per_layout = 10; 455 output->max_layouts_per_audio_sdp = 1; 456 } 457 } 458 } 459 460 static uint32_t get_av_stream_map_lane_count( 461 enum dp_link_encoding encoding, 462 enum dc_lane_count lane_count, 463 bool is_mst) 464 { 465 uint32_t av_stream_map_lane_count = 0; 466 467 if (encoding == DP_8b_10b_ENCODING) { 468 if (!is_mst) 469 av_stream_map_lane_count = lane_count; 470 else 471 av_stream_map_lane_count = 4; 472 } else if (encoding == DP_128b_132b_ENCODING) { 473 av_stream_map_lane_count = 4; 474 } 475 476 ASSERT(av_stream_map_lane_count != 0); 477 478 return av_stream_map_lane_count; 479 } 480 481 static uint32_t get_audio_sdp_overhead( 482 enum dp_link_encoding encoding, 483 enum dc_lane_count lane_count, 484 bool is_mst) 485 { 486 uint32_t audio_sdp_overhead = 0; 487 488 if (encoding == DP_8b_10b_ENCODING) { 489 if (is_mst) 490 audio_sdp_overhead = 16; /* 4 * 2 + 8 */ 491 else 492 audio_sdp_overhead = lane_count * 2 + 8; 493 } else if (encoding == DP_128b_132b_ENCODING) { 494 audio_sdp_overhead = 10; /* 4 x 2.5 */ 495 } 496 497 ASSERT(audio_sdp_overhead != 0); 498 499 return audio_sdp_overhead; 500 } 501 502 /* Current calculation only applicable for 8b/10b MST and 128b/132b SST/MST. 503 */ 504 static uint32_t calculate_overhead_hblank_bw_in_symbols( 505 uint32_t max_slice_h) 506 { 507 uint32_t overhead_hblank_bw = 0; /* in stream symbols */ 508 509 overhead_hblank_bw += max_slice_h * 4; /* EOC overhead */ 510 overhead_hblank_bw += 12; /* Main link overhead (VBID, BS/BE) */ 511 512 return overhead_hblank_bw; 513 } 514 515 uint32_t dp_required_hblank_size_bytes( 516 const struct dc_link *link, 517 struct dp_audio_bandwidth_params *audio_params) 518 { 519 /* Main logic from dce_audio is duplicated here, with the main 520 * difference being: 521 * - Pre-determined lane count of 4 522 * - Assumed 16 dsc slices for worst case 523 * - Assumed SDP split disabled for worst case 524 * TODO: Unify logic from dce_audio to prevent duplicated logic. 525 */ 526 527 const struct dc_crtc_timing *timing = audio_params->crtc_timing; 528 const uint32_t channel_count = audio_params->channel_count; 529 const uint32_t sample_rate_hz = audio_params->sample_rate_hz; 530 const enum dp_link_encoding link_encoding = audio_params->link_encoding; 531 532 // 8b/10b MST and 128b/132b are always 4 logical lanes. 533 const uint32_t lane_count = 4; 534 const bool is_mst = (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT); 535 // Maximum slice count is with ODM 4:1, 4 slices per DSC 536 const uint32_t max_slices_h = 16; 537 538 const uint32_t av_stream_map_lane_count = get_av_stream_map_lane_count( 539 link_encoding, lane_count, is_mst); 540 const uint32_t audio_sdp_overhead = get_audio_sdp_overhead( 541 link_encoding, lane_count, is_mst); 542 struct dp_audio_layout_config layout_config; 543 544 if (link_encoding == DP_8b_10b_ENCODING && link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT) 545 return 0; 546 547 get_audio_layout_config( 548 channel_count, link_encoding, &layout_config); 549 550 /* DP spec recommends between 1.05 to 1.1 safety margin to prevent sample under-run */ 551 struct fixed31_32 audio_sdp_margin = dc_fixpt_from_fraction(110, 100); 552 struct fixed31_32 horizontal_line_freq_khz = dc_fixpt_from_fraction( 553 timing->pix_clk_100hz, (long long)timing->h_total * 10); 554 struct fixed31_32 samples_per_line; 555 struct fixed31_32 layouts_per_line; 556 struct fixed31_32 symbols_per_sdp_max_layout; 557 struct fixed31_32 remainder; 558 uint32_t num_sdp_with_max_layouts; 559 uint32_t required_symbols_per_hblank; 560 uint32_t required_bytes_per_hblank = 0; 561 562 samples_per_line = dc_fixpt_from_fraction(sample_rate_hz, 1000); 563 samples_per_line = dc_fixpt_div(samples_per_line, horizontal_line_freq_khz); 564 layouts_per_line = dc_fixpt_div_int(samples_per_line, layout_config.layouts_per_sample_denom); 565 // HBlank expansion usage assumes SDP split disabled to allow for worst case. 566 layouts_per_line = dc_fixpt_from_int(dc_fixpt_ceil(layouts_per_line)); 567 568 num_sdp_with_max_layouts = dc_fixpt_floor( 569 dc_fixpt_div_int(layouts_per_line, layout_config.max_layouts_per_audio_sdp)); 570 symbols_per_sdp_max_layout = dc_fixpt_from_int( 571 layout_config.max_layouts_per_audio_sdp * layout_config.symbols_per_layout); 572 symbols_per_sdp_max_layout = dc_fixpt_add_int(symbols_per_sdp_max_layout, audio_sdp_overhead); 573 symbols_per_sdp_max_layout = dc_fixpt_mul(symbols_per_sdp_max_layout, audio_sdp_margin); 574 required_symbols_per_hblank = num_sdp_with_max_layouts; 575 required_symbols_per_hblank *= ((dc_fixpt_ceil(symbols_per_sdp_max_layout) + av_stream_map_lane_count) / 576 av_stream_map_lane_count) * av_stream_map_lane_count; 577 578 if (num_sdp_with_max_layouts != dc_fixpt_ceil( 579 dc_fixpt_div_int(layouts_per_line, layout_config.max_layouts_per_audio_sdp))) { 580 remainder = dc_fixpt_sub_int(layouts_per_line, 581 num_sdp_with_max_layouts * layout_config.max_layouts_per_audio_sdp); 582 remainder = dc_fixpt_mul_int(remainder, layout_config.symbols_per_layout); 583 remainder = dc_fixpt_add_int(remainder, audio_sdp_overhead); 584 remainder = dc_fixpt_mul(remainder, audio_sdp_margin); 585 required_symbols_per_hblank += ((dc_fixpt_ceil(remainder) + av_stream_map_lane_count) / 586 av_stream_map_lane_count) * av_stream_map_lane_count; 587 } 588 589 required_symbols_per_hblank += calculate_overhead_hblank_bw_in_symbols(max_slices_h); 590 591 if (link_encoding == DP_8b_10b_ENCODING) 592 required_bytes_per_hblank = required_symbols_per_hblank; // 8 bits per 8b/10b symbol 593 else if (link_encoding == DP_128b_132b_ENCODING) 594 required_bytes_per_hblank = required_symbols_per_hblank * 4; // 32 bits per 128b/132b symbol 595 596 return required_bytes_per_hblank; 597 } 598 599