sleep.c 3.7 KB

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