From: Albert Esteve <aesteve@redhat.com>
To: Sumit Semwal <sumit.semwal@linaro.org>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Brian Starkey <Brian.Starkey@arm.com>,
John Stultz <jstultz@google.com>,
"T.J. Mercier" <tjmercier@google.com>,
Christian König <christian.koenig@amd.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
iommu@lists.linux.dev, devicetree@vger.kernel.org,
Albert Esteve <aesteve@redhat.com>,
mripard@redhat.com, echanude@redhat.com
Subject: [PATCH v3 3/6] of_reserved_mem: add a helper for rmem device_init op
Date: Fri, 06 Mar 2026 11:36:34 +0100 [thread overview]
Message-ID: <20260306-b4-dmabuf-heap-coherent-rmem-v3-3-3d00d36c9bc4@redhat.com> (raw)
In-Reply-To: <20260306-b4-dmabuf-heap-coherent-rmem-v3-0-3d00d36c9bc4@redhat.com>
Add a helper function wrapping internal reserved memory
device_init call and expose it externally.
Use the new helper function within of_reserved_mem_device_init_by_idx().
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
drivers/of/of_reserved_mem.c | 68 ++++++++++++++++++++++++++---------------
include/linux/of_reserved_mem.h | 8 +++++
2 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 1fd28f8056108..26ca871f7f919 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -605,6 +605,49 @@ struct rmem_assigned_device {
static LIST_HEAD(of_rmem_assigned_device_list);
static DEFINE_MUTEX(of_rmem_assigned_device_mutex);
+/**
+ * of_reserved_mem_device_init_with_mem() - assign reserved memory region to
+ * given device
+ * @dev: Pointer to the device to configure
+ * @rmem: Reserved memory region to assign
+ *
+ * This function assigns respective DMA-mapping operations based on the
+ * reserved memory region already provided in @rmem to the @dev device,
+ * without walking DT nodes.
+ *
+ * Returns error code or zero on success.
+ */
+int of_reserved_mem_device_init_with_mem(struct device *dev,
+ struct reserved_mem *rmem)
+{
+ struct rmem_assigned_device *rd;
+ int ret;
+
+ if (!dev || !rmem || !rmem->ops || !rmem->ops->device_init)
+ return -EINVAL;
+
+ rd = kmalloc_obj(struct rmem_assigned_device);
+ if (!rd)
+ return -ENOMEM;
+
+ ret = rmem->ops->device_init(rmem, dev);
+ if (ret == 0) {
+ rd->dev = dev;
+ rd->rmem = rmem;
+
+ mutex_lock(&of_rmem_assigned_device_mutex);
+ list_add(&rd->list, &of_rmem_assigned_device_list);
+ mutex_unlock(&of_rmem_assigned_device_mutex);
+
+ dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
+ } else {
+ kfree(rd);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_with_mem);
+
/**
* of_reserved_mem_device_init_by_idx() - assign reserved memory region to
* given device
@@ -623,10 +666,8 @@ static DEFINE_MUTEX(of_rmem_assigned_device_mutex);
int of_reserved_mem_device_init_by_idx(struct device *dev,
struct device_node *np, int idx)
{
- struct rmem_assigned_device *rd;
struct device_node *target;
struct reserved_mem *rmem;
- int ret;
if (!np || !dev)
return -EINVAL;
@@ -643,28 +684,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev,
rmem = of_reserved_mem_lookup(target);
of_node_put(target);
- if (!rmem || !rmem->ops || !rmem->ops->device_init)
- return -EINVAL;
-
- rd = kmalloc_obj(struct rmem_assigned_device);
- if (!rd)
- return -ENOMEM;
-
- ret = rmem->ops->device_init(rmem, dev);
- if (ret == 0) {
- rd->dev = dev;
- rd->rmem = rmem;
-
- mutex_lock(&of_rmem_assigned_device_mutex);
- list_add(&rd->list, &of_rmem_assigned_device_list);
- mutex_unlock(&of_rmem_assigned_device_mutex);
-
- dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
- } else {
- kfree(rd);
- }
-
- return ret;
+ return of_reserved_mem_device_init_with_mem(dev, rmem);
}
EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_idx);
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h
index f573423359f48..12f7ddb7ee61f 100644
--- a/include/linux/of_reserved_mem.h
+++ b/include/linux/of_reserved_mem.h
@@ -32,6 +32,8 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
_OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
+int of_reserved_mem_device_init_with_mem(struct device *dev,
+ struct reserved_mem *rmem);
int of_reserved_mem_device_init_by_idx(struct device *dev,
struct device_node *np, int idx);
int of_reserved_mem_device_init_by_name(struct device *dev,
@@ -51,6 +53,12 @@ int of_reserved_mem_region_count(const struct device_node *np);
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
_OF_DECLARE_STUB(reservedmem, name, compat, init, reservedmem_of_init_fn)
+static inline int of_reserved_mem_device_init_with_mem(struct device *dev,
+ struct reserved_mem *rmem)
+{
+ return -EOPNOTSUPP;
+}
+
static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
struct device_node *np, int idx)
{
--
2.52.0
next prev parent reply other threads:[~2026-03-06 10:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 10:36 [PATCH v3 0/6] dma-buf: heaps: add coherent reserved-memory heap Albert Esteve
2026-03-06 10:36 ` [PATCH v3 1/6] dma-buf: dma-heap: Keep track of the heap device struct Albert Esteve
2026-03-08 23:02 ` Claude review: " Claude Code Review Bot
2026-03-06 10:36 ` [PATCH v3 2/6] dma-buf: dma-heap: split dma_heap_add Albert Esteve
2026-03-08 23:02 ` Claude review: " Claude Code Review Bot
2026-03-06 10:36 ` Albert Esteve [this message]
2026-03-08 23:02 ` Claude review: of_reserved_mem: add a helper for rmem device_init op Claude Code Review Bot
2026-03-06 10:36 ` [PATCH v3 4/6] dma: coherent: store reserved memory coherent regions Albert Esteve
2026-03-08 23:02 ` Claude review: " Claude Code Review Bot
2026-03-06 10:36 ` [PATCH v3 5/6] dma-buf: heaps: Add Coherent heap to dmabuf heaps Albert Esteve
2026-03-08 23:02 ` Claude review: " Claude Code Review Bot
2026-03-06 10:36 ` [PATCH v3 6/6] dma-buf: heaps: coherent: Turn heap into a module Albert Esteve
2026-03-08 23:02 ` Claude review: " Claude Code Review Bot
2026-03-08 23:02 ` Claude review: dma-buf: heaps: add coherent reserved-memory heap Claude Code Review Bot
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=20260306-b4-dmabuf-heap-coherent-rmem-v3-3-3d00d36c9bc4@redhat.com \
--to=aesteve@redhat.com \
--cc=Brian.Starkey@arm.com \
--cc=benjamin.gaignard@collabora.com \
--cc=christian.koenig@amd.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=echanude@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jstultz@google.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mripard@redhat.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=saravanak@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.com \
/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