Module Name: src Committed By: jmcneill Date: Fri Jun 2 15:22:47 UTC 2017
Modified Files: src/sys/arch/evbarm/conf: VEXPRESS_A15 files.vexpress mk.vexpress std.vexpress src/sys/arch/evbarm/vexpress: vexpress_start.S Added Files: src/sys/arch/arm/vexpress: files.vexpress vexpress_platform.c Removed Files: src/sys/arch/evbarm/vexpress: if_smsh_axi.c platform.h vexpress_axi.c vexpress_intr.h vexpress_machdep.c vexpress_plcom.c vexpress_plmmc.c vexpress_space.c vexpress_var.h Log Message: Switch VEXPRESS_A15 kernel to use FDT and GENERIC.common. The dtb for this kernel can be found in the sysutils/dtb-arm-vexpress package as vexpress-v2p-ca15-tc1.dtb To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/vexpress/files.vexpress \ src/sys/arch/arm/vexpress/vexpress_platform.c cvs rdiff -u -r1.7 -r1.8 src/sys/arch/evbarm/conf/VEXPRESS_A15 cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/conf/files.vexpress cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbarm/conf/mk.vexpress cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbarm/conf/std.vexpress cvs rdiff -u -r1.3 -r0 src/sys/arch/evbarm/vexpress/if_smsh_axi.c \ src/sys/arch/evbarm/vexpress/vexpress_machdep.c cvs rdiff -u -r1.2 -r0 src/sys/arch/evbarm/vexpress/platform.h \ src/sys/arch/evbarm/vexpress/vexpress_axi.c \ src/sys/arch/evbarm/vexpress/vexpress_intr.h \ src/sys/arch/evbarm/vexpress/vexpress_plcom.c \ src/sys/arch/evbarm/vexpress/vexpress_plmmc.c \ src/sys/arch/evbarm/vexpress/vexpress_space.c \ src/sys/arch/evbarm/vexpress/vexpress_var.h cvs rdiff -u -r1.2 -r1.3 src/sys/arch/evbarm/vexpress/vexpress_start.S Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/evbarm/conf/VEXPRESS_A15 diff -u src/sys/arch/evbarm/conf/VEXPRESS_A15:1.7 src/sys/arch/evbarm/conf/VEXPRESS_A15:1.8 --- src/sys/arch/evbarm/conf/VEXPRESS_A15:1.7 Sun Feb 19 07:47:00 2017 +++ src/sys/arch/evbarm/conf/VEXPRESS_A15 Fri Jun 2 15:22:47 2017 @@ -1,215 +1,65 @@ # -# $NetBSD: VEXPRESS_A15,v 1.7 2017/02/19 07:47:00 rin Exp $ +# $NetBSD: VEXPRESS_A15,v 1.8 2017/06/02 15:22:47 jmcneill Exp $ # -# VEXPRESS_A15 -- Versatile Express A15 kernel +# ARM Versatile Express A15 # include "arch/evbarm/conf/std.vexpress" +include "arch/evbarm/conf/GENERIC.common" -# estimated number of users - -maxusers 32 - -# Standard system options - -options RTC_OFFSET=0 # hardware clock is this many mins. west of GMT -#options NTP # NTP phase/frequency locked loop - -# CPU options -options CPU_CORTEX options CPU_CORTEXA15 +options SOC_TEGRA124 #options MULTIPROCESSOR -options PMAPCOUNTERS -options BUSDMA_COUNTERS -#options UVMHIST -#options USB_DEBUG -#options USBHIST_SIZE=100000 -#options UVMHIST_PRINT,KERNHIST_DELAY=0 -options __HAVE_MM_MD_DIRECT_MAPPED_PHYS -options PMAP_NEED_ALLOC_POOLPAGE - -# Specify the memory size in megabytes (optional). -#options MEMSIZE=512 - -# File systems -file-system FFS # UFS -#file-system LFS # log-structured file system -file-system MFS # memory file system -file-system NFS # Network file system -#file-system ADOSFS # AmigaDOS-compatible file system -#file-system EXT2FS # second extended file system (linux) -#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 PROCFS # /proc -#file-system PUFFS # Userspace file systems (e.g. ntfs-3g & sshfs) -#file-system UMAPFS # NULLFS + uid and gid remapping -#file-system UNION # union file system -file-system TMPFS # memory file system -file-system PTYFS # /dev/pts/N support - -# File system options -#options QUOTA # legacy UFS quotas -#options QUOTA2 # new, in-filesystem UFS quotas -#options DISKLABEL_EI # disklabel Endian Independent support -#options FFS_EI # FFS Endian Independent support -#options NFSSERVER -options WAPBL # File system journaling support -#options FFS_NO_SNAPSHOT # No FFS snapshot support - -# Networking options - -#options GATEWAY # packet forwarding -options INET # IP + ICMP + TCP + UDP -options INET6 # IPV6 -#options IPSEC # IP security -#options IPSEC_DEBUG # debug for IP security -#options MROUTING # IP multicast routing -#options PIM # Protocol Independent Multicast -#options NETATALK # AppleTalk networking -#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 TCP_DEBUG # Record last TCP_NDEBUG packets with SO_DEBUG - -options NFS_BOOT_BOOTP -options NFS_BOOT_DHCP -#options NFS_BOOT_BOOTSTATIC -#options NFS_BOOTSTATIC_MYIP="\"192.168.1.4\"" -#options NFS_BOOTSTATIC_GWIP="\"192.168.1.1\"" -#options NFS_BOOTSTATIC_MASK="\"255.255.255.0\"" -#options NFS_BOOTSTATIC_SERVADDR="\"192.168.1.1\"" -#options NFS_BOOTSTATIC_SERVER="\"192.168.1.1:/nfs/sdp2430\"" - -options NFS_BOOT_RWSIZE=1024 - -# Compatibility options - -options COMPAT_NETBSD32 # allow running arm (e.g. non-earm) binaries -#options COMPAT_43 # 4.3BSD compatibility. -#options COMPAT_09 # NetBSD 0.9, -#options COMPAT_10 # NetBSD 1.0, -#options COMPAT_11 # NetBSD 1.1, -#options COMPAT_12 # NetBSD 1.2, -#options COMPAT_13 # NetBSD 1.3, -#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, -options COMPAT_40 # NetBSD 4.0, -options COMPAT_50 # NetBSD 5.0, -options COMPAT_60 # NetBSD 6.0, and -options COMPAT_70 # NetBSD 7.0 binary compatibility. -#options TCP_COMPAT_42 # 4.2BSD TCP/IP bug compat. Not recommended. -#options COMPAT_BSDPTY # /dev/[pt]ty?? ptys. - -# Shared memory options - -options SYSVMSG # System V-like message queues -options SYSVSEM # System V-like semaphores -options SYSVSHM # System V-like memory sharing - -# Device options - -#options MEMORY_DISK_HOOKS # boottime setup of ramdisk -#options MEMORY_DISK_ROOT_SIZE=8192 # Size in blocks -#options MEMORY_DISK_DYNAMIC -#options MINIROOTSIZE=1000 # Size in blocks -#options MEMORY_DISK_IS_ROOT # use memory disk as root - -# Wedge support -options DKWEDGE_AUTODISCOVER # Automatically add dk(4) instances -options DKWEDGE_METHOD_GPT # Supports GPT partitions as wedges - -# Miscellaneous kernel options -options KTRACE # system call tracing, a la ktrace(1) -#options SCSIVERBOSE # Verbose SCSI errors -options MIIVERBOSE # Verbose MII autoconfuration messages -#options DDB_KEYCODE=0x40 -#options USERCONF # userconf(4) support -#options PIPE_SOCKETPAIR # smaller, but slower pipe(2) - -# Development and Debugging options - -#options PERFCTRS # performance counters -options DIAGNOSTIC # internal consistency checks -options DEBUG -options LOCKDEBUG +pseudo-device openfirm # /dev/openfirm + +#options DIAGNOSTIC # internal consistency checks +#options DEBUG +#options LOCKDEBUG #options PMAP_DEBUG # Enable pmap_debug_level code #options IPKDB # remote kernel debugging -options VERBOSE_INIT_ARM # verbose bootstraping messages -options DDB # in-kernel debugger -options DDB_ONPANIC=1 -options DDB_HISTORY_SIZE=100 # Enable history editing in DDB -#options KGDB +#options VERBOSE_INIT_ARM # verbose bootstrapping messages + makeoptions DEBUG="-g" # compile full symbol table makeoptions COPY_SYMTAB=1 -options PLCONSOLE - -# Valid options for BOOT_ARGS: -# single Boot to single user only -# kdb Give control to kernel debugger -# ask Ask for file name to reboot from -# memorydisk=<n> Set memorydisk size to <n> KB -# quiet Show aprint_naive output -# verbose Show aprint_normal and aprint_verbose output -#options BOOT_ARGS="\"\"" -options BOOT_ARGS="\"verbose\"" config netbsd root on ? type ? -# The main bus device -mainbus0 at root +# Device tree support +armfdt0 at root +fdt* at fdtbus? + +# CPUs +cpus* at fdt? pass 0 +cpu* at cpus? + +fclock* at fdt? pass 4 +fregulator* at fdt? pass 4 +gpiokeys* at fdt? + +# Timer +gtmr* at fdt? pass 1 # ARM Generic Timer +armgtmr0 at gtmr? + +# Interrupt controller +gic* at fdt? pass 1 # GIC +armgic0 at gic? + + +# Ethernet +smsh* at fdt? # SMSC LAN9118 +ukphy* at mii? phy ? + +# UART +plcom* at fdt? # ARM PL011 UART + +# SDMMC +plmmc* at fdt? # ARM PrimeCell MCI +sdmmc* at sdmmcbus? +ld0 at sdmmc0 +ld1 at sdmmc1 +ld2 at sdmmc2 +ld3 at sdmmc3 +ld* at sdmmc? -# The boot cpu and secondary CPUs -cpu0 at mainbus? -#cpu? at mainbus? # Multiprocessor - -# A9 core devices -armperiph0 at mainbus? -armgic0 at armperiph? # Interrupt Controller -armgtmr0 at armperiph? # Generic Timer - -# VEXPRESS AXI0 -axi0 at mainbus? - -# PL011 uart -plcom0 at axi? addr 0x1c090000 irq 37 - -# PL181 MMCI host controller -plmmc0 at axi? addr 0x1c050000 irq 41 -sdmmc* at plmmc0 -ld* at sdmmc? -#options SDMMC_DEBUG -#options SDMMCCISDEBUG - -# LAN 9118 -smsh0 at axi? addr 0x1a000000 irq 47 - -# MII/PHY support -ukphy* at mii? phy ? # smsh(4) internal PHY - -# Pseudo-Devices - -# disk/mass storage pseudo-devices -#pseudo-device md # memory disk device (ramdisk) -#pseudo-device vnd # disk-like interface to files -#pseudo-device fss # file system snapshot device -#pseudo-device putter # for puffs and pud -pseudo-device drvctl # driver control - -# network pseudo-devices -pseudo-device bpfilter # Berkeley packet filter -pseudo-device loop # network loopback -#pseudo-device kttcp # network loopback - -# miscellaneous pseudo-devices -pseudo-device pty # pseudo-terminals -#options RND_COM -#pseudo-device clockctl # user control of clock subsystem -pseudo-device ksyms # /dev/ksyms -#pseudo-device lockstat # lock profiling +cinclude "arch/evbarm/conf/VEXPRESS_A15.local" Index: src/sys/arch/evbarm/conf/files.vexpress diff -u src/sys/arch/evbarm/conf/files.vexpress:1.2 src/sys/arch/evbarm/conf/files.vexpress:1.3 --- src/sys/arch/evbarm/conf/files.vexpress:1.2 Wed Feb 11 07:51:10 2015 +++ src/sys/arch/evbarm/conf/files.vexpress Fri Jun 2 15:22:47 2017 @@ -1,34 +1,8 @@ -# $NetBSD: files.vexpress,v 1.2 2015/02/11 07:51:10 ozaki-r Exp $ +# $NetBSD: files.vexpress,v 1.3 2017/06/02 15:22:47 jmcneill Exp $ # # Versatile Express board configuration info # -file arch/evbarm/vexpress/vexpress_machdep.c - -include "arch/arm/pic/files.pic" -include "arch/arm/cortex/files.cortex" - -file arch/arm/arm32/arm32_boot.c -file arch/arm/arm32/arm32_kvminit.c -file arch/arm/arm32/arm32_reboot.c -file arch/arm/arm32/irq_dispatch.S - -file arch/evbarm/vexpress/vexpress_space.c - -# VEXPRESS AXI/AHB bus interface and SoC domains -device axi { [addr=-1], [size=0], [irq=-1], [irqbase=-1]} : bus_space_generic -attach axi at mainbus -file arch/evbarm/vexpress/vexpress_axi.c axi - -# UART Interface -attach plcom at axi with vexpressplcom -file arch/evbarm/vexpress/vexpress_plcom.c vexpressplcom - -# MMCI host controller -attach plmmc at axi with vexpressplmmc -file arch/evbarm/vexpress/vexpress_plmmc.c vexpressplmmc - -# SMSC LAN9118 -attach smsh at axi with smsh_axi -file arch/evbarm/vexpress/if_smsh_axi.c smsh_axi +include "arch/evbarm/conf/files.fdt" +include "arch/arm/vexpress/files.vexpress" Index: src/sys/arch/evbarm/conf/mk.vexpress diff -u src/sys/arch/evbarm/conf/mk.vexpress:1.1 src/sys/arch/evbarm/conf/mk.vexpress:1.2 --- src/sys/arch/evbarm/conf/mk.vexpress:1.1 Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/conf/mk.vexpress Fri Jun 2 15:22:47 2017 @@ -1,4 +1,4 @@ -# $NetBSD: mk.vexpress,v 1.1 2015/02/09 07:47:15 slp Exp $ +# $NetBSD: mk.vexpress,v 1.2 2017/06/02 15:22:47 jmcneill Exp $ .if !empty(MACHINE_ARCH:M*eb) EXTRA_LINKFLAGS+= --be8 @@ -12,42 +12,7 @@ _OSRELEASE!= ${HOST_SH} $S/conf/osrelea KERNEL_BASE_PHYS?=$(LOADADDRESS) KERNEL_BASE_VIRT?=$(LOADADDRESS) -MKUBOOTIMAGEARGS= -A arm -T kernel -MKUBOOTIMAGEARGS+= -a $(KERNEL_BASE_PHYS) -e $(KERNEL_BASE_PHYS) -MKUBOOTIMAGEARGS+= -n "NetBSD/$(BOARDTYPE) ${_OSRELEASE}" -MKUBOOTIMAGEARGS_NONE= ${MKUBOOTIMAGEARGS} -C none -MKUBOOTIMAGEARGS_GZ= ${MKUBOOTIMAGEARGS} -C gz - -SYSTEM_LD_TAIL_EXTRA+=; \ - echo ${OBJCOPY} -S -O binary $@ $@.bin; \ - ${OBJCOPY} -S -O binary $@ $@.bin; \ - echo ${TOOL_GZIP} -9c $@.bin > $@.bin.gz; \ - ${TOOL_GZIP} -9c $@.bin > $@.bin.gz; \ - echo ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_GZ} $@.bin.gz $@.gz.ub; \ - ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_GZ} $@.bin.gz $@.gz.ub; \ - echo ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_NONE} $@.bin $@.ub; \ - ${TOOL_MKUBOOTIMAGE} ${MKUBOOTIMAGEARGS_NONE} $@.bin $@.ub; \ - echo - -EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.bin@} -EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.ub@} -EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.bin.gz@} -EXTRA_KERNELS+= ${KERNELS:@.KERNEL.@${.KERNEL.}.gz.ub@} -# $NetBSD: mk.vexpress,v 1.1 2015/02/09 07:47:15 slp Exp $ - -.if !empty(MACHINE_ARCH:M*eb) -EXTRA_LINKFLAGS+= --be8 -.endif - -SYSTEM_FIRST_OBJ= vexpress_start.o -SYSTEM_FIRST_SFILE= ${THISARM}/vexpress/vexpress_start.S - -_OSRELEASE!= ${HOST_SH} $S/conf/osrelease.sh - -KERNEL_BASE_PHYS?=$(LOADADDRESS) -KERNEL_BASE_VIRT?=$(LOADADDRESS) - -MKUBOOTIMAGEARGS= -A arm -T kernel +MKUBOOTIMAGEARGS= -A arm -T kernel -O linux MKUBOOTIMAGEARGS+= -a $(KERNEL_BASE_PHYS) -e $(KERNEL_BASE_PHYS) MKUBOOTIMAGEARGS+= -n "NetBSD/$(BOARDTYPE) ${_OSRELEASE}" MKUBOOTIMAGEARGS_NONE= ${MKUBOOTIMAGEARGS} -C none Index: src/sys/arch/evbarm/conf/std.vexpress diff -u src/sys/arch/evbarm/conf/std.vexpress:1.3 src/sys/arch/evbarm/conf/std.vexpress:1.4 --- src/sys/arch/evbarm/conf/std.vexpress:1.3 Sat Apr 2 08:48:35 2016 +++ src/sys/arch/evbarm/conf/std.vexpress Fri Jun 2 15:22:47 2017 @@ -1,4 +1,4 @@ -# $NetBSD: std.vexpress,v 1.3 2016/04/02 08:48:35 skrll Exp $ +# $NetBSD: std.vexpress,v 1.4 2017/06/02 15:22:47 jmcneill Exp $ # # standard NetBSD/evbarm for VEXPRESS options @@ -8,11 +8,10 @@ include "arch/evbarm/conf/std.evbarm" # Pull in VEXPRESS config definitions include "arch/evbarm/conf/files.vexpress" -# To support easy transit to ../arch/arm/arm32 +options FDT # Flattened Device Tree support options MODULAR options MODULAR_DEFAULT_AUTOLOAD options ARM_HAS_VBAR -options CORTEX_PMC options __HAVE_CPU_COUNTER options __HAVE_FAST_SOFTINTS # should be in types.h #options __HAVE_MM_MD_DIRECT_MAPPED_PHYS @@ -20,12 +19,12 @@ options TPIDRPRW_IS_CURCPU options KERNEL_BASE_EXT=0x80000000 options FPU_VFP -makeoptions KERNEL_BASE_PHYS="0x80000000" -makeoptions KERNEL_BASE_VIRT="0x80000000" +makeoptions KERNEL_BASE_PHYS="0x81000000" +makeoptions KERNEL_BASE_VIRT="0x81000000" makeoptions BOARDTYPE="vexpress" makeoptions BOARDMKFRAG="${THISARM}/conf/mk.vexpress" makeoptions CPUFLAGS="-mcpu=cortex-a15 -mfpu=neon" -options ARM_INTR_IMPL="<arch/evbarm/vexpress/vexpress_intr.h>" +options ARM_INTR_IMPL="<arch/arm/fdt/fdt_intr.h>" options ARM_GENERIC_TODR Index: src/sys/arch/evbarm/vexpress/vexpress_start.S diff -u src/sys/arch/evbarm/vexpress/vexpress_start.S:1.2 src/sys/arch/evbarm/vexpress/vexpress_start.S:1.3 --- src/sys/arch/evbarm/vexpress/vexpress_start.S:1.2 Wed Feb 11 07:51:10 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_start.S Fri Jun 2 15:22:47 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vexpress_start.S,v 1.2 2015/02/11 07:51:10 ozaki-r Exp $ */ +/* $NetBSD: vexpress_start.S,v 1.3 2017/06/02 15:22:47 jmcneill Exp $ */ /*- * Copyright (c) 2015 The NetBSD Foundation, Inc. @@ -37,18 +37,23 @@ #include <arm/asm.h> #include <arm/armreg.h> #include "assym.h" -#include "platform.h" -RCSID("$NetBSD: vexpress_start.S,v 1.2 2015/02/11 07:51:10 ozaki-r Exp $") +#define VEXPRESS_CORE_VBASE 0xf0000000 +#define VEXPRESS_CORE_PBASE 0x10000000 +#define VEXPRESS_CORE_SIZE 0x10000000 + +RCSID("$NetBSD: vexpress_start.S,v 1.3 2017/06/02 15:22:47 jmcneill Exp $") #define XPUTC(n) mov r0, n; bl xputc #define XPUTC2(n) mov r0, n; blx r11 #define INIT_MEMSIZE 128 -#define TEMP_L1_TABLE (KERNEL_BASE - KERNEL_BASE_VOFFSET + INIT_MEMSIZE * 0x100000 - L1_TABLE_SIZE) +#define TEMP_L1_TABLE (KERNEL_BASE - KERNEL_BASE_VOFFSET + INIT_MEMSIZE * L1_S_SIZE - L1_TABLE_SIZE) + +#define MD_CPU_HATCH _C_LABEL(arm_fdt_cpu_hatch) /* - * Kernel start routine for ODROID boards running on uboot firmware + * Kernel start routine for Versatile Express boards running on uboot firmware * At this point, this code has been loaded into SDRAM * and the MMU is off */ @@ -62,6 +67,12 @@ _C_LABEL(vexpress_start): /* Move into supervisor mode and disable IRQs/FIQs. */ cpsid if, #PSR_SVC32_MODE + /* Save any arguments passed to us. */ + movw r4, #:lower16:uboot_args + movt r4, #:upper16:uboot_args + sub r4, r4, #KERNEL_BASE_VOFFSET + stmia r4, {r0-r3} + XPUTC('a') bl cortex_init Added files: Index: src/sys/arch/arm/vexpress/files.vexpress diff -u /dev/null src/sys/arch/arm/vexpress/files.vexpress:1.1 --- /dev/null Fri Jun 2 15:22:47 2017 +++ src/sys/arch/arm/vexpress/files.vexpress Fri Jun 2 15:22:47 2017 @@ -0,0 +1,18 @@ +# $NetBSD: files.vexpress,v 1.1 2017/06/02 15:22:47 jmcneill Exp $ +# +# Configuration info for ARM Ltd. Versatile Express peripherals +# +# + +include "arch/arm/pic/files.pic" +include "arch/arm/cortex/files.cortex" + +file arch/arm/arm32/arm32_boot.c +file arch/arm/arm32/arm32_kvminit.c +file arch/arm/arm32/arm32_reboot.c +file arch/arm/arm32/irq_dispatch.S +file arch/arm/arm32/armv7_generic_space.c +file arch/arm/arm32/armv7_generic_dma.c +file arch/arm/arm/bus_space_a4x.S + +file arch/arm/vexpress/vexpress_platform.c Index: src/sys/arch/arm/vexpress/vexpress_platform.c diff -u /dev/null src/sys/arch/arm/vexpress/vexpress_platform.c:1.1 --- /dev/null Fri Jun 2 15:22:47 2017 +++ src/sys/arch/arm/vexpress/vexpress_platform.c Fri Jun 2 15:22:47 2017 @@ -0,0 +1,170 @@ +/* $NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $ */ + +/*- + * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca> + * 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 THE AUTHOR ``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 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 "opt_multiprocessor.h" +#include "opt_fdt_arm.h" + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/cpu.h> +#include <sys/device.h> +#include <sys/termios.h> + +#include <dev/fdt/fdtvar.h> + +#include <uvm/uvm_extern.h> + +#include <machine/bootconfig.h> +#include <arm/cpufunc.h> + +#include <arm/fdt/arm_fdtvar.h> + +#include <arm/cortex/gtmr_var.h> + +#include <evbarm/dev/plcomvar.h> + +#define VEXPRESS_REF_FREQ 24000000 + +#define VEXPRESS_CORE_VBASE 0xf0000000 +#define VEXPRESS_CORE_PBASE 0x10000000 +#define VEXPRESS_CORE_SIZE 0x10000000 + +#define DEVMAP_ALIGN(a) ((a) & ~L1_S_OFFSET) +#define DEVMAP_SIZE(s) roundup2((s), L1_S_SIZE) +#define DEVMAP_ENTRY(va, pa, sz) \ + { \ + .pd_va = DEVMAP_ALIGN(va), \ + .pd_pa = DEVMAP_ALIGN(pa), \ + .pd_size = DEVMAP_SIZE(sz), \ + .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \ + .pd_cache = PTE_NOCACHE \ + } +#define DEVMAP_ENTRY_END { 0 } + +extern struct bus_space armv7_generic_bs_tag; +extern struct bus_space armv7_generic_a4x_bs_tag; +extern struct arm32_bus_dma_tag armv7_generic_dma_tag; + +#define SYSREG_BASE 0x1c010000 +#define SYSREG_SIZE 0x1000 + +#define SYS_FLAGS 0x0030 +#define SYS_FLAGSCLR 0x0034 +#define SYS_CFGDATA 0x00a0 +#define SYS_CFGCTRL 0x00a4 +#define SYS_CFGCTRL_START __BIT(31) +#define SYS_CFGCTRL_WRITE __BIT(30) +#define SYS_CFGCTRL_DCC __BITS(29,26) +#define SYS_CFGCTRL_FUNCTION __BITS(25,20) +#define SYS_CFGCTRL_FUNCTION_SHUTDOWN 8 +#define SYS_CFGCTRL_FUNCTION_REBOOT 9 +#define SYS_CFGCTRL_SITE __BITS(17,16) +#define SYS_CFGCTRL_POSITION __BITS(15,12) +#define SYS_CFGCTRL_DEVICE __BITS(11,0) +#define SYS_CFGSTAT 0x00a8 +#define SYS_CFGSTAT_ERROR __BIT(1) +#define SYS_CFGSTAT_COMPLETE __BIT(0) + +static bus_space_tag_t sysreg_bst = &armv7_generic_bs_tag; +static bus_space_handle_t sysreg_bsh; + +#define SYSREG_WRITE(o, v) \ + bus_space_write_4(sysreg_bst, sysreg_bsh, (o), (v)) + + +static const struct pmap_devmap * +vexpress_platform_devmap(void) +{ + static const struct pmap_devmap devmap[] = { + DEVMAP_ENTRY(VEXPRESS_CORE_VBASE, + VEXPRESS_CORE_PBASE, + VEXPRESS_CORE_SIZE), + DEVMAP_ENTRY_END + }; + + return devmap; +} + +static void +vexpress_platform_bootstrap(void) +{ + bus_space_map(sysreg_bst, SYSREG_BASE, SYSREG_SIZE, 0, + &sysreg_bsh); +} + +static void +vexpress_platform_init_attach_args(struct fdt_attach_args *faa) +{ + faa->faa_bst = &armv7_generic_bs_tag; + faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag; + faa->faa_dmat = &armv7_generic_dma_tag; +} + +static void +vexpress_platform_early_putchar(char c) +{ +} + +static void +vexpress_platform_device_register(device_t self, void *aux) +{ +} + +static void +vexpress_platform_reset(void) +{ + SYSREG_WRITE(SYS_CFGSTAT, 0); + SYSREG_WRITE(SYS_CFGDATA, 0); + SYSREG_WRITE(SYS_CFGCTRL, + SYS_CFGCTRL_START | + SYS_CFGCTRL_WRITE | + __SHIFTIN(SYS_CFGCTRL_FUNCTION_REBOOT, + SYS_CFGCTRL_FUNCTION)); +} + +static u_int +vexpress_platform_uart_freq(void) +{ + return VEXPRESS_REF_FREQ; +} + +static const struct arm_platform vexpress_platform = { + .devmap = vexpress_platform_devmap, + .bootstrap = vexpress_platform_bootstrap, + .init_attach_args = vexpress_platform_init_attach_args, + .early_putchar = vexpress_platform_early_putchar, + .device_register = vexpress_platform_device_register, + .reset = vexpress_platform_reset, + .delay = gtmr_delay, + .uart_freq = vexpress_platform_uart_freq, +}; + +ARM_PLATFORM(vexpress, "arm,vexpress", &vexpress_platform);