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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D66C3C05027 for ; Mon, 6 Feb 2023 12:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjBFMtC (ORCPT ); Mon, 6 Feb 2023 07:49:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbjBFMtA (ORCPT ); Mon, 6 Feb 2023 07:49:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CCD0212D for ; Mon, 6 Feb 2023 04:48:59 -0800 (PST) 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 AC8D0B8100E for ; Mon, 6 Feb 2023 12:48:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59E9BC433EF; Mon, 6 Feb 2023 12:48:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675687736; bh=fSMEihA6KwvdtkMU3BE+V5pyx2N4hJ3YxHsRae9tMy8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cmzG8nHCWQ4HV8sefavjHMRN6eA49t/73TC00JgEOfT7jfEb0RXbMBxrs8fyGSkkx DpcHZjDf28XiTyNm1ejhVuJU1awiaejoBqj/lLv6b7Eo8UH8+AtTjSuKSaIM+pucgo SzPowhqIxmGyK7jvbXBEzw2k6Hf72a1JWF1QcOmBy31ggl4l3v6VmWRlZTRs+iB6YD s63LWJIzsaZKJY1Cd9bwNQSNQrUNG3RhvWmi/LGoZiU3c6zr9uZLoiI9d4m1HDiP8g dEdwDCIFz+tbhaEpjVFtPcwQ4YzWU+eoFe4WKiPv+yqaoE/10Mj7MKWKS3+BlMnhly 8UYZPBb/ISVOg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.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 1pP0vV-0080Hn-S1; Mon, 06 Feb 2023 12:48:54 +0000 Date: Mon, 06 Feb 2023 12:48:53 +0000 Message-ID: <86v8kfyn62.wl-maz@kernel.org> From: Marc Zyngier To: Mason Huo Cc: Thomas Gleixner , Palmer Dabbelt , Paul Walmsley , , , Ley Foon Tan , Sia Jee Heng Subject: Re: [PATCH v1] irqchip/irq-sifive-plic: Add syscore callbacks for hibernation In-Reply-To: References: <20230113094216.116036-1-mason.huo@starfivetech.com> <864js01j26.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/28.2 (aarch64-unknown-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: mason.huo@starfivetech.com, tglx@linutronix.de, palmer@dabbelt.com, paul.walmsley@sifive.com, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, leyfoon.tan@starfivetech.com, jeeheng.sia@starfivetech.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 Mon, 06 Feb 2023 06:13:11 +0000, Mason Huo wrote: > > > > On 2023/2/5 18:51, Marc Zyngier wrote: > > On Fri, 13 Jan 2023 09:42:16 +0000, > > Mason Huo wrote: > >> > >> The priority and enable registers of plic will be reset > >> during hibernation power cycle in poweroff mode, > >> add the syscore callbacks to save/restore those registers. > >> > >> Signed-off-by: Mason Huo > >> Reviewed-by: Ley Foon Tan > >> Reviewed-by: Sia Jee Heng > >> --- > >> drivers/irqchip/irq-sifive-plic.c | 93 ++++++++++++++++++++++++++++++- > >> 1 file changed, 91 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/irqchip/irq-sifive-plic.c b/drivers/irqchip/irq-sifive-plic.c > >> index ff47bd0dec45..80306de45d2b 100644 > >> --- a/drivers/irqchip/irq-sifive-plic.c > >> +++ b/drivers/irqchip/irq-sifive-plic.c > >> @@ -17,6 +17,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> > >> /* > >> @@ -67,6 +68,8 @@ struct plic_priv { > >> struct irq_domain *irqdomain; > >> void __iomem *regs; > >> unsigned long plic_quirks; > >> + unsigned int nr_irqs; > >> + u32 *priority_reg; > >> }; > >> > >> struct plic_handler { > >> @@ -79,10 +82,13 @@ struct plic_handler { > >> raw_spinlock_t enable_lock; > >> void __iomem *enable_base; > >> struct plic_priv *priv; > >> + /* To record interrupts that are enabled before suspend. */ > >> + u32 enable_reg[MAX_DEVICES / 32]; > > > > What does MAX_DEVICES represent here? How is it related to the number > > of interrupts you're trying to save? It seems to be related to the > > number of CPUs, so it hardly makes any sense so far. > > > The comment of this macro describes that "The largest number supported > by devices marked as 'sifive,plic-1.0.0', is 1024, of which > device 0 is defined as non-existent by the RISC-V Privileged Spec." > As far as I understand, the *device* here means HW IRQ source, > and the HW IRQ 0 is non-existent. So why is it sized to that maximum value? The binding gives you the *real* value that the HW implements. > > >> }; > >> static int plic_parent_irq __ro_after_init; > >> static bool plic_cpuhp_setup_done __ro_after_init; > >> static DEFINE_PER_CPU(struct plic_handler, plic_handlers); > >> +static struct plic_priv *priv_data; > >> > >> static int plic_irq_set_type(struct irq_data *d, unsigned int type); > >> > >> @@ -229,6 +235,78 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type) > >> return IRQ_SET_MASK_OK; > >> } > >> > >> +static void plic_irq_resume(void) > >> +{ > >> + unsigned int i, cpu; > >> + u32 __iomem *reg; > >> + > >> + for (i = 0; i < priv_data->nr_irqs; i++) > >> + writel(priv_data->priority_reg[i], > >> + priv_data->regs + PRIORITY_BASE + i * PRIORITY_PER_ID); > > > > From what I can tell, this driver uses exactly 2 priorities: 0 and 1. > > And yet you use a full 32bit to encode those. Does it seem like a good > > idea? > > > Yes, currently this driver uses oly 2 priorities. > But, according to the sifive spec, the priority register is a 32bit register, > and it supports 7 levels of priority. And? This is a Linux driver, not an implementation validation tool. What is the point of saving/restoring stuff that is *never* used? :-( M. -- Without deviation from the norm, progress is not possible.