* [PATCH v4 0/6] Introduce MSM-specific DSC helpers
@ 2023-04-05 0:41 Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods Jessica Zhang
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
There are some overlap in calculations for MSM-specific DSC variables
between DP and DSI. In addition, the calculations for initial_scale_value
and det_thresh_flatness that are defined within the DSC 1.2 specifications,
but aren't yet included in drm_dsc_helper.c.
This series moves these calculations to a shared msm_dsc_helper.c file and
defines drm_dsc_helper methods for initial_scale_value and
det_thresh_flatness.
Note: For now, the MSM specific helper methods are only called for the DSI
path, but will called for DP once DSC 1.2 support for DP has been added.
Depends on: "drm/i915: move DSC RC tables to drm_dsc_helper.c" [1]
[1] https://patchwork.freedesktop.org/series/114472/
---
Changes in v4:
- Changed msm_dsc_get_uncompressed_pclk_per_intf to msm_dsc_get_pclk_per_intf
- Moved pclk_per_intf calculation for dsi_timing_setup to `if
(msm_host->dsc)` block
- Link to v3: https://lore.kernel.org/r/20230329-rfc-msm-dsc-helper-v3-0-6bec0d277a83@quicinc.com
Changes in v3:
- Cleaned up unused parameters
- Reworded some calculations for clarity
- Changed get_bytes_per_soft_slice() to a public method
- Added comment documentation to MSM DSC helpers
- Changed msm_dsc_get_eol_byte_num() to *_get_bytes_per_intf()
- Split dsi_timing_setup() hdisplay calculation to a separate patch
- Dropped 78c8b81d57d8 ("drm/display/dsc: Add flatness and initial scale
value calculations") patch as it was absorbed in Dmitry's DSC series [1]
- Link to v2: https://lore.kernel.org/r/20230329-rfc-msm-dsc-helper-v2-0-3c13ced536b2@quicinc.com
Changes in v2:
- Changed det_thresh_flatness to flatness_det_thresh
- Moved msm_dsc_helper files to msm/ directory
- Fixed type mismatch issues in MSM DSC helpers
- Dropped MSM_DSC_SLICE_PER_PKT macro
- Removed get_comp_ratio() helper
- Style changes to improve readability
- Use drm_dsc_get_bpp_int() instead of DSC_BPP macro
- Picked up Fixes tags for patches 3/5 and 4/5
- Picked up Reviewed-by for patch 4/5
- Split eol_byte_num and pkt_per_line calculation into a separate patch
- Moved pclk_per_line calculation into `if (dsc)` block in
dsi_timing_setup()
- Link to v1: https://lore.kernel.org/r/20230329-rfc-msm-dsc-helper-v1-0-f3e479f59b6d@quicinc.com
---
Jessica Zhang (6):
drm/msm: Add MSM-specific DSC helper methods
drm/msm/dpu: Use DRM DSC helper for det_thresh_flatness
drm/msm/dpu: Fix slice_last_group_size calculation
drm/msm/dsi: Use MSM and DRM DSC helper methods
drm/msm/dsi: update hdisplay calculation for dsi_timing_setup
drm/msm/dsi: Fix calculations pkt_per_line
drivers/gpu/drm/msm/Makefile | 1 +
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c | 9 ++--
drivers/gpu/drm/msm/dsi/dsi_host.c | 21 ++++++---
drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++
drivers/gpu/drm/msm/msm_dsc_helper.h | 70 ++++++++++++++++++++++++++++++
5 files changed, 140 insertions(+), 8 deletions(-)
---
base-commit: 56777fc93a145afcf71b92ba4281250f59ba6d9b
change-id: 20230329-rfc-msm-dsc-helper-981a95edfbd0
Best regards,
--
Jessica Zhang <quic_jesszhan@quicinc.com>
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 2/6] drm/msm/dpu: Use DRM DSC helper for det_thresh_flatness Jessica Zhang
` (4 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
Introduce MSM-specific DSC helper methods, as some calculations are
common between DP and DSC.
Changes in v2:
- Moved files up to msm/ directory
- Dropped get_comp_ratio() helper
- Used drm_int2fixp() to convert to integers to fp
- Style changes to improve readability
- Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
- Changed msm_dsc_get_slice_per_intf() to a static inline method
- Dropped last division step of msm_dsc_get_pclk_per_line() and changed
method name accordingly
- Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
- Fixed some math issues caused by passing in incorrect types to
drm_fixed methods in get_bytes_per_soft_slice()
Changes in v3:
- Dropped src_bpp parameter from all methods -- src_bpp can be
calculated as dsc->bits_per_component * 3
- Dropped intf_width parameter from get_bytes_per_soft_slice()
- Moved dsc->bits_per_component to numerator calculation in
get_bytes_per_soft_slice()
- Renamed msm_dsc_get_uncompressed_pclk_per_line to
*_get_uncompressed_pclk_per_intf()
- Removed dsc->slice_width check from
msm_dsc_get_uncompressed_pclk_per_intf()
- Made get_bytes_per_soft_slice() a public method (this will be called
later to help calculate DP pclk params)
- Added documentation in comments
- Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
Changes in v4:
- Changed msm_dsc_get_uncompressed_pclk_per_intf to
msm_dsc_get_pclk_per_intf
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
---
drivers/gpu/drm/msm/Makefile | 1 +
drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
drivers/gpu/drm/msm/msm_dsc_helper.h | 70 ++++++++++++++++++++++++++++++++++++
3 files changed, 118 insertions(+)
diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
index 7274c41228ed..b814fc80e2d5 100644
--- a/drivers/gpu/drm/msm/Makefile
+++ b/drivers/gpu/drm/msm/Makefile
@@ -94,6 +94,7 @@ msm-y += \
msm_atomic_tracepoints.o \
msm_debugfs.o \
msm_drv.o \
+ msm_dsc_helper.o \
msm_fb.o \
msm_fence.o \
msm_gem.o \
diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c b/drivers/gpu/drm/msm/msm_dsc_helper.c
new file mode 100644
index 000000000000..0539221eb09d
--- /dev/null
+++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <drm/drm_fixed.h>
+
+#include "msm_drv.h"
+#include "msm_dsc_helper.h"
+
+s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
+{
+ int bpp = msm_dsc_get_bpp_int(dsc);
+ s64 numerator_fp, denominator_fp;
+ s64 comp_ratio_fp = drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
+
+ numerator_fp = drm_int2fixp(dsc->slice_width * 3 * dsc->bits_per_component);
+ denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
+
+ return drm_fixp_div(numerator_fp, denominator_fp);
+}
+
+u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int intf_width)
+{
+ u32 bytes_per_soft_slice, bytes_per_intf;
+ s64 bytes_per_soft_slice_fp;
+ int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
+
+ bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
+ bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
+
+ bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
+
+ return bytes_per_intf;
+}
+
+int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
+{
+ s64 data_width;
+
+ data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
+ get_bytes_per_soft_slice(dsc));
+
+ return drm_fixp2int_ceil(data_width);
+}
diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h b/drivers/gpu/drm/msm/msm_dsc_helper.h
new file mode 100644
index 000000000000..31116a31090f
--- /dev/null
+++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
+ */
+
+#ifndef MSM_DSC_HELPER_H_
+#define MSM_DSC_HELPER_H_
+
+#include <drm/display/drm_dsc_helper.h>
+#include <drm/drm_modes.h>
+
+/*
+ * Helper methods for MSM specific DSC calculations that are common between timing engine,
+ * DSI, and DP.
+ */
+
+/**
+ * msm_dsc_get_bpp_int - get bits per pixel integer value
+ * @dsc: Pointer to drm dsc config struct
+ */
+static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
+{
+ WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
+ return dsc->bits_per_pixel >> 4;
+}
+
+/**
+ * msm_dsc_get_slice_per_intf - get number of slices per interface
+ * @dsc: Pointer to drm dsc config struct
+ * @intf_width: interface width
+ */
+static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config *dsc, int intf_width)
+{
+ return DIV_ROUND_UP(intf_width, dsc->slice_width);
+}
+
+/**
+ * msm_dsc_get_dce_bytes_per_line - get bytes per line to help calculate data width
+ * when configuring the timing engine
+ * @dsc: Pointer to drm dsc config struct
+ * @intf_width: interface width
+ */
+static inline u32 msm_dsc_get_dce_bytes_per_line(struct drm_dsc_config *dsc, int intf_width)
+{
+ return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
+}
+
+/**
+ * get_bytes_per_soft_slice - get size of each soft slice for dsc
+ * @dsc: Pointer to drm dsc config struct
+ */
+s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
+
+/**
+ * msm_dsc_get_bytes_per_intf - get total bytes per interface
+ * @dsc: Pointer to drm dsc config struct
+ * @intf_width: interface width
+ */
+u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int intf_width);
+
+/**
+ * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
+ * @dsc: Pointer to drm dsc config struct
+ *
+ * Note: This value will then be passed along to DSI and DP for some more
+ * calculations. This is because DSI and DP divide the pclk_per_intf value
+ * by different values depending on if widebus is enabled.
+ */
+int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
+#endif /* MSM_DSC_HELPER_H_ */
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 2/6] drm/msm/dpu: Use DRM DSC helper for det_thresh_flatness
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation Jessica Zhang
` (3 subsequent siblings)
5 siblings, 0 replies; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
Use the DRM DSC helper for det_thresh_flatness to match downstream
implementation and the DSC spec.
Changes in V2:
- Added a Fixes tag
Fixes: c110cfd1753e ("drm/msm/disp/dpu1: Add support for DSC")
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
index 619926da1441..b952f7d2b7f5 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
@@ -3,6 +3,8 @@
* Copyright (c) 2020-2022, Linaro Limited
*/
+#include <drm/display/drm_dsc_helper.h>
+
#include "dpu_kms.h"
#include "dpu_hw_catalog.h"
#include "dpu_hwio.h"
@@ -102,7 +104,7 @@ static void dpu_hw_dsc_config(struct dpu_hw_dsc *hw_dsc,
data |= dsc->final_offset;
DPU_REG_WRITE(c, DSC_DSC_OFFSET, data);
- det_thresh_flatness = 7 + 2 * (dsc->bits_per_component - 8);
+ det_thresh_flatness = drm_dsc_calculate_flatness_det_thresh(dsc);
data = det_thresh_flatness << 10;
data |= dsc->flatness_max_qp << 5;
data |= dsc->flatness_min_qp;
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 2/6] drm/msm/dpu: Use DRM DSC helper for det_thresh_flatness Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods Jessica Zhang
` (2 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
Correct the math for slice_last_group_size so that it matches the
calculations downstream.
Changes in v3:
- Reworded slice_last_group_size calculation to
`(dsc->slice_width + 2) % 3`
Fixes: c110cfd1753e ("drm/msm/disp/dpu1: Add support for DSC")
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
---
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
index b952f7d2b7f5..ff1c8f92fb20 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
@@ -56,9 +56,10 @@ static void dpu_hw_dsc_config(struct dpu_hw_dsc *hw_dsc,
if (is_cmd_mode)
initial_lines += 1;
- slice_last_group_size = 3 - (dsc->slice_width % 3);
+ slice_last_group_size = (dsc->slice_width + 2) % 3;
+
data = (initial_lines << 20);
- data |= ((slice_last_group_size - 1) << 18);
+ data |= (slice_last_group_size << 18);
/* bpp is 6.4 format, 4 LSBs bits are for fractional part */
data |= (dsc->bits_per_pixel << 8);
data |= (dsc->block_pred_enable << 7);
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
` (2 preceding siblings ...)
2023-04-05 0:41 ` [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 19:27 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line Jessica Zhang
5 siblings, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
Use MSM and DRM DSC helper methods to configure DSC for DSI.
Changes in V2:
- *_calculate_initial_scale_value --> *_set_initial_scale_value
- Split pkt_per_line and eol_byte_num changes to a separate patch
- Moved pclk_per_line calculation to hdisplay adjustment in `if (dsc)`
block of dsi_update_dsc_timing()
Changes in v3:
- Split pclk_per_intf calculation into a separate patch
- Added slice_width check to dsi_timing_setup
- Used MSM DSC helper to calculate total_bytes_per_intf
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
---
drivers/gpu/drm/msm/dsi/dsi_host.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 74d38f90398a..6a6218a9655f 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -28,6 +28,7 @@
#include "dsi.xml.h"
#include "sfpb.xml.h"
#include "dsi_cfg.h"
+#include "msm_dsc_helper.h"
#include "msm_kms.h"
#include "msm_gem.h"
#include "phy/dsi_phy.h"
@@ -848,7 +849,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
/* first calculate dsc parameters and then program
* compress mode registers
*/
- slice_per_intf = DIV_ROUND_UP(hdisplay, dsc->slice_width);
+ slice_per_intf = msm_dsc_get_slice_per_intf(dsc, hdisplay);
/*
* If slice_count is greater than slice_per_intf
@@ -858,7 +859,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
if (dsc->slice_count > slice_per_intf)
dsc->slice_count = 1;
- total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
+ total_bytes_per_intf = msm_dsc_get_bytes_per_intf(dsc, hdisplay);
eol_byte_num = total_bytes_per_intf % 3;
pkt_per_line = slice_per_intf / dsc->slice_count;
@@ -936,6 +937,12 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
return;
}
+ if (!dsc->slice_width || (mode->hdisplay < dsc->slice_width)) {
+ pr_err("DSI: invalid slice width %d (pic_width: %d)\n",
+ dsc->slice_width, mode->hdisplay);
+ return;
+ }
+
dsc->pic_width = mode->hdisplay;
dsc->pic_height = mode->vdisplay;
DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
@@ -1759,7 +1766,7 @@ static int dsi_populate_dsc_params(struct msm_dsi_host *msm_host, struct drm_dsc
return ret;
}
- dsc->initial_scale_value = 32;
+ drm_dsc_set_initial_scale_value(dsc);
dsc->line_buf_depth = dsc->bits_per_component + 1;
return drm_dsc_compute_rc_parameters(dsc);
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
` (3 preceding siblings ...)
2023-04-05 0:41 ` [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 19:28 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line Jessica Zhang
5 siblings, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
hdisplay for compressed images should be calculated as bytes_per_slice *
slice_count. Thus, use MSM DSC helper to calculate hdisplay for
dsi_timing_setup instead of directly using mode->hdisplay.
Changes in v3:
- Split from previous patch
- Initialized hdisplay as uncompressed pclk per line at the beginning of
dsi_timing_setup as to not break dual DSI calculations
Changes in v4:
- Moved pclk_per_intf calculations to DSC hdisplay adjustments
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
---
drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 6a6218a9655f..412339cc9301 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -958,7 +958,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
* pulse width same
*/
h_total -= hdisplay;
- hdisplay /= 3;
+ hdisplay = msm_dsc_get_pclk_per_intf(msm_host->dsc) / 3;
h_total += hdisplay;
ha_end = ha_start + hdisplay;
}
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
` (4 preceding siblings ...)
2023-04-05 0:41 ` [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup Jessica Zhang
@ 2023-04-05 0:41 ` Jessica Zhang
2023-04-05 19:28 ` Dmitry Baryshkov
5 siblings, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 0:41 UTC (permalink / raw)
To: freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Dmitry Baryshkov, Sean Paul, dri-devel,
linux-arm-msm, Jessica Zhang
Currently, pkt_per_line is calculated by dividing slice_per_intf by
slice_count. This is incorrect, as slice_per_intf should be divided by
slice_per_pkt, which is not always equivalent to slice_count as it is
possible for there to be multiple soft slices per interface even though
a panel only specifies one slice per packet.
Fixes: 08802f515c3c ("drm/msm/dsi: Add support for DSC configuration")
Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/gpu/drm/msm/dsi/dsi_host.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 412339cc9301..633b60acfe18 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -862,7 +862,11 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
total_bytes_per_intf = msm_dsc_get_bytes_per_intf(dsc, hdisplay);
eol_byte_num = total_bytes_per_intf % 3;
- pkt_per_line = slice_per_intf / dsc->slice_count;
+
+ /* Default to 1 slice_per_pkt, so pkt_per_line will be equal to
+ * slice per intf.
+ */
+ pkt_per_line = slice_per_intf;
if (is_cmd_mode) /* packet data type */
reg = DSI_COMMAND_COMPRESSION_MODE_CTRL_STREAM0_DATATYPE(MIPI_DSI_DCS_LONG_WRITE);
--
2.40.0
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 0:41 ` [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods Jessica Zhang
@ 2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 22:02 ` [Freedreno] " Jessica Zhang
2023-04-05 23:34 ` Abhinav Kumar
0 siblings, 2 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 19:26 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 05/04/2023 03:41, Jessica Zhang wrote:
> Introduce MSM-specific DSC helper methods, as some calculations are
> common between DP and DSC.
>
> Changes in v2:
> - Moved files up to msm/ directory
> - Dropped get_comp_ratio() helper
> - Used drm_int2fixp() to convert to integers to fp
> - Style changes to improve readability
> - Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
> - Changed msm_dsc_get_slice_per_intf() to a static inline method
> - Dropped last division step of msm_dsc_get_pclk_per_line() and changed
> method name accordingly
> - Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
> - Fixed some math issues caused by passing in incorrect types to
> drm_fixed methods in get_bytes_per_soft_slice()
>
> Changes in v3:
> - Dropped src_bpp parameter from all methods -- src_bpp can be
> calculated as dsc->bits_per_component * 3
> - Dropped intf_width parameter from get_bytes_per_soft_slice()
> - Moved dsc->bits_per_component to numerator calculation in
> get_bytes_per_soft_slice()
> - Renamed msm_dsc_get_uncompressed_pclk_per_line to
> *_get_uncompressed_pclk_per_intf()
> - Removed dsc->slice_width check from
> msm_dsc_get_uncompressed_pclk_per_intf()
> - Made get_bytes_per_soft_slice() a public method (this will be called
> later to help calculate DP pclk params)
> - Added documentation in comments
> - Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
> renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
>
> Changes in v4:
> - Changed msm_dsc_get_uncompressed_pclk_per_intf to
> msm_dsc_get_pclk_per_intf
>
> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
> ---
> drivers/gpu/drm/msm/Makefile | 1 +
> drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
> drivers/gpu/drm/msm/msm_dsc_helper.h | 70 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 118 insertions(+)
>
> diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
> index 7274c41228ed..b814fc80e2d5 100644
> --- a/drivers/gpu/drm/msm/Makefile
> +++ b/drivers/gpu/drm/msm/Makefile
> @@ -94,6 +94,7 @@ msm-y += \
> msm_atomic_tracepoints.o \
> msm_debugfs.o \
> msm_drv.o \
> + msm_dsc_helper.o \
> msm_fb.o \
> msm_fence.o \
> msm_gem.o \
> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c b/drivers/gpu/drm/msm/msm_dsc_helper.c
> new file mode 100644
> index 000000000000..0539221eb09d
> --- /dev/null
> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
> @@ -0,0 +1,47 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <drm/drm_fixed.h>
> +
> +#include "msm_drv.h"
> +#include "msm_dsc_helper.h"
> +
> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
> +{
> + int bpp = msm_dsc_get_bpp_int(dsc);
> + s64 numerator_fp, denominator_fp;
> + s64 comp_ratio_fp = drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
> +
> + numerator_fp = drm_int2fixp(dsc->slice_width * 3 * dsc->bits_per_component);
> + denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
> +
> + return drm_fixp_div(numerator_fp, denominator_fp);
If we remove 3 * dsc->bits_per_components from both numerator and
denominator, this whole function seems to be as simple as
DIV_ROUND_UP(dsc->slice_width * bpp, 8)
Or, if you prefer FP math, drm_fixp_from_fraction(dsc->slice_width *
bpp, 8).
> +}
> +
> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int intf_width)
> +{
> + u32 bytes_per_soft_slice, bytes_per_intf;
> + s64 bytes_per_soft_slice_fp;
> + int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
> +
> + bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
> + bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
> +
> + bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
> +
> + return bytes_per_intf;
> +}
> +
> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
> +{
> + s64 data_width;
> +
> + data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
> + get_bytes_per_soft_slice(dsc));
And this is then DIV_ROUND_UP(dsc->slice_width * dsc->slice_count * bpp, 8)
> +
> + return drm_fixp2int_ceil(data_width);
> +}
> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h b/drivers/gpu/drm/msm/msm_dsc_helper.h
> new file mode 100644
> index 000000000000..31116a31090f
> --- /dev/null
> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
> @@ -0,0 +1,70 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
> + */
> +
> +#ifndef MSM_DSC_HELPER_H_
> +#define MSM_DSC_HELPER_H_
> +
> +#include <drm/display/drm_dsc_helper.h>
> +#include <drm/drm_modes.h>
> +
> +/*
> + * Helper methods for MSM specific DSC calculations that are common between timing engine,
> + * DSI, and DP.
> + */
> +
> +/**
> + * msm_dsc_get_bpp_int - get bits per pixel integer value
> + * @dsc: Pointer to drm dsc config struct
> + */
> +static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
> +{
> + WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
> + return dsc->bits_per_pixel >> 4;
> +}
> +
> +/**
> + * msm_dsc_get_slice_per_intf - get number of slices per interface
> + * @dsc: Pointer to drm dsc config struct
> + * @intf_width: interface width
> + */
> +static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config *dsc, int intf_width)
> +{
> + return DIV_ROUND_UP(intf_width, dsc->slice_width);
> +}
> +
> +/**
> + * msm_dsc_get_dce_bytes_per_line - get bytes per line to help calculate data width
> + * when configuring the timing engine
> + * @dsc: Pointer to drm dsc config struct
> + * @intf_width: interface width
> + */
> +static inline u32 msm_dsc_get_dce_bytes_per_line(struct drm_dsc_config *dsc, int intf_width)
> +{
> + return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
> +}
> +
> +/**
> + * get_bytes_per_soft_slice - get size of each soft slice for dsc
> + * @dsc: Pointer to drm dsc config struct
> + */
> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
> +
> +/**
> + * msm_dsc_get_bytes_per_intf - get total bytes per interface
> + * @dsc: Pointer to drm dsc config struct
> + * @intf_width: interface width
> + */
> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int intf_width);
> +
> +/**
> + * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
> + * @dsc: Pointer to drm dsc config struct
> + *
> + * Note: This value will then be passed along to DSI and DP for some more
> + * calculations. This is because DSI and DP divide the pclk_per_intf value
> + * by different values depending on if widebus is enabled.
> + */
> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
empty line, please
> +#endif /* MSM_DSC_HELPER_H_ */
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation
2023-04-05 0:41 ` [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation Jessica Zhang
@ 2023-04-05 19:26 ` Dmitry Baryshkov
0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 19:26 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 05/04/2023 03:41, Jessica Zhang wrote:
> Correct the math for slice_last_group_size so that it matches the
> calculations downstream.
>
> Changes in v3:
> - Reworded slice_last_group_size calculation to
> `(dsc->slice_width + 2) % 3`
>
> Fixes: c110cfd1753e ("drm/msm/disp/dpu1: Add support for DSC")
> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
> ---
> drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods
2023-04-05 0:41 ` [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods Jessica Zhang
@ 2023-04-05 19:27 ` Dmitry Baryshkov
2023-04-05 20:39 ` Jessica Zhang
0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 19:27 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 05/04/2023 03:41, Jessica Zhang wrote:
> Use MSM and DRM DSC helper methods to configure DSC for DSI.
>
> Changes in V2:
> - *_calculate_initial_scale_value --> *_set_initial_scale_value
> - Split pkt_per_line and eol_byte_num changes to a separate patch
> - Moved pclk_per_line calculation to hdisplay adjustment in `if (dsc)`
> block of dsi_update_dsc_timing()
>
> Changes in v3:
> - Split pclk_per_intf calculation into a separate patch
> - Added slice_width check to dsi_timing_setup
> - Used MSM DSC helper to calculate total_bytes_per_intf
>
> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
> ---
> drivers/gpu/drm/msm/dsi/dsi_host.c | 13 ++++++++++---
> 1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
> index 74d38f90398a..6a6218a9655f 100644
> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
> @@ -28,6 +28,7 @@
> #include "dsi.xml.h"
> #include "sfpb.xml.h"
> #include "dsi_cfg.h"
> +#include "msm_dsc_helper.h"
> #include "msm_kms.h"
> #include "msm_gem.h"
> #include "phy/dsi_phy.h"
> @@ -848,7 +849,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
> /* first calculate dsc parameters and then program
> * compress mode registers
> */
> - slice_per_intf = DIV_ROUND_UP(hdisplay, dsc->slice_width);
> + slice_per_intf = msm_dsc_get_slice_per_intf(dsc, hdisplay);
>
> /*
> * If slice_count is greater than slice_per_intf
> @@ -858,7 +859,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
> if (dsc->slice_count > slice_per_intf)
> dsc->slice_count = 1;
>
> - total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
> + total_bytes_per_intf = msm_dsc_get_bytes_per_intf(dsc, hdisplay);
>
> eol_byte_num = total_bytes_per_intf % 3;
> pkt_per_line = slice_per_intf / dsc->slice_count;
> @@ -936,6 +937,12 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
> return;
> }
>
> + if (!dsc->slice_width || (mode->hdisplay < dsc->slice_width)) {
> + pr_err("DSI: invalid slice width %d (pic_width: %d)\n",
> + dsc->slice_width, mode->hdisplay);
> + return;
> + }
This is not the "use of MSM and DRM DSC helper methods" and thus should
be moved to a separate patch.
> +
> dsc->pic_width = mode->hdisplay;
> dsc->pic_height = mode->vdisplay;
> DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
> @@ -1759,7 +1766,7 @@ static int dsi_populate_dsc_params(struct msm_dsi_host *msm_host, struct drm_dsc
> return ret;
> }
>
> - dsc->initial_scale_value = 32;
> + drm_dsc_set_initial_scale_value(dsc);
> dsc->line_buf_depth = dsc->bits_per_component + 1;
>
> return drm_dsc_compute_rc_parameters(dsc);
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup
2023-04-05 0:41 ` [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup Jessica Zhang
@ 2023-04-05 19:28 ` Dmitry Baryshkov
0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 19:28 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 05/04/2023 03:41, Jessica Zhang wrote:
> hdisplay for compressed images should be calculated as bytes_per_slice *
> slice_count. Thus, use MSM DSC helper to calculate hdisplay for
> dsi_timing_setup instead of directly using mode->hdisplay.
>
> Changes in v3:
> - Split from previous patch
> - Initialized hdisplay as uncompressed pclk per line at the beginning of
> dsi_timing_setup as to not break dual DSI calculations
>
> Changes in v4:
> - Moved pclk_per_intf calculations to DSC hdisplay adjustments
>
> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
> ---
> drivers/gpu/drm/msm/dsi/dsi_host.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line
2023-04-05 0:41 ` [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line Jessica Zhang
@ 2023-04-05 19:28 ` Dmitry Baryshkov
0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 19:28 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 05/04/2023 03:41, Jessica Zhang wrote:
> Currently, pkt_per_line is calculated by dividing slice_per_intf by
> slice_count. This is incorrect, as slice_per_intf should be divided by
> slice_per_pkt, which is not always equivalent to slice_count as it is
> possible for there to be multiple soft slices per interface even though
> a panel only specifies one slice per packet.
>
> Fixes: 08802f515c3c ("drm/msm/dsi: Add support for DSC configuration")
> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
> drivers/gpu/drm/msm/dsi/dsi_host.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods
2023-04-05 19:27 ` Dmitry Baryshkov
@ 2023-04-05 20:39 ` Jessica Zhang
0 siblings, 0 replies; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 20:39 UTC (permalink / raw)
To: Dmitry Baryshkov, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Abhinav Kumar, Sean Paul, dri-devel, linux-arm-msm
On 4/5/2023 12:27 PM, Dmitry Baryshkov wrote:
> On 05/04/2023 03:41, Jessica Zhang wrote:
>> Use MSM and DRM DSC helper methods to configure DSC for DSI.
>>
>> Changes in V2:
>> - *_calculate_initial_scale_value --> *_set_initial_scale_value
>> - Split pkt_per_line and eol_byte_num changes to a separate patch
>> - Moved pclk_per_line calculation to hdisplay adjustment in `if (dsc)`
>> block of dsi_update_dsc_timing()
>>
>> Changes in v3:
>> - Split pclk_per_intf calculation into a separate patch
>> - Added slice_width check to dsi_timing_setup
>> - Used MSM DSC helper to calculate total_bytes_per_intf
>>
>> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
>> ---
>> drivers/gpu/drm/msm/dsi/dsi_host.c | 13 ++++++++++---
>> 1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c
>> b/drivers/gpu/drm/msm/dsi/dsi_host.c
>> index 74d38f90398a..6a6218a9655f 100644
>> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
>> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
>> @@ -28,6 +28,7 @@
>> #include "dsi.xml.h"
>> #include "sfpb.xml.h"
>> #include "dsi_cfg.h"
>> +#include "msm_dsc_helper.h"
>> #include "msm_kms.h"
>> #include "msm_gem.h"
>> #include "phy/dsi_phy.h"
>> @@ -848,7 +849,7 @@ static void dsi_update_dsc_timing(struct
>> msm_dsi_host *msm_host, bool is_cmd_mod
>> /* first calculate dsc parameters and then program
>> * compress mode registers
>> */
>> - slice_per_intf = DIV_ROUND_UP(hdisplay, dsc->slice_width);
>> + slice_per_intf = msm_dsc_get_slice_per_intf(dsc, hdisplay);
>> /*
>> * If slice_count is greater than slice_per_intf
>> @@ -858,7 +859,7 @@ static void dsi_update_dsc_timing(struct
>> msm_dsi_host *msm_host, bool is_cmd_mod
>> if (dsc->slice_count > slice_per_intf)
>> dsc->slice_count = 1;
>> - total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
>> + total_bytes_per_intf = msm_dsc_get_bytes_per_intf(dsc, hdisplay);
>> eol_byte_num = total_bytes_per_intf % 3;
>> pkt_per_line = slice_per_intf / dsc->slice_count;
>> @@ -936,6 +937,12 @@ static void dsi_timing_setup(struct msm_dsi_host
>> *msm_host, bool is_bonded_dsi)
>> return;
>> }
>> + if (!dsc->slice_width || (mode->hdisplay < dsc->slice_width)) {
>> + pr_err("DSI: invalid slice width %d (pic_width: %d)\n",
>> + dsc->slice_width, mode->hdisplay);
>> + return;
>> + }
>
> This is not the "use of MSM and DRM DSC helper methods" and thus should
> be moved to a separate patch.
Hi Dmitry,
Acked.
Thanks,
Jessica Zhang
>
>> +
>> dsc->pic_width = mode->hdisplay;
>> dsc->pic_height = mode->vdisplay;
>> DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
>> @@ -1759,7 +1766,7 @@ static int dsi_populate_dsc_params(struct
>> msm_dsi_host *msm_host, struct drm_dsc
>> return ret;
>> }
>> - dsc->initial_scale_value = 32;
>> + drm_dsc_set_initial_scale_value(dsc);
>> dsc->line_buf_depth = dsc->bits_per_component + 1;
>> return drm_dsc_compute_rc_parameters(dsc);
>>
>
> --
> With best wishes
> Dmitry
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Freedreno] [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 19:26 ` Dmitry Baryshkov
@ 2023-04-05 22:02 ` Jessica Zhang
2023-04-05 22:03 ` Dmitry Baryshkov
2023-04-05 23:34 ` Abhinav Kumar
1 sibling, 1 reply; 17+ messages in thread
From: Jessica Zhang @ 2023-04-05 22:02 UTC (permalink / raw)
To: Dmitry Baryshkov, freedreno
Cc: linux-arm-msm, Abhinav Kumar, dri-devel, Konrad Dybcio,
Rob Clark, Daniel Vetter, Marijn Suijten, Sean Paul
On 4/5/2023 12:26 PM, Dmitry Baryshkov wrote:
> On 05/04/2023 03:41, Jessica Zhang wrote:
>> Introduce MSM-specific DSC helper methods, as some calculations are
>> common between DP and DSC.
>>
>> Changes in v2:
>> - Moved files up to msm/ directory
>> - Dropped get_comp_ratio() helper
>> - Used drm_int2fixp() to convert to integers to fp
>> - Style changes to improve readability
>> - Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
>> - Changed msm_dsc_get_slice_per_intf() to a static inline method
>> - Dropped last division step of msm_dsc_get_pclk_per_line() and changed
>> method name accordingly
>> - Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
>> - Fixed some math issues caused by passing in incorrect types to
>> drm_fixed methods in get_bytes_per_soft_slice()
>>
>> Changes in v3:
>> - Dropped src_bpp parameter from all methods -- src_bpp can be
>> calculated as dsc->bits_per_component * 3
>> - Dropped intf_width parameter from get_bytes_per_soft_slice()
>> - Moved dsc->bits_per_component to numerator calculation in
>> get_bytes_per_soft_slice()
>> - Renamed msm_dsc_get_uncompressed_pclk_per_line to
>> *_get_uncompressed_pclk_per_intf()
>> - Removed dsc->slice_width check from
>> msm_dsc_get_uncompressed_pclk_per_intf()
>> - Made get_bytes_per_soft_slice() a public method (this will be called
>> later to help calculate DP pclk params)
>> - Added documentation in comments
>> - Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
>> renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
>>
>> Changes in v4:
>> - Changed msm_dsc_get_uncompressed_pclk_per_intf to
>> msm_dsc_get_pclk_per_intf
>>
>> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
>> ---
>> drivers/gpu/drm/msm/Makefile | 1 +
>> drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
>> drivers/gpu/drm/msm/msm_dsc_helper.h | 70
>> ++++++++++++++++++++++++++++++++++++
>> 3 files changed, 118 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
>> index 7274c41228ed..b814fc80e2d5 100644
>> --- a/drivers/gpu/drm/msm/Makefile
>> +++ b/drivers/gpu/drm/msm/Makefile
>> @@ -94,6 +94,7 @@ msm-y += \
>> msm_atomic_tracepoints.o \
>> msm_debugfs.o \
>> msm_drv.o \
>> + msm_dsc_helper.o \
>> msm_fb.o \
>> msm_fence.o \
>> msm_gem.o \
>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c
>> b/drivers/gpu/drm/msm/msm_dsc_helper.c
>> new file mode 100644
>> index 000000000000..0539221eb09d
>> --- /dev/null
>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
>> @@ -0,0 +1,47 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>> reserved
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/errno.h>
>> +#include <drm/drm_fixed.h>
>> +
>> +#include "msm_drv.h"
>> +#include "msm_dsc_helper.h"
>> +
>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
>> +{
>> + int bpp = msm_dsc_get_bpp_int(dsc);
>> + s64 numerator_fp, denominator_fp;
>> + s64 comp_ratio_fp =
>> drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
>> +
>> + numerator_fp = drm_int2fixp(dsc->slice_width * 3 *
>> dsc->bits_per_component);
>> + denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
>> +
>> + return drm_fixp_div(numerator_fp, denominator_fp);
>
> If we remove 3 * dsc->bits_per_components from both numerator and
> denominator, this whole function seems to be as simple as
> DIV_ROUND_UP(dsc->slice_width * bpp, 8)
>
> Or, if you prefer FP math, drm_fixp_from_fraction(dsc->slice_width *
> bpp, 8).
Hi Dmitry,
Sounds good.
>
>> +}
>> +
>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>> intf_width)
>> +{
>> + u32 bytes_per_soft_slice, bytes_per_intf;
>> + s64 bytes_per_soft_slice_fp;
>> + int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
>> +
>> + bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
>> + bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
>> +
>> + bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
>> +
>> + return bytes_per_intf;
>> +}
>> +
>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
>> +{
>> + s64 data_width;
>> +
>> + data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
>> + get_bytes_per_soft_slice(dsc));
>
> And this is then DIV_ROUND_UP(dsc->slice_width * dsc->slice_count * bpp, 8)
I would prefer to keep the FP math/get_bytes_per_soft_slice() call here
and leave the ceil() until the end.
>
>> +
>> + return drm_fixp2int_ceil(data_width);
>> +}
>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h
>> b/drivers/gpu/drm/msm/msm_dsc_helper.h
>> new file mode 100644
>> index 000000000000..31116a31090f
>> --- /dev/null
>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
>> @@ -0,0 +1,70 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>> reserved
>> + */
>> +
>> +#ifndef MSM_DSC_HELPER_H_
>> +#define MSM_DSC_HELPER_H_
>> +
>> +#include <drm/display/drm_dsc_helper.h>
>> +#include <drm/drm_modes.h>
>> +
>> +/*
>> + * Helper methods for MSM specific DSC calculations that are common
>> between timing engine,
>> + * DSI, and DP.
>> + */
>> +
>> +/**
>> + * msm_dsc_get_bpp_int - get bits per pixel integer value
>> + * @dsc: Pointer to drm dsc config struct
>> + */
>> +static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
>> +{
>> + WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
>> + return dsc->bits_per_pixel >> 4;
>> +}
>> +
>> +/**
>> + * msm_dsc_get_slice_per_intf - get number of slices per interface
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config
>> *dsc, int intf_width)
>> +{
>> + return DIV_ROUND_UP(intf_width, dsc->slice_width);
>> +}
>> +
>> +/**
>> + * msm_dsc_get_dce_bytes_per_line - get bytes per line to help
>> calculate data width
>> + * when configuring the timing engine
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +static inline u32 msm_dsc_get_dce_bytes_per_line(struct
>> drm_dsc_config *dsc, int intf_width)
>> +{
>> + return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
>> +}
>> +
>> +/**
>> + * get_bytes_per_soft_slice - get size of each soft slice for dsc
>> + * @dsc: Pointer to drm dsc config struct
>> + */
>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
>> +
>> +/**
>> + * msm_dsc_get_bytes_per_intf - get total bytes per interface
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>> intf_width);
>> +
>> +/**
>> + * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
>> + * @dsc: Pointer to drm dsc config struct
>> + *
>> + * Note: This value will then be passed along to DSI and DP for some
>> more
>> + * calculations. This is because DSI and DP divide the pclk_per_intf
>> value
>> + * by different values depending on if widebus is enabled.
>> + */
>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
>
> empty line, please
Acked.
Thanks,
Jessica Zhang
>
>> +#endif /* MSM_DSC_HELPER_H_ */
>>
>
> --
> With best wishes
> Dmitry
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [Freedreno] [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 22:02 ` [Freedreno] " Jessica Zhang
@ 2023-04-05 22:03 ` Dmitry Baryshkov
0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 22:03 UTC (permalink / raw)
To: Jessica Zhang, freedreno
Cc: linux-arm-msm, Abhinav Kumar, dri-devel, Konrad Dybcio,
Rob Clark, Daniel Vetter, Marijn Suijten, Sean Paul
On 06/04/2023 01:02, Jessica Zhang wrote:
>
>
> On 4/5/2023 12:26 PM, Dmitry Baryshkov wrote:
>> On 05/04/2023 03:41, Jessica Zhang wrote:
>>> Introduce MSM-specific DSC helper methods, as some calculations are
>>> common between DP and DSC.
>>>
>>> Changes in v2:
>>> - Moved files up to msm/ directory
>>> - Dropped get_comp_ratio() helper
>>> - Used drm_int2fixp() to convert to integers to fp
>>> - Style changes to improve readability
>>> - Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
>>> - Changed msm_dsc_get_slice_per_intf() to a static inline method
>>> - Dropped last division step of msm_dsc_get_pclk_per_line() and changed
>>> method name accordingly
>>> - Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
>>> - Fixed some math issues caused by passing in incorrect types to
>>> drm_fixed methods in get_bytes_per_soft_slice()
>>>
>>> Changes in v3:
>>> - Dropped src_bpp parameter from all methods -- src_bpp can be
>>> calculated as dsc->bits_per_component * 3
>>> - Dropped intf_width parameter from get_bytes_per_soft_slice()
>>> - Moved dsc->bits_per_component to numerator calculation in
>>> get_bytes_per_soft_slice()
>>> - Renamed msm_dsc_get_uncompressed_pclk_per_line to
>>> *_get_uncompressed_pclk_per_intf()
>>> - Removed dsc->slice_width check from
>>> msm_dsc_get_uncompressed_pclk_per_intf()
>>> - Made get_bytes_per_soft_slice() a public method (this will be called
>>> later to help calculate DP pclk params)
>>> - Added documentation in comments
>>> - Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
>>> renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
>>>
>>> Changes in v4:
>>> - Changed msm_dsc_get_uncompressed_pclk_per_intf to
>>> msm_dsc_get_pclk_per_intf
>>>
>>> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
>>> ---
>>> drivers/gpu/drm/msm/Makefile | 1 +
>>> drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
>>> drivers/gpu/drm/msm/msm_dsc_helper.h | 70
>>> ++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 118 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
>>> index 7274c41228ed..b814fc80e2d5 100644
>>> --- a/drivers/gpu/drm/msm/Makefile
>>> +++ b/drivers/gpu/drm/msm/Makefile
>>> @@ -94,6 +94,7 @@ msm-y += \
>>> msm_atomic_tracepoints.o \
>>> msm_debugfs.o \
>>> msm_drv.o \
>>> + msm_dsc_helper.o \
>>> msm_fb.o \
>>> msm_fence.o \
>>> msm_gem.o \
>>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> b/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> new file mode 100644
>>> index 000000000000..0539221eb09d
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> @@ -0,0 +1,47 @@
>>> +// SPDX-License-Identifier: GPL-2.0-only
>>> +/*
>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>>> reserved
>>> + */
>>> +
>>> +#include <linux/kernel.h>
>>> +#include <linux/errno.h>
>>> +#include <drm/drm_fixed.h>
>>> +
>>> +#include "msm_drv.h"
>>> +#include "msm_dsc_helper.h"
>>> +
>>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
>>> +{
>>> + int bpp = msm_dsc_get_bpp_int(dsc);
>>> + s64 numerator_fp, denominator_fp;
>>> + s64 comp_ratio_fp =
>>> drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
>>> +
>>> + numerator_fp = drm_int2fixp(dsc->slice_width * 3 *
>>> dsc->bits_per_component);
>>> + denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
>>> +
>>> + return drm_fixp_div(numerator_fp, denominator_fp);
>>
>> If we remove 3 * dsc->bits_per_components from both numerator and
>> denominator, this whole function seems to be as simple as
>> DIV_ROUND_UP(dsc->slice_width * bpp, 8)
>>
>> Or, if you prefer FP math, drm_fixp_from_fraction(dsc->slice_width *
>> bpp, 8).
>
> Hi Dmitry,
>
> Sounds good.
>
>>
>>> +}
>>> +
>>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>>> intf_width)
>>> +{
>>> + u32 bytes_per_soft_slice, bytes_per_intf;
>>> + s64 bytes_per_soft_slice_fp;
>>> + int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
>>> +
>>> + bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
>>> + bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
>>> +
>>> + bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
>>> +
>>> + return bytes_per_intf;
>>> +}
>>> +
>>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
>>> +{
>>> + s64 data_width;
>>> +
>>> + data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
>>> + get_bytes_per_soft_slice(dsc));
>>
>> And this is then DIV_ROUND_UP(dsc->slice_width * dsc->slice_count *
>> bpp, 8)
>
> I would prefer to keep the FP math/get_bytes_per_soft_slice() call here
> and leave the ceil() until the end.
It is the code, you are calling ceil right after drm_fixp_mul. So, there
is no difference.
>
>>
>>> +
>>> + return drm_fixp2int_ceil(data_width);
>>> +}
>>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> b/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> new file mode 100644
>>> index 000000000000..31116a31090f
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> @@ -0,0 +1,70 @@
>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>> +/*
>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>>> reserved
>>> + */
>>> +
>>> +#ifndef MSM_DSC_HELPER_H_
>>> +#define MSM_DSC_HELPER_H_
>>> +
>>> +#include <drm/display/drm_dsc_helper.h>
>>> +#include <drm/drm_modes.h>
>>> +
>>> +/*
>>> + * Helper methods for MSM specific DSC calculations that are common
>>> between timing engine,
>>> + * DSI, and DP.
>>> + */
>>> +
>>> +/**
>>> + * msm_dsc_get_bpp_int - get bits per pixel integer value
>>> + * @dsc: Pointer to drm dsc config struct
>>> + */
>>> +static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
>>> +{
>>> + WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
>>> + return dsc->bits_per_pixel >> 4;
>>> +}
>>> +
>>> +/**
>>> + * msm_dsc_get_slice_per_intf - get number of slices per interface
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config
>>> *dsc, int intf_width)
>>> +{
>>> + return DIV_ROUND_UP(intf_width, dsc->slice_width);
>>> +}
>>> +
>>> +/**
>>> + * msm_dsc_get_dce_bytes_per_line - get bytes per line to help
>>> calculate data width
>>> + * when configuring the timing engine
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +static inline u32 msm_dsc_get_dce_bytes_per_line(struct
>>> drm_dsc_config *dsc, int intf_width)
>>> +{
>>> + return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
>>> +}
>>> +
>>> +/**
>>> + * get_bytes_per_soft_slice - get size of each soft slice for dsc
>>> + * @dsc: Pointer to drm dsc config struct
>>> + */
>>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
>>> +
>>> +/**
>>> + * msm_dsc_get_bytes_per_intf - get total bytes per interface
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>>> intf_width);
>>> +
>>> +/**
>>> + * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
>>> + * @dsc: Pointer to drm dsc config struct
>>> + *
>>> + * Note: This value will then be passed along to DSI and DP for some
>>> more
>>> + * calculations. This is because DSI and DP divide the pclk_per_intf
>>> value
>>> + * by different values depending on if widebus is enabled.
>>> + */
>>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
>>
>> empty line, please
>
> Acked.
>
> Thanks,
>
> Jessica Zhang
>
>>
>>> +#endif /* MSM_DSC_HELPER_H_ */
>>>
>>
>> --
>> With best wishes
>> Dmitry
>>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 22:02 ` [Freedreno] " Jessica Zhang
@ 2023-04-05 23:34 ` Abhinav Kumar
2023-04-05 23:37 ` Dmitry Baryshkov
1 sibling, 1 reply; 17+ messages in thread
From: Abhinav Kumar @ 2023-04-05 23:34 UTC (permalink / raw)
To: Dmitry Baryshkov, Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Sean Paul, dri-devel, linux-arm-msm
On 4/5/2023 12:26 PM, Dmitry Baryshkov wrote:
> On 05/04/2023 03:41, Jessica Zhang wrote:
>> Introduce MSM-specific DSC helper methods, as some calculations are
>> common between DP and DSC.
>>
>> Changes in v2:
>> - Moved files up to msm/ directory
>> - Dropped get_comp_ratio() helper
>> - Used drm_int2fixp() to convert to integers to fp
>> - Style changes to improve readability
>> - Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
>> - Changed msm_dsc_get_slice_per_intf() to a static inline method
>> - Dropped last division step of msm_dsc_get_pclk_per_line() and changed
>> method name accordingly
>> - Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
>> - Fixed some math issues caused by passing in incorrect types to
>> drm_fixed methods in get_bytes_per_soft_slice()
>>
>> Changes in v3:
>> - Dropped src_bpp parameter from all methods -- src_bpp can be
>> calculated as dsc->bits_per_component * 3
>> - Dropped intf_width parameter from get_bytes_per_soft_slice()
>> - Moved dsc->bits_per_component to numerator calculation in
>> get_bytes_per_soft_slice()
>> - Renamed msm_dsc_get_uncompressed_pclk_per_line to
>> *_get_uncompressed_pclk_per_intf()
>> - Removed dsc->slice_width check from
>> msm_dsc_get_uncompressed_pclk_per_intf()
>> - Made get_bytes_per_soft_slice() a public method (this will be called
>> later to help calculate DP pclk params)
>> - Added documentation in comments
>> - Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
>> renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
>>
>> Changes in v4:
>> - Changed msm_dsc_get_uncompressed_pclk_per_intf to
>> msm_dsc_get_pclk_per_intf
>>
>> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
>> ---
>> drivers/gpu/drm/msm/Makefile | 1 +
>> drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
>> drivers/gpu/drm/msm/msm_dsc_helper.h | 70
>> ++++++++++++++++++++++++++++++++++++
>> 3 files changed, 118 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
>> index 7274c41228ed..b814fc80e2d5 100644
>> --- a/drivers/gpu/drm/msm/Makefile
>> +++ b/drivers/gpu/drm/msm/Makefile
>> @@ -94,6 +94,7 @@ msm-y += \
>> msm_atomic_tracepoints.o \
>> msm_debugfs.o \
>> msm_drv.o \
>> + msm_dsc_helper.o \
>> msm_fb.o \
>> msm_fence.o \
>> msm_gem.o \
>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c
>> b/drivers/gpu/drm/msm/msm_dsc_helper.c
>> new file mode 100644
>> index 000000000000..0539221eb09d
>> --- /dev/null
>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
>> @@ -0,0 +1,47 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>> reserved
>> + */
>> +
>> +#include <linux/kernel.h>
>> +#include <linux/errno.h>
>> +#include <drm/drm_fixed.h>
>> +
>> +#include "msm_drv.h"
>> +#include "msm_dsc_helper.h"
>> +
>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
>> +{
>> + int bpp = msm_dsc_get_bpp_int(dsc);
>> + s64 numerator_fp, denominator_fp;
>> + s64 comp_ratio_fp =
>> drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
>> +
>> + numerator_fp = drm_int2fixp(dsc->slice_width * 3 *
>> dsc->bits_per_component);
>> + denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
>> +
>> + return drm_fixp_div(numerator_fp, denominator_fp);
>
> If we remove 3 * dsc->bits_per_components from both numerator and
> denominator, this whole function seems to be as simple as
> DIV_ROUND_UP(dsc->slice_width * bpp, 8)
>
> Or, if you prefer FP math, drm_fixp_from_fraction(dsc->slice_width *
> bpp, 8).
>
True and thats not really surprising because bytes_per_soft_slice is
eventually (dsc->slice_width * bpp, 8)
I also thought about it after you mentioned that they will cancel out
then why was downstream code and our programming guide doing this way.
So i thought a bit more and the reason from what I can see is that its
showing that compression ratio was factored into the math while
calculating it. If we just go with (dsc->slice_width * bpp, 8), it does
not really show that this was actually compressed bytes per slice
leading to the earlier confusion that it was uncompressed pclk while it
actually was.
>> +}
>> +
>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>> intf_width)
>> +{
>> + u32 bytes_per_soft_slice, bytes_per_intf;
>> + s64 bytes_per_soft_slice_fp;
>> + int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
>> +
>> + bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
>> + bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
>> +
>> + bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
>> +
>> + return bytes_per_intf;
>> +}
>> +
>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
>> +{
>> + s64 data_width;
>> +
>> + data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
>> + get_bytes_per_soft_slice(dsc));
>
> And this is then DIV_ROUND_UP(dsc->slice_width * dsc->slice_count * bpp, 8)
>
>> +
>> + return drm_fixp2int_ceil(data_width);
>> +}
>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h
>> b/drivers/gpu/drm/msm/msm_dsc_helper.h
>> new file mode 100644
>> index 000000000000..31116a31090f
>> --- /dev/null
>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
>> @@ -0,0 +1,70 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>> reserved
>> + */
>> +
>> +#ifndef MSM_DSC_HELPER_H_
>> +#define MSM_DSC_HELPER_H_
>> +
>> +#include <drm/display/drm_dsc_helper.h>
>> +#include <drm/drm_modes.h>
>> +
>> +/*
>> + * Helper methods for MSM specific DSC calculations that are common
>> between timing engine,
>> + * DSI, and DP.
>> + */
>> +
>> +/**
>> + * msm_dsc_get_bpp_int - get bits per pixel integer value
>> + * @dsc: Pointer to drm dsc config struct
>> + */
>> +static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
>> +{
>> + WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
>> + return dsc->bits_per_pixel >> 4;
>> +}
>> +
>> +/**
>> + * msm_dsc_get_slice_per_intf - get number of slices per interface
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config
>> *dsc, int intf_width)
>> +{
>> + return DIV_ROUND_UP(intf_width, dsc->slice_width);
>> +}
>> +
>> +/**
>> + * msm_dsc_get_dce_bytes_per_line - get bytes per line to help
>> calculate data width
>> + * when configuring the timing engine
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +static inline u32 msm_dsc_get_dce_bytes_per_line(struct
>> drm_dsc_config *dsc, int intf_width)
>> +{
>> + return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
>> +}
>> +
>> +/**
>> + * get_bytes_per_soft_slice - get size of each soft slice for dsc
>> + * @dsc: Pointer to drm dsc config struct
>> + */
>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
>> +
>> +/**
>> + * msm_dsc_get_bytes_per_intf - get total bytes per interface
>> + * @dsc: Pointer to drm dsc config struct
>> + * @intf_width: interface width
>> + */
>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>> intf_width);
>> +
>> +/**
>> + * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
>> + * @dsc: Pointer to drm dsc config struct
>> + *
>> + * Note: This value will then be passed along to DSI and DP for some
>> more
>> + * calculations. This is because DSI and DP divide the pclk_per_intf
>> value
>> + * by different values depending on if widebus is enabled.
>> + */
>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
>
> empty line, please
>
>> +#endif /* MSM_DSC_HELPER_H_ */
>>
>
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods
2023-04-05 23:34 ` Abhinav Kumar
@ 2023-04-05 23:37 ` Dmitry Baryshkov
0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Baryshkov @ 2023-04-05 23:37 UTC (permalink / raw)
To: Abhinav Kumar, Jessica Zhang, freedreno
Cc: Marijn Suijten, Konrad Dybcio, Daniel Vetter, Rob Clark,
Sean Paul, dri-devel, linux-arm-msm
On 06/04/2023 02:34, Abhinav Kumar wrote:
>
>
> On 4/5/2023 12:26 PM, Dmitry Baryshkov wrote:
>> On 05/04/2023 03:41, Jessica Zhang wrote:
>>> Introduce MSM-specific DSC helper methods, as some calculations are
>>> common between DP and DSC.
>>>
>>> Changes in v2:
>>> - Moved files up to msm/ directory
>>> - Dropped get_comp_ratio() helper
>>> - Used drm_int2fixp() to convert to integers to fp
>>> - Style changes to improve readability
>>> - Dropped unused bpp variable in msm_dsc_get_dce_bytes_per_line()
>>> - Changed msm_dsc_get_slice_per_intf() to a static inline method
>>> - Dropped last division step of msm_dsc_get_pclk_per_line() and changed
>>> method name accordingly
>>> - Changed DSC_BPP macro to drm_dsc_get_bpp_int() helper method
>>> - Fixed some math issues caused by passing in incorrect types to
>>> drm_fixed methods in get_bytes_per_soft_slice()
>>>
>>> Changes in v3:
>>> - Dropped src_bpp parameter from all methods -- src_bpp can be
>>> calculated as dsc->bits_per_component * 3
>>> - Dropped intf_width parameter from get_bytes_per_soft_slice()
>>> - Moved dsc->bits_per_component to numerator calculation in
>>> get_bytes_per_soft_slice()
>>> - Renamed msm_dsc_get_uncompressed_pclk_per_line to
>>> *_get_uncompressed_pclk_per_intf()
>>> - Removed dsc->slice_width check from
>>> msm_dsc_get_uncompressed_pclk_per_intf()
>>> - Made get_bytes_per_soft_slice() a public method (this will be called
>>> later to help calculate DP pclk params)
>>> - Added documentation in comments
>>> - Moved extra_eol_bytes math out of msm_dsc_get_eol_byte_num() and
>>> renamed msm_dsc_get_eol_byte_num to *_get_bytes_per_intf.
>>>
>>> Changes in v4:
>>> - Changed msm_dsc_get_uncompressed_pclk_per_intf to
>>> msm_dsc_get_pclk_per_intf
>>>
>>> Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
>>> ---
>>> drivers/gpu/drm/msm/Makefile | 1 +
>>> drivers/gpu/drm/msm/msm_dsc_helper.c | 47 ++++++++++++++++++++++++
>>> drivers/gpu/drm/msm/msm_dsc_helper.h | 70
>>> ++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 118 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
>>> index 7274c41228ed..b814fc80e2d5 100644
>>> --- a/drivers/gpu/drm/msm/Makefile
>>> +++ b/drivers/gpu/drm/msm/Makefile
>>> @@ -94,6 +94,7 @@ msm-y += \
>>> msm_atomic_tracepoints.o \
>>> msm_debugfs.o \
>>> msm_drv.o \
>>> + msm_dsc_helper.o \
>>> msm_fb.o \
>>> msm_fence.o \
>>> msm_gem.o \
>>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> b/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> new file mode 100644
>>> index 000000000000..0539221eb09d
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.c
>>> @@ -0,0 +1,47 @@
>>> +// SPDX-License-Identifier: GPL-2.0-only
>>> +/*
>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>>> reserved
>>> + */
>>> +
>>> +#include <linux/kernel.h>
>>> +#include <linux/errno.h>
>>> +#include <drm/drm_fixed.h>
>>> +
>>> +#include "msm_drv.h"
>>> +#include "msm_dsc_helper.h"
>>> +
>>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc)
>>> +{
>>> + int bpp = msm_dsc_get_bpp_int(dsc);
>>> + s64 numerator_fp, denominator_fp;
>>> + s64 comp_ratio_fp =
>>> drm_fixp_from_fraction(dsc->bits_per_component * 3, bpp);
>>> +
>>> + numerator_fp = drm_int2fixp(dsc->slice_width * 3 *
>>> dsc->bits_per_component);
>>> + denominator_fp = drm_fixp_mul(comp_ratio_fp, drm_int2fixp(8));
>>> +
>>> + return drm_fixp_div(numerator_fp, denominator_fp);
>>
>> If we remove 3 * dsc->bits_per_components from both numerator and
>> denominator, this whole function seems to be as simple as
>> DIV_ROUND_UP(dsc->slice_width * bpp, 8)
>>
>> Or, if you prefer FP math, drm_fixp_from_fraction(dsc->slice_width *
>> bpp, 8).
>>
>
> True and thats not really surprising because bytes_per_soft_slice is
> eventually (dsc->slice_width * bpp, 8)
>
> I also thought about it after you mentioned that they will cancel out
> then why was downstream code and our programming guide doing this way.
>
> So i thought a bit more and the reason from what I can see is that its
> showing that compression ratio was factored into the math while
> calculating it. If we just go with (dsc->slice_width * bpp, 8), it does
> not really show that this was actually compressed bytes per slice
> leading to the earlier confusion that it was uncompressed pclk while it
> actually was.
I'd say, name we can name that dsc_bpp or compressed_bpp instead of just
bpp, this way showing that it is a compressed pclk. But please don't
complicate the math.
>
>>> +}
>>> +
>>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>>> intf_width)
>>> +{
>>> + u32 bytes_per_soft_slice, bytes_per_intf;
>>> + s64 bytes_per_soft_slice_fp;
>>> + int slice_per_intf = msm_dsc_get_slice_per_intf(dsc, intf_width);
>>> +
>>> + bytes_per_soft_slice_fp = get_bytes_per_soft_slice(dsc);
>>> + bytes_per_soft_slice = drm_fixp2int_ceil(bytes_per_soft_slice_fp);
>>> +
>>> + bytes_per_intf = bytes_per_soft_slice * slice_per_intf;
>>> +
>>> + return bytes_per_intf;
>>> +}
>>> +
>>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc)
>>> +{
>>> + s64 data_width;
>>> +
>>> + data_width = drm_fixp_mul(drm_int2fixp(dsc->slice_count),
>>> + get_bytes_per_soft_slice(dsc));
>>
>> And this is then DIV_ROUND_UP(dsc->slice_width * dsc->slice_count *
>> bpp, 8)
>>
>>> +
>>> + return drm_fixp2int_ceil(data_width);
>>> +}
>>> diff --git a/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> b/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> new file mode 100644
>>> index 000000000000..31116a31090f
>>> --- /dev/null
>>> +++ b/drivers/gpu/drm/msm/msm_dsc_helper.h
>>> @@ -0,0 +1,70 @@
>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>> +/*
>>> + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights
>>> reserved
>>> + */
>>> +
>>> +#ifndef MSM_DSC_HELPER_H_
>>> +#define MSM_DSC_HELPER_H_
>>> +
>>> +#include <drm/display/drm_dsc_helper.h>
>>> +#include <drm/drm_modes.h>
>>> +
>>> +/*
>>> + * Helper methods for MSM specific DSC calculations that are common
>>> between timing engine,
>>> + * DSI, and DP.
>>> + */
>>> +
>>> +/**
>>> + * msm_dsc_get_bpp_int - get bits per pixel integer value
>>> + * @dsc: Pointer to drm dsc config struct
>>> + */
>>> +static inline int msm_dsc_get_bpp_int(struct drm_dsc_config *dsc)
>>> +{
>>> + WARN_ON_ONCE(dsc->bits_per_pixel & 0xf);
>>> + return dsc->bits_per_pixel >> 4;
>>> +}
>>> +
>>> +/**
>>> + * msm_dsc_get_slice_per_intf - get number of slices per interface
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +static inline int msm_dsc_get_slice_per_intf(struct drm_dsc_config
>>> *dsc, int intf_width)
>>> +{
>>> + return DIV_ROUND_UP(intf_width, dsc->slice_width);
>>> +}
>>> +
>>> +/**
>>> + * msm_dsc_get_dce_bytes_per_line - get bytes per line to help
>>> calculate data width
>>> + * when configuring the timing engine
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +static inline u32 msm_dsc_get_dce_bytes_per_line(struct
>>> drm_dsc_config *dsc, int intf_width)
>>> +{
>>> + return DIV_ROUND_UP(msm_dsc_get_bpp_int(dsc) * intf_width, 8);
>>> +}
>>> +
>>> +/**
>>> + * get_bytes_per_soft_slice - get size of each soft slice for dsc
>>> + * @dsc: Pointer to drm dsc config struct
>>> + */
>>> +s64 get_bytes_per_soft_slice(struct drm_dsc_config *dsc);
>>> +
>>> +/**
>>> + * msm_dsc_get_bytes_per_intf - get total bytes per interface
>>> + * @dsc: Pointer to drm dsc config struct
>>> + * @intf_width: interface width
>>> + */
>>> +u32 msm_dsc_get_bytes_per_intf(struct drm_dsc_config *dsc, int
>>> intf_width);
>>> +
>>> +/**
>>> + * msm_dsc_get_pclk_per_intf - Calculate pclk per interface.
>>> + * @dsc: Pointer to drm dsc config struct
>>> + *
>>> + * Note: This value will then be passed along to DSI and DP for some
>>> more
>>> + * calculations. This is because DSI and DP divide the pclk_per_intf
>>> value
>>> + * by different values depending on if widebus is enabled.
>>> + */
>>> +int msm_dsc_get_pclk_per_intf(struct drm_dsc_config *dsc);
>>
>> empty line, please
>>
>>> +#endif /* MSM_DSC_HELPER_H_ */
>>>
>>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2023-04-05 23:37 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-05 0:41 [PATCH v4 0/6] Introduce MSM-specific DSC helpers Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 1/6] drm/msm: Add MSM-specific DSC helper methods Jessica Zhang
2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 22:02 ` [Freedreno] " Jessica Zhang
2023-04-05 22:03 ` Dmitry Baryshkov
2023-04-05 23:34 ` Abhinav Kumar
2023-04-05 23:37 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 2/6] drm/msm/dpu: Use DRM DSC helper for det_thresh_flatness Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 3/6] drm/msm/dpu: Fix slice_last_group_size calculation Jessica Zhang
2023-04-05 19:26 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 4/6] drm/msm/dsi: Use MSM and DRM DSC helper methods Jessica Zhang
2023-04-05 19:27 ` Dmitry Baryshkov
2023-04-05 20:39 ` Jessica Zhang
2023-04-05 0:41 ` [PATCH v4 5/6] drm/msm/dsi: update hdisplay calculation for dsi_timing_setup Jessica Zhang
2023-04-05 19:28 ` Dmitry Baryshkov
2023-04-05 0:41 ` [PATCH v4 6/6] drm/msm/dsi: Fix calculations pkt_per_line Jessica Zhang
2023-04-05 19:28 ` Dmitry Baryshkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).