Home | History | Annotate | Line # | Download | only in mca
esp_mca.c revision 1.18
      1  1.18   tsutsui /*	$NetBSD: esp_mca.c,v 1.18 2008/04/13 04:55:53 tsutsui Exp $	*/
      2   1.1  jdolecek 
      3   1.1  jdolecek /*-
      4   1.3  jdolecek  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.1  jdolecek  * All rights reserved.
      6   1.1  jdolecek  *
      7   1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8   1.3  jdolecek  * by Jaromir Dolecek <jdolecek (at) NetBSD.org>.
      9   1.1  jdolecek  *
     10   1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11   1.1  jdolecek  * modification, are permitted provided that the following conditions
     12   1.1  jdolecek  * are met:
     13   1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15   1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18   1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19   1.1  jdolecek  *    must display the following acknowledgement:
     20   1.1  jdolecek  *	This product includes software developed by the NetBSD
     21   1.1  jdolecek  *	Foundation, Inc. and its contributors.
     22   1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     24   1.1  jdolecek  *    from this software without specific prior written permission.
     25   1.1  jdolecek  *
     26   1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  jdolecek  */
     38   1.1  jdolecek 
     39   1.1  jdolecek /*
     40   1.2  jdolecek  * Driver for NCR 53c90, MCA version, with 86c01 DMA controller chip.
     41   1.9     perry  *
     42   1.2  jdolecek  * Some of the information used to write this driver was taken
     43   1.2  jdolecek  * from Tymm Twillman <tymm (at) computer.org>'s Linux MCA NC53c90 driver,
     44   1.2  jdolecek  * in drivers/scsi/mca_53c9x.c
     45   1.1  jdolecek  */
     46   1.7     lukem 
     47   1.7     lukem #include <sys/cdefs.h>
     48  1.18   tsutsui __KERNEL_RCSID(0, "$NetBSD: esp_mca.c,v 1.18 2008/04/13 04:55:53 tsutsui Exp $");
     49   1.1  jdolecek 
     50   1.1  jdolecek #include <sys/types.h>
     51   1.1  jdolecek #include <sys/param.h>
     52   1.1  jdolecek #include <sys/systm.h>
     53   1.1  jdolecek #include <sys/kernel.h>
     54   1.1  jdolecek #include <sys/errno.h>
     55   1.1  jdolecek #include <sys/ioctl.h>
     56   1.1  jdolecek #include <sys/device.h>
     57   1.1  jdolecek #include <sys/buf.h>
     58   1.1  jdolecek #include <sys/proc.h>
     59   1.1  jdolecek #include <sys/user.h>
     60   1.1  jdolecek #include <sys/queue.h>
     61   1.1  jdolecek 
     62   1.1  jdolecek #include <dev/scsipi/scsi_all.h>
     63   1.1  jdolecek #include <dev/scsipi/scsipi_all.h>
     64   1.1  jdolecek #include <dev/scsipi/scsiconf.h>
     65   1.1  jdolecek #include <dev/scsipi/scsi_message.h>
     66   1.1  jdolecek 
     67  1.16        ad #include <sys/bus.h>
     68  1.16        ad #include <sys/cpu.h>
     69   1.1  jdolecek 
     70   1.1  jdolecek #include <dev/ic/ncr53c9xreg.h>
     71   1.1  jdolecek #include <dev/ic/ncr53c9xvar.h>
     72   1.1  jdolecek 
     73   1.1  jdolecek #include <dev/mca/espvar.h>
     74   1.2  jdolecek #include <dev/mca/espreg.h>
     75   1.1  jdolecek 
     76   1.1  jdolecek #include <dev/mca/mcavar.h>
     77   1.1  jdolecek #include <dev/mca/mcareg.h>
     78   1.1  jdolecek #include <dev/mca/mcadevs.h>
     79   1.1  jdolecek 
     80   1.2  jdolecek #if 0
     81   1.1  jdolecek #if defined(DEBUG) && !defined(NCR53C9X_DEBUG)
     82   1.1  jdolecek #define NCR53C9X_DEBUG
     83   1.1  jdolecek #endif
     84   1.2  jdolecek #endif
     85   1.1  jdolecek 
     86   1.1  jdolecek #ifdef NCR53C9X_DEBUG
     87   1.2  jdolecek static int esp_mca_debug = 0;
     88   1.1  jdolecek #define DPRINTF(x) if (esp_mca_debug) printf x;
     89   1.1  jdolecek #else
     90   1.1  jdolecek #define DPRINTF(x)
     91   1.1  jdolecek #endif
     92   1.1  jdolecek 
     93   1.1  jdolecek #define ESP_MCA_IOSIZE  0x20
     94   1.2  jdolecek #define ESP_REG_OFFSET	0x10
     95   1.1  jdolecek 
     96  1.18   tsutsui static int	esp_mca_match(device_t, cfdata_t, void *);
     97  1.18   tsutsui static void	esp_mca_attach(device_t, device_t, void *);
     98   1.1  jdolecek 
     99  1.18   tsutsui CFATTACH_DECL_NWE(esp_mca, sizeof(struct esp_softc),
    100   1.6   thorpej     esp_mca_match, esp_mca_attach, NULL, NULL);
    101   1.1  jdolecek 
    102   1.1  jdolecek /*
    103   1.1  jdolecek  * Functions and the switch for the MI code.
    104   1.1  jdolecek  */
    105  1.18   tsutsui static uint8_t	esp_read_reg(struct ncr53c9x_softc *, int);
    106  1.18   tsutsui static void	esp_write_reg(struct ncr53c9x_softc *, int, uint8_t);
    107   1.8     perry static int	esp_dma_isintr(struct ncr53c9x_softc *);
    108   1.8     perry static void	esp_dma_reset(struct ncr53c9x_softc *);
    109   1.8     perry static int	esp_dma_intr(struct ncr53c9x_softc *);
    110  1.18   tsutsui static int	esp_dma_setup(struct ncr53c9x_softc *, uint8_t **,
    111   1.8     perry 	    size_t *, int, size_t *);
    112   1.8     perry static void	esp_dma_go(struct ncr53c9x_softc *);
    113   1.8     perry static void	esp_dma_stop(struct ncr53c9x_softc *);
    114   1.8     perry static int	esp_dma_isactive(struct ncr53c9x_softc *);
    115   1.1  jdolecek 
    116   1.1  jdolecek static struct ncr53c9x_glue esp_glue = {
    117   1.1  jdolecek 	esp_read_reg,
    118   1.1  jdolecek 	esp_write_reg,
    119   1.1  jdolecek 	esp_dma_isintr,
    120   1.1  jdolecek 	esp_dma_reset,
    121   1.1  jdolecek 	esp_dma_intr,
    122   1.1  jdolecek 	esp_dma_setup,
    123   1.1  jdolecek 	esp_dma_go,
    124   1.1  jdolecek 	esp_dma_stop,
    125   1.1  jdolecek 	esp_dma_isactive,
    126   1.1  jdolecek 	NULL,			/* gl_clear_latched_intr */
    127   1.1  jdolecek };
    128   1.1  jdolecek 
    129   1.1  jdolecek static int
    130  1.18   tsutsui esp_mca_match(device_t parent, cfdata_t cf, void *aux)
    131   1.1  jdolecek {
    132   1.1  jdolecek 	struct mca_attach_args *ma = aux;
    133   1.1  jdolecek 
    134   1.1  jdolecek 	switch (ma->ma_id) {
    135   1.1  jdolecek 	case MCA_PRODUCT_NCR53C90:
    136   1.1  jdolecek 		return 1;
    137   1.1  jdolecek 	}
    138   1.1  jdolecek 
    139   1.1  jdolecek 	return 0;
    140   1.1  jdolecek }
    141   1.1  jdolecek 
    142   1.1  jdolecek static void
    143  1.18   tsutsui esp_mca_attach(device_t parent, device_t self, void *aux)
    144   1.1  jdolecek {
    145  1.12   thorpej 	struct esp_softc *esc = device_private(self);
    146   1.1  jdolecek 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    147  1.18   tsutsui 	struct mca_attach_args *ma = aux;
    148  1.18   tsutsui 	uint16_t iobase;
    149   1.2  jdolecek 	int scsi_id, irq, drq, error;
    150   1.1  jdolecek 	bus_space_handle_t ioh;
    151   1.1  jdolecek 	int pos2, pos3, pos5;
    152   1.1  jdolecek 
    153  1.18   tsutsui 	static const uint16_t ncrmca_iobase[] = {
    154   1.1  jdolecek 		0, 0x240, 0x340, 0x400, 0x420, 0x3240, 0x8240, 0xa240
    155   1.1  jdolecek 	};
    156   1.1  jdolecek 
    157  1.18   tsutsui 	sc->sc_dev = self;
    158  1.18   tsutsui 
    159   1.1  jdolecek 	/*
    160   1.1  jdolecek 	 * NCR SCSI Adapter (ADF 7f4f)
    161   1.1  jdolecek 	 *
    162   1.1  jdolecek 	 * POS register 2: (adf pos0)
    163   1.9     perry 	 *
    164   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    165   1.1  jdolecek 	 *     \_/ \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
    166   1.1  jdolecek 	 *      |      \____ I/O base (32B): 001=0x240 010=0x340 011=0x400
    167   1.1  jdolecek 	 *      |              100=0x420 101=0x3240 110=0x8240 111=0xa240
    168   1.1  jdolecek 	 *       \__________ IRQ: 00=3 01=5 10=7 11=9
    169   1.1  jdolecek 	 *
    170   1.1  jdolecek 	 * POS register 3: (adf pos1)
    171   1.9     perry 	 *
    172   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    173   1.1  jdolecek 	 * 1 1 1 | \_____/
    174   1.1  jdolecek 	 *       |       \__ DMA level
    175   1.1  jdolecek 	 *        \_________ Fairness: 1=enabled 0=disabled
    176   1.1  jdolecek 	 *
    177   1.1  jdolecek 	 * POS register 5: (adf pos3)
    178   1.9     perry 	 *
    179   1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    180   1.1  jdolecek 	 * 1   |     \___/
    181   1.1  jdolecek 	 *     |         \__ Static Ram: 0xC8000-0xC87FF + XX*0x4000
    182   1.1  jdolecek 	 *      \___________ Host Adapter ID: 1=7 0=6
    183   1.1  jdolecek 	 */
    184   1.1  jdolecek 
    185   1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    186   1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    187   1.1  jdolecek 	pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
    188   1.1  jdolecek 
    189   1.1  jdolecek 	iobase = ncrmca_iobase[(pos2 & 0x0e) >> 1];
    190  1.18   tsutsui 	irq = 3 + 2 * ((pos2 & 0x30) >> 4);
    191   1.1  jdolecek 	drq = (pos3 & 0x0f);
    192   1.1  jdolecek 	scsi_id = 6 + ((pos5 & 0x20) ? 1 : 0);
    193   1.1  jdolecek 
    194  1.18   tsutsui 	aprint_normal(" slot %d irq %d drq %d: NCR SCSI Adapter\n",
    195  1.18   tsutsui 	    ma->ma_slot + 1, irq, drq);
    196   1.1  jdolecek 
    197   1.2  jdolecek 	/* Map the 86C01 registers */
    198   1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, ESP_MCA_IOSIZE, 0, &ioh)) {
    199  1.17    cegger 		aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
    200   1.1  jdolecek 		return;
    201   1.1  jdolecek 	}
    202   1.1  jdolecek 
    203   1.1  jdolecek 	esc->sc_iot = ma->ma_iot;
    204   1.1  jdolecek 	esc->sc_ioh = ioh;
    205   1.1  jdolecek 
    206   1.2  jdolecek 	/* Submap the 'esp' registers */
    207   1.2  jdolecek 	if (bus_space_subregion(ma->ma_iot, ioh, ESP_REG_OFFSET,
    208   1.2  jdolecek 	    ESP_MCA_IOSIZE-ESP_REG_OFFSET, &esc->sc_esp_ioh)) {
    209  1.17    cegger 		aprint_error_dev(&sc->sc_dev, "can't subregion i/o space\n");
    210   1.2  jdolecek 		return;
    211   1.2  jdolecek 	}
    212   1.2  jdolecek 
    213   1.1  jdolecek 	/* Setup DMA map */
    214   1.1  jdolecek 	esc->sc_dmat = ma->ma_dmat;
    215   1.1  jdolecek 	if ((error = mca_dmamap_create(esc->sc_dmat, MAXPHYS,
    216   1.2  jdolecek             BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW | MCABUS_DMA_IOPORT,
    217   1.2  jdolecek 	    &esc->sc_xfer, drq)) != 0){
    218  1.18   tsutsui                 aprint_error_dev(&sc->sc_dev,
    219  1.18   tsutsui 		    "couldn't create DMA map - error %d\n", error);
    220   1.1  jdolecek                 return;
    221   1.1  jdolecek         }
    222   1.1  jdolecek 
    223   1.2  jdolecek 	/* MI code glue */
    224   1.1  jdolecek 	sc->sc_id = scsi_id;
    225  1.11     lukem 	sc->sc_freq = 25;		/* MHz */
    226   1.1  jdolecek 
    227   1.1  jdolecek 	sc->sc_glue = &esp_glue;
    228   1.1  jdolecek 
    229   1.2  jdolecek 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB; //| NCRCFG1_SLOW;
    230   1.2  jdolecek 	/* No point setting sc_cfg[2345], they won't be used */
    231   1.1  jdolecek 
    232   1.2  jdolecek 	sc->sc_rev = NCR_VARIANT_NCR53C90_86C01;
    233   1.1  jdolecek 	sc->sc_minsync = 0;
    234   1.1  jdolecek 
    235   1.1  jdolecek 	/* max 64KB DMA */
    236   1.1  jdolecek 	sc->sc_maxxfer = 64 * 1024;
    237   1.1  jdolecek 
    238   1.1  jdolecek 	/* Establish interrupt */
    239   1.1  jdolecek 	esc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_BIO, ncr53c9x_intr,
    240  1.18   tsutsui 	    esc);
    241   1.1  jdolecek 	if (esc->sc_ih == NULL) {
    242  1.17    cegger 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
    243   1.1  jdolecek 		return;
    244   1.1  jdolecek 	}
    245   1.1  jdolecek 
    246   1.1  jdolecek 	/*
    247   1.2  jdolecek 	 * Massage the 86C01 chip - setup MCA DMA controller for DMA via
    248   1.2  jdolecek 	 * the 86C01 register, and enable 86C01 interrupts.
    249   1.2  jdolecek 	 */
    250   1.2  jdolecek 	mca_dma_set_ioport(drq, iobase + N86C01_PIO);
    251   1.2  jdolecek 
    252   1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE,
    253  1.18   tsutsui 	    bus_space_read_1(esc->sc_iot, esc->sc_ioh, N86C01_MODE_ENABLE) |
    254  1.18   tsutsui 	    N86C01_INTR_ENABLE);
    255   1.2  jdolecek 
    256   1.2  jdolecek 	/*
    257   1.1  jdolecek 	 * Now try to attach all the sub-devices
    258   1.1  jdolecek 	 */
    259   1.1  jdolecek 	sc->sc_adapter.adapt_minphys = minphys;
    260   1.1  jdolecek 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    261   1.1  jdolecek 
    262   1.1  jdolecek 	/* Do the common parts of attachment. */
    263  1.18   tsutsui 	printf("%s", device_xname(self));
    264   1.1  jdolecek 	ncr53c9x_attach(sc);
    265   1.1  jdolecek }
    266   1.1  jdolecek 
    267   1.1  jdolecek /*
    268   1.1  jdolecek  * Glue functions.
    269   1.1  jdolecek  */
    270   1.1  jdolecek 
    271  1.18   tsutsui static uint8_t
    272  1.18   tsutsui esp_read_reg(struct ncr53c9x_softc *sc, int reg)
    273   1.1  jdolecek {
    274   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    275   1.1  jdolecek 
    276  1.18   tsutsui 	return bus_space_read_1(esc->sc_iot, esc->sc_esp_ioh, reg);
    277   1.1  jdolecek }
    278   1.1  jdolecek 
    279   1.1  jdolecek static void
    280  1.18   tsutsui esp_write_reg(struct ncr53c9x_softc *sc, int reg, uint8_t val)
    281   1.1  jdolecek {
    282   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    283   1.1  jdolecek 
    284   1.2  jdolecek 	bus_space_write_1(esc->sc_iot, esc->sc_esp_ioh, reg, val);
    285   1.1  jdolecek }
    286   1.1  jdolecek 
    287   1.1  jdolecek static int
    288  1.18   tsutsui esp_dma_isintr(struct ncr53c9x_softc *sc)
    289   1.1  jdolecek {
    290   1.2  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    291   1.2  jdolecek 
    292   1.1  jdolecek 	DPRINTF(("[esp_dma_isintr] "));
    293  1.18   tsutsui 	return bus_space_read_1(esc->sc_iot, esc->sc_ioh, N86C01_STATUS) &
    294  1.18   tsutsui 	    N86C01_IRQ_PEND;
    295   1.1  jdolecek }
    296   1.1  jdolecek 
    297   1.1  jdolecek static void
    298  1.18   tsutsui esp_dma_reset(struct ncr53c9x_softc *sc)
    299   1.1  jdolecek {
    300   1.1  jdolecek 	struct esp_softc *esc = (struct esp_softc *)sc;
    301   1.1  jdolecek 
    302   1.1  jdolecek 	DPRINTF(("[esp_dma_reset] "));
    303   1.1  jdolecek 
    304   1.1  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    305   1.1  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    306   1.1  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    307   1.1  jdolecek 	}
    308   1.2  jdolecek 
    309   1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_ACTIVE) {
    310   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    311   1.2  jdolecek 		mca_disk_unbusy();
    312   1.2  jdolecek 	}
    313   1.1  jdolecek }
    314   1.1  jdolecek 
    315   1.1  jdolecek static int
    316  1.18   tsutsui esp_dma_intr(struct ncr53c9x_softc *sc)
    317   1.1  jdolecek {
    318  1.18   tsutsui 	struct esp_softc *esc = (struct esp_softc *)sc;
    319  1.18   tsutsui 
    320   1.1  jdolecek 	DPRINTF(("[esp_dma_intr] "));
    321   1.1  jdolecek 
    322   1.1  jdolecek 	if ((esc->sc_flags & ESP_XFER_ACTIVE) == 0) {
    323  1.18   tsutsui 		printf("%s: dma_intr--inactive DMA\n",
    324  1.18   tsutsui 		    device_xname(sc->sc_dev));
    325  1.18   tsutsui 		return -1;
    326   1.1  jdolecek 	}
    327   1.1  jdolecek 
    328   1.2  jdolecek 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    329   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_ACTIVE;
    330   1.2  jdolecek 		mca_disk_unbusy();
    331  1.18   tsutsui 		return 0;
    332   1.2  jdolecek 	}
    333   1.2  jdolecek 
    334   1.2  jdolecek 	sc->sc_espstat |= NCRSTAT_TC;	/* XXX */
    335   1.2  jdolecek 
    336   1.2  jdolecek 	if ((sc->sc_espstat & NCRSTAT_TC) == 0) {
    337  1.18   tsutsui 		printf("%s: DMA not complete?\n", device_xname(sc->sc_dev));
    338  1.18   tsutsui 		return 1;
    339   1.2  jdolecek 	}
    340   1.2  jdolecek 
    341  1.18   tsutsui 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0, *esc->sc_xfer_len,
    342  1.18   tsutsui 	    (esc->sc_flags & ESP_XFER_READ) ?
    343  1.18   tsutsui 	    BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
    344   1.9     perry 
    345   1.2  jdolecek 	bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    346   1.2  jdolecek 	esc->sc_flags &= ~ESP_XFER_LOADED;
    347   1.1  jdolecek 
    348  1.18   tsutsui 	*esc->sc_xfer_addr += *esc->sc_xfer_len;
    349   1.2  jdolecek 	*esc->sc_xfer_len = 0;
    350   1.1  jdolecek 
    351   1.1  jdolecek 	esc->sc_flags &= ~ESP_XFER_ACTIVE;
    352   1.2  jdolecek 	mca_disk_unbusy();
    353   1.2  jdolecek 
    354  1.18   tsutsui 	return 0;
    355   1.1  jdolecek }
    356   1.1  jdolecek 
    357   1.1  jdolecek /*
    358   1.1  jdolecek  * Setup DMA transfer.
    359   1.1  jdolecek  */
    360   1.1  jdolecek static int
    361  1.18   tsutsui esp_dma_setup(struct ncr53c9x_softc *sc, uint8_t **addr, size_t *len,
    362  1.18   tsutsui     int datain, size_t *dmasize)
    363   1.1  jdolecek {
    364  1.18   tsutsui 	struct esp_softc *esc = (struct esp_softc *)sc;
    365   1.1  jdolecek 	int error;
    366   1.1  jdolecek 	int fl;
    367   1.1  jdolecek 
    368   1.1  jdolecek 	DPRINTF(("[esp_dma_setup] "));
    369   1.1  jdolecek 
    370   1.2  jdolecek 	if (esc->sc_flags & ESP_XFER_LOADED) {
    371  1.18   tsutsui 		printf("%s: %s: unloading leaked xfer\n",
    372  1.18   tsutsui 		    device_xname(sc->sc_dev), __func__);
    373   1.2  jdolecek 		bus_dmamap_unload(esc->sc_dmat, esc->sc_xfer);
    374   1.2  jdolecek 		esc->sc_flags &= ~ESP_XFER_LOADED;
    375   1.2  jdolecek 	}
    376   1.2  jdolecek 
    377   1.1  jdolecek 	/* Load the buffer for DMA transfer. */
    378   1.1  jdolecek 	fl = (datain) ? BUS_DMA_READ : BUS_DMA_WRITE;
    379   1.1  jdolecek 
    380   1.1  jdolecek 	if ((error = bus_dmamap_load(esc->sc_dmat, esc->sc_xfer, *addr,
    381   1.1  jdolecek 	    *len, NULL, BUS_DMA_STREAMING|fl))) {
    382  1.18   tsutsui 		printf("%s: %s: unable to load DMA buffer - error %d\n",
    383  1.18   tsutsui 		    device_xname(sc->sc_dev), __func__, error);
    384  1.18   tsutsui 		return error;
    385   1.1  jdolecek 	}
    386   1.1  jdolecek 
    387  1.18   tsutsui 	bus_dmamap_sync(esc->sc_dmat, esc->sc_xfer, 0, *len,
    388  1.18   tsutsui 	    (datain) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
    389   1.9     perry 
    390   1.2  jdolecek 	esc->sc_flags |= ESP_XFER_LOADED | (datain ? ESP_XFER_READ : 0);
    391   1.2  jdolecek 	esc->sc_xfer_addr = addr;
    392   1.2  jdolecek 	esc->sc_xfer_len  = len;
    393   1.1  jdolecek 
    394  1.18   tsutsui 	return 0;
    395   1.1  jdolecek }
    396   1.1  jdolecek 
    397   1.1  jdolecek static void
    398  1.18   tsutsui esp_dma_go(struct ncr53c9x_softc *sc)
    399   1.1  jdolecek {
    400  1.18   tsutsui 	struct esp_softc *esc = (struct esp_softc *)sc;
    401   1.1  jdolecek 	DPRINTF(("[esp_dma_go] "));
    402   1.1  jdolecek 
    403   1.1  jdolecek 	esc->sc_flags |= ESP_XFER_ACTIVE;
    404   1.2  jdolecek 	mca_disk_busy();
    405   1.1  jdolecek }
    406   1.1  jdolecek 
    407   1.1  jdolecek static void
    408  1.18   tsutsui esp_dma_stop(struct ncr53c9x_softc *sc)
    409   1.1  jdolecek {
    410  1.18   tsutsui 
    411   1.1  jdolecek 	DPRINTF(("[esp_dma_stop] "));
    412   1.1  jdolecek 
    413  1.18   tsutsui 	panic("%s: stop not yet implemented", device_xname(sc->sc_dev));
    414   1.1  jdolecek }
    415   1.1  jdolecek 
    416   1.1  jdolecek static int
    417  1.18   tsutsui esp_dma_isactive(struct ncr53c9x_softc *sc)
    418   1.1  jdolecek {
    419  1.18   tsutsui 	struct esp_softc *esc = (struct esp_softc *)sc;
    420   1.1  jdolecek 	DPRINTF(("[esp_dma_isactive] "));
    421   1.1  jdolecek 
    422  1.18   tsutsui 	return esc->sc_flags & ESP_XFER_ACTIVE;
    423   1.1  jdolecek }
    424