* [PATCH 0/5] misc: fastrpc: patches for v7.5
@ 2026-12-01 23:25 srini
2026-12-01 23:25 ` [PATCH 1/5] dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node names srini
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:25 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla
From: Srinivas Kandagatla <srini@kernel.org>
Hi Greg,
Here are few fastrpc patches for v7.5, Could you please queue these for v7.5.
The branch is based on char-misc-linus as these patches build on top of the
fastrpc fixes series already queued there.
Patches include
- iterate compute-bank nodes manually instead of
of_platform_populate and move ADSP duplicate session creation
into the driver.
- map the ADSP remote heap into the remoteproc IOMMU domain.
- dt-bindings update to allow hex digits in compute-cb node
names and deprecate qcom,nsessions.
Thanks,
Srini
Anandu Krishnan E (1):
misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain
Ekansh Gupta (1):
dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node
names
Vinayak Katoch (3):
misc: fastrpc: iterate CB nodes manually instead of
of_platform_populate
misc: fastrpc: move ADSP duplicate session creation to the driver
dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions
.../bindings/misc/qcom,fastrpc.yaml | 4 +-
drivers/misc/fastrpc.c | 302 +++++++++++++-----
2 files changed, 220 insertions(+), 86 deletions(-)
base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node names
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
@ 2026-12-01 23:25 ` srini
2026-12-01 23:26 ` [PATCH 2/5] misc: fastrpc: iterate CB nodes manually instead of of_platform_populate srini
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:25 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, Ekansh Gupta, Mukesh Ojha, Rob Herring (Arm),
Srinivas Kandagatla
From: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
The patternProperties key for compute-cb subnodes used [0-9]* which
only matches decimal digits. However, per DTS convention, node unit
addresses must be the lowercase hexadecimal representation of the reg
value. For compute-cb nodes with reg values >= 10 (e.g. 12, 13, 14),
the correct node names are compute-cb@c, compute-cb@d, compute-cb@e
respectively, which are not matched by the current pattern.
Extend the pattern to [0-9a-f]+ to allow lowercase hex digits, making
it consistent with DTS unit address conventions. Also change * to +
to require at least one digit in the unit address.
Reviewed-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Signed-off-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
index 49d2a5e8ba39..d9444f452585 100644
--- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
+++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
@@ -79,7 +79,7 @@ properties:
const: 0
patternProperties:
- "(compute-)?cb@[0-9]*$":
+ "(compute-)?cb@[0-9a-f]+$":
type: object
description: >
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/5] misc: fastrpc: iterate CB nodes manually instead of of_platform_populate
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
2026-12-01 23:25 ` [PATCH 1/5] dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node names srini
@ 2026-12-01 23:26 ` srini
2026-12-01 23:26 ` [PATCH 3/5] misc: fastrpc: move ADSP duplicate session creation to the driver srini
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:26 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Vinayak Katoch, Tyler Baker, Srinivas Kandagatla
From: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
of_platform_populate() only guarantees that child devices are registered,
not that their probes have completed before it returns. This creates a
window where fastrpc_cb_init() may not have run for all context bank
nodes, leaving the channel context partially initialised.
Introduce fastrpc_cb_devices_create() to iterate over child DT nodes
directly and call fastrpc_cb_init() synchronously for each
qcom,fastrpc-compute-cb node. This ensures all context banks are fully
initialised before fastrpc_rpmsg_probe() returns.
Since no driver binds to the CB devices any more, the driver core no
longer runs dma_configure() for them. Call of_dma_configure() for each
CB so that dma-coherent, dma-ranges and the IOMMU group are set up
before the session is used. If a CB cannot be configured (or has
"iommus" but no IOMMU group), log it, destroy that CB device and carry
on with the remaining ones, rather than leaving a half-configured
device behind for a later IOMMU registration to trip over, or failing
the whole channel probe. -EPROBE_DEFER still fails the probe so that it
is retried once the SMMU is available.
Introduce fastrpc_cb_devices_destroy() as the symmetric counterpart.
Before destroying the CB platform devices, invalidate all sessions under
the channel lock so that any fastrpc_user still holding a reference to
the channel context cannot acquire a new session backed by a destroyed
device.
Since fastrpc_cb_driver is no longer needed as an independent platform
driver, remove it along with its match table and remove callback. Use
module_rpmsg_driver() now that only a single driver registration remains.
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Tested-by: Tyler Baker <tyler.baker@oss.qualcomm.com> # Eliza EVK, EL2
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
drivers/misc/fastrpc.c | 120 ++++++++++++++++++++++-------------------
1 file changed, 66 insertions(+), 54 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 56284a7e42ca..811aeeb181f6 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/sort.h>
#include <linux/of_platform.h>
@@ -2459,7 +2460,7 @@ static const struct file_operations fastrpc_fops = {
.compat_ioctl = fastrpc_device_ioctl,
};
-static int fastrpc_cb_probe(struct platform_device *pdev)
+static int fastrpc_cb_init(struct platform_device *pdev)
{
struct fastrpc_channel_ctx *cctx;
struct fastrpc_session_ctx *sess;
@@ -2481,7 +2482,7 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
spin_lock_irqsave(&cctx->lock, flags);
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
spin_unlock_irqrestore(&cctx->lock, flags);
- dev_err(&pdev->dev, "too many sessions\n");
+ dev_err(dev, "too many sessions\n");
return -ENOSPC;
}
dma_bits = cctx->soc_data->dma_addr_bits_default;
@@ -2489,7 +2490,6 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
sess->used = false;
sess->valid = true;
sess->dev = dev;
- dev_set_drvdata(dev, sess);
sess->sid = sid;
if (cctx->domain_id == CDSP_DOMAIN_ID)
@@ -2515,37 +2515,75 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
return 0;
}
-static void fastrpc_cb_remove(struct platform_device *pdev)
+static void fastrpc_cb_devices_destroy(struct rpmsg_device *rpdev)
{
- struct fastrpc_channel_ctx *cctx = dev_get_drvdata(pdev->dev.parent);
- struct fastrpc_session_ctx *sess = dev_get_drvdata(&pdev->dev);
+ struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev);
+ struct device *rdev = &rpdev->dev;
unsigned long flags;
int i;
spin_lock_irqsave(&cctx->lock, flags);
- for (i = 0; i < FASTRPC_MAX_SESSIONS; i++) {
- if (cctx->session[i].sid == sess->sid) {
- cctx->session[i].valid = false;
- cctx->sesscount--;
- }
- }
+ for (i = 0; i < cctx->sesscount; i++)
+ cctx->session[i].valid = false;
spin_unlock_irqrestore(&cctx->lock, flags);
+
+ device_for_each_child_reverse(rdev, NULL, of_platform_device_destroy);
}
-static const struct of_device_id fastrpc_match_table[] = {
- { .compatible = "qcom,fastrpc-compute-cb" },
- { }
-};
+static int fastrpc_cb_devices_create(struct rpmsg_device *rpdev)
+{
+ struct device *rdev = &rpdev->dev;
+ struct platform_device *pdev;
+ struct device_node *np;
+ int err;
-static struct platform_driver fastrpc_cb_driver = {
- .probe = fastrpc_cb_probe,
- .remove = fastrpc_cb_remove,
- .driver = {
- .name = "qcom,fastrpc-cb",
- .of_match_table = fastrpc_match_table,
- .suppress_bind_attrs = true,
- },
-};
+ for_each_available_child_of_node(rdev->of_node, np) {
+ if (!of_device_is_compatible(np, "qcom,fastrpc-compute-cb"))
+ continue;
+
+ pdev = of_platform_device_create(np, NULL, rdev);
+ if (!pdev) {
+ of_node_put(np);
+ fastrpc_cb_devices_destroy(rpdev);
+ return -ENODEV;
+ }
+
+ /*
+ * No driver binds to the CB devices, so the driver core never
+ * runs dma_configure for them. Do it here so that dma-coherent,
+ * dma-ranges and the IOMMU link are set up before the session
+ * is used. A CB whose IOMMU setup failed is destroyed now,
+ * instead of being left for the next IOMMU registration to
+ * retry (and fail on), but does not fail the whole channel:
+ * failing the probe makes the DSP reopen the channel in a loop.
+ */
+ err = of_dma_configure(&pdev->dev, np, true);
+ if (!err && of_property_present(np, "iommus") &&
+ !device_iommu_mapped(&pdev->dev))
+ err = -ENODEV;
+ if (err) {
+ if (err == -EPROBE_DEFER) {
+ of_node_put(np);
+ fastrpc_cb_devices_destroy(rpdev);
+ return err;
+ }
+
+ dev_err(rdev, "skipping %pOF: failed to configure DMA/IOMMU: %d\n",
+ np, err);
+ of_platform_device_destroy(&pdev->dev, NULL);
+ continue;
+ }
+
+ err = fastrpc_cb_init(pdev);
+ if (err) {
+ of_node_put(np);
+ fastrpc_cb_devices_destroy(rpdev);
+ return err;
+ }
+ }
+
+ return 0;
+}
static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx,
bool is_secured, const char *domain)
@@ -2761,7 +2799,7 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
data->rpdev = rpdev;
dev_set_drvdata(&rpdev->dev, data);
- err = of_platform_populate(rdev->of_node, NULL, NULL, rdev);
+ err = fastrpc_cb_devices_create(rpdev);
if (err)
goto err_free_data;
@@ -2860,7 +2898,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
&cctx->remote_heap_addr, cctx->remote_heap_size, err);
}
- of_platform_depopulate(&rpdev->dev);
+ fastrpc_cb_devices_destroy(rpdev);
fastrpc_channel_ctx_put(cctx);
}
@@ -2947,33 +2985,7 @@ static struct rpmsg_driver fastrpc_driver = {
},
};
-static int fastrpc_init(void)
-{
- int ret;
-
- ret = platform_driver_register(&fastrpc_cb_driver);
- if (ret < 0) {
- pr_err("fastrpc: failed to register cb driver\n");
- return ret;
- }
-
- ret = register_rpmsg_driver(&fastrpc_driver);
- if (ret < 0) {
- pr_err("fastrpc: failed to register rpmsg driver\n");
- platform_driver_unregister(&fastrpc_cb_driver);
- return ret;
- }
-
- return 0;
-}
-module_init(fastrpc_init);
-
-static void fastrpc_exit(void)
-{
- platform_driver_unregister(&fastrpc_cb_driver);
- unregister_rpmsg_driver(&fastrpc_driver);
-}
-module_exit(fastrpc_exit);
+module_rpmsg_driver(fastrpc_driver);
MODULE_DESCRIPTION("Qualcomm FastRPC");
MODULE_LICENSE("GPL v2");
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] misc: fastrpc: move ADSP duplicate session creation to the driver
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
2026-12-01 23:25 ` [PATCH 1/5] dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node names srini
2026-12-01 23:26 ` [PATCH 2/5] misc: fastrpc: iterate CB nodes manually instead of of_platform_populate srini
@ 2026-12-01 23:26 ` srini
2026-12-01 23:26 ` [PATCH 4/5] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions srini
2026-12-01 23:26 ` [PATCH 5/5] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain srini
4 siblings, 0 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:26 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Vinayak Katoch, Tyler Baker, Srinivas Kandagatla
From: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
For ADSP, only a limited number of FastRPC context banks (CBs) are
available. Each CB supports a single session, which means only a few
processes can run on ADSP simultaneously. If all sessions are consumed
by fastrpc daemons, no session remains available when a user application
starts, causing the application to fail.
To work around this, qcom,nsessions = <5> was set in DT to duplicate
sessions inline during fastrpc_cb_init(). This policy does not belong
in DT and should be handled at the driver level instead.
Remove the qcom,nsessions DT property read and the per-CB duplication
logic from fastrpc_cb_init(). After all context banks have been
initialised in fastrpc_rpmsg_probe(), append FASTRPC_DUP_SESSIONS (4)
copies of the last successfully initialised session for the ADSP
domain.
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Tested-by: Tyler Baker <tyler.baker@oss.qualcomm.com> # Eliza EVK, EL2
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
drivers/misc/fastrpc.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 811aeeb181f6..1d4a0d268bf1 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -35,6 +35,11 @@
#define CDSP_DOMAIN_ID (3)
#define GDSP_DOMAIN_ID (4)
#define FASTRPC_MAX_SESSIONS 14
+/*
+ * Extra ADSP sessions duplicated from the last CB, as each CB supports
+ * only one session.
+ */
+#define FASTRPC_DUP_SESSIONS 4
#define FASTRPC_MAX_VMIDS 16
#define FASTRPC_ALIGN 128
#define FASTRPC_MAX_FDLIST 16
@@ -2465,7 +2470,6 @@ static int fastrpc_cb_init(struct platform_device *pdev)
struct fastrpc_channel_ctx *cctx;
struct fastrpc_session_ctx *sess;
struct device *dev = &pdev->dev;
- int i, sessions = 0;
unsigned long flags;
u32 dma_bits;
u32 sid = 0;
@@ -2475,7 +2479,6 @@ static int fastrpc_cb_init(struct platform_device *pdev)
if (!cctx)
return -EINVAL;
- of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions);
if (of_property_read_u32(dev->of_node, "reg", &sid))
dev_info(dev, "FastRPC Session ID not specified in DT\n");
@@ -2495,16 +2498,6 @@ static int fastrpc_cb_init(struct platform_device *pdev)
if (cctx->domain_id == CDSP_DOMAIN_ID)
dma_bits = cctx->soc_data->dma_addr_bits_cdsp;
- if (sessions > 0) {
- struct fastrpc_session_ctx *dup_sess;
-
- for (i = 1; i < sessions; i++) {
- if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
- break;
- dup_sess = &cctx->session[cctx->sesscount++];
- memcpy(dup_sess, sess, sizeof(*dup_sess));
- }
- }
spin_unlock_irqrestore(&cctx->lock, flags);
rc = dma_set_mask(dev, DMA_BIT_MASK(dma_bits));
if (rc) {
@@ -2830,6 +2823,22 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
goto err_depopulate;
}
+ if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
+ struct fastrpc_session_ctx *last_sess;
+ struct fastrpc_session_ctx *dup_sess;
+ unsigned long flags;
+
+ spin_lock_irqsave(&data->lock, flags);
+ last_sess = &data->session[data->sesscount - 1];
+ for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
+ if (data->sesscount >= FASTRPC_MAX_SESSIONS)
+ break;
+ dup_sess = &data->session[data->sesscount++];
+ memcpy(dup_sess, last_sess, sizeof(*dup_sess));
+ }
+ spin_unlock_irqrestore(&data->lock, flags);
+ }
+
return 0;
err_deregister_fdev:
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
` (2 preceding siblings ...)
2026-12-01 23:26 ` [PATCH 3/5] misc: fastrpc: move ADSP duplicate session creation to the driver srini
@ 2026-12-01 23:26 ` srini
2026-12-01 23:26 ` [PATCH 5/5] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain srini
4 siblings, 0 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:26 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, Vinayak Katoch, Krzysztof Kozlowski, Ekansh Gupta,
Tyler Baker, Srinivas Kandagatla
From: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
The qcom,nsessions property was used to duplicate FastRPC sessions
inline during context bank initialisation. Session duplication is now
handled at the driver level, making this DT property redundant. Mark
it deprecated.
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Reviewed-by: Ekansh Gupta <ekansh.gupta@oss.qualcomm.com>
Signed-off-by: Vinayak Katoch <vinayak.katoch@oss.qualcomm.com>
Tested-by: Tyler Baker <tyler.baker@oss.qualcomm.com> # Eliza EVK, EL2
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
index d9444f452585..6b6ad95d5cf4 100644
--- a/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
+++ b/Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
@@ -101,8 +101,10 @@ patternProperties:
qcom,nsessions:
$ref: /schemas/types.yaml#/definitions/uint32
default: 1
+ deprecated: true
description: >
A value indicating how many sessions can share this context bank.
+ Session duplication is now handled by the driver.
required:
- compatible
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
` (3 preceding siblings ...)
2026-12-01 23:26 ` [PATCH 4/5] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions srini
@ 2026-12-01 23:26 ` srini
4 siblings, 0 replies; 6+ messages in thread
From: srini @ 2026-12-01 23:26 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Anandu Krishnan E, Tyler Baker, Srinivas Kandagatla
From: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
On Qualcomm platforms without Gunyah/QHEE, the kernel runs at EL2
without a separate hypervisor to manage inter-VM memory access
control. In this configuration the remoteproc is assigned its own
IOMMU domain, and any memory carveout the DSP must access requires
an explicit mapping into that domain before the DSP can reach it.
The existing code calls qcom_scm_assign_mem() to transfer ownership
of the ADSP remote heap carveout from HLOS to the DSP VM. This SCM
call is only meaningful when a separate hypervisor (e.g. Gunyah) is
present to enforce inter-VM memory access control. On platforms
without such a hypervisor, the carveout must instead be mapped into
the remoteproc's IOMMU domain via an identity mapping (IOVA == PA)
using iommu_map(). Without this mapping the DSP triggers an SMMU
translation fault when accessing the remote heap during audio PD
static process creation.
Detect whether the remoteproc has an IOMMU by checking for the
"iommus" property on the remoteproc DT node and store the result in
a new use_iommu_map flag in fastrpc_channel_ctx. When the flag is
set, map the carveout into the remoteproc's IOMMU domain instead of
calling qcom_scm_assign_mem(). Introduce fastrpc_remote_heap_map()
and fastrpc_remote_heap_unmap() helpers to encapsulate the IOMMU
domain lookup and map/unmap operations, and a shared
fastrpc_remote_heap_release() helper that tears the mapping (or SCM
assignment) back down, used both from fastrpc_rpmsg_remove() and
from fastrpc_rpmsg_probe()'s error path.
Tested-by: Tyler Baker <tyler.baker@oss.qualcomm.com> # Eliza EVK, EL2
Signed-off-by: Anandu Krishnan E <anandu.e@oss.qualcomm.com>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
drivers/misc/fastrpc.c | 149 +++++++++++++++++++++++++++++++++++------
1 file changed, 130 insertions(+), 19 deletions(-)
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 1d4a0d268bf1..6b5f63cee14c 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -8,6 +8,7 @@
#include <linux/dma-mapping.h>
#include <linux/dma-resv.h>
#include <linux/idr.h>
+#include <linux/iommu.h>
#include <linux/list.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
@@ -330,6 +331,8 @@ struct fastrpc_channel_ctx {
/* Audio PD reserved remote heap region */
phys_addr_t remote_heap_addr;
u64 remote_heap_size;
+ /* set when remoteproc has an IOMMU; use iommu_map instead of hyp_assign */
+ bool use_iommu_map;
u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES];
struct fastrpc_device *secure_fdevice;
struct fastrpc_device *fdevice;
@@ -2660,9 +2663,120 @@ static const struct of_device_id fastrpc_poll_supported_machines[] __maybe_unuse
{},
};
+static struct device_node *fastrpc_get_rproc_node(struct device_node *node)
+{
+ struct device_node *parent, *rproc_node;
+
+ parent = of_get_parent(node);
+ if (!parent)
+ return NULL;
+
+ rproc_node = of_get_parent(parent);
+ of_node_put(parent);
+
+ return rproc_node;
+}
+
+static int fastrpc_remote_heap_map(struct device *rdev,
+ struct device_node *rproc_node,
+ phys_addr_t addr, u64 size)
+{
+ struct platform_device *rproc_pdev;
+ struct iommu_domain *domain;
+ int ret;
+
+ rproc_pdev = of_find_device_by_node(rproc_node);
+ if (!rproc_pdev) {
+ dev_err(rdev, "failed to find remoteproc platform device\n");
+ return -ENODEV;
+ }
+
+ domain = iommu_get_domain_for_dev(&rproc_pdev->dev);
+ if (!domain) {
+ put_device(&rproc_pdev->dev);
+ dev_err(rdev, "no IOMMU domain for remoteproc\n");
+ return -ENODEV;
+ }
+
+ ret = iommu_map(domain, addr, addr, size, IOMMU_READ | IOMMU_WRITE, GFP_KERNEL);
+ if (ret)
+ dev_err(rdev, "failed to map remote heap phys=0x%llx size=0x%llx err=%d\n",
+ (u64)addr, size, ret);
+
+ put_device(&rproc_pdev->dev);
+ return ret;
+}
+
+static void fastrpc_remote_heap_unmap(struct rpmsg_device *rpdev,
+ phys_addr_t addr, u64 size)
+{
+ struct device_node *rproc_node;
+ struct platform_device *rproc_pdev;
+ struct iommu_domain *domain;
+ size_t unmapped;
+
+ rproc_node = fastrpc_get_rproc_node(rpdev->dev.of_node);
+ if (!rproc_node) {
+ dev_warn(&rpdev->dev, "failed to find remoteproc node for heap unmap\n");
+ return;
+ }
+
+ rproc_pdev = of_find_device_by_node(rproc_node);
+ of_node_put(rproc_node);
+ if (!rproc_pdev) {
+ dev_warn(&rpdev->dev, "failed to find remoteproc platform device for heap unmap\n");
+ return;
+ }
+
+ domain = iommu_get_domain_for_dev(&rproc_pdev->dev);
+ if (!domain) {
+ dev_warn(&rpdev->dev, "no IOMMU domain for remoteproc during heap unmap\n");
+ put_device(&rproc_pdev->dev);
+ return;
+ }
+
+ unmapped = iommu_unmap(domain, addr, size);
+ if (unmapped != size)
+ dev_warn(&rpdev->dev, "partial/failed heap unmap: requested=0x%llx unmapped=0x%zx\n",
+ size, unmapped);
+
+ put_device(&rproc_pdev->dev);
+}
+
+static void fastrpc_remote_heap_release(struct fastrpc_channel_ctx *cctx,
+ struct rpmsg_device *rpdev)
+{
+ if (!cctx->remote_heap_size)
+ return;
+
+ if (cctx->use_iommu_map) {
+ fastrpc_remote_heap_unmap(rpdev, cctx->remote_heap_addr,
+ cctx->remote_heap_size);
+ } else if (cctx->vmcount) {
+ u64 src_perms = 0;
+ int err, i;
+ struct qcom_scm_vmperm dst_perms;
+
+ for (i = 0; i < cctx->vmcount; i++)
+ src_perms |= BIT(cctx->vmperms[i].vmid);
+
+ dst_perms.vmid = QCOM_SCM_VMID_HLOS;
+ dst_perms.perm = QCOM_SCM_PERM_RWX;
+
+ err = qcom_scm_assign_mem(cctx->remote_heap_addr,
+ cctx->remote_heap_size, &src_perms,
+ &dst_perms, 1);
+ if (err)
+ dev_err(&rpdev->dev,
+ "Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n",
+ &cctx->remote_heap_addr, cctx->remote_heap_size, err);
+ }
+}
+
static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
struct device *rdev, u32 domain_id)
{
+ struct device_node *rproc_node;
struct resource res;
u64 src_perms;
int err;
@@ -2689,6 +2803,19 @@ static int fastrpc_init_reserved_mem(struct fastrpc_channel_ctx *cctx,
if (domain_id == ADSP_DOMAIN_ID) {
cctx->remote_heap_addr = res.start;
cctx->remote_heap_size = resource_size(&res);
+
+ rproc_node = fastrpc_get_rproc_node(rdev->of_node);
+ if (rproc_node)
+ cctx->use_iommu_map = of_property_present(rproc_node, "iommus");
+
+ if (cctx->use_iommu_map) {
+ err = fastrpc_remote_heap_map(rdev, rproc_node, res.start,
+ resource_size(&res));
+ of_node_put(rproc_node);
+ return err;
+ }
+
+ of_node_put(rproc_node);
}
if (!cctx->vmcount)
@@ -2860,10 +2987,12 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
spin_unlock_irqrestore(&data->lock, flags);
of_platform_depopulate(rdev);
+ fastrpc_remote_heap_release(data, rpdev);
fastrpc_channel_ctx_put(data);
return err;
err_free_data:
+ fastrpc_remote_heap_release(data, rpdev);
kfree(data);
return err;
}
@@ -2887,25 +3016,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
fastrpc_notify_users(user);
spin_unlock_irqrestore(&cctx->lock, flags);
- if (cctx->remote_heap_size && cctx->vmcount) {
- u64 src_perms = 0;
- int err, i;
- struct qcom_scm_vmperm dst_perms;
-
- for (i = 0; i < cctx->vmcount; i++)
- src_perms |= BIT(cctx->vmperms[i].vmid);
-
- dst_perms.vmid = QCOM_SCM_VMID_HLOS;
- dst_perms.perm = QCOM_SCM_PERM_RWX;
-
- err = qcom_scm_assign_mem(cctx->remote_heap_addr,
- cctx->remote_heap_size, &src_perms,
- &dst_perms, 1);
- if (err)
- dev_err(&rpdev->dev,
- "Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n",
- &cctx->remote_heap_addr, cctx->remote_heap_size, err);
- }
+ fastrpc_remote_heap_release(cctx, rpdev);
fastrpc_cb_devices_destroy(rpdev);
--
2.53.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-01 23:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 23:25 [PATCH 0/5] misc: fastrpc: patches for v7.5 srini
2026-12-01 23:25 ` [PATCH 1/5] dt-bindings: misc: qcom,fastrpc: Allow hex digits in compute-cb node names srini
2026-12-01 23:26 ` [PATCH 2/5] misc: fastrpc: iterate CB nodes manually instead of of_platform_populate srini
2026-12-01 23:26 ` [PATCH 3/5] misc: fastrpc: move ADSP duplicate session creation to the driver srini
2026-12-01 23:26 ` [PATCH 4/5] dt-bindings: misc: qcom,fastrpc: deprecate qcom,nsessions srini
2026-12-01 23:26 ` [PATCH 5/5] misc: fastrpc: map ADSP remote heap into remoteproc IOMMU domain srini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®