Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Add support for QEMU ARM Virtual Machine ("virt").



details:   https://anonhg.NetBSD.org/src/rev/2e99faaa1cbf
branches:  trunk
changeset: 323414:2e99faaa1cbf
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Thu Jun 14 10:56:39 2018 +0000

description:
Add support for QEMU ARM Virtual Machine ("virt").

diffstat:

 sys/arch/arm/virt/files.virt         |    9 +
 sys/arch/arm/virt/virt_platform.c    |  130 +++++++++++++++++++++++++
 sys/arch/arm/virt/virt_platform.h    |   40 +++++++
 sys/arch/evbarm/conf/GENERIC64       |    4 +-
 sys/arch/evbarm/conf/VIRT            |   56 +++++++++++
 sys/arch/evbarm/conf/files.generic64 |    3 +-
 sys/arch/evbarm/conf/files.virt      |   19 +++
 sys/arch/evbarm/conf/mk.virt         |   35 ++++++
 sys/arch/evbarm/conf/std.virt        |   36 +++++++
 sys/arch/evbarm/virt/virt_start.S    |  178 +++++++++++++++++++++++++++++++++++
 10 files changed, 508 insertions(+), 2 deletions(-)

diffs (truncated from 575 to 300 lines):

diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/arm/virt/files.virt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/virt/files.virt      Thu Jun 14 10:56:39 2018 +0000
@@ -0,0 +1,9 @@
+#      $NetBSD: files.virt,v 1.1 2018/06/14 10:56:39 jmcneill Exp $
+#
+# Configuration info for QEMU virtual boards.
+#
+#
+
+file   arch/arm/virt/virt_platform.c           soc_virt
+
+defflag        opt_soc.h                               SOC_VIRT
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/arm/virt/virt_platform.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/virt/virt_platform.c Thu Jun 14 10:56:39 2018 +0000
@@ -0,0 +1,130 @@
+/* $NetBSD: virt_platform.c,v 1.1 2018/06/14 10:56:39 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * 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_soc.h"
+#include "opt_multiprocessor.h"
+#include "opt_fdt_arm.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: virt_platform.c,v 1.1 2018/06/14 10:56:39 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 <arm/fdt/arm_fdtvar.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/bootconfig.h>
+#include <arm/cpufunc.h>
+
+#include <evbarm/dev/plcomreg.h>
+#include <evbarm/dev/plcomvar.h>
+
+#include <dev/ic/ns16550reg.h>
+#include <dev/ic/comreg.h>
+
+#include <arm/cortex/gtmr_var.h>
+
+#include <arm/arm/psci.h>
+#include <arm/fdt/psci_fdt.h>
+
+#include <arm/virt/virt_platform.h>
+
+#define        VIRT_UART_BASE  0x09000000
+
+static const struct pmap_devmap *
+virt_platform_devmap(void)
+{
+       static const struct pmap_devmap devmap[] = {
+               DEVMAP_ENTRY(VIRT_CORE_VBASE,
+                            VIRT_CORE_PBASE,
+                            VIRT_CORE_SIZE),
+               DEVMAP_ENTRY_END
+       };
+
+       return devmap;
+}
+
+static void
+virt_platform_init_attach_args(struct fdt_attach_args *faa)
+{
+       extern struct arm32_bus_dma_tag arm_generic_dma_tag;
+       extern struct bus_space arm_generic_bs_tag;
+       extern struct bus_space arm_generic_a4x_bs_tag;
+
+       faa->faa_bst = &arm_generic_bs_tag;
+       faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
+       faa->faa_dmat = &arm_generic_dma_tag;
+}
+
+void virt_platform_early_putchar(char);
+
+void
+virt_platform_early_putchar(char c)
+{
+       volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ?
+               (volatile uint32_t *)VIRT_CORE_PTOV(VIRT_UART_BASE) :
+               (volatile uint32_t *)VIRT_UART_BASE;
+
+       while ((uartaddr[PL01XCOM_FR / 4] & PL01X_FR_TXFF) != 0)
+               continue;
+
+       uartaddr[PL01XCOM_DR / 4] = c;
+
+       while ((uartaddr[PL01XCOM_FR / 4] & PL01X_FR_TXFE) == 0)
+               continue;
+}
+
+static void
+virt_platform_device_register(device_t self, void *aux)
+{
+}
+
+static u_int
+virt_platform_uart_freq(void)
+{
+       return 24000000;
+}
+
+static const struct arm_platform virt_platform = {
+       .devmap = virt_platform_devmap,
+       .bootstrap = psci_fdt_bootstrap,
+       .init_attach_args = virt_platform_init_attach_args,
+       .early_putchar = virt_platform_early_putchar,
+       .device_register = virt_platform_device_register,
+       .reset = psci_fdt_reset,
+       .delay = gtmr_delay,
+       .uart_freq = virt_platform_uart_freq,
+};
+
+ARM_PLATFORM(virt, "linux,dummy-virt", &virt_platform);
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/arm/virt/virt_platform.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/virt/virt_platform.h Thu Jun 14 10:56:39 2018 +0000
@@ -0,0 +1,40 @@
+/* $NetBSD: virt_platform.h,v 1.1 2018/06/14 10:56:39 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * 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.
+ */
+
+#ifndef _ARM_VIRT_PLATFORM_H
+#define _ARM_VIRT_PLATFORM_H
+
+#include <arch/evbarm/fdt/platform.h>
+
+#define        VIRT_CORE_VBASE         KERNEL_IO_VBASE
+#define        VIRT_CORE_PBASE         0x00000000
+#define        VIRT_CORE_SIZE          0x10000000
+
+#define        VIRT_CORE_PTOV(p)       (((p) - VIRT_CORE_PBASE) + VIRT_CORE_VBASE)
+
+#endif /* _ARM_VIRT_PLATFORM_H */
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/evbarm/conf/GENERIC64
--- a/sys/arch/evbarm/conf/GENERIC64    Thu Jun 14 10:53:39 2018 +0000
+++ b/sys/arch/evbarm/conf/GENERIC64    Thu Jun 14 10:56:39 2018 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: GENERIC64,v 1.15 2018/05/10 00:05:22 jmcneill Exp $
+#      $NetBSD: GENERIC64,v 1.16 2018/06/14 10:56:39 jmcneill Exp $
 #
 #      GENERIC ARM (aarch64) kernel
 #
