From patchwork Fri Aug 9 15:03:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 18924 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DFE182391D for ; Fri, 9 Aug 2013 15:04:44 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id o19sf2339793qap.11 for ; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=2G9IMlSowV/3a/ITDEkNk4hB6K2o4rfr3Il6tP/d1yA=; b=IZ0aU/ROtde39gKMeqhisnXS+KUo/Gl7sDUk6hIeA0z0vnM1Z9c1C+i/1gLVwGOEYH ekQOHins0cNgI/XasfKHt8Nr0YAUp91VVKMMliIxrK/KtuV4hz7Gv5swpn6kw+sqpKFK BiPAkGNZb859aZR6Ouww+EZyKY2vCc4Ew+tC9aZ6wxZx40Zk2623yk18+9uKvm19xuVq 4IrzwodoiWIyWWLidNIn5K1tC5pX/ENEUvegHqGT6XujBD8LWiYzAkRctsS5Jr2m9ERQ xO2PJPsG5tQcLl/NVHOmM6yoNXcs2cvwjcDH6glmVCr1SAnBK9l8i3eN2mRIv7V/XTPi xNTA== X-Received: by 10.236.180.41 with SMTP id i29mr5505019yhm.1.1376060684700; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.96.9 with SMTP id do9ls1384419qeb.80.gmail; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) X-Received: by 10.220.145.132 with SMTP id d4mr631845vcv.9.1376060684550; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by mx.google.com with ESMTPS id cu1si4729578vcb.136.2013.08.09.08.04.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 08:04:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.41 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.41; Received: by mail-vb0-f41.google.com with SMTP id g17so4142796vbg.14 for ; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) X-Gm-Message-State: ALoCoQmB9tpy0L/Capa251XeOqlJaH2r9oZu7MHn+ygMtpXL3hlQRmJUqVjRndTv73qm8J3AHwFB X-Received: by 10.58.211.227 with SMTP id nf3mr650702vec.20.1376060684453; Fri, 09 Aug 2013 08:04:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp78361vcz; Fri, 9 Aug 2013 08:04:43 -0700 (PDT) X-Received: by 10.60.60.5 with SMTP id d5mr9040228oer.0.1376060683711; Fri, 09 Aug 2013 08:04:43 -0700 (PDT) Received: from mail-oa0-f54.google.com (mail-oa0-f54.google.com [209.85.219.54]) by mx.google.com with ESMTPS id s9si7566025oem.68.2013.08.09.08.04.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 08:04:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.219.54 is neither permitted nor denied by best guess record for domain of andre.przywara@linaro.org) client-ip=209.85.219.54; Received: by mail-oa0-f54.google.com with SMTP id o6so5101172oag.13 for ; Fri, 09 Aug 2013 08:04:43 -0700 (PDT) X-Received: by 10.182.104.36 with SMTP id gb4mr798849obb.43.1376060683423; Fri, 09 Aug 2013 08:04:43 -0700 (PDT) Received: from slackpad.drs.calxeda.com (f053081188.adsl.alicedsl.de. [78.53.81.188]) by mx.google.com with ESMTPSA id hm1sm19249781obb.9.2013.08.09.08.04.40 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 08:04:42 -0700 (PDT) From: Andre Przywara To: trini@ti.com, albert.u.boot@aribaud.net, christoffer.dall@linaro.org Cc: u-boot@lists.denx.de, marc.zyngier@arm.com, peter.maydell@linaro.org, geoff.levand@linaro.org, agraf@suse.de, kvmarm@lists.cs.columbia.edu, yamada.m@jp.panasonic.com, nicknickolaev@gmail.com, patches@linaro.org, Andre Przywara Subject: [PATCH v4 6/8] ARM: add SMP support for non-secure switch Date: Fri, 9 Aug 2013 17:03:10 +0200 Message-Id: <1376060592-10824-7-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1376060592-10824-1-git-send-email-andre.przywara@linaro.org> References: <1376060592-10824-1-git-send-email-andre.przywara@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: andre.przywara@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.41 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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. While this approach is pretty universal across several ARMv7 boards, we make this function weak in case someone needs to tweak this for a specific board. The way of setting the secondary's start address is board specific, so each supported board should implement smp_set_boot_cpu_addr(). Signed-off-by: Andre Przywara --- arch/arm/cpu/armv7/nonsec_virt.S | 22 ++++++++++++++++++++++ arch/arm/cpu/armv7/virt-v7.c | 16 +++++++++++++++- arch/arm/include/asm/armv7.h | 1 + arch/arm/include/asm/gic.h | 2 ++ include/common.h | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S index 81384df..a88fa6b 100644 --- a/arch/arm/cpu/armv7/nonsec_virt.S +++ b/arch/arm/cpu/armv7/nonsec_virt.S @@ -59,6 +59,28 @@ _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. + */ +ENTRY(_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, [r0, #GICC_IAR] @ acknowledge IPI + str r1, [r0, #GICC_EOIR] @ signal end of interrupt + + adr r0, _smp_pen @ do not use this address again + b smp_waitloop @ wait for IPIs, board specific +ENDPROC(_smp_pen) + +/* * Switch a core to non-secure state. * * 1. initialize the GIC per-core interface diff --git a/arch/arm/cpu/armv7/virt-v7.c b/arch/arm/cpu/armv7/virt-v7.c index 689023f..50f0a3a 100644 --- a/arch/arm/cpu/armv7/virt-v7.c +++ b/arch/arm/cpu/armv7/virt-v7.c @@ -79,6 +79,17 @@ static unsigned long get_gicd_base_address(void) #endif } +static void kick_secondary_cpus_gic(unsigned long gicdaddr) +{ + /* kick all CPUs (except this one) by writing to GICD_SGIR */ + writel(1U << 24, gicdaddr + GICD_SGIR); +} + +void __weak smp_kick_all_cpus(void) +{ + kick_secondary_cpus_gic(gic_dist_addr); +} + int armv7_switch_nonsec(void) { unsigned int reg; @@ -114,7 +125,10 @@ int armv7_switch_nonsec(void) for (i = 0; i <= itlinesnr; i++) writel((unsigned)-1, gic_dist_addr + GICD_IGROUPRn + 4 * i); - /* call the non-sec switching code on this CPU */ + smp_set_core_boot_addr((unsigned long)_smp_pen, -1); + smp_kick_all_cpus(); + + /* call the non-sec switching code on this CPU also */ _nonsec_init(); return 0; diff --git a/arch/arm/include/asm/armv7.h b/arch/arm/include/asm/armv7.h index 10ced11..06657fe 100644 --- a/arch/arm/include/asm/armv7.h +++ b/arch/arm/include/asm/armv7.h @@ -98,6 +98,7 @@ int armv7_switch_nonsec(void); /* defined in assembly file */ unsigned int _nonsec_init(void); +void _smp_pen(void); #endif /* CONFIG_ARMV7_NONSEC */ #endif /* ! __ASSEMBLY__ */ diff --git a/arch/arm/include/asm/gic.h b/arch/arm/include/asm/gic.h index c2b1e28..a0891cc 100644 --- a/arch/arm/include/asm/gic.h +++ b/arch/arm/include/asm/gic.h @@ -13,5 +13,7 @@ #define GIC_CPU_OFFSET_A15 0x2000 #define GICC_CTLR 0x0000 #define GICC_PMR 0x0004 +#define GICC_IAR 0x000C +#define GICC_EOIR 0x0010 #endif diff --git a/include/common.h b/include/common.h index e5220cf..05b30d7 100644 --- a/include/common.h +++ b/include/common.h @@ -642,6 +642,8 @@ void ft_pci_setup(void *blob, bd_t *bd); #endif #endif +void smp_set_core_boot_addr(unsigned long addr, int corenr); +void smp_kick_all_cpus(void); /* $(CPU)/serial.c */ int serial_init (void);