diff mbox series

drm/i915: Move hotplug inversion logic into separate helper

Message ID 20220919145659.293492-1-gustavo.sousa@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915: Move hotplug inversion logic into separate helper | expand

Commit Message

Gustavo Sousa Sept. 19, 2022, 2:56 p.m. UTC
Make the code more readable, which will be more apparent as new
platforms with different hotplug inversion needs are added.

Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
---
 drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Comments

Lucas De Marchi Sept. 20, 2022, 7:01 a.m. UTC | #1
On Mon, Sep 19, 2022 at 11:56:59AM -0300, Gustavo Sousa wrote:
>Make the code more readable, which will be more apparent as new
>platforms with different hotplug inversion needs are added.
>
>Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>---
> drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
> 1 file changed, 16 insertions(+), 9 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>index de06f293e173..c53d21ae197f 100644
>--- a/drivers/gpu/drm/i915/i915_irq.c
>+++ b/drivers/gpu/drm/i915/i915_irq.c
>@@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
> 	spin_unlock_irq(&dev_priv->irq_lock);
> }
>
>+static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)

new users of drm_i915_private should use "i915" as variable name rather
than dev_priv.

other than that,  Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>


Lucas De Marchi

>+{
>+	u32 invert_bits;
>+
>+	if (HAS_PCH_DG1(dev_priv))
>+		invert_bits = INVERT_DDIA_HPD |
>+			      INVERT_DDIB_HPD |
>+			      INVERT_DDIC_HPD |
>+			      INVERT_DDID_HPD;
>+	else
>+		return;
>+
>+	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
>+}
>+
> static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
> 			       enum hpd_pin pin)
> {
>@@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
>
> static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
> {
>-	u32 val;
>-
>-	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
>-	val |= (INVERT_DDIA_HPD |
>-		INVERT_DDIB_HPD |
>-		INVERT_DDIC_HPD |
>-		INVERT_DDID_HPD);
>-	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
>-
>+	setup_hotplug_inversion(dev_priv);
> 	icp_hpd_irq_setup(dev_priv);
> }
>
>-- 
>2.37.3
>
Jani Nikula Sept. 20, 2022, 7:19 a.m. UTC | #2
On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> Make the code more readable, which will be more apparent as new
> platforms with different hotplug inversion needs are added.
>
> Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> index de06f293e173..c53d21ae197f 100644
> --- a/drivers/gpu/drm/i915/i915_irq.c
> +++ b/drivers/gpu/drm/i915/i915_irq.c
> @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>  	spin_unlock_irq(&dev_priv->irq_lock);
>  }
>  
> +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
> +{
> +	u32 invert_bits;
> +
> +	if (HAS_PCH_DG1(dev_priv))
> +		invert_bits = INVERT_DDIA_HPD |
> +			      INVERT_DDIB_HPD |
> +			      INVERT_DDIC_HPD |
> +			      INVERT_DDID_HPD;

Nitpick, the indentation will be off compared to automated indentation.

> +	else
> +		return;
> +
> +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
> +}
> +
>  static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
>  			       enum hpd_pin pin)
>  {
> @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
>  
>  static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
>  {
> -	u32 val;
> -
> -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
> -	val |= (INVERT_DDIA_HPD |
> -		INVERT_DDIB_HPD |
> -		INVERT_DDIC_HPD |
> -		INVERT_DDID_HPD);
> -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
> -
> +	setup_hotplug_inversion(dev_priv);

Since you're already in a platform specific function here, seems a bit
odd to call a new generic function that needs to have another if ladder
platform check. What are we gaining here? The end result is
de-duplicating just one line of intel_uncore_rmw(). I'm not convinced.

BR,
Jani.


>  	icp_hpd_irq_setup(dev_priv);
>  }
Gustavo Sousa Sept. 20, 2022, 4:27 p.m. UTC | #3
On Tue, Sep 20, 2022 at 12:01:36AM -0700, Lucas De Marchi wrote:
> On Mon, Sep 19, 2022 at 11:56:59AM -0300, Gustavo Sousa wrote:
> > Make the code more readable, which will be more apparent as new
> > platforms with different hotplug inversion needs are added.
> > 
> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
> > ---
> > drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
> > 1 file changed, 16 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> > index de06f293e173..c53d21ae197f 100644
> > --- a/drivers/gpu/drm/i915/i915_irq.c
> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
> > 	spin_unlock_irq(&dev_priv->irq_lock);
> > }
> > 
> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
> 
> new users of drm_i915_private should use "i915" as variable name rather
> than dev_priv.

