Home | History | Annotate | Line # | Download | only in eisa
bha_eisa.c revision 1.15
      1 /*	$NetBSD: bha_eisa.c,v 1.15 1998/08/15 02:37:51 mycroft Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1996, 1997, 1998 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 <dev/scsipi/scsi_all.h>
     41 #include <dev/scsipi/scsipi_all.h>
     42 #include <dev/scsipi/scsiconf.h>
     43 
     44 #include <dev/eisa/eisavar.h>
     45 #include <dev/eisa/eisadevs.h>
     46 
     47 #include <dev/ic/bhareg.h>
     48 #include <dev/ic/bhavar.h>
     49 
     50 #define BHA_EISA_SLOT_OFFSET	0x0c80
     51 #define	BHA_EISA_IOSIZE		0x0010
     52 #define	BHA_ISA_IOSIZE		0x0004
     53 
     54 #define	BHA_EISA_IOCONF		0x0c
     55 
     56 int	bha_eisa_address __P((bus_space_tag_t, bus_space_handle_t, int *));
     57 int	bha_eisa_match __P((struct device *, struct cfdata *, void *));
     58 void	bha_eisa_attach __P((struct device *, struct device *, void *));
     59 
     60 struct cfattach bha_eisa_ca = {
     61 	sizeof(struct bha_softc), bha_eisa_match, bha_eisa_attach
     62 };
     63 
     64 int
     65 bha_eisa_address(iot, ioh, portp)
     66 	bus_space_tag_t iot;
     67 	bus_space_handle_t ioh;
     68 	int *portp;
     69 {
     70 	int port;
     71 
     72 	switch (bus_space_read_1(iot, ioh, BHA_EISA_IOCONF) & 0x07) {
     73 	case 0x00:
     74 		port = 0x330;
     75 		break;
     76 	case 0x01:
     77 		port = 0x334;
     78 		break;
     79 	case 0x02:
     80 		port = 0x230;
     81 		break;
     82 	case 0x03:
     83 		port = 0x234;
     84 		break;
     85 	case 0x04:
     86 		port = 0x130;
     87 		break;
     88 	case 0x05:
     89 		port = 0x134;
     90 		break;
     91 	default:
     92 		return (1);
     93 	}
     94 
     95 	*portp = port;
     96 	return (0);
     97 }
     98 
     99 /*
    100  * Check the slots looking for a board we recognise
    101  * If we find one, note it's address (slot) and call
    102  * the actual probe routine to check it out.
    103  */
    104 int
    105 bha_eisa_match(parent, match, aux)
    106 	struct device *parent;
    107 	struct cfdata *match;
    108 	void *aux;
    109 {
    110 	struct eisa_attach_args *ea = aux;
    111 	bus_space_tag_t iot = ea->ea_iot;
    112 	bus_space_handle_t ioh, ioh2;
    113 	int port;
    114 	int rv;
    115 
    116 	/* must match one of our known ID strings */
    117 	if (strcmp(ea->ea_idstring, "BUS4201") &&
    118 	    strcmp(ea->ea_idstring, "BUS4202"))
    119 		return (0);
    120 
    121 	if (bus_space_map(iot,
    122 	    EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE,
    123 	    0, &ioh))
    124 		return (0);
    125 
    126 	if (bha_eisa_address(iot, ioh, &port) ||
    127 	    bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2)) {
    128 		bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE);
    129 		return (0);
    130 	}
    131 
    132 	rv = bha_find(iot, ioh2, NULL);
    133 
    134 	bus_space_unmap(iot, ioh2, BHA_ISA_IOSIZE);
    135 	bus_space_unmap(iot, ioh, BHA_EISA_IOSIZE);
    136 
    137 	return (rv);
    138 }
    139 
    140 /*
    141  * Attach all the sub-devices we can find
    142  */
    143 void
    144 bha_eisa_attach(parent, self, aux)
    145 	struct device *parent, *self;
    146 	void *aux;
    147 {
    148 	struct eisa_attach_args *ea = aux;
    149 	struct bha_softc *sc = (void *)self;
    150 	bus_space_tag_t iot = ea->ea_iot;
    151 	bus_space_handle_t ioh, ioh2;
    152 	int port;
    153 	struct bha_probe_data bpd;
    154 	eisa_chipset_tag_t ec = ea->ea_ec;
    155 	eisa_intr_handle_t ih;
    156 	const char *model, *intrstr;
    157 
    158 	if (!strcmp(ea->ea_idstring, "BUS4201"))
    159 		model = EISA_PRODUCT_BUS4201;
    160 	else if (!strcmp(ea->ea_idstring, "BUS4202"))
    161 		model = EISA_PRODUCT_BUS4202;
    162 	else
    163 		model = "unknown model!";
    164 	printf(": %s\n", model);
    165 
    166 	if (bus_space_map(iot,
    167 	    EISA_SLOT_ADDR(ea->ea_slot) + BHA_EISA_SLOT_OFFSET, BHA_EISA_IOSIZE,
    168 	    0, &ioh))
    169 		panic("bha_eisa_attach: could not map EISA slot");
    170 
    171 	if (bha_eisa_address(iot, ioh, &port) ||
    172 	    bus_space_map(iot, port, BHA_ISA_IOSIZE, 0, &ioh2))
    173 		panic("bha_eisa_attach: could not map ISA address");
    174 
    175 	sc->sc_iot = iot;
    176 	sc->sc_ioh = ioh2;
    177 	sc->sc_dmat = ea->ea_dmat;
    178 	if (!bha_find(iot, ioh2, &bpd))
    179 		panic("bha_eisa_attach: bha_find failed");
    180 
    181 	sc->sc_dmaflags = 0;
    182 
    183 	if (eisa_intr_map(ec, bpd.sc_irq, &ih)) {
    184 		printf("%s: couldn't map interrupt (%d)\n",
    185 		    sc->sc_dev.dv_xname, bpd.sc_irq);
    186 		return;
    187 	}
    188 	intrstr = eisa_intr_string(ec, ih);
    189 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    190 	    bha_intr, sc);
    191 	if (sc->sc_ih == NULL) {
    192 		printf("%s: couldn't establish interrupt",
    193 		    sc->sc_dev.dv_xname);
    194 		if (intrstr != NULL)
    195 			printf(" at %s", intrstr);
    196 		printf("\n");
    197 		return;
    198 	}
    199 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    200 
    201 	bha_attach(sc, &bpd);
    202 }
    203