xref: /netbsd-src/sys/arch/vax/vax/ka660.c (revision f82d7874c259b2a6cc59b714f844919f32bf7b51)
1 /*	$NetBSD: ka660.c,v 1.9 2008/03/11 05:34:03 matt Exp $	*/
2 /*
3  * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *     This product includes software developed at Ludd, University of
17  *     Lule}, Sweden and its contributors.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: ka660.c,v 1.9 2008/03/11 05:34:03 matt Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/device.h>
39 #include <sys/kernel.h>
40 #include <sys/systm.h>
41 
42 #include <uvm/uvm_extern.h>
43 
44 #include <machine/pte.h>
45 #include <machine/cpu.h>
46 #include <machine/mtpr.h>
47 #include <machine/sid.h>
48 #include <machine/pmap.h>
49 #include <machine/nexus.h>
50 #include <machine/uvax.h>
51 #include <machine/ka410.h>
52 #include <machine/ka420.h>
53 #include <machine/clock.h>
54 #include <machine/vsbus.h>
55 
56 #define KA660_CCR	37		/* Cache Control Register */
57 #define KA660_CTAG	0x20150000	/* Cache Tags */
58 #define KA660_CDATA	0x20150400	/* Cache Data */
59 #define KA660_BEHR	0x20150800	/* Bank Enable/Hit Register */
60 #define CCR_WWP		8	/* Write Wrong Parity */
61 #define CCR_ENA		4	/* Cache Enable */
62 #define CCR_FLU 2	/* Cache Flush */
63 #define CCR_DIA 1	/* Diagnostic mode */
64 
65 static void ka660_conf(void);
66 static void ka660_memerr(void);
67 static void ka660_cache_enable(void);
68 static void ka660_attach_cpu(device_t);
69 static int ka660_mchk(void *);
70 
71 static const char * const ka660_devs[] = { "cpu", "sgec", "vsbus", NULL };
72 
73 /*
74  * Declaration of 660-specific calls.
75  */
76 const struct cpu_dep ka660_calls = {
77 	.cpu_steal_pages = ka660_cache_enable,	/* ewww */
78 	.cpu_mchk	= ka660_mchk,
79 	.cpu_memerr	= ka660_memerr,
80 	.cpu_conf	= ka660_conf,
81 	.cpu_gettime	= generic_gettime,
82 	.cpu_settime	= generic_settime,
83 	.cpu_vups	= 6,	/* ~VUPS */
84 	.cpu_scbsz	= 2,	/* SCB pages */
85 	.cpu_halt	= generic_halt,
86 	.cpu_reboot	= generic_reboot,
87 	.cpu_devs	= ka660_devs,
88 	.cpu_attach_cpu	= ka660_attach_cpu,
89 };
90 
91 
92 void
93 ka660_conf(void)
94 {
95 	cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1);
96 }
97 
98 void
99 ka660_attach_cpu(device_t self)
100 {
101 	aprint_normal(
102 	    ": %s, Rigel (ucode rev. %d), 2KB L1 cache, 128KB L2 cache\n",
103 	    "KA660",
104 	    vax_cpudata & 0377);
105 }
106 
107 void
108 ka660_cache_enable(void)
109 {
110 	unsigned int *p;
111 	int cnt, bnk, behrtmp;
112 
113 	mtpr(0, KA660_CCR);	/* Disable cache */
114 	mtpr(CCR_DIA, KA660_CCR);	/* Switch to diag mode */
115 	bnk = 1;
116 	behrtmp = 0;
117 	while(bnk <= 0x80)
118 	{
119 		*(int *)KA660_BEHR = bnk;
120 		p = (int *)KA660_CDATA;
121 		*p = 0x55aaff00L;
122 		if(*p == 0x55aaff00L) behrtmp |= bnk;
123 		*p = 0xffaa0055L;
124 		if(*p != 0xffaa0055L) behrtmp &= ~bnk;
125 		cnt = 256;
126 		while(cnt--) *p++ = 0L;
127 		p = (int *) KA660_CTAG;
128 		cnt =128;
129 		while(cnt--) { *p++ = 0x80000000L; p++; }
130 		bnk <<= 1;
131 	}
132 	*(int *)KA660_BEHR = behrtmp;
133 
134 	mtpr(CCR_DIA|CCR_FLU, KA660_CCR);	/* Flush tags */
135 	mtpr(CCR_ENA, KA660_CCR);	/* Enable cache */
136 }
137 
138 void
139 ka660_memerr(void)
140 {
141 	printf("Memory err!\n");
142 }
143 
144 int
145 ka660_mchk(void *addr)
146 {
147 	panic("Machine check");
148 	return 0;
149 }
150