linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature
@ 2012-06-11  9:04 Kyungmin Park
  2012-06-11  9:44 ` Russell King - ARM Linux
  2012-06-20 10:59 ` Dave Martin
  0 siblings, 2 replies; 4+ messages in thread
From: Kyungmin Park @ 2012-06-11  9:04 UTC (permalink / raw)
  To: linux-arm-kernel

From: Kyungmin Park <kyungmin.park@samsung.com>

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

Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
diff --git a/arch/arm/mach-exynos/Makefile b/arch/arm/mach-exynos/Makefile
index 9b58024..d3ec71c 100644
--- a/arch/arm/mach-exynos/Makefile
+++ b/arch/arm/mach-exynos/Makefile
@@ -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
diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
index aed2eeb..d3e2f29 100644
--- a/arch/arm/mach-exynos/common.h
+++ b/arch/arm/mach-exynos/common.h
@@ -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
diff --git a/arch/arm/mach-exynos/exynos-smc.S b/arch/arm/mach-exynos/exynos-smc.S
new file mode 100644
index 0000000..2ef8f59
--- /dev/null
+++ b/arch/arm/mach-exynos/exynos-smc.S
@@ -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)

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature
  2012-06-11  9:04 [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature Kyungmin Park
@ 2012-06-11  9:44 ` Russell King - ARM Linux
  2012-06-11 10:19   ` Marek Szyprowski
  2012-06-20 10:59 ` Dave Martin
  1 sibling, 1 reply; 4+ messages in thread
From: Russell King - ARM Linux @ 2012-06-11  9:44 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jun 11, 2012 at 06:04:40PM +0900, Kyungmin Park wrote:
> +/*
> + * Read registers
> + * Function signature: u32 exynos_smc_readsfr(u32 addr, u32 *val)

What address space is 'addr' in?

> + */
> +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.

> +	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

> +	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.

> +	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

?

> +	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}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature
  2012-06-11  9:44 ` Russell King - ARM Linux
@ 2012-06-11 10:19   ` Marek Szyprowski
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Szyprowski @ 2012-06-11 10:19 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

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

On 6/11/12, Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> On Mon, Jun 11, 2012 at 06:04:40PM +0900, Kyungmin Park wrote:
>> +/*
>> + * 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.

>> + */
>> +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;

> 
>> +    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.

> 
>> +    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.
> 
>> +    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
> 
> ?
> 
>> +    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}

I'll change it.

Thank you,
Kyungmin Park

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature
  2012-06-11  9:04 [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature Kyungmin Park
  2012-06-11  9:44 ` Russell King - ARM Linux
@ 2012-06-20 10:59 ` Dave Martin
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Martin @ 2012-06-20 10:59 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Jun 11, 2012 at 06:04:40PM +0900, Kyungmin Park wrote:
> From: Kyungmin Park <kyungmin.park@samsung.com>
> 
> Linux runs in non-secure mode on some boards, so we need secure monitor calls
> 
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> ---
> diff --git a/arch/arm/mach-exynos/Makefile b/arch/arm/mach-exynos/Makefile
> index 9b58024..d3ec71c 100644
> --- a/arch/arm/mach-exynos/Makefile
> +++ b/arch/arm/mach-exynos/Makefile
> @@ -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

>  # machine support
>  
>  obj-$(CONFIG_MACH_SMDKC210)		+= mach-smdkv310.o
> diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
> index aed2eeb..d3e2f29 100644
> --- a/arch/arm/mach-exynos/common.h
> +++ b/arch/arm/mach-exynos/common.h
> @@ -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
> diff --git a/arch/arm/mach-exynos/exynos-smc.S b/arch/arm/mach-exynos/exynos-smc.S
> new file mode 100644
> index 0000000..2ef8f59
> --- /dev/null
> +++ b/arch/arm/mach-exynos/exynos-smc.S
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-20 10:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-11  9:04 [PATCH] ARM: EXYNOS: Add smc call to support trustzone feature Kyungmin Park
2012-06-11  9:44 ` Russell King - ARM Linux
2012-06-11 10:19   ` Marek Szyprowski
2012-06-20 10:59 ` Dave Martin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).