Skip to contentSkip to conversation

drm: Improve fbdev emulation for DMA-able framebuffers

PATCH Superseded Thomas Zimmermann 4 participants 16 messages Jul 6, 2023 – Jul 7, 2023

Subsystems (8)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover drm: Improve fbdev emulation for DMA-able framebuffers

Add fbdev helpers for framebuffers in DMA-able memory and update fbdev emulation in the respective DRM drivers. DMA memory used to handled as system memory. Improve this and prepare for possible future changes.

Patch 1 adds initializer macros for struct fb_ops and a Kconfig token for framebuffers in DMA memory.

Patches 2 to 4 update fbdev-dma and tegra. No functional changes are expected as both used system memory before.

Patches 5 and 6 update exynos to use DMA helpers. Exynos incorrectly used fbdev's I/O-memory helpers. Fix this.

Patches 7 to 9 update omapdrm to use DMA helpers. Patch 7 first reworks the driver's mmap to current best practices. This also makes it suitable for use with fbdev, which patches 8 and 9 implement.

Patchies 10 removes some fbdev macros for system memory that are now unused; patch 11 fixes some comments.

The patchset would ideally go through drm-misc-next. Future patches can build upon it and update fbdev drivers in similar ways.

v2:
* fix omap mmap flags
* drop FBINFO_DEFAULT from patches
* minor cleanups

Thomas Zimmermann (11):
fbdev: Add fb_ops init macros for framebuffers in DMA-able memory drm/fbdev-dma: Use fbdev DMA helpers
drm/tegra: Use fbdev DMA helpers
drm/tegra: Set fbdev FBINFO_VIRTFB flag
drm/exynos: Use fbdev DMA helpers
drm/exynos: Set fbdev FBINFO_VIRTFB flag
drm/omapdrm: Set VM flags in GEM-object mmap function drm/omapdrm: Use GEM mmap for fbdev emulation drm/omapdrm: Set fbdev FBINFO_VIRTFB flag
fbdev: Remove FB_DEFAULT_SYS_OPS
fbdev: Harmonize some comments in <linux/fb.h>

 drivers/gpu/drm/Kconfig                   |  2 +-
 drivers/gpu/drm/drm_fbdev_dma.c           |  4 ++--
 drivers/gpu/drm/exynos/Kconfig            |  2 +-
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  5 ++--
 drivers/gpu/drm/omapdrm/Kconfig           |  2 +-
 drivers/gpu/drm/omapdrm/omap_drv.c        | 12 +---------
 drivers/gpu/drm/omapdrm/omap_fbdev.c      | 16 +++++++++++--
 drivers/gpu/drm/omapdrm/omap_gem.c        | 24 +++++--------------
 drivers/gpu/drm/omapdrm/omap_gem.h        |  3 ---
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c |  7 +-----
 drivers/gpu/drm/tegra/Kconfig             |  2 +-
 drivers/gpu/drm/tegra/fbdev.c             |  5 ++--
 drivers/video/fbdev/Kconfig               |  8 +++++++
 include/linux/fb.h                        | 29 ++++++++++-------------
 14 files changed, 55 insertions(+), 66 deletions(-)
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH v2 1/11 fbdev: Add fb_ops init macros for framebuffers in DMA-able memory

Add initializer macros for struct fb_ops for framebuffers in DMA-able memory areas. Also add a corresponding Kconfig token. As of now, this is equivalent to system framebuffers and mostly useful for labeling drivers correctly.

A later patch may add a generic DMA-specific mmap operation. Linux offers a number of dma_mmap_*() helpers for different use cases.

---
 drivers/video/fbdev/Kconfig |  8 ++++++++
 include/linux/fb.h          | 13 +++++++++++++
 2 files changed, 21 insertions(+)
drivers/video/fbdev/Kconfig +8 -0
index cecf15418632..f14229757311 100644
@@ -168,6 +168,14 @@ config FB_DEFERRED_IO
 	bool
 	depends on FB
 
+config FB_DMA_HELPERS
+	bool
+	depends on FB
+	select FB_SYS_COPYAREA
+	select FB_SYS_FILLRECT
+	select FB_SYS_FOPS
+	select FB_SYS_IMAGEBLIT
+
 config FB_IO_HELPERS
 	bool
 	depends on FB
