/arch/i386/kernel/acpi/sleep.c

https://bitbucket.org/evzijst/gittest · C · 93 lines · 55 code · 14 blank · 24 comment · 15 complexity · 74fdc65673e6b539e0f43376e17eaeb4 MD5 · raw file

  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 <asm/smp.h>
  10. #include <asm/tlbflush.h>
  11. /* address in low memory of the wakeup routine. */
  12. unsigned long acpi_wakeup_address = 0;
  13. unsigned long acpi_video_flags;
  14. extern char wakeup_start, wakeup_end;
  15. extern void zap_low_mappings(void);
  16. extern unsigned long FASTCALL(acpi_copy_wakeup_routine(unsigned long));
  17. static void init_low_mapping(pgd_t *pgd, int pgd_limit)
  18. {
  19. int pgd_ofs = 0;
  20. while ((pgd_ofs < pgd_limit) && (pgd_ofs + USER_PTRS_PER_PGD < PTRS_PER_PGD)) {
  21. set_pgd(pgd, *(pgd+USER_PTRS_PER_PGD));
  22. pgd_ofs++, pgd++;
  23. }
  24. flush_tlb_all();
  25. }
  26. /**
  27. * acpi_save_state_mem - save kernel state
  28. *
  29. * Create an identity mapped page table and copy the wakeup routine to
  30. * low memory.
  31. */
  32. int acpi_save_state_mem (void)
  33. {
  34. if (!acpi_wakeup_address)
  35. return 1;
  36. init_low_mapping(swapper_pg_dir, USER_PTRS_PER_PGD);
  37. memcpy((void *) acpi_wakeup_address, &wakeup_start, &wakeup_end - &wakeup_start);
  38. acpi_copy_wakeup_routine(acpi_wakeup_address);
  39. return 0;
  40. }
  41. /*
  42. * acpi_restore_state - undo effects of acpi_save_state_mem
  43. */
  44. void acpi_restore_state_mem (void)
  45. {
  46. zap_low_mappings();
  47. }
  48. /**
  49. * acpi_reserve_bootmem - do _very_ early ACPI initialisation
  50. *
  51. * We allocate a page from the first 1MB of memory for the wakeup
  52. * routine for when we come back from a sleep state. The
  53. * runtime allocator allows specification of <16MB pages, but not
  54. * <1MB pages.
  55. */
  56. void __init acpi_reserve_bootmem(void)
  57. {
  58. if ((&wakeup_end - &wakeup_start) > PAGE_SIZE) {
  59. printk(KERN_ERR "ACPI: Wakeup code way too big, S3 disabled.\n");
  60. return;
  61. }
  62. acpi_wakeup_address = (unsigned long)alloc_bootmem_low(PAGE_SIZE);
  63. if (!acpi_wakeup_address)
  64. printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
  65. }
  66. static int __init acpi_sleep_setup(char *str)
  67. {
  68. while ((str != NULL) && (*str != '\0')) {
  69. if (strncmp(str, "s3_bios", 7) == 0)
  70. acpi_video_flags = 1;
  71. if (strncmp(str, "s3_mode", 7) == 0)
  72. acpi_video_flags |= 2;
  73. str = strchr(str, ',');
  74. if (str != NULL)
  75. str += strspn(str, ", \t");
  76. }
  77. return 1;
  78. }
  79. __setup("acpi_sleep=", acpi_sleep_setup);