1 #include <linux/types.h>
2 #include <linux/tick.h>
3 #include <linux/percpu-defs.h>
6 #include <xen/interface/xen.h>
7 #include <xen/grant_table.h>
8 #include <xen/events.h>
10 #include <asm/cpufeatures.h>
11 #include <asm/msr-index.h>
12 #include <asm/xen/hypercall.h>
13 #include <asm/xen/page.h>
14 #include <asm/fixmap.h>
20 static void xen_pv_pre_suspend(void)
24 xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
25 xen_start_info->console.domU.mfn =
26 mfn_to_pfn(xen_start_info->console.domU.mfn);
28 BUG_ON(!irqs_disabled());
30 HYPERVISOR_shared_info = &xen_dummy_shared_info;
31 if (HYPERVISOR_update_va_mapping(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
36 static void xen_hvm_post_suspend(int suspend_cancelled)
38 #ifdef CONFIG_XEN_PVHVM
40 if (!suspend_cancelled)
41 xen_hvm_init_shared_info();
42 xen_callback_vector();
43 xen_unplug_emulated_devices();
44 if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
45 for_each_online_cpu(cpu) {
46 xen_setup_runstate_info(cpu);
52 static void xen_pv_post_suspend(int suspend_cancelled)
54 xen_build_mfn_list_list();
56 xen_setup_shared_info();
58 if (suspend_cancelled) {
59 xen_start_info->store_mfn =
60 pfn_to_mfn(xen_start_info->store_mfn);
61 xen_start_info->console.domU.mfn =
62 pfn_to_mfn(xen_start_info->console.domU.mfn);
65 BUG_ON(xen_cpu_initialized_map == NULL);
66 cpumask_copy(xen_cpu_initialized_map, cpu_online_mask);
74 static DEFINE_PER_CPU(u64, spec_ctrl);
76 void xen_arch_pre_suspend(void)
82 void xen_arch_post_suspend(int cancelled)
85 xen_pv_post_suspend(cancelled);
87 xen_hvm_post_suspend(cancelled);
90 static void xen_vcpu_notify_restore(void *data)
92 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
93 wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
95 /* Boot processor notified via generic timekeeping_resume() */
96 if (smp_processor_id() == 0)
102 static void xen_vcpu_notify_suspend(void *data)
106 tick_suspend_local();
108 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
109 rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
110 this_cpu_write(spec_ctrl, tmp);
111 wrmsrl(MSR_IA32_SPEC_CTRL, 0);
115 void xen_arch_resume(void)
119 on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
121 for_each_online_cpu(cpu)
125 void xen_arch_suspend(void)
129 for_each_online_cpu(cpu)
132 on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);