1 /* $NetBSD: iha_pci.c,v 1.13 2006/11/16 01:33:09 christos 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 Ken Westerback 11 * Copyright (c) 2001 Izumi Tsutsui 12 * All rights reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer, 19 * without modification, immediately at the beginning of the file. 20 * 2. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /* 37 * Ported to NetBSD by Izumi Tsutsui <tsutsui@ceres.dti.ne.jp> from OpenBSD: 38 * $OpenBSD: iha_pci.c,v 1.2 2001/03/29 23:53:38 krw Exp $ 39 */ 40 41 #include <sys/cdefs.h> 42 __KERNEL_RCSID(0, "$NetBSD: iha_pci.c,v 1.13 2006/11/16 01:33:09 christos Exp $"); 43 44 #include <sys/param.h> 45 #include <sys/systm.h> 46 #include <sys/device.h> 47 48 #include <uvm/uvm_extern.h> 49 50 #include <dev/pci/pcidevs.h> 51 #include <dev/pci/pcivar.h> 52 53 #include <dev/scsipi/scsipi_all.h> 54 #include <dev/scsipi/scsi_all.h> 55 #include <dev/scsipi/scsiconf.h> 56 57 #include <dev/ic/ihavar.h> 58 59 static int iha_pci_match(struct device *, struct cfdata *, void *); 60 static void iha_pci_attach(struct device *, struct device *, void *); 61 62 CFATTACH_DECL(iha_pci, sizeof(struct iha_softc), 63 iha_pci_match, iha_pci_attach, NULL, NULL); 64 65 static int 66 iha_pci_match(struct device *parent, struct cfdata *match, 67 void *aux) 68 { 69 struct pci_attach_args *pa = aux; 70 71 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INITIO) 72 return (0); 73 74 switch (PCI_PRODUCT(pa->pa_id)) { 75 case PCI_PRODUCT_INITIO_I940: 76 case PCI_PRODUCT_INITIO_I950: 77 return (1); 78 } 79 80 return (0); 81 } 82 83 static void 84 iha_pci_attach(struct device *parent, struct device *self, void *aux) 85 { 86 struct pci_attach_args *pa = aux; 87 bus_space_tag_t iot; 88 bus_space_handle_t ioh; 89 pci_intr_handle_t ih; 90 struct iha_softc *sc = (struct iha_softc *)self; 91 const char *intrstr; 92 pcireg_t command; 93 int ioh_valid; 94 char devinfo[256]; 95 96 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 97 printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); 98 99 command = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG); 100 command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE; 101 102 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); 103 104 /* 105 * XXX - Tried memory mapping (using code from adw and ahc) 106 * rather that IO mapping, but it didn't work at all.. 107 */ 108 ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, 109 &iot, &ioh, NULL, NULL); 110 111 if (ioh_valid != 0) { 112 printf("%s: unable to map registers\n", sc->sc_dev.dv_xname); 113 return; 114 } 115 116 sc->sc_iot = iot; 117 sc->sc_ioh = ioh; 118 sc->sc_dmat = pa->pa_dmat; 119 120 if (pci_intr_map(pa, &ih)) { 121 printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname); 122 return; 123 } 124 intrstr = pci_intr_string(pa->pa_pc, ih); 125 126 sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc); 127 128 if (sc->sc_ih == NULL) { 129 printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname); 130 if (intrstr != NULL) 131 printf(" at %s", intrstr); 132 printf("\n"); 133 return; 134 } 135 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr); 136 137 iha_attach(sc); 138 } 139