sio.c revision 1.27 1 /* $NetBSD: sio.c,v 1.27 1999/11/12 22:07:28 lukem 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.27 1999/11/12 22:07:28 lukem 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((struct device *));
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 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI &&
115 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543)
116 return (1);
117
118 return (0);
119 }
120
121 int
122 pcebmatch(parent, match, aux)
123 struct device *parent;
124 struct cfdata *match;
125 void *aux;
126 {
127 struct pci_attach_args *pa = aux;
128
129 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
130 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB)
131 return (1);
132
133 return (0);
134 }
135
136 void
137 sioattach(parent, self, aux)
138 struct device *parent, *self;
139 void *aux;
140 {
141 struct sio_softc *sc = (struct sio_softc *)self;
142 struct pci_attach_args *pa = aux;
143 char devinfo[256];
144
145 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
146 printf(": %s (rev. 0x%02x)\n", devinfo,
147 PCI_REVISION(pa->pa_class));
148
149 sc->sc_iot = pa->pa_iot;
150 sc->sc_memt = pa->pa_memt;
151 sc->sc_parent_dmat = pa->pa_dmat;
152 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL &&
153 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
154 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ &&
155 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693);
156
157 #ifdef EVCNT_COUNTERS
158 evcnt_attach(&sc->sc_dv, "intr", &sio_intr_evcnt);
159 #endif
160
161 config_defer(self, sio_bridge_callback);
162 }
163
164 void
165 sio_bridge_callback(self)
166 struct device *self;
167 {
168 struct sio_softc *sc = (struct sio_softc *)self;
169 struct alpha_eisa_chipset ec;
170 union sio_attach_args sa;
171
172 if (sc->sc_haseisa) {
173 ec.ec_v = NULL;
174 ec.ec_attach_hook = sio_eisa_attach_hook;
175 ec.ec_maxslots = sio_eisa_maxslots;
176 ec.ec_intr_map = sio_eisa_intr_map;
177 ec.ec_intr_string = sio_intr_string;
178 ec.ec_intr_establish = sio_intr_establish;
179 ec.ec_intr_disestablish = sio_intr_disestablish;
180
181 sa.sa_eba.eba_busname = "eisa";
182 sa.sa_eba.eba_iot = sc->sc_iot;
183 sa.sa_eba.eba_memt = sc->sc_memt;
184 sa.sa_eba.eba_dmat =
185 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA);
186 sa.sa_eba.eba_ec = &ec;
187 config_found(&sc->sc_dv, &sa.sa_eba, sioprint);
188 }
189
190 sc->sc_isa_chipset.ic_v = NULL;
191 sc->sc_isa_chipset.ic_attach_hook = sio_isa_attach_hook;
192 sc->sc_isa_chipset.ic_intr_establish = sio_intr_establish;
193 sc->sc_isa_chipset.ic_intr_disestablish = sio_intr_disestablish;
194 sc->sc_isa_chipset.ic_intr_alloc = sio_intr_alloc;
195
196 sa.sa_iba.iba_busname = "isa";
197 sa.sa_iba.iba_iot = sc->sc_iot;
198 sa.sa_iba.iba_memt = sc->sc_memt;
199 sa.sa_iba.iba_dmat =
200 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA);
201 sa.sa_iba.iba_ic = &sc->sc_isa_chipset;
202 config_found(&sc->sc_dv, &sa.sa_iba, sioprint);
203 }
204
205 int
206 sioprint(aux, pnp)
207 void *aux;
208 const char *pnp;
209 {
210 register union sio_attach_args *sa = aux;
211
212 if (pnp)
213 printf("%s at %s", sa->sa_name, pnp);
214 return (UNCONF);
215 }
216
217 void
218 sio_isa_attach_hook(parent, self, iba)
219 struct device *parent, *self;
220 struct isabus_attach_args *iba;
221 {
222
223 /* Nothing to do. */
224 }
225
226 void
227 sio_eisa_attach_hook(parent, self, eba)
228 struct device *parent, *self;
229 struct eisabus_attach_args *eba;
230 {
231
232 /* Nothing to do. */
233 }
234
235 int
236 sio_eisa_maxslots(v)
237 void *v;
238 {
239
240 return 16; /* as good a number as any. only 8, maybe? */
241 }
242
243 int
244 sio_eisa_intr_map(v, irq, ihp)
245 void *v;
246 u_int irq;
247 eisa_intr_handle_t *ihp;
248 {
249
250 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
251
252 if (irq >= ICU_LEN) {
253 printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
254 *ihp = -1;
255 return 1;
256 }
257 if (irq == 2) {
258 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
259 irq = 9;
260 }
261
262 *ihp = irq;
263 return 0;
264 }
265