Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2085651pxb; Sat, 28 Aug 2021 04:08:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdqR/acahWPaO5VIP56yuzYnHLvYG9dOaC2opvzR9T/TDZpOqCZpQEhJZE28DoYXFYCmkp X-Received: by 2002:a05:6e02:1526:: with SMTP id i6mr9275679ilu.74.1630148906025; Sat, 28 Aug 2021 04:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630148906; cv=none; d=google.com; s=arc-20160816; b=0kGpSHyznXEerZL/a9xH4ZWX0cGVWt1TmKJt0HFZF++xauICTRs8p3DRAgHyLmlTNy JbCL8vCKNkBvoR8uwcDZuq4lI/TZ1+bcQbpE1QDzNiE4eNpCm/Z1RtxTXqcSeyfEJsmK twXKKFh92kGJ24Ws3z+vjLGnU04Xfou1rbuMy5mbkiqGBMP5GcuI/HRI37ql/mqyV+C+ N2tNSctTNfRT/KDAt+ePXSYrMGDN2sTjOzE1FVxQPICgnHHbkwOC1RkRtBldEVtnA2xL gWolN5v2PHT1VCyBXf2omaZ4sbmbMGgP1yaXDgxzW/JqdBT77xx7IUYCUx4sy3p717pA HMVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=CvCxJ/C7b7ktEqXyXPzYtldhx9IpLt/rY92xkhMjIv8=; b=jDnEiWo1FKvXuO5DDkWKxr4rJ63Bp3WB0HsypUJTrSpBil3mDDHPtNwWcbfWGPgniu 8eLpRhOOp0MV+lboRPx+Q4hdijlqKeG1MRBQa4xbI5IeRqmUYbeV7PCGeHygADtOwmS6 KMH7ItJPmd95QK1vEcof9Ex4VxOvr7ouJLTlS6avAs/eQXnBpPR1WLS9L+7H/mvSdNTI zpJBFFMyEuUt+OAgZFx6lloR4SjO8hin3mPFBM2owpcJHzQptyvqSEEr/Ae4pUC/wOmz 0YWj6/P5O+MB12MCimWcJQd8jZT/gM1Q/uQoFv0G4YwSGfqjjZwtfVRz7Z0p7KrnYely TNCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h30si8882858ila.1.2021.08.28.04.08.14; Sat, 28 Aug 2021 04:08:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233853AbhH1LIT (ORCPT + 99 others); Sat, 28 Aug 2021 07:08:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:60938 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233732AbhH1LIP (ORCPT ); Sat, 28 Aug 2021 07:08:15 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E84A0601FD; Sat, 28 Aug 2021 11:07:23 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mJwBF-007iqY-V4; Sat, 28 Aug 2021 12:07:22 +0100 Date: Sat, 28 Aug 2021 12:07:17 +0100 Message-ID: <87v93pddzu.wl-maz@kernel.org> From: Marc Zyngier To: Huacai Chen Cc: Huacai Chen , Thomas Gleixner , LKML , Xuefeng Li , Jiaxun Yang Subject: Re: [PATCH V3 08/10] irqchip: Add LoongArch CPU interrupt controller support In-Reply-To: References: <20210825061152.3396398-1-chenhuacai@loongson.cn> <20210825061152.3396398-9-chenhuacai@loongson.cn> <87pmu1q5ms.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: chenhuacai@gmail.com, chenhuacai@loongson.cn, tglx@linutronix.de, linux-kernel@vger.kernel.org, lixuefeng@loongson.cn, jiaxun.yang@flygoat.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Huacai, On Sat, 28 Aug 2021 11:07:16 +0100, Huacai Chen wrote: > > Hi, Marc, > > On Wed, Aug 25, 2021 at 4:40 PM Marc Zyngier wrote: > > > > On Wed, 25 Aug 2021 07:11:50 +0100, > > Huacai Chen wrote: > > > > > > We are preparing to add new Loongson (based on LoongArch, not MIPS) > > > > You keep saying "not MIPS", and yet all I see is a blind copy of the > > MIPS code. > > > > > support. This patch add LoongArch CPU interrupt controller support. > > > > > > Signed-off-by: Huacai Chen > > > --- > > > drivers/irqchip/Kconfig | 10 ++++ > > > drivers/irqchip/Makefile | 1 + > > > drivers/irqchip/irq-loongarch-cpu.c | 76 +++++++++++++++++++++++++++++ > > > 3 files changed, 87 insertions(+) > > > create mode 100644 drivers/irqchip/irq-loongarch-cpu.c > > > > > > diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig > > > index 084bc4c2eebd..443c3a7a0cc1 100644 > > > --- a/drivers/irqchip/Kconfig > > > +++ b/drivers/irqchip/Kconfig > > > @@ -528,6 +528,16 @@ config EXYNOS_IRQ_COMBINER > > > Say yes here to add support for the IRQ combiner devices embedded > > > in Samsung Exynos chips. > > > > > > +config IRQ_LOONGARCH_CPU > > > + bool > > > + select GENERIC_IRQ_CHIP > > > + select IRQ_DOMAIN > > > + select GENERIC_IRQ_EFFECTIVE_AFF_MASK > > > + help > > > + Support for the LoongArch CPU Interrupt Controller. For details of > > > + irq chip hierarchy on LoongArch platforms please read the document > > > + Documentation/loongarch/irq-chip-model.rst. > > > + > > > config LOONGSON_LIOINTC > > > bool "Loongson Local I/O Interrupt Controller" > > > depends on MACH_LOONGSON64 > > > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > > > index f88cbf36a9d2..4e34eebe180b 100644 > > > --- a/drivers/irqchip/Makefile > > > +++ b/drivers/irqchip/Makefile > > > @@ -105,6 +105,7 @@ obj-$(CONFIG_LS1X_IRQ) += irq-ls1x.o > > > obj-$(CONFIG_TI_SCI_INTR_IRQCHIP) += irq-ti-sci-intr.o > > > obj-$(CONFIG_TI_SCI_INTA_IRQCHIP) += irq-ti-sci-inta.o > > > obj-$(CONFIG_TI_PRUSS_INTC) += irq-pruss-intc.o > > > +obj-$(CONFIG_IRQ_LOONGARCH_CPU) += irq-loongarch-cpu.o > > > obj-$(CONFIG_LOONGSON_LIOINTC) += irq-loongson-liointc.o > > > obj-$(CONFIG_LOONGSON_HTPIC) += irq-loongson-htpic.o > > > obj-$(CONFIG_LOONGSON_HTVEC) += irq-loongson-htvec.o > > > diff --git a/drivers/irqchip/irq-loongarch-cpu.c b/drivers/irqchip/irq-loongarch-cpu.c > > > new file mode 100644 > > > index 000000000000..8e9e8d39cb22 > > > --- /dev/null > > > +++ b/drivers/irqchip/irq-loongarch-cpu.c > > > @@ -0,0 +1,76 @@ > > > +// SPDX-License-Identifier: GPL-2.0 > > > +/* > > > + * Copyright (C) 2020-2021 Loongson Technology Corporation Limited > > > + */ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > + > > > +#include > > > +#include > > > + > > > +static struct irq_domain *irq_domain; > > > + > > > +static inline void enable_loongarch_irq(struct irq_data *d) > > > > Why 'inline' given that it is used as a function pointer? > > > > > +{ > > > + set_csr_ecfg(ECFGF(d->hwirq)); > > > +} > > > + > > > +#define eoi_loongarch_irq enable_loongarch_irq > > > > NAK. EOI and enable cannot be the same operation. > > > > > + > > > +static inline void disable_loongarch_irq(struct irq_data *d) > > > +{ > > > + clear_csr_ecfg(ECFGF(d->hwirq)); > > > +} > > > + > > > +#define ack_loongarch_irq disable_loongarch_irq > > > > Same thing. Either you have different operations, or this only > > supports mask/unmask. > > > > > + > > > +static struct irq_chip loongarch_cpu_irq_controller = { > > > + .name = "LoongArch", > > > + .irq_ack = ack_loongarch_irq, > > > + .irq_eoi = eoi_loongarch_irq, > > > + .irq_enable = enable_loongarch_irq, > > > + .irq_disable = disable_loongarch_irq, > > > +}; > > > + > > > +asmlinkage void default_handle_irq(int irq) > > > +{ > > > + do_IRQ(irq_linear_revmap(irq_domain, irq)); > > > > This looks both wrong and short sighted: > > > > - irq_linear_revmap() is now another name for irq_find_mapping(). > > Which means it uses a RCU read critical section. If, as I expect, > > this is just a blind copy of the MIPS code, do_IRQ() will not do > > anything with respect to irq_enter()/irq_exit(), which will result > > in something pretty bad on the exit from idle path. Lockdep will > > probably shout at you pretty loudly. > > > > - A single root interrupt controller is, in my modest experience, > > something that rarely happen. You will eventually have a variety of > > them, and you will have to join the other arches such as arm, arm64, > > riscv and csky that use CONFIG_GENERIC_IRQ_MULTI_HANDLER instead of > > following the existing MIPS model. > I try to use CONFIG_GENERIC_IRQ_MULTI_HANDLER and > set_handle_irq()/handle_arch_irq() as arm64, riscv and csky do. But I > found a problem: > The main handler (e.g., handle_arch_irq()) take only one argument > (i.e., struct pt_regs *regs) and polling all interrupts, but we want > to use vectored interrupts which take a "irq" argument (as > default_handle_irq() does) which can directly handle it. Are you saying that there is no way for the interrupt controller driver to figure out the hwirq number on its own? That would seem pretty odd (even the MIPS GIC has that). Worse case, you can provide an arch-specific helper that exposes the current hwirq based on the vector that triggered. do_IRQ() is a terrible abstraction, and only outlines that your arch code is badly structured. What does the arch code have to do with a Linux irq number? It shouldn't care at all, because as a value it has no significance to the arch code at all. You just go back there because the management of your interrupt context is upside down, and it really shouldn't matter *what interrupt fired*. > This seems that if I want to use vectored interrupts, then I will fall > to the MIPS model. Not happening, I'm afraid. M. -- Without deviation from the norm, progress is not possible.