From: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
To: Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Manivannan Sadhasivam <mani@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Subject: [PATCH v3 08/12] firmware: qcom_scm: Add shmbridge support to pas_init/release function
Date: Sun, 21 Sep 2025 01:11:06 +0530 [thread overview]
Message-ID: <20250921-kvm_rproc_pas-v3-8-458f09647920@oss.qualcomm.com> (raw)
In-Reply-To: <20250921-kvm_rproc_pas-v3-0-458f09647920@oss.qualcomm.com>
For memory passed to Qualcomm TrustZone, it must either be part of a
pool registered with TZ or be directly registered via SHMbridge SMC
calls. When QHEE is present, PAS SMC calls from Linux running at EL1 are
trapped by QHEE (running at EL2), which then creates or retrieves memory
from the SHM bridge for both metadata and remoteproc carveout memory
before passing them to TZ. However, when the SoC runs with a
non-QHEE-based hypervisor, Linux must create the SHM bridge for both
metadata (before it is passed to TZ in qcom_scm_pas_init_image()) and
for remoteproc memory (before the call is made to TZ in
qcom_scm_pas_auth_and_reset()).
When QHEE is present, it takes care of programming firmware stream
and mapping resources for a remote processor which Linux need to take
care on its absence. Remote processor driver should appropriately set
ctx->has_iommu to let PAS SMC function to know and creating shmbridge
for the call to work
Lets put this awareness into qcom_scm_pas_init_image() and
qcom_scm_pas_metadata_release().
Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
---
drivers/firmware/qcom/qcom_scm.c | 46 +++++++++++++++++++++++++++++++---
include/linux/firmware/qcom/qcom_scm.h | 5 +++-
2 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c
index 022529778f84..6376a58a059c 100644
--- a/drivers/firmware/qcom/qcom_scm.c
+++ b/drivers/firmware/qcom/qcom_scm.c
@@ -642,6 +642,35 @@ static int __qcom_scm_pas_init_image(u32 pas_id, dma_addr_t mdata_phys, void *me
return ret;
}
+static int qcom_scm_pas_prep_and_init_image(struct qcom_scm_pas_ctx *ctx,
+ const void *metadata, size_t size)
+{
+ struct qcom_scm_pas_metadata *mdt_ctx;
+ struct qcom_scm_res res;
+ phys_addr_t mdata_phys;
+ void *mdata_buf;
+ int ret;
+
+ mdt_ctx = ctx->metadata;
+ mdata_buf = qcom_tzmem_alloc(__scm->mempool, size, GFP_KERNEL);
+ if (!mdata_buf)
+ return -ENOMEM;
+
+ memcpy(mdata_buf, metadata, size);
+ mdata_phys = qcom_tzmem_to_phys(mdata_buf);
+
+ ret = __qcom_scm_pas_init_image(ctx->pas_id, mdata_phys, mdata_buf, size, &res);
+ if (ret < 0 || !mdt_ctx) {
+ qcom_tzmem_free(mdata_buf);
+ } else if (mdt_ctx) {
+ mdt_ctx->ptr = mdata_buf;
+ mdt_ctx->addr.phys_addr = mdata_phys;
+ mdt_ctx->size = size;
+ }
+
+ return ret ? : res.result[0];
+}
+
/**
* qcom_scm_pas_init_image() - Initialize peripheral authentication service
* state machine for a given peripheral, using the
@@ -668,6 +697,11 @@ int qcom_scm_pas_init_image(u32 pas_id, const void *metadata, size_t size,
void *mdata_buf;
int ret;
+ if (ctx && ctx->has_iommu) {
+ ret = qcom_scm_pas_prep_and_init_image(ctx, metadata, size);
+ return ret;
+ }
+
/*
* During the scm call memory protection will be enabled for the meta
* data blob, so make sure it's physically contiguous, 4K aligned and
@@ -693,7 +727,7 @@ int qcom_scm_pas_init_image(u32 pas_id, const void *metadata, size_t size,
} else if (ctx && ctx->metadata) {
mdt_ctx = ctx->metadata;
mdt_ctx->ptr = mdata_buf;
- mdt_ctx->phys = mdata_phys;
+ mdt_ctx->addr.dma_addr = mdata_phys;
mdt_ctx->size = size;
}
@@ -713,9 +747,15 @@ void qcom_scm_pas_metadata_release(struct qcom_scm_pas_ctx *ctx)
if (!mdt_ctx->ptr)
return;
- dma_free_coherent(__scm->dev, mdt_ctx->size, mdt_ctx->ptr, mdt_ctx->phys);
+ if (ctx->has_iommu) {
+ qcom_tzmem_free(mdt_ctx->ptr);
+ mdt_ctx->addr.phys_addr = 0;
+ } else {
+ dma_free_coherent(__scm->dev, mdt_ctx->size, mdt_ctx->ptr,
+ mdt_ctx->addr.dma_addr);
+ mdt_ctx->addr.dma_addr = 0;
+ }
mdt_ctx->ptr = NULL;
- mdt_ctx->phys = 0;
mdt_ctx->size = 0;
}
EXPORT_SYMBOL_GPL(qcom_scm_pas_metadata_release);
diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h
index 1774584ff5e3..2fd42493d07c 100644
--- a/include/linux/firmware/qcom/qcom_scm.h
+++ b/include/linux/firmware/qcom/qcom_scm.h
@@ -68,7 +68,10 @@ int qcom_scm_set_remote_state(u32 state, u32 id);
struct qcom_scm_pas_metadata {
void *ptr;
- dma_addr_t phys;
+ union {
+ dma_addr_t dma_addr;
+ phys_addr_t phys_addr;
+ } addr;
ssize_t size;
};
--
2.50.1
next prev parent reply other threads:[~2025-09-20 19:42 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-20 19:40 [PATCH v3 00/12] Peripheral Image Loader support for Qualcomm SoCs running Linux host at EL2 Mukesh Ojha
2025-09-20 19:40 ` [PATCH v3 01/12] dt-bindings: remoteproc: qcom,pas: Add iommus property Mukesh Ojha
2025-09-21 21:32 ` Bryan O'Donoghue
2025-09-22 20:29 ` Rob Herring (Arm)
2025-09-20 19:41 ` [PATCH v3 02/12] firmware: qcom_scm: Rename peripheral as pas_id Mukesh Ojha
2025-09-21 21:31 ` Bryan O'Donoghue
2025-09-20 19:41 ` [PATCH v3 03/12] firmware: qcom_scm: Introduce PAS context initialization and destroy helper Mukesh Ojha
2025-09-21 21:40 ` Bryan O'Donoghue
2025-09-22 11:34 ` Mukesh Ojha
2025-09-20 19:41 ` [PATCH v3 04/12] soc: qcom: mdtloader: Add context aware qcom_mdt_pas_load() helper Mukesh Ojha
2025-09-21 7:31 ` kernel test robot
2025-09-21 21:49 ` Bryan O'Donoghue
2025-09-20 19:41 ` [PATCH v3 05/12] remoteproc: pas: Use PAS context awareness in smc and mdt functions Mukesh Ojha
2025-09-21 22:14 ` Bryan O'Donoghue
2025-09-20 19:41 ` [PATCH v3 06/12] firmware: qcom_scm: Add a prep version of auth_and_reset function Mukesh Ojha
2025-09-21 22:23 ` Bryan O'Donoghue
2025-09-21 22:27 ` Bryan O'Donoghue
2025-09-22 6:12 ` Mukesh Ojha
2025-09-20 19:41 ` [PATCH v3 07/12] firmware: qcom_scm: Simplify qcom_scm_pas_init_image() Mukesh Ojha
2025-09-20 19:41 ` Mukesh Ojha [this message]
2025-09-20 19:41 ` [PATCH v3 09/12] firmware: qcom_scm: Add qcom_scm_pas_get_rsc_table() to get resource table Mukesh Ojha
2025-09-20 19:41 ` [PATCH v3 10/12] remoteproc: pas: Extend parse_fw callback to fetch resources via SMC call Mukesh Ojha
2025-09-21 18:07 ` kernel test robot
2025-09-22 6:08 ` Mukesh Ojha
2025-09-20 19:41 ` [PATCH v3 11/12] remoteproc: qcom: pas: Enable Secure PAS support with IOMMU managed by Linux Mukesh Ojha
2025-09-20 19:41 ` [PATCH v3 12/12] arm64: dts: qcom: Add EL2 overlay for Lemans Mukesh Ojha
2025-09-22 8:21 ` Stephan Gerhold
2025-09-22 11:06 ` Mukesh Ojha
2025-09-22 12:15 ` Akhil P Oommen
2025-09-22 8:10 ` [PATCH v3 00/12] Peripheral Image Loader support for Qualcomm SoCs running Linux host at EL2 Stephan Gerhold
2025-09-22 9:47 ` Mukesh Ojha
2025-09-22 9:53 ` Stephan Gerhold
2025-09-22 10:33 ` Mukesh Ojha
2025-10-08 9:49 ` Konrad Dybcio
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=20250921-kvm_rproc_pas-v3-8-458f09647920@oss.qualcomm.com \
--to=mukesh.ojha@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=robh@kernel.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;
as well as URLs for NNTP newsgroup(s).