mem.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * Sizes
  14. */
  15. #define BY2PG (4*KiB) /* bytes per page */
  16. #define PGSHIFT 12 /* log(BY2PG) */
  17. #define PGROUND(s) ROUNDUP(s, BY2PG)
  18. #define ROUND(s, sz) (((s)+(sz-1))&~(sz-1))
  19. #define MAXMACH 1 /* max # cpus system can run */
  20. #define MACHSIZE BY2PG
  21. #define KSTKSIZE (8*KiB)
  22. #define STACKALIGN(sp) ((sp) & ~3) /* bug: assure with alloc */
  23. /*
  24. * Address spaces.
  25. * KTZERO is used by kprof and dumpstack (if any).
  26. *
  27. * KZERO is mapped to physical 0 (start of ram).
  28. *
  29. * vectors are at 0, plan9.ini is at KZERO+256 and is limited to 16K by
  30. * devenv.
  31. */
  32. #define KSEG0 0x80000000 /* kernel segment */
  33. /* mask to check segment; good for 512MB dram */
  34. #define KSEGM 0xE0000000
  35. #define KZERO KSEG0 /* kernel address space */
  36. #define CONFADDR (KZERO+0x100) /* unparsed plan9.ini */
  37. #define MACHADDR (KZERO+0x2000) /* Mach structure */
  38. #define L2 (KZERO+0x3000) /* L2 ptes for vectors etc */
  39. #define VCBUFFER (KZERO+0x3400) /* videocore mailbox buffer */
  40. #define FIQSTKTOP (KZERO+0x4000) /* FIQ stack */
  41. #define L1 (KZERO+0x4000) /* tt ptes: 16KiB aligned */
  42. #define KTZERO (KZERO+0x8000) /* kernel text start */
  43. #define VIRTIO 0x7E000000 /* i/o registers */
  44. #define FRAMEBUFFER 0xA0000000 /* video framebuffer */
  45. #define UZERO 0 /* user segment */
  46. #define UTZERO (UZERO+BY2PG) /* user text start */
  47. #define USTKTOP 0x20000000 /* user segment end +1 */
  48. #define USTKSIZE (8*1024*1024) /* user stack size */
  49. #define TSTKTOP (USTKTOP-USTKSIZE) /* sysexec temporary stack */
  50. #define TSTKSIZ 256
  51. /* address at which to copy and execute rebootcode */
  52. #define REBOOTADDR (KZERO+0x3400)
  53. /*
  54. * Legacy...
  55. */
  56. #define BLOCKALIGN 32 /* only used in allocb.c */
  57. #define KSTACK KSTKSIZE
  58. /*
  59. * Sizes
  60. */
  61. #define BI2BY 8 /* bits per byte */
  62. #define BY2SE 4
  63. #define BY2WD 4
  64. #define BY2V 8 /* only used in xalloc.c */
  65. #define CACHELINESZ 32
  66. #define PTEMAPMEM (1024*1024)
  67. #define PTEPERTAB (PTEMAPMEM/BY2PG)
  68. #define SEGMAPSIZE 1984
  69. #define SSEGMAPSIZE 16
  70. #define PPN(x) ((x)&~(BY2PG-1))
  71. /*
  72. * With a little work these move to port.
  73. */
  74. #define PTEVALID (1<<0)
  75. #define PTERONLY 0
  76. #define PTEWRITE (1<<1)
  77. #define PTEUNCACHED (1<<2)
  78. #define PTEKERNEL (1<<3)
  79. /*
  80. * Physical machine information from here on.
  81. * PHYS addresses as seen from the arm cpu.
  82. * BUS addresses as seen from the videocore gpu.
  83. */
  84. #define PHYSDRAM 0
  85. #define BUSDRAM 0x40000000
  86. #define DRAMSIZE (512*MiB)
  87. #define PHYSIO 0x20000000
  88. #define BUSIO 0x7E000000
  89. #define IOSIZE (16*MiB)