pgalloc.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * arch/arm/include/asm/pgalloc.h
  3. *
  4. * Copyright (C) 2000-2001 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _ASMARM_PGALLOC_H
  11. #define _ASMARM_PGALLOC_H
  12. #include <linux/pagemap.h>
  13. #include <asm/domain.h>
  14. #include <asm/pgtable-hwdef.h>
  15. #include <asm/processor.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/tlbflush.h>
  18. #define check_pgt_cache() do { } while (0)
  19. #ifdef CONFIG_MMU
  20. #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
  21. #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
  22. #ifdef CONFIG_ARM_LPAE
  23. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  24. {
  25. return (pmd_t *)get_zeroed_page(GFP_KERNEL);
  26. }
  27. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  28. {
  29. BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
  30. free_page((unsigned long)pmd);
  31. }
  32. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  33. {
  34. set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
  35. }
  36. #else /* !CONFIG_ARM_LPAE */
  37. /*
  38. * Since we have only two-level page tables, these are trivial
  39. */
  40. #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
  41. #define pmd_free(mm, pmd) do { } while (0)
  42. #define pud_populate(mm,pmd,pte) BUG()
  43. #endif /* CONFIG_ARM_LPAE */
  44. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  45. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  46. #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
  47. static inline void clean_pte_table(pte_t *pte)
  48. {
  49. clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
  50. }
  51. /*
  52. * Allocate one PTE table.
  53. *
  54. * This actually allocates two hardware PTE tables, but we wrap this up
  55. * into one table thus:
  56. *
  57. * +------------+
  58. * | Linux pt 0 |
  59. * +------------+
  60. * | Linux pt 1 |
  61. * +------------+
  62. * | h/w pt 0 |
  63. * +------------+
  64. * | h/w pt 1 |
  65. * +------------+
  66. */
  67. static inline pte_t *
  68. pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
  69. {
  70. pte_t *pte;
  71. pte = (pte_t *)__get_free_page(PGALLOC_GFP);
  72. if (pte)
  73. clean_pte_table(pte);
  74. return pte;
  75. }
  76. static inline pgtable_t
  77. pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  78. {
  79. struct page *pte;
  80. #ifdef CONFIG_HIGHPTE
  81. pte = alloc_pages(PGALLOC_GFP | __GFP_HIGHMEM, 0);
  82. #else
  83. pte = alloc_pages(PGALLOC_GFP, 0);
  84. #endif
  85. if (!pte)
  86. return NULL;
  87. if (!PageHighMem(pte))
  88. clean_pte_table(page_address(pte));
  89. if (!pgtable_page_ctor(pte)) {
  90. __free_page(pte);
  91. return NULL;
  92. }
  93. return pte;
  94. }
  95. /*
  96. * Free one PTE table.
  97. */
  98. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  99. {
  100. if (pte)
  101. free_page((unsigned long)pte);
  102. }
  103. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  104. {
  105. pgtable_page_dtor(pte);
  106. __free_page(pte);
  107. }
  108. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
  109. pmdval_t prot)
  110. {
  111. pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot;
  112. pmdp[0] = __pmd(pmdval);
  113. #ifndef CONFIG_ARM_LPAE
  114. pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
  115. #endif
  116. flush_pmd_entry(pmdp);
  117. }
  118. /*
  119. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  120. * of the mm address space.
  121. *
  122. * Ensure that we always set both PMD entries.
  123. */
  124. static inline void
  125. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  126. {
  127. /*
  128. * The pmd must be loaded with the physical address of the PTE table
  129. */
  130. __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
  131. }
  132. static inline void
  133. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  134. {
  135. extern pmdval_t user_pmd_table;
  136. pmdval_t prot;
  137. if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE))
  138. prot = user_pmd_table;
  139. else
  140. prot = _PAGE_USER_TABLE;
  141. __pmd_populate(pmdp, page_to_phys(ptep), prot);
  142. }
  143. #define pmd_pgtable(pmd) pmd_page(pmd)
  144. #endif /* CONFIG_MMU */
  145. #endif