drm/mediatek: Implement mmap as GEM object function
Subsystems (3)
PATCH 1/1 drm/mediatek: 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 mediatek functions are being removed. The file_operations structure fops is now being created by the helper macro DEFINE_DRM_GEM_FOPS().
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++------ drivers/gpu/drm/mediatek/mtk_drm_gem.c | 44 +++++++------------------- drivers/gpu/drm/mediatek/mtk_drm_gem.h | 3 -- 3 files changed, 14 insertions(+), 46 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +2 -11
@@ -300,16 +300,7 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)component_unbind_all (drm->dev, drm); } -static const struct file_operations mtk_drm_fops = { - .owner =THIS_MODULE , - .open = drm_open, - .release = drm_release, - .unlocked_ioctl = drm_ioctl, - .mmap = mtk_drm_gem_mmap, - .poll = drm_poll, - .read = drm_read, - .compat_ioctl = drm_compat_ioctl, -}; +DEFINE_DRM_GEM_FOPS (mtk_drm_fops);/* * We need to override this because the device used to import the memory is
@@ -332,7 +323,7 @@ static const struct drm_driver mtk_drm_driver = { .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = mtk_drm_gem_prime_import, .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table, - .gem_prime_mmap = mtk_drm_gem_mmap_buf, + .gem_prime_mmap = drm_gem_prime_mmap, .fops = &mtk_drm_fops, .name = DRIVER_NAME,
drivers/gpu/drm/mediatek/mtk_drm_gem.c +12 -32
71 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_gem.h +0 -3
@@ -39,9 +39,6 @@ struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size, bool alloc_kmap);int mtk_drm_gem_dumb_create (struct drm_file *file_priv,struct drm_device *dev,struct drm_mode_create_dumb *args); -int mtk_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma); -int mtk_drm_gem_mmap_buf (struct drm_gem_object *obj, -struct vm_area_struct *vma);struct sg_table *mtk_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *mtk_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sg);
Signature · 1 line
2.32.0
ping for review
Am 24.06.21 um 11:01 schrieb Thomas Zimmermann:
Quoted 138 lines
Moving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks.
The respective mediatek functions are being removed. The
file_operationsstructure fops is now being created by the helper macroDEFINE_DRM_GEM_FOPS().Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++------ drivers/gpu/drm/mediatek/mtk_drm_gem.c | 44 +++++++------------------- drivers/gpu/drm/mediatek/mtk_drm_gem.h | 3 -- 3 files changed, 14 insertions(+), 46 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +2
-11@@ -300,16 +300,7 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)component_unbind_all (drm->dev, drm); } -static const struct file_operations mtk_drm_fops = { - .owner =THIS_MODULE , - .open = drm_open, - .release = drm_release, - .unlocked_ioctl = drm_ioctl, - .mmap = mtk_drm_gem_mmap, - .poll = drm_poll, - .read = drm_read, - .compat_ioctl = drm_compat_ioctl, -}; +DEFINE_DRM_GEM_FOPS (mtk_drm_fops);/* * We need to override this because the device used to import the memory is @@ -332,7 +323,7 @@ static const struct drm_driver mtk_drm_driver = { .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = mtk_drm_gem_prime_import, .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table, - .gem_prime_mmap = mtk_drm_gem_mmap_buf, + .gem_prime_mmap = drm_gem_prime_mmap, .fops = &mtk_drm_fops, .name = DRIVER_NAME,drivers/gpu/drm/mediatek/mtk_drm_gem.c +12
-32@@ -14,11 +14,14 @@#include "mtk_drm_drv.h" #include "mtk_drm_gem.h" +static int mtk_drm_gem_object_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma); +static const struct drm_gem_object_funcs mtk_drm_gem_object_funcs = { .free = mtk_drm_gem_free_object, .get_sg_table = mtk_gem_prime_get_sg_table, .vmap = mtk_drm_gem_prime_vmap, .vunmap = mtk_drm_gem_prime_vunmap, + .mmap = mtk_drm_gem_object_mmap, .vm_ops = &drm_gem_cma_vm_ops, };@@ -145,11 +148,19 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,struct mtk_drm_gem_obj *mtk_gem =to_mtk_gem_obj (obj);struct mtk_drm_private *priv = obj->dev->dev_private; +/* +* Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the +* whole buffer from the start. +*/ + vma->vm_pgoff =0 ; +/* * dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear * VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap(). */ - vma->vm_flags &= ~VM_PFNMAP ; + vma->vm_flags |=VM_IO |VM_DONTEXPAND |VM_DONTDUMP ; + vma->vm_page_prot =pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); + vma->vm_page_prot =pgprot_decrypted (vma->vm_page_prot); ret =dma_mmap_attrs (priv->dma_dev, vma, mtk_gem->cookie, mtk_gem->dma_addr, obj->size, mtk_gem->dma_attrs);@@ -159,37 +170,6 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,return ret; } -int mtk_drm_gem_mmap_buf (struct drm_gem_object *obj,struct vm_area_struct *vma) -{ -int ret; - - ret =drm_gem_mmap_obj (obj, obj->size, vma); -if (ret) -return ret; - -return mtk_drm_gem_object_mmap (obj, vma); -} - -int mtk_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) -{ -struct drm_gem_object *obj; -int ret; - - ret =drm_gem_mmap (filp, vma); -if (ret) -return ret; - - obj = vma->vm_private_data; - -/* -* Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the -* whole buffer from the start. -*/ - vma->vm_pgoff =0 ; - -return mtk_drm_gem_object_mmap (obj, vma); -} -/* * Allocate a sg_table for this GEM object. * Note: Both the table's contents, and the sg_table itself must be freed by drivers/gpu/drm/mediatek/mtk_drm_gem.h +0
-3@@ -39,9 +39,6 @@ struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size, bool alloc_kmap);int mtk_drm_gem_dumb_create (struct drm_file *file_priv,struct drm_device *dev,struct drm_mode_create_dumb *args); -int mtk_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma); -int mtk_drm_gem_mmap_buf (struct drm_gem_object *obj, -struct vm_area_struct *vma);struct sg_table *mtk_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *mtk_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sg);
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Hi, Thomas:
Thomas Zimmermann <[email protected]> 於 2021年6月24日 週四 下午5:01寫道:
Quoted 7 lines
Moving the driver-specific mmap code into a GEM object function allows for using DRM helpers for various mmap callbacks.
The respective mediatek functions are being removed. The
file_operationsstructure fops is now being created by the helper macroDEFINE_DRM_GEM_FOPS().
Applied to mediatek-drm-next [1], thanks.
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next
Regards,
Chun-Kuang.
Quoted 134 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++------ drivers/gpu/drm/mediatek/mtk_drm_gem.c | 44 +++++++------------------- drivers/gpu/drm/mediatek/mtk_drm_gem.h | 3 -- 3 files changed, 14 insertions(+), 46 deletions(-)drivers/gpu/drm/mediatek/mtk_drm_drv.c +2
-11@@ -300,16 +300,7 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)component_unbind_all (drm->dev, drm); } -static const struct file_operations mtk_drm_fops = { - .owner =THIS_MODULE , - .open = drm_open, - .release = drm_release, - .unlocked_ioctl = drm_ioctl, - .mmap = mtk_drm_gem_mmap, - .poll = drm_poll, - .read = drm_read, - .compat_ioctl = drm_compat_ioctl, -}; +DEFINE_DRM_GEM_FOPS (mtk_drm_fops);/* * We need to override this because the device used to import the memory is @@ -332,7 +323,7 @@ static const struct drm_driver mtk_drm_driver = { .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_import = mtk_drm_gem_prime_import, .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table, - .gem_prime_mmap = mtk_drm_gem_mmap_buf, + .gem_prime_mmap = drm_gem_prime_mmap, .fops = &mtk_drm_fops, .name = DRIVER_NAME,drivers/gpu/drm/mediatek/mtk_drm_gem.c +12
-32@@ -14,11 +14,14 @@#include "mtk_drm_drv.h" #include "mtk_drm_gem.h" +static int mtk_drm_gem_object_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma); +static const struct drm_gem_object_funcs mtk_drm_gem_object_funcs = { .free = mtk_drm_gem_free_object, .get_sg_table = mtk_gem_prime_get_sg_table, .vmap = mtk_drm_gem_prime_vmap, .vunmap = mtk_drm_gem_prime_vunmap, + .mmap = mtk_drm_gem_object_mmap, .vm_ops = &drm_gem_cma_vm_ops, };@@ -145,11 +148,19 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,struct mtk_drm_gem_obj *mtk_gem =to_mtk_gem_obj (obj);struct mtk_drm_private *priv = obj->dev->dev_private; +/* +* Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the +* whole buffer from the start. +*/ + vma->vm_pgoff =0 ; +/* * dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear * VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap(). */ - vma->vm_flags &= ~VM_PFNMAP ; + vma->vm_flags |=VM_IO |VM_DONTEXPAND |VM_DONTDUMP ; + vma->vm_page_prot =pgprot_writecombine (vm_get_page_prot (vma->vm_flags)); + vma->vm_page_prot =pgprot_decrypted (vma->vm_page_prot); ret =dma_mmap_attrs (priv->dma_dev, vma, mtk_gem->cookie, mtk_gem->dma_addr, obj->size, mtk_gem->dma_attrs);@@ -159,37 +170,6 @@ static int mtk_drm_gem_object_mmap(struct drm_gem_object *obj,return ret; } -int mtk_drm_gem_mmap_buf (struct drm_gem_object *obj,struct vm_area_struct *vma) -{ -int ret; - - ret =drm_gem_mmap_obj (obj, obj->size, vma); -if (ret) -return ret; - -return mtk_drm_gem_object_mmap (obj, vma); -} - -int mtk_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma) -{ -struct drm_gem_object *obj; -int ret; - - ret =drm_gem_mmap (filp, vma); -if (ret) -return ret; - - obj = vma->vm_private_data; - -/* -* Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the -* whole buffer from the start. -*/ - vma->vm_pgoff =0 ; - -return mtk_drm_gem_object_mmap (obj, vma); -} -/* * Allocate a sg_table for this GEM object. * Note: Both the table's contents, and the sg_table itself must be freed by drivers/gpu/drm/mediatek/mtk_drm_gem.h +0
-4@@ -39,9 +39,6 @@ struct mtk_drm_gem_obj *mtk_drm_gem_create(struct drm_device *dev, size_t size, bool alloc_kmap);int mtk_drm_gem_dumb_create (struct drm_file *file_priv,struct drm_device *dev,struct drm_mode_create_dumb *args); -int mtk_drm_gem_mmap (struct file *filp,struct vm_area_struct *vma); -int mtk_drm_gem_mmap_buf (struct drm_gem_object *obj, -struct vm_area_struct *vma);struct sg_table *mtk_gem_prime_get_sg_table (struct drm_gem_object *obj);struct drm_gem_object *mtk_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sg); --2.32.0