aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch')
-rw-r--r--recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch180
1 files changed, 180 insertions, 0 deletions
diff --git a/recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch b/recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch
new file mode 100644
index 0000000..f65b7cb
--- /dev/null
+++ b/recipes-kernel/linux/linux-yocto/generic-drivers/0002-FROMLIST-dma-heap-Provide-accessors-so-that-in-kerne.patch
@@ -0,0 +1,180 @@
+From fd0d8a09c8d928459d37ae535825018bb0594357 Mon Sep 17 00:00:00 2001
+From: John Stultz <jstultz@google.com>
+Date: Mon, 11 Sep 2023 10:30:32 +0800
+Subject: [PATCH 2/2] FROMLIST: dma-heap: Provide accessors so that in-kernel
+ drivers can allocate dmabufs from specific heaps
+
+This allows drivers who don't want to create their own
+DMA-BUF exporter to be able to allocate DMA-BUFs directly
+from existing DMA-BUF Heaps.
+
+There is some concern that the premise of DMA-BUF heaps is
+that userland knows better about what type of heap memory
+is needed for a pipeline, so it would likely be best for
+drivers to import and fill DMA-BUFs allocated by userland
+instead of allocating one themselves, but this is still
+up for debate.
+
+[Yong: Fix the checkpatch alignment warning]
+Signed-off-by: John Stultz <jstultz@google.com>
+Signed-off-by: T.J. Mercier <tjmercier@google.com>
+Signed-off-by: Yong Wu <yong.wu@mediatek.com>
+Signed-off-by: Vijayanand Jitta <quic_vjitta@quicinc.com>
+Signed-off-by: Atul Dhudase <quic_adhudase@quicinc.com>
+Upstream-Status: Submitted [https://lore.kernel.org/lkml/20230911023038.30649-4-yong.wu@mediatek.com/]
+---
+ drivers/dma-buf/dma-heap.c | 60 ++++++++++++++++++++++++++++----------
+ include/linux/dma-heap.h | 25 ++++++++++++++++
+ 2 files changed, 69 insertions(+), 16 deletions(-)
+
+diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
+index 59328045975a..e17705427b23 100644
+--- a/drivers/dma-buf/dma-heap.c
++++ b/drivers/dma-buf/dma-heap.c
+@@ -54,12 +54,15 @@ static dev_t dma_heap_devt;
+ static struct class *dma_heap_class;
+ static DEFINE_XARRAY_ALLOC(dma_heap_minors);
+
+-static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
+- unsigned int fd_flags,
+- unsigned int heap_flags)
++struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
++ unsigned int fd_flags,
++ unsigned int heap_flags)
+ {
+- struct dma_buf *dmabuf;
+- int fd;
++ if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS)
++ return ERR_PTR(-EINVAL);
++
++ if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
++ return ERR_PTR(-EINVAL);
+
+ /*
+ * Allocations from all heaps have to begin
+@@ -67,9 +70,20 @@ static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
+ */
+ len = PAGE_ALIGN(len);
+ if (!len)
+- return -EINVAL;
++ return ERR_PTR(-EINVAL);
+
+- dmabuf = heap->ops->allocate(heap, len, fd_flags, heap_flags);
++ return heap->ops->allocate(heap, len, fd_flags, heap_flags);
++}
++EXPORT_SYMBOL_GPL(dma_heap_buffer_alloc);
++
++static int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len,
++ unsigned int fd_flags,
++ unsigned int heap_flags)
++{
++ struct dma_buf *dmabuf;
++ int fd;
++
++ dmabuf = dma_heap_buffer_alloc(heap, len, fd_flags, heap_flags);
+ if (IS_ERR(dmabuf))
+ return PTR_ERR(dmabuf);
+
+@@ -107,15 +121,9 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data)
+ if (heap_allocation->fd)
+ return -EINVAL;
+
+- if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS)
+- return -EINVAL;
+-
+- if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
+- return -EINVAL;
+-
+- fd = dma_heap_buffer_alloc(heap, heap_allocation->len,
+- heap_allocation->fd_flags,
+- heap_allocation->heap_flags);
++ fd = dma_heap_bufferfd_alloc(heap, heap_allocation->len,
++ heap_allocation->fd_flags,
++ heap_allocation->heap_flags);
+ if (fd < 0)
+ return fd;
+
+@@ -220,6 +228,7 @@ const char *dma_heap_get_name(struct dma_heap *heap)
+ {
+ return heap->name;
+ }
++EXPORT_SYMBOL_GPL(dma_heap_get_name);
+
+ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
+ {
+@@ -305,6 +314,24 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
+ kfree(heap);
+ return err_ret;
+ }
++EXPORT_SYMBOL_GPL(dma_heap_add);
++
++struct dma_heap *dma_heap_find(const char *name)
++{
++ struct dma_heap *h;
++
++ mutex_lock(&heap_list_lock);
++ list_for_each_entry(h, &heap_list, list) {
++ if (!strcmp(h->name, name)) {
++ kref_get(&h->refcount);
++ mutex_unlock(&heap_list_lock);
++ return h;
++ }
++ }
++ mutex_unlock(&heap_list_lock);
++ return NULL;
++}
++EXPORT_SYMBOL_GPL(dma_heap_find);
+
+ static void dma_heap_release(struct kref *ref)
+ {
+@@ -330,6 +357,7 @@ void dma_heap_put(struct dma_heap *h)
+ kref_put(&h->refcount, dma_heap_release);
+ mutex_unlock(&heap_list_lock);
+ }
++EXPORT_SYMBOL_GPL(dma_heap_put);
+
+ static char *dma_heap_devnode(const struct device *dev, umode_t *mode)
+ {
+diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h
+index f8c986dd9a8b..31f44d83f11b 100644
+--- a/include/linux/dma-heap.h
++++ b/include/linux/dma-heap.h
+@@ -65,10 +65,35 @@ const char *dma_heap_get_name(struct dma_heap *heap);
+ */
+ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
+
++/**
++ * dma_heap_find - get the heap registered with the specified name
++ * @name: Name of the DMA-Heap to find
++ *
++ * Returns:
++ * The DMA-Heap with the provided name.
++ *
++ * NOTE: DMA-Heaps returned from this function MUST be released using
++ * dma_heap_put() when the user is done to enable the heap to be unloaded.
++ */
++struct dma_heap *dma_heap_find(const char *name);
++
+ /**
+ * dma_heap_put - drops a reference to a dmabuf heap, potentially freeing it
+ * @heap: the heap whose reference count to decrement
+ */
+ void dma_heap_put(struct dma_heap *heap);
+
++/**
++ * dma_heap_buffer_alloc - Allocate dma-buf from a dma_heap
++ * @heap: DMA-Heap to allocate from
++ * @len: size to allocate in bytes
++ * @fd_flags: flags to set on returned dma-buf fd
++ * @heap_flags: flags to pass to the dma heap
++ *
++ * This is for internal dma-buf allocations only. Free returned buffers with dma_buf_put().
++ */
++struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
++ unsigned int fd_flags,
++ unsigned int heap_flags);
++
+ #endif /* _DMA_HEAPS_H */
+--
+2.25.1
+