1*6c8f7fc3SBen Gras /* $NetBSD: pipe.h,v 1.32 2009/12/20 09:36:06 dsl Exp $ */ 2*6c8f7fc3SBen Gras 3*6c8f7fc3SBen Gras /* 4*6c8f7fc3SBen Gras * Copyright (c) 1996 John S. Dyson 5*6c8f7fc3SBen Gras * All rights reserved. 6*6c8f7fc3SBen Gras * 7*6c8f7fc3SBen Gras * Redistribution and use in source and binary forms, with or without 8*6c8f7fc3SBen Gras * modification, are permitted provided that the following conditions 9*6c8f7fc3SBen Gras * are met: 10*6c8f7fc3SBen Gras * 1. Redistributions of source code must retain the above copyright 11*6c8f7fc3SBen Gras * notice immediately at the beginning of the file, without modification, 12*6c8f7fc3SBen Gras * this list of conditions, and the following disclaimer. 13*6c8f7fc3SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 14*6c8f7fc3SBen Gras * notice, this list of conditions and the following disclaimer in the 15*6c8f7fc3SBen Gras * documentation and/or other materials provided with the distribution. 16*6c8f7fc3SBen Gras * 3. Absolutely no warranty of function or purpose is made by the author 17*6c8f7fc3SBen Gras * John S. Dyson. 18*6c8f7fc3SBen Gras * 4. This work was done expressly for inclusion into FreeBSD. Other use 19*6c8f7fc3SBen Gras * is allowed if this notation is included. 20*6c8f7fc3SBen Gras * 5. Modifications may be freely made to this file if the above conditions 21*6c8f7fc3SBen Gras * are met. 22*6c8f7fc3SBen Gras * 23*6c8f7fc3SBen Gras * $FreeBSD: src/sys/sys/pipe.h,v 1.18 2002/02/27 07:35:59 alfred Exp $ 24*6c8f7fc3SBen Gras */ 25*6c8f7fc3SBen Gras 26*6c8f7fc3SBen Gras #ifndef _SYS_PIPE_H_ 27*6c8f7fc3SBen Gras #define _SYS_PIPE_H_ 28*6c8f7fc3SBen Gras 29*6c8f7fc3SBen Gras #include <sys/selinfo.h> /* for struct selinfo */ 30*6c8f7fc3SBen Gras 31*6c8f7fc3SBen Gras #include <uvm/uvm_extern.h> 32*6c8f7fc3SBen Gras 33*6c8f7fc3SBen Gras /* 34*6c8f7fc3SBen Gras * Pipe buffer size, keep moderate in value, pipes take kva space. 35*6c8f7fc3SBen Gras */ 36*6c8f7fc3SBen Gras #ifndef PIPE_SIZE 37*6c8f7fc3SBen Gras #define PIPE_SIZE 16384 38*6c8f7fc3SBen Gras #endif 39*6c8f7fc3SBen Gras 40*6c8f7fc3SBen Gras #ifndef BIG_PIPE_SIZE 41*6c8f7fc3SBen Gras #define BIG_PIPE_SIZE (4*PIPE_SIZE) 42*6c8f7fc3SBen Gras #endif 43*6c8f7fc3SBen Gras 44*6c8f7fc3SBen Gras /* 45*6c8f7fc3SBen Gras * Maximum size of kva for direct write transfer. If the amount 46*6c8f7fc3SBen Gras * of data in buffer is larger, it would be transferred in chunks of this 47*6c8f7fc3SBen Gras * size. This kva memory is freed after use if amount of pipe kva memory 48*6c8f7fc3SBen Gras * is bigger than limitpipekva. 49*6c8f7fc3SBen Gras */ 50*6c8f7fc3SBen Gras #ifndef PIPE_DIRECT_CHUNK 51*6c8f7fc3SBen Gras #define PIPE_DIRECT_CHUNK (1*1024*1024) 52*6c8f7fc3SBen Gras #endif 53*6c8f7fc3SBen Gras 54*6c8f7fc3SBen Gras /* 55*6c8f7fc3SBen Gras * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger 56*6c8f7fc3SBen Gras * than PIPE_BUF. 57*6c8f7fc3SBen Gras */ 58*6c8f7fc3SBen Gras #ifndef PIPE_MINDIRECT 59*6c8f7fc3SBen Gras #define PIPE_MINDIRECT 8192 60*6c8f7fc3SBen Gras #endif 61*6c8f7fc3SBen Gras 62*6c8f7fc3SBen Gras /* 63*6c8f7fc3SBen Gras * Pipe buffer information. 64*6c8f7fc3SBen Gras * Separate in, out, cnt are used to simplify calculations. 65*6c8f7fc3SBen Gras * Buffered write is active when the buffer.cnt field is set. 66*6c8f7fc3SBen Gras */ 67*6c8f7fc3SBen Gras struct pipebuf { 68*6c8f7fc3SBen Gras size_t cnt; /* number of chars currently in buffer */ 69*6c8f7fc3SBen Gras u_int in; /* in pointer */ 70*6c8f7fc3SBen Gras u_int out; /* out pointer */ 71*6c8f7fc3SBen Gras size_t size; /* size of buffer */ 72*6c8f7fc3SBen Gras void * buffer; /* kva of buffer */ 73*6c8f7fc3SBen Gras }; 74*6c8f7fc3SBen Gras 75*6c8f7fc3SBen Gras /* 76*6c8f7fc3SBen Gras * Information to support direct transfers between processes for pipes. 77*6c8f7fc3SBen Gras */ 78*6c8f7fc3SBen Gras struct pipemapping { 79*6c8f7fc3SBen Gras vaddr_t kva; /* kernel virtual address */ 80*6c8f7fc3SBen Gras vsize_t cnt; /* number of chars in buffer */ 81*6c8f7fc3SBen Gras voff_t pos; /* current position within page */ 82*6c8f7fc3SBen Gras int npages; /* how many pages allocated */ 83*6c8f7fc3SBen Gras struct vm_page **pgs; /* pointers to the pages */ 84*6c8f7fc3SBen Gras u_int egen; /* emap generation number */ 85*6c8f7fc3SBen Gras }; 86*6c8f7fc3SBen Gras 87*6c8f7fc3SBen Gras /* 88*6c8f7fc3SBen Gras * Bits in pipe_state. 89*6c8f7fc3SBen Gras */ 90*6c8f7fc3SBen Gras #define PIPE_ASYNC 0x001 /* Async I/O */ 91*6c8f7fc3SBen Gras #define PIPE_EOF 0x010 /* Pipe is in EOF condition */ 92*6c8f7fc3SBen Gras #define PIPE_SIGNALR 0x020 /* Do selwakeup() on read(2) */ 93*6c8f7fc3SBen Gras #define PIPE_DIRECTW 0x040 /* Pipe in direct write mode setup */ 94*6c8f7fc3SBen Gras #define PIPE_DIRECTR 0x080 /* Pipe direct read request (setup complete) */ 95*6c8f7fc3SBen Gras #define PIPE_LOCKFL 0x100 /* Process has exclusive access to 96*6c8f7fc3SBen Gras pointers/data. */ 97*6c8f7fc3SBen Gras #define PIPE_LWANT 0x200 /* Process wants exclusive access to 98*6c8f7fc3SBen Gras pointers/data. */ 99*6c8f7fc3SBen Gras #define PIPE_RESTART 0x400 /* Return ERESTART to blocked syscalls */ 100*6c8f7fc3SBen Gras 101*6c8f7fc3SBen Gras /* 102*6c8f7fc3SBen Gras * Per-pipe data structure. 103*6c8f7fc3SBen Gras * Two of these are linked together to produce bi-directional pipes. 104*6c8f7fc3SBen Gras */ 105*6c8f7fc3SBen Gras struct pipe { 106*6c8f7fc3SBen Gras kmutex_t *pipe_lock; /* pipe mutex */ 107*6c8f7fc3SBen Gras kcondvar_t pipe_rcv; /* cv for readers */ 108*6c8f7fc3SBen Gras kcondvar_t pipe_wcv; /* cv for writers */ 109*6c8f7fc3SBen Gras kcondvar_t pipe_draincv; /* cv for close */ 110*6c8f7fc3SBen Gras kcondvar_t pipe_lkcv; /* locking */ 111*6c8f7fc3SBen Gras struct pipebuf pipe_buffer; /* data storage */ 112*6c8f7fc3SBen Gras struct pipemapping pipe_map; /* pipe mapping for direct I/O */ 113*6c8f7fc3SBen Gras struct selinfo pipe_sel; /* for compat with select */ 114*6c8f7fc3SBen Gras struct timespec pipe_atime; /* time of last access */ 115*6c8f7fc3SBen Gras struct timespec pipe_mtime; /* time of last modify */ 116*6c8f7fc3SBen Gras struct timespec pipe_btime; /* time of creation */ 117*6c8f7fc3SBen Gras pid_t pipe_pgid; /* process group for sigio */ 118*6c8f7fc3SBen Gras struct pipe *pipe_peer; /* link with other direction */ 119*6c8f7fc3SBen Gras u_int pipe_state; /* pipe status info */ 120*6c8f7fc3SBen Gras int pipe_busy; /* busy flag, to handle rundown */ 121*6c8f7fc3SBen Gras vaddr_t pipe_kmem; /* preallocated PIPE_SIZE buffer */ 122*6c8f7fc3SBen Gras }; 123*6c8f7fc3SBen Gras 124*6c8f7fc3SBen Gras /* 125*6c8f7fc3SBen Gras * KERN_PIPE subtypes 126*6c8f7fc3SBen Gras */ 127*6c8f7fc3SBen Gras #define KERN_PIPE_MAXKVASZ 1 /* maximum kva size */ 128*6c8f7fc3SBen Gras #define KERN_PIPE_LIMITKVA 2 /* */ 129*6c8f7fc3SBen Gras #define KERN_PIPE_MAXBIGPIPES 3 /* maximum # of "big" pipes */ 130*6c8f7fc3SBen Gras #define KERN_PIPE_NBIGPIPES 4 /* current number of "big" p. */ 131*6c8f7fc3SBen Gras #define KERN_PIPE_KVASIZE 5 /* current pipe kva size */ 132*6c8f7fc3SBen Gras #define KERN_PIPE_MAXID 6 133*6c8f7fc3SBen Gras 134*6c8f7fc3SBen Gras #define CTL_PIPE_NAMES { \ 135*6c8f7fc3SBen Gras { 0, 0 }, \ 136*6c8f7fc3SBen Gras { "maxkvasz", CTLTYPE_INT }, \ 137*6c8f7fc3SBen Gras { "maxloankvasz", CTLTYPE_INT }, \ 138*6c8f7fc3SBen Gras { "maxbigpipes", CTLTYPE_INT }, \ 139*6c8f7fc3SBen Gras { "nbigpipes", CTLTYPE_INT }, \ 140*6c8f7fc3SBen Gras { "kvasize", CTLTYPE_INT }, \ 141*6c8f7fc3SBen Gras } 142*6c8f7fc3SBen Gras 143*6c8f7fc3SBen Gras #ifdef _KERNEL 144*6c8f7fc3SBen Gras int sysctl_dopipe(int *, u_int, void *, size_t *, void *, size_t); 145*6c8f7fc3SBen Gras void pipe_init(void); 146*6c8f7fc3SBen Gras #endif /* _KERNEL */ 147*6c8f7fc3SBen Gras 148*6c8f7fc3SBen Gras #endif /* !_SYS_PIPE_H_ */ 149