Thanks. I will update this.

Is there any documentation where we can find information like this?

> 
> other than that,  Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
> 
> 
> Lucas De Marchi
> 
> > +{
> > +	u32 invert_bits;
> > +
> > +	if (HAS_PCH_DG1(dev_priv))
> > +		invert_bits = INVERT_DDIA_HPD |
> > +			      INVERT_DDIB_HPD |
> > +			      INVERT_DDIC_HPD |
> > +			      INVERT_DDID_HPD;
> > +	else
> > +		return;
> > +
> > +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
> > +}
> > +
> > static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
> > 			       enum hpd_pin pin)
> > {
> > @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
> > 
> > static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
> > {
> > -	u32 val;
> > -
> > -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
> > -	val |= (INVERT_DDIA_HPD |
> > -		INVERT_DDIB_HPD |
> > -		INVERT_DDIC_HPD |
> > -		INVERT_DDID_HPD);
> > -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
> > -
> > +	setup_hotplug_inversion(dev_priv);
> > 	icp_hpd_irq_setup(dev_priv);
> > }
> > 
> > -- 
> > 2.37.3
> >
Gustavo Sousa Sept. 20, 2022, 5:04 p.m. UTC | #4
Hi, Jani.

On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> > Make the code more readable, which will be more apparent as new
> > platforms with different hotplug inversion needs are added.
> >
> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
> > ---
> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
> >  1 file changed, 16 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> > index de06f293e173..c53d21ae197f 100644
> > --- a/drivers/gpu/drm/i915/i915_irq.c
> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
> >  	spin_unlock_irq(&dev_priv->irq_lock);
> >  }
> >  
> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
> > +{
> > +	u32 invert_bits;
> > +
> > +	if (HAS_PCH_DG1(dev_priv))
> > +		invert_bits = INVERT_DDIA_HPD |
> > +			      INVERT_DDIB_HPD |
> > +			      INVERT_DDIC_HPD |
> > +			      INVERT_DDID_HPD;
> 
> Nitpick, the indentation will be off compared to automated indentation.

What do you mean by automated indentation?

> 
> > +	else
> > +		return;
> > +
> > +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
> > +}
> > +
> >  static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
> >  			       enum hpd_pin pin)
> >  {
> > @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
> >  
> >  static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
> >  {
> > -	u32 val;
> > -
> > -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
> > -	val |= (INVERT_DDIA_HPD |
> > -		INVERT_DDIB_HPD |
> > -		INVERT_DDIC_HPD |
> > -		INVERT_DDID_HPD);
> > -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
> > -
> > +	setup_hotplug_inversion(dev_priv);
> 
> Since you're already in a platform specific function here, seems a bit
> odd to call a new generic function that needs to have another if ladder
> platform check. What are we gaining here? The end result is
> de-duplicating just one line of intel_uncore_rmw(). I'm not convinced.

It is true that the proposed refactor repeats a platform check, but the proposed
refactor has its benefits. As more platforms with hotplug inversion needs are
added (e.g. MTL), we will have a common place for the logic of hotplug
inversion. That arguably makes the code more readable and makes future refactors
easier when we need split a function that has become too complex due to platform
checks.

To make that last point clearer, I am quoting Lucas' (copied here as well)
comment (which was what convinced me) from a discussion regarding the advantage
of using such a helper:

    that is what helpers are for, so you don't have to open code it in every
    platform-fork of the function that needs it. See how the various
    "Sequences to initialize display" are done in the driver... When we are
    extending it to a future platform, if the change is small enough we just
    add e few if/else in the same function. But it doesn't take too long for
    those functions to become unreadable if there are several branches the
    code path may take.  So then we "fork" the function for a new platform,
    but reuse the helpers doing the individual steps.

--
Gustavo Sousa
Lucas De Marchi Sept. 20, 2022, 5:56 p.m. UTC | #5
On Tue, Sep 20, 2022 at 02:04:33PM -0300, Gustavo Sousa wrote:
>Hi, Jani.
>
>On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
>> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
>> > Make the code more readable, which will be more apparent as new
>> > platforms with different hotplug inversion needs are added.
>> >
>> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> > ---
>> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>> >  1 file changed, 16 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>> > index de06f293e173..c53d21ae197f 100644
>> > --- a/drivers/gpu/drm/i915/i915_irq.c
>> > +++ b/drivers/gpu/drm/i915/i915_irq.c
>> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>> >  	spin_unlock_irq(&dev_priv->irq_lock);
>> >  }
>> >
>> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
>> > +{
>> > +	u32 invert_bits;
>> > +
>> > +	if (HAS_PCH_DG1(dev_priv))
>> > +		invert_bits = INVERT_DDIA_HPD |
>> > +			      INVERT_DDIB_HPD |
>> > +			      INVERT_DDIC_HPD |
>> > +			      INVERT_DDID_HPD;
>>
>> Nitpick, the indentation will be off compared to automated indentation.
>
>What do you mean by automated indentation?
>
>>
>> > +	else
>> > +		return;
>> > +
>> > +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
>> > +}
>> > +
>> >  static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
>> >  			       enum hpd_pin pin)
>> >  {
>> > @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
>> >
>> >  static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
>> >  {
>> > -	u32 val;
>> > -
>> > -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
>> > -	val |= (INVERT_DDIA_HPD |
>> > -		INVERT_DDIB_HPD |
>> > -		INVERT_DDIC_HPD |
>> > -		INVERT_DDID_HPD);
>> > -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
>> > -
>> > +	setup_hotplug_inversion(dev_priv);
>>
>> Since you're already in a platform specific function here, seems a bit
>> odd to call a new generic function that needs to have another if ladder
>> platform check. What are we gaining here? The end result is
>> de-duplicating just one line of intel_uncore_rmw(). I'm not convinced.
>
>It is true that the proposed refactor repeats a platform check, but the proposed
>refactor has its benefits. As more platforms with hotplug inversion needs are
>added (e.g. MTL), we will have a common place for the logic of hotplug
>inversion. That arguably makes the code more readable and makes future refactors
>easier when we need split a function that has become too complex due to platform
>checks.
>
>To make that last point clearer, I am quoting Lucas' (copied here as well)
>comment (which was what convinced me) from a discussion regarding the advantage
>of using such a helper:
>
>    that is what helpers are for, so you don't have to open code it in every
>    platform-fork of the function that needs it. See how the various
>    "Sequences to initialize display" are done in the driver... When we are
>    extending it to a future platform, if the change is small enough we just
>    add e few if/else in the same function. But it doesn't take too long for
>    those functions to become unreadable if there are several branches the
>    code path may take.  So then we "fork" the function for a new platform,
>    but reuse the helpers doing the individual steps.

the missing information here is that there are changes in the pipeline
for platforms that have different bits to be inverted, or none at
all, with a different register to program. Adding the if/else in this
function seems unrelated churn.

Another possibility would be to just let the caller handle the if/else
decision, passing the bits (and possibly register) to invert. The noise
in xxx_hpd_irq_setup() function may be avoid by

#define INVERT_DII_HPD		(INVERT_DDIA_HPD | INVERT_DDIB_HPD | INVERT_DDIC_HPD | INVERT_DDID_HPD)
#define XXX_INVERT_DII_HPD	(...)

Third possibility since the function is already very small is to just go
ahead and use another _setup() for the next platforms.

Lucas De Marchi
Jani Nikula Sept. 21, 2022, 8:21 a.m. UTC | #6
On Tue, 20 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> Hi, Jani.
>
> On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
>> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
>> > Make the code more readable, which will be more apparent as new
>> > platforms with different hotplug inversion needs are added.
>> >
>> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> > ---
>> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>> >  1 file changed, 16 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>> > index de06f293e173..c53d21ae197f 100644
>> > --- a/drivers/gpu/drm/i915/i915_irq.c
>> > +++ b/drivers/gpu/drm/i915/i915_irq.c
>> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>> >  	spin_unlock_irq(&dev_priv->irq_lock);
>> >  }
>> >  
>> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
>> > +{
>> > +	u32 invert_bits;
>> > +
>> > +	if (HAS_PCH_DG1(dev_priv))
>> > +		invert_bits = INVERT_DDIA_HPD |
>> > +			      INVERT_DDIB_HPD |
>> > +			      INVERT_DDIC_HPD |
>> > +			      INVERT_DDID_HPD;
>> 
>> Nitpick, the indentation will be off compared to automated indentation.
>
> What do you mean by automated indentation?

For example, hit TAB on the lines using a smart enough editor, which has
been configured to follow kernel coding style. ;)


BR,
Jani.
Jani Nikula Sept. 21, 2022, 9:59 a.m. UTC | #7
On Tue, 20 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> On Tue, Sep 20, 2022 at 12:01:36AM -0700, Lucas De Marchi wrote:
>> On Mon, Sep 19, 2022 at 11:56:59AM -0300, Gustavo Sousa wrote:
>> > Make the code more readable, which will be more apparent as new
>> > platforms with different hotplug inversion needs are added.
>> > 
>> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> > ---
>> > drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>> > 1 file changed, 16 insertions(+), 9 deletions(-)
>> > 
>> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>> > index de06f293e173..c53d21ae197f 100644
>> > --- a/drivers/gpu/drm/i915/i915_irq.c
>> > +++ b/drivers/gpu/drm/i915/i915_irq.c
>> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>> > 	spin_unlock_irq(&dev_priv->irq_lock);
>> > }
>> > 
>> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
>> 
>> new users of drm_i915_private should use "i915" as variable name rather
>> than dev_priv.
>
> Thanks. I will update this.
>
> Is there any documentation where we can find information like this?

