From patchwork Tue Jul 9 23:54:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 18296 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qe0-f71.google.com (mail-qe0-f71.google.com [209.85.128.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1CCBA25E71 for ; Tue, 9 Jul 2013 23:55:23 +0000 (UTC) Received: by mail-qe0-f71.google.com with SMTP id 1sf7716266qee.2 for ; Tue, 09 Jul 2013 16:55:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=A9spbyJhwOs6zsZstTM/tfbYSY/XkURb0fRF4RHZoqE=; b=pKQb5vSlhusJfvNiyPtiJ+YGrSDvQkPELIfSgICpLPWd9ueJxjC4eKfzrpGnaR8UCT 3SbN3OOr0Pr1kxrOjcZqEV+ocuNxBf0YrCBsJTDcBN2CTIiPT1pXBjEmqWRU+7ihTMY+ 5MAHcNTcC3r+A1OqvbjYn4ZyJ/uT6q0icMoHlGqLtcsioL0tPq/TKWL/mfl9xCvA4Yxs VvPQUBarUihnVRLICNce6PoOPYolEXkTipW/Vk5pyAdwWqQN3+m8gGzGIawaV6BVANJG k+Z2MQhxDi5egFBqNQj3JISGdXYjlk60jmB82VoimlRTAhmfDTleZuK59j0gQw2I2bjA eWIw== X-Received: by 10.236.20.83 with SMTP id o59mr15664562yho.28.1373414122865; Tue, 09 Jul 2013 16:55:22 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.50.10 with SMTP id y10ls2370115qen.69.gmail; Tue, 09 Jul 2013 16:55:22 -0700 (PDT) X-Received: by 10.58.224.102 with SMTP id rb6mr17494349vec.43.1373414122718; Tue, 09 Jul 2013 16:55:22 -0700 (PDT) Received: from mail-vb0-f52.google.com (mail-vb0-f52.google.com [209.85.212.52]) by mx.google.com with ESMTPS id u4si8433027ven.124.2013.07.09.16.55.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:22 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.52 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.52; Received: by mail-vb0-f52.google.com with SMTP id f12so4948927vbg.11 for ; Tue, 09 Jul 2013 16:55:22 -0700 (PDT) X-Received: by 10.58.128.71 with SMTP id nm7mr2093997veb.51.1373414122431; Tue, 09 Jul 2013 16:55:22 -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.149.77 with SMTP id s13csp57408vcv; Tue, 9 Jul 2013 16:55:21 -0700 (PDT) X-Received: by 10.194.87.9 with SMTP id t9mr10774443wjz.39.1373414121386; Tue, 09 Jul 2013 16:55:21 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mx.google.com with ESMTPS id n9si9388430wic.10.2013.07.09.16.55.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:21 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.181 is neither permitted nor denied by best guess record for domain of andre.przywara@linaro.org) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id hq4so5710641wib.14 for ; Tue, 09 Jul 2013 16:55:20 -0700 (PDT) X-Received: by 10.194.242.134 with SMTP id wq6mr16026790wjc.94.1373414120629; Tue, 09 Jul 2013 16:55:20 -0700 (PDT) Received: from localhost.localdomain ([193.120.41.118]) by mx.google.com with ESMTPSA id fs8sm64073738wib.0.2013.07.09.16.55.19 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Jul 2013 16:55:19 -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 Subject: [PATCH v3 5/7] ARM: add SMP support for non-secure switch Date: Wed, 10 Jul 2013 01:54:17 +0200 Message-Id: <1373414059-22779-6-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1373414059-22779-1-git-send-email-andre.przywara@linaro.org> References: <1373414059-22779-1-git-send-email-andre.przywara@linaro.org> X-Gm-Message-State: ALoCoQn7RAcxn2E0RqtVlQXQkdtVP6nuPChchjV1LZC2mK1/noneaCGeGh9gzjc2f9VzdjAKjQ6P X-Original-Sender: andre.przywara@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.52 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. 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/cpu/armv7/virt-v7.c | 19 ++++++++++++++++++- arch/arm/include/asm/armv7.h | 1 + arch/arm/include/asm/gic.h | 2 ++ include/configs/vexpress_ca15_tc2.h | 3 +++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S index e9ee831..f9b6b39 100644 --- a/arch/arm/cpu/armv7/nonsec_virt.S +++ b/arch/arm/cpu/armv7/nonsec_virt.S @@ -58,6 +58,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. + */ +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 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 +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 54f9746..a0d0b34 100644 --- a/arch/arm/cpu/armv7/virt-v7.c +++ b/arch/arm/cpu/armv7/virt-v7.c @@ -77,6 +77,21 @@ static int get_gicd_base_address(unsigned int *gicdaddr) #endif } +static void kick_secondary_cpus(unsigned int gicdaddr) +{ + unsigned int *secondary_boot_addr; + + secondary_boot_addr = (void *)CONFIG_SYSFLAGS_ADDR; +#ifdef CONFIG_SYSFLAGS_NEED_CLEAR_BITS + secondary_boot_addr[1] = (unsigned)-1; +#endif + *secondary_boot_addr = (uintptr_t)_smp_pen; + dmb(); + + /* now kick all CPUs (except this one) by writing to GICD_SGIR */ + writel(1U << 24, gicdaddr + GICD_SGIR); +} + enum nonsec_virt_errors armv7_switch_nonsec(void) { unsigned int reg, ret; @@ -110,7 +125,9 @@ enum nonsec_virt_errors armv7_switch_nonsec(void) for (i = 0; i <= itlinesnr; i++) writel((unsigned)-1, gicdaddr + GICD_IGROUPRn + 4 * i); - /* call the non-sec switching code on this CPU */ + kick_secondary_cpus(gicdaddr); + + /* call the non-sec switching code on this CPU also */ _nonsec_init(); return NONSEC_VIRT_SUCCESS; diff --git a/arch/arm/include/asm/armv7.h b/arch/arm/include/asm/armv7.h index e5c0279..f6582a1 100644 --- a/arch/arm/include/asm/armv7.h +++ b/arch/arm/include/asm/armv7.h @@ -102,6 +102,7 @@ enum nonsec_virt_errors 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/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