Skip to contentSkip to conversation

drm/exynos: add exynos drm specific fb_mmap function

PATCH Applied Prathyush K 3 participants 3 messages Nov 19, 2012 – Nov 20, 2012

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

PATCH v3 1/1 drm/exynos: add exynos drm specific fb_mmap function

Changelog v3:

Passing the actual buffer size instead of vm_size to dma_mmap_attrs.

Changelog v2:

Extracting the private data from fb_info structure to obtain the exynos gem buffer structure. Now, dma address is obtained from the exynos gem buffer structure and not from smem_start. Also calling dma_mmap_attrs (instead of dma_mmap_writecombine) with the same attributes used during allocation.

Changelog v1:

This patch adds a exynos drm specific implementation of fb_mmap which supports mapping a non-contiguous buffer to user space.

This new function does not assume that the frame buffer is contiguous and calls dma_mmap_writecombine for mapping the buffer to user space. dma_mmap_writecombine will be able to map a contiguous buffer as well as non-contig buffer depending on whether an IOMMU mapping is created for drm or not.

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |   30 +++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +30 -0
index 67eb6ba..a6f8cc2 100644
@@ -46,8 +46,38 @@ struct exynos_drm_fbdev {
 	struct exynos_drm_gem_obj	*exynos_gem_obj;
 };
 
