sleep.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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@suse.cz>
  6. */
  7. #include <linux/acpi.h>
  8. #include <linux/bootmem.h>
  9. #include <linux/dmi.h>
  10. #include <linux/cpumask.h>
  11. #include "realmode/wakeup.h"
  12. #include "sleep.h"
  13. unsigned long acpi_wakeup_address;
  14. unsigned long acpi_realmode_flags;
  15. /* address in low memory of the wakeup routine. */
  16. static unsigned long acpi_realmode;
  17. #ifdef CONFIG_64BIT
  18. static char temp_stack[10240];
  19. #endif
  20. /**
  21. * acpi_save_state_mem - save kernel state
  22. *
  23. * Create an identity mapped page table and copy the wakeup routine to
  24. * low memory.
  25. *
  26. * Note that this is too late to change acpi_wakeup_address.
  27. */
  28. int acpi_save_state_mem(void)
  29. {
  30. struct wakeup_header *header;
  31. if (!acpi_realmode) {
  32. printk(KERN_ERR "Could not allocate memory during boot, "
  33. "S3 disabled\n");
  34. return -ENOMEM;
  35. }
  36. memcpy((void *)acpi_realmode, &wakeup_code_start, WAKEUP_SIZE);
  37. header = (struct wakeup_header *)(acpi_realmode + HEADER_OFFSET);
  38. if (header->signature != 0x51ee1111) {
  39. printk(KERN_ERR "wakeup header does not match\n");
  40. return -EINVAL;
  41. }
  42. header->video_mode = saved_video_mode;
  43. #ifndef CONFIG_64BIT
  44. store_gdt((struct desc_ptr *)&header->pmode_gdt);
  45. header->pmode_efer_low = nx_enabled;
  46. if (header->pmode_efer_low & 1) {
  47. /* This is strange, why not save efer, always? */
  48. rdmsr(MSR_EFER, header->pmode_efer_low,
  49. header->pmode_efer_high);
  50. }
  51. #endif /* !CONFIG_64BIT */
  52. header->pmode_cr0 = read_cr0();
  53. header->pmode_cr4 = read_cr4();
  54. header->realmode_flags = acpi_realmode_flags;
  55. header->real_magic = 0x12345678;
  56. #ifndef CONFIG_64BIT
  57. header->pmode_entry = (u32)&wakeup_pmode_return;
  58. header->pmode_cr3 = (u32)(swsusp_pg_dir - __PAGE_OFFSET);
  59. saved_magic = 0x12345678;
  60. #else /* CONFIG_64BIT */
  61. header->trampoline_segment = setup_trampoline() >> 4;
  62. init_rsp = (unsigned long)temp_stack + 4096;
  63. initial_code = (unsigned long)wakeup_long64;
  64. saved_magic = 0x123456789abcdef0;
  65. #endif /* CONFIG_64BIT */
  66. return 0;
  67. }
  68. /*
  69. * acpi_restore_state - undo effects of acpi_save_state_mem
  70. */
  71. void acpi_restore_state_mem(void)
  72. {
  73. }
  74. /**
  75. * acpi_reserve_bootmem - do _very_ early ACPI initialisation
  76. *
  77. * We allocate a page from the first 1MB of memory for the wakeup
  78. * routine for when we come back from a sleep state. The
  79. * runtime allocator allows specification of <16MB pages, but not
  80. * <1MB pages.
  81. */
  82. void __init acpi_reserve_bootmem(void)
  83. {
  84. if ((&wakeup_code_end - &wakeup_code_start) > WAKEUP_SIZE) {
  85. printk(KERN_ERR
  86. "ACPI: Wakeup code way too big, S3 disabled.\n");
  87. return;
  88. }
  89. acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
  90. if (!acpi_realmode) {
  91. printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
  92. return;
  93. }
  94. acpi_wakeup_address = acpi_realmode;
  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. str = strchr(str, ',');
  106. if (str != NULL)
  107. str += strspn(str, ", \t");
  108. }
  109. return 1;
  110. }
  111. __setup("acpi_sleep=", acpi_sleep_setup);