WIP:

https://gitlab.freedesktop.org/jani/i915-check/-/blob/main/i915-style-guide.rst

BR,
Jani.

>
>> 
>> other than that,  Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
>> 
>> 
>> Lucas De Marchi
>> 
>> > +{
>> > +	u32 invert_bits;
>> > +
>> > +	if (HAS_PCH_DG1(dev_priv))
>> > +		invert_bits = INVERT_DDIA_HPD |
>> > +			      INVERT_DDIB_HPD |
>> > +			      INVERT_DDIC_HPD |
>> > +			      INVERT_DDID_HPD;
>> > +	else
>> > +		return;
>> > +
>> > +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
>> > +}
>> > +
>> > static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
>> > 			       enum hpd_pin pin)
>> > {
>> > @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
>> > 
>> > static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
>> > {
>> > -	u32 val;
>> > -
>> > -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
>> > -	val |= (INVERT_DDIA_HPD |
>> > -		INVERT_DDIB_HPD |
>> > -		INVERT_DDIC_HPD |
>> > -		INVERT_DDID_HPD);
>> > -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
>> > -
>> > +	setup_hotplug_inversion(dev_priv);
>> > 	icp_hpd_irq_setup(dev_priv);
>> > }
>> > 
>> > -- 
>> > 2.37.3
>> >
Jani Nikula Sept. 21, 2022, 10:23 a.m. UTC | #8
On Tue, 20 Sep 2022, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
> On Tue, Sep 20, 2022 at 02:04:33PM -0300, Gustavo Sousa wrote:
>>Hi, Jani.
>>
>>On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
>>> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
>>> > Make the code more readable, which will be more apparent as new
>>> > platforms with different hotplug inversion needs are added.
>>> >
>>> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>>> > ---
>>> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>>> >  1 file changed, 16 insertions(+), 9 deletions(-)
>>> >
>>> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>>> > index de06f293e173..c53d21ae197f 100644
>>> > --- a/drivers/gpu/drm/i915/i915_irq.c
>>> > +++ b/drivers/gpu/drm/i915/i915_irq.c
>>> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>>> >  	spin_unlock_irq(&dev_priv->irq_lock);
>>> >  }
>>> >
>>> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
>>> > +{
>>> > +	u32 invert_bits;
>>> > +
>>> > +	if (HAS_PCH_DG1(dev_priv))
>>> > +		invert_bits = INVERT_DDIA_HPD |
>>> > +			      INVERT_DDIB_HPD |
>>> > +			      INVERT_DDIC_HPD |
>>> > +			      INVERT_DDID_HPD;
>>>
>>> Nitpick, the indentation will be off compared to automated indentation.
>>
>>What do you mean by automated indentation?
>>
>>>
>>> > +	else
>>> > +		return;
>>> > +
>>> > +	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
>>> > +}
>>> > +
>>> >  static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
>>> >  			       enum hpd_pin pin)
>>> >  {
>>> > @@ -3413,15 +3428,7 @@ static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
>>> >
>>> >  static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
>>> >  {
>>> > -	u32 val;
>>> > -
>>> > -	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
>>> > -	val |= (INVERT_DDIA_HPD |
>>> > -		INVERT_DDIB_HPD |
>>> > -		INVERT_DDIC_HPD |
>>> > -		INVERT_DDID_HPD);
>>> > -	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
>>> > -
>>> > +	setup_hotplug_inversion(dev_priv);
>>>
>>> Since you're already in a platform specific function here, seems a bit
>>> odd to call a new generic function that needs to have another if ladder
>>> platform check. What are we gaining here? The end result is
>>> de-duplicating just one line of intel_uncore_rmw(). I'm not convinced.
>>
>>It is true that the proposed refactor repeats a platform check, but the proposed
>>refactor has its benefits. As more platforms with hotplug inversion needs are
>>added (e.g. MTL), we will have a common place for the logic of hotplug
>>inversion. That arguably makes the code more readable and makes future refactors
>>easier when we need split a function that has become too complex due to platform
>>checks.
>>
>>To make that last point clearer, I am quoting Lucas' (copied here as well)
>>comment (which was what convinced me) from a discussion regarding the advantage
>>of using such a helper:
>>
>>    that is what helpers are for, so you don't have to open code it in every
>>    platform-fork of the function that needs it. See how the various
>>    "Sequences to initialize display" are done in the driver... When we are
>>    extending it to a future platform, if the change is small enough we just
>>    add e few if/else in the same function. But it doesn't take too long for
>>    those functions to become unreadable if there are several branches the
>>    code path may take.  So then we "fork" the function for a new platform,
>>    but reuse the helpers doing the individual steps.
>
> the missing information here is that there are changes in the pipeline
> for platforms that have different bits to be inverted, or none at
> all, with a different register to program. Adding the if/else in this
> function seems unrelated churn.
>
> Another possibility would be to just let the caller handle the if/else
> decision, passing the bits (and possibly register) to invert. The noise
> in xxx_hpd_irq_setup() function may be avoid by
>
> #define INVERT_DII_HPD		(INVERT_DDIA_HPD | INVERT_DDIB_HPD | INVERT_DDIC_HPD | INVERT_DDID_HPD)
> #define XXX_INVERT_DII_HPD	(...)
>
> Third possibility since the function is already very small is to just go
> ahead and use another _setup() for the next platforms.

IMO if you already have platform specific functions, it can get
confusing if you call generic helpers that again spread out to platform
specific functions, possibly with different conditions than the first
one. We've had a bunch of those where you eventually realize there's
conditions in the helper that never happen.

I'd probably just add small *platform specific* hpd invert
functions. dg1_hpd_invert() and mtl_hpd_invert() etc.

Compare with *_hpd_detection_setup(), and wonder what that would look
like if it were a generic helper. Pretty bad, huh?

Also note how bxt actually handles hpd invert within
bxt_hpd_detection_setup().


BR,
Jani.
Gustavo Sousa Sept. 21, 2022, 12:05 p.m. UTC | #9
On Wed, Sep 21, 2022 at 11:21:00AM +0300, Jani Nikula wrote:
> On Tue, 20 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> > Hi, Jani.
> >
> > On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
> >> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> >> > Make the code more readable, which will be more apparent as new
> >> > platforms with different hotplug inversion needs are added.
> >> >
> >> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
> >> > ---
> >> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
> >> >  1 file changed, 16 insertions(+), 9 deletions(-)
> >> >
> >> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> >> > index de06f293e173..c53d21ae197f 100644
> >> > --- a/drivers/gpu/drm/i915/i915_irq.c
> >> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> >> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
> >> >  	spin_unlock_irq(&dev_priv->irq_lock);
> >> >  }
> >> >  
> >> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
> >> > +{
> >> > +	u32 invert_bits;
> >> > +
> >> > +	if (HAS_PCH_DG1(dev_priv))
> >> > +		invert_bits = INVERT_DDIA_HPD |
> >> > +			      INVERT_DDIB_HPD |
> >> > +			      INVERT_DDIC_HPD |
> >> > +			      INVERT_DDID_HPD;
> >> 
> >> Nitpick, the indentation will be off compared to automated indentation.
> >
> > What do you mean by automated indentation?
> 
> For example, hit TAB on the lines using a smart enough editor, which has
> been configured to follow kernel coding style. ;)
> 

I'm not sure I completely understand the issue. Could you provide an example of
such a configuration?

Is the problem here the spaces after the tabs to align each INVERT_DDI*? Would
you suggest I just use tabs and do not align them to the first one?

E.g.:

                invert_bits = INVERT_DDIA_HPD |
                                INVERT_DDIB_HPD |
                                INVERT_DDIC_HPD |
                                INVERT_DDID_HPD;

Another one:

                invert_bits = INVERT_DDIA_HPD |
                        INVERT_DDIB_HPD |
                        INVERT_DDIC_HPD |
                        INVERT_DDID_HPD;


Note: I'm using 8 spaces for instead tabs in the above examples for proper
visual, but they would be tab characters in the source.

--
Gustavo Sousa
Jani Nikula Sept. 22, 2022, 8:17 a.m. UTC | #10
On Wed, 21 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> On Wed, Sep 21, 2022 at 11:21:00AM +0300, Jani Nikula wrote:
>> On Tue, 20 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
>> > Hi, Jani.
>> >
>> > On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
>> >> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
>> >> > Make the code more readable, which will be more apparent as new
>> >> > platforms with different hotplug inversion needs are added.
>> >> >
>> >> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
>> >> > ---
>> >> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
>> >> >  1 file changed, 16 insertions(+), 9 deletions(-)
>> >> >
>> >> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
>> >> > index de06f293e173..c53d21ae197f 100644
>> >> > --- a/drivers/gpu/drm/i915/i915_irq.c
>> >> > +++ b/drivers/gpu/drm/i915/i915_irq.c
>> >> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
>> >> >  	spin_unlock_irq(&dev_priv->irq_lock);
>> >> >  }
>> >> >  
>> >> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
>> >> > +{
>> >> > +	u32 invert_bits;
>> >> > +
>> >> > +	if (HAS_PCH_DG1(dev_priv))
>> >> > +		invert_bits = INVERT_DDIA_HPD |
>> >> > +			      INVERT_DDIB_HPD |
>> >> > +			      INVERT_DDIC_HPD |
>> >> > +			      INVERT_DDID_HPD;
>> >> 
>> >> Nitpick, the indentation will be off compared to automated indentation.
>> >
>> > What do you mean by automated indentation?
>> 
>> For example, hit TAB on the lines using a smart enough editor, which has
>> been configured to follow kernel coding style. ;)
>> 
>
> I'm not sure I completely understand the issue. Could you provide an example of
> such a configuration?

