1 /* $OpenBSD: iha_pci.c,v 1.4 2001/07/13 03:24:19 krw 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 return (0); 79 } 80 81 void 82 iha_pci_attach(parent, self, aux) 83 struct device *parent; 84 struct device *self; 85 void *aux; 86 { 87 struct pci_attach_args *pa = aux; 88 bus_space_handle_t ioh; 89 pci_intr_handle_t ih; 90 struct iha_softc *sc = (void *)self; 91 bus_space_tag_t iot; 92 const char *intrstr; 93 pcireg_t command; 94 int ioh_valid; 95 96 command = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG); 97 command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE; 98 99 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); 100 101 /* 102 * XXX - Tried memory mapping (using code from adw and ahc) 103 * rather that IO mapping, but it didn't work at all.. 104 */ 105 ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, 106 &iot, &ioh, NULL, NULL, 0); 107 108 if (ioh_valid != 0) { 109 printf("%s: unable to map registers\n", sc->sc_dev.dv_xname); 110 return; 111 } 112 113 sc->sc_iot = iot; 114 sc->sc_ioh = ioh; 115 sc->sc_dmat = pa->pa_dmat; 116 117 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin, 118 pa->pa_intrline, &ih)) { 119 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); 120 return; 121 } 122 intrstr = pci_intr_string(pa->pa_pc, ih); 123 124 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc, 125 sc->sc_dev.dv_xname); 126 127 if (sc->sc_ih == NULL) { 128 printf(": couldn't establish interrupt"); 129 if (intrstr != NULL) 130 printf(" at %s", intrstr); 131 printf("\n"); 132 } else { 133 if (intrstr != NULL) 134 printf(": %s\n", intrstr); 135 136 if (iha_init_tulip(sc) == 0) 137 config_found(&sc->sc_dev, &sc->sc_link, scsiprint); 138 } 139 } 140