mem.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #define MAXMACH 1 /* max # cpus system can run */
  37. #define MACHSIZE BY2PG
  38. #define KSTKSIZE (8*KiB)
  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 is mapped to physical 0.
  45. * u-boot claims to take 0 - 8MB.
  46. *
  47. * vectors are at 0, plan9.ini is at KZERO+4K and is limited to 16K by
  48. * devenv. L2 PTEs for trap vectors & i/o regs are stored from KZERO+56K
  49. * to L1-MACHSIZE (KZERO+60K). cpu0's Mach struct is at L1 - MACHSIZE(4K)
  50. * to L1 (KZERO+60K to KZERO+64K). L1 PTEs are stored from L1 to L1+32K
  51. * (KZERO+64K to KZERO+96K). KTZERO may be anywhere after KZERO+96K.
  52. */
  53. #define KSEG0 0x60000000 /* kernel segment */
  54. /* mask to check segment; good for 512MB dram */
  55. #define KSEGM 0xE0000000
  56. #define KZERO KSEG0 /* kernel address space */
  57. #define CONFADDR (KZERO+4*KiB) /* unparsed plan9.ini */
  58. #define L1 (KZERO+64*KiB) /* tt ptes: 16KiB aligned */
  59. #define KTZERO (KZERO+0x800000) /* kernel text start */
  60. #define UZERO 0 /* user segment */
  61. #define UTZERO (UZERO+BY2PG) /* user text start */
  62. #define USTKTOP KZERO /* user segment end +1 */
  63. #define USTKSIZE (8*1024*1024) /* user stack size */
  64. #define TSTKTOP (USTKTOP-USTKSIZE) /* sysexec temporary stack */
  65. #define TSTKSIZ 256
  66. /* address at which to copy and execute rebootcode */
  67. #define REBOOTADDR KADDR(0x100)
  68. /*
  69. * Time.
  70. * Does this need to be here? Used in assembler?
  71. */
  72. #define HZ 100 /* clock frequency */
  73. #define MS2HZ (1000/HZ) /* millisec per clock tick */
  74. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  75. /*
  76. * More accurate time
  77. */
  78. #define CLOCKFREQ (200*1000*1000) /* TCLK on sheeva: 200MHz */
  79. //#define MS2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000))
  80. //#define US2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000000))
  81. /*
  82. * Legacy...
  83. */
  84. #define BLOCKALIGN 32 /* only used in allocb.c */
  85. #define KSTACK KSTKSIZE
  86. /*
  87. * Sizes
  88. */
  89. #define BI2BY 8 /* bits per byte */
  90. #define BY2SE 4
  91. #define BY2WD 4
  92. #define BY2V 8 /* only used in xalloc.c */
  93. #define CACHELINESZ 32
  94. #define PTEMAPMEM (1024*1024)
  95. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  96. #define SEGMAPSIZE 1984
  97. #define SSEGMAPSIZE 16
  98. #define PPN(x) ((x)&~(BY2PG-1))
  99. /*
  100. * With a little work these move to port.
  101. */
  102. #define PTEVALID (1<<0)
  103. #define PTERONLY 0
  104. #define PTEWRITE (1<<1)
  105. #define PTEUNCACHED (1<<2)
  106. #define PTEKERNEL (1<<3)
  107. /*
  108. * Physical machine information from here on.
  109. */
  110. #define PHYSDRAM 0
  111. /* from 0x80000000 up is uncached by L2 (see archkw.c) */
  112. #define PHYSCESASRAM 0xc8010000
  113. // #define PHYSSPIFLASH 0xe8000000 /* ignore spi flash */
  114. /* this address is configured by u-boot, and is 0xd0000000 at reset */
  115. #define PHYSIO 0xf1000000 /* internal registers */
  116. #define PHYSCONS (PHYSIO + 0x12000) /* uart */
  117. #define PHYSNAND1 0xf9000000 /* sheeva/openrd (remapped) */
  118. #define PHYSNAND2 0xd8000000 /* guru */
  119. #define PHYSBOOTROM 0xffff0000 /* boot rom */
  120. #define FLASHSIZE (512*MiB) /* but not addressed linearly */
  121. #define VIRTIO PHYSIO