blob: a38b8b0952517590b0f0dd7d2da643c63bc8f648 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Andrew Morton53ce3d92009-01-09 12:27:08 -08002/*
3 * Uniprocessor-only support functions. The counterpart to kernel/smp.c
4 */
5
Ingo Molnar6e962812009-01-12 16:04:37 +01006#include <linux/interrupt.h>
Andrew Morton53ce3d92009-01-09 12:27:08 -08007#include <linux/kernel.h>
Paul Gortmaker9984de12011-05-23 14:51:41 -04008#include <linux/export.h>
Andrew Morton53ce3d92009-01-09 12:27:08 -08009#include <linux/smp.h>
Juergen Gross47ae4b02016-08-29 08:48:43 +020010#include <linux/hypervisor.h>
Andrew Morton53ce3d92009-01-09 12:27:08 -080011
12int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
13 int wait)
14{
David Daney081192b2013-09-11 14:23:25 -070015 unsigned long flags;
16
Paul E. McKenney1e474b22020-02-05 06:34:09 -080017 if (cpu != 0)
18 return -ENXIO;
Ingo Molnar93423b82009-01-11 05:15:21 +010019
David Daney081192b2013-09-11 14:23:25 -070020 local_irq_save(flags);
21 func(info);
22 local_irq_restore(flags);
Ingo Molnar93423b82009-01-11 05:15:21 +010023
Andrew Morton53ce3d92009-01-09 12:27:08 -080024 return 0;
25}
26EXPORT_SYMBOL(smp_call_function_single);
David Daneyfa688202013-09-11 14:23:24 -070027
Arnd Bergmann1139aeb2021-05-05 23:12:42 +020028int smp_call_function_single_async(int cpu, struct __call_single_data *csd)
Christoph Hellwig40c01e8b2013-11-14 14:32:08 -080029{
30 unsigned long flags;
31
32 local_irq_save(flags);
33 csd->func(csd->info);
34 local_irq_restore(flags);
Jan Kara08eed442014-02-24 16:39:57 +010035 return 0;
Christoph Hellwig40c01e8b2013-11-14 14:32:08 -080036}
Frederic Weisbeckerc46fff22014-02-24 16:40:02 +010037EXPORT_SYMBOL(smp_call_function_single_async);
Christoph Hellwig40c01e8b2013-11-14 14:32:08 -080038
David Daneyfa688202013-09-11 14:23:24 -070039/*
40 * Preemption is disabled here to make sure the cond_func is called under the
Bhaskar Chowdhuryf0fffaf2021-05-06 18:06:33 -070041 * same conditions in UP and SMP.
David Daneyfa688202013-09-11 14:23:24 -070042 */
Sebastian Andrzej Siewior5671d812020-01-17 10:01:35 +010043void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
Sebastian Andrzej Siewiorcb923152020-01-17 10:01:37 +010044 void *info, bool wait, const struct cpumask *mask)
David Daneyfa688202013-09-11 14:23:24 -070045{
46 unsigned long flags;
47
48 preempt_disable();
Nadav Amita5aa5ce2021-02-20 15:17:12 -080049 if ((!cond_func || cond_func(0, info)) && cpumask_test_cpu(0, mask)) {
David Daneyfa688202013-09-11 14:23:24 -070050 local_irq_save(flags);
51 func(info);
52 local_irq_restore(flags);
53 }
54 preempt_enable();
55}
Rik van Riel7d49b282018-09-25 23:58:41 -040056EXPORT_SYMBOL(on_each_cpu_cond_mask);
57
Juergen Grossdf8ce9d2016-08-29 08:48:44 +020058int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
59{
60 int ret;
61
62 if (cpu != 0)
63 return -ENXIO;
64
65 if (phys)
66 hypervisor_pin_vcpu(0);
67 ret = func(par);
68 if (phys)
69 hypervisor_pin_vcpu(-1);
70
71 return ret;
72}
73EXPORT_SYMBOL_GPL(smp_call_on_cpu);