From patchwork Tue Aug 9 10:46:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 1048922 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p79Am7ds013789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 9 Aug 2011 10:48:27 GMT Received: from canuck.infradead.org ([134.117.69.58]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qqjqj-0004z3-Mg; Tue, 09 Aug 2011 10:47:54 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qqjqj-0004Iu-6s; Tue, 09 Aug 2011 10:47:53 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qqjq3-0004AF-SU for linux-arm-kernel@canuck.infradead.org; Tue, 09 Aug 2011 10:47:12 +0000 Received: from service87.mimecast.com ([94.185.240.25]) by casper.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qqjpz-0002lo-Eg for linux-arm-kernel@lists.infradead.org; Tue, 09 Aug 2011 10:47:10 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Tue, 09 Aug 2011 11:47:04 +0100 Received: from localhost.localdomain ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 9 Aug 2011 11:46:54 +0100 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org Subject: [RFC PATCH 01/12] ARM: local timers: allow smp_twd to be used standalone Date: Tue, 9 Aug 2011 11:46:43 +0100 Message-Id: <1312886814-15627-2-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1312886814-15627-1-git-send-email-marc.zyngier@arm.com> References: <1312886814-15627-1-git-send-email-marc.zyngier@arm.com> X-OriginalArrivalTime: 09 Aug 2011 10:46:54.0432 (UTC) FILETIME=[A74A0E00:01CC5681] X-MC-Unique: 111080911470400501 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110809_114707_716850_3DD7EDFF X-CRM114-Status: GOOD ( 15.53 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [94.185.240.25 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 09 Aug 2011 10:48:27 +0000 (UTC) Allow smp_twd to be built in a "standalone" version, without relying on the CONFIG_LOCAL_TIMER infrastructure. It mainly relies on a CPU notifier block to stop or start the timer on the right CPU. The CONFIG_ARM_SMP_TWD option selects the new behaviour. Signed-off-by: Marc Zyngier --- arch/arm/Kconfig | 6 +++- arch/arm/include/asm/smp_twd.h | 9 +++++ arch/arm/kernel/smp_twd.c | 76 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 2c71a8f..7ac28a3 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1394,6 +1394,10 @@ config HAVE_ARM_TWD help This options enables support for the ARM timer and watchdog unit +config ARM_SMP_TWD + bool + select HAVE_ARM_TWD if SMP + choice prompt "Memory split" default VMSPLIT_3G @@ -1432,7 +1436,7 @@ config HOTPLUG_CPU config LOCAL_TIMERS bool "Use local timer interrupts" - depends on SMP + depends on SMP && !ARM_SMP_TWD default y select HAVE_ARM_TWD if (!ARCH_MSM_SCORPIONMP && !EXYNOS4_MCT) help diff --git a/arch/arm/include/asm/smp_twd.h b/arch/arm/include/asm/smp_twd.h index ef9ffba..934f1bc 100644 --- a/arch/arm/include/asm/smp_twd.h +++ b/arch/arm/include/asm/smp_twd.h @@ -19,10 +19,19 @@ #define TWD_TIMER_CONTROL_IT_ENABLE (1 << 2) struct clock_event_device; +struct resource; extern void __iomem *twd_base; void twd_timer_setup(struct clock_event_device *); void twd_timer_stop(struct clock_event_device *); +#ifdef CONFIG_HAVE_ARM_TWD +int twd_timer_register(struct resource *res, int res_nr); +#else +static inline int twd_timer_register(struct resource *res, int res_nr) +{ + return 0; +} +#endif #endif diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c index 7156f09..5b6d99b 100644 --- a/arch/arm/kernel/smp_twd.c +++ b/arch/arm/kernel/smp_twd.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -135,7 +136,7 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) clk->name = "local_timer"; clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_C3STOP; - clk->rating = 350; + clk->rating = 450; /* Make sure this is higher than broadcast */ clk->set_mode = twd_set_mode; clk->set_next_event = twd_set_next_event; clk->shift = 20; @@ -150,3 +151,76 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk) pr_err("%s: can't register interrupt %d on cpu %d (%d)\n", clk->name, clk->irq, smp_processor_id(), err); } + +#ifdef CONFIG_ARM_SMP_TWD +static struct clock_event_device __percpu *twd_evt; +static int twd_ppi; + +static void __cpuinit twd_setup(void *data) +{ + struct clock_event_device *clk = data; + clk->cpumask = cpumask_of(smp_processor_id()); + clk->irq = twd_ppi; + twd_timer_setup(clk); +} + +static void __cpuinit twd_teardown(void *data) +{ + struct clock_event_device *clk = data; + twd_timer_stop(clk); +} + +static int __cpuinit twd_cpu_notify(struct notifier_block *self, + unsigned long action, void *data) +{ + int cpu = (int)data; + struct clock_event_device *clk = per_cpu_ptr(twd_evt, cpu); + + switch (action) { + case CPU_STARTING: + case CPU_STARTING_FROZEN: + smp_call_function_single(cpu, twd_setup, clk, 1); + break; + + case CPU_DOWN_PREPARE: + case CPU_DOWN_PREPARE_FROZEN: + smp_call_function_single(cpu, twd_teardown, clk, 1); + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block __cpuinitdata twd_cpu_nb = { + .notifier_call = twd_cpu_notify, +}; + +int twd_timer_register(struct resource *res, int res_nr) +{ + struct clock_event_device *clk; + + if (res_nr != 2 || res[1].start < 0) + return -EINVAL; + + if (twd_base) + return -EBUSY; + + twd_ppi = res[1].start; + twd_base = ioremap(res[0].start, resource_size(&res[0])); + twd_evt = alloc_percpu(struct clock_event_device); + if (!twd_base || !twd_evt) { + iounmap(twd_base); + twd_base = NULL; + free_percpu(twd_evt); + return -ENOMEM; + } + + /* Immediately configure the timer on the boot CPU */ + clk = per_cpu_ptr(twd_evt, smp_processor_id()); + twd_setup(clk); + + register_cpu_notifier(&twd_cpu_nb); + + return 0; +} +#endif