All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [RFC 2/7] drm: Add GEM backed framebuffer library
Date: Fri, 21 Jul 2017 20:39:17 +0200	[thread overview]
Message-ID: <41e632ff-e480-564a-1971-720d65ca2154@tronnes.org> (raw)
In-Reply-To: <20170720081036.nyc73hb7yf2hy7aw@phenom.ffwll.local>


Den 20.07.2017 10.10, skrev Daniel Vetter:
> On Tue, Jul 18, 2017 at 05:42:28PM +0200, Noralf Trønnes wrote:
>> Den 12.07.2017 15.46, skrev Noralf Trønnes:
>>> Add a library for drivers that can use a simple representation
>>> of a GEM backed framebuffer.
>>>
>>> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
>>> ---
>> This patch adds a gem backed drm_framebuffer like this:
>>
>> struct drm_fb_gem {
>>      /**
>>       * @base: Base DRM framebuffer
>>       */
>>      struct drm_framebuffer base;
>>      /**
>>       * @obj: GEM object array backing the framebuffer. One object per
>>       * plane.
>>       */
>>      struct drm_gem_object *obj[4];
>> };
>>
>> Now I wonder if it would be better to extend drm_framebuffer instead:
>>
>>   struct drm_framebuffer {
>> +    /**
>> +     * @obj: GEM objects backing the framebuffer, one per plane (optional).
>> +     */
>> +    struct drm_gem_object *obj[4];
>>   };
> I think we can directly embedd the gem obj pointers into the
> drm_framebuffer. Again the idea that there would be anything else than gem
> kinda didn't pan out, except for vmwgfx.
>
> We could then have a gem version of drm_helper_mode_fill_fb_struct(),
> which also does the gem bo lookups.

How about this, I've copied from drm_fb_cma_create_with_funcs():

/**
  * drm_helper_mode_fill_fb_gem - fill out framebuffer metadata and 
lookup GEM
  * @dev: DRM device
  * @file_priv: DRM file to lookup buffers from
  * @fb: drm_framebuffer object to fill out
  * @mode_cmd: metadata from the userspace fb creation request
  *
  * This helper can be used in a drivers fb_create callback to pre-fill 
the fb's
  * metadata fields and lookup the GEM buffer object(s).
  *
  * Returns:
  * 0 on success or a negative error code on failure.
  */
int drm_helper_mode_fill_fb_gem(struct drm_device *dev,
                 struct drm_file *file_priv,
                 struct drm_framebuffer *fb,
                 const struct drm_mode_fb_cmd2 *mode_cmd)
{
     int i, ret;

     drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
     if (!fb->format)
         return -EINVAL;

     for (i = 0; i < fb->format->num_planes; i++) {
         unsigned int width = mode_cmd->width /
                      (i ? fb->format->hsub : 1);
         unsigned int height = mode_cmd->height /
                       (i ? fb->format->vsub : 1);
         unsigned int min_size;

         fb->objs[i] = drm_gem_object_lookup(file_priv,
                             mode_cmd->handles[i]);
         if (!fb->objs[i]) {
             ret = -ENOENT;
             goto err_gem_object_put;
         }

         min_size = (height - 1) * mode_cmd->pitches[i] +
                width * fb->format->cpp[i] + mode_cmd->offsets[i];

         if (fb->objs[i]->size < min_size) {
             drm_gem_object_put_unlocked(fb->objs[i]);
             fb->objs[i] = NULL;
             ret = -EINVAL;
             goto err_gem_object_put;
         }
     }

err_gem_object_put:
     for (i--; i >= 0; i--) {
         drm_gem_object_put_unlocked(fb->objs[i]);
         fb->objs[i] = NULL;
     }

     return ret;
}
EXPORT_SYMBOL(drm_helper_mode_fill_fb_gem);

>> The reason for this, is that I have looked through all drivers that
>> subclass drm_framebuffer and found this:
>> - 11 drivers just adds drm_gem_object
> Usually that's because they don't support yuv, so only need one plane.
>
>> - 2 drivers adds drm_gem_object and some more
>> - 6 drivers adds drm_gem_object indirectly through their subclassed
>>    drm_gem_object
>> - 3 drivers doesn't add drm_gem_object
> I think for easier conversion we can leave all the driver-specific stuff
> intact, and just provide helpers that work on the core bits.
>
> I guess this would also help a lot with unifying the cma fb helpers by
> essentially making them fully generic gem fb helpers?

Yes both cma and shmem library can now use these helpers. But pushing
the helpers all the way out to the cma drivers will be too much for me.

Any chance the fbdev helper could get a struct drm_file?
It would be nice to use drm_driver.dumb_create and
drm_mode_config_funcs.fb_create to get a
framebuffer for fbdev.

Noralf.

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-07-21 18:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 13:45 [RFC 0/7] drm: Add shmem GEM library Noralf Trønnes
2017-07-12 13:45 ` [RFC 1/7] drm/gem: Add drm_gem_dumb_map_offset() Noralf Trønnes
2017-07-18 21:06   ` Noralf Trønnes
2017-07-20  8:04     ` Daniel Vetter
2017-07-19 21:01   ` Eric Anholt
2017-07-19 22:13     ` Noralf Trønnes
2017-07-20  8:00       ` Daniel Vetter
2017-07-21 18:41         ` Noralf Trønnes
2017-07-24  8:28           ` Daniel Vetter
2017-07-24 19:41             ` Noralf Trønnes
2017-07-12 13:46 ` [RFC 2/7] drm: Add GEM backed framebuffer library Noralf Trønnes
2017-07-18 15:42   ` Noralf Trønnes
2017-07-19 20:59     ` Eric Anholt
2017-07-20  8:10     ` Daniel Vetter
2017-07-21 18:39       ` Noralf Trønnes [this message]
2017-07-25  7:00         ` Daniel Vetter
2017-07-12 13:46 ` [RFC 3/7] drm/fb-helper: Support shadow buffer with deferred io Noralf Trønnes
2017-07-12 13:46 ` [RFC 4/7] drm/fb-helper: Add simple init/fini functions Noralf Trønnes
2017-07-12 13:46 ` [RFC 5/7] drm: Add library for shmem backed GEM objects Noralf Trønnes
2017-07-12 13:46 ` [RFC 6/7] drm: Add kms library for shmem backed GEM Noralf Trønnes
2017-07-12 13:46 ` [RFC 7/7] drm/tinydrm: Switch from CMA to shmem buffers Noralf Trønnes

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=41e632ff-e480-564a-1971-720d65ca2154@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=daniel@ffwll.ch \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.