Skip to content

Commit 4964610

Browse files
paulburtonKAGA-KOKO
authored andcommitted
irqchip/mips-gic: Replace open coded online CPU iterations
Several places in the MIPS GIC driver iterate over the online CPUs to operate on the CPU's GIC local register block, accessed via the GIC's other/redirect register block. Abstract the process of iterating over online CPUs & configuring the other/redirect region to access their registers through a new for_each_online_cpu_gic() macro and convert all usage sites over. Signed-off-by: Paul Burton <[email protected]> Signed-off-by: Chao-ying Fu <[email protected]> Signed-off-by: Dragan Mladjenovic <[email protected]> Signed-off-by: Aleksandar Rikalo <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Serge Semin <[email protected]> Tested-by: Gregory CLEMENT <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent d1a128b commit 4964610

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

drivers/irqchip/irq-mips-gic.c

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,44 @@ static struct gic_all_vpes_chip_data {
6666
bool mask;
6767
} gic_all_vpes_chip_data[GIC_NUM_LOCAL_INTRS];
6868

69+
static int __gic_with_next_online_cpu(int prev)
70+
{
71+
unsigned int cpu;
72+
73+
/* Discover the next online CPU */
74+
cpu = cpumask_next(prev, cpu_online_mask);
75+
76+
/* If there isn't one, we're done */
77+
if (cpu >= nr_cpu_ids)
78+
return cpu;
79+
80+
/*
81+
* Move the access lock to the next CPU's GIC local register block.
82+
*
83+
* Set GIC_VL_OTHER. Since the caller holds gic_lock nothing can
84+
* clobber the written value.
85+
*/
86+
write_gic_vl_other(mips_cm_vp_id(cpu));
87+
88+
return cpu;
89+
}
90+
91+
/**
92+
* for_each_online_cpu_gic() - Iterate over online CPUs, access local registers
93+
* @cpu: An integer variable to hold the current CPU number
94+
* @gic_lock: A pointer to raw spin lock used as a guard
95+
*
96+
* Iterate over online CPUs & configure the other/redirect register region to
97+
* access each CPUs GIC local register block, which can be accessed from the
98+
* loop body using read_gic_vo_*() or write_gic_vo_*() accessor functions or
99+
* their derivatives.
100+
*/
101+
#define for_each_online_cpu_gic(cpu, gic_lock) \
102+
guard(raw_spinlock_irqsave)(gic_lock); \
103+
for ((cpu) = __gic_with_next_online_cpu(-1); \
104+
(cpu) < nr_cpu_ids; \
105+
(cpu) = __gic_with_next_online_cpu(cpu))
106+
69107
static void gic_clear_pcpu_masks(unsigned int intr)
70108
{
71109
unsigned int i;
@@ -350,37 +388,27 @@ static struct irq_chip gic_local_irq_controller = {
350388
static void gic_mask_local_irq_all_vpes(struct irq_data *d)
351389
{
352390
struct gic_all_vpes_chip_data *cd;
353-
unsigned long flags;
354391
int intr, cpu;
355392

356393
intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
357394
cd = irq_data_get_irq_chip_data(d);
358395
cd->mask = false;
359396

360-
raw_spin_lock_irqsave(&gic_lock, flags);
361-
for_each_online_cpu(cpu) {
362-
write_gic_vl_other(mips_cm_vp_id(cpu));
397+
for_each_online_cpu_gic(cpu, &gic_lock)
363398
write_gic_vo_rmask(BIT(intr));
364-
}
365-
raw_spin_unlock_irqrestore(&gic_lock, flags);
366399
}
367400

368401
static void gic_unmask_local_irq_all_vpes(struct irq_data *d)
369402
{
370403
struct gic_all_vpes_chip_data *cd;
371-
unsigned long flags;
372404
int intr, cpu;
373405

374406
intr = GIC_HWIRQ_TO_LOCAL(d->hwirq);
375407
cd = irq_data_get_irq_chip_data(d);
376408
cd->mask = true;
377409

378-
raw_spin_lock_irqsave(&gic_lock, flags);
379-
for_each_online_cpu(cpu) {
380-
write_gic_vl_other(mips_cm_vp_id(cpu));
410+
for_each_online_cpu_gic(cpu, &gic_lock)
381411
write_gic_vo_smask(BIT(intr));
382-
}
383-
raw_spin_unlock_irqrestore(&gic_lock, flags);
384412
}
385413

386414
static void gic_all_vpes_irq_cpu_online(void)
@@ -469,7 +497,6 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
469497
irq_hw_number_t hwirq)
470498
{
471499
struct gic_all_vpes_chip_data *cd;
472-
unsigned long flags;
473500
unsigned int intr;
474501
int err, cpu;
475502
u32 map;
@@ -533,12 +560,8 @@ static int gic_irq_domain_map(struct irq_domain *d, unsigned int virq,
533560
if (!gic_local_irq_is_routable(intr))
534561
return -EPERM;
535562

536-
raw_spin_lock_irqsave(&gic_lock, flags);
537-
for_each_online_cpu(cpu) {
538-
write_gic_vl_other(mips_cm_vp_id(cpu));
563+
for_each_online_cpu_gic(cpu, &gic_lock)
539564
write_gic_vo_map(mips_gic_vx_map_reg(intr), map);
540-
}
541-
raw_spin_unlock_irqrestore(&gic_lock, flags);
542565

543566
return 0;
544567
}

0 commit comments

Comments
 (0)