From nobody Fri Jun 16 06:14:14 2023 X-Original-To: dev-commits-src-all@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 4Qj84k71LCz4fG8t; Fri, 16 Jun 2023 06:14:14 +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 4Qj84k6Kkcz3qMp; Fri, 16 Jun 2023 06:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896054; 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=6d5jlzF8K47Z7sEhazRPZ66/HVAyKCOkjO+ZjLHbaZg=; b=n3EM/VpjYzUtkm6WzzEUMSkBYUyRFBovZR/vxEXDvNBohz8DQQZ7KvpV31gPY4V9Z7rZNa n1PL38wZK/kO1grCTujO1A+yvk5WYW2eH2BpHKGwF7YD+LofOd16wR85DPfPPjgTzK0DG/ qBDY7+FQkgnwdGtf3ldU56ukb8XtJdXAORFNHYVWmpNADq61gH67S5QWRFKR4OESepkRqy b88JxOn81Im9Cx9LJ7ypHsqFzBapsb3SnHiIvPMQ4LhQU6EAGNtJMZnakQWwtNtCYDQ0L8 D8OfkiyrY54M9L6gd6/VAAXXiFqoloG3dQoKkR5dYYdu/ghxMnegipg9bFBnKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896054; 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=6d5jlzF8K47Z7sEhazRPZ66/HVAyKCOkjO+ZjLHbaZg=; b=iTwFGKsNDwEFOXgEAJnUbOC/DDdpO99KcTceOSy6qic5i8d/peXOH4OARq3kbvt5aiOwAr DGXSVyt/Pe7bnBN9M8BDLMwIh/kwKg8SFgVK4Mk/wvR36kMOYSSZmpbXJIaGyrj5KhLDYd goO+97jxnjLmxEGkkHEPwIazyVZ0gys2fi8DAg/CwUcLa/cKnfXXVJ2pf2rttWFHd9CxwV 2cPnI+99b+berXb68lkrUmLGcETFis0jMHEpRWWqe1QSzTi5Z/NKQw/tHU2y2KiFLuAu+N +CLv0vANN8iWNDwUjgs3i2EurlQ/2n9kiK+GIDSZOvHcuancOkEqawpOwH3IIA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686896054; a=rsa-sha256; cv=none; b=C4wDGDFmjbMbfgbnVPkIlNUtLiCBOBgQ+M/yakYWYXkcbZU6HeNsr99t0/hcEd9h1FWD9P 7Zn+lZBTlwaTgaBeNZtf2tEbkj4veuwlQ/SJuOXhZ3Le4pY2D1ui7UdJOgnGnA43h+Pn7L GYiGEE8pO5CLt+pgDOSSD4aUSikLRDtcodMRBcGkwdlrGutGygbX9SVPVCYd2d4R5MH3Wk 7VYResEnKlxw4vEH/d8WixIgpvxMG9KUcVHCULgeYQ3NbnEFqwLviI3oZQAYMOC5IziLIk hj234ZxZxgX4e9HXa2TgMNnGblc0GH90GK99jMVmMz3wmgMSv7jvbE7k9143uA== 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 4Qj84k5CBTzHGF; Fri, 16 Jun 2023 06:14:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35G6EEpR035124; Fri, 16 Jun 2023 06:14:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35G6EEPb035123; Fri, 16 Jun 2023 06:14:14 GMT (envelope-from git) Date: Fri, 16 Jun 2023 06:14:14 GMT Message-Id: <202306160614.35G6EEPb035123@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: 4a9bf50f408e - main - bhyve: read out graphics stolen memory address and size List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 4a9bf50f408eb9f1acc220dba2b260ec610fd15b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=4a9bf50f408eb9f1acc220dba2b260ec610fd15b commit 4a9bf50f408eb9f1acc220dba2b260ec610fd15b Author: Corvin Köhne AuthorDate: 2023-05-11 08:53:15 +0000 Commit: Corvin Köhne CommitDate: 2023-06-16 05:53:46 +0000 bhyve: read out graphics stolen memory address and size This is the first step to emulate the graphics stolen memory register. Note that the graphics stolen memory is somehow confusing. On the one hand the Intel Open Source HD Graphics Programmers' Reference Manual states that it's only GPU accessible. As the CPU can't access the area, the guest shouldn't need it. On the other hand, the Intel GOP driver refuses to work properly, if it's not set to a proper address. Intel itself maps it into the guest by EPT [1]. At the moment, we're not aware of any situation where this EPT mapping is required, so we don't do it yet. Intel also states that the Windows driver for Tiger Lake reads the address of the graphics stolen memory [2]. As the GVT-d code doesn't support Tiger Lake in its first implementation, we can't check how it behaves. We should keep an eye on it. [1] https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L655-L657 [2] https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L626-L629 Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40039 --- usr.sbin/bhyve/pci_gvt-d.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_gvt-d.c b/usr.sbin/bhyve/pci_gvt-d.c index 767b8ee3127f..0be740921c92 100644 --- a/usr.sbin/bhyve/pci_gvt-d.c +++ b/usr.sbin/bhyve/pci_gvt-d.c @@ -6,6 +6,9 @@ */ #include +#include + +#include #include @@ -16,6 +19,8 @@ #define PCI_VENDOR_INTEL 0x8086 +#define GVT_D_MAP_GSM 0 + static int gvt_d_probe(struct pci_devinst *const pi) { @@ -36,12 +41,78 @@ gvt_d_probe(struct pci_devinst *const pi) return (0); } +/* + * Note that the graphics stolen memory is somehow confusing. On the one hand + * the Intel Open Source HD Graphics Programmers' Reference Manual states that + * it's only GPU accessible. As the CPU can't access the area, the guest + * shouldn't need it. On the other hand, the Intel GOP driver refuses to work + * properly, if it's not set to a proper address. + * + * Intel itself maps it into the guest by EPT [1]. At the moment, we're not + * aware of any situation where this EPT mapping is required, so we don't do it + * yet. + * + * Intel also states that the Windows driver for Tiger Lake reads the address of + * the graphics stolen memory [2]. As the GVT-d code doesn't support Tiger Lake + * in its first implementation, we can't check how it behaves. We should keep an + * eye on it. + * + * [1] + * https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L655-L657 + * [2] + * https://github.com/projectacrn/acrn-hypervisor/blob/e28d6fbfdfd556ff1bc3ff330e41d4ddbaa0f897/devicemodel/hw/pci/passthrough.c#L626-L629 + */ static int -gvt_d_init(struct pci_devinst *const pi __unused, nvlist_t *const nvl __unused) +gvt_d_setup_gsm(struct pci_devinst *const pi) { + struct passthru_softc *sc; + struct passthru_mmio_mapping *gsm; + size_t sysctl_len; + int error; + + sc = pi->pi_arg; + + gsm = passthru_get_mmio(sc, GVT_D_MAP_GSM); + if (gsm == NULL) { + warnx("%s: Unable to access gsm", __func__); + return (-1); + } + + sysctl_len = sizeof(gsm->hpa); + error = sysctlbyname("hw.intel_graphics_stolen_base", &gsm->hpa, + &sysctl_len, NULL, 0); + if (error) { + warn("%s: Unable to get graphics stolen memory base", + __func__); + return (-1); + } + sysctl_len = sizeof(gsm->len); + error = sysctlbyname("hw.intel_graphics_stolen_size", &gsm->len, + &sysctl_len, NULL, 0); + if (error) { + warn("%s: Unable to get graphics stolen memory length", + __func__); + return (-1); + } + gsm->hva = NULL; /* unused */ + return (0); } +static int +gvt_d_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused) +{ + int error; + + if ((error = gvt_d_setup_gsm(pi)) != 0) { + warnx("%s: Unable to setup Graphics Stolen Memory", __func__); + goto done; + } + +done: + return (error); +} + static void gvt_d_deinit(struct pci_devinst *const pi __unused) {