Skip to content

Commit f48b4bd

Browse files
nick650823KAGA-KOKO
authored andcommitted
irqchip/riscv-imsic: Add a CPU pm notifier to restore the IMSIC on exit
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. Signed-off-by: Nick Hu <nick.hu@sifive.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> Reviewed-by: Cyan Yang <cyan.yang@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Nutty Liu <liujingqi@lanxincomputing.com> Link: https://patch.msgid.link/20251202-preserve-aplic-imsic-v3-1-1844fbf1fe92@sifive.com
1 parent 97232dc commit f48b4bd

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

drivers/irqchip/irq-riscv-imsic-early.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define pr_fmt(fmt) "riscv-imsic: " fmt
88
#include <linux/acpi.h>
99
#include <linux/cpu.h>
10+
#include <linux/cpu_pm.h>
1011
#include <linux/export.h>
1112
#include <linux/interrupt.h>
1213
#include <linux/init.h>
@@ -123,14 +124,8 @@ static void imsic_handle_irq(struct irq_desc *desc)
123124
chained_irq_exit(chip, desc);
124125
}
125126

126-
static int imsic_starting_cpu(unsigned int cpu)
127+
static void imsic_hw_states_init(void)
127128
{
128-
/* Mark per-CPU IMSIC state as online */
129-
imsic_state_online();
130-
131-
/* Enable per-CPU parent interrupt */
132-
enable_percpu_irq(imsic_parent_irq, irq_get_trigger_type(imsic_parent_irq));
133-
134129
/* Setup IPIs */
135130
imsic_ipi_starting_cpu();
136131

@@ -142,6 +137,18 @@ static int imsic_starting_cpu(unsigned int cpu)
142137

143138
/* Enable local interrupt delivery */
144139
imsic_local_delivery(true);
140+
}
141+
142+
static int imsic_starting_cpu(unsigned int cpu)
143+
{
144+
/* Mark per-CPU IMSIC state as online */
145+
imsic_state_online();
146+
147+
/* Enable per-CPU parent interrupt */
148+
enable_percpu_irq(imsic_parent_irq, irq_get_trigger_type(imsic_parent_irq));
149+
150+
/* Initialize the IMSIC registers to enable the interrupt delivery */
151+
imsic_hw_states_init();
145152

146153
return 0;
147154
}
@@ -157,6 +164,22 @@ static int imsic_dying_cpu(unsigned int cpu)
157164
return 0;
158165
}
159166

167+
static int imsic_pm_notifier(struct notifier_block *self, unsigned long cmd, void *v)
168+
{
169+
switch (cmd) {
170+
case CPU_PM_EXIT:
171+
/* Initialize the IMSIC registers to enable the interrupt delivery */
172+
imsic_hw_states_init();
173+
break;
174+
}
175+
176+
return NOTIFY_OK;
177+
}
178+
179+
static struct notifier_block imsic_pm_notifier_block = {
180+
.notifier_call = imsic_pm_notifier,
181+
};
182+
160183
static int __init imsic_early_probe(struct fwnode_handle *fwnode)
161184
{
162185
struct irq_domain *domain;
@@ -194,7 +217,7 @@ static int __init imsic_early_probe(struct fwnode_handle *fwnode)
194217
cpuhp_setup_state(CPUHP_AP_IRQ_RISCV_IMSIC_STARTING, "irqchip/riscv/imsic:starting",
195218
imsic_starting_cpu, imsic_dying_cpu);
196219

197-
return 0;
220+
return cpu_pm_register_notifier(&imsic_pm_notifier_block);
198221
}
199222

200223
static int __init imsic_early_dt_init(struct device_node *node, struct device_node *parent)

0 commit comments

Comments
 (0)