pgalloc.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #define __HAVE_ARCH_PMD_ALLOC_ONE
  15. #define __HAVE_ARCH_PUD_ALLOC_ONE
  16. #define __HAVE_ARCH_PGD_FREE
  17. #include <asm-generic/pgalloc.h>
  18. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  19. pte_t *pte)
  20. {
  21. set_pmd(pmd, __pmd((unsigned long)pte));
  22. }
  23. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  24. pgtable_t pte)
  25. {
  26. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  27. }
  28. /*
  29. * Initialize a new pmd table with invalid pointers.
  30. */
  31. extern void pmd_init(unsigned long page, unsigned long pagetable);
  32. #ifndef __PAGETABLE_PMD_FOLDED
  33. static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  34. {
  35. set_pud(pud, __pud((unsigned long)pmd));
  36. }
  37. #endif
  38. /*
  39. * Initialize a new pgd / pmd table with invalid pointers.
  40. */
  41. extern void pgd_init(unsigned long page);
  42. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  43. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  44. {
  45. free_pages((unsigned long)pgd, PGD_TABLE_ORDER);
  46. }
  47. #define __pte_free_tlb(tlb,pte,address) \
  48. do { \
  49. pgtable_pte_page_dtor(pte); \
  50. tlb_remove_page((tlb), pte); \
  51. } while (0)
  52. #ifndef __PAGETABLE_PMD_FOLDED
  53. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  54. {
  55. pmd_t *pmd;
  56. struct page *pg;
  57. pg = alloc_pages(GFP_KERNEL_ACCOUNT, PMD_TABLE_ORDER);
  58. if (!pg)
  59. return NULL;
  60. if (!pgtable_pmd_page_ctor(pg)) {
  61. __free_pages(pg, PMD_TABLE_ORDER);
  62. return NULL;
  63. }
  64. pmd = (pmd_t *)page_address(pg);
  65. pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
  66. return pmd;
  67. }
  68. #define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
  69. #endif
  70. #ifndef __PAGETABLE_PUD_FOLDED
  71. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
  72. {
  73. pud_t *pud;
  74. pud = (pud_t *) __get_free_pages(GFP_KERNEL, PUD_TABLE_ORDER);
  75. if (pud)
  76. pud_init((unsigned long)pud, (unsigned long)invalid_pmd_table);
  77. return pud;
  78. }
  79. static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
  80. {
  81. set_p4d(p4d, __p4d((unsigned long)pud));
  82. }
  83. #define __pud_free_tlb(tlb, x, addr) pud_free((tlb)->mm, x)
  84. #endif /* __PAGETABLE_PUD_FOLDED */
  85. extern void pagetable_init(void);
  86. #endif /* _ASM_PGALLOC_H */