pci_eb64plus.c revision 1.6 1 /* $NetBSD: pci_eb64plus.c,v 1.6 2000/06/04 19:14:23 cgd Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
42 * All rights reserved.
43 *
44 * Author: Chris G. Demetriou
45 *
46 * Permission to use, copy, modify and distribute this software and
47 * its documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
51 *
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 *
56 * Carnegie Mellon requests users of this software to return to
57 *
58 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
68
69 __KERNEL_RCSID(0, "$NetBSD: pci_eb64plus.c,v 1.6 2000/06/04 19:14:23 cgd Exp $");
70
71 #include <sys/types.h>
72 #include <sys/param.h>
73 #include <sys/time.h>
74 #include <sys/systm.h>
75 #include <sys/errno.h>
76 #include <sys/malloc.h>
77 #include <sys/device.h>
78 #include <sys/syslog.h>
79
80 #include <vm/vm.h>
81
82 #include <machine/autoconf.h>
83
84 #include <dev/pci/pcireg.h>
85 #include <dev/pci/pcivar.h>
86
87 #include <alpha/pci/apecsreg.h>
88 #include <alpha/pci/apecsvar.h>
89
90 #include <alpha/pci/pci_eb64plus.h>
91
92 #ifndef EVCNT_COUNTERS
93 #include <machine/intrcnt.h>
94 #endif
95
96 #include "sio.h"
97 #if NSIO
98 #include <alpha/pci/siovar.h>
99 #endif
100
101 int dec_eb64plus_intr_map __P((void *, pcitag_t, int, int,
102 pci_intr_handle_t *));
103 const char *dec_eb64plus_intr_string __P((void *, pci_intr_handle_t));
104 const struct evcnt *dec_eb64plus_intr_evcnt __P((void *, pci_intr_handle_t));
105 void *dec_eb64plus_intr_establish __P((void *, pci_intr_handle_t,
106 int, int (*func)(void *), void *));
107 void dec_eb64plus_intr_disestablish __P((void *, void *));
108
109 #define EB64PLUS_MAX_IRQ 32
110 #define PCI_STRAY_MAX 5
111
112 struct alpha_shared_intr *eb64plus_pci_intr;
113 #ifdef EVCNT_COUNTERS
114 struct evcnt eb64plus_intr_evcnt;
115 #endif
116
117 bus_space_tag_t eb64plus_intrgate_iot;
118 bus_space_handle_t eb64plus_intrgate_ioh;
119
120 void eb64plus_iointr __P((void *framep, unsigned long vec));
121 extern void eb64plus_intr_enable __P((int irq)); /* pci_eb64plus_intr.S */
122 extern void eb64plus_intr_disable __P((int irq)); /* pci_eb64plus_intr.S */
123
124 void
125 pci_eb64plus_pickintr(acp)
126 struct apecs_config *acp;
127 {
128 bus_space_tag_t iot = &acp->ac_iot;
129 pci_chipset_tag_t pc = &acp->ac_pc;
130 int i;
131
132 pc->pc_intr_v = acp;
133 pc->pc_intr_map = dec_eb64plus_intr_map;
134 pc->pc_intr_string = dec_eb64plus_intr_string;
135 pc->pc_intr_evcnt = dec_eb64plus_intr_evcnt;
136 pc->pc_intr_establish = dec_eb64plus_intr_establish;
137 pc->pc_intr_disestablish = dec_eb64plus_intr_disestablish;
138
139 /* Not supported on the EB64+. */
140 pc->pc_pciide_compat_intr_establish = NULL;
141
142 eb64plus_intrgate_iot = iot;
143 if (bus_space_map(eb64plus_intrgate_iot, 0x804, 3, 0,
144 &eb64plus_intrgate_ioh) != 0)
145 panic("pci_eb64plus_pickintr: couldn't map interrupt PLD");
146 for (i = 0; i < EB64PLUS_MAX_IRQ; i++)
147 eb64plus_intr_disable(i);
148
149 eb64plus_pci_intr = alpha_shared_intr_alloc(EB64PLUS_MAX_IRQ);
150 for (i = 0; i < EB64PLUS_MAX_IRQ; i++)
151 alpha_shared_intr_set_maxstrays(eb64plus_pci_intr, i,
152 PCI_STRAY_MAX);
153
154 #if NSIO
155 sio_intr_setup(pc, iot);
156 #endif
157
158 set_iointr(eb64plus_iointr);
159 }
160
161 int
162 dec_eb64plus_intr_map(acv, bustag, buspin, line, ihp)
163 void *acv;
164 pcitag_t bustag;
165 int buspin, line;
166 pci_intr_handle_t *ihp;
167 {
168 struct apecs_config *acp = acv;
169 pci_chipset_tag_t pc = &acp->ac_pc;
170 int bus, device, function;
171
172 if (buspin == 0) {
173 /* No IRQ used. */
174 return 1;
175 }
176 if (buspin > 4) {
177 printf("dec_eb64plus_intr_map: bad interrupt pin %d\n", buspin);
178 return 1;
179 }
180
181 alpha_pci_decompose_tag(pc, bustag, &bus, &device, &function);
182
183 /*
184 * The console places the interrupt mapping in the "line" value.
185 * A value of (char)-1 indicates there is no mapping.
186 */
187 if (line == 0xff) {
188 printf("dec_eb64plus_intr_map: no mapping for %d/%d/%d\n",
189 bus, device, function);
190 return (1);
191 }
192
193 if (line >= EB64PLUS_MAX_IRQ)
194 panic("dec_eb64plus_intr_map: eb64+ irq too large (%d)\n",
195 line);
196
197 *ihp = line;
198 return (0);
199 }
200
201 const char *
202 dec_eb64plus_intr_string(acv, ih)
203 void *acv;
204 pci_intr_handle_t ih;
205 {
206 static char irqstr[15]; /* 11 + 2 + NULL + sanity */
207
208 if (ih > EB64PLUS_MAX_IRQ)
209 panic("dec_eb64plus_intr_string: bogus eb64+ IRQ 0x%lx\n", ih);
210 sprintf(irqstr, "eb64+ irq %ld", ih);
211 return (irqstr);
212 }
213
214 const struct evcnt *
215 dec_eb64plus_intr_evcnt(acv, ih)
216 void *acv;
217 pci_intr_handle_t ih;
218 {
219
220 /* XXX for now, no evcnt parent reported */
221 return (NULL);
222 }
223
224 void *
225 dec_eb64plus_intr_establish(acv, ih, level, func, arg)
226 void *acv, *arg;
227 pci_intr_handle_t ih;
228 int level;
229 int (*func) __P((void *));
230 {
231 void *cookie;
232
233 if (ih > EB64PLUS_MAX_IRQ)
234 panic("dec_eb64plus_intr_establish: bogus eb64+ IRQ 0x%lx\n",
235 ih);
236
237 cookie = alpha_shared_intr_establish(eb64plus_pci_intr, ih, IST_LEVEL,
238 level, func, arg, "eb64+ irq");
239
240 if (cookie != NULL && alpha_shared_intr_isactive(eb64plus_pci_intr, ih))
241 eb64plus_intr_enable(ih);
242 return (cookie);
243 }
244
245 void
246 dec_eb64plus_intr_disestablish(acv, cookie)
247 void *acv, *cookie;
248 {
249 struct alpha_shared_intrhand *ih = cookie;
250 unsigned int irq = ih->ih_num;
251 int s;
252
253 s = splhigh();
254
255 alpha_shared_intr_disestablish(eb64plus_pci_intr, cookie,
256 "eb64+ irq");
257 if (alpha_shared_intr_isactive(eb64plus_pci_intr, irq) == 0) {
258 eb64plus_intr_disable(irq);
259 alpha_shared_intr_set_dfltsharetype(eb64plus_pci_intr, irq,
260 IST_NONE);
261 }
262
263 splx(s);
264 }
265
266 void
267 eb64plus_iointr(framep, vec)
268 void *framep;
269 unsigned long vec;
270 {
271 int irq;
272
273 if (vec >= 0x900) {
274 if (vec >= 0x900 + (EB64PLUS_MAX_IRQ << 4))
275 panic("eb64plus_iointr: vec 0x%lx out of range\n", vec);
276 irq = (vec - 0x900) >> 4;
277
278 #ifdef EVCNT_COUNTERS
279 eb64plus_intr_evcnt.ev_count++;
280 #else
281 if (EB64PLUS_MAX_IRQ != INTRCNT_EB64PLUS_IRQ_LEN)
282 panic("eb64plus interrupt counter sizes inconsistent");
283 intrcnt[INTRCNT_EB64PLUS_IRQ + irq]++;
284 #endif
285
286 if (!alpha_shared_intr_dispatch(eb64plus_pci_intr, irq)) {
287 alpha_shared_intr_stray(eb64plus_pci_intr, irq,
288 "eb64+ irq");
289 if (ALPHA_SHARED_INTR_DISABLE(eb64plus_pci_intr, irq))
290 eb64plus_intr_disable(irq);
291 }
292 return;
293 }
294 #if NSIO
295 if (vec >= 0x800) {
296 sio_iointr(framep, vec);
297 return;
298 }
299 #endif
300 panic("eb64plus_iointr: weird vec 0x%lx\n", vec);
301 }
302
303 #if 0 /* THIS DOES NOT WORK! see pci_eb64plus_intr.S. */
304 u_int8_t eb64plus_intr_mask[3] = { 0xff, 0xff, 0xff };
305
306 void
307 eb64plus_intr_enable(irq)
308 int irq;
309 {
310 int byte = (irq / 8), bit = (irq % 8);
311
312 #if 1
313 printf("eb64plus_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
314 #endif
315 eb64plus_intr_mask[byte] &= ~(1 << bit);
316
317 bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
318 eb64plus_intr_mask[byte]);
319 }
320
321 void
322 eb64plus_intr_disable(irq)
323 int irq;
324 {
325 int byte = (irq / 8), bit = (irq % 8);
326
327 #if 1
328 printf("eb64plus_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
329 #endif
330 eb64plus_intr_mask[byte] |= (1 << bit);
331
332 bus_space_write_1(eb64plus_intrgate_iot, eb64plus_intrgate_ioh, byte,
333 eb64plus_intr_mask[byte]);
334 }
335 #endif
336