home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 202.img / SCO386N2.TD0 / usr / include / sys / stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-30  |  13.8 KB  |  525 lines

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