pgalloc_64.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef _SPARC64_PGALLOC_H
  2. #define _SPARC64_PGALLOC_H
  3. #include <linux/kernel.h>
  4. #include <linux/sched.h>
  5. #include <linux/mm.h>
  6. #include <linux/slab.h>
  7. #include <asm/spitfire.h>
  8. #include <asm/cpudata.h>
  9. #include <asm/cacheflush.h>
  10. #include <asm/page.h>
  11. /* Page table allocation/freeing. */
  12. extern struct kmem_cache *pgtable_cache;
  13. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  14. {
  15. return kmem_cache_alloc(pgtable_cache, GFP_KERNEL);
  16. }
  17. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  18. {
  19. kmem_cache_free(pgtable_cache, pgd);
  20. }
  21. #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
  22. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  23. {
  24. return kmem_cache_alloc(pgtable_cache,
  25. GFP_KERNEL|__GFP_REPEAT);
  26. }
  27. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  28. {
  29. kmem_cache_free(pgtable_cache, pmd);
  30. }
  31. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  32. unsigned long address)
  33. {
  34. return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  35. }
  36. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  37. unsigned long address)
  38. {
  39. struct page *page;
  40. pte_t *pte;
  41. pte = pte_alloc_one_kernel(mm, address);
  42. if (!pte)
  43. return NULL;
  44. page = virt_to_page(pte);
  45. pgtable_page_ctor(page);
  46. return page;
  47. }
  48. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  49. {
  50. free_page((unsigned long)pte);
  51. }
  52. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  53. {
  54. pgtable_page_dtor(ptepage);
  55. __free_page(ptepage);
  56. }
  57. #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
  58. #define pmd_populate(MM,PMD,PTE_PAGE) \
  59. pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
  60. #define pmd_pgtable(pmd) pmd_page(pmd)
  61. #define check_pgt_cache() do { } while (0)
  62. static inline void pgtable_free(void *table, bool is_page)
  63. {
  64. if (is_page)
  65. free_page((unsigned long)table);
  66. else
  67. kmem_cache_free(pgtable_cache, table);
  68. }
  69. #ifdef CONFIG_SMP
  70. struct mmu_gather;
  71. extern void tlb_remove_table(struct mmu_gather *, void *);
  72. static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, bool is_page)
  73. {
  74. unsigned long pgf = (unsigned long)table;
  75. if (is_page)
  76. pgf |= 0x1UL;
  77. tlb_remove_table(tlb, (void *)pgf);
  78. }
  79. static inline void __tlb_remove_table(void *_table)
  80. {
  81. void *table = (void *)((unsigned long)_table & ~0x1UL);
  82. bool is_page = false;
  83. if ((unsigned long)_table & 0x1UL)
  84. is_page = true;
  85. pgtable_free(table, is_page);
  86. }
  87. #else /* CONFIG_SMP */
  88. static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, bool is_page)
  89. {
  90. pgtable_free(table, is_page);
  91. }
  92. #endif /* !CONFIG_SMP */
  93. static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage,
  94. unsigned long address)
  95. {
  96. pgtable_page_dtor(ptepage);
  97. pgtable_free_tlb(tlb, page_address(ptepage), true);
  98. }
  99. #define __pmd_free_tlb(tlb, pmd, addr) \
  100. pgtable_free_tlb(tlb, pmd, false)
  101. #endif /* _SPARC64_PGALLOC_H */