2 * Copyright 2019 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <drm/display/drm_dp_helper.h>
26 #include <drm/display/drm_dsc_helper.h>
27 #include "dc_hw_types.h"
31 #include "fixed31_32.h"
36 /* This module's internal functions */
38 /* default DSC policy target bitrate limit is 16bpp */
39 static uint32_t dsc_policy_max_target_bpp_limit = 16;
41 /* default DSC policy enables DSC only when needed */
42 static bool dsc_policy_enable_dsc_when_not_needed;
44 static bool dsc_policy_disable_dsc_stream_overhead;
46 static bool disable_128b_132b_stream_overhead;
49 #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
52 #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
55 /* Need to account for padding due to pixel-to-symbol packing
56 * for uncompressed 128b/132b streams.
58 static uint32_t apply_128b_132b_stream_overhead(
59 const struct dc_crtc_timing *timing, const uint32_t kbps)
61 uint32_t total_kbps = kbps;
63 if (disable_128b_132b_stream_overhead)
66 if (!timing->flags.DSC) {
67 struct fixed31_32 bpp;
68 struct fixed31_32 overhead_factor;
70 bpp = dc_fixpt_from_int(kbps);
71 bpp = dc_fixpt_div_int(bpp, timing->pix_clk_100hz / 10);
73 /* Symbols_per_HActive = HActive * bpp / (4 lanes * 32-bit symbol size)
74 * Overhead_factor = ceil(Symbols_per_HActive) / Symbols_per_HActive
76 overhead_factor = dc_fixpt_from_int(timing->h_addressable);
77 overhead_factor = dc_fixpt_mul(overhead_factor, bpp);
78 overhead_factor = dc_fixpt_div_int(overhead_factor, 128);
79 overhead_factor = dc_fixpt_div(
80 dc_fixpt_from_int(dc_fixpt_ceil(overhead_factor)),
83 total_kbps = dc_fixpt_ceil(
84 dc_fixpt_mul_int(overhead_factor, total_kbps));
90 uint32_t dc_bandwidth_in_kbps_from_timing(
91 const struct dc_crtc_timing *timing,
92 const enum dc_link_encoding_format link_encoding)
94 uint32_t bits_per_channel = 0;
97 if (timing->flags.DSC)
98 return dc_dsc_stream_bandwidth_in_kbps(timing,
99 timing->dsc_cfg.bits_per_pixel,
100 timing->dsc_cfg.num_slices_h,
101 timing->dsc_cfg.is_dp);
103 switch (timing->display_color_depth) {
104 case COLOR_DEPTH_666:
105 bits_per_channel = 6;
107 case COLOR_DEPTH_888:
108 bits_per_channel = 8;
110 case COLOR_DEPTH_101010:
111 bits_per_channel = 10;
113 case COLOR_DEPTH_121212:
114 bits_per_channel = 12;
116 case COLOR_DEPTH_141414:
117 bits_per_channel = 14;
119 case COLOR_DEPTH_161616:
120 bits_per_channel = 16;
123 ASSERT(bits_per_channel != 0);
124 bits_per_channel = 8;
128 kbps = timing->pix_clk_100hz / 10;
129 kbps *= bits_per_channel;
131 if (timing->flags.Y_ONLY != 1) {
132 /*Only YOnly make reduce bandwidth by 1/3 compares to RGB*/
134 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
136 else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
140 if (link_encoding == DC_LINK_ENCODING_DP_128b_132b)
141 kbps = apply_128b_132b_stream_overhead(timing, kbps);
143 if (link_encoding == DC_LINK_ENCODING_HDMI_FRL &&
144 timing->vic == 0 && timing->hdmi_vic == 0 &&
145 timing->frl_uncompressed_video_bandwidth_in_kbps != 0)
146 kbps = timing->frl_uncompressed_video_bandwidth_in_kbps;
151 /* Forward Declerations */
152 static bool decide_dsc_bandwidth_range(
153 const uint32_t min_bpp_x16,
154 const uint32_t max_bpp_x16,
155 const uint32_t num_slices_h,
156 const struct dsc_enc_caps *dsc_caps,
157 const struct dc_crtc_timing *timing,
158 const enum dc_link_encoding_format link_encoding,
159 struct dc_dsc_bw_range *range);
161 static uint32_t compute_bpp_x16_from_target_bandwidth(
162 const uint32_t bandwidth_in_kbps,
163 const struct dc_crtc_timing *timing,
164 const uint32_t num_slices_h,
165 const uint32_t bpp_increment_div,
168 static void get_dsc_enc_caps(
169 const struct display_stream_compressor *dsc,
170 struct dsc_enc_caps *dsc_enc_caps,
171 int pixel_clock_100Hz);
173 static bool intersect_dsc_caps(
174 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
175 const struct dsc_enc_caps *dsc_enc_caps,
176 enum dc_pixel_encoding pixel_encoding,
177 struct dsc_enc_caps *dsc_common_caps);
179 static bool setup_dsc_config(
180 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
181 const struct dsc_enc_caps *dsc_enc_caps,
182 int target_bandwidth_kbps,
183 const struct dc_crtc_timing *timing,
184 const struct dc_dsc_config_options *options,
185 const enum dc_link_encoding_format link_encoding,
186 struct dc_dsc_config *dsc_cfg);
188 static bool dsc_buff_block_size_from_dpcd(int dpcd_buff_block_size, int *buff_block_size)
191 switch (dpcd_buff_block_size) {
192 case DP_DSC_RC_BUF_BLK_SIZE_1:
193 *buff_block_size = 1024;
195 case DP_DSC_RC_BUF_BLK_SIZE_4:
196 *buff_block_size = 4 * 1024;
198 case DP_DSC_RC_BUF_BLK_SIZE_16:
199 *buff_block_size = 16 * 1024;
201 case DP_DSC_RC_BUF_BLK_SIZE_64:
202 *buff_block_size = 64 * 1024;
205 dm_error("%s: DPCD DSC buffer size not recognized.\n", __func__);
214 static bool dsc_line_buff_depth_from_dpcd(int dpcd_line_buff_bit_depth, int *line_buff_bit_depth)
216 if (0 <= dpcd_line_buff_bit_depth && dpcd_line_buff_bit_depth <= 7)
217 *line_buff_bit_depth = dpcd_line_buff_bit_depth + 9;
218 else if (dpcd_line_buff_bit_depth == 8)
219 *line_buff_bit_depth = 8;
221 dm_error("%s: DPCD DSC buffer depth not recognized.\n", __func__);
229 static bool dsc_throughput_from_dpcd(int dpcd_throughput, int *throughput)
231 switch (dpcd_throughput) {
232 case DP_DSC_THROUGHPUT_MODE_0_UNSUPPORTED:
235 case DP_DSC_THROUGHPUT_MODE_0_170:
238 case DP_DSC_THROUGHPUT_MODE_0_340:
241 case DP_DSC_THROUGHPUT_MODE_0_400:
244 case DP_DSC_THROUGHPUT_MODE_0_450:
247 case DP_DSC_THROUGHPUT_MODE_0_500:
250 case DP_DSC_THROUGHPUT_MODE_0_550:
253 case DP_DSC_THROUGHPUT_MODE_0_600:
256 case DP_DSC_THROUGHPUT_MODE_0_650:
259 case DP_DSC_THROUGHPUT_MODE_0_700:
262 case DP_DSC_THROUGHPUT_MODE_0_750:
265 case DP_DSC_THROUGHPUT_MODE_0_800:
268 case DP_DSC_THROUGHPUT_MODE_0_850:
271 case DP_DSC_THROUGHPUT_MODE_0_900:
274 case DP_DSC_THROUGHPUT_MODE_0_950:
277 case DP_DSC_THROUGHPUT_MODE_0_1000:
281 dm_error("%s: DPCD DSC throughput mode not recognized.\n", __func__);
290 static bool dsc_bpp_increment_div_from_dpcd(uint8_t bpp_increment_dpcd, uint32_t *bpp_increment_div)
292 // Mask bpp increment dpcd field to avoid reading other fields
293 bpp_increment_dpcd &= 0x7;
295 switch (bpp_increment_dpcd) {
297 *bpp_increment_div = 16;
300 *bpp_increment_div = 8;
303 *bpp_increment_div = 4;
306 *bpp_increment_div = 2;
309 *bpp_increment_div = 1;
312 dm_error("%s: DPCD DSC bits-per-pixel increment not recognized.\n", __func__);
322 bool dc_dsc_parse_dsc_dpcd(const struct dc *dc,
323 const uint8_t *dpcd_dsc_basic_data,
324 const uint8_t *dpcd_dsc_branch_decoder_caps,
325 struct dsc_dec_dpcd_caps *dsc_sink_caps)
327 if (!dpcd_dsc_basic_data)
330 dsc_sink_caps->is_dsc_supported =
331 (dpcd_dsc_basic_data[DP_DSC_SUPPORT - DP_DSC_SUPPORT] & DP_DSC_DECOMPRESSION_IS_SUPPORTED) != 0;
332 if (!dsc_sink_caps->is_dsc_supported)
335 dsc_sink_caps->dsc_version = dpcd_dsc_basic_data[DP_DSC_REV - DP_DSC_SUPPORT];
341 if (!dsc_buff_block_size_from_dpcd(
342 dpcd_dsc_basic_data[DP_DSC_RC_BUF_BLK_SIZE - DP_DSC_SUPPORT] & 0x03,
346 buff_size = dpcd_dsc_basic_data[DP_DSC_RC_BUF_SIZE - DP_DSC_SUPPORT] + 1;
347 dsc_sink_caps->rc_buffer_size = buff_size * buff_block_size;
350 dsc_sink_caps->slice_caps1.raw = dpcd_dsc_basic_data[DP_DSC_SLICE_CAP_1 - DP_DSC_SUPPORT];
351 if (!dsc_line_buff_depth_from_dpcd(dpcd_dsc_basic_data[DP_DSC_LINE_BUF_BIT_DEPTH - DP_DSC_SUPPORT],
352 &dsc_sink_caps->lb_bit_depth))
355 dsc_sink_caps->is_block_pred_supported =
356 (dpcd_dsc_basic_data[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] &
357 DP_DSC_BLK_PREDICTION_IS_SUPPORTED) != 0;
359 dsc_sink_caps->edp_max_bits_per_pixel =
360 dpcd_dsc_basic_data[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |
361 dpcd_dsc_basic_data[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] << 8;
363 dsc_sink_caps->color_formats.raw = dpcd_dsc_basic_data[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT];
364 dsc_sink_caps->color_depth.raw = dpcd_dsc_basic_data[DP_DSC_DEC_COLOR_DEPTH_CAP - DP_DSC_SUPPORT];
367 int dpcd_throughput = dpcd_dsc_basic_data[DP_DSC_PEAK_THROUGHPUT - DP_DSC_SUPPORT];
368 int dsc_throughput_granular_delta;
370 dsc_throughput_granular_delta = dpcd_dsc_basic_data[DP_DSC_RC_BUF_BLK_SIZE - DP_DSC_SUPPORT] >> 3;
371 dsc_throughput_granular_delta *= 2;
373 if (!dsc_throughput_from_dpcd(dpcd_throughput & DP_DSC_THROUGHPUT_MODE_0_MASK,
374 &dsc_sink_caps->throughput_mode_0_mps))
376 dsc_sink_caps->throughput_mode_0_mps += dsc_throughput_granular_delta;
378 dpcd_throughput = (dpcd_throughput & DP_DSC_THROUGHPUT_MODE_1_MASK) >> DP_DSC_THROUGHPUT_MODE_1_SHIFT;
379 if (!dsc_throughput_from_dpcd(dpcd_throughput, &dsc_sink_caps->throughput_mode_1_mps))
383 dsc_sink_caps->max_slice_width = dpcd_dsc_basic_data[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] * 320;
384 dsc_sink_caps->slice_caps2.raw = dpcd_dsc_basic_data[DP_DSC_SLICE_CAP_2 - DP_DSC_SUPPORT];
386 if (!dsc_bpp_increment_div_from_dpcd(dpcd_dsc_basic_data[DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT],
387 &dsc_sink_caps->bpp_increment_div))
390 if (dc->debug.dsc_bpp_increment_div) {
391 /* dsc_bpp_increment_div should onl be 1, 2, 4, 8 or 16, but rather than rejecting invalid values,
392 * we'll accept all and get it into range. This also makes the above check against 0 redundant,
393 * but that one stresses out the override will be only used if it's not 0.
395 if (dc->debug.dsc_bpp_increment_div >= 1)
396 dsc_sink_caps->bpp_increment_div = 1;
397 if (dc->debug.dsc_bpp_increment_div >= 2)
398 dsc_sink_caps->bpp_increment_div = 2;
399 if (dc->debug.dsc_bpp_increment_div >= 4)
400 dsc_sink_caps->bpp_increment_div = 4;
401 if (dc->debug.dsc_bpp_increment_div >= 8)
402 dsc_sink_caps->bpp_increment_div = 8;
403 if (dc->debug.dsc_bpp_increment_div >= 16)
404 dsc_sink_caps->bpp_increment_div = 16;
408 if (dpcd_dsc_branch_decoder_caps == NULL) { // branch decoder DPCD DSC data can be null for non branch device
409 dsc_sink_caps->branch_overall_throughput_0_mps = 0;
410 dsc_sink_caps->branch_overall_throughput_1_mps = 0;
411 dsc_sink_caps->branch_max_line_width = 0;
415 dsc_sink_caps->branch_overall_throughput_0_mps =
416 dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_OVERALL_THROUGHPUT_0 - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0];
417 if (dsc_sink_caps->branch_overall_throughput_0_mps == 0)
418 dsc_sink_caps->branch_overall_throughput_0_mps = 0;
419 else if (dsc_sink_caps->branch_overall_throughput_0_mps == 1)
420 dsc_sink_caps->branch_overall_throughput_0_mps = 680;
422 dsc_sink_caps->branch_overall_throughput_0_mps *= 50;
423 dsc_sink_caps->branch_overall_throughput_0_mps += 600;
426 dsc_sink_caps->branch_overall_throughput_1_mps =
427 dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_OVERALL_THROUGHPUT_1 - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0];
428 if (dsc_sink_caps->branch_overall_throughput_1_mps == 0)
429 dsc_sink_caps->branch_overall_throughput_1_mps = 0;
430 else if (dsc_sink_caps->branch_overall_throughput_1_mps == 1)
431 dsc_sink_caps->branch_overall_throughput_1_mps = 680;
433 dsc_sink_caps->branch_overall_throughput_1_mps *= 50;
434 dsc_sink_caps->branch_overall_throughput_1_mps += 600;
437 dsc_sink_caps->branch_max_line_width =
438 dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_MAX_LINE_WIDTH - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0] * 320;
439 ASSERT(dsc_sink_caps->branch_max_line_width == 0 || dsc_sink_caps->branch_max_line_width >= 5120);
441 dsc_sink_caps->is_dp = true;
446 /* If DSC is possbile, get DSC bandwidth range based on [min_bpp, max_bpp] target bitrate range and
447 * timing's pixel clock and uncompressed bandwidth.
448 * If DSC is not possible, leave '*range' untouched.
450 bool dc_dsc_compute_bandwidth_range(
451 const struct display_stream_compressor *dsc,
452 uint32_t dsc_min_slice_height_override,
453 uint32_t min_bpp_x16,
454 uint32_t max_bpp_x16,
455 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
456 const struct dc_crtc_timing *timing,
457 const enum dc_link_encoding_format link_encoding,
458 struct dc_dsc_bw_range *range)
460 bool is_dsc_possible = false;
461 struct dsc_enc_caps dsc_enc_caps;
462 struct dsc_enc_caps dsc_common_caps;
463 struct dc_dsc_config config = {0};
464 struct dc_dsc_config_options options = {0};
466 options.dsc_min_slice_height_override = dsc_min_slice_height_override;
467 options.max_target_bpp_limit_override_x16 = max_bpp_x16;
468 options.slice_height_granularity = 1;
470 get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
472 is_dsc_possible = intersect_dsc_caps(dsc_sink_caps, &dsc_enc_caps,
473 timing->pixel_encoding, &dsc_common_caps);
476 is_dsc_possible = setup_dsc_config(dsc_sink_caps, &dsc_enc_caps, 0, timing,
477 &options, link_encoding, &config);
480 is_dsc_possible = decide_dsc_bandwidth_range(min_bpp_x16, max_bpp_x16,
481 config.num_slices_h, &dsc_common_caps, timing, link_encoding, range);
483 return is_dsc_possible;
486 void dc_dsc_dump_encoder_caps(const struct display_stream_compressor *dsc,
487 const struct dc_crtc_timing *timing)
489 struct dsc_enc_caps dsc_enc_caps;
491 get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
493 DC_LOG_DSC("dsc encoder caps:");
494 DC_LOG_DSC("\tdsc_version 0x%x", dsc_enc_caps.dsc_version);
495 DC_LOG_DSC("\tslice_caps 0x%x", dsc_enc_caps.slice_caps.raw);
496 DC_LOG_DSC("\tlb_bit_depth %d", dsc_enc_caps.lb_bit_depth);
497 DC_LOG_DSC("\tis_block_pred_supported %d", dsc_enc_caps.is_block_pred_supported);
498 DC_LOG_DSC("\tcolor_formats 0x%x", dsc_enc_caps.color_formats.raw);
499 DC_LOG_DSC("\tcolor_depth 0x%x", dsc_enc_caps.color_depth.raw);
500 DC_LOG_DSC("\tmax_total_throughput_mps %d", dsc_enc_caps.max_total_throughput_mps);
501 DC_LOG_DSC("\tmax_slice_width %d", dsc_enc_caps.max_slice_width);
502 DC_LOG_DSC("\tbpp_increment_div %d", dsc_enc_caps.bpp_increment_div);
505 void dc_dsc_dump_decoder_caps(const struct display_stream_compressor *dsc,
506 const struct dsc_dec_dpcd_caps *dsc_sink_caps)
508 DC_LOG_DSC("dsc decoder caps:");
509 DC_LOG_DSC("\tis_dsc_supported %d", dsc_sink_caps->is_dsc_supported);
510 DC_LOG_DSC("\tdsc_version 0x%x", dsc_sink_caps->dsc_version);
511 DC_LOG_DSC("\trc_buffer_size %d", dsc_sink_caps->rc_buffer_size);
512 DC_LOG_DSC("\tslice_caps1 0x%x", dsc_sink_caps->slice_caps1.raw);
513 DC_LOG_DSC("\tslice_caps2 0x%x", dsc_sink_caps->slice_caps2.raw);
514 DC_LOG_DSC("\tlb_bit_depth %d", dsc_sink_caps->lb_bit_depth);
515 DC_LOG_DSC("\tis_block_pred_supported %d", dsc_sink_caps->is_block_pred_supported);
516 DC_LOG_DSC("\tedp_max_bits_per_pixel %d", dsc_sink_caps->edp_max_bits_per_pixel);
517 DC_LOG_DSC("\tcolor_formats 0x%x", dsc_sink_caps->color_formats.raw);
518 DC_LOG_DSC("\tthroughput_mode_0_mps %d", dsc_sink_caps->throughput_mode_0_mps);
519 DC_LOG_DSC("\tthroughput_mode_1_mps %d", dsc_sink_caps->throughput_mode_1_mps);
520 DC_LOG_DSC("\tmax_slice_width %d", dsc_sink_caps->max_slice_width);
521 DC_LOG_DSC("\tbpp_increment_div %d", dsc_sink_caps->bpp_increment_div);
522 DC_LOG_DSC("\tbranch_overall_throughput_0_mps %d", dsc_sink_caps->branch_overall_throughput_0_mps);
523 DC_LOG_DSC("\tbranch_overall_throughput_1_mps %d", dsc_sink_caps->branch_overall_throughput_1_mps);
524 DC_LOG_DSC("\tbranch_max_line_width %d", dsc_sink_caps->branch_max_line_width);
525 DC_LOG_DSC("\tis_dp %d", dsc_sink_caps->is_dp);
528 static void get_dsc_enc_caps(
529 const struct display_stream_compressor *dsc,
530 struct dsc_enc_caps *dsc_enc_caps,
531 int pixel_clock_100Hz)
533 // This is a static HW query, so we can use any DSC
535 memset(dsc_enc_caps, 0, sizeof(struct dsc_enc_caps));
537 if (!dsc->ctx->dc->debug.disable_dsc)
538 dsc->funcs->dsc_get_enc_caps(dsc_enc_caps, pixel_clock_100Hz);
539 if (dsc->ctx->dc->debug.native422_support)
540 dsc_enc_caps->color_formats.bits.YCBCR_NATIVE_422 = 1;
544 /* Returns 'false' if no intersection was found for at least one capability.
545 * It also implicitly validates some sink caps against invalid value of zero.
547 static bool intersect_dsc_caps(
548 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
549 const struct dsc_enc_caps *dsc_enc_caps,
550 enum dc_pixel_encoding pixel_encoding,
551 struct dsc_enc_caps *dsc_common_caps)
554 int32_t total_sink_throughput;
556 memset(dsc_common_caps, 0, sizeof(struct dsc_enc_caps));
558 dsc_common_caps->dsc_version = min(dsc_sink_caps->dsc_version, dsc_enc_caps->dsc_version);
559 if (!dsc_common_caps->dsc_version)
562 dsc_common_caps->slice_caps.bits.NUM_SLICES_1 =
563 dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_1;
564 dsc_common_caps->slice_caps.bits.NUM_SLICES_2 =
565 dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_2;
566 dsc_common_caps->slice_caps.bits.NUM_SLICES_4 =
567 dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_4;
568 dsc_common_caps->slice_caps.bits.NUM_SLICES_8 =
569 dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_8;
570 dsc_common_caps->slice_caps.bits.NUM_SLICES_12 =
571 dsc_sink_caps->slice_caps1.bits.NUM_SLICES_12 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_12;
572 dsc_common_caps->slice_caps.bits.NUM_SLICES_16 =
573 dsc_sink_caps->slice_caps2.bits.NUM_SLICES_16 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_16;
575 if (!dsc_common_caps->slice_caps.raw)
578 dsc_common_caps->lb_bit_depth = min(dsc_sink_caps->lb_bit_depth, dsc_enc_caps->lb_bit_depth);
579 if (!dsc_common_caps->lb_bit_depth)
582 dsc_common_caps->is_block_pred_supported =
583 dsc_sink_caps->is_block_pred_supported && dsc_enc_caps->is_block_pred_supported;
585 dsc_common_caps->color_formats.raw = dsc_sink_caps->color_formats.raw & dsc_enc_caps->color_formats.raw;
586 if (!dsc_common_caps->color_formats.raw)
589 dsc_common_caps->color_depth.raw = dsc_sink_caps->color_depth.raw & dsc_enc_caps->color_depth.raw;
590 if (!dsc_common_caps->color_depth.raw)
594 if (dsc_common_caps->slice_caps.bits.NUM_SLICES_1)
597 if (dsc_common_caps->slice_caps.bits.NUM_SLICES_2)
600 if (dsc_common_caps->slice_caps.bits.NUM_SLICES_4)
603 total_sink_throughput = max_slices * dsc_sink_caps->throughput_mode_0_mps;
604 if (pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420)
605 total_sink_throughput = max_slices * dsc_sink_caps->throughput_mode_1_mps;
607 dsc_common_caps->max_total_throughput_mps = min(total_sink_throughput, dsc_enc_caps->max_total_throughput_mps);
609 dsc_common_caps->max_slice_width = min(dsc_sink_caps->max_slice_width, dsc_enc_caps->max_slice_width);
610 if (!dsc_common_caps->max_slice_width)
613 dsc_common_caps->bpp_increment_div = min(dsc_sink_caps->bpp_increment_div, dsc_enc_caps->bpp_increment_div);
615 // TODO DSC: Remove this workaround for N422 and 420 once it's fixed, or move it to get_dsc_encoder_caps()
616 if (pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420)
617 dsc_common_caps->bpp_increment_div = min(dsc_common_caps->bpp_increment_div, (uint32_t)8);
619 dsc_common_caps->edp_sink_max_bits_per_pixel = dsc_sink_caps->edp_max_bits_per_pixel;
620 dsc_common_caps->is_dp = dsc_sink_caps->is_dp;
624 static inline uint32_t dsc_div_by_10_round_up(uint32_t value)
626 return (value + 9) / 10;
629 static uint32_t compute_bpp_x16_from_target_bandwidth(
630 const uint32_t bandwidth_in_kbps,
631 const struct dc_crtc_timing *timing,
632 const uint32_t num_slices_h,
633 const uint32_t bpp_increment_div,
636 uint32_t overhead_in_kbps;
637 struct fixed31_32 effective_bandwidth_in_kbps;
638 struct fixed31_32 bpp_x16;
640 overhead_in_kbps = dc_dsc_stream_bandwidth_overhead_in_kbps(
641 timing, num_slices_h, is_dp);
642 effective_bandwidth_in_kbps = dc_fixpt_from_int(bandwidth_in_kbps);
643 effective_bandwidth_in_kbps = dc_fixpt_sub_int(effective_bandwidth_in_kbps,
645 bpp_x16 = dc_fixpt_mul_int(effective_bandwidth_in_kbps, 10);
646 bpp_x16 = dc_fixpt_div_int(bpp_x16, timing->pix_clk_100hz);
647 bpp_x16 = dc_fixpt_from_int(dc_fixpt_floor(dc_fixpt_mul_int(bpp_x16, bpp_increment_div)));
648 bpp_x16 = dc_fixpt_div_int(bpp_x16, bpp_increment_div);
649 bpp_x16 = dc_fixpt_mul_int(bpp_x16, 16);
650 return dc_fixpt_floor(bpp_x16);
653 /* Decide DSC bandwidth range based on signal, timing, specs specific and input min and max
655 * The range output includes decided min/max target bpp, the respective bandwidth requirements
656 * and native timing bandwidth requirement when DSC is not used.
658 static bool decide_dsc_bandwidth_range(
659 const uint32_t min_bpp_x16,
660 const uint32_t max_bpp_x16,
661 const uint32_t num_slices_h,
662 const struct dsc_enc_caps *dsc_caps,
663 const struct dc_crtc_timing *timing,
664 const enum dc_link_encoding_format link_encoding,
665 struct dc_dsc_bw_range *range)
667 uint32_t preferred_bpp_x16 = timing->dsc_fixed_bits_per_pixel_x16;
669 memset(range, 0, sizeof(*range));
671 /* apply signal, timing, specs and explicitly specified DSC range requirements */
672 if (preferred_bpp_x16) {
673 if (preferred_bpp_x16 <= max_bpp_x16 &&
674 preferred_bpp_x16 >= min_bpp_x16) {
675 range->max_target_bpp_x16 = preferred_bpp_x16;
676 range->min_target_bpp_x16 = preferred_bpp_x16;
679 /* TODO - make this value generic to all signal types */
680 else if (dsc_caps->edp_sink_max_bits_per_pixel) {
681 /* apply max bpp limitation from edp sink */
682 range->max_target_bpp_x16 = MIN(dsc_caps->edp_sink_max_bits_per_pixel,
684 range->min_target_bpp_x16 = min_bpp_x16;
687 range->max_target_bpp_x16 = max_bpp_x16;
688 range->min_target_bpp_x16 = min_bpp_x16;
691 /* populate output structure */
692 if (range->max_target_bpp_x16 >= range->min_target_bpp_x16 && range->min_target_bpp_x16 > 0) {
693 /* native stream bandwidth */
694 range->stream_kbps = dc_bandwidth_in_kbps_from_timing(timing, link_encoding);
696 /* max dsc target bpp */
697 range->max_kbps = dc_dsc_stream_bandwidth_in_kbps(timing,
698 range->max_target_bpp_x16, num_slices_h, dsc_caps->is_dp);
700 /* min dsc target bpp */
701 range->min_kbps = dc_dsc_stream_bandwidth_in_kbps(timing,
702 range->min_target_bpp_x16, num_slices_h, dsc_caps->is_dp);
705 return range->max_kbps >= range->min_kbps && range->min_kbps > 0;
708 /* Decides if DSC should be used and calculates target bpp if it should, applying DSC policy.
711 * - 'true' if target bpp is decided
712 * - 'false' if target bpp cannot be decided (e.g. cannot fit even with min DSC bpp),
714 static bool decide_dsc_target_bpp_x16(
715 const struct dc_dsc_policy *policy,
716 const struct dc_dsc_config_options *options,
717 const struct dsc_enc_caps *dsc_common_caps,
718 const int target_bandwidth_kbps,
719 const struct dc_crtc_timing *timing,
720 const int num_slices_h,
721 const enum dc_link_encoding_format link_encoding,
724 struct dc_dsc_bw_range range;
728 if (decide_dsc_bandwidth_range(policy->min_target_bpp * 16, policy->max_target_bpp * 16,
729 num_slices_h, dsc_common_caps, timing, link_encoding, &range)) {
730 if (target_bandwidth_kbps >= range.stream_kbps) {
731 if (policy->enable_dsc_when_not_needed || options->force_dsc_when_not_needed)
732 /* enable max bpp even dsc is not needed */
733 *target_bpp_x16 = range.max_target_bpp_x16;
734 } else if (target_bandwidth_kbps >= range.max_kbps) {
735 /* use max target bpp allowed */
736 *target_bpp_x16 = range.max_target_bpp_x16;
737 } else if (target_bandwidth_kbps >= range.min_kbps) {
738 /* use target bpp that can take entire target bandwidth */
739 *target_bpp_x16 = compute_bpp_x16_from_target_bandwidth(
740 target_bandwidth_kbps, timing, num_slices_h,
741 dsc_common_caps->bpp_increment_div,
742 dsc_common_caps->is_dp);
746 return *target_bpp_x16 != 0;
749 #define MIN_AVAILABLE_SLICES_SIZE 6
751 static int get_available_dsc_slices(union dsc_enc_slice_caps slice_caps, int *available_slices)
755 if (slice_caps.bits.NUM_SLICES_1)
756 available_slices[idx++] = 1;
758 if (slice_caps.bits.NUM_SLICES_2)
759 available_slices[idx++] = 2;
761 if (slice_caps.bits.NUM_SLICES_4)
762 available_slices[idx++] = 4;
764 if (slice_caps.bits.NUM_SLICES_8)
765 available_slices[idx++] = 8;
767 if (slice_caps.bits.NUM_SLICES_12)
768 available_slices[idx++] = 12;
770 if (slice_caps.bits.NUM_SLICES_16)
771 available_slices[idx++] = 16;
777 static int get_max_dsc_slices(union dsc_enc_slice_caps slice_caps)
780 int available_slices[MIN_AVAILABLE_SLICES_SIZE];
781 int end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
784 max_slices = available_slices[end_idx - 1];
790 // Increment slice number in available slice numbers stops if possible, or just increment if not
791 static int inc_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
793 // Get next bigger num slices available in common caps
794 int available_slices[MIN_AVAILABLE_SLICES_SIZE];
797 int new_num_slices = num_slices;
799 end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
801 // No available slices found
803 return new_num_slices;
806 // Numbers of slices found - get the next bigger number
807 for (i = 0; i < end_idx; i++) {
808 if (new_num_slices < available_slices[i]) {
809 new_num_slices = available_slices[i];
814 if (new_num_slices == num_slices) // No bigger number of slices found
817 return new_num_slices;
821 // Decrement slice number in available slice numbers stops if possible, or just decrement if not. Stop at zero.
822 static int dec_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
824 // Get next bigger num slices available in common caps
825 int available_slices[MIN_AVAILABLE_SLICES_SIZE];
828 int new_num_slices = num_slices;
830 end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
831 if (end_idx == 0 && new_num_slices > 0) {
832 // No numbers of slices found
834 return new_num_slices;
837 // Numbers of slices found - get the next smaller number
838 for (i = end_idx - 1; i >= 0; i--) {
839 if (new_num_slices > available_slices[i]) {
840 new_num_slices = available_slices[i];
845 if (new_num_slices == num_slices) {
846 // No smaller number of slices found
848 if (new_num_slices < 0)
852 return new_num_slices;
856 // Choose next bigger number of slices if the requested number of slices is not available
857 static int fit_num_slices_up(union dsc_enc_slice_caps slice_caps, int num_slices)
859 // Get next bigger num slices available in common caps
860 int available_slices[MIN_AVAILABLE_SLICES_SIZE];
863 int new_num_slices = num_slices;
865 end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
867 // No available slices found
869 return new_num_slices;
872 // Numbers of slices found - get the equal or next bigger number
873 for (i = 0; i < end_idx; i++) {
874 if (new_num_slices <= available_slices[i]) {
875 new_num_slices = available_slices[i];
880 return new_num_slices;
884 /* Attempts to set DSC configuration for the stream, applying DSC policy.
885 * Returns 'true' if successful or 'false' if not.
889 * dsc_sink_caps - DSC sink decoder capabilities (from DPCD)
891 * dsc_enc_caps - DSC encoder capabilities
893 * target_bandwidth_kbps - Target bandwidth to fit the stream into.
894 * If 0, do not calculate target bpp.
896 * timing - The stream timing to fit into 'target_bandwidth_kbps' or apply
897 * maximum compression to, if 'target_badwidth == 0'
899 * dsc_cfg - DSC configuration to use if it was possible to come up with
900 * one for the given inputs.
901 * The target bitrate after DSC can be calculated by multiplying
902 * dsc_cfg.bits_per_pixel (in U6.4 format) by pixel rate, e.g.
904 * dsc_stream_bitrate_kbps = (int)ceil(timing->pix_clk_khz * dsc_cfg.bits_per_pixel / 16.0);
906 static bool setup_dsc_config(
907 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
908 const struct dsc_enc_caps *dsc_enc_caps,
909 int target_bandwidth_kbps,
910 const struct dc_crtc_timing *timing,
911 const struct dc_dsc_config_options *options,
912 const enum dc_link_encoding_format link_encoding,
913 struct dc_dsc_config *dsc_cfg)
915 struct dsc_enc_caps dsc_common_caps;
916 int max_slices_h = 0;
917 int min_slices_h = 0;
918 int num_slices_h = 0;
922 int sink_per_slice_throughput_mps;
923 int branch_max_throughput_mps = 0;
924 bool is_dsc_possible = false;
927 struct dc_dsc_policy policy;
929 memset(dsc_cfg, 0, sizeof(struct dc_dsc_config));
931 dc_dsc_get_policy_for_timing(timing, options->max_target_bpp_limit_override_x16, &policy, link_encoding);
932 pic_width = timing->h_addressable + timing->h_border_left + timing->h_border_right;
933 pic_height = timing->v_addressable + timing->v_border_top + timing->v_border_bottom;
935 if (!dsc_sink_caps->is_dsc_supported)
938 if (dsc_sink_caps->branch_max_line_width && dsc_sink_caps->branch_max_line_width < pic_width)
941 // Intersect decoder with encoder DSC caps and validate DSC settings
942 is_dsc_possible = intersect_dsc_caps(dsc_sink_caps, dsc_enc_caps, timing->pixel_encoding, &dsc_common_caps);
943 if (!is_dsc_possible)
946 sink_per_slice_throughput_mps = 0;
948 // Validate available DSC settings against the mode timing
950 // Validate color format (and pick up the throughput values)
951 dsc_cfg->ycbcr422_simple = false;
952 switch (timing->pixel_encoding) {
953 case PIXEL_ENCODING_RGB:
954 is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.RGB;
955 sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
956 branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_0_mps;
958 case PIXEL_ENCODING_YCBCR444:
959 is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_444;
960 sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
961 branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_0_mps;
963 case PIXEL_ENCODING_YCBCR422:
964 is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_NATIVE_422;
965 sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_1_mps;
966 branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_1_mps;
967 if (!is_dsc_possible) {
968 is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_SIMPLE_422;
969 dsc_cfg->ycbcr422_simple = is_dsc_possible;
970 sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
973 case PIXEL_ENCODING_YCBCR420:
974 is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_NATIVE_420;
975 sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_1_mps;
976 branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_1_mps;
979 is_dsc_possible = false;
982 // Validate branch's maximum throughput
983 if (branch_max_throughput_mps && dsc_div_by_10_round_up(timing->pix_clk_100hz) > branch_max_throughput_mps * 1000)
984 is_dsc_possible = false;
986 if (!is_dsc_possible)
990 switch (timing->display_color_depth) {
991 case COLOR_DEPTH_888:
992 is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_8_BPC;
994 case COLOR_DEPTH_101010:
995 is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_10_BPC;
997 case COLOR_DEPTH_121212:
998 is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_12_BPC;
1001 is_dsc_possible = false;
1004 if (!is_dsc_possible)
1007 // Slice width (i.e. number of slices per line)
1008 max_slices_h = get_max_dsc_slices(dsc_common_caps.slice_caps);
1010 while (max_slices_h > 0) {
1011 if (pic_width % max_slices_h == 0)
1014 max_slices_h = dec_num_slices(dsc_common_caps.slice_caps, max_slices_h);
1017 is_dsc_possible = (dsc_common_caps.max_slice_width > 0);
1018 if (!is_dsc_possible)
1021 min_slices_h = pic_width / dsc_common_caps.max_slice_width;
1022 if (pic_width % dsc_common_caps.max_slice_width)
1025 min_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, min_slices_h);
1027 while (min_slices_h <= max_slices_h) {
1028 int pix_clk_per_slice_khz = dsc_div_by_10_round_up(timing->pix_clk_100hz) / min_slices_h;
1029 if (pix_clk_per_slice_khz <= sink_per_slice_throughput_mps * 1000)
1032 min_slices_h = inc_num_slices(dsc_common_caps.slice_caps, min_slices_h);
1035 is_dsc_possible = (min_slices_h <= max_slices_h);
1037 if (pic_width % min_slices_h != 0)
1038 min_slices_h = 0; // DSC TODO: Maybe try increasing the number of slices first?
1040 if (min_slices_h == 0 && max_slices_h == 0)
1041 is_dsc_possible = false;
1043 if (!is_dsc_possible)
1046 if (policy.use_min_slices_h) {
1047 if (min_slices_h > 0)
1048 num_slices_h = min_slices_h;
1049 else if (max_slices_h > 0) { // Fall back to max slices if min slices is not working out
1050 if (policy.max_slices_h)
1051 num_slices_h = min(policy.max_slices_h, max_slices_h);
1053 num_slices_h = max_slices_h;
1055 is_dsc_possible = false;
1057 if (max_slices_h > 0) {
1058 if (policy.max_slices_h)
1059 num_slices_h = min(policy.max_slices_h, max_slices_h);
1061 num_slices_h = max_slices_h;
1062 } else if (min_slices_h > 0) // Fall back to min slices if max slices is not possible
1063 num_slices_h = min_slices_h;
1065 is_dsc_possible = false;
1067 // When we force ODM, num dsc h slices must be divisible by num odm h slices
1068 switch (options->dsc_force_odm_hslice_override) {
1073 if (num_slices_h < 2)
1074 num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 2);
1077 if (dsc_common_caps.slice_caps.bits.NUM_SLICES_12)
1083 if (num_slices_h < 4)
1084 num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 4);
1089 if (num_slices_h == 0)
1090 is_dsc_possible = false;
1091 if (!is_dsc_possible)
1094 dsc_cfg->num_slices_h = num_slices_h;
1095 slice_width = pic_width / num_slices_h;
1097 is_dsc_possible = slice_width <= dsc_common_caps.max_slice_width;
1098 if (!is_dsc_possible)
1101 // Slice height (i.e. number of slices per column): start with policy and pick the first one that height is divisible by.
1102 // For 4:2:0 make sure the slice height is divisible by 2 as well.
1103 if (options->dsc_min_slice_height_override == 0)
1104 slice_height = min(policy.min_slice_height, pic_height);
1106 slice_height = min((int)(options->dsc_min_slice_height_override), pic_height);
1108 while (slice_height < pic_height && (pic_height % slice_height != 0 ||
1109 slice_height % options->slice_height_granularity != 0 ||
1110 (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 && slice_height % 2 != 0)))
1113 if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) // For the case when pic_height < dsc_policy.min_sice_height
1114 is_dsc_possible = (slice_height % 2 == 0);
1116 if (!is_dsc_possible)
1119 if (slice_height > 0) {
1120 dsc_cfg->num_slices_v = pic_height / slice_height;
1122 is_dsc_possible = false;
1126 if (target_bandwidth_kbps > 0) {
1127 is_dsc_possible = decide_dsc_target_bpp_x16(
1131 target_bandwidth_kbps,
1136 dsc_cfg->bits_per_pixel = target_bpp;
1138 if (!is_dsc_possible)
1141 /* Fill out the rest of DSC settings */
1142 dsc_cfg->block_pred_enable = dsc_common_caps.is_block_pred_supported;
1143 dsc_cfg->linebuf_depth = dsc_common_caps.lb_bit_depth;
1144 dsc_cfg->version_minor = (dsc_common_caps.dsc_version & 0xf0) >> 4;
1145 dsc_cfg->is_dp = dsc_sink_caps->is_dp;
1148 if (!is_dsc_possible)
1149 memset(dsc_cfg, 0, sizeof(struct dc_dsc_config));
1151 return is_dsc_possible;
1154 bool dc_dsc_compute_config(
1155 const struct display_stream_compressor *dsc,
1156 const struct dsc_dec_dpcd_caps *dsc_sink_caps,
1157 const struct dc_dsc_config_options *options,
1158 uint32_t target_bandwidth_kbps,
1159 const struct dc_crtc_timing *timing,
1160 const enum dc_link_encoding_format link_encoding,
1161 struct dc_dsc_config *dsc_cfg)
1163 bool is_dsc_possible = false;
1164 struct dsc_enc_caps dsc_enc_caps;
1166 get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
1167 is_dsc_possible = setup_dsc_config(dsc_sink_caps,
1169 target_bandwidth_kbps,
1170 timing, options, link_encoding, dsc_cfg);
1171 return is_dsc_possible;
1174 uint32_t dc_dsc_stream_bandwidth_in_kbps(const struct dc_crtc_timing *timing,
1175 uint32_t bpp_x16, uint32_t num_slices_h, bool is_dp)
1177 uint32_t overhead_in_kbps;
1178 struct fixed31_32 bpp;
1179 struct fixed31_32 actual_bandwidth_in_kbps;
1181 overhead_in_kbps = dc_dsc_stream_bandwidth_overhead_in_kbps(
1182 timing, num_slices_h, is_dp);
1183 bpp = dc_fixpt_from_fraction(bpp_x16, 16);
1184 actual_bandwidth_in_kbps = dc_fixpt_from_fraction(timing->pix_clk_100hz, 10);
1185 actual_bandwidth_in_kbps = dc_fixpt_mul(actual_bandwidth_in_kbps, bpp);
1186 actual_bandwidth_in_kbps = dc_fixpt_add_int(actual_bandwidth_in_kbps, overhead_in_kbps);
1187 return dc_fixpt_ceil(actual_bandwidth_in_kbps);
1190 uint32_t dc_dsc_stream_bandwidth_overhead_in_kbps(
1191 const struct dc_crtc_timing *timing,
1192 const int num_slices_h,
1195 struct fixed31_32 max_dsc_overhead;
1196 struct fixed31_32 refresh_rate;
1198 if (dsc_policy_disable_dsc_stream_overhead || !is_dp)
1201 /* use target bpp that can take entire target bandwidth */
1202 refresh_rate = dc_fixpt_from_int(timing->pix_clk_100hz);
1203 refresh_rate = dc_fixpt_div_int(refresh_rate, timing->h_total);
1204 refresh_rate = dc_fixpt_div_int(refresh_rate, timing->v_total);
1205 refresh_rate = dc_fixpt_mul_int(refresh_rate, 100);
1207 max_dsc_overhead = dc_fixpt_from_int(num_slices_h);
1208 max_dsc_overhead = dc_fixpt_mul_int(max_dsc_overhead, timing->v_total);
1209 max_dsc_overhead = dc_fixpt_mul_int(max_dsc_overhead, 256);
1210 max_dsc_overhead = dc_fixpt_div_int(max_dsc_overhead, 1000);
1211 max_dsc_overhead = dc_fixpt_mul(max_dsc_overhead, refresh_rate);
1213 return dc_fixpt_ceil(max_dsc_overhead);
1216 void dc_dsc_get_policy_for_timing(const struct dc_crtc_timing *timing,
1217 uint32_t max_target_bpp_limit_override_x16,
1218 struct dc_dsc_policy *policy,
1219 const enum dc_link_encoding_format link_encoding)
1223 policy->min_target_bpp = 0;
1224 policy->max_target_bpp = 0;
1226 /* DSC Policy: Use minimum number of slices that fits the pixel clock */
1227 policy->use_min_slices_h = true;
1229 /* DSC Policy: Use max available slices
1230 * (in our case 4 for or 8, depending on the mode)
1232 policy->max_slices_h = 0;
1234 /* DSC Policy: Use slice height recommended
1235 * by VESA DSC Spreadsheet user guide
1237 policy->min_slice_height = 108;
1239 /* DSC Policy: follow DP specs with an internal upper limit to 16 bpp
1240 * for better interoperability
1242 switch (timing->display_color_depth) {
1243 case COLOR_DEPTH_888:
1246 case COLOR_DEPTH_101010:
1249 case COLOR_DEPTH_121212:
1255 switch (timing->pixel_encoding) {
1256 case PIXEL_ENCODING_RGB:
1257 case PIXEL_ENCODING_YCBCR444:
1258 case PIXEL_ENCODING_YCBCR422: /* assume no YCbCr422 native support */
1259 /* DP specs limits to 8 */
1260 policy->min_target_bpp = 8;
1261 /* DP specs limits to 3 x bpc */
1262 policy->max_target_bpp = 3 * bpc;
1264 case PIXEL_ENCODING_YCBCR420:
1265 /* DP specs limits to 6 */
1266 policy->min_target_bpp = 6;
1267 /* DP specs limits to 1.5 x bpc assume bpc is an even number */
1268 policy->max_target_bpp = bpc * 3 / 2;
1274 /* internal upper limit, default 16 bpp */
1275 if (policy->max_target_bpp > dsc_policy_max_target_bpp_limit)
1276 policy->max_target_bpp = dsc_policy_max_target_bpp_limit;
1278 /* apply override */
1279 if (max_target_bpp_limit_override_x16 && policy->max_target_bpp > max_target_bpp_limit_override_x16 / 16)
1280 policy->max_target_bpp = max_target_bpp_limit_override_x16 / 16;
1282 /* enable DSC when not needed, default false */
1283 policy->enable_dsc_when_not_needed = dsc_policy_enable_dsc_when_not_needed;
1286 void dc_dsc_policy_set_max_target_bpp_limit(uint32_t limit)
1288 dsc_policy_max_target_bpp_limit = limit;
1291 void dc_dsc_policy_set_enable_dsc_when_not_needed(bool enable)
1293 dsc_policy_enable_dsc_when_not_needed = enable;
1296 void dc_dsc_policy_set_disable_dsc_stream_overhead(bool disable)
1298 dsc_policy_disable_dsc_stream_overhead = disable;
1301 void dc_set_disable_128b_132b_stream_overhead(bool disable)
1303 disable_128b_132b_stream_overhead = disable;
1306 void dc_dsc_get_default_config_option(const struct dc *dc, struct dc_dsc_config_options *options)
1308 options->dsc_min_slice_height_override = dc->debug.dsc_min_slice_height_override;
1309 options->dsc_force_odm_hslice_override = dc->debug.force_odm_combine;
1310 options->max_target_bpp_limit_override_x16 = 0;
1311 options->slice_height_granularity = 1;
1312 options->force_dsc_when_not_needed = false;