sleep.c 2.8 KB

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