pgalloc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  40. {
  41. pgd_t *ret, *init;
  42. ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
  43. if (ret) {
  44. init = pgd_offset(&init_mm, 0UL);
  45. pgd_init((unsigned long)ret);
  46. memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  47. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  48. }
  49. return ret;
  50. }
  51. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  52. {
  53. free_pages((unsigned long)pgd, PGD_ORDER);
  54. }
  55. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  56. unsigned long address)
  57. {
  58. return (pte_t *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, PTE_ORDER);
  59. }
  60. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  61. unsigned long address)
  62. {
  63. struct page *pte;
  64. pte = alloc_pages(GFP_KERNEL, PTE_ORDER);
  65. if (!pte)
  66. return NULL;
  67. clear_highpage(pte);
  68. if (!pgtable_page_ctor(pte)) {
  69. __free_page(pte);
  70. return NULL;
  71. }
  72. return pte;
  73. }
  74. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  75. {
  76. free_pages((unsigned long)pte, PTE_ORDER);
  77. }
  78. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  79. {
  80. pgtable_page_dtor(pte);
  81. __free_pages(pte, PTE_ORDER);
  82. }
  83. #define __pte_free_tlb(tlb,pte,address) \
  84. do { \
  85. pgtable_page_dtor(pte); \
  86. tlb_remove_page((tlb), pte); \
  87. } while (0)
  88. #ifndef __PAGETABLE_PMD_FOLDED
  89. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  90. {
  91. pmd_t *pmd;
  92. pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ORDER);
  93. if (pmd)
  94. pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
  95. return pmd;
  96. }
  97. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  98. {
  99. free_pages((unsigned long)pmd, PMD_ORDER);
  100. }
  101. #define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
  102. #endif
  103. #define check_pgt_cache() do { } while (0)
  104. extern void pagetable_init(void);
  105. #endif /* _ASM_PGALLOC_H */