pgalloc.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. struct page *pte)
  14. {
  15. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  16. }
  17. static inline void pgd_ctor(void *x)
  18. {
  19. pgd_t *pgd = x;
  20. memcpy(pgd + USER_PTRS_PER_PGD,
  21. swapper_pg_dir + USER_PTRS_PER_PGD,
  22. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  23. }
  24. /*
  25. * Allocate and free page tables.
  26. */
  27. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  28. {
  29. return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
  30. }
  31. static inline void pgd_free(pgd_t *pgd)
  32. {
  33. quicklist_free(QUICK_PGD, NULL, pgd);
  34. }
  35. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  36. unsigned long address)
  37. {
  38. return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
  39. }
  40. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  41. unsigned long address)
  42. {
  43. void *pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
  44. return pg ? virt_to_page(pg) : NULL;
  45. }
  46. static inline void pte_free_kernel(pte_t *pte)
  47. {
  48. quicklist_free(QUICK_PT, NULL, pte);
  49. }
  50. static inline void pte_free(struct page *pte)
  51. {
  52. quicklist_free_page(QUICK_PT, NULL, pte);
  53. }
  54. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  55. /*
  56. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  57. * inside the pgd, so has no extra memory associated with it.
  58. */
  59. #define pmd_free(x) do { } while (0)
  60. #define __pmd_free_tlb(tlb,x) do { } while (0)
  61. static inline void check_pgt_cache(void)
  62. {
  63. quicklist_trim(QUICK_PGD, NULL, 25, 16);
  64. quicklist_trim(QUICK_PT, NULL, 25, 16);
  65. }
  66. #endif /* __ASM_SH_PGALLOC_H */