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