include/linux/fb.h +13 -0
index 1d5c13f34b09..1191a78c5289 100644
@@ -594,6 +594,19 @@ extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
 	__FB_DEFAULT_SYS_OPS_DRAW, \
 	__FB_DEFAULT_SYS_OPS_MMAP
 
+/*
+ * Helpers for framebuffers in DMA-able memory
+ */
+
+#define __FB_DEFAULT_DMA_OPS_RDWR \
+	.fb_read	= fb_sys_read, \
+	.fb_write	= fb_sys_write
+
+#define __FB_DEFAULT_DMA_OPS_DRAW \
+	.fb_fillrect	= sys_fillrect, \
+	.fb_copyarea	= sys_copyarea, \
+	.fb_imageblit	= sys_imageblit
+
 /* drivers/video/fbmem.c */
 extern int register_framebuffer(struct fb_info *fb_info);
 extern void unregister_framebuffer(struct fb_info *fb_info);
Signature · 1 line
2.41.0
author maintainer
#2 lore raw

PATCH v2 2/11 drm/fbdev-dma: Use fbdev DMA helpers

In reply to Thomas Zimmermann

Use fbdev's DMA helpers for fbdev-dma. They are equivalent to the previously used system-memory helpers, so no functional changes here.

---
 drivers/gpu/drm/Kconfig         | 2 +-
 drivers/gpu/drm/drm_fbdev_dma.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/Kconfig +1 -1
index afb3b2f5f425..da3aa0625c36 100644
@@ -216,7 +216,7 @@ config DRM_TTM_HELPER
 config DRM_GEM_DMA_HELPER
 	tristate
 	depends on DRM
-	select FB_SYS_HELPERS if DRM_FBDEV_EMULATION
+	select FB_DMA_HELPERS if DRM_FBDEV_EMULATION
 	help
 	  Choose this if you need the GEM DMA helper functions
 
drivers/gpu/drm/drm_fbdev_dma.c +2 -2
index 8217f1ddc007..040c229a1737 100644
@@ -62,9 +62,9 @@ static const struct fb_ops drm_fbdev_dma_fb_ops = {
 	.owner = THIS_MODULE,
 	.fb_open = drm_fbdev_dma_fb_open,
 	.fb_release = drm_fbdev_dma_fb_release,
-	__FB_DEFAULT_SYS_OPS_RDWR,
+	__FB_DEFAULT_DMA_OPS_RDWR,
 	DRM_FB_HELPER_DEFAULT_OPS,
-	__FB_DEFAULT_SYS_OPS_DRAW,
+	__FB_DEFAULT_DMA_OPS_DRAW,
 	.fb_mmap = drm_fbdev_dma_fb_mmap,
 	.fb_destroy = drm_fbdev_dma_fb_destroy,
 };
Signature · 1 line
2.41.0
author maintainer
#3 lore raw

PATCH v2 3/11 drm/tegra: Use fbdev DMA helpers

In reply to Thomas Zimmermann

Use fbdev's DMA helpers for fbdev emulation. They are equivalent to the previously used system-memory helpers, so no functional changes here.

---
 drivers/gpu/drm/tegra/Kconfig | 2 +-
 drivers/gpu/drm/tegra/fbdev.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/Kconfig +1 -1
index 498313778175..39452c8480c1 100644
@@ -12,7 +12,7 @@ config DRM_TEGRA
 	select DRM_KMS_HELPER
 	select DRM_MIPI_DSI
 	select DRM_PANEL
-	select FB_SYS_HELPERS if DRM_FBDEV_EMULATION
+	select FB_DMA_HELPERS if DRM_FBDEV_EMULATION
 	select TEGRA_HOST1X
 	select INTERCONNECT
 	select IOMMU_IOVA
