Home | History | Annotate | Line # | Download | only in pci
bha_pci.c revision 1.6
      1 /*	$NetBSD: bha_pci.c,v 1.6 1996/11/05 03:04:36 jonathan Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1996 Charles M. Hannum.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Charles M. Hannum.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/types.h>
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/device.h>
     36 
     37 #include <machine/bus.h>
     38 #include <machine/intr.h>
     39 
     40 #include <scsi/scsi_all.h>
     41 #include <scsi/scsiconf.h>
     42 
     43 #include <dev/pci/pcivar.h>
     44 #include <dev/pci/pcidevs.h>
     45 
     46 #include <dev/ic/bhareg.h>
     47 #include <dev/ic/bhavar.h>
     48 
     49 #define	PCI_CBIO	0x10
     50 
     51 int	bha_pci_match __P((struct device *, void *, void *));
     52 void	bha_pci_attach __P((struct device *, struct device *, void *));
     53 
     54 struct cfattach bha_pci_ca = {
     55 	sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
     56 };
     57 
     58 /*
     59  * Check the slots looking for a board we recognise
     60  * If we find one, note it's address (slot) and call
     61  * the actual probe routine to check it out.
     62  */
     63 int
     64 bha_pci_match(parent, match, aux)
     65 	struct device *parent;
     66 	void *match, *aux;
     67 {
     68 	struct pci_attach_args *pa = aux;
     69 	bus_space_tag_t iot = pa->pa_iot;
     70 	bus_addr_t iobase;
     71 	bus_size_t iosize;
     72 	bus_space_handle_t ioh;
     73 	pci_chipset_tag_t pc = pa->pa_pc;
     74 	int rv;
     75 
     76 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
     77 		return (0);
     78 
     79 	if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_OLD946C &&
     80 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_946C)
     81 		return (0);
     82 
     83 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
     84 		return (0);
     85 	if (bus_space_map(iot, iobase, iosize, 0, &ioh))
     86 		return (0);
     87 
     88 	rv = bha_find(iot, ioh, NULL);
     89 
     90 	bus_space_unmap(iot, ioh, iosize);
     91 
     92 	return (rv);
     93 }
     94 
     95 /*
     96  * Attach all the sub-devices we can find
     97  */
     98 void
     99 bha_pci_attach(parent, self, aux)
    100 	struct device *parent, *self;
    101 	void *aux;
    102 {
    103 	struct pci_attach_args *pa = aux;
    104 	struct bha_softc *sc = (void *)self;
    105 	bus_space_tag_t iot = pa->pa_iot;
    106 	bus_addr_t iobase;
    107 	bus_size_t iosize;
    108 	bus_space_handle_t ioh;
    109 	pci_chipset_tag_t pc = pa->pa_pc;
    110 	pci_intr_handle_t ih;
    111 	pcireg_t csr;
    112 	const char *model, *intrstr;
    113 
    114 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_OLD946C)
    115 		model = "BusLogic 9xxC SCSI";
    116 	else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_946C)
    117 		model = "BusLogic 9xxC SCSI";
    118 	else
    119 		model = "unknown model!";
    120 	printf(": %s\n", model);
    121 
    122 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
    123 		panic("bha_attach: pci_io_find failed!");
    124 	if (bus_space_map(iot, iobase, iosize, 0, &ioh))
    125 		panic("bha_attach: bus_space_map failed!");
    126 
    127 	sc->sc_iot = iot;
    128 	sc->sc_ioh = ioh;
    129 	if (!bha_find(iot, ioh, sc))
    130 		panic("bha_attach: bha_find failed!");
    131 
    132 	csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    133 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    134 	    csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
    135 
    136 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    137 	    pa->pa_intrline, &ih)) {
    138 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    139 		return;
    140 	}
    141 	intrstr = pci_intr_string(pc, ih);
    142 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
    143 	if (sc->sc_ih == NULL) {
    144 		printf("%s: couldn't establish interrupt",
    145 		    sc->sc_dev.dv_xname);
    146 		if (intrstr != NULL)
    147 			printf(" at %s", intrstr);
    148 		printf("\n");
    149 		return;
    150 	}
    151 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    152 
    153 	bha_attach(sc);
    154 
    155 	bha_disable_isacompat(sc);
    156 }
    157