Home | History | Annotate | Line # | Download | only in dev
dma.c revision 1.7
      1  1.7  thorpej /*	$NetBSD: dma.c,v 1.7 1996/02/14 02:44:17 thorpej Exp $	*/
      2  1.5      cgd 
      3  1.1      cgd /*
      4  1.6  thorpej  * Copyright (c) 1995 Jason R. Thorpe.
      5  1.4  mycroft  * Copyright (c) 1982, 1990, 1993
      6  1.4  mycroft  *	The Regents of the University of California.  All rights reserved.
      7  1.1      cgd  *
      8  1.1      cgd  * Redistribution and use in source and binary forms, with or without
      9  1.1      cgd  * modification, are permitted provided that the following conditions
     10  1.1      cgd  * are met:
     11  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     12  1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     13  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     15  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     16  1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     17  1.1      cgd  *    must display the following acknowledgement:
     18  1.1      cgd  *	This product includes software developed by the University of
     19  1.1      cgd  *	California, Berkeley and its contributors.
     20  1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     21  1.1      cgd  *    may be used to endorse or promote products derived from this software
     22  1.1      cgd  *    without specific prior written permission.
     23  1.1      cgd  *
     24  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1      cgd  * SUCH DAMAGE.
     35  1.1      cgd  *
     36  1.5      cgd  *	@(#)dma.c	8.1 (Berkeley) 6/10/93
     37  1.1      cgd  */
     38  1.1      cgd 
     39  1.1      cgd /*
     40  1.1      cgd  * DMA driver
     41  1.1      cgd  */
     42  1.1      cgd 
     43  1.4  mycroft #include <sys/param.h>
     44  1.4  mycroft #include <sys/systm.h>
     45  1.4  mycroft #include <sys/time.h>
     46  1.4  mycroft #include <sys/kernel.h>
     47  1.4  mycroft #include <sys/proc.h>
     48  1.4  mycroft 
     49  1.4  mycroft #include <machine/cpu.h>
     50  1.4  mycroft 
     51  1.4  mycroft #include <hp300/dev/device.h>
     52  1.4  mycroft #include <hp300/dev/dmareg.h>
     53  1.4  mycroft #include <hp300/dev/dmavar.h>
     54  1.1      cgd 
     55  1.4  mycroft #include <hp300/hp300/isr.h>
     56  1.1      cgd 
     57  1.1      cgd extern void isrlink();
     58  1.1      cgd extern void _insque();
     59  1.1      cgd extern void _remque();
     60  1.1      cgd extern u_int kvtop();
     61  1.1      cgd extern void PCIA();
     62  1.1      cgd 
     63  1.1      cgd /*
     64  1.1      cgd  * The largest single request will be MAXPHYS bytes which will require
     65  1.1      cgd  * at most MAXPHYS/NBPG+1 chain elements to describe, i.e. if none of
     66  1.1      cgd  * the buffer pages are physically contiguous (MAXPHYS/NBPG) and the
     67  1.1      cgd  * buffer is not page aligned (+1).
     68  1.1      cgd  */
     69  1.1      cgd #define	DMAMAXIO	(MAXPHYS/NBPG+1)
     70  1.1      cgd 
     71  1.1      cgd struct	dma_chain {
     72  1.1      cgd 	int	dc_count;
     73  1.1      cgd 	char	*dc_addr;
     74  1.1      cgd };
     75  1.1      cgd 
     76  1.6  thorpej struct	dma_channel {
     77  1.6  thorpej 	struct	dma_softc *dm_softc;		/* pointer back to softc */
     78  1.6  thorpej 	struct	dmadevice *dm_hwaddr;		/* registers if DMA_C */
     79  1.6  thorpej 	struct	dmaBdevice *dm_Bhwaddr;		/* registers if not DMA_C */
     80  1.6  thorpej 	char	dm_flags;			/* misc. flags */
     81  1.6  thorpej 	u_short	dm_cmd;				/* DMA controller command */
     82  1.6  thorpej 	struct	dma_chain *dm_cur;		/* current segment */
     83  1.6  thorpej 	struct	dma_chain *dm_last;		/* last segment */
     84  1.6  thorpej 	struct	dma_chain dm_chain[DMAMAXIO];	/* all segments */
     85  1.6  thorpej };
     86  1.6  thorpej 
     87  1.1      cgd struct	dma_softc {
     88  1.6  thorpej 	char	*sc_xname;			/* XXX external name */
     89  1.6  thorpej 	struct	dmareg *sc_dmareg;		/* pointer to our hardware */
     90  1.6  thorpej 	struct	dma_channel sc_chan[NDMACHAN];	/* 2 channels */
     91  1.6  thorpej 	char	sc_type;			/* A, B, or C */
     92  1.6  thorpej } Dma_softc;
     93  1.1      cgd 
     94  1.1      cgd /* types */
     95  1.1      cgd #define	DMA_B	0
     96  1.1      cgd #define DMA_C	1
     97  1.1      cgd 
     98  1.1      cgd /* flags */
     99  1.1      cgd #define DMAF_PCFLUSH	0x01
    100  1.1      cgd #define DMAF_VCFLUSH	0x02
    101  1.1      cgd #define DMAF_NOINTR	0x04
    102  1.1      cgd 
    103  1.6  thorpej struct	devqueue dmachan[NDMACHAN + 1];
    104  1.7  thorpej int	dmaintr __P((void *));
    105  1.1      cgd 
    106  1.1      cgd #ifdef DEBUG
    107  1.1      cgd int	dmadebug = 0;
    108  1.1      cgd #define DDB_WORD	0x01	/* same as DMAGO_WORD */
    109  1.1      cgd #define DDB_LWORD	0x02	/* same as DMAGO_LWORD */
    110  1.1      cgd #define	DDB_FOLLOW	0x04
    111  1.1      cgd #define DDB_IO		0x08
    112  1.1      cgd 
    113  1.3  mycroft void	dmatimeout __P((void *));
    114  1.6  thorpej int	dmatimo[NDMACHAN];
    115  1.1      cgd 
    116  1.6  thorpej long	dmahits[NDMACHAN];
    117  1.6  thorpej long	dmamisses[NDMACHAN];
    118  1.6  thorpej long	dmabyte[NDMACHAN];
    119  1.6  thorpej long	dmaword[NDMACHAN];
    120  1.6  thorpej long	dmalword[NDMACHAN];
    121  1.1      cgd #endif
    122  1.1      cgd 
    123  1.1      cgd void
    124  1.1      cgd dmainit()
    125  1.1      cgd {
    126  1.6  thorpej 	struct dma_softc *sc = &Dma_softc;
    127  1.6  thorpej 	struct dmareg *dma;
    128  1.6  thorpej 	struct dma_channel *dc;
    129  1.6  thorpej 	int i;
    130  1.1      cgd 	char rev;
    131  1.1      cgd 
    132  1.6  thorpej 	/* There's just one. */
    133  1.6  thorpej 	sc->sc_dmareg = (struct dmareg *)DMA_BASE;
    134  1.6  thorpej 	dma = sc->sc_dmareg;
    135  1.6  thorpej 	sc->sc_xname = "dma0";
    136  1.6  thorpej 
    137  1.1      cgd 	/*
    138  1.6  thorpej 	 * Determine the DMA type.  A DMA_A or DMA_B will fail the
    139  1.6  thorpej 	 * following probe.
    140  1.6  thorpej 	 *
    141  1.6  thorpej 	 * XXX Don't know how to easily differentiate the A and B cards,
    142  1.1      cgd 	 * so we just hope nobody has an A card (A cards will work if
    143  1.1      cgd 	 * DMAINTLVL is set to 3).
    144  1.1      cgd 	 */
    145  1.6  thorpej 	if (badbaddr((char *)&dma->dma_id[2])) {
    146  1.1      cgd 		rev = 'B';
    147  1.1      cgd #if !defined(HP320)
    148  1.1      cgd 		panic("dmainit: DMA card requires hp320 support");
    149  1.1      cgd #endif
    150  1.6  thorpej 	} else
    151  1.6  thorpej 		rev = dma->dma_id[2];
    152  1.6  thorpej 
    153  1.6  thorpej 	sc->sc_type = (rev == 'B') ? DMA_B : DMA_C;
    154  1.1      cgd 
    155  1.6  thorpej 	for (i = 0; i < NDMACHAN; i++) {
    156  1.6  thorpej 		dc = &sc->sc_chan[i];
    157  1.6  thorpej 		dc->dm_softc = sc;
    158  1.6  thorpej 		switch (i) {
    159  1.6  thorpej 		case 0:
    160  1.6  thorpej 			dc->dm_hwaddr = &dma->dma_chan0;
    161  1.6  thorpej 			dc->dm_Bhwaddr = &dma->dma_Bchan0;
    162  1.6  thorpej 			break;
    163  1.6  thorpej 
    164  1.6  thorpej 		case 1:
    165  1.6  thorpej 			dc->dm_hwaddr = &dma->dma_chan1;
    166  1.6  thorpej 			dc->dm_Bhwaddr = &dma->dma_Bchan1;
    167  1.6  thorpej 			break;
    168  1.6  thorpej 
    169  1.6  thorpej 		default:
    170  1.6  thorpej 			panic("dmainit: more than 2 channels?");
    171  1.6  thorpej 			/* NOTREACHED */
    172  1.6  thorpej 		}
    173  1.1      cgd 		dmachan[i].dq_forw = dmachan[i].dq_back = &dmachan[i];
    174  1.1      cgd 	}
    175  1.1      cgd 	dmachan[i].dq_forw = dmachan[i].dq_back = &dmachan[i];
    176  1.1      cgd #ifdef DEBUG
    177  1.1      cgd 	/* make sure timeout is really not needed */
    178  1.6  thorpej 	timeout(dmatimeout, sc, 30 * hz);
    179  1.1      cgd #endif
    180  1.1      cgd 
    181  1.6  thorpej 	printf("%s: 98620%c, 2 channels, %d bit\n", sc->sc_xname,
    182  1.6  thorpej 	       rev, (rev == 'B') ? 16 : 32);
    183  1.7  thorpej 
    184  1.7  thorpej 	/* Establish the interrupt handler */
    185  1.7  thorpej 	isrlink(dmaintr, sc, DMAINTLVL, ISRPRI_BIO);
    186  1.1      cgd }
    187  1.1      cgd 
    188  1.1      cgd int
    189  1.1      cgd dmareq(dq)
    190  1.1      cgd 	register struct devqueue *dq;
    191  1.1      cgd {
    192  1.1      cgd 	register int i;
    193  1.1      cgd 	register int chan;
    194  1.1      cgd 	register int s = splbio();
    195  1.1      cgd 
    196  1.1      cgd 	chan = dq->dq_ctlr;
    197  1.6  thorpej 	i = NDMACHAN;
    198  1.1      cgd 	while (--i >= 0) {
    199  1.1      cgd 		if ((chan & (1 << i)) == 0)
    200  1.1      cgd 			continue;
    201  1.1      cgd 		if (dmachan[i].dq_forw != &dmachan[i])
    202  1.1      cgd 			continue;
    203  1.1      cgd 		insque(dq, &dmachan[i]);
    204  1.1      cgd 		dq->dq_ctlr = i;
    205  1.1      cgd 		splx(s);
    206  1.1      cgd 		return(1);
    207  1.1      cgd 	}
    208  1.6  thorpej 	insque(dq, dmachan[NDMACHAN].dq_back);
    209  1.1      cgd 	splx(s);
    210  1.1      cgd 	return(0);
    211  1.1      cgd }
    212  1.1      cgd 
    213  1.1      cgd void
    214  1.1      cgd dmafree(dq)
    215  1.1      cgd 	register struct devqueue *dq;
    216  1.1      cgd {
    217  1.1      cgd 	int unit = dq->dq_ctlr;
    218  1.6  thorpej 	struct dma_softc *sc = &Dma_softc;
    219  1.6  thorpej 	register struct dma_channel *dc = &sc->sc_chan[unit];
    220  1.1      cgd 	register struct devqueue *dn;
    221  1.1      cgd 	register int chan, s;
    222  1.1      cgd 
    223  1.1      cgd 	s = splbio();
    224  1.1      cgd #ifdef DEBUG
    225  1.1      cgd 	dmatimo[unit] = 0;
    226  1.1      cgd #endif
    227  1.1      cgd 	DMA_CLEAR(dc);
    228  1.4  mycroft #if defined(HP360) || defined(HP370) || defined(HP380)
    229  1.1      cgd 	/*
    230  1.1      cgd 	 * XXX we may not always go thru the flush code in dmastop()
    231  1.1      cgd 	 */
    232  1.6  thorpej 	if (dc->dm_flags & DMAF_PCFLUSH) {
    233  1.1      cgd 		PCIA();
    234  1.6  thorpej 		dc->dm_flags &= ~DMAF_PCFLUSH;
    235  1.1      cgd 	}
    236  1.1      cgd #endif
    237  1.1      cgd #if defined(HP320) || defined(HP350)
    238  1.6  thorpej 	if (dc->dm_flags & DMAF_VCFLUSH) {
    239  1.1      cgd 		/*
    240  1.1      cgd 		 * 320/350s have VACs that may also need flushing.
    241  1.1      cgd 		 * In our case we only flush the supervisor side
    242  1.1      cgd 		 * because we know that if we are DMAing to user
    243  1.1      cgd 		 * space, the physical pages will also be mapped
    244  1.1      cgd 		 * in kernel space (via vmapbuf) and hence cache-
    245  1.1      cgd 		 * inhibited by the pmap module due to the multiple
    246  1.1      cgd 		 * mapping.
    247  1.1      cgd 		 */
    248  1.1      cgd 		DCIS();
    249  1.6  thorpej 		dc->dm_flags &= ~DMAF_VCFLUSH;
    250  1.1      cgd 	}
    251  1.1      cgd #endif
    252  1.1      cgd 	remque(dq);
    253  1.1      cgd 	chan = 1 << unit;
    254  1.6  thorpej 	for (dn = dmachan[NDMACHAN].dq_forw;
    255  1.6  thorpej 	     dn != &dmachan[NDMACHAN]; dn = dn->dq_forw) {
    256  1.1      cgd 		if (dn->dq_ctlr & chan) {
    257  1.1      cgd 			remque((caddr_t)dn);
    258  1.1      cgd 			insque((caddr_t)dn, (caddr_t)dq->dq_back);
    259  1.1      cgd 			splx(s);
    260  1.1      cgd 			dn->dq_ctlr = dq->dq_ctlr;
    261  1.1      cgd 			(dn->dq_driver->d_start)(dn->dq_unit);
    262  1.1      cgd 			return;
    263  1.1      cgd 		}
    264  1.1      cgd 	}
    265  1.1      cgd 	splx(s);
    266  1.1      cgd }
    267  1.1      cgd 
    268  1.1      cgd void
    269  1.1      cgd dmago(unit, addr, count, flags)
    270  1.1      cgd 	int unit;
    271  1.1      cgd 	register char *addr;
    272  1.1      cgd 	register int count;
    273  1.1      cgd 	register int flags;
    274  1.1      cgd {
    275  1.6  thorpej 	struct dma_softc *sc = &Dma_softc;
    276  1.6  thorpej 	register struct dma_channel *dc = &sc->sc_chan[unit];
    277  1.1      cgd 	register struct dma_chain *dcp;
    278  1.1      cgd 	register char *dmaend = NULL;
    279  1.1      cgd 	register int tcount;
    280  1.1      cgd 
    281  1.1      cgd 	if (count > MAXPHYS)
    282  1.1      cgd 		panic("dmago: count > MAXPHYS");
    283  1.1      cgd #if defined(HP320)
    284  1.6  thorpej 	if (sc->sc_type == DMA_B && (flags & DMAGO_LWORD))
    285  1.1      cgd 		panic("dmago: no can do 32-bit DMA");
    286  1.1      cgd #endif
    287  1.1      cgd #ifdef DEBUG
    288  1.1      cgd 	if (dmadebug & DDB_FOLLOW)
    289  1.1      cgd 		printf("dmago(%d, %x, %x, %x)\n",
    290  1.1      cgd 		       unit, addr, count, flags);
    291  1.1      cgd 	if (flags & DMAGO_LWORD)
    292  1.1      cgd 		dmalword[unit]++;
    293  1.1      cgd 	else if (flags & DMAGO_WORD)
    294  1.1      cgd 		dmaword[unit]++;
    295  1.1      cgd 	else
    296  1.1      cgd 		dmabyte[unit]++;
    297  1.1      cgd #endif
    298  1.1      cgd 	/*
    299  1.1      cgd 	 * Build the DMA chain
    300  1.1      cgd 	 */
    301  1.6  thorpej 	for (dcp = dc->dm_chain; count > 0; dcp++) {
    302  1.1      cgd 		dcp->dc_addr = (char *) kvtop(addr);
    303  1.4  mycroft #if defined(HP380)
    304  1.4  mycroft 		/*
    305  1.4  mycroft 		 * Push back dirty cache lines
    306  1.4  mycroft 		 */
    307  1.4  mycroft 		if (mmutype == MMU_68040)
    308  1.4  mycroft 			DCFP(dcp->dc_addr);
    309  1.4  mycroft #endif
    310  1.1      cgd 		if (count < (tcount = NBPG - ((int)addr & PGOFSET)))
    311  1.1      cgd 			tcount = count;
    312  1.1      cgd 		dcp->dc_count = tcount;
    313  1.1      cgd 		addr += tcount;
    314  1.1      cgd 		count -= tcount;
    315  1.1      cgd 		if (flags & DMAGO_LWORD)
    316  1.1      cgd 			tcount >>= 2;
    317  1.1      cgd 		else if (flags & DMAGO_WORD)
    318  1.1      cgd 			tcount >>= 1;
    319  1.1      cgd 		if (dcp->dc_addr == dmaend
    320  1.1      cgd #if defined(HP320)
    321  1.1      cgd 		    /* only 16-bit count on 98620B */
    322  1.6  thorpej 		    && (sc->sc_type != DMA_B ||
    323  1.1      cgd 			(dcp-1)->dc_count + tcount <= 65536)
    324  1.1      cgd #endif
    325  1.1      cgd 		) {
    326  1.1      cgd #ifdef DEBUG
    327  1.1      cgd 			dmahits[unit]++;
    328  1.1      cgd #endif
    329  1.1      cgd 			dmaend += dcp->dc_count;
    330  1.1      cgd 			(--dcp)->dc_count += tcount;
    331  1.1      cgd 		} else {
    332  1.1      cgd #ifdef DEBUG
    333  1.1      cgd 			dmamisses[unit]++;
    334  1.1      cgd #endif
    335  1.1      cgd 			dmaend = dcp->dc_addr + dcp->dc_count;
    336  1.1      cgd 			dcp->dc_count = tcount;
    337  1.1      cgd 		}
    338  1.1      cgd 	}
    339  1.6  thorpej 	dc->dm_cur = dc->dm_chain;
    340  1.6  thorpej 	dc->dm_last = --dcp;
    341  1.6  thorpej 	dc->dm_flags = 0;
    342  1.1      cgd 	/*
    343  1.1      cgd 	 * Set up the command word based on flags
    344  1.1      cgd 	 */
    345  1.6  thorpej 	dc->dm_cmd = DMA_ENAB | DMA_IPL(DMAINTLVL) | DMA_START;
    346  1.1      cgd 	if ((flags & DMAGO_READ) == 0)
    347  1.6  thorpej 		dc->dm_cmd |= DMA_WRT;
    348  1.1      cgd 	if (flags & DMAGO_LWORD)
    349  1.6  thorpej 		dc->dm_cmd |= DMA_LWORD;
    350  1.1      cgd 	else if (flags & DMAGO_WORD)
    351  1.6  thorpej 		dc->dm_cmd |= DMA_WORD;
    352  1.1      cgd 	if (flags & DMAGO_PRI)
    353  1.6  thorpej 		dc->dm_cmd |= DMA_PRI;
    354  1.4  mycroft #if defined(HP380)
    355  1.4  mycroft 	/*
    356  1.4  mycroft 	 * On the 68040 we need to flush (push) the data cache before a
    357  1.4  mycroft 	 * DMA (already done above) and flush again after DMA completes.
    358  1.4  mycroft 	 * In theory we should only need to flush prior to a write DMA
    359  1.4  mycroft 	 * and purge after a read DMA but if the entire page is not
    360  1.4  mycroft 	 * involved in the DMA we might purge some valid data.
    361  1.4  mycroft 	 */
    362  1.4  mycroft 	if (mmutype == MMU_68040 && (flags & DMAGO_READ))
    363  1.6  thorpej 		dc->dm_flags |= DMAF_PCFLUSH;
    364  1.4  mycroft #endif
    365  1.1      cgd #if defined(HP360) || defined(HP370)
    366  1.1      cgd 	/*
    367  1.1      cgd 	 * Remember if we need to flush external physical cache when
    368  1.1      cgd 	 * DMA is done.  We only do this if we are reading (writing memory).
    369  1.1      cgd 	 */
    370  1.1      cgd 	if (ectype == EC_PHYS && (flags & DMAGO_READ))
    371  1.6  thorpej 		dc->dm_flags |= DMAF_PCFLUSH;
    372  1.1      cgd #endif
    373  1.1      cgd #if defined(HP320) || defined(HP350)
    374  1.1      cgd 	if (ectype == EC_VIRT && (flags & DMAGO_READ))
    375  1.6  thorpej 		dc->dm_flags |= DMAF_VCFLUSH;
    376  1.1      cgd #endif
    377  1.1      cgd 	/*
    378  1.1      cgd 	 * Remember if we can skip the dma completion interrupt on
    379  1.1      cgd 	 * the last segment in the chain.
    380  1.1      cgd 	 */
    381  1.1      cgd 	if (flags & DMAGO_NOINT) {
    382  1.6  thorpej 		if (dc->dm_cur == dc->dm_last)
    383  1.6  thorpej 			dc->dm_cmd &= ~DMA_ENAB;
    384  1.1      cgd 		else
    385  1.6  thorpej 			dc->dm_flags |= DMAF_NOINTR;
    386  1.1      cgd 	}
    387  1.1      cgd #ifdef DEBUG
    388  1.1      cgd 	if (dmadebug & DDB_IO)
    389  1.6  thorpej 		if ((dmadebug&DDB_WORD) && (dc->dm_cmd&DMA_WORD) ||
    390  1.6  thorpej 		    (dmadebug&DDB_LWORD) && (dc->dm_cmd&DMA_LWORD)) {
    391  1.1      cgd 			printf("dmago: cmd %x, flags %x\n",
    392  1.6  thorpej 			       dc->dm_cmd, dc->dm_flags);
    393  1.6  thorpej 			for (dcp = dc->dm_chain; dcp <= dc->dm_last; dcp++)
    394  1.6  thorpej 				printf("  %d: %d@%x\n", dcp-dc->dm_chain,
    395  1.1      cgd 				       dcp->dc_count, dcp->dc_addr);
    396  1.1      cgd 		}
    397  1.1      cgd 	dmatimo[unit] = 1;
    398  1.1      cgd #endif
    399  1.1      cgd 	DMA_ARM(dc);
    400  1.1      cgd }
    401  1.1      cgd 
    402  1.1      cgd void
    403  1.1      cgd dmastop(unit)
    404  1.1      cgd 	register int unit;
    405  1.1      cgd {
    406  1.6  thorpej 	struct dma_softc *sc = &Dma_softc;
    407  1.6  thorpej 	register struct dma_channel *dc = &sc->sc_chan[unit];
    408  1.1      cgd 	register struct devqueue *dq;
    409  1.1      cgd 
    410  1.1      cgd #ifdef DEBUG
    411  1.1      cgd 	if (dmadebug & DDB_FOLLOW)
    412  1.1      cgd 		printf("dmastop(%d)\n", unit);
    413  1.1      cgd 	dmatimo[unit] = 0;
    414  1.1      cgd #endif
    415  1.1      cgd 	DMA_CLEAR(dc);
    416  1.4  mycroft #if defined(HP360) || defined(HP370) || defined(HP380)
    417  1.6  thorpej 	if (dc->dm_flags & DMAF_PCFLUSH) {
    418  1.1      cgd 		PCIA();
    419  1.6  thorpej 		dc->dm_flags &= ~DMAF_PCFLUSH;
    420  1.1      cgd 	}
    421  1.1      cgd #endif
    422  1.1      cgd #if defined(HP320) || defined(HP350)
    423  1.6  thorpej 	if (dc->dm_flags & DMAF_VCFLUSH) {
    424  1.1      cgd 		/*
    425  1.1      cgd 		 * 320/350s have VACs that may also need flushing.
    426  1.1      cgd 		 * In our case we only flush the supervisor side
    427  1.1      cgd 		 * because we know that if we are DMAing to user
    428  1.1      cgd 		 * space, the physical pages will also be mapped
    429  1.1      cgd 		 * in kernel space (via vmapbuf) and hence cache-
    430  1.1      cgd 		 * inhibited by the pmap module due to the multiple
    431  1.1      cgd 		 * mapping.
    432  1.1      cgd 		 */
    433  1.1      cgd 		DCIS();
    434  1.6  thorpej 		dc->dm_flags &= ~DMAF_VCFLUSH;
    435  1.1      cgd 	}
    436  1.1      cgd #endif
    437  1.1      cgd 	/*
    438  1.1      cgd 	 * We may get this interrupt after a device service routine
    439  1.1      cgd 	 * has freed the dma channel.  So, ignore the intr if there's
    440  1.1      cgd 	 * nothing on the queue.
    441  1.1      cgd 	 */
    442  1.1      cgd 	dq = dmachan[unit].dq_forw;
    443  1.1      cgd 	if (dq != &dmachan[unit])
    444  1.1      cgd 		(dq->dq_driver->d_done)(dq->dq_unit);
    445  1.1      cgd }
    446  1.1      cgd 
    447  1.1      cgd int
    448  1.7  thorpej dmaintr(arg)
    449  1.7  thorpej 	void *arg;
    450  1.1      cgd {
    451  1.7  thorpej 	struct dma_softc *sc = arg;
    452  1.6  thorpej 	register struct dma_channel *dc;
    453  1.1      cgd 	register int i, stat;
    454  1.1      cgd 	int found = 0;
    455  1.1      cgd 
    456  1.1      cgd #ifdef DEBUG
    457  1.1      cgd 	if (dmadebug & DDB_FOLLOW)
    458  1.1      cgd 		printf("dmaintr\n");
    459  1.1      cgd #endif
    460  1.6  thorpej 	for (i = 0; i < NDMACHAN; i++) {
    461  1.6  thorpej 		dc = &sc->sc_chan[i];
    462  1.1      cgd 		stat = DMA_STAT(dc);
    463  1.1      cgd 		if ((stat & DMA_INTR) == 0)
    464  1.1      cgd 			continue;
    465  1.1      cgd 		found++;
    466  1.1      cgd #ifdef DEBUG
    467  1.1      cgd 		if (dmadebug & DDB_IO) {
    468  1.6  thorpej 			if ((dmadebug&DDB_WORD) && (dc->dm_cmd&DMA_WORD) ||
    469  1.6  thorpej 			    (dmadebug&DDB_LWORD) && (dc->dm_cmd&DMA_LWORD))
    470  1.1      cgd 				printf("dmaintr: unit %d stat %x next %d\n",
    471  1.6  thorpej 				       i, stat, (dc->dm_cur-dc->dm_chain)+1);
    472  1.1      cgd 		}
    473  1.1      cgd 		if (stat & DMA_ARMED)
    474  1.6  thorpej 			printf("%s, chan %d: intr when armed\n",
    475  1.6  thorpej 			    sc->sc_xname, i);
    476  1.1      cgd #endif
    477  1.6  thorpej 		if (++dc->dm_cur <= dc->dm_last) {
    478  1.1      cgd #ifdef DEBUG
    479  1.1      cgd 			dmatimo[i] = 1;
    480  1.1      cgd #endif
    481  1.1      cgd 			/*
    482  1.1      cgd 			 * Last chain segment, disable DMA interrupt.
    483  1.1      cgd 			 */
    484  1.6  thorpej 			if (dc->dm_cur == dc->dm_last &&
    485  1.6  thorpej 			    (dc->dm_flags & DMAF_NOINTR))
    486  1.6  thorpej 				dc->dm_cmd &= ~DMA_ENAB;
    487  1.1      cgd 			DMA_CLEAR(dc);
    488  1.1      cgd 			DMA_ARM(dc);
    489  1.1      cgd 		} else
    490  1.1      cgd 			dmastop(i);
    491  1.1      cgd 	}
    492  1.1      cgd 	return(found);
    493  1.1      cgd }
    494  1.1      cgd 
    495  1.1      cgd #ifdef DEBUG
    496  1.1      cgd void
    497  1.3  mycroft dmatimeout(arg)
    498  1.3  mycroft 	void *arg;
    499  1.1      cgd {
    500  1.1      cgd 	register int i, s;
    501  1.6  thorpej 	struct dma_softc *sc = arg;
    502  1.1      cgd 
    503  1.6  thorpej 	for (i = 0; i < NDMACHAN; i++) {
    504  1.1      cgd 		s = splbio();
    505  1.1      cgd 		if (dmatimo[i]) {
    506  1.1      cgd 			if (dmatimo[i] > 1)
    507  1.6  thorpej 				printf("%s: timeout #%d\n", sc->sc_xname,
    508  1.1      cgd 				       i, dmatimo[i]-1);
    509  1.1      cgd 			dmatimo[i]++;
    510  1.1      cgd 		}
    511  1.1      cgd 		splx(s);
    512  1.1      cgd 	}
    513  1.6  thorpej 	timeout(dmatimeout, sc, 30 * hz);
    514  1.1      cgd }
    515  1.1      cgd #endif
    516