sio.c revision 1.30 1 /* $NetBSD: sio.c,v 1.30 2000/06/13 16:40:37 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
68 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
69
70 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.30 2000/06/13 16:40:37 thorpej Exp $");
71
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/kernel.h>
75 #include <sys/device.h>
76
77 #include <machine/intr.h>
78 #include <machine/bus.h>
79 #include <machine/rpb.h>
80
81 #include <dev/isa/isavar.h>
82 #include <dev/eisa/eisavar.h>
83
84 #include <dev/pci/pcireg.h>
85 #include <dev/pci/pcivar.h>
86 #include <dev/pci/pcidevs.h>
87
88 #include <alpha/pci/siovar.h>
89
90 #ifdef DEC_2100_A500
91 #include <alpha/pci/pci_2100_a500.h>
92 #endif
93
94 struct sio_softc {
95 struct device sc_dv;
96
97 pci_chipset_tag_t sc_pc;
98
99 bus_space_tag_t sc_iot, sc_memt;
100 bus_dma_tag_t sc_parent_dmat;
101 int sc_haseisa;
102 int sc_is82c693;
103
104 /* ISA chipset must persist; it's used after autoconfig. */
105 struct alpha_isa_chipset sc_isa_chipset;
106 };
107
108 int siomatch __P((struct device *, struct cfdata *, void *));
109 void sioattach __P((struct device *, struct device *, void *));
110
111 struct cfattach sio_ca = {
112 sizeof(struct sio_softc), siomatch, sioattach,
113 };
114
115 int pcebmatch __P((struct device *, struct cfdata *, void *));
116
117 struct cfattach pceb_ca = {
118 sizeof(struct sio_softc), pcebmatch, sioattach,
119 };
120
121 union sio_attach_args {
122 const char *sa_name; /* XXX should be common */
123 struct isabus_attach_args sa_iba;
124 struct eisabus_attach_args sa_eba;
125 };
126
127 int sioprint __P((void *, const char *pnp));
128 void sio_isa_attach_hook __P((struct device *, struct device *,
129 struct isabus_attach_args *));
130 void sio_eisa_attach_hook __P((struct device *, struct device *,
131 struct eisabus_attach_args *));
132 int sio_eisa_maxslots __P((void *));
133 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
134
135 void sio_bridge_callback __P((struct device *));
136
137 int
138 siomatch(parent, match, aux)
139 struct device *parent;
140 struct cfdata *match;
141 void *aux;
142 {
143 struct pci_attach_args *pa = aux;
144
145 /*
146 * The Cypress 82C693 is more-or-less an SIO, but with
147 * indirect register access. (XXX for everything, or
148 * just the ELCR?)
149 */
150 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
151 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
152 pa->pa_function == 0)
153 return (1);
154
155 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
156 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
157 return (1);
158
159 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI &&
160 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543)
161 return (1);
162
163 return (0);
164 }
165
166 int
167 pcebmatch(parent, match, aux)
168 struct device *parent;
169 struct cfdata *match;
170 void *aux;
171 {
172 struct pci_attach_args *pa = aux;
173
174 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
175 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
176 return (1);
177
178 return (0);
179 }
180
181 void
182 sioattach(parent, self, aux)
183 struct device *parent, *self;
184 void *aux;
185 {
186 struct sio_softc *sc = (struct sio_softc *)self;
187 struct pci_attach_args *pa = aux;
188 char devinfo[256];
189
190 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
191 printf(": %s (rev. 0x%02x)\n", devinfo,
192 PCI_REVISION(pa->pa_class));
193
194 sc->sc_pc = pa->pa_pc;
195 sc->sc_iot = pa->pa_iot;
196 sc->sc_memt = pa->pa_memt;
197 sc->sc_parent_dmat = pa->pa_dmat;
198 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
199 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
200 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
201 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
202
203 config_defer(self, sio_bridge_callback);
204 }
205
206 void
207 sio_bridge_callback(self)
208 struct device *self;
209 {
210 struct sio_softc *sc = (struct sio_softc *)self;
211 struct alpha_eisa_chipset ec;
212 union sio_attach_args sa;
213
214 if (sc->sc_haseisa) {
215 ec.ec_v = NULL;
216 ec.ec_attach_hook = sio_eisa_attach_hook;
217 ec.ec_maxslots = sio_eisa_maxslots;
218
219 /*
220 * Deal with platforms that hook EISA interrupts
221 * up differently.
222 */
223 switch (cputype) {
224 #ifdef DEC_2100_A500
225 case ST_DEC_2100_A500:
226 pci_2100_a500_eisa_pickintr(sc->sc_pc, &ec);
227 break;
228 #endif
229 default:
230 ec.ec_intr_map = sio_eisa_intr_map;
231 ec.ec_intr_string = sio_intr_string;
232 ec.ec_intr_evcnt = sio_intr_evcnt;
233 ec.ec_intr_establish = sio_intr_establish;
234 ec.ec_intr_disestablish = sio_intr_disestablish;
235 }
236
237 sa.sa_eba.eba_busname = "eisa";
238 sa.sa_eba.eba_iot = sc->sc_iot;
239 sa.sa_eba.eba_memt = sc->sc_memt;
240 sa.sa_eba.eba_dmat =
241 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
242 sa.sa_eba.eba_ec = &ec;
243 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
244 }
245
246 sc->sc_isa_chipset.ic_v = NULL;
247 sc->sc_isa_chipset.ic_attach_hook = sio_isa_attach_hook;
248
249 /*
250 * Deal with platforms that hook up ISA interrupts differently.
251 */
252 switch (cputype) {
253 #ifdef DEC_2100_A500
254 case ST_DEC_2100_A500:
255 pci_2100_a500_isa_pickintr(sc->sc_pc, &sc->sc_isa_chipset);
256 break;
257 #endif
258 default:
259 sc->sc_isa_chipset.ic_intr_evcnt = sio_intr_evcnt;
260 sc->sc_isa_chipset.ic_intr_establish = sio_intr_establish;
261 sc->sc_isa_chipset.ic_intr_disestablish = sio_intr_disestablish;
262 sc->sc_isa_chipset.ic_intr_alloc = sio_intr_alloc;
263 }
264
265 sa.sa_iba.iba_busname = "isa";
266 sa.sa_iba.iba_iot = sc->sc_iot;
267 sa.sa_iba.iba_memt = sc->sc_memt;
268 sa.sa_iba.iba_dmat =
269 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
270 sa.sa_iba.iba_ic = &sc->sc_isa_chipset;
271 config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
272 }
273
274 int
275 sioprint(aux, pnp)
276 void *aux;
277 const char *pnp;
278 {
279 register union sio_attach_args *sa = aux;
280
281 if (pnp)
282 printf("%s at %s", sa->sa_name, pnp);
283 return (UNCONF);
284 }
285
286 void
287 sio_isa_attach_hook(parent, self, iba)
288 struct device *parent, *self;
289 struct isabus_attach_args *iba;
290 {
291
292 /* Nothing to do. */
293 }
294
295 void
296 sio_eisa_attach_hook(parent, self, eba)
297 struct device *parent, *self;
298 struct eisabus_attach_args *eba;
299 {
300
301 /* Nothing to do. */
302 }
303
304 int
305 sio_eisa_maxslots(v)
306 void *v;
307 {
308
309 return 16; /* as good a number as any. only 8, maybe? */
310 }
311
312 int
313 sio_eisa_intr_map(v, irq, ihp)
314 void *v;
315 u_int irq;
316 eisa_intr_handle_t *ihp;
317 {
318
319 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
320
321 if (irq >= ICU_LEN) {
322 printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
323 *ihp = -1;
324 return 1;
325 }
326 if (irq == 2) {
327 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
328 irq = 9;
329 }
330
331 *ihp = irq;
332 return 0;
333 }
334