All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andrew F. Davis" <afd@ti.com>
To: Tony Lindgren <tony@atomide.com>
Cc: <linux-omap@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Andrew F . Davis" <afd@ti.com>
Subject: [PATCH] ARM: OMAP: Use ARM SMC Calling Convention when OP-TEE is available
Date: Mon, 18 Nov 2019 11:52:36 -0500	[thread overview]
Message-ID: <20191118165236.22136-1-afd@ti.com> (raw)

On High-Security(HS) OMAP2+ class devices a couple actions must be performed
from the ARM TrustZone during boot. These traditionally can be performed by
calling into the secure ROM code resident in this secure world using legacy
SMC calls. Optionally OP-TEE can replace this secure world functionality by
replacing the ROM after boot. ARM recommends a standard calling convention
is used for this interaction (SMC Calling Convention). We check DT for the
presence of OP-TEE and use this type of call to perform the needed actions,
falling back to the legacy OMAP ROM call if OP-TEE is not available.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 arch/arm/mach-omap2/common.h      |  2 +-
 arch/arm/mach-omap2/omap-secure.c | 27 ++++++++++++++++++++++++++-
 arch/arm/mach-omap2/omap-secure.h |  1 +
 arch/arm/mach-omap2/omap-smc.S    |  6 +++---
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h
index 6316da3623b3..ffcc580aef01 100644
--- a/arch/arm/mach-omap2/common.h
+++ b/arch/arm/mach-omap2/common.h
@@ -255,7 +255,7 @@ extern void gic_dist_disable(void);
 extern void gic_dist_enable(void);
 extern bool gic_dist_disabled(void);
 extern void gic_timer_retrigger(void);
-extern void omap_smc1(u32 fn, u32 arg);
+extern void _omap_smc1(u32 fn, u32 arg);
 extern void omap4_sar_ram_init(void);
 extern void __iomem *omap4_get_sar_ram_base(void);
 extern void omap4_mpuss_early_init(void);
diff --git a/arch/arm/mach-omap2/omap-secure.c b/arch/arm/mach-omap2/omap-secure.c
index 24298e47b9f1..a2df3cb74bc3 100644
--- a/arch/arm/mach-omap2/omap-secure.c
+++ b/arch/arm/mach-omap2/omap-secure.c
@@ -12,10 +12,12 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/memblock.h>
-
+#include <linux/of.h>
+#include <linux/arm-smccc.h>
 #include <asm/cacheflush.h>
 #include <asm/memblock.h>
 
+#include "common.h"
 #include "omap-secure.h"
 
 static phys_addr_t omap_secure_memblock_base;
@@ -53,6 +55,29 @@ u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2,
 	return ret;
 }
 
