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