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