Commit c01d73fa authored by Inki Dae's avatar Inki Dae

drm/exynos: added cache attribute support for gem.

with this patch, user application can set cache attribute(such as
cachable, writecombime or non-cachable) of the memory region allocated
by gem framework.
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
parent 922f6e99
...@@ -66,6 +66,22 @@ static int check_gem_flags(unsigned int flags) ...@@ -66,6 +66,22 @@ static int check_gem_flags(unsigned int flags)
return 0; return 0;
} }
static void update_vm_cache_attr(struct exynos_drm_gem_obj *obj,
struct vm_area_struct *vma)
{
DRM_DEBUG_KMS("flags = 0x%x\n", obj->flags);
/* non-cachable as default. */
if (obj->flags & EXYNOS_BO_CACHABLE)
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
else if (obj->flags & EXYNOS_BO_WC)
vma->vm_page_prot =
pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
else
vma->vm_page_prot =
pgprot_noncached(vm_get_page_prot(vma->vm_flags));
}
static unsigned long roundup_gem_size(unsigned long size, unsigned int flags) static unsigned long roundup_gem_size(unsigned long size, unsigned int flags)
{ {
if (!IS_NONCONTIG_BUFFER(flags)) { if (!IS_NONCONTIG_BUFFER(flags)) {
...@@ -262,24 +278,24 @@ static int exynos_drm_gem_handle_create(struct drm_gem_object *obj, ...@@ -262,24 +278,24 @@ static int exynos_drm_gem_handle_create(struct drm_gem_object *obj,
void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj) void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj)
{ {
struct drm_gem_object *obj; struct drm_gem_object *obj;
struct exynos_drm_gem_buf *buf;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
if (!exynos_gem_obj)
return;
obj = &exynos_gem_obj->base; obj = &exynos_gem_obj->base;
buf = exynos_gem_obj->buffer;
DRM_DEBUG_KMS("handle count = %d\n", atomic_read(&obj->handle_count)); DRM_DEBUG_KMS("handle count = %d\n", atomic_read(&obj->handle_count));
if ((exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) && if (!buf->pages)
exynos_gem_obj->buffer->pages) return;
if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG)
exynos_drm_gem_put_pages(obj); exynos_drm_gem_put_pages(obj);
else else
exynos_drm_free_buf(obj->dev, exynos_gem_obj->flags, exynos_drm_free_buf(obj->dev, exynos_gem_obj->flags, buf);
exynos_gem_obj->buffer);
exynos_drm_fini_buf(obj->dev, exynos_gem_obj->buffer); exynos_drm_fini_buf(obj->dev, buf);
exynos_gem_obj->buffer = NULL; exynos_gem_obj->buffer = NULL;
if (obj->map_list.map) if (obj->map_list.map)
...@@ -493,8 +509,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, ...@@ -493,8 +509,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
vma->vm_flags |= (VM_IO | VM_RESERVED); vma->vm_flags |= (VM_IO | VM_RESERVED);
/* in case of direct mapping, always having non-cachable attribute */ update_vm_cache_attr(exynos_gem_obj, vma);
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
vm_size = usize = vma->vm_end - vma->vm_start; vm_size = usize = vma->vm_end - vma->vm_start;
...@@ -724,6 +739,8 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) ...@@ -724,6 +739,8 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj;
struct drm_gem_object *obj;
int ret; int ret;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
...@@ -735,8 +752,20 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -735,8 +752,20 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
return ret; return ret;
} }
obj = vma->vm_private_data;
exynos_gem_obj = to_exynos_gem_obj(obj);
ret = check_gem_flags(exynos_gem_obj->flags);
if (ret) {
drm_gem_vm_close(vma);
drm_gem_free_mmap_offset(obj);
return ret;
}
vma->vm_flags &= ~VM_PFNMAP; vma->vm_flags &= ~VM_PFNMAP;
vma->vm_flags |= VM_MIXEDMAP; vma->vm_flags |= VM_MIXEDMAP;
update_vm_cache_attr(exynos_gem_obj, vma);
return ret; return ret;
} }
...@@ -95,9 +95,18 @@ struct drm_exynos_plane_set_zpos { ...@@ -95,9 +95,18 @@ struct drm_exynos_plane_set_zpos {
/* memory type definitions. */ /* memory type definitions. */
enum e_drm_exynos_gem_mem_type { enum e_drm_exynos_gem_mem_type {
/* Physically Continuous memory and used as default. */
EXYNOS_BO_CONTIG = 0 << 0,
/* Physically Non-Continuous memory. */ /* Physically Non-Continuous memory. */
EXYNOS_BO_NONCONTIG = 1 << 0, EXYNOS_BO_NONCONTIG = 1 << 0,
EXYNOS_BO_MASK = EXYNOS_BO_NONCONTIG /* non-cachable mapping and used as default. */
EXYNOS_BO_NONCACHABLE = 0 << 1,
/* cachable mapping. */
EXYNOS_BO_CACHABLE = 1 << 1,
/* write-combine mapping. */
EXYNOS_BO_WC = 1 << 2,
EXYNOS_BO_MASK = EXYNOS_BO_NONCONTIG | EXYNOS_BO_CACHABLE |
EXYNOS_BO_WC
}; };
#define DRM_EXYNOS_GEM_CREATE 0x00 #define DRM_EXYNOS_GEM_CREATE 0x00
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment