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