I never indent anything manually. If I hit TAB in emacs (or run M-x
indent-region), it'll indent the current line (or region) using the
built-in "linux" style [1].

[1] https://www.gnu.org/software/emacs/manual/html_node/ccmode/Built_002din-Styles.html

> Is the problem here the spaces after the tabs to align each INVERT_DDI*? Would
> you suggest I just use tabs and do not align them to the first one?

If a parenthesized element in round brackets is split to multiple lines,
the indent is usually tabs first and then spaces to align everything
after the open parenthesis. If there are no parenthesis, the indent is
just tabs.

Guess why the original dg1_hpd_irq_setup() has round brackets in the
statement. ;) Though not everyone likes superfluous parenthesis for
style.

> E.g.:
>
>                 invert_bits = INVERT_DDIA_HPD |
>                                 INVERT_DDIB_HPD |
>                                 INVERT_DDIC_HPD |
>                                 INVERT_DDID_HPD;
>
> Another one:
>
>                 invert_bits = INVERT_DDIA_HPD |
>                         INVERT_DDIB_HPD |
>                         INVERT_DDIC_HPD |
>                         INVERT_DDID_HPD;

Your patch applied, re-indented, and tabs converted to spaces for visual
here:

        if (HAS_PCH_DG1(dev_priv))
                invert_bits = INVERT_DDIA_HPD |
                        INVERT_DDIB_HPD |
                        INVERT_DDIC_HPD |
                        INVERT_DDID_HPD;

