All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 06/24] drm/i915: Convert the dmabuf object to use the new i915_gem_object_ops
Date: Tue,  4 Sep 2012 21:02:58 +0100	[thread overview]
Message-ID: <1346788996-19080-7-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1346788996-19080-1-git-send-email-chris@chris-wilson.co.uk>

By providing a callback for when we need to bind the pages, and then
release them again later, we can shorten the amount of time we hold the
foreign pages mapped and pinned, and importantly the dmabuf objects then
behave as any other normal object with respect to the shrinker and
memory management.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_drv.h        |    1 -
 drivers/gpu/drm/i915/i915_gem.c        |   10 ++++----
 drivers/gpu/drm/i915/i915_gem_dmabuf.c |   44 ++++++++++++++++++++++----------
 drivers/gpu/drm/i915/i915_gem_gtt.c    |    4 +--
 4 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 1a714fa..a86f50d 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -998,7 +998,6 @@ struct drm_i915_gem_object {
 	int pages_pin_count;
 
 	/* prime dma-buf support */
-	struct sg_table *sg_table;
 	void *dma_buf_vmapping;
 	int vmapping_count;
 
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 06589a9..58075e3 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1692,7 +1692,7 @@ i915_gem_object_put_pages(struct drm_i915_gem_object *obj)
 {
 	const struct drm_i915_gem_object_ops *ops = obj->ops;
 
-	if (obj->sg_table || obj->pages == NULL)
+	if (obj->pages == NULL)
 		return 0;
 
 	BUG_ON(obj->gtt_space);
@@ -1838,7 +1838,7 @@ i915_gem_object_get_pages(struct drm_i915_gem_object *obj)
 	const struct drm_i915_gem_object_ops *ops = obj->ops;
 	int ret;
 
-	if (obj->sg_table || obj->pages)
+	if (obj->pages)
 		return 0;
 
 	BUG_ON(obj->pages_pin_count);
@@ -3731,9 +3731,6 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 
 	trace_i915_gem_object_destroy(obj);
 
-	if (gem_obj->import_attach)
-		drm_prime_gem_destroy(gem_obj, obj->sg_table);
-
 	if (obj->phys_obj)
 		i915_gem_detach_phys_object(dev, obj);
 
@@ -3755,6 +3752,9 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj)
 
 	BUG_ON(obj->pages);
 
+	if (obj->base.import_attach)
+		drm_prime_gem_destroy(&obj->base, NULL);
+
 	drm_gem_object_release(&obj->base);
 	i915_gem_info_remove_obj(dev_priv, obj->base.size);
 
diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
index 4bb1b94..ca3497e 100644
--- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c
+++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c
@@ -82,7 +82,8 @@ out:
 }
 
 static void i915_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
-			    struct sg_table *sg, enum dma_data_direction dir)
+				   struct sg_table *sg,
+				   enum dma_data_direction dir)
 {
 	dma_unmap_sg(attachment->dev, sg->sgl, sg->nents, dir);
 	sg_free_table(sg);
@@ -228,11 +229,35 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
 	return dma_buf_export(obj, &i915_dmabuf_ops, obj->base.size, 0600);
 }
 
+static int i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object *obj)
+{
+	struct sg_table *sg;
+
+	sg = dma_buf_map_attachment(obj->base.import_attach, DMA_BIDIRECTIONAL);
+	if (IS_ERR(sg))
+		return PTR_ERR(sg);
+
+	obj->pages = sg;
+	obj->has_dma_mapping = true;
+	return 0;
+}
+
+static void i915_gem_object_put_pages_dmabuf(struct drm_i915_gem_object *obj)
+{
+	dma_buf_unmap_attachment(obj->base.import_attach,
+				 obj->pages, DMA_BIDIRECTIONAL);
+	obj->has_dma_mapping = false;
+}
+
+static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
+	.get_pages = i915_gem_object_get_pages_dmabuf,
+	.put_pages = i915_gem_object_put_pages_dmabuf,
+};
+
 struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 					     struct dma_buf *dma_buf)
 {
 	struct dma_buf_attachment *attach;
-	struct sg_table *sg;
 	struct drm_i915_gem_object *obj;
 	int ret;
 
@@ -251,34 +276,25 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
 	if (IS_ERR(attach))
 		return ERR_CAST(attach);
 
-	sg = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
-	if (IS_ERR(sg)) {
-		ret = PTR_ERR(sg);
-		goto fail_detach;
-	}
 
 	obj = kzalloc(sizeof(*obj), GFP_KERNEL);
 	if (obj == NULL) {
 		ret = -ENOMEM;
-		goto fail_unmap;
+		goto fail_detach;
 	}
 
 	ret = drm_gem_private_object_init(dev, &obj->base, dma_buf->size);
 	if (ret) {
 		kfree(obj);
-		goto fail_unmap;
+		goto fail_detach;
 	}
 
-	obj->has_dma_mapping = true;
-	obj->sg_table = sg;
+	i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops);
 	obj->base.import_attach = attach;
 
 	return &obj->base;
 
-fail_unmap:
-	dma_buf_unmap_attachment(attach, sg, DMA_BIDIRECTIONAL);
 fail_detach:
 	dma_buf_detach(dma_buf, attach);
 	return ERR_PTR(ret);
 }
-
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 6746109..c86dc59 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -234,7 +234,7 @@ void i915_ppgtt_bind_object(struct i915_hw_ppgtt *ppgtt,
 	}
 
 	i915_ppgtt_insert_sg_entries(ppgtt,
-				     obj->sg_table ?: obj->pages,
+				     obj->pages,
 				     obj->gtt_space->start >> PAGE_SHIFT,
 				     pte_flags);
 }
