Russell King | e8ce0eb | 2011-08-26 20:28:52 +0100 | [diff] [blame^] | 1 | #include <linux/init.h> |
| 2 | |
| 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 | |
| 9 | static pgd_t *suspend_pgd; |
| 10 | |
| 11 | extern int __cpu_suspend(int, long, unsigned long, int (*)(unsigned long)); |
| 12 | extern void cpu_resume_turn_mmu_on(void); |
| 13 | |
| 14 | /* |
| 15 | * Hide the first two arguments to __cpu_suspend - these are an implementation |
| 16 | * detail which platform code shouldn't have to know about. |
| 17 | */ |
| 18 | int cpu_suspend(unsigned long arg, int (*fn)(unsigned long)) |
| 19 | { |
| 20 | struct mm_struct *mm = current->active_mm; |
| 21 | int ret; |
| 22 | |
| 23 | if (!suspend_pgd) |
| 24 | return -EINVAL; |
| 25 | |
| 26 | /* |
| 27 | * Temporarily switch the page tables to our suspend page |
| 28 | * tables, which contain the temporary identity mapping |
| 29 | * required for resuming. |
| 30 | */ |
| 31 | cpu_switch_mm(suspend_pgd, mm); |
| 32 | ret = __cpu_suspend(0, PHYS_OFFSET - PAGE_OFFSET, arg, fn); |
| 33 | cpu_switch_mm(mm->pgd, mm); |
| 34 | local_flush_tlb_all(); |
| 35 | |
| 36 | return ret; |
| 37 | } |
| 38 | |
| 39 | static int __init cpu_suspend_init(void) |
| 40 | { |
| 41 | suspend_pgd = pgd_alloc(&init_mm); |
| 42 | if (suspend_pgd) { |
| 43 | unsigned long addr = virt_to_phys(cpu_resume_turn_mmu_on); |
| 44 | identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE); |
| 45 | } |
| 46 | return suspend_pgd ? 0 : -ENOMEM; |
| 47 | } |
| 48 | core_initcall(cpu_suspend_init); |