pgalloc_64.h 3.1 KB

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