Home | History | Annotate | Line # | Download | only in mvme
lpt_mvme.c revision 1.2.2.2
      1  1.2.2.2  jdolecek /*	$NetBSD: lpt_mvme.c,v 1.2.2.2 2002/10/10 18:40:14 jdolecek Exp $	*/
      2  1.2.2.2  jdolecek 
      3  1.2.2.2  jdolecek /*-
      4  1.2.2.2  jdolecek  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
      5  1.2.2.2  jdolecek  * All rights reserved.
      6  1.2.2.2  jdolecek  *
      7  1.2.2.2  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2.2.2  jdolecek  * by Steve C. Woodford.
      9  1.2.2.2  jdolecek  *
     10  1.2.2.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     11  1.2.2.2  jdolecek  * modification, are permitted provided that the following conditions
     12  1.2.2.2  jdolecek  * are met:
     13  1.2.2.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14  1.2.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15  1.2.2.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17  1.2.2.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     18  1.2.2.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19  1.2.2.2  jdolecek  *    must display the following acknowledgement:
     20  1.2.2.2  jdolecek  *	This product includes software developed by the NetBSD
     21  1.2.2.2  jdolecek  *	Foundation, Inc. and its contributors.
     22  1.2.2.2  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2.2.2  jdolecek  *    contributors may be used to endorse or promote products derived
     24  1.2.2.2  jdolecek  *    from this software without specific prior written permission.
     25  1.2.2.2  jdolecek  *
     26  1.2.2.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2.2.2  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2.2.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2.2.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2.2.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2.2.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2.2.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2.2.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2.2.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2.2.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2.2.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2.2.2  jdolecek  */
     38  1.2.2.2  jdolecek 
     39  1.2.2.2  jdolecek /*
     40  1.2.2.2  jdolecek  * Copyright (c) 1993, 1994 Charles M. Hannum.
     41  1.2.2.2  jdolecek  * Copyright (c) 1990 William F. Jolitz, TeleMuse
     42  1.2.2.2  jdolecek  * All rights reserved.
     43  1.2.2.2  jdolecek  *
     44  1.2.2.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     45  1.2.2.2  jdolecek  * modification, are permitted provided that the following conditions
     46  1.2.2.2  jdolecek  * are met:
     47  1.2.2.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     48  1.2.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     49  1.2.2.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.2.2.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     51  1.2.2.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     52  1.2.2.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     53  1.2.2.2  jdolecek  *    must display the following acknowledgement:
     54  1.2.2.2  jdolecek  *	This software is a component of "386BSD" developed by
     55  1.2.2.2  jdolecek  *	William F. Jolitz, TeleMuse.
     56  1.2.2.2  jdolecek  * 4. Neither the name of the developer nor the name "386BSD"
     57  1.2.2.2  jdolecek  *    may be used to endorse or promote products derived from this software
     58  1.2.2.2  jdolecek  *    without specific prior written permission.
     59  1.2.2.2  jdolecek  *
     60  1.2.2.2  jdolecek  * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
     61  1.2.2.2  jdolecek  * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
     62  1.2.2.2  jdolecek  * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
     63  1.2.2.2  jdolecek  * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
     64  1.2.2.2  jdolecek  * NOT MAKE USE OF THIS WORK.
     65  1.2.2.2  jdolecek  *
     66  1.2.2.2  jdolecek  * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
     67  1.2.2.2  jdolecek  * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
     68  1.2.2.2  jdolecek  * REFERENCES SUCH AS THE  "PORTING UNIX TO THE 386" SERIES
     69  1.2.2.2  jdolecek  * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
     70  1.2.2.2  jdolecek  * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
     71  1.2.2.2  jdolecek  * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
     72  1.2.2.2  jdolecek  * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
     73  1.2.2.2  jdolecek  * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
     74  1.2.2.2  jdolecek  *
     75  1.2.2.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
     76  1.2.2.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     77  1.2.2.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     78  1.2.2.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
     79  1.2.2.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     80  1.2.2.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     81  1.2.2.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     82  1.2.2.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     83  1.2.2.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     84  1.2.2.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     85  1.2.2.2  jdolecek  * SUCH DAMAGE.
     86  1.2.2.2  jdolecek  */
     87  1.2.2.2  jdolecek 
     88  1.2.2.2  jdolecek /*
     89  1.2.2.2  jdolecek  * Device Driver for an MVME68K/MVME88K board's parallel printer port
     90  1.2.2.2  jdolecek  * This driver attaches above the board-specific back-end.
     91  1.2.2.2  jdolecek  */
     92  1.2.2.2  jdolecek 
     93  1.2.2.2  jdolecek #include <sys/param.h>
     94  1.2.2.2  jdolecek #include <sys/systm.h>
     95  1.2.2.2  jdolecek #include <sys/proc.h>
     96  1.2.2.2  jdolecek #include <sys/user.h>
     97  1.2.2.2  jdolecek #include <sys/buf.h>
     98  1.2.2.2  jdolecek #include <sys/kernel.h>
     99  1.2.2.2  jdolecek #include <sys/ioctl.h>
    100  1.2.2.2  jdolecek #include <sys/uio.h>
    101  1.2.2.2  jdolecek #include <sys/device.h>
    102  1.2.2.2  jdolecek #include <sys/conf.h>
    103  1.2.2.2  jdolecek #include <sys/syslog.h>
    104  1.2.2.2  jdolecek 
    105  1.2.2.2  jdolecek #include <machine/cpu.h>
    106  1.2.2.2  jdolecek #include <machine/bus.h>
    107  1.2.2.2  jdolecek 
    108  1.2.2.2  jdolecek #include <dev/mvme/lptvar.h>
    109  1.2.2.2  jdolecek 
    110  1.2.2.2  jdolecek 
    111  1.2.2.2  jdolecek #define	TIMEOUT		hz*16	/* wait up to 16 seconds for a ready */
    112  1.2.2.2  jdolecek #define	STEP		hz/4
    113  1.2.2.2  jdolecek 
    114  1.2.2.2  jdolecek #define	LPTPRI		(PZERO+8)
    115  1.2.2.2  jdolecek #define	LPT_BSIZE	1024
    116  1.2.2.2  jdolecek 
    117  1.2.2.2  jdolecek #if !defined(DEBUG) || !defined(notdef)
    118  1.2.2.2  jdolecek #define LPRINTF(a)
    119  1.2.2.2  jdolecek #else
    120  1.2.2.2  jdolecek #define LPRINTF		if (lptdebug) printf a
    121  1.2.2.2  jdolecek int lptdebug = 1;
    122  1.2.2.2  jdolecek #endif
    123  1.2.2.2  jdolecek 
    124  1.2.2.2  jdolecek #define	LPTUNIT(s)	(minor(s) & 0x0f)
    125  1.2.2.2  jdolecek #define	LPTFLAGS(s)	(minor(s) & 0xf0)
    126  1.2.2.2  jdolecek 
    127  1.2.2.2  jdolecek static void lpt_wakeup __P((void *arg));
    128  1.2.2.2  jdolecek static int pushbytes __P((struct lpt_softc *));
    129  1.2.2.2  jdolecek 
    130  1.2.2.2  jdolecek extern struct cfdriver lpt_cd;
    131  1.2.2.2  jdolecek 
    132  1.2.2.2  jdolecek dev_type_open(lptopen);
    133  1.2.2.2  jdolecek dev_type_close(lptclose);
    134  1.2.2.2  jdolecek dev_type_write(lptwrite);
    135  1.2.2.2  jdolecek dev_type_ioctl(lptioctl);
    136  1.2.2.2  jdolecek 
    137  1.2.2.2  jdolecek const struct cdevsw lpt_cdevsw = {
    138  1.2.2.2  jdolecek 	lptopen, lptclose, noread, lptwrite, lptioctl,
    139  1.2.2.2  jdolecek 	nostop, notty, nopoll, nommap, nokqfilter,
    140  1.2.2.2  jdolecek };
    141  1.2.2.2  jdolecek 
    142  1.2.2.2  jdolecek void
    143  1.2.2.2  jdolecek lpt_attach_subr(sc)
    144  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    145  1.2.2.2  jdolecek {
    146  1.2.2.2  jdolecek 
    147  1.2.2.2  jdolecek 	sc->sc_state = 0;
    148  1.2.2.2  jdolecek 	callout_init(&sc->sc_wakeup_ch);
    149  1.2.2.2  jdolecek }
    150  1.2.2.2  jdolecek 
    151  1.2.2.2  jdolecek /*
    152  1.2.2.2  jdolecek  * Reset the printer, then wait until it's selected and not busy.
    153  1.2.2.2  jdolecek  */
    154  1.2.2.2  jdolecek int
    155  1.2.2.2  jdolecek lptopen(dev, flag, mode, p)
    156  1.2.2.2  jdolecek 	dev_t dev;
    157  1.2.2.2  jdolecek 	int flag;
    158  1.2.2.2  jdolecek 	int mode;
    159  1.2.2.2  jdolecek 	struct proc *p;
    160  1.2.2.2  jdolecek {
    161  1.2.2.2  jdolecek 	int unit;
    162  1.2.2.2  jdolecek 	u_char flags;
    163  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    164  1.2.2.2  jdolecek 	int error;
    165  1.2.2.2  jdolecek 	int spin;
    166  1.2.2.2  jdolecek 
    167  1.2.2.2  jdolecek 	unit = LPTUNIT(dev);
    168  1.2.2.2  jdolecek 	flags = LPTFLAGS(dev);
    169  1.2.2.2  jdolecek 
    170  1.2.2.2  jdolecek 	if (unit >= lpt_cd.cd_ndevs)
    171  1.2.2.2  jdolecek 		return (ENXIO);
    172  1.2.2.2  jdolecek 	sc = lpt_cd.cd_devs[unit];
    173  1.2.2.2  jdolecek 	if (!sc)
    174  1.2.2.2  jdolecek 		return (ENXIO);
    175  1.2.2.2  jdolecek 
    176  1.2.2.2  jdolecek #ifdef DIAGNOSTIC
    177  1.2.2.2  jdolecek 	if (sc->sc_state)
    178  1.2.2.2  jdolecek 		printf("%s: stat=0x%x not zero\n", sc->sc_dev.dv_xname,
    179  1.2.2.2  jdolecek 		    sc->sc_state);
    180  1.2.2.2  jdolecek #endif
    181  1.2.2.2  jdolecek 
    182  1.2.2.2  jdolecek 	if (sc->sc_state)
    183  1.2.2.2  jdolecek 		return (EBUSY);
    184  1.2.2.2  jdolecek 
    185  1.2.2.2  jdolecek 	sc->sc_state = LPT_INIT;
    186  1.2.2.2  jdolecek 	sc->sc_flags = flags;
    187  1.2.2.2  jdolecek 	LPRINTF(("%s: open: flags=0x%x\n", sc->sc_dev.dv_xname, flags));
    188  1.2.2.2  jdolecek 
    189  1.2.2.2  jdolecek 	if ((flags & LPT_NOPRIME) == 0) {
    190  1.2.2.2  jdolecek 		/* assert Input Prime for 100 usec to start up printer */
    191  1.2.2.2  jdolecek 		(sc->sc_funcs->lf_iprime) (sc);
    192  1.2.2.2  jdolecek 	}
    193  1.2.2.2  jdolecek 
    194  1.2.2.2  jdolecek 	/* select fast or slow strobe depending on minor device number */
    195  1.2.2.2  jdolecek 	if (flags & LPT_FAST_STROBE)
    196  1.2.2.2  jdolecek 		(sc->sc_funcs->lf_speed) (sc, LPT_STROBE_FAST);
    197  1.2.2.2  jdolecek 	else
    198  1.2.2.2  jdolecek 		(sc->sc_funcs->lf_speed) (sc, LPT_STROBE_SLOW);
    199  1.2.2.2  jdolecek 
    200  1.2.2.2  jdolecek 	/* wait till ready (printer running diagnostics) */
    201  1.2.2.2  jdolecek 	for (spin = 0; (sc->sc_funcs->lf_notrdy) (sc, 1); spin += STEP) {
    202  1.2.2.2  jdolecek 		if (spin >= TIMEOUT) {
    203  1.2.2.2  jdolecek 			sc->sc_state = 0;
    204  1.2.2.2  jdolecek 			return (EBUSY);
    205  1.2.2.2  jdolecek 		}
    206  1.2.2.2  jdolecek 		/* wait 1/4 second, give up if we get a signal */
    207  1.2.2.2  jdolecek 		error = tsleep((caddr_t) sc, LPTPRI | PCATCH, "lptopen", STEP);
    208  1.2.2.2  jdolecek 		if (error != EWOULDBLOCK) {
    209  1.2.2.2  jdolecek 			sc->sc_state = 0;
    210  1.2.2.2  jdolecek 			return (error);
    211  1.2.2.2  jdolecek 		}
    212  1.2.2.2  jdolecek 	}
    213  1.2.2.2  jdolecek 
    214  1.2.2.2  jdolecek 	sc->sc_inbuf = geteblk(LPT_BSIZE);
    215  1.2.2.2  jdolecek 	sc->sc_count = 0;
    216  1.2.2.2  jdolecek 	sc->sc_state = LPT_OPEN;
    217  1.2.2.2  jdolecek 
    218  1.2.2.2  jdolecek 	if ((sc->sc_flags & LPT_NOINTR) == 0)
    219  1.2.2.2  jdolecek 		lpt_wakeup(sc);
    220  1.2.2.2  jdolecek 
    221  1.2.2.2  jdolecek 	(sc->sc_funcs->lf_open) (sc, sc->sc_flags & LPT_NOINTR);
    222  1.2.2.2  jdolecek 
    223  1.2.2.2  jdolecek 	LPRINTF(("%s: opened\n", sc->sc_dev.dv_xname));
    224  1.2.2.2  jdolecek 	return (0);
    225  1.2.2.2  jdolecek }
    226  1.2.2.2  jdolecek 
    227  1.2.2.2  jdolecek void
    228  1.2.2.2  jdolecek lpt_wakeup(arg)
    229  1.2.2.2  jdolecek 	void *arg;
    230  1.2.2.2  jdolecek {
    231  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    232  1.2.2.2  jdolecek 	int s;
    233  1.2.2.2  jdolecek 
    234  1.2.2.2  jdolecek 	sc = arg;
    235  1.2.2.2  jdolecek 
    236  1.2.2.2  jdolecek 	s = spltty();
    237  1.2.2.2  jdolecek 	lpt_intr(sc);
    238  1.2.2.2  jdolecek 	splx(s);
    239  1.2.2.2  jdolecek 
    240  1.2.2.2  jdolecek 	callout_reset(&sc->sc_wakeup_ch, STEP, lpt_wakeup, sc);
    241  1.2.2.2  jdolecek }
    242  1.2.2.2  jdolecek 
    243  1.2.2.2  jdolecek /*
    244  1.2.2.2  jdolecek  * Close the device, and free the local line buffer.
    245  1.2.2.2  jdolecek  */
    246  1.2.2.2  jdolecek int
    247  1.2.2.2  jdolecek lptclose(dev, flag, mode, p)
    248  1.2.2.2  jdolecek 	dev_t dev;
    249  1.2.2.2  jdolecek 	int flag;
    250  1.2.2.2  jdolecek 	int mode;
    251  1.2.2.2  jdolecek 	struct proc *p;
    252  1.2.2.2  jdolecek {
    253  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    254  1.2.2.2  jdolecek 	int unit;
    255  1.2.2.2  jdolecek 
    256  1.2.2.2  jdolecek 	unit = LPTUNIT(dev);
    257  1.2.2.2  jdolecek 	sc = lpt_cd.cd_devs[unit];
    258  1.2.2.2  jdolecek 
    259  1.2.2.2  jdolecek 	if (sc->sc_count)
    260  1.2.2.2  jdolecek 		(void) pushbytes(sc);
    261  1.2.2.2  jdolecek 
    262  1.2.2.2  jdolecek 	if ((sc->sc_flags & LPT_NOINTR) == 0)
    263  1.2.2.2  jdolecek 		callout_stop(&sc->sc_wakeup_ch);
    264  1.2.2.2  jdolecek 
    265  1.2.2.2  jdolecek 	(sc->sc_funcs->lf_close) (sc);
    266  1.2.2.2  jdolecek 
    267  1.2.2.2  jdolecek 	sc->sc_state = 0;
    268  1.2.2.2  jdolecek 	brelse(sc->sc_inbuf);
    269  1.2.2.2  jdolecek 
    270  1.2.2.2  jdolecek 	LPRINTF(("%s: closed\n", sc->sc_dev.dv_xname));
    271  1.2.2.2  jdolecek 	return (0);
    272  1.2.2.2  jdolecek }
    273  1.2.2.2  jdolecek 
    274  1.2.2.2  jdolecek int
    275  1.2.2.2  jdolecek pushbytes(sc)
    276  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    277  1.2.2.2  jdolecek {
    278  1.2.2.2  jdolecek 	int s, error, spin, tic;
    279  1.2.2.2  jdolecek 
    280  1.2.2.2  jdolecek 	if (sc->sc_flags & LPT_NOINTR) {
    281  1.2.2.2  jdolecek 		while (sc->sc_count > 0) {
    282  1.2.2.2  jdolecek 			spin = 0;
    283  1.2.2.2  jdolecek 			while ((sc->sc_funcs->lf_notrdy) (sc, 0)) {
    284  1.2.2.2  jdolecek 				if (++spin < sc->sc_spinmax)
    285  1.2.2.2  jdolecek 					continue;
    286  1.2.2.2  jdolecek 				tic = 0;
    287  1.2.2.2  jdolecek 				/* adapt busy-wait algorithm */
    288  1.2.2.2  jdolecek 				sc->sc_spinmax++;
    289  1.2.2.2  jdolecek 				while ((sc->sc_funcs->lf_notrdy) (sc, 1)) {
    290  1.2.2.2  jdolecek 					/* exponential backoff */
    291  1.2.2.2  jdolecek 					tic = tic + tic + 1;
    292  1.2.2.2  jdolecek 					if (tic > TIMEOUT)
    293  1.2.2.2  jdolecek 						tic = TIMEOUT;
    294  1.2.2.2  jdolecek 					error = tsleep((caddr_t) sc,
    295  1.2.2.2  jdolecek 					    LPTPRI | PCATCH, "lptpsh", tic);
    296  1.2.2.2  jdolecek 					if (error != EWOULDBLOCK)
    297  1.2.2.2  jdolecek 						return (error);
    298  1.2.2.2  jdolecek 				}
    299  1.2.2.2  jdolecek 				break;
    300  1.2.2.2  jdolecek 			}
    301  1.2.2.2  jdolecek 
    302  1.2.2.2  jdolecek 			(sc->sc_funcs->lf_wrdata) (sc, *sc->sc_cp++);
    303  1.2.2.2  jdolecek 			sc->sc_count--;
    304  1.2.2.2  jdolecek 
    305  1.2.2.2  jdolecek 			/* adapt busy-wait algorithm */
    306  1.2.2.2  jdolecek 			if (spin * 2 + 16 < sc->sc_spinmax)
    307  1.2.2.2  jdolecek 				sc->sc_spinmax--;
    308  1.2.2.2  jdolecek 		}
    309  1.2.2.2  jdolecek 	} else {
    310  1.2.2.2  jdolecek 		while (sc->sc_count > 0) {
    311  1.2.2.2  jdolecek 			/* if the printer is ready for a char, give it one */
    312  1.2.2.2  jdolecek 			if ((sc->sc_state & LPT_OBUSY) == 0) {
    313  1.2.2.2  jdolecek 				LPRINTF(("%s: write %d\n", sc->sc_dev.dv_xname,
    314  1.2.2.2  jdolecek 					sc->sc_count));
    315  1.2.2.2  jdolecek 				s = spltty();
    316  1.2.2.2  jdolecek 				(void) lpt_intr(sc);
    317  1.2.2.2  jdolecek 				splx(s);
    318  1.2.2.2  jdolecek 			}
    319  1.2.2.2  jdolecek 			error = tsleep((caddr_t) sc, LPTPRI | PCATCH,
    320  1.2.2.2  jdolecek 			    "lptwrite2", 0);
    321  1.2.2.2  jdolecek 			if (error)
    322  1.2.2.2  jdolecek 				return (error);
    323  1.2.2.2  jdolecek 		}
    324  1.2.2.2  jdolecek 	}
    325  1.2.2.2  jdolecek 	return (0);
    326  1.2.2.2  jdolecek }
    327  1.2.2.2  jdolecek 
    328  1.2.2.2  jdolecek /*
    329  1.2.2.2  jdolecek  * Copy a line from user space to a local buffer, then call putc to get the
    330  1.2.2.2  jdolecek  * chars moved to the output queue.
    331  1.2.2.2  jdolecek  */
    332  1.2.2.2  jdolecek int
    333  1.2.2.2  jdolecek lptwrite(dev, uio, flags)
    334  1.2.2.2  jdolecek 	dev_t dev;
    335  1.2.2.2  jdolecek 	struct uio *uio;
    336  1.2.2.2  jdolecek 	int flags;
    337  1.2.2.2  jdolecek {
    338  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    339  1.2.2.2  jdolecek 	size_t n;
    340  1.2.2.2  jdolecek 	int error;
    341  1.2.2.2  jdolecek 
    342  1.2.2.2  jdolecek 	sc = lpt_cd.cd_devs[LPTUNIT(dev)];
    343  1.2.2.2  jdolecek 	error = 0;
    344  1.2.2.2  jdolecek 
    345  1.2.2.2  jdolecek 	while ((n = min(LPT_BSIZE, uio->uio_resid)) != 0) {
    346  1.2.2.2  jdolecek 		uiomove(sc->sc_cp = sc->sc_inbuf->b_data, n, uio);
    347  1.2.2.2  jdolecek 		sc->sc_count = n;
    348  1.2.2.2  jdolecek 		error = pushbytes(sc);
    349  1.2.2.2  jdolecek 		if (error) {
    350  1.2.2.2  jdolecek 			/*
    351  1.2.2.2  jdolecek 			 * Return accurate residual if interrupted or timed
    352  1.2.2.2  jdolecek 			 * out.
    353  1.2.2.2  jdolecek 			 */
    354  1.2.2.2  jdolecek 			uio->uio_resid += sc->sc_count;
    355  1.2.2.2  jdolecek 			sc->sc_count = 0;
    356  1.2.2.2  jdolecek 			return (error);
    357  1.2.2.2  jdolecek 		}
    358  1.2.2.2  jdolecek 	}
    359  1.2.2.2  jdolecek 	return (0);
    360  1.2.2.2  jdolecek }
    361  1.2.2.2  jdolecek 
    362  1.2.2.2  jdolecek /*
    363  1.2.2.2  jdolecek  * Handle printer interrupts which occur when the printer is ready to accept
    364  1.2.2.2  jdolecek  * another char.
    365  1.2.2.2  jdolecek  */
    366  1.2.2.2  jdolecek int
    367  1.2.2.2  jdolecek lpt_intr(sc)
    368  1.2.2.2  jdolecek 	struct lpt_softc *sc;
    369  1.2.2.2  jdolecek {
    370  1.2.2.2  jdolecek 
    371  1.2.2.2  jdolecek 	if (sc->sc_count) {
    372  1.2.2.2  jdolecek 		/* send char */
    373  1.2.2.2  jdolecek 		(sc->sc_funcs->lf_wrdata) (sc, *sc->sc_cp++);
    374  1.2.2.2  jdolecek 		sc->sc_count--;
    375  1.2.2.2  jdolecek 		sc->sc_state |= LPT_OBUSY;
    376  1.2.2.2  jdolecek 	} else
    377  1.2.2.2  jdolecek 		sc->sc_state &= ~LPT_OBUSY;
    378  1.2.2.2  jdolecek 
    379  1.2.2.2  jdolecek 	if (sc->sc_count == 0) {
    380  1.2.2.2  jdolecek 		/* none, wake up the top half to get more */
    381  1.2.2.2  jdolecek 		wakeup((caddr_t) sc);
    382  1.2.2.2  jdolecek 	}
    383  1.2.2.2  jdolecek 
    384  1.2.2.2  jdolecek 	return (1);
    385  1.2.2.2  jdolecek }
    386  1.2.2.2  jdolecek 
    387  1.2.2.2  jdolecek /* ARGSUSED */
    388  1.2.2.2  jdolecek int
    389  1.2.2.2  jdolecek lptioctl(dev, cmd, data, flag, p)
    390  1.2.2.2  jdolecek 	dev_t dev;
    391  1.2.2.2  jdolecek 	u_long cmd;
    392  1.2.2.2  jdolecek 	caddr_t data;
    393  1.2.2.2  jdolecek 	int flag;
    394  1.2.2.2  jdolecek 	struct proc *p;
    395  1.2.2.2  jdolecek {
    396  1.2.2.2  jdolecek 
    397  1.2.2.2  jdolecek 	return (ENODEV);
    398  1.2.2.2  jdolecek }
    399