From patchwork Thu Aug 14 11:15:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 4723761 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 87A859F377 for ; Thu, 14 Aug 2014 11:18:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6338A201D5 for ; Thu, 14 Aug 2014 11:18:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (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 394A9200E5 for ; Thu, 14 Aug 2014 11:18:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XHt1Q-0000o3-Vb; Thu, 14 Aug 2014 11:16:44 +0000 Received: from mail-wi0-f180.google.com ([209.85.212.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XHt1E-0000fm-4o for linux-arm-kernel@lists.infradead.org; Thu, 14 Aug 2014 11:16:33 +0000 Received: by mail-wi0-f180.google.com with SMTP id n3so2112314wiv.13 for ; Thu, 14 Aug 2014 04:16:06 -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=SU6Zkes9uCNuiqnb+TTq5j7l41AEvPHE+uF+8TL9m+8=; b=OPNgDJXRXCvwLfDQIrx0TgxwL4gqnX+STVL7Lf/r0OizCSJMRs9+7TBB/aZMtM99Bz EpXG9n2ZwZhqgzmaCXVdYjTukFJ0LUvRhwJ49FE0DWlRUv5Uz7f8zY5WP2gAURZaraOj VvaBnd1fKN9gwFihY+riwRLHZYoYmHqt2P5jehZ+4CSYHfjGZKqM7Xw51fQ1HRF6U+re peRGjiC73pzzzRujBYB1unIkZO0ZrC4pd1p0KygxSpJvEmMbsuo1on2StqUNyEd+12b9 Rm2SbLgtnTgab8IHLlo78k/9fuFzub3kmfMaOjh0c80Nh3GWFo4YL2UP9jfX9Qzm6mRR eujA== X-Gm-Message-State: ALoCoQmRcyRCyKX5O4ArJKrhk3dFAuiUQ9ImjN/pKPK6g0UDOzbCwqPHi9cKi8Z0r2qPhqqEo/u4 X-Received: by 10.194.205.70 with SMTP id le6mr10862354wjc.25.1408014966589; Thu, 14 Aug 2014 04:16:06 -0700 (PDT) Received: from sundance.lan (cpc4-aztw19-0-0-cust157.18-1.cable.virginm.net. [82.33.25.158]) by mx.google.com with ESMTPSA id gb5sm18966593wib.8.2014.08.14.04.16.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Aug 2014 04:16:05 -0700 (PDT) From: Daniel Thompson To: Russell King Subject: [RFC PATCH 3/3] irqchip: gic: Add support for IPI FIQ Date: Thu, 14 Aug 2014 12:15:51 +0100 Message-Id: <1408014951-24820-4-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1408014951-24820-1-git-send-email-daniel.thompson@linaro.org> References: <53EC9404.5010908@linaro.org> <1408014951-24820-1-git-send-email-daniel.thompson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140814_041632_523082_7A43E60C X-CRM114-Status: GOOD ( 28.40 ) X-Spam-Score: -0.7 (/) Cc: Daniel Thompson , linaro-kernel@lists.linaro.org, Catalin Marinas , patches@linaro.org, kgdb-bugreport@lists.sourceforge.net, Linus Walleij , Nicolas Pitre , linux-kernel@vger.kernel.org, Frederic Weisbecker , Anton Vorontsov , Ben Dooks , John Stultz , Fabio Estevam , Colin Cross , kernel-team@android.com, Dave Martin , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, 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 To support IPI FIQ we alter gic_cpu_init() to honour SMP_IPI_FIQ_MASK and register a fairly high priority notifier to acknowledge and clear the IPI when it is triggered. For the IPI FIQ to be useful we must also make it safe to call gic_raise_softirq() from the FIQ handler by altering the locking strategy slightly. Signed-off-by: Daniel Thompson --- drivers/irqchip/irq-gic.c | 126 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 19 deletions(-) diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index d928912..240cc87 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #ifdef CONFIG_FIQ @@ -51,6 +52,10 @@ #include "irq-gic-common.h" #include "irqchip.h" +#ifndef SMP_IPI_FIQ_MASK +#define SMP_IPI_FIQ_MASK 0 +#endif + union gic_base { void __iomem *common_base; void __percpu * __iomem *percpu_base; @@ -77,6 +82,8 @@ struct gic_chip_data { }; static DEFINE_RAW_SPINLOCK(irq_controller_lock); +/* A fiq-safe spinlock must only be locked when the FIQ is masked */ +static DEFINE_RAW_SPINLOCK(fiq_safe_migration_lock); /* * The GIC mapping of CPU interfaces does not necessarily match @@ -346,20 +353,21 @@ static struct irq_chip gic_chip = { * match what "ARM strongly recommends" for a system where no Group 1 * interrupt must ever preempt a Group 0 interrupt. */ -static void gic_set_group_irq(struct irq_data *d, int group) +static void gic_set_group_irq(void __iomem *base, unsigned int hwirq, + int group) { - unsigned int grp_reg = gic_irq(d) / 32 * 4; - u32 grp_mask = 1 << (gic_irq(d) % 32); + unsigned int grp_reg = hwirq / 32 * 4; + u32 grp_mask = 1 << (hwirq % 32); u32 grp_val; - unsigned int pri_reg = (gic_irq(d) / 4) * 4; - u32 pri_mask = 1 << (7 + ((gic_irq(d) % 4) * 8)); + unsigned int pri_reg = (hwirq / 4) * 4; + u32 pri_mask = 1 << (7 + ((hwirq % 4) * 8)); u32 pri_val; raw_spin_lock(&irq_controller_lock); - grp_val = readl_relaxed(gic_dist_base(d) + GIC_DIST_IGROUP + grp_reg); - pri_val = readl_relaxed(gic_dist_base(d) + GIC_DIST_PRI + pri_reg); + grp_val = readl_relaxed(base + GIC_DIST_IGROUP + grp_reg); + pri_val = readl_relaxed(base + GIC_DIST_PRI + pri_reg); if (group) { grp_val |= grp_mask; @@ -369,20 +377,20 @@ static void gic_set_group_irq(struct irq_data *d, int group) pri_val &= ~pri_mask; } - writel_relaxed(grp_val, gic_dist_base(d) + GIC_DIST_IGROUP + grp_reg); - writel_relaxed(pri_val, gic_dist_base(d) + GIC_DIST_PRI + pri_reg); + writel_relaxed(grp_val, base + GIC_DIST_IGROUP + grp_reg); + writel_relaxed(pri_val, base + GIC_DIST_PRI + pri_reg); raw_spin_unlock(&irq_controller_lock); } static void gic_enable_fiq(struct irq_data *d) { - gic_set_group_irq(d, 0); + gic_set_group_irq(gic_dist_base(d), gic_irq(d), 0); } static void gic_disable_fiq(struct irq_data *d) { - gic_set_group_irq(d, 1); + gic_set_group_irq(gic_dist_base(d), gic_irq(d), 1); } static int gic_ack_fiq(struct irq_data *d) @@ -430,7 +438,63 @@ static void __init gic_init_fiq(struct gic_chip_data *gic, for (i = 0; i < num_irqs; i++) fiq_register_mapping(first_irq + i, &gic_fiq); } + +/* + * Fully acknowledge (both ack and eoi) a FIQ-based IPI + */ +static int gic_eoi_fiq_ipi(struct notifier_block *nb, unsigned long expected, + void *data) +{ + struct gic_chip_data *gic = &gic_data[0]; + void __iomem *cpu_base = gic_data_cpu_base(gic); + unsigned long irqstat, irqnr, last_irqnr; + + if (WARN_ON(!in_nmi())) + return NOTIFY_BAD; + + irqnr = -1; + do { + irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); + writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); + + last_irqnr = irqnr; + irqnr = irqstat & GICC_IAR_INT_ID_MASK; + if (likely(irqnr == expected)) + return NOTIFY_OK; + + /* We're in pretty serious trouble if we get here. We cannot + * safely call the handler for the unexpected interrupt either + * because we don't know how (if it is a FIQ) or we can't do so + * safely (if it is an IRQ). The only recovery possible is to + * spuriously EOI (which we've already done by this point) and + * hope this is sufficient to clear the spurious FIQ. + */ + WARN_RATELIMIT(1, "Unexpected irqnr %lu (expected %lu)\n", + irqnr, expected); + } while (last_irqnr != irqnr); + + /* We've become stuck EOIing the same interrupt. There's nothing + * more we can do here except hope that "something has changed" and + * that the FIQ handler doesn't re-enter. + * + * We ratelimit the message because expecting something to change + * is really quite optimistic. + */ + pr_crit_ratelimited("gic_eoi_fiq_ipi: Stuck on %lu, giving up\n", + irqnr); + return NOTIFY_BAD; +} + +/* + * Notifier to ensure IPI FIQ is acknowledged correctly. + */ +static struct notifier_block gic_fiq_ipi_notifier = { + .notifier_call = gic_eoi_fiq_ipi, + .priority = 100, +}; #else /* CONFIG_FIQ */ +static inline void gic_set_group_irq(void __iomem *base, unsigned int hwirq, + int group) {} static inline void gic_init_fiq(struct gic_chip_data *gic, irq_hw_number_t first_irq, unsigned int num_irqs) {} @@ -508,6 +572,7 @@ static void gic_cpu_init(struct gic_chip_data *gic) void __iomem *base = gic_data_cpu_base(gic); unsigned int cpu_mask, cpu = smp_processor_id(); int i; + u32 val; /* * Get what the GIC says our CPU mask is. @@ -527,14 +592,19 @@ static void gic_cpu_init(struct gic_chip_data *gic) gic_cpu_config(dist_base, NULL); /* - * Set all PPI and SGI interrupts to be group 1. - * - * If grouping is not available (not implemented or prohibited by - * security mode) these registers are read-as-zero/write-ignored. + * Optionally set all PPI and SGI interrupts to be group 1. */ if (gic_data_fiq_enable(gic)) writel_relaxed(0xffffffff, dist_base + GIC_DIST_IGROUP + 0); + /* + * Optionally shift the FIQ based IPIs to group 0. + */ + if (gic_data_fiq_enable(gic)) + for (i = 0; i < 16; i++) + if (SMP_IPI_FIQ_MASK & (1 << i)) + gic_set_group_irq(dist_base, i, 0); + writel_relaxed(0xf0, base + GIC_CPU_PRIMASK); if (gic_data_fiq_enable(gic)) writel_relaxed(0x1f, base + GIC_CPU_CTRL); @@ -747,7 +817,17 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) unsigned long flags, map = 0; unsigned long softint; - raw_spin_lock_irqsave(&irq_controller_lock, flags); + /* + * The locking in this function ensures we don't use stale cpu mappings + * and thus we never route an IPI to the wrong physical core during a + * big.LITTLE switch. The switch code takes both of these locks meaning + * we can choose whichever lock is safe to use from our current calling + * context. + */ + if (in_nmi()) + raw_spin_lock(&fiq_safe_migration_lock); + else + raw_spin_lock_irqsave(&irq_controller_lock, flags); /* Convert our logical CPU mask into a physical one. */ for_each_cpu(cpu, mask) @@ -761,12 +841,16 @@ static void gic_raise_softirq(const struct cpumask *mask, unsigned int irq) /* this always happens on GIC0 */ softint = map << 16 | irq; - if (gic_data_fiq_enable(&gic_data[0])) + if (gic_data_fiq_enable(&gic_data[0]) && + !(SMP_IPI_FIQ_MASK & (1 << irq))) softint |= 0x8000; writel_relaxed(softint, gic_data_dist_base(&gic_data[0]) + GIC_DIST_SOFTINT); - raw_spin_unlock_irqrestore(&irq_controller_lock, flags); + if (in_nmi()) + raw_spin_unlock(&fiq_safe_migration_lock); + else + raw_spin_unlock_irqrestore(&irq_controller_lock, flags); } #endif @@ -814,7 +898,7 @@ int gic_get_cpu_id(unsigned int cpu) * Migrate all peripheral interrupts with a target matching the current CPU * to the interface corresponding to @new_cpu_id. The CPU interface mapping * is also updated. Targets to other CPU interfaces are unchanged. - * This must be called with IRQs locally disabled. + * This must be called with IRQ and FIQ locally disabled. */ void gic_migrate_target(unsigned int new_cpu_id) { @@ -836,6 +920,7 @@ void gic_migrate_target(unsigned int new_cpu_id) ror_val = (cur_cpu_id - new_cpu_id) & 31; raw_spin_lock(&irq_controller_lock); + raw_spin_lock(&fiq_safe_migration_lock); /* Update the target interface for this logical CPU */ gic_cpu_map[cpu] = 1 << new_cpu_id; @@ -855,6 +940,7 @@ void gic_migrate_target(unsigned int new_cpu_id) } } + raw_spin_unlock(&fiq_safe_migration_lock); raw_spin_unlock(&irq_controller_lock); /* @@ -1125,6 +1211,8 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start, #ifdef CONFIG_SMP set_smp_cross_call(gic_raise_softirq); register_cpu_notifier(&gic_cpu_notifier); + if (gic_data_fiq_enable(gic)) + register_fiq_ipi_notifier(&gic_fiq_ipi_notifier); #endif set_handle_irq(gic_handle_irq); }