sio.c revision 1.23 1 /* $NetBSD: sio.c,v 1.23 1998/04/12 08:32:19 mjacob 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/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.23 1998/04/12 08:32:19 mjacob Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
38
39 #include <machine/intr.h>
40 #include <machine/bus.h>
41
42 #include <dev/isa/isavar.h>
43 #include <dev/eisa/eisavar.h>
44
45 #include <dev/pci/pcireg.h>
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pcidevs.h>
48
49 #include <alpha/pci/siovar.h>
50
51 struct sio_softc {
52 struct device sc_dv;
53
54 bus_space_tag_t sc_iot, sc_memt;
55 bus_dma_tag_t sc_parent_dmat;
56 int sc_haseisa;
57 int sc_is82c693;
58 };
59
60 int siomatch __P((struct device *, struct cfdata *, void *));
61 void sioattach __P((struct device *, struct device *, void *));
62
63 struct cfattach sio_ca = {
64 sizeof(struct sio_softc), siomatch, sioattach,
65 };
66
67 int pcebmatch __P((struct device *, struct cfdata *, void *));
68
69 struct cfattach pceb_ca = {
70 sizeof(struct sio_softc), pcebmatch, sioattach,
71 };
72
73 union sio_attach_args {
74 const char *sa_name; /* XXX should be common */
75 struct isabus_attach_args sa_iba;
76 struct eisabus_attach_args sa_eba;
77 };
78
79 int sioprint __P((void *, const char *pnp));
80 void sio_isa_attach_hook __P((struct device *, struct device *,
81 struct isabus_attach_args *));
82 void sio_eisa_attach_hook __P((struct device *, struct device *,
83 struct eisabus_attach_args *));
84 int sio_eisa_maxslots __P((void *));
85 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
86
87 void sio_bridge_callback __P((void *));
88
89 int
90 siomatch(parent, match, aux)
91 struct device *parent;
92 struct cfdata *match;
93 void *aux;
94 {
95 struct pci_attach_args *pa = aux;
96
97 /*
98 * The Cypress 82C693 is more-or-less an SIO, but with
99 * indirect register access. (XXX for everything, or
100 * just the ELCR?)
101 */
102 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
103 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
104 pa->pa_function == 0)
105 return (1);
106
107 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
108 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
109 return (1);
110
111 return (0);
112 }
113
114 int
115 pcebmatch(parent, match, aux)
116 struct device *parent;
117 struct cfdata *match;
118 void *aux;
119 {
120 struct pci_attach_args *pa = aux;
121
122 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
123 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
124 return (1);
125
126 return (0);
127 }
128
129 void
130 sioattach(parent, self, aux)
131 struct device *parent, *self;
132 void *aux;
133 {
134 struct sio_softc *sc = (struct sio_softc *)self;
135 struct pci_attach_args *pa = aux;
136 char devinfo[256];
137
138 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
139 printf(": %s (rev. 0x%02x)\n", devinfo,
140 PCI_REVISION(pa->pa_class));
141
142 sc->sc_iot = pa->pa_iot;
143 sc->sc_memt = pa->pa_memt;
144 sc->sc_parent_dmat = pa->pa_dmat;
145 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
146 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
147 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
148 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
149
150 #ifdef EVCNT_COUNTERS
151 evcnt_attach(&sc->sc_dv, "intr", &sio_intr_evcnt);
152 #endif
153
154 set_pci_isa_bridge_callback(sio_bridge_callback, sc);
155 }
156
157 void
158 sio_bridge_callback(v)
159 void *v;
160 {
161 struct sio_softc *sc = v;
162 struct alpha_eisa_chipset ec;
163 struct alpha_isa_chipset ic;
164 union sio_attach_args sa;
165
166 if (sc->sc_haseisa) {
167 ec.ec_v = NULL;
168 ec.ec_attach_hook = sio_eisa_attach_hook;
169 ec.ec_maxslots = sio_eisa_maxslots;
170 ec.ec_intr_map = sio_eisa_intr_map;
171 ec.ec_intr_string = sio_intr_string;
172 ec.ec_intr_establish = sio_intr_establish;
173 ec.ec_intr_disestablish = sio_intr_disestablish;
174
175 sa.sa_eba.eba_busname = "eisa";
176 sa.sa_eba.eba_iot = sc->sc_iot;
177 sa.sa_eba.eba_memt = sc->sc_memt;
178 sa.sa_eba.eba_dmat =
179 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
180 sa.sa_eba.eba_ec = &ec;
181 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
182 }
183
184 ic.ic_v = NULL;
185 ic.ic_attach_hook = sio_isa_attach_hook;
186 ic.ic_intr_establish = sio_intr_establish;
187 ic.ic_intr_disestablish = sio_intr_disestablish;
188
189 sa.sa_iba.iba_busname = "isa";
190 sa.sa_iba.iba_iot = sc->sc_iot;
191 sa.sa_iba.iba_memt = sc->sc_memt;
192 sa.sa_iba.iba_dmat =
193 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
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