Home | History | Annotate | Line # | Download | only in vsa
asc_vsbus.c revision 1.21.2.3
      1  1.21.2.3  bouyer /*	$NetBSD: asc_vsbus.c,v 1.21.2.3 2000/11/22 16:02:16 bouyer Exp $	*/
      2  1.21.2.2  bouyer 
      3  1.21.2.2  bouyer /*-
      4  1.21.2.2  bouyer  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.21.2.2  bouyer  * All rights reserved.
      6  1.21.2.2  bouyer  *
      7  1.21.2.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.21.2.2  bouyer  * by Charles M. Hannum.
      9  1.21.2.2  bouyer  *
     10  1.21.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     11  1.21.2.2  bouyer  * modification, are permitted provided that the following conditions
     12  1.21.2.2  bouyer  * are met:
     13  1.21.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     14  1.21.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     15  1.21.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.21.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     17  1.21.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     18  1.21.2.2  bouyer  * 3. All advertising materials mentioning features or use of this software
     19  1.21.2.2  bouyer  *    must display the following acknowledgement:
     20  1.21.2.2  bouyer  *	  This product includes software developed by the NetBSD
     21  1.21.2.2  bouyer  *	  Foundation, Inc. and its contributors.
     22  1.21.2.2  bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.21.2.2  bouyer  *    contributors may be used to endorse or promote products derived
     24  1.21.2.2  bouyer  *    from this software without specific prior written permission.
     25  1.21.2.2  bouyer  *
     26  1.21.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.21.2.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.21.2.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.21.2.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.21.2.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.21.2.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.21.2.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.21.2.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.21.2.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.21.2.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.21.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     37  1.21.2.2  bouyer  */
     38  1.21.2.2  bouyer 
     39  1.21.2.2  bouyer #include "opt_cputype.h"
     40  1.21.2.2  bouyer 
     41  1.21.2.2  bouyer #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     42  1.21.2.2  bouyer 
     43  1.21.2.3  bouyer __KERNEL_RCSID(0, "$NetBSD: asc_vsbus.c,v 1.21.2.3 2000/11/22 16:02:16 bouyer Exp $");
     44  1.21.2.2  bouyer 
     45  1.21.2.2  bouyer #include <sys/types.h>
     46  1.21.2.2  bouyer #include <sys/param.h>
     47  1.21.2.2  bouyer #include <sys/systm.h>
     48  1.21.2.2  bouyer #include <sys/kernel.h>
     49  1.21.2.2  bouyer #include <sys/errno.h>
     50  1.21.2.2  bouyer #include <sys/ioctl.h>
     51  1.21.2.2  bouyer #include <sys/device.h>
     52  1.21.2.2  bouyer #include <sys/buf.h>
     53  1.21.2.2  bouyer #include <sys/proc.h>
     54  1.21.2.2  bouyer #include <sys/user.h>
     55  1.21.2.2  bouyer #include <sys/reboot.h>
     56  1.21.2.2  bouyer #include <sys/queue.h>
     57  1.21.2.2  bouyer 
     58  1.21.2.2  bouyer #include <dev/scsipi/scsi_all.h>
     59  1.21.2.2  bouyer #include <dev/scsipi/scsipi_all.h>
     60  1.21.2.2  bouyer #include <dev/scsipi/scsiconf.h>
     61  1.21.2.2  bouyer #include <dev/scsipi/scsi_message.h>
     62  1.21.2.2  bouyer 
     63  1.21.2.2  bouyer #include <machine/bus.h>
     64  1.21.2.2  bouyer #include <machine/vmparam.h>
     65  1.21.2.2  bouyer 
     66  1.21.2.2  bouyer #include <dev/ic/ncr53c9xreg.h>
     67  1.21.2.2  bouyer #include <dev/ic/ncr53c9xvar.h>
     68  1.21.2.2  bouyer 
     69  1.21.2.2  bouyer #include <machine/cpu.h>
     70  1.21.2.2  bouyer #include <machine/sid.h>
     71  1.21.2.2  bouyer #include <machine/scb.h>
     72  1.21.2.2  bouyer #include <machine/vsbus.h>
     73  1.21.2.2  bouyer #include <machine/clock.h>	/* for SCSI ctlr ID# XXX */
     74  1.21.2.2  bouyer 
     75  1.21.2.2  bouyer struct asc_vsbus_softc {
     76  1.21.2.2  bouyer 	struct ncr53c9x_softc sc_ncr53c9x;	/* Must be first */
     77  1.21.2.2  bouyer 	struct evcnt sc_intrcnt;		/* count interrupts */
     78  1.21.2.2  bouyer 	bus_space_tag_t sc_bst;			/* bus space tag */
     79  1.21.2.2  bouyer 	bus_space_handle_t sc_bsh;		/* bus space handle */
     80  1.21.2.2  bouyer 	bus_space_handle_t sc_dirh;		/* scsi direction handle */
     81  1.21.2.2  bouyer 	bus_space_handle_t sc_adrh;		/* scsi address handle */
     82  1.21.2.2  bouyer 	bus_space_handle_t sc_ncrh;		/* ncr bus space handle */
     83  1.21.2.2  bouyer 	bus_dma_tag_t sc_dmat;			/* bus dma tag */
     84  1.21.2.2  bouyer 	bus_dmamap_t sc_dmamap;
     85  1.21.2.2  bouyer 	caddr_t *sc_dmaaddr;
     86  1.21.2.2  bouyer 	size_t *sc_dmalen;
     87  1.21.2.2  bouyer 	size_t sc_dmasize;
     88  1.21.2.2  bouyer 	unsigned int sc_flags;
     89  1.21.2.2  bouyer #define	ASC_FROMMEMORY		0x0001		/* Must be 1 */
     90  1.21.2.2  bouyer #define	ASC_DMAACTIVE		0x0002
     91  1.21.2.2  bouyer #define	ASC_MAPLOADED		0x0004
     92  1.21.2.2  bouyer 	unsigned long sc_xfers;
     93  1.21.2.2  bouyer };
     94  1.21.2.2  bouyer 
     95  1.21.2.2  bouyer #define	ASC_REG_KA46_ADR	0x0000
     96  1.21.2.2  bouyer #define	ASC_REG_KA46_DIR	0x000C
     97  1.21.2.2  bouyer #define	ASC_REG_KA49_ADR	0x0000
     98  1.21.2.2  bouyer #define	ASC_REG_KA49_DIR	0x0004
     99  1.21.2.2  bouyer #define	ASC_REG_NCR		0x0080
    100  1.21.2.2  bouyer #define	ASC_REG_END		0x00B0
    101  1.21.2.2  bouyer 
    102  1.21.2.2  bouyer #define	ASC_MAXXFERSIZE		65536
    103  1.21.2.2  bouyer #define	ASC_FREQUENCY		25000000
    104  1.21.2.2  bouyer 
    105  1.21.2.2  bouyer static int asc_vsbus_match(struct device *, struct cfdata *, void *);
    106  1.21.2.2  bouyer static void asc_vsbus_attach(struct device *, struct device *, void *);
    107  1.21.2.2  bouyer 
    108  1.21.2.2  bouyer struct cfattach asc_vsbus_ca = {
    109  1.21.2.2  bouyer 	sizeof(struct asc_vsbus_softc), asc_vsbus_match, asc_vsbus_attach
    110  1.21.2.2  bouyer };
    111  1.21.2.2  bouyer 
    112  1.21.2.2  bouyer /*
    113  1.21.2.2  bouyer  * Functions and the switch for the MI code
    114  1.21.2.2  bouyer  */
    115  1.21.2.2  bouyer static u_char	asc_vsbus_read_reg(struct ncr53c9x_softc *, int);
    116  1.21.2.2  bouyer static void	asc_vsbus_write_reg(struct ncr53c9x_softc *, int, u_char);
    117  1.21.2.2  bouyer static int	asc_vsbus_dma_isintr(struct ncr53c9x_softc *);
    118  1.21.2.2  bouyer static void	asc_vsbus_dma_reset(struct ncr53c9x_softc *);
    119  1.21.2.2  bouyer static int	asc_vsbus_dma_intr(struct ncr53c9x_softc *);
    120  1.21.2.2  bouyer static int	asc_vsbus_dma_setup(struct ncr53c9x_softc *, caddr_t *,
    121  1.21.2.2  bouyer 		    size_t *, int, size_t *);
    122  1.21.2.2  bouyer static void	asc_vsbus_dma_go(struct ncr53c9x_softc *);
    123  1.21.2.2  bouyer static void	asc_vsbus_dma_stop(struct ncr53c9x_softc *);
    124  1.21.2.2  bouyer static int	asc_vsbus_dma_isactive(struct ncr53c9x_softc *);
    125  1.21.2.2  bouyer 
    126  1.21.2.2  bouyer static struct ncr53c9x_glue asc_vsbus_glue = {
    127  1.21.2.2  bouyer 	asc_vsbus_read_reg,
    128  1.21.2.2  bouyer 	asc_vsbus_write_reg,
    129  1.21.2.2  bouyer 	asc_vsbus_dma_isintr,
    130  1.21.2.2  bouyer 	asc_vsbus_dma_reset,
    131  1.21.2.2  bouyer 	asc_vsbus_dma_intr,
    132  1.21.2.2  bouyer 	asc_vsbus_dma_setup,
    133  1.21.2.2  bouyer 	asc_vsbus_dma_go,
    134  1.21.2.2  bouyer 	asc_vsbus_dma_stop,
    135  1.21.2.2  bouyer 	asc_vsbus_dma_isactive,
    136  1.21.2.2  bouyer 	NULL,
    137  1.21.2.2  bouyer };
    138  1.21.2.2  bouyer 
    139  1.21.2.2  bouyer static u_int8_t asc_attached;		/* can't have more than one asc */
    140  1.21.2.2  bouyer 
    141  1.21.2.2  bouyer static int
    142  1.21.2.2  bouyer asc_vsbus_match( struct device *parent, struct cfdata *cf, void *aux)
    143  1.21.2.2  bouyer {
    144  1.21.2.2  bouyer 	struct vsbus_attach_args *va = aux;
    145  1.21.2.2  bouyer 	volatile u_int8_t *ncr_regs;
    146  1.21.2.2  bouyer 	int dummy;
    147  1.21.2.2  bouyer 
    148  1.21.2.2  bouyer 	if (asc_attached)
    149  1.21.2.2  bouyer 		return 0;
    150  1.21.2.2  bouyer 
    151  1.21.2.2  bouyer 	if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
    152  1.21.2.2  bouyer 		if (cf->cf_loc[0] != 0x200c0080)
    153  1.21.2.2  bouyer 			return 0;
    154  1.21.2.3  bouyer #if 1
    155  1.21.2.2  bouyer 	} else if (vax_boardtype == VAX_BTYP_49) {
    156  1.21.2.2  bouyer 		if (cf->cf_loc[0] != 0x26000080)
    157  1.21.2.2  bouyer 			return 0;
    158  1.21.2.2  bouyer #endif
    159  1.21.2.2  bouyer 	} else {
    160  1.21.2.2  bouyer 		return 0;
    161  1.21.2.2  bouyer 	}
    162  1.21.2.2  bouyer 
    163  1.21.2.2  bouyer 	ncr_regs = (volatile u_int8_t *) va->va_addr;
    164  1.21.2.2  bouyer 
    165  1.21.2.2  bouyer 	/*  *** need to generate an interrupt here
    166  1.21.2.2  bouyer 	 * From trial and error, I've determined that an INT is generated
    167  1.21.2.2  bouyer 	 * only when the following sequence of events occurs:
    168  1.21.2.2  bouyer 	 *   1) The interrupt status register (0x05) must be read.
    169  1.21.2.2  bouyer 	 *   2) SCSI bus reset interrupt must be enabled
    170  1.21.2.2  bouyer 	 *   3) SCSI bus reset command must be sent
    171  1.21.2.2  bouyer 	 *   4) NOP command must be sent
    172  1.21.2.2  bouyer 	 */
    173  1.21.2.2  bouyer 
    174  1.21.2.2  bouyer 	dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
    175  1.21.2.2  bouyer         ncr_regs[NCR_CFG1 << 2] = 0x06; /* we're ID 6, turn on INT for SCSI reset */
    176  1.21.2.2  bouyer         ncr_regs[NCR_CMD << 2] = NCRCMD_RSTSCSI; /* send the reset */
    177  1.21.2.2  bouyer         ncr_regs[NCR_CMD << 2] = NCRCMD_NOP; /* send a NOP */
    178  1.21.2.2  bouyer 	DELAY(10000);
    179  1.21.2.2  bouyer 
    180  1.21.2.2  bouyer 	dummy = ncr_regs[NCR_INTR << 2] & 0xFF;
    181  1.21.2.2  bouyer 	return (dummy & NCRINTR_SBR) != 0;
    182  1.21.2.2  bouyer }
    183  1.21.2.2  bouyer 
    184  1.21.2.2  bouyer 
    185  1.21.2.2  bouyer /*
    186  1.21.2.2  bouyer  * Attach this instance, and then all the sub-devices
    187  1.21.2.2  bouyer  */
    188  1.21.2.2  bouyer static void
    189  1.21.2.2  bouyer asc_vsbus_attach(struct device *parent, struct device *self, void *aux)
    190  1.21.2.2  bouyer {
    191  1.21.2.2  bouyer 	struct vsbus_attach_args *va = aux;
    192  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (void *)self;
    193  1.21.2.2  bouyer 	struct ncr53c9x_softc *sc = &asc->sc_ncr53c9x;
    194  1.21.2.2  bouyer 	int error;
    195  1.21.2.2  bouyer 
    196  1.21.2.2  bouyer 	asc_attached = 1;
    197  1.21.2.2  bouyer 	/*
    198  1.21.2.2  bouyer 	 * Set up glue for MI code early; we use some of it here.
    199  1.21.2.2  bouyer 	 */
    200  1.21.2.2  bouyer 	sc->sc_glue = &asc_vsbus_glue;
    201  1.21.2.2  bouyer 
    202  1.21.2.2  bouyer 	asc->sc_bst = va->va_iot;
    203  1.21.2.2  bouyer 	asc->sc_dmat = va->va_dmat;
    204  1.21.2.2  bouyer 
    205  1.21.2.2  bouyer 	error = bus_space_map(asc->sc_bst, va->va_paddr - ASC_REG_NCR,
    206  1.21.2.2  bouyer 	    ASC_REG_END, 0, &asc->sc_bsh);
    207  1.21.2.2  bouyer 	if (error) {
    208  1.21.2.2  bouyer 		printf(": failed to map registers: error=%d\n", error);
    209  1.21.2.2  bouyer 		return;
    210  1.21.2.2  bouyer 	}
    211  1.21.2.2  bouyer 	error = bus_space_subregion(asc->sc_bst, asc->sc_bsh, ASC_REG_NCR,
    212  1.21.2.2  bouyer 	    ASC_REG_END - ASC_REG_NCR, &asc->sc_ncrh);
    213  1.21.2.2  bouyer 	if (error) {
    214  1.21.2.2  bouyer 		printf(": failed to map ncr registers: error=%d\n", error);
    215  1.21.2.2  bouyer 		return;
    216  1.21.2.2  bouyer 	}
    217  1.21.2.2  bouyer 	if (vax_boardtype == VAX_BTYP_46 || vax_boardtype == VAX_BTYP_48) {
    218  1.21.2.2  bouyer 		error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
    219  1.21.2.2  bouyer 		    ASC_REG_KA46_ADR, sizeof(u_int32_t), &asc->sc_adrh);
    220  1.21.2.2  bouyer 		if (error) {
    221  1.21.2.2  bouyer 			printf(": failed to map adr register: error=%d\n",
    222  1.21.2.2  bouyer 			     error);
    223  1.21.2.2  bouyer 			return;
    224  1.21.2.2  bouyer 		}
    225  1.21.2.2  bouyer 		error = bus_space_subregion(asc->sc_bst, asc->sc_bsh,
    226  1.21.2.2  bouyer 		    ASC_REG_KA46_DIR, sizeof(u_int32_t), &asc->sc_dirh);
    227  1.21.2.2  bouyer 		if (error) {
    228  1.21.2.2  bouyer 			printf(": failed to map dir register: error=%d\n",
    229  1.21.2.2  bouyer 			     error);
    230  1.21.2.2  bouyer 			return;
    231  1.21.2.2  bouyer 		}
    232  1.21.2.2  bouyer 	} else {
    233  1.21.2.2  bouyer 		/* This is a gross and disgusting kludge but it'll
    234  1.21.2.2  bouyer 		 * save a bunch of ugly code.  Unlike the VS4000/60,
    235  1.21.2.2  bouyer 		 * the SCSI Address and direction registers are not
    236  1.21.2.2  bouyer 		 * near the SCSI NCR registers and are inside the
    237  1.21.2.2  bouyer 		 * block of general VAXstation registers.  So we grab
    238  1.21.2.2  bouyer 		 * them from there and knowing the internals of the
    239  1.21.2.2  bouyer 		 * bus_space implementation, we cast to bus_space_handles.
    240  1.21.2.2  bouyer 		 */
    241  1.21.2.2  bouyer 		struct vsbus_softc *vsc = (struct vsbus_softc *) parent;
    242  1.21.2.2  bouyer 		asc->sc_adrh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_ADR);
    243  1.21.2.2  bouyer 		asc->sc_dirh = (bus_space_handle_t) (vsc->sc_vsregs + ASC_REG_KA49_DIR);
    244  1.21.2.2  bouyer #if 0
    245  1.21.2.2  bouyer 		printf("\n%s: adrh=0x%08lx dirh=0x%08lx", self->dv_xname,
    246  1.21.2.2  bouyer 		       asc->sc_adrh, asc->sc_dirh);
    247  1.21.2.2  bouyer 		ncr53c9x_debug = NCR_SHOWDMA|NCR_SHOWINTS|NCR_SHOWCMDS|NCR_SHOWPHASE|NCR_SHOWSTART|NCR_SHOWMSGS;
    248  1.21.2.2  bouyer #endif
    249  1.21.2.2  bouyer 	}
    250  1.21.2.2  bouyer 	error = bus_dmamap_create(asc->sc_dmat, ASC_MAXXFERSIZE, 1,
    251  1.21.2.2  bouyer 	    ASC_MAXXFERSIZE, 0, BUS_DMA_NOWAIT, &asc->sc_dmamap);
    252  1.21.2.2  bouyer 
    253  1.21.2.2  bouyer 	switch (vax_boardtype) {
    254  1.21.2.2  bouyer #if defined(VAX46)
    255  1.21.2.2  bouyer 	case VAX_BTYP_46:
    256  1.21.2.2  bouyer 		sc->sc_id = (clk_page[0xbc/2] >> clk_tweak) & 7;
    257  1.21.2.2  bouyer 		break;
    258  1.21.2.2  bouyer #endif
    259  1.21.2.2  bouyer 	default:
    260  1.21.2.2  bouyer 		sc->sc_id = 6;	/* XXX need to get this from VMB */
    261  1.21.2.2  bouyer 		break;
    262  1.21.2.2  bouyer 	}
    263  1.21.2.2  bouyer 
    264  1.21.2.2  bouyer 	sc->sc_freq = ASC_FREQUENCY;
    265  1.21.2.2  bouyer 
    266  1.21.2.2  bouyer 	/* gimme Mhz */
    267  1.21.2.2  bouyer 	sc->sc_freq /= 1000000;
    268  1.21.2.2  bouyer 
    269  1.21.2.2  bouyer 	scb_vecalloc(va->va_cvec, (void (*)(void *)) ncr53c9x_intr,
    270  1.21.2.2  bouyer 	    &asc->sc_ncr53c9x, SCB_ISTACK, &asc->sc_intrcnt);
    271  1.21.2.2  bouyer 	evcnt_attach_dynamic(&asc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    272  1.21.2.2  bouyer 	    self->dv_xname, "intr");
    273  1.21.2.2  bouyer 
    274  1.21.2.2  bouyer 	/*
    275  1.21.2.2  bouyer 	 * XXX More of this should be in ncr53c9x_attach(), but
    276  1.21.2.2  bouyer 	 * XXX should we really poke around the chip that much in
    277  1.21.2.2  bouyer 	 * XXX the MI code?  Think about this more...
    278  1.21.2.2  bouyer 	 */
    279  1.21.2.2  bouyer 
    280  1.21.2.2  bouyer 	/*
    281  1.21.2.2  bouyer 	 * Set up static configuration info.
    282  1.21.2.2  bouyer 	 */
    283  1.21.2.2  bouyer 	sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
    284  1.21.2.2  bouyer 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    285  1.21.2.2  bouyer 	sc->sc_cfg3 = 0;
    286  1.21.2.2  bouyer 	sc->sc_rev = NCR_VARIANT_NCR53C94;
    287  1.21.2.2  bouyer 
    288  1.21.2.2  bouyer 	/*
    289  1.21.2.2  bouyer 	 * XXX minsync and maxxfer _should_ be set up in MI code,
    290  1.21.2.2  bouyer 	 * XXX but it appears to have some dependency on what sort
    291  1.21.2.2  bouyer 	 * XXX of DMA we're hooked up to, etc.
    292  1.21.2.2  bouyer 	 */
    293  1.21.2.2  bouyer 
    294  1.21.2.2  bouyer 	/*
    295  1.21.2.2  bouyer 	 * This is the value used to start sync negotiations
    296  1.21.2.2  bouyer 	 * Note that the NCR register "SYNCTP" is programmed
    297  1.21.2.2  bouyer 	 * in "clocks per byte", and has a minimum value of 4.
    298  1.21.2.2  bouyer 	 * The SCSI period used in negotiation is one-fourth
    299  1.21.2.2  bouyer 	 * of the time (in nanoseconds) needed to transfer one byte.
    300  1.21.2.2  bouyer 	 * Since the chip's clock is given in MHz, we have the following
    301  1.21.2.2  bouyer 	 * formula: 4 * period = (1000 / freq) * 4
    302  1.21.2.2  bouyer 	 */
    303  1.21.2.2  bouyer 	sc->sc_minsync = (1000 / sc->sc_freq);
    304  1.21.2.2  bouyer 	sc->sc_maxxfer = 63 * 1024;
    305  1.21.2.2  bouyer 
    306  1.21.2.2  bouyer 	printf("\n%s", self->dv_xname);	/* Pretty print */
    307  1.21.2.2  bouyer 
    308  1.21.2.2  bouyer 	/* Do the common parts of attachment. */
    309  1.21.2.2  bouyer 	ncr53c9x_attach(sc, NULL, NULL);
    310  1.21.2.2  bouyer }
    311  1.21.2.2  bouyer 
    312  1.21.2.2  bouyer /*
    313  1.21.2.2  bouyer  * Glue functions.
    314  1.21.2.2  bouyer  */
    315  1.21.2.2  bouyer 
    316  1.21.2.2  bouyer static u_char
    317  1.21.2.2  bouyer asc_vsbus_read_reg(struct ncr53c9x_softc *sc, int reg)
    318  1.21.2.2  bouyer {
    319  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    320  1.21.2.2  bouyer 
    321  1.21.2.2  bouyer 	return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
    322  1.21.2.2  bouyer 	    reg * sizeof(u_int32_t));
    323  1.21.2.2  bouyer }
    324  1.21.2.2  bouyer 
    325  1.21.2.2  bouyer static void
    326  1.21.2.2  bouyer asc_vsbus_write_reg(sc, reg, val)
    327  1.21.2.2  bouyer 	struct ncr53c9x_softc *sc;
    328  1.21.2.2  bouyer 	int reg;
    329  1.21.2.2  bouyer 	u_char val;
    330  1.21.2.2  bouyer {
    331  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    332  1.21.2.2  bouyer 
    333  1.21.2.2  bouyer 	bus_space_write_1(asc->sc_bst, asc->sc_ncrh,
    334  1.21.2.2  bouyer 	    reg * sizeof(u_int32_t), val);
    335  1.21.2.2  bouyer }
    336  1.21.2.2  bouyer 
    337  1.21.2.2  bouyer static int
    338  1.21.2.2  bouyer asc_vsbus_dma_isintr(sc)
    339  1.21.2.2  bouyer 	struct ncr53c9x_softc *sc;
    340  1.21.2.2  bouyer {
    341  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    342  1.21.2.2  bouyer 	return bus_space_read_1(asc->sc_bst, asc->sc_ncrh,
    343  1.21.2.2  bouyer 	    NCR_STAT * sizeof(u_int32_t)) & NCRSTAT_INT;
    344  1.21.2.2  bouyer }
    345  1.21.2.2  bouyer 
    346  1.21.2.2  bouyer static void
    347  1.21.2.2  bouyer asc_vsbus_dma_reset(sc)
    348  1.21.2.2  bouyer 	struct ncr53c9x_softc *sc;
    349  1.21.2.2  bouyer {
    350  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    351  1.21.2.2  bouyer 
    352  1.21.2.2  bouyer 	if (asc->sc_flags & ASC_MAPLOADED)
    353  1.21.2.2  bouyer 		bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
    354  1.21.2.2  bouyer 	asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
    355  1.21.2.2  bouyer }
    356  1.21.2.2  bouyer 
    357  1.21.2.2  bouyer static int
    358  1.21.2.2  bouyer asc_vsbus_dma_intr(sc)
    359  1.21.2.2  bouyer 	struct ncr53c9x_softc *sc;
    360  1.21.2.2  bouyer {
    361  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    362  1.21.2.2  bouyer 	u_int tcl, tcm;
    363  1.21.2.2  bouyer 	int trans, resid;
    364  1.21.2.2  bouyer 
    365  1.21.2.2  bouyer 	if ((asc->sc_flags & ASC_DMAACTIVE) == 0)
    366  1.21.2.2  bouyer 		panic("asc_vsbus_dma_intr: DMA wasn't active");
    367  1.21.2.2  bouyer 
    368  1.21.2.2  bouyer 	asc->sc_flags &= ~ASC_DMAACTIVE;
    369  1.21.2.2  bouyer 
    370  1.21.2.2  bouyer 	if (asc->sc_dmasize == 0) {
    371  1.21.2.2  bouyer 		/* A "Transfer Pad" operation completed */
    372  1.21.2.2  bouyer 		tcl = NCR_READ_REG(sc, NCR_TCL);
    373  1.21.2.2  bouyer 		tcm = NCR_READ_REG(sc, NCR_TCM);
    374  1.21.2.2  bouyer 		NCR_DMA(("asc_vsbus_intr: discarded %d bytes (tcl=%d, tcm=%d)\n",
    375  1.21.2.2  bouyer 		    tcl | (tcm << 8), tcl, tcm));
    376  1.21.2.2  bouyer 		return 0;
    377  1.21.2.2  bouyer 	}
    378  1.21.2.2  bouyer 
    379  1.21.2.2  bouyer 	resid = 0;
    380  1.21.2.2  bouyer 	if ((resid = (NCR_READ_REG(sc, NCR_FFLAG) & NCRFIFO_FF)) != 0) {
    381  1.21.2.2  bouyer 		NCR_DMA(("asc_vsbus_intr: empty FIFO of %d ", resid));
    382  1.21.2.2  bouyer 		DELAY(1);
    383  1.21.2.2  bouyer 	}
    384  1.21.2.2  bouyer 	if (asc->sc_flags & ASC_MAPLOADED) {
    385  1.21.2.2  bouyer 		bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
    386  1.21.2.2  bouyer 				0, asc->sc_dmasize,
    387  1.21.2.2  bouyer 				asc->sc_flags & ASC_FROMMEMORY
    388  1.21.2.2  bouyer 					? BUS_DMASYNC_POSTWRITE
    389  1.21.2.2  bouyer 					: BUS_DMASYNC_POSTREAD);
    390  1.21.2.2  bouyer 		bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
    391  1.21.2.2  bouyer 	}
    392  1.21.2.2  bouyer 	asc->sc_flags &= ~ASC_MAPLOADED;
    393  1.21.2.2  bouyer 
    394  1.21.2.2  bouyer 	resid += (tcl = NCR_READ_REG(sc, NCR_TCL));
    395  1.21.2.2  bouyer 	resid += (tcm = NCR_READ_REG(sc, NCR_TCM)) << 8;
    396  1.21.2.2  bouyer 
    397  1.21.2.2  bouyer 	trans = asc->sc_dmasize - resid;
    398  1.21.2.2  bouyer 	if (trans < 0) {			/* transferred < 0 ? */
    399  1.21.2.2  bouyer 		printf("asc_vsbus_intr: xfer (%d) > req (%lu)\n",
    400  1.21.2.2  bouyer 		    trans, (u_long) asc->sc_dmasize);
    401  1.21.2.2  bouyer 		trans = asc->sc_dmasize;
    402  1.21.2.2  bouyer 	}
    403  1.21.2.2  bouyer 	NCR_DMA(("asc_vsbus_intr: tcl=%d, tcm=%d; trans=%d, resid=%d\n",
    404  1.21.2.2  bouyer 	    tcl, tcm, trans, resid));
    405  1.21.2.2  bouyer 
    406  1.21.2.2  bouyer 	*asc->sc_dmalen -= trans;
    407  1.21.2.2  bouyer 	*asc->sc_dmaaddr += trans;
    408  1.21.2.2  bouyer 
    409  1.21.2.2  bouyer 	asc->sc_xfers++;
    410  1.21.2.2  bouyer 	return 0;
    411  1.21.2.2  bouyer }
    412  1.21.2.2  bouyer 
    413  1.21.2.2  bouyer static int
    414  1.21.2.2  bouyer asc_vsbus_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, size_t *len,
    415  1.21.2.2  bouyer 		    int datain, size_t *dmasize)
    416  1.21.2.2  bouyer {
    417  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    418  1.21.2.2  bouyer 
    419  1.21.2.2  bouyer 	asc->sc_dmaaddr = addr;
    420  1.21.2.2  bouyer 	asc->sc_dmalen = len;
    421  1.21.2.2  bouyer 	if (datain) {
    422  1.21.2.2  bouyer 		asc->sc_flags &= ~ASC_FROMMEMORY;
    423  1.21.2.2  bouyer 	} else {
    424  1.21.2.2  bouyer 		asc->sc_flags |= ASC_FROMMEMORY;
    425  1.21.2.2  bouyer 	}
    426  1.21.2.2  bouyer 	if ((vaddr_t) *asc->sc_dmaaddr < VM_MIN_KERNEL_ADDRESS)
    427  1.21.2.2  bouyer 		panic("asc_vsbus_dma_setup: dma address (%p) outside of kernel",
    428  1.21.2.2  bouyer 		    *asc->sc_dmaaddr);
    429  1.21.2.2  bouyer 
    430  1.21.2.2  bouyer         NCR_DMA(("%s: start %d@%p,%d\n", sc->sc_dev.dv_xname,
    431  1.21.2.2  bouyer                 (int)*asc->sc_dmalen, *asc->sc_dmaaddr, (asc->sc_flags & ASC_FROMMEMORY)));
    432  1.21.2.2  bouyer 	*dmasize = asc->sc_dmasize = min(*dmasize, ASC_MAXXFERSIZE);
    433  1.21.2.2  bouyer 
    434  1.21.2.2  bouyer 	if (asc->sc_dmasize) {
    435  1.21.2.2  bouyer 		if (bus_dmamap_load(asc->sc_dmat, asc->sc_dmamap,
    436  1.21.2.2  bouyer 				*asc->sc_dmaaddr, asc->sc_dmasize,
    437  1.21.2.2  bouyer 				NULL /* kernel address */,
    438  1.21.2.2  bouyer 				BUS_DMA_NOWAIT|VAX_BUS_DMA_SPILLPAGE))
    439  1.21.2.2  bouyer 			panic("%s: cannot load dma map", sc->sc_dev.dv_xname);
    440  1.21.2.2  bouyer 		bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
    441  1.21.2.2  bouyer 				0, asc->sc_dmasize,
    442  1.21.2.2  bouyer 				asc->sc_flags & ASC_FROMMEMORY
    443  1.21.2.2  bouyer 					? BUS_DMASYNC_PREWRITE
    444  1.21.2.2  bouyer 					: BUS_DMASYNC_PREREAD);
    445  1.21.2.2  bouyer 		bus_space_write_4(asc->sc_bst, asc->sc_adrh, 0,
    446  1.21.2.2  bouyer 				  asc->sc_dmamap->dm_segs[0].ds_addr);
    447  1.21.2.2  bouyer 		bus_space_write_4(asc->sc_bst, asc->sc_dirh, 0,
    448  1.21.2.2  bouyer 				  asc->sc_flags & ASC_FROMMEMORY);
    449  1.21.2.2  bouyer 		NCR_DMA(("%s: dma-load %lu@0x%08lx\n", sc->sc_dev.dv_xname,
    450  1.21.2.2  bouyer 			asc->sc_dmamap->dm_segs[0].ds_len,
    451  1.21.2.2  bouyer 			asc->sc_dmamap->dm_segs[0].ds_addr));
    452  1.21.2.2  bouyer 		asc->sc_flags |= ASC_MAPLOADED;
    453  1.21.2.2  bouyer 	}
    454  1.21.2.2  bouyer 
    455  1.21.2.2  bouyer 	return 0;
    456  1.21.2.2  bouyer }
    457  1.21.2.2  bouyer 
    458  1.21.2.2  bouyer static void
    459  1.21.2.2  bouyer asc_vsbus_dma_go(struct ncr53c9x_softc *sc)
    460  1.21.2.2  bouyer {
    461  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    462  1.21.2.2  bouyer 
    463  1.21.2.2  bouyer 	asc->sc_flags |= ASC_DMAACTIVE;
    464  1.21.2.2  bouyer }
    465  1.21.2.2  bouyer 
    466  1.21.2.2  bouyer static void
    467  1.21.2.2  bouyer asc_vsbus_dma_stop(struct ncr53c9x_softc *sc)
    468  1.21.2.2  bouyer {
    469  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    470  1.21.2.2  bouyer 
    471  1.21.2.2  bouyer 	if (asc->sc_flags & ASC_MAPLOADED) {
    472  1.21.2.2  bouyer 		bus_dmamap_sync(asc->sc_dmat, asc->sc_dmamap,
    473  1.21.2.2  bouyer 				0, asc->sc_dmasize,
    474  1.21.2.2  bouyer 				asc->sc_flags & ASC_FROMMEMORY
    475  1.21.2.2  bouyer 					? BUS_DMASYNC_POSTWRITE
    476  1.21.2.2  bouyer 					: BUS_DMASYNC_POSTREAD);
    477  1.21.2.2  bouyer 		bus_dmamap_unload(asc->sc_dmat, asc->sc_dmamap);
    478  1.21.2.2  bouyer 	}
    479  1.21.2.2  bouyer 
    480  1.21.2.2  bouyer 	asc->sc_flags &= ~(ASC_DMAACTIVE|ASC_MAPLOADED);
    481  1.21.2.2  bouyer }
    482  1.21.2.2  bouyer 
    483  1.21.2.2  bouyer static int
    484  1.21.2.2  bouyer asc_vsbus_dma_isactive(struct ncr53c9x_softc *sc)
    485  1.21.2.2  bouyer {
    486  1.21.2.2  bouyer 	struct asc_vsbus_softc *asc = (struct asc_vsbus_softc *)sc;
    487  1.21.2.2  bouyer 
    488  1.21.2.2  bouyer 	return (asc->sc_flags & ASC_DMAACTIVE) != 0;
    489  1.21.2.2  bouyer }
    490