cac_eisa.c revision 1.1 1 /* $NetBSD: cac_eisa.c,v 1.1 2000/09/01 12:15:20 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 2000 Jonathan Lemon
41 * Copyright (c) 1999 by Matthew N. Dodd <winter (at) jurai.net>
42 * All Rights Reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions, and the following disclaimer,
49 * without modification, immediately at the beginning of the file.
50 * 2. The name of the author may not be used to endorse or promote products
51 * derived from this software without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
57 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 */
65
66 /*
67 * EISA front-end for cac(4) driver.
68 */
69
70 #include <sys/types.h>
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/device.h>
74
75 #include <machine/bus.h>
76 #include <machine/intr.h>
77
78 #include <dev/eisa/eisavar.h>
79 #include <dev/eisa/eisadevs.h>
80
81 #include <dev/ic/cacreg.h>
82 #include <dev/ic/cacvar.h>
83
84 #define CAC_EISA_SLOT_OFFSET 0x0c88
85 #define CAC_EISA_IOSIZE 0x0017
86 #define CAC_EISA_IOCONF 0x38
87
88 static void cac_eisa_attach(struct device *, struct device *, void *);
89 static int cac_eisa_match(struct device *, struct cfdata *, void *);
90
91 static struct cac_ccb *cac_eisa_l0_completed(struct cac_softc *);
92 static void cac_eisa_l0_intr_enable(struct cac_softc *, int);
93 static int cac_eisa_l0_fifo_full(struct cac_softc *);
94 static int cac_eisa_l0_intr_pending(struct cac_softc *);
95 static void cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *);
96
97 struct cfattach cac_eisa_ca = {
98 sizeof(struct cac_softc), cac_eisa_match, cac_eisa_attach
99 };
100
101 static struct cac_linkage cac_eisa_l0 = {
102 cac_eisa_l0_completed,
103 cac_eisa_l0_fifo_full,
104 cac_eisa_l0_intr_enable,
105 cac_eisa_l0_intr_pending,
106 cac_eisa_l0_submit
107 };
108
109 struct cac_eisa_type {
110 const char *ct_prodstr;
111 const char *ct_typestr;
112 struct cac_linkage *ct_linkage;
113 } static cac_eisa_type[] = {
114 { "CPQ4001", "IDA", &cac_eisa_l0 },
115 { "CPQ4002", "IDA-2", &cac_eisa_l0 },
116 { "CPQ4010", "IEAS", &cac_eisa_l0 },
117 { "CPQ4020", "SMART", &cac_eisa_l0 },
118 { "CPQ4030", "SMART-2/E", &cac_l0 },
119 };
120
121 static int
122 cac_eisa_match(struct device *parent, struct cfdata *match, void *aux)
123 {
124 struct eisa_attach_args *ea;
125 int i;
126
127 ea = aux;
128
129 for (i = 0; i < sizeof(cac_eisa_type) / sizeof(cac_eisa_type[0]); i++)
130 if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0)
131 return (1);
132
133 return (0);
134 }
135
136 static void
137 cac_eisa_attach(struct device *parent, struct device *self, void *aux)
138 {
139 struct eisa_attach_args *ea;
140 bus_space_handle_t ioh;
141 eisa_chipset_tag_t ec;
142 eisa_intr_handle_t ih;
143 struct cac_softc *sc;
144 bus_space_tag_t iot;
145 const char *intrstr;
146 int irq, i;
147
148 ea = aux;
149 sc = (struct cac_softc *)self;
150 iot = ea->ea_iot;
151 ec = ea->ea_ec;
152
153 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
154 CAC_EISA_SLOT_OFFSET, CAC_EISA_IOSIZE, 0, &ioh)) {
155 printf("can't map i/o space\n");
156 return;
157 }
158
159 sc->sc_iot = iot;
160 sc->sc_ioh = ioh;
161 sc->sc_dmat = ea->ea_dmat;
162
163 /*
164 * Map and establish the interrupt.
165 */
166 switch (bus_space_read_1(iot, ioh, CAC_EISA_IOCONF) & 0xf0) {
167 case 0x20:
168 irq = 10;
169 break;
170 case 0x10:
171 irq = 11;
172 break;
173 case 0x40:
174 irq = 14;
175 break;
176 case 0x80:
177 irq = 15;
178 break;
179 default:
180 printf("controller on invalid IRQ\n");
181 return;
182 }
183
184 if (eisa_intr_map(ec, irq, &ih)) {
185 printf("can't map interrupt (%d)\n", irq);
186 return;
187 }
188
189 intrstr = eisa_intr_string(ec, ih);
190 if ((sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
191 cac_intr, sc)) == NULL) {
192 printf("can't establish interrupt");
193 if (intrstr != NULL)
194 printf(" at %s", intrstr);
195 printf("\n");
196 return;
197 }
198
199 /*
200 * Print board type and attach to the bus-independent code.
201 */
202 for (i = 0; i < sizeof(cac_eisa_type) / sizeof(cac_eisa_type[0]); i++)
203 if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0)
204 break;
205
206 printf(": Compaq %s\n", cac_eisa_type[i].ct_typestr);
207 sc->sc_cl = cac_eisa_type[i].ct_linkage;
208 cac_init(sc, intrstr, 0);
209 }
210
211 /*
212 * Linkage specific to EISA boards.
213 */
214
215 static int
216 cac_eisa_l0_fifo_full(struct cac_softc *sc)
217 {
218
219 return ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
220 CAC_EISA_CHANNEL_CLEAR) == 0);
221 }
222
223 static void
224 cac_eisa_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb)
225 {
226 u_int16_t size;
227
228 /*
229 * On these boards, `ccb_hdr.size' is actually for control flags.
230 * Set it to zero and pass the value by means of an I/O port.
231 */
232 size = le16toh(ccb->ccb_hdr.size) << 2;
233 ccb->ccb_hdr.size = 0;
234
235 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, (caddr_t)ccb - sc->sc_ccbs,
236 sizeof(struct cac_ccb), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
237
238 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
239 cac_outl(sc, CAC_EISAREG_LIST_ADDR, ccb->ccb_paddr);
240 cac_outw(sc, CAC_EISAREG_LIST_LEN, size);
241 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_BUSY);
242 }
243
244 static struct cac_ccb *
245 cac_eisa_l0_completed(struct cac_softc *sc)
246 {
247 struct cac_ccb *ccb;
248 u_int32_t off;
249 u_int8_t status;
250
251 if ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
252 CAC_EISA_CHANNEL_BUSY) == 0)
253 return (NULL);
254
255 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_BUSY);
256 off = cac_inl(sc, CAC_EISAREG_COMPLETE_ADDR);
257 status = cac_inb(sc, CAC_EISAREG_LIST_STATUS);
258 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_CLEAR);
259
260 if (off == 0)
261 return (NULL);
262
263 off = (off & ~3) - sc->sc_ccbs_paddr;
264 ccb = (struct cac_ccb *)(sc->sc_ccbs + off);
265
266 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, off, sizeof(struct cac_ccb),
267 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
268
269 ccb->ccb_req.error = status;
270 return (ccb);
271 }
272
273 static int
274 cac_eisa_l0_intr_pending(struct cac_softc *sc)
275 {
276
277 return (cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) &
278 CAC_EISA_CHANNEL_BUSY);
279 }
280
281 static void
282 cac_eisa_l0_intr_enable(struct cac_softc *sc, int state)
283 {
284
285 if (state) {
286 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL,
287 ~CAC_EISA_CHANNEL_CLEAR);
288 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL,
289 CAC_EISA_CHANNEL_BUSY);
290 cac_outb(sc, CAC_EISAREG_INTR_MASK, CAC_INTR_ENABLE);
291 cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_ENABLE);
292 } else
293 cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_DISABLE);
294 }
295