1/* $NetBSD: pipe.h,v 1.38 2021/01/25 19:21:11 dholland 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#include <sys/selinfo.h>		/* for struct selinfo */
 30#include <sys/time.h>			/* for struct timespec */
 31
 32#include <uvm/uvm_extern.h>
 33
 34/*
 35 * Pipe buffer size, keep moderate in value, pipes take kva space.
 36 */
 37#ifndef PIPE_SIZE
 38#define PIPE_SIZE	16384
 39#endif
 40
 41#ifndef BIG_PIPE_SIZE
 42#define BIG_PIPE_SIZE	(4*PIPE_SIZE)
 43#endif
 44
 45/*
 46 * Maximum size of transfer for direct write transfer. If the amount
 47 * of data in buffer is larger, it would be transferred in chunks of this
 48 * size.
 49 */
 50#ifndef PIPE_DIRECT_CHUNK
 51#define PIPE_DIRECT_CHUNK	(1*1024*1024)
 52#endif
 53
 54/*
 55 * PIPE_MINDIRECT MUST be smaller than PIPE_SIZE and MUST be bigger
 56 * than PIPE_BUF.
 57 */
 58#ifndef PIPE_MINDIRECT
 59#define PIPE_MINDIRECT	8192
 60#endif
 61
 62/*
 63 * Pipe buffer information.
 64 * Separate in, out, cnt are used to simplify calculations.
 65 * Buffered write is active when the buffer.cnt field is set.
 66 */
 67struct pipebuf {
 68	size_t	cnt;		/* number of chars currently in buffer */
 69	u_int	in;		/* in pointer */
 70	u_int	out;		/* out pointer */
 71	size_t	size;		/* size of buffer */
 72	void *	buffer;		/* kva of buffer */
 73};
 74
 75/*
 76 * Bits in pipe_state.
 77 */
 78#define PIPE_ASYNC	0x001	/* Async I/O */
 79#define PIPE_EOF	0x010	/* Pipe is in EOF condition */
 80#define PIPE_SIGNALR	0x020	/* Do selwakeup() on read(2) */
 81#define	PIPE_LOCKFL	0x100	/* Process has exclusive access to
 82				   pointers/data. */
 83/*	unused  	0x200	*/
 84#define	PIPE_RESTART	0x400	/* Return ERESTART to blocked syscalls */
 85
 86/*
 87 * Per-pipe data structure.
 88 * Two of these are linked together to produce bi-directional pipes.
 89 */
 90struct pipe {
 91	kmutex_t *pipe_lock;		/* pipe mutex */
 92	kcondvar_t pipe_rcv;		/* cv for readers */
 93	kcondvar_t pipe_wcv;		/* cv for writers */
 94	kcondvar_t pipe_draincv;	/* cv for close */
 95	kcondvar_t pipe_lkcv;		/* locking */
 96	struct	pipebuf pipe_buffer;	/* data storage */
 97	struct	selinfo pipe_sel;	/* for compat with select */
 98	struct	timespec pipe_atime;	/* time of last access */
 99	struct	timespec pipe_mtime;	/* time of last modify */
100	struct	timespec pipe_btime;	/* time of creation */
101	pid_t	pipe_pgid;		/* process group for sigio */
102	u_int	pipe_waiters;		/* number of waiters pending */
103	struct	pipe *pipe_peer;	/* link with other direction */
104	u_int	pipe_state;		/* pipe status info */
105	int	pipe_busy;		/* busy flag, to handle rundown */
106	vaddr_t	pipe_kmem;		/* preallocated PIPE_SIZE buffer */
107};
108
109/*
110 * KERN_PIPE subtypes
111 */
112#define	KERN_PIPE_MAXKVASZ		1	/* maximum kva size (obsolete) */
113#define	KERN_PIPE_LIMITKVA		2	/* limit kva for laons (obsolete) */
114#define	KERN_PIPE_MAXBIGPIPES		3	/* maximum # of "big" pipes */
115#define	KERN_PIPE_NBIGPIPES		4	/* current number of "big" p. */
116#define	KERN_PIPE_KVASIZE		5	/* current pipe kva size */
117
118#ifdef _KERNEL
119int	sysctl_dopipe(int *, u_int, void *, size_t *, void *, size_t);
120void	pipe_init(void);
121#endif /* _KERNEL */
122
123#endif /* !_SYS_PIPE_H_ */