Home | History | Annotate | Line # | Download | only in isa
esp_isa.c revision 1.33.16.1
      1  1.33.16.1       mjf /*	$NetBSD: esp_isa.c,v 1.33.16.1 2008/06/02 13:23:30 mjf Exp $	*/
      2        1.2   thorpej 
      3        1.5   thorpej /*-
      4       1.12   mycroft  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5        1.1        pk  * All rights reserved.
      6        1.1        pk  *
      7        1.5   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.13   mycroft  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
      9       1.13   mycroft  * Simulation Facility, NASA Ames Research Center.
     10        1.5   thorpej  *
     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  *
     20        1.5   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21        1.5   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22        1.5   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23        1.5   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24        1.5   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25        1.5   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26        1.5   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27        1.5   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28        1.5   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29        1.5   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30        1.5   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31        1.1        pk  */
     32        1.1        pk 
     33        1.1        pk /*
     34        1.1        pk  * Copyright (c) 1994 Peter Galbavy
     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 /*
     79        1.1        pk  * Copyright (c) 1997 Eric S. Hvozda (hvozda (at) netcom.com)
     80        1.1        pk  * All rights reserved.
     81        1.1        pk  *
     82        1.1        pk  * Redistribution and use in source and binary forms, with or without
     83        1.1        pk  * modification, are permitted provided that the following conditions
     84        1.1        pk  * are met:
     85        1.1        pk  * 1. Redistributions of source code must retain the above copyright
     86        1.1        pk  *    notice, this list of conditions and the following disclaimer.
     87        1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     88        1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     89        1.1        pk  *    documentation and/or other materials provided with the distribution.
     90        1.1        pk  * 3. All advertising materials mentioning features or use of this software
     91        1.1        pk  *    must display the following acknowledgement:
     92        1.1        pk  *      This product includes software developed by Eric S. Hvozda.
     93        1.1        pk  * 4. The name of Eric S. Hvozda may not be used to endorse or promote products
     94        1.1        pk  *    derived from this software without specific prior written permission.
     95        1.1        pk  *
     96        1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     97        1.1        pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     98        1.1        pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     99        1.1        pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    100        1.1        pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    101        1.1        pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    102        1.1        pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    103        1.1        pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    104        1.1        pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    105        1.1        pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    106        1.1        pk  */
    107       1.23     lukem 
    108       1.23     lukem #include <sys/cdefs.h>
    109  1.33.16.1       mjf __KERNEL_RCSID(0, "$NetBSD: esp_isa.c,v 1.33.16.1 2008/06/02 13:23:30 mjf Exp $");
    110        1.1        pk 
    111        1.1        pk #include <sys/param.h>
    112        1.1        pk #include <sys/systm.h>
    113        1.1        pk #include <sys/device.h>
    114        1.1        pk #include <sys/buf.h>
    115        1.1        pk 
    116       1.33        ad #include <sys/bus.h>
    117       1.33        ad #include <sys/intr.h>
    118        1.1        pk 
    119       1.22    bouyer #include <dev/scsipi/scsipi_all.h>
    120        1.4    bouyer #include <dev/scsipi/scsi_all.h>
    121        1.4    bouyer #include <dev/scsipi/scsiconf.h>
    122        1.1        pk 
    123        1.1        pk #include <dev/isa/isavar.h>
    124        1.1        pk #include <dev/isa/isadmavar.h>
    125        1.1        pk 
    126        1.1        pk #include <dev/ic/ncr53c9xreg.h>
    127        1.1        pk #include <dev/ic/ncr53c9xvar.h>
    128        1.1        pk 
    129       1.18   mycroft #include <dev/isa/esp_isavar.h>
    130        1.1        pk 
    131  1.33.16.1       mjf int	esp_isa_match(device_t, cfdata_t, void *);
    132  1.33.16.1       mjf void	esp_isa_attach(device_t, device_t, void *);
    133        1.1        pk 
    134  1.33.16.1       mjf CFATTACH_DECL_NEW(esp_isa, sizeof(struct esp_isa_softc),
    135       1.27   thorpej     esp_isa_match, esp_isa_attach, NULL, NULL);
    136        1.1        pk 
    137       1.17   mycroft int esp_isa_debug = 0;	/* ESP_SHOWTRAC | ESP_SHOWREGS | ESP_SHOWMISC */
    138        1.1        pk 
    139        1.1        pk /*
    140        1.1        pk  * Functions and the switch for the MI code.
    141        1.1        pk  */
    142  1.33.16.1       mjf uint8_t	esp_isa_read_reg(struct ncr53c9x_softc *, int);
    143  1.33.16.1       mjf void	esp_isa_write_reg(struct ncr53c9x_softc *, int, uint8_t);
    144       1.29     perry int	esp_isa_dma_isintr(struct ncr53c9x_softc *);
    145       1.29     perry void	esp_isa_dma_reset(struct ncr53c9x_softc *);
    146       1.29     perry int	esp_isa_dma_intr(struct ncr53c9x_softc *);
    147  1.33.16.1       mjf int	esp_isa_dma_setup(struct ncr53c9x_softc *, uint8_t **,
    148       1.29     perry 	    size_t *, int, size_t *);
    149       1.29     perry void	esp_isa_dma_go(struct ncr53c9x_softc *);
    150       1.29     perry void	esp_isa_dma_stop(struct ncr53c9x_softc *);
    151       1.29     perry int	esp_isa_dma_isactive(struct ncr53c9x_softc *);
    152       1.17   mycroft 
    153       1.17   mycroft struct ncr53c9x_glue esp_isa_glue = {
    154       1.17   mycroft 	esp_isa_read_reg,
    155       1.17   mycroft 	esp_isa_write_reg,
    156       1.17   mycroft 	esp_isa_dma_isintr,
    157       1.17   mycroft 	esp_isa_dma_reset,
    158       1.17   mycroft 	esp_isa_dma_intr,
    159       1.17   mycroft 	esp_isa_dma_setup,
    160       1.17   mycroft 	esp_isa_dma_go,
    161       1.17   mycroft 	esp_isa_dma_stop,
    162       1.17   mycroft 	esp_isa_dma_isactive,
    163        1.1        pk 	NULL,			/* gl_clear_latched_intr */
    164        1.1        pk };
    165        1.1        pk 
    166        1.1        pk /*
    167        1.1        pk  * Look for the board
    168        1.1        pk  */
    169        1.1        pk int
    170  1.33.16.1       mjf esp_isa_find(bus_space_tag_t iot, bus_space_handle_t ioh,
    171  1.33.16.1       mjf     struct esp_isa_probe_data *epd)
    172        1.1        pk {
    173        1.1        pk 	u_int vers;
    174        1.1        pk 	u_int p1;
    175        1.1        pk 	u_int p2;
    176        1.1        pk 	u_int jmp;
    177        1.1        pk 
    178       1.17   mycroft 	ESP_TRACE(("[esp_isa_find] "));
    179        1.1        pk 
    180        1.1        pk 	/* reset card before we probe? */
    181        1.1        pk 
    182       1.19   mycroft 	epd->sc_cfg4 = NCRCFG4_ACTNEG;
    183       1.19   mycroft 	epd->sc_cfg5 = NCRCFG5_CRS1 | NCRCFG5_AADDR | NCRCFG5_PTRINC;
    184       1.19   mycroft 
    185        1.1        pk 	/*
    186        1.1        pk 	 * Switch to the PIO regs and look for the bit pattern
    187        1.1        pk 	 * we expect...
    188        1.1        pk 	 */
    189       1.19   mycroft 	bus_space_write_1(iot, ioh, NCR_CFG5, epd->sc_cfg5);
    190        1.1        pk 
    191        1.1        pk #define SIG_MASK 0x87
    192        1.1        pk #define REV_MASK 0x70
    193        1.1        pk #define	M1	 0x02
    194        1.1        pk #define	M2	 0x05
    195        1.1        pk #define ISNCR	 0x80
    196        1.1        pk #define ISESP406 0x40
    197        1.1        pk 
    198        1.1        pk 	vers = bus_space_read_1(iot, ioh, NCR_SIGNTR);
    199        1.1        pk 	p1 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    200        1.1        pk 	p2 = bus_space_read_1(iot, ioh, NCR_SIGNTR) & SIG_MASK;
    201        1.1        pk 
    202       1.17   mycroft 	ESP_MISC(("esp_isa_find: 0x%0x 0x%0x 0x%0x\n", vers, p1, p2));
    203        1.1        pk 
    204        1.1        pk 	if (!((p1 == M1 && p2 == M2) || (p1 == M2 && p2 == M1)))
    205        1.1        pk 		return 0;
    206        1.1        pk 
    207        1.1        pk 	/* Ok, what is it? */
    208        1.1        pk 	epd->sc_isncr = (vers & ISNCR);
    209        1.1        pk 	epd->sc_rev = ((vers & REV_MASK) == ISESP406) ?
    210        1.1        pk 	    NCR_VARIANT_ESP406 : NCR_VARIANT_FAS408;
    211        1.1        pk 
    212        1.1        pk 	/* What do the jumpers tell us? */
    213        1.1        pk 	jmp = bus_space_read_1(iot, ioh, NCR_JMP);
    214        1.1        pk 
    215        1.1        pk 	epd->sc_msize = (jmp & NCRJMP_ROMSZ) ? 0x4000 : 0x8000;
    216        1.1        pk 	epd->sc_parity = jmp & NCRJMP_J2;
    217        1.1        pk 	epd->sc_sync = jmp & NCRJMP_J4;
    218        1.1        pk 	epd->sc_id = (jmp & NCRJMP_J3) ? 7 : 6;
    219        1.1        pk 	switch (jmp & (NCRJMP_J0 | NCRJMP_J1)) {
    220        1.1        pk 		case NCRJMP_J0 | NCRJMP_J1:
    221        1.1        pk 			epd->sc_irq = 11;
    222        1.1        pk 			break;
    223        1.1        pk 		case NCRJMP_J0:
    224        1.1        pk 			epd->sc_irq = 10;
    225        1.1        pk 			break;
    226        1.1        pk 		case NCRJMP_J1:
    227        1.1        pk 			epd->sc_irq = 15;
    228        1.1        pk 			break;
    229        1.1        pk 		default:
    230        1.1        pk 			epd->sc_irq = 12;
    231        1.1        pk 			break;
    232        1.1        pk 	}
    233        1.1        pk 
    234       1.19   mycroft 	bus_space_write_1(iot, ioh, NCR_CFG5, epd->sc_cfg5);
    235        1.1        pk 
    236        1.1        pk 	/* Try to set NCRESPCFG3_FCLK, some FAS408's don't support
    237        1.1        pk 	 * NCRESPCFG3_FCLK even though it is documented.  A bad
    238        1.1        pk 	 * batch of chips perhaps?
    239        1.1        pk 	 */
    240        1.1        pk 	bus_space_write_1(iot, ioh, NCR_ESPCFG3,
    241        1.1        pk 	    bus_space_read_1(iot, ioh, NCR_ESPCFG3) | NCRESPCFG3_FCLK);
    242        1.1        pk 	epd->sc_isfast = bus_space_read_1(iot, ioh, NCR_ESPCFG3)
    243        1.1        pk 	    & NCRESPCFG3_FCLK;
    244        1.1        pk 
    245        1.1        pk 	return 1;
    246        1.1        pk }
    247        1.1        pk 
    248        1.1        pk void
    249  1.33.16.1       mjf esp_isa_init(struct esp_isa_softc *esc, struct esp_isa_probe_data *epd)
    250        1.1        pk {
    251        1.1        pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    252        1.1        pk 
    253       1.17   mycroft 	ESP_TRACE(("[esp_isa_init] "));
    254        1.1        pk 
    255        1.1        pk 	/*
    256        1.1        pk 	 * Set up the glue for MI code early; we use some of it here.
    257        1.1        pk 	 */
    258       1.17   mycroft 	sc->sc_glue = &esp_isa_glue;
    259        1.1        pk 
    260        1.1        pk 	sc->sc_rev = epd->sc_rev;
    261        1.1        pk 	sc->sc_id = epd->sc_id;
    262        1.1        pk 
    263        1.1        pk 	/* If we could set NCRESPCFG3_FCLK earlier, we can really move */
    264        1.1        pk 	sc->sc_cfg3 = NCR_READ_REG(sc, NCR_ESPCFG3);
    265        1.1        pk 	if ((epd->sc_rev == NCR_VARIANT_FAS408) && epd->sc_isfast) {
    266        1.1        pk 		sc->sc_freq = 40;
    267        1.1        pk 		sc->sc_cfg3 |= NCRESPCFG3_FCLK;
    268       1.19   mycroft 	} else
    269        1.1        pk 		sc->sc_freq = 24;
    270        1.1        pk 
    271        1.1        pk 	/* Setup the register defaults */
    272        1.1        pk 	sc->sc_cfg1 = sc->sc_id;
    273        1.1        pk 	if (epd->sc_parity)
    274        1.1        pk 		sc->sc_cfg1 |= NCRCFG1_PARENB;
    275        1.1        pk 	sc->sc_cfg2 = NCRCFG2_SCSI2;
    276        1.1        pk 	sc->sc_cfg3 |= NCRESPCFG3_IDM | NCRESPCFG3_FSCSI;
    277       1.19   mycroft 	sc->sc_cfg4 = epd->sc_cfg4;
    278       1.19   mycroft 	sc->sc_cfg5 = epd->sc_cfg5;
    279        1.1        pk 
    280        1.1        pk 	/*
    281        1.1        pk 	 * This is the value used to start sync negotiations
    282        1.1        pk 	 * Note that the NCR register "SYNCTP" is programmed
    283        1.1        pk 	 * in "clocks per byte", and has a minimum value of 4.
    284        1.1        pk 	 * The SCSI period used in negotiation is one-fourth
    285        1.1        pk 	 * of the time (in nanoseconds) needed to transfer one byte.
    286        1.1        pk 	 * Since the chip's clock is given in MHz, we have the following
    287        1.1        pk 	 * formula: 4 * period = (1000 / freq) * 4
    288        1.1        pk 	 */
    289  1.33.16.1       mjf 	if (epd->sc_sync) {
    290        1.1        pk #ifdef DIAGNOSTIC
    291  1.33.16.1       mjf 		aprint_normal_dev(sc->sc_dev,
    292  1.33.16.1       mjf 		    "sync requested, but not supported; will do async\n");
    293        1.1        pk #endif
    294        1.1        pk 		epd->sc_sync = 0;
    295        1.1        pk 	}
    296        1.1        pk 
    297        1.1        pk 	sc->sc_minsync = 0;
    298        1.1        pk 
    299        1.1        pk 	/* Really no limit, but since we want to fit into the TCR... */
    300        1.1        pk 	sc->sc_maxxfer = 64 * 1024;
    301        1.1        pk }
    302        1.1        pk 
    303        1.1        pk /*
    304        1.1        pk  * Check the slots looking for a board we recognise
    305        1.1        pk  * If we find one, note it's address (slot) and call
    306        1.1        pk  * the actual probe routine to check it out.
    307        1.1        pk  */
    308        1.1        pk int
    309  1.33.16.1       mjf esp_isa_match(device_t parent, cfdata_t cf, void *aux)
    310        1.1        pk {
    311        1.1        pk 	struct isa_attach_args *ia = aux;
    312        1.1        pk 	bus_space_tag_t iot = ia->ia_iot;
    313        1.1        pk 	bus_space_handle_t ioh;
    314       1.17   mycroft 	struct esp_isa_probe_data epd;
    315        1.1        pk 	int rv;
    316        1.1        pk 
    317       1.24  christos 	if (ia->ia_nio < 1)
    318  1.33.16.1       mjf 		return 0;
    319       1.24  christos 	if (ia->ia_nirq < 1)
    320  1.33.16.1       mjf 		return 0;
    321       1.24  christos 	if (ia->ia_ndrq < 1)
    322  1.33.16.1       mjf 		return 0;
    323       1.24  christos 
    324       1.24  christos 	if (ISA_DIRECT_CONFIG(ia))
    325  1.33.16.1       mjf 		return 0;
    326       1.24  christos 
    327        1.1        pk 	ESP_TRACE(("[esp_isa_match] "));
    328        1.1        pk 
    329       1.28  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    330        1.1        pk 		return 0;
    331        1.1        pk 
    332       1.24  christos 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, ESP_ISA_IOSIZE, 0, &ioh))
    333        1.1        pk 		return 0;
    334        1.1        pk 
    335       1.17   mycroft 	rv = esp_isa_find(iot, ioh, &epd);
    336        1.1        pk 
    337        1.1        pk 	bus_space_unmap(iot, ioh, ESP_ISA_IOSIZE);
    338        1.1        pk 
    339        1.1        pk 	if (rv) {
    340       1.28  drochner 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
    341       1.24  christos 		    ia->ia_irq[0].ir_irq != epd.sc_irq) {
    342        1.1        pk #ifdef DIAGNOSTIC
    343  1.33.16.1       mjf 		printf("%s: configured IRQ (%0d) does not "
    344  1.33.16.1       mjf 		    "match board IRQ (%0d), device not configured\n",
    345  1.33.16.1       mjf 		    __func__, ia->ia_irq[0].ir_irq, epd.sc_irq);
    346        1.1        pk #endif
    347        1.1        pk 			return 0;
    348        1.1        pk 		}
    349       1.24  christos 		ia->ia_irq[0].ir_irq = epd.sc_irq;
    350       1.24  christos 		ia->ia_iomem[0].ir_size = 0;
    351       1.24  christos 		ia->ia_io[0].ir_size = ESP_ISA_IOSIZE;
    352        1.1        pk 	}
    353  1.33.16.1       mjf 	return rv;
    354        1.1        pk }
    355        1.1        pk 
    356        1.1        pk /*
    357        1.1        pk  * Attach this instance, and then all the sub-devices
    358        1.1        pk  */
    359        1.1        pk void
    360  1.33.16.1       mjf esp_isa_attach(device_t parent, device_t self, void *aux)
    361        1.1        pk {
    362  1.33.16.1       mjf 	struct esp_isa_softc *esc = device_private(self);
    363        1.1        pk 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
    364  1.33.16.1       mjf 	struct isa_attach_args *ia = aux;
    365        1.1        pk 	bus_space_tag_t iot = ia->ia_iot;
    366        1.1        pk 	bus_space_handle_t ioh;
    367       1.17   mycroft 	struct esp_isa_probe_data epd;
    368        1.1        pk 	isa_chipset_tag_t ic = ia->ia_ic;
    369       1.11   thorpej 	int error;
    370        1.1        pk 
    371  1.33.16.1       mjf 	sc->sc_dev = self;
    372  1.33.16.1       mjf 	aprint_normal("\n");
    373        1.1        pk 	ESP_TRACE(("[esp_isa_attach] "));
    374        1.1        pk 
    375       1.24  christos 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, ESP_ISA_IOSIZE, 0, &ioh)) {
    376  1.33.16.1       mjf 		aprint_error_dev(self, "can't map i/o space\n");
    377        1.6   thorpej 		return;
    378        1.6   thorpej 	}
    379        1.1        pk 
    380       1.17   mycroft 	if (!esp_isa_find(iot, ioh, &epd)) {
    381  1.33.16.1       mjf 		aprint_error_dev(self, "esp_isa_find failed\n");
    382        1.6   thorpej 		return;
    383        1.6   thorpej 	}
    384        1.1        pk 
    385       1.28  drochner 	if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ) {
    386       1.24  christos 		if ((error = isa_dmacascade(ic, ia->ia_drq[0].ir_drq)) != 0) {
    387  1.33.16.1       mjf 			aprint_error_dev(self,
    388  1.33.16.1       mjf 			    "unable to cascade DRQ, error = %d\n", error);
    389       1.11   thorpej 			return;
    390       1.11   thorpej 		}
    391       1.11   thorpej 	}
    392        1.1        pk 
    393       1.24  christos 	esc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
    394       1.24  christos 	    IPL_BIO, ncr53c9x_intr, esc);
    395        1.1        pk 	if (esc->sc_ih == NULL) {
    396  1.33.16.1       mjf 		aprint_error_dev(self, "couldn't establish interrupt\n");
    397        1.1        pk 		return;
    398        1.1        pk 	}
    399        1.1        pk 
    400        1.1        pk 	esc->sc_ioh = ioh;
    401        1.1        pk 	esc->sc_iot = iot;
    402       1.17   mycroft 	esp_isa_init(esc, &epd);
    403        1.1        pk 
    404  1.33.16.1       mjf 	aprint_normal_dev(self, "%ssync,%sparity\n",
    405        1.1        pk 	    epd.sc_sync ? " " : " no ", epd.sc_parity ? " " : " no ");
    406  1.33.16.1       mjf 	aprint_normal("%s", device_xname(self));
    407        1.1        pk 
    408        1.1        pk 	/*
    409        1.1        pk 	 * Now try to attach all the sub-devices
    410        1.1        pk 	 */
    411       1.22    bouyer 	sc->sc_adapter.adapt_minphys = minphys;
    412       1.22    bouyer 	sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
    413       1.22    bouyer 	ncr53c9x_attach(sc);
    414        1.1        pk }
    415        1.1        pk 
    416        1.1        pk /*
    417        1.1        pk  * Glue functions.
    418        1.1        pk  */
    419  1.33.16.1       mjf uint8_t
    420  1.33.16.1       mjf esp_isa_read_reg(struct ncr53c9x_softc *sc, int reg)
    421        1.1        pk {
    422       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    423  1.33.16.1       mjf 	uint8_t v;
    424        1.1        pk 
    425        1.1        pk 	v =  bus_space_read_1(esc->sc_iot, esc->sc_ioh, reg);
    426        1.1        pk 
    427       1.17   mycroft 	ESP_REGS(("[esp_isa_read_reg CRS%c 0x%02x=0x%02x] ",
    428        1.1        pk 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    429        1.1        pk 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    430        1.1        pk 
    431        1.1        pk 	return v;
    432        1.1        pk }
    433        1.1        pk 
    434        1.1        pk void
    435  1.33.16.1       mjf esp_isa_write_reg(struct ncr53c9x_softc *sc, int reg, uint8_t val)
    436        1.1        pk {
    437       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    438  1.33.16.1       mjf 	uint8_t v = val;
    439        1.1        pk 
    440        1.1        pk 	if (reg == NCR_CMD && v == (NCRCMD_TRANS|NCRCMD_DMA)) {
    441        1.1        pk 		v = NCRCMD_TRANS;
    442        1.1        pk 	}
    443        1.1        pk 
    444       1.17   mycroft 	ESP_REGS(("[esp_isa_write_reg CRS%c 0x%02x=0x%02x] ",
    445        1.1        pk 	    (bus_space_read_1(esc->sc_iot, esc->sc_ioh, NCR_CFG4) &
    446        1.1        pk 	    NCRCFG4_CRS1) ? '1' : '0', reg, v));
    447        1.1        pk 
    448        1.1        pk 	bus_space_write_1(esc->sc_iot, esc->sc_ioh, reg, v);
    449        1.1        pk }
    450        1.1        pk 
    451        1.1        pk int
    452  1.33.16.1       mjf esp_isa_dma_isintr(struct ncr53c9x_softc *sc)
    453        1.1        pk {
    454  1.33.16.1       mjf 
    455       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_isintr] "));
    456        1.1        pk 
    457        1.1        pk 	return NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT;
    458        1.1        pk }
    459        1.1        pk 
    460        1.1        pk void
    461  1.33.16.1       mjf esp_isa_dma_reset(struct ncr53c9x_softc *sc)
    462        1.1        pk {
    463       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    464        1.1        pk 
    465       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_reset] "));
    466        1.1        pk 
    467        1.1        pk 	esc->sc_active = 0;
    468        1.1        pk 	esc->sc_tc = 0;
    469        1.1        pk }
    470        1.1        pk 
    471        1.1        pk int
    472  1.33.16.1       mjf esp_isa_dma_intr(struct ncr53c9x_softc *sc)
    473        1.1        pk {
    474       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    475  1.33.16.1       mjf 	uint8_t*p;
    476        1.1        pk 	u_int	espphase, espstat, espintr;
    477        1.1        pk 	int	cnt;
    478        1.1        pk 
    479       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_intr] "));
    480        1.1        pk 
    481        1.1        pk 	if (esc->sc_active == 0) {
    482  1.33.16.1       mjf 		printf("%s: dma_intr--inactive DMA\n",
    483  1.33.16.1       mjf 		    device_xname(sc->sc_dev));
    484        1.1        pk 		return -1;
    485        1.1        pk 	}
    486        1.1        pk 
    487        1.1        pk 	if ((sc->sc_espintr & NCRINTR_BS) == 0) {
    488        1.1        pk 		esc->sc_active = 0;
    489        1.1        pk 		return 0;
    490        1.1        pk 	}
    491        1.1        pk 
    492        1.1        pk 	cnt = *esc->sc_pdmalen;
    493        1.1        pk 	if (*esc->sc_pdmalen == 0) {
    494        1.1        pk 		printf("%s: data interrupt, but no count left\n",
    495  1.33.16.1       mjf 		    device_xname(sc->sc_dev));
    496        1.1        pk 	}
    497        1.1        pk 
    498        1.1        pk 	p = *esc->sc_dmaaddr;
    499        1.1        pk 	espphase = sc->sc_phase;
    500  1.33.16.1       mjf 	espstat = (u_int)sc->sc_espstat;
    501  1.33.16.1       mjf 	espintr = (u_int)sc->sc_espintr;
    502        1.1        pk 	do {
    503        1.1        pk 		if (esc->sc_datain) {
    504        1.1        pk 			*p++ = NCR_READ_REG(sc, NCR_FIFO);
    505        1.1        pk 			cnt--;
    506        1.1        pk 			if (espphase == DATA_IN_PHASE) {
    507        1.1        pk 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    508        1.1        pk 			} else {
    509        1.1        pk 				esc->sc_active = 0;
    510        1.1        pk 			}
    511        1.1        pk 	 	} else {
    512  1.33.16.1       mjf 			if ((espphase == DATA_OUT_PHASE) ||
    513  1.33.16.1       mjf 			    (espphase == MESSAGE_OUT_PHASE)) {
    514        1.1        pk 				NCR_WRITE_REG(sc, NCR_FIFO, *p++);
    515        1.1        pk 				cnt--;
    516        1.1        pk 				NCR_WRITE_REG(sc, NCR_CMD, NCRCMD_TRANS);
    517        1.1        pk 			} else {
    518        1.1        pk 				esc->sc_active = 0;
    519        1.1        pk 			}
    520        1.1        pk 		}
    521        1.1        pk 
    522        1.1        pk 		if (esc->sc_active) {
    523  1.33.16.1       mjf 			while ((NCR_READ_REG(sc, NCR_STAT) & NCRSTAT_INT) == 0)
    524  1.33.16.1       mjf 				;
    525        1.1        pk 			espstat = NCR_READ_REG(sc, NCR_STAT);
    526        1.1        pk 			espintr = NCR_READ_REG(sc, NCR_INTR);
    527  1.33.16.1       mjf 			espphase = (espintr & NCRINTR_DIS) ?
    528  1.33.16.1       mjf 			    /* Disconnected */ BUSFREE_PHASE :
    529  1.33.16.1       mjf 			    espstat & PHASE_MASK;
    530        1.1        pk 		}
    531        1.1        pk 	} while (esc->sc_active && espintr);
    532        1.1        pk 	sc->sc_phase = espphase;
    533  1.33.16.1       mjf 	sc->sc_espstat = (uint8_t)espstat;
    534  1.33.16.1       mjf 	sc->sc_espintr = (uint8_t)espintr;
    535        1.1        pk 	*esc->sc_dmaaddr = p;
    536        1.1        pk 	*esc->sc_pdmalen = cnt;
    537        1.1        pk 
    538        1.1        pk 	if (*esc->sc_pdmalen == 0) {
    539        1.1        pk 		esc->sc_tc = NCRSTAT_TC;
    540        1.1        pk 	}
    541        1.1        pk 	sc->sc_espstat |= esc->sc_tc;
    542        1.1        pk 	return 0;
    543        1.1        pk }
    544        1.1        pk 
    545        1.1        pk int
    546  1.33.16.1       mjf esp_isa_dma_setup(struct ncr53c9x_softc *sc, uint8_t **addr, size_t *len,
    547  1.33.16.1       mjf     int datain, size_t *dmasize)
    548        1.1        pk {
    549       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    550        1.1        pk 
    551       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_setup] "));
    552        1.1        pk 
    553        1.1        pk 	esc->sc_dmaaddr = addr;
    554        1.1        pk 	esc->sc_pdmalen = len;
    555        1.1        pk 	esc->sc_datain = datain;
    556        1.1        pk 	esc->sc_dmasize = *dmasize;
    557        1.1        pk 	esc->sc_tc = 0;
    558        1.1        pk 
    559        1.1        pk 	return 0;
    560        1.1        pk }
    561        1.1        pk 
    562        1.1        pk void
    563  1.33.16.1       mjf esp_isa_dma_go(struct ncr53c9x_softc *sc)
    564        1.1        pk {
    565       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    566        1.1        pk 
    567       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_go] "));
    568        1.1        pk 
    569        1.1        pk 	esc->sc_active = 1;
    570        1.1        pk }
    571        1.1        pk 
    572        1.1        pk void
    573  1.33.16.1       mjf esp_isa_dma_stop(struct ncr53c9x_softc *sc)
    574        1.1        pk {
    575       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_stop] "));
    576        1.1        pk }
    577        1.1        pk 
    578        1.1        pk int
    579  1.33.16.1       mjf esp_isa_dma_isactive(struct ncr53c9x_softc *sc)
    580        1.1        pk {
    581       1.17   mycroft 	struct esp_isa_softc *esc = (struct esp_isa_softc *)sc;
    582        1.1        pk 
    583       1.17   mycroft 	ESP_TRACE(("[esp_isa_dma_isactive] "));
    584        1.1        pk 
    585        1.1        pk 	return esc->sc_active;
    586        1.1        pk }
    587