Skip to content

Commit 62a0d98

Browse files
Benjamin-Gaignarddanvet
authored andcommitted
drm: allow to use mmuless SoC
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
1 parent 99c48e1 commit 62a0d98

4 files changed

Lines changed: 101 additions & 2 deletions

File tree

‎Documentation/gpu/drm-mm.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ created.
310310
Drivers that want to map the GEM object upfront instead of handling page
311311
faults can implement their own mmap file operation handler.
312312

313+
For platforms without MMU the GEM core provides a helper method
314+
:c:func:`drm_gem_cma_get_unmapped_area`. The mmap() routines will call
315+
this to get a proposed address for the mapping.
316+
317+
To use :c:func:`drm_gem_cma_get_unmapped_area`, drivers must fill the
318+
struct :c:type:`struct file_operations <file_operations>` get_unmapped_area
319+
field with a pointer on :c:func:`drm_gem_cma_get_unmapped_area`.
320+
321+
More detailed information about get_unmapped_area can be found in
322+
Documentation/nommu-mmap.txt
323+
313324
Memory Coherency
314325
----------------
315326

‎drivers/gpu/drm/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
menuconfig DRM
88
tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
9-
depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU && HAS_DMA
9+
depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA
1010
select HDMI
1111
select FB_CMDLINE
1212
select I2C
@@ -113,7 +113,7 @@ config DRM_LOAD_EDID_FIRMWARE
113113

114114
config DRM_TTM
115115
tristate
116-
depends on DRM
116+
depends on DRM && MMU
117117
help
118118
GPU memory management subsystem for devices with multiple
119119
GPU memory types. Will be enabled automatically if a device driver

‎drivers/gpu/drm/drm_gem_cma_helper.c‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,77 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma)
358358
}
359359
EXPORT_SYMBOL_GPL(drm_gem_cma_mmap);
360360

361+
#ifndef CONFIG_MMU
362+
/**
363+
* drm_gem_cma_get_unmapped_area - propose address for mapping in noMMU cases
364+
* @filp: file object
365+
* @addr: memory address
366+
* @len: buffer size
367+
* @pgoff: page offset
368+
* @flags: memory flags
369+
*
370+
* This function is used in noMMU platforms to propose address mapping
371+
* for a given buffer.
372+
* It's intended to be used as a direct handler for the struct
373+
* &file_operations.get_unmapped_area operation.
374+
*
375+
* Returns:
376+
* mapping address on success or a negative error code on failure.
377+
*/
378+
unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
379+
unsigned long addr,
380+
unsigned long len,
381+
unsigned long pgoff,
382+
unsigned long flags)
383+
{
384+
struct drm_gem_cma_object *cma_obj;
385+
struct drm_gem_object *obj = NULL;
386+
struct drm_file *priv = filp->private_data;
387+
struct drm_device *dev = priv->minor->dev;
388+
struct drm_vma_offset_node *node;
389+
390+
if (drm_device_is_unplugged(dev))
391+
return -ENODEV;
392+
393+
drm_vma_offset_lock_lookup(dev->vma_offset_manager);
394+
node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager,
395+
pgoff,
396+
len >> PAGE_SHIFT);
397+
if (likely(node)) {
398+
obj = container_of(node, struct drm_gem_object, vma_node);
399+
/*
400+
* When the object is being freed, after it hits 0-refcnt it
401+
* proceeds to tear down the object. In the process it will
402+
* attempt to remove the VMA offset and so acquire this
403+
* mgr->vm_lock. Therefore if we find an object with a 0-refcnt
404+
* that matches our range, we know it is in the process of being
405+
* destroyed and will be freed as soon as we release the lock -
406+
* so we have to check for the 0-refcnted object and treat it as
407+
* invalid.
408+
*/
409+
if (!kref_get_unless_zero(&obj->refcount))
410+
obj = NULL;
411+
}
412+
413+
drm_vma_offset_unlock_lookup(dev->vma_offset_manager);
414+
415+
if (!obj)
416+
return -EINVAL;
417+
418+
if (!drm_vma_node_is_allowed(node, priv)) {
419+
drm_gem_object_unreference_unlocked(obj);
420+
return -EACCES;
421+
}
422+
423+
cma_obj = to_drm_gem_cma_obj(obj);
424+
425+
drm_gem_object_unreference_unlocked(obj);
426+
427+
return cma_obj->vaddr ? (unsigned long)cma_obj->vaddr : -EINVAL;
428+
}
429+
EXPORT_SYMBOL_GPL(drm_gem_cma_get_unmapped_area);
430+
#endif
431+
361432
#ifdef CONFIG_DEBUG_FS
362433
/**
363434
* drm_gem_cma_describe - describe a CMA GEM object for debugfs

‎include/drm/drm_gem_cma_helper.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
5353

5454
extern const struct vm_operations_struct drm_gem_cma_vm_ops;
5555

56+
#ifndef CONFIG_MMU
57+
unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
58+
unsigned long addr,
59+
unsigned long len,
60+
unsigned long pgoff,
61+
unsigned long flags);
62+
#else
63+
static inline unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
64+
unsigned long addr,
65+
unsigned long len,
66+
unsigned long pgoff,
67+
unsigned long flags)
68+
{
69+
return -EINVAL;
70+
}
71+
#endif
72+
5673
#ifdef CONFIG_DEBUG_FS
5774
void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
5875
#endif

0 commit comments

Comments
 (0)