pgalloc-64.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #ifndef CONFIG_PPC_SUBPAGE_PROT
  29. static inline void subpage_prot_free(pgd_t *pgd) {}
  30. #endif
  31. extern struct kmem_cache *pgtable_cache[];
  32. #define PGT_CACHE(shift) (pgtable_cache[(shift)-1])
  33. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  34. {
  35. return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL);
  36. }
  37. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  38. {
  39. subpage_prot_free(pgd);
  40. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  41. }
  42. #ifndef CONFIG_PPC_64K_PAGES
  43. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  44. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  45. {
  46. return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE),
  47. GFP_KERNEL|__GFP_REPEAT);
  48. }
  49. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  50. {
  51. kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud);
  52. }
  53. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  54. {
  55. pud_set(pud, (unsigned long)pmd);
  56. }
  57. #define pmd_populate(mm, pmd, pte_page) \
  58. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  59. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  60. #define pmd_pgtable(pmd) pmd_page(pmd)
  61. #else /* CONFIG_PPC_64K_PAGES */
  62. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  63. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  64. pte_t *pte)
  65. {
  66. pmd_set(pmd, (unsigned long)pte);
  67. }
  68. #define pmd_populate(mm, pmd, pte_page) \
  69. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  70. #define pmd_pgtable(pmd) pmd_page(pmd)
  71. #endif /* CONFIG_PPC_64K_PAGES */
  72. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  73. {
  74. return kmem_cache_alloc(PGT_CACHE(PMD_INDEX_SIZE),
  75. GFP_KERNEL|__GFP_REPEAT);
  76. }
  77. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  78. {
  79. kmem_cache_free(PGT_CACHE(PMD_INDEX_SIZE), pmd);
  80. }
  81. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  82. unsigned long address)
  83. {
  84. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  85. }
  86. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  87. unsigned long address)
  88. {
  89. struct page *page;
  90. pte_t *pte;
  91. pte = pte_alloc_one_kernel(mm, address);
  92. if (!pte)
  93. return NULL;
  94. page = virt_to_page(pte);
  95. pgtable_page_ctor(page);
  96. return page;
  97. }
  98. static inline void pgtable_free(void *table, unsigned index_size)
  99. {
  100. if (!index_size)
  101. free_page((unsigned long)table);
  102. else {
  103. BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  104. kmem_cache_free(PGT_CACHE(index_size), table);
  105. }
  106. }
  107. #define __pmd_free_tlb(tlb, pmd, addr) \
  108. pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE)
  109. #ifndef CONFIG_PPC_64K_PAGES
  110. #define __pud_free_tlb(tlb, pud, addr) \
  111. pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
  112. #endif /* CONFIG_PPC_64K_PAGES */
  113. #define check_pgt_cache() do { } while (0)
  114. #endif /* _ASM_POWERPC_PGALLOC_64_H */