xref: /openbsd-src/share/man/man9/physio.9 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: physio.9,v 1.3 2001/06/28 22:14:23 millert Exp $
2.\"	$NetBSD: physio.9,v 1.5 1999/03/16 00:40:47 garbled Exp $
3.\"
4.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Paul Kranenburg.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"        This product includes software developed by the NetBSD
21.\"        Foundation, Inc. and its contributors.
22.\" 4. Neither the name of The NetBSD Foundation nor the names of its
23.\"    contributors may be used to endorse or promote products derived
24.\"    from this software without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36.\" POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd June 15, 1996
39.Dt PHYSIO 9
40.Os
41.Sh NAME
42.Nm physio
43.Nd initiate I/O on raw devices
44.Sh SYNOPSIS
45.Ft int
46.Fo "physio"
47.Fa "void (*strategy)(struct buf *)"
48.Fa "struct buf *bp"
49.Fa "dev_t dev"
50.Fa "int flags"
51.Fa "void (*minphys)(struct buf *)"
52.Fa "struct uio *uio"
53.Fc
54.Sh DESCRIPTION
55.Fn physio
56is a helper function typically called from character device read and write
57routines to start I/O on a user process buffer.
58It calls back on the provided
59.Fa strategy
60routine one or more times to complete the transfer described by
61.Fa uio .
62The maximum amount of data to transfer with each call to
63.Fa strategy
64is determined by the
65.Fa minphys
66routine.
67Since
68.Fa uio
69normally describes user space addresses,
70.Fn physio
71needs to lock the appropriate data area into memory before each transaction
72with
73.Fa strategy ( see the
74.Fn uvm_vslock
75and
76.Fn uvm_vsunlock
77functions in
78.Xr uvm 9 ) .
79.Fn physio
80always awaits the completion of the entire requested transfer before
81returning, unless an error condition is detected earlier.
82In all cases, the buffer passed in
83.Fa bp
84is locked (marked as
85.Dq busy )
86for the duration of the entire transfer.
87.Pp
88A break-down of the arguments follows:
89.Bl -tag -width indent
90.It Fa strategy
91The device strategy routine to call for each chunk of data to initiate
92device I/O.
93.It Fa bp
94The buffer to use with the strategy routine.
95The buffer flags will have
96.Dv B_BUSY ,
97.Dv B_PHYS ,
98and
99.Dv B_RAW
100set when passed to the strategy routine.
101If
102.Dv NULL ,
103a buffer is allocated from a system pool.
104.It Fa dev
105The device number identifying the device to interact with.
106.It Fa flags
107Direction of transfer; the only valid settings are
108.Dv B_READ
109or
110.Dv B_WRITE .
111.It Fa minphys
112A device specific routine called to determine the maximum transfer size
113that the device's strategy routine can handle.
114.It Fa uio
115The description of the entire transfer as requested by the user process.
116Currently, the results of passing a
117.Fa uio
118structure with the
119.Sq uio_segflg
120set to anything other than
121.Dv UIO_USERSPACE ,
122are undefined.
123.El
124.Sh RETURN VALUES
125If successful
126.Fn physio
127returns 0.
128.Er EFAULT
129is returned if the address range described by
130.Fa uio
131is not accessible by the requesting process.
132.Fn physio
133will return any error resulting from calls to the device strategy routine,
134by examining the
135.Dv B_ERROR
136buffer flag and the
137.Sq b_error
138field.
139Note that the actual transfer size may be less than requested by
140.Fa uio
141if the device signals an
142.Dq end of file
143condition.
144.Sh SEE ALSO
145.Xr read 2 ,
146.Xr write 2
147