+#define OMAP_SIP_SMC_STD_CALL_VAL(func_num) \
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
+	ARM_SMCCC_OWNER_SIP, (func_num))
+
+void omap_smc1(u32 fn, u32 arg)
+{
+	struct device_node *optee;
+	struct arm_smccc_res res;
+
+	/*
+	 * If this platform has OP-TEE installed we use ARM SMC calls
+	 * otherwise fall back to the OMAP ROM style calls.
+	 */
+	optee = of_find_node_by_path("/firmware/optee");
+	if (optee) {
+		arm_smccc_smc(OMAP_SIP_SMC_STD_CALL_VAL(fn), arg,
+			      0, 0, 0, 0, 0, 0, &res);
+		WARN(res.a0, "Secure function call 0x%08x failed\n", fn);
+	} else {
+		_omap_smc1(fn, arg);
+	}
+}
+
 /* Allocate the memory to save secure ram */
 int __init omap_secure_ram_reserve_memblock(void)
 {
diff --git a/arch/arm/mach-omap2/omap-secure.h b/arch/arm/mach-omap2/omap-secure.h
index 20046e8f8ecb..601d64b2c744 100644
--- a/arch/arm/mach-omap2/omap-secure.h
+++ b/arch/arm/mach-omap2/omap-secure.h
@@ -60,6 +60,7 @@
 
 extern u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs,
 				u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+extern void omap_smc1(u32 fn, u32 arg);
 extern u32 omap_smc2(u32 id, u32 falg, u32 pargs);
 extern u32 omap_smc3(u32 id, u32 process, u32 flag, u32 pargs);
 extern phys_addr_t omap_secure_ram_mempool_base(void);
diff --git a/arch/arm/mach-omap2/omap-smc.S b/arch/arm/mach-omap2/omap-smc.S
index fd2bcd91f4a1..d4832845a4e8 100644
--- a/arch/arm/mach-omap2/omap-smc.S
+++ b/arch/arm/mach-omap2/omap-smc.S
@@ -18,18 +18,18 @@
  * the monitor API number. It uses few CPU registers
  * internally and hence they need be backed up including
  * link register "lr".
- * Function signature : void omap_smc1(u32 fn, u32 arg)
+ * Function signature : void _omap_smc1(u32 fn, u32 arg)
  */
 	.arch armv7-a
 	.arch_extension sec
-ENTRY(omap_smc1)
+ENTRY(_omap_smc1)
 	stmfd   sp!, {r2-r12, lr}
 	mov	r12, r0
 	mov 	r0, r1
 	dsb
 	smc	#0
 	ldmfd   sp!, {r2-r12, pc}
-ENDPROC(omap_smc1)
+ENDPROC(_omap_smc1)
 
 /**
  * u32 omap_smc2(u32 id, u32 falg, u32 pargs)
-- 
2.17.1


WARNING: multiple messages have this Message-ID (diff)
From: "Andrew F. Davis" <afd@ti.com>
To: Tony Lindgren <tony@atomide.com>
Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Andrew F . Davis" <afd@ti.com>
Subject: [PATCH] ARM: OMAP: Use ARM SMC Calling Convention when OP-TEE is available
Date: Mon, 18 Nov 2019 11:52:36 -0500	[thread overview]
Message-ID: <20191118165236.22136-1-afd@ti.com> (raw)

On High-Security(HS) OMAP2+ class devices a couple actions must be performed
from the ARM TrustZone during boot. These traditionally can be performed by
calling into the secure ROM code resident in this secure world using legacy
SMC calls. Optionally OP-TEE can replace this secure world functionality by
replacing the ROM after boot. ARM recommends a standard calling convention
is used for this interaction (SMC Calling Convention). We check DT for the
presence of OP-TEE and use this type of call to perform the needed actions,
falling back to the legacy OMAP ROM call if OP-TEE is not available.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 arch/arm/mach-omap2/common.h      |  2 +-
 arch/arm/mach-omap2/omap-secure.c | 27 ++++++++++++++++++++++++++-
 arch/arm/mach-omap2/omap-secure.h |  1 +
 arch/arm/mach-omap2/omap-smc.S    |  6 +++---
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h
index 6316da3623b3..ffcc580aef01 100644
--- a/arch/arm/mach-omap2/common.h
+++ b/arch/arm/mach-omap2/common.h
@@ -255,7 +255,7 @@ extern void gic_dist_disable(void);
 extern void gic_dist_enable(void);
 extern bool gic_dist_disabled(void);
 extern void gic_timer_retrigger(void);
-extern void omap_smc1(u32 fn, u32 arg);
+extern void _omap_smc1(u32 fn, u32 arg);
 extern void omap4_sar_ram_init(void);
 extern void __iomem *omap4_get_sar_ram_base(void);
 extern void omap4_mpuss_early_init(void);
diff --git a/arch/arm/mach-omap2/omap-secure.c b/arch/arm/mach-omap2/omap-secure.c
index 24298e47b9f1..a2df3cb74bc3 100644
--- a/arch/arm/mach-omap2/omap-secure.c
+++ b/arch/arm/mach-omap2/omap-secure.c
@@ -12,10 +12,12 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/memblock.h>
-
+#include <linux/of.h>
+#include <linux/arm-smccc.h>
 #include <asm/cacheflush.h>
 #include <asm/memblock.h>
 
+#include "common.h"
 #include "omap-secure.h"
 
 static phys_addr_t omap_secure_memblock_base;
@@ -53,6 +55,29 @@ u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2,
 	return ret;
 }
 
+#define OMAP_SIP_SMC_STD_CALL_VAL(func_num) \
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
+	ARM_SMCCC_OWNER_SIP, (func_num))
+
+void omap_smc1(u32 fn, u32 arg)
+{
+	struct device_node *optee;
+	struct arm_smccc_res res;
+
+	/*
+	 * If this platform has OP-TEE installed we use ARM SMC calls
+	 * otherwise fall back to the OMAP ROM style calls.
+	 */
+	optee = of_find_node_by_path("/firmware/optee");
+	if (optee) {
+		arm_smccc_smc(OMAP_SIP_SMC_STD_CALL_VAL(fn), arg,
+			      0, 0, 0, 0, 0, 0, &res);
+		WARN(res.a0, "Secure function call 0x%08x failed\n", fn);
+	} else {
+		_omap_smc1(fn, arg);
+	}
+}
+
 /* Allocate the memory to save secure ram */
 int __init omap_secure_ram_reserve_memblock(void)
 {
diff --git a/arch/arm/mach-omap2/omap-secure.h b/arch/arm/mach-omap2/omap-secure.h
index 20046e8f8ecb..601d64b2c744 100644
--- a/arch/arm/mach-omap2/omap-secure.h
+++ b/arch/arm/mach-omap2/omap-secure.h
@@ -60,6 +60,7 @@
 
 extern u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs,
 				u32 arg1, u32 arg2, u32 arg3, u32 arg4);
