Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp467603iog; Wed, 29 Jun 2022 04:05:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkk6Vutk5dTSkvgSmvn3EL1TMVgQQ/BY+tP2GwfCHUjuz3TPbVshrBLIVBf4khSD2TadQf X-Received: by 2002:aa7:90c4:0:b0:521:2cd6:bd3e with SMTP id k4-20020aa790c4000000b005212cd6bd3emr9772218pfk.19.1656500734965; Wed, 29 Jun 2022 04:05:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656500734; cv=none; d=google.com; s=arc-20160816; b=xgGFOhfgpE4XROkauw3gsezYAjVKsJdylK3C2jjAIerE4YVdgPQAS/mC5HRk+rZJxZ 9KZWXtpJ7fyjFg5kenp6kCbNClVYqC2kA+NnKxJ3VP6lZ9Gv4M51M9ueYVnweqAVXimF FaODW7sJTJuVFESicIap3wGIjOJaJ9exLbutLu+Mv1lFlUT2c9yGZqhJOhISmx9PNi8Q XVs2McNbSO/3FdVZuKM37dvxgTaHgHCeYWeV/yqAq369q/gFUn8xT2LKjlcHesl+MJPv oG/lnE2Cm9fHTjrUzWW8S3fePgVlMz56pKLz+xnAQ6C3b+Yvjf3Odz4iA/51RdOZz667 1leg== 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:dkim-signature; bh=NkiHNCrtM+Hu0F8rVDwy2bEx0iuCDOCo1LD6+GFNVNc=; b=bJQ0/eRdHiW/1CV68HMrRAy9Dvcox9EiDLqpEIiErb/5EK0mVUelY+DSnTV83TItG2 OR/OWs+wRmp0eEOvaSIuJiHnwQ7yw2Op++6OA23StC1ZRx4HlzNYuhi9uxE2WIMps4na SYhAm6XS6KNTNiXGuJ95+i5kTTjgGQXRtco5mC4ZfWfN4CP2KPjWVyrKaUv/S5WX+0Ic neMqlMS4JMJA4xasanTJGDURurHUYSi3A8BH+XtcyKn+WKy1T7W7rsPy6+V3fG6BZPph 7sLNe1JeYxmQguOWWL6Qht60MuB8EFN/zns6Dmh+DI9gwd1Vi9hgIqToV30tYzBJ8T9f a9+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LSvHg7H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a056a000a9300b0050dd86727b8si22859562pfl.349.2022.06.29.04.05.21; Wed, 29 Jun 2022 04:05:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LSvHg7H5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233460AbiF2K7H (ORCPT + 99 others); Wed, 29 Jun 2022 06:59:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233453AbiF2K7F (ORCPT ); Wed, 29 Jun 2022 06:59:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325593E0E5 for ; Wed, 29 Jun 2022 03:59:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9007CB81F00 for ; Wed, 29 Jun 2022 10:59:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10E97C34114; Wed, 29 Jun 2022 10:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656500341; bh=sQufmCz5FhplH4cuoGsepfj3uW9p51dBjPkETSTm9t8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LSvHg7H56wNozRjkmzoGm2fiZW2JLil7UKerWhjBvJqwg6+Z6RnzjOdtdx35PWCfG cyLahYh7OIV31q8XJJ4XBMkpE2Emb1gMAXS+jtdPUQItrfBomKoCPb/kzxLrw1K078 0/v31grCir72SvKHO15jRZHHrJiqr6Ma8O6vsseXC32AqirS52QNZr6vkqBkP0LpOd kruILHZpn1AjKRkiDg+BAMjrI1FlfL5Oc0UT0iBhwp0P7rtdRPMAz922dfkNXNS+I1 TXM60WTUIjV3KYq7c+3YL+BWTfMAbtRFGoPeOP+w989NkXDdjp9wW54pWR0/TbC4KW 4suR4vHCkIBaQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o6VPO-0042rk-R0; Wed, 29 Jun 2022 11:58:59 +0100 Date: Wed, 29 Jun 2022 11:58:58 +0100 Message-ID: <87wncz20st.wl-maz@kernel.org> From: Marc Zyngier To: Jianmin Lv Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, Hanjun Guo , Lorenzo Pieralisi , Jiaxun Yang , Huacai Chen Subject: Re: [PATCH V13 05/13] irqchip: Add Loongson PCH LPC controller support In-Reply-To: <1656329997-20524-6-git-send-email-lvjianmin@loongson.cn> References: <1656329997-20524-1-git-send-email-lvjianmin@loongson.cn> <1656329997-20524-6-git-send-email-lvjianmin@loongson.cn> 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: lvjianmin@loongson.cn, tglx@linutronix.de, linux-kernel@vger.kernel.org, guohanjun@huawei.com, lorenzo.pieralisi@arm.com, jiaxun.yang@flygoat.com, chenhuacai@loongson.cn X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Jun 2022 12:39:49 +0100, Jianmin Lv wrote: > > From: Huacai Chen > > PCH-LPC stands for "LPC Interrupts" that described in Section 24.3 of > "Loongson 7A1000 Bridge User Manual". For more information please refer > Documentation/loongarch/irq-chip-model.rst. > > Co-developed-by: Jianmin Lv > Signed-off-by: Jianmin Lv > Signed-off-by: Huacai Chen > --- > arch/loongarch/include/asm/irq.h | 4 +- > arch/loongarch/kernel/irq.c | 1 - > drivers/irqchip/Kconfig | 8 ++ > drivers/irqchip/Makefile | 1 + > drivers/irqchip/irq-loongson-pch-lpc.c | 203 +++++++++++++++++++++++++++++++++ > 5 files changed, 214 insertions(+), 3 deletions(-) > create mode 100644 drivers/irqchip/irq-loongson-pch-lpc.c > > diff --git a/arch/loongarch/include/asm/irq.h b/arch/loongarch/include/asm/irq.h > index ace3ea6..48c0ce4 100644 > --- a/arch/loongarch/include/asm/irq.h > +++ b/arch/loongarch/include/asm/irq.h > @@ -104,7 +104,7 @@ struct irq_domain *eiointc_acpi_init(struct irq_domain *parent, > > struct irq_domain *htvec_acpi_init(struct irq_domain *parent, > struct acpi_madt_ht_pic *acpi_htvec); > -struct irq_domain *pch_lpc_acpi_init(struct irq_domain *parent, > +int pch_lpc_acpi_init(struct irq_domain *parent, > struct acpi_madt_lpc_pic *acpi_pchlpc); > struct irq_domain *pch_msi_acpi_init(struct irq_domain *parent, > struct acpi_madt_msi_pic *acpi_pchmsi); > @@ -121,7 +121,7 @@ struct irq_domain *pch_pic_acpi_init(struct irq_domain *parent, > > extern struct irq_domain *cpu_domain; > extern struct irq_domain *liointc_domain; > -extern struct irq_domain *pch_lpc_domain; > +extern struct fwnode_handle *pch_lpc_handle; > extern struct irq_domain *pch_msi_domain[MAX_IO_PICS]; > extern struct irq_domain *pch_pic_domain[MAX_IO_PICS]; > > diff --git a/arch/loongarch/kernel/irq.c b/arch/loongarch/kernel/irq.c > index b34b8d7..07d6059 100644 > --- a/arch/loongarch/kernel/irq.c > +++ b/arch/loongarch/kernel/irq.c > @@ -27,7 +27,6 @@ > > struct irq_domain *cpu_domain; > struct irq_domain *liointc_domain; > -struct irq_domain *pch_lpc_domain; > struct irq_domain *pch_msi_domain[MAX_IO_PICS]; > struct irq_domain *pch_pic_domain[MAX_IO_PICS]; > > diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig > index 1f23a6b..c1d527f 100644 > --- a/drivers/irqchip/Kconfig > +++ b/drivers/irqchip/Kconfig > @@ -591,6 +591,14 @@ config LOONGSON_PCH_MSI > help > Support for the Loongson PCH MSI Controller. > > +config LOONGSON_PCH_LPC > + bool "Loongson PCH LPC Controller" > + depends on MACH_LOONGSON64 > + default (MACH_LOONGSON64 && LOONGARCH) > + select IRQ_DOMAIN_HIERARCHY > + help > + Support for the Loongson PCH LPC Controller. > + > config MST_IRQ > bool "MStar Interrupt Controller" > depends on ARCH_MEDIATEK || ARCH_MSTARV7 || COMPILE_TEST > diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile > index 5b67450..242b8b3 100644 > --- a/drivers/irqchip/Makefile > +++ b/drivers/irqchip/Makefile > @@ -108,6 +108,7 @@ obj-$(CONFIG_LOONGSON_HTPIC) += irq-loongson-htpic.o > obj-$(CONFIG_LOONGSON_HTVEC) += irq-loongson-htvec.o > obj-$(CONFIG_LOONGSON_PCH_PIC) += irq-loongson-pch-pic.o > obj-$(CONFIG_LOONGSON_PCH_MSI) += irq-loongson-pch-msi.o > +obj-$(CONFIG_LOONGSON_PCH_LPC) += irq-loongson-pch-lpc.o > obj-$(CONFIG_MST_IRQ) += irq-mst-intc.o > obj-$(CONFIG_SL28CPLD_INTC) += irq-sl28cpld.o > obj-$(CONFIG_MACH_REALTEK_RTL) += irq-realtek-rtl.o > diff --git a/drivers/irqchip/irq-loongson-pch-lpc.c b/drivers/irqchip/irq-loongson-pch-lpc.c > new file mode 100644 > index 0000000..7e4d89a > --- /dev/null > +++ b/drivers/irqchip/irq-loongson-pch-lpc.c > @@ -0,0 +1,203 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Loongson LPC Interrupt Controller support > + * > + * Copyright (C) 2020-2022 Loongson Technology Corporation Limited > + */ > + > +#define pr_fmt(fmt) "lpc: " fmt > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Registers */ > +#define LPC_INT_CTL 0x00 > +#define LPC_INT_ENA 0x04 > +#define LPC_INT_STS 0x08 > +#define LPC_INT_CLR 0x0c > +#define LPC_INT_POL 0x10 > +#define LPC_COUNT 16 > + > +struct pch_lpc { > + void __iomem *base; > + struct irq_domain *lpc_domain; > + raw_spinlock_t lpc_lock; > + u32 saved_reg_ctl; > + u32 saved_reg_ena; > + u32 saved_reg_pol; > +}; > + > +struct fwnode_handle *pch_lpc_handle; > + > +static void ack_lpc_irq(struct irq_data *d) > +{ > + unsigned long flags; > + struct pch_lpc *priv = d->domain->host_data; > + > + raw_spin_lock_irqsave(&priv->lpc_lock, flags); > + writel(0x1 << d->hwirq, priv->base + LPC_INT_CLR); > + raw_spin_unlock_irqrestore(&priv->lpc_lock, flags); > +} > +static void mask_lpc_irq(struct irq_data *d) > +{ > + unsigned long flags; > + struct pch_lpc *priv = d->domain->host_data; > + > + raw_spin_lock_irqsave(&priv->lpc_lock, flags); > + writel(readl(priv->base + LPC_INT_ENA) & (~(0x1 << (d->hwirq))), > + priv->base + LPC_INT_ENA); > + raw_spin_unlock_irqrestore(&priv->lpc_lock, flags); > +} > + > +static void unmask_lpc_irq(struct irq_data *d) > +{ > + unsigned long flags; > + struct pch_lpc *priv = d->domain->host_data; > + > + raw_spin_lock_irqsave(&priv->lpc_lock, flags); > + writel(readl(priv->base + LPC_INT_ENA) | (0x1 << (d->hwirq)), > + priv->base + LPC_INT_ENA); > + raw_spin_unlock_irqrestore(&priv->lpc_lock, flags); > +} > + > +static int lpc_set_type(struct irq_data *d, unsigned int type) > +{ > + u32 val; > + u32 mask = 0x1 << (d->hwirq); > + struct pch_lpc *priv = d->domain->host_data; > + > + if (!(type & IRQ_TYPE_LEVEL_MASK)) > + return 0; > + > + val = readl(priv->base + LPC_INT_POL); > + > + if (type == IRQ_TYPE_LEVEL_HIGH) > + val |= mask; > + else > + val &= ~mask; > + > + writel(val, priv->base + LPC_INT_POL); > + > + return 0; > +} > + > +static struct irq_chip pch_lpc_irq_chip = { Make this const. > + .name = "PCH LPC", > + .irq_mask = mask_lpc_irq, > + .irq_unmask = unmask_lpc_irq, > + .irq_ack = ack_lpc_irq, > + .irq_set_type = lpc_set_type, nit: please use the same format for all callbacks: lpc_irq_OPERATION (lpc_irq_mask, lpc_irq_set_type...), which makes it much easier to read. > + .flags = IRQCHIP_SKIP_SET_WAKE, > +}; > + > +static void lpc_irq_dispatch(struct irq_desc *desc) > +{ > + u32 pending, bit, virq; > + struct irq_chip *chip = irq_desc_get_chip(desc); > + struct pch_lpc *priv = irq_desc_get_handler_data(desc); > + > + chained_irq_enter(chip, desc); > + > + pending = readl(priv->base + LPC_INT_ENA); > + pending &= readl(priv->base + LPC_INT_STS); > + if (!pending) > + spurious_interrupt(); > + > + while (pending) { > + bit = __ffs(pending); > + virq = irq_linear_revmap(priv->lpc_domain, bit); > + > + generic_handle_irq(bit); Replace the whole thing with a call to generic_handle_domain_irq(). No new code should ever have to use generic_handle_irq(). > + pending &= ~BIT(bit); > + } > + chained_irq_exit(chip, desc); > +} > + > +static int pch_lpc_map(struct irq_domain *d, unsigned int irq, > + irq_hw_number_t hw) > +{ > + irq_set_chip_and_handler(irq, &pch_lpc_irq_chip, handle_level_irq); > + return 0; > +} > + > +static const struct irq_domain_ops pch_lpc_domain_ops = { > + .map = pch_lpc_map, > + .translate = irq_domain_translate_twocell, > +}; > + > +static void pch_lpc_reset(struct pch_lpc *priv) > +{ > + /* Enable the LPC interrupt, bit31: en bit30: edge */ > + writel(0x80000000, priv->base + LPC_INT_CTL); Please don't hardcode numbers. Add the proper bit definitions. > + writel(0, priv->base + LPC_INT_ENA); > + /* Clear all 18-bit interrpt bit */ > + writel(0x3ffff, priv->base + LPC_INT_CLR); If that's just a mask, then use GENMASK(17, 0) instead. > +} > + > +static int pch_lpc_disabled(struct pch_lpc *priv) > +{ > + return (readl(priv->base + LPC_INT_ENA) == 0xffffffff) && > + (readl(priv->base + LPC_INT_STS) == 0xffffffff); > +} > + > +int __init pch_lpc_acpi_init(struct irq_domain *parent, > + struct acpi_madt_lpc_pic *acpi_pchlpc) > +{ > + int parent_irq; > + struct pch_lpc *priv; > + struct irq_fwspec fwspec; > + struct fwnode_handle *irq_handle; > + > + if (!acpi_pchlpc) > + return -EINVAL; > + > + priv = kzalloc(sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + raw_spin_lock_init(&priv->lpc_lock); > + > + priv->base = ioremap(acpi_pchlpc->address, acpi_pchlpc->size); > + if (!priv->base) > + goto free_priv; > + > + if (pch_lpc_disabled(priv)) { > + pr_err("Failed to get LPC status\n"); > + goto iounmap_base; > + } > + > + irq_handle = irq_domain_alloc_named_fwnode("lpcintc"); > + if (!irq_handle) { > + pr_err("Unable to allocate domain handle\n"); > + goto iounmap_base; > + } > + > + priv->lpc_domain = irq_domain_create_linear(irq_handle, LPC_COUNT, > + &pch_lpc_domain_ops, priv); > + if (!priv->lpc_domain) { > + pr_err("Failed to create IRQ domain\n"); > + goto iounmap_base; You also need to free the fwnode. > + } > + pch_lpc_reset(priv); > + > + fwspec.fwnode = parent->fwnode; > + fwspec.param[0] = acpi_pchlpc->cascade; > + fwspec.param[1] = IRQ_TYPE_LEVEL_HIGH; > + fwspec.param_count = 2; > + parent_irq = irq_create_fwspec_mapping(&fwspec); > + irq_set_chained_handler_and_data(parent_irq, lpc_irq_dispatch, priv); > + > + pch_lpc_handle = irq_handle; > + return 0; > + > +iounmap_base: > + iounmap(priv->base); > +free_priv: > + kfree(priv); > + > + return -ENOMEM; > +} > -- > 1.8.3.1 > > Thanks, M. -- Without deviation from the norm, progress is not possible.