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