From patchwork Sat Oct 25 11:06:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 39520 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DF8442145E for ; Sat, 25 Oct 2014 11:10:02 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id gf13sf442874lab.9 for ; Sat, 25 Oct 2014 04:10:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=Yrq1EKWyj6TI793qeTFaOT+Cza6xCfi7axmLD8tU6YA=; b=JCi9OMyCllMVbZLZHQ2AU7Aid03t+xIwLj/RPsmxlwrv7kPM8J3lU7yk3RYSn/x//A wz63uor2nxtmg/171trDv7sljChuNNKbYhogOfpWWBAH9vzZkWEdkxDDpYmpfUDzczes D7mOehp5rjHjfyphtuVpKBnoZCDA2icuHZehmocgdVTS7k2hhWI2wtALKLAN7jL174qL lRw8oAawX1SrbUY9MJ7E+Y5TjSAl8MJfx78LEWmuWSHbHn+jF2eK7u1XxRsFI2ajlKAX HMJcgbuG0C95GT7Bw7VOiYyUZwApi7Bm6pJpWC7JeONKpHSrmoEpxGzjx8PHlJKYAF0M nxBA== X-Gm-Message-State: ALoCoQnmP3q1QcqUwNgLyTtK38Qc1pk3nDSfGgilVGPuQa5fOhWxHZmAOWN+h+W4mHvM+e7rOVUm X-Received: by 10.112.99.72 with SMTP id eo8mr3472741lbb.7.1414235401300; Sat, 25 Oct 2014 04:10:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.4 with SMTP id ky4ls553036lab.23.gmail; Sat, 25 Oct 2014 04:10:00 -0700 (PDT) X-Received: by 10.152.2.100 with SMTP id 4mr10344289lat.6.1414235400678; Sat, 25 Oct 2014 04:10:00 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id k3si10844922lbs.64.2014.10.25.04.10.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 25 Oct 2014 04:10:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id gm9so3840717lab.13 for ; Sat, 25 Oct 2014 04:10:00 -0700 (PDT) X-Received: by 10.152.120.199 with SMTP id le7mr10091712lab.67.1414235400192; Sat, 25 Oct 2014 04:10:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp24182lbz; Sat, 25 Oct 2014 04:09:59 -0700 (PDT) X-Received: by 10.70.88.75 with SMTP id be11mr3538282pdb.32.1414235397394; Sat, 25 Oct 2014 04:09:57 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id rd7si6233345pab.141.2014.10.25.04.09.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Oct 2014 04:09:57 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1XhzCR-0004Oc-7i; Sat, 25 Oct 2014 11:07:59 +0000 Received: from inca-roads.misterjones.org ([213.251.177.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XhzC3-0004LS-9E for linux-arm-kernel@lists.infradead.org; Sat, 25 Oct 2014 11:07:36 +0000 Received: from [90.219.10.17] (helo=why.wild-wind.fr.eu.org) by cheepnis.misterjones.org with esmtpsa (TLSv1.2:AES128-SHA256:128) (Exim 4.80) (envelope-from ) id 1XhzBa-00075o-2y; Sat, 25 Oct 2014 13:07:06 +0200 From: Marc Zyngier To: Thomas Gleixner , Jason Cooper Subject: [PATCH 2/3] irqchip: GIC: Convert to EOImode == 1 Date: Sat, 25 Oct 2014 12:06:54 +0100 Message-Id: <1414235215-10468-3-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1414235215-10468-1-git-send-email-marc.zyngier@arm.com> References: <1414235215-10468-1-git-send-email-marc.zyngier@arm.com> X-SA-Exim-Connect-IP: 90.219.10.17 X-SA-Exim-Rcpt-To: tglx@linutronix.de, jason@lakedaemon.net, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: marc.zyngier@arm.com X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141025_040735_616625_FA302F24 X-CRM114-Status: GOOD ( 21.16 ) X-Spam-Score: 1.0 (+) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) Cc: linux-kernel@vger.kernel.org, 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com 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.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 So far, GICv2 has been used in with EOImode == 0. The effect of this mode is to perform the priority drop and the deactivation of the interrupt at the same time. While this works perfectly for Linux (we only have a single priority), it causes issues when an interrupt is forwarded to a guest, and when we want the guest to perform the EOI itself. This is also rather inefficient for threaded interrupts, as it forces us to hit the distributor (which is slower, specially when using virtualization). For this case, the GIC architecture provides EOImode == 1, where: - A write to the EOI register drops the priority of the interrupt and leaves it active. Other interrupts at the same priority level can now be taken, but the active interrupt cannot be taken again - A write to the DIR marks the interrupt as inactive, meaning it can now be taken again. We only enable this feature when booted in HYP mode. Also, as most device trees are broken (they report the CPU interface size to be 4kB, while the GICv2 CPU interface size is 8kB), output a warning if we're booted in HYP mode, and disable the feature. Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic.c | 64 +++++++++++++++++++++++++++++++++++++---- include/linux/irqchip/arm-gic.h | 4 +++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c index d78169e..53aedc8 100644 --- a/drivers/irqchip/irq-gic.c +++ b/drivers/irqchip/irq-gic.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "irq-gic-common.h" #include "irqchip.h" @@ -93,6 +94,10 @@ struct irq_chip gic_arch_extn = { .irq_set_wake = NULL, }; +static struct irq_chip *gic_chip; + +static bool supports_deactivate = false; + #ifndef MAX_GIC_NR #define MAX_GIC_NR 1 #endif @@ -192,6 +197,16 @@ static void gic_eoi_irq(struct irq_data *d) writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_EOI); } +static void gic_priority_drop_irq(struct irq_data *d) +{ + gic_eoi_irq(d); +} + +static void gic_deactivate_irq(struct irq_data *d) +{ + writel_relaxed(gic_irq(d), gic_cpu_base(d) + GIC_CPU_DEACTIVATE); +} + static void gic_irq_set_irqchip_state(struct irq_data *d, int state, int val) { u32 reg; @@ -333,6 +348,8 @@ static void __exception_irq_entry gic_handle_irq(struct pt_regs *regs) } if (irqnr < 16) { writel_relaxed(irqstat, cpu_base + GIC_CPU_EOI); + if (supports_deactivate) + writel_relaxed(irqstat, cpu_base + GIC_CPU_DEACTIVATE); #ifdef CONFIG_SMP handle_IPI(irqnr, regs); #endif @@ -369,7 +386,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc) chained_irq_exit(chip, desc); } -static struct irq_chip gic_chip = { +static struct irq_chip gicv1_chip = { .name = "GIC", .irq_mask = gic_mask_irq, .irq_unmask = gic_unmask_irq, @@ -384,6 +401,23 @@ static struct irq_chip gic_chip = { .irq_set_irqchip_state = gic_irq_set_irqchip_state, }; +static struct irq_chip gicv2_chip = { + .name = "GIC", + .flags = IRQCHIP_EOI_THREADED, + .irq_mask = gic_mask_irq, + .irq_unmask = gic_unmask_irq, + .irq_priority_drop = gic_priority_drop_irq, + .irq_eoi = gic_deactivate_irq, + .irq_set_type = gic_set_type, + .irq_retrigger = gic_retrigger, +#ifdef CONFIG_SMP + .irq_set_affinity = gic_set_affinity, +#endif + .irq_set_wake = gic_set_wake, + .irq_get_irqchip_state = gic_irq_get_irqchip_state, + .irq_set_irqchip_state = gic_irq_set_irqchip_state, +}; + void __init gic_cascade_irq(unsigned int gic_nr, unsigned int irq) { if (gic_nr >= MAX_GIC_NR) @@ -415,7 +449,11 @@ static u8 gic_get_cpumask(struct gic_chip_data *gic) static void gic_cpu_if_up(void) { void __iomem *cpu_base = gic_data_cpu_base(&gic_data[0]); - u32 bypass = 0; + u32 bypass; + u32 mode = 0; + + if (supports_deactivate) + mode = GIC_CPU_CTRL_EOImodeNS; /* * Preserve bypass disable bits to be written back later @@ -423,7 +461,7 @@ static void gic_cpu_if_up(void) bypass = readl(cpu_base + GIC_CPU_CTRL); bypass &= GICC_DIS_BYPASS_MASK; - writel_relaxed(bypass | GICC_ENABLE, cpu_base + GIC_CPU_CTRL); + writel_relaxed(bypass | mode | GICC_ENABLE, cpu_base + GIC_CPU_CTRL); } @@ -848,11 +886,11 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int irq, { if (hw < 32) { irq_set_percpu_devid(irq); - irq_set_chip_and_handler(irq, &gic_chip, + irq_set_chip_and_handler(irq, gic_chip, handle_percpu_devid_irq); set_irq_flags(irq, IRQF_VALID | IRQF_NOAUTOEN); } else { - irq_set_chip_and_handler(irq, &gic_chip, + irq_set_chip_and_handler(irq, gic_chip, handle_fasteoi_irq); set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); @@ -1031,6 +1069,11 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start, gic_irqs -= hwirq_base; /* calculate # of irqs to allocate */ + if (!supports_deactivate) + gic_chip = &gicv1_chip; + else + gic_chip = &gicv2_chip; + if (of_property_read_u32(node, "arm,routable-irqs", &nr_routable_irqs)) { irq_base = irq_alloc_descs(irq_start, 16, gic_irqs, @@ -1060,7 +1103,7 @@ void __init gic_init_bases(unsigned int gic_nr, int irq_start, set_handle_irq(gic_handle_irq); } - gic_chip.flags |= gic_arch_extn.flags; + gic_chip->flags |= gic_arch_extn.flags; gic_dist_init(gic); gic_cpu_init(gic); gic_pm_init(gic); @@ -1074,6 +1117,7 @@ gic_of_init(struct device_node *node, struct device_node *parent) { void __iomem *cpu_base; void __iomem *dist_base; + struct resource cpu_res; u32 percpu_offset; int irq; @@ -1086,6 +1130,14 @@ gic_of_init(struct device_node *node, struct device_node *parent) cpu_base = of_iomap(node, 1); WARN(!cpu_base, "unable to map gic cpu registers\n"); + of_address_to_resource(node, 1, &cpu_res); + if (is_hyp_mode_available()) { + if (resource_size(&cpu_res) >= SZ_8K) + supports_deactivate = true; + else + pr_warn("GIC: CPU interface size is %x, DT is probably wrong\n", (int)resource_size(&cpu_res)); + } + if (of_property_read_u32(node, "cpu-offset", &percpu_offset)) percpu_offset = 0; diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h index 13eed92..e8de29a 100644 --- a/include/linux/irqchip/arm-gic.h +++ b/include/linux/irqchip/arm-gic.h @@ -20,9 +20,13 @@ #define GIC_CPU_ALIAS_BINPOINT 0x1c #define GIC_CPU_ACTIVEPRIO 0xd0 #define GIC_CPU_IDENT 0xfc +#define GIC_CPU_DEACTIVATE 0x1000 #define GICC_ENABLE 0x1 #define GICC_INT_PRI_THRESHOLD 0xf0 + +#define GIC_CPU_CTRL_EOImodeNS (1 << 9) + #define GICC_IAR_INT_ID_MASK 0x3ff #define GICC_INT_SPURIOUS 1023 #define GICC_DIS_BYPASS_MASK 0x1e0