+extern void omap_smc1(u32 fn, u32 arg);
 extern u32 omap_smc2(u32 id, u32 falg, u32 pargs);
 extern u32 omap_smc3(u32 id, u32 process, u32 flag, u32 pargs);
 extern phys_addr_t omap_secure_ram_mempool_base(void);
diff --git a/arch/arm/mach-omap2/omap-smc.S b/arch/arm/mach-omap2/omap-smc.S
index fd2bcd91f4a1..d4832845a4e8 100644
--- a/arch/arm/mach-omap2/omap-smc.S
+++ b/arch/arm/mach-omap2/omap-smc.S
@@ -18,18 +18,18 @@
  * the monitor API number. It uses few CPU registers
  * internally and hence they need be backed up including
  * link register "lr".
- * Function signature : void omap_smc1(u32 fn, u32 arg)
+ * Function signature : void _omap_smc1(u32 fn, u32 arg)
  */
 	.arch armv7-a
 	.arch_extension sec
-ENTRY(omap_smc1)
+ENTRY(_omap_smc1)
 	stmfd   sp!, {r2-r12, lr}
 	mov	r12, r0
 	mov 	r0, r1
 	dsb
 	smc	#0
 	ldmfd   sp!, {r2-r12, pc}
-ENDPROC(omap_smc1)
+ENDPROC(_omap_smc1)
 
 /**
  * u32 omap_smc2(u32 id, u32 falg, u32 pargs)
-- 
2.17.1

             reply	other threads:[~2019-11-18 16:52 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18 16:52 Andrew F. Davis [this message]
2019-11-18 16:52 ` [PATCH] ARM: OMAP: Use ARM SMC Calling Convention when OP-TEE is available Andrew F. Davis
2019-11-18 21:57 ` Tony Lindgren
2019-11-18 22:13   ` Andrew F. Davis
2019-11-18 22:13     ` Andrew F. Davis
2019-11-18 22:31     ` Tony Lindgren
2019-11-19  1:13       ` Andrew F. Davis
2019-11-19  1:13         ` Andrew F. Davis
2019-11-19 16:21         ` Tony Lindgren
2019-11-19 16:21           ` Tony Lindgren
2019-11-19 16:30           ` Tony Lindgren
2019-11-19 16:30           ` Andrew F. Davis
2019-11-19 16:30             ` Andrew F. Davis
2019-11-19 16:42             ` Tony Lindgren
2019-11-19 18:05               ` Tony Lindgren
2019-11-19 18:20                 ` Andrew F. Davis
2019-11-19 18:20                   ` Andrew F. Davis
2019-11-19 18:32                   ` Tony Lindgren
2019-11-19 18:50                     ` Andrew F. Davis
2019-11-19 18:50                       ` Andrew F. Davis
2019-11-19 19:07                       ` Tony Lindgren
2019-11-19 19:12                         ` Andrew F. Davis
2019-11-19 19:12                           ` Andrew F. Davis
2019-11-19 19:20                           ` Tony Lindgren
2019-11-19 19:35                             ` Andrew F. Davis
2019-11-19 19:35                               ` Andrew F. Davis
2019-11-19 19:44                               ` Tony Lindgren
2019-11-19 19:59                                 ` Andrew F. Davis
2019-11-19 19:59                                   ` Andrew F. Davis
2019-12-16 20:56                                   ` Andrew F. Davis
2019-12-16 20:56                                     ` Andrew F. Davis
2019-12-16 21:04                                     ` Tony Lindgren
2019-12-16 22:34                                       ` Andrew F. Davis
2019-12-16 22:34                                         ` Andrew F. Davis
2019-12-16 22:41                                         ` Tony Lindgren
2019-12-17 13:14                                           ` Andrew F. Davis
2019-12-17 13:14                                             ` Andrew F. Davis
2019-12-17 15:07                                             ` Tony Lindgren
2019-12-17 17:01                                               ` Andrew F. Davis
2019-12-17 17:01                                                 ` Andrew F. Davis
2019-12-17 17:11                                                 ` Tony Lindgren
2019-12-17 17:18                                                   ` Tony Lindgren

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=20191118165236.22136-1-afd@ti.com \
    --to=afd@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.