tc_3000_300.c revision 1.16 1 /* $NetBSD: tc_3000_300.c,v 1.16 1998/10/22 01:03:09 briggs 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_300.c,v 1.16 1998/10/22 01:03:09 briggs 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 #ifndef EVCNT_COUNTERS
41 #include <machine/intrcnt.h>
42 #endif
43
44 #include <dev/tc/tcvar.h>
45 #include <alpha/tc/tc_conf.h>
46 #include <alpha/tc/tc_3000_300.h>
47 #include <alpha/tc/ioasicreg.h>
48 #include <alpha/tc/sfbvar.h>
49
50 int tc_3000_300_intrnull __P((void *));
51
52 #define C(x) ((void *)(u_long)x)
53 #define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
54
55 /*
56 * We have to read and modify the IOASIC registers directly, because
57 * the TC option slot interrupt request and mask bits are stored there,
58 * and the ioasic code isn't initted when we need to frob some interrupt
59 * bits.
60 */
61 #define DEC_3000_300_IOASIC_ADDR KV(0x1a0000000)
62
63 struct tc_slotdesc tc_3000_300_slots[] = {
64 { KV(0x100000000), C(TC_3000_300_DEV_OPT0), }, /* 0 - opt slot 0 */
65 { KV(0x120000000), C(TC_3000_300_DEV_OPT1), }, /* 1 - opt slot 1 */
66 { KV(0x180000000), C(TC_3000_300_DEV_BOGUS), }, /* 2 - TCDS ASIC */
67 { KV(0x1a0000000), C(TC_3000_300_DEV_BOGUS), }, /* 3 - IOCTL ASIC */
68 { KV(0x1c0000000), C(TC_3000_300_DEV_CXTURBO), }, /* 4 - CXTurbo */
69 };
70 int tc_3000_300_nslots =
71 sizeof(tc_3000_300_slots) / sizeof(tc_3000_300_slots[0]);
72
73 struct tc_builtin tc_3000_300_builtins[] = {
74 { "PMAGB-BA", 4, 0x02000000, C(TC_3000_300_DEV_CXTURBO), },
75 { "FLAMG-IO", 3, 0x00000000, C(TC_3000_300_DEV_IOASIC), },
76 { "PMAZ-DS ", 2, 0x00000000, C(TC_3000_300_DEV_TCDS), },
77 };
78 int tc_3000_300_nbuiltins =
79 sizeof(tc_3000_300_builtins) / sizeof(tc_3000_300_builtins[0]);
80
81 struct tcintr {
82 int (*tci_func) __P((void *));
83 void *tci_arg;
84 } tc_3000_300_intr[TC_3000_300_NCOOKIES];
85
86 void
87 tc_3000_300_intr_setup()
88 {
89 volatile u_int32_t *imskp;
90 u_long i;
91
92 /*
93 * Disable all interrupts that we can (can't disable builtins).
94 */
95 imskp = (volatile u_int32_t *)IOASIC_REG_IMSK(DEC_3000_300_IOASIC_ADDR);
96 *imskp &= ~(IOASIC_INTR_300_OPT0 | IOASIC_INTR_300_OPT1);
97
98 /*
99 * Set up interrupt handlers.
100 */
101 for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
102 tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
103 tc_3000_300_intr[i].tci_arg = (void *)i;
104 }
105 }
106
107 void
108 tc_3000_300_intr_establish(tcadev, cookie, level, func, arg)
109 struct device *tcadev;
110 void *cookie, *arg;
111 tc_intrlevel_t level;
112 int (*func) __P((void *));
113 {
114 volatile u_int32_t *imskp;
115 u_long dev = (u_long)cookie;
116
117 #ifdef DIAGNOSTIC
118 /* XXX bounds-check cookie. */
119 #endif
120
121 if (tc_3000_300_intr[dev].tci_func != tc_3000_300_intrnull)
122 panic("tc_3000_300_intr_establish: cookie %d twice", dev);
123
124 tc_3000_300_intr[dev].tci_func = func;
125 tc_3000_300_intr[dev].tci_arg = arg;
126
127 imskp = (volatile u_int32_t *)IOASIC_REG_IMSK(DEC_3000_300_IOASIC_ADDR);
128 switch (dev) {
129 case TC_3000_300_DEV_OPT0:
130 *imskp |= IOASIC_INTR_300_OPT0;
131 break;
132 case TC_3000_300_DEV_OPT1:
133 *imskp |= IOASIC_INTR_300_OPT1;
134 break;
135 default:
136 /* interrupts for builtins always enabled */
137 break;
138 }
139 }
140
141 void
142 tc_3000_300_intr_disestablish(tcadev, cookie)
143 struct device *tcadev;
144 void *cookie;
145 {
146 volatile u_int32_t *imskp;
147 u_long dev = (u_long)cookie;
148
149 #ifdef DIAGNOSTIC
150 /* XXX bounds-check cookie. */
151 #endif
152
153 if (tc_3000_300_intr[dev].tci_func == tc_3000_300_intrnull)
154 panic("tc_3000_300_intr_disestablish: cookie %d bad intr",
155 dev);
156
157 imskp = (volatile u_int32_t *)IOASIC_REG_IMSK(DEC_3000_300_IOASIC_ADDR);
158 switch (dev) {
159 case TC_3000_300_DEV_OPT0:
160 *imskp &= ~IOASIC_INTR_300_OPT0;
161 break;
162 case TC_3000_300_DEV_OPT1:
163 *imskp &= ~IOASIC_INTR_300_OPT1;
164 break;
165 default:
166 /* interrupts for builtins always enabled */
167 break;
168 }
169
170 tc_3000_300_intr[dev].tci_func = tc_3000_300_intrnull;
171 tc_3000_300_intr[dev].tci_arg = (void *)dev;
172 }
173
174 int
175 tc_3000_300_intrnull(val)
176 void *val;
177 {
178
179 panic("tc_3000_300_intrnull: uncaught TC intr for cookie %ld\n",
180 (u_long)val);
181 }
182
183 void
184 tc_3000_300_iointr(framep, vec)
185 void *framep;
186 unsigned long vec;
187 {
188 u_int32_t tcir, ioasicir, ioasicimr;
189 int ifound;
190
191 #ifdef DIAGNOSTIC
192 int s;
193 if (vec != 0x800)
194 panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
195 s = splhigh();
196 if (s != ALPHA_PSL_IPL_IO)
197 panic("INVALID ASSUMPTION: IPL %d, not %d", s,
198 ALPHA_PSL_IPL_IO);
199 splx(s);
200 #endif
201
202 do {
203 tc_syncbus();
204
205 /* find out what interrupts/errors occurred */
206 tcir = *(volatile u_int32_t *)TC_3000_300_IR;
207 ioasicir = *(volatile u_int32_t *)
208 IOASIC_REG_INTR(DEC_3000_300_IOASIC_ADDR);
209 ioasicimr = *(volatile u_int32_t *)
210 IOASIC_REG_IMSK(DEC_3000_300_IOASIC_ADDR);
211 tc_mb();
212
213 /* Ignore interrupts that aren't enabled out. */
214 ioasicir &= ioasicimr;
215
216 /* clear the interrupts/errors we found. */
217 *(volatile u_int32_t *)TC_3000_300_IR = tcir;
218 /* XXX can't clear TC option slot interrupts here? */
219 tc_wmb();
220
221 ifound = 0;
222
223 #ifdef EVCNT_COUNTERS
224 /* No interrupt counting via evcnt counters */
225 XXX BREAK HERE XXX
226 #else /* !EVCNT_COUNTERS */
227 #define INCRINTRCNT(slot) intrcnt[INTRCNT_KN16 + slot]++
228 #endif /* EVCNT_COUNTERS */
229
230 #define CHECKINTR(slot, flag) \
231 if (flag) { \
232 ifound = 1; \
233 INCRINTRCNT(slot); \
234 (*tc_3000_300_intr[slot].tci_func) \
235 (tc_3000_300_intr[slot].tci_arg); \
236 }
237 /* Do them in order of priority; highest slot # first. */
238 CHECKINTR(TC_3000_300_DEV_CXTURBO,
239 tcir & TC_3000_300_IR_CXTURBO);
240 CHECKINTR(TC_3000_300_DEV_IOASIC,
241 (tcir & TC_3000_300_IR_IOASIC) &&
242 (ioasicir & ~(IOASIC_INTR_300_OPT1|IOASIC_INTR_300_OPT0)));
243 CHECKINTR(TC_3000_300_DEV_TCDS, tcir & TC_3000_300_IR_TCDS);
244 CHECKINTR(TC_3000_300_DEV_OPT1,
245 ioasicir & IOASIC_INTR_300_OPT1);
246 CHECKINTR(TC_3000_300_DEV_OPT0,
247 ioasicir & IOASIC_INTR_300_OPT0);
248 #undef CHECKINTR
249
250 #ifdef DIAGNOSTIC
251 #define PRINTINTR(msg, bits) \
252 if (tcir & bits) \
253 printf(msg);
254 PRINTINTR("BCache tag parity error\n",
255 TC_3000_300_IR_BCTAGPARITY);
256 PRINTINTR("TC overrun error\n", TC_3000_300_IR_TCOVERRUN);
257 PRINTINTR("TC I/O timeout\n", TC_3000_300_IR_TCTIMEOUT);
258 PRINTINTR("Bcache parity error\n",
259 TC_3000_300_IR_BCACHEPARITY);
260 PRINTINTR("Memory parity error\n", TC_3000_300_IR_MEMPARITY);
261 #undef PRINTINTR
262 #endif
263 } while (ifound);
264 }
265
266 /*
267 * tc_3000_300_fb_cnattach --
268 * Attempt to map the CTB output device to a slot and attach the
269 * framebuffer as the output side of the console.
270 */
271 int
272 tc_3000_300_fb_cnattach(turbo_slot)
273 u_int64_t turbo_slot;
274 {
275 u_int32_t output_slot;
276
277 output_slot = turbo_slot & 0xffffffff;
278
279 if (output_slot >= tc_3000_300_nslots) {
280 return 0;
281 }
282
283 if (output_slot == 0) {
284 sfb_cnattach(KV(0x1c0000000) + 0x02000000);
285 return 1;
286 }
287
288 return tc_fb_cnattach(tc_3000_300_slots[output_slot-1].tcs_addr);
289 }
290