pgtable-ppc32.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. #ifndef _ASM_POWERPC_PGTABLE_PPC32_H
  2. #define _ASM_POWERPC_PGTABLE_PPC32_H
  3. #include <asm-generic/pgtable-nopmd.h>
  4. #ifndef __ASSEMBLY__
  5. #include <linux/sched.h>
  6. #include <linux/threads.h>
  7. #include <asm/io.h> /* For sub-arch specific PPC_PIN_SIZE */
  8. extern unsigned long va_to_phys(unsigned long address);
  9. extern pte_t *va_to_pte(unsigned long address);
  10. extern unsigned long ioremap_bot, ioremap_base;
  11. #ifdef CONFIG_44x
  12. extern int icache_44x_need_flush;
  13. #endif
  14. #endif /* __ASSEMBLY__ */
  15. /*
  16. * The normal case is that PTEs are 32-bits and we have a 1-page
  17. * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus
  18. *
  19. * For any >32-bit physical address platform, we can use the following
  20. * two level page table layout where the pgdir is 8KB and the MS 13 bits
  21. * are an index to the second level table. The combined pgdir/pmd first
  22. * level has 2048 entries and the second level has 512 64-bit PTE entries.
  23. * -Matt
  24. */
  25. /* PGDIR_SHIFT determines what a top-level page table entry can map */
  26. #define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT)
  27. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  28. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  29. /*
  30. * entries per page directory level: our page-table tree is two-level, so
  31. * we don't really have any PMD directory.
  32. */
  33. #ifndef __ASSEMBLY__
  34. #define PTE_TABLE_SIZE (sizeof(pte_t) << PTE_SHIFT)
  35. #define PGD_TABLE_SIZE (sizeof(pgd_t) << (32 - PGDIR_SHIFT))
  36. #endif /* __ASSEMBLY__ */
  37. #define PTRS_PER_PTE (1 << PTE_SHIFT)
  38. #define PTRS_PER_PMD 1
  39. #define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))
  40. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  41. #define FIRST_USER_ADDRESS 0
  42. #define pte_ERROR(e) \
  43. printk("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \
  44. (unsigned long long)pte_val(e))
  45. #define pgd_ERROR(e) \
  46. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  47. /*
  48. * Just any arbitrary offset to the start of the vmalloc VM area: the
  49. * current 64MB value just means that there will be a 64MB "hole" after the
  50. * physical memory until the kernel virtual memory starts. That means that
  51. * any out-of-bounds memory accesses will hopefully be caught.
  52. * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  53. * area for the same reason. ;)
  54. *
  55. * We no longer map larger than phys RAM with the BATs so we don't have
  56. * to worry about the VMALLOC_OFFSET causing problems. We do have to worry
  57. * about clashes between our early calls to ioremap() that start growing down
  58. * from ioremap_base being run into the VM area allocations (growing upwards
  59. * from VMALLOC_START). For this reason we have ioremap_bot to check when
  60. * we actually run into our mappings setup in the early boot with the VM
  61. * system. This really does become a problem for machines with good amounts
  62. * of RAM. -- Cort
  63. */
  64. #define VMALLOC_OFFSET (0x1000000) /* 16M */
  65. #ifdef PPC_PIN_SIZE
  66. #define VMALLOC_START (((_ALIGN((long)high_memory, PPC_PIN_SIZE) + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
  67. #else
  68. #define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
  69. #endif
  70. #define VMALLOC_END ioremap_bot
  71. /*
  72. * Bits in a linux-style PTE. These match the bits in the
  73. * (hardware-defined) PowerPC PTE as closely as possible.
  74. */
  75. #if defined(CONFIG_40x)
  76. #include <asm/pte-40x.h>
  77. #elif defined(CONFIG_44x)
  78. #include <asm/pte-44x.h>
  79. #elif defined(CONFIG_FSL_BOOKE)
  80. #include <asm/pte-fsl-booke.h>
  81. #elif defined(CONFIG_8xx)
  82. #include <asm/pte-8xx.h>
  83. #else /* CONFIG_6xx */
  84. #include <asm/pte-hash32.h>
  85. #endif
  86. /* And here we include common definitions */
  87. #include <asm/pte-common.h>
  88. #ifndef __ASSEMBLY__
  89. #define pte_clear(mm, addr, ptep) \
  90. do { pte_update(ptep, ~_PAGE_HASHPTE, 0); } while (0)
  91. #define pmd_none(pmd) (!pmd_val(pmd))
  92. #define pmd_bad(pmd) (pmd_val(pmd) & _PMD_BAD)
  93. #define pmd_present(pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK)
  94. #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0)
  95. /*
  96. * When flushing the tlb entry for a page, we also need to flush the hash
  97. * table entry. flush_hash_pages is assembler (for speed) in hashtable.S.
  98. */
  99. extern int flush_hash_pages(unsigned context, unsigned long va,
  100. unsigned long pmdval, int count);
  101. /* Add an HPTE to the hash table */
  102. extern void add_hash_page(unsigned context, unsigned long va,
  103. unsigned long pmdval);
  104. /* Flush an entry from the TLB/hash table */
  105. extern void flush_hash_entry(struct mm_struct *mm, pte_t *ptep,
  106. unsigned long address);
  107. /*
  108. * PTE updates. This function is called whenever an existing
  109. * valid PTE is updated. This does -not- include set_pte_at()
  110. * which nowadays only sets a new PTE.
  111. *
  112. * Depending on the type of MMU, we may need to use atomic updates
  113. * and the PTE may be either 32 or 64 bit wide. In the later case,
  114. * when using atomic updates, only the low part of the PTE is
  115. * accessed atomically.
  116. *
  117. * In addition, on 44x, we also maintain a global flag indicating
  118. * that an executable user mapping was modified, which is needed
  119. * to properly flush the virtually tagged instruction cache of
  120. * those implementations.
  121. */
  122. #ifndef CONFIG_PTE_64BIT
  123. static inline unsigned long pte_update(pte_t *p,
  124. unsigned long clr,
  125. unsigned long set)
  126. {
  127. #ifdef PTE_ATOMIC_UPDATES
  128. unsigned long old, tmp;
  129. __asm__ __volatile__("\
  130. 1: lwarx %0,0,%3\n\
  131. andc %1,%0,%4\n\
  132. or %1,%1,%5\n"
  133. PPC405_ERR77(0,%3)
  134. " stwcx. %1,0,%3\n\
  135. bne- 1b"
  136. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  137. : "r" (p), "r" (clr), "r" (set), "m" (*p)
  138. : "cc" );
  139. #else /* PTE_ATOMIC_UPDATES */
  140. unsigned long old = pte_val(*p);
  141. *p = __pte((old & ~clr) | set);
  142. #endif /* !PTE_ATOMIC_UPDATES */
  143. #ifdef CONFIG_44x
  144. if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC))
  145. icache_44x_need_flush = 1;
  146. #endif
  147. return old;
  148. }
  149. #else /* CONFIG_PTE_64BIT */
  150. static inline unsigned long long pte_update(pte_t *p,
  151. unsigned long clr,
  152. unsigned long set)
  153. {
  154. #ifdef PTE_ATOMIC_UPDATES
  155. unsigned long long old;
  156. unsigned long tmp;
  157. __asm__ __volatile__("\
  158. 1: lwarx %L0,0,%4\n\
  159. lwzx %0,0,%3\n\
  160. andc %1,%L0,%5\n\
  161. or %1,%1,%6\n"
  162. PPC405_ERR77(0,%3)
  163. " stwcx. %1,0,%4\n\
  164. bne- 1b"
  165. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  166. : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p)
  167. : "cc" );
  168. #else /* PTE_ATOMIC_UPDATES */
  169. unsigned long long old = pte_val(*p);
  170. *p = __pte((old & ~(unsigned long long)clr) | set);
  171. #endif /* !PTE_ATOMIC_UPDATES */
  172. #ifdef CONFIG_44x
  173. if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC))
  174. icache_44x_need_flush = 1;
  175. #endif
  176. return old;
  177. }
  178. #endif /* CONFIG_PTE_64BIT */
  179. /*
  180. * 2.6 calls this without flushing the TLB entry; this is wrong
  181. * for our hash-based implementation, we fix that up here.
  182. */
  183. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  184. static inline int __ptep_test_and_clear_young(unsigned int context, unsigned long addr, pte_t *ptep)
  185. {
  186. unsigned long old;
  187. old = pte_update(ptep, _PAGE_ACCESSED, 0);
  188. #if _PAGE_HASHPTE != 0
  189. if (old & _PAGE_HASHPTE) {
  190. unsigned long ptephys = __pa(ptep) & PAGE_MASK;
  191. flush_hash_pages(context, addr, ptephys, 1);
  192. }
  193. #endif
  194. return (old & _PAGE_ACCESSED) != 0;
  195. }
  196. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  197. __ptep_test_and_clear_young((__vma)->vm_mm->context.id, __addr, __ptep)
  198. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  199. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  200. pte_t *ptep)
  201. {
  202. return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0));
  203. }
  204. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  205. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
  206. pte_t *ptep)
  207. {
  208. pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0);
  209. }
  210. static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
  211. unsigned long addr, pte_t *ptep)
  212. {
  213. ptep_set_wrprotect(mm, addr, ptep);
  214. }
  215. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
  216. {
  217. unsigned long bits = pte_val(entry) &
  218. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW |
  219. _PAGE_HWEXEC | _PAGE_EXEC);
  220. pte_update(ptep, 0, bits);
  221. }
  222. #define __HAVE_ARCH_PTE_SAME
  223. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
  224. /*
  225. * Note that on Book E processors, the pmd contains the kernel virtual
  226. * (lowmem) address of the pte page. The physical address is less useful
  227. * because everything runs with translation enabled (even the TLB miss
  228. * handler). On everything else the pmd contains the physical address
  229. * of the pte page. -- paulus
  230. */
  231. #ifndef CONFIG_BOOKE
  232. #define pmd_page_vaddr(pmd) \
  233. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  234. #define pmd_page(pmd) \
  235. (mem_map + (pmd_val(pmd) >> PAGE_SHIFT))
  236. #else
  237. #define pmd_page_vaddr(pmd) \
  238. ((unsigned long) (pmd_val(pmd) & PAGE_MASK))
  239. #define pmd_page(pmd) \
  240. pfn_to_page((__pa(pmd_val(pmd)) >> PAGE_SHIFT))
  241. #endif
  242. /* to find an entry in a kernel page-table-directory */
  243. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  244. /* to find an entry in a page-table-directory */
  245. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  246. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  247. /* Find an entry in the third-level page table.. */
  248. #define pte_index(address) \
  249. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  250. #define pte_offset_kernel(dir, addr) \
  251. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr))
  252. #define pte_offset_map(dir, addr) \
  253. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE0) + pte_index(addr))
  254. #define pte_offset_map_nested(dir, addr) \
  255. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE1) + pte_index(addr))
  256. #define pte_unmap(pte) kunmap_atomic(pte, KM_PTE0)
  257. #define pte_unmap_nested(pte) kunmap_atomic(pte, KM_PTE1)
  258. /*
  259. * Encode and decode a swap entry.
  260. * Note that the bits we use in a PTE for representing a swap entry
  261. * must not include the _PAGE_PRESENT bit, the _PAGE_FILE bit, or the
  262. *_PAGE_HASHPTE bit (if used). -- paulus
  263. */
  264. #define __swp_type(entry) ((entry).val & 0x1f)
  265. #define __swp_offset(entry) ((entry).val >> 5)
  266. #define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 5) })
  267. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 })
  268. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 })
  269. /* Encode and decode a nonlinear file mapping entry */
  270. #define PTE_FILE_MAX_BITS 29
  271. #define pte_to_pgoff(pte) (pte_val(pte) >> 3)
  272. #define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE })
  273. /*
  274. * No page table caches to initialise
  275. */
  276. #define pgtable_cache_init() do { } while (0)
  277. extern int get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep,
  278. pmd_t **pmdp);
  279. #endif /* !__ASSEMBLY__ */
  280. #endif /* _ASM_POWERPC_PGTABLE_PPC32_H */