1 /* $NetBSD: pipe.h,v 1.11 2002/03/13 20:51:37 jdolecek Exp $ */ 2 3 /* 4 * Copyright (c) 1996 John S. Dyson 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice immediately at the beginning of the file, without modification, 12 * this list of conditions, and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Absolutely no warranty of function or purpose is made by the author 17 * John S. Dyson. 18 * 4. This work was done expressly for inclusion into FreeBSD. Other use 19 * is allowed if this notation is included. 20 * 5. Modifications may be freely made to this file if the above conditions 21 * are met. 22 * 23 * $FreeBSD: src/sys/sys/pipe.h,v 1.18 2002/02/27 07:35:59 alfred Exp $ 24 */ 25 26 #ifndef _SYS_PIPE_H_ 27 #define _SYS_PIPE_H_ 28 29 #ifndef _KERNEL 30 #ifdef __FreeBSD__ 31 #include <sys/time.h> /* for struct timeval */ 32 #include <sys/selinfo.h> /* for struct selinfo */ 33 #include <vm/vm.h> /* for vm_page_t */ 34 #include <machine/param.h> /* for PAGE_SIZE */ 35 #endif 36 #ifdef __NetBSD__ 37 #include <sys/select.h> /* for struct selinfo */ 38 #endif 39 #endif 40 41 /* 42 * Pipe buffer size, keep moderate in value, pipes take kva space. 43 */ 44 #ifndef PIPE_SIZE 45 #define PIPE_SIZE 16384 46 #endif 47 48 #ifndef BIG_PIPE_SIZE 49 #define BIG_PIPE_SIZE (4*PIPE_SIZE) 50 #endif 51 52 /* 53 * Maximum size of kva for direct write transfer. If the amount 54 * of data in buffer is larger, it would be transferred in chunks of this 55 * size. This kva memory is freed after use if amount of pipe kva memory 56 * is bigger than limitpipekva. 57 */ 58 #ifndef PIPE_DIRECT_CHUNK 59 #define PIPE_DIRECT_CHUNK (1*1024*1024) 60 #endif 61 62 /* 63 * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger 64 * than PIPE_BUF. 65 */ 66 #ifndef PIPE_MINDIRECT 67 #define PIPE_MINDIRECT 8192 68 #endif 69 70 /* 71 * Pipe buffer information. 72 * Separate in, out, cnt are used to simplify calculations. 73 * Buffered write is active when the buffer.cnt field is set. 74 */ 75 struct pipebuf { 76 size_t cnt; /* number of chars currently in buffer */ 77 u_int in; /* in pointer */ 78 u_int out; /* out pointer */ 79 size_t size; /* size of buffer */ 80 caddr_t buffer; /* kva of buffer */ 81 #ifdef __FreeBSD__ 82 struct vm_object *object; /* VM object containing buffer */ 83 #endif 84 }; 85 86 /* 87 * Information to support direct transfers between processes for pipes. 88 */ 89 #if defined(__FreeBSD__) 90 #define PIPENPAGES (BIG_PIPE_SIZE / PAGE_SIZE + 1) 91 struct pipemapping { 92 vm_offset_t kva; /* kernel virtual address */ 93 vm_size_t cnt; /* number of chars in buffer */ 94 vm_size_t pos; /* current position of transfer */ 95 int npages; /* number of pages */ 96 vm_page_t ms[PIPENPAGES]; /* pages in source process */ 97 }; 98 #elif defined(__NetBSD__) 99 struct pipemapping { 100 vaddr_t kva; /* kernel virtual address */ 101 vsize_t cnt; /* number of chars in buffer */ 102 voff_t pos; /* current position within page */ 103 int npages; /* how many pages allocated */ 104 struct vm_page **pgs; /* pointers to the pages */ 105 }; 106 #endif 107 108 /* 109 * Bits in pipe_state. 110 */ 111 #define PIPE_ASYNC 0x004 /* Async? I/O. */ 112 #define PIPE_WANTR 0x008 /* Reader wants some characters. */ 113 #define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ 114 #define PIPE_WANTCLOSE 0x020 /* Pipe is wanted to be run-down. */ 115 #define PIPE_SEL 0x040 /* Pipe has a select active. */ 116 #define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ 117 #define PIPE_LOCKFL 0x100 /* Process has exclusive access to pointers/data. */ 118 #define PIPE_LWANT 0x200 /* Process wants exclusive access to pointers/data. */ 119 #define PIPE_DIRECTW 0x400 /* Pipe direct write active. */ 120 #define PIPE_SIGNALR 0x800 /* Do selwakeup() on read(2) */ 121 122 /* 123 * Per-pipe data structure. 124 * Two of these are linked together to produce bi-directional pipes. 125 */ 126 struct pipe { 127 struct pipebuf pipe_buffer; /* data storage */ 128 struct pipemapping pipe_map; /* pipe mapping for direct I/O */ 129 struct selinfo pipe_sel; /* for compat with select */ 130 #ifdef __FreeBSD__ 131 struct timespec pipe_atime; /* time of last access */ 132 struct timespec pipe_mtime; /* time of last modify */ 133 struct timespec pipe_ctime; /* time of status change */ 134 struct sigio *pipe_sigio; /* information for async I/O */ 135 struct mtx *pipe_mtxp; /* shared mutex between both pipes */ 136 #elif defined(__NetBSD__) 137 struct timeval pipe_atime; /* time of last access */ 138 struct timeval pipe_mtime; /* time of last modify */ 139 struct timeval pipe_ctime; /* time of status change */ 140 gid_t pipe_pgid; /* process group for sigio */ 141 struct lock pipe_lock; /* pipe lock */ 142 #endif 143 struct pipe *pipe_peer; /* link with other direction */ 144 u_int pipe_state; /* pipe status info */ 145 int pipe_busy; /* busy flag, mostly to handle rundown sanely */ 146 }; 147 148 #ifdef __FreeBSD__ 149 #define PIPE_MTX(pipe) (pipe)->pipe_mtxp 150 #define PIPE_LOCK(pipe) mtx_lock(PIPE_MTX(pipe)) 151 #define PIPE_UNLOCK(pipe) mtx_unlock(PIPE_MTX(pipe)) 152 #define PIPE_LOCK_ASSERT(pipe, type) mtx_assert(PIPE_MTX(pipe), (type)) 153 #endif /* FreeBSD */ 154 155 #ifdef __NetBSD__ 156 /* 157 * KERN_PIPE subtypes 158 */ 159 #define KERN_PIPE_MAXKVASZ 1 /* maximum kva size */ 160 #define KERN_PIPE_LIMITKVA 2 /* */ 161 #define KERN_PIPE_MAXBIGPIPES 3 /* maximum # of "big" pipes */ 162 #define KERN_PIPE_NBIGPIPES 4 /* current number of "big" p. */ 163 #define KERN_PIPE_KVASIZE 5 /* current pipe kva size */ 164 #define KERN_PIPE_MAXID 6 165 166 #define CTL_PIPE_NAMES { \ 167 { 0, 0 }, \ 168 { "maxkvasz", CTLTYPE_INT }, \ 169 { "maxloankvasz", CTLTYPE_INT }, \ 170 { "maxbigpipes", CTLTYPE_INT }, \ 171 { "nbigpipes", CTLTYPE_INT }, \ 172 { "kvasize", CTLTYPE_INT }, \ 173 } 174 175 #ifdef _KERNEL 176 void pipe_init __P((void)); 177 int sysctl_dopipe __P((int *, u_int, void *, size_t *, void *, size_t)); 178 179 /* XXXSMP use spinlock ? clear for now */ 180 #define PIPE_MTX(pipe) NULL 181 #define PIPE_LOCK(pipe) 182 #define PIPE_UNLOCK(pipe) 183 #define PIPE_LOCK_ASSERT(pipe, type) 184 185 #endif /* _KERNEL */ 186 187 #endif /* NetBSD */ 188 189 #endif /* !_SYS_PIPE_H_ */ 190