malta_machdep.c revision 182901
1178173Simp/*- 2178173Simp * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org> 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 * $FreeBSD: head/sys/mips/malta/malta_machdep.c 182901 2008-09-10 03:49:08Z gonzo $ 27178173Simp */ 28178173Simp#include <sys/cdefs.h> 29178173Simp__FBSDID("$FreeBSD: head/sys/mips/malta/malta_machdep.c 182901 2008-09-10 03:49:08Z gonzo $"); 30178173Simp 31178173Simp#include "opt_ddb.h" 32178173Simp 33178173Simp#include <sys/param.h> 34178173Simp#include <sys/conf.h> 35178173Simp#include <sys/kernel.h> 36178173Simp#include <sys/systm.h> 37178173Simp#include <sys/imgact.h> 38178173Simp#include <sys/bio.h> 39178173Simp#include <sys/buf.h> 40178173Simp#include <sys/bus.h> 41178173Simp#include <sys/cpu.h> 42178173Simp#include <sys/cons.h> 43178173Simp#include <sys/exec.h> 44178173Simp#include <sys/ucontext.h> 45178173Simp#include <sys/proc.h> 46178173Simp#include <sys/kdb.h> 47178173Simp#include <sys/ptrace.h> 48178173Simp#include <sys/reboot.h> 49178173Simp#include <sys/signalvar.h> 50178173Simp#include <sys/sysent.h> 51178173Simp#include <sys/sysproto.h> 52178173Simp#include <sys/user.h> 53178173Simp 54178173Simp#include <vm/vm.h> 55178173Simp#include <vm/vm_object.h> 56178173Simp#include <vm/vm_page.h> 57178173Simp#include <vm/vm_pager.h> 58178173Simp 59178173Simp#include <machine/clock.h> 60178173Simp#include <machine/cpu.h> 61178173Simp#include <machine/cpuregs.h> 62178173Simp#include <machine/hwfunc.h> 63178173Simp#include <machine/md_var.h> 64178173Simp#include <machine/pmap.h> 65178173Simp#include <machine/trap.h> 66178173Simp 67178173Simp#ifdef TICK_USE_YAMON_FREQ 68182901Sgonzo#include <mips/malta/yamon.h> 69178173Simp#endif 70178173Simp 71178173Simp#ifdef TICK_USE_MALTA_RTC 72178173Simp#include <mips/mips4k/malta/maltareg.h> 73178173Simp#include <dev/mc146818/mc146818reg.h> 74178173Simp#include <isa/rtc.h> 75178173Simp#endif 76178173Simp 77182901Sgonzo#include <mips/malta/maltareg.h> 78178173Simp 79178173Simpextern int *edata; 80178173Simpextern int *end; 81178173Simp 82178173Simpvoid lcd_init(void); 83178173Simpvoid lcd_puts(char *); 84178173Simpvoid malta_reset(void); 85178173Simp 86178173Simp/* 87178173Simp * Offsets to MALTA LCD characters. 88178173Simp */ 89178173Simpstatic int malta_lcd_offs[] = { 90178173Simp MALTA_ASCIIPOS0, 91178173Simp MALTA_ASCIIPOS1, 92178173Simp MALTA_ASCIIPOS2, 93178173Simp MALTA_ASCIIPOS3, 94178173Simp MALTA_ASCIIPOS4, 95178173Simp MALTA_ASCIIPOS5, 96178173Simp MALTA_ASCIIPOS6, 97178173Simp MALTA_ASCIIPOS7 98178173Simp}; 99178173Simp 100178173Simp/* 101178173Simp * Put character to Malta LCD at given position. 102178173Simp */ 103178173Simpstatic void 104178173Simpmalta_lcd_putc(int pos, char c) 105178173Simp{ 106178173Simp void *addr; 107178173Simp char *ch; 108178173Simp 109178173Simp if (pos < 0 || pos > 7) 110178173Simp return; 111178173Simp addr = (void *)(MALTA_ASCII_BASE + malta_lcd_offs[pos]); 112178173Simp ch = (char *)MIPS_PHYS_TO_KSEG0(addr); 113178173Simp *ch = c; 114178173Simp} 115178173Simp 116178173Simp/* 117178173Simp * Print given string on LCD. 118178173Simp */ 119178173Simpstatic void 120178173Simpmalta_lcd_print(char *str) 121178173Simp{ 122178173Simp int i; 123178173Simp 124178173Simp if (str == NULL) 125178173Simp return; 126178173Simp 127178173Simp for (i = 0; *str != '\0'; i++, str++) 128178173Simp malta_lcd_putc(i, *str); 129178173Simp} 130178173Simp 131178173Simpvoid 132178173Simplcd_init(void) 133178173Simp{ 134178173Simp malta_lcd_print("FreeBSD_"); 135178173Simp} 136178173Simp 137178173Simpvoid 138178173Simplcd_puts(char *s) 139178173Simp{ 140178173Simp malta_lcd_print(s); 141178173Simp} 142178173Simp 143178173Simp#ifdef TICK_USE_MALTA_RTC 144178173Simpstatic __inline uint8_t 145178173Simprtcin(uint8_t addr) 146178173Simp{ 147178173Simp 148178173Simp *((volatile uint8_t *) 149178173Simp MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr; 150178173Simp return (*((volatile uint8_t *) 151178173Simp MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT)))); 152178173Simp} 153178173Simp 154178173Simpstatic __inline void 155178173Simpwritertc(uint8_t addr, uint8_t val) 156178173Simp{ 157178173Simp 158178173Simp *((volatile uint8_t *) 159178173Simp MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr; 160178173Simp *((volatile uint8_t *) 161178173Simp MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))) = val; 162178173Simp} 163178173Simp#endif 164178173Simp 165178173Simpstatic void 166178173Simpmips_init(void) 167178173Simp{ 168178173Simp int i; 169178173Simp 170178173Simp for (i = 0; i < 10; i++) { 171178173Simp phys_avail[i] = 0; 172178173Simp } 173178173Simp 174178173Simp /* phys_avail regions are in bytes */ 175178173Simp phys_avail[0] = MIPS_KSEG0_TO_PHYS((vm_offset_t)&end); 176178173Simp phys_avail[1] = ctob(realmem); 177178173Simp 178178173Simp physmem = realmem; 179178173Simp 180178173Simp init_param1(); 181178173Simp init_param2(physmem); 182178173Simp mips_cpu_init(); 183178173Simp pmap_bootstrap(); 184178173Simp mips_proc0_init(); 185178173Simp mutex_init(); 186178173Simp#ifdef DDB 187178173Simp kdb_init(); 188178173Simp#endif 189178173Simp} 190178173Simp 191178173Simpvoid 192178173Simpplatform_halt(void) 193178173Simp{ 194178173Simp 195178173Simp} 196178173Simp 197178173Simp 198178173Simpvoid 199178173Simpplatform_identify(void) 200178173Simp{ 201178173Simp 202178173Simp} 203178173Simp 204178173Simp/* 205178173Simp * Perform a board-level soft-reset. 206178173Simp * Note that this is not emulated by gxemul. 207178173Simp */ 208178173Simpvoid 209178173Simpplatform_reset(void) 210178173Simp{ 211178173Simp char *c; 212178173Simp 213178173Simp c = (char *)MIPS_PHYS_TO_KSEG0(MALTA_SOFTRES); 214178173Simp *c = MALTA_GORESET; 215178173Simp} 216178173Simp 217178173Simpvoid 218178173Simpplatform_trap_enter(void) 219178173Simp{ 220178173Simp 221178173Simp} 222178173Simp 223178173Simpvoid 224178173Simpplatform_trap_exit(void) 225178173Simp{ 226178173Simp 227178173Simp} 228178173Simp 229178173Simpvoid 230178173Simpplatform_start(__register_t a0, __register_t a1, __register_t a2, 231178173Simp __register_t a3) 232178173Simp{ 233178173Simp vm_offset_t kernend; 234178173Simp uint64_t platform_counter_freq; 235178173Simp int argc = a0; 236178173Simp char **argv = (char **)a1; 237178173Simp char **envp = (char **)a2; 238178173Simp unsigned int memsize = a3; 239178173Simp int i; 240178173Simp 241178173Simp /* clear the BSS and SBSS segments */ 242178173Simp kernend = round_page((vm_offset_t)&end); 243178173Simp memset(&edata, 0, kernend - (vm_offset_t)(&edata)); 244178173Simp 245178173Simp cninit(); 246178173Simp printf("entry: platform_start()\n"); 247178173Simp 248178173Simp bootverbose = 1; 249178173Simp if (bootverbose) { 250178173Simp printf("cmd line: "); 251178173Simp for (i = 0; i < argc; i++) 252178173Simp printf("%s ", argv[i]); 253178173Simp printf("\n"); 254178173Simp 255178173Simp printf("envp:\n"); 256178173Simp for (i = 0; envp[i]; i += 2) 257178173Simp printf("\t%s = %s\n", envp[i], envp[i+1]); 258178173Simp 259178173Simp printf("memsize = %08x\n", memsize); 260178173Simp } 261178173Simp 262178173Simp realmem = btoc(memsize); 263178173Simp mips_init(); 264178173Simp 265178173Simp do { 266178173Simp#if defined(TICK_USE_YAMON_FREQ) 267178173Simp /* 268178173Simp * If we are running on a board which uses YAMON firmware, 269178173Simp * then query CPU pipeline clock from the syscon object. 270178173Simp * If unsuccessful, use hard-coded default. 271178173Simp */ 272178173Simp platform_counter_freq = yamon_getcpufreq(); 273178173Simp if (platform_counter_freq == 0) 274178173Simp platform_counter_freq = MIPS_DEFAULT_HZ; 275178173Simp 276178173Simp#elif defined(TICK_USE_MALTA_RTC) 277178173Simp /* 278178173Simp * If we are running on a board with the MC146818 RTC, 279178173Simp * use it to determine CPU pipeline clock frequency. 280178173Simp */ 281178173Simp u_int64_t counterval[2]; 282178173Simp 283178173Simp /* Set RTC to binary mode. */ 284178173Simp writertc(RTC_STATUSB, (rtcin(RTC_STATUSB) | RTCSB_BCD)); 285178173Simp 286178173Simp /* Busy-wait for falling edge of RTC update. */ 287178173Simp while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0)) 288178173Simp ; 289178173Simp while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0)) 290178173Simp ; 291178173Simp counterval[0] = mips_rd_count(); 292178173Simp 293178173Simp /* Busy-wait for falling edge of RTC update. */ 294178173Simp while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0)) 295178173Simp ; 296178173Simp while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0)) 297178173Simp ; 298178173Simp counterval[1] = mips_rd_count(); 299178173Simp 300178173Simp platform_counter_freq = counterval[1] - counterval[0]; 301178173Simp#endif 302178173Simp } while(0); 303178173Simp 304178173Simp mips_timer_init_params(platform_counter_freq, 0); 305178173Simp} 306