pgalloc.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_PGALLOC_H
  3. #define __ASM_SH_PGALLOC_H
  4. #include <linux/quicklist.h>
  5. #include <asm/page.h>
  6. #define QUICK_PT 0 /* Other page table pages that are zero on free */
  7. extern pgd_t *pgd_alloc(struct mm_struct *);
  8. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  9. #if PAGETABLE_LEVELS > 2
  10. extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
  11. extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
  12. extern void pmd_free(struct mm_struct *mm, pmd_t *pmd);
  13. #endif
  14. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  15. pte_t *pte)
  16. {
  17. set_pmd(pmd, __pmd((unsigned long)pte));
  18. }
  19. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  20. pgtable_t pte)
  21. {
  22. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  23. }
  24. #define pmd_pgtable(pmd) pmd_page(pmd)
  25. /*
  26. * Allocate and free page tables.
  27. */
  28. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  29. unsigned long address)
  30. {
  31. return quicklist_alloc(QUICK_PT, GFP_KERNEL, NULL);
  32. }
  33. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  34. unsigned long address)
  35. {
  36. struct page *page;
  37. void *pg;
  38. pg = quicklist_alloc(QUICK_PT, GFP_KERNEL, NULL);
  39. if (!pg)
  40. return NULL;
  41. page = virt_to_page(pg);
  42. if (!pgtable_page_ctor(page)) {
  43. quicklist_free(QUICK_PT, NULL, pg);
  44. return NULL;
  45. }
  46. return page;
  47. }
  48. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  49. {
  50. quicklist_free(QUICK_PT, NULL, pte);
  51. }
  52. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  53. {
  54. pgtable_page_dtor(pte);
  55. quicklist_free_page(QUICK_PT, NULL, pte);
  56. }
  57. #define __pte_free_tlb(tlb,pte,addr) \
  58. do { \
  59. pgtable_page_dtor(pte); \
  60. tlb_remove_page((tlb), (pte)); \
  61. } while (0)
  62. static inline void check_pgt_cache(void)
  63. {
  64. quicklist_trim(QUICK_PT, NULL, 25, 16);
  65. }
  66. #endif /* __ASM_SH_PGALLOC_H */