iha_pci.c revision 1.16
11.16Stsutsui/* $NetBSD: iha_pci.c,v 1.16 2008/05/14 13:29:29 tsutsui Exp $ */ 21.16Stsutsui 31.16Stsutsui/*- 41.16Stsutsui * Copyright (c) 2001 Izumi Tsutsui. All rights reserved. 51.16Stsutsui * 61.16Stsutsui * Redistribution and use in source and binary forms, with or without 71.16Stsutsui * modification, are permitted provided that the following conditions 81.16Stsutsui * are met: 91.16Stsutsui * 1. Redistributions of source code must retain the above copyright 101.16Stsutsui * notice, this list of conditions and the following disclaimer. 111.16Stsutsui * 2. Redistributions in binary form must reproduce the above copyright 121.16Stsutsui * notice, this list of conditions and the following disclaimer in the 131.16Stsutsui * documentation and/or other materials provided with the distribution. 141.16Stsutsui * 151.16Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 161.16Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 171.16Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 181.16Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 191.16Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 201.16Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 211.16Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 221.16Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 231.16Stsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 241.16Stsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 251.16Stsutsui */ 261.7Stsutsui 271.7Stsutsui/*- 281.7Stsutsui * Device driver for the INI-9XXXU/UW or INIC-940/950 PCI SCSI Controller. 291.7Stsutsui * 301.7Stsutsui * Written for 386bsd and FreeBSD by 311.7Stsutsui * Winston Hung <winstonh@initio.com> 321.1Stsutsui * 331.7Stsutsui * Copyright (c) 1997-1999 Initio Corp. 341.1Stsutsui * Copyright (c) 2000 Ken Westerback 351.1Stsutsui * All rights reserved. 361.1Stsutsui * 371.1Stsutsui * Redistribution and use in source and binary forms, with or without 381.1Stsutsui * modification, are permitted provided that the following conditions 391.1Stsutsui * are met: 401.1Stsutsui * 1. Redistributions of source code must retain the above copyright 411.1Stsutsui * notice, this list of conditions and the following disclaimer, 421.1Stsutsui * without modification, immediately at the beginning of the file. 431.1Stsutsui * 2. The name of the author may not be used to endorse or promote products 441.1Stsutsui * derived from this software without specific prior written permission. 451.1Stsutsui * 461.1Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 471.1Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 481.1Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 491.1Stsutsui * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 501.1Stsutsui * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 511.1Stsutsui * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 521.1Stsutsui * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 531.1Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 541.1Stsutsui * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 551.1Stsutsui * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 561.1Stsutsui * THE POSSIBILITY OF SUCH DAMAGE. 571.1Stsutsui */ 581.1Stsutsui 591.1Stsutsui/* 601.15Stsutsui * Ported to NetBSD by Izumi Tsutsui <tsutsui@NetBSD.org> from OpenBSD: 611.1Stsutsui * $OpenBSD: iha_pci.c,v 1.2 2001/03/29 23:53:38 krw Exp $ 621.1Stsutsui */ 631.3Slukem 641.3Slukem#include <sys/cdefs.h> 651.16Stsutsui__KERNEL_RCSID(0, "$NetBSD: iha_pci.c,v 1.16 2008/05/14 13:29:29 tsutsui Exp $"); 661.1Stsutsui 671.1Stsutsui#include <sys/param.h> 681.1Stsutsui#include <sys/systm.h> 691.1Stsutsui#include <sys/device.h> 701.2Stsutsui 711.2Stsutsui#include <uvm/uvm_extern.h> 721.1Stsutsui 731.1Stsutsui#include <dev/pci/pcidevs.h> 741.1Stsutsui#include <dev/pci/pcivar.h> 751.1Stsutsui 761.1Stsutsui#include <dev/scsipi/scsipi_all.h> 771.1Stsutsui#include <dev/scsipi/scsi_all.h> 781.1Stsutsui#include <dev/scsipi/scsiconf.h> 791.1Stsutsui 801.1Stsutsui#include <dev/ic/ihavar.h> 811.1Stsutsui 821.15Stsutsuistatic int iha_pci_match(device_t, cfdata_t, void *); 831.15Stsutsuistatic void iha_pci_attach(device_t, device_t, void *); 841.1Stsutsui 851.15StsutsuiCFATTACH_DECL_NEW(iha_pci, sizeof(struct iha_softc), 861.10Stsutsui iha_pci_match, iha_pci_attach, NULL, NULL); 871.1Stsutsui 881.1Stsutsuistatic int 891.15Stsutsuiiha_pci_match(device_t parent, cfdata_t cf, void *aux) 901.1Stsutsui{ 911.1Stsutsui struct pci_attach_args *pa = aux; 921.1Stsutsui 931.1Stsutsui if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INITIO) 941.15Stsutsui return 0; 951.1Stsutsui 961.1Stsutsui switch (PCI_PRODUCT(pa->pa_id)) { 971.1Stsutsui case PCI_PRODUCT_INITIO_I940: 981.1Stsutsui case PCI_PRODUCT_INITIO_I950: 991.15Stsutsui return 1; 1001.1Stsutsui } 1011.1Stsutsui 1021.15Stsutsui return 0; 1031.1Stsutsui} 1041.1Stsutsui 1051.1Stsutsuistatic void 1061.15Stsutsuiiha_pci_attach(device_t parent, device_t self, void *aux) 1071.1Stsutsui{ 1081.15Stsutsui struct iha_softc *sc = device_private(self); 1091.1Stsutsui struct pci_attach_args *pa = aux; 1101.1Stsutsui bus_space_tag_t iot; 1111.1Stsutsui bus_space_handle_t ioh; 1121.1Stsutsui pci_intr_handle_t ih; 1131.1Stsutsui const char *intrstr; 1141.1Stsutsui pcireg_t command; 1151.1Stsutsui int ioh_valid; 1161.1Stsutsui char devinfo[256]; 1171.1Stsutsui 1181.15Stsutsui sc->sc_dev = self; 1191.15Stsutsui 1201.8Sitojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 1211.15Stsutsui aprint_normal(": %s (rev. 0x%02x)\n", 1221.15Stsutsui devinfo, PCI_REVISION(pa->pa_class)); 1231.1Stsutsui 1241.1Stsutsui command = pci_conf_read(pa->pa_pc,pa->pa_tag,PCI_COMMAND_STATUS_REG); 1251.1Stsutsui command |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_PARITY_ENABLE; 1261.1Stsutsui 1271.1Stsutsui pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command); 1281.1Stsutsui 1291.1Stsutsui /* 1301.1Stsutsui * XXX - Tried memory mapping (using code from adw and ahc) 1311.1Stsutsui * rather that IO mapping, but it didn't work at all.. 1321.1Stsutsui */ 1331.1Stsutsui ioh_valid = pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, 1341.1Stsutsui &iot, &ioh, NULL, NULL); 1351.1Stsutsui 1361.1Stsutsui if (ioh_valid != 0) { 1371.15Stsutsui aprint_error_dev(self, "unable to map registers\n"); 1381.1Stsutsui return; 1391.1Stsutsui } 1401.1Stsutsui 1411.1Stsutsui sc->sc_iot = iot; 1421.1Stsutsui sc->sc_ioh = ioh; 1431.1Stsutsui sc->sc_dmat = pa->pa_dmat; 1441.1Stsutsui 1451.1Stsutsui if (pci_intr_map(pa, &ih)) { 1461.15Stsutsui aprint_error_dev(self, "couldn't map interrupt\n"); 1471.1Stsutsui return; 1481.1Stsutsui } 1491.1Stsutsui intrstr = pci_intr_string(pa->pa_pc, ih); 1501.1Stsutsui 1511.1Stsutsui sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, iha_intr, sc); 1521.1Stsutsui 1531.1Stsutsui if (sc->sc_ih == NULL) { 1541.15Stsutsui aprint_error_dev(self, "couldn't establish interrupt"); 1551.1Stsutsui if (intrstr != NULL) 1561.15Stsutsui aprint_error(" at %s", intrstr); 1571.15Stsutsui aprint_error("\n"); 1581.1Stsutsui return; 1591.1Stsutsui } 1601.15Stsutsui aprint_normal_dev(self, "interrupting at %s\n", intrstr); 1611.1Stsutsui 1621.1Stsutsui iha_attach(sc); 1631.1Stsutsui} 164