Page MenuHomeFreeBSD

D40040.id121796.diff
No OneTemporary

D40040.id121796.diff

diff --git a/usr.sbin/bhyve/pci_gvt-d.c b/usr.sbin/bhyve/pci_gvt-d.c
--- a/usr.sbin/bhyve/pci_gvt-d.c
+++ b/usr.sbin/bhyve/pci_gvt-d.c
@@ -6,16 +6,31 @@
*/
#include <sys/types.h>
+#include <sys/mman.h>
#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
#include "pci_gvt-d.h"
#include "pci_passthru.h"
+#define KB (1024UL)
+#define MB (1024 * KB)
+#define GB (1024 * MB)
+
+#ifndef _PATH_MEM
+#define _PATH_MEM "/dev/mem"
+#endif
+
#define PCIR_BDSM 0x5C /* Base of Data Stolen Memory register */
+#define PCIR_ASLS_CTL 0xFC /* Opregion start address register */
/* GVT-d definitions */
#define GVT_D_MAP_GSM 0
+#define GVT_D_MAP_OPREGION 1
static int
gvt_d_setup_gsm(struct pci_devinst *const pi)
@@ -31,6 +46,54 @@
passthru_cfgwrite_emulate));
}
+static int
+gvt_d_setup_opregion(struct pci_devinst *const pi)
+{
+ struct passthru_softc *sc;
+ struct passthru_mmio_mapping *opregion;
+ struct igd_opregion_header *header;
+ uint64_t asls;
+ int memfd;
+
+ sc = pi->pi_arg;
+
+ memfd = open(_PATH_MEM, O_RDWR, 0);
+ if (memfd < 0) {
+ warn("%s: Failed to open %s", __func__, _PATH_MEM);
+ return (-1);
+ }
+
+ opregion = passthru_get_mmio(sc, GVT_D_MAP_OPREGION);
+ if (opregion == NULL) {
+ warnx("%s: Unable to access opregion", __func__);
+ close(memfd);
+ return (-1);
+ }
+
+ asls = read_config(passthru_get_sel(sc), PCIR_ASLS_CTL, 4);
+
+ header = mmap(NULL, sizeof(*header), PROT_READ, MAP_SHARED, memfd,
+ asls);
+ if (header == MAP_FAILED) {
+ warnx("%s: Unable to map OpRegion header", __func__);
+ close(memfd);
+ return (errno);
+ }
+ if (memcmp(header->sign, IGD_OPREGION_HEADER_SIGN,
+ sizeof(header->sign)) != 0) {
+ warnx("%s: Invalid OpRegion signature", __func__);
+ munmap(header, sizeof(*header));
+ close(memfd);
+ return (-1);
+ }
+
+ opregion->hpa = asls;
+ opregion->len = header->size * KB;
+ munmap(header, sizeof(header));
+
+ return (0);
+}
+
int
gvt_d_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused)
{
@@ -41,6 +104,11 @@
goto done;
}
+ if ((error = gvt_d_setup_opregion(pi)) != 0) {
+ warnx("%s: Unable to setup OpRegion", __func__);
+ goto done;
+ }
+
done:
return (error);
}

File Metadata

Mime Type
text/plain
Expires
Wed, Sep 30, 7:26 PM (21 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39968536
Default Alt Text
D40040.id121796.diff (2 KB)

Event Timeline