1997-04-14 06:33:16 +04:00
|
|
|
/* $NetBSD: fhpib.c,v 1.17 1997/04/14 02:33:19 thorpej Exp $ */
|
1994-10-26 10:22:45 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
1997-01-30 12:06:51 +03:00
|
|
|
* Copyright (c) 1996, 1997 Jason R. Thorpe. All rights reserved.
|
1994-05-23 09:58:16 +04:00
|
|
|
* Copyright (c) 1982, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-05-13 17:56:20 +04:00
|
|
|
*
|
|
|
|
* 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 10:22:45 +03:00
|
|
|
* @(#)fhpib.c 8.2 (Berkeley) 1/12/94
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 98625A/B HPIB driver
|
|
|
|
*/
|
|
|
|
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1995-01-07 13:30:10 +03:00
|
|
|
#include <sys/kernel.h>
|
1994-05-23 09:58:16 +04:00
|
|
|
#include <sys/buf.h>
|
1997-01-30 12:06:51 +03:00
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
1997-04-14 06:33:16 +04:00
|
|
|
#include <machine/intr.h>
|
1997-01-30 12:06:51 +03:00
|
|
|
|
|
|
|
#include <hp300/dev/dioreg.h>
|
|
|
|
#include <hp300/dev/diovar.h>
|
|
|
|
#include <hp300/dev/diodevs.h>
|
|
|
|
|
|
|
|
#include <hp300/dev/dmavar.h>
|
1994-05-23 09:58:16 +04:00
|
|
|
|
|
|
|
#include <hp300/dev/fhpibreg.h>
|
|
|
|
#include <hp300/dev/hpibvar.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Inline version of fhpibwait to be used in places where
|
|
|
|
* we don't worry about getting hung.
|
|
|
|
*/
|
1996-05-19 03:56:59 +04:00
|
|
|
#define FHPIBWAIT(hd, m) while (((hd)->hpib_intr & (m)) == 0) DELAY(1)
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
int fhpibdebugunit = -1;
|
|
|
|
int fhpibdebug = 0;
|
|
|
|
#define FDB_FAIL 0x01
|
|
|
|
#define FDB_DMA 0x02
|
|
|
|
#define FDB_WAIT 0x04
|
|
|
|
#define FDB_PPOLL 0x08
|
|
|
|
|
|
|
|
int dopriodma = 0; /* use high priority DMA */
|
|
|
|
int doworddma = 1; /* non-zero if we should attempt word dma */
|
|
|
|
int doppollint = 1; /* use ppoll interrupts instead of watchdog */
|
1994-05-23 09:58:16 +04:00
|
|
|
int fhpibppolldelay = 50;
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
void fhpibifc __P((struct fhpibdevice *));
|
|
|
|
void fhpibdmadone __P((void *));
|
|
|
|
int fhpibwait __P((struct fhpibdevice *, int));
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
void fhpibreset __P((struct hpibbus_softc *));
|
|
|
|
int fhpibsend __P((struct hpibbus_softc *, int, int, void *, int));
|
|
|
|
int fhpibrecv __P((struct hpibbus_softc *, int, int, void *, int));
|
|
|
|
int fhpibppoll __P((struct hpibbus_softc *));
|
1995-11-19 20:57:15 +03:00
|
|
|
void fhpibppwatch __P((void *));
|
1997-01-30 12:06:51 +03:00
|
|
|
void fhpibgo __P((struct hpibbus_softc *, int, int, void *, int, int, int));
|
|
|
|
void fhpibdone __P((struct hpibbus_softc *));
|
1996-02-14 05:43:54 +03:00
|
|
|
int fhpibintr __P((void *));
|
1995-11-19 20:57:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Our controller ops structure.
|
|
|
|
*/
|
|
|
|
struct hpib_controller fhpib_controller = {
|
|
|
|
fhpibreset,
|
|
|
|
fhpibsend,
|
|
|
|
fhpibrecv,
|
|
|
|
fhpibppoll,
|
|
|
|
fhpibppwatch,
|
|
|
|
fhpibgo,
|
|
|
|
fhpibdone,
|
|
|
|
fhpibintr
|
|
|
|
};
|
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc {
|
|
|
|
struct device sc_dev; /* generic device glue */
|
|
|
|
struct fhpibdevice *sc_regs; /* device registers */
|
|
|
|
int sc_cmd;
|
|
|
|
struct hpibbus_softc *sc_hpibbus; /* XXX */
|
|
|
|
};
|
|
|
|
|
|
|
|
int fhpibmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void fhpibattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach fhpib_ca = {
|
|
|
|
sizeof(struct fhpib_softc), fhpibmatch, fhpibattach
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cfdriver fhpib_cd = {
|
|
|
|
NULL, "fhpib", DV_DULL
|
|
|
|
};
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibmatch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct dio_attach_args *da = aux;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
if (da->da_id == DIO_DEVICE_ID_FHPIB)
|
|
|
|
return (1);
|
1995-11-19 20:57:15 +03:00
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
return (0);
|
1995-12-02 21:21:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1995-12-02 21:21:49 +03:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)self;
|
|
|
|
struct dio_attach_args *da = aux;
|
|
|
|
struct hpibdev_attach_args ha;
|
|
|
|
int ipl;
|
|
|
|
|
|
|
|
sc->sc_regs = (struct fhpibdevice *)iomap(dio_scodetopa(da->da_scode),
|
|
|
|
da->da_size);
|
|
|
|
if (sc->sc_regs == NULL) {
|
|
|
|
printf("\n%s: can't map registers\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipl = DIO_IPL(sc->sc_regs);
|
|
|
|
printf(" ipl %d: %s\n", ipl, DIO_DEVICE_DESC_FHPIB);
|
1995-12-02 21:21:49 +03:00
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
/* Establish the interrupt handler. */
|
1997-04-14 06:33:16 +04:00
|
|
|
(void) intr_establish(fhpibintr, sc, ipl, IPL_BIO);
|
1997-01-30 12:06:51 +03:00
|
|
|
dmacomputeipl();
|
1995-12-02 21:21:49 +03:00
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
ha.ha_ops = &fhpib_controller;
|
|
|
|
ha.ha_type = HPIBC; /* XXX */
|
|
|
|
ha.ha_ba = HPIBC_BA;
|
|
|
|
ha.ha_softcpp = &sc->sc_hpibbus; /* XXX */
|
|
|
|
(void)config_found(self, &ha, hpibdevprint);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibreset(hs)
|
|
|
|
struct hpibbus_softc *hs;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
hd->hpib_cid = 0xFF;
|
|
|
|
DELAY(100);
|
|
|
|
hd->hpib_cmd = CT_8BIT;
|
|
|
|
hd->hpib_ar = AR_ARONC;
|
|
|
|
fhpibifc(hd);
|
|
|
|
hd->hpib_ie = IDS_IE;
|
|
|
|
hd->hpib_data = C_DCL;
|
|
|
|
DELAY(100000);
|
|
|
|
/*
|
|
|
|
* See if we can do word dma.
|
|
|
|
* If so, we should be able to write and read back the appropos bit.
|
|
|
|
*/
|
|
|
|
hd->hpib_ie |= IDS_WDMA;
|
|
|
|
if (hd->hpib_ie & IDS_WDMA) {
|
|
|
|
hd->hpib_ie &= ~IDS_WDMA;
|
|
|
|
hs->sc_flags |= HPIBF_DMA16;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (fhpibdebug & FDB_DMA)
|
1997-01-30 12:06:51 +03:00
|
|
|
printf("fhpibtype: %s has word dma\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-30 12:06:51 +03:00
|
|
|
void
|
1993-05-13 17:56:20 +04:00
|
|
|
fhpibifc(hd)
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
|
|
|
hd->hpib_cmd |= CT_IFC;
|
|
|
|
hd->hpib_cmd |= CT_INITFIFO;
|
|
|
|
DELAY(100);
|
|
|
|
hd->hpib_cmd &= ~CT_IFC;
|
|
|
|
hd->hpib_cmd |= CT_REN;
|
|
|
|
hd->hpib_stat = ST_ATN;
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibsend(hs, slave, sec, ptr, origcnt)
|
|
|
|
struct hpibbus_softc *hs;
|
|
|
|
int slave, sec, origcnt;
|
1995-11-19 20:57:15 +03:00
|
|
|
void *ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
1997-03-31 11:32:14 +04:00
|
|
|
int cnt = origcnt;
|
|
|
|
int timo;
|
1995-11-19 20:57:15 +03:00
|
|
|
char *addr = ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
hd->hpib_stat = 0;
|
|
|
|
hd->hpib_imask = IM_IDLE | IM_ROOM;
|
|
|
|
if (fhpibwait(hd, IM_IDLE) < 0)
|
|
|
|
goto senderr;
|
|
|
|
hd->hpib_stat = ST_ATN;
|
|
|
|
hd->hpib_data = C_UNL;
|
|
|
|
hd->hpib_data = C_TAG + hs->sc_ba;
|
|
|
|
hd->hpib_data = C_LAG + slave;
|
1995-01-07 13:30:10 +03:00
|
|
|
if (sec < 0) {
|
|
|
|
if (sec == -2) /* selected device clear KLUDGE */
|
|
|
|
hd->hpib_data = C_SDC;
|
|
|
|
} else
|
1993-05-13 17:56:20 +04:00
|
|
|
hd->hpib_data = C_SCG + sec;
|
|
|
|
if (fhpibwait(hd, IM_IDLE) < 0)
|
|
|
|
goto senderr;
|
|
|
|
if (cnt) {
|
|
|
|
hd->hpib_stat = ST_WRITE;
|
|
|
|
while (--cnt) {
|
|
|
|
hd->hpib_data = *addr++;
|
|
|
|
timo = hpibtimeout;
|
|
|
|
while ((hd->hpib_intr & IM_ROOM) == 0) {
|
|
|
|
if (--timo <= 0)
|
|
|
|
goto senderr;
|
1996-05-19 03:56:59 +04:00
|
|
|
DELAY(1);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
hd->hpib_stat = ST_EOI;
|
|
|
|
hd->hpib_data = *addr;
|
|
|
|
FHPIBWAIT(hd, IM_ROOM);
|
|
|
|
hd->hpib_stat = ST_ATN;
|
|
|
|
/* XXX: HP-UX claims bug with CS80 transparent messages */
|
|
|
|
if (sec == 0x12)
|
|
|
|
DELAY(150);
|
|
|
|
hd->hpib_data = C_UNL;
|
|
|
|
(void) fhpibwait(hd, IM_IDLE);
|
|
|
|
}
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
return (origcnt);
|
1995-01-07 13:30:10 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
senderr:
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
fhpibifc(hd);
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (fhpibdebug & FDB_FAIL) {
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("%s: fhpibsend failed: slave %d, sec %x, ",
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_dev.dv_xname, slave, sec);
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("sent %d of %d bytes\n", origcnt-cnt-1, origcnt);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
1995-01-07 13:30:10 +03:00
|
|
|
return (origcnt - cnt - 1);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibrecv(hs, slave, sec, ptr, origcnt)
|
|
|
|
struct hpibbus_softc *hs;
|
|
|
|
int slave, sec, origcnt;
|
1995-11-19 20:57:15 +03:00
|
|
|
void *ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
1997-03-31 11:32:14 +04:00
|
|
|
int cnt = origcnt;
|
|
|
|
int timo;
|
1995-11-19 20:57:15 +03:00
|
|
|
char *addr = ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1995-01-07 13:30:10 +03:00
|
|
|
/*
|
|
|
|
* Slave < 0 implies continuation of a previous receive
|
|
|
|
* that probably timed out.
|
|
|
|
*/
|
|
|
|
if (slave >= 0) {
|
|
|
|
hd->hpib_stat = 0;
|
|
|
|
hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
|
|
|
|
if (fhpibwait(hd, IM_IDLE) < 0)
|
|
|
|
goto recverror;
|
|
|
|
hd->hpib_stat = ST_ATN;
|
|
|
|
hd->hpib_data = C_UNL;
|
|
|
|
hd->hpib_data = C_LAG + hs->sc_ba;
|
|
|
|
hd->hpib_data = C_TAG + slave;
|
|
|
|
if (sec != -1)
|
|
|
|
hd->hpib_data = C_SCG + sec;
|
|
|
|
if (fhpibwait(hd, IM_IDLE) < 0)
|
|
|
|
goto recverror;
|
|
|
|
hd->hpib_stat = ST_READ0;
|
|
|
|
hd->hpib_data = 0;
|
|
|
|
}
|
1993-05-13 17:56:20 +04:00
|
|
|
if (cnt) {
|
|
|
|
while (--cnt >= 0) {
|
|
|
|
timo = hpibtimeout;
|
|
|
|
while ((hd->hpib_intr & IM_BYTE) == 0) {
|
|
|
|
if (--timo == 0)
|
|
|
|
goto recvbyteserror;
|
1996-05-19 03:56:59 +04:00
|
|
|
DELAY(1);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
*addr++ = hd->hpib_data;
|
|
|
|
}
|
|
|
|
FHPIBWAIT(hd, IM_ROOM);
|
|
|
|
hd->hpib_stat = ST_ATN;
|
|
|
|
hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
|
|
|
|
(void) fhpibwait(hd, IM_IDLE);
|
|
|
|
}
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
return (origcnt);
|
|
|
|
|
|
|
|
recverror:
|
|
|
|
fhpibifc(hd);
|
|
|
|
recvbyteserror:
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (fhpibdebug & FDB_FAIL) {
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("%s: fhpibrecv failed: slave %d, sec %x, ",
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_dev.dv_xname, slave, sec);
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("got %d of %d bytes\n", origcnt-cnt-1, origcnt);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
1995-01-07 13:30:10 +03:00
|
|
|
return (origcnt - cnt - 1);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibgo(hs, slave, sec, ptr, count, rw, timo)
|
|
|
|
struct hpibbus_softc *hs;
|
|
|
|
int slave, sec, count, rw, timo;
|
1995-11-19 20:57:15 +03:00
|
|
|
void *ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
int i;
|
1995-11-19 20:57:15 +03:00
|
|
|
char *addr = ptr;
|
1993-05-13 17:56:20 +04:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
hs->sc_flags |= HPIBF_IO;
|
1995-01-07 13:30:10 +03:00
|
|
|
if (timo)
|
|
|
|
hs->sc_flags |= HPIBF_TIMO;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (rw == B_READ)
|
|
|
|
hs->sc_flags |= HPIBF_READ;
|
|
|
|
#ifdef DEBUG
|
|
|
|
else if (hs->sc_flags & HPIBF_READ) {
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibgo: HPIBF_READ still set\n");
|
1993-05-13 17:56:20 +04:00
|
|
|
hs->sc_flags &= ~HPIBF_READ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
hs->sc_count = count;
|
|
|
|
hs->sc_addr = addr;
|
|
|
|
#ifdef DEBUG
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibtransfer[unit]++; XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
if ((hs->sc_flags & HPIBF_DMA16) &&
|
|
|
|
((int)addr & 1) == 0 && count && (count & 1) == 0
|
|
|
|
#ifdef DEBUG
|
|
|
|
&& doworddma
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
#ifdef DEBUG
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibworddma[unit]++; XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
flags |= DMAGO_WORD;
|
|
|
|
hd->hpib_latch = 0;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (dopriodma)
|
|
|
|
flags |= DMAGO_PRI;
|
|
|
|
#endif
|
|
|
|
if (hs->sc_flags & HPIBF_READ) {
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_cmd = CT_REN | CT_8BIT;
|
1993-05-13 17:56:20 +04:00
|
|
|
hs->sc_curcnt = count;
|
1997-01-30 12:06:51 +03:00
|
|
|
dmago(hs->sc_dq->dq_chan, addr, count, flags|DMAGO_READ);
|
|
|
|
if (fhpibrecv(hs, slave, sec, 0, 0) < 0) {
|
1993-05-13 17:56:20 +04:00
|
|
|
#ifdef DEBUG
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibgo: recv failed, retrying...\n");
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
1997-01-30 12:06:51 +03:00
|
|
|
(void) fhpibrecv(hs, slave, sec, 0, 0);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
i = hd->hpib_cmd;
|
1997-01-30 12:06:51 +03:00
|
|
|
hd->hpib_cmd = sc->sc_cmd;
|
|
|
|
hd->hpib_ie = IDS_DMA(hs->sc_dq->dq_chan) |
|
1993-05-13 17:56:20 +04:00
|
|
|
((flags & DMAGO_WORD) ? IDS_WDMA : 0);
|
|
|
|
return;
|
|
|
|
}
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_cmd = CT_REN | CT_8BIT | CT_FIFOSEL;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (count < hpibdmathresh) {
|
|
|
|
#ifdef DEBUG
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibnondma[unit]++; XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
if (flags & DMAGO_WORD)
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibworddma[unit]--; XXX */ ;
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
hs->sc_curcnt = count;
|
1997-01-30 12:06:51 +03:00
|
|
|
(void) fhpibsend(hs, slave, sec, addr, count);
|
|
|
|
fhpibdone(hs);
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
count -= (flags & DMAGO_WORD) ? 2 : 1;
|
|
|
|
hs->sc_curcnt = count;
|
1997-01-30 12:06:51 +03:00
|
|
|
dmago(hs->sc_dq->dq_chan, addr, count, flags);
|
|
|
|
if (fhpibsend(hs, slave, sec, 0, 0) < 0) {
|
1993-05-13 17:56:20 +04:00
|
|
|
#ifdef DEBUG
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibgo: send failed, retrying...\n");
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
1997-01-30 12:06:51 +03:00
|
|
|
(void) fhpibsend(hs, slave, sec, 0, 0);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
i = hd->hpib_cmd;
|
1997-01-30 12:06:51 +03:00
|
|
|
hd->hpib_cmd = sc->sc_cmd;
|
|
|
|
hd->hpib_ie = IDS_DMA(hs->sc_dq->dq_chan) | IDS_WRITE |
|
1993-05-13 17:56:20 +04:00
|
|
|
((flags & DMAGO_WORD) ? IDS_WDMA : 0);
|
|
|
|
}
|
|
|
|
|
1995-01-07 13:30:10 +03:00
|
|
|
/*
|
|
|
|
* A DMA read can finish but the device can still be waiting (MAG-tape
|
|
|
|
* with more data than we're waiting for). This timeout routine
|
|
|
|
* takes care of that. Somehow, the thing gets hosed. For now, since
|
|
|
|
* this should be a very rare occurence, we RESET it.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fhpibdmadone(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
struct hpibbus_softc *hs = arg;
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
1995-01-07 13:30:10 +03:00
|
|
|
int s = splbio();
|
|
|
|
|
|
|
|
if (hs->sc_flags & HPIBF_IO) {
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
struct hpibqueue *hq;
|
1995-01-07 13:30:10 +03:00
|
|
|
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
hd->hpib_cid = 0xFF;
|
|
|
|
DELAY(100);
|
|
|
|
hd->hpib_cmd = CT_8BIT;
|
|
|
|
hd->hpib_ar = AR_ARONC;
|
|
|
|
fhpibifc(hd);
|
|
|
|
hd->hpib_ie = IDS_IE;
|
|
|
|
hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
|
1997-01-30 12:06:51 +03:00
|
|
|
dmafree(hs->sc_dq);
|
|
|
|
|
|
|
|
hq = hs->sc_queue.tqh_first;
|
|
|
|
(hq->hq_intr)(hq->hq_softc);
|
1995-01-07 13:30:10 +03:00
|
|
|
}
|
1997-01-30 12:06:51 +03:00
|
|
|
splx(s);
|
1995-01-07 13:30:10 +03:00
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
void
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibdone(hs)
|
|
|
|
struct hpibbus_softc *hs;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
char *addr;
|
|
|
|
int cnt;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
cnt = hs->sc_curcnt;
|
|
|
|
hs->sc_addr += cnt;
|
|
|
|
hs->sc_count -= cnt;
|
|
|
|
#ifdef DEBUG
|
1997-04-03 02:37:21 +04:00
|
|
|
if ((fhpibdebug & FDB_DMA) && fhpibdebugunit == sc->sc_dev.dv_unit)
|
|
|
|
printf("fhpibdone: addr %p cnt %d\n",
|
1993-05-13 17:56:20 +04:00
|
|
|
hs->sc_addr, hs->sc_count);
|
|
|
|
#endif
|
1995-01-07 13:30:10 +03:00
|
|
|
if (hs->sc_flags & HPIBF_READ) {
|
1993-05-13 17:56:20 +04:00
|
|
|
hd->hpib_imask = IM_IDLE | IM_BYTE;
|
1995-01-07 13:30:10 +03:00
|
|
|
if (hs->sc_flags & HPIBF_TIMO)
|
1997-01-30 12:06:51 +03:00
|
|
|
timeout(fhpibdmadone, hs, hz >> 2);
|
1995-01-07 13:30:10 +03:00
|
|
|
} else {
|
1993-05-13 17:56:20 +04:00
|
|
|
cnt = hs->sc_count;
|
|
|
|
if (cnt) {
|
|
|
|
addr = hs->sc_addr;
|
|
|
|
hd->hpib_imask = IM_IDLE | IM_ROOM;
|
|
|
|
FHPIBWAIT(hd, IM_IDLE);
|
|
|
|
hd->hpib_stat = ST_WRITE;
|
|
|
|
while (--cnt) {
|
|
|
|
hd->hpib_data = *addr++;
|
|
|
|
FHPIBWAIT(hd, IM_ROOM);
|
|
|
|
}
|
|
|
|
hd->hpib_stat = ST_EOI;
|
|
|
|
hd->hpib_data = *addr;
|
|
|
|
}
|
|
|
|
hd->hpib_imask = IM_IDLE;
|
|
|
|
}
|
|
|
|
hs->sc_flags |= HPIBF_DONE;
|
|
|
|
hd->hpib_stat = ST_IENAB;
|
|
|
|
hd->hpib_ie = IDS_IE;
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1996-02-14 05:43:54 +03:00
|
|
|
fhpibintr(arg)
|
|
|
|
void *arg;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = arg;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct hpibbus_softc *hs = sc->sc_hpibbus;
|
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
struct hpibqueue *hq;
|
|
|
|
int stat0;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
stat0 = hd->hpib_ids;
|
|
|
|
if ((stat0 & (IDS_IE|IDS_IR)) != (IDS_IE|IDS_IR)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if ((fhpibdebug & FDB_FAIL) && (stat0 & IDS_IR) &&
|
|
|
|
(hs->sc_flags & (HPIBF_IO|HPIBF_DONE)) != HPIBF_IO)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("%s: fhpibintr: bad status %x\n",
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_dev.dv_xname, stat0);
|
|
|
|
/* fhpibbadint[0]++; XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
if ((hs->sc_flags & (HPIBF_IO|HPIBF_DONE)) == HPIBF_IO) {
|
|
|
|
#ifdef DEBUG
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibbadint[1]++; XXX */
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
1997-04-03 02:37:21 +04:00
|
|
|
if ((fhpibdebug & FDB_DMA) && fhpibdebugunit == sc->sc_dev.dv_unit)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibintr: flags %x\n", hs->sc_flags);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
1997-01-30 12:06:51 +03:00
|
|
|
hq = hs->sc_queue.tqh_first;
|
1993-05-13 17:56:20 +04:00
|
|
|
if (hs->sc_flags & HPIBF_IO) {
|
1995-01-07 13:30:10 +03:00
|
|
|
if (hs->sc_flags & HPIBF_TIMO)
|
1997-01-30 12:06:51 +03:00
|
|
|
untimeout(fhpibdmadone, hs);
|
1993-05-13 17:56:20 +04:00
|
|
|
stat0 = hd->hpib_cmd;
|
1997-01-30 12:06:51 +03:00
|
|
|
hd->hpib_cmd = sc->sc_cmd & ~CT_8BIT;
|
1993-05-13 17:56:20 +04:00
|
|
|
hd->hpib_stat = 0;
|
|
|
|
hd->hpib_cmd = CT_REN | CT_8BIT;
|
|
|
|
stat0 = hd->hpib_intr;
|
|
|
|
hd->hpib_imask = 0;
|
1995-01-07 13:30:10 +03:00
|
|
|
hs->sc_flags &= ~(HPIBF_DONE|HPIBF_IO|HPIBF_READ|HPIBF_TIMO);
|
1997-01-30 12:06:51 +03:00
|
|
|
dmafree(hs->sc_dq);
|
|
|
|
(hq->hq_intr)(hq->hq_softc);
|
1993-05-13 17:56:20 +04:00
|
|
|
} else if (hs->sc_flags & HPIBF_PPOLL) {
|
|
|
|
stat0 = hd->hpib_intr;
|
|
|
|
#ifdef DEBUG
|
|
|
|
if ((fhpibdebug & FDB_FAIL) &&
|
|
|
|
doppollint && (stat0 & IM_PPRESP) == 0)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("%s: fhpibintr: bad intr reg %x\n",
|
1997-01-30 12:06:51 +03:00
|
|
|
sc->sc_dev.dv_xname, stat0);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
hd->hpib_stat = 0;
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
#ifdef DEBUG
|
1997-01-30 12:06:51 +03:00
|
|
|
stat0 = fhpibppoll(hs);
|
1997-04-03 02:37:21 +04:00
|
|
|
if ((fhpibdebug & FDB_PPOLL) &&
|
|
|
|
fhpibdebugunit == sc->sc_dev.dv_unit)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibintr: got PPOLL status %x\n", stat0);
|
1997-01-30 12:06:51 +03:00
|
|
|
if ((stat0 & (0x80 >> hq->hq_slave)) == 0) {
|
1994-05-23 09:58:16 +04:00
|
|
|
/*
|
|
|
|
* XXX give it another shot (68040)
|
|
|
|
*/
|
1997-01-30 12:06:51 +03:00
|
|
|
/* fhpibppollfail[unit]++; XXX */
|
1994-05-23 09:58:16 +04:00
|
|
|
DELAY(fhpibppolldelay);
|
1997-01-30 12:06:51 +03:00
|
|
|
stat0 = fhpibppoll(hs);
|
|
|
|
if ((stat0 & (0x80 >> hq->hq_slave)) == 0 &&
|
1997-04-03 02:37:21 +04:00
|
|
|
(fhpibdebug & FDB_PPOLL) &&
|
|
|
|
fhpibdebugunit == sc->sc_dev.dv_unit)
|
1996-10-13 07:14:05 +04:00
|
|
|
printf("fhpibintr: PPOLL: unit %d slave %d stat %x\n",
|
1997-04-03 02:37:21 +04:00
|
|
|
sc->sc_dev.dv_unit, hq->hq_slave, stat0);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
hs->sc_flags &= ~HPIBF_PPOLL;
|
1997-01-30 12:06:51 +03:00
|
|
|
(hq->hq_intr)(hq->hq_softc);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1997-01-30 12:06:51 +03:00
|
|
|
fhpibppoll(hs)
|
|
|
|
struct hpibbus_softc *hs;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
int ppoll;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
hd->hpib_stat = 0;
|
|
|
|
hd->hpib_psense = 0;
|
|
|
|
hd->hpib_pmask = 0xFF;
|
|
|
|
hd->hpib_imask = IM_PPRESP | IM_PABORT;
|
|
|
|
DELAY(25);
|
|
|
|
hd->hpib_intr = IM_PABORT;
|
|
|
|
ppoll = hd->hpib_data;
|
|
|
|
if (hd->hpib_intr & IM_PABORT)
|
|
|
|
ppoll = 0;
|
|
|
|
hd->hpib_imask = 0;
|
|
|
|
hd->hpib_pmask = 0;
|
|
|
|
hd->hpib_stat = ST_IENAB;
|
|
|
|
return(ppoll);
|
|
|
|
}
|
|
|
|
|
1995-11-19 20:57:15 +03:00
|
|
|
int
|
1993-05-13 17:56:20 +04:00
|
|
|
fhpibwait(hd, x)
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd;
|
1994-05-23 09:58:16 +04:00
|
|
|
int x;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
int timo = hpibtimeout;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
while ((hd->hpib_intr & x) == 0 && --timo)
|
1996-05-19 03:56:59 +04:00
|
|
|
DELAY(1);
|
1993-05-13 17:56:20 +04:00
|
|
|
if (timo == 0) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (fhpibdebug & FDB_FAIL)
|
1997-04-03 02:37:21 +04:00
|
|
|
printf("fhpibwait(%p, %x) timeout\n", hd, x);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-05-23 09:58:16 +04:00
|
|
|
* XXX: this will have to change if we ever allow more than one
|
1993-05-13 17:56:20 +04:00
|
|
|
* pending operation per HP-IB.
|
|
|
|
*/
|
1994-05-23 09:58:16 +04:00
|
|
|
void
|
1994-05-05 14:10:21 +04:00
|
|
|
fhpibppwatch(arg)
|
|
|
|
void *arg;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1997-03-31 11:32:14 +04:00
|
|
|
struct hpibbus_softc *hs = arg;
|
1997-01-30 12:06:51 +03:00
|
|
|
struct fhpib_softc *sc = (struct fhpib_softc *)hs->sc_dev.dv_parent;
|
1997-03-31 11:32:14 +04:00
|
|
|
struct fhpibdevice *hd = sc->sc_regs;
|
|
|
|
int slave;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
if ((hs->sc_flags & HPIBF_PPOLL) == 0)
|
|
|
|
return;
|
1997-01-30 12:06:51 +03:00
|
|
|
slave = (0x80 >> hs->sc_queue.tqh_first->hq_slave);
|
1993-05-13 17:56:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!doppollint) {
|
1997-01-30 12:06:51 +03:00
|
|
|
if (fhpibppoll(hs) & slave) {
|
1993-05-13 17:56:20 +04:00
|
|
|
hd->hpib_stat = ST_IENAB;
|
|
|
|
hd->hpib_imask = IM_IDLE | IM_ROOM;
|
|
|
|
} else
|
1997-01-30 12:06:51 +03:00
|
|
|
timeout(fhpibppwatch, sc, 1);
|
1993-05-13 17:56:20 +04:00
|
|
|
return;
|
|
|
|
}
|
1997-01-30 12:06:51 +03:00
|
|
|
if ((fhpibdebug & FDB_PPOLL) && sc->sc_dev.dv_unit == fhpibdebugunit)
|
|
|
|
printf("fhpibppwatch: sense request on %s\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
hd->hpib_psense = ~slave;
|
|
|
|
hd->hpib_pmask = slave;
|
|
|
|
hd->hpib_stat = ST_IENAB;
|
|
|
|
hd->hpib_imask = IM_PPRESP | IM_PABORT;
|
|
|
|
hd->hpib_ie = IDS_IE;
|
|
|
|
}
|