Thread (123 messages) 123 messages, 7 authors, 2017-07-08
STALE3312d

Revision v5 of 8 in this series.

Revisions (8)
  1. v1 [diff vs current]
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 current
  6. v6 [diff vs current]
  7. v7 [diff vs current]
  8. v8 [diff vs current]

[PATCH v5 4/7] pci: implement parse bus operation

From: Gaetan Rivet <hidden>
Date: 2017-06-20 23:30:54
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

Signed-off-by: Gaetan Rivet <redacted>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 16 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 5 files changed, 63 insertions(+)
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b6bf57e..e69ce38 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -215,3 +215,19 @@ rte_bus_find_device(const struct rte_device *start,
 	}
 	return dev;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	return rte_bus_find(bus_cmp_name, str, NULL);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 00d48d9..0f3ecdb 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -450,6 +450,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -505,6 +523,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 05503ea..da8b8a1 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -268,6 +268,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help