aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <corvink@FreeBSD.org>2023-05-10 10:22:33 +0000
committerCorvin Köhne <corvink@FreeBSD.org>2023-05-12 07:29:44 +0000
commit93cf93179c505cebbcdbeef196d523d36890ed4a (patch)
treeaae30a5ec31601e42af583a927acfee4261c1493
parent99aeb28b2f7e28c516dd6434db63a9bc1c1f3218 (diff)
downloadsrc-93cf93179c505cebbcdbeef196d523d36890ed4a.tar.gz
src-93cf93179c505cebbcdbeef196d523d36890ed4a.zip
bhyve: add helper for passthru specific mmio ranges
Intel GPUs have two special memory regions. They are called Graphics Stolen Memory and OpRegion. bhyve has to emulate both of them. In order to keep track of those special regions, add generic mmio ranges to the passthru emulation. Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40036
-rw-r--r--usr.sbin/bhyve/pci_passthru.c12
-rw-r--r--usr.sbin/bhyve/pci_passthru.h10
2 files changed, 22 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index 054b284a2f27..0b7a0d362593 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -78,6 +78,8 @@ __FBSDID("$FreeBSD$");
#define MSIX_TABLE_COUNT(ctrl) (((ctrl) & PCIM_MSIXCTRL_TABLE_SIZE) + 1)
#define MSIX_CAPLEN 12
+#define PASSTHRU_MMIO_MAX 2
+
static int pcifd = -1;
struct passthru_softc {
@@ -94,6 +96,7 @@ struct passthru_softc {
} psc_msix;
struct pcisel psc_sel;
+ struct passthru_mmio_mapping psc_mmio_map[PASSTHRU_MMIO_MAX];
cfgread_handler psc_pcir_rhandler[PCI_REGMAX + 1];
cfgwrite_handler psc_pcir_whandler[PCI_REGMAX + 1];
};
@@ -660,6 +663,15 @@ done:
return (error);
}
+struct passthru_mmio_mapping *
+passthru_get_mmio(struct passthru_softc *sc, int num)
+{
+ assert(sc != NULL);
+ assert(num < PASSTHRU_MMIO_MAX);
+
+ return (&sc->psc_mmio_map[num]);
+}
+
struct pcisel *
passthru_get_sel(struct passthru_softc *sc)
{
diff --git a/usr.sbin/bhyve/pci_passthru.h b/usr.sbin/bhyve/pci_passthru.h
index 79578a8496c4..1ca10fa343e4 100644
--- a/usr.sbin/bhyve/pci_passthru.h
+++ b/usr.sbin/bhyve/pci_passthru.h
@@ -11,6 +11,14 @@
#include "pci_emul.h"
+struct passthru_mmio_mapping {
+ vm_paddr_t gpa; /* guest physical address */
+ void *gva; /* guest virtual address */
+ vm_paddr_t hpa; /* host physical address */
+ void *hva; /* guest virtual address */
+ vm_paddr_t len;
+};
+
struct passthru_softc;
typedef int (*cfgread_handler)(struct passthru_softc *sc,
@@ -24,6 +32,8 @@ int passthru_cfgread_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
int coff, int bytes, uint32_t *rv);
int passthru_cfgwrite_emulate(struct passthru_softc *sc, struct pci_devinst *pi,
int coff, int bytes, uint32_t val);
+struct passthru_mmio_mapping *passthru_get_mmio(struct passthru_softc *sc,
+ int num);
struct pcisel *passthru_get_sel(struct passthru_softc *sc);
int set_pcir_handler(struct passthru_softc *sc, int reg, int len,
cfgread_handler rhandler, cfgwrite_handler whandler);