]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/bitsy/mem.h
merge
[plan9front.git] / sys / src / 9 / bitsy / mem.h
1 /*
2  * Memory and machine-specific definitions.  Used in C and assembler.
3  */
4
5 /*
6  * Sizes
7  */
8 #define BI2BY           8                       /* bits per byte */
9 #define BI2WD           32                      /* bits per word */
10 #define BY2WD           4                       /* bytes per word */
11 #define BY2V            8                       /* bytes per double word */
12 #define BY2PG           4096                    /* bytes per page */
13 #define WD2PG           (BY2PG/BY2WD)           /* words per page */
14 #define PGSHIFT         12                      /* log(BY2PG) */
15 #define ROUND(s, sz)    (((s)+(sz-1))&~(sz-1))
16 #define PGROUND(s)      ROUND(s, BY2PG)
17 #define BLOCKALIGN      8
18
19 #define MAXMACH 1                       /* max # cpus system can run */
20
21 /*
22  * Time
23  */
24 #define HZ              (20)                            /* clock frequency */
25 #define MS2HZ   (1000/HZ)               /* millisec per clock tick */
26 #define TK2SEC(t)       ((t)/HZ)                        /* ticks to seconds */
27
28 /*
29  *  Virtual addresses:
30  *
31  *  We direct map all discovered DRAM and the area twixt 0xe0000000 and
32  *  0xe8000000 used to provide zeros for cache flushing.
33  *
34  *  Flash is mapped to 0xb0000000 and special registers are mapped
35  *  on demand to areas starting at 0xa0000000.
36  *
37  *  The direct mapping is convenient but not necessary.  It means
38  *  that we don't have to turn on the MMU till well into the
39  *  kernel.  This can be changed by providing a mapping in l.s
40  *  before calling main.
41  */
42 #define UZERO           0                               /* base of user address space */
43 #define UTZERO          (UZERO+BY2PG)   /* first address in user text */
44 #define KZERO           0xC0000000              /* base of kernel address space */
45 #define KTZERO          0xC0008000              /* first address in kernel text */
46 #define EMEMZERO        0x90000000              /* 256 meg for add on memory */
47 #define EMEMTOP         0xA0000000              /* ... */
48 #define REGZERO         0xA0000000              /* 128 meg for mapspecial regs */
49 #define REGTOP          0xA8000000              /* ... */
50 #define FLASHZERO       0xB0000000              /* 128 meg for flash */
51 #define FLASHTOP        0xB8000000              /* ... */
52 #define DRAMZERO        0xC0000000              /* 128 meg for dram */
53 #define DRAMTOP         0xC8000000              /* ... */
54 #define UCDRAMZERO      0xC8000000              /* 128 meg for dram (uncached/unbuffered) */
55 #define UCDRAMTOP       0xD0000000              /* ... */
56 #define NULLZERO        0xE0000000              /* 128 meg for cache flush zeroes */
57 #define NULLTOP         0xE8000000              /* ... */
58 #define USTKTOP         0x2000000               /* byte just beyond user stack */
59 #define USTKSIZE                (8*1024*1024)           /* size of user stack */
60 #define MACHADDR        (KZERO+0x00001000)
61 #define EVECTORS        0xFFFF0000              /* virt base of exception vectors */
62
63 #define KSTACK          (16*1024)                       /* Size of kernel stack */
64
65 /*
66  *  Offsets into flash
67  */
68 #define Flash_bootldr   (FLASHZERO+0x0)         /* boot loader */
69 #define Flash_kernel    (FLASHZERO+0x10000)     /* boot kernel */
70 #define Flash_tar               (FLASHZERO+0x200000)    /* fs.sac (tar file) */
71
72 /*
73  *  virtual MMU
74  */
75 #define PTEMAPMEM       (1024*1024)     
76 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
77 #define SEGMAPSIZE      1984
78 #define SSEGMAPSIZE     16
79 #define PPN(x)          ((x)&~(BY2PG-1))
80
81 /*
82  *  SA1110 definitions
83  */
84
85 /*
86  *  memory physical addresses
87  */
88 #define PHYSFLASH0      0x00000000
89 #define PHYSDRAM0       0xC0000000
90 #define PHYSNULL0       0xE0000000
91
92 /*
93  *  peripheral control module physical addresses
94  */
95 #define USBREGS         0x80000000      /* serial port 0 - USB */
96 #define UART1REGS               0x80010000      /* serial port 1 - UART */
97 #define GPCLKREGS               0x80020060      /* serial port 1 - general purpose clock */
98 #define UART2REGS               0x80030000      /* serial port 2 - low speed IR */
99 #define HSSPREGS                0x80040060      /* serial port 2 - high speed IR */
100 #define UART3REGS               0x80050000      /* serial port 3 - RS232 UART */
101 #define MCPREGS         0x80060000      /* serial port 4 - multimedia comm port */
102 #define SSPREGS         0x80070060      /* serial port 4 - synchronous serial port */
103 #define OSTIMERREGS     0x90000000      /* operating system timer registers */
104 #define POWERREGS               0x90020000      /* power management */
105 #define RESETREGS               0x90030000      /* reset controller */
106 #define GPIOREGS                0x90040000      /* 28 general purpose IO pins */
107 #define INTRREGS                0x90050000      /* interrupt registers */
108 #define PPCREGS         0x90060000      /* peripheral pin controller */
109 #define MEMCONFREGS     0xA0000000      /* memory configuration */
110 #define LCDREGS         0xB0100000      /* display */
111
112 /*
113  *  PCMCIA addresses
114  */
115 #define PHYSPCM0REGS    0x20000000
116 #define PYHSPCM0ATTR    0x28000000
117 #define PYHSPCM0MEM     0x2C000000
118 #define PHYSPCM1REGS    0x30000000
119 #define PYHSPCM1ATTR    0x38000000
120 #define PYHSPCM1MEM     0x3C000000
121
122 /*
123  *  Program Status Registers
124  */
125 #define PsrMusr         0x00000010      /* mode */
126 #define PsrMfiq         0x00000011
127 #define PsrMirq         0x00000012
128 #define PsrMsvc         0x00000013
129 #define PsrMabt         0x00000017
130 #define PsrMund         0x0000001B
131 #define PsrMask         0x0000001F
132
133 #define PsrDfiq         0x00000040      /* disable FIQ interrupts */
134 #define PsrDirq         0x00000080      /* disable IRQ interrupts */
135
136 #define PsrV            0x10000000      /* overflow */
137 #define PsrC            0x20000000      /* carry/borrow/extend */
138 #define PsrZ            0x40000000      /* zero */
139 #define PsrN            0x80000000      /* negative/less than */
140
141 /*
142  *  Coprocessors
143  */
144 #define CpMMU           15
145 #define CpPWR           15
146
147 /*
148  *  Internal MMU coprocessor registers
149  */
150 #define CpCPUID         0               /* R: */
151 #define CpControl       1               /* RW: */
152 #define CpTTB           2               /* RW: translation table base */
153 #define CpDAC           3               /* RW: domain access control */
154 #define CpFSR           5               /* RW: fault status */
155 #define CpFAR           6               /* RW: fault address */
156 #define CpCacheFlush    7               /* W: cache flushing, wb draining*/
157 #define CpTLBFlush      8               /* W: TLB flushing */
158 #define CpRBFlush       9               /* W: Read Buffer ops */
159 #define CpPID           13              /* RW: PID for virtual mapping */
160 #define CpBpt           14              /* W: Breakpoint register */
161 #define CpTest          15              /* W: Test, Clock and Idle Control */
162
163 /*
164  *  CpControl
165  */
166 #define CpCmmuena       0x00000001      /* M: MMU enable */
167 #define CpCalign        0x00000002      /* A: alignment fault enable */
168 #define CpCdcache       0x00000004      /* C: data cache on */
169 #define CpCwb           0x00000008      /* W: write buffer turned on */
170 #define CpCi32          0x00000010      /* P: 32-bit program space */
171 #define CpCd32          0x00000020      /* D: 32-bit data space */
172 #define CpCbe           0x00000080      /* B: big-endian operation */
173 #define CpCsystem       0x00000100      /* S: system permission */
174 #define CpCrom          0x00000200      /* R: ROM permission */
175 #define CpCicache       0x00001000      /* I: instruction cache on */
176 #define CpCvivec        0x00002000      /* X: virtual interrupt vector adjust */
177
178 /*
179  *  fault codes
180  */
181 #define FCterm          0x2     /* terminal */
182 #define FCvec           0x0     /* vector */
183 #define FCalignf        0x1     /* unaligned full word data access */
184 #define FCalignh        0x3     /* unaligned half word data access */
185 #define FCl1abort       0xc     /* level 1 external abort on translation */
186 #define FCl2abort       0xe     /* level 2 external abort on translation */
187 #define FCtransSec      0x5     /* section translation */
188 #define FCtransPage     0x7     /* page translation */
189 #define FCdomainSec     0x9     /* section domain  */
190 #define FCdomainPage    0x11    /* page domain */
191 #define FCpermSec       0x9     /* section permissions  */
192 #define FCpermPage      0x11    /* page permissions */
193 #define FCabortLFSec    0x4     /* external abort on linefetch for section */
194 #define FCabortLFPage   0x6     /* external abort on linefetch for page */
195 #define FCabortNLFSec   0x8     /* external abort on non-linefetch for section */
196 #define FCabortNLFPage  0xa     /* external abort on non-linefetch for page */
197
198 /*
199  *  PTE bits used by fault.h.  mmu.c translates them to real values.
200  */
201 #define PTEVALID        (1<<0)
202 #define PTERONLY        0       /* this is implied by the absence of PTEWRITE */
203 #define PTEWRITE        (1<<1)
204 #define PTEUNCACHED     (1<<2)
205 #define PTEKERNEL       (1<<3)  /* no user access */
206
207 /*
208  *  H3650 specific definitions
209  */
210 #define EGPIOREGS       0x49000000      /* Additional GPIO register */
211
212 /* Power management */
213
214 #define PWR_rtc         0x80000000      /* resume on RTC */
215 #define PWR_gpio0       0x00000001      /* resume on power button */
216
217 #define RCSR_all        0x0000000f
218 #define PCFR_opde       0x00000001      /* oscillator power-down enable */
219 #define PCFR_suspend    0x00000001
220 #define PCFR_fp         0x00000002      /* float pcmcia */
221 #define PCFR_fs         0x00000004      /* float static memory */
222 #define PCFR_fo         0x00000008
223
224 #define MDREFR_k1db2    (1 << 22)
225 #define MDREFR_slfrsh   0x80000000      /* self refresh */
226 #define MDREFR_e1pin    (1 << 20)
227 #define MSC_rt          0x00030003
228
229 #define MDCNFG_de0      0x00000001      /* dram enable */
230 #define MDCNFG_de1      0x00000002
231 #define MDCNFG_de2      0x00000004
232 #define MDCNFG_de3      0x00000008
233 #define MDCFNG_de       0x0000000f
234 #define PMCR_sf         1