From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id E6DED7CEF for ; Wed, 24 May 2017 17:18:42 +0200 (CEST) Received: by mail-wm0-f46.google.com with SMTP id m7so23992101wmg.0 for ; Wed, 24 May 2017 08:18:42 -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=+6CtNTiSzT0J5EeqK9ErxcUX7cBEAIMszqbTkY2L9tk=; b=otFk60eW4uTkh9xXxSZ0bCYyVvy+kfH6M2msCQnyxD92hCCrSX/SzPOUdwh2Dd3T3a jBVTkq4Oqbz9uNbYOFYWVKJe2vJ7j9XXnwcZtmqBOBPFRCMVSO9+J7Z2dnsp/2oDVGUG PZKVK+vy1FRQ+u775+7RoS9EE6XDv2swDHIPLUR7d3xLl0mFO/AObLi8BZc0+V+TxYd/ dmMSbKqlBBNWR1coB8ifa5KoMUr1aVpG9v0Xl8UD4CG5IxT8E2cZkzfIjfA+IUerCGDK dPRNcjP50E91xTyg9BmjhoL5o1a+Ux7+mCsocXqQQmrkKk01vZDMVw+PyMf5FMuIdcpa bk+A== 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=+6CtNTiSzT0J5EeqK9ErxcUX7cBEAIMszqbTkY2L9tk=; b=OaFNfrqekaqz69pZx9Lb9bqQkhkIiSZHe87VpIvUxlTuxuyseKCVPbq6d0GTR0G94d y9l1TucuzINst7F+mc6CIULXE9A4fY5LildybY84ZAjQd7AGu+uFCBLezqYZ6l0b59JB sq99SqUJS/LNvqu/9CaX67NKSCJdQTf+TisNYz36i+Z2nZY2uQYeUI/Vaa0hBHh5LEQg sMVEE1uMwO34/RnGk90z0Ef2oMPfi478ATrCtuKh+xSv5EhThX2VGjMeX0QwOaYJvxlV j2U3RXGugip4eVHAUtmvizq9spwACoXiSo4bCLqgt77T/IJ3TZHruRotz/exWgQOw5UV BIHQ== X-Gm-Message-State: AODbwcCCPCxEwHcwrk3tuRS1P19N3CXkDD3obBUZ9vfcHMH2bl/EwxpA MFIs31n1ZobeMiARq7M= X-Received: by 10.28.139.18 with SMTP id n18mr6926286wmd.100.1495639122365; Wed, 24 May 2017 08:18:42 -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 p107sm5880800wrb.64.2017.05.24.08.18.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 May 2017 08:18:41 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet , Jan Blunck , Stephen Hemminger , Maxime Coquelin , Jerin Jacob , David Marchand Date: Wed, 24 May 2017 17:18:29 +0200 Message-Id: <4ae996fef85b87917d442f7700c7a0239531d641.1495629219.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 1/3] pci: implement attach/detach 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: Wed, 24 May 2017 15:18:43 -0000 Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_pci.c | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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 #include #include +#include #include #include #include @@ -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), -- 2.1.4