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