2 #include <linux/kexec.h>
4 #include <xen/features.h>
5 #include <xen/events.h>
6 #include <xen/interface/memory.h>
10 #include <asm/reboot.h>
11 #include <asm/setup.h>
12 #include <asm/hypervisor.h>
14 #include <asm/xen/cpuid.h>
15 #include <asm/xen/hypervisor.h>
21 void __ref xen_hvm_init_shared_info(void)
24 struct xen_add_to_physmap xatp;
25 static struct shared_info *shared_info_page;
27 if (!shared_info_page)
28 shared_info_page = (struct shared_info *)
29 extend_brk(PAGE_SIZE, PAGE_SIZE);
30 xatp.domid = DOMID_SELF;
32 xatp.space = XENMAPSPACE_shared_info;
33 xatp.gpfn = __pa(shared_info_page) >> PAGE_SHIFT;
34 if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
37 HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
39 /* xen_vcpu is a pointer to the vcpu_info struct in the shared_info
40 * page, we use it in the event channel upcall and in some pvclock
41 * related functions. We don't need the vcpu_info placement
42 * optimizations because we don't use any pv_mmu or pv_irq op on
44 * When xen_hvm_init_shared_info is run at boot time only vcpu 0 is
45 * online but xen_hvm_init_shared_info is run at resume time too and
46 * in that case multiple vcpus might be online. */
47 for_each_online_cpu(cpu) {
48 xen_vcpu_info_reset(cpu);
52 static void __init init_hvm_pv_info(void)
55 uint32_t eax, ebx, ecx, edx, base;
57 base = xen_cpuid_base();
58 eax = cpuid_eax(base + 1);
62 printk(KERN_INFO "Xen version %d.%d.\n", major, minor);
64 xen_domain_type = XEN_HVM_DOMAIN;
66 /* PVH set up hypercall page in xen_prepare_pvh(). */
68 pv_info.name = "Xen PVH";
73 pv_info.name = "Xen HVM";
74 msr = cpuid_ebx(base + 2);
75 pfn = __pa(hypercall_page);
76 wrmsr_safe(msr, (u32)pfn, (u32)(pfn >> 32));
81 cpuid(base + 4, &eax, &ebx, &ecx, &edx);
82 if (eax & XEN_HVM_CPUID_VCPU_ID_PRESENT)
83 this_cpu_write(xen_vcpu_id, ebx);
85 this_cpu_write(xen_vcpu_id, smp_processor_id());
88 #ifdef CONFIG_KEXEC_CORE
89 static void xen_hvm_shutdown(void)
91 native_machine_shutdown();
92 if (kexec_in_progress)
93 xen_reboot(SHUTDOWN_soft_reset);
96 static void xen_hvm_crash_shutdown(struct pt_regs *regs)
98 native_machine_crash_shutdown(regs);
99 xen_reboot(SHUTDOWN_soft_reset);
103 static int xen_cpu_up_prepare_hvm(unsigned int cpu)
108 * This can happen if CPU was offlined earlier and
109 * offlining timed out in common_cpu_die().
111 if (cpu_report_state(cpu) == CPU_DEAD_FROZEN) {
112 xen_smp_intr_free(cpu);
113 xen_uninit_lock_cpu(cpu);
116 if (cpu_acpi_id(cpu) != U32_MAX)
117 per_cpu(xen_vcpu_id, cpu) = cpu_acpi_id(cpu);
119 per_cpu(xen_vcpu_id, cpu) = cpu;
122 if (xen_have_vector_callback && xen_feature(XENFEAT_hvm_safe_pvclock))
123 xen_setup_timer(cpu);
125 rc = xen_smp_intr_init(cpu);
127 WARN(1, "xen_smp_intr_init() for CPU %d failed: %d\n",
134 static int xen_cpu_dead_hvm(unsigned int cpu)
136 xen_smp_intr_free(cpu);
138 if (xen_have_vector_callback && xen_feature(XENFEAT_hvm_safe_pvclock))
139 xen_teardown_timer(cpu);
144 static void __init xen_hvm_guest_init(void)
151 xen_hvm_init_shared_info();
153 xen_panic_handler_init();
155 if (xen_feature(XENFEAT_hvm_callback_vector))
156 xen_have_vector_callback = 1;
159 WARN_ON(xen_cpuhp_setup(xen_cpu_up_prepare_hvm, xen_cpu_dead_hvm));
160 xen_unplug_emulated_devices();
161 x86_init.irqs.intr_init = xen_init_IRQ;
162 xen_hvm_init_time_ops();
163 xen_hvm_init_mmu_ops();
165 if (xen_pvh_domain())
166 machine_ops.emergency_restart = xen_emergency_restart;
167 #ifdef CONFIG_KEXEC_CORE
168 machine_ops.shutdown = xen_hvm_shutdown;
169 machine_ops.crash_shutdown = xen_hvm_crash_shutdown;
173 static bool xen_nopv;
174 static __init int xen_parse_nopv(char *arg)
179 early_param("xen_nopv", xen_parse_nopv);
181 bool xen_hvm_need_lapic(void)
187 if (!xen_hvm_domain())
189 if (xen_feature(XENFEAT_hvm_pirqs) && xen_have_vector_callback)
193 EXPORT_SYMBOL_GPL(xen_hvm_need_lapic);
195 static uint32_t __init xen_platform_hvm(void)
197 if (xen_pv_domain() || xen_nopv)
200 return xen_cpuid_base();
203 const struct hypervisor_x86 x86_hyper_xen_hvm = {
205 .detect = xen_platform_hvm,
206 .init_platform = xen_hvm_guest_init,
207 .pin_vcpu = xen_pin_vcpu,
208 .x2apic_available = xen_x2apic_para_available,
210 EXPORT_SYMBOL(x86_hyper_xen_hvm);