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:
parent
cb1e4509fe
commit
fb2f686c68
4 changed files with 22 additions and 21 deletions
|
@ -45,7 +45,7 @@ static bool ivshmem_configure_interrupts(const struct device *dev)
|
||||||
|
|
||||||
key = irq_lock();
|
key = irq_lock();
|
||||||
|
|
||||||
n_vectors = pcie_msi_vectors_allocate(data->bdf,
|
n_vectors = pcie_msi_vectors_allocate(data->pcie->bdf,
|
||||||
CONFIG_IVSHMEM_INT_PRIORITY,
|
CONFIG_IVSHMEM_INT_PRIORITY,
|
||||||
data->vectors,
|
data->vectors,
|
||||||
CONFIG_IVSHMEM_MSI_X_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].dev = dev;
|
||||||
data->params[i].vector = i;
|
data->params[i].vector = i;
|
||||||
|
|
||||||
if (!pcie_msi_vector_connect(data->bdf,
|
if (!pcie_msi_vector_connect(data->pcie->bdf,
|
||||||
&data->vectors[i],
|
&data->vectors[i],
|
||||||
ivshmem_doorbell,
|
ivshmem_doorbell,
|
||||||
&data->params[i], 0)) {
|
&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);
|
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");
|
LOG_ERR("Could not enable MSI-X");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ static bool ivshmem_configure(const struct device *dev)
|
||||||
struct ivshmem *data = dev->data;
|
struct ivshmem *data = dev->data;
|
||||||
struct pcie_bar mbar_regs, mbar_mem;
|
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
|
#ifdef CONFIG_IVSHMEM_DOORBELL
|
||||||
LOG_ERR("ivshmem regs bar not found");
|
LOG_ERR("ivshmem regs bar not found");
|
||||||
return false;
|
return false;
|
||||||
|
@ -120,13 +120,13 @@ static bool ivshmem_configure(const struct device *dev)
|
||||||
sizeof(struct ivshmem_reg), K_MEM_CACHE_NONE);
|
sizeof(struct ivshmem_reg), K_MEM_CACHE_NONE);
|
||||||
#endif /* CONFIG_IVSHMEM_DOORBELL */
|
#endif /* CONFIG_IVSHMEM_DOORBELL */
|
||||||
} else {
|
} 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,
|
device_map(DEVICE_MMIO_RAM_PTR(dev), mbar_regs.phys_addr,
|
||||||
mbar_regs.size, K_MEM_CACHE_NONE);
|
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");
|
LOG_ERR("ivshmem mem bar not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -227,24 +227,24 @@ static int ivshmem_init(const struct device *dev)
|
||||||
struct ivshmem *data = dev->data;
|
struct ivshmem *data = dev->data;
|
||||||
static bool bdf_lookup_done;
|
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"
|
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"
|
"Using more than one with PCIE_BDF_NONE parameter might conflict\n"
|
||||||
"with already initialized instances.");
|
"with already initialized instances.");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
if ((data->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
|
if ((data->pcie->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
|
||||||
if (data->dev_ven_id) {
|
if (data->pcie->id == PCIE_ID_NONE) {
|
||||||
data->bdf = pcie_bdf_lookup(data->dev_ven_id);
|
data->pcie->id = PCIE_ID(IVSHMEM_VENDOR_ID,
|
||||||
} else {
|
IVSHMEM_DEVICE_ID);
|
||||||
data->bdf = pcie_bdf_lookup(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");
|
LOG_WRN("ivshmem device not found");
|
||||||
return -ENOTSUP;
|
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;
|
bdf_lookup_done = true;
|
||||||
|
|
||||||
if (!ivshmem_configure(dev)) {
|
if (!ivshmem_configure(dev)) {
|
||||||
|
@ -254,9 +254,9 @@ static int ivshmem_init(const struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IVSHMEM_DEVICE_INIT(n) \
|
#define IVSHMEM_DEVICE_INIT(n) \
|
||||||
|
DEVICE_PCIE_INST_DECLARE(n); \
|
||||||
static struct ivshmem ivshmem_data_##n = { \
|
static struct ivshmem ivshmem_data_##n = { \
|
||||||
.bdf = DT_INST_REG_ADDR_BY_IDX(n, 0), \
|
DEVICE_PCIE_INST_INIT(n, pcie), \
|
||||||
.dev_ven_id = DT_INST_REG_SIZE_BY_IDX(n, 0) \
|
|
||||||
}; \
|
}; \
|
||||||
DEVICE_DT_INST_DEFINE(n, &ivshmem_init, NULL, \
|
DEVICE_DT_INST_DEFINE(n, &ivshmem_init, NULL, \
|
||||||
&ivshmem_data_##n, NULL, \
|
&ivshmem_data_##n, NULL, \
|
||||||
|
|
|
@ -24,8 +24,7 @@ struct ivshmem_param {
|
||||||
|
|
||||||
struct ivshmem {
|
struct ivshmem {
|
||||||
DEVICE_MMIO_RAM;
|
DEVICE_MMIO_RAM;
|
||||||
pcie_bdf_t bdf;
|
struct pcie_dev *pcie;
|
||||||
uint32_t dev_ven_id;
|
|
||||||
uintptr_t shmem;
|
uintptr_t shmem;
|
||||||
size_t size;
|
size_t size;
|
||||||
#ifdef CONFIG_IVSHMEM_DOORBELL
|
#ifdef CONFIG_IVSHMEM_DOORBELL
|
||||||
|
|
|
@ -5,4 +5,4 @@ description: ivShMem device properties
|
||||||
|
|
||||||
compatible: "qemu,ivshmem"
|
compatible: "qemu,ivshmem"
|
||||||
|
|
||||||
include: base.yaml
|
include: [base.yaml, pcie-device.yaml]
|
||||||
|
|
|
@ -12,10 +12,12 @@
|
||||||
compatible = "intel,pcie";
|
compatible = "intel,pcie";
|
||||||
ranges;
|
ranges;
|
||||||
|
|
||||||
ivshmem0: ivshmem@800 {
|
ivshmem0: ivshmem0 {
|
||||||
compatible = "qemu,ivshmem";
|
compatible = "qemu,ivshmem";
|
||||||
|
|
||||||
reg = <PCIE_BDF_NONE PCIE_ID(0x1af4,0x1110)>;
|
vendor-id = <0x1af4>;
|
||||||
|
device-id = <0x1110>;
|
||||||
|
|
||||||
status = "okay";
|
status = "okay";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue