Skip to content

Instantly share code, notes, and snippets.

@enukane
Created July 29, 2012 17:48
Show Gist options
  • Save enukane/3200560 to your computer and use it in GitHub Desktop.
Save enukane/3200560 to your computer and use it in GitHub Desktop.
WIP: host-side virtio-9p mock device
Index: usr.sbin/bhyve/Makefile
===================================================================
--- usr.sbin/bhyve/Makefile (revision 238860)
+++ usr.sbin/bhyve/Makefile (working copy)
@@ -8,6 +8,7 @@
SRCS+= instruction_emul.c mevent.c
SRCS+= pci_emul.c pci_hostbridge.c pci_passthru.c pci_virtio_block.c
SRCS+= pci_virtio_net.c pci_uart.c pit_8254.c post.c rtc.c uart.c xmsr.c
+SRCS+= pci_virtio_9p.c
NO_MAN=
Index: usr.sbin/bhyve/pci_virtio_9p.c
===================================================================
--- usr.sbin/bhyve/pci_virtio_9p.c (revision 0)
+++ usr.sbin/bhyve/pci_virtio_9p.c (working copy)
@@ -0,0 +1,98 @@
+/*-
+ * Copyright (c) 2011 NetApp, Inc.
+ * 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 NETAPP, INC ``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 NETAPP, INC 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/linker_set.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <sys/ioctl.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <assert.h>
+#include <pthread.h>
+
+#include "fbsdrun.h"
+#include "pci_emul.h"
+#include "virtio.h"
+
+static int
+pci_vt9p_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts)
+{
+ printf("%u %s : opts = %s\n", __LINE__, __func__, opts);
+
+ /* initialize config space */
+ pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_9P);
+ pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR);
+ pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE);
+ pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_9P);
+ pci_emul_alloc_bar(pi, 0, 0, PCIBAR_IO, 10);
+
+ return 0;
+}
+
+static void
+pci_vt9p_write(struct pci_devinst *pi, int baridx,
+ int offset, int size, uint32_t value)
+{
+ printf("%u %s : baridx=%d, offset=%d, size=%d, value=%u\n",
+ __LINE__, __func__,
+ baridx,
+ offset,
+ size,
+ value);
+}
+
+static uint32_t
+pci_vt9p_read(struct pci_devinst *pi, int baridx, int offset, int size)
+{
+ printf("%u %s : baridx=%d, offset=%d, size=%d\n",
+ __LINE__, __func__,
+ baridx,
+ offset,
+ size);
+ return 0;
+}
+
+struct pci_devemu pci_de_9p = {
+ .pe_emu = "virtio-9p",
+ .pe_init = pci_vt9p_init,
+ .pe_iow = pci_vt9p_write,
+ .pe_ior = pci_vt9p_read,
+};
+
+PCI_EMUL_SET(pci_de_9p);
Index: usr.sbin/bhyve/virtio.h
===================================================================
--- usr.sbin/bhyve/virtio.h (revision 238860)
+++ usr.sbin/bhyve/virtio.h (working copy)
@@ -59,6 +59,7 @@
*/
#define VIRTIO_TYPE_NET 1
#define VIRTIO_TYPE_BLOCK 2
+#define VIRTIO_TYPE_9P 9
/*
* PCI vendor/device IDs
@@ -66,6 +67,7 @@
#define VIRTIO_VENDOR 0x1AF4
#define VIRTIO_DEV_NET 0x1000
#define VIRTIO_DEV_BLOCK 0x1001
+#define VIRTIO_DEV_9P 0x1009
/*
* PCI config space constants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment