hibernate.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Hibernation support specific for ARM
  3. *
  4. * Derived from work on ARM hibernation support by:
  5. *
  6. * Ubuntu project, hibernation support for mach-dove
  7. * Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu)
  8. * Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.)
  9. * https://lkml.org/lkml/2010/6/18/4
  10. * https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
  11. * https://patchwork.kernel.org/patch/96442/
  12. *
  13. * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
  14. *
  15. * License terms: GNU General Public License (GPL) version 2
  16. */
  17. #include <linux/mm.h>
  18. #include <linux/suspend.h>
  19. #include <asm/system_misc.h>
  20. #include <asm/idmap.h>
  21. #include <asm/suspend.h>
  22. #include <asm/memory.h>
  23. #include <asm/sections.h>
  24. #include "reboot.h"
  25. int pfn_is_nosave(unsigned long pfn)
  26. {
  27. unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
  28. unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
  29. return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
  30. }
  31. void notrace save_processor_state(void)
  32. {
  33. WARN_ON(num_online_cpus() != 1);
  34. local_fiq_disable();
  35. }
  36. void notrace restore_processor_state(void)
  37. {
  38. local_fiq_enable();
  39. }
  40. /*
  41. * Snapshot kernel memory and reset the system.
  42. *
  43. * swsusp_save() is executed in the suspend finisher so that the CPU
  44. * context pointer and memory are part of the saved image, which is
  45. * required by the resume kernel image to restart execution from
  46. * swsusp_arch_suspend().
  47. *
  48. * soft_restart is not technically needed, but is used to get success
  49. * returned from cpu_suspend.
  50. *
  51. * When soft reboot completes, the hibernation snapshot is written out.
  52. */
  53. static int notrace arch_save_image(unsigned long unused)
  54. {
  55. int ret;
  56. ret = swsusp_save();
  57. if (ret == 0)
  58. _soft_restart(virt_to_idmap(cpu_resume), false);
  59. return ret;
  60. }
  61. /*
  62. * Save the current CPU state before suspend / poweroff.
  63. */
  64. int notrace swsusp_arch_suspend(void)
  65. {
  66. return cpu_suspend(0, arch_save_image);
  67. }
  68. /*
  69. * Restore page contents for physical pages that were in use during loading
  70. * hibernation image. Switch to idmap_pgd so the physical page tables
  71. * are overwritten with the same contents.
  72. */
  73. static void notrace arch_restore_image(void *unused)
  74. {
  75. struct pbe *pbe;
  76. cpu_switch_mm(idmap_pgd, &init_mm);
  77. for (pbe = restore_pblist; pbe; pbe = pbe->next)
  78. copy_page(pbe->orig_address, pbe->address);
  79. _soft_restart(virt_to_idmap(cpu_resume), false);
  80. }
  81. static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
  82. /*
  83. * Resume from the hibernation image.
  84. * Due to the kernel heap / data restore, stack contents change underneath
  85. * and that would make function calls impossible; switch to a temporary
  86. * stack within the nosave region to avoid that problem.
  87. */
  88. int swsusp_arch_resume(void)
  89. {
  90. call_with_stack(arch_restore_image, 0,
  91. resume_stack + ARRAY_SIZE(resume_stack));
  92. return 0;
  93. }