Make si at obio and si at vme on sun3 use bus_dma(9) for data xfer.

XXX1: Only si at vme on TME is tested.
XXX2: No info about DMA on si at sebuf. (bounce buffer required?)
This commit is contained in:
tsutsui 2007-02-03 18:02:57 +00:00
parent 277e6a5263
commit f7397aaa8c
4 changed files with 73 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: si.c,v 1.57 2005/12/11 12:19:20 christos Exp $ */
/* $NetBSD: si.c,v 1.58 2007/02/03 18:02:57 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si.c,v 1.57 2005/12/11 12:19:20 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: si.c,v 1.58 2007/02/03 18:02:57 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -95,6 +95,7 @@ __KERNEL_RCSID(0, "$NetBSD: si.c,v 1.57 2005/12/11 12:19:20 christos Exp $");
#include <dev/scsipi/scsiconf.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/dvma.h>
/* #define DEBUG XXX */
@ -271,18 +272,18 @@ si_dma_alloc(struct ncr5380_softc *ncr_sc)
struct scsipi_xfer *xs = sr->sr_xs;
struct si_dma_handle *dh;
int i, xlen;
u_long addr;
void *addr;
#ifdef DIAGNOSTIC
if (sr->sr_dma_hand != NULL)
panic("si_dma_alloc: already have DMA handle");
#endif
addr = (u_long) ncr_sc->sc_dataptr;
addr = ncr_sc->sc_dataptr;
xlen = ncr_sc->sc_datalen;
/* If the DMA start addr is misaligned then do PIO */
if ((addr & 1) || (xlen & 1)) {
if (((vaddr_t)addr & 1) || (xlen & 1)) {
printf("si_dma_alloc: misaligned.\n");
return;
}
@ -314,14 +315,22 @@ found:
dh = &sc->sc_dma[i];
dh->dh_flags = SIDH_BUSY;
dh->dh_addr = (u_char*) addr;
dh->dh_maplen = xlen;
dh->dh_dvma = 0;
dh->dh_addr = addr;
if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmap, addr, xlen, NULL,
BUS_DMA_NOWAIT) != 0)
panic("%s: can't load dmamap", ncr_sc->sc_dev.dv_xname);
dh->dh_dmaaddr = sc->sc_dmap->dm_segs[0].ds_addr & DVMA_VME_SLAVE_MASK;
dh->dh_dmalen = xlen;
/* Copy the "write" flag for convenience. */
if (xs->xs_control & XS_CTL_DATA_OUT)
dh->dh_flags |= SIDH_OUT;
bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap, 0, dh->dh_dmalen,
(dh->dh_flags & SIDH_OUT) == 0 ?
BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
#if 0
/*
* Some machines might not need to remap B_PHYS buffers.
@ -334,15 +343,6 @@ found:
dh->dh_flags |= SIDH_PHYS;
#endif
dh->dh_dvma = dvma_mapin((char *)addr, xlen, 0);
if (!dh->dh_dvma) {
/* Can't remap segment */
printf("si_dma_alloc: can't remap %p/0x%x\n",
dh->dh_addr, dh->dh_maplen);
dh->dh_flags = 0;
return;
}
/* success */
sr->sr_dma_hand = dh;
@ -353,6 +353,7 @@ found:
void
si_dma_free(struct ncr5380_softc *ncr_sc)
{
struct si_softc *sc = (struct si_softc *)ncr_sc;
struct sci_req *sr = ncr_sc->sc_current;
struct si_dma_handle *dh = sr->sr_dma_hand;
@ -365,10 +366,11 @@ si_dma_free(struct ncr5380_softc *ncr_sc)
panic("si_dma_free: free while in progress");
if (dh->dh_flags & SIDH_BUSY) {
/* XXX - Should separate allocation and mapping. */
/* Give back the DVMA space. */
dvma_mapout(dh->dh_dvma, dh->dh_maplen);
dh->dh_dvma = 0;
bus_dmamap_sync(sc->sc_dmat, sc->sc_dmap, 0, dh->dh_dmalen,
(dh->dh_flags & SIDH_OUT) == 0 ?
BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
dh->dh_dmaaddr = 0;
dh->dh_flags = 0;
}
sr->sr_dma_hand = NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: si_obio.c,v 1.32 2006/03/29 04:16:48 thorpej Exp $ */
/* $NetBSD: si_obio.c,v 1.33 2007/02/03 18:02:57 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -81,7 +81,7 @@
****************************************************************/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si_obio.c,v 1.32 2006/03/29 04:16:48 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: si_obio.c,v 1.33 2007/02/03 18:02:57 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -168,6 +168,22 @@ si_obio_attach(struct device *parent, struct device *self, void *args)
struct cfdata *cf = device_cfdata(self);
struct confargs *ca = args;
sc->sc_bst = ca->ca_bustag;
sc->sc_dmat = ca->ca_dmatag;
if (bus_space_map(sc->sc_bst, ca->ca_paddr, sizeof(struct si_regs), 0,
&sc->sc_bsh) != 0) {
printf(": can't map register\n");
return;
}
sc->sc_regs = bus_space_vaddr(sc->sc_bst, sc->sc_bsh);
if (bus_dmamap_create(sc->sc_dmat, MAXPHYS, 1, MAXPHYS, 0,
BUS_DMA_NOWAIT, &sc->sc_dmap) != 0) {
printf(": can't create DMA map\n");
return;
}
/* Get options from config flags if specified. */
if (cf->cf_flags)
sc->sc_options = cf->cf_flags;
@ -177,8 +193,6 @@ si_obio_attach(struct device *parent, struct device *self, void *args)
printf(": options=0x%x\n", sc->sc_options);
sc->sc_adapter_type = ca->ca_bustype;
sc->sc_regs = bus_mapin(ca->ca_bustype,
ca->ca_paddr, sizeof(struct si_regs));
/*
* MD function pointers used by the MI code.
@ -280,11 +294,10 @@ si_obio_dma_setup(struct ncr5380_softc *ncr_sc)
* Get the DVMA mapping for this segment.
* XXX - Should separate allocation and mapin.
*/
data_pa = dvma_kvtopa(dh->dh_dvma, sc->sc_adapter_type);
data_pa += (ncr_sc->sc_dataptr - dh->dh_addr);
data_pa = dh->dh_dmaaddr;
if (data_pa & 1)
panic("si_dma_start: bad pa=0x%lx", data_pa);
xlen = ncr_sc->sc_datalen;
xlen = dh->dh_dmalen;
sc->sc_reqlen = xlen; /* XXX: or less? */
#ifdef DEBUG

View File

@ -1,4 +1,4 @@
/* $NetBSD: si_vme.c,v 1.25 2006/03/29 04:16:48 thorpej Exp $ */
/* $NetBSD: si_vme.c,v 1.26 2007/02/03 18:02:57 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -81,7 +81,7 @@
****************************************************************/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si_vme.c,v 1.25 2006/03/29 04:16:48 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: si_vme.c,v 1.26 2007/02/03 18:02:57 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -184,6 +184,22 @@ si_vme_attach(struct device *parent, struct device *self, void *args)
struct cfdata *cf = device_cfdata(self);
struct confargs *ca = args;
sc->sc_bst = ca->ca_bustag;
sc->sc_dmat = ca->ca_dmatag;
if (bus_space_map(sc->sc_bst, ca->ca_paddr, sizeof(struct si_regs), 0,
&sc->sc_bsh) != 0) {
printf(": can't map register\n");
return;
}
sc->sc_regs = bus_space_vaddr(sc->sc_bst, sc->sc_bsh);
if (bus_dmamap_create(sc->sc_dmat, MAXPHYS, 1, MAXPHYS, 0,
BUS_DMA_NOWAIT, &sc->sc_dmap) != 0) {
printf(": can't create DMA map\n");
return;
}
/* Get options from config flags if specified. */
if (cf->cf_flags)
sc->sc_options = cf->cf_flags;
@ -193,11 +209,7 @@ si_vme_attach(struct device *parent, struct device *self, void *args)
printf(": options=0x%x\n", sc->sc_options);
sc->sc_adapter_type = ca->ca_bustype;
sc->sc_regs = (struct si_regs *)
bus_mapin(ca->ca_bustype, ca->ca_paddr,
sizeof(struct si_regs));
sc->sc_adapter_iv_am =
VME_SUPV_DATA_24 | (ca->ca_intvec & 0xFF);
sc->sc_adapter_iv_am = VME_SUPV_DATA_24 | (ca->ca_intvec & 0xFF);
/*
* MD function pointers used by the MI code.
@ -215,8 +227,7 @@ si_vme_attach(struct device *parent, struct device *self, void *args)
ncr_sc->sc_intr_off = si_vme_intr_off;
/* Attach interrupt handler. */
isr_add_vectored(si_intr, (void *)sc,
ca->ca_intpri, ca->ca_intvec);
isr_add_vectored(si_intr, (void *)sc, ca->ca_intpri, ca->ca_intvec);
/* Reset the hardware. */
si_vme_reset(ncr_sc);
@ -324,11 +335,10 @@ si_vme_dma_setup(struct ncr5380_softc *ncr_sc)
* Get the DVMA mapping for this segment.
* XXX - Should separate allocation and mapin.
*/
data_pa = dvma_kvtopa(dh->dh_dvma, sc->sc_adapter_type);
data_pa += (ncr_sc->sc_dataptr - dh->dh_addr);
data_pa = dh->dh_dmaaddr;
if (data_pa & 1)
panic("si_dma_start: bad pa=0x%lx", data_pa);
xlen = ncr_sc->sc_datalen;
xlen = dh->dh_dmalen;
xlen &= ~1; /* XXX: necessary? */
sc->sc_reqlen = xlen; /* XXX: or less? */

View File

@ -1,4 +1,4 @@
/* $NetBSD: sivar.h,v 1.8 2005/12/11 12:19:20 christos Exp $ */
/* $NetBSD: sivar.h,v 1.9 2007/02/03 18:02:57 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -62,9 +62,9 @@ struct si_dma_handle {
int dh_flags;
#define SIDH_BUSY 1 /* This DH is in use */
#define SIDH_OUT 2 /* DMA does data out (write) */
u_char * dh_addr; /* KVA of start of buffer */
int dh_maplen; /* Length of KVA mapping. */
void * dh_dvma; /* VA of buffer in DVMA space */
void *dh_addr; /* KVA of start of buffer */
vaddr_t dh_dmaaddr; /* VA of buffer in DVMA space */
vsize_t dh_dmalen; /* Length of KVA mapping. */
};
/*
@ -73,7 +73,11 @@ struct si_dma_handle {
*/
struct si_softc {
struct ncr5380_softc ncr_sc;
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
volatile struct si_regs *sc_regs;
bus_dma_tag_t sc_dmat;
bus_dmamap_t sc_dmap;
int sc_adapter_type;
int sc_adapter_iv_am; /* int. vec + address modifier */
int sc_options; /* options for this instance */