1 /* $NetBSD: ka410.c,v 1.33 2010/12/14 23:44:49 matt 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/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: ka410.c,v 1.33 2010/12/14 23:44:49 matt Exp $"); 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/cpu.h> 41 #include <sys/device.h> 42 #include <sys/kernel.h> 43 44 #include <machine/sid.h> 45 #include <machine/nexus.h> 46 #include <machine/ka410.h> 47 #include <machine/ka420.h> 48 #include <machine/clock.h> 49 #include <machine/vsbus.h> 50 51 static void ka410_conf(void); 52 static void ka410_memerr(void); 53 static int ka410_mchk(void *); 54 static void ka410_halt(void); 55 static void ka410_reboot(int); 56 static void ka41_cache_enable(void); 57 static void ka410_clrf(void); 58 59 static const char * const ka410_devs[] = { "cpu", "vsbus", NULL }; 60 61 static void * l2cache; /* mapped in address */ 62 static long *cacr; /* l2csche ctlr reg */ 63 64 /* 65 * Declaration of 410-specific calls. 66 */ 67 const struct cpu_dep ka410_calls = { 68 .cpu_mchk = ka410_mchk, 69 .cpu_memerr = ka410_memerr, 70 .cpu_conf = ka410_conf, 71 .cpu_gettime = chip_gettime, 72 .cpu_settime = chip_settime, 73 .cpu_vups = 1, /* ~VUPS */ 74 .cpu_scbsz = 2, /* SCB pages */ 75 .cpu_halt = ka410_halt, 76 .cpu_reboot = ka410_reboot, 77 .cpu_clrf = ka410_clrf, 78 .cpu_devs = ka410_devs, 79 .cpu_flags = CPU_RAISEIPL, 80 }; 81 82 83 void 84 ka410_conf(void) 85 { 86 struct cpu_info * const ci = curcpu(); 87 struct vs_cpu *ka410_cpu; 88 89 ka410_cpu = (struct vs_cpu *)vax_map_physmem(VS_REGS, 1); 90 91 switch (vax_cputype) { 92 case VAX_TYP_UV2: 93 ka410_cpu->vc_410mser = 1; 94 ci->ci_cpustr = "KA410, UV2"; 95 break; 96 97 case VAX_TYP_CVAX: 98 ka410_cpu->vc_vdcorg = 0; /* XXX */ 99 ka410_cpu->vc_parctl = PARCTL_CPEN | PARCTL_DPEN ; 100 mtpr(KA420_CADR_S2E|KA420_CADR_S1E|KA420_CADR_ISE|KA420_CADR_DSE, PR_CADR); 101 if (vax_confdata & KA420_CFG_CACHPR) { 102 l2cache = (void *)vax_map_physmem(KA420_CH2_BASE, 103 (KA420_CH2_SIZE / VAX_NBPG)); 104 cacr = (void *)vax_map_physmem(KA420_CACR, 1); 105 ka41_cache_enable(); 106 ci->ci_cpustr = 107 "KA420, CVAX, 1KB L1 cache, 64KB L2 cache"; 108 } else { 109 ci->ci_cpustr = "KA420, CVAX, 1KB L1 cache"; 110 } 111 } 112 /* Done with ka410_cpu - release it */ 113 vax_unmap_physmem((vaddr_t)ka410_cpu, 1); 114 /* 115 * Setup parameters necessary to read time from clock chip. 116 */ 117 clk_adrshift = 1; /* Addressed at long's... */ 118 clk_tweak = 2; /* ...and shift two */ 119 clk_page = (short *)vax_map_physmem(KA420_WAT_BASE, 1); 120 } 121 122 void 123 ka41_cache_enable(void) 124 { 125 *cacr = KA420_CACR_TPE; /* Clear any error, disable cache */ 126 memset(l2cache, 0, KA420_CH2_SIZE); /* Clear whole cache */ 127 *cacr = KA420_CACR_CEN; /* Enable cache */ 128 } 129 130 void 131 ka410_memerr(void) 132 { 133 printf("Memory err!\n"); 134 } 135 136 int 137 ka410_mchk(void *addr) 138 { 139 panic("Machine check"); 140 return 0; 141 } 142 143 static void 144 ka410_halt(void) 145 { 146 __asm("movl $0xc, (%0)"::"r"((int)clk_page + 0x38)); /* Don't ask */ 147 __asm("halt"); 148 } 149 150 static void 151 ka410_reboot(int arg) 152 { 153 __asm("movl $0xc, (%0)"::"r"((int)clk_page + 0x38)); /* Don't ask */ 154 __asm("halt"); 155 } 156 157 static void 158 ka410_clrf(void) 159 { 160 volatile struct ka410_clock *clk = (volatile void *)clk_page; 161 162 /* 163 * Clear restart and boot in progress flags 164 * in the CPMBX. (ie. clear bits 4 and 5) 165 */ 166 clk->cpmbx = (clk->cpmbx & ~0x30); 167 } 168