drm/rockchip: support cpu cache for drm memory
authorMark Yao <mark.yao@rock-chips.com>
Fri, 17 Feb 2017 11:49:08 +0000 (19:49 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Wed, 22 Feb 2017 06:51:15 +0000 (14:51 +0800)
Change-Id: Ic9ca3d0862eb8c5c4d8a002db8cbbcc93d2dcc02
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
drivers/gpu/drm/rockchip/rockchip_drm_gem.c
include/uapi/drm/rockchip_drm.h

index 58b6ecf8b4ca1d9003218be6550d89a33ea1bfb8..4a7bc553e75e9ba71c64ff3c08a74a5214b5f07a 100644 (file)
@@ -264,6 +264,10 @@ static int rockchip_drm_gem_object_mmap(struct drm_gem_object *obj,
        int ret;
        struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);
 
+       /* default is wc. */
+       if (rk_obj->flags & ROCKCHIP_BO_CACHABLE)
+               vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
+
        /*
         * We allocated a struct page table for rk_obj, so clear
         * VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap().
@@ -400,7 +404,7 @@ void rockchip_gem_free_object(struct drm_gem_object *obj)
 static struct rockchip_gem_object *
 rockchip_gem_create_with_handle(struct drm_file *file_priv,
                                struct drm_device *drm, unsigned int size,
-                               unsigned int *handle)
+                               unsigned int *handle, unsigned int flags)
 {
        struct rockchip_gem_object *rk_obj;
        struct drm_gem_object *obj;
@@ -420,6 +424,8 @@ rockchip_gem_create_with_handle(struct drm_file *file_priv,
        if (ret)
                goto err_handle_create;
 
+       rk_obj->flags = flags;
+
        /* drop reference from allocate - handle holds it now. */
        drm_gem_object_unreference_unlocked(obj);
 
@@ -478,7 +484,7 @@ int rockchip_gem_dumb_create(struct drm_file *file_priv,
        args->size = args->pitch * args->height;
 
        rk_obj = rockchip_gem_create_with_handle(file_priv, dev, args->size,
-                                                &args->handle);
+                                                &args->handle, args->flags);
 
        return PTR_ERR_OR_ZERO(rk_obj);
 }
@@ -499,7 +505,7 @@ int rockchip_gem_create_ioctl(struct drm_device *dev, void *data,
        struct rockchip_gem_object *rk_obj;
 
        rk_obj = rockchip_gem_create_with_handle(file_priv, dev, args->size,
-                                                &args->handle);
+                                                &args->handle, args->flags);
        return PTR_ERR_OR_ZERO(rk_obj);
 }
 
index fbc3f493cb20fa9d0838119bef8b95d5b57fd7d3..ef25ccf3a8ac4d5ac072966076ee1aaa05f13443 100644 (file)
 
 #include <drm/drm.h>
 
+/* memory type definitions. */
+enum drm_rockchip_gem_mem_type {
+       /* Physically Continuous memory and used as default. */
+       ROCKCHIP_BO_CONTIG      = 0 << 0,
+       /* Physically Non-Continuous memory. */
+       ROCKCHIP_BO_NONCONTIG   = 1 << 0,
+       /* non-cachable mapping and used as default. */
+       ROCKCHIP_BO_NONCACHABLE = 0 << 1,
+       /* cachable mapping. */
+       ROCKCHIP_BO_CACHABLE    = 1 << 1,
+       /* write-combine mapping. */
+       ROCKCHIP_BO_WC          = 1 << 2,
+       ROCKCHIP_BO_MASK        = ROCKCHIP_BO_NONCONTIG | ROCKCHIP_BO_CACHABLE |
+                               ROCKCHIP_BO_WC
+};
+
 /**
  * User-desired buffer creation information structure.
  *