xref: /titanic_52/usr/src/uts/common/sys/uio.h (revision c2785286330b58810071fc24f6ca69f401682dff)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * University Copyright- Copyright (c) 1982, 1986, 1988
31  * The Regents of the University of California
32  * All Rights Reserved
33  *
34  * University Acknowledgment- Portions of this document are derived from
35  * software developed by the University of California, Berkeley, and its
36  * contributors.
37  */
38 
39 #ifndef _SYS_UIO_H
40 #define	_SYS_UIO_H
41 
42 #pragma ident	"%Z%%M%	%I%	%E% SMI"
43 
44 #include <sys/feature_tests.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 #include <sys/types.h>
51 
52 /*
53  * I/O parameter information.  A uio structure describes the I/O which
54  * is to be performed by an operation.  Typically the data movement will
55  * be performed by a routine such as uiomove(), which updates the uio
56  * structure to reflect what was done.
57  */
58 
59 #if	defined(_XPG4_2)
60 typedef struct iovec {
61 	void	*iov_base;
62 	size_t	iov_len;
63 } iovec_t;
64 #else
65 typedef struct iovec {
66 	caddr_t	iov_base;
67 #if defined(_LP64)
68 	size_t	iov_len;
69 #else
70 	long	iov_len;
71 #endif
72 } iovec_t;
73 #endif	/* defined(_XPG4_2) */
74 
75 #if defined(_SYSCALL32)
76 
77 /* Kernel's view of user ILP32 iovec struct */
78 
79 typedef	struct iovec32 {
80 	caddr32_t	iov_base;
81 	int32_t		iov_len;
82 } iovec32_t;
83 
84 #endif	/* _SYSCALL32 */
85 
86 #if 	!defined(_XPG4_2) || defined(__EXTENSIONS__)
87 /*
88  * Segment flag values.
89  */
90 typedef enum uio_seg { UIO_USERSPACE, UIO_SYSSPACE, UIO_USERISPACE } uio_seg_t;
91 
92 typedef struct uio {
93 	iovec_t		*uio_iov;	/* pointer to array of iovecs */
94 	int		uio_iovcnt;	/* number of iovecs */
95 	lloff_t		_uio_offset;	/* file offset */
96 	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
97 	uint16_t	uio_fmode;	/* file mode flags */
98 	uint16_t	uio_extflg;	/* extended flags */
99 	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
100 	ssize_t		uio_resid;	/* residual count */
101 } uio_t;
102 
103 /*
104  * Extended uio_t uioa_t used for asynchronous uio.
105  *
106  * Note: UIOA_IOV_MAX is defined and used as it is in "fs/vncalls.c"
107  *	 as there isn't a formal definition of IOV_MAX for the kernel.
108  */
109 #define	UIOA_IOV_MAX	16
110 
111 typedef struct uioa_page_s {		/* locked uio_iov state */
112 	int	uioa_pfncnt;		/* count of pfn_t(s) in *uioa_ppp */
113 	void	**uioa_ppp;		/* page_t or pfn_t arrary */
114 	caddr_t	uioa_base;		/* address base */
115 	size_t	uioa_len;		/* span length */
116 } uioa_page_t;
117 
118 typedef struct uioa_s {
119 	iovec_t		*uio_iov;	/* pointer to array of iovecs */
120 	int		uio_iovcnt;	/* number of iovecs */
121 	lloff_t		_uio_offset;	/* file offset */
122 	uio_seg_t	uio_segflg;	/* address space (kernel or user) */
123 	uint16_t	uio_fmode;	/* file mode flags */
124 	uint16_t	uio_extflg;	/* extended flags */
125 	lloff_t		_uio_limit;	/* u-limit (maximum byte offset) */
126 	ssize_t		uio_resid;	/* residual count */
127 	/*
128 	 * uioa extended members.
129 	 */
130 	uint32_t	uioa_state;	/* state of asynch i/o */
131 	uioa_page_t	*uioa_lcur;	/* pointer into uioa_locked[] */
132 	void		**uioa_lppp;	/* pointer into lcur->uioa_ppp[] */
133 	void		*uioa_hwst[4];	/* opaque hardware state */
134 	uioa_page_t	uioa_locked[UIOA_IOV_MAX]; /* Per iov locked pages */
135 } uioa_t;
136 
137 #define	UIOA_ALLOC	0x0001		/* allocated but not yet initialized */
138 #define	UIOA_INIT	0x0002		/* initialized but not yet enabled */
139 #define	UIOA_ENABLED	0x0004		/* enabled, asynch i/o active */
140 #define	UIOA_FINI	0x0008		/* finished waiting for uioafini() */
141 
142 #define	UIOA_CLR	(~0x000F)	/* clear mutually exclusive bits */
143 
144 #define	UIOA_POLL	0x0010		/* need dcopy_poll() */
145 
146 #define	uio_loffset	_uio_offset._f
147 #if !defined(_LP64)
148 #define	uio_offset	_uio_offset._p._l
149 #else
150 #define	uio_offset	uio_loffset
151 #endif
152 
153 #define	uio_llimit	_uio_limit._f
154 #if !defined(_LP64)
155 #define	uio_limit	_uio_limit._p._l
156 #else
157 #define	uio_limit	uio_llimit
158 #endif
159 
160 /*
161  * I/O direction.
162  */
163 typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t;
164 
165 /*
166  * uio_extflg: extended flags
167  *
168  * NOTE: This flag will be used in uiomove to determine if non-temporal
169  * access, ie, access bypassing caches, should be used.  Filesystems that
170  * don't initialize this field could experience suboptimal performance due to
171  * the random data the field contains.
172  *
173  * NOTE: This flag is also used by uioasync callers to pass an extended
174  * uio_t (uioa_t), to uioasync enabled consumers. Unlike above all
175  * consumers of a uioa_t require the uio_extflg to be initialized.
176  */
177 #define	UIO_COPY_DEFAULT	0x0000	/* no special options to copy */
178 #define	UIO_COPY_CACHED		0x0001	/* copy should not bypass caches */
179 
180 #define	UIO_ASYNC		0x0002	/* uio_t is really a uioa_t */
181 
182 /*
183  * Global uioasync capability shadow state.
184  */
185 typedef struct uioasync_s {
186 	boolean_t	enabled;	/* Is uioasync enabled? */
187 	size_t		mincnt;		/* Minimum byte count for use of */
188 } uioasync_t;
189 
190 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
191 
192 #if	defined(_KERNEL)
193 
194 int	uiomove(void *, size_t, enum uio_rw, uio_t *);
195 int	ureadc(int, uio_t *);	/* should be errno_t in future */
196 int	uwritec(struct uio *);
197 void	uioskip(uio_t *, size_t);
198 int	uiodup(uio_t *, uio_t *, iovec_t *, int);
199 
200 int	uioamove(void *, size_t, enum uio_rw, uioa_t *);
201 int	uioainit(uio_t *, uioa_t *);
202 int	uioafini(uio_t *, uioa_t *);
203 extern	uioasync_t uioasync;
204 
205 #else	/* defined(_KERNEL) */
206 
207 #if 	defined(__STDC__)
208 
209 extern ssize_t readv(int, const struct iovec *, int);
210 extern ssize_t writev(int, const struct iovec *, int);
211 
212 #else	/* defined(__STDC__) */
213 
214 extern ssize_t readv();
215 extern ssize_t writev();
216 
217 #endif	/* defined(__STDC__) */
218 
219 #endif	/* defined(_KERNEL) */
220 
221 #ifdef	__cplusplus
222 }
223 #endif
224 
225 #endif	/* _SYS_UIO_H */
226