sleep.c 2.8 KB

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