pgalloc-64.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #ifndef _ASM_POWERPC_PGALLOC_64_H
  2. #define _ASM_POWERPC_PGALLOC_64_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. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  40. {
  41. return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL);
  42. }
  43. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  44. {
  45. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  46. }
  47. #ifndef CONFIG_PPC_64K_PAGES
  48. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  49. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  50. {
  51. return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE),
  52. GFP_KERNEL|__GFP_REPEAT);
  53. }
  54. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  55. {
  56. kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud);
  57. }
  58. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  59. {
  60. pud_set(pud, (unsigned long)pmd);
  61. }
  62. #define pmd_populate(mm, pmd, pte_page) \
  63. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  64. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  65. #define pmd_pgtable(pmd) pmd_page(pmd)
  66. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  67. unsigned long address)
  68. {
  69. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  70. }
  71. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  72. unsigned long address)
  73. {
  74. struct page *page;
  75. pte_t *pte;
  76. pte = pte_alloc_one_kernel(mm, address);
  77. if (!pte)
  78. return NULL;
  79. page = virt_to_page(pte);
  80. if (!pgtable_page_ctor(page)) {
  81. __free_page(page);
  82. return NULL;
  83. }
  84. return page;
  85. }
  86. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  87. {
  88. free_page((unsigned long)pte);
  89. }
  90. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  91. {
  92. pgtable_page_dtor(ptepage);
  93. __free_page(ptepage);
  94. }
  95. static inline void pgtable_free(void *table, unsigned index_size)
  96. {
  97. if (!index_size)
  98. free_page((unsigned long)table);
  99. else {
  100. BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  101. kmem_cache_free(PGT_CACHE(index_size), table);
  102. }
  103. }
  104. #ifdef CONFIG_SMP
  105. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  106. void *table, int shift)
  107. {
  108. unsigned long pgf = (unsigned long)table;
  109. BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  110. pgf |= shift;
  111. tlb_remove_table(tlb, (void *)pgf);
  112. }
  113. static inline void __tlb_remove_table(void *_table)
  114. {
  115. void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
  116. unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
  117. pgtable_free(table, shift);
  118. }
  119. #else /* !CONFIG_SMP */
  120. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  121. void *table, int shift)
  122. {
  123. pgtable_free(table, shift);
  124. }
  125. #endif /* CONFIG_SMP */
  126. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  127. unsigned long address)
  128. {
  129. tlb_flush_pgtable(tlb, address);
  130. pgtable_page_dtor(table);
  131. pgtable_free_tlb(tlb, page_address(table), 0);
  132. }
  133. #else /* if CONFIG_PPC_64K_PAGES */
  134. /*
  135. * we support 16 fragments per PTE page.
  136. */
  137. #define PTE_FRAG_NR 16
  138. /*
  139. * We use a 2K PTE page fragment and another 2K for storing
  140. * real_pte_t hash index
  141. */
  142. #define PTE_FRAG_SIZE_SHIFT 12
  143. #define PTE_FRAG_SIZE (2 * PTRS_PER_PTE * sizeof(pte_t))
  144. extern pte_t *page_table_alloc(struct mm_struct *, unsigned long, int);
  145. extern void page_table_free(struct mm_struct *, unsigned long *, int);
  146. extern void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift);
  147. #ifdef CONFIG_SMP
  148. extern void __tlb_remove_table(void *_table);
  149. #endif
  150. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  151. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  152. pte_t *pte)
  153. {
  154. pmd_set(pmd, (unsigned long)pte);
  155. }
  156. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  157. pgtable_t pte_page)
  158. {
  159. pmd_set(pmd, (unsigned long)pte_page);
  160. }
  161. static inline pgtable_t pmd_pgtable(pmd_t pmd)
  162. {
  163. return (pgtable_t)(pmd_val(pmd) & ~PMD_MASKED_BITS);
  164. }
  165. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  166. unsigned long address)
  167. {
  168. return (pte_t *)page_table_alloc(mm, address, 1);
  169. }
  170. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  171. unsigned long address)
  172. {
  173. return (pgtable_t)page_table_alloc(mm, address, 0);
  174. }
  175. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  176. {
  177. page_table_free(mm, (unsigned long *)pte, 1);
  178. }
  179. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  180. {
  181. page_table_free(mm, (unsigned long *)ptepage, 0);
  182. }
  183. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  184. unsigned long address)
  185. {
  186. tlb_flush_pgtable(tlb, address);
  187. pgtable_free_tlb(tlb, table, 0);
  188. }
  189. #endif /* CONFIG_PPC_64K_PAGES */
  190. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  191. {
  192. return kmem_cache_alloc(PGT_CACHE(PMD_CACHE_INDEX),
  193. GFP_KERNEL|__GFP_REPEAT);
  194. }
  195. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  196. {
  197. kmem_cache_free(PGT_CACHE(PMD_CACHE_INDEX), pmd);
  198. }
  199. #define __pmd_free_tlb(tlb, pmd, addr) \
  200. pgtable_free_tlb(tlb, pmd, PMD_CACHE_INDEX)
  201. #ifndef CONFIG_PPC_64K_PAGES
  202. #define __pud_free_tlb(tlb, pud, addr) \
  203. pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
  204. #endif /* CONFIG_PPC_64K_PAGES */
  205. #define check_pgt_cache() do { } while (0)
  206. #endif /* _ASM_POWERPC_PGALLOC_64_H */