projects/linux·blob master · refs

72 lines · 1.5 KiB

1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Uniprocessor-only support functions. The counterpart to kernel/smp.c
4 */
5
6#include <linux/interrupt.h>
7#include <linux/kernel.h>
8#include <linux/export.h>
9#include <linux/smp.h>
10#include <linux/hypervisor.h>
11
12int smp_call_function_single(int cpu, void (*func)(void *info), void *info, bool wait)
13{
14 unsigned long flags;
15
16 if (cpu != 0)
17 return -ENXIO;
18
19 local_irq_save(flags);
20 func(info);
21 local_irq_restore(flags);
22
23 return 0;
24}
25EXPORT_SYMBOL(smp_call_function_single);
26
27int smp_call_function_single_async(int cpu, call_single_data_t *csd)
28{
29 unsigned long flags;
30
31 local_irq_save(flags);
32 csd->func(csd->info);
33 local_irq_restore(flags);
34 return 0;
35}
36EXPORT_SYMBOL(smp_call_function_single_async);
37
38/*
39 * Preemption is disabled here to make sure the cond_func is called under the
40 * same conditions in UP and SMP.
41 */
42void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
43 void *info, bool wait, const struct cpumask *mask)
44{
45 unsigned long flags;
46
47 preempt_disable();
48 if ((!cond_func || cond_func(0, info)) && cpumask_test_cpu(0, mask)) {
49 local_irq_save(flags);
50 func(info);
51 local_irq_restore(flags);
52 }
53 preempt_enable();
54}
55EXPORT_SYMBOL(on_each_cpu_cond_mask);
56
57int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
58{
59 int ret;
60
61 if (cpu != 0)
62 return -ENXIO;
63
64 if (phys)
65 hypervisor_pin_vcpu(0);
66 ret = func(par);
67 if (phys)
68 hypervisor_pin_vcpu(-1);
69
70 return ret;
71}
72EXPORT_SYMBOL_GPL(smp_call_on_cpu);