Skip to contentSkip to conversation

Add new driver for WCSS secure PIL loading

PATCH In review Varadarajan Narayanan 5 participants 20 messages Aug 3 – Aug 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v14 cover Add new driver for WCSS secure PIL loading

As discussed in [4] posting this series after dropping IPQ5424 support to remove dependency on Sricharan's tmel-qmp mailbox driver series v4 [1].

Imported from [email protected].

Imported from [email protected] I've resumed Gokul's work as the last submission dates back April 2025.

- Secure PIL is signed, firmware images which only TrustZone (TZ) can authenticate and load. Linux kernel will send a request to TZ to authenticate and load the PIL images.

- When secure PIL support was added to the existing wcss PIL driver earlier in [2], Bjorn suggested not to overload the existing WCSS rproc driver, instead post a new driver for PAS based IPQ WCSS driver. This series adds a new secure PIL driver for the same.

- Also adds changes to scm to pass metadata size as required for IPQ5332, reposted from [3].

[1]
https://patchwork.kernel.org/project/linux-arm-msm/cover/[email protected]/

[2]
https://patchwork.kernel.org/project/linux-arm-msm/patch/[email protected]/

[3]
https://patchwork.kernel.org/project/linux-arm-msm/patch/[email protected]/

[4]
https://lore.kernel.org/linux-arm-msm/aUN7Aer%[email protected]/

Changes in v14:
- Fix dt-bindings-error
- Drop 'driver' from mbox description
- Remove Tested-by from dt-bindings patch
- Address applicable AI review feedback
Use %pe for PTR_ERR
Use the generic PAS context/API consistently
Handle wcss_sec_start() failures
Use proper PAS stop sequence in wcss_sec_stop()
Disable 'q6v5_wcss' in dtsi and enable in board specific dts
- Update constraints for qcom,smem-states in qcom,ipq5018-wcss-sec-pil.yaml
- Link to v13: https://lore.kernel.org/r/[email protected]

Changes in v13:
- Rebase to ToT (First patch alone had conflicts)
- Add 'Tested-by: Vignesh'
- Link to v12: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v12:
- No code change
- Rebase to ToT
- Change quicinc mail ids to oss.qualcomm.com mail ids
- Link to v11: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v11:
- Add R-b tags
- Rebase the first patch ("firmware: qcom_scm: ipq5332: add support to pass metadata size") to top of tree
- No change in other patches
- Link to v10: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v10:
- Add R-b tags
- Remove unused fields from 'struct wcss_sec'
- Remove glink and ssr subdev if wcss_sec_probe() fails
- Link to v9: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v9:
- Add R-b from Konrad for dts patches
- Renamed qcom,wcss-sec-pil.yaml -> qcom,ipq5018-wcss-sec-pil.yaml
- Restore clocks & clock-names in above yaml
- Fix DCO on two patches
- Link to v8: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v8:
- Dropped Krzysztof's 'Reviewed-by' as the bindings file has changed significantly
* IPQ5018 support added in v6
* IPQ5424 support dropped in v8
* Updated to use IPQ9574 as example
- dt-bindings-check and dtbs-check passed
- Dropped IPQ5424 support from drivers/remoteproc/qcom_q6v5_wcss_sec.c
- Updated copyrights of drivers/remoteproc/qcom_q6v5_wcss_sec.c
- Change 'qcom,smem-state-names' order to resolve dt-bindings-check error in ipq5018.dtsi
- Dropped changes to ipq5424.dtsi
- Link to v7: https://lore.kernel.org/linux-arm-msm/[email protected]/

Changes in v7:
- correctly sorted QCOM_SCM_PIL_PAS_INIT_IMAGE_V2 by command ID
- correctly sorted smp2p-wcss nodes in dtsi files
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- added patch to fix IPC register offset for ipq5424
- changed phandle description for mboxes property in dt-bindings
- updated bindings to define the right clocks per SoC based on
compatible. Ran make dt_binding_check for validation of all
SoCs
- use of more descriptive match data property (use_tmelcom) and
added a condition in wcss_start to not error out if tmelcom
isn't used
- mitigated potential off-by-one
- adopted use of of_reserved_mem_region_to_resource to acquire
memory-region resource
- added driver support for ipq5018 SoC
- corrected size of reg properties as per Konrad's comments
- added patch to bring up Q6 in ipq5018 dtsi
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- retained all the patches as in v3 and addressed comments in v3.
- reverted changes to dt-bindings done in v4 and retained as in v3 and fixed firmware format from .mdt to .mbn and retained reviewed-by.
- dropped 2 patches in v4 that adds support for q6 dtb loading. Will post them as a new series.

Following tests were done:
- checkpatch
- dt_binding_check and dtbs_check
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- changed q6 firmware image format from .mdt to .mbn
- corrected arrangement of variable assignemnts as per comments
in qcom_scm.c
- added scm call to get board machid
- added support for q6 dtb loading with support for additional
reserved memory for q6 dtb in .mbn format
- updated dt-bindings to include new dts entry qcom,q6-dtb-info
and additional item in memory-region for q6 dtb region.
- removed unnecessary dependency for QCOM_Q6V5_WCSS_SEC in
Kconfig
- removed unwanted header files in qcom_q6v5_wcss_sec.c
- removed repeated dtb parsing during runtime in qcom_q6v5_wcss_sec.c
- added required check for using tmelcom, if available. Enabled
fallback to scm based authentication, if tmelcom is unavailable.
- added necessary padding for 8digt hex address in dts
- Link to v3: https://lore.kernel.org/r/[email protected]

Following tests were done:
- checkpatch
- kernel-doc
- dt_binding_check and dtbs_check

Changes in v3:
- fixed copyright years and markings based on Jeff's comments.
- replaced devm_ioremap_wc() with ioremap_wc() in
wcss_sec_copy_segment().
- replaced rproc_alloc() and rproc_add() with their devres
counterparts.
- added mailbox call to tmelcom for secure image authentication
as required for IPQ5424. Added ipq5424 APCS comatible required.
- added changes to scm call to pass metadata size as required for
IPQ5332.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Removed dependency of this series to q6 clock removal series
as recommended by Krzysztof
- Link to v1: https://lore.kernel.org/r/[email protected]

George Moussalem (1):
arm64: dts: qcom: ipq5018: add nodes to bring up q6

Manikanta Mylavarapu (4):
firmware: qcom_scm: ipq5332: add support to pass metadata size
dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL
arm64: dts: qcom: ipq5332: add nodes to bring up q6
arm64: dts: qcom: ipq9574: add nodes to bring up q6

Vignesh Viswanathan (1):
remoteproc: qcom: add hexagon based WCSS secure PIL driver

 .../remoteproc/qcom,ipq5018-wcss-sec-pil.yaml | 178 ++++++++++
 arch/arm64/boot/dts/qcom/ipq5018.dtsi         |  64 ++++
 arch/arm64/boot/dts/qcom/ipq5332.dtsi         |  64 +++-
 arch/arm64/boot/dts/qcom/ipq9574.dtsi         |  60 +++-
 drivers/firmware/qcom/qcom_scm.c              |  14 +-
 drivers/firmware/qcom/qcom_scm.h              |   1 +
 drivers/remoteproc/Kconfig                    |  19 +
 drivers/remoteproc/Makefile                   |   1 +
 drivers/remoteproc/qcom_q6v5_wcss_sec.c       | 325 ++++++++++++++++++
 include/linux/remoteproc.h                    |   2 +
 10 files changed, 723 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml
 create mode 100644 drivers/remoteproc/qcom_q6v5_wcss_sec.c

To: Bjorn Andersson <[email protected]>
To: Konrad Dybcio <[email protected]>
To: Mathieu Poirier <[email protected]>
To: Rob Herring <[email protected]>
To: Krzysztof Kozlowski <[email protected]>
To: Conor Dooley <[email protected]>
To: Manikanta Mylavarapu <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
base-commit: next-20260710

Signature · 42 lines
2.34.1

Signed-off-by: Varadarajan Narayanan <[email protected]>
---
George Moussalem (1):
      arm64: dts: qcom: ipq5018: add nodes to bring up q6

Manikanta Mylavarapu (4):
      firmware: qcom_scm: ipq5332: add support to pass metadata size
      dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL
      arm64: dts: qcom: ipq5332: add nodes to bring up q6
      arm64: dts: qcom: ipq9574: add nodes to bring up q6

Varadarajan Narayanan (3):
      arm64: dts: qcom: ipq5018: Enable q6v5_wcss
      arm64: dts: qcom: ipq5332: Enable q6v5_wcss
      arm64: dts: qcom: ipq9574: Enable q6v5_wcss

Vignesh Viswanathan (1):
      remoteproc: qcom: add hexagon based WCSS secure PIL driver

 .../remoteproc/qcom,ipq5018-wcss-sec-pil.yaml      | 178 +++++++++++
 arch/arm64/boot/dts/qcom/ipq5018-rdp432-c2.dts     |   4 +
 arch/arm64/boot/dts/qcom/ipq5018.dtsi              |  66 ++++
 arch/arm64/boot/dts/qcom/ipq5332-rdp-common.dtsi   |   4 +
 arch/arm64/boot/dts/qcom/ipq5332.dtsi              |  64 ++++
 arch/arm64/boot/dts/qcom/ipq9574-rdp-common.dtsi   |   4 +
 arch/arm64/boot/dts/qcom/ipq9574.dtsi              |  62 +++-
 drivers/firmware/qcom/qcom_scm.c                   |  16 +-
 drivers/firmware/qcom/qcom_scm.h                   |   1 +
 drivers/remoteproc/Kconfig                         |  20 ++
 drivers/remoteproc/Makefile                        |   1 +
 drivers/remoteproc/qcom_q6v5_wcss_sec.c            | 337 +++++++++++++++++++++
 include/linux/remoteproc.h                         |   2 +
 13 files changed, 754 insertions(+), 5 deletions(-)
---
base-commit: 9dba66b6217aacb924d997de3866e7e4c0dcf952
change-id: 20260710-rproc-c4f4d0c1f45c

Best regards,
-- 
Varadarajan Narayanan <[email protected]>
#1 lore raw

PATCH v14 1/9 firmware: qcom_scm: ipq5332: add support to pass metadata size

From: Manikanta Mylavarapu <[email protected]>

IPQ5332 security software running under trustzone requires metadata size. With new command support added in TrustZone that includes a size parameter, pass metadata size as well.

