mmu-layout.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. =================================
  2. FR451 MMU LINUX MEMORY MANAGEMENT
  3. =================================
  4. ============
  5. MMU HARDWARE
  6. ============
  7. FR451 MMU Linux puts the MMU into EDAT mode whilst running. This means that it uses both the SAT
  8. registers and the DAT TLB to perform address translation.
  9. There are 8 IAMLR/IAMPR register pairs and 16 DAMLR/DAMPR register pairs for SAT mode.
  10. In DAT mode, there is also a TLB organised in cache format as 64 lines x 2 ways. Each line spans a
  11. 16KB range of addresses, but can match a larger region.
  12. ===========================
  13. MEMORY MANAGEMENT REGISTERS
  14. ===========================
  15. Certain control registers are used by the kernel memory management routines:
  16. REGISTERS USAGE
  17. ====================== ==================================================
  18. IAMR0, DAMR0 Kernel image and data mappings
  19. IAMR1, DAMR1 First-chance TLB lookup mapping
  20. DAMR2 Page attachment for cache flush by page
  21. DAMR3 Current PGD mapping
  22. SCR0, DAMR4 Instruction TLB PGE/PTD cache
  23. SCR1, DAMR5 Data TLB PGE/PTD cache
  24. DAMR6-10 kmap_atomic() mappings
  25. DAMR11 I/O mapping
  26. CXNR mm_struct context ID
  27. TTBR Page directory (PGD) pointer (physical address)
  28. =====================
  29. GENERAL MEMORY LAYOUT
  30. =====================
  31. The physical memory layout is as follows:
  32. PHYSICAL ADDRESS CONTROLLER DEVICE
  33. =================== ============== =======================================
  34. 00000000 - BFFFFFFF SDRAM SDRAM area
  35. E0000000 - EFFFFFFF L-BUS CS2# VDK SLBUS/PCI window
  36. F0000000 - F0FFFFFF L-BUS CS5# MB93493 CSC area (DAV daughter board)
  37. F1000000 - F1FFFFFF L-BUS CS7# (CB70 CPU-card PCMCIA port I/O space)
  38. FC000000 - FC0FFFFF L-BUS CS1# VDK MB86943 config space
  39. FC100000 - FC1FFFFF L-BUS CS6# DM9000 NIC I/O space
  40. FC200000 - FC2FFFFF L-BUS CS3# MB93493 CSR area (DAV daughter board)
  41. FD000000 - FDFFFFFF L-BUS CS4# (CB70 CPU-card extra flash space)
  42. FE000000 - FEFFFFFF Internal CPU peripherals
  43. FF000000 - FF1FFFFF L-BUS CS0# Flash 1
  44. FF200000 - FF3FFFFF L-BUS CS0# Flash 2
  45. FFC00000 - FFC0001F L-BUS CS0# FPGA
  46. The virtual memory layout is:
  47. VIRTUAL ADDRESS PHYSICAL TRANSLATOR FLAGS SIZE OCCUPATION
  48. ================= ======== ============== ======= ======= ===================================
  49. 00004000-BFFFFFFF various TLB,xAMR1 D-N-??V 3GB Userspace
  50. C0000000-CFFFFFFF 00000000 xAMPR0 -L-S--V 256MB Kernel image and data
  51. D0000000-D7FFFFFF various TLB,xAMR1 D-NS??V 128MB vmalloc area
  52. D8000000-DBFFFFFF various TLB,xAMR1 D-NS??V 64MB kmap() area
  53. DC000000-DCFFFFFF various TLB 1MB Secondary kmap_atomic() frame
  54. DD000000-DD27FFFF various DAMR 160KB Primary kmap_atomic() frame
  55. DD040000 DAMR2/IAMR2 -L-S--V page Page cache flush attachment point
  56. DD080000 DAMR3 -L-SC-V page Page Directory (PGD)
  57. DD0C0000 DAMR4 -L-SC-V page Cached insn TLB Page Table lookup
  58. DD100000 DAMR5 -L-SC-V page Cached data TLB Page Table lookup
  59. DD140000 DAMR6 -L-S--V page kmap_atomic(KM_BOUNCE_READ)
  60. DD180000 DAMR7 -L-S--V page kmap_atomic(KM_SKB_SUNRPC_DATA)
  61. DD1C0000 DAMR8 -L-S--V page kmap_atomic(KM_SKB_DATA_SOFTIRQ)
  62. DD200000 DAMR9 -L-S--V page kmap_atomic(KM_USER0)
  63. DD240000 DAMR10 -L-S--V page kmap_atomic(KM_USER1)
  64. E0000000-FFFFFFFF E0000000 DAMR11 -L-SC-V 512MB I/O region
  65. IAMPR1 and DAMPR1 are used as an extension to the TLB.
  66. ====================
  67. KMAP AND KMAP_ATOMIC
  68. ====================
  69. To access pages in the page cache (which may not be directly accessible if highmem is available),
  70. the kernel calls kmap(), does the access and then calls kunmap(); or it calls kmap_atomic(), does
  71. the access and then calls kunmap_atomic().
  72. kmap() creates an attachment between an arbitrary inaccessible page and a range of virtual
  73. addresses by installing a PTE in a special page table. The kernel can then access this page as it
  74. wills. When it's finished, the kernel calls kunmap() to clear the PTE.
  75. kmap_atomic() does something slightly different. In the interests of speed, it chooses one of two
  76. strategies:
  77. (1) If possible, kmap_atomic() attaches the requested page to one of DAMPR5 through DAMPR10
  78. register pairs; and the matching kunmap_atomic() clears the DAMPR. This makes high memory
  79. support really fast as there's no need to flush the TLB or modify the page tables. The DAMLR
  80. registers being used for this are preset during boot and don't change over the lifetime of the
  81. process. There's a direct mapping between the first few kmap_atomic() types, DAMR number and
  82. virtual address slot.
  83. However, there are more kmap_atomic() types defined than there are DAMR registers available,
  84. so we fall back to:
  85. (2) kmap_atomic() uses a slot in the secondary frame (determined by the type parameter), and then
  86. locks an entry in the TLB to translate that slot to the specified page. The number of slots is
  87. obviously limited, and their positions are controlled such that each slot is matched by a
  88. different line in the TLB. kunmap() ejects the entry from the TLB.
  89. Note that the first three kmap atomic types are really just declared as placeholders. The DAMPR
  90. registers involved are actually modified directly.
  91. Also note that kmap() itself may sleep, kmap_atomic() may never sleep and both always succeed;
  92. furthermore, a driver using kmap() may sleep before calling kunmap(), but may not sleep before
  93. calling kunmap_atomic() if it had previously called kmap_atomic().
  94. ===============================
  95. USING MORE THAN 256MB OF MEMORY
  96. ===============================
  97. The kernel cannot access more than 256MB of memory directly. The physical layout, however, permits
  98. up to 3GB of SDRAM (possibly 3.25GB) to be made available. By using CONFIG_HIGHMEM, the kernel can
  99. allow userspace (by way of page tables) and itself (by way of kmap) to deal with the memory
  100. allocation.
  101. External devices can, of course, still DMA to and from all of the SDRAM, even if the kernel can't
  102. see it directly. The kernel translates page references into real addresses for communicating to the
  103. devices.
  104. ===================
  105. PAGE TABLE TOPOLOGY
  106. ===================
  107. The page tables are arranged in 2-layer format. There is a middle layer (PMD) that would be used in
  108. 3-layer format tables but that is folded into the top layer (PGD) and so consumes no extra memory
  109. or processing power.
  110. +------+ PGD PMD
  111. | TTBR |--->+-------------------+
  112. +------+ | | : STE |
  113. | PGE0 | PME0 : STE |
  114. | | : STE |
  115. +-------------------+ Page Table
  116. | | : STE -------------->+--------+ +0x0000
  117. | PGE1 | PME0 : STE -----------+ | PTE0 |
  118. | | : STE -------+ | +--------+
  119. +-------------------+ | | | PTE63 |
  120. | | : STE | | +-->+--------+ +0x0100
  121. | PGE2 | PME0 : STE | | | PTE64 |
  122. | | : STE | | +--------+
  123. +-------------------+ | | PTE127 |
  124. | | : STE | +------>+--------+ +0x0200
  125. | PGE3 | PME0 : STE | | PTE128 |
  126. | | : STE | +--------+
  127. +-------------------+ | PTE191 |
  128. +--------+ +0x0300
  129. Each Page Directory (PGD) is 16KB (page size) in size and is divided into 64 entries (PGEs). Each
  130. PGE contains one Page Mid Directory (PMD).
  131. Each PMD is 256 bytes in size and contains a single entry (PME). Each PME holds 64 FR451 MMU
  132. segment table entries of 4 bytes apiece. Each PME "points to" a page table. In practice, each STE
  133. points to a subset of the page table, the first to PT+0x0000, the second to PT+0x0100, the third to
  134. PT+0x200, and so on.
  135. Each PGE and PME covers 64MB of the total virtual address space.
  136. Each Page Table (PTD) is 16KB (page size) in size, and is divided into 4096 entries (PTEs). Each
  137. entry can point to one 16KB page. In practice, each Linux page table is subdivided into 64 FR451
  138. MMU page tables. But they are all grouped together to make management easier, in particular rmap
  139. support is then trivial.
  140. Grouping page tables in this fashion makes PGE caching in SCR0/SCR1 more efficient because the
  141. coverage of the cached item is greater.
  142. Page tables for the vmalloc area are allocated at boot time and shared between all mm_structs.
  143. =================
  144. USER SPACE LAYOUT
  145. =================
  146. For MMU capable Linux, the regions userspace code are allowed to access are kept entirely separate
  147. from those dedicated to the kernel:
  148. VIRTUAL ADDRESS SIZE PURPOSE
  149. ================= ===== ===================================
  150. 00000000-00003fff 4KB NULL pointer access trap
  151. 00004000-01ffffff ~32MB lower mmap space (grows up)
  152. 02000000-021fffff 2MB Stack space (grows down from top)
  153. 02200000-nnnnnnnn Executable mapping
  154. nnnnnnnn- brk space (grows up)
  155. -bfffffff upper mmap space (grows down)
  156. This is so arranged so as to make best use of the 16KB page tables and the way in which PGEs/PMEs
  157. are cached by the TLB handler. The lower mmap space is filled first, and then the upper mmap space
  158. is filled.
  159. ===============================
  160. GDB-STUB MMU DEBUGGING SERVICES
  161. ===============================
  162. The gdb-stub included in this kernel provides a number of services to aid in the debugging of MMU
  163. related kernel services:
  164. (*) Every time the kernel stops, certain state information is dumped into __debug_mmu. This
  165. variable is defined in arch/frv/kernel/gdb-stub.c. Note that the gdbinit file in this
  166. directory has some useful macros for dealing with this.
  167. (*) __debug_mmu.tlb[]
  168. This receives the current TLB contents. This can be viewed with the _tlb GDB macro:
  169. (gdb) _tlb
  170. tlb[0x00]: 01000005 00718203 01000002 00718203
  171. tlb[0x01]: 01004002 006d4201 01004005 006d4203
  172. tlb[0x02]: 01008002 006d0201 01008006 00004200
  173. tlb[0x03]: 0100c006 007f4202 0100c002 0064c202
  174. tlb[0x04]: 01110005 00774201 01110002 00774201
  175. tlb[0x05]: 01114005 00770201 01114002 00770201
  176. tlb[0x06]: 01118002 0076c201 01118005 0076c201
  177. ...
  178. tlb[0x3d]: 010f4002 00790200 001f4002 0054ca02
  179. tlb[0x3e]: 010f8005 0078c201 010f8002 0078c201
  180. tlb[0x3f]: 001fc002 0056ca01 001fc005 00538a01
  181. (*) __debug_mmu.iamr[]
  182. (*) __debug_mmu.damr[]
  183. These receive the current IAMR and DAMR contents. These can be viewed with the _amr
  184. GDB macro:
  185. (gdb) _amr
  186. AMRx DAMR IAMR
  187. ==== ===================== =====================
  188. amr0 : L:c0000000 P:00000cb9 : L:c0000000 P:000004b9
  189. amr1 : L:01070005 P:006f9203 : L:0102c005 P:006a1201
  190. amr2 : L:d8d00000 P:00000000 : L:d8d00000 P:00000000
  191. amr3 : L:d8d04000 P:00534c0d : L:00000000 P:00000000
  192. amr4 : L:d8d08000 P:00554c0d : L:00000000 P:00000000
  193. amr5 : L:d8d0c000 P:00554c0d : L:00000000 P:00000000
  194. amr6 : L:d8d10000 P:00000000 : L:00000000 P:00000000
  195. amr7 : L:d8d14000 P:00000000 : L:00000000 P:00000000
  196. amr8 : L:d8d18000 P:00000000
  197. amr9 : L:d8d1c000 P:00000000
  198. amr10: L:d8d20000 P:00000000
  199. amr11: L:e0000000 P:e0000ccd
  200. (*) The current task's page directory is bound to DAMR3.
  201. This can be viewed with the _pgd GDB macro:
  202. (gdb) _pgd
  203. $3 = {{pge = {{ste = {0x554001, 0x554101, 0x554201, 0x554301, 0x554401,
  204. 0x554501, 0x554601, 0x554701, 0x554801, 0x554901, 0x554a01,
  205. 0x554b01, 0x554c01, 0x554d01, 0x554e01, 0x554f01, 0x555001,
  206. 0x555101, 0x555201, 0x555301, 0x555401, 0x555501, 0x555601,
  207. 0x555701, 0x555801, 0x555901, 0x555a01, 0x555b01, 0x555c01,
  208. 0x555d01, 0x555e01, 0x555f01, 0x556001, 0x556101, 0x556201,
  209. 0x556301, 0x556401, 0x556501, 0x556601, 0x556701, 0x556801,
  210. 0x556901, 0x556a01, 0x556b01, 0x556c01, 0x556d01, 0x556e01,
  211. 0x556f01, 0x557001, 0x557101, 0x557201, 0x557301, 0x557401,
  212. 0x557501, 0x557601, 0x557701, 0x557801, 0x557901, 0x557a01,
  213. 0x557b01, 0x557c01, 0x557d01, 0x557e01, 0x557f01}}}}, {pge = {{
  214. ste = {0x0 <repeats 64 times>}}}} <repeats 51 times>, {pge = {{ste = {
  215. 0x248001, 0x248101, 0x248201, 0x248301, 0x248401, 0x248501,
  216. 0x248601, 0x248701, 0x248801, 0x248901, 0x248a01, 0x248b01,
  217. 0x248c01, 0x248d01, 0x248e01, 0x248f01, 0x249001, 0x249101,
  218. 0x249201, 0x249301, 0x249401, 0x249501, 0x249601, 0x249701,
  219. 0x249801, 0x249901, 0x249a01, 0x249b01, 0x249c01, 0x249d01,
  220. 0x249e01, 0x249f01, 0x24a001, 0x24a101, 0x24a201, 0x24a301,
  221. 0x24a401, 0x24a501, 0x24a601, 0x24a701, 0x24a801, 0x24a901,
  222. 0x24aa01, 0x24ab01, 0x24ac01, 0x24ad01, 0x24ae01, 0x24af01,
  223. 0x24b001, 0x24b101, 0x24b201, 0x24b301, 0x24b401, 0x24b501,
  224. 0x24b601, 0x24b701, 0x24b801, 0x24b901, 0x24ba01, 0x24bb01,
  225. 0x24bc01, 0x24bd01, 0x24be01, 0x24bf01}}}}, {pge = {{ste = {
  226. 0x0 <repeats 64 times>}}}} <repeats 11 times>}
  227. (*) The PTD last used by the instruction TLB miss handler is attached to DAMR4.
  228. (*) The PTD last used by the data TLB miss handler is attached to DAMR5.
  229. These can be viewed with the _ptd_i and _ptd_d GDB macros:
  230. (gdb) _ptd_d
  231. $5 = {{pte = 0x0} <repeats 127 times>, {pte = 0x539b01}, {
  232. pte = 0x0} <repeats 896 times>, {pte = 0x719303}, {pte = 0x6d5303}, {
  233. pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {
  234. pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {pte = 0x6a1303}, {
  235. pte = 0x0} <repeats 12 times>, {pte = 0x709303}, {pte = 0x0}, {pte = 0x0},
  236. {pte = 0x6fd303}, {pte = 0x6f9303}, {pte = 0x6f5303}, {pte = 0x0}, {
  237. pte = 0x6ed303}, {pte = 0x531b01}, {pte = 0x50db01}, {
  238. pte = 0x0} <repeats 13 times>, {pte = 0x5303}, {pte = 0x7f5303}, {
  239. pte = 0x509b01}, {pte = 0x505b01}, {pte = 0x7c9303}, {pte = 0x7b9303}, {
  240. pte = 0x7b5303}, {pte = 0x7b1303}, {pte = 0x7ad303}, {pte = 0x0}, {
  241. pte = 0x0}, {pte = 0x7a1303}, {pte = 0x0}, {pte = 0x795303}, {pte = 0x0}, {
  242. pte = 0x78d303}, {pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {pte = 0x0}, {
  243. pte = 0x0}, {pte = 0x775303}, {pte = 0x771303}, {pte = 0x76d303}, {
  244. pte = 0x0}, {pte = 0x765303}, {pte = 0x7c5303}, {pte = 0x501b01}, {
  245. pte = 0x4f1b01}, {pte = 0x4edb01}, {pte = 0x0}, {pte = 0x4f9b01}, {
  246. pte = 0x4fdb01}, {pte = 0x0} <repeats 2992 times>}