Anyway, indentation isn't a very fruitful conversation in itself. The
original nitpick was an off the cuff remark. I'm mostly trying to
suggest to use tools that will do indentation and other things for you,
so you don't have to worry about getting it right.


BR,
Jani.

>
>
> Note: I'm using 8 spaces for instead tabs in the above examples for proper
> visual, but they would be tab characters in the source.
>
> --
> Gustavo Sousa
Gustavo Sousa Sept. 22, 2022, 10:53 a.m. UTC | #11
On Thu, Sep 22, 2022 at 11:17:01AM +0300, Jani Nikula wrote:
> On Wed, 21 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> > On Wed, Sep 21, 2022 at 11:21:00AM +0300, Jani Nikula wrote:
> >> On Tue, 20 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> >> > Hi, Jani.
> >> >
> >> > On Tue, Sep 20, 2022 at 10:19:53AM +0300, Jani Nikula wrote:
> >> >> On Mon, 19 Sep 2022, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> >> >> > Make the code more readable, which will be more apparent as new
> >> >> > platforms with different hotplug inversion needs are added.
> >> >> >
> >> >> > Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
> >> >> > ---
> >> >> >  drivers/gpu/drm/i915/i915_irq.c | 25 ++++++++++++++++---------
> >> >> >  1 file changed, 16 insertions(+), 9 deletions(-)
> >> >> >
> >> >> > diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
> >> >> > index de06f293e173..c53d21ae197f 100644
> >> >> > --- a/drivers/gpu/drm/i915/i915_irq.c
> >> >> > +++ b/drivers/gpu/drm/i915/i915_irq.c
> >> >> > @@ -3263,6 +3263,21 @@ static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
> >> >> >  	spin_unlock_irq(&dev_priv->irq_lock);
> >> >> >  }
> >> >> >  
> >> >> > +static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
> >> >> > +{
> >> >> > +	u32 invert_bits;
> >> >> > +
> >> >> > +	if (HAS_PCH_DG1(dev_priv))
> >> >> > +		invert_bits = INVERT_DDIA_HPD |
> >> >> > +			      INVERT_DDIB_HPD |
> >> >> > +			      INVERT_DDIC_HPD |
> >> >> > +			      INVERT_DDID_HPD;

Just checked the source and it seems I'm the only oddball aligning stuff like
this :-)

