xref: /onnv-gate/usr/src/uts/common/sys/uio.h (revision 7660:1f3541e68e06)
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 /*
226707Sbrutus  * Copyright 2008 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 */
129*7660SEric.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 
1366707Sbrutus #define	UIOA_ALLOC	0x0001		/* allocated but not yet initialized */
1376707Sbrutus #define	UIOA_INIT	0x0002		/* initialized but not yet enabled */
1386707Sbrutus #define	UIOA_ENABLED	0x0004		/* enabled, asynch i/o active */
1396707Sbrutus #define	UIOA_FINI	0x0008		/* finished waiting for uioafini() */
1406707Sbrutus 
1416707Sbrutus #define	UIOA_CLR	(~0x000F)	/* clear mutually exclusive bits */
1426707Sbrutus 
1436707Sbrutus #define	UIOA_POLL	0x0010		/* need dcopy_poll() */
1446707Sbrutus 
1450Sstevel@tonic-gate #define	uio_loffset	_uio_offset._f
1460Sstevel@tonic-gate #if !defined(_LP64)
1470Sstevel@tonic-gate #define	uio_offset	_uio_offset._p._l
1480Sstevel@tonic-gate #else
1490Sstevel@tonic-gate #define	uio_offset	uio_loffset
1500Sstevel@tonic-gate #endif
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	uio_llimit	_uio_limit._f
1530Sstevel@tonic-gate #if !defined(_LP64)
1540Sstevel@tonic-gate #define	uio_limit	_uio_limit._p._l
1550Sstevel@tonic-gate #else
1560Sstevel@tonic-gate #define	uio_limit	uio_llimit
1570Sstevel@tonic-gate #endif
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * I/O direction.
1610Sstevel@tonic-gate  */
1620Sstevel@tonic-gate typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate  * uio_extflg: extended flags
1660Sstevel@tonic-gate  *
1670Sstevel@tonic-gate  * NOTE: This flag will be used in uiomove to determine if non-temporal
1680Sstevel@tonic-gate  * access, ie, access bypassing caches, should be used.  Filesystems that
1690Sstevel@tonic-gate  * don't initialize this field could experience suboptimal performance due to
1700Sstevel@tonic-gate  * the random data the field contains.
1716707Sbrutus  *
1726707Sbrutus  * NOTE: This flag is also used by uioasync callers to pass an extended
1736707Sbrutus  * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all
1746707Sbrutus  * consumers of a uioa_t require the uio_extflg to be initialized.
1750Sstevel@tonic-gate  */
1760Sstevel@tonic-gate #define	UIO_COPY_DEFAULT	0x0000	/* no special options to copy */
1770Sstevel@tonic-gate #define	UIO_COPY_CACHED		0x0001	/* copy should not bypass caches */
1780Sstevel@tonic-gate 
1796707Sbrutus #define	UIO_ASYNC		0x0002	/* uio_t is really a uioa_t */
1806707Sbrutus 
1816707Sbrutus /*
1826707Sbrutus  * Global uioasync capability shadow state.
1836707Sbrutus  */
1846707Sbrutus typedef struct uioasync_s {
1856707Sbrutus 	boolean_t	enabled;	/* Is uioasync enabled? */
1866707Sbrutus 	size_t		mincnt;		/* Minimum byte count for use of */
1876707Sbrutus } uioasync_t;
1886707Sbrutus 
1890Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate #if	defined(_KERNEL)
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate int	uiomove(void *, size_t, enum uio_rw, uio_t *);
1940Sstevel@tonic-gate int	ureadc(int, uio_t *);	/* should be errno_t in future */
1950Sstevel@tonic-gate int	uwritec(struct uio *);
1960Sstevel@tonic-gate void	uioskip(uio_t *, size_t);
1970Sstevel@tonic-gate int	uiodup(uio_t *, uio_t *, iovec_t *, int);
1980Sstevel@tonic-gate 
1996707Sbrutus int	uioamove(void *, size_t, enum uio_rw, uioa_t *);
2006707Sbrutus int	uioainit(uio_t *, uioa_t *);
2016707Sbrutus int	uioafini(uio_t *, uioa_t *);
2026707Sbrutus extern	uioasync_t uioasync;
2036707Sbrutus 
2040Sstevel@tonic-gate #else	/* defined(_KERNEL) */
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate #if 	defined(__STDC__)
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate extern ssize_t readv(int, const struct iovec *, int);
2090Sstevel@tonic-gate extern ssize_t writev(int, const struct iovec *, int);
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate #else	/* defined(__STDC__) */
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate extern ssize_t readv();
2140Sstevel@tonic-gate extern ssize_t writev();
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate #endif	/* defined(__STDC__) */
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #ifdef	__cplusplus
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate #endif
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate #endif	/* _SYS_UIO_H */
225