drivers: virtualization: ivshmem: Convert to use dynamic BDF lookup

Use the new PCIe core infrastructure for looking up the BDF at runtime
based on the VID/DID values.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2022-11-11 13:15:55 +02:00 committed by Carles Cufí
parent cb1e4509fe
commit fb2f686c68
4 changed files with 22 additions and 21 deletions

View File

@ -45,7 +45,7 @@ static bool ivshmem_configure_interrupts(const struct device *dev)
key = irq_lock();
n_vectors = pcie_msi_vectors_allocate(data->bdf,
n_vectors = pcie_msi_vectors_allocate(data->pcie->bdf,
CONFIG_IVSHMEM_INT_PRIORITY,
data->vectors,
CONFIG_IVSHMEM_MSI_X_VECTORS);
@ -61,7 +61,7 @@ static bool ivshmem_configure_interrupts(const struct device *dev)
data->params[i].dev = dev;
data->params[i].vector = i;
if (!pcie_msi_vector_connect(data->bdf,
if (!pcie_msi_vector_connect(data->pcie->bdf,
&data->vectors[i],
ivshmem_doorbell,
&data->params[i], 0)) {
@ -72,7 +72,7 @@ static bool ivshmem_configure_interrupts(const struct device *dev)
LOG_DBG("%u MSI-X Vectors connected", n_vectors);
if (!pcie_msi_enable(data->bdf, data->vectors, n_vectors, 0)) {
if (!pcie_msi_enable(data->pcie->bdf, data->vectors, n_vectors, 0)) {
LOG_ERR("Could not enable MSI-X");
goto out;
}
@ -110,7 +110,7 @@ static bool ivshmem_configure(const struct device *dev)
struct ivshmem *data = dev->data;
struct pcie_bar mbar_regs, mbar_mem;
if (!pcie_get_mbar(data->bdf, IVSHMEM_PCIE_REG_BAR_IDX, &mbar_regs)) {
if (!pcie_get_mbar(data->pcie->bdf, IVSHMEM_PCIE_REG_BAR_IDX, &mbar_regs)) {
#ifdef CONFIG_IVSHMEM_DOORBELL
LOG_ERR("ivshmem regs bar not found");
return false;
@ -120,13 +120,13 @@ static bool ivshmem_configure(const struct device *dev)
sizeof(struct ivshmem_reg), K_MEM_CACHE_NONE);
#endif /* CONFIG_IVSHMEM_DOORBELL */
} else {
pcie_set_cmd(data->bdf, PCIE_CONF_CMDSTAT_MEM, true);
pcie_set_cmd(data->pcie->bdf, PCIE_CONF_CMDSTAT_MEM, true);
device_map(DEVICE_MMIO_RAM_PTR(dev), mbar_regs.phys_addr,
mbar_regs.size, K_MEM_CACHE_NONE);
}
if (!pcie_get_mbar(data->bdf, IVSHMEM_PCIE_SHMEM_BAR_IDX, &mbar_mem)) {
if (!pcie_get_mbar(data->pcie->bdf, IVSHMEM_PCIE_SHMEM_BAR_IDX, &mbar_mem)) {
LOG_ERR("ivshmem mem bar not found");
return false;
}
@ -227,24 +227,24 @@ static int ivshmem_init(const struct device *dev)
struct ivshmem *data = dev->data;
static bool bdf_lookup_done;
if ((data->bdf == PCIE_BDF_NONE) && bdf_lookup_done) {
if ((data->pcie->bdf == PCIE_BDF_NONE) && bdf_lookup_done) {
LOG_ERR("One instance of ivshmem with pcie_bdf_lookup() already initialized.\n"
"Using more than one with PCIE_BDF_NONE parameter might conflict\n"
"with already initialized instances.");
return -ENOTSUP;
}
if ((data->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
if (data->dev_ven_id) {
data->bdf = pcie_bdf_lookup(data->dev_ven_id);
} else {
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID, IVSHMEM_DEVICE_ID));
if ((data->pcie->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
if (data->pcie->id == PCIE_ID_NONE) {
data->pcie->id = PCIE_ID(IVSHMEM_VENDOR_ID,
IVSHMEM_DEVICE_ID);
data->pcie->bdf = pcie_bdf_lookup(data->pcie->id);
}
if (data->bdf == PCIE_BDF_NONE) {
if (data->pcie->bdf == PCIE_BDF_NONE) {
LOG_WRN("ivshmem device not found");
return -ENOTSUP;
}
}
LOG_DBG("ivshmem found at bdf 0x%x", data->bdf);
LOG_DBG("ivshmem found at bdf 0x%x", data->pcie->bdf);
bdf_lookup_done = true;
if (!ivshmem_configure(dev)) {
@ -254,9 +254,9 @@ static int ivshmem_init(const struct device *dev)
}
#define IVSHMEM_DEVICE_INIT(n) \
DEVICE_PCIE_INST_DECLARE(n); \
static struct ivshmem ivshmem_data_##n = { \
.bdf = DT_INST_REG_ADDR_BY_IDX(n, 0), \
.dev_ven_id = DT_INST_REG_SIZE_BY_IDX(n, 0) \
DEVICE_PCIE_INST_INIT(n, pcie), \
}; \
DEVICE_DT_INST_DEFINE(n, &ivshmem_init, NULL, \
&ivshmem_data_##n, NULL, \

View File

@ -24,8 +24,7 @@ struct ivshmem_param {
struct ivshmem {
DEVICE_MMIO_RAM;
pcie_bdf_t bdf;
uint32_t dev_ven_id;
struct pcie_dev *pcie;
uintptr_t shmem;
size_t size;
#ifdef CONFIG_IVSHMEM_DOORBELL

View File

@ -5,4 +5,4 @@ description: ivShMem device properties
compatible: "qemu,ivshmem"
include: base.yaml
include: [base.yaml, pcie-device.yaml]

View File

@ -12,10 +12,12 @@
compatible = "intel,pcie";
ranges;
ivshmem0: ivshmem@800 {
ivshmem0: ivshmem0 {
compatible = "qemu,ivshmem";
reg = <PCIE_BDF_NONE PCIE_ID(0x1af4,0x1110)>;
vendor-id = <0x1af4>;
device-id = <0x1110>;
status = "okay";
};
};