mem.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 BY2PG (4*KiB) /* bytes per page */
  33. #define PGSHIFT 12 /* log(BY2PG) */
  34. #define PGROUND(s) ROUNDUP(s, BY2PG)
  35. #define ROUND(s, sz) (((s)+(sz-1))&~(sz-1))
  36. /* max # of cpus system can run. tegra2 cpu ids are two bits wide. */
  37. #define MAXMACH 4
  38. #define MACHSIZE BY2PG
  39. #define L1SIZE (4 * BY2PG)
  40. #define KSTKSIZE (16*KiB) /* was 8K */
  41. #define STACKALIGN(sp) ((sp) & ~7) /* bug: assure with alloc */
  42. /*
  43. * Magic registers
  44. */
  45. #define USER 9 /* R9 is up-> */
  46. #define MACH 10 /* R10 is m-> */
  47. /*
  48. * Address spaces.
  49. * KTZERO is used by kprof and dumpstack (if any).
  50. *
  51. * KZERO (0xc0000000) is mapped to physical 0 (start of dram).
  52. * u-boot claims to occupy the first 4 MB of dram, but we're willing to
  53. * step on it once we're loaded.
  54. *
  55. * L2 PTEs are stored in 4K before cpu0's Mach (8K to 12K above KZERO).
  56. * cpu0's Mach struct is at L1 - MACHSIZE(4K) to L1 (12K to 16K above KZERO).
  57. * L1 PTEs are stored from L1 to L1+32K (16K to 48K above KZERO).
  58. * plan9.ini is loaded at CONFADDR (4MB).
  59. * KTZERO may be anywhere after that.
  60. */
  61. #define KSEG0 0xC0000000 /* kernel segment */
  62. /* mask to check segment; good for 1GB dram */
  63. #define KSEGM 0xC0000000
  64. #define KZERO KSEG0 /* kernel address space */
  65. #define L1 (KZERO+16*KiB) /* cpu0 l1 page table; 16KiB aligned */
  66. #define CONFADDR (KZERO+0x400000) /* unparsed plan9.ini */
  67. #define CACHECONF (CONFADDR+48*KiB)
  68. /* KTZERO must match loadaddr in mkfile */
  69. #define KTZERO (KZERO+0x410000) /* kernel text start */
  70. #define L2pages (2*MiB) /* high memory reserved for l2 page tables */
  71. #define RESRVDHIMEM (64*KiB + MiB + L2pages) /* avoid HVECTOR, l2 pages */
  72. /* we assume that we have 1 GB of ram, which is true for all trimslices. */
  73. #define DRAMSIZE GiB
  74. #define UZERO 0 /* user segment */
  75. #define UTZERO (UZERO+BY2PG) /* user text start */
  76. #define UTROUND(t) ROUNDUP((t), BY2PG)
  77. /*
  78. * moved USTKTOP down to 1GB to keep MMIO space out of user space.
  79. * moved it down another MB to utterly avoid KADDR(stack_base) mapping
  80. * to high exception vectors. see confinit().
  81. */
  82. #define USTKTOP (0x40000000 - 64*KiB - MiB) /* user segment end +1 */
  83. #define USTKSIZE (8*1024*1024) /* user stack size */
  84. #define TSTKTOP (USTKTOP-USTKSIZE) /* sysexec temporary stack */
  85. #define TSTKSIZ 256
  86. /* address at which to copy and execute rebootcode */
  87. #define REBOOTADDR KADDR(0x100)
  88. /*
  89. * Legacy...
  90. */
  91. #define BLOCKALIGN CACHELINESZ /* only used in allocb.c */
  92. #define KSTACK KSTKSIZE
  93. /*
  94. * Sizes
  95. */
  96. #define BI2BY 8 /* bits per byte */
  97. #define BY2SE 4
  98. #define BY2WD 4
  99. #define BY2V 8 /* only used in xalloc.c */
  100. #define CACHELINESZ 32 /* bytes per cache line */
  101. #define PTEMAPMEM (1024*1024)
  102. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  103. #define SEGMAPSIZE 1984 /* magic 16*124 */
  104. #define SSEGMAPSIZE 16 /* magic */
  105. #define PPN(x) ((x)&~(BY2PG-1)) /* pure page number? */
  106. /*
  107. * With a little work these move to port.
  108. */
  109. #define PTEVALID (1<<0)
  110. #define PTERONLY 0
  111. #define PTEWRITE (1<<1)
  112. #define PTEUNCACHED (1<<2)
  113. #define PTEKERNEL (1<<3)
  114. /*
  115. * Physical machine information from here on.
  116. */
  117. #define PHYSDRAM 0
  118. #define PHYSIO 0x50000000 /* cpu */
  119. #define VIRTIO PHYSIO
  120. #define PHYSL2BAG 0x50043000 /* l2 cache bag-on-the-side */
  121. #define PHYSEVP 0x6000f100 /* undocumented `exception vector' */
  122. #define PHYSCONS 0x70006000 /* uart console */
  123. #define PHYSIOEND 0xc0000000 /* end of ahb mem & pcie */
  124. #define PHYSAHB 0xc0000000 /* ahb bus */
  125. #define VIRTAHB 0xb0000000
  126. #define P2VAHB(pa) ((pa) - PHYSAHB + VIRTAHB)
  127. #define PHYSNOR 0xd0000000
  128. #define VIRTNOR 0x40000000