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
get_tmds_output_pixel_clock_100hz(const struct dc_crtc_timing * timing)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
dp_active_dongle_validate_timing(const struct dc_crtc_timing * timing,const struct dpcd_caps * dpcd_caps)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
dp_link_bandwidth_kbps(const struct dc_link * link,const struct dc_link_settings * link_settings)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
dp_get_timing_bandwidth_kbps(const struct dc_crtc_timing * timing,const struct dc_link * link)266 static uint32_t dp_get_timing_bandwidth_kbps(
267 const struct dc_crtc_timing *timing,
268 const struct dc_link *link)
269 {
270 return dc_bandwidth_in_kbps_from_timing(timing,
271 dc_link_get_highest_encoding_format(link));
272 }
273
dp_validate_mode_timing(struct dc_link * link,const struct dc_crtc_timing * timing)274 static bool dp_validate_mode_timing(
275 struct dc_link *link,
276 const struct dc_crtc_timing *timing)
277 {
278 uint32_t req_bw;
279 uint32_t max_bw;
280
281 const struct dc_link_settings *link_setting;
282
283 /* According to spec, VSC SDP should be used if pixel format is YCbCr420 */
284 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 &&
285 !link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED &&
286 dal_graphics_object_id_get_connector_id(link->link_id) != CONNECTOR_ID_VIRTUAL)
287 return false;
288
289 /*always DP fail safe mode*/
290 if ((timing->pix_clk_100hz / 10) == (uint32_t) 25175 &&
291 timing->h_addressable == (uint32_t) 640 &&
292 timing->v_addressable == (uint32_t) 480)
293 return true;
294
295 link_setting = dp_get_verified_link_cap(link);
296
297 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
298 /*if (flags.DYNAMIC_VALIDATION == 1 &&
299 link->verified_link_cap.lane_count != LANE_COUNT_UNKNOWN)
300 link_setting = &link->verified_link_cap;
301 */
302
303 req_bw = dc_bandwidth_in_kbps_from_timing(timing, dc_link_get_highest_encoding_format(link));
304 max_bw = dp_link_bandwidth_kbps(link, link_setting);
305
306 bool is_max_uncompressed_pixel_rate_exceeded = link->dpcd_caps.max_uncompressed_pixel_rate_cap.bits.valid &&
307 timing->pix_clk_100hz > link->dpcd_caps.max_uncompressed_pixel_rate_cap.bits.max_uncompressed_pixel_rate_cap * 10000;
308
309 if (is_max_uncompressed_pixel_rate_exceeded && !timing->flags.DSC) {
310 return false;
311 }
312
313 if (req_bw <= max_bw) {
314 /* remember the biggest mode here, during
315 * initial link training (to get
316 * verified_link_cap), LS sends event about
317 * cannot train at reported cap to upper
318 * layer and upper layer will re-enumerate modes.
319 * this is not necessary if the lower
320 * verified_link_cap is enough to drive
321 * all the modes */
322
323 /* TODO: DYNAMIC_VALIDATION needs to be implemented */
324 /* if (flags.DYNAMIC_VALIDATION == 1)
325 dpsst->max_req_bw_for_verified_linkcap = dal_max(
326 dpsst->max_req_bw_for_verified_linkcap, req_bw); */
327 return true;
328 } else
329 return false;
330 }
331
link_validate_mode_timing(const struct dc_stream_state * stream,struct dc_link * link,const struct dc_crtc_timing * timing)332 enum dc_status link_validate_mode_timing(
333 const struct dc_stream_state *stream,
334 struct dc_link *link,
335 const struct dc_crtc_timing *timing)
336 {
337 uint32_t max_pix_clk = stream->link->dongle_max_pix_clk * 10;
338 struct dpcd_caps *dpcd_caps = &link->dpcd_caps;
339
340 /* A hack to avoid failing any modes for EDID override feature on
341 * topology change such as lower quality cable for DP or different dongle
342 */
343 if (link->remote_sinks[0] && link->remote_sinks[0]->sink_signal == SIGNAL_TYPE_VIRTUAL)
344 return DC_OK;
345
346 /* Passive Dongle */
347 if (max_pix_clk != 0 && get_tmds_output_pixel_clock_100hz(timing) > max_pix_clk)
348 return DC_EXCEED_DONGLE_CAP;
349
350 /* Active Dongle*/
351 if (!dp_active_dongle_validate_timing(timing, dpcd_caps))
352 return DC_EXCEED_DONGLE_CAP;
353
354 switch (stream->signal) {
355 case SIGNAL_TYPE_EDP:
356 case SIGNAL_TYPE_DISPLAY_PORT:
357 if (!dp_validate_mode_timing(
358 link,
359 timing))
360 return DC_NO_DP_LINK_BANDWIDTH;
361 break;
362
363 default:
364 break;
365 }
366
367 return DC_OK;
368 }
369
get_dp_tunnel_settings(const struct dc_state * context,const struct dc_stream_state * stream)370 static const struct dc_tunnel_settings *get_dp_tunnel_settings(const struct dc_state *context,
371 const struct dc_stream_state *stream)
372 {
373 int i;
374 const struct dc_tunnel_settings *dp_tunnel_settings = NULL;
375
376 for (i = 0; i < MAX_PIPES; i++) {
377 if (context->res_ctx.pipe_ctx[i].stream && (context->res_ctx.pipe_ctx[i].stream == stream)) {
378 dp_tunnel_settings = &context->res_ctx.pipe_ctx[i].link_config.dp_tunnel_settings;
379 break;
380 }
381 }
382
383 return dp_tunnel_settings;
384 }
385
386 /*
387 * Calculates the DP tunneling bandwidth required for the stream timing
388 * and aggregates the stream bandwidth for the respective DP tunneling link
389 *
390 * return: dc_status
391 */
link_validate_dp_tunnel_bandwidth(const struct dc * dc,const struct dc_state * new_ctx)392 enum dc_status link_validate_dp_tunnel_bandwidth(const struct dc *dc, const struct dc_state *new_ctx)
393 {
394 struct dc_validation_dpia_set dpia_link_sets[MAX_DPIA_NUM] = { 0 };
395 uint8_t link_count = 0;
396 enum dc_status result = DC_OK;
397
398 // Iterate through streams in the new context
399 for (uint8_t i = 0; (i < MAX_PIPES && i < new_ctx->stream_count); i++) {
400 const struct dc_stream_state *stream = new_ctx->streams[i];
401 const struct dc_link *link;
402 const struct dc_tunnel_settings *dp_tunnel_settings;
403 uint32_t timing_bw;
404
405 if (stream == NULL)
406 continue;
407
408 link = stream->link;
409
410 if (!(link && (stream->signal == SIGNAL_TYPE_DISPLAY_PORT
411 || stream->signal == SIGNAL_TYPE_DISPLAY_PORT_MST)
412 && link->hpd_status))
413 continue;
414
415 dp_tunnel_settings = get_dp_tunnel_settings(new_ctx, stream);
416
417 if ((dp_tunnel_settings == NULL) || (dp_tunnel_settings->should_use_dp_bw_allocation == false))
418 continue;
419
420 timing_bw = dp_get_timing_bandwidth_kbps(&stream->timing, link);
421
422 // Find an existing entry for this 'link' in 'dpia_link_sets'
423 for (uint8_t j = 0; j < MAX_DPIA_NUM; j++) {
424 bool is_new_slot = false;
425
426 if (dpia_link_sets[j].link == NULL) {
427 is_new_slot = true;
428 link_count++;
429 dpia_link_sets[j].required_bw = 0;
430 dpia_link_sets[j].link = link;
431 }
432
433 if (is_new_slot || (dpia_link_sets[j].link == link)) {
434 dpia_link_sets[j].tunnel_settings = dp_tunnel_settings;
435 dpia_link_sets[j].required_bw += timing_bw;
436 break;
437 }
438 }
439 }
440
441 if (link_count && link_dpia_validate_dp_tunnel_bandwidth(dpia_link_sets, link_count) == false)
442 result = DC_FAIL_DP_TUNNEL_BW_VALIDATE;
443
444 return result;
445 }
446
447 struct dp_audio_layout_config {
448 uint8_t layouts_per_sample_denom;
449 uint8_t symbols_per_layout;
450 uint8_t max_layouts_per_audio_sdp;
451 };
452
get_audio_layout_config(uint32_t channel_count,enum dp_link_encoding encoding,struct dp_audio_layout_config * output)453 static void get_audio_layout_config(
454 uint32_t channel_count,
455 enum dp_link_encoding encoding,
456 struct dp_audio_layout_config *output)
457 {
458 memset(output, 0, sizeof(struct dp_audio_layout_config));
459
460 /* Assuming L-PCM audio. Current implementation uses max 1 layout per SDP,
461 * with each layout being the same size (8ch layout).
462 */
463 if (encoding == DP_8b_10b_ENCODING) {
464 if (channel_count == 2) {
465 output->layouts_per_sample_denom = 4;
466 output->symbols_per_layout = 40;
467 output->max_layouts_per_audio_sdp = 1;
468 } else if (channel_count == 8 || channel_count == 6) {
469 output->layouts_per_sample_denom = 1;
470 output->symbols_per_layout = 40;
471 output->max_layouts_per_audio_sdp = 1;
472 }
473 } else if (encoding == DP_128b_132b_ENCODING) {
474 if (channel_count == 2) {
475 output->layouts_per_sample_denom = 4;
476 output->symbols_per_layout = 10;
477 output->max_layouts_per_audio_sdp = 1;
478 } else if (channel_count == 8 || channel_count == 6) {
479 output->layouts_per_sample_denom = 1;
480 output->symbols_per_layout = 10;
481 output->max_layouts_per_audio_sdp = 1;
482 }
483 }
484 }
485
get_av_stream_map_lane_count(enum dp_link_encoding encoding,enum dc_lane_count lane_count,bool is_mst)486 static uint32_t get_av_stream_map_lane_count(
487 enum dp_link_encoding encoding,
488 enum dc_lane_count lane_count,
489 bool is_mst)
490 {
491 uint32_t av_stream_map_lane_count = 0;
492
493 if (encoding == DP_8b_10b_ENCODING) {
494 if (!is_mst)
495 av_stream_map_lane_count = lane_count;
496 else
497 av_stream_map_lane_count = 4;
498 } else if (encoding == DP_128b_132b_ENCODING) {
499 av_stream_map_lane_count = 4;
500 }
501
502 ASSERT(av_stream_map_lane_count != 0);
503
504 return av_stream_map_lane_count;
505 }
506
get_audio_sdp_overhead(enum dp_link_encoding encoding,enum dc_lane_count lane_count,bool is_mst)507 static uint32_t get_audio_sdp_overhead(
508 enum dp_link_encoding encoding,
509 enum dc_lane_count lane_count,
510 bool is_mst)
511 {
512 uint32_t audio_sdp_overhead = 0;
513
514 if (encoding == DP_8b_10b_ENCODING) {
515 if (is_mst)
516 audio_sdp_overhead = 16; /* 4 * 2 + 8 */
517 else
518 audio_sdp_overhead = lane_count * 2 + 8;
519 } else if (encoding == DP_128b_132b_ENCODING) {
520 audio_sdp_overhead = 10; /* 4 x 2.5 */
521 }
522
523 ASSERT(audio_sdp_overhead != 0);
524
525 return audio_sdp_overhead;
526 }
527
528 /* Current calculation only applicable for 8b/10b MST and 128b/132b SST/MST.
529 */
calculate_overhead_hblank_bw_in_symbols(uint32_t max_slice_h)530 static uint32_t calculate_overhead_hblank_bw_in_symbols(
531 uint32_t max_slice_h)
532 {
533 uint32_t overhead_hblank_bw = 0; /* in stream symbols */
534
535 overhead_hblank_bw += max_slice_h * 4; /* EOC overhead */
536 overhead_hblank_bw += 12; /* Main link overhead (VBID, BS/BE) */
537
538 return overhead_hblank_bw;
539 }
540
dp_required_hblank_size_bytes(const struct dc_link * link,struct dp_audio_bandwidth_params * audio_params)541 uint32_t dp_required_hblank_size_bytes(
542 const struct dc_link *link,
543 struct dp_audio_bandwidth_params *audio_params)
544 {
545 /* Main logic from dce_audio is duplicated here, with the main
546 * difference being:
547 * - Pre-determined lane count of 4
548 * - Assumed 16 dsc slices for worst case
549 * - Assumed SDP split disabled for worst case
550 * TODO: Unify logic from dce_audio to prevent duplicated logic.
551 */
552
553 const struct dc_crtc_timing *timing = audio_params->crtc_timing;
554 const uint32_t channel_count = audio_params->channel_count;
555 const uint32_t sample_rate_hz = audio_params->sample_rate_hz;
556 const enum dp_link_encoding link_encoding = audio_params->link_encoding;
557
558 // 8b/10b MST and 128b/132b are always 4 logical lanes.
559 const uint32_t lane_count = 4;
560 const bool is_mst = (link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT);
561 // Maximum slice count is with ODM 4:1, 4 slices per DSC
562 const uint32_t max_slices_h = 16;
563
564 const uint32_t av_stream_map_lane_count = get_av_stream_map_lane_count(
565 link_encoding, lane_count, is_mst);
566 const uint32_t audio_sdp_overhead = get_audio_sdp_overhead(
567 link_encoding, lane_count, is_mst);
568 struct dp_audio_layout_config layout_config;
569
570 if (link_encoding == DP_8b_10b_ENCODING && link->connector_signal == SIGNAL_TYPE_DISPLAY_PORT)
571 return 0;
572
573 get_audio_layout_config(
574 channel_count, link_encoding, &layout_config);
575
576 /* DP spec recommends between 1.05 to 1.1 safety margin to prevent sample under-run */
577 struct fixed31_32 audio_sdp_margin = dc_fixpt_from_fraction(110, 100);
578 struct fixed31_32 horizontal_line_freq_khz = dc_fixpt_from_fraction(
579 timing->pix_clk_100hz, (long long)timing->h_total * 10);
580 struct fixed31_32 samples_per_line;
581 struct fixed31_32 layouts_per_line;
582 struct fixed31_32 symbols_per_sdp_max_layout;
583 struct fixed31_32 remainder;
584 uint32_t num_sdp_with_max_layouts;
585 uint32_t required_symbols_per_hblank;
586 uint32_t required_bytes_per_hblank = 0;
587
588 samples_per_line = dc_fixpt_from_fraction(sample_rate_hz, 1000);
589 samples_per_line = dc_fixpt_div(samples_per_line, horizontal_line_freq_khz);
590 layouts_per_line = dc_fixpt_div_int(samples_per_line, layout_config.layouts_per_sample_denom);
591 // HBlank expansion usage assumes SDP split disabled to allow for worst case.
592 layouts_per_line = dc_fixpt_from_int(dc_fixpt_ceil(layouts_per_line));
593
594 num_sdp_with_max_layouts = dc_fixpt_floor(
595 dc_fixpt_div_int(layouts_per_line, layout_config.max_layouts_per_audio_sdp));
596 symbols_per_sdp_max_layout = dc_fixpt_from_int(
597 layout_config.max_layouts_per_audio_sdp * layout_config.symbols_per_layout);
598 symbols_per_sdp_max_layout = dc_fixpt_add_int(symbols_per_sdp_max_layout, audio_sdp_overhead);
599 symbols_per_sdp_max_layout = dc_fixpt_mul(symbols_per_sdp_max_layout, audio_sdp_margin);
600 required_symbols_per_hblank = num_sdp_with_max_layouts;
601 required_symbols_per_hblank *= ((dc_fixpt_ceil(symbols_per_sdp_max_layout) + av_stream_map_lane_count) /
602 av_stream_map_lane_count) * av_stream_map_lane_count;
603
604 if (num_sdp_with_max_layouts != dc_fixpt_ceil(
605 dc_fixpt_div_int(layouts_per_line, layout_config.max_layouts_per_audio_sdp))) {
606 remainder = dc_fixpt_sub_int(layouts_per_line,
607 num_sdp_with_max_layouts * layout_config.max_layouts_per_audio_sdp);
608 remainder = dc_fixpt_mul_int(remainder, layout_config.symbols_per_layout);
609 remainder = dc_fixpt_add_int(remainder, audio_sdp_overhead);
610 remainder = dc_fixpt_mul(remainder, audio_sdp_margin);
611 required_symbols_per_hblank += ((dc_fixpt_ceil(remainder) + av_stream_map_lane_count) /
612 av_stream_map_lane_count) * av_stream_map_lane_count;
613 }
614
615 required_symbols_per_hblank += calculate_overhead_hblank_bw_in_symbols(max_slices_h);
616
617 if (link_encoding == DP_8b_10b_ENCODING)
618 required_bytes_per_hblank = required_symbols_per_hblank; // 8 bits per 8b/10b symbol
619 else if (link_encoding == DP_128b_132b_ENCODING)
620 required_bytes_per_hblank = required_symbols_per_hblank * 4; // 32 bits per 128b/132b symbol
621
622 return required_bytes_per_hblank;
623 }
624
625