Module Name:    src
Committed By:   thorpej
Date:           Sun Sep 27 23:59:37 UTC 2020

Modified Files:
        src/sys/arch/alpha/alpha: mainbus.c
        src/sys/arch/alpha/conf: GENERIC files.alpha
Added Files:
        src/sys/arch/alpha/alpha: qemu.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/alpha/alpha/mainbus.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/alpha/alpha/qemu.c
cvs rdiff -u -r1.408 -r1.409 src/sys/arch/alpha/conf/GENERIC
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/alpha/conf/files.alpha

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/mainbus.c
diff -u src/sys/arch/alpha/alpha/mainbus.c:1.33 src/sys/arch/alpha/alpha/mainbus.c:1.34
--- src/sys/arch/alpha/alpha/mainbus.c:1.33	Mon Feb  6 02:14:12 2012
+++ src/sys/arch/alpha/alpha/mainbus.c	Sun Sep 27 23:59:37 2020
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 
 #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 @@ mbattach(device_t parent, device_t self,
 		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 */

Index: src/sys/arch/alpha/conf/GENERIC
diff -u src/sys/arch/alpha/conf/GENERIC:1.408 src/sys/arch/alpha/conf/GENERIC:1.409
--- src/sys/arch/alpha/conf/GENERIC:1.408	Sun Sep 27 13:48:49 2020
+++ src/sys/arch/alpha/conf/GENERIC	Sun Sep 27 23:59:37 2020
@@ -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 @@ include 	"arch/alpha/conf/std.alpha"
 
 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 @@ config		netbsd	root on ? type ?
 
 mainbus0 at	root
 cpu*	at	mainbus0
+qemu*	at	mainbus0
 
 # TurboLaser bus support and devices
 tlsb*	at	mainbus0

Index: src/sys/arch/alpha/conf/files.alpha
diff -u src/sys/arch/alpha/conf/files.alpha:1.191 src/sys/arch/alpha/conf/files.alpha:1.192
--- src/sys/arch/alpha/conf/files.alpha:1.191	Wed Aug 21 04:17:40 2019
+++ src/sys/arch/alpha/conf/files.alpha	Sun Sep 27 23:59:37 2020
@@ -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 @@ device	cpu { }				# not really optional
 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.
 #

Added files:

Index: src/sys/arch/alpha/alpha/qemu.c
diff -u /dev/null src/sys/arch/alpha/alpha/qemu.c:1.1
--- /dev/null	Sun Sep 27 23:59:37 2020
+++ src/sys/arch/alpha/alpha/qemu.c	Sun Sep 27 23:59:37 2020
@@ -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);

Reply via email to