smp_hvm.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <asm/smp.h>
  3. #include <xen/events.h>
  4. #include "xen-ops.h"
  5. #include "smp.h"
  6. static void __init xen_hvm_smp_prepare_boot_cpu(void)
  7. {
  8. BUG_ON(smp_processor_id() != 0);
  9. native_smp_prepare_boot_cpu();
  10. /*
  11. * Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info
  12. * in xen_cpu_up_prepare_hvm().
  13. */
  14. xen_vcpu_setup(0);
  15. /*
  16. * The alternative logic (which patches the unlock/lock) runs before
  17. * the smp bootup up code is activated. Hence we need to set this up
  18. * the core kernel is being patched. Otherwise we will have only
  19. * modules patched but not core code.
  20. */
  21. xen_init_spinlocks();
  22. }
  23. static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
  24. {
  25. int cpu;
  26. native_smp_prepare_cpus(max_cpus);
  27. WARN_ON(xen_smp_intr_init(0));
  28. xen_init_lock_cpu(0);
  29. for_each_possible_cpu(cpu) {
  30. if (cpu == 0)
  31. continue;
  32. /* Set default vcpu_id to make sure that we don't use cpu-0's */
  33. per_cpu(xen_vcpu_id, cpu) = XEN_VCPU_ID_INVALID;
  34. }
  35. }
  36. #ifdef CONFIG_HOTPLUG_CPU
  37. static void xen_hvm_cpu_die(unsigned int cpu)
  38. {
  39. if (common_cpu_die(cpu) == 0) {
  40. xen_smp_intr_free(cpu);
  41. xen_uninit_lock_cpu(cpu);
  42. xen_teardown_timer(cpu);
  43. }
  44. }
  45. #else
  46. static void xen_hvm_cpu_die(unsigned int cpu)
  47. {
  48. BUG();
  49. }
  50. #endif
  51. void __init xen_hvm_smp_init(void)
  52. {
  53. if (!xen_have_vector_callback)
  54. return;
  55. smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
  56. smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
  57. smp_ops.cpu_die = xen_hvm_cpu_die;
  58. smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
  59. smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
  60. smp_ops.smp_prepare_boot_cpu = xen_hvm_smp_prepare_boot_cpu;
  61. smp_ops.smp_cpus_done = xen_smp_cpus_done;
  62. }