diff mbox

[v3,1/8] drm/modes: Introduce drm_mode_match()

Message ID 1515738096-16892-2-git-send-email-ankit.k.nautiyal@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nautiyal, Ankit K Jan. 12, 2018, 6:21 a.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Make mode matching less confusing by allowing the caller to specify
which parts of the modes should match via some flags.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_modes.c | 134 ++++++++++++++++++++++++++++++++++----------
 include/drm/drm_modes.h     |   9 +++
 2 files changed, 112 insertions(+), 31 deletions(-)

Comments

Sharma, Shashank Jan. 17, 2018, 8:41 a.m. UTC | #1
On 1/12/2018 11:51 AM, Nautiyal, Ankit K wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Make mode matching less confusing by allowing the caller to specify
> which parts of the modes should match via some flags.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/drm_modes.c | 134 ++++++++++++++++++++++++++++++++++----------
>   include/drm/drm_modes.h     |   9 +++
>   2 files changed, 112 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index 4a3f68a..8128dbb 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -940,17 +940,68 @@ struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
>   }
>   EXPORT_SYMBOL(drm_mode_duplicate);
>   
> +static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
> +				   const struct drm_display_mode *mode2)
Shouldn't the second parameter be aligned to next char after the opening 
bracket in above line (instead of being align to the bracket) ?
I have this same comment for most of the functions in this patch.
> +{
> +	return mode1->hdisplay == mode2->hdisplay &&
> +		mode1->hsync_start == mode2->hsync_start &&
> +		mode1->hsync_end == mode2->hsync_end &&
> +		mode1->htotal == mode2->htotal &&
> +		mode1->hskew == mode2->hskew &&
> +		mode1->vdisplay == mode2->vdisplay &&
> +		mode1->vsync_start == mode2->vsync_start &&
> +		mode1->vsync_end == mode2->vsync_end &&
> +		mode1->vtotal == mode2->vtotal &&
> +		mode1->vscan == mode2->vscan;
> +}
> +
> +static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
> +				  const struct drm_display_mode *mode2)
> +{
> +	/*
> +	 * do clock check convert to PICOS
> +	 * so fb modes get matched the same
> +	 */
> +	if (mode1->clock && mode2->clock)
> +		return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
> +	else
> +		return mode1->clock == mode2->clock;
> +}
> +
> +static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
Should we call it drm_mode_match_flag_no_stereo ?
> +				 const struct drm_display_mode *mode2)
> +{
> +	return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
> +		(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
> +}
> +
> +static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
> +				    const struct drm_display_mode *mode2)
> +{
> +	return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
> +		(mode2->flags & DRM_MODE_FLAG_3D_MASK);
> +}
> +
> +static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
> +					const struct drm_display_mode *mode2)
> +{
> +	return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
> +}
> +
>   /**
> - * drm_mode_equal - test modes for equality
> + * drm_mode_match - test modes for (partial) equality
>    * @mode1: first mode
>    * @mode2: second mode
> + * @match_flags: which parts need to match (DRM_MODE_MATCH_*)
>    *
>    * Check to see if @mode1 and @mode2 are equivalent.
>    *
>    * Returns:
> - * True if the modes are equal, false otherwise.
> + * True if the modes are (partially) equal, false otherwise.
>    */
> -bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
> +bool drm_mode_match(const struct drm_display_mode *mode1,
> +		    const struct drm_display_mode *mode2,
> +		    unsigned int match_flags)
>   {
>   	if (!mode1 && !mode2)
>   		return true;
> @@ -958,15 +1009,48 @@ bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_displ
>   	if (!mode1 || !mode2)
>   		return false;
>   
> -	/* do clock check convert to PICOS so fb modes get matched
> -	 * the same */
> -	if (mode1->clock && mode2->clock) {
> -		if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
> -			return false;
> -	} else if (mode1->clock != mode2->clock)
> +	if (match_flags & DRM_MODE_MATCH_TIMINGS &&
> +	    !drm_mode_match_timings(mode1, mode2))
> +		return false;
> +
> +	if (match_flags & DRM_MODE_MATCH_CLOCK &&
> +	    !drm_mode_match_clock(mode1, mode2))
> +		return false;
> +
> +	if (match_flags & DRM_MODE_MATCH_FLAGS &&
> +	    !drm_mode_match_flags(mode1, mode2))
> +		return false;
> +
> +	if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
> +	    !drm_mode_match_3d_flags(mode1, mode2))
>   		return false;
>   
> -	return drm_mode_equal_no_clocks(mode1, mode2);
> +	if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
> +	    !drm_mode_match_aspect_ratio(mode1, mode2))
> +		return false;
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_mode_match);
> +
> +/**
> + * drm_mode_equal - test modes for equality
> + * @mode1: first mode
> + * @mode2: second mode
> + *
> + * Check to see if @mode1 and @mode2 are equivalent.
> + *
> + * Returns:
> + * True if the modes are equal, false otherwise.
> + */
> +bool drm_mode_equal(const struct drm_display_mode *mode1,
> +		    const struct drm_display_mode *mode2)
> +{
> +	return drm_mode_match(mode1, mode2,
> +			      DRM_MODE_MATCH_TIMINGS |
> +			      DRM_MODE_MATCH_CLOCK |
> +			      DRM_MODE_MATCH_FLAGS |
> +			      DRM_MODE_MATCH_3D_FLAGS);
>   }
>   EXPORT_SYMBOL(drm_mode_equal);
>   
> @@ -981,13 +1065,13 @@ EXPORT_SYMBOL(drm_mode_equal);
>    * Returns:
>    * True if the modes are equal, false otherwise.
>    */
> -bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
> +bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
> +			      const struct drm_display_mode *mode2)
>   {
> -	if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
> -	    (mode2->flags & DRM_MODE_FLAG_3D_MASK))
> -		return false;
> -
> -	return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
> +	return drm_mode_match(mode1, mode2,
> +			      DRM_MODE_MATCH_TIMINGS |
> +			      DRM_MODE_MATCH_FLAGS |
> +			      DRM_MODE_MATCH_3D_FLAGS);
>   }
>   EXPORT_SYMBOL(drm_mode_equal_no_clocks);
>   
> @@ -1005,21 +1089,9 @@ EXPORT_SYMBOL(drm_mode_equal_no_clocks);
>   bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
>   					const struct drm_display_mode *mode2)
>   {
> -	if (mode1->hdisplay == mode2->hdisplay &&
> -	    mode1->hsync_start == mode2->hsync_start &&
> -	    mode1->hsync_end == mode2->hsync_end &&
> -	    mode1->htotal == mode2->htotal &&
> -	    mode1->hskew == mode2->hskew &&
> -	    mode1->vdisplay == mode2->vdisplay &&
> -	    mode1->vsync_start == mode2->vsync_start &&
> -	    mode1->vsync_end == mode2->vsync_end &&
> -	    mode1->vtotal == mode2->vtotal &&
> -	    mode1->vscan == mode2->vscan &&
> -	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
> -	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
> -		return true;
> -
> -	return false;
> +	return drm_mode_match(mode1, mode2,
> +			      DRM_MODE_MATCH_TIMINGS |
> +			      DRM_MODE_MATCH_FLAGS);
>   }
>   EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
>   
> diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
> index 9f3421c..839eb9c 100644
> --- a/include/drm/drm_modes.h
> +++ b/include/drm/drm_modes.h
> @@ -150,6 +150,12 @@ enum drm_mode_status {
>   
>   #define DRM_MODE_FLAG_3D_MAX	DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
>   
> +#define DRM_MODE_MATCH_TIMINGS (1 << 0)
> +#define DRM_MODE_MATCH_CLOCK (1 << 1)
> +#define DRM_MODE_MATCH_FLAGS (1 << 2)
> +#define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
> +#define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
> +
>   /**
>    * struct drm_display_mode - DRM kernel-internal display mode structure
>    * @hdisplay: horizontal display size
> @@ -493,6 +499,9 @@ void drm_mode_copy(struct drm_display_mode *dst,
>   		   const struct drm_display_mode *src);
>   struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
>   					    const struct drm_display_mode *mode);
> +bool drm_mode_match(const struct drm_display_mode *mode1,
> +		    const struct drm_display_mode *mode2,
Same here for the alignment
> +		    unsigned int match_flags);
>   bool drm_mode_equal(const struct drm_display_mode *mode1,
>   		    const struct drm_display_mode *mode2);
>   bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
With the minor comments above, please feel free to use
Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>
Ville Syrjälä Jan. 17, 2018, 3:21 p.m. UTC | #2
On Wed, Jan 17, 2018 at 02:11:55PM +0530, Sharma, Shashank wrote:
> 
> 
> On 1/12/2018 11:51 AM, Nautiyal, Ankit K wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Make mode matching less confusing by allowing the caller to specify
> > which parts of the modes should match via some flags.
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/drm_modes.c | 134 ++++++++++++++++++++++++++++++++++----------
> >   include/drm/drm_modes.h     |   9 +++
> >   2 files changed, 112 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> > index 4a3f68a..8128dbb 100644
> > --- a/drivers/gpu/drm/drm_modes.c
> > +++ b/drivers/gpu/drm/drm_modes.c
> > @@ -940,17 +940,68 @@ struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
> >   }
> >   EXPORT_SYMBOL(drm_mode_duplicate);
> >   
> > +static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
> > +				   const struct drm_display_mode *mode2)
> Shouldn't the second parameter be aligned to next char after the opening 
> bracket in above line (instead of being align to the bracket) ?

It is. The extra junk at the start of the line is causing the alignment
to look wrong when it's not because the tab stops are still aligned to
the start of the line. This is one reason why I think that using tabs
for alignment isn't a particularly great idea.

> I have this same comment for most of the functions in this patch.
> > +{
> > +	return mode1->hdisplay == mode2->hdisplay &&
> > +		mode1->hsync_start == mode2->hsync_start &&
> > +		mode1->hsync_end == mode2->hsync_end &&
> > +		mode1->htotal == mode2->htotal &&
> > +		mode1->hskew == mode2->hskew &&
> > +		mode1->vdisplay == mode2->vdisplay &&
> > +		mode1->vsync_start == mode2->vsync_start &&
> > +		mode1->vsync_end == mode2->vsync_end &&
> > +		mode1->vtotal == mode2->vtotal &&
> > +		mode1->vscan == mode2->vscan;
> > +}
> > +
> > +static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
> > +				  const struct drm_display_mode *mode2)
> > +{
> > +	/*
> > +	 * do clock check convert to PICOS
> > +	 * so fb modes get matched the same
> > +	 */
> > +	if (mode1->clock && mode2->clock)
> > +		return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
> > +	else
> > +		return mode1->clock == mode2->clock;
> > +}
> > +
> > +static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
> Should we call it drm_mode_match_flag_no_stereo ?

It's not really "no stereo", rather it's "check all the flags not being
checked by something more specific".

> > +				 const struct drm_display_mode *mode2)
> > +{
> > +	return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
> > +		(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
> > +}
> > +
> > +static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
> > +				    const struct drm_display_mode *mode2)
> > +{
> > +	return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
> > +		(mode2->flags & DRM_MODE_FLAG_3D_MASK);
> > +}
> > +
> > +static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
> > +					const struct drm_display_mode *mode2)
> > +{
> > +	return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
> > +}
> > +
> >   /**
> > - * drm_mode_equal - test modes for equality
> > + * drm_mode_match - test modes for (partial) equality
> >    * @mode1: first mode
> >    * @mode2: second mode
> > + * @match_flags: which parts need to match (DRM_MODE_MATCH_*)
> >    *
> >    * Check to see if @mode1 and @mode2 are equivalent.
> >    *
> >    * Returns:
> > - * True if the modes are equal, false otherwise.
> > + * True if the modes are (partially) equal, false otherwise.
> >    */
> > -bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
> > +bool drm_mode_match(const struct drm_display_mode *mode1,
> > +		    const struct drm_display_mode *mode2,
> > +		    unsigned int match_flags)
> >   {
> >   	if (!mode1 && !mode2)
> >   		return true;
> > @@ -958,15 +1009,48 @@ bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_displ
> >   	if (!mode1 || !mode2)
> >   		return false;
> >   
> > -	/* do clock check convert to PICOS so fb modes get matched
> > -	 * the same */
> > -	if (mode1->clock && mode2->clock) {
> > -		if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
> > -			return false;
> > -	} else if (mode1->clock != mode2->clock)
> > +	if (match_flags & DRM_MODE_MATCH_TIMINGS &&
> > +	    !drm_mode_match_timings(mode1, mode2))
> > +		return false;
> > +
> > +	if (match_flags & DRM_MODE_MATCH_CLOCK &&
> > +	    !drm_mode_match_clock(mode1, mode2))
> > +		return false;
> > +
> > +	if (match_flags & DRM_MODE_MATCH_FLAGS &&
> > +	    !drm_mode_match_flags(mode1, mode2))
> > +		return false;
> > +
> > +	if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
> > +	    !drm_mode_match_3d_flags(mode1, mode2))
> >   		return false;
> >   
> > -	return drm_mode_equal_no_clocks(mode1, mode2);
> > +	if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
> > +	    !drm_mode_match_aspect_ratio(mode1, mode2))
> > +		return false;
> > +
> > +	return true;
> > +}
> > +EXPORT_SYMBOL(drm_mode_match);
> > +
> > +/**
> > + * drm_mode_equal - test modes for equality
> > + * @mode1: first mode
> > + * @mode2: second mode
> > + *
> > + * Check to see if @mode1 and @mode2 are equivalent.
> > + *
> > + * Returns:
> > + * True if the modes are equal, false otherwise.
> > + */
> > +bool drm_mode_equal(const struct drm_display_mode *mode1,
> > +		    const struct drm_display_mode *mode2)
> > +{
> > +	return drm_mode_match(mode1, mode2,
> > +			      DRM_MODE_MATCH_TIMINGS |
> > +			      DRM_MODE_MATCH_CLOCK |
> > +			      DRM_MODE_MATCH_FLAGS |
> > +			      DRM_MODE_MATCH_3D_FLAGS);
> >   }
> >   EXPORT_SYMBOL(drm_mode_equal);
> >   
> > @@ -981,13 +1065,13 @@ EXPORT_SYMBOL(drm_mode_equal);
> >    * Returns:
> >    * True if the modes are equal, false otherwise.
> >    */
> > -bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
> > +bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
> > +			      const struct drm_display_mode *mode2)
> >   {
> > -	if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
> > -	    (mode2->flags & DRM_MODE_FLAG_3D_MASK))
> > -		return false;
> > -
> > -	return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
> > +	return drm_mode_match(mode1, mode2,
> > +			      DRM_MODE_MATCH_TIMINGS |
> > +			      DRM_MODE_MATCH_FLAGS |
> > +			      DRM_MODE_MATCH_3D_FLAGS);
> >   }
> >   EXPORT_SYMBOL(drm_mode_equal_no_clocks);
> >   
> > @@ -1005,21 +1089,9 @@ EXPORT_SYMBOL(drm_mode_equal_no_clocks);
> >   bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
> >   					const struct drm_display_mode *mode2)
> >   {
> > -	if (mode1->hdisplay == mode2->hdisplay &&
> > -	    mode1->hsync_start == mode2->hsync_start &&
> > -	    mode1->hsync_end == mode2->hsync_end &&
> > -	    mode1->htotal == mode2->htotal &&
> > -	    mode1->hskew == mode2->hskew &&
> > -	    mode1->vdisplay == mode2->vdisplay &&
> > -	    mode1->vsync_start == mode2->vsync_start &&
> > -	    mode1->vsync_end == mode2->vsync_end &&
> > -	    mode1->vtotal == mode2->vtotal &&
> > -	    mode1->vscan == mode2->vscan &&
> > -	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
> > -	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
> > -		return true;
> > -
> > -	return false;
> > +	return drm_mode_match(mode1, mode2,
> > +			      DRM_MODE_MATCH_TIMINGS |
> > +			      DRM_MODE_MATCH_FLAGS);
> >   }
> >   EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
> >   
> > diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
> > index 9f3421c..839eb9c 100644
> > --- a/include/drm/drm_modes.h
> > +++ b/include/drm/drm_modes.h
> > @@ -150,6 +150,12 @@ enum drm_mode_status {
> >   
> >   #define DRM_MODE_FLAG_3D_MAX	DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
> >   
> > +#define DRM_MODE_MATCH_TIMINGS (1 << 0)
> > +#define DRM_MODE_MATCH_CLOCK (1 << 1)
> > +#define DRM_MODE_MATCH_FLAGS (1 << 2)
> > +#define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
> > +#define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
> > +
> >   /**
> >    * struct drm_display_mode - DRM kernel-internal display mode structure
> >    * @hdisplay: horizontal display size
> > @@ -493,6 +499,9 @@ void drm_mode_copy(struct drm_display_mode *dst,
> >   		   const struct drm_display_mode *src);
> >   struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
> >   					    const struct drm_display_mode *mode);
> > +bool drm_mode_match(const struct drm_display_mode *mode1,
> > +		    const struct drm_display_mode *mode2,
> Same here for the alignment
> > +		    unsigned int match_flags);
> >   bool drm_mode_equal(const struct drm_display_mode *mode1,
> >   		    const struct drm_display_mode *mode2);
> >   bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
> With the minor comments above, please feel free to use
> Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>
Sharma, Shashank Jan. 18, 2018, 6:10 a.m. UTC | #3
Regards

Shashank


On 1/17/2018 8:51 PM, Ville Syrjälä wrote:
> On Wed, Jan 17, 2018 at 02:11:55PM +0530, Sharma, Shashank wrote:
>>
>> On 1/12/2018 11:51 AM, Nautiyal, Ankit K wrote:
>>> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>>
>>> Make mode matching less confusing by allowing the caller to specify
>>> which parts of the modes should match via some flags.
>>>
>>> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>> ---
>>>    drivers/gpu/drm/drm_modes.c | 134 ++++++++++++++++++++++++++++++++++----------
>>>    include/drm/drm_modes.h     |   9 +++
>>>    2 files changed, 112 insertions(+), 31 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
>>> index 4a3f68a..8128dbb 100644
>>> --- a/drivers/gpu/drm/drm_modes.c
>>> +++ b/drivers/gpu/drm/drm_modes.c
>>> @@ -940,17 +940,68 @@ struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
>>>    }
>>>    EXPORT_SYMBOL(drm_mode_duplicate);
>>>    
>>> +static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
>>> +				   const struct drm_display_mode *mode2)
>> Shouldn't the second parameter be aligned to next char after the opening
>> bracket in above line (instead of being align to the bracket) ?
> It is. The extra junk at the start of the line is causing the alignment
> to look wrong when it's not because the tab stops are still aligned to
> the start of the line. This is one reason why I think that using tabs
> for alignment isn't a particularly great idea.
>
>> I have this same comment for most of the functions in this patch.
>>> +{
>>> +	return mode1->hdisplay == mode2->hdisplay &&
>>> +		mode1->hsync_start == mode2->hsync_start &&
>>> +		mode1->hsync_end == mode2->hsync_end &&
>>> +		mode1->htotal == mode2->htotal &&
>>> +		mode1->hskew == mode2->hskew &&
>>> +		mode1->vdisplay == mode2->vdisplay &&
>>> +		mode1->vsync_start == mode2->vsync_start &&
>>> +		mode1->vsync_end == mode2->vsync_end &&
>>> +		mode1->vtotal == mode2->vtotal &&
>>> +		mode1->vscan == mode2->vscan;
>>> +}
>>> +
>>> +static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
>>> +				  const struct drm_display_mode *mode2)
>>> +{
>>> +	/*
>>> +	 * do clock check convert to PICOS
>>> +	 * so fb modes get matched the same
>>> +	 */
>>> +	if (mode1->clock && mode2->clock)
>>> +		return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
>>> +	else
>>> +		return mode1->clock == mode2->clock;
>>> +}
>>> +
>>> +static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
>> Should we call it drm_mode_match_flag_no_stereo ?
> It's not really "no stereo", rather it's "check all the flags not being
> checked by something more specific".
Yeah, anyways no big deal. With or without, feel free to use my r-b
- Shashank
>>> +				 const struct drm_display_mode *mode2)
>>> +{
>>> +	return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
>>> +		(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
>>> +}
>>> +
>>> +static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
>>> +				    const struct drm_display_mode *mode2)
>>> +{
>>> +	return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
>>> +		(mode2->flags & DRM_MODE_FLAG_3D_MASK);
>>> +}
>>> +
>>> +static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
>>> +					const struct drm_display_mode *mode2)
>>> +{
>>> +	return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
>>> +}
>>> +
>>>    /**
>>> - * drm_mode_equal - test modes for equality
>>> + * drm_mode_match - test modes for (partial) equality
>>>     * @mode1: first mode
>>>     * @mode2: second mode
>>> + * @match_flags: which parts need to match (DRM_MODE_MATCH_*)
>>>     *
>>>     * Check to see if @mode1 and @mode2 are equivalent.
>>>     *
>>>     * Returns:
>>> - * True if the modes are equal, false otherwise.
>>> + * True if the modes are (partially) equal, false otherwise.
>>>     */
>>> -bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
>>> +bool drm_mode_match(const struct drm_display_mode *mode1,
>>> +		    const struct drm_display_mode *mode2,
>>> +		    unsigned int match_flags)
>>>    {
>>>    	if (!mode1 && !mode2)
>>>    		return true;
>>> @@ -958,15 +1009,48 @@ bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_displ
>>>    	if (!mode1 || !mode2)
>>>    		return false;
>>>    
>>> -	/* do clock check convert to PICOS so fb modes get matched
>>> -	 * the same */
>>> -	if (mode1->clock && mode2->clock) {
>>> -		if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
>>> -			return false;
>>> -	} else if (mode1->clock != mode2->clock)
>>> +	if (match_flags & DRM_MODE_MATCH_TIMINGS &&
>>> +	    !drm_mode_match_timings(mode1, mode2))
>>> +		return false;
>>> +
>>> +	if (match_flags & DRM_MODE_MATCH_CLOCK &&
>>> +	    !drm_mode_match_clock(mode1, mode2))
>>> +		return false;
>>> +
>>> +	if (match_flags & DRM_MODE_MATCH_FLAGS &&
>>> +	    !drm_mode_match_flags(mode1, mode2))
>>> +		return false;
>>> +
>>> +	if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
>>> +	    !drm_mode_match_3d_flags(mode1, mode2))
>>>    		return false;
>>>    
>>> -	return drm_mode_equal_no_clocks(mode1, mode2);
>>> +	if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
>>> +	    !drm_mode_match_aspect_ratio(mode1, mode2))
>>> +		return false;
>>> +
>>> +	return true;
>>> +}
>>> +EXPORT_SYMBOL(drm_mode_match);
>>> +
>>> +/**
>>> + * drm_mode_equal - test modes for equality
>>> + * @mode1: first mode
>>> + * @mode2: second mode
>>> + *
>>> + * Check to see if @mode1 and @mode2 are equivalent.
>>> + *
>>> + * Returns:
>>> + * True if the modes are equal, false otherwise.
>>> + */
>>> +bool drm_mode_equal(const struct drm_display_mode *mode1,
>>> +		    const struct drm_display_mode *mode2)
>>> +{
>>> +	return drm_mode_match(mode1, mode2,
>>> +			      DRM_MODE_MATCH_TIMINGS |
>>> +			      DRM_MODE_MATCH_CLOCK |
>>> +			      DRM_MODE_MATCH_FLAGS |
>>> +			      DRM_MODE_MATCH_3D_FLAGS);
>>>    }
>>>    EXPORT_SYMBOL(drm_mode_equal);
>>>    
>>> @@ -981,13 +1065,13 @@ EXPORT_SYMBOL(drm_mode_equal);
>>>     * Returns:
>>>     * True if the modes are equal, false otherwise.
>>>     */
>>> -bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
>>> +bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
>>> +			      const struct drm_display_mode *mode2)
>>>    {
>>> -	if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
>>> -	    (mode2->flags & DRM_MODE_FLAG_3D_MASK))
>>> -		return false;
>>> -
>>> -	return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
>>> +	return drm_mode_match(mode1, mode2,
>>> +			      DRM_MODE_MATCH_TIMINGS |
>>> +			      DRM_MODE_MATCH_FLAGS |
>>> +			      DRM_MODE_MATCH_3D_FLAGS);
>>>    }
>>>    EXPORT_SYMBOL(drm_mode_equal_no_clocks);
>>>    
>>> @@ -1005,21 +1089,9 @@ EXPORT_SYMBOL(drm_mode_equal_no_clocks);
>>>    bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
>>>    					const struct drm_display_mode *mode2)
>>>    {
>>> -	if (mode1->hdisplay == mode2->hdisplay &&
>>> -	    mode1->hsync_start == mode2->hsync_start &&
>>> -	    mode1->hsync_end == mode2->hsync_end &&
>>> -	    mode1->htotal == mode2->htotal &&
>>> -	    mode1->hskew == mode2->hskew &&
>>> -	    mode1->vdisplay == mode2->vdisplay &&
>>> -	    mode1->vsync_start == mode2->vsync_start &&
>>> -	    mode1->vsync_end == mode2->vsync_end &&
>>> -	    mode1->vtotal == mode2->vtotal &&
>>> -	    mode1->vscan == mode2->vscan &&
>>> -	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
>>> -	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
>>> -		return true;
>>> -
>>> -	return false;
>>> +	return drm_mode_match(mode1, mode2,
>>> +			      DRM_MODE_MATCH_TIMINGS |
>>> +			      DRM_MODE_MATCH_FLAGS);
>>>    }
>>>    EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
>>>    
>>> diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
>>> index 9f3421c..839eb9c 100644
>>> --- a/include/drm/drm_modes.h
>>> +++ b/include/drm/drm_modes.h
>>> @@ -150,6 +150,12 @@ enum drm_mode_status {
>>>    
>>>    #define DRM_MODE_FLAG_3D_MAX	DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
>>>    
>>> +#define DRM_MODE_MATCH_TIMINGS (1 << 0)
>>> +#define DRM_MODE_MATCH_CLOCK (1 << 1)
>>> +#define DRM_MODE_MATCH_FLAGS (1 << 2)
>>> +#define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
>>> +#define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
>>> +
>>>    /**
>>>     * struct drm_display_mode - DRM kernel-internal display mode structure
>>>     * @hdisplay: horizontal display size
>>> @@ -493,6 +499,9 @@ void drm_mode_copy(struct drm_display_mode *dst,
>>>    		   const struct drm_display_mode *src);
>>>    struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
>>>    					    const struct drm_display_mode *mode);
>>> +bool drm_mode_match(const struct drm_display_mode *mode1,
>>> +		    const struct drm_display_mode *mode2,
>> Same here for the alignment
>>> +		    unsigned int match_flags);
>>>    bool drm_mode_equal(const struct drm_display_mode *mode1,
>>>    		    const struct drm_display_mode *mode2);
>>>    bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
>> With the minor comments above, please feel free to use
>> Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 4a3f68a..8128dbb 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -940,17 +940,68 @@  struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_mode_duplicate);
 
+static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
+				   const struct drm_display_mode *mode2)
+{
+	return mode1->hdisplay == mode2->hdisplay &&
+		mode1->hsync_start == mode2->hsync_start &&
+		mode1->hsync_end == mode2->hsync_end &&
+		mode1->htotal == mode2->htotal &&
+		mode1->hskew == mode2->hskew &&
+		mode1->vdisplay == mode2->vdisplay &&
+		mode1->vsync_start == mode2->vsync_start &&
+		mode1->vsync_end == mode2->vsync_end &&
+		mode1->vtotal == mode2->vtotal &&
+		mode1->vscan == mode2->vscan;
+}
+
+static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
+				  const struct drm_display_mode *mode2)
+{
+	/*
+	 * do clock check convert to PICOS
+	 * so fb modes get matched the same
+	 */
+	if (mode1->clock && mode2->clock)
+		return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
+	else
+		return mode1->clock == mode2->clock;
+}
+
+static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
+				 const struct drm_display_mode *mode2)
+{
+	return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
+		(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
+}
+
+static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
+				    const struct drm_display_mode *mode2)
+{
+	return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
+		(mode2->flags & DRM_MODE_FLAG_3D_MASK);
+}
+
+static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
+					const struct drm_display_mode *mode2)
+{
+	return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
+}
+
 /**
- * drm_mode_equal - test modes for equality
+ * drm_mode_match - test modes for (partial) equality
  * @mode1: first mode
  * @mode2: second mode
+ * @match_flags: which parts need to match (DRM_MODE_MATCH_*)
  *
  * Check to see if @mode1 and @mode2 are equivalent.
  *
  * Returns:
- * True if the modes are equal, false otherwise.
+ * True if the modes are (partially) equal, false otherwise.
  */
-bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
+bool drm_mode_match(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2,
+		    unsigned int match_flags)
 {
 	if (!mode1 && !mode2)
 		return true;
@@ -958,15 +1009,48 @@  bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_displ
 	if (!mode1 || !mode2)
 		return false;
 
-	/* do clock check convert to PICOS so fb modes get matched
-	 * the same */
-	if (mode1->clock && mode2->clock) {
-		if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
-			return false;
-	} else if (mode1->clock != mode2->clock)
+	if (match_flags & DRM_MODE_MATCH_TIMINGS &&
+	    !drm_mode_match_timings(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_CLOCK &&
+	    !drm_mode_match_clock(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_FLAGS &&
+	    !drm_mode_match_flags(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
+	    !drm_mode_match_3d_flags(mode1, mode2))
 		return false;
 
-	return drm_mode_equal_no_clocks(mode1, mode2);
+	if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
+	    !drm_mode_match_aspect_ratio(mode1, mode2))
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL(drm_mode_match);
+
+/**
+ * drm_mode_equal - test modes for equality
+ * @mode1: first mode
+ * @mode2: second mode
+ *
+ * Check to see if @mode1 and @mode2 are equivalent.
+ *
+ * Returns:
+ * True if the modes are equal, false otherwise.
+ */
+bool drm_mode_equal(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2)
+{
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_CLOCK |
+			      DRM_MODE_MATCH_FLAGS |
+			      DRM_MODE_MATCH_3D_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal);
 
@@ -981,13 +1065,13 @@  EXPORT_SYMBOL(drm_mode_equal);
  * Returns:
  * True if the modes are equal, false otherwise.
  */
-bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
+bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
+			      const struct drm_display_mode *mode2)
 {
-	if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
-	    (mode2->flags & DRM_MODE_FLAG_3D_MASK))
-		return false;
-
-	return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_FLAGS |
+			      DRM_MODE_MATCH_3D_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal_no_clocks);
 
@@ -1005,21 +1089,9 @@  EXPORT_SYMBOL(drm_mode_equal_no_clocks);
 bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
 					const struct drm_display_mode *mode2)
 {
-	if (mode1->hdisplay == mode2->hdisplay &&
-	    mode1->hsync_start == mode2->hsync_start &&
-	    mode1->hsync_end == mode2->hsync_end &&
-	    mode1->htotal == mode2->htotal &&
-	    mode1->hskew == mode2->hskew &&
-	    mode1->vdisplay == mode2->vdisplay &&
-	    mode1->vsync_start == mode2->vsync_start &&
-	    mode1->vsync_end == mode2->vsync_end &&
-	    mode1->vtotal == mode2->vtotal &&
-	    mode1->vscan == mode2->vscan &&
-	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
-	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
-		return true;
-
-	return false;
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
 
diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
index 9f3421c..839eb9c 100644
--- a/include/drm/drm_modes.h
+++ b/include/drm/drm_modes.h
@@ -150,6 +150,12 @@  enum drm_mode_status {
 
 #define DRM_MODE_FLAG_3D_MAX	DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
 
+#define DRM_MODE_MATCH_TIMINGS (1 << 0)
+#define DRM_MODE_MATCH_CLOCK (1 << 1)
+#define DRM_MODE_MATCH_FLAGS (1 << 2)
+#define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
+#define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
+
 /**
  * struct drm_display_mode - DRM kernel-internal display mode structure
  * @hdisplay: horizontal display size
@@ -493,6 +499,9 @@  void drm_mode_copy(struct drm_display_mode *dst,
 		   const struct drm_display_mode *src);
 struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
 					    const struct drm_display_mode *mode);
+bool drm_mode_match(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2,
+		    unsigned int match_flags);
 bool drm_mode_equal(const struct drm_display_mode *mode1,
 		    const struct drm_display_mode *mode2);
 bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,