+static int exynos_drm_fb_mmap(struct fb_info *info,
+			struct vm_area_struct *vma)
+{
+	struct drm_fb_helper *helper = info->par;
+	struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(helper);
+	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
+	struct exynos_drm_gem_buf *buffer = exynos_gem_obj->buffer;
+	unsigned long vm_size;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
+
+	vm_size = vma->vm_end - vma->vm_start;
+
+	if (vm_size > buffer->size)
+		return -EINVAL;
+
+	ret = dma_mmap_attrs(helper->dev->dev, vma, buffer->kvaddr,
+		buffer->dma_addr, buffer->size, &buffer->dma_attrs);
+	if (ret < 0) {
+		DRM_ERROR("failed to mmap.\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static struct fb_ops exynos_drm_fb_ops = {
 	.owner		= THIS_MODULE,
+	.fb_mmap        = exynos_drm_fb_mmap,
 	.fb_fillrect	= cfb_fillrect,
 	.fb_copyarea	= cfb_copyarea,
 	.fb_imageblit	= cfb_imageblit,
Signature · 1 line
1.7.0.4
#1 lore raw

Hi,

Quoted 41 lines · Prathyush K

Changelog v3:

Passing the actual buffer size instead of vm_size to dma_mmap_attrs.

Changelog v2:

Extracting the private data from fb_info structure to obtain the exynos gem buffer structure. Now, dma address is obtained from the exynos gem buffer structure and not from smem_start. Also calling dma_mmap_attrs (instead of dma_mmap_writecombine) with the same attributes used during allocation.

Changelog v1:

This patch adds a exynos drm specific implementation of fb_mmap which supports mapping a non-contiguous buffer to user space.

This new function does not assume that the frame buffer is contiguous and calls dma_mmap_writecombine for mapping the buffer to user space. dma_mmap_writecombine will be able to map a contiguous buffer as well as non-contig buffer depending on whether an IOMMU mapping is created for drm or not.

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |   30
+++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +3 -0
index 67eb6ba..a6f8cc2 100644
@@ -46,8 +46,38 @@ struct exynos_drm_fbdev {
 	struct exynos_drm_gem_obj	*exynos_gem_obj;
 };
 
+static int exynos_drm_fb_mmap(struct fb_info *info,
+			struct vm_area_struct *vma)
+{

drivers/gpu/drm/exynos/exynos_drm_fbdev.c struct exynos_drm_fbdev { · line 61

Quoted 10 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +10 -0
+	struct drm_fb_helper *helper = info->par;
+	struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(helper);
+	struct exynos_drm_gem_obj *exynos_gem_obj = exynos_fbd->exynos_gem_obj;
+	struct exynos_drm_gem_buf *buffer = exynos_gem_obj->buffer;
+	unsigned long vm_size;
+	int ret;
+
+	DRM_DEBUG_KMS("%s\n", __func__);
+
+	vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;

How do you sure VM_MIXEDMAP is not required?

drivers/gpu/drm/exynos/exynos_drm_fbdev.c struct exynos_drm_fbdev { · line 66

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +5 -0
+
+	vm_size = vma->vm_end - vma->vm_start;
+
+	if (vm_size > buffer->size)
+		return -EINVAL;

does it really happended?

Thank you,
Kyungmin Park

Quoted 25 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +12 -1
+
+	ret = dma_mmap_attrs(helper->dev->dev, vma, buffer->kvaddr,
+		buffer->dma_addr, buffer->size, &buffer->dma_attrs);
+	if (ret < 0) {
+		DRM_ERROR("failed to mmap.\n");
+		return ret;
+	}
+
+	return 0;
+}
+
 static struct fb_ops exynos_drm_fb_ops = {
 	.owner		= THIS_MODULE,
+	.fb_mmap        = exynos_drm_fb_mmap,
 	.fb_fillrect	= cfb_fillrect,
 	.fb_copyarea	= cfb_copyarea,
 	.fb_imageblit	= cfb_imageblit,
--

1.7.0.4

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Applied
#2 lore raw

2012/11/19 Kyungmin Park <[email protected]>

Quoted 48 lines

Hi,

Quoted 35 lines · Prathyush K

Changelog v3:

Passing the actual buffer size instead of vm_size to dma_mmap_attrs.

Changelog v2:

Extracting the private data from fb_info structure to obtain the exynos gem buffer structure. Now, dma address is obtained from the exynos gem buffer structure and not from smem_start. Also calling dma_mmap_attrs (instead of dma_mmap_writecombine) with the same attributes used during allocation.

Changelog v1:

This patch adds a exynos drm specific implementation of fb_mmap which supports mapping a non-contiguous buffer to user space.

This new function does not assume that the frame buffer is contiguous and calls dma_mmap_writecombine for mapping the buffer to user space. dma_mmap_writecombine will be able to map a contiguous buffer as well as non-contig buffer depending on whether an IOMMU mapping is created for drm or not.

---
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |   30
+++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +0 -0
index 67eb6ba..a6f8cc2 100644

drivers/gpu/drm/exynos/exynos_drm_fbdev.c struct exynos_drm_fbdev { · line 54

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +6 -0
@@ -46,8 +46,38 @@ struct exynos_drm_fbdev {
      struct exynos_drm_gem_obj       *exynos_gem_obj;
 };
 
+static int exynos_drm_fb_mmap(struct fb_info *info,
+                     struct vm_area_struct *vma)
+{
+     struct drm_fb_helper *helper = info->par;
+     struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(helper);
+     struct exynos_drm_gem_obj *exynos_gem_obj =

exynos_fbd->exynos_gem_obj;

Quoted 9 lines

drivers/gpu/drm/exynos/exynos_drm_fbdev.c struct exynos_drm_fbdev { · line 61

Quoted 7 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +7 -0
+     struct exynos_drm_gem_buf *buffer = exynos_gem_obj->buffer;
+     unsigned long vm_size;
+     int ret;
+
+     DRM_DEBUG_KMS("%s\n", __func__);
+
+     vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;

How do you sure VM_MIXEDMAP is not required?

With iommu, VM_MIXEDMAP flag would be set internally.

Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_fbdev.c struct exynos_drm_fbdev { · line 66

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +5 -0
+
+     vm_size = vma->vm_end - vma->vm_start;
+
+     if (vm_size > buffer->size)
+             return -EINVAL;

does it really happended?

vm_size is decided by user-mmap request so size to the vma area should be checked.

Applied.

Thanks,
Inki Dae

Quoted 22 lines

Thank you,
Kyungmin Park

Quoted 20 lines
drivers/gpu/drm/exynos/exynos_drm_fbdev.c +12 -1
+
+     ret = dma_mmap_attrs(helper->dev->dev, vma, buffer->kvaddr,
+             buffer->dma_addr, buffer->size, &buffer->dma_attrs);
+     if (ret < 0) {
+             DRM_ERROR("failed to mmap.\n");
+             return ret;
+     }
+
+     return 0;
+}
+
 static struct fb_ops exynos_drm_fb_ops = {
      .owner          = THIS_MODULE,
+     .fb_mmap        = exynos_drm_fb_mmap,
      .fb_fillrect    = cfb_fillrect,
      .fb_copyarea    = cfb_copyarea,
      .fb_imageblit   = cfb_imageblit,
--

1.7.0.4

Quoted 10 lines
Quoted 5 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel