suspend.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. u32 *ctx = ptr;
  18. *save_ptr = virt_to_phys(ptr);
  19. /* This must correspond to the LDM in cpu_resume() assembly */
  20. *ptr++ = virt_to_phys(idmap_pgd);
  21. *ptr++ = sp;
  22. *ptr++ = virt_to_phys(cpu_do_resume);
  23. cpu_do_suspend(ptr);
  24. flush_cache_louis();
  25. /*
  26. * flush_cache_louis does not guarantee that
  27. * save_ptr and ptr are cleaned to main memory,
  28. * just up to the Level of Unification Inner Shareable.
  29. * Since the context pointer and context itself
  30. * are to be retrieved with the MMU off that
  31. * data must be cleaned from all cache levels
  32. * to main memory using "area" cache primitives.
  33. */
  34. __cpuc_flush_dcache_area(ctx, ptrsz);
  35. __cpuc_flush_dcache_area(save_ptr, sizeof(*save_ptr));
  36. outer_clean_range(*save_ptr, *save_ptr + ptrsz);
  37. outer_clean_range(virt_to_phys(save_ptr),
  38. virt_to_phys(save_ptr) + sizeof(*save_ptr));
  39. }
  40. /*
  41. * Hide the first two arguments to __cpu_suspend - these are an implementation
  42. * detail which platform code shouldn't have to know about.
  43. */
  44. int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
  45. {
  46. struct mm_struct *mm = current->active_mm;
  47. int ret;
  48. if (!idmap_pgd)
  49. return -EINVAL;
  50. /*
  51. * Provide a temporary page table with an identity mapping for
  52. * the MMU-enable code, required for resuming. On successful
  53. * resume (indicated by a zero return code), we need to switch
  54. * back to the correct page tables.
  55. */
  56. ret = __cpu_suspend(arg, fn);
  57. if (ret == 0) {
  58. cpu_switch_mm(mm->pgd, mm);
  59. local_flush_tlb_all();
  60. }
  61. return ret;
  62. }