pgtable-ppc32.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. /* If _PAGE_SPECIAL is defined, then we advertise our support for it */
  87. #ifdef _PAGE_SPECIAL
  88. #define __HAVE_ARCH_PTE_SPECIAL
  89. #endif
  90. /*
  91. * Some bits are only used on some cpu families... Make sure that all
  92. * the undefined gets defined as 0
  93. */
  94. #ifndef _PAGE_HASHPTE
  95. #define _PAGE_HASHPTE 0
  96. #endif
  97. #ifndef _PTE_NONE_MASK
  98. #define _PTE_NONE_MASK 0
  99. #endif
  100. #ifndef _PAGE_SHARED
  101. #define _PAGE_SHARED 0
  102. #endif
  103. #ifndef _PAGE_HWWRITE
  104. #define _PAGE_HWWRITE 0
  105. #endif
  106. #ifndef _PAGE_HWEXEC
  107. #define _PAGE_HWEXEC 0
  108. #endif
  109. #ifndef _PAGE_EXEC
  110. #define _PAGE_EXEC 0
  111. #endif
  112. #ifndef _PAGE_ENDIAN
  113. #define _PAGE_ENDIAN 0
  114. #endif
  115. #ifndef _PAGE_COHERENT
  116. #define _PAGE_COHERENT 0
  117. #endif
  118. #ifndef _PAGE_WRITETHRU
  119. #define _PAGE_WRITETHRU 0
  120. #endif
  121. #ifndef _PAGE_SPECIAL
  122. #define _PAGE_SPECIAL 0
  123. #endif
  124. #ifndef _PMD_PRESENT_MASK
  125. #define _PMD_PRESENT_MASK _PMD_PRESENT
  126. #endif
  127. #ifndef _PMD_SIZE
  128. #define _PMD_SIZE 0
  129. #define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
  130. #endif
  131. #define _PAGE_HPTEFLAGS _PAGE_HASHPTE
  132. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | \
  133. _PAGE_SPECIAL)
  134. #define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | _PAGE_NO_CACHE | \
  135. _PAGE_WRITETHRU | _PAGE_ENDIAN | \
  136. _PAGE_USER | _PAGE_ACCESSED | \
  137. _PAGE_RW | _PAGE_HWWRITE | _PAGE_DIRTY | \
  138. _PAGE_EXEC | _PAGE_HWEXEC)
  139. /*
  140. * We define 2 sets of base prot bits, one for basic pages (ie,
  141. * cacheable kernel and user pages) and one for non cacheable
  142. * pages. We always set _PAGE_COHERENT when SMP is enabled or
  143. * the processor might need it for DMA coherency.
  144. */
  145. #if defined(CONFIG_SMP) || defined(CONFIG_PPC_STD_MMU)
  146. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT)
  147. #else
  148. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
  149. #endif
  150. #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_NO_CACHE)
  151. #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE)
  152. #define _PAGE_KERNEL (_PAGE_BASE | _PAGE_SHARED | _PAGE_WRENABLE)
  153. #define _PAGE_KERNEL_NC (_PAGE_BASE_NC | _PAGE_SHARED | _PAGE_WRENABLE)
  154. #ifdef CONFIG_PPC_STD_MMU
  155. /* On standard PPC MMU, no user access implies kernel read/write access,
  156. * so to write-protect kernel memory we must turn on user access */
  157. #define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED | _PAGE_USER)
  158. #else
  159. #define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED)
  160. #endif
  161. #define _PAGE_IO (_PAGE_KERNEL_NC | _PAGE_GUARDED)
  162. #define _PAGE_RAM (_PAGE_KERNEL | _PAGE_HWEXEC)
  163. #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
  164. defined(CONFIG_KPROBES)
  165. /* We want the debuggers to be able to set breakpoints anywhere, so
  166. * don't write protect the kernel text */
  167. #define _PAGE_RAM_TEXT _PAGE_RAM
  168. #else
  169. #define _PAGE_RAM_TEXT (_PAGE_KERNEL_RO | _PAGE_HWEXEC)
  170. #endif
  171. #define PAGE_NONE __pgprot(_PAGE_BASE)
  172. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
  173. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  174. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
  175. #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
  176. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
  177. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  178. #define PAGE_KERNEL __pgprot(_PAGE_RAM)
  179. #define PAGE_KERNEL_NOCACHE __pgprot(_PAGE_IO)
  180. /*
  181. * The PowerPC can only do execute protection on a segment (256MB) basis,
  182. * not on a page basis. So we consider execute permission the same as read.
  183. * Also, write permissions imply read permissions.
  184. * This is the closest we can get..
  185. */
  186. #define __P000 PAGE_NONE
  187. #define __P001 PAGE_READONLY_X
  188. #define __P010 PAGE_COPY
  189. #define __P011 PAGE_COPY_X
  190. #define __P100 PAGE_READONLY
  191. #define __P101 PAGE_READONLY_X
  192. #define __P110 PAGE_COPY
  193. #define __P111 PAGE_COPY_X
  194. #define __S000 PAGE_NONE
  195. #define __S001 PAGE_READONLY_X
  196. #define __S010 PAGE_SHARED
  197. #define __S011 PAGE_SHARED_X
  198. #define __S100 PAGE_READONLY
  199. #define __S101 PAGE_READONLY_X
  200. #define __S110 PAGE_SHARED
  201. #define __S111 PAGE_SHARED_X
  202. #ifndef __ASSEMBLY__
  203. /* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
  204. * kernel without large page PMD support */
  205. extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
  206. /*
  207. * Conversions between PTE values and page frame numbers.
  208. */
  209. /* in some case we want to additionaly adjust where the pfn is in the pte to
  210. * allow room for more flags */
  211. #if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_PTE_64BIT)
  212. #define PFN_SHIFT_OFFSET (PAGE_SHIFT + 8)
  213. #else
  214. #define PFN_SHIFT_OFFSET (PAGE_SHIFT)
  215. #endif
  216. #define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET)
  217. #define pte_page(x) pfn_to_page(pte_pfn(x))
  218. #define pfn_pte(pfn, prot) __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) |\
  219. pgprot_val(prot))
  220. #define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
  221. #endif /* __ASSEMBLY__ */
  222. #define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0)
  223. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  224. #define pte_clear(mm, addr, ptep) \
  225. do { pte_update(ptep, ~_PAGE_HASHPTE, 0); } while (0)
  226. #define pmd_none(pmd) (!pmd_val(pmd))
  227. #define pmd_bad(pmd) (pmd_val(pmd) & _PMD_BAD)
  228. #define pmd_present(pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK)
  229. #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0)
  230. #ifndef __ASSEMBLY__
  231. /*
  232. * The following only work if pte_present() is true.
  233. * Undefined behaviour if not..
  234. */
  235. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
  236. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  237. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  238. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  239. static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
  240. static inline pte_t pte_wrprotect(pte_t pte) {
  241. pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
  242. static inline pte_t pte_mkclean(pte_t pte) {
  243. pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  244. static inline pte_t pte_mkold(pte_t pte) {
  245. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  246. static inline pte_t pte_mkwrite(pte_t pte) {
  247. pte_val(pte) |= _PAGE_RW; return pte; }
  248. static inline pte_t pte_mkdirty(pte_t pte) {
  249. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  250. static inline pte_t pte_mkyoung(pte_t pte) {
  251. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  252. static inline pte_t pte_mkspecial(pte_t pte) {
  253. pte_val(pte) |= _PAGE_SPECIAL; return pte; }
  254. static inline pgprot_t pte_pgprot(pte_t pte)
  255. {
  256. return __pgprot(pte_val(pte) & PAGE_PROT_BITS);
  257. }
  258. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  259. {
  260. pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
  261. return pte;
  262. }
  263. /*
  264. * When flushing the tlb entry for a page, we also need to flush the hash
  265. * table entry. flush_hash_pages is assembler (for speed) in hashtable.S.
  266. */
  267. extern int flush_hash_pages(unsigned context, unsigned long va,
  268. unsigned long pmdval, int count);
  269. /* Add an HPTE to the hash table */
  270. extern void add_hash_page(unsigned context, unsigned long va,
  271. unsigned long pmdval);
  272. /* Flush an entry from the TLB/hash table */
  273. extern void flush_hash_entry(struct mm_struct *mm, pte_t *ptep,
  274. unsigned long address);
  275. /*
  276. * PTE updates. This function is called whenever an existing
  277. * valid PTE is updated. This does -not- include set_pte_at()
  278. * which nowadays only sets a new PTE.
  279. *
  280. * Depending on the type of MMU, we may need to use atomic updates
  281. * and the PTE may be either 32 or 64 bit wide. In the later case,
  282. * when using atomic updates, only the low part of the PTE is
  283. * accessed atomically.
  284. *
  285. * In addition, on 44x, we also maintain a global flag indicating
  286. * that an executable user mapping was modified, which is needed
  287. * to properly flush the virtually tagged instruction cache of
  288. * those implementations.
  289. */
  290. #ifndef CONFIG_PTE_64BIT
  291. static inline unsigned long pte_update(pte_t *p,
  292. unsigned long clr,
  293. unsigned long set)
  294. {
  295. #ifdef PTE_ATOMIC_UPDATES
  296. unsigned long old, tmp;
  297. __asm__ __volatile__("\
  298. 1: lwarx %0,0,%3\n\
  299. andc %1,%0,%4\n\
  300. or %1,%1,%5\n"
  301. PPC405_ERR77(0,%3)
  302. " stwcx. %1,0,%3\n\
  303. bne- 1b"
  304. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  305. : "r" (p), "r" (clr), "r" (set), "m" (*p)
  306. : "cc" );
  307. #else /* PTE_ATOMIC_UPDATES */
  308. unsigned long old = pte_val(*p);
  309. *p = __pte((old & ~clr) | set);
  310. #endif /* !PTE_ATOMIC_UPDATES */
  311. #ifdef CONFIG_44x
  312. if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC))
  313. icache_44x_need_flush = 1;
  314. #endif
  315. return old;
  316. }
  317. #else /* CONFIG_PTE_64BIT */
  318. static inline unsigned long long pte_update(pte_t *p,
  319. unsigned long clr,
  320. unsigned long set)
  321. {
  322. #ifdef PTE_ATOMIC_UPDATES
  323. unsigned long long old;
  324. unsigned long tmp;
  325. __asm__ __volatile__("\
  326. 1: lwarx %L0,0,%4\n\
  327. lwzx %0,0,%3\n\
  328. andc %1,%L0,%5\n\
  329. or %1,%1,%6\n"
  330. PPC405_ERR77(0,%3)
  331. " stwcx. %1,0,%4\n\
  332. bne- 1b"
  333. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  334. : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p)
  335. : "cc" );
  336. #else /* PTE_ATOMIC_UPDATES */
  337. unsigned long long old = pte_val(*p);
  338. *p = __pte((old & ~(unsigned long long)clr) | set);
  339. #endif /* !PTE_ATOMIC_UPDATES */
  340. #ifdef CONFIG_44x
  341. if ((old & _PAGE_USER) && (old & _PAGE_HWEXEC))
  342. icache_44x_need_flush = 1;
  343. #endif
  344. return old;
  345. }
  346. #endif /* CONFIG_PTE_64BIT */
  347. /*
  348. * 2.6 calls this without flushing the TLB entry; this is wrong
  349. * for our hash-based implementation, we fix that up here.
  350. */
  351. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  352. static inline int __ptep_test_and_clear_young(unsigned int context, unsigned long addr, pte_t *ptep)
  353. {
  354. unsigned long old;
  355. old = pte_update(ptep, _PAGE_ACCESSED, 0);
  356. #if _PAGE_HASHPTE != 0
  357. if (old & _PAGE_HASHPTE) {
  358. unsigned long ptephys = __pa(ptep) & PAGE_MASK;
  359. flush_hash_pages(context, addr, ptephys, 1);
  360. }
  361. #endif
  362. return (old & _PAGE_ACCESSED) != 0;
  363. }
  364. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  365. __ptep_test_and_clear_young((__vma)->vm_mm->context.id, __addr, __ptep)
  366. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  367. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  368. pte_t *ptep)
  369. {
  370. return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0));
  371. }
  372. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  373. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
  374. pte_t *ptep)
  375. {
  376. pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0);
  377. }
  378. static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
  379. unsigned long addr, pte_t *ptep)
  380. {
  381. ptep_set_wrprotect(mm, addr, ptep);
  382. }
  383. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
  384. {
  385. unsigned long bits = pte_val(entry) &
  386. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW |
  387. _PAGE_HWEXEC | _PAGE_EXEC);
  388. pte_update(ptep, 0, bits);
  389. }
  390. #define __HAVE_ARCH_PTE_SAME
  391. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
  392. /*
  393. * Note that on Book E processors, the pmd contains the kernel virtual
  394. * (lowmem) address of the pte page. The physical address is less useful
  395. * because everything runs with translation enabled (even the TLB miss
  396. * handler). On everything else the pmd contains the physical address
  397. * of the pte page. -- paulus
  398. */
  399. #ifndef CONFIG_BOOKE
  400. #define pmd_page_vaddr(pmd) \
  401. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  402. #define pmd_page(pmd) \
  403. (mem_map + (pmd_val(pmd) >> PAGE_SHIFT))
  404. #else
  405. #define pmd_page_vaddr(pmd) \
  406. ((unsigned long) (pmd_val(pmd) & PAGE_MASK))
  407. #define pmd_page(pmd) \
  408. pfn_to_page((__pa(pmd_val(pmd)) >> PAGE_SHIFT))
  409. #endif
  410. /* to find an entry in a kernel page-table-directory */
  411. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  412. /* to find an entry in a page-table-directory */
  413. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  414. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  415. /* Find an entry in the third-level page table.. */
  416. #define pte_index(address) \
  417. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  418. #define pte_offset_kernel(dir, addr) \
  419. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr))
  420. #define pte_offset_map(dir, addr) \
  421. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE0) + pte_index(addr))
  422. #define pte_offset_map_nested(dir, addr) \
  423. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE1) + pte_index(addr))
  424. #define pte_unmap(pte) kunmap_atomic(pte, KM_PTE0)
  425. #define pte_unmap_nested(pte) kunmap_atomic(pte, KM_PTE1)
  426. /*
  427. * Encode and decode a swap entry.
  428. * Note that the bits we use in a PTE for representing a swap entry
  429. * must not include the _PAGE_PRESENT bit, the _PAGE_FILE bit, or the
  430. *_PAGE_HASHPTE bit (if used). -- paulus
  431. */
  432. #define __swp_type(entry) ((entry).val & 0x1f)
  433. #define __swp_offset(entry) ((entry).val >> 5)
  434. #define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 5) })
  435. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 })
  436. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 })
  437. /* Encode and decode a nonlinear file mapping entry */
  438. #define PTE_FILE_MAX_BITS 29
  439. #define pte_to_pgoff(pte) (pte_val(pte) >> 3)
  440. #define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE })
  441. /*
  442. * No page table caches to initialise
  443. */
  444. #define pgtable_cache_init() do { } while (0)
  445. extern int get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep,
  446. pmd_t **pmdp);
  447. #endif /* !__ASSEMBLY__ */
  448. #endif /* _ASM_POWERPC_PGTABLE_PPC32_H */