Signed-off-by: Gaetan Rivet <gaetan.ri...@6wind.com> --- lib/librte_eal/common/eal_common_pci.c | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 2a52b9e..580ce86 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> @@ -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), -- 2.1.4