diff --git a/include/spdk/env.h b/include/spdk/env.h index 5d6ed8d96..4f3bb9bea 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -728,6 +728,25 @@ struct spdk_pci_driver *spdk_pci_virtio_get_driver(void); */ int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx); +/** + * Begin iterating over enumerated PCI device by calling this function to get + * the first PCI device. If there no PCI devices enumerated, return NULL + * + * \return a pointer to a PCI device on success, NULL otherwise. + */ +struct spdk_pci_device *spdk_pci_get_first_device(void); + +/** + * Continue iterating over enumerated PCI devices. + * If no additional PCI devices, return NULL + * + * \param prev Previous PCI device returned from \ref spdk_pci_get_first_device + * or \ref spdk_pci_get_next_device + * + * \return a pointer to the next PCI device on success, NULL otherwise. + */ +struct spdk_pci_device *spdk_pci_get_next_device(struct spdk_pci_device *prev); + /** * Map a PCI BAR in the current process. * diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index 31dec6f58..25695ad7c 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -464,6 +464,18 @@ spdk_pci_enumerate(struct spdk_pci_driver *driver, return 0; } +struct spdk_pci_device * +spdk_pci_get_first_device(void) +{ + return TAILQ_FIRST(&g_pci_devices); +} + +struct spdk_pci_device * +spdk_pci_get_next_device(struct spdk_pci_device *prev) +{ + return TAILQ_NEXT(prev, internal.tailq); +} + int spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar, void **mapped_addr, uint64_t *phys_addr, uint64_t *size)