sb_machdep.c revision 202864
1195333Simp/*- 2195333Simp * Copyright (c) 2007 Bruce M. Simpson. 3195333Simp * All rights reserved. 4195333Simp * 5195333Simp * Redistribution and use in source and binary forms, with or without 6195333Simp * modification, are permitted provided that the following conditions 7195333Simp * are met: 8195333Simp * 1. Redistributions of source code must retain the above copyright 9195333Simp * notice, this list of conditions and the following disclaimer. 10195333Simp * 2. Redistributions in binary form must reproduce the above copyright 11195333Simp * notice, this list of conditions and the following disclaimer in the 12195333Simp * documentation and/or other materials provided with the distribution. 13195333Simp * 14195333Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15195333Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16195333Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17195333Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18195333Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19195333Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20195333Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21195333Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22195333Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23195333Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24195333Simp * SUCH DAMAGE. 25195333Simp */ 26195333Simp 27195333Simp#include <sys/cdefs.h> 28195333Simp__FBSDID("$FreeBSD: head/sys/mips/sibyte/sb_machdep.c 202864 2010-01-23 03:19:13Z neel $"); 29195333Simp 30195333Simp#include <sys/param.h> 31195333Simp#include <machine/cpuregs.h> 32195333Simp 33195333Simp#include "opt_ddb.h" 34195333Simp#include "opt_kdb.h" 35195333Simp 36195333Simp#include <sys/param.h> 37195333Simp#include <sys/conf.h> 38195333Simp#include <sys/kernel.h> 39195333Simp#include <sys/systm.h> 40195333Simp#include <sys/imgact.h> 41195333Simp#include <sys/bio.h> 42195333Simp#include <sys/buf.h> 43195333Simp#include <sys/bus.h> 44195333Simp#include <sys/cpu.h> 45195333Simp#include <sys/cons.h> 46195333Simp#include <sys/exec.h> 47195333Simp#include <sys/ucontext.h> 48195333Simp#include <sys/proc.h> 49195333Simp#include <sys/kdb.h> 50195333Simp#include <sys/ptrace.h> 51195333Simp#include <sys/reboot.h> 52195333Simp#include <sys/signalvar.h> 53195333Simp#include <sys/sysent.h> 54195333Simp#include <sys/sysproto.h> 55195333Simp#include <sys/user.h> 56195333Simp 57195333Simp#include <vm/vm.h> 58195333Simp#include <vm/vm_object.h> 59195333Simp#include <vm/vm_page.h> 60195333Simp#include <vm/vm_pager.h> 61195333Simp 62195333Simp#include <machine/cache.h> 63195333Simp#include <machine/clock.h> 64195333Simp#include <machine/cpu.h> 65195333Simp#include <machine/cpuinfo.h> 66195333Simp#include <machine/cpufunc.h> 67195333Simp#include <machine/cpuregs.h> 68195333Simp#include <machine/hwfunc.h> 69195333Simp#include <machine/intr_machdep.h> 70195333Simp#include <machine/locore.h> 71195333Simp#include <machine/md_var.h> 72195333Simp#include <machine/pte.h> 73195333Simp#include <machine/sigframe.h> 74195333Simp#include <machine/trap.h> 75195333Simp#include <machine/vmparam.h> 76195333Simp 77195333Simp#ifdef CFE 78195333Simp#include <dev/cfe/cfe_api.h> 79195333Simp#endif 80195333Simp 81195333Simp#include "sb_scd.h" 82195333Simp 83195333Simp#ifdef DDB 84195333Simp#ifndef KDB 85195333Simp#error KDB must be enabled in order for DDB to work! 86195333Simp#endif 87195333Simp#endif 88195333Simp 89195333Simp#ifdef CFE_ENV 90195333Simpextern void cfe_env_init(void); 91195333Simp#endif 92195333Simp 93195333Simpextern int *edata; 94195333Simpextern int *end; 95195333Simp 96198669Srrsvoid 97198669Srrsplatform_cpu_init() 98198669Srrs{ 99198669Srrs /* Nothing special */ 100198669Srrs} 101198669Srrs 102195333Simpstatic void 103195333Simpmips_init(void) 104195333Simp{ 105195333Simp int i, cfe_mem_idx, tmp; 106195333Simp uint64_t maxmem; 107195333Simp 108195333Simp#ifdef CFE_ENV 109195333Simp cfe_env_init(); 110195333Simp#endif 111195333Simp 112195333Simp TUNABLE_INT_FETCH("boothowto", &boothowto); 113195333Simp 114195333Simp if (boothowto & RB_VERBOSE) 115195333Simp bootverbose++; 116195333Simp 117195333Simp#ifdef MAXMEM 118195333Simp tmp = MAXMEM; 119195333Simp#else 120195333Simp tmp = 0; 121195333Simp#endif 122195333Simp TUNABLE_INT_FETCH("hw.physmem", &tmp); 123195333Simp maxmem = (uint64_t)tmp * 1024; 124195333Simp 125195333Simp#ifdef CFE 126195333Simp /* 127195333Simp * Query DRAM memory map from CFE. 128195333Simp */ 129195333Simp physmem = 0; 130195333Simp cfe_mem_idx = 0; 131195333Simp for (i = 0; i < 10; i += 2) { 132195333Simp int result; 133195333Simp uint64_t addr, len, type; 134195333Simp 135195333Simp result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type); 136195333Simp if (result < 0) { 137195333Simp phys_avail[i] = phys_avail[i + 1] = 0; 138195333Simp break; 139195333Simp } 140195333Simp 141195333Simp KASSERT(type == CFE_MI_AVAILABLE, 142195333Simp ("CFE DRAM region is not available?")); 143195333Simp 144195333Simp if (bootverbose) 145195333Simp printf("cfe_enummem: 0x%016jx/%llu.\n", addr, len); 146195333Simp 147195333Simp if (maxmem != 0) { 148195333Simp if (addr >= maxmem) { 149195333Simp printf("Ignoring %llu bytes of memory at 0x%jx " 150195333Simp "that is above maxmem %dMB\n", 151195333Simp len, addr, 152195333Simp (int)(maxmem / (1024 * 1024))); 153195333Simp continue; 154195333Simp } 155195333Simp 156195333Simp if (addr + len > maxmem) { 157195333Simp printf("Ignoring %llu bytes of memory " 158195333Simp "that is above maxmem %dMB\n", 159195333Simp (addr + len) - maxmem, 160195333Simp (int)(maxmem / (1024 * 1024))); 161195333Simp len = maxmem - addr; 162195333Simp } 163195333Simp } 164195333Simp 165195333Simp phys_avail[i] = addr; 166195333Simp if (i == 0 && addr == 0) { 167195333Simp /* 168195333Simp * If this is the first physical memory segment probed 169195333Simp * from CFE, omit the region at the start of physical 170195333Simp * memory where the kernel has been loaded. 171195333Simp */ 172195333Simp phys_avail[i] += MIPS_KSEG0_TO_PHYS((vm_offset_t)&end); 173195333Simp } 174195333Simp phys_avail[i + 1] = addr + len; 175195333Simp physmem += len; 176195333Simp } 177195333Simp 178195333Simp realmem = btoc(physmem); 179195333Simp#endif 180195333Simp 181195333Simp physmem = realmem; 182195333Simp 183195333Simp init_param1(); 184195333Simp init_param2(physmem); 185195333Simp mips_cpu_init(); 186195333Simp pmap_bootstrap(); 187195333Simp mips_proc0_init(); 188195333Simp mutex_init(); 189195333Simp 190195333Simp kdb_init(); 191195333Simp#ifdef KDB 192195333Simp if (boothowto & RB_KDB) 193195333Simp kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 194195333Simp#endif 195195333Simp} 196195333Simp 197195333Simpvoid 198195333Simpplatform_halt(void) 199195333Simp{ 200195333Simp 201195333Simp} 202195333Simp 203195333Simp 204195333Simpvoid 205195333Simpplatform_identify(void) 206195333Simp{ 207195333Simp 208195333Simp} 209195333Simp 210195333Simpvoid 211195333Simpplatform_reset(void) 212195333Simp{ 213195333Simp 214195333Simp /* 215195333Simp * XXX SMP 216195333Simp * XXX flush data caches 217195333Simp */ 218195333Simp sb_system_reset(); 219195333Simp} 220195333Simp 221195333Simpvoid 222195333Simpplatform_trap_enter(void) 223195333Simp{ 224195333Simp 225195333Simp} 226195333Simp 227195333Simpvoid 228195333Simpplatform_trap_exit(void) 229195333Simp{ 230195333Simp 231195333Simp} 232195333Simp 233202864Sneelstatic void 234202864Sneelkseg0_map_coherent(void) 235202864Sneel{ 236202864Sneel uint32_t config; 237202864Sneel const int CFG_K0_COHERENT = 5; 238202864Sneel 239202864Sneel config = mips_rd_config(); 240202864Sneel config &= ~CFG_K0_MASK; 241202864Sneel config |= CFG_K0_COHERENT; 242202864Sneel mips_wr_config(config); 243202864Sneel} 244202864Sneel 245195333Simpvoid 246201631Sneelplatform_start(__register_t a0, __register_t a1, __register_t a2, 247201631Sneel __register_t a3) 248195333Simp{ 249195333Simp vm_offset_t kernend; 250195333Simp 251202864Sneel /* 252202864Sneel * Make sure that kseg0 is mapped cacheable-coherent 253202864Sneel */ 254202864Sneel kseg0_map_coherent(); 255202864Sneel 256195333Simp /* clear the BSS and SBSS segments */ 257195333Simp memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata); 258195333Simp kernend = round_page((vm_offset_t)&end); 259195333Simp 260201845Simp /* Initialize pcpu stuff */ 261201881Simp mips_pcpu0_init(); 262201845Simp 263195333Simp#ifdef CFE 264195333Simp /* 265195333Simp * Initialize CFE firmware trampolines before 266195333Simp * we initialize the low-level console. 267201631Sneel * 268201631Sneel * CFE passes the following values in registers: 269201631Sneel * a0: firmware handle 270201631Sneel * a2: firmware entry point 271201631Sneel * a3: entry point seal 272195333Simp */ 273201631Sneel if (a3 == CFE_EPTSEAL) 274201631Sneel cfe_init(a0, a2); 275195333Simp#endif 276195333Simp cninit(); 277195333Simp 278195333Simp mips_init(); 279195333Simp 280195333Simp mips_timer_init_params(sb_cpu_speed(), 0); 281195333Simp} 282