[dpdk-dev,v2,1/3] pci: implement plug/unplug bus operation
Checks
Commit Message
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_eal/common/eal_common_pci.c | 56 ++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
@@ -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>
@@ -545,12 +546,67 @@ pci_find_device(rte_dev_match_t match, const void *data)
return NULL;
}
+static int
+pci_plug(struct rte_devargs *da)
+{
+ struct rte_pci_device *pdev;
+ struct rte_pci_addr addr;
+
+ if (da == NULL)
+ return -EINVAL;
+ if (pci_parse(da->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. */
+ if (pdev->device.devargs &&
+ da != pdev->device.devargs) {
+ /* TODO: cleanup free */
+ free(pdev->device.devargs->args);
+ rte_memcpy(pdev->device.devargs, da, sizeof(*da));
+ }
+ break;
+ }
+ if (rte_pci_probe_one(&addr))
+ return -ENODEV;
+ /* Get back new device name. */
+ if (pdev->device.devargs &&
+ da != pdev->device.devargs)
+ snprintf(da->name, sizeof(da->name), "%s",
+ pdev->device.devargs->name);
+ return 0;
+}
+
+static int
+pci_unplug(struct rte_devargs *da)
+{
+ struct rte_pci_addr addr;
+
+ if (da == NULL)
+ return -EINVAL;
+ if (pci_parse(da->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,
+ .plug = pci_plug,
+ .unplug = pci_unplug,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),