drivers/gpu/drm/tegra/fbdev.c +2 -2
index e74d9be981c7..82577b7c88da 100644
@@ -59,9 +59,9 @@ static void tegra_fbdev_fb_destroy(struct fb_info *info)
 
 static const struct fb_ops tegra_fb_ops = {
 	.owner = THIS_MODULE,
-	__FB_DEFAULT_SYS_OPS_RDWR,
+	__FB_DEFAULT_DMA_OPS_RDWR,
 	DRM_FB_HELPER_DEFAULT_OPS,
-	__FB_DEFAULT_SYS_OPS_DRAW,
+	__FB_DEFAULT_DMA_OPS_DRAW,
 	.fb_mmap = tegra_fb_mmap,
 	.fb_destroy = tegra_fbdev_fb_destroy,
 };
Signature · 1 line
2.41.0
author maintainer
#4 lore raw

PATCH v2 4/11 drm/tegra: Set fbdev FBINFO_VIRTFB flag

In reply to Thomas Zimmermann

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

v2:
* drop FBINFO_DEFAULT

---
 drivers/gpu/drm/tegra/fbdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/tegra/fbdev.c +1 -0
index 82577b7c88da..d8460c5dc91e 100644
@@ -132,6 +132,7 @@ static int tegra_fbdev_probe(struct drm_fb_helper *helper,
 		}
 	}
 
+	info->flags |= FBINFO_VIRTFB;
 	info->screen_base = (void __iomem *)bo->vaddr + offset;
 	info->screen_size = size;
 	info->fix.smem_start = (unsigned long)(bo->iova + offset);
Signature · 1 line
2.41.0
#5 lore raw

Re: [PATCH v2 04/11] drm/tegra: Set fbdev FBINFO_VIRTFB flag

Quoted 21 lines · Thomas Zimmermann

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

v2:
* drop FBINFO_DEFAULT

---
 drivers/gpu/drm/tegra/fbdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/tegra/fbdev.c +0 -0
index 82577b7c88da..d8460c5dc91e 100644

drivers/gpu/drm/tegra/fbdev.c static int tegra_fbdev_probe(struct drm_fb_helper *helper, · line 136

Quoted 5 lines
drivers/gpu/drm/tegra/fbdev.c +1 -0
@@ -132,6 +132,7 @@ static int tegra_fbdev_probe(struct drm_fb_helper *helper,
 		}
 	}
 
+	info->flags |= FBINFO_VIRTFB;
 	info->screen_base = (void __iomem *)bo->vaddr + offset;

As part of this, do we also need to set info->screen_buffer instead of info->screen_base? The drm_fbdev_dma_helper functions do that.

Thierry

Quoted 5 lines
drivers/gpu/drm/tegra/fbdev.c +0 -0
 	info->screen_size = size;
 	info->fix.smem_start = (unsigned long)(bo->iova + offset);
Signature · 1 line
2.41.0
author maintainer
#6 lore raw

Re: [PATCH v2 04/11] drm/tegra: Set fbdev FBINFO_VIRTFB flag

Hi

Am 06.07.23 um 16:31 schrieb Thierry Reding:

Quoted 25 lines · Thomas Zimmermann
Quoted 24 lines

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

v2:
* drop FBINFO_DEFAULT

---
  drivers/gpu/drm/tegra/fbdev.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/tegra/fbdev.c +0 -0
index 82577b7c88da..d8460c5dc91e 100644
@@ -132,6 +132,7 @@ static int tegra_fbdev_probe(struct drm_fb_helper *helper,
  		}
  	}
 
Quoted 5 lines

