hibernate.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * linux/arch/unicore32/kernel/hibernate.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Maintained by GUAN Xue-tao <gxt@mprc.pku.edu.cn>
  7. * Copyright (C) 2001-2010 Guan Xuetao
  8. *
  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.
  12. */
  13. #include <linux/gfp.h>
  14. #include <linux/suspend.h>
  15. #include <linux/bootmem.h>
  16. #include <asm/system.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/suspend.h>
  21. #include "mach/pm.h"
  22. /* Pointer to the temporary resume page tables */
  23. pgd_t *resume_pg_dir;
  24. struct swsusp_arch_regs swsusp_arch_regs_cpu0;
  25. /*
  26. * Create a middle page table on a resume-safe page and put a pointer to it in
  27. * the given global directory entry. This only returns the gd entry
  28. * in non-PAE compilation mode, since the middle layer is folded.
  29. */
  30. static pmd_t *resume_one_md_table_init(pgd_t *pgd)
  31. {
  32. pud_t *pud;
  33. pmd_t *pmd_table;
  34. pud = pud_offset(pgd, 0);
  35. pmd_table = pmd_offset(pud, 0);
  36. return pmd_table;
  37. }
  38. /*
  39. * Create a page table on a resume-safe page and place a pointer to it in
  40. * a middle page directory entry.
  41. */
  42. static pte_t *resume_one_page_table_init(pmd_t *pmd)
  43. {
  44. if (pmd_none(*pmd)) {
  45. pte_t *page_table = (pte_t *)get_safe_page(GFP_ATOMIC);
  46. if (!page_table)
  47. return NULL;
  48. set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_KERNEL_TABLE));
  49. BUG_ON(page_table != pte_offset_kernel(pmd, 0));
  50. return page_table;
  51. }
  52. return pte_offset_kernel(pmd, 0);
  53. }
  54. /*
  55. * This maps the physical memory to kernel virtual address space, a total
  56. * of max_low_pfn pages, by creating page tables starting from address
  57. * PAGE_OFFSET. The page tables are allocated out of resume-safe pages.
  58. */
  59. static int resume_physical_mapping_init(pgd_t *pgd_base)
  60. {
  61. unsigned long pfn;
  62. pgd_t *pgd;
  63. pmd_t *pmd;
  64. pte_t *pte;
  65. int pgd_idx, pmd_idx;
  66. pgd_idx = pgd_index(PAGE_OFFSET);
  67. pgd = pgd_base + pgd_idx;
  68. pfn = 0;
  69. for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
  70. pmd = resume_one_md_table_init(pgd);
  71. if (!pmd)
  72. return -ENOMEM;
  73. if (pfn >= max_low_pfn)
  74. continue;
  75. for (pmd_idx = 0; pmd_idx < PTRS_PER_PMD; pmd++, pmd_idx++) {
  76. pte_t *max_pte;
  77. if (pfn >= max_low_pfn)
  78. break;
  79. /* Map with normal page tables.
  80. * NOTE: We can mark everything as executable here
  81. */
  82. pte = resume_one_page_table_init(pmd);
  83. if (!pte)
  84. return -ENOMEM;
  85. max_pte = pte + PTRS_PER_PTE;
  86. for (; pte < max_pte; pte++, pfn++) {
  87. if (pfn >= max_low_pfn)
  88. break;
  89. set_pte(pte, pfn_pte(pfn, PAGE_KERNEL_EXEC));
  90. }
  91. }
  92. }
  93. return 0;
  94. }
  95. static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
  96. {
  97. }
  98. int swsusp_arch_resume(void)
  99. {
  100. int error;
  101. resume_pg_dir = (pgd_t *)get_safe_page(GFP_ATOMIC);
  102. if (!resume_pg_dir)
  103. return -ENOMEM;
  104. resume_init_first_level_page_table(resume_pg_dir);
  105. error = resume_physical_mapping_init(resume_pg_dir);
  106. if (error)
  107. return error;
  108. /* We have got enough memory and from now on we cannot recover */
  109. restore_image(resume_pg_dir, restore_pblist);
  110. return 0;
  111. }
  112. /*
  113. * pfn_is_nosave - check if given pfn is in the 'nosave' section
  114. */
  115. int pfn_is_nosave(unsigned long pfn)
  116. {
  117. unsigned long begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT;
  118. unsigned long end_pfn = PAGE_ALIGN(__pa(&__nosave_end)) >> PAGE_SHIFT;
  119. return (pfn >= begin_pfn) && (pfn < end_pfn);
  120. }
  121. void save_processor_state(void)
  122. {
  123. }
  124. void restore_processor_state(void)
  125. {
  126. local_flush_tlb_all();
  127. }