pgalloc-64.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /*
  13. * Functions that deal with pagetables that could be at any level of
  14. * the table need to be passed an "index_size" so they know how to
  15. * handle allocation. For PTE pages (which are linked to a struct
  16. * page for now, and drawn from the main get_free_pages() pool), the
  17. * allocation size will be (2^index_size * sizeof(pointer)) and
  18. * allocations are drawn from the kmem_cache in PGT_CACHE(index_size).
  19. *
  20. * The maximum index size needs to be big enough to allow any
  21. * pagetable sizes we need, but small enough to fit in the low bits of
  22. * any page table pointer. In other words all pagetables, even tiny
  23. * ones, must be aligned to allow at least enough low 0 bits to
  24. * contain this value. This value is also used as a mask, so it must
  25. * be one less than a power of two.
  26. */
  27. #define MAX_PGTABLE_INDEX_SIZE 0xf
  28. extern struct kmem_cache *pgtable_cache[];
  29. #define PGT_CACHE(shift) (pgtable_cache[(shift)-1])
  30. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  31. {
  32. return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL);
  33. }
  34. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  35. {
  36. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  37. }
  38. #ifndef CONFIG_PPC_64K_PAGES
  39. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  40. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  41. {
  42. return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE),
  43. GFP_KERNEL|__GFP_REPEAT);
  44. }
  45. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  46. {
  47. kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud);
  48. }
  49. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  50. {
  51. pud_set(pud, (unsigned long)pmd);
  52. }
  53. #define pmd_populate(mm, pmd, pte_page) \
  54. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  55. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  56. #define pmd_pgtable(pmd) pmd_page(pmd)
  57. #else /* CONFIG_PPC_64K_PAGES */
  58. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  59. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  60. pte_t *pte)
  61. {
  62. pmd_set(pmd, (unsigned long)pte);
  63. }
  64. #define pmd_populate(mm, pmd, pte_page) \
  65. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  66. #define pmd_pgtable(pmd) pmd_page(pmd)
  67. #endif /* CONFIG_PPC_64K_PAGES */
  68. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  69. {
  70. return kmem_cache_alloc(PGT_CACHE(PMD_INDEX_SIZE),
  71. GFP_KERNEL|__GFP_REPEAT);
  72. }
  73. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  74. {
  75. kmem_cache_free(PGT_CACHE(PMD_INDEX_SIZE), pmd);
  76. }
  77. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  78. unsigned long address)
  79. {
  80. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  81. }
  82. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  83. unsigned long address)
  84. {
  85. struct page *page;
  86. pte_t *pte;
  87. pte = pte_alloc_one_kernel(mm, address);
  88. if (!pte)
  89. return NULL;
  90. page = virt_to_page(pte);
  91. pgtable_page_ctor(page);
  92. return page;
  93. }
  94. static inline void pgtable_free(void *table, unsigned index_size)
  95. {
  96. if (!index_size)
  97. free_page((unsigned long)table);
  98. else {
  99. BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  100. kmem_cache_free(PGT_CACHE(index_size), table);
  101. }
  102. }
  103. #define __pmd_free_tlb(tlb, pmd, addr) \
  104. pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE)
  105. #ifndef CONFIG_PPC_64K_PAGES
  106. #define __pud_free_tlb(tlb, pud, addr) \
  107. pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
  108. #endif /* CONFIG_PPC_64K_PAGES */
  109. #define check_pgt_cache() do { } while (0)
  110. #endif /* _ASM_POWERPC_PGALLOC_64_H */