17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
51716904brutus * Common Development and Distribution License (the "License").
61716904brutus * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
22ba3594bGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23ba3594bGarrett D'Amore *
24c242f9achunli zhang - Sun Microsystems - Irvine United States * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
257c478bdstevel@tonic-gate * Use is subject to license terms.
26b819ceaGordon Ross *
27b819ceaGordon Ross * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
28fca543cDJ Hoffman * Copyright (c) 2015, Joyent, Inc.  All rights reserved.
297c478bdstevel@tonic-gate */
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
32b4203d7Marcel Telka/*	  All Rights Reserved	*/
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate/*
357c478bdstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
367c478bdstevel@tonic-gate * The Regents of the University of California
377c478bdstevel@tonic-gate * All Rights Reserved
387c478bdstevel@tonic-gate *
397c478bdstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
407c478bdstevel@tonic-gate * software developed by the University of California, Berkeley, and its
417c478bdstevel@tonic-gate * contributors.
427c478bdstevel@tonic-gate */
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate#ifndef _SYS_UIO_H
457c478bdstevel@tonic-gate#define	_SYS_UIO_H
467c478bdstevel@tonic-gate
477c478bdstevel@tonic-gate#include <sys/feature_tests.h>
487c478bdstevel@tonic-gate
497c478bdstevel@tonic-gate#ifdef	__cplusplus
507c478bdstevel@tonic-gateextern "C" {
517c478bdstevel@tonic-gate#endif
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate#include <sys/types.h>
547c478bdstevel@tonic-gate
557c478bdstevel@tonic-gate/*
567c478bdstevel@tonic-gate * I/O parameter information.  A uio structure describes the I/O which
577c478bdstevel@tonic-gate * is to be performed by an operation.  Typically the data movement will
587c478bdstevel@tonic-gate * be performed by a routine such as uiomove(), which updates the uio
597c478bdstevel@tonic-gate * structure to reflect what was done.
607c478bdstevel@tonic-gate */
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate#if	defined(_XPG4_2)
637c478bdstevel@tonic-gatetypedef struct iovec {
647c478bdstevel@tonic-gate	void	*iov_base;
657c478bdstevel@tonic-gate	size_t	iov_len;
667c478bdstevel@tonic-gate} iovec_t;
677c478bdstevel@tonic-gate#else
687c478bdstevel@tonic-gatetypedef struct iovec {
697c478bdstevel@tonic-gate	caddr_t	iov_base;
707c478bdstevel@tonic-gate#if defined(_LP64)
717c478bdstevel@tonic-gate	size_t	iov_len;
727c478bdstevel@tonic-gate#else
737c478bdstevel@tonic-gate	long	iov_len;
747c478bdstevel@tonic-gate#endif
757c478bdstevel@tonic-gate} iovec_t;
767c478bdstevel@tonic-gate#endif	/* defined(_XPG4_2) */
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate#if defined(_SYSCALL32)
797c478bdstevel@tonic-gate
807c478bdstevel@tonic-gate/* Kernel's view of user ILP32 iovec struct */
817c478bdstevel@tonic-gate
827c478bdstevel@tonic-gatetypedef	struct iovec32 {
837c478bdstevel@tonic-gate	caddr32_t	iov_base;
847c478bdstevel@tonic-gate	int32_t		iov_len;
857c478bdstevel@tonic-gate} iovec32_t;
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate#endif	/* _SYSCALL32 */
887c478bdstevel@tonic-gate
897c478bdstevel@tonic-gate#if 	!defined(_XPG4_2) || defined(__EXTENSIONS__)
907c478bdstevel@tonic-gate/*
917c478bdstevel@tonic-gate * Segment flag values.
927c478bdstevel@tonic-gate */
937c478bdstevel@tonic-gatetypedef enum uio_seg { UIO_USERSPACE, UIO_SYSSPACE, UIO_USERISPACE } uio_seg_t;
947c478bdstevel@tonic-gate
957c478bdstevel@tonic-gatetypedef struct uio {
967c478bdstevel@tonic-gate	iovec_t		*uio_iov;	/* pointer to array of iovecs */
977c478bdstevel@tonic-gate	int		uio_iovcnt;	/* number of iovecs */
987c478bdstevel@tonic-gate	lloff_t		_uio_offset;	/* file offset */
997c478bdstevel@tonic-gate	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
1007c478bdstevel@tonic-gate	uint16_t	uio_fmode;	/* file mode flags */
1017c478bdstevel@tonic-gate	uint16_t	uio_extflg;	/* extended flags */
1027c478bdstevel@tonic-gate	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
1037c478bdstevel@tonic-gate	ssize_t		uio_resid;	/* residual count */
1047c478bdstevel@tonic-gate} uio_t;
1057c478bdstevel@tonic-gate
1061716904brutus/*
1071716904brutus * Extended uio_t uioa_t used for asynchronous uio.
1081716904brutus *
1091716904brutus * Note: UIOA_IOV_MAX is defined and used as it is in "fs/vncalls.c"
1101716904brutus *	 as there isn't a formal definition of IOV_MAX for the kernel.
1111716904brutus */
1121716904brutus#define	UIOA_IOV_MAX	16
1131716904brutus
1141716904brutustypedef struct uioa_page_s {		/* locked uio_iov state */
1151716904brutus	int	uioa_pfncnt;		/* count of pfn_t(s) in *uioa_ppp */
1161716904brutus	void	**uioa_ppp;		/* page_t or pfn_t arrary */
1171716904brutus	caddr_t	uioa_base;		/* address base */
1181716904brutus	size_t	uioa_len;		/* span length */
1191716904brutus} uioa_page_t;
1201716904brutus
1211716904brutustypedef struct uioa_s {
1221716904brutus	iovec_t		*uio_iov;	/* pointer to array of iovecs */
1231716904brutus	int		uio_iovcnt;	/* number of iovecs */
1241716904brutus	lloff_t		_uio_offset;	/* file offset */
1251716904brutus	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
1261716904brutus	uint16_t	uio_fmode;	/* file mode flags */
1271716904brutus	uint16_t	uio_extflg;	/* extended flags */
1281716904brutus	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
1291716904brutus	ssize_t		uio_resid;	/* residual count */
1301716904brutus	/*
1311716904brutus	 * uioa extended members.
1321716904brutus	 */
1331716904brutus	uint32_t	uioa_state;	/* state of asynch i/o */
13496e0e3dYu Xiangning<Eric.Yu@Sun.COM>	ssize_t		uioa_mbytes;	/* bytes that have been uioamove()ed */
1351716904brutus	uioa_page_t	*uioa_lcur;	/* pointer into uioa_locked[] */
1361716904brutus	void		**uioa_lppp;	/* pointer into lcur->uioa_ppp[] */
1371716904brutus	void		*uioa_hwst[4];	/* opaque hardware state */
1381716904brutus	uioa_page_t	uioa_locked[UIOA_IOV_MAX]; /* Per iov locked pages */
1391716904brutus} uioa_t;
1401716904brutus
141c242f9achunli zhang - Sun Microsystems - Irvine United States/*
142c242f9achunli zhang - Sun Microsystems - Irvine United States * uio extensions
143c242f9achunli zhang - Sun Microsystems - Irvine United States *
144c242f9achunli zhang - Sun Microsystems - Irvine United States * PSARC 2009/478: Copy Reduction Interfaces
145c242f9achunli zhang - Sun Microsystems - Irvine United States */
146c242f9achunli zhang - Sun Microsystems - Irvine United Statestypedef enum xuio_type {
147c242f9achunli zhang - Sun Microsystems - Irvine United States	UIOTYPE_ASYNCIO,
148c242f9achunli zhang - Sun Microsystems - Irvine United States	UIOTYPE_ZEROCOPY
149c242f9achunli zhang - Sun Microsystems - Irvine United States} xuio_type_t;
150c242f9achunli zhang - Sun Microsystems - Irvine United States
151c242f9achunli zhang - Sun Microsystems - Irvine United Statestypedef struct xuio {
152c242f9achunli zhang - Sun Microsystems - Irvine United States	uio_t xu_uio;		/* Embedded UIO structure */
153c242f9achunli zhang - Sun Microsystems - Irvine United States
154c242f9achunli zhang - Sun Microsystems - Irvine United States	/* Extended uio fields */
155c242f9achunli zhang - Sun Microsystems - Irvine United States	enum xuio_type xu_type;	/* What kind of uio structure? */
156c242f9achunli zhang - Sun Microsystems - Irvine United States	union {
157c242f9achunli zhang - Sun Microsystems - Irvine United States		/* Async I/O Support, intend to replace uioa_t. */
158c242f9achunli zhang - Sun Microsystems - Irvine United States		struct {
159c242f9achunli zhang - Sun Microsystems - Irvine United States			uint32_t xu_a_state;	/* state of async i/o */
160c242f9achunli zhang - Sun Microsystems - Irvine United States			/* bytes that have been uioamove()ed */
161c242f9achunli zhang - Sun Microsystems - Irvine United States			ssize_t xu_a_mbytes;
162c242f9achunli zhang - Sun Microsystems - Irvine United States			uioa_page_t *xu_a_lcur;	/* pointer into uioa_locked[] */
163c242f9achunli zhang - Sun Microsystems - Irvine United States			/* pointer into lcur->uioa_ppp[] */
164c242f9achunli zhang - Sun Microsystems - Irvine United States			void **xu_a_lppp;
165c242f9achunli zhang - Sun Microsystems - Irvine United States			void *xu_a_hwst[4];	/* opaque hardware state */
166c242f9achunli zhang - Sun Microsystems - Irvine United States			/* Per iov locked pages */
167c242f9achunli zhang - Sun Microsystems - Irvine United States			uioa_page_t xu_a_locked[UIOA_IOV_MAX];
168c242f9achunli zhang - Sun Microsystems - Irvine United States		} xu_aio;
169c242f9achunli zhang - Sun Microsystems - Irvine United States
170c242f9achunli zhang - Sun Microsystems - Irvine United States		/*
171c242f9achunli zhang - Sun Microsystems - Irvine United States		 * Copy Reduction Support -- facilate loaning / returning of
172c242f9achunli zhang - Sun Microsystems - Irvine United States		 * filesystem cache buffers.
173c242f9achunli zhang - Sun Microsystems - Irvine United States		 */
174c242f9achunli zhang - Sun Microsystems - Irvine United States		struct {
175c242f9achunli zhang - Sun Microsystems - Irvine United States			int xu_zc_rw;	/* read or write buffer */
176c242f9achunli zhang - Sun Microsystems - Irvine United States			void *xu_zc_priv;	/* fs specific */
177c242f9achunli zhang - Sun Microsystems - Irvine United States		} xu_zc;
178c242f9achunli zhang - Sun Microsystems - Irvine United States	} xu_ext;
179c242f9achunli zhang - Sun Microsystems - Irvine United States} xuio_t;
180c242f9achunli zhang - Sun Microsystems - Irvine United States
181c242f9achunli zhang - Sun Microsystems - Irvine United States#define	XUIO_XUZC_PRIV(xuio)    xuio->xu_ext.xu_zc.xu_zc_priv
182c242f9achunli zhang - Sun Microsystems - Irvine United States#define	XUIO_XUZC_RW(xuio)	xuio->xu_ext.xu_zc.xu_zc_rw
183c242f9achunli zhang - Sun Microsystems - Irvine United States
1841716904brutus#define	UIOA_ALLOC	0x0001		/* allocated but not yet initialized */
1851716904brutus#define	UIOA_INIT	0x0002		/* initialized but not yet enabled */
1861716904brutus#define	UIOA_ENABLED	0x0004		/* enabled, asynch i/o active */
1871716904brutus#define	UIOA_FINI	0x0008		/* finished waiting for uioafini() */
1881716904brutus
1891716904brutus#define	UIOA_CLR	(~0x000F)	/* clear mutually exclusive bits */
1901716904brutus
1911716904brutus#define	UIOA_POLL	0x0010		/* need dcopy_poll() */
1921716904brutus
1937c478bdstevel@tonic-gate#define	uio_loffset	_uio_offset._f
1947c478bdstevel@tonic-gate#if !defined(_LP64)
1957c478bdstevel@tonic-gate#define	uio_offset	_uio_offset._p._l
1967c478bdstevel@tonic-gate#else
1977c478bdstevel@tonic-gate#define	uio_offset	uio_loffset
1987c478bdstevel@tonic-gate#endif
1997c478bdstevel@tonic-gate
2007c478bdstevel@tonic-gate#define	uio_llimit	_uio_limit._f
2017c478bdstevel@tonic-gate#if !defined(_LP64)
2027c478bdstevel@tonic-gate#define	uio_limit	_uio_limit._p._l
2037c478bdstevel@tonic-gate#else
2047c478bdstevel@tonic-gate#define	uio_limit	uio_llimit
2057c478bdstevel@tonic-gate#endif
2067c478bdstevel@tonic-gate
2077c478bdstevel@tonic-gate/*
2087c478bdstevel@tonic-gate * I/O direction.
2097c478bdstevel@tonic-gate */
2107c478bdstevel@tonic-gatetypedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t;
2117c478bdstevel@tonic-gate
2127c478bdstevel@tonic-gate/*
2137c478bdstevel@tonic-gate * uio_extflg: extended flags
2147c478bdstevel@tonic-gate *
2157c478bdstevel@tonic-gate * NOTE: This flag will be used in uiomove to determine if non-temporal
2167c478bdstevel@tonic-gate * access, ie, access bypassing caches, should be used.  Filesystems that
2177c478bdstevel@tonic-gate * don't initialize this field could experience suboptimal performance due to
2187c478bdstevel@tonic-gate * the random data the field contains.
2191716904brutus *
2201716904brutus * NOTE: This flag is also used by uioasync callers to pass an extended
2211716904brutus * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all
2221716904brutus * consumers of a uioa_t require the uio_extflg to be initialized.
2237c478bdstevel@tonic-gate */
2247c478bdstevel@tonic-gate#define	UIO_COPY_DEFAULT	0x0000	/* no special options to copy */
2257c478bdstevel@tonic-gate#define	UIO_COPY_CACHED		0x0001	/* copy should not bypass caches */
2267c478bdstevel@tonic-gate
2271716904brutus#define	UIO_ASYNC		0x0002	/* uio_t is really a uioa_t */
228c242f9achunli zhang - Sun Microsystems - Irvine United States#define	UIO_XUIO		0x0004	/* Structure is xuio_t */
2291716904brutus
2301716904brutus/*
2311716904brutus * Global uioasync capability shadow state.
2321716904brutus */
2331716904brutustypedef struct uioasync_s {
2341716904brutus	boolean_t	enabled;	/* Is uioasync enabled? */
2351716904brutus	size_t		mincnt;		/* Minimum byte count for use of */
2361716904brutus} uioasync_t;
2371716904brutus
2387c478bdstevel@tonic-gate#endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
2397c478bdstevel@tonic-gate
240b819ceaGordon Ross#if defined(_KERNEL) || defined(_FAKE_KERNEL)
2417c478bdstevel@tonic-gate
2427c478bdstevel@tonic-gateint	uiomove(void *, size_t, enum uio_rw, uio_t *);
2436f5f1c6Donghai Qiaovoid	uio_prefaultpages(ssize_t, uio_t *);
2442fdbea2Aleksandr Guzovskiyint	uiocopy(void *, size_t, enum uio_rw, uio_t *, size_t *);
2457c478bdstevel@tonic-gateint	ureadc(int, uio_t *);	/* should be errno_t in future */
2467c478bdstevel@tonic-gateint	uwritec(struct uio *);
2477c478bdstevel@tonic-gatevoid	uioskip(uio_t *, size_t);
2487c478bdstevel@tonic-gateint	uiodup(uio_t *, uio_t *, iovec_t *, int);
2497c478bdstevel@tonic-gate
2501716904brutusint	uioamove(void *, size_t, enum uio_rw, uioa_t *);
2511716904brutusint	uioainit(uio_t *, uioa_t *);
2521716904brutusint	uioafini(uio_t *, uioa_t *);
2531716904brutusextern	uioasync_t uioasync;
2541716904brutus
2557c478bdstevel@tonic-gate#else	/* defined(_KERNEL) */
2567c478bdstevel@tonic-gate
2577c478bdstevel@tonic-gateextern ssize_t readv(int, const struct iovec *, int);
2587c478bdstevel@tonic-gateextern ssize_t writev(int, const struct iovec *, int);
2597c478bdstevel@tonic-gate
260fca543cDJ Hoffman/*
261fca543cDJ Hoffman * When in the large file compilation environment,
262fca543cDJ Hoffman * map preadv/pwritev to their 64 bit offset versions
263fca543cDJ Hoffman */
264fca543cDJ Hoffman#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
265fca543cDJ Hoffman#ifdef __PRAGMA_REDEFINE_EXTNAME
266fca543cDJ Hoffman#pragma	redefine_extname	preadv	preadv64
267fca543cDJ Hoffman#pragma	redefine_extname	pwritev	pwritev64
268fca543cDJ Hoffman#else /* __PRAGMA_REDEFINE_EXTNAME */
269fca543cDJ Hoffman#define	preadv	preadv64
270fca543cDJ Hoffman#define	pwritev	pwritev64
271fca543cDJ Hoffman#endif /* __PRAGMA_REDEFINE_EXTNAME */
272fca543cDJ Hoffman#endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
273fca543cDJ Hoffman
274fca543cDJ Hoffman/* In the LP64 compilation environment, the APIs are already large file */
275fca543cDJ Hoffman#if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
276fca543cDJ Hoffman#ifdef  __PRAGMA_REDEFINE_EXTNAME
277fca543cDJ Hoffman#pragma	redefine_extname	preadv64	preadv
278fca543cDJ Hoffman#pragma	redefine_extname	pwritev64	pwritev
279fca543cDJ Hoffman#else   /* __PRAGMA_REDEFINE_EXTNAME */
280fca543cDJ Hoffman#define	preadv64	preadv
281fca543cDJ Hoffman#define	pwritev64	pwritev
282fca543cDJ Hoffman#endif  /* __PRAGMA_REDEFINE_EXTNAME */
283fca543cDJ Hoffman#endif  /* _LP64 && _LARGEFILE64_SOURCE */
284fca543cDJ Hoffman
285fca543cDJ Hoffmanextern ssize_t preadv(int, const struct iovec *, int, off_t);
286fca543cDJ Hoffmanextern ssize_t pwritev(int, const struct iovec *, int, off_t);
287fca543cDJ Hoffman
288fca543cDJ Hoffman/*
289fca543cDJ Hoffman * preadv64 and pwritev64 should be defined when:
290fca543cDJ Hoffman * - Using the transitional compilation environment, and not
291fca543cDJ Hoffman *     the large file compilation environment.
292fca543cDJ Hoffman */
293fca543cDJ Hoffman#if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
294fca543cDJ Hoffman	!defined(__PRAGMA_REDEFINE_EXTNAME))
295fca543cDJ Hoffmanextern ssize_t preadv64(int, const struct iovec *, int, off64_t);
296fca543cDJ Hoffmanextern ssize_t pwritev64(int, const struct iovec *, int, off64_t);
297fca543cDJ Hoffman#endif /* _LARGEFILE64_SOURCE */
298fca543cDJ Hoffman
2997c478bdstevel@tonic-gate#endif	/* defined(_KERNEL) */
3007c478bdstevel@tonic-gate
3017c478bdstevel@tonic-gate#ifdef	__cplusplus
3027c478bdstevel@tonic-gate}
3037c478bdstevel@tonic-gate#endif
3047c478bdstevel@tonic-gate
3057c478bdstevel@tonic-gate#endif	/* _SYS_UIO_H */
306