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