Home | History | Annotate | Line # | Download | only in dev
ppi.c revision 1.15
      1  1.15   thorpej /*	$NetBSD: ppi.c,v 1.15 1997/10/04 10:00:23 thorpej Exp $	*/
      2  1.15   thorpej 
      3  1.15   thorpej /*-
      4  1.15   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.15   thorpej  * All rights reserved.
      6  1.15   thorpej  *
      7  1.15   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.15   thorpej  * by Jason R. Thorpe.
      9  1.15   thorpej  *
     10  1.15   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.15   thorpej  * modification, are permitted provided that the following conditions
     12  1.15   thorpej  * are met:
     13  1.15   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.15   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.15   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.15   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.15   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.15   thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.15   thorpej  *    must display the following acknowledgement:
     20  1.15   thorpej  *	This product includes software developed by the NetBSD
     21  1.15   thorpej  *	Foundation, Inc. and its contributors.
     22  1.15   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.15   thorpej  *    contributors may be used to endorse or promote products derived
     24  1.15   thorpej  *    from this software without specific prior written permission.
     25  1.15   thorpej  *
     26  1.15   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.15   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.15   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.15   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.15   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.15   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.15   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.15   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.15   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.15   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.15   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.15   thorpej  */
     38   1.6       cgd 
     39   1.1       cgd /*
     40   1.5   mycroft  * Copyright (c) 1982, 1990, 1993
     41   1.5   mycroft  *	The Regents of the University of California.  All rights reserved.
     42   1.1       cgd  *
     43   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     44   1.1       cgd  * modification, are permitted provided that the following conditions
     45   1.1       cgd  * are met:
     46   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     47   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     48   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     50   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     51   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     52   1.1       cgd  *    must display the following acknowledgement:
     53   1.1       cgd  *	This product includes software developed by the University of
     54   1.1       cgd  *	California, Berkeley and its contributors.
     55   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     56   1.1       cgd  *    may be used to endorse or promote products derived from this software
     57   1.1       cgd  *    without specific prior written permission.
     58   1.1       cgd  *
     59   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69   1.1       cgd  * SUCH DAMAGE.
     70   1.1       cgd  *
     71   1.6       cgd  *	@(#)ppi.c	8.1 (Berkeley) 6/16/93
     72   1.1       cgd  */
     73   1.1       cgd 
     74   1.1       cgd /*
     75   1.1       cgd  * Printer/Plotter HPIB interface
     76   1.1       cgd  */
     77   1.1       cgd 
     78   1.3   mycroft #include <sys/param.h>
     79   1.3   mycroft #include <sys/systm.h>
     80  1.12    scottr #include <sys/conf.h>
     81  1.12    scottr #include <sys/device.h>
     82   1.3   mycroft #include <sys/errno.h>
     83  1.12    scottr #include <sys/malloc.h>
     84  1.12    scottr #include <sys/proc.h>
     85   1.3   mycroft #include <sys/uio.h>
     86  1.11   thorpej 
     87  1.11   thorpej #include <hp300/dev/hpibvar.h>
     88   1.1       cgd 
     89   1.3   mycroft #include <hp300/dev/ppiioctl.h>
     90   1.1       cgd 
     91   1.1       cgd struct	ppi_softc {
     92  1.11   thorpej 	struct device sc_dev;
     93   1.1       cgd 	int	sc_flags;
     94  1.11   thorpej 	struct	hpibqueue sc_hq;	/* HP-IB job queue entry */
     95   1.1       cgd 	struct	ppiparam sc_param;
     96   1.1       cgd #define sc_burst sc_param.burst
     97   1.1       cgd #define sc_timo  sc_param.timo
     98   1.1       cgd #define sc_delay sc_param.delay
     99   1.1       cgd 	int	sc_sec;
    100  1.11   thorpej 	int	sc_slave;		/* HP-IB slave address */
    101  1.11   thorpej };
    102   1.1       cgd 
    103   1.1       cgd /* sc_flags values */
    104   1.1       cgd #define	PPIF_ALIVE	0x01
    105   1.1       cgd #define	PPIF_OPEN	0x02
    106   1.1       cgd #define PPIF_UIO	0x04
    107   1.1       cgd #define PPIF_TIMO	0x08
    108   1.1       cgd #define PPIF_DELAY	0x10
    109   1.1       cgd 
    110  1.11   thorpej int	ppimatch __P((struct device *, struct cfdata *, void *));
    111  1.11   thorpej void	ppiattach __P((struct device *, struct device *, void *));
    112  1.11   thorpej 
    113  1.11   thorpej struct cfattach ppi_ca = {
    114  1.11   thorpej 	sizeof(struct ppi_softc), ppimatch, ppiattach
    115  1.11   thorpej };
    116  1.11   thorpej 
    117  1.11   thorpej struct cfdriver ppi_cd = {
    118  1.11   thorpej 	NULL, "ppi", DV_DULL
    119  1.11   thorpej };
    120  1.11   thorpej 
    121  1.11   thorpej void	ppistart __P((void *));
    122  1.11   thorpej void	ppinoop __P((void *));
    123  1.11   thorpej 
    124  1.11   thorpej void	ppitimo __P((void *));
    125  1.11   thorpej int	ppirw __P((dev_t, struct uio *));
    126  1.11   thorpej int	ppihztoms __P((int));
    127  1.11   thorpej int	ppimstohz __P((int));
    128  1.11   thorpej 
    129  1.11   thorpej bdev_decl(ppi);
    130  1.11   thorpej cdev_decl(ppi);
    131  1.11   thorpej 
    132   1.1       cgd #define UNIT(x)		minor(x)
    133   1.1       cgd 
    134   1.1       cgd #ifdef DEBUG
    135   1.1       cgd int	ppidebug = 0x80;
    136   1.1       cgd #define PDB_FOLLOW	0x01
    137   1.1       cgd #define PDB_IO		0x02
    138   1.1       cgd #define PDB_NOCHECK	0x80
    139   1.1       cgd #endif
    140   1.1       cgd 
    141   1.7   thorpej int
    142  1.11   thorpej ppimatch(parent, match, aux)
    143  1.11   thorpej 	struct device *parent;
    144  1.11   thorpej 	struct cfdata *match;
    145  1.11   thorpej 	void *aux;
    146   1.1       cgd {
    147  1.11   thorpej 	struct hpibbus_attach_args *ha = aux;
    148  1.11   thorpej 
    149  1.11   thorpej 	/*
    150  1.11   thorpej 	 * The printer/plotter doesn't return an ID tag.
    151  1.11   thorpej 	 * The check below prevents us from matching a CS80
    152  1.11   thorpej 	 * device by mistake.
    153  1.11   thorpej 	 */
    154  1.11   thorpej 	if (ha->ha_id & 0x200)
    155  1.11   thorpej 		return (0);
    156   1.1       cgd 
    157   1.1       cgd 	/*
    158  1.11   thorpej 	 * To prevent matching all unused slots on the bus, we
    159  1.11   thorpej 	 * don't allow wildcarded locators.
    160   1.1       cgd 	 */
    161  1.14       jtk 	if (match->hpibbuscf_slave == HPIBBUSCF_SLAVE_DEFAULT ||
    162  1.14       jtk 	    match->hpibbuscf_punit == HPIBBUSCF_PUNIT_DEFAULT)
    163   1.7   thorpej 		return (0);
    164   1.7   thorpej 
    165   1.7   thorpej 	return (1);
    166   1.7   thorpej }
    167   1.7   thorpej 
    168   1.7   thorpej void
    169  1.11   thorpej ppiattach(parent, self, aux)
    170  1.11   thorpej 	struct device *parent, *self;
    171  1.11   thorpej 	void *aux;
    172   1.7   thorpej {
    173  1.11   thorpej 	struct ppi_softc *sc = (struct ppi_softc *)self;
    174  1.11   thorpej 	struct hpibbus_attach_args *ha = aux;
    175   1.7   thorpej 
    176  1.10  christos 	printf("\n");
    177   1.7   thorpej 
    178  1.11   thorpej 	sc->sc_slave = ha->ha_slave;
    179  1.11   thorpej 
    180  1.11   thorpej 	/* Initialize the hpib queue entry. */
    181  1.11   thorpej 	sc->sc_hq.hq_softc = sc;
    182  1.11   thorpej 	sc->sc_hq.hq_slave = sc->sc_slave;
    183  1.11   thorpej 	sc->sc_hq.hq_start = ppistart;
    184  1.11   thorpej 	sc->sc_hq.hq_go = ppinoop;
    185  1.11   thorpej 	sc->sc_hq.hq_intr = ppinoop;
    186  1.11   thorpej 
    187   1.1       cgd 	sc->sc_flags = PPIF_ALIVE;
    188   1.1       cgd }
    189   1.1       cgd 
    190  1.11   thorpej void
    191  1.11   thorpej ppinoop(arg)
    192  1.11   thorpej 	void *arg;
    193  1.11   thorpej {
    194  1.11   thorpej 	/* Noop! */
    195  1.11   thorpej }
    196  1.11   thorpej 
    197  1.11   thorpej int
    198  1.11   thorpej ppiopen(dev, flags, fmt, p)
    199   1.1       cgd 	dev_t dev;
    200  1.11   thorpej 	int flags, fmt;
    201  1.11   thorpej 	struct proc *p;
    202   1.1       cgd {
    203  1.12    scottr 	int unit = UNIT(dev);
    204  1.11   thorpej 	struct ppi_softc *sc;
    205  1.11   thorpej 
    206  1.11   thorpej 	if (unit >= ppi_cd.cd_ndevs ||
    207  1.11   thorpej 	    (sc = ppi_cd.cd_devs[unit]) == NULL ||
    208  1.11   thorpej 	    (sc->sc_flags & PPIF_ALIVE) == 0)
    209  1.11   thorpej 		return (ENXIO);
    210   1.1       cgd 
    211   1.1       cgd #ifdef DEBUG
    212   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    213  1.10  christos 		printf("ppiopen(%x, %x): flags %x\n",
    214   1.1       cgd 		       dev, flags, sc->sc_flags);
    215   1.1       cgd #endif
    216   1.1       cgd 	if (sc->sc_flags & PPIF_OPEN)
    217  1.11   thorpej 		return (EBUSY);
    218   1.1       cgd 	sc->sc_flags |= PPIF_OPEN;
    219   1.1       cgd 	sc->sc_burst = PPI_BURST;
    220   1.1       cgd 	sc->sc_timo = ppimstohz(PPI_TIMO);
    221   1.1       cgd 	sc->sc_delay = ppimstohz(PPI_DELAY);
    222   1.1       cgd 	sc->sc_sec = -1;
    223   1.1       cgd 	return(0);
    224   1.1       cgd }
    225   1.1       cgd 
    226  1.11   thorpej int
    227  1.11   thorpej ppiclose(dev, flags, fmt, p)
    228   1.1       cgd 	dev_t dev;
    229  1.11   thorpej 	int flags, fmt;
    230  1.11   thorpej 	struct proc *p;
    231   1.1       cgd {
    232  1.12    scottr 	int unit = UNIT(dev);
    233  1.11   thorpej 	struct ppi_softc *sc = ppi_cd.cd_devs[unit];
    234   1.1       cgd 
    235   1.1       cgd #ifdef DEBUG
    236   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    237  1.10  christos 		printf("ppiclose(%x, %x): flags %x\n",
    238   1.1       cgd 		       dev, flags, sc->sc_flags);
    239   1.1       cgd #endif
    240   1.1       cgd 	sc->sc_flags &= ~PPIF_OPEN;
    241   1.1       cgd 	return(0);
    242   1.1       cgd }
    243   1.1       cgd 
    244  1.11   thorpej void
    245  1.11   thorpej ppistart(arg)
    246  1.11   thorpej 	void *arg;
    247   1.1       cgd {
    248  1.11   thorpej 	struct ppi_softc *sc = arg;
    249  1.11   thorpej 
    250   1.1       cgd #ifdef DEBUG
    251   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    252  1.13    scottr 		printf("ppistart(%x)\n", sc->sc_dev.dv_unit);
    253   1.1       cgd #endif
    254  1.11   thorpej 	sc->sc_flags &= ~PPIF_DELAY;
    255  1.11   thorpej 	wakeup(sc);
    256   1.1       cgd }
    257   1.1       cgd 
    258   1.5   mycroft void
    259  1.11   thorpej ppitimo(arg)
    260  1.11   thorpej 	void *arg;
    261   1.1       cgd {
    262  1.11   thorpej 	struct ppi_softc *sc = arg;
    263  1.11   thorpej 
    264   1.1       cgd #ifdef DEBUG
    265   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    266  1.11   thorpej 		printf("ppitimo(%x)\n", sc->sc_dev.dv_unit);
    267   1.1       cgd #endif
    268  1.11   thorpej 	sc->sc_flags &= ~(PPIF_UIO|PPIF_TIMO);
    269  1.11   thorpej 	wakeup(sc);
    270   1.1       cgd }
    271   1.1       cgd 
    272  1.11   thorpej int
    273  1.11   thorpej ppiread(dev, uio, flags)
    274   1.1       cgd 	dev_t dev;
    275   1.1       cgd 	struct uio *uio;
    276  1.11   thorpej 	int flags;
    277   1.1       cgd {
    278   1.1       cgd 
    279   1.1       cgd #ifdef DEBUG
    280   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    281  1.13    scottr 		printf("ppiread(%x, %p)\n", dev, uio);
    282   1.1       cgd #endif
    283   1.1       cgd 	return (ppirw(dev, uio));
    284   1.1       cgd }
    285   1.1       cgd 
    286  1.11   thorpej int
    287  1.11   thorpej ppiwrite(dev, uio, flags)
    288   1.1       cgd 	dev_t dev;
    289   1.1       cgd 	struct uio *uio;
    290  1.11   thorpej 	int flags;
    291   1.1       cgd {
    292   1.1       cgd 
    293   1.1       cgd #ifdef DEBUG
    294   1.1       cgd 	if (ppidebug & PDB_FOLLOW)
    295  1.13    scottr 		printf("ppiwrite(%x, %p)\n", dev, uio);
    296   1.1       cgd #endif
    297   1.1       cgd 	return (ppirw(dev, uio));
    298   1.1       cgd }
    299   1.1       cgd 
    300  1.11   thorpej int
    301   1.1       cgd ppirw(dev, uio)
    302   1.1       cgd 	dev_t dev;
    303  1.12    scottr 	struct uio *uio;
    304   1.1       cgd {
    305   1.1       cgd 	int unit = UNIT(dev);
    306  1.11   thorpej 	struct ppi_softc *sc = ppi_cd.cd_devs[unit];
    307  1.12    scottr 	int s, len, cnt;
    308  1.12    scottr 	char *cp;
    309   1.1       cgd 	int error = 0, gotdata = 0;
    310  1.11   thorpej 	int buflen, ctlr, slave;
    311   1.1       cgd 	char *buf;
    312   1.1       cgd 
    313   1.1       cgd 	if (uio->uio_resid == 0)
    314   1.1       cgd 		return(0);
    315   1.1       cgd 
    316  1.11   thorpej 	ctlr = sc->sc_dev.dv_parent->dv_unit;
    317  1.11   thorpej 	slave = sc->sc_slave;
    318  1.11   thorpej 
    319   1.1       cgd #ifdef DEBUG
    320   1.1       cgd 	if (ppidebug & (PDB_FOLLOW|PDB_IO))
    321  1.13    scottr 		printf("ppirw(%x, %p, %c): burst %d, timo %d, resid %x\n",
    322   1.1       cgd 		       dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
    323   1.1       cgd 		       sc->sc_burst, sc->sc_timo, uio->uio_resid);
    324   1.1       cgd #endif
    325   1.5   mycroft 	buflen = min(sc->sc_burst, uio->uio_resid);
    326   1.1       cgd 	buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
    327   1.1       cgd 	sc->sc_flags |= PPIF_UIO;
    328   1.1       cgd 	if (sc->sc_timo > 0) {
    329   1.1       cgd 		sc->sc_flags |= PPIF_TIMO;
    330  1.11   thorpej 		timeout(ppitimo, sc, sc->sc_timo);
    331   1.1       cgd 	}
    332  1.12    scottr 	len = cnt = 0;
    333   1.1       cgd 	while (uio->uio_resid > 0) {
    334   1.5   mycroft 		len = min(buflen, uio->uio_resid);
    335   1.1       cgd 		cp = buf;
    336   1.1       cgd 		if (uio->uio_rw == UIO_WRITE) {
    337   1.1       cgd 			error = uiomove(cp, len, uio);
    338   1.1       cgd 			if (error)
    339   1.1       cgd 				break;
    340   1.1       cgd 		}
    341   1.1       cgd again:
    342   1.1       cgd 		s = splbio();
    343  1.11   thorpej 		if ((sc->sc_flags & PPIF_UIO) &&
    344  1.11   thorpej 		    hpibreq(sc->sc_dev.dv_parent, &sc->sc_hq) == 0)
    345   1.1       cgd 			sleep(sc, PRIBIO+1);
    346   1.1       cgd 		/*
    347   1.1       cgd 		 * Check if we timed out during sleep or uiomove
    348   1.1       cgd 		 */
    349   1.1       cgd 		(void) splsoftclock();
    350   1.1       cgd 		if ((sc->sc_flags & PPIF_UIO) == 0) {
    351   1.1       cgd #ifdef DEBUG
    352   1.1       cgd 			if (ppidebug & PDB_IO)
    353  1.10  christos 				printf("ppirw: uiomove/sleep timo, flags %x\n",
    354   1.1       cgd 				       sc->sc_flags);
    355   1.1       cgd #endif
    356   1.1       cgd 			if (sc->sc_flags & PPIF_TIMO) {
    357  1.11   thorpej 				untimeout(ppitimo, sc);
    358   1.1       cgd 				sc->sc_flags &= ~PPIF_TIMO;
    359   1.1       cgd 			}
    360   1.1       cgd 			splx(s);
    361   1.1       cgd 			break;
    362   1.1       cgd 		}
    363   1.1       cgd 		splx(s);
    364   1.1       cgd 		/*
    365   1.1       cgd 		 * Perform the operation
    366   1.1       cgd 		 */
    367   1.1       cgd 		if (uio->uio_rw == UIO_WRITE)
    368  1.11   thorpej 			cnt = hpibsend(ctlr, slave, sc->sc_sec, cp, len);
    369   1.1       cgd 		else
    370  1.11   thorpej 			cnt = hpibrecv(ctlr, slave, sc->sc_sec, cp, len);
    371   1.1       cgd 		s = splbio();
    372  1.11   thorpej 		hpibfree(sc->sc_dev.dv_parent, &sc->sc_hq);
    373   1.1       cgd #ifdef DEBUG
    374   1.1       cgd 		if (ppidebug & PDB_IO)
    375  1.13    scottr 			printf("ppirw: %s(%d, %d, %x, %p, %d) -> %d\n",
    376   1.1       cgd 			       uio->uio_rw == UIO_READ ? "recv" : "send",
    377  1.11   thorpej 			       ctlr, slave, sc->sc_sec, cp, len, cnt);
    378   1.1       cgd #endif
    379   1.1       cgd 		splx(s);
    380   1.1       cgd 		if (uio->uio_rw == UIO_READ) {
    381   1.1       cgd 			if (cnt) {
    382   1.1       cgd 				error = uiomove(cp, cnt, uio);
    383   1.1       cgd 				if (error)
    384   1.1       cgd 					break;
    385   1.1       cgd 				gotdata++;
    386   1.1       cgd 			}
    387   1.1       cgd 			/*
    388   1.1       cgd 			 * Didn't get anything this time, but did in the past.
    389   1.1       cgd 			 * Consider us done.
    390   1.1       cgd 			 */
    391   1.1       cgd 			else if (gotdata)
    392   1.1       cgd 				break;
    393   1.1       cgd 		}
    394   1.1       cgd 		s = splsoftclock();
    395   1.1       cgd 		/*
    396   1.1       cgd 		 * Operation timeout (or non-blocking), quit now.
    397   1.1       cgd 		 */
    398   1.1       cgd 		if ((sc->sc_flags & PPIF_UIO) == 0) {
    399   1.1       cgd #ifdef DEBUG
    400   1.1       cgd 			if (ppidebug & PDB_IO)
    401  1.10  christos 				printf("ppirw: timeout/done\n");
    402   1.1       cgd #endif
    403   1.1       cgd 			splx(s);
    404   1.1       cgd 			break;
    405   1.1       cgd 		}
    406   1.1       cgd 		/*
    407   1.1       cgd 		 * Implement inter-read delay
    408   1.1       cgd 		 */
    409   1.1       cgd 		if (sc->sc_delay > 0) {
    410   1.1       cgd 			sc->sc_flags |= PPIF_DELAY;
    411  1.11   thorpej 			timeout(ppistart, sc, sc->sc_delay);
    412  1.12    scottr 			error = tsleep(sc, (PCATCH|PZERO) + 1, "hpib", 0);
    413   1.1       cgd 			if (error) {
    414   1.1       cgd 				splx(s);
    415   1.1       cgd 				break;
    416   1.1       cgd 			}
    417   1.1       cgd 		}
    418   1.1       cgd 		splx(s);
    419   1.1       cgd 		/*
    420   1.1       cgd 		 * Must not call uiomove again til we've used all data
    421   1.1       cgd 		 * that we already grabbed.
    422   1.1       cgd 		 */
    423   1.1       cgd 		if (uio->uio_rw == UIO_WRITE && cnt != len) {
    424   1.1       cgd 			cp += cnt;
    425   1.1       cgd 			len -= cnt;
    426   1.1       cgd 			cnt = 0;
    427   1.1       cgd 			goto again;
    428   1.1       cgd 		}
    429   1.1       cgd 	}
    430   1.1       cgd 	s = splsoftclock();
    431   1.1       cgd 	if (sc->sc_flags & PPIF_TIMO) {
    432  1.11   thorpej 		untimeout(ppitimo, sc);
    433   1.1       cgd 		sc->sc_flags &= ~PPIF_TIMO;
    434   1.1       cgd 	}
    435   1.1       cgd 	if (sc->sc_flags & PPIF_DELAY) {
    436  1.11   thorpej 		untimeout(ppistart, sc);
    437   1.1       cgd 		sc->sc_flags &= ~PPIF_DELAY;
    438   1.1       cgd 	}
    439   1.1       cgd 	splx(s);
    440   1.1       cgd 	/*
    441   1.1       cgd 	 * Adjust for those chars that we uiomove'ed but never wrote
    442   1.1       cgd 	 */
    443   1.1       cgd 	if (uio->uio_rw == UIO_WRITE && cnt != len) {
    444   1.1       cgd 		uio->uio_resid += (len - cnt);
    445   1.1       cgd #ifdef DEBUG
    446   1.1       cgd 		if (ppidebug & PDB_IO)
    447  1.10  christos 			printf("ppirw: short write, adjust by %d\n",
    448   1.1       cgd 			       len-cnt);
    449   1.1       cgd #endif
    450   1.1       cgd 	}
    451   1.1       cgd 	free(buf, M_DEVBUF);
    452   1.1       cgd #ifdef DEBUG
    453   1.1       cgd 	if (ppidebug & (PDB_FOLLOW|PDB_IO))
    454  1.10  christos 		printf("ppirw: return %d, resid %d\n", error, uio->uio_resid);
    455   1.1       cgd #endif
    456   1.1       cgd 	return (error);
    457   1.1       cgd }
    458   1.1       cgd 
    459  1.11   thorpej int
    460   1.3   mycroft ppiioctl(dev, cmd, data, flag, p)
    461   1.1       cgd 	dev_t dev;
    462  1.11   thorpej 	u_long cmd;
    463   1.1       cgd 	caddr_t data;
    464   1.1       cgd 	int flag;
    465   1.3   mycroft 	struct proc *p;
    466   1.1       cgd {
    467  1.11   thorpej 	struct ppi_softc *sc = ppi_cd.cd_devs[UNIT(dev)];
    468   1.1       cgd 	struct ppiparam *pp, *upp;
    469   1.1       cgd 	int error = 0;
    470   1.1       cgd 
    471   1.1       cgd 	switch (cmd) {
    472   1.1       cgd 	case PPIIOCGPARAM:
    473   1.1       cgd 		pp = &sc->sc_param;
    474   1.1       cgd 		upp = (struct ppiparam *)data;
    475   1.1       cgd 		upp->burst = pp->burst;
    476   1.1       cgd 		upp->timo = ppihztoms(pp->timo);
    477   1.1       cgd 		upp->delay = ppihztoms(pp->delay);
    478   1.1       cgd 		break;
    479   1.1       cgd 	case PPIIOCSPARAM:
    480   1.1       cgd 		pp = &sc->sc_param;
    481   1.1       cgd 		upp = (struct ppiparam *)data;
    482   1.1       cgd 		if (upp->burst < PPI_BURST_MIN || upp->burst > PPI_BURST_MAX ||
    483   1.1       cgd 		    upp->delay < PPI_DELAY_MIN || upp->delay > PPI_DELAY_MAX)
    484   1.1       cgd 			return(EINVAL);
    485   1.1       cgd 		pp->burst = upp->burst;
    486   1.1       cgd 		pp->timo = ppimstohz(upp->timo);
    487   1.1       cgd 		pp->delay = ppimstohz(upp->delay);
    488   1.1       cgd 		break;
    489   1.1       cgd 	case PPIIOCSSEC:
    490   1.1       cgd 		sc->sc_sec = *(int *)data;
    491   1.1       cgd 		break;
    492   1.1       cgd 	default:
    493   1.1       cgd 		return(EINVAL);
    494   1.1       cgd 	}
    495   1.1       cgd 	return (error);
    496   1.1       cgd }
    497   1.1       cgd 
    498  1.11   thorpej int
    499   1.1       cgd ppihztoms(h)
    500   1.1       cgd 	int h;
    501   1.1       cgd {
    502   1.1       cgd 	extern int hz;
    503  1.12    scottr 	int m = h;
    504   1.1       cgd 
    505   1.1       cgd 	if (m > 0)
    506   1.1       cgd 		m = m * 1000 / hz;
    507   1.1       cgd 	return(m);
    508   1.1       cgd }
    509   1.1       cgd 
    510  1.11   thorpej int
    511   1.1       cgd ppimstohz(m)
    512   1.1       cgd 	int m;
    513   1.1       cgd {
    514   1.1       cgd 	extern int hz;
    515  1.12    scottr 	int h = m;
    516   1.1       cgd 
    517   1.1       cgd 	if (h > 0) {
    518   1.1       cgd 		h = h * hz / 1000;
    519   1.1       cgd 		if (h == 0)
    520   1.1       cgd 			h = 1000 / hz;
    521   1.1       cgd 	}
    522   1.1       cgd 	return(h);
    523   1.1       cgd }
    524