From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by dpdk.org (Postfix) with ESMTP id C4DD5FB2F for ; Thu, 19 Jan 2017 05:45:31 +0100 (CET) Received: by mail-wm0-f52.google.com with SMTP id r144so58582265wme.1 for ; Wed, 18 Jan 2017 20:45:31 -0800 (PST) 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; bh=URtmZYtc1y/K8dGXXSWNs2FkGEMTa4AUlPfcj3WQMbM=; b=xLikQlSNe3IaRE5D6nugQcqhr7lR9VHy9UNntITubGB5MhXZBZSYGOZwR+6NQFzqnf STdwFyOYTYlcF1rQ+N/94/HmRgTSEyWwAxfhzOLObTFu45Lc8cIvEVYgXD5pCVu4yg9P HlJ9zD9L2OIukCodaHB0XUcYRSH6/ThP2JEwOLbP8KuqBmrC0b00q6dTlKmi/PeX7uGD K9MSxCiYquIIVSFeSJFZH+Kt2cWiz1GLP5Akr87yuyJczu6kEPv3TBvegaV4VfcL1Bn8 hpUz6tPpm7/HylklAz/VmjocyXjnnCVb7QLs+MsC1HnWpZgJz/MuezGMG6sFzlD0T+Q7 0+6Q== 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; bh=URtmZYtc1y/K8dGXXSWNs2FkGEMTa4AUlPfcj3WQMbM=; b=D81PoDEWUjbLUFeogHY1wA7rPh8/qeNN0JrZHfZMLqClslN+/G817Ej8u59+use8Mi vgDXpAIwx85pxJnKuSLqu6DRPaMsyRzUiyUmXjzwWG633Qvj/emeWAoGMRGuMQLt49bK iGxP0hR62o+tatsPyTMdS0Aai0G/8VM1j719wLp6gJYXT85QBNZ2kS/dNXGwTLOqYS0N UROKeEU1KyKU88BWc/UR6DUy+F1Ig86u1kZ/EdHxcsRQ+6o7aLTctimf5qOvruxnp0qt m2i+uskkXqyt5wfQCSyO2lPblFdc+KlkLeoOgHUhEGcxq4kHlhwE4xpxwX9gbsMJVaBm LPmA== X-Gm-Message-State: AIkVDXItL+Latw8HmRm8nOYvUZI0mciQ2cs/E5MRRqnSTjRvAo+yzixN6zhbx46YViI2+JRq X-Received: by 10.28.54.90 with SMTP id d87mr24322821wma.89.1484801131413; Wed, 18 Jan 2017 20:45:31 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id t194sm2568586wmd.1.2017.01.18.20.45.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Jan 2017 20:45:30 -0800 (PST) From: Thomas Monjalon To: Shreyansh Jain Cc: dev@dpdk.org Date: Thu, 19 Jan 2017 05:45:13 +0100 Message-Id: <1484801117-779-10-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1484801117-779-1-git-send-email-thomas.monjalon@6wind.com> References: <1484748329-5418-1-git-send-email-shreyansh.jain@nxp.com> <1484801117-779-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH v11 09/13] 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: Thu, 19 Jan 2017 04:45:32 -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 --- lib/librte_eal/bsdapp/eal/eal.c | 1 + lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++++ lib/librte_eal/common/eal_common_pci.c | 25 +++++++++++++ lib/librte_eal/common/include/rte_pci.h | 65 +++++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 12 ++++++ 5 files changed, 114 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 534aeea..ee7c9de 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 3a5c315..48bfe24 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -673,3 +673,14 @@ rte_eal_pci_init(void) } return 0; } + +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_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 8b4ae2d..c53e2bd 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -87,6 +88,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) @@ -479,3 +482,25 @@ 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); +} diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index adc20b9..957cddb 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 */ @@ -523,6 +553,41 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__) void rte_eal_pci_unregister(struct rte_pci_driver *driver); /** + * 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); + +/** * Read PCI config space. * * @param device diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index e2fc219..c40814d 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 @@ -723,3 +724,14 @@ rte_eal_pci_init(void) return 0; } + +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); -- 2.7.0