Home | History | Annotate | Line # | Download | only in dev
par.c revision 1.23.4.1
      1  1.23.4.1  jdolecek /*	$NetBSD: par.c,v 1.23.4.1 2002/02/11 20:07:04 jdolecek Exp $ */
      2       1.9       cgd 
      3       1.1        mw /*
      4       1.1        mw  * Copyright (c) 1982, 1990 The Regents of the University of California.
      5       1.1        mw  * All rights reserved.
      6       1.1        mw  *
      7       1.1        mw  * Redistribution and use in source and binary forms, with or without
      8       1.1        mw  * modification, are permitted provided that the following conditions
      9       1.1        mw  * are met:
     10       1.1        mw  * 1. Redistributions of source code must retain the above copyright
     11       1.1        mw  *    notice, this list of conditions and the following disclaimer.
     12       1.1        mw  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1        mw  *    notice, this list of conditions and the following disclaimer in the
     14       1.1        mw  *    documentation and/or other materials provided with the distribution.
     15       1.1        mw  * 3. All advertising materials mentioning features or use of this software
     16       1.1        mw  *    must display the following acknowledgement:
     17       1.1        mw  *	This product includes software developed by the University of
     18       1.1        mw  *	California, Berkeley and its contributors.
     19       1.1        mw  * 4. Neither the name of the University nor the names of its contributors
     20       1.1        mw  *    may be used to endorse or promote products derived from this software
     21       1.1        mw  *    without specific prior written permission.
     22       1.1        mw  *
     23       1.1        mw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24       1.1        mw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25       1.1        mw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26       1.1        mw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27       1.1        mw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28       1.1        mw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29       1.1        mw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30       1.1        mw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31       1.1        mw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32       1.1        mw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33       1.1        mw  * SUCH DAMAGE.
     34       1.1        mw  *
     35      1.10       cgd  *	@(#)ppi.c	7.3 (Berkeley) 12/16/90
     36       1.1        mw  */
     37       1.1        mw 
     38  1.23.4.1  jdolecek #include <sys/cdefs.h>
     39  1.23.4.1  jdolecek __KERNEL_RCSID(0, "$NetBSD: par.c,v 1.23.4.1 2002/02/11 20:07:04 jdolecek Exp $");
     40  1.23.4.1  jdolecek 
     41       1.1        mw /*
     42       1.1        mw  * parallel port interface
     43       1.1        mw  */
     44       1.1        mw 
     45       1.2        mw #include "par.h"
     46       1.1        mw #if NPAR > 0
     47       1.1        mw 
     48       1.6    chopps #include <sys/param.h>
     49       1.6    chopps #include <sys/errno.h>
     50       1.6    chopps #include <sys/uio.h>
     51       1.7    chopps #include <sys/device.h>
     52       1.6    chopps #include <sys/malloc.h>
     53       1.6    chopps #include <sys/file.h>
     54       1.6    chopps #include <sys/systm.h>
     55      1.20   thorpej #include <sys/callout.h>
     56      1.13     veego #include <sys/proc.h>
     57       1.1        mw 
     58       1.7    chopps #include <amiga/amiga/device.h>
     59       1.7    chopps #include <amiga/amiga/cia.h>
     60       1.6    chopps #include <amiga/dev/parioctl.h>
     61       1.1        mw 
     62      1.13     veego #include <sys/conf.h>
     63      1.13     veego #include <machine/conf.h>
     64       1.1        mw 
     65       1.1        mw struct	par_softc {
     66      1.21   frueauf 	struct device sc_dev;
     67      1.21   frueauf 
     68       1.1        mw 	int	sc_flags;
     69       1.1        mw 	struct	parparam sc_param;
     70       1.1        mw #define sc_burst sc_param.burst
     71       1.1        mw #define sc_timo  sc_param.timo
     72       1.1        mw #define sc_delay sc_param.delay
     73      1.20   thorpej 
     74      1.20   thorpej 	struct callout sc_timo_ch;
     75      1.20   thorpej 	struct callout sc_start_ch;
     76       1.7    chopps } *par_softcp;
     77       1.7    chopps 
     78       1.7    chopps #define getparsp(x)	(x > 0 ? NULL : par_softcp)
     79       1.1        mw 
     80       1.1        mw /* sc_flags values */
     81  1.23.4.1  jdolecek #define	PARF_ALIVE	0x01
     82  1.23.4.1  jdolecek #define	PARF_OPEN	0x02
     83       1.1        mw #define PARF_UIO	0x04
     84       1.1        mw #define PARF_TIMO	0x08
     85       1.1        mw #define PARF_DELAY	0x10
     86       1.1        mw #define PARF_OREAD	0x40
     87       1.1        mw #define PARF_OWRITE	0x80
     88       1.1        mw 
     89       1.1        mw #define UNIT(x)		minor(x)
     90       1.1        mw 
     91       1.1        mw #ifdef DEBUG
     92       1.2        mw int	pardebug = 0;
     93       1.1        mw #define PDB_FOLLOW	0x01
     94       1.1        mw #define PDB_IO		0x02
     95       1.2        mw #define PDB_INTERRUPT   0x04
     96       1.1        mw #define PDB_NOCHECK	0x80
     97       1.1        mw #endif
     98       1.1        mw 
     99  1.23.4.1  jdolecek int parrw(dev_t, struct uio *);
    100  1.23.4.1  jdolecek int parhztoms(int);
    101  1.23.4.1  jdolecek int parmstohz(int);
    102  1.23.4.1  jdolecek int parsend(u_char *, int);
    103  1.23.4.1  jdolecek int parreceive(u_char *, int);
    104  1.23.4.1  jdolecek int parsendch(u_char);
    105  1.23.4.1  jdolecek 
    106  1.23.4.1  jdolecek void partimo(void *);
    107  1.23.4.1  jdolecek void parstart(void *);
    108  1.23.4.1  jdolecek void parintr(void *);
    109       1.7    chopps 
    110  1.23.4.1  jdolecek void parattach(struct device *, struct device *, void *);
    111  1.23.4.1  jdolecek int parmatch(struct device *, struct cfdata *, void *);
    112       1.7    chopps 
    113      1.12   thorpej struct cfattach par_ca = {
    114      1.22    mhitch 	sizeof(struct par_softc), parmatch, parattach
    115      1.12   thorpej };
    116       1.7    chopps 
    117       1.7    chopps /*ARGSUSED*/
    118       1.7    chopps int
    119  1.23.4.1  jdolecek parmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
    120       1.7    chopps {
    121      1.19    kleink 	static int par_found = 0;
    122      1.12   thorpej 
    123      1.19    kleink 	if (!matchname((char *)auxp, "par") || par_found)
    124      1.19    kleink 		return(0);
    125      1.19    kleink 
    126      1.19    kleink 	par_found = 1;
    127      1.19    kleink 	return(1);
    128       1.7    chopps }
    129       1.7    chopps 
    130       1.7    chopps void
    131  1.23.4.1  jdolecek parattach(struct device *pdp, struct device *dp, void *auxp)
    132       1.1        mw {
    133       1.7    chopps 	par_softcp = (struct par_softc *)dp;
    134       1.1        mw 
    135       1.1        mw #ifdef DEBUG
    136       1.7    chopps 	if ((pardebug & PDB_NOCHECK) == 0)
    137       1.1        mw #endif
    138       1.7    chopps 		par_softcp->sc_flags = PARF_ALIVE;
    139      1.15  christos 	printf("\n");
    140      1.20   thorpej 
    141      1.20   thorpej 	callout_init(&par_softcp->sc_timo_ch);
    142      1.20   thorpej 	callout_init(&par_softcp->sc_start_ch);
    143       1.1        mw }
    144       1.1        mw 
    145      1.13     veego int
    146  1.23.4.1  jdolecek paropen(dev_t dev, int flags, int mode, struct proc *p)
    147       1.1        mw {
    148       1.7    chopps 	int unit = UNIT(dev);
    149       1.7    chopps 	struct par_softc *sc = getparsp(unit);
    150  1.23.4.1  jdolecek 
    151       1.7    chopps 	if (unit >= NPAR || (sc->sc_flags & PARF_ALIVE) == 0)
    152       1.7    chopps 		return(ENXIO);
    153       1.1        mw #ifdef DEBUG
    154       1.7    chopps 	if (pardebug & PDB_FOLLOW) {
    155      1.15  christos 		printf("paropen(%x, %x): flags %x, ",
    156       1.7    chopps 		    dev, flags, sc->sc_flags);
    157      1.15  christos 		printf ("port = $%x\n", ((ciab.pra ^ CIAB_PRA_SEL)
    158       1.7    chopps 		    & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
    159       1.7    chopps 	}
    160       1.1        mw #endif
    161       1.7    chopps 	if (sc->sc_flags & PARF_OPEN)
    162       1.7    chopps 		return(EBUSY);
    163       1.7    chopps 	/* can either read or write, but not both */
    164       1.7    chopps 	if ((flags & (FREAD|FWRITE)) == (FREAD|FWRITE))
    165       1.7    chopps 		return EINVAL;
    166  1.23.4.1  jdolecek 
    167       1.7    chopps 	sc->sc_flags |= PARF_OPEN;
    168       1.7    chopps 
    169       1.7    chopps 	if (flags & FREAD)
    170       1.7    chopps 		sc->sc_flags |= PARF_OREAD;
    171       1.7    chopps 	else
    172       1.7    chopps 		sc->sc_flags |= PARF_OWRITE;
    173       1.7    chopps 
    174       1.7    chopps 	sc->sc_burst = PAR_BURST;
    175       1.7    chopps 	sc->sc_timo = parmstohz(PAR_TIMO);
    176       1.7    chopps 	sc->sc_delay = parmstohz(PAR_DELAY);
    177       1.7    chopps 	/* enable interrupts for CIAA-FLG */
    178       1.7    chopps 	ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_FLG;
    179       1.7    chopps 	return(0);
    180       1.1        mw }
    181       1.1        mw 
    182      1.13     veego int
    183  1.23.4.1  jdolecek parclose(dev_t dev, int flags, int mode, struct proc *p)
    184       1.1        mw {
    185       1.7    chopps   int unit = UNIT(dev);
    186       1.7    chopps   struct par_softc *sc = getparsp(unit);
    187       1.1        mw 
    188       1.1        mw #ifdef DEBUG
    189       1.1        mw   if (pardebug & PDB_FOLLOW)
    190      1.15  christos     printf("parclose(%x, %x): flags %x\n",
    191       1.1        mw 	   dev, flags, sc->sc_flags);
    192       1.1        mw #endif
    193       1.1        mw   sc->sc_flags &= ~(PARF_OPEN|PARF_OREAD|PARF_OWRITE);
    194       1.1        mw   /* don't allow interrupts for CIAA-FLG any longer */
    195       1.1        mw   ciaa.icr = CIA_ICR_FLG;
    196       1.1        mw   return(0);
    197       1.1        mw }
    198       1.1        mw 
    199       1.7    chopps void
    200  1.23.4.1  jdolecek parstart(void *arg)
    201       1.1        mw {
    202      1.20   thorpej 	struct par_softc *sc = arg;
    203       1.7    chopps 
    204       1.1        mw #ifdef DEBUG
    205       1.7    chopps 	if (pardebug & PDB_FOLLOW)
    206      1.20   thorpej 		printf("parstart(%x)\n", sc->sc_dev.dv_unit);
    207       1.1        mw #endif
    208       1.7    chopps 	sc->sc_flags &= ~PARF_DELAY;
    209       1.7    chopps 	wakeup(sc);
    210       1.1        mw }
    211       1.1        mw 
    212       1.7    chopps void
    213  1.23.4.1  jdolecek partimo(void *arg)
    214       1.1        mw {
    215      1.20   thorpej 	struct par_softc *sc = arg;
    216       1.7    chopps 
    217       1.1        mw #ifdef DEBUG
    218       1.7    chopps 	if (pardebug & PDB_FOLLOW)
    219      1.20   thorpej 		printf("partimo(%x)\n", sc->sc_dev.dv_unit);
    220       1.1        mw #endif
    221       1.7    chopps 	sc->sc_flags &= ~(PARF_UIO|PARF_TIMO);
    222       1.7    chopps 	wakeup(sc);
    223       1.1        mw }
    224       1.1        mw 
    225      1.13     veego int
    226  1.23.4.1  jdolecek parread(dev_t dev, struct uio *uio, int flags)
    227       1.1        mw {
    228       1.1        mw 
    229       1.1        mw #ifdef DEBUG
    230      1.13     veego 	if (pardebug & PDB_FOLLOW)
    231      1.15  christos 		printf("parread(%x, %p)\n", dev, uio);
    232       1.1        mw #endif
    233      1.13     veego 	return (parrw(dev, uio));
    234       1.1        mw }
    235       1.1        mw 
    236      1.13     veego 
    237      1.13     veego int
    238  1.23.4.1  jdolecek parwrite(dev_t dev, struct uio *uio, int flags)
    239       1.1        mw {
    240       1.1        mw 
    241       1.1        mw #ifdef DEBUG
    242      1.13     veego 	if (pardebug & PDB_FOLLOW)
    243      1.15  christos 		printf("parwrite(%x, %p)\n", dev, uio);
    244       1.1        mw #endif
    245      1.13     veego 	return (parrw(dev, uio));
    246       1.1        mw }
    247       1.1        mw 
    248      1.13     veego 
    249      1.13     veego int
    250  1.23.4.1  jdolecek parrw(dev_t dev, register struct uio *uio)
    251       1.1        mw {
    252       1.1        mw   int unit = UNIT(dev);
    253       1.7    chopps   register struct par_softc *sc = getparsp(unit);
    254       1.1        mw   register int s, len, cnt;
    255       1.1        mw   register char *cp;
    256       1.1        mw   int error = 0, gotdata = 0;
    257       1.1        mw   int buflen;
    258       1.1        mw   char *buf;
    259       1.1        mw 
    260      1.13     veego   len = 0;
    261      1.13     veego   cnt = 0;
    262       1.2        mw   if (!!(sc->sc_flags & PARF_OREAD) ^ (uio->uio_rw == UIO_READ))
    263       1.1        mw     return EINVAL;
    264       1.1        mw 
    265       1.1        mw   if (uio->uio_resid == 0)
    266       1.1        mw     return(0);
    267       1.1        mw 
    268       1.1        mw #ifdef DEBUG
    269       1.1        mw   if (pardebug & (PDB_FOLLOW|PDB_IO))
    270      1.15  christos     printf("parrw(%x, %p, %c): burst %d, timo %d, resid %x\n",
    271       1.1        mw 	   dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
    272       1.1        mw 	   sc->sc_burst, sc->sc_timo, uio->uio_resid);
    273       1.1        mw #endif
    274       1.8    chopps   buflen = min(sc->sc_burst, uio->uio_resid);
    275       1.1        mw   buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
    276       1.1        mw   sc->sc_flags |= PARF_UIO;
    277  1.23.4.1  jdolecek   if (sc->sc_timo > 0)
    278       1.2        mw     {
    279       1.2        mw       sc->sc_flags |= PARF_TIMO;
    280      1.20   thorpej       callout_reset(&sc->sc_timo_ch, sc->sc_timo, partimo, sc);
    281       1.1        mw     }
    282  1.23.4.1  jdolecek   while (uio->uio_resid > 0)
    283       1.2        mw     {
    284       1.8    chopps       len = min(buflen, uio->uio_resid);
    285       1.2        mw       cp = buf;
    286  1.23.4.1  jdolecek       if (uio->uio_rw == UIO_WRITE)
    287       1.2        mw 	{
    288       1.2        mw 	  error = uiomove(cp, len, uio);
    289       1.2        mw 	  if (error)
    290       1.2        mw 	    break;
    291       1.2        mw 	}
    292       1.2        mw again:
    293       1.2        mw       s = splbio();
    294       1.2        mw #if 0
    295       1.2        mw       if ((sc->sc_flags & PARF_UIO) && hpibreq(&sc->sc_dq) == 0)
    296       1.2        mw 	sleep(sc, PRIBIO+1);
    297       1.2        mw #endif
    298       1.2        mw       /*
    299       1.2        mw        * Check if we timed out during sleep or uiomove
    300       1.2        mw        */
    301      1.18   thorpej       (void) spllowersoftclock();
    302  1.23.4.1  jdolecek       if ((sc->sc_flags & PARF_UIO) == 0)
    303       1.2        mw 	{
    304       1.2        mw #ifdef DEBUG
    305       1.2        mw 	  if (pardebug & PDB_IO)
    306      1.15  christos 	    printf("parrw: uiomove/sleep timo, flags %x\n",
    307       1.2        mw 		   sc->sc_flags);
    308       1.2        mw #endif
    309  1.23.4.1  jdolecek 	  if (sc->sc_flags & PARF_TIMO)
    310       1.2        mw 	    {
    311      1.20   thorpej 	      callout_stop(&sc->sc_timo_ch);
    312       1.2        mw 	      sc->sc_flags &= ~PARF_TIMO;
    313       1.2        mw 	    }
    314       1.2        mw 	  splx(s);
    315       1.2        mw 	  break;
    316       1.2        mw 	}
    317       1.2        mw       splx(s);
    318       1.2        mw       /*
    319       1.2        mw        * Perform the operation
    320       1.2        mw        */
    321       1.2        mw       if (uio->uio_rw == UIO_WRITE)
    322       1.2        mw 	cnt = parsend (cp, len);
    323       1.2        mw       else
    324       1.2        mw 	cnt = parreceive (cp, len);
    325  1.23.4.1  jdolecek 
    326       1.2        mw       if (cnt < 0)
    327       1.2        mw 	{
    328       1.2        mw 	  error = -cnt;
    329       1.2        mw 	  break;
    330       1.2        mw 	}
    331  1.23.4.1  jdolecek 
    332       1.2        mw       s = splbio();
    333       1.1        mw #if 0
    334       1.2        mw       hpibfree(&sc->sc_dq);
    335       1.1        mw #endif
    336       1.1        mw #ifdef DEBUG
    337       1.1        mw       if (pardebug & PDB_IO)
    338      1.15  christos 	printf("parrw: %s(%p, %d) -> %d\n",
    339       1.2        mw 	       uio->uio_rw == UIO_READ ? "recv" : "send", cp, len, cnt);
    340       1.1        mw #endif
    341       1.1        mw       splx(s);
    342  1.23.4.1  jdolecek       if (uio->uio_rw == UIO_READ)
    343       1.2        mw 	{
    344  1.23.4.1  jdolecek 	  if (cnt)
    345       1.2        mw 	    {
    346       1.2        mw 	      error = uiomove(cp, cnt, uio);
    347       1.2        mw 	      if (error)
    348       1.2        mw 		break;
    349       1.2        mw 	      gotdata++;
    350       1.2        mw 	    }
    351       1.2        mw 	  /*
    352       1.2        mw 	   * Didn't get anything this time, but did in the past.
    353       1.2        mw 	   * Consider us done.
    354       1.2        mw 	   */
    355       1.2        mw 	  else if (gotdata)
    356       1.2        mw 	    break;
    357       1.2        mw 	}
    358       1.2        mw       s = splsoftclock();
    359       1.1        mw       /*
    360       1.2        mw        * Operation timeout (or non-blocking), quit now.
    361       1.1        mw        */
    362  1.23.4.1  jdolecek       if ((sc->sc_flags & PARF_UIO) == 0)
    363       1.2        mw 	{
    364       1.1        mw #ifdef DEBUG
    365       1.2        mw 	  if (pardebug & PDB_IO)
    366      1.15  christos 	    printf("parrw: timeout/done\n");
    367       1.1        mw #endif
    368       1.2        mw 	  splx(s);
    369       1.2        mw 	  break;
    370       1.2        mw 	}
    371       1.2        mw       /*
    372       1.2        mw        * Implement inter-read delay
    373       1.2        mw        */
    374  1.23.4.1  jdolecek       if (sc->sc_delay > 0)
    375       1.2        mw 	{
    376       1.2        mw 	  sc->sc_flags |= PARF_DELAY;
    377      1.20   thorpej 	  callout_reset(&sc->sc_start_ch, sc->sc_delay, parstart, sc);
    378      1.13     veego 	  error = tsleep(sc, PCATCH | (PZERO - 1), "par-cdelay", 0);
    379  1.23.4.1  jdolecek 	  if (error)
    380       1.2        mw 	    {
    381       1.2        mw 	      splx(s);
    382       1.2        mw 	      break;
    383       1.2        mw 	    }
    384       1.2        mw 	}
    385       1.1        mw       splx(s);
    386       1.2        mw       /*
    387       1.2        mw        * Must not call uiomove again til we've used all data
    388       1.2        mw        * that we already grabbed.
    389       1.2        mw        */
    390  1.23.4.1  jdolecek       if (uio->uio_rw == UIO_WRITE && cnt != len)
    391       1.2        mw 	{
    392       1.2        mw 	  cp += cnt;
    393       1.2        mw 	  len -= cnt;
    394       1.2        mw 	  cnt = 0;
    395       1.2        mw 	  goto again;
    396       1.2        mw 	}
    397       1.1        mw     }
    398       1.2        mw   s = splsoftclock();
    399  1.23.4.1  jdolecek   if (sc->sc_flags & PARF_TIMO)
    400       1.2        mw     {
    401      1.20   thorpej       callout_stop(&sc->sc_timo_ch);
    402       1.2        mw       sc->sc_flags &= ~PARF_TIMO;
    403       1.1        mw     }
    404  1.23.4.1  jdolecek   if (sc->sc_flags & PARF_DELAY)
    405       1.2        mw     {
    406      1.20   thorpej       callout_stop(&sc->sc_start_ch);
    407       1.2        mw       sc->sc_flags &= ~PARF_DELAY;
    408       1.1        mw     }
    409       1.1        mw   splx(s);
    410       1.1        mw   /*
    411       1.1        mw    * Adjust for those chars that we uiomove'ed but never wrote
    412       1.1        mw    */
    413  1.23.4.1  jdolecek   if (uio->uio_rw == UIO_WRITE && cnt != len)
    414       1.2        mw     {
    415       1.2        mw       uio->uio_resid += (len - cnt);
    416       1.1        mw #ifdef DEBUG
    417       1.2        mw       if (pardebug & PDB_IO)
    418      1.15  christos 	printf("parrw: short write, adjust by %d\n",
    419       1.2        mw 	       len-cnt);
    420       1.1        mw #endif
    421       1.2        mw     }
    422       1.1        mw   free(buf, M_DEVBUF);
    423       1.1        mw #ifdef DEBUG
    424       1.1        mw   if (pardebug & (PDB_FOLLOW|PDB_IO))
    425      1.15  christos     printf("parrw: return %d, resid %d\n", error, uio->uio_resid);
    426       1.1        mw #endif
    427       1.1        mw   return (error);
    428       1.1        mw }
    429       1.1        mw 
    430       1.2        mw int
    431  1.23.4.1  jdolecek parioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
    432       1.1        mw {
    433       1.7    chopps   struct par_softc *sc = getparsp(UNIT(dev));
    434       1.1        mw   struct parparam *pp, *upp;
    435       1.1        mw   int error = 0;
    436       1.1        mw 
    437  1.23.4.1  jdolecek   switch (cmd)
    438       1.2        mw     {
    439       1.2        mw     case PARIOCGPARAM:
    440       1.2        mw       pp = &sc->sc_param;
    441       1.2        mw       upp = (struct parparam *)data;
    442       1.2        mw       upp->burst = pp->burst;
    443       1.2        mw       upp->timo = parhztoms(pp->timo);
    444       1.2        mw       upp->delay = parhztoms(pp->delay);
    445       1.2        mw       break;
    446       1.2        mw 
    447       1.2        mw     case PARIOCSPARAM:
    448       1.2        mw       pp = &sc->sc_param;
    449       1.2        mw       upp = (struct parparam *)data;
    450       1.2        mw       if (upp->burst < PAR_BURST_MIN || upp->burst > PAR_BURST_MAX ||
    451       1.2        mw 	  upp->delay < PAR_DELAY_MIN || upp->delay > PAR_DELAY_MAX)
    452       1.2        mw 	return(EINVAL);
    453       1.2        mw       pp->burst = upp->burst;
    454       1.2        mw       pp->timo = parmstohz(upp->timo);
    455       1.2        mw       pp->delay = parmstohz(upp->delay);
    456       1.2        mw       break;
    457       1.2        mw 
    458       1.2        mw     default:
    459       1.1        mw       return(EINVAL);
    460       1.2        mw     }
    461       1.1        mw   return (error);
    462       1.1        mw }
    463       1.1        mw 
    464       1.2        mw int
    465  1.23.4.1  jdolecek parhztoms(int h)
    466       1.1        mw {
    467       1.1        mw   extern int hz;
    468       1.1        mw   register int m = h;
    469       1.1        mw 
    470       1.1        mw   if (m > 0)
    471       1.1        mw     m = m * 1000 / hz;
    472       1.1        mw   return(m);
    473       1.1        mw }
    474       1.1        mw 
    475       1.2        mw int
    476  1.23.4.1  jdolecek parmstohz(int m)
    477       1.1        mw {
    478       1.1        mw   extern int hz;
    479       1.1        mw   register int h = m;
    480       1.1        mw 
    481       1.1        mw   if (h > 0) {
    482       1.1        mw     h = h * hz / 1000;
    483       1.1        mw     if (h == 0)
    484       1.1        mw       h = 1000 / hz;
    485       1.1        mw   }
    486       1.1        mw   return(h);
    487       1.1        mw }
    488       1.1        mw 
    489       1.2        mw /* stuff below here if for interrupt driven output of data thru
    490       1.2        mw    the parallel port. */
    491       1.2        mw 
    492       1.2        mw int parsend_pending;
    493       1.2        mw 
    494       1.1        mw void
    495  1.23.4.1  jdolecek parintr(void *arg)
    496       1.1        mw {
    497      1.23        is 	int s;
    498       1.7    chopps 
    499       1.7    chopps 	s = splclock();
    500       1.7    chopps 
    501       1.2        mw #ifdef DEBUG
    502       1.7    chopps 	if (pardebug & PDB_INTERRUPT)
    503      1.23        is 		printf("parintr\n");
    504       1.7    chopps #endif
    505      1.23        is 	parsend_pending = 0;
    506  1.23.4.1  jdolecek 
    507       1.7    chopps 	wakeup(parintr);
    508       1.7    chopps 	splx(s);
    509       1.2        mw }
    510       1.2        mw 
    511       1.2        mw int
    512  1.23.4.1  jdolecek parsendch (u_char ch)
    513       1.2        mw {
    514       1.2        mw   int error = 0;
    515       1.2        mw   int s;
    516       1.2        mw 
    517       1.2        mw   /* if either offline, busy or out of paper, wait for that
    518       1.2        mw      condition to clear */
    519       1.2        mw   s = splclock();
    520  1.23.4.1  jdolecek   while (!error
    521  1.23.4.1  jdolecek 	 && (parsend_pending
    522       1.2        mw 	     || ((ciab.pra ^ CIAB_PRA_SEL)
    523       1.2        mw 		 & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT))))
    524       1.2        mw     {
    525       1.2        mw       extern int hz;
    526       1.2        mw 
    527       1.2        mw #ifdef DEBUG
    528       1.2        mw       if (pardebug & PDB_INTERRUPT)
    529      1.15  christos 	printf ("parsendch, port = $%x\n",
    530       1.2        mw 		((ciab.pra ^ CIAB_PRA_SEL)
    531       1.2        mw 		 & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
    532       1.2        mw #endif
    533       1.2        mw       /* this is essentially a flipflop to have us wait for the
    534       1.2        mw 	 first character being transmitted when trying to transmit
    535       1.2        mw 	 the second, etc. */
    536       1.2        mw       parsend_pending = 0;
    537       1.2        mw       /* it's quite important that a parallel putc can be
    538       1.2        mw 	 interrupted, given the possibility to lock a printer
    539       1.2        mw 	 in an offline condition.. */
    540      1.23        is       error = tsleep(parintr, PCATCH | (PZERO - 1), "parsendch", hz);
    541      1.23        is       if (error == EWOULDBLOCK)
    542      1.23        is 	error = 0;
    543      1.23        is       if (error > 0)
    544       1.2        mw 	{
    545       1.2        mw #ifdef DEBUG
    546       1.2        mw 	  if (pardebug & PDB_INTERRUPT)
    547      1.15  christos 	    printf ("parsendch interrupted, error = %d\n", error);
    548       1.2        mw #endif
    549       1.2        mw 	}
    550       1.2        mw     }
    551       1.2        mw 
    552       1.2        mw   if (! error)
    553       1.2        mw     {
    554       1.2        mw #ifdef DEBUG
    555       1.2        mw       if (pardebug & PDB_INTERRUPT)
    556      1.15  christos 	printf ("#%d", ch);
    557       1.2        mw #endif
    558       1.2        mw       ciaa.prb = ch;
    559       1.2        mw       parsend_pending = 1;
    560       1.2        mw     }
    561       1.2        mw 
    562       1.2        mw   splx (s);
    563       1.2        mw 
    564       1.2        mw   return error;
    565       1.1        mw }
    566       1.1        mw 
    567       1.2        mw 
    568       1.1        mw int
    569  1.23.4.1  jdolecek parsend (u_char *buf, int len)
    570       1.1        mw {
    571       1.2        mw   int err, orig_len = len;
    572       1.2        mw 
    573       1.1        mw   /* make sure I/O lines are setup right for output */
    574       1.1        mw 
    575       1.1        mw   /* control lines set to input */
    576       1.1        mw   ciab.ddra &= ~(CIAB_PRA_SEL|CIAB_PRA_POUT|CIAB_PRA_BUSY);
    577       1.1        mw   /* data lines to output */
    578       1.1        mw   ciaa.ddrb = 0xff;
    579  1.23.4.1  jdolecek 
    580       1.2        mw   for (; len; len--, buf++)
    581      1.13     veego     if ((err = parsendch (*buf)) != 0)
    582       1.2        mw       return err < 0 ? -EINTR : -err;
    583       1.2        mw 
    584       1.2        mw   /* either all or nothing.. */
    585       1.2        mw   return orig_len;
    586       1.1        mw }
    587       1.1        mw 
    588       1.1        mw 
    589       1.1        mw 
    590       1.2        mw int
    591  1.23.4.1  jdolecek parreceive (u_char *buf, int len)
    592       1.2        mw {
    593       1.2        mw   /* oh deary me, something's gotta be left to be implemented
    594       1.2        mw      later... */
    595       1.2        mw   return 0;
    596       1.2        mw }
    597       1.1        mw 
    598       1.1        mw 
    599       1.1        mw #endif
    600