mem.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Memory and machine-specific definitions. Used in C and assembler.
  3. */
  4. #define KiB 1024u /* Kibi 0x0000000000000400 */
  5. #define MiB 1048576u /* Mebi 0x0000000000100000 */
  6. #define GiB 1073741824u /* Gibi 000000000040000000 */
  7. #define HOWMANY(x, y) (((x)+((y)-1))/(y))
  8. #define ROUNDUP(x, y) (HOWMANY((x), (y))*(y)) /* ceiling */
  9. #define ROUNDDN(x, y) (((x)/(y))*(y)) /* floor */
  10. #define MIN(a, b) ((a) < (b)? (a): (b))
  11. #define MAX(a, b) ((a) > (b)? (a): (b))
  12. /*
  13. * Not sure where these macros should go.
  14. * This probably isn't right but will do for now.
  15. * The macro names are problematic too.
  16. */
  17. /*
  18. * In B(o), 'o' is the bit offset in the register.
  19. * For multi-bit fields use F(v, o, w) where 'v' is the value
  20. * of the bit-field of width 'w' with LSb at bit offset 'o'.
  21. */
  22. #define B(o) (1<<(o))
  23. #define F(v, o, w) (((v) & ((1<<(w))-1))<<(o))
  24. #define FCLR(d, o, w) ((d) & ~(((1<<(w))-1)<<(o)))
  25. #define FEXT(d, o, w) (((d)>>(o)) & ((1<<(w))-1))
  26. #define FINS(d, o, w, v) (FCLR((d), (o), (w))|F((v), (o), (w)))
  27. #define FSET(d, o, w) ((d)|(((1<<(w))-1)<<(o)))
  28. #define FMASK(o, w) (((1<<(w))-1)<<(o))
  29. /*
  30. * Sizes
  31. */
  32. #define PGSIZE (4*KiB) /* bytes per page */
  33. #define PGSHIFT 12 /* log(PGZIZE) */
  34. #define PGROUND(s) ROUNDUP(s, PGSIZE)
  35. #define ROUND(s, sz) (((s)+(sz-1))&~(sz-1))
  36. #define MAXMACH 1 /* max # cpus system can run */
  37. #define MACHSIZE (PGSIZE)
  38. #define KSTKSIZE (16*KiB) /* was 8K */
  39. #define STACKALIGN(sp) ((sp) & ~3) /* bug: assure with alloc */
  40. /*
  41. * Address spaces.
  42. * KTZERO is used by kprof and dumpstack (if any).
  43. *
  44. * KZERO (0xc0000000) is mapped to physical 0x80000000 (start of dram).
  45. * u-boot claims to occupy the first 3 MB of dram, but we're willing to
  46. * step on it once we're loaded. Expect plan9.ini in the first 64K past 3MB.
  47. *
  48. * L2 PTEs are stored in 1K before Mach (11K to 12K above KZERO).
  49. * cpu0's Mach struct is at L1 - MACHSIZE(4K) to L1 (12K to 16K above KZERO).
  50. * L1 PTEs are stored from L1 to L1+32K (16K to 48K above KZERO).
  51. * KTZERO may be anywhere after that (but probably shouldn't collide with
  52. * u-boot).
  53. * This should leave over 8K from KZERO to L2 PTEs.
  54. */
  55. #define KSEG0 0xC0000000 /* kernel segment */
  56. /* mask to check segment; good for 512MB dram */
  57. #define KSEGM 0xE0000000
  58. #define KZERO KSEG0 /* kernel address space */
  59. #define L1 (KZERO+16*KiB) /* tt ptes: 16KiB aligned */
  60. #define CONFADDR (KZERO+0x300000) /* unparsed plan9.ini */
  61. /* KTZERO must match loadaddr in mkfile */
  62. #define KTZERO (KZERO+0x310000) /* kernel text start */
  63. #define UZERO 0 /* user segment */
  64. #define UTZERO (UZERO+BY2PG) /* user text start */
  65. #define UTROUND(t) ROUNDUP((t), BY2PG)
  66. /* moved USTKTOP down to 512MB to keep MMIO space out of user space. */
  67. #define USTKTOP 0x20000000 /* user segment end +1 */
  68. #define USTKSIZE (8*1024*1024) /* user stack size */
  69. #define TSTKTOP (USTKTOP-USTKSIZE) /* sysexec temporary stack */
  70. #define TSTKSIZ 256
  71. /* address at which to copy and execute rebootcode */
  72. #define REBOOTADDR KADDR(0x100)
  73. /*
  74. * Legacy...
  75. */
  76. #define BLOCKALIGN 32 /* only used in allocb.c */
  77. #define KSTACK KSTKSIZE
  78. /*
  79. * Sizes
  80. */
  81. #define BI2BY 8 /* bits per byte */
  82. #define BY2PG PGSIZE
  83. #define BY2SE 4
  84. #define BY2WD 4
  85. #define BY2V 8 /* only used in xalloc.c */
  86. #define CACHELINESZ 64 /* bytes per cache line */
  87. #define PTEMAPMEM (1024*1024)
  88. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  89. #define SEGMAPSIZE 1984 /* magic 16*124 */
  90. #define SSEGMAPSIZE 16 /* magic */
  91. #define PPN(x) ((x)&~(BY2PG-1)) /* pure page number? */
  92. /*
  93. * With a little work these move to port.
  94. */
  95. #define PTEVALID (1<<0)
  96. #define PTERONLY 0
  97. #define PTEWRITE (1<<1)
  98. #define PTEUNCACHED (1<<2)
  99. #define PTEKERNEL (1<<3)
  100. /*
  101. * Physical machine information from here on.
  102. */
  103. /* gpmc-controlled address space 0—1G */
  104. #define PHYSNAND 1 /* cs0 is onenand flash */
  105. #define PHYSETHER 0x2c000000
  106. #define PHYSIO 0x48000000 /* L4 ctl */
  107. #define PHYSSCM 0x48002000 /* system control module */
  108. /* core control pad cfg 0x48002030—0x480021e4, */
  109. /* core control d2d pad cfg 0x480021e4—0x48002264 */
  110. #define PHYSSCMPCONF 0x48002270 /* general device config */
  111. #define PHYSOMAPSTS 0x4800244c /* standalone short: has l2 size */
  112. /* core control pad cfg (2) 0x480025d8—0x480025fc */
  113. #define PHYSSWBOOTCFG 0x48002910 /* sw booting config */
  114. /* wakeup control pad cfg 0x48002a00—0x48002a54 */
  115. #define PHYSSCMMPU 0x48004900 /* actually CPU */
  116. #define PHYSSCMCORE 0x48004a00
  117. #define PHYSSCMWKUP 0x48004c00
  118. #define PHYSSCMPLL 0x48004d00 /* clock ctl for dpll[3-5] */
  119. #define PHYSSCMPER 0x48005000
  120. #define PHYSSCMUSB 0x48005400
  121. #define PHYSL4CORE 0x48040100 /* l4 ap */
  122. #define PHYSSDMA 0x48056000 /* system dma */
  123. #define PHYSDMA 0x48060000
  124. #define PHYSUSBTLL 0x48062000 /* usb: transceiver-less link */
  125. #define PHYSUHH 0x48064000 /* usb: `high-speed usb host' ctlr or subsys */
  126. #define PHYSOHCI 0x48064400 /* usb 1.0: slow */
  127. #define PHYSEHCI 0x48064800 /* usb 2.0: medium */
  128. #define PHYSUART0 0x4806a000
  129. #define PHYSUART1 0x4806c000
  130. #define PHYSUSBOTG 0x480ab000 /* on-the-go usb */
  131. #define PHYSINTC 0x48200000 /* interrupt controller */
  132. #define PHYSPRMIVA2 0x48206000 /* prm iva2 regs */
  133. /* 48306d40 sys_clkin_sel */
  134. #define PHYSPRMGLBL 0x48307200 /* prm global regs */
  135. #define PHYSPRMWKUSB 0x48307400
  136. #define PHYSCNTRL 0x4830a200 /* SoC id, etc. */
  137. #define PHYSWDT1 0x4830c000 /* wdt1, not on GP omaps */
  138. #define PHYSWDOG 0x48314000 /* watchdog timer, wdt2 */
  139. #define PHYSWDT2 0x48314000 /* watchdog timer, wdt2 */
  140. #define PHYSTIMER1 0x48318000
  141. #define PHYSL4WKUP 0x48328100 /* l4 wkup */
  142. #define PHYSL4PER 0x49000100 /* l4 per */
  143. #define PHYSCONS 0x49020000 /* uart console (third one) */
  144. #define PHYSWDT3 0x49030000 /* wdt3 */
  145. #define PHYSTIMER2 0x49032000
  146. #define PHYSTIMER3 0x49034000
  147. #define PHYSGPIO5 0x49056000
  148. #define PHYSGPIO6 0x49058000 /* contains igep ether gpio */
  149. #define PHYSIOEND 0x49100000 /* end of PHYSIO identity map */
  150. #define PHYSL4EMU 0x54006100 /* l4 emu */
  151. #define PHYSL4PROT 0x54728000 /* l4 protection regs */
  152. #define PHYSL3 0x68000000 /* l3 interconnect control */
  153. #define PHYSL3GPMCCFG 0x68002000 /* l3 gpmc target port agent cfg */
  154. #define PHYSL3USB 0x68004000 /* l3 regs for usb */
  155. #define PHYSL3USBOTG 0x68004400 /* l3 regs for usb otg */
  156. /* (target port) protection registers */
  157. #define PHYSL3PMRT 0x68010000 /* l3 PM register target prot. */
  158. #define PHYSL3GPMCPM 0x68012400 /* l3 gpmc target port protection */
  159. #define PHYSL3OCTRAM 0x68012800 /* l3 ocm ram */
  160. #define PHYSL3OCTROM 0x68012c00 /* l3 ocm rom */
  161. #define PHYSL3MAD2D 0x68013000 /* l3 die-to-die */
  162. #define PHYSL3IVA 0x68014000 /* l3 die-to-die */
  163. #define PHYSSMS 0x6c000000 /* cfg regs: sms addr space 2 */
  164. #define PHYSDRC 0x6d000000 /* sdram ctlr, addr space 3 */
  165. #define PHYSGPMC 0x6e000000 /* flash, non-dram memory ctlr */
  166. #define PHYSDRAM 0x80000000
  167. #define VIRTNAND 0x20000000 /* fixed by u-boot */
  168. #define VIRTIO PHYSIO