Add a helper function for matching a device against a given vendor and device ID. This will be used in a subsequent commit to match devices against drivers.
Signed-off-by: David Matlack dmatlack@google.com --- tools/testing/selftests/vfio/lib/include/vfio_util.h | 7 +++++++ tools/testing/selftests/vfio/vfio_pci_device_test.c | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/vfio/lib/include/vfio_util.h b/tools/testing/selftests/vfio/lib/include/vfio_util.h index 2b96be07f182..df56c84273e8 100644 --- a/tools/testing/selftests/vfio/lib/include/vfio_util.h +++ b/tools/testing/selftests/vfio/lib/include/vfio_util.h @@ -153,4 +153,11 @@ static inline void vfio_pci_msix_disable(struct vfio_pci_device *device) iova_t __to_iova(struct vfio_pci_device *device, void *vaddr); iova_t to_iova(struct vfio_pci_device *device, void *vaddr);
+static inline bool vfio_pci_device_match(struct vfio_pci_device *device, + u16 vendor_id, u16 device_id) +{ + return (vendor_id == vfio_pci_config_readw(device, PCI_VENDOR_ID)) && + (device_id == vfio_pci_config_readw(device, PCI_DEVICE_ID)); +} + #endif /* SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H */ diff --git a/tools/testing/selftests/vfio/vfio_pci_device_test.c b/tools/testing/selftests/vfio/vfio_pci_device_test.c index 27f60cccd3a7..1a26df0f2280 100644 --- a/tools/testing/selftests/vfio/vfio_pci_device_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_device_test.c @@ -54,9 +54,7 @@ TEST_F(vfio_pci_device_test, config_space_read_write) /* Check that Vendor and Device match what the kernel reports. */ vendor = read_pci_id_from_sysfs("vendor"); device = read_pci_id_from_sysfs("device"); - - ASSERT_EQ(vendor, vfio_pci_config_readw(self->device, PCI_VENDOR_ID)); - ASSERT_EQ(device, vfio_pci_config_readw(self->device, PCI_DEVICE_ID)); + ASSERT_TRUE(vfio_pci_device_match(self->device, vendor, device));
printf("Vendor: %04x, Device: %04x\n", vendor, device);