/* SPDX-License-Identifier: MIT1* Copyright (C) 2018 Intel Corp.2*3* Authors:4* Manasi Navare <[email protected]>5*/67#ifndef DRM_DSC_H_8#define DRM_DSC_H_910#include <drm/display/drm_dp.h>1112/* VESA Display Stream Compression DSC 1.2 constants */13#define DSC_NUM_BUF_RANGES 1514#define DSC_MUX_WORD_SIZE_8_10_BPC 4815#define DSC_MUX_WORD_SIZE_12_BPC 6416#define DSC_RC_PIXELS_PER_GROUP 317#define DSC_SCALE_DECREMENT_INTERVAL_MAX 409518#define DSC_RANGE_BPG_OFFSET_MASK 0x3f1920/* DSC Rate Control Constants */21#define DSC_RC_MODEL_SIZE_CONST 819222#define DSC_RC_EDGE_FACTOR_CONST 623#define DSC_RC_TGT_OFFSET_HI_CONST 324#define DSC_RC_TGT_OFFSET_LO_CONST 32526/* DSC PPS constants and macros */27#define DSC_PPS_VERSION_MAJOR_SHIFT 428#define DSC_PPS_BPC_SHIFT 429#define DSC_PPS_MSB_SHIFT 830#define DSC_PPS_LSB_MASK (0xFF << 0)31#define DSC_PPS_BPP_HIGH_MASK (0x3 << 8)32#define DSC_PPS_VBR_EN_SHIFT 233#define DSC_PPS_SIMPLE422_SHIFT 334#define DSC_PPS_CONVERT_RGB_SHIFT 435#define DSC_PPS_BLOCK_PRED_EN_SHIFT 536#define DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK (0x3 << 8)37#define DSC_PPS_SCALE_DEC_INT_HIGH_MASK (0xF << 8)38#define DSC_PPS_RC_TGT_OFFSET_HI_SHIFT 439#define DSC_PPS_RC_RANGE_MINQP_SHIFT 1140#define DSC_PPS_RC_RANGE_MAXQP_SHIFT 641#define DSC_PPS_NATIVE_420_SHIFT 14243/**44* struct drm_dsc_rc_range_parameters - DSC Rate Control range parameters45*46* This defines different rate control parameters used by the DSC engine47* to compress the frame.48*/49struct drm_dsc_rc_range_parameters {50/**51* @range_min_qp: Min Quantization Parameters allowed for this range52*/53u8 range_min_qp;54/**55* @range_max_qp: Max Quantization Parameters allowed for this range56*/57u8 range_max_qp;58/**59* @range_bpg_offset:60* Bits/group offset to apply to target for this group61*/62u8 range_bpg_offset;63};6465/**66* struct drm_dsc_config - Parameters required to configure DSC67*68* Driver populates this structure with all the parameters required69* to configure the display stream compression on the source.70*/71struct drm_dsc_config {72/**73* @line_buf_depth:74* Bits per component for previous reconstructed line buffer75*/76u8 line_buf_depth;77/**78* @bits_per_component: Bits per component to code (8/10/12)79*/80u8 bits_per_component;81/**82* @convert_rgb:83* Flag to indicate if RGB - YCoCg conversion is needed84* True if RGB input, False if YCoCg input85*/86bool convert_rgb;87/**88* @slice_count: Number fo slices per line used by the DSC encoder89*/90u8 slice_count;91/**92* @slice_width: Width of each slice in pixels93*/94u16 slice_width;95/**96* @slice_height: Slice height in pixels97*/98u16 slice_height;99/**100* @simple_422: True if simple 4_2_2 mode is enabled else False101*/102bool simple_422;103/**104* @pic_width: Width of the input display frame in pixels105*/106u16 pic_width;107/**108* @pic_height: Vertical height of the input display frame109*/110u16 pic_height;111/**112* @rc_tgt_offset_high:113* Offset to bits/group used by RC to determine QP adjustment114*/115u8 rc_tgt_offset_high;116/**117* @rc_tgt_offset_low:118* Offset to bits/group used by RC to determine QP adjustment119*/120u8 rc_tgt_offset_low;121/**122* @bits_per_pixel:123* Target bits per pixel with 4 fractional bits, bits_per_pixel << 4124*/125u16 bits_per_pixel;126/**127* @rc_edge_factor:128* Factor to determine if an edge is present based on the bits produced129*/130u8 rc_edge_factor;131/**132* @rc_quant_incr_limit1:133* Slow down incrementing once the range reaches this value134*/135u8 rc_quant_incr_limit1;136/**137* @rc_quant_incr_limit0:138* Slow down incrementing once the range reaches this value139*/140u8 rc_quant_incr_limit0;141/**142* @initial_xmit_delay:143* Number of pixels to delay the initial transmission144*/145u16 initial_xmit_delay;146/**147* @initial_dec_delay:148* Initial decoder delay, number of pixel times that the decoder149* accumulates data in its rate buffer before starting to decode150* and output pixels.151*/152u16 initial_dec_delay;153/**154* @block_pred_enable:155* True if block prediction is used to code any groups within the156* picture. False if BP not used157*/158bool block_pred_enable;159/**160* @first_line_bpg_offset:161* Number of additional bits allocated for each group on the first162* line of slice.163*/164u8 first_line_bpg_offset;165/**166* @initial_offset: Value to use for RC model offset at slice start167*/168u16 initial_offset;169/**170* @rc_buf_thresh: Thresholds defining each of the buffer ranges171*/172u16 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];173/**174* @rc_range_params:175* Parameters for each of the RC ranges defined in176* &struct drm_dsc_rc_range_parameters177*/178struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];179/**180* @rc_model_size: Total size of RC model181*/182u16 rc_model_size;183/**184* @flatness_min_qp: Minimum QP where flatness information is sent185*/186u8 flatness_min_qp;187/**188* @flatness_max_qp: Maximum QP where flatness information is sent189*/190u8 flatness_max_qp;191/**192* @initial_scale_value: Initial value for the scale factor193*/194u8 initial_scale_value;195/**196* @scale_decrement_interval:197* Specifies number of group times between decrementing the scale factor198* at beginning of a slice.199*/200u16 scale_decrement_interval;201/**202* @scale_increment_interval:203* Number of group times between incrementing the scale factor value204* used at the beginning of a slice.205*/206u16 scale_increment_interval;207/**208* @nfl_bpg_offset: Non first line BPG offset to be used209*/210u16 nfl_bpg_offset;211/**212* @slice_bpg_offset: BPG offset used to enforce slice bit213*/214u16 slice_bpg_offset;215/**216* @final_offset: Final RC linear transformation offset value217*/218u16 final_offset;219/**220* @vbr_enable: True if VBR mode is enabled, false if disabled221*/222bool vbr_enable;223/**224* @mux_word_size: Mux word size (in bits) for SSM mode225*/226u8 mux_word_size;227/**228* @slice_chunk_size:229* The (max) size in bytes of the "chunks" that are used in slice230* multiplexing.231*/232u16 slice_chunk_size;233/**234* @rc_bits: Rate control buffer size in bits235*/236u16 rc_bits;237/**238* @dsc_version_minor: DSC minor version239*/240u8 dsc_version_minor;241/**242* @dsc_version_major: DSC major version243*/244u8 dsc_version_major;245/**246* @native_422: True if Native 4:2:2 supported, else false247*/248bool native_422;249/**250* @native_420: True if Native 4:2:0 supported else false.251*/252bool native_420;253/**254* @second_line_bpg_offset:255* Additional bits/grp for seconnd line of slice for native 4:2:0256*/257u8 second_line_bpg_offset;258/**259* @nsl_bpg_offset:260* Num of bits deallocated for each grp that is not in second line of261* slice262*/263u16 nsl_bpg_offset;264/**265* @second_line_offset_adj:266* Offset adjustment for second line in Native 4:2:0 mode267*/268u16 second_line_offset_adj;269};270271/**272* struct drm_dsc_picture_parameter_set - Represents 128 bytes of273* Picture Parameter Set274*275* The VESA DSC standard defines picture parameter set (PPS) which display276* stream compression encoders must communicate to decoders.277* The PPS is encapsulated in 128 bytes (PPS 0 through PPS 127). The fields in278* this structure are as per Table 4.1 in Vesa DSC specification v1.1/v1.2.279* The PPS fields that span over more than a byte should be stored in Big Endian280* format.281*/282struct drm_dsc_picture_parameter_set {283/**284* @dsc_version:285* PPS0[3:0] - dsc_version_minor: Contains Minor version of DSC286* PPS0[7:4] - dsc_version_major: Contains major version of DSC287*/288u8 dsc_version;289/**290* @pps_identifier:291* PPS1[7:0] - Application specific identifier that can be292* used to differentiate between different PPS tables.293*/294u8 pps_identifier;295/**296* @pps_reserved:297* PPS2[7:0]- RESERVED Byte298*/299u8 pps_reserved;300/**301* @pps_3:302* PPS3[3:0] - linebuf_depth: Contains linebuffer bit depth used to303* generate the bitstream. (0x0 - 16 bits for DSC 1.2, 0x8 - 8 bits,304* 0xA - 10 bits, 0xB - 11 bits, 0xC - 12 bits, 0xD - 13 bits,305* 0xE - 14 bits for DSC1.2, 0xF - 14 bits for DSC 1.2.306* PPS3[7:4] - bits_per_component: Bits per component for the original307* pixels of the encoded picture.308* 0x0 = 16bpc (allowed only when dsc_version_minor = 0x2)309* 0x8 = 8bpc, 0xA = 10bpc, 0xC = 12bpc, 0xE = 14bpc (also310* allowed only when dsc_minor_version = 0x2)311*/312u8 pps_3;313/**314* @pps_4:315* PPS4[1:0] -These are the most significant 2 bits of316* compressed BPP bits_per_pixel[9:0] syntax element.317* PPS4[2] - vbr_enable: 0 = VBR disabled, 1 = VBR enabled318* PPS4[3] - simple_422: Indicates if decoder drops samples to319* reconstruct the 4:2:2 picture.320* PPS4[4] - Convert_rgb: Indicates if DSC color space conversion is321* active.322* PPS4[5] - blobk_pred_enable: Indicates if BP is used to code any323* groups in picture324* PPS4[7:6] - Reseved bits325*/326u8 pps_4;327/**328* @bits_per_pixel_low:329* PPS5[7:0] - This indicates the lower significant 8 bits of330* the compressed BPP bits_per_pixel[9:0] element.331*/332u8 bits_per_pixel_low;333/**334* @pic_height:335* PPS6[7:0], PPS7[7:0] -pic_height: Specifies the number of pixel rows336* within the raster.337*/338__be16 pic_height;339/**340* @pic_width:341* PPS8[7:0], PPS9[7:0] - pic_width: Number of pixel columns within342* the raster.343*/344__be16 pic_width;345/**346* @slice_height:347* PPS10[7:0], PPS11[7:0] - Slice height in units of pixels.348*/349__be16 slice_height;350/**351* @slice_width:352* PPS12[7:0], PPS13[7:0] - Slice width in terms of pixels.353*/354__be16 slice_width;355/**356* @chunk_size:357* PPS14[7:0], PPS15[7:0] - Size in units of bytes of the chunks358* that are used for slice multiplexing.359*/360__be16 chunk_size;361/**362* @initial_xmit_delay_high:363* PPS16[1:0] - Most Significant two bits of initial transmission delay.364* It specifies the number of pixel times that the encoder waits before365* transmitting data from its rate buffer.366* PPS16[7:2] - Reserved367*/368u8 initial_xmit_delay_high;369/**370* @initial_xmit_delay_low:371* PPS17[7:0] - Least significant 8 bits of initial transmission delay.372*/373u8 initial_xmit_delay_low;374/**375* @initial_dec_delay:376*377* PPS18[7:0], PPS19[7:0] - Initial decoding delay which is the number378* of pixel times that the decoder accumulates data in its rate buffer379* before starting to decode and output pixels.380*/381__be16 initial_dec_delay;382/**383* @pps20_reserved:384*385* PPS20[7:0] - Reserved386*/387u8 pps20_reserved;388/**389* @initial_scale_value:390* PPS21[5:0] - Initial rcXformScale factor used at beginning391* of a slice.392* PPS21[7:6] - Reserved393*/394u8 initial_scale_value;395/**396* @scale_increment_interval:397* PPS22[7:0], PPS23[7:0] - Number of group times between incrementing398* the rcXformScale factor at end of a slice.399*/400__be16 scale_increment_interval;401/**402* @scale_decrement_interval_high:403* PPS24[3:0] - Higher 4 bits indicating number of group times between404* decrementing the rcXformScale factor at beginning of a slice.405* PPS24[7:4] - Reserved406*/407u8 scale_decrement_interval_high;408/**409* @scale_decrement_interval_low:410* PPS25[7:0] - Lower 8 bits of scale decrement interval411*/412u8 scale_decrement_interval_low;413/**414* @pps26_reserved:415* PPS26[7:0]416*/417u8 pps26_reserved;418/**419* @first_line_bpg_offset:420* PPS27[4:0] - Number of additional bits that are allocated421* for each group on first line of a slice.422* PPS27[7:5] - Reserved423*/424u8 first_line_bpg_offset;425/**426* @nfl_bpg_offset:427* PPS28[7:0], PPS29[7:0] - Number of bits including frac bits428* deallocated for each group for groups after the first line of slice.429*/430__be16 nfl_bpg_offset;431/**432* @slice_bpg_offset:433* PPS30, PPS31[7:0] - Number of bits that are deallocated for each434* group to enforce the slice constraint.435*/436__be16 slice_bpg_offset;437/**438* @initial_offset:439* PPS32,33[7:0] - Initial value for rcXformOffset440*/441__be16 initial_offset;442/**443* @final_offset:444* PPS34,35[7:0] - Maximum end-of-slice value for rcXformOffset445*/446__be16 final_offset;447/**448* @flatness_min_qp:449* PPS36[4:0] - Minimum QP at which flatness is signaled and450* flatness QP adjustment is made.451* PPS36[7:5] - Reserved452*/453u8 flatness_min_qp;454/**455* @flatness_max_qp:456* PPS37[4:0] - Max QP at which flatness is signalled and457* the flatness adjustment is made.458* PPS37[7:5] - Reserved459*/460u8 flatness_max_qp;461/**462* @rc_model_size:463* PPS38,39[7:0] - Number of bits within RC Model.464*/465__be16 rc_model_size;466/**467* @rc_edge_factor:468* PPS40[3:0] - Ratio of current activity vs, previous469* activity to determine presence of edge.470* PPS40[7:4] - Reserved471*/472u8 rc_edge_factor;473/**474* @rc_quant_incr_limit0:475* PPS41[4:0] - QP threshold used in short term RC476* PPS41[7:5] - Reserved477*/478u8 rc_quant_incr_limit0;479/**480* @rc_quant_incr_limit1:481* PPS42[4:0] - QP threshold used in short term RC482* PPS42[7:5] - Reserved483*/484u8 rc_quant_incr_limit1;485/**486* @rc_tgt_offset:487* PPS43[3:0] - Lower end of the variability range around the target488* bits per group that is allowed by short term RC.489* PPS43[7:4]- Upper end of the variability range around the target490* bits per group that i allowed by short term rc.491*/492u8 rc_tgt_offset;493/**494* @rc_buf_thresh:495* PPS44[7:0] - PPS57[7:0] - Specifies the thresholds in RC model for496* the 15 ranges defined by 14 thresholds.497*/498u8 rc_buf_thresh[DSC_NUM_BUF_RANGES - 1];499/**500* @rc_range_parameters:501* PPS58[7:0] - PPS87[7:0]502* Parameters that correspond to each of the 15 ranges.503*/504__be16 rc_range_parameters[DSC_NUM_BUF_RANGES];505/**506* @native_422_420:507* PPS88[0] - 0 = Native 4:2:2 not used508* 1 = Native 4:2:2 used509* PPS88[1] - 0 = Native 4:2:0 not use510* 1 = Native 4:2:0 used511* PPS88[7:2] - Reserved 6 bits512*/513u8 native_422_420;514/**515* @second_line_bpg_offset:516* PPS89[4:0] - Additional bits/group budget for the517* second line of a slice in Native 4:2:0 mode.518* Set to 0 if DSC minor version is 1 or native420 is 0.519* PPS89[7:5] - Reserved520*/521u8 second_line_bpg_offset;522/**523* @nsl_bpg_offset:524* PPS90[7:0], PPS91[7:0] - Number of bits that are deallocated525* for each group that is not in the second line of a slice.526*/527__be16 nsl_bpg_offset;528/**529* @second_line_offset_adj:530* PPS92[7:0], PPS93[7:0] - Used as offset adjustment for the second531* line in Native 4:2:0 mode.532*/533__be16 second_line_offset_adj;534/**535* @pps_long_94_reserved:536* PPS 94, 95, 96, 97 - Reserved537*/538u32 pps_long_94_reserved;539/**540* @pps_long_98_reserved:541* PPS 98, 99, 100, 101 - Reserved542*/543u32 pps_long_98_reserved;544/**545* @pps_long_102_reserved:546* PPS 102, 103, 104, 105 - Reserved547*/548u32 pps_long_102_reserved;549/**550* @pps_long_106_reserved:551* PPS 106, 107, 108, 109 - reserved552*/553u32 pps_long_106_reserved;554/**555* @pps_long_110_reserved:556* PPS 110, 111, 112, 113 - reserved557*/558u32 pps_long_110_reserved;559/**560* @pps_long_114_reserved:561* PPS 114 - 117 - reserved562*/563u32 pps_long_114_reserved;564/**565* @pps_long_118_reserved:566* PPS 118 - 121 - reserved567*/568u32 pps_long_118_reserved;569/**570* @pps_long_122_reserved:571* PPS 122- 125 - reserved572*/573u32 pps_long_122_reserved;574/**575* @pps_short_126_reserved:576* PPS 126, 127 - reserved577*/578__be16 pps_short_126_reserved;579} __packed;580581/**582* struct drm_dsc_pps_infoframe - DSC infoframe carrying the Picture Parameter583* Set Metadata584*585* This structure represents the DSC PPS infoframe required to send the Picture586* Parameter Set metadata required before enabling VESA Display Stream587* Compression. This is based on the DP Secondary Data Packet structure and588* comprises of SDP Header as defined &struct dp_sdp_header in drm_dp_helper.h589* and PPS payload defined in &struct drm_dsc_picture_parameter_set.590*591* @pps_header: Header for PPS as per DP SDP header format of type592* &struct dp_sdp_header593* @pps_payload: PPS payload fields as per DSC specification Table 4-1594* as represented in &struct drm_dsc_picture_parameter_set595*/596struct drm_dsc_pps_infoframe {597struct dp_sdp_header pps_header;598struct drm_dsc_picture_parameter_set pps_payload;599} __packed;600601#endif /* _DRM_DSC_H_ */602603604