up.c 1.5 KB

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