pgalloc.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef _X86_64_PGALLOC_H
  2. #define _X86_64_PGALLOC_H
  3. #include <asm/fixmap.h>
  4. #include <asm/pda.h>
  5. #include <linux/threads.h>
  6. #include <linux/mm.h>
  7. #define pmd_populate_kernel(mm, pmd, pte) \
  8. set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
  9. #define pud_populate(mm, pud, pmd) \
  10. set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)))
  11. #define pgd_populate(mm, pgd, pud) \
  12. set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
  13. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
  14. {
  15. set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
  16. }
  17. extern __inline__ pmd_t *get_pmd(void)
  18. {
  19. return (pmd_t *)get_zeroed_page(GFP_KERNEL);
  20. }
  21. extern __inline__ void pmd_free(pmd_t *pmd)
  22. {
  23. BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
  24. free_page((unsigned long)pmd);
  25. }
  26. static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
  27. {
  28. return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  29. }
  30. static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
  31. {
  32. return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  33. }
  34. static inline void pud_free (pud_t *pud)
  35. {
  36. BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
  37. free_page((unsigned long)pud);
  38. }
  39. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  40. {
  41. unsigned boundary;
  42. pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
  43. if (!pgd)
  44. return NULL;
  45. /*
  46. * Copy kernel pointers in from init.
  47. * Could keep a freelist or slab cache of those because the kernel
  48. * part never changes.
  49. */
  50. boundary = pgd_index(__PAGE_OFFSET);
  51. memset(pgd, 0, boundary * sizeof(pgd_t));
  52. memcpy(pgd + boundary,
  53. init_level4_pgt + boundary,
  54. (PTRS_PER_PGD - boundary) * sizeof(pgd_t));
  55. return pgd;
  56. }
  57. static inline void pgd_free(pgd_t *pgd)
  58. {
  59. BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
  60. free_page((unsigned long)pgd);
  61. }
  62. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  63. {
  64. return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  65. }
  66. static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
  67. {
  68. void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  69. if (!p)
  70. return NULL;
  71. return virt_to_page(p);
  72. }
  73. /* Should really implement gc for free page table pages. This could be
  74. done with a reference count in struct page. */
  75. extern __inline__ void pte_free_kernel(pte_t *pte)
  76. {
  77. BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
  78. free_page((unsigned long)pte);
  79. }
  80. extern inline void pte_free(struct page *pte)
  81. {
  82. __free_page(pte);
  83. }
  84. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  85. #define __pmd_free_tlb(tlb,x) tlb_remove_page((tlb),virt_to_page(x))
  86. #define __pud_free_tlb(tlb,x) tlb_remove_page((tlb),virt_to_page(x))
  87. #endif /* _X86_64_PGALLOC_H */