pgtable-ppc32.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. #endif /* __ASSEMBLY__ */
  12. /*
  13. * The PowerPC MMU uses a hash table containing PTEs, together with
  14. * a set of 16 segment registers (on 32-bit implementations), to define
  15. * the virtual to physical address mapping.
  16. *
  17. * We use the hash table as an extended TLB, i.e. a cache of currently
  18. * active mappings. We maintain a two-level page table tree, much
  19. * like that used by the i386, for the sake of the Linux memory
  20. * management code. Low-level assembler code in hashtable.S
  21. * (procedure hash_page) is responsible for extracting ptes from the
  22. * tree and putting them into the hash table when necessary, and
  23. * updating the accessed and modified bits in the page table tree.
  24. */
  25. /*
  26. * The PowerPC MPC8xx uses a TLB with hardware assisted, software tablewalk.
  27. * We also use the two level tables, but we can put the real bits in them
  28. * needed for the TLB and tablewalk. These definitions require Mx_CTR.PPM = 0,
  29. * Mx_CTR.PPCS = 0, and MD_CTR.TWAM = 1. The level 2 descriptor has
  30. * additional page protection (when Mx_CTR.PPCS = 1) that allows TLB hit
  31. * based upon user/super access. The TLB does not have accessed nor write
  32. * protect. We assume that if the TLB get loaded with an entry it is
  33. * accessed, and overload the changed bit for write protect. We use
  34. * two bits in the software pte that are supposed to be set to zero in
  35. * the TLB entry (24 and 25) for these indicators. Although the level 1
  36. * descriptor contains the guarded and writethrough/copyback bits, we can
  37. * set these at the page level since they get copied from the Mx_TWC
  38. * register when the TLB entry is loaded. We will use bit 27 for guard, since
  39. * that is where it exists in the MD_TWC, and bit 26 for writethrough.
  40. * These will get masked from the level 2 descriptor at TLB load time, and
  41. * copied to the MD_TWC before it gets loaded.
  42. * Large page sizes added. We currently support two sizes, 4K and 8M.
  43. * This also allows a TLB hander optimization because we can directly
  44. * load the PMD into MD_TWC. The 8M pages are only used for kernel
  45. * mapping of well known areas. The PMD (PGD) entries contain control
  46. * flags in addition to the address, so care must be taken that the
  47. * software no longer assumes these are only pointers.
  48. */
  49. /*
  50. * At present, all PowerPC 400-class processors share a similar TLB
  51. * architecture. The instruction and data sides share a unified,
  52. * 64-entry, fully-associative TLB which is maintained totally under
  53. * software control. In addition, the instruction side has a
  54. * hardware-managed, 4-entry, fully-associative TLB which serves as a
  55. * first level to the shared TLB. These two TLBs are known as the UTLB
  56. * and ITLB, respectively (see "mmu.h" for definitions).
  57. */
  58. /*
  59. * The normal case is that PTEs are 32-bits and we have a 1-page
  60. * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus
  61. *
  62. * For any >32-bit physical address platform, we can use the following
  63. * two level page table layout where the pgdir is 8KB and the MS 13 bits
  64. * are an index to the second level table. The combined pgdir/pmd first
  65. * level has 2048 entries and the second level has 512 64-bit PTE entries.
  66. * -Matt
  67. */
  68. /* PGDIR_SHIFT determines what a top-level page table entry can map */
  69. #define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT)
  70. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  71. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  72. /*
  73. * entries per page directory level: our page-table tree is two-level, so
  74. * we don't really have any PMD directory.
  75. */
  76. #define PTRS_PER_PTE (1 << PTE_SHIFT)
  77. #define PTRS_PER_PMD 1
  78. #define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))
  79. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  80. #define FIRST_USER_ADDRESS 0
  81. #define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
  82. #define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
  83. #define pte_ERROR(e) \
  84. printk("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \
  85. (unsigned long long)pte_val(e))
  86. #define pgd_ERROR(e) \
  87. printk("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e))
  88. /*
  89. * Just any arbitrary offset to the start of the vmalloc VM area: the
  90. * current 64MB value just means that there will be a 64MB "hole" after the
  91. * physical memory until the kernel virtual memory starts. That means that
  92. * any out-of-bounds memory accesses will hopefully be caught.
  93. * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  94. * area for the same reason. ;)
  95. *
  96. * We no longer map larger than phys RAM with the BATs so we don't have
  97. * to worry about the VMALLOC_OFFSET causing problems. We do have to worry
  98. * about clashes between our early calls to ioremap() that start growing down
  99. * from ioremap_base being run into the VM area allocations (growing upwards
  100. * from VMALLOC_START). For this reason we have ioremap_bot to check when
  101. * we actually run into our mappings setup in the early boot with the VM
  102. * system. This really does become a problem for machines with good amounts
  103. * of RAM. -- Cort
  104. */
  105. #define VMALLOC_OFFSET (0x1000000) /* 16M */
  106. #ifdef PPC_PIN_SIZE
  107. #define VMALLOC_START (((_ALIGN((long)high_memory, PPC_PIN_SIZE) + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
  108. #else
  109. #define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
  110. #endif
  111. #define VMALLOC_END ioremap_bot
  112. /*
  113. * Bits in a linux-style PTE. These match the bits in the
  114. * (hardware-defined) PowerPC PTE as closely as possible.
  115. */
  116. #if defined(CONFIG_40x)
  117. /* There are several potential gotchas here. The 40x hardware TLBLO
  118. field looks like this:
  119. 0 1 2 3 4 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  120. RPN..................... 0 0 EX WR ZSEL....... W I M G
  121. Where possible we make the Linux PTE bits match up with this
  122. - bits 20 and 21 must be cleared, because we use 4k pages (40x can
  123. support down to 1k pages), this is done in the TLBMiss exception
  124. handler.
  125. - We use only zones 0 (for kernel pages) and 1 (for user pages)
  126. of the 16 available. Bit 24-26 of the TLB are cleared in the TLB
  127. miss handler. Bit 27 is PAGE_USER, thus selecting the correct
  128. zone.
  129. - PRESENT *must* be in the bottom two bits because swap cache
  130. entries use the top 30 bits. Because 40x doesn't support SMP
  131. anyway, M is irrelevant so we borrow it for PAGE_PRESENT. Bit 30
  132. is cleared in the TLB miss handler before the TLB entry is loaded.
  133. - All other bits of the PTE are loaded into TLBLO without
  134. modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for
  135. software PTE bits. We actually use use bits 21, 24, 25, and
  136. 30 respectively for the software bits: ACCESSED, DIRTY, RW, and
  137. PRESENT.
  138. */
  139. /* Definitions for 40x embedded chips. */
  140. #define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */
  141. #define _PAGE_FILE 0x001 /* when !present: nonlinear file mapping */
  142. #define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */
  143. #define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */
  144. #define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */
  145. #define _PAGE_USER 0x010 /* matches one of the zone permission bits */
  146. #define _PAGE_RW 0x040 /* software: Writes permitted */
  147. #define _PAGE_DIRTY 0x080 /* software: dirty page */
  148. #define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */
  149. #define _PAGE_HWEXEC 0x200 /* hardware: EX permission */
  150. #define _PAGE_ACCESSED 0x400 /* software: R: page referenced */
  151. #define _PMD_PRESENT 0x400 /* PMD points to page of PTEs */
  152. #define _PMD_BAD 0x802
  153. #define _PMD_SIZE 0x0e0 /* size field, != 0 for large-page PMD entry */
  154. #define _PMD_SIZE_4M 0x0c0
  155. #define _PMD_SIZE_16M 0x0e0
  156. #define PMD_PAGE_SIZE(pmdval) (1024 << (((pmdval) & _PMD_SIZE) >> 4))
  157. #elif defined(CONFIG_44x)
  158. /*
  159. * Definitions for PPC440
  160. *
  161. * Because of the 3 word TLB entries to support 36-bit addressing,
  162. * the attribute are difficult to map in such a fashion that they
  163. * are easily loaded during exception processing. I decided to
  164. * organize the entry so the ERPN is the only portion in the
  165. * upper word of the PTE and the attribute bits below are packed
  166. * in as sensibly as they can be in the area below a 4KB page size
  167. * oriented RPN. This at least makes it easy to load the RPN and
  168. * ERPN fields in the TLB. -Matt
  169. *
  170. * Note that these bits preclude future use of a page size
  171. * less than 4KB.
  172. *
  173. *
  174. * PPC 440 core has following TLB attribute fields;
  175. *
  176. * TLB1:
  177. * 0 1 2 3 4 ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  178. * RPN................................. - - - - - - ERPN.......
  179. *
  180. * TLB2:
  181. * 0 1 2 3 4 ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  182. * - - - - - - U0 U1 U2 U3 W I M G E - UX UW UR SX SW SR
  183. *
  184. * There are some constrains and options, to decide mapping software bits
  185. * into TLB entry.
  186. *
  187. * - PRESENT *must* be in the bottom three bits because swap cache
  188. * entries use the top 29 bits for TLB2.
  189. *
  190. * - FILE *must* be in the bottom three bits because swap cache
  191. * entries use the top 29 bits for TLB2.
  192. *
  193. * - CACHE COHERENT bit (M) has no effect on PPC440 core, because it
  194. * doesn't support SMP. So we can use this as software bit, like
  195. * DIRTY.
  196. *
  197. * With the PPC 44x Linux implementation, the 0-11th LSBs of the PTE are used
  198. * for memory protection related functions (see PTE structure in
  199. * include/asm-ppc/mmu.h). The _PAGE_XXX definitions in this file map to the
  200. * above bits. Note that the bit values are CPU specific, not architecture
  201. * specific.
  202. *
  203. * The kernel PTE entry holds an arch-dependent swp_entry structure under
  204. * certain situations. In other words, in such situations some portion of
  205. * the PTE bits are used as a swp_entry. In the PPC implementation, the
  206. * 3-24th LSB are shared with swp_entry, however the 0-2nd three LSB still
  207. * hold protection values. That means the three protection bits are
  208. * reserved for both PTE and SWAP entry at the most significant three
  209. * LSBs.
  210. *
  211. * There are three protection bits available for SWAP entry:
  212. * _PAGE_PRESENT
  213. * _PAGE_FILE
  214. * _PAGE_HASHPTE (if HW has)
  215. *
  216. * So those three bits have to be inside of 0-2nd LSB of PTE.
  217. *
  218. */
  219. #define _PAGE_PRESENT 0x00000001 /* S: PTE valid */
  220. #define _PAGE_RW 0x00000002 /* S: Write permission */
  221. #define _PAGE_FILE 0x00000004 /* S: nonlinear file mapping */
  222. #define _PAGE_ACCESSED 0x00000008 /* S: Page referenced */
  223. #define _PAGE_HWWRITE 0x00000010 /* H: Dirty & RW */
  224. #define _PAGE_HWEXEC 0x00000020 /* H: Execute permission */
  225. #define _PAGE_USER 0x00000040 /* S: User page */
  226. #define _PAGE_ENDIAN 0x00000080 /* H: E bit */
  227. #define _PAGE_GUARDED 0x00000100 /* H: G bit */
  228. #define _PAGE_DIRTY 0x00000200 /* S: Page dirty */
  229. #define _PAGE_NO_CACHE 0x00000400 /* H: I bit */
  230. #define _PAGE_WRITETHRU 0x00000800 /* H: W bit */
  231. /* TODO: Add large page lowmem mapping support */
  232. #define _PMD_PRESENT 0
  233. #define _PMD_PRESENT_MASK (PAGE_MASK)
  234. #define _PMD_BAD (~PAGE_MASK)
  235. /* ERPN in a PTE never gets cleared, ignore it */
  236. #define _PTE_NONE_MASK 0xffffffff00000000ULL
  237. #elif defined(CONFIG_FSL_BOOKE)
  238. /*
  239. MMU Assist Register 3:
  240. 32 33 34 35 36 ... 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  241. RPN...................... 0 0 U0 U1 U2 U3 UX SX UW SW UR SR
  242. - PRESENT *must* be in the bottom three bits because swap cache
  243. entries use the top 29 bits.
  244. - FILE *must* be in the bottom three bits because swap cache
  245. entries use the top 29 bits.
  246. */
  247. /* Definitions for FSL Book-E Cores */
  248. #define _PAGE_PRESENT 0x00001 /* S: PTE contains a translation */
  249. #define _PAGE_USER 0x00002 /* S: User page (maps to UR) */
  250. #define _PAGE_FILE 0x00002 /* S: when !present: nonlinear file mapping */
  251. #define _PAGE_ACCESSED 0x00004 /* S: Page referenced */
  252. #define _PAGE_HWWRITE 0x00008 /* H: Dirty & RW, set in exception */
  253. #define _PAGE_RW 0x00010 /* S: Write permission */
  254. #define _PAGE_HWEXEC 0x00020 /* H: UX permission */
  255. #define _PAGE_ENDIAN 0x00040 /* H: E bit */
  256. #define _PAGE_GUARDED 0x00080 /* H: G bit */
  257. #define _PAGE_COHERENT 0x00100 /* H: M bit */
  258. #define _PAGE_NO_CACHE 0x00200 /* H: I bit */
  259. #define _PAGE_WRITETHRU 0x00400 /* H: W bit */
  260. #ifdef CONFIG_PTE_64BIT
  261. #define _PAGE_DIRTY 0x08000 /* S: Page dirty */
  262. /* ERPN in a PTE never gets cleared, ignore it */
  263. #define _PTE_NONE_MASK 0xffffffffffff0000ULL
  264. #else
  265. #define _PAGE_DIRTY 0x00800 /* S: Page dirty */
  266. #endif
  267. #define _PMD_PRESENT 0
  268. #define _PMD_PRESENT_MASK (PAGE_MASK)
  269. #define _PMD_BAD (~PAGE_MASK)
  270. #elif defined(CONFIG_8xx)
  271. /* Definitions for 8xx embedded chips. */
  272. #define _PAGE_PRESENT 0x0001 /* Page is valid */
  273. #define _PAGE_FILE 0x0002 /* when !present: nonlinear file mapping */
  274. #define _PAGE_NO_CACHE 0x0002 /* I: cache inhibit */
  275. #define _PAGE_SHARED 0x0004 /* No ASID (context) compare */
  276. /* These five software bits must be masked out when the entry is loaded
  277. * into the TLB.
  278. */
  279. #define _PAGE_EXEC 0x0008 /* software: i-cache coherency required */
  280. #define _PAGE_GUARDED 0x0010 /* software: guarded access */
  281. #define _PAGE_DIRTY 0x0020 /* software: page changed */
  282. #define _PAGE_RW 0x0040 /* software: user write access allowed */
  283. #define _PAGE_ACCESSED 0x0080 /* software: page referenced */
  284. /* Setting any bits in the nibble with the follow two controls will
  285. * require a TLB exception handler change. It is assumed unused bits
  286. * are always zero.
  287. */
  288. #define _PAGE_HWWRITE 0x0100 /* h/w write enable: never set in Linux PTE */
  289. #define _PAGE_USER 0x0800 /* One of the PP bits, the other is USER&~RW */
  290. #define _PMD_PRESENT 0x0001
  291. #define _PMD_BAD 0x0ff0
  292. #define _PMD_PAGE_MASK 0x000c
  293. #define _PMD_PAGE_8M 0x000c
  294. /*
  295. * The 8xx TLB miss handler allegedly sets _PAGE_ACCESSED in the PTE
  296. * for an address even if _PAGE_PRESENT is not set, as a performance
  297. * optimization. This is a bug if you ever want to use swap unless
  298. * _PAGE_ACCESSED is 2, which it isn't, or unless you have 8xx-specific
  299. * definitions for __swp_entry etc. below, which would be gross.
  300. * -- paulus
  301. */
  302. #define _PTE_NONE_MASK _PAGE_ACCESSED
  303. #else /* CONFIG_6xx */
  304. /* Definitions for 60x, 740/750, etc. */
  305. #define _PAGE_PRESENT 0x001 /* software: pte contains a translation */
  306. #define _PAGE_HASHPTE 0x002 /* hash_page has made an HPTE for this pte */
  307. #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
  308. #define _PAGE_USER 0x004 /* usermode access allowed */
  309. #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
  310. #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
  311. #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
  312. #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
  313. #define _PAGE_DIRTY 0x080 /* C: page changed */
  314. #define _PAGE_ACCESSED 0x100 /* R: page referenced */
  315. #define _PAGE_EXEC 0x200 /* software: i-cache coherency required */
  316. #define _PAGE_RW 0x400 /* software: user write access allowed */
  317. #define _PTE_NONE_MASK _PAGE_HASHPTE
  318. #define _PMD_PRESENT 0
  319. #define _PMD_PRESENT_MASK (PAGE_MASK)
  320. #define _PMD_BAD (~PAGE_MASK)
  321. #endif
  322. /*
  323. * Some bits are only used on some cpu families...
  324. */
  325. #ifndef _PAGE_HASHPTE
  326. #define _PAGE_HASHPTE 0
  327. #endif
  328. #ifndef _PTE_NONE_MASK
  329. #define _PTE_NONE_MASK 0
  330. #endif
  331. #ifndef _PAGE_SHARED
  332. #define _PAGE_SHARED 0
  333. #endif
  334. #ifndef _PAGE_HWWRITE
  335. #define _PAGE_HWWRITE 0
  336. #endif
  337. #ifndef _PAGE_HWEXEC
  338. #define _PAGE_HWEXEC 0
  339. #endif
  340. #ifndef _PAGE_EXEC
  341. #define _PAGE_EXEC 0
  342. #endif
  343. #ifndef _PMD_PRESENT_MASK
  344. #define _PMD_PRESENT_MASK _PMD_PRESENT
  345. #endif
  346. #ifndef _PMD_SIZE
  347. #define _PMD_SIZE 0
  348. #define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
  349. #endif
  350. #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
  351. /*
  352. * Note: the _PAGE_COHERENT bit automatically gets set in the hardware
  353. * PTE if CONFIG_SMP is defined (hash_page does this); there is no need
  354. * to have it in the Linux PTE, and in fact the bit could be reused for
  355. * another purpose. -- paulus.
  356. */
  357. #ifdef CONFIG_44x
  358. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_GUARDED)
  359. #else
  360. #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
  361. #endif
  362. #define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE)
  363. #define _PAGE_KERNEL (_PAGE_BASE | _PAGE_SHARED | _PAGE_WRENABLE)
  364. #ifdef CONFIG_PPC_STD_MMU
  365. /* On standard PPC MMU, no user access implies kernel read/write access,
  366. * so to write-protect kernel memory we must turn on user access */
  367. #define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED | _PAGE_USER)
  368. #else
  369. #define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED)
  370. #endif
  371. #define _PAGE_IO (_PAGE_KERNEL | _PAGE_NO_CACHE | _PAGE_GUARDED)
  372. #define _PAGE_RAM (_PAGE_KERNEL | _PAGE_HWEXEC)
  373. #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH)
  374. /* We want the debuggers to be able to set breakpoints anywhere, so
  375. * don't write protect the kernel text */
  376. #define _PAGE_RAM_TEXT _PAGE_RAM
  377. #else
  378. #define _PAGE_RAM_TEXT (_PAGE_KERNEL_RO | _PAGE_HWEXEC)
  379. #endif
  380. #define PAGE_NONE __pgprot(_PAGE_BASE)
  381. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
  382. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  383. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
  384. #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
  385. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
  386. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
  387. #define PAGE_KERNEL __pgprot(_PAGE_RAM)
  388. #define PAGE_KERNEL_NOCACHE __pgprot(_PAGE_IO)
  389. /*
  390. * The PowerPC can only do execute protection on a segment (256MB) basis,
  391. * not on a page basis. So we consider execute permission the same as read.
  392. * Also, write permissions imply read permissions.
  393. * This is the closest we can get..
  394. */
  395. #define __P000 PAGE_NONE
  396. #define __P001 PAGE_READONLY_X
  397. #define __P010 PAGE_COPY
  398. #define __P011 PAGE_COPY_X
  399. #define __P100 PAGE_READONLY
  400. #define __P101 PAGE_READONLY_X
  401. #define __P110 PAGE_COPY
  402. #define __P111 PAGE_COPY_X
  403. #define __S000 PAGE_NONE
  404. #define __S001 PAGE_READONLY_X
  405. #define __S010 PAGE_SHARED
  406. #define __S011 PAGE_SHARED_X
  407. #define __S100 PAGE_READONLY
  408. #define __S101 PAGE_READONLY_X
  409. #define __S110 PAGE_SHARED
  410. #define __S111 PAGE_SHARED_X
  411. #ifndef __ASSEMBLY__
  412. /* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
  413. * kernel without large page PMD support */
  414. extern unsigned long bad_call_to_PMD_PAGE_SIZE(void);
  415. /*
  416. * Conversions between PTE values and page frame numbers.
  417. */
  418. /* in some case we want to additionaly adjust where the pfn is in the pte to
  419. * allow room for more flags */
  420. #if defined(CONFIG_FSL_BOOKE) && defined(CONFIG_PTE_64BIT)
  421. #define PFN_SHIFT_OFFSET (PAGE_SHIFT + 8)
  422. #else
  423. #define PFN_SHIFT_OFFSET (PAGE_SHIFT)
  424. #endif
  425. #define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET)
  426. #define pte_page(x) pfn_to_page(pte_pfn(x))
  427. #define pfn_pte(pfn, prot) __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) |\
  428. pgprot_val(prot))
  429. #define mk_pte(page, prot) pfn_pte(page_to_pfn(page), prot)
  430. #endif /* __ASSEMBLY__ */
  431. #define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0)
  432. #define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT)
  433. #define pte_clear(mm,addr,ptep) do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0)
  434. #define pmd_none(pmd) (!pmd_val(pmd))
  435. #define pmd_bad(pmd) (pmd_val(pmd) & _PMD_BAD)
  436. #define pmd_present(pmd) (pmd_val(pmd) & _PMD_PRESENT_MASK)
  437. #define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0)
  438. #ifndef __ASSEMBLY__
  439. /*
  440. * The following only work if pte_present() is true.
  441. * Undefined behaviour if not..
  442. */
  443. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
  444. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  445. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  446. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  447. static inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; }
  448. static inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; }
  449. static inline pte_t pte_wrprotect(pte_t pte) {
  450. pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
  451. static inline pte_t pte_mkclean(pte_t pte) {
  452. pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  453. static inline pte_t pte_mkold(pte_t pte) {
  454. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  455. static inline pte_t pte_mkwrite(pte_t pte) {
  456. pte_val(pte) |= _PAGE_RW; return pte; }
  457. static inline pte_t pte_mkdirty(pte_t pte) {
  458. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  459. static inline pte_t pte_mkyoung(pte_t pte) {
  460. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  461. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  462. {
  463. pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
  464. return pte;
  465. }
  466. /*
  467. * When flushing the tlb entry for a page, we also need to flush the hash
  468. * table entry. flush_hash_pages is assembler (for speed) in hashtable.S.
  469. */
  470. extern int flush_hash_pages(unsigned context, unsigned long va,
  471. unsigned long pmdval, int count);
  472. /* Add an HPTE to the hash table */
  473. extern void add_hash_page(unsigned context, unsigned long va,
  474. unsigned long pmdval);
  475. /*
  476. * Atomic PTE updates.
  477. *
  478. * pte_update clears and sets bit atomically, and returns
  479. * the old pte value. In the 64-bit PTE case we lock around the
  480. * low PTE word since we expect ALL flag bits to be there
  481. */
  482. #ifndef CONFIG_PTE_64BIT
  483. static inline unsigned long pte_update(pte_t *p, unsigned long clr,
  484. unsigned long set)
  485. {
  486. unsigned long old, tmp;
  487. __asm__ __volatile__("\
  488. 1: lwarx %0,0,%3\n\
  489. andc %1,%0,%4\n\
  490. or %1,%1,%5\n"
  491. PPC405_ERR77(0,%3)
  492. " stwcx. %1,0,%3\n\
  493. bne- 1b"
  494. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  495. : "r" (p), "r" (clr), "r" (set), "m" (*p)
  496. : "cc" );
  497. return old;
  498. }
  499. #else
  500. static inline unsigned long long pte_update(pte_t *p, unsigned long clr,
  501. unsigned long set)
  502. {
  503. unsigned long long old;
  504. unsigned long tmp;
  505. __asm__ __volatile__("\
  506. 1: lwarx %L0,0,%4\n\
  507. lwzx %0,0,%3\n\
  508. andc %1,%L0,%5\n\
  509. or %1,%1,%6\n"
  510. PPC405_ERR77(0,%3)
  511. " stwcx. %1,0,%4\n\
  512. bne- 1b"
  513. : "=&r" (old), "=&r" (tmp), "=m" (*p)
  514. : "r" (p), "r" ((unsigned long)(p) + 4), "r" (clr), "r" (set), "m" (*p)
  515. : "cc" );
  516. return old;
  517. }
  518. #endif
  519. /*
  520. * set_pte stores a linux PTE into the linux page table.
  521. * On machines which use an MMU hash table we avoid changing the
  522. * _PAGE_HASHPTE bit.
  523. */
  524. static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  525. pte_t *ptep, pte_t pte)
  526. {
  527. #if _PAGE_HASHPTE != 0
  528. pte_update(ptep, ~_PAGE_HASHPTE, pte_val(pte) & ~_PAGE_HASHPTE);
  529. #else
  530. *ptep = pte;
  531. #endif
  532. }
  533. /*
  534. * 2.6 calles this without flushing the TLB entry, this is wrong
  535. * for our hash-based implementation, we fix that up here
  536. */
  537. #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
  538. static inline int __ptep_test_and_clear_young(unsigned int context, unsigned long addr, pte_t *ptep)
  539. {
  540. unsigned long old;
  541. old = pte_update(ptep, _PAGE_ACCESSED, 0);
  542. #if _PAGE_HASHPTE != 0
  543. if (old & _PAGE_HASHPTE) {
  544. unsigned long ptephys = __pa(ptep) & PAGE_MASK;
  545. flush_hash_pages(context, addr, ptephys, 1);
  546. }
  547. #endif
  548. return (old & _PAGE_ACCESSED) != 0;
  549. }
  550. #define ptep_test_and_clear_young(__vma, __addr, __ptep) \
  551. __ptep_test_and_clear_young((__vma)->vm_mm->context.id, __addr, __ptep)
  552. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  553. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  554. pte_t *ptep)
  555. {
  556. return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0));
  557. }
  558. #define __HAVE_ARCH_PTEP_SET_WRPROTECT
  559. static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
  560. pte_t *ptep)
  561. {
  562. pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0);
  563. }
  564. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  565. static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry, int dirty)
  566. {
  567. unsigned long bits = pte_val(entry) &
  568. (_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW);
  569. pte_update(ptep, 0, bits);
  570. }
  571. #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
  572. ({ \
  573. int __changed = !pte_same(*(__ptep), __entry); \
  574. if (__changed) { \
  575. __ptep_set_access_flags(__ptep, __entry, __dirty); \
  576. flush_tlb_page_nohash(__vma, __address); \
  577. } \
  578. __changed; \
  579. })
  580. /*
  581. * Macro to mark a page protection value as "uncacheable".
  582. */
  583. #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_NO_CACHE | _PAGE_GUARDED))
  584. struct file;
  585. extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  586. unsigned long size, pgprot_t vma_prot);
  587. #define __HAVE_PHYS_MEM_ACCESS_PROT
  588. #define __HAVE_ARCH_PTE_SAME
  589. #define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)
  590. /*
  591. * Note that on Book E processors, the pmd contains the kernel virtual
  592. * (lowmem) address of the pte page. The physical address is less useful
  593. * because everything runs with translation enabled (even the TLB miss
  594. * handler). On everything else the pmd contains the physical address
  595. * of the pte page. -- paulus
  596. */
  597. #ifndef CONFIG_BOOKE
  598. #define pmd_page_vaddr(pmd) \
  599. ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  600. #define pmd_page(pmd) \
  601. (mem_map + (pmd_val(pmd) >> PAGE_SHIFT))
  602. #else
  603. #define pmd_page_vaddr(pmd) \
  604. ((unsigned long) (pmd_val(pmd) & PAGE_MASK))
  605. #define pmd_page(pmd) \
  606. (mem_map + (__pa(pmd_val(pmd)) >> PAGE_SHIFT))
  607. #endif
  608. /* to find an entry in a kernel page-table-directory */
  609. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  610. /* to find an entry in a page-table-directory */
  611. #define pgd_index(address) ((address) >> PGDIR_SHIFT)
  612. #define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
  613. /* Find an entry in the third-level page table.. */
  614. #define pte_index(address) \
  615. (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  616. #define pte_offset_kernel(dir, addr) \
  617. ((pte_t *) pmd_page_vaddr(*(dir)) + pte_index(addr))
  618. #define pte_offset_map(dir, addr) \
  619. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE0) + pte_index(addr))
  620. #define pte_offset_map_nested(dir, addr) \
  621. ((pte_t *) kmap_atomic(pmd_page(*(dir)), KM_PTE1) + pte_index(addr))
  622. #define pte_unmap(pte) kunmap_atomic(pte, KM_PTE0)
  623. #define pte_unmap_nested(pte) kunmap_atomic(pte, KM_PTE1)
  624. /*
  625. * Encode and decode a swap entry.
  626. * Note that the bits we use in a PTE for representing a swap entry
  627. * must not include the _PAGE_PRESENT bit, the _PAGE_FILE bit, or the
  628. *_PAGE_HASHPTE bit (if used). -- paulus
  629. */
  630. #define __swp_type(entry) ((entry).val & 0x1f)
  631. #define __swp_offset(entry) ((entry).val >> 5)
  632. #define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 5) })
  633. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 })
  634. #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 })
  635. /* Encode and decode a nonlinear file mapping entry */
  636. #define PTE_FILE_MAX_BITS 29
  637. #define pte_to_pgoff(pte) (pte_val(pte) >> 3)
  638. #define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE })
  639. /*
  640. * No page table caches to initialise
  641. */
  642. #define pgtable_cache_init() do { } while (0)
  643. extern int get_pteptr(struct mm_struct *mm, unsigned long addr, pte_t **ptep,
  644. pmd_t **pmdp);
  645. #endif /* !__ASSEMBLY__ */
  646. #endif /* _ASM_POWERPC_PGTABLE_PPC32_H */