pgalloc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #ifndef _ASM_POWERPC_BOOK3S_64_PGALLOC_H
  2. #define _ASM_POWERPC_BOOK3S_64_PGALLOC_H
  3. /*
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/cpumask.h>
  11. #include <linux/percpu.h>
  12. struct vmemmap_backing {
  13. struct vmemmap_backing *list;
  14. unsigned long phys;
  15. unsigned long virt_addr;
  16. };
  17. extern struct vmemmap_backing *vmemmap_list;
  18. /*
  19. * Functions that deal with pagetables that could be at any level of
  20. * the table need to be passed an "index_size" so they know how to
  21. * handle allocation. For PTE pages (which are linked to a struct
  22. * page for now, and drawn from the main get_free_pages() pool), the
  23. * allocation size will be (2^index_size * sizeof(pointer)) and
  24. * allocations are drawn from the kmem_cache in PGT_CACHE(index_size).
  25. *
  26. * The maximum index size needs to be big enough to allow any
  27. * pagetable sizes we need, but small enough to fit in the low bits of
  28. * any page table pointer. In other words all pagetables, even tiny
  29. * ones, must be aligned to allow at least enough low 0 bits to
  30. * contain this value. This value is also used as a mask, so it must
  31. * be one less than a power of two.
  32. */
  33. #define MAX_PGTABLE_INDEX_SIZE 0xf
  34. extern struct kmem_cache *pgtable_cache[];
  35. #define PGT_CACHE(shift) ({ \
  36. BUG_ON(!(shift)); \
  37. pgtable_cache[(shift) - 1]; \
  38. })
  39. extern pte_t *pte_fragment_alloc(struct mm_struct *, unsigned long, int);
  40. extern pmd_t *pmd_fragment_alloc(struct mm_struct *, unsigned long);
  41. extern void pte_fragment_free(unsigned long *, int);
  42. extern void pmd_fragment_free(unsigned long *);
  43. extern void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift);
  44. #ifdef CONFIG_SMP
  45. extern void __tlb_remove_table(void *_table);
  46. #endif
  47. static inline pgd_t *radix__pgd_alloc(struct mm_struct *mm)
  48. {
  49. #ifdef CONFIG_PPC_64K_PAGES
  50. return (pgd_t *)__get_free_page(pgtable_gfp_flags(mm, PGALLOC_GFP));
  51. #else
  52. struct page *page;
  53. page = alloc_pages(pgtable_gfp_flags(mm, PGALLOC_GFP | __GFP_RETRY_MAYFAIL),
  54. 4);
  55. if (!page)
  56. return NULL;
  57. return (pgd_t *) page_address(page);
  58. #endif
  59. }
  60. static inline void radix__pgd_free(struct mm_struct *mm, pgd_t *pgd)
  61. {
  62. #ifdef CONFIG_PPC_64K_PAGES
  63. free_page((unsigned long)pgd);
  64. #else
  65. free_pages((unsigned long)pgd, 4);
  66. #endif
  67. }
  68. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  69. {
  70. pgd_t *pgd;
  71. if (radix_enabled())
  72. return radix__pgd_alloc(mm);
  73. pgd = kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
  74. pgtable_gfp_flags(mm, GFP_KERNEL));
  75. /*
  76. * With hugetlb, we don't clear the second half of the page table.
  77. * If we share the same slab cache with the pmd or pud level table,
  78. * we need to make sure we zero out the full table on alloc.
  79. * With 4K we don't store slot in the second half. Hence we don't
  80. * need to do this for 4k.
  81. */
  82. #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_PPC_64K_PAGES) && \
  83. (H_PGD_INDEX_SIZE == H_PUD_CACHE_INDEX)
  84. memset(pgd, 0, PGD_TABLE_SIZE);
  85. #endif
  86. return pgd;
  87. }
  88. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  89. {
  90. if (radix_enabled())
  91. return radix__pgd_free(mm, pgd);
  92. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  93. }
  94. static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
  95. {
  96. pgd_set(pgd, __pgtable_ptr_val(pud) | PGD_VAL_BITS);
  97. }
  98. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  99. {
  100. return kmem_cache_alloc(PGT_CACHE(PUD_CACHE_INDEX),
  101. pgtable_gfp_flags(mm, GFP_KERNEL));
  102. }
  103. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  104. {
  105. kmem_cache_free(PGT_CACHE(PUD_CACHE_INDEX), pud);
  106. }
  107. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  108. {
  109. pud_set(pud, __pgtable_ptr_val(pmd) | PUD_VAL_BITS);
  110. }
  111. static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
  112. unsigned long address)
  113. {
  114. /*
  115. * By now all the pud entries should be none entries. So go
  116. * ahead and flush the page walk cache
  117. */
  118. flush_tlb_pgtable(tlb, address);
  119. pgtable_free_tlb(tlb, pud, PUD_INDEX);
  120. }
  121. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  122. {
  123. return pmd_fragment_alloc(mm, addr);
  124. }
  125. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  126. {
  127. pmd_fragment_free((unsigned long *)pmd);
  128. }
  129. static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
  130. unsigned long address)
  131. {
  132. /*
  133. * By now all the pud entries should be none entries. So go
  134. * ahead and flush the page walk cache
  135. */
  136. flush_tlb_pgtable(tlb, address);
  137. return pgtable_free_tlb(tlb, pmd, PMD_INDEX);
  138. }
  139. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  140. pte_t *pte)
  141. {
  142. pmd_set(pmd, __pgtable_ptr_val(pte) | PMD_VAL_BITS);
  143. }
  144. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  145. pgtable_t pte_page)
  146. {
  147. pmd_set(pmd, __pgtable_ptr_val(pte_page) | PMD_VAL_BITS);
  148. }
  149. static inline pgtable_t pmd_pgtable(pmd_t pmd)
  150. {
  151. return (pgtable_t)pmd_page_vaddr(pmd);
  152. }
  153. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  154. unsigned long address)
  155. {
  156. return (pte_t *)pte_fragment_alloc(mm, address, 1);
  157. }
  158. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  159. unsigned long address)
  160. {
  161. return (pgtable_t)pte_fragment_alloc(mm, address, 0);
  162. }
  163. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  164. {
  165. pte_fragment_free((unsigned long *)pte, 1);
  166. }
  167. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  168. {
  169. pte_fragment_free((unsigned long *)ptepage, 0);
  170. }
  171. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  172. unsigned long address)
  173. {
  174. /*
  175. * By now all the pud entries should be none entries. So go
  176. * ahead and flush the page walk cache
  177. */
  178. flush_tlb_pgtable(tlb, address);
  179. pgtable_free_tlb(tlb, table, PTE_INDEX);
  180. }
  181. #define check_pgt_cache() do { } while (0)
  182. #endif /* _ASM_POWERPC_BOOK3S_64_PGALLOC_H */