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