sb_machdep.c revision 195333
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 195333 2009-07-04 03:05:48Z imp $"); 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 90extern uint32_t cfe_handle; 91extern uint32_t cfe_vector; 92#endif 93 94#ifdef CFE_ENV 95extern void cfe_env_init(void); 96#endif 97 98extern int *edata; 99extern int *end; 100 101static void 102mips_init(void) 103{ 104 int i, cfe_mem_idx, tmp; 105 uint64_t maxmem; 106 107#ifdef CFE_ENV 108 cfe_env_init(); 109#endif 110 111 TUNABLE_INT_FETCH("boothowto", &boothowto); 112 113 if (boothowto & RB_VERBOSE) 114 bootverbose++; 115 116#ifdef MAXMEM 117 tmp = MAXMEM; 118#else 119 tmp = 0; 120#endif 121 TUNABLE_INT_FETCH("hw.physmem", &tmp); 122 maxmem = (uint64_t)tmp * 1024; 123 124#ifdef CFE 125 /* 126 * Query DRAM memory map from CFE. 127 */ 128 physmem = 0; 129 cfe_mem_idx = 0; 130 for (i = 0; i < 10; i += 2) { 131 int result; 132 uint64_t addr, len, type; 133 134 result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type); 135 if (result < 0) { 136 phys_avail[i] = phys_avail[i + 1] = 0; 137 break; 138 } 139 140 KASSERT(type == CFE_MI_AVAILABLE, 141 ("CFE DRAM region is not available?")); 142 143 if (bootverbose) 144 printf("cfe_enummem: 0x%016jx/%llu.\n", addr, len); 145 146 if (maxmem != 0) { 147 if (addr >= maxmem) { 148 printf("Ignoring %llu bytes of memory at 0x%jx " 149 "that is above maxmem %dMB\n", 150 len, addr, 151 (int)(maxmem / (1024 * 1024))); 152 continue; 153 } 154 155 if (addr + len > maxmem) { 156 printf("Ignoring %llu bytes of memory " 157 "that is above maxmem %dMB\n", 158 (addr + len) - maxmem, 159 (int)(maxmem / (1024 * 1024))); 160 len = maxmem - addr; 161 } 162 } 163 164 phys_avail[i] = addr; 165 if (i == 0 && addr == 0) { 166 /* 167 * If this is the first physical memory segment probed 168 * from CFE, omit the region at the start of physical 169 * memory where the kernel has been loaded. 170 */ 171 phys_avail[i] += MIPS_KSEG0_TO_PHYS((vm_offset_t)&end); 172 } 173 phys_avail[i + 1] = addr + len; 174 physmem += len; 175 } 176 177 realmem = btoc(physmem); 178#endif 179 180 physmem = realmem; 181 182 init_param1(); 183 init_param2(physmem); 184 mips_cpu_init(); 185 pmap_bootstrap(); 186 mips_proc0_init(); 187 mutex_init(); 188 189 kdb_init(); 190#ifdef KDB 191 if (boothowto & RB_KDB) 192 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 193#endif 194} 195 196void 197platform_halt(void) 198{ 199 200} 201 202 203void 204platform_identify(void) 205{ 206 207} 208 209void 210platform_reset(void) 211{ 212 213 /* 214 * XXX SMP 215 * XXX flush data caches 216 */ 217 sb_system_reset(); 218} 219 220void 221platform_trap_enter(void) 222{ 223 224} 225 226void 227platform_trap_exit(void) 228{ 229 230} 231 232void 233platform_start(__register_t a0 __unused, __register_t a1 __unused, 234 __register_t a2 __unused, __register_t a3 __unused) 235{ 236 vm_offset_t kernend; 237 238 /* clear the BSS and SBSS segments */ 239 memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata); 240 kernend = round_page((vm_offset_t)&end); 241 242#ifdef CFE 243 /* 244 * Initialize CFE firmware trampolines before 245 * we initialize the low-level console. 246 */ 247 if (cfe_handle != 0) 248 cfe_init(cfe_handle, cfe_vector); 249#endif 250 cninit(); 251 252#ifdef CFE 253 if (cfe_handle == 0) 254 panic("CFE was not detected by locore.\n"); 255#endif 256 mips_init(); 257 258 mips_timer_init_params(sb_cpu_speed(), 0); 259} 260