@@ -49,6 +49,7 @@
 options        SOC_SUN50I_A64
 options        SOC_SUN50I_H5
 options        SOC_SUN50I_H6
+options        SOC_VIRT
 #options       MULTIPROCESSOR
 
 pseudo-device  openfirm        # /dev/openfirm
@@ -63,6 +64,7 @@
 #options       EARLYCONS=bcm2837
 #options       EARLYCONS=sunxi, CONSADDR=0x01c28000
 #options       EARLYCONS=tegra, CONSADDR=0x70006000
+#options       EARLYCONS=virt
 
 makeoptions    DEBUG="-g"      # compile full symbol table
 makeoptions    COPY_SYMTAB=1
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/evbarm/conf/VIRT
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbarm/conf/VIRT Thu Jun 14 10:56:39 2018 +0000
@@ -0,0 +1,56 @@
+#
+#      $NetBSD: VIRT,v 1.1 2018/06/14 10:56:39 jmcneill Exp $
+#
+#      QEMU ARM 'virt' virtual machine
+#
+
+include        "arch/evbarm/conf/std.virt"
+include        "arch/evbarm/conf/GENERIC.common"
+
+options        CPU_CORTEXA15
+options        SOC_VIRT
+options        MULTIPROCESSOR
+
+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 bootstrapping messages
+
+makeoptions    DEBUG="-g"      # compile full symbol table
+makeoptions    COPY_SYMTAB=1
+
+config         netbsd          root on ? type ?
+
+# 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
+
+# Power state coordination interface
+psci*          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?
+
+# UART
+plcom*         at fdt?                 # ARM PL011 UART
+
+# RTC
+plrtc*         at fdt?                 # ARM PrimeCell RTC
+
+cinclude "arch/evbarm/conf/VIRT.local"
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/evbarm/conf/files.generic64
--- a/sys/arch/evbarm/conf/files.generic64      Thu Jun 14 10:53:39 2018 +0000
+++ b/sys/arch/evbarm/conf/files.generic64      Thu Jun 14 10:56:39 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.generic64,v 1.1 2018/04/01 04:35:04 ryo Exp $
+#      $NetBSD: files.generic64,v 1.2 2018/06/14 10:56:39 jmcneill Exp $
 #
 
 defparam opt_arm_debug.h       EARLYCONS
@@ -13,3 +13,4 @@
 include "arch/arm/broadcom/files.bcm2835"
 include "arch/arm/nvidia/files.tegra"
 include "arch/arm/sunxi/files.sunxi"
+include "arch/arm/virt/files.virt"
diff -r 84ec422cff8b -r 2e99faaa1cbf sys/arch/evbarm/conf/files.virt
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/evbarm/conf/files.virt   Thu Jun 14 10:56:39 2018 +0000
@@ -0,0 +1,19 @@
+#      $NetBSD: files.virt,v 1.1 2018/06/14 10:56:39 jmcneill Exp $
+#
+# QEMU 'virt' machine configuration info
+#
+



Home | Main Index | Thread Index | Old Index