/*
* Copyright (c) 2009 Stephen M. Rumble
* Copyright (c) 2001 Wayne Knowles
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Wayne Knowles
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
if ((cpu_intr_establish(oa->oa_irq, IPL_BIO,
oiocsc_scsiintr, sc)) == NULL) {
printf(": unable to establish interrupt!\n");
return;
}
wd33c93_attach(sc);
}
/*
* Prime the hardware for a DMA transfer
*
* Requires splbio() interrupts to be disabled by the caller
*
* XXX- I'm not sure if this works properly yet. Primarily, I'm not sure
* that all ds_addr's after the first will be page aligned. If they're
* not, we apparently cannot use this DMA engine...
*
* Unfortunately, I'm getting mutex panics while testing with EFS (haven't
* tried FFS), so I cannot yet confirm whether this works or not.
*/
int
oiocsc_dmasetup(struct wd33c93_softc *dev, void **addr, size_t *len, int datain,
size_t *dmasize)
{
struct oiocsc_softc *osc = (void *)dev;
struct oioc_dma_softc *dsc = &osc->sc_oiocdma;
int count, err, i;
void *vaddr;
KASSERT((osc->sc_flags & WDSC_DMA_ACTIVE) == 0);
vaddr = *addr;
count = dsc->sc_dlen = *len;
if (count) {
bus_dmamap_t dmamap = osc->sc_dmamap;
/* Build list of physical addresses for this transfer */
if ((err = bus_dmamap_load(osc->sc_dmat, osc->sc_dmamap,
vaddr, count,
NULL /* kernel address */,
BUS_DMA_NOWAIT)) != 0)
panic("%s: bus_dmamap_load err=%d",
device_xname(dev->sc_dev), err);
/*
* We can map the contiguous buffer with up to 256 pages.
* The DMA low address register contains a 12-bit offset for
* the first page (in case the buffer isn't aligned). The 256
* high registers contain 16 bits each for page numbers.
*
* We will fill in the high registers here. The low register
* fires off the DMA engine and is set in oiocsc_dmago.
*/
dsc->sc_dmalow = dmamap->dm_segs[0].ds_addr &
OIOC_SCSI_DMA_LOW_ADDR_MASK;
KASSERT(dmamap->dm_nsegs <= OIOC_SCSI_DMA_NSEGS);
for (i = 0; i < dmamap->dm_nsegs; i++) {
uint16_t pgnum;
if (datain)
dsc->sc_dmalow |= OIOC_SCSI_DMA_LOW_ADDR_DMADIR;
}
return (count);
}
/*
* Prime the hardware for the next DMA transfer
*/
int
oiocsc_dmago(struct wd33c93_softc *dev)
{
struct oiocsc_softc *osc = (void *)dev;
struct oioc_dma_softc *dsc = &osc->sc_oiocdma;