pci_kn20aa.c revision 1.26 1 /* $NetBSD: pci_kn20aa.c,v 1.26 1997/09/02 20:10:30 thorpej 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: pci_kn20aa.c,v 1.26 1997/09/02 20:10:30 thorpej Exp $");
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/malloc.h>
40 #include <sys/device.h>
41 #include <sys/syslog.h>
42
43 #include <vm/vm.h>
44
45 #include <machine/autoconf.h>
46
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49
50 #include <alpha/pci/ciareg.h>
51 #include <alpha/pci/ciavar.h>
52
53 #include <alpha/pci/pci_kn20aa.h>
54
55 #ifndef EVCNT_COUNTERS
56 #include <machine/intrcnt.h>
57 #endif
58
59 #include "sio.h"
60 #if NSIO
61 #include <alpha/pci/siovar.h>
62 #endif
63
64 int dec_kn20aa_intr_map __P((void *, pcitag_t, int, int,
65 pci_intr_handle_t *));
66 const char *dec_kn20aa_intr_string __P((void *, pci_intr_handle_t));
67 void *dec_kn20aa_intr_establish __P((void *, pci_intr_handle_t,
68 int, int (*func)(void *), void *));
69 void dec_kn20aa_intr_disestablish __P((void *, void *));
70
71 #define KN20AA_PCEB_IRQ 31
72 #define KN20AA_MAX_IRQ 32
73 #define PCI_STRAY_MAX 5
74
75 struct alpha_shared_intr *kn20aa_pci_intr;
76 #ifdef EVCNT_COUNTERS
77 struct evcnt kn20aa_intr_evcnt;
78 #endif
79
80 void kn20aa_iointr __P((void *framep, unsigned long vec));
81 void kn20aa_enable_intr __P((int irq));
82 void kn20aa_disable_intr __P((int irq));
83
84 void
85 pci_kn20aa_pickintr(ccp)
86 struct cia_config *ccp;
87 {
88 int i;
89 bus_space_tag_t iot = &ccp->cc_iot;
90 pci_chipset_tag_t pc = &ccp->cc_pc;
91
92 pc->pc_intr_v = ccp;
93 pc->pc_intr_map = dec_kn20aa_intr_map;
94 pc->pc_intr_string = dec_kn20aa_intr_string;
95 pc->pc_intr_establish = dec_kn20aa_intr_establish;
96 pc->pc_intr_disestablish = dec_kn20aa_intr_disestablish;
97
98 kn20aa_pci_intr = alpha_shared_intr_alloc(KN20AA_MAX_IRQ);
99 for (i = 0; i < KN20AA_MAX_IRQ; i++)
100 alpha_shared_intr_set_maxstrays(kn20aa_pci_intr, i,
101 PCI_STRAY_MAX);
102
103 #if NSIO
104 sio_intr_setup(iot);
105 kn20aa_enable_intr(KN20AA_PCEB_IRQ);
106 #endif
107
108 set_iointr(kn20aa_iointr);
109 }
110
111 int
112 dec_kn20aa_intr_map(ccv, bustag, buspin, line, ihp)
113 void *ccv;
114 pcitag_t bustag;
115 int buspin, line;
116 pci_intr_handle_t *ihp;
117 {
118 struct cia_config *ccp = ccv;
119 pci_chipset_tag_t pc = &ccp->cc_pc;
120 int device;
121 int kn20aa_irq;
122
123 if (buspin == 0) {
124 /* No IRQ used. */
125 return 1;
126 }
127 if (buspin > 4) {
128 printf("pci_map_int: bad interrupt pin %d\n", buspin);
129 return 1;
130 }
131
132 /*
133 * Slot->interrupt translation. Appears to work, though it
134 * may not hold up forever.
135 *
136 * The DEC engineers who did this hardware obviously engaged
137 * in random drug testing.
138 */
139 alpha_pci_decompose_tag(pc, bustag, NULL, &device, NULL);
140 switch (device) {
141 case 11:
142 case 12:
143 kn20aa_irq = ((device - 11) + 0) * 4;
144 break;
145
146 case 7:
147 kn20aa_irq = 8;
148 break;
149
150 case 9:
151 kn20aa_irq = 12;
152 break;
153
154 case 6: /* 21040 on AlphaStation 500 */
155 kn20aa_irq = 13;
156 break;
157
158 case 8:
159 kn20aa_irq = 16;
160 break;
161
162 default:
163 printf("dec_kn20aa_intr_map: weird device number %d\n",
164 device);
165 return 1;
166 }
167
168 kn20aa_irq += buspin - 1;
169 if (kn20aa_irq > KN20AA_MAX_IRQ)
170 panic("pci_kn20aa_map_int: kn20aa_irq too large (%d)\n",
171 kn20aa_irq);
172
173 *ihp = kn20aa_irq;
174 return (0);
175 }
176
177 const char *
178 dec_kn20aa_intr_string(ccv, ih)
179 void *ccv;
180 pci_intr_handle_t ih;
181 {
182 #if 0
183 struct cia_config *ccp = ccv;
184 #endif
185 static char irqstr[15]; /* 11 + 2 + NULL + sanity */
186
187 if (ih > KN20AA_MAX_IRQ)
188 panic("dec_kn20aa_intr_string: bogus kn20aa IRQ 0x%x\n",
189 ih);
190
191 sprintf(irqstr, "kn20aa irq %ld", ih);
192 return (irqstr);
193 }
194
195 void *
196 dec_kn20aa_intr_establish(ccv, ih, level, func, arg)
197 void *ccv, *arg;
198 pci_intr_handle_t ih;
199 int level;
200 int (*func) __P((void *));
201 {
202 #if 0
203 struct cia_config *ccp = ccv;
204 #endif
205 void *cookie;
206
207 if (ih > KN20AA_MAX_IRQ)
208 panic("dec_kn20aa_intr_establish: bogus kn20aa IRQ 0x%x\n",
209 ih);
210
211 cookie = alpha_shared_intr_establish(kn20aa_pci_intr, ih, IST_LEVEL,
212 level, func, arg, "kn20aa irq");
213
214 if (cookie != NULL &&
215 alpha_shared_intr_isactive(kn20aa_pci_intr, ih))
216 kn20aa_enable_intr(ih);
217 return (cookie);
218 }
219
220 void
221 dec_kn20aa_intr_disestablish(ccv, cookie)
222 void *ccv, *cookie;
223 {
224 #if 0
225 struct cia_config *ccp = ccv;
226 #endif
227
228 panic("dec_kn20aa_intr_disestablish not implemented"); /* XXX */
229 }
230
231 void
232 kn20aa_iointr(framep, vec)
233 void *framep;
234 unsigned long vec;
235 {
236 int irq;
237
238 if (vec >= 0x900) {
239 if (vec >= 0x900 + (KN20AA_MAX_IRQ << 4))
240 panic("kn20aa_iointr: vec 0x%x out of range\n", vec);
241 irq = (vec - 0x900) >> 4;
242
243 #ifdef EVCNT_COUNTERS
244 kn20aa_intr_evcnt.ev_count++;
245 #else
246 if (KN20AA_MAX_IRQ != INTRCNT_KN20AA_IRQ_LEN)
247 panic("kn20aa interrupt counter sizes inconsistent");
248 intrcnt[INTRCNT_KN20AA_IRQ + irq]++;
249 #endif
250
251 if (!alpha_shared_intr_dispatch(kn20aa_pci_intr, irq)) {
252 alpha_shared_intr_stray(kn20aa_pci_intr, irq,
253 "kn20aa irq");
254 if (kn20aa_pci_intr[irq].intr_nstrays ==
255 kn20aa_pci_intr[irq].intr_maxstrays)
256 kn20aa_disable_intr(irq);
257 }
258 return;
259 }
260 #if NSIO
261 if (vec >= 0x800) {
262 sio_iointr(framep, vec);
263 return;
264 }
265 #endif
266 panic("kn20aa_iointr: weird vec 0x%x\n", vec);
267 }
268
269 void
270 kn20aa_enable_intr(irq)
271 int irq;
272 {
273
274 /*
275 * From disassembling small bits of the OSF/1 kernel:
276 * the following appears to enable a given interrupt request.
277 * "blech." I'd give valuable body parts for better docs or
278 * for a good decompiler.
279 */
280 alpha_mb();
281 REGVAL(0x8780000000L + 0x40L) |= (1 << irq); /* XXX */
282 alpha_mb();
283 }
284
285 void
286 kn20aa_disable_intr(irq)
287 int irq;
288 {
289
290 alpha_mb();
291 REGVAL(0x8780000000L + 0x40L) &= ~(1 << irq); /* XXX */
292 alpha_mb();
293 }
294