blob: ed4160b64e66b03d607cd2cf00b9cdac425a8395 [file] [log] [blame]
Russell Kinge8ce0eb2011-08-26 20:28:52 +01001#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
9static pgd_t *suspend_pgd;
10
11extern int __cpu_suspend(int, long, unsigned long, int (*)(unsigned long));
Russell King62b2d072011-08-31 23:26:18 +010012extern void cpu_resume_mmu(void);
Russell Kinge8ce0eb2011-08-26 20:28:52 +010013
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 */
18int 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 Kingde8e71c2011-08-27 22:39:09 +010027 * 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 Kinge8ce0eb2011-08-26 20:28:52 +010031 */
Russell Kingde8e71c2011-08-27 22:39:09 +010032 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 Kinge8ce0eb2011-08-26 20:28:52 +010038
39 return ret;
40}
41
42static int __init cpu_suspend_init(void)
43{
44 suspend_pgd = pgd_alloc(&init_mm);
45 if (suspend_pgd) {
Russell King62b2d072011-08-31 23:26:18 +010046 unsigned long addr = virt_to_phys(cpu_resume_mmu);
Russell Kinge8ce0eb2011-08-26 20:28:52 +010047 identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE);
48 }
49 return suspend_pgd ? 0 : -ENOMEM;
50}
51core_initcall(cpu_suspend_init);