ka43.c revision 1.4 1 1.4 ragge /* $NetBSD: ka43.c,v 1.4 1997/02/19 10:04:14 ragge Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * This code is derived from software contributed to Ludd by Bertram Barth.
7 1.1 ragge *
8 1.1 ragge * Redistribution and use in source and binary forms, with or without
9 1.1 ragge * modification, are permitted provided that the following conditions
10 1.1 ragge * are met:
11 1.1 ragge * 1. Redistributions of source code must retain the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer.
13 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer in the
15 1.1 ragge * documentation and/or other materials provided with the distribution.
16 1.1 ragge * 3. All advertising materials mentioning features or use of this software
17 1.1 ragge * must display the following acknowledgement:
18 1.4 ragge * This product includes software developed at Ludd, University of
19 1.4 ragge * Lule}, Sweden and its contributors.
20 1.1 ragge * 4. The name of the author may not be used to endorse or promote products
21 1.1 ragge * derived from this software without specific prior written permission
22 1.1 ragge *
23 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 ragge */
34 1.1 ragge
35 1.1 ragge #include <sys/param.h>
36 1.1 ragge #include <sys/types.h>
37 1.1 ragge #include <sys/device.h>
38 1.1 ragge #include <sys/kernel.h>
39 1.1 ragge
40 1.1 ragge #include <vm/vm.h>
41 1.1 ragge #include <vm/vm_kern.h>
42 1.1 ragge
43 1.1 ragge #include <machine/pte.h>
44 1.4 ragge #include <machine/cpu.h>
45 1.1 ragge #include <machine/mtpr.h>
46 1.1 ragge #include <machine/sid.h>
47 1.1 ragge #include <machine/pmap.h>
48 1.1 ragge #include <machine/nexus.h>
49 1.1 ragge #include <machine/uvax.h>
50 1.1 ragge #include <machine/ka43.h>
51 1.1 ragge #include <machine/clock.h>
52 1.1 ragge #include <machine/ka650.h> /* cache ??? */
53 1.1 ragge
54 1.4 ragge #define xtrace(x)
55 1.1 ragge
56 1.1 ragge void ka43_conf __P((struct device*, struct device*, void*));
57 1.1 ragge void ka43_steal_pages __P((void));
58 1.1 ragge
59 1.1 ragge void ka43_memerr __P((void));
60 1.1 ragge int ka43_mchk __P((caddr_t));
61 1.1 ragge
62 1.4 ragge struct ka43_clock *ka43_clkptr;
63 1.1 ragge
64 1.1 ragge
65 1.4 ragge static struct uc_map ka43_map[] = {
66 1.1 ragge { KA43_CFGTST, KA43_CFGTST, 4, 0 },
67 1.1 ragge { KA43_ROM_BASE, KA43_ROM_END, KA43_ROM_SIZE, 0 },
68 1.1 ragge { KA43_CPU_BASE, KA43_CPU_END, KA43_CPU_SIZE, 0 },
69 1.1 ragge { KA43_CT2_BASE, KA43_CT2_END, KA43_CT2_SIZE, 0 },
70 1.1 ragge { KA43_CH2_CREG, KA43_CH2_CREG, 4, 0 },
71 1.1 ragge { KA43_NWA_BASE, KA43_NWA_END, KA43_NWA_SIZE, 0 },
72 1.1 ragge { KA43_SER_BASE, KA43_SER_END, KA43_SER_SIZE, 0 },
73 1.1 ragge { KA43_WAT_BASE, KA43_WAT_END, KA43_WAT_SIZE, 0 },
74 1.1 ragge { KA43_SCS_BASE, KA43_SCS_END, KA43_SCS_SIZE, 0 },
75 1.1 ragge { KA43_LAN_BASE, KA43_LAN_END, KA43_LAN_SIZE, 0 },
76 1.1 ragge { KA43_CUR_BASE, KA43_CUR_END, KA43_CUR_SIZE, 0 },
77 1.1 ragge { KA43_DMA_BASE, KA43_DMA_END, KA43_DMA_SIZE, 0 },
78 1.1 ragge { KA43_VME_BASE, KA43_VME_END, KA43_VME_SIZE, 0 },
79 1.1 ragge /*
80 1.1 ragge * there's more to come, eg. framebuffers (GPX/SPX)
81 1.1 ragge */
82 1.1 ragge {0, 0, 0, 0},
83 1.1 ragge };
84 1.1 ragge
85 1.4 ragge struct cpu_dep ka43_calls = {
86 1.4 ragge ka43_steal_pages,
87 1.4 ragge no_nicr_clock,
88 1.4 ragge ka43_mchk,
89 1.4 ragge ka43_memerr,
90 1.4 ragge ka43_conf,
91 1.4 ragge ka43_clkread,
92 1.4 ragge ka43_clkwrite,
93 1.4 ragge 4,
94 1.4 ragge (void*)KA43_INTREQ,
95 1.4 ragge (void*)KA43_INTCLR,
96 1.4 ragge (void*)KA43_INTMSK,
97 1.4 ragge ka43_map,
98 1.4 ragge };
99 1.4 ragge
100 1.1 ragge #define CH1_BITS \
101 1.1 ragge "\020\015BCHIT\014BUSERR\013PPERR\012DPERR\011TPERR\010TRAP1" \
102 1.1 ragge "\007TRAP2\006INTR\005HIT\004REFRESH\003FLUSH\002ENABLE\001FORCEHIT"
103 1.1 ragge
104 1.1 ragge #define CH2_BITS \
105 1.1 ragge "\020\010TPE\007DPE\006MISS\005DIRTY\004CERR\003LERR\002SERR\001ENAB"
106 1.1 ragge
107 1.1 ragge void
108 1.1 ragge ka43_memerr()
109 1.1 ragge {
110 1.1 ragge int mapen;
111 1.1 ragge int *ch2reg;
112 1.1 ragge
113 1.3 christos printf("memory error!\n");
114 1.3 christos printf("primary cache status: %b\n", mfpr(PR_PCSTS), CH1_BITS);
115 1.1 ragge
116 1.1 ragge mapen = mfpr(PR_MAPEN);
117 1.1 ragge if (mapen)
118 1.1 ragge ch2reg = (void*)uvax_phys2virt(KA43_CH2_CREG);
119 1.1 ragge else
120 1.1 ragge ch2reg = (void*)KA43_CH2_CREG;
121 1.3 christos printf("secondary cache status: %b\n", *ch2reg, CH2_BITS);
122 1.1 ragge }
123 1.1 ragge
124 1.1 ragge static char *mcc43[] = {
125 1.1 ragge "no error (0)",
126 1.1 ragge "FPA signalled protocoll error",
127 1.1 ragge "FPA signalled illegal opcode",
128 1.1 ragge "FPA detected parity error",
129 1.1 ragge "FPA returned unknown status",
130 1.1 ragge "FPA result has parity error",
131 1.1 ragge "unused (6)",
132 1.1 ragge "unused (7)",
133 1.1 ragge "MMU error (TLB miss)",
134 1.1 ragge "MMU error (TLB hit)",
135 1.1 ragge "HW interrupt at unused IPL",
136 1.1 ragge "impossible microcode state",
137 1.1 ragge "undefined trap code (i-box)",
138 1.1 ragge "undefined control store address",
139 1.1 ragge "unused (14)",
140 1.1 ragge "unused (15)",
141 1.1 ragge "PC tag or data parity error",
142 1.1 ragge "data bus parity error",
143 1.1 ragge "data bus error (NXM)",
144 1.1 ragge "undefined data bus state",
145 1.1 ragge };
146 1.1 ragge
147 1.1 ragge int
148 1.1 ragge ka43_mchk(addr)
149 1.1 ragge caddr_t addr;
150 1.1 ragge {
151 1.1 ragge struct {
152 1.1 ragge int bcount; /* byte count (0x18) */
153 1.1 ragge int mcc; /* "R"-flag and machine check code */
154 1.1 ragge int mrva; /* most recent virtual address */
155 1.1 ragge int viba; /* contents of VIBA register */
156 1.1 ragge int sisr; /* ICCS bit 6 and SISR bits 15:0 */
157 1.1 ragge int isd; /* internal state */
158 1.1 ragge int scr; /* shift count register */
159 1.1 ragge int pc; /* program counter */
160 1.1 ragge int psl; /* processor status longword */
161 1.1 ragge } *p = (void*)addr;
162 1.1 ragge
163 1.3 christos printf("machine check: 0x%x\n", p->mcc);
164 1.3 christos printf("reason: %s\n", mcc43[p->mcc & 0xff]);
165 1.1 ragge
166 1.3 christos printf("bcount:0x%x, check-code:0x%x, virtaddr:0x%x\n",
167 1.1 ragge p->bcount, p->mcc, p->mrva);
168 1.3 christos printf("pc:0x%x, psl:0x%x, viba: %x, state: %x\n",
169 1.1 ragge p->pc, p->psl, p->viba, p->isd);
170 1.1 ragge
171 1.1 ragge return (-1);
172 1.1 ragge }
173 1.1 ragge
174 1.1 ragge int
175 1.1 ragge ka43_setup(uc,flags)
176 1.1 ragge struct uvax_calls *uc;
177 1.1 ragge int flags;
178 1.1 ragge {
179 1.1 ragge uc->uc_name = "ka43";
180 1.1 ragge
181 1.1 ragge uc->uc_physmap = ka43_map;
182 1.1 ragge }
183 1.1 ragge
184 1.1 ragge ka43_discache()
185 1.1 ragge {
186 1.1 ragge int *ctag;
187 1.1 ragge int *creg;
188 1.1 ragge int mapen;
189 1.1 ragge int i;
190 1.1 ragge
191 1.1 ragge xtrace(("ka43_discache()\n"));
192 1.1 ragge return (0);
193 1.1 ragge
194 1.1 ragge /*
195 1.1 ragge * first disable primary cache
196 1.1 ragge */
197 1.1 ragge #if 0
198 1.1 ragge mtpr(0, PR_PCSTS);
199 1.1 ragge mtpr(0, PR_PCERR);
200 1.1 ragge mtpr(0, PR_PCIDX);
201 1.1 ragge mtpr(0, PR_PCTAG);
202 1.1 ragge #else
203 1.1 ragge i = mfpr(PR_PCSTS);
204 1.1 ragge mtpr((i & ~2), PR_PCSTS);
205 1.3 christos printf("pcsts: %x --> %x\n", i, mfpr(PR_PCSTS));
206 1.1 ragge #endif
207 1.1 ragge /*
208 1.1 ragge * now secondary cache
209 1.1 ragge */
210 1.1 ragge mapen = mfpr(PR_MAPEN);
211 1.1 ragge if (mapen) {
212 1.1 ragge ctag = (void*)uvax_phys2virt(KA43_CT2_BASE);
213 1.1 ragge creg = (void*)uvax_phys2virt(KA43_CH2_CREG);
214 1.1 ragge } else {
215 1.1 ragge ctag = (void*)KA43_CT2_BASE;
216 1.1 ragge creg = (void*)KA43_CH2_CREG;
217 1.1 ragge }
218 1.1 ragge i = *creg;
219 1.1 ragge *creg = (i & ~1);
220 1.3 christos printf("creg: %x --> %x\n", i, *creg);
221 1.1 ragge
222 1.1 ragge xtrace(("ka43_discache() done.\n"));
223 1.1 ragge }
224 1.1 ragge
225 1.1 ragge ka43_encache()
226 1.1 ragge {
227 1.1 ragge int *ctag;
228 1.1 ragge int *creg;
229 1.1 ragge int mapen;
230 1.1 ragge int i;
231 1.1 ragge
232 1.1 ragge xtrace(("ka43_encache()\n"));
233 1.1 ragge
234 1.1 ragge ka43_discache();
235 1.1 ragge
236 1.1 ragge /*
237 1.1 ragge * first enable primary cache
238 1.1 ragge */
239 1.3 christos printf("P-0");
240 1.1 ragge i = mfpr(PR_PCSTS);
241 1.1 ragge mtpr((i & ~2), PR_PCSTS);
242 1.1 ragge mtpr(0, PR_PCSTS);
243 1.3 christos printf("P-1");
244 1.1 ragge #if 1
245 1.1 ragge mtpr(KA43_PCS_ENABLE | KA43_PCS_FLUSH | KA43_PCS_REFRESH, PR_PCSTS);
246 1.1 ragge #else
247 1.1 ragge mtpr(KA43_PCS_ENABLE, PR_PCSTS);
248 1.1 ragge #endif
249 1.3 christos printf("P-2");
250 1.1 ragge
251 1.1 ragge /*
252 1.1 ragge * now secondary cache
253 1.1 ragge */
254 1.1 ragge mapen = mfpr(PR_MAPEN);
255 1.1 ragge if (mapen) {
256 1.1 ragge ctag = (void*)uvax_phys2virt(KA43_CT2_BASE);
257 1.1 ragge creg = (void*)uvax_phys2virt(KA43_CH2_CREG);
258 1.1 ragge } else {
259 1.1 ragge ctag = (void*)KA43_CT2_BASE;
260 1.1 ragge creg = (void*)KA43_CH2_CREG;
261 1.1 ragge }
262 1.3 christos printf("ctag: %x, creg: %x\n", ctag, creg);
263 1.3 christos printf("S-1");
264 1.1 ragge i = *creg;
265 1.3 christos printf("creg=[%x] ", *creg);
266 1.1 ragge #if 0
267 1.1 ragge *creg = (i & ~1);
268 1.3 christos printf("creg=[%x] ", *creg);
269 1.3 christos printf("S-2");
270 1.1 ragge for (i = 0; i < KA43_CT2_SIZE; i += 4) /* Quadword entries */
271 1.1 ragge ctag[i/4] = 0; /* reset lower half */
272 1.3 christos printf("S-3");
273 1.1 ragge i = *creg;
274 1.3 christos printf("creg=[%x] ", *creg);
275 1.1 ragge *creg = (i & ~1);
276 1.3 christos printf("creg=[%x] ", *creg);
277 1.3 christos printf("S-4");
278 1.1 ragge /* *creg = 1; */
279 1.3 christos printf("S-5");
280 1.1 ragge #endif
281 1.1 ragge xtrace(("ka43_encache() done.\n"));
282 1.1 ragge
283 1.3 christos printf("primary cache status: %b\n", mfpr(PR_PCSTS), CH1_BITS);
284 1.3 christos printf("secondary cache status: %b\n", *creg, CH2_BITS);
285 1.1 ragge }
286 1.1 ragge
287 1.1 ragge void
288 1.1 ragge ka43_conf(parent, self, aux)
289 1.1 ragge struct device *parent, *self;
290 1.1 ragge void *aux;
291 1.1 ragge {
292 1.1 ragge extern char cpu_model[];
293 1.1 ragge extern int vax_siedata;
294 1.1 ragge
295 1.1 ragge if (vax_siedata & 0x02) /* "single-user" flag */
296 1.1 ragge strcpy(cpu_model,"VAXstation 3100 model 76");
297 1.1 ragge else if (vax_siedata & 0x01) /* "multiuser" flag */
298 1.1 ragge strcpy(cpu_model,"MicroVAX 3100 model 76(?)");
299 1.1 ragge else
300 1.1 ragge strcpy(cpu_model, "unknown KA43 board");
301 1.1 ragge
302 1.3 christos printf(": %s\n", cpu_model);
303 1.1 ragge
304 1.1 ragge ka43_encache();
305 1.1 ragge }
306 1.1 ragge
307 1.1 ragge
308 1.1 ragge /*
309 1.1 ragge *
310 1.1 ragge */
311 1.1 ragge u_long le_iomem; /* base addr of RAM -- CPU's view */
312 1.1 ragge u_long le_ioaddr; /* base addr of RAM -- LANCE's view */
313 1.1 ragge
314 1.1 ragge void
315 1.1 ragge ka43_steal_pages()
316 1.1 ragge {
317 1.4 ragge extern vm_offset_t avail_start, virtual_avail, avail_end;
318 1.1 ragge int junk;
319 1.1 ragge int i;
320 1.1 ragge struct {
321 1.1 ragge u_long :2;
322 1.1 ragge u_long data:8;
323 1.1 ragge u_long :22;
324 1.1 ragge } *p;
325 1.1 ragge int *srp; /* Scratch Ram */
326 1.1 ragge int *pctl; /* parity control register */
327 1.1 ragge char *q = (void*)&srp;
328 1.1 ragge char line[20];
329 1.1 ragge
330 1.1 ragge ka43_encache();
331 1.1 ragge
332 1.1 ragge pctl = (void*)KA43_PARCTL;
333 1.3 christos printf("parctl: 0x%x\n", *pctl);
334 1.1 ragge #if 0
335 1.1 ragge *pctl = KA43_PCTL_DPEN | KA43_PCTL_CPEN;
336 1.1 ragge #else
337 1.1 ragge *pctl = KA43_PCTL_CPEN;
338 1.1 ragge #endif
339 1.4 ragge panic("No support for ka43");
340 1.4 ragge #if 0
341 1.3 christos printf("new value for parctl: ");
342 1.1 ragge gets(line);
343 1.4 ragge #endif
344 1.1 ragge *pctl = *line - '0';
345 1.3 christos printf("parctl: 0x%x\n", *pctl);
346 1.1 ragge
347 1.1 ragge srp = NULL;
348 1.1 ragge p = (void*)KA43_SCR;
349 1.1 ragge for (i=0; i<4; i++) {
350 1.3 christos printf("p[%d] = %x, ", i, p[i].data);
351 1.4 ragge q[i] = p[i].data;
352 1.1 ragge }
353 1.1 ragge p = (void*)KA43_SCRLEN;
354 1.3 christos printf("\nlen = %d\n", p->data);
355 1.3 christos printf("srp = 0x%x\n", srp);
356 1.1 ragge
357 1.1 ragge for (i=0; i<0x2; i++) {
358 1.3 christos printf("%x:0x%x ", i*4, srp[i]);
359 1.1 ragge if ((i & 0x07) == 0x07)
360 1.3 christos printf("\n");
361 1.4 ragge }
362 1.3 christos printf("\n");
363 1.1 ragge
364 1.3 christos printf ("ka43_steal_pages: avail_end=0x%x\n", avail_end);
365 1.1 ragge
366 1.1 ragge /*
367 1.1 ragge * SCB is already copied/initialized at addr avail_start
368 1.1 ragge * by pmap_bootstrap(), but it's not yet mapped. Thus we use
369 1.1 ragge * the MAPPHYS() macro to reserve these two pages and to
370 1.1 ragge * perform the mapping. The mapped address is assigned to junk.
371 1.1 ragge */
372 1.1 ragge MAPPHYS(junk, 2, VM_PROT_READ|VM_PROT_WRITE);
373 1.1 ragge
374 1.1 ragge /*
375 1.1 ragge * At top of physical memory there are some console-prom and/or
376 1.1 ragge * restart-specific data. Make this area unavailable.
377 1.1 ragge */
378 1.1 ragge #if 1
379 1.1 ragge avail_end -= 10 * NBPG;
380 1.1 ragge #endif
381 1.1 ragge
382 1.1 ragge /*
383 1.1 ragge * If we need to map physical areas also, we can decrease avail_end
384 1.1 ragge * (the highest available memory-address), copy the stuff into the
385 1.1 ragge * gap between and use pmap_map to map it...
386 1.1 ragge *
387 1.1 ragge * Don't use the MAPPHYS macro here, since this uses and changes(!)
388 1.1 ragge * the value of avail_start. Use MAPVIRT even if it's name misleads.
389 1.1 ragge */
390 1.1 ragge avail_end &= ~0xffff;
391 1.1 ragge avail_end -= (64 * 1024);
392 1.1 ragge
393 1.1 ragge avail_end = 0xf00000;
394 1.1 ragge le_ioaddr = 0xf40000;
395 1.1 ragge
396 1.1 ragge MAPVIRT(le_iomem, (64 * 1024)/NBPG);
397 1.1 ragge pmap_map((vm_offset_t)le_iomem, le_ioaddr, le_ioaddr + 0xffff,
398 1.1 ragge VM_PROT_READ|VM_PROT_WRITE);
399 1.1 ragge
400 1.1 ragge if (1 || le_ioaddr > 0xffffff) {
401 1.1 ragge le_ioaddr &= 0xffffff;
402 1.1 ragge *pctl |= KA43_PCTL_DMA;
403 1.1 ragge }
404 1.3 christos printf("le_iomem: %x, le_ioaddr: %x, parctl:%x\n",
405 1.1 ragge le_iomem, le_ioaddr, *pctl);
406 1.1 ragge
407 1.1 ragge /*
408 1.1 ragge * now map in anything listed in ka43_map...
409 1.1 ragge */
410 1.4 ragge uvax_fillmap();
411 1.1 ragge
412 1.1 ragge /*
413 1.1 ragge * Clear restart and boot in progress flags in the CPMBX.
414 1.1 ragge */
415 1.4 ragge ((struct ka43_clock*)ka43_clkptr)->cpmbx =
416 1.4 ragge ((struct ka43_clock*)ka43_clkptr)->cpmbx & 0xF0;
417 1.1 ragge
418 1.1 ragge /*
419 1.1 ragge * Enable memory parity error detection and clear error bits.
420 1.1 ragge */
421 1.4 ragge ((struct ka43_cpu *)KA43_CPU_BASE)->ka43_mser = 0x01;
422 1.1 ragge /* (UVAXIIMSER_PEN | UVAXIIMSER_MERR | UVAXIIMSER_LEB); */
423 1.1 ragge
424 1.1 ragge /*
425 1.1 ragge * MM is not yet enabled, thus we still used the physical addresses,
426 1.1 ragge * but before leaving this routine, we need to reset them to virtual.
427 1.1 ragge */
428 1.1 ragge ka43_clkptr = (void*)uvax_phys2virt(KA43_WAT_BASE);
429 1.1 ragge }
430 1.1 ragge
431 1.1 ragge /*
432 1.1 ragge * define what we need and overwrite the uVAX_??? names
433 1.1 ragge */
434 1.1 ragge
435 1.1 ragge #define NEED_UVAX_GENCLOCK
436 1.1 ragge #define NEED_UVAX_PROTOCLOCK
437 1.1 ragge
438 1.1 ragge #define uVAX_clock ka43_clock
439 1.1 ragge #define uVAX_clkptr ka43_clkptr
440 1.1 ragge #define uVAX_clkread ka43_clkread
441 1.1 ragge #define uVAX_clkwrite ka43_clkwrite
442 1.1 ragge #define uVAX_genclock ka43_genclock
443 1.1 ragge
444 1.1 ragge #include <arch/vax/vax/uvax_proto.c>
445