---
 drivers/firmware/qcom/qcom_scm.c | 16 ++++++++++++----
 drivers/firmware/qcom/qcom_scm.h |  1 +
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/firmware/qcom/qcom_scm.c +12 -4
index 3eaa4c9ccf3c..8902c445cf19 100644
@@ -598,7 +598,7 @@ EXPORT_SYMBOL_GPL(devm_qcom_scm_pas_context_alloc);
 
 static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
 				     dma_addr_t mdata_phys,
-				     struct qcom_scm_res *res)
+				     struct qcom_scm_res *res, size_t size)
 {
 	struct qcom_scm_desc desc = {
 		.svc = QCOM_SCM_SVC_PIL,
@@ -619,6 +619,14 @@ static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
 
 	desc.args[1] = mdata_phys;
 
+	if (__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_PIL,
+					 QCOM_SCM_PIL_PAS_INIT_IMAGE_V2)) {
+		desc.cmd = QCOM_SCM_PIL_PAS_INIT_IMAGE_V2;
+		desc.arginfo = QCOM_SCM_ARGS(3, QCOM_SCM_VAL, QCOM_SCM_RW,
+					     QCOM_SCM_VAL);
+		desc.args[2] = size;
+	}
+
 	ret = qcom_scm_call(dev, &desc, res);
 	qcom_scm_bw_disable();
 
@@ -644,7 +652,7 @@ static int qcom_scm_pas_prep_and_init_image(struct device *dev,
 	memcpy(mdata_buf, metadata, size);
 	mdata_phys = qcom_tzmem_to_phys(mdata_buf);
 
-	ret = __qcom_scm_pas_init_image(dev, ctx->pas_id, mdata_phys, &res);
+	ret = __qcom_scm_pas_init_image(dev, ctx->pas_id, mdata_phys, &res, size);
 	if (ret < 0)
 		qcom_tzmem_free(mdata_buf);
 	else
@@ -683,7 +691,7 @@ static int __qcom_scm_pas_init_image2(struct device *dev, u32 pas_id,
 
 	memcpy(mdata_buf, metadata, size);
 
-	ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res);
+	ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res, size);
 	if (ret < 0 || !ctx) {
 		dma_free_coherent(dev, size, mdata_buf, mdata_phys);
 	} else if (ctx) {
@@ -2528,7 +2536,7 @@ static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm)
 	gunyah_wdt_dev = platform_device_register_simple("gunyah-wdt", -1,
 							 NULL, 0);
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",
 			PTR_ERR(gunyah_wdt_dev));
 		return;
 	}
drivers/firmware/qcom/qcom_scm.h +1 -0
index cf90a565fdfb..e58c76aba45c 100644
@@ -105,6 +105,7 @@ int qcom_scm_shm_bridge_enable(struct device *scm_dev);
 #define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
 #define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
 #define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
+#define QCOM_SCM_PIL_PAS_INIT_IMAGE_V2	0x1a
 #define QCOM_SCM_PIL_PAS_GET_RSCTABLE	0x21
 
 #define QCOM_SCM_SVC_IO			0x05
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The format specifier `%pe` is used with `PTR_ERR(gunyah_wdt_dev)`, causing a variadic type…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The format specifier %pe is used with PTR_ERR(gunyah_wdt_dev), causing a variadic type mismatch since %pe expects a pointer while PTR_ERR() returns a long. --

--- Patch [1]: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size --- commit fc14da7f3ebc47ea633f966df3048e0592f524ee
Author: Manikanta Mylavarapu <[email protected]>

firmware: qcom_scm: ipq5332: add support to pass metadata size

IPQ5332 security software running under trustzone requires metadata size. With new command support added in TrustZone that includes a size parameter, this passes the metadata size as well.

Quoted 4 lines
drivers/firmware/qcom/qcom_scm.c +0 -0
index 3eaa4c9ccf3cc..8902c445cf19f 100644

[ ... ]

drivers/firmware/qcom/qcom_scm.c static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm) · line 2540

Quoted 7 lines
drivers/firmware/qcom/qcom_scm.c +1 -1
@@ -2528,7 +2536,7 @@ static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm)
 	gunyah_wdt_dev = platform_device_register_simple("gunyah-wdt", -1,
 							 NULL, 0);
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",
 			PTR_ERR(gunyah_wdt_dev));

[Severity: Medium]
Will this type mismatch cause formatting or build issues?

The %pe format specifier strictly expects a pointer, but PTR_ERR() returns a long. Passing a long to %pe violates C variadic argument typing rules and triggers a compiler warning that could break the build in configurations using -Werror. At runtime, accessing a long as a pointer from va_list can lead to undefined behavior depending on the architecture's calling convention.

Could PTR_ERR() be removed so that gunyah_wdt_dev is passed directly to %pe?

Quoted 2 lines
drivers/firmware/qcom/qcom_scm.c +0 -0
 		return;
 	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v14 1/9
#3 lore raw

Re: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size

In reply to Varadarajan Narayanan
Quoted 64 lines · Varadarajan Narayanan

From: Manikanta Mylavarapu <[email protected]>

IPQ5332 security software running under trustzone requires metadata size. With new command support added in TrustZone that includes a size parameter, pass metadata size as well.

---
 drivers/firmware/qcom/qcom_scm.c | 16 ++++++++++++----
 drivers/firmware/qcom/qcom_scm.h |  1 +
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/firmware/qcom/qcom_scm.c +11 -3
index 3eaa4c9ccf3c..8902c445cf19 100644
@@ -598,7 +598,7 @@ EXPORT_SYMBOL_GPL(devm_qcom_scm_pas_context_alloc);
 
 static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
 				     dma_addr_t mdata_phys,
-				     struct qcom_scm_res *res)
+				     struct qcom_scm_res *res, size_t size)
 {
 	struct qcom_scm_desc desc = {
 		.svc = QCOM_SCM_SVC_PIL,
@@ -619,6 +619,14 @@ static int __qcom_scm_pas_init_image(struct device *dev, u32 pas_id,
 
 	desc.args[1] = mdata_phys;
 
+	if (__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_PIL,
+					 QCOM_SCM_PIL_PAS_INIT_IMAGE_V2)) {
+		desc.cmd = QCOM_SCM_PIL_PAS_INIT_IMAGE_V2;
+		desc.arginfo = QCOM_SCM_ARGS(3, QCOM_SCM_VAL, QCOM_SCM_RW,
+					     QCOM_SCM_VAL);
+		desc.args[2] = size;
+	}
+
 	ret = qcom_scm_call(dev, &desc, res);
 	qcom_scm_bw_disable();
 
@@ -644,7 +652,7 @@ static int qcom_scm_pas_prep_and_init_image(struct device *dev,
 	memcpy(mdata_buf, metadata, size);
 	mdata_phys = qcom_tzmem_to_phys(mdata_buf);
 
-	ret = __qcom_scm_pas_init_image(dev, ctx->pas_id, mdata_phys, &res);
+	ret = __qcom_scm_pas_init_image(dev, ctx->pas_id, mdata_phys, &res, size);
 	if (ret < 0)
 		qcom_tzmem_free(mdata_buf);
 	else
@@ -683,7 +691,7 @@ static int __qcom_scm_pas_init_image2(struct device *dev, u32 pas_id,
 
 	memcpy(mdata_buf, metadata, size);
 
-	ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res);
+	ret = __qcom_scm_pas_init_image(dev, pas_id, mdata_phys, &res, size);
 	if (ret < 0 || !ctx) {
 		dma_free_coherent(dev, size, mdata_buf, mdata_phys);
 	} else if (ctx) {

drivers/firmware/qcom/qcom_scm.c static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm) · line 2539

Quoted 5 lines
drivers/firmware/qcom/qcom_scm.c +1 -1
@@ -2528,7 +2536,7 @@ static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm)
 	gunyah_wdt_dev = platform_device_register_simple("gunyah-wdt", -1,
 							 NULL, 0);
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",

stray change..

Quoted 19 lines
drivers/firmware/qcom/qcom_scm.c +0 -0
 			PTR_ERR(gunyah_wdt_dev));
 		return;
 	}
drivers/firmware/qcom/qcom_scm.h +1 -0
index cf90a565fdfb..e58c76aba45c 100644
@@ -105,6 +105,7 @@ int qcom_scm_shm_bridge_enable(struct device *scm_dev);
 #define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
 #define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
 #define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
+#define QCOM_SCM_PIL_PAS_INIT_IMAGE_V2	0x1a
 #define QCOM_SCM_PIL_PAS_GET_RSCTABLE	0x21
 
 #define QCOM_SCM_SVC_IO			0x05
Signature · 2 lines
-- 
2.34.1

Otherwise, looks fine.

Signature · 1 line
-Mukesh Ojha
#4 lore raw

Re: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size

Mukesh,

[ . . . ]

Quoted 5 lines

drivers/firmware/qcom/qcom_scm.c static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm) · line 2539

Quoted 3 lines
drivers/firmware/qcom/qcom_scm.c +1 -1
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",

stray change..

Based on AI feedhack changed %ld to %pe to print PTR_ERR.

Thanks
Varada

Quoted 26 lines
Quoted 17 lines
drivers/firmware/qcom/qcom_scm.c +0 -0
 			PTR_ERR(gunyah_wdt_dev));
 		return;
 	}
drivers/firmware/qcom/qcom_scm.h +1 -1
index cf90a565fdfb..e58c76aba45c 100644
@@ -105,6 +105,7 @@ int qcom_scm_shm_bridge_enable(struct device *scm_dev);
 #define QCOM_SCM_PIL_PAS_SHUTDOWN	0x06
 #define QCOM_SCM_PIL_PAS_IS_SUPPORTED	0x07
 #define QCOM_SCM_PIL_PAS_MSS_RESET	0x0a
+#define QCOM_SCM_PIL_PAS_INIT_IMAGE_V2	0x1a
 #define QCOM_SCM_PIL_PAS_GET_RSCTABLE	0x21
 
 #define QCOM_SCM_SVC_IO			0x05
 
--
Quoted 2 lines

2.34.1

Otherwise, looks fine.

--
-Mukesh Ojha

#5 lore raw

Re: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size

Quoted 11 lines · Varadarajan Narayanan

Mukesh,

[ . . . ]

Quoted 5 lines

drivers/firmware/qcom/qcom_scm.c static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm) · line 2539

Quoted 3 lines
drivers/firmware/qcom/qcom_scm.c +1 -1
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",

stray change..

Based on AI feedhack changed %ld to %pe to print PTR_ERR.

Should be separate change.

-Mukesh

#6 lore raw

