2 * linux/arch/unicore32/kernel/hibernate.c
4 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 Guan Xuetao
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/gfp.h>
15 #include <linux/suspend.h>
16 #include <linux/bootmem.h>
19 #include <asm/pgtable.h>
20 #include <asm/pgalloc.h>
21 #include <asm/suspend.h>
25 /* Pointer to the temporary resume page tables */
28 struct swsusp_arch_regs swsusp_arch_regs_cpu0;
31 * Create a middle page table on a resume-safe page and put a pointer to it in
32 * the given global directory entry. This only returns the gd entry
33 * in non-PAE compilation mode, since the middle layer is folded.
35 static pmd_t *resume_one_md_table_init(pgd_t *pgd)
40 pud = pud_offset(pgd, 0);
41 pmd_table = pmd_offset(pud, 0);
47 * Create a page table on a resume-safe page and place a pointer to it in
48 * a middle page directory entry.
50 static pte_t *resume_one_page_table_init(pmd_t *pmd)
53 pte_t *page_table = (pte_t *)get_safe_page(GFP_ATOMIC);
57 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_KERNEL_TABLE));
59 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
64 return pte_offset_kernel(pmd, 0);
68 * This maps the physical memory to kernel virtual address space, a total
69 * of max_low_pfn pages, by creating page tables starting from address
70 * PAGE_OFFSET. The page tables are allocated out of resume-safe pages.
72 static int resume_physical_mapping_init(pgd_t *pgd_base)
80 pgd_idx = pgd_index(PAGE_OFFSET);
81 pgd = pgd_base + pgd_idx;
84 for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
85 pmd = resume_one_md_table_init(pgd);
89 if (pfn >= max_low_pfn)
92 for (pmd_idx = 0; pmd_idx < PTRS_PER_PMD; pmd++, pmd_idx++) {
95 if (pfn >= max_low_pfn)
98 /* Map with normal page tables.
99 * NOTE: We can mark everything as executable here
101 pte = resume_one_page_table_init(pmd);
105 max_pte = pte + PTRS_PER_PTE;
106 for (; pte < max_pte; pte++, pfn++) {
107 if (pfn >= max_low_pfn)
110 set_pte(pte, pfn_pte(pfn, PAGE_KERNEL_EXEC));
118 static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
122 int swsusp_arch_resume(void)
126 resume_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
130 resume_init_first_level_page_table(resume_pg_dir);
131 error = resume_physical_mapping_init(resume_pg_dir);
135 /* We have got enough memory and from now on we cannot recover */
136 restore_image(resume_pg_dir, restore_pblist);
141 * pfn_is_nosave - check if given pfn is in the 'nosave' section
144 int pfn_is_nosave(unsigned long pfn)
146 unsigned long begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT;
147 unsigned long end_pfn = PAGE_ALIGN(__pa(&__nosave_end)) >> PAGE_SHIFT;
149 return (pfn >= begin_pfn) && (pfn < end_pfn);
152 void save_processor_state(void)
156 void restore_processor_state(void)
158 local_flush_tlb_all();