pgtable-ppc64.h 10 KB

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