dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3] DRM: Add DRM kms/fb cma helper
Date: Thu, 19 Jul 2012 15:31:45 +0200	[thread overview]
Message-ID: <4616520.LXHlBWndsQ@avalon> (raw)
In-Reply-To: <3176651.XRgMMYj3qf@avalon>

On Thursday 19 July 2012 14:46:38 Laurent Pinchart wrote:
> On Monday 02 July 2012 16:37:47 Lars-Peter Clausen wrote:
> > This patchset introduces a set of helper function for implementing the KMS
> > framebuffer layer for drivers which use the drm gem CMA helper function.
> > 
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> > 
> > ---
> > Note: This patch depends on Sascha's "DRM: add drm gem CMA helper" patch
> > 
> > Changes since v2:
> > 	* Adapt to changes in the GEM CMA helper
> > 	* Add basic buffer size checking in drm_fb_cma_create
> > 
> > Changes since v1:
> > 	* Some spelling fixes
> > 	* Add missing kfree in drm_fb_cma_alloc error path
> > 	* Add multi-plane support
> > 
> > ---
> > 
> >  drivers/gpu/drm/Kconfig             |   10 +
> >  drivers/gpu/drm/Makefile            |    1 +
> >  drivers/gpu/drm/drm_fb_cma_helper.c |  393
> >  ++++++++++++++++++++++++++++++++
> >  include/drm/drm_fb_cma_helper.h     |   27 +++
> >  4 files changed, 431 insertions(+)
> >  create mode 100644 drivers/gpu/drm/drm_fb_cma_helper.c
> >  create mode 100644 include/drm/drm_fb_cma_helper.h
> 
> [snip]
> 
> > diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c
> > b/drivers/gpu/drm/drm_fb_cma_helper.c new file mode 100644
> > index 0000000..9042233
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_fb_cma_helper.c
> 
> [snip]
> 
> > +/**
> > + * drm_fb_cma_create() - (struct drm_mode_config_funcs *)->fb_create
> > callback function
> > + *
> > + * If your hardware has special alignment or pitch requirements these
> > should be
> > + * checked before calling this function.
> > + */
> > +struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev,
> > +	struct drm_file *file_priv, struct drm_mode_fb_cmd2 *mode_cmd)
> > +{
> > +	struct drm_fb_cma *fb_cma;
> > +	struct drm_gem_cma_object *objs[4];
> > +	struct drm_gem_object *obj;
> > +	int ret;
> > +	int i;
> > +
> > +	for (i = 0; i < drm_format_num_planes(mode_cmd->pixel_format); i++) {
> > +		obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[i]);
> > +		if (!obj) {
> > +			dev_err(dev->dev, "Failed to lookup GEM object\n");
> > +			ret = -ENXIO;
> > +			goto err_gem_object_unreference;
> > +		}
> > +
> > +		if (obj->size < mode_cmd->height * mode_cmd->pitches[i]) {
> 
> Shouldn't this be
> 
> if (obj->size < mode_cmd->height * mode_cmd->pitches[i]
>               + mode_cmd->offsets[i])
> 
> ?

And, for multiplanar formats, we need to divide height by the plane vertical
subsampling factor. What about something like this ?

        struct drm_fb_cma *fb_cma;
        struct drm_gem_cma_object *objs[4];
        struct drm_gem_object *obj;
        int ret;
        int i;

        for (i = 0; i < drm_format_num_planes(mode_cmd->pixel_format); i++) {
                unsigned int min_size;

                obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[i]);
                if (!obj) {
                        dev_err(dev->dev, "Failed to lookup GEM object\n");
                        ret = -ENXIO;
                        goto err_gem_object_unreference;
                }

                min_size = mode_cmd->pitches[i] * mode_cmd->height;
                if (i)
                        min_size /= drm_format_vert_chroma_subsampling(mode_cmd->pixel_format);
                min_size += mode_cmd->offsets[i];

                if (obj->size < min_size) {
                        drm_gem_object_unreference_unlocked(obj);
                        ret = -EINVAL;
                        goto err_gem_object_unreference;
                }
                objs[i] = to_drm_gem_cma_obj(obj);
        }

On a totally unrelated note, I'm wondering whether we should replace the
various DRM format information calls (drm_format_num_planes,
drm_fb_get_bpp_depth, ...) by a single drm_get_format_info() function that
would return a const pointer to format information. We could keep the existing
API as static inline functions. This would save CPU time when we need to
repeatedly access various information about a single format.

> > +			drm_gem_object_unreference_unlocked(obj);
> > +			ret = -EINVAL;
> > +			goto err_gem_object_unreference;
> > +		}
> > +		objs[i] = to_drm_gem_cma_obj(obj);
> > +	}
> > +
> > +	fb_cma = drm_fb_cma_alloc(dev, mode_cmd, objs, i);
> > +	if (IS_ERR(fb_cma)) {
> > +		ret = PTR_ERR(fb_cma);
> > +		goto err_gem_object_unreference;
> > +	}
> > +
> > +	return &fb_cma->fb;
> > +
> > +err_gem_object_unreference:
> > +	for (i--; i >= 0; i--)
> > +		drm_gem_object_unreference_unlocked(&objs[i]->base);
> > +	return ERR_PTR(ret);
> > +}
> > +EXPORT_SYMBOL_GPL(drm_fb_cma_create);

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2012-07-19 13:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-02 14:37 [PATCH v3] DRM: Add DRM kms/fb cma helper Lars-Peter Clausen
2012-07-11 18:53 ` Sascha Hauer
2012-07-19 12:46 ` Laurent Pinchart
2012-07-19 13:31   ` Laurent Pinchart [this message]
2012-07-19 13:34   ` Lars-Peter Clausen
2012-07-19 13:33     ` Laurent Pinchart
2012-07-19 13:55       ` Lars-Peter Clausen
2012-07-19 14:02         ` Laurent Pinchart
2012-07-19 14:41           ` Laurent Pinchart
2012-07-19 14:57             ` Lars-Peter Clausen
2012-07-19 15:01               ` Lars-Peter Clausen
2012-07-19 15:01               ` Laurent Pinchart
2012-07-19 15:36                 ` Lars-Peter Clausen
2012-07-19 15:12               ` Lars-Peter Clausen
2012-07-19 15:46                 ` Laurent Pinchart
2012-07-19 16:01                   ` Lars-Peter Clausen
2012-08-08 14:43 ` Laurent Pinchart

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=4616520.LXHlBWndsQ@avalon \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dri-devel@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