sio.c revision 1.15 1 /* $NetBSD: sio.c,v 1.15 1996/12/05 01:39:36 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/device.h>
34
35 #include <machine/intr.h>
36 #include <machine/bus.h>
37
38 #include <dev/isa/isavar.h>
39 #include <dev/eisa/eisavar.h>
40
41 #include <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <dev/pci/pcidevs.h>
44
45 #include <alpha/pci/siovar.h>
46
47 struct sio_softc {
48 struct device sc_dv;
49
50 bus_space_tag_t sc_iot, sc_memt;
51 int sc_haseisa;
52 };
53
54 #ifdef __BROKEN_INDIRECT_CONFIG
55 int siomatch __P((struct device *, void *, void *));
56 #else
57 int siomatch __P((struct device *, struct cfdata *, void *));
58 #endif
59 void sioattach __P((struct device *, struct device *, void *));
60
61 struct cfattach sio_ca = {
62 sizeof(struct sio_softc), siomatch, sioattach,
63 };
64
65 struct cfdriver sio_cd = {
66 NULL, "sio", DV_DULL,
67 };
68
69 #ifdef __BROKEN_INDIRECT_CONFIG
70 int pcebmatch __P((struct device *, void *, void *));
71 #else
72 int pcebmatch __P((struct device *, struct cfdata *, void *));
73 #endif
74
75 struct cfattach pceb_ca = {
76 sizeof(struct device), pcebmatch, sioattach,
77 };
78
79 struct cfdriver pceb_cd = {
80 NULL, "pceb", DV_DULL,
81 };
82
83 union sio_attach_args {
84 const char *sa_name; /* XXX should be common */
85 struct isabus_attach_args sa_iba;
86 struct eisabus_attach_args sa_eba;
87 };
88
89 int sioprint __P((void *, const char *pnp));
90 void sio_isa_attach_hook __P((struct device *, struct device *,
91 struct isabus_attach_args *));
92 void sio_eisa_attach_hook __P((struct device *, struct device *,
93 struct eisabus_attach_args *));
94 int sio_eisa_maxslots __P((void *));
95 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
96
97 void sio_bridge_callback __P((void *));
98
99 int
100 siomatch(parent, match, aux)
101 struct device *parent;
102 #ifdef __BROKEN_INDIRECT_CONFIG
103 void *match;
104 #else
105 struct cfdata *match;
106 #endif
107 void *aux;
108 {
109 struct pci_attach_args *pa = aux;
110
111 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
112 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_SIO)
113 return (0);
114
115 return (1);
116 }
117
118 int
119 pcebmatch(parent, match, aux)
120 struct device *parent;
121 #ifdef __BROKEN_INDIRECT_CONFIG
122 void *match;
123 #else
124 struct cfdata *match;
125 #endif
126 void *aux;
127 {
128 struct pci_attach_args *pa = aux;
129
130 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
131 PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_PCEB)
132 return (0);
133
134 return (1);
135 }
136
137 void
138 sioattach(parent, self, aux)
139 struct device *parent, *self;
140 void *aux;
141 {
142 struct sio_softc *sc = (struct sio_softc *)self;
143 struct pci_attach_args *pa = aux;
144 char devinfo[256];
145
146 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
147 printf(": %s (rev. 0x%02x)\n", devinfo,
148 PCI_REVISION(pa->pa_class));
149
150 sc->sc_iot = pa->pa_iot;
151 sc->sc_memt = pa->pa_memt;
152 sc->sc_haseisa = (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
153
154 #ifdef EVCNT_COUNTERS
155 evcnt_attach(&sc->sc_dv, "intr", &sio_intr_evcnt);
156 #endif
157
158 set_pci_isa_bridge_callback(sio_bridge_callback, sc);
159 }
160
161 void
162 sio_bridge_callback(v)
163 void *v;
164 {
165 struct sio_softc *sc = v;
166 struct alpha_eisa_chipset ec;
167 struct alpha_isa_chipset ic;
168 union sio_attach_args sa;
169
170 if (sc->sc_haseisa) {
171 ec.ec_v = NULL;
172 ec.ec_attach_hook = sio_eisa_attach_hook;
173 ec.ec_maxslots = sio_eisa_maxslots;
174 ec.ec_intr_map = sio_eisa_intr_map;
175 ec.ec_intr_string = sio_intr_string;
176 ec.ec_intr_establish = sio_intr_establish;
177 ec.ec_intr_disestablish = sio_intr_disestablish;
178
179 sa.sa_eba.eba_busname = "eisa";
180 sa.sa_eba.eba_iot = sc->sc_iot;
181 sa.sa_eba.eba_memt = sc->sc_memt;
182 sa.sa_eba.eba_ec = &ec;
183 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
184 }
185
186 ic.ic_v = NULL;
187 ic.ic_attach_hook = sio_isa_attach_hook;
188 ic.ic_intr_establish = sio_intr_establish;
189 ic.ic_intr_disestablish = sio_intr_disestablish;
190
191 sa.sa_iba.iba_busname = "isa";
192 sa.sa_iba.iba_iot = sc->sc_iot;
193 sa.sa_iba.iba_memt = sc->sc_memt;
194 sa.sa_iba.iba_ic = ⁣
195 config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
196 }
197
198 int
199 sioprint(aux, pnp)
200 void *aux;
201 const char *pnp;
202 {
203 register union sio_attach_args *sa = aux;
204
205 if (pnp)
206 printf("%s at %s", sa->sa_name, pnp);
207 return (UNCONF);
208 }
209
210 void
211 sio_isa_attach_hook(parent, self, iba)
212 struct device *parent, *self;
213 struct isabus_attach_args *iba;
214 {
215
216 /* Nothing to do. */
217 }
218
219 void
220 sio_eisa_attach_hook(parent, self, eba)
221 struct device *parent, *self;
222 struct eisabus_attach_args *eba;
223 {
224
225 /* Nothing to do. */
226 }
227
228 int
229 sio_eisa_maxslots(v)
230 void *v;
231 {
232
233 return 16; /* as good a number as any. only 8, maybe? */
234 }
235
236 int
237 sio_eisa_intr_map(v, irq, ihp)
238 void *v;
239 u_int irq;
240 eisa_intr_handle_t *ihp;
241 {
242
243 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
244
245 if (irq >= ICU_LEN) {
246 printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
247 *ihp = -1;
248 return 1;
249 }
250 if (irq == 2) {
251 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
252 irq = 9;
253 }
254
255 *ihp = irq;
256 return 0;
257 }
258