pgalloc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Based on arch/arm/include/asm/pgalloc.h
  3. *
  4. * Copyright (C) 2000-2001 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __ASM_PGALLOC_H
  20. #define __ASM_PGALLOC_H
  21. #include <asm/pgtable-hwdef.h>
  22. #include <asm/processor.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/tlbflush.h>
  25. #define check_pgt_cache() do { } while (0)
  26. #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
  27. #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  28. #if CONFIG_PGTABLE_LEVELS > 2
  29. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  30. {
  31. return (pmd_t *)__get_free_page(PGALLOC_GFP);
  32. }
  33. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  34. {
  35. BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
  36. free_page((unsigned long)pmd);
  37. }
  38. static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot)
  39. {
  40. set_pud(pud, __pud(pmd | prot));
  41. }
  42. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  43. {
  44. __pud_populate(pud, __pa(pmd), PMD_TYPE_TABLE);
  45. }
  46. #else
  47. static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot)
  48. {
  49. BUILD_BUG();
  50. }
  51. #endif /* CONFIG_PGTABLE_LEVELS > 2 */
  52. #if CONFIG_PGTABLE_LEVELS > 3
  53. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  54. {
  55. return (pud_t *)__get_free_page(PGALLOC_GFP);
  56. }
  57. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  58. {
  59. BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
  60. free_page((unsigned long)pud);
  61. }
  62. static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot)
  63. {
  64. set_pgd(pgdp, __pgd(pud | prot));
  65. }
  66. static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
  67. {
  68. __pgd_populate(pgd, __pa(pud), PUD_TYPE_TABLE);
  69. }
  70. #else
  71. static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot)
  72. {
  73. BUILD_BUG();
  74. }
  75. #endif /* CONFIG_PGTABLE_LEVELS > 3 */
  76. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  77. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  78. static inline pte_t *
  79. pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
  80. {
  81. return (pte_t *)__get_free_page(PGALLOC_GFP);
  82. }
  83. static inline pgtable_t
  84. pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  85. {
  86. struct page *pte;
  87. pte = alloc_pages(PGALLOC_GFP, 0);
  88. if (!pte)
  89. return NULL;
  90. if (!pgtable_page_ctor(pte)) {
  91. __free_page(pte);
  92. return NULL;
  93. }
  94. return pte;
  95. }
  96. /*
  97. * Free a PTE table.
  98. */
  99. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  100. {
  101. if (pte)
  102. free_page((unsigned long)pte);
  103. }
  104. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  105. {
  106. pgtable_page_dtor(pte);
  107. __free_page(pte);
  108. }
  109. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
  110. pmdval_t prot)
  111. {
  112. set_pmd(pmdp, __pmd(pte | prot));
  113. }
  114. /*
  115. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  116. * of the mm address space.
  117. */
  118. static inline void
  119. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  120. {
  121. /*
  122. * The pmd must be loaded with the physical address of the PTE table
  123. */
  124. __pmd_populate(pmdp, __pa(ptep), PMD_TYPE_TABLE);
  125. }
  126. static inline void
  127. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  128. {
  129. __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE);
  130. }
  131. #define pmd_pgtable(pmd) pmd_page(pmd)
  132. #endif