From: Tiwei Bie <tiwei.bie@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, anatoly.burakov@intel.com,
bruce.richardson@intel.com, keith.wiles@intel.com,
david.marchand@redhat.com, alejandro.lucero@netronome.com,
cunming.liang@intel.com
Subject: [dpdk-dev] [RFC v2 1/5] bus/pci: introduce an internal representation of PCI device
Date: Mon, 15 Jul 2019 15:52:10 +0800 [thread overview]
Message-ID: <20190715075214.16616-2-tiwei.bie@intel.com> (raw)
In-Reply-To: <20190715075214.16616-1-tiwei.bie@intel.com>
This patch introduces an internal representation of the PCI device
which will be used to store the internal information that don't have
to be exposed, e.g. the VFIO region sizes/offsets.
In this patch, the internal structure is simply a wrapper of the
rte_pci_device structure. More fields will be added in the coming
patches.
Suggested-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
---
drivers/bus/pci/bsd/pci.c | 14 ++++++++------
drivers/bus/pci/linux/pci.c | 25 ++++++++++++++-----------
drivers/bus/pci/pci_common.c | 2 +-
drivers/bus/pci/private.h | 12 ++++++++++++
4 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index a2de70910..636868f38 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -213,16 +213,18 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
static int
pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
{
+ struct rte_pci_device_internal *pdev;
struct rte_pci_device *dev;
struct pci_bar_io bar;
unsigned i, max;
- dev = malloc(sizeof(*dev));
- if (dev == NULL) {
+ pdev = malloc(sizeof(*pdev));
+ if (pdev == NULL)
return -1;
- }
- memset(dev, 0, sizeof(*dev));
+ memset(pdev, 0, sizeof(*pdev));
+
+ dev = &pdev->device;
dev->device.bus = &rte_pci_bus.bus;
dev->addr.domain = conf->pc_sel.pc_domain;
@@ -308,7 +310,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
memmove(dev2->mem_resource,
dev->mem_resource,
sizeof(dev->mem_resource));
- free(dev);
+ free(pdev);
}
return 0;
}
@@ -318,7 +320,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
return 0;
skipdev:
- free(dev);
+ free(pdev);
return 0;
}
diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 33c8ea7e9..dfab7b81b 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -219,22 +219,25 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
{
char filename[PATH_MAX];
unsigned long tmp;
+ struct rte_pci_device_internal *pdev;
struct rte_pci_device *dev;
char driver[PATH_MAX];
int ret;
- dev = malloc(sizeof(*dev));
- if (dev == NULL)
+ pdev = malloc(sizeof(*pdev));
+ if (pdev == NULL)
return -1;
- memset(dev, 0, sizeof(*dev));
+ memset(pdev, 0, sizeof(*pdev));
+
+ dev = &pdev->device;
dev->device.bus = &rte_pci_bus.bus;
dev->addr = *addr;
/* get vendor id */
snprintf(filename, sizeof(filename), "%s/vendor", dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
- free(dev);
+ free(pdev);
return -1;
}
dev->id.vendor_id = (uint16_t)tmp;
@@ -242,7 +245,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
/* get device id */
snprintf(filename, sizeof(filename), "%s/device", dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
- free(dev);
+ free(pdev);
return -1;
}
dev->id.device_id = (uint16_t)tmp;
@@ -251,7 +254,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
- free(dev);
+ free(pdev);
return -1;
}
dev->id.subsystem_vendor_id = (uint16_t)tmp;
@@ -260,7 +263,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
snprintf(filename, sizeof(filename), "%s/subsystem_device",
dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
- free(dev);
+ free(pdev);
return -1;
}
dev->id.subsystem_device_id = (uint16_t)tmp;
@@ -269,7 +272,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
snprintf(filename, sizeof(filename), "%s/class",
dirname);
if (eal_parse_sysfs_value(filename, &tmp) < 0) {
- free(dev);
+ free(pdev);
return -1;
}
/* the least 24 bits are valid: class, subclass, program interface */
@@ -309,7 +312,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
snprintf(filename, sizeof(filename), "%s/resource", dirname);
if (pci_parse_sysfs_resource(filename, dev) < 0) {
RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
- free(dev);
+ free(pdev);
return -1;
}
@@ -318,7 +321,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
ret = pci_get_kernel_driver_by_path(filename, driver, sizeof(driver));
if (ret < 0) {
RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
- free(dev);
+ free(pdev);
return -1;
}
@@ -382,7 +385,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
RTE_LOG(ERR, EAL, "Unexpected device scan at %s!\n",
filename);
}
- free(dev);
+ free(pdev);
}
return 0;
}
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index d2af472ef..8b9deca8b 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -523,7 +523,7 @@ pci_unplug(struct rte_device *dev)
if (ret == 0) {
rte_pci_remove_device(pdev);
rte_devargs_remove(dev->devargs);
- free(pdev);
+ free(RTE_PCI_DEVICE_INTERNAL(pdev));
}
return ret;
}
diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index 8a5524052..3e2abd818 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -10,6 +10,14 @@
#include <rte_pci.h>
#include <rte_bus_pci.h>
+/*
+ * Convert struct rte_pci_device to struct rte_pci_device_internal
+ */
+#define RTE_PCI_DEVICE_INTERNAL(ptr) \
+ container_of(ptr, struct rte_pci_device_internal, device)
+#define RTE_PCI_DEVICE_INTERNAL_CONST(ptr) \
+ container_of(ptr, const struct rte_pci_device_internal, device)
+
extern struct rte_pci_bus rte_pci_bus;
struct rte_pci_driver;
@@ -17,6 +25,10 @@ struct rte_pci_device;
extern struct rte_pci_bus rte_pci_bus;
+struct rte_pci_device_internal {
+ struct rte_pci_device device;
+};
+
/**
* Probe the PCI bus
*
--
2.17.1
next prev parent reply other threads:[~2019-07-15 7:54 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-03 7:18 [dpdk-dev] [RFC 0/3] Add mdev (Mediated device) support in DPDK Tiwei Bie
2019-04-03 7:18 ` Tiwei Bie
2019-04-03 7:18 ` [dpdk-dev] [RFC 1/3] eal: add a helper for reading string from sysfs Tiwei Bie
2019-04-03 7:18 ` Tiwei Bie
2019-04-03 7:18 ` [dpdk-dev] [RFC 2/3] bus/mdev: add mdev bus support Tiwei Bie
2019-04-03 7:18 ` Tiwei Bie
2019-04-03 7:18 ` [dpdk-dev] [RFC 3/3] bus/pci: add mdev support Tiwei Bie
2019-04-03 7:18 ` Tiwei Bie
2019-04-03 14:13 ` Wiles, Keith
2019-04-03 14:13 ` Wiles, Keith
2019-04-04 4:19 ` Tiwei Bie
2019-04-04 4:19 ` Tiwei Bie
2019-04-08 8:44 ` [dpdk-dev] [RFC 0/3] Add mdev (Mediated device) support in DPDK Alejandro Lucero
2019-04-08 8:44 ` Alejandro Lucero
2019-04-08 9:36 ` Tiwei Bie
2019-04-08 9:36 ` Tiwei Bie
2019-04-10 10:02 ` Francois Ozog
2019-04-10 10:02 ` Francois Ozog
2023-07-03 23:54 ` Stephen Hemminger
2019-07-15 7:52 ` [dpdk-dev] [RFC v2 0/5] " Tiwei Bie
2019-07-15 7:52 ` Tiwei Bie [this message]
2019-07-15 7:52 ` [dpdk-dev] [RFC v2 2/5] bus/pci: avoid depending on private value in kernel source Tiwei Bie
2019-07-15 7:52 ` [dpdk-dev] [RFC v2 3/5] bus/pci: introduce helper for MMIO read and write Tiwei Bie
2019-07-15 7:52 ` [dpdk-dev] [RFC v2 4/5] eal: add a helper for reading string from sysfs Tiwei Bie
2019-07-15 7:52 ` [dpdk-dev] [RFC v2 5/5] bus/pci: add mdev support Tiwei Bie
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 0/6] Add mdev (Mediated device) support in DPDK Chenbo Xia
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 1/6] bus/pci: introduce an internal representation of PCI device Chenbo Xia
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 2/6] bus/pci: avoid depending on private value in kernel source Chenbo Xia
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 3/6] bus/pci: introduce helper for MMIO read and write Chenbo Xia
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 4/6] eal: add a helper for reading string from sysfs Chenbo Xia
2021-06-01 5:37 ` Stephen Hemminger
2021-06-08 5:47 ` Xia, Chenbo
2021-06-01 5:39 ` Stephen Hemminger
2021-06-08 5:48 ` Xia, Chenbo
2021-06-11 7:19 ` Thomas Monjalon
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 5/6] bus/pci: add mdev support Chenbo Xia
2021-06-01 3:06 ` [dpdk-dev] [RFC v3 6/6] bus/pci: add sparse mmap support for mediated PCI devices Chenbo Xia
2021-06-11 7:15 ` [dpdk-dev] [RFC v3 0/6] Add mdev (Mediated device) support in DPDK Thomas Monjalon
2021-06-15 2:49 ` Xia, Chenbo
2021-06-15 7:48 ` Thomas Monjalon
2021-06-15 10:44 ` Xia, Chenbo
2021-06-15 11:57 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190715075214.16616-2-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=alejandro.lucero@netronome.com \
--cc=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=cunming.liang@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=keith.wiles@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).