sleep.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <asm/smp.h>
  11. #include <asm/tlbflush.h>
  12. /* address in low memory of the wakeup routine. */
  13. unsigned long acpi_wakeup_address = 0;
  14. unsigned long acpi_video_flags;
  15. extern char wakeup_start, wakeup_end;
  16. extern void zap_low_mappings(void);
  17. extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
  18. static void init_low_mapping(pgd_t * pgd, int pgd_limit)
  19. {
  20. int pgd_ofs = 0;
  21. while ((pgd_ofs < pgd_limit)
  22. && (pgd_ofs + USER_PTRS_PER_PGD < PTRS_PER_PGD)) {
  23. set_pgd(pgd, *(pgd + USER_PTRS_PER_PGD));
  24. pgd_ofs++, pgd++;
  25. }
  26. flush_tlb_all();
  27. }
  28. /**
  29. * acpi_save_state_mem - save kernel state
  30. *
  31. * Create an identity mapped page table and copy the wakeup routine to
  32. * low memory.
  33. */
  34. int acpi_save_state_mem(void)
  35. {
  36. if (!acpi_wakeup_address)
  37. return 1;
  38. init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
  39. memcpy((void *)acpi_wakeup_address, &wakeup_start,
  40. &wakeup_end - &wakeup_start);
  41. acpi_copy_wakeup_routine(acpi_wakeup_address);
  42. return 0;
  43. }
  44. /*
  45. * acpi_restore_state - undo effects of acpi_save_state_mem
  46. */
  47. void acpi_restore_state_mem(void)
  48. {
  49. zap_low_mappings();
  50. }
  51. /**
  52. * acpi_reserve_bootmem - do _very_ early ACPI initialisation
  53. *
  54. * We allocate a page from the first 1MB of memory for the wakeup
  55. * routine for when we come back from a sleep state. The
  56. * runtime allocator allows specification of <16MB pages, but not
  57. * <1MB pages.
  58. */
  59. void __init acpi_reserve_bootmem(void)
  60. {
  61. if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
  62. printk(KERN_ERR
  63. "ACPI: Wakeup code way too big, S3 disabled.\n");
  64. return;
  65. }
  66. acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
  67. if (!acpi_wakeup_address)
  68. printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
  69. }
  70. static int __init acpi_sleep_setup(char *str)
  71. {
  72. while ((str != NULL) && (*str != '\0')) {
  73. if (strncmp(str, "s3_bios", 7) == 0)
  74. acpi_video_flags = 1;
  75. if (strncmp(str, "s3_mode", 7) == 0)
  76. acpi_video_flags |= 2;
  77. str = strchr(str, ',');
  78. if (str != NULL)
  79. str += strspn(str, ", \t");
  80. }
  81. return 1;
  82. }
  83. __setup("acpi_sleep=", acpi_sleep_setup);
  84. static __init int reset_videomode_after_s3(struct dmi_system_id *d)
  85. {
  86. acpi_video_flags |= 2;
  87. return 0;
  88. }
  89. static __initdata struct dmi_system_id acpisleep_dmi_table[] = {
  90. { /* Reset video mode after returning from ACPI S3 sleep */
  91. .callback = reset_videomode_after_s3,
  92. .ident = "Toshiba Satellite 4030cdt",
  93. .matches = {
  94. DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),
  95. },
  96. },
  97. {}
  98. };
  99. static int __init acpisleep_dmi_init(void)
  100. {
  101. dmi_check_system(acpisleep_dmi_table);
  102. return 0;
  103. }
  104. core_initcall(acpisleep_dmi_init);