Add support for the Exynos secure firmware
PATCH v3 1/1 Add support for the Exynos secure firmware
The existence of secure firmware is dictated by the presence of "samsung,secure-firmware" in the DT.
The Arndale board does not have that entry, and uses the address as defined in "samsung,exynos4210-sysram", offset 0 as the smp init address. This is possibly true for all SoCs without secure firmware.
For other boards which do have a "secure-firmware" node, use sysram-ns at offset +0x1c as the smp init address.
The "secure-firmware" MMIO range contains ways to idle the CPU. As this gets mapped to DOM0 because of its presence in the DT, we blacklist it.
Have tested this on the Odroid XU. I have also tested the other code path on the Odroid XU by removing "secure-firmware" from its DT. I could see that the other code path was exercised with correct smp init address values.
---
This patch is based off of the staging area.
Changes between versions as follows:
v3:
Inline function exynos_smp_init_getbasesizeoffset as its used in only one place.
Call exynos_smc for SMC_CMD_CPU1BOOT only if secure_firmware is present. Remove EXYNOS5_PA_PMU as its value is extracted from DT.
v2:
Consolidate exynos_smp_init_getbaseandoffset().
Use the size from the DT as mapping length conistently.
Do not check if the poking addresses are within size. We just expect it to be.
Add smc call in cpu bring up code. Linux does this call irrespective of the presence of "secure-firmware" in the DT.
Blacklist "samsung,secure-firmware".
Change subject line appropriately.
v1:
Unbreak Arndale XEN boot.
Remove BUG_ON for checking the address offsets that we poke with. Instead use the size field from the DT to make valid comaprisons.
--- xen/arch/arm/platforms/exynos5.c | 92 +++++++++++++++++++++++---------- xen/include/asm-arm/platforms/exynos5.h | 2 - 2 files changed, 65 insertions(+), 29 deletions(-)
xen/arch/arm/platforms/exynos5.c +65 -27
@@ -28,11 +28,31 @@#include <asm/platform.h> #include <asm/io.h> +static bool_t secure_firmware; + +static noinline void exynos_smc(register_t function_id, register_t arg0, +register_t arg1,register_t arg2) +{ + asmvolatile ( + __asmeq("%0", "r0") + __asmeq("%1", "r1") + __asmeq("%2", "r2") + __asmeq("%3", "r3") + "smc #0" + : + : "r" (function_id), "r" (arg0), "r" (arg1), "r" (arg2)); +} + +/* This corresponds to CONFIG_NR_CPUS in linux config */ +#define EXYNOS_CONFIG_NR_CPUS 0x08 +#define EXYNOS_ARM_CORE0_CONFIG 0x2000 -#define EXYNOS_ARM_CORE_CONFIG (_nr) (0x80 * (_nr)) +#define EXYNOS_ARM_CORE_CONFIG (_nr) (EXYNOS_ARM_CORE0_CONFIG + (0x80 * (_nr)))#define EXYNOS_ARM_CORE_STATUS (_nr) (EXYNOS_ARM_CORE_CONFIG(_nr) + 0x4)#define S5P_CORE_LOCAL_PWR_EN 0x3 +#define SMC_CMD_CPU1BOOT (-4) +static int exynos5_init_time (void ) {uint32_t reg;
@@ -42,8 +62,6 @@ static int exynos5_init_time(void)u64 mct_base_addr;u64 size; -BUILD_BUG_ON (EXYNOS5_MCT_G_TCON >=PAGE_SIZE ); - node =dt_find_compatible_node (NULL ,NULL ,"samsung,exynos4210-mct" );if ( !node ) {
@@ -61,7 +79,7 @@ static int exynos5_init_time(void)dprintk (XENLOG_INFO ,"mct_base_addr: %016llx size: %016llx\n" , mct_base_addr, size); - mct =ioremap_attr (mct_base_addr,PAGE_SIZE ,PAGE_HYPERVISOR_NOCACHE ); + mct =ioremap_attr (mct_base_addr, size,PAGE_HYPERVISOR_NOCACHE );if ( !mct ) {dprintk (XENLOG_ERR ,"Unable to map MCT\n" );
@@ -93,30 +111,47 @@ static int exynos5250_specific_mapping(struct domain *d)static int __init exynos5_smp_init (void ) { -void __iomem *sysram;struct dt_device_node *node; -u64 sysram_ns_base_addr; +void __iomem *sysram; +char *compatible; +u64 sysram_addr;u64 size; +u64 sysram_offset;int rc; - node =dt_find_compatible_node (NULL ,NULL ,"samsung,exynos4210-sysram" ); + node =dt_find_compatible_node (NULL ,NULL ,"samsung,secure-firmware" ); +if ( node ) + { +/* Have to use sysram_ns_base_addr + 0x1c for boot address */ + compatible ="samsung,exynos4210-sysram-ns" ; + sysram_offset =0x1c ; + secure_firmware =1 ; +printk ("Running under secure firmware.\n" ); + } +else + { +/* Have to use sysram_base_addr + offset 0 for boot address */ + compatible ="samsung,exynos4210-sysram" ; + sysram_offset =0 ; + } + + node =dt_find_compatible_node (NULL ,NULL , compatible);if ( !node ) { -dprintk (XENLOG_ERR ,"samsung,exynos4210-sysram-ns missing in DT\n" ); +dprintk (XENLOG_ERR ,"%s missing in DT\n" , compatible);return -ENXIO ; } - rc =dt_device_get_address (node,0 , &sysram_ns_base_addr, &size); + rc =dt_device_get_address (node,0 , &sysram_addr, &size);if ( rc ) { -dprintk (XENLOG_ERR ,"Error in \"samsung,exynos4210-sysram-ns\"\n" ); +dprintk (XENLOG_ERR ,"Error in %s\n" , compatible);return -ENXIO ; } +dprintk (XENLOG_INFO ,"sysram_addr: %016llx size: %016llx offset: %016llx\n" , + sysram_addr, size, sysram_offset); -dprintk (XENLOG_INFO ,"sysram_ns_base_addr: %016llx size: %016llx\n" , - sysram_ns_base_addr, size); - - sysram =ioremap_nocache (sysram_ns_base_addr,PAGE_SIZE ); + sysram =ioremap_nocache (sysram_addr, size);if ( !sysram ) {dprintk (XENLOG_ERR ,"Unable to map exynos5 MMIO\n" );
@@ -125,7 +160,7 @@ static int __init exynos5_smp_init(void)printk ("Set SYSRAM to %" PRIpaddr" (%p)\n" ,__pa (init_secondary), init_secondary); -writel (__pa (init_secondary), sysram); +writel (__pa (init_secondary), sysram + sysram_offset);iounmap (sysram);
@@ -135,7 +170,7 @@ static int __init exynos5_smp_init(void)static int exynos_cpu_power_state (void __iomem *power,int cpu) {return __raw_readl (power +EXYNOS_ARM_CORE_STATUS (cpu)) & -S5P_CORE_LOCAL_PWR_EN ; +S5P_CORE_LOCAL_PWR_EN ; }static void exynos_cpu_power_up (void __iomem *power,int cpu)
@@ -171,8 +206,8 @@ static int exynos5_cpu_power_up(void __iomem *power, int cpu)return 0 ; } -static int exynos5_get_pmu_base_addr (u64 *power_base_addr) { -u64 size; +static int exynos5_get_pmu_baseandsize (u64 *power_base_addr,u64 *size) +{struct dt_device_node *node;int rc; static const struct dt_device_match exynos_dt_pmu_matches[] __initconst =
@@ -190,7 +225,7 @@ static int exynos5_get_pmu_base_addr(u64 *power_base_addr) {return -ENXIO ; } - rc =dt_device_get_address (node,0 , power_base_addr, &size); + rc =dt_device_get_address (node,0 , power_base_addr, size);if ( rc ) {dprintk (XENLOG_ERR ,"Error in \"samsung,exynos5XXX-pmu\"\n" );
@@ -198,7 +233,7 @@ static int exynos5_get_pmu_base_addr(u64 *power_base_addr) { }dprintk (XENLOG_DEBUG ,"power_base_addr: %016llx size: %016llx\n" , - *power_base_addr, size); + *power_base_addr, *size);return 0 ; }
@@ -206,15 +241,15 @@ static int exynos5_get_pmu_base_addr(u64 *power_base_addr) {static int exynos5_cpu_up (int cpu) {u64 power_base_addr; +u64 size;void __iomem *power;int rc; - rc =exynos5_get_pmu_base_addr (&power_base_addr); + rc =exynos5_get_pmu_baseandsize (&power_base_addr, &size);if ( rc )return rc; - power =ioremap_nocache (power_base_addr + -EXYNOS_ARM_CORE0_CONFIG ,PAGE_SIZE ); + power =ioremap_nocache (power_base_addr, size);if ( !power ) {dprintk (XENLOG_ERR ,"Unable to map power MMIO\n" );
@@ -230,22 +265,24 @@ static int exynos5_cpu_up(int cpu)iounmap (power); +if ( secure_firmware ) +exynos_smc (SMC_CMD_CPU1BOOT , cpu,0 ,0 ); +return cpu_up_send_sgi (cpu); }static void exynos5_reset (void ) {u64 power_base_addr; +u64 size;void __iomem *pmu;int rc; -BUILD_BUG_ON (EXYNOS5_SWRESET >=PAGE_SIZE ); - - rc =exynos5_get_pmu_base_addr (&power_base_addr); + rc =exynos5_get_pmu_baseandsize (&power_base_addr, &size);if ( rc )return ; - pmu =ioremap_nocache (power_base_addr,PAGE_SIZE ); + pmu =ioremap_nocache (power_base_addr, size);if ( !pmu ) {dprintk (XENLOG_ERR ,"Unable to map PMU\n" );
@@ -264,6 +301,7 @@ static const struct dt_device_match exynos5_blacklist_dev[] __initconst =* This is result to random freeze. */ DT_MATCH_COMPATIBLE ("samsung,exynos4210-mct" ), + DT_MATCH_COMPATIBLE("samsung,secure-firmware"), { /* sentinel */ }, };
xen/include/asm-arm/platforms/exynos5.h +0 -2
@@ -6,8 +6,6 @@#define EXYNOS5_PA_CHIPID 0x10000000#define EXYNOS5_PA_TIMER 0x12dd0000 -/* Base address of system controller */ -#define EXYNOS5_PA_PMU 0x10040000#define EXYNOS5_SWRESET 0x0400/* Relative to PA_PMU */
Signature · 1 line
1.9.1
On Mon, 2014-09-15 at 12:34 -0700, Suriyan Ramasami wrote:
I've not had a chance to look at this yet but someone mentioned on IRC that the original Odroid patch also broke reboot on arndale. Is that likely to be fixed by this too?
What caused you to CC Jan and Keir here? They are not generally interested in ARM stuff.
The MAINTAINERS file can guide you here, and there is a tool in ./scripts/get_maintainers.pl which you can pipe a patch into and it'll do the look up for you.
Ian.
Quoted 6 lines · Ian Campbell
On Mon, 2014-09-15 at 12:34 -0700, Suriyan Ramasami wrote:
I've not had a chance to look at this yet but someone mentioned on IRC that the original Odroid patch also broke reboot on arndale. Is that likely to be fixed by this too?
I do not know what the "original Odroid patch" refers to anymore. BTW, if the build from the staging area (which has your code on top of the Odroid patch) works, then this should also work.
I do not have an arndale board, and hence have no way of testing it.
Quoted 7 lines
What caused you to CC Jan and Keir here? They are not generally interested in ARM stuff.
The
MAINTAINERSfile can guide you here, and there is a tool in./scripts/get_maintainers.plwhich you can pipe a patch into and it'll do the look up for you.
I shall do this next time around. Thanks!
- Suriyan
Quoted 2 lines
Ian.
Quoted 2 lines · Suriyan Ramasami
On Mon, Sep 15, 2014 at 4:00 PM, Ian Campbell <[email protected]>
Quoted 11 lines · wrote:
Quoted 6 lines · Suriyan Ramasami
I've not had a chance to look at this yet but someone mentioned on IRC that the original Odroid patch also broke reboot on arndale. Is that likely to be fixed by this too?
I do not know what the "original Odroid patch" refers to anymore. BTW, if the build from the staging area (which has your code on top of the Odroid patch) works, then this should also work.
I do not have an arndale board, and hence have no way of testing it.
Ah! Now I understand the issue! The original patch as part of mapping the pmu did not map from base. This led to SWRESET being off. These patches as they map the pmu base for the full size should not be hitting the reboot issue seen before.
Quoted 12 lines
Quoted 7 lines
What caused you to CC Jan and Keir here? They are not generally interested in ARM stuff.
The
MAINTAINERSfile can guide you here, and there is a tool in./scripts/get_maintainers.plwhich you can pipe a patch into and it'll do the look up for you.I shall do this next time around. Thanks!
- SuriyanQuoted 2 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 13 lines · Suriyan Ramasami
The existence of secure firmware is dictated by the presence of "samsung,secure-firmware" in the DT.
The Arndale board does not have that entry, and uses the address as defined in "samsung,exynos4210-sysram", offset 0 as the smp init address. This is possibly true for all SoCs without secure firmware.
For other boards which do have a "secure-firmware" node, use sysram-ns at offset +0x1c as the smp init address.
The "secure-firmware" MMIO range contains ways to idle the CPU. As this gets mapped to DOM0 because of its presence in the DT, we blacklist it.
Quoted 6 lines
Have tested this on the Odroid XU. I have also tested the other code path on the Odroid XU by removing "secure-firmware" from its DT. I could see that the other code path was exercised with correct smp init address values.
Signed-off-by Suriyan Ramasami <[email protected]>
I think this had already been sent when I accidentally reviewed v2 instead. The main thing which still applies is the EXYNOS_CONFIG_NR_CPUS which needs to be dropped.
Ideally I'd like to see exynos_smc and __invoke_psci_fn_smc become a common helper somewhere but I won't insist.
The rest looks good, thanks.
Ian.
Quoted 19 lines · Ian Campbell
Quoted 18 lines · Suriyan Ramasami
The existence of secure firmware is dictated by the presence of "samsung,secure-firmware" in the DT.
The Arndale board does not have that entry, and uses the address as defined in "samsung,exynos4210-sysram", offset 0 as the smp init address. This is possibly true for all SoCs without secure firmware.
For other boards which do have a "secure-firmware" node, use sysram-ns at offset +0x1c as the smp init address.
The "secure-firmware" MMIO range contains ways to idle the CPU. As this gets mapped to DOM0 because of its presence in the DT, we blacklist it.
Have tested this on the Odroid XU. I have also tested the other code path on the Odroid XU by removing "secure-firmware" from its DT. I could see that the other code path was exercised with correct smp init address values.
Quoted 6 lines
Quoted 1 line
Signed-off-by Suriyan Ramasami <[email protected]>I think this had already been sent when I accidentally reviewed v2 instead. The main thing which still applies is the
EXYNOS_CONFIG_NR_CPUSwhich needs to be dropped.
I shall drop that.
Quoted 3 lines
Ideally I'd like to see
exynos_smcand__invoke_psci_fn_smcbecome a common helper somewhere but I won't insist.
I shall pick this up when I work on the Odroid-XU3 (exynos5422 based) XEN support, if that is OK.
I also have to remove __init_const from exynos_dt_pmu_matches[] so that the reset code works on arndale and odroidxu.
I shall push a v4 with these changes.
Thanks!
- Suriyan
Quoted 4 lines
The rest looks good, thanks.
Ian.