tc_3000_500.c revision 1.22 1 /* $NetBSD: tc_3000_500.c,v 1.22 2000/06/04 19:14:29 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/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: tc_3000_500.c,v 1.22 2000/06/04 19:14:29 cgd Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <machine/autoconf.h>
39 #include <machine/pte.h>
40 #include <machine/rpb.h>
41 #ifndef EVCNT_COUNTERS
42 #include <machine/intrcnt.h>
43 #endif
44
45 #include <dev/tc/tcvar.h>
46 #include <alpha/tc/tc_conf.h>
47 #include <alpha/tc/tc_3000_500.h>
48
49 #include "wsdisplay.h"
50 #include "sfb.h"
51
52 #if NSFB > 0
53 extern int sfb_cnattach __P((tc_addr_t));
54 #endif
55
56 void tc_3000_500_intr_setup __P((void));
57 void tc_3000_500_intr_establish __P((struct device *, void *,
58 tc_intrlevel_t, int (*)(void *), void *));
59 void tc_3000_500_intr_disestablish __P((struct device *, void *));
60 void tc_3000_500_iointr __P((void *, unsigned long));
61
62 int tc_3000_500_intrnull __P((void *));
63 int tc_3000_500_fb_cnattach __P((u_int64_t));
64
65 #define C(x) ((void *)(u_long)x)
66 #define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
67
68 struct tc_slotdesc tc_3000_500_slots[] = {
69 { KV(0x100000000), C(TC_3000_500_DEV_OPT0), }, /* 0 - opt slot 0 */
70 { KV(0x120000000), C(TC_3000_500_DEV_OPT1), }, /* 1 - opt slot 1 */
71 { KV(0x140000000), C(TC_3000_500_DEV_OPT2), }, /* 2 - opt slot 2 */
72 { KV(0x160000000), C(TC_3000_500_DEV_OPT3), }, /* 3 - opt slot 3 */
73 { KV(0x180000000), C(TC_3000_500_DEV_OPT4), }, /* 4 - opt slot 4 */
74 { KV(0x1a0000000), C(TC_3000_500_DEV_OPT5), }, /* 5 - opt slot 5 */
75 { KV(0x1c0000000), C(TC_3000_500_DEV_BOGUS), }, /* 6 - TCDS ASIC */
76 { KV(0x1e0000000), C(TC_3000_500_DEV_BOGUS), }, /* 7 - IOCTL ASIC */
77 };
78 int tc_3000_500_nslots =
79 sizeof(tc_3000_500_slots) / sizeof(tc_3000_500_slots[0]);
80
81 struct tc_builtin tc_3000_500_graphics_builtins[] = {
82 { "FLAMG-IO", 7, 0x00000000, C(TC_3000_500_DEV_IOASIC), },
83 { "PMAGB-BA", 7, 0x02000000, C(TC_3000_500_DEV_CXTURBO), },
84 { "PMAZ-DS ", 6, 0x00000000, C(TC_3000_500_DEV_TCDS), },
85 };
86 int tc_3000_500_graphics_nbuiltins = sizeof(tc_3000_500_graphics_builtins) /
87 sizeof(tc_3000_500_graphics_builtins[0]);
88
89 struct tc_builtin tc_3000_500_nographics_builtins[] = {
90 { "FLAMG-IO", 7, 0x00000000, C(TC_3000_500_DEV_IOASIC), },
91 { "PMAZ-DS ", 6, 0x00000000, C(TC_3000_500_DEV_TCDS), },
92 };
93 int tc_3000_500_nographics_nbuiltins = sizeof(tc_3000_500_nographics_builtins) /
94 sizeof(tc_3000_500_nographics_builtins[0]);
95
96 u_int32_t tc_3000_500_intrbits[TC_3000_500_NCOOKIES] = {
97 TC_3000_500_IR_OPT0,
98 TC_3000_500_IR_OPT1,
99 TC_3000_500_IR_OPT2,
100 TC_3000_500_IR_OPT3,
101 TC_3000_500_IR_OPT4,
102 TC_3000_500_IR_OPT5,
103 TC_3000_500_IR_TCDS,
104 TC_3000_500_IR_IOASIC,
105 TC_3000_500_IR_CXTURBO,
106 };
107
108 struct tcintr {
109 int (*tci_func) __P((void *));
110 void *tci_arg;
111 } tc_3000_500_intr[TC_3000_500_NCOOKIES];
112
113 u_int32_t tc_3000_500_imask; /* intrs we want to ignore; mirrors IMR. */
114
115 void
116 tc_3000_500_intr_setup()
117 {
118 u_long i;
119
120 /*
121 * Disable all slot interrupts. Note that this cannot
122 * actually disable CXTurbo, TCDS, and IOASIC interrupts.
123 */
124 tc_3000_500_imask = *(volatile u_int32_t *)TC_3000_500_IMR_READ;
125 for (i = 0; i < TC_3000_500_NCOOKIES; i++)
126 tc_3000_500_imask |= tc_3000_500_intrbits[i];
127 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
128 tc_mb();
129
130 /*
131 * Set up interrupt handlers.
132 */
133 for (i = 0; i < TC_3000_500_NCOOKIES; i++) {
134 tc_3000_500_intr[i].tci_func = tc_3000_500_intrnull;
135 tc_3000_500_intr[i].tci_arg = (void *)i;
136 }
137 }
138
139 const struct evcnt *
140 tc_3000_500_intr_evcnt(tcadev, cookie)
141 struct device *tcadev;
142 void *cookie;
143 {
144
145 /* XXX for now, no evcnt parent reported */
146 return (NULL);
147 }
148
149 void
150 tc_3000_500_intr_establish(tcadev, cookie, level, func, arg)
151 struct device *tcadev;
152 void *cookie, *arg;
153 tc_intrlevel_t level;
154 int (*func) __P((void *));
155 {
156 u_long dev = (u_long)cookie;
157
158 #ifdef DIAGNOSTIC
159 /* XXX bounds-check cookie. */
160 #endif
161
162 if (tc_3000_500_intr[dev].tci_func != tc_3000_500_intrnull)
163 panic("tc_3000_500_intr_establish: cookie %lu twice", dev);
164
165 tc_3000_500_intr[dev].tci_func = func;
166 tc_3000_500_intr[dev].tci_arg = arg;
167
168 tc_3000_500_imask &= ~tc_3000_500_intrbits[dev];
169 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
170 tc_mb();
171 }
172
173 void
174 tc_3000_500_intr_disestablish(tcadev, cookie)
175 struct device *tcadev;
176 void *cookie;
177 {
178 u_long dev = (u_long)cookie;
179
180 #ifdef DIAGNOSTIC
181 /* XXX bounds-check cookie. */
182 #endif
183
184 if (tc_3000_500_intr[dev].tci_func == tc_3000_500_intrnull)
185 panic("tc_3000_500_intr_disestablish: cookie %lu bad intr",
186 dev);
187
188 tc_3000_500_imask |= tc_3000_500_intrbits[dev];
189 *(volatile u_int32_t *)TC_3000_500_IMR_WRITE = tc_3000_500_imask;
190 tc_mb();
191
192 tc_3000_500_intr[dev].tci_func = tc_3000_500_intrnull;
193 tc_3000_500_intr[dev].tci_arg = (void *)dev;
194 }
195
196 int
197 tc_3000_500_intrnull(val)
198 void *val;
199 {
200
201 panic("tc_3000_500_intrnull: uncaught TC intr for cookie %ld\n",
202 (u_long)val);
203 }
204
205 void
206 tc_3000_500_iointr(framep, vec)
207 void *framep;
208 unsigned long vec;
209 {
210 u_int32_t ir;
211 int ifound;
212
213 #ifdef DIAGNOSTIC
214 int s;
215 if (vec != 0x800)
216 panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
217 s = splhigh();
218 if (s != ALPHA_PSL_IPL_IO)
219 panic("INVALID ASSUMPTION: IPL %d, not %d", s,
220 ALPHA_PSL_IPL_IO);
221 splx(s);
222 #endif
223
224 do {
225 tc_syncbus();
226 ir = *(volatile u_int32_t *)TC_3000_500_IR_CLEAR;
227
228 /* Ignore interrupts that we haven't enabled. */
229 ir &= ~(tc_3000_500_imask & 0x1ff);
230
231 ifound = 0;
232
233 #ifdef EVCNT_COUNTERS
234 /* No interrupt counting via evcnt counters */
235 XXX BREAK HERE XXX
236 #else /* !EVCNT_COUNTERS */
237 #define INCRINTRCNT(slot) intrcnt[INTRCNT_KN15 + slot]++
238 #endif /* EVCNT_COUNTERS */
239
240 #define CHECKINTR(slot) \
241 if (ir & tc_3000_500_intrbits[slot]) { \
242 ifound = 1; \
243 INCRINTRCNT(slot); \
244 (*tc_3000_500_intr[slot].tci_func) \
245 (tc_3000_500_intr[slot].tci_arg); \
246 }
247 /* Do them in order of priority; highest slot # first. */
248 CHECKINTR(TC_3000_500_DEV_CXTURBO);
249 CHECKINTR(TC_3000_500_DEV_IOASIC);
250 CHECKINTR(TC_3000_500_DEV_TCDS);
251 CHECKINTR(TC_3000_500_DEV_OPT5);
252 CHECKINTR(TC_3000_500_DEV_OPT4);
253 CHECKINTR(TC_3000_500_DEV_OPT3);
254 CHECKINTR(TC_3000_500_DEV_OPT2);
255 CHECKINTR(TC_3000_500_DEV_OPT1);
256 CHECKINTR(TC_3000_500_DEV_OPT0);
257 #undef CHECKINTR
258
259 #ifdef DIAGNOSTIC
260 #define PRINTINTR(msg, bits) \
261 if (ir & bits) \
262 printf(msg);
263 PRINTINTR("Second error occurred\n", TC_3000_500_IR_ERR2);
264 PRINTINTR("DMA buffer error\n", TC_3000_500_IR_DMABE);
265 PRINTINTR("DMA cross 2K boundary\n", TC_3000_500_IR_DMA2K);
266 PRINTINTR("TC reset in progress\n", TC_3000_500_IR_TCRESET);
267 PRINTINTR("TC parity error\n", TC_3000_500_IR_TCPAR);
268 PRINTINTR("DMA tag error\n", TC_3000_500_IR_DMATAG);
269 PRINTINTR("Single-bit error\n", TC_3000_500_IR_DMASBE);
270 PRINTINTR("Double-bit error\n", TC_3000_500_IR_DMADBE);
271 PRINTINTR("TC I/O timeout\n", TC_3000_500_IR_TCTIMEOUT);
272 PRINTINTR("DMA block too long\n", TC_3000_500_IR_DMABLOCK);
273 PRINTINTR("Invalid I/O address\n", TC_3000_500_IR_IOADDR);
274 PRINTINTR("DMA scatter/gather invalid\n", TC_3000_500_IR_DMASG);
275 PRINTINTR("Scatter/gather parity error\n",
276 TC_3000_500_IR_SGPAR);
277 #undef PRINTINTR
278 #endif
279 } while (ifound);
280 }
281
282 #if NWSDISPLAY > 0
283 /*
284 * tc_3000_500_fb_cnattach --
285 * Attempt to map the CTB output device to a slot and attach the
286 * framebuffer as the output side of the console.
287 */
288 int
289 tc_3000_500_fb_cnattach(turbo_slot)
290 u_int64_t turbo_slot;
291 {
292 u_int32_t output_slot;
293
294 output_slot = turbo_slot & 0xffffffff;
295
296 if (output_slot >= tc_3000_500_nslots) {
297 return EINVAL;
298 }
299
300 if (hwrpb->rpb_variation & SV_GRAPHICS) {
301 if (output_slot == 0) {
302 #if NSFB > 0
303 sfb_cnattach(KV(0x1e0000000) + 0x02000000);
304 return 0;
305 #else
306 return ENXIO;
307 #endif
308 }
309 } else {
310 /*
311 * Slots 0-2 in the tc_3000_500_slots array are only
312 * on the 500 models that also have the CXTurbo
313 * (500/800/900) and a total of 6 TC slots. For the
314 * 400/600/700, slots 0-2 are in table locations 3-5, so
315 * offset the CTB slot by 3 to get the address in our table.
316 */
317 output_slot += 3;
318 }
319 return tc_fb_cnattach(tc_3000_500_slots[output_slot-1].tcs_addr);
320 }
321 #endif /* NWSDISPLAY */
322
323 #if 0
324 /*
325 * tc_3000_500_ioslot --
326 * Set the PBS bits for devices on the TC.
327 */
328 void
329 tc_3000_500_ioslot(slot, flags, set)
330 u_int32_t slot, flags;
331 int set;
332 {
333 volatile u_int32_t *iosp;
334 u_int32_t ios;
335 int s;
336
337 iosp = (volatile u_int32_t *)TC_3000_500_IOSLOT;
338 ios = *iosp;
339 flags <<= (slot * 3);
340 if (set)
341 ios |= flags;
342 else
343 ios &= ~flags;
344 s = splhigh();
345 *iosp = ios;
346 tc_mb();
347 splx(s);
348 }
349 #endif
350