Home | History | Annotate | Line # | Download | only in pci
dpt_pci.c revision 1.8
      1 /*	$NetBSD: dpt_pci.c,v 1.8 2001/04/25 17:53:36 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999, 2000, 2001 Andrew Doran <ad (at) 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/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/device.h>
     37 #include <sys/queue.h>
     38 
     39 #include <machine/bus.h>
     40 #include <machine/intr.h>
     41 
     42 #include <dev/scsipi/scsipi_all.h>
     43 #include <dev/scsipi/scsiconf.h>
     44 
     45 #include <dev/pci/pcidevs.h>
     46 #include <dev/pci/pcivar.h>
     47 
     48 #include <dev/ic/dptreg.h>
     49 #include <dev/ic/dptvar.h>
     50 
     51 #define	PCI_CBMA	0x14	/* Configuration base memory address */
     52 #define	PCI_CBIO	0x10	/* Configuration base I/O address */
     53 
     54 static int	dpt_pci_match(struct device *, struct cfdata *, void *);
     55 static void	dpt_pci_attach(struct device *, struct device *, void *);
     56 
     57 struct cfattach dpt_pci_ca = {
     58 	sizeof(struct dpt_softc), dpt_pci_match, dpt_pci_attach
     59 };
     60 
     61 static int
     62 dpt_pci_match(struct device *parent, struct cfdata *match, void *aux)
     63 {
     64 	struct pci_attach_args *pa;
     65 
     66 	pa = (struct pci_attach_args *)aux;
     67 
     68 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_DPT &&
     69 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_DPT_SC_RAID)
     70 		return (1);
     71 
     72 	return (0);
     73 }
     74 
     75 static void
     76 dpt_pci_attach(struct device *parent, struct device *self, void *aux)
     77 {
     78 	struct pci_attach_args *pa;
     79 	struct dpt_softc *sc;
     80 	pci_chipset_tag_t pc;
     81 	pci_intr_handle_t ih;
     82 	bus_space_handle_t ioh;
     83 	const char *intrstr;
     84 	pcireg_t csr;
     85 
     86 	sc = (struct dpt_softc *)self;
     87 	pa = (struct pci_attach_args *)aux;
     88 	pc = pa->pa_pc;
     89 	printf(": ");
     90 
     91 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, &sc->sc_iot,
     92 	    &ioh, NULL, NULL)) {
     93 		printf("can't map i/o space\n");
     94 		return;
     95 	}
     96 
     97 	/* Need to map in by 16 registers. */
     98 	if (bus_space_subregion(sc->sc_iot, ioh, 16, 16, &sc->sc_ioh)) {
     99 		printf("can't map i/o subregion\n");
    100 		return;
    101 	}
    102 
    103 	sc->sc_dmat = pa->pa_dmat;
    104 
    105 	/* Enable the device. */
    106 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    107 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    108 		       csr | PCI_COMMAND_MASTER_ENABLE);
    109 
    110 	/* Map and establish the interrupt. */
    111 	if (pci_intr_map(pa, &ih)) {
    112 		printf("can't map interrupt\n");
    113 		return;
    114 	}
    115 	intrstr = pci_intr_string(pc, ih);
    116 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, dpt_intr, sc);
    117 	if (sc->sc_ih == NULL) {
    118 		printf("can't establish interrupt");
    119 		if (intrstr != NULL)
    120 			printf(" at %s", intrstr);
    121 		printf("\n");
    122 		return;
    123 	}
    124 
    125 	/* Read the EATA configuration. */
    126 	if (dpt_readcfg(sc)) {
    127 		printf("%s: readcfg failed - see dpt(4)\n",
    128 		    sc->sc_dv.dv_xname);
    129 		return;
    130 	}
    131 
    132 	/* Now attach to the bus-independent code. */
    133 	dpt_init(sc, intrstr);
    134 }
    135