From patchwork Thu Jun 13 11:01:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 251051 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 39A5E2C009A for ; Thu, 13 Jun 2013 21:04:06 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3D5F44A2CD; Thu, 13 Jun 2013 13:03:45 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rSMN-TYN-fBx; Thu, 13 Jun 2013 13:03:45 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 072624A271; Thu, 13 Jun 2013 13:03:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 21BD34A115 for ; Thu, 13 Jun 2013 13:03:14 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xdySZWzeNZQa for ; Thu, 13 Jun 2013 13:03:08 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from mail-oa0-f48.google.com (mail-oa0-f48.google.com [209.85.219.48]) by theia.denx.de (Postfix) with ESMTPS id CB8184A19C for ; Thu, 13 Jun 2013 13:03:00 +0200 (CEST) Received: by mail-oa0-f48.google.com with SMTP id f4so6834520oah.35 for ; Thu, 13 Jun 2013 04:02:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=mRR5NjfZNNZaDGPI3O/mrB8W0pr0yEOM5JrYUoOXKVc=; b=hRWQp0I/lamYAFuLYQII0b7v4Rs1NroLpjQYMsmHT+5fbqMoE0LFi6rWRJ5i86rGrT 90OHFtHX0vT3TWroPoEv4TXlAukOOsyuHGnB5v3Wj1NkCp4rMaQOjqxSBRgqmhyEEp2w TkSU55OvvbRPTnnPDmRfv3Xvu+3lOe8GBmnovjgCnFZjKzPYSqSOMeOO3sC+qLFzPq8z 7GhI/FBP0G9deW3XKxNX2ZkV0+r8xD1zb4hmS/3yTvofeVt3I/E/RElIsMB7rgXf6jdg HK+DEIt52xVU6RWBuvpHdQr9kqjr4Ld8sSzPZuVlthoqpZiRVrUcVtXIW+T7VoRx8z1M zoqg== X-Received: by 10.60.116.164 with SMTP id jx4mr285498oeb.29.1371121379056; Thu, 13 Jun 2013 04:02:59 -0700 (PDT) Received: from slackpad.drs.calxeda.com (g224198135.adsl.alicedsl.de. [92.224.198.135]) by mx.google.com with ESMTPSA id b1sm38831288oeo.8.2013.06.13.04.02.56 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 04:02:58 -0700 (PDT) From: Andre Przywara To: trini@ti.com, albert.u.boot@aribaud.net, christoffer.dall@linaro.org Date: Thu, 13 Jun 2013 13:01:11 +0200 Message-Id: <1371121273-18763-6-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1371121273-18763-1-git-send-email-andre.przywara@linaro.org> References: <1371121273-18763-1-git-send-email-andre.przywara@linaro.org> X-Gm-Message-State: ALoCoQmNjsuy2TQQKIRVrmvF1OuBtRi3iCB0YApAYnMwURFtL4Xrr/DIpoBdoqaXte/qZV3bdx4K Cc: peter.maydell@linaro.org, geoff.levand@linaro.org, marc.zyngier@arm.com, agraf@suse.de, u-boot@lists.denx.de, kvmarm@lists.cs.columbia.edu Subject: [U-Boot] [PATCH v2 5/7] ARM: add SMP support for non-secure switch X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- 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 + 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; + + sysflags = (void *)CONFIG_SYSFLAGS_ADDR; +#ifdef CONFIG_SYSFLAGS_NEED_CLEAR_BITS + sysflags[1] = (unsigned)-1; +#endif + *sysflags = (uintptr_t)_smp_pen; + dmb(); + + /* now kick all CPUs (expect this one) by writing to GICD_SGIR */ + 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