home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / include / sys / stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-26  |  16.1 KB  |  589 lines

  1. /*    Copyright (c) 1984, 1986, 1987, 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8.  
  9. #ident    "@(#)head.sys:stream.h    1.4.1.1"
  10.  
  11. /*
  12.  * data queue
  13.  */
  14. struct    queue {
  15.     struct    qinit    *q_qinfo;    /* procs and limits for queue */
  16.     struct    msgb    *q_first;    /* first data block */
  17.     struct    msgb    *q_last;    /* last data block */
  18.     struct    queue    *q_next;    /* Q of next stream */
  19.     struct    queue    *q_link;    /* to next Q for scheduling */
  20.     caddr_t    q_ptr;            /* to private data structure */
  21.     ushort    q_count;        /* number of blocks on Q */
  22.     ushort    q_flag;            /* queue state */
  23.     short q_minpsz;            /* min packet size accepted by this module */
  24.     short q_maxpsz;            /* max packet size accepted by this module */
  25.     ushort q_hiwat;            /* queue high water mark */
  26.     ushort q_lowat;            /* queue low water mark */
  27. };
  28.  
  29. typedef struct queue queue_t;
  30.  
  31. /*
  32.  * Queue flags
  33.  */
  34. #define    QENAB    01            /* Queue is already enabled to run */
  35. #define    QWANTR    02            /* Someone wants to read Q */
  36. #define    QWANTW    04            /* Someone wants to write Q */
  37. #define    QFULL    010            /* Q is considered full */
  38. #define    QREADR    020            /* This is the reader (first) Q */
  39. #define    QUSE    040            /* This queue in use (allocation) */
  40. #define    QNOENB    0100            /* Don't enable Q via putq */
  41.  
  42.  
  43.  
  44. /*
  45.  * module information structure
  46.  */
  47. struct module_info {
  48.     ushort    mi_idnum;        /* module id number */
  49.     char     *mi_idname;        /* module name */
  50.     short   mi_minpsz;        /* min packet size accepted */
  51.     short   mi_maxpsz;        /* max packet size accepted */
  52.     ushort    mi_hiwat;        /* hi-water mark */
  53.     ushort     mi_lowat;        /* lo-water mark */
  54. };
  55.  
  56.  
  57. /*
  58.  * queue information structure
  59.  */
  60. struct    qinit {
  61.     int    (*qi_putp)();        /* put procedure */
  62.     int    (*qi_srvp)();        /* service procedure */
  63.     int    (*qi_qopen)();        /* called on startup */
  64.     int    (*qi_qclose)();        /* called on finish */
  65.     int    (*qi_qadmin)();        /* for 3bnet only */
  66.     struct module_info *qi_minfo;    /* module information structure */
  67.     struct module_stat *qi_mstat;    /* module statistics structure */
  68. };
  69.  
  70.  
  71.  
  72.  
  73. /*
  74.  * Streamtab (used in cdevsw and fmodsw to point to module or driver)
  75.  */
  76.  
  77. struct streamtab {
  78.     struct qinit *st_rdinit;
  79.     struct qinit *st_wrinit;
  80.     struct qinit *st_muxrinit;
  81.     struct qinit *st_muxwinit;
  82. };
  83.  
  84.  
  85.  
  86. /*
  87.  * Header for a stream: interface to rest of system
  88.  */
  89.  
  90. struct stdata {
  91.     struct    queue *sd_wrq;        /* write queue */
  92.     struct    msgb *sd_iocblk;    /* return block for ioctl */
  93.     dev_t    sd_rdev;        /* device number */
  94.     ushort    sd_icnt;        /* number of inodes pointing to stream */
  95.     struct     streamtab *sd_strtab;    /* pointer to streamtab for stream */
  96.     long    sd_flag;        /* state/flags */
  97.     long    sd_iocid;        /* ioctl id */
  98.     ushort    sd_iocwait;        /* count of procs waiting to do ioctl */
  99.     short    sd_pgrp;        /* process group, for signals */
  100.     ushort    sd_wroff;        /* write offset */
  101.     unsigned char  sd_error;    /* hangup or error to set u.u_error */
  102.     int    sd_pushcnt;        /* number of pushes done on stream */
  103.     struct  strevent *sd_siglist;    /* pid linked list to rcv SIGPOLL sig */
  104.     struct    strevent *sd_pollist;    /* pid linked list to wakeup poll() */
  105.     int    sd_sigflags;        /* logical OR of all siglist events */
  106.     int    sd_pollflags;        /* logical OR of all sellist events */
  107. };
  108.  
  109.  
  110.  
  111. /*
  112.  * stdata flag field defines
  113.  */
  114. #define    IOCWAIT        01        /* Someone wants to do ioctl */
  115. #define RSLEEP        02        /* Someone wants to read/recv msg */
  116. #define    WSLEEP        04        /* Someone wants to write */
  117. #define STRPRI           010        /* An M_PCPROTO is at stream head */
  118. #define    STRHUP           020        /* Device has vanished */
  119. #define    STWOPEN           040        /* waiting for 1st open */
  120. #define STPLEX          0100        /* stream is being multiplexed */
  121. #define CTTYFLG          0200        /* used of finding control tty */
  122. #define RMSGDIS          0400        /* read msg discard */
  123. #define RMSGNODIS    01000        /* read msg no discard */
  124. #define STRERR         02000        /* fatal error from M_ERROR */
  125. #define STRTIME      04000        /* used with timeout strtime */
  126. #define STR2TIME    010000        /* used with timeout str2time */
  127. #define STR3TIME    020000        /* used with timeout str3time */
  128. #define STRCLOSE    040000              /* wait for a close to complete */
  129. #define SNDMREAD   0100000              /* used for read notification */
  130. #define OLDNDELAY  0200000        /* use old TTY semantics for NDELAY reads
  131.                        and writes */
  132. #define RDBUFWAIT  0400000              /* used with bufcall in strqbuf() */
  133.  
  134. /*
  135.  * value in sd_wrq to reserve stream
  136.  */
  137.  
  138. #define RESERVED    1
  139.  
  140. /* 
  141.  * structure for storing triples of mux'ed streams 
  142.  */
  143. struct linkblk {
  144.     queue_t *l_qtop;    /* lowest level write queue of upper stream */
  145.     queue_t *l_qbot;    /* highest level write queue of lower stream */
  146.     int      l_index;    /* file[] index for lower stream. */
  147. };
  148.  
  149.  
  150. /*
  151.  * Structure of list of processes to be sent SIGSEL signal
  152.  * on request, or for processes sleeping on select().  The valid 
  153.  * SIGSEL events are defined in stropts.h, and the valid select()
  154.  * events are defined in select.h.
  155.  */
  156. struct strevent {
  157.     union {
  158.         struct {
  159.             struct proc     *procp;
  160.             long         events;
  161.             } e;
  162.         struct {
  163.             int (*func)();
  164.             long arg;
  165.             } b;
  166.     } x;
  167.     struct strevent *se_next;
  168. };
  169.  
  170. #define se_procp x.e.procp
  171. #define se_events x.e.events
  172. #define se_func x.b.func
  173. #define se_arg x.b.arg
  174.  
  175. #define SE_SLEEP    0    /* ok to sleep in allocation */
  176. #define SE_NOSLP    1    /* don't sleep in allocation */
  177.  
  178.  
  179. /*
  180.  *  Data block descriptor
  181.  */
  182. struct datab {
  183.     struct datab    *db_freep;
  184.     unsigned char    *db_base;
  185.     unsigned char    *db_lim;
  186.     unsigned char    db_ref;
  187.     unsigned char    db_type;
  188.     unsigned char    db_class;
  189. };
  190.  
  191.  
  192. /*
  193.  * Message block descriptor
  194.  */
  195. struct    msgb {
  196.     struct    msgb    *b_next;
  197.     struct  msgb    *b_prev;
  198.     struct    msgb    *b_cont;
  199.     unsigned char    *b_rptr;
  200.     unsigned char    *b_wptr;
  201.     struct datab     *b_datap;
  202. };
  203.  
  204. typedef struct msgb mblk_t;
  205. typedef struct datab dblk_t;
  206.  
  207.  
  208.  
  209.  
  210. /*
  211.  * Data block allocation information.  Defines cutoffs for allocation 
  212.  * priorities; bufcall lists. 
  213.  */
  214.  
  215. struct dbalcst {
  216.     int dba_cnt;
  217.     int dba_lo;
  218.     int dba_med;
  219.     struct strevent *dba_lop;
  220.     struct strevent *dba_medp;
  221.     struct strevent *dba_hip;
  222. };
  223.  
  224.  
  225.  
  226. /********************************************************************************/
  227. /*             Streams message types                    */
  228. /********************************************************************************/
  229.  
  230.  
  231. /*
  232.  * Data and protocol messages (regular priority)
  233.  */
  234. #define    M_DATA        00        /* regular data */
  235. #define M_PROTO        01        /* protocol control */
  236.  
  237. /*
  238.  * Control messages (regular priority)
  239.  */
  240. #define    M_BREAK        010        /* line break */
  241. #define M_PASSFP    011        /* pass file pointer */
  242. #define    M_SIG        013        /* generate process signal */
  243. #define    M_DELAY        014        /* real-time xmit delay (1 param) */
  244. #define M_CTL        015        /* device-specific control message */
  245. #define    M_IOCTL        016        /* ioctl; set/get params */
  246. #define M_SETOPTS    020        /* set various stream head options */
  247. #define M_RSE        021        /* reserved for RSE use only */
  248.  
  249.  
  250. /*
  251.  * Control messages (high priority; go to head of queue)
  252.  */
  253. #define    M_IOCACK    0201        /* acknowledge ioctl */
  254. #define    M_IOCNAK    0202        /* negative ioctl acknowledge */
  255. #define M_PCPROTO    0203        /* priority proto message */
  256. #define    M_PCSIG        0204        /* generate process signal */
  257. #define    M_READ        0205        /* generate read notification */
  258. #define    M_FLUSH        0206        /* flush your queues */
  259. #define    M_STOP        0207        /* stop transmission immediately */
  260. #define    M_START        0210        /* restart transmission after stop */
  261. #define    M_HANGUP    0211        /* line disconnect */
  262. #define M_ERROR        0212        /* fatal error used to set u.u_error */
  263. #define M_COPYIN    0213        /* request to copin data */
  264. #define M_COPYOUT    0214        /* request to copyout data */
  265. #define M_IOCDATA    0215        /* response to M_COPYIN and M_COPYOUT */
  266. #define M_PCRSE        0216        /* reserved for RSE use only */
  267.  
  268.  
  269. /*
  270.  * Queue message class definitions.  
  271.  */
  272. #define QNORM    0            /* normal messages */
  273. #define QPCTL 0200            /* priority cntrl messages */
  274.  
  275.  
  276.  
  277. /*
  278.  *  IOCTL structure - this structure is the format of the M_IOCTL message type.
  279.  */
  280. struct iocblk {
  281.     int     ioc_cmd;        /* ioctl command type */
  282.     ushort    ioc_uid;        /* effective uid of user */
  283.     ushort    ioc_gid;        /* effective gid of user */
  284.     uint    ioc_id;            /* ioctl id */
  285.     uint    ioc_count;        /* count of bytes in data field */
  286.     int    ioc_error;        /* error code */
  287.     int    ioc_rval;        /* return value  */
  288. };
  289.  
  290. /*
  291.  * structure for the M_COPYIN and M_COPYOUT message types.
  292.  */
  293.  
  294. struct copyreq {
  295.     int    cq_cmd;            /* ioctl command (from ioc_cmd) */
  296.     ushort    cq_uid;            /* effective uid of user */
  297.     ushort    cq_gid;            /* effective gid of user */
  298.     uint    cq_id;            /* ioctl id (from ioc_id) */
  299.     caddr_t    cq_addr;        /* address to copy data to/from */
  300.     uint    cq_size;        /* number of bytes to copy */
  301.     int    cq_flag;        /* see below */
  302.     mblk_t *cq_private;        /* privtate state information */
  303. };
  304.  
  305. /* cq_flag values */
  306.  
  307. #define STRCANON    0x01        /* b_cont data block contains canonical
  308.                        format specifier */
  309. #define RECOPY        0x02        /* perform I_STR copyin again, this time
  310.                        using canonical format specifier */
  311.  
  312.  
  313. /*
  314.  * structure for the M_IOCDATA message type.
  315.  */
  316.  
  317. struct copyresp {
  318.     int    cp_cmd;            /* ioctl command (from ioc_cmd) */
  319.     ushort    cp_uid;            /* effective uid of user */
  320.     ushort    cp_gid;            /* effective gid of user */
  321.     uint    cp_id;            /* ioctl id (from ioc_id) */
  322.     caddr_t    cp_rval;        /* status of request: 0 -> success
  323.                                   non-zero -> failure */
  324.     uint    cp_pad1;        /* reserved */
  325.     int    cp_pad2;        /* reserved */
  326.     mblk_t *cp_private;        /* private state information */
  327. };
  328.  
  329. /*
  330.  * Options structure for M_SETOPTS message.  This is sent upstream
  331.  * by driver to set stream head options.
  332.  */
  333. struct stroptions {
  334.     short so_flags;        /* options to set */
  335.     short so_readopt;    /* read option */
  336.     ushort so_wroff;    /* write offset */
  337.     short so_minpsz;    /* minimum read packet size */
  338.     short so_maxpsz;    /* maximum read packet size */
  339.     ushort so_hiwat;    /* read queue high water mark */
  340.     ushort so_lowat;    /* read queue low water mark */
  341. };
  342.  
  343. /* flags for stream options set message */
  344.  
  345. #define SO_ALL        077    /* set all options */
  346. #define SO_READOPT     01    /* set read opttion */
  347. #define SO_WROFF     02    /* set write offset */
  348. #define SO_MINPSZ     04    /* set min packet size */
  349. #define SO_MAXPSZ    010    /* set max packet size */
  350. #define SO_HIWAT    020    /* set high water mark */
  351. #define SO_LOWAT    040    /* set low water mark */
  352. #define SO_MREADON       0100    /* set read notification ON */
  353. #define SO_MREADOFF      0200    /* set read notification OFF */
  354. #define SO_NDELON     0400    /* old TTY semantics for NDELAY reads and writes */
  355. #define SO_NDELOFF      01000    /* old TTY semantics for NDELAY reads and writes */
  356.  
  357.  
  358.  
  359.  
  360. /********************************************************************************/
  361. /*        Miscellaneous parameters and flags                */
  362. /********************************************************************************/
  363.  
  364. /*
  365.  * Default timeout in seconds for ioctls and close
  366.  */
  367. #define STRTIMOUT 15
  368.  
  369. /*
  370.  * Stream head default high/low water marks 
  371.  */
  372. #define STRHIGH 5120
  373. #define STRLOW    1024
  374.  
  375. /*
  376.  * flag values for stream io waiting procedure (strwaitq)
  377.  */
  378. #define WRITEWAIT    0x1    /* waiting for write event */
  379. #define READWAIT    0x2    /* waiting for read event */
  380. #define NOINTR        0x4    /* error is not to be set for signal */
  381. #define GETWAIT        0x8    /* waiting for getmsg event */
  382.  
  383. /*
  384.  * sleep priorities for stream io
  385.  */
  386. #define    STIPRI    PZERO+3
  387. #define    STOPRI    PZERO+3
  388.  
  389. /*
  390.  * Block allocation parameters
  391.  */
  392. #define NCLASS 9            /* number of block classes */
  393. #define QBSIZE        65        /* min size for block allocation retries */
  394. #define MAXBSIZE    4096        /* max block size */
  395. #define MAXIOCBSZ    1024        /* max ioctl data block size */
  396.  
  397. /*
  398.  * Copy modes for tty and I_STR ioctls
  399.  */
  400. #define    U_TO_K     01            /* User to Kernel */
  401. #define    K_TO_K  02            /* Kernel to Kernel */
  402.  
  403. /*
  404.  * Values for stream flag in open to indicate module open, clone open;
  405.  * return value for failure.
  406.  */
  407. #define MODOPEN     0x1        /* open as a module */
  408. #define CLONEOPEN    0x2        /* open for clone, pick own minor device */
  409. #define OPENFAIL    -1        /* returned for open failure */
  410.  
  411. /*
  412.  * Priority definitions for block allocation.
  413.  */
  414. #define BPRI_LO        1
  415. #define BPRI_MED    2
  416. #define BPRI_HI        3
  417.  
  418. /*
  419.  * Value for packet size that denotes infinity
  420.  */
  421. #define INFPSZ        -1
  422.  
  423. /*
  424.  * Flags for flushq()
  425.  */
  426. #define FLUSHALL    1    /* flush all messages */
  427. #define FLUSHDATA    0    /* don't flush control messages */
  428.  
  429. /*
  430.  * flag for transparent ioctls
  431.  */
  432. #define TRANSPARENT    (unsigned int)(-1)
  433.  
  434. /*
  435.  * canonical structure definitions
  436.  */
  437.  
  438. #define STRLINK        "lli"
  439. #define STRIOCTL    "iiil"
  440. #define STRPEEK        "iiliill"
  441. #define STRFDINSERT    "iiliillii"
  442. #define STRRECVFD    "lssc8"
  443. #define STRNAME        "c0"
  444. #define STRINT        "i"
  445. #define STRTERMIO    "ssssc12"
  446. #define STRTERMCB    "c6"
  447. #define STRSGTTYB    "c4i"
  448.  
  449. /************************************************************************/
  450. /*    Defintions of Streams macros and function interfaces.        */
  451. /************************************************************************/
  452.  
  453. /*
  454.  * determine block allocation cutoff for given class and priority.
  455.  */
  456. #define bcmax(class, pri) ( (pri) == BPRI_LO ? dballoc[class].dba_lo : \
  457.                ((pri) == BPRI_HI ? nmblock : dballoc[class].dba_med))
  458.  
  459. /*
  460.  *  Queue scheduling macros
  461.  */
  462. #define setqsched()     qrunflag = 1    /* set up queue scheduler */
  463. #define qready()    qrunflag    /* test if queues are ready to run */
  464.  
  465. /*
  466.  * Definition of spl function needed to provide critical region protection
  467.  * for streams drivers and modules.
  468.  */
  469. #if u3b2 | i386
  470. #define splstr() spltty()
  471. #else
  472. #define splstr() spl5()
  473. #endif
  474.  
  475.  
  476. /*
  477.  * canenable - check if queue can be enabled by putq().
  478.  */
  479. #define canenable(q)    !((q)->q_flag & QNOENB)
  480.  
  481. /*
  482.  * Finding related queues
  483.  */
  484. #define    OTHERQ(q)    ((q)->q_flag&QREADR? (q)+1: (q)-1)
  485. #define    WR(q)        (q+1)
  486. #define    RD(q)        (q-1)
  487.  
  488. /*
  489.  * put a message of the next queue of the given queue
  490.  */
  491. #define putnext(q, mp)    ((*q->q_next->q_qinfo->qi_putp)(q->q_next, mp))
  492.  
  493. /*
  494.  * free a queue pair
  495.  */
  496. #define freeq(q)    { (q)->q_flag = WR(q)->q_flag = 0; strst.queue.use--; }
  497.  
  498. /*
  499.  * Test if data block type is one of the data messages (i.e. not a control
  500.  * message).
  501.  */
  502. #define datamsg(type) (type == M_DATA || type == M_PROTO || type == M_PCPROTO)
  503.  
  504. /*
  505.  * extract queue class of message block
  506.  */
  507. #define queclass(bp) (bp->b_datap->db_type & QPCTL)
  508.  
  509. /*
  510.  * Align address on next lower word boundary
  511.  */
  512. #define straln(a)    (caddr_t)((long)(a) & ~(sizeof(int)-1))
  513.  
  514. /*
  515.  * Copy data from one data buffer to another.
  516.  * The addresses must be word aligned - if not, use bcopy!
  517.  */
  518. #ifdef u3b2
  519. /*
  520.  * Use the MOVBLW instruction on the 3b2.  
  521.  */
  522. asm    void
  523. strbcpy(s, d, c)
  524. {
  525. %mem    s,d,c;
  526.     
  527.     MOVW    s,%r0
  528.     MOVW    d,%r1
  529.     MOVW    c,%r2
  530.     ADDW2    &3,%r2
  531.     LRSW3    &2,%r2,%r2
  532.     MOVBLW
  533. }
  534.  
  535. #else
  536. #define    strbcpy(s, d, c)    bcopy(s, d, c)
  537. #endif
  538.  
  539. /*
  540.  * declarations of common routines
  541.  */
  542. extern mblk_t *rmvb();
  543. extern mblk_t *dupmsg();
  544. extern mblk_t *copymsg();
  545. extern mblk_t *allocb();
  546. extern mblk_t *unlinkb();
  547. extern mblk_t *dupb();
  548. extern mblk_t *copyb();
  549. extern mblk_t *getq();
  550. extern int    putq();
  551. extern queue_t *backq();
  552. extern queue_t *allocq();
  553. extern int    qenable();
  554. extern mblk_t *unlinkb();
  555. extern mblk_t *unlinkmsg();
  556. extern int    pullupmsg();
  557. extern int    adjmsg();
  558. extern struct queue *getendq();
  559. extern struct linkblk *findlinks();
  560. extern struct file *getf();
  561. extern struct strevent *sealloc();
  562. extern int   sefree();
  563. extern int noenable();
  564. extern int enabelok();
  565.  
  566. /*
  567.  * shared or externally configured data structures
  568.  */
  569. extern struct stdata streams[];        /* table of streams */
  570. extern queue_t    queue[];        /* table of queues */
  571. extern mblk_t     mblock[];         /* table of msg blk desc */
  572. extern dblk_t     dblock[];         /* table of data blk desc */
  573. extern ushort    rbsize[];        /* map of class to real block size */
  574. extern struct linkblk linkblk[];    /* multiplexor link table */
  575. extern struct strevent strevent[];    /* table of stream event cells */
  576. extern struct strstat strst;        /* Streams statistics structure */
  577. extern queue_t    *qhead;            /* head of runnable queue list */
  578. extern queue_t    *qtail;            /* tail of runnable queue list */
  579. extern int strmsgsz;            /* maximum stream message size */
  580. extern int strctlsz;            /* maximum size of ctl part of message */
  581. extern int nmblock;            /* number of msg blk desc */
  582. extern int nmuxlink;            /* number of multiplexor links */
  583. extern int nstrpush;            /* maxmimum number of pushes allowed */
  584. extern int nstrevent;            /* initial number of stream event cells */
  585. extern int maxsepgcnt;            /* page limit for event cell allocation */
  586. extern int pollwait;            /* poll sleeps on &pollwait */
  587. extern char qrunflag;            /* set if there are queues to run */
  588. extern char queueflag;            /* set iff inside queuerun() */
  589.