1178173Simp/*- 2178173Simp * Copyright (c) 2007 Bruce M. Simpson. 3178173Simp * All rights reserved. 4178173Simp * 5178173Simp * Redistribution and use in source and binary forms, with or without 6178173Simp * modification, are permitted provided that the following conditions 7178173Simp * are met: 8178173Simp * 1. Redistributions of source code must retain the above copyright 9178173Simp * notice, this list of conditions and the following disclaimer. 10178173Simp * 2. Redistributions in binary form must reproduce the above copyright 11178173Simp * notice, this list of conditions and the following disclaimer in the 12178173Simp * documentation and/or other materials provided with the distribution. 13178173Simp * 14178173Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15178173Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16178173Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17178173Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18178173Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19178173Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20178173Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21178173Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22178173Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23178173Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24178173Simp * SUCH DAMAGE. 25178173Simp */ 26178173Simp 27178173Simp#include <sys/cdefs.h> 28178173Simp__FBSDID("$FreeBSD$"); 29178173Simp 30178173Simp#include "opt_ddb.h" 31178173Simp 32178173Simp#include <sys/param.h> 33178173Simp#include <sys/conf.h> 34178173Simp#include <sys/kernel.h> 35178173Simp#include <sys/systm.h> 36178173Simp#include <sys/imgact.h> 37178173Simp#include <sys/bio.h> 38178173Simp#include <sys/buf.h> 39178173Simp#include <sys/bus.h> 40178173Simp#include <sys/cpu.h> 41178173Simp#include <sys/cons.h> 42178173Simp#include <sys/exec.h> 43178173Simp#include <sys/ucontext.h> 44178173Simp#include <sys/proc.h> 45178173Simp#include <sys/kdb.h> 46178173Simp#include <sys/ptrace.h> 47178173Simp#include <sys/reboot.h> 48178173Simp#include <sys/signalvar.h> 49178173Simp#include <sys/sysent.h> 50178173Simp#include <sys/sysproto.h> 51178173Simp#include <sys/user.h> 52178173Simp 53178173Simp#include <vm/vm.h> 54178173Simp#include <vm/vm_object.h> 55178173Simp#include <vm/vm_page.h> 56178173Simp#include <vm/vm_pager.h> 57178173Simp 58178173Simp#include <machine/cache.h> 59178173Simp#include <machine/clock.h> 60178173Simp#include <machine/cpu.h> 61178173Simp#include <machine/cpuinfo.h> 62178173Simp#include <machine/cpufunc.h> 63178173Simp#include <machine/cpuregs.h> 64178173Simp#include <machine/hwfunc.h> 65178173Simp#include <machine/intr_machdep.h> 66178173Simp#include <machine/locore.h> 67178173Simp#include <machine/md_var.h> 68178173Simp#include <machine/pte.h> 69178173Simp#include <machine/sigframe.h> 70178173Simp#include <machine/trap.h> 71178173Simp#include <machine/vmparam.h> 72178173Simp 73223562Skevlo#include <mips/sentry5/s5reg.h> 74223562Skevlo 75178173Simp#ifdef CFE 76178173Simp#include <dev/cfe/cfe_api.h> 77178173Simp#endif 78178173Simp 79178173Simpextern int *edata; 80178173Simpextern int *end; 81178173Simp 82202036Simpvoid 83202036Simpplatform_cpu_init() 84202036Simp{ 85202036Simp /* Nothing special */ 86202036Simp} 87202036Simp 88178173Simpstatic void 89178173Simpmips_init(void) 90178173Simp{ 91216318Sgonzo int i, j; 92178173Simp 93178173Simp printf("entry: mips_init()\n"); 94178173Simp 95178173Simp#ifdef CFE 96178173Simp /* 97178173Simp * Query DRAM memory map from CFE. 98178173Simp */ 99178173Simp physmem = 0; 100178173Simp for (i = 0; i < 10; i += 2) { 101178173Simp int result; 102178173Simp uint64_t addr, len, type; 103178173Simp 104178173Simp result = cfe_enummem(i, 0, &addr, &len, &type); 105178173Simp if (result < 0) { 106178173Simp phys_avail[i] = phys_avail[i + 1] = 0; 107178173Simp break; 108178173Simp } 109178173Simp if (type != CFE_MI_AVAILABLE) 110178173Simp continue; 111178173Simp 112178173Simp phys_avail[i] = addr; 113178173Simp if (i == 0 && addr == 0) { 114178173Simp /* 115178173Simp * If this is the first physical memory segment probed 116178173Simp * from CFE, omit the region at the start of physical 117178173Simp * memory where the kernel has been loaded. 118178173Simp */ 119202954Sgonzo phys_avail[i] += MIPS_KSEG0_TO_PHYS(kernel_kseg0_end); 120178173Simp } 121178173Simp phys_avail[i + 1] = addr + len; 122178173Simp physmem += len; 123178173Simp } 124178173Simp 125178173Simp realmem = btoc(physmem); 126178173Simp#endif 127178173Simp 128216320Sgonzo for (j = 0; j < i; j++) 129216318Sgonzo dump_avail[j] = phys_avail[j]; 130216318Sgonzo 131178173Simp physmem = realmem; 132178173Simp 133178173Simp init_param1(); 134178173Simp init_param2(physmem); 135178173Simp mips_cpu_init(); 136178173Simp pmap_bootstrap(); 137178173Simp mips_proc0_init(); 138178173Simp mutex_init(); 139178173Simp kdb_init(); 140202849Simp#ifdef KDB 141202849Simp if (boothowto & RB_KDB) 142202849Simp kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); 143178173Simp#endif 144178173Simp} 145178173Simp 146178173Simpvoid 147178173Simpplatform_halt(void) 148178173Simp{ 149178173Simp 150178173Simp} 151178173Simp 152178173Simp 153178173Simpvoid 154178173Simpplatform_identify(void) 155178173Simp{ 156178173Simp 157178173Simp} 158178173Simp 159178173Simpvoid 160178173Simpplatform_reset(void) 161178173Simp{ 162178173Simp 163178173Simp#if defined(CFE) 164178173Simp cfe_exit(0, 0); 165178173Simp#else 166178173Simp *((volatile uint8_t *)MIPS_PHYS_TO_KSEG1(SENTRY5_EXTIFADR)) = 0x80; 167178173Simp#endif 168178173Simp} 169178173Simp 170178173Simpvoid 171178173Simpplatform_trap_enter(void) 172178173Simp{ 173178173Simp 174178173Simp} 175178173Simp 176178173Simpvoid 177178173Simpplatform_trap_exit(void) 178178173Simp{ 179178173Simp 180178173Simp} 181178173Simp 182178173Simpvoid 183202036Simpplatform_start(__register_t a0, __register_t a1, __register_t a2, 184202036Simp __register_t a3) 185178173Simp{ 186178173Simp vm_offset_t kernend; 187178173Simp uint64_t platform_counter_freq; 188178173Simp 189178173Simp /* clear the BSS and SBSS segments */ 190202954Sgonzo kernend = (vm_offset_t)&end; 191178173Simp memset(&edata, 0, kernend - (vm_offset_t)(&edata)); 192178173Simp 193202954Sgonzo mips_postboot_fixup(); 194202954Sgonzo 195202036Simp /* Initialize pcpu stuff */ 196202036Simp mips_pcpu0_init(); 197202036Simp 198178173Simp#ifdef CFE 199178173Simp /* 200178173Simp * Initialize CFE firmware trampolines before 201178173Simp * we initialize the low-level console. 202202036Simp * 203202036Simp * CFE passes the following values in registers: 204202036Simp * a0: firmware handle 205202036Simp * a2: firmware entry point 206202036Simp * a3: entry point seal 207178173Simp */ 208202036Simp if (a3 == CFE_EPTSEAL) 209202036Simp cfe_init(a0, a2); 210178173Simp#endif 211178173Simp cninit(); 212178173Simp 213178173Simp mips_init(); 214178173Simp 215178173Simp# if 0 216178173Simp /* 217178173Simp * Probe the Broadcom Sentry5's on-chip PLL clock registers 218178173Simp * and discover the CPU pipeline clock and bus clock 219178173Simp * multipliers from this. 220178173Simp * XXX: Wrong place. You have to ask the ChipCommon 221178173Simp * or External Interface cores on the SiBa. 222178173Simp */ 223178173Simp uint32_t busmult, cpumult, refclock, clkcfg1; 224178173Simp#define S5_CLKCFG1_REFCLOCK_MASK 0x0000001F 225178173Simp#define S5_CLKCFG1_BUSMULT_MASK 0x000003E0 226178173Simp#define S5_CLKCFG1_BUSMULT_SHIFT 5 227178173Simp#define S5_CLKCFG1_CPUMULT_MASK 0xFFFFFC00 228178173Simp#define S5_CLKCFG1_CPUMULT_SHIFT 10 229178173Simp 230178173Simp counter_freq = 100000000; /* XXX */ 231178173Simp 232178173Simp clkcfg1 = s5_rd_clkcfg1(); 233178173Simp printf("clkcfg1 = 0x%08x\n", clkcfg1); 234178173Simp 235178173Simp refclock = clkcfg1 & 0x1F; 236178173Simp busmult = ((clkcfg1 & 0x000003E0) >> 5) + 1; 237178173Simp cpumult = ((clkcfg1 & 0xFFFFFC00) >> 10) + 1; 238178173Simp 239178173Simp printf("refclock = %u\n", refclock); 240178173Simp printf("busmult = %u\n", busmult); 241178173Simp printf("cpumult = %u\n", cpumult); 242178173Simp 243178173Simp counter_freq = cpumult * refclock; 244178173Simp# else 245178173Simp platform_counter_freq = 200 * 1000 * 1000; /* Sentry5 is 200MHz */ 246178173Simp# endif 247178173Simp 248178173Simp mips_timer_init_params(platform_counter_freq, 0); 249178173Simp} 250