Module Name: src Committed By: slp Date: Mon Feb 9 07:47:15 UTC 2015
Added Files: src/sys/arch/evbarm/conf: files.vexpress mk.vexpress std.vexpress 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_start.S vexpress_var.h Log Message: Add support for Versatile Express A15 board. This has not been tested with real hardware, just with the software model emulated by QEMU. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/conf/files.vexpress \ src/sys/arch/evbarm/conf/mk.vexpress \ src/sys/arch/evbarm/conf/std.vexpress cvs rdiff -u -r0 -r1.1 src/sys/arch/evbarm/vexpress/if_smsh_axi.c \ 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_machdep.c \ 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_start.S \ src/sys/arch/evbarm/vexpress/vexpress_var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Added files: Index: src/sys/arch/evbarm/conf/files.vexpress diff -u /dev/null src/sys/arch/evbarm/conf/files.vexpress:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/conf/files.vexpress Mon Feb 9 07:47:15 2015 @@ -0,0 +1,68 @@ +# $NetBSD: files.vexpress,v 1.1 2015/02/09 07:47:15 slp 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 + +# $NetBSD: files.vexpress,v 1.1 2015/02/09 07:47:15 slp 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 + Index: src/sys/arch/evbarm/conf/mk.vexpress diff -u /dev/null src/sys/arch/evbarm/conf/mk.vexpress:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/conf/mk.vexpress Mon Feb 9 07:47:15 2015 @@ -0,0 +1,70 @@ +# $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 $(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 $(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@} Index: src/sys/arch/evbarm/conf/std.vexpress diff -u /dev/null src/sys/arch/evbarm/conf/std.vexpress:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/conf/std.vexpress Mon Feb 9 07:47:15 2015 @@ -0,0 +1,64 @@ +# $NetBSD: std.vexpress,v 1.1 2015/02/09 07:47:15 slp Exp $ +# +# standard NetBSD/evbarm for VEXPRESS options + +machine evbarm arm +include "arch/evbarm/conf/std.evbarm" + +# Pull in VEXPRESS config definitions +include "arch/evbarm/conf/files.vexpress" + +makeoptions CPUFLAGS="-march=armv7-a -mfpu=neon" + +# To support easy transit to ../arch/arm/arm32 +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 +options TPIDRPRW_IS_CURCPU +options KERNEL_BASE_EXT=0x80000000 +options FPU_VFP + +makeoptions KERNEL_BASE_PHYS="0x80000000" +makeoptions KERNEL_BASE_VIRT="0x80000000" +makeoptions BOARDTYPE="vexpress" +makeoptions BOARDMKFRAG="${THISARM}/conf/mk.vexpress" + +options ARM_INTR_IMPL="<arch/evbarm/vexpress/vexpress_intr.h>" +options ARM_GENERIC_TODR + +# $NetBSD: std.vexpress,v 1.1 2015/02/09 07:47:15 slp Exp $ +# +# standard NetBSD/evbarm for VEXPRESS options + +machine evbarm arm +include "arch/evbarm/conf/std.evbarm" + +# Pull in VEXPRESS config definitions +include "arch/evbarm/conf/files.vexpress" + +makeoptions CPUFLAGS="-march=armv7-a -mfpu=neon" + +# To support easy transit to ../arch/arm/arm32 +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 +options TPIDRPRW_IS_CURCPU +options KERNEL_BASE_EXT=0x80000000 +options FPU_VFP + +makeoptions KERNEL_BASE_PHYS="0x80000000" +makeoptions KERNEL_BASE_VIRT="0x80000000" +makeoptions BOARDTYPE="vexpress" +makeoptions BOARDMKFRAG="${THISARM}/conf/mk.vexpress" + +options ARM_INTR_IMPL="<arch/evbarm/vexpress/vexpress_intr.h>" +options ARM_GENERIC_TODR + Index: src/sys/arch/evbarm/vexpress/if_smsh_axi.c diff -u /dev/null src/sys/arch/evbarm/vexpress/if_smsh_axi.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/if_smsh_axi.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,234 @@ +/* $NetBSD: if_smsh_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: if_smsh_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include "locators.h" + +#include <sys/param.h> +#include <sys/device.h> +#include <sys/errno.h> +#include <sys/bus.h> +#include <sys/systm.h> + +#include <net/if.h> +#include <net/if_ether.h> +#include <net/if_media.h> + +#include <dev/mii/miivar.h> + +#include <dev/ic/lan9118var.h> +#include <dev/ic/lan9118reg.h> + +#include <evbarm/vexpress/vexpress_var.h> + + +static int smsh_axi_match(device_t, struct cfdata *, void *); +static void smsh_axi_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(smsh_axi, sizeof(struct lan9118_softc), + smsh_axi_match, smsh_axi_attach, NULL, NULL); + + +/* ARGSUSED */ +static int +smsh_axi_match(device_t parent, struct cfdata * match, void *aux) +{ + struct axi_attach_args *aa = aux; + + /* Disallow wildcarded values. */ + if (aa->aa_addr == 0) + return 0; + if (aa->aa_irq == 0) + return 0; + + return 1; +} + +/* ARGSUSED */ +static void +smsh_axi_attach(device_t parent, device_t self, void *aux) +{ + struct lan9118_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + prop_dictionary_t dict = device_properties(self); + void *ih; + + sc->sc_dev = self; + + /* + * Prefer the Ethernet address in device properties. + */ + prop_data_t ea = prop_dictionary_get(dict, "mac-address"); + if (ea != NULL) { + KASSERT(prop_object_type(ea) == PROP_TYPE_DATA); + KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN); + memcpy(sc->sc_enaddr, prop_data_data_nocopy(ea), + ETHER_ADDR_LEN); + sc->sc_flags |= LAN9118_FLAGS_NO_EEPROM; + } + /* Map i/o space. */ + if (bus_space_map(aa->aa_iot, aa->aa_addr, LAN9118_IOSIZE, 0, + &sc->sc_ioh)) + panic("smsh_axi_attach: can't map i/o space"); + sc->sc_iot = aa->aa_iot; + + if (lan9118_attach(sc) != 0) { + bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE); + return; + } + /* Establish the interrupt handler. */ + ih = intr_establish(aa->aa_irq, IPL_NET, IST_LEVEL, + lan9118_intr, sc); + if (ih == NULL) { + aprint_error_dev(self, + "couldn't establish interrupt handler\n"); + bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE); + return; + } +} +/* $NetBSD: if_smsh_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: if_smsh_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include "locators.h" + +#include <sys/param.h> +#include <sys/device.h> +#include <sys/errno.h> +#include <sys/bus.h> +#include <sys/systm.h> + +#include <net/if.h> +#include <net/if_ether.h> +#include <net/if_media.h> + +#include <dev/mii/miivar.h> + +#include <dev/ic/lan9118var.h> +#include <dev/ic/lan9118reg.h> + +#include <evbarm/vexpress/vexpress_var.h> + + +static int smsh_axi_match(device_t, struct cfdata *, void *); +static void smsh_axi_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(smsh_axi, sizeof(struct lan9118_softc), + smsh_axi_match, smsh_axi_attach, NULL, NULL); + + +/* ARGSUSED */ +static int +smsh_axi_match(device_t parent, struct cfdata * match, void *aux) +{ + struct axi_attach_args *aa = aux; + + /* Disallow wildcarded values. */ + if (aa->aa_addr == 0) + return 0; + if (aa->aa_irq == 0) + return 0; + + return 1; +} + +/* ARGSUSED */ +static void +smsh_axi_attach(device_t parent, device_t self, void *aux) +{ + struct lan9118_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + prop_dictionary_t dict = device_properties(self); + void *ih; + + sc->sc_dev = self; + + /* + * Prefer the Ethernet address in device properties. + */ + prop_data_t ea = prop_dictionary_get(dict, "mac-address"); + if (ea != NULL) { + KASSERT(prop_object_type(ea) == PROP_TYPE_DATA); + KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN); + memcpy(sc->sc_enaddr, prop_data_data_nocopy(ea), + ETHER_ADDR_LEN); + sc->sc_flags |= LAN9118_FLAGS_NO_EEPROM; + } + /* Map i/o space. */ + if (bus_space_map(aa->aa_iot, aa->aa_addr, LAN9118_IOSIZE, 0, + &sc->sc_ioh)) + panic("smsh_axi_attach: can't map i/o space"); + sc->sc_iot = aa->aa_iot; + + if (lan9118_attach(sc) != 0) { + bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE); + return; + } + /* Establish the interrupt handler. */ + ih = intr_establish(aa->aa_irq, IPL_NET, IST_LEVEL, + lan9118_intr, sc); + if (ih == NULL) { + aprint_error_dev(self, + "couldn't establish interrupt handler\n"); + bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE); + return; + } +} Index: src/sys/arch/evbarm/vexpress/platform.h diff -u /dev/null src/sys/arch/evbarm/vexpress/platform.h:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/platform.h Mon Feb 9 07:47:15 2015 @@ -0,0 +1,102 @@ +/* $NetBSD: platform.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +#ifndef _ARM_VEXPRESS_PLATFORM_H +#define _ARM_VEXPRESS_PLATFORM_H + +/* + * IO space + */ + +#define VEXPRESS_CORE_VBASE 0xf0000000 +#define VEXPRESS_CORE_PBASE 0x10000000 +#define VEXPRESS_CORE_SIZE 0x10000000 + +/* + * Kernel VM space 16Mb behind KERNEL_BASE upto 0xeff00000 + */ +#define KERNEL_VM_BASE 0xc0000000 +#define KERNEL_VM_SIZE (VEXPRESS_CORE_VBASE - KERNEL_VM_BASE) + +#define VEXPRESS_REF_FREQ (24*1000*1000) /* 24MHz */ + +#endif /* _ARM_VEXPRESS_PLATFORM_H */ +/* $NetBSD: platform.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +#ifndef _ARM_VEXPRESS_PLATFORM_H +#define _ARM_VEXPRESS_PLATFORM_H + +/* + * IO space + */ + +#define VEXPRESS_CORE_VBASE 0xf0000000 +#define VEXPRESS_CORE_PBASE 0x10000000 +#define VEXPRESS_CORE_SIZE 0x10000000 + +/* + * Kernel VM space 16Mb behind KERNEL_BASE upto 0xeff00000 + */ +#define KERNEL_VM_BASE 0xc0000000 +#define KERNEL_VM_SIZE (VEXPRESS_CORE_VBASE - KERNEL_VM_BASE) + +#define VEXPRESS_REF_FREQ (24*1000*1000) /* 24MHz */ + +#endif /* _ARM_VEXPRESS_PLATFORM_H */ Index: src/sys/arch/evbarm/vexpress/vexpress_axi.c diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_axi.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_axi.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,312 @@ +/* $NetBSD: vexpress_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: vexpress_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/device.h> + +#include <uvm/uvm_extern.h> + +#include <evbarm/vexpress/vexpress_var.h> + +#include "locators.h" + +struct axi_softc { + device_t sc_dev; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; +}; + +static int axi_match(device_t, struct cfdata *, void *); +static void axi_attach(device_t, device_t, void *); +static int axi_search(device_t, struct cfdata *, const int *, void *); +static int axi_critical_search(device_t, struct cfdata *, const int *, void *); +static int axi_search(device_t, struct cfdata *, const int *, void *); +static int axi_print(void *, const char *); + +CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc), + axi_match, axi_attach, NULL, NULL); + +/* ARGSUSED */ +static int +axi_match(device_t parent __unused, struct cfdata * match __unused, + void *aux __unused) +{ + return 1; +} + +/* ARGSUSED */ +static void +axi_attach(device_t parent __unused, device_t self, void *aux __unused) +{ + struct axi_softc *sc; + struct axi_attach_args aa; + + aprint_normal(": Advanced eXtensible Interface\n"); + aprint_naive("\n"); + + sc = device_private(self); + sc->sc_iot = &vexpress_bs_tag; +#if NBUS_DMA_GENERIC > 0 + sc->sc_dmat = &vexpress_bus_dma_tag; +#else + sc->sc_dmat = 0; +#endif + + aa.aa_name = "axi"; + aa.aa_iot = sc->sc_iot; + aa.aa_dmat = sc->sc_dmat; + config_search_ia(axi_critical_search, self, "axi", &aa); + config_search_ia(axi_search, self, "axi", &aa); +} + +/* ARGSUSED */ +static int +axi_critical_search(device_t parent, struct cfdata * cf, + const int *ldesc __unused, void *aux) +{ + struct axi_attach_args *aa; + + aa = aux; + + if (strcmp(cf->cf_name, "plcom") != 0) + return 0; + + aa->aa_name = cf->cf_name; + aa->aa_addr = cf->cf_loc[AXICF_ADDR]; + aa->aa_size = cf->cf_loc[AXICF_SIZE]; + aa->aa_irq = cf->cf_loc[AXICF_IRQ]; + aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE]; + + if (config_match(parent, cf, aux) > 0) + config_attach(parent, cf, aux, axi_print); + + return 0; +} + +/* ARGSUSED */ +static int +axi_search(device_t parent, struct cfdata * cf, const int *ldesc __unused, + void *aux) +{ + struct axi_attach_args *aa; + + aa = aux; + + aa->aa_addr = cf->cf_loc[AXICF_ADDR]; + aa->aa_size = cf->cf_loc[AXICF_SIZE]; + aa->aa_irq = cf->cf_loc[AXICF_IRQ]; + aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE]; + + if (config_match(parent, cf, aux) > 0) + config_attach(parent, cf, aux, axi_print); + + return 0; +} + +/* ARGSUSED */ +static int +axi_print(void *aux, const char *name __unused) +{ + struct axi_attach_args *aa = (struct axi_attach_args *) aux; + + if (aa->aa_addr != AXICF_ADDR_DEFAULT) { + aprint_normal(" addr 0x%lx", aa->aa_addr); + if (aa->aa_size > AXICF_SIZE_DEFAULT) + aprint_normal("-0x%lx", + aa->aa_addr + aa->aa_size - 1); + } + if (aa->aa_irq != AXICF_IRQ_DEFAULT) + aprint_normal(" intr %d", aa->aa_irq); + if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT) + aprint_normal(" irqbase %d", aa->aa_irqbase); + + return (UNCONF); +} +/* $NetBSD: vexpress_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: vexpress_axi.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/device.h> + +#include <uvm/uvm_extern.h> + +#include <evbarm/vexpress/vexpress_var.h> + +#include "locators.h" + +struct axi_softc { + device_t sc_dev; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; +}; + +static int axi_match(device_t, struct cfdata *, void *); +static void axi_attach(device_t, device_t, void *); +static int axi_search(device_t, struct cfdata *, const int *, void *); +static int axi_critical_search(device_t, struct cfdata *, const int *, void *); +static int axi_search(device_t, struct cfdata *, const int *, void *); +static int axi_print(void *, const char *); + +CFATTACH_DECL_NEW(axi, sizeof(struct axi_softc), + axi_match, axi_attach, NULL, NULL); + +/* ARGSUSED */ +static int +axi_match(device_t parent __unused, struct cfdata * match __unused, + void *aux __unused) +{ + return 1; +} + +/* ARGSUSED */ +static void +axi_attach(device_t parent __unused, device_t self, void *aux __unused) +{ + struct axi_softc *sc; + struct axi_attach_args aa; + + aprint_normal(": Advanced eXtensible Interface\n"); + aprint_naive("\n"); + + sc = device_private(self); + sc->sc_iot = &vexpress_bs_tag; +#if NBUS_DMA_GENERIC > 0 + sc->sc_dmat = &vexpress_bus_dma_tag; +#else + sc->sc_dmat = 0; +#endif + + aa.aa_name = "axi"; + aa.aa_iot = sc->sc_iot; + aa.aa_dmat = sc->sc_dmat; + config_search_ia(axi_critical_search, self, "axi", &aa); + config_search_ia(axi_search, self, "axi", &aa); +} + +/* ARGSUSED */ +static int +axi_critical_search(device_t parent, struct cfdata * cf, + const int *ldesc __unused, void *aux) +{ + struct axi_attach_args *aa; + + aa = aux; + + if (strcmp(cf->cf_name, "plcom") != 0) + return 0; + + aa->aa_name = cf->cf_name; + aa->aa_addr = cf->cf_loc[AXICF_ADDR]; + aa->aa_size = cf->cf_loc[AXICF_SIZE]; + aa->aa_irq = cf->cf_loc[AXICF_IRQ]; + aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE]; + + if (config_match(parent, cf, aux) > 0) + config_attach(parent, cf, aux, axi_print); + + return 0; +} + +/* ARGSUSED */ +static int +axi_search(device_t parent, struct cfdata * cf, const int *ldesc __unused, + void *aux) +{ + struct axi_attach_args *aa; + + aa = aux; + + aa->aa_addr = cf->cf_loc[AXICF_ADDR]; + aa->aa_size = cf->cf_loc[AXICF_SIZE]; + aa->aa_irq = cf->cf_loc[AXICF_IRQ]; + aa->aa_irqbase = cf->cf_loc[AXICF_IRQBASE]; + + if (config_match(parent, cf, aux) > 0) + config_attach(parent, cf, aux, axi_print); + + return 0; +} + +/* ARGSUSED */ +static int +axi_print(void *aux, const char *name __unused) +{ + struct axi_attach_args *aa = (struct axi_attach_args *) aux; + + if (aa->aa_addr != AXICF_ADDR_DEFAULT) { + aprint_normal(" addr 0x%lx", aa->aa_addr); + if (aa->aa_size > AXICF_SIZE_DEFAULT) + aprint_normal("-0x%lx", + aa->aa_addr + aa->aa_size - 1); + } + if (aa->aa_irq != AXICF_IRQ_DEFAULT) + aprint_normal(" intr %d", aa->aa_irq); + if (aa->aa_irqbase != AXICF_IRQBASE_DEFAULT) + aprint_normal(" irqbase %d", aa->aa_irqbase); + + return (UNCONF); +} Index: src/sys/arch/evbarm/vexpress/vexpress_intr.h diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_intr.h:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_intr.h Mon Feb 9 07:47:15 2015 @@ -0,0 +1,108 @@ +/* $NetBSD: vexpress_intr.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +#ifndef _ARM_VEXPRESS_INTR_H_ +#define _ARM_VEXPRESS_INTR_H_ + +#define PIC_MAXSOURCES GIC_MAXSOURCES(224) +#define PIC_MAXMAXSOURCES (PIC_MAXSOURCES + 32) /* XXX */ + +/* + * The Exynos uses a generic interrupt controller + */ +#include <arm/cortex/gic_intr.h> + +/* + * The GIC supports + * - 16 Software Generated Interrupts (SGIs) + * - 16 Private Peripheral Interrupts (PPIs) + * - 127 Shared Peripheral Interrupts (SPIs) + */ + +#define IRQ_MCT_LTIMER IRQ_PPI(12) + +#include <arm/cortex/gtmr_intr.h> + +#endif /* _ARM_VEXPRESS_INTR_H_ */ +/* $NetBSD: vexpress_intr.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +#ifndef _ARM_VEXPRESS_INTR_H_ +#define _ARM_VEXPRESS_INTR_H_ + +#define PIC_MAXSOURCES GIC_MAXSOURCES(224) +#define PIC_MAXMAXSOURCES (PIC_MAXSOURCES + 32) /* XXX */ + +/* + * The Exynos uses a generic interrupt controller + */ +#include <arm/cortex/gic_intr.h> + +/* + * The GIC supports + * - 16 Software Generated Interrupts (SGIs) + * - 16 Private Peripheral Interrupts (PPIs) + * - 127 Shared Peripheral Interrupts (SPIs) + */ + +#define IRQ_MCT_LTIMER IRQ_PPI(12) + +#include <arm/cortex/gtmr_intr.h> + +#endif /* _ARM_VEXPRESS_INTR_H_ */ Index: src/sys/arch/evbarm/vexpress/vexpress_machdep.c diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_machdep.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_machdep.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,568 @@ +/* $NetBSD: vexpress_machdep.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/* + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: vexpress_machdep.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include "opt_machdep.h" +#include "opt_ddb.h" +#include "opt_kgdb.h" +#include "opt_ipkdb.h" +#include "opt_md.h" +#include "opt_arm_debug.h" + +#include "ukbd.h" +#include "arml2cc.h" // RPZ why is it not called opt_l2cc.h? + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/cpu.h> +#include <sys/device.h> +#include <sys/exec.h> +#include <sys/kernel.h> +#include <sys/ksyms.h> +#include <sys/msgbuf.h> +#include <sys/proc.h> +#include <sys/reboot.h> +#include <sys/termios.h> +#include <sys/gpio.h> + +#include <uvm/uvm_extern.h> + +#include <sys/conf.h> +#include <dev/cons.h> +#include <dev/md.h> + +#include <machine/db_machdep.h> +#include <ddb/db_sym.h> +#include <ddb/db_extern.h> +#ifdef KGDB +#include <sys/kgdb.h> +#endif + +#include <machine/bootconfig.h> +#include <arm/armreg.h> +#include <arm/undefined.h> +#include <arm/cortex/pl310_var.h> + +#include <arm/arm32/machdep.h> +#include <arm/mainbus/mainbus.h> + +#include <evbarm/vexpress/vexpress_var.h> + +#include <evbarm/include/autoconf.h> +#include <evbarm/vexpress/platform.h> + +#include <dev/i2c/i2cvar.h> +#include <dev/i2c/ddcreg.h> + +#include <dev/usb/ukbdvar.h> +#include <net/if_ether.h> + +#include "plcom.h" + +#if NPLCOM > 0 +#include <evbarm/dev/plcomreg.h> +#include <evbarm/dev/plcomvar.h> +#endif + +#define PLCONADDR 0x1c090000 + +#ifndef CONSDEVNAME +#define CONSDEVNAME "plcom" +#endif + +#ifndef PLCONSPEED +#define PLCONSPEED B115200 +#endif +#ifndef PLCONMODE +#define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ +#endif +#ifndef PLCOMCNUNIT +#define PLCOMCNUNIT -1 +#endif + +#if (NPLCOM > 0) +static const bus_addr_t consaddr = (bus_addr_t) PLCONADDR; + +int plcomcnspeed = PLCONSPEED; +int plcomcnmode = PLCONMODE; +#endif + +#if (NPLCOM > 0 && (defined(PLCONSOLE) || defined(KGDB))) +static struct plcom_instance vexpress_pi = { + .pi_type = PLCOM_TYPE_PL011, + .pi_flags = PLC_FLAG_32BIT_ACCESS, + .pi_iot = &vexpress_bs_tag, + .pi_size = PL011COM_UART_SIZE +}; +#endif + +/* + * kernel start and end from the linker + */ +extern char KERNEL_BASE_phys[]; /* physical start of kernel */ +extern char KERNEL_BASE_virt[]; /* virtual start of kernel */ +extern char _end[]; /* physical end of kernel */ +#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) + +#define KERN_VTOPDIFF ((vaddr_t)KERNEL_BASE_phys - (vaddr_t)KERNEL_BASE_virt) +#define KERN_VTOPHYS(va) ((paddr_t)((vaddr_t)va + (vaddr_t)KERN_VTOPDIFF)) +#define KERN_PHYSTOV(pa) ((vaddr_t)((paddr_t)pa - (vaddr_t)KERN_VTOPDIFF)) + +BootConfig bootconfig; /* Boot config storage */ +char *boot_args = NULL; + +/* prototypes */ +void consinit(void); +#ifdef KGDB +static void kgdb_port_init(void); +#endif +static void vexpress_device_register(device_t, void *); + +/* + * Our static device mappings at fixed virtual addresses so we can use them + * while booting the kernel. + * + * Map the extents segment-aligned and segment-rounded in size to avoid L2 + * page tables + */ + +#define _A(a) ((a) & ~L1_S_OFFSET) +#define _S(s) (((s) + L1_S_SIZE - 1) & (~(L1_S_SIZE-1))) + +static const struct pmap_devmap vexpress_devmap[] = { + { + /* map in core IO space */ + .pd_va = _A(VEXPRESS_CORE_VBASE), + .pd_pa = _A(VEXPRESS_CORE_PBASE), + .pd_size = _S(VEXPRESS_CORE_SIZE), + .pd_prot = VM_PROT_READ | VM_PROT_WRITE, + .pd_cache = PTE_NOCACHE + }, + {0} +}; +#undef _A +#undef _S + +/* + * u_int initarm(...) + * + * Our entry point from the assembly before main() is called. + * - take a copy of the config we got from uboot + * - init the physical console + * - setting up page tables for the kernel + */ + +u_int +initarm(void *arg) +{ +#ifdef MEMSIZE + psize_t memsize = (unsigned) MEMSIZE * 1024 * 1024; +#else + /* If MEMSIZE is not defined, use QEMU's default value (128 MB) */ + psize_t memsize = (unsigned) 128 * 1024 * 1024; +#endif + + pmap_devmap_register(vexpress_devmap); + + set_cpufuncs(); + + consinit(); + + /* Talk to the user */ +#define BDSTR(s) _BDSTR(s) +#define _BDSTR(s) #s + printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n"); + +#ifdef VERBOSE_INIT_ARM + printf("initarm: cbar=%#x\n", armreg_cbar_read()); +#endif + + bootconfig.dramblocks = 1; + bootconfig.dram[0].address = KERN_VTOPHYS(KERNEL_BASE); + bootconfig.dram[0].pages = memsize / PAGE_SIZE; + + arm32_bootmem_init(bootconfig.dram[0].address, memsize, + (uintptr_t) KERNEL_BASE_phys); + + arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, vexpress_devmap, + true); + +#ifdef VERBOSE_INIT_ARM + printf("initarm: Configuring system ...\n"); +#endif + + cortex_pmc_ccnt_init(); + + /* We've a specific device_register routine */ + evbarm_device_register = vexpress_device_register; + + return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); +} + +void +consinit(void) +{ + static int consinit_called = 0; + + if (consinit_called != 0) + return; + + consinit_called = 1; + +#if (NPLCOM > 0 && defined(PLCONSOLE)) + /* + * Initialise the diagnostic serial console + * This allows a means of generating output during initarm(). + */ + vexpress_pi.pi_iobase = consaddr; + + plcomcnattach(&vexpress_pi, plcomcnspeed, 3000000, + plcomcnmode, PLCOMCNUNIT); + +#endif +} + +void +vexpress_device_register(device_t self, void *aux) +{ + prop_dictionary_t dict = device_properties(self); + + if (device_is_a(self, "armperiph") + && device_is_a(device_parent(self), "mainbus")) { + /* + * XXX KLUDGE ALERT XXX + * The iot mainbus supplies is completely wrong since it scales + * addresses by 2. The simpliest remedy is to replace with our + * bus space used for the armcore regisers (which armperiph uses). + */ + struct mainbus_attach_args *const mb = aux; + mb->mb_iot = &vexpress_bs_tag; + return; + } +#if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15) + if (device_is_a(self, "armgtmr")) { + /* + * The frequency of the generic timer is the reference + * frequency. + */ + prop_dictionary_set_uint32(dict, "frequency", VEXPRESS_REF_FREQ); + return; + } +#endif +} +/* $NetBSD: vexpress_machdep.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/* + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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: vexpress_machdep.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include "opt_machdep.h" +#include "opt_ddb.h" +#include "opt_kgdb.h" +#include "opt_ipkdb.h" +#include "opt_md.h" +#include "opt_arm_debug.h" + +#include "ukbd.h" +#include "arml2cc.h" // RPZ why is it not called opt_l2cc.h? + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/bus.h> +#include <sys/cpu.h> +#include <sys/device.h> +#include <sys/exec.h> +#include <sys/kernel.h> +#include <sys/ksyms.h> +#include <sys/msgbuf.h> +#include <sys/proc.h> +#include <sys/reboot.h> +#include <sys/termios.h> +#include <sys/gpio.h> + +#include <uvm/uvm_extern.h> + +#include <sys/conf.h> +#include <dev/cons.h> +#include <dev/md.h> + +#include <machine/db_machdep.h> +#include <ddb/db_sym.h> +#include <ddb/db_extern.h> +#ifdef KGDB +#include <sys/kgdb.h> +#endif + +#include <machine/bootconfig.h> +#include <arm/armreg.h> +#include <arm/undefined.h> +#include <arm/cortex/pl310_var.h> + +#include <arm/arm32/machdep.h> +#include <arm/mainbus/mainbus.h> + +#include <evbarm/vexpress/vexpress_var.h> + +#include <evbarm/include/autoconf.h> +#include <evbarm/vexpress/platform.h> + +#include <dev/i2c/i2cvar.h> +#include <dev/i2c/ddcreg.h> + +#include <dev/usb/ukbdvar.h> +#include <net/if_ether.h> + +#include "plcom.h" + +#if NPLCOM > 0 +#include <evbarm/dev/plcomreg.h> +#include <evbarm/dev/plcomvar.h> +#endif + +#define PLCONADDR 0x1c090000 + +#ifndef CONSDEVNAME +#define CONSDEVNAME "plcom" +#endif + +#ifndef PLCONSPEED +#define PLCONSPEED B115200 +#endif +#ifndef PLCONMODE +#define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ +#endif +#ifndef PLCOMCNUNIT +#define PLCOMCNUNIT -1 +#endif + +#if (NPLCOM > 0) +static const bus_addr_t consaddr = (bus_addr_t) PLCONADDR; + +int plcomcnspeed = PLCONSPEED; +int plcomcnmode = PLCONMODE; +#endif + +#if (NPLCOM > 0 && (defined(PLCONSOLE) || defined(KGDB))) +static struct plcom_instance vexpress_pi = { + .pi_type = PLCOM_TYPE_PL011, + .pi_flags = PLC_FLAG_32BIT_ACCESS, + .pi_iot = &vexpress_bs_tag, + .pi_size = PL011COM_UART_SIZE +}; +#endif + +/* + * kernel start and end from the linker + */ +extern char KERNEL_BASE_phys[]; /* physical start of kernel */ +extern char KERNEL_BASE_virt[]; /* virtual start of kernel */ +extern char _end[]; /* physical end of kernel */ +#define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys) + +#define KERN_VTOPDIFF ((vaddr_t)KERNEL_BASE_phys - (vaddr_t)KERNEL_BASE_virt) +#define KERN_VTOPHYS(va) ((paddr_t)((vaddr_t)va + (vaddr_t)KERN_VTOPDIFF)) +#define KERN_PHYSTOV(pa) ((vaddr_t)((paddr_t)pa - (vaddr_t)KERN_VTOPDIFF)) + +BootConfig bootconfig; /* Boot config storage */ +char *boot_args = NULL; + +/* prototypes */ +void consinit(void); +#ifdef KGDB +static void kgdb_port_init(void); +#endif +static void vexpress_device_register(device_t, void *); + +/* + * Our static device mappings at fixed virtual addresses so we can use them + * while booting the kernel. + * + * Map the extents segment-aligned and segment-rounded in size to avoid L2 + * page tables + */ + +#define _A(a) ((a) & ~L1_S_OFFSET) +#define _S(s) (((s) + L1_S_SIZE - 1) & (~(L1_S_SIZE-1))) + +static const struct pmap_devmap vexpress_devmap[] = { + { + /* map in core IO space */ + .pd_va = _A(VEXPRESS_CORE_VBASE), + .pd_pa = _A(VEXPRESS_CORE_PBASE), + .pd_size = _S(VEXPRESS_CORE_SIZE), + .pd_prot = VM_PROT_READ | VM_PROT_WRITE, + .pd_cache = PTE_NOCACHE + }, + {0} +}; +#undef _A +#undef _S + +/* + * u_int initarm(...) + * + * Our entry point from the assembly before main() is called. + * - take a copy of the config we got from uboot + * - init the physical console + * - setting up page tables for the kernel + */ + +u_int +initarm(void *arg) +{ +#ifdef MEMSIZE + psize_t memsize = (unsigned) MEMSIZE * 1024 * 1024; +#else + /* If MEMSIZE is not defined, use QEMU's default value (128 MB) */ + psize_t memsize = (unsigned) 128 * 1024 * 1024; +#endif + + pmap_devmap_register(vexpress_devmap); + + set_cpufuncs(); + + consinit(); + + /* Talk to the user */ +#define BDSTR(s) _BDSTR(s) +#define _BDSTR(s) #s + printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n"); + +#ifdef VERBOSE_INIT_ARM + printf("initarm: cbar=%#x\n", armreg_cbar_read()); +#endif + + bootconfig.dramblocks = 1; + bootconfig.dram[0].address = KERN_VTOPHYS(KERNEL_BASE); + bootconfig.dram[0].pages = memsize / PAGE_SIZE; + + arm32_bootmem_init(bootconfig.dram[0].address, memsize, + (uintptr_t) KERNEL_BASE_phys); + + arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0, vexpress_devmap, + true); + +#ifdef VERBOSE_INIT_ARM + printf("initarm: Configuring system ...\n"); +#endif + + cortex_pmc_ccnt_init(); + + /* We've a specific device_register routine */ + evbarm_device_register = vexpress_device_register; + + return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0); +} + +void +consinit(void) +{ + static int consinit_called = 0; + + if (consinit_called != 0) + return; + + consinit_called = 1; + +#if (NPLCOM > 0 && defined(PLCONSOLE)) + /* + * Initialise the diagnostic serial console + * This allows a means of generating output during initarm(). + */ + vexpress_pi.pi_iobase = consaddr; + + plcomcnattach(&vexpress_pi, plcomcnspeed, 3000000, + plcomcnmode, PLCOMCNUNIT); + +#endif +} + +void +vexpress_device_register(device_t self, void *aux) +{ + prop_dictionary_t dict = device_properties(self); + + if (device_is_a(self, "armperiph") + && device_is_a(device_parent(self), "mainbus")) { + /* + * XXX KLUDGE ALERT XXX + * The iot mainbus supplies is completely wrong since it scales + * addresses by 2. The simpliest remedy is to replace with our + * bus space used for the armcore regisers (which armperiph uses). + */ + struct mainbus_attach_args *const mb = aux; + mb->mb_iot = &vexpress_bs_tag; + return; + } +#if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15) + if (device_is_a(self, "armgtmr")) { + /* + * The frequency of the generic timer is the reference + * frequency. + */ + prop_dictionary_set_uint32(dict, "frequency", VEXPRESS_REF_FREQ); + return; + } +#endif +} Index: src/sys/arch/evbarm/vexpress/vexpress_plcom.c diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_plcom.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_plcom.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,194 @@ +/* $NetBSD: vexpress_plcom.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* Interface to plcom (PL011) serial driver. */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: vexpress_plcom.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/types.h> +#include <sys/device.h> +#include <sys/systm.h> +#include <sys/param.h> +#include <sys/termios.h> +#include <sys/bus.h> + +#include <evbarm/vexpress/platform.h> +#include <evbarm/vexpress/vexpress_var.h> + +#include <evbarm/dev/plcomreg.h> +#include <evbarm/dev/plcomvar.h> + +static int vexpress_plcom_match(device_t, cfdata_t, void *); +static void vexpress_plcom_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(vexpressplcom, sizeof(struct plcom_softc), + vexpress_plcom_match, vexpress_plcom_attach, NULL, NULL); + +static int +vexpress_plcom_match(device_t parent, cfdata_t cf, void *aux) +{ + struct axi_attach_args *aa = aux; + + if (strcmp(aa->aa_name, "plcom") != 0) + return 0; + + return 1; +} + +static void +vexpress_plcom_attach(device_t parent, device_t self, void *aux) +{ + struct plcom_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + void *ih; + + sc->sc_dev = self; + sc->sc_frequency = VEXPRESS_REF_FREQ; + sc->sc_hwflags = PLCOM_HW_TXFIFO_DISABLE; + sc->sc_swflags = 0; + sc->sc_set_mcr = NULL; + sc->sc_set_mcr_arg = NULL; + + sc->sc_pi.pi_type = PLCOM_TYPE_PL011; + sc->sc_pi.pi_flags = PLC_FLAG_32BIT_ACCESS; + sc->sc_pi.pi_iot = aa->aa_iot; + sc->sc_pi.pi_iobase = aa->aa_addr; + + if (bus_space_map(aa->aa_iot, aa->aa_addr, PL011COM_UART_SIZE, 0, + &sc->sc_pi.pi_ioh)) { + aprint_error_dev(sc->sc_dev, "unable to map device\n"); + return; + } + plcom_attach_subr(sc); + + ih = intr_establish(aa->aa_irq, IPL_SERIAL, IST_LEVEL_LOW, plcomintr, sc); + if (ih == NULL) + panic("%s: cannot install interrupt handler", + device_xname(sc->sc_dev)); +} +/* $NetBSD: vexpress_plcom.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* Interface to plcom (PL011) serial driver. */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: vexpress_plcom.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/types.h> +#include <sys/device.h> +#include <sys/systm.h> +#include <sys/param.h> +#include <sys/termios.h> +#include <sys/bus.h> + +#include <evbarm/vexpress/platform.h> +#include <evbarm/vexpress/vexpress_var.h> + +#include <evbarm/dev/plcomreg.h> +#include <evbarm/dev/plcomvar.h> + +static int vexpress_plcom_match(device_t, cfdata_t, void *); +static void vexpress_plcom_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(vexpressplcom, sizeof(struct plcom_softc), + vexpress_plcom_match, vexpress_plcom_attach, NULL, NULL); + +static int +vexpress_plcom_match(device_t parent, cfdata_t cf, void *aux) +{ + struct axi_attach_args *aa = aux; + + if (strcmp(aa->aa_name, "plcom") != 0) + return 0; + + return 1; +} + +static void +vexpress_plcom_attach(device_t parent, device_t self, void *aux) +{ + struct plcom_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + void *ih; + + sc->sc_dev = self; + sc->sc_frequency = VEXPRESS_REF_FREQ; + sc->sc_hwflags = PLCOM_HW_TXFIFO_DISABLE; + sc->sc_swflags = 0; + sc->sc_set_mcr = NULL; + sc->sc_set_mcr_arg = NULL; + + sc->sc_pi.pi_type = PLCOM_TYPE_PL011; + sc->sc_pi.pi_flags = PLC_FLAG_32BIT_ACCESS; + sc->sc_pi.pi_iot = aa->aa_iot; + sc->sc_pi.pi_iobase = aa->aa_addr; + + if (bus_space_map(aa->aa_iot, aa->aa_addr, PL011COM_UART_SIZE, 0, + &sc->sc_pi.pi_ioh)) { + aprint_error_dev(sc->sc_dev, "unable to map device\n"); + return; + } + plcom_attach_subr(sc); + + ih = intr_establish(aa->aa_irq, IPL_SERIAL, IST_LEVEL_LOW, plcomintr, sc); + if (ih == NULL) + panic("%s: cannot install interrupt handler", + device_xname(sc->sc_dev)); +} Index: src/sys/arch/evbarm/vexpress/vexpress_plmmc.c diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_plmmc.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_plmmc.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,182 @@ +/* $NetBSD: vexpress_plmmc.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* Interface to plmmc (PL181) MMC driver. */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: vexpress_plmmc.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/types.h> +#include <sys/device.h> +#include <sys/systm.h> +#include <sys/param.h> +#include <sys/malloc.h> + +#include <sys/termios.h> + +#include <machine/intr.h> +#include <sys/bus.h> + +#include <dev/ic/pl181reg.h> +#include <dev/ic/pl181var.h> + +#include <evbarm/vexpress/platform.h> +#include <evbarm/vexpress/vexpress_var.h> + +static int plmmc_vexpress_match(device_t, cfdata_t, void *); +static void plmmc_vexpress_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(vexpressplmmc, sizeof(struct plmmc_softc), + plmmc_vexpress_match, plmmc_vexpress_attach, NULL, NULL); + +static int +plmmc_vexpress_match(device_t parent, cfdata_t cf, void *aux) +{ + return 1; +} + +static void +plmmc_vexpress_attach(device_t parent, device_t self, void *aux) +{ + struct plmmc_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + void *ih; + + sc->sc_dev = self; + sc->sc_clock_freq = VEXPRESS_REF_FREQ; + sc->sc_bst = aa->aa_iot; + if (bus_space_map(aa->aa_iot, aa->aa_addr, 0x1000, 0, + &sc->sc_bsh)) { + printf("%s: unable to map device\n", device_xname(sc->sc_dev)); + return; + } + + aprint_naive("\n"); + aprint_normal("\n"); + + ih = intr_establish(aa->aa_irq, IPL_BIO, IST_LEVEL_LOW, plmmc_intr, sc); + if (ih == NULL) + panic("%s: cannot install interrupt handler", + device_xname(sc->sc_dev)); + plmmc_init(sc); +} + +/* $NetBSD: vexpress_plmmc.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* Interface to plmmc (PL181) MMC driver. */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: vexpress_plmmc.c,v 1.1 2015/02/09 07:47:15 slp Exp $"); + +#include <sys/types.h> +#include <sys/device.h> +#include <sys/systm.h> +#include <sys/param.h> +#include <sys/malloc.h> + +#include <sys/termios.h> + +#include <machine/intr.h> +#include <sys/bus.h> + +#include <dev/ic/pl181reg.h> +#include <dev/ic/pl181var.h> + +#include <evbarm/vexpress/platform.h> +#include <evbarm/vexpress/vexpress_var.h> + +static int plmmc_vexpress_match(device_t, cfdata_t, void *); +static void plmmc_vexpress_attach(device_t, device_t, void *); + +CFATTACH_DECL_NEW(vexpressplmmc, sizeof(struct plmmc_softc), + plmmc_vexpress_match, plmmc_vexpress_attach, NULL, NULL); + +static int +plmmc_vexpress_match(device_t parent, cfdata_t cf, void *aux) +{ + return 1; +} + +static void +plmmc_vexpress_attach(device_t parent, device_t self, void *aux) +{ + struct plmmc_softc *sc = device_private(self); + struct axi_attach_args *aa = aux; + void *ih; + + sc->sc_dev = self; + sc->sc_clock_freq = VEXPRESS_REF_FREQ; + sc->sc_bst = aa->aa_iot; + if (bus_space_map(aa->aa_iot, aa->aa_addr, 0x1000, 0, + &sc->sc_bsh)) { + printf("%s: unable to map device\n", device_xname(sc->sc_dev)); + return; + } + + aprint_naive("\n"); + aprint_normal("\n"); + + ih = intr_establish(aa->aa_irq, IPL_BIO, IST_LEVEL_LOW, plmmc_intr, sc); + if (ih == NULL) + panic("%s: cannot install interrupt handler", + device_xname(sc->sc_dev)); + plmmc_init(sc); +} + Index: src/sys/arch/evbarm/vexpress/vexpress_space.c diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_space.c:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_space.c Mon Feb 9 07:47:15 2015 @@ -0,0 +1,506 @@ +/* $NetBSD: vexpress_space.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* + * bus_space(9) support for Versatile Express AXI + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <uvm/uvm_extern.h> +#include <sys/bus.h> + +bs_protos(vexpress); +bs_protos(generic); +bs_protos(generic_armv4); +bs_protos(bs_notimpl); + +struct bus_space vexpress_bs_tag = { + /* cookie */ + (void *) 0, + + /* mapping/unmapping */ + vexpress_bs_map, + vexpress_bs_unmap, + vexpress_bs_subregion, + + /* allocation/deallocation */ + vexpress_bs_alloc, /* not implemented */ + vexpress_bs_free, /* not implemented */ + + /* get kernel virtual address */ + vexpress_bs_vaddr, + + /* mmap */ + bs_notimpl_bs_mmap, + + /* barrier */ + vexpress_bs_barrier, + + /* read (single) */ + generic_bs_r_1, + generic_armv4_bs_r_2, + generic_bs_r_4, + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + generic_armv4_bs_rm_2, + generic_bs_rm_4, + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + generic_armv4_bs_rr_2, + generic_bs_rr_4, + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + generic_armv4_bs_w_2, + generic_bs_w_4, + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + generic_armv4_bs_wm_2, + generic_bs_wm_4, + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + generic_armv4_bs_wr_2, + generic_bs_wr_4, + bs_notimpl_bs_wr_8, + + /* set multiple */ + bs_notimpl_bs_sm_1, + bs_notimpl_bs_sm_2, + bs_notimpl_bs_sm_4, + bs_notimpl_bs_sm_8, + + /* set region */ + generic_bs_sr_1, + generic_armv4_bs_sr_2, + bs_notimpl_bs_sr_4, + bs_notimpl_bs_sr_8, + + /* copy */ + bs_notimpl_bs_c_1, + generic_armv4_bs_c_2, + bs_notimpl_bs_c_4, + bs_notimpl_bs_c_8, + +#ifdef __BUS_SPACE_HAS_STREAM_METHODS + /* read (single) */ + generic_bs_r_1, + generic_armv4_bs_r_2, + generic_bs_r_4, + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + generic_armv4_bs_rm_2, + generic_bs_rm_4, + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + generic_armv4_bs_rr_2, + generic_bs_rr_4, + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + generic_armv4_bs_w_2, + generic_bs_w_4, + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + generic_armv4_bs_wm_2, + generic_bs_wm_4, + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + generic_armv4_bs_wr_2, + generic_bs_wr_4, + bs_notimpl_bs_wr_8, +#endif +}; + +int +vexpress_bs_map(void *t, bus_addr_t bpa, bus_size_t size, + int flag, bus_space_handle_t * bshp) +{ + const struct pmap_devmap *pd; + paddr_t startpa, endpa, pa; + vaddr_t va; + + if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { + /* Device was statically mapped. */ + *bshp = pd->pd_va + (bpa - pd->pd_pa); + return 0; + } + startpa = trunc_page(bpa); + endpa = round_page(bpa + size); + + /* XXX use extent manager to check duplicate mapping */ + + va = uvm_km_alloc(kernel_map, endpa - startpa, 0, + UVM_KMF_VAONLY | UVM_KMF_NOWAIT); + if (!va) + return (ENOMEM); + + *bshp = (bus_space_handle_t) (va + (bpa - startpa)); + + for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { + pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, + (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE); + } + pmap_update(pmap_kernel()); + + return (0); +} + +void +vexpress_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + vaddr_t va; + vsize_t sz; + + if (pmap_devmap_find_va(bsh, size) != NULL) { + /* Device was statically mapped; nothing to do. */ + return; + } + va = trunc_page(bsh); + sz = round_page(bsh + size) - va; + + pmap_kremove(va, sz); + pmap_update(pmap_kernel()); + uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); +} + + +int +vexpress_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t size, bus_space_handle_t * nbshp) +{ + + *nbshp = bsh + offset; + return (0); +} + +void +vexpress_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t len, int flags) +{ + + /* Nothing to do. */ +} + +void * +vexpress_bs_vaddr(void *t, bus_space_handle_t bsh) +{ + + return ((void *) bsh); +} + + +int +vexpress_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, + bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, + bus_addr_t * bpap, bus_space_handle_t * bshp) +{ + + panic("vexpress_io_bs_alloc(): not implemented\n"); +} + +void +vexpress_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + + panic("vexpress_io_bs_free(): not implemented\n"); +} +/* $NetBSD: vexpress_space.c,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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. + */ + +/* + * bus_space(9) support for Versatile Express AXI + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <uvm/uvm_extern.h> +#include <sys/bus.h> + +bs_protos(vexpress); +bs_protos(generic); +bs_protos(generic_armv4); +bs_protos(bs_notimpl); + +struct bus_space vexpress_bs_tag = { + /* cookie */ + (void *) 0, + + /* mapping/unmapping */ + vexpress_bs_map, + vexpress_bs_unmap, + vexpress_bs_subregion, + + /* allocation/deallocation */ + vexpress_bs_alloc, /* not implemented */ + vexpress_bs_free, /* not implemented */ + + /* get kernel virtual address */ + vexpress_bs_vaddr, + + /* mmap */ + bs_notimpl_bs_mmap, + + /* barrier */ + vexpress_bs_barrier, + + /* read (single) */ + generic_bs_r_1, + generic_armv4_bs_r_2, + generic_bs_r_4, + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + generic_armv4_bs_rm_2, + generic_bs_rm_4, + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + generic_armv4_bs_rr_2, + generic_bs_rr_4, + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + generic_armv4_bs_w_2, + generic_bs_w_4, + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + generic_armv4_bs_wm_2, + generic_bs_wm_4, + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + generic_armv4_bs_wr_2, + generic_bs_wr_4, + bs_notimpl_bs_wr_8, + + /* set multiple */ + bs_notimpl_bs_sm_1, + bs_notimpl_bs_sm_2, + bs_notimpl_bs_sm_4, + bs_notimpl_bs_sm_8, + + /* set region */ + generic_bs_sr_1, + generic_armv4_bs_sr_2, + bs_notimpl_bs_sr_4, + bs_notimpl_bs_sr_8, + + /* copy */ + bs_notimpl_bs_c_1, + generic_armv4_bs_c_2, + bs_notimpl_bs_c_4, + bs_notimpl_bs_c_8, + +#ifdef __BUS_SPACE_HAS_STREAM_METHODS + /* read (single) */ + generic_bs_r_1, + generic_armv4_bs_r_2, + generic_bs_r_4, + bs_notimpl_bs_r_8, + + /* read multiple */ + generic_bs_rm_1, + generic_armv4_bs_rm_2, + generic_bs_rm_4, + bs_notimpl_bs_rm_8, + + /* read region */ + generic_bs_rr_1, + generic_armv4_bs_rr_2, + generic_bs_rr_4, + bs_notimpl_bs_rr_8, + + /* write (single) */ + generic_bs_w_1, + generic_armv4_bs_w_2, + generic_bs_w_4, + bs_notimpl_bs_w_8, + + /* write multiple */ + generic_bs_wm_1, + generic_armv4_bs_wm_2, + generic_bs_wm_4, + bs_notimpl_bs_wm_8, + + /* write region */ + generic_bs_wr_1, + generic_armv4_bs_wr_2, + generic_bs_wr_4, + bs_notimpl_bs_wr_8, +#endif +}; + +int +vexpress_bs_map(void *t, bus_addr_t bpa, bus_size_t size, + int flag, bus_space_handle_t * bshp) +{ + const struct pmap_devmap *pd; + paddr_t startpa, endpa, pa; + vaddr_t va; + + if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { + /* Device was statically mapped. */ + *bshp = pd->pd_va + (bpa - pd->pd_pa); + return 0; + } + startpa = trunc_page(bpa); + endpa = round_page(bpa + size); + + /* XXX use extent manager to check duplicate mapping */ + + va = uvm_km_alloc(kernel_map, endpa - startpa, 0, + UVM_KMF_VAONLY | UVM_KMF_NOWAIT); + if (!va) + return (ENOMEM); + + *bshp = (bus_space_handle_t) (va + (bpa - startpa)); + + for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { + pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, + (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE); + } + pmap_update(pmap_kernel()); + + return (0); +} + +void +vexpress_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + vaddr_t va; + vsize_t sz; + + if (pmap_devmap_find_va(bsh, size) != NULL) { + /* Device was statically mapped; nothing to do. */ + return; + } + va = trunc_page(bsh); + sz = round_page(bsh + size) - va; + + pmap_kremove(va, sz); + pmap_update(pmap_kernel()); + uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); +} + + +int +vexpress_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t size, bus_space_handle_t * nbshp) +{ + + *nbshp = bsh + offset; + return (0); +} + +void +vexpress_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, + bus_size_t len, int flags) +{ + + /* Nothing to do. */ +} + +void * +vexpress_bs_vaddr(void *t, bus_space_handle_t bsh) +{ + + return ((void *) bsh); +} + + +int +vexpress_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, + bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, + bus_addr_t * bpap, bus_space_handle_t * bshp) +{ + + panic("vexpress_io_bs_alloc(): not implemented\n"); +} + +void +vexpress_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) +{ + + panic("vexpress_io_bs_free(): not implemented\n"); +} Index: src/sys/arch/evbarm/vexpress/vexpress_start.S diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_start.S:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_start.S Mon Feb 9 07:47:15 2015 @@ -0,0 +1,274 @@ +/* $NetBSD: vexpress_start.S,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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 "opt_cpuoptions.h" +#include "opt_cputypes.h" +#include "opt_multiprocessor.h" +#include "opt_arm_debug.h" + +#include <arm/asm.h> +#include <arm/armreg.h> +#include "assym.h" +#include "platform.h" + +RCSID("$NetBSD: vexpress_start.S,v 1.1 2015/02/09 07:47:15 slp 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) + +/* + * Kernel start routine for ODROID boards running on uboot firmware + * At this point, this code has been loaded into SDRAM + * and the MMU is off + */ + .section .start,"ax",%progbits + + .global _C_LABEL(vexpress_start) +_C_LABEL(vexpress_start): +#ifdef __ARMEB__ + setend be /* force big endian */ +#endif + /* Move into supervisor mode and disable IRQs/FIQs. */ + cpsid if, #PSR_SVC32_MODE + + XPUTC('a') + + bl cortex_init + + XPUTC('b') + + /* + * Set up a preliminary mapping in the MMU to allow us to run + * at KERNEL_BASE with caches on. + */ + adr r1, .Lmmu_init_table + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE + bl arm_boot_l1pt_init + + XPUTC('c') + + adr r11, xputc + movw lr, #:lower16:1f + movt lr, #:upper16:1f + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE + b arm_cpuinit + + .pushsection .text, "ax", %progbits + .align 0 + +1: + XPUTC2('d') + + b start + + .popsection + + .align 0 + .global xputc + .type xputc,%function +xputc: + movw r2, #0x0000 + movt r2, #0x1c09 + str r0, [r2] + bx lr + +#include <arm/cortex/a9_mpsubr.S> + + .align 0 +.Lmmu_init_table: + /* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable, shareable */ + MMU_INIT(KERNEL_BASE, KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) + +#if KERNEL_BASE_VOFFSET + /* Map physical addresses of kernel 1:1 PA:VA write-back cacheable, shareable */ + MMU_INIT(KERNEL_BASE - KERNEL_BASE_VOFFSET, + KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) +#endif + + /* Map VEXPRESS CORE (so console will work) */ + MMU_INIT(VEXPRESS_CORE_VBASE, VEXPRESS_CORE_PBASE, + VEXPRESS_CORE_SIZE / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* Map VEXPRESS CORE (so console will work) */ + MMU_INIT(VEXPRESS_CORE_PBASE, VEXPRESS_CORE_PBASE, + VEXPRESS_CORE_SIZE / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* end of table */ + MMU_INIT(0, 0, 0, 0) + + +END(vexpress_start) +/* $NetBSD: vexpress_start.S,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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 "opt_cpuoptions.h" +#include "opt_cputypes.h" +#include "opt_multiprocessor.h" +#include "opt_arm_debug.h" + +#include <arm/asm.h> +#include <arm/armreg.h> +#include "assym.h" +#include "platform.h" + +RCSID("$NetBSD: vexpress_start.S,v 1.1 2015/02/09 07:47:15 slp 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) + +/* + * Kernel start routine for ODROID boards running on uboot firmware + * At this point, this code has been loaded into SDRAM + * and the MMU is off + */ + .section .start,"ax",%progbits + + .global _C_LABEL(vexpress_start) +_C_LABEL(vexpress_start): +#ifdef __ARMEB__ + setend be /* force big endian */ +#endif + /* Move into supervisor mode and disable IRQs/FIQs. */ + cpsid if, #PSR_SVC32_MODE + + XPUTC('a') + + bl cortex_init + + XPUTC('b') + + /* + * Set up a preliminary mapping in the MMU to allow us to run + * at KERNEL_BASE with caches on. + */ + adr r1, .Lmmu_init_table + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE + bl arm_boot_l1pt_init + + XPUTC('c') + + adr r11, xputc + movw lr, #:lower16:1f + movt lr, #:upper16:1f + movw r0, #:lower16:TEMP_L1_TABLE + movt r0, #:upper16:TEMP_L1_TABLE + b arm_cpuinit + + .pushsection .text, "ax", %progbits + .align 0 + +1: + XPUTC2('d') + + b start + + .popsection + + .align 0 + .global xputc + .type xputc,%function +xputc: + movw r2, #0x0000 + movt r2, #0x1c09 + str r0, [r2] + bx lr + +#include <arm/cortex/a9_mpsubr.S> + + .align 0 +.Lmmu_init_table: + /* Map KERNEL_BASE VA to SDRAM PA, write-back cacheable, shareable */ + MMU_INIT(KERNEL_BASE, KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) + +#if KERNEL_BASE_VOFFSET + /* Map physical addresses of kernel 1:1 PA:VA write-back cacheable, shareable */ + MMU_INIT(KERNEL_BASE - KERNEL_BASE_VOFFSET, + KERNEL_BASE - KERNEL_BASE_VOFFSET, INIT_MEMSIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_CACHEABLE) +#endif + + /* Map VEXPRESS CORE (so console will work) */ + MMU_INIT(VEXPRESS_CORE_VBASE, VEXPRESS_CORE_PBASE, + VEXPRESS_CORE_SIZE / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* Map VEXPRESS CORE (so console will work) */ + MMU_INIT(VEXPRESS_CORE_PBASE, VEXPRESS_CORE_PBASE, + VEXPRESS_CORE_SIZE / L1_S_SIZE, + L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN) + + /* end of table */ + MMU_INIT(0, 0, 0, 0) + + +END(vexpress_start) Index: src/sys/arch/evbarm/vexpress/vexpress_var.h diff -u /dev/null src/sys/arch/evbarm/vexpress/vexpress_var.h:1.1 --- /dev/null Mon Feb 9 07:47:15 2015 +++ src/sys/arch/evbarm/vexpress/vexpress_var.h Mon Feb 9 07:47:15 2015 @@ -0,0 +1,96 @@ +/* $NetBSD: vexpress_var.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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/types.h> +#include <sys/bus.h> + +struct axi_attach_args { + const char *aa_name; + bus_space_tag_t aa_iot; + bus_dma_tag_t aa_dmat; + bus_addr_t aa_addr; + bus_size_t aa_size; + int aa_irq; + int aa_irqbase; +}; + +extern struct bus_space vexpress_bs_tag; +extern struct arm32_bus_dma_tag vexpress_bus_dma_tag; +extern bus_space_tag_t vexpress_armcore_bst; +extern bus_space_handle_t vexpress_armcore_bsh; +/* $NetBSD: vexpress_var.h,v 1.1 2015/02/09 07:47:15 slp Exp $ */ + +/*- + * Copyright (c) 2015 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Sergio L. Pascual. + * + * 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 NETBSD FOUNDATION, 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 FOUNDATION 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/types.h> +#include <sys/bus.h> + +struct axi_attach_args { + const char *aa_name; + bus_space_tag_t aa_iot; + bus_dma_tag_t aa_dmat; + bus_addr_t aa_addr; + bus_size_t aa_size; + int aa_irq; + int aa_irqbase; +}; + +extern struct bus_space vexpress_bs_tag; +extern struct arm32_bus_dma_tag vexpress_bus_dma_tag; +extern bus_space_tag_t vexpress_armcore_bst; +extern bus_space_handle_t vexpress_armcore_bsh;