pgtable.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * This file contains the functions and defines necessary to modify and
  4. * use the SuperH page table tree.
  5. *
  6. * Copyright (C) 1999 Niibe Yutaka
  7. * Copyright (C) 2002 - 2007 Paul Mundt
  8. */
  9. #ifndef __ASM_SH_PGTABLE_H
  10. #define __ASM_SH_PGTABLE_H
  11. #ifdef CONFIG_X2TLB
  12. #include <asm/pgtable-3level.h>
  13. #else
  14. #include <asm/pgtable-2level.h>
  15. #endif
  16. #include <asm/page.h>
  17. #include <asm/mmu.h>
  18. #ifndef __ASSEMBLY__
  19. #include <asm/addrspace.h>
  20. #include <asm/fixmap.h>
  21. /*
  22. * ZERO_PAGE is a global shared page that is always zero: used
  23. * for zero-mapped memory areas etc..
  24. */
  25. extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
  26. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  27. #endif /* !__ASSEMBLY__ */
  28. /*
  29. * Effective and physical address definitions, to aid with sign
  30. * extension.
  31. */
  32. #define NEFF 32
  33. #define NEFF_SIGN (1LL << (NEFF - 1))
  34. #define NEFF_MASK (-1LL << NEFF)
  35. static inline unsigned long long neff_sign_extend(unsigned long val)
  36. {
  37. unsigned long long extended = val;
  38. return (extended & NEFF_SIGN) ? (extended | NEFF_MASK) : extended;
  39. }
  40. #ifdef CONFIG_29BIT
  41. #define NPHYS 29
  42. #else
  43. #define NPHYS 32
  44. #endif
  45. #define NPHYS_SIGN (1LL << (NPHYS - 1))
  46. #define NPHYS_MASK (-1LL << NPHYS)
  47. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  48. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  49. /* Entries per level */
  50. #define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE))
  51. #define PHYS_ADDR_MASK29 0x1fffffff
  52. #define PHYS_ADDR_MASK32 0xffffffff
  53. static inline unsigned long phys_addr_mask(void)
  54. {
  55. /* Is the MMU in 29bit mode? */
  56. if (__in_29bit_mode())
  57. return PHYS_ADDR_MASK29;
  58. return PHYS_ADDR_MASK32;
  59. }
  60. #define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK)
  61. #define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT)
  62. #define VMALLOC_START (P3SEG)
  63. #define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
  64. #include <asm/pgtable_32.h>
  65. /*
  66. * SH-X and lower (legacy) SuperH parts (SH-3, SH-4, some SH-4A) can't do page
  67. * protection for execute, and considers it the same as a read. Also, write
  68. * permission implies read permission. This is the closest we can get..
  69. *
  70. * SH-X2 (SH7785) and later parts take this to the opposite end of the extreme,
  71. * not only supporting separate execute, read, and write bits, but having
  72. * completely separate permission bits for user and kernel space.
  73. */
  74. /*xwr*/
  75. typedef pte_t *pte_addr_t;
  76. #define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT)))
  77. struct vm_area_struct;
  78. struct mm_struct;
  79. extern void __update_cache(struct vm_area_struct *vma,
  80. unsigned long address, pte_t pte);
  81. extern void __update_tlb(struct vm_area_struct *vma,
  82. unsigned long address, pte_t pte);
  83. static inline void update_mmu_cache_range(struct vm_fault *vmf,
  84. struct vm_area_struct *vma, unsigned long address,
  85. pte_t *ptep, unsigned int nr)
  86. {
  87. pte_t pte = *ptep;
  88. __update_cache(vma, address, pte);
  89. __update_tlb(vma, address, pte);
  90. }
  91. #define update_mmu_cache(vma, addr, ptep) \
  92. update_mmu_cache_range(NULL, vma, addr, ptep, 1)
  93. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  94. extern void paging_init(void);
  95. extern void page_table_range_init(unsigned long start, unsigned long end,
  96. pgd_t *pgd);
  97. static inline bool __pte_access_permitted(pte_t pte, u64 prot)
  98. {
  99. return (pte_val(pte) & (prot | _PAGE_SPECIAL)) == prot;
  100. }
  101. #ifdef CONFIG_X2TLB
  102. static inline bool pte_access_permitted(pte_t pte, bool write)
  103. {
  104. u64 prot = _PAGE_PRESENT;
  105. prot |= _PAGE_EXT(_PAGE_EXT_KERN_READ | _PAGE_EXT_USER_READ);
  106. if (write)
  107. prot |= _PAGE_EXT(_PAGE_EXT_KERN_WRITE | _PAGE_EXT_USER_WRITE);
  108. return __pte_access_permitted(pte, prot);
  109. }
  110. #else
  111. static inline bool pte_access_permitted(pte_t pte, bool write)
  112. {
  113. u64 prot = _PAGE_PRESENT | _PAGE_USER;
  114. if (write)
  115. prot |= _PAGE_RW;
  116. return __pte_access_permitted(pte, prot);
  117. }
  118. #endif
  119. #define pte_access_permitted pte_access_permitted
  120. /* arch/sh/mm/mmap.c */
  121. #define HAVE_ARCH_UNMAPPED_AREA
  122. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  123. #endif /* __ASM_SH_PGTABLE_H */