2005-02-12 17:39:50 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
|
2010-02-01 21:21:10 +00:00
|
|
|
* Copyright (c) 2010 Joerg Wunsch <joerg@FreeBSD.org>
|
2005-02-12 17:39:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
2012-01-15 13:23:43 +00:00
|
|
|
* High-level driver for µPD7210 based GPIB cards.
|
2005-02-12 17:39:50 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
# define IBDEBUG
|
|
|
|
# undef IBDEBUG
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <sys/module.h>
|
2010-02-01 21:21:10 +00:00
|
|
|
#include <sys/rman.h>
|
2005-02-12 17:39:50 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <isa/isavar.h>
|
|
|
|
|
|
|
|
#include <dev/ieee488/ugpib.h>
|
|
|
|
|
|
|
|
#define UPD7210_SW_DRIVER
|
|
|
|
#include <dev/ieee488/upd7210.h>
|
2010-02-01 21:21:10 +00:00
|
|
|
#include <dev/ieee488/tnt4882.h>
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
static MALLOC_DEFINE(M_IBFOO, "IBFOO", "IBFOO");
|
|
|
|
|
|
|
|
|
|
|
|
/* ibfoo API */
|
|
|
|
|
|
|
|
#include <dev/ieee488/ibfoo_int.h>
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
/* XXX: This is really a bitmap */
|
|
|
|
enum h_kind {
|
|
|
|
H_DEV = 1,
|
|
|
|
H_BOARD = 2,
|
|
|
|
H_EITHER = 3
|
|
|
|
};
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
struct handle {
|
|
|
|
LIST_ENTRY(handle) list;
|
|
|
|
int handle;
|
2005-02-12 23:52:44 +00:00
|
|
|
enum h_kind kind;
|
2005-02-12 17:39:50 +00:00
|
|
|
int pad;
|
|
|
|
int sad;
|
|
|
|
struct timeval timeout;
|
|
|
|
int eot;
|
|
|
|
int eos;
|
|
|
|
int dma;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibfoo {
|
2005-02-12 21:07:09 +00:00
|
|
|
struct upd7210 *u;
|
2005-02-12 17:39:50 +00:00
|
|
|
LIST_HEAD(,handle) handles;
|
|
|
|
struct unrhdr *unrhdr;
|
2005-02-12 21:07:09 +00:00
|
|
|
struct callout callout;
|
|
|
|
struct handle *h;
|
|
|
|
struct ibarg *ap;
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
IDLE,
|
2005-02-12 21:07:09 +00:00
|
|
|
BUSY,
|
2005-02-12 17:39:50 +00:00
|
|
|
PIO_IDATA,
|
|
|
|
PIO_ODATA,
|
2005-02-12 21:07:09 +00:00
|
|
|
PIO_CMD,
|
2010-02-01 21:21:10 +00:00
|
|
|
DMA_IDATA,
|
|
|
|
FIFO_IDATA,
|
|
|
|
FIFO_ODATA,
|
|
|
|
FIFO_CMD
|
2005-02-12 17:39:50 +00:00
|
|
|
} mode;
|
|
|
|
|
|
|
|
struct timeval deadline;
|
|
|
|
|
|
|
|
struct handle *rdh; /* addressed for read */
|
|
|
|
struct handle *wrh; /* addressed for write */
|
|
|
|
|
|
|
|
int doeoi;
|
|
|
|
|
|
|
|
u_char *buf;
|
|
|
|
u_int buflen;
|
|
|
|
};
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
typedef int ibhandler_t(struct ibfoo *ib);
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
static struct timeval timeouts[] = {
|
|
|
|
[TNONE] = { 0, 0},
|
|
|
|
[T10us] = { 0, 10},
|
|
|
|
[T30us] = { 0, 30},
|
|
|
|
[T100us] = { 0, 100},
|
|
|
|
[T300us] = { 0, 300},
|
|
|
|
[T1ms] = { 0, 1000},
|
|
|
|
[T3ms] = { 0, 3000},
|
|
|
|
[T10ms] = { 0, 10000},
|
|
|
|
[T30ms] = { 0, 30000},
|
|
|
|
[T100ms] = { 0, 100000},
|
|
|
|
[T300ms] = { 0, 300000},
|
|
|
|
[T1s] = { 1, 0},
|
|
|
|
[T3s] = { 3, 0},
|
|
|
|
[T10s] = { 10, 0},
|
|
|
|
[T30s] = { 30, 0},
|
|
|
|
[T100s] = { 100, 0},
|
|
|
|
[T300s] = { 300, 0},
|
|
|
|
[T1000s] = { 1000, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u_int max_timeouts = sizeof timeouts / sizeof timeouts[0];
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
static int ibdebug;
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ib_set_error(struct ibarg *ap, int error)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ap->__iberr == 0)
|
|
|
|
ap->__iberr = error;
|
|
|
|
ap->__ibsta |= ERR;
|
|
|
|
ap->__retval = ap->__ibsta;
|
|
|
|
return (0);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
static int
|
|
|
|
ib_had_timeout(struct ibarg *ap)
|
|
|
|
{
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
ib_set_error(ap, EABO);
|
|
|
|
ap->__ibsta |= TIMO;
|
|
|
|
ap->__retval = ap->__ibsta;
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
static int
|
|
|
|
ib_set_errno(struct ibarg *ap, int errno)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ap->__iberr == 0) {
|
|
|
|
ap->__iberr = EDVR;
|
|
|
|
ap->__ibcnt = errno;
|
|
|
|
}
|
|
|
|
ap->__ibsta |= ERR;
|
|
|
|
ap->__retval = ap->__ibsta;
|
|
|
|
return (0);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
static int
|
2010-02-01 21:21:10 +00:00
|
|
|
gpib_ib_irq(struct upd7210 *u, int isr_3)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
struct ibfoo *ib;
|
|
|
|
|
|
|
|
ib = u->ibfoo;
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
mtx_assert(&u->mutex, MA_OWNED);
|
2005-02-12 17:39:50 +00:00
|
|
|
switch (ib->mode) {
|
|
|
|
case PIO_CMD:
|
|
|
|
if (!(u->rreg[ISR2] & IXR2_CO))
|
|
|
|
return (0);
|
|
|
|
if (ib->buflen == 0)
|
|
|
|
break;
|
|
|
|
upd7210_wr(u, CDOR, *ib->buf);
|
|
|
|
ib->buf++;
|
|
|
|
ib->buflen--;
|
|
|
|
return (1);
|
|
|
|
case PIO_IDATA:
|
|
|
|
if (!(u->rreg[ISR1] & IXR1_DI))
|
|
|
|
return (0);
|
|
|
|
*ib->buf = upd7210_rd(u, DIR);
|
|
|
|
ib->buf++;
|
|
|
|
ib->buflen--;
|
|
|
|
if (ib->buflen == 0 || (u->rreg[ISR1] & IXR1_ENDRX))
|
|
|
|
break;
|
|
|
|
return (1);
|
|
|
|
case PIO_ODATA:
|
|
|
|
if (!(u->rreg[ISR1] & IXR1_DO))
|
|
|
|
return (0);
|
|
|
|
if (ib->buflen == 0)
|
|
|
|
break;
|
|
|
|
if (ib->buflen == 1 && ib->doeoi)
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_SEOI);
|
|
|
|
upd7210_wr(u, CDOR, *ib->buf);
|
|
|
|
ib->buf++;
|
|
|
|
ib->buflen--;
|
|
|
|
return (1);
|
|
|
|
case DMA_IDATA:
|
|
|
|
if (!(u->rreg[ISR1] & IXR1_ENDRX))
|
|
|
|
return (0);
|
|
|
|
break;
|
2010-02-01 21:21:10 +00:00
|
|
|
case FIFO_IDATA:
|
|
|
|
if (!(isr_3 & 0x15))
|
|
|
|
return (0);
|
|
|
|
while (ib->buflen != 0 && (isr_3 & 0x04 /* NEF */) != 0) {
|
|
|
|
*ib->buf = bus_read_1(u->reg_res[0], fifob);
|
|
|
|
ib->buf++;
|
|
|
|
ib->buflen--;
|
|
|
|
isr_3 = bus_read_1(u->reg_res[0], isr3);
|
|
|
|
}
|
|
|
|
if ((isr_3 & 0x01) != 0 /* xfr done */ ||
|
|
|
|
(u->rreg[ISR1] & IXR1_ENDRX) != 0 ||
|
|
|
|
ib->buflen == 0)
|
|
|
|
break;
|
|
|
|
if (isr_3 & 0x10)
|
|
|
|
/* xfr stopped */
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x04); /* GO */
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_RFD);
|
|
|
|
return (1);
|
|
|
|
case FIFO_CMD:
|
|
|
|
case FIFO_ODATA:
|
|
|
|
if (!(isr_3 & 0x19))
|
|
|
|
return (0);
|
|
|
|
if (ib->buflen == 0)
|
|
|
|
/* xfr DONE */
|
|
|
|
break;
|
|
|
|
while (ib->buflen != 0 && (isr_3 & 0x08 /* NFF */) != 0) {
|
|
|
|
bus_write_1(u->reg_res[0], fifob, *ib->buf);
|
|
|
|
ib->buf++;
|
|
|
|
ib->buflen--;
|
|
|
|
isr_3 = bus_read_1(u->reg_res[0], isr3);
|
|
|
|
}
|
|
|
|
if (isr_3 & 0x10)
|
|
|
|
/* xfr stopped */
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x04); /* GO */
|
|
|
|
if (ib->buflen == 0)
|
|
|
|
/* no more NFF interrupts wanted */
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x11); /* STOP IE, DONE IE */
|
|
|
|
return (1);
|
2005-02-12 17:39:50 +00:00
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
upd7210_wr(u, IMR1, 0);
|
|
|
|
upd7210_wr(u, IMR2, 0);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x00);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x22); /* soft RESET */
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->mode = BUSY;
|
|
|
|
wakeup(&ib->buflen);
|
2005-02-12 17:39:50 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
static void
|
|
|
|
gpib_ib_timeout(void *arg)
|
|
|
|
{
|
|
|
|
struct upd7210 *u;
|
|
|
|
struct ibfoo *ib;
|
|
|
|
struct timeval tv;
|
2010-02-01 21:21:10 +00:00
|
|
|
u_int isr_3;
|
2005-02-12 21:07:09 +00:00
|
|
|
|
|
|
|
u = arg;
|
|
|
|
ib = u->ibfoo;
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
if (ib->mode == DMA_IDATA && isa_dmatc(u->dmachan)) {
|
2005-02-12 23:52:44 +00:00
|
|
|
KASSERT(u->dmachan >= 0, ("Bogus dmachan = %d", u->dmachan));
|
2005-02-12 21:07:09 +00:00
|
|
|
upd7210_wr(u, IMR1, 0);
|
|
|
|
upd7210_wr(u, IMR2, 0);
|
2005-03-06 19:43:12 +00:00
|
|
|
ib->mode = BUSY;
|
2005-02-12 21:07:09 +00:00
|
|
|
wakeup(&ib->buflen);
|
|
|
|
}
|
|
|
|
if (ib->mode > BUSY) {
|
|
|
|
upd7210_rd(u, ISR1);
|
|
|
|
upd7210_rd(u, ISR2);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo)
|
|
|
|
isr_3 = bus_read_1(u->reg_res[0], isr3);
|
|
|
|
else
|
|
|
|
isr_3 = 0;
|
|
|
|
gpib_ib_irq(u, isr_3);
|
2005-02-12 21:07:09 +00:00
|
|
|
}
|
|
|
|
if (ib->mode != IDLE && timevalisset(&ib->deadline)) {
|
|
|
|
getmicrouptime(&tv);
|
|
|
|
if (timevalcmp(&ib->deadline, &tv, <)) {
|
|
|
|
ib_had_timeout(ib->ap);
|
|
|
|
upd7210_wr(u, IMR1, 0);
|
|
|
|
upd7210_wr(u, IMR2, 0);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x00);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x22); /* soft RESET */
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->mode = BUSY;
|
|
|
|
wakeup(&ib->buflen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ib->mode != IDLE)
|
2005-03-06 19:43:12 +00:00
|
|
|
callout_reset(&ib->callout, hz / 5, gpib_ib_timeout, arg);
|
2005-02-12 21:07:09 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gpib_ib_wait_xfer(struct upd7210 *u, struct ibfoo *ib)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mtx_assert(&u->mutex, MA_OWNED);
|
|
|
|
while (ib->mode > BUSY) {
|
|
|
|
i = msleep(&ib->buflen, &u->mutex,
|
|
|
|
PZERO | PCATCH, "ibwxfr", 0);
|
|
|
|
if (i == EINTR) {
|
|
|
|
ib_set_errno(ib->ap, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (u->rreg[ISR1] & IXR1_ERR) {
|
|
|
|
ib_set_error(ib->ap, EABO); /* XXX ? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 22:20:11 +00:00
|
|
|
if ((u->rreg[ISR1] & IXR1_ENDRX) != 0) {
|
|
|
|
ib->ap->__retval |= END;
|
|
|
|
ib->ap->__ibsta |= END;
|
|
|
|
}
|
|
|
|
if ((u->rreg[ISR2] & IXR2_SRQI) != 0) {
|
|
|
|
ib->ap->__retval |= SRQI;
|
|
|
|
ib->ap->__ibsta |= SRQI;
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->mode = BUSY;
|
|
|
|
ib->buf = NULL;
|
|
|
|
upd7210_wr(u, IMR1, 0);
|
|
|
|
upd7210_wr(u, IMR2, 0);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo)
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x00);
|
2005-02-12 21:07:09 +00:00
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
static void
|
|
|
|
config_eos(struct upd7210 *u, struct handle *h)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
if (h->eos & REOS) {
|
|
|
|
upd7210_wr(u, EOSR, h->eos & 0xff);
|
|
|
|
i |= AUXA_REOS;
|
|
|
|
}
|
|
|
|
if (h->eos & XEOS) {
|
|
|
|
upd7210_wr(u, EOSR, h->eos & 0xff);
|
|
|
|
i |= AUXA_XEOS;
|
|
|
|
}
|
|
|
|
if (h->eos & BIN)
|
|
|
|
i |= AUXA_BIN;
|
|
|
|
upd7210_wr(u, AUXRA, C_AUXA | i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up the handle, and set the deadline if the handle has a timeout.
|
|
|
|
*/
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
gethandle(struct upd7210 *u, struct ibarg *ap, struct handle **hp)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
struct ibfoo *ib;
|
|
|
|
struct handle *h;
|
|
|
|
|
|
|
|
KASSERT(ap->__field & __F_HANDLE, ("gethandle without __F_HANDLE"));
|
|
|
|
ib = u->ibfoo;
|
|
|
|
LIST_FOREACH(h, &ib->handles, list) {
|
|
|
|
if (h->handle == ap->handle) {
|
|
|
|
*hp = h;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
ib_set_error(ap, EARG);
|
2005-02-12 17:39:50 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pio_cmd(struct upd7210 *u, u_char *cmd, int len)
|
|
|
|
{
|
|
|
|
struct ibfoo *ib;
|
|
|
|
|
|
|
|
ib = u->ibfoo;
|
|
|
|
|
|
|
|
if (ib->rdh != NULL || ib->wrh != NULL) {
|
|
|
|
upd7210_take_ctrl_async(u);
|
|
|
|
ib->rdh = NULL;
|
|
|
|
ib->wrh = NULL;
|
|
|
|
}
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
ib->buf = cmd;
|
|
|
|
ib->buflen = len;
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
/* TNT5004 or TNT4882 in FIFO mode */
|
|
|
|
ib->mode = FIFO_CMD;
|
|
|
|
upd7210_wr(u, AUXMR, 0x51); /* holdoff immediately */
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x10); /* reset FIFO */
|
|
|
|
bus_write_1(u->reg_res[0], cfg, 0x80); /* CMD, xfer OUT, 8-bit FIFO */
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x19); /* STOP IE, NFF IE, DONE IE */
|
|
|
|
bus_write_1(u->reg_res[0], cnt0, -len);
|
|
|
|
bus_write_1(u->reg_res[0], cnt1, (-len) >> 8);
|
|
|
|
bus_write_1(u->reg_res[0], cnt2, (-len) >> 16);
|
|
|
|
bus_write_1(u->reg_res[0], cnt3, (-len) >> 24);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x04); /* GO */
|
|
|
|
} else {
|
|
|
|
ib->mode = PIO_CMD;
|
|
|
|
upd7210_wr(u, IMR2, IXR2_CO);
|
|
|
|
gpib_ib_irq(u, 0);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
gpib_ib_wait_xfer(u, ib);
|
|
|
|
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo)
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x08); /* STOP */
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
2005-02-12 21:07:09 +00:00
|
|
|
return (len - ib->buflen);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pio_odata(struct upd7210 *u, u_char *data, int len)
|
|
|
|
{
|
|
|
|
struct ibfoo *ib;
|
|
|
|
|
|
|
|
ib = u->ibfoo;
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return (0);
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
ib->buf = data;
|
|
|
|
ib->buflen = len;
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
/* TNT5004 or TNT4882 in FIFO mode */
|
|
|
|
ib->mode = FIFO_ODATA;
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x10); /* reset FIFO */
|
|
|
|
if (ib->doeoi)
|
|
|
|
bus_write_1(u->reg_res[0], cfg, 0x08); /* CCEN */
|
|
|
|
else
|
|
|
|
bus_write_1(u->reg_res[0], cfg, 0x00); /* xfer OUT, 8-bit FIFO */
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x19); /* STOP IE, NFF IE, DONE IE */
|
|
|
|
bus_write_1(u->reg_res[0], cnt0, -len);
|
|
|
|
bus_write_1(u->reg_res[0], cnt1, (-len) >> 8);
|
|
|
|
bus_write_1(u->reg_res[0], cnt2, (-len) >> 16);
|
|
|
|
bus_write_1(u->reg_res[0], cnt3, (-len) >> 24);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x04); /* GO */
|
|
|
|
} else {
|
|
|
|
ib->mode = PIO_ODATA;
|
|
|
|
upd7210_wr(u, IMR1, IXR1_DO);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
gpib_ib_wait_xfer(u, ib);
|
|
|
|
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo)
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x08); /* STOP */
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (len - ib->buflen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pio_idata(struct upd7210 *u, u_char *data, int len)
|
|
|
|
{
|
|
|
|
struct ibfoo *ib;
|
|
|
|
|
|
|
|
ib = u->ibfoo;
|
|
|
|
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
ib->buf = data;
|
|
|
|
ib->buflen = len;
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
/* TNT5004 or TNT4882 in FIFO mode */
|
|
|
|
ib->mode = FIFO_IDATA;
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x10); /* reset FIFO */
|
|
|
|
bus_write_1(u->reg_res[0], cfg, 0x20); /* xfer IN, 8-bit FIFO */
|
|
|
|
bus_write_1(u->reg_res[0], cnt0, -len);
|
|
|
|
bus_write_1(u->reg_res[0], cnt1, (-len) >> 8);
|
|
|
|
bus_write_1(u->reg_res[0], cnt2, (-len) >> 16);
|
|
|
|
bus_write_1(u->reg_res[0], cnt3, (-len) >> 24);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x04); /* GO */
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_RFD);
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x15); /* STOP IE, NEF IE, DONE IE */
|
|
|
|
} else {
|
|
|
|
ib->mode = PIO_IDATA;
|
|
|
|
upd7210_wr(u, IMR1, IXR1_DI);
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
|
|
|
|
gpib_ib_wait_xfer(u, ib);
|
|
|
|
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo)
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x08); /* STOP */
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
2005-02-12 21:07:09 +00:00
|
|
|
return (len - ib->buflen);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
dma_idata(struct upd7210 *u, u_char *data, int len)
|
|
|
|
{
|
2005-02-12 21:07:09 +00:00
|
|
|
int j;
|
2005-02-12 17:39:50 +00:00
|
|
|
struct ibfoo *ib;
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
KASSERT(u->dmachan >= 0, ("Bogus dmachan %d", u->dmachan));
|
2005-02-12 17:39:50 +00:00
|
|
|
ib = u->ibfoo;
|
|
|
|
ib->mode = DMA_IDATA;
|
|
|
|
isa_dmastart(ISADMA_READ, data, len, u->dmachan);
|
|
|
|
mtx_lock(&u->mutex);
|
2005-02-12 21:07:09 +00:00
|
|
|
upd7210_wr(u, IMR1, IXR1_ENDRX);
|
2005-02-12 17:39:50 +00:00
|
|
|
upd7210_wr(u, IMR2, IMR2_DMAI);
|
2005-02-12 21:07:09 +00:00
|
|
|
gpib_ib_wait_xfer(u, ib);
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
j = isa_dmastatus(u->dmachan);
|
|
|
|
isa_dmadone(ISADMA_READ, data, len, u->dmachan);
|
2005-02-12 21:07:09 +00:00
|
|
|
return (len - j);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
static int
|
|
|
|
ib_send_msg(struct ibfoo *ib, int msg)
|
|
|
|
{
|
|
|
|
u_char buf[10];
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
buf[i++] = UNT;
|
|
|
|
buf[i++] = UNL;
|
|
|
|
buf[i++] = LAD | ib->h->pad;
|
|
|
|
if (ib->h->sad)
|
|
|
|
buf[i++] = LAD | TAD | ib->h->sad;
|
|
|
|
buf[i++] = TAD | 0;
|
|
|
|
buf[i++] = msg;
|
|
|
|
j = pio_cmd(ib->u, buf, i);
|
|
|
|
if (i != j)
|
|
|
|
ib_set_error(ib->ap, EABO); /* XXX ? */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibask(struct ibfoo *ib)
|
|
|
|
{ /* XXX */
|
|
|
|
|
|
|
|
ibdebug = ib->ap->option;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibbna NULL
|
|
|
|
#define ibcac NULL
|
2005-02-12 23:52:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ibclr(struct ibfoo *ib)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ib_send_msg(ib, SDC));
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibcmd NULL
|
|
|
|
#define ibcmda NULL
|
|
|
|
#define ibconfig NULL
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibdev(struct ibfoo *ib)
|
2005-02-12 23:52:44 +00:00
|
|
|
{ /* TBD */
|
2005-02-12 21:07:09 +00:00
|
|
|
struct handle *h;
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
h = malloc(sizeof *h, M_IBFOO, M_ZERO | M_WAITOK);
|
|
|
|
h->handle = alloc_unr(ib->unrhdr);
|
2005-02-12 23:52:44 +00:00
|
|
|
h->kind = H_DEV;
|
2005-02-12 21:07:09 +00:00
|
|
|
h->pad = ib->ap->pad;
|
|
|
|
h->sad = ib->ap->sad;
|
|
|
|
h->timeout = timeouts[ib->ap->tmo];
|
|
|
|
h->eot = ib->ap->eot;
|
|
|
|
h->eos = ib->ap->eos;
|
|
|
|
mtx_lock(&ib->u->mutex);
|
2005-02-12 17:39:50 +00:00
|
|
|
LIST_INSERT_HEAD(&ib->handles, h, list);
|
2005-02-12 21:07:09 +00:00
|
|
|
mtx_unlock(&ib->u->mutex);
|
|
|
|
ib->ap->__retval = h->handle;
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ibdiag NULL
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibdma(struct ibfoo *ib)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ib->u->dmachan < 0 && ib->ap->v)
|
|
|
|
return (ib_set_error(ib->ap, EARG));
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->h->dma = ib->ap->v;
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibeos(struct ibfoo *ib)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
ib->ap->__iberr = ib->h->eos;
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->h->eos = ib->ap->eos;
|
|
|
|
if (ib->rdh == ib->h)
|
|
|
|
config_eos(ib->u, ib->h);
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibeot(struct ibfoo *ib)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->h->eot = ib->ap->eot;
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ibevent NULL
|
|
|
|
#define ibfind NULL
|
|
|
|
#define ibgts NULL
|
|
|
|
#define ibist NULL
|
|
|
|
#define iblines NULL
|
|
|
|
#define ibllo NULL
|
|
|
|
#define ibln NULL
|
2005-02-12 23:52:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ibloc(struct ibfoo *ib)
|
|
|
|
{ /* XXX */
|
|
|
|
|
|
|
|
if (ib->h->kind == H_BOARD)
|
|
|
|
return (EOPNOTSUPP); /* XXX */
|
|
|
|
return (ib_send_msg(ib, GTL));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibonl(struct ibfoo *ib)
|
|
|
|
{ /* XXX */
|
|
|
|
|
|
|
|
if (ib->ap->v)
|
|
|
|
return (EOPNOTSUPP); /* XXX */
|
|
|
|
mtx_lock(&ib->u->mutex);
|
|
|
|
LIST_REMOVE(ib->h, list);
|
|
|
|
mtx_unlock(&ib->u->mutex);
|
|
|
|
free(ib->h, M_IBFOO);
|
|
|
|
ib->h = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ibpad(struct ibfoo *ib)
|
|
|
|
{
|
|
|
|
|
|
|
|
ib->h->pad = ib->ap->pad;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibpct NULL
|
|
|
|
#define ibpoke NULL
|
|
|
|
#define ibppc NULL
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibrd(struct ibfoo *ib)
|
2005-02-12 23:52:44 +00:00
|
|
|
{ /* TBD */
|
2005-02-12 17:39:50 +00:00
|
|
|
u_char buf[10], *bp;
|
|
|
|
int i, j, error, bl, bc;
|
|
|
|
u_char *dp;
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ib->h->kind == H_BOARD)
|
|
|
|
return (EOPNOTSUPP); /* XXX */
|
2005-02-12 21:07:09 +00:00
|
|
|
bl = ib->ap->cnt;
|
2005-02-12 17:39:50 +00:00
|
|
|
if (bl > PAGE_SIZE)
|
|
|
|
bl = PAGE_SIZE;
|
|
|
|
bp = malloc(bl, M_IBFOO, M_WAITOK);
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ib->rdh != ib->h) {
|
2005-02-12 17:39:50 +00:00
|
|
|
i = 0;
|
|
|
|
buf[i++] = UNT;
|
|
|
|
buf[i++] = UNL;
|
|
|
|
buf[i++] = LAD | 0;
|
2005-02-12 21:07:09 +00:00
|
|
|
buf[i++] = TAD | ib->h->pad;
|
|
|
|
if (ib->h->sad)
|
|
|
|
buf[i++] = ib->h->sad;
|
|
|
|
i = pio_cmd(ib->u, buf, i);
|
|
|
|
config_eos(ib->u, ib->h);
|
|
|
|
ib->rdh = ib->h;
|
2005-02-12 17:39:50 +00:00
|
|
|
ib->wrh = NULL;
|
|
|
|
}
|
2005-03-06 19:43:12 +00:00
|
|
|
upd7210_goto_standby(ib->u);
|
2005-02-12 21:07:09 +00:00
|
|
|
dp = ib->ap->buffer;
|
|
|
|
bc = ib->ap->cnt;
|
2005-02-12 17:39:50 +00:00
|
|
|
error = 0;
|
2005-02-12 21:07:09 +00:00
|
|
|
while (bc > 0 && ib->ap->__iberr == 0) {
|
2005-02-12 17:39:50 +00:00
|
|
|
j = imin(bc, PAGE_SIZE);
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ib->h->dma)
|
|
|
|
i = dma_idata(ib->u, bp, j);
|
2005-02-12 17:39:50 +00:00
|
|
|
else
|
2005-02-12 21:07:09 +00:00
|
|
|
i = pio_idata(ib->u, bp, j);
|
2005-02-12 17:39:50 +00:00
|
|
|
error = copyout(bp, dp , i);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->ap->__ibcnt += i;
|
2005-02-12 17:39:50 +00:00
|
|
|
if (i != j)
|
|
|
|
break;
|
|
|
|
bc -= i;
|
|
|
|
dp += i;
|
|
|
|
}
|
2005-03-06 19:43:12 +00:00
|
|
|
upd7210_take_ctrl_async(ib->u);
|
2005-02-12 17:39:50 +00:00
|
|
|
free(bp, M_IBFOO);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ibrda NULL
|
|
|
|
#define ibrdf NULL
|
|
|
|
#define ibrdkey NULL
|
|
|
|
#define ibrpp NULL
|
|
|
|
#define ibrsc NULL
|
|
|
|
#define ibrsp NULL
|
|
|
|
#define ibrsv NULL
|
2005-02-12 23:52:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ibsad(struct ibfoo *ib)
|
|
|
|
{
|
|
|
|
|
|
|
|
ib->h->sad = ib->ap->sad;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibsgnl NULL
|
2005-02-12 23:52:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ibsic(struct ibfoo *ib)
|
|
|
|
{ /* TBD */
|
|
|
|
|
|
|
|
upd7210_wr(ib->u, AUXMR, AUXMR_SIFC);
|
|
|
|
DELAY(100);
|
|
|
|
upd7210_wr(ib->u, AUXMR, AUXMR_CIFC);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibsre NULL
|
|
|
|
#define ibsrq NULL
|
|
|
|
#define ibstop NULL
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibtmo(struct ibfoo *ib)
|
2005-02-12 17:39:50 +00:00
|
|
|
{
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->h->timeout = timeouts[ib->ap->tmo];
|
2005-02-12 17:39:50 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ibtrap NULL
|
2005-02-12 23:52:44 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
ibtrg(struct ibfoo *ib)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ib_send_msg(ib, GET));
|
|
|
|
}
|
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
#define ibwait NULL
|
|
|
|
|
|
|
|
static int
|
2005-02-12 21:07:09 +00:00
|
|
|
ibwrt(struct ibfoo *ib)
|
2005-02-12 23:52:44 +00:00
|
|
|
{ /* XXX */
|
2005-02-12 17:39:50 +00:00
|
|
|
u_char buf[10], *bp;
|
|
|
|
int i;
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ib->h->kind == H_BOARD)
|
|
|
|
return (EOPNOTSUPP);
|
2005-02-12 21:07:09 +00:00
|
|
|
bp = malloc(ib->ap->cnt, M_IBFOO, M_WAITOK);
|
|
|
|
/* XXX: bigger than PAGE_SIZE handling */
|
|
|
|
i = copyin(ib->ap->buffer, bp, ib->ap->cnt);
|
2005-02-12 17:39:50 +00:00
|
|
|
if (i) {
|
|
|
|
free(bp, M_IBFOO);
|
|
|
|
return (i);
|
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ib->wrh != ib->h) {
|
2005-02-12 17:39:50 +00:00
|
|
|
i = 0;
|
|
|
|
buf[i++] = UNT;
|
|
|
|
buf[i++] = UNL;
|
2005-02-12 21:07:09 +00:00
|
|
|
buf[i++] = LAD | ib->h->pad;
|
|
|
|
if (ib->h->sad)
|
|
|
|
buf[i++] = LAD | TAD | ib->h->sad;
|
2005-02-12 17:39:50 +00:00
|
|
|
buf[i++] = TAD | 0;
|
2005-02-12 21:07:09 +00:00
|
|
|
i = pio_cmd(ib->u, buf, i);
|
2005-02-12 17:39:50 +00:00
|
|
|
ib->rdh = NULL;
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->wrh = ib->h;
|
|
|
|
config_eos(ib->u, ib->h);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
2005-03-06 19:43:12 +00:00
|
|
|
upd7210_goto_standby(ib->u);
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->doeoi = ib->h->eot;
|
|
|
|
i = pio_odata(ib->u, bp, ib->ap->cnt);
|
2005-03-06 19:43:12 +00:00
|
|
|
upd7210_take_ctrl_async(ib->u);
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->ap->__ibcnt = i;
|
2005-02-12 17:39:50 +00:00
|
|
|
free(bp, M_IBFOO);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ibwrta NULL
|
|
|
|
#define ibwrtf NULL
|
|
|
|
#define ibwrtkey NULL
|
|
|
|
#define ibxtrc NULL
|
|
|
|
|
|
|
|
static struct ibhandler {
|
|
|
|
const char *name;
|
2005-02-12 23:52:44 +00:00
|
|
|
enum h_kind kind;
|
2005-02-12 17:39:50 +00:00
|
|
|
ibhandler_t *func;
|
|
|
|
u_int args;
|
|
|
|
} ibhandlers[] = {
|
2005-02-12 23:52:44 +00:00
|
|
|
[__ID_IBASK] = { "ibask", H_EITHER, ibask, __F_HANDLE | __F_OPTION | __F_RETVAL },
|
|
|
|
[__ID_IBBNA] = { "ibbna", H_DEV, ibbna, __F_HANDLE | __F_BDNAME },
|
|
|
|
[__ID_IBCAC] = { "ibcac", H_BOARD, ibcac, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBCLR] = { "ibclr", H_DEV, ibclr, __F_HANDLE },
|
|
|
|
[__ID_IBCMD] = { "ibcmd", H_BOARD, ibcmd, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBCMDA] = { "ibcmda", H_BOARD, ibcmda, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBCONFIG] = { "ibconfig", H_EITHER, ibconfig, __F_HANDLE | __F_OPTION | __F_VALUE },
|
|
|
|
[__ID_IBDEV] = { "ibdev", 0, ibdev, __F_BOARDID | __F_PAD | __F_SAD | __F_TMO | __F_EOT | __F_EOS },
|
|
|
|
[__ID_IBDIAG] = { "ibdiag", H_EITHER, ibdiag, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBDMA] = { "ibdma", H_EITHER, ibdma, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBEOS] = { "ibeos", H_EITHER, ibeos, __F_HANDLE | __F_EOS },
|
|
|
|
[__ID_IBEOT] = { "ibeot", H_EITHER, ibeot, __F_HANDLE | __F_EOT },
|
|
|
|
[__ID_IBEVENT] = { "ibevent", H_BOARD, ibevent, __F_HANDLE | __F_EVENT },
|
|
|
|
[__ID_IBFIND] = { "ibfind", 0, ibfind, __F_BDNAME },
|
|
|
|
[__ID_IBGTS] = { "ibgts", H_BOARD, ibgts, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBIST] = { "ibist", H_BOARD, ibist, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBLINES] = { "iblines", H_BOARD, iblines, __F_HANDLE | __F_LINES },
|
|
|
|
[__ID_IBLLO] = { "ibllo", H_EITHER, ibllo, __F_HANDLE },
|
|
|
|
[__ID_IBLN] = { "ibln", H_BOARD, ibln, __F_HANDLE | __F_PADVAL | __F_SADVAL | __F_LISTENFLAG },
|
|
|
|
[__ID_IBLOC] = { "ibloc", H_EITHER, ibloc, __F_HANDLE },
|
|
|
|
[__ID_IBONL] = { "ibonl", H_EITHER, ibonl, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBPAD] = { "ibpad", H_EITHER, ibpad, __F_HANDLE | __F_PAD },
|
|
|
|
[__ID_IBPCT] = { "ibpct", H_DEV, ibpct, __F_HANDLE },
|
|
|
|
[__ID_IBPOKE] = { "ibpoke", H_EITHER, ibpoke, __F_HANDLE | __F_OPTION | __F_VALUE },
|
|
|
|
[__ID_IBPPC] = { "ibppc", H_EITHER, ibppc, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBRD] = { "ibrd", H_EITHER, ibrd, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBRDA] = { "ibrda", H_EITHER, ibrda, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBRDF] = { "ibrdf", H_EITHER, ibrdf, __F_HANDLE | __F_FLNAME },
|
|
|
|
[__ID_IBRDKEY] = { "ibrdkey", H_EITHER, ibrdkey, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBRPP] = { "ibrpp", H_EITHER, ibrpp, __F_HANDLE | __F_PPR },
|
|
|
|
[__ID_IBRSC] = { "ibrsc", H_BOARD, ibrsc, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBRSP] = { "ibrsp", H_DEV, ibrsp, __F_HANDLE | __F_SPR },
|
|
|
|
[__ID_IBRSV] = { "ibrsv", H_EITHER, ibrsv, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBSAD] = { "ibsad", H_EITHER, ibsad, __F_HANDLE | __F_SAD },
|
|
|
|
[__ID_IBSGNL] = { "ibsgnl", H_EITHER, ibsgnl, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBSIC] = { "ibsic", H_BOARD, ibsic, __F_HANDLE },
|
|
|
|
[__ID_IBSRE] = { "ibsre", H_BOARD, ibsre, __F_HANDLE | __F_V },
|
|
|
|
[__ID_IBSRQ] = { "ibsrq", H_EITHER, ibsrq, __F_FUNC },
|
|
|
|
[__ID_IBSTOP] = { "ibstop", H_EITHER, ibstop, __F_HANDLE },
|
|
|
|
[__ID_IBTMO] = { "ibtmo", H_EITHER, ibtmo, __F_HANDLE | __F_TMO },
|
|
|
|
[__ID_IBTRAP] = { "ibtrap", H_EITHER, ibtrap, __F_MASK | __F_MODE },
|
|
|
|
[__ID_IBTRG] = { "ibtrg", H_DEV, ibtrg, __F_HANDLE },
|
|
|
|
[__ID_IBWAIT] = { "ibwait", H_EITHER, ibwait, __F_HANDLE | __F_MASK },
|
|
|
|
[__ID_IBWRT] = { "ibwrt", H_EITHER, ibwrt, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBWRTA] = { "ibwrta", H_EITHER, ibwrta, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBWRTF] = { "ibwrtf", H_EITHER, ibwrtf, __F_HANDLE | __F_FLNAME },
|
|
|
|
[__ID_IBWRTKEY] = { "ibwrtkey", H_EITHER, ibwrtkey, __F_HANDLE | __F_BUFFER | __F_CNT },
|
|
|
|
[__ID_IBXTRC] = { "ibxtrc", H_EITHER, ibxtrc, __F_HANDLE | __F_BUFFER | __F_CNT },
|
2005-02-12 17:39:50 +00:00
|
|
|
};
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
static const u_int max_ibhandler = sizeof ibhandlers / sizeof ibhandlers[0];
|
|
|
|
|
|
|
|
static void
|
|
|
|
ib_dump_args(struct ibhandler *ih, struct ibarg *ap)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ih->name != NULL)
|
|
|
|
printf("%s(", ih->name);
|
|
|
|
else
|
|
|
|
printf("ibinvalid(");
|
|
|
|
printf("[0x%x]", ap->__field);
|
|
|
|
if (ap->__field & __F_HANDLE) printf(" handle=%d", ap->handle);
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ap->__field & __F_EOS) printf(" eos=0x%x", ap->eos);
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ap->__field & __F_EOT) printf(" eot=%d", ap->eot);
|
|
|
|
if (ap->__field & __F_TMO) printf(" tmo=%d", ap->tmo);
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ap->__field & __F_PAD) printf(" pad=0x%x", ap->pad);
|
|
|
|
if (ap->__field & __F_SAD) printf(" sad=0x%x", ap->sad);
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ap->__field & __F_BUFFER) printf(" buffer=%p", ap->buffer);
|
|
|
|
if (ap->__field & __F_CNT) printf(" cnt=%ld", ap->cnt);
|
2005-02-12 23:52:44 +00:00
|
|
|
if (ap->__field & __F_V) printf(" v=%d/0x%x", ap->v, ap->v);
|
2005-02-12 21:07:09 +00:00
|
|
|
/* XXX more ... */
|
|
|
|
printf(")\n");
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
gpib_ib_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
struct upd7210 *u;
|
|
|
|
struct ibfoo *ib;
|
2005-02-12 23:52:44 +00:00
|
|
|
int error = 0;
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
u = dev->si_drv1;
|
|
|
|
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
if (u->busy) {
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
u->busy = 1;
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
if (u->dmachan >= 0) {
|
|
|
|
error = isa_dma_acquire(u->dmachan);
|
|
|
|
if (!error) {
|
|
|
|
error = isa_dma_init(u->dmachan, PAGE_SIZE, M_WAITOK);
|
|
|
|
if (error)
|
|
|
|
isa_dma_release(u->dmachan);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
2005-02-12 23:52:44 +00:00
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
if (error) {
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
u->busy = 0;
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
ib = malloc(sizeof *ib, M_IBFOO, M_WAITOK | M_ZERO);
|
|
|
|
LIST_INIT(&ib->handles);
|
2008-04-16 16:47:14 +00:00
|
|
|
callout_init(&ib->callout, CALLOUT_MPSAFE);
|
2005-03-07 11:05:47 +00:00
|
|
|
ib->unrhdr = new_unrhdr(0, INT_MAX, NULL);
|
2005-02-12 17:39:50 +00:00
|
|
|
dev->si_drv2 = ib;
|
2005-02-12 21:07:09 +00:00
|
|
|
ib->u = u;
|
2005-02-12 17:39:50 +00:00
|
|
|
u->ibfoo = ib;
|
|
|
|
u->irq = gpib_ib_irq;
|
|
|
|
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_CRST);
|
|
|
|
DELAY(10000);
|
|
|
|
DELAY(1000);
|
|
|
|
upd7210_wr(u, IMR1, 0x00);
|
|
|
|
upd7210_wr(u, IMR2, 0x00);
|
|
|
|
upd7210_wr(u, SPMR, 0x00);
|
|
|
|
upd7210_wr(u, ADR, 0x00);
|
|
|
|
upd7210_wr(u, ADR, ADR_ARS | ADR_DL | ADR_DT);
|
|
|
|
upd7210_wr(u, ADMR, ADMR_ADM0 | ADMR_TRM0 | ADMR_TRM1);
|
|
|
|
upd7210_wr(u, EOSR, 0x00);
|
|
|
|
upd7210_wr(u, AUXMR, C_ICR | 8);
|
|
|
|
upd7210_wr(u, AUXMR, C_PPR | PPR_U);
|
|
|
|
upd7210_wr(u, AUXMR, C_AUXA);
|
|
|
|
upd7210_wr(u, AUXMR, C_AUXB + 3);
|
|
|
|
upd7210_wr(u, AUXMR, C_AUXE + 0);
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_PON);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x00);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x22); /* soft reset */
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x03); /* set system
|
|
|
|
* controller bit */
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
upd7210_wr(u, AUXMR, AUXMR_CIFC);
|
|
|
|
DELAY(100);
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_SIFC);
|
|
|
|
upd7210_wr(u, AUXMR, AUXMR_SREN);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gpib_ib_close(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
struct upd7210 *u;
|
|
|
|
struct ibfoo *ib;
|
|
|
|
|
|
|
|
u = dev->si_drv1;
|
|
|
|
ib = dev->si_drv2;
|
|
|
|
/* XXX: assert pointer consistency */
|
|
|
|
|
|
|
|
u->ibfoo = NULL;
|
|
|
|
/* XXX: free handles */
|
|
|
|
dev->si_drv2 = NULL;
|
|
|
|
free(ib, M_IBFOO);
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
if (u->dmachan >= 0) {
|
|
|
|
isa_dma_release(u->dmachan);
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
u->busy = 0;
|
2005-02-12 23:52:44 +00:00
|
|
|
ibdebug = 0;
|
2005-02-12 17:39:50 +00:00
|
|
|
upd7210_wr(u, IMR1, 0x00);
|
|
|
|
upd7210_wr(u, IMR2, 0x00);
|
2010-02-01 21:21:10 +00:00
|
|
|
if (u->use_fifo) {
|
|
|
|
bus_write_1(u->reg_res[0], imr3, 0x00);
|
|
|
|
bus_write_1(u->reg_res[0], cmdr, 0x02); /* clear system
|
|
|
|
* controller bit */
|
|
|
|
}
|
2005-02-12 17:39:50 +00:00
|
|
|
upd7210_wr(u, AUXMR, AUXMR_CRST);
|
|
|
|
DELAY(10000);
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gpib_ib_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
|
|
|
|
{
|
2005-02-12 21:07:09 +00:00
|
|
|
struct ibarg *ap;
|
2005-02-12 17:39:50 +00:00
|
|
|
struct ibhandler *ih;
|
|
|
|
struct handle *h;
|
|
|
|
struct upd7210 *u;
|
2005-02-12 21:07:09 +00:00
|
|
|
struct ibfoo *ib;
|
2005-02-12 17:39:50 +00:00
|
|
|
int error;
|
2005-02-12 21:07:09 +00:00
|
|
|
struct timeval deadline, tv;
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
u = dev->si_drv1;
|
2005-02-12 21:07:09 +00:00
|
|
|
ib = u->ibfoo;
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
/* We only support a single ioctl, everything else is a mistake */
|
2005-02-12 17:39:50 +00:00
|
|
|
if (cmd != GPIB_IBFOO)
|
|
|
|
return (ENOIOCTL);
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
/* Check the identifier and field-bitmap in the arguments. */
|
2005-02-12 17:39:50 +00:00
|
|
|
ap = (void *)data;
|
|
|
|
if (ap->__ident < 0 || ap->__ident >= max_ibhandler)
|
|
|
|
return (EINVAL);
|
|
|
|
ih = &ibhandlers[ap->__ident];
|
|
|
|
if (ap->__field != ih->args)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ibdebug)
|
|
|
|
ib_dump_args(ih, ap);
|
|
|
|
|
|
|
|
if (ih->func == NULL)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
ap->__iberr = 0;
|
|
|
|
ap->__ibsta = 0;
|
|
|
|
ap->__ibcnt = 0;
|
2010-12-10 14:04:41 +00:00
|
|
|
ap->__retval = 0;
|
2005-02-12 21:07:09 +00:00
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
if (ap->__field & __F_TMO) {
|
2005-02-12 21:07:09 +00:00
|
|
|
if (ap->tmo < 0 || ap->tmo >= max_timeouts)
|
|
|
|
return (ib_set_error(ap, EARG));
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ap->__field & __F_EOS) {
|
2005-02-12 21:07:09 +00:00
|
|
|
if ((ap->eos & ~(REOS | XEOS | BIN | 0xff)) ||
|
|
|
|
((ap->eos & (BIN | 0x80)) == 0x80))
|
|
|
|
return (ib_set_error(ap, EARG));
|
|
|
|
}
|
|
|
|
if (ap->__field & __F_PAD) {
|
|
|
|
if (ap->pad < 0 || ap->pad > 30)
|
|
|
|
return (ib_set_error(ap, EARG));
|
|
|
|
}
|
|
|
|
if (ap->__field & __F_SAD) {
|
|
|
|
if (ap->sad != 0 && (ap->sad < 0x60 || ap->sad > 126))
|
|
|
|
return (ib_set_error(ap, EARG));
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
mtx_lock(&u->mutex);
|
2005-02-12 21:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Find the handle, if any */
|
|
|
|
h = NULL;
|
|
|
|
if ((ap->__field & __F_HANDLE) && gethandle(u, ap, &h)) {
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-12 23:52:44 +00:00
|
|
|
/* Check that the handle is the right kind */
|
|
|
|
if (h != NULL && !(h->kind & ih->kind)) {
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
return (ib_set_error(ap, EARG));
|
|
|
|
}
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
/* Set up handle and deadline */
|
|
|
|
if (h != NULL && timevalisset(&h->timeout)) {
|
|
|
|
getmicrouptime(&deadline);
|
|
|
|
timevaladd(&deadline, &h->timeout);
|
|
|
|
} else {
|
|
|
|
timevalclear(&deadline);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the card to be(come) available, respect deadline */
|
2005-02-12 17:39:50 +00:00
|
|
|
while(u->busy != 1) {
|
2005-02-12 21:07:09 +00:00
|
|
|
error = msleep(ib, &u->mutex,
|
|
|
|
PZERO | PCATCH, "gpib_ibioctl", hz / 10);
|
|
|
|
if (error == 0)
|
|
|
|
continue;
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
if (error == EINTR)
|
|
|
|
return(ib_set_error(ap, EABO));
|
|
|
|
if (error == EWOULDBLOCK && timevalisset(&deadline)) {
|
|
|
|
getmicrouptime(&tv);
|
|
|
|
if (timevalcmp(&deadline, &tv, <))
|
|
|
|
return(ib_had_timeout(ap));
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
2005-02-12 21:07:09 +00:00
|
|
|
mtx_lock(&u->mutex);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
u->busy = 2;
|
|
|
|
mtx_unlock(&u->mutex);
|
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
/* Hand over deadline handling to the callout routine */
|
|
|
|
ib->ap = ap;
|
|
|
|
ib->h = h;
|
|
|
|
ib->mode = BUSY;
|
|
|
|
ib->deadline = deadline;
|
2005-03-06 19:43:12 +00:00
|
|
|
callout_reset(&ib->callout, hz / 5, gpib_ib_timeout, u);
|
2005-02-12 17:39:50 +00:00
|
|
|
|
2005-02-12 21:07:09 +00:00
|
|
|
error = ih->func(ib);
|
|
|
|
|
|
|
|
/* Release card */
|
|
|
|
ib->mode = IDLE;
|
|
|
|
ib->ap = NULL;
|
|
|
|
ib->h = NULL;
|
|
|
|
timevalclear(&deadline);
|
|
|
|
callout_stop(&ib->callout);
|
2005-02-12 17:39:50 +00:00
|
|
|
|
|
|
|
mtx_lock(&u->mutex);
|
|
|
|
u->busy = 1;
|
2005-02-12 21:07:09 +00:00
|
|
|
wakeup(ib);
|
2005-02-12 17:39:50 +00:00
|
|
|
mtx_unlock(&u->mutex);
|
2005-02-12 21:07:09 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
return(ib_set_errno(ap, error));
|
|
|
|
return (0);
|
2005-02-12 17:39:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cdevsw gpib_ib_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_name = "gpib_ib",
|
|
|
|
.d_open = gpib_ib_open,
|
|
|
|
.d_ioctl = gpib_ib_ioctl,
|
|
|
|
.d_close = gpib_ib_close,
|
|
|
|
};
|