Skip to content

Commit 14ff9e5

Browse files
Charles MirabileKAGA-KOKO
authored andcommitted
irqchip/sifive-plic: Cache the interrupt enable state
Optimize the PLIC driver by maintaining the interrupt enable state in the handler's enable_save array during normal operation rather than only during suspend/resume. This eliminates the need to read enable registers during suspend and makes the enable state immediately available for other purposes. Let __plic_toggle() update both the hardware registers and the cached enable_save state atomically within the existing enable_lock protection. That allows to remove the suspend-time enable register reading since handler::enable_save now always reflects the current state. [ tglx: Massaged change log ] Signed-off-by: Charles Mirabile <cmirabil@redhat.com> Signed-off-by: Lucas Zampieri <lzampier@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://patch.msgid.link/20251024083647.475239-4-lzampier@redhat.com
1 parent 9dfb295 commit 14ff9e5

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

drivers/irqchip/irq-sifive-plic.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,30 @@ static DEFINE_PER_CPU(struct plic_handler, plic_handlers);
9494

9595
static int plic_irq_set_type(struct irq_data *d, unsigned int type);
9696

97-
static void __plic_toggle(void __iomem *enable_base, int hwirq, int enable)
97+
static void __plic_toggle(struct plic_handler *handler, int hwirq, int enable)
9898
{
99-
u32 __iomem *reg = enable_base + (hwirq / 32) * sizeof(u32);
99+
u32 __iomem *base = handler->enable_base;
100100
u32 hwirq_mask = 1 << (hwirq % 32);
101+
int group = hwirq / 32;
102+
u32 value;
103+
104+
value = readl(base + group);
101105

102106
if (enable)
103-
writel(readl(reg) | hwirq_mask, reg);
107+
value |= hwirq_mask;
104108
else
105-
writel(readl(reg) & ~hwirq_mask, reg);
109+
value &= ~hwirq_mask;
110+
111+
handler->enable_save[group] = value;
112+
writel(value, base + group);
106113
}
107114

108115
static void plic_toggle(struct plic_handler *handler, int hwirq, int enable)
109116
{
110117
unsigned long flags;
111118

112119
raw_spin_lock_irqsave(&handler->enable_lock, flags);
113-
__plic_toggle(handler->enable_base, hwirq, enable);
120+
__plic_toggle(handler, hwirq, enable);
114121
raw_spin_unlock_irqrestore(&handler->enable_lock, flags);
115122
}
116123

@@ -247,33 +254,16 @@ static int plic_irq_set_type(struct irq_data *d, unsigned int type)
247254

248255
static int plic_irq_suspend(void)
249256
{
250-
unsigned int i, cpu;
251-
unsigned long flags;
252-
u32 __iomem *reg;
253257
struct plic_priv *priv;
254258

255259
priv = per_cpu_ptr(&plic_handlers, smp_processor_id())->priv;
256260

257261
/* irq ID 0 is reserved */
258-
for (i = 1; i < priv->nr_irqs; i++) {
262+
for (unsigned int i = 1; i < priv->nr_irqs; i++) {
259263
__assign_bit(i, priv->prio_save,
260264
readl(priv->regs + PRIORITY_BASE + i * PRIORITY_PER_ID));
261265
}
262266

263-
for_each_present_cpu(cpu) {
264-
struct plic_handler *handler = per_cpu_ptr(&plic_handlers, cpu);
265-
266-
if (!handler->present)
267-
continue;
268-
269-
raw_spin_lock_irqsave(&handler->enable_lock, flags);
270-
for (i = 0; i < DIV_ROUND_UP(priv->nr_irqs, 32); i++) {
271-
reg = handler->enable_base + i * sizeof(u32);
272-
handler->enable_save[i] = readl(reg);
273-
}
274-
raw_spin_unlock_irqrestore(&handler->enable_lock, flags);
275-
}
276-
277267
return 0;
278268
}
279269

0 commit comments

Comments
 (0)