Re: [PATCH v14 1/9] firmware: qcom_scm: ipq5332: add support to pass metadata size

In reply to Varadarajan Narayanan
Quoted 11 lines · Varadarajan Narayanan

Mukesh,

[ . . . ]

Quoted 5 lines

drivers/firmware/qcom/qcom_scm.c static void qcom_scm_gunyah_wdt_init(struct qcom_scm *scm) · line 2539

Quoted 3 lines
drivers/firmware/qcom/qcom_scm.c +1 -1
 	if (IS_ERR(gunyah_wdt_dev)) {
-		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %ld\n",
+		dev_err(scm->dev, "Failed to register Gunyah watchdog device: %pe\n",

stray change..

Based on AI feedhack changed %ld to %pe to print PTR_ERR.

That was bad feedback. You just want the number, not the human readable string

#7 lore raw

PATCH v14 2/9 dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL

In reply to Varadarajan Narayanan

From: Manikanta Mylavarapu <[email protected]>

Add new binding document for hexagon based WCSS secure PIL remoteproc. IPQ5018, IPQ5332 and IPQ9574 follow secure PIL remoteproc.

---
 .../remoteproc/qcom,ipq5018-wcss-sec-pil.yaml      | 178 +++++++++++++++++++++
 1 file changed, 178 insertions(+)
Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml new file +178 -0
new file mode 100644
index 000000000000..1ec8df60d963
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm WCSS Secure Peripheral Image Loader
+
+maintainers:
+  - Manikanta Mylavarapu <[email protected]>
+
+description:
+  Wireless Connectivity Subsystem (WCSS) Secure Peripheral Image Loader loads
+  firmware and power up QDSP6 remoteproc on the Qualcomm IPQ series SoC.
+
+properties:
+  compatible:
+    enum:
+      - qcom,ipq5018-wcss-sec-pil
+      - qcom,ipq5332-wcss-sec-pil
+      - qcom,ipq9574-wcss-sec-pil
+
+  reg:
+    maxItems: 1
+
+  firmware-name:
+    maxItems: 1
+    description: Firmware name for the Hexagon core
+
+  interrupts:
+    items:
+      - description: Watchdog interrupt
+      - description: Fatal interrupt
+      - description: Ready interrupt
+      - description: Handover interrupt
+      - description: Stop acknowledge interrupt
+
+  interrupt-names:
+    items:
+      - const: wdog
+      - const: fatal
+      - const: ready
+      - const: handover
+      - const: stop-ack
+
+  clocks:
+    minItems: 1
+    items:
+      - description: sleep clock
+      - description: AHB interconnect clock
+
+  clock-names:
+    minItems: 1
+    items:
+      - const: sleep
+      - const: interconnect
+
+  mboxes:
+    items:
+      - description: TMECom mailbox
+
+  qcom,smem-states:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description: States used by the AP to signal the remote processor
+    items:
+      - minItems: 2
+      - maxItems: 2
+
+  qcom,smem-state-names:
+    description:
+      Names of the states used by the AP to signal the remote processor
+    items:
+      - const: stop
+      - const: shutdown
+
+  memory-region:
+    items:
+      - description: Q6 reserved region
+
+  glink-edge:
+    $ref: /schemas/remoteproc/qcom,glink-edge.yaml#
+    description:
+      Qualcomm G-Link subnode which represents communication edge, channels
+      and devices related to the Modem.
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - firmware-name
+  - interrupts
+  - interrupt-names
+  - qcom,smem-states
+  - qcom,smem-state-names
+  - memory-region
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,ipq5018-wcss-sec-pil
+    then:
+      properties:
+        clocks:
+          items:
+            - description: sleep clock
+            - description: AHB interconnect clock
+        clock-names:
+          items:
+            - const: sleep
+            - const: interconnect
+      required:
+        - clocks
+        - clock-names
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            const: qcom,ipq5332-wcss-sec-pil
+    then:
+      properties:
+        clocks:
+          items:
+            - description: sleep clock
+        clock-names:
+          items:
+            - const: sleep
+      required:
+        - clocks
+        - clock-names
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - qcom,ipq9574-wcss-sec-pil
+    then:
+      properties:
+        clocks: false
+        clock-names: false
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    q6v5_wcss: remoteproc@cd00000 {
+        compatible = "qcom,ipq9574-wcss-sec-pil";
+        reg = <0x0cd00000 0x10000>;
+        firmware-name = "ath11k/IPQ9574/hw1.0/q6_fw.mbn";
+        interrupts-extended = <&intc GIC_SPI 325 IRQ_TYPE_EDGE_RISING>,
+                              <&smp2p_wcss_in 0 IRQ_TYPE_NONE>,
+                              <&smp2p_wcss_in 1 IRQ_TYPE_NONE>,
+                              <&smp2p_wcss_in 2 IRQ_TYPE_NONE>,
+                              <&smp2p_wcss_in 3 IRQ_TYPE_NONE>;
+        interrupt-names = "wdog",
+                          "fatal",
+                          "ready",
+                          "handover",
+                          "stop-ack";
+
+        qcom,smem-states = <&smp2p_wcss_out 1>,
+                           <&smp2p_wcss_out 0>;
+        qcom,smem-state-names = "stop",
+                                "shutdown";
+        memory-region = <&q6_region>;
+
+        glink-edge {
+            interrupts = <GIC_SPI 321 IRQ_TYPE_EDGE_RISING>;
+            label = "rtr";
+            qcom,remote-pid = <1>;
+            mboxes = <&apcs_glb 8>;
+        };
+    };
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v14 2/9] dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Incorrect placement of `minItems` and `maxItems` inside the `items` list for `qcom,smem-states`.…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Incorrect placement of minItems and maxItems inside the items list for qcom,smem-states.
- [Low] Copy-paste error in the description for glink-edge referencing the 'Modem'.
--

--- Patch [2]: [PATCH v14 2/9] dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL --- commit 8f051c37adcc2888cdf46122f432edbd580d36be
Author: Manikanta Mylavarapu <[email protected]>

dt-bindings: remoteproc: qcom: document hexagon based WCSS secure PIL

Add new binding document for hexagon based WCSS secure PIL remoteproc. IPQ5018, IPQ5332 and IPQ9574 follow secure PIL remoteproc.

Quoted 5 lines
Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml new file +0 -0
new file mode 100644
index 0000000000000..1ec8df60d9633

[ ... ]

Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml line 67

Quoted 10 lines
Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml new file +10 -0
+  mboxes:
+    items:
+      - description: TMECom mailbox
+
+  qcom,smem-states:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    description: States used by the AP to signal the remote processor
+    items:
+      - minItems: 2
+      - maxItems: 2

[Severity: Medium]
Is it intentional to place minItems and maxItems as elements inside the items array?

By placing them inside the items array, the dt-schema validator treats them as schemas for the individual elements of the phandle array (i.e. the first tuple is validated against {minItems: 2} and the second against {maxItems: 2}).

If the intent is to restrict the length of the qcom,smem-states array itself to 2 items, should these be sibling properties to items rather than inside it?

Quoted 4 lines
Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml new file +4 -0
+
+  qcom,smem-state-names:
+    description:
+      Names of the states used by the AP to signal the remote processor

[ ... ]

Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml line 84

Quoted 9 lines
Documentation/devicetree/bindings/remoteproc/qcom,ipq5018-wcss-sec-pil.yaml new file +9 -0
+  memory-region:
+    items:
+      - description: Q6 reserved region
+
+  glink-edge:
+    $ref: /schemas/remoteproc/qcom,glink-edge.yaml#
+    description:
+      Qualcomm G-Link subnode which represents communication edge, channels
+      and devices related to the Modem.

[Severity: Low]
This isn't a bug, but should the description reference "WCSS" instead of "Modem"?

Since this binding is for the Wireless Connectivity Subsystem, mentioning the Modem appears to be a leftover from a copy-paste of a modem remoteproc binding.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#9 lore raw

PATCH v14 3/9 remoteproc: qcom: add hexagon based WCSS secure PIL driver

In reply to Varadarajan Narayanan

From: Vignesh Viswanathan <[email protected]>

Add support to bring up hexagon based WCSS using secure PIL. All IPQxxxx SoCs support secure Peripheral Image Loading (PIL).

Secure PIL image is signed firmware image which only trusted software such as TrustZone (TZ) can authenticate and load. Linux kernel will send a Peripheral Authentication Service (PAS) request to TZ to authenticate and load the PIL images.

In order to avoid overloading the existing WCSS driver or PAS driver, we came up with this new PAS based IPQ WCSS driver.

---
 drivers/remoteproc/Kconfig              |  20 ++
 drivers/remoteproc/Makefile             |   1 +
 drivers/remoteproc/qcom_q6v5_wcss_sec.c | 337 ++++++++++++++++++++++++++++++++
 include/linux/remoteproc.h              |   2 +
 4 files changed, 360 insertions(+)
drivers/remoteproc/Kconfig +20 -0
index 5b56b2dcc725..3feea5bda129 100644
@@ -267,6 +267,26 @@ config QCOM_Q6V5_WCSS
 	  Hexagon V5 based WCSS remote processors on e.g. IPQ8074.  This is
 	  a non-TrustZone wireless subsystem.
 
+config QCOM_Q6V5_WCSS_SEC
+	tristate "Qualcomm Hexagon based WCSS Secure Peripheral Image Loader"
+	depends on OF && ARCH_QCOM
+	depends on QCOM_SMEM
+	depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n
+	depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n
+	depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n
+	select QCOM_MDT_LOADER
+	select QCOM_PIL_INFO
+	select QCOM_Q6V5_COMMON
+	select QCOM_RPROC_COMMON
+	select QCOM_SCM
+	help
+	  Say y here to support the Qualcomm Secure Peripheral Image Loader
+	  for the Hexagon based remote processors on e.g. IPQ5332.
+
+	  This is TrustZone wireless subsystem. The firmware is
+	  verified and booted with the help of the Peripheral Authentication
+	  System (PAS) in TrustZone.
+
 config QCOM_SYSMON
 	tristate "Qualcomm sysmon driver"
 	depends on RPMSG
drivers/remoteproc/Makefile +1 -0
index 689686de0d41..f74519ea6502 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_QCOM_Q6V5_ADSP)		+= qcom_q6v5_adsp.o
 obj-$(CONFIG_QCOM_Q6V5_MSS)		+= qcom_q6v5_mss.o
 obj-$(CONFIG_QCOM_Q6V5_PAS)		+= qcom_q6v5_pas.o
 obj-$(CONFIG_QCOM_Q6V5_WCSS)		+= qcom_q6v5_wcss.o
