| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ppi.c,v 1.42 2008/06/18 12:25:13 tsutsui Exp $ */ | | 1 | /* $NetBSD: ppi.c,v 1.43 2011/07/28 03:42:20 uebayasi Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe. | | 8 | * by Jason R. Thorpe. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -55,27 +55,27 @@ | | | @@ -55,27 +55,27 @@ |
55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)ppi.c 8.1 (Berkeley) 6/16/93 | | 60 | * @(#)ppi.c 8.1 (Berkeley) 6/16/93 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | /* | | 63 | /* |
64 | * Printer/Plotter HPIB interface | | 64 | * Printer/Plotter HPIB interface |
65 | */ | | 65 | */ |
66 | | | 66 | |
67 | #include <sys/cdefs.h> | | 67 | #include <sys/cdefs.h> |
68 | __KERNEL_RCSID(0, "$NetBSD: ppi.c,v 1.42 2008/06/18 12:25:13 tsutsui Exp $"); | | 68 | __KERNEL_RCSID(0, "$NetBSD: ppi.c,v 1.43 2011/07/28 03:42:20 uebayasi Exp $"); |
69 | | | 69 | |
70 | #include <sys/param.h> | | 70 | #include <sys/param.h> |
71 | #include <sys/systm.h> | | 71 | #include <sys/systm.h> |
72 | #include <sys/callout.h> | | 72 | #include <sys/callout.h> |
73 | #include <sys/conf.h> | | 73 | #include <sys/conf.h> |
74 | #include <sys/device.h> | | 74 | #include <sys/device.h> |
75 | #include <sys/errno.h> | | 75 | #include <sys/errno.h> |
76 | #include <sys/malloc.h> | | 76 | #include <sys/malloc.h> |
77 | #include <sys/proc.h> | | 77 | #include <sys/proc.h> |
78 | #include <sys/uio.h> | | 78 | #include <sys/uio.h> |
79 | | | 79 | |
80 | #include <hp300/dev/hpibvar.h> | | 80 | #include <hp300/dev/hpibvar.h> |
81 | | | 81 | |
| @@ -196,47 +196,47 @@ int | | | @@ -196,47 +196,47 @@ int |
196 | ppiopen(dev_t dev, int flags, int fmt, struct lwp *l) | | 196 | ppiopen(dev_t dev, int flags, int fmt, struct lwp *l) |
197 | { | | 197 | { |
198 | struct ppi_softc *sc; | | 198 | struct ppi_softc *sc; |
199 | | | 199 | |
200 | sc = device_lookup_private(&ppi_cd,UNIT(dev)); | | 200 | sc = device_lookup_private(&ppi_cd,UNIT(dev)); |
201 | if (sc == NULL) | | 201 | if (sc == NULL) |
202 | return ENXIO; | | 202 | return ENXIO; |
203 | | | 203 | |
204 | if ((sc->sc_flags & PPIF_ALIVE) == 0) | | 204 | if ((sc->sc_flags & PPIF_ALIVE) == 0) |
205 | return ENXIO; | | 205 | return ENXIO; |
206 | | | 206 | |
207 | #ifdef DEBUG | | 207 | #ifdef DEBUG |
208 | if (ppidebug & PDB_FOLLOW) | | 208 | if (ppidebug & PDB_FOLLOW) |
209 | printf("ppiopen(%x, %x): flags %x\n", | | 209 | printf("ppiopen(%"PRIx64", %x): flags %x\n", |
210 | dev, flags, sc->sc_flags); | | 210 | dev, flags, sc->sc_flags); |
211 | #endif | | 211 | #endif |
212 | if (sc->sc_flags & PPIF_OPEN) | | 212 | if (sc->sc_flags & PPIF_OPEN) |
213 | return EBUSY; | | 213 | return EBUSY; |
214 | sc->sc_flags |= PPIF_OPEN; | | 214 | sc->sc_flags |= PPIF_OPEN; |
215 | sc->sc_burst = PPI_BURST; | | 215 | sc->sc_burst = PPI_BURST; |
216 | sc->sc_timo = ppimstohz(PPI_TIMO); | | 216 | sc->sc_timo = ppimstohz(PPI_TIMO); |
217 | sc->sc_delay = ppimstohz(PPI_DELAY); | | 217 | sc->sc_delay = ppimstohz(PPI_DELAY); |
218 | sc->sc_sec = -1; | | 218 | sc->sc_sec = -1; |
219 | return 0; | | 219 | return 0; |
220 | } | | 220 | } |
221 | | | 221 | |
222 | static int | | 222 | static int |
223 | ppiclose(dev_t dev, int flags, int fmt, struct lwp *l) | | 223 | ppiclose(dev_t dev, int flags, int fmt, struct lwp *l) |
224 | { | | 224 | { |
225 | struct ppi_softc *sc = device_lookup_private(&ppi_cd, UNIT(dev)); | | 225 | struct ppi_softc *sc = device_lookup_private(&ppi_cd, UNIT(dev)); |
226 | | | 226 | |
227 | #ifdef DEBUG | | 227 | #ifdef DEBUG |
228 | if (ppidebug & PDB_FOLLOW) | | 228 | if (ppidebug & PDB_FOLLOW) |
229 | printf("ppiclose(%x, %x): flags %x\n", | | 229 | printf("ppiclose(%"PRIx64", %x): flags %x\n", |
230 | dev, flags, sc->sc_flags); | | 230 | dev, flags, sc->sc_flags); |
231 | #endif | | 231 | #endif |
232 | sc->sc_flags &= ~PPIF_OPEN; | | 232 | sc->sc_flags &= ~PPIF_OPEN; |
233 | return 0; | | 233 | return 0; |
234 | } | | 234 | } |
235 | | | 235 | |
236 | static void | | 236 | static void |
237 | ppistart(void *arg) | | 237 | ppistart(void *arg) |
238 | { | | 238 | { |
239 | struct ppi_softc *sc = arg; | | 239 | struct ppi_softc *sc = arg; |
240 | | | 240 | |
241 | #ifdef DEBUG | | 241 | #ifdef DEBUG |
242 | if (ppidebug & PDB_FOLLOW) | | 242 | if (ppidebug & PDB_FOLLOW) |
| @@ -255,61 +255,61 @@ ppitimo(void *arg) | | | @@ -255,61 +255,61 @@ ppitimo(void *arg) |
255 | if (ppidebug & PDB_FOLLOW) | | 255 | if (ppidebug & PDB_FOLLOW) |
256 | printf("ppitimo(%x)\n", device_unit(sc->sc_dev)); | | 256 | printf("ppitimo(%x)\n", device_unit(sc->sc_dev)); |
257 | #endif | | 257 | #endif |
258 | sc->sc_flags &= ~(PPIF_UIO|PPIF_TIMO); | | 258 | sc->sc_flags &= ~(PPIF_UIO|PPIF_TIMO); |
259 | wakeup(sc); | | 259 | wakeup(sc); |
260 | } | | 260 | } |
261 | | | 261 | |
262 | static int | | 262 | static int |
263 | ppiread(dev_t dev, struct uio *uio, int flags) | | 263 | ppiread(dev_t dev, struct uio *uio, int flags) |
264 | { | | 264 | { |
265 | | | 265 | |
266 | #ifdef DEBUG | | 266 | #ifdef DEBUG |
267 | if (ppidebug & PDB_FOLLOW) | | 267 | if (ppidebug & PDB_FOLLOW) |
268 | printf("ppiread(%x, %p)\n", dev, uio); | | 268 | printf("ppiread(%"PRIx64", %p)\n", dev, uio); |
269 | #endif | | 269 | #endif |
270 | return ppirw(dev, uio); | | 270 | return ppirw(dev, uio); |
271 | } | | 271 | } |
272 | | | 272 | |
273 | static int | | 273 | static int |
274 | ppiwrite(dev_t dev, struct uio *uio, int flags) | | 274 | ppiwrite(dev_t dev, struct uio *uio, int flags) |
275 | { | | 275 | { |
276 | | | 276 | |
277 | #ifdef DEBUG | | 277 | #ifdef DEBUG |
278 | if (ppidebug & PDB_FOLLOW) | | 278 | if (ppidebug & PDB_FOLLOW) |
279 | printf("ppiwrite(%x, %p)\n", dev, uio); | | 279 | printf("ppiwrite(%"PRIx64", %p)\n", dev, uio); |
280 | #endif | | 280 | #endif |
281 | return ppirw(dev, uio); | | 281 | return ppirw(dev, uio); |
282 | } | | 282 | } |
283 | | | 283 | |
284 | static int | | 284 | static int |
285 | ppirw(dev_t dev, struct uio *uio) | | 285 | ppirw(dev_t dev, struct uio *uio) |
286 | { | | 286 | { |
287 | struct ppi_softc *sc = device_lookup_private(&ppi_cd, UNIT(dev)); | | 287 | struct ppi_softc *sc = device_lookup_private(&ppi_cd, UNIT(dev)); |
288 | int s, s2, len, cnt; | | 288 | int s, s2, len, cnt; |
289 | char *cp; | | 289 | char *cp; |
290 | int error = 0, gotdata = 0; | | 290 | int error = 0, gotdata = 0; |
291 | int buflen, ctlr, slave; | | 291 | int buflen, ctlr, slave; |
292 | char *buf; | | 292 | char *buf; |
293 | | | 293 | |
294 | if (uio->uio_resid == 0) | | 294 | if (uio->uio_resid == 0) |
295 | return 0; | | 295 | return 0; |
296 | | | 296 | |
297 | ctlr = device_unit(device_parent(sc->sc_dev)); | | 297 | ctlr = device_unit(device_parent(sc->sc_dev)); |
298 | slave = sc->sc_slave; | | 298 | slave = sc->sc_slave; |
299 | | | 299 | |
300 | #ifdef DEBUG | | 300 | #ifdef DEBUG |
301 | if (ppidebug & (PDB_FOLLOW|PDB_IO)) | | 301 | if (ppidebug & (PDB_FOLLOW|PDB_IO)) |
302 | printf("ppirw(%x, %p, %c): burst %d, timo %d, resid %x\n", | | 302 | printf("ppirw(%"PRIx64", %p, %c): burst %d, timo %d, resid %x\n", |
303 | dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W', | | 303 | dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W', |
304 | sc->sc_burst, sc->sc_timo, uio->uio_resid); | | 304 | sc->sc_burst, sc->sc_timo, uio->uio_resid); |
305 | #endif | | 305 | #endif |
306 | buflen = min(sc->sc_burst, uio->uio_resid); | | 306 | buflen = min(sc->sc_burst, uio->uio_resid); |
307 | buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK); | | 307 | buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK); |
308 | sc->sc_flags |= PPIF_UIO; | | 308 | sc->sc_flags |= PPIF_UIO; |
309 | if (sc->sc_timo > 0) { | | 309 | if (sc->sc_timo > 0) { |
310 | sc->sc_flags |= PPIF_TIMO; | | 310 | sc->sc_flags |= PPIF_TIMO; |
311 | callout_reset(&sc->sc_timo_ch, sc->sc_timo, ppitimo, sc); | | 311 | callout_reset(&sc->sc_timo_ch, sc->sc_timo, ppitimo, sc); |
312 | } | | 312 | } |
313 | len = cnt = 0; | | 313 | len = cnt = 0; |
314 | while (uio->uio_resid > 0) { | | 314 | while (uio->uio_resid > 0) { |
315 | len = min(buflen, uio->uio_resid); | | 315 | len = min(buflen, uio->uio_resid); |