Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Morton | 53ce3d9 | 2009-01-09 12:27:08 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Uniprocessor-only support functions. The counterpart to kernel/smp.c |
| 4 | */ |
| 5 | |
Ingo Molnar | 6e96281 | 2009-01-12 16:04:37 +0100 | [diff] [blame] | 6 | #include <linux/interrupt.h> |
Andrew Morton | 53ce3d9 | 2009-01-09 12:27:08 -0800 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 8 | #include <linux/export.h> |
Andrew Morton | 53ce3d9 | 2009-01-09 12:27:08 -0800 | [diff] [blame] | 9 | #include <linux/smp.h> |
Juergen Gross | 47ae4b0 | 2016-08-29 08:48:43 +0200 | [diff] [blame] | 10 | #include <linux/hypervisor.h> |
Andrew Morton | 53ce3d9 | 2009-01-09 12:27:08 -0800 | [diff] [blame] | 11 | |
| 12 | int smp_call_function_single(int cpu, void (*func) (void *info), void *info, |
| 13 | int wait) |
| 14 | { |
David Daney | 081192b | 2013-09-11 14:23:25 -0700 | [diff] [blame] | 15 | unsigned long flags; |
| 16 | |
Paul E. McKenney | 1e474b2 | 2020-02-05 06:34:09 -0800 | [diff] [blame] | 17 | if (cpu != 0) |
| 18 | return -ENXIO; |
Ingo Molnar | 93423b8 | 2009-01-11 05:15:21 +0100 | [diff] [blame] | 19 | |
David Daney | 081192b | 2013-09-11 14:23:25 -0700 | [diff] [blame] | 20 | local_irq_save(flags); |
| 21 | func(info); |
| 22 | local_irq_restore(flags); |
Ingo Molnar | 93423b8 | 2009-01-11 05:15:21 +0100 | [diff] [blame] | 23 | |
Andrew Morton | 53ce3d9 | 2009-01-09 12:27:08 -0800 | [diff] [blame] | 24 | return 0; |
| 25 | } |
| 26 | EXPORT_SYMBOL(smp_call_function_single); |
David Daney | fa68820 | 2013-09-11 14:23:24 -0700 | [diff] [blame] | 27 | |
Arnd Bergmann | 1139aeb | 2021-05-05 23:12:42 +0200 | [diff] [blame^] | 28 | int smp_call_function_single_async(int cpu, struct __call_single_data *csd) |
Christoph Hellwig | 40c01e8b | 2013-11-14 14:32:08 -0800 | [diff] [blame] | 29 | { |
| 30 | unsigned long flags; |
| 31 | |
| 32 | local_irq_save(flags); |
| 33 | csd->func(csd->info); |
| 34 | local_irq_restore(flags); |
Jan Kara | 08eed44 | 2014-02-24 16:39:57 +0100 | [diff] [blame] | 35 | return 0; |
Christoph Hellwig | 40c01e8b | 2013-11-14 14:32:08 -0800 | [diff] [blame] | 36 | } |
Frederic Weisbecker | c46fff2 | 2014-02-24 16:40:02 +0100 | [diff] [blame] | 37 | EXPORT_SYMBOL(smp_call_function_single_async); |
Christoph Hellwig | 40c01e8b | 2013-11-14 14:32:08 -0800 | [diff] [blame] | 38 | |
David Daney | fa68820 | 2013-09-11 14:23:24 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Preemption is disabled here to make sure the cond_func is called under the |
| 41 | * same condtions in UP and SMP. |
| 42 | */ |
Sebastian Andrzej Siewior | 5671d81 | 2020-01-17 10:01:35 +0100 | [diff] [blame] | 43 | void on_each_cpu_cond_mask(smp_cond_func_t cond_func, smp_call_func_t func, |
Sebastian Andrzej Siewior | cb92315 | 2020-01-17 10:01:37 +0100 | [diff] [blame] | 44 | void *info, bool wait, const struct cpumask *mask) |
David Daney | fa68820 | 2013-09-11 14:23:24 -0700 | [diff] [blame] | 45 | { |
| 46 | unsigned long flags; |
| 47 | |
| 48 | preempt_disable(); |
Nadav Amit | a5aa5ce | 2021-02-20 15:17:12 -0800 | [diff] [blame] | 49 | if ((!cond_func || cond_func(0, info)) && cpumask_test_cpu(0, mask)) { |
David Daney | fa68820 | 2013-09-11 14:23:24 -0700 | [diff] [blame] | 50 | local_irq_save(flags); |
| 51 | func(info); |
| 52 | local_irq_restore(flags); |
| 53 | } |
| 54 | preempt_enable(); |
| 55 | } |
Rik van Riel | 7d49b28 | 2018-09-25 23:58:41 -0400 | [diff] [blame] | 56 | EXPORT_SYMBOL(on_each_cpu_cond_mask); |
| 57 | |
Juergen Gross | df8ce9d | 2016-08-29 08:48:44 +0200 | [diff] [blame] | 58 | int 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 | } |
| 73 | EXPORT_SYMBOL_GPL(smp_call_on_cpu); |