pci_eb164.c revision 1.7 1 /* $NetBSD: pci_eb164.c,v 1.7 1997/05/31 05:46:08 cgd 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 <machine/options.h> /* Config options headers */
31 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
32
33 __KERNEL_RCSID(0, "$NetBSD: pci_eb164.c,v 1.7 1997/05/31 05:46:08 cgd Exp $");
34
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/time.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/malloc.h>
41 #include <sys/device.h>
42 #include <sys/syslog.h>
43
44 #include <vm/vm.h>
45
46 #include <machine/autoconf.h>
47
48 #include <dev/pci/pcireg.h>
49 #include <dev/pci/pcivar.h>
50
51 #include <alpha/pci/ciareg.h>
52 #include <alpha/pci/ciavar.h>
53
54 #include <alpha/pci/pci_eb164.h>
55
56 #ifndef EVCNT_COUNTERS
57 #include <machine/intrcnt.h>
58 #endif
59
60 #include "sio.h"
61 #if NSIO
62 #include <alpha/pci/siovar.h>
63 #endif
64
65 int dec_eb164_intr_map __P((void *, pcitag_t, int, int,
66 pci_intr_handle_t *));
67 const char *dec_eb164_intr_string __P((void *, pci_intr_handle_t));
68 void *dec_eb164_intr_establish __P((void *, pci_intr_handle_t,
69 int, int (*func)(void *), void *));
70 void dec_eb164_intr_disestablish __P((void *, void *));
71
72 #define EB164_SIO_IRQ 4
73 #define EB164_MAX_IRQ 24
74 #define PCI_STRAY_MAX 5
75
76 struct alpha_shared_intr *eb164_pci_intr;
77 #ifdef EVCNT_COUNTERS
78 struct evcnt eb164_intr_evcnt;
79 #endif
80
81 bus_space_tag_t eb164_intrgate_iot;
82 bus_space_handle_t eb164_intrgate_ioh;
83
84 void eb164_iointr __P((void *framep, unsigned long vec));
85 extern void eb164_intr_enable __P((int irq)); /* pci_eb164_intr.S */
86 extern void eb164_intr_disable __P((int irq)); /* pci_eb164_intr.S */
87
88 void
89 pci_eb164_pickintr(ccp)
90 struct cia_config *ccp;
91 {
92 bus_space_tag_t iot = ccp->cc_iot;
93 pci_chipset_tag_t pc = &ccp->cc_pc;
94 int i;
95
96 pc->pc_intr_v = ccp;
97 pc->pc_intr_map = dec_eb164_intr_map;
98 pc->pc_intr_string = dec_eb164_intr_string;
99 pc->pc_intr_establish = dec_eb164_intr_establish;
100 pc->pc_intr_disestablish = dec_eb164_intr_disestablish;
101
102 eb164_intrgate_iot = iot;
103 if (bus_space_map(eb164_intrgate_iot, 0x804, 3, 0,
104 &eb164_intrgate_ioh) != 0)
105 panic("pci_eb164_pickintr: couldn't map interrupt PLD");
106 for (i = 0; i < EB164_MAX_IRQ; i++)
107 eb164_intr_disable(i);
108
109 eb164_pci_intr = alpha_shared_intr_alloc(EB164_MAX_IRQ);
110 for (i = 0; i < EB164_MAX_IRQ; i++)
111 alpha_shared_intr_set_maxstrays(eb164_pci_intr, i,
112 PCI_STRAY_MAX);
113
114 #if NSIO
115 sio_intr_setup(iot);
116 eb164_intr_enable(EB164_SIO_IRQ);
117 #endif
118
119 set_iointr(eb164_iointr);
120 }
121
122 int
123 dec_eb164_intr_map(ccv, bustag, buspin, line, ihp)
124 void *ccv;
125 pcitag_t bustag;
126 int buspin, line;
127 pci_intr_handle_t *ihp;
128 {
129 struct cia_config *ccp = ccv;
130 pci_chipset_tag_t pc = &ccp->cc_pc;
131 int device;
132 int eb164_irq, pinbase, pinoff;
133
134 #ifndef DIAGNOSTIC
135 pinbase = pinoff = 0; /* XXX gcc -Wuninitialized */
136 #endif
137
138 if (buspin == 0) {
139 /* No IRQ used. */
140 return 1;
141 }
142 if (buspin > 4) {
143 printf("pci_map_int: bad interrupt pin %d\n", buspin);
144 return 1;
145 }
146
147 pci_decompose_tag(pc, bustag, NULL, &device, NULL);
148 switch (device) {
149 #if 0 /* THIS CODE SHOULD NEVER BE CALLED FOR THE SIO */
150 case 8: /* SIO */
151 eb164_irq = 4;
152 break;
153 #endif
154
155 case 11:
156 eb164_irq = 5; /* IDE */
157 break;
158
159 case 5:
160 case 6:
161 case 7:
162 case 9:
163 switch (buspin) {
164 case 1:
165 pinbase = 0;
166 break;
167 case 2:
168 case 3:
169 case 4:
170 pinbase = (buspin * 4) - 1;
171 break;
172 #ifdef DIAGNOSTIC
173 default:
174 panic("dec_eb164_intr_map: slot buspin switch");
175 #endif
176 };
177 switch (device) {
178 case 5:
179 pinoff = 2;
180 break;
181
182 case 6:
183 case 7:
184 case 9:
185 pinoff = device - 6;
186 break;
187 #ifdef DIAGNOSTIC
188 default:
189 panic("dec_eb164_intr_map: slot device switch");
190 #endif
191 }
192 eb164_irq = pinoff + pinbase;
193 break;
194 default:
195 panic("pci_eb164_map_int: invalid device number %d\n",
196 device);
197 }
198
199 if (eb164_irq > EB164_MAX_IRQ)
200 panic("pci_eb164_map_int: eb164_irq too large (%d)\n",
201 eb164_irq);
202
203 *ihp = eb164_irq;
204 return (0);
205 }
206
207 const char *
208 dec_eb164_intr_string(ccv, ih)
209 void *ccv;
210 pci_intr_handle_t ih;
211 {
212 #if 0
213 struct cia_config *ccp = ccv;
214 #endif
215 static char irqstr[15]; /* 11 + 2 + NULL + sanity */
216
217 if (ih > EB164_MAX_IRQ)
218 panic("dec_eb164_intr_string: bogus eb164 IRQ 0x%x\n", ih);
219 sprintf(irqstr, "eb164 irq %d", ih);
220 return (irqstr);
221 }
222
223 void *
224 dec_eb164_intr_establish(ccv, ih, level, func, arg)
225 void *ccv, *arg;
226 pci_intr_handle_t ih;
227 int level;
228 int (*func) __P((void *));
229 {
230 #if 0
231 struct cia_config *ccp = ccv;
232 #endif
233 void *cookie;
234
235 if (ih > EB164_MAX_IRQ)
236 panic("dec_eb164_intr_establish: bogus eb164 IRQ 0x%x\n", ih);
237
238 cookie = alpha_shared_intr_establish(eb164_pci_intr, ih, IST_LEVEL,
239 level, func, arg, "eb164 irq");
240
241 if (cookie != NULL && alpha_shared_intr_isactive(eb164_pci_intr, ih))
242 eb164_intr_enable(ih);
243 return (cookie);
244 }
245
246 void
247 dec_eb164_intr_disestablish(ccv, cookie)
248 void *ccv, *cookie;
249 {
250 #if 0
251 struct cia_config *ccp = ccv;
252 #endif
253
254 panic("dec_eb164_intr_disestablish not implemented"); /* XXX */
255 }
256
257 void
258 eb164_iointr(framep, vec)
259 void *framep;
260 unsigned long vec;
261 {
262 int irq;
263
264 if (vec >= 0x900) {
265 if (vec >= 0x900 + (EB164_MAX_IRQ << 4))
266 panic("eb164_iointr: vec 0x%x out of range\n", vec);
267 irq = (vec - 0x900) >> 4;
268
269 #ifdef EVCNT_COUNTERS
270 eb164_intr_evcnt.ev_count++;
271 #else
272 if (EB164_MAX_IRQ != INTRCNT_EB164_IRQ_LEN)
273 panic("eb164 interrupt counter sizes inconsistent");
274 intrcnt[INTRCNT_EB164_IRQ + irq]++;
275 #endif
276
277 if (!alpha_shared_intr_dispatch(eb164_pci_intr, irq)) {
278 alpha_shared_intr_stray(eb164_pci_intr, irq,
279 "eb164 irq");
280 if (eb164_pci_intr[irq].intr_nstrays ==
281 eb164_pci_intr[irq].intr_maxstrays)
282 eb164_intr_disable(irq);
283 }
284 return;
285 }
286 #if NSIO
287 if (vec >= 0x800) {
288 sio_iointr(framep, vec);
289 return;
290 }
291 #endif
292 panic("eb164_iointr: weird vec 0x%x\n", vec);
293 }
294
295 #if 0 /* THIS DOES NOT WORK! see pci_eb164_intr.S. */
296 u_int8_t eb164_intr_mask[3] = { 0xff, 0xff, 0xff };
297
298 void
299 eb164_intr_enable(irq)
300 int irq;
301 {
302 int byte = (irq / 8), bit = (irq % 8);
303
304 #if 1
305 printf("eb164_intr_enable: enabling %d (%d:%d)\n", irq, byte, bit);
306 #endif
307 eb164_intr_mask[byte] &= ~(1 << bit);
308
309 bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
310 eb164_intr_mask[byte]);
311 }
312
313 void
314 eb164_intr_disable(irq)
315 int irq;
316 {
317 int byte = (irq / 8), bit = (irq % 8);
318
319 #if 1
320 printf("eb164_intr_disable: disabling %d (%d:%d)\n", irq, byte, bit);
321 #endif
322 eb164_intr_mask[byte] |= (1 << bit);
323
324 bus_space_write_1(eb164_intrgate_iot, eb164_intrgate_ioh, byte,
325 eb164_intr_mask[byte]);
326 }
327 #endif
328