Skip to content

Commit

Permalink
drm/shmem: add support for per object caching flags.
Browse files Browse the repository at this point in the history
Add map_cached bool to drm_gem_shmem_object, to request cached mappings
on a per-object base.  Check the flag before adding writecombine to
pgprot bits.

Cc: stable@vger.kernel.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Guillaume Gardet <Guillaume.Gardet@arm.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200226154752.24328-2-kraxel@redhat.com
  • Loading branch information
Gerd Hoffmann committed Feb 27, 2020
1 parent d1f3722 commit 1cad629
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/gpu/drm/drm_gem_shmem_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
if (ret)
goto err_zero_use;

if (obj->import_attach)
if (obj->import_attach) {
shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf);
else
} else {
pgprot_t prot = PAGE_KERNEL;

if (!shmem->map_cached)
prot = pgprot_writecombine(prot);
shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
VM_MAP, pgprot_writecombine(PAGE_KERNEL));
VM_MAP, prot);
}

if (!shmem->vaddr) {
DRM_DEBUG_KMS("Failed to vmap pages\n");
Expand Down Expand Up @@ -540,7 +545,9 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
}

vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND;
vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
if (!shmem->map_cached)
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
vma->vm_ops = &drm_gem_shmem_vm_ops;

Expand Down
5 changes: 5 additions & 0 deletions include/drm/drm_gem_shmem_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ struct drm_gem_shmem_object {
* The address are un-mapped when the count reaches zero.
*/
unsigned int vmap_use_count;

/**
* @map_cached: map object cached (instead of using writecombine).
*/
bool map_cached;
};

#define to_drm_gem_shmem_obj(obj) \
Expand Down

0 comments on commit 1cad629

Please sign in to comment.