Home | History | Annotate | Line # | Download | only in pci
bha_pci.c revision 1.1
      1  1.1  mycroft #include <sys/types.h>
      2  1.1  mycroft #include <sys/param.h>
      3  1.1  mycroft #include <sys/device.h>
      4  1.1  mycroft 
      5  1.1  mycroft #include <machine/bus.h>
      6  1.1  mycroft #include <machine/intr.h>
      7  1.1  mycroft 
      8  1.1  mycroft #include <scsi/scsi_all.h>
      9  1.1  mycroft #include <scsi/scsiconf.h>
     10  1.1  mycroft 
     11  1.1  mycroft #include <dev/pci/pcivar.h>
     12  1.1  mycroft #include <dev/pci/pcidevs.h>
     13  1.1  mycroft 
     14  1.1  mycroft #include <dev/ic/bhareg.h>
     15  1.1  mycroft #include <dev/ic/bhavar.h>
     16  1.1  mycroft 
     17  1.1  mycroft #define	PCI_CBIO	0x10
     18  1.1  mycroft 
     19  1.1  mycroft int	bha_pci_match __P((struct device *, void *, void *));
     20  1.1  mycroft void	bha_pci_attach __P((struct device *, struct device *, void *));
     21  1.1  mycroft 
     22  1.1  mycroft struct cfattach bha_pci_ca = {
     23  1.1  mycroft 	sizeof(struct bha_softc), bha_pci_match, bha_pci_attach
     24  1.1  mycroft };
     25  1.1  mycroft 
     26  1.1  mycroft /*
     27  1.1  mycroft  * Check the slots looking for a board we recognise
     28  1.1  mycroft  * If we find one, note it's address (slot) and call
     29  1.1  mycroft  * the actual probe routine to check it out.
     30  1.1  mycroft  */
     31  1.1  mycroft int
     32  1.1  mycroft bha_pci_match(parent, match, aux)
     33  1.1  mycroft 	struct device *parent;
     34  1.1  mycroft 	void *match, *aux;
     35  1.1  mycroft {
     36  1.1  mycroft 	struct pci_attach_args *pa = aux;
     37  1.1  mycroft 	bus_chipset_tag_t bc = pa->pa_bc;
     38  1.1  mycroft 	bus_io_addr_t iobase;
     39  1.1  mycroft 	bus_io_size_t iosize;
     40  1.1  mycroft 	bus_io_handle_t ioh;
     41  1.1  mycroft 	pci_chipset_tag_t pc = pa->pa_pc;
     42  1.1  mycroft 	int rv;
     43  1.1  mycroft 
     44  1.1  mycroft 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_BUSLOGIC)
     45  1.1  mycroft 		return (0);
     46  1.1  mycroft 
     47  1.1  mycroft 	if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_OLD946C &&
     48  1.1  mycroft 	    PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_BUSLOGIC_946C)
     49  1.1  mycroft 		return (0);
     50  1.1  mycroft 
     51  1.1  mycroft 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
     52  1.1  mycroft 		return (0);
     53  1.1  mycroft 	if (bus_io_map(bc, iobase, iosize, &ioh))
     54  1.1  mycroft 		return (0);
     55  1.1  mycroft 
     56  1.1  mycroft 	rv = bha_find(bc, ioh, NULL);
     57  1.1  mycroft 
     58  1.1  mycroft 	bus_io_unmap(bc, ioh, iosize);
     59  1.1  mycroft 
     60  1.1  mycroft 	return (rv);
     61  1.1  mycroft }
     62  1.1  mycroft 
     63  1.1  mycroft /*
     64  1.1  mycroft  * Attach all the sub-devices we can find
     65  1.1  mycroft  */
     66  1.1  mycroft void
     67  1.1  mycroft bha_pci_attach(parent, self, aux)
     68  1.1  mycroft 	struct device *parent, *self;
     69  1.1  mycroft 	void *aux;
     70  1.1  mycroft {
     71  1.1  mycroft 	struct pci_attach_args *pa = aux;
     72  1.1  mycroft 	struct bha_softc *sc = (void *)self;
     73  1.1  mycroft 	bus_chipset_tag_t bc = pa->pa_bc;
     74  1.1  mycroft 	bus_io_addr_t iobase;
     75  1.1  mycroft 	bus_io_size_t iosize;
     76  1.1  mycroft 	bus_io_handle_t ioh;
     77  1.1  mycroft 	pci_chipset_tag_t pc = pa->pa_pc;
     78  1.1  mycroft 	pci_intr_handle_t ih;
     79  1.1  mycroft 	pcireg_t csr;
     80  1.1  mycroft 	const char *model, *intrstr;
     81  1.1  mycroft 
     82  1.1  mycroft 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_OLD946C)
     83  1.1  mycroft 		model = "BusLogic 9xxC SCSI";
     84  1.1  mycroft 	else if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_BUSLOGIC_946C)
     85  1.1  mycroft 		model = "BusLogic 9xxC SCSI";
     86  1.1  mycroft 	else
     87  1.1  mycroft 		model = "unknown model!";
     88  1.1  mycroft 	printf(": %s\n", model);
     89  1.1  mycroft 
     90  1.1  mycroft 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize))
     91  1.1  mycroft 		panic("bha_attach: pci_io_find failed!");
     92  1.1  mycroft 	if (bus_io_map(bc, iobase, iosize, &ioh))
     93  1.1  mycroft 		panic("bha_attach: bus_io_map failed!");
     94  1.1  mycroft 
     95  1.1  mycroft 	sc->sc_bc = bc;
     96  1.1  mycroft 	sc->sc_ioh = ioh;
     97  1.1  mycroft 	if (!bha_find(bc, ioh, sc))
     98  1.1  mycroft 		panic("bha_attach: bha_find failed!");
     99  1.1  mycroft 
    100  1.1  mycroft 	csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    101  1.1  mycroft 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    102  1.1  mycroft 	    csr | PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE);
    103  1.1  mycroft 
    104  1.1  mycroft 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    105  1.1  mycroft 	    pa->pa_intrline, &ih)) {
    106  1.1  mycroft 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    107  1.1  mycroft 		return;
    108  1.1  mycroft 	}
    109  1.1  mycroft 	intrstr = pci_intr_string(pc, ih);
    110  1.1  mycroft 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_BIO, bha_intr, sc);
    111  1.1  mycroft 	if (sc->sc_ih == NULL) {
    112  1.1  mycroft 		printf("%s: couldn't establish interrupt",
    113  1.1  mycroft 		    sc->sc_dev.dv_xname);
    114  1.1  mycroft 		if (intrstr != NULL)
    115  1.1  mycroft 			printf(" at %s", intrstr);
    116  1.1  mycroft 		printf("\n");
    117  1.1  mycroft 		return;
    118  1.1  mycroft 	}
    119  1.1  mycroft 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    120  1.1  mycroft 
    121  1.1  mycroft 	bha_attach(sc);
    122  1.1  mycroft }
    123