Bring forward from matt-nb5-mips64. Support for Ralink RT3883 MIPS 74K SoC

from CradlePoint Technology.
This commit is contained in:
matt 2011-07-28 15:50:13 +00:00
parent 0062f2f291
commit 9c6e0201a3
7 changed files with 935 additions and 0 deletions

View File

@ -0,0 +1,239 @@
include "arch/evbmips/conf/std.rasoc"
options SYMTAB_SPACE=450000 # size for embedded symbol table
options RT3883
options RTNORFLASH
options RTMEMSIZE=128
#options SLICKROCK
options RALINK_ETH_NUM_SW_PARTITIONS=5
options CONSPEED=57600
#options SYSCALL_DEBUG
maxusers 8
# Size reduction options
#options VNODE_OP_NOINLINE
#options PIPE_SOCKETPAIR # smaller, but slower pipe(2)
#options SOSEND_NO_LOAN
# Standard system options
options INSECURE # disable kernel security levels - X needs this
options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT
options NTP # NTP phase/frequency locked loop
#options KTRACE # system call tracing via ktrace(1)
#options SYSVMSG # System V-like message queues
#options SYSVSEM # System V-like semaphores
#options SYSVSHM # System V-like memory sharing
#options SHMMAXPGS=2048 # 2048 pages is the default
#options P1003_1B_SEMAPHORE # p1003.1b semaphore support
#options NMBCLUSTERS=1024
#options MCLSHIFT=12 # 4k mbuf clusters (increases pool max's to 4k as well)
#options USERCONF # userconf(4) support
#options SYSCTL_INCLUDE_DESCR # Include sysctl descriptions in kernel
# Diagnostic/debugging support options
options DIAGNOSTIC # expensive kernel consistency checks
#options LOCKDEBUG
#options KSTACK_CHECK_MAGIC
options DEBUG # expensive debugging checks/support
options KMEMSTATS # kernel memory statistics (vmstat -m)
options DDB # in-kernel debugger
options DDB_ONPANIC=1 # see also sysctl(8): `ddb.onpanic'
#options DDB_HISTORY_SIZE=512 # enable history editing in DDB
#options DDB_COMMANDONENTER="w/b 0x90000128 0 ; bt" # disable watchdog & drop history on enter
#options KGDB # remote debugger
#options KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x2f8,KGDB_DEVRATE=9600
#makeoptions DEBUG="-g2" # compile full symbol table
#makeoptions COPTS="-Os" # Optimise for space.
#makeoptions PROF="-p" # build profiling in
#options GPROF
# Compatibility options
#options COMPAT_NOMID # NetBSD 0.8, 386BSD, and BSDI
#options COMPAT_09 # NetBSD 0.9
#options COMPAT_10 # NetBSD 1.0
#options COMPAT_11 # NetBSD 1.1
#options COMPAT_12 # NetBSD 1.2, 386BSD, and BSDI
#options COMPAT_13 # NetBSD 1.3, 386BSD, and BSDI
#options COMPAT_14 # NetBSD 1.4
#options COMPAT_15 # NetBSD 1.5
#options COMPAT_16 # NetBSD 1.6
#options COMPAT_20 # NetBSD 2.0
#options COMPAT_30 # NetBSD 3.0 compatibility.
#options COMPAT_40 # NetBSD 4.0
options COMPAT_50 # NetBSD 5.0 compatibility.
#options COMPAT_43 # 4.3BSD, 386BSD, and BSDI
#options COMPAT_386BSD_MBRPART # recognize old partition ID
#options TCP_COMPAT_42 # 4.2BSD TCP/IP bug compat. Not recommended.
#options COMPAT_SVR4 # binary compatibility with SVR4
#options COMPAT_IBCS2 # binary compatibility with SCO and ISC
#options COMPAT_LINUX # binary compatibility with Linux
#options COMPAT_FREEBSD # binary compatibility with FreeBSD
#options COMPAT_BSDPTY # /dev/[pt]ty?? ptys.
# File systems
file-system FFS # UFS
#file-system EXT2FS # second extended file system (linux)
#file-system LFS # log-structured file system
file-system MFS # memory file system
file-system NFS # Network File System client
#file-system CD9660 # ISO 9660 + Rock Ridge file system
file-system MSDOSFS # MS-DOS file system
#file-system FDESC # /dev/fd
file-system KERNFS # /kern
#file-system NULLFS # loopback file system
#file-system PORTAL # portal filesystem (still experimental)
file-system PROCFS # /proc
#file-system UMAPFS # NULLFS + uid and gid remapping
#file-system UNION # union file system
#file-system SMBFS # experimental - CIFS; also needs nsmb (below)
#file-system PTYFS # /dev/pts/N support
file-system TMPFS # Efficient memory file-system
# File system options
#options QUOTA # UFS quotas
#options FFS_EI # FFS Endian Independant support
#options NFSSERVER # Network File System server
options FFS_NO_SNAPSHOT # No FF snapshot support
#options EXT2FS_SYSTEM_FLAGS # makes ext2fs file flags (append and immutable) behave as system flags.
# Networking options
options GATEWAY # packet forwarding
options INET # IP + ICMP + TCP + UDP
options MROUTING # IP multicast routing
#options INET6 # IPV6
#options IPSEC # IP security
#options IPSEC_ESP # IP security (encryption part; define w/IPSEC)
#options IPSEC_NAT_T # IPsec NAT traversal (NAT-T)
#options IPSEC_DEBUG # debug for IP security
#options PIM # Protocol Independent Multicast
#options ISO,TPIP # OSI
#options EON # OSI tunneling over IP
#options NETATALK # AppleTalk networking protocols
#options PPP_BSDCOMP # BSD-Compress compression support for PPP
#options PPP_DEFLATE # Deflate compression support for PPP
#options PPP_FILTER # Active filter support for PPP (requires bpf)
options PFIL_HOOKS # pfil(9) packet filter hooks
#options IPFILTER_LOG # ipmon(8) log support
#options IPFILTER_LOOKUP # ippool(8) support
#options IPFILTER_DEFAULT_BLOCK # block all packets by default
#options TCP_DEBUG # Record last TCP_NDEBUG packets with SO_DEBUG
#options ALTQ # Manipulate network interfaces' output queues
#options ALTQ_BLUE # Stochastic Fair Blue
#options ALTQ_CBQ # Class-Based Queueing
#options ALTQ_CDNR # Diffserv Traffic Conditioner
#options ALTQ_FIFOQ # First-In First-Out Queue
#options ALTQ_FLOWVALVE # RED/flow-valve (red-penalty-box)
#options ALTQ_HFSC # Hierarchical Fair Service Curve
#options ALTQ_LOCALQ # Local queueing discipline
#options ALTQ_PRIQ # Priority Queueing
#options ALTQ_RED # Random Early Detection
#options ALTQ_RIO # RED with IN/OUT
#options ALTQ_WFQ # Weighted Fair Queueing
# These options enable verbose messages for several subsystems.
# Warning, these may compile large string tables into the kernel!
#options EISAVERBOSE # verbose EISA device autoconfig messages
#options PCIVERBOSE # verbose PCI device autoconfig messages
#options PCI_CONFIG_DUMP # verbosely dump PCI config space
#options PCMCIAVERBOSE # verbose PCMCIA configuration messages
#options SCSIVERBOSE # human readable SCSI error messages
#options USBVERBOSE # verbose USB device autoconfig messages
# Options for necessary to use MD
#options MEMORY_DISK_HOOKS
#options MEMORY_DISK_IS_ROOT # force root on memory disk
#options MEMORY_DISK_SERVER=0 # no userspace memory disk support
#options MEMORY_DISK_ROOT_SIZE=8192 # embed the FS into the system for now
#options MEMORY_RBFLAGS=0 # keep the kernel from forcing single user mode
# Options for NFS root boot
options NFS_BOOT_DHCP,NFS_BOOT_BOOTPARAM,NFS_BOOT_STATIC
#options NFS_BOOTSTATIC_MYIP="\"192.168.0.1\""
#options NFS_BOOTSTATIC_GWIP="\"192.168.0.1\""
#options NFS_BOOTSTATIC_MASK="\"255.255.255.0\""
#options NFS_BOOTSTATIC_SERVADDR="\"192.168.0.5\""
#options NFS_BOOTSTATIC_SERVER="\"192.168.0.5:/home/andersen/nfs/mbr1400\""
# Need more mbufs for IPsec VPN
#options NMBCLUSTERS=4096
# rt3052 dev board root on embedded NFS mount disk
config netbsd root on ? type ?
config netbsd-sd0a root on sd0a type ffs dumps none
config netbsd-reth0 root on reth0 type nfs dumps none
mainbus0 at root
cpu0 at mainbus?
com0 at mainbus?
reth* at mainbus?
rwdog0 at mainbus?
options RA_WDOG_DEFAULT_PERIOD=-30
#options RA_WDOG_DEFAULT_MODE=WDOG_MODE_DISARMED
options RA_WDOG_DEFAULT_MODE=WDOG_MODE_KTICKLE
# USB support on rusb0
ehci* at mainbus?
usb* at ehci?
# USB support on rusb0
ohci* at mainbus?
usb* at ohci?
# GPIO support
rgpio0 at mainbus?
gpio* at rgpio?
# I2C support
ri2c0 at mainbus?
iic* at ri2c?
# USB Hubs
uhub* at usb?
uhub* at uhub? port ?
# USB Mass Storage
umass* at uhub? port ?
scsibus* at scsi?
sd* at scsibus? target ? lun ?
# USB Ethernet adapters
#aue* at uhub? port ? # ADMtek AN986 Pegasus based adapters
#axe* at uhub? port ? # ASIX AX88172 10/100 based adapters
# USB Generic driver
ugen* at uhub? port ?
# PHY Support
ukphy* at mii? phy ? # generic unknown PHYs
#arphy* at mii? phy ? # Atheros AR8316 switch
# Pseudo-Devices
# disk/mass storage pseudo-devices
# network pseudo-devices
pseudo-device bpfilter # Berkeley packet filter
pseudo-device bridge # simple inter-network bridging
pseudo-device loop # network loopback
pseudo-device tap # virtual Ethernet
pseudo-device pf # PF packet filter
pseudo-device pflog # PF log if
pseudo-device pppoe # PPPoE protocol
pseudo-device vlan # 802.1q
# miscellaneous pseudo-devices
pseudo-device pty # pseudo-terminals
pseudo-device rnd # /dev/random - in-kernel generator
pseudo-device clockctl # /dev/clockctl - user control of clock subsystem
pseudo-device ksyms # /dev/ksyms - kernel symbols

View File

@ -0,0 +1,24 @@
# $NetBSD: INSTALL_CPMBR1400,v 1.2 2011/07/28 15:50:13 matt Exp $
include "arch/evbmips/conf/CPMBR1400"
#ident "INSTALL_MALTA-$Revision: 1.2 $"
# Enable the hooks used for initializing the root memory-disk.
# The ramdisk size must be kept in sync manually with the size of
# the `ramdisk' image (which is built in distrib/evbmips/ramdisk/ramdisk).
pseudo-device md # memory disk device
options MEMORY_DISK_HOOKS
options MEMORY_DISK_IS_ROOT # force root on memory disk
options MEMORY_DISK_SERVER=0 # no userspace memory disk
options MEMORY_DISK_ROOT_SIZE=12288 # size of memory disk, in blocks
#options UVMHIST
#options UVMHIST_PRINT
makeoptions DEBUG="-g"
makeoptions NEED_MDSETIMAGE=yes
#makeoptions NEED_UBOOTIMAGE=yes
no config netbsd-sd0a
no config netbsd-reth0
no options VMSWAP

View File

@ -0,0 +1,55 @@
# $NetBSD: files.rasoc,v 1.2 2011/07/28 15:50:13 matt Exp $
file arch/mips/mips/bus_dma.c
file arch/mips/mips/mips3_clock.c
file arch/mips/mips/mips3_clockintr.c
#file arch/evbmips/evbmips/disksubr.c
file kern/subr_disk_mbr.c disk
file arch/evbmips/evbmips/interrupt.c
file arch/evbmips/rasoc/autoconf.c
file arch/evbmips/rasoc/machdep.c
file arch/evbmips/rasoc/console.c
# System bus
device mainbus { }
attach mainbus at root
file arch/mips/ralink/ralink_mainbus.c mainbus
device cpu
attach cpu at mainbus
file arch/evbmips/evbmips/cpu.c cpu
# Machine-independent I2O drivers.
include "dev/i2o/files.i2o"
# Machine-independent ATA drivers
include "dev/ata/files.ata"
# Machine-independent SCSI drivers
include "dev/scsipi/files.scsipi"
# Machine-independent ATA drivers
#include "dev/ata/files.ata"
# Machine-independent USB device support
include "dev/usb/files.usb"
# Memory Disk
file dev/md_root.c memory_disk_hooks
include "dev/pci/files.pci"
device pchb
attach pchb at pci
file arch/evbmips/rmixl/pci/pchb.c pchb
device pcib: isabus
attach pcib at pci
file arch/evbmips/rmixl/pci/pcib.c pcib
#
# Devices on the local I/O bus.
#
include "arch/mips/conf/files.ralink"