> >> >> 
> >> >> Nitpick, the indentation will be off compared to automated indentation.
> >> >
> >> > What do you mean by automated indentation?
> >> 
> >> For example, hit TAB on the lines using a smart enough editor, which has
> >> been configured to follow kernel coding style. ;)
> >> 
> >
> > I'm not sure I completely understand the issue. Could you provide an example of
> > such a configuration?
> 
> I never indent anything manually. If I hit TAB in emacs (or run M-x
> indent-region), it'll indent the current line (or region) using the
> built-in "linux" style [1].
> 
> [1] https://www.gnu.org/software/emacs/manual/html_node/ccmode/Built_002din-Styles.html
> 
> > Is the problem here the spaces after the tabs to align each INVERT_DDI*? Would
> > you suggest I just use tabs and do not align them to the first one?
> 
> If a parenthesized element in round brackets is split to multiple lines,
> the indent is usually tabs first and then spaces to align everything
> after the open parenthesis. If there are no parenthesis, the indent is
> just tabs.
> 
> Guess why the original dg1_hpd_irq_setup() has round brackets in the
> statement. ;) Though not everyone likes superfluous parenthesis for
> style.
> 
> > E.g.:
> >
> >                 invert_bits = INVERT_DDIA_HPD |
> >                                 INVERT_DDIB_HPD |
> >                                 INVERT_DDIC_HPD |
> >                                 INVERT_DDID_HPD;
> >
> > Another one:
> >
> >                 invert_bits = INVERT_DDIA_HPD |
> >                         INVERT_DDIB_HPD |
> >                         INVERT_DDIC_HPD |
> >                         INVERT_DDID_HPD;
> 
> Your patch applied, re-indented, and tabs converted to spaces for visual
> here:
> 
>         if (HAS_PCH_DG1(dev_priv))
>                 invert_bits = INVERT_DDIA_HPD |
>                         INVERT_DDIB_HPD |
>                         INVERT_DDIC_HPD |
>                         INVERT_DDID_HPD;
> 
> Anyway, indentation isn't a very fruitful conversation in itself. The
> original nitpick was an off the cuff remark. I'm mostly trying to
> suggest to use tools that will do indentation and other things for you,
> so you don't have to worry about getting it right.
> 

