diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -46,6 +46,7 @@ pci_emul.c \ pci_hda.c \ pci_fbuf.c \ + pci_gvt-d.c \ pci_hostbridge.c \ pci_irq.c \ pci_lpc.c \ diff --git a/usr.sbin/bhyve/pci_gvt-d.c b/usr.sbin/bhyve/pci_gvt-d.c new file mode 100644 --- /dev/null +++ b/usr.sbin/bhyve/pci_gvt-d.c @@ -0,0 +1,49 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#include + +#include + +#include "pci_gvt-d-opregion.h" +#include "pci_passthru.h" + +#define PCI_VENDOR_INTEL 0x8086 + +static int +gvt_d_init(struct pci_devinst *const pi __unused, nvlist_t *const nvl __unused) +{ + return (0); +} + +static void +gvt_d_deinit(struct pci_devinst *const pi __unused) +{ +} + +static struct passthru_dev gvt_d_dev = { + .init = gvt_d_init, + .deinit = gvt_d_deinit, +}; + +struct passthru_dev * +gvt_d_match(struct pci_devinst *const pi) +{ + struct passthru_softc *sc; + uint16_t vendor; + uint8_t class; + + sc = pi->pi_arg; + + vendor = read_config(passthru_get_sel(sc), PCIR_VENDOR, 0x02); + class = read_config(passthru_get_sel(sc), PCIR_CLASS, 0x01); + + if (vendor == PCI_VENDOR_INTEL && class == PCIC_DISPLAY) + return (&gvt_d_dev); + + return (NULL); +} diff --git a/usr.sbin/bhyve/pci_passthru.h b/usr.sbin/bhyve/pci_passthru.h --- a/usr.sbin/bhyve/pci_passthru.h +++ b/usr.sbin/bhyve/pci_passthru.h @@ -9,6 +9,7 @@ #include +#include "config.h" #include "pci_emul.h" struct passthru_mmio_mapping { @@ -21,6 +22,13 @@ struct passthru_softc; +struct passthru_dev { + int (*init)(struct pci_devinst *pi, nvlist_t *nvl); + void (*deinit)(struct pci_devinst *pi); +}; + +struct passthru_dev *gvt_d_match(struct pci_devinst *pi); + typedef int (*cfgread_handler)(struct passthru_softc *sc, struct pci_devinst *pi, int coff, int bytes, uint32_t *rv); typedef int (*cfgwrite_handler)(struct passthru_softc *sc, diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -856,6 +856,7 @@ { int bus, slot, func, error, memflags; struct passthru_softc *sc; + struct passthru_dev *dev = NULL; const char *value; sc = NULL; @@ -919,9 +920,19 @@ if ((error = set_pcir_handler(sc, PCIR_COMMAND, 0x04, NULL, NULL)) != 0) goto done; + dev = gvt_d_match(pi); + + if (dev != NULL) { + error = dev->init(pi, nvl); + if (error != 0) + goto done; + } + error = 0; /* success */ done: if (error) { + if (dev != NULL) + dev->deinit(pi); free(sc); vm_unassign_pptdev(pi->pi_vmctx, bus, slot, func); }