drivers/gpu/drm/tegra/fbdev.c static int tegra_fbdev_probe(struct drm_fb_helper *helper, · line 136

Quoted 2 lines
drivers/gpu/drm/tegra/fbdev.c +1 -0
+	info->flags |= FBINFO_VIRTFB;
  	info->screen_base = (void __iomem *)bo->vaddr + offset;

As part of this, do we also need to set info->screen_buffer instead of info->screen_base? The drm_fbdev_dma_helper functions do that.

Indeed, good point. I'll update this in the next iteration.

Best regards
Thomas

Quoted 8 lines

Thierry

Quoted 5 lines
drivers/gpu/drm/tegra/fbdev.c +0 -0
  	info->screen_size = size;
  	info->fix.smem_start = (unsigned long)(bo->iova + offset);
Signature · 1 line
2.41.0
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#7 lore raw

PATCH v2 5/11 drm/exynos: Use fbdev DMA helpers

In reply to Thomas Zimmermann

Use fbdev's DMA helpers for fbdev emulation. The driver previously used the I/O-memory helpers, while allocating DMA-able system memory. This could (in theory) result in bus errors from accessing the memory range.

This bug has been present since the exynos driver was first added.

v2:
* drop the pointless Fixes tag (Javier)
* fix typo in commit message

---
 drivers/gpu/drm/exynos/Kconfig            | 2 +-
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/exynos/Kconfig +1 -1
index 7ca7e1dab52c..661b42ad4873 100644
@@ -7,7 +7,7 @@ config DRM_EXYNOS
 	select DRM_DISPLAY_HELPER if DRM_EXYNOS_DP
 	select DRM_KMS_HELPER
 	select VIDEOMODE_HELPERS
-	select FB_IO_HELPERS if DRM_FBDEV_EMULATION
+	select FB_DMA_HELPERS if DRM_FBDEV_EMULATION
 	select SND_SOC_HDMI_CODEC if SND_SOC
 	help
 	  Choose this option if you have a Samsung SoC Exynos chipset.
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +2 -2
index fdf65587f1fe..7ca3424b59ce 100644
@@ -49,9 +49,9 @@ static void exynos_drm_fb_destroy(struct fb_info *info)
 
 static const struct fb_ops exynos_drm_fb_ops = {
 	.owner		= THIS_MODULE,
-	__FB_DEFAULT_IO_OPS_RDWR,
+	__FB_DEFAULT_DMA_OPS_RDWR,
 	DRM_FB_HELPER_DEFAULT_OPS,
-	__FB_DEFAULT_IO_OPS_DRAW,
+	__FB_DEFAULT_DMA_OPS_DRAW,
 	.fb_mmap        = exynos_drm_fb_mmap,
 	.fb_destroy	= exynos_drm_fb_destroy,
 };
Signature · 1 line
2.41.0
author maintainer
#8 lore raw

PATCH v2 6/11 drm/exynos: Set fbdev FBINFO_VIRTFB flag

In reply to Thomas Zimmermann

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

v2:
* drop FBINFO_FLAG_DEFAULT

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -0
index 7ca3424b59ce..828318de8529 100644
@@ -79,6 +79,7 @@ static int exynos_drm_fbdev_update(struct drm_fb_helper *helper,
 	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_size = size;
 	fbi->fix.smem_len = size;
Signature · 1 line
2.41.0
maintainer Acked-by on v2 6/11
#9 lore raw

RE: [PATCH v2 06/11] drm/exynos: Set fbdev FBINFO_VIRTFB flag

Hi,

Quoted 17 lines

-----Original Message-----
From: Thomas Zimmermann <[email protected]>
Sent: Thursday, July 6, 2023 9:47 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; Thomas Zimmermann <[email protected]>; Inki Dae <[email protected]>; Seung-Woo Kim <[email protected]>; Kyungmin Park <[email protected]>; Krzysztof Kozlowski <[email protected]>; Alim Akhtar <[email protected]>
Subject: [PATCH v2 06/11] drm/exynos: Set fbdev FBINFO_VIRTFB flag

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

Quoted 6 lines

v2:
* drop FBINFO_FLAG_DEFAULT

Thanks,
Inki Dae

Quoted 25 lines
Cc Inki Dae <[email protected]>
Cc Seung-Woo Kim <[email protected]>
Cc Kyungmin Park <[email protected]>
Cc Krzysztof Kozlowski <[email protected]>
Cc Alim Akhtar <[email protected]>
---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +1 -0
index 7ca3424b59ce..828318de8529 100644
@@ -79,6 +79,7 @@ static int exynos_drm_fbdev_update(struct drm_fb_helper
 *helper,
 	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_size = size;

fbi->fix.smem_len = size;
--
2.41.0

author maintainer
#10 lore raw

PATCH v2 7/11 drm/omapdrm: Set VM flags in GEM-object mmap function

In reply to Thomas Zimmermann

Use the mmap callback in struct drm_gem_object_funcs to set the VM flags. Replace a number of mmap helpers in omapdrm with their GEM helper counterparts. Generate DRM's file-operations instance with GEM's DEFINE_DRM_GEM_FOPS.

The omapdrm driver uses DRM's drm_gem_mmap() helper to prepare the VMA structure. It then modifies the resulting VMA state in its own helper omap_gem_mmap_obj(). The patch improves this by setting up the VMA in the mmap callback in drm_gem_object_funcs, which is called from within drm_gem_mmap().

Omapdrm's omap_gem_mmap() and omap_gem_mmap() can then be removed from the driver. A call to drm_gem_mmap() is sufficient for the mmap operation.

Finally, with the omap functions gone, the drivers file_ops in omapdriver_fops can be generated with DEFINE_DRM_GEM_FOPS, which sets DRM's default helpers.

v2:
* detailed commit message (Javier)
* do not set VM_PFNMAP

---
 drivers/gpu/drm/omapdrm/omap_drv.c        | 12 +-----------
 drivers/gpu/drm/omapdrm/omap_gem.c        | 24 ++++++-----------------
 drivers/gpu/drm/omapdrm/omap_gem.h        |  3 ---
 drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c |  7 +------
 4 files changed, 8 insertions(+), 38 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +1 -11
index e2697fe80e62..afeeb7737552 100644
@@ -636,17 +636,7 @@ static int dev_open(struct drm_device *dev, struct drm_file *file)
 	return 0;
 }
 
-static const struct file_operations omapdriver_fops = {
-	.owner = THIS_MODULE,
-	.open = drm_open,
-	.unlocked_ioctl = drm_ioctl,
-	.compat_ioctl = drm_compat_ioctl,
-	.release = drm_release,
-	.mmap = omap_gem_mmap,
-	.poll = drm_poll,
-	.read = drm_read,
-	.llseek = noop_llseek,
-};
+DEFINE_DRM_GEM_FOPS(omapdriver_fops);
 
 static const struct drm_driver omap_drm_driver = {
 	.driver_features = DRIVER_MODESET | DRIVER_GEM  |
drivers/gpu/drm/omapdrm/omap_gem.c +6 -18
index 6b58a5bb7b44..c48fa531ca32 100644
@@ -524,26 +524,11 @@ static vm_fault_t omap_gem_fault(struct vm_fault *vmf)
 	return ret;
 }
 
-/** We override mainly to fix up some of the vm mapping flags.. */
-int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma)
-{
-	int ret;
-
-	ret = drm_gem_mmap(filp, vma);
-	if (ret) {
-		DBG("mmap failed: %d", ret);
-		return ret;
-	}
-
-	return omap_gem_mmap_obj(vma->vm_private_data, vma);
-}
-
-int omap_gem_mmap_obj(struct drm_gem_object *obj,
-		struct vm_area_struct *vma)
+static int omap_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 {
 	struct omap_gem_object *omap_obj = to_omap_bo(obj);
 
-	vm_flags_mod(vma, VM_MIXEDMAP, VM_PFNMAP);
+	vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP | VM_IO | VM_MIXEDMAP);
 
 	if (omap_obj->flags & OMAP_BO_WC) {
 		vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
@@ -563,12 +548,14 @@ int omap_gem_mmap_obj(struct drm_gem_object *obj,
 		 * address_space (so unmap_mapping_range does what we want,
 		 * in particular in the case of mmap'd dmabufs)
 		 */
-		vma->vm_pgoff = 0;
+		vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
 		vma_set_file(vma, obj->filp);
 
 		vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 	}
 
+	vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
+
 	return 0;
 }
 
@@ -1282,6 +1269,7 @@ static const struct vm_operations_struct omap_gem_vm_ops = {
 static const struct drm_gem_object_funcs omap_gem_object_funcs = {
 	.free = omap_gem_free_object,
 	.export = omap_gem_prime_export,
+	.mmap = omap_gem_object_mmap,
 	.vm_ops = &omap_gem_vm_ops,
 };
 
drivers/gpu/drm/omapdrm/omap_gem.h +0 -3
index 4d4488939f6b..fec3fa0e4c33 100644
@@ -57,9 +57,6 @@ int omap_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
 		struct drm_mode_create_dumb *args);
 
 /* mmap() Interface */
-int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma);
-int omap_gem_mmap_obj(struct drm_gem_object *obj,
-		struct vm_area_struct *vma);
 u64 omap_gem_mmap_offset(struct drm_gem_object *obj);
 size_t omap_gem_mmap_size(struct drm_gem_object *obj);
 
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c +1 -6
index 8e194dbc9506..36f9ee4baad3 100644
@@ -64,13 +64,8 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
 		struct vm_area_struct *vma)
 {
 	struct drm_gem_object *obj = buffer->priv;
-	int ret = 0;
 
-	ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
-	if (ret < 0)
-		return ret;
-
-	return omap_gem_mmap_obj(obj, vma);
+	return drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
 }
 
 static const struct dma_buf_ops omap_dmabuf_ops = {
Signature · 1 line
2.41.0
author maintainer
#11 lore raw

PATCH v2 8/11 drm/omapdrm: Use GEM mmap for fbdev emulation

In reply to Thomas Zimmermann

The fbdev emulation currently uses fbdev's default mmap code, which has been written for I/O memory. Provide an mmap that uses GEM's mmap infrastructure.

Utilize fine-grained fbdev macros to initialize struct fb_ops. The macros set the read/write and the draw callbacks for DMA memory. Set the fb_mmap callback to omapdrm's new mmap helper. Also select the correct Kconfig token for fbdev's DMA helpers. Note that the DMA helpers are the same as for system memory.

---
 drivers/gpu/drm/omapdrm/Kconfig      |  2 +-
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/Kconfig +1 -1
index b4ac76c9f31b..d3c4877e465c 100644
@@ -4,7 +4,7 @@ config DRM_OMAP
 	depends on DRM && OF
 	depends on ARCH_OMAP2PLUS
 	select DRM_KMS_HELPER
-	select FB_SYS_HELPERS if DRM_FBDEV_EMULATION
+	select FB_DMA_HELPERS if DRM_FBDEV_EMULATION
 	select VIDEOMODE_HELPERS
 	select HDMI
 	default n
drivers/gpu/drm/omapdrm/omap_fbdev.c +13 -2
index b7ccce0704a3..b1a2d00ef52d 100644
@@ -76,6 +76,15 @@ static int omap_fbdev_pan_display(struct fb_var_screeninfo *var,
 	return drm_fb_helper_pan_display(var, fbi);
 }
 
+static int omap_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
+{
+	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);
+
+	return drm_gem_mmap_obj(bo, omap_gem_mmap_size(bo), vma);
+}
+
 static void omap_fbdev_fb_destroy(struct fb_info *info)
 {
 	struct drm_fb_helper *helper = info->par;
@@ -97,14 +106,16 @@ static void omap_fbdev_fb_destroy(struct fb_info *info)
 
 static const struct fb_ops omap_fb_ops = {
 	.owner = THIS_MODULE,
-	FB_DEFAULT_SYS_OPS,
+	__FB_DEFAULT_DMA_OPS_RDWR,
 	.fb_check_var	= drm_fb_helper_check_var,
 	.fb_set_par	= drm_fb_helper_set_par,
 	.fb_setcmap	= drm_fb_helper_setcmap,
 	.fb_blank	= drm_fb_helper_blank,
 	.fb_pan_display = omap_fbdev_pan_display,
+	__FB_DEFAULT_DMA_OPS_DRAW,
 	.fb_ioctl	= drm_fb_helper_ioctl,
-	.fb_destroy = omap_fbdev_fb_destroy,
+	.fb_mmap	= omap_fbdev_fb_mmap,
+	.fb_destroy	= omap_fbdev_fb_destroy,
 };
 
 static int omap_fbdev_create(struct drm_fb_helper *helper,
Signature · 1 line
2.41.0
author maintainer
#12 lore raw

PATCH v2 9/11 drm/omapdrm: Set fbdev FBINFO_VIRTFB flag

In reply to Thomas Zimmermann

Mark the framebuffer with FBINFO_VIRTFB. The framebuffer range is in DMA-able memory and should be accessed with the CPU's regular memory ops.

v2:
* drop FBINFO_DEFAULT

---
 drivers/gpu/drm/omapdrm/omap_fbdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/omapdrm/omap_fbdev.c +1 -0
index b1a2d00ef52d..2821182f1d93 100644
@@ -207,6 +207,7 @@ static int omap_fbdev_create(struct drm_fb_helper *helper,
 
 	drm_fb_helper_fill_info(fbi, helper, sizes);
 
+	fbi->flags |= FBINFO_VIRTFB;
 	fbi->screen_buffer = omap_gem_vaddr(bo);
 	fbi->screen_size = bo->size;
 	fbi->fix.smem_start = dma_addr;
Signature · 1 line
2.41.0
author maintainer
#13 lore raw

PATCH v2 10/11 fbdev: Remove FB_DEFAULT_SYS_OPS

In reply to Thomas Zimmermann

Remove the initializer macro FB_DEFAULT_SYS_OPS and its helper macro __FB_DEFAULT_SYS_OPS_MMAP. There are no users.

---
 include/linux/fb.h | 8 --------
 1 file changed, 8 deletions(-)
include/linux/fb.h +0 -8
index 1191a78c5289..d370f84fbca9 100644
@@ -586,14 +586,6 @@ extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
 	.fb_copyarea	= sys_copyarea, \
 	.fb_imageblit	= sys_imageblit
 
-#define __FB_DEFAULT_SYS_OPS_MMAP \
-	.fb_mmap	= NULL /* default implementation */
-
-#define FB_DEFAULT_SYS_OPS \
-	__FB_DEFAULT_SYS_OPS_RDWR, \
-	__FB_DEFAULT_SYS_OPS_DRAW, \
-	__FB_DEFAULT_SYS_OPS_MMAP
-
 /*
  * Helpers for framebuffers in DMA-able memory
  */
Signature · 1 line
2.41.0
author maintainer
#14 lore raw

PATCH v2 11/11 fbdev: Harmonize some comments in <linux/fb.h>

In reply to Thomas Zimmermann

Make the comments for I/O, system and DMA memory say the same. Makes the header file's structure more obvious.

---
 include/linux/fb.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
include/linux/fb.h +2 -10
index d370f84fbca9..c8ca9c265fda 100644
@@ -529,7 +529,7 @@ extern int fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var);
 extern int fb_blank(struct fb_info *info, int blank);
 
 /*
- * Drawing operations where framebuffer is in I/O memory
+ * Helpers for framebuffers in I/O memory
  */
 
 extern void cfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
@@ -540,10 +540,6 @@ extern ssize_t fb_io_read(struct fb_info *info, char __user *buf,
 extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
 			   size_t count, loff_t *ppos);
 
-/*
- * Initializes struct fb_ops for framebuffers in I/O memory.
- */
-
 #define __FB_DEFAULT_IO_OPS_RDWR \
 	.fb_read	= fb_io_read, \
 	.fb_write	= fb_io_write
@@ -562,7 +558,7 @@ extern ssize_t fb_io_write(struct fb_info *info, const char __user *buf,
 	__FB_DEFAULT_IO_OPS_MMAP
 
 /*
- * Drawing operations where framebuffer is in system RAM
+ * Helpers for framebuffers in system memory
  */
 
 extern void sys_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
@@ -573,10 +569,6 @@ extern ssize_t fb_sys_read(struct fb_info *info, char __user *buf,
 extern ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
 			    size_t count, loff_t *ppos);
 
-/*
- * Initializes struct fb_ops for framebuffers in system memory.
- */
-
 #define __FB_DEFAULT_SYS_OPS_RDWR \
 	.fb_read	= fb_sys_read, \
 	.fb_write	= fb_sys_write
Signature · 1 line
2.41.0
Reviewed-by on v2 11/11
#15 lore raw

Re: [PATCH v2 11/11] fbdev: Harmonize some comments in <linux/fb.h>

Thomas Zimmermann <[email protected]> writes:

Hello Thomas,

Quoted 6 lines

Make the comments for I/O, system and DMA memory say the same. Makes the header file's structure more obvious.

---

Looks good to me. Thanks!

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat