1 /* $NetBSD: ka660.c,v 1.10 2010/12/14 23:44:49 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.10 2010/12/14 23:44:49 matt Exp $"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/cpu.h> 39 #include <sys/device.h> 40 #include <sys/kernel.h> 41 42 #include <machine/sid.h> 43 #include <machine/nexus.h> 44 #include <machine/ka410.h> 45 #include <machine/ka420.h> 46 #include <machine/clock.h> 47 #include <machine/vsbus.h> 48 49 #define KA660_CCR 37 /* Cache Control Register */ 50 #define KA660_CTAG 0x20150000 /* Cache Tags */ 51 #define KA660_CDATA 0x20150400 /* Cache Data */ 52 #define KA660_BEHR 0x20150800 /* Bank Enable/Hit Register */ 53 #define CCR_WWP 8 /* Write Wrong Parity */ 54 #define CCR_ENA 4 /* Cache Enable */ 55 #define CCR_FLU 2 /* Cache Flush */ 56 #define CCR_DIA 1 /* Diagnostic mode */ 57 58 static void ka660_conf(void); 59 static void ka660_memerr(void); 60 static void ka660_cache_enable(void); 61 static void ka660_attach_cpu(device_t); 62 static int ka660_mchk(void *); 63 64 static const char * const ka660_devs[] = { "cpu", "sgec", "vsbus", NULL }; 65 66 /* 67 * Declaration of 660-specific calls. 68 */ 69 const struct cpu_dep ka660_calls = { 70 .cpu_steal_pages = ka660_cache_enable, /* ewww */ 71 .cpu_mchk = ka660_mchk, 72 .cpu_memerr = ka660_memerr, 73 .cpu_conf = ka660_conf, 74 .cpu_gettime = generic_gettime, 75 .cpu_settime = generic_settime, 76 .cpu_vups = 6, /* ~VUPS */ 77 .cpu_scbsz = 2, /* SCB pages */ 78 .cpu_halt = generic_halt, 79 .cpu_reboot = generic_reboot, 80 .cpu_devs = ka660_devs, 81 .cpu_attach_cpu = ka660_attach_cpu, 82 }; 83 84 85 void 86 ka660_conf(void) 87 { 88 cpmbx = (struct cpmbx *)vax_map_physmem(0x20140400, 1); 89 } 90 91 void 92 ka660_attach_cpu(device_t self) 93 { 94 aprint_normal( 95 ": %s, Rigel (ucode rev. %d), 2KB L1 cache, 128KB L2 cache\n", 96 "KA660", 97 vax_cpudata & 0377); 98 } 99 100 void 101 ka660_cache_enable(void) 102 { 103 unsigned int *p; 104 int cnt, bnk, behrtmp; 105 106 mtpr(0, KA660_CCR); /* Disable cache */ 107 mtpr(CCR_DIA, KA660_CCR); /* Switch to diag mode */ 108 bnk = 1; 109 behrtmp = 0; 110 while(bnk <= 0x80) 111 { 112 *(int *)KA660_BEHR = bnk; 113 p = (int *)KA660_CDATA; 114 *p = 0x55aaff00L; 115 if(*p == 0x55aaff00L) behrtmp |= bnk; 116 *p = 0xffaa0055L; 117 if(*p != 0xffaa0055L) behrtmp &= ~bnk; 118 cnt = 256; 119 while(cnt--) *p++ = 0L; 120 p = (int *) KA660_CTAG; 121 cnt =128; 122 while(cnt--) { *p++ = 0x80000000L; p++; } 123 bnk <<= 1; 124 } 125 *(int *)KA660_BEHR = behrtmp; 126 127 mtpr(CCR_DIA|CCR_FLU, KA660_CCR); /* Flush tags */ 128 mtpr(CCR_ENA, KA660_CCR); /* Enable cache */ 129 } 130 131 void 132 ka660_memerr(void) 133 { 134 printf("Memory err!\n"); 135 } 136 137 int 138 ka660_mchk(void *addr) 139 { 140 panic("Machine check"); 141 return 0; 142 } 143