From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id 3006238EB for ; Tue, 11 Apr 2017 13:07:54 +0200 (CEST) Received: by mail-wm0-f48.google.com with SMTP id t189so58340258wmt.1 for ; Tue, 11 Apr 2017 04:07:54 -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=vDqt2RK19WH5ma1c7XC7rjYvgL6L6uhoTzvFzss1rak=; b=XXkNDlWVE22MFt/GEqBF/GtJo59enGnyBfHma/pMSgYejJK3jdPglNtBu7Yqp8KdVO lm7QoXtLKECdcZihcI41PlehaSbWlJsDjeIWZKAEIAk/6B90UeDtbnEGINCGiTgkkhqg JwopuR4zG4RhdY95MDmV/J5zbVbTfiX2cFBDPXRMtUqiSGthR23nNTdRh+Raxo/NWNNN tRI5k3rsPZ0VLOhuNtscj5Ksrp7ilcqg7OiD23f3RnM/7FiuYb9+3hbUbccS8IsERegK 2LsleKC8N4meHQKW22KlcXgKmwOqTnu08La6SmMPHjn8xGjommnn2VjxLLtww0oRoWDY FR1g== 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=vDqt2RK19WH5ma1c7XC7rjYvgL6L6uhoTzvFzss1rak=; b=DQbGHQHrmU48qdeJAWR9IR/guhSKzGpTU2kpyRX0Qbu4kLwPY9GYnK1zTK2dhtcLfZ uy7N+mE4IiuwQNx2LlKDSbxKOA7Onk9zERvahQWNgnTakmZH6EitYWhWWf30Is73BN2U l/lFN3lAD1NfrrcO/Jrj7nhIaMsbUF2mHwoHpWpdYGBq13Dzht4ViGYNfFNMN/G4HRpx 5KZ/Mxy6XhubLevjIW+1BfIsXeYDyma+GI50zieL6RnLcpNy24iR0wnXhbvBtH1T/gNj sM4GusEIUd5M3YXIILGbYgHSO0uJrK0GYS2ZWY420Qv7VnJq1liYNSMZiNwHhEPFCeDS QNCA== X-Gm-Message-State: AN3rC/7d4x9eDgx6O/QHyH7yZ/pi28mtJfHvanNPx4MWnxM+/JGGpfkMjhH2QwAy7oUIbyhw X-Received: by 10.28.238.213 with SMTP id j82mr11782165wmi.43.1491908874030; Tue, 11 Apr 2017 04:07:54 -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 g15sm1151735wmc.14.2017.04.11.04.07.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 11 Apr 2017 04:07:53 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Shreyansh Jain , Thomas Monjalon Date: Tue, 11 Apr 2017 13:07:31 +0200 Message-Id: <5f675518436b5a18885d26e69eb9d55a27a95147.1491906224.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 v13 4/7] pci: add bus driver 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: Tue, 11 Apr 2017 11:07:55 -0000 From: Shreyansh Jain Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch. EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices. Signed-off-by: Shreyansh Jain Reviewed-by: Ferruh Yigit Signed-off-by: Thomas Monjalon Reviewed-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/eal_pci.c | 2 ++ lib/librte_eal/common/eal_common_pci.c | 36 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 35 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 30 +++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 3 +++ 5 files changed, 106 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 16a1743..6ef8781 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -87,6 +87,8 @@ * enabling bus master. */ +extern struct rte_pci_bus rte_pci_bus; + /* Map pci device */ int rte_eal_pci_map_device(struct rte_pci_device *dev) diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 498a3bb..5ac050a 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -72,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,8 @@ struct pci_driver_list pci_driver_list = struct pci_device_list pci_device_list = TAILQ_HEAD_INITIALIZER(pci_device_list); +extern struct rte_pci_bus rte_pci_bus; + #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" const char *pci_get_sysfs_path(void) @@ -489,3 +492,36 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver) rte_eal_driver_unregister(&driver->driver); TAILQ_REMOVE(&pci_driver_list, driver, next); } + +/* Add a device to PCI bus */ +void +rte_eal_pci_add_device(struct rte_pci_device *pci_dev) +{ + TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next); +} + +/* Insert a device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev, + struct rte_pci_device *new_pci_dev) +{ + TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next); +} + +/* Remove a device from PCI bus */ +void +rte_eal_pci_remove_device(struct rte_pci_device *pci_dev) +{ + TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next); +} + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), + .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus); diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 8b2d323..47c84df 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -123,6 +123,41 @@ struct rte_pci_driver; struct rte_pci_device; /** + * Add a PCI device to the PCI Bus (append to PCI Device list). This function + * also updates the bus references of the PCI Device (and the generic device + * object embedded within. + * + * @param pci_dev + * PCI device to add + * @return void + */ +void rte_eal_pci_add_device(struct rte_pci_device *pci_dev); + +/** + * Insert a PCI device in the PCI Bus at a particular location in the device + * list. It also updates the PCI Bus reference of the new devices to be + * inserted. + * + * @param exist_pci_dev + * Existing PCI device in PCI Bus + * @param new_pci_dev + * PCI device to be added before exist_pci_dev + * @return void + */ +void rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev, + struct rte_pci_device *new_pci_dev); + +/** + * Remove a PCI device from the PCI Bus. This sets to NULL the bus references + * in the PCI device object as well as the generic device object. + * + * @param pci_device + * PCI device to be removed from PCI Bus + * @return void + */ +void rte_eal_pci_remove_device(struct rte_pci_device *pci_device); + +/** * Update a pci device object by asking the kernel for the latest information. * * This function is private to EAL. diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 8557e47..729429f 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -85,6 +85,7 @@ extern "C" { #include #include #include +#include TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */ TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */ @@ -111,6 +112,25 @@ const char *pci_get_sysfs_path(void); /** Maximum number of PCI resources. */ #define PCI_MAX_RESOURCE 6 +/** Name of PCI Bus */ +#define PCI_BUS_NAME "PCI" + +/* Forward declarations */ +struct rte_pci_device; +struct rte_pci_driver; + +/** List of PCI devices */ +TAILQ_HEAD(rte_pci_device_list, rte_pci_device); +/** List of PCI drivers */ +TAILQ_HEAD(rte_pci_driver_list, rte_pci_driver); + +/* PCI Bus iterators */ +#define FOREACH_DEVICE_ON_PCIBUS(p) \ + TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next) + +#define FOREACH_DRIVER_ON_PCIBUS(p) \ + TAILQ_FOREACH(p, &(rte_pci_bus.driver_list), next) + /** * A structure describing an ID for a PCI driver. Each driver provides a * table of these IDs for each device that it supports. @@ -206,12 +226,22 @@ typedef int (pci_remove_t)(struct rte_pci_device *); struct rte_pci_driver { TAILQ_ENTRY(rte_pci_driver) next; /**< Next in list. */ struct rte_driver driver; /**< Inherit core driver. */ + struct rte_pci_bus *bus; /**< PCI bus reference. */ pci_probe_t *probe; /**< Device Probe function. */ pci_remove_t *remove; /**< Device Remove function. */ const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ uint32_t drv_flags; /**< Flags contolling handling of device. */ }; +/** + * Structure describing the PCI bus + */ +struct rte_pci_bus { + struct rte_bus bus; /**< Inherit the generic class */ + struct rte_pci_device_list device_list; /**< List of PCI devices */ + struct rte_pci_driver_list driver_list; /**< List of PCI drivers */ +}; + /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */ #define RTE_PCI_DRV_NEED_MAPPING 0x0001 /** Device driver supports link state interrupt */ diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 7d6f50a..1bd3496 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,8 @@ * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +extern struct rte_pci_bus rte_pci_bus; + static int pci_get_kernel_driver_by_path(const char *filename, char *dri_name) { -- 2.1.4