pgalloc.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #ifndef _ASMNDS32_PGALLOC_H
  4. #define _ASMNDS32_PGALLOC_H
  5. #include <asm/processor.h>
  6. #include <asm/cacheflush.h>
  7. #include <asm/tlbflush.h>
  8. #include <asm/proc-fns.h>
  9. /*
  10. * Since we have only two-level page tables, these are trivial
  11. */
  12. #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
  13. #define pmd_free(mm, pmd) do { } while (0)
  14. #define pgd_populate(mm, pmd, pte) BUG()
  15. #define pmd_pgtable(pmd) pmd_page(pmd)
  16. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  17. extern void pgd_free(struct mm_struct *mm, pgd_t * pgd);
  18. #define check_pgt_cache() do { } while (0)
  19. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  20. unsigned long addr)
  21. {
  22. pte_t *pte;
  23. pte =
  24. (pte_t *) __get_free_page(GFP_KERNEL | __GFP_RETRY_MAYFAIL |
  25. __GFP_ZERO);
  26. return pte;
  27. }
  28. static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  29. {
  30. pgtable_t pte;
  31. pte = alloc_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_ZERO, 0);
  32. if (pte)
  33. cpu_dcache_wb_page((unsigned long)page_address(pte));
  34. return pte;
  35. }
  36. /*
  37. * Free one PTE table.
  38. */
  39. static inline void pte_free_kernel(struct mm_struct *mm, pte_t * pte)
  40. {
  41. if (pte) {
  42. free_page((unsigned long)pte);
  43. }
  44. }
  45. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  46. {
  47. __free_page(pte);
  48. }
  49. /*
  50. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  51. * of the mm address space.
  52. *
  53. * Ensure that we always set both PMD entries.
  54. */
  55. static inline void
  56. pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep)
  57. {
  58. unsigned long pte_ptr = (unsigned long)ptep;
  59. unsigned long pmdval;
  60. BUG_ON(mm != &init_mm);
  61. /*
  62. * The pmd must be loaded with the physical
  63. * address of the PTE table
  64. */
  65. pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE;
  66. set_pmd(pmdp, __pmd(pmdval));
  67. }
  68. static inline void
  69. pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep)
  70. {
  71. unsigned long pmdval;
  72. BUG_ON(mm == &init_mm);
  73. pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE;
  74. set_pmd(pmdp, __pmd(pmdval));
  75. }
  76. #endif