drm: allow to use mmuless SoC
authorBenjamin Gaignard <benjamin.gaignard@linaro.org>
Wed, 4 Jan 2017 09:12:57 +0000 (10:12 +0100)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 6 Jan 2017 10:04:54 +0000 (11:04 +0100)
Some SoC without MMU have display driver where a drm/kms driver
could be implemented.

Before doing such kind of thing drm/kms must allow to use mmuless devices.
This patch propose to remove MMU configuration flag and add a cma helper
function to help implementing mmuless display driver

version 4:
- add documentation about drm_gem_cma_get_unmapped_area()
- stub it MMU case

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
[danvet: Use recommended struct member references in kernel-doc.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1483521177-21794-4-git-send-email-benjamin.gaignard@linaro.org
Documentation/gpu/drm-mm.rst
drivers/gpu/drm/Kconfig
drivers/gpu/drm/drm_gem_cma_helper.c
include/drm/drm_gem_cma_helper.h

index d3c6d77246cdc608543f0de0857a368c86725eea..1ea94fc86caa6cae8c83f2a516c545a154037e2a 100644 (file)
@@ -310,6 +310,17 @@ created.
 Drivers that want to map the GEM object upfront instead of handling page
 faults can implement their own mmap file operation handler.
 
+For platforms without MMU the GEM core provides a helper method
+:c:func:`drm_gem_cma_get_unmapped_area`. The mmap() routines will call
+this to get a proposed address for the mapping.
+
+To use :c:func:`drm_gem_cma_get_unmapped_area`, drivers must fill the
+struct :c:type:`struct file_operations <file_operations>` get_unmapped_area
+field with a pointer on :c:func:`drm_gem_cma_get_unmapped_area`.
+
+More detailed information about get_unmapped_area can be found in
+Documentation/nommu-mmap.txt
+
 Memory Coherency
 ----------------
 
index d56b85c03b7bf2c4d0fed854713611f545b26fe9..505ca1d262ee1364021ae097cb50757a00e8f650 100644 (file)
@@ -6,7 +6,7 @@
 #
 menuconfig DRM
        tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
-       depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU && HAS_DMA
+       depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA
        select HDMI
        select FB_CMDLINE
        select I2C
@@ -113,7 +113,7 @@ config DRM_LOAD_EDID_FIRMWARE
 
 config DRM_TTM
        tristate
-       depends on DRM
+       depends on DRM && MMU
        help
          GPU memory management subsystem for devices with multiple
          GPU memory types. Will be enabled automatically if a device driver
index e0806a2ad11c6e10fa7023827fd571c3e1f92240..5cf38a4748457ee5d2af7b84d37e4438019ecc9a 100644 (file)
@@ -358,6 +358,77 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma)
 }
 EXPORT_SYMBOL_GPL(drm_gem_cma_mmap);
 
+#ifndef CONFIG_MMU
+/**
+ * drm_gem_cma_get_unmapped_area - propose address for mapping in noMMU cases
+ * @filp: file object
+ * @addr: memory address
+ * @len: buffer size
+ * @pgoff: page offset
+ * @flags: memory flags
+ *
+ * This function is used in noMMU platforms to propose address mapping
+ * for a given buffer.
+ * It's intended to be used as a direct handler for the struct
+ * &file_operations.get_unmapped_area operation.
+ *
+ * Returns:
+ * mapping address on success or a negative error code on failure.
+ */
+unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
+                                           unsigned long addr,
+                                           unsigned long len,
+                                           unsigned long pgoff,
+                                           unsigned long flags)
+{
+       struct drm_gem_cma_object *cma_obj;
+       struct drm_gem_object *obj = NULL;
+       struct drm_file *priv = filp->private_data;
+       struct drm_device *dev = priv->minor->dev;
+       struct drm_vma_offset_node *node;
+
+       if (drm_device_is_unplugged(dev))
+               return -ENODEV;
+
+       drm_vma_offset_lock_lookup(dev->vma_offset_manager);
+       node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
+                                                 pgoff,
+                                                 len >> PAGE_SHIFT);
+       if (likely(node)) {
+               obj = container_of(node, struct drm_gem_object, vma_node);
+               /*
+                * When the object is being freed, after it hits 0-refcnt it
+                * proceeds to tear down the object. In the process it will
+                * attempt to remove the VMA offset and so acquire this
+                * mgr->vm_lock.  Therefore if we find an object with a 0-refcnt
+                * that matches our range, we know it is in the process of being
+                * destroyed and will be freed as soon as we release the lock -
+                * so we have to check for the 0-refcnted object and treat it as
+                * invalid.
+                */
+               if (!kref_get_unless_zero(&obj->refcount))
+                       obj = NULL;
+       }
+
+       drm_vma_offset_unlock_lookup(dev->vma_offset_manager);
+
+       if (!obj)
+               return -EINVAL;
+
+       if (!drm_vma_node_is_allowed(node, priv)) {
+               drm_gem_object_unreference_unlocked(obj);
+               return -EACCES;
+       }
+
+       cma_obj = to_drm_gem_cma_obj(obj);
+
+       drm_gem_object_unreference_unlocked(obj);
+
+       return cma_obj->vaddr ? (unsigned long)cma_obj->vaddr : -EINVAL;
+}
+EXPORT_SYMBOL_GPL(drm_gem_cma_get_unmapped_area);
+#endif
+
 #ifdef CONFIG_DEBUG_FS
 /**
  * drm_gem_cma_describe - describe a CMA GEM object for debugfs
index acd6af8a8e675b5b58856651f18f788257bcc868..2abcd5190cc137f6e4714d2c0b7c3ae03459febd 100644 (file)
@@ -53,6 +53,23 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
 
 extern const struct vm_operations_struct drm_gem_cma_vm_ops;
 
+#ifndef CONFIG_MMU
+unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
+                                           unsigned long addr,
+                                           unsigned long len,
+                                           unsigned long pgoff,
+                                           unsigned long flags);
+#else
+static inline unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
+                                                         unsigned long addr,
+                                                         unsigned long len,
+                                                         unsigned long pgoff,
+                                                         unsigned long flags)
+{
+       return -EINVAL;
+}
+#endif
+
 #ifdef CONFIG_DEBUG_FS
 void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
 #endif