From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id 9F3757CFA for ; Thu, 1 Jun 2017 12:12:13 +0200 (CEST) Received: by mail-wm0-f53.google.com with SMTP id 7so151451111wmo.1 for ; Thu, 01 Jun 2017 03:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=OUk9woXGiJc+ju1hZ+B7wXB+xyT5K+eMaa1bIAZEEYc=; b=z89hd2DeeuWk+Zh+Lm8x7IJcMB4u5eimUiFdfpfvci1vHFd+DkKWopis5rQSRpu1zf kmQvlp1gTgpDAp2mzTC9Whw+usv1DQtraVJoaA0ysg6ZbX7099Alv1CFy9s1QEzhD1wu oju93G4HCzkwafPCakf7qj4AR5iTWeYK6bHrj87Lon0RLaJyA7LIM61rn4+2tizUFaFe wND0tiJZtKT3XbqduRaTOiDvpEbVoTzXXGF8suatnv/ejV9wrqVhMVRvlONcRoZvCyPv Lc8gEnb8WMAUFIA98vFg2s3rWpAR5oRzNoE4ehfZXF1l8/UGbi52gupWZDs920d1NL3D 2fRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=OUk9woXGiJc+ju1hZ+B7wXB+xyT5K+eMaa1bIAZEEYc=; b=rB81LqFwuBMx7Y4xp91EGN33dT91DFEV9oQf9qRlIBmgCxVa74qsgzRXlSxeDxc4Ri IxcV8np4ST/c7ZHK9FAeCkLwRD60CjCM0qEd/RqwuY6i/t3eL2VxGcnj0+x90HBPG6AN 4kJpGCPl5pfaFiWET452ZSTb8zKGR/8LAhgxE0/pPGYQ21K+YXuxSa61iq2YPb37963J 2x2Up1zyJu8feBnCznMGo1oEI1THEfdd+aQt1nCl2phaHiJM/lSIV1SPpirDUoUW+eYv fSkgCEHTUXUdG1r4bDZbBRoimXhRTkC93AgKDQhWRzzWTzvMONhW1nAzv2HLNdkyJCG9 gzfg== X-Gm-Message-State: AODbwcDT+g2KU+PxaWPcfmqG2WhyKnM4fMKVyQF4KN+3t21zi9SV53Uh itsP0mQ3CZOWcUg+b+0= X-Received: by 10.223.157.11 with SMTP id k11mr647049wre.71.1496311933051; Thu, 01 Jun 2017 03:12:13 -0700 (PDT) Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id e83sm33697524wmc.28.2017.06.01.03.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Jun 2017 03:12:12 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 1 Jun 2017 12:12:00 +0200 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 1/3] pci: implement plug/unplug bus operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jun 2017 10:12:13 -0000 Signed-off-by: Gaetan Rivet --- 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 #include #include +#include #include #include #include @@ -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