beri_machdep.c revision 261274
1/*- 2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org> 3 * Copyright (c) 2012 Robert N. M. Watson 4 * All rights reserved. 5 * 6 * This software was developed by SRI International and the University of 7 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 8 * ("CTSRD"), as part of the DARPA CRASH research programme. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31#include <sys/cdefs.h> 32__FBSDID("$FreeBSD: stable/10/sys/mips/beri/beri_machdep.c 261274 2014-01-29 20:48:26Z brooks $"); 33 34#include "opt_ddb.h" 35#include "opt_platform.h" 36 37#include <sys/param.h> 38#include <sys/conf.h> 39#include <sys/kernel.h> 40#include <sys/systm.h> 41#include <sys/imgact.h> 42#include <sys/bio.h> 43#include <sys/buf.h> 44#include <sys/bus.h> 45#include <sys/cpu.h> 46#include <sys/cons.h> 47#include <sys/exec.h> 48#include <sys/linker.h> 49#include <sys/ucontext.h> 50#include <sys/proc.h> 51#include <sys/kdb.h> 52#include <sys/ptrace.h> 53#include <sys/reboot.h> 54#include <sys/signalvar.h> 55#include <sys/sysent.h> 56#include <sys/sysproto.h> 57#include <sys/user.h> 58 59#ifdef FDT 60#include <dev/fdt/fdt_common.h> 61#include <dev/ofw/openfirm.h> 62#endif 63 64#include <vm/vm.h> 65#include <vm/vm_object.h> 66#include <vm/vm_page.h> 67 68#include <machine/clock.h> 69#include <machine/cpu.h> 70#include <machine/cpuregs.h> 71#include <machine/hwfunc.h> 72#include <machine/md_var.h> 73#include <machine/metadata.h> 74#include <machine/pmap.h> 75#include <machine/trap.h> 76 77extern int *edata; 78extern int *end; 79 80void 81platform_cpu_init() 82{ 83 /* Nothing special */ 84} 85 86static void 87mips_init(void) 88{ 89 int i; 90 91 for (i = 0; i < 10; i++) { 92 phys_avail[i] = 0; 93 } 94 95 /* phys_avail regions are in bytes */ 96 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); 97 phys_avail[1] = ctob(realmem); 98 99 dump_avail[0] = phys_avail[0]; 100 dump_avail[1] = phys_avail[1]; 101 102 physmem = realmem; 103 104 init_param1(); 105 init_param2(physmem); 106 mips_cpu_init(); 107 pmap_bootstrap(); 108 mips_proc0_init(); 109 mutex_init(); 110 kdb_init(); 111#ifdef KDB 112 if (boothowto & RB_KDB) 113 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 114#endif 115} 116 117/* 118 * Perform a board-level soft-reset. 119 */ 120void 121platform_reset(void) 122{ 123 124 /* XXX SMP will likely require us to do more. */ 125 __asm__ __volatile__( 126 "mfc0 $k0, $12\n\t" 127 "li $k1, 0x00100000\n\t" 128 "or $k0, $k0, $k1\n\t" 129 "mtc0 $k0, $12\n"); 130 for( ; ; ) 131 __asm__ __volatile("wait"); 132} 133 134void 135platform_start(__register_t a0, __register_t a1, __register_t a2, 136 __register_t a3) 137{ 138 vm_offset_t kernend; 139 uint64_t platform_counter_freq; 140 int argc = a0; 141 char **argv = (char **)a1; 142 char **envp = (char **)a2; 143 unsigned int memsize = a3; 144#ifdef FDT 145 vm_offset_t dtbp; 146 void *kmdp; 147#endif 148 int i; 149 150 /* clear the BSS and SBSS segments */ 151 kernend = (vm_offset_t)&end; 152 memset(&edata, 0, kernend - (vm_offset_t)(&edata)); 153 154 mips_postboot_fixup(); 155 156 mips_pcpu0_init(); 157 158#ifdef FDT 159 /* 160 * Find the dtb passed in by the boot loader (currently fictional). 161 */ 162 kmdp = preload_search_by_type("elf kernel"); 163 if (kmdp != NULL) 164 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t); 165 else 166 dtbp = (vm_offset_t)NULL; 167 168#if defined(FDT_DTB_STATIC) 169 /* 170 * In case the device tree blob was not retrieved (from metadata) try 171 * to use the statically embedded one. 172 */ 173 if (dtbp == (vm_offset_t)NULL) 174 dtbp = (vm_offset_t)&fdt_static_dtb; 175#else 176#error "Non-static FDT not yet supported on BERI" 177#endif 178 179 if (OF_install(OFW_FDT, 0) == FALSE) 180 while (1); 181 if (OF_init((void *)dtbp) != 0) 182 while (1); 183#endif 184 185 /* 186 * XXXRW: We have no way to compare wallclock time to cycle rate on 187 * BERI, so for now assume we run at the MALTA default (100MHz). 188 */ 189 platform_counter_freq = MIPS_DEFAULT_HZ; 190 mips_timer_early_init(platform_counter_freq); 191 192 cninit(); 193 printf("entry: platform_start()\n"); 194 195 bootverbose = 1; 196 if (bootverbose) { 197 printf("cmd line: "); 198 for (i = 0; i < argc; i++) 199 printf("%s ", argv[i]); 200 printf("\n"); 201 202 printf("envp:\n"); 203 for (i = 0; envp[i]; i += 2) 204 printf("\t%s = %s\n", envp[i], envp[i+1]); 205 206 printf("memsize = %08x\n", memsize); 207 } 208 209 realmem = btoc(memsize); 210 mips_init(); 211 212 mips_timer_init_params(platform_counter_freq, 0); 213} 214