pgalloc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_IA64_PGALLOC_H
  3. #define _ASM_IA64_PGALLOC_H
  4. /*
  5. * This file contains the functions and defines necessary to allocate
  6. * page tables.
  7. *
  8. * This hopefully works with any (fixed) ia-64 page-size, as defined
  9. * in <asm/page.h> (currently 8192).
  10. *
  11. * Copyright (C) 1998-2001 Hewlett-Packard Co
  12. * David Mosberger-Tang <davidm@hpl.hp.com>
  13. * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
  14. */
  15. #include <linux/compiler.h>
  16. #include <linux/mm.h>
  17. #include <linux/page-flags.h>
  18. #include <linux/threads.h>
  19. #include <linux/quicklist.h>
  20. #include <asm/mmu_context.h>
  21. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  22. {
  23. return quicklist_alloc(0, GFP_KERNEL, NULL);
  24. }
  25. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  26. {
  27. quicklist_free(0, NULL, pgd);
  28. }
  29. #if CONFIG_PGTABLE_LEVELS == 4
  30. static inline void
  31. pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
  32. {
  33. pgd_val(*pgd_entry) = __pa(pud);
  34. }
  35. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  36. {
  37. return quicklist_alloc(0, GFP_KERNEL, NULL);
  38. }
  39. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  40. {
  41. quicklist_free(0, NULL, pud);
  42. }
  43. #define __pud_free_tlb(tlb, pud, address) pud_free((tlb)->mm, pud)
  44. #endif /* CONFIG_PGTABLE_LEVELS == 4 */
  45. static inline void
  46. pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
  47. {
  48. pud_val(*pud_entry) = __pa(pmd);
  49. }
  50. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  51. {
  52. return quicklist_alloc(0, GFP_KERNEL, NULL);
  53. }
  54. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  55. {
  56. quicklist_free(0, NULL, pmd);
  57. }
  58. #define __pmd_free_tlb(tlb, pmd, address) pmd_free((tlb)->mm, pmd)
  59. static inline void
  60. pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
  61. {
  62. pmd_val(*pmd_entry) = page_to_phys(pte);
  63. }
  64. #define pmd_pgtable(pmd) pmd_page(pmd)
  65. static inline void
  66. pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
  67. {
  68. pmd_val(*pmd_entry) = __pa(pte);
  69. }
  70. static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  71. {
  72. struct page *page;
  73. void *pg;
  74. pg = quicklist_alloc(0, GFP_KERNEL, NULL);
  75. if (!pg)
  76. return NULL;
  77. page = virt_to_page(pg);
  78. if (!pgtable_page_ctor(page)) {
  79. quicklist_free(0, NULL, pg);
  80. return NULL;
  81. }
  82. return page;
  83. }
  84. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  85. unsigned long addr)
  86. {
  87. return quicklist_alloc(0, GFP_KERNEL, NULL);
  88. }
  89. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  90. {
  91. pgtable_page_dtor(pte);
  92. quicklist_free_page(0, NULL, pte);
  93. }
  94. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  95. {
  96. quicklist_free(0, NULL, pte);
  97. }
  98. static inline void check_pgt_cache(void)
  99. {
  100. quicklist_trim(0, NULL, 25, 16);
  101. }
  102. #define __pte_free_tlb(tlb, pte, address) pte_free((tlb)->mm, pte)
  103. #endif /* _ASM_IA64_PGALLOC_H */