From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gaetan Rivet Subject: [PATCH v3 1/3] pci: implement hotplug bus operation Date: Thu, 8 Jun 2017 01:58:28 +0200 Message-ID: <60a7c41e72b5aa9bb17e4729d081ec0a783b9054.1496876926.git.gaetan.rivet@6wind.com> References: Cc: Gaetan Rivet To: dev@dpdk.org Return-path: Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by dpdk.org (Postfix) with ESMTP id AF6E137A2 for ; Thu, 8 Jun 2017 01:58:43 +0200 (CEST) Received: by mail-wm0-f41.google.com with SMTP id m7so35446372wmg.0 for ; Wed, 07 Jun 2017 16:58:43 -0700 (PDT) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_pci.c | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index b4f8056..6049b49 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -517,12 +518,78 @@ pci_find_device(rte_dev_cmp_t cmp, const void *data) return NULL; } +static struct rte_device * +pci_plug(struct rte_devargs *da) +{ + struct rte_pci_device *pdev; + struct rte_pci_addr addr; + + if (pci_parse(da->name, &addr)) { + rte_errno = EFAULT; + return NULL; + } + /* + * Update eventual pci device in global list. + * Insert it if none was found. + */ + if (pci_update_device(&addr) < 0) { + rte_errno = EIO; + return NULL; + } + /* 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. */ + pdev->device.devargs = rte_eal_devargs_clone(da); + if (pdev->device.devargs == NULL) { + rte_errno = ENOMEM; + return NULL; + } + break; + } + if (rte_pci_probe_one(&addr)) { + rte_errno = ENODEV; + return NULL; + } + /* 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 &pdev->device; +} + +static int +pci_unplug(struct rte_device *dev) +{ + struct rte_pci_addr addr; + + if (dev == NULL) { + rte_errno = EINVAL; + return -1; + } + if (pci_parse(dev->name, &addr)) { + rte_errno = EFAULT; + return -1; + } + if (rte_pci_detach(&addr)) { + rte_errno = ENODEV; + return -1; + } + if (dev->devargs) + rte_eal_devargs_rmv(dev->devargs); + 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