mmu.h 26 KB

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