Skip to contentSkip to conversation

ARM: EXYNOS: Add smc call to support trustzone feature

PATCH Superseded Kyungmin Park 4 participants 4 messages Jun 11, 2012 – Jun 20, 2012

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: EXYNOS: Add smc call to support trustzone feature

From: Kyungmin Park <[email protected]>

Linux runs in non-secure mode on some boards, so we need secure monitor calls

---

arch/arm/mach-exynos/Makefile +5 -0
index 9b58024..d3ec71c 100644
@@ -30,6 +30,11 @@ obj-$(CONFIG_EXYNOS4_MCT)	+= mct.o
 
 obj-$(CONFIG_HOTPLUG_CPU)	+= hotplug.o
 
+obj-$(CONFIG_ARM_TRUSTZONE)	+= exynos-smc.o
+
+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_exynos-smc.o		:=-Wa,-march=armv7-a$(plus_sec)
+
 # machine support
 
 obj-$(CONFIG_MACH_SMDKC210)		+= mach-smdkv310.o
arch/arm/mach-exynos/common.h +3 -0
index aed2eeb..d3e2f29 100644
@@ -21,6 +21,9 @@ void exynos4_restart(char mode, const char *cmd);
 void exynos5_restart(char mode, const char *cmd);
 void exynos_init_late(void);
 
+extern void exynos_smc(u32 cmd, u32 arg1, u32 arg2, u32 arg3);
+extern u32 exynos_smc_readsfr(u32 addr, u32 *val);
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS
 int exynos_pm_late_initcall(void);
 #else
arch/arm/mach-exynos/exynos-smc.S new file +46 -0

46 lines not on this page · raw message

#1 lore raw

PATCH 1/1 ARM: EXYNOS: Add smc call to support trustzone feature

Quoted 3 lines · Kyungmin Park

+/*
+ * Read registers
+ * Function signature: u32 exynos_smc_readsfr(u32 addr, u32 *val)

What address space is 'addr' in?

arch/arm/mach-exynos/exynos-smc.S line 34

Quoted 8 lines

+ */

arch/arm/mach-exynos/exynos-smc.S new file +7 -0
+ENTRY(exynos_smc_readsfr)
+	stmfd	sp!, {r4-r11, lr}
+	mov	r2, #0
+	lsr	r0, r0, #2
+	mov	ip, r1
+	mov	r3, r2
+	orr	r1, r0, #0xC0000000

I assume this is not PAGE_OFFSET.

arch/arm/mach-exynos/exynos-smc.S line 35

Quoted 1 line
arch/arm/mach-exynos/exynos-smc.S new file +1 -0
+	mvn	r0, #100

Hmm. The compiler will automatically use mvn instead of a normal mov with negative numbers. It may be clearer to write:

	mov	r0, #-101

arch/arm/mach-exynos/exynos-smc.S line 38

Quoted 3 lines
arch/arm/mach-exynos/exynos-smc.S new file +3 -0
+	dsb
+	smc	#0
+	cmn	r0, #101

Same here:

	cmp	r0, #-101

Notice that writing it this way means it's obvious that you're checking for -101, the original value passed in.

arch/arm/mach-exynos/exynos-smc.S line 43

Quoted 5 lines
arch/arm/mach-exynos/exynos-smc.S new file +5 -0
+	beq	1f
+	cmp	r0, #0
+	streq	r2, [ip]
+	ldmfd	sp!, {r4-r11, pc}
+1:	subs	r0, r1, #0

Isn't this just a normal:

	movs	r0, r1

?

arch/arm/mach-exynos/exynos-smc.S line 46

Quoted 3 lines
arch/arm/mach-exynos/exynos-smc.S new file +3 -0
+	streq	r2, [ip]
+	ldmfd	sp!, {r4-r11, pc}
+ENDPROC(exynos_smc_readsfr)

In any case, can't this end part be written:

	cmp	r0, #-101
	moveq	r0, r1
	teq	r0, #0		@ I prefer teq over cmp to test equality
	streq	r2, [ip]
	ldmfd	sp!, {r4 - r11, pc}
#2 lore raw

PATCH 1/1 ARM: EXYNOS: Add smc call to support trustzone feature

Hello,

This is a forwarded message originally posted by Kyungmin Park [kyungmin.park at samsung.com]:

Quoted 6 lines · Russell King - ARM Linux
Quoted 3 lines · Kyungmin Park

+/*
+ * Read registers
+ * Function signature: u32 exynos_smc_readsfr(u32 addr, u32 *val)

What address space is 'addr' in?

It's Memory Controller address with physical address space. I don't know why this address is required. It's vendor specific address. If exynos_smc_readsfr is ambiguous, then it will drop at this time.

Quoted 10 lines

arch/arm/mach-exynos/exynos-smc.S line 34

Quoted 8 lines

+ */

arch/arm/mach-exynos/exynos-smc.S new file +7 -0
+ENTRY(exynos_smc_readsfr)
+    stmfd    sp!, {r4-r11, lr}
+    mov      r2, #0
+    lsr        r0, r0, #2
+    mov      ip, r1
+    mov      r3, r2
+    orr       r1, r0, #0xC0000000

I assume this is not PAGE_OFFSET.

Right, it's also vendor specific command.

To read SFR, it send r0 = -101, r1 = (0x3 << 30) | ((addr) >> 2), r2 = r3 = 0;

