dma-buf: Integrate KDS with dma-buf
authorSteven Price <steven.price@arm.com>
Tue, 29 May 2012 13:58:27 +0000 (14:58 +0100)
committerAnush Elangovan <anush@google.com>
Wed, 18 Jul 2012 01:42:43 +0000 (18:42 -0700)
Each dma-buf now has a KDS resource which can be retrieved with
get_dma_buf_kds_resource. The synchronisation is co-operative, drivers
must agree on what synchronisation to use with a particular buffer.

Add option DMA_SHARED_BUFFER_USES_KDS:
This is enabled automatically when DMA_SHARED_BUFFER is enabled, but
allows modules to check whether the kernel has support for KDS in dma_buf

BUG=None
TEST=Tested on Daisy

Change-Id: I633a29acf1309b20847b876f985a3afd41845295
Signed-off-by: Tom Cooksey <Tom.Cooksey@arm.com>
Reviewed-on: https://gerrit.chromium.org/gerrit/26442
Tested-by: David Garbett <David.Garbett@arm.com>
Reviewed-by: Anush Elangovan <anush@google.com>
Tested-by: Anush Elangovan <anush@google.com>
Commit-Ready: Anush Elangovan <anush@google.com>

drivers/base/Kconfig
drivers/base/dma-buf.c
include/linux/dma-buf.h

index 5d98d07..ae1d84b 100644 (file)
@@ -185,6 +185,8 @@ config DMA_SHARED_BUFFER
        bool
        default n
        select ANON_INODES
+       select KDS
+       select DMA_SHARED_BUFFER_USES_KDS
        depends on EXPERIMENTAL
        help
          This option enables the framework for buffer-sharing between
@@ -281,6 +283,12 @@ config CMA_AREAS
 
 endif
 
+config DMA_SHARED_BUFFER_USES_KDS
+       bool
+       default n
+       help
+         This option adds a KDS resource within every dma_buf allocation.
+
 config KDS
        bool "Kernel dependency system"
        help
index 20258e1..c286212 100644 (file)
@@ -40,6 +40,7 @@ static int dma_buf_release(struct inode *inode, struct file *file)
        dmabuf = file->private_data;
 
        dmabuf->ops->release(dmabuf);
+       kds_resource_term(&dmabuf->kds);
        kfree(dmabuf);
        return 0;
 }
@@ -120,6 +121,8 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops,
        mutex_init(&dmabuf->lock);
        INIT_LIST_HEAD(&dmabuf->attachments);
 
+       kds_resource_init(&dmabuf->kds);
+
        return dmabuf;
 }
 EXPORT_SYMBOL_GPL(dma_buf_export);
index eb48f38..0dc4137 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/list.h>
 #include <linux/dma-mapping.h>
 #include <linux/fs.h>
+#include <linux/kds.h>
 
 struct device;
 struct dma_buf;
@@ -121,6 +122,7 @@ struct dma_buf {
        const struct dma_buf_ops *ops;
        /* mutex to serialize list manipulation and attach/detach */
        struct mutex lock;
+       struct kds_resource kds;
        void *priv;
 };
 
@@ -156,6 +158,21 @@ static inline void get_dma_buf(struct dma_buf *dmabuf)
        get_file(dmabuf->file);
 }
 
+/**
+ * get_dma_buf_kds_resource - get a KDS resource for this dma-buf
+ * @dmabuf:    [in]    pointer to dma_buf
+ *
+ * Returns a KDS resource that represents the dma-buf. This should be used by
+ * drivers to synchronize access to the buffer. Note that the caller should
+ * ensure that a reference to the dma-buf exists from the call to
+ * kds_async_wait until kds_resource_set_release is called.
+ */
+static inline struct kds_resource *
+       get_dma_buf_kds_resource(struct dma_buf *dmabuf)
+{
+       return &dmabuf->kds;
+}
+
 #ifdef CONFIG_DMA_SHARED_BUFFER
 struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
                                                        struct device *dev);