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