sleep.c 2.1 KB

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