]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/port/portdat.h
remove audio.h, put stuff in port^(dat fns).h
[plan9front.git] / sys / src / 9 / port / portdat.h
1 typedef struct Alarms   Alarms;
2 typedef struct Audio    Audio;
3 typedef struct Block    Block;
4 typedef struct Chan     Chan;
5 typedef struct Cmdbuf   Cmdbuf;
6 typedef struct Cmdtab   Cmdtab;
7 typedef struct Confmem  Confmem;
8 typedef struct Dev      Dev;
9 typedef struct Dirtab   Dirtab;
10 typedef struct Edf      Edf;
11 typedef struct Egrp     Egrp;
12 typedef struct Evalue   Evalue;
13 typedef struct Fgrp     Fgrp;
14 typedef struct DevConf  DevConf;
15 typedef struct Image    Image;
16 typedef struct Log      Log;
17 typedef struct Logflag  Logflag;
18 typedef struct Mntcache Mntcache;
19 typedef struct Mount    Mount;
20 typedef struct Mntrpc   Mntrpc;
21 typedef struct Mntwalk  Mntwalk;
22 typedef struct Mnt      Mnt;
23 typedef struct Mhead    Mhead;
24 typedef struct Note     Note;
25 typedef struct Page     Page;
26 typedef struct Path     Path;
27 typedef struct Palloc   Palloc;
28 typedef struct Pallocmem        Pallocmem;
29 typedef struct Perf     Perf;
30 typedef struct PhysUart PhysUart;
31 typedef struct Pgrp     Pgrp;
32 typedef struct Physseg  Physseg;
33 typedef struct Proc     Proc;
34 typedef struct Pte      Pte;
35 typedef struct QLock    QLock;
36 typedef struct Queue    Queue;
37 typedef struct Ref      Ref;
38 typedef struct Rendez   Rendez;
39 typedef struct Rgrp     Rgrp;
40 typedef struct RWlock   RWlock;
41 typedef struct Sargs    Sargs;
42 typedef struct Schedq   Schedq;
43 typedef struct Segment  Segment;
44 typedef struct Sema     Sema;
45 typedef struct Timer    Timer;
46 typedef struct Timers   Timers;
47 typedef struct Uart     Uart;
48 typedef struct Waitq    Waitq;
49 typedef struct Walkqid  Walkqid;
50 typedef struct Watchdog Watchdog;
51 typedef int    Devgen(Chan*, char*, Dirtab*, int, int, Dir*);
52
53 #pragma incomplete DevConf
54 #pragma incomplete Edf
55 #pragma incomplete Mntcache
56 #pragma incomplete Mntrpc
57 #pragma incomplete Queue
58 #pragma incomplete Timers
59
60 #include <fcall.h>
61
62 struct Ref
63 {
64         Lock;
65         long    ref;
66 };
67
68 struct Rendez
69 {
70         Lock;
71         Proc    *p;
72 };
73
74 struct QLock
75 {
76         Lock    use;            /* to access Qlock structure */
77         Proc    *head;          /* next process waiting for object */
78         Proc    *tail;          /* last process waiting for object */
79         int     locked;         /* flag */
80 };
81
82 struct RWlock
83 {
84         Lock    use;
85         Proc    *head;          /* list of waiting processes */
86         Proc    *tail;
87         ulong   wpc;            /* pc of writer */
88         Proc    *wproc;         /* writing proc */
89         int     readers;        /* number of readers */
90         int     writer;         /* number of writers */
91 };
92
93 struct Alarms
94 {
95         QLock;
96         Proc    *head;
97 };
98
99 struct Sargs
100 {
101         ulong   args[MAXSYSARG];
102 };
103
104 /*
105  * Access types in namec & channel flags
106  */
107 enum
108 {
109         Aaccess,                        /* as in stat, wstat */
110         Abind,                          /* for left-hand-side of bind */
111         Atodir,                         /* as in chdir */
112         Aopen,                          /* for i/o */
113         Amount,                         /* to be mounted or mounted upon */
114         Acreate,                        /* is to be created */
115         Aremove,                        /* will be removed by caller */
116
117         COPEN   = 0x0001,               /* for i/o */
118         CMSG    = 0x0002,               /* the message channel for a mount */
119 /*rsc   CCREATE = 0x0004,               /* permits creation if c->mnt */
120         CCEXEC  = 0x0008,               /* close on exec */
121         CFREE   = 0x0010,               /* not in use */
122         CRCLOSE = 0x0020,               /* remove on close */
123         CCACHE  = 0x0080,               /* client cache */
124 };
125
126 /* flag values */
127 enum
128 {
129         BINTR   =       (1<<0),
130         BFREE   =       (1<<1),
131         Bipck   =       (1<<2),         /* ip checksum */
132         Budpck  =       (1<<3),         /* udp checksum */
133         Btcpck  =       (1<<4),         /* tcp checksum */
134         Bpktck  =       (1<<5),         /* packet checksum */
135 };
136
137 struct Block
138 {
139         long    ref;
140         Block*  next;
141         Block*  list;
142         uchar*  rp;                     /* first unconsumed byte */
143         uchar*  wp;                     /* first empty byte */
144         uchar*  lim;                    /* 1 past the end of the buffer */
145         uchar*  base;                   /* start of the buffer */
146         void    (*free)(Block*);
147         ushort  flag;
148         ushort  checksum;               /* IP checksum of complete packet (minus media header) */
149 };
150
151 #define BLEN(s) ((s)->wp - (s)->rp)
152 #define BALLOC(s) ((s)->lim - (s)->base)
153
154 struct Chan
155 {
156         Ref;                            /* the Lock in this Ref is also Chan's lock */
157         Chan*   next;                   /* allocation */
158         Chan*   link;
159         vlong   offset;                 /* in fd */
160         vlong   devoffset;              /* in underlying device; see read */
161         ushort  type;
162         ulong   dev;
163         ushort  mode;                   /* read/write */
164         ushort  flag;
165         Qid     qid;
166         int     fid;                    /* for devmnt */
167         ulong   iounit;                 /* chunk size for i/o; 0==default */
168         Mhead*  umh;                    /* mount point that derived Chan; used in unionread */
169         Chan*   umc;                    /* channel in union; held for union read */
170         QLock   umqlock;                /* serialize unionreads */
171         int     uri;                    /* union read index */
172         int     dri;                    /* devdirread index */
173         uchar*  dirrock;                /* directory entry rock for translations */
174         int     nrock;
175         int     mrock;
176         QLock   rockqlock;
177         int     ismtpt;
178         Mntcache*mcp;                   /* Mount cache pointer */
179         Mnt*    mux;                    /* Mnt for clients using me for messages */
180         union {
181                 void*   aux;
182                 Qid     pgrpid;         /* for #p/notepg */
183                 ulong   mid;            /* for ns in devproc */
184         };
185         Chan*   mchan;                  /* channel to mounted server */
186         Qid     mqid;                   /* qid of root of mount point */
187         Path*   path;
188 };
189
190 struct Path
191 {
192         Ref;
193         char    *s;
194         Chan    **mtpt;                 /* mtpt history */
195         int     len;                    /* strlen(s) */
196         int     alen;                   /* allocated length of s */
197         int     mlen;                   /* number of path elements */
198         int     malen;                  /* allocated length of mtpt */
199 };
200
201 struct Dev
202 {
203         int     dc;
204         char*   name;
205
206         void    (*reset)(void);
207         void    (*init)(void);
208         void    (*shutdown)(void);
209         Chan*   (*attach)(char*);
210         Walkqid*(*walk)(Chan*, Chan*, char**, int);
211         int     (*stat)(Chan*, uchar*, int);
212         Chan*   (*open)(Chan*, int);
213         void    (*create)(Chan*, char*, int, ulong);
214         void    (*close)(Chan*);
215         long    (*read)(Chan*, void*, long, vlong);
216         Block*  (*bread)(Chan*, long, ulong);
217         long    (*write)(Chan*, void*, long, vlong);
218         long    (*bwrite)(Chan*, Block*, ulong);
219         void    (*remove)(Chan*);
220         int     (*wstat)(Chan*, uchar*, int);
221         void    (*power)(int);  /* power mgt: power(1) => on, power (0) => off */
222         int     (*config)(int, char*, DevConf*);        /* returns nil on error */
223 };
224
225 struct Dirtab
226 {
227         char    name[KNAMELEN];
228         Qid     qid;
229         vlong   length;
230         long    perm;
231 };
232
233 struct Walkqid
234 {
235         Chan    *clone;
236         int     nqid;
237         Qid     qid[1];
238 };
239
240 enum
241 {
242         NSMAX   =       1000,
243         NSLOG   =       7,
244         NSCACHE =       (1<<NSLOG),
245 };
246
247 struct Mntwalk                          /* state for /proc/#/ns */
248 {
249         int     cddone;
250         Mhead*  mh;
251         Mount*  cm;
252 };
253
254 struct Mount
255 {
256         ulong   mountid;
257         Mount*  next;
258         Mhead*  head;
259         Mount*  copy;
260         Mount*  order;
261         Chan*   to;                     /* channel replacing channel */
262         int     mflag;
263         char    *spec;
264 };
265
266 struct Mhead
267 {
268         Ref;
269         RWlock  lock;
270         Chan*   from;                   /* channel mounted upon */
271         Mount*  mount;                  /* what's mounted upon it */
272         Mhead*  hash;                   /* Hash chain */
273 };
274
275 struct Mnt
276 {
277         Lock;
278         /* references are counted using c->ref; channels on this mount point incref(c->mchan) == Mnt.c */
279         Chan    *c;             /* Channel to file service */
280         Proc    *rip;           /* Reader in progress */
281         Mntrpc  *queue;         /* Queue of pending requests on this channel */
282         ulong   id;             /* Multiplexer id for channel check */
283         Mnt     *list;          /* Free list */
284         int     flags;          /* cache */
285         int     msize;          /* data + IOHDRSZ */
286         char    *version;       /* 9P version */
287         Queue   *q;             /* input queue */
288 };
289
290 enum
291 {
292         NUser,                          /* note provided externally */
293         NExit,                          /* deliver note quietly */
294         NDebug,                         /* print debug message */
295 };
296
297 struct Note
298 {
299         char    msg[ERRMAX];
300         int     flag;                   /* whether system posted it */
301 };
302
303 enum
304 {
305         PG_NOFLUSH      = 0,
306         PG_TXTFLUSH     = 1,            /* flush dcache and invalidate icache */
307         PG_DATFLUSH     = 2,            /* flush both i & d caches (UNUSED) */
308         PG_NEWCOL       = 3,            /* page has been recolored */
309
310         PG_MOD          = 0x01,         /* software modified bit */
311         PG_REF          = 0x02,         /* software referenced bit */
312 };
313
314 struct Page
315 {
316         Lock;
317         ulong   pa;                     /* Physical address in memory */
318         ulong   va;                     /* Virtual address for user */
319         ulong   daddr;                  /* Disc address on swap */
320         ulong   gen;                    /* Generation counter for swap */
321         ushort  ref;                    /* Reference count */
322         char    modref;                 /* Simulated modify/reference bits */
323         char    color;                  /* Cache coloring */
324         char    cachectl[MAXMACH];      /* Cache flushing control for putmmu */
325         Image   *image;                 /* Associated text or swap image */
326         Page    *next;                  /* Lru free list */
327         Page    *prev;
328         Page    *hash;                  /* Image hash chains */
329 };
330
331 struct Swapalloc
332 {
333         Lock;                           /* Free map lock */
334         int     free;                   /* currently free swap pages */
335         uchar*  swmap;                  /* Base of swap map in memory */
336         uchar*  alloc;                  /* Round robin allocator */
337         uchar*  last;                   /* Speed swap allocation */
338         uchar*  top;                    /* Top of swap map */
339         Rendez  r;                      /* Pager kproc idle sleep */
340         ulong   highwater;              /* Pager start threshold */
341         ulong   headroom;               /* Space pager frees under highwater */
342 }swapalloc;
343
344 struct Image
345 {
346         Ref;
347         Chan    *c;                     /* channel to text file */
348         Qid     qid;                    /* Qid for page cache coherence */
349         Qid     mqid;
350         Chan    *mchan;
351         ushort  type;                   /* Device type of owning channel */
352         Segment *s;                     /* TEXT segment for image if running */
353         Image   *hash;                  /* Qid hash chains */
354         Image   *next;                  /* Free list */
355         int     notext;                 /* no file associated */
356 };
357
358 struct Pte
359 {
360         Page    *pages[PTEPERTAB];      /* Page map for this chunk of pte */
361         Page    **first;                /* First used entry */
362         Page    **last;                 /* Last used entry */
363 };
364
365 /* Segment types */
366 enum
367 {
368         SG_TYPE         = 07,           /* Mask type of segment */
369         SG_TEXT         = 00,
370         SG_DATA         = 01,
371         SG_BSS          = 02,
372         SG_STACK        = 03,
373         SG_SHARED       = 04,
374         SG_PHYSICAL     = 05,
375
376         SG_RONLY        = 0040,         /* Segment is read only */
377         SG_CEXEC        = 0100,         /* Detach at exec */
378 };
379
380 #define PG_ONSWAP       1
381 #define onswap(s)       (((ulong)s)&PG_ONSWAP)
382 #define pagedout(s)     (((ulong)s)==0 || onswap(s))
383 #define swapaddr(s)     (((ulong)s)&~PG_ONSWAP)
384
385 #define SEGMAXSIZE      (SEGMAPSIZE*PTEMAPMEM)
386
387 struct Physseg
388 {
389         ulong   attr;                   /* Segment attributes */
390         char    *name;                  /* Attach name */
391         ulong   pa;                     /* Physical address */
392         ulong   size;                   /* Maximum segment size in pages */
393         Page    *(*pgalloc)(Segment*, ulong);   /* Allocation if we need it */
394         void    (*pgfree)(Page*);
395 };
396
397 struct Sema
398 {
399         Rendez;
400         long    *addr;
401         int     waiting;
402         Sema    *next;
403         Sema    *prev;
404 };
405
406 struct Segment
407 {
408         Ref;
409         QLock   lk;
410         ushort  steal;          /* Page stealer lock */
411         ushort  type;           /* segment type */
412         ulong   base;           /* virtual base */
413         ulong   top;            /* virtual top */
414         ulong   size;           /* size in pages */
415         ulong   fstart;         /* start address in file for demand load */
416         ulong   flen;           /* length of segment in file */
417         int     flushme;        /* maintain icache for this segment */
418         Image   *image;         /* text in file attached to this segment */
419         Physseg *pseg;
420         ulong*  profile;        /* Tick profile area */
421         Pte     **map;
422         int     mapsize;
423         Pte     *ssegmap[SSEGMAPSIZE];
424         Lock    semalock;
425         Sema    sema;
426         ulong   mark;           /* portcountrefs */
427 };
428
429 enum
430 {
431         RENDLOG =       5,
432         RENDHASH =      1<<RENDLOG,     /* Hash to lookup rendezvous tags */
433         MNTLOG  =       5,
434         MNTHASH =       1<<MNTLOG,      /* Hash to walk mount table */
435         NFD =           100,            /* per process file descriptors */
436         PGHLOG  =       9,
437         PGHSIZE =       1<<PGHLOG,      /* Page hash for image lookup */
438 };
439 #define REND(p,s)       ((p)->rendhash[(s)&((1<<RENDLOG)-1)])
440 #define MOUNTH(p,qid)   ((p)->mnthash[(qid).path&((1<<MNTLOG)-1)])
441
442 struct Pgrp
443 {
444         Ref;                            /* also used as a lock when mounting */
445         int     noattach;
446         ulong   pgrpid;
447         QLock   debug;                  /* single access via devproc.c */
448         RWlock  ns;                     /* Namespace n read/one write lock */
449         Mhead   *mnthash[MNTHASH];
450 };
451
452 struct Rgrp
453 {
454         Ref;                            /* the Ref's lock is also the Rgrp's lock */
455         Proc    *rendhash[RENDHASH];    /* Rendezvous tag hash */
456 };
457
458 struct Egrp
459 {
460         Ref;
461         RWlock;
462         Evalue  **ent;
463         int     nent;
464         int     ment;
465         ulong   path;   /* qid.path of next Evalue to be allocated */
466         ulong   vers;   /* of Egrp */
467 };
468
469 struct Evalue
470 {
471         char    *name;
472         char    *value;
473         int     len;
474         Evalue  *link;
475         Qid     qid;
476 };
477
478 struct Fgrp
479 {
480         Ref;
481         Chan    **fd;
482         int     nfd;                    /* number allocated */
483         int     maxfd;                  /* highest fd in use */
484         int     exceed;                 /* debugging */
485 };
486
487 enum
488 {
489         DELTAFD = 20            /* incremental increase in Fgrp.fd's */
490 };
491
492 struct Pallocmem
493 {
494         ulong base;
495         ulong npage;
496 };
497
498 struct Palloc
499 {
500         Lock;
501         Pallocmem       mem[4];
502         Page    *head;                  /* most recently used */
503         Page    *tail;                  /* least recently used */
504         ulong   freecount;              /* how many pages on free list now */
505         Page    *pages;                 /* array of all pages */
506         ulong   user;                   /* how many user pages */
507         Page    *hash[PGHSIZE];
508         Lock    hashlock;
509         Rendez  r;                      /* Sleep for free mem */
510         QLock   pwait;                  /* Queue of procs waiting for memory */
511 };
512
513 struct Waitq
514 {
515         Waitmsg w;
516         Waitq   *next;
517 };
518
519 /*
520  * fasttick timer interrupts
521  */
522 enum {
523         /* Mode */
524         Trelative,      /* timer programmed in ns from now */
525         Tperiodic,      /* periodic timer, period in ns */
526 };
527
528 struct Timer
529 {
530         /* Public interface */
531         int     tmode;          /* See above */
532         vlong   tns;            /* meaning defined by mode */
533         void    (*tf)(Ureg*, Timer*);
534         void    *ta;
535         /* Internal */
536         Lock;
537         Timers  *tt;            /* Timers queue this timer runs on */
538         Tval    tticks;         /* tns converted to ticks */
539         Tval    twhen;          /* ns represented in fastticks */
540         Timer   *tnext;
541 };
542
543 enum
544 {
545         RFNAMEG         = (1<<0),
546         RFENVG          = (1<<1),
547         RFFDG           = (1<<2),
548         RFNOTEG         = (1<<3),
549         RFPROC          = (1<<4),
550         RFMEM           = (1<<5),
551         RFNOWAIT        = (1<<6),
552         RFCNAMEG        = (1<<10),
553         RFCENVG         = (1<<11),
554         RFCFDG          = (1<<12),
555         RFREND          = (1<<13),
556         RFNOMNT         = (1<<14),
557 };
558
559 /*
560  *  process memory segments - NSEG always last !
561  */
562 enum
563 {
564         SSEG, TSEG, DSEG, BSEG, ESEG, LSEG, SEG1, SEG2, SEG3, SEG4, NSEG
565 };
566
567 enum
568 {
569         Dead = 0,               /* Process states */
570         Moribund,
571         Ready,
572         Scheding,
573         Running,
574         Queueing,
575         QueueingR,
576         QueueingW,
577         Wakeme,
578         Broken,
579         Stopped,
580         Rendezvous,
581         Waitrelease,
582
583         Proc_stopme = 1,        /* devproc requests */
584         Proc_exitme,
585         Proc_traceme,
586         Proc_exitbig,
587         Proc_tracesyscall,
588
589         TUser = 0,              /* Proc.time */
590         TSys,
591         TReal,
592         TCUser,
593         TCSys,
594         TCReal,
595
596         NERR = 64,
597         NNOTE = 5,
598
599         Npriq           = 20,           /* number of scheduler priority levels */
600         Nrq             = Npriq+2,      /* number of priority levels including real time */
601         PriRelease      = Npriq,        /* released edf processes */
602         PriEdf          = Npriq+1,      /* active edf processes */
603         PriNormal       = 10,           /* base priority for normal processes */
604         PriExtra        = Npriq-1,      /* edf processes at high best-effort pri */
605         PriKproc        = 13,           /* base priority for kernel processes */
606         PriRoot         = 13,           /* base priority for root processes */
607 };
608
609 struct Schedq
610 {
611         Lock;
612         Proc*   head;
613         Proc*   tail;
614         int     n;
615 };
616
617 struct Proc
618 {
619         Label   sched;          /* known to l.s */
620         char    *kstack;        /* known to l.s */
621         Mach    *mach;          /* machine running this proc */
622         char    *text;
623         char    *user;
624         char    *args;
625         int     nargs;          /* number of bytes of args */
626         Proc    *rnext;         /* next process in run queue */
627         Proc    *qnext;         /* next process on queue for a QLock */
628         QLock   *qlock;         /* addr of qlock being queued for DEBUG */
629         int     state;
630         char    *psstate;       /* What /proc/#/status reports */
631         Segment *seg[NSEG];
632         QLock   seglock;        /* locked whenever seg[] changes */
633         ulong   pid;
634         ulong   noteid;         /* Equivalent of note group */
635         Proc    *pidhash;       /* next proc in pid hash */
636
637         Lock    exl;            /* Lock count and waitq */
638         Waitq   *waitq;         /* Exited processes wait children */
639         int     nchild;         /* Number of living children */
640         int     nwait;          /* Number of uncollected wait records */
641         QLock   qwaitr;
642         Rendez  waitr;          /* Place to hang out in wait */
643         Proc    *parent;
644
645         Pgrp    *pgrp;          /* Process group for namespace */
646         Egrp    *egrp;          /* Environment group */
647         Fgrp    *fgrp;          /* File descriptor group */
648         Rgrp    *rgrp;          /* Rendez group */
649
650         Fgrp    *closingfgrp;   /* used during teardown */
651
652         ulong   parentpid;
653         ulong   time[6];        /* User, Sys, Real; child U, S, R */
654
655         uvlong  kentry;         /* Kernel entry time stamp (for profiling) */
656         /*
657          * pcycles: cycles spent in this process (updated on procsave/restore)
658          * when this is the current proc and we're in the kernel
659          * (procrestores outnumber procsaves by one)
660          * the number of cycles spent in the proc is pcycles + cycles()
661          * when this is not the current process or we're in user mode
662          * (procrestores and procsaves balance), it is pcycles.
663          */
664         vlong   pcycles;
665
666         int     insyscall;
667         int     fpstate;
668
669         QLock   debug;          /* to access debugging elements of User */
670         Proc    *pdbg;          /* the debugging process */
671         ulong   procmode;       /* proc device default file mode */
672         ulong   privatemem;     /* proc does not let anyone read mem */
673         int     hang;           /* hang at next exec for debug */
674         int     procctl;        /* Control for /proc debugging */
675         ulong   pc;             /* DEBUG only */
676
677         Lock    rlock;          /* sync sleep/wakeup with postnote */
678         Rendez  *r;             /* rendezvous point slept on */
679         Rendez  sleep;          /* place for syssleep/debug */
680         int     notepending;    /* note issued but not acted on */
681         int     kp;             /* true if a kernel process */
682         Proc    *palarm;        /* Next alarm time */
683         ulong   alarm;          /* Time of call */
684         int     newtlb;         /* Pager has changed my pte's, I must flush */
685         int     noswap;         /* process is not swappable */
686
687         uintptr rendtag;        /* Tag for rendezvous */
688         uintptr rendval;        /* Value for rendezvous */
689         Proc    *rendhash;      /* Hash list for tag values */
690
691         Timer;                  /* For tsleep and real-time */
692         Rendez  *trend;
693         int     (*tfn)(void*);
694         void    (*kpfun)(void*);
695         void    *kparg;
696
697         FPsave  fpsave;         /* address of this is known by db */
698         int     scallnr;        /* sys call number - known by db */
699         Sargs   s;              /* address of this is known by db */
700         int     nerrlab;
701         Label   errlab[NERR];
702         char    *syserrstr;     /* last error from a system call, errbuf0 or 1 */
703         char    *errstr;        /* reason we're unwinding the error stack, errbuf1 or 0 */
704         char    errbuf0[ERRMAX];
705         char    errbuf1[ERRMAX];
706         char    genbuf[128];    /* buffer used e.g. for last name element from namec */
707         Chan    *slash;
708         Chan    *dot;
709
710         Note    note[NNOTE];
711         short   nnote;
712         short   notified;       /* sysnoted is due */
713         Note    lastnote;
714         int     (*notify)(void*, char*);
715
716         Lock    *lockwait;
717         Lock    *lastlock;      /* debugging */
718         Lock    *lastilock;     /* debugging */
719
720         Mach    *wired;
721         Mach    *mp;            /* machine this process last ran on */
722         Ref     nlocks;         /* number of locks held by proc */
723         ulong   delaysched;
724         ulong   priority;       /* priority level */
725         ulong   basepri;        /* base priority level */
726         uchar   fixedpri;       /* priority level deson't change */
727         ulong   cpu;            /* cpu average */
728         ulong   lastupdate;
729         uchar   yield;          /* non-zero if the process just did a sleep(0) */
730         ulong   readytime;      /* time process came ready */
731         ulong   movetime;       /* last time process switched processors */
732         int     preempted;      /* true if this process hasn't finished the interrupt
733                                  *  that last preempted it
734                                  */
735         Edf     *edf;           /* if non-null, real-time proc, edf contains scheduling params */
736         int     trace;          /* process being traced? */
737
738         ulong   qpc;            /* pc calling last blocking qlock */
739
740         int     setargs;
741
742         void    *ureg;          /* User registers for notes */
743         void    *dbgreg;        /* User registers for devproc */
744         Notsave;
745
746         /*
747          *  machine specific MMU
748          */
749         PMMU;
750         char    *syscalltrace;  /* syscall trace */
751 };
752
753 enum
754 {
755         PRINTSIZE =     256,
756         MAXCRYPT =      127,
757         NUMSIZE =       12,             /* size of formatted number */
758         MB =            (1024*1024),
759         /* READSTR was 1000, which is way too small for usb's ctl file */
760         READSTR =       4000,           /* temporary buffer size for device reads */
761 };
762
763 extern  Conf    conf;
764 extern  char*   conffile;
765 extern  int     cpuserver;
766 extern  Dev*    devtab[];
767 extern  char*   eve;
768 extern  char    hostdomain[];
769 extern  uchar   initcode[];
770 extern  int     kbdbuttons;
771 extern  Queue*  kbdq;
772 extern  Queue*  kprintoq;
773 extern  Ref     noteidalloc;
774 extern  int     nsyscall;
775 extern  Palloc  palloc;
776 extern  Queue*  serialoq;
777 extern  char*   statename[];
778 extern  Image   swapimage;
779 extern  char*   sysname;
780 extern  uint    qiomaxatomic;
781 extern  char*   sysctab[];
782
783 enum
784 {
785         LRESPROF        = 3,
786 };
787
788 /*
789  *  action log
790  */
791 struct Log {
792         Lock;
793         int     opens;
794         char*   buf;
795         char    *end;
796         char    *rptr;
797         int     len;
798         int     nlog;
799         int     minread;
800
801         int     logmask;        /* mask of things to debug */
802
803         QLock   readq;
804         Rendez  readr;
805 };
806
807 struct Logflag {
808         char*   name;
809         int     mask;
810 };
811
812 enum
813 {
814         NCMDFIELD = 128
815 };
816
817 struct Cmdbuf
818 {
819         char    *buf;
820         char    **f;
821         int     nf;
822 };
823
824 struct Cmdtab
825 {
826         int     index;  /* used by client to switch on result */
827         char    *cmd;   /* command name */
828         int     narg;   /* expected #args; 0 ==> variadic */
829 };
830
831 /*
832  *  routines to access UART hardware
833  */
834 struct PhysUart
835 {
836         char*   name;
837         Uart*   (*pnp)(void);
838         void    (*enable)(Uart*, int);
839         void    (*disable)(Uart*);
840         void    (*kick)(Uart*);
841         void    (*dobreak)(Uart*, int);
842         int     (*baud)(Uart*, int);
843         int     (*bits)(Uart*, int);
844         int     (*stop)(Uart*, int);
845         int     (*parity)(Uart*, int);
846         void    (*modemctl)(Uart*, int);
847         void    (*rts)(Uart*, int);
848         void    (*dtr)(Uart*, int);
849         long    (*status)(Uart*, void*, long, long);
850         void    (*fifo)(Uart*, int);
851         void    (*power)(Uart*, int);
852         int     (*getc)(Uart*); /* polling versions, for iprint, rdb */
853         void    (*putc)(Uart*, int);
854 };
855
856 enum {
857         Stagesize=      2048
858 };
859
860 /*
861  *  software UART
862  */
863 struct Uart
864 {
865         void*   regs;                   /* hardware stuff */
866         void*   saveregs;               /* place to put registers on power down */
867         char*   name;                   /* internal name */
868         ulong   freq;                   /* clock frequency */
869         int     bits;                   /* bits per character */
870         int     stop;                   /* stop bits */
871         int     parity;                 /* even, odd or no parity */
872         int     baud;                   /* baud rate */
873         PhysUart*phys;
874         int     console;                /* used as a serial console */
875         int     special;                /* internal kernel device */
876         Uart*   next;                   /* list of allocated uarts */
877
878         QLock;
879         int     type;                   /* ?? */
880         int     dev;
881         int     opens;
882
883         int     enabled;
884         Uart    *elist;                 /* next enabled interface */
885
886         int     perr;                   /* parity errors */
887         int     ferr;                   /* framing errors */
888         int     oerr;                   /* rcvr overruns */
889         int     berr;                   /* no input buffers */
890         int     serr;                   /* input queue overflow */
891
892         /* buffers */
893         int     (*putc)(Queue*, int);
894         Queue   *iq;
895         Queue   *oq;
896
897         Lock    rlock;
898         uchar   istage[Stagesize];
899         uchar   *iw;
900         uchar   *ir;
901         uchar   *ie;
902
903         Lock    tlock;                  /* transmit */
904         uchar   ostage[Stagesize];
905         uchar   *op;
906         uchar   *oe;
907         int     drain;
908
909         int     modem;                  /* hardware flow control on */
910         int     xonoff;                 /* software flow control on */
911         int     blocked;
912         int     cts, dsr, dcd;  /* keep track of modem status */ 
913         int     ctsbackoff;
914         int     hup_dsr, hup_dcd;       /* send hangup upstream? */
915         int     dohup;
916
917         Rendez  r;
918 };
919
920 extern  Uart*   consuart;
921
922 struct Audio {
923         Audio *next;
924         char *name;
925         void *ctlr;
926         void *mixer;
927         void (*attach)(Audio *);
928         long (*read)(Audio *, void *, long, vlong);
929         long (*write)(Audio *, void *, long, vlong);
930         long (*volread)(Audio *, void *, long, vlong);
931         long (*volwrite)(Audio *, void *, long, vlong);
932         void (*close)(Audio *);
933         long (*ctl)(Audio *, void *, long, vlong);
934         long (*status)(Audio *, void *, long, vlong);
935         long (*buffered)(Audio *);
936         int ctlrno;
937 };
938
939 /*
940  *  performance timers, all units in perfticks
941  */
942 struct Perf
943 {
944         ulong   intrts;         /* time of last interrupt */
945         ulong   inintr;         /* time since last clock tick in interrupt handlers */
946         ulong   avg_inintr;     /* avg time per clock tick in interrupt handlers */
947         ulong   inidle;         /* time since last clock tick in idle loop */
948         ulong   avg_inidle;     /* avg time per clock tick in idle loop */
949         ulong   last;           /* value of perfticks() at last clock tick */
950         ulong   period;         /* perfticks() per clock tick */
951 };
952
953 struct Watchdog
954 {
955         void    (*enable)(void);        /* watchdog enable */
956         void    (*disable)(void);       /* watchdog disable */
957         void    (*restart)(void);       /* watchdog restart */
958         void    (*stat)(char*, char*);  /* watchdog statistics */
959 };
960
961
962 /* queue state bits,  Qmsg, Qcoalesce, and Qkick can be set in qopen */
963 enum
964 {
965         /* Queue.state */
966         Qstarve         = (1<<0),       /* consumer starved */
967         Qmsg            = (1<<1),       /* message stream */
968         Qclosed         = (1<<2),       /* queue has been closed/hungup */
969         Qflow           = (1<<3),       /* producer flow controlled */
970         Qcoalesce       = (1<<4),       /* coallesce packets on read */
971         Qkick           = (1<<5),       /* always call the kick routine after qwrite */
972 };
973
974 #define DEVDOTDOT -1
975
976 #pragma varargck        type    "I"     uchar*
977 #pragma varargck        type    "V"     uchar*
978 #pragma varargck        type    "E"     uchar*
979 #pragma varargck        type    "M"     uchar*