From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E51411B142D for ; Tue, 2 Dec 2025 06:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764655287; cv=none; b=XoH4POdARqd7cedjVD9+bNWNqy79CFOYNOZoubGW/Mb4MzmpgsdF0vPC5pONVCLvf8/i3g9NM6khyzr7fPZJaXlKr5UkFlo7ElVbA00usjOZDD165x8YQoaO0rjszctHN+b20UWmtuIC1DroMXbSyBorAPHrtIPIpWeXlbv+APk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764655287; c=relaxed/simple; bh=N4kt44cpQ0wWrZGKssR0ItUmuPwHOPpCy4YqsMkPX5s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EbhKn1SeQ6IKv4H4A1+CF8h0EQhetNos6UEN+QuIner0ro9UZaN7bn/0e7aMIyajB8bZGYmRayAnkbDIv83brgr+xTfOhzxd0rjd0A6iydgjBnSeNHN91KwyNX6jKXw641QNrfHtFfADSBpASGVVRAwn4ILe6xi7IWh83FqSPJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=LXU1jCvI; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="LXU1jCvI" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-343ee44d89aso7091572a91.2 for ; Mon, 01 Dec 2025 22:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1764655285; x=1765260085; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Z+0bwtwpEeyVYpmofwpoipaViqDC4tDJleo3CtFrHJI=; b=LXU1jCvIKi5UbioYBHnh3nMHVgSbygTGn8hO5pr6sIY1zoYpdrQTgItnelCoE/Y3N9 JabI7o5Cp2oHStiHBKyhTa/Ij2KKJFUmSBCzrsY5kbAM88LGlXBZjgbI4HbOl6NnuNwc Q3Axb/dXVXgk2Iojw0iaSHHhY04B9DDqrX1T7LShL2Q6IGLkeeiNsYY0ieXZ/yyWfeON 4vIymITVyiUUAKaBfDlL0ATGN+kBpmQhfyjerdAloGJaERQLJxTLMiQM7K9v7bW+x2ZL PJLV4jOSbRsqTpQaX0AOOF6gj/uaYa9JsARraDNNMJFwdtWiCnX+JfY4A1ZtaKrfDtON pLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764655285; x=1765260085; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Z+0bwtwpEeyVYpmofwpoipaViqDC4tDJleo3CtFrHJI=; b=IS0YYzr16I5Lh76NF+6AxqJWF0YjyswP9dCKZ5XuRVGWL/U1L8cvas5c46G0uk6RWq Z0j1fNafIg/Zdgw5Cg+XmzAbJ1hSgjOIde1Mzgt6EV13YSYBk+4mZrAZZZtQDOk8xvjt lAULIPvPWqxm/4bvtQIduZ8TF9qpskVyrd43VFeFW5xjmBFbbSrNlzk5lVjn9x4cDumK f6AkUmvgW8HoXbWiVNA3Ilc+bANsjicyZ8BOg7ZLR5LmtCTlro4arFw5ssYBEasD6o+J ws+H7MrbqNRbHGdQufQOsok7dWRriIAZ5qaNpCBFjNXtrH7MXhzzx8m/RHAIKekV8IdV leWA== X-Forwarded-Encrypted: i=1; AJvYcCXNluzuiCcr5D+2mTGLw42bdTdkABs+ulIvdv3qdOuvFzq00tw1OkVFtSMIDzt7SbGGzluKAYBAPdI/P8s=@vger.kernel.org X-Gm-Message-State: AOJu0YypjMBEx/tde43FK1klV/VxkAUj5AeHRoUwBNXq9Vy8N9umkVdK /EXFL5SjpaOQ2XLpPa+qh2yRGrbKmd69fXXODuOUPlODsCt1OR4RIPKF2i4NHOhbfTQ= X-Gm-Gg: ASbGncvIneNKMJXu9C+/D8qocByhrktZHsvca3345cnNY/KfMzHwkooGLpNEc4XqgrZ tdjZeotHDleOZ4Xj2+ZiY3hgAwgV4Y75NbmFamvrPtim7uLRpPQUklnFgcJ/X9cKB4ai12uzQT/ mIkt9xYMWXCTmaaGbXRFb3IPueDVSImCm1ALAE20cv1Yn7ETKKsHfUOLnVql/OGe54m8j8yOdat NlaeZHbtyrjRmEKdrXvJ+Lugz0JjivpHwbmauyBxUq0ECQtq1qG/eS0rwLrtZpL9f79Jry25ZyF SkBOhYiuzGr3cNL1n5/Hl/+qFlORh9wVbbS3C0Mrx/KkFf2cC2mQpqcWnzFpptMoxG+vo9yrXaN g+v0wBs5u8RpyskSKsNkYLAjvY0J9vTPNNHjpWuxUCG1t+imryHmwcvwgRNfJQFHwZXNv5lOGYg YAIj4NLfWk X-Google-Smtp-Source: AGHT+IEnfEWG66It067xSAX9BxgaSPW2cyBqDhkU4hrpj7sZyUsCv1ote9pGTUAbus8Lyv4F4oawAg== X-Received: by 2002:a17:90b:3841:b0:343:6d82:9278 with SMTP id 98e67ed59e1d1-34733f36040mr37615818a91.30.1764655284576; Mon, 01 Dec 2025 22:01:24 -0800 (PST) Received: from [127.0.1.1] ([210.176.154.34]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3476a547483sm19083810a91.4.2025.12.01.22.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 22:01:24 -0800 (PST) From: Nick Hu Date: Tue, 02 Dec 2025 14:07:40 +0800 Subject: [PATCH v3 1/2] irqchip/riscv-imsic: Add a CPU pm notifier to restore the IMSIC on exit Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20251202-preserve-aplic-imsic-v3-1-1844fbf1fe92@sifive.com> References: <20251202-preserve-aplic-imsic-v3-0-1844fbf1fe92@sifive.com> In-Reply-To: <20251202-preserve-aplic-imsic-v3-0-1844fbf1fe92@sifive.com> To: Anup Patel , Thomas Gleixner , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Yong-Xuan Wang , Cyan Yang , Nutty Liu , Nick Hu X-Mailer: b4 0.14.2 The IMSIC might be reset when the system enters a low power state, but on exit nothing restores the registers, which prevents interrupt delivery. Solve this by registering a CPU power management notifier, which restores the IMSIC on exit. Reviewed-by: Yong-Xuan Wang Reviewed-by: Cyan Yang Reviewed-by: Anup Patel Reviewed-by: Nutty Liu Signed-off-by: Nick Hu --- drivers/irqchip/irq-riscv-imsic-early.c | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-riscv-imsic-early.c index 2c4c682627b8cc81ad51a98a1f341aa506d649ac..d1727c343c38f6f88a25b3327aaa080c1cfe3078 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -7,6 +7,7 @@ #define pr_fmt(fmt) "riscv-imsic: " fmt #include #include +#include #include #include #include @@ -128,14 +129,8 @@ static void imsic_handle_irq(struct irq_desc *desc) chained_irq_exit(chip, desc); } -static int imsic_starting_cpu(unsigned int cpu) +static void imsic_hw_states_init(void) { - /* Mark per-CPU IMSIC state as online */ - imsic_state_online(); - - /* Enable per-CPU parent interrupt */ - enable_percpu_irq(imsic_parent_irq, irq_get_trigger_type(imsic_parent_irq)); - /* Setup IPIs */ imsic_ipi_starting_cpu(); @@ -147,6 +142,18 @@ static int imsic_starting_cpu(unsigned int cpu) /* Enable local interrupt delivery */ imsic_local_delivery(true); +} + +static int imsic_starting_cpu(unsigned int cpu) +{ + /* Mark per-CPU IMSIC state as online */ + imsic_state_online(); + + /* Enable per-CPU parent interrupt */ + enable_percpu_irq(imsic_parent_irq, irq_get_trigger_type(imsic_parent_irq)); + + /* Initialize the IMSIC registers to enable the interrupt delivery */ + imsic_hw_states_init(); return 0; } @@ -162,6 +169,22 @@ static int imsic_dying_cpu(unsigned int cpu) return 0; } +static int imsic_pm_notifier(struct notifier_block *self, unsigned long cmd, void *v) +{ + switch (cmd) { + case CPU_PM_EXIT: + /* Initialize the IMSIC registers to enable the interrupt delivery */ + imsic_hw_states_init(); + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block imsic_pm_notifier_block = { + .notifier_call = imsic_pm_notifier, +}; + static int __init imsic_early_probe(struct fwnode_handle *fwnode) { struct irq_domain *domain; @@ -199,7 +222,7 @@ static int __init imsic_early_probe(struct fwnode_handle *fwnode) cpuhp_setup_state(CPUHP_AP_IRQ_RISCV_IMSIC_STARTING, "irqchip/riscv/imsic:starting", imsic_starting_cpu, imsic_dying_cpu); - return 0; + return cpu_pm_register_notifier(&imsic_pm_notifier_block); } static int __init imsic_early_dt_init(struct device_node *node, struct device_node *parent) -- 2.34.1