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