Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/alpha Add a "qemu" driver to access services provid...



details:   https://anonhg.NetBSD.org/src/rev/b22d62a9fe92
branches:  trunk
changeset: 976618:b22d62a9fe92
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Sep 27 23:59:37 2020 +0000

description:
Add a "qemu" driver to access services provided by the Qemu VM.  First
order of business is to use the Qemu "get-time" console service call as
the perferred system timecounter.

diffstat:

 sys/arch/alpha/alpha/mainbus.c  |   11 +++-
 sys/arch/alpha/alpha/qemu.c     |  104 ++++++++++++++++++++++++++++++++++++++++
 sys/arch/alpha/conf/GENERIC     |    5 +-
 sys/arch/alpha/conf/files.alpha |    6 +-
 4 files changed, 121 insertions(+), 5 deletions(-)

diffs (193 lines):

diff -r 20d5fec7395d -r b22d62a9fe92 sys/arch/alpha/alpha/mainbus.c
--- a/sys/arch/alpha/alpha/mainbus.c    Sun Sep 27 23:56:25 2020 +0000
+++ b/sys/arch/alpha/alpha/mainbus.c    Sun Sep 27 23:59:37 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.33 2012/02/06 02:14:12 matt Exp $ */
+/* $NetBSD: mainbus.c,v 1.34 2020/09/27 23:59:37 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.33 2012/02/06 02:14:12 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.34 2020/09/27 23:59:37 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -37,6 +37,7 @@
 #include <sys/reboot.h>
 #include <sys/conf.h>
 
+#include <machine/alpha.h>
 #include <machine/autoconf.h>
 #include <machine/rpb.h>
 #include <machine/cpuconf.h>
@@ -91,6 +92,12 @@
                printf("WARNING: %d cpus in machine, %d attached\n",
                        ncpus, cpuattachcnt);
 
+       if (alpha_is_qemu) {
+               ma.ma_name = "qemu";
+               ma.ma_slot = 0;                 /* meaningless */
+               config_found(self, &ma, mbprint);
+       }
+
        if (platform.iobus != NULL) {
                ma.ma_name = platform.iobus;
                ma.ma_slot = 0;                 /* meaningless */
diff -r 20d5fec7395d -r b22d62a9fe92 sys/arch/alpha/alpha/qemu.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/alpha/alpha/qemu.c       Sun Sep 27 23:59:37 2020 +0000
@@ -0,0 +1,104 @@
+/* $NetBSD: qemu.c,v 1.1 2020/09/27 23:59:37 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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>                 /* RCS ID & Copyright macro defns */
+
+__KERNEL_RCSID(0, "$NetBSD");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/time.h>
+#include <sys/timetc.h>
+#include <sys/cpu.h>
+
+#include <machine/autoconf.h>
+#include <machine/rpb.h>
+#include <machine/alpha.h>
+
+extern struct cfdriver qemu_cd;
+
+struct qemu_softc {
+       device_t        sc_dev;
+
+       struct timecounter sc_tc;
+};
+
+static u_int
+qemu_get_timecount(struct timecounter * const tc __unused)
+{
+       register unsigned long v0 __asm("$0");
+       register unsigned long a0 __asm("$16") = 7;     /* Qemu get-time */
+       
+       __asm volatile ("call_pal %2"
+               : "=r"(v0), "+r"(a0)
+               : "i"(PAL_cserve)
+               : "$17", "$18", "$19", "$20", "$21");
+
+       return (u_int)v0;
+}
+
+static int
+qemu_match(device_t parent, cfdata_t cfdata, void *aux)
+{
+       struct mainbus_attach_args *ma = aux;
+
+       if (strcmp(ma->ma_name, qemu_cd.cd_name) != 0)
+               return (0);
+
+       return (1);
+}
+
+static void
+qemu_attach(device_t parent, device_t self, void *aux)
+{
+       struct qemu_softc * const sc = device_private(self);
+       struct timecounter * const tc = &sc->sc_tc;
+
+       sc->sc_dev = self;
+
+       aprint_normal(": Qemu virtual machine services\n");
+       aprint_naive("\n");
+
+       /*
+        * Use the Qemu "VM time" hypercall as the system timecounter.
+        */
+       tc->tc_name = "Qemu";
+       tc->tc_get_timecount = qemu_get_timecount;
+       tc->tc_quality = 3000;
+       tc->tc_counter_mask = __BITS(0,31);
+       tc->tc_frequency = 1000000000UL;        /* nanosecond granularity */
+       tc->tc_priv = sc;
+       tc_init(tc);
+}
+
+CFATTACH_DECL_NEW(qemu, sizeof(struct qemu_softc),
+    qemu_match, qemu_attach, NULL, NULL);
diff -r 20d5fec7395d -r b22d62a9fe92 sys/arch/alpha/conf/GENERIC
--- a/sys/arch/alpha/conf/GENERIC       Sun Sep 27 23:56:25 2020 +0000
+++ b/sys/arch/alpha/conf/GENERIC       Sun Sep 27 23:59:37 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.408 2020/09/27 13:48:49 roy Exp $
+# $NetBSD: GENERIC,v 1.409 2020/09/27 23:59:37 thorpej Exp $
 #
 # This machine description file is used to generate the default NetBSD
 # kernel.
@@ -19,7 +19,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-ident          "GENERIC-$Revision: 1.408 $"
+ident          "GENERIC-$Revision: 1.409 $"
 
 maxusers 32
 
@@ -185,6 +185,7 @@
 
 mainbus0 at    root
 cpu*   at      mainbus0
+qemu*  at      mainbus0
 
 # TurboLaser bus support and devices
 tlsb*  at      mainbus0
diff -r 20d5fec7395d -r b22d62a9fe92 sys/arch/alpha/conf/files.alpha
--- a/sys/arch/alpha/conf/files.alpha   Sun Sep 27 23:56:25 2020 +0000
+++ b/sys/arch/alpha/conf/files.alpha   Sun Sep 27 23:59:37 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.alpha,v 1.191 2019/08/21 04:17:40 msaitoh Exp $
+# $NetBSD: files.alpha,v 1.192 2020/09/27 23:59:37 thorpej Exp $
 #
 # alpha-specific configuration info
 
@@ -55,6 +55,10 @@
 attach cpu at mainbus
 file   arch/alpha/alpha/cpu.c          cpu
 
+device qemu
+attach qemu at mainbus
+file   arch/alpha/alpha/qemu.c         qemu
+
 #
 # Machine-independent I2O drivers.
 #



Home | Main Index | Thread Index | Old Index