drm/exynos: Implement mmap as GEM object function
Moving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks. The respective exynos functions are being removed. The file_operations structure exynos_drm_driver_fops is now being created by the helper macro DEFINE_DRM_GEM_FOPS(). Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> Fixed merge conflict. Signed-off-by: Inki Dae <inki.dae@samsung.com>
This commit is contained in:
parent
ee6c8b5afa
commit
2043e6f6d5
|
@ -102,16 +102,7 @@ static const struct drm_ioctl_desc exynos_ioctls[] = {
|
|||
DRM_RENDER_ALLOW),
|
||||
};
|
||||
|
||||
static const struct file_operations exynos_drm_driver_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = drm_open,
|
||||
.mmap = exynos_drm_gem_mmap,
|
||||
.poll = drm_poll,
|
||||
.read = drm_read,
|
||||
.unlocked_ioctl = drm_ioctl,
|
||||
.compat_ioctl = drm_compat_ioctl,
|
||||
.release = drm_release,
|
||||
};
|
||||
DEFINE_DRM_GEM_FOPS(exynos_drm_driver_fops);
|
||||
|
||||
static const struct drm_driver exynos_drm_driver = {
|
||||
.driver_features = DRIVER_MODESET | DRIVER_GEM
|
||||
|
@ -124,7 +115,7 @@ static const struct drm_driver exynos_drm_driver = {
|
|||
.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
|
||||
.gem_prime_import = exynos_drm_gem_prime_import,
|
||||
.gem_prime_import_sg_table = exynos_drm_gem_prime_import_sg_table,
|
||||
.gem_prime_mmap = exynos_drm_gem_prime_mmap,
|
||||
.gem_prime_mmap = drm_gem_prime_mmap,
|
||||
.ioctls = exynos_ioctls,
|
||||
.num_ioctls = ARRAY_SIZE(exynos_ioctls),
|
||||
.fops = &exynos_drm_driver_fops,
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <drm/drm_crtc.h>
|
||||
#include <drm/drm_fb_helper.h>
|
||||
#include <drm/drm_fourcc.h>
|
||||
#include <drm/drm_prime.h>
|
||||
#include <drm/drm_probe_helper.h>
|
||||
#include <drm/exynos_drm.h>
|
||||
|
||||
|
@ -39,25 +40,8 @@ static int exynos_drm_fb_mmap(struct fb_info *info,
|
|||
struct drm_fb_helper *helper = info->par;
|
||||
struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(helper);
|
||||
struct exynos_drm_gem *exynos_gem = exynos_fbd->exynos_gem;
|
||||
unsigned long vm_size;
|
||||
int ret;
|
||||
|
||||
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
|
||||
|
||||
vm_size = vma->vm_end - vma->vm_start;
|
||||
|
||||
if (vm_size > exynos_gem->size)
|
||||
return -EINVAL;
|
||||
|
||||
ret = dma_mmap_attrs(to_dma_dev(helper->dev), vma, exynos_gem->cookie,
|
||||
exynos_gem->dma_addr, exynos_gem->size,
|
||||
exynos_gem->dma_attrs);
|
||||
if (ret < 0) {
|
||||
DRM_DEV_ERROR(to_dma_dev(helper->dev), "failed to mmap.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return drm_gem_prime_mmap(&exynos_gem->base, vma);
|
||||
}
|
||||
|
||||
static const struct fb_ops exynos_drm_fb_ops = {
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
MODULE_IMPORT_NS(DMA_BUF);
|
||||
|
||||
static int exynos_drm_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
|
||||
|
||||
static int exynos_drm_alloc_buf(struct exynos_drm_gem *exynos_gem, bool kvmap)
|
||||
{
|
||||
struct drm_device *dev = exynos_gem->base.dev;
|
||||
|
@ -138,6 +140,7 @@ static const struct vm_operations_struct exynos_drm_gem_vm_ops = {
|
|||
static const struct drm_gem_object_funcs exynos_drm_gem_object_funcs = {
|
||||
.free = exynos_drm_gem_free_object,
|
||||
.get_sg_table = exynos_drm_gem_prime_get_sg_table,
|
||||
.mmap = exynos_drm_gem_mmap,
|
||||
.vm_ops = &exynos_drm_gem_vm_ops,
|
||||
};
|
||||
|
||||
|
@ -357,12 +360,16 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int exynos_drm_gem_mmap_obj(struct drm_gem_object *obj,
|
||||
struct vm_area_struct *vma)
|
||||
static int exynos_drm_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
|
||||
{
|
||||
struct exynos_drm_gem *exynos_gem = to_exynos_gem(obj);
|
||||
int ret;
|
||||
|
||||
if (obj->import_attach)
|
||||
return dma_buf_mmap(obj->dma_buf, vma, 0);
|
||||
|
||||
vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
|
||||
|
||||
DRM_DEV_DEBUG_KMS(to_dma_dev(obj->dev), "flags = 0x%x\n",
|
||||
exynos_gem->flags);
|
||||
|
||||
|
@ -388,26 +395,6 @@ err_close_vm:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
|
||||
{
|
||||
struct drm_gem_object *obj;
|
||||
int ret;
|
||||
|
||||
/* set vm_area_struct. */
|
||||
ret = drm_gem_mmap(filp, vma);
|
||||
if (ret < 0) {
|
||||
DRM_ERROR("failed to mmap.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
obj = vma->vm_private_data;
|
||||
|
||||
if (obj->import_attach)
|
||||
return dma_buf_mmap(obj->dma_buf, vma, 0);
|
||||
|
||||
return exynos_drm_gem_mmap_obj(obj, vma);
|
||||
}
|
||||
|
||||
/* low-level interface prime helpers */
|
||||
struct drm_gem_object *exynos_drm_gem_prime_import(struct drm_device *dev,
|
||||
struct dma_buf *dma_buf)
|
||||
|
@ -469,15 +456,3 @@ exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
|
|||
exynos_gem->sgt = sgt;
|
||||
return &exynos_gem->base;
|
||||
}
|
||||
|
||||
int exynos_drm_gem_prime_mmap(struct drm_gem_object *obj,
|
||||
struct vm_area_struct *vma)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = drm_gem_mmap_obj(obj, obj->size, vma);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return exynos_drm_gem_mmap_obj(obj, vma);
|
||||
}
|
||||
|
|
|
@ -96,9 +96,6 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
|
|||
struct drm_device *dev,
|
||||
struct drm_mode_create_dumb *args);
|
||||
|
||||
/* set vm_flags and we can change the vm attribute to other one at here. */
|
||||
int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
|
||||
|
||||
/* low-level interface prime helpers */
|
||||
struct drm_gem_object *exynos_drm_gem_prime_import(struct drm_device *dev,
|
||||
struct dma_buf *dma_buf);
|
||||
|
@ -107,7 +104,5 @@ struct drm_gem_object *
|
|||
exynos_drm_gem_prime_import_sg_table(struct drm_device *dev,
|
||||
struct dma_buf_attachment *attach,
|
||||
struct sg_table *sgt);
|
||||
int exynos_drm_gem_prime_mmap(struct drm_gem_object *obj,
|
||||
struct vm_area_struct *vma);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue