blob: 6c8a805819ffc01ef98166f80b3095eaff450078 [file] [log] [blame]
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +01001#include <asm/smp.h>
2
Boris Ostrovsky84d582d2017-04-24 15:04:53 -04003#include <xen/events.h>
4
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +01005#include "xen-ops.h"
6#include "smp.h"
7
8
9static void __init xen_hvm_smp_prepare_boot_cpu(void)
10{
11 BUG_ON(smp_processor_id() != 0);
12 native_smp_prepare_boot_cpu();
13
14 /*
Ankur Aroraad73fd52017-06-02 17:05:58 -070015 * Setup vcpu_info for boot CPU. Secondary CPUs get their vcpu_info
16 * in xen_cpu_up_prepare_hvm().
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +010017 */
18 xen_vcpu_setup(0);
19
20 /*
21 * The alternative logic (which patches the unlock/lock) runs before
22 * the smp bootup up code is activated. Hence we need to set this up
23 * the core kernel is being patched. Otherwise we will have only
24 * modules patched but not core code.
25 */
26 xen_init_spinlocks();
27}
28
29static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
30{
Ankur Arora0b64ffb2017-06-02 17:05:59 -070031 int cpu;
32
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +010033 native_smp_prepare_cpus(max_cpus);
34 WARN_ON(xen_smp_intr_init(0));
35
36 xen_init_lock_cpu(0);
Ankur Arora0b64ffb2017-06-02 17:05:59 -070037
38 for_each_possible_cpu(cpu) {
39 if (cpu == 0)
40 continue;
41
42 /* Set default vcpu_id to make sure that we don't use cpu-0's */
43 per_cpu(xen_vcpu_id, cpu) = XEN_VCPU_ID_INVALID;
44 }
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +010045}
46
47#ifdef CONFIG_HOTPLUG_CPU
48static void xen_hvm_cpu_die(unsigned int cpu)
49{
50 if (common_cpu_die(cpu) == 0) {
51 xen_smp_intr_free(cpu);
52 xen_uninit_lock_cpu(cpu);
53 xen_teardown_timer(cpu);
54 }
55}
56#else
57static void xen_hvm_cpu_die(unsigned int cpu)
58{
59 BUG();
60}
61#endif
62
63void __init xen_hvm_smp_init(void)
64{
Boris Ostrovsky84d582d2017-04-24 15:04:53 -040065 if (!xen_have_vector_callback)
66 return;
67
Vitaly Kuznetsova52482d2017-03-14 18:35:45 +010068 smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
69 smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
70 smp_ops.cpu_die = xen_hvm_cpu_die;
71 smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
72 smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
73 smp_ops.smp_prepare_boot_cpu = xen_hvm_smp_prepare_boot_cpu;
74}