pgalloc.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef _ASM_SCORE_PGALLOC_H
  2. #define _ASM_SCORE_PGALLOC_H
  3. #include <linux/mm.h>
  4. #include <linux/highmem.h>
  5. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  6. pte_t *pte)
  7. {
  8. set_pmd(pmd, __pmd((unsigned long)pte));
  9. }
  10. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  11. pgtable_t pte)
  12. {
  13. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  14. }
  15. #define pmd_pgtable(pmd) pmd_page(pmd)
  16. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  17. {
  18. pgd_t *ret, *init;
  19. ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
  20. if (ret) {
  21. init = pgd_offset(&init_mm, 0UL);
  22. pgd_init((unsigned long)ret);
  23. memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
  24. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  25. }
  26. return ret;
  27. }
  28. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  29. {
  30. free_pages((unsigned long)pgd, PGD_ORDER);
  31. }
  32. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  33. unsigned long address)
  34. {
  35. pte_t *pte;
  36. pte = (pte_t *) __get_free_pages(GFP_KERNEL|__GFP_ZERO, PTE_ORDER);
  37. return pte;
  38. }
  39. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  40. unsigned long address)
  41. {
  42. struct page *pte;
  43. pte = alloc_pages(GFP_KERNEL, PTE_ORDER);
  44. if (!pte)
  45. return NULL;
  46. clear_highpage(pte);
  47. if (!pgtable_page_ctor(pte)) {
  48. __free_page(pte);
  49. return NULL;
  50. }
  51. return pte;
  52. }
  53. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  54. {
  55. free_pages((unsigned long)pte, PTE_ORDER);
  56. }
  57. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  58. {
  59. pgtable_page_dtor(pte);
  60. __free_pages(pte, PTE_ORDER);
  61. }
  62. #define __pte_free_tlb(tlb, pte, buf) \
  63. do { \
  64. pgtable_page_dtor(pte); \
  65. tlb_remove_page((tlb), pte); \
  66. } while (0)
  67. #define check_pgt_cache() do {} while (0)
  68. #endif /* _ASM_SCORE_PGALLOC_H */