pgalloc_32.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef _I386_PGALLOC_H
  2. #define _I386_PGALLOC_H
  3. #include <linux/threads.h>
  4. #include <linux/mm.h> /* for struct page */
  5. #include <asm/tlb.h>
  6. #include <asm-generic/tlb.h>
  7. #ifdef CONFIG_PARAVIRT
  8. #include <asm/paravirt.h>
  9. #else
  10. #define paravirt_alloc_pt(mm, pfn) do { } while (0)
  11. #define paravirt_alloc_pd(mm, pfn) do { } while (0)
  12. #define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) do { } while (0)
  13. #define paravirt_release_pt(pfn) do { } while (0)
  14. #define paravirt_release_pd(pfn) do { } while (0)
  15. #endif
  16. static inline void pmd_populate_kernel(struct mm_struct *mm,
  17. pmd_t *pmd, pte_t *pte)
  18. {
  19. paravirt_alloc_pt(mm, __pa(pte) >> PAGE_SHIFT);
  20. set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
  21. }
  22. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
  23. {
  24. unsigned long pfn = page_to_pfn(pte);
  25. paravirt_alloc_pt(mm, pfn);
  26. set_pmd(pmd, __pmd(((pteval_t)pfn << PAGE_SHIFT) | _PAGE_TABLE));
  27. }
  28. /*
  29. * Allocate and free page tables.
  30. */
  31. extern pgd_t *pgd_alloc(struct mm_struct *);
  32. extern void pgd_free(pgd_t *pgd);
  33. extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
  34. extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
  35. static inline void pte_free_kernel(pte_t *pte)
  36. {
  37. free_page((unsigned long)pte);
  38. }
  39. static inline void pte_free(struct page *pte)
  40. {
  41. __free_page(pte);
  42. }
  43. static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
  44. {
  45. paravirt_release_pt(page_to_pfn(pte));
  46. tlb_remove_page(tlb, pte);
  47. }
  48. #ifdef CONFIG_X86_PAE
  49. /*
  50. * In the PAE case we free the pmds as part of the pgd.
  51. */
  52. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  53. {
  54. return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
  55. }
  56. static inline void pmd_free(pmd_t *pmd)
  57. {
  58. BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
  59. free_page((unsigned long)pmd);
  60. }
  61. static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
  62. {
  63. paravirt_release_pd(__pa(pmd) >> PAGE_SHIFT);
  64. tlb_remove_page(tlb, virt_to_page(pmd));
  65. }
  66. static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
  67. {
  68. paravirt_alloc_pd(mm, __pa(pmd) >> PAGE_SHIFT);
  69. /* Note: almost everything apart from _PAGE_PRESENT is
  70. reserved at the pmd (PDPT) level. */
  71. set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
  72. /*
  73. * Pentium-II erratum A13: in PAE mode we explicitly have to flush
  74. * the TLB via cr3 if the top-level pgd is changed...
  75. */
  76. if (mm == current->active_mm)
  77. write_cr3(read_cr3());
  78. }
  79. #endif /* CONFIG_X86_PAE */
  80. #endif /* _I386_PGALLOC_H */