Skip to contentSkip to conversation

crypto/fsl: allow accessing Job Ring from non-TrustZone

PATCH Superseded Emanuele Ghidoli 2 participants 5 messages Mar 25, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover crypto/fsl: allow accessing Job Ring from non-TrustZone

From: Emanuele Ghidoli <[email protected]>

This series allows using Freescale CAAM Job Ring from Linux without having OP-TEE, this is needed for example on Toradex Colibri iMX7 where we just have U-Boot + Linux kernel.

To achieve this add a new config option to allow the non-secure world to access job rings.

The functionality has been broken since U-Boot v2019.07, with commit 51f1357f3428 ("Revert "drivers/crypto/fsl: assign job-rings to non-TrustZone"")

Regards,
Emanuele Ghidoli

Emanuele Ghidoli (3):
crypto/fsl: allow accessing Job Ring from non-TrustZone
configs: colibri-imx7: set non-secure boot mode as default
configs: colibri-imx7: allow accessing job-rings from non-TrustZone

 configs/colibri_imx7_defconfig      |  1 +
 configs/colibri_imx7_emmc_defconfig |  2 +-
 drivers/crypto/fsl/Kconfig          |  7 +++++++
 drivers/crypto/fsl/jr.c             | 19 +++++++++++++++++++
 drivers/crypto/fsl/jr.h             |  2 ++
 5 files changed, 30 insertions(+), 1 deletion(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 crypto/fsl: allow accessing Job Ring from non-TrustZone

From: Emanuele Ghidoli <[email protected]>

Add a new kconfig option to allow non-secure world access to the CAAM Job Ring.
This is needed, for example, when running linux without OP-TEE services, as it's done on Colibri iMX7.

Fixes 51f1357f3428 ("Revert "drivers/crypto/fsl: assign job-rings to non-TrustZone"")
---
 drivers/crypto/fsl/Kconfig |  7 +++++++
 drivers/crypto/fsl/jr.c    | 19 +++++++++++++++++++
 drivers/crypto/fsl/jr.h    |  2 ++
 3 files changed, 28 insertions(+)
drivers/crypto/fsl/Kconfig +7 -0
index eaad19633f1d..e95675ee3e8e 100644
@@ -62,6 +62,13 @@ config SYS_FSL_SEC_LE
 
 if FSL_CAAM
 
+config FSL_CAAM_JR_NTZ_ACCESS
+	bool "Give caam Job Ring access to non-secure world"
+	default n
+	help
+	  It is needed when OP-TEE is not used and Freescale CAAM Job Ring linux
+	  driver is used.
+
 config FSL_CAAM_RNG
 	bool "Enable Random Number Generator support"
 	depends on DM_RNG
drivers/crypto/fsl/jr.c +19 -0
index ceb66dd6270d..203f16252159 100644
@@ -673,6 +673,21 @@ static int rng_init(uint8_t sec_idx, ccsr_sec_t *sec)
 	return ret;
 }
 
+#if CONFIG_IS_ENABLED(FSL_CAAM_JR_NTZ_ACCESS)
+static void jr_setown_non_trusted(ccsr_sec_t *sec)
+{
+	u32 jrown_ns;
+	int i;
+
+	/* Set ownership of job rings to non-TrustZone mode */
+	for (i = 0; i < ARRAY_SIZE(sec->jrliodnr); i++) {
+		jrown_ns = sec_in32(&sec->jrliodnr[i].ms);
+		jrown_ns |= JROWN_NS | JRMID_NS;
+		sec_out32(&sec->jrliodnr[i].ms, jrown_ns);
+	}
+}
+#endif
+
 int sec_init_idx(uint8_t sec_idx)
 {
 	int ret = 0;
@@ -761,6 +776,10 @@ int sec_init_idx(uint8_t sec_idx)
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 init:
 #endif
+#if CONFIG_IS_ENABLED(FSL_CAAM_JR_NTZ_ACCESS)
+	jr_setown_non_trusted(sec);
+#endif
+
 	ret = jr_init(sec_idx, caam);
 	if (ret < 0) {
 		printf("SEC%u:  initialization failed\n", sec_idx);
drivers/crypto/fsl/jr.h +2 -0
index 4e4c4af5805f..b136cd8d05a9 100644
@@ -37,6 +37,8 @@
 #define JRNSLIODN_MASK		0x0fff0000
 #define JRSLIODN_SHIFT		0
 #define JRSLIODN_MASK		0x00000fff
+#define JROWN_NS		0x00000008
+#define JRMID_NS		0x00000001
 
 #define JRDID_MS_PRIM_DID	BIT(0)
 #define JRDID_MS_PRIM_TZ	BIT(4)
Signature · 1 line
2.34.1
reviewer
#2 lore raw

Hi Emanuele,

drivers/crypto/fsl/Kconfig config SYS_FSL_SEC_LE · line 66

Quoted 2 lines · Emanuele Ghidoli
drivers/crypto/fsl/Kconfig +2 -0
+config FSL_CAAM_JR_NTZ_ACCESS
+       bool "Give caam Job Ring access to non-secure world"

Please spell CAAM instead.

Quoted 1 line

+ default n

'default n' is already the default, please drop this line.

#3 lore raw

PATCH 2/3 configs: colibri-imx7: set non-secure boot mode as default

In reply to Emanuele Ghidoli

From: Emanuele Ghidoli <[email protected]>

Linux kernel is supposed to run in non-secure world, fix the defconfig accordingly.

---
 configs/colibri_imx7_emmc_defconfig | 1 -
 1 file changed, 1 deletion(-)
configs/colibri_imx7_emmc_defconfig +0 -1
index 9d4423cd0d6a..8dd9fe6e6a38 100644
@@ -8,7 +8,6 @@ CONFIG_DEFAULT_DEVICE_TREE="imx7d-colibri-emmc-eval-v3"
 CONFIG_TARGET_COLIBRI_IMX7=y
 CONFIG_TARGET_COLIBRI_IMX7_EMMC=y
 CONFIG_OF_LIBFDT_OVERLAY=y
-CONFIG_ARMV7_BOOT_SEC_DEFAULT=y
 CONFIG_IMX_RDC=y
 CONFIG_IMX_BOOTAUX=y
 CONFIG_IMX_HAB=y
Signature · 1 line
2.34.1
#4 lore raw

PATCH 3/3 configs: colibri-imx7: allow accessing job-rings from non-TrustZone

In reply to Emanuele Ghidoli

From: Emanuele Ghidoli <[email protected]>

Set FSL_CAAM_JR_NTZ_ACCESS configuration since colibri-imx7 uses Freescale CAAM Job Ring linux driver

---
 configs/colibri_imx7_defconfig      | 1 +
 configs/colibri_imx7_emmc_defconfig | 1 +
 2 files changed, 2 insertions(+)
configs/colibri_imx7_defconfig +1 -0
index 0c6a272ddfc6..16f923b07c22 100644
@@ -72,6 +72,7 @@ CONFIG_SERVERIP="192.168.10.1"
 CONFIG_BOUNCE_BUFFER=y
 CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_BOOTCOUNT_ENV=y
+CONFIG_FSL_CAAM_JR_NTZ_ACCESS=y
 CONFIG_DFU_NAND=y
 CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x81100000
configs/colibri_imx7_emmc_defconfig +1 -0
index 8dd9fe6e6a38..7c6a725ea9a2 100644
@@ -61,6 +61,7 @@ CONFIG_USE_SERVERIP=y
 CONFIG_SERVERIP="192.168.10.1"
 CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_BOOTCOUNT_ENV=y
+CONFIG_FSL_CAAM_JR_NTZ_ACCESS=y
 CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x81100000
 CONFIG_FASTBOOT_FLASH=y
Signature · 1 line
2.34.1