@@ -325,7 +325,7 @@ void i915_gem_gtt_bind_object(struct drm_i915_gem_object *obj,
 	struct drm_device *dev = obj->base.dev;
 	unsigned int agp_type = cache_level_to_agp_type(dev, cache_level);
 
-	intel_gtt_insert_sg_entries(obj->sg_table ?: obj->pages,
+	intel_gtt_insert_sg_entries(obj->pages,
 				    obj->gtt_space->start >> PAGE_SHIFT,
 				    agp_type);
 	obj->has_global_gtt_mapping = 1;
-- 
1.7.10.4

  parent reply	other threads:[~2012-09-04 20:06 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 20:02 Stolen memory, again Chris Wilson
2012-09-04 20:02 ` [PATCH 01/24] drm/i915: Introduce drm_i915_gem_object_ops Chris Wilson
2012-09-06 22:32   ` Ben Widawsky
2012-10-11 18:28   ` Jesse Barnes
2012-09-04 20:02 ` [PATCH 02/24] drm/i915: Pin backing pages whilst exporting through a dmabuf vmap Chris Wilson
2012-09-06 22:55   ` Ben Widawsky
2012-10-11 18:30   ` Jesse Barnes
2012-09-04 20:02 ` [PATCH 03/24] drm/i915: Pin backing pages for pwrite Chris Wilson
2012-09-07  0:07   ` Ben Widawsky
2012-09-12 13:13     ` Daniel Vetter
2012-09-12 13:20       ` Daniel Vetter
2012-10-11 18:31   ` Jesse Barnes
2012-09-04 20:02 ` [PATCH 04/24] drm/i915: Pin backing pages for pread Chris Wilson
2012-09-07  0:10   ` Ben Widawsky
2012-09-04 20:02 ` [PATCH 05/24] drm/i915: Replace the array of pages with a scatterlist Chris Wilson
2012-09-07  1:49   ` Ben Widawsky
2012-09-10 16:34     ` Chris Wilson
2012-09-12 13:33       ` Daniel Vetter
2012-09-04 20:02 ` Chris Wilson [this message]
2012-09-14 18:02   ` [PATCH 06/24] drm/i915: Convert the dmabuf object to use the new i915_gem_object_ops Ben Widawsky
2012-09-14 18:24     ` Chris Wilson
2012-09-14 21:43   ` Daniel Vetter
2012-09-04 20:02 ` [PATCH 07/24] drm: Introduce drm_mm_create_block() Chris Wilson
2012-09-12 13:43   ` Daniel Vetter
2012-09-04 20:03 ` [PATCH 08/24] drm/i915: Fix detection of stolen base for gen2 Chris Wilson
2012-09-04 20:03 ` [PATCH 09/24] drm/i915: Fix location of stolen memory register for SandyBridge+ Chris Wilson
2012-10-11 18:43   ` Jesse Barnes
2012-10-11 19:06     ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 10/24] drm/i915: Avoid clearing preallocated regions from the GTT Chris Wilson
2012-10-11 18:45   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 11/24] drm: Introduce an iterator over holes in the drm_mm range manager Chris Wilson
2012-09-12 13:54   ` Daniel Vetter
2012-09-04 20:03 ` [PATCH 12/24] drm/i915: Delay allocation of stolen space for FBC Chris Wilson
2012-10-11 18:49   ` Jesse Barnes
2012-10-11 18:56     ` Chris Wilson
2012-09-04 20:03 ` [PATCH 13/24] drm/i915: Defer allocation of stolen memory for FBC until first use Chris Wilson
2012-09-04 20:03 ` [PATCH 14/24] drm/i915: Allow objects to be created with no backing pages, but stolen space Chris Wilson
2012-09-04 20:03 ` [PATCH 15/24] drm/i915: Differentiate between prime and stolen objects Chris Wilson
2012-10-11 18:50   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 16/24] drm/i915: Support readback of stolen objects upon error Chris Wilson
2012-10-11 18:51   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 17/24] drm/i915: Handle stolen objects in pwrite Chris Wilson
2012-09-04 20:03 ` [PATCH 18/24] drm/i915: Handle stolen objects for pread Chris Wilson
2012-09-04 20:03 ` [PATCH 19/24] drm/i915: Introduce i915_gem_object_create_stolen() Chris Wilson
2012-10-11 18:53   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 20/24] drm/i915: Allocate fbcon from stolen memory Chris Wilson
2012-10-11 18:54   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 21/24] drm/i915: Allocate ringbuffers " Chris Wilson
2012-10-11 18:54   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 22/24] drm/i915: Allocate overlay registers " Chris Wilson
2012-10-11 18:55   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 23/24] drm/i915: Use a slab for object allocation Chris Wilson
2012-10-11 18:55   ` Jesse Barnes
2012-09-04 20:03 ` [PATCH 24/24] drm/i915: Introduce mapping of user pages into video memory (userptr) ioctl Chris Wilson
  -- strict thread matches above, loose matches on Subject: below --
2012-08-30 15:30 Next iteration of stolen support Chris Wilson
2012-08-30 15:31 ` [PATCH 06/24] drm/i915: Convert the dmabuf object to use the new i915_gem_object_ops Chris Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1346788996-19080-7-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --subject='Re: [PATCH 06/24] drm/i915: Convert the dmabuf object to use the new i915_gem_object_ops' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.