Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp619343rwb; Fri, 13 Jan 2023 01:59:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXuNaQKiy7ur9P76gzsfTIubobfFvf5tVfBXgZpS5zHQUBdmu13c4JkLO6m5k8MZOEEyHaem X-Received: by 2002:a17:902:9045:b0:194:6f3b:3aa1 with SMTP id w5-20020a170902904500b001946f3b3aa1mr1477940plz.55.1673603991175; Fri, 13 Jan 2023 01:59:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673603991; cv=none; d=google.com; s=arc-20160816; b=HJ7ndXs0twoPlWYXU70P5sV9Ru3k5ioapvy6danT7227x2eXNRBC+l0O/70eFaAMuV qlqtJNzFKNovF8L083ItEyVcfTekjlUvsciGhZf5a86MbqIFtExmAWtijYy2p0gGQ/2v As95oM+zjmBeA8SrT8WijTI2mOS0YQ1g2PHXAj0ujwPIr35gea0A85FWaYYz/QMqMp8O BXwiZJJHcqRy8WVTt6fFaG9T3ybo+fMEIgLljTUJBec8Ffgm95CpEE2/O68WYEwQSLYS o5rDrMG7ylzt7Iq6glTK62X+R/8TWBij1pABB7yvoYahyI72XsStA6CgBEskVUL1C2X6 mqBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=9r8rWpvWrGImyidM5dw0wQOX84bpO68ycrT0XzMBJQ4=; b=gtChR/Jqu51dwmisN7RIt0NJxxuMMVTjn8ZYoOcEKhQbjadgJBoHNMmiMhST6vseau U8vgNRCK/m4MAQBsj4ayHyWgPRDwfaise675A+wYMuSFIFcF+s73GTwlzxxd2eIZexd0 kJ4X1G9UqllxAwaJWzsZxMUm8Xb1fiQzCR4c92y8hYcULj12e8cEy/XwnfRHcg4aJYDP 0t0B0LcKfALhloTvWMcFrWImKPL9b7xbAagYSobYX6otvtvmEPXZELhOto41F/EUUkPi me7WKMSP3xM32b3LgpIuF3Qd01bzLD66tc5Vci3LnCoOLkRf6CrxisLjvm+l5KYwaK8j 1GjA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a170903240700b0019475289415si437281plo.85.2023.01.13.01.59.44; Fri, 13 Jan 2023 01:59:51 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241087AbjAMJui convert rfc822-to-8bit (ORCPT + 51 others); Fri, 13 Jan 2023 04:50:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240798AbjAMJty (ORCPT ); Fri, 13 Jan 2023 04:49:54 -0500 Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F00A93AC for ; Fri, 13 Jan 2023 01:42:28 -0800 (PST) Received: from EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id 7F88D24DDB2; Fri, 13 Jan 2023 17:42:21 +0800 (CST) Received: from EXMBX067.cuchost.com (172.16.6.67) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 13 Jan 2023 17:42:19 +0800 Received: from ubuntu.localdomain (113.72.144.207) by EXMBX067.cuchost.com (172.16.6.67) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 13 Jan 2023 17:42:18 +0800 From: Mason Huo To: Thomas Gleixner , Marc Zyngier , Palmer Dabbelt , Paul Walmsley CC: , , "Mason Huo" , Ley Foon Tan , Sia Jee Heng Subject: [PATCH v1] irqchip/irq-sifive-plic: Add syscore callbacks for hibernation Date: Fri, 13 Jan 2023 17:42:16 +0800 Message-ID: <20230113094216.116036-1-mason.huo@starfivetech.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [113.72.144.207] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX067.cuchost.com (172.16.6.67) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 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]; }; 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); + + for_each_cpu(cpu, cpu_present_mask) { + struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); + + if (!handler->present) + continue; + + for (i = 0; i < DIV_ROUND_UP(priv_data->nr_irqs, 32); i++) { + reg = handler->enable_base + i * sizeof(u32); + raw_spin_lock(&handler->enable_lock); + writel(handler->enable_reg[i], reg); + raw_spin_unlock(&handler->enable_lock); + } + } +} + +static int plic_irq_suspend(void) +{ + unsigned int i, cpu; + u32 __iomem *reg; + + for (i = 0; i < priv_data->nr_irqs; i++) + priv_data->priority_reg[i] = + readl(priv_data->regs + PRIORITY_BASE + i * PRIORITY_PER_ID); + + for_each_cpu(cpu, cpu_present_mask) { + struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); + + if (!handler->present) + continue; + + for (i = 0; i < DIV_ROUND_UP(priv_data->nr_irqs, 32); i++) { + reg = handler->enable_base + i * sizeof(u32); + raw_spin_lock(&handler->enable_lock); + handler->enable_reg[i] = readl(reg); + raw_spin_unlock(&handler->enable_lock); + } + } + + return 0; +} + +static struct syscore_ops plic_irq_syscore_ops = { + .suspend = plic_irq_suspend, + .resume = plic_irq_resume, +}; + +static void plic_irq_pm_init(void) +{ + unsigned int cpu; + + for_each_cpu(cpu, cpu_present_mask) { + struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu); + + if (!handler->present) + continue; + + memset(&handler->enable_reg[0], 0, + sizeof(handler->enable_reg)); + } + + register_syscore_ops(&plic_irq_syscore_ops); +} + static int plic_irqdomain_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hwirq) { @@ -351,6 +429,7 @@ static int __init __plic_init(struct device_node *node, return -ENOMEM; priv->plic_quirks = plic_quirks; + priv_data = priv; priv->regs = of_iomap(node, 0); if (WARN_ON(!priv->regs)) { @@ -363,15 +442,21 @@ static int __init __plic_init(struct device_node *node, if (WARN_ON(!nr_irqs)) goto out_iounmap; + priv->nr_irqs = nr_irqs; + + priv->priority_reg = kcalloc(nr_irqs, sizeof(u32), GFP_KERNEL); + if (!priv->priority_reg) + goto out_free_priority_reg; + nr_contexts = of_irq_count(node); if (WARN_ON(!nr_contexts)) - goto out_iounmap; + goto out_free_priority_reg; error = -ENOMEM; priv->irqdomain = irq_domain_add_linear(node, nr_irqs + 1, &plic_irqdomain_ops, priv); if (WARN_ON(!priv->irqdomain)) - goto out_iounmap; + goto out_free_priority_reg; for (i = 0; i < nr_contexts; i++) { struct of_phandle_args parent; @@ -461,11 +546,15 @@ static int __init __plic_init(struct device_node *node, plic_starting_cpu, plic_dying_cpu); plic_cpuhp_setup_done = true; } + plic_irq_pm_init(); pr_info("%pOFP: mapped %d interrupts with %d handlers for" " %d contexts.\n", node, nr_irqs, nr_handlers, nr_contexts); return 0; +out_free_priority_reg: + kfree(priv->priority_reg); + out_iounmap: iounmap(priv->regs); out_free_priv: -- 2.39.0