Skip to content

Commit 413b757

Browse files
author
Thomas Zimmermann
committed
drm/omapdrm: Set VM flags in GEM-object mmap function
Use the mmap callback in struct drm_gem_object_funcs to set the VM flags. Replace a number of mmap helpers in omapdrm with their GEM helper counterparts. Generate DRM's file-operations instance with GEM's DEFINE_DRM_GEM_FOPS. The omapdrm driver uses DRM's drm_gem_mmap() helper to prepare the VMA structure. It then modifies the resulting VMA state in its own helper omap_gem_mmap_obj(). The patch improves this by setting up the VMA in the mmap callback in drm_gem_object_funcs, which is called from within drm_gem_mmap(). Omapdrm's omap_gem_mmap() and omap_gem_mmap() can then be removed from the driver. A call to drm_gem_mmap() is sufficient for the mmap operation. Finally, with the omap functions gone, the drivers file_ops in omapdriver_fops can be generated with DEFINE_DRM_GEM_FOPS, which sets DRM's default helpers. v2: * detailed commit message (Javier) * do not set VM_PFNMAP Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Acked-by: Maxime Ripard <[email protected]> Cc: Tomi Valkeinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5ad315c commit 413b757

File tree

4 files changed

+8
-38
lines changed

4 files changed

+8
-38
lines changed

drivers/gpu/drm/omapdrm/omap_drv.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -636,17 +636,7 @@ static int dev_open(struct drm_device *dev, struct drm_file *file)
636636
return 0;
637637
}
638638

639-
static const struct file_operations omapdriver_fops = {
640-
.owner = THIS_MODULE,
641-
.open = drm_open,
642-
.unlocked_ioctl = drm_ioctl,
643-
.compat_ioctl = drm_compat_ioctl,
644-
.release = drm_release,
645-
.mmap = omap_gem_mmap,
646-
.poll = drm_poll,
647-
.read = drm_read,
648-
.llseek = noop_llseek,
649-
};
639+
DEFINE_DRM_GEM_FOPS(omapdriver_fops);
650640

651641
static const struct drm_driver omap_drm_driver = {
652642
.driver_features = DRIVER_MODESET | DRIVER_GEM |

drivers/gpu/drm/omapdrm/omap_gem.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,26 +524,11 @@ static vm_fault_t omap_gem_fault(struct vm_fault *vmf)
524524
return ret;
525525
}
526526

527-
/** We override mainly to fix up some of the vm mapping flags.. */
528-
int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma)
529-
{
530-
int ret;
531-
532-
ret = drm_gem_mmap(filp, vma);
533-
if (ret) {
534-
DBG("mmap failed: %d", ret);
535-
return ret;
536-
}
537-
538-
return omap_gem_mmap_obj(vma->vm_private_data, vma);
539-
}
540-
541-
int omap_gem_mmap_obj(struct drm_gem_object *obj,
542-
struct vm_area_struct *vma)
527+
static int omap_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
543528
{
544529
struct omap_gem_object *omap_obj = to_omap_bo(obj);
545530

546-
vm_flags_mod(vma, VM_MIXEDMAP, VM_PFNMAP);
531+
vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP | VM_IO | VM_MIXEDMAP);
547532

548533
if (omap_obj->flags & OMAP_BO_WC) {
549534
vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
@@ -563,12 +548,14 @@ int omap_gem_mmap_obj(struct drm_gem_object *obj,
563548
* address_space (so unmap_mapping_range does what we want,
564549
* in particular in the case of mmap'd dmabufs)
565550
*/
566-
vma->vm_pgoff = 0;
551+
vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
567552
vma_set_file(vma, obj->filp);
568553

569554
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
570555
}
571556

557+
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
558+
572559
return 0;
573560
}
574561

@@ -1282,6 +1269,7 @@ static const struct vm_operations_struct omap_gem_vm_ops = {
12821269
static const struct drm_gem_object_funcs omap_gem_object_funcs = {
12831270
.free = omap_gem_free_object,
12841271
.export = omap_gem_prime_export,
1272+
.mmap = omap_gem_object_mmap,
12851273
.vm_ops = &omap_gem_vm_ops,
12861274
};
12871275

drivers/gpu/drm/omapdrm/omap_gem.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ int omap_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
5757
struct drm_mode_create_dumb *args);
5858

5959
/* mmap() Interface */
60-
int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma);
61-
int omap_gem_mmap_obj(struct drm_gem_object *obj,
62-
struct vm_area_struct *vma);
6360
u64 omap_gem_mmap_offset(struct drm_gem_object *obj);
6461
size_t omap_gem_mmap_size(struct drm_gem_object *obj);
6562

drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,8 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
6464
struct vm_area_struct *vma)
6565
{
6666
struct drm_gem_object *obj = buffer->priv;
67-
int ret = 0;
6867

69-
ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
70-
if (ret < 0)
71-
return ret;
72-
73-
return omap_gem_mmap_obj(obj, vma);
68+
return drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
7469
}
7570

7671
static const struct dma_buf_ops omap_dmabuf_ops = {

0 commit comments

Comments
 (0)