From nobody Fri Jun 16 06:14:18 2023 X-Original-To: dev-commits-src-main@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 4Qj84p3zXpz4fGTV; Fri, 16 Jun 2023 06:14:18 +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 4Qj84p1mW9z3qbl; Fri, 16 Jun 2023 06:14:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896058; 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=mRBOhNbpPTJMozl4FzoftgcX5Xqs/Mj5zOTgq52KlBE=; b=APyqOmjh6pei2BnZtfJCGpKdwPLSmwZ8uYvkqEkQrRmgO7PcgykhxgzHt4rt0GJauHYlYC 7GCCEFb4C5rD0w5KJNKL/JN1PcDGNHbRlYT8/Dqj121erO7vadL6HFT8lpEqRdqiDf2ifu nHDIRoa7JTdCRjA2eEswogorZhvkcEXtcFoMsXv+0cq0IC1jHvB5aKdfFvgb4moOqLN/El o2pF2MSPchCxlE98vFo9i+koBxObz9Ppl4+ZrTTwo6m+XvivfO42jU1e95yvQPZx3DflXd /dssFtpCzpfJExOMBxzF7VBN4OZsjn5HsJJzyDB/557T0IFJBhg3ITLD/ODTSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686896058; 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=mRBOhNbpPTJMozl4FzoftgcX5Xqs/Mj5zOTgq52KlBE=; b=K415v15xoqHfUlhVfBD/CfGzEAxpo8JaqyuM+m6bH3eiVSNjQ4jngkKiaIo/55nhUa/S65 6VPXrBDwxhm28BNKfJ/6sjr3yU1I0uKua5vduiIUi20npKQ4iwFfVvwMZaOyrEjHDeavio rfMBjwfm9B6PYm2rTSagqX9jnO0h2MIxiEGXiN+LBZVsgWAKXU1CAVEvIkmvCCBdMO63TI AWrrBoGW4OzK3zLwIAbESHJAVAxomUFKaOF2FF2Nqk0LFfdwPb9BkKtGpHES/eqh4qRH+k x9c/TRBjW1gBEiB12fvnQyCMS+usynl2Jh2abFJwD0RSL1rfhUX9wTA3yp49zQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686896058; a=rsa-sha256; cv=none; b=gpIX9CNtDlMSMDU4Nvcl5fISU2IQwgqPqMt0zBLv2+j5nETjb6H4YxUFNPT87mIOOA5Ni+ T4sopxUC9ZcNbaPrrIPDxDUl7twqLORvOGYLKtithSQqJooPv26jTts7UNiiwFxPo92l8T ACbiHI+YczlNlb3gzEgLcW8CQsP25YuZj4P/c4GR9qL0zvsB2I5bsHZCN63xmK7wCm8CmX 4uvRIyhdWDbXkg+OecHu/3n5sCRJn95UYpzM8gWmozzNDB2FAP5voqKfeBGMKTqXmjTyAg jj61986qJO5SlcIRvnqQToWV0aDOPGSnafC0e8aQLuLMTPCufrJ8cTRcWacBqA== 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 4Qj84p0tgHzGy7; Fri, 16 Jun 2023 06:14:18 +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 35G6EIsL035198; Fri, 16 Jun 2023 06:14:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35G6EIJQ035197; Fri, 16 Jun 2023 06:14:18 GMT (envelope-from git) Date: Fri, 16 Jun 2023 06:14:18 GMT Message-Id: <202306160614.35G6EIJQ035197@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: 6952b9d25e18 - main - bhyve: read OpRegion address and size for GVT-d List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 6952b9d25e18fd3a4bf0d1bb7d6b44ff6edf6737 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=6952b9d25e18fd3a4bf0d1bb7d6b44ff6edf6737 commit 6952b9d25e18fd3a4bf0d1bb7d6b44ff6edf6737 Author: Corvin Köhne AuthorDate: 2023-05-10 11:38:02 +0000 Commit: Corvin Köhne CommitDate: 2023-06-16 05:54:53 +0000 bhyve: read OpRegion address and size for GVT-d The OpRegion provides some configuration bits and ACPI methods used by some Intel drivers. The guest needs access to it. In the first step, we're reading it's address and size. Reviewed by: jhb MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D40040 --- usr.sbin/bhyve/pci_gvt-d.c | 67 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/usr.sbin/bhyve/pci_gvt-d.c b/usr.sbin/bhyve/pci_gvt-d.c index 3109bc06be82..fd3b48c3e5b7 100644 --- a/usr.sbin/bhyve/pci_gvt-d.c +++ b/usr.sbin/bhyve/pci_gvt-d.c @@ -6,12 +6,16 @@ */ #include +#include #include #include #include #include +#include +#include +#include #include "e820.h" #include "pci_gvt-d-opregion.h" @@ -21,14 +25,20 @@ #define MB (1024 * KB) #define GB (1024 * MB) +#ifndef _PATH_MEM +#define _PATH_MEM "/dev/mem" +#endif + #define PCI_VENDOR_INTEL 0x8086 -#define PCIR_BDSM 0x5C /* Base of Data Stolen Memory register */ +#define PCIR_BDSM 0x5C /* Base of Data Stolen Memory register */ +#define PCIR_ASLS_CTL 0xFC /* Opregion start address register */ #define PCIM_BDSM_GSM_ALIGNMENT \ 0x00100000 /* Graphics Stolen Memory is 1 MB aligned */ #define GVT_D_MAP_GSM 0 +#define GVT_D_MAP_OPREGION 1 static int gvt_d_probe(struct pci_devinst *const pi) @@ -167,6 +177,56 @@ gvt_d_setup_gsm(struct pci_devinst *const pi) 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_RDONLY, 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) { + warn("%s: Unable to map OpRegion header", __func__); + close(memfd); + return (-1); + } + 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)); + + close(memfd); + + return (0); +} + static int gvt_d_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused) { @@ -177,6 +237,11 @@ gvt_d_init(struct pci_devinst *const pi, nvlist_t *const nvl __unused) goto done; } + if ((error = gvt_d_setup_opregion(pi)) != 0) { + warnx("%s: Unable to setup OpRegion", __func__); + goto done; + } + done: return (error); }