sleep.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "../../realmode/rm/wakeup.h"
  18. #include "sleep.h"
  19. unsigned long acpi_realmode_flags;
  20. #if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
  21. static char temp_stack[4096];
  22. #endif
  23. /**
  24. * x86_acpi_suspend_lowlevel - save kernel state
  25. *
  26. * Create an identity mapped page table and copy the wakeup routine to
  27. * low memory.
  28. */
  29. int x86_acpi_suspend_lowlevel(void)
  30. {
  31. struct wakeup_header *header =
  32. (struct wakeup_header *) __va(real_mode_header->wakeup_header);
  33. if (header->signature != WAKEUP_HEADER_SIGNATURE) {
  34. printk(KERN_ERR "wakeup header does not match\n");
  35. return -EINVAL;
  36. }
  37. header->video_mode = saved_video_mode;
  38. header->pmode_behavior = 0;
  39. #ifndef CONFIG_64BIT
  40. native_store_gdt((struct desc_ptr *)&header->pmode_gdt);
  41. /*
  42. * We have to check that we can write back the value, and not
  43. * just read it. At least on 90 nm Pentium M (Family 6, Model
  44. * 13), reading an invalid MSR is not guaranteed to trap, see
  45. * Erratum X4 in "Intel Pentium M Processor on 90 nm Process
  46. * with 2-MB L2 Cache and Intel® Processor A100 and A110 on 90
  47. * nm process with 512-KB L2 Cache Specification Update".
  48. */
  49. if (!rdmsr_safe(MSR_EFER,
  50. &header->pmode_efer_low,
  51. &header->pmode_efer_high) &&
  52. !wrmsr_safe(MSR_EFER,
  53. header->pmode_efer_low,
  54. header->pmode_efer_high))
  55. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
  56. #endif /* !CONFIG_64BIT */
  57. header->pmode_cr0 = read_cr0();
  58. if (__this_cpu_read(cpu_info.cpuid_level) >= 0) {
  59. header->pmode_cr4 = read_cr4();
  60. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
  61. }
  62. if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
  63. &header->pmode_misc_en_low,
  64. &header->pmode_misc_en_high) &&
  65. !wrmsr_safe(MSR_IA32_MISC_ENABLE,
  66. header->pmode_misc_en_low,
  67. header->pmode_misc_en_high))
  68. header->pmode_behavior |=
  69. (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
  70. header->realmode_flags = acpi_realmode_flags;
  71. header->real_magic = 0x12345678;
  72. #ifndef CONFIG_64BIT
  73. header->pmode_entry = (u32)&wakeup_pmode_return;
  74. header->pmode_cr3 = (u32)__pa_symbol(initial_page_table);
  75. saved_magic = 0x12345678;
  76. #else /* CONFIG_64BIT */
  77. #ifdef CONFIG_SMP
  78. stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
  79. early_gdt_descr.address =
  80. (unsigned long)get_cpu_gdt_table(smp_processor_id());
  81. initial_gs = per_cpu_offset(smp_processor_id());
  82. #endif
  83. initial_code = (unsigned long)wakeup_long64;
  84. saved_magic = 0x123456789abcdef0L;
  85. #endif /* CONFIG_64BIT */
  86. do_suspend_lowlevel();
  87. return 0;
  88. }
  89. static int __init acpi_sleep_setup(char *str)
  90. {
  91. while ((str != NULL) && (*str != '\0')) {
  92. if (strncmp(str, "s3_bios", 7) == 0)
  93. acpi_realmode_flags |= 1;
  94. if (strncmp(str, "s3_mode", 7) == 0)
  95. acpi_realmode_flags |= 2;
  96. if (strncmp(str, "s3_beep", 7) == 0)
  97. acpi_realmode_flags |= 4;
  98. #ifdef CONFIG_HIBERNATION
  99. if (strncmp(str, "s4_nohwsig", 10) == 0)
  100. acpi_no_s4_hw_signature();
  101. #endif
  102. if (strncmp(str, "nonvs", 5) == 0)
  103. acpi_nvs_nosave();
  104. if (strncmp(str, "nonvs_s3", 8) == 0)
  105. acpi_nvs_nosave_s3();
  106. if (strncmp(str, "old_ordering", 12) == 0)
  107. acpi_old_suspend_ordering();
  108. str = strchr(str, ',');
  109. if (str != NULL)
  110. str += strspn(str, ", \t");
  111. }
  112. return 1;
  113. }
  114. __setup("acpi_sleep=", acpi_sleep_setup);