sleep.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * 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 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. store_gdt((struct desc_ptr *)&header->pmode_gdt);
  41. if (!rdmsr_safe(MSR_EFER,
  42. &header->pmode_efer_low,
  43. &header->pmode_efer_high))
  44. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_EFER);
  45. #endif /* !CONFIG_64BIT */
  46. header->pmode_cr0 = read_cr0();
  47. if (__this_cpu_read(cpu_info.cpuid_level) >= 0) {
  48. header->pmode_cr4 = read_cr4();
  49. header->pmode_behavior |= (1 << WAKEUP_BEHAVIOR_RESTORE_CR4);
  50. }
  51. if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
  52. &header->pmode_misc_en_low,
  53. &header->pmode_misc_en_high))
  54. header->pmode_behavior |=
  55. (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
  56. header->realmode_flags = acpi_realmode_flags;
  57. header->real_magic = 0x12345678;
  58. #ifndef CONFIG_64BIT
  59. header->pmode_entry = (u32)&wakeup_pmode_return;
  60. header->pmode_cr3 = (u32)__pa_symbol(initial_page_table);
  61. saved_magic = 0x12345678;
  62. #else /* CONFIG_64BIT */
  63. #ifdef CONFIG_SMP
  64. stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
  65. early_gdt_descr.address =
  66. (unsigned long)get_cpu_gdt_table(smp_processor_id());
  67. initial_gs = per_cpu_offset(smp_processor_id());
  68. #endif
  69. initial_code = (unsigned long)wakeup_long64;
  70. saved_magic = 0x123456789abcdef0L;
  71. #endif /* CONFIG_64BIT */
  72. do_suspend_lowlevel();
  73. return 0;
  74. }
  75. static int __init acpi_sleep_setup(char *str)
  76. {
  77. while ((str != NULL) && (*str != '\0')) {
  78. if (strncmp(str, "s3_bios", 7) == 0)
  79. acpi_realmode_flags |= 1;
  80. if (strncmp(str, "s3_mode", 7) == 0)
  81. acpi_realmode_flags |= 2;
  82. if (strncmp(str, "s3_beep", 7) == 0)
  83. acpi_realmode_flags |= 4;
  84. #ifdef CONFIG_HIBERNATION
  85. if (strncmp(str, "s4_nohwsig", 10) == 0)
  86. acpi_no_s4_hw_signature();
  87. #endif
  88. if (strncmp(str, "nonvs", 5) == 0)
  89. acpi_nvs_nosave();
  90. if (strncmp(str, "nonvs_s3", 8) == 0)
  91. acpi_nvs_nosave_s3();
  92. if (strncmp(str, "old_ordering", 12) == 0)
  93. acpi_old_suspend_ordering();
  94. str = strchr(str, ',');
  95. if (str != NULL)
  96. str += strspn(str, ", \t");
  97. }
  98. return 1;
  99. }
  100. __setup("acpi_sleep=", acpi_sleep_setup);