pgtable.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 kern_addr_valid(addr) (1)
  77. #define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT)))
  78. struct vm_area_struct;
  79. struct mm_struct;
  80. extern void __update_cache(struct vm_area_struct *vma,
  81. unsigned long address, pte_t pte);
  82. extern void __update_tlb(struct vm_area_struct *vma,
  83. unsigned long address, pte_t pte);
  84. static inline void
  85. update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
  86. {
  87. pte_t pte = *ptep;
  88. __update_cache(vma, address, pte);
  89. __update_tlb(vma, address, pte);
  90. }
  91. extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
  92. extern void paging_init(void);
  93. extern void page_table_range_init(unsigned long start, unsigned long end,
  94. pgd_t *pgd);
  95. static inline bool __pte_access_permitted(pte_t pte, u64 prot)
  96. {
  97. return (pte_val(pte) & (prot | _PAGE_SPECIAL)) == prot;
  98. }
  99. #ifdef CONFIG_X2TLB
  100. static inline bool pte_access_permitted(pte_t pte, bool write)
  101. {
  102. u64 prot = _PAGE_PRESENT;
  103. prot |= _PAGE_EXT(_PAGE_EXT_KERN_READ | _PAGE_EXT_USER_READ);
  104. if (write)
  105. prot |= _PAGE_EXT(_PAGE_EXT_KERN_WRITE | _PAGE_EXT_USER_WRITE);
  106. return __pte_access_permitted(pte, prot);
  107. }
  108. #else
  109. static inline bool pte_access_permitted(pte_t pte, bool write)
  110. {
  111. u64 prot = _PAGE_PRESENT | _PAGE_USER;
  112. if (write)
  113. prot |= _PAGE_RW;
  114. return __pte_access_permitted(pte, prot);
  115. }
  116. #endif
  117. #define pte_access_permitted pte_access_permitted
  118. /* arch/sh/mm/mmap.c */
  119. #define HAVE_ARCH_UNMAPPED_AREA
  120. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  121. #endif /* __ASM_SH_PGTABLE_H */