git: ffaed739a803 - main - bhyve: add helper to read PCI IDs from bhyve config
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 27 Mar 2023 08:11:39 UTC
The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=ffaed739a80319a56d0b1dfd6cedeb3d194ff42c commit ffaed739a80319a56d0b1dfd6cedeb3d194ff42c Author: Corvin Köhne <corvink@FreeBSD.org> AuthorDate: 2023-02-06 10:43:49 +0000 Commit: Corvin Köhne <corvink@FreeBSD.org> 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 <sys/queue.h> #include <sys/kernel.h> #include <sys/nv.h> +#include <sys/pciio.h> #include <sys/_pthreadtypes.h> #include <dev/pci/pcireg.h> @@ -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,