1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
#include <drm/display/drm_dp_helper.h>
#include <drm/display/drm_dsc_helper.h>
#include "dc_hw_types.h"
#include "dsc.h"
#include "dc.h"
#include "rc_calc.h"
#include "fixed31_32.h"
#include "clk_mgr.h"
#include "resource.h"
#define DC_LOGGER \
dsc->ctx->logger
static uint32_t dsc_policy_max_target_bpp_limit = 16;
static bool dsc_policy_enable_dsc_when_not_needed;
static bool dsc_policy_disable_dsc_stream_overhead;
static bool disable_128b_132b_stream_overhead;
#ifndef MAX
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
#endif
#ifndef MIN
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#endif
static uint32_t apply_128b_132b_stream_overhead(
const struct dc_crtc_timing *timing, const uint32_t kbps)
{
uint32_t total_kbps = kbps;
if (disable_128b_132b_stream_overhead)
return kbps;
if (!timing->flags.DSC) {
struct fixed31_32 bpp;
struct fixed31_32 overhead_factor;
bpp = dc_fixpt_from_int(kbps);
bpp = dc_fixpt_div_int(bpp, timing->pix_clk_100hz / 10);
overhead_factor = dc_fixpt_from_int(timing->h_addressable);
overhead_factor = dc_fixpt_mul(overhead_factor, bpp);
overhead_factor = dc_fixpt_div_int(overhead_factor, 128);
overhead_factor = dc_fixpt_div(
dc_fixpt_from_int(dc_fixpt_ceil(overhead_factor)),
overhead_factor);
total_kbps = dc_fixpt_ceil(
dc_fixpt_mul_int(overhead_factor, total_kbps));
}
return total_kbps;
}
uint32_t dc_bandwidth_in_kbps_from_timing(
const struct dc_crtc_timing *timing,
const enum dc_link_encoding_format link_encoding)
{
uint32_t bits_per_channel = 0;
uint32_t kbps;
if (timing->flags.DSC)
return dc_dsc_stream_bandwidth_in_kbps(timing,
timing->dsc_cfg.bits_per_pixel,
timing->dsc_cfg.num_slices_h,
timing->dsc_cfg.is_dp);
switch (timing->display_color_depth) {
case COLOR_DEPTH_666:
bits_per_channel = 6;
break;
case COLOR_DEPTH_888:
bits_per_channel = 8;
break;
case COLOR_DEPTH_101010:
bits_per_channel = 10;
break;
case COLOR_DEPTH_121212:
bits_per_channel = 12;
break;
case COLOR_DEPTH_141414:
bits_per_channel = 14;
break;
case COLOR_DEPTH_161616:
bits_per_channel = 16;
break;
default:
ASSERT(bits_per_channel != 0);
bits_per_channel = 8;
break;
}
kbps = timing->pix_clk_100hz / 10;
kbps *= bits_per_channel;
if (timing->flags.Y_ONLY != 1) {
kbps *= 3;
if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
kbps /= 2;
else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422)
kbps = kbps * 2 / 3;
}
if (link_encoding == DC_LINK_ENCODING_DP_128b_132b)
kbps = apply_128b_132b_stream_overhead(timing, kbps);
if (link_encoding == DC_LINK_ENCODING_HDMI_FRL &&
timing->vic == 0 && timing->hdmi_vic == 0 &&
timing->frl_uncompressed_video_bandwidth_in_kbps != 0)
kbps = timing->frl_uncompressed_video_bandwidth_in_kbps;
return kbps;
}
const struct dc_dsc_primary_bpp prim_bpp_444[] = {
{64, 192},
{77, 192},
{63, 192},
{78, 192},
{93, 192},
{103, 192},
{94, 192},
{104, 192},
{95, 192},
{105, 192},
{114, 192},
{116, 192},
{96, 192},
{106, 192},
{97, 192},
{107, 192},
{117, 192},
{119, 192},
{118, 192},
{120, 192},
{98, 192},
{99, 192},
{100, 192},
{115, 192},
{101, 192},
{102, 192},
{218, 192},
{219, 192},
{121, 192},
{122, 192},
{123, 192},
{124, 192},
{125, 192},
{126, 173},
{127, 192},
{193, 175},
{194, 192},
{202, 192},
{195, 192},
{203, 192},
{196, 192},
{204, 192},
{197, 157},
{205, 157},
{198, 157},
{206, 157},
{199, 159},
{207, 159},
{200, 134},
{208, 134},
{201, 130},
{209, 130},
{210, 182},
{211, 181},
{212, 177},
{213, 163},
{214, 162},
{215, 157},
};
const struct dc_dsc_primary_bpp prim_bpp_422[] = {
{114, 192},
{116, 192},
{96, 192},
{106, 192},
{97, 192},
{107, 192},
{117, 137},
{119, 137},
{118, 113},
{120, 113},
{115, 192},
{101, 192},
{102, 192},
{218, 192},
{219, 192},
{121, 192},
{122, 192},
{123, 192},
{124, 192},
{125, 192},
{126, 173},
{127, 192},
{193, 175},
{194, 123},
{202, 123},
{195, 123},
{203, 123},
{196, 118},
{204, 118},
{197, 123},
{205, 123},
{198, 123},
{206, 123},
{199, 119},
{207, 119},
{200, 134},
{208, 134},
{201, 130},
{209, 130},
{210, 182},
{211, 181},
{212, 177},
{213, 126},
{214, 125},
{215, 117},
{216, 125},
{217, 117},
};
const struct dc_dsc_primary_bpp prim_bpp_420[] = {
{114, 192},
{116, 192},
{96, 192},
{106, 192},
{97, 192},
{107, 192},
{117, 137},
{119, 137},
{118, 113},
{120, 113},
{115, 192},
{101, 192},
{102, 192},
{218, 129},
{219, 106},
{124, 192},
{125, 192},
{126, 173},
{127, 192},
{193, 175},
{194, 123},
{202, 123},
{195, 123},
{203, 123},
{196, 118},
{204, 118},
{197, 123},
{205, 123},
{198, 123},
{206, 123},
{199, 119},
{207, 119},
{200, 112},
{208, 112},
{201, 103},
{209, 103},
{210, 98},
{211, 98},
{212, 177},
{213, 98},
{214, 125},
{215, 117},
{216, 107},
{217, 97},
};
static unsigned int get_min_dsc_slice_count_for_odm(
const struct display_stream_compressor *dsc,
const struct dsc_enc_caps *dsc_enc_caps,
const struct dc_crtc_timing *timing);
static bool decide_dsc_bandwidth_range(
const uint32_t min_bpp_x16,
const uint32_t max_bpp_x16,
const uint32_t num_slices_h,
const struct dsc_enc_caps *dsc_caps,
const struct dc_crtc_timing *timing,
const enum dc_link_encoding_format link_encoding,
struct dc_dsc_bw_range *range);
static uint32_t compute_bpp_x16_from_target_bandwidth(
const uint32_t bandwidth_in_kbps,
const struct dc_crtc_timing *timing,
const uint32_t num_slices_h,
const uint32_t bpp_increment_div,
const bool is_dp);
static void get_dsc_enc_caps(
const struct display_stream_compressor *dsc,
struct dsc_enc_caps *dsc_enc_caps,
int pixel_clock_100Hz);
static bool intersect_dsc_caps(
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dsc_enc_caps *dsc_enc_caps,
enum dc_pixel_encoding pixel_encoding,
struct dsc_enc_caps *dsc_common_caps);
static bool setup_dsc_config(
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dsc_enc_caps *dsc_enc_caps,
int target_bandwidth_kbps,
const struct dc_crtc_timing *timing,
const struct dc_dsc_config_options *options,
const enum dc_link_encoding_format link_encoding,
int min_slice_count,
struct dc_dsc_config *dsc_cfg);
static bool convert_bandwidth_to_frl_params(
int bandwidth_kbps,
int *num_lanes,
int *frl_rate);
static uint32_t compute_bpp_x16_from_frl_params(
const struct dc_crtc_timing *timing,
const uint32_t num_slices_h,
const struct dsc_enc_caps *dsc_caps);
static bool dsc_buff_block_size_from_dpcd(int dpcd_buff_block_size, int *buff_block_size)
{
switch (dpcd_buff_block_size) {
case DP_DSC_RC_BUF_BLK_SIZE_1:
*buff_block_size = 1024;
break;
case DP_DSC_RC_BUF_BLK_SIZE_4:
*buff_block_size = 4 * 1024;
break;
case DP_DSC_RC_BUF_BLK_SIZE_16:
*buff_block_size = 16 * 1024;
break;
case DP_DSC_RC_BUF_BLK_SIZE_64:
*buff_block_size = 64 * 1024;
break;
default: {
dm_error("%s: DPCD DSC buffer size not recognized.\n", __func__);
return false;
}
}
return true;
}
static bool dsc_line_buff_depth_from_dpcd(int dpcd_line_buff_bit_depth, int *line_buff_bit_depth)
{
if (0 <= dpcd_line_buff_bit_depth && dpcd_line_buff_bit_depth <= 7)
*line_buff_bit_depth = dpcd_line_buff_bit_depth + 9;
else if (dpcd_line_buff_bit_depth == 8)
*line_buff_bit_depth = 8;
else {
dm_error("%s: DPCD DSC buffer depth not recognized.\n", __func__);
return false;
}
return true;
}
static bool dsc_throughput_from_dpcd(int dpcd_throughput, int *throughput)
{
switch (dpcd_throughput) {
case DP_DSC_THROUGHPUT_MODE_0_UNSUPPORTED:
*throughput = 0;
break;
case DP_DSC_THROUGHPUT_MODE_0_170:
*throughput = 170;
break;
case DP_DSC_THROUGHPUT_MODE_0_340:
*throughput = 340;
break;
case DP_DSC_THROUGHPUT_MODE_0_400:
*throughput = 400;
break;
case DP_DSC_THROUGHPUT_MODE_0_450:
*throughput = 450;
break;
case DP_DSC_THROUGHPUT_MODE_0_500:
*throughput = 500;
break;
case DP_DSC_THROUGHPUT_MODE_0_550:
*throughput = 550;
break;
case DP_DSC_THROUGHPUT_MODE_0_600:
*throughput = 600;
break;
case DP_DSC_THROUGHPUT_MODE_0_650:
*throughput = 650;
break;
case DP_DSC_THROUGHPUT_MODE_0_700:
*throughput = 700;
break;
case DP_DSC_THROUGHPUT_MODE_0_750:
*throughput = 750;
break;
case DP_DSC_THROUGHPUT_MODE_0_800:
*throughput = 800;
break;
case DP_DSC_THROUGHPUT_MODE_0_850:
*throughput = 850;
break;
case DP_DSC_THROUGHPUT_MODE_0_900:
*throughput = 900;
break;
case DP_DSC_THROUGHPUT_MODE_0_950:
*throughput = 950;
break;
case DP_DSC_THROUGHPUT_MODE_0_1000:
*throughput = 1000;
break;
default: {
dm_error("%s: DPCD DSC throughput mode not recognized.\n", __func__);
return false;
}
}
return true;
}
static bool dsc_bpp_increment_div_from_dpcd(uint8_t bpp_increment_dpcd, uint32_t *bpp_increment_div)
{
bpp_increment_dpcd &= 0x7;
switch (bpp_increment_dpcd) {
case 0:
*bpp_increment_div = 16;
break;
case 1:
*bpp_increment_div = 8;
break;
case 2:
*bpp_increment_div = 4;
break;
case 3:
*bpp_increment_div = 2;
break;
case 4:
*bpp_increment_div = 1;
break;
default: {
dm_error("%s: DPCD DSC bits-per-pixel increment not recognized.\n", __func__);
return false;
}
}
return true;
}
static bool get_vic_preset_bpp(
const struct dc_crtc_timing *timing,
int *preset_bpp)
{
bool preset_found = false;
uint32_t table_size_444 = ARRAY_SIZE(prim_bpp_444);
uint32_t table_size_422 = ARRAY_SIZE(prim_bpp_422);
uint32_t table_size_420 = ARRAY_SIZE(prim_bpp_420);
uint32_t i;
uint32_t vid_id;
if (timing->vic == 0 && timing->hdmi_vic == 0)
return false;
vid_id = timing->vic;
switch (timing->hdmi_vic) {
case 1:
vid_id = 95;
break;
case 2:
vid_id = 94;
break;
case 3:
vid_id = 93;
break;
case 4:
vid_id = 98;
break;
default:
break;
}
if (timing->pixel_encoding == PIXEL_ENCODING_RGB ||
timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) {
for (i = 0; i < table_size_444 ; i++) {
if (prim_bpp_444[i].vic == vid_id) {
preset_found = true;
*preset_bpp = prim_bpp_444[i].target_bpp;
break;
}
}
} else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
for (i = 0; i < table_size_422 ; i++) {
if (prim_bpp_422[i].vic == vid_id) {
preset_found = true;
*preset_bpp = prim_bpp_422[i].target_bpp;
break;
}
}
} else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) {
for (i = 0; i < table_size_420 ; i++) {
if (prim_bpp_420[i].vic == vid_id) {
preset_found = true;
*preset_bpp = prim_bpp_420[i].target_bpp;
break;
}
}
} else {
return false;
}
return preset_found;
}
static int hdmi_dsc_get_num_slices(const struct dc_crtc_timing *timing)
{
int k_slice_adjust = 1;
int adj_pix_clk_mhz;
int min_slices;
int slice_target;
int slice_width = timing->h_addressable;
int h_ratio_adj_pix_clk_mhz;
if (timing->pixel_encoding == PIXEL_ENCODING_RGB ||
timing->pixel_encoding == PIXEL_ENCODING_YCBCR444)
k_slice_adjust = 2;
adj_pix_clk_mhz = k_slice_adjust * timing->pix_clk_100hz / 10000 / 2;
h_ratio_adj_pix_clk_mhz = adj_pix_clk_mhz * timing->h_addressable / timing->h_total;
if (adj_pix_clk_mhz <= 2720) {
min_slices = adj_pix_clk_mhz / 340;
if (adj_pix_clk_mhz % 340 != 0)
min_slices++;
} else if (adj_pix_clk_mhz <= 4800) {
min_slices = adj_pix_clk_mhz / 400;
if (adj_pix_clk_mhz % 400 != 0)
min_slices++;
} else if (h_ratio_adj_pix_clk_mhz <= 4800) {
min_slices = h_ratio_adj_pix_clk_mhz / 600;
if (h_ratio_adj_pix_clk_mhz % 600 != 0)
min_slices++;
} else {
min_slices = h_ratio_adj_pix_clk_mhz / 900;
if (h_ratio_adj_pix_clk_mhz % 900 != 0)
min_slices++;
}
do {
if (min_slices <= 1)
slice_target = 1;
else if (min_slices <= 2)
slice_target = 2;
else if (min_slices <= 4)
slice_target = 4;
else if (min_slices <= 8)
slice_target = 8;
else if (min_slices <= 12)
slice_target = 12;
else if (min_slices <= 16)
slice_target = 16;
else
return 0;
slice_width = timing->h_addressable / slice_target;
min_slices++;
} while (slice_width > 2720);
return slice_target;
}
static int hdmi_dsc_get_bpp(const struct dc_crtc_timing *timing,
const struct dsc_enc_caps *dsc_common_caps)
{
int max_dsc_bpp, min_dsc_bpp;
int target_bytes;
bool bpp_found = false;
int bpp_decrement_x16;
int src_fractional_bpp = dsc_common_caps->bpp_increment_div;
int bpp_target;
int bpp_target_x16;
int bpc_factor = 8;
int slice_width;
int num_slices;
bool hdmi_all_bpp = dsc_common_caps->is_vic_all_bpp;
int hdmi_max_chunk_bytes = dsc_common_caps->total_chunk_kbytes;
int preset_bpp;
bool preset_found = false;
if (timing->display_color_depth == COLOR_DEPTH_101010)
bpc_factor = 10;
if (timing->display_color_depth == COLOR_DEPTH_121212)
bpc_factor = 12;
if (timing->pixel_encoding == PIXEL_ENCODING_RGB ||
timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) {
min_dsc_bpp = 8;
max_dsc_bpp = 3 * bpc_factor;
} else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
min_dsc_bpp = 7;
max_dsc_bpp = 2 * bpc_factor;
} else {
min_dsc_bpp = 6;
max_dsc_bpp = 3 * bpc_factor / 2;
}
if (!hdmi_all_bpp)
max_dsc_bpp = min(max_dsc_bpp, 12);
num_slices = hdmi_dsc_get_num_slices(timing);
if (num_slices == 0)
return 0;
slice_width = timing->h_addressable / num_slices;
bpp_target = max_dsc_bpp;
bpp_decrement_x16 = 16 / src_fractional_bpp;
bpp_target_x16 = (bpp_target * 16) - bpp_decrement_x16;
if (!hdmi_all_bpp)
bpp_target_x16 = (bpp_target * 16);
while (bpp_target_x16 > (min_dsc_bpp * 16)) {
target_bytes = num_slices * slice_width * bpp_target_x16 / 16 / 8;
if (target_bytes <= hdmi_max_chunk_bytes) {
bpp_found = true;
break;
}
bpp_target_x16 -= bpp_decrement_x16;
}
if (bpp_found) {
if (!hdmi_all_bpp) {
preset_found = get_vic_preset_bpp(timing, &preset_bpp);
if (preset_found) {
bpp_target_x16 = preset_bpp;
target_bytes =
num_slices * slice_width * bpp_target_x16 / 16 / 8;
if (target_bytes > hdmi_max_chunk_bytes)
return 0;
}
}
return bpp_target_x16;
}
return 0;
}
bool dc_dsc_parse_dsc_dpcd(const struct dc *dc,
const uint8_t *dpcd_dsc_basic_data,
const uint8_t *dpcd_dsc_branch_decoder_caps,
struct dsc_dec_dpcd_caps *dsc_sink_caps)
{
if (!dpcd_dsc_basic_data)
return false;
dsc_sink_caps->is_dsc_supported =
(dpcd_dsc_basic_data[DP_DSC_SUPPORT - DP_DSC_SUPPORT] & DP_DSC_DECOMPRESSION_IS_SUPPORTED) != 0;
if (!dsc_sink_caps->is_dsc_supported)
return false;
dsc_sink_caps->dsc_version = dpcd_dsc_basic_data[DP_DSC_REV - DP_DSC_SUPPORT];
{
int buff_block_size;
int buff_size;
if (!dsc_buff_block_size_from_dpcd(
dpcd_dsc_basic_data[DP_DSC_RC_BUF_BLK_SIZE - DP_DSC_SUPPORT] & 0x03,
&buff_block_size))
return false;
buff_size = dpcd_dsc_basic_data[DP_DSC_RC_BUF_SIZE - DP_DSC_SUPPORT] + 1;
dsc_sink_caps->rc_buffer_size = buff_size * buff_block_size;
}
dsc_sink_caps->slice_caps1.raw = dpcd_dsc_basic_data[DP_DSC_SLICE_CAP_1 - DP_DSC_SUPPORT];
if (!dsc_line_buff_depth_from_dpcd(dpcd_dsc_basic_data[DP_DSC_LINE_BUF_BIT_DEPTH - DP_DSC_SUPPORT],
&dsc_sink_caps->lb_bit_depth))
return false;
dsc_sink_caps->is_block_pred_supported =
(dpcd_dsc_basic_data[DP_DSC_BLK_PREDICTION_SUPPORT - DP_DSC_SUPPORT] &
DP_DSC_BLK_PREDICTION_IS_SUPPORTED) != 0;
dsc_sink_caps->edp_max_bits_per_pixel =
dpcd_dsc_basic_data[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |
dpcd_dsc_basic_data[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] << 8;
dsc_sink_caps->color_formats.raw = dpcd_dsc_basic_data[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT];
dsc_sink_caps->color_depth.raw = dpcd_dsc_basic_data[DP_DSC_DEC_COLOR_DEPTH_CAP - DP_DSC_SUPPORT];
{
int dpcd_throughput = dpcd_dsc_basic_data[DP_DSC_PEAK_THROUGHPUT - DP_DSC_SUPPORT];
int dsc_throughput_granular_delta;
dsc_throughput_granular_delta = dpcd_dsc_basic_data[DP_DSC_RC_BUF_BLK_SIZE - DP_DSC_SUPPORT] >> 3;
dsc_throughput_granular_delta *= 2;
if (!dsc_throughput_from_dpcd(dpcd_throughput & DP_DSC_THROUGHPUT_MODE_0_MASK,
&dsc_sink_caps->throughput_mode_0_mps))
return false;
dsc_sink_caps->throughput_mode_0_mps += dsc_throughput_granular_delta;
dpcd_throughput = (dpcd_throughput & DP_DSC_THROUGHPUT_MODE_1_MASK) >> DP_DSC_THROUGHPUT_MODE_1_SHIFT;
if (!dsc_throughput_from_dpcd(dpcd_throughput, &dsc_sink_caps->throughput_mode_1_mps))
return false;
}
dsc_sink_caps->max_slice_width = dpcd_dsc_basic_data[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] * 320;
dsc_sink_caps->slice_caps2.raw = dpcd_dsc_basic_data[DP_DSC_SLICE_CAP_2 - DP_DSC_SUPPORT];
if (!dsc_bpp_increment_div_from_dpcd(dpcd_dsc_basic_data[DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT],
&dsc_sink_caps->bpp_increment_div))
return false;
if (dc->debug.dsc_bpp_increment_div) {
if (dc->debug.dsc_bpp_increment_div >= 1)
dsc_sink_caps->bpp_increment_div = 1;
if (dc->debug.dsc_bpp_increment_div >= 2)
dsc_sink_caps->bpp_increment_div = 2;
if (dc->debug.dsc_bpp_increment_div >= 4)
dsc_sink_caps->bpp_increment_div = 4;
if (dc->debug.dsc_bpp_increment_div >= 8)
dsc_sink_caps->bpp_increment_div = 8;
if (dc->debug.dsc_bpp_increment_div >= 16)
dsc_sink_caps->bpp_increment_div = 16;
}
if (dpcd_dsc_branch_decoder_caps == NULL) {
dsc_sink_caps->branch_overall_throughput_0_mps = 0;
dsc_sink_caps->branch_overall_throughput_1_mps = 0;
dsc_sink_caps->branch_max_line_width = 0;
return true;
}
dsc_sink_caps->branch_overall_throughput_0_mps =
dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_OVERALL_THROUGHPUT_0 - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0];
if (dsc_sink_caps->branch_overall_throughput_0_mps == 0)
dsc_sink_caps->branch_overall_throughput_0_mps = 0;
else if (dsc_sink_caps->branch_overall_throughput_0_mps == 1)
dsc_sink_caps->branch_overall_throughput_0_mps = 680;
else {
dsc_sink_caps->branch_overall_throughput_0_mps *= 50;
dsc_sink_caps->branch_overall_throughput_0_mps += 600;
}
dsc_sink_caps->branch_overall_throughput_1_mps =
dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_OVERALL_THROUGHPUT_1 - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0];
if (dsc_sink_caps->branch_overall_throughput_1_mps == 0)
dsc_sink_caps->branch_overall_throughput_1_mps = 0;
else if (dsc_sink_caps->branch_overall_throughput_1_mps == 1)
dsc_sink_caps->branch_overall_throughput_1_mps = 680;
else {
dsc_sink_caps->branch_overall_throughput_1_mps *= 50;
dsc_sink_caps->branch_overall_throughput_1_mps += 600;
}
dsc_sink_caps->branch_max_line_width =
dpcd_dsc_branch_decoder_caps[DP_DSC_BRANCH_MAX_LINE_WIDTH - DP_DSC_BRANCH_OVERALL_THROUGHPUT_0] * 320;
ASSERT(dsc_sink_caps->branch_max_line_width == 0 || dsc_sink_caps->branch_max_line_width >= 5120);
dsc_sink_caps->is_dp = true;
return true;
}
bool dc_dsc_parse_dsc_edid(const struct dc *dc, const struct dc_edid_caps *edid_caps,
struct dsc_dec_dpcd_caps *dsc_sink_caps)
{
(void)dc;
dsc_sink_caps->is_dsc_supported = edid_caps->frl_dsc_support;
if (!edid_caps->frl_dsc_support)
return false;
dsc_sink_caps->dsc_version = 0x21;
dsc_sink_caps->is_frl = true;
dsc_sink_caps->is_dp = false;
switch (edid_caps->frl_dsc_max_slices) {
case 0:
break;
case 1:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->throughput_mode_0_mps = 340;
dsc_sink_caps->throughput_mode_1_mps = 680;
break;
case 2:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->throughput_mode_0_mps = 340;
dsc_sink_caps->throughput_mode_1_mps = 680;
break;
case 3:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->throughput_mode_0_mps = 340;
dsc_sink_caps->throughput_mode_1_mps = 680;
break;
case 4:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 = 1;
dsc_sink_caps->throughput_mode_0_mps = 340;
dsc_sink_caps->throughput_mode_1_mps = 680;
break;
case 5:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 = 1;
dsc_sink_caps->throughput_mode_0_mps = 400;
dsc_sink_caps->throughput_mode_1_mps = 800;
break;
case 6:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_12 = 1;
dsc_sink_caps->throughput_mode_0_mps = 400;
dsc_sink_caps->throughput_mode_1_mps = 800;
break;
case 7:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_12 = 1;
dsc_sink_caps->throughput_mode_0_mps = 600;
dsc_sink_caps->throughput_mode_1_mps = 1200;
break;
case 8:
default:
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 = 1;
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_12 = 1;
dsc_sink_caps->throughput_mode_0_mps = 900;
dsc_sink_caps->throughput_mode_1_mps = 1800;
break;
}
dsc_sink_caps->lb_bit_depth = 13;
dsc_sink_caps->is_block_pred_supported = true;
dsc_sink_caps->color_formats.bits.RGB = 1;
dsc_sink_caps->color_formats.bits.YCBCR_444 = 1;
dsc_sink_caps->color_formats.bits.YCBCR_NATIVE_422 = 1;
dsc_sink_caps->color_formats.bits.YCBCR_NATIVE_420 =
(edid_caps->frl_dsc_native_420 == true) ? 1 : 0;
dsc_sink_caps->color_depth.bits.COLOR_DEPTH_8_BPC = 1;
dsc_sink_caps->color_depth.bits.COLOR_DEPTH_10_BPC =
(edid_caps->frl_dsc_10bpc == true) ? 1 : 0;
dsc_sink_caps->color_depth.bits.COLOR_DEPTH_12_BPC =
(edid_caps->frl_dsc_12bpc == true) ? 1 : 0;
dsc_sink_caps->max_slice_width = 2560;
dsc_sink_caps->bpp_increment_div = 16;
dsc_sink_caps->is_vic_all_bpp = edid_caps->frl_dsc_all_bpp;
dsc_sink_caps->total_chunk_kbytes =
1024 * (1 + edid_caps->frl_dsc_total_chunk_kbytes);
return true;
}
bool dc_dsc_compute_bandwidth_range(
const struct display_stream_compressor *dsc,
uint32_t dsc_min_slice_height_override,
uint32_t min_bpp_x16,
uint32_t max_bpp_x16,
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dc_crtc_timing *timing,
const enum dc_link_encoding_format link_encoding,
struct dc_dsc_bw_range *range)
{
bool is_dsc_possible = false;
unsigned int min_dsc_slice_count;
struct dsc_enc_caps dsc_enc_caps;
struct dsc_enc_caps dsc_common_caps;
struct dc_dsc_config config = {0};
struct dc_dsc_config_options options = {0};
options.dsc_min_slice_height_override = dsc_min_slice_height_override;
options.max_target_bpp_limit_override_x16 = max_bpp_x16;
options.slice_height_granularity = 1;
get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
min_dsc_slice_count = get_min_dsc_slice_count_for_odm(dsc, &dsc_enc_caps, timing);
is_dsc_possible = intersect_dsc_caps(dsc_sink_caps, &dsc_enc_caps,
timing->pixel_encoding, &dsc_common_caps);
if (is_dsc_possible)
is_dsc_possible = setup_dsc_config(dsc_sink_caps, &dsc_enc_caps, 0, timing,
&options, link_encoding, min_dsc_slice_count, &config);
if (is_dsc_possible)
is_dsc_possible = decide_dsc_bandwidth_range(min_bpp_x16, max_bpp_x16,
config.num_slices_h, &dsc_common_caps, timing, link_encoding, range);
return is_dsc_possible;
}
void dc_dsc_dump_encoder_caps(const struct display_stream_compressor *dsc,
const struct dc_crtc_timing *timing)
{
struct dsc_enc_caps dsc_enc_caps;
get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
DC_LOG_DSC("dsc encoder caps:");
DC_LOG_DSC("\tdsc_version 0x%x", dsc_enc_caps.dsc_version);
DC_LOG_DSC("\tslice_caps 0x%x", dsc_enc_caps.slice_caps.raw);
DC_LOG_DSC("\tlb_bit_depth %d", dsc_enc_caps.lb_bit_depth);
DC_LOG_DSC("\tis_block_pred_supported %d", dsc_enc_caps.is_block_pred_supported);
DC_LOG_DSC("\tcolor_formats 0x%x", dsc_enc_caps.color_formats.raw);
DC_LOG_DSC("\tcolor_depth 0x%x", dsc_enc_caps.color_depth.raw);
DC_LOG_DSC("\tmax_total_throughput_mps %d", dsc_enc_caps.max_total_throughput_mps);
DC_LOG_DSC("\tmax_slice_width %d", dsc_enc_caps.max_slice_width);
DC_LOG_DSC("\tbpp_increment_div %d", dsc_enc_caps.bpp_increment_div);
}
void dc_dsc_dump_decoder_caps(const struct display_stream_compressor *dsc,
const struct dsc_dec_dpcd_caps *dsc_sink_caps)
{
DC_LOG_DSC("dsc decoder caps:");
DC_LOG_DSC("\tis_dsc_supported %d", dsc_sink_caps->is_dsc_supported);
DC_LOG_DSC("\tdsc_version 0x%x", dsc_sink_caps->dsc_version);
DC_LOG_DSC("\trc_buffer_size %d", dsc_sink_caps->rc_buffer_size);
DC_LOG_DSC("\tslice_caps1 0x%x", dsc_sink_caps->slice_caps1.raw);
DC_LOG_DSC("\tslice_caps2 0x%x", dsc_sink_caps->slice_caps2.raw);
DC_LOG_DSC("\tlb_bit_depth %d", dsc_sink_caps->lb_bit_depth);
DC_LOG_DSC("\tis_block_pred_supported %d", dsc_sink_caps->is_block_pred_supported);
DC_LOG_DSC("\tedp_max_bits_per_pixel %d", dsc_sink_caps->edp_max_bits_per_pixel);
DC_LOG_DSC("\tcolor_formats 0x%x", dsc_sink_caps->color_formats.raw);
DC_LOG_DSC("\tthroughput_mode_0_mps %d", dsc_sink_caps->throughput_mode_0_mps);
DC_LOG_DSC("\tthroughput_mode_1_mps %d", dsc_sink_caps->throughput_mode_1_mps);
DC_LOG_DSC("\tmax_slice_width %d", dsc_sink_caps->max_slice_width);
DC_LOG_DSC("\tbpp_increment_div %d", dsc_sink_caps->bpp_increment_div);
DC_LOG_DSC("\tbranch_overall_throughput_0_mps %d", dsc_sink_caps->branch_overall_throughput_0_mps);
DC_LOG_DSC("\tbranch_overall_throughput_1_mps %d", dsc_sink_caps->branch_overall_throughput_1_mps);
DC_LOG_DSC("\tbranch_max_line_width %d", dsc_sink_caps->branch_max_line_width);
DC_LOG_DSC("\tis_dp %d", dsc_sink_caps->is_dp);
}
static void build_dsc_enc_combined_slice_caps(
const struct dsc_enc_caps *single_dsc_enc_caps,
struct dsc_enc_caps *dsc_enc_caps,
unsigned int max_odm_combine_factor)
{
dsc_enc_caps->slice_caps.raw |= single_dsc_enc_caps->slice_caps.raw;
if (max_odm_combine_factor >= 2) {
dsc_enc_caps->slice_caps.bits.NUM_SLICES_2 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_1;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_4 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_2;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_8 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_4;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_16 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_8;
}
if (max_odm_combine_factor >= 3) {
dsc_enc_caps->slice_caps.bits.NUM_SLICES_12 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_4;
}
if (max_odm_combine_factor >= 4) {
dsc_enc_caps->slice_caps.bits.NUM_SLICES_4 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_1;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_8 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_2;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_12 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_3;
dsc_enc_caps->slice_caps.bits.NUM_SLICES_16 |= single_dsc_enc_caps->slice_caps.bits.NUM_SLICES_4;
}
}
static void build_dsc_enc_caps(
const struct display_stream_compressor *dsc,
struct dsc_enc_caps *dsc_enc_caps)
{
unsigned int max_dscclk_khz;
unsigned int num_dsc;
unsigned int max_odm_combine_factor;
struct dsc_enc_caps single_dsc_enc_caps;
struct dc *dc;
if (!dsc || !dsc->ctx || !dsc->ctx->dc || !dsc->funcs->dsc_get_single_enc_caps)
return;
dc = dsc->ctx->dc;
if (!dc->clk_mgr || !dc->clk_mgr->funcs->get_max_clock_khz || !dc->res_pool || dc->debug.disable_dsc)
return;
max_dscclk_khz = dc->clk_mgr->funcs->get_max_clock_khz(dc->clk_mgr, CLK_TYPE_DSCCLK);
dsc->funcs->dsc_get_single_enc_caps(&single_dsc_enc_caps, max_dscclk_khz);
dsc_enc_caps->dsc_version = single_dsc_enc_caps.dsc_version;
dsc_enc_caps->lb_bit_depth = single_dsc_enc_caps.lb_bit_depth;
dsc_enc_caps->is_block_pred_supported = single_dsc_enc_caps.is_block_pred_supported;
dsc_enc_caps->max_slice_width = single_dsc_enc_caps.max_slice_width;
dsc_enc_caps->bpp_increment_div = single_dsc_enc_caps.bpp_increment_div;
dsc_enc_caps->color_formats.raw = single_dsc_enc_caps.color_formats.raw;
dsc_enc_caps->color_depth.raw = single_dsc_enc_caps.color_depth.raw;
max_odm_combine_factor = dc->caps.max_odm_combine_factor;
num_dsc = dc->res_pool->res_cap->num_dsc;
max_odm_combine_factor = min(max_odm_combine_factor, num_dsc);
dsc_enc_caps->max_total_throughput_mps =
single_dsc_enc_caps.max_total_throughput_mps *
max_odm_combine_factor;
build_dsc_enc_combined_slice_caps(&single_dsc_enc_caps, dsc_enc_caps, max_odm_combine_factor);
}
static inline uint32_t dsc_div_by_10_round_up(uint32_t value)
{
return (value + 9) / 10;
}
static unsigned int get_min_dsc_slice_count_for_odm(
const struct display_stream_compressor *dsc,
const struct dsc_enc_caps *dsc_enc_caps,
const struct dc_crtc_timing *timing)
{
unsigned int max_dispclk_khz;
max_dispclk_khz = dsc_enc_caps->max_total_throughput_mps * 1000;
if (dsc && dsc->ctx->dc) {
if (dsc->ctx->dc->clk_mgr &&
dsc->ctx->dc->clk_mgr->funcs->get_max_clock_khz) {
max_dispclk_khz = dsc->ctx->dc->clk_mgr->funcs->get_max_clock_khz(dsc->ctx->dc->clk_mgr, CLK_TYPE_DISPCLK);
}
}
if (max_dispclk_khz == 0 || dsc_enc_caps->max_slice_width == 0)
return 1;
return dc_fixpt_ceil(dc_fixpt_max(
dc_fixpt_div_int(dc_fixpt_from_int(dsc_div_by_10_round_up(timing->pix_clk_100hz)),
max_dispclk_khz),
dc_fixpt_div_int(dc_fixpt_from_int(timing->h_addressable + timing->h_border_left + timing->h_border_right),
dsc_enc_caps->max_slice_width)));
}
static void get_dsc_enc_caps(
const struct display_stream_compressor *dsc,
struct dsc_enc_caps *dsc_enc_caps,
int pixel_clock_100Hz)
{
memset(dsc_enc_caps, 0, sizeof(struct dsc_enc_caps));
if (!dsc || !dsc->ctx || !dsc->ctx->dc || dsc->ctx->dc->debug.disable_dsc)
return;
if (dsc->funcs->dsc_get_enc_caps) {
dsc->funcs->dsc_get_enc_caps(dsc_enc_caps, pixel_clock_100Hz);
} else {
build_dsc_enc_caps(dsc, dsc_enc_caps);
}
}
static bool intersect_dsc_caps(
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dsc_enc_caps *dsc_enc_caps,
enum dc_pixel_encoding pixel_encoding,
struct dsc_enc_caps *dsc_common_caps)
{
int32_t max_slices;
int32_t total_sink_throughput;
memset(dsc_common_caps, 0, sizeof(struct dsc_enc_caps));
dsc_common_caps->dsc_version = min(dsc_sink_caps->dsc_version, dsc_enc_caps->dsc_version);
if (!dsc_common_caps->dsc_version)
return false;
dsc_common_caps->slice_caps.bits.NUM_SLICES_1 =
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_1 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_1;
dsc_common_caps->slice_caps.bits.NUM_SLICES_2 =
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_2 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_2;
dsc_common_caps->slice_caps.bits.NUM_SLICES_4 =
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_4 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_4;
dsc_common_caps->slice_caps.bits.NUM_SLICES_8 =
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_8 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_8;
dsc_common_caps->slice_caps.bits.NUM_SLICES_12 =
dsc_sink_caps->slice_caps1.bits.NUM_SLICES_12 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_12;
dsc_common_caps->slice_caps.bits.NUM_SLICES_16 =
dsc_sink_caps->slice_caps2.bits.NUM_SLICES_16 && dsc_enc_caps->slice_caps.bits.NUM_SLICES_16;
if (!dsc_common_caps->slice_caps.raw)
return false;
dsc_common_caps->lb_bit_depth = min(dsc_sink_caps->lb_bit_depth, dsc_enc_caps->lb_bit_depth);
if (!dsc_common_caps->lb_bit_depth)
return false;
dsc_common_caps->is_block_pred_supported =
dsc_sink_caps->is_block_pred_supported && dsc_enc_caps->is_block_pred_supported;
dsc_common_caps->color_formats.raw = dsc_sink_caps->color_formats.raw & dsc_enc_caps->color_formats.raw;
if (!dsc_common_caps->color_formats.raw)
return false;
dsc_common_caps->color_depth.raw = dsc_sink_caps->color_depth.raw & dsc_enc_caps->color_depth.raw;
if (!dsc_common_caps->color_depth.raw)
return false;
max_slices = 0;
if (dsc_common_caps->slice_caps.bits.NUM_SLICES_1)
max_slices = 1;
if (dsc_common_caps->slice_caps.bits.NUM_SLICES_2)
max_slices = 2;
if (dsc_common_caps->slice_caps.bits.NUM_SLICES_4)
max_slices = 4;
total_sink_throughput = max_slices * dsc_sink_caps->throughput_mode_0_mps;
if (pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420)
total_sink_throughput = max_slices * dsc_sink_caps->throughput_mode_1_mps;
dsc_common_caps->max_total_throughput_mps = min(total_sink_throughput, dsc_enc_caps->max_total_throughput_mps);
dsc_common_caps->max_slice_width = min(dsc_sink_caps->max_slice_width, dsc_enc_caps->max_slice_width);
if (!dsc_common_caps->max_slice_width)
return false;
dsc_common_caps->bpp_increment_div = min(dsc_sink_caps->bpp_increment_div, dsc_enc_caps->bpp_increment_div);
if (pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420)
dsc_common_caps->bpp_increment_div = min(dsc_common_caps->bpp_increment_div, (uint32_t)8);
dsc_common_caps->is_frl = dsc_sink_caps->is_frl;
dsc_common_caps->is_vic_all_bpp = dsc_sink_caps->is_vic_all_bpp;
dsc_common_caps->total_chunk_kbytes = dsc_sink_caps->total_chunk_kbytes;
dsc_common_caps->edp_sink_max_bits_per_pixel = dsc_sink_caps->edp_max_bits_per_pixel;
dsc_common_caps->is_dp = dsc_sink_caps->is_dp;
return true;
}
static uint32_t compute_bpp_x16_from_target_bandwidth(
const uint32_t bandwidth_in_kbps,
const struct dc_crtc_timing *timing,
const uint32_t num_slices_h,
const uint32_t bpp_increment_div,
const bool is_dp)
{
uint32_t overhead_in_kbps;
struct fixed31_32 effective_bandwidth_in_kbps;
struct fixed31_32 bpp_x16;
overhead_in_kbps = dc_dsc_stream_bandwidth_overhead_in_kbps(
timing, num_slices_h, is_dp);
effective_bandwidth_in_kbps = dc_fixpt_from_int(bandwidth_in_kbps);
effective_bandwidth_in_kbps = dc_fixpt_sub_int(effective_bandwidth_in_kbps,
overhead_in_kbps);
bpp_x16 = dc_fixpt_mul_int(effective_bandwidth_in_kbps, 10);
bpp_x16 = dc_fixpt_div_int(bpp_x16, timing->pix_clk_100hz);
bpp_x16 = dc_fixpt_from_int(dc_fixpt_floor(dc_fixpt_mul_int(bpp_x16, bpp_increment_div)));
bpp_x16 = dc_fixpt_div_int(bpp_x16, bpp_increment_div);
bpp_x16 = dc_fixpt_mul_int(bpp_x16, 16);
return dc_fixpt_floor(bpp_x16);
}
static bool convert_bandwidth_to_frl_params(
int bandwidth_kbps,
int *num_lanes,
int *frl_rate)
{
if (bandwidth_kbps == 0)
return false;
switch (bandwidth_kbps) {
case 9000000:
*num_lanes = 3;
*frl_rate = 3000;
break;
case 18000000:
*num_lanes = 3;
*frl_rate = 6000;
break;
case 24000000:
*num_lanes = 4;
*frl_rate = 6000;
break;
case 32000000:
*num_lanes = 4;
*frl_rate = 8000;
break;
case 40000000:
*num_lanes = 4;
*frl_rate = 10000;
break;
case 48000000:
*num_lanes = 4;
*frl_rate = 12000;
break;
case 64000000:
*num_lanes = 4;
*frl_rate = 16000;
break;
case 80000000:
*num_lanes = 4;
*frl_rate = 20000;
break;
default:
return false;
}
return true;
}
static uint32_t compute_bpp_x16_from_frl_params(
const struct dc_crtc_timing *timing,
const uint32_t num_slices_h,
const struct dsc_enc_caps *dsc_caps)
{
struct fixed31_32 pixel_clock;
uint32_t num_lanes = dsc_caps->num_lanes;
uint32_t frl_rate = dsc_caps->frl_rate;
uint32_t h_active = timing->h_addressable;
uint32_t h_blank = timing->h_total - timing->h_addressable;
uint32_t bpp_target_x16;
struct fixed31_32 r_bit;
uint32_t f_audio = 48000;
struct fixed31_32 pixel_rate_tolerance;
uint32_t audio_tolerance = 1000;
uint32_t frl_bit_tolerance = 300;
uint32_t acr_rate_max = 1500;
uint32_t c_frl_cb = 510;
uint32_t c_frl_sb;
struct fixed31_32 overhead_sb;
struct fixed31_32 overhead_rs;
struct fixed31_32 overhead_map;
struct fixed31_32 overhead_min;
struct fixed31_32 overhead_m;
struct fixed31_32 overhead_max;
struct fixed31_32 pixel_clock_max;
struct fixed31_32 t_line;
struct fixed31_32 r_bit_min;
struct fixed31_32 r_frl_char_min;
struct fixed31_32 c_frl_line;
uint32_t c_frl_line_int;
struct fixed31_32 c_frl_available;
uint32_t c_frl_av_int;
struct fixed31_32 c_frl_active_av;
struct fixed31_32 c_frl_blank_av;
uint32_t acat_ap = 4;
struct fixed31_32 r_ap;
struct fixed31_32 max_audio_tol_rate;
struct fixed31_32 avg_audio_packets_line;
uint32_t avg_audio_packets_line_int;
int hc_blank_audio_min;
uint32_t bytes_target;
uint32_t hc_active_target;
uint32_t hc_blank_target_est1;
uint32_t hc_blank_target_est2;
struct fixed31_32 hc_blank_target_bandwidth;
int hc_blank_target;
uint32_t bpc_factor = 8;
uint32_t min_dsc_bpp_x16;
uint32_t max_dsc_bpp_x16;
bool hdmi_all_bpp = dsc_caps->is_vic_all_bpp;
uint32_t slice_width;
if (timing->display_color_depth == COLOR_DEPTH_101010)
bpc_factor = 10;
if (timing->display_color_depth == COLOR_DEPTH_121212)
bpc_factor = 12;
if (timing->pixel_encoding == PIXEL_ENCODING_RGB ||
timing->pixel_encoding == PIXEL_ENCODING_YCBCR444) {
min_dsc_bpp_x16 = 8 * 16;
max_dsc_bpp_x16 = 3 * 16 * bpc_factor;
} else if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422) {
min_dsc_bpp_x16 = 7 * 16;
max_dsc_bpp_x16 = 2 * 16 * bpc_factor;
} else {
min_dsc_bpp_x16 = 6 * 16;
max_dsc_bpp_x16 = 3 * 16 * bpc_factor / 2;
}
max_dsc_bpp_x16 = MIN(max_dsc_bpp_x16, 256);
if (!hdmi_all_bpp)
max_dsc_bpp_x16 = MIN(max_dsc_bpp_x16, 192);
c_frl_sb = 4 * c_frl_cb + num_lanes;
pixel_clock = dc_fixpt_div_int(dc_fixpt_from_int(timing->pix_clk_100hz), 10000);
r_bit = dc_fixpt_from_int(frl_rate);
pixel_rate_tolerance = dc_fixpt_div_int(dc_fixpt_from_int(5), 1000);
overhead_sb = dc_fixpt_div_int(dc_fixpt_from_int(num_lanes), c_frl_sb);
overhead_rs = dc_fixpt_div_int(dc_fixpt_from_int(32), c_frl_sb);
overhead_map = dc_fixpt_div_int(dc_fixpt_from_int(25), (c_frl_sb * 10));
overhead_min = dc_fixpt_add(overhead_sb, overhead_rs);
overhead_min = dc_fixpt_add(overhead_min, overhead_map);
overhead_m = dc_fixpt_div_int(dc_fixpt_from_int(3), 1000);
overhead_max = dc_fixpt_add(overhead_min, overhead_m);
pixel_rate_tolerance = dc_fixpt_add_int(pixel_rate_tolerance, 1);
pixel_clock_max = dc_fixpt_mul(pixel_clock, pixel_rate_tolerance);
t_line = dc_fixpt_div(dc_fixpt_from_int(h_active + h_blank), pixel_clock_max);
r_bit_min = dc_fixpt_div_int(dc_fixpt_from_int(frl_bit_tolerance), 1000000);
r_bit_min = dc_fixpt_sub(dc_fixpt_from_int(1), r_bit_min);
r_bit_min = dc_fixpt_mul(r_bit, r_bit_min);
r_frl_char_min = dc_fixpt_div_int(r_bit_min, 18);
c_frl_line = dc_fixpt_mul(t_line, r_frl_char_min);
c_frl_line = dc_fixpt_mul_int(c_frl_line, num_lanes);
c_frl_line_int = dc_fixpt_floor(c_frl_line);
c_frl_available = dc_fixpt_sub(dc_fixpt_from_int(1), overhead_max);
c_frl_available = dc_fixpt_mul_int(c_frl_available, c_frl_line_int);
c_frl_av_int = dc_fixpt_floor(c_frl_available);
c_frl_active_av = dc_fixpt_mul_int(dc_fixpt_from_int(c_frl_av_int), h_active);
c_frl_active_av = dc_fixpt_div_int(c_frl_active_av, (h_active + h_blank));
c_frl_blank_av = dc_fixpt_mul_int(dc_fixpt_from_int(c_frl_av_int), h_blank);
c_frl_blank_av = dc_fixpt_div_int(c_frl_blank_av, (h_active + h_blank));
r_ap = dc_fixpt_max(dc_fixpt_from_int(192000),
dc_fixpt_from_int(f_audio * acat_ap));
r_ap = dc_fixpt_add(r_ap, dc_fixpt_from_int(2 * acr_rate_max));
max_audio_tol_rate = dc_fixpt_div_int(dc_fixpt_from_int(audio_tolerance), 1000000);
max_audio_tol_rate = dc_fixpt_add(dc_fixpt_from_int(1), max_audio_tol_rate);
r_ap = dc_fixpt_mul(r_ap, max_audio_tol_rate);
avg_audio_packets_line = dc_fixpt_mul(r_ap, t_line);
avg_audio_packets_line = dc_fixpt_div_int(avg_audio_packets_line, 1000000);
avg_audio_packets_line_int = dc_fixpt_ceil(avg_audio_packets_line);
hc_blank_audio_min = 32 + 32 * avg_audio_packets_line_int;
slice_width = dc_fixpt_ceil(dc_fixpt_div_int(
dc_fixpt_from_int(h_active), num_slices_h));
if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 && slice_width % 2 != 0) {
slice_width++;
}
for (uint32_t i = max_dsc_bpp_x16; i >= min_dsc_bpp_x16; i--) {
bpp_target_x16 = i;
bytes_target = num_slices_h * dc_fixpt_ceil(dc_fixpt_div_int(
dc_fixpt_from_int(bpp_target_x16 * slice_width), 8 * 16));
hc_active_target = dc_fixpt_ceil(dc_fixpt_div_int(
dc_fixpt_from_int(bytes_target), 3));
hc_blank_target_est1 = dc_fixpt_ceil(dc_fixpt_div_int(
dc_fixpt_from_int(hc_active_target * h_blank), h_active));
hc_blank_target_est2 = dc_fixpt_floor(dc_fixpt_max(
dc_fixpt_from_int(hc_blank_target_est1),
dc_fixpt_from_int(hc_blank_audio_min)));
hc_blank_target_bandwidth = dc_fixpt_div_int(dc_fixpt_from_int(3), 2);
hc_blank_target_bandwidth = dc_fixpt_mul(hc_blank_target_bandwidth,
dc_fixpt_from_int(hc_active_target));
hc_blank_target_bandwidth = dc_fixpt_sub(dc_fixpt_from_int(c_frl_av_int),
hc_blank_target_bandwidth);
hc_blank_target_bandwidth = dc_fixpt_min(hc_blank_target_bandwidth,
dc_fixpt_from_int(hc_blank_target_est2));
hc_blank_target_bandwidth = dc_fixpt_div_int(hc_blank_target_bandwidth, 4);
hc_blank_target = dc_fixpt_floor(hc_blank_target_bandwidth) * 4;
if (hc_blank_target >= hc_blank_audio_min)
return bpp_target_x16;
}
return 0;
}
static bool decide_dsc_bandwidth_range(
const uint32_t min_bpp_x16,
const uint32_t max_bpp_x16,
const uint32_t num_slices_h,
const struct dsc_enc_caps *dsc_caps,
const struct dc_crtc_timing *timing,
const enum dc_link_encoding_format link_encoding,
struct dc_dsc_bw_range *range)
{
uint32_t preferred_bpp_x16 = timing->dsc_fixed_bits_per_pixel_x16;
memset(range, 0, sizeof(*range));
if (preferred_bpp_x16) {
if (preferred_bpp_x16 <= max_bpp_x16 &&
preferred_bpp_x16 >= min_bpp_x16) {
range->max_target_bpp_x16 = preferred_bpp_x16;
range->min_target_bpp_x16 = preferred_bpp_x16;
}
}
else if (dsc_caps->is_frl) {
uint32_t specs_preferred_bpp_x16 = hdmi_dsc_get_bpp(timing, dsc_caps);
uint32_t specs_calculated_bpp_x16 = 0;
if (timing->vic) {
range->max_target_bpp_x16 = specs_preferred_bpp_x16;
if (dsc_caps->is_vic_all_bpp || dsc_caps->is_dp)
range->min_target_bpp_x16 = min_bpp_x16;
else
range->min_target_bpp_x16 = specs_preferred_bpp_x16;
} else {
if (timing->vic == 0 && timing->hdmi_vic == 0)
specs_calculated_bpp_x16 = compute_bpp_x16_from_frl_params(
timing, num_slices_h, dsc_caps);
if (specs_calculated_bpp_x16 != 0)
specs_preferred_bpp_x16 = MIN(specs_calculated_bpp_x16,
specs_preferred_bpp_x16);
range->max_target_bpp_x16 = MIN(max_bpp_x16, specs_preferred_bpp_x16);
range->min_target_bpp_x16 = min_bpp_x16;
}
}
else if (dsc_caps->edp_sink_max_bits_per_pixel) {
range->max_target_bpp_x16 = MIN(dsc_caps->edp_sink_max_bits_per_pixel,
max_bpp_x16);
range->min_target_bpp_x16 = min_bpp_x16;
}
else {
range->max_target_bpp_x16 = max_bpp_x16;
range->min_target_bpp_x16 = min_bpp_x16;
}
if (range->max_target_bpp_x16 >= range->min_target_bpp_x16 && range->min_target_bpp_x16 > 0) {
range->stream_kbps = dc_bandwidth_in_kbps_from_timing(timing, link_encoding);
range->max_kbps = dc_dsc_stream_bandwidth_in_kbps(timing,
range->max_target_bpp_x16, num_slices_h, dsc_caps->is_dp);
range->min_kbps = dc_dsc_stream_bandwidth_in_kbps(timing,
range->min_target_bpp_x16, num_slices_h, dsc_caps->is_dp);
}
return range->max_kbps >= range->min_kbps && range->min_kbps > 0;
}
static bool decide_dsc_target_bpp_x16(
const struct dc_dsc_policy *policy,
const struct dc_dsc_config_options *options,
const struct dsc_enc_caps *dsc_common_caps,
const int target_bandwidth_kbps,
const struct dc_crtc_timing *timing,
const int num_slices_h,
const enum dc_link_encoding_format link_encoding,
int *target_bpp_x16)
{
struct dc_dsc_bw_range range;
uint32_t target_bandwidth_kbps_u = (uint32_t)target_bandwidth_kbps;
*target_bpp_x16 = 0;
if (decide_dsc_bandwidth_range(policy->min_target_bpp * 16, policy->max_target_bpp * 16,
num_slices_h, dsc_common_caps, timing, link_encoding, &range)) {
if (target_bandwidth_kbps_u >= range.stream_kbps) {
if (policy->enable_dsc_when_not_needed || options->force_dsc_when_not_needed)
*target_bpp_x16 = range.max_target_bpp_x16;
} else if (target_bandwidth_kbps_u >= range.max_kbps) {
*target_bpp_x16 = range.max_target_bpp_x16;
} else if (target_bandwidth_kbps_u >= range.min_kbps) {
*target_bpp_x16 = compute_bpp_x16_from_target_bandwidth(
target_bandwidth_kbps, timing, num_slices_h,
dsc_common_caps->bpp_increment_div,
dsc_common_caps->is_dp);
}
if (target_bandwidth_kbps < range.min_kbps)
if (dsc_common_caps->is_frl)
*target_bpp_x16 = range.min_target_bpp_x16;
}
return *target_bpp_x16 != 0;
}
#define MIN_AVAILABLE_SLICES_SIZE 6
static int get_available_dsc_slices(union dsc_enc_slice_caps slice_caps, int *available_slices)
{
int idx = 0;
if (slice_caps.bits.NUM_SLICES_1)
available_slices[idx++] = 1;
if (slice_caps.bits.NUM_SLICES_2)
available_slices[idx++] = 2;
if (slice_caps.bits.NUM_SLICES_4)
available_slices[idx++] = 4;
if (slice_caps.bits.NUM_SLICES_8)
available_slices[idx++] = 8;
if (slice_caps.bits.NUM_SLICES_12)
available_slices[idx++] = 12;
if (slice_caps.bits.NUM_SLICES_16)
available_slices[idx++] = 16;
return idx;
}
static int get_max_dsc_slices(union dsc_enc_slice_caps slice_caps)
{
int max_slices = 0;
int available_slices[MIN_AVAILABLE_SLICES_SIZE];
int end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
if (end_idx > 0)
max_slices = available_slices[end_idx - 1];
return max_slices;
}
static int inc_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
{
int available_slices[MIN_AVAILABLE_SLICES_SIZE];
int end_idx;
int i;
int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
if (end_idx == 0) {
new_num_slices++;
return new_num_slices;
}
for (i = 0; i < end_idx; i++) {
if (new_num_slices < available_slices[i]) {
new_num_slices = available_slices[i];
break;
}
}
if (new_num_slices == num_slices)
new_num_slices++;
return new_num_slices;
}
static int dec_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
{
int available_slices[MIN_AVAILABLE_SLICES_SIZE];
int end_idx;
int i;
int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
if (end_idx == 0 && new_num_slices > 0) {
new_num_slices++;
return new_num_slices;
}
for (i = end_idx - 1; i >= 0; i--) {
if (new_num_slices > available_slices[i]) {
new_num_slices = available_slices[i];
break;
}
}
if (new_num_slices == num_slices) {
new_num_slices--;
if (new_num_slices < 0)
new_num_slices = 0;
}
return new_num_slices;
}
static int fit_num_slices_up(union dsc_enc_slice_caps slice_caps, int num_slices)
{
int available_slices[MIN_AVAILABLE_SLICES_SIZE];
int end_idx;
int i;
int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
if (end_idx == 0) {
new_num_slices++;
return new_num_slices;
}
for (i = 0; i < end_idx; i++) {
if (new_num_slices <= available_slices[i]) {
new_num_slices = available_slices[i];
break;
}
}
return new_num_slices;
}
static bool setup_dsc_config(
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dsc_enc_caps *dsc_enc_caps,
int target_bandwidth_kbps,
const struct dc_crtc_timing *timing,
const struct dc_dsc_config_options *options,
const enum dc_link_encoding_format link_encoding,
int min_slices_h,
struct dc_dsc_config *dsc_cfg)
{
struct dsc_enc_caps dsc_common_caps;
int max_slices_h = 0;
int num_slices_h = 0;
int pic_width;
uint32_t pic_width_u;
int slice_width;
int target_bpp;
int sink_per_slice_throughput_mps;
uint32_t branch_max_throughput_mps = 0;
bool is_dsc_possible = false;
int pic_height;
int slice_height;
struct dc_dsc_policy policy;
int num_lanes;
int frl_rate;
memset(dsc_cfg, 0, sizeof(struct dc_dsc_config));
dc_dsc_get_policy_for_timing(timing, options->max_target_bpp_limit_override_x16, &policy, link_encoding);
pic_width = timing->h_addressable + timing->h_border_left + timing->h_border_right;
pic_width_u = (uint32_t)pic_width;
pic_height = timing->v_addressable + timing->v_border_top + timing->v_border_bottom;
if (!dsc_sink_caps->is_dsc_supported)
goto done;
if (dsc_sink_caps->branch_max_line_width && dsc_sink_caps->branch_max_line_width < pic_width_u)
goto done;
is_dsc_possible = intersect_dsc_caps(dsc_sink_caps, dsc_enc_caps, timing->pixel_encoding, &dsc_common_caps);
if (!is_dsc_possible)
goto done;
if (convert_bandwidth_to_frl_params(
target_bandwidth_kbps, &num_lanes, &frl_rate)) {
dsc_common_caps.num_lanes = num_lanes;
dsc_common_caps.frl_rate = frl_rate;
}
sink_per_slice_throughput_mps = 0;
dsc_cfg->ycbcr422_simple = false;
switch (timing->pixel_encoding) {
case PIXEL_ENCODING_RGB:
is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.RGB;
sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_0_mps;
break;
case PIXEL_ENCODING_YCBCR444:
is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_444;
sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_0_mps;
break;
case PIXEL_ENCODING_YCBCR422:
if (policy.ycbcr422_simple) {
is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_SIMPLE_422;
dsc_cfg->ycbcr422_simple = is_dsc_possible;
sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_0_mps;
} else {
is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_NATIVE_422;
sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_1_mps;
branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_1_mps;
}
break;
case PIXEL_ENCODING_YCBCR420:
is_dsc_possible = (bool)dsc_common_caps.color_formats.bits.YCBCR_NATIVE_420;
sink_per_slice_throughput_mps = dsc_sink_caps->throughput_mode_1_mps;
branch_max_throughput_mps = dsc_sink_caps->branch_overall_throughput_1_mps;
break;
default:
is_dsc_possible = false;
}
if (branch_max_throughput_mps && dsc_div_by_10_round_up(timing->pix_clk_100hz) > branch_max_throughput_mps * 1000)
is_dsc_possible = false;
if (!is_dsc_possible)
goto done;
switch (timing->display_color_depth) {
case COLOR_DEPTH_888:
is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_8_BPC;
break;
case COLOR_DEPTH_101010:
is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_10_BPC;
break;
case COLOR_DEPTH_121212:
is_dsc_possible = (bool)dsc_common_caps.color_depth.bits.COLOR_DEPTH_12_BPC;
break;
default:
is_dsc_possible = false;
}
if (!is_dsc_possible)
goto done;
max_slices_h = get_max_dsc_slices(dsc_common_caps.slice_caps);
while (max_slices_h > 0) {
if (pic_width % max_slices_h == 0)
break;
max_slices_h = dec_num_slices(dsc_common_caps.slice_caps, max_slices_h);
}
is_dsc_possible = (dsc_common_caps.max_slice_width > 0);
if (!is_dsc_possible)
goto done;
min_slices_h = dc_fixpt_ceil(dc_fixpt_max(
dc_fixpt_div_int(dc_fixpt_from_int(pic_width), dsc_common_caps.max_slice_width),
dc_fixpt_from_int(min_slices_h)));
min_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, min_slices_h);
while (min_slices_h <= max_slices_h) {
int pix_clk_per_slice_khz = dsc_div_by_10_round_up(timing->pix_clk_100hz) / min_slices_h;
if (pix_clk_per_slice_khz <= sink_per_slice_throughput_mps * 1000)
break;
min_slices_h = inc_num_slices(dsc_common_caps.slice_caps, min_slices_h);
}
while (pic_width % min_slices_h != 0 && min_slices_h <= max_slices_h) {
min_slices_h = inc_num_slices(dsc_common_caps.slice_caps, min_slices_h);
}
is_dsc_possible = (min_slices_h <= max_slices_h) && max_slices_h != 0;
if (!is_dsc_possible)
goto done;
if (policy.use_min_slices_h) {
if (min_slices_h > 0)
num_slices_h = min_slices_h;
else if (max_slices_h > 0) {
if (policy.max_slices_h)
num_slices_h = min(policy.max_slices_h, max_slices_h);
else
num_slices_h = max_slices_h;
} else
is_dsc_possible = false;
} else {
if (max_slices_h > 0) {
if (policy.max_slices_h)
num_slices_h = min(policy.max_slices_h, max_slices_h);
else
num_slices_h = max_slices_h;
} else if (min_slices_h > 0)
num_slices_h = min_slices_h;
else
is_dsc_possible = false;
}
if (dsc_sink_caps->is_frl)
num_slices_h = hdmi_dsc_get_num_slices(timing);
switch (options->dsc_force_odm_hslice_override) {
case 0:
case 1:
break;
case 2:
if (num_slices_h < 2)
num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 2);
break;
case 3:
if (dsc_common_caps.slice_caps.bits.NUM_SLICES_12)
num_slices_h = 12;
else
num_slices_h = 0;
break;
case 4:
if (num_slices_h < 4)
num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 4);
break;
default:
break;
}
if (num_slices_h == 0)
is_dsc_possible = false;
if (!is_dsc_possible)
goto done;
dsc_cfg->num_slices_h = num_slices_h;
slice_width = pic_width / num_slices_h;
is_dsc_possible = slice_width <= dsc_common_caps.max_slice_width;
if (!is_dsc_possible)
goto done;
if (options->dsc_min_slice_height_override == 0)
slice_height = min(policy.min_slice_height, pic_height);
else
slice_height = min((int)(options->dsc_min_slice_height_override), pic_height);
while (slice_height < pic_height && (pic_height % slice_height != 0 ||
slice_height % options->slice_height_granularity != 0 ||
(timing->pixel_encoding == PIXEL_ENCODING_YCBCR420 && slice_height % 2 != 0)))
slice_height++;
if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
is_dsc_possible = (slice_height % 2 == 0);
if (!is_dsc_possible)
goto done;
if (slice_height > 0) {
dsc_cfg->num_slices_v = pic_height / slice_height;
} else {
is_dsc_possible = false;
goto done;
}
if (target_bandwidth_kbps > 0) {
is_dsc_possible = decide_dsc_target_bpp_x16(
&policy,
options,
&dsc_common_caps,
target_bandwidth_kbps,
timing,
num_slices_h,
link_encoding,
&target_bpp);
dsc_cfg->bits_per_pixel = target_bpp;
}
if (!is_dsc_possible)
goto done;
dsc_cfg->block_pred_enable = dsc_common_caps.is_block_pred_supported;
dsc_cfg->linebuf_depth = dsc_common_caps.lb_bit_depth;
dsc_cfg->version_minor = (dsc_common_caps.dsc_version & 0xf0) >> 4;
dsc_cfg->is_frl = dsc_sink_caps->is_frl;
if (dsc_cfg->is_frl)
dsc_cfg->num_slices_h = num_slices_h;
dsc_cfg->is_vic_all_bpp = dsc_sink_caps->is_vic_all_bpp;
dsc_cfg->total_chunk_kbytes = dsc_sink_caps->total_chunk_kbytes;
dsc_cfg->is_dp = dsc_sink_caps->is_dp;
done:
if (!is_dsc_possible)
memset(dsc_cfg, 0, sizeof(struct dc_dsc_config));
return is_dsc_possible;
}
bool dc_dsc_compute_config(
const struct display_stream_compressor *dsc,
const struct dsc_dec_dpcd_caps *dsc_sink_caps,
const struct dc_dsc_config_options *options,
uint32_t target_bandwidth_kbps,
const struct dc_crtc_timing *timing,
const enum dc_link_encoding_format link_encoding,
struct dc_dsc_config *dsc_cfg)
{
bool is_dsc_possible = false;
struct dsc_enc_caps dsc_enc_caps;
unsigned int min_dsc_slice_count;
get_dsc_enc_caps(dsc, &dsc_enc_caps, timing->pix_clk_100hz);
min_dsc_slice_count = get_min_dsc_slice_count_for_odm(dsc, &dsc_enc_caps, timing);
is_dsc_possible = setup_dsc_config(dsc_sink_caps,
&dsc_enc_caps,
target_bandwidth_kbps,
timing,
options,
link_encoding,
min_dsc_slice_count,
dsc_cfg);
return is_dsc_possible;
}
uint32_t dc_dsc_stream_bandwidth_in_kbps(const struct dc_crtc_timing *timing,
uint32_t bpp_x16, uint32_t num_slices_h, bool is_dp)
{
uint32_t overhead_in_kbps;
struct fixed31_32 bpp;
struct fixed31_32 actual_bandwidth_in_kbps;
overhead_in_kbps = dc_dsc_stream_bandwidth_overhead_in_kbps(
timing, num_slices_h, is_dp);
bpp = dc_fixpt_from_fraction(bpp_x16, 16);
actual_bandwidth_in_kbps = dc_fixpt_from_fraction(timing->pix_clk_100hz, 10);
actual_bandwidth_in_kbps = dc_fixpt_mul(actual_bandwidth_in_kbps, bpp);
actual_bandwidth_in_kbps = dc_fixpt_add_int(actual_bandwidth_in_kbps, overhead_in_kbps);
return dc_fixpt_ceil(actual_bandwidth_in_kbps);
}
uint32_t dc_dsc_stream_bandwidth_overhead_in_kbps(
const struct dc_crtc_timing *timing,
const uint32_t num_slices_h,
const bool is_dp)
{
struct fixed31_32 max_dsc_overhead;
struct fixed31_32 refresh_rate;
if (dsc_policy_disable_dsc_stream_overhead || !is_dp)
return 0;
refresh_rate = dc_fixpt_from_int(timing->pix_clk_100hz);
refresh_rate = dc_fixpt_div_int(refresh_rate, timing->h_total);
refresh_rate = dc_fixpt_div_int(refresh_rate, timing->v_total);
refresh_rate = dc_fixpt_mul_int(refresh_rate, 100);
max_dsc_overhead = dc_fixpt_from_int(num_slices_h);
max_dsc_overhead = dc_fixpt_mul_int(max_dsc_overhead, timing->v_total);
max_dsc_overhead = dc_fixpt_mul_int(max_dsc_overhead, 256);
max_dsc_overhead = dc_fixpt_div_int(max_dsc_overhead, 1000);
max_dsc_overhead = dc_fixpt_mul(max_dsc_overhead, refresh_rate);
return dc_fixpt_ceil(max_dsc_overhead);
}
void dc_dsc_get_policy_for_timing(const struct dc_crtc_timing *timing,
uint32_t max_target_bpp_limit_override_x16,
struct dc_dsc_policy *policy,
const enum dc_link_encoding_format link_encoding)
{
uint32_t bpc = 0;
policy->min_target_bpp = 0;
policy->max_target_bpp = 0;
policy->use_min_slices_h = true;
policy->max_slices_h = 0;
policy->min_slice_height = 108;
switch (timing->display_color_depth) {
case COLOR_DEPTH_888:
bpc = 8;
break;
case COLOR_DEPTH_101010:
bpc = 10;
break;
case COLOR_DEPTH_121212:
bpc = 12;
break;
default:
return;
}
switch (timing->pixel_encoding) {
case PIXEL_ENCODING_RGB:
case PIXEL_ENCODING_YCBCR444:
case PIXEL_ENCODING_YCBCR422:
policy->min_target_bpp = 8;
policy->max_target_bpp = 3 * bpc;
policy->ycbcr422_simple = true;
if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR422 && link_encoding == DC_LINK_ENCODING_HDMI_FRL) {
policy->min_target_bpp = 7;
policy->max_target_bpp = 2 * bpc;
policy->ycbcr422_simple = false;
}
break;
case PIXEL_ENCODING_YCBCR420:
policy->min_target_bpp = 6;
policy->max_target_bpp = bpc * 3 / 2;
break;
default:
return;
}
if (policy->max_target_bpp > dsc_policy_max_target_bpp_limit)
policy->max_target_bpp = dsc_policy_max_target_bpp_limit;
if (max_target_bpp_limit_override_x16 && policy->max_target_bpp > max_target_bpp_limit_override_x16 / 16)
policy->max_target_bpp = max_target_bpp_limit_override_x16 / 16;
policy->enable_dsc_when_not_needed = dsc_policy_enable_dsc_when_not_needed;
}
void dc_dsc_policy_set_max_target_bpp_limit(uint32_t limit)
{
dsc_policy_max_target_bpp_limit = limit;
}
void dc_dsc_policy_set_enable_dsc_when_not_needed(bool enable)
{
dsc_policy_enable_dsc_when_not_needed = enable;
}
void dc_dsc_policy_set_disable_dsc_stream_overhead(bool disable)
{
dsc_policy_disable_dsc_stream_overhead = disable;
}
void dc_set_disable_128b_132b_stream_overhead(bool disable)
{
disable_128b_132b_stream_overhead = disable;
}
void dc_dsc_get_default_config_option(const struct dc *dc, struct dc_dsc_config_options *options)
{
options->dsc_min_slice_height_override = dc->debug.dsc_min_slice_height_override;
options->dsc_force_odm_hslice_override = dc->debug.force_odm_combine;
options->max_target_bpp_limit_override_x16 = 0;
options->slice_height_granularity = 1;
options->force_dsc_when_not_needed = false;
}