blob: c4df9dbd63b7c81f70c624c417d8362b85d3d34e [file] [log] [blame]
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +01001#include <linux/types.h>
Ian Campbellf6eafe32009-11-25 14:12:08 +00002#include <linux/clockchips.h>
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +01003
4#include <xen/interface/xen.h>
5#include <xen/grant_table.h>
6#include <xen/events.h>
7
8#include <asm/xen/hypercall.h>
9#include <asm/xen/page.h>
Ingo Molnar99d00002009-01-23 11:09:15 +010010#include <asm/fixmap.h>
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010011
12#include "xen-ops.h"
13#include "mmu.h"
14
David Vrabelaa8532c2014-05-08 11:09:23 +010015static void xen_pv_pre_suspend(void)
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010016{
David Vrabelaa8532c2014-05-08 11:09:23 +010017 xen_mm_pin_all();
18
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010019 xen_start_info->store_mfn = mfn_to_pfn(xen_start_info->store_mfn);
20 xen_start_info->console.domU.mfn =
21 mfn_to_pfn(xen_start_info->console.domU.mfn);
22
23 BUG_ON(!irqs_disabled());
24
25 HYPERVISOR_shared_info = &xen_dummy_shared_info;
26 if (HYPERVISOR_update_va_mapping(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
27 __pte_ma(0), 0))
28 BUG();
29}
30
David Vrabelaa8532c2014-05-08 11:09:23 +010031static void xen_hvm_post_suspend(int suspend_cancelled)
Stefano Stabellini016b6f52010-05-14 12:45:07 +010032{
Stefano Stabellinie057a4b2011-02-11 17:55:13 +000033#ifdef CONFIG_XEN_PVHVM
Stefano Stabellini409771d2010-05-14 12:48:19 +010034 int cpu;
Konrad Rzeszutek Wilke9daff22013-02-14 21:29:31 -050035 xen_hvm_init_shared_info();
Stefano Stabellini016b6f52010-05-14 12:45:07 +010036 xen_callback_vector();
Stefano Stabellini512b1092010-12-01 14:51:44 +000037 xen_unplug_emulated_devices();
Stefano Stabellini409771d2010-05-14 12:48:19 +010038 if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
39 for_each_online_cpu(cpu) {
40 xen_setup_runstate_info(cpu);
41 }
42 }
Stefano Stabellinie057a4b2011-02-11 17:55:13 +000043#endif
Stefano Stabellini016b6f52010-05-14 12:45:07 +010044}
45
David Vrabelaa8532c2014-05-08 11:09:23 +010046static void xen_pv_post_suspend(int suspend_cancelled)
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010047{
Ian Campbellfa24ba62009-11-21 11:32:49 +000048 xen_build_mfn_list_list();
49
Jeremy Fitzhardinge9c7a7942008-05-31 01:33:02 +010050 xen_setup_shared_info();
51
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010052 if (suspend_cancelled) {
53 xen_start_info->store_mfn =
54 pfn_to_mfn(xen_start_info->store_mfn);
55 xen_start_info->console.domU.mfn =
56 pfn_to_mfn(xen_start_info->console.domU.mfn);
57 } else {
58#ifdef CONFIG_SMP
Mike Travisb78936e2008-12-16 17:33:57 -080059 BUG_ON(xen_cpu_initialized_map == NULL);
60 cpumask_copy(xen_cpu_initialized_map, cpu_online_mask);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010061#endif
Jeremy Fitzhardinge9c7a7942008-05-31 01:33:02 +010062 xen_vcpu_restore();
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010063 }
64
David Vrabelaa8532c2014-05-08 11:09:23 +010065 xen_mm_unpin_all();
66}
67
68void xen_arch_pre_suspend(void)
69{
70 if (xen_pv_domain())
71 xen_pv_pre_suspend();
72}
73
74void xen_arch_post_suspend(int cancelled)
75{
76 if (xen_pv_domain())
77 xen_pv_post_suspend(cancelled);
78 else
79 xen_hvm_post_suspend(cancelled);
Jeremy Fitzhardinge0e913982008-05-26 23:31:27 +010080}
81
Ian Campbellf6eafe32009-11-25 14:12:08 +000082static void xen_vcpu_notify_restore(void *data)
83{
84 unsigned long reason = (unsigned long)data;
85
86 /* Boot processor notified via generic timekeeping_resume() */
87 if ( smp_processor_id() == 0)
88 return;
89
90 clockevents_notify(reason, NULL);
91}
92
Isaku Yamahataad55db92008-07-08 15:06:32 -070093void xen_arch_resume(void)
94{
Ian Campbellcd52e172010-05-19 16:19:25 +010095 on_each_cpu(xen_vcpu_notify_restore,
96 (void *)CLOCK_EVT_NOTIFY_RESUME, 1);
Isaku Yamahataad55db92008-07-08 15:06:32 -070097}