dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH v2 1/3] drm: Make sure at least one plane supports the fb format
Date: Tue, 6 Mar 2018 14:54:50 +0200	[thread overview]
Message-ID: <20180306125450.GG5453@intel.com> (raw)
In-Reply-To: <20180306115726.GD5453@intel.com>

On Tue, Mar 06, 2018 at 01:57:26PM +0200, Ville Syrjälä wrote:
> On Mon, Mar 05, 2018 at 11:41:02PM +0200, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > To make life easier for drivers, let's have the core check that the
> > requested pixel format is supported by at least one plane when creating
> > a new framebuffer.
> > 
> > v2: Accept anyformat if the driver doesn't do planes (Eric)
> >     s/planes_have_format/any_plane_has_format/ (Eric)
> >     Check the modifier as well since we already have a function
> >     that does both
> > 
> > Cc: Eric Anholt <eric@anholt.net>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/drm_framebuffer.c | 43 +++++++++++++++++++++++++++++++--------
> >  1 file changed, 35 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> > index c0530a1af5e3..b9a33e3f13e9 100644
> > --- a/drivers/gpu/drm/drm_framebuffer.c
> > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > @@ -152,12 +152,37 @@ static int fb_plane_height(int height,
> >  	return DIV_ROUND_UP(height, format->vsub);
> >  }
> >  
> > +static bool any_plane_has_format(struct drm_device *dev,
> > +				 u32 format, u64 modifier)
> > +{
> > +	struct drm_plane *plane;
> > +
> > +	/* TODO: maybe maintain a device level format list? */
> > +	drm_for_each_plane(plane, dev) {
> > +		/*
> > +		 * In case the driver doesn't really do
> > +		 * planes we have to accept any format here.
> > +		 */
> > +		if (plane->format_default)
> > +			return true;
> > +
> > +		if (drm_plane_check_pixel_format(plane, format, modifier) == 0)
> > +			return true;
> > +	}
> > +
> > +	return false;
> > +}
> > +
> >  static int framebuffer_check(struct drm_device *dev,
> >  			     const struct drm_mode_fb_cmd2 *r)
> >  {
> >  	const struct drm_format_info *info;
> > +	u64 modifier = 0;
> >  	int i;
> >  
> > +	if (r->flags & DRM_MODE_FB_MODIFIERS)
> > +		modifier = r->modifier[0];
> 
> And of course this isn't quite correct. For the !modifiers case we're
> now checking if any plane supports the format with the linear modifier,
> but the actual modifier will only be picked by the driver later.
> 
> Not quite sure how I would write this in a way that really makes
> sense. Might have to make it the driver's responsibility to call
> any_plane_has_format() instead...

Hmm. One idea would be to stick the check into drm_framebuffer_init(),
but I'm not comfortable with that since the driver may well be doing
things in its .fb_create() hook that expects the format+modifier to
have been validated already, and drm_framebuffer_init() should only be
called once everything is ready.

I guess I'll just export drm_any_plane_has_format() and add some
kerneldoc for .fb_create() to let people know about it. Better ideas
are welcome of course.

> 
> > +
> >  	/* check if the format is supported at all */
> >  	info = __drm_format_info(r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN);
> >  	if (!info) {
> > @@ -168,6 +193,15 @@ static int framebuffer_check(struct drm_device *dev,
> >  		return -EINVAL;
> >  	}
> >  
> > +	if (!any_plane_has_format(dev, r->pixel_format, modifier)) {
> > +		struct drm_format_name_buf format_name;
> > +
> > +		DRM_DEBUG_KMS("unsupported pixel format %s, modifier 0x%llx\n",
> > +			      drm_get_format_name(r->pixel_format, &format_name),
> > +			      modifier);
> > +		return -EINVAL;
> > +	}
> > +
> >  	/* now let the driver pick its own format info */
> >  	info = drm_get_format_info(dev, r);
> >  
> > @@ -202,14 +236,7 @@ static int framebuffer_check(struct drm_device *dev,
> >  			return -EINVAL;
> >  		}
> >  
> > -		if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
> > -			DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
> > -				      r->modifier[i], i);
> > -			return -EINVAL;
> > -		}
> > -
> > -		if (r->flags & DRM_MODE_FB_MODIFIERS &&
> > -		    r->modifier[i] != r->modifier[0]) {
> > +		if (r->modifier[i] != modifier) {
> >  			DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
> >  				      r->modifier[i], i);
> >  			return -EINVAL;
> > -- 
> > 2.16.1
> > 
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> -- 
> Ville Syrjälä
> Intel OTC

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

      reply	other threads:[~2018-03-06 12:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-05 14:49 [PATCH 1/3] drm: Make sure at least one plane supports the fb format Ville Syrjala
2018-03-05 14:49 ` [PATCH 2/3] drm/i915: Eliminate the horrendous format check code Ville Syrjala
2018-03-05 21:41   ` [PATCH v2 " Ville Syrjala
2018-03-05 14:49 ` [PATCH 3/3] drm: Fix some coding style issues Ville Syrjala
2018-03-06 10:31   ` Daniel Vetter
2018-03-05 20:59 ` [Intel-gfx] [PATCH 1/3] drm: Make sure at least one plane supports the fb format Eric Anholt
2018-03-05 21:15   ` Ville Syrjälä
2018-03-05 21:33     ` Alex Deucher
2018-03-05 22:44       ` [Intel-gfx] " Harry Wentland
2018-03-06 10:09         ` Ville Syrjälä
2018-03-06 10:35         ` [Intel-gfx] " Daniel Vetter
2018-03-06 16:12           ` Harry Wentland
2018-03-05 22:56     ` Eric Anholt
2018-03-05 21:41 ` [PATCH v2 " Ville Syrjala
2018-03-06 11:57   ` [Intel-gfx] " Ville Syrjälä
2018-03-06 12:54     ` Ville Syrjälä [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180306125450.GG5453@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox