Deleted Added
full compact
kern_physio.c (1542) kern_physio.c (1549)
1/*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
1/*
2 * Copyright (c) 1994 John S. Dyson
3 * All rights reserved.
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
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
9 * notice immediately at the beginning of the file, without modification,
10 * 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.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * 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 University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: @(#)kern_physio.c 8.1 (Berkeley) 6/10/93
14 * 3. Absolutely no warranty of function or purpose is made by the author
15 * John S. Dyson.
16 * 4. Modifications may be freely made to this file if the above conditions
17 * are met.
39 */
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/buf.h>
44#include <sys/conf.h>
45#include <sys/proc.h>
18 */
19
20#include <sys/param.h>
21#include <sys/systm.h>
22#include <sys/buf.h>
23#include <sys/conf.h>
24#include <sys/proc.h>
25#include <vm/vm.h>
46
26
47physio(a1, a2, a3, a4, a5, a6)
48 int (*a1)();
49 struct buf *a2;
50 dev_t a3;
51 int a4;
52 u_int (*a5)();
53 struct uio *a6;
27static void physwakeup();
28
29int
30physio(strategy, bp, dev, rw, minp, uio)
31 int (*strategy)();
32 struct buf *bp;
33 dev_t dev;
34 int rw;
35 u_int (*minp)();
36 struct uio *uio;
54{
37{
38 int i;
39 int bp_alloc = (bp == 0);
40 int bufflags = rw?B_READ:0;
41 int error;
42 int spl;
55
43
56 /*
57 * Body deleted.
58 */
59 return (EIO);
44/*
45 * keep the process from being swapped
46 */
47 curproc->p_flag |= P_PHYSIO;
48
49 /* create and build a buffer header for a transfer */
50
51 if (bp_alloc) {
52 bp = (struct buf *)getpbuf();
53 } else {
54 spl = splbio();
55 while (bp->b_flags & B_BUSY) {
56 bp->b_flags |= B_WANTED;
57 tsleep((caddr_t)bp, PRIBIO, "physbw", 0);
58 }
59 bp->b_flags |= B_BUSY;
60 splx(spl);
61 }
62
63 bp->b_proc = curproc;
64 bp->b_dev = dev;
65 error = bp->b_error = 0;
66
67 for(i=0;i<uio->uio_iovcnt;i++) {
68 while( uio->uio_iov[i].iov_len) {
69 vm_offset_t v, lastv, pa;
70 caddr_t adr;
71
72 bp->b_bcount = uio->uio_iov[i].iov_len;
73 bp->b_bufsize = bp->b_bcount;
74 bp->b_flags = B_BUSY | B_PHYS | B_CALL | bufflags;
75 bp->b_iodone = physwakeup;
76 bp->b_data = uio->uio_iov[i].iov_base;
77 bp->b_blkno = btodb(uio->uio_offset);
78
79
80 if (rw && !useracc(bp->b_data, bp->b_bufsize, B_WRITE)) {
81 error = EFAULT;
82 goto doerror;
83 }
84 if (!rw && !useracc(bp->b_data, bp->b_bufsize, B_READ)) {
85 error = EFAULT;
86 goto doerror;
87 }
88
89 vmapbuf(bp);
90
91 /* perform transfer */
92 (*strategy)(bp);
93
94 spl = splbio();
95 while ((bp->b_flags & B_DONE) == 0)
96 tsleep((caddr_t)bp, PRIBIO, "physstr", 0);
97 splx(spl);
98
99 vunmapbuf(bp);
100
101 /*
102 * update the uio data
103 */
104 {
105 int iolen = bp->b_bcount - bp->b_resid;
106 uio->uio_iov[i].iov_len -= iolen;
107 uio->uio_iov[i].iov_base += iolen;
108 uio->uio_resid -= iolen;
109 uio->uio_offset += iolen;
110 }
111
112 /*
113 * check for an error
114 */
115 if( bp->b_flags & B_ERROR) {
116 error = bp->b_error;
117 goto doerror;
118 }
119 }
120 }
121
122
123doerror:
124 if (bp_alloc) {
125 relpbuf(bp);
126 } else {
127 bp->b_flags &= ~(B_BUSY|B_PHYS);
128 if( bp->b_flags & B_WANTED) {
129 bp->b_flags &= ~B_WANTED;
130 wakeup((caddr_t)bp);
131 }
132 }
133/*
134 * allow the process to be swapped
135 */
136 curproc->p_flag &= ~P_PHYSIO;
137
138 return (error);
60}
61
62u_int
139}
140
141u_int
63minphys(a1)
64 struct buf *a1;
142minphys(struct buf *bp)
65{
66
143{
144
67 /*
68 * Body deleted.
69 */
70 return (0);
145 if( bp->b_bcount > MAXBSIZE) {
146 bp->b_bcount = MAXBSIZE;
147 }
148 return bp->b_bcount;
71}
72
149}
150
73/*
74 * Do a read on a device for a user process.
75 */
76rawread(dev, uio)
77 dev_t dev;
78 struct uio *uio;
151int
152rawread(dev_t dev, struct uio *uio)
79{
80 return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
153{
154 return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
81 dev, B_READ, minphys, uio));
155 dev, 1, minphys, uio));
82}
83
156}
157
84/*
85 * Do a write on a device for a user process.
86 */
87rawwrite(dev, uio)
88 dev_t dev;
89 struct uio *uio;
158int
159rawwrite(dev_t dev, struct uio *uio)
90{
91 return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
160{
161 return (physio(cdevsw[major(dev)].d_strategy, (struct buf *)NULL,
92 dev, B_WRITE, minphys, uio));
162 dev, 0, minphys, uio));
93}
163}
164
165static void
166physwakeup(bp)
167 struct buf *bp;
168{
169 wakeup((caddr_t) bp);
170 bp->b_flags &= ~B_CALL;
171}