pgalloc.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef __ASM_SH_PGALLOC_H
  2. #define __ASM_SH_PGALLOC_H
  3. #include <linux/quicklist.h>
  4. #include <asm/page.h>
  5. #define QUICK_PGD 0 /* We preserve special mappings over free */
  6. #define QUICK_PT 1 /* Other page table pages that are zero on free */
  7. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  8. pte_t *pte)
  9. {
  10. set_pmd(pmd, __pmd((unsigned long)pte));
  11. }
  12. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  13. pgtable_t pte)
  14. {
  15. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  16. }
  17. #define pmd_pgtable(pmd) pmd_page(pmd)
  18. static inline void pgd_ctor(void *x)
  19. {
  20. pgd_t *pgd = x;
  21. memcpy(pgd + USER_PTRS_PER_PGD,
  22. swapper_pg_dir + USER_PTRS_PER_PGD,
  23. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  24. }
  25. /*
  26. * Allocate and free page tables.
  27. */
  28. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  29. {
  30. return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
  31. }
  32. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  33. {
  34. quicklist_free(QUICK_PGD, NULL, pgd);
  35. }
  36. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  37. unsigned long address)
  38. {
  39. return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
  40. }
  41. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  42. unsigned long address)
  43. {
  44. struct page *page;
  45. void *pg;
  46. pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
  47. if (!pg)
  48. return NULL;
  49. page = virt_to_page(pg);
  50. pgtable_page_ctor(page);
  51. return page;
  52. }
  53. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  54. {
  55. quicklist_free(QUICK_PT, NULL, pte);
  56. }
  57. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  58. {
  59. pgtable_page_dtor(pte);
  60. quicklist_free_page(QUICK_PT, NULL, pte);
  61. }
  62. #define __pte_free_tlb(tlb,pte) \
  63. do { \
  64. pgtable_page_dtor(pte); \
  65. tlb_remove_page((tlb), (pte)); \
  66. } while (0)
  67. /*
  68. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  69. * inside the pgd, so has no extra memory associated with it.
  70. */
  71. #define pmd_free(mm, x) do { } while (0)
  72. #define __pmd_free_tlb(tlb,x) do { } while (0)
  73. static inline void check_pgt_cache(void)
  74. {
  75. quicklist_trim(QUICK_PGD, NULL, 25, 16);
  76. quicklist_trim(QUICK_PT, NULL, 25, 16);
  77. }
  78. #endif /* __ASM_SH_PGALLOC_H */