sio.c revision 1.33 1 /* $NetBSD: sio.c,v 1.33 2000/07/29 23:18:47 thorpej 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 Jason R. Thorpe.
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) 1995, 1996 Carnegie-Mellon University.
41 * All rights reserved.
42 *
43 * Author: Chris G. Demetriou
44 *
45 * Permission to use, copy, modify and distribute this software and
46 * its documentation is hereby granted, provided that both the copyright
47 * notice and this permission notice appear in all copies of the
48 * software, derivative works or modified versions, and any portions
49 * thereof, and that both notices appear in supporting documentation.
50 *
51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
52 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54 *
55 * Carnegie Mellon requests users of this software to return to
56 *
57 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
58 * School of Computer Science
59 * Carnegie Mellon University
60 * Pittsburgh PA 15213-3890
61 *
62 * any improvements or extensions that they make and grant Carnegie the
63 * rights to redistribute these changes.
64 */
65
66 #include "opt_dec_2100_a500.h"
67 #include "opt_dec_2100a_a500.h"
68 #include "eisa.h"
69
70 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
71
72 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.33 2000/07/29 23:18:47 thorpej Exp $");
73
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/device.h>
78 #include <sys/malloc.h>
79
80 #include <machine/intr.h>
81 #include <machine/bus.h>
82 #include <machine/rpb.h>
83
84 #include <dev/isa/isavar.h>
85 #include <dev/eisa/eisavar.h>
86
87 #include <dev/pci/pcireg.h>
88 #include <dev/pci/pcivar.h>
89 #include <dev/pci/pcidevs.h>
90
91 #include <alpha/pci/siovar.h>
92
93 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
94 #include <alpha/pci/pci_2100_a500.h>
95 #include <alpha/sableio/sableiovar.h>
96 #endif
97
98 struct sio_softc {
99 struct device sc_dv;
100
101 pci_chipset_tag_t sc_pc;
102
103 bus_space_tag_t sc_iot, sc_memt;
104 bus_dma_tag_t sc_parent_dmat;
105 int sc_haseisa;
106 int sc_is82c693;
107
108 /* ISA chipset must persist; it's used after autoconfig. */
109 isa_chipset_tag_t sc_ic;
110 };
111
112 int siomatch __P((struct device *, struct cfdata *, void *));
113 void sioattach __P((struct device *, struct device *, void *));
114
115 struct cfattach sio_ca = {
116 sizeof(struct sio_softc), siomatch, sioattach,
117 };
118
119 int pcebmatch __P((struct device *, struct cfdata *, void *));
120
121 struct cfattach pceb_ca = {
122 sizeof(struct sio_softc), pcebmatch, sioattach,
123 };
124
125 union sio_attach_args {
126 const char *sa_name; /* XXX should be common */
127 struct isabus_attach_args sa_iba;
128 struct eisabus_attach_args sa_eba;
129 };
130
131 int sioprint __P((void *, const char *pnp));
132 void sio_isa_attach_hook __P((struct device *, struct device *,
133 struct isabus_attach_args *));
134 void sio_eisa_attach_hook __P((struct device *, struct device *,
135 struct eisabus_attach_args *));
136 int sio_eisa_maxslots __P((void *));
137 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
138
139 void sio_bridge_callback __P((struct device *));
140
141 int
142 siomatch(parent, match, aux)
143 struct device *parent;
144 struct cfdata *match;
145 void *aux;
146 {
147 struct pci_attach_args *pa = aux;
148
149 /*
150 * The Cypress 82C693 is more-or-less an SIO, but with
151 * indirect register access. (XXX for everything, or
152 * just the ELCR?)
153 */
154 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
155 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
156 pa->pa_function == 0)
157 return (1);
158
159 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
160 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
161 return (1);
162
163 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI &&
164 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543)
165 return (1);
166
167 return (0);
168 }
169
170 int
171 pcebmatch(parent, match, aux)
172 struct device *parent;
173 struct cfdata *match;
174 void *aux;
175 {
176 struct pci_attach_args *pa = aux;
177
178 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
179 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
180 return (1);
181
182 return (0);
183 }
184
185 void
186 sioattach(parent, self, aux)
187 struct device *parent, *self;
188 void *aux;
189 {
190 struct sio_softc *sc = (struct sio_softc *)self;
191 struct pci_attach_args *pa = aux;
192 char devinfo[256];
193
194 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
195 printf(": %s (rev. 0x%02x)\n", devinfo,
196 PCI_REVISION(pa->pa_class));
197
198 sc->sc_pc = pa->pa_pc;
199 sc->sc_iot = pa->pa_iot;
200 sc->sc_memt = pa->pa_memt;
201 sc->sc_parent_dmat = pa->pa_dmat;
202 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
203 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
204 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
205 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
206
207 config_defer(self, sio_bridge_callback);
208 }
209
210 void
211 sio_bridge_callback(self)
212 struct device *self;
213 {
214 struct sio_softc *sc = (struct sio_softc *)self;
215 struct alpha_eisa_chipset ec;
216 union sio_attach_args sa;
217
218 if (sc->sc_haseisa) {
219 ec.ec_v = NULL;
220 ec.ec_attach_hook = sio_eisa_attach_hook;
221 ec.ec_maxslots = sio_eisa_maxslots;
222
223 /*
224 * Deal with platforms that hook EISA interrupts
225 * up differently.
226 */
227 switch (cputype) {
228 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
229 case ST_DEC_2100_A500:
230 case ST_DEC_2100A_A500:
231 pci_2100_a500_eisa_pickintr(sc->sc_pc, &ec);
232 break;
233 #endif
234 default:
235 ec.ec_intr_map = sio_eisa_intr_map;
236 ec.ec_intr_string = sio_intr_string;
237 ec.ec_intr_evcnt = sio_intr_evcnt;
238 ec.ec_intr_establish = sio_intr_establish;
239 ec.ec_intr_disestablish = sio_intr_disestablish;
240 }
241
242 sa.sa_eba.eba_busname = "eisa";
243 sa.sa_eba.eba_iot = sc->sc_iot;
244 sa.sa_eba.eba_memt = sc->sc_memt;
245 sa.sa_eba.eba_dmat =
246 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
247 sa.sa_eba.eba_ec = &ec;
248 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
249 }
250
251 /*
252 * Deal with platforms which have Odd ISA DMA needs.
253 */
254 switch (cputype) {
255 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
256 case ST_DEC_2100_A500:
257 case ST_DEC_2100A_A500:
258 sc->sc_ic = sableio_pickisa();
259 break;
260 #endif
261 default:
262 sc->sc_ic = malloc(sizeof(*sc->sc_ic), M_DEVBUF, M_WAITOK);
263 memset(sc->sc_ic, 0, sizeof(*sc->sc_ic));
264 }
265
266 sc->sc_ic->ic_v = NULL;
267 sc->sc_ic->ic_attach_hook = sio_isa_attach_hook;
268
269 /*
270 * Deal with platforms that hook up ISA interrupts differently.
271 */
272 switch (cputype) {
273 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500)
274 case ST_DEC_2100_A500:
275 case ST_DEC_2100A_A500:
276 pci_2100_a500_isa_pickintr(sc->sc_pc, sc->sc_ic);
277 break;
278 #endif
279 default:
280 sc->sc_ic->ic_intr_evcnt = sio_intr_evcnt;
281 sc->sc_ic->ic_intr_establish = sio_intr_establish;
282 sc->sc_ic->ic_intr_disestablish = sio_intr_disestablish;
283 sc->sc_ic->ic_intr_alloc = sio_intr_alloc;
284 }
285
286 sa.sa_iba.iba_busname = "isa";
287 sa.sa_iba.iba_iot = sc->sc_iot;
288 sa.sa_iba.iba_memt = sc->sc_memt;
289 sa.sa_iba.iba_dmat =
290 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
291 sa.sa_iba.iba_ic = sc->sc_ic;
292 config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
293 }
294
295 int
296 sioprint(aux, pnp)
297 void *aux;
298 const char *pnp;
299 {
300 register union sio_attach_args *sa = aux;
301
302 if (pnp)
303 printf("%s at %s", sa->sa_name, pnp);
304 return (UNCONF);
305 }
306
307 void
308 sio_isa_attach_hook(parent, self, iba)
309 struct device *parent, *self;
310 struct isabus_attach_args *iba;
311 {
312
313 /* Nothing to do. */
314 }
315
316 void
317 sio_eisa_attach_hook(parent, self, eba)
318 struct device *parent, *self;
319 struct eisabus_attach_args *eba;
320 {
321
322 #if NEISA > 0
323 eisa_init();
324 #endif
325 }
326
327 int
328 sio_eisa_maxslots(v)
329 void *v;
330 {
331
332 return 16; /* as good a number as any. only 8, maybe? */
333 }
334
335 int
336 sio_eisa_intr_map(v, irq, ihp)
337 void *v;
338 u_int irq;
339 eisa_intr_handle_t *ihp;
340 {
341
342 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
343
344 if (irq >= ICU_LEN) {
345 printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
346 *ihp = -1;
347 return 1;
348 }
349 if (irq == 2) {
350 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
351 irq = 9;
352 }
353
354 *ihp = irq;
355 return 0;
356 }
357