drivers/virtualization: Take advantage of pcie_bdf_lookup()

Use the new pcie_bdf_lookup() API instead of having a custom lookup
function.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2021-02-04 16:21:04 +02:00 committed by Anas Nashif
commit 935ebc0134
2 changed files with 3 additions and 43 deletions

View file

@ -103,43 +103,6 @@ static const struct ivshmem_reg no_reg;
#endif /* CONFIG_IVSHMEM_DOORBELL */
static bool ivshmem_check_on_bdf(pcie_bdf_t bdf)
{
uint32_t data;
data = pcie_conf_read(bdf, PCIE_CONF_ID);
if ((data != PCIE_ID_NONE) &&
(PCIE_ID_TO_VEND(data) == IVSHMEM_VENDOR_ID) &&
(PCIE_ID_TO_DEV(data) == IVSHMEM_DEVICE_ID)) {
return true;
}
return false;
}
/* Ivshmem's BDF is not a static value that we could get from DTS,
* since the same image could run on qemu or ACRN which could set
* a different one. So instead, let's find it at runtime.
*/
static pcie_bdf_t ivshmem_bdf_lookup(void)
{
int bus, dev, func;
for (bus = 0; bus <= MAX_BUS; bus++) {
for (dev = 0; dev <= MAX_DEV; ++dev) {
for (func = 0; func <= MAX_FUNC; ++func) {
pcie_bdf_t bdf = PCIE_BDF(bus, dev, func);
if (ivshmem_check_on_bdf(bdf)) {
return bdf;
}
}
}
}
return 0;
}
static bool ivshmem_configure(const struct device *dev)
{
struct ivshmem *data = dev->data;
@ -261,8 +224,9 @@ static int ivshmem_init(const struct device *dev)
{
struct ivshmem *data = dev->data;
data->bdf = ivshmem_bdf_lookup();
if (data->bdf == 0) {
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID,
IVSHMEM_DEVICE_ID));
if (data->bdf == PCIE_BDF_NONE) {
LOG_WRN("ivshmem device not found");
return -ENOTSUP;
}

View file

@ -16,10 +16,6 @@
#define IVSHMEM_PCIE_REG_BAR_IDX 0
#define IVSHMEM_PCIE_SHMEM_BAR_IDX 2
#define MAX_BUS (0xFFFFFFFF & PCIE_BDF_BUS_MASK)
#define MAX_DEV (0xFFFFFFFF & PCIE_BDF_DEV_MASK)
#define MAX_FUNC (0xFFFFFFFF & PCIE_BDF_FUNC_MASK)
struct ivshmem_param {
const struct device *dev;
struct k_poll_signal *signal;