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)); |
Russell King | 62b2d07 | 2011-08-31 23:26:18 +0100 | [diff] [blame^] | 12 | extern void cpu_resume_mmu(void); |
Russell King | e8ce0eb | 2011-08-26 20:28:52 +0100 | [diff] [blame] | 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 | /* |
Russell King | de8e71c | 2011-08-27 22:39:09 +0100 | [diff] [blame] | 27 | * Provide a temporary page table with an identity mapping for |
| 28 | * the MMU-enable code, required for resuming. On successful |
| 29 | * resume (indicated by a zero return code), we need to switch |
| 30 | * back to the correct page tables. |
Russell King | e8ce0eb | 2011-08-26 20:28:52 +0100 | [diff] [blame] | 31 | */ |
Russell King | de8e71c | 2011-08-27 22:39:09 +0100 | [diff] [blame] | 32 | ret = __cpu_suspend(virt_to_phys(suspend_pgd), |
| 33 | PHYS_OFFSET - PAGE_OFFSET, arg, fn); |
| 34 | if (ret == 0) { |
| 35 | cpu_switch_mm(mm->pgd, mm); |
| 36 | local_flush_tlb_all(); |
| 37 | } |
Russell King | e8ce0eb | 2011-08-26 20:28:52 +0100 | [diff] [blame] | 38 | |
| 39 | return ret; |
| 40 | } |
| 41 | |
| 42 | static int __init cpu_suspend_init(void) |
| 43 | { |
| 44 | suspend_pgd = pgd_alloc(&init_mm); |
| 45 | if (suspend_pgd) { |
Russell King | 62b2d07 | 2011-08-31 23:26:18 +0100 | [diff] [blame^] | 46 | unsigned long addr = virt_to_phys(cpu_resume_mmu); |
Russell King | e8ce0eb | 2011-08-26 20:28:52 +0100 | [diff] [blame] | 47 | identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE); |
| 48 | } |
| 49 | return suspend_pgd ? 0 : -ENOMEM; |
| 50 | } |
| 51 | core_initcall(cpu_suspend_init); |