1 /* $NetBSD: dpt_pci.c,v 1.7 2000/12/28 22:59:11 sommerfeld Exp $ */ 2 3 /* 4 * Copyright (c) 1999 Andrew Doran <ad@NetBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29 30 /* 31 * PCI front-end for DPT EATA SCSI driver. 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: dpt_pci.c,v 1.7 2000/12/28 22:59:11 sommerfeld Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/device.h> 41 #include <sys/queue.h> 42 #include <sys/proc.h> 43 44 #include <machine/endian.h> 45 #include <machine/bus.h> 46 47 #include <dev/scsipi/scsi_all.h> 48 #include <dev/scsipi/scsipi_all.h> 49 #include <dev/scsipi/scsiconf.h> 50 51 #include <dev/pci/pcidevs.h> 52 #include <dev/pci/pcivar.h> 53 54 #include <dev/ic/dptreg.h> 55 #include <dev/ic/dptvar.h> 56 57 #define PCI_CBMA 0x14 /* Configuration base memory address */ 58 #define PCI_CBIO 0x10 /* Configuration base I/O address */ 59 60 int dpt_pci_match __P((struct device *, struct cfdata *, void *)); 61 void dpt_pci_attach __P((struct device *, struct device *, void *)); 62 63 struct cfattach dpt_pci_ca = { 64 sizeof(struct dpt_softc), dpt_pci_match, dpt_pci_attach 65 }; 66 67 int 68 dpt_pci_match(parent, match, aux) 69 struct device *parent; 70 struct cfdata *match; 71 void *aux; 72 { 73 struct pci_attach_args *pa; 74 75 pa = (struct pci_attach_args *)aux; 76 77 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DPT && 78 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_SC_RAID) 79 return (1); 80 81 return (0); 82 } 83 84 void 85 dpt_pci_attach(parent, self, aux) 86 struct device *parent; 87 struct device *self; 88 void *aux; 89 { 90 struct pci_attach_args *pa; 91 struct dpt_softc *sc; 92 pci_chipset_tag_t pc; 93 pci_intr_handle_t ih; 94 bus_space_handle_t ioh; 95 const char *intrstr; 96 pcireg_t csr; 97 98 sc = (struct dpt_softc *)self; 99 pa = (struct pci_attach_args *)aux; 100 pc = pa->pa_pc; 101 printf(": "); 102 103 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot, 104 &ioh, NULL, NULL)) { 105 printf("can't map i/o space\n"); 106 return; 107 } 108 109 /* Need to map in by 16 registers */ 110 if (bus_space_subregion(sc->sc_iot, ioh, 16, 16, &sc->sc_ioh)) { 111 printf("can't map i/o subregion\n"); 112 return; 113 } 114 115 sc->sc_dmat = pa->pa_dmat; 116 117 /* Enable the device. */ 118 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 119 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 120 csr | PCI_COMMAND_MASTER_ENABLE); 121 122 /* Map and establish the interrupt. */ 123 if (pci_intr_map(pa, &ih)) { 124 printf("can't map interrupt\n"); 125 return; 126 } 127 intrstr = pci_intr_string(pc, ih); 128 sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, dpt_intr, sc); 129 if (sc->sc_ih == NULL) { 130 printf("can't establish interrupt"); 131 if (intrstr != NULL) 132 printf(" at %s", intrstr); 133 printf("\n"); 134 return; 135 } 136 137 /* Read the EATA configuration */ 138 if (dpt_readcfg(sc)) { 139 printf("%s: readcfg failed - see dpt(4)\n", 140 sc->sc_dv.dv_xname); 141 return; 142 } 143 144 /* Now attach to the bus-independent code */ 145 dpt_init(sc, intrstr); 146 } 147