drm/gem: add drm_gem_create_mmap_offset_size()

Variant of drm_gem_create_mmap_offset() which doesn't make the
assumption that virtual size and physical size (obj->size) are the same.
This is needed in omapdrm to deal with tiled buffers.  And lets us get
rid of a duplicated and slightly modified version of
drm_gem_create_mmap_offset() in omapdrm.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Rob Clark 2013-08-07 13:41:23 -04:00 committed by Dave Airlie
parent 5833bd2fe1
commit 367bbd4920
2 changed files with 28 additions and 7 deletions

View File

@ -316,6 +316,31 @@ drm_gem_free_mmap_offset(struct drm_gem_object *obj)
} }
EXPORT_SYMBOL(drm_gem_free_mmap_offset); EXPORT_SYMBOL(drm_gem_free_mmap_offset);
/**
* drm_gem_create_mmap_offset_size - create a fake mmap offset for an object
* @obj: obj in question
* @size: the virtual size
*
* GEM memory mapping works by handing back to userspace a fake mmap offset
* it can use in a subsequent mmap(2) call. The DRM core code then looks
* up the object based on the offset and sets up the various memory mapping
* structures.
*
* This routine allocates and attaches a fake offset for @obj, in cases where
* the virtual size differs from the physical size (ie. obj->size). Otherwise
* just use drm_gem_create_mmap_offset().
*/
int
drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size)
{
struct drm_device *dev = obj->dev;
struct drm_gem_mm *mm = dev->mm_private;
return drm_vma_offset_add(&mm->vma_manager, &obj->vma_node,
size / PAGE_SIZE);
}
EXPORT_SYMBOL(drm_gem_create_mmap_offset_size);
/** /**
* drm_gem_create_mmap_offset - create a fake mmap offset for an object * drm_gem_create_mmap_offset - create a fake mmap offset for an object
* @obj: obj in question * @obj: obj in question
@ -327,14 +352,9 @@ EXPORT_SYMBOL(drm_gem_free_mmap_offset);
* *
* This routine allocates and attaches a fake offset for @obj. * This routine allocates and attaches a fake offset for @obj.
*/ */
int int drm_gem_create_mmap_offset(struct drm_gem_object *obj)
drm_gem_create_mmap_offset(struct drm_gem_object *obj)
{ {
struct drm_device *dev = obj->dev; return drm_gem_create_mmap_offset_size(obj, obj->size);
struct drm_gem_mm *mm = dev->mm_private;
return drm_vma_offset_add(&mm->vma_manager, &obj->vma_node,
obj->size / PAGE_SIZE);
} }
EXPORT_SYMBOL(drm_gem_create_mmap_offset); EXPORT_SYMBOL(drm_gem_create_mmap_offset);

View File

@ -1614,6 +1614,7 @@ drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
void drm_gem_free_mmap_offset(struct drm_gem_object *obj); void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
int drm_gem_create_mmap_offset(struct drm_gem_object *obj); int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
struct drm_file *filp, struct drm_file *filp,