View File

@ -0,0 +1,20 @@
# $NetBSD: std.rasoc,v 1.2 2011/07/28 15:50:13 matt Exp $
machine evbmips mips
include "conf/std" # MI standard options
options MIPS3_ENABLE_CLOCK_INTR
#options MIPS32
options MIPS32R2 # MIPS32 Release 2
options NOFPU # No FPU
options FPEMUL # emulate FPU insn
options EXEC_ELF32 # exec ELF32 binaries
options EXEC_SCRIPT # exec #! scripts
makeoptions CPUFLAGS+="-march=mips32r2"
makeoptions DEFTEXTADDR="0x80010000"
makeoptions NEED_BINARY="yes"
makeoptions NEED_UBOOTIMAGE="yes"
include "arch/evbmips/conf/files.rasoc"

View File

@ -0,0 +1,68 @@
/* $NetBSD: autoconf.c,v 1.2 2011/07/28 15:50:13 matt Exp $ */
/*-
* Copyright (c) 2011 CradlePoint Technology, Inc.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY CRADLEPOINT TECHNOLOGY, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.2 2011/07/28 15:50:13 matt Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/systm.h>
/*
* Configure all devices on system
*/
void
cpu_configure(void)
{
intr_init();
/* Kick off autoconfiguration. */
if (config_rootfound("mainbus", NULL) == NULL)
panic("no mainbus found");
/*
* Hardware interrupts will be enabled in
* sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
* to avoid hardclock(9) by CPU INT5 before softclockintr is
* initialized in initclocks().
*/
}
void
cpu_rootconf(void)
{
setroot(booted_device, booted_partition);
}
void
device_register(struct device *dev, void *aux)
{
/* TBD */
}

