Home | History | Annotate | Line # | Download | only in eisa
bha_eisa.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/eisa/eisavar.h>
     12  1.1  mycroft #include <dev/eisa/eisadevs.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	BHA_EISA_SLOT_OFFSET	0xc00
     18  1.1  mycroft #define	BHA_EISA_IOSIZE		0x100
     19  1.1  mycroft 
     20  1.1  mycroft int	bha_eisa_match __P((struct device *, void *, void *));
     21  1.1  mycroft void	bha_eisa_attach __P((struct device *, struct device *, void *));
     22  1.1  mycroft 
     23  1.1  mycroft struct cfattach bha_eisa_ca = {
     24  1.1  mycroft 	sizeof(struct bha_softc), bha_eisa_match, bha_eisa_attach
     25  1.1  mycroft };
     26  1.1  mycroft 
     27  1.1  mycroft /*
     28  1.1  mycroft  * Check the slots looking for a board we recognise
     29  1.1  mycroft  * If we find one, note it's address (slot) and call
     30  1.1  mycroft  * the actual probe routine to check it out.
     31  1.1  mycroft  */
     32  1.1  mycroft int
     33  1.1  mycroft bha_eisa_match(parent, match, aux)
     34  1.1  mycroft 	struct device *parent;
     35  1.1  mycroft 	void *match, *aux;
     36  1.1  mycroft {
     37  1.1  mycroft 	struct eisa_attach_args *ea = aux;
     38  1.1  mycroft 	bus_chipset_tag_t bc = ea->ea_bc;
     39  1.1  mycroft 	bus_io_handle_t ioh;
     40  1.1  mycroft 	int rv;
     41  1.1  mycroft 
     42  1.1  mycroft 	/* must match one of our known ID strings */
     43  1.1  mycroft 	if (strcmp(ea->ea_idstring, "BUS4201") &&
     44  1.1  mycroft 	    strcmp(ea->ea_idstring, "BUS4202"))
     45  1.1  mycroft 		return (0);
     46  1.1  mycroft 
     47  1.1  mycroft 	if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET,
     48  1.1  mycroft 	    BHA_EISA_IOSIZE, &ioh))
     49  1.1  mycroft 		return (0);
     50  1.1  mycroft 
     51  1.1  mycroft 	rv = bha_find(bc, ioh, NULL);
     52  1.1  mycroft 
     53  1.1  mycroft 	bus_io_unmap(bc, ioh, BHA_EISA_IOSIZE);
     54  1.1  mycroft 
     55  1.1  mycroft 	return (rv);
     56  1.1  mycroft }
     57  1.1  mycroft 
     58  1.1  mycroft /*
     59  1.1  mycroft  * Attach all the sub-devices we can find
     60  1.1  mycroft  */
     61  1.1  mycroft void
     62  1.1  mycroft bha_eisa_attach(parent, self, aux)
     63  1.1  mycroft 	struct device *parent, *self;
     64  1.1  mycroft 	void *aux;
     65  1.1  mycroft {
     66  1.1  mycroft 	struct eisa_attach_args *ea = aux;
     67  1.1  mycroft 	struct bha_softc *sc = (void *)self;
     68  1.1  mycroft 	bus_chipset_tag_t bc = ea->ea_bc;
     69  1.1  mycroft 	bus_io_handle_t ioh;
     70  1.1  mycroft 	eisa_chipset_tag_t ec = ea->ea_ec;
     71  1.1  mycroft 	eisa_intr_handle_t ih;
     72  1.1  mycroft 	const char *model, *intrstr;
     73  1.1  mycroft 
     74  1.1  mycroft 	if (!strcmp(ea->ea_idstring, "BUS4201"))
     75  1.1  mycroft 		model = EISA_PRODUCT_BUS4201;
     76  1.1  mycroft 	else if (!strcmp(ea->ea_idstring, "BUS4202"))
     77  1.1  mycroft 		model = EISA_PRODUCT_BUS4202;
     78  1.1  mycroft 	else
     79  1.1  mycroft 		model = "unknown model!";
     80  1.1  mycroft 	printf(": %s\n", model);
     81  1.1  mycroft 
     82  1.1  mycroft 	if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET,
     83  1.1  mycroft 	    BHA_EISA_IOSIZE, &ioh))
     84  1.1  mycroft 		panic("bha_attach: could not map I/O addresses");
     85  1.1  mycroft 
     86  1.1  mycroft 	sc->sc_bc = bc;
     87  1.1  mycroft 	sc->sc_ioh = ioh;
     88  1.1  mycroft 	if (!bha_find(bc, ioh, sc))
     89  1.1  mycroft 		panic("bha_attach: bha_find failed!");
     90  1.1  mycroft 
     91  1.1  mycroft 	if (eisa_intr_map(ec, sc->sc_irq, &ih)) {
     92  1.1  mycroft 		printf("%s: couldn't map interrupt (%d)\n",
     93  1.1  mycroft 		    sc->sc_dev.dv_xname, sc->sc_irq);
     94  1.1  mycroft 		return;
     95  1.1  mycroft 	}
     96  1.1  mycroft 	intrstr = eisa_intr_string(ec, ih);
     97  1.1  mycroft 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
     98  1.1  mycroft 	    bha_intr, sc);
     99  1.1  mycroft 	if (sc->sc_ih == NULL) {
    100  1.1  mycroft 		printf("%s: couldn't establish interrupt",
    101  1.1  mycroft 		    sc->sc_dev.dv_xname);
    102  1.1  mycroft 		if (intrstr != NULL)
    103  1.1  mycroft 			printf(" at %s", intrstr);
    104  1.1  mycroft 		printf("\n");
    105  1.1  mycroft 		return;
    106  1.1  mycroft 	}
    107  1.1  mycroft 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    108  1.1  mycroft 
    109  1.1  mycroft 	bha_attach(sc);
    110  1.1  mycroft }
    111