mmu.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*
  2. * PowerPC memory management structures
  3. */
  4. #ifndef _PPC_MMU_H_
  5. #define _PPC_MMU_H_
  6. #ifndef __ASSEMBLY__
  7. /* Hardware Page Table Entry */
  8. typedef struct _PTE {
  9. #ifdef CONFIG_PPC64BRIDGE
  10. unsigned long long vsid:52;
  11. unsigned long api:5;
  12. unsigned long :5;
  13. unsigned long h:1;
  14. unsigned long v:1;
  15. unsigned long long rpn:52;
  16. #else /* CONFIG_PPC64BRIDGE */
  17. unsigned long v:1; /* Entry is valid */
  18. unsigned long vsid:24; /* Virtual segment identifier */
  19. unsigned long h:1; /* Hash algorithm indicator */
  20. unsigned long api:6; /* Abbreviated page index */
  21. unsigned long rpn:20; /* Real (physical) page number */
  22. #endif /* CONFIG_PPC64BRIDGE */
  23. unsigned long :3; /* Unused */
  24. unsigned long r:1; /* Referenced */
  25. unsigned long c:1; /* Changed */
  26. unsigned long w:1; /* Write-thru cache mode */
  27. unsigned long i:1; /* Cache inhibited */
  28. unsigned long m:1; /* Memory coherence */
  29. unsigned long g:1; /* Guarded */
  30. unsigned long :1; /* Unused */
  31. unsigned long pp:2; /* Page protection */
  32. } PTE;
  33. /* Values for PP (assumes Ks=0, Kp=1) */
  34. #define PP_RWXX 0 /* Supervisor read/write, User none */
  35. #define PP_RWRX 1 /* Supervisor read/write, User read */
  36. #define PP_RWRW 2 /* Supervisor read/write, User read/write */
  37. #define PP_RXRX 3 /* Supervisor read, User read */
  38. /* Segment Register */
  39. typedef struct _SEGREG {
  40. unsigned long t:1; /* Normal or I/O type */
  41. unsigned long ks:1; /* Supervisor 'key' (normally 0) */
  42. unsigned long kp:1; /* User 'key' (normally 1) */
  43. unsigned long n:1; /* No-execute */
  44. unsigned long :4; /* Unused */
  45. unsigned long vsid:24; /* Virtual Segment Identifier */
  46. } SEGREG;
  47. /* Block Address Translation (BAT) Registers */
  48. typedef struct _P601_BATU { /* Upper part of BAT for 601 processor */
  49. unsigned long bepi:15; /* Effective page index (virtual address) */
  50. unsigned long :8; /* unused */
  51. unsigned long w:1;
  52. unsigned long i:1; /* Cache inhibit */
  53. unsigned long m:1; /* Memory coherence */
  54. unsigned long ks:1; /* Supervisor key (normally 0) */
  55. unsigned long kp:1; /* User key (normally 1) */
  56. unsigned long pp:2; /* Page access protections */
  57. } P601_BATU;
  58. typedef struct _BATU { /* Upper part of BAT (all except 601) */
  59. #ifdef CONFIG_PPC64BRIDGE
  60. unsigned long long bepi:47;
  61. #else /* CONFIG_PPC64BRIDGE */
  62. unsigned long bepi:15; /* Effective page index (virtual address) */
  63. #endif /* CONFIG_PPC64BRIDGE */
  64. unsigned long :4; /* Unused */
  65. unsigned long bl:11; /* Block size mask */
  66. unsigned long vs:1; /* Supervisor valid */
  67. unsigned long vp:1; /* User valid */
  68. } BATU;
  69. typedef struct _P601_BATL { /* Lower part of BAT for 601 processor */
  70. unsigned long brpn:15; /* Real page index (physical address) */
  71. unsigned long :10; /* Unused */
  72. unsigned long v:1; /* Valid bit */
  73. unsigned long bl:6; /* Block size mask */
  74. } P601_BATL;
  75. typedef struct _BATL { /* Lower part of BAT (all except 601) */
  76. #ifdef CONFIG_PPC64BRIDGE
  77. unsigned long long brpn:47;
  78. #else /* CONFIG_PPC64BRIDGE */
  79. unsigned long brpn:15; /* Real page index (physical address) */
  80. #endif /* CONFIG_PPC64BRIDGE */
  81. unsigned long :10; /* Unused */
  82. unsigned long w:1; /* Write-thru cache */
  83. unsigned long i:1; /* Cache inhibit */
  84. unsigned long m:1; /* Memory coherence */
  85. unsigned long g:1; /* Guarded (MBZ in IBAT) */
  86. unsigned long :1; /* Unused */
  87. unsigned long pp:2; /* Page access protections */
  88. } BATL;
  89. typedef struct _BAT {
  90. BATU batu; /* Upper register */
  91. BATL batl; /* Lower register */
  92. } BAT;
  93. typedef struct _P601_BAT {
  94. P601_BATU batu; /* Upper register */
  95. P601_BATL batl; /* Lower register */
  96. } P601_BAT;
  97. /*
  98. * Simulated two-level MMU. This structure is used by the kernel
  99. * to keep track of MMU mappings and is used to update/maintain
  100. * the hardware HASH table which is really a cache of mappings.
  101. *
  102. * The simulated structures mimic the hardware available on other
  103. * platforms, notably the 80x86 and 680x0.
  104. */
  105. typedef struct _pte {
  106. unsigned long page_num:20;
  107. unsigned long flags:12; /* Page flags (some unused bits) */
  108. } pte;
  109. #define PD_SHIFT (10+12) /* Page directory */
  110. #define PD_MASK 0x02FF
  111. #define PT_SHIFT (12) /* Page Table */
  112. #define PT_MASK 0x02FF
  113. #define PG_SHIFT (12) /* Page Entry */
  114. /* MMU context */
  115. typedef struct _MMU_context {
  116. SEGREG segs[16]; /* Segment registers */
  117. pte **pmap; /* Two-level page-map structure */
  118. } MMU_context;
  119. extern void _tlbie(unsigned long va); /* invalidate a TLB entry */
  120. extern void _tlbia(void); /* invalidate all TLB entries */
  121. #ifdef CONFIG_ADDR_MAP
  122. extern void init_addr_map(void);
  123. #endif
  124. typedef enum {
  125. IBAT0 = 0, IBAT1, IBAT2, IBAT3,
  126. DBAT0, DBAT1, DBAT2, DBAT3,
  127. #ifdef CONFIG_HIGH_BATS
  128. IBAT4, IBAT5, IBAT6, IBAT7,
  129. DBAT4, DBAT5, DBAT6, DBAT7
  130. #endif
  131. } ppc_bat_t;
  132. extern int read_bat(ppc_bat_t bat, unsigned long *upper, unsigned long *lower);
  133. extern int write_bat(ppc_bat_t bat, unsigned long upper, unsigned long lower);
  134. extern void print_bats(void);
  135. #endif /* __ASSEMBLY__ */
  136. #define BATU_VS 0x00000002
  137. #define BATU_VP 0x00000001
  138. #define BATU_INVALID 0x00000000
  139. #define BATL_WRITETHROUGH 0x00000040
  140. #define BATL_CACHEINHIBIT 0x00000020
  141. #define BATL_MEMCOHERENCE 0x00000010
  142. #define BATL_GUARDEDSTORAGE 0x00000008
  143. #define BATL_NO_ACCESS 0x00000000
  144. #define BATL_PP_MSK 0x00000003
  145. #define BATL_PP_00 0x00000000 /* No access */
  146. #define BATL_PP_01 0x00000001 /* Read-only */
  147. #define BATL_PP_10 0x00000002 /* Read-write */
  148. #define BATL_PP_11 0x00000003
  149. #define BATL_PP_NO_ACCESS BATL_PP_00
  150. #define BATL_PP_RO BATL_PP_01
  151. #define BATL_PP_RW BATL_PP_10
  152. /* BAT Block size values */
  153. #define BATU_BL_128K 0x00000000
  154. #define BATU_BL_256K 0x00000004
  155. #define BATU_BL_512K 0x0000000c
  156. #define BATU_BL_1M 0x0000001c
  157. #define BATU_BL_2M 0x0000003c
  158. #define BATU_BL_4M 0x0000007c
  159. #define BATU_BL_8M 0x000000fc
  160. #define BATU_BL_16M 0x000001fc
  161. #define BATU_BL_32M 0x000003fc
  162. #define BATU_BL_64M 0x000007fc
  163. #define BATU_BL_128M 0x00000ffc
  164. #define BATU_BL_256M 0x00001ffc
  165. /* Block lengths for processors that support extended block length */
  166. #ifdef HID0_XBSEN
  167. #define BATU_BL_512M 0x00003ffc
  168. #define BATU_BL_1G 0x00007ffc
  169. #define BATU_BL_2G 0x0000fffc
  170. #define BATU_BL_4G 0x0001fffc
  171. #define BATU_BL_MAX BATU_BL_4G
  172. #else
  173. #define BATU_BL_MAX BATU_BL_256M
  174. #endif
  175. /* BAT Access Protection */
  176. #define BPP_XX 0x00 /* No access */
  177. #define BPP_RX 0x01 /* Read only */
  178. #define BPP_RW 0x02 /* Read/write */
  179. /* Macros to get values from BATs, once data is in the BAT register format */
  180. #define BATU_VALID(x) (x & 0x3)
  181. #define BATU_VADDR(x) (x & 0xfffe0000)
  182. #define BATL_PADDR(x) ((phys_addr_t)((x & 0xfffe0000) \
  183. | ((x & 0x0e00ULL) << 24) \
  184. | ((x & 0x04ULL) << 30)))
  185. #define BATU_SIZE(x) (1ULL << (fls((x & BATU_BL_MAX) >> 2) + 17))
  186. /* bytes into BATU_BL */
  187. #define TO_BATU_BL(x) \
  188. (u32)((((1ull << __ilog2_u64((u64)x)) / (128 * 1024)) - 1) * 4)
  189. /* Used to set up SDR1 register */
  190. #define HASH_TABLE_SIZE_64K 0x00010000
  191. #define HASH_TABLE_SIZE_128K 0x00020000
  192. #define HASH_TABLE_SIZE_256K 0x00040000
  193. #define HASH_TABLE_SIZE_512K 0x00080000
  194. #define HASH_TABLE_SIZE_1M 0x00100000
  195. #define HASH_TABLE_SIZE_2M 0x00200000
  196. #define HASH_TABLE_SIZE_4M 0x00400000
  197. #define HASH_TABLE_MASK_64K 0x000
  198. #define HASH_TABLE_MASK_128K 0x001
  199. #define HASH_TABLE_MASK_256K 0x003
  200. #define HASH_TABLE_MASK_512K 0x007
  201. #define HASH_TABLE_MASK_1M 0x00F
  202. #define HASH_TABLE_MASK_2M 0x01F
  203. #define HASH_TABLE_MASK_4M 0x03F
  204. /* Control/status registers for the MPC8xx.
  205. * A write operation to these registers causes serialized access.
  206. * During software tablewalk, the registers used perform mask/shift-add
  207. * operations when written/read. A TLB entry is created when the Mx_RPN
  208. * is written, and the contents of several registers are used to
  209. * create the entry.
  210. */
  211. #define MI_CTR 784 /* Instruction TLB control register */
  212. #define MI_GPM 0x80000000 /* Set domain manager mode */
  213. #define MI_PPM 0x40000000 /* Set subpage protection */
  214. #define MI_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  215. #define MI_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  216. #define MI_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  217. #define MI_IDXMASK 0x00001f00 /* TLB index to be loaded */
  218. #define MI_RESETVAL 0x00000000 /* Value of register at reset */
  219. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  220. * Ks = 0, Kp = 1.
  221. */
  222. #define MI_AP 786
  223. #define MI_Ks 0x80000000 /* Should not be set */
  224. #define MI_Kp 0x40000000 /* Should always be set */
  225. /* The effective page number register. When read, contains the information
  226. * about the last instruction TLB miss. When MI_RPN is written, bits in
  227. * this register are used to create the TLB entry.
  228. */
  229. #define MI_EPN 787
  230. #define MI_EPNMASK 0xfffff000 /* Effective page number for entry */
  231. #define MI_EVALID 0x00000200 /* Entry is valid */
  232. #define MI_ASIDMASK 0x0000000f /* ASID match value */
  233. /* Reset value is undefined */
  234. /* A "level 1" or "segment" or whatever you want to call it register.
  235. * For the instruction TLB, it contains bits that get loaded into the
  236. * TLB entry when the MI_RPN is written.
  237. */
  238. #define MI_TWC 789
  239. #define MI_APG 0x000001e0 /* Access protection group (0) */
  240. #define MI_GUARDED 0x00000010 /* Guarded storage */
  241. #define MI_PSMASK 0x0000000c /* Mask of page size bits */
  242. #define MI_PS8MEG 0x0000000c /* 8M page size */
  243. #define MI_PS512K 0x00000004 /* 512K page size */
  244. #define MI_PS4K_16K 0x00000000 /* 4K or 16K page size */
  245. #define MI_SVALID 0x00000001 /* Segment entry is valid */
  246. /* Reset value is undefined */
  247. /* Real page number. Defined by the pte. Writing this register
  248. * causes a TLB entry to be created for the instruction TLB, using
  249. * additional information from the MI_EPN, and MI_TWC registers.
  250. */
  251. #define MI_RPN 790
  252. /* Define an RPN value for mapping kernel memory to large virtual
  253. * pages for boot initialization. This has real page number of 0,
  254. * large page size, shared page, cache enabled, and valid.
  255. * Also mark all subpages valid and write access.
  256. */
  257. #define MI_BOOTINIT 0x000001fd
  258. #define MD_CTR 792 /* Data TLB control register */
  259. #define MD_GPM 0x80000000 /* Set domain manager mode */
  260. #define MD_PPM 0x40000000 /* Set subpage protection */
  261. #define MD_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  262. #define MD_WTDEF 0x10000000 /* Set writethrough when MMU dis */
  263. #define MD_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  264. #define MD_TWAM 0x04000000 /* Use 4K page hardware assist */
  265. #define MD_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  266. #define MD_IDXMASK 0x00001f00 /* TLB index to be loaded */
  267. #define MD_RESETVAL 0x04000000 /* Value of register at reset */
  268. #define M_CASID 793 /* Address space ID (context) to match */
  269. #define MC_ASIDMASK 0x0000000f /* Bits used for ASID value */
  270. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  271. * Ks = 0, Kp = 1.
  272. */
  273. #define MD_AP 794
  274. #define MD_Ks 0x80000000 /* Should not be set */
  275. #define MD_Kp 0x40000000 /* Should always be set */
  276. /* The effective page number register. When read, contains the information
  277. * about the last instruction TLB miss. When MD_RPN is written, bits in
  278. * this register are used to create the TLB entry.
  279. */
  280. #define MD_EPN 795
  281. #define MD_EPNMASK 0xfffff000 /* Effective page number for entry */
  282. #define MD_EVALID 0x00000200 /* Entry is valid */
  283. #define MD_ASIDMASK 0x0000000f /* ASID match value */
  284. /* Reset value is undefined */
  285. /* The pointer to the base address of the first level page table.
  286. * During a software tablewalk, reading this register provides the address
  287. * of the entry associated with MD_EPN.
  288. */
  289. #define M_TWB 796
  290. #define M_L1TB 0xfffff000 /* Level 1 table base address */
  291. #define M_L1INDX 0x00000ffc /* Level 1 index, when read */
  292. /* Reset value is undefined */
  293. /* A "level 1" or "segment" or whatever you want to call it register.
  294. * For the data TLB, it contains bits that get loaded into the TLB entry
  295. * when the MD_RPN is written. It is also provides the hardware assist
  296. * for finding the PTE address during software tablewalk.
  297. */
  298. #define MD_TWC 797
  299. #define MD_L2TB 0xfffff000 /* Level 2 table base address */
  300. #define MD_L2INDX 0xfffffe00 /* Level 2 index (*pte), when read */
  301. #define MD_APG 0x000001e0 /* Access protection group (0) */
  302. #define MD_GUARDED 0x00000010 /* Guarded storage */
  303. #define MD_PSMASK 0x0000000c /* Mask of page size bits */
  304. #define MD_PS8MEG 0x0000000c /* 8M page size */
  305. #define MD_PS512K 0x00000004 /* 512K page size */
  306. #define MD_PS4K_16K 0x00000000 /* 4K or 16K page size */
  307. #define MD_WT 0x00000002 /* Use writethrough page attribute */
  308. #define MD_SVALID 0x00000001 /* Segment entry is valid */
  309. /* Reset value is undefined */
  310. /* Real page number. Defined by the pte. Writing this register
  311. * causes a TLB entry to be created for the data TLB, using
  312. * additional information from the MD_EPN, and MD_TWC registers.
  313. */
  314. #define MD_RPN 798
  315. /* This is a temporary storage register that could be used to save
  316. * a processor working register during a tablewalk.
  317. */
  318. #define M_TW 799
  319. /*
  320. * At present, all PowerPC 400-class processors share a similar TLB
  321. * architecture. The instruction and data sides share a unified,
  322. * 64-entry, fully-associative TLB which is maintained totally under
  323. * software control. In addition, the instruction side has a
  324. * hardware-managed, 4-entry, fully- associative TLB which serves as a
  325. * first level to the shared TLB. These two TLBs are known as the UTLB
  326. * and ITLB, respectively.
  327. */
  328. #define PPC4XX_TLB_SIZE 64
  329. /*
  330. * TLB entries are defined by a "high" tag portion and a "low" data
  331. * portion. On all architectures, the data portion is 32-bits.
  332. *
  333. * TLB entries are managed entirely under software control by reading,
  334. * writing, and searchoing using the 4xx-specific tlbre, tlbwr, and tlbsx
  335. * instructions.
  336. */
  337. /*
  338. * FSL Book-E support
  339. */
  340. #define MAS0_TLBSEL_MSK 0x30000000
  341. #define MAS0_TLBSEL(x) (((x) << 28) & MAS0_TLBSEL_MSK)
  342. #define MAS0_ESEL_MSK 0x0FFF0000
  343. #define MAS0_ESEL(x) (((x) << 16) & MAS0_ESEL_MSK)
  344. #define MAS0_NV(x) ((x) & 0x00000FFF)
  345. #define MAS1_VALID 0x80000000
  346. #define MAS1_IPROT 0x40000000
  347. #define MAS1_TID(x) (((x) << 16) & 0x3FFF0000)
  348. #define MAS1_TS 0x00001000
  349. #define MAS1_TSIZE(x) (((x) << 7) & 0x00000F80)
  350. #define TSIZE_TO_BYTES(x) (1ULL << ((x) + 10))
  351. #define MAS2_EPN 0xFFFFF000
  352. #define MAS2_X0 0x00000040
  353. #define MAS2_X1 0x00000020
  354. #define MAS2_W 0x00000010
  355. #define MAS2_I 0x00000008
  356. #define MAS2_M 0x00000004
  357. #define MAS2_G 0x00000002
  358. #define MAS2_E 0x00000001
  359. #define MAS3_RPN 0xFFFFF000
  360. #define MAS3_U0 0x00000200
  361. #define MAS3_U1 0x00000100
  362. #define MAS3_U2 0x00000080
  363. #define MAS3_U3 0x00000040
  364. #define MAS3_UX 0x00000020
  365. #define MAS3_SX 0x00000010
  366. #define MAS3_UW 0x00000008
  367. #define MAS3_SW 0x00000004
  368. #define MAS3_UR 0x00000002
  369. #define MAS3_SR 0x00000001
  370. #define MAS4_TLBSELD(x) MAS0_TLBSEL(x)
  371. #define MAS4_TIDDSEL 0x000F0000
  372. #define MAS4_TSIZED(x) MAS1_TSIZE(x)
  373. #define MAS4_X0D 0x00000040
  374. #define MAS4_X1D 0x00000020
  375. #define MAS4_WD 0x00000010
  376. #define MAS4_ID 0x00000008
  377. #define MAS4_MD 0x00000004
  378. #define MAS4_GD 0x00000002
  379. #define MAS4_ED 0x00000001
  380. #define MAS6_SPID0 0x3FFF0000
  381. #define MAS6_SPID1 0x00007FFE
  382. #define MAS6_SAS 0x00000001
  383. #define MAS6_SPID MAS6_SPID0
  384. #define MAS7_RPN 0xFFFFFFFF
  385. #define FSL_BOOKE_MAS0(tlbsel,esel,nv) \
  386. (MAS0_TLBSEL(tlbsel) | MAS0_ESEL(esel) | MAS0_NV(nv))
  387. #define FSL_BOOKE_MAS1(v,iprot,tid,ts,tsize) \
  388. ((((v) << 31) & MAS1_VALID) |\
  389. (((iprot) << 30) & MAS1_IPROT) |\
  390. (MAS1_TID(tid)) |\
  391. (((ts) << 12) & MAS1_TS) |\
  392. (MAS1_TSIZE(tsize)))
  393. #define FSL_BOOKE_MAS2(epn, wimge) \
  394. (((epn) & MAS3_RPN) | (wimge))
  395. #define FSL_BOOKE_MAS3(rpn, user, perms) \
  396. (((rpn) & MAS3_RPN) | (user) | (perms))
  397. #define FSL_BOOKE_MAS7(rpn) \
  398. (((u64)(rpn)) >> 32)
  399. #define BOOKE_PAGESZ_1K 0
  400. #define BOOKE_PAGESZ_2K 1
  401. #define BOOKE_PAGESZ_4K 2
  402. #define BOOKE_PAGESZ_8K 3
  403. #define BOOKE_PAGESZ_16K 4
  404. #define BOOKE_PAGESZ_32K 5
  405. #define BOOKE_PAGESZ_64K 6
  406. #define BOOKE_PAGESZ_128K 7
  407. #define BOOKE_PAGESZ_256K 8
  408. #define BOOKE_PAGESZ_512K 9
  409. #define BOOKE_PAGESZ_1M 10
  410. #define BOOKE_PAGESZ_2M 11
  411. #define BOOKE_PAGESZ_4M 12
  412. #define BOOKE_PAGESZ_8M 13
  413. #define BOOKE_PAGESZ_16M 14
  414. #define BOOKE_PAGESZ_32M 15
  415. #define BOOKE_PAGESZ_64M 16
  416. #define BOOKE_PAGESZ_128M 17
  417. #define BOOKE_PAGESZ_256M 18
  418. #define BOOKE_PAGESZ_512M 19
  419. #define BOOKE_PAGESZ_1G 20
  420. #define BOOKE_PAGESZ_2G 21
  421. #define BOOKE_PAGESZ_4G 22
  422. #define BOOKE_PAGESZ_8G 23
  423. #define BOOKE_PAGESZ_16GB 24
  424. #define BOOKE_PAGESZ_32GB 25
  425. #define BOOKE_PAGESZ_64GB 26
  426. #define BOOKE_PAGESZ_128GB 27
  427. #define BOOKE_PAGESZ_256GB 28
  428. #define BOOKE_PAGESZ_512GB 29
  429. #define BOOKE_PAGESZ_1TB 30
  430. #define BOOKE_PAGESZ_2TB 31
  431. #define TLBIVAX_ALL 4
  432. #define TLBIVAX_TLB0 0
  433. #define TLBIVAX_TLB1 8
  434. #ifdef CONFIG_E500
  435. #ifndef __ASSEMBLY__
  436. extern void set_tlb(u8 tlb, u32 epn, u64 rpn,
  437. u8 perms, u8 wimge,
  438. u8 ts, u8 esel, u8 tsize, u8 iprot);
  439. extern void disable_tlb(u8 esel);
  440. extern void invalidate_tlb(u8 tlb);
  441. extern void init_tlbs(void);
  442. extern int find_tlb_idx(void *addr, u8 tlbsel);
  443. extern void init_used_tlb_cams(void);
  444. extern int find_free_tlbcam(void);
  445. extern void print_tlbcam(void);
  446. extern unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg);
  447. extern void clear_ddr_tlbs(unsigned int memsize_in_meg);
  448. enum tlb_map_type {
  449. TLB_MAP_RAM,
  450. TLB_MAP_IO,
  451. };
  452. extern uint64_t tlb_map_range(ulong v_addr, phys_addr_t p_addr, uint64_t size,
  453. enum tlb_map_type map_type);
  454. extern void write_tlb(u32 _mas0, u32 _mas1, u32 _mas2, u32 _mas3, u32 _mas7);
  455. #define SET_TLB_ENTRY(_tlb, _epn, _rpn, _perms, _wimge, _ts, _esel, _sz, _iprot) \
  456. { .mas0 = FSL_BOOKE_MAS0(_tlb, _esel, 0), \
  457. .mas1 = FSL_BOOKE_MAS1(1, _iprot, 0, _ts, _sz), \
  458. .mas2 = FSL_BOOKE_MAS2(_epn, _wimge), \
  459. .mas3 = FSL_BOOKE_MAS3(_rpn, 0, _perms), \
  460. .mas7 = FSL_BOOKE_MAS7(_rpn), }
  461. struct fsl_e_tlb_entry {
  462. u32 mas0;
  463. u32 mas1;
  464. u32 mas2;
  465. u32 mas3;
  466. u32 mas7;
  467. };
  468. extern struct fsl_e_tlb_entry tlb_table[];
  469. extern int num_tlb_entries;
  470. #endif
  471. #endif
  472. #ifdef CONFIG_E300
  473. #define LAWAR_EN 0x80000000
  474. #define LAWAR_SIZE 0x0000003F
  475. #define LAWAR_TRGT_IF_PCI 0x00000000
  476. #define LAWAR_TRGT_IF_PCI1 0x00000000
  477. #define LAWAR_TRGT_IF_PCIX 0x00000000
  478. #define LAWAR_TRGT_IF_PCI2 0x00100000
  479. #define LAWAR_TRGT_IF_PCIE1 0x00200000
  480. #define LAWAR_TRGT_IF_PCIE2 0x00100000
  481. #define LAWAR_TRGT_IF_PCIE3 0x00300000
  482. #define LAWAR_TRGT_IF_LBC 0x00400000
  483. #define LAWAR_TRGT_IF_CCSR 0x00800000
  484. #define LAWAR_TRGT_IF_DDR_INTERLEAVED 0x00B00000
  485. #define LAWAR_TRGT_IF_RIO 0x00c00000
  486. #define LAWAR_TRGT_IF_DDR 0x00f00000
  487. #define LAWAR_TRGT_IF_DDR1 0x00f00000
  488. #define LAWAR_TRGT_IF_DDR2 0x01600000
  489. #define LAWAR_SIZE_BASE 0xa
  490. #define LAWAR_SIZE_4K (LAWAR_SIZE_BASE+1)
  491. #define LAWAR_SIZE_8K (LAWAR_SIZE_BASE+2)
  492. #define LAWAR_SIZE_16K (LAWAR_SIZE_BASE+3)
  493. #define LAWAR_SIZE_32K (LAWAR_SIZE_BASE+4)
  494. #define LAWAR_SIZE_64K (LAWAR_SIZE_BASE+5)
  495. #define LAWAR_SIZE_128K (LAWAR_SIZE_BASE+6)
  496. #define LAWAR_SIZE_256K (LAWAR_SIZE_BASE+7)
  497. #define LAWAR_SIZE_512K (LAWAR_SIZE_BASE+8)
  498. #define LAWAR_SIZE_1M (LAWAR_SIZE_BASE+9)
  499. #define LAWAR_SIZE_2M (LAWAR_SIZE_BASE+10)
  500. #define LAWAR_SIZE_4M (LAWAR_SIZE_BASE+11)
  501. #define LAWAR_SIZE_8M (LAWAR_SIZE_BASE+12)
  502. #define LAWAR_SIZE_16M (LAWAR_SIZE_BASE+13)
  503. #define LAWAR_SIZE_32M (LAWAR_SIZE_BASE+14)
  504. #define LAWAR_SIZE_64M (LAWAR_SIZE_BASE+15)
  505. #define LAWAR_SIZE_128M (LAWAR_SIZE_BASE+16)
  506. #define LAWAR_SIZE_256M (LAWAR_SIZE_BASE+17)
  507. #define LAWAR_SIZE_512M (LAWAR_SIZE_BASE+18)
  508. #define LAWAR_SIZE_1G (LAWAR_SIZE_BASE+19)
  509. #define LAWAR_SIZE_2G (LAWAR_SIZE_BASE+20)
  510. #define LAWAR_SIZE_4G (LAWAR_SIZE_BASE+21)
  511. #define LAWAR_SIZE_8G (LAWAR_SIZE_BASE+22)
  512. #define LAWAR_SIZE_16G (LAWAR_SIZE_BASE+23)
  513. #define LAWAR_SIZE_32G (LAWAR_SIZE_BASE+24)
  514. #endif
  515. #ifdef CONFIG_440
  516. /* General */
  517. #define TLB_VALID 0x00000200
  518. /* Supported page sizes */
  519. #define SZ_1K 0x00000000
  520. #define SZ_4K 0x00000010
  521. #define SZ_16K 0x00000020
  522. #define SZ_64K 0x00000030
  523. #define SZ_256K 0x00000040
  524. #define SZ_1M 0x00000050
  525. #define SZ_16M 0x00000070
  526. #define SZ_256M 0x00000090
  527. /* Storage attributes */
  528. #define SA_W 0x00000800 /* Write-through */
  529. #define SA_I 0x00000400 /* Caching inhibited */
  530. #define SA_M 0x00000200 /* Memory coherence */
  531. #define SA_G 0x00000100 /* Guarded */
  532. #define SA_E 0x00000080 /* Endian */
  533. /* Some additional macros for combinations often used */
  534. #define SA_IG (SA_I | SA_G)
  535. /* Access control */
  536. #define AC_X 0x00000024 /* Execute */
  537. #define AC_W 0x00000012 /* Write */
  538. #define AC_R 0x00000009 /* Read */
  539. /* Some additional macros for combinations often used */
  540. #define AC_RW (AC_R | AC_W)
  541. #define AC_RWX (AC_R | AC_W | AC_X)
  542. /* Some handy macros */
  543. #define EPN(e) ((e) & 0xfffffc00)
  544. #define TLB0(epn,sz) ((EPN((epn)) | (sz) | TLB_VALID ))
  545. #define TLB1(rpn,erpn) (((rpn) & 0xfffffc00) | (erpn))
  546. #define TLB2(a) ((a) & 0x00000fbf)
  547. #define tlbtab_start\
  548. mflr r1 ;\
  549. bl 0f ;
  550. #define tlbtab_end\
  551. .long 0, 0, 0 ;\
  552. 0: mflr r0 ;\
  553. mtlr r1 ;\
  554. blr ;
  555. #define tlbentry(epn,sz,rpn,erpn,attr)\
  556. .long TLB0(epn,sz),TLB1(rpn,erpn),TLB2(attr)
  557. /*----------------------------------------------------------------------------+
  558. | TLB specific defines.
  559. +----------------------------------------------------------------------------*/
  560. #define TLB_256MB_ALIGN_MASK 0xFF0000000ULL
  561. #define TLB_16MB_ALIGN_MASK 0xFFF000000ULL
  562. #define TLB_1MB_ALIGN_MASK 0xFFFF00000ULL
  563. #define TLB_256KB_ALIGN_MASK 0xFFFFC0000ULL
  564. #define TLB_64KB_ALIGN_MASK 0xFFFFF0000ULL
  565. #define TLB_16KB_ALIGN_MASK 0xFFFFFC000ULL
  566. #define TLB_4KB_ALIGN_MASK 0xFFFFFF000ULL
  567. #define TLB_1KB_ALIGN_MASK 0xFFFFFFC00ULL
  568. #define TLB_256MB_SIZE 0x10000000
  569. #define TLB_16MB_SIZE 0x01000000
  570. #define TLB_1MB_SIZE 0x00100000
  571. #define TLB_256KB_SIZE 0x00040000
  572. #define TLB_64KB_SIZE 0x00010000
  573. #define TLB_16KB_SIZE 0x00004000
  574. #define TLB_4KB_SIZE 0x00001000
  575. #define TLB_1KB_SIZE 0x00000400
  576. #define TLB_WORD0_EPN_MASK 0xFFFFFC00
  577. #define TLB_WORD0_EPN_ENCODE(n) (((unsigned long)(n))&0xFFFFFC00)
  578. #define TLB_WORD0_EPN_DECODE(n) (((unsigned long)(n))&0xFFFFFC00)
  579. #define TLB_WORD0_V_MASK 0x00000200
  580. #define TLB_WORD0_V_ENABLE 0x00000200
  581. #define TLB_WORD0_V_DISABLE 0x00000000
  582. #define TLB_WORD0_TS_MASK 0x00000100
  583. #define TLB_WORD0_TS_1 0x00000100
  584. #define TLB_WORD0_TS_0 0x00000000
  585. #define TLB_WORD0_SIZE_MASK 0x000000F0
  586. #define TLB_WORD0_SIZE_1KB 0x00000000
  587. #define TLB_WORD0_SIZE_4KB 0x00000010
  588. #define TLB_WORD0_SIZE_16KB 0x00000020
  589. #define TLB_WORD0_SIZE_64KB 0x00000030
  590. #define TLB_WORD0_SIZE_256KB 0x00000040
  591. #define TLB_WORD0_SIZE_1MB 0x00000050
  592. #define TLB_WORD0_SIZE_16MB 0x00000070
  593. #define TLB_WORD0_SIZE_256MB 0x00000090
  594. #define TLB_WORD0_TPAR_MASK 0x0000000F
  595. #define TLB_WORD0_TPAR_ENCODE(n) ((((unsigned long)(n))&0x0F)<<0)
  596. #define TLB_WORD0_TPAR_DECODE(n) ((((unsigned long)(n))>>0)&0x0F)
  597. #define TLB_WORD1_RPN_MASK 0xFFFFFC00
  598. #define TLB_WORD1_RPN_ENCODE(n) (((unsigned long)(n))&0xFFFFFC00)
  599. #define TLB_WORD1_RPN_DECODE(n) (((unsigned long)(n))&0xFFFFFC00)
  600. #define TLB_WORD1_PAR1_MASK 0x00000300
  601. #define TLB_WORD1_PAR1_ENCODE(n) ((((unsigned long)(n))&0x03)<<8)
  602. #define TLB_WORD1_PAR1_DECODE(n) ((((unsigned long)(n))>>8)&0x03)
  603. #define TLB_WORD1_PAR1_0 0x00000000
  604. #define TLB_WORD1_PAR1_1 0x00000100
  605. #define TLB_WORD1_PAR1_2 0x00000200
  606. #define TLB_WORD1_PAR1_3 0x00000300
  607. #define TLB_WORD1_ERPN_MASK 0x0000000F
  608. #define TLB_WORD1_ERPN_ENCODE(n) ((((unsigned long)(n))&0x0F)<<0)
  609. #define TLB_WORD1_ERPN_DECODE(n) ((((unsigned long)(n))>>0)&0x0F)
  610. #define TLB_WORD2_PAR2_MASK 0xC0000000
  611. #define TLB_WORD2_PAR2_ENCODE(n) ((((unsigned long)(n))&0x03)<<30)
  612. #define TLB_WORD2_PAR2_DECODE(n) ((((unsigned long)(n))>>30)&0x03)
  613. #define TLB_WORD2_PAR2_0 0x00000000
  614. #define TLB_WORD2_PAR2_1 0x40000000
  615. #define TLB_WORD2_PAR2_2 0x80000000
  616. #define TLB_WORD2_PAR2_3 0xC0000000
  617. #define TLB_WORD2_U0_MASK 0x00008000
  618. #define TLB_WORD2_U0_ENABLE 0x00008000
  619. #define TLB_WORD2_U0_DISABLE 0x00000000
  620. #define TLB_WORD2_U1_MASK 0x00004000
  621. #define TLB_WORD2_U1_ENABLE 0x00004000
  622. #define TLB_WORD2_U1_DISABLE 0x00000000
  623. #define TLB_WORD2_U2_MASK 0x00002000
  624. #define TLB_WORD2_U2_ENABLE 0x00002000
  625. #define TLB_WORD2_U2_DISABLE 0x00000000
  626. #define TLB_WORD2_U3_MASK 0x00001000
  627. #define TLB_WORD2_U3_ENABLE 0x00001000
  628. #define TLB_WORD2_U3_DISABLE 0x00000000
  629. #define TLB_WORD2_W_MASK 0x00000800
  630. #define TLB_WORD2_W_ENABLE 0x00000800
  631. #define TLB_WORD2_W_DISABLE 0x00000000
  632. #define TLB_WORD2_I_MASK 0x00000400
  633. #define TLB_WORD2_I_ENABLE 0x00000400
  634. #define TLB_WORD2_I_DISABLE 0x00000000
  635. #define TLB_WORD2_M_MASK 0x00000200
  636. #define TLB_WORD2_M_ENABLE 0x00000200
  637. #define TLB_WORD2_M_DISABLE 0x00000000
  638. #define TLB_WORD2_G_MASK 0x00000100
  639. #define TLB_WORD2_G_ENABLE 0x00000100
  640. #define TLB_WORD2_G_DISABLE 0x00000000
  641. #define TLB_WORD2_E_MASK 0x00000080
  642. #define TLB_WORD2_E_ENABLE 0x00000080
  643. #define TLB_WORD2_E_DISABLE 0x00000000
  644. #define TLB_WORD2_UX_MASK 0x00000020
  645. #define TLB_WORD2_UX_ENABLE 0x00000020
  646. #define TLB_WORD2_UX_DISABLE 0x00000000
  647. #define TLB_WORD2_UW_MASK 0x00000010
  648. #define TLB_WORD2_UW_ENABLE 0x00000010
  649. #define TLB_WORD2_UW_DISABLE 0x00000000
  650. #define TLB_WORD2_UR_MASK 0x00000008
  651. #define TLB_WORD2_UR_ENABLE 0x00000008
  652. #define TLB_WORD2_UR_DISABLE 0x00000000
  653. #define TLB_WORD2_SX_MASK 0x00000004
  654. #define TLB_WORD2_SX_ENABLE 0x00000004
  655. #define TLB_WORD2_SX_DISABLE 0x00000000
  656. #define TLB_WORD2_SW_MASK 0x00000002
  657. #define TLB_WORD2_SW_ENABLE 0x00000002
  658. #define TLB_WORD2_SW_DISABLE 0x00000000
  659. #define TLB_WORD2_SR_MASK 0x00000001
  660. #define TLB_WORD2_SR_ENABLE 0x00000001
  661. #define TLB_WORD2_SR_DISABLE 0x00000000
  662. /*----------------------------------------------------------------------------+
  663. | Following instructions are not available in Book E mode of the GNU assembler.
  664. +----------------------------------------------------------------------------*/
  665. #define DCCCI(ra,rb) .long 0x7c000000|\
  666. (ra<<16)|(rb<<11)|(454<<1)
  667. #define ICCCI(ra,rb) .long 0x7c000000|\
  668. (ra<<16)|(rb<<11)|(966<<1)
  669. #define DCREAD(rt,ra,rb) .long 0x7c000000|\
  670. (rt<<21)|(ra<<16)|(rb<<11)|(486<<1)
  671. #define ICREAD(ra,rb) .long 0x7c000000|\
  672. (ra<<16)|(rb<<11)|(998<<1)
  673. #define TLBSX(rt,ra,rb) .long 0x7c000000|\
  674. (rt<<21)|(ra<<16)|(rb<<11)|(914<<1)
  675. #define TLBWE(rs,ra,ws) .long 0x7c000000|\
  676. (rs<<21)|(ra<<16)|(ws<<11)|(978<<1)
  677. #define TLBRE(rt,ra,ws) .long 0x7c000000|\
  678. (rt<<21)|(ra<<16)|(ws<<11)|(946<<1)
  679. #define TLBSXDOT(rt,ra,rb) .long 0x7c000001|\
  680. (rt<<21)|(ra<<16)|(rb<<11)|(914<<1)
  681. #define MSYNC .long 0x7c000000|\
  682. (598<<1)
  683. #define MBAR_INST .long 0x7c000000|\
  684. (854<<1)
  685. #ifndef __ASSEMBLY__
  686. /* Prototypes */
  687. void mttlb1(unsigned long index, unsigned long value);
  688. void mttlb2(unsigned long index, unsigned long value);
  689. void mttlb3(unsigned long index, unsigned long value);
  690. unsigned long mftlb1(unsigned long index);
  691. unsigned long mftlb2(unsigned long index);
  692. unsigned long mftlb3(unsigned long index);
  693. void program_tlb(u64 phys_addr, u32 virt_addr, u32 size, u32 tlb_word2_i_value);
  694. void remove_tlb(u32 vaddr, u32 size);
  695. void change_tlb(u32 vaddr, u32 size, u32 tlb_word2_i_value);
  696. #endif /* __ASSEMBLY__ */
  697. #endif /* CONFIG_440 */
  698. #endif /* _PPC_MMU_H_ */