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