pgtable-ppc64.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #ifndef _ASM_POWERPC_PGTABLE_PPC64_H_
  2. #define _ASM_POWERPC_PGTABLE_PPC64_H_
  3. /*
  4. * This file contains the functions and defines necessary to modify and use
  5. * the ppc64 hashed page table.
  6. */
  7. #ifndef __ASSEMBLY__
  8. #include <linux/stddef.h>
  9. #include <asm/tlbflush.h>
  10. #endif /* __ASSEMBLY__ */
  11. #ifdef CONFIG_PPC_64K_PAGES
  12. #include <asm/pgtable-ppc64-64k.h>
  13. #else
  14. #include <asm/pgtable-ppc64-4k.h>
  15. #endif
  16. #define FIRST_USER_ADDRESS 0
  17. /*
  18. * Size of EA range mapped by our pagetables.
  19. */
  20. #define PGTABLE_EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
  21. PUD_INDEX_SIZE + PGD_INDEX_SIZE + PAGE_SHIFT)
  22. #define PGTABLE_RANGE (ASM_CONST(1) << PGTABLE_EADDR_SIZE)
  23. /* Some sanity checking */
  24. #if TASK_SIZE_USER64 > PGTABLE_RANGE
  25. #error TASK_SIZE_USER64 exceeds pagetable range
  26. #endif
  27. #if TASK_SIZE_USER64 > (1UL << (USER_ESID_BITS + SID_SHIFT))
  28. #error TASK_SIZE_USER64 exceeds user VSID range
  29. #endif
  30. /*
  31. * Define the address range of the vmalloc VM area.
  32. */
  33. #define VMALLOC_START ASM_CONST(0xD000000000000000)
  34. #define VMALLOC_SIZE (PGTABLE_RANGE >> 1)
  35. #define VMALLOC_END (VMALLOC_START + VMALLOC_SIZE)
  36. /*
  37. * Define the address ranges for MMIO and IO space :
  38. *
  39. * ISA_IO_BASE = VMALLOC_END, 64K reserved area
  40. * PHB_IO_BASE = ISA_IO_BASE + 64K to ISA_IO_BASE + 2G, PHB IO spaces
  41. * IOREMAP_BASE = ISA_IO_BASE + 2G to VMALLOC_START + PGTABLE_RANGE
  42. */
  43. #define FULL_IO_SIZE 0x80000000ul
  44. #define ISA_IO_BASE (VMALLOC_END)
  45. #define ISA_IO_END (VMALLOC_END + 0x10000ul)
  46. #define PHB_IO_BASE (ISA_IO_END)
  47. #define PHB_IO_END (VMALLOC_END + FULL_IO_SIZE)
  48. #define IOREMAP_BASE (PHB_IO_END)
  49. #define IOREMAP_END (VMALLOC_START + PGTABLE_RANGE)
  50. /*
  51. * Region IDs
  52. */
  53. #define REGION_SHIFT 60UL
  54. #define REGION_MASK (0xfUL << REGION_SHIFT)
  55. #define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
  56. #define VMALLOC_REGION_ID (REGION_ID(VMALLOC_START))
  57. #define KERNEL_REGION_ID (REGION_ID(PAGE_OFFSET))
  58. #define VMEMMAP_REGION_ID (0xfUL)
  59. #define USER_REGION_ID (0UL)
  60. /*
  61. * Defines the address of the vmemap area, in its own region
  62. */
  63. #define VMEMMAP_BASE (VMEMMAP_REGION_ID << REGION_SHIFT)
  64. #define vmemmap ((struct page *)VMEMMAP_BASE)
  65. /*
  66. * Include the PTE bits definitions
  67. */
  68. #include <asm/pte-hash64.h>
  69. #include <asm/pte-common.h>
  70. #ifdef CONFIG_PPC_MM_SLICES
  71. #define HAVE_ARCH_UNMAPPED_AREA
  72. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  73. #endif /* CONFIG_PPC_MM_SLICES */
  74. #ifndef __ASSEMBLY__
  75. /*
  76. * This is the default implementation of various PTE accessors, it's
  77. * used in all cases except Book3S with 64K pages where we have a
  78. * concept of sub-pages
  79. */
  80. #ifndef __real_pte
  81. #ifdef STRICT_MM_TYPECHECKS
  82. #define __real_pte(e,p) ((real_pte_t){(e)})
  83. #define __rpte_to_pte(r) ((r).pte)
  84. #else
  85. #define __real_pte(e,p) (e)
  86. #define __rpte_to_pte(r) (__pte(r))
  87. #endif
  88. #define __rpte_to_hidx(r,index) (pte_val(__rpte_to_pte(r)) >> 12)
  89. #define pte_iterate_hashed_subpages(rpte, psize, va, index, shift) \
  90. do { \
  91. index = 0; \
  92. shift = mmu_psize_defs[psize].shift; \
  93. #define pte_iterate_hashed_end() } while(0)
  94. #ifdef CONFIG_PPC_HAS_HASH_64K
  95. #define pte_pagesize_index(mm, addr, pte) get_slice_psize(mm, addr)
  96. #else
  97. #define pte_pagesize_index(mm, addr, pte) MMU_PAGE_4K
  98. #endif
  99. #endif /* __real_pte */
  100. /* pte_clear moved to later in this file */
  101. #define PMD_BAD_BITS (PTE_TABLE_SIZE-1)
  102. #define PUD_BAD_BITS (PMD_TABLE_SIZE-1)
  103. #define pmd_set(pmdp, pmdval) (pmd_val(*(pmdp)) = (pmdval))
  104. #define pmd_none(pmd) (!pmd_val(pmd))
  105. #define pmd_bad(pmd) (!is_kernel_addr(pmd_val(pmd)) \
  106. || (pmd_val(pmd) & PMD_BAD_BITS))
  107. #define pmd_present(pmd) (pmd_val(pmd) != 0)
  108. #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0)
  109. #define pmd_page_vaddr(pmd) (pmd_val(pmd) & ~PMD_MASKED_BITS)
  110. #define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
  111. #define pud_set(pudp, pudval) (pud_val(*(pudp)) = (pudval))
  112. #define pud_none(pud) (!pud_val(pud))
  113. #define pud_bad(pud) (!is_kernel_addr(pud_val(pud)) \
  114. || (pud_val(pud) & PUD_BAD_BITS))
  115. #define pud_present(pud) (pud_val(pud) != 0)
  116. #define pud_clear(pudp) (pud_val(*(pudp)) = 0)
  117. #define pud_page_vaddr(pud) (pud_val(pud) & ~PUD_MASKED_BITS)
  118. #define pud_page(pud) virt_to_page(pud_page_vaddr(pud))
  119. #define pgd_set(pgdp, pudp) ({pgd_val(*(pgdp)) = (unsigned long)(pudp);})
  120. /*
  121. * Find an entry in a page-table-directory. We combine the address region
  122. * (the high order N bits) and the pgd portion of the address.
  123. */
  124. /* to avoid overflow in free_pgtables we don't use PTRS_PER_PGD here */
  125. #define pgd_index(address) (((address) >> (PGDIR_SHIFT)) & 0x1ff)
  126. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  127. #define pmd_offset(pudp,addr) \
  128. (((pmd_t *) pud_page_vaddr(*(pudp))) + (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)))
  129. #define pte_offset_kernel(dir,addr) \
  130. (((pte_t *) pmd_page_vaddr(*(dir))) + (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
  131. #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
  132. #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
  133. #define pte_unmap(pte) do { } while(0)
  134. #define pte_unmap_nested(pte) do { } while(0)
  135. /* to find an entry in a kernel page-table-directory */
  136. /* This now only contains the vmalloc pages */
  137. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  138. /* Atomic PTE updates */
  139. static inline unsigned long pte_update(struct mm_struct *mm,
  140. unsigned long addr,
  141. pte_t *ptep, unsigned long clr,
  142. int huge)
  143. {
  144. #ifdef PTE_ATOMIC_UPDATES
  145. unsigned long old, tmp;
  146. __asm__ __volatile__(
  147. "1: ldarx %0,0,%3 # pte_update\n\
  148. andi. %1,%0,%6\n\
  149. bne- 1b \n\
  150. andc %1,%0,%4 \n\
  151. stdcx. %1,0,%3 \n\
  152. bne- 1b"
  153. : "=&r" (old), "=&r" (tmp), "=m" (*ptep)
  154. : "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY)
  155. : "cc" );
  156. #else
  157. unsigned long old = pte_val(*ptep);
  158. *ptep = __pte(old & ~clr);
  159. #endif
  160. /* huge pages use the old page table lock */
  161. if (!huge)
  162. assert_pte_locked(mm, addr);
  163. if (old & _PAGE_HASHPTE)
  164. hpte_need_flush(mm, addr, ptep, old, huge);
  165. return old;
  166. }
  167. static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
  168. unsigned long addr, pte_t *ptep)
  169. {
  170. unsigned long old;
  171. if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
  172. return 0;
  173. old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0);
  174. return (old & _PAGE_ACCESSED) != 0;
  175. }
  176. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  177. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  178. ({ \
  179. int __r; \
  180. __r = __ptep_test_and_clear_young((__vma)->vm_mm, __addr, __ptep); \
  181. __r; \
  182. })
  183. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  184. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
  185. pte_t *ptep)
  186. {
  187. unsigned long old;
  188. if ((pte_val(*ptep) & _PAGE_RW) == 0)
  189. return;
  190. old = pte_update(mm, addr, ptep, _PAGE_RW, 0);
  191. }
  192. static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
  193. unsigned long addr, pte_t *ptep)
  194. {
  195. unsigned long old;
  196. if ((pte_val(*ptep) & _PAGE_RW) == 0)
  197. return;
  198. old = pte_update(mm, addr, ptep, _PAGE_RW, 1);
  199. }
  200. /*
  201. * We currently remove entries from the hashtable regardless of whether
  202. * the entry was young or dirty. The generic routines only flush if the
  203. * entry was young or dirty which is not good enough.
  204. *
  205. * We should be more intelligent about this but for the moment we override
  206. * these functions and force a tlb flush unconditionally
  207. */
  208. #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
  209. #define ptep_clear_flush_young(__vma, __address, __ptep) \
  210. ({ \
  211. int __young = __ptep_test_and_clear_young((__vma)->vm_mm, __address, \
  212. __ptep); \
  213. __young; \
  214. })
  215. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  216. static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
  217. unsigned long addr, pte_t *ptep)
  218. {
  219. unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0);
  220. return __pte(old);
  221. }
  222. static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
  223. pte_t * ptep)
  224. {
  225. pte_update(mm, addr, ptep, ~0UL, 0);
  226. }
  227. /* Set the dirty and/or accessed bits atomically in a linux PTE, this
  228. * function doesn't need to flush the hash entry
  229. */
  230. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
  231. {
  232. unsigned long bits = pte_val(entry) &
  233. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW |
  234. _PAGE_EXEC | _PAGE_HWEXEC);
  235. #ifdef PTE_ATOMIC_UPDATES
  236. unsigned long old, tmp;
  237. __asm__ __volatile__(
  238. "1: ldarx %0,0,%4\n\
  239. andi. %1,%0,%6\n\
  240. bne- 1b \n\
  241. or %0,%3,%0\n\
  242. stdcx. %0,0,%4\n\
  243. bne- 1b"
  244. :"=&r" (old), "=&r" (tmp), "=m" (*ptep)
  245. :"r" (bits), "r" (ptep), "m" (*ptep), "i" (_PAGE_BUSY)
  246. :"cc");
  247. #else
  248. unsigned long old = pte_val(*ptep);
  249. *ptep = __pte(old | bits);
  250. #endif
  251. }
  252. #define __HAVE_ARCH_PTE_SAME
  253. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HPTEFLAGS) == 0)
  254. #define pte_ERROR(e) \
  255. printk("%s:%d: bad pte %08lx.\n", __FILE__, __LINE__, pte_val(e))
  256. #define pmd_ERROR(e) \
  257. printk("%s:%d: bad pmd %08lx.\n", __FILE__, __LINE__, pmd_val(e))
  258. #define pgd_ERROR(e) \
  259. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  260. /* Encode and de-code a swap entry */
  261. #define __swp_type(entry) (((entry).val >> 1) & 0x3f)
  262. #define __swp_offset(entry) ((entry).val >> 8)
  263. #define __swp_entry(type, offset) ((swp_entry_t){((type)<< 1)|((offset)<<8)})
  264. #define __pte_to_swp_entry(pte) ((swp_entry_t){pte_val(pte) >> PTE_RPN_SHIFT})
  265. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << PTE_RPN_SHIFT })
  266. #define pte_to_pgoff(pte) (pte_val(pte) >> PTE_RPN_SHIFT)
  267. #define pgoff_to_pte(off) ((pte_t) {((off) << PTE_RPN_SHIFT)|_PAGE_FILE})
  268. #define PTE_FILE_MAX_BITS (BITS_PER_LONG - PTE_RPN_SHIFT)
  269. void pgtable_cache_init(void);
  270. /*
  271. * find_linux_pte returns the address of a linux pte for a given
  272. * effective address and directory. If not found, it returns zero.
  273. */static inline pte_t *find_linux_pte(pgd_t *pgdir, unsigned long ea)
  274. {
  275. pgd_t *pg;
  276. pud_t *pu;
  277. pmd_t *pm;
  278. pte_t *pt = NULL;
  279. pg = pgdir + pgd_index(ea);
  280. if (!pgd_none(*pg)) {
  281. pu = pud_offset(pg, ea);
  282. if (!pud_none(*pu)) {
  283. pm = pmd_offset(pu, ea);
  284. if (pmd_present(*pm))
  285. pt = pte_offset_kernel(pm, ea);
  286. }
  287. }
  288. return pt;
  289. }
  290. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long address);
  291. #endif /* __ASSEMBLY__ */
  292. #endif /* _ASM_POWERPC_PGTABLE_PPC64_H_ */