sb_machdep.c revision 201631
1/*- 2 * Copyright (c) 2007 Bruce M. Simpson. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: projects/mips/sys/mips/sibyte/sb_machdep.c 201631 2010-01-06 06:42:08Z neel $"); 29 30#include <sys/param.h> 31#include <machine/cpuregs.h> 32 33#include "opt_ddb.h" 34#include "opt_kdb.h" 35 36#include <sys/param.h> 37#include <sys/conf.h> 38#include <sys/kernel.h> 39#include <sys/systm.h> 40#include <sys/imgact.h> 41#include <sys/bio.h> 42#include <sys/buf.h> 43#include <sys/bus.h> 44#include <sys/cpu.h> 45#include <sys/cons.h> 46#include <sys/exec.h> 47#include <sys/ucontext.h> 48#include <sys/proc.h> 49#include <sys/kdb.h> 50#include <sys/ptrace.h> 51#include <sys/reboot.h> 52#include <sys/signalvar.h> 53#include <sys/sysent.h> 54#include <sys/sysproto.h> 55#include <sys/user.h> 56 57#include <vm/vm.h> 58#include <vm/vm_object.h> 59#include <vm/vm_page.h> 60#include <vm/vm_pager.h> 61 62#include <machine/cache.h> 63#include <machine/clock.h> 64#include <machine/cpu.h> 65#include <machine/cpuinfo.h> 66#include <machine/cpufunc.h> 67#include <machine/cpuregs.h> 68#include <machine/hwfunc.h> 69#include <machine/intr_machdep.h> 70#include <machine/locore.h> 71#include <machine/md_var.h> 72#include <machine/pte.h> 73#include <machine/sigframe.h> 74#include <machine/trap.h> 75#include <machine/vmparam.h> 76 77#ifdef CFE 78#include <dev/cfe/cfe_api.h> 79#endif 80 81#include "sb_scd.h" 82 83#ifdef DDB 84#ifndef KDB 85#error KDB must be enabled in order for DDB to work! 86#endif 87#endif 88 89#ifdef CFE_ENV 90extern void cfe_env_init(void); 91#endif 92 93extern int *edata; 94extern int *end; 95 96void 97platform_cpu_init() 98{ 99 /* Nothing special */ 100} 101 102static void 103mips_init(void) 104{ 105 int i, cfe_mem_idx, tmp; 106 uint64_t maxmem; 107 108#ifdef CFE_ENV 109 cfe_env_init(); 110#endif 111 112 TUNABLE_INT_FETCH("boothowto", &boothowto); 113 114 if (boothowto & RB_VERBOSE) 115 bootverbose++; 116 117#ifdef MAXMEM 118 tmp = MAXMEM; 119#else 120 tmp = 0; 121#endif 122 TUNABLE_INT_FETCH("hw.physmem", &tmp); 123 maxmem = (uint64_t)tmp * 1024; 124 125#ifdef CFE 126 /* 127 * Query DRAM memory map from CFE. 128 */ 129 physmem = 0; 130 cfe_mem_idx = 0; 131 for (i = 0; i < 10; i += 2) { 132 int result; 133 uint64_t addr, len, type; 134 135 result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type); 136 if (result < 0) { 137 phys_avail[i] = phys_avail[i + 1] = 0; 138 break; 139 } 140 141 KASSERT(type == CFE_MI_AVAILABLE, 142 ("CFE DRAM region is not available?")); 143 144 if (bootverbose) 145 printf("cfe_enummem: 0x%016jx/%llu.\n", addr, len); 146 147 if (maxmem != 0) { 148 if (addr >= maxmem) { 149 printf("Ignoring %llu bytes of memory at 0x%jx " 150 "that is above maxmem %dMB\n", 151 len, addr, 152 (int)(maxmem / (1024 * 1024))); 153 continue; 154 } 155 156 if (addr + len > maxmem) { 157 printf("Ignoring %llu bytes of memory " 158 "that is above maxmem %dMB\n", 159 (addr + len) - maxmem, 160 (int)(maxmem / (1024 * 1024))); 161 len = maxmem - addr; 162 } 163 } 164 165 phys_avail[i] = addr; 166 if (i == 0 && addr == 0) { 167 /* 168 * If this is the first physical memory segment probed 169 * from CFE, omit the region at the start of physical 170 * memory where the kernel has been loaded. 171 */ 172 phys_avail[i] += MIPS_KSEG0_TO_PHYS((vm_offset_t)&end); 173 } 174 phys_avail[i + 1] = addr + len; 175 physmem += len; 176 } 177 178 realmem = btoc(physmem); 179#endif 180 181 physmem = realmem; 182 183 init_param1(); 184 init_param2(physmem); 185 mips_cpu_init(); 186 pmap_bootstrap(); 187 mips_proc0_init(); 188 mutex_init(); 189 190 kdb_init(); 191#ifdef KDB 192 if (boothowto & RB_KDB) 193 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 194#endif 195} 196 197void 198platform_halt(void) 199{ 200 201} 202 203 204void 205platform_identify(void) 206{ 207 208} 209 210void 211platform_reset(void) 212{ 213 214 /* 215 * XXX SMP 216 * XXX flush data caches 217 */ 218 sb_system_reset(); 219} 220 221void 222platform_trap_enter(void) 223{ 224 225} 226 227void 228platform_trap_exit(void) 229{ 230 231} 232 233void 234platform_start(__register_t a0, __register_t a1, __register_t a2, 235 __register_t a3) 236{ 237 vm_offset_t kernend; 238 239 /* clear the BSS and SBSS segments */ 240 memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata); 241 kernend = round_page((vm_offset_t)&end); 242 243#ifdef CFE 244 /* 245 * Initialize CFE firmware trampolines before 246 * we initialize the low-level console. 247 * 248 * CFE passes the following values in registers: 249 * a0: firmware handle 250 * a2: firmware entry point 251 * a3: entry point seal 252 */ 253 if (a3 == CFE_EPTSEAL) 254 cfe_init(a0, a2); 255#endif 256 cninit(); 257 258 mips_init(); 259 260 mips_timer_init_params(sb_cpu_speed(), 0); 261} 262