1 /* $OpenBSD: iha_pci.c,v 1.8 2002/11/14 02:31:46 krw Exp $ */ 2 /*------------------------------------------------------------------------- 3 * 4 * Device driver for the INI-9XXXU/UW or INIC-940/950 PCI SCSI Controller. 5 * 6 * Written for 386bsd and FreeBSD by 7 * Winston Hung <winstonh@initio.com> 8 * 9 * Copyright (c) 1997-1999 Initio Corp 10 * Copyright (c) 2000-2002 Ken Westerback 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer, 17 * without modification, immediately at the beginning of the file. 18 * 2. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 31 * THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 *------------------------------------------------------------------------- 34 */ 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 39 #include <dev/pci/pcidevs.h> 40 #include <dev/pci/pcivar.h> 41 42 #include <scsi/scsi_all.h> 43 #include <scsi/scsiconf.h> 44 45 #include <dev/ic/iha.h> 46 47 int iha_pci_probe(struct device *, void *, void *); 48 void iha_pci_attach(struct device *, struct device *, void *); 49 50 struct cfattach iha_pci_ca = { 51 sizeof(struct iha_softc), iha_pci_probe, iha_pci_attach 52 }; 53 54 int 55 iha_pci_probe(parent, match, aux) 56 struct device *parent; 57 void *match; 58 void *aux; 59 { 60 struct pci_attach_args *pa = aux; 61 62 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INITIO) 63 switch (PCI_PRODUCT(pa->pa_id)) { 64 case PCI_PRODUCT_INITIO_INIC940: 65 case PCI_PRODUCT_INITIO_INIC950: 66 return (1); 67 } 68 69 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DTCTECH) 70 switch (PCI_PRODUCT(pa->pa_id)) { 71 case PCI_PRODUCT_DTCTECH_DMX3194U: 72 return (1); 73 } 74 75 return (0); 76 } 77 78 void 79 iha_pci_attach(parent, self, aux) 80 struct device *parent; 81 struct device *self; 82 void *aux; 83 { 84 struct pci_attach_args *pa = aux; 85 bus_space_handle_t ioh; 86 pci_intr_handle_t ih; 87 struct iha_softc *sc = (void *)self; 88 bus_space_tag_t iot; 89 const char *intrstr; 90 pcireg_t command; 91 int ioh_valid; 92 93 command = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG); 94 command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE; 95 96 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); 97 98 /* 99 * XXX - Tried memory mapping (using code from adw and ahc) 100 * rather that IO mapping, but it didn't work at all.. 101 */ 102 ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, 103 &iot, &ioh, NULL, NULL, 0); 104 105 if (ioh_valid != 0) { 106 printf("%s: unable to map registers\n", sc->sc_dev.dv_xname); 107 return; 108 } 109 110 sc->sc_iot = iot; 111 sc->sc_ioh = ioh; 112 sc->sc_dmat = pa->pa_dmat; 113 114 if (pci_intr_map(pa, &ih)) { 115 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); 116 return; 117 } 118 intrstr = pci_intr_string(pa->pa_pc, ih); 119 120 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc, 121 sc->sc_dev.dv_xname); 122 123 if (sc->sc_ih == NULL) { 124 printf(": couldn't establish interrupt"); 125 if (intrstr != NULL) 126 printf(" at %s", intrstr); 127 printf("\n"); 128 } else { 129 if (intrstr != NULL) 130 printf(": %s\n", intrstr); 131 132 if (iha_init_tulip(sc) == 0) 133 config_found(&sc->sc_dev, &sc->sc_link, scsiprint); 134 } 135 } 136