+obj-$(CONFIG_QCOM_Q6V5_WCSS_SEC)	+= qcom_q6v5_wcss_sec.o
 obj-$(CONFIG_QCOM_SYSMON)		+= qcom_sysmon.o
 obj-$(CONFIG_QCOM_WCNSS_PIL)		+= qcom_wcnss_pil.o
 qcom_wcnss_pil-y			+= qcom_wcnss.o
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +337 -0

337 lines not on this page · raw message

include/linux/remoteproc.h +2 -0
index ef711a5b1a7f..cf06b9846309 100644
@@ -204,6 +204,7 @@ enum rproc_dump_mechanism {
  * @node:	list node related to the rproc segment list
  * @da:		device address of the segment
  * @size:	size of the segment
+ * @io_ptr:	ptr to store the ioremapped dump segment
  * @priv:	private data associated with the dump_segment
  * @dump:	custom dump function to fill device memory segment associated
  *		with coredump
@@ -215,6 +216,7 @@ struct rproc_dump_segment {
 	dma_addr_t da;
 	size_t size;
 
+	void __iomem *io_ptr;
 	void *priv;
 	void (*dump)(struct rproc *rproc, struct rproc_dump_segment *segment,
 		     void *dest, size_t offset, size_t size);
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v14 3/9] remoteproc: qcom: add hexagon based WCSS secure PIL driver

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:

New issues:
- [High] Teardown asymmetry between devm_rproc_add and manual remove cleanup causes subdevices to skip shutdown routines and causes lockless list corruption.
- [High] wcss_sec_copy_segment silently returns on ioremap_wc failure, corrupting the devcoredump with uninitialized memory or zeroes.
- [Medium] Permanent ioremap_wc mapping leak during coredump segment reading due to unreachable unmap condition.
- [Medium] Error paths in wcss_sec_dump_segments permanently leak previously added custom coredump segments.
- [Medium] Missing NULL check on of_device_get_match_data during driver probe.

Pre-existing issues:
- [High] Unconditionally calling qcom_remove_ssr_subdev() on uninitialized subdev causes a kernel panic if qcom_add_ssr_subdev() failed silently. --

--- Patch [3]: [PATCH v14 3/9] remoteproc: qcom: add hexagon based WCSS secure PIL driver --- commit f96fb4a46b22ed73d132da71366a2ebbfe51729c
Author: Vignesh Viswanathan <[email protected]>
Subject: remoteproc: qcom: add hexagon based WCSS secure PIL driver

Adds support for a Hexagon-based WCSS secure PIL driver for IPQxxxx SoCs using TrustZone (TZ) for authentication and loading.

Quoted 4 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 4 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +4 -0
+static void wcss_sec_copy_segment(struct rproc *rproc,
+				  struct rproc_dump_segment *segment,
+				  void *dest, size_t offset, size_t size)
+{

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 145

Quoted 10 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +10 -0
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+
+	if (!segment->io_ptr)
+		segment->io_ptr = ioremap_wc(segment->da, segment->size);
+
+	if (!segment->io_ptr) {
+		dev_err(dev, "Failed to ioremap segment %pad size 0x%zx\n",
+			&segment->da, segment->size);
+		return;

[Severity: High]
If ioremap_wc() fails, this returns early without populating the userspace buffer. Because it returns void, the devcoredump core assumes the copy succeeded.

Does this cause the framework to leak uninitialized kernel memory (if not zeroed) or zeroes to userspace, silently corrupting the coredump instead of gracefully failing?

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 153

Quoted 8 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +8 -0
+	}
+
+	if (offset + size <= segment->size) {
+		memcpy_fromio(dest, segment->io_ptr + offset, size);
+	} else {
+		iounmap(segment->io_ptr);
+		segment->io_ptr = NULL;
+	}

[Severity: Medium]
Because the remoteproc framework bounds the read size such that offset + size <= segment->size is always true, is this else branch mathematically dead code?

During cleanup, rproc_coredump_cleanup() frees the segment structure but lacks a hook to unmap the custom io_ptr. Could this permanently leak vmalloc space on every crash dump?

Quoted 1 line

+}

[ ... ]

Quoted 17 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +17 -0
+static int wcss_sec_dump_segments(struct rproc *rproc,
+				  const struct firmware *fw)
+{
+	struct device *dev = rproc->dev.parent;
+	struct reserved_mem *rmem = NULL;
+	struct device_node *node;
+	int num_segs, index;
+	int ret;
+
+	/*
+	 * Parse through additional reserved memory regions for the rproc
+	 * and add them to the coredump segments
+	 */
+	num_segs = of_count_phandle_with_args(dev->of_node,
+					      "memory-region", NULL);
+	for (index = 0; index < num_segs; index++) {
+		node = of_parse_phandle(dev->of_node,

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 182

Quoted 10 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +10 -0
+					"memory-region", index);
+		if (!node)
+			return -EINVAL;
+
+		rmem = of_reserved_mem_lookup(node);
+		of_node_put(node);
+		if (!rmem) {
+			dev_err(dev, "unable to acquire memory-region index %d num_segs %d\n",
+				index, num_segs);
+			return -EINVAL;

[Severity: Medium]
If an error occurs midway through the segment parsing loop, does returning early here leave previously added segments on the rproc->dump_segments list?

The remoteproc core's rproc_fw_boot() handles a parse_fw() failure by jumping directly to unprepare_rproc, bypassing rproc_resource_cleanup(). Will any segments successfully added in earlier iterations be permanently leaked?

Quoted 1 line
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +1 -0
+		}

[ ... ]

Quoted 7 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +7 -0
+static int wcss_sec_probe(struct platform_device *pdev)
+{
+	const struct wcss_data *desc = of_device_get_match_data(&pdev->dev);
+	const char *fw_name = NULL;
+	struct wcss_sec *wcss;
+	struct clk *sleep_clk;
+	struct clk *int_clk;

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 249

Quoted 10 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +10 -0
+	struct rproc *rproc;
+	int ret;
+
+	ret = of_property_read_string(pdev->dev.of_node, "firmware-name",
+				      &fw_name);
+	if (ret < 0)
+		return ret;
+
+	rproc = devm_rproc_alloc(&pdev->dev, desc->ss_name, &wcss_sec_ops,
+				 fw_name, sizeof(*wcss));

[Severity: Medium]
Is a NULL check needed for the return value of of_device_get_match_data()?

If the driver is bound manually via sysfs to a platform device with a compatible of_node that lacks match data in the driver's table, it could return NULL and cause a NULL pointer dereference on desc->ss_name.

Quoted 1 line
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +1 -0
+	if (!rproc) {

[ ... ]

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 287

Quoted 10 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +10 -0
+	qcom_add_glink_subdev(rproc, &wcss->glink_subdev, desc->ss_name);
+	qcom_add_ssr_subdev(rproc, &wcss->ssr_subdev, desc->ss_name);
+
+	rproc->auto_boot = desc->auto_boot;
+	rproc->dump_conf = RPROC_COREDUMP_INLINE;
+	rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
+
+	ret = devm_rproc_add(&pdev->dev, rproc);
+	if (ret) {
+		qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);

[Severity: High]
This is a pre-existing issue, but if qcom_add_ssr_subdev() fails (e.g., due to -ENOMEM), it returns early and leaves ssr->subdev.node zero-initialized.

Later, unconditionally calling qcom_remove_ssr_subdev() here during probe error handling (or in wcss_sec_remove() below) invokes list_del() on the zero-initialized list head. Can this dereference a NULL prev pointer and cause a kernel panic?

Quoted 7 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +7 -0
+		qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);
+		qcom_q6v5_deinit(&wcss->q6);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, rproc);
+

drivers/remoteproc/qcom_q6v5_wcss_sec.c line 304

Quoted 10 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +10 -0
+	return 0;
+}
+
+static void wcss_sec_remove(struct platform_device *pdev)
+{
+	struct rproc *rproc = platform_get_drvdata(pdev);
+	struct wcss_sec *wcss = rproc->priv;
+
+	qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);
+	qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);

[Severity: High]
Because rproc_del() is deferred to devres cleanup (after remove()), does manually removing subdevices from rproc->subdevs here while the rproc is still active skip their .stop callbacks?

Since they are no longer in the list when rproc_del() executes, it seems this leaves GLINK edges active and dangling for a powered-off remoteproc, potentially corrupting the GLINK state machine and freeing structures still in use. Should the subdevices be left for rproc_del() to clean up?

Quoted 2 lines
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +2 -0
+	qcom_q6v5_deinit(&wcss->q6);
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#11 lore raw

Re: [PATCH v14 3/9] remoteproc: qcom: add hexagon based WCSS secure PIL driver

In reply to Varadarajan Narayanan
Quoted 5 lines · Varadarajan Narayanan

From: Vignesh Viswanathan <[email protected]>

Add support to bring up hexagon based WCSS using secure PIL. All IPQxxxx SoCs support secure Peripheral Image Loading (PIL).

Quoted 7 lines

Secure PIL image is signed firmware image which only trusted software such as TrustZone (TZ) can authenticate and load. Linux kernel will send a Peripheral Authentication Service (PAS) request to TZ to authenticate and load the PIL images.

In order to avoid overloading the existing WCSS driver or PAS driver, we came up with this new PAS based IPQ WCSS driver.

Can you tell why you need another driver if you are using the same PAS method and it is using more of everything what PAS already supports ?

Quoted 8 lines

Author and tested looks weird..here..

Quoted 418 lines
---
 drivers/remoteproc/Kconfig              |  20 ++
 drivers/remoteproc/Makefile             |   1 +
 drivers/remoteproc/qcom_q6v5_wcss_sec.c | 337 ++++++++++++++++++++++++++++++++
 include/linux/remoteproc.h              |   2 +
 4 files changed, 360 insertions(+)
drivers/remoteproc/Kconfig +20 -0
index 5b56b2dcc725..3feea5bda129 100644
@@ -267,6 +267,26 @@ config QCOM_Q6V5_WCSS
 	  Hexagon V5 based WCSS remote processors on e.g. IPQ8074.  This is
 	  a non-TrustZone wireless subsystem.
 
+config QCOM_Q6V5_WCSS_SEC
+	tristate "Qualcomm Hexagon based WCSS Secure Peripheral Image Loader"
+	depends on OF && ARCH_QCOM
+	depends on QCOM_SMEM
+	depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n
+	depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n
+	depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n
+	select QCOM_MDT_LOADER
+	select QCOM_PIL_INFO
+	select QCOM_Q6V5_COMMON
+	select QCOM_RPROC_COMMON
+	select QCOM_SCM
+	help
+	  Say y here to support the Qualcomm Secure Peripheral Image Loader
+	  for the Hexagon based remote processors on e.g. IPQ5332.
+
+	  This is TrustZone wireless subsystem. The firmware is
+	  verified and booted with the help of the Peripheral Authentication
+	  System (PAS) in TrustZone.
+
 config QCOM_SYSMON
 	tristate "Qualcomm sysmon driver"
 	depends on RPMSG
drivers/remoteproc/Makefile +1 -0
index 689686de0d41..f74519ea6502 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_QCOM_Q6V5_ADSP)		+= qcom_q6v5_adsp.o
 obj-$(CONFIG_QCOM_Q6V5_MSS)		+= qcom_q6v5_mss.o
 obj-$(CONFIG_QCOM_Q6V5_PAS)		+= qcom_q6v5_pas.o
 obj-$(CONFIG_QCOM_Q6V5_WCSS)		+= qcom_q6v5_wcss.o
