xref: /onnv-gate/usr/src/uts/common/sys/uio.h (revision 11539:10d35fc3d7fd)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56707Sbrutus  * Common Development and Distribution License (the "License").
66707Sbrutus  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11539SChunli.Zhang@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifndef _SYS_UIO_H
400Sstevel@tonic-gate #define	_SYS_UIO_H
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #include <sys/feature_tests.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #ifdef	__cplusplus
450Sstevel@tonic-gate extern "C" {
460Sstevel@tonic-gate #endif
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #include <sys/types.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * I/O parameter information.  A uio structure describes the I/O which
520Sstevel@tonic-gate  * is to be performed by an operation.  Typically the data movement will
530Sstevel@tonic-gate  * be performed by a routine such as uiomove(), which updates the uio
540Sstevel@tonic-gate  * structure to reflect what was done.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #if	defined(_XPG4_2)
580Sstevel@tonic-gate typedef struct iovec {
590Sstevel@tonic-gate 	void	*iov_base;
600Sstevel@tonic-gate 	size_t	iov_len;
610Sstevel@tonic-gate } iovec_t;
620Sstevel@tonic-gate #else
630Sstevel@tonic-gate typedef struct iovec {
640Sstevel@tonic-gate 	caddr_t	iov_base;
650Sstevel@tonic-gate #if defined(_LP64)
660Sstevel@tonic-gate 	size_t	iov_len;
670Sstevel@tonic-gate #else
680Sstevel@tonic-gate 	long	iov_len;
690Sstevel@tonic-gate #endif
700Sstevel@tonic-gate } iovec_t;
710Sstevel@tonic-gate #endif	/* defined(_XPG4_2) */
720Sstevel@tonic-gate 
730Sstevel@tonic-gate #if defined(_SYSCALL32)
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /* Kernel's view of user ILP32 iovec struct */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate typedef	struct iovec32 {
780Sstevel@tonic-gate 	caddr32_t	iov_base;
790Sstevel@tonic-gate 	int32_t		iov_len;
800Sstevel@tonic-gate } iovec32_t;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #endif	/* _SYSCALL32 */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate #if 	!defined(_XPG4_2) || defined(__EXTENSIONS__)
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Segment flag values.
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate typedef enum uio_seg { UIO_USERSPACE, UIO_SYSSPACE, UIO_USERISPACE } uio_seg_t;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate typedef struct uio {
910Sstevel@tonic-gate 	iovec_t		*uio_iov;	/* pointer to array of iovecs */
920Sstevel@tonic-gate 	int		uio_iovcnt;	/* number of iovecs */
930Sstevel@tonic-gate 	lloff_t		_uio_offset;	/* file offset */
940Sstevel@tonic-gate 	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
950Sstevel@tonic-gate 	uint16_t	uio_fmode;	/* file mode flags */
960Sstevel@tonic-gate 	uint16_t	uio_extflg;	/* extended flags */
970Sstevel@tonic-gate 	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
980Sstevel@tonic-gate 	ssize_t		uio_resid;	/* residual count */
990Sstevel@tonic-gate } uio_t;
1000Sstevel@tonic-gate 
1016707Sbrutus /*
1026707Sbrutus  * Extended uio_t uioa_t used for asynchronous uio.
1036707Sbrutus  *
1046707Sbrutus  * Note: UIOA_IOV_MAX is defined and used as it is in "fs/vncalls.c"
1056707Sbrutus  *	 as there isn't a formal definition of IOV_MAX for the kernel.
1066707Sbrutus  */
1076707Sbrutus #define	UIOA_IOV_MAX	16
1086707Sbrutus 
1096707Sbrutus typedef struct uioa_page_s {		/* locked uio_iov state */
1106707Sbrutus 	int	uioa_pfncnt;		/* count of pfn_t(s) in *uioa_ppp */
1116707Sbrutus 	void	**uioa_ppp;		/* page_t or pfn_t arrary */
1126707Sbrutus 	caddr_t	uioa_base;		/* address base */
1136707Sbrutus 	size_t	uioa_len;		/* span length */
1146707Sbrutus } uioa_page_t;
1156707Sbrutus 
1166707Sbrutus typedef struct uioa_s {
1176707Sbrutus 	iovec_t		*uio_iov;	/* pointer to array of iovecs */
1186707Sbrutus 	int		uio_iovcnt;	/* number of iovecs */
1196707Sbrutus 	lloff_t		_uio_offset;	/* file offset */
1206707Sbrutus 	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
1216707Sbrutus 	uint16_t	uio_fmode;	/* file mode flags */
1226707Sbrutus 	uint16_t	uio_extflg;	/* extended flags */
1236707Sbrutus 	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
1246707Sbrutus 	ssize_t		uio_resid;	/* residual count */
1256707Sbrutus 	/*
1266707Sbrutus 	 * uioa extended members.
1276707Sbrutus 	 */
1286707Sbrutus 	uint32_t	uioa_state;	/* state of asynch i/o */
1297660SEric.Yu@Sun.COM 	ssize_t		uioa_mbytes;	/* bytes that have been uioamove()ed */
1306707Sbrutus 	uioa_page_t	*uioa_lcur;	/* pointer into uioa_locked[] */
1316707Sbrutus 	void		**uioa_lppp;	/* pointer into lcur->uioa_ppp[] */
1326707Sbrutus 	void		*uioa_hwst[4];	/* opaque hardware state */
1336707Sbrutus 	uioa_page_t	uioa_locked[UIOA_IOV_MAX]; /* Per iov locked pages */
1346707Sbrutus } uioa_t;
1356707Sbrutus 
136*11539SChunli.Zhang@Sun.COM /*
137*11539SChunli.Zhang@Sun.COM  * uio extensions
138*11539SChunli.Zhang@Sun.COM  *
139*11539SChunli.Zhang@Sun.COM  * PSARC 2009/478: Copy Reduction Interfaces
140*11539SChunli.Zhang@Sun.COM  */
141*11539SChunli.Zhang@Sun.COM typedef enum xuio_type {
142*11539SChunli.Zhang@Sun.COM 	UIOTYPE_ASYNCIO,
143*11539SChunli.Zhang@Sun.COM 	UIOTYPE_ZEROCOPY
144*11539SChunli.Zhang@Sun.COM } xuio_type_t;
145*11539SChunli.Zhang@Sun.COM 
146*11539SChunli.Zhang@Sun.COM typedef struct xuio {
147*11539SChunli.Zhang@Sun.COM 	uio_t xu_uio;		/* Embedded UIO structure */
148*11539SChunli.Zhang@Sun.COM 
149*11539SChunli.Zhang@Sun.COM 	/* Extended uio fields */
150*11539SChunli.Zhang@Sun.COM 	enum xuio_type xu_type;	/* What kind of uio structure? */
151*11539SChunli.Zhang@Sun.COM 	union {
152*11539SChunli.Zhang@Sun.COM 		/* Async I/O Support, intend to replace uioa_t. */
153*11539SChunli.Zhang@Sun.COM 		struct {
154*11539SChunli.Zhang@Sun.COM 			uint32_t xu_a_state;	/* state of async i/o */
155*11539SChunli.Zhang@Sun.COM 			/* bytes that have been uioamove()ed */
156*11539SChunli.Zhang@Sun.COM 			ssize_t xu_a_mbytes;
157*11539SChunli.Zhang@Sun.COM 			uioa_page_t *xu_a_lcur;	/* pointer into uioa_locked[] */
158*11539SChunli.Zhang@Sun.COM 			/* pointer into lcur->uioa_ppp[] */
159*11539SChunli.Zhang@Sun.COM 			void **xu_a_lppp;
160*11539SChunli.Zhang@Sun.COM 			void *xu_a_hwst[4];	/* opaque hardware state */
161*11539SChunli.Zhang@Sun.COM 			/* Per iov locked pages */
162*11539SChunli.Zhang@Sun.COM 			uioa_page_t xu_a_locked[UIOA_IOV_MAX];
163*11539SChunli.Zhang@Sun.COM 		} xu_aio;
164*11539SChunli.Zhang@Sun.COM 
165*11539SChunli.Zhang@Sun.COM 		/*
166*11539SChunli.Zhang@Sun.COM 		 * Copy Reduction Support -- facilate loaning / returning of
167*11539SChunli.Zhang@Sun.COM 		 * filesystem cache buffers.
168*11539SChunli.Zhang@Sun.COM 		 */
169*11539SChunli.Zhang@Sun.COM 		struct {
170*11539SChunli.Zhang@Sun.COM 			int xu_zc_rw;	/* read or write buffer */
171*11539SChunli.Zhang@Sun.COM 			void *xu_zc_priv;	/* fs specific */
172*11539SChunli.Zhang@Sun.COM 		} xu_zc;
173*11539SChunli.Zhang@Sun.COM 	} xu_ext;
174*11539SChunli.Zhang@Sun.COM } xuio_t;
175*11539SChunli.Zhang@Sun.COM 
176*11539SChunli.Zhang@Sun.COM #define	XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
177*11539SChunli.Zhang@Sun.COM #define	XUIO_XUZC_RW(xuio)	xuio->xu_ext.xu_zc.xu_zc_rw
178*11539SChunli.Zhang@Sun.COM 
1796707Sbrutus #define	UIOA_ALLOC	0x0001		/* allocated but not yet initialized */
1806707Sbrutus #define	UIOA_INIT	0x0002		/* initialized but not yet enabled */
1816707Sbrutus #define	UIOA_ENABLED	0x0004		/* enabled, asynch i/o active */
1826707Sbrutus #define	UIOA_FINI	0x0008		/* finished waiting for uioafini() */
1836707Sbrutus 
1846707Sbrutus #define	UIOA_CLR	(~0x000F)	/* clear mutually exclusive bits */
1856707Sbrutus 
1866707Sbrutus #define	UIOA_POLL	0x0010		/* need dcopy_poll() */
1876707Sbrutus 
1880Sstevel@tonic-gate #define	uio_loffset	_uio_offset._f
1890Sstevel@tonic-gate #if !defined(_LP64)
1900Sstevel@tonic-gate #define	uio_offset	_uio_offset._p._l
1910Sstevel@tonic-gate #else
1920Sstevel@tonic-gate #define	uio_offset	uio_loffset
1930Sstevel@tonic-gate #endif
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	uio_llimit	_uio_limit._f
1960Sstevel@tonic-gate #if !defined(_LP64)
1970Sstevel@tonic-gate #define	uio_limit	_uio_limit._p._l
1980Sstevel@tonic-gate #else
1990Sstevel@tonic-gate #define	uio_limit	uio_llimit
2000Sstevel@tonic-gate #endif
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate  * I/O direction.
2040Sstevel@tonic-gate  */
2050Sstevel@tonic-gate typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t;
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate /*
2080Sstevel@tonic-gate  * uio_extflg: extended flags
2090Sstevel@tonic-gate  *
2100Sstevel@tonic-gate  * NOTE: This flag will be used in uiomove to determine if non-temporal
2110Sstevel@tonic-gate  * access, ie, access bypassing caches, should be used.  Filesystems that
2120Sstevel@tonic-gate  * don't initialize this field could experience suboptimal performance due to
2130Sstevel@tonic-gate  * the random data the field contains.
2146707Sbrutus  *
2156707Sbrutus  * NOTE: This flag is also used by uioasync callers to pass an extended
2166707Sbrutus  * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all
2176707Sbrutus  * consumers of a uioa_t require the uio_extflg to be initialized.
2180Sstevel@tonic-gate  */
2190Sstevel@tonic-gate #define	UIO_COPY_DEFAULT	0x0000	/* no special options to copy */
2200Sstevel@tonic-gate #define	UIO_COPY_CACHED		0x0001	/* copy should not bypass caches */
2210Sstevel@tonic-gate 
2226707Sbrutus #define	UIO_ASYNC		0x0002	/* uio_t is really a uioa_t */
223*11539SChunli.Zhang@Sun.COM #define	UIO_XUIO		0x0004	/* Structure is xuio_t */
2246707Sbrutus 
2256707Sbrutus /*
2266707Sbrutus  * Global uioasync capability shadow state.
2276707Sbrutus  */
2286707Sbrutus typedef struct uioasync_s {
2296707Sbrutus 	boolean_t	enabled;	/* Is uioasync enabled? */
2306707Sbrutus 	size_t		mincnt;		/* Minimum byte count for use of */
2316707Sbrutus } uioasync_t;
2326707Sbrutus 
2330Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate #if	defined(_KERNEL)
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate int	uiomove(void *, size_t, enum uio_rw, uio_t *);
2388059SDonghai.Qiao@Sun.COM void	uio_prefaultpages(ssize_t, uio_t *);
2399412SAleksandr.Guzovskiy@Sun.COM int	uiocopy(void *, size_t, enum uio_rw, uio_t *, size_t *);
2400Sstevel@tonic-gate int	ureadc(int, uio_t *);	/* should be errno_t in future */
2410Sstevel@tonic-gate int	uwritec(struct uio *);
2420Sstevel@tonic-gate void	uioskip(uio_t *, size_t);
2430Sstevel@tonic-gate int	uiodup(uio_t *, uio_t *, iovec_t *, int);
2440Sstevel@tonic-gate 
2456707Sbrutus int	uioamove(void *, size_t, enum uio_rw, uioa_t *);
2466707Sbrutus int	uioainit(uio_t *, uioa_t *);
2476707Sbrutus int	uioafini(uio_t *, uioa_t *);
2486707Sbrutus extern	uioasync_t uioasync;
2496707Sbrutus 
2500Sstevel@tonic-gate #else	/* defined(_KERNEL) */
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate #if 	defined(__STDC__)
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate extern ssize_t readv(int, const struct iovec *, int);
2550Sstevel@tonic-gate extern ssize_t writev(int, const struct iovec *, int);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate #else	/* defined(__STDC__) */
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate extern ssize_t readv();
2600Sstevel@tonic-gate extern ssize_t writev();
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate #endif	/* defined(__STDC__) */
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate #ifdef	__cplusplus
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate #endif
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate #endif	/* _SYS_UIO_H */
271