1/*- 2 * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 22 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $Id: $ 26 * 27 */ 28 29#include <sys/cdefs.h> 30__FBSDID("$FreeBSD: releng/10.2/sys/mips/idt/idt_machdep.c 247297 2013-02-26 01:00:11Z attilio $"); 31 32#include "opt_ddb.h" 33 34#include <sys/param.h> 35#include <sys/conf.h> 36#include <sys/kernel.h> 37#include <sys/systm.h> 38#include <sys/imgact.h> 39#include <sys/bio.h> 40#include <sys/buf.h> 41#include <sys/bus.h> 42#include <sys/cpu.h> 43#include <sys/cons.h> 44#include <sys/exec.h> 45#include <sys/ucontext.h> 46#include <sys/proc.h> 47#include <sys/kdb.h> 48#include <sys/ptrace.h> 49#include <sys/reboot.h> 50#include <sys/signalvar.h> 51#include <sys/sysent.h> 52#include <sys/sysproto.h> 53#include <sys/user.h> 54 55#include <vm/vm.h> 56#include <vm/vm_object.h> 57#include <vm/vm_page.h> 58 59#include <machine/cache.h> 60#include <machine/clock.h> 61#include <machine/cpu.h> 62#include <machine/cpuinfo.h> 63#include <machine/cpufunc.h> 64#include <machine/cpuregs.h> 65#include <machine/hwfunc.h> 66#include <machine/intr_machdep.h> 67#include <machine/locore.h> 68#include <machine/md_var.h> 69#include <machine/pte.h> 70#include <machine/sigframe.h> 71#include <machine/trap.h> 72#include <machine/vmparam.h> 73 74extern int *edata; 75extern int *end; 76 77void 78platform_cpu_init() 79{ 80 /* Nothing special */ 81} 82 83void 84platform_reset(void) 85{ 86 volatile unsigned int * p = (void *)0xb8008000; 87 /* 88 * TODO: we should take care of TLB stuff here. Otherwise 89 * board does not boots properly next time 90 */ 91 92 /* Write 0x8000_0001 to the Reset register */ 93 *p = 0x80000001; 94 95 __asm __volatile("li $25, 0xbfc00000"); 96 __asm __volatile("j $25"); 97} 98 99void 100platform_start(__register_t a0, __register_t a1, 101 __register_t a2 __unused, __register_t a3 __unused) 102{ 103 uint64_t platform_counter_freq; 104 vm_offset_t kernend; 105 int argc = a0; 106 char **argv = (char **)a1; 107 int i, mem; 108 109 110 /* clear the BSS and SBSS segments */ 111 kernend = (vm_offset_t)&end; 112 memset(&edata, 0, kernend - (vm_offset_t)(&edata)); 113 114 mips_postboot_fixup(); 115 116 /* Initialize pcpu stuff */ 117 mips_pcpu0_init(); 118 119 /* 120 * Looking for mem=XXM argument 121 */ 122 mem = 0; /* Just something to start with */ 123 for (i=0; i < argc; i++) { 124 if (strncmp(argv[i], "mem=", 4) == 0) { 125 mem = strtol(argv[i] + 4, NULL, 0); 126 break; 127 } 128 } 129 130 bootverbose = 1; 131 if (mem > 0) 132 realmem = btoc(mem << 20); 133 else 134 realmem = btoc(32 << 20); 135 136 for (i = 0; i < 10; i++) { 137 phys_avail[i] = 0; 138 } 139 140 /* phys_avail regions are in bytes */ 141 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); 142 phys_avail[1] = ctob(realmem); 143 144 dump_avail[0] = phys_avail[0]; 145 dump_avail[1] = phys_avail[1]; 146 147 physmem = realmem; 148 149 /* 150 * ns8250 uart code uses DELAY so ticker should be inititalized 151 * before cninit. And tick_init_params refers to hz, so * init_param1 152 * should be called first. 153 */ 154 init_param1(); 155 /* TODO: parse argc,argv */ 156 platform_counter_freq = 330000000UL; 157 mips_timer_init_params(platform_counter_freq, 1); 158 cninit(); 159 /* Panic here, after cninit */ 160 if (mem == 0) 161 panic("No mem=XX parameter in arguments"); 162 163 printf("cmd line: "); 164 for (i=0; i < argc; i++) 165 printf("%s ", argv[i]); 166 printf("\n"); 167 168 init_param2(physmem); 169 mips_cpu_init(); 170 pmap_bootstrap(); 171 mips_proc0_init(); 172 mutex_init(); 173 kdb_init(); 174#ifdef KDB 175 if (boothowto & RB_KDB) 176 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 177#endif 178} 179