| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ld_thunkbus.c,v 1.21 2011/12/13 13:32:15 jmcneill Exp $ */ | | 1 | /* $NetBSD: ld_thunkbus.c,v 1.22 2011/12/13 15:50:17 reinoud Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.21 2011/12/13 13:32:15 jmcneill Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: ld_thunkbus.c,v 1.22 2011/12/13 15:50:17 reinoud Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/proc.h> | | 33 | #include <sys/proc.h> |
34 | #include <sys/systm.h> | | 34 | #include <sys/systm.h> |
35 | #include <sys/device.h> | | 35 | #include <sys/device.h> |
36 | #include <sys/buf.h> | | 36 | #include <sys/buf.h> |
37 | #include <sys/disk.h> | | 37 | #include <sys/disk.h> |
38 | #include <sys/kmem.h> | | 38 | #include <sys/kmem.h> |
39 | | | 39 | |
40 | #include <dev/ldvar.h> | | 40 | #include <dev/ldvar.h> |
41 | | | 41 | |
42 | #include <machine/mainbus.h> | | 42 | #include <machine/mainbus.h> |
43 | #include <machine/thunk.h> | | 43 | #include <machine/thunk.h> |
| @@ -55,28 +55,26 @@ static void ld_thunkbus_complete(void *a | | | @@ -55,28 +55,26 @@ static void ld_thunkbus_complete(void *a |
55 | struct ld_thunkbus_softc; | | 55 | struct ld_thunkbus_softc; |
56 | | | 56 | |
57 | struct ld_thunkbus_transfer { | | 57 | struct ld_thunkbus_transfer { |
58 | struct ld_thunkbus_softc *tt_sc; | | 58 | struct ld_thunkbus_softc *tt_sc; |
59 | struct buf *tt_bp; | | 59 | struct buf *tt_bp; |
60 | }; | | 60 | }; |
61 | | | 61 | |
62 | struct ld_thunkbus_softc { | | 62 | struct ld_thunkbus_softc { |
63 | struct ld_softc sc_ld; | | 63 | struct ld_softc sc_ld; |
64 | | | 64 | |
65 | int sc_fd; | | 65 | int sc_fd; |
66 | void *sc_ih; | | 66 | void *sc_ih; |
67 | | | 67 | |
68 | uint8_t sc_bbuf[MAXBSIZE]; | | | |
69 | | | | |
70 | struct ld_thunkbus_transfer sc_tt; | | 68 | struct ld_thunkbus_transfer sc_tt; |
71 | bool busy; | | 69 | bool busy; |
72 | }; | | 70 | }; |
73 | | | 71 | |
74 | CFATTACH_DECL_NEW(ld_thunkbus, sizeof(struct ld_thunkbus_softc), | | 72 | CFATTACH_DECL_NEW(ld_thunkbus, sizeof(struct ld_thunkbus_softc), |
75 | ld_thunkbus_match, ld_thunkbus_attach, NULL, NULL); | | 73 | ld_thunkbus_match, ld_thunkbus_attach, NULL, NULL); |
76 | | | 74 | |
77 | static int | | 75 | static int |
78 | ld_thunkbus_match(device_t parent, cfdata_t match, void *opaque) | | 76 | ld_thunkbus_match(device_t parent, cfdata_t match, void *opaque) |
79 | { | | 77 | { |
80 | struct thunkbus_attach_args *taa = opaque; | | 78 | struct thunkbus_attach_args *taa = opaque; |
81 | | | 79 | |
82 | if (taa->taa_type != THUNKBUS_TYPE_DISKIMAGE) | | 80 | if (taa->taa_type != THUNKBUS_TYPE_DISKIMAGE) |
| @@ -142,62 +140,46 @@ ld_thunkbus_ldstart(struct ld_softc *ld, | | | @@ -142,62 +140,46 @@ ld_thunkbus_ldstart(struct ld_softc *ld, |
142 | error = 0; | | 140 | error = 0; |
143 | | | 141 | |
144 | return error == -1 ? thunk_geterrno() : 0; | | 142 | return error == -1 ? thunk_geterrno() : 0; |
145 | } | | 143 | } |
146 | | | 144 | |
147 | static void | | 145 | static void |
148 | ld_thunkbus_complete(void *arg) | | 146 | ld_thunkbus_complete(void *arg) |
149 | { | | 147 | { |
150 | struct ld_softc *ld = arg; | | 148 | struct ld_softc *ld = arg; |
151 | struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld; | | 149 | struct ld_thunkbus_softc *sc = (struct ld_thunkbus_softc *)ld; |
152 | struct ld_thunkbus_transfer *tt = &sc->sc_tt; | | 150 | struct ld_thunkbus_transfer *tt = &sc->sc_tt; |
153 | struct buf *bp = tt->tt_bp; | | 151 | struct buf *bp = tt->tt_bp; |
154 | off_t offset = bp->b_rawblkno * ld->sc_secsize; | | 152 | off_t offset = bp->b_rawblkno * ld->sc_secsize; |
155 | void *bbuf = sc->sc_bbuf; | | | |
156 | size_t ret; | | 153 | size_t ret; |
157 | | | 154 | |
158 | if (!sc->busy) | | 155 | if (!sc->busy) |
159 | panic("%s: but not busy?\n", __func__); | | 156 | panic("%s: but not busy?\n", __func__); |
160 | | | 157 | |
161 | if (offset < 0 || | | 158 | if (offset < 0 || |
162 | offset + bp->b_bcount > ld->sc_secsize * ld->sc_secperunit) { | | 159 | offset + bp->b_bcount > ld->sc_secsize * ld->sc_secperunit) { |
163 | bp->b_error = EIO; | | 160 | bp->b_error = EIO; |
164 | bp->b_resid = bp->b_bcount; | | 161 | bp->b_resid = bp->b_bcount; |
165 | goto done; | | 162 | goto done; |
166 | } | | 163 | } |
167 | | | 164 | |
168 | //printf("ld: %s %u @ %lld -> %p (flags 0x%08x)\n", bp->b_flags & B_READ ? "read" : "write", | | 165 | //printf("ld: %s %u @ %lld -> %p (flags 0x%08x)\n", bp->b_flags & B_READ ? "read" : "write", |
169 | // (unsigned int)bp->b_bcount, (long long)offset, bp->b_data, bp->b_flags); | | 166 | // (unsigned int)bp->b_bcount, (long long)offset, bp->b_data, bp->b_flags); |
170 | | | 167 | |
171 | /* read/write the request */ | | 168 | /* read/write the request */ |
172 | if (bp->b_flags & B_READ) { | | 169 | if (bp->b_flags & B_READ) { |
173 | if (bp->b_flags & B_PHYS) { | | 170 | ret = thunk_pread(sc->sc_fd, bp->b_data, bp->b_bcount, offset); |
174 | /* read to bounce buffer and copy out */ | | | |
175 | ret = thunk_pread(sc->sc_fd, bbuf, bp->b_bcount, offset); | | | |
176 | if (ret > 0) | | | |
177 | copyout(bbuf, bp->b_data, ret); | | | |
178 | } else { | | | |
179 | /* just read it */ | | | |
180 | ret = thunk_pread(sc->sc_fd, bp->b_data, bp->b_bcount, offset); | | | |
181 | } | | | |
182 | } else { | | 171 | } else { |
183 | if (bp->b_flags & B_PHYS) { | | 172 | ret = thunk_pwrite(sc->sc_fd, bp->b_data, bp->b_bcount, offset); |
184 | /* copy in to bounce buffer and write it */ | | | |
185 | copyin(bp->b_data, bbuf, bp->b_bcount); | | | |
186 | ret = thunk_pwrite(sc->sc_fd, bbuf, bp->b_bcount, offset); | | | |
187 | } else { | | | |
188 | /* just write it */ | | | |
189 | ret = thunk_pwrite(sc->sc_fd, bp->b_data, bp->b_bcount, offset); | | | |
190 | } | | | |
191 | } | | 173 | } |
192 | | | 174 | |
193 | //if (ret == -1) | | 175 | //if (ret == -1) |
194 | // printf("ld: errno = %d\n", thunk_geterrno()); | | 176 | // printf("ld: errno = %d\n", thunk_geterrno()); |
195 | | | 177 | |
196 | /* setup return params */ | | 178 | /* setup return params */ |
197 | if ((ret >= 0) && (ret == bp->b_bcount)) { | | 179 | if ((ret >= 0) && (ret == bp->b_bcount)) { |
198 | bp->b_resid = 0; | | 180 | bp->b_resid = 0; |
199 | } else { | | 181 | } else { |
200 | bp->b_error = thunk_geterrno(); | | 182 | bp->b_error = thunk_geterrno(); |
201 | bp->b_resid = bp->b_bcount; | | 183 | bp->b_resid = bp->b_bcount; |
202 | } | | 184 | } |
203 | | | 185 | |