pgalloc-64.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef CONFIG_PPC_SUBPAGE_PROT
  13. static inline void subpage_prot_free(pgd_t *pgd) {}
  14. #endif
  15. extern struct kmem_cache *pgtable_cache[];
  16. #define PGD_CACHE_NUM 0
  17. #define PUD_CACHE_NUM 1
  18. #define PMD_CACHE_NUM 1
  19. #define HUGEPTE_CACHE_NUM 2
  20. #define PTE_NONCACHE_NUM 7 /* from GFP rather than kmem_cache */
  21. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  22. {
  23. return kmem_cache_alloc(pgtable_cache[PGD_CACHE_NUM], GFP_KERNEL);
  24. }
  25. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  26. {
  27. subpage_prot_free(pgd);
  28. kmem_cache_free(pgtable_cache[PGD_CACHE_NUM], pgd);
  29. }
  30. #ifndef CONFIG_PPC_64K_PAGES
  31. #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
  32. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  33. {
  34. return kmem_cache_alloc(pgtable_cache[PUD_CACHE_NUM],
  35. GFP_KERNEL|__GFP_REPEAT);
  36. }
  37. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  38. {
  39. kmem_cache_free(pgtable_cache[PUD_CACHE_NUM], pud);
  40. }
  41. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  42. {
  43. pud_set(pud, (unsigned long)pmd);
  44. }
  45. #define pmd_populate(mm, pmd, pte_page) \
  46. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  47. #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
  48. #define pmd_pgtable(pmd) pmd_page(pmd)
  49. #else /* CONFIG_PPC_64K_PAGES */
  50. #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
  51. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  52. pte_t *pte)
  53. {
  54. pmd_set(pmd, (unsigned long)pte);
  55. }
  56. #define pmd_populate(mm, pmd, pte_page) \
  57. pmd_populate_kernel(mm, pmd, page_address(pte_page))
  58. #define pmd_pgtable(pmd) pmd_page(pmd)
  59. #endif /* CONFIG_PPC_64K_PAGES */
  60. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  61. {
  62. return kmem_cache_alloc(pgtable_cache[PMD_CACHE_NUM],
  63. GFP_KERNEL|__GFP_REPEAT);
  64. }
  65. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  66. {
  67. kmem_cache_free(pgtable_cache[PMD_CACHE_NUM], pmd);
  68. }
  69. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  70. unsigned long address)
  71. {
  72. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  73. }
  74. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  75. unsigned long address)
  76. {
  77. struct page *page;
  78. pte_t *pte;
  79. pte = pte_alloc_one_kernel(mm, address);
  80. if (!pte)
  81. return NULL;
  82. page = virt_to_page(pte);
  83. pgtable_page_ctor(page);
  84. return page;
  85. }
  86. static inline void pgtable_free(pgtable_free_t pgf)
  87. {
  88. void *p = (void *)(pgf.val & ~PGF_CACHENUM_MASK);
  89. int cachenum = pgf.val & PGF_CACHENUM_MASK;
  90. if (cachenum == PTE_NONCACHE_NUM)
  91. free_page((unsigned long)p);
  92. else
  93. kmem_cache_free(pgtable_cache[cachenum], p);
  94. }
  95. #define __pmd_free_tlb(tlb, pmd) \
  96. pgtable_free_tlb(tlb, pgtable_free_cache(pmd, \
  97. PMD_CACHE_NUM, PMD_TABLE_SIZE-1))
  98. #ifndef CONFIG_PPC_64K_PAGES
  99. #define __pud_free_tlb(tlb, pud) \
  100. pgtable_free_tlb(tlb, pgtable_free_cache(pud, \
  101. PUD_CACHE_NUM, PUD_TABLE_SIZE-1))
  102. #endif /* CONFIG_PPC_64K_PAGES */
  103. #define check_pgt_cache() do { } while (0)
  104. #endif /* _ASM_POWERPC_PGALLOC_64_H */