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