pgalloc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
  7. * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_PGALLOC_H
  10. #define _ASM_PGALLOC_H
  11. #include <linux/highmem.h>
  12. #include <linux/mm.h>
  13. #include <linux/sched.h>
  14. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  15. pte_t *pte)
  16. {
  17. set_pmd(pmd, __pmd((unsigned long)pte));
  18. }
  19. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  20. pgtable_t pte)
  21. {
  22. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  23. }
  24. #define pmd_pgtable(pmd) pmd_page(pmd)
  25. /*
  26. * Initialize a new pmd table with invalid pointers.
  27. */
  28. extern void pmd_init(unsigned long page, unsigned long pagetable);
  29. #ifndef __PAGETABLE_PMD_FOLDED
  30. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  31. {
  32. set_pud(pud, __pud((unsigned long)pmd));
  33. }
  34. #endif
  35. /*
  36. * Initialize a new pgd / pmd table with invalid pointers.
  37. */
  38. extern void pgd_init(unsigned long page);
  39. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  40. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  41. {
  42. free_pages((unsigned long)pgd, PGD_ORDER);
  43. }
  44. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  45. unsigned long address)
  46. {
  47. return (pte_t *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, PTE_ORDER);
  48. }
  49. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  50. unsigned long address)
  51. {
  52. struct page *pte;
  53. pte = alloc_pages(GFP_KERNEL, PTE_ORDER);
  54. if (!pte)
  55. return NULL;
  56. clear_highpage(pte);
  57. if (!pgtable_page_ctor(pte)) {
  58. __free_page(pte);
  59. return NULL;
  60. }
  61. return pte;
  62. }
  63. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  64. {
  65. free_pages((unsigned long)pte, PTE_ORDER);
  66. }
  67. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  68. {
  69. pgtable_page_dtor(pte);
  70. __free_pages(pte, PTE_ORDER);
  71. }
  72. #define __pte_free_tlb(tlb,pte,address) \
  73. do { \
  74. pgtable_page_dtor(pte); \
  75. tlb_remove_page((tlb), pte); \
  76. } while (0)
  77. #ifndef __PAGETABLE_PMD_FOLDED
  78. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  79. {
  80. pmd_t *pmd;
  81. pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ORDER);
  82. if (pmd)
  83. pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
  84. return pmd;
  85. }
  86. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  87. {
  88. free_pages((unsigned long)pmd, PMD_ORDER);
  89. }
  90. #define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
  91. #endif
  92. #ifndef __PAGETABLE_PUD_FOLDED
  93. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
  94. {
  95. pud_t *pud;
  96. pud = (pud_t *) __get_free_pages(GFP_KERNEL, PUD_ORDER);
  97. if (pud)
  98. pud_init((unsigned long)pud, (unsigned long)invalid_pmd_table);
  99. return pud;
  100. }
  101. static inline void pud_free(struct mm_struct *mm, pud_t *pud)
  102. {
  103. free_pages((unsigned long)pud, PUD_ORDER);
  104. }
  105. static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
  106. {
  107. set_pgd(pgd, __pgd((unsigned long)pud));
  108. }
  109. #define __pud_free_tlb(tlb, x, addr) pud_free((tlb)->mm, x)
  110. #endif /* __PAGETABLE_PUD_FOLDED */
  111. #define check_pgt_cache() do { } while (0)
  112. extern void pagetable_init(void);
  113. #endif /* _ASM_PGALLOC_H */