summaryrefslogtreecommitdiff
path: root/usr/src/lib/libvmmapi
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libvmmapi')
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.c61
-rw-r--r--usr/src/lib/libvmmapi/common/vmmapi.h4
2 files changed, 45 insertions, 20 deletions
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.c b/usr/src/lib/libvmmapi/common/vmmapi.c
index bae214aba0..b4c96d5455 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.c
+++ b/usr/src/lib/libvmmapi/common/vmmapi.c
@@ -47,7 +47,11 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
+#ifdef __FreeBSD__
+#include <sys/linker.h>
+#endif
#include <sys/mman.h>
+#include <sys/module.h>
#include <sys/_iovec.h>
#include <sys/cpuset.h>
@@ -156,7 +160,11 @@ vm_device_open(const char *name)
int
vm_create(const char *name)
{
-
+#ifdef __FreeBSD__
+ /* Try to load vmm(4) module before creating a guest. */
+ if (modfind("vmm") < 0)
+ kldload("vmm");
+#endif
return (CREATE((char *)name));
}
@@ -898,6 +906,25 @@ vm_ioapic_pincount(struct vmctx *ctx, int *pincount)
}
int
+vm_readwrite_kernemu_device(struct vmctx *ctx, int vcpu, vm_paddr_t gpa,
+ bool write, int size, uint64_t *value)
+{
+ struct vm_readwrite_kernemu_device irp = {
+ .vcpuid = vcpu,
+ .access_width = fls(size) - 1,
+ .gpa = gpa,
+ .value = write ? *value : ~0ul,
+ };
+ long cmd = (write ? VM_SET_KERNEMU_DEV : VM_GET_KERNEMU_DEV);
+ int rc;
+
+ rc = ioctl(ctx->fd, cmd, &irp);
+ if (rc == 0 && !write)
+ *value = irp.value;
+ return (rc);
+}
+
+int
vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq)
{
struct vm_isa_irq isa_irq;
@@ -957,16 +984,13 @@ vm_inject_nmi(struct vmctx *ctx, int vcpu)
return (ioctl(ctx->fd, VM_INJECT_NMI, &vmnmi));
}
-static struct {
- const char *name;
- int type;
-} capstrmap[] = {
- { "hlt_exit", VM_CAP_HALT_EXIT },
- { "mtrap_exit", VM_CAP_MTRAP_EXIT },
- { "pause_exit", VM_CAP_PAUSE_EXIT },
- { "unrestricted_guest", VM_CAP_UNRESTRICTED_GUEST },
- { "enable_invpcid", VM_CAP_ENABLE_INVPCID },
- { 0 }
+static const char *capstrmap[] = {
+ [VM_CAP_HALT_EXIT] = "hlt_exit",
+ [VM_CAP_MTRAP_EXIT] = "mtrap_exit",
+ [VM_CAP_PAUSE_EXIT] = "pause_exit",
+ [VM_CAP_UNRESTRICTED_GUEST] = "unrestricted_guest",
+ [VM_CAP_ENABLE_INVPCID] = "enable_invpcid",
+ [VM_CAP_BPT_EXIT] = "bpt_exit",
};
int
@@ -974,9 +998,9 @@ vm_capability_name2type(const char *capname)
{
int i;
- for (i = 0; capstrmap[i].name != NULL && capname != NULL; i++) {
- if (strcmp(capstrmap[i].name, capname) == 0)
- return (capstrmap[i].type);
+ for (i = 0; i < nitems(capstrmap); i++) {
+ if (strcmp(capstrmap[i], capname) == 0)
+ return (i);
}
return (-1);
@@ -985,12 +1009,8 @@ vm_capability_name2type(const char *capname)
const char *
vm_capability_type2name(int type)
{
- int i;
-
- for (i = 0; capstrmap[i].name != NULL; i++) {
- if (capstrmap[i].type == type)
- return (capstrmap[i].name);
- }
+ if (type >= 0 && type < nitems(capstrmap))
+ return (capstrmap[type]);
return (NULL);
}
@@ -1808,6 +1828,7 @@ vm_get_ioctls(size_t *len)
VM_MMAP_GETNEXT, VM_SET_REGISTER, VM_GET_REGISTER,
VM_SET_SEGMENT_DESCRIPTOR, VM_GET_SEGMENT_DESCRIPTOR,
VM_SET_REGISTER_SET, VM_GET_REGISTER_SET,
+ VM_SET_KERNEMU_DEV, VM_GET_KERNEMU_DEV,
VM_INJECT_EXCEPTION, VM_LAPIC_IRQ, VM_LAPIC_LOCAL_IRQ,
VM_LAPIC_MSI, VM_IOAPIC_ASSERT_IRQ, VM_IOAPIC_DEASSERT_IRQ,
VM_IOAPIC_PULSE_IRQ, VM_IOAPIC_PINCOUNT, VM_ISA_ASSERT_IRQ,
diff --git a/usr/src/lib/libvmmapi/common/vmmapi.h b/usr/src/lib/libvmmapi/common/vmmapi.h
index 6cb7a1186d..f7a8731c9a 100644
--- a/usr/src/lib/libvmmapi/common/vmmapi.h
+++ b/usr/src/lib/libvmmapi/common/vmmapi.h
@@ -47,6 +47,8 @@
#include <sys/param.h>
#include <sys/cpuset.h>
+#include <stdbool.h>
+
/*
* API version for out-of-tree consumers like grub-bhyve for making compile
* time decisions.
@@ -175,6 +177,8 @@ int vm_ioapic_assert_irq(struct vmctx *ctx, int irq);
int vm_ioapic_deassert_irq(struct vmctx *ctx, int irq);
int vm_ioapic_pulse_irq(struct vmctx *ctx, int irq);
int vm_ioapic_pincount(struct vmctx *ctx, int *pincount);
+int vm_readwrite_kernemu_device(struct vmctx *ctx, int vcpu,
+ vm_paddr_t gpa, bool write, int size, uint64_t *value);
int vm_isa_assert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
int vm_isa_deassert_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);
int vm_isa_pulse_irq(struct vmctx *ctx, int atpic_irq, int ioapic_irq);