suspend.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include <linux/types.h>
  2. #include <linux/tick.h>
  3. #include <linux/percpu-defs.h>
  4. #include <xen/xen.h>
  5. #include <xen/interface/xen.h>
  6. #include <xen/grant_table.h>
  7. #include <xen/events.h>
  8. #include <asm/cpufeatures.h>
  9. #include <asm/msr-index.h>
  10. #include <asm/xen/hypercall.h>
  11. #include <asm/xen/page.h>
  12. #include <asm/fixmap.h>
  13. #include "xen-ops.h"
  14. #include "mmu.h"
  15. #include "pmu.h"
  16. static void xen_pv_pre_suspend(void)
  17. {
  18. xen_mm_pin_all();
  19. 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. BUG_ON(!irqs_disabled());
  23. HYPERVISOR_shared_info = &xen_dummy_shared_info;
  24. if (HYPERVISOR_update_va_mapping(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
  25. __pte_ma(0), 0))
  26. BUG();
  27. }
  28. static void xen_hvm_post_suspend(int suspend_cancelled)
  29. {
  30. #ifdef CONFIG_XEN_PVHVM
  31. int cpu;
  32. if (!suspend_cancelled)
  33. xen_hvm_init_shared_info();
  34. xen_callback_vector();
  35. xen_unplug_emulated_devices();
  36. if (xen_feature(XENFEAT_hvm_safe_pvclock)) {
  37. for_each_online_cpu(cpu) {
  38. xen_setup_runstate_info(cpu);
  39. }
  40. }
  41. #endif
  42. }
  43. static void xen_pv_post_suspend(int suspend_cancelled)
  44. {
  45. xen_build_mfn_list_list();
  46. xen_setup_shared_info();
  47. if (suspend_cancelled) {
  48. xen_start_info->store_mfn =
  49. pfn_to_mfn(xen_start_info->store_mfn);
  50. xen_start_info->console.domU.mfn =
  51. pfn_to_mfn(xen_start_info->console.domU.mfn);
  52. } else {
  53. #ifdef CONFIG_SMP
  54. BUG_ON(xen_cpu_initialized_map == NULL);
  55. cpumask_copy(xen_cpu_initialized_map, cpu_online_mask);
  56. #endif
  57. xen_vcpu_restore();
  58. }
  59. xen_mm_unpin_all();
  60. }
  61. static DEFINE_PER_CPU(u64, spec_ctrl);
  62. void xen_arch_pre_suspend(void)
  63. {
  64. if (xen_pv_domain())
  65. xen_pv_pre_suspend();
  66. }
  67. void xen_arch_post_suspend(int cancelled)
  68. {
  69. if (xen_pv_domain())
  70. xen_pv_post_suspend(cancelled);
  71. else
  72. xen_hvm_post_suspend(cancelled);
  73. }
  74. static void xen_vcpu_notify_restore(void *data)
  75. {
  76. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
  77. wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
  78. /* Boot processor notified via generic timekeeping_resume() */
  79. if (smp_processor_id() == 0)
  80. return;
  81. tick_resume_local();
  82. }
  83. static void xen_vcpu_notify_suspend(void *data)
  84. {
  85. u64 tmp;
  86. tick_suspend_local();
  87. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
  88. rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
  89. this_cpu_write(spec_ctrl, tmp);
  90. wrmsrl(MSR_IA32_SPEC_CTRL, 0);
  91. }
  92. }
  93. void xen_arch_resume(void)
  94. {
  95. int cpu;
  96. on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
  97. for_each_online_cpu(cpu)
  98. xen_pmu_init(cpu);
  99. }
  100. void xen_arch_suspend(void)
  101. {
  102. int cpu;
  103. for_each_online_cpu(cpu)
  104. xen_pmu_finish(cpu);
  105. on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);
  106. }