Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4652444pxv; Tue, 6 Jul 2021 06:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeyKUFnTy3BhemlvSCnh8nL6wOuU1T8mE0ksZRzgnmtHcuwFQ087cXkJi0499vQ2oOPZjU X-Received: by 2002:a17:907:d28:: with SMTP id gn40mr18887437ejc.471.1625577208850; Tue, 06 Jul 2021 06:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625577208; cv=none; d=google.com; s=arc-20160816; b=vQQJIgMH4SgbXrT9Zj43GHPbIxwHzliVw7ZoqcnlA47uW20XdAWmNPuxqUETybOqfH R7v3KpartTnQh5IYtD3g+fXhGcGZS0XoeJ2Lhsme/BdFrr5T7vk6a+34cIjSe48//zJH 4aV7QpFRLCa4x/5zbXX26ArRHENie1q30oPYNoksUz8RgAZ0/rKnQxDZOHdVe78bXCcV tujcmdh7X9wgVNuLwAIFACkDjGYjN1DijvfOJGNjsghw7J0PF5nUF9PCaacnRVER+gp6 X9eC6FU89larXyndJeH6GW+0JvVmfdgZGr1O3w7gmLYgFwyRJ1eEunpaITB3PfDt523A Hcfw== 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=DXRyZQAdG1O+ajuvwb/VpnYWsGjR1sj/SLEG5WDjNaE=; b=B/ndFEkqPHzQhGPfIhDG0lclPgUGedpz0JhWqSfX0gHqBXMqFvDG5TKXxJb7QqIqGM BTKtJ2iSpeoc1q6kuccUOurjFp5ZHR7JefwinKWjW3eUWOaWkhIcZFhjpnS9WSdHQYR0 hWtT0UyKaY7dPGCh2JyUdrnJ8l1VIkDuXmUWqa9Z+D/lbLeRs1afRT9//NoeguEvH5S0 ENn07z01B/UB2gwtH7JassKSclFBTifSbXHBQzJgzSoJEddUcDlb+URrcisd3U4oLi0x UjR5RyvoRtP96389L89+j3RnQRQuU9OHKGQTbuM6s3L/Z/pJEVBPf76vktIIc5W+hAw3 GWjA== 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 ka25si14143258ejc.354.2021.07.06.06.13.04; Tue, 06 Jul 2021 06:13: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; 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 S231444AbhGFNNh (ORCPT + 99 others); Tue, 6 Jul 2021 09:13:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:60224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbhGFNNg (ORCPT ); Tue, 6 Jul 2021 09:13:36 -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 585E961C2F; Tue, 6 Jul 2021 13:10:58 +0000 (UTC) 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.94.2) (envelope-from ) id 1m0kqm-00BjgJ-9Y; Tue, 06 Jul 2021 14:10:56 +0100 Date: Tue, 06 Jul 2021 14:10:55 +0100 Message-ID: <877di38u5c.wl-maz@kernel.org> From: Marc Zyngier To: Huacai Chen Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, Xuefeng Li , Huacai Chen , Jiaxun Yang Subject: Re: [PATCH 3/9] irqchip/loongson-pch-pic: Add ACPI init support In-Reply-To: <20210706030904.1411775-4-chenhuacai@loongson.cn> References: <20210706030904.1411775-1-chenhuacai@loongson.cn> <20210706030904.1411775-4-chenhuacai@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: chenhuacai@loongson.cn, tglx@linutronix.de, linux-kernel@vger.kernel.org, lixuefeng@loongson.cn, chenhuacai@gmail.com, 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 On Tue, 06 Jul 2021 04:08:58 +0100, Huacai Chen wrote: > > We are preparing to add new Loongson (based on LoongArch, not MIPS) > support. LoongArch use ACPI other than DT as its boot protocol, so > add ACPI init support. > > Signed-off-by: Huacai Chen > --- > drivers/irqchip/irq-loongson-pch-pic.c | 120 ++++++++++++++++++++++++- > 1 file changed, 119 insertions(+), 1 deletion(-) > > diff --git a/drivers/irqchip/irq-loongson-pch-pic.c b/drivers/irqchip/irq-loongson-pch-pic.c > index a4eb8a2181c7..62382611995b 100644 > --- a/drivers/irqchip/irq-loongson-pch-pic.c > +++ b/drivers/irqchip/irq-loongson-pch-pic.c > @@ -1,6 +1,8 @@ > // SPDX-License-Identifier: GPL-2.0 > /* > * Copyright (C) 2020, Jiaxun Yang > + * Jianmin Lv > + * Huacai Chen Please drop this change. I'm in a position where I can verify who owns the copyright to this code, and I seriously doubt that 100 lines of boilerplate probing code give you any right over it. > * Loongson PCH PIC support > */ > > @@ -15,6 +17,7 @@ > #include > #include > #include > +#include > > /* Registers */ > #define PCH_PIC_MASK 0x20 > @@ -32,14 +35,23 @@ > #define PIC_COUNT (PIC_COUNT_PER_REG * PIC_REG_COUNT) > #define PIC_REG_IDX(irq_id) ((irq_id) / PIC_COUNT_PER_REG) > #define PIC_REG_BIT(irq_id) ((irq_id) % PIC_COUNT_PER_REG) > +#define PCH_PIC_SIZE 0x400 > + > +static int nr_pch_pics; > > struct pch_pic { > void __iomem *base; > struct irq_domain *pic_domain; > + struct fwnode_handle *domain_handle; > u32 ht_vec_base; > raw_spinlock_t pic_lock; > + u32 saved_vec_en[PIC_REG_COUNT]; > + u32 saved_vec_pol[PIC_REG_COUNT]; > + u32 saved_vec_edge[PIC_REG_COUNT]; > }; > > +struct pch_pic *pch_pic_priv[4]; > + > static void pch_pic_bitset(struct pch_pic *priv, int offset, int bit) > { > u32 reg; > @@ -137,6 +149,7 @@ static struct irq_chip pch_pic_irq_chip = { > .irq_ack = pch_pic_ack_irq, > .irq_set_affinity = irq_chip_set_affinity_parent, > .irq_set_type = pch_pic_set_type, > + .flags = IRQCHIP_SKIP_SET_WAKE, > }; > > static int pch_pic_alloc(struct irq_domain *domain, unsigned int virq, > @@ -180,7 +193,7 @@ static void pch_pic_reset(struct pch_pic *priv) > int i; > > for (i = 0; i < PIC_COUNT; i++) { > - /* Write vectored ID */ > + /* Write vector ID */ > writeb(priv->ht_vec_base + i, priv->base + PCH_INT_HTVEC(i)); > /* Hardcode route to HT0 Lo */ > writeb(1, priv->base + PCH_INT_ROUTE(i)); > @@ -198,6 +211,48 @@ static void pch_pic_reset(struct pch_pic *priv) > } > } > > +static int pch_pic_suspend(void) > +{ > + int i, j; > + > + for (i = 0; i < nr_pch_pics; i++) { > + for (j = 0; j < PIC_REG_COUNT; j++) { > + pch_pic_priv[i]->saved_vec_pol[j] = > + readl(pch_pic_priv[i]->base + PCH_PIC_POL + 4 * j); > + pch_pic_priv[i]->saved_vec_edge[j] = > + readl(pch_pic_priv[i]->base + PCH_PIC_EDGE + 4 * j); > + pch_pic_priv[i]->saved_vec_en[j] = > + readl(pch_pic_priv[i]->base + PCH_PIC_MASK + 4 * j); > + } > + } > + > + return 0; > +} > + > +static void pch_pic_resume(void) > +{ > + int i, j; > + > + for (i = 0; i < nr_pch_pics; i++) { > + pch_pic_reset(pch_pic_priv[i]); > + for (j = 0; j < PIC_REG_COUNT; j++) { > + writel(pch_pic_priv[i]->saved_vec_pol[j], > + pch_pic_priv[i]->base + PCH_PIC_POL + 4 * j); > + writel(pch_pic_priv[i]->saved_vec_edge[j], > + pch_pic_priv[i]->base + PCH_PIC_EDGE + 4 * j); > + writel(pch_pic_priv[i]->saved_vec_en[j], > + pch_pic_priv[i]->base + PCH_PIC_MASK + 4 * j); > + } > + } > +} > + > +static struct syscore_ops pch_pic_syscore_ops = { > + .suspend = pch_pic_suspend, > + .resume = pch_pic_resume, > +}; None of this has anything to do with what is described in the commit message. Please move this into its own patch. > + > +#ifdef CONFIG_OF > + > static int pch_pic_of_init(struct device_node *node, > struct device_node *parent) > { > @@ -242,6 +297,9 @@ static int pch_pic_of_init(struct device_node *node, > } > > pch_pic_reset(priv); > + pch_pic_priv[0] = priv; > + > + register_syscore_ops(&pch_pic_syscore_ops); > > return 0; > > @@ -254,3 +312,63 @@ static int pch_pic_of_init(struct device_node *node, > } > > IRQCHIP_DECLARE(pch_pic, "loongson,pch-pic-1.0", pch_pic_of_init); > + > +#endif > + > +#ifdef CONFIG_ACPI > + > +struct fwnode_handle *pch_pic_acpi_init(struct fwnode_handle *parent, > + struct acpi_madt_bio_pic *acpi_pchpic) > +{ > + int count; > + struct pch_pic *priv; > + struct irq_domain *parent_domain; > + > + priv = kzalloc(sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return NULL; > + > + raw_spin_lock_init(&priv->pic_lock); > + priv->base = ioremap(acpi_pchpic->address, acpi_pchpic->size); > + if (!priv->base) > + goto free_priv; > + > + priv->domain_handle = irq_domain_alloc_fwnode(priv->base); > + if (!priv->domain_handle) { > + pr_err("Unable to allocate domain handle\n"); > + goto iounmap_base; > + } > + > + priv->ht_vec_base = acpi_pchpic->gsi_base; > + count = ((readq(priv->base) >> 48) & 0xff) + 1; > + parent_domain = irq_find_matching_fwnode(parent, DOMAIN_BUS_ANY); > + if (!parent_domain) { > + pr_err("Failed to find the parent domain\n"); > + goto iounmap_base; > + } > + > + priv->pic_domain = irq_domain_create_hierarchy(parent_domain, 0, > + count, priv->domain_handle, > + &pch_pic_domain_ops, priv); > + > + if (!priv->pic_domain) { > + pr_err("Failed to create IRQ domain\n"); > + goto iounmap_base; > + } > + > + pch_pic_reset(priv); > + pch_pic_priv[nr_pch_pics++] = priv; > + > + register_syscore_ops(&pch_pic_syscore_ops); > + > + return priv->domain_handle; > + > +iounmap_base: > + iounmap(priv->base); > +free_priv: > + kfree(priv); > + > + return NULL; > +} > + > +#endif A lot of this code is common with its OF counterpart. How about making this logic common? M. -- Without deviation from the norm, progress is not possible.