mem.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Memory and machine-specific definitions. Used in C and assembler.
  3. */
  4. /*
  5. * Sizes
  6. */
  7. #define BI2BY 8 /* bits per byte */
  8. #define BI2WD 32 /* bits per word */
  9. #define BY2WD 4 /* bytes per word */
  10. #define BY2V 8 /* bytes per double word */
  11. #define BY2PG 4096 /* bytes per page */
  12. #define WD2PG (BY2PG/BY2WD) /* words per page */
  13. #define PGSHIFT 12 /* log(BY2PG) */
  14. #define ROUND(s, sz) (((s)+(sz-1))&~(sz-1))
  15. #define PGROUND(s) ROUND(s, BY2PG)
  16. #define BIT(n) (1<<n)
  17. #define BITS(a,b) ((1<<(b+1))-(1<<a))
  18. #define MAXMACH 1 /* max # cpus system can run */
  19. /*
  20. * Time
  21. */
  22. #define HZ (100) /* clock frequency */
  23. #define MS2HZ (1000/HZ) /* millisec per clock tick */
  24. #define TK2SEC(t) ((t)/HZ) /* ticks to seconds */
  25. #define MS2TK(t) ((t)/MS2HZ) /* milliseconds to ticks */
  26. /*
  27. * More accurate time
  28. */
  29. #define CLOCKFREQ 3686400
  30. #define MS2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000))
  31. #define US2TMR(t) ((ulong)(((uvlong)(t)*CLOCKFREQ)/1000000))
  32. /*
  33. * Address spaces
  34. * nearly everything maps 1-1 with physical addresses
  35. * 0 to 1Mb is not mapped
  36. * cache strategy varies as needed (see mmu.c)
  37. */
  38. #define KZERO 0xC0000000
  39. #define MACHADDR (KZERO+0x00001000)
  40. #define KTTB (KZERO+0x00004000)
  41. #define KTZERO (KZERO+0x00008010)
  42. #define KSTACK 8192 /* Size of kernel stack */
  43. #define FLASHMEM 0x50000000 /* map flash at phys 0 to otherwise unused virtual space */
  44. #define FLUSHMEM 0xE0000000 /* internally decoded zero memory (for cache flushing) */
  45. #define DCFADDR FLUSHMEM /* cached and buffered for cache writeback */
  46. #define MCFADDR (FLUSHMEM+(1<<20)) /* cached and unbuffered for minicache writeback */
  47. #define UCDRAMZERO 0xC8000000 /* base of memory doubly-mapped as uncached */
  48. #define AIVECADDR 0xFFFF0000 /* alternative interrupt vector address (other is 0) */
  49. /*
  50. * Physical addresses
  51. */
  52. #define PHYSFLASH0 0x00000000 /* flash (chip select 0) */
  53. #define PHYSCS1 0x08000000 /* static chip select 1 */
  54. #define PHYSCS2 0x10000000 /* static chip select 2 */
  55. #define PHYSCS3 0x18000000 /* static chip select 3 */
  56. #define PHYSPCMCIA0 0x20000000 /* PCMCIA socket 0 space */
  57. #define PHYSPCMCIA1 0x30000000 /* PCMCIA socket 1 space */
  58. #define PCMCIASIZE 0x10000000 /* they're both huge */
  59. #define PHYSCS4 0x40000000 /* static chip select 4 */
  60. #define PHYSCS5 0x48000000 /* static chip select 5 */
  61. #define PHYSSERIAL(n) (0x80000000+0x10000*(n)) /* serial devices */
  62. #define PHYSUSB 0x80000000
  63. #define PHYSGPCLK 0x80020060
  64. #define PHYSMCP 0x80060000
  65. #define PHYSSSP 0x80070060
  66. #define PHYSOSTMR 0x90000000 /* timers */
  67. #define PHYSRTC 0x90010000 /* real time clock */
  68. #define PHYSPOWER 0x90020000 /* power management registers */
  69. #define PHYSRESET 0x90030000 /* reset controller */
  70. #define PHYSGPIO 0x90040000
  71. #define PHYSINTR 0x90050000 /* interrupt controller */
  72. #define PHYSPPC 0x90060000 /* peripheral pin controller */
  73. #define PHYSMEMCFG 0xA0000000 /* memory configuration */
  74. #define PHYSDMA 0xB0000000 /* DMA controller */
  75. #define PHYSLCD 0xB0100000 /* LCD controller */
  76. #define PHYSMEM0 0xC0000000
  77. #define PHYSFLUSH0 0xE0000000 /* internally decoded, for cache flushing */
  78. /*
  79. * Memory Interface Control Registers
  80. */
  81. #define MDCNFG (PHYSMEMCFG) /* memory controller configuration */
  82. #define MDCAS0 (PHYSMEMCFG+4)
  83. #define MDCAS1 (PHYSMEMCFG+8)
  84. #define MDCAS2 (PHYSMEMCFG+0xC)
  85. #define MSC0 (PHYSMEMCFG+0x10)
  86. #define MSC1 (PHYSMEMCFG+0x14)
  87. #define MSC2 (PHYSMEMCFG+0x2C) /* SA1110, but not SA1100 */
  88. #define MSCx(RRR, RDN, RDF, RBW, RT) ((((RRR)&0x7)<<13)|(((RDN)&0x1F)<<8)|(((RDF)&0x1F)<<3)|(((RBW)&1)<<2)|((RT)&3))
  89. #define CACHELINELOG 5
  90. #define CACHELINESZ (1<<CACHELINELOG)
  91. /*
  92. * PSR
  93. */
  94. #define PsrMusr 0x10 /* mode */
  95. #define PsrMfiq 0x11
  96. #define PsrMirq 0x12
  97. #define PsrMsvc 0x13
  98. #define PsrMabt 0x17
  99. #define PsrMund 0x1B
  100. #define PsrMsys 0x1F
  101. #define PsrMask 0x1F
  102. #define PsrDfiq 0x00000040 /* disable FIQ interrupts */
  103. #define PsrDirq 0x00000080 /* disable IRQ interrupts */
  104. #define PsrV 0x10000000 /* overflow */
  105. #define PsrC 0x20000000 /* carry/borrow/extend */
  106. #define PsrZ 0x40000000 /* zero */
  107. #define PsrN 0x80000000 /* negative/less than */
  108. /*
  109. * Internal MMU coprocessor registers
  110. */
  111. #define CpCPUID 0 /* R: */
  112. #define CpControl 1 /* R/W: */
  113. #define CpTTB 2 /* R/W: translation table base */
  114. #define CpDAC 3 /* R/W: domain access control */
  115. #define CpFSR 5 /* R/W: fault status */
  116. #define CpFAR 6 /* R/W: fault address */
  117. #define CpCacheCtl 7 /* W: */
  118. #define CpTLBops 8 /* W: TLB operations */
  119. #define CpRBops 9 /* W: Read Buffer operations */
  120. #define CpPID 13 /* R/W: Process ID Virtual Mapping */
  121. #define CpDebug 14 /* R/W: debug registers */
  122. #define CpTest 15 /* W: Test, Clock and Idle Control */
  123. /*
  124. * Coprocessors
  125. */
  126. #define CpMMU 15
  127. #define CpPWR 15
  128. /*
  129. * CpControl bits
  130. */
  131. #define CpCmmu 0x00000001 /* M: MMU enable */
  132. #define CpCalign 0x00000002 /* A: alignment fault enable */
  133. #define CpCDcache 0x00000004 /* C: instruction/data cache on */
  134. #define CpCwb 0x00000008 /* W: write buffer turned on */
  135. #define CpCi32 0x00000010 /* P: 32-bit programme space */
  136. #define CpCd32 0x00000020 /* D: 32-bit data space */
  137. #define CpCbe 0x00000080 /* B: big-endian operation */
  138. #define CpCsystem 0x00000100 /* S: system permission */
  139. #define CpCrom 0x00000200 /* R: ROM permission */
  140. #define CpCIcache 0x00001000 /* I: Instruction Cache on */
  141. #define CpCaltivec 0x00002000 /* X: alternative interrupt vectors */
  142. /*
  143. * MMU
  144. */
  145. /*
  146. * Small pages:
  147. * L1: 12-bit index -> 4096 descriptors -> 16Kb
  148. * L2: 8-bit index -> 256 descriptors -> 1Kb
  149. * Each L2 descriptor has access permissions for 4 1Kb sub-pages.
  150. *
  151. * TTB + L1Tx gives address of L1 descriptor
  152. * L1 descriptor gives PTBA
  153. * PTBA + L2Tx gives address of L2 descriptor
  154. * L2 descriptor gives PBA
  155. */
  156. #define MmuSection (1<<20)
  157. #define MmuLargePage (1<<16)
  158. #define MmuSmallPage (1<<12)
  159. #define MmuTTB(pa) ((pa) & ~0x3FFF) /* translation table base */
  160. #define MmuL1x(pa) (((pa)>>20) & 0xFFF) /* L1 table index */
  161. #define MmuPTBA(pa) ((pa) & ~0x3FF) /* page table base address */
  162. #define MmuL2x(pa) (((pa)>>12) & 0xFF) /* L2 table index */
  163. #define MmuPBA(pa) ((pa) & ~0xFFF) /* page base address */
  164. #define MmuSBA(pa) ((pa) & ~0xFFFFF) /* section base address */
  165. #define MmuL1type 0x03
  166. #define MmuL1page 0x01 /* descriptor is for L2 pages */
  167. #define MmuL1section 0x02 /* descriptor is for section */
  168. #define MmuL2invalid 0x000
  169. #define MmuL2large 0x001 /* large */
  170. #define MmuL2small 0x002 /* small */
  171. #define MmuWB 0x004 /* data goes through write buffer */
  172. #define MmuIDC 0x008 /* data placed in cache */
  173. #define MmuDAC(d) (((d) & 0xF)<<5) /* L1 domain */
  174. #define MmuAP(i, v) ((v)<<(((i)*2)+4)) /* access permissions */
  175. #define MmuL1AP(v) MmuAP(3, (v))
  176. #define MmuL2AP(v) MmuAP(3, (v))|MmuAP(2, (v))|MmuAP(1, (v))|MmuAP(0, (v))
  177. #define MmuAPsro 0 /* supervisor ro if S|R */
  178. #define MmuAPsrw 1 /* supervisor rw */
  179. #define MmuAPuro 2 /* supervisor rw + user ro */
  180. #define MmuAPurw 3 /* supervisor rw + user rw */