pgalloc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  14. pte_t *pte)
  15. {
  16. set_pmd(pmd, __pmd((unsigned long)pte));
  17. }
  18. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  19. struct page *pte)
  20. {
  21. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  22. }
  23. /*
  24. * Initialize a new pmd table with invalid pointers.
  25. */
  26. extern void pmd_init(unsigned long page, unsigned long pagetable);
  27. #ifdef CONFIG_64BIT
  28. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  29. {
  30. set_pud(pud, __pud((unsigned long)pmd));
  31. }
  32. #endif
  33. /*
  34. * Initialize a new pgd / pmd table with invalid pointers.
  35. */
  36. extern void pgd_init(unsigned long page);
  37. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  38. {
  39. pgd_t *ret, *init;
  40. ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
  41. if (ret) {
  42. init = pgd_offset(&init_mm, 0);
  43. pgd_init((unsigned long)ret);
  44. memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  45. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  46. }
  47. return ret;
  48. }
  49. static inline void pgd_free(pgd_t *pgd)
  50. {
  51. free_pages((unsigned long)pgd, PGD_ORDER);
  52. }
  53. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  54. unsigned long address)
  55. {
  56. pte_t *pte;
  57. pte = (pte_t *) __get_free_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, PTE_ORDER);
  58. return pte;
  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 | __GFP_REPEAT, PTE_ORDER);
  65. if (pte)
  66. clear_highpage(pte);
  67. return pte;
  68. }
  69. static inline void pte_free_kernel(pte_t *pte)
  70. {
  71. free_pages((unsigned long)pte, PTE_ORDER);
  72. }
  73. static inline void pte_free(struct page *pte)
  74. {
  75. __free_pages(pte, PTE_ORDER);
  76. }
  77. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  78. #ifdef CONFIG_32BIT
  79. /*
  80. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  81. * inside the pgd, so has no extra memory associated with it.
  82. */
  83. #define pmd_free(x) do { } while (0)
  84. #define __pmd_free_tlb(tlb,x) do { } while (0)
  85. #endif
  86. #ifdef CONFIG_64BIT
  87. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  88. {
  89. pmd_t *pmd;
  90. pmd = (pmd_t *) __get_free_pages(GFP_KERNEL|__GFP_REPEAT, PMD_ORDER);
  91. if (pmd)
  92. pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
  93. return pmd;
  94. }
  95. static inline void pmd_free(pmd_t *pmd)
  96. {
  97. free_pages((unsigned long)pmd, PMD_ORDER);
  98. }
  99. #define __pmd_free_tlb(tlb,x) pmd_free(x)
  100. #endif
  101. #define check_pgt_cache() do { } while (0)
  102. #endif /* _ASM_PGALLOC_H */