Thank you for the tips! I find them very helpful. I'll make sure to use proper
style when sending a new version.

--
Gustavo Sousa
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
index de06f293e173..c53d21ae197f 100644
--- a/drivers/gpu/drm/i915/i915_irq.c
+++ b/drivers/gpu/drm/i915/i915_irq.c
@@ -3263,6 +3263,21 @@  static void cherryview_irq_reset(struct drm_i915_private *dev_priv)
 	spin_unlock_irq(&dev_priv->irq_lock);
 }
 
+static void setup_hotplug_inversion(struct drm_i915_private *dev_priv)
+{
+	u32 invert_bits;
+
+	if (HAS_PCH_DG1(dev_priv))
+		invert_bits = INVERT_DDIA_HPD |
+			      INVERT_DDIB_HPD |
+			      INVERT_DDIC_HPD |
+			      INVERT_DDID_HPD;
+	else
+		return;
+
+	intel_uncore_rmw(&dev_priv->uncore, SOUTH_CHICKEN1, 0, invert_bits);
+}
+
 static u32 ibx_hotplug_enables(struct drm_i915_private *i915,
 			       enum hpd_pin pin)
 {
@@ -3413,15 +3428,7 @@  static u32 gen11_hotplug_enables(struct drm_i915_private *i915,
 
 static void dg1_hpd_irq_setup(struct drm_i915_private *dev_priv)
 {
-	u32 val;
-
-	val = intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN1);
-	val |= (INVERT_DDIA_HPD |
-		INVERT_DDIB_HPD |
-		INVERT_DDIC_HPD |
-		INVERT_DDID_HPD);
-	intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN1, val);
-
+	setup_hotplug_inversion(dev_priv);
 	icp_hpd_irq_setup(dev_priv);
 }