Home | History | Annotate | Line # | Download | only in eisa
bha_eisa.c revision 1.2
      1 /*	$NetBSD: bha_eisa.c,v 1.2 1996/09/01 00:20:20 mycroft 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/device.h>
     35 
     36 #include <machine/bus.h>
     37 #include <machine/intr.h>
     38 
     39 #include <scsi/scsi_all.h>
     40 #include <scsi/scsiconf.h>
     41 
     42 #include <dev/eisa/eisavar.h>
     43 #include <dev/eisa/eisadevs.h>
     44 
     45 #include <dev/ic/bhareg.h>
     46 #include <dev/ic/bhavar.h>
     47 
     48 #define	BHA_EISA_SLOT_OFFSET	0xc00
     49 #define	BHA_EISA_IOSIZE		0x100
     50 
     51 int	bha_eisa_match __P((struct device *, void *, void *));
     52 void	bha_eisa_attach __P((struct device *, struct device *, void *));
     53 
     54 struct cfattach bha_eisa_ca = {
     55 	sizeof(struct bha_softc), bha_eisa_match, bha_eisa_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_eisa_match(parent, match, aux)
     65 	struct device *parent;
     66 	void *match, *aux;
     67 {
     68 	struct eisa_attach_args *ea = aux;
     69 	bus_chipset_tag_t bc = ea->ea_bc;
     70 	bus_io_handle_t ioh;
     71 	int rv;
     72 
     73 	/* must match one of our known ID strings */
     74 	if (strcmp(ea->ea_idstring, "BUS4201") &&
     75 	    strcmp(ea->ea_idstring, "BUS4202"))
     76 		return (0);
     77 
     78 	if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET,
     79 	    BHA_EISA_IOSIZE, &ioh))
     80 		return (0);
     81 
     82 	rv = bha_find(bc, ioh, NULL);
     83 
     84 	bus_io_unmap(bc, ioh, BHA_EISA_IOSIZE);
     85 
     86 	return (rv);
     87 }
     88 
     89 /*
     90  * Attach all the sub-devices we can find
     91  */
     92 void
     93 bha_eisa_attach(parent, self, aux)
     94 	struct device *parent, *self;
     95 	void *aux;
     96 {
     97 	struct eisa_attach_args *ea = aux;
     98 	struct bha_softc *sc = (void *)self;
     99 	bus_chipset_tag_t bc = ea->ea_bc;
    100 	bus_io_handle_t ioh;
    101 	eisa_chipset_tag_t ec = ea->ea_ec;
    102 	eisa_intr_handle_t ih;
    103 	const char *model, *intrstr;
    104 
    105 	if (!strcmp(ea->ea_idstring, "BUS4201"))
    106 		model = EISA_PRODUCT_BUS4201;
    107 	else if (!strcmp(ea->ea_idstring, "BUS4202"))
    108 		model = EISA_PRODUCT_BUS4202;
    109 	else
    110 		model = "unknown model!";
    111 	printf(": %s\n", model);
    112 
    113 	if (bus_io_map(bc, EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET,
    114 	    BHA_EISA_IOSIZE, &ioh))
    115 		panic("bha_attach: could not map I/O addresses");
    116 
    117 	sc->sc_bc = bc;
    118 	sc->sc_ioh = ioh;
    119 	if (!bha_find(bc, ioh, sc))
    120 		panic("bha_attach: bha_find failed!");
    121 
    122 	if (eisa_intr_map(ec, sc->sc_irq, &ih)) {
    123 		printf("%s: couldn't map interrupt (%d)\n",
    124 		    sc->sc_dev.dv_xname, sc->sc_irq);
    125 		return;
    126 	}
    127 	intrstr = eisa_intr_string(ec, ih);
    128 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    129 	    bha_intr, sc);
    130 	if (sc->sc_ih == NULL) {
    131 		printf("%s: couldn't establish interrupt",
    132 		    sc->sc_dev.dv_xname);
    133 		if (intrstr != NULL)
    134 			printf(" at %s", intrstr);
    135 		printf("\n");
    136 		return;
    137 	}
    138 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    139 
    140 	bha_attach(sc);
    141 }
    142