Home | History | Annotate | Line # | Download | only in sbus
esp_sbus.c revision 1.9
      1  1.9      cgd /*	$NetBSD: esp_sbus.c,v 1.9 2000/06/04 19:15:13 cgd Exp $	*/
      2  1.1       pk 
      3  1.1       pk /*-
      4  1.1       pk  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  1.1       pk  * All rights reserved.
      6  1.1       pk  *
      7  1.1       pk  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1       pk  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9  1.1       pk  * Simulation Facility, NASA Ames Research Center; Paul Kranenburg.
     10  1.1       pk  *
     11  1.1       pk  * Redistribution and use in source and binary forms, with or without
     12  1.1       pk  * modification, are permitted provided that the following conditions
     13  1.1       pk  * are met:
     14  1.1       pk  * 1. Redistributions of source code must retain the above copyright
     15  1.1       pk  *    notice, this list of conditions and the following disclaimer.
     16  1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     18  1.1       pk  *    documentation and/or other materials provided with the distribution.
     19  1.1       pk  * 3. All advertising materials mentioning features or use of this software
     20  1.1       pk  *    must display the following acknowledgement:
     21  1.1       pk  *	This product includes software developed by the NetBSD
     22  1.1       pk  *	Foundation, Inc. and its contributors.
     23  1.1       pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1       pk  *    contributors may be used to endorse or promote products derived
     25  1.1       pk  *    from this software without specific prior written permission.
     26  1.1       pk  *
     27  1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1       pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1       pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1       pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1       pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1       pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1       pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1       pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1       pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1       pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1       pk  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1       pk  */
     39  1.1       pk 
     40  1.1       pk #include <sys/types.h>
     41  1.1       pk #include <sys/param.h>
     42  1.1       pk #include <sys/systm.h>
     43  1.1       pk #include <sys/kernel.h>
     44  1.1       pk #include <sys/errno.h>
     45  1.1       pk #include <sys/device.h>
     46  1.1       pk #include <sys/buf.h>
     47  1.1       pk 
     48  1.1       pk #include <dev/scsipi/scsi_all.h>
     49  1.1       pk #include <dev/scsipi/scsipi_all.h>
     50  1.1       pk #include <dev/scsipi/scsiconf.h>
     51  1.1       pk #include <dev/scsipi/scsi_message.h>
     52  1.1       pk 
     53  1.1       pk #include <machine/bus.h>
     54  1.1       pk #include <machine/autoconf.h>
     55  1.1       pk #include <machine/cpu.h>
     56  1.1       pk 
     57  1.1       pk #include <dev/ic/lsi64854reg.h>
     58  1.1       pk #include <dev/ic/lsi64854var.h>
     59  1.1       pk 
     60  1.1       pk #include <dev/ic/ncr53c9xreg.h>
     61  1.1       pk #include <dev/ic/ncr53c9xvar.h>
     62  1.1       pk 
     63  1.1       pk #include <dev/sbus/sbusvar.h>
     64  1.1       pk 
     65  1.1       pk struct esp_softc {
     66  1.1       pk 	struct ncr53c9x_softc sc_ncr53c9x;	/* glue to MI code */
     67  1.1       pk 	struct sbusdev	sc_sd;			/* sbus device */
     68  1.1       pk 
     69  1.1       pk 	bus_space_tag_t	sc_bustag;
     70  1.1       pk 	bus_dma_tag_t	sc_dmatag;
     71  1.1       pk 
     72  1.1       pk 	bus_space_handle_t sc_reg;		/* the registers */
     73  1.1       pk 	struct lsi64854_softc *sc_dma;		/* pointer to my dma */
     74  1.1       pk 
     75  1.1       pk 	int	sc_pri;				/* SBUS priority */
     76  1.1       pk };
     77  1.1       pk 
     78  1.1       pk void	espattach_sbus	__P((struct device *, struct device *, void *));
     79  1.1       pk void	espattach_dma	__P((struct device *, struct device *, void *));
     80  1.1       pk int	espmatch_sbus	__P((struct device *, struct cfdata *, void *));
     81  1.1       pk 
     82  1.1       pk 
     83  1.1       pk /* Linkup to the rest of the kernel */
     84  1.1       pk struct cfattach esp_sbus_ca = {
     85  1.1       pk 	sizeof(struct esp_softc), espmatch_sbus, espattach_sbus
     86  1.1       pk };
     87  1.1       pk struct cfattach esp_dma_ca = {
     88  1.1       pk 	sizeof(struct esp_softc), espmatch_sbus, espattach_dma
     89  1.1       pk };
     90  1.1       pk 
     91  1.1       pk static struct scsipi_device esp_sbus_dev = {
     92  1.1       pk 	NULL,			/* Use default error handler */
     93  1.1       pk 	NULL,			/* have a queue, served by this */
     94  1.1       pk 	NULL,			/* have no async handler */
     95  1.1       pk 	NULL,			/* Use default 'done' routine */
     96  1.1       pk };
     97  1.1       pk 
     98  1.1       pk /*
     99  1.1       pk  * Functions and the switch for the MI code.
    100  1.1       pk  */
    101  1.1       pk static u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    102  1.1       pk static void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    103  1.6   mjacob static u_char	esp_rdreg1 __P((struct ncr53c9x_softc *, int));
    104  1.6   mjacob static void	esp_wrreg1 __P((struct ncr53c9x_softc *, int, u_char));
    105  1.1       pk static int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    106  1.1       pk static void	esp_dma_reset __P((struct ncr53c9x_softc *));
    107  1.1       pk static int	esp_dma_intr __P((struct ncr53c9x_softc *));
    108  1.1       pk static int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    109  1.1       pk 				    size_t *, int, size_t *));
    110  1.1       pk static void	esp_dma_go __P((struct ncr53c9x_softc *));
    111  1.1       pk static void	esp_dma_stop __P((struct ncr53c9x_softc *));
    112  1.1       pk static int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    113  1.1       pk 
    114  1.1       pk static struct ncr53c9x_glue esp_sbus_glue = {
    115  1.1       pk 	esp_read_reg,
    116  1.1       pk 	esp_write_reg,
    117  1.1       pk 	esp_dma_isintr,
    118  1.1       pk 	esp_dma_reset,
    119  1.1       pk 	esp_dma_intr,
    120  1.1       pk 	esp_dma_setup,
    121  1.1       pk 	esp_dma_go,
    122  1.1       pk 	esp_dma_stop,
    123  1.1       pk 	esp_dma_isactive,
    124  1.1       pk 	NULL,			/* gl_clear_latched_intr */
    125  1.1       pk };
    126  1.1       pk 
    127  1.6   mjacob static struct ncr53c9x_glue esp_sbus_glue1 = {
    128  1.6   mjacob 	esp_rdreg1,
    129  1.6   mjacob 	esp_wrreg1,
    130  1.6   mjacob 	esp_dma_isintr,
    131  1.6   mjacob 	esp_dma_reset,
    132  1.6   mjacob 	esp_dma_intr,
    133  1.6   mjacob 	esp_dma_setup,
    134  1.6   mjacob 	esp_dma_go,
    135  1.6   mjacob 	esp_dma_stop,
    136  1.6   mjacob 	esp_dma_isactive,
    137  1.6   mjacob 	NULL,			/* gl_clear_latched_intr */
    138  1.6   mjacob };
    139  1.6   mjacob 
    140  1.6   mjacob static void	espattach __P((struct esp_softc *, struct ncr53c9x_glue *));
    141  1.6   mjacob 
    142  1.1       pk int
    143  1.1       pk espmatch_sbus(parent, cf, aux)
    144  1.1       pk 	struct device *parent;
    145  1.1       pk 	struct cfdata *cf;
    146  1.1       pk 	void *aux;
    147  1.1       pk {
    148  1.6   mjacob 	int rv;
    149  1.1       pk 	struct sbus_attach_args *sa = aux;
    150  1.1       pk 
    151  1.6   mjacob 	rv = (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0 ||
    152  1.6   mjacob 	    strcmp("ptscII", sa->sa_name) == 0);
    153  1.6   mjacob 	return (rv);
    154  1.1       pk }
    155  1.1       pk 
    156  1.1       pk void
    157  1.1       pk espattach_sbus(parent, self, aux)
    158  1.1       pk 	struct device *parent, *self;
    159  1.1       pk 	void *aux;
    160  1.1       pk {
    161  1.1       pk 	struct esp_softc *esc = (void *)self;
    162  1.1       pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    163  1.1       pk 	struct sbus_attach_args *sa = aux;
    164  1.1       pk 
    165  1.1       pk 	esc->sc_bustag = sa->sa_bustag;
    166  1.1       pk 	esc->sc_dmatag = sa->sa_dmatag;
    167  1.1       pk 
    168  1.1       pk 	sc->sc_id = getpropint(sa->sa_node, "initiator-id", 7);
    169  1.1       pk 	sc->sc_freq = getpropint(sa->sa_node, "clock-frequency", -1);
    170  1.1       pk 	if (sc->sc_freq < 0)
    171  1.1       pk 		sc->sc_freq = ((struct sbus_softc *)
    172  1.1       pk 		    sc->sc_dev.dv_parent)->sc_clockfreq;
    173  1.1       pk 
    174  1.1       pk 	/*
    175  1.1       pk 	 * Find the DMA by poking around the dma device structures
    176  1.1       pk 	 *
    177  1.1       pk 	 * What happens here is that if the dma driver has not been
    178  1.1       pk 	 * configured, then this returns a NULL pointer. Then when the
    179  1.1       pk 	 * dma actually gets configured, it does the opposing test, and
    180  1.1       pk 	 * if the sc->sc_esp field in it's softc is NULL, then tries to
    181  1.1       pk 	 * find the matching esp driver.
    182  1.1       pk 	 */
    183  1.1       pk 	esc->sc_dma = (struct lsi64854_softc *)
    184  1.1       pk 				getdevunit("dma", sc->sc_dev.dv_unit);
    185  1.1       pk 
    186  1.1       pk 	/*
    187  1.1       pk 	 * and a back pointer to us, for DMA
    188  1.1       pk 	 */
    189  1.1       pk 	if (esc->sc_dma)
    190  1.2       pk 		esc->sc_dma->sc_client = sc;
    191  1.1       pk 	else {
    192  1.1       pk 		printf("\n");
    193  1.1       pk 		panic("espattach: no dma found");
    194  1.1       pk 	}
    195  1.1       pk 
    196  1.1       pk 	/*
    197  1.1       pk 	 * Map my registers in, if they aren't already in virtual
    198  1.1       pk 	 * address space.
    199  1.1       pk 	 */
    200  1.1       pk 	if (sa->sa_npromvaddrs)
    201  1.1       pk 		esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
    202  1.1       pk 	else {
    203  1.1       pk 		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    204  1.1       pk 				 sa->sa_offset,
    205  1.1       pk 				 sa->sa_size,
    206  1.1       pk 				 BUS_SPACE_MAP_LINEAR,
    207  1.2       pk 				 0, &esc->sc_reg) != 0) {
    208  1.1       pk 			printf("%s @ sbus: cannot map registers\n",
    209  1.1       pk 				self->dv_xname);
    210  1.1       pk 			return;
    211  1.1       pk 		}
    212  1.1       pk 	}
    213  1.1       pk 
    214  1.7       pk 	if (sa->sa_nintr == 0) {
    215  1.7       pk 		/*
    216  1.7       pk 		 * No interrupt properties: we quit; this might
    217  1.7       pk 		 * happen on e.g. a Sparc X terminal.
    218  1.7       pk 		 */
    219  1.7       pk 		printf("\n%s: no interrupt property\n", self->dv_xname);
    220  1.7       pk 		return;
    221  1.7       pk 	}
    222  1.7       pk 
    223  1.1       pk 	esc->sc_pri = sa->sa_pri;
    224  1.1       pk 
    225  1.1       pk 	/* add me to the sbus structures */
    226  1.1       pk 	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
    227  1.1       pk 	sbus_establish(&esc->sc_sd, &sc->sc_dev);
    228  1.1       pk 
    229  1.6   mjacob 	if (strcmp("ptscII", sa->sa_name) == 0) {
    230  1.6   mjacob 		espattach(esc, &esp_sbus_glue1);
    231  1.6   mjacob 	} else {
    232  1.6   mjacob 		espattach(esc, &esp_sbus_glue);
    233  1.6   mjacob 	}
    234  1.1       pk }
    235  1.1       pk 
    236  1.1       pk void
    237  1.1       pk espattach_dma(parent, self, aux)
    238  1.1       pk 	struct device *parent, *self;
    239  1.1       pk 	void *aux;
    240  1.1       pk {
    241  1.1       pk 	struct esp_softc *esc = (void *)self;
    242  1.1       pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    243  1.1       pk 	struct sbus_attach_args *sa = aux;
    244  1.1       pk 
    245  1.6   mjacob 	if (strcmp("ptscII", sa->sa_name) == 0) {
    246  1.6   mjacob 		return;
    247  1.6   mjacob 	}
    248  1.6   mjacob 
    249  1.1       pk 	esc->sc_bustag = sa->sa_bustag;
    250  1.1       pk 	esc->sc_dmatag = sa->sa_dmatag;
    251  1.1       pk 
    252  1.1       pk 	sc->sc_id = getpropint(sa->sa_node, "initiator-id", 7);
    253  1.1       pk 	sc->sc_freq = getpropint(sa->sa_node, "clock-frequency", -1);
    254  1.1       pk 
    255  1.1       pk 	esc->sc_dma = (struct lsi64854_softc *)parent;
    256  1.2       pk 	esc->sc_dma->sc_client = sc;
    257  1.1       pk 
    258  1.1       pk 	/*
    259  1.1       pk 	 * Map my registers in, if they aren't already in virtual
    260  1.1       pk 	 * address space.
    261  1.1       pk 	 */
    262  1.1       pk 	if (sa->sa_npromvaddrs)
    263  1.1       pk 		esc->sc_reg = (bus_space_handle_t)sa->sa_promvaddrs[0];
    264  1.1       pk 	else {
    265  1.1       pk 		if (bus_space_map2(sa->sa_bustag,
    266  1.1       pk 				   sa->sa_slot,
    267  1.1       pk 				   sa->sa_offset,
    268  1.1       pk 				   sa->sa_size,
    269  1.1       pk 				   BUS_SPACE_MAP_LINEAR,
    270  1.2       pk 				   0, &esc->sc_reg) != 0) {
    271  1.1       pk 			printf("%s @ dma: cannot map registers\n",
    272  1.1       pk 				self->dv_xname);
    273  1.1       pk 			return;
    274  1.1       pk 		}
    275  1.1       pk 	}
    276  1.1       pk 
    277  1.7       pk 	if (sa->sa_nintr == 0) {
    278  1.7       pk 		/*
    279  1.7       pk 		 * No interrupt properties: we quit; this might
    280  1.7       pk 		 * happen on e.g. a Sparc X terminal.
    281  1.7       pk 		 */
    282  1.7       pk 		printf("\n%s: no interrupt property\n", self->dv_xname);
    283  1.7       pk 		return;
    284  1.7       pk 	}
    285  1.7       pk 
    286  1.1       pk 	esc->sc_pri = sa->sa_pri;
    287  1.1       pk 
    288  1.1       pk 	/* Assume SBus is grandparent */
    289  1.1       pk 	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
    290  1.1       pk 	sbus_establish(&esc->sc_sd, parent);
    291  1.1       pk 
    292  1.6   mjacob 	espattach(esc, &esp_sbus_glue);
    293  1.1       pk }
    294  1.1       pk 
    295  1.1       pk 
    296  1.1       pk /*
    297  1.1       pk  * Attach this instance, and then all the sub-devices
    298  1.1       pk  */
    299  1.1       pk void
    300  1.6   mjacob espattach(esc, gluep)
    301  1.1       pk 	struct esp_softc *esc;
    302  1.6   mjacob 	struct ncr53c9x_glue *gluep;
    303  1.1       pk {
    304  1.1       pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    305  1.1       pk 	void *icookie;
    306  1.1       pk 
    307  1.1       pk 	/*
    308  1.1       pk 	 * Set up glue for MI code early; we use some of it here.
    309  1.1       pk 	 */
    310  1.6   mjacob 	sc->sc_glue = gluep;
    311  1.1       pk 
    312  1.1       pk 	/* gimme Mhz */
    313  1.1       pk 	sc->sc_freq /= 1000000;
    314  1.1       pk 
    315  1.1       pk 	/*
    316  1.1       pk 	 * XXX More of this should be in ncr53c9x_attach(), but
    317  1.1       pk 	 * XXX should we really poke around the chip that much in
    318  1.1       pk 	 * XXX the MI code?  Think about this more...
    319  1.1       pk 	 */
    320  1.1       pk 
    321  1.1       pk 	/*
    322  1.1       pk 	 * It is necessary to try to load the 2nd config register here,
    323  1.1       pk 	 * to find out what rev the esp chip is, else the ncr53c9x_reset
    324  1.1       pk 	 * will not set up the defaults correctly.
    325  1.1       pk 	 */
    326  1.1       pk 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
    327  1.1       pk 	sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_RPE;
    328  1.1       pk 	sc->sc_cfg3 = NCRCFG3_CDB;
    329  1.1       pk 	NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
    330  1.1       pk 
    331  1.1       pk 	if ((NCR_READ_REG(sc, NCR_CFG2) & ~NCRCFG2_RSVD) !=
    332  1.1       pk 	    (NCRCFG2_SCSI2 | NCRCFG2_RPE)) {
    333  1.1       pk 		sc->sc_rev = NCR_VARIANT_ESP100;
    334  1.1       pk 	} else {
    335  1.1       pk 		sc->sc_cfg2 = NCRCFG2_SCSI2;
    336  1.1       pk 		NCR_WRITE_REG(sc, NCR_CFG2, sc->sc_cfg2);
    337  1.1       pk 		sc->sc_cfg3 = 0;
    338  1.1       pk 		NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    339  1.1       pk 		sc->sc_cfg3 = (NCRCFG3_CDB | NCRCFG3_FCLK);
    340  1.1       pk 		NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    341  1.1       pk 		if (NCR_READ_REG(sc, NCR_CFG3) !=
    342  1.1       pk 		    (NCRCFG3_CDB | NCRCFG3_FCLK)) {
    343  1.1       pk 			sc->sc_rev = NCR_VARIANT_ESP100A;
    344  1.1       pk 		} else {
    345  1.1       pk 			/* NCRCFG2_FE enables > 64K transfers */
    346  1.1       pk 			sc->sc_cfg2 |= NCRCFG2_FE;
    347  1.1       pk 			sc->sc_cfg3 = 0;
    348  1.1       pk 			NCR_WRITE_REG(sc, NCR_CFG3, sc->sc_cfg3);
    349  1.1       pk 			sc->sc_rev = NCR_VARIANT_ESP200;
    350  1.1       pk 		}
    351  1.1       pk 	}
    352  1.1       pk 
    353  1.1       pk 	/*
    354  1.1       pk 	 * XXX minsync and maxxfer _should_ be set up in MI code,
    355  1.1       pk 	 * XXX but it appears to have some dependency on what sort
    356  1.1       pk 	 * XXX of DMA we're hooked up to, etc.
    357  1.1       pk 	 */
    358  1.1       pk 
    359  1.1       pk 	/*
    360  1.1       pk 	 * This is the value used to start sync negotiations
    361  1.1       pk 	 * Note that the NCR register "SYNCTP" is programmed
    362  1.1       pk 	 * in "clocks per byte", and has a minimum value of 4.
    363  1.1       pk 	 * The SCSI period used in negotiation is one-fourth
    364  1.1       pk 	 * of the time (in nanoseconds) needed to transfer one byte.
    365  1.1       pk 	 * Since the chip's clock is given in MHz, we have the following
    366  1.1       pk 	 * formula: 4 * period = (1000 / freq) * 4
    367  1.1       pk 	 */
    368  1.1       pk 	sc->sc_minsync = 1000 / sc->sc_freq;
    369  1.1       pk 
    370  1.1       pk 	/*
    371  1.1       pk 	 * Alas, we must now modify the value a bit, because it's
    372  1.1       pk 	 * only valid when can switch on FASTCLK and FASTSCSI bits
    373  1.1       pk 	 * in config register 3...
    374  1.1       pk 	 */
    375  1.1       pk 	switch (sc->sc_rev) {
    376  1.1       pk 	case NCR_VARIANT_ESP100:
    377  1.1       pk 		sc->sc_maxxfer = 64 * 1024;
    378  1.1       pk 		sc->sc_minsync = 0;	/* No synch on old chip? */
    379  1.1       pk 		break;
    380  1.1       pk 
    381  1.1       pk 	case NCR_VARIANT_ESP100A:
    382  1.1       pk 		sc->sc_maxxfer = 64 * 1024;
    383  1.1       pk 		/* Min clocks/byte is 5 */
    384  1.1       pk 		sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5);
    385  1.1       pk 		break;
    386  1.1       pk 
    387  1.1       pk 	case NCR_VARIANT_ESP200:
    388  1.1       pk 		sc->sc_maxxfer = 16 * 1024 * 1024;
    389  1.1       pk 		/* XXX - do actually set FAST* bits */
    390  1.1       pk 		break;
    391  1.1       pk 	}
    392  1.1       pk 
    393  1.1       pk 	/* Establish interrupt channel */
    394  1.1       pk 	icookie = bus_intr_establish(esc->sc_bustag,
    395  1.1       pk 				     esc->sc_pri, 0,
    396  1.1       pk 				     (int(*)__P((void*)))ncr53c9x_intr, sc);
    397  1.1       pk 
    398  1.1       pk 	/* register interrupt stats */
    399  1.9      cgd 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    400  1.9      cgd 	    sc->sc_dev.dv_xname, "intr");
    401  1.1       pk 
    402  1.1       pk 	/* Do the common parts of attachment. */
    403  1.5  thorpej 	sc->sc_adapter.scsipi_cmd = ncr53c9x_scsi_cmd;
    404  1.5  thorpej 	sc->sc_adapter.scsipi_minphys = minphys;
    405  1.5  thorpej 	ncr53c9x_attach(sc, &esp_sbus_dev);
    406  1.1       pk 
    407  1.1       pk 	/* Turn on target selection using the `dma' method */
    408  1.1       pk 	ncr53c9x_dmaselect = 1;
    409  1.1       pk }
    410  1.1       pk 
    411  1.1       pk /*
    412  1.1       pk  * Glue functions.
    413  1.1       pk  */
    414  1.1       pk 
    415  1.1       pk u_char
    416  1.1       pk esp_read_reg(sc, reg)
    417  1.1       pk 	struct ncr53c9x_softc *sc;
    418  1.1       pk 	int reg;
    419  1.1       pk {
    420  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    421  1.1       pk 
    422  1.1       pk 	return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg * 4));
    423  1.1       pk }
    424  1.1       pk 
    425  1.1       pk void
    426  1.1       pk esp_write_reg(sc, reg, v)
    427  1.1       pk 	struct ncr53c9x_softc *sc;
    428  1.1       pk 	int reg;
    429  1.1       pk 	u_char v;
    430  1.1       pk {
    431  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    432  1.1       pk 
    433  1.1       pk 	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg * 4, v);
    434  1.6   mjacob }
    435  1.6   mjacob 
    436  1.6   mjacob u_char
    437  1.6   mjacob esp_rdreg1(sc, reg)
    438  1.6   mjacob 	struct ncr53c9x_softc *sc;
    439  1.6   mjacob 	int reg;
    440  1.6   mjacob {
    441  1.6   mjacob 	struct esp_softc *esc = (struct esp_softc *)sc;
    442  1.6   mjacob 
    443  1.6   mjacob 	return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg));
    444  1.6   mjacob }
    445  1.6   mjacob 
    446  1.6   mjacob void
    447  1.6   mjacob esp_wrreg1(sc, reg, v)
    448  1.6   mjacob 	struct ncr53c9x_softc *sc;
    449  1.6   mjacob 	int reg;
    450  1.6   mjacob 	u_char v;
    451  1.6   mjacob {
    452  1.6   mjacob 	struct esp_softc *esc = (struct esp_softc *)sc;
    453  1.6   mjacob 
    454  1.6   mjacob 	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg, v);
    455  1.1       pk }
    456  1.1       pk 
    457  1.1       pk int
    458  1.1       pk esp_dma_isintr(sc)
    459  1.1       pk 	struct ncr53c9x_softc *sc;
    460  1.1       pk {
    461  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    462  1.1       pk 
    463  1.1       pk 	return (DMA_ISINTR(esc->sc_dma));
    464  1.1       pk }
    465  1.1       pk 
    466  1.1       pk void
    467  1.1       pk esp_dma_reset(sc)
    468  1.1       pk 	struct ncr53c9x_softc *sc;
    469  1.1       pk {
    470  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    471  1.1       pk 
    472  1.1       pk 	DMA_RESET(esc->sc_dma);
    473  1.1       pk }
    474  1.1       pk 
    475  1.1       pk int
    476  1.1       pk esp_dma_intr(sc)
    477  1.1       pk 	struct ncr53c9x_softc *sc;
    478  1.1       pk {
    479  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    480  1.1       pk 
    481  1.1       pk 	return (DMA_INTR(esc->sc_dma));
    482  1.1       pk }
    483  1.1       pk 
    484  1.1       pk int
    485  1.1       pk esp_dma_setup(sc, addr, len, datain, dmasize)
    486  1.1       pk 	struct ncr53c9x_softc *sc;
    487  1.1       pk 	caddr_t *addr;
    488  1.1       pk 	size_t *len;
    489  1.1       pk 	int datain;
    490  1.1       pk 	size_t *dmasize;
    491  1.1       pk {
    492  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    493  1.1       pk 
    494  1.1       pk 	return (DMA_SETUP(esc->sc_dma, addr, len, datain, dmasize));
    495  1.1       pk }
    496  1.1       pk 
    497  1.1       pk void
    498  1.1       pk esp_dma_go(sc)
    499  1.1       pk 	struct ncr53c9x_softc *sc;
    500  1.1       pk {
    501  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    502  1.1       pk 
    503  1.1       pk 	DMA_GO(esc->sc_dma);
    504  1.1       pk }
    505  1.1       pk 
    506  1.1       pk void
    507  1.1       pk esp_dma_stop(sc)
    508  1.1       pk 	struct ncr53c9x_softc *sc;
    509  1.1       pk {
    510  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    511  1.1       pk 	u_int32_t csr;
    512  1.1       pk 
    513  1.1       pk 	csr = L64854_GCSR(esc->sc_dma);
    514  1.1       pk 	csr &= ~D_EN_DMA;
    515  1.1       pk 	L64854_SCSR(esc->sc_dma, csr);
    516  1.1       pk }
    517  1.1       pk 
    518  1.1       pk int
    519  1.1       pk esp_dma_isactive(sc)
    520  1.1       pk 	struct ncr53c9x_softc *sc;
    521  1.1       pk {
    522  1.1       pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    523  1.1       pk 
    524  1.1       pk 	return (DMA_ISACTIVE(esc->sc_dma));
    525  1.1       pk }
    526