aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorvin Köhne <corvink@FreeBSD.org>2022-03-17 12:11:14 +0000
committerCorvin Köhne <corvink@FreeBSD.org>2025-09-16 06:55:09 +0000
commiteffcd0ded0ef1c92bef29c1e9bbf517c97bb45b8 (patch)
tree69f1492153e671615555bdcec254eef29182895a
parent8c9a919abaa3f6f16a17586ca72bab939788bf69 (diff)
bhyve: assign a valid INTPIN to NVIDIA GPUs
When passing an NVIDIA GPU to a Linux VM, the GPU driver refuses to work and complains about a missing IRQ: [ 77.208984] NVRM: Can't find an IRQ for your NVIDIA card! [ 77.212697] NVRM: Please check your BIOS settings. [ 77.212699] NVRM: [Plug & Play OS] should be set to NO [ 77.212700] NVRM: [Assign IRQ to VGA] should be set to YES [ 77.212702] nvidia: probe of 0000:00:07.0 failed with error -1 By setting a valid INTPIN in the PCI config space those error messages disappear. Additionally, tools like nvidia-smi are able to detect the GPU and the GPU driver seems to work properly. Note that bhyve still doesn't support legacy interrupts. So, the guest shouldn't try to use it even though we're assigning an INTPIN. Reviewed by: jhb Tested by: chuck MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D51892
-rw-r--r--usr.sbin/bhyve/amd64/Makefile.inc1
-rw-r--r--usr.sbin/bhyve/pci_passthru_quirks.c48
2 files changed, 49 insertions, 0 deletions
diff --git a/usr.sbin/bhyve/amd64/Makefile.inc b/usr.sbin/bhyve/amd64/Makefile.inc
index 92e53433ff01..50a011ed4bfd 100644
--- a/usr.sbin/bhyve/amd64/Makefile.inc
+++ b/usr.sbin/bhyve/amd64/Makefile.inc
@@ -13,6 +13,7 @@ SRCS+= \
pci_gvt-d.c \
pci_lpc.c \
pci_passthru.c \
+ pci_passthru_quirks.c \
pctestdev.c \
pm.c \
post.c \
diff --git a/usr.sbin/bhyve/pci_passthru_quirks.c b/usr.sbin/bhyve/pci_passthru_quirks.c
new file mode 100644
index 000000000000..5ba0e674f311
--- /dev/null
+++ b/usr.sbin/bhyve/pci_passthru_quirks.c
@@ -0,0 +1,48 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Beckhoff Automation GmbH & Co. KG
+ * Author: Corvin Köhne <c.koehne@beckhoff.com>
+ */
+
+#include <dev/pci/pcireg.h>
+
+#include <errno.h>
+
+#include "pci_passthru.h"
+
+#define PCI_VENDOR_NVIDIA 0x10DE
+
+static int
+nvidia_gpu_probe(struct pci_devinst *const pi)
+{
+ struct passthru_softc *sc;
+ uint16_t vendor;
+ uint8_t class;
+
+ sc = pi->pi_arg;
+
+ vendor = pci_host_read_config(passthru_get_sel(sc), PCIR_VENDOR, 0x02);
+ if (vendor != PCI_VENDOR_NVIDIA)
+ return (ENXIO);
+
+ class = pci_host_read_config(passthru_get_sel(sc), PCIR_CLASS, 0x01);
+ if (class != PCIC_DISPLAY)
+ return (ENXIO);
+
+ return (0);
+}
+
+static int
+nvidia_gpu_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused)
+{
+ pci_set_cfgdata8(pi, PCIR_INTPIN, 1);
+
+ return (0);
+}
+
+static struct passthru_dev nvidia_gpu = {
+ .probe = nvidia_gpu_probe,
+ .init = nvidia_gpu_init,
+};
+PASSTHRU_DEV_SET(nvidia_gpu);