pgalloc.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * include/asm-xtensa/pgalloc.h
  4. *
  5. * Copyright (C) 2001-2007 Tensilica Inc.
  6. */
  7. #ifndef _XTENSA_PGALLOC_H
  8. #define _XTENSA_PGALLOC_H
  9. #ifdef CONFIG_MMU
  10. #include <linux/highmem.h>
  11. #include <linux/slab.h>
  12. #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
  13. #define __HAVE_ARCH_PTE_ALLOC_ONE
  14. #include <asm-generic/pgalloc.h>
  15. /*
  16. * Allocating and freeing a pmd is trivial: the 1-entry pmd is
  17. * inside the pgd, so has no extra memory associated with it.
  18. */
  19. #define pmd_populate_kernel(mm, pmdp, ptep) \
  20. (pmd_val(*(pmdp)) = ((unsigned long)ptep))
  21. #define pmd_populate(mm, pmdp, page) \
  22. (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page)))
  23. static inline pgd_t*
  24. pgd_alloc(struct mm_struct *mm)
  25. {
  26. return (pgd_t*) __get_free_page(GFP_KERNEL | __GFP_ZERO);
  27. }
  28. static inline void ptes_clear(pte_t *ptep)
  29. {
  30. int i;
  31. for (i = 0; i < PTRS_PER_PTE; i++)
  32. pte_clear(NULL, 0, ptep + i);
  33. }
  34. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
  35. {
  36. pte_t *ptep;
  37. ptep = (pte_t *)__pte_alloc_one_kernel(mm);
  38. if (!ptep)
  39. return NULL;
  40. ptes_clear(ptep);
  41. return ptep;
  42. }
  43. static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
  44. {
  45. struct page *page;
  46. page = __pte_alloc_one(mm, GFP_PGTABLE_USER);
  47. if (!page)
  48. return NULL;
  49. ptes_clear(page_address(page));
  50. return page;
  51. }
  52. #endif /* CONFIG_MMU */
  53. #endif /* _XTENSA_PGALLOC_H */