]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/omap/mem.h
kernel: dont use atomic increment for Proc.nlocks, maintain Lock.m for lock(), use...
[plan9front.git] / sys / src / 9 / omap / mem.h
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
8 #define HOWMANY(x, y)   (((x)+((y)-1))/(y))
9 #define ROUNDUP(x, y)   (HOWMANY((x), (y))*(y)) /* ceiling */
10 #define ROUNDDN(x, y)   (((x)/(y))*(y))         /* floor */
11 #define MIN(a, b)       ((a) < (b)? (a): (b))
12 #define MAX(a, b)       ((a) > (b)? (a): (b))
13
14 /*
15  * Not sure where these macros should go.
16  * This probably isn't right but will do for now.
17  * The macro names are problematic too.
18  */
19 /*
20  * In B(o), 'o' is the bit offset in the register.
21  * For multi-bit fields use F(v, o, w) where 'v' is the value
22  * of the bit-field of width 'w' with LSb at bit offset 'o'.
23  */
24 #define B(o)            (1<<(o))
25 #define F(v, o, w)      (((v) & ((1<<(w))-1))<<(o))
26
27 #define FCLR(d, o, w)   ((d) & ~(((1<<(w))-1)<<(o)))
28 #define FEXT(d, o, w)   (((d)>>(o)) & ((1<<(w))-1))
29 #define FINS(d, o, w, v) (FCLR((d), (o), (w))|F((v), (o), (w)))
30 #define FSET(d, o, w)   ((d)|(((1<<(w))-1)<<(o)))
31
32 #define FMASK(o, w)     (((1<<(w))-1)<<(o))
33
34 /*
35  * Sizes
36  */
37 #define BY2PG           (4*KiB)                 /* bytes per page */
38 #define PGSHIFT         12                      /* log(BY2PG) */
39 #define PGROUND(s)      ROUNDUP(s, BY2PG)
40 #define ROUND(s, sz)    (((s)+(sz-1))&~(sz-1))
41
42 #define MAXMACH         1                       /* max # cpus system can run */
43 #define MACHSIZE        BY2PG
44
45 #define KSTKSIZE        (16*KiB)                        /* was 8K */
46 #define STACKALIGN(sp)  ((sp) & ~3)             /* bug: assure with alloc */
47
48 /*
49  * Address spaces.
50  * KTZERO is used by kprof and dumpstack (if any).
51  *
52  * KZERO (0xc0000000) is mapped to physical 0x80000000 (start of dram).
53  * u-boot claims to occupy the first 3 MB of dram, but we're willing to
54  * step on it once we're loaded.  Expect plan9.ini in the first 64K past 3MB.
55  *
56  * L2 PTEs are stored in 1K before Mach (11K to 12K above KZERO).
57  * cpu0's Mach struct is at L1 - MACHSIZE(4K) to L1 (12K to 16K above KZERO).
58  * L1 PTEs are stored from L1 to L1+32K (16K to 48K above KZERO).
59  * KTZERO may be anywhere after that (but probably shouldn't collide with
60  * u-boot).
61  * This should leave over 8K from KZERO to L2 PTEs.
62  */
63 #define KSEG0           0xC0000000              /* kernel segment */
64 /* mask to check segment; good for 512MB dram */
65 #define KSEGM           0xE0000000
66 #define KZERO           KSEG0                   /* kernel address space */
67 #define L1              (KZERO+16*KiB)          /* tt ptes: 16KiB aligned */
68 #define CONFADDR        (KZERO+0x300000)        /* unparsed plan9.ini */
69 /* KTZERO must match loadaddr in mkfile */
70 #define KTZERO          (KZERO+0x310000)        /* kernel text start */
71
72 #define UZERO           0                       /* user segment */
73 #define UTZERO          (UZERO+BY2PG)           /* user text start */
74 #define UTROUND(t)      ROUNDUP((t), BY2PG)
75 /* moved USTKTOP down to 512MB to keep MMIO space out of user space. */
76 #define USTKTOP         0x20000000              /* user segment end +1 */
77 #define USTKSIZE        (8*1024*1024)           /* user stack size */
78
79 /* address at which to copy and execute rebootcode */
80 #define REBOOTADDR      KADDR(0x100)
81
82 /*
83  * Legacy...
84  */
85 #define BLOCKALIGN      32                      /* only used in allocb.c */
86 #define KSTACK          KSTKSIZE
87
88 /*
89  * Sizes
90  */
91 #define BI2BY           8                       /* bits per byte */
92 #define BY2SE           4
93 #define BY2WD           4
94 #define BY2V            8                       /* only used in xalloc.c */
95
96 #define CACHELINESZ     64                      /* bytes per cache line */
97 #define PTEMAPMEM       (1024*1024)
98 #define PTEPERTAB       (PTEMAPMEM/BY2PG)
99 #define SEGMAPSIZE      1984                    /* magic 16*124 */
100 #define SSEGMAPSIZE     16                      /* magic */
101 #define PPN(x)          ((x)&~(BY2PG-1))        /* pure page number? */
102
103 /*
104  * With a little work these move to port.
105  */
106 #define PTEVALID        (1<<0)
107 #define PTERONLY        0
108 #define PTEWRITE        (1<<1)
109 #define PTEUNCACHED     (1<<2)
110 #define PTEKERNEL       (1<<3)
111
112 /*
113  * Physical machine information from here on.
114  */
115
116 /* gpmc-controlled address space 0—1G */
117 #define PHYSNAND        1               /* cs0 is onenand flash */
118 #define PHYSETHER       0x2c000000
119
120 #define PHYSIO          0x48000000      /* L4 ctl */
121
122 #define PHYSSCM         0x48002000      /* system control module */
123
124 /* core control pad cfg         0x48002030—0x480021e4, */
125 /* core control d2d pad cfg     0x480021e4—0x48002264 */
126 #define PHYSSCMPCONF    0x48002270      /* general device config */
127 #define PHYSOMAPSTS     0x4800244c      /* standalone short: has l2 size */
128 /* core control pad cfg (2)     0x480025d8—0x480025fc */
129 #define PHYSSWBOOTCFG   0x48002910      /* sw booting config */
130 /* wakeup control pad cfg       0x48002a00—0x48002a54 */
131
132 #define PHYSSCMMPU      0x48004900      /* actually CPU */
133 #define PHYSSCMCORE     0x48004a00
134 #define PHYSSCMWKUP     0x48004c00
135 #define PHYSSCMPLL      0x48004d00      /* clock ctl for dpll[3-5] */
136 #define PHYSSCMDSS      0x48004e00
137 #define PHYSSCMPER      0x48005000
138 #define PHYSSCMUSB      0x48005400
139
140 #define PHYSL4CORE      0x48040100      /* l4 ap */
141 #define PHYSDSS         0x48050000      /* start of dss registers */
142 #define PHYSDISPC       0x48050400
143 #define PHYSGFX         0x48050480      /* part of dispc */
144
145 #define PHYSSDMA        0x48056000      /* system dma */
146 #define PHYSDMA         0x48060000
147
148 #define PHYSUSBTLL      0x48062000      /* usb: transceiver-less link */
149 #define PHYSUHH         0x48064000      /* usb: `high-speed usb host' ctlr or subsys */
150 #define PHYSOHCI        0x48064400      /* usb 1.0: slow */
151 #define PHYSEHCI        0x48064800      /* usb 2.0: medium */
152 #define PHYSUART0       0x4806a000
153 #define PHYSUART1       0x4806c000
154 #define PHYSMMCHS1      0x4809c000      /* mmc/sdio */
155 #define PHYSUSBOTG      0x480ab000      /* on-the-go usb */
156 #define PHYSMMCHS3      0x480ad000
157 #define PHYSMMCHS2      0x480b4000
158
159 #define PHYSINTC        0x48200000      /* interrupt controller */
160
161 #define PHYSPRMIVA2     0x48206000      /* prm iva2 regs */
162 /* 48306d40 sys_clkin_sel */
163 #define PHYSPRMGLBL     0x48307200      /* prm global regs */
164 #define PHYSPRMWKUSB    0x48307400
165
166 #define PHYSCNTRL       0x4830a200      /* SoC id, etc. */
167 #define PHYSWDT1        0x4830c000      /* wdt1, not on GP omaps */
168
169 #define PHYSGPIO1       0x48310000      /* contains dss gpio */
170
171 #define PHYSWDOG        0x48314000      /* watchdog timer, wdt2 */
172 #define PHYSWDT2        0x48314000      /* watchdog timer, wdt2 */
173 #define PHYSTIMER1      0x48318000
174
175 #define PHYSL4WKUP      0x48328100      /* l4 wkup */
176 #define PHYSL4PER       0x49000100      /* l4 per */
177
178 #define PHYSCONS        0x49020000      /* uart console (third one) */
179
180 #define PHYSWDT3        0x49030000      /* wdt3 */
181 #define PHYSTIMER2      0x49032000
182 #define PHYSTIMER3      0x49034000
183 #define PHYSGPIO5       0x49056000
184 #define PHYSGPIO6       0x49058000      /* contains igep ether gpio */
185
186 #define PHYSIOEND       0x49100000      /* end of PHYSIO identity map */
187
188 #define PHYSL4EMU       0x54006100      /* l4 emu */
189 #define PHYSL4PROT      0x54728000      /* l4 protection regs */
190
191 #define PHYSL3          0x68000000      /* l3 interconnect control */
192 #define PHYSL3GPMCCFG   0x68002000      /* l3 gpmc target port agent cfg */
193 #define PHYSL3USB       0x68004000      /* l3 regs for usb */
194 #define PHYSL3USBOTG    0x68004400      /* l3 regs for usb otg */
195 /* (target port) protection registers */
196 #define PHYSL3PMRT      0x68010000      /* l3 PM register target prot. */
197 #define PHYSL3GPMCPM    0x68012400      /* l3 gpmc target port protection */
198 #define PHYSL3OCTRAM    0x68012800      /* l3 ocm ram */
199 #define PHYSL3OCTROM    0x68012c00      /* l3 ocm rom */
200 #define PHYSL3MAD2D     0x68013000      /* l3 die-to-die */
201 #define PHYSL3IVA       0x68014000      /* l3 die-to-die */
202
203 #define PHYSSMS         0x6c000000      /* cfg regs: sms addr space 2 */
204 #define PHYSDRC         0x6d000000      /* sdram ctlr, addr space 3 */
205 #define PHYSGPMC        0x6e000000      /* flash, non-dram memory ctlr */
206
207 #define PHYSDRAM        0x80000000
208
209 #define VIRTNAND        0x20000000      /* fixed by u-boot */
210 #define VIRTIO          PHYSIO