pgalloc-64.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. /*
  18. * Functions that deal with pagetables that could be at any level of
  19. * the table need to be passed an "index_size" so they know how to
  20. * handle allocation. For PTE pages (which are linked to a struct
  21. * page for now, and drawn from the main get_free_pages() pool), the
  22. * allocation size will be (2^index_size * sizeof(pointer)) and
  23. * allocations are drawn from the kmem_cache in PGT_CACHE(index_size).
  24. *
  25. * The maximum index size needs to be big enough to allow any
  26. * pagetable sizes we need, but small enough to fit in the low bits of
  27. * any page table pointer. In other words all pagetables, even tiny
  28. * ones, must be aligned to allow at least enough low 0 bits to
  29. * contain this value. This value is also used as a mask, so it must
  30. * be one less than a power of two.
  31. */
  32. #define MAX_PGTABLE_INDEX_SIZE 0xf
  33. extern struct kmem_cache *pgtable_cache[];
  34. #define PGT_CACHE(shift) ({ \
  35. BUG_ON(!(shift)); \
  36. pgtable_cache[(shift) - 1]; \
  37. })
  38. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  39. {
  40. return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL);
  41. }
  42. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  43. {
  44. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  45. }
  46. #ifndef CONFIG_PPC_64K_PAGES
  47. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  48. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  49. {
  50. return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE),
  51. GFP_KERNEL|__GFP_REPEAT);
  52. }
  53. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  54. {
  55. kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud);
  56. }
  57. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  58. {
  59. pud_set(pud, (unsigned long)pmd);
  60. }
  61. #define pmd_populate(mm, pmd, pte_page) \
  62. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  63. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  64. #define pmd_pgtable(pmd) pmd_page(pmd)
  65. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  66. unsigned long address)
  67. {
  68. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  69. }
  70. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  71. unsigned long address)
  72. {
  73. struct page *page;
  74. pte_t *pte;
  75. pte = pte_alloc_one_kernel(mm, address);
  76. if (!pte)
  77. return NULL;
  78. page = virt_to_page(pte);
  79. pgtable_page_ctor(page);
  80. return page;
  81. }
  82. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  83. {
  84. free_page((unsigned long)pte);
  85. }
  86. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  87. {
  88. pgtable_page_dtor(ptepage);
  89. __free_page(ptepage);
  90. }
  91. static inline void pgtable_free(void *table, unsigned index_size)
  92. {
  93. if (!index_size)
  94. free_page((unsigned long)table);
  95. else {
  96. BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  97. kmem_cache_free(PGT_CACHE(index_size), table);
  98. }
  99. }
  100. #ifdef CONFIG_SMP
  101. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  102. void *table, int shift)
  103. {
  104. unsigned long pgf = (unsigned long)table;
  105. BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  106. pgf |= shift;
  107. tlb_remove_table(tlb, (void *)pgf);
  108. }
  109. static inline void __tlb_remove_table(void *_table)
  110. {
  111. void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
  112. unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
  113. pgtable_free(table, shift);
  114. }
  115. #else /* !CONFIG_SMP */
  116. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  117. void *table, int shift)
  118. {
  119. pgtable_free(table, shift);
  120. }
  121. #endif /* CONFIG_SMP */
  122. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  123. unsigned long address)
  124. {
  125. struct page *page = page_address(table);
  126. tlb_flush_pgtable(tlb, address);
  127. pgtable_page_dtor(page);
  128. pgtable_free_tlb(tlb, page, 0);
  129. }
  130. #else /* if CONFIG_PPC_64K_PAGES */
  131. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  132. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  133. pte_t *pte)
  134. {
  135. pmd_set(pmd, (unsigned long)pte);
  136. }
  137. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  138. pgtable_t pte_page)
  139. {
  140. pmd_populate_kernel(mm, pmd, page_address(pte_page));
  141. }
  142. static inline pgtable_t pmd_pgtable(pmd_t pmd)
  143. {
  144. return pmd_page(pmd);
  145. }
  146. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  147. unsigned long address)
  148. {
  149. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  150. }
  151. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  152. unsigned long address)
  153. {
  154. struct page *page;
  155. pte_t *pte;
  156. pte = pte_alloc_one_kernel(mm, address);
  157. if (!pte)
  158. return NULL;
  159. page = virt_to_page(pte);
  160. pgtable_page_ctor(page);
  161. return page;
  162. }
  163. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  164. {
  165. free_page((unsigned long)pte);
  166. }
  167. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  168. {
  169. pgtable_page_dtor(ptepage);
  170. __free_page(ptepage);
  171. }
  172. static inline void pgtable_free(void *table, unsigned index_size)
  173. {
  174. if (!index_size)
  175. free_page((unsigned long)table);
  176. else {
  177. BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  178. kmem_cache_free(PGT_CACHE(index_size), table);
  179. }
  180. }
  181. #ifdef CONFIG_SMP
  182. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  183. void *table, int shift)
  184. {
  185. unsigned long pgf = (unsigned long)table;
  186. BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  187. pgf |= shift;
  188. tlb_remove_table(tlb, (void *)pgf);
  189. }
  190. static inline void __tlb_remove_table(void *_table)
  191. {
  192. void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
  193. unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
  194. pgtable_free(table, shift);
  195. }
  196. #else /* !CONFIG_SMP */
  197. static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  198. void *table, int shift)
  199. {
  200. pgtable_free(table, shift);
  201. }
  202. #endif /* CONFIG_SMP */
  203. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  204. unsigned long address)
  205. {
  206. struct page *page = page_address(table);
  207. tlb_flush_pgtable(tlb, address);
  208. pgtable_page_dtor(page);
  209. pgtable_free_tlb(tlb, page, 0);
  210. }
  211. #endif /* CONFIG_PPC_64K_PAGES */
  212. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  213. {
  214. return kmem_cache_alloc(PGT_CACHE(PMD_INDEX_SIZE),
  215. GFP_KERNEL|__GFP_REPEAT);
  216. }
  217. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  218. {
  219. kmem_cache_free(PGT_CACHE(PMD_INDEX_SIZE), pmd);
  220. }
  221. #define __pmd_free_tlb(tlb, pmd, addr) \
  222. pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE)
  223. #ifndef CONFIG_PPC_64K_PAGES
  224. #define __pud_free_tlb(tlb, pud, addr) \
  225. pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
  226. #endif /* CONFIG_PPC_64K_PAGES */
  227. #define check_pgt_cache() do { } while (0)
  228. #endif /* _ASM_POWERPC_PGALLOC_64_H */