Skip to contentSkip to conversation

drm/exynos: fbdev: Use client buffers

PATCH In review Thomas Zimmermann 3 participants 10 messages Apr 23 – May 8

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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.

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    |   2 +-
 drivers/gpu/drm/exynos/exynos_drm_fb.h    |   7 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 100 ++++++++++------------
 3 files changed, 47 insertions(+), 62 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 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.

Fixes 19c8b8343d9c ("drm/exynos: fixed overlay data updating.")
Cc <[email protected]> # v3.2+
---
 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
index 637927818dfe..d283ded266d5 100644
@@ -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.53.0
#2 lore raw

PATCH 2/5 drm/exynos: fbdev: Inline exynos_drm_fbdev_update()

In reply to Thomas Zimmermann

Inline 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
index d283ded266d5..1c564edd497e 100644
@@ -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.53.0
#3 lore raw

PATCH 3/5 drm/exynos: fbdev: Calculate buffer geometry with format helpers

In reply to Thomas Zimmermann

Replace 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
index 1c564edd497e..9225cf1a83c8 100644
@@ -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.53.0
#4 lore raw

PATCH 4/5 drm/exynos: fbdev: Use a DRM client buffer

In reply to Thomas Zimmermann

Replace 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
index 9225cf1a83c8..f43ce974c952 100644
@@ -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.53.0
#5 lore raw

PATCH 5/5 drm/exynos: Make exynos_drm_framebuffer_init() an internal interface

In reply to Thomas Zimmermann

The only caller of exynos_drm_framebuffer_init() is the helper exynos_user_fb_create() from the same source file. Declare the former as static.

---
 drivers/gpu/drm/exynos/exynos_drm_fb.c | 2 +-
 drivers/gpu/drm/exynos/exynos_drm_fb.h | 7 -------
 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fb.c +1 -1
index ab0e0c74ec47..66dec2b7a5de 100644
@@ -55,7 +55,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 +0 -7
index fdc6cb40cc9c..aeb6f29eb167 100644
@@ -12,13 +12,6 @@
 
 #include "exynos_drm_gem.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);
-
 dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer *fb, int index);
 
 void exynos_drm_mode_config_init(struct drm_device *dev);
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH 5/5] drm/exynos: Make exynos_drm_framebuffer_init() an internal interface

Quoted 29 lines · Thomas Zimmermann

The only caller of exynos_drm_framebuffer_init() is the helper exynos_user_fb_create() from the same source file. Declare the former as static.

---
 drivers/gpu/drm/exynos/exynos_drm_fb.c | 2 +-
 drivers/gpu/drm/exynos/exynos_drm_fb.h | 7 -------
 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fb.c +1 -1
index ab0e0c74ec47..66dec2b7a5de 100644
@@ -55,7 +55,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 +0 -0
index fdc6cb40cc9c..aeb6f29eb167 100644

drivers/gpu/drm/exynos/exynos_drm_fb.h line 13

Quoted 2 lines
drivers/gpu/drm/exynos/exynos_drm_fb.h +0 -0
@@ -12,13 +12,6 @@
 
 #include "exynos_drm_gem.h"

Nit: you could move the include statement to exynos_drm_fb.c as well.

Quoted 13 lines
drivers/gpu/drm/exynos/exynos_drm_fb.h +0 -8
-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);
-
 dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer *fb, int index);
 
 void exynos_drm_mode_config_init(struct drm_device *dev);
--

2.53.0

#7 lore raw

Re: [PATCH 5/5] drm/exynos: Make exynos_drm_framebuffer_init() an internal interface

Hi

Am 06.05.26 um 08:59 schrieb Chen-Yu Tsai:
[...]

Quoted 6 lines

drivers/gpu/drm/exynos/exynos_drm_fb.h line 13

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_fb.h +0 -0
@@ -12,13 +12,6 @@
 
  #include "exynos_drm_gem.h"

Nit: you could move the include statement to exynos_drm_fb.c as well.

Right, good point. I'll send an update in a bit.

Best regards
Thomas

Quoted 14 lines
Quoted 14 lines
drivers/gpu/drm/exynos/exynos_drm_fb.h +0 -8
-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);
-
  dma_addr_t exynos_drm_fb_dma_addr(struct drm_framebuffer *fb, int index);
 
  void exynos_drm_mode_config_init(struct drm_device *dev);
--

2.53.0

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)
Tested-by Acked-by on the v1 series
#8 lore raw
In reply to Thomas Zimmermann
Quoted 11 lines · Thomas Zimmermann

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.

Quoted 3 lines

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.

Quoted 15 lines

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.

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

Quoted 5 lines
 drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 +-
 drivers/gpu/drm/exynos/exynos_drm_fb.h    |   7 --
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 100 ++++++++++------------
 3 files changed, 47 insertions(+), 62 deletions(-)

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
#9 lore raw

Hi

Am 06.05.26 um 08:35 schrieb Marek Szyprowski:

Quoted 12 lines · Thomas Zimmermann
Quoted 11 lines

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.

Quoted 6 lines
Quoted 3 lines

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.

Thanks a lot!

Quoted 23 lines
Quoted 17 lines

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.

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

Quoted 5 lines
  drivers/gpu/drm/exynos/exynos_drm_fb.c    |   2 +-
  drivers/gpu/drm/exynos/exynos_drm_fb.h    |   7 --
  drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 100 ++++++++++------------
  3 files changed, 47 insertions(+), 62 deletions(-)

Best regards

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)