Skip to content

Commit eea1a28

Browse files
committed
openrisc: Fix IPIs on simple multicore systems
Commit c056718 ("openrisc: sleep instead of spin on secondary wait") fixed OpenRISC SMP Linux for QEMU. However, stability was never achieved on FPGA development boards. This is because the above patch has a step to unmask IPIs on non-boot cpu's but on hardware without power management, IPIs remain masked. This meant that IPI's were never actually working on the simple SMP systems we run on development boards. The systems booted but stability was very suspect. Add the ability to unmask IPI's on the non-boot cores. This is done by making the OMPIC IRQs proper percpu IRQs. We can then use the enabled_percpu_irq() to unmask IRQ on the non-boot cpus. Update the or1k PIC driver to use a flow handler that can switch between percpu and the configured level or edge flow handlers at runtime. This mechanism is inspired by that done in the J-Core AIC driver. Signed-off-by: Stafford Horne <shorne@gmail.com> Acked-by: Thomas Gleixner <tglx@kernel.org>
1 parent 111005c commit eea1a28

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

arch/openrisc/include/asm/smp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ extern void smp_init_cpus(void);
2020
extern void arch_send_call_function_single_ipi(int cpu);
2121
extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
2222

23-
extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int));
23+
extern void set_smp_cross_call(void (*)(const struct cpumask *, unsigned int),
24+
unsigned int irq);
2425
extern void handle_IPI(unsigned int ipi_msg);
2526

2627
#endif /* __ASM_OPENRISC_SMP_H */

arch/openrisc/kernel/smp.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <linux/smp.h>
1515
#include <linux/cpu.h>
16+
#include <linux/interrupt.h>
1617
#include <linux/sched.h>
1718
#include <linux/sched/mm.h>
1819
#include <linux/irq.h>
@@ -25,6 +26,7 @@
2526

2627
asmlinkage __init void secondary_start_kernel(void);
2728

29+
static unsigned int ipi_irq __ro_after_init;
2830
static void (*smp_cross_call)(const struct cpumask *, unsigned int);
2931

3032
unsigned long secondary_release = -1;
@@ -39,6 +41,14 @@ enum ipi_msg_type {
3941

4042
static DEFINE_SPINLOCK(boot_lock);
4143

44+
static void or1k_ipi_enable(void)
45+
{
46+
if (WARN_ON_ONCE(!ipi_irq))
47+
return;
48+
49+
enable_percpu_irq(ipi_irq, 0);
50+
}
51+
4252
static void boot_secondary(unsigned int cpu, struct task_struct *idle)
4353
{
4454
/*
@@ -136,6 +146,7 @@ asmlinkage __init void secondary_start_kernel(void)
136146
complete(&cpu_running);
137147

138148
synchronise_count_slave(cpu);
149+
or1k_ipi_enable();
139150
set_cpu_online(cpu, true);
140151

141152
local_irq_enable();
@@ -195,9 +206,18 @@ void smp_send_stop(void)
195206
smp_call_function(stop_this_cpu, NULL, 0);
196207
}
197208

198-
void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
209+
void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int),
210+
unsigned int irq)
199211
{
212+
if (WARN_ON(ipi_irq))
213+
return;
214+
200215
smp_cross_call = fn;
216+
217+
ipi_irq = irq;
218+
219+
/* Enabled IPIs for boot CPU immediately */
220+
or1k_ipi_enable();
201221
}
202222

203223
void arch_send_call_function_single_ipi(int cpu)

drivers/irqchip/irq-ompic.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ DEFINE_PER_CPU(unsigned long, ops);
8484

8585
static void __iomem *ompic_base;
8686

87+
static DEFINE_PER_CPU_READ_MOSTLY(int, ipi_dummy_dev);
88+
8789
static inline u32 ompic_readreg(void __iomem *base, loff_t offset)
8890
{
8991
return ioread32be(base + offset);
@@ -183,12 +185,17 @@ static int __init ompic_of_init(struct device_node *node,
183185
goto out_unmap;
184186
}
185187

186-
ret = request_irq(irq, ompic_ipi_handler, IRQF_PERCPU,
187-
"ompic_ipi", NULL);
188-
if (ret)
188+
irq_set_percpu_devid(irq);
189+
ret = request_percpu_irq(irq, ompic_ipi_handler, "ompic_ipi",
190+
&ipi_dummy_dev);
191+
192+
if (ret) {
193+
pr_err("ompic: failed to request irq %d, error: %d",
194+
irq, ret);
189195
goto out_irq_disp;
196+
}
190197

191-
set_smp_cross_call(ompic_raise_softirq);
198+
set_smp_cross_call(ompic_raise_softirq, irq);
192199

193200
return 0;
194201

drivers/irqchip/irq-or1k-pic.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,36 @@ static void or1k_pic_handle_irq(struct pt_regs *regs)
118118
generic_handle_domain_irq(root_domain, irq);
119119
}
120120

121+
/*
122+
* The OR1K PIC is a cpu-local interrupt controller and does not distinguish or
123+
* use distinct irq number ranges for per-cpu event interrupts (IPI). Since
124+
* information to determine whether a particular irq number should be treated as
125+
* per-cpu is not available at mapping time, we use a wrapper handler function
126+
* which chooses the right handler at runtime based on whether IRQF_PERCPU was
127+
* used when requesting the irq. Borrowed from J-Core AIC.
128+
*/
129+
static void or1k_irq_flow_handler(struct irq_desc *desc)
130+
{
131+
#ifdef CONFIG_SMP
132+
struct irq_data *data = irq_desc_get_irq_data(desc);
133+
struct or1k_pic_dev *pic = data->domain->host_data;
134+
135+
if (irqd_is_per_cpu(data))
136+
handle_percpu_devid_irq(desc);
137+
else
138+
pic->handle(desc);
139+
#endif
140+
}
141+
121142
static int or1k_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
122143
{
123144
struct or1k_pic_dev *pic = d->host_data;
124145

125-
irq_set_chip_and_handler(irq, &pic->chip, pic->handle);
146+
if (IS_ENABLED(CONFIG_SMP))
147+
irq_set_chip_and_handler(irq, &pic->chip, or1k_irq_flow_handler);
148+
else
149+
irq_set_chip_and_handler(irq, &pic->chip, pic->handle);
150+
126151
irq_set_status_flags(irq, pic->flags);
127152

128153
return 0;

0 commit comments

Comments
 (0)