public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Christoffer Dall <christoffer.dall@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 5/7] ARM: add SMP support for non-secure switch
Date: Wed, 19 Jun 2013 16:27:17 -0700	[thread overview]
Message-ID: <20130619232717.GF7870@lvm> (raw)
In-Reply-To: <1371121273-18763-6-git-send-email-andre.przywara@linaro.org>

On Thu, Jun 13, 2013 at 01:01:11PM +0200, Andre Przywara wrote:
> Currently the non-secure switch is only done for the boot processor.
> To enable full SMP support, we have to switch all secondary cores
> into non-secure state also.
> 
> So we add an entry point for secondary CPUs coming out of low-power
> state and make sure we put them into WFI again after having switched
> to non-secure state.
> For this we acknowledge and EOI the wake-up IPI, then go into WFI.
> Once being kicked out of it later, we sanity check that the start
> address has actually been changed (since another attempt to switch
> to non-secure would block the core) and jump to the new address.
> 
> The actual CPU kick is done by sending an inter-processor interrupt
> via the GIC to all CPU interfaces except the requesting processor.
> The secondary cores will then setup their respective GIC CPU
> interface.
> 
> The address secondary cores jump to is board specific, we provide
> the value here for the Versatile Express board.
> 
> Signed-off-by: Andre Przywara <andre.przywara@linaro.org>
> ---
>  arch/arm/cpu/armv7/nonsec_virt.S    | 27 +++++++++++++++++++++++++++
>  arch/arm/include/asm/armv7.h        |  1 +
>  arch/arm/lib/virt-v7.c              | 19 ++++++++++++++++++-
>  include/configs/vexpress_ca15_tc2.h |  3 +++
>  4 files changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S
> index 656d99b..919f6e9 100644
> --- a/arch/arm/cpu/armv7/nonsec_virt.S
> +++ b/arch/arm/cpu/armv7/nonsec_virt.S
> @@ -54,6 +54,33 @@ _secure_monitor:
>  
>  	movs	pc, lr				@ return to non-secure SVC
>  
> +/*
> + * Secondary CPUs start here and call the code for the core specific parts
> + * of the non-secure and HYP mode transition. The GIC distributor specific
> + * code has already been executed by a C function before.
> + * Then they go back to wfi and wait to be woken up by the kernel again.
> + */
> +.globl _smp_pen
> +_smp_pen:
> +	mrs	r0, cpsr
> +	orr	r0, r0, #0xc0
> +	msr	cpsr, r0			@ disable interrupts
> +	ldr	r1, =_start
> +	mcr	p15, 0, r1, c12, c0, 0		@ set VBAR
> +
> +	bl	_nonsec_init
> +
> +	ldr	r1, [r3, #0x0c]			@ read GICD acknowledge
> +	str	r1, [r3, #0x10]			@ write GICD EOI
> +	adr	r1, _smp_pen
> +waitloop:
> +	wfi
> +	ldr	r0, =CONFIG_SYSFLAGS_ADDR	@ load start address

the name sysflags addr is a very vexpress specific thingy.

I think you need to call this something like SMP_SECONDARY_BOOT_ADDR or
whatever, which is more generic.

> +	ldr	r0, [r0]
> +	cmp	r0, r1			@ make sure we dont execute this code
> +	beq	waitloop		@ again (due to a spurious wakeup)
> +	mov	pc, r0
> +
>  #define lo(x) ((x) & 0xFFFF)
>  #define hi(x) ((x) >> 16)
>  
> diff --git a/arch/arm/include/asm/armv7.h b/arch/arm/include/asm/armv7.h
> index 56d0dd0..04545b9 100644
> --- a/arch/arm/include/asm/armv7.h
> +++ b/arch/arm/include/asm/armv7.h
> @@ -97,6 +97,7 @@ int armv7_switch_nonsec(void);
>  
>  /* defined in cpu/armv7/nonsec_virt.S */
>  void _nonsec_init(void);
> +void _smp_pen(void);
>  #endif /* CONFIG_ARMV7_VIRT */
>  
>  #endif /* ! __ASSEMBLY__ */
> diff --git a/arch/arm/lib/virt-v7.c b/arch/arm/lib/virt-v7.c
> index 7876a77..6946e4d 100644
> --- a/arch/arm/lib/virt-v7.c
> +++ b/arch/arm/lib/virt-v7.c
> @@ -95,6 +95,21 @@ static int get_gic_base_address(char **gicdptr)
>  #endif
>  }
>  
> +static void kick_secondary_cpus(char *gicdptr)
> +{
> +	unsigned int *sysflags;

again, I think the use of the name sysflags here is misunderstood.

> +
> +	sysflags = (void *)CONFIG_SYSFLAGS_ADDR;
> +#ifdef CONFIG_SYSFLAGS_NEED_CLEAR_BITS
> +	sysflags[1] = (unsigned)-1;

this feels like we're wrapping some vexpress-logic into some
pseudo-generic logic here.  It feels like there should be a function
provided by the board code, that we simply call.

void set_board_smp_boot_addr(unsigned long addr);

> +#endif
> +	*sysflags = (uintptr_t)_smp_pen;
> +	dmb();
> +
> +	/* now kick all CPUs (expect this one) by writing to GICD_SGIR */

s/expect/except/

> +	writel(1U << 24, &gicdptr[GICD_SGIR]);
> +}
> +
>  int armv7_switch_nonsec(void)
>  {
>  	unsigned int reg, ret;
> @@ -130,7 +145,9 @@ int armv7_switch_nonsec(void)
>  	for (i = 0; i <= itlinesnr; i++)
>  		writel((unsigned)-1, &gicdptr[GICD_IGROUPRn + 4 * i]);
>  
> -	/* call the non-sec switching code on this CPU */
> +	kick_secondary_cpus(gicdptr);
> +
> +	/* call the non-sec switching code on this CPU also */
>  	_nonsec_init();
>  
>  	return 0;
> diff --git a/include/configs/vexpress_ca15_tc2.h b/include/configs/vexpress_ca15_tc2.h
> index 4f425ac..ade9e5b 100644
> --- a/include/configs/vexpress_ca15_tc2.h
> +++ b/include/configs/vexpress_ca15_tc2.h
> @@ -31,4 +31,7 @@
>  #include "vexpress_common.h"
>  #define CONFIG_BOOTP_VCI_STRING     "U-boot.armv7.vexpress_ca15x2_tc2"
>  
> +#define CONFIG_SYSFLAGS_ADDR 0x1c010030
> +#define CONFIG_SYSFLAGS_NEED_CLEAR_BITS
> +
>  #endif
> -- 
> 1.7.12.1
> 

  reply	other threads:[~2013-06-19 23:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-13 11:01 [U-Boot] [PATCH v2 0/7] ARMv7: Add HYP mode switching support Andre Przywara
2013-06-13 11:01 ` [U-Boot] [PATCH v2 1/7] ARM: prepare armv7.h to be included from assembly source Andre Przywara
2013-06-28  1:00   ` Masahiro Yamada
2013-07-04  7:38     ` Andre Przywara
2013-06-13 11:01 ` [U-Boot] [PATCH v2 2/7] ARM: add secure monitor handler to switch to non-secure state Andre Przywara
2013-06-28  3:00   ` Masahiro Yamada
2013-06-13 11:01 ` [U-Boot] [PATCH v2 3/7] ARM: add assembly routine " Andre Przywara
2013-06-19 22:27   ` Christoffer Dall
2013-06-28  3:09   ` Masahiro Yamada
2013-06-13 11:01 ` [U-Boot] [PATCH v2 4/7] ARM: switch to non-secure state during bootm execution Andre Przywara
2013-06-19 23:13   ` Christoffer Dall
2013-06-28  3:18   ` Masahiro Yamada
2013-07-04  7:42     ` Andre Przywara
2013-06-13 11:01 ` [U-Boot] [PATCH v2 5/7] ARM: add SMP support for non-secure switch Andre Przywara
2013-06-19 23:27   ` Christoffer Dall [this message]
2013-06-28  3:22   ` Masahiro Yamada
2013-06-13 11:01 ` [U-Boot] [PATCH v2 6/7] ARM: extend non-secure switch to also go into HYP mode Andre Przywara
2013-06-19 23:40   ` Christoffer Dall
2013-06-21 14:38   ` Nikolay Nikolaev
2013-06-25  8:27     ` Andre Przywara
2013-06-28  3:51   ` Masahiro Yamada
2013-07-04 11:29     ` Andre Przywara
2013-06-13 11:01 ` [U-Boot] [PATCH v2 7/7] ARM: VExpress: enable ARMv7 virt support for VExpress A15 Andre Przywara

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=20130619232717.GF7870@lvm \
    --to=christoffer.dall@linaro.org \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox