From nobody Wed Apr 05 10:02:30 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 4Ps0YM0vWvz44Bcs; Wed, 5 Apr 2023 10:02:31 +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 4Ps0YM0QMWz4LSc; Wed, 5 Apr 2023 10:02:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680688951; 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=t+ZvW76oaDKyoiJnserm3LaOeknNLdOq7MCNO5Ai+x4=; b=A/MdbHBxdMIXYqVqW56E7gDHmBzFmghILI1O/0T6MYwgDnU8wai2FaTV5l/0VjosCDymz6 7CCAhkbZjWmyqD8J1aaH9AWt3ujRdEBLRafNCIueYfu8CZOIp1UqhLNU5mpKWBGx0QO6/K nBQZoXs1xslQ6lrs1sVCVYBt4dLb9aeqriTxJEQa8liALqoOqgDQNxPNBSMHvflrV88O98 BrivyaqTUf6/c0LdagU1ClqEHGUF7kcuUNXWPiY7qnPf/JD+6klyNI7r+f2J60rDXcx4eP ccF8CsyPrND/mCziekcyTbH36yuIhkIVp9J9U8lMZM9dH+osoaq70AiY0kdauA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680688951; 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=t+ZvW76oaDKyoiJnserm3LaOeknNLdOq7MCNO5Ai+x4=; b=VZlSOzxQPGbR7TCBYsBJn/0qxnY8CISbHcCDzIcoENOi41nVNoiEg/wPx7duIz1/HXv7x/ yX2C/nbjkv5d79cNTGCWNGW0B8+L8kY50NeJgd2no8JsK+4eFA+eSRDCLdr4ACByNGADaf +52tw938yV6hzhq13wU3wC+kqH+r4vN8gQFvQvfWyGtoaYUWKwZ+Yx+BLQb/aVipo+8T3i 32Rli/kxDCDJ6cD8D68eIoMWGaaWQ71YbaTZ3XHD3uUOyc3Ct4exZszNJB+B8pQZAxkGis ILKaGU1oTC8PEgid3bh6w1ksphwZwmcylUjIuBzEi8FZTd+pG7r1zLWq3Taqgw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680688951; a=rsa-sha256; cv=none; b=TweZyBHuN1A9cen5rKrq3h9yaVJeW4Z5ciINUstDAchE/2GPJLpyg8N5iVltkxlARtjC3a ee1jayYw+RibTo8K3tsH0suXqQoctKZDM7TjA3PrZzS0PRvrcGENlV07RwQ+QyExZZMlUg PPXDgvxPWKdgQF83PadzTzr77Vj0f/X18ycvkaEwuOorOwN8h6BpiSdVhm05hWUVfRrmM2 8qUfLqojygHHgq4UZoYecV6LnEwiLEqqVK/dsmGiHfZyaES9pBGldPyxYWwopcRCBTOclE Y6f8mBCeFumixu4WWfyb2+yKVz+ZBAVWi//1OP4eUuBLIXJYRYnTqq6aD2hMwQ== 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 4Ps0YL6Hc1zJ1D; Wed, 5 Apr 2023 10:02:30 +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 335A2UOC040363; Wed, 5 Apr 2023 10:02:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 335A2U2j040362; Wed, 5 Apr 2023 10:02:30 GMT (envelope-from git) Date: Wed, 5 Apr 2023 10:02:30 GMT Message-Id: <202304051002.335A2U2j040362@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: ee3a7907bb98 - stable/13 - bhyve: add helper to read PCI IDs from bhyve config 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: ee3a7907bb987b104246efd149c4af251e7bc402 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=ee3a7907bb987b104246efd149c4af251e7bc402 commit ee3a7907bb987b104246efd149c4af251e7bc402 Author: Corvin Köhne AuthorDate: 2023-02-06 10:43:49 +0000 Commit: Corvin Köhne CommitDate: 2023-04-05 10:00:39 +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 (cherry picked from commit ffaed739a80319a56d0b1dfd6cedeb3d194ff42c) --- 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 93411751d635..41b7718e6935 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 117fc78898a2..40487b18f87b 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,