pgtable-ppc32.h 27 KB

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