+obj-$(CONFIG_QCOM_Q6V5_WCSS_SEC)	+= qcom_q6v5_wcss_sec.o
 obj-$(CONFIG_QCOM_SYSMON)		+= qcom_sysmon.o
 obj-$(CONFIG_QCOM_WCNSS_PIL)		+= qcom_wcnss_pil.o
 qcom_wcnss_pil-y			+= qcom_wcnss.o
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +337 -0
new file mode 100644
index 000000000000..4837825d1717
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+#include <linux/clk.h>
+#include <linux/firmware/qcom/qcom_pas.h>
+#include <linux/io.h>
+#include <linux/mailbox_client.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/soc/qcom/mdt_loader.h>
+
+#include "qcom_common.h"
+#include "qcom_q6v5.h"
+#include "qcom_pil_info.h"
+
+#define WCSS_CRASH_REASON		421
+
+#define WCSS_PAS_ID			0x6
+#define MPD_WCSS_PAS_ID			0xd
+
+#define Q6_WAIT_TIMEOUT			(5 * HZ)
+
+struct wcss_sec {
+	struct device *dev;
+	struct qcom_rproc_glink glink_subdev;
+	struct qcom_rproc_ssr ssr_subdev;
+	struct qcom_q6v5 q6;
+	phys_addr_t mem_phys;
+	phys_addr_t mem_reloc;
+	void *mem_region;
+	size_t mem_size;
+	const struct wcss_data *desc;
+};
+
+struct wcss_data {
+	u32 pasid;
+	const char *ss_name;
+	bool auto_boot;
+};
+
+static int wcss_sec_start(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_q6v5_prepare(&wcss->q6);
+	if (ret)
+		return ret;
+
+	ret = qcom_pas_auth_and_reset(wcss->desc->pasid);
+	if (ret) {
+		dev_err(dev, "wcss_reset failed\n");
+		goto unprepare;
+	}
+
+	ret = qcom_q6v5_wait_for_start(&wcss->q6, msecs_to_jiffies(Q6_WAIT_TIMEOUT));
+
+	if (ret == -ETIMEDOUT) {
+		dev_err(dev, "start timed out\n");
+		qcom_pas_shutdown(wcss->desc->pasid);
+		goto unprepare;
+	}
+
+	return 0;
+
+unprepare:
+	qcom_q6v5_unprepare(&wcss->q6);
+
+	return ret;
+}
+
+static int wcss_sec_stop(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_q6v5_request_stop(&wcss->q6, NULL);
+	if (ret == -ETIMEDOUT)
+		dev_err(dev, "timed out on wait\n");
+
+	ret = qcom_pas_shutdown(wcss->desc->pasid);
+	if (ret)
+		dev_err(dev, "Failed to shutdown %d\n", ret);
+
+	qcom_q6v5_unprepare(&wcss->q6);
+
+	return ret;
+}
+
+static void *wcss_sec_da_to_va(struct rproc *rproc, u64 da, size_t len,
+			       bool *is_iomem)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	int offset;
+
+	offset = da - wcss->mem_reloc;
+	if (offset < 0 || offset + len > wcss->mem_size)
+		return NULL;
+
+	if (is_iomem)
+		*is_iomem = true;
+
+	return wcss->mem_region + offset;
+}
+
+static int wcss_sec_load(struct rproc *rproc, const struct firmware *fw)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_mdt_load(dev, fw, rproc->firmware, wcss->desc->pasid, wcss->mem_region,
+			    wcss->mem_phys, wcss->mem_size, &wcss->mem_reloc);
+	if (ret)
+		return ret;
+
+	qcom_pil_info_store("wcss", wcss->mem_phys, wcss->mem_size);
+
+	return 0;
+}
+
+static unsigned long wcss_sec_panic(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+
+	return qcom_q6v5_panic(&wcss->q6);
+}
+
+static void wcss_sec_copy_segment(struct rproc *rproc,
+				  struct rproc_dump_segment *segment,
+				  void *dest, size_t offset, size_t size)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+
+	if (!segment->io_ptr)
+		segment->io_ptr = ioremap_wc(segment->da, segment->size);
+
+	if (!segment->io_ptr) {
+		dev_err(dev, "Failed to ioremap segment %pad size 0x%zx\n",
+			&segment->da, segment->size);
+		return;
+	}
+
+	if (offset + size <= segment->size) {
+		memcpy_fromio(dest, segment->io_ptr + offset, size);
+	} else {
+		iounmap(segment->io_ptr);
+		segment->io_ptr = NULL;
+	}
+}
+
+static int wcss_sec_dump_segments(struct rproc *rproc,
+				  const struct firmware *fw)
+{
+	struct device *dev = rproc->dev.parent;
+	struct reserved_mem *rmem = NULL;
+	struct device_node *node;
+	int num_segs, index;
+	int ret;
+
+	/*
+	 * Parse through additional reserved memory regions for the rproc
+	 * and add them to the coredump segments
+	 */
+	num_segs = of_count_phandle_with_args(dev->of_node,
+					      "memory-region", NULL);
+	for (index = 0; index < num_segs; index++) {
+		node = of_parse_phandle(dev->of_node,
+					"memory-region", index);
+		if (!node)
+			return -EINVAL;
+
+		rmem = of_reserved_mem_lookup(node);
+		of_node_put(node);
+		if (!rmem) {
+			dev_err(dev, "unable to acquire memory-region index %d num_segs %d\n",
+				index, num_segs);
+			return -EINVAL;
+		}
+
+		dev_dbg(dev, "Adding segment 0x%pa size 0x%pa",
+			&rmem->base, &rmem->size);
+		ret = rproc_coredump_add_custom_segment(rproc,
+							rmem->base,
+							rmem->size,
+							wcss_sec_copy_segment,
+							NULL);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const struct rproc_ops wcss_sec_ops = {
+	.start = wcss_sec_start,
+	.stop = wcss_sec_stop,
+	.da_to_va = wcss_sec_da_to_va,
+	.load = wcss_sec_load,
+	.get_boot_addr = rproc_elf_get_boot_addr,
+	.panic = wcss_sec_panic,
+	.parse_fw = wcss_sec_dump_segments,
+};
+
+static int wcss_sec_alloc_memory_region(struct wcss_sec *wcss)
+{
+	struct device *dev = wcss->dev;
+	struct resource res;
+	int ret;
+
+	ret = of_reserved_mem_region_to_resource(dev->of_node, 0, &res);
+	if (ret) {
+		dev_err(dev, "unable to acquire memory-region resource\n");
+		return ret;
+	}
+
+	wcss->mem_phys = res.start;
+	wcss->mem_reloc = res.start;
+	wcss->mem_size = resource_size(&res);
+	wcss->mem_region = devm_ioremap_resource_wc(dev, &res);
+	if (IS_ERR(wcss->mem_region)) {
+		dev_err(dev, "unable to map memory region: %pR\n", &res);
+		return PTR_ERR(wcss->mem_region);
+	}
+
+	return 0;
+}
+
+static int wcss_sec_probe(struct platform_device *pdev)
+{
+	const struct wcss_data *desc = of_device_get_match_data(&pdev->dev);
+	const char *fw_name = NULL;
+	struct wcss_sec *wcss;
+	struct clk *sleep_clk;
+	struct clk *int_clk;
+	struct rproc *rproc;
+	int ret;
+
+	ret = of_property_read_string(pdev->dev.of_node, "firmware-name",
+				      &fw_name);
+	if (ret < 0)
+		return ret;
+
+	rproc = devm_rproc_alloc(&pdev->dev, desc->ss_name, &wcss_sec_ops,
+				 fw_name, sizeof(*wcss));
+	if (!rproc) {
+		dev_err(&pdev->dev, "failed to allocate rproc\n");
+		return -ENOMEM;
+	}
+
+	wcss = rproc->priv;
+	wcss->dev = &pdev->dev;
+	wcss->desc = desc;
+
+	ret = wcss_sec_alloc_memory_region(wcss);
+	if (ret)
+		return ret;
+
+	sleep_clk = devm_clk_get_optional_enabled(&pdev->dev, "sleep");
+	if (IS_ERR(sleep_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sleep_clk),
+				     "Failed to get sleep clock\n");
+
+	int_clk = devm_clk_get_optional_enabled(&pdev->dev, "interconnect");
+	if (IS_ERR(int_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(int_clk),
+				     "Failed to get interconnect clock\n");
+
+	ret = qcom_q6v5_init(&wcss->q6, pdev, rproc,
+			     WCSS_CRASH_REASON, NULL, NULL);
+	if (ret)
+		return ret;
+
+	qcom_add_glink_subdev(rproc, &wcss->glink_subdev, desc->ss_name);
+	qcom_add_ssr_subdev(rproc, &wcss->ssr_subdev, desc->ss_name);
+
+	rproc->auto_boot = desc->auto_boot;
+	rproc->dump_conf = RPROC_COREDUMP_INLINE;
+	rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
+
+	ret = devm_rproc_add(&pdev->dev, rproc);
+	if (ret) {
+		qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);
+		qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);
+		qcom_q6v5_deinit(&wcss->q6);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, rproc);
+
+	return 0;
+}
+
+static void wcss_sec_remove(struct platform_device *pdev)
+{
+	struct rproc *rproc = platform_get_drvdata(pdev);
+	struct wcss_sec *wcss = rproc->priv;
+
+	qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);
+	qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);
+	qcom_q6v5_deinit(&wcss->q6);
+}
+
+static const struct wcss_data wcss_sec_ipq5332_res_init = {
+	.pasid = MPD_WCSS_PAS_ID,
+	.ss_name = "q6wcss",
+};
+
+static const struct wcss_data wcss_sec_ipq9574_res_init = {
+	.pasid = WCSS_PAS_ID,
+	.ss_name = "q6wcss",
+};
+
+static const struct of_device_id wcss_sec_of_match[] = {
+	{ .compatible = "qcom,ipq5018-wcss-sec-pil", .data = &wcss_sec_ipq5332_res_init },
+	{ .compatible = "qcom,ipq5332-wcss-sec-pil", .data = &wcss_sec_ipq5332_res_init },
+	{ .compatible = "qcom,ipq9574-wcss-sec-pil", .data = &wcss_sec_ipq9574_res_init },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, wcss_sec_of_match);
+
+static struct platform_driver wcss_sec_driver = {
+	.probe = wcss_sec_probe,
+	.remove = wcss_sec_remove,
+	.driver = {
+		.name = "qcom-wcss-secure-pil",
+		.of_match_table = wcss_sec_of_match,
+	},
+};
+module_platform_driver(wcss_sec_driver);
+
+MODULE_DESCRIPTION("Hexagon WCSS Secure Peripheral Image Loader");
+MODULE_LICENSE("GPL");
include/linux/remoteproc.h +2 -0
index ef711a5b1a7f..cf06b9846309 100644
@@ -204,6 +204,7 @@ enum rproc_dump_mechanism {
  * @node:	list node related to the rproc segment list
  * @da:		device address of the segment
  * @size:	size of the segment
+ * @io_ptr:	ptr to store the ioremapped dump segment
  * @priv:	private data associated with the dump_segment
  * @dump:	custom dump function to fill device memory segment associated
  *		with coredump
@@ -215,6 +216,7 @@ struct rproc_dump_segment {
 	dma_addr_t da;
 	size_t size;
 
+	void __iomem *io_ptr;
 	void *priv;
 	void (*dump)(struct rproc *rproc, struct rproc_dump_segment *segment,
 		     void *dest, size_t offset, size_t size);
Signature · 2 lines
-- 
2.34.1
Signature · 1 line
-Mukesh Ojha
#12 lore raw

Re: [PATCH v14 3/9] remoteproc: qcom: add hexagon based WCSS secure PIL driver

Quoted 11 lines · Mukesh Ojha
Quoted 10 lines · Varadarajan Narayanan

From: Vignesh Viswanathan <[email protected]>

Add support to bring up hexagon based WCSS using secure PIL. All IPQxxxx SoCs support secure Peripheral Image Loading (PIL).

Secure PIL image is signed firmware image which only trusted software such as TrustZone (TZ) can authenticate and load. Linux kernel will send a Peripheral Authentication Service (PAS) request to TZ to authenticate and load the PIL images.

Quoted 7 lines
Quoted 2 lines

In order to avoid overloading the existing WCSS driver or PAS driver, we came up with this new PAS based IPQ WCSS driver.

Can you tell why you need another driver if you are using the same PAS method and it is using more of everything what PAS already supports ?

Hi Mukesh,

We just use pas_auth_and_reset and pas_shutdown APIs and do not need the entire framework provided by the PAS driver for IPQ WCSS.

Also, feedback from Bjorn in [1] was to have separate driver instead of overloading existing WCSS driver.

[1] https://lore.kernel.org/all/[email protected]/

Quoted 11 lines
Quoted 8 lines

Author and tested looks weird..here..

Will drop Tested-by here.

Thanks,
Vignesh

Quoted 421 lines
Quoted 420 lines
---
 drivers/remoteproc/Kconfig              |  20 ++
 drivers/remoteproc/Makefile             |   1 +
 drivers/remoteproc/qcom_q6v5_wcss_sec.c | 337 ++++++++++++++++++++++++++++++++
 include/linux/remoteproc.h              |   2 +
 4 files changed, 360 insertions(+)
drivers/remoteproc/Kconfig +20 -0
index 5b56b2dcc725..3feea5bda129 100644
@@ -267,6 +267,26 @@ config QCOM_Q6V5_WCSS
 	  Hexagon V5 based WCSS remote processors on e.g. IPQ8074.  This is
 	  a non-TrustZone wireless subsystem.
 
+config QCOM_Q6V5_WCSS_SEC
+	tristate "Qualcomm Hexagon based WCSS Secure Peripheral Image Loader"
+	depends on OF && ARCH_QCOM
+	depends on QCOM_SMEM
+	depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n
+	depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n
+	depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n
+	select QCOM_MDT_LOADER
+	select QCOM_PIL_INFO
+	select QCOM_Q6V5_COMMON
+	select QCOM_RPROC_COMMON
+	select QCOM_SCM
+	help
+	  Say y here to support the Qualcomm Secure Peripheral Image Loader
+	  for the Hexagon based remote processors on e.g. IPQ5332.
+
+	  This is TrustZone wireless subsystem. The firmware is
+	  verified and booted with the help of the Peripheral Authentication
+	  System (PAS) in TrustZone.
+
 config QCOM_SYSMON
 	tristate "Qualcomm sysmon driver"
 	depends on RPMSG
drivers/remoteproc/Makefile +1 -0
index 689686de0d41..f74519ea6502 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_QCOM_Q6V5_ADSP)		+= qcom_q6v5_adsp.o
 obj-$(CONFIG_QCOM_Q6V5_MSS)		+= qcom_q6v5_mss.o
 obj-$(CONFIG_QCOM_Q6V5_PAS)		+= qcom_q6v5_pas.o
 obj-$(CONFIG_QCOM_Q6V5_WCSS)		+= qcom_q6v5_wcss.o
+obj-$(CONFIG_QCOM_Q6V5_WCSS_SEC)	+= qcom_q6v5_wcss_sec.o
 obj-$(CONFIG_QCOM_SYSMON)		+= qcom_sysmon.o
 obj-$(CONFIG_QCOM_WCNSS_PIL)		+= qcom_wcnss_pil.o
 qcom_wcnss_pil-y			+= qcom_wcnss.o
drivers/remoteproc/qcom_q6v5_wcss_sec.c new file +337 -0
new file mode 100644
index 000000000000..4837825d1717
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ */
+#include <linux/clk.h>
+#include <linux/firmware/qcom/qcom_pas.h>
+#include <linux/io.h>
+#include <linux/mailbox_client.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/soc/qcom/mdt_loader.h>
+
+#include "qcom_common.h"
+#include "qcom_q6v5.h"
+#include "qcom_pil_info.h"
+
+#define WCSS_CRASH_REASON		421
+
+#define WCSS_PAS_ID			0x6
+#define MPD_WCSS_PAS_ID			0xd
+
+#define Q6_WAIT_TIMEOUT			(5 * HZ)
+
+struct wcss_sec {
+	struct device *dev;
+	struct qcom_rproc_glink glink_subdev;
+	struct qcom_rproc_ssr ssr_subdev;
+	struct qcom_q6v5 q6;
+	phys_addr_t mem_phys;
+	phys_addr_t mem_reloc;
+	void *mem_region;
+	size_t mem_size;
+	const struct wcss_data *desc;
+};
+
+struct wcss_data {
+	u32 pasid;
+	const char *ss_name;
+	bool auto_boot;
+};
+
+static int wcss_sec_start(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_q6v5_prepare(&wcss->q6);
+	if (ret)
+		return ret;
+
+	ret = qcom_pas_auth_and_reset(wcss->desc->pasid);
+	if (ret) {
+		dev_err(dev, "wcss_reset failed\n");
+		goto unprepare;
+	}
+
+	ret = qcom_q6v5_wait_for_start(&wcss->q6, msecs_to_jiffies(Q6_WAIT_TIMEOUT));
+
+	if (ret == -ETIMEDOUT) {
+		dev_err(dev, "start timed out\n");
+		qcom_pas_shutdown(wcss->desc->pasid);
+		goto unprepare;
+	}
+
+	return 0;
+
+unprepare:
+	qcom_q6v5_unprepare(&wcss->q6);
+
+	return ret;
+}
+
+static int wcss_sec_stop(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_q6v5_request_stop(&wcss->q6, NULL);
+	if (ret == -ETIMEDOUT)
+		dev_err(dev, "timed out on wait\n");
+
+	ret = qcom_pas_shutdown(wcss->desc->pasid);
+	if (ret)
+		dev_err(dev, "Failed to shutdown %d\n", ret);
+
+	qcom_q6v5_unprepare(&wcss->q6);
+
+	return ret;
+}
+
+static void *wcss_sec_da_to_va(struct rproc *rproc, u64 da, size_t len,
+			       bool *is_iomem)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	int offset;
+
+	offset = da - wcss->mem_reloc;
+	if (offset < 0 || offset + len > wcss->mem_size)
+		return NULL;
+
+	if (is_iomem)
+		*is_iomem = true;
+
+	return wcss->mem_region + offset;
+}
+
+static int wcss_sec_load(struct rproc *rproc, const struct firmware *fw)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+	int ret;
+
+	ret = qcom_mdt_load(dev, fw, rproc->firmware, wcss->desc->pasid, wcss->mem_region,
+			    wcss->mem_phys, wcss->mem_size, &wcss->mem_reloc);
+	if (ret)
+		return ret;
+
+	qcom_pil_info_store("wcss", wcss->mem_phys, wcss->mem_size);
+
+	return 0;
+}
+
+static unsigned long wcss_sec_panic(struct rproc *rproc)
+{
+	struct wcss_sec *wcss = rproc->priv;
+
+	return qcom_q6v5_panic(&wcss->q6);
+}
+
+static void wcss_sec_copy_segment(struct rproc *rproc,
+				  struct rproc_dump_segment *segment,
+				  void *dest, size_t offset, size_t size)
+{
+	struct wcss_sec *wcss = rproc->priv;
+	struct device *dev = wcss->dev;
+
+	if (!segment->io_ptr)
+		segment->io_ptr = ioremap_wc(segment->da, segment->size);
+
+	if (!segment->io_ptr) {
+		dev_err(dev, "Failed to ioremap segment %pad size 0x%zx\n",
+			&segment->da, segment->size);
+		return;
+	}
+
+	if (offset + size <= segment->size) {
+		memcpy_fromio(dest, segment->io_ptr + offset, size);
+	} else {
+		iounmap(segment->io_ptr);
+		segment->io_ptr = NULL;
+	}
+}
+
+static int wcss_sec_dump_segments(struct rproc *rproc,
+				  const struct firmware *fw)
+{
+	struct device *dev = rproc->dev.parent;
+	struct reserved_mem *rmem = NULL;
+	struct device_node *node;
+	int num_segs, index;
+	int ret;
+
+	/*
+	 * Parse through additional reserved memory regions for the rproc
+	 * and add them to the coredump segments
+	 */
+	num_segs = of_count_phandle_with_args(dev->of_node,
+					      "memory-region", NULL);
+	for (index = 0; index < num_segs; index++) {
+		node = of_parse_phandle(dev->of_node,
+					"memory-region", index);
+		if (!node)
+			return -EINVAL;
+
+		rmem = of_reserved_mem_lookup(node);
+		of_node_put(node);
+		if (!rmem) {
+			dev_err(dev, "unable to acquire memory-region index %d num_segs %d\n",
+				index, num_segs);
+			return -EINVAL;
+		}
+
+		dev_dbg(dev, "Adding segment 0x%pa size 0x%pa",
+			&rmem->base, &rmem->size);
+		ret = rproc_coredump_add_custom_segment(rproc,
+							rmem->base,
+							rmem->size,
+							wcss_sec_copy_segment,
+							NULL);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const struct rproc_ops wcss_sec_ops = {
+	.start = wcss_sec_start,
+	.stop = wcss_sec_stop,
+	.da_to_va = wcss_sec_da_to_va,
+	.load = wcss_sec_load,
+	.get_boot_addr = rproc_elf_get_boot_addr,
+	.panic = wcss_sec_panic,
+	.parse_fw = wcss_sec_dump_segments,
+};
+
+static int wcss_sec_alloc_memory_region(struct wcss_sec *wcss)
+{
+	struct device *dev = wcss->dev;
+	struct resource res;
+	int ret;
+
+	ret = of_reserved_mem_region_to_resource(dev->of_node, 0, &res);
+	if (ret) {
+		dev_err(dev, "unable to acquire memory-region resource\n");
+		return ret;
+	}
+
+	wcss->mem_phys = res.start;
+	wcss->mem_reloc = res.start;
+	wcss->mem_size = resource_size(&res);
+	wcss->mem_region = devm_ioremap_resource_wc(dev, &res);
+	if (IS_ERR(wcss->mem_region)) {
+		dev_err(dev, "unable to map memory region: %pR\n", &res);
+		return PTR_ERR(wcss->mem_region);
+	}
+
+	return 0;
+}
+
+static int wcss_sec_probe(struct platform_device *pdev)
+{
+	const struct wcss_data *desc = of_device_get_match_data(&pdev->dev);
+	const char *fw_name = NULL;
+	struct wcss_sec *wcss;
+	struct clk *sleep_clk;
+	struct clk *int_clk;
+	struct rproc *rproc;
+	int ret;
+
+	ret = of_property_read_string(pdev->dev.of_node, "firmware-name",
+				      &fw_name);
+	if (ret < 0)
+		return ret;
+
+	rproc = devm_rproc_alloc(&pdev->dev, desc->ss_name, &wcss_sec_ops,
+				 fw_name, sizeof(*wcss));
+	if (!rproc) {
+		dev_err(&pdev->dev, "failed to allocate rproc\n");
+		return -ENOMEM;
+	}
+
+	wcss = rproc->priv;
+	wcss->dev = &pdev->dev;
+	wcss->desc = desc;
+
+	ret = wcss_sec_alloc_memory_region(wcss);
+	if (ret)
+		return ret;
+
+	sleep_clk = devm_clk_get_optional_enabled(&pdev->dev, "sleep");
+	if (IS_ERR(sleep_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(sleep_clk),
+				     "Failed to get sleep clock\n");
+
+	int_clk = devm_clk_get_optional_enabled(&pdev->dev, "interconnect");
+	if (IS_ERR(int_clk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(int_clk),
+				     "Failed to get interconnect clock\n");
+
+	ret = qcom_q6v5_init(&wcss->q6, pdev, rproc,
+			     WCSS_CRASH_REASON, NULL, NULL);
+	if (ret)
+		return ret;
+
+	qcom_add_glink_subdev(rproc, &wcss->glink_subdev, desc->ss_name);
+	qcom_add_ssr_subdev(rproc, &wcss->ssr_subdev, desc->ss_name);
+
+	rproc->auto_boot = desc->auto_boot;
+	rproc->dump_conf = RPROC_COREDUMP_INLINE;
+	rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
+
+	ret = devm_rproc_add(&pdev->dev, rproc);
+	if (ret) {
+		qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);
+		qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);
+		qcom_q6v5_deinit(&wcss->q6);
+		return ret;
+	}
+
+	platform_set_drvdata(pdev, rproc);
+
+	return 0;
+}
+
+static void wcss_sec_remove(struct platform_device *pdev)
+{
+	struct rproc *rproc = platform_get_drvdata(pdev);
+	struct wcss_sec *wcss = rproc->priv;
+
+	qcom_remove_ssr_subdev(rproc, &wcss->ssr_subdev);
+	qcom_remove_glink_subdev(rproc, &wcss->glink_subdev);
+	qcom_q6v5_deinit(&wcss->q6);
+}
+
+static const struct wcss_data wcss_sec_ipq5332_res_init = {
+	.pasid = MPD_WCSS_PAS_ID,
+	.ss_name = "q6wcss",
+};
+
+static const struct wcss_data wcss_sec_ipq9574_res_init = {
+	.pasid = WCSS_PAS_ID,
+	.ss_name = "q6wcss",
+};
+
+static const struct of_device_id wcss_sec_of_match[] = {
+	{ .compatible = "qcom,ipq5018-wcss-sec-pil", .data = &wcss_sec_ipq5332_res_init },
+	{ .compatible = "qcom,ipq5332-wcss-sec-pil", .data = &wcss_sec_ipq5332_res_init },
+	{ .compatible = "qcom,ipq9574-wcss-sec-pil", .data = &wcss_sec_ipq9574_res_init },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, wcss_sec_of_match);
+
+static struct platform_driver wcss_sec_driver = {
+	.probe = wcss_sec_probe,
+	.remove = wcss_sec_remove,
+	.driver = {
+		.name = "qcom-wcss-secure-pil",
+		.of_match_table = wcss_sec_of_match,
+	},
+};
+module_platform_driver(wcss_sec_driver);
+
+MODULE_DESCRIPTION("Hexagon WCSS Secure Peripheral Image Loader");
+MODULE_LICENSE("GPL");
include/linux/remoteproc.h +2 -0
index ef711a5b1a7f..cf06b9846309 100644
@@ -204,6 +204,7 @@ enum rproc_dump_mechanism {
  * @node:	list node related to the rproc segment list
  * @da:		device address of the segment
  * @size:	size of the segment
+ * @io_ptr:	ptr to store the ioremapped dump segment
  * @priv:	private data associated with the dump_segment
  * @dump:	custom dump function to fill device memory segment associated
  *		with coredump
@@ -215,6 +216,7 @@ struct rproc_dump_segment {
 	dma_addr_t da;
 	size_t size;
 
+	void __iomem *io_ptr;
 	void *priv;
 	void (*dump)(struct rproc *rproc, struct rproc_dump_segment *segment,
 		     void *dest, size_t offset, size_t size);
Signature · 2 lines
-- 
2.34.1
#13 lore raw

Re: [PATCH v14 3/9] remoteproc: qcom: add hexagon based WCSS secure PIL driver

Quoted 22 lines · Vignesh Viswanathan
Quoted 11 lines · Mukesh Ojha
Quoted 10 lines · Varadarajan Narayanan

From: Vignesh Viswanathan <[email protected]>

Add support to bring up hexagon based WCSS using secure PIL. All IPQxxxx SoCs support secure Peripheral Image Loading (PIL).

Secure PIL image is signed firmware image which only trusted software such as TrustZone (TZ) can authenticate and load. Linux kernel will send a Peripheral Authentication Service (PAS) request to TZ to authenticate and load the PIL images.

Quoted 7 lines
Quoted 2 lines

In order to avoid overloading the existing WCSS driver or PAS driver, we came up with this new PAS based IPQ WCSS driver.

Can you tell why you need another driver if you are using the same PAS method and it is using more of everything what PAS already supports ?

Quoted 4 lines

Hi Mukesh,

We just use pas_auth_and_reset and pas_shutdown APIs and do not need the entire framework provided by the PAS driver for IPQ WCSS.

But you are using qcom_mdt_load() in wcss_sec_load(), which internally will call pas_init and memset SMCs.

Quoted 3 lines

Also, feedback from Bjorn in [1] was to have separate driver instead of overloading existing WCSS driver.

That's a very old thread, 5 years is a long time. We can still revisit why you need a separate driver. If you already have all the stuff required to be a PAS driver, why not use that?

Quoted 3 lines

[1] https://lore.kernel.org/all/[email protected]/

-Mukesh

#14 lore raw

PATCH v14 4/9 arm64: dts: qcom: ipq5018: add nodes to bring up q6

In reply to Varadarajan Narayanan

From: George Moussalem <[email protected]>

Enable nodes required for q6 remoteproc bring up.

[ Change 'qcom,smem-state-names' order to resolve dt-bindings-check error ]
---
 arch/arm64/boot/dts/qcom/ipq5018.dtsi | 66 +++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
arch/arm64/boot/dts/qcom/ipq5018.dtsi +66 -0
index 4fc627b47fe7..82af532bff38 100644
@@ -158,6 +158,35 @@ tz_region: tz@4ac00000 {
 			reg = <0x0 0x4ac00000 0x0 0x200000>;
 			no-map;
 		};
+
+		q6_region: wcss@4b000000 {
+			reg = <0x0 0x4b000000 0x0 0x1b00000>;
+			no-map;
+		};
+	};
+
+	wcss: smp2p-wcss {
+		compatible = "qcom,smp2p";
+		qcom,smem = <435>, <428>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <GIC_SPI 177 IRQ_TYPE_EDGE_RISING>;
+
+		mboxes = <&apcs_glb 9>;
+
+		qcom,local-pid = <0>;
+		qcom,remote-pid = <1>;
+
+		wcss_smp2p_out: master-kernel {
+			qcom,entry-name = "master-kernel";
+			#qcom,smem-state-cells = <1>;
+		};
+
+		wcss_smp2p_in: slave-kernel {
+			qcom,entry-name = "slave-kernel";
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
 	};
 
 	soc: soc@0 {
@@ -734,6 +763,43 @@ frame@b128000 {
 			};
 		};
 
+		q6v5_wcss: remoteproc@cd00000 {
+			compatible = "qcom,ipq5018-wcss-sec-pil";
+			reg = <0x0cd00000 0x10000>;
+			firmware-name = "ath11k/IPQ5018/hw1.0/q6_fw.mbn";
+			interrupts-extended = <&intc GIC_SPI 291 IRQ_TYPE_EDGE_RISING>,
+					      <&wcss_smp2p_in 0 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 1 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 2 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 3 IRQ_TYPE_NONE>;
+			interrupt-names = "wdog",
+					  "fatal",
+					  "ready",
+					  "handover",
+					  "stop-ack";
+
+			clocks = <&gcc GCC_SLEEP_CLK_SRC>,
+				 <&gcc GCC_SYS_NOC_WCSS_AHB_CLK>;
+			clock-names = "sleep",
+				      "interconnect";
+
+			qcom,smem-states = <&wcss_smp2p_out 1>,
+					   <&wcss_smp2p_out 0>;
+			qcom,smem-state-names = "stop",
+						"shutdown";
+
+			memory-region = <&q6_region>;
+
+			status = "disabled";
+
+			glink-edge {
+				interrupts = <GIC_SPI 179 IRQ_TYPE_EDGE_RISING>;
+				label = "rtr";
+				qcom,remote-pid = <1>;
+				mboxes = <&apcs_glb 8>;
+			};
+		};
+
 		pcie1: pcie@80000000 {
 			compatible = "qcom,pcie-ipq5018";
 			reg = <0x80000000 0xf1d>,
Signature · 1 line
2.34.1
#15 lore raw

PATCH v14 5/9 arm64: dts: qcom: ipq5332: add nodes to bring up q6

In reply to Varadarajan Narayanan

From: Manikanta Mylavarapu <[email protected]>

Enable nodes required for q6 remoteproc bring up.

---
 arch/arm64/boot/dts/qcom/ipq5332.dtsi | 64 +++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332.dtsi +64 -0
index 74d9de8d7641..ff4187fb7fba 100644
@@ -159,6 +159,35 @@ smem@4a800000 {
 
 			hwlocks = <&tcsr_mutex 3>;
 		};
+
+		q6_region: wcss@4a900000 {
+			reg = <0x0 0x4a900000 0x0 0x2b00000>;
+			no-map;
+		};
+	};
+
+	wcss: smp2p-wcss {
+		compatible = "qcom,smp2p";
+		qcom,smem = <435>, <428>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <GIC_SPI 418 IRQ_TYPE_EDGE_RISING>;
+
+		mboxes = <&apcs_glb 9>;
+
+		qcom,local-pid = <0>;
+		qcom,remote-pid = <1>;
+
+		wcss_smp2p_out: master-kernel {
+			qcom,entry-name = "master-kernel";
+			#qcom,smem-state-cells = <1>;
+		};
+
+		wcss_smp2p_in: slave-kernel {
+			qcom,entry-name = "slave-kernel";
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
 	};
 
 	soc@0 {
@@ -656,6 +685,41 @@ frame@b128000 {
 			};
 		};
 
+		q6v5_wcss: remoteproc@d100000 {
+			compatible = "qcom,ipq5332-wcss-sec-pil";
+			reg = <0x0d100000 0x10000>;
+			firmware-name = "ath12k/IPQ5332/hw1.0/q6_fw0.mbn";
+			interrupts-extended = <&intc GIC_SPI 421 IRQ_TYPE_EDGE_RISING>,
+					      <&wcss_smp2p_in 0 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 1 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 2 IRQ_TYPE_NONE>,
+					      <&wcss_smp2p_in 3 IRQ_TYPE_NONE>;
+			interrupt-names = "wdog",
+					  "fatal",
+					  "ready",
+					  "handover",
+					  "stop-ack";
+
+			clocks = <&gcc GCC_IM_SLEEP_CLK>;
+			clock-names = "sleep";
+
+			qcom,smem-states = <&wcss_smp2p_out 1>,
+					   <&wcss_smp2p_out 0>;
+			qcom,smem-state-names = "stop",
+						"shutdown";
+
+			memory-region = <&q6_region>;
+
+			status = "disabled";
+
+			glink-edge {
+				interrupts = <GIC_SPI 417 IRQ_TYPE_EDGE_RISING>;
+				label = "rtr";
+				qcom,remote-pid = <1>;
+				mboxes = <&apcs_glb 8>;
+			};
+		};
+
 		pcie1: pcie@18000000 {
 			compatible = "qcom,pcie-ipq5332", "qcom,pcie-ipq9574";
 			reg = <0x18000000 0xf1c>,
Signature · 1 line
2.34.1
#16 lore raw

PATCH v14 6/9 arm64: dts: qcom: ipq9574: add nodes to bring up q6

In reply to Varadarajan Narayanan

From: Manikanta Mylavarapu <[email protected]>

Enable nodes required for q6 remoteproc bring up.

---
 arch/arm64/boot/dts/qcom/ipq9574.dtsi | 62 ++++++++++++++++++++++++++++++++++-
 1 file changed, 61 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/ipq9574.dtsi +61 -1
index 5a5bda5f21a1..194bba02f2ea 100644
@@ -3,7 +3,7 @@
  * IPQ9574 SoC device tree source
  *
  * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
- * Copyright (c) 2023-2024, Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2023-2025, Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <dt-bindings/clock/qcom,apss-ipq.h>
@@ -222,6 +222,35 @@ smem@4aa00000 {
 			hwlocks = <&tcsr_mutex 3>;
 			no-map;
 		};
+
+		q6_region: wcss@4ab00000 {
+			reg = <0x0 0x4ab00000 0x0 0x2b00000>;
+			no-map;
+		};
+	};
+
+	wcss: smp2p-wcss {
+		compatible = "qcom,smp2p";
+		qcom,smem = <435>, <428>;
+
+		interrupt-parent = <&intc>;
+		interrupts = <GIC_SPI 322 IRQ_TYPE_EDGE_RISING>;
+
+		mboxes = <&apcs_glb 9>;
+
+		qcom,local-pid = <0>;
+		qcom,remote-pid = <1>;
+
+		smp2p_wcss_out: master-kernel {
+			qcom,entry-name = "master-kernel";
+			#qcom,smem-state-cells = <1>;
+		};
+
+		smp2p_wcss_in: slave-kernel {
+			qcom,entry-name = "slave-kernel";
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
 	};
 
 	soc: soc@0 {
@@ -924,6 +953,37 @@ frame@b128000 {
 			};
 		};
 
+		q6v5_wcss: remoteproc@cd00000 {
+			compatible = "qcom,ipq9574-wcss-sec-pil";
+			reg = <0x0cd00000 0x10000>;
+			firmware-name = "ath11k/IPQ9574/hw1.0/q6_fw.mbn";
+			interrupts-extended = <&intc GIC_SPI 325 IRQ_TYPE_EDGE_RISING>,
+					      <&smp2p_wcss_in 0 IRQ_TYPE_NONE>,
+					      <&smp2p_wcss_in 1 IRQ_TYPE_NONE>,
+					      <&smp2p_wcss_in 2 IRQ_TYPE_NONE>,
+					      <&smp2p_wcss_in 3 IRQ_TYPE_NONE>;
+			interrupt-names = "wdog",
+					  "fatal",
+					  "ready",
+					  "handover",
+					  "stop-ack";
+
+			qcom,smem-states = <&smp2p_wcss_out 1>,
+					   <&smp2p_wcss_out 0>;
+			qcom,smem-state-names = "stop",
+						"shutdown";
+			memory-region = <&q6_region>;
+
+			status = "disabled";
+
+			glink-edge {
+				interrupts = <GIC_SPI 321 IRQ_TYPE_EDGE_RISING>;
+				label = "rtr";
+				qcom,remote-pid = <1>;
+				mboxes = <&apcs_glb 8>;
+			};
+		};
+
 		pcie1: pcie@10000000 {
 			compatible = "qcom,pcie-ipq9574";
 			reg = <0x10000000 0xf1d>,
Signature · 1 line
2.34.1
#17 lore raw

PATCH v14 7/9 arm64: dts: qcom: ipq5018: Enable q6v5_wcss

In reply to Varadarajan Narayanan

Turn on the q6v5_wcss node.

---
 arch/arm64/boot/dts/qcom/ipq5018-rdp432-c2.dts | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/ipq5018-rdp432-c2.dts +4 -0
index 33eef92b19b1..ce3970358056 100644
@@ -46,6 +46,10 @@ &pcie0_port0 {
 	wake-gpios = <&tlmm 16 GPIO_ACTIVE_LOW>;
 };
 
+&q6v5_wcss {
+	status = "okay";
+};
+
 &sdhc_1 {
 	pinctrl-0 = <&sdc_default_state>;
 	pinctrl-names = "default";
Signature · 1 line
2.34.1
#18 lore raw

PATCH v14 8/9 arm64: dts: qcom: ipq5332: Enable q6v5_wcss

In reply to Varadarajan Narayanan

Turn on the q6v5_wcss node.

---
 arch/arm64/boot/dts/qcom/ipq5332-rdp-common.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/ipq5332-rdp-common.dtsi +4 -0
index 3bbf748f2e5c..9e82afb354d4 100644
@@ -55,6 +55,10 @@ &blsp1_uart0 {
 	status = "okay";
 };
 
+&q6v5_wcss {
+	status = "okay";
+};
+
 /*
  * The bootstrap pins for the board select the XO clock frequency that
  * supports 48 MHZ or 96 MHZ. This setting automatically enables the
Signature · 1 line
2.34.1
#19 lore raw

PATCH v14 9/9 arm64: dts: qcom: ipq9574: Enable q6v5_wcss

In reply to Varadarajan Narayanan

Turn on the q6v5_wcss node.

---
 arch/arm64/boot/dts/qcom/ipq9574-rdp-common.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm64/boot/dts/qcom/ipq9574-rdp-common.dtsi +4 -0
index 62877b46f9b3..494a150535cf 100644
@@ -113,6 +113,10 @@ &cpu3 {
 	cpu-supply = <&mp5496_s1>;
 };
 
+&q6v5_wcss {
+	status = "okay";
+};
+
 &rpm_requests {
 	regulators {
 		compatible = "qcom,rpm-mp5496-regulators";
Signature · 1 line
2.34.1