drm/omapdrm: fbdev: Use client buffers
Subsystems (3)
Thomas Zimmermann
maintainercover drm/omapdrm: fbdev: Use client buffers
A client buffer holds the DRM framebuffer for an in-kernel DRM client. Until now, omapdrm created an internal ad-hoc framebuffer for its fbdev emulation, while by-passing the regular interfaces used by user-space compositors.
Convert omapdrm's fbdev emulation to use client buffers. Replacing the existing code with a client buffer allows for stream-lining omapdrm code and later also the fbdev helpers. The new framebuffer will be registered against the client's file and will support handles for GEM objects. It is then just another framebuffer within the DRM ecosystem.
If all driver's fbdev-emulation helpers can be converted to use client buffers, the emulation's framebuffer handling as a whole can possibly be moved into shared helpers.
Patches 1 and 2 convert omapdrm's fbdev emulation to client buffers. It still allocates a GEM object buffer tailored towards fbdev emulation, but size calculations now use common DRM helpers.
Patch 3 cleans up symbol visibility in omapdrm's fb code.
Thomas Zimmermann (3):
drm/omapdrm: fbdev: Calculate buffer geometry with format helpers drm/omapdrm: fbdev: Use a DRM client buffer drm/omapdrm: Make omap_framebuffer_init() an internal interface
drivers/gpu/drm/omapdrm/omap_fb.c | 68 +++++++++---------- drivers/gpu/drm/omapdrm/omap_fb.h | 3 - drivers/gpu/drm/omapdrm/omap_fbdev.c | 98 +++++++++++++++------------- 3 files changed, 88 insertions(+), 81 deletions(-)
Signature · 1 line
2.53.0
Thomas Zimmermann
maintainerPATCH 1/3 drm/omapdrm: fbdev: Calculate buffer geometry with format helpers
Replace the geometry and size calculation in omapdrm's fbdev emulation with DRM format helpers. This consists of a 4CC lookup from the fbdev parameters, format lookup, pitch calculation and size calculation.
Then allocate the GEM buffer object for the framebuffer memory from the calculated size. Mmap provides the allocated buffer to user space, so align the buffer size to PAGE_SIZE.
--- drivers/gpu/drm/omapdrm/omap_fbdev.c | 42 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 18 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +24 -18
@@ -5,6 +5,7 @@*/ #include <linux/fb.h> +#include <linux/overflow.h> #include <drm/clients/drm_client_setup.h> #include <drm/drm_drv.h>
@@ -155,6 +156,9 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,struct omap_drm_private *priv = dev->dev_private;struct omap_fbdev *fbdev = priv->fbdev;struct fb_info *fbi = helper->info; +u32 fourcc; +u64 pitch, size; +const struct drm_format_info *format;struct drm_framebuffer *fb =NULL ;union omap_gem_size gsize;struct drm_mode_fb_cmd2 mode_cmd = {0 };
@@ -169,24 +173,24 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, sizes->surface_height, sizes->surface_bpp, sizes->fb_width, sizes->fb_height); - mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, - sizes->surface_depth); - - mode_cmd.width = sizes->surface_width; - mode_cmd.height = sizes->surface_height; - - mode_cmd.pitches[0 ] = -DIV_ROUND_UP (mode_cmd.width * sizes->surface_bpp,8 ); - fbdev->ywrap_enabled = priv->has_dmm && ywrap_enabled; -if (fbdev->ywrap_enabled) { -/* need to align pitch to page size if using DMM scrolling */ - mode_cmd.pitches[0 ] =PAGE_ALIGN (mode_cmd.pitches[0 ]); - } + + fourcc =drm_mode_legacy_fb_format (sizes->surface_bpp, sizes->surface_depth); + format =drm_get_format_info (dev, fourcc,DRM_FORMAT_MOD_LINEAR ); +if (!format) +return -EINVAL ; + pitch =drm_format_info_min_pitch (format,0 , sizes->surface_width); +if (!pitch) +return -EINVAL ; +if (fbdev->ywrap_enabled) + pitch =PAGE_ALIGN (pitch);/* required if using DMM scrolling */ +if (check_mul_overflow (pitch, sizes->surface_height, &size)) +return -EINVAL ; + size =PAGE_ALIGN (size);/* allocate backing bo */ gsize = (union omap_gem_size ){ - .bytes =PAGE_ALIGN (mode_cmd.pitches[0 ] * mode_cmd.height), + .bytes = size, };DBG ("allocating %d bytes for fb %d" , gsize.bytes, dev->primary->index); bo =omap_gem_new (dev, gsize,OMAP_BO_SCANOUT |OMAP_BO_WC );
@@ -196,10 +200,12 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, goto fail; } - fb =omap_framebuffer_init (dev, -drm_get_format_info (dev, mode_cmd.pixel_format, - mode_cmd.modifier[0 ]), - &mode_cmd, &bo); + mode_cmd.pixel_format = fourcc; + mode_cmd.width = sizes->surface_width; + mode_cmd.height = sizes->surface_height; + mode_cmd.pitches[0 ] = pitch; + + fb =omap_framebuffer_init (dev, format, &mode_cmd, &bo);if (IS_ERR (fb)) {dev_err (dev->dev,"failed to allocate fb\n" );/* note: if fb creation failed, we can't rely on fb destroy
Signature · 1 line
2.53.0
Thomas Zimmermann
maintainerPATCH 2/3 drm/omapdrm: fbdev: Use a DRM client buffer
In reply to Thomas ZimmermannReplace the internal DRM framebuffer with a DRM client buffer. The client buffer allocates the DRM framebuffer on a file and also uses GEM object handles via the regular ADDFB2 interfaces.
Using client-buffer interfaces unifies framebuffer allocation for DRM clients in user space and omapdrm's internal fbdev emulation. It also simplifies the clean-up side of the fbdev emulation.
--- drivers/gpu/drm/omapdrm/omap_fbdev.c | 68 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 33 deletions(-)
drivers/gpu/drm/omapdrm/omap_fbdev.c +35 -33
@@ -93,8 +93,7 @@ static int omap_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)static void omap_fbdev_fb_destroy (struct fb_info *info) {struct drm_fb_helper *helper = info->par; -struct drm_framebuffer *fb = helper->fb; -struct drm_gem_object *bo =drm_gem_fb_get_obj (fb,0 ); +struct drm_gem_object *bo =drm_gem_fb_get_obj (helper->fb,0 );DBG ();
@@ -102,8 +101,8 @@ static void omap_fbdev_fb_destroy(struct fb_info *info)drm_fb_helper_fini (helper);omap_gem_unpin (bo); -drm_framebuffer_remove (fb); +drm_client_buffer_delete (helper->buffer);drm_client_release (&helper->client); }
@@ -152,18 +151,20 @@ static struct drm_fb_helper *get_fb(struct fb_info *fbi)int omap_fbdev_driver_fbdev_probe (struct drm_fb_helper *helper,struct drm_fb_helper_surface_size *sizes) { -struct drm_device *dev = helper->dev; +struct drm_client_dev *client = &helper->client; +struct drm_device *dev = client->dev; +struct drm_file *file = client->file;struct omap_drm_private *priv = dev->dev_private;struct omap_fbdev *fbdev = priv->fbdev;struct fb_info *fbi = helper->info;u32 fourcc;u64 pitch, size;const struct drm_format_info *format; -struct drm_framebuffer *fb =NULL ;union omap_gem_size gsize; -struct drm_mode_fb_cmd2 mode_cmd = {0 };struct drm_gem_object *bo; +struct drm_client_buffer *buffer;dma_addr_t dma_addr; +u32 handle;int ret; sizes->surface_bpp =32 ;
@@ -196,24 +197,18 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, bo =omap_gem_new (dev, gsize,OMAP_BO_SCANOUT |OMAP_BO_WC );if (!bo) {dev_err (dev->dev,"failed to allocate buffer object\n" ); - ret = -ENOMEM ; - goto fail; +return -ENOMEM ; } - mode_cmd.pixel_format = fourcc; - mode_cmd.width = sizes->surface_width; - mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0 ] = pitch; - - fb =omap_framebuffer_init (dev, format, &mode_cmd, &bo); -if (IS_ERR (fb)) { -dev_err (dev->dev,"failed to allocate fb\n" ); -/* note: if fb creation failed, we can't rely on fb destroy -* to unref the bo: -*/ -drm_gem_object_put (bo); - ret =PTR_ERR (fb); - goto fail; + ret =drm_gem_handle_create (file, bo, &handle); +if (ret) + goto err_drm_gem_object_put; + + buffer =drm_client_buffer_create (client, sizes->surface_width, sizes->surface_height, + fourcc, handle, pitch); +if (IS_ERR (buffer)) { + ret =PTR_ERR (buffer); + goto err_drm_gem_handle_delete; }/* note: this keeps the bo pinned.. which is perhaps not ideal,
@@ -228,13 +223,14 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,if (ret) {dev_err (dev->dev,"could not pin framebuffer\n" ); ret = -ENOMEM ; - goto fail; + goto err_drm_client_buffer_delete; }DBG ("fbi=%p, dev=%p" , fbi, dev); helper->funcs = &omap_fbdev_helper_funcs; - helper->fb = fb; + helper->buffer = buffer; + helper->fb = buffer->fb; fbi->fbops = &omap_fb_ops;
@@ -253,7 +249,7 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, fbi->fbdefio = &helper->fbdefio; ret =fb_deferred_io_init (fbi);if (ret) - goto fail; + goto err_omap_gem_unpin;/* if we have DMM, then we can use it for scrolling by just * shuffling pages around in DMM rather than doing sw blit.
@@ -264,19 +260,25 @@ int omap_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, fbi->fix.ywrapstep =1 ; } -DBG ("par=%p, %dx%d" , fbi->par, fbi->var.xres, fbi->var.yres); -DBG ("allocated %dx%d fb" , fb->width, fb->height); +DBG ("allocated %dx%d fb" , buffer->fb->width, buffer->fb->height); -return 0 ; +/* The handle is only needed for creating the framebuffer. */ +drm_gem_handle_delete (file, handle); -fail: +/* The framebuffer still holds a reference on the GEM object. */ +drm_gem_object_put (bo); -if (ret) { -if (fb) -drm_framebuffer_remove (fb); - } +return 0 ; +err_omap_gem_unpin: +omap_gem_unpin (bo); +err_drm_client_buffer_delete: +drm_client_buffer_delete (buffer); +err_drm_gem_handle_delete: +drm_gem_handle_delete (file, handle); +err_drm_gem_object_put: +drm_gem_object_put (bo);return ret; }
Signature · 1 line
2.53.0
Thomas Zimmermann
maintainerPATCH 3/3 drm/omapdrm: Make omap_framebuffer_init() an internal interface
In reply to Thomas ZimmermannThe only caller of omap_framebuffer_init() is omap_framebuffer_create() from the same source file. Declare the former as static. Reorder the functions to avoid forward declarations.
--- drivers/gpu/drm/omapdrm/omap_fb.c | 68 ++++++++++++++++--------------- drivers/gpu/drm/omapdrm/omap_fb.h | 3 -- 2 files changed, 35 insertions(+), 36 deletions(-)
drivers/gpu/drm/omapdrm/omap_fb.c +35 -33
@@ -335,39 +335,10 @@ void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m) }#endif -struct drm_framebuffer *omap_framebuffer_create (struct drm_device *dev, -struct drm_file *file,const struct drm_format_info *info, -const struct drm_mode_fb_cmd2 *mode_cmd) -{ -unsigned int num_planes = info->num_planes; -struct drm_gem_object *bos[4 ]; -struct drm_framebuffer *fb; -int i; - -for (i =0 ; i < num_planes; i++) { - bos[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); -if (!bos[i]) { - fb =ERR_PTR (-ENOENT ); - goto error; - } - } - - fb =omap_framebuffer_init (dev, info, mode_cmd, bos); -if (IS_ERR (fb)) - goto error; - -return fb; - -error: -while (--i >=0 ) -drm_gem_object_put (bos[i]); - -return fb; -} - -struct drm_framebuffer *omap_framebuffer_init (struct drm_device *dev, -const struct drm_format_info *info, -const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **bos) +static struct drm_framebuffer * +omap_framebuffer_init (struct drm_device *dev, +const struct drm_format_info *info, +const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **bos) {struct omap_framebuffer *omap_fb =NULL ;struct drm_framebuffer *fb =NULL ;
@@ -455,3 +426,34 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,return ERR_PTR (ret); } + +struct drm_framebuffer *omap_framebuffer_create (struct drm_device *dev, +struct drm_file *file, +const struct drm_format_info *info, +const struct drm_mode_fb_cmd2 *mode_cmd) +{ +unsigned int num_planes = info->num_planes; +struct drm_gem_object *bos[4 ]; +struct drm_framebuffer *fb; +int i; + +for (i =0 ; i < num_planes; i++) { + bos[i] =drm_gem_object_lookup (file, mode_cmd->handles[i]); +if (!bos[i]) { + fb =ERR_PTR (-ENOENT ); + goto error; + } + } + + fb =omap_framebuffer_init (dev, info, mode_cmd, bos); +if (IS_ERR (fb)) + goto error; + +return fb; + +error: +while (--i >=0 ) +drm_gem_object_put (bos[i]); + +return fb; +}
drivers/gpu/drm/omapdrm/omap_fb.h +0 -3
@@ -23,9 +23,6 @@ struct seq_file;struct drm_framebuffer *omap_framebuffer_create (struct drm_device *dev,struct drm_file *file,const struct drm_format_info *info,const struct drm_mode_fb_cmd2 *mode_cmd); -struct drm_framebuffer *omap_framebuffer_init (struct drm_device *dev, -const struct drm_format_info *info, -const struct drm_mode_fb_cmd2 *mode_cmd,struct drm_gem_object **bos);int omap_framebuffer_pin (struct drm_framebuffer *fb);void omap_framebuffer_unpin (struct drm_framebuffer *fb); void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
Signature · 1 line
2.53.0
Thomas Zimmermann
maintainerping for a review
Am 23.04.26 um 15:58 schrieb Thomas Zimmermann:
Quoted 31 lines
A client buffer holds the DRM framebuffer for an in-kernel DRM client. Until now, omapdrm created an internal ad-hoc framebuffer for its fbdev emulation, while by-passing the regular interfaces used by user-space compositors.
Convert omapdrm's fbdev emulation to use client buffers. Replacing the existing code with a client buffer allows for stream-lining omapdrm code and later also the fbdev helpers. The new framebuffer will be registered against the client's file and will support handles for GEM objects. It is then just another framebuffer within the DRM ecosystem.
If all driver's fbdev-emulation helpers can be converted to use client buffers, the emulation's framebuffer handling as a whole can possibly be moved into shared helpers.
Patches 1 and 2 convert omapdrm's fbdev emulation to client buffers. It still allocates a GEM object buffer tailored towards fbdev emulation, but size calculations now use common DRM helpers.
Patch 3 cleans up symbol visibility in omapdrm's fb code.
Thomas Zimmermann (3):
drm/omapdrm: fbdev: Calculate buffer geometry with format helpers drm/omapdrm: fbdev: Use a DRM client buffer drm/omapdrm: Makeomap_framebuffer_init()an internal interfacedrivers/gpu/drm/omapdrm/omap_fb.c | 68 +++++++++---------- drivers/gpu/drm/omapdrm/omap_fb.h | 3 - drivers/gpu/drm/omapdrm/omap_fbdev.c | 98 +++++++++++++++------------- 3 files changed, 88 insertions(+), 81 deletions(-)
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
Thomas Zimmermann
maintainerping for a review
Am 23.04.26 um 15:58 schrieb Thomas Zimmermann:
Quoted 31 lines
A client buffer holds the DRM framebuffer for an in-kernel DRM client. Until now, omapdrm created an internal ad-hoc framebuffer for its fbdev emulation, while by-passing the regular interfaces used by user-space compositors.
Convert omapdrm's fbdev emulation to use client buffers. Replacing the existing code with a client buffer allows for stream-lining omapdrm code and later also the fbdev helpers. The new framebuffer will be registered against the client's file and will support handles for GEM objects. It is then just another framebuffer within the DRM ecosystem.
If all driver's fbdev-emulation helpers can be converted to use client buffers, the emulation's framebuffer handling as a whole can possibly be moved into shared helpers.
Patches 1 and 2 convert omapdrm's fbdev emulation to client buffers. It still allocates a GEM object buffer tailored towards fbdev emulation, but size calculations now use common DRM helpers.
Patch 3 cleans up symbol visibility in omapdrm's fb code.
Thomas Zimmermann (3):
drm/omapdrm: fbdev: Calculate buffer geometry with format helpers drm/omapdrm: fbdev: Use a DRM client buffer drm/omapdrm: Makeomap_framebuffer_init()an internal interfacedrivers/gpu/drm/omapdrm/omap_fb.c | 68 +++++++++---------- drivers/gpu/drm/omapdrm/omap_fb.h | 3 - drivers/gpu/drm/omapdrm/omap_fbdev.c | 98 +++++++++++++++------------- 3 files changed, 88 insertions(+), 81 deletions(-)
Signature · 6 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)