The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation
@ 2024-10-05 14:38 Jonathan Marek
  2024-10-05 14:38 ` [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Jonathan Marek
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jonathan Marek @ 2024-10-05 14:38 UTC (permalink / raw)
  To: freedreno
  Cc: Rob Clark, Abhinav Kumar, Dmitry Baryshkov, Sean Paul,
	Marijn Suijten, David Airlie, Simona Vetter, Jessica Zhang,
	Konrad Dybcio, open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

drm_mode_vrefresh() can introduce a large rounding error, avoid it.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
---
 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 185d7de0bf376..1205aa398e445 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
 
 	int new_htotal = mode->htotal - mode->hdisplay + new_hdisplay;
 
-	return new_htotal * mode->vtotal * drm_mode_vrefresh(mode);
+	return mult_frac(mode->clock * 1000u, new_htotal, mode->htotal);
 }
 
 static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,
-- 
2.45.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation
  2024-10-05 14:38 [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Jonathan Marek
@ 2024-10-05 14:38 ` Jonathan Marek
  2024-10-06 17:32   ` Dmitry Baryshkov
  2024-10-05 16:31 ` [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Konrad Dybcio
  2024-10-06 17:32 ` Dmitry Baryshkov
  2 siblings, 1 reply; 6+ messages in thread
From: Jonathan Marek @ 2024-10-05 14:38 UTC (permalink / raw)
  To: freedreno
  Cc: Rob Clark, Abhinav Kumar, Dmitry Baryshkov, Sean Paul,
	Marijn Suijten, David Airlie, Simona Vetter, Jessica Zhang,
	Konrad Dybcio, open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

When (mode->clock * 1000) is larger than (1<<31), int to unsigned long
conversion will sign extend the int to 64 bits and the pclk_rate value
will be incorrect.

Fix this by making the result of the multiplication unsigned.

Note that above (1<<32) would still be broken and require more changes, but
its unlikely anyone will need that anytime soon.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
---
 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 1205aa398e445..a98d24b7cb00b 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -550,7 +550,7 @@ static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,
 {
 	unsigned long pclk_rate;
 
-	pclk_rate = mode->clock * 1000;
+	pclk_rate = mode->clock * 1000u;
 
 	if (dsc)
 		pclk_rate = dsi_adjust_pclk_for_compression(mode, dsc);
-- 
2.45.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation
  2024-10-05 14:38 [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Jonathan Marek
  2024-10-05 14:38 ` [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Jonathan Marek
@ 2024-10-05 16:31 ` Konrad Dybcio
  2024-10-05 16:55   ` Jonathan Marek
  2024-10-06 17:32 ` Dmitry Baryshkov
  2 siblings, 1 reply; 6+ messages in thread
From: Konrad Dybcio @ 2024-10-05 16:31 UTC (permalink / raw)
  To: Jonathan Marek, freedreno
  Cc: Rob Clark, Abhinav Kumar, Dmitry Baryshkov, Sean Paul,
	Marijn Suijten, David Airlie, Simona Vetter, Jessica Zhang,
	Konrad Dybcio, open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

On 5.10.2024 4:38 PM, Jonathan Marek wrote:
> drm_mode_vrefresh() can introduce a large rounding error, avoid it.
> 
> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
> ---
>  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 185d7de0bf376..1205aa398e445 100644
> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
> @@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
>  
>  	int new_htotal = mode->htotal - mode->hdisplay + new_hdisplay;
>  
> -	return new_htotal * mode->vtotal * drm_mode_vrefresh(mode);
> +	return mult_frac(mode->clock * 1000u, new_htotal, mode->htotal);

This seems to ignore mult/div by two on certain mode flags.. is that
intended?

Konrad

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation
  2024-10-05 16:31 ` [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Konrad Dybcio
@ 2024-10-05 16:55   ` Jonathan Marek
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Marek @ 2024-10-05 16:55 UTC (permalink / raw)
  To: Konrad Dybcio, freedreno
  Cc: Rob Clark, Abhinav Kumar, Dmitry Baryshkov, Sean Paul,
	Marijn Suijten, David Airlie, Simona Vetter, Jessica Zhang,
	Konrad Dybcio, open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

On 10/5/24 12:31 PM, Konrad Dybcio wrote:
> On 5.10.2024 4:38 PM, Jonathan Marek wrote:
>> drm_mode_vrefresh() can introduce a large rounding error, avoid it.
>>
>> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
>> ---
>>   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 185d7de0bf376..1205aa398e445 100644
>> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
>> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
>> @@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
>>   
>>   	int new_htotal = mode->htotal - mode->hdisplay + new_hdisplay;
>>   
>> -	return new_htotal * mode->vtotal * drm_mode_vrefresh(mode);
>> +	return mult_frac(mode->clock * 1000u, new_htotal, mode->htotal);
> 
> This seems to ignore mult/div by two on certain mode flags.. is that
> intended?
> 
> Konrad
> 

It is intended - those flags are not relevant to DSI panels, and DSC 
pclk adjustment is only about how DSC affects htotal.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation
  2024-10-05 14:38 [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Jonathan Marek
  2024-10-05 14:38 ` [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Jonathan Marek
  2024-10-05 16:31 ` [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Konrad Dybcio
@ 2024-10-06 17:32 ` Dmitry Baryshkov
  2 siblings, 0 replies; 6+ messages in thread
From: Dmitry Baryshkov @ 2024-10-06 17:32 UTC (permalink / raw)
  To: Jonathan Marek
  Cc: freedreno, Rob Clark, Abhinav Kumar, Sean Paul, Marijn Suijten,
	David Airlie, Simona Vetter, Jessica Zhang, Konrad Dybcio,
	open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

On Sat, Oct 05, 2024 at 10:38:09AM GMT, Jonathan Marek wrote:
> drm_mode_vrefresh() can introduce a large rounding error, avoid it.
> 

Fixes?

> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
> ---
>  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 185d7de0bf376..1205aa398e445 100644
> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
> @@ -542,7 +542,7 @@ static unsigned long dsi_adjust_pclk_for_compression(const struct drm_display_mo
>  
>  	int new_htotal = mode->htotal - mode->hdisplay + new_hdisplay;
>  
> -	return new_htotal * mode->vtotal * drm_mode_vrefresh(mode);
> +	return mult_frac(mode->clock * 1000u, new_htotal, mode->htotal);
>  }
>  
>  static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,
> -- 
> 2.45.1
> 

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation
  2024-10-05 14:38 ` [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Jonathan Marek
@ 2024-10-06 17:32   ` Dmitry Baryshkov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Baryshkov @ 2024-10-06 17:32 UTC (permalink / raw)
  To: Jonathan Marek
  Cc: freedreno, Rob Clark, Abhinav Kumar, Sean Paul, Marijn Suijten,
	David Airlie, Simona Vetter, Jessica Zhang, Konrad Dybcio,
	open list:DRM DRIVER for Qualcomm display hardware,
	open list:DRM DRIVER for Qualcomm display hardware, open list

On Sat, Oct 05, 2024 at 10:38:10AM GMT, Jonathan Marek wrote:
> When (mode->clock * 1000) is larger than (1<<31), int to unsigned long
> conversion will sign extend the int to 64 bits and the pclk_rate value
> will be incorrect.
> 
> Fix this by making the result of the multiplication unsigned.
> 
> Note that above (1<<32) would still be broken and require more changes, but
> its unlikely anyone will need that anytime soon.
> 

Fixes?

> Signed-off-by: Jonathan Marek <jonathan@marek.ca>
> ---
>  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 1205aa398e445..a98d24b7cb00b 100644
> --- a/drivers/gpu/drm/msm/dsi/dsi_host.c
> +++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
> @@ -550,7 +550,7 @@ static unsigned long dsi_get_pclk_rate(const struct drm_display_mode *mode,
>  {
>  	unsigned long pclk_rate;
>  
> -	pclk_rate = mode->clock * 1000;
> +	pclk_rate = mode->clock * 1000u;
>  
>  	if (dsc)
>  		pclk_rate = dsi_adjust_pclk_for_compression(mode, dsc);
> -- 
> 2.45.1
> 

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-06 17:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-05 14:38 [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Jonathan Marek
2024-10-05 14:38 ` [PATCH 2/2] drm/msm/dsi: fix 32-bit signed integer extension in pclk_rate calculation Jonathan Marek
2024-10-06 17:32   ` Dmitry Baryshkov
2024-10-05 16:31 ` [PATCH 1/2] drm/msm/dsi: improve/fix dsc pclk calculation Konrad Dybcio
2024-10-05 16:55   ` Jonathan Marek
2024-10-06 17:32 ` Dmitry Baryshkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox