sio.c revision 1.9 1 1.9 cgd /* $NetBSD: sio.c,v 1.9 1996/08/27 21:54:03 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.1 cgd
30 1.1 cgd #include <sys/param.h>
31 1.1 cgd #include <sys/systm.h>
32 1.1 cgd #include <sys/kernel.h>
33 1.1 cgd #include <sys/device.h>
34 1.1 cgd
35 1.5 cgd #include <machine/intr.h>
36 1.5 cgd #include <machine/bus.h>
37 1.5 cgd
38 1.3 cgd #include <dev/isa/isavar.h>
39 1.3 cgd #include <dev/eisa/eisavar.h>
40 1.3 cgd
41 1.1 cgd #include <dev/pci/pcireg.h>
42 1.1 cgd #include <dev/pci/pcivar.h>
43 1.1 cgd #include <dev/pci/pcidevs.h>
44 1.1 cgd
45 1.3 cgd #include <alpha/pci/siovar.h>
46 1.1 cgd
47 1.1 cgd int siomatch __P((struct device *, void *, void *));
48 1.1 cgd void sioattach __P((struct device *, struct device *, void *));
49 1.1 cgd
50 1.4 thorpej struct cfattach sio_ca = {
51 1.5 cgd sizeof(struct device), siomatch, sioattach,
52 1.4 thorpej };
53 1.4 thorpej
54 1.4 thorpej struct cfdriver sio_cd = {
55 1.5 cgd NULL, "sio", DV_DULL,
56 1.1 cgd };
57 1.1 cgd
58 1.3 cgd int pcebmatch __P((struct device *, void *, void *));
59 1.3 cgd
60 1.4 thorpej struct cfattach pceb_ca = {
61 1.5 cgd sizeof(struct device), pcebmatch, sioattach,
62 1.4 thorpej };
63 1.4 thorpej
64 1.4 thorpej struct cfdriver pceb_cd = {
65 1.5 cgd NULL, "pceb", DV_DULL,
66 1.5 cgd };
67 1.5 cgd
68 1.5 cgd union sio_attach_args {
69 1.5 cgd const char *sa_name; /* XXX should be common */
70 1.5 cgd struct isabus_attach_args sa_iba;
71 1.5 cgd struct eisabus_attach_args sa_eba;
72 1.3 cgd };
73 1.3 cgd
74 1.9 cgd int sioprint __P((void *, const char *pnp));
75 1.8 cgd void sio_isa_attach_hook __P((struct device *, struct device *,
76 1.8 cgd struct isabus_attach_args *));
77 1.8 cgd void sio_eisa_attach_hook __P((struct device *, struct device *,
78 1.8 cgd struct eisabus_attach_args *));
79 1.8 cgd int sio_eisa_maxslots __P((void *));
80 1.8 cgd int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *));
81 1.1 cgd
82 1.1 cgd int
83 1.1 cgd siomatch(parent, match, aux)
84 1.1 cgd struct device *parent;
85 1.1 cgd void *match, *aux;
86 1.1 cgd {
87 1.1 cgd struct cfdata *cf = match;
88 1.5 cgd struct pci_attach_args *pa = aux;
89 1.3 cgd
90 1.5 cgd if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
91 1.5 cgd PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_SIO)
92 1.3 cgd return (0);
93 1.3 cgd
94 1.3 cgd return (1);
95 1.3 cgd }
96 1.3 cgd
97 1.3 cgd int
98 1.3 cgd pcebmatch(parent, match, aux)
99 1.3 cgd struct device *parent;
100 1.3 cgd void *match, *aux;
101 1.3 cgd {
102 1.3 cgd struct cfdata *cf = match;
103 1.5 cgd struct pci_attach_args *pa = aux;
104 1.1 cgd
105 1.5 cgd if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL ||
106 1.5 cgd PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_INTEL_PCEB)
107 1.1 cgd return (0);
108 1.1 cgd
109 1.1 cgd return (1);
110 1.1 cgd }
111 1.1 cgd
112 1.1 cgd void
113 1.1 cgd sioattach(parent, self, aux)
114 1.1 cgd struct device *parent, *self;
115 1.1 cgd void *aux;
116 1.1 cgd {
117 1.5 cgd struct pci_attach_args *pa = aux;
118 1.6 cgd struct alpha_isa_chipset ic;
119 1.6 cgd struct alpha_eisa_chipset ec;
120 1.5 cgd union sio_attach_args sa;
121 1.3 cgd int sio, haseisa;
122 1.3 cgd char devinfo[256];
123 1.3 cgd
124 1.5 cgd sio = (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO);
125 1.5 cgd haseisa = (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB);
126 1.3 cgd
127 1.5 cgd pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
128 1.3 cgd printf(": %s (rev. 0x%02x)\n", devinfo,
129 1.5 cgd PCI_REVISION(pa->pa_class));
130 1.3 cgd
131 1.3 cgd if (sio) {
132 1.3 cgd pci_revision_t rev;
133 1.3 cgd
134 1.5 cgd rev = PCI_REVISION(pa->pa_class);
135 1.3 cgd
136 1.3 cgd if (rev < 3)
137 1.3 cgd printf("%s: WARNING: SIO I SUPPORT UNTESTED\n",
138 1.3 cgd self->dv_xname);
139 1.3 cgd }
140 1.3 cgd
141 1.3 cgd #ifdef EVCNT_COUNTERS
142 1.3 cgd evcnt_attach(self, "intr", &sio_intr_evcnt);
143 1.3 cgd #endif
144 1.3 cgd
145 1.3 cgd if (haseisa) {
146 1.8 cgd ec.ec_v = NULL;
147 1.8 cgd ec.ec_attach_hook = sio_eisa_attach_hook;
148 1.8 cgd ec.ec_maxslots = sio_eisa_maxslots;
149 1.8 cgd ec.ec_intr_map = sio_eisa_intr_map;
150 1.8 cgd ec.ec_intr_string = sio_intr_string;
151 1.8 cgd ec.ec_intr_establish = sio_intr_establish;
152 1.8 cgd ec.ec_intr_disestablish = sio_intr_disestablish;
153 1.8 cgd
154 1.5 cgd sa.sa_eba.eba_busname = "eisa";
155 1.5 cgd sa.sa_eba.eba_bc = pa->pa_bc;
156 1.6 cgd sa.sa_eba.eba_ec = &ec;
157 1.5 cgd config_found(self, &sa.sa_eba, sioprint);
158 1.1 cgd }
159 1.5 cgd
160 1.6 cgd ic.ic_v = NULL;
161 1.6 cgd ic.ic_attach_hook = sio_isa_attach_hook;
162 1.6 cgd ic.ic_intr_establish = sio_intr_establish;
163 1.6 cgd ic.ic_intr_disestablish = sio_intr_disestablish;
164 1.6 cgd
165 1.5 cgd sa.sa_iba.iba_busname = "isa";
166 1.5 cgd sa.sa_iba.iba_bc = pa->pa_bc;
167 1.6 cgd sa.sa_iba.iba_ic = ⁣
168 1.5 cgd config_found(self, &sa.sa_iba, sioprint);
169 1.1 cgd }
170 1.1 cgd
171 1.8 cgd int
172 1.1 cgd sioprint(aux, pnp)
173 1.1 cgd void *aux;
174 1.9 cgd const char *pnp;
175 1.1 cgd {
176 1.5 cgd register union sio_attach_args *sa = aux;
177 1.1 cgd
178 1.1 cgd if (pnp)
179 1.5 cgd printf("%s at %s", sa->sa_name, pnp);
180 1.1 cgd return (UNCONF);
181 1.6 cgd }
182 1.6 cgd
183 1.8 cgd void
184 1.6 cgd sio_isa_attach_hook(parent, self, iba)
185 1.6 cgd struct device *parent, *self;
186 1.6 cgd struct isabus_attach_args *iba;
187 1.6 cgd {
188 1.6 cgd
189 1.6 cgd /* Nothing to do. */
190 1.8 cgd }
191 1.8 cgd
192 1.8 cgd void
193 1.8 cgd sio_eisa_attach_hook(parent, self, eba)
194 1.8 cgd struct device *parent, *self;
195 1.8 cgd struct eisabus_attach_args *eba;
196 1.8 cgd {
197 1.8 cgd
198 1.8 cgd /* Nothing to do. */
199 1.8 cgd }
200 1.8 cgd
201 1.8 cgd int
202 1.8 cgd sio_eisa_maxslots(v)
203 1.8 cgd void *v;
204 1.8 cgd {
205 1.8 cgd
206 1.8 cgd return 16; /* as good a number as any. only 8, maybe? */
207 1.8 cgd }
208 1.8 cgd
209 1.8 cgd int
210 1.8 cgd sio_eisa_intr_map(v, irq, ihp)
211 1.8 cgd void *v;
212 1.8 cgd u_int irq;
213 1.8 cgd eisa_intr_handle_t *ihp;
214 1.8 cgd {
215 1.8 cgd
216 1.8 cgd #define ICU_LEN 16 /* number of ISA IRQs (XXX) */
217 1.8 cgd
218 1.8 cgd if (irq >= ICU_LEN) {
219 1.8 cgd printf("sio_eisa_intr_map: bad IRQ %d\n", irq);
220 1.8 cgd *ihp = -1;
221 1.8 cgd return 1;
222 1.8 cgd }
223 1.8 cgd if (irq == 2) {
224 1.8 cgd printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n");
225 1.8 cgd irq = 9;
226 1.8 cgd }
227 1.8 cgd
228 1.8 cgd *ihp = irq;
229 1.8 cgd return 0;
230 1.1 cgd }
231