bha_isa.c revision 1.17
1/* $NetBSD: bha_isa.c,v 1.17 2001/04/25 17:53:35 bouyer Exp $ */ 2 3/*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/types.h> 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/device.h> 43 44#include <machine/bus.h> 45#include <machine/intr.h> 46 47#include <dev/scsipi/scsipi_all.h> 48#include <dev/scsipi/scsiconf.h> 49 50#include <dev/isa/isavar.h> 51#include <dev/isa/isadmavar.h> 52 53#include <dev/ic/bhareg.h> 54#include <dev/ic/bhavar.h> 55 56#define BHA_ISA_IOSIZE 4 57 58int bha_isa_probe __P((struct device *, struct cfdata *, void *)); 59void bha_isa_attach __P((struct device *, struct device *, void *)); 60 61struct cfattach bha_isa_ca = { 62 sizeof(struct bha_softc), bha_isa_probe, bha_isa_attach 63}; 64 65/* 66 * Check the slots looking for a board we recognise 67 * If we find one, note it's address (slot) and call 68 * the actual probe routine to check it out. 69 */ 70int 71bha_isa_probe(parent, match, aux) 72 struct device *parent; 73 struct cfdata *match; 74 void *aux; 75{ 76 struct isa_attach_args *ia = aux; 77 bus_space_tag_t iot = ia->ia_iot; 78 bus_space_handle_t ioh; 79 struct bha_probe_data bpd; 80 int rv; 81 82 /* Disallow wildcarded i/o address. */ 83 if (ia->ia_iobase == ISACF_PORT_DEFAULT) 84 return (0); 85 86 if (bus_space_map(iot, ia->ia_iobase, BHA_ISA_IOSIZE, 0, &ioh)) 87 return (0); 88 89 rv = bha_find(iot, ioh, &bpd); 90 91 bus_space_unmap(iot, ioh, BHA_ISA_IOSIZE); 92 93 if (rv) { 94 if (ia->ia_irq != -1 && ia->ia_irq != bpd.sc_irq) 95 return (0); 96 if (ia->ia_drq != -1 && ia->ia_drq != bpd.sc_drq) 97 return (0); 98 ia->ia_irq = bpd.sc_irq; 99 ia->ia_drq = bpd.sc_drq; 100 ia->ia_msize = 0; 101 ia->ia_iosize = BHA_ISA_IOSIZE; 102 } 103 return (rv); 104} 105 106/* 107 * Attach all the sub-devices we can find 108 */ 109void 110bha_isa_attach(parent, self, aux) 111 struct device *parent, *self; 112 void *aux; 113{ 114 struct isa_attach_args *ia = aux; 115 struct bha_softc *sc = (void *)self; 116 bus_space_tag_t iot = ia->ia_iot; 117 bus_space_handle_t ioh; 118 struct bha_probe_data bpd; 119 isa_chipset_tag_t ic = ia->ia_ic; 120 int error; 121 122 printf("\n"); 123 124 if (bus_space_map(iot, ia->ia_iobase, BHA_ISA_IOSIZE, 0, &ioh)) { 125 printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname); 126 return; 127 } 128 129 sc->sc_iot = iot; 130 sc->sc_ioh = ioh; 131 sc->sc_dmat = ia->ia_dmat; 132 if (!bha_find(iot, ioh, &bpd)) { 133 printf("%s: bha_find failed\n", sc->sc_dev.dv_xname); 134 return; 135 } 136 137 sc->sc_dmaflags = 0; 138 if (bpd.sc_drq != -1) { 139 if ((error = isa_dmacascade(ic, bpd.sc_drq)) != 0) { 140 printf("%s: unable to cascade DRQ, error = %d\n", 141 sc->sc_dev.dv_xname, error); 142 return; 143 } 144 } else { 145 /* 146 * We have a VLB controller. If we're at least both 147 * hardware revision E and firmware revision 3.37, 148 * we can do 32-bit DMA (earlier revisions are buggy 149 * in this regard). 150 */ 151 (void) bha_info(sc); 152 if (strcmp(sc->sc_firmware, "3.37") < 0) 153 printf("%s: buggy VLB controller, disabling 32-bit DMA\n", 154 sc->sc_dev.dv_xname); 155 else 156 sc->sc_dmaflags = ISABUS_DMA_32BIT; 157 } 158 159 sc->sc_ih = isa_intr_establish(ic, bpd.sc_irq, IST_EDGE, IPL_BIO, 160 bha_intr, sc); 161 if (sc->sc_ih == NULL) { 162 printf("%s: couldn't establish interrupt\n", 163 sc->sc_dev.dv_xname); 164 return; 165 } 166 167 bha_attach(sc, &bpd); 168} 169