2007-03-04 08:59:00 +03:00
|
|
|
/* $NetBSD: isadma.c,v 1.10 2007/03/04 05:59:35 christos Exp $ */
|
2000-01-23 23:24:23 +03:00
|
|
|
/* $OpenBSD: isadma.c,v 1.2 1996/11/23 21:45:34 kstailey Exp $ */
|
2000-01-24 00:01:48 +03:00
|
|
|
/* NetBSD: isadma.c,v 1.19 1996/04/29 20:03:26 christos Exp */
|
2000-01-23 23:24:23 +03:00
|
|
|
|
2003-07-15 04:04:39 +04:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-04 08:59:00 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: isadma.c,v 1.10 2007/03/04 05:59:35 christos Exp $");
|
2003-07-15 04:04:39 +04:00
|
|
|
|
2000-01-23 23:24:23 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
2000-06-29 12:32:34 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#include <machine/pio.h>
|
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
#include <dev/isa/isadmavar.h>
|
|
|
|
#include <arch/arc/isa/isadmareg.h> /*XXX*/
|
|
|
|
|
|
|
|
struct dma_info {
|
|
|
|
int flags;
|
|
|
|
int active;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *addr;
|
2000-02-22 14:25:55 +03:00
|
|
|
bus_size_t nbytes;
|
2000-01-23 23:24:23 +03:00
|
|
|
struct isadma_seg phys[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct isadma_softc *isadma_sc; /*XXX ugly */
|
|
|
|
static struct dma_info dma_info[8];
|
2005-01-22 10:35:33 +03:00
|
|
|
static uint8_t dma_finished;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
/* high byte of address is stored in this port for i-th dma channel */
|
|
|
|
static int dmapageport[2][4] = {
|
|
|
|
{0x87, 0x83, 0x81, 0x82},
|
|
|
|
{0x8f, 0x8b, 0x89, 0x8a}
|
|
|
|
};
|
|
|
|
|
2005-01-22 10:35:33 +03:00
|
|
|
static uint8_t dmamode[4] = {
|
2000-01-23 23:24:23 +03:00
|
|
|
DMA37MD_READ | DMA37MD_SINGLE,
|
|
|
|
DMA37MD_WRITE | DMA37MD_SINGLE,
|
|
|
|
DMA37MD_READ | DMA37MD_LOOP,
|
|
|
|
DMA37MD_WRITE | DMA37MD_LOOP
|
|
|
|
};
|
|
|
|
|
2005-01-22 10:35:33 +03:00
|
|
|
int isadmamatch(struct device *, struct cfdata *, void *);
|
|
|
|
void isadmaattach(struct device *, struct device *, void *);
|
|
|
|
int isadmaprint(void *, const char *);
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
struct isadma_softc {
|
|
|
|
struct device sc_dev;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t sc_iot;
|
|
|
|
bus_space_handle_t sc_ioh1;
|
|
|
|
bus_space_handle_t sc_ioh2;
|
2000-01-23 23:24:23 +03:00
|
|
|
}
|
|
|
|
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(isadma, sizeof(struct isadma_softc),
|
|
|
|
isadmamatch, isadmaattach, NULL, NULL);
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
struct cfdriver isadma_cd = {
|
|
|
|
NULL, "isadma", DV_DULL, 1
|
|
|
|
};
|
|
|
|
|
2005-01-22 10:35:33 +03:00
|
|
|
isadmamatch(struct device *parent, struct cfdata *match, void *aux)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
|
|
|
|
/* Sure we exist */
|
|
|
|
ia->ia_iosize = 0;
|
2005-01-22 10:35:33 +03:00
|
|
|
return 1;
|
2000-01-23 23:24:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-22 10:35:33 +03:00
|
|
|
isadmaattach(struct device *parent, struct device *self, void *aux)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct isadma_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
2000-01-24 00:01:48 +03:00
|
|
|
iot = sc->sc_iot = ia->ia_iot;
|
|
|
|
if (bus_space_map(iot, IO_DMA1, DMA_NREGS, 0, &ioh))
|
2000-01-23 23:24:23 +03:00
|
|
|
panic("isadmaattach: couldn't map I/O ports");
|
|
|
|
sc->sc_ioh1 = ioh;
|
2000-01-24 00:01:48 +03:00
|
|
|
if (bus_space_map(iot, IO_DMA2, DMA_NREGS*2, 0, &ioh))
|
2000-01-23 23:24:23 +03:00
|
|
|
panic("isadmaattach: couldn't map I/O ports");
|
|
|
|
sc->sc_ioh2 = ioh;
|
|
|
|
isadma_sc = sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* isadma_cascade(): program 8237 DMA controller channel to accept
|
|
|
|
* external dma control by a board.
|
|
|
|
*/
|
|
|
|
void
|
2005-01-22 10:35:33 +03:00
|
|
|
isadma_cascade(int chan)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct isadma_softc *sc = isadma_sc;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
if (chan < 0 || chan > 7)
|
|
|
|
panic("isadma_cascade: impossible request");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* set dma channel mode, and set dma channel mode */
|
|
|
|
if ((chan & 4) == 0) {
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh1, DMA1_MODE,
|
|
|
|
chan | DMA37MD_CASCADE);
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh1, DMA1_SMSK, chan);
|
2000-01-23 23:24:23 +03:00
|
|
|
} else {
|
|
|
|
chan &= 3;
|
|
|
|
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh2, DMA2_MODE,
|
|
|
|
chan | DMA37MD_CASCADE);
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh2, DMA2_SMSK, chan);
|
2000-01-23 23:24:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* isadma_start(): program 8237 DMA controller channel, avoid page alignment
|
|
|
|
* problems by using a bounce buffer.
|
|
|
|
*/
|
|
|
|
void
|
2007-03-04 08:59:00 +03:00
|
|
|
isadma_start(void *addr, bus_size_t nbytes, int chan, int flags)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct dma_info *di;
|
|
|
|
int waport;
|
|
|
|
int mflags;
|
|
|
|
struct isadma_softc *sc = isadma_sc;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
if (chan < 0 || chan > 7 ||
|
|
|
|
(((flags & DMAMODE_READ) != 0) + ((flags & DMAMODE_WRITE) != 0) +
|
|
|
|
((flags & DMAMODE_LOOP) != 0) != 1) ||
|
|
|
|
((chan & 4) ? (nbytes >= (1<<17) || nbytes & 1 || (u_int)addr & 1) :
|
|
|
|
(nbytes >= (1<<16))))
|
|
|
|
panic("isadma_start: impossible request");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
di = dma_info+chan;
|
|
|
|
if (di->active) {
|
|
|
|
log(LOG_ERR,"isadma_start: old request active on %d\n",chan);
|
|
|
|
isadma_abort(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
di->flags = flags;
|
|
|
|
di->active = 1;
|
|
|
|
di->addr = addr;
|
|
|
|
di->nbytes = nbytes;
|
|
|
|
|
|
|
|
mflags = ISADMA_MAP_WAITOK | ISADMA_MAP_BOUNCE | ISADMA_MAP_CONTIG;
|
|
|
|
mflags |= (chan & 4) ? ISADMA_MAP_16BIT : ISADMA_MAP_8BIT;
|
|
|
|
|
|
|
|
if (isadma_map(addr, nbytes, di->phys, mflags) != 1)
|
|
|
|
panic("isadma_start: cannot map");
|
|
|
|
|
|
|
|
/* XXX Will this do what we want with DMAMODE_LOOP? */
|
|
|
|
if ((flags & DMAMODE_READ) == 0)
|
|
|
|
isadma_copytobuf(addr, nbytes, 1, di->phys);
|
|
|
|
|
|
|
|
dma_finished &= ~(1 << chan);
|
|
|
|
|
|
|
|
if ((chan & 4) == 0) {
|
|
|
|
ioh = sc->sc_ioh1;
|
|
|
|
/*
|
|
|
|
* Program one of DMA channels 0..3. These are
|
|
|
|
* byte mode channels.
|
|
|
|
*/
|
|
|
|
/* set dma channel mode, and reset address ff */
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_write_1(iot, ioh, DMA1_MODE, chan | dmamode[flags]);
|
|
|
|
bus_space_write_1(iot, ioh, DMA1_FFC, 0);
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
/* send start address */
|
|
|
|
waport = DMA1_CHN(chan);
|
|
|
|
outb(dmapageport[0][chan], di->phys[0].addr>>16);
|
|
|
|
outb(waport, di->phys[0].addr);
|
|
|
|
outb(waport, di->phys[0].addr>>8);
|
|
|
|
|
|
|
|
/* send count */
|
|
|
|
outb(waport + 1, --nbytes);
|
|
|
|
outb(waport + 1, nbytes>>8);
|
|
|
|
|
|
|
|
/* unmask channel */
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_write_1(iot, ioh, DMA1_SMSK, chan | DMA37SM_CLEAR);
|
2000-01-23 23:24:23 +03:00
|
|
|
} else {
|
|
|
|
ioh = sc->sc_ioh2;
|
|
|
|
/*
|
|
|
|
* Program one of DMA channels 4..7. These are
|
|
|
|
* word mode channels.
|
|
|
|
*/
|
|
|
|
/* set dma channel mode, and reset address ff */
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, ioh, DMA2_MODE,
|
|
|
|
(chan & 3) | dmamode[flags]);
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_write_1(iot, ioh, DMA2_FFC, 0);
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
/* send start address */
|
|
|
|
waport = DMA2_CHN(chan & 3);
|
|
|
|
outb(dmapageport[1][chan], di->phys[0].addr>>16);
|
|
|
|
outb(waport, di->phys[0].addr>>1);
|
|
|
|
outb(waport, di->phys[0].addr>>9);
|
|
|
|
|
|
|
|
/* send count */
|
|
|
|
nbytes >>= 1;
|
|
|
|
outb(waport + 2, --nbytes);
|
|
|
|
outb(waport + 2, nbytes>>8);
|
|
|
|
|
|
|
|
/* unmask channel */
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, ioh, DMA2_SMSK,
|
|
|
|
(chan & 3) | DMA37SM_CLEAR);
|
2000-01-23 23:24:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-22 10:35:33 +03:00
|
|
|
isadma_abort(int chan)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct dma_info *di;
|
|
|
|
struct isadma_softc *sc = isadma_sc;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
if (chan < 0 || chan > 7)
|
|
|
|
panic("isadma_abort: impossible request");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
di = dma_info+chan;
|
|
|
|
if (! di->active) {
|
|
|
|
log(LOG_ERR,"isadma_abort: no request active on %d\n",chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mask channel */
|
|
|
|
if ((chan & 4) == 0)
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh1, DMA1_SMSK,
|
|
|
|
DMA37SM_SET | chan);
|
2000-01-23 23:24:23 +03:00
|
|
|
else
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh2, DMA2_SMSK,
|
|
|
|
DMA37SM_SET | (chan & 3));
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
isadma_unmap(di->addr, di->nbytes, 1, di->phys);
|
|
|
|
di->active = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-01-22 10:35:33 +03:00
|
|
|
isadma_finished(int chan)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct isadma_softc *sc = isadma_sc;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#ifdef ISADMA_DEBUG
|
|
|
|
if (chan < 0 || chan > 7)
|
|
|
|
panic("isadma_finished: impossible request");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* check that the terminal count was reached */
|
|
|
|
if ((chan & 4) == 0)
|
2005-01-22 10:35:33 +03:00
|
|
|
dma_finished |=
|
|
|
|
bus_space_read_1(iot, sc->sc_ioh1, DMA1_SR) & 0x0f;
|
2000-01-23 23:24:23 +03:00
|
|
|
else
|
2005-01-22 10:35:33 +03:00
|
|
|
dma_finished |=
|
|
|
|
(bus_space_read_1(iot, sc->sc_ioh2, DMA2_SR) & 0x0f) << 4;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
2005-01-22 10:35:33 +03:00
|
|
|
return (dma_finished & (1 << chan)) != 0;
|
2000-01-23 23:24:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-22 10:35:33 +03:00
|
|
|
isadma_done(int chan)
|
2000-01-23 23:24:23 +03:00
|
|
|
{
|
|
|
|
struct dma_info *di;
|
|
|
|
u_char tc;
|
|
|
|
struct isadma_softc *sc = isadma_sc;
|
2000-01-24 00:01:48 +03:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (chan < 0 || chan > 7)
|
|
|
|
panic("isadma_done: impossible request");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
di = dma_info+chan;
|
|
|
|
if (! di->active) {
|
|
|
|
log(LOG_ERR,"isadma_done: no request active on %d\n",chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check that the terminal count was reached */
|
|
|
|
if ((chan & 4) == 0)
|
2000-01-24 00:01:48 +03:00
|
|
|
tc = bus_space_read_1(iot, sc->sc_ioh1, DMA1_SR) & (1 << chan);
|
2000-01-23 23:24:23 +03:00
|
|
|
else
|
2005-01-22 10:35:33 +03:00
|
|
|
tc = bus_space_read_1(iot, sc->sc_ioh2, DMA2_SR) &
|
|
|
|
(1 << (chan & 3));
|
2000-01-23 23:24:23 +03:00
|
|
|
if (tc == 0)
|
|
|
|
/* XXX probably should panic or something */
|
|
|
|
log(LOG_ERR, "dma channel %d not finished\n", chan);
|
|
|
|
|
|
|
|
/* mask channel */
|
|
|
|
if ((chan & 4) == 0)
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh1, DMA1_SMSK,
|
|
|
|
DMA37SM_SET | chan);
|
2000-01-23 23:24:23 +03:00
|
|
|
else
|
2005-01-22 10:35:33 +03:00
|
|
|
bus_space_write_1(iot, sc->sc_ioh2, DMA2_SMSK,
|
|
|
|
DMA37SM_SET | (chan & 3));
|
2000-01-23 23:24:23 +03:00
|
|
|
|
|
|
|
/* XXX Will this do what we want with DMAMODE_LOOP? */
|
|
|
|
if (di->flags & DMAMODE_READ)
|
|
|
|
isadma_copyfrombuf(di->addr, di->nbytes, 1, di->phys);
|
|
|
|
|
|
|
|
isadma_unmap(di->addr, di->nbytes, 1, di->phys);
|
|
|
|
di->active = 0;
|
|
|
|
}
|