1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/unicore32/kernel/hibernate.c
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
8 * Copyright (C) 2001-2010 Guan Xuetao
11 #include <linux/gfp.h>
12 #include <linux/suspend.h>
13 #include <linux/memblock.h>
16 #include <asm/pgtable.h>
17 #include <asm/pgalloc.h>
18 #include <asm/sections.h>
19 #include <asm/suspend.h>
23 /* Pointer to the temporary resume page tables */
26 struct swsusp_arch_regs swsusp_arch_regs_cpu0
;
29 * Create a middle page table on a resume-safe page and put a pointer to it in
30 * the given global directory entry. This only returns the gd entry
31 * in non-PAE compilation mode, since the middle layer is folded.
33 static pmd_t
*resume_one_md_table_init(pgd_t
*pgd
)
38 pud
= pud_offset(pgd
, 0);
39 pmd_table
= pmd_offset(pud
, 0);
45 * Create a page table on a resume-safe page and place a pointer to it in
46 * a middle page directory entry.
48 static pte_t
*resume_one_page_table_init(pmd_t
*pmd
)
51 pte_t
*page_table
= (pte_t
*)get_safe_page(GFP_ATOMIC
);
55 set_pmd(pmd
, __pmd(__pa(page_table
) | _PAGE_KERNEL_TABLE
));
57 BUG_ON(page_table
!= pte_offset_kernel(pmd
, 0));
62 return pte_offset_kernel(pmd
, 0);
66 * This maps the physical memory to kernel virtual address space, a total
67 * of max_low_pfn pages, by creating page tables starting from address
68 * PAGE_OFFSET. The page tables are allocated out of resume-safe pages.
70 static int resume_physical_mapping_init(pgd_t
*pgd_base
)
78 pgd_idx
= pgd_index(PAGE_OFFSET
);
79 pgd
= pgd_base
+ pgd_idx
;
82 for (; pgd_idx
< PTRS_PER_PGD
; pgd
++, pgd_idx
++) {
83 pmd
= resume_one_md_table_init(pgd
);
87 if (pfn
>= max_low_pfn
)
90 for (pmd_idx
= 0; pmd_idx
< PTRS_PER_PMD
; pmd
++, pmd_idx
++) {
93 if (pfn
>= max_low_pfn
)
96 /* Map with normal page tables.
97 * NOTE: We can mark everything as executable here
99 pte
= resume_one_page_table_init(pmd
);
103 max_pte
= pte
+ PTRS_PER_PTE
;
104 for (; pte
< max_pte
; pte
++, pfn
++) {
105 if (pfn
>= max_low_pfn
)
108 set_pte(pte
, pfn_pte(pfn
, PAGE_KERNEL_EXEC
));
116 static inline void resume_init_first_level_page_table(pgd_t
*pg_dir
)
120 int swsusp_arch_resume(void)
124 resume_pg_dir
= (pgd_t
*)get_safe_page(GFP_ATOMIC
);
128 resume_init_first_level_page_table(resume_pg_dir
);
129 error
= resume_physical_mapping_init(resume_pg_dir
);
133 /* We have got enough memory and from now on we cannot recover */
134 restore_image(resume_pg_dir
, restore_pblist
);
139 * pfn_is_nosave - check if given pfn is in the 'nosave' section
142 int pfn_is_nosave(unsigned long pfn
)
144 unsigned long begin_pfn
= __pa(&__nosave_begin
) >> PAGE_SHIFT
;
145 unsigned long end_pfn
= PAGE_ALIGN(__pa(&__nosave_end
)) >> PAGE_SHIFT
;
147 return (pfn
>= begin_pfn
) && (pfn
< end_pfn
);
150 void save_processor_state(void)
154 void restore_processor_state(void)
156 local_flush_tlb_all();