2 * SMP initialisation and IPI support
3 * Based on arch/arm64/kernel/smp.c
5 * Copyright (C) 2012 ARM Ltd.
6 * Copyright (C) 2015 Regents of the University of California
7 * Copyright (C) 2017 SiFive
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <linux/interrupt.h>
23 #include <linux/smp.h>
24 #include <linux/sched.h>
27 #include <asm/tlbflush.h>
28 #include <asm/cacheflush.h>
30 /* A collection of single bit ipi messages. */
32 unsigned long bits ____cacheline_aligned
;
33 } ipi_data
[NR_CPUS
] __cacheline_aligned
;
35 enum ipi_message_type
{
41 irqreturn_t
handle_ipi(void)
43 unsigned long *pending_ipis
= &ipi_data
[smp_processor_id()].bits
;
45 /* Clear pending IPI */
46 csr_clear(sip
, SIE_SSIE
);
51 /* Order bit clearing and data access. */
54 ops
= xchg(pending_ipis
, 0);
58 if (ops
& (1 << IPI_RESCHEDULE
))
61 if (ops
& (1 << IPI_CALL_FUNC
))
62 generic_smp_call_function_interrupt();
64 BUG_ON((ops
>> IPI_MAX
) != 0);
66 /* Order data access and bit testing. */
74 send_ipi_message(const struct cpumask
*to_whom
, enum ipi_message_type operation
)
79 for_each_cpu(i
, to_whom
)
80 set_bit(operation
, &ipi_data
[i
].bits
);
83 sbi_send_ipi(cpumask_bits(to_whom
));
86 void arch_send_call_function_ipi_mask(struct cpumask
*mask
)
88 send_ipi_message(mask
, IPI_CALL_FUNC
);
91 void arch_send_call_function_single_ipi(int cpu
)
93 send_ipi_message(cpumask_of(cpu
), IPI_CALL_FUNC
);
96 static void ipi_stop(void *unused
)
102 void smp_send_stop(void)
104 on_each_cpu(ipi_stop
, NULL
, 1);
107 void smp_send_reschedule(int cpu
)
109 send_ipi_message(cpumask_of(cpu
), IPI_RESCHEDULE
);