[dpdk-dev,1/3] pci: implement attach/detach bus operation

Message ID 4ae996fef85b87917d442f7700c7a0239531d641.1495629219.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Gaëtan Rivet May 24, 2017, 3:18 p.m. UTC
  Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 50 ++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 6d9fdda..269abb8 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -76,6 +76,7 @@ 
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
+#include <rte_memcpy.h>
 #include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_string_fns.h>
@@ -546,12 +547,61 @@  pci_find_device(int (*match)(const struct rte_device *dev, const void *data),
 	return NULL;
 }
 
+static int
+pci_attach(struct rte_device *dev)
+{
+	struct rte_pci_device *pdev;
+	struct rte_pci_addr addr;
+
+	if (dev == NULL)
+		return -EINVAL;
+	if (pci_parse(dev->name, &addr))
+		return -EFAULT;
+	/*
+	 * Update eventual pci device in global list.
+	 * Insert it if none was found.
+	 */
+	if (pci_update_device(&addr) < 0)
+		return -EIO;
+	/* Find the current device holding this address in the bus. */
+	FOREACH_DEVICE_ON_PCIBUS(pdev) {
+		if (rte_eal_compare_pci_addr(&pdev->addr, &addr))
+			continue;
+		/* Update eventual devargs, others device infos. */
+		if (dev != &pdev->device)
+			rte_memcpy(&pdev->device, dev, sizeof(*dev));
+		break;
+	}
+	if (rte_pci_probe_one(&addr))
+		return -ENODEV;
+	/* Get back new device info. */
+	if (dev != &pdev->device)
+		rte_memcpy(dev, &pdev->device, sizeof(*dev));
+	return 0;
+}
+
+static int
+pci_detach(struct rte_device *dev)
+{
+	struct rte_pci_addr addr;
+
+	if (dev == NULL)
+		return -EINVAL;
+	if (pci_parse(dev->name, &addr))
+		return -EFAULT;
+	if (rte_pci_detach(&addr))
+		return -ENODEV;
+	return 0;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
 		.parse = pci_parse,
+		.attach = pci_attach,
+		.detach = pci_detach,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),