Linux Media Controller development
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Cc: sumit.semwal@linaro.org
Subject: [PATCH 4/5] dma-buf: add dma_buf_(un)map_attachment_locked variants
Date: Fri,  1 Jun 2018 14:00:19 +0200	[thread overview]
Message-ID: <20180601120020.11520-4-christian.koenig@amd.com> (raw)
In-Reply-To: <20180601120020.11520-1-christian.koenig@amd.com>

Add function variants which can be called with the reservation lock
already held.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-buf.c | 60 ++++++++++++++++++++++++++++++++++++++++++-----
 include/linux/dma-buf.h   |  5 ++++
 2 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 4f0708cb58a7..3371509b468e 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -606,6 +606,38 @@ void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
 }
 EXPORT_SYMBOL_GPL(dma_buf_detach);
 
+/**
+ * dma_buf_map_attachment_locked - Maps the buffer into _device_ address space
+ * with the reservation lock held. Is a wrapper for map_dma_buf() of the
+ *
+ * Returns the scatterlist table of the attachment;
+ * dma_buf_ops.
+ * @attach:	[in]	attachment whose scatterlist is to be returned
+ * @direction:	[in]	direction of DMA transfer
+ *
+ * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR
+ * on error. May return -EINTR if it is interrupted by a signal.
+ *
+ * A mapping must be unmapped by using dma_buf_unmap_attachment(). Note that
+ * the underlying backing storage is pinned for as long as a mapping exists,
+ * therefore users/importers should not hold onto a mapping for undue amounts of
+ * time.
+ */
+struct sg_table *
+dma_buf_map_attachment_locked(struct dma_buf_attachment *attach,
+			      enum dma_data_direction direction)
+{
+	struct sg_table *sg_table;
+
+	might_sleep();
+	sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
+	if (!sg_table)
+		sg_table = ERR_PTR(-ENOMEM);
+
+	return sg_table;
+}
+EXPORT_SYMBOL_GPL(dma_buf_map_attachment_locked);
+
 /**
  * dma_buf_map_attachment - Returns the scatterlist table of the attachment;
  * mapped into _device_ address space. Is a wrapper for map_dma_buf() of the
@@ -626,13 +658,12 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 {
 	struct sg_table *sg_table;
 
-	might_sleep();
 
 	if (WARN_ON(!attach || !attach->dmabuf))
 		return ERR_PTR(-EINVAL);
 
 	reservation_object_lock(attach->dmabuf->resv, NULL);
-	sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
+	sg_table = dma_buf_map_attachment_locked(attach, direction);
 	reservation_object_unlock(attach->dmabuf->resv);
 	if (!sg_table)
 		sg_table = ERR_PTR(-ENOMEM);
@@ -641,6 +672,26 @@ struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach,
 }
 EXPORT_SYMBOL_GPL(dma_buf_map_attachment);
 
+/**
+ * dma_buf_unmap_attachment_locked - unmaps the buffer with reservation lock
+ * held, should deallocate the associated scatterlist. Is a wrapper for
+ * unmap_dma_buf() of dma_buf_ops.
+ * @attach:	[in]	attachment to unmap buffer from
+ * @sg_table:	[in]	scatterlist info of the buffer to unmap
+ * @direction:  [in]    direction of DMA transfer
+ *
+ * This unmaps a DMA mapping for @attached obtained by dma_buf_map_attachment().
+ */
+void dma_buf_unmap_attachment_locked(struct dma_buf_attachment *attach,
+				     struct sg_table *sg_table,
+				     enum dma_data_direction direction)
+{
+	might_sleep();
+	attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
+						direction);
+}
+EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment_locked);
+
 /**
  * dma_buf_unmap_attachment - unmaps and decreases usecount of the buffer;might
  * deallocate the scatterlist associated. Is a wrapper for unmap_dma_buf() of
@@ -655,14 +706,11 @@ void dma_buf_unmap_attachment(struct dma_buf_attachment *attach,
 				struct sg_table *sg_table,
 				enum dma_data_direction direction)
 {
-	might_sleep();
-
 	if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
 		return;
 
 	reservation_object_lock(attach->dmabuf->resv, NULL);
-	attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
-						direction);
+	dma_buf_unmap_attachment_locked(attach, sg_table, direction);
 	reservation_object_unlock(attach->dmabuf->resv);
 }
 EXPORT_SYMBOL_GPL(dma_buf_unmap_attachment);
diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
index d2ba7a027a78..968777e8c662 100644
--- a/include/linux/dma-buf.h
+++ b/include/linux/dma-buf.h
@@ -388,8 +388,13 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags);
 struct dma_buf *dma_buf_get(int fd);
 void dma_buf_put(struct dma_buf *dmabuf);
 
+struct sg_table *dma_buf_map_attachment_locked(struct dma_buf_attachment *,
+					       enum dma_data_direction);
 struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *,
 					enum dma_data_direction);
+void dma_buf_unmap_attachment_locked(struct dma_buf_attachment *,
+				     struct sg_table *,
+				     enum dma_data_direction);
 void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *,
 				enum dma_data_direction);
 int dma_buf_begin_cpu_access(struct dma_buf *dma_buf,
-- 
2.14.1

  parent reply	other threads:[~2018-06-01 12:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 12:00 [PATCH 1/5] dma_buf: remove device parameter from attach callback Christian König
2018-06-01 12:00 ` [PATCH 2/5] dma-buf: remove kmap_atomic interface Christian König
2018-06-18  8:18   ` Daniel Vetter
2018-06-19 14:47     ` Christian König
2018-06-19 15:35       ` Daniel Vetter
2018-06-20 12:46         ` Christian König
2018-06-20 12:52           ` Daniel Vetter
2018-06-20 14:04             ` Christian König
2018-06-20 14:21               ` Christian König
2018-06-21  6:26                 ` Daniel Vetter
2018-06-21  6:30                   ` Daniel Vetter
2018-06-21 10:59                     ` Christian König
2018-06-20  6:10       ` Sumit Semwal
2018-06-20  6:22         ` Christian König
2018-06-01 12:00 ` [PATCH 3/5] dma-buf: lock the reservation object during (un)map_dma_buf Christian König
2018-06-18  8:22   ` Daniel Vetter
2018-06-18 12:43     ` Christian König
2018-06-01 12:00 ` Christian König [this message]
2018-06-18  8:27   ` [PATCH 4/5] dma-buf: add dma_buf_(un)map_attachment_locked variants Daniel Vetter
2018-06-01 12:00 ` [PATCH 5/5] drm/amdgpu: add independent DMA-buf export v3 Christian König
2018-06-18  8:28   ` Daniel Vetter
2018-06-22 13:39     ` Christian König
2018-06-25  7:46       ` Daniel Vetter
2018-06-01 12:11 ` [PATCH 1/5] dma_buf: remove device parameter from attach callback Christian König
2018-06-01 14:02   ` Michel Dänzer
2018-06-01 15:17     ` Christian König
2018-06-01 15:30       ` Michel Dänzer
2018-06-06 11:24 ` Christian König
2018-06-18  8:14 ` Daniel Vetter

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=20180601120020.11520-4-christian.koenig@amd.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-media@vger.kernel.org \
    --cc=sumit.semwal@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox