pgalloc.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Based on arch/arm/include/asm/pgalloc.h
  4. *
  5. * Copyright (C) 2000-2001 Russell King
  6. * Copyright (C) 2012 ARM Ltd.
  7. */
  8. #ifndef __ASM_PGALLOC_H
  9. #define __ASM_PGALLOC_H
  10. #include <asm/pgtable-hwdef.h>
  11. #include <asm/processor.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/tlbflush.h>
  14. #define __HAVE_ARCH_PGD_FREE
  15. #include <asm-generic/pgalloc.h>
  16. #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
  17. #if CONFIG_PGTABLE_LEVELS > 2
  18. static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
  19. {
  20. set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot));
  21. }
  22. static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
  23. {
  24. pudval_t pudval = PUD_TYPE_TABLE;
  25. pudval |= (mm == &init_mm) ? PUD_TABLE_UXN : PUD_TABLE_PXN;
  26. __pud_populate(pudp, __pa(pmdp), pudval);
  27. }
  28. #else
  29. static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot)
  30. {
  31. BUILD_BUG();
  32. }
  33. #endif /* CONFIG_PGTABLE_LEVELS > 2 */
  34. #if CONFIG_PGTABLE_LEVELS > 3
  35. static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot)
  36. {
  37. set_p4d(p4dp, __p4d(__phys_to_p4d_val(pudp) | prot));
  38. }
  39. static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp)
  40. {
  41. p4dval_t p4dval = P4D_TYPE_TABLE;
  42. p4dval |= (mm == &init_mm) ? P4D_TABLE_UXN : P4D_TABLE_PXN;
  43. __p4d_populate(p4dp, __pa(pudp), p4dval);
  44. }
  45. #else
  46. static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot)
  47. {
  48. BUILD_BUG();
  49. }
  50. #endif /* CONFIG_PGTABLE_LEVELS > 3 */
  51. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  52. extern void pgd_free(struct mm_struct *mm, pgd_t *pgdp);
  53. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t ptep,
  54. pmdval_t prot)
  55. {
  56. set_pmd(pmdp, __pmd(__phys_to_pmd_val(ptep) | prot));
  57. }
  58. /*
  59. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  60. * of the mm address space.
  61. */
  62. static inline void
  63. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  64. {
  65. VM_BUG_ON(mm && mm != &init_mm);
  66. __pmd_populate(pmdp, __pa(ptep), PMD_TYPE_TABLE | PMD_TABLE_UXN);
  67. }
  68. static inline void
  69. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  70. {
  71. VM_BUG_ON(mm == &init_mm);
  72. __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN);
  73. }
  74. #endif