]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/teg2/dat.h
kernel: clean up Mach structure
[plan9front.git] / sys / src / 9 / teg2 / dat.h
1 /*
2  * Time.
3  *
4  * HZ should divide 1000 evenly, ideally.
5  * 100, 125, 200, 250 and 333 are okay.
6  */
7 #define HZ              100                     /* clock frequency */
8 #define MS2HZ           (1000/HZ)               /* millisec per clock tick */
9 #define TK2SEC(t)       ((t)/HZ)                /* ticks to seconds */
10
11 enum {
12         Mhz     = 1000 * 1000,
13         Dogsectimeout = 4,              /* must be ≤ 34 s. to fit in a ulong */
14 };
15
16 /*
17  * More accurate time
18  */
19 #define MS2TMR(t)       ((ulong)(((uvlong)(t) * m->cpuhz)/1000))
20 #define US2TMR(t)       ((ulong)(((uvlong)(t) * m->cpuhz)/1000000))
21
22 #define CONSOLE 0
23
24 typedef struct Conf     Conf;
25 typedef struct Confmem  Confmem;
26 typedef struct FPsave   FPsave;
27 typedef struct PFPU     PFPU;
28 typedef struct ISAConf  ISAConf;
29 typedef struct Isolated Isolated;
30 typedef struct Label    Label;
31 typedef struct Lock     Lock;
32 typedef struct Lowmemcache Lowmemcache;
33 typedef struct Memcache Memcache;
34 typedef struct MMMU     MMMU;
35 typedef struct Mach     Mach;
36 typedef u32int Mreg;                            /* Msr - bloody UART */
37 typedef struct Page     Page;
38 typedef struct Pcisiz Pcisiz;
39 typedef struct Pcidev Pcidev;
40 typedef struct PhysUart PhysUart;
41 typedef struct PMMU     PMMU;
42 typedef struct Proc     Proc;
43 typedef u32int          PTE;
44 typedef struct Soc      Soc;
45 typedef struct Uart     Uart;
46 typedef struct Ureg     Ureg;
47 typedef uvlong          Tval;
48
49 #pragma incomplete Pcidev
50 #pragma incomplete Ureg
51
52 #define MAXSYSARG       5       /* for mount(fd, mpt, flag, arg, srv) */
53
54 /*
55  *  parameters for sysproc.c
56  */
57 #define AOUT_MAGIC      (E_MAGIC)
58
59 struct Lock
60 {
61         ulong   key;
62         u32int  sr;
63         uintptr pc;
64         Proc*   p;
65         Mach*   m;
66         int     isilock;
67 };
68
69 struct Label
70 {
71         uintptr sp;
72         uintptr pc;
73 };
74
75 /*
76  * emulated or vfp3 floating point
77  */
78 enum {
79         Maxfpregs       = 32,   /* could be 16 or 32, see Mach.fpnregs */
80         Nfpctlregs      = 16,
81 };
82
83 struct FPsave
84 {
85         ulong   status;
86         ulong   control;
87         /*
88          * vfp3 with ieee fp regs; uvlong is sufficient for hardware but
89          * each must be able to hold an Internal from fpi.h for sw emulation.
90          */
91         ulong   regs[Maxfpregs][3];
92
93         int     fpstate;
94         uintptr pc;             /* of failed fp instr. */
95 };
96
97 struct PFPU
98 {
99         int     fpstate;
100         FPsave  fpsave[1];
101 };
102
103 enum
104 {
105         FPinit,
106         FPactive,
107         FPinactive,
108         FPemu,
109
110         /* bit or'd with the state */
111         FPillegal= 0x100,
112 };
113
114 struct Confmem
115 {
116         uintptr base;
117         usize   npage;
118         uintptr limit;
119         uintptr kbase;
120         uintptr klimit;
121 };
122
123 struct Conf
124 {
125         ulong   nmach;          /* processors */
126         ulong   nproc;          /* processes */
127         Confmem mem[1];         /* physical memory */
128         ulong   npage;          /* total physical pages of memory */
129         usize   upages;         /* user page pool */
130         ulong   copymode;       /* 0 is copy on write, 1 is copy on reference */
131         ulong   ialloc;         /* max interrupt time allocation in bytes */
132         ulong   pipeqsize;      /* size in bytes of pipe queues */
133         ulong   nimage;         /* number of page cache image headers */
134         ulong   nswap;          /* number of swap pages */
135         int     nswppo;         /* max # of pageouts per segment pass */
136         ulong   hz;             /* processor cycle freq */
137         ulong   mhz;
138         int     monitor;        /* flag */
139 };
140
141 /*
142  *  MMU stuff in Mach.
143  */
144 struct MMMU
145 {
146         PTE*    mmul1;          /* l1 for this processor */
147         int     mmul1lo;
148         int     mmul1hi;
149         int     mmupid;
150 };
151
152 /*
153  *  MMU stuff in proc
154  */
155 #define NCOLOR  1               /* 1 level cache, don't worry about VCE's */
156 struct PMMU
157 {
158         Page*   mmul2;
159         Page*   mmul2cache;     /* free mmu pages */
160 };
161
162 #include "../port/portdat.h"
163
164 struct Mach
165 {
166         int     machno;                 /* physical id of processor */
167         uintptr splpc;                  /* pc of last caller to splhi */
168         Proc*   proc;                   /* current process on this processor */
169
170         MMMU;
171         /* end of offsets known to asm */
172
173         PMach;
174
175         uvlong  fastclock;              /* last sampled value */
176         int     inclockintr;
177         int     inidlehands;
178
179         int     probing;                /* probeaddr() state */
180         int     trapped;
181         Lock    probelock;
182
183         int     cputype;
184         ulong   delayloop;
185         int     cpumhz;
186         uvlong  cpuhz;                  /* speed of cpu */
187
188         /* vfp3 fpu */
189         int     havefp;
190         int     havefpvalid;
191         int     fpon;
192         int     fpconfiged;
193         int     fpnregs;
194         ulong   fpscr;                  /* sw copy */
195         int     fppid;                  /* pid of last fault */
196         uintptr fppc;                   /* addr of last fault */
197         int     fpcnt;                  /* how many consecutive at that addr */
198
199         /* save areas for exceptions, hold R0-R4 */
200         u32int  sfiq[5];
201         u32int  sirq[5];
202         u32int  sund[5];
203         u32int  sabt[5];
204         u32int  smon[5];                /* probably not needed */
205         u32int  ssys[5];
206
207         uintptr stack[1];
208 };
209
210 /*
211  * Fake kmap.
212  */
213 typedef void            KMap;
214 #define VA(k)           ((uintptr)(k))
215 #define kmap(p)         (KMap*)((p)->pa|kseg0)
216 #define kunmap(k)
217
218 struct
219 {
220         Lock;
221         char    machs[MAXMACH];         /* active CPUs */
222         int     wfi;                    /* bitmap of CPUs in WFI state */
223         int     stopped;                /* bitmap of CPUs stopped */
224         int     exiting;                /* shutdown */
225 }active;
226
227 extern register Mach* m;                        /* R10 */
228 extern register Proc* up;                       /* R9 */
229
230 /* an object guaranteed to be in its own cache line */
231 typedef uchar Cacheline[CACHELINESZ];
232 struct Isolated {
233         Cacheline c0;
234         ulong   word;
235         Cacheline c1;
236 };
237
238 extern Memcache cachel[];               /* arm arch v7 supports 1-7 */
239 extern ulong intrcount[MAXMACH];
240 extern int irqtooearly;
241 extern uintptr kseg0;
242 extern Isolated l1ptstable;
243 extern uchar *l2pages;
244 extern Mach* machaddr[MAXMACH];
245 extern ulong memsize;
246 extern int navailcpus;
247 extern int normalprint;
248
249 /*
250  *  a parsed plan9.ini line
251  */
252 #define NISAOPT         8
253
254 struct ISAConf {
255         char    *type;
256         ulong   port;
257         int     irq;
258         ulong   dma;
259         ulong   mem;
260         ulong   size;
261         ulong   freq;
262
263         int     nopt;
264         char    *opt[NISAOPT];
265 };
266
267 #define MACHP(n) machaddr[n]
268
269 /*
270  * Horrid. But the alternative is 'defined'.
271  */
272 #ifdef _DBGC_
273 #define DBGFLG          (dbgflg[_DBGC_])
274 #else
275 #define DBGFLG          (0)
276 #endif /* _DBGC_ */
277
278 int vflag;
279 extern char dbgflg[256];
280
281 #define dbgprint        print           /* for now */
282
283 /*
284  *  hardware info about a device
285  */
286 typedef struct {
287         ulong   port;
288         int     size;
289 } Devport;
290
291 struct DevConf
292 {
293         ulong   intnum;                 /* interrupt number */
294         char    *type;                  /* card type, malloced */
295         int     nports;                 /* Number of ports */
296         Devport *ports;                 /* The ports themselves */
297 };
298
299 /* characteristics of a given arm cache level */
300 struct Memcache {
301         uint    waysh;          /* shifts for set/way register */
302         uint    setsh;
303
304         uint    log2linelen;
305
306         uint    level;          /* 1 is nearest processor, 2 further away */
307         uint    type;
308         uint    external;       /* flag */
309         uint    l1ip;           /* l1 I policy */
310
311         uint    nways;          /* associativity */
312         uint    nsets;
313         uint    linelen;        /* bytes per cache line */
314         uint    setsways;
315 };
316 enum Cachetype {
317         Nocache,
318         Ionly,
319         Donly,
320         Splitid,
321         Unified,
322 };
323 enum {
324         Intcache,
325         Extcache,
326 };
327
328 /*
329  * characteristics of cache level, kept at low, fixed address (CACHECONF).
330  * all offsets are known to cache.v7.s.
331  */
332 struct Lowmemcache {
333         uint    l1waysh;                /* shifts for set/way register */
334         uint    l1setsh;
335         uint    l2waysh;
336         uint    l2setsh;
337 };
338
339 /*
340  * cache capabilities.  write-back vs write-through is controlled
341  * by the Buffered bit in PTEs.
342  *
343  * see cache.v7.s and Memcache in dat.h
344  */
345 enum {
346         Cawt    = 1 << 31,
347         Cawb    = 1 << 30,
348         Cara    = 1 << 29,
349         Cawa    = 1 << 28,
350 };
351
352 /* non-architectural L2 cache */
353 typedef struct Cacheimpl Cacheimpl;
354 struct Cacheimpl {
355         void    (*info)(Memcache *);
356         void    (*on)(void);
357         void    (*off)(void);
358
359         void    (*inv)(void);
360         void    (*wb)(void);
361         void    (*wbinv)(void);
362
363         void    (*invse)(void *, int);
364         void    (*wbse)(void *, int);
365         void    (*wbinvse)(void *, int);
366 };
367 /* extern */ Cacheimpl *l2cache, *allcache, *nocache, *l1cache;
368
369 enum Dmamode {
370         Const,
371         Postincr,
372         Index,
373         Index2,
374 };
375
376 /* pmu = power management unit */
377 enum Irqs {
378         /*
379          * 1st 32 gic irqs reserved for cpu; private interrupts.
380          *  0—15 are software-generated by other cpus;
381          * 16—31 are private peripheral intrs.
382          */
383         Cpu0irq         = 0,
384         Cpu1irq,
385         /* ... */
386         Cpu15irq        = 15,
387         Glbtmrirq       = 27,
388         Loctmrirq       = 29,
389         Wdtmrirq        = 30,
390
391         /* shared interrupts */
392         Ctlr0base       = (1+0)*32,             /* primary ctlr */
393         Tn0irq          = Ctlr0base + 0,        /* tegra timers */
394         Tn1irq          = Ctlr0base + 1,
395         Rtcirq          = Ctlr0base + 2,
396
397         Ctlr1base       = (1+1)*32,             /* secondary ctlr */
398         Uartirq         = Ctlr1base + 4,
399         Tn2irq          = Ctlr1base + 9,        /* tegra timers */
400         Tn3irq          = Ctlr1base + 10,
401         /* +24 is cpu0_pmu_intr, +25 is cpu1_pum_intr */
402
403         Ctlr2base       = (1+2)*32,             /* ternary ctlr */
404         Extpmuirq       = Ctlr2base + 22,
405
406         Ctlr3base       = (1+3)*32,             /* quad ctlr */
407         Pcieirq         = Ctlr3base + 2,
408 };
409
410 struct Soc {                    /* addr's of SoC controllers */
411         uintptr clkrst;
412         uintptr power;
413         uintptr exceptvec;
414         uintptr sema;
415         uintptr l2cache;
416         uintptr flow;
417
418         /* private memory region */
419         uintptr scu;
420         uintptr intr;           /* `cpu interface' */
421         /* private-peripheral-interrupt cortex-a clocks */
422         uintptr glbtmr;
423         uintptr loctmr;
424
425         uintptr intrdist;
426
427         uintptr uart[5];
428
429         /* shared-peripheral-interrupt tegra2 clocks */
430         uintptr rtc;            /* real-time clock */
431         uintptr tmr[4];
432         uintptr µs;
433
434         uintptr pci;
435         uintptr ether;
436
437         uintptr ehci;
438         uintptr ide;
439
440         uintptr nand;
441         uintptr nor;
442
443         uintptr spi[4];
444         uintptr twsi;
445         uintptr mmc[4];
446         uintptr gpio[7];
447 } soc;
448 extern Soc soc;