2011-08-27 02:28:52 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <asm/pgalloc.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/memory.h>
|
|
|
|
#include <asm/suspend.h>
|
|
|
|
#include <asm/tlbflush.h>
|
|
|
|
|
|
|
|
static pgd_t *suspend_pgd;
|
|
|
|
|
|
|
|
extern int __cpu_suspend(int, long, unsigned long, int (*)(unsigned long));
|
2011-09-01 05:26:18 +07:00
|
|
|
extern void cpu_resume_mmu(void);
|
2011-08-27 02:28:52 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hide the first two arguments to __cpu_suspend - these are an implementation
|
|
|
|
* detail which platform code shouldn't have to know about.
|
|
|
|
*/
|
|
|
|
int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
|
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->active_mm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!suspend_pgd)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/*
|
2011-08-28 04:39:09 +07:00
|
|
|
* Provide a temporary page table with an identity mapping for
|
|
|
|
* the MMU-enable code, required for resuming. On successful
|
|
|
|
* resume (indicated by a zero return code), we need to switch
|
|
|
|
* back to the correct page tables.
|
2011-08-27 02:28:52 +07:00
|
|
|
*/
|
2011-08-28 04:39:09 +07:00
|
|
|
ret = __cpu_suspend(virt_to_phys(suspend_pgd),
|
|
|
|
PHYS_OFFSET - PAGE_OFFSET, arg, fn);
|
|
|
|
if (ret == 0) {
|
|
|
|
cpu_switch_mm(mm->pgd, mm);
|
|
|
|
local_flush_tlb_all();
|
|
|
|
}
|
2011-08-27 02:28:52 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init cpu_suspend_init(void)
|
|
|
|
{
|
|
|
|
suspend_pgd = pgd_alloc(&init_mm);
|
|
|
|
if (suspend_pgd) {
|
2011-09-01 05:26:18 +07:00
|
|
|
unsigned long addr = virt_to_phys(cpu_resume_mmu);
|
2011-08-27 02:28:52 +07:00
|
|
|
identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE);
|
|
|
|
}
|
|
|
|
return suspend_pgd ? 0 : -ENOMEM;
|
|
|
|
}
|
|
|
|
core_initcall(cpu_suspend_init);
|