From patchwork Tue Jan 13 16:35:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 43067 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1153120DE8 for ; Tue, 13 Jan 2015 16:36:06 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf2281036lbv.1 for ; Tue, 13 Jan 2015 08:36:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=M55j9nKNXs9eHJ0838d4vtyQN1fgv6J93S5mzP6Qxag=; b=B9wfJzMYuOih4iCVhYWOx5tyEnIuC7On5zqPMAlC5RVHeJqD2cL/Q7ab0PGkJBDl7k YgCW56B1wIRvoCK95Z9M3bdII9s2GQgn5DnmIGdkoTJ7dIoWhtfzcQCHK/QHWIailqhR GgeaJrGwweFeOHvgfqekmYsRaVlhvbkIbXrAokyBz32tkBvPINP9hmogZRzJzYCXTw7f Sk/uaqNnciWDH+tqpwaZUmWrbB8mJhHB2CQE4HmXWOknRE4YxZ1lt+a8zEAMfvQC4kUT Fxk1s4CKBWDFXQ6p33oQpWVvf03p7FylaCSRcY0Uj2rk3f+wIUxEKGLUOThsZuE2eHKj 3rHg== X-Gm-Message-State: ALoCoQmxlnsXxUgOb5vnw/ATrTWaJIZY36wNqvh8z3SNzPUQgdnp6SO6bGuT6VwvqBCKMBcvKrQA X-Received: by 10.112.64.197 with SMTP id q5mr176018lbs.4.1421166964721; Tue, 13 Jan 2015 08:36:04 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.34 with SMTP id cr2ls18622lad.30.gmail; Tue, 13 Jan 2015 08:36:04 -0800 (PST) X-Received: by 10.112.89.232 with SMTP id br8mr43256614lbb.69.1421166964580; Tue, 13 Jan 2015 08:36:04 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id qg8si24656797lbb.139.2015.01.13.08.36.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 08:36:04 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id hv19so3598741lab.0 for ; Tue, 13 Jan 2015 08:36:04 -0800 (PST) X-Received: by 10.112.98.99 with SMTP id eh3mr42742613lbb.32.1421166964490; Tue, 13 Jan 2015 08:36:04 -0800 (PST) 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.112.9.200 with SMTP id c8csp1435397lbb; Tue, 13 Jan 2015 08:36:03 -0800 (PST) X-Received: by 10.194.192.167 with SMTP id hh7mr30715474wjc.111.1421166959492; Tue, 13 Jan 2015 08:35:59 -0800 (PST) Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com. [74.125.82.46]) by mx.google.com with ESMTPS id b9si21035926wix.89.2015.01.13.08.35.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 08:35:59 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 74.125.82.46 as permitted sender) client-ip=74.125.82.46; Received: by mail-wg0-f46.google.com with SMTP id x13so4005340wgg.5 for ; Tue, 13 Jan 2015 08:35:59 -0800 (PST) X-Received: by 10.194.62.76 with SMTP id w12mr41291264wjr.5.1421166959205; Tue, 13 Jan 2015 08:35:59 -0800 (PST) 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 q10sm26349181wjx.34.2015.01.13.08.35.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jan 2015 08:35:58 -0800 (PST) From: Daniel Thompson To: Thomas Gleixner , Jason Cooper , Russell King Cc: Daniel Thompson , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, patches@linaro.org, linaro-kernel@lists.linaro.org, John Stultz , Sumit Semwal , Dirk Behme , Daniel Drake , Dmitry Pervushin , Tim Sander , Stephen Boyd Subject: [RFC PATCH 3/5] irq: gic: Add support for NMI routing Date: Tue, 13 Jan 2015 16:35:29 +0000 Message-Id: <1421166931-14134-4-git-send-email-daniel.thompson@linaro.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1421166931-14134-1-git-send-email-daniel.thompson@linaro.org> References: <1421166931-14134-1-git-send-email-daniel.thompson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.thompson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) 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: , This patch provides an implementation of irq_set_nmi_routing by allowing SPIs to be switched between group 1 (IRQ) and group 0 (FIQ). It also repaces the interface used between the default FIQ handler and the GIC. These extensions are required in order to allow SPIs to be acknowledged and completed. Signed-off-by: Daniel Thompson --- arch/arm/kernel/traps.c | 12 ++++--- drivers/irqchip/irq-gic.c | 75 ++++++++++++++++++++++++++++++----------- include/linux/irqchip/arm-gic.h | 8 ++++- 3 files changed, 71 insertions(+), 24 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 5645f81ac4cc..74c752b9db68 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -478,17 +478,21 @@ asmlinkage void __exception_irq_entry handle_fiq_as_nmi(struct pt_regs *regs) { unsigned int cpu = smp_processor_id(); struct pt_regs *old_regs = set_irq_regs(regs); + int irq = 0; __inc_irq_stat(cpu, __nmi_count); nmi_enter(); + irq = gic_ack_fiq(); -#ifdef CONFIG_ARM_GIC - gic_handle_fiq_ipi(); -#endif + if (irq) { + /* empty - no SPI handlers (yet) */ + } else { #ifdef CONFIG_SMP - ipi_cpu_backtrace(regs); + ipi_cpu_backtrace(regs); #endif + } + gic_eoi_fiq(); nmi_exit(); set_irq_regs(old_regs); diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index c4f4a8827ed8..7c212b3126b8 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -129,6 +129,9 @@ struct irq_chip gic_arch_extn = { static struct gic_chip_data gic_data[MAX_GIC_NR] __read_mostly; +static int gic_set_group_irq(struct gic_chip_data *gic, unsigned int hwirq, + int group); + #ifdef CONFIG_GIC_NON_BANKED static void __iomem *gic_get_percpu_base(union gic_base *base) { @@ -214,6 +217,18 @@ static void gic_eoi_irq(struct irq_data *d) writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); } +static int gic_set_nmi_routing(struct irq_data *d, unsigned int nmi) +{ + struct gic_chip_data *gic = irq_data_get_irq_chip_data(d); + int ret; + + ret = gic_set_group_irq(gic, gic_irq(d), !nmi); + if (ret >= 0) + ret = !ret; + + return ret; +} + static int gic_set_type(struct irq_data *d, unsigned int type) { void __iomem *base = gic_dist_base(d); @@ -346,6 +361,7 @@ static struct irq_chip gic_chip = { .irq_mask = gic_mask_irq, .irq_unmask = gic_unmask_irq, .irq_eoi = gic_eoi_irq, + .irq_set_nmi_routing = gic_set_nmi_routing, .irq_set_type = gic_set_type, .irq_retrigger = gic_retrigger, #ifdef CONFIG_SMP @@ -364,8 +380,8 @@ static struct irq_chip gic_chip = { * If is safe to call this function on systems which do not support * grouping (it will have no effect). */ -static void gic_set_group_irq(struct gic_chip_data *gic, unsigned int hwirq, - int group) +static int gic_set_group_irq(struct gic_chip_data *gic, unsigned int hwirq, + int group) { void __iomem *base = gic_data_dist_base(gic); unsigned int grp_reg = hwirq / 32 * 4; @@ -381,7 +397,7 @@ static void gic_set_group_irq(struct gic_chip_data *gic, unsigned int hwirq, * the EnableGrp1 bit set. */ if (!(GICD_ENABLE_GRP1 & readl_relaxed(base + GIC_DIST_CTRL))) - return; + return -EINVAL; raw_spin_lock(&irq_controller_lock); @@ -403,32 +419,53 @@ static void gic_set_group_irq(struct gic_chip_data *gic, unsigned int hwirq, writel_relaxed(pri_val, base + GIC_DIST_PRI + pri_reg); raw_spin_unlock(&irq_controller_lock); + + return group; } -/* - * Fully acknowledge (both ack and eoi) any outstanding FIQ-based IPI, - * otherwise do nothing. - */ -void gic_handle_fiq_ipi(void) +static DEFINE_PER_CPU(unsigned long, gic_irqstat_fiq); + +int gic_ack_fiq(void) { struct gic_chip_data *gic = &gic_data[0]; void __iomem *cpu_base = gic_data_cpu_base(gic); - unsigned long irqstat, irqnr; + unsigned long irqstat, hwirq; + unsigned int irq = 0; + + /* + * This function is called unconditionally by the default FIQ + * handler so first we must check that the driver it + * initialized. + */ + if (!gic->gic_irqs) + return 0; if (WARN_ON(!in_nmi())) - return; + return 0; - while ((1u << readl_relaxed(cpu_base + GIC_CPU_HIGHPRI)) & - SMP_IPI_FIQ_MASK) { - irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); - writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); + /* read intack with the priority mask set so we only acknowledge FIQs */ + writel_relaxed(GICC_INT_PRI_THRESHOLD >> 1, cpu_base + GIC_CPU_PRIMASK); + irqstat = readl_relaxed(cpu_base + GIC_CPU_INTACK); + raw_cpu_write(gic_irqstat_fiq, irqstat); + writel_relaxed(GICC_INT_PRI_THRESHOLD, cpu_base + GIC_CPU_PRIMASK); - irqnr = irqstat & GICC_IAR_INT_ID_MASK; - WARN_RATELIMIT(irqnr > 16, - "Unexpected irqnr %lu (bad prioritization?)\n", - irqnr); - } + hwirq = irqstat & GICC_IAR_INT_ID_MASK; + if (likely(hwirq > 15 && hwirq < 1021)) + irq = irq_find_mapping(gic->domain, hwirq); + + return irq; +} + +void gic_eoi_fiq(void) +{ + struct gic_chip_data *gic = &gic_data[0]; + + if (!gic->gic_irqs) + return; + + writel_relaxed(raw_cpu_read(gic_irqstat_fiq), + gic_data_cpu_base(gic) + GIC_CPU_EOI); } void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq) diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h index 7690f70049a3..7c03e12f9e52 100644 --- a/include/linux/irqchip/arm-gic.h +++ b/include/linux/irqchip/arm-gic.h @@ -127,7 +127,13 @@ static inline void __init register_routable_domain_ops gic_routable_irq_domain_ops = ops; } -void gic_handle_fiq_ipi(void); +#ifdef CONFIG_ARM_GIC +int gic_ack_fiq(void); +void gic_eoi_fiq(void); +#else +static inline int gic_ack_fiq(void) { return 0; } +static inline void gic_eof_fiq(void) {} +#endif #endif /* __ASSEMBLY */ #endif