]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/teg2/dat.h
usbehci: catch interrupt in tsleep
[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         /* offsets known to asm */
167         int     machno;                 /* physical id of processor */
168         uintptr splpc;                  /* pc of last caller to splhi */
169
170         Proc*   proc;                   /* current process */
171
172         MMMU;
173         /* end of offsets known to asm */
174         int     flushmmu;               /* flush current proc mmu state */
175
176         ulong   ticks;                  /* of the clock since boot time */
177         Label   sched;                  /* scheduler wakeup */
178         Lock    alarmlock;              /* access to alarm list */
179         void*   alarm;                  /* alarms bound to this clock */
180         int     inclockintr;
181
182         Proc*   readied;                /* for runproc */
183         ulong   schedticks;             /* next forced context switch */
184
185         int     cputype;
186         ulong   delayloop;
187
188         /* stats */
189         int     tlbfault;
190         int     tlbpurge;
191         int     pfault;
192         int     cs;
193         int     syscall;
194         int     load;
195         int     intr;
196         uvlong  fastclock;              /* last sampled value */
197         uvlong  inidle;                 /* time spent in idlehands() */
198         ulong   spuriousintr;
199         int     lastintr;
200         int     ilockdepth;
201         Perf    perf;                   /* performance counters */
202
203         int     probing;                /* probeaddr() state */
204         int     trapped;
205         Lock    probelock;
206         int     inidlehands;
207
208         int     cpumhz;
209         uvlong  cpuhz;                  /* speed of cpu */
210         uvlong  cyclefreq;              /* Frequency of user readable cycle counter */
211
212         /* vfp3 fpu */
213         int     havefp;
214         int     havefpvalid;
215         int     fpon;
216         int     fpconfiged;
217         int     fpnregs;
218         ulong   fpscr;                  /* sw copy */
219         int     fppid;                  /* pid of last fault */
220         uintptr fppc;                   /* addr of last fault */
221         int     fpcnt;                  /* how many consecutive at that addr */
222
223         /* save areas for exceptions, hold R0-R4 */
224         u32int  sfiq[5];
225         u32int  sirq[5];
226         u32int  sund[5];
227         u32int  sabt[5];
228         u32int  smon[5];                /* probably not needed */
229         u32int  ssys[5];
230
231         int     stack[1];
232 };
233
234 /*
235  * Fake kmap.
236  */
237 typedef void            KMap;
238 #define VA(k)           ((uintptr)(k))
239 #define kmap(p)         (KMap*)((p)->pa|kseg0)
240 #define kunmap(k)
241
242 struct
243 {
244         Lock;
245         char    machs[MAXMACH];         /* active CPUs */
246         int     wfi;                    /* bitmap of CPUs in WFI state */
247         int     stopped;                /* bitmap of CPUs stopped */
248         int     exiting;                /* shutdown */
249 }active;
250
251 extern register Mach* m;                        /* R10 */
252 extern register Proc* up;                       /* R9 */
253
254 /* an object guaranteed to be in its own cache line */
255 typedef uchar Cacheline[CACHELINESZ];
256 struct Isolated {
257         Cacheline c0;
258         ulong   word;
259         Cacheline c1;
260 };
261
262 extern Memcache cachel[];               /* arm arch v7 supports 1-7 */
263 extern ulong intrcount[MAXMACH];
264 extern int irqtooearly;
265 extern uintptr kseg0;
266 extern Isolated l1ptstable;
267 extern uchar *l2pages;
268 extern Mach* machaddr[MAXMACH];
269 extern ulong memsize;
270 extern int navailcpus;
271 extern int normalprint;
272
273 /*
274  *  a parsed plan9.ini line
275  */
276 #define NISAOPT         8
277
278 struct ISAConf {
279         char    *type;
280         ulong   port;
281         int     irq;
282         ulong   dma;
283         ulong   mem;
284         ulong   size;
285         ulong   freq;
286
287         int     nopt;
288         char    *opt[NISAOPT];
289 };
290
291 #define MACHP(n) machaddr[n]
292
293 /*
294  * Horrid. But the alternative is 'defined'.
295  */
296 #ifdef _DBGC_
297 #define DBGFLG          (dbgflg[_DBGC_])
298 #else
299 #define DBGFLG          (0)
300 #endif /* _DBGC_ */
301
302 int vflag;
303 extern char dbgflg[256];
304
305 #define dbgprint        print           /* for now */
306
307 /*
308  *  hardware info about a device
309  */
310 typedef struct {
311         ulong   port;
312         int     size;
313 } Devport;
314
315 struct DevConf
316 {
317         ulong   intnum;                 /* interrupt number */
318         char    *type;                  /* card type, malloced */
319         int     nports;                 /* Number of ports */
320         Devport *ports;                 /* The ports themselves */
321 };
322
323 /* characteristics of a given arm cache level */
324 struct Memcache {
325         uint    waysh;          /* shifts for set/way register */
326         uint    setsh;
327
328         uint    log2linelen;
329
330         uint    level;          /* 1 is nearest processor, 2 further away */
331         uint    type;
332         uint    external;       /* flag */
333         uint    l1ip;           /* l1 I policy */
334
335         uint    nways;          /* associativity */
336         uint    nsets;
337         uint    linelen;        /* bytes per cache line */
338         uint    setsways;
339 };
340 enum Cachetype {
341         Nocache,
342         Ionly,
343         Donly,
344         Splitid,
345         Unified,
346 };
347 enum {
348         Intcache,
349         Extcache,
350 };
351
352 /*
353  * characteristics of cache level, kept at low, fixed address (CACHECONF).
354  * all offsets are known to cache.v7.s.
355  */
356 struct Lowmemcache {
357         uint    l1waysh;                /* shifts for set/way register */
358         uint    l1setsh;
359         uint    l2waysh;
360         uint    l2setsh;
361 };
362
363 /*
364  * cache capabilities.  write-back vs write-through is controlled
365  * by the Buffered bit in PTEs.
366  *
367  * see cache.v7.s and Memcache in dat.h
368  */
369 enum {
370         Cawt    = 1 << 31,
371         Cawb    = 1 << 30,
372         Cara    = 1 << 29,
373         Cawa    = 1 << 28,
374 };
375
376 /* non-architectural L2 cache */
377 typedef struct Cacheimpl Cacheimpl;
378 struct Cacheimpl {
379         void    (*info)(Memcache *);
380         void    (*on)(void);
381         void    (*off)(void);
382
383         void    (*inv)(void);
384         void    (*wb)(void);
385         void    (*wbinv)(void);
386
387         void    (*invse)(void *, int);
388         void    (*wbse)(void *, int);
389         void    (*wbinvse)(void *, int);
390 };
391 /* extern */ Cacheimpl *l2cache, *allcache, *nocache, *l1cache;
392
393 enum Dmamode {
394         Const,
395         Postincr,
396         Index,
397         Index2,
398 };
399
400 /* pmu = power management unit */
401 enum Irqs {
402         /*
403          * 1st 32 gic irqs reserved for cpu; private interrupts.
404          *  0—15 are software-generated by other cpus;
405          * 16—31 are private peripheral intrs.
406          */
407         Cpu0irq         = 0,
408         Cpu1irq,
409         /* ... */
410         Cpu15irq        = 15,
411         Glbtmrirq       = 27,
412         Loctmrirq       = 29,
413         Wdtmrirq        = 30,
414
415         /* shared interrupts */
416         Ctlr0base       = (1+0)*32,             /* primary ctlr */
417         Tn0irq          = Ctlr0base + 0,        /* tegra timers */
418         Tn1irq          = Ctlr0base + 1,
419         Rtcirq          = Ctlr0base + 2,
420
421         Ctlr1base       = (1+1)*32,             /* secondary ctlr */
422         Uartirq         = Ctlr1base + 4,
423         Tn2irq          = Ctlr1base + 9,        /* tegra timers */
424         Tn3irq          = Ctlr1base + 10,
425         /* +24 is cpu0_pmu_intr, +25 is cpu1_pum_intr */
426
427         Ctlr2base       = (1+2)*32,             /* ternary ctlr */
428         Extpmuirq       = Ctlr2base + 22,
429
430         Ctlr3base       = (1+3)*32,             /* quad ctlr */
431         Pcieirq         = Ctlr3base + 2,
432 };
433
434 struct Soc {                    /* addr's of SoC controllers */
435         uintptr clkrst;
436         uintptr power;
437         uintptr exceptvec;
438         uintptr sema;
439         uintptr l2cache;
440         uintptr flow;
441
442         /* private memory region */
443         uintptr scu;
444         uintptr intr;           /* `cpu interface' */
445         /* private-peripheral-interrupt cortex-a clocks */
446         uintptr glbtmr;
447         uintptr loctmr;
448
449         uintptr intrdist;
450
451         uintptr uart[5];
452
453         /* shared-peripheral-interrupt tegra2 clocks */
454         uintptr rtc;            /* real-time clock */
455         uintptr tmr[4];
456         uintptr µs;
457
458         uintptr pci;
459         uintptr ether;
460
461         uintptr ehci;
462         uintptr ide;
463
464         uintptr nand;
465         uintptr nor;
466
467         uintptr spi[4];
468         uintptr twsi;
469         uintptr mmc[4];
470         uintptr gpio[7];
471 } soc;
472 extern Soc soc;