suspend.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <linux/init.h>
  2. #include <asm/idmap.h>
  3. #include <asm/pgalloc.h>
  4. #include <asm/pgtable.h>
  5. #include <asm/memory.h>
  6. #include <asm/suspend.h>
  7. #include <asm/tlbflush.h>
  8. extern int __cpu_suspend(unsigned long, int (*)(unsigned long));
  9. extern void cpu_resume_mmu(void);
  10. /*
  11. * This is called by __cpu_suspend() to save the state, and do whatever
  12. * flushing is required to ensure that when the CPU goes to sleep we have
  13. * the necessary data available when the caches are not searched.
  14. */
  15. void __cpu_suspend_save(u32 *ptr, u32 ptrsz, u32 sp, u32 *save_ptr)
  16. {
  17. *save_ptr = virt_to_phys(ptr);
  18. /* This must correspond to the LDM in cpu_resume() assembly */
  19. *ptr++ = virt_to_phys(idmap_pgd);
  20. *ptr++ = sp;
  21. *ptr++ = virt_to_phys(cpu_do_resume);
  22. cpu_do_suspend(ptr);
  23. flush_cache_all();
  24. outer_clean_range(*save_ptr, *save_ptr + ptrsz);
  25. outer_clean_range(virt_to_phys(save_ptr),
  26. virt_to_phys(save_ptr) + sizeof(*save_ptr));
  27. }
  28. /*
  29. * Hide the first two arguments to __cpu_suspend - these are an implementation
  30. * detail which platform code shouldn't have to know about.
  31. */
  32. int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
  33. {
  34. struct mm_struct *mm = current->active_mm;
  35. int ret;
  36. if (!idmap_pgd)
  37. return -EINVAL;
  38. /*
  39. * Provide a temporary page table with an identity mapping for
  40. * the MMU-enable code, required for resuming. On successful
  41. * resume (indicated by a zero return code), we need to switch
  42. * back to the correct page tables.
  43. */
  44. ret = __cpu_suspend(arg, fn);
  45. if (ret == 0) {
  46. cpu_switch_mm(mm->pgd, mm);
  47. local_flush_tlb_all();
  48. }
  49. return ret;
  50. }