@@ -372,10 +372,13 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
struct exynos_drm_gem_buf *buffer;
unsigned long vm_size;
+ int ret;
DRM_DEBUG_KMS("%s\n", __FILE__);
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
+ vma->vm_private_data = obj;
+ vma->vm_ops = obj->dev->driver->gem_vm_ops;
update_vm_cache_attr(exynos_gem_obj, vma);
@@ -391,9 +394,22 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
if (vm_size > buffer->size)
return -EINVAL;
- return dma_mmap_attrs(obj->dev->dev, vma, buffer->kvaddr,
+ ret = dma_mmap_attrs(obj->dev->dev, vma, buffer->kvaddr,
buffer->dma_addr, buffer->size,
&buffer->dma_attrs);
+ if (ret < 0) {
+ DRM_ERROR("failed to mmap.\n");
+ return ret;
+ }
+
+ /*
+ * take a reference to this mapping of the object. And this reference
+ * is unreferenced by the corresponding vm_close call.
+ */
+ drm_gem_object_reference(obj);
+ drm_vm_open_locked(obj->dev, vma);
+
+ return 0;
}
static const struct file_operations exynos_drm_gem_fops = {
@@ -426,6 +442,8 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
addr = vm_mmap(obj->filp, 0, args->size,
PROT_READ | PROT_WRITE, MAP_SHARED, 0);
+ /* restore it to drm_file object. */
+ obj->filp->private_data = file_priv;
drm_gem_object_unreference_unlocked(obj);
if (IS_ERR((void *)addr))