// SPDX-License-Identifier: MIT /* * Copyright © 2018 Intel Corp * * Author: * Manasi Navare <[email protected]> */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/byteorder/generic.h> #include <drm/display/drm_dp_helper.h> #include <drm/display/drm_dsc_helper.h> #include <drm/drm_fixed.h> #include <drm/drm_print.h> /** * DOC: dsc helpers * * VESA specification for DP 1.4 adds a new feature called Display Stream * Compression (DSC) used to compress the pixel bits before sending it on * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing * display interfaces can support high resolutions at higher frames rates uisng * the maximum available link capacity of these interfaces. * * These functions contain some common logic and helpers to deal with VESA * Display Stream Compression standard required for DSC on Display Port/eDP or * MIPI display interfaces. */ /** * drm_dsc_dp_pps_header_init() - Initializes the PPS Header * for DisplayPort as per the DP 1.4 spec. * @pps_header: Secondary data packet header for DSC Picture * Parameter Set as defined in &struct dp_sdp_header * * DP 1.4 spec defines the secondary data packet for sending the * picture parameter infoframes from the source to the sink. * This function populates the SDP header defined in * &struct dp_sdp_header. */ void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header) { … } EXPORT_SYMBOL(…); /** * drm_dsc_dp_rc_buffer_size - get rc buffer size in bytes * @rc_buffer_block_size: block size code, according to DPCD offset 62h * @rc_buffer_size: number of blocks - 1, according to DPCD offset 63h * * return: * buffer size in bytes, or 0 on invalid input */ int drm_dsc_dp_rc_buffer_size(u8 rc_buffer_block_size, u8 rc_buffer_size) { … } EXPORT_SYMBOL(…); /** * drm_dsc_pps_payload_pack() - Populates the DSC PPS * * @pps_payload: * Bitwise struct for DSC Picture Parameter Set. This is defined * by &struct drm_dsc_picture_parameter_set * @dsc_cfg: * DSC Configuration data filled by driver as defined by * &struct drm_dsc_config * * DSC source device sends a picture parameter set (PPS) containing the * information required by the sink to decode the compressed frame. Driver * populates the DSC PPS struct using the DSC configuration parameters in * the order expected by the DSC Display Sink device. For the DSC, the sink * device expects the PPS payload in big endian format for fields * that span more than 1 byte. */ void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload, const struct drm_dsc_config *dsc_cfg) { … } EXPORT_SYMBOL(…); /** * drm_dsc_set_const_params() - Set DSC parameters considered typically * constant across operation modes * * @vdsc_cfg: * DSC Configuration data partially filled by driver */ void drm_dsc_set_const_params(struct drm_dsc_config *vdsc_cfg) { … } EXPORT_SYMBOL(…); /* From DSC_v1.11 spec, rc_parameter_Set syntax element typically constant */ static const u16 drm_dsc_rc_buf_thresh[] = …; /** * drm_dsc_set_rc_buf_thresh() - Set thresholds for the RC model * in accordance with the DSC 1.2 specification. * * @vdsc_cfg: DSC Configuration data partially filled by driver */ void drm_dsc_set_rc_buf_thresh(struct drm_dsc_config *vdsc_cfg) { … } EXPORT_SYMBOL(…); struct rc_parameters { … }; struct rc_parameters_data { … }; #define DSC_BPP(bpp) … /* * Rate Control Related Parameter Recommended Values from DSC_v1.1 spec prior * to DSC 1.1 fractional bpp underflow SCR (DSC_v1.1_E1.pdf) * * Cross-checked against C Model releases: DSC_model_20161212 and 20210623 */ static const struct rc_parameters_data rc_parameters_pre_scr[] = …; /* * Selected Rate Control Related Parameter Recommended Values from DSC v1.2, v1.2a, v1.2b and * DSC_v1.1_E1 specs. * * Cross-checked against C Model releases: DSC_model_20161212 and 20210623 */ static const struct rc_parameters_data rc_parameters_1_2_444[] = …; /* * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from * DSC v1.2, v1.2a, v1.2b * * Cross-checked against C Model releases: DSC_model_20161212 and 20210623 */ static const struct rc_parameters_data rc_parameters_1_2_422[] = …; /* * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from * DSC v1.2, v1.2a, v1.2b * * Cross-checked against C Model releases: DSC_model_20161212 and 20210623 */ static const struct rc_parameters_data rc_parameters_1_2_420[] = …; static const struct rc_parameters *get_rc_params(const struct rc_parameters_data *rc_parameters, u16 dsc_bpp, u8 bits_per_component) { … } /** * drm_dsc_setup_rc_params() - Set parameters and limits for RC model in * accordance with the DSC 1.1 or 1.2 specification and DSC C Model * Required bits_per_pixel and bits_per_component to be set before calling this * function. * * @vdsc_cfg: DSC Configuration data partially filled by driver * @type: operating mode and standard to follow * * Return: 0 or -error code in case of an error */ int drm_dsc_setup_rc_params(struct drm_dsc_config *vdsc_cfg, enum drm_dsc_params_type type) { … } EXPORT_SYMBOL(…); /** * drm_dsc_compute_rc_parameters() - Write rate control * parameters to the dsc configuration defined in * &struct drm_dsc_config in accordance with the DSC 1.2 * specification. Some configuration fields must be present * beforehand. * * @vdsc_cfg: * DSC Configuration data partially filled by driver */ int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg) { … } EXPORT_SYMBOL(…); /** * drm_dsc_get_bpp_int() - Get integer bits per pixel value for the given DRM DSC config * @vdsc_cfg: Pointer to DRM DSC config struct * * Return: Integer BPP value */ u32 drm_dsc_get_bpp_int(const struct drm_dsc_config *vdsc_cfg) { … } EXPORT_SYMBOL(…); /** * drm_dsc_initial_scale_value() - Calculate the initial scale value for the given DSC config * @dsc: Pointer to DRM DSC config struct * * Return: Calculated initial scale value */ u8 drm_dsc_initial_scale_value(const struct drm_dsc_config *dsc) { … } EXPORT_SYMBOL(…); /** * drm_dsc_flatness_det_thresh() - Calculate the flatness_det_thresh for the given DSC config * @dsc: Pointer to DRM DSC config struct * * Return: Calculated flatness det thresh value */ u32 drm_dsc_flatness_det_thresh(const struct drm_dsc_config *dsc) { … } EXPORT_SYMBOL(…); static void drm_dsc_dump_config_main_params(struct drm_printer *p, int indent, const struct drm_dsc_config *cfg) { … } static void drm_dsc_dump_config_rc_params(struct drm_printer *p, int indent, const struct drm_dsc_config *cfg) { … } /** * drm_dsc_dump_config - Dump the provided DSC configuration * @p: The printer used for output * @indent: Tab indentation level (max 5) * @cfg: DSC configuration to print * * Print the provided DSC configuration in @cfg. */ void drm_dsc_dump_config(struct drm_printer *p, int indent, const struct drm_dsc_config *cfg) { … } EXPORT_SYMBOL(…);