mmu.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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) (1ULL << (fls((x & BATU_BL_MAX) >> 2) + 17))
  187. /* bytes into BATU_BL */
  188. #define TO_BATU_BL(x) \
  189. (u32)((((1ull << __ilog2_u64((u64)x)) / (128 * 1024)) - 1) * 4)
  190. /* Used to set up SDR1 register */
  191. #define HASH_TABLE_SIZE_64K 0x00010000
  192. #define HASH_TABLE_SIZE_128K 0x00020000
  193. #define HASH_TABLE_SIZE_256K 0x00040000
  194. #define HASH_TABLE_SIZE_512K 0x00080000
  195. #define HASH_TABLE_SIZE_1M 0x00100000
  196. #define HASH_TABLE_SIZE_2M 0x00200000
  197. #define HASH_TABLE_SIZE_4M 0x00400000
  198. #define HASH_TABLE_MASK_64K 0x000
  199. #define HASH_TABLE_MASK_128K 0x001
  200. #define HASH_TABLE_MASK_256K 0x003
  201. #define HASH_TABLE_MASK_512K 0x007
  202. #define HASH_TABLE_MASK_1M 0x00F
  203. #define HASH_TABLE_MASK_2M 0x01F
  204. #define HASH_TABLE_MASK_4M 0x03F
  205. /* Control/status registers for the MPC8xx.
  206. * A write operation to these registers causes serialized access.
  207. * During software tablewalk, the registers used perform mask/shift-add
  208. * operations when written/read. A TLB entry is created when the Mx_RPN
  209. * is written, and the contents of several registers are used to
  210. * create the entry.
  211. */
  212. #define MI_CTR 784 /* Instruction TLB control register */
  213. #define MI_GPM 0x80000000 /* Set domain manager mode */
  214. #define MI_PPM 0x40000000 /* Set subpage protection */
  215. #define MI_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  216. #define MI_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  217. #define MI_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  218. #define MI_IDXMASK 0x00001f00 /* TLB index to be loaded */
  219. #define MI_RESETVAL 0x00000000 /* Value of register at reset */
  220. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  221. * Ks = 0, Kp = 1.
  222. */
  223. #define MI_AP 786
  224. #define MI_Ks 0x80000000 /* Should not be set */
  225. #define MI_Kp 0x40000000 /* Should always be set */
  226. /* The effective page number register. When read, contains the information
  227. * about the last instruction TLB miss. When MI_RPN is written, bits in
  228. * this register are used to create the TLB entry.
  229. */
  230. #define MI_EPN 787
  231. #define MI_EPNMASK 0xfffff000 /* Effective page number for entry */
  232. #define MI_EVALID 0x00000200 /* Entry is valid */
  233. #define MI_ASIDMASK 0x0000000f /* ASID match value */
  234. /* Reset value is undefined */
  235. /* A "level 1" or "segment" or whatever you want to call it register.
  236. * For the instruction TLB, it contains bits that get loaded into the
  237. * TLB entry when the MI_RPN is written.
  238. */
  239. #define MI_TWC 789
  240. #define MI_APG 0x000001e0 /* Access protection group (0) */
  241. #define MI_GUARDED 0x00000010 /* Guarded storage */
  242. #define MI_PSMASK 0x0000000c /* Mask of page size bits */
  243. #define MI_PS8MEG 0x0000000c /* 8M page size */
  244. #define MI_PS512K 0x00000004 /* 512K page size */
  245. #define MI_PS4K_16K 0x00000000 /* 4K or 16K page size */
  246. #define MI_SVALID 0x00000001 /* Segment entry is valid */
  247. /* Reset value is undefined */
  248. /* Real page number. Defined by the pte. Writing this register
  249. * causes a TLB entry to be created for the instruction TLB, using
  250. * additional information from the MI_EPN, and MI_TWC registers.
  251. */
  252. #define MI_RPN 790
  253. /* Define an RPN value for mapping kernel memory to large virtual
  254. * pages for boot initialization. This has real page number of 0,
  255. * large page size, shared page, cache enabled, and valid.
  256. * Also mark all subpages valid and write access.
  257. */
  258. #define MI_BOOTINIT 0x000001fd
  259. #define MD_CTR 792 /* Data TLB control register */
  260. #define MD_GPM 0x80000000 /* Set domain manager mode */
  261. #define MD_PPM 0x40000000 /* Set subpage protection */
  262. #define MD_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  263. #define MD_WTDEF 0x10000000 /* Set writethrough when MMU dis */
  264. #define MD_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  265. #define MD_TWAM 0x04000000 /* Use 4K page hardware assist */
  266. #define MD_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  267. #define MD_IDXMASK 0x00001f00 /* TLB index to be loaded */
  268. #define MD_RESETVAL 0x04000000 /* Value of register at reset */
  269. #define M_CASID 793 /* Address space ID (context) to match */
  270. #define MC_ASIDMASK 0x0000000f /* Bits used for ASID value */
  271. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  272. * Ks = 0, Kp = 1.
  273. */
  274. #define MD_AP 794
  275. #define MD_Ks 0x80000000 /* Should not be set */
  276. #define MD_Kp 0x40000000 /* Should always be set */
  277. /* The effective page number register. When read, contains the information
  278. * about the last instruction TLB miss. When MD_RPN is written, bits in
  279. * this register are used to create the TLB entry.
  280. */
  281. #define MD_EPN 795
  282. #define MD_EPNMASK 0xfffff000 /* Effective page number for entry */
  283. #define MD_EVALID 0x00000200 /* Entry is valid */
  284. #define MD_ASIDMASK 0x0000000f /* ASID match value */
  285. /* Reset value is undefined */
  286. /* The pointer to the base address of the first level page table.
  287. * During a software tablewalk, reading this register provides the address
  288. * of the entry associated with MD_EPN.
  289. */
  290. #define M_TWB 796
  291. #define M_L1TB 0xfffff000 /* Level 1 table base address */
  292. #define M_L1INDX 0x00000ffc /* Level 1 index, when read */
  293. /* Reset value is undefined */
  294. /* A "level 1" or "segment" or whatever you want to call it register.
  295. * For the data TLB, it contains bits that get loaded into the TLB entry
  296. * when the MD_RPN is written. It is also provides the hardware assist
  297. * for finding the PTE address during software tablewalk.
  298. */
  299. #define MD_TWC 797
  300. #define MD_L2TB 0xfffff000 /* Level 2 table base address */
  301. #define MD_L2INDX 0xfffffe00 /* Level 2 index (*pte), when read */
  302. #define MD_APG 0x000001e0 /* Access protection group (0) */
  303. #define MD_GUARDED 0x00000010 /* Guarded storage */
  304. #define MD_PSMASK 0x0000000c /* Mask of page size bits */
  305. #define MD_PS8MEG 0x0000000c /* 8M page size */
  306. #define MD_PS512K 0x00000004 /* 512K page size */
  307. #define MD_PS4K_16K 0x00000000 /* 4K or 16K page size */
  308. #define MD_WT 0x00000002 /* Use writethrough page attribute */
  309. #define MD_SVALID 0x00000001 /* Segment entry is valid */
  310. /* Reset value is undefined */
  311. /* Real page number. Defined by the pte. Writing this register
  312. * causes a TLB entry to be created for the data TLB, using
  313. * additional information from the MD_EPN, and MD_TWC registers.
  314. */
  315. #define MD_RPN 798
  316. /* This is a temporary storage register that could be used to save
  317. * a processor working register during a tablewalk.
  318. */
  319. #define M_TW 799
  320. /*
  321. * At present, all PowerPC 400-class processors share a similar TLB
  322. * architecture. The instruction and data sides share a unified,
  323. * 64-entry, fully-associative TLB which is maintained totally under
  324. * software control. In addition, the instruction side has a
  325. * hardware-managed, 4-entry, fully- associative TLB which serves as a
  326. * first level to the shared TLB. These two TLBs are known as the UTLB
  327. * and ITLB, respectively.
  328. */
  329. #define PPC4XX_TLB_SIZE 64
  330. /*
  331. * TLB entries are defined by a "high" tag portion and a "low" data
  332. * portion. On all architectures, the data portion is 32-bits.
  333. *
  334. * TLB entries are managed entirely under software control by reading,
  335. * writing, and searchoing using the 4xx-specific tlbre, tlbwr, and tlbsx
  336. * instructions.
  337. */
  338. /*
  339. * FSL Book-E support
  340. */
  341. #define MAS0_TLBSEL_MSK 0x30000000
  342. #define MAS0_TLBSEL(x) ((x << 28) & MAS0_TLBSEL_MSK)
  343. #define MAS0_ESEL_MSK 0x0FFF0000
  344. #define MAS0_ESEL(x) ((x << 16) & MAS0_ESEL_MSK)
  345. #define MAS0_NV(x) ((x) & 0x00000FFF)
  346. #define MAS1_VALID 0x80000000
  347. #define MAS1_IPROT 0x40000000
  348. #define MAS1_TID(x) ((x << 16) & 0x3FFF0000)
  349. #define MAS1_TS 0x00001000
  350. #define MAS1_TSIZE(x) ((x << 8) & 0x00000F00)
  351. #define TSIZE_TO_BYTES(x) ((phys_addr_t)(1UL << ((tsize * 2) + 10)))
  352. #define MAS2_EPN 0xFFFFF000
  353. #define MAS2_X0 0x00000040
  354. #define MAS2_X1 0x00000020
  355. #define MAS2_W 0x00000010
  356. #define MAS2_I 0x00000008
  357. #define MAS2_M 0x00000004
  358. #define MAS2_G 0x00000002
  359. #define MAS2_E 0x00000001
  360. #define MAS3_RPN 0xFFFFF000
  361. #define MAS3_U0 0x00000200
  362. #define MAS3_U1 0x00000100
  363. #define MAS3_U2 0x00000080
  364. #define MAS3_U3 0x00000040
  365. #define MAS3_UX 0x00000020
  366. #define MAS3_SX 0x00000010
  367. #define MAS3_UW 0x00000008
  368. #define MAS3_SW 0x00000004
  369. #define MAS3_UR 0x00000002
  370. #define MAS3_SR 0x00000001
  371. #define MAS4_TLBSELD(x) MAS0_TLBSEL(x)
  372. #define MAS4_TIDDSEL 0x000F0000
  373. #define MAS4_TSIZED(x) MAS1_TSIZE(x)
  374. #define MAS4_X0D 0x00000040
  375. #define MAS4_X1D 0x00000020
  376. #define MAS4_WD 0x00000010
  377. #define MAS4_ID 0x00000008
  378. #define MAS4_MD 0x00000004
  379. #define MAS4_GD 0x00000002
  380. #define MAS4_ED 0x00000001
  381. #define MAS6_SPID0 0x3FFF0000
  382. #define MAS6_SPID1 0x00007FFE
  383. #define MAS6_SAS 0x00000001
  384. #define MAS6_SPID MAS6_SPID0
  385. #define MAS7_RPN 0xFFFFFFFF
  386. #define FSL_BOOKE_MAS0(tlbsel,esel,nv) \
  387. (MAS0_TLBSEL(tlbsel) | MAS0_ESEL(esel) | MAS0_NV(nv))
  388. #define FSL_BOOKE_MAS1(v,iprot,tid,ts,tsize) \
  389. ((((v) << 31) & MAS1_VALID) |\
  390. (((iprot) << 30) & MAS1_IPROT) |\
  391. (MAS1_TID(tid)) |\
  392. (((ts) << 12) & MAS1_TS) |\
  393. (MAS1_TSIZE(tsize)))
  394. #define FSL_BOOKE_MAS2(epn, wimge) \
  395. (((epn) & MAS3_RPN) | (wimge))
  396. #define FSL_BOOKE_MAS3(rpn, user, perms) \
  397. (((rpn) & MAS3_RPN) | (user) | (perms))
  398. #define FSL_BOOKE_MAS7(rpn) \
  399. (((u64)(rpn)) >> 32)
  400. #define BOOKE_PAGESZ_1K 0
  401. #define BOOKE_PAGESZ_4K 1
  402. #define BOOKE_PAGESZ_16K 2
  403. #define BOOKE_PAGESZ_64K 3
  404. #define BOOKE_PAGESZ_256K 4
  405. #define BOOKE_PAGESZ_1M 5
  406. #define BOOKE_PAGESZ_4M 6
  407. #define BOOKE_PAGESZ_16M 7
  408. #define BOOKE_PAGESZ_64M 8
  409. #define BOOKE_PAGESZ_256M 9
  410. #define BOOKE_PAGESZ_1G 10
  411. #define BOOKE_PAGESZ_4G 11
  412. #define BOOKE_PAGESZ_16GB 12
  413. #define BOOKE_PAGESZ_64GB 13
  414. #define BOOKE_PAGESZ_256GB 14
  415. #define BOOKE_PAGESZ_1TB 15
  416. #ifdef CONFIG_E500
  417. #ifndef __ASSEMBLY__
  418. extern void set_tlb(u8 tlb, u32 epn, u64 rpn,
  419. u8 perms, u8 wimge,
  420. u8 ts, u8 esel, u8 tsize, u8 iprot);
  421. extern void disable_tlb(u8 esel);
  422. extern void invalidate_tlb(u8 tlb);
  423. extern void init_tlbs(void);
  424. extern int find_tlb_idx(void *addr, u8 tlbsel);
  425. extern void init_used_tlb_cams(void);
  426. extern int find_free_tlbcam(void);
  427. extern void print_tlbcam(void);
  428. extern unsigned int setup_ddr_tlbs(unsigned int memsize_in_meg);
  429. extern void write_tlb(u32 _mas0, u32 _mas1, u32 _mas2, u32 _mas3, u32 _mas7);
  430. #define SET_TLB_ENTRY(_tlb, _epn, _rpn, _perms, _wimge, _ts, _esel, _sz, _iprot) \
  431. { .mas0 = FSL_BOOKE_MAS0(_tlb, _esel, 0), \
  432. .mas1 = FSL_BOOKE_MAS1(1, _iprot, 0, _ts, _sz), \
  433. .mas2 = FSL_BOOKE_MAS2(_epn, _wimge), \
  434. .mas3 = FSL_BOOKE_MAS3(_rpn, 0, _perms), \
  435. .mas7 = FSL_BOOKE_MAS7(_rpn), }
  436. struct fsl_e_tlb_entry {
  437. u32 mas0;
  438. u32 mas1;
  439. u32 mas2;
  440. u32 mas3;
  441. u32 mas7;
  442. };
  443. extern struct fsl_e_tlb_entry tlb_table[];
  444. extern int num_tlb_entries;
  445. #endif
  446. #endif
  447. #ifdef CONFIG_E300
  448. #define LAWAR_EN 0x80000000
  449. #define LAWAR_SIZE 0x0000003F
  450. #define LAWAR_TRGT_IF_PCI 0x00000000
  451. #define LAWAR_TRGT_IF_PCI1 0x00000000
  452. #define LAWAR_TRGT_IF_PCIX 0x00000000
  453. #define LAWAR_TRGT_IF_PCI2 0x00100000
  454. #define LAWAR_TRGT_IF_PCIE1 0x00200000
  455. #define LAWAR_TRGT_IF_PCIE2 0x00100000
  456. #define LAWAR_TRGT_IF_PCIE3 0x00300000
  457. #define LAWAR_TRGT_IF_LBC 0x00400000
  458. #define LAWAR_TRGT_IF_CCSR 0x00800000
  459. #define LAWAR_TRGT_IF_DDR_INTERLEAVED 0x00B00000
  460. #define LAWAR_TRGT_IF_RIO 0x00c00000
  461. #define LAWAR_TRGT_IF_DDR 0x00f00000
  462. #define LAWAR_TRGT_IF_DDR1 0x00f00000
  463. #define LAWAR_TRGT_IF_DDR2 0x01600000
  464. #define LAWAR_SIZE_BASE 0xa
  465. #define LAWAR_SIZE_4K (LAWAR_SIZE_BASE+1)
  466. #define LAWAR_SIZE_8K (LAWAR_SIZE_BASE+2)
  467. #define LAWAR_SIZE_16K (LAWAR_SIZE_BASE+3)
  468. #define LAWAR_SIZE_32K (LAWAR_SIZE_BASE+4)
  469. #define LAWAR_SIZE_64K (LAWAR_SIZE_BASE+5)
  470. #define LAWAR_SIZE_128K (LAWAR_SIZE_BASE+6)
  471. #define LAWAR_SIZE_256K (LAWAR_SIZE_BASE+7)
  472. #define LAWAR_SIZE_512K (LAWAR_SIZE_BASE+8)
  473. #define LAWAR_SIZE_1M (LAWAR_SIZE_BASE+9)
  474. #define LAWAR_SIZE_2M (LAWAR_SIZE_BASE+10)
  475. #define LAWAR_SIZE_4M (LAWAR_SIZE_BASE+11)
  476. #define LAWAR_SIZE_8M (LAWAR_SIZE_BASE+12)
  477. #define LAWAR_SIZE_16M (LAWAR_SIZE_BASE+13)
  478. #define LAWAR_SIZE_32M (LAWAR_SIZE_BASE+14)
  479. #define LAWAR_SIZE_64M (LAWAR_SIZE_BASE+15)
  480. #define LAWAR_SIZE_128M (LAWAR_SIZE_BASE+16)
  481. #define LAWAR_SIZE_256M (LAWAR_SIZE_BASE+17)
  482. #define LAWAR_SIZE_512M (LAWAR_SIZE_BASE+18)
  483. #define LAWAR_SIZE_1G (LAWAR_SIZE_BASE+19)
  484. #define LAWAR_SIZE_2G (LAWAR_SIZE_BASE+20)
  485. #define LAWAR_SIZE_4G (LAWAR_SIZE_BASE+21)
  486. #define LAWAR_SIZE_8G (LAWAR_SIZE_BASE+22)
  487. #define LAWAR_SIZE_16G (LAWAR_SIZE_BASE+23)
  488. #define LAWAR_SIZE_32G (LAWAR_SIZE_BASE+24)
  489. #endif
  490. #ifdef CONFIG_440
  491. /* General */
  492. #define TLB_VALID 0x00000200
  493. /* Supported page sizes */
  494. #define SZ_1K 0x00000000
  495. #define SZ_4K 0x00000010
  496. #define SZ_16K 0x00000020
  497. #define SZ_64K 0x00000030
  498. #define SZ_256K 0x00000040
  499. #define SZ_1M 0x00000050
  500. #define SZ_16M 0x00000070
  501. #define SZ_256M 0x00000090
  502. /* Storage attributes */
  503. #define SA_W 0x00000800 /* Write-through */
  504. #define SA_I 0x00000400 /* Caching inhibited */
  505. #define SA_M 0x00000200 /* Memory coherence */
  506. #define SA_G 0x00000100 /* Guarded */
  507. #define SA_E 0x00000080 /* Endian */
  508. /* Some additional macros for combinations often used */
  509. #define SA_IG (SA_I | SA_G)
  510. /* Access control */
  511. #define AC_X 0x00000024 /* Execute */
  512. #define AC_W 0x00000012 /* Write */
  513. #define AC_R 0x00000009 /* Read */
  514. /* Some additional macros for combinations often used */
  515. #define AC_RW (AC_R | AC_W)
  516. #define AC_RWX (AC_R | AC_W | AC_X)
  517. /* Some handy macros */
  518. #define EPN(e) ((e) & 0xfffffc00)
  519. #define TLB0(epn,sz) ((EPN((epn)) | (sz) | TLB_VALID ))
  520. #define TLB1(rpn,erpn) (((rpn) & 0xfffffc00) | (erpn))
  521. #define TLB2(a) ((a) & 0x00000fbf)
  522. #define tlbtab_start\
  523. mflr r1 ;\
  524. bl 0f ;
  525. #define tlbtab_end\
  526. .long 0, 0, 0 ;\
  527. 0: mflr r0 ;\
  528. mtlr r1 ;\
  529. blr ;
  530. #define tlbentry(epn,sz,rpn,erpn,attr)\
  531. .long TLB0(epn,sz),TLB1(rpn,erpn),TLB2(attr)
  532. /*----------------------------------------------------------------------------+
  533. | TLB specific defines.
  534. +----------------------------------------------------------------------------*/
  535. #define TLB_256MB_ALIGN_MASK 0xFF0000000ULL
  536. #define TLB_16MB_ALIGN_MASK 0xFFF000000ULL
  537. #define TLB_1MB_ALIGN_MASK 0xFFFF00000ULL
  538. #define TLB_256KB_ALIGN_MASK 0xFFFFC0000ULL
  539. #define TLB_64KB_ALIGN_MASK 0xFFFFF0000ULL
  540. #define TLB_16KB_ALIGN_MASK 0xFFFFFC000ULL
  541. #define TLB_4KB_ALIGN_MASK 0xFFFFFF000ULL
  542. #define TLB_1KB_ALIGN_MASK 0xFFFFFFC00ULL
  543. #define TLB_256MB_SIZE 0x10000000
  544. #define TLB_16MB_SIZE 0x01000000
  545. #define TLB_1MB_SIZE 0x00100000
  546. #define TLB_256KB_SIZE 0x00040000
  547. #define TLB_64KB_SIZE 0x00010000
  548. #define TLB_16KB_SIZE 0x00004000
  549. #define TLB_4KB_SIZE 0x00001000
  550. #define TLB_1KB_SIZE 0x00000400
  551. #define TLB_WORD0_EPN_MASK 0xFFFFFC00
  552. #define TLB_WORD0_EPN_ENCODE(n) (((unsigned long)(n))&0xFFFFFC00)
  553. #define TLB_WORD0_EPN_DECODE(n) (((unsigned long)(n))&0xFFFFFC00)
  554. #define TLB_WORD0_V_MASK 0x00000200
  555. #define TLB_WORD0_V_ENABLE 0x00000200
  556. #define TLB_WORD0_V_DISABLE 0x00000000
  557. #define TLB_WORD0_TS_MASK 0x00000100
  558. #define TLB_WORD0_TS_1 0x00000100
  559. #define TLB_WORD0_TS_0 0x00000000
  560. #define TLB_WORD0_SIZE_MASK 0x000000F0
  561. #define TLB_WORD0_SIZE_1KB 0x00000000
  562. #define TLB_WORD0_SIZE_4KB 0x00000010
  563. #define TLB_WORD0_SIZE_16KB 0x00000020
  564. #define TLB_WORD0_SIZE_64KB 0x00000030
  565. #define TLB_WORD0_SIZE_256KB 0x00000040
  566. #define TLB_WORD0_SIZE_1MB 0x00000050
  567. #define TLB_WORD0_SIZE_16MB 0x00000070
  568. #define TLB_WORD0_SIZE_256MB 0x00000090
  569. #define TLB_WORD0_TPAR_MASK 0x0000000F
  570. #define TLB_WORD0_TPAR_ENCODE(n) ((((unsigned long)(n))&0x0F)<<0)
  571. #define TLB_WORD0_TPAR_DECODE(n) ((((unsigned long)(n))>>0)&0x0F)
  572. #define TLB_WORD1_RPN_MASK 0xFFFFFC00
  573. #define TLB_WORD1_RPN_ENCODE(n) (((unsigned long)(n))&0xFFFFFC00)
  574. #define TLB_WORD1_RPN_DECODE(n) (((unsigned long)(n))&0xFFFFFC00)
  575. #define TLB_WORD1_PAR1_MASK 0x00000300
  576. #define TLB_WORD1_PAR1_ENCODE(n) ((((unsigned long)(n))&0x03)<<8)
  577. #define TLB_WORD1_PAR1_DECODE(n) ((((unsigned long)(n))>>8)&0x03)
  578. #define TLB_WORD1_PAR1_0 0x00000000
  579. #define TLB_WORD1_PAR1_1 0x00000100
  580. #define TLB_WORD1_PAR1_2 0x00000200
  581. #define TLB_WORD1_PAR1_3 0x00000300
  582. #define TLB_WORD1_ERPN_MASK 0x0000000F
  583. #define TLB_WORD1_ERPN_ENCODE(n) ((((unsigned long)(n))&0x0F)<<0)
  584. #define TLB_WORD1_ERPN_DECODE(n) ((((unsigned long)(n))>>0)&0x0F)
  585. #define TLB_WORD2_PAR2_MASK 0xC0000000
  586. #define TLB_WORD2_PAR2_ENCODE(n) ((((unsigned long)(n))&0x03)<<30)
  587. #define TLB_WORD2_PAR2_DECODE(n) ((((unsigned long)(n))>>30)&0x03)
  588. #define TLB_WORD2_PAR2_0 0x00000000
  589. #define TLB_WORD2_PAR2_1 0x40000000
  590. #define TLB_WORD2_PAR2_2 0x80000000
  591. #define TLB_WORD2_PAR2_3 0xC0000000
  592. #define TLB_WORD2_U0_MASK 0x00008000
  593. #define TLB_WORD2_U0_ENABLE 0x00008000
  594. #define TLB_WORD2_U0_DISABLE 0x00000000
  595. #define TLB_WORD2_U1_MASK 0x00004000
  596. #define TLB_WORD2_U1_ENABLE 0x00004000
  597. #define TLB_WORD2_U1_DISABLE 0x00000000
  598. #define TLB_WORD2_U2_MASK 0x00002000
  599. #define TLB_WORD2_U2_ENABLE 0x00002000
  600. #define TLB_WORD2_U2_DISABLE 0x00000000
  601. #define TLB_WORD2_U3_MASK 0x00001000
  602. #define TLB_WORD2_U3_ENABLE 0x00001000
  603. #define TLB_WORD2_U3_DISABLE 0x00000000
  604. #define TLB_WORD2_W_MASK 0x00000800
  605. #define TLB_WORD2_W_ENABLE 0x00000800
  606. #define TLB_WORD2_W_DISABLE 0x00000000
  607. #define TLB_WORD2_I_MASK 0x00000400
  608. #define TLB_WORD2_I_ENABLE 0x00000400
  609. #define TLB_WORD2_I_DISABLE 0x00000000
  610. #define TLB_WORD2_M_MASK 0x00000200
  611. #define TLB_WORD2_M_ENABLE 0x00000200
  612. #define TLB_WORD2_M_DISABLE 0x00000000
  613. #define TLB_WORD2_G_MASK 0x00000100
  614. #define TLB_WORD2_G_ENABLE 0x00000100
  615. #define TLB_WORD2_G_DISABLE 0x00000000
  616. #define TLB_WORD2_E_MASK 0x00000080
  617. #define TLB_WORD2_E_ENABLE 0x00000080
  618. #define TLB_WORD2_E_DISABLE 0x00000000
  619. #define TLB_WORD2_UX_MASK 0x00000020
  620. #define TLB_WORD2_UX_ENABLE 0x00000020
  621. #define TLB_WORD2_UX_DISABLE 0x00000000
  622. #define TLB_WORD2_UW_MASK 0x00000010
  623. #define TLB_WORD2_UW_ENABLE 0x00000010
  624. #define TLB_WORD2_UW_DISABLE 0x00000000
  625. #define TLB_WORD2_UR_MASK 0x00000008
  626. #define TLB_WORD2_UR_ENABLE 0x00000008
  627. #define TLB_WORD2_UR_DISABLE 0x00000000
  628. #define TLB_WORD2_SX_MASK 0x00000004
  629. #define TLB_WORD2_SX_ENABLE 0x00000004
  630. #define TLB_WORD2_SX_DISABLE 0x00000000
  631. #define TLB_WORD2_SW_MASK 0x00000002
  632. #define TLB_WORD2_SW_ENABLE 0x00000002
  633. #define TLB_WORD2_SW_DISABLE 0x00000000
  634. #define TLB_WORD2_SR_MASK 0x00000001
  635. #define TLB_WORD2_SR_ENABLE 0x00000001
  636. #define TLB_WORD2_SR_DISABLE 0x00000000
  637. /*----------------------------------------------------------------------------+
  638. | Following instructions are not available in Book E mode of the GNU assembler.
  639. +----------------------------------------------------------------------------*/
  640. #define DCCCI(ra,rb) .long 0x7c000000|\
  641. (ra<<16)|(rb<<11)|(454<<1)
  642. #define ICCCI(ra,rb) .long 0x7c000000|\
  643. (ra<<16)|(rb<<11)|(966<<1)
  644. #define DCREAD(rt,ra,rb) .long 0x7c000000|\
  645. (rt<<21)|(ra<<16)|(rb<<11)|(486<<1)
  646. #define ICREAD(ra,rb) .long 0x7c000000|\
  647. (ra<<16)|(rb<<11)|(998<<1)
  648. #define TLBSX(rt,ra,rb) .long 0x7c000000|\
  649. (rt<<21)|(ra<<16)|(rb<<11)|(914<<1)
  650. #define TLBWE(rs,ra,ws) .long 0x7c000000|\
  651. (rs<<21)|(ra<<16)|(ws<<11)|(978<<1)
  652. #define TLBRE(rt,ra,ws) .long 0x7c000000|\
  653. (rt<<21)|(ra<<16)|(ws<<11)|(946<<1)
  654. #define TLBSXDOT(rt,ra,rb) .long 0x7c000001|\
  655. (rt<<21)|(ra<<16)|(rb<<11)|(914<<1)
  656. #define MSYNC .long 0x7c000000|\
  657. (598<<1)
  658. #define MBAR_INST .long 0x7c000000|\
  659. (854<<1)
  660. #ifndef __ASSEMBLY__
  661. /* Prototypes */
  662. void mttlb1(unsigned long index, unsigned long value);
  663. void mttlb2(unsigned long index, unsigned long value);
  664. void mttlb3(unsigned long index, unsigned long value);
  665. unsigned long mftlb1(unsigned long index);
  666. unsigned long mftlb2(unsigned long index);
  667. unsigned long mftlb3(unsigned long index);
  668. void program_tlb(u64 phys_addr, u32 virt_addr, u32 size, u32 tlb_word2_i_value);
  669. void remove_tlb(u32 vaddr, u32 size);
  670. void change_tlb(u32 vaddr, u32 size, u32 tlb_word2_i_value);
  671. #endif /* __ASSEMBLY__ */
  672. #endif /* CONFIG_440 */
  673. #endif /* _PPC_MMU_H_ */