[Openchrome-devel] drm-openchrome: 3 commits - drivers/gpu/drm

James Simmons jsimmons at kemper.freedesktop.org
Mon Dec 29 19:38:07 PST 2014


 drivers/gpu/drm/via/init_ttm.c  |   10 -----
 drivers/gpu/drm/via/ttm_gem.c   |   65 +++++++++++++++++++++++----------
 drivers/gpu/drm/via/via_crtc.c  |   12 +++---
 drivers/gpu/drm/via/via_drv.c   |   23 +++++++----
 drivers/gpu/drm/via/via_drv.h   |   38 -------------------
 drivers/gpu/drm/via/via_fb.c    |   11 ++---
 drivers/gpu/drm/via/via_ioc32.c |   30 ++++++++-------
 drivers/gpu/drm/via/via_mem.h   |   77 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/via/via_ttm.c   |    4 +-
 9 files changed, 169 insertions(+), 101 deletions(-)

New commits:
commit fb00c5aeefdad1ba0274971ec2071e157f0a11d9
Merge: c72c0f1 f3ab97b
Author: James Simmons <jsimmons at infradead.org>
Date:   Mon Dec 29 22:32:08 2014 -0500

    Merge branch 'master' of git.freedesktop.org:/git/openchrome/drm-openchrome
    
    Conflicts:
    	drivers/gpu/drm/via/ttm_gem.c
    	drivers/gpu/drm/via/via_drv.h
    	drivers/gpu/drm/via/via_fb.c

commit c72c0f1193676d48bffd12d10d0bf93c336b1acf
Author: James Simmons <jsimmons at infradead.org>
Date:   Sun Dec 28 17:19:06 2014 -0500

    drm/via: Remove dependency on gem object private field
    
    In newer kernels the private field in struct drm_gem_object
    disappears. Also gem_object_init() handling will migrate to
    gem_object_open() so we preform this update here. Added a
    header to expose struct ttm_heap to the GEM handling code.
    
    Signed-off-by: James Simmons <jsimmons at infradead.org>

diff --git a/drivers/gpu/drm/via/init_ttm.c b/drivers/gpu/drm/via/init_ttm.c
index 1688d4f..71d02bc 100644
--- a/drivers/gpu/drm/via/init_ttm.c
+++ b/drivers/gpu/drm/via/init_ttm.c
@@ -22,18 +22,10 @@
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#include "drmP.h"
-#include "ttm/ttm_bo_driver.h"
-#include "ttm/ttm_placement.h"
+#include "via_mem.h"
 
 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
 
