drm/exynos: fbdev: Use client buffers
Subsystems (4)
v2 cover drm/exynos: fbdev: Use client buffers
A client buffer holds the DRM framebuffer for an in-kernel DRM client. Until now, exynos created an internal ad-hoc framebuffer for its fbdev emulation, while by-passing the regular interfaces used by user-space compositors.
Convert exynos' fbdev emulation to use client buffers. Replacing the existing code with a client buffer allows for stream-lining exynos 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.
Patch 1 first fixes a long-standing bug.
Patches 2 to 4 convert exynos' 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 5 cleans up symbol visibility in exynos' fb code.
v2:
- clean up exynos fb header (Chen-Yu)
Thomas Zimmermann (5):
drm/exynos: fbdev: Remove offset into screen_buffer drm/exynos: fbdev: Inline exynos_drm_fbdev_update() drm/exynos: fbdev: Calculate buffer geometry with format helpers drm/exynos: fbdev: Use a DRM client buffer
drm/exynos: Make exynos_drm_framebuffer_init() an internal interface
drivers/gpu/drm/exynos/exynos_drm_fb.c | 3 +- drivers/gpu/drm/exynos/exynos_drm_fb.h | 10 +-- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 101 ++++++++++------------ 3 files changed, 52 insertions(+), 62 deletions(-)
base-commit: 94d56a898a2db27f841b17f6966a81ba502fe63c
Signature · 1 line
2.54.0
PATCH v2 1/5 drm/exynos: fbdev: Remove offset into screen_buffer
The screen_buffer field in struct fb_info contains the kernel address of the first byte of framebuffer memory. Do not add the display offset. This offset only describes scrolling during scanout.
--- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -5
@@ -61,17 +61,13 @@ static int exynos_drm_fbdev_update(struct drm_fb_helper *helper,struct fb_info *fbi = helper->info;struct drm_framebuffer *fb = helper->fb;unsigned int size = fb->width * fb->height * fb->format->cpp[0 ]; -unsigned long offset; fbi->fbops = &exynos_drm_fb_ops;drm_fb_helper_fill_info (fbi, helper, sizes); - offset = fbi->var.xoffset * fb->format->cpp[0 ]; - offset += fbi->var.yoffset * fb->pitches[0 ]; - fbi->flags |=FBINFO_VIRTFB ; - fbi->screen_buffer = exynos_gem->kvaddr + offset; + fbi->screen_buffer = exynos_gem->kvaddr; fbi->screen_size = size; fbi->fix.smem_len = size;
Signature · 1 line
2.54.0
PATCH v2 2/5 drm/exynos: fbdev: Inline exynos_drm_fbdev_update()
In reply to Thomas ZimmermannInline exynos_drm_fbdev_update() into its only caller. Prepares the code for using DRM client buffers.
--- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 35 ++++++----------------- 1 file changed, 9 insertions(+), 26 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +9 -26
@@ -54,26 +54,6 @@ static const struct fb_ops exynos_drm_fb_ops = { .fb_destroy = exynos_drm_fb_destroy, }; -static int exynos_drm_fbdev_update (struct drm_fb_helper *helper, -struct drm_fb_helper_surface_size *sizes, -struct exynos_drm_gem *exynos_gem) -{ -struct fb_info *fbi = helper->info; -struct drm_framebuffer *fb = helper->fb; -unsigned int size = fb->width * fb->height * fb->format->cpp[0 ]; - - fbi->fbops = &exynos_drm_fb_ops; - -drm_fb_helper_fill_info (fbi, helper, sizes); - - fbi->flags |=FBINFO_VIRTFB ; - fbi->screen_buffer = exynos_gem->kvaddr; - fbi->screen_size = size; - fbi->fix.smem_len = size; - -return 0 ; -} -static const struct drm_fb_helper_funcs exynos_drm_fbdev_helper_funcs = { };
@@ -82,6 +62,7 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, {struct exynos_drm_gem *exynos_gem;struct drm_device *dev = helper->dev; +struct fb_info *info = helper->info;struct drm_mode_fb_cmd2 mode_cmd = {0 };unsigned long size;int ret;
@@ -115,15 +96,17 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, } helper->funcs = &exynos_drm_fbdev_helper_funcs; - ret =exynos_drm_fbdev_update (helper, sizes, exynos_gem); -if (ret <0 ) - goto err_destroy_framebuffer; + info->fbops = &exynos_drm_fb_ops; + +drm_fb_helper_fill_info (info, helper, sizes); + + info->flags |=FBINFO_VIRTFB ; + info->screen_buffer = exynos_gem->kvaddr; + info->screen_size = size; + info->fix.smem_len = size;return 0 ; -err_destroy_framebuffer: -drm_framebuffer_cleanup (helper->fb); - helper->fb =NULL ; err_destroy_gem:exynos_drm_gem_destroy (exynos_gem);return ret;
Signature · 1 line
2.54.0
PATCH v2 3/5 drm/exynos: fbdev: Calculate buffer geometry with format helpers
In reply to Thomas ZimmermannReplace the geometry and size calculation in exynos' 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.
Initialize the fields screen_size and fix.smem_len in struct fb_info from the size of the allocated buffer object. This is the real size and can differ from the requested size.
--- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 35 ++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +19 -16
@@ -60,11 +60,14 @@ static const struct drm_fb_helper_funcs exynos_drm_fbdev_helper_funcs = {int exynos_drm_fbdev_driver_fbdev_probe (struct drm_fb_helper *helper,struct drm_fb_helper_surface_size *sizes) { -struct exynos_drm_gem *exynos_gem;struct drm_device *dev = helper->dev;struct fb_info *info = helper->info; +u32 fourcc, pitch; +u64 size; +const struct drm_format_info *format; +struct exynos_drm_gem *exynos_gem; +struct drm_gem_object *obj;struct drm_mode_fb_cmd2 mode_cmd = {0 }; -unsigned long size;int ret; DRM_DEV_DEBUG_KMS(dev->dev,
@@ -72,23 +75,23 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, sizes->surface_width, sizes->surface_height, sizes->surface_bpp); - mode_cmd.width = sizes->surface_width; - mode_cmd.height = sizes->surface_height; - mode_cmd.pitches[0 ] = sizes->surface_width * (sizes->surface_bpp >>3 ); - mode_cmd.pixel_format =drm_mode_legacy_fb_format (sizes->surface_bpp, - sizes->surface_depth); - - size = mode_cmd.pitches[0 ] * mode_cmd.height; + fourcc =drm_mode_legacy_fb_format (sizes->surface_bpp, sizes->surface_depth); + format =drm_get_format_info (dev, fourcc,DRM_FORMAT_MOD_LINEAR ); + pitch =drm_format_info_min_pitch (format,0 , sizes->surface_width); + size =ALIGN (pitch * sizes->surface_height,PAGE_SIZE ); exynos_gem =exynos_drm_gem_create (dev,EXYNOS_BO_WC , size, true);if (IS_ERR (exynos_gem))return PTR_ERR (exynos_gem); + obj = &exynos_gem->base; + + mode_cmd.width = sizes->surface_width; + mode_cmd.height = sizes->surface_height; + mode_cmd.pixel_format = fourcc; + mode_cmd.pitches[0 ] = pitch; + mode_cmd.modifier[0 ] =DRM_FORMAT_MOD_LINEAR ; - helper->fb = -exynos_drm_framebuffer_init (dev, -drm_get_format_info (dev, mode_cmd.pixel_format, - mode_cmd.modifier[0 ]), - &mode_cmd, &exynos_gem,1 ); + helper->fb =exynos_drm_framebuffer_init (dev, format, &mode_cmd, &exynos_gem,1 );if (IS_ERR (helper->fb)) {DRM_DEV_ERROR (dev->dev,"failed to create drm framebuffer.\n" ); ret =PTR_ERR (helper->fb);
@@ -102,8 +105,8 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, info->flags |=FBINFO_VIRTFB ; info->screen_buffer = exynos_gem->kvaddr; - info->screen_size = size; - info->fix.smem_len = size; + info->screen_size = obj->size; + info->fix.smem_len = obj->size;return 0 ;
Signature · 1 line
2.54.0
PATCH v2 4/5 drm/exynos: 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 exynos' internal fbdev emulation. It also simplifies the clean-up side of the fbdev emulation.
--- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 46 ++++++++++++++--------- 1 file changed, 28 insertions(+), 18 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +28 -18
@@ -36,12 +36,10 @@ static int exynos_drm_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)static void exynos_drm_fb_destroy (struct fb_info *info) {struct drm_fb_helper *fb_helper = info->par; -struct drm_framebuffer *fb = fb_helper->fb;drm_fb_helper_fini (fb_helper); -drm_framebuffer_remove (fb); - +drm_client_buffer_delete (fb_helper->buffer);drm_client_release (&fb_helper->client); }
@@ -60,14 +58,17 @@ static const struct drm_fb_helper_funcs exynos_drm_fbdev_helper_funcs = {int exynos_drm_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 fb_info *info = helper->info;u32 fourcc, pitch;u64 size;const struct drm_format_info *format;struct exynos_drm_gem *exynos_gem;struct drm_gem_object *obj; -struct drm_mode_fb_cmd2 mode_cmd = {0 }; +struct drm_client_buffer *buffer; +u32 handle;int ret; DRM_DEV_DEBUG_KMS(dev->dev,
@@ -85,19 +86,20 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper,return PTR_ERR (exynos_gem); obj = &exynos_gem->base; - mode_cmd.width = sizes->surface_width; - mode_cmd.height = sizes->surface_height; - mode_cmd.pixel_format = fourcc; - mode_cmd.pitches[0 ] = pitch; - mode_cmd.modifier[0 ] =DRM_FORMAT_MOD_LINEAR ; - - helper->fb =exynos_drm_framebuffer_init (dev, format, &mode_cmd, &exynos_gem,1 ); -if (IS_ERR (helper->fb)) { -DRM_DEV_ERROR (dev->dev,"failed to create drm framebuffer.\n" ); - ret =PTR_ERR (helper->fb); - goto err_destroy_gem; + ret =drm_gem_handle_create (file, obj, &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; } + helper->funcs = &exynos_drm_fbdev_helper_funcs; + helper->buffer = buffer; + helper->fb = buffer->fb; info->fbops = &exynos_drm_fb_ops;
@@ -108,9 +110,17 @@ int exynos_drm_fbdev_driver_fbdev_probe(struct drm_fb_helper *helper, info->screen_size = obj->size; info->fix.smem_len = obj->size; +/* The handle is only needed for creating the framebuffer. */ +drm_gem_handle_delete (file, handle); + +/* The framebuffer still holds a reference on the GEM object. */ +drm_gem_object_put (obj); +return 0 ; -err_destroy_gem: -exynos_drm_gem_destroy (exynos_gem); +err_drm_gem_handle_delete: +drm_gem_handle_delete (file, handle); +err_drm_gem_object_put: +drm_gem_object_put (obj);return ret; }
Signature · 1 line
2.54.0
PATCH v2 5/5 drm/exynos: Make exynos_drm_framebuffer_init() an internal interface
In reply to Thomas ZimmermannThe only caller of exynos_drm_framebuffer_init() is the helper exynos_user_fb_create() from the same source file. Declare the former as static. Tidy up the header's include statements.
v2:
- clean up the includes in the header file (Chen-Yu)
--- drivers/gpu/drm/exynos/exynos_drm_fb.c | 3 ++- drivers/gpu/drm/exynos/exynos_drm_fb.h | 10 +++------- drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 1 + 3 files changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fb.c +2 -1
@@ -22,6 +22,7 @@#include "exynos_drm_drv.h" #include "exynos_drm_fb.h" #include "exynos_drm_fbdev.h" +#include "exynos_drm_gem.h" static int check_fb_gem_memory_type (struct drm_device *drm_dev,struct exynos_drm_gem *exynos_gem)
@@ -55,7 +56,7 @@ static const struct drm_framebuffer_funcs exynos_drm_fb_funcs = { .create_handle = drm_gem_fb_create_handle, }; -struct drm_framebuffer * +static struct drm_framebuffer * exynos_drm_framebuffer_init(struct drm_device *dev, const struct drm_format_info *info, const struct drm_mode_fb_cmd2 *mode_cmd,
drivers/gpu/drm/exynos/exynos_drm_fb.h +3 -7
@@ -10,14 +10,10 @@#ifndef _EXYNOS_DRM_FB_H_#define _EXYNOS_DRM_FB_H_ -#include "exynos_drm_gem.h" +#include <linux/types.h> -struct drm_framebuffer * -exynos_drm_framebuffer_init (struct drm_device *dev, -const struct drm_format_info *info, -const struct drm_mode_fb_cmd2 *mode_cmd, -struct exynos_drm_gem **exynos_gem, -int count); +struct drm_device ; +struct drm_framebuffer ;dma_addr_t exynos_drm_fb_dma_addr (struct drm_framebuffer *fb,int index);
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -0
@@ -22,6 +22,7 @@#include "exynos_drm_drv.h" #include "exynos_drm_fb.h" #include "exynos_drm_fbdev.h" +#include "exynos_drm_gem.h" #define MAX_CONNECTOR 4
Signature · 1 line
2.54.0