]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc/dat.h
bcm, bcm64: add support for device tree parameter passing
[plan9front.git] / sys / src / 9 / pc / dat.h
1 typedef struct BIOS32si BIOS32si;
2 typedef struct BIOS32ci BIOS32ci;
3 typedef struct Conf     Conf;
4 typedef struct Confmem  Confmem;
5 typedef union FPsave    FPsave;
6 typedef struct FPx87state FPx87state;
7 typedef struct FPssestate FPssestate;
8 typedef struct PFPU     PFPU;
9 typedef struct ISAConf  ISAConf;
10 typedef struct Label    Label;
11 typedef struct Lock     Lock;
12 typedef struct MMU      MMU;
13 typedef struct Mach     Mach;
14 typedef struct PCArch   PCArch;
15 typedef struct Pcidev   Pcidev;
16 typedef struct PCMmap   PCMmap;
17 typedef struct PCMslot  PCMslot;
18 typedef struct Page     Page;
19 typedef struct PMMU     PMMU;
20 typedef struct Proc     Proc;
21 typedef struct Segdesc  Segdesc;
22 typedef vlong           Tval;
23 typedef struct Ureg     Ureg;
24 typedef struct Vctl     Vctl;
25
26 #pragma incomplete BIOS32si
27 #pragma incomplete Pcidev
28 #pragma incomplete Ureg
29
30 #define MAXSYSARG       5       /* for mount(fd, afd, mpt, flag, arg) */
31
32 /*
33  *  parameters for sysproc.c
34  */
35 #define AOUT_MAGIC      (I_MAGIC)
36
37 struct Lock
38 {
39         ulong   key;
40         ulong   sr;
41         uintptr pc;
42         Proc    *p;
43         Mach    *m;
44         ushort  isilock;
45         long    lockcycles;
46 };
47
48 struct Label
49 {
50         ulong   sp;
51         ulong   pc;
52 };
53
54 struct  FPx87state              /* x87 fp state */
55 {
56         ushort  control;
57         ushort  r1;
58         ushort  status;
59         ushort  r2;
60         ushort  tag;
61         ushort  r3;
62         ulong   pc;
63         ushort  selector;
64         ushort  opcode;
65         ulong   operand;
66         ushort  oselector;
67         ushort  r4;
68         uchar   regs[80];       /* floating point registers */
69 };
70
71 struct  FPssestate              /* SSE fp state */
72 {
73         ushort  fcw;            /* control */
74         ushort  fsw;            /* status */
75         ushort  ftw;            /* tag */
76         ushort  fop;            /* opcode */
77         ulong   fpuip;          /* pc */
78         ushort  cs;             /* pc segment */
79         ushort  rsrvd1;         /* reserved */
80         ulong   fpudp;          /* data pointer */
81         ushort  ds;             /* data pointer segment */
82         ushort  rsrvd2;
83         ulong   mxcsr;          /* MXCSR register state */
84         ulong   mxcsr_mask;     /* MXCSR mask register */
85         uchar   xregs[480];     /* extended registers */
86 };
87
88 union FPsave {
89         FPx87state;
90         FPssestate;
91 };
92
93 struct PFPU
94 {
95         int     fpstate;
96         FPsave  *fpsave;
97 };
98
99 enum
100 {
101         /* this is a state */
102         FPinit=         0,
103         FPactive=       1,
104         FPinactive=     2,
105
106         /* the following is a bit that can be or'd into the state */
107         FPillegal=      0x100,
108 };
109
110 struct Confmem
111 {
112         ulong   base;
113         ulong   npage;
114         ulong   kbase;
115         ulong   klimit;
116 };
117
118 struct Conf
119 {
120         ulong   nmach;          /* processors */
121         ulong   nproc;          /* processes */
122         ulong   monitor;        /* has monitor? */
123         Confmem mem[4];         /* physical memory */
124         ulong   npage;          /* total physical pages of memory */
125         ulong   upages;         /* user page pool */
126         ulong   nimage;         /* number of page cache image headers */
127         ulong   nswap;          /* number of swap pages */
128         int     nswppo;         /* max # of pageouts per segment pass */
129         ulong   copymode;       /* 0 is copy on write, 1 is copy on reference */
130         ulong   ialloc;         /* max interrupt time allocation in bytes */
131         ulong   pipeqsize;      /* size in bytes of pipe queues */
132         int     nuart;          /* number of uart devices */
133 };
134
135 struct Segdesc
136 {
137         ulong   d0;
138         ulong   d1;
139 };
140
141 /*
142  *  MMU stuff in proc
143  */
144 #define NCOLOR 1
145 struct PMMU
146 {
147         Page*   mmupdb;                 /* page directory base */
148         Page*   mmufree;                /* unused page table pages */
149         Page*   mmuused;                /* used page table pages */
150         Page*   kmaptable;              /* page table used by kmap */
151         uint    lastkmap;               /* last entry used by kmap */
152         int     nkmap;                  /* number of current kmaps */
153
154         Segdesc gdt[NPROCSEG];  /* per process descriptors */
155         Segdesc *ldt;   /* local descriptor table */
156         int     nldt;   /* number of ldt descriptors allocated */
157         
158         u32int  dr[8];                  /* debug registers */
159         void    *vmx;
160 };
161
162 #include "../port/portdat.h"
163
164 typedef struct {
165         ulong   link;                   /* link (old TSS selector) */
166         ulong   esp0;                   /* privilege level 0 stack pointer */
167         ulong   ss0;                    /* privilege level 0 stack selector */
168         ulong   esp1;                   /* privilege level 1 stack pointer */
169         ulong   ss1;                    /* privilege level 1 stack selector */
170         ulong   esp2;                   /* privilege level 2 stack pointer */
171         ulong   ss2;                    /* privilege level 2 stack selector */
172         ulong   xcr3;                   /* page directory base register - not used because we don't use trap gates */
173         ulong   eip;                    /* instruction pointer */
174         ulong   eflags;                 /* flags register */
175         ulong   eax;                    /* general registers */
176         ulong   ecx;
177         ulong   edx;
178         ulong   ebx;
179         ulong   esp;
180         ulong   ebp;
181         ulong   esi;
182         ulong   edi;
183         ulong   es;                     /* segment selectors */
184         ulong   cs;
185         ulong   ss;
186         ulong   ds;
187         ulong   fs;
188         ulong   gs;
189         ulong   ldt;                    /* selector for task's LDT */
190         ulong   iomap;                  /* I/O map base address + T-bit */
191 } Tss;
192
193 struct Mach
194 {
195         int     machno;                 /* physical id of processor (KNOWN TO ASSEMBLY) */
196         ulong   splpc;                  /* pc of last caller to splhi */
197
198         ulong*  pdb;                    /* page directory base for this processor (va) */
199         Tss*    tss;                    /* tss for this processor */
200         Segdesc *gdt;                   /* gdt for this processor */
201
202         Proc*   proc;                   /* current process on this processor */
203         Proc*   externup;               /* extern register Proc *up */
204
205         Page*   pdbpool;
206         int     pdbcnt;
207
208         ulong   ticks;                  /* of the clock since boot time */
209         Label   sched;                  /* scheduler wakeup */
210         Lock    alarmlock;              /* access to alarm list */
211         void*   alarm;                  /* alarms bound to this clock */
212         int     inclockintr;
213
214         Proc*   readied;                /* for runproc */
215         ulong   schedticks;             /* next forced context switch */
216
217         int     tlbfault;
218         int     tlbpurge;
219         int     pfault;
220         int     cs;
221         int     syscall;
222         int     load;
223         int     intr;
224         int     flushmmu;               /* make current proc flush it's mmu state */
225         int     ilockdepth;
226         Perf    perf;                   /* performance counters */
227
228         ulong   spuriousintr;
229         int     lastintr;
230
231         int     loopconst;
232
233         int     cpumhz;
234         uvlong  cyclefreq;              /* Frequency of user readable cycle counter */
235         uvlong  cpuhz;
236         int     cpuidax;
237         int     cpuidcx;
238         int     cpuiddx;
239         char    cpuidid[16];
240         char*   cpuidtype;
241         uchar   cpuidfamily;
242         uchar   cpuidmodel;
243         uchar   cpuidstepping;
244         int     havetsc;
245         int     havepge;
246         int     havewatchpt8;
247         uvlong  tscticks;
248         int     pdballoc;
249         int     pdbfree;
250         
251         u32int  dr7;                    /* shadow copy of dr7 */
252         
253         void*   vmx;
254
255         int     stack[1];
256 };
257
258 /*
259  * KMap the structure doesn't exist, but the functions do.
260  */
261 typedef struct KMap             KMap;
262 #define VA(k)           ((void*)(k))
263 KMap*   kmap(Page*);
264 void    kunmap(KMap*);
265
266 extern u32int MemMin;
267
268 struct
269 {
270         char    machs[MAXMACH];         /* active CPUs */
271         int     exiting;                /* shutdown */
272 }active;
273
274 /*
275  *  routines for things outside the PC model, like power management
276  */
277 struct PCArch
278 {
279         char*   id;
280         int     (*ident)(void);         /* this should be in the model */
281         void    (*reset)(void);         /* this should be in the model */
282         int     (*serialpower)(int);    /* 1 == on, 0 == off */
283         int     (*modempower)(int);     /* 1 == on, 0 == off */
284
285         void    (*intrinit)(void);
286         int     (*intrenable)(Vctl*);
287         int     (*intrvecno)(int);
288         int     (*intrdisable)(int);
289         void    (*introff)(void);
290         void    (*intron)(void);
291
292         void    (*clockenable)(void);
293         uvlong  (*fastclock)(uvlong*);
294         void    (*timerset)(uvlong);
295 };
296
297 /* cpuid instruction result register bits */
298 enum {
299         /* cx */
300         Monitor = 1<<3,
301
302         /* dx */
303         Fpuonchip = 1<<0,
304         Vmex    = 1<<1,         /* virtual-mode extensions */
305         Pse     = 1<<3,         /* page size extensions */
306         Tsc     = 1<<4,         /* time-stamp counter */
307         Cpumsr  = 1<<5,         /* model-specific registers, rdmsr/wrmsr */
308         Pae     = 1<<6,         /* physical-addr extensions */
309         Mce     = 1<<7,         /* machine-check exception */
310         Cmpxchg8b = 1<<8,
311         Cpuapic = 1<<9,
312         Mtrr    = 1<<12,        /* memory-type range regs.  */
313         Pge     = 1<<13,        /* page global extension */
314         Mca     = 1<<14,        /* machine-check architecture */
315         Pat     = 1<<16,        /* page attribute table */
316         Pse2    = 1<<17,        /* more page size extensions */
317         Clflush = 1<<19,
318         Acpif   = 1<<22,        /* therm control msr */
319         Mmx     = 1<<23,
320         Fxsr    = 1<<24,        /* have SSE FXSAVE/FXRSTOR */
321         Sse     = 1<<25,        /* thus sfence instr. */
322         Sse2    = 1<<26,        /* thus mfence & lfence instr.s */
323         Rdrnd   = 1<<30,        /* RDRAND support bit */
324 };
325
326 /* model-specific registers, for compatibility with pc64 code */
327 enum {
328         Efer            = 0xc0000080,           /* Extended Feature Enable */
329         Star            = 0xc0000081,           /* Legacy Target IP and [CS]S */
330         Lstar           = 0xc0000082,           /* Long Mode Target IP */
331         Cstar           = 0xc0000083,           /* Compatibility Target IP */
332         Sfmask          = 0xc0000084,           /* SYSCALL Flags Mask */
333         FSbase          = 0xc0000100,           /* 64-bit FS Base Address */
334         GSbase          = 0xc0000101,           /* 64-bit GS Base Address */
335         KernelGSbase    = 0xc0000102,           /* SWAPGS instruction */
336 };
337
338 /*
339  *  a parsed plan9.ini line
340  */
341 #define NISAOPT         8
342
343 struct ISAConf {
344         char    *type;
345         ulong   port;
346         int     irq;
347         ulong   dma;
348         ulong   mem;
349         ulong   size;
350         ulong   freq;
351
352         int     nopt;
353         char    *opt[NISAOPT];
354 };
355
356 extern PCArch   *arch;                  /* PC architecture */
357
358 /*
359  * Each processor sees its own Mach structure at address MACHADDR.
360  * However, the Mach structures must also be available via the per-processor
361  * MMU information array machp, mainly for disambiguation and access to
362  * the clock which is only maintained by the bootstrap processor (0).
363  */
364 Mach* machp[MAXMACH];
365         
366 #define MACHP(n)        (machp[n])
367
368 extern Mach     *m;
369 #define up      (((Mach*)MACHADDR)->externup)
370
371 /*
372  *  hardware info about a device
373  */
374 typedef struct {
375         ulong   port;   
376         int     size;
377 } Devport;
378
379 struct DevConf
380 {
381         ulong   intnum;                 /* interrupt number */
382         char    *type;                  /* card type, malloced */
383         int     nports;                 /* Number of ports */
384         Devport *ports;                 /* The ports themselves */
385 };
386
387 typedef struct BIOS32ci {               /* BIOS32 Calling Interface */
388         u32int  eax;
389         u32int  ebx;
390         u32int  ecx;
391         u32int  edx;
392         u32int  esi;
393         u32int  edi;
394 } BIOS32ci;