-struct ttm_heap {
-	uint32_t busy_placements[TTM_NUM_MEM_TYPES];
-	uint32_t placements[TTM_NUM_MEM_TYPES];
-	struct ttm_buffer_object pbo;
-};
-
 static int
 ttm_global_mem_init(struct drm_global_reference *ref)
 {
diff --git a/drivers/gpu/drm/via/ttm_gem.c b/drivers/gpu/drm/via/ttm_gem.c
index a78c2a01..ed20925 100644
--- a/drivers/gpu/drm/via/ttm_gem.c
+++ b/drivers/gpu/drm/via/ttm_gem.c
@@ -23,10 +23,15 @@
 #include "drmP.h"
 #include "via_drv.h"
 
+struct ttm_gem_object {
+	struct drm_gem_object gem;
+	struct ttm_heap *heap;
+};
+
 /*
  * initialize the gem buffer object
  */
-int ttm_gem_init_object(struct drm_gem_object *obj)
+int ttm_gem_open_object(struct drm_gem_object *obj, struct drm_file *file_priv)
 {
 	return 0;
 }
@@ -36,14 +41,27 @@ int ttm_gem_init_object(struct drm_gem_object *obj)
  */
 void ttm_gem_free_object(struct drm_gem_object *obj)
 {
-	struct ttm_buffer_object *bo = obj->driver_private;
+	struct ttm_gem_object *gem = container_of(obj, struct ttm_gem_object, gem);
+
+	if (gem->heap != NULL) {
+		struct ttm_buffer_object *bo = &gem->heap->pbo;
 
-	if (bo) {
-		obj->driver_private = NULL;
 		ttm_bo_unref(&bo);
+		gem->heap = NULL;
 	}
 	drm_gem_object_release(obj);
-	kfree(obj);
+	kfree(gem);
+}
+
+struct ttm_buffer_object *
+ttm_gem_mapping(struct drm_gem_object *obj)
+{
+	struct ttm_gem_object *gem;
+
+	gem = container_of(obj, struct ttm_gem_object, gem);
+	if (gem->heap == NULL)
+		return NULL;
+	return &gem->heap->pbo;
 }
 
 /*
@@ -66,30 +84,37 @@ int ttm_mmap(struct file *filp, struct vm_area_struct *vma)
 }
 
 struct drm_gem_object *
-ttm_gem_create(struct drm_device *dev, struct ttm_bo_device *bdev, int types,
-		bool interruptible, int byte_align, int page_align,
-		unsigned long size)
+ttm_gem_create(struct drm_device *dev, struct ttm_bo_device *bdev,
+		enum ttm_bo_type origin, int types, bool interruptible,
+		int byte_align, int page_align, unsigned long size)
 {
 	struct ttm_buffer_object *bo = NULL;
-	struct drm_gem_object *obj;
+	struct ttm_gem_object *obj;
 	int ret;
 
 	size = round_up(size, byte_align);
 	size = ALIGN(size, page_align);
 
-	obj = drm_gem_object_alloc(dev, size);
-	if (!obj)
-		return ERR_PTR(-ENOMEM);
-
-	ret = ttm_bo_allocate(bdev, size, ttm_bo_type_device, types,
-				byte_align, page_align, interruptible,
-				NULL, &bo);
+	ret = ttm_bo_allocate(bdev, size, origin, types, byte_align,
+			      page_align, interruptible, NULL, &bo);
 	if (ret) {
 		DRM_ERROR("Failed to create buffer object\n");
-		drm_gem_object_unreference_unlocked(obj);
 		return ERR_PTR(ret);
 	}
-	bo->persistent_swap_storage = obj->filp;
-	obj->driver_private = bo;
-	return obj;
+
+	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
+	if (!obj) {
+		ttm_bo_unref(&bo);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	ret = drm_gem_object_init(dev, &obj->gem, size);
+	if (unlikely(ret)) {
+		ttm_bo_unref(&bo);
+		return ERR_PTR(ret);
+	}
+
+	obj->heap = container_of(bo, struct ttm_heap, pbo);
+	bo->persistent_swap_storage = obj->gem.filp;
+	return &obj->gem;
 }
diff --git a/drivers/gpu/drm/via/via_crtc.c b/drivers/gpu/drm/via/via_crtc.c
index 546066e..fa7311e 100644
--- a/drivers/gpu/drm/via/via_crtc.c
+++ b/drivers/gpu/drm/via/via_crtc.c
@@ -111,12 +111,12 @@ via_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
 	}
 
 	obj = drm_gem_object_lookup(dev, file_priv, handle);
-	if (!obj || !obj->driver_private) {
+	if (!obj) {
 		DRM_ERROR("Cannot find cursor object %x for crtc %d\n", handle, crtc->base.id);
 		return -ENOENT;
 	}
 
-	user_kmap.bo = obj->driver_private;
+	user_kmap.bo = ttm_gem_mapping(obj);
 	ret = ttm_bo_kmap(user_kmap.bo, 0, user_kmap.bo->num_pages, &user_kmap);
 	if (!ret) {
 		/* Copy data from userland to cursor memory region */
@@ -1160,7 +1160,7 @@ via_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
 		return ret;
 
 	obj = new_fb->helper_private;
-	bo = obj->driver_private;
+	bo = ttm_gem_mapping(obj);
 
 	ret = ttm_bo_pin(bo, NULL);
 	if (unlikely(ret)) {
@@ -1179,7 +1179,7 @@ via_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
 	/* Free the old framebuffer if it exist */
 	if (fb) {
 		obj = fb->helper_private;
-		bo = obj->driver_private;
+		bo = ttm_gem_mapping(obj);
 
 		ret = ttm_bo_unpin(bo, NULL);
 		if (unlikely(ret))
@@ -1196,7 +1196,7 @@ via_iga1_mode_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
 	struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
 	struct drm_via_private *dev_priv = crtc->dev->dev_private;
 	struct drm_gem_object *obj = fb->helper_private;
-	struct ttm_buffer_object *bo = obj->driver_private;
+	struct ttm_buffer_object *bo = ttm_gem_mapping(obj);
 	u8 value;
 
 	/* Set the framebuffer offset */
@@ -1254,7 +1254,7 @@ via_iga2_mode_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
 	struct via_crtc *iga = container_of(crtc, struct via_crtc, base);
 	struct drm_via_private *dev_priv = crtc->dev->dev_private;
 	struct drm_gem_object *obj = fb->helper_private;
-	struct ttm_buffer_object *bo = obj->driver_private;
+	struct ttm_buffer_object *bo = ttm_gem_mapping(obj);
 	u8 value;
 
 	/* Set the framebuffer offset */
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index d425db0..2541608 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -217,8 +217,9 @@ static int via_dumb_create(struct drm_file *filp, struct drm_device *dev,
 
 	args->pitch = round_up(args->width * (args->bpp >> 3), 16);
 	args->size = args->pitch * args->height;
-	obj = ttm_gem_create(dev, &dev_priv->bdev, TTM_PL_FLAG_VRAM,
-				false, 16, PAGE_SIZE, args->size);
+	obj = ttm_gem_create(dev, &dev_priv->bdev, ttm_bo_type_device,
+			     TTM_PL_FLAG_VRAM, false, 16, PAGE_SIZE,
+			     args->size);
 	if (IS_ERR(obj))
 		return PTR_ERR(obj);
 
@@ -233,15 +234,19 @@ static int via_dumb_mmap(struct drm_file *filp, struct drm_device *dev,
 {
 	struct ttm_buffer_object *bo;
 	struct drm_gem_object *obj;
+	int rc = -ENOENT;
 
 	obj = drm_gem_object_lookup(dev, filp, handle);
-	if (!obj || !obj->driver_private)
-		return -ENOENT;
+	if (obj == NULL)
+		return rc;
 
-	bo = obj->driver_private;
-	*offset_p = drm_vma_node_offset_addr(&bo->vma_node);
+	bo = ttm_gem_mapping(obj);
+	if (bo != NULL) {
+		*offset_p = drm_vma_node_offset_addr(&bo->vma_node);
+		rc = 0;
+	}
 	drm_gem_object_unreference_unlocked(obj);
-	return 0;
+	return rc;
 }
 
 static int gem_dumb_destroy(struct drm_file *filp, struct drm_device *dev,
@@ -327,7 +332,7 @@ via_driver_load(struct drm_device *dev, unsigned long chipset)
 
 	via_init_command_verifier();
 
-	ret = via_ttm_init(dev_priv);
+	ret = via_ttm_init(dev);
 	if (ret)
 		goto out_err;
 
@@ -458,7 +463,7 @@ static struct drm_driver via_driver = {
 	.irq_handler = via_driver_irq_handler,
 	.dma_quiescent = via_driver_dma_quiescent,
 	.lastclose = via_driver_lastclose,
-	.gem_init_object = ttm_gem_init_object,
+	.gem_open_object = ttm_gem_open_object,
 	.gem_free_object = ttm_gem_free_object,
 	.dumb_create = via_dumb_create,
 	.dumb_map_offset = via_dumb_mmap,
diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
index 9e6bc02..82a2fcc 100644
--- a/drivers/gpu/drm/via/via_drv.h
+++ b/drivers/gpu/drm/via/via_drv.h
@@ -46,6 +46,7 @@
 #include <drm/via_drm.h>
 
 #include "via_regs.h"
+#include "via_mem.h"
 #include "via_fence.h"
 #include "via_dma.h"
 #include "via_verifier.h"
@@ -209,43 +210,6 @@ extern int via_wait_idle(struct drm_via_private *dev_priv);
 
 extern int via_detect_vram(struct drm_device *dev);
 
-extern int via_ttm_init(struct drm_via_private *dev_priv);
-extern struct ttm_tt *via_sgdma_backend_init(struct ttm_bo_device *bdev, unsigned long size,
-					uint32_t page_flags, struct page *dummy_read_page);
-
-extern int ttm_global_init(struct drm_global_reference *global_ref,
-				struct ttm_bo_global_ref *global_bo,
-				struct ttm_bo_driver *driver,
-				struct ttm_bo_device *bdev,
-				bool dma32);
-extern void ttm_global_fini(struct drm_global_reference *global_ref,
-				struct ttm_bo_global_ref *global_bo,
-				struct ttm_bo_device *bdev);
-
-extern int ttm_bo_allocate(struct ttm_bo_device *bdev, unsigned long size,
-				enum ttm_bo_type origin, int types,
-				uint32_t byte_align, uint32_t page_align,
-				bool interruptible, struct sg_table *sg,
-				struct ttm_buffer_object **p_bo);
-extern void ttm_placement_from_domain(struct ttm_buffer_object *bo,
-				struct ttm_placement *placement, u32 domains,
-				struct ttm_bo_device *bdev);
-extern int ttm_bo_unpin(struct ttm_buffer_object *bo, struct ttm_bo_kmap_obj *kmap);
-extern int ttm_bo_pin(struct ttm_buffer_object *bo, struct ttm_bo_kmap_obj *kmap);
-extern int ttm_allocate_kernel_buffer(struct ttm_bo_device *bdev, unsigned long size,
-				uint32_t alignment, uint32_t domain,
-				struct ttm_bo_kmap_obj *kmap);
-
-extern int ttm_mmap(struct file *filp, struct vm_area_struct *vma);
-
-extern int ttm_gem_init_object(struct drm_gem_object *obj);
-extern void ttm_gem_free_object(struct drm_gem_object *obj);
-extern struct drm_gem_object *ttm_gem_create(struct drm_device *dev,
-					struct ttm_bo_device *bdev, int type,
-					bool interruptible,
-					int byte_align, int page_align,
-					unsigned long size);
-
 extern int via_enable_vblank(struct drm_device *dev, int crtc);
 extern void via_disable_vblank(struct drm_device *dev, int crtc);
 
diff --git a/drivers/gpu/drm/via/via_fb.c b/drivers/gpu/drm/via/via_fb.c
index b42e251..c160cb2 100644
--- a/drivers/gpu/drm/via/via_fb.c
+++ b/drivers/gpu/drm/via/via_fb.c
@@ -1020,17 +1020,16 @@ via_fb_probe(struct drm_fb_helper *helper,
 	size = mode_cmd.pitches[0] * mode_cmd.height;
 	size = ALIGN(size, PAGE_SIZE);
 
-	obj = drm_gem_object_alloc(helper->dev, size);
+	obj = ttm_gem_create(helper->dev, &dev_priv->bdev, ttm_bo_type_kernel,
+			     TTM_PL_FLAG_VRAM, false, 1, PAGE_SIZE, size);
 	if (unlikely(IS_ERR(obj))) {
 		ret = PTR_ERR(obj);
 		goto out_err;
 	}
-	ret = ttm_bo_allocate(&dev_priv->bdev, size, ttm_bo_type_kernel,
-				TTM_PL_FLAG_VRAM, 1, PAGE_SIZE, false,
-				NULL, &kmap->bo);
-	if (unlikely(ret))
+
+	kmap->bo = ttm_gem_mapping(obj);
+	if (kmap->bo == NULL)
 		goto out_err;
-	kmap->bo->persistent_swap_storage = obj->filp;
 
 	ret = ttm_bo_pin(kmap->bo, kmap);
 	if (unlikely(ret))
diff --git a/drivers/gpu/drm/via/via_ioc32.c b/drivers/gpu/drm/via/via_ioc32.c
index a0738c1..a1aaed1 100644
--- a/drivers/gpu/drm/via/via_ioc32.c
+++ b/drivers/gpu/drm/via/via_ioc32.c
@@ -24,7 +24,6 @@
 /*
  * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
  */
-
 #include "drmP.h"
 #include "via_drv.h"
 
@@ -67,14 +66,15 @@ via_gem_alloc(struct drm_device *dev, void *data,
 	struct drm_gem_object *obj;
 	int ret = -ENOMEM;
 
-	obj = ttm_gem_create(dev, &dev_priv->bdev, args->domains, false,
-				args->alignment, PAGE_SIZE, args->size);
-	if (obj && obj->driver_private) {
+	obj = ttm_gem_create(dev, &dev_priv->bdev, ttm_bo_type_device,
+			     args->domains, false, args->alignment,
+			     PAGE_SIZE, args->size);
+	if (obj != NULL) {
 		ret = drm_gem_handle_create(filp, obj, &args->handle);
 		/* drop reference from allocate - handle holds it now */
 		drm_gem_object_unreference_unlocked(obj);
 		if (!ret) {
-			struct ttm_buffer_object *bo = obj->driver_private;
+			struct ttm_buffer_object *bo = ttm_gem_mapping(obj);
 
 			args->map_handle = drm_vma_node_offset_addr(&bo->vma_node);
 			args->domains = bo->mem.placement & TTM_PL_MASK_MEM;
@@ -90,17 +90,19 @@ via_gem_alloc(struct drm_device *dev, void *data,
 static int
 via_gem_state(struct drm_device *dev, void *data, struct drm_file *file_priv)
 {
-	struct ttm_buffer_object *bo = NULL;
 	struct drm_via_gem_object *args = data;
+	struct ttm_buffer_object *bo = NULL;
 	struct drm_gem_object *obj = NULL;
 	struct ttm_placement placement;
 	int ret = -EINVAL;
 
 	obj = drm_gem_object_lookup(dev, file_priv, args->handle);
-	if (!obj || !obj->driver_private)
+	if (obj == NULL)
 		return ret;
 
-	bo = obj->driver_private;
+	bo = ttm_gem_mapping(obj);
+	if (bo == NULL)
+		return ret;
 
 	/* Don't bother to migrate to same domain */
 	args->domains &= ~(bo->mem.placement & TTM_PL_MASK_MEM);
@@ -134,16 +136,18 @@ via_gem_wait(struct drm_device *dev, void *data, struct drm_file *file_priv)
 	struct drm_via_gem_wait *args = data;
 	struct ttm_buffer_object *bo;
 	struct drm_gem_object *obj;
+	int ret = -EINVAL;
 	bool no_wait;
-	int ret;
 
 	obj = drm_gem_object_lookup(dev, file_priv, args->handle);
-	if (!obj)
-		return -EINVAL;
+	if (obj == NULL)
+		return ret;
 
-	no_wait = (args->no_wait != 0);
-	bo = obj->driver_private;
+	bo = ttm_gem_mapping(obj);
+	if (bo == NULL)
+		return ret;
 
+	no_wait = (args->no_wait != 0);
 	ret = ttm_bo_reserve(bo, true, no_wait, false, 0);
 	if (unlikely(ret != 0))
 		return ret;
diff --git a/drivers/gpu/drm/via/via_mem.h b/drivers/gpu/drm/via/via_mem.h
new file mode 100644
index 0000000..95c1580
--- /dev/null
+++ b/drivers/gpu/drm/via/via_mem.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014 James Simmons <jsimmons at infradead.org>
+ *
+ * Influenced by sample code from VIA Technologies and the radeon driver.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#ifndef _VIA_MEM_H_
+#define _VIA_MEM_H_
+
+#include "drmP.h"
+#include "ttm/ttm_bo_driver.h"
+#include "ttm/ttm_placement.h"
+
+struct ttm_heap {
+	uint32_t busy_placements[TTM_NUM_MEM_TYPES];
+	uint32_t placements[TTM_NUM_MEM_TYPES];
+	struct ttm_buffer_object pbo;
+};
+
+extern int via_ttm_init(struct drm_device *dev);
+extern struct ttm_tt *via_sgdma_backend_init(struct ttm_bo_device *bdev, unsigned long size,
+                                        uint32_t page_flags, struct page *dummy_read_page);
+
+extern int ttm_global_init(struct drm_global_reference *global_ref,
+                                struct ttm_bo_global_ref *global_bo,
+                                struct ttm_bo_driver *driver,
+                                struct ttm_bo_device *bdev,
+                                bool dma32);
+extern void ttm_global_fini(struct drm_global_reference *global_ref,
+                                struct ttm_bo_global_ref *global_bo,
+                                struct ttm_bo_device *bdev);
+
+extern int ttm_bo_allocate(struct ttm_bo_device *bdev, unsigned long size,
+                                enum ttm_bo_type origin, uint32_t domains,
+                                uint32_t byte_align, uint32_t page_align,
+                                bool interruptible, struct sg_table *sg,
+                                struct ttm_buffer_object **p_bo);
+extern void ttm_placement_from_domain(struct ttm_buffer_object *bo,
+                                struct ttm_placement *placement, u32 domains,
+                                struct ttm_bo_device *bdev);
+extern int ttm_bo_unpin(struct ttm_buffer_object *bo, struct ttm_bo_kmap_obj *kmap);
+extern int ttm_bo_pin(struct ttm_buffer_object *bo, struct ttm_bo_kmap_obj *kmap);
+extern int ttm_allocate_kernel_buffer(struct ttm_bo_device *bdev, unsigned long size,
+                                uint32_t alignment, uint32_t domain,
+                                struct ttm_bo_kmap_obj *kmap);
+
+extern int ttm_mmap(struct file *filp, struct vm_area_struct *vma);
+
+extern int ttm_gem_open_object(struct drm_gem_object *obj, struct drm_file *file_priv);
+extern void ttm_gem_free_object(struct drm_gem_object *obj);
+extern struct drm_gem_object *ttm_gem_create(struct drm_device *dev,
+					     struct ttm_bo_device *bdev,
+					     enum ttm_bo_type origin,
+					     int type, bool interruptible,
+					     int byte_align, int page_align,
+					     unsigned long size);
+extern struct ttm_buffer_object *ttm_gem_mapping(struct drm_gem_object *obj);
+
+#endif /* _VIA_MEM_H_ */
diff --git a/drivers/gpu/drm/via/via_ttm.c b/drivers/gpu/drm/via/via_ttm.c
index 08e9c1e..f96ce2d 100644
--- a/drivers/gpu/drm/via/via_ttm.c
+++ b/drivers/gpu/drm/via/via_ttm.c
@@ -483,8 +483,10 @@ static struct ttm_bo_driver via_bo_driver = {
 	.io_mem_free		= via_ttm_io_mem_free,
 };
 
-int via_ttm_init(struct drm_via_private *dev_priv)
+int via_ttm_init(struct drm_device *dev)
 {
+	struct drm_via_private *dev_priv = dev->dev_private;
+
 	int ret = ttm_global_init(&dev_priv->mem_global_ref,
 				&dev_priv->bo_global_ref,
 				&via_bo_driver,
commit ac1f388a593d08356d37d9d2b6d630ff17ba0152
Author: James Simmons <jsimmons at infradead.org>
Date:   Sat Dec 27 14:40:12 2014 -0500

    drm/via: Remove GEM handling out of ttm_bo_allocate
    
    The function ttm_bo_allocate assumes that the GEM object
    will be created before the ttm_buffer_object which might
    not be the case. So we move the shem handling in
    ttm_bo_allocate to the gem handling code.
    
    Signed-off-by: James Simmons <jsimmons at infradead.org>

diff --git a/drivers/gpu/drm/via/init_ttm.c b/drivers/gpu/drm/via/init_ttm.c
index aab0221..1688d4f 100644
--- a/drivers/gpu/drm/via/init_ttm.c
+++ b/drivers/gpu/drm/via/init_ttm.c
@@ -153,7 +153,6 @@ ttm_bo_allocate(struct ttm_bo_device *bdev,
 		uint32_t page_align,
 		bool interruptible,
 		struct sg_table *sg,
-		struct file *persistant_swap_storage,
 		struct ttm_buffer_object **p_bo)
 {
 	unsigned long acc_size = sizeof(struct ttm_heap);
@@ -174,10 +173,10 @@ ttm_bo_allocate(struct ttm_bo_device *bdev,
 	ttm_placement_from_domain(bo, &placement, domains, bdev);
 
 	ret = ttm_bo_init(bdev, bo, size, origin, &placement,
-				page_align >> PAGE_SHIFT,
-				interruptible, persistant_swap_storage,
-				ttm_bo_dma_acc_size(bdev, size, acc_size),
-				sg, ttm_buffer_object_destroy);
+			  page_align >> PAGE_SHIFT,
+			  interruptible, NULL,
+			  ttm_bo_dma_acc_size(bdev, size, acc_size),
+			  sg, ttm_buffer_object_destroy);
 	if (unlikely(ret))
 		kfree(heap);
 	else
@@ -237,7 +236,7 @@ ttm_allocate_kernel_buffer(struct ttm_bo_device *bdev, unsigned long size,
 {
 	int ret = ttm_bo_allocate(bdev, size, ttm_bo_type_kernel, domain,
 					alignment, PAGE_SIZE, false, NULL,
-					NULL, &kmap->bo);
+					&kmap->bo);
 	if (likely(!ret)) {
 		ret = ttm_bo_pin(kmap->bo, kmap);
 		if (unlikely(ret)) {
diff --git a/drivers/gpu/drm/via/ttm_gem.c b/drivers/gpu/drm/via/ttm_gem.c
index 4c30b8b..a78c2a01 100644
--- a/drivers/gpu/drm/via/ttm_gem.c
+++ b/drivers/gpu/drm/via/ttm_gem.c
@@ -83,12 +83,13 @@ ttm_gem_create(struct drm_device *dev, struct ttm_bo_device *bdev, int types,
 
 	ret = ttm_bo_allocate(bdev, size, ttm_bo_type_device, types,
 				byte_align, page_align, interruptible,
-				NULL, obj->filp, &bo);
+				NULL, &bo);
 	if (ret) {
 		DRM_ERROR("Failed to create buffer object\n");
 		drm_gem_object_unreference_unlocked(obj);
 		return ERR_PTR(ret);
 	}
+	bo->persistent_swap_storage = obj->filp;
 	obj->driver_private = bo;
 	return obj;
 }
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index ac17d3d..d425db0 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -152,8 +152,7 @@ via_mmio_setup(struct drm_device *dev)
 		return ret;
 
 	ret = ttm_bo_allocate(&dev_priv->bdev, VIA_MMIO_REGSIZE, ttm_bo_type_kernel,
-				TTM_PL_FLAG_PRIV0, 1, PAGE_SIZE, false, NULL,
-				NULL, &bo);
+				TTM_PL_FLAG_PRIV0, 1, PAGE_SIZE, false, NULL, &bo);
 	if (ret)
 		goto err;
 
diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
index 5198a43..9e6bc02 100644
--- a/drivers/gpu/drm/via/via_drv.h
+++ b/drivers/gpu/drm/via/via_drv.h
@@ -226,7 +226,6 @@ extern int ttm_bo_allocate(struct ttm_bo_device *bdev, unsigned long size,
 				enum ttm_bo_type origin, int types,
 				uint32_t byte_align, uint32_t page_align,
 				bool interruptible, struct sg_table *sg,
-				struct file *persistant_swap_storage,
 				struct ttm_buffer_object **p_bo);
 extern void ttm_placement_from_domain(struct ttm_buffer_object *bo,
 				struct ttm_placement *placement, u32 domains,
diff --git a/drivers/gpu/drm/via/via_fb.c b/drivers/gpu/drm/via/via_fb.c
index 06ac2df..b42e251 100644
--- a/drivers/gpu/drm/via/via_fb.c
+++ b/drivers/gpu/drm/via/via_fb.c
@@ -1027,9 +1027,10 @@ via_fb_probe(struct drm_fb_helper *helper,
 	}
 	ret = ttm_bo_allocate(&dev_priv->bdev, size, ttm_bo_type_kernel,
 				TTM_PL_FLAG_VRAM, 1, PAGE_SIZE, false,
-				NULL, obj->filp, &kmap->bo);
+				NULL, &kmap->bo);
 	if (unlikely(ret))
 		goto out_err;
+	kmap->bo->persistent_swap_storage = obj->filp;
 
 	ret = ttm_bo_pin(kmap->bo, kmap);
 	if (unlikely(ret))
diff --git a/drivers/gpu/drm/via/via_h1_cmdbuf.c b/drivers/gpu/drm/via/via_h1_cmdbuf.c
index e5087f9..e4e0698 100644
--- a/drivers/gpu/drm/via/via_h1_cmdbuf.c
+++ b/drivers/gpu/drm/via/via_h1_cmdbuf.c
@@ -161,7 +161,7 @@ static int via_initialize(struct drm_device *dev,
 
 	ret = ttm_bo_allocate(&dev_priv->bdev, init->size, ttm_bo_type_kernel,
 				TTM_PL_FLAG_TT, VIA_MM_ALIGN_SIZE, PAGE_SIZE,
-				false, NULL, NULL, &bo);
+				false, NULL, &bo);
 	if (!ret) {
 		ret = ttm_bo_pin(bo, &dev_priv->dmabuf);
 		if (ret)


More information about the Openchrome-devel mailing list