pgalloc_32.h 2.3 KB

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