Re: [Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-14 Thread Srivatsa, Anusha



> -Original Message-
> From: Ville Syrjälä 
> Sent: Friday, November 11, 2022 11:40 AM
> To: Srivatsa, Anusha 
> Cc: intel-gfx@lists.freedesktop.org; Roper, Matthew D
> 
> Subject: Re: [PATCH] drm/i915/display: Add missing checks for cdclk crawling
> 
> On Fri, Nov 11, 2022 at 11:26:02AM -0800, Anusha Srivatsa wrote:
> > cdclk_sanitize() function was written assuming vco was a signed integer.
> > vco gets assigned to -1 (essentially ~0) for the case where PLL might
> > be enabled and vco is not a frequency that will ever get used. In such
> > a scenario the right thing to do is disable the PLL and re-enable it
> > again with a valid frequency.
> > However the vco is declared as a unsigned variable.
> > With the above assumption, driver takes crawl path when not needed.
> > Add explicit check to not crawl in the case of an invalid PLL.
> >
> > v2: Move the check from .h to .c (MattR)
> > - Move check to bxt_set_cdclk() instead of
> > intel_modeset_calc_cdclk() which is directly in the path of the
> > sanitize() function (Ville)
> >
> > Cc: Ville Syrjälä 
> > Cc: Matt Roper 
> > Suggested-by: Ville Syrjälä 
> > Signed-off-by: Anusha Srivatsa 
> > ---
> >  drivers/gpu/drm/i915/display/intel_cdclk.c | 13 -
> >  1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c
> > b/drivers/gpu/drm/i915/display/intel_cdclk.c
> > index 8a9031012d74..2d9b7ba58358 100644
> > --- a/drivers/gpu/drm/i915/display/intel_cdclk.c
> > +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
> > @@ -1716,6 +1716,16 @@ static void dg2_cdclk_squash_program(struct
> drm_i915_private *i915,
> > intel_de_write(i915, CDCLK_SQUASH_CTL, squash_ctl);  }
> >
> > +static bool cdclk_pll_is_unknown(unsigned int vco) {
> > +   /*
> > +* Ensure driver does not take the crawl path for the
> > +* case when the vco is set to ~0 in the
> > +* sanitize path.
> > +*/
> > +   return (vco == ~0);
> 
> Pointless parens.
> 
> > +}
> > +
> >  static void bxt_set_cdclk(struct drm_i915_private *dev_priv,
> >   const struct intel_cdclk_config *cdclk_config,
> >   enum pipe pipe)
> > @@ -1748,7 +1758,8 @@ static void bxt_set_cdclk(struct drm_i915_private
> *dev_priv,
> > return;
> > }
> >
> > -   if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco
> > 0 && vco > 0) {
> > +   if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco
> > 0 && vco > 0 &&
> > +   (!cdclk_pll_is_unknown(dev_priv->display.cdclk.hw.vco))) {
> 
> More pointless parens
> 
> With those removed
> Reviewed-by: Ville Syrjälä 

Thanks Ville.

> Though I think we should probably add the pll_is_enabled() helper too, just
> make the code a bit more self explanatory.

At this point the current code should atleast not block the MTL cdclk churn 
series. But the suggested helper will make the code more explanatory and I can 
take it up.
Thanks for the feedback!

Anusha
 
> > if (dev_priv->display.cdclk.hw.vco != vco)
> > adlp_cdclk_pll_crawl(dev_priv, vco);
> > } else if (DISPLAY_VER(dev_priv) >= 11)
> > --
> > 2.25.1
> 
> --
> Ville Syrjälä
> Intel


Re: [Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-11 Thread Ville Syrjälä
On Fri, Nov 11, 2022 at 11:26:02AM -0800, Anusha Srivatsa wrote:
> cdclk_sanitize() function was written assuming vco was a signed integer.
> vco gets assigned to -1 (essentially ~0) for the case where PLL
> might be enabled and vco is not a frequency that will ever
> get used. In such a scenario the right thing to do is disable the
> PLL and re-enable it again with a valid frequency.
> However the vco is declared as a unsigned variable.
> With the above assumption, driver takes crawl path when not needed.
> Add explicit check to not crawl in the case of an invalid PLL.
> 
> v2: Move the check from .h to .c (MattR)
> - Move check to bxt_set_cdclk() instead of
> intel_modeset_calc_cdclk() which is directly in
> the path of the sanitize() function (Ville)
> 
> Cc: Ville Syrjälä 
> Cc: Matt Roper 
> Suggested-by: Ville Syrjälä 
> Signed-off-by: Anusha Srivatsa 
> ---
>  drivers/gpu/drm/i915/display/intel_cdclk.c | 13 -
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
> b/drivers/gpu/drm/i915/display/intel_cdclk.c
> index 8a9031012d74..2d9b7ba58358 100644
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.c
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
> @@ -1716,6 +1716,16 @@ static void dg2_cdclk_squash_program(struct 
> drm_i915_private *i915,
>   intel_de_write(i915, CDCLK_SQUASH_CTL, squash_ctl);
>  }
>  
> +static bool cdclk_pll_is_unknown(unsigned int vco)
> +{
> + /*
> +  * Ensure driver does not take the crawl path for the
> +  * case when the vco is set to ~0 in the
> +  * sanitize path.
> +  */
> + return (vco == ~0);

Pointless parens.

> +}
> +
>  static void bxt_set_cdclk(struct drm_i915_private *dev_priv,
> const struct intel_cdclk_config *cdclk_config,
> enum pipe pipe)
> @@ -1748,7 +1758,8 @@ static void bxt_set_cdclk(struct drm_i915_private 
> *dev_priv,
>   return;
>   }
>  
> - if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco > 0 && 
> vco > 0) {
> + if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco > 0 && 
> vco > 0 &&
> + (!cdclk_pll_is_unknown(dev_priv->display.cdclk.hw.vco))) {

More pointless parens

With those removed
Reviewed-by: Ville Syrjälä 

Though I think we should probably add the pll_is_enabled()
helper too, just make the code a bit more self explanatory.

>   if (dev_priv->display.cdclk.hw.vco != vco)
>   adlp_cdclk_pll_crawl(dev_priv, vco);
>   } else if (DISPLAY_VER(dev_priv) >= 11)
> -- 
> 2.25.1

-- 
Ville Syrjälä
Intel


[Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-11 Thread Anusha Srivatsa
cdclk_sanitize() function was written assuming vco was a signed integer.
vco gets assigned to -1 (essentially ~0) for the case where PLL
might be enabled and vco is not a frequency that will ever
get used. In such a scenario the right thing to do is disable the
PLL and re-enable it again with a valid frequency.
However the vco is declared as a unsigned variable.
With the above assumption, driver takes crawl path when not needed.
Add explicit check to not crawl in the case of an invalid PLL.

v2: Move the check from .h to .c (MattR)
- Move check to bxt_set_cdclk() instead of
intel_modeset_calc_cdclk() which is directly in
the path of the sanitize() function (Ville)

Cc: Ville Syrjälä 
Cc: Matt Roper 
Suggested-by: Ville Syrjälä 
Signed-off-by: Anusha Srivatsa 
---
 drivers/gpu/drm/i915/display/intel_cdclk.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
b/drivers/gpu/drm/i915/display/intel_cdclk.c
index 8a9031012d74..2d9b7ba58358 100644
--- a/drivers/gpu/drm/i915/display/intel_cdclk.c
+++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
@@ -1716,6 +1716,16 @@ static void dg2_cdclk_squash_program(struct 
drm_i915_private *i915,
intel_de_write(i915, CDCLK_SQUASH_CTL, squash_ctl);
 }
 
+static bool cdclk_pll_is_unknown(unsigned int vco)
+{
+   /*
+* Ensure driver does not take the crawl path for the
+* case when the vco is set to ~0 in the
+* sanitize path.
+*/
+   return (vco == ~0);
+}
+
 static void bxt_set_cdclk(struct drm_i915_private *dev_priv,
  const struct intel_cdclk_config *cdclk_config,
  enum pipe pipe)
@@ -1748,7 +1758,8 @@ static void bxt_set_cdclk(struct drm_i915_private 
*dev_priv,
return;
}
 
-   if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco > 0 && 
vco > 0) {
+   if (HAS_CDCLK_CRAWL(dev_priv) && dev_priv->display.cdclk.hw.vco > 0 && 
vco > 0 &&
+   (!cdclk_pll_is_unknown(dev_priv->display.cdclk.hw.vco))) {
if (dev_priv->display.cdclk.hw.vco != vco)
adlp_cdclk_pll_crawl(dev_priv, vco);
} else if (DISPLAY_VER(dev_priv) >= 11)
-- 
2.25.1



Re: [Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-10 Thread Ville Syrjälä
On Wed, Nov 09, 2022 at 09:37:24PM -0800, Anusha Srivatsa wrote:
> cdclk_sanitize() function was written assuming vco was a signed integer.
> vco gets assigned to -1 (essentially ~0) for the case where PLL
> might be enabled and vco is not a frequency that will ever
> get used. In such a scenario the right thing to do is disable the
> PLL and re-enable it again with a valid frequency.
> However the vco is declared as a unsigned variable.
> With the above assumption, driver takes crawl path when not needed.
> Add explicit check to not crawl in the case of an invalid PLL.
> 
> Cc: Matt Roper 
> Suggested-by: Ville Syrjälä 
> Signed-off-by: Anusha Srivatsa 
> ---
>  drivers/gpu/drm/i915/display/intel_cdclk.c | 2 ++
>  drivers/gpu/drm/i915/display/intel_cdclk.h | 1 +
>  2 files changed, 3 insertions(+)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
> b/drivers/gpu/drm/i915/display/intel_cdclk.c
> index 8a9031012d74..91112d266763 100644
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.c
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
> @@ -1962,6 +1962,8 @@ static bool intel_cdclk_can_crawl(struct 
> drm_i915_private *dev_priv,
>   if (!HAS_CDCLK_CRAWL(dev_priv))
>   return false;
>  
> + if (intel_pll_is_unknown(a->vco))
> + return false;

I think this guy is only called from the atomic_check() path, so
this check shouldn't be needed here. Where we do need it is the
crawl check bxt_set_cdclk() since that is what gets called directly
from the sanitize() path with hw.vco=~0.

>   /*
>* The vco and cd2x divider will change independently
>* from each, so we disallow cd2x change when crawling.
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.h 
> b/drivers/gpu/drm/i915/display/intel_cdclk.h
> index c674879a84a5..6eb83d806f11 100644
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.h
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.h
> @@ -80,6 +80,7 @@ intel_atomic_get_cdclk_state(struct intel_atomic_state 
> *state);
>   to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, 
> _i915(state->base.dev)->display.cdclk.obj))
>  #define intel_atomic_get_new_cdclk_state(state) \
>   to_intel_cdclk_state(intel_atomic_get_new_global_obj_state(state, 
> _i915(state->base.dev)->display.cdclk.obj))
> +#define intel_pll_is_unknown(vco)((vco) == ~0)
>  
>  int intel_cdclk_init(struct drm_i915_private *dev_priv);
>  
> -- 
> 2.25.1

-- 
Ville Syrjälä
Intel


Re: [Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-10 Thread Matt Roper
On Thu, Nov 10, 2022 at 01:28:19PM +0200, Jani Nikula wrote:
> On Wed, 09 Nov 2022, Anusha Srivatsa  wrote:
> > cdclk_sanitize() function was written assuming vco was a signed integer.
> > vco gets assigned to -1 (essentially ~0) for the case where PLL
> > might be enabled and vco is not a frequency that will ever
> > get used. In such a scenario the right thing to do is disable the
> > PLL and re-enable it again with a valid frequency.
> > However the vco is declared as a unsigned variable.
> > With the above assumption, driver takes crawl path when not needed.
> > Add explicit check to not crawl in the case of an invalid PLL.
> >
> > Cc: Matt Roper 
> > Suggested-by: Ville Syrjälä 
> > Signed-off-by: Anusha Srivatsa 
> > ---
> >  drivers/gpu/drm/i915/display/intel_cdclk.c | 2 ++
> >  drivers/gpu/drm/i915/display/intel_cdclk.h | 1 +
> >  2 files changed, 3 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
> > b/drivers/gpu/drm/i915/display/intel_cdclk.c
> > index 8a9031012d74..91112d266763 100644
> > --- a/drivers/gpu/drm/i915/display/intel_cdclk.c
> > +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
> > @@ -1962,6 +1962,8 @@ static bool intel_cdclk_can_crawl(struct 
> > drm_i915_private *dev_priv,
> > if (!HAS_CDCLK_CRAWL(dev_priv))
> > return false;
> >  
> > +   if (intel_pll_is_unknown(a->vco))
> > +   return false;
> > /*
> >  * The vco and cd2x divider will change independently
> >  * from each, so we disallow cd2x change when crawling.
> > diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.h 
> > b/drivers/gpu/drm/i915/display/intel_cdclk.h
> > index c674879a84a5..6eb83d806f11 100644
> > --- a/drivers/gpu/drm/i915/display/intel_cdclk.h
> > +++ b/drivers/gpu/drm/i915/display/intel_cdclk.h
> > @@ -80,6 +80,7 @@ intel_atomic_get_cdclk_state(struct intel_atomic_state 
> > *state);
> > to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, 
> > _i915(state->base.dev)->display.cdclk.obj))
> >  #define intel_atomic_get_new_cdclk_state(state) \
> > to_intel_cdclk_state(intel_atomic_get_new_global_obj_state(state, 
> > _i915(state->base.dev)->display.cdclk.obj))
> > +#define intel_pll_is_unknown(vco)  ((vco) == ~0)
> 
> Why here? What does a pll function do in intel_cdclk.h?

Since this is referring to the cdclk pll (not port pll's), I suspect
this shouldn't be needed anywhere outside the cdclk code.  So it might
be best just make this a static function inside the cdclk .c file rather
than placing it in a header that exposes it to the rest of the driver.
I.e., something like:

static bool pll_us_unknown(struct intel_cdclk_state *s) {
return (s->vco == ~0);
}


Matt

> 
> BR,
> Jani.
> 
> >  
> >  int intel_cdclk_init(struct drm_i915_private *dev_priv);
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 
Matt Roper
Graphics Software Engineer
VTT-OSGC Platform Enablement
Intel Corporation


Re: [Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-10 Thread Jani Nikula
On Wed, 09 Nov 2022, Anusha Srivatsa  wrote:
> cdclk_sanitize() function was written assuming vco was a signed integer.
> vco gets assigned to -1 (essentially ~0) for the case where PLL
> might be enabled and vco is not a frequency that will ever
> get used. In such a scenario the right thing to do is disable the
> PLL and re-enable it again with a valid frequency.
> However the vco is declared as a unsigned variable.
> With the above assumption, driver takes crawl path when not needed.
> Add explicit check to not crawl in the case of an invalid PLL.
>
> Cc: Matt Roper 
> Suggested-by: Ville Syrjälä 
> Signed-off-by: Anusha Srivatsa 
> ---
>  drivers/gpu/drm/i915/display/intel_cdclk.c | 2 ++
>  drivers/gpu/drm/i915/display/intel_cdclk.h | 1 +
>  2 files changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
> b/drivers/gpu/drm/i915/display/intel_cdclk.c
> index 8a9031012d74..91112d266763 100644
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.c
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
> @@ -1962,6 +1962,8 @@ static bool intel_cdclk_can_crawl(struct 
> drm_i915_private *dev_priv,
>   if (!HAS_CDCLK_CRAWL(dev_priv))
>   return false;
>  
> + if (intel_pll_is_unknown(a->vco))
> + return false;
>   /*
>* The vco and cd2x divider will change independently
>* from each, so we disallow cd2x change when crawling.
> diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.h 
> b/drivers/gpu/drm/i915/display/intel_cdclk.h
> index c674879a84a5..6eb83d806f11 100644
> --- a/drivers/gpu/drm/i915/display/intel_cdclk.h
> +++ b/drivers/gpu/drm/i915/display/intel_cdclk.h
> @@ -80,6 +80,7 @@ intel_atomic_get_cdclk_state(struct intel_atomic_state 
> *state);
>   to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, 
> _i915(state->base.dev)->display.cdclk.obj))
>  #define intel_atomic_get_new_cdclk_state(state) \
>   to_intel_cdclk_state(intel_atomic_get_new_global_obj_state(state, 
> _i915(state->base.dev)->display.cdclk.obj))
> +#define intel_pll_is_unknown(vco)((vco) == ~0)

Why here? What does a pll function do in intel_cdclk.h?

BR,
Jani.

>  
>  int intel_cdclk_init(struct drm_i915_private *dev_priv);

-- 
Jani Nikula, Intel Open Source Graphics Center


[Intel-gfx] [PATCH] drm/i915/display: Add missing checks for cdclk crawling

2022-11-09 Thread Anusha Srivatsa
cdclk_sanitize() function was written assuming vco was a signed integer.
vco gets assigned to -1 (essentially ~0) for the case where PLL
might be enabled and vco is not a frequency that will ever
get used. In such a scenario the right thing to do is disable the
PLL and re-enable it again with a valid frequency.
However the vco is declared as a unsigned variable.
With the above assumption, driver takes crawl path when not needed.
Add explicit check to not crawl in the case of an invalid PLL.

Cc: Matt Roper 
Suggested-by: Ville Syrjälä 
Signed-off-by: Anusha Srivatsa 
---
 drivers/gpu/drm/i915/display/intel_cdclk.c | 2 ++
 drivers/gpu/drm/i915/display/intel_cdclk.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c 
b/drivers/gpu/drm/i915/display/intel_cdclk.c
index 8a9031012d74..91112d266763 100644
--- a/drivers/gpu/drm/i915/display/intel_cdclk.c
+++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
@@ -1962,6 +1962,8 @@ static bool intel_cdclk_can_crawl(struct drm_i915_private 
*dev_priv,
if (!HAS_CDCLK_CRAWL(dev_priv))
return false;
 
+   if (intel_pll_is_unknown(a->vco))
+   return false;
/*
 * The vco and cd2x divider will change independently
 * from each, so we disallow cd2x change when crawling.
diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.h 
b/drivers/gpu/drm/i915/display/intel_cdclk.h
index c674879a84a5..6eb83d806f11 100644
--- a/drivers/gpu/drm/i915/display/intel_cdclk.h
+++ b/drivers/gpu/drm/i915/display/intel_cdclk.h
@@ -80,6 +80,7 @@ intel_atomic_get_cdclk_state(struct intel_atomic_state 
*state);
to_intel_cdclk_state(intel_atomic_get_old_global_obj_state(state, 
_i915(state->base.dev)->display.cdclk.obj))
 #define intel_atomic_get_new_cdclk_state(state) \
to_intel_cdclk_state(intel_atomic_get_new_global_obj_state(state, 
_i915(state->base.dev)->display.cdclk.obj))
+#define intel_pll_is_unknown(vco)  ((vco) == ~0)
 
 int intel_cdclk_init(struct drm_i915_private *dev_priv);
 
-- 
2.25.1