Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
0e91398f | 2 | #include <linux/types.h> |
4ffee521 | 3 | #include <linux/tick.h> |
71c208dd | 4 | #include <linux/percpu-defs.h> |
0e91398f | 5 | |
facca616 | 6 | #include <xen/xen.h> |
0e91398f JF |
7 | #include <xen/interface/xen.h> |
8 | #include <xen/grant_table.h> | |
9 | #include <xen/events.h> | |
10 | ||
71c208dd JG |
11 | #include <asm/cpufeatures.h> |
12 | #include <asm/msr-index.h> | |
0e91398f JF |
13 | #include <asm/xen/hypercall.h> |
14 | #include <asm/xen/page.h> | |
99d0000f | 15 | #include <asm/fixmap.h> |
efef7f18 | 16 | #include <asm/msr.h> |
0e91398f JF |
17 | |
18 | #include "xen-ops.h" | |
0e91398f | 19 | |
71c208dd JG |
20 | static DEFINE_PER_CPU(u64, spec_ctrl); |
21 | ||
aa8532c3 DV |
22 | void xen_arch_pre_suspend(void) |
23 | { | |
2229f70b JM |
24 | xen_save_time_memory_area(); |
25 | ||
65d0cf0b BO |
26 | if (xen_pv_domain()) |
27 | xen_pv_pre_suspend(); | |
aa8532c3 DV |
28 | } |
29 | ||
30 | void xen_arch_post_suspend(int cancelled) | |
31 | { | |
65d0cf0b BO |
32 | if (xen_pv_domain()) |
33 | xen_pv_post_suspend(cancelled); | |
34 | else | |
35 | xen_hvm_post_suspend(cancelled); | |
2229f70b JM |
36 | |
37 | xen_restore_time_memory_area(); | |
0e91398f JF |
38 | } |
39 | ||
f6eafe36 IC |
40 | static void xen_vcpu_notify_restore(void *data) |
41 | { | |
71c208dd | 42 | if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) |
78255eb2 | 43 | wrmsrq(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl)); |
71c208dd | 44 | |
f6eafe36 | 45 | /* Boot processor notified via generic timekeeping_resume() */ |
4ffee521 | 46 | if (smp_processor_id() == 0) |
f6eafe36 IC |
47 | return; |
48 | ||
f46481d0 | 49 | tick_resume_local(); |
f6eafe36 IC |
50 | } |
51 | ||
2b953a5e BO |
52 | static void xen_vcpu_notify_suspend(void *data) |
53 | { | |
71c208dd JG |
54 | u64 tmp; |
55 | ||
2b953a5e | 56 | tick_suspend_local(); |
71c208dd JG |
57 | |
58 | if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) { | |
c435e608 | 59 | rdmsrq(MSR_IA32_SPEC_CTRL, tmp); |
71c208dd | 60 | this_cpu_write(spec_ctrl, tmp); |
78255eb2 | 61 | wrmsrq(MSR_IA32_SPEC_CTRL, 0); |
71c208dd | 62 | } |
2b953a5e BO |
63 | } |
64 | ||
ad55db9f IY |
65 | void xen_arch_resume(void) |
66 | { | |
de0afc9b BO |
67 | int cpu; |
68 | ||
4ffee521 | 69 | on_each_cpu(xen_vcpu_notify_restore, NULL, 1); |
de0afc9b BO |
70 | |
71 | for_each_online_cpu(cpu) | |
72 | xen_pmu_init(cpu); | |
ad55db9f | 73 | } |
2b953a5e BO |
74 | |
75 | void xen_arch_suspend(void) | |
76 | { | |
de0afc9b BO |
77 | int cpu; |
78 | ||
79 | for_each_online_cpu(cpu) | |
80 | xen_pmu_finish(cpu); | |
81 | ||
2b953a5e BO |
82 | on_each_cpu(xen_vcpu_notify_suspend, NULL, 1); |
83 | } |