From patchwork Thu Jun 13 11:07:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 17906 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D09BF25DF1 for ; Thu, 13 Jun 2013 11:08:31 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id p12sf9443701vbe.11 for ; Thu, 13 Jun 2013 04:08:31 -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: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=mRR5NjfZNNZaDGPI3O/mrB8W0pr0yEOM5JrYUoOXKVc=; b=N1DkAowkbsUVo8lbC1fDxvmbBY3RPgr9iPhePCp/LiXSe+vViVszO7DzQMO91+bARH Et2FywZiGGFwCWgMEmttc1t6cFEhg+5iD2HZeNE4oQ2qsI/aSwfhWYjTQwqLvZ+NvF3Z XTyS9Wh2EaKy4MzTwc3Dn0wYuY1bagLqpmxPJ+tbKeDF4/1hy3EdoaXm642VQK+ooT6q x8O30+t5+B0dcQ+GY+VnVQul/bYWZ8nZWUWDt+e+tJJuP7MgP49zHkOc3UZ3lu5JHIct w/XGHDes1kkuqULzmnzz1RL+6YsmZagzuOhuforbw+z6z8XLoHwbr3A4Q5p5rmpjYtar 62Xg== X-Received: by 10.236.149.113 with SMTP id w77mr166642yhj.2.1371121711584; Thu, 13 Jun 2013 04:08:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.81.243 with SMTP id d19ls938062qey.2.gmail; Thu, 13 Jun 2013 04:08:31 -0700 (PDT) X-Received: by 10.52.183.170 with SMTP id en10mr128322vdc.5.1371121711464; Thu, 13 Jun 2013 04:08:31 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id cp2si9174475vcb.27.2013.06.13.04.08.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 04:08:31 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id hv10so6971019vcb.8 for ; Thu, 13 Jun 2013 04:08:31 -0700 (PDT) X-Received: by 10.221.21.74 with SMTP id qr10mr70011vcb.25.1371121711337; Thu, 13 Jun 2013 04:08:31 -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.58.191.99 with SMTP id gx3csp17026vec; Thu, 13 Jun 2013 04:08:30 -0700 (PDT) X-Received: by 10.60.63.52 with SMTP id d20mr229808oes.116.1371121710736; Thu, 13 Jun 2013 04:08:30 -0700 (PDT) Received: from mail-oa0-x229.google.com (mail-oa0-x229.google.com [2607:f8b0:4003:c02::229]) by mx.google.com with ESMTPS id mu7si19575938obc.136.2013.06.13.04.08.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 04:08:30 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:4003:c02::229 is neither permitted nor denied by best guess record for domain of andre.przywara@linaro.org) client-ip=2607:f8b0:4003:c02::229; Received: by mail-oa0-f41.google.com with SMTP id n10so4231202oag.0 for ; Thu, 13 Jun 2013 04:08:30 -0700 (PDT) X-Received: by 10.60.173.143 with SMTP id bk15mr261053oec.70.1371121710395; Thu, 13 Jun 2013 04:08:30 -0700 (PDT) Received: from slackpad.drs.calxeda.com (g224198135.adsl.alicedsl.de. [92.224.198.135]) by mx.google.com with ESMTPSA id eq4sm38120532obb.5.2013.06.13.04.08.29 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 04:08:30 -0700 (PDT) From: Andre Przywara To: patches@linaro.org Subject: [PATCH v2 5/7] ARM: add SMP support for non-secure switch Date: Thu, 13 Jun 2013 13:07:41 +0200 Message-Id: <1371121663-18810-6-git-send-email-andre.przywara@linaro.org> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1371121663-18810-1-git-send-email-andre.przywara@linaro.org> References: <1371121663-18810-1-git-send-email-andre.przywara@linaro.org> X-Gm-Message-State: ALoCoQm4K4HozKPbyLXFcjyuOYaLdlIFIdPS7a1WQ77ldi40Gu1g2CZEJkGeeABVetrG92VWKsd/ X-Original-Sender: andre.przywara@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 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/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