Quoted 7 lines
Quoted 2 lines

+ mvn r0, #100

Hmm. The compiler will automatically use mvn instead of a normal mov with negative numbers. It may be clearer to write:

        mov      r0, #-101

exactly. I refered the compiled generated codes. I'll change it.

Quoted 26 lines

arch/arm/mach-exynos/exynos-smc.S line 38

Quoted 4 lines
arch/arm/mach-exynos/exynos-smc.S new file +3 -0
+    dsb
+    smc      #0
+    cmn      r0, #101

Same here:

        cmp      r0, #-101

Notice that writing it this way means it's obvious that you're checking for -101, the original value passed in.

arch/arm/mach-exynos/exynos-smc.S line 43

Quoted 5 lines
arch/arm/mach-exynos/exynos-smc.S new file +5 -0
+    beq      1f
+    cmp      r0, #0
+    streq    r2, [ip]
+    ldmfd    sp!, {r4-r11, pc}
+1:  subs     r0, r1, #0

Isn't this just a normal:
movs r0, r1

?

arch/arm/mach-exynos/exynos-smc.S line 46

Quoted 3 lines
arch/arm/mach-exynos/exynos-smc.S new file +3 -0
+    streq    r2, [ip]
+    ldmfd    sp!, {r4-r11, pc}
+ENDPROC(exynos_smc_readsfr)
Quoted 7 lines

In any case, can't this end part be written:

cmp r0, #-101
moveq r0, r1
teq r0, #0 @ I prefer teq over cmp to test equality
streq r2, [ip]
ldmfd sp!, {r4 - r11, pc}

I'll change it.

Thank you,
Kyungmin Park

#3 lore raw

PATCH 1/1 ARM: EXYNOS: Add smc call to support trustzone feature

In reply to Kyungmin Park
Quoted 11 lines · Kyungmin Park

From: Kyungmin Park <[email protected]>

Linux runs in non-secure mode on some boards, so we need secure monitor calls

---

arch/arm/mach-exynos/Makefile +0 -0
index 9b58024..d3ec71c 100644

arch/arm/mach-exynos/Makefile obj-$(CONFIG_EXYNOS4_MCT) += mct.o · line 37

Quoted 8 lines
arch/arm/mach-exynos/Makefile +5 -0
@@ -30,6 +30,11 @@ obj-$(CONFIG_EXYNOS4_MCT)	+= mct.o
 
 obj-$(CONFIG_HOTPLUG_CPU)	+= hotplug.o
 
+obj-$(CONFIG_ARM_TRUSTZONE)	+= exynos-smc.o
+
+plus_sec := $(call as-instr,.arch_extension sec,+sec)
+AFLAGS_exynos-smc.o		:=-Wa,-march=armv7-a$(plus_sec)
+

If we can get DT bindings to say what the firmware is present, then this can be decided at run-time (see the other thread), allowing a single kernel to boot on boards deployed either with or without the firmware.

Also, CONFIG_ARM_TRUSTZONE is probably not a good name: the issue here is not whether TrustZone is present, but what firmware (if any) is accessible via the SMC instruction.

Cheers
---Dave

Quoted 74 lines
arch/arm/mach-exynos/Makefile +0 -0
 # machine support
 
 obj-$(CONFIG_MACH_SMDKC210)		+= mach-smdkv310.o
arch/arm/mach-exynos/common.h +3 -0
index aed2eeb..d3e2f29 100644
@@ -21,6 +21,9 @@ void exynos4_restart(char mode, const char *cmd);
 void exynos5_restart(char mode, const char *cmd);
 void exynos_init_late(void);
 
+extern void exynos_smc(u32 cmd, u32 arg1, u32 arg2, u32 arg3);
+extern u32 exynos_smc_readsfr(u32 addr, u32 *val);
+
 #ifdef CONFIG_PM_GENERIC_DOMAINS
 int exynos_pm_late_initcall(void);
 #else
arch/arm/mach-exynos/exynos-smc.S new file +46 -0
new file mode 100644
index 0000000..2ef8f59
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics.
+ *
+ * Copied from omap-smc.S Copyright (C) 2010 Texas Instruments, Inc.
+ *
+ * This program is free software,you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/linkage.h>
+
+/*
+ * Function signature: void exynos_smc(u32 cmd, u32 arg1, u32 arg2, u32 arg3)
+ */
+
+ENTRY(exynos_smc)
+	stmfd	sp!, {r4-r11, lr}
+	dsb
+	smc	#0
+	ldmfd	sp!, {r4-r11, pc}
+ENDPROC(exynos_smc)
+
+/*
+ * Read registers
+ * Function signature: u32 exynos_smc_readsfr(u32 addr, u32 *val)
+ */
+ENTRY(exynos_smc_readsfr)
+	stmfd	sp!, {r4-r11, lr}
+	mov	r2, #0
+	lsr	r0, r0, #2
+	mov	ip, r1
+	mov	r3, r2
+	orr	r1, r0, #0xC0000000
+	mvn	r0, #100
+	dsb
+	smc	#0
+	cmn	r0, #101
+	beq	1f
+	cmp	r0, #0
+	streq	r2, [ip]
+	ldmfd	sp!, {r4-r11, pc}
+1:	subs	r0, r1, #0
+	streq	r2, [ip]
+	ldmfd	sp!, {r4-r11, pc}
+ENDPROC(exynos_smc_readsfr)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel