blob: c6f323dcd45bb9efe1401b1b7893350667305493 [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
Ying Huang966a9672017-08-08 12:30:00 +080028int smp_call_function_single_async(int cpu, call_single_data_t *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
Nadav Amitcaa75932019-06-12 23:48:05 -070039void on_each_cpu(smp_call_func_t func, void *info, int wait)
David Daneybff2dc42013-09-11 14:23:26 -070040{
41 unsigned long flags;
42
43 local_irq_save(flags);
44 func(info);
45 local_irq_restore(flags);
David Daneybff2dc42013-09-11 14:23:26 -070046}
47EXPORT_SYMBOL(on_each_cpu);
48
David Daneyfa688202013-09-11 14:23:24 -070049/*
50 * Note we still need to test the mask even for UP
51 * because we actually can get an empty mask from
52 * code that on SMP might call us without the local
53 * CPU in the mask.
54 */
55void on_each_cpu_mask(const struct cpumask *mask,
56 smp_call_func_t func, void *info, bool wait)
57{
58 unsigned long flags;
59
60 if (cpumask_test_cpu(0, mask)) {
61 local_irq_save(flags);
62 func(info);
63 local_irq_restore(flags);
64 }
65}
66EXPORT_SYMBOL(on_each_cpu_mask);
67
68/*
69 * Preemption is disabled here to make sure the cond_func is called under the
70 * same condtions in UP and SMP.
71 */
Sebastian Andrzej Siewior5671d812020-01-17 10:01:35 +010072void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func,
Sebastian Andrzej Siewiorcb923152020-01-17 10:01:37 +010073 void *info, bool wait, const struct cpumask *mask)
David Daneyfa688202013-09-11 14:23:24 -070074{
75 unsigned long flags;
76
77 preempt_disable();
78 if (cond_func(0, info)) {
79 local_irq_save(flags);
80 func(info);
81 local_irq_restore(flags);
82 }
83 preempt_enable();
84}
Rik van Riel7d49b282018-09-25 23:58:41 -040085EXPORT_SYMBOL(on_each_cpu_cond_mask);
86
Sebastian Andrzej Siewior5671d812020-01-17 10:01:35 +010087void on_each_cpu_cond(smp_cond_func_t cond_func, smp_call_func_t func,
Sebastian Andrzej Siewiorcb923152020-01-17 10:01:37 +010088 void *info, bool wait)
Rik van Riel7d49b282018-09-25 23:58:41 -040089{
Sebastian Andrzej Siewiorcb923152020-01-17 10:01:37 +010090 on_each_cpu_cond_mask(cond_func, func, info, wait, NULL);
Rik van Riel7d49b282018-09-25 23:58:41 -040091}
David Daneyfa688202013-09-11 14:23:24 -070092EXPORT_SYMBOL(on_each_cpu_cond);
Juergen Grossdf8ce9d2016-08-29 08:48:44 +020093
94int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
95{
96 int ret;
97
98 if (cpu != 0)
99 return -ENXIO;
100
101 if (phys)
102 hypervisor_pin_vcpu(0);
103 ret = func(par);
104 if (phys)
105 hypervisor_pin_vcpu(-1);
106
107 return ret;
108}
109EXPORT_SYMBOL_GPL(smp_call_on_cpu);