summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/amd64/conf/GENERIC5
-rw-r--r--sys/arch/i386/conf/GENERIC3
-rw-r--r--sys/dev/pci/files.pci6
-rw-r--r--sys/dev/pci/virtio_pci.c5
-rw-r--r--sys/dev/pci/virtioreg.h3
-rw-r--r--sys/dev/pci/vmmci.c121
6 files changed, 137 insertions, 6 deletions
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC
index 0895ebad348..ac06ef25676 100644
--- a/sys/arch/amd64/conf/GENERIC
+++ b/sys/arch/amd64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.438 2017/01/10 11:41:32 jsg Exp $
+# $OpenBSD: GENERIC,v 1.439 2017/01/13 14:37:32 reyk Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -654,4 +654,5 @@ vio* at virtio? # Virtio network device
viomb* at virtio? # Virtio memory ballooning device
viornd* at virtio? # Virtio entropy device
vioscsi* at virtio? # Virtio SCSI device
-#viocon* at virtio? # Virtio console device
+#viocon* at virtio? # Virtio console device
+#vmmci* at virtio? # VMM control interface
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index 9e3d2a265be..1a5b23aa312 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.824 2016/10/21 06:20:58 mlarkin Exp $
+# $OpenBSD: GENERIC,v 1.825 2017/01/13 14:37:32 reyk Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -769,3 +769,4 @@ vio* at virtio? # Virtio network device
viomb* at virtio? # Virtio memory ballooning device
viornd* at virtio? # Virtio entropy device
vioscsi* at virtio? # Virtio SCSI device
+#vmmci* at virtio? # VMM control interface
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci
index 78968b0a84b..7bd0d9688ad 100644
--- a/sys/dev/pci/files.pci
+++ b/sys/dev/pci/files.pci
@@ -1,4 +1,4 @@
-# $OpenBSD: files.pci,v 1.327 2016/11/24 17:39:49 mikeb Exp $
+# $OpenBSD: files.pci,v 1.328 2017/01/13 14:37:32 reyk Exp $
# $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $
#
# Config file and device description for machine-independent PCI code.
@@ -834,5 +834,9 @@ device vioscsi: scsi
attach vioscsi at virtio
file dev/pci/vioscsi.c vioscsi
+device vmmci
+attach vmmci at virtio
+file dev/pci/vmmci.c vmmci
+
include "dev/pci/files.agp"
include "dev/pci/drm/files.drm"
diff --git a/sys/dev/pci/virtio_pci.c b/sys/dev/pci/virtio_pci.c
index fbd5a38ea73..1038342924b 100644
--- a/sys/dev/pci/virtio_pci.c
+++ b/sys/dev/pci/virtio_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtio_pci.c,v 1.15 2016/07/19 02:51:09 sf Exp $ */
+/* $OpenBSD: virtio_pci.c,v 1.16 2017/01/13 14:37:32 reyk Exp $ */
/* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */
/*
@@ -180,6 +180,9 @@ virtio_pci_match(struct device *parent, void *match, void *aux)
PCI_PRODUCT(pa->pa_id) <= 0x103f &&
PCI_REVISION(pa->pa_class) == 0)
return 1;
+ if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_OPENBSD &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_OPENBSD_CONTROL)
+ return 1;
return 0;
}
diff --git a/sys/dev/pci/virtioreg.h b/sys/dev/pci/virtioreg.h
index b74e44c3230..581615c0692 100644
--- a/sys/dev/pci/virtioreg.h
+++ b/sys/dev/pci/virtioreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: virtioreg.h,v 1.3 2016/07/16 12:07:21 sf Exp $ */
+/* $OpenBSD: virtioreg.h,v 1.4 2017/01/13 14:37:32 reyk Exp $ */
/* $NetBSD: virtioreg.h,v 1.1 2011/10/30 12:12:21 hannken Exp $ */
/*
@@ -80,6 +80,7 @@
#define PCI_PRODUCT_VIRTIO_SCSI 8
#define PCI_PRODUCT_VIRTIO_9P 9
#define PCI_PRODUCT_VIRTIO_MAC80211 10
+#define PCI_PRODUCT_VIRTIO_VMMCI 65535 /* private id */
/* Virtio header */
#define VIRTIO_CONFIG_DEVICE_FEATURES 0 /* 32bit */
diff --git a/sys/dev/pci/vmmci.c b/sys/dev/pci/vmmci.c
new file mode 100644
index 00000000000..23f86c5e4ea
--- /dev/null
+++ b/sys/dev/pci/vmmci.c
@@ -0,0 +1,121 @@
+/* $OpenBSD: vmmci.c,v 1.1 2017/01/13 14:37:32 reyk Exp $ */
+
+/*
+ * Copyright (c) 2017 Reyk Floeter <reyk@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/timeout.h>
+#include <sys/signalvar.h>
+#include <sys/syslog.h>
+#include <sys/device.h>
+#include <sys/pool.h>
+#include <sys/proc.h>
+
+#include <machine/bus.h>
+
+#include <dev/pci/virtioreg.h>
+#include <dev/pci/virtiovar.h>
+#include <dev/pv/pvvar.h>
+#include <dev/rndvar.h>
+
+enum vmmci_cmd {
+ VMMCI_NONE = 0,
+ VMMCI_SHUTDOWN,
+ VMMCI_REBOOT,
+};
+
+struct vmmci_softc {
+ struct device sc_dev;
+ struct virtio_softc *sc_virtio;
+ enum vmmci_cmd sc_cmd;
+ unsigned int sc_interval;
+ struct timeout sc_tick;
+};
+
+int vmmci_match(struct device *, void *, void *);
+void vmmci_attach(struct device *, struct device *, void *);
+
+int vmmci_config_change(struct virtio_softc *);
+
+struct cfattach vmmci_ca = {
+ sizeof(struct vmmci_softc),
+ vmmci_match,
+ vmmci_attach,
+ NULL
+};
+
+struct cfdriver vmmci_cd = {
+ NULL, "vmmci", DV_DULL
+};
+
+int
+vmmci_match(struct device *parent, void *match, void *aux)
+{
+ struct virtio_softc *va = aux;
+ if (va->sc_childdevid == PCI_PRODUCT_VIRTIO_VMMCI)
+ return (1);
+ return (0);
+}
+
+void
+vmmci_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct vmmci_softc *sc = (struct vmmci_softc *)self;
+ struct virtio_softc *vsc = (struct virtio_softc *)parent;
+
+ if (vsc->sc_child != NULL)
+ panic("already attached to something else");
+
+ vsc->sc_child = self;
+ vsc->sc_nvqs = 0;
+ vsc->sc_config_change = vmmci_config_change;
+ vsc->sc_ipl = IPL_NET;
+ sc->sc_virtio = vsc;
+
+ virtio_negotiate_features(vsc, 0, NULL);
+
+ printf("\n");
+}
+
+int
+vmmci_config_change(struct virtio_softc *vsc)
+{
+ struct vmmci_softc *sc = (struct vmmci_softc *)vsc->sc_child;
+ int cmd = virtio_read_device_config_1(vsc, 0);
+
+ if (cmd == sc->sc_cmd)
+ return (0);
+ sc->sc_cmd = cmd;
+
+ switch (cmd) {
+ case VMMCI_NONE:
+ /* no action */
+ break;
+ case VMMCI_SHUTDOWN:
+ pvbus_shutdown(&sc->sc_dev);
+ break;
+ case VMMCI_REBOOT:
+ pvbus_reboot(&sc->sc_dev);
+ break;
+ default:
+ printf("%s: invalid command %d\n", sc->sc_dev.dv_xname, cmd);
+ break;
+ }
+
+ return (1);
+}