1 /* $NetBSD: ka53.c,v 1.17 2017/05/22 16:46:15 ragge Exp $ */
2 /*
3 * Copyright (c) 2002 Hugh Graham.
4 * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 /*
31 * Done by Michael Kukat (michael@unixiron.org)
32 * Thanx for the good cooperation with Hugh Graham (hugh@openbsd.org)
33 * and his useful hints for the console of these machines
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: ka53.c,v 1.17 2017/05/22 16:46:15 ragge Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/cpu.h>
42 #include <sys/device.h>
43 #include <sys/kernel.h>
44
45 #include <machine/clock.h>
46 #include <machine/scb.h>
47 #include <machine/sid.h>
48
49 static void ka53_conf(void);
50 static void ka53_memerr(void);
51 static int ka53_mchk(void *);
52 static void ka53_softmem(void *);
53 static void ka53_hardmem(void *);
54 static void ka53_steal_pages(void);
55 static void ka53_cache_enable(void);
56 static void ka53_attach_cpu(device_t);
57
58 static const char * const ka53_devs[] = { "cpu", "sgec", "vsbus", "uba", NULL };
59
60 /*
61 * Declaration of 53-specific calls.
62 */
63 const struct cpu_dep ka53_calls = {
64 .cpu_steal_pages = ka53_steal_pages,
65 .cpu_mchk = ka53_mchk,
66 .cpu_memerr = ka53_memerr,
67 .cpu_conf = ka53_conf,
68 .cpu_gettime = generic_gettime,
69 .cpu_settime = generic_settime,
70 .cpu_vups = 32, /* ~VUPS */
71 .cpu_scbsz = 2, /* SCB pages */
72 .cpu_halt = generic_halt,
73 .cpu_reboot = generic_reboot,
74 .cpu_flags = CPU_RAISEIPL,
75 .cpu_devs = ka53_devs,
76 .cpu_attach_cpu = ka53_attach_cpu,
77 };
78
79 void
ka53_conf(void)80 ka53_conf(void)
81 {
82
83 /* Don't ask why, but we seem to need this... */
84 volatile int *hej = (void *)mfpr(PR_ISP);
85 *hej = *hej;
86 hej[-1] = hej[-1];
87
88 cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1);
89 }
90
91 void
ka53_attach_cpu(device_t self)92 ka53_attach_cpu(device_t self)
93 {
94 const char *cpuname;
95
96 switch((vax_siedata & 0xff00) >> 8) {
97 case VAX_STYP_51: cpuname = "KA51"; break;
98 case VAX_STYP_52: cpuname = "KA52"; break;
99 case VAX_STYP_53: cpuname = "KA53,54,57"; break;
100 case VAX_STYP_55: cpuname = "KA55"; break;
101 default: cpuname = "unknown NVAX";
102 }
103 printf("cpu0: %s, ucode rev %d\n", cpuname, vax_cpudata & 0xff);
104 }
105
106 /*
107 * Why may we get memory errors during startup???
108 */
109
110 void
ka53_hardmem(void * arg)111 ka53_hardmem(void *arg)
112 {
113 if (cold == 0)
114 printf("Hard memory error\n");
115 splhigh();
116 }
117
118 void
ka53_softmem(void * arg)119 ka53_softmem(void *arg)
120 {
121 if (cold == 0)
122 printf("Soft memory error\n");
123 splhigh();
124 }
125
126 /*
127 * KA53-specific IPRs. KA53 has the funny habit to control all caches
128 * via IPRs.
129 */
130 #define PR_CCTL 0xa0
131 #define CCTL_ENABLE 0x00000001
132 #define CCTL_SW_ETM 0x40000000
133 #define CCTL_HW_ETM 0x80000000
134
135 #define PR_BCETSTS 0xa3
136 #define PR_BCEDSTS 0xa6
137 #define PR_NESTS 0xae
138
139 #define PR_VMAR 0xd0
140 #define PR_VTAG 0xd1
141 #define PR_ICSR 0xd3
142 #define ICSR_ENABLE 0x01
143
144 #define PR_PCCTL 0xf8
145 #define PCCTL_P_EN 0x10
146 #define PCCTL_I_EN 0x02
147 #define PCCTL_D_EN 0x01
148
149 void
ka53_cache_enable(void)150 ka53_cache_enable(void)
151 {
152 int start, slut;
153
154 /*
155 * Turn caches off.
156 */
157 mtpr(0, PR_ICSR);
158 mtpr(0, PR_PCCTL);
159 mtpr(mfpr(PR_CCTL) | CCTL_SW_ETM, PR_CCTL);
160
161 /*
162 * Invalidate caches.
163 */
164 mtpr(mfpr(PR_CCTL) | 6, PR_CCTL); /* Set cache size and speed */
165 mtpr(mfpr(PR_BCETSTS), PR_BCETSTS); /* Clear error bits */
166 mtpr(mfpr(PR_BCEDSTS), PR_BCEDSTS); /* Clear error bits */
167 mtpr(mfpr(PR_NESTS), PR_NESTS); /* Clear error bits */
168
169
170 start = 0x01400000;
171 slut = 0x01420000;
172
173 /* Flush cache lines */
174 for (; start < slut; start += 0x20)
175 mtpr(0, start);
176
177 mtpr((mfpr(PR_CCTL) & ~(CCTL_SW_ETM|CCTL_ENABLE)) | CCTL_HW_ETM,
178 PR_CCTL);
179
180 start = 0x01000000;
181 slut = 0x01020000;
182
183 /* clear tag and valid */
184 for (; start < slut; start += 0x20)
185 mtpr(0, start);
186
187 mtpr(mfpr(PR_CCTL) | 6 | CCTL_ENABLE, PR_CCTL); /* enab. bcache */
188
189 start = 0x01800000;
190 slut = 0x01802000;
191
192 /* Clear primary cache */
193 for (; start < slut; start += 0x20)
194 mtpr(0, start);
195
196 /* Flush the pipes (via REI) */
197 __asm("movpsl -(%sp); movab 1f,-(%sp); rei; 1:;");
198
199 /* Enable primary cache */
200 mtpr(PCCTL_P_EN|PCCTL_I_EN|PCCTL_D_EN, PR_PCCTL);
201
202 /* Enable the VIC */
203 start = 0;
204 slut = 0x800;
205 for (; start < slut; start += 0x20) {
206 mtpr(start, PR_VMAR);
207 mtpr(0, PR_VTAG);
208 }
209 mtpr(ICSR_ENABLE, PR_ICSR);
210 }
211
212 void
ka53_memerr(void)213 ka53_memerr(void)
214 {
215 printf("Memory err!\n");
216 }
217
218 int
ka53_mchk(void * addr)219 ka53_mchk(void *addr)
220 {
221 mtpr(0x00, PR_MCESR);
222 printf("Machine Check\n");
223 return 0;
224 }
225
226 void
ka53_steal_pages(void)227 ka53_steal_pages(void)
228 {
229
230 /*
231 * Get the soft and hard memory error vectors now.
232 */
233
234 scb_vecalloc(0x54, ka53_softmem, NULL, 0, NULL);
235 scb_vecalloc(0x60, ka53_hardmem, NULL, 0, NULL);
236
237
238 /* Turn on caches (to speed up execution a bit) */
239 ka53_cache_enable();
240 }
241