tc_3000_500.c revision 1.9 1 /* $NetBSD: tc_3000_500.c,v 1.9 1996/07/14 04:06:28 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994, 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/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
33
34 #include <machine/autoconf.h>
35 #include <machine/pte.h>
36 #ifndef EVCNT_COUNTERS
37 #include <machine/intrcnt.h>
38 #endif
39
40 #include <dev/tc/tcvar.h>
41 #include <alpha/tc/tc_conf.h>
42 #include <alpha/tc/tc_3000_500.h>
43
44 void tc_3000_500_intr_setup __P((void));
45 void tc_3000_500_intr_establish __P((struct device *, void *,
46 tc_intrlevel_t, int (*)(void *), void *));
47 void tc_3000_500_intr_disestablish __P((struct device *, void *));
48 void tc_3000_500_iointr __P((void *, unsigned long));
49
50 int tc_3000_500_intrnull __P((void *));
51
52 #define C(x) ((void *)(u_long)x)
53 #define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
54
55 struct tc_slotdesc tc_3000_500_slots[] = {
56 { KV(0x100000000), C(TC_3000_500_DEV_OPT0), }, /* 0 - opt slot 0 */
57 { KV(0x120000000), C(TC_3000_500_DEV_OPT1), }, /* 1 - opt slot 1 */
58 { KV(0x140000000), C(TC_3000_500_DEV_OPT2), }, /* 2 - opt slot 2 */
59 { KV(0x160000000), C(TC_3000_500_DEV_OPT3), }, /* 3 - opt slot 3 */
60 { KV(0x180000000), C(TC_3000_500_DEV_OPT4), }, /* 4 - opt slot 4 */
61 { KV(0x1a0000000), C(TC_3000_500_DEV_OPT5), }, /* 5 - opt slot 5 */
62 { KV(0x1c0000000), C(TC_3000_500_DEV_BOGUS), }, /* 6 - TCDS ASIC */
63 { KV(0x1e0000000), C(TC_3000_500_DEV_BOGUS), }, /* 7 - IOCTL ASIC */
64 };
65 int tc_3000_500_nslots =
66 sizeof(tc_3000_500_slots) / sizeof(tc_3000_500_slots[0]);
67
68 struct tc_builtin tc_3000_500_builtins[] = {
69 { "FLAMG-IO", 7, 0x00000000, C(TC_3000_500_DEV_IOASIC), },
70 { "PMAGB-BA", 7, 0x02000000, C(TC_3000_500_DEV_CXTURBO), },
71 { "PMAZ-DS ", 6, 0x00000000, C(TC_3000_500_DEV_TCDS), },
72 };
73 int tc_3000_500_nbuiltins =
74 sizeof(tc_3000_500_builtins) / sizeof(tc_3000_500_builtins[0]);
75
76 u_int32_t tc_3000_500_intrbits[TC_3000_500_NCOOKIES] = {
77 TC_3000_500_IR_OPT0,
78 TC_3000_500_IR_OPT1,
79 TC_3000_500_IR_OPT2,
80 TC_3000_500_IR_OPT3,
81 TC_3000_500_IR_OPT4,
82 TC_3000_500_IR_OPT5,
83 TC_3000_500_IR_TCDS,
84 TC_3000_500_IR_IOASIC,
85 TC_3000_500_IR_CXTURBO,
86 };
87
88 struct tcintr {
89 int (*tci_func) __P((void *));
90 void *tci_arg;
91 } tc_3000_500_intr[TC_3000_500_NCOOKIES];
92
93 u_int32_t tc_3000_500_imask; /* intrs we want to ignore; mirrors IMR. */
94
95 void
96 tc_3000_500_intr_setup()
97 {
98 u_long i;
99
100 /*
101 * Disable all slot interrupts. Note that this cannot
102 * actually disable CXTurbo, TCDS, and IOASIC interrupts.
103 */
104 tc_3000_500_imask = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
105 for (i = 0; i < TC_3000_500_NCOOKIES; i++)
106 tc_3000_500_imask |= tc_3000_500_intrbits[i];
107 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
108 tc_mb();
109
110 /*
111 * Set up interrupt handlers.
112 */
113 for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
114 tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
115 tc_3000_500_intr[i].tci_arg = (void *)i;
116 }
117 }
118
119 void
120 tc_3000_500_intr_establish(tcadev, cookie, level, func, arg)
121 struct device *tcadev;
122 void *cookie, *arg;
123 tc_intrlevel_t level;
124 int (*func) __P((void *));
125 {
126 u_long dev = (u_long)cookie;
127
128 #ifdef DIAGNOSTIC
129 /* XXX bounds-check cookie. */
130 #endif
131
132 if (tc_3000_500_intr[dev].tci_func != tc_3000_500_intrnull)
133 panic("tc_3000_500_intr_establish: cookie %d twice", dev);
134
135 tc_3000_500_intr[dev].tci_func = func;
136 tc_3000_500_intr[dev].tci_arg = arg;
137
138 tc_3000_500_imask &= ~tc_3000_500_intrbits[dev];
139 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
140 tc_mb();
141 }
142
143 void
144 tc_3000_500_intr_disestablish(tcadev, cookie)
145 struct device *tcadev;
146 void *cookie;
147 {
148 u_long dev = (u_long)cookie;
149
150 #ifdef DIAGNOSTIC
151 /* XXX bounds-check cookie. */
152 #endif
153
154 if (tc_3000_500_intr[dev].tci_func == tc_3000_500_intrnull)
155 panic("tc_3000_500_intr_disestablish: cookie %d bad intr",
156 dev);
157
158 tc_3000_500_imask |= tc_3000_500_intrbits[dev];
159 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
160 tc_mb();
161
162 tc_3000_500_intr[dev].tci_func = tc_3000_500_intrnull;
163 tc_3000_500_intr[dev].tci_arg = (void *)dev;
164 }
165
166 int
167 tc_3000_500_intrnull(val)
168 void *val;
169 {
170
171 panic("tc_3000_500_intrnull: uncaught TC intr for cookie %ld\n",
172 (u_long)val);
173 }
174
175 void
176 tc_3000_500_iointr(framep, vec)
177 void *framep;
178 unsigned long vec;
179 {
180 u_int32_t ir;
181 int ifound;
182
183 #ifdef DIAGNOSTIC
184 int s;
185 if (vec != 0x800)
186 panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
187 s = splhigh();
188 if (s != ALPHA_PSL_IPL_IO)
189 panic("INVALID ASSUMPTION: IPL %d, not %d", s,
190 ALPHA_PSL_IPL_IO);
191 splx(s);
192 #endif
193
194 do {
195 tc_syncbus();
196 ir = *(volatile u_int32_t *)TC_3000_500_IR_CLEAR;
197
198 /* Ignore interrupts that we haven't enabled. */
199 ir &= ~(tc_3000_500_imask & 0x1ff);
200
201 ifound = 0;
202
203 #ifdef EVCNT_COUNTERS
204 /* No interrupt counting via evcnt counters */
205 XXX BREAK HERE XXX
206 #else /* !EVCNT_COUNTERS */
207 #define INCRINTRCNT(slot) intrcnt[INTRCNT_KN15 + slot]++
208 #endif /* EVCNT_COUNTERS */
209
210 #define CHECKINTR(slot) \
211 if (ir & tc_3000_500_intrbits[slot]) { \
212 ifound = 1; \
213 INCRINTRCNT(slot); \
214 (*tc_3000_500_intr[slot].tci_func) \
215 (tc_3000_500_intr[slot].tci_arg); \
216 }
217 /* Do them in order of priority; highest slot # first. */
218 CHECKINTR(TC_3000_500_DEV_CXTURBO);
219 CHECKINTR(TC_3000_500_DEV_IOASIC);
220 CHECKINTR(TC_3000_500_DEV_TCDS);
221 CHECKINTR(TC_3000_500_DEV_OPT5);
222 CHECKINTR(TC_3000_500_DEV_OPT4);
223 CHECKINTR(TC_3000_500_DEV_OPT3);
224 CHECKINTR(TC_3000_500_DEV_OPT2);
225 CHECKINTR(TC_3000_500_DEV_OPT1);
226 CHECKINTR(TC_3000_500_DEV_OPT0);
227 #undef CHECKINTR
228
229 #ifdef DIAGNOSTIC
230 #define PRINTINTR(msg, bits) \
231 if (ir & bits) \
232 printf(msg);
233 PRINTINTR("Second error occurred\n", TC_3000_500_IR_ERR2);
234 PRINTINTR("DMA buffer error\n", TC_3000_500_IR_DMABE);
235 PRINTINTR("DMA cross 2K boundary\n", TC_3000_500_IR_DMA2K);
236 PRINTINTR("TC reset in progress\n", TC_3000_500_IR_TCRESET);
237 PRINTINTR("TC parity error\n", TC_3000_500_IR_TCPAR);
238 PRINTINTR("DMA tag error\n", TC_3000_500_IR_DMATAG);
239 PRINTINTR("Single-bit error\n", TC_3000_500_IR_DMASBE);
240 PRINTINTR("Double-bit error\n", TC_3000_500_IR_DMADBE);
241 PRINTINTR("TC I/O timeout\n", TC_3000_500_IR_TCTIMEOUT);
242 PRINTINTR("DMA block too long\n", TC_3000_500_IR_DMABLOCK);
243 PRINTINTR("Invalid I/O address\n", TC_3000_500_IR_IOADDR);
244 PRINTINTR("DMA scatter/gather invalid\n", TC_3000_500_IR_DMASG);
245 PRINTINTR("Scatter/gather parity error\n",
246 TC_3000_500_IR_SGPAR);
247 #undef PRINTINTR
248 #endif
249 } while (ifound);
250 }
251
252 #if 0
253 /*
254 * tc_3000_500_ioslot --
255 * Set the PBS bits for devices on the TC.
256 */
257 void
258 tc_3000_500_ioslot(slot, flags, set)
259 u_int32_t slot, flags;
260 int set;
261 {
262 volatile u_int32_t *iosp;
263 u_int32_t ios;
264 int s;
265
266 iosp = (volatile u_int32_t *)TC_3000_500_IOSLOT;
267 ios = *iosp;
268 flags <<= (slot * 3);
269 if (set)
270 ios |= flags;
271 else
272 ios &= ~flags;
273 s = splhigh();
274 *iosp = ios;
275 tc_mb();
276 splx(s);
277 }
278 #endif
279