From patchwork Fri Mar 28 21:12:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 3907421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A4EB49F334 for ; Fri, 28 Mar 2014 21:14:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C30ED20256 for ; Fri, 28 Mar 2014 21:14:04 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 999B0200DF for ; Fri, 28 Mar 2014 21:14:03 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WTe5n-0006lu-ID; Fri, 28 Mar 2014 21:13:35 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WTe5e-0004Pi-Jd; Fri, 28 Mar 2014 21:13:26 +0000 Received: from mail-ie0-f182.google.com ([209.85.223.182]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WTe5K-0004M3-3o for linux-arm-kernel@lists.infradead.org; Fri, 28 Mar 2014 21:13:07 +0000 Received: by mail-ie0-f182.google.com with SMTP id y20so5487815ier.41 for ; Fri, 28 Mar 2014 14:12:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Xj/SRehvFChQBuz1rdm/8mFloOAyG+LIg6ic+nzn2jg=; b=GJ2apIlilefFWQ30yn+Dom0l2W2P1Sq9g22ZUpDgUwl+ug8PmyBSFTTas4dkrVSZ7a HD3i7cE/sOy5JYmX/kSg5uBb7LWgpfsKfaBTyzbesD0jmHKXYzy8XVV0igYiJ1AesB4D EH6aAXc89Mdj4mdWz2rf5HWus60dV8MhmAtDQTUPmoO/IPGJ5DkuhtD187jThPl06IpM ihhbaMUxVkzt3Uc3FHsjEKTUQpmgn4bkmTvBw0RVNu+YKGz05O+/+9yz/cPc/DTdFXWJ 9Hx3MJ+hJbMkL752v2peBJrrovOg3abmkD81IF6BOptk4px8sKOdhIg+WDbNfrag8nBG jKbg== X-Gm-Message-State: ALoCoQmq+IBIT8Kbm1fcs8GrDV4phsfSSH/QKk2PaTrHGigUazIwdK25NN6z6iTpRq+C1EsVPuYe X-Received: by 10.42.88.79 with SMTP id b15mr3394533icm.65.1396041165041; Fri, 28 Mar 2014 14:12:45 -0700 (PDT) Received: from localhost.localdomain (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id t1sm7139024igw.16.2014.03.28.14.12.43 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 14:12:44 -0700 (PDT) From: Alex Elder To: linux@arm.linux.org.uk, linus.walleij@linaro.org, viresh.linux@gmail.com, shiraz.hashim@gmail.com, catalin.marinas@arm.com Subject: [RFC PATCH 2/7] ARM: SMP: generic SMP spin-table method routines Date: Fri, 28 Mar 2014 16:12:55 -0500 Message-Id: <1396041180-29897-3-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1396041180-29897-1-git-send-email-elder@linaro.org> References: <1396041180-29897-1-git-send-email-elder@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140328_171306_243110_08B06D0E X-CRM114-Status: GOOD ( 20.50 ) X-Spam-Score: -2.6 (--) Cc: devicetree@vger.kernel.org, spear-devel@list.st.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implement a centralized version of the spin table (a.k.a. "holding pen") method of secondary CPU initialization. This is the first step in removing a number of duplicate implementations of this code. The eventual goal is to allow "enable-method" properties in device tree nodes for CPUs to select and use this common code. As such, some of the names are selected to match the names used in the SMP spin-table code for ARM64. Note: Most implementations examine only the bottom 4 bits of the MPIDR in order to determine a CPU's id. This version looks at the bottom 24 bits instead, based on MPIDR_HWID_BITMASK. If using only 4 bits is a requirement for most of the platforms that might use it I'll switch this use 4 bits instead. Signed-off-by: Alex Elder --- arch/arm/include/asm/smp.h | 5 +++ arch/arm/kernel/head.S | 33 +++++++++++++++++++ arch/arm/kernel/smp.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h index 22a3b9b..83064d1 100644 --- a/arch/arm/include/asm/smp.h +++ b/arch/arm/include/asm/smp.h @@ -75,6 +75,11 @@ struct secondary_data { extern struct secondary_data secondary_data; extern volatile int pen_release; +extern volatile u32 secondary_holding_pen_release; +extern void secondary_holding_pen(void); +extern int smp_boot_secondary(unsigned int cpu, struct task_struct *idle); +extern void smp_secondary_init(unsigned int cpu); + extern int __cpu_disable(void); extern void __cpu_die(unsigned int cpu); diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index f5f381d..3340f94 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -22,6 +22,7 @@ #include #include #include +#include #if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_SEMIHOSTING) #include CONFIG_DEBUG_LL_INCLUDE @@ -402,6 +403,38 @@ __secondary_data: .long . .long secondary_data .long __secondary_switched + + + /* + * Secondary cores spin in this "holding pen" until they are + * signaled to proceed by jumping to secondary_startup + * (above). A core knows to proceed when it finds that the + * value of the secondary_holding_pen_release global matches + * its (hardware) CPU ID. The secondary core acknowledges + * it has begun executing by writing an invalid value (-1) + * back into secondary_holding_pen_release (in + * smp_operations->smp_secondary_init). + */ +ENTRY(secondary_holding_pen) + ARM_BE8(setend be) + mrc p15, 0, r0, c0, c0, 5 @ Get MPIDR and extract CPU id from it + and r0, r0, #MPIDR_HWID_BITMASK + adr r4, 1f @ Get secondary_holding_pen_release + ldmia r4, {r5, r6} @ and compute its physical address + sub r4, r4, r5 + add r6, r6, r4 +pen: ldr r7, [r6] @ while secondary_holding_pen_release + cmp r7, r0 @ doesn't hold our CPU id, spin + bne pen + /* + * At this point we have been released from the holding pen; + * secondary_stack now contains the SVC stack for this core. + */ + b secondary_startup +ENDPROC(secondary_holding_pen) + .align +1: .long . + .long secondary_holding_pen_release #endif /* defined(CONFIG_SMP) */ diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index b7b4c86..e18151a 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -59,6 +59,8 @@ struct secondary_data secondary_data; * boot "holding pen" */ volatile int pen_release = -1; +volatile u32 secondary_holding_pen_release = -1; +static DEFINE_RAW_SPINLOCK(boot_lock); enum ipi_msg_type { IPI_WAKEUP, @@ -386,6 +388,81 @@ asmlinkage void secondary_start_kernel(void) cpu_startup_entry(CPUHP_ONLINE); } +static void write_pen_release(int val) +{ + secondary_holding_pen_release = val; + smp_wmb(); + sync_cache_w(&secondary_holding_pen_release); +} + +/* + * This is a smp_operations->smp_boot_secondary function, called by + * boot_secondary() to signal a secondary core spinning in + * secondary_holding_pen() that it should proceed. The current + * (boot) core writes the secondary's (hardware) CPU ID into + * secondary_holding_pen_release. The secondary core signals it has + * started running by rewriting an invalid value (-1) back + * into secondary_holding_pen_release. + */ +int smp_boot_secondary(unsigned int cpu, struct task_struct *idle) +{ + unsigned long timeout; + + /* + * The secondary core will wait for this lock after + * signaling it has started. That way we know it won't + * proceed until we've recognized the acknowledgement. + */ + raw_spin_lock(&boot_lock); + + /* + * Release the secondary core from its holding pen by + * writing its CPU ID into secondary_holding_pen_release. + */ + write_pen_release(cpu_logical_map(cpu)); + + /* + * Send the secondary CPU a soft interrupt, thereby causing + * it to jump to its secondary entry point. + */ + arch_send_wakeup_ipi_mask(cpumask_of(cpu)); + + /* Give it some time to start running. */ + timeout = jiffies + (1 * HZ); + while (time_before(jiffies, timeout)) { + smp_rmb(); + if (secondary_holding_pen_release == -1) + break; + + udelay(10); + } + + /* + * We now know that the secondary core is running (or it + * timed out). Release the lock so it can proceed. + */ + raw_spin_unlock(&boot_lock); + + return secondary_holding_pen_release == -1 ? 0 : -ENOSYS; +} + +/* + * This is a smp_operations->secondary_init function, called by + * secondary_start_kernel() on a newly-booted secondary cpu to do + * some initialization activity. All we need to do is write + * secondary_holding_pen_release with an invalid value to signal + * we've started executing. We synchronize with the boot core by + * waiting to acquire the boot lock before continuing. + */ +void smp_secondary_init(unsigned int cpu) +{ + /* Let the primary processor know we're out of the pen. */ + write_pen_release(-1); + + raw_spin_lock(&boot_lock); + raw_spin_unlock(&boot_lock); +} + void __init smp_cpus_done(unsigned int max_cpus) { printk(KERN_INFO "SMP: Total of %d processors activated.\n",