hibernate.c 3.4 KB

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