View File

@ -0,0 +1,172 @@
/* $NetBSD: console.c,v 1.2 2011/07/28 15:50:13 matt Exp $ */
/*-
* Copyright (c) 2011 CradlePoint Technology, Inc.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY CRADLEPOINT TECHNOLOGY, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: console.c,v 1.2 2011/07/28 15:50:13 matt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <dev/cons.h>
#include <mips/ralink/ralink_reg.h>
#include <mips/ralink/ralink_var.h>
static inline uint32_t
sysctl_read(const u_int offset)
{
return *RA_IOREG_VADDR(RA_SYSCTL_BASE, offset);
}
static inline void
sysctl_write(const u_int offset, uint32_t val)
{
*RA_IOREG_VADDR(RA_SYSCTL_BASE, offset) = val;
}
static inline uint32_t
uart_read(const u_int offset)
{
return *RA_IOREG_VADDR(RA_UART_LITE_BASE, offset);
}
static inline void
uart_write(const u_int offset, const uint32_t val)
{
*RA_IOREG_VADDR(RA_UART_LITE_BASE, offset) = val;
}
#ifdef RA_CONSOLE_EARLY
static void
ra_console_putc(dev_t dev, int c)
{
u_int timo;
timo = 150000;
do {
if ((uart_read(RA_UART_LSR) & UART_LSR_TDRQ) != 0)
break;
} while(--timo != 0);
uart_write(RA_UART_TBR, c);
if (c == '\n')
ra_console_putc (dev, '\r');
#if 1
timo = 150000;
do {
if ((uart_read(RA_UART_LSR) & UART_LSR_TEMT) != 0)
break;
} while(--timo != 0);
#endif
}
static int
ra_console_getc(dev_t dev)
{
while ((uart_read(RA_UART_LSR) & UART_LSR_DR) == 0)
;
return (char)(uart_read(RA_UART_RBR) & 0xff);
}
static void
ra_console_flush(dev_t dev)
{
while ((uart_read(RA_UART_LSR) & UART_LSR_TEMT) == 0)
;
}
void
ra_console_early(void)
{
uint32_t r;
/* reset */
r = sysctl_read(RA_SYSCTL_RST);
r |= RST_UARTL;
sysctl_write(RA_SYSCTL_RST, r);
r ^= RST_UARTL;
sysctl_write(RA_SYSCTL_RST, r);
/* make sure we are in UART mode */
r = sysctl_read(RA_SYSCTL_GPIOMODE);
r &= ~GPIOMODE_UARTL;
sysctl_write(RA_SYSCTL_GPIOMODE, r);
uart_write(RA_UART_IER, 0); /* disable interrupts */
uart_write(RA_UART_FCR, 0); /* disable fifos */
/* set baud rate */
uart_write(RA_UART_LCR,
UART_LCR_WLS0 | UART_LCR_WLS1 | UART_LCR_DLAB);
uart_write(RA_UART_DLL,
(RA_UART_FREQ / RA_SERIAL_CLKDIV / RA_BAUDRATE)
& 0xffff);
uart_write(RA_UART_LCR,
UART_LCR_WLS0 | UART_LCR_WLS1);
static struct consdev lite_cn = {
.cn_probe = NULL,
.cn_init = NULL,
.cn_getc = ra_console_getc,
.cn_putc = ra_console_putc,
.cn_pollc = nullcnpollc,
.cn_bell = NULL,
.cn_halt = NULL,
.cn_flush = ra_console_flush,
.cn_dev = makedev(0, 0),
.cn_pri = CN_DEAD,
};
cn_tab = &lite_cn;
}
#endif /* RA_CONSOLE_EARLY */
void
consinit(void)
{
if (ra_check_memo_reg(SERIAL_CONSOLE)) {
ralink_com_early(0);
printf("Enabled early console\n");
} else {
/*
* this should be OK, but our shell configuration doesn't seem
* to be working, so create a silent console
*/
cn_tab = NULL;
ralink_com_early(1);
printf("Enabled silent console\n");
}
#if 0
/* update ddb escape sequence to '~~' to avoid the undocking issue */
cn_set_magic("\x7E\x7E");
#endif
}

View File

@ -0,0 +1,357 @@
/* $NetBSD: machdep.c,v 1.2 2011/07/28 15:50:13 matt Exp $ */
/*-
* Copyright (c) 2011 CradlePoint Technology, Inc.
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY CRADLEPOINT TECHNOLOGY, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.2 2011/07/28 15:50:13 matt Exp $");
#include <sys/param.h>
#include <sys/boot_flag.h>
#include <sys/buf.h>
#include <sys/device.h>
#include <sys/mount.h>
#include <sys/kcore.h>
#include <sys/reboot.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/termios.h>
#include <uvm/uvm_extern.h>
#include <dev/cons.h>
#include <mips/cache.h>
#include <mips/locore.h>
#include <mips/cpuregs.h>
#include <mips/ralink/ralink_reg.h>
#include <mips/ralink/ralink_var.h>
/* structures we define/alloc for other files in the kernel */
struct vm_map *mb_map = NULL;
struct vm_map *phys_map = NULL;
struct cpu_info cpu_info_store;
int physmem; /* # pages of physical memory */
int mem_cluster_cnt = 0;
phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
/* structures others define for us */
extern struct user *proc0paddr;
void mach_init(void);
static inline uint32_t
sysctl_read(u_int offset)
{
return *RA_IOREG_VADDR(RA_SYSCTL_BASE, offset);
}
static inline void
sysctl_write(u_int offset, uint32_t val)
{
*RA_IOREG_VADDR(RA_SYSCTL_BASE, offset) = val;
}
static void
cal_timer(void)
{
uint32_t cntfreq;
cntfreq = curcpu()->ci_cpu_freq = RA_CLOCK_RATE;
/* MIPS 4Kc CP0 counts every other clock */
if (mips_options.mips_cpu_flags & CPU_MIPS_DOUBLE_COUNT)
cntfreq /= 2;
curcpu()->ci_cycles_per_hz = (cntfreq + hz / 2) / hz;
/* Compute number of cycles per 1us (1/MHz). 0.5MHz is for roundup. */
curcpu()->ci_divisor_delay = ((cntfreq + 500000) / 1000000);
}
void
mach_init(void)
{
vaddr_t kernend;
psize_t memsize;
extern char kernel_text[];
extern char edata[], end[]; /* From Linker */
/* clear the BSS segment */
kernend = mips_round_page(end);
memset(edata, 0, kernend - (vaddr_t)edata);
#ifdef RA_CONSOLE_EARLY
/*
* set up early console
* cannot printf until sometime (?) in mips_vector_init
* meanwhile can use the ra_console_putc primitive if necessary
*/
ra_console_early();
#endif
/* set CPU model info for sysctl_hw */
uint32_t tmp;
tmp = sysctl_read(RA_SYSCTL_ID0);
memcpy(&cpu_model[0], &tmp, 4);
tmp = sysctl_read(RA_SYSCTL_ID1);
memcpy(&cpu_model[4], &tmp, 4);
cpu_model[9] = 0;
/*
* Set up the exception vectors and CPU-specific function
* vectors early on. We need the wbflush() vector set up
* before comcnattach() is called (or at least before the
* first printf() after that is called).
* Sets up mips_cpu_flags that may be queried by other
* functions called during startup.
* Also clears the I+D caches.
*/
mips_vector_init(NULL, false);
/*
* Calibrate timers.
*/
cal_timer();
/*
* Set the VM page size.
*/
uvm_setpagesize();
/*
* Look at arguments passed to us and compute boothowto.
*/
boothowto = RB_AUTOBOOT;
#ifdef KADB
boothowto |= RB_KDB;
#endif
/*
* Determine the memory size.
*
* Note: Reserve the first page! That's where the trap
* vectors are located.
*/
memsize = RTMEMSIZE * 1024 * 1024;
physmem = btoc(memsize);
mem_clusters[mem_cluster_cnt].start = PAGE_SIZE;
mem_clusters[mem_cluster_cnt].size =
memsize - mem_clusters[mem_cluster_cnt].start;
mem_cluster_cnt++;
/*
* Load the memory into the VM system
*/
mips_page_physload((vaddr_t)kernel_text, kernend,
mem_clusters, mem_cluster_cnt,
NULL, 0);
/*
* Initialize message buffer (at end of core).
*/
mips_init_msgbuf();
/*
* Initialize the virtual memory system.
*/
pmap_bootstrap();
/*
* Init mapping for u page(s) for proc0.
*/
mips_init_lwp0_uarea();
/*
* Initialize busses.
*/
ra_bus_init();
#ifdef DDB
if (boothowto & RB_KDB)
Debugger();
#endif
}
void
cpu_startup(void)
{
char pbuf[9];
vaddr_t minaddr, maxaddr;
#ifdef DEBUG
extern int pmapdebug; /* XXX */
int opmapdebug = pmapdebug;
pmapdebug = 0; /* Shut up pmap debug during bootstrap */
#endif
/*
* Good {morning,afternoon,evening,night}.
*/
printf("%s%s", copyright, version);
printf("Boot processor: %s\n", cpu_model);
format_bytes(pbuf, sizeof(pbuf), RTMEMSIZE * 1024 * 1024);
printf("total memory = %s\n", pbuf);
/*
* Allocate a submap for physio
*/
minaddr = 0;
phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
VM_PHYS_SIZE, 0, FALSE, NULL);
/*
* No need to allocate an mbuf cluster submap. Mbuf clusters
* are allocated via the pool allocator, and we use KSEG to
* map those pages.
*/
#ifdef DEBUG
pmapdebug = opmapdebug;
#endif
format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
printf("avail memory = %s\n", pbuf);
}
void
cpu_reboot(int howto, char *bootstr)
{
static int waittime = -1;
/* Take a snapshot before clobbering any registers. */
savectx(lwp_getpcb(curlwp));
/* If "always halt" was specified as a boot flag, obey. */
if (boothowto & RB_HALT)
howto |= RB_HALT;
boothowto = howto;
/* If system is cold, just halt. */
if (cold) {
boothowto |= RB_HALT;
goto haltsys;
}
if ((boothowto & RB_NOSYNC) == 0 && waittime < 0) {
waittime = 0;
/*
* Synchronize the disks....
*/
vfs_shutdown();
/*
* If we've been adjusting the clock, the todr
* will be out of synch; adjust it now.
*/
resettodr();
}
/* Disable interrupts. */
splhigh();
if (boothowto & RB_DUMP)
dumpsys();
haltsys:
/* Run any shutdown hooks. */
doshutdownhooks();
pmf_system_shutdown(boothowto);
/*
* Firmware may autoboot (depending on settings), and we cannot pass
* flags to it (at least I haven't figured out how to yet), so
* we "pseudo-halt" now.
*/
if (boothowto & RB_HALT) {
printf("\n");
printf("The operating system has halted.\n");
printf("Please press any key to reboot.\n\n");
cnpollc(1); /* For proper keyboard command handling */
cngetc();
cnpollc(0);
}
printf("reseting board...\n\n");
mips_icache_sync_all();
mips_dcache_wbinv_all();
sysctl_write(RA_SYSCTL_RST, 1); /* SoC Reset */
sysctl_write(RA_SYSCTL_RST, 0);
#if 0
__asm volatile("jr %0" :: "r"(MIPS_RESET_EXC_VEC));
#endif
printf("Oops, back from reset\n\nSpinning...");
for (;;)
/* spin forever */ ; /* XXX */
/*NOTREACHED*/
}
#define NO_SECURITY_MAGIC 0x27051958
#define SERIAL_MAGIC 0x100000
int
ra_check_memo_reg(int key)
{
uint32_t magic;
/*
* These registers may be overwritten. Keep the value around in case
* it is used later. Bitmask 1 == security, 2 = serial
*/
static int keyvalue;
switch (key) {
case NO_SECURITY:
magic = sysctl_read(RA_SYSCTL_MEMO0);
if ((NO_SECURITY_MAGIC == magic) || ((keyvalue & 1) != 0)) {
keyvalue |= 1;
return 1;
}
return 0;
break;
case SERIAL_CONSOLE:
magic = sysctl_read(RA_SYSCTL_MEMO1);
if (((SERIAL_MAGIC & magic) != 0) || ((keyvalue & 2) != 0)) {
keyvalue |= 2;
return 1;
}
return 0;
break;
default:
return 0;
}
}