sleep.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "realmode/wakeup.h"
  17. #include "sleep.h"
  18. unsigned long acpi_realmode_flags;
  19. #if defined(CONFIG_SMP) && defined(CONFIG_64BIT)
  20. static char temp_stack[4096];
  21. #endif
  22. asmlinkage void acpi_enter_s3(void)
  23. {
  24. acpi_enter_sleep_state(3, wake_sleep_flags);
  25. }
  26. /**
  27. * acpi_suspend_lowlevel - save kernel state
  28. *
  29. * Create an identity mapped page table and copy the wakeup routine to
  30. * low memory.
  31. */
  32. int acpi_suspend_lowlevel(void)
  33. {
  34. struct wakeup_header *header;
  35. /* address in low memory of the wakeup routine. */
  36. char *acpi_realmode;
  37. acpi_realmode = TRAMPOLINE_SYM(acpi_wakeup_code);
  38. header = (struct wakeup_header *)(acpi_realmode + WAKEUP_HEADER_OFFSET);
  39. if (header->signature != WAKEUP_HEADER_SIGNATURE) {
  40. printk(KERN_ERR "wakeup header does not match\n");
  41. return -EINVAL;
  42. }
  43. header->video_mode = saved_video_mode;
  44. header->wakeup_jmp_seg = acpi_wakeup_address >> 4;
  45. /*
  46. * Set up the wakeup GDT. We set these up as Big Real Mode,
  47. * that is, with limits set to 4 GB. At least the Lenovo
  48. * Thinkpad X61 is known to need this for the video BIOS
  49. * initialization quirk to work; this is likely to also
  50. * be the case for other laptops or integrated video devices.
  51. */
  52. /* GDT[0]: GDT self-pointer */
  53. header->wakeup_gdt[0] =
  54. (u64)(sizeof(header->wakeup_gdt) - 1) +
  55. ((u64)__pa(&header->wakeup_gdt) << 16);
  56. /* GDT[1]: big real mode-like code segment */
  57. header->wakeup_gdt[1] =
  58. GDT_ENTRY(0x809b, acpi_wakeup_address, 0xfffff);
  59. /* GDT[2]: big real mode-like data segment */
  60. header->wakeup_gdt[2] =
  61. GDT_ENTRY(0x8093, acpi_wakeup_address, 0xfffff);
  62. #ifndef CONFIG_64BIT
  63. store_gdt((struct desc_ptr *)&header->pmode_gdt);
  64. if (rdmsr_safe(MSR_EFER, &header->pmode_efer_low,
  65. &header->pmode_efer_high))
  66. header->pmode_efer_low = header->pmode_efer_high = 0;
  67. #endif /* !CONFIG_64BIT */
  68. header->pmode_cr0 = read_cr0();
  69. header->pmode_cr4 = read_cr4_safe();
  70. header->pmode_behavior = 0;
  71. if (!rdmsr_safe(MSR_IA32_MISC_ENABLE,
  72. &header->pmode_misc_en_low,
  73. &header->pmode_misc_en_high))
  74. header->pmode_behavior |=
  75. (1 << WAKEUP_BEHAVIOR_RESTORE_MISC_ENABLE);
  76. header->realmode_flags = acpi_realmode_flags;
  77. header->real_magic = 0x12345678;
  78. #ifndef CONFIG_64BIT
  79. header->pmode_entry = (u32)&wakeup_pmode_return;
  80. header->pmode_cr3 = (u32)__pa(&initial_page_table);
  81. saved_magic = 0x12345678;
  82. #else /* CONFIG_64BIT */
  83. header->trampoline_segment = trampoline_address() >> 4;
  84. #ifdef CONFIG_SMP
  85. stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
  86. early_gdt_descr.address =
  87. (unsigned long)get_cpu_gdt_table(smp_processor_id());
  88. initial_gs = per_cpu_offset(smp_processor_id());
  89. #endif
  90. initial_code = (unsigned long)wakeup_long64;
  91. saved_magic = 0x123456789abcdef0L;
  92. #endif /* CONFIG_64BIT */
  93. do_suspend_lowlevel();
  94. return 0;
  95. }
  96. static int __init acpi_sleep_setup(char *str)
  97. {
  98. while ((str != NULL) && (*str != '\0')) {
  99. if (strncmp(str, "s3_bios", 7) == 0)
  100. acpi_realmode_flags |= 1;
  101. if (strncmp(str, "s3_mode", 7) == 0)
  102. acpi_realmode_flags |= 2;
  103. if (strncmp(str, "s3_beep", 7) == 0)
  104. acpi_realmode_flags |= 4;
  105. #ifdef CONFIG_HIBERNATION
  106. if (strncmp(str, "s4_nohwsig", 10) == 0)
  107. acpi_no_s4_hw_signature();
  108. #endif
  109. if (strncmp(str, "nonvs", 5) == 0)
  110. acpi_nvs_nosave();
  111. if (strncmp(str, "old_ordering", 12) == 0)
  112. acpi_old_suspend_ordering();
  113. str = strchr(str, ',');
  114. if (str != NULL)
  115. str += strspn(str, ", \t");
  116. }
  117. return 1;
  118. }
  119. __setup("acpi_sleep=", acpi_sleep_setup);