From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 12/12] drm/amdgpu: add DMA-buf invalidation callback v2
Date: Fri, 26 Apr 2019 14:36:38 +0200 [thread overview]
Message-ID: <20190426123638.40221-12-christian.koenig@amd.com> (raw)
In-Reply-To: <20190426123638.40221-1-christian.koenig@amd.com>
Allow for invalidation of imported DMA-bufs.
v2: add dma_buf_pin/dma_buf_unpin support
Signed-off-by: Christian König <christian.koenig@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 24 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d26e2f0b88d2..affde72b44db 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -850,6 +850,9 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
return 0;
}
+ if (bo->gem_base.import_attach)
+ dma_buf_pin(bo->gem_base.import_attach->dmabuf);
+
bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
/* force to pin into visible video ram */
if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
@@ -933,6 +936,9 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
amdgpu_bo_subtract_pin_size(bo);
+ if (bo->gem_base.import_attach)
+ dma_buf_unpin(bo->gem_base.import_attach->dmabuf);
+
for (i = 0; i < bo->placement.num_placement; i++) {
bo->placements[i].lpfn = 0;
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index 662cd99980cb..675375b2fb7b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
@@ -458,6 +458,28 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
return buf;
}
+/**
+ * amdgpu_gem_prime_invalidate_mappings - &attach.invalidate implementation
+ *
+ * @attach: the DMA-buf attachment
+ *
+ * Invalidate the DMA-buf attachment, making sure that the we re-create the
+ * mapping before the next use.
+ */
+static void
+amdgpu_gem_prime_invalidate_mappings(struct dma_buf_attachment *attach)
+{
+ struct ttm_operation_ctx ctx = { false, false };
+ struct drm_gem_object *obj = attach->importer_priv;
+ struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
+ struct ttm_placement placement = {};
+ int r;
+
+ r = ttm_bo_validate(&bo->tbo, &placement, &ctx);
+ if (r)
+ DRM_ERROR("Failed to invalidate DMA-buf import (%d))\n", r);
+}
+
/**
* amdgpu_gem_prime_import - &drm_driver.gem_prime_import implementation
* @dev: DRM device
@@ -475,6 +497,7 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
struct dma_buf_attach_info attach_info = {
.dev = dev->dev,
.dmabuf = dma_buf,
+ .invalidate = amdgpu_gem_prime_invalidate_mappings
};
struct dma_buf_attachment *attach;
struct drm_gem_object *obj;
@@ -495,6 +518,7 @@ struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev,
if (IS_ERR(obj))
return obj;
+ attach_info.importer_priv = obj;
attach = dma_buf_attach(&attach_info);
if (IS_ERR(attach)) {
drm_gem_object_put(obj);
--
2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-04-26 12:36 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-26 12:36 [PATCH 01/12] dma-buf: add struct dma_buf_attach_info Christian König
2019-04-26 12:36 ` [PATCH 02/12] dma-buf: add explicit buffer pinning v2 Christian König
2019-04-29 8:40 ` Daniel Vetter
2019-04-30 13:42 ` Christian König
2019-04-30 13:59 ` Daniel Vetter
2019-04-30 14:26 ` Christian König
2019-04-30 14:34 ` Daniel Vetter
2019-04-30 14:41 ` Koenig, Christian
2019-04-30 15:22 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 03/12] dma-buf: start caching of sg_table objects Christian König
2019-04-29 8:54 ` Daniel Vetter
2019-04-30 14:18 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 04/12] dma-buf: lock the reservation object during (un)map_dma_buf v4 Christian König
2019-04-26 12:36 ` [PATCH 05/12] dma-buf: add dma_buf_(un)map_attachment_locked variants v4 Christian König
2019-04-26 12:36 ` [PATCH 06/12] dma-buf: add optional invalidate_mappings callback v5 Christian König
2019-04-29 8:42 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 07/12] drm: remove prime sg_table caching Christian König
2019-04-26 12:36 ` [PATCH 08/12] drm/ttm: remove the backing store if no placement is given Christian König
2019-04-26 12:36 ` [PATCH 09/12] drm/ttm: use the parent resv for ghost objects Christian König
2019-04-26 12:36 ` [PATCH 10/12] drm/amdgpu: add independent DMA-buf export v3 Christian König
2019-04-30 14:16 ` Daniel Vetter
2019-05-03 12:35 ` Christian König
2019-05-06 8:04 ` Daniel Vetter
2019-05-06 10:05 ` Koenig, Christian
2019-05-06 15:10 ` Daniel Vetter
2019-04-26 12:36 ` [PATCH 11/12] drm/amdgpu: add independent DMA-buf import v4 Christian König
2019-04-26 12:36 ` Christian König [this message]
2019-04-29 8:24 ` [PATCH 01/12] dma-buf: add struct dma_buf_attach_info Daniel Vetter
2019-04-30 12:40 ` Christian König
-- strict thread matches above, loose matches on Subject: below --
2019-04-16 18:38 dynamic DMA-buf sharing between devices Christian König
2019-04-16 18:38 ` [PATCH 12/12] drm/amdgpu: add DMA-buf invalidation callback v2 Christian König
2019-04-16 18:38 ` Christian König
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=20190426123638.40221-12-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.