1 /* $NetBSD: bha_pci.c,v 1.14 1997/08/27 11:25:22 bouyer Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1996, 1997 Charles M. Hannum. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Charles M. Hannum. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/types.h> 33 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/device.h> 36 37 #include <machine/bus.h> 38 #include <machine/intr.h> 39 40 #include <dev/scsipi/scsi_all.h> 41 #include <dev/scsipi/scsipi_all.h> 42 #include <dev/scsipi/scsiconf.h> 43 44 #include <dev/pci/pcivar.h> 45 #include <dev/pci/pcidevs.h> 46 47 #include <dev/ic/bhareg.h> 48 #include <dev/ic/bhavar.h> 49 50 #define PCI_CBIO 0x10 51 52 #ifdef __BROKEN_INDIRECT_CONFIG 53 int bha_pci_match __P((struct device *, void *, void *)); 54 #else 55 int bha_pci_match __P((struct device *, struct cfdata *, void *)); 56 #endif 57 void bha_pci_attach __P((struct device *, struct device *, void *)); 58 59 struct cfattach bha_pci_ca = { 60 sizeof(struct bha_softc), bha_pci_match, bha_pci_attach 61 }; 62 63 /* 64 * Check the slots looking for a board we recognise 65 * If we find one, note it's address (slot) and call 66 * the actual probe routine to check it out. 67 */ 68 int 69 bha_pci_match(parent, match, aux) 70 struct device *parent; 71 #ifdef __BROKEN_INDIRECT_CONFIG 72 void *match; 73 #else 74 struct cfdata *match; 75 #endif 76 void *aux; 77 { 78 struct pci_attach_args *pa = aux; 79 bus_space_tag_t iot; 80 bus_space_handle_t ioh; 81 bus_size_t iosize; 82 int rv; 83 84 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC) 85 return (0); 86 87 if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC && 88 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_MULTIMASTER) 89 return (0); 90 91 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, 92 NULL, &iosize)) 93 return (0); 94 95 rv = bha_find(iot, ioh, NULL); 96 97 bus_space_unmap(iot, ioh, iosize); 98 99 return (rv); 100 } 101 102 /* 103 * Attach all the sub-devices we can find 104 */ 105 void 106 bha_pci_attach(parent, self, aux) 107 struct device *parent, *self; 108 void *aux; 109 { 110 struct pci_attach_args *pa = aux; 111 struct bha_softc *sc = (void *)self; 112 bus_space_tag_t iot; 113 bus_space_handle_t ioh; 114 struct bha_probe_data bpd; 115 pci_chipset_tag_t pc = pa->pa_pc; 116 pci_intr_handle_t ih; 117 pcireg_t csr; 118 const char *model, *intrstr; 119 120 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER_NC) 121 model = "BusLogic 9xxC SCSI"; 122 else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_MULTIMASTER) 123 model = "BusLogic 9xxC SCSI"; 124 else 125 model = "unknown model!"; 126 printf(": %s\n", model); 127 128 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &iot, &ioh, 129 NULL, NULL)) { 130 printf("%s: unable to map device registers\n", 131 sc->sc_dev.dv_xname); 132 return; 133 } 134 135 sc->sc_iot = iot; 136 sc->sc_ioh = ioh; 137 sc->sc_dmat = pa->pa_dmat; 138 if (!bha_find(iot, ioh, &bpd)) 139 panic("bha_pci_attach: bha_find failed"); 140 141 sc->sc_dmaflags = 0; 142 143 csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 144 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 145 csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE); 146 147 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 148 pa->pa_intrline, &ih)) { 149 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); 150 return; 151 } 152 intrstr = pci_intr_string(pc, ih); 153 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc); 154 if (sc->sc_ih == NULL) { 155 printf("%s: couldn't establish interrupt", 156 sc->sc_dev.dv_xname); 157 if (intrstr != NULL) 158 printf(" at %s", intrstr); 159 printf("\n"); 160 return; 161 } 162 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); 163 164 bha_attach(sc, &bpd); 165 166 bha_disable_isacompat(sc); 167 } 168