From patchwork Tue May 3 13:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 12835816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F5D5C433F5 for ; Tue, 3 May 2022 13:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=AI31r6ACNBpCj+yEm6iqeXxHeWlueaJYajJVjZ/SuzE=; b=1UgLXIwXkXLuR2 brS15cd9/HMPR20XimAb1nC/lYVrc9BAKwyHKmH6RmoYnIM2m2KRUf/Ex4b2eLk1u9cgAqMBZIzAS cBJWX35FpMOIPMQRuWx/lwp3XtuBZHiyJB4Z9ztKoyPl57V9h3R1BU0Iud+8v8y1w2776Pt3Zj/FX gIebrr0qxM2rizFLqqHHdIkNCz6HtLp2rsLdguIRGEpk5S574WxFxno99Mf+PwIUuCHwQZ5O6MMuO AfJrBBM6AQMrxM2o4BKBCAWHwM21DEbPn/FcUCEI3N0urXTJbu67qJU4YVpKrPlypWWXcrUMVuM0L 95X/YD82hJWqS8A9b8ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlsqf-0064wc-Fj; Tue, 03 May 2022 13:45:53 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlsqa-0064tl-NK for linux-arm-kernel@lists.infradead.org; Tue, 03 May 2022 13:45:51 +0000 Received: by mail-wr1-x434.google.com with SMTP id d5so23441884wrb.6 for ; Tue, 03 May 2022 06:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2l7FO86j4xB2KtqQIq0q0SW9gMxybtUx7HgngsHixTs=; b=cEyeZvvw2Tu39/c04bJbtDNch9vMteVk9LRrmDt5DchuMGpQycd4xtq0jsKjwfiAvn rVO/veX+tk6jdbbAGbwrok006OxQxy0UwYG3lTuPowlbvBV09y7zOwN0+r6v0L+BjahT bz9HFxeWV7uV9QD8wjSPsvskVdFExQfn4PWGSo4+9mscWQZsOLOsWR/8J/xNqZVkPV+c f3OHnlDfIhYgVe2pgExDHfpuyip7Qqzt5KvU8M8vmrwRIVcsfcpLBhS+79vDyvdheN3O FAB0L3kZ6k4MIgk6/2ci1EkmaRsGbv3k8VJHB0cU7cRqyCbL33insklCnZH5AFnUySlh uU3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2l7FO86j4xB2KtqQIq0q0SW9gMxybtUx7HgngsHixTs=; b=2r7/0nngxyFUGDScwXtHsXfRhXzuLt7FnJsk8d1jT813oIjBuexFkDFylHrTF5TLrV DbXnHVzAuZigNQRW4e9vL91C3bir5i5Gajv9wxSoZIgqY+2k+JCeJvdcIKi9vGWNtU/i dZVNgiTzQ7+f1cTh8rWFkpXTNlq5IcRZ8peqSITnORwfY0xdNbyixXIzfrntP4UhyXnL DXerA4vmwEQeE3sqkHjo2IPA0rCH/mDeFmMx17EEFjdsWmDO0Z4zI2vSYwmQosha6yXs QvS7joEDjZz9+td/728c0bdwBqEEUw3TsiKHtJhpjveiBNV6gCu+YV5/zgup+YaUNgwH E+0A== X-Gm-Message-State: AOAM533RA3pkmdlAkG4wgUeiAHETe8ITmiv2hF3rxiYuPzT4/0/rQN1x Jr+vOTo426GPCMsjXJL9DgC69A== X-Google-Smtp-Source: ABdhPJyKo1xSFFzC3jNvl/uaHEsRxkT5UAeworwoEISx5eWwOXlATfDD3f4Ba+8moyg9ujjASNlKsw== X-Received: by 2002:a5d:4882:0:b0:207:97dd:111c with SMTP id g2-20020a5d4882000000b0020797dd111cmr13663218wrq.115.1651585544975; Tue, 03 May 2022 06:45:44 -0700 (PDT) Received: from maple.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id e11-20020a05600c4e4b00b003942a244f36sm1766544wmq.15.2022.05.03.06.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 06:45:44 -0700 (PDT) From: Daniel Thompson To: Marc Zyngier , Thomas Gleixner Cc: Daniel Thompson , Catalin Marinas , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] irqchip/exiu: Fix acknowledgment of edge triggered interrupts Date: Tue, 3 May 2022 14:45:41 +0100 Message-Id: <20220503134541.2566457-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220503_064548_834532_4C5466A7 X-CRM114-Status: GOOD ( 23.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently the EXIU uses the fasteoi interrupt flow that is configured by it's parent (irq-gic-v3.c). With this flow the only chance to clear the interrupt request happens during .irq_eoi() and (obviously) this happens after the interrupt handler has run. EXIU requires edge triggered interrupts to be acked prior to interrupt handling. Without this we risk incorrect interrupt dismissal when a new interrupt is delivered after the handler reads and acknowledges the peripheral but before the irq_eoi() takes place. Fix this by clearing the interrupt request from .irq_ack() if we are configured for edge triggered interrupts. This requires adopting the fasteoi-ack flow instead of the fasteoi to ensure the ack gets called. These changes have been tested using the power button on a Developerbox/SC2A11 combined with some hackery in gpio-keys so I can play with the different trigger mode [and an mdelay(500) so I can can check what happens on a double click in both modes]. Fixes: 706cffc1b912 ("irqchip/exiu: Add support for Socionext Synquacer EXIU controller") Signed-off-by: Daniel Thompson Reviewed-by: Ard Biesheuvel --- Notes: Changes in v3: * Optimize exiu_irq_eoi() to avoid unnecessary register read (Marc Z) * Add comment to exiu_irq_eoi() so future adventurers can better understand how the EXIU on SC2A11 behaves (Marc Z) * Remove redundant trigger mode management from exiu_domain_alloc() (Marc Z) Changes in v2: * Switch to dynamic selection of handle_fasteoi_irq and handle_fasteoi_ack_irq and reintroduce exiu_irq_eoi() since we need that for level triggered interrupts (Ard B). * Above changes mean we are no longer using sun6i NMI code as a template to tidy up the description accordingly. arch/arm64/Kconfig.platforms | 1 + drivers/irqchip/irq-sni-exiu.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) base-commit: b2d229d4ddb17db541098b83524d901257e93845 -- 2.35.1 diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms index 30b123cde02c..aaeaf57c8222 100644 --- a/arch/arm64/Kconfig.platforms +++ b/arch/arm64/Kconfig.platforms @@ -253,6 +253,7 @@ config ARCH_INTEL_SOCFPGA config ARCH_SYNQUACER bool "Socionext SynQuacer SoC Family" + select IRQ_FASTEOI_HIERARCHY_HANDLERS config ARCH_TEGRA bool "NVIDIA Tegra SoC Family" diff --git a/drivers/irqchip/irq-sni-exiu.c b/drivers/irqchip/irq-sni-exiu.c index abd011fcecf4..c7db617e1a2f 100644 --- a/drivers/irqchip/irq-sni-exiu.c +++ b/drivers/irqchip/irq-sni-exiu.c @@ -37,11 +37,26 @@ struct exiu_irq_data { u32 spi_base; }; -static void exiu_irq_eoi(struct irq_data *d) +static void exiu_irq_ack(struct irq_data *d) { struct exiu_irq_data *data = irq_data_get_irq_chip_data(d); writel(BIT(d->hwirq), data->base + EIREQCLR); +} + +static void exiu_irq_eoi(struct irq_data *d) +{ + struct exiu_irq_data *data = irq_data_get_irq_chip_data(d); + + /* + * Level triggered interrupts are latched and must be cleared during + * EOI or the interrupt will be jammed on. Of course if a level + * triggered interrupt is still asserted then the write will not clear + * the interrupt. + */ + if (irqd_is_level_type(d)) + writel(BIT(d->hwirq), data->base + EIREQCLR); + irq_chip_eoi_parent(d); } @@ -91,10 +106,13 @@ static int exiu_irq_set_type(struct irq_data *d, unsigned int type) writel_relaxed(val, data->base + EILVL); val = readl_relaxed(data->base + EIEDG); - if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) + if (type == IRQ_TYPE_LEVEL_LOW || type == IRQ_TYPE_LEVEL_HIGH) { val &= ~BIT(d->hwirq); - else + irq_set_handler_locked(d, handle_fasteoi_irq); + } else { val |= BIT(d->hwirq); + irq_set_handler_locked(d, handle_fasteoi_ack_irq); + } writel_relaxed(val, data->base + EIEDG); writel_relaxed(BIT(d->hwirq), data->base + EIREQCLR); @@ -104,6 +122,7 @@ static int exiu_irq_set_type(struct irq_data *d, unsigned int type) static struct irq_chip exiu_irq_chip = { .name = "EXIU", + .irq_ack = exiu_irq_ack, .irq_eoi = exiu_irq_eoi, .irq_enable = exiu_irq_enable, .irq_mask = exiu_irq_mask,