Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2054844pxb; Sat, 28 Aug 2021 03:08:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNo17zUcHZgjdiVLh5hpDakEK0ZKj3/4ZSaMh7vfKIt6+cjBmMf1zrQ8Uv/QwtCM2LAiqs X-Received: by 2002:a6b:8f4e:: with SMTP id r75mr11087699iod.172.1630145308122; Sat, 28 Aug 2021 03:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630145308; cv=none; d=google.com; s=arc-20160816; b=kruq/te2P4uWc8Hd1Fabig9jy9nTTRsNaEAVnldaiaAx8RoT3sFnjhDboMj3kwAa6t RbXMbrDO847qZcCB3vIGHotIDbjTxIcmDnIsXPY/jVJp3FQk+NuhiHD0xTHqnpQng8jM 40KmsKCzgJ+0MSrUcl557g1iujdMe2//AR9SxiaBbWOE0v2fZJpl0bbqN+lsyPZX88sh e48yMfEOaq9gZMCDtJfMKaMfoRMnMXjE/jSPBiSxFY054Sx8dGavlWHs4MysCkhvgEA5 PDjHciDCu8cgnqJL789PBnsVyCrKTEJtwoDCciO2GzOd9F+rnfnmWCC4m9qlJu0uFYEJ QDUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mtj/gpMFpx8qvMVsIwiFw6Cv7Eqh7JdFS2jbIunoY1o=; b=lgrY/19NxC2Yh2QYoJH+3DTgz8CHyA+uiKMWdc3kT87NjczlJXrOmBMh6sBDvehi6w BpOEi/BoZdmXFbvQNs54IBCElLRhNhNLfJD4nUYAw+pzOrUpsfJK565GIgmZ5/Xco+Ui IsQoCDonbTXQpaiZ4ct0ol48qloI+2XndoqHmHyoFKssRl7WiXNkW/uX/uAB3I3JKP8y 5BLkSDH1E1Nvy/izVYVuKV07N8gVNCy6SoyXYTl/t2LyVLTqBMR7DWlFKe5vdWdqRLnm 24tFsFTzvZh4hv13UcVdWOtqyu3+TVqYyWkqg25J+bKYwPd7ofZZSfzZ7rGvrVYkay9J M2XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JDTB6EJG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f16si8423434ils.116.2021.08.28.03.08.16; Sat, 28 Aug 2021 03:08:28 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JDTB6EJG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233682AbhH1KIV (ORCPT + 99 others); Sat, 28 Aug 2021 06:08:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbhH1KIT (ORCPT ); Sat, 28 Aug 2021 06:08:19 -0400 Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57922C061756 for ; Sat, 28 Aug 2021 03:07:29 -0700 (PDT) Received: by mail-vs1-xe29.google.com with SMTP id i23so6579428vsj.4 for ; Sat, 28 Aug 2021 03:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mtj/gpMFpx8qvMVsIwiFw6Cv7Eqh7JdFS2jbIunoY1o=; b=JDTB6EJG+wAx0rVhc61S/b/K6PgsPx6WnR0IIo23QyeNs3KERttn+6rdSkUO0s4fr6 onKXlg3dL97gm/L6PC03gYhaclQGN7RoRlrMF7FqtI5Cj4sFSrgRcyJQqa9fOOpnCEQF yGVVrnjmkd7p1vPUoRm+2SeqedQxiyVQWZg5D73MRbHfmsf8UoDVbA1dCTcudJ9Vf+7d Q5McJzDHxmG8jJTznkrOFSy1/IyjAUSSj7LFTqst+WedAHqdMtlOJNzDMMukip7qVNRT 244o/Ksrvjc7ouN6G1pB612STbXpPZXW7hv6KTOzjTJGWREUzSUCuM8HKMDBSs90xS+6 /Lww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mtj/gpMFpx8qvMVsIwiFw6Cv7Eqh7JdFS2jbIunoY1o=; b=NV1UTwVLTMiHFhdbXihztOtCE6QMV7YC/7qNZbBYIkCyCeJVJsuy3VVvfQkwdyhw1t mq0D1J76HP/vqHGWoM5xH7ZT4UcwscXE3adSBndNynZFgOB0TZETMFevYieBHSYTAtCI l2HUeXvX1JBJjbKxootAXbLyGvpH1sn3aOAEliGJcUkncZsZrkGuJ/ANHwH45uR2lXmN eMLs9r+A90HiLoK9jScLACwmjToeGNXgoMMXxou+mdtEm1U1Hr6Vtfk76A4NgoMzwoer kZIVADwph4/5mdjmta8FBr04OItYwK5OVdGaI+SiJWw9GEf21t4uZi8oxF6PoUJAWoLi bd4g== X-Gm-Message-State: AOAM53014gJE9rqNUON+K+QkAsnxy44ownocftSUykEDb10Pzr+96n6o YaLgMFkCLtdptGHNGeCoMEw+NmhSBVmCsiVCX6E= X-Received: by 2002:a67:f510:: with SMTP id u16mr10408176vsn.60.1630145248330; Sat, 28 Aug 2021 03:07:28 -0700 (PDT) MIME-Version: 1.0 References: <20210825061152.3396398-1-chenhuacai@loongson.cn> <20210825061152.3396398-9-chenhuacai@loongson.cn> <87pmu1q5ms.wl-maz@kernel.org> In-Reply-To: <87pmu1q5ms.wl-maz@kernel.org> From: Huacai Chen Date: Sat, 28 Aug 2021 18:07:16 +0800 Message-ID: Subject: Re: [PATCH V3 08/10] irqchip: Add LoongArch CPU interrupt controller support To: Marc Zyngier Cc: Huacai Chen , Thomas Gleixner , LKML , Xuefeng Li , Jiaxun Yang Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This seems that if I want to use vectored interrupts, then I will fall to the MIPS model. Huacai > > You can solve this by: > > - Move over to CONFIG_GENERIC_IRQ_MULTI_HANDLER so that the interrupt > controller can register itself with the core, rather than being > defined at compile time. > > - Drop the do_IRQ() madness. Perform whenever stuff you need to do in > the arch code *before* calling into the interrupt controller code. > > - Use generic_handle_irq() to call into the irq stack. It will handle > all the irq_enter()/irq_exit() correctly. It will also avoid the > silly double lookup of the irq_desc on interrupt handling. > > > +} > > + > > +static int loongarch_cpu_intc_map(struct irq_domain *d, unsigned int irq, > > + irq_hw_number_t hwirq) > > +{ > > + struct irq_chip *chip; > > + > > + irq_set_noprobe(irq); > > + chip = &loongarch_cpu_irq_controller; > > + set_vi_handler(EXCCODE_INT_START + hwirq, default_handle_irq); > > What is that? Yet another MIPS legacy? Why does it have to be per > interrupt if it obviously apply to each and every root interrupt? > > Given that 'vi' probably stands for "vectored interrupt", why isn't > that the irq_enable() code? > > > + irq_set_chip_and_handler(irq, chip, handle_percpu_irq); > > + > > + return 0; > > +} > > + > > +static const struct irq_domain_ops loongarch_cpu_intc_irq_domain_ops = { > > + .map = loongarch_cpu_intc_map, > > + .xlate = irq_domain_xlate_onecell, > > +}; > > + > > +int __init loongarch_cpu_irq_init(void) > > +{ > > + /* Mask interrupts. */ > > + clear_csr_ecfg(ECFG0_IM); > > + clear_csr_estat(ESTATF_IP); > > + > > + irq_domain = irq_domain_add_simple(NULL, EXCCODE_INT_NUM, > > + LOONGSON_CPU_IRQ_BASE, &loongarch_cpu_intc_irq_domain_ops, NULL); > > NAK. You still obviously have some static partitioning of the > interrupt space, which is not acceptable for a new architecture. > > > + > > + if (!irq_domain) > > + panic("Failed to add irqdomain for LoongArch CPU"); > > + > > + return 0; > > +} > > I haven't seen much progress from the first version I reviewed. This > is still the same antiquated, broken MIPS code, only with a different > name. > > M. > > -- > Without deviation from the norm, progress is not possible.