mmu.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /*
  2. * PowerPC memory management structures
  3. */
  4. #ifdef __KERNEL__
  5. #ifndef _PPC_MMU_H_
  6. #define _PPC_MMU_H_
  7. #include <linux/config.h>
  8. #ifndef __ASSEMBLY__
  9. /*
  10. * Define physical address type. Machines using split size
  11. * virtual/physical addressing like 32-bit virtual / 36-bit
  12. * physical need a larger than native word size type. -Matt
  13. */
  14. #ifndef CONFIG_PHYS_64BIT
  15. typedef unsigned long phys_addr_t;
  16. #define PHYS_FMT "%.8lx"
  17. #else
  18. typedef unsigned long long phys_addr_t;
  19. extern phys_addr_t fixup_bigphys_addr(phys_addr_t, phys_addr_t);
  20. #define PHYS_FMT "%16Lx"
  21. #endif
  22. /* Default "unsigned long" context */
  23. typedef unsigned long mm_context_t;
  24. /* Hardware Page Table Entry */
  25. typedef struct _PTE {
  26. #ifdef CONFIG_PPC64BRIDGE
  27. unsigned long long vsid:52;
  28. unsigned long api:5;
  29. unsigned long :5;
  30. unsigned long h:1;
  31. unsigned long v:1;
  32. unsigned long long rpn:52;
  33. #else /* CONFIG_PPC64BRIDGE */
  34. unsigned long v:1; /* Entry is valid */
  35. unsigned long vsid:24; /* Virtual segment identifier */
  36. unsigned long h:1; /* Hash algorithm indicator */
  37. unsigned long api:6; /* Abbreviated page index */
  38. unsigned long rpn:20; /* Real (physical) page number */
  39. #endif /* CONFIG_PPC64BRIDGE */
  40. unsigned long :3; /* Unused */
  41. unsigned long r:1; /* Referenced */
  42. unsigned long c:1; /* Changed */
  43. unsigned long w:1; /* Write-thru cache mode */
  44. unsigned long i:1; /* Cache inhibited */
  45. unsigned long m:1; /* Memory coherence */
  46. unsigned long g:1; /* Guarded */
  47. unsigned long :1; /* Unused */
  48. unsigned long pp:2; /* Page protection */
  49. } PTE;
  50. /* Values for PP (assumes Ks=0, Kp=1) */
  51. #define PP_RWXX 0 /* Supervisor read/write, User none */
  52. #define PP_RWRX 1 /* Supervisor read/write, User read */
  53. #define PP_RWRW 2 /* Supervisor read/write, User read/write */
  54. #define PP_RXRX 3 /* Supervisor read, User read */
  55. /* Segment Register */
  56. typedef struct _SEGREG {
  57. unsigned long t:1; /* Normal or I/O type */
  58. unsigned long ks:1; /* Supervisor 'key' (normally 0) */
  59. unsigned long kp:1; /* User 'key' (normally 1) */
  60. unsigned long n:1; /* No-execute */
  61. unsigned long :4; /* Unused */
  62. unsigned long vsid:24; /* Virtual Segment Identifier */
  63. } SEGREG;
  64. /* Block Address Translation (BAT) Registers */
  65. typedef struct _P601_BATU { /* Upper part of BAT for 601 processor */
  66. unsigned long bepi:15; /* Effective page index (virtual address) */
  67. unsigned long :8; /* unused */
  68. unsigned long w:1;
  69. unsigned long i:1; /* Cache inhibit */
  70. unsigned long m:1; /* Memory coherence */
  71. unsigned long ks:1; /* Supervisor key (normally 0) */
  72. unsigned long kp:1; /* User key (normally 1) */
  73. unsigned long pp:2; /* Page access protections */
  74. } P601_BATU;
  75. typedef struct _BATU { /* Upper part of BAT (all except 601) */
  76. #ifdef CONFIG_PPC64BRIDGE
  77. unsigned long long bepi:47;
  78. #else /* CONFIG_PPC64BRIDGE */
  79. unsigned long bepi:15; /* Effective page index (virtual address) */
  80. #endif /* CONFIG_PPC64BRIDGE */
  81. unsigned long :4; /* Unused */
  82. unsigned long bl:11; /* Block size mask */
  83. unsigned long vs:1; /* Supervisor valid */
  84. unsigned long vp:1; /* User valid */
  85. } BATU;
  86. typedef struct _P601_BATL { /* Lower part of BAT for 601 processor */
  87. unsigned long brpn:15; /* Real page index (physical address) */
  88. unsigned long :10; /* Unused */
  89. unsigned long v:1; /* Valid bit */
  90. unsigned long bl:6; /* Block size mask */
  91. } P601_BATL;
  92. typedef struct _BATL { /* Lower part of BAT (all except 601) */
  93. #ifdef CONFIG_PPC64BRIDGE
  94. unsigned long long brpn:47;
  95. #else /* CONFIG_PPC64BRIDGE */
  96. unsigned long brpn:15; /* Real page index (physical address) */
  97. #endif /* CONFIG_PPC64BRIDGE */
  98. unsigned long :10; /* Unused */
  99. unsigned long w:1; /* Write-thru cache */
  100. unsigned long i:1; /* Cache inhibit */
  101. unsigned long m:1; /* Memory coherence */
  102. unsigned long g:1; /* Guarded (MBZ in IBAT) */
  103. unsigned long :1; /* Unused */
  104. unsigned long pp:2; /* Page access protections */
  105. } BATL;
  106. typedef struct _BAT {
  107. BATU batu; /* Upper register */
  108. BATL batl; /* Lower register */
  109. } BAT;
  110. typedef struct _P601_BAT {
  111. P601_BATU batu; /* Upper register */
  112. P601_BATL batl; /* Lower register */
  113. } P601_BAT;
  114. #endif /* __ASSEMBLY__ */
  115. /* Block size masks */
  116. #define BL_128K 0x000
  117. #define BL_256K 0x001
  118. #define BL_512K 0x003
  119. #define BL_1M 0x007
  120. #define BL_2M 0x00F
  121. #define BL_4M 0x01F
  122. #define BL_8M 0x03F
  123. #define BL_16M 0x07F
  124. #define BL_32M 0x0FF
  125. #define BL_64M 0x1FF
  126. #define BL_128M 0x3FF
  127. #define BL_256M 0x7FF
  128. /* BAT Access Protection */
  129. #define BPP_XX 0x00 /* No access */
  130. #define BPP_RX 0x01 /* Read only */
  131. #define BPP_RW 0x02 /* Read/write */
  132. /* Control/status registers for the MPC8xx.
  133. * A write operation to these registers causes serialized access.
  134. * During software tablewalk, the registers used perform mask/shift-add
  135. * operations when written/read. A TLB entry is created when the Mx_RPN
  136. * is written, and the contents of several registers are used to
  137. * create the entry.
  138. */
  139. #define SPRN_MI_CTR 784 /* Instruction TLB control register */
  140. #define MI_GPM 0x80000000 /* Set domain manager mode */
  141. #define MI_PPM 0x40000000 /* Set subpage protection */
  142. #define MI_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  143. #define MI_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  144. #define MI_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  145. #define MI_IDXMASK 0x00001f00 /* TLB index to be loaded */
  146. #define MI_RESETVAL 0x00000000 /* Value of register at reset */
  147. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  148. * Ks = 0, Kp = 1.
  149. */
  150. #define SPRN_MI_AP 786
  151. #define MI_Ks 0x80000000 /* Should not be set */
  152. #define MI_Kp 0x40000000 /* Should always be set */
  153. /* The effective page number register. When read, contains the information
  154. * about the last instruction TLB miss. When MI_RPN is written, bits in
  155. * this register are used to create the TLB entry.
  156. */
  157. #define SPRN_MI_EPN 787
  158. #define MI_EPNMASK 0xfffff000 /* Effective page number for entry */
  159. #define MI_EVALID 0x00000200 /* Entry is valid */
  160. #define MI_ASIDMASK 0x0000000f /* ASID match value */
  161. /* Reset value is undefined */
  162. /* A "level 1" or "segment" or whatever you want to call it register.
  163. * For the instruction TLB, it contains bits that get loaded into the
  164. * TLB entry when the MI_RPN is written.
  165. */
  166. #define SPRN_MI_TWC 789
  167. #define MI_APG 0x000001e0 /* Access protection group (0) */
  168. #define MI_GUARDED 0x00000010 /* Guarded storage */
  169. #define MI_PSMASK 0x0000000c /* Mask of page size bits */
  170. #define MI_PS8MEG 0x0000000c /* 8M page size */
  171. #define MI_PS512K 0x00000004 /* 512K page size */
  172. #define MI_PS4K_16K 0x00000000 /* 4K or 16K page size */
  173. #define MI_SVALID 0x00000001 /* Segment entry is valid */
  174. /* Reset value is undefined */
  175. /* Real page number. Defined by the pte. Writing this register
  176. * causes a TLB entry to be created for the instruction TLB, using
  177. * additional information from the MI_EPN, and MI_TWC registers.
  178. */
  179. #define SPRN_MI_RPN 790
  180. /* Define an RPN value for mapping kernel memory to large virtual
  181. * pages for boot initialization. This has real page number of 0,
  182. * large page size, shared page, cache enabled, and valid.
  183. * Also mark all subpages valid and write access.
  184. */
  185. #define MI_BOOTINIT 0x000001fd
  186. #define SPRN_MD_CTR 792 /* Data TLB control register */
  187. #define MD_GPM 0x80000000 /* Set domain manager mode */
  188. #define MD_PPM 0x40000000 /* Set subpage protection */
  189. #define MD_CIDEF 0x20000000 /* Set cache inhibit when MMU dis */
  190. #define MD_WTDEF 0x10000000 /* Set writethrough when MMU dis */
  191. #define MD_RSV4I 0x08000000 /* Reserve 4 TLB entries */
  192. #define MD_TWAM 0x04000000 /* Use 4K page hardware assist */
  193. #define MD_PPCS 0x02000000 /* Use MI_RPN prob/priv state */
  194. #define MD_IDXMASK 0x00001f00 /* TLB index to be loaded */
  195. #define MD_RESETVAL 0x04000000 /* Value of register at reset */
  196. #define SPRN_M_CASID 793 /* Address space ID (context) to match */
  197. #define MC_ASIDMASK 0x0000000f /* Bits used for ASID value */
  198. /* These are the Ks and Kp from the PowerPC books. For proper operation,
  199. * Ks = 0, Kp = 1.
  200. */
  201. #define SPRN_MD_AP 794
  202. #define MD_Ks 0x80000000 /* Should not be set */
  203. #define MD_Kp 0x40000000 /* Should always be set */
  204. /* The effective page number register. When read, contains the information
  205. * about the last instruction TLB miss. When MD_RPN is written, bits in
  206. * this register are used to create the TLB entry.
  207. */
  208. #define SPRN_MD_EPN 795
  209. #define MD_EPNMASK 0xfffff000 /* Effective page number for entry */
  210. #define MD_EVALID 0x00000200 /* Entry is valid */
  211. #define MD_ASIDMASK 0x0000000f /* ASID match value */
  212. /* Reset value is undefined */
  213. /* The pointer to the base address of the first level page table.
  214. * During a software tablewalk, reading this register provides the address
  215. * of the entry associated with MD_EPN.
  216. */
  217. #define SPRN_M_TWB 796
  218. #define M_L1TB 0xfffff000 /* Level 1 table base address */
  219. #define M_L1INDX 0x00000ffc /* Level 1 index, when read */
  220. /* Reset value is undefined */
  221. /* A "level 1" or "segment" or whatever you want to call it register.
  222. * For the data TLB, it contains bits that get loaded into the TLB entry
  223. * when the MD_RPN is written. It is also provides the hardware assist
  224. * for finding the PTE address during software tablewalk.
  225. */
  226. #define SPRN_MD_TWC 797
  227. #define MD_L2TB 0xfffff000 /* Level 2 table base address */
  228. #define MD_L2INDX 0xfffffe00 /* Level 2 index (*pte), when read */
  229. #define MD_APG 0x000001e0 /* Access protection group (0) */
  230. #define MD_GUARDED 0x00000010 /* Guarded storage */
  231. #define MD_PSMASK 0x0000000c /* Mask of page size bits */
  232. #define MD_PS8MEG 0x0000000c /* 8M page size */
  233. #define MD_PS512K 0x00000004 /* 512K page size */
  234. #define MD_PS4K_16K 0x00000000 /* 4K or 16K page size */
  235. #define MD_WT 0x00000002 /* Use writethrough page attribute */
  236. #define MD_SVALID 0x00000001 /* Segment entry is valid */
  237. /* Reset value is undefined */
  238. /* Real page number. Defined by the pte. Writing this register
  239. * causes a TLB entry to be created for the data TLB, using
  240. * additional information from the MD_EPN, and MD_TWC registers.
  241. */
  242. #define SPRN_MD_RPN 798
  243. /* This is a temporary storage register that could be used to save
  244. * a processor working register during a tablewalk.
  245. */
  246. #define SPRN_M_TW 799
  247. /*
  248. * At present, all PowerPC 400-class processors share a similar TLB
  249. * architecture. The instruction and data sides share a unified,
  250. * 64-entry, fully-associative TLB which is maintained totally under
  251. * software control. In addition, the instruction side has a
  252. * hardware-managed, 4-entry, fully- associative TLB which serves as a
  253. * first level to the shared TLB. These two TLBs are known as the UTLB
  254. * and ITLB, respectively.
  255. */
  256. #define PPC4XX_TLB_SIZE 64
  257. /*
  258. * TLB entries are defined by a "high" tag portion and a "low" data
  259. * portion. On all architectures, the data portion is 32-bits.
  260. *
  261. * TLB entries are managed entirely under software control by reading,
  262. * writing, and searchoing using the 4xx-specific tlbre, tlbwr, and tlbsx
  263. * instructions.
  264. */
  265. #define TLB_LO 1
  266. #define TLB_HI 0
  267. #define TLB_DATA TLB_LO
  268. #define TLB_TAG TLB_HI
  269. /* Tag portion */
  270. #define TLB_EPN_MASK 0xFFFFFC00 /* Effective Page Number */
  271. #define TLB_PAGESZ_MASK 0x00000380
  272. #define TLB_PAGESZ(x) (((x) & 0x7) << 7)
  273. #define PAGESZ_1K 0
  274. #define PAGESZ_4K 1
  275. #define PAGESZ_16K 2
  276. #define PAGESZ_64K 3
  277. #define PAGESZ_256K 4
  278. #define PAGESZ_1M 5
  279. #define PAGESZ_4M 6
  280. #define PAGESZ_16M 7
  281. #define TLB_VALID 0x00000040 /* Entry is valid */
  282. /* Data portion */
  283. #define TLB_RPN_MASK 0xFFFFFC00 /* Real Page Number */
  284. #define TLB_PERM_MASK 0x00000300
  285. #define TLB_EX 0x00000200 /* Instruction execution allowed */
  286. #define TLB_WR 0x00000100 /* Writes permitted */
  287. #define TLB_ZSEL_MASK 0x000000F0
  288. #define TLB_ZSEL(x) (((x) & 0xF) << 4)
  289. #define TLB_ATTR_MASK 0x0000000F
  290. #define TLB_W 0x00000008 /* Caching is write-through */
  291. #define TLB_I 0x00000004 /* Caching is inhibited */
  292. #define TLB_M 0x00000002 /* Memory is coherent */
  293. #define TLB_G 0x00000001 /* Memory is guarded from prefetch */
  294. /*
  295. * PPC440 support
  296. */
  297. #define PPC44x_MMUCR_TID 0x000000ff
  298. #define PPC44x_MMUCR_STS 0x00010000
  299. #define PPC44x_TLB_PAGEID 0
  300. #define PPC44x_TLB_XLAT 1
  301. #define PPC44x_TLB_ATTRIB 2
  302. /* Page identification fields */
  303. #define PPC44x_TLB_EPN_MASK 0xfffffc00 /* Effective Page Number */
  304. #define PPC44x_TLB_VALID 0x00000200 /* Valid flag */
  305. #define PPC44x_TLB_TS 0x00000100 /* Translation address space */
  306. #define PPC44x_TLB_1K 0x00000000 /* Page sizes */
  307. #define PPC44x_TLB_4K 0x00000010
  308. #define PPC44x_TLB_16K 0x00000020
  309. #define PPC44x_TLB_64K 0x00000030
  310. #define PPC44x_TLB_256K 0x00000040
  311. #define PPC44x_TLB_1M 0x00000050
  312. #define PPC44x_TLB_16M 0x00000070
  313. #define PPC44x_TLB_256M 0x00000090
  314. /* Translation fields */
  315. #define PPC44x_TLB_RPN_MASK 0xfffffc00 /* Real Page Number */
  316. #define PPC44x_TLB_ERPN_MASK 0x0000000f
  317. /* Storage attribute and access control fields */
  318. #define PPC44x_TLB_ATTR_MASK 0x0000ff80
  319. #define PPC44x_TLB_U0 0x00008000 /* User 0 */
  320. #define PPC44x_TLB_U1 0x00004000 /* User 1 */
  321. #define PPC44x_TLB_U2 0x00002000 /* User 2 */
  322. #define PPC44x_TLB_U3 0x00001000 /* User 3 */
  323. #define PPC44x_TLB_W 0x00000800 /* Caching is write-through */
  324. #define PPC44x_TLB_I 0x00000400 /* Caching is inhibited */
  325. #define PPC44x_TLB_M 0x00000200 /* Memory is coherent */
  326. #define PPC44x_TLB_G 0x00000100 /* Memory is guarded */
  327. #define PPC44x_TLB_E 0x00000080 /* Memory is guarded */
  328. #define PPC44x_TLB_PERM_MASK 0x0000003f
  329. #define PPC44x_TLB_UX 0x00000020 /* User execution */
  330. #define PPC44x_TLB_UW 0x00000010 /* User write */
  331. #define PPC44x_TLB_UR 0x00000008 /* User read */
  332. #define PPC44x_TLB_SX 0x00000004 /* Super execution */
  333. #define PPC44x_TLB_SW 0x00000002 /* Super write */
  334. #define PPC44x_TLB_SR 0x00000001 /* Super read */
  335. /* Book-E defined page sizes */
  336. #define BOOKE_PAGESZ_1K 0
  337. #define BOOKE_PAGESZ_4K 1
  338. #define BOOKE_PAGESZ_16K 2
  339. #define BOOKE_PAGESZ_64K 3
  340. #define BOOKE_PAGESZ_256K 4
  341. #define BOOKE_PAGESZ_1M 5
  342. #define BOOKE_PAGESZ_4M 6
  343. #define BOOKE_PAGESZ_16M 7
  344. #define BOOKE_PAGESZ_64M 8
  345. #define BOOKE_PAGESZ_256M 9
  346. #define BOOKE_PAGESZ_1GB 10
  347. #define BOOKE_PAGESZ_4GB 11
  348. #define BOOKE_PAGESZ_16GB 12
  349. #define BOOKE_PAGESZ_64GB 13
  350. #define BOOKE_PAGESZ_256GB 14
  351. #define BOOKE_PAGESZ_1TB 15
  352. /*
  353. * Freescale Book-E MMU support
  354. */
  355. #define MAS0_TLBSEL(x) ((x << 28) & 0x30000000)
  356. #define MAS0_ESEL(x) ((x << 16) & 0x0FFF0000)
  357. #define MAS0_NV(x) ((x) & 0x00000FFF)
  358. #define MAS1_VALID 0x80000000
  359. #define MAS1_IPROT 0x40000000
  360. #define MAS1_TID(x) ((x << 16) & 0x3FFF0000)
  361. #define MAS1_TS 0x00001000
  362. #define MAS1_TSIZE(x) ((x << 8) & 0x00000F00)
  363. #define MAS2_EPN 0xFFFFF000
  364. #define MAS2_X0 0x00000040
  365. #define MAS2_X1 0x00000020
  366. #define MAS2_W 0x00000010
  367. #define MAS2_I 0x00000008
  368. #define MAS2_M 0x00000004
  369. #define MAS2_G 0x00000002
  370. #define MAS2_E 0x00000001
  371. #define MAS3_RPN 0xFFFFF000
  372. #define MAS3_U0 0x00000200
  373. #define MAS3_U1 0x00000100
  374. #define MAS3_U2 0x00000080
  375. #define MAS3_U3 0x00000040
  376. #define MAS3_UX 0x00000020
  377. #define MAS3_SX 0x00000010
  378. #define MAS3_UW 0x00000008
  379. #define MAS3_SW 0x00000004
  380. #define MAS3_UR 0x00000002
  381. #define MAS3_SR 0x00000001
  382. #define MAS4_TLBSELD(x) MAS0_TLBSEL(x)
  383. #define MAS4_TIDDSEL 0x000F0000
  384. #define MAS4_TSIZED(x) MAS1_TSIZE(x)
  385. #define MAS4_X0D 0x00000040
  386. #define MAS4_X1D 0x00000020
  387. #define MAS4_WD 0x00000010
  388. #define MAS4_ID 0x00000008
  389. #define MAS4_MD 0x00000004
  390. #define MAS4_GD 0x00000002
  391. #define MAS4_ED 0x00000001
  392. #define MAS6_SPID0 0x3FFF0000
  393. #define MAS6_SPID1 0x00007FFE
  394. #define MAS6_SAS 0x00000001
  395. #define MAS6_SPID MAS6_SPID0
  396. #define MAS7_RPN 0xFFFFFFFF
  397. #endif /* _PPC_MMU_H_ */
  398. #endif /* __KERNEL__ */