aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bhyve/pci_passthru_quirks.c
blob: 5ba0e674f311ff95ae584b0cae2b9c9962072468 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);