tc_3000_300.c revision 1.35 1 1.35 thorpej /* $NetBSD: tc_3000_300.c,v 1.35 2020/09/05 16:29:08 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.6 cgd * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 1.1 cgd * All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Author: Chris G. Demetriou
8 1.32 matt *
9 1.1 cgd * Permission to use, copy, modify and distribute this software and
10 1.1 cgd * its documentation is hereby granted, provided that both the copyright
11 1.1 cgd * notice and this permission notice appear in all copies of the
12 1.1 cgd * software, derivative works or modified versions, and any portions
13 1.1 cgd * thereof, and that both notices appear in supporting documentation.
14 1.32 matt *
15 1.32 matt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.32 matt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 cgd * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.32 matt *
19 1.1 cgd * Carnegie Mellon requests users of this software to return to
20 1.1 cgd *
21 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 cgd * School of Computer Science
23 1.1 cgd * Carnegie Mellon University
24 1.1 cgd * Pittsburgh PA 15213-3890
25 1.1 cgd *
26 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
27 1.1 cgd * rights to redistribute these changes.
28 1.1 cgd */
29 1.13 cgd
30 1.14 cgd #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31 1.14 cgd
32 1.35 thorpej __KERNEL_RCSID(0, "$NetBSD: tc_3000_300.c,v 1.35 2020/09/05 16:29:08 thorpej Exp $");
33 1.1 cgd
34 1.1 cgd #include <sys/param.h>
35 1.9 cgd #include <sys/systm.h>
36 1.1 cgd #include <sys/device.h>
37 1.25 thorpej #include <sys/malloc.h>
38 1.1 cgd
39 1.1 cgd #include <machine/autoconf.h>
40 1.1 cgd #include <machine/pte.h>
41 1.1 cgd
42 1.4 cgd #include <dev/tc/tcvar.h>
43 1.21 nisimura #include <dev/tc/ioasicreg.h>
44 1.4 cgd #include <alpha/tc/tc_conf.h>
45 1.1 cgd #include <alpha/tc/tc_3000_300.h>
46 1.17 briggs
47 1.19 drochner #include "wsdisplay.h"
48 1.17 briggs #include "sfb.h"
49 1.17 briggs
50 1.17 briggs #if NSFB > 0
51 1.28 dsl extern int sfb_cnattach(tc_addr_t);
52 1.17 briggs #endif
53 1.1 cgd
54 1.28 dsl int tc_3000_300_intrnull(void *);
55 1.4 cgd
56 1.4 cgd #define C(x) ((void *)(u_long)x)
57 1.9 cgd #define KV(x) (ALPHA_PHYS_TO_K0SEG(x))
58 1.1 cgd
59 1.5 cgd /*
60 1.5 cgd * We have to read and modify the IOASIC registers directly, because
61 1.5 cgd * the TC option slot interrupt request and mask bits are stored there,
62 1.5 cgd * and the ioasic code isn't initted when we need to frob some interrupt
63 1.5 cgd * bits.
64 1.5 cgd */
65 1.5 cgd #define DEC_3000_300_IOASIC_ADDR KV(0x1a0000000)
66 1.5 cgd
67 1.4 cgd struct tc_slotdesc tc_3000_300_slots[] = {
68 1.4 cgd { KV(0x100000000), C(TC_3000_300_DEV_OPT0), }, /* 0 - opt slot 0 */
69 1.4 cgd { KV(0x120000000), C(TC_3000_300_DEV_OPT1), }, /* 1 - opt slot 1 */
70 1.22 nisimura { KV(0x140000000), C(TC_3000_300_DEV_BOGUS), }, /* 2 - unused */
71 1.22 nisimura { KV(0x160000000), C(TC_3000_300_DEV_BOGUS), }, /* 3 - unused */
72 1.22 nisimura { KV(0x180000000), C(TC_3000_300_DEV_BOGUS), }, /* 4 - TCDS ASIC */
73 1.22 nisimura { KV(0x1a0000000), C(TC_3000_300_DEV_BOGUS), }, /* 5 - IOCTL ASIC */
74 1.22 nisimura { KV(0x1c0000000), C(TC_3000_300_DEV_BOGUS), }, /* 6 - CXTurbo */
75 1.1 cgd };
76 1.4 cgd int tc_3000_300_nslots =
77 1.4 cgd sizeof(tc_3000_300_slots) / sizeof(tc_3000_300_slots[0]);
78 1.1 cgd
79 1.4 cgd struct tc_builtin tc_3000_300_builtins[] = {
80 1.22 nisimura { "PMAGB-BA", 6, 0x02000000, C(TC_3000_300_DEV_CXTURBO), },
81 1.22 nisimura { "FLAMG-IO", 5, 0x00000000, C(TC_3000_300_DEV_IOASIC), },
82 1.22 nisimura { "PMAZ-DS ", 4, 0x00000000, C(TC_3000_300_DEV_TCDS), },
83 1.1 cgd };
84 1.4 cgd int tc_3000_300_nbuiltins =
85 1.4 cgd sizeof(tc_3000_300_builtins) / sizeof(tc_3000_300_builtins[0]);
86 1.1 cgd
87 1.4 cgd struct tcintr {
88 1.28 dsl int (*tci_func)(void *);
89 1.4 cgd void *tci_arg;
90 1.25 thorpej struct evcnt tci_evcnt;
91 1.4 cgd } tc_3000_300_intr[TC_3000_300_NCOOKIES];
92 1.4 cgd
93 1.1 cgd void
94 1.32 matt tc_3000_300_intr_setup(void)
95 1.1 cgd {
96 1.32 matt volatile uint32_t *imskp;
97 1.25 thorpej char *cp;
98 1.4 cgd u_long i;
99 1.1 cgd
100 1.4 cgd /*
101 1.5 cgd * Disable all interrupts that we can (can't disable builtins).
102 1.4 cgd */
103 1.32 matt imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
104 1.5 cgd *imskp &= ~(IOASIC_INTR_300_OPT0 | IOASIC_INTR_300_OPT1);
105 1.4 cgd
106 1.4 cgd /*
107 1.4 cgd * Set up interrupt handlers.
108 1.4 cgd */
109 1.4 cgd for (i = 0; i < TC_3000_300_NCOOKIES; i++) {
110 1.33 christos static const size_t len = 12;
111 1.32 matt tc_3000_300_intr[i].tci_func = tc_3000_300_intrnull;
112 1.32 matt tc_3000_300_intr[i].tci_arg = (void *)i;
113 1.25 thorpej
114 1.34 chs cp = malloc(len, M_DEVBUF, M_WAITOK);
115 1.33 christos snprintf(cp, len, "slot %lu", i);
116 1.25 thorpej evcnt_attach_dynamic(&tc_3000_300_intr[i].tci_evcnt,
117 1.25 thorpej EVCNT_TYPE_INTR, NULL, "tc", cp);
118 1.2 cgd }
119 1.24 cgd }
120 1.24 cgd
121 1.24 cgd const struct evcnt *
122 1.31 matt tc_3000_300_intr_evcnt(device_t tcadev, void *cookie)
123 1.24 cgd {
124 1.25 thorpej u_long dev = (u_long)cookie;
125 1.25 thorpej
126 1.25 thorpej #ifdef DIAGNOSTIC
127 1.25 thorpej /* XXX bounds-check cookie. */
128 1.25 thorpej #endif
129 1.24 cgd
130 1.25 thorpej return (&tc_3000_300_intr[dev].tci_evcnt);
131 1.1 cgd }
132 1.1 cgd
133 1.1 cgd void
134 1.31 matt tc_3000_300_intr_establish(device_t tcadev, void *cookie, tc_intrlevel_t level, int (*func)(void *), void *arg)
135 1.1 cgd {
136 1.32 matt volatile uint32_t *imskp;
137 1.4 cgd u_long dev = (u_long)cookie;
138 1.1 cgd
139 1.1 cgd #ifdef DIAGNOSTIC
140 1.4 cgd /* XXX bounds-check cookie. */
141 1.1 cgd #endif
142 1.1 cgd
143 1.4 cgd if (tc_3000_300_intr[dev].tci_func != tc_3000_300_intrnull)
144 1.18 thorpej panic("tc_3000_300_intr_establish: cookie %lu twice", dev);
145 1.1 cgd
146 1.4 cgd tc_3000_300_intr[dev].tci_func = func;
147 1.4 cgd tc_3000_300_intr[dev].tci_arg = arg;
148 1.1 cgd
149 1.32 matt imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
150 1.4 cgd switch (dev) {
151 1.4 cgd case TC_3000_300_DEV_OPT0:
152 1.5 cgd *imskp |= IOASIC_INTR_300_OPT0;
153 1.4 cgd break;
154 1.4 cgd case TC_3000_300_DEV_OPT1:
155 1.5 cgd *imskp |= IOASIC_INTR_300_OPT1;
156 1.4 cgd break;
157 1.4 cgd default:
158 1.4 cgd /* interrupts for builtins always enabled */
159 1.4 cgd break;
160 1.4 cgd }
161 1.1 cgd }
162 1.1 cgd
163 1.1 cgd void
164 1.31 matt tc_3000_300_intr_disestablish(device_t tcadev, void *cookie)
165 1.1 cgd {
166 1.32 matt volatile uint32_t *imskp;
167 1.4 cgd u_long dev = (u_long)cookie;
168 1.1 cgd
169 1.1 cgd #ifdef DIAGNOSTIC
170 1.4 cgd /* XXX bounds-check cookie. */
171 1.1 cgd #endif
172 1.1 cgd
173 1.4 cgd if (tc_3000_300_intr[dev].tci_func == tc_3000_300_intrnull)
174 1.18 thorpej panic("tc_3000_300_intr_disestablish: cookie %lu bad intr",
175 1.1 cgd dev);
176 1.1 cgd
177 1.32 matt imskp = (volatile uint32_t *)(DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
178 1.4 cgd switch (dev) {
179 1.4 cgd case TC_3000_300_DEV_OPT0:
180 1.5 cgd *imskp &= ~IOASIC_INTR_300_OPT0;
181 1.4 cgd break;
182 1.4 cgd case TC_3000_300_DEV_OPT1:
183 1.5 cgd *imskp &= ~IOASIC_INTR_300_OPT1;
184 1.4 cgd break;
185 1.4 cgd default:
186 1.4 cgd /* interrupts for builtins always enabled */
187 1.4 cgd break;
188 1.4 cgd }
189 1.1 cgd
190 1.4 cgd tc_3000_300_intr[dev].tci_func = tc_3000_300_intrnull;
191 1.4 cgd tc_3000_300_intr[dev].tci_arg = (void *)dev;
192 1.4 cgd }
193 1.4 cgd
194 1.4 cgd int
195 1.29 dsl tc_3000_300_intrnull(void *val)
196 1.4 cgd {
197 1.4 cgd
198 1.27 provos panic("tc_3000_300_intrnull: uncaught TC intr for cookie %ld",
199 1.4 cgd (u_long)val);
200 1.1 cgd }
201 1.1 cgd
202 1.1 cgd void
203 1.29 dsl tc_3000_300_iointr(void *arg, unsigned long vec)
204 1.1 cgd {
205 1.32 matt uint32_t tcir, ioasicir, ioasicimr;
206 1.9 cgd int ifound;
207 1.1 cgd
208 1.1 cgd #ifdef DIAGNOSTIC
209 1.1 cgd int s;
210 1.1 cgd if (vec != 0x800)
211 1.10 cgd panic("INVALID ASSUMPTION: vec 0x%lx, not 0x800", vec);
212 1.1 cgd s = splhigh();
213 1.35 thorpej if (s != ALPHA_PSL_IPL_IO_HI)
214 1.9 cgd panic("INVALID ASSUMPTION: IPL %d, not %d", s,
215 1.35 thorpej ALPHA_PSL_IPL_IO_HI);
216 1.1 cgd splx(s);
217 1.1 cgd #endif
218 1.1 cgd
219 1.1 cgd do {
220 1.4 cgd tc_syncbus();
221 1.2 cgd
222 1.2 cgd /* find out what interrupts/errors occurred */
223 1.32 matt tcir = *(volatile uint32_t *)TC_3000_300_IR;
224 1.32 matt ioasicir = *(volatile uint32_t *)
225 1.21 nisimura (DEC_3000_300_IOASIC_ADDR + IOASIC_INTR);
226 1.32 matt ioasicimr = *(volatile uint32_t *)
227 1.21 nisimura (DEC_3000_300_IOASIC_ADDR + IOASIC_IMSK);
228 1.4 cgd tc_mb();
229 1.2 cgd
230 1.7 cgd /* Ignore interrupts that aren't enabled out. */
231 1.7 cgd ioasicir &= ioasicimr;
232 1.7 cgd
233 1.2 cgd /* clear the interrupts/errors we found. */
234 1.32 matt *(volatile uint32_t *)TC_3000_300_IR = tcir;
235 1.4 cgd /* XXX can't clear TC option slot interrupts here? */
236 1.4 cgd tc_wmb();
237 1.1 cgd
238 1.1 cgd ifound = 0;
239 1.8 cgd
240 1.25 thorpej #define INCRINTRCNT(slot) tc_3000_300_intr[slot].tci_evcnt.ev_count++
241 1.8 cgd
242 1.4 cgd #define CHECKINTR(slot, flag) \
243 1.8 cgd if (flag) { \
244 1.1 cgd ifound = 1; \
245 1.8 cgd INCRINTRCNT(slot); \
246 1.4 cgd (*tc_3000_300_intr[slot].tci_func) \
247 1.4 cgd (tc_3000_300_intr[slot].tci_arg); \
248 1.1 cgd }
249 1.1 cgd /* Do them in order of priority; highest slot # first. */
250 1.5 cgd CHECKINTR(TC_3000_300_DEV_CXTURBO,
251 1.5 cgd tcir & TC_3000_300_IR_CXTURBO);
252 1.8 cgd CHECKINTR(TC_3000_300_DEV_IOASIC,
253 1.8 cgd (tcir & TC_3000_300_IR_IOASIC) &&
254 1.8 cgd (ioasicir & ~(IOASIC_INTR_300_OPT1|IOASIC_INTR_300_OPT0)));
255 1.5 cgd CHECKINTR(TC_3000_300_DEV_TCDS, tcir & TC_3000_300_IR_TCDS);
256 1.5 cgd CHECKINTR(TC_3000_300_DEV_OPT1,
257 1.7 cgd ioasicir & IOASIC_INTR_300_OPT1);
258 1.7 cgd CHECKINTR(TC_3000_300_DEV_OPT0,
259 1.5 cgd ioasicir & IOASIC_INTR_300_OPT0);
260 1.1 cgd #undef CHECKINTR
261 1.1 cgd
262 1.1 cgd #ifdef DIAGNOSTIC
263 1.1 cgd #define PRINTINTR(msg, bits) \
264 1.5 cgd if (tcir & bits) \
265 1.12 christos printf(msg);
266 1.1 cgd PRINTINTR("BCache tag parity error\n",
267 1.1 cgd TC_3000_300_IR_BCTAGPARITY);
268 1.1 cgd PRINTINTR("TC overrun error\n", TC_3000_300_IR_TCOVERRUN);
269 1.1 cgd PRINTINTR("TC I/O timeout\n", TC_3000_300_IR_TCTIMEOUT);
270 1.1 cgd PRINTINTR("Bcache parity error\n",
271 1.1 cgd TC_3000_300_IR_BCACHEPARITY);
272 1.1 cgd PRINTINTR("Memory parity error\n", TC_3000_300_IR_MEMPARITY);
273 1.1 cgd #undef PRINTINTR
274 1.1 cgd #endif
275 1.1 cgd } while (ifound);
276 1.16 briggs }
277 1.16 briggs
278 1.19 drochner #if NWSDISPLAY > 0
279 1.16 briggs /*
280 1.16 briggs * tc_3000_300_fb_cnattach --
281 1.16 briggs * Attempt to map the CTB output device to a slot and attach the
282 1.16 briggs * framebuffer as the output side of the console.
283 1.16 briggs */
284 1.16 briggs int
285 1.32 matt tc_3000_300_fb_cnattach(uint64_t turbo_slot)
286 1.16 briggs {
287 1.32 matt uint32_t output_slot;
288 1.16 briggs
289 1.16 briggs output_slot = turbo_slot & 0xffffffff;
290 1.16 briggs
291 1.16 briggs if (output_slot >= tc_3000_300_nslots) {
292 1.20 drochner return EINVAL;
293 1.16 briggs }
294 1.16 briggs
295 1.16 briggs if (output_slot == 0) {
296 1.17 briggs #if NSFB > 0
297 1.16 briggs sfb_cnattach(KV(0x1c0000000) + 0x02000000);
298 1.20 drochner return 0;
299 1.17 briggs #else
300 1.20 drochner return ENXIO;
301 1.17 briggs #endif
302 1.16 briggs }
303 1.16 briggs
304 1.16 briggs return tc_fb_cnattach(tc_3000_300_slots[output_slot-1].tcs_addr);
305 1.1 cgd }
306 1.19 drochner #endif /* NWSDISPLAY */
307