Home | History | Annotate | Line # | Download | only in dev
intio_dmac.c revision 1.11.8.3
      1  1.11.8.3  nathanw /*	$NetBSD: intio_dmac.c,v 1.11.8.3 2002/08/13 02:19:09 nathanw Exp $	*/
      2  1.11.8.2  nathanw 
      3  1.11.8.2  nathanw /*-
      4  1.11.8.2  nathanw  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  1.11.8.2  nathanw  * All rights reserved.
      6  1.11.8.2  nathanw  *
      7  1.11.8.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11.8.2  nathanw  * by Minoura Makoto.
      9  1.11.8.2  nathanw  *
     10  1.11.8.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.11.8.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.11.8.2  nathanw  * are met:
     13  1.11.8.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.11.8.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.11.8.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.11.8.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.11.8.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.11.8.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.11.8.2  nathanw  *    must display the following acknowledgement:
     20  1.11.8.2  nathanw  *	This product includes software developed by the NetBSD
     21  1.11.8.2  nathanw  *	Foundation, Inc. and its contributors.
     22  1.11.8.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.11.8.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.11.8.2  nathanw  *    from this software without specific prior written permission.
     25  1.11.8.2  nathanw  *
     26  1.11.8.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.11.8.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.11.8.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.11.8.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.11.8.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.11.8.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.11.8.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.11.8.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.11.8.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.11.8.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.11.8.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.11.8.2  nathanw  */
     38  1.11.8.2  nathanw 
     39  1.11.8.2  nathanw /*
     40  1.11.8.2  nathanw  * Hitachi HD63450 (= Motorola MC68450) DMAC driver for x68k.
     41  1.11.8.2  nathanw  */
     42  1.11.8.2  nathanw 
     43  1.11.8.2  nathanw #include "opt_m680x0.h"
     44  1.11.8.2  nathanw 
     45  1.11.8.2  nathanw #include <sys/param.h>
     46  1.11.8.2  nathanw #include <sys/systm.h>
     47  1.11.8.2  nathanw #include <sys/device.h>
     48  1.11.8.2  nathanw #include <uvm/uvm_extern.h>
     49  1.11.8.2  nathanw 
     50  1.11.8.2  nathanw #include <machine/bus.h>
     51  1.11.8.2  nathanw #include <machine/cpu.h>
     52  1.11.8.2  nathanw #include <machine/frame.h>
     53  1.11.8.2  nathanw 
     54  1.11.8.2  nathanw #include <arch/x68k/dev/intiovar.h>
     55  1.11.8.2  nathanw #include <arch/x68k/dev/dmacvar.h>
     56  1.11.8.2  nathanw 
     57  1.11.8.2  nathanw #ifdef DMAC_DEBUG
     58  1.11.8.3  nathanw #define DPRINTF(n,x)	if (dmacdebug>((n)&0x0f)) printf x
     59  1.11.8.3  nathanw #define DDUMPREGS(n,x)	if (dmacdebug>((n)&0x0f)) {printf x; dmac_dump_regs();}
     60  1.11.8.2  nathanw int dmacdebug = 0;
     61  1.11.8.2  nathanw #else
     62  1.11.8.2  nathanw #define DPRINTF(n,x)
     63  1.11.8.2  nathanw #define DDUMPREGS(n,x)
     64  1.11.8.2  nathanw #endif
     65  1.11.8.2  nathanw 
     66  1.11.8.2  nathanw static void dmac_init_channels __P((struct dmac_softc*));
     67  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
     68  1.11.8.2  nathanw static int dmac_program_arraychain __P((struct device*, struct dmac_dma_xfer*,
     69  1.11.8.2  nathanw 					u_int, u_int));
     70  1.11.8.2  nathanw #endif
     71  1.11.8.2  nathanw static int dmac_done __P((void*));
     72  1.11.8.2  nathanw static int dmac_error __P((void*));
     73  1.11.8.2  nathanw 
     74  1.11.8.2  nathanw #ifdef DMAC_DEBUG
     75  1.11.8.2  nathanw static int dmac_dump_regs __P((void));
     76  1.11.8.2  nathanw #endif
     77  1.11.8.2  nathanw 
     78  1.11.8.2  nathanw /*
     79  1.11.8.2  nathanw  * autoconf stuff
     80  1.11.8.2  nathanw  */
     81  1.11.8.2  nathanw static int dmac_match __P((struct device *, struct cfdata *, void *));
     82  1.11.8.2  nathanw static void dmac_attach __P((struct device *, struct device *, void *));
     83  1.11.8.2  nathanw 
     84  1.11.8.2  nathanw struct cfattach dmac_ca = {
     85  1.11.8.2  nathanw 	sizeof(struct dmac_softc), dmac_match, dmac_attach
     86  1.11.8.2  nathanw };
     87  1.11.8.2  nathanw 
     88  1.11.8.2  nathanw static int
     89  1.11.8.2  nathanw dmac_match(parent, cf, aux)
     90  1.11.8.2  nathanw 	struct device *parent;
     91  1.11.8.2  nathanw 	struct cfdata *cf;
     92  1.11.8.2  nathanw 	void *aux;
     93  1.11.8.2  nathanw {
     94  1.11.8.2  nathanw 	struct intio_attach_args *ia = aux;
     95  1.11.8.2  nathanw 
     96  1.11.8.2  nathanw 	if (strcmp (ia->ia_name, "dmac") != 0)
     97  1.11.8.2  nathanw 		return (0);
     98  1.11.8.2  nathanw 	if (cf->cf_unit != 0)
     99  1.11.8.2  nathanw 		return (0);
    100  1.11.8.2  nathanw 
    101  1.11.8.2  nathanw 	if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
    102  1.11.8.2  nathanw 		ia->ia_addr = DMAC_ADDR;
    103  1.11.8.2  nathanw 
    104  1.11.8.2  nathanw 	/* fixed address */
    105  1.11.8.2  nathanw 	if (ia->ia_addr != DMAC_ADDR)
    106  1.11.8.2  nathanw 		return (0);
    107  1.11.8.2  nathanw 	if (ia->ia_intr != INTIOCF_INTR_DEFAULT)
    108  1.11.8.2  nathanw 		return (0);
    109  1.11.8.2  nathanw 
    110  1.11.8.2  nathanw 	return 1;
    111  1.11.8.2  nathanw }
    112  1.11.8.2  nathanw 
    113  1.11.8.2  nathanw static void
    114  1.11.8.2  nathanw dmac_attach(parent, self, aux)
    115  1.11.8.2  nathanw 	struct device *parent, *self;
    116  1.11.8.2  nathanw 	void *aux;
    117  1.11.8.2  nathanw {
    118  1.11.8.2  nathanw 	struct dmac_softc *sc = (struct dmac_softc *)self;
    119  1.11.8.2  nathanw 	struct intio_attach_args *ia = aux;
    120  1.11.8.2  nathanw 	int r;
    121  1.11.8.2  nathanw 
    122  1.11.8.2  nathanw 	ia->ia_size = DMAC_CHAN_SIZE * DMAC_NCHAN;
    123  1.11.8.2  nathanw 	r = intio_map_allocate_region (parent, ia, INTIO_MAP_ALLOCATE);
    124  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    125  1.11.8.2  nathanw 	if (r)
    126  1.11.8.2  nathanw 		panic ("IO map for DMAC corruption??");
    127  1.11.8.2  nathanw #endif
    128  1.11.8.2  nathanw 
    129  1.11.8.2  nathanw 	((struct intio_softc*) parent)->sc_dmac = self;
    130  1.11.8.2  nathanw 	sc->sc_bst = ia->ia_bst;
    131  1.11.8.2  nathanw 	bus_space_map (sc->sc_bst, ia->ia_addr, ia->ia_size, 0, &sc->sc_bht);
    132  1.11.8.2  nathanw 	dmac_init_channels(sc);
    133  1.11.8.2  nathanw 
    134  1.11.8.2  nathanw 	printf (": HD63450 DMAC\n%s: 4 channels available.\n", self->dv_xname);
    135  1.11.8.2  nathanw }
    136  1.11.8.2  nathanw 
    137  1.11.8.2  nathanw static void
    138  1.11.8.2  nathanw dmac_init_channels(sc)
    139  1.11.8.2  nathanw 	struct dmac_softc *sc;
    140  1.11.8.2  nathanw {
    141  1.11.8.2  nathanw 	int i;
    142  1.11.8.2  nathanw 
    143  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_init_channels\n"));
    144  1.11.8.2  nathanw 	for (i=0; i<DMAC_NCHAN; i++) {
    145  1.11.8.2  nathanw 		sc->sc_channels[i].ch_channel = i;
    146  1.11.8.2  nathanw 		sc->sc_channels[i].ch_name[0] = 0;
    147  1.11.8.2  nathanw 		sc->sc_channels[i].ch_softc = &sc->sc_dev;
    148  1.11.8.2  nathanw 		bus_space_subregion(sc->sc_bst, sc->sc_bht,
    149  1.11.8.2  nathanw 				    DMAC_CHAN_SIZE*i, DMAC_CHAN_SIZE,
    150  1.11.8.2  nathanw 				    &sc->sc_channels[i].ch_bht);
    151  1.11.8.2  nathanw 		sc->sc_channels[i].ch_xfer.dx_dmamap = 0;
    152  1.11.8.2  nathanw 		/* reset the status register */
    153  1.11.8.2  nathanw 		bus_space_write_1(sc->sc_bst, sc->sc_channels[i].ch_bht,
    154  1.11.8.2  nathanw 				  DMAC_REG_CSR, 0xff);
    155  1.11.8.2  nathanw 	}
    156  1.11.8.2  nathanw 
    157  1.11.8.2  nathanw 	return;
    158  1.11.8.2  nathanw }
    159  1.11.8.2  nathanw 
    160  1.11.8.2  nathanw 
    161  1.11.8.2  nathanw /*
    162  1.11.8.2  nathanw  * Channel initialization/deinitialization per user device.
    163  1.11.8.2  nathanw  */
    164  1.11.8.2  nathanw struct dmac_channel_stat *
    165  1.11.8.2  nathanw dmac_alloc_channel(self, ch, name,
    166  1.11.8.2  nathanw 		   normalv, normal, normalarg,
    167  1.11.8.2  nathanw 		   errorv, error, errorarg)
    168  1.11.8.2  nathanw 	struct device *self;
    169  1.11.8.2  nathanw 	int ch;
    170  1.11.8.2  nathanw 	char *name;
    171  1.11.8.2  nathanw 	int normalv, errorv;
    172  1.11.8.2  nathanw 	dmac_intr_handler_t normal, error;
    173  1.11.8.2  nathanw 	void *normalarg, *errorarg;
    174  1.11.8.2  nathanw {
    175  1.11.8.2  nathanw 	struct intio_softc *intio = (void*) self;
    176  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) intio->sc_dmac;
    177  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = &sc->sc_channels[ch];
    178  1.11.8.2  nathanw 	char intrname[16];
    179  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    180  1.11.8.2  nathanw 	int r, dummy;
    181  1.11.8.2  nathanw #endif
    182  1.11.8.2  nathanw 
    183  1.11.8.2  nathanw 	printf ("%s: allocating ch %d for %s.\n",
    184  1.11.8.2  nathanw 		sc->sc_dev.dv_xname, ch, name);
    185  1.11.8.2  nathanw 	DPRINTF (3, ("dmamap=%p\n", (void*) chan->ch_xfer.dx_dmamap));
    186  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    187  1.11.8.2  nathanw 	if (ch < 0 || ch >= DMAC_NCHAN)
    188  1.11.8.2  nathanw 		panic ("Invalid DMAC channel.");
    189  1.11.8.2  nathanw 	if (chan->ch_name[0])
    190  1.11.8.2  nathanw 		panic ("DMAC: channel in use.");
    191  1.11.8.2  nathanw 	if (strlen(name) > 8)
    192  1.11.8.2  nathanw 	  	panic ("DMAC: wrong user name.");
    193  1.11.8.2  nathanw #endif
    194  1.11.8.2  nathanw 
    195  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    196  1.11.8.2  nathanw 	/* allocate the DMAC arraychaining map */
    197  1.11.8.2  nathanw 	r = bus_dmamem_alloc(intio->sc_dmat,
    198  1.11.8.2  nathanw 			     sizeof(struct dmac_sg_array) * DMAC_MAPSIZE,
    199  1.11.8.2  nathanw 			     4, 0, &chan->ch_seg[0], 1, &dummy,
    200  1.11.8.2  nathanw 			     BUS_DMA_NOWAIT);
    201  1.11.8.2  nathanw 	if (r)
    202  1.11.8.2  nathanw 		panic ("DMAC: cannot alloc DMA safe memory");
    203  1.11.8.2  nathanw 	r = bus_dmamem_map(intio->sc_dmat,
    204  1.11.8.2  nathanw 			   &chan->ch_seg[0], 1,
    205  1.11.8.2  nathanw 			   sizeof(struct dmac_sg_array) * DMAC_MAPSIZE,
    206  1.11.8.2  nathanw 			   (caddr_t*) &chan->ch_map,
    207  1.11.8.2  nathanw 			   BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
    208  1.11.8.2  nathanw 	if (r)
    209  1.11.8.2  nathanw 		panic ("DMAC: cannot map DMA safe memory");
    210  1.11.8.2  nathanw #endif
    211  1.11.8.2  nathanw 
    212  1.11.8.2  nathanw 	/* fill the channel status structure by the default values. */
    213  1.11.8.2  nathanw 	strcpy(chan->ch_name, name);
    214  1.11.8.2  nathanw 	chan->ch_dcr = (DMAC_DCR_XRM_CSWH | DMAC_DCR_OTYP_EASYNC |
    215  1.11.8.2  nathanw 			DMAC_DCR_OPS_8BIT);
    216  1.11.8.2  nathanw 	chan->ch_ocr = (DMAC_OCR_SIZE_BYTE | DMAC_OCR_REQG_EXTERNAL);
    217  1.11.8.2  nathanw 	chan->ch_normalv = normalv;
    218  1.11.8.2  nathanw 	chan->ch_errorv = errorv;
    219  1.11.8.2  nathanw 	chan->ch_normal = normal;
    220  1.11.8.2  nathanw 	chan->ch_error = error;
    221  1.11.8.2  nathanw 	chan->ch_normalarg = normalarg;
    222  1.11.8.2  nathanw 	chan->ch_errorarg = errorarg;
    223  1.11.8.2  nathanw 	chan->ch_xfer.dx_dmamap = 0;
    224  1.11.8.2  nathanw 
    225  1.11.8.2  nathanw 	/* setup the device-specific registers */
    226  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    227  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht,
    228  1.11.8.2  nathanw 			   DMAC_REG_DCR, chan->ch_dcr);
    229  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_CPR, 0);
    230  1.11.8.2  nathanw 
    231  1.11.8.2  nathanw 	/*
    232  1.11.8.2  nathanw 	 * X68k physical user space is a subset of the kernel space;
    233  1.11.8.2  nathanw 	 * the memory is always included in the physical user space,
    234  1.11.8.2  nathanw 	 * while the device is not.
    235  1.11.8.2  nathanw 	 */
    236  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht,
    237  1.11.8.2  nathanw 			   DMAC_REG_BFCR, DMAC_FC_USER_DATA);
    238  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht,
    239  1.11.8.2  nathanw 			   DMAC_REG_MFCR, DMAC_FC_USER_DATA);
    240  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht,
    241  1.11.8.2  nathanw 			   DMAC_REG_DFCR, DMAC_FC_KERNEL_DATA);
    242  1.11.8.2  nathanw 
    243  1.11.8.2  nathanw 	/* setup the interrupt handlers */
    244  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR, normalv);
    245  1.11.8.2  nathanw 	bus_space_write_1 (sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR, errorv);
    246  1.11.8.2  nathanw 
    247  1.11.8.2  nathanw 	strcpy(intrname, name);
    248  1.11.8.2  nathanw 	strcat(intrname, "dma");
    249  1.11.8.2  nathanw 	intio_intr_establish (normalv, intrname, dmac_done, chan);
    250  1.11.8.2  nathanw 
    251  1.11.8.2  nathanw 	strcpy(intrname, name);
    252  1.11.8.2  nathanw 	strcat(intrname, "dmaerr");
    253  1.11.8.2  nathanw 	intio_intr_establish (errorv, intrname, dmac_error, chan);
    254  1.11.8.2  nathanw 
    255  1.11.8.2  nathanw 	return chan;
    256  1.11.8.2  nathanw }
    257  1.11.8.2  nathanw 
    258  1.11.8.2  nathanw int
    259  1.11.8.2  nathanw dmac_free_channel(self, ch, channel)
    260  1.11.8.2  nathanw 	struct device *self;
    261  1.11.8.2  nathanw 	int ch;
    262  1.11.8.2  nathanw 	void *channel;
    263  1.11.8.2  nathanw {
    264  1.11.8.2  nathanw 	struct intio_softc *intio = (void*) self;
    265  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) intio->sc_dmac;
    266  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = &sc->sc_channels[ch];
    267  1.11.8.2  nathanw 
    268  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_free_channel, %d\n", ch));
    269  1.11.8.2  nathanw 	DPRINTF (3, ("dmamap=%p\n", (void*) chan->ch_xfer.dx_dmamap));
    270  1.11.8.2  nathanw 	if (chan != channel)
    271  1.11.8.2  nathanw 		return -1;
    272  1.11.8.2  nathanw 	if (ch != chan->ch_channel)
    273  1.11.8.2  nathanw 		return -1;
    274  1.11.8.2  nathanw 
    275  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    276  1.11.8.2  nathanw 	bus_dmamem_unmap(intio->sc_dmat, (caddr_t) chan->ch_map,
    277  1.11.8.2  nathanw 			 sizeof(struct dmac_sg_array) * DMAC_MAPSIZE);
    278  1.11.8.2  nathanw 	bus_dmamem_free(intio->sc_dmat, &chan->ch_seg[0], 1);
    279  1.11.8.2  nathanw #endif
    280  1.11.8.2  nathanw 	chan->ch_name[0] = 0;
    281  1.11.8.2  nathanw 	intio_intr_disestablish(chan->ch_normalv, channel);
    282  1.11.8.2  nathanw 	intio_intr_disestablish(chan->ch_errorv, channel);
    283  1.11.8.2  nathanw 
    284  1.11.8.2  nathanw 	return 0;
    285  1.11.8.2  nathanw }
    286  1.11.8.2  nathanw 
    287  1.11.8.2  nathanw /*
    288  1.11.8.2  nathanw  * Initialization / deinitialization per transfer.
    289  1.11.8.2  nathanw  */
    290  1.11.8.2  nathanw struct dmac_dma_xfer *
    291  1.11.8.2  nathanw dmac_alloc_xfer (chan, dmat, dmamap)
    292  1.11.8.2  nathanw 	struct dmac_channel_stat *chan;
    293  1.11.8.2  nathanw 	bus_dma_tag_t dmat;
    294  1.11.8.2  nathanw 	bus_dmamap_t dmamap;
    295  1.11.8.2  nathanw {
    296  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf = &chan->ch_xfer;
    297  1.11.8.2  nathanw 
    298  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_alloc_xfer\n"));
    299  1.11.8.2  nathanw 	xf->dx_channel = chan;
    300  1.11.8.2  nathanw 	xf->dx_dmamap = dmamap;
    301  1.11.8.2  nathanw 	xf->dx_tag = dmat;
    302  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    303  1.11.8.2  nathanw 	xf->dx_array = chan->ch_map;
    304  1.11.8.2  nathanw 	xf->dx_done = 0;
    305  1.11.8.2  nathanw #endif
    306  1.11.8.2  nathanw 	xf->dx_nextoff = xf->dx_nextsize = -1;
    307  1.11.8.2  nathanw 	return xf;
    308  1.11.8.2  nathanw }
    309  1.11.8.2  nathanw 
    310  1.11.8.2  nathanw int
    311  1.11.8.2  nathanw dmac_load_xfer (self, xf)
    312  1.11.8.2  nathanw 	struct device *self;
    313  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    314  1.11.8.2  nathanw {
    315  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) self;
    316  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = xf->dx_channel;
    317  1.11.8.2  nathanw 
    318  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_load_xfer\n"));
    319  1.11.8.2  nathanw 
    320  1.11.8.2  nathanw 	xf->dx_ocr &= ~DMAC_OCR_CHAIN_MASK;
    321  1.11.8.2  nathanw 	if (xf->dx_dmamap->dm_nsegs == 1)
    322  1.11.8.2  nathanw 		xf->dx_ocr |= DMAC_OCR_CHAIN_DISABLED;
    323  1.11.8.2  nathanw 	else {
    324  1.11.8.2  nathanw 		xf->dx_ocr |= DMAC_OCR_CHAIN_ARRAY;
    325  1.11.8.2  nathanw 		xf->dx_nextoff = ~0;
    326  1.11.8.2  nathanw 		xf->dx_nextsize = ~0;
    327  1.11.8.2  nathanw 	}
    328  1.11.8.2  nathanw 
    329  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    330  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_SCR, xf->dx_scr);
    331  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht,
    332  1.11.8.2  nathanw 			  DMAC_REG_OCR, (xf->dx_ocr | chan->ch_ocr));
    333  1.11.8.2  nathanw 	bus_space_write_4(sc->sc_bst, chan->ch_bht,
    334  1.11.8.2  nathanw 			  DMAC_REG_DAR, (int) xf->dx_device);
    335  1.11.8.2  nathanw 
    336  1.11.8.2  nathanw 	return 0;
    337  1.11.8.2  nathanw }
    338  1.11.8.2  nathanw 
    339  1.11.8.2  nathanw struct dmac_dma_xfer *
    340  1.11.8.2  nathanw dmac_prepare_xfer (chan, dmat, dmamap, dir, scr, dar)
    341  1.11.8.2  nathanw 	struct dmac_channel_stat *chan;
    342  1.11.8.2  nathanw 	bus_dma_tag_t dmat;
    343  1.11.8.2  nathanw 	bus_dmamap_t dmamap;
    344  1.11.8.2  nathanw 	int dir, scr;
    345  1.11.8.2  nathanw 	void *dar;
    346  1.11.8.2  nathanw {
    347  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    348  1.11.8.2  nathanw 	struct dmac_softc *sc = (struct dmac_softc*) chan->ch_softc;
    349  1.11.8.2  nathanw 
    350  1.11.8.2  nathanw 	xf = dmac_alloc_xfer(chan, dmat, dmamap);
    351  1.11.8.2  nathanw 
    352  1.11.8.2  nathanw 	xf->dx_ocr = dir & DMAC_OCR_DIR_MASK;
    353  1.11.8.2  nathanw 	xf->dx_scr = scr & (DMAC_SCR_MAC_MASK|DMAC_SCR_DAC_MASK);
    354  1.11.8.2  nathanw 	xf->dx_device = dar;
    355  1.11.8.2  nathanw 
    356  1.11.8.2  nathanw 	dmac_load_xfer(&sc->sc_dev, xf);
    357  1.11.8.2  nathanw 
    358  1.11.8.2  nathanw 	return xf;
    359  1.11.8.2  nathanw }
    360  1.11.8.2  nathanw 
    361  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    362  1.11.8.2  nathanw static struct dmac_channel_stat *debugchan = 0;
    363  1.11.8.2  nathanw #endif
    364  1.11.8.2  nathanw 
    365  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    366  1.11.8.2  nathanw static u_int8_t dcsr, dcer, ddcr, docr, dscr, dccr, dcpr, dgcr,
    367  1.11.8.2  nathanw   dnivr, deivr, ddfcr, dmfcr, dbfcr;
    368  1.11.8.2  nathanw static u_int16_t dmtcr, dbtcr;
    369  1.11.8.2  nathanw static u_int32_t ddar, dmar, dbar;
    370  1.11.8.2  nathanw #endif
    371  1.11.8.2  nathanw /*
    372  1.11.8.2  nathanw  * Do the actual transfer.
    373  1.11.8.2  nathanw  */
    374  1.11.8.2  nathanw int
    375  1.11.8.2  nathanw dmac_start_xfer(self, xf)
    376  1.11.8.2  nathanw 	struct device *self;
    377  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    378  1.11.8.2  nathanw {
    379  1.11.8.2  nathanw 	return dmac_start_xfer_offset(self, xf, 0, 0);
    380  1.11.8.2  nathanw }
    381  1.11.8.2  nathanw 
    382  1.11.8.2  nathanw int
    383  1.11.8.2  nathanw dmac_start_xfer_offset(self, xf, offset, size)
    384  1.11.8.2  nathanw 	struct device *self;
    385  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    386  1.11.8.2  nathanw 	u_int offset;
    387  1.11.8.2  nathanw 	u_int size;
    388  1.11.8.2  nathanw {
    389  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) self;
    390  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = xf->dx_channel;
    391  1.11.8.2  nathanw 	struct x68k_bus_dmamap *dmamap = xf->dx_dmamap;
    392  1.11.8.2  nathanw 	int go = DMAC_CCR_STR|DMAC_CCR_INT;
    393  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    394  1.11.8.2  nathanw 	int c;
    395  1.11.8.2  nathanw #endif
    396  1.11.8.2  nathanw 
    397  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_start_xfer\n"));
    398  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    399  1.11.8.2  nathanw 	debugchan=chan;
    400  1.11.8.2  nathanw #endif
    401  1.11.8.2  nathanw 
    402  1.11.8.2  nathanw 	if (size == 0) {
    403  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    404  1.11.8.2  nathanw 		if (offset != 0)
    405  1.11.8.2  nathanw 			panic ("dmac_start_xfer_offset: invalid offset %x",
    406  1.11.8.2  nathanw 			       offset);
    407  1.11.8.2  nathanw #endif
    408  1.11.8.2  nathanw 		size = dmamap->dm_mapsize;
    409  1.11.8.2  nathanw 	}
    410  1.11.8.2  nathanw 
    411  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    412  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    413  1.11.8.2  nathanw 	if (xf->dx_done)
    414  1.11.8.2  nathanw 		panic("dmac_start_xfer: DMA transfer in progress");
    415  1.11.8.2  nathanw #endif
    416  1.11.8.2  nathanw #endif
    417  1.11.8.2  nathanw 	DPRINTF (3, ("First program:\n"));
    418  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    419  1.11.8.2  nathanw 	if ((offset >= dmamap->dm_mapsize) ||
    420  1.11.8.2  nathanw 	    (offset + size > dmamap->dm_mapsize))
    421  1.11.8.2  nathanw 		panic ("dmac_start_xfer_offset: invalid offset: "
    422  1.11.8.3  nathanw 			"offset=%d, size=%d, mapsize=%ld",
    423  1.11.8.2  nathanw 		       offset, size, dmamap->dm_mapsize);
    424  1.11.8.2  nathanw #endif
    425  1.11.8.2  nathanw 	/* program DMAC in single block mode or array chainning mode */
    426  1.11.8.2  nathanw 	if (dmamap->dm_nsegs == 1) {
    427  1.11.8.2  nathanw 		DPRINTF(3, ("single block mode\n"));
    428  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    429  1.11.8.2  nathanw 		if (dmamap->dm_mapsize != dmamap->dm_segs[0].ds_len)
    430  1.11.8.2  nathanw 			panic ("dmac_start_xfer_offset: dmamap curruption");
    431  1.11.8.2  nathanw #endif
    432  1.11.8.2  nathanw 		if (offset == xf->dx_nextoff &&
    433  1.11.8.2  nathanw 		    size == xf->dx_nextsize) {
    434  1.11.8.2  nathanw 			/* Use continued operation */
    435  1.11.8.2  nathanw 			go |=  DMAC_CCR_CNT;
    436  1.11.8.2  nathanw 			xf->dx_nextoff += size;
    437  1.11.8.2  nathanw 		} else {
    438  1.11.8.2  nathanw 			bus_space_write_4(sc->sc_bst, chan->ch_bht,
    439  1.11.8.2  nathanw 					  DMAC_REG_MAR,
    440  1.11.8.2  nathanw 					  (int) dmamap->dm_segs[0].ds_addr
    441  1.11.8.2  nathanw 					  + offset);
    442  1.11.8.2  nathanw 			bus_space_write_2(sc->sc_bst, chan->ch_bht,
    443  1.11.8.2  nathanw 					  DMAC_REG_MTCR, (int) size);
    444  1.11.8.2  nathanw 			xf->dx_nextoff = offset;
    445  1.11.8.2  nathanw 			xf->dx_nextsize = size;
    446  1.11.8.2  nathanw 		}
    447  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    448  1.11.8.2  nathanw 		xf->dx_done = 1;
    449  1.11.8.2  nathanw #endif
    450  1.11.8.2  nathanw 	} else {
    451  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    452  1.11.8.2  nathanw 		c = dmac_program_arraychain(self, xf, offset, size);
    453  1.11.8.2  nathanw 		bus_space_write_4(sc->sc_bst, chan->ch_bht,
    454  1.11.8.2  nathanw 				  DMAC_REG_BAR, (int) chan->ch_seg[0].ds_addr);
    455  1.11.8.2  nathanw 		bus_space_write_2(sc->sc_bst, chan->ch_bht,
    456  1.11.8.2  nathanw 				  DMAC_REG_BTCR, c);
    457  1.11.8.2  nathanw #else
    458  1.11.8.2  nathanw 		panic ("DMAC: unexpected use of arraychaining mode");
    459  1.11.8.2  nathanw #endif
    460  1.11.8.2  nathanw 	}
    461  1.11.8.2  nathanw 
    462  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    463  1.11.8.2  nathanw 
    464  1.11.8.2  nathanw 	/* START!! */
    465  1.11.8.2  nathanw 	DDUMPREGS (3, ("first start\n"));
    466  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    467  1.11.8.2  nathanw 	dcsr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR);
    468  1.11.8.2  nathanw 	dcer = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER);
    469  1.11.8.2  nathanw 	ddcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DCR);
    470  1.11.8.2  nathanw 	docr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_OCR);
    471  1.11.8.2  nathanw 	dscr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_SCR);
    472  1.11.8.2  nathanw 	dccr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR);
    473  1.11.8.2  nathanw 	dcpr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CPR);
    474  1.11.8.2  nathanw 	dgcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_GCR);
    475  1.11.8.2  nathanw 	dnivr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR);
    476  1.11.8.2  nathanw 	deivr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR);
    477  1.11.8.2  nathanw 	ddfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DFCR);
    478  1.11.8.2  nathanw 	dmfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_MFCR);
    479  1.11.8.2  nathanw 	dbfcr = bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_BFCR);
    480  1.11.8.2  nathanw 	dmtcr = bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_MTCR);
    481  1.11.8.2  nathanw 	dbtcr = bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_BTCR);
    482  1.11.8.2  nathanw 	ddar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_DAR);
    483  1.11.8.2  nathanw 	dmar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_MAR);
    484  1.11.8.2  nathanw 	dbar = bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_BAR);
    485  1.11.8.2  nathanw #endif
    486  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    487  1.11.8.2  nathanw #if defined(M68040) || defined(M68060)
    488  1.11.8.2  nathanw 	/* flush data cache for the map */
    489  1.11.8.2  nathanw 	if (dmamap->dm_nsegs != 1 && mmutype == MMU_68040)
    490  1.11.8.2  nathanw 		dma_cachectl((caddr_t) xf->dx_array,
    491  1.11.8.2  nathanw 			     sizeof(struct dmac_sg_array) * c);
    492  1.11.8.2  nathanw #endif
    493  1.11.8.2  nathanw #endif
    494  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR, go);
    495  1.11.8.2  nathanw 
    496  1.11.8.2  nathanw 	if (xf->dx_nextoff != ~0) {
    497  1.11.8.2  nathanw 		bus_space_write_4(sc->sc_bst, chan->ch_bht,
    498  1.11.8.2  nathanw 				  DMAC_REG_BAR, xf->dx_nextoff);
    499  1.11.8.2  nathanw 		bus_space_write_2(sc->sc_bst, chan->ch_bht,
    500  1.11.8.2  nathanw 				  DMAC_REG_BTCR, xf->dx_nextsize);
    501  1.11.8.2  nathanw 	}
    502  1.11.8.2  nathanw 
    503  1.11.8.2  nathanw 	return 0;
    504  1.11.8.2  nathanw }
    505  1.11.8.2  nathanw 
    506  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    507  1.11.8.2  nathanw static int
    508  1.11.8.2  nathanw dmac_program_arraychain(self, xf, offset, size)
    509  1.11.8.2  nathanw 	struct device *self;
    510  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    511  1.11.8.2  nathanw 	u_int offset;
    512  1.11.8.2  nathanw 	u_int size;
    513  1.11.8.2  nathanw {
    514  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = xf->dx_channel;
    515  1.11.8.2  nathanw 	int ch = chan->ch_channel;
    516  1.11.8.2  nathanw 	struct x68k_bus_dmamap *map = xf->dx_dmamap;
    517  1.11.8.2  nathanw 	int i, j;
    518  1.11.8.2  nathanw 
    519  1.11.8.2  nathanw 	/* XXX not yet!! */
    520  1.11.8.2  nathanw 	if (offset != 0 || size != map->dm_mapsize)
    521  1.11.8.2  nathanw 		panic ("dmac_program_arraychain: unsupported offset/size");
    522  1.11.8.2  nathanw 
    523  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_program_arraychain\n"));
    524  1.11.8.2  nathanw 	for (i=0, j=xf->dx_done; i<DMAC_MAPSIZE && j<map->dm_nsegs;
    525  1.11.8.2  nathanw 	     i++, j++) {
    526  1.11.8.2  nathanw 		xf->dx_array[i].da_addr = map->dm_segs[j].ds_addr;
    527  1.11.8.2  nathanw #ifdef DIAGNOSTIC
    528  1.11.8.2  nathanw 		if (map->dm_segs[j].ds_len > DMAC_MAXSEGSZ)
    529  1.11.8.2  nathanw 			panic ("dmac_program_arraychain: wrong map: %ld",
    530  1.11.8.2  nathanw 			       map->dm_segs[j].ds_len);
    531  1.11.8.2  nathanw #endif
    532  1.11.8.2  nathanw 		xf->dx_array[i].da_count = map->dm_segs[j].ds_len;
    533  1.11.8.2  nathanw 	}
    534  1.11.8.2  nathanw 	xf->dx_done = j;
    535  1.11.8.2  nathanw 
    536  1.11.8.2  nathanw 	return i;
    537  1.11.8.2  nathanw }
    538  1.11.8.2  nathanw #endif
    539  1.11.8.2  nathanw 
    540  1.11.8.2  nathanw /*
    541  1.11.8.2  nathanw  * interrupt handlers.
    542  1.11.8.2  nathanw  */
    543  1.11.8.2  nathanw static int
    544  1.11.8.2  nathanw dmac_done(arg)
    545  1.11.8.2  nathanw 	void *arg;
    546  1.11.8.2  nathanw {
    547  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = arg;
    548  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) chan->ch_softc;
    549  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    550  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf = &chan->ch_xfer;
    551  1.11.8.2  nathanw 	struct x68k_bus_dmamap *map = xf->dx_dmamap;
    552  1.11.8.2  nathanw 	int c;
    553  1.11.8.2  nathanw #endif
    554  1.11.8.2  nathanw 
    555  1.11.8.2  nathanw 	DPRINTF (3, ("dmac_done\n"));
    556  1.11.8.2  nathanw 
    557  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    558  1.11.8.2  nathanw 
    559  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    560  1.11.8.2  nathanw 	if (xf->dx_done == map->dm_nsegs) {
    561  1.11.8.2  nathanw 		xf->dx_done = 0;
    562  1.11.8.2  nathanw #endif
    563  1.11.8.2  nathanw 		/* Done */
    564  1.11.8.2  nathanw 		return (*chan->ch_normal) (chan->ch_normalarg);
    565  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    566  1.11.8.2  nathanw 	}
    567  1.11.8.2  nathanw #endif
    568  1.11.8.2  nathanw 
    569  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    570  1.11.8.2  nathanw 	/* Continue transfer */
    571  1.11.8.2  nathanw 	DPRINTF (3, ("reprograming\n"));
    572  1.11.8.2  nathanw 	c = dmac_program_arraychain (&sc->sc_dev, xf, 0, map->dm_mapsize);
    573  1.11.8.2  nathanw 
    574  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    575  1.11.8.2  nathanw 	bus_space_write_4(sc->sc_bst, chan->ch_bht,
    576  1.11.8.2  nathanw 			  DMAC_REG_BAR, (int) chan->ch_map);
    577  1.11.8.2  nathanw 	bus_space_write_4(sc->sc_bst, chan->ch_bht,
    578  1.11.8.2  nathanw 			  DMAC_REG_DAR, (int) xf->dx_device);
    579  1.11.8.2  nathanw 	bus_space_write_2(sc->sc_bst, chan->ch_bht, DMAC_REG_BTCR, c);
    580  1.11.8.2  nathanw 
    581  1.11.8.2  nathanw 	/* START!! */
    582  1.11.8.2  nathanw 	DDUMPREGS (3, ("restart\n"));
    583  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht,
    584  1.11.8.2  nathanw 			  DMAC_REG_CCR, DMAC_CCR_STR|DMAC_CCR_INT);
    585  1.11.8.2  nathanw 
    586  1.11.8.2  nathanw 	return 1;
    587  1.11.8.2  nathanw #endif
    588  1.11.8.2  nathanw }
    589  1.11.8.2  nathanw 
    590  1.11.8.2  nathanw static int
    591  1.11.8.2  nathanw dmac_error(arg)
    592  1.11.8.2  nathanw 	void *arg;
    593  1.11.8.2  nathanw {
    594  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = arg;
    595  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) chan->ch_softc;
    596  1.11.8.2  nathanw 
    597  1.11.8.2  nathanw 	printf ("DMAC transfer error CSR=%02x, CER=%02x\n",
    598  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR),
    599  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER));
    600  1.11.8.2  nathanw 	DPRINTF(5, ("registers were:\n"));
    601  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    602  1.11.8.2  nathanw 	if ((dmacdebug & 0x0f) > 5) {
    603  1.11.8.2  nathanw 		printf ("CSR=%02x, CER=%02x, DCR=%02x, OCR=%02x, SCR=%02x, "
    604  1.11.8.2  nathanw 			"CCR=%02x, CPR=%02x, GCR=%02x\n",
    605  1.11.8.2  nathanw 			dcsr, dcer, ddcr, docr, dscr, dccr, dcpr, dgcr);
    606  1.11.8.2  nathanw 		printf ("NIVR=%02x, EIVR=%02x, MTCR=%04x, BTCR=%04x, "
    607  1.11.8.2  nathanw 			"DFCR=%02x, MFCR=%02x, BFCR=%02x\n",
    608  1.11.8.2  nathanw 			dnivr, deivr, dmtcr, dbtcr, ddfcr, dmfcr, dbfcr);
    609  1.11.8.2  nathanw 		printf ("DAR=%08x, MAR=%08x, BAR=%08x\n",
    610  1.11.8.2  nathanw 			ddar, dmar, dbar);
    611  1.11.8.2  nathanw 	}
    612  1.11.8.2  nathanw #endif
    613  1.11.8.2  nathanw 
    614  1.11.8.2  nathanw 	/* Clear the status bits */
    615  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    616  1.11.8.2  nathanw 	DDUMPREGS(3, ("dmac_error\n"));
    617  1.11.8.2  nathanw 
    618  1.11.8.2  nathanw #ifdef DMAC_ARRAYCHAIN
    619  1.11.8.2  nathanw 	chan->ch_xfer.dx_done = 0;
    620  1.11.8.2  nathanw #endif
    621  1.11.8.2  nathanw 
    622  1.11.8.2  nathanw 	return (*chan->ch_error) (chan->ch_errorarg);
    623  1.11.8.2  nathanw }
    624  1.11.8.2  nathanw 
    625  1.11.8.2  nathanw int
    626  1.11.8.2  nathanw dmac_abort_xfer(self, xf)
    627  1.11.8.2  nathanw 	struct device *self;
    628  1.11.8.2  nathanw 	struct dmac_dma_xfer *xf;
    629  1.11.8.2  nathanw {
    630  1.11.8.2  nathanw 	struct dmac_softc *sc = (void*) self;
    631  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = xf->dx_channel;
    632  1.11.8.2  nathanw 
    633  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR,
    634  1.11.8.2  nathanw 			  DMAC_CCR_INT | DMAC_CCR_HLT);
    635  1.11.8.2  nathanw 	bus_space_write_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR, 0xff);
    636  1.11.8.2  nathanw 	xf->dx_nextoff = xf->dx_nextsize = -1;
    637  1.11.8.2  nathanw 
    638  1.11.8.2  nathanw 	return 0;
    639  1.11.8.2  nathanw }
    640  1.11.8.2  nathanw 
    641  1.11.8.2  nathanw #ifdef DMAC_DEBUG
    642  1.11.8.2  nathanw static int
    643  1.11.8.2  nathanw dmac_dump_regs(void)
    644  1.11.8.2  nathanw {
    645  1.11.8.2  nathanw 	struct dmac_channel_stat *chan = debugchan;
    646  1.11.8.2  nathanw 	struct dmac_softc *sc;
    647  1.11.8.2  nathanw 
    648  1.11.8.3  nathanw 	if ((chan == 0) || (dmacdebug & 0xf0))
    649  1.11.8.3  nathanw 		return 0;
    650  1.11.8.2  nathanw 	sc = (void*) chan->ch_softc;
    651  1.11.8.2  nathanw 
    652  1.11.8.2  nathanw 	printf ("DMAC channel %d registers\n", chan->ch_channel);
    653  1.11.8.2  nathanw 	printf ("CSR=%02x, CER=%02x, DCR=%02x, OCR=%02x, SCR=%02x,"
    654  1.11.8.2  nathanw 		"CCR=%02x, CPR=%02x, GCR=%02x\n",
    655  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CSR),
    656  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CER),
    657  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DCR),
    658  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_OCR),
    659  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_SCR),
    660  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CCR),
    661  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_CPR),
    662  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_GCR));
    663  1.11.8.2  nathanw 	printf ("NIVR=%02x, EIVR=%02x, MTCR=%04x, BTCR=%04x, DFCR=%02x,"
    664  1.11.8.2  nathanw 		"MFCR=%02x, BFCR=%02x\n",
    665  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_NIVR),
    666  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_EIVR),
    667  1.11.8.2  nathanw 		bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_MTCR),
    668  1.11.8.2  nathanw 		bus_space_read_2(sc->sc_bst, chan->ch_bht, DMAC_REG_BTCR),
    669  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_DFCR),
    670  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_MFCR),
    671  1.11.8.2  nathanw 		bus_space_read_1(sc->sc_bst, chan->ch_bht, DMAC_REG_BFCR));
    672  1.11.8.2  nathanw 	printf ("DAR=%08x, MAR=%08x, BAR=%08x\n",
    673  1.11.8.2  nathanw 		bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_DAR),
    674  1.11.8.2  nathanw 		bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_MAR),
    675  1.11.8.2  nathanw 		bus_space_read_4(sc->sc_bst, chan->ch_bht, DMAC_REG_BAR));
    676  1.11.8.2  nathanw 
    677  1.11.8.2  nathanw 	return 0;
    678  1.11.8.2  nathanw }
    679  1.11.8.2  nathanw #endif
    680