dpt_eisa.c revision 1.9 1 /* $NetBSD: dpt_eisa.c,v 1.9 2002/10/02 16:33:46 thorpej 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/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: dpt_eisa.c,v 1.9 2002/10/02 16:33:46 thorpej Exp $");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/queue.h>
41
42 #include <machine/bus.h>
43 #include <machine/intr.h>
44
45 #include <dev/scsipi/scsipi_all.h>
46 #include <dev/scsipi/scsiconf.h>
47
48 #include <dev/eisa/eisavar.h>
49
50 #include <dev/ic/dptreg.h>
51 #include <dev/ic/dptvar.h>
52
53 #define DPT_EISA_SLOT_OFFSET 0x0c00
54 #define DPT_EISA_IOSIZE 0x0100
55 #define DPT_EISA_IOCONF 0x90
56 #define DPT_EISA_EATA_REG_OFFSET 0x88
57
58 static void dpt_eisa_attach(struct device *, struct device *, void *);
59 static int dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
60 static int dpt_eisa_match(struct device *, struct cfdata *, void *);
61
62 CFATTACH_DECL(dpt_eisa, sizeof(struct dpt_softc),
63 dpt_eisa_match, dpt_eisa_attach, NULL, NULL);
64
65 static const char * const dpt_eisa_boards[] = {
66 "DPT2402",
67 "DPTA401",
68 "DPTA402",
69 "DPTA410",
70 "DPTA411",
71 "DPTA412",
72 "DPTA420",
73 "DPTA501",
74 "DPTA502",
75 "DPTA701",
76 "DPTBC01",
77 "NEC8200", /* OEM */
78 "ATT2408", /* OEM */
79 NULL
80 };
81
82 static int
83 dpt_eisa_irq(bus_space_tag_t iot, bus_space_handle_t ioh, int *irq)
84 {
85
86 switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
87 case 0x08:
88 *irq = 11;
89 break;
90 case 0x10:
91 *irq = 15;
92 break;
93 case 0x20:
94 *irq = 14;
95 break;
96 default:
97 return (-1);
98 }
99
100 return (0);
101 }
102
103 static int
104 dpt_eisa_match(struct device *parent, struct cfdata *match, void *aux)
105 {
106 struct eisa_attach_args *ea;
107 int i;
108
109 ea = aux;
110
111 for (i = 0; dpt_eisa_boards[i] != NULL; i++)
112 if (strcmp(ea->ea_idstring, dpt_eisa_boards[i]) == 0)
113 break;
114
115 return (dpt_eisa_boards[i] != NULL);
116 }
117
118 static void
119 dpt_eisa_attach(struct device *parent, struct device *self, void *aux)
120 {
121 struct eisa_attach_args *ea;
122 bus_space_handle_t ioh;
123 eisa_chipset_tag_t ec;
124 eisa_intr_handle_t ih;
125 struct dpt_softc *sc;
126 bus_space_tag_t iot;
127 const char *intrstr;
128 int irq;
129
130 ea = aux;
131 sc = (struct dpt_softc *)self;
132 iot = ea->ea_iot;
133 ec = ea->ea_ec;
134
135 printf(": ");
136
137 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
138 DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
139 printf("can't map i/o space\n");
140 return;
141 }
142
143 sc->sc_iot = iot;
144 sc->sc_ioh = ioh;
145 sc->sc_dmat = ea->ea_dmat;
146
147 /* Map and establish the interrupt. */
148 if (dpt_eisa_irq(iot, ioh, &irq)) {
149 printf("HBA on invalid IRQ\n");
150 return;
151 }
152
153 if (eisa_intr_map(ec, irq, &ih)) {
154 printf("can't map interrupt (%d)\n", irq);
155 return;
156 }
157
158 intrstr = eisa_intr_string(ec, ih);
159 sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
160 dpt_intr, sc);
161 if (sc->sc_ih == NULL) {
162 printf("can't establish interrupt");
163 if (intrstr != NULL)
164 printf(" at %s", intrstr);
165 printf("\n");
166 return;
167 }
168
169 /* Read the EATA configuration. */
170 if (dpt_readcfg(sc)) {
171 printf("%s: readcfg failed - see dpt(4)\n",
172 sc->sc_dv.dv_xname);
173 return;
174 }
175
176 /* Now attach to the bus-independent code. */
177 dpt_init(sc, intrstr);
178 }
179