Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3274574imm; Fri, 25 May 2018 02:53:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpgP1HFIINbh13KqRcLBnqf7hvog20+QdPQSxR/9HaH7XhK3eJQs78UhKcnJx1XXiSFL0D1 X-Received: by 2002:a17:902:d68b:: with SMTP id v11-v6mr1904216ply.16.1527242006317; Fri, 25 May 2018 02:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527242006; cv=none; d=google.com; s=arc-20160816; b=o30Pwpm0Cn4GlgYrpD0VV3DM8jGwB2E6A92Y8yzZnEybdvD/S6V4A+s8NTCtWe8/yY kze+4oKR3zsCT9HWOy5hDUH4FClP6Yw4p2igI4+TAPuw0pU0EkYcrT8xA3StyVqSodLE oUkf10lPwD627NHp2B2vOyadXxCXyaf960PoaDctQsNzqDE3zSgC7ArZDavmqKuubmWh MfDeJrf+Iu/veoaJY4l8Bn29Ykm996iI3TaaQLhfPMPQkdv0QCKcIvzl/W27bpuM1g7/ abuD1gAxZw9XWBGOhCcKK55BqTc+NDEZq7BJMGdKft4cxZePEdT6K9RNJGIOcPRwToYt xFUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Dk5iqRJVarmiEPyAcUv4azATXfsK8VDoU/abZU/lF0o=; b=FodEDMV8HK/7ZS7kUf1zHlGSnNC/vbwWA0NtSJA73Tzc1FRu9fauNh89IFvkXamV/9 D1oN82UsrY+2tQWrZAGOv/51XkvGnOTQXnEgsFG7AryKNc2Mho5YZcL1VufrC9+ghMK2 fES0bN8WXnvzbxLkURLuK2D//fEObJkJYiUdB3cDY2IgahuEBEOXrxr/NgNLBbW0KkjI X9iqXgpu6g4TYzJnZTm5418XjQSZToYe8y084pKp8+6dnMG3u7HmmP7IO1YGmjqcdN4i DwEyKIonC7oDBSZSVh43NGerJx5aJY03t3Y4mzT7+39Rw9xLwNN937xfGMvjk4XUBm4F 7Rfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10-v6si17874041pgc.299.2018.05.25.02.53.11; Fri, 25 May 2018 02:53:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965722AbeEYJw1 (ORCPT + 99 others); Fri, 25 May 2018 05:52:27 -0400 Received: from foss.arm.com ([217.140.101.70]:57696 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966272AbeEYJvA (ORCPT ); Fri, 25 May 2018 05:51:00 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E0B4E1596; Fri, 25 May 2018 02:50:59 -0700 (PDT) Received: from e112298-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8CFEF3F25D; Fri, 25 May 2018 02:50:57 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, james.morse@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, Julien Thierry , Thomas Gleixner , Jason Cooper Subject: [PATCH v4 26/26] irqchip/gic-v3: Allow interrupts to be set as pseudo-NMI Date: Fri, 25 May 2018 10:49:32 +0100 Message-Id: <1527241772-48007-27-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527241772-48007-1-git-send-email-julien.thierry@arm.com> References: <1527241772-48007-1-git-send-email-julien.thierry@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a way to set a GICv3 interrupt as pseudo-NMI. The interrupt must not be enabled when setting/clearing the NMI status of the interrupt. Signed-off-by: Julien Thierry Cc: Thomas Gleixner Cc: Jason Cooper Cc: Marc Zyngier --- drivers/irqchip/irq-gic-v3.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/interrupt.h | 1 + 2 files changed, 55 insertions(+) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index fa23d12..cea1000 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -305,6 +305,43 @@ static void handle_percpu_devid_nmi(struct irq_desc *desc) chip->irq_eoi(&desc->irq_data); } +static int gic_irq_set_irqchip_prio(struct irq_data *d, bool val) +{ + u8 prio; + irq_flow_handler_t handler; + + if (gic_peek_irq(d, GICD_ISENABLER)) { + pr_err("Cannot set NMI property of enabled IRQ %u\n", d->irq); + return -EPERM; + } + + if (val) { + prio = GICD_INT_NMI_PRI; + + if (gic_irq(d) < 32) + handler = handle_percpu_devid_nmi; + else + handler = handle_fasteoi_nmi; + } else { + prio = GICD_INT_DEF_PRI; + + if (gic_irq(d) < 32) + handler = handle_percpu_devid_irq; + else + handler = handle_fasteoi_irq; + } + + /* + * Already in a locked context for the desc from calling + * irq_set_irq_chip_state. + * It should be safe to simply modify the handler. + */ + irq_to_desc(d->irq)->handle_irq = handler; + gic_set_irq_prio(gic_irq(d), gic_dist_base(d), prio); + + return 0; +} + static int gic_irq_set_irqchip_state(struct irq_data *d, enum irqchip_irq_state which, bool val) { @@ -326,6 +363,16 @@ static int gic_irq_set_irqchip_state(struct irq_data *d, reg = val ? GICD_ICENABLER : GICD_ISENABLER; break; + case IRQCHIP_STATE_NMI: + if (gic_supports_nmi()) { + return gic_irq_set_irqchip_prio(d, val); + } else if (val) { + pr_warn("Failed to set IRQ %u as NMI, NMIs are unsupported\n", + gic_irq(d)); + return -EINVAL; + } + return 0; + default: return -EINVAL; } @@ -353,6 +400,13 @@ static int gic_irq_get_irqchip_state(struct irq_data *d, *val = !gic_peek_irq(d, GICD_ISENABLER); break; + case IRQCHIP_STATE_NMI: + if (!gic_supports_nmi()) + return -EINVAL; + *val = (gic_get_irq_prio(gic_irq(d), gic_dist_base(d)) == + GICD_INT_NMI_PRI); + break; + default: return -EINVAL; } diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index 5426627..02c794f 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -419,6 +419,7 @@ enum irqchip_irq_state { IRQCHIP_STATE_ACTIVE, /* Is interrupt in progress? */ IRQCHIP_STATE_MASKED, /* Is interrupt masked? */ IRQCHIP_STATE_LINE_LEVEL, /* Is IRQ line high? */ + IRQCHIP_STATE_NMI, /* Is IRQ an NMI? */ }; extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which, -- 1.9.1