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 * Copyright (c) 1982, 1990, 1993
@ -79,6 +79,30 @@ long fhpibppollfail[NHPIB] = { 0 };
int fhpibcmd[NHPIB]; 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) fhpibtype(hc)
register struct hp_ctlr *hc; register struct hp_ctlr *hc;
{ {
@ -87,12 +111,17 @@ fhpibtype(hc)
if (hd->hpib_cid != HPIBC) if (hd->hpib_cid != HPIBC)
return(0); return(0);
hs->sc_type = HPIBC; hs->sc_type = HPIBC;
hs->sc_ba = HPIBC_BA; hs->sc_ba = HPIBC_BA;
hc->hp_ipl = HPIB_IPL(hd->hpib_ids); hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
hs->sc_controller = &fhpib_controller;
hs->sc_descrip = "98625A or 98625B fast HP-IB";
return(1); return(1);
} }
void
fhpibreset(unit) fhpibreset(unit)
int unit; int unit;
{ {
@ -135,14 +164,16 @@ fhpibifc(hd)
hd->hpib_stat = ST_ATN; hd->hpib_stat = ST_ATN;
} }
fhpibsend(unit, slave, sec, addr, origcnt) int
fhpibsend(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt; int unit, slave, sec, origcnt;
register char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd; register struct fhpibdevice *hd;
register int cnt = origcnt; register int cnt = origcnt;
register int timo; register int timo;
char *addr = ptr;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr; hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
hd->hpib_stat = 0; hd->hpib_stat = 0;
@ -197,14 +228,16 @@ senderr:
return (origcnt - cnt - 1); return (origcnt - cnt - 1);
} }
fhpibrecv(unit, slave, sec, addr, origcnt) int
fhpibrecv(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt; int unit, slave, sec, origcnt;
register char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd; register struct fhpibdevice *hd;
register int cnt = origcnt; register int cnt = origcnt;
register int timo; register int timo;
char *addr = ptr;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr; hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
/* /*
@ -259,14 +292,15 @@ recvbyteserror:
return (origcnt - cnt - 1); return (origcnt - cnt - 1);
} }
fhpibgo(unit, slave, sec, addr, count, rw, timo) void
register int unit; fhpibgo(unit, slave, sec, ptr, count, rw, timo)
int slave, sec, count, rw; int unit, slave, sec, count, rw, timo;
char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct fhpibdevice *hd; register struct fhpibdevice *hd;
register int i; register int i;
char *addr = ptr;
int flags = 0; int flags = 0;
hd = (struct fhpibdevice *)hs->sc_hc->hp_addr; hd = (struct fhpibdevice *)hs->sc_hc->hp_addr;
@ -381,6 +415,7 @@ fhpibdmadone(arg)
(void) splx(s); (void) splx(s);
} }
void
fhpibdone(unit) fhpibdone(unit)
int unit; int unit;
{ {
@ -423,6 +458,7 @@ fhpibdone(unit)
hd->hpib_ie = IDS_IE; hd->hpib_ie = IDS_IE;
} }
int
fhpibintr(unit) fhpibintr(unit)
register int unit; register int unit;
{ {
@ -499,6 +535,7 @@ fhpibintr(unit)
return(1); return(1);
} }
int
fhpibppoll(unit) fhpibppoll(unit)
int unit; int unit;
{ {
@ -521,6 +558,7 @@ fhpibppoll(unit)
return(ppoll); return(ppoll);
} }
int
fhpibwait(hd, x) fhpibwait(hd, x)
register struct fhpibdevice *hd; register struct fhpibdevice *hd;
int x; int x;
@ -576,4 +614,4 @@ fhpibppwatch(arg)
hd->hpib_imask = IM_PPRESP | IM_PABORT; hd->hpib_imask = IM_PPRESP | IM_PABORT;
hd->hpib_ie = IDS_IE; 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 * Copyright (c) 1982, 1990, 1993
@ -52,47 +52,66 @@
#include <machine/cpu.h> #include <machine/cpu.h>
#include <hp300/hp300/isr.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 = { 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 hpib_softc hpib_softc[NHPIB];
struct isr hpib_isr[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 hpibtimeout = 100000; /* # of status tests before we give up */
int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */ int hpibidtimeout = 10000; /* # of status tests for hpibid() calls */
int hpibdmathresh = 3; /* byte count beyond which to attempt dma */ int hpibdmathresh = 3; /* byte count beyond which to attempt dma */
int
hpibinit(hc) hpibinit(hc)
register struct hp_ctlr *hc; register struct hp_ctlr *hc;
{ {
register struct hpib_softc *hs = &hpib_softc[hc->hp_unit]; register struct hpib_softc *hs = &hpib_softc[hc->hp_unit];
if (!nhpibtype(hc) && !fhpibtype(hc)) if ((nhpibtype(hc) == 0) && (fhpibtype(hc) == 0))
return(0); return(0);
hs->sc_hc = hc; hs->sc_hc = hc;
hs->sc_dq.dq_unit = hc->hp_unit; hs->sc_dq.dq_unit = hc->hp_unit;
hs->sc_dq.dq_driver = &hpibdriver; hs->sc_dq.dq_driver = &hpibdriver;
hs->sc_sq.dq_forw = hs->sc_sq.dq_back = &hs->sc_sq; 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_intr = hpibintr;
hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl; hpib_isr[hc->hp_unit].isr_ipl = hc->hp_ipl;
hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit; hpib_isr[hc->hp_unit].isr_arg = hc->hp_unit;
isrlink(&hpib_isr[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); hpibreset(hc->hp_unit);
printf("hpib%d: %s\n", hc->hp_unit, hs->sc_descrip);
return(1); return(1);
} }
void
hpibreset(unit) hpibreset(unit)
register int unit; register int unit;
{ {
if (hpib_softc[unit].sc_type == HPIBC)
fhpibreset(unit); (hpib_softc[unit].sc_controller->hpib_reset)(unit);
else
nhpibreset(unit);
} }
int
hpibreq(dq) hpibreq(dq)
register struct devqueue *dq; register struct devqueue *dq;
{ {
@ -105,6 +124,7 @@ hpibreq(dq)
return(0); return(0);
} }
void
hpibfree(dq) hpibfree(dq)
register struct devqueue *dq; register struct devqueue *dq;
{ {
@ -116,6 +136,7 @@ hpibfree(dq)
(dq->dq_driver->d_start)(dq->dq_unit); (dq->dq_driver->d_start)(dq->dq_unit);
} }
int
hpibid(unit, slave) hpibid(unit, slave)
int unit, slave; int unit, slave;
{ {
@ -134,36 +155,37 @@ hpibid(unit, slave)
return(id); return(id);
} }
int
hpibsend(unit, slave, sec, addr, cnt) hpibsend(unit, slave, sec, addr, cnt)
register int unit; int unit, slave, sec, cnt;
int slave, sec, addr, cnt; void *addr;
{ {
if (hpib_softc[unit].sc_type == HPIBC)
return(fhpibsend(unit, slave, sec, addr, cnt)); return ((hpib_softc[unit].sc_controller->hpib_send)(unit, slave,
else sec, addr, cnt));
return(nhpibsend(unit, slave, sec, addr, cnt));
} }
int
hpibrecv(unit, slave, sec, addr, cnt) hpibrecv(unit, slave, sec, addr, cnt)
register int unit; int unit, slave, sec, cnt;
int slave, sec, addr, cnt; void *addr;
{ {
if (hpib_softc[unit].sc_type == HPIBC)
return(fhpibrecv(unit, slave, sec, addr, cnt)); return ((hpib_softc[unit].sc_controller->hpib_recv)(unit, slave,
else sec, addr, cnt));
return(nhpibrecv(unit, slave, sec, addr, cnt));
} }
int
hpibpptest(unit, slave) hpibpptest(unit, slave)
register int unit; register int unit;
int slave; int slave;
{ {
int (*ppoll)();
ppoll = (hpib_softc[unit].sc_type == HPIBC) ? fhpibppoll : nhpibppoll; return ((hpib_softc[unit].sc_controller->hpib_ppoll)(unit) &
return((*ppoll)(unit) & (0x80 >> slave)); (0x80 >> slave));
} }
void
hpibppclear(unit) hpibppclear(unit)
int unit; int unit;
{ {
@ -176,20 +198,18 @@ hpibawait(unit)
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
hs->sc_flags |= HPIBF_PPOLL; hs->sc_flags |= HPIBF_PPOLL;
if (hs->sc_type == HPIBC) (hs->sc_controller->hpib_ppwatch)((void *)unit);
fhpibppwatch((void *)unit);
else
nhpibppwatch((void *)unit);
} }
int
hpibswait(unit, slave) hpibswait(unit, slave)
register int unit; register int unit;
int slave; int slave;
{ {
register int timo = hpibtimeout; 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; mask = 0x80 >> slave;
while (((ppoll)(unit) & mask) == 0) while (((ppoll)(unit) & mask) == 0)
if (--timo == 0) { if (--timo == 0) {
@ -199,6 +219,7 @@ hpibswait(unit, slave)
return(0); return(0);
} }
int
hpibustart(unit) hpibustart(unit)
int unit; int unit;
{ {
@ -213,6 +234,7 @@ hpibustart(unit)
return(0); return(0);
} }
void
hpibstart(unit) hpibstart(unit)
int unit; int unit;
{ {
@ -222,34 +244,29 @@ hpibstart(unit)
(dq->dq_driver->d_go)(dq->dq_unit); (dq->dq_driver->d_go)(dq->dq_unit);
} }
void
hpibgo(unit, slave, sec, addr, count, rw, timo) hpibgo(unit, slave, sec, addr, count, rw, timo)
register int unit; int unit, slave, sec, count, rw, timo;
int slave, sec, addr, count, rw; void *addr;
{ {
if (hpib_softc[unit].sc_type == HPIBC)
fhpibgo(unit, slave, sec, addr, count, rw, timo); (hpib_softc[unit].sc_controller->hpib_go)(unit, slave, sec,
else addr, count, rw, timo);
nhpibgo(unit, slave, sec, addr, count, rw, timo);
} }
void
hpibdone(unit) hpibdone(unit)
register int unit; register int unit;
{ {
if (hpib_softc[unit].sc_type == HPIBC)
fhpibdone(unit); (hpib_softc[unit].sc_controller->hpib_done)(unit);
else
nhpibdone(unit);
} }
int
hpibintr(unit) hpibintr(unit)
register int unit; register int unit;
{ {
int found;
if (hpib_softc[unit].sc_type == HPIBC) return ((hpib_softc[unit].sc_controller->hpib_intr)(unit));
found = fhpibintr(unit);
else
found = nhpibintr(unit);
return(found);
} }
#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 * Copyright (c) 1982, 1990, 1993
@ -66,8 +66,25 @@
#define C_UNT_P 0xdf /* with odd parity */ #define C_UNT_P 0xdf /* with odd parity */
#define C_SCG 0x60 /* Secondary group commands */ #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 hpib_softc {
struct hp_ctlr *sc_hc; struct hp_ctlr *sc_hc;
struct hpib_controller *sc_controller;
char *sc_descrip;
int sc_flags; int sc_flags;
struct devqueue sc_dq; struct devqueue sc_dq;
struct devqueue sc_sq; struct devqueue sc_sq;
@ -91,6 +108,8 @@ extern struct hpib_softc hpib_softc[];
extern caddr_t internalhpib; extern caddr_t internalhpib;
extern int hpibtimeout; extern int hpibtimeout;
extern int hpibdmathresh; 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 #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 * Copyright (c) 1982, 1990, 1993
@ -74,6 +74,30 @@ static u_char sec_par[] = {
0370,0171,0172,0373,0174,0375,0376,0177 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) nhpibtype(hc)
register struct hp_ctlr *hc; register struct hp_ctlr *hc;
{ {
@ -84,17 +108,22 @@ nhpibtype(hc)
hs->sc_type = HPIBA; hs->sc_type = HPIBA;
hs->sc_ba = HPIBA_BA; hs->sc_ba = HPIBA_BA;
hc->hp_ipl = HPIBA_IPL; hc->hp_ipl = HPIBA_IPL;
hs->sc_descrip = "Internal HP-IB";
} }
else if (hd->hpib_cid == HPIBB) { else if (hd->hpib_cid == HPIBB) {
hs->sc_type = HPIBB; hs->sc_type = HPIBB;
hs->sc_ba = hd->hpib_csa & CSA_BA; hs->sc_ba = hd->hpib_csa & CSA_BA;
hc->hp_ipl = HPIB_IPL(hd->hpib_ids); hc->hp_ipl = HPIB_IPL(hd->hpib_ids);
hs->sc_descrip = "98624 HP-IB";
} }
else else
return(0); return(0);
hs->sc_controller = &nhpib_controller;
return(1); return(1);
} }
void
nhpibreset(unit) nhpibreset(unit)
int unit; int unit;
{ {
@ -132,13 +161,15 @@ nhpibifc(hd)
hd->hpib_acr = AUX_SSRE; hd->hpib_acr = AUX_SSRE;
} }
nhpibsend(unit, slave, sec, addr, origcnt) int
nhpibsend(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt; int unit, slave, sec, origcnt;
register char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd; register struct nhpibdevice *hd;
register int cnt = origcnt; register int cnt = origcnt;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr; hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
hd->hpib_acr = AUX_TCA; hd->hpib_acr = AUX_TCA;
@ -188,13 +219,15 @@ senderror:
return(origcnt - cnt - 1); return(origcnt - cnt - 1);
} }
nhpibrecv(unit, slave, sec, addr, origcnt) int
nhpibrecv(unit, slave, sec, ptr, origcnt)
int unit, slave, sec, origcnt; int unit, slave, sec, origcnt;
register char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd; register struct nhpibdevice *hd;
register int cnt = origcnt; register int cnt = origcnt;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr; hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
/* /*
@ -239,13 +272,14 @@ recvbyteserror:
return(origcnt - cnt - 1); return(origcnt - cnt - 1);
} }
nhpibgo(unit, slave, sec, addr, count, rw, timo) void
register int unit, slave; nhpibgo(unit, slave, sec, ptr, count, rw, timo)
int sec, count, rw; int unit, slave, sec, count, rw, timo;
char *addr; void *ptr;
{ {
register struct hpib_softc *hs = &hpib_softc[unit]; register struct hpib_softc *hs = &hpib_softc[unit];
register struct nhpibdevice *hd; register struct nhpibdevice *hd;
char *addr = ptr;
hd = (struct nhpibdevice *)hs->sc_hc->hp_addr; hd = (struct nhpibdevice *)hs->sc_hc->hp_addr;
hs->sc_flags |= HPIBF_IO; hs->sc_flags |= HPIBF_IO;
@ -313,6 +347,7 @@ nhpibreadtimo(arg)
(void) splx(s); (void) splx(s);
} }
void
nhpibdone(unit) nhpibdone(unit)
register int unit; register int unit;
{ {
@ -344,6 +379,7 @@ nhpibdone(unit)
} }
} }
int
nhpibintr(unit) nhpibintr(unit)
register int unit; register int unit;
{ {
@ -389,6 +425,7 @@ nhpibintr(unit)
return(1); return(1);
} }
int
nhpibppoll(unit) nhpibppoll(unit)
int unit; int unit;
{ {
@ -407,6 +444,7 @@ nhpibppoll(unit)
int nhpibreporttimo = 0; int nhpibreporttimo = 0;
#endif #endif
int
nhpibwait(hd, x) nhpibwait(hd, x)
register struct nhpibdevice *hd; register struct nhpibdevice *hd;
int x; int x;
@ -446,4 +484,4 @@ again:
else else
timeout(nhpibppwatch, (void *)unit, 1); timeout(nhpibppwatch, (void *)unit, 1);
} }
#endif #endif /* NHPIB > 0 */