sio.c revision 1.25 1 /* $NetBSD: sio.c,v 1.25 1998/06/08 23:49:05 thorpej 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.25 1998/06/08 23:49:05 thorpej 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 /* ISA chipset must persist; it's used after autoconfig. */
60 struct alpha_isa_chipset sc_isa_chipset;
61 };
62
63 int siomatch __P((struct device *, struct cfdata *, void *));
64 void sioattach __P((struct device *, struct device *, void *));
65
66 struct cfattach sio_ca = {
67 sizeof(struct sio_softc), siomatch, sioattach,
68 };
69
70 int pcebmatch __P((struct device *, struct cfdata *, void *));
71
72 struct cfattach pceb_ca = {
73 sizeof(struct sio_softc), pcebmatch, sioattach,
74 };
75
76 union sio_attach_args {
77 const char *sa_name; /* XXX should be common */
78 struct isabus_attach_args sa_iba;
79 struct eisabus_attach_args sa_eba;
80 };
81
82 int sioprint __P((void *, const char *pnp));
83 void sio_isa_attach_hook __P((struct device *, struct device *,
84 struct isabus_attach_args *));
85 void sio_eisa_attach_hook __P((struct device *, struct device *,
86 struct eisabus_attach_args *));
87 int sio_eisa_maxslots __P((void *));
88 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
89
90 void sio_bridge_callback __P((void *));
91
92 int
93 siomatch(parent, match, aux)
94 struct device *parent;
95 struct cfdata *match;
96 void *aux;
97 {
98 struct pci_attach_args *pa = aux;
99
100 /*
101 * The Cypress 82C693 is more-or-less an SIO, but with
102 * indirect register access. (XXX for everything, or
103 * just the ELCR?)
104 */
105 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
106 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 &&
107 pa->pa_function == 0)
108 return (1);
109
110 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
111 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO)
112 return (1);
113
114 return (0);
115 }
116
117 int
118 pcebmatch(parent, match, aux)
119 struct device *parent;
120 struct cfdata *match;
121 void *aux;
122 {
123 struct pci_attach_args *pa = aux;
124
125 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
126 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
127 return (1);
128
129 return (0);
130 }
131
132 void
133 sioattach(parent, self, aux)
134 struct device *parent, *self;
135 void *aux;
136 {
137 struct sio_softc *sc = (struct sio_softc *)self;
138 struct pci_attach_args *pa = aux;
139 char devinfo[256];
140
141 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
142 printf(": %s (rev. 0x%02x)\n", devinfo,
143 PCI_REVISION(pa->pa_class));
144
145 sc->sc_iot = pa->pa_iot;
146 sc->sc_memt = pa->pa_memt;
147 sc->sc_parent_dmat = pa->pa_dmat;
148 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
149 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
150 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
151 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
152
153 #ifdef EVCNT_COUNTERS
154 evcnt_attach(&sc->sc_dv, "intr", &sio_intr_evcnt);
155 #endif
156
157 set_pci_isa_bridge_callback(sio_bridge_callback, sc);
158 }
159
160 void
161 sio_bridge_callback(v)
162 void *v;
163 {
164 struct sio_softc *sc = v;
165 struct alpha_eisa_chipset ec;
166 union sio_attach_args sa;
167
168 if (sc->sc_haseisa) {
169 ec.ec_v = NULL;
170 ec.ec_attach_hook = sio_eisa_attach_hook;
171 ec.ec_maxslots = sio_eisa_maxslots;
172 ec.ec_intr_map = sio_eisa_intr_map;
173 ec.ec_intr_string = sio_intr_string;
174 ec.ec_intr_establish = sio_intr_establish;
175 ec.ec_intr_disestablish = sio_intr_disestablish;
176
177 sa.sa_eba.eba_busname = "eisa";
178 sa.sa_eba.eba_iot = sc->sc_iot;
179 sa.sa_eba.eba_memt = sc->sc_memt;
180 sa.sa_eba.eba_dmat =
181 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
182 sa.sa_eba.eba_ec = &ec;
183 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
184 }
185
186 sc->sc_isa_chipset.ic_v = NULL;
187 sc->sc_isa_chipset.ic_attach_hook = sio_isa_attach_hook;
188 sc->sc_isa_chipset.ic_intr_establish = sio_intr_establish;
189 sc->sc_isa_chipset.ic_intr_disestablish = sio_intr_disestablish;
190 sc->sc_isa_chipset.ic_intr_alloc = sio_intr_alloc;
191
192 sa.sa_iba.iba_busname = "isa";
193 sa.sa_iba.iba_iot = sc->sc_iot;
194 sa.sa_iba.iba_memt = sc->sc_memt;
195 sa.sa_iba.iba_dmat =
196 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
197 sa.sa_iba.iba_ic = &sc->sc_isa_chipset;
198 config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
199 }
200
201 int
202 sioprint(aux, pnp)
203 void *aux;
204 const char *pnp;
205 {
206 register union sio_attach_args *sa = aux;
207
208 if (pnp)
209 printf("%s at %s", sa->sa_name, pnp);
210 return (UNCONF);
211 }
212
213 void
214 sio_isa_attach_hook(parent, self, iba)
215 struct device *parent, *self;
216 struct isabus_attach_args *iba;
217 {
218
219 /* Nothing to do. */
220 }
221
222 void
223 sio_eisa_attach_hook(parent, self, eba)
224 struct device *parent, *self;
225 struct eisabus_attach_args *eba;
226 {
227
228 /* Nothing to do. */
229 }
230
231 int
232 sio_eisa_maxslots(v)
233 void *v;
234 {
235
236 return 16; /* as good a number as any. only 8, maybe? */
237 }
238
239 int
240 sio_eisa_intr_map(v, irq, ihp)
241 void *v;
242 u_int irq;
243 eisa_intr_handle_t *ihp;
244 {
245
246 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
247
248 if (irq >= ICU_LEN) {
249 printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
250 *ihp = -1;
251 return 1;
252 }
253 if (irq == 2) {
254 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
255 irq = 9;
256 }
257
258 *ihp = irq;
259 return 0;
260 }
261