Skip to content

Commit 316863c

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch/smp: Refine some ipi functions on LoongArch platform
Refine the ipi handling on LoongArch platform, there are three modifications: 1. Add generic function get_percpu_irq(), replacing some percpu irq functions such as get_ipi_irq()/get_pmc_irq()/get_timer_irq() with get_percpu_irq(). 2. Change definition about parameter action called by function loongson_send_ipi_single() and loongson_send_ipi_mask(), and it is defined as decimal encoding format at ipi sender side. Normal decimal encoding is used rather than binary bitmap encoding for ipi action, ipi hw sender uses decimal encoding code, and ipi receiver will get binary bitmap encoding, the ipi hw will convert it into bitmap in ipi message buffer. 3. Add a structure smp_ops on LoongArch platform so that pv ipi can be used later. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent dd5a440 commit 316863c

File tree

7 files changed

+63
-71
lines changed

7 files changed

+63
-71
lines changed

arch/loongarch/include/asm/hardirq.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern void ack_bad_irq(unsigned int irq);
1414

1515
#define NR_IPI 2
1616

17+
enum ipi_msg_type {
18+
IPI_RESCHEDULE,
19+
IPI_CALL_FUNCTION,
20+
};
21+
1722
typedef struct {
1823
unsigned int ipi_irqs[NR_IPI];
1924
unsigned int __softirq_pending;

arch/loongarch/include/asm/irq.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ extern struct fwnode_handle *liointc_handle;
117117
extern struct fwnode_handle *pch_lpc_handle;
118118
extern struct fwnode_handle *pch_pic_handle[MAX_IO_PICS];
119119

120-
extern irqreturn_t loongson_ipi_interrupt(int irq, void *dev);
120+
static inline int get_percpu_irq(int vector)
121+
{
122+
struct irq_domain *d;
123+
124+
d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
125+
if (d)
126+
return irq_create_mapping(d, vector);
127+
128+
return -EINVAL;
129+
}
121130

122131
#include <asm-generic/irq.h>
123132

arch/loongarch/include/asm/smp.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
#include <linux/threads.h>
1313
#include <linux/cpumask.h>
1414

15+
struct smp_ops {
16+
void (*init_ipi)(void);
17+
void (*send_ipi_single)(int cpu, unsigned int action);
18+
void (*send_ipi_mask)(const struct cpumask *mask, unsigned int action);
19+
};
20+
extern struct smp_ops mp_ops;
21+
1522
extern int smp_num_siblings;
1623
extern int num_processors;
1724
extern int disabled_cpus;
@@ -24,8 +31,6 @@ void loongson_prepare_cpus(unsigned int max_cpus);
2431
void loongson_boot_secondary(int cpu, struct task_struct *idle);
2532
void loongson_init_secondary(void);
2633
void loongson_smp_finish(void);
27-
void loongson_send_ipi_single(int cpu, unsigned int action);
28-
void loongson_send_ipi_mask(const struct cpumask *mask, unsigned int action);
2934
#ifdef CONFIG_HOTPLUG_CPU
3035
int loongson_cpu_disable(void);
3136
void loongson_cpu_die(unsigned int cpu);
@@ -59,9 +64,12 @@ extern int __cpu_logical_map[NR_CPUS];
5964

6065
#define cpu_physical_id(cpu) cpu_logical_map(cpu)
6166

62-
#define SMP_BOOT_CPU 0x1
63-
#define SMP_RESCHEDULE 0x2
64-
#define SMP_CALL_FUNCTION 0x4
67+
#define ACTION_BOOT_CPU 0
68+
#define ACTION_RESCHEDULE 1
69+
#define ACTION_CALL_FUNCTION 2
70+
#define SMP_BOOT_CPU BIT(ACTION_BOOT_CPU)
71+
#define SMP_RESCHEDULE BIT(ACTION_RESCHEDULE)
72+
#define SMP_CALL_FUNCTION BIT(ACTION_CALL_FUNCTION)
6573

6674
struct secondary_data {
6775
unsigned long stack;
@@ -81,12 +89,12 @@ extern void show_ipi_list(struct seq_file *p, int prec);
8189

8290
static inline void arch_send_call_function_single_ipi(int cpu)
8391
{
84-
loongson_send_ipi_single(cpu, SMP_CALL_FUNCTION);
92+
mp_ops.send_ipi_single(cpu, ACTION_CALL_FUNCTION);
8593
}
8694

8795
static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
8896
{
89-
loongson_send_ipi_mask(mask, SMP_CALL_FUNCTION);
97+
mp_ops.send_ipi_mask(mask, ACTION_CALL_FUNCTION);
9098
}
9199

92100
#ifdef CONFIG_HOTPLUG_CPU

arch/loongarch/kernel/irq.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,9 @@ static void __init init_vec_parent_group(void)
8787
acpi_table_parse(ACPI_SIG_MCFG, early_pci_mcfg_parse);
8888
}
8989

90-
static int __init get_ipi_irq(void)
91-
{
92-
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
93-
94-
if (d)
95-
return irq_create_mapping(d, INT_IPI);
96-
97-
return -EINVAL;
98-
}
99-
10090
void __init init_IRQ(void)
10191
{
10292
int i;
103-
#ifdef CONFIG_SMP
104-
int r, ipi_irq;
105-
static int ipi_dummy_dev;
106-
#endif
10793
unsigned int order = get_order(IRQ_STACK_SIZE);
10894
struct page *page;
10995

@@ -113,13 +99,7 @@ void __init init_IRQ(void)
11399
init_vec_parent_group();
114100
irqchip_init();
115101
#ifdef CONFIG_SMP
116-
ipi_irq = get_ipi_irq();
117-
if (ipi_irq < 0)
118-
panic("IPI IRQ mapping failed\n");
119-
irq_set_percpu_devid(ipi_irq);
120-
r = request_percpu_irq(ipi_irq, loongson_ipi_interrupt, "IPI", &ipi_dummy_dev);
121-
if (r < 0)
122-
panic("IPI IRQ request failed\n");
102+
mp_ops.init_ipi();
123103
#endif
124104

125105
for (i = 0; i < NR_IRQS; i++)

arch/loongarch/kernel/perf_event.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,24 +456,14 @@ static void loongarch_pmu_disable(struct pmu *pmu)
456456
static DEFINE_MUTEX(pmu_reserve_mutex);
457457
static atomic_t active_events = ATOMIC_INIT(0);
458458

459-
static int get_pmc_irq(void)
460-
{
461-
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
462-
463-
if (d)
464-
return irq_create_mapping(d, INT_PCOV);
465-
466-
return -EINVAL;
467-
}
468-
469459
static void reset_counters(void *arg);
470460
static int __hw_perf_event_init(struct perf_event *event);
471461

472462
static void hw_perf_event_destroy(struct perf_event *event)
473463
{
474464
if (atomic_dec_and_mutex_lock(&active_events, &pmu_reserve_mutex)) {
475465
on_each_cpu(reset_counters, NULL, 1);
476-
free_irq(get_pmc_irq(), &loongarch_pmu);
466+
free_irq(get_percpu_irq(INT_PCOV), &loongarch_pmu);
477467
mutex_unlock(&pmu_reserve_mutex);
478468
}
479469
}
@@ -562,7 +552,7 @@ static int loongarch_pmu_event_init(struct perf_event *event)
562552
if (event->cpu >= 0 && !cpu_online(event->cpu))
563553
return -ENODEV;
564554

565-
irq = get_pmc_irq();
555+
irq = get_percpu_irq(INT_PCOV);
566556
flags = IRQF_PERCPU | IRQF_NOBALANCING | IRQF_NO_THREAD | IRQF_NO_SUSPEND | IRQF_SHARED;
567557
if (!atomic_inc_not_zero(&active_events)) {
568558
mutex_lock(&pmu_reserve_mutex);

arch/loongarch/kernel/smp.c

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ static cpumask_t cpu_core_setup_map;
6666
struct secondary_data cpuboot_data;
6767
static DEFINE_PER_CPU(int, cpu_state);
6868

69-
enum ipi_msg_type {
70-
IPI_RESCHEDULE,
71-
IPI_CALL_FUNCTION,
72-
};
73-
7469
static const char *ipi_types[NR_IPI] __tracepoint_string = {
7570
[IPI_RESCHEDULE] = "Rescheduling interrupts",
7671
[IPI_CALL_FUNCTION] = "Function call interrupts",
@@ -190,24 +185,19 @@ static u32 ipi_read_clear(int cpu)
190185

191186
static void ipi_write_action(int cpu, u32 action)
192187
{
193-
unsigned int irq = 0;
194-
195-
while ((irq = ffs(action))) {
196-
uint32_t val = IOCSR_IPI_SEND_BLOCKING;
188+
uint32_t val;
197189

198-
val |= (irq - 1);
199-
val |= (cpu << IOCSR_IPI_SEND_CPU_SHIFT);
200-
iocsr_write32(val, LOONGARCH_IOCSR_IPI_SEND);
201-
action &= ~BIT(irq - 1);
202-
}
190+
val = IOCSR_IPI_SEND_BLOCKING | action;
191+
val |= (cpu << IOCSR_IPI_SEND_CPU_SHIFT);
192+
iocsr_write32(val, LOONGARCH_IOCSR_IPI_SEND);
203193
}
204194

205-
void loongson_send_ipi_single(int cpu, unsigned int action)
195+
static void loongson_send_ipi_single(int cpu, unsigned int action)
206196
{
207197
ipi_write_action(cpu_logical_map(cpu), (u32)action);
208198
}
209199

210-
void loongson_send_ipi_mask(const struct cpumask *mask, unsigned int action)
200+
static void loongson_send_ipi_mask(const struct cpumask *mask, unsigned int action)
211201
{
212202
unsigned int i;
213203

@@ -222,11 +212,11 @@ void loongson_send_ipi_mask(const struct cpumask *mask, unsigned int action)
222212
*/
223213
void arch_smp_send_reschedule(int cpu)
224214
{
225-
loongson_send_ipi_single(cpu, SMP_RESCHEDULE);
215+
mp_ops.send_ipi_single(cpu, ACTION_RESCHEDULE);
226216
}
227217
EXPORT_SYMBOL_GPL(arch_smp_send_reschedule);
228218

229-
irqreturn_t loongson_ipi_interrupt(int irq, void *dev)
219+
static irqreturn_t loongson_ipi_interrupt(int irq, void *dev)
230220
{
231221
unsigned int action;
232222
unsigned int cpu = smp_processor_id();
@@ -246,6 +236,26 @@ irqreturn_t loongson_ipi_interrupt(int irq, void *dev)
246236
return IRQ_HANDLED;
247237
}
248238

239+
static void loongson_init_ipi(void)
240+
{
241+
int r, ipi_irq;
242+
243+
ipi_irq = get_percpu_irq(INT_IPI);
244+
if (ipi_irq < 0)
245+
panic("IPI IRQ mapping failed\n");
246+
247+
irq_set_percpu_devid(ipi_irq);
248+
r = request_percpu_irq(ipi_irq, loongson_ipi_interrupt, "IPI", &irq_stat);
249+
if (r < 0)
250+
panic("IPI IRQ request failed\n");
251+
}
252+
253+
struct smp_ops mp_ops = {
254+
.init_ipi = loongson_init_ipi,
255+
.send_ipi_single = loongson_send_ipi_single,
256+
.send_ipi_mask = loongson_send_ipi_mask,
257+
};
258+
249259
static void __init fdt_smp_setup(void)
250260
{
251261
#ifdef CONFIG_OF
@@ -323,7 +333,7 @@ void loongson_boot_secondary(int cpu, struct task_struct *idle)
323333

324334
csr_mail_send(entry, cpu_logical_map(cpu), 0);
325335

326-
loongson_send_ipi_single(cpu, SMP_BOOT_CPU);
336+
loongson_send_ipi_single(cpu, ACTION_BOOT_CPU);
327337
}
328338

329339
/*

arch/loongarch/kernel/time.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ void sync_counter(void)
123123
csr_write64(init_offset, LOONGARCH_CSR_CNTC);
124124
}
125125

126-
static int get_timer_irq(void)
127-
{
128-
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
129-
130-
if (d)
131-
return irq_create_mapping(d, INT_TI);
132-
133-
return -EINVAL;
134-
}
135-
136126
int constant_clockevent_init(void)
137127
{
138128
unsigned int cpu = smp_processor_id();
@@ -142,7 +132,7 @@ int constant_clockevent_init(void)
142132
static int irq = 0, timer_irq_installed = 0;
143133

144134
if (!timer_irq_installed) {
145-
irq = get_timer_irq();
135+
irq = get_percpu_irq(INT_TI);
146136
if (irq < 0)
147137
pr_err("Failed to map irq %d (timer)\n", irq);
148138
}

0 commit comments

Comments
 (0)