1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/interrupt.h>
23#include <linux/smp.h>
24#include <linux/sched.h>
25
26#include <asm/sbi.h>
27#include <asm/tlbflush.h>
28#include <asm/cacheflush.h>
29
30
31static struct {
32 unsigned long bits ____cacheline_aligned;
33} ipi_data[NR_CPUS] __cacheline_aligned;
34
35enum ipi_message_type {
36 IPI_RESCHEDULE,
37 IPI_CALL_FUNC,
38 IPI_MAX
39};
40
41
42
43int setup_profiling_timer(unsigned int multiplier)
44{
45 return -EINVAL;
46}
47
48void riscv_software_interrupt(void)
49{
50 unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
51
52
53 csr_clear(sip, SIE_SSIE);
54
55 while (true) {
56 unsigned long ops;
57
58
59 mb();
60
61 ops = xchg(pending_ipis, 0);
62 if (ops == 0)
63 return;
64
65 if (ops & (1 << IPI_RESCHEDULE))
66 scheduler_ipi();
67
68 if (ops & (1 << IPI_CALL_FUNC))
69 generic_smp_call_function_interrupt();
70
71 BUG_ON((ops >> IPI_MAX) != 0);
72
73
74 mb();
75 }
76}
77
78static void
79send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
80{
81 int i;
82
83 mb();
84 for_each_cpu(i, to_whom)
85 set_bit(operation, &ipi_data[i].bits);
86
87 mb();
88 sbi_send_ipi(cpumask_bits(to_whom));
89}
90
91void arch_send_call_function_ipi_mask(struct cpumask *mask)
92{
93 send_ipi_message(mask, IPI_CALL_FUNC);
94}
95
96void arch_send_call_function_single_ipi(int cpu)
97{
98 send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
99}
100
101static void ipi_stop(void *unused)
102{
103 while (1)
104 wait_for_interrupt();
105}
106
107void smp_send_stop(void)
108{
109 on_each_cpu(ipi_stop, NULL, 1);
110}
111
112void smp_send_reschedule(int cpu)
113{
114 send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
115}
116
117
118
119
120
121
122
123
124
125
126
127void flush_icache_mm(struct mm_struct *mm, bool local)
128{
129 unsigned int cpu;
130 cpumask_t others, *mask;
131
132 preempt_disable();
133
134
135 mask = &mm->context.icache_stale_mask;
136 cpumask_setall(mask);
137
138 cpu = smp_processor_id();
139 cpumask_clear_cpu(cpu, mask);
140 local_flush_icache_all();
141
142
143
144
145
146 cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu));
147 local |= cpumask_empty(&others);
148 if (mm != current->active_mm || !local)
149 sbi_remote_fence_i(others.bits);
150 else {
151
152
153
154
155
156
157
158
159 smp_mb();
160 }
161
162 preempt_enable();
163}
164