2000-08-27 14:35:43 +04:00
|
|
|
/* $NetBSD: par.c,v 1.23 2000/08/27 10:35:43 is Exp $ */
|
1994-10-26 05:01:24 +03:00
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-10-26 05:31:56 +03:00
|
|
|
* @(#)ppi.c 7.3 (Berkeley) 12/16/90
|
1993-09-02 20:52:31 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parallel port interface
|
|
|
|
*/
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
#include "par.h"
|
1993-09-02 20:52:31 +04:00
|
|
|
#if NPAR > 0
|
|
|
|
|
1994-02-14 00:10:20 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/uio.h>
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <sys/device.h>
|
1994-02-14 00:10:20 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 09:30:07 +03:00
|
|
|
#include <sys/callout.h>
|
1996-04-22 01:10:48 +04:00
|
|
|
#include <sys/proc.h>
|
1993-09-02 20:52:31 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <amiga/amiga/device.h>
|
1994-02-14 00:10:20 +03:00
|
|
|
#include <amiga/amiga/cia.h>
|
1994-05-08 09:52:54 +04:00
|
|
|
#include <amiga/dev/parioctl.h>
|
1993-09-02 20:52:31 +04:00
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <machine/conf.h>
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
struct par_softc {
|
2000-03-26 14:15:32 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
int sc_flags;
|
|
|
|
struct parparam sc_param;
|
|
|
|
#define sc_burst sc_param.burst
|
|
|
|
#define sc_timo sc_param.timo
|
|
|
|
#define sc_delay sc_param.delay
|
2000-03-23 09:30:07 +03:00
|
|
|
|
|
|
|
struct callout sc_timo_ch;
|
|
|
|
struct callout sc_start_ch;
|
1994-05-08 09:52:54 +04:00
|
|
|
} *par_softcp;
|
|
|
|
|
|
|
|
#define getparsp(x) (x > 0 ? NULL : par_softcp)
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
/* sc_flags values */
|
|
|
|
#define PARF_ALIVE 0x01
|
|
|
|
#define PARF_OPEN 0x02
|
|
|
|
#define PARF_UIO 0x04
|
|
|
|
#define PARF_TIMO 0x08
|
|
|
|
#define PARF_DELAY 0x10
|
|
|
|
#define PARF_OREAD 0x40
|
|
|
|
#define PARF_OWRITE 0x80
|
|
|
|
|
|
|
|
#define UNIT(x) minor(x)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1993-10-31 02:40:53 +03:00
|
|
|
int pardebug = 0;
|
1993-09-02 20:52:31 +04:00
|
|
|
#define PDB_FOLLOW 0x01
|
|
|
|
#define PDB_IO 0x02
|
1993-10-31 02:40:53 +03:00
|
|
|
#define PDB_INTERRUPT 0x04
|
1993-09-02 20:52:31 +04:00
|
|
|
#define PDB_NOCHECK 0x80
|
|
|
|
#endif
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
int parrw __P((dev_t, struct uio *));
|
|
|
|
int parhztoms __P((int));
|
|
|
|
int parmstohz __P((int));
|
|
|
|
int parsend __P((u_char *, int));
|
|
|
|
int parreceive __P((u_char *, int));
|
|
|
|
int parsendch __P((u_char));
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
void partimo __P((void *));
|
|
|
|
void parstart __P((void *));
|
|
|
|
void parintr __P((void *));
|
|
|
|
|
|
|
|
void parattach __P((struct device *, struct device *, void *));
|
1996-12-23 12:09:49 +03:00
|
|
|
int parmatch __P((struct device *, struct cfdata *, void *));
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1996-03-17 04:16:48 +03:00
|
|
|
struct cfattach par_ca = {
|
2000-04-23 23:55:51 +04:00
|
|
|
sizeof(struct par_softc), parmatch, parattach
|
1996-03-17 04:16:48 +03:00
|
|
|
};
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
/*ARGSUSED*/
|
|
|
|
int
|
1996-12-23 12:09:49 +03:00
|
|
|
parmatch(pdp, cfp, auxp)
|
1994-05-08 09:52:54 +04:00
|
|
|
struct device *pdp;
|
1996-12-23 12:09:49 +03:00
|
|
|
struct cfdata *cfp;
|
|
|
|
void *auxp;
|
1994-05-08 09:52:54 +04:00
|
|
|
{
|
2000-03-16 19:37:20 +03:00
|
|
|
static int par_found = 0;
|
1996-03-17 04:16:48 +03:00
|
|
|
|
2000-03-16 19:37:20 +03:00
|
|
|
if (!matchname((char *)auxp, "par") || par_found)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
par_found = 1;
|
|
|
|
return(1);
|
1994-05-08 09:52:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
parattach(pdp, dp, auxp)
|
|
|
|
struct device *pdp, *dp;
|
|
|
|
void *auxp;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
1994-05-08 09:52:54 +04:00
|
|
|
par_softcp = (struct par_softc *)dp;
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-05-08 09:52:54 +04:00
|
|
|
if ((pardebug & PDB_NOCHECK) == 0)
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
par_softcp->sc_flags = PARF_ALIVE;
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("\n");
|
2000-03-23 09:30:07 +03:00
|
|
|
|
|
|
|
callout_init(&par_softcp->sc_timo_ch);
|
|
|
|
callout_init(&par_softcp->sc_start_ch);
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
int
|
|
|
|
paropen(dev, flags, mode, p)
|
1994-05-08 09:52:54 +04:00
|
|
|
dev_t dev;
|
1996-04-22 01:10:48 +04:00
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
1994-05-08 09:52:54 +04:00
|
|
|
int unit = UNIT(dev);
|
|
|
|
struct par_softc *sc = getparsp(unit);
|
1993-09-02 20:52:31 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
if (unit >= NPAR || (sc->sc_flags & PARF_ALIVE) == 0)
|
|
|
|
return(ENXIO);
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1994-05-08 09:52:54 +04:00
|
|
|
if (pardebug & PDB_FOLLOW) {
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("paropen(%x, %x): flags %x, ",
|
1994-05-08 09:52:54 +04:00
|
|
|
dev, flags, sc->sc_flags);
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("port = $%x\n", ((ciab.pra ^ CIAB_PRA_SEL)
|
1994-05-08 09:52:54 +04:00
|
|
|
& (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
if (sc->sc_flags & PARF_OPEN)
|
|
|
|
return(EBUSY);
|
|
|
|
/* can either read or write, but not both */
|
|
|
|
if ((flags & (FREAD|FWRITE)) == (FREAD|FWRITE))
|
|
|
|
return EINVAL;
|
1993-09-02 20:52:31 +04:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
sc->sc_flags |= PARF_OPEN;
|
|
|
|
|
|
|
|
if (flags & FREAD)
|
|
|
|
sc->sc_flags |= PARF_OREAD;
|
|
|
|
else
|
|
|
|
sc->sc_flags |= PARF_OWRITE;
|
|
|
|
|
|
|
|
sc->sc_burst = PAR_BURST;
|
|
|
|
sc->sc_timo = parmstohz(PAR_TIMO);
|
|
|
|
sc->sc_delay = parmstohz(PAR_DELAY);
|
|
|
|
/* enable interrupts for CIAA-FLG */
|
|
|
|
ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_FLG;
|
|
|
|
return(0);
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
int
|
|
|
|
parclose(dev, flags, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flags;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
1994-05-08 09:52:54 +04:00
|
|
|
int unit = UNIT(dev);
|
|
|
|
struct par_softc *sc = getparsp(unit);
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & PDB_FOLLOW)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parclose(%x, %x): flags %x\n",
|
1993-09-02 20:52:31 +04:00
|
|
|
dev, flags, sc->sc_flags);
|
|
|
|
#endif
|
|
|
|
sc->sc_flags &= ~(PARF_OPEN|PARF_OREAD|PARF_OWRITE);
|
|
|
|
/* don't allow interrupts for CIAA-FLG any longer */
|
|
|
|
ciaa.icr = CIA_ICR_FLG;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
void
|
|
|
|
parstart(arg)
|
|
|
|
void *arg;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
2000-03-23 09:30:07 +03:00
|
|
|
struct par_softc *sc = arg;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1994-05-08 09:52:54 +04:00
|
|
|
if (pardebug & PDB_FOLLOW)
|
2000-03-23 09:30:07 +03:00
|
|
|
printf("parstart(%x)\n", sc->sc_dev.dv_unit);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
sc->sc_flags &= ~PARF_DELAY;
|
|
|
|
wakeup(sc);
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
void
|
|
|
|
partimo(arg)
|
|
|
|
void *arg;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
2000-03-23 09:30:07 +03:00
|
|
|
struct par_softc *sc = arg;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1994-05-08 09:52:54 +04:00
|
|
|
if (pardebug & PDB_FOLLOW)
|
2000-03-23 09:30:07 +03:00
|
|
|
printf("partimo(%x)\n", sc->sc_dev.dv_unit);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1994-05-08 09:52:54 +04:00
|
|
|
sc->sc_flags &= ~(PARF_UIO|PARF_TIMO);
|
|
|
|
wakeup(sc);
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
int
|
|
|
|
parread(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-04-22 01:10:48 +04:00
|
|
|
if (pardebug & PDB_FOLLOW)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parread(%x, %p)\n", dev, uio);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1996-04-22 01:10:48 +04:00
|
|
|
return (parrw(dev, uio));
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
parwrite(dev, uio, flags)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flags;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1996-04-22 01:10:48 +04:00
|
|
|
if (pardebug & PDB_FOLLOW)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parwrite(%x, %p)\n", dev, uio);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1996-04-22 01:10:48 +04:00
|
|
|
return (parrw(dev, uio));
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
|
|
|
|
int
|
1993-09-02 20:52:31 +04:00
|
|
|
parrw(dev, uio)
|
|
|
|
dev_t dev;
|
|
|
|
register struct uio *uio;
|
|
|
|
{
|
|
|
|
int unit = UNIT(dev);
|
1994-05-08 09:52:54 +04:00
|
|
|
register struct par_softc *sc = getparsp(unit);
|
1993-09-02 20:52:31 +04:00
|
|
|
register int s, len, cnt;
|
|
|
|
register char *cp;
|
|
|
|
int error = 0, gotdata = 0;
|
|
|
|
int buflen;
|
|
|
|
char *buf;
|
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
len = 0;
|
|
|
|
cnt = 0;
|
1993-10-31 02:40:53 +03:00
|
|
|
if (!!(sc->sc_flags & PARF_OREAD) ^ (uio->uio_rw == UIO_READ))
|
1993-09-02 20:52:31 +04:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if (uio->uio_resid == 0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & (PDB_FOLLOW|PDB_IO))
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw(%x, %p, %c): burst %d, timo %d, resid %x\n",
|
1993-09-02 20:52:31 +04:00
|
|
|
dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
|
|
|
|
sc->sc_burst, sc->sc_timo, uio->uio_resid);
|
|
|
|
#endif
|
1994-05-31 07:11:42 +04:00
|
|
|
buflen = min(sc->sc_burst, uio->uio_resid);
|
1993-09-02 20:52:31 +04:00
|
|
|
buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
|
|
|
|
sc->sc_flags |= PARF_UIO;
|
1993-10-31 02:40:53 +03:00
|
|
|
if (sc->sc_timo > 0)
|
|
|
|
{
|
|
|
|
sc->sc_flags |= PARF_TIMO;
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_reset(&sc->sc_timo_ch, sc->sc_timo, partimo, sc);
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
1993-10-31 02:40:53 +03:00
|
|
|
while (uio->uio_resid > 0)
|
|
|
|
{
|
1994-05-31 07:11:42 +04:00
|
|
|
len = min(buflen, uio->uio_resid);
|
1993-10-31 02:40:53 +03:00
|
|
|
cp = buf;
|
|
|
|
if (uio->uio_rw == UIO_WRITE)
|
|
|
|
{
|
|
|
|
error = uiomove(cp, len, uio);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
again:
|
|
|
|
s = splbio();
|
1993-09-02 20:52:31 +04:00
|
|
|
#if 0
|
1993-10-31 02:40:53 +03:00
|
|
|
if ((sc->sc_flags & PARF_UIO) && hpibreq(&sc->sc_dq) == 0)
|
|
|
|
sleep(sc, PRIBIO+1);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1993-10-31 02:40:53 +03:00
|
|
|
/*
|
|
|
|
* Check if we timed out during sleep or uiomove
|
|
|
|
*/
|
1999-08-05 22:08:08 +04:00
|
|
|
(void) spllowersoftclock();
|
1993-10-31 02:40:53 +03:00
|
|
|
if ((sc->sc_flags & PARF_UIO) == 0)
|
|
|
|
{
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1993-10-31 02:40:53 +03:00
|
|
|
if (pardebug & PDB_IO)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw: uiomove/sleep timo, flags %x\n",
|
1993-10-31 02:40:53 +03:00
|
|
|
sc->sc_flags);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1993-10-31 02:40:53 +03:00
|
|
|
if (sc->sc_flags & PARF_TIMO)
|
|
|
|
{
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_stop(&sc->sc_timo_ch);
|
1993-10-31 02:40:53 +03:00
|
|
|
sc->sc_flags &= ~PARF_TIMO;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
splx(s);
|
1993-10-31 02:40:53 +03:00
|
|
|
/*
|
|
|
|
* Perform the operation
|
|
|
|
*/
|
|
|
|
if (uio->uio_rw == UIO_WRITE)
|
|
|
|
cnt = parsend (cp, len);
|
|
|
|
else
|
|
|
|
cnt = parreceive (cp, len);
|
|
|
|
|
|
|
|
if (cnt < 0)
|
|
|
|
{
|
|
|
|
error = -cnt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
#if 0
|
|
|
|
hpibfree(&sc->sc_dq);
|
|
|
|
#endif
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1993-10-31 02:40:53 +03:00
|
|
|
if (pardebug & PDB_IO)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw: %s(%p, %d) -> %d\n",
|
1993-10-31 02:40:53 +03:00
|
|
|
uio->uio_rw == UIO_READ ? "recv" : "send", cp, len, cnt);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1993-10-31 02:40:53 +03:00
|
|
|
splx(s);
|
|
|
|
if (uio->uio_rw == UIO_READ)
|
|
|
|
{
|
|
|
|
if (cnt)
|
|
|
|
{
|
|
|
|
error = uiomove(cp, cnt, uio);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
gotdata++;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Didn't get anything this time, but did in the past.
|
|
|
|
* Consider us done.
|
|
|
|
*/
|
|
|
|
else if (gotdata)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
s = splsoftclock();
|
1993-09-02 20:52:31 +04:00
|
|
|
/*
|
1993-10-31 02:40:53 +03:00
|
|
|
* Operation timeout (or non-blocking), quit now.
|
1993-09-02 20:52:31 +04:00
|
|
|
*/
|
1993-10-31 02:40:53 +03:00
|
|
|
if ((sc->sc_flags & PARF_UIO) == 0)
|
|
|
|
{
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1993-10-31 02:40:53 +03:00
|
|
|
if (pardebug & PDB_IO)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw: timeout/done\n");
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1993-10-31 02:40:53 +03:00
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Implement inter-read delay
|
|
|
|
*/
|
|
|
|
if (sc->sc_delay > 0)
|
|
|
|
{
|
|
|
|
sc->sc_flags |= PARF_DELAY;
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_reset(&sc->sc_start_ch, sc->sc_delay, parstart, sc);
|
1996-04-22 01:10:48 +04:00
|
|
|
error = tsleep(sc, PCATCH | (PZERO - 1), "par-cdelay", 0);
|
1993-10-31 02:40:53 +03:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
splx(s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
splx(s);
|
1993-10-31 02:40:53 +03:00
|
|
|
/*
|
|
|
|
* Must not call uiomove again til we've used all data
|
|
|
|
* that we already grabbed.
|
|
|
|
*/
|
|
|
|
if (uio->uio_rw == UIO_WRITE && cnt != len)
|
|
|
|
{
|
|
|
|
cp += cnt;
|
|
|
|
len -= cnt;
|
|
|
|
cnt = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
1993-10-31 02:40:53 +03:00
|
|
|
s = splsoftclock();
|
|
|
|
if (sc->sc_flags & PARF_TIMO)
|
|
|
|
{
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_stop(&sc->sc_timo_ch);
|
1993-10-31 02:40:53 +03:00
|
|
|
sc->sc_flags &= ~PARF_TIMO;
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
1993-10-31 02:40:53 +03:00
|
|
|
if (sc->sc_flags & PARF_DELAY)
|
|
|
|
{
|
2000-03-23 09:30:07 +03:00
|
|
|
callout_stop(&sc->sc_start_ch);
|
1993-10-31 02:40:53 +03:00
|
|
|
sc->sc_flags &= ~PARF_DELAY;
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
/*
|
|
|
|
* Adjust for those chars that we uiomove'ed but never wrote
|
|
|
|
*/
|
1993-10-31 02:40:53 +03:00
|
|
|
if (uio->uio_rw == UIO_WRITE && cnt != len)
|
|
|
|
{
|
|
|
|
uio->uio_resid += (len - cnt);
|
1993-09-02 20:52:31 +04:00
|
|
|
#ifdef DEBUG
|
1993-10-31 02:40:53 +03:00
|
|
|
if (pardebug & PDB_IO)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw: short write, adjust by %d\n",
|
1993-10-31 02:40:53 +03:00
|
|
|
len-cnt);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
1993-10-31 02:40:53 +03:00
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
free(buf, M_DEVBUF);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & (PDB_FOLLOW|PDB_IO))
|
1996-10-13 07:05:43 +04:00
|
|
|
printf("parrw: return %d, resid %d\n", error, uio->uio_resid);
|
1993-09-02 20:52:31 +04:00
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
int
|
1994-02-11 08:02:36 +03:00
|
|
|
parioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
1994-12-01 20:24:23 +03:00
|
|
|
u_long cmd;
|
1994-02-11 08:02:36 +03:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
1994-05-08 09:52:54 +04:00
|
|
|
struct par_softc *sc = getparsp(UNIT(dev));
|
1993-09-02 20:52:31 +04:00
|
|
|
struct parparam *pp, *upp;
|
|
|
|
int error = 0;
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case PARIOCGPARAM:
|
|
|
|
pp = &sc->sc_param;
|
|
|
|
upp = (struct parparam *)data;
|
|
|
|
upp->burst = pp->burst;
|
|
|
|
upp->timo = parhztoms(pp->timo);
|
|
|
|
upp->delay = parhztoms(pp->delay);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PARIOCSPARAM:
|
|
|
|
pp = &sc->sc_param;
|
|
|
|
upp = (struct parparam *)data;
|
|
|
|
if (upp->burst < PAR_BURST_MIN || upp->burst > PAR_BURST_MAX ||
|
|
|
|
upp->delay < PAR_DELAY_MIN || upp->delay > PAR_DELAY_MAX)
|
|
|
|
return(EINVAL);
|
|
|
|
pp->burst = upp->burst;
|
|
|
|
pp->timo = parmstohz(upp->timo);
|
|
|
|
pp->delay = parmstohz(upp->delay);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1993-09-02 20:52:31 +04:00
|
|
|
return(EINVAL);
|
1993-10-31 02:40:53 +03:00
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
int
|
1993-09-02 20:52:31 +04:00
|
|
|
parhztoms(h)
|
1993-10-31 02:40:53 +03:00
|
|
|
int h;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
|
|
|
extern int hz;
|
|
|
|
register int m = h;
|
|
|
|
|
|
|
|
if (m > 0)
|
|
|
|
m = m * 1000 / hz;
|
|
|
|
return(m);
|
|
|
|
}
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
int
|
1993-09-02 20:52:31 +04:00
|
|
|
parmstohz(m)
|
1993-10-31 02:40:53 +03:00
|
|
|
int m;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
|
|
|
extern int hz;
|
|
|
|
register int h = m;
|
|
|
|
|
|
|
|
if (h > 0) {
|
|
|
|
h = h * hz / 1000;
|
|
|
|
if (h == 0)
|
|
|
|
h = 1000 / hz;
|
|
|
|
}
|
|
|
|
return(h);
|
|
|
|
}
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
/* stuff below here if for interrupt driven output of data thru
|
|
|
|
the parallel port. */
|
|
|
|
|
|
|
|
int parsend_pending;
|
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
void
|
1994-05-08 09:52:54 +04:00
|
|
|
parintr(arg)
|
|
|
|
void *arg;
|
1993-09-02 20:52:31 +04:00
|
|
|
{
|
2000-08-27 14:35:43 +04:00
|
|
|
int s;
|
1994-05-08 09:52:54 +04:00
|
|
|
|
|
|
|
s = splclock();
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
#ifdef DEBUG
|
1994-05-08 09:52:54 +04:00
|
|
|
if (pardebug & PDB_INTERRUPT)
|
2000-08-27 14:35:43 +04:00
|
|
|
printf("parintr\n");
|
1993-10-31 02:40:53 +03:00
|
|
|
#endif
|
2000-08-27 14:35:43 +04:00
|
|
|
parsend_pending = 0;
|
1993-10-31 02:40:53 +03:00
|
|
|
|
1994-05-08 09:52:54 +04:00
|
|
|
wakeup(parintr);
|
|
|
|
splx(s);
|
1993-10-31 02:40:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
parsendch (ch)
|
|
|
|
u_char ch;
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
/* if either offline, busy or out of paper, wait for that
|
|
|
|
condition to clear */
|
|
|
|
s = splclock();
|
|
|
|
while (!error
|
|
|
|
&& (parsend_pending
|
|
|
|
|| ((ciab.pra ^ CIAB_PRA_SEL)
|
|
|
|
& (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT))))
|
|
|
|
{
|
|
|
|
extern int hz;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & PDB_INTERRUPT)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("parsendch, port = $%x\n",
|
1993-10-31 02:40:53 +03:00
|
|
|
((ciab.pra ^ CIAB_PRA_SEL)
|
|
|
|
& (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
|
|
|
|
#endif
|
|
|
|
/* this is essentially a flipflop to have us wait for the
|
|
|
|
first character being transmitted when trying to transmit
|
|
|
|
the second, etc. */
|
|
|
|
parsend_pending = 0;
|
|
|
|
/* it's quite important that a parallel putc can be
|
|
|
|
interrupted, given the possibility to lock a printer
|
|
|
|
in an offline condition.. */
|
2000-08-27 14:35:43 +04:00
|
|
|
error = tsleep(parintr, PCATCH | (PZERO - 1), "parsendch", hz);
|
|
|
|
if (error == EWOULDBLOCK)
|
|
|
|
error = 0;
|
|
|
|
if (error > 0)
|
1993-10-31 02:40:53 +03:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & PDB_INTERRUPT)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("parsendch interrupted, error = %d\n", error);
|
1993-10-31 02:40:53 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! error)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (pardebug & PDB_INTERRUPT)
|
1996-10-13 07:05:43 +04:00
|
|
|
printf ("#%d", ch);
|
1993-10-31 02:40:53 +03:00
|
|
|
#endif
|
|
|
|
ciaa.prb = ch;
|
|
|
|
parsend_pending = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx (s);
|
|
|
|
|
|
|
|
return error;
|
1993-09-02 20:52:31 +04:00
|
|
|
}
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
int
|
|
|
|
parsend (buf, len)
|
|
|
|
u_char *buf;
|
|
|
|
int len;
|
|
|
|
{
|
1993-10-31 02:40:53 +03:00
|
|
|
int err, orig_len = len;
|
|
|
|
|
1993-09-02 20:52:31 +04:00
|
|
|
/* make sure I/O lines are setup right for output */
|
|
|
|
|
|
|
|
/* control lines set to input */
|
|
|
|
ciab.ddra &= ~(CIAB_PRA_SEL|CIAB_PRA_POUT|CIAB_PRA_BUSY);
|
|
|
|
/* data lines to output */
|
|
|
|
ciaa.ddrb = 0xff;
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
for (; len; len--, buf++)
|
1996-04-22 01:10:48 +04:00
|
|
|
if ((err = parsendch (*buf)) != 0)
|
1993-10-31 02:40:53 +03:00
|
|
|
return err < 0 ? -EINTR : -err;
|
1993-09-02 20:52:31 +04:00
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
/* either all or nothing.. */
|
|
|
|
return orig_len;
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1993-10-31 02:40:53 +03:00
|
|
|
int
|
|
|
|
parreceive (buf, len)
|
|
|
|
u_char *buf;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
/* oh deary me, something's gotta be left to be implemented
|
|
|
|
later... */
|
|
|
|
return 0;
|
|
|
|
}
|
1993-09-02 20:52:31 +04:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|