sleep.c 3.8 KB

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