sleep.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * sleep.c - x86-specific ACPI sleep support.
  3. *
  4. * Copyright (C) 2001-2003 Patrick Mochel
  5. * Copyright (C) 2001-2003 Pavel Machek <pavel@ucw.cz>
  6. */
  7. #include <linux/acpi.h>
  8. #include <linux/bootmem.h>
  9. #include <linux/memblock.h>
  10. #include <linux/dmi.h>
  11. #include <linux/cpumask.h>
  12. #include <asm/segment.h>
  13. #include <asm/desc.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/realmode.h>
  17. #include <linux/ftrace.h>
  18. #include "../../realmode/rm/wakeup.h"
  19. #include "sleep.h"
  20. unsigned long acpi_realmode_flags;
  21. #if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
  22. static char temp_stack[4096];
  23. #endif
  24. /**
  25. * x86_acpi_enter_sleep_state - enter sleep state
  26. * @state: Sleep state to enter.
  27. *
  28. * Wrapper around acpi_enter_sleep_state() to be called by assmebly.
  29. */
  30. acpi_status asmlinkage __visible x86_acpi_enter_sleep_state(u8 state)
  31. {
  32. return acpi_enter_sleep_state(state);
  33. }
  34. /**
  35. * x86_acpi_suspend_lowlevel - save kernel state
  36. *
  37. * Create an identity mapped page table and copy the wakeup routine to
  38. * low memory.
  39. */
  40. int x86_acpi_suspend_lowlevel(void)
  41. {
  42. struct wakeup_header *header =
  43. (struct wakeup_header *) __va(real_mode_header->wakeup_header);
  44. if (header->signature != WAKEUP_HEADER_SIGNATURE) {
  45. printk(KERN_ERR "wakeup header does not match\n");
  46. return -EINVAL;
  47. }
  48. header->video_mode = saved_video_mode;
  49. header->pmode_behavior = 0;
  50. #ifndef CONFIG_64BIT
  51. native_store_gdt((struct desc_ptr *)&header->pmode_gdt);
  52. /*
  53. * We have to check that we can write back the value, and not
  54. * just read it. At least on 90 nm Pentium M (Family 6, Model
  55. * 13), reading an invalid MSR is not guaranteed to trap, see
  56. * Erratum X4 in "Intel Pentium M Processor on 90 nm Process
  57. * with 2-MB L2 Cache and Intel® Processor A100 and A110 on 90
  58. * nm process with 512-KB L2 Cache Specification Update".
  59. */
  60. if (!rdmsr_safe(MSR_EFER,
  61. &header->pmode_efer_low,
  62. &header->pmode_efer_high) &&
  63. !wrmsr_safe(MSR_EFER,
  64. header->pmode_efer_low,
  65. header->pmode_efer_high))
  66. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
  67. #endif /* !CONFIG_64BIT */
  68. header->pmode_cr0 = read_cr0();
  69. if (__this_cpu_read(cpu_info.cpuid_level) >= 0) {
  70. header->pmode_cr4 = __read_cr4();
  71. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
  72. }
  73. if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
  74. &header->pmode_misc_en_low,
  75. &header->pmode_misc_en_high) &&
  76. !wrmsr_safe(MSR_IA32_MISC_ENABLE,
  77. header->pmode_misc_en_low,
  78. header->pmode_misc_en_high))
  79. header->pmode_behavior |=
  80. (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
  81. header->realmode_flags = acpi_realmode_flags;
  82. header->real_magic = 0x12345678;
  83. #ifndef CONFIG_64BIT
  84. header->pmode_entry = (u32)&wakeup_pmode_return;
  85. header->pmode_cr3 = (u32)__pa_symbol(initial_page_table);
  86. saved_magic = 0x12345678;
  87. #else /* CONFIG_64BIT */
  88. #ifdef CONFIG_SMP
  89. initial_stack = (unsigned long)temp_stack + sizeof(temp_stack);
  90. early_gdt_descr.address =
  91. (unsigned long)get_cpu_gdt_table(smp_processor_id());
  92. initial_gs = per_cpu_offset(smp_processor_id());
  93. #endif
  94. initial_code = (unsigned long)wakeup_long64;
  95. saved_magic = 0x123456789abcdef0L;
  96. #endif /* CONFIG_64BIT */
  97. /*
  98. * Pause/unpause graph tracing around do_suspend_lowlevel as it has
  99. * inconsistent call/return info after it jumps to the wakeup vector.
  100. */
  101. pause_graph_tracing();
  102. do_suspend_lowlevel();
  103. unpause_graph_tracing();
  104. return 0;
  105. }
  106. static int __init acpi_sleep_setup(char *str)
  107. {
  108. while ((str != NULL) && (*str != '\0')) {
  109. if (strncmp(str, "s3_bios", 7) == 0)
  110. acpi_realmode_flags |= 1;
  111. if (strncmp(str, "s3_mode", 7) == 0)
  112. acpi_realmode_flags |= 2;
  113. if (strncmp(str, "s3_beep", 7) == 0)
  114. acpi_realmode_flags |= 4;
  115. #ifdef CONFIG_HIBERNATION
  116. if (strncmp(str, "s4_nohwsig", 10) == 0)
  117. acpi_no_s4_hw_signature();
  118. #endif
  119. if (strncmp(str, "nonvs", 5) == 0)
  120. acpi_nvs_nosave();
  121. if (strncmp(str, "nonvs_s3", 8) == 0)
  122. acpi_nvs_nosave_s3();
  123. if (strncmp(str, "old_ordering", 12) == 0)
  124. acpi_old_suspend_ordering();
  125. str = strchr(str, ',');
  126. if (str != NULL)
  127. str += strspn(str, ", \t");
  128. }
  129. return 1;
  130. }
  131. __setup("acpi_sleep=", acpi_sleep_setup);