From nobody Fri Aug 18 07:41:46 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RRv2g0wSmz4qrNn; Fri, 18 Aug 2023 07:41:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RRv2f6yPmz3G6n; Fri, 18 Aug 2023 07:41:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692344507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2HjHZHn1FfIFIfOKZq3WRXpUiPt/z7Nsdae3N/7PZNc=; b=iGwlbqRBCPCneISzxZouuD0k54X9iEiQjvAXef10AQDOPdw8c6DnfoISM9FrRvzwIXBGL/ AXcbxndAEGXv5V31yN/9SQKls934vzAy+JjHbgsylOHOcB/DnYzBRQLJ64dTrotA38MkPs MtybGs50OyLpS4lufTt3UKghrc/MALzkAC/0SLifvS9SzIgwD1qgGmKfZDCxI7MC9AE9zF UjqhLdMgdY8ZVn3+1WIthKlnoQ+2TLWwGKRv9bpDJgOlaVpvFz4ESwjzNZ3v8FDINJhbr5 M8xqWBFZEyjTq7wyEdbjoko1+YCrCBXsSE6u0UMhxjQccJDQ5oa2BL92TToGwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692344507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2HjHZHn1FfIFIfOKZq3WRXpUiPt/z7Nsdae3N/7PZNc=; b=OEJyLAA2WL+CUwfw3ZmKI+Tt4OiYfXHBQV40E/6PIlr7NtSn+rPLT0x0Zw8HSObPluBH8W gjnXl+MoGVzMOwmB3EwW+p8ompoLidcA1YNyyXa5EfY3sM/MIV3uahgX4/UmW4RgARmoPF NvwIFZsPSHbbSgaJphDGT8A89pDcUDX61eAQPbdyxgZOtGEv1QVGSxziwNj/9JU2O7fJ69 BirxU/OPNpCr3YiBpy9cl3Ewcm+OwbmS1TZlQAgOTGFODgTOEqGu5+Xp7Rk9RZ90b0vvFv nrvQKtzHZtzq53jzyu980FpXruTG+KSO06oT2CozzsJlJn0KcWP6yF2A7PcHQQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692344507; a=rsa-sha256; cv=none; b=w1+p9pGoGuULma/yQcMFSwlGCNu2B2vV7LmHleDtRvjAVeSNUahqzZ+TXq7mv0qKguTzyg 7cdGINlszrsR5SBXZeyvpUS9T2nV6eYI6pRMP7IsuLlep6ez1RycNd223g1RkZdNigR92U nQzwyO8m7dFyg15ANEbsz4W3I3Vqdu4X4CTbMYzLtuwdrxqrfZsOC6kIZgHHJprcIXkfiy T6pTE8+ytyidZGlTFEAWY4w0K3wkET4ykbFXsRg3srW1mR/FZO1dCZuxbLY5nB2TK6PJIS W8t0JnNWCwi/EhoO4MxGPrJL7SEhZEhL6RBriHIjyAMkVmJMPEGBAmYLtJw+2Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RRv2f63HWz16tG; Fri, 18 Aug 2023 07:41:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37I7fkRM065842; Fri, 18 Aug 2023 07:41:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37I7fkYM065839; Fri, 18 Aug 2023 07:41:46 GMT (envelope-from git) Date: Fri, 18 Aug 2023 07:41:46 GMT Message-Id: <202308180741.37I7fkYM065839@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Corvin =?utf-8?Q?K=C3=B6hne?= Subject: git: 3b81aa26ab4c - stable/13 - bhyve: add empty GVT-d emulation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: corvink X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3b81aa26ab4c8fb360d25a6cd2fedc49cff67e51 Auto-Submitted: auto-generated The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=3b81aa26ab4c8fb360d25a6cd2fedc49cff67e51 commit 3b81aa26ab4c8fb360d25a6cd2fedc49cff67e51 Author: Corvin Köhne AuthorDate: 2023-05-10 10:31:50 +0000 Commit: Corvin Köhne CommitDate: 2023-08-18 07:32:05 +0000 bhyve: add empty GVT-d emulation Don't emulate anything yet. Just check if the user would like to pass an Intel GPU to the guest. Reviewed by: jhb, markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40038 (cherry picked from commit 90c3a1b6629c80a7e4c3fa86d6b794596fdf06b4) --- usr.sbin/bhyve/Makefile | 1 + usr.sbin/bhyve/pci_gvt-d.c | 55 +++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/pci_passthru.c | 22 ++++++++++++++++- usr.sbin/bhyve/pci_passthru.h | 10 ++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index c2b426359c22..2f282567eb87 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -45,6 +45,7 @@ SRCS= \ 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 index 000000000000..767b8ee3127f --- /dev/null +++ b/usr.sbin/bhyve/pci_gvt-d.c @@ -0,0 +1,55 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Beckhoff Automation GmbH & Co. KG + * Author: Corvin Köhne + */ + +#include + +#include + +#include + +#include "pci_gvt-d-opregion.h" +#include "pci_passthru.h" + +#define PCI_VENDOR_INTEL 0x8086 + +static int +gvt_d_probe(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); + if (vendor != PCI_VENDOR_INTEL) + return (ENXIO); + + class = read_config(passthru_get_sel(sc), PCIR_CLASS, 0x01); + if (class != PCIC_DISPLAY) + return (ENXIO); + + return (0); +} + +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 = { + .probe = gvt_d_probe, + .init = gvt_d_init, + .deinit = gvt_d_deinit, +}; +PASSTHRU_DEV_SET(gvt_d_dev); diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index d6978a1be822..793fe3762530 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -64,7 +64,6 @@ __FBSDID("$FreeBSD$"); #include -#include "config.h" #include "debug.h" #include "mem.h" #include "pci_passthru.h" @@ -82,6 +81,8 @@ __FBSDID("$FreeBSD$"); static int pcifd = -1; +SET_DECLARE(passthru_dev_set, struct passthru_dev); + struct passthru_softc { struct pci_devinst *psc_pi; /* ROM is handled like a BAR */ @@ -856,6 +857,8 @@ passthru_init(struct pci_devinst *pi, nvlist_t *nvl) { int bus, slot, func, error, memflags; struct passthru_softc *sc; + struct passthru_dev **devpp; + struct passthru_dev *devp, *dev = NULL; const char *value; sc = NULL; @@ -919,9 +922,26 @@ passthru_init(struct pci_devinst *pi, nvlist_t *nvl) if ((error = set_pcir_handler(sc, PCIR_COMMAND, 0x04, NULL, NULL)) != 0) goto done; + SET_FOREACH(devpp, passthru_dev_set) { + devp = *devpp; + assert(devp->probe != NULL); + if (devp->probe(pi) == 0) { + dev = devp; + break; + } + } + + 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); } diff --git a/usr.sbin/bhyve/pci_passthru.h b/usr.sbin/bhyve/pci_passthru.h index 7ce12a27bba4..49d2bb309f71 100644 --- a/usr.sbin/bhyve/pci_passthru.h +++ b/usr.sbin/bhyve/pci_passthru.h @@ -7,8 +7,11 @@ #pragma once +#include + #include +#include "config.h" #include "pci_emul.h" struct passthru_mmio_mapping { @@ -21,6 +24,13 @@ struct passthru_mmio_mapping { struct passthru_softc; +struct passthru_dev { + int (*probe)(struct pci_devinst *pi); + int (*init)(struct pci_devinst *pi, nvlist_t *nvl); + void (*deinit)(struct pci_devinst *pi); +}; +#define PASSTHRU_DEV_SET(x) DATA_SET(passthru_dev_set, x) + 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,