Do an indirect driver a little more like an indirect driver would like to

be done.  Set up a structure filled with function pointers in the
controller-specific probe routines, and jump through them, instead of
if()'ing our way though each operation.

Be a little more discriptive; print out the controller type found
during the probe in a way that's somewhat meaningful.
This commit is contained in:
thorpej 1995-11-19 17:57:15 +00:00
parent 9cd0c2cad7
commit d0e01feb5c
4 changed files with 182 additions and 70 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fhpib.c,v 1.6 1995/01/07 10:30:10 mycroft Exp $ */
/* $NetBSD: fhpib.c,v 1.7 1995/11/19 17:57:15 thorpej Exp $ */
/*
* Copyright (c) 1982, 1990, 1993
@ -79,6 +79,30 @@ long fhpibppollfail[NHPIB] = { 0 };
int fhpibcmd[NHPIB];
void fhpibreset __P((int));
int fhpibsend __P((int, int, int, void *, int));
int fhpibrecv __P((int, int, int, void *, int));
int fhpibppoll __P((int));
void fhpibppwatch __P((void *));
void fhpibgo __P((int, int, int, void *, int, int, int));
void fhpibdone __P((int));
int fhpibintr __P((int));
/*
* Our controller ops structure.
*/
struct hpib_controller fhpib_controller = {
fhpibreset,
fhpibsend,
fhpibrecv,
fhpibppoll,
fhpibppwatch,
fhpibgo,
fhpibdone,
fhpibintr
};
int
fhpibtype(hc)
register struct hp_ctlr *hc;
{
@ -87,12 +111,17 @@ fhpibtype(hc)
if (hd->hpib_cid != HPIBC)
return(0);
hs->sc_type = HPIBC;
hs->sc_ba = HPIBC_BA;
hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
hs->sc_controller = &fhpib_controller;
hs->sc_descrip = "98625A or 98625B fast HP-IB";
return(1);
}
void
fhpibreset(unit)
int unit;
{
@ -135,14 +164,16 @@ fhpibifc(hd)
hd->hpib_stat = ST_ATN;
}
fhpibsend(unit, slave, sec, addr, origcnt)
int
fhpibsend(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt;
register char *addr;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd;
register int cnt = origcnt;
register int timo;
char *addr = ptr;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
hd->hpib_stat = 0;
@ -197,14 +228,16 @@ senderr:
return (origcnt - cnt - 1);
}
fhpibrecv(unit, slave, sec, addr, origcnt)
int
fhpibrecv(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt;
register char *addr;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd;
register int cnt = origcnt;
register int timo;
char *addr = ptr;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
/*
@ -259,14 +292,15 @@ recvbyteserror:
return (origcnt - cnt - 1);
}
fhpibgo(unit, slave, sec, addr, count, rw, timo)
register int unit;
int slave, sec, count, rw;
char *addr;
void
fhpibgo(unit, slave, sec, ptr, count, rw, timo)
int unit, slave, sec, count, rw, timo;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd;
register int i;
char *addr = ptr;
int flags = 0;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
@ -381,6 +415,7 @@ fhpibdmadone(arg)
(void) splx(s);
}
void
fhpibdone(unit)
int unit;
{
@ -423,6 +458,7 @@ fhpibdone(unit)
hd->hpib_ie = IDS_IE;
}
int
fhpibintr(unit)
register int unit;
{
@ -499,6 +535,7 @@ fhpibintr(unit)
return(1);
}
int
fhpibppoll(unit)
int unit;
{
@ -521,6 +558,7 @@ fhpibppoll(unit)
return(ppoll);
}
int
fhpibwait(hd, x)
register struct fhpibdevice *hd;
int x;
@ -576,4 +614,4 @@ fhpibppwatch(arg)
hd->hpib_imask = IM_PPRESP | IM_PABORT;
hd->hpib_ie = IDS_IE;
}
#endif
#endif /* NHPIB > 0 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: hpib.c,v 1.5 1995/01/07 10:30:12 mycroft Exp $ */
/* $NetBSD: hpib.c,v 1.6 1995/11/19 17:57:17 thorpej Exp $ */
/*
* Copyright (c) 1982, 1990, 1993
@ -52,47 +52,66 @@
#include <machine/cpu.h>
#include <hp300/hp300/isr.h>
int hpibinit(), hpibstart(), hpibgo(), hpibintr(), hpibdone();
int hpibinit __P((struct hp_ctlr *));
void hpibstart __P((int));
void hpibgo __P((int, int, int, void *, int, int, int));
void hpibdone __P((int));
int hpibintr __P((int));
struct driver hpibdriver = {
hpibinit, "hpib", hpibstart, hpibgo, hpibintr, hpibdone,
hpibinit,
"hpib",
(int(*)())hpibstart, /* XXX */
(int(*)())hpibgo, /* XXX */
hpibintr,
(int(*)())hpibdone, /* XXX */
};
struct hpib_softc hpib_softc[NHPIB];
struct isr hpib_isr[NHPIB];
int nhpibppoll(), fhpibppoll();
extern int nhpibtype __P((struct hp_ctlr *)); /* XXX */
extern int fhpibtype __P((struct hp_ctlr *)); /* XXX */
int hpibtimeout = 100000; /* # of status tests before we give up */
int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */
int hpibdmathresh = 3; /* byte count beyond which to attempt dma */
int
hpibinit(hc)
register struct hp_ctlr *hc;
{
register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
if (!nhpibtype(hc) && !fhpibtype(hc))
if ((nhpibtype(hc) == 0) && (fhpibtype(hc) == 0))
return(0);
hs->sc_hc = hc;
hs->sc_dq.dq_unit = hc->hp_unit;
hs->sc_dq.dq_driver = &hpibdriver;
hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq;
/* Establish the interrupt handler. */
hpib_isr[hc->hp_unit].isr_intr = hpibintr;
hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
isrlink(&hpib_isr[hc->hp_unit]);
/* Reset the controller, display what we've seen, and we're done. */
hpibreset(hc->hp_unit);
printf("hpib%d: %s\n", hc->hp_unit, hs->sc_descrip);
return(1);
}
void
hpibreset(unit)
register int unit;
{
if (hpib_softc[unit].sc_type == HPIBC)
fhpibreset(unit);
else
nhpibreset(unit);
(hpib_softc[unit].sc_controller->hpib_reset)(unit);
}
int
hpibreq(dq)
register struct devqueue *dq;
{
@ -105,6 +124,7 @@ hpibreq(dq)
return(0);
}
void
hpibfree(dq)
register struct devqueue *dq;
{
@ -116,6 +136,7 @@ hpibfree(dq)
(dq->dq_driver->d_start)(dq->dq_unit);
}
int
hpibid(unit, slave)
int unit, slave;
{
@ -134,36 +155,37 @@ hpibid(unit, slave)
return(id);
}
int
hpibsend(unit, slave, sec, addr, cnt)
register int unit;
int slave, sec, addr, cnt;
int unit, slave, sec, cnt;
void *addr;
{
if (hpib_softc[unit].sc_type == HPIBC)
return(fhpibsend(unit, slave, sec, addr, cnt));
else
return(nhpibsend(unit, slave, sec, addr, cnt));
return ((hpib_softc[unit].sc_controller->hpib_send)(unit, slave,
sec, addr, cnt));
}
int
hpibrecv(unit, slave, sec, addr, cnt)
register int unit;
int slave, sec, addr, cnt;
int unit, slave, sec, cnt;
void *addr;
{
if (hpib_softc[unit].sc_type == HPIBC)
return(fhpibrecv(unit, slave, sec, addr, cnt));
else
return(nhpibrecv(unit, slave, sec, addr, cnt));
return ((hpib_softc[unit].sc_controller->hpib_recv)(unit, slave,
sec, addr, cnt));
}
int
hpibpptest(unit, slave)
register int unit;
int slave;
{
int (*ppoll)();
ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
return((*ppoll)(unit) & (0x80 >> slave));
return ((hpib_softc[unit].sc_controller->hpib_ppoll)(unit) &
(0x80 >> slave));
}
void
hpibppclear(unit)
int unit;
{
@ -176,20 +198,18 @@ hpibawait(unit)
register struct hpib_softc *hs = &hpib_softc[unit];
hs->sc_flags |= HPIBF_PPOLL;
if (hs->sc_type == HPIBC)
fhpibppwatch((void *)unit);
else
nhpibppwatch((void *)unit);
(hs->sc_controller->hpib_ppwatch)((void *)unit);
}
int
hpibswait(unit, slave)
register int unit;
int slave;
{
register int timo = hpibtimeout;
register int mask, (*ppoll)();
register int mask, (*ppoll) __P((int));
ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll;
ppoll = hpib_softc[unit].sc_controller->hpib_ppoll;
mask = 0x80 >> slave;
while (((ppoll)(unit) & mask) == 0)
if (--timo == 0) {
@ -199,6 +219,7 @@ hpibswait(unit, slave)
return(0);
}
int
hpibustart(unit)
int unit;
{
@ -213,6 +234,7 @@ hpibustart(unit)
return(0);
}
void
hpibstart(unit)
int unit;
{
@ -222,34 +244,29 @@ hpibstart(unit)
(dq->dq_driver->d_go)(dq->dq_unit);
}
void
hpibgo(unit, slave, sec, addr, count, rw, timo)
register int unit;
int slave, sec, addr, count, rw;
int unit, slave, sec, count, rw, timo;
void *addr;
{
if (hpib_softc[unit].sc_type == HPIBC)
fhpibgo(unit, slave, sec, addr, count, rw, timo);
else
nhpibgo(unit, slave, sec, addr, count, rw, timo);
(hpib_softc[unit].sc_controller->hpib_go)(unit, slave, sec,
addr, count, rw, timo);
}
void
hpibdone(unit)
register int unit;
{
if (hpib_softc[unit].sc_type == HPIBC)
fhpibdone(unit);
else
nhpibdone(unit);
(hpib_softc[unit].sc_controller->hpib_done)(unit);
}
int
hpibintr(unit)
register int unit;
{
int found;
if (hpib_softc[unit].sc_type == HPIBC)
found = fhpibintr(unit);
else
found = nhpibintr(unit);
return(found);
return ((hpib_softc[unit].sc_controller->hpib_intr)(unit));
}
#endif
#endif /* NHPIB > 0 */

View File

@ -1,4 +1,4 @@
/* $NetBSD: hpibvar.h,v 1.6 1995/03/28 18:16:09 jtc Exp $ */
/* $NetBSD: hpibvar.h,v 1.7 1995/11/19 17:57:18 thorpej Exp $ */
/*
* Copyright (c) 1982, 1990, 1993
@ -66,8 +66,25 @@
#define C_UNT_P 0xdf /* with odd parity */
#define C_SCG 0x60 /* Secondary group commands */
/*
* Each of the HP-IB controller drivers fills in this structure, which
* is used by the indirect driver to call controller-specific functions.
*/
struct hpib_controller {
void (*hpib_reset) __P((int));
int (*hpib_send) __P((int, int, int, void *, int));
int (*hpib_recv) __P((int, int, int, void *, int));
int (*hpib_ppoll) __P((int));
void (*hpib_ppwatch) __P((void *));
void (*hpib_go) __P((int, int, int, void *, int, int, int));
void (*hpib_done) __P((int));
int (*hpib_intr) __P((int));
};
struct hpib_softc {
struct hp_ctlr *sc_hc;
struct hpib_controller *sc_controller;
char *sc_descrip;
int sc_flags;
struct devqueue sc_dq;
struct devqueue sc_sq;
@ -91,6 +108,8 @@ extern struct hpib_softc hpib_softc[];
extern caddr_t internalhpib;
extern int hpibtimeout;
extern int hpibdmathresh;
void fhpibppwatch __P((void *arg));
void nhpibppwatch __P((void *arg));
void hpibreset __P((int));
int hpibsend __P((int, int, int, void *, int));
int hpibrecv __P((int, int, int, void *, int));
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: nhpib.c,v 1.6 1995/01/07 10:30:14 mycroft Exp $ */
/* $NetBSD: nhpib.c,v 1.7 1995/11/19 17:57:19 thorpej Exp $ */
/*
* Copyright (c) 1982, 1990, 1993
@ -74,6 +74,30 @@ static u_char sec_par[] = {
0370,0171,0172,0373,0174,0375,0376,0177
};
void nhpibreset __P((int));
int nhpibsend __P((int, int, int, void *, int));
int nhpibrecv __P((int, int, int, void *, int));
int nhpibppoll __P((int));
void nhpibppwatch __P((void *));
void nhpibgo __P((int, int, int, void *, int, int, int));
void nhpibdone __P((int));
int nhpibintr __P((int));
/*
* Our controller ops structure.
*/
struct hpib_controller nhpib_controller = {
nhpibreset,
nhpibsend,
nhpibrecv,
nhpibppoll,
nhpibppwatch,
nhpibgo,
nhpibdone,
nhpibintr
};
int
nhpibtype(hc)
register struct hp_ctlr *hc;
{
@ -84,17 +108,22 @@ nhpibtype(hc)
hs->sc_type = HPIBA;
hs->sc_ba = HPIBA_BA;
hc->hp_ipl = HPIBA_IPL;
hs->sc_descrip = "Internal HP-IB";
}
else if (hd->hpib_cid == HPIBB) {
hs->sc_type = HPIBB;
hs->sc_ba = hd->hpib_csa & CSA_BA;
hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
hs->sc_descrip = "98624 HP-IB";
}
else
return(0);
hs->sc_controller = &nhpib_controller;
return(1);
}
void
nhpibreset(unit)
int unit;
{
@ -132,13 +161,15 @@ nhpibifc(hd)
hd->hpib_acr = AUX_SSRE;
}
nhpibsend(unit, slave, sec, addr, origcnt)
int
nhpibsend(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt;
register char *addr;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd;
register int cnt = origcnt;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
hd->hpib_acr = AUX_TCA;
@ -188,13 +219,15 @@ senderror:
return(origcnt - cnt - 1);
}
nhpibrecv(unit, slave, sec, addr, origcnt)
int
nhpibrecv(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt;
register char *addr;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd;
register int cnt = origcnt;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
/*
@ -239,13 +272,14 @@ recvbyteserror:
return(origcnt - cnt - 1);
}
nhpibgo(unit, slave, sec, addr, count, rw, timo)
register int unit, slave;
int sec, count, rw;
char *addr;
void
nhpibgo(unit, slave, sec, ptr, count, rw, timo)
int unit, slave, sec, count, rw, timo;
void *ptr;
{
register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
hs->sc_flags |= HPIBF_IO;
@ -313,6 +347,7 @@ nhpibreadtimo(arg)
(void) splx(s);
}
void
nhpibdone(unit)
register int unit;
{
@ -344,6 +379,7 @@ nhpibdone(unit)
}
}
int
nhpibintr(unit)
register int unit;
{
@ -389,6 +425,7 @@ nhpibintr(unit)
return(1);
}
int
nhpibppoll(unit)
int unit;
{
@ -407,6 +444,7 @@ nhpibppoll(unit)
int nhpibreporttimo = 0;
#endif
int
nhpibwait(hd, x)
register struct nhpibdevice *hd;
int x;
@ -446,4 +484,4 @@ again:
else
timeout(nhpibppwatch, (void *)unit, 1);
}
#endif
#endif /* NHPIB > 0 */