Home | History | Annotate | Line # | Download | only in eisa
bha_eisa.c revision 1.5
      1 /*	$NetBSD: bha_eisa.c,v 1.5 1996/10/21 22:31:00 thorpej 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/eisa/eisavar.h>
     44 #include <dev/eisa/eisadevs.h>
     45 
     46 #include <dev/ic/bhareg.h>
     47 #include <dev/ic/bhavar.h>
     48 
     49 #define	BHA_EISA_SLOT_OFFSET	0xc00
     50 #define	BHA_EISA_IOSIZE		0x100
     51 
     52 int	bha_eisa_match __P((struct device *, void *, void *));
     53 void	bha_eisa_attach __P((struct device *, struct device *, void *));
     54 
     55 struct cfattach bha_eisa_ca = {
     56 	sizeof(struct bha_softc), bha_eisa_match, bha_eisa_attach
     57 };
     58 
     59 /*
     60  * Check the slots looking for a board we recognise
     61  * If we find one, note it's address (slot) and call
     62  * the actual probe routine to check it out.
     63  */
     64 int
     65 bha_eisa_match(parent, match, aux)
     66 	struct device *parent;
     67 	void *match, *aux;
     68 {
     69 	struct eisa_attach_args *ea = aux;
     70 	bus_space_tag_t iot = ea->ea_iot;
     71 	bus_space_handle_t ioh;
     72 	int rv;
     73 
     74 	/* must match one of our known ID strings */
     75 	if (strcmp(ea->ea_idstring, "BUS4201") &&
     76 	    strcmp(ea->ea_idstring, "BUS4202"))
     77 		return (0);
     78 
     79 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
     80 	    BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE, 0, &ioh))
     81 		return (0);
     82 
     83 	rv = bha_find(iot, ioh, NULL);
     84 
     85 	bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE);
     86 
     87 	return (rv);
     88 }
     89 
     90 /*
     91  * Attach all the sub-devices we can find
     92  */
     93 void
     94 bha_eisa_attach(parent, self, aux)
     95 	struct device *parent, *self;
     96 	void *aux;
     97 {
     98 	struct eisa_attach_args *ea = aux;
     99 	struct bha_softc *sc = (void *)self;
    100 	bus_space_tag_t iot = ea->ea_iot;
    101 	bus_space_handle_t ioh;
    102 	eisa_chipset_tag_t ec = ea->ea_ec;
    103 	eisa_intr_handle_t ih;
    104 	const char *model, *intrstr;
    105 
    106 	if (!strcmp(ea->ea_idstring, "BUS4201"))
    107 		model = EISA_PRODUCT_BUS4201;
    108 	else if (!strcmp(ea->ea_idstring, "BUS4202"))
    109 		model = EISA_PRODUCT_BUS4202;
    110 	else
    111 		model = "unknown model!";
    112 	printf(": %s\n", model);
    113 
    114 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    115 	    BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE, 0, &ioh))
    116 		panic("bha_attach: could not map I/O addresses");
    117 
    118 	sc->sc_iot = iot;
    119 	sc->sc_ioh = ioh;
    120 	if (!bha_find(iot, ioh, sc))
    121 		panic("bha_attach: bha_find failed!");
    122 
    123 	if (eisa_intr_map(ec, sc->sc_irq, &ih)) {
    124 		printf("%s: couldn't map interrupt (%d)\n",
    125 		    sc->sc_dev.dv_xname, sc->sc_irq);
    126 		return;
    127 	}
    128 	intrstr = eisa_intr_string(ec, ih);
    129 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    130 	    bha_intr, sc);
    131 	if (sc->sc_ih == NULL) {
    132 		printf("%s: couldn't establish interrupt",
    133 		    sc->sc_dev.dv_xname);
    134 		if (intrstr != NULL)
    135 			printf(" at %s", intrstr);
    136 		printf("\n");
    137 		return;
    138 	}
    139 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    140 
    141 	bha_attach(sc);
    142 }
    143