From nobody Mon Mar 27 08:11:39 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 4PlQWb4dLgz41wYB; Mon, 27 Mar 2023 08:11:39 +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 4PlQWb4CSDz483D; Mon, 27 Mar 2023 08:11:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679904699; 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=3zKcaKbcXagYHYaJWnVOxhI4GF6Veazg3tkc2yHtwZg=; b=OLJHva+lvafZV/eFqrMRsuMMno8ecWM9tUFQiHYMMSGfK78QZOz2sST0GGR+rmMvuuhx3c 0ojiCFlFYmn6mBnVCAoGa9398oh7zJMI2w1QWZmbAv+0c+wPifTneFLIF9oaCPHojOQNQu 8ptQBHDTb3lwRFVPHZPmk+rw566j+RB+T9MYrATIvSklvlE+jeBtr/uyWEIR+AWM9Qzl/h GYPY/QNH2HwtCB/YLsyP1DKefMSeAYegoAG8zWKF+xwzE5JDDk7tWT3Z4z7S4LwOHnlLgs a4sKEyGAgIKFQuU7Gt/tYyDb2Nd5gK+1Gs7AX+OOYcuHr9SsqO6BmRfDz3LYiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679904699; 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=3zKcaKbcXagYHYaJWnVOxhI4GF6Veazg3tkc2yHtwZg=; b=YzS8vI2J5NApAZaSnZ3mNp/L53jm1c9Q7s7kB/Nsgk3mk+czzIv0VuVH8nRB4jh3Cg9g6H ZxzMnU4Y2YSKl6VlJLyz2jI5Yi63Q43a0hmCFoXMmGNvi3B/fuOf9TMjbGh9LWyl3emQrt hSXS/Wx7vAV1ZyBi/VjLTLFck27pq2boNaCgNljnlACueIxgEdaJj8Ti/ENpFUnshIOTnX 1zCyg3WCit4BRS2UXmM2OMgWg4Vjin4Bi7jkASYJE5ZKjBUhkE56zCEg6Rb7bVW/dA0bpx Qozb+wSA4ZiKw7vYz/VSPrRqyg9ErVh+sRamDkiPit+w0QOGk/YP422GaI6L/g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679904699; a=rsa-sha256; cv=none; b=P03desDXwzDxud9KKozuSroZFg6KmDaDzXYwaRmZZ6T6PEb/DgjeFNVkvGNwtqQIZpeNGr EQW572lxrAqxhNDkktx2efJ+SkjycNnNVyI6bK4Kh98X7fw7XseVrWyJP/cwSdga86UAx4 iMT1KYA1PW3w0OyYaYX5zyotiAHkGT/NKNbH0vreHceSLEuI/fOyFhLuCDidiJzkGS6rrA 14LhqpEVn5P6lDy1bKIoAsvKexS1Q8aTdp9iTrEEJl8Twc/sQw8wa7wUHDBdc0LtLNqWM5 VmQuLQ0HPOglSmF+aeElTm1W8MbCtP1Y3lKQE570s4BKGk7BC6grm1CbxCxscQ== 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 4PlQWb3GFxzF2m; Mon, 27 Mar 2023 08:11:39 +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 32R8Bdiw043721; Mon, 27 Mar 2023 08:11:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32R8Bd4B043720; Mon, 27 Mar 2023 08:11:39 GMT (envelope-from git) Date: Mon, 27 Mar 2023 08:11:39 GMT Message-Id: <202303270811.32R8Bd4B043720@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: ffaed739a803 - main - bhyve: add helper to read PCI IDs from bhyve config 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: ffaed739a80319a56d0b1dfd6cedeb3d194ff42c Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=ffaed739a80319a56d0b1dfd6cedeb3d194ff42c commit ffaed739a80319a56d0b1dfd6cedeb3d194ff42c Author: Corvin Köhne AuthorDate: 2023-02-06 10:43:49 +0000 Commit: Corvin Köhne CommitDate: 2023-03-27 08:10:24 +0000 bhyve: add helper to read PCI IDs from bhyve config Changing the PCI IDs is valuable in some situations. The Intel GOP driver requires that some PCI IDs of the LPC bridge are aligned with the physical values of the host LPC bridge. Another use case are oracles virtio driver. They require different subvendor ID than the default one. For that reason, create a helper which makes it easy to read PCI IDs from bhyve config. Additionally, this helper ensures that all emulation devices are using the same config keys. Reviewed by: jhb MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38402 --- usr.sbin/bhyve/pci_emul.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/bhyve/pci_emul.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/usr.sbin/bhyve/pci_emul.c b/usr.sbin/bhyve/pci_emul.c index 48d80a63ea51..d94b419ca622 100644 --- a/usr.sbin/bhyve/pci_emul.c +++ b/usr.sbin/bhyve/pci_emul.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include "pci_emul.h" #include "pci_irq.h" #include "pci_lpc.h" +#include "pci_passthru.h" #define CONF1_ADDR_PORT 0x0cf8 #define CONF1_DATA_PORT 0x0cfc @@ -332,6 +333,49 @@ pci_print_supported_devices(void) } } +uint32_t +pci_config_read_reg(const struct pcisel *const host_sel, nvlist_t *nvl, + const uint32_t reg, const uint8_t size, const uint32_t def) +{ + const char *config; + const nvlist_t *pci_regs; + + assert(size == 1 || size == 2 || size == 4); + + pci_regs = find_relative_config_node(nvl, "pcireg"); + if (pci_regs == NULL) { + return def; + } + + switch (reg) { + case PCIR_DEVICE: + config = get_config_value_node(pci_regs, "device"); + break; + case PCIR_VENDOR: + config = get_config_value_node(pci_regs, "vendor"); + break; + case PCIR_REVID: + config = get_config_value_node(pci_regs, "revid"); + break; + case PCIR_SUBVEND_0: + config = get_config_value_node(pci_regs, "subvendor"); + break; + case PCIR_SUBDEV_0: + config = get_config_value_node(pci_regs, "subdevice"); + break; + default: + return (-1); + } + + if (config == NULL) { + return def; + } else if (host_sel != NULL && strcmp(config, "host") == 0) { + return read_config(host_sel, reg, size); + } else { + return strtol(config, NULL, 16); + } +} + static int pci_valid_pba_offset(struct pci_devinst *pi, uint64_t offset) { diff --git a/usr.sbin/bhyve/pci_emul.h b/usr.sbin/bhyve/pci_emul.h index b54f3f15fbad..c623576b37c0 100644 --- a/usr.sbin/bhyve/pci_emul.h +++ b/usr.sbin/bhyve/pci_emul.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -227,6 +228,8 @@ typedef void (*pci_lintr_cb)(int b, int s, int pin, int pirq_pin, int init_pci(struct vmctx *ctx); void pci_callback(void); +uint32_t pci_config_read_reg(const struct pcisel *host_sel, nvlist_t *nvl, + uint32_t reg, uint8_t size, uint32_t def); int pci_emul_alloc_bar(struct pci_devinst *pdi, int idx, enum pcibar_type type, uint64_t size); int pci_emul_alloc_rom(struct pci_devinst *const pdi, const uint64_t size,