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
This commit is contained in:
Corvin Köhne 2023-02-06 11:43:49 +01:00
parent 107597fbd4
commit ffaed739a8
No known key found for this signature in database
GPG Key ID: D854DA56315E026A
2 changed files with 47 additions and 0 deletions

View File

@ -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)
{

View File

@ -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,