fbmem: add a default get_fb_unmapped_area function
authorBenjamin Gaignard <benjamin.gaignard@linaro.org>
Wed, 4 Jan 2017 09:12:55 +0000 (10:12 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 6 Jan 2017 10:00:09 +0000 (11:00 +0100)
Allow generic frame-buffer to provide a default
get_fb_unmapped_area function if specific devices need it.

Usually this function is defined in architecture directories but
define it here may limit code duplication especially for all ARM
platforms without MMU.

version 5:
- set get_unmapped_area field if FB_PROVIDE_GET_FB_UNMAPPED_AREA is
  defined

version 4:
- introdude a configuration flag to be independent of architecture

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1483521177-21794-2-git-send-email-benjamin.gaignard@linaro.org
drivers/video/fbdev/Kconfig
drivers/video/fbdev/core/fbmem.c

index 5d3b0db5ce0af34997a3aa748292b6bd8d48c191..922e4eaed9c5b5278572a79eb1cfc14e267a8bd5 100644 (file)
@@ -138,6 +138,14 @@ config FB_SYS_IMAGEBLIT
          blitting. This is used by drivers that don't provide their own
          (accelerated) version and the framebuffer is in system RAM.
 
+config FB_PROVIDE_GET_FB_UNMAPPED_AREA
+       bool
+       depends on FB
+       default n
+       ---help---
+         Allow generic frame-buffer to provide get_fb_unmapped_area
+         function.
+
 menuconfig FB_FOREIGN_ENDIAN
        bool "Framebuffer foreign endianness support"
        depends on FB
index 76c1ad96fb37d4f07bbde6462f54825f566acbac..069fe7960df1cedd17c3f7119d2ab6a6989e46c1 100644 (file)
@@ -1492,6 +1492,21 @@ __releases(&info->lock)
        return 0;
 }
 
+#ifdef CONFIG_FB_PROVIDE_GET_FB_UNMAPPED_AREA
+unsigned long get_fb_unmapped_area(struct file *filp,
+                                  unsigned long addr, unsigned long len,
+                                  unsigned long pgoff, unsigned long flags)
+{
+       struct fb_info * const info = filp->private_data;
+       unsigned long fb_size = PAGE_ALIGN(info->fix.smem_len);
+
+       if (pgoff > fb_size || len > fb_size - pgoff)
+               return -EINVAL;
+
+       return (unsigned long)info->screen_base + pgoff;
+}
+#endif
+
 static const struct file_operations fb_fops = {
        .owner =        THIS_MODULE,
        .read =         fb_read,
@@ -1503,7 +1518,8 @@ static const struct file_operations fb_fops = {
        .mmap =         fb_mmap,
        .open =         fb_open,
        .release =      fb_release,
-#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
+#if defined(HAVE_ARCH_FB_UNMAPPED_AREA) || \
+    defined(CONFIG_FB_PROVIDE_GET_FB_UNMAPPED_AREA)
        .get_unmapped_area = get_fb_unmapped_area,
 #endif
 #ifdef CONFIG_FB_DEFERRED_IO