From aba747fe19ad6840d18c64d20b7591e6871e52a8 Mon Sep 17 00:00:00 2001 From: Gaetan Rivet Date: Thu, 26 Oct 2017 12:05:59 +0200 Subject: [PATCH] pci: introduce PCI address parsing function A new single function that is able to parse all currently supported format: * Domain-Bus-Device-Function * Bus-Device-Function Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_pci.c | 9 +++++++++ lib/librte_eal/common/include/rte_pci.h | 14 ++++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 24 insertions(+) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 2230e0995c..d01b0f9d5b 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -199,6 +199,15 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, return rte_pci_addr_cmp(addr, addr2); } +int +rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr) +{ + if (rte_pci_bdf_parse(str, addr) == 0 || + rte_pci_dbdf_parse(str, addr) == 0) + return 0; + return -1; +} + void pci_name_set(struct rte_pci_device *dev) { diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 9ac19d5bed..11ba442be2 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -346,6 +346,20 @@ int rte_pci_addr_cmp(const struct rte_pci_addr *addr, int rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, const struct rte_pci_addr *addr2); +/** + * Utility function to parse a string into a PCI location. + * + * @param str + * The string to parse + * @param addr + * The reference to the structure where the location + * is stored. + * @return + * 0 on success + * <0 otherwise + */ +int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr); + /** * Scan the content of the PCI bus, and the devices in the devices * list diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 5cad972b1a..3568694367 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -254,6 +254,7 @@ DPDK_17.11 { rte_lcore_has_role; rte_memcpy_ptr; rte_pci_addr_cmp; + rte_pci_addr_parse; rte_pci_bdf_parse; rte_pci_dbdf_parse; rte_pci_device_name; -- 2.20.1