mmu-book3e.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. #ifndef _ASM_POWERPC_MMU_BOOK3E_H_
  2. #define _ASM_POWERPC_MMU_BOOK3E_H_
  3. /*
  4. * Freescale Book-E/Book-3e (ISA 2.06+) MMU support
  5. */
  6. /* Book-3e defined page sizes */
  7. #define BOOK3E_PAGESZ_1K 0
  8. #define BOOK3E_PAGESZ_2K 1
  9. #define BOOK3E_PAGESZ_4K 2
  10. #define BOOK3E_PAGESZ_8K 3
  11. #define BOOK3E_PAGESZ_16K 4
  12. #define BOOK3E_PAGESZ_32K 5
  13. #define BOOK3E_PAGESZ_64K 6
  14. #define BOOK3E_PAGESZ_128K 7
  15. #define BOOK3E_PAGESZ_256K 8
  16. #define BOOK3E_PAGESZ_512K 9
  17. #define BOOK3E_PAGESZ_1M 10
  18. #define BOOK3E_PAGESZ_2M 11
  19. #define BOOK3E_PAGESZ_4M 12
  20. #define BOOK3E_PAGESZ_8M 13
  21. #define BOOK3E_PAGESZ_16M 14
  22. #define BOOK3E_PAGESZ_32M 15
  23. #define BOOK3E_PAGESZ_64M 16
  24. #define BOOK3E_PAGESZ_128M 17
  25. #define BOOK3E_PAGESZ_256M 18
  26. #define BOOK3E_PAGESZ_512M 19
  27. #define BOOK3E_PAGESZ_1GB 20
  28. #define BOOK3E_PAGESZ_2GB 21
  29. #define BOOK3E_PAGESZ_4GB 22
  30. #define BOOK3E_PAGESZ_8GB 23
  31. #define BOOK3E_PAGESZ_16GB 24
  32. #define BOOK3E_PAGESZ_32GB 25
  33. #define BOOK3E_PAGESZ_64GB 26
  34. #define BOOK3E_PAGESZ_128GB 27
  35. #define BOOK3E_PAGESZ_256GB 28
  36. #define BOOK3E_PAGESZ_512GB 29
  37. #define BOOK3E_PAGESZ_1TB 30
  38. #define BOOK3E_PAGESZ_2TB 31
  39. /* MAS registers bit definitions */
  40. #define MAS0_TLBSEL_MASK 0x30000000
  41. #define MAS0_TLBSEL_SHIFT 28
  42. #define MAS0_TLBSEL(x) (((x) << MAS0_TLBSEL_SHIFT) & MAS0_TLBSEL_MASK)
  43. #define MAS0_GET_TLBSEL(mas0) (((mas0) & MAS0_TLBSEL_MASK) >> \
  44. MAS0_TLBSEL_SHIFT)
  45. #define MAS0_ESEL_MASK 0x0FFF0000
  46. #define MAS0_ESEL_SHIFT 16
  47. #define MAS0_ESEL(x) (((x) << MAS0_ESEL_SHIFT) & MAS0_ESEL_MASK)
  48. #define MAS0_NV(x) ((x) & 0x00000FFF)
  49. #define MAS0_HES 0x00004000
  50. #define MAS0_WQ_ALLWAYS 0x00000000
  51. #define MAS0_WQ_COND 0x00001000
  52. #define MAS0_WQ_CLR_RSRV 0x00002000
  53. #define MAS1_VALID 0x80000000
  54. #define MAS1_IPROT 0x40000000
  55. #define MAS1_TID(x) (((x) << 16) & 0x3FFF0000)
  56. #define MAS1_IND 0x00002000
  57. #define MAS1_TS 0x00001000
  58. #define MAS1_TSIZE_MASK 0x00000f80
  59. #define MAS1_TSIZE_SHIFT 7
  60. #define MAS1_TSIZE(x) (((x) << MAS1_TSIZE_SHIFT) & MAS1_TSIZE_MASK)
  61. #define MAS1_GET_TSIZE(mas1) (((mas1) & MAS1_TSIZE_MASK) >> MAS1_TSIZE_SHIFT)
  62. #define MAS2_EPN (~0xFFFUL)
  63. #define MAS2_X0 0x00000040
  64. #define MAS2_X1 0x00000020
  65. #define MAS2_W 0x00000010
  66. #define MAS2_I 0x00000008
  67. #define MAS2_M 0x00000004
  68. #define MAS2_G 0x00000002
  69. #define MAS2_E 0x00000001
  70. #define MAS2_WIMGE_MASK 0x0000001f
  71. #define MAS2_EPN_MASK(size) (~0 << (size + 10))
  72. #define MAS2_VAL(addr, size, flags) ((addr) & MAS2_EPN_MASK(size) | (flags))
  73. #define MAS3_RPN 0xFFFFF000
  74. #define MAS3_U0 0x00000200
  75. #define MAS3_U1 0x00000100
  76. #define MAS3_U2 0x00000080
  77. #define MAS3_U3 0x00000040
  78. #define MAS3_UX 0x00000020
  79. #define MAS3_SX 0x00000010
  80. #define MAS3_UW 0x00000008
  81. #define MAS3_SW 0x00000004
  82. #define MAS3_UR 0x00000002
  83. #define MAS3_SR 0x00000001
  84. #define MAS3_BAP_MASK 0x0000003f
  85. #define MAS3_SPSIZE 0x0000003e
  86. #define MAS3_SPSIZE_SHIFT 1
  87. #define MAS4_TLBSEL_MASK MAS0_TLBSEL_MASK
  88. #define MAS4_TLBSELD(x) MAS0_TLBSEL(x)
  89. #define MAS4_INDD 0x00008000 /* Default IND */
  90. #define MAS4_TSIZED(x) MAS1_TSIZE(x)
  91. #define MAS4_X0D 0x00000040
  92. #define MAS4_X1D 0x00000020
  93. #define MAS4_WD 0x00000010
  94. #define MAS4_ID 0x00000008
  95. #define MAS4_MD 0x00000004
  96. #define MAS4_GD 0x00000002
  97. #define MAS4_ED 0x00000001
  98. #define MAS4_WIMGED_MASK 0x0000001f /* Default WIMGE */
  99. #define MAS4_WIMGED_SHIFT 0
  100. #define MAS4_VLED MAS4_X1D /* Default VLE */
  101. #define MAS4_ACMD 0x000000c0 /* Default ACM */
  102. #define MAS4_ACMD_SHIFT 6
  103. #define MAS4_TSIZED_MASK 0x00000f80 /* Default TSIZE */
  104. #define MAS4_TSIZED_SHIFT 7
  105. #define MAS5_SGS 0x80000000
  106. #define MAS6_SPID0 0x3FFF0000
  107. #define MAS6_SPID1 0x00007FFE
  108. #define MAS6_ISIZE(x) MAS1_TSIZE(x)
  109. #define MAS6_SAS 0x00000001
  110. #define MAS6_SPID MAS6_SPID0
  111. #define MAS6_SIND 0x00000002 /* Indirect page */
  112. #define MAS6_SIND_SHIFT 1
  113. #define MAS6_SPID_MASK 0x3fff0000
  114. #define MAS6_SPID_SHIFT 16
  115. #define MAS6_ISIZE_MASK 0x00000f80
  116. #define MAS6_ISIZE_SHIFT 7
  117. #define MAS7_RPN 0xFFFFFFFF
  118. #define MAS8_TGS 0x80000000 /* Guest space */
  119. #define MAS8_VF 0x40000000 /* Virtualization Fault */
  120. #define MAS8_TLPID 0x000000ff
  121. /* Bit definitions for MMUCFG */
  122. #define MMUCFG_MAVN 0x00000003 /* MMU Architecture Version Number */
  123. #define MMUCFG_MAVN_V1 0x00000000 /* v1.0 */
  124. #define MMUCFG_MAVN_V2 0x00000001 /* v2.0 */
  125. #define MMUCFG_NTLBS 0x0000000c /* Number of TLBs */
  126. #define MMUCFG_PIDSIZE 0x000007c0 /* PID Reg Size */
  127. #define MMUCFG_TWC 0x00008000 /* TLB Write Conditional (v2.0) */
  128. #define MMUCFG_LRAT 0x00010000 /* LRAT Supported (v2.0) */
  129. #define MMUCFG_RASIZE 0x00fe0000 /* Real Addr Size */
  130. #define MMUCFG_LPIDSIZE 0x0f000000 /* LPID Reg Size */
  131. /* Bit definitions for MMUCSR0 */
  132. #define MMUCSR0_TLB1FI 0x00000002 /* TLB1 Flash invalidate */
  133. #define MMUCSR0_TLB0FI 0x00000004 /* TLB0 Flash invalidate */
  134. #define MMUCSR0_TLB2FI 0x00000040 /* TLB2 Flash invalidate */
  135. #define MMUCSR0_TLB3FI 0x00000020 /* TLB3 Flash invalidate */
  136. #define MMUCSR0_TLBFI (MMUCSR0_TLB0FI | MMUCSR0_TLB1FI | \
  137. MMUCSR0_TLB2FI | MMUCSR0_TLB3FI)
  138. #define MMUCSR0_TLB0PS 0x00000780 /* TLB0 Page Size */
  139. #define MMUCSR0_TLB1PS 0x00007800 /* TLB1 Page Size */
  140. #define MMUCSR0_TLB2PS 0x00078000 /* TLB2 Page Size */
  141. #define MMUCSR0_TLB3PS 0x00780000 /* TLB3 Page Size */
  142. /* MMUCFG bits */
  143. #define MMUCFG_MAVN_NASK 0x00000003
  144. #define MMUCFG_MAVN_V1_0 0x00000000
  145. #define MMUCFG_MAVN_V2_0 0x00000001
  146. #define MMUCFG_NTLB_MASK 0x0000000c
  147. #define MMUCFG_NTLB_SHIFT 2
  148. #define MMUCFG_PIDSIZE_MASK 0x000007c0
  149. #define MMUCFG_PIDSIZE_SHIFT 6
  150. #define MMUCFG_TWC 0x00008000
  151. #define MMUCFG_LRAT 0x00010000
  152. #define MMUCFG_RASIZE_MASK 0x00fe0000
  153. #define MMUCFG_RASIZE_SHIFT 17
  154. #define MMUCFG_LPIDSIZE_MASK 0x0f000000
  155. #define MMUCFG_LPIDSIZE_SHIFT 24
  156. /* TLBnCFG encoding */
  157. #define TLBnCFG_N_ENTRY 0x00000fff /* number of entries */
  158. #define TLBnCFG_HES 0x00002000 /* HW select supported */
  159. #define TLBnCFG_IPROT 0x00008000 /* IPROT supported */
  160. #define TLBnCFG_GTWE 0x00010000 /* Guest can write */
  161. #define TLBnCFG_IND 0x00020000 /* IND entries supported */
  162. #define TLBnCFG_PT 0x00040000 /* Can load from page table */
  163. #define TLBnCFG_MINSIZE 0x00f00000 /* Minimum Page Size (v1.0) */
  164. #define TLBnCFG_MINSIZE_SHIFT 20
  165. #define TLBnCFG_MAXSIZE 0x000f0000 /* Maximum Page Size (v1.0) */
  166. #define TLBnCFG_MAXSIZE_SHIFT 16
  167. #define TLBnCFG_ASSOC 0xff000000 /* Associativity */
  168. #define TLBnCFG_ASSOC_SHIFT 24
  169. /* TLBnPS encoding */
  170. #define TLBnPS_4K 0x00000004
  171. #define TLBnPS_8K 0x00000008
  172. #define TLBnPS_16K 0x00000010
  173. #define TLBnPS_32K 0x00000020
  174. #define TLBnPS_64K 0x00000040
  175. #define TLBnPS_128K 0x00000080
  176. #define TLBnPS_256K 0x00000100
  177. #define TLBnPS_512K 0x00000200
  178. #define TLBnPS_1M 0x00000400
  179. #define TLBnPS_2M 0x00000800
  180. #define TLBnPS_4M 0x00001000
  181. #define TLBnPS_8M 0x00002000
  182. #define TLBnPS_16M 0x00004000
  183. #define TLBnPS_32M 0x00008000
  184. #define TLBnPS_64M 0x00010000
  185. #define TLBnPS_128M 0x00020000
  186. #define TLBnPS_256M 0x00040000
  187. #define TLBnPS_512M 0x00080000
  188. #define TLBnPS_1G 0x00100000
  189. #define TLBnPS_2G 0x00200000
  190. #define TLBnPS_4G 0x00400000
  191. #define TLBnPS_8G 0x00800000
  192. #define TLBnPS_16G 0x01000000
  193. #define TLBnPS_32G 0x02000000
  194. #define TLBnPS_64G 0x04000000
  195. #define TLBnPS_128G 0x08000000
  196. #define TLBnPS_256G 0x10000000
  197. /* tlbilx action encoding */
  198. #define TLBILX_T_ALL 0
  199. #define TLBILX_T_TID 1
  200. #define TLBILX_T_FULLMATCH 3
  201. #define TLBILX_T_CLASS0 4
  202. #define TLBILX_T_CLASS1 5
  203. #define TLBILX_T_CLASS2 6
  204. #define TLBILX_T_CLASS3 7
  205. #ifndef __ASSEMBLY__
  206. #include <asm/bug.h>
  207. extern unsigned int tlbcam_index;
  208. typedef struct {
  209. unsigned int id;
  210. unsigned int active;
  211. unsigned long vdso_base;
  212. #ifdef CONFIG_PPC_MM_SLICES
  213. u64 low_slices_psize; /* SLB page size encodings */
  214. u64 high_slices_psize; /* 4 bits per slice for now */
  215. u16 user_psize; /* page size index */
  216. #endif
  217. #ifdef CONFIG_PPC_64K_PAGES
  218. /* for 4K PTE fragment support */
  219. void *pte_frag;
  220. #endif
  221. } mm_context_t;
  222. /* Page size definitions, common between 32 and 64-bit
  223. *
  224. * shift : is the "PAGE_SHIFT" value for that page size
  225. * penc : is the pte encoding mask
  226. *
  227. */
  228. struct mmu_psize_def
  229. {
  230. unsigned int shift; /* number of bits */
  231. unsigned int enc; /* PTE encoding */
  232. unsigned int ind; /* Corresponding indirect page size shift */
  233. unsigned int flags;
  234. #define MMU_PAGE_SIZE_DIRECT 0x1 /* Supported as a direct size */
  235. #define MMU_PAGE_SIZE_INDIRECT 0x2 /* Supported as an indirect size */
  236. };
  237. extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
  238. static inline int shift_to_mmu_psize(unsigned int shift)
  239. {
  240. int psize;
  241. for (psize = 0; psize < MMU_PAGE_COUNT; ++psize)
  242. if (mmu_psize_defs[psize].shift == shift)
  243. return psize;
  244. return -1;
  245. }
  246. static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)
  247. {
  248. if (mmu_psize_defs[mmu_psize].shift)
  249. return mmu_psize_defs[mmu_psize].shift;
  250. BUG();
  251. }
  252. /* The page sizes use the same names as 64-bit hash but are
  253. * constants
  254. */
  255. #if defined(CONFIG_PPC_4K_PAGES)
  256. #define mmu_virtual_psize MMU_PAGE_4K
  257. #elif defined(CONFIG_PPC_64K_PAGES)
  258. #define mmu_virtual_psize MMU_PAGE_64K
  259. #else
  260. #error Unsupported page size
  261. #endif
  262. extern int mmu_linear_psize;
  263. extern int mmu_vmemmap_psize;
  264. struct tlb_core_data {
  265. /*
  266. * Per-core spinlock for e6500 TLB handlers (no tlbsrx.)
  267. * Must be the first struct element.
  268. */
  269. u8 lock;
  270. /* For software way selection, as on Freescale TLB1 */
  271. u8 esel_next, esel_max, esel_first;
  272. };
  273. #ifdef CONFIG_PPC64
  274. extern unsigned long linear_map_top;
  275. extern int book3e_htw_mode;
  276. #define PPC_HTW_NONE 0
  277. #define PPC_HTW_IBM 1
  278. #define PPC_HTW_E6500 2
  279. /*
  280. * 64-bit booke platforms don't load the tlb in the tlb miss handler code.
  281. * HUGETLB_NEED_PRELOAD handles this - it causes huge_ptep_set_access_flags to
  282. * return 1, indicating that the tlb requires preloading.
  283. */
  284. #define HUGETLB_NEED_PRELOAD
  285. #endif
  286. #endif /* !__ASSEMBLY__ */
  287. #endif /* _ASM_POWERPC_MMU_BOOK3E_H_ */