Home | History | Annotate | Line # | Download | only in isa
esp_isa.c revision 1.1
      1  1.1  pk /*
      2  1.1  pk  * Copyright (c) 1997 Jason R. Thorpe.
      3  1.1  pk  * All rights reserved.
      4  1.1  pk  *
      5  1.1  pk  * Redistribution and use in source and binary forms, with or without
      6  1.1  pk  * modification, are permitted provided that the following conditions
      7  1.1  pk  * are met:
      8  1.1  pk  * 1. Redistributions of source code must retain the above copyright
      9  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     10  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  pk  *    documentation and/or other materials provided with the distribution.
     13  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     14  1.1  pk  *    must display the following acknowledgement:
     15  1.1  pk  *	This product includes software developed for the NetBSD Project
     16  1.1  pk  *	by Jason R. Thorpe.
     17  1.1  pk  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  pk  *    derived from this software without specific prior written permission.
     19  1.1  pk  *
     20  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  pk  */
     31  1.1  pk 
     32  1.1  pk /*
     33  1.1  pk  * Copyright (c) 1994 Peter Galbavy
     34  1.1  pk  * Copyright (c) 1995 Paul Kranenburg
     35  1.1  pk  * All rights reserved.
     36  1.1  pk  *
     37  1.1  pk  * Redistribution and use in source and binary forms, with or without
     38  1.1  pk  * modification, are permitted provided that the following conditions
     39  1.1  pk  * are met:
     40  1.1  pk  * 1. Redistributions of source code must retain the above copyright
     41  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     42  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     44  1.1  pk  *    documentation and/or other materials provided with the distribution.
     45  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     46  1.1  pk  *    must display the following acknowledgement:
     47  1.1  pk  *	This product includes software developed by Peter Galbavy
     48  1.1  pk  * 4. The name of the author may not be used to endorse or promote products
     49  1.1  pk  *    derived from this software without specific prior written permission.
     50  1.1  pk  *
     51  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     52  1.1  pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     53  1.1  pk  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     54  1.1  pk  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     55  1.1  pk  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     56  1.1  pk  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     57  1.1  pk  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58  1.1  pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     59  1.1  pk  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     60  1.1  pk  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     61  1.1  pk  * POSSIBILITY OF SUCH DAMAGE.
     62  1.1  pk  */
     63  1.1  pk 
     64  1.1  pk /*
     65  1.1  pk  * Based on aic6360 by Jarle Greipsland
     66  1.1  pk  *
     67  1.1  pk  * Acknowledgements: Many of the algorithms used in this driver are
     68  1.1  pk  * inspired by the work of Julian Elischer (julian (at) tfs.com) and
     69  1.1  pk  * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu).  Thanks a million!
     70  1.1  pk  */
     71  1.1  pk 
     72  1.1  pk /*
     73  1.1  pk  * Initial m68k mac support from Allen Briggs <briggs (at) macbsd.com>
     74  1.1  pk  * (basically consisting of the match, a bit of the attach, and the
     75  1.1  pk  *  "DMA" glue functions).
     76  1.1  pk  */
     77  1.1  pk /*
     78  1.1  pk  * Copyright (c) 1994, 1996, 1997 Charles M. Hannum.  All rights reserved.
     79  1.1  pk  *
     80  1.1  pk  * Redistribution and use in source and binary forms, with or without
     81  1.1  pk  * modification, are permitted provided that the following conditions
     82  1.1  pk  * are met:
     83  1.1  pk  * 1. Redistributions of source code must retain the above copyright
     84  1.1  pk  *    notice, this list of conditions and the following disclaimer.
     85  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
     86  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
     87  1.1  pk  *    documentation and/or other materials provided with the distribution.
     88  1.1  pk  * 3. All advertising materials mentioning features or use of this software
     89  1.1  pk  *    must display the following acknowledgement:
     90  1.1  pk  *	This product includes software developed by Charles M. Hannum.
     91  1.1  pk  * 4. The name of the author may not be used to endorse or promote products
     92  1.1  pk  *    derived from this software without specific prior written permission.
     93  1.1  pk  *
     94  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     95  1.1  pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     96  1.1  pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     97  1.1  pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     98  1.1  pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     99  1.1  pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    100  1.1  pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    101  1.1  pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    102  1.1  pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    103  1.1  pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    104  1.1  pk  */
    105  1.1  pk 
    106  1.1  pk /*
    107  1.1  pk  * Copyright (c) 1997 Eric S. Hvozda (hvozda (at) netcom.com)
    108  1.1  pk  * All rights reserved.
    109  1.1  pk  *
    110  1.1  pk  * Redistribution and use in source and binary forms, with or without
    111  1.1  pk  * modification, are permitted provided that the following conditions
    112  1.1  pk  * are met:
    113  1.1  pk  * 1. Redistributions of source code must retain the above copyright
    114  1.1  pk  *    notice, this list of conditions and the following disclaimer.
    115  1.1  pk  * 2. Redistributions in binary form must reproduce the above copyright
    116  1.1  pk  *    notice, this list of conditions and the following disclaimer in the
    117  1.1  pk  *    documentation and/or other materials provided with the distribution.
    118  1.1  pk  * 3. All advertising materials mentioning features or use of this software
    119  1.1  pk  *    must display the following acknowledgement:
    120  1.1  pk  *      This product includes software developed by Eric S. Hvozda.
    121  1.1  pk  * 4. The name of Eric S. Hvozda may not be used to endorse or promote products
    122  1.1  pk  *    derived from this software without specific prior written permission.
    123  1.1  pk  *
    124  1.1  pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    125  1.1  pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    126  1.1  pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    127  1.1  pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    128  1.1  pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    129  1.1  pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    130  1.1  pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    131  1.1  pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    132  1.1  pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    133  1.1  pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    134  1.1  pk  */
    135  1.1  pk 
    136  1.1  pk #include <sys/param.h>
    137  1.1  pk #include <sys/systm.h>
    138  1.1  pk #include <sys/device.h>
    139  1.1  pk #include <sys/buf.h>
    140  1.1  pk 
    141  1.1  pk #include <machine/bus.h>
    142  1.1  pk #include <machine/intr.h>
    143  1.1  pk 
    144  1.1  pk #include <scsi/scsi_all.h>
    145  1.1  pk #include <scsi/scsiconf.h>
    146  1.1  pk 
    147  1.1  pk #include <dev/isa/isavar.h>
    148  1.1  pk #include <dev/isa/isadmavar.h>
    149  1.1  pk 
    150  1.1  pk #include <dev/ic/ncr53c9xreg.h>
    151  1.1  pk #include <dev/ic/ncr53c9xvar.h>
    152  1.1  pk 
    153  1.1  pk #include <dev/isa/espvar.h>
    154  1.1  pk 
    155  1.1  pk int	esp_isa_match __P((struct device *, void *, void *));
    156  1.1  pk void	esp_isa_attach __P((struct device *, struct device *, void *));
    157  1.1  pk 
    158  1.1  pk struct cfattach esp_isa_ca = {
    159  1.1  pk 	sizeof(struct esp_softc), esp_isa_match, esp_isa_attach
    160  1.1  pk };
    161  1.1  pk 
    162  1.1  pk struct cfdriver esp_cd = {
    163  1.1  pk 	NULL, "esp", DV_DULL
    164  1.1  pk };
    165  1.1  pk 
    166  1.1  pk struct scsi_adapter esp_switch = {
    167  1.1  pk 	ncr53c9x_scsi_cmd,
    168  1.1  pk 	minphys,		/* no max at this level; handled by DMA code */
    169  1.1  pk 	NULL,
    170  1.1  pk 	NULL,
    171  1.1  pk };
    172  1.1  pk 
    173  1.1  pk struct scsi_device esp_dev = {
    174  1.1  pk 	NULL,			/* Use default error handler */
    175  1.1  pk 	NULL,			/* have a queue, served by this */
    176  1.1  pk 	NULL,			/* have no async handler */
    177  1.1  pk 	NULL,			/* Use default 'done' routine */
    178  1.1  pk };
    179  1.1  pk 
    180  1.1  pk int esp_debug = 0;	/* ESP_SHOWTRAC | ESP_SHOWREGS | ESP_SHOWMISC */
    181  1.1  pk 
    182  1.1  pk /*
    183  1.1  pk  * Functions and the switch for the MI code.
    184  1.1  pk  */
    185  1.1  pk u_char	esp_read_reg __P((struct ncr53c9x_softc *, int));
    186  1.1  pk void	esp_write_reg __P((struct ncr53c9x_softc *, int, u_char));
    187  1.1  pk int	esp_dma_isintr __P((struct ncr53c9x_softc *));
    188  1.1  pk void	esp_dma_reset __P((struct ncr53c9x_softc *));
    189  1.1  pk int	esp_dma_intr __P((struct ncr53c9x_softc *));
    190  1.1  pk int	esp_dma_setup __P((struct ncr53c9x_softc *, caddr_t *,
    191  1.1  pk 	    size_t *, int, size_t *));
    192  1.1  pk void	esp_dma_go __P((struct ncr53c9x_softc *));
    193  1.1  pk void	esp_dma_stop __P((struct ncr53c9x_softc *));
    194  1.1  pk int	esp_dma_isactive __P((struct ncr53c9x_softc *));
    195  1.1  pk 
    196  1.1  pk struct ncr53c9x_glue esp_glue = {
    197  1.1  pk 	esp_read_reg,
    198  1.1  pk 	esp_write_reg,
    199  1.1  pk 	esp_dma_isintr,
    200  1.1  pk 	esp_dma_reset,
    201  1.1  pk 	esp_dma_intr,
    202  1.1  pk 	esp_dma_setup,
    203  1.1  pk 	esp_dma_go,
    204  1.1  pk 	esp_dma_stop,
    205  1.1  pk 	esp_dma_isactive,
    206  1.1  pk 	NULL,			/* gl_clear_latched_intr */
    207  1.1  pk };
    208  1.1  pk 
    209  1.1  pk /*
    210  1.1  pk  * Look for the board
    211  1.1  pk  */
    212  1.1  pk int
    213  1.1  pk esp_find(iot, ioh, epd)
    214  1.1  pk 	bus_space_tag_t iot;
    215  1.1  pk 	bus_space_handle_t ioh;
    216  1.1  pk 	struct esp_probe_data *epd;
    217  1.1  pk {
    218  1.1  pk 	u_int vers;
    219  1.1  pk 	u_int p1;
    220  1.1  pk 	u_int p2;
    221  1.1  pk 	u_int jmp;
    222  1.1  pk 
    223  1.1  pk 	ESP_TRACE(("[esp_find] "));
    224  1.1  pk 
    225  1.1  pk 	/* reset card before we probe? */
    226  1.1  pk 
    227  1.1  pk 	/*
    228  1.1  pk 	 * Switch to the PIO regs and look for the bit pattern
    229  1.1  pk 	 * we expect...
    230  1.1  pk 	 */
    231  1.1  pk 	bus_space_write_1(iot, ioh, NCR_CFG4,
    232  1.1  pk 		NCRCFG4_CRS1 | bus_space_read_1(iot, ioh, NCR_CFG4));
    233  1.1  pk 
    234  1.1  pk #define SIG_MASK 0x87
    235  1.1  pk #define REV_MASK 0x70
    236  1.1  pk #define	M1	 0x02
    237  1.1  pk #define	M2	 0x05
    238  1.1  pk #define ISNCR	 0x80
    239  1.1  pk #define ISESP406 0x40
    240  1.1  pk 
    241  1.1  pk 	vers = bus_space_read_1(iot, ioh, NCR_SIGNTR);
    242  1.1  pk 	p1 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    243  1.1  pk 	p2 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    244  1.1  pk 
    245  1.1  pk 	ESP_MISC(("%s: 0x%0x 0x%0x 0x%0x\n", epd->sc_dev.dv_xname,
    246  1.1  pk 	    vers, p1, p2));
    247  1.1  pk 
    248  1.1  pk 	if (!((p1 == M1 && p2 == M2) || (p1 == M2 && p2 == M1)))
    249  1.1  pk 		return 0;
    250  1.1  pk 
    251  1.1  pk 	/* Ok, what is it? */
    252  1.1  pk 	epd->sc_isncr = (vers & ISNCR);
    253  1.1  pk 	epd->sc_rev = ((vers & REV_MASK) == ISESP406) ?
    254  1.1  pk 	    NCR_VARIANT_ESP406 : NCR_VARIANT_FAS408;
    255  1.1  pk 
    256  1.1  pk 	/* What do the jumpers tell us? */
    257  1.1  pk 	jmp = bus_space_read_1(iot, ioh, NCR_JMP);
    258  1.1  pk 
    259  1.1  pk 	epd->sc_msize = (jmp & NCRJMP_ROMSZ) ? 0x4000 : 0x8000;
    260  1.1  pk 	epd->sc_parity = jmp & NCRJMP_J2;
    261  1.1  pk 	epd->sc_sync = jmp & NCRJMP_J4;
    262  1.1  pk 	epd->sc_id = (jmp & NCRJMP_J3) ? 7 : 6;
    263  1.1  pk 	switch (jmp & (NCRJMP_J0 | NCRJMP_J1)) {
    264  1.1  pk 		case NCRJMP_J0 | NCRJMP_J1:
    265  1.1  pk 			epd->sc_irq = 11;
    266  1.1  pk 			break;
    267  1.1  pk 		case NCRJMP_J0:
    268  1.1  pk 			epd->sc_irq = 10;
    269  1.1  pk 			break;
    270  1.1  pk 		case NCRJMP_J1:
    271  1.1  pk 			epd->sc_irq = 15;
    272  1.1  pk 			break;
    273  1.1  pk 		default:
    274  1.1  pk 			epd->sc_irq = 12;
    275  1.1  pk 			break;
    276  1.1  pk 	}
    277  1.1  pk 
    278  1.1  pk 	bus_space_write_1(iot, ioh, NCR_CFG4,
    279  1.1  pk 		~NCRCFG4_CRS1 & bus_space_read_1(iot, ioh, NCR_CFG4));
    280  1.1  pk 
    281  1.1  pk 	/* Try to set NCRESPCFG3_FCLK, some FAS408's don't support
    282  1.1  pk 	 * NCRESPCFG3_FCLK even though it is documented.  A bad
    283  1.1  pk 	 * batch of chips perhaps?
    284  1.1  pk 	 */
    285  1.1  pk 	bus_space_write_1(iot, ioh, NCR_ESPCFG3,
    286  1.1  pk 	    bus_space_read_1(iot, ioh, NCR_ESPCFG3) | NCRESPCFG3_FCLK);
    287  1.1  pk 	epd->sc_isfast = bus_space_read_1(iot, ioh, NCR_ESPCFG3)
    288  1.1  pk 	    & NCRESPCFG3_FCLK;
    289  1.1  pk 
    290  1.1  pk 	return 1;
    291  1.1  pk }
    292  1.1  pk 
    293  1.1  pk void
    294  1.1  pk esp_init(esc, epd)
    295  1.1  pk 	struct esp_softc *esc;
    296  1.1  pk 	struct esp_probe_data *epd;
    297  1.1  pk {
    298  1.1  pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    299  1.1  pk 
    300  1.1  pk 	ESP_TRACE(("[esp_init] "));
    301  1.1  pk 
    302  1.1  pk 	/*
    303  1.1  pk 	 * Set up the glue for MI code early; we use some of it here.
    304  1.1  pk 	 */
    305  1.1  pk 	sc->sc_glue = &esp_glue;
    306  1.1  pk 
    307  1.1  pk 	sc->sc_rev = epd->sc_rev;
    308  1.1  pk 	sc->sc_id = epd->sc_id;
    309  1.1  pk 
    310  1.1  pk 	/* If we could set NCRESPCFG3_FCLK earlier, we can really move */
    311  1.1  pk 	sc->sc_cfg3 = NCR_READ_REG(sc, NCR_ESPCFG3);
    312  1.1  pk 	if ((epd->sc_rev == NCR_VARIANT_FAS408) && epd->sc_isfast) {
    313  1.1  pk 		sc->sc_freq = 40;
    314  1.1  pk 		sc->sc_cfg3 |= NCRESPCFG3_FCLK;
    315  1.1  pk 	}
    316  1.1  pk 	else
    317  1.1  pk 		sc->sc_freq = 24;
    318  1.1  pk 
    319  1.1  pk 	/* Setup the register defaults */
    320  1.1  pk 	sc->sc_cfg1 = sc->sc_id;
    321  1.1  pk 	if (epd->sc_parity)
    322  1.1  pk 		sc->sc_cfg1 |= NCRCFG1_PARENB;
    323  1.1  pk 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    324  1.1  pk 	sc->sc_cfg3 |= NCRESPCFG3_IDM | NCRESPCFG3_FSCSI;
    325  1.1  pk 
    326  1.1  pk 	/*
    327  1.1  pk 	 * This is the value used to start sync negotiations
    328  1.1  pk 	 * Note that the NCR register "SYNCTP" is programmed
    329  1.1  pk 	 * in "clocks per byte", and has a minimum value of 4.
    330  1.1  pk 	 * The SCSI period used in negotiation is one-fourth
    331  1.1  pk 	 * of the time (in nanoseconds) needed to transfer one byte.
    332  1.1  pk 	 * Since the chip's clock is given in MHz, we have the following
    333  1.1  pk 	 * formula: 4 * period = (1000 / freq) * 4
    334  1.1  pk 	 */
    335  1.1  pk 	if (epd->sc_sync)
    336  1.1  pk 	{
    337  1.1  pk #ifdef DIAGNOSTIC
    338  1.1  pk 		printf("%s: sync requested, but not supported; will do async\n",
    339  1.1  pk 		    sc->sc_dev.dv_xname);
    340  1.1  pk #endif
    341  1.1  pk 		epd->sc_sync = 0;
    342  1.1  pk 	}
    343  1.1  pk 
    344  1.1  pk 	sc->sc_minsync = 0;
    345  1.1  pk 
    346  1.1  pk 	/* Really no limit, but since we want to fit into the TCR... */
    347  1.1  pk 	sc->sc_maxxfer = 64 * 1024;
    348  1.1  pk }
    349  1.1  pk 
    350  1.1  pk /*
    351  1.1  pk  * Check the slots looking for a board we recognise
    352  1.1  pk  * If we find one, note it's address (slot) and call
    353  1.1  pk  * the actual probe routine to check it out.
    354  1.1  pk  */
    355  1.1  pk int
    356  1.1  pk esp_isa_match(parent, match, aux)
    357  1.1  pk 	struct device *parent;
    358  1.1  pk 	void *match, *aux;
    359  1.1  pk {
    360  1.1  pk 	struct ncr53c9x_softc *sc = match;
    361  1.1  pk 	struct isa_attach_args *ia = aux;
    362  1.1  pk 	bus_space_tag_t iot = ia->ia_iot;
    363  1.1  pk 	bus_space_handle_t ioh;
    364  1.1  pk 	struct esp_probe_data epd;
    365  1.1  pk 	int rv;
    366  1.1  pk 
    367  1.1  pk 	ESP_TRACE(("[esp_isa_match] "));
    368  1.1  pk 
    369  1.1  pk 	if (ia->ia_iobase != 0x230 && ia->ia_iobase != 0x330) {
    370  1.1  pk #ifdef DIAGNOSTIC
    371  1.1  pk 		printf("%s: invalid iobase 0x%0x, device not configured\n",
    372  1.1  pk 		    sc->sc_dev.dv_xname, ia->ia_iobase);
    373  1.1  pk #endif
    374  1.1  pk 		return 0;
    375  1.1  pk 	}
    376  1.1  pk 
    377  1.1  pk 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh)) {
    378  1.1  pk #ifdef DIAGNOSTIC
    379  1.1  pk 		printf("%s: bus_space_map() failed!\n", sc->sc_dev.dv_xname);
    380  1.1  pk #endif
    381  1.1  pk 		return 0;
    382  1.1  pk 	}
    383  1.1  pk 
    384  1.1  pk 	epd.sc_dev = sc->sc_dev;
    385  1.1  pk 	rv = esp_find(iot, ioh, &epd);
    386  1.1  pk 
    387  1.1  pk 	bus_space_unmap(iot, ioh, ESP_ISA_IOSIZE);
    388  1.1  pk 
    389  1.1  pk 	if (rv) {
    390  1.1  pk 		if (ia->ia_irq != IRQUNK && ia->ia_irq != epd.sc_irq) {
    391  1.1  pk #ifdef DIAGNOSTIC
    392  1.1  pk 		printf("%s: configured IRQ (%0d) does not match board IRQ (%0d), device not configured\n",
    393  1.1  pk 		    sc->sc_dev.dv_xname, ia->ia_irq, epd.sc_irq);
    394  1.1  pk #endif
    395  1.1  pk 			return 0;
    396  1.1  pk 		}
    397  1.1  pk 		ia->ia_irq = epd.sc_irq;
    398  1.1  pk 		ia->ia_msize = 0;
    399  1.1  pk 		ia->ia_iosize = ESP_ISA_IOSIZE;
    400  1.1  pk 	}
    401  1.1  pk 	return (rv);
    402  1.1  pk }
    403  1.1  pk 
    404  1.1  pk /*
    405  1.1  pk  * Attach this instance, and then all the sub-devices
    406  1.1  pk  */
    407  1.1  pk void
    408  1.1  pk esp_isa_attach(parent, self, aux)
    409  1.1  pk 	struct device *parent, *self;
    410  1.1  pk 	void *aux;
    411  1.1  pk {
    412  1.1  pk 	struct isa_attach_args *ia = aux;
    413  1.1  pk 	struct esp_softc *esc = (void *)self;
    414  1.1  pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    415  1.1  pk 	bus_space_tag_t iot = ia->ia_iot;
    416  1.1  pk 	bus_space_handle_t ioh;
    417  1.1  pk 	struct esp_probe_data epd;
    418  1.1  pk 	isa_chipset_tag_t ic = ia->ia_ic;
    419  1.1  pk 
    420  1.1  pk 	printf("\n");
    421  1.1  pk 	ESP_TRACE(("[esp_isa_attach] "));
    422  1.1  pk 
    423  1.1  pk 	if (bus_space_map(iot, ia->ia_iobase, ESP_ISA_IOSIZE, 0, &ioh))
    424  1.1  pk 		panic("espattach: bus_space_map failed");
    425  1.1  pk 
    426  1.1  pk 	epd.sc_dev = sc->sc_dev;
    427  1.1  pk 	if (!esp_find(iot, ioh, &epd))
    428  1.1  pk 		panic("espattach: esp_find failed");
    429  1.1  pk 
    430  1.1  pk 	if (ia->ia_drq != DRQUNK)
    431  1.1  pk 		isa_dmacascade(ia->ia_drq);
    432  1.1  pk 
    433  1.1  pk 	esc->sc_ih = isa_intr_establish(ic, ia->ia_irq, IST_EDGE, IPL_BIO,
    434  1.1  pk 	    (int (*)(void *))ncr53c9x_intr, esc);
    435  1.1  pk 	if (esc->sc_ih == NULL) {
    436  1.1  pk 		printf("%s: couldn't establish interrupt\n",
    437  1.1  pk 		    sc->sc_dev.dv_xname);
    438  1.1  pk 		return;
    439  1.1  pk 	}
    440  1.1  pk 
    441  1.1  pk 	esp_init(esc, &epd);
    442  1.1  pk 
    443  1.1  pk 	esc->sc_ioh = ioh;
    444  1.1  pk 	esc->sc_iot = iot;
    445  1.1  pk 
    446  1.1  pk 	printf("%s:%ssync,%sparity\n", sc->sc_dev.dv_xname,
    447  1.1  pk 	    epd.sc_sync ? " " : " no ", epd.sc_parity ? " " : " no ");
    448  1.1  pk 	printf("%s", sc->sc_dev.dv_xname);
    449  1.1  pk 
    450  1.1  pk 	/*
    451  1.1  pk 	 * Now try to attach all the sub-devices
    452  1.1  pk 	 */
    453  1.1  pk 	ncr53c9x_attach(sc, &esp_switch, &esp_dev);
    454  1.1  pk }
    455  1.1  pk 
    456  1.1  pk /*
    457  1.1  pk  * Glue functions.
    458  1.1  pk  */
    459  1.1  pk u_char
    460  1.1  pk esp_read_reg(sc, reg)
    461  1.1  pk 	struct ncr53c9x_softc *sc;
    462  1.1  pk 	int reg;
    463  1.1  pk {
    464  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    465  1.1  pk 	u_char v;
    466  1.1  pk 
    467  1.1  pk 	v =  bus_space_read_1(esc->sc_iot, esc->sc_ioh, reg);
    468  1.1  pk 
    469  1.1  pk 	ESP_REGS(("[esp_read_reg CRS%c 0x%02x=0x%02x] ",
    470  1.1  pk 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    471  1.1  pk 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    472  1.1  pk 
    473  1.1  pk 	return v;
    474  1.1  pk }
    475  1.1  pk 
    476  1.1  pk void
    477  1.1  pk esp_write_reg(sc, reg, val)
    478  1.1  pk 	struct ncr53c9x_softc *sc;
    479  1.1  pk 	int reg;
    480  1.1  pk 	u_char val;
    481  1.1  pk {
    482  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    483  1.1  pk 	u_char v = val;
    484  1.1  pk 
    485  1.1  pk 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    486  1.1  pk 		v = NCRCMD_TRANS;
    487  1.1  pk 	}
    488  1.1  pk 
    489  1.1  pk 	ESP_REGS(("[esp_write_reg CRS%c 0x%02x=0x%02x] ",
    490  1.1  pk 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    491  1.1  pk 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    492  1.1  pk 
    493  1.1  pk 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, reg, v);
    494  1.1  pk }
    495  1.1  pk 
    496  1.1  pk int
    497  1.1  pk esp_dma_isintr(sc)
    498  1.1  pk 	struct ncr53c9x_softc *sc;
    499  1.1  pk {
    500  1.1  pk 	ESP_TRACE(("[esp_dma_isintr] "));
    501  1.1  pk 
    502  1.1  pk 	return NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT;
    503  1.1  pk }
    504  1.1  pk 
    505  1.1  pk void
    506  1.1  pk esp_dma_reset(sc)
    507  1.1  pk 	struct ncr53c9x_softc *sc;
    508  1.1  pk {
    509  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    510  1.1  pk 
    511  1.1  pk 	ESP_TRACE(("[esp_dma_reset] "));
    512  1.1  pk 
    513  1.1  pk 	esc->sc_active = 0;
    514  1.1  pk 	esc->sc_tc = 0;
    515  1.1  pk }
    516  1.1  pk 
    517  1.1  pk int
    518  1.1  pk esp_dma_intr(sc)
    519  1.1  pk 	struct ncr53c9x_softc *sc;
    520  1.1  pk {
    521  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    522  1.1  pk 	u_char	*p;
    523  1.1  pk 	u_int	espphase, espstat, espintr;
    524  1.1  pk 	int	cnt;
    525  1.1  pk 
    526  1.1  pk 	ESP_TRACE(("[esp_dma_intr] "));
    527  1.1  pk 
    528  1.1  pk 	if (esc->sc_active == 0) {
    529  1.1  pk 		printf("%s: dma_intr--inactive DMA\n", sc->sc_dev.dv_xname);
    530  1.1  pk 		return -1;
    531  1.1  pk 	}
    532  1.1  pk 
    533  1.1  pk 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    534  1.1  pk 		esc->sc_active = 0;
    535  1.1  pk 		return 0;
    536  1.1  pk 	}
    537  1.1  pk 
    538  1.1  pk 	cnt = *esc->sc_pdmalen;
    539  1.1  pk 	if (*esc->sc_pdmalen == 0) {
    540  1.1  pk 		printf("%s: data interrupt, but no count left\n",
    541  1.1  pk 		    sc->sc_dev.dv_xname);
    542  1.1  pk 	}
    543  1.1  pk 
    544  1.1  pk 	p = *esc->sc_dmaaddr;
    545  1.1  pk 	espphase = sc->sc_phase;
    546  1.1  pk 	espstat = (u_int) sc->sc_espstat;
    547  1.1  pk 	espintr = (u_int) sc->sc_espintr;
    548  1.1  pk 	do {
    549  1.1  pk 		if (esc->sc_datain) {
    550  1.1  pk 			*p++ = NCR_READ_REG(sc, NCR_FIFO);
    551  1.1  pk 			cnt--;
    552  1.1  pk 			if (espphase == DATA_IN_PHASE) {
    553  1.1  pk 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    554  1.1  pk 			} else {
    555  1.1  pk 				esc->sc_active = 0;
    556  1.1  pk 			}
    557  1.1  pk 	 	} else {
    558  1.1  pk 			if (   (espphase == DATA_OUT_PHASE)
    559  1.1  pk 			    || (espphase == MESSAGE_OUT_PHASE)) {
    560  1.1  pk 				NCR_WRITE_REG(sc, NCR_FIFO, *p++);
    561  1.1  pk 				cnt--;
    562  1.1  pk 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    563  1.1  pk 			} else {
    564  1.1  pk 				esc->sc_active = 0;
    565  1.1  pk 			}
    566  1.1  pk 		}
    567  1.1  pk 
    568  1.1  pk 		if (esc->sc_active) {
    569  1.1  pk 			while (!(NCR_READ_REG(sc, NCR_STAT) & 0x80));
    570  1.1  pk 			espstat = NCR_READ_REG(sc, NCR_STAT);
    571  1.1  pk 			espintr = NCR_READ_REG(sc, NCR_INTR);
    572  1.1  pk 			espphase = (espintr & NCRINTR_DIS)
    573  1.1  pk 				    ? /* Disconnected */ BUSFREE_PHASE
    574  1.1  pk 				    : espstat & PHASE_MASK;
    575  1.1  pk 		}
    576  1.1  pk 	} while (esc->sc_active && espintr);
    577  1.1  pk 	sc->sc_phase = espphase;
    578  1.1  pk 	sc->sc_espstat = (u_char) espstat;
    579  1.1  pk 	sc->sc_espintr = (u_char) espintr;
    580  1.1  pk 	*esc->sc_dmaaddr = p;
    581  1.1  pk 	*esc->sc_pdmalen = cnt;
    582  1.1  pk 
    583  1.1  pk 	if (*esc->sc_pdmalen == 0) {
    584  1.1  pk 		esc->sc_tc = NCRSTAT_TC;
    585  1.1  pk 	}
    586  1.1  pk 	sc->sc_espstat |= esc->sc_tc;
    587  1.1  pk 	return 0;
    588  1.1  pk }
    589  1.1  pk 
    590  1.1  pk int
    591  1.1  pk esp_dma_setup(sc, addr, len, datain, dmasize)
    592  1.1  pk 	struct ncr53c9x_softc *sc;
    593  1.1  pk 	caddr_t *addr;
    594  1.1  pk 	size_t *len;
    595  1.1  pk 	int datain;
    596  1.1  pk 	size_t *dmasize;
    597  1.1  pk {
    598  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    599  1.1  pk 
    600  1.1  pk 	ESP_TRACE(("[esp_dma_setup] "));
    601  1.1  pk 
    602  1.1  pk 	esc->sc_dmaaddr = addr;
    603  1.1  pk 	esc->sc_pdmalen = len;
    604  1.1  pk 	esc->sc_datain = datain;
    605  1.1  pk 	esc->sc_dmasize = *dmasize;
    606  1.1  pk 	esc->sc_tc = 0;
    607  1.1  pk 
    608  1.1  pk 	return 0;
    609  1.1  pk }
    610  1.1  pk 
    611  1.1  pk void
    612  1.1  pk esp_dma_go(sc)
    613  1.1  pk 	struct ncr53c9x_softc *sc;
    614  1.1  pk {
    615  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    616  1.1  pk 
    617  1.1  pk 	ESP_TRACE(("[esp_dma_go] "));
    618  1.1  pk 
    619  1.1  pk 	esc->sc_active = 1;
    620  1.1  pk }
    621  1.1  pk 
    622  1.1  pk void
    623  1.1  pk esp_dma_stop(sc)
    624  1.1  pk 	struct ncr53c9x_softc *sc;
    625  1.1  pk {
    626  1.1  pk 	ESP_TRACE(("[esp_dma_stop] "));
    627  1.1  pk }
    628  1.1  pk 
    629  1.1  pk int
    630  1.1  pk esp_dma_isactive(sc)
    631  1.1  pk 	struct ncr53c9x_softc *sc;
    632  1.1  pk {
    633  1.1  pk 	struct esp_softc *esc = (struct esp_softc *)sc;
    634  1.1  pk 
    635  1.1  pk 	ESP_TRACE(("[esp_dma_isactive] "));
    636  1.1  pk 
    637  1.1  pk 	return esc->sc_active;
    638  1.1  pk }
    639