drm/udl: add cache flags definitions for udl_gem_object
authorHaixia Shi <hshi@chromium.org>
Thu, 13 Nov 2014 02:33:52 +0000 (18:33 -0800)
committerDave Airlie <airlied@redhat.com>
Thu, 20 Nov 2014 01:41:32 +0000 (11:41 +1000)
By default set udl_gem_object as cacheable, but set WC flag when attaching
dmabuf. In udl_gem_mmap() update cache attributes based on the flags, similar
to exynos_drm_gem_mmap().

Signed-off-by: Haixia Shi <hshi@chromium.org>
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/udl/udl_drv.h
drivers/gpu/drm/udl/udl_gem.c

index c7490a2489a750c2bc884761300b6b324c5b572a..308278086c7280090bd7083ac7e7bbb34fe9ec71 100644 (file)
@@ -25,6 +25,9 @@
 #define DRIVER_MINOR           0
 #define DRIVER_PATCHLEVEL      1
 
+#define UDL_BO_CACHEABLE               (1 << 0)
+#define UDL_BO_WC              (1 << 1)
+
 struct udl_device;
 
 struct urb_node {
@@ -69,6 +72,7 @@ struct udl_gem_object {
        struct page **pages;
        void *vmapping;
        struct sg_table *sg;
+       unsigned int flags;
 };
 
 #define to_udl_bo(x) container_of(x, struct udl_gem_object, base)
index 8044f5fb7c49a1f5709c6e1d62be72a798d465b8..e00459d38dcbf2370341b1355e343d56fc4437ad 100644 (file)
@@ -25,6 +25,7 @@ struct udl_gem_object *udl_gem_alloc_object(struct drm_device *dev,
                return NULL;
        }
 
+       obj->flags = UDL_BO_CACHEABLE;
        return obj;
 }
 
@@ -56,6 +57,23 @@ udl_gem_create(struct drm_file *file,
        return 0;
 }
 
+static void update_vm_cache_attr(struct udl_gem_object *obj,
+                                struct vm_area_struct *vma)
+{
+       DRM_DEBUG_KMS("flags = 0x%x\n", obj->flags);
+
+       /* non-cacheable as default. */
+       if (obj->flags & UDL_BO_CACHEABLE) {
+               vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
+       } else if (obj->flags & UDL_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));
+       }
+}
+
 int udl_dumb_create(struct drm_file *file,
                    struct drm_device *dev,
                    struct drm_mode_create_dumb *args)
@@ -77,6 +95,8 @@ int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
        vma->vm_flags &= ~VM_PFNMAP;
        vma->vm_flags |= VM_MIXEDMAP;
 
+       update_vm_cache_attr(to_udl_bo(vma->vm_private_data), vma);
+
        return ret;
 }
 
@@ -279,6 +299,7 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev,
        }
 
        uobj->base.import_attach = attach;
+       uobj->flags = UDL_BO_WC;
 
        return &uobj->base;