Home | History | Annotate | Line # | Download | only in eisa
dpt_eisa.c revision 1.5
      1 /*	$NetBSD: dpt_eisa.c,v 1.5 2001/04/25 17:53:27 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999, 2000, 2001 Andrew Doran <ad (at) netbsd.org>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  *
     28  */
     29 
     30 /*
     31  * EISA front-end for DPT EATA SCSI driver.
     32  */
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/device.h>
     37 #include <sys/queue.h>
     38 
     39 #include <machine/bus.h>
     40 #include <machine/intr.h>
     41 
     42 #include <dev/scsipi/scsipi_all.h>
     43 #include <dev/scsipi/scsiconf.h>
     44 
     45 #include <dev/eisa/eisavar.h>
     46 
     47 #include <dev/ic/dptreg.h>
     48 #include <dev/ic/dptvar.h>
     49 
     50 #define DPT_EISA_SLOT_OFFSET		0x0c00
     51 #define DPT_EISA_IOSIZE			0x0100
     52 #define DPT_EISA_IOCONF			0x90
     53 #define DPT_EISA_EATA_REG_OFFSET	0x88
     54 
     55 static void	dpt_eisa_attach(struct device *, struct device *, void *);
     56 static int	dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
     57 static int	dpt_eisa_match(struct device *, struct cfdata *, void *);
     58 
     59 struct cfattach dpt_eisa_ca = {
     60 	sizeof(struct dpt_softc), dpt_eisa_match, dpt_eisa_attach
     61 };
     62 
     63 static const char * const dpt_eisa_boards[] = {
     64 	"DPT2402",
     65 	"DPTA401",
     66 	"DPTA402",
     67 	"DPTA410",
     68 	"DPTA411",
     69 	"DPTA412",
     70 	"DPTA420",
     71 	"DPTA501",
     72 	"DPTA502",
     73 	"DPTA701",
     74 	"DPTBC01",
     75 	"NEC8200",	/* OEM */
     76 	"ATT2408",	/* OEM */
     77 	NULL
     78 };
     79 
     80 static int
     81 dpt_eisa_irq(bus_space_tag_t iot, bus_space_handle_t ioh, int *irq)
     82 {
     83 
     84 	switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
     85 	case 0x08:
     86 		*irq = 11;
     87 		break;
     88 	case 0x10:
     89 		*irq = 15;
     90 		break;
     91 	case 0x20:
     92 		*irq = 14;
     93 		break;
     94 	default:
     95 		return (-1);
     96 	}
     97 
     98 	return (0);
     99 }
    100 
    101 static int
    102 dpt_eisa_match(struct device *parent, struct cfdata *match, void *aux)
    103 {
    104 	struct eisa_attach_args *ea;
    105 	int i;
    106 
    107 	ea = aux;
    108 
    109 	for (i = 0; dpt_eisa_boards[i] != NULL; i++)
    110 		if (strcmp(ea->ea_idstring, dpt_eisa_boards[i]) == 0)
    111 			break;
    112 
    113 	return (dpt_eisa_boards[i] != NULL);
    114 }
    115 
    116 static void
    117 dpt_eisa_attach(struct device *parent, struct device *self, void *aux)
    118 {
    119 	struct eisa_attach_args *ea;
    120 	bus_space_handle_t ioh;
    121 	eisa_chipset_tag_t ec;
    122 	eisa_intr_handle_t ih;
    123 	struct dpt_softc *sc;
    124 	bus_space_tag_t iot;
    125 	const char *intrstr;
    126 	int irq;
    127 
    128 	ea = aux;
    129 	sc = (struct dpt_softc *)self;
    130 	iot = ea->ea_iot;
    131 	ec = ea->ea_ec;
    132 
    133 	printf(": ");
    134 
    135 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    136 	    DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
    137 		printf("can't map i/o space\n");
    138 		return;
    139 	}
    140 
    141 	sc->sc_iot = iot;
    142 	sc->sc_ioh = ioh;
    143 	sc->sc_dmat = ea->ea_dmat;
    144 
    145 	/* Map and establish the interrupt. */
    146 	if (dpt_eisa_irq(iot, ioh, &irq)) {
    147 		printf("HBA on invalid IRQ\n");
    148 		return;
    149 	}
    150 
    151 	if (eisa_intr_map(ec, irq, &ih)) {
    152 		printf("can't map interrupt (%d)\n", irq);
    153 		return;
    154 	}
    155 
    156 	intrstr = eisa_intr_string(ec, ih);
    157 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
    158 	    dpt_intr, sc);
    159 	if (sc->sc_ih == NULL) {
    160 		printf("can't establish interrupt");
    161 		if (intrstr != NULL)
    162 			printf(" at %s", intrstr);
    163 		printf("\n");
    164 		return;
    165 	}
    166 
    167 	/* Read the EATA configuration. */
    168 	if (dpt_readcfg(sc)) {
    169 		printf("%s: readcfg failed - see dpt(4)\n",
    170 		    sc->sc_dv.dv_xname);
    171 		return;
    172 	}
    173 
    174 	/* Now attach to the bus-independent code. */
    175 	dpt_init(sc, intrstr);
    176 }
    177