Skip to content

Commit 935ebc0

Browse files
Johan Hedbergnashif
authored andcommitted
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 <[email protected]>
1 parent d01fa56 commit 935ebc0

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

drivers/virtualization/virt_ivshmem.c

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -103,43 +103,6 @@ static const struct ivshmem_reg no_reg;
103103

104104
#endif /* CONFIG_IVSHMEM_DOORBELL */
105105

106-
static bool ivshmem_check_on_bdf(pcie_bdf_t bdf)
107-
{
108-
uint32_t data;
109-
110-
data = pcie_conf_read(bdf, PCIE_CONF_ID);
111-
if ((data != PCIE_ID_NONE) &&
112-
(PCIE_ID_TO_VEND(data) == IVSHMEM_VENDOR_ID) &&
113-
(PCIE_ID_TO_DEV(data) == IVSHMEM_DEVICE_ID)) {
114-
return true;
115-
}
116-
117-
return false;
118-
}
119-
120-
/* Ivshmem's BDF is not a static value that we could get from DTS,
121-
* since the same image could run on qemu or ACRN which could set
122-
* a different one. So instead, let's find it at runtime.
123-
*/
124-
static pcie_bdf_t ivshmem_bdf_lookup(void)
125-
{
126-
int bus, dev, func;
127-
128-
for (bus = 0; bus <= MAX_BUS; bus++) {
129-
for (dev = 0; dev <= MAX_DEV; ++dev) {
130-
for (func = 0; func <= MAX_FUNC; ++func) {
131-
pcie_bdf_t bdf = PCIE_BDF(bus, dev, func);
132-
133-
if (ivshmem_check_on_bdf(bdf)) {
134-
return bdf;
135-
}
136-
}
137-
}
138-
}
139-
140-
return 0;
141-
}
142-
143106
static bool ivshmem_configure(const struct device *dev)
144107
{
145108
struct ivshmem *data = dev->data;
@@ -261,8 +224,9 @@ static int ivshmem_init(const struct device *dev)
261224
{
262225
struct ivshmem *data = dev->data;
263226

264-
data->bdf = ivshmem_bdf_lookup();
265-
if (data->bdf == 0) {
227+
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID,
228+
IVSHMEM_DEVICE_ID));
229+
if (data->bdf == PCIE_BDF_NONE) {
266230
LOG_WRN("ivshmem device not found");
267231
return -ENOTSUP;
268232
}

drivers/virtualization/virt_ivshmem.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#define IVSHMEM_PCIE_REG_BAR_IDX 0
1717
#define IVSHMEM_PCIE_SHMEM_BAR_IDX 2
1818

19-
#define MAX_BUS (0xFFFFFFFF & PCIE_BDF_BUS_MASK)
20-
#define MAX_DEV (0xFFFFFFFF & PCIE_BDF_DEV_MASK)
21-
#define MAX_FUNC (0xFFFFFFFF & PCIE_BDF_FUNC_MASK)
22-
2319
struct ivshmem_param {
2420
const struct device *dev;
2521
struct k_poll_signal *signal;

0 commit comments

Comments
 (0)