Skip to contentSkip to conversation

hash: fix maybe-uninitialized warning on minsize build

PATCH In review Cheryl Bansal 3 participants 6 messages Nov 23 – Dec 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 hash: fix maybe-uninitialized warning on minsize build

With --buildtype=minsize and -Werror, gcc reports that slot_id may be used uninitialized in alloc_slot(). This is a false positive: every path either returns EMPTY_SLOT or assigns slot_id before use.

Initialize slot_id to EMPTY_SLOT to silence the warning.

Fixes 5915699153d7 ("hash: fix scaling by reducing contention")
---
 .mailmap                   | 1 +
 lib/hash/rte_cuckoo_hash.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
.mailmap +1 -0
index a0096fb97a..5146a4fa2b 100644
@@ -288,6 +288,7 @@ Chenna Arnoori <[email protected]>
 Chenxingyu Wang <[email protected]>
 Chenxu Di <[email protected]>
 Chenyu Huang <[email protected]>
+Cheryl Bansal <[email protected]>
 Cheryl Houser <[email protected]>
 Chinh Cao <[email protected]>
 Chintu Hetam <[email protected]>
lib/hash/rte_cuckoo_hash.c +1 -1
index 5d495ae973..47ea909d38 100644
@@ -1298,7 +1298,7 @@ static inline uint32_t
 alloc_slot(const struct rte_hash *h, struct lcore_cache *cached_free_slots)
 {
 	unsigned int n_slots;
-	uint32_t slot_id;
+	uint32_t slot_id = EMPTY_SLOT;
 
 	if (h->use_local_cache) {
 		/* Try to get a free slot from the local cache */
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 bus/pci: add selective BAR mapping support

Drivers that only need a subset of PCI BARs still pay the cost of mapping every valid BAR. There is no bus-level way to select which BARs are mapped without changing each PMD.

Add the bar_mask PCI bus argument to select which BARs to map. If it is omitted, all valid BARs are mapped. A zero mask, a value outside BAR0-BAR5, or a malformed value is rejected. The argument is parsed from bus_str so it is not passed to PMDs. UIO and VFIO map slots are indexed by BAR number so primary and secondary processes stay consistent when some BARs are skipped.

Example: -a bus=pci,addr=0000:01:00.0,bar_mask=0x05

---
 doc/guides/prog_guide/devargs.rst      | 13 +++++++
 doc/guides/rel_notes/release_26_11.rst |  6 +++
 drivers/bus/pci/linux/pci_vfio.c       |  7 ++++
 drivers/bus/pci/pci_common.c           | 46 +++++++++++++++++++++++
 drivers/bus/pci/pci_common_uio.c       | 52 ++++++++++++++------------
 drivers/bus/pci/pci_params.c           |  2 +
 drivers/bus/pci/private.h              | 16 ++++++++
 7 files changed, 118 insertions(+), 24 deletions(-)
doc/guides/prog_guide/devargs.rst +13 -0
index c8a7224aa0..dc30f3a487 100644
@@ -82,6 +82,19 @@ The above example will pass ``representor=[0-3]`` devarg
 only to device corresponding to PCI address ``0000:02:00.0``,
 and only if it is managed by ``ice`` driver.
 
+PCI bus arguments include:
+
+* ``addr``: PCI address of the device (BDF).
+* ``bar_mask``: bitmask of BARs to map (bits 0-5 for BAR0-BAR5).
+  If omitted, all valid BARs are mapped.
+  A zero mask, a value outside BAR0-BAR5, or a malformed value is rejected.
+
+.. code-block:: none
+
+   bus=pci,addr=0000:01:00.0,bar_mask=0x05
+
+The above example maps BAR0 and BAR2 only for the given PCI device.
+
 
 Simplified syntax
 ~~~~~~~~~~~~~~~~~
doc/guides/rel_notes/release_26_11.rst +6 -0
index 10ab2355ae..90dc79ee16 100644
@@ -58,6 +58,12 @@ New Features
   the kernel driver is the generic ``vfio-platform``,
   which carries no device identity in its name.
 
+* **Added selective PCI BAR mapping.**
+
+  Added the PCI bus argument ``bar_mask`` to select which BARs to map.
+  If omitted, all valid BARs are mapped.
+  Example: ``-a bus=pci,addr=0000:01:00.0,bar_mask=0x05``.
+
 * **Added 1.6T link speed to ethdev.**
 
   Added the 1.6 Tb/s Ethernet link speed,
drivers/bus/pci/linux/pci_vfio.c +7 -0
index 4363d7ff2c..1046d84c36 100644
@@ -738,6 +738,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 	struct mapped_pci_resource *vfio_res = NULL;
 	struct mapped_pci_res_list *vfio_res_list =
 		RTE_TAILQ_CAST(dev_vfio_tailq.head, mapped_pci_res_list);
+	uint8_t bar_mask = pci_get_bar_mask(dev);
 
 	struct pci_map *maps;
 
@@ -814,6 +815,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 		struct vfio_info_cap_header *hdr;
 		struct vfio_region_info_cap_sparse_mmap *sparse;
 
+		if ((bar_mask & (1 << i)) == 0)
+			continue;
+
 		ret = pci_vfio_get_region_info(vfio_dev_fd, &reg, i);
 		if (ret < 0) {
 			PCI_LOG(ERR, "%s cannot get device region info error %i (%s)",
@@ -1018,6 +1022,9 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev)
 int
 pci_vfio_map_resource(struct rte_pci_device *dev)
 {
+	if (RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask_err != 0)
+		return -EINVAL;
+
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		return pci_vfio_map_resource_primary(dev);
 	else
drivers/bus/pci/pci_common.c +46 -0

73 lines not on this page · raw message

drivers/bus/pci/pci_common_uio.c +28 -24

117 lines not on this page · raw message

drivers/bus/pci/pci_params.c +2 -0
index 6cbd98b4c8..4fe148b0a1 100644
@@ -17,11 +17,13 @@
 
 enum pci_params {
 	RTE_PCI_PARAM_ADDR,
+	RTE_PCI_PARAM_BAR_MASK,
 	RTE_PCI_PARAM_MAX,
 };
 
 static const char * const pci_params_keys[] = {
 	[RTE_PCI_PARAM_ADDR] = "addr",
+	[RTE_PCI_PARAM_BAR_MASK] = PCI_BAR_MASK_ARG,
 	[RTE_PCI_PARAM_MAX] = NULL,
 };
 
drivers/bus/pci/private.h +16 -0
index f266a1b04d..0806822602 100644
@@ -43,8 +43,24 @@ struct rte_pci_device_internal {
 	struct rte_pci_device device;
 	/* PCI regions provided by e.g. VFIO. */
 	struct rte_pci_region region[RTE_MAX_PCI_REGIONS];
+	int bar_mask_err;	/* nonzero if bar_mask was present but invalid */
+	uint8_t bar_mask;	/* 0 = map all BARs */
 };
 
+#define PCI_BAR_MASK_ARG "bar_mask"
+#define PCI_BAR_MASK_ALL ((1U << PCI_MAX_RESOURCE) - 1)
+
+static inline uint8_t
+pci_get_bar_mask(struct rte_pci_device *dev)
+{
+	struct rte_pci_device_internal *pdev = RTE_PCI_DEVICE_INTERNAL(dev);
+	uint8_t mask = pdev->bar_mask;
+
+	if (mask == 0)
+		mask = PCI_BAR_MASK_ALL;
+	return mask;
+}
+
 /**
  * Scan the content of the PCI bus, and the devices in the devices
  * list
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 2/2] bus/pci: add selective BAR mapping support

Quoted 12 lines · Cheryl Bansal

Drivers that only need a subset of PCI BARs still pay the cost of mapping every valid BAR. There is no bus-level way to select which BARs are mapped without changing each PMD.

Add the bar_mask PCI bus argument to select which BARs to map. If it is omitted, all valid BARs are mapped. A zero mask, a value outside BAR0-BAR5, or a malformed value is rejected. The argument is parsed from bus_str so it is not passed to PMDs. UIO and VFIO map slots are indexed by BAR number so primary and secondary processes stay consistent when some BARs are skipped.

Quoted 3 lines

Example: -a bus=pci,addr=0000:01:00.0,bar_mask=0x05

Clearly too late for 26.11.
And don't Cc: stable.

Adding a devargs looks like a bad idea.
Why should a user know about such an internal consideration?

A change in the internal PCI bus API seems a better direction.

I wonder, which DPDK in-tree driver would benefit from this change?

Signature · 1 line
David Marchand
#3 lore raw

Re: [PATCH 2/2] bus/pci: add selective BAR mapping support

Quoted 21 lines · On Mon, 23 Nov 2026 08:57:45 +0100 David Marchand <[email protected]>…
Quoted 12 lines · Cheryl Bansal

Drivers that only need a subset of PCI BARs still pay the cost of mapping every valid BAR. There is no bus-level way to select which BARs are mapped without changing each PMD.

Add the bar_mask PCI bus argument to select which BARs to map. If it is omitted, all valid BARs are mapped. A zero mask, a value outside BAR0-BAR5, or a malformed value is rejected. The argument is parsed from bus_str so it is not passed to PMDs. UIO and VFIO map slots are indexed by BAR number so primary and secondary processes stay consistent when some BARs are skipped.

Quoted 3 lines

Example: -a bus=pci,addr=0000:01:00.0,bar_mask=0x05

Clearly too late for 26.11.
And don't Cc: stable.

Quoted 8 lines

Adding a devargs looks like a bad idea.
Why should a user know about such an internal consideration?

A change in the internal PCI bus API seems a better direction.

I wonder, which DPDK in-tree driver would benefit from this change?

Agree. Too late for 26.11 and devargs is not the best way to handle. I wonder if bus API could allow probe to reject a device? How does Linux and FreeBSD handle it?

#4 lore raw

PATCH v2 1/1 bus/pci: map selected BARs from the driver

In reply to Cheryl Bansal

Drivers that only need a subset of PCI BARs still pay the cost of mapping every valid BAR. There is no bus-level way for a driver to select which BARs are mapped.

Add the internal rte_pci_map_device_bars(). A driver calls it from probe() and does not set RTE_PCI_DRV_NEED_MAPPING. Bit N selects BAR N. A zero mask maps every valid BAR, which is what rte_pci_map_device() does. A mask outside BAR0-BAR5 is rejected. UIO and VFIO map slots stay indexed by BAR number so primary and secondary processes stay consistent when some BARs are skipped.

---
v2:
* Drop the PCI bus devarg. A driver calls rte_pci_map_device_bars() from probe() and does not set RTE_PCI_DRV_NEED_MAPPING. A failed map is the driver's probe error. Linux, FreeBSD and Windows all use the same mask.
* Rebased on v26.11. For 27.03.

 drivers/bus/pci/bsd/pci.c        | 25 +++++++++++++---
 drivers/bus/pci/linux/pci.c      | 25 +++++++++++++---
 drivers/bus/pci/linux/pci_vfio.c |  4 +++
 drivers/bus/pci/pci_common.c     |  2 ++
 drivers/bus/pci/pci_common_uio.c | 49 ++++++++++++++++----------------
 drivers/bus/pci/private.h        | 14 +++++++++
 drivers/bus/pci/rte_bus_pci.h    | 17 +++++++++++
 drivers/bus/pci/windows/pci.c    | 12 ++++++++
 8 files changed, 116 insertions(+), 32 deletions(-)
drivers/bus/pci/bsd/pci.c +21 -4
index 2d29f8d2e2..5c10f2e823 100644
@@ -48,10 +48,8 @@
  * PCI probing under BSD.
  */
 
-/* Map pci device */
-RTE_EXPORT_SYMBOL(rte_pci_map_device)
-int
-rte_pci_map_device(struct rte_pci_device *dev)
+static int
+pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
 
@@ -70,6 +68,25 @@ rte_pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
+/* Map pci device */
+RTE_EXPORT_SYMBOL(rte_pci_map_device)
+int
+rte_pci_map_device(struct rte_pci_device *dev)
+{
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+	return pci_map_device(dev);
+}
+
 /* Unmap pci device */
 RTE_EXPORT_SYMBOL(rte_pci_unmap_device)
 void
drivers/bus/pci/linux/pci.c +21 -4
index 28949e3720..74ff60dcf0 100644
@@ -55,10 +55,8 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name,
 	return -1;
 }
 
-/* Map pci device */
-RTE_EXPORT_SYMBOL(rte_pci_map_device)
-int
-rte_pci_map_device(struct rte_pci_device *dev)
+static int
+pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
 
@@ -84,6 +82,25 @@ rte_pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
+/* Map pci device */
+RTE_EXPORT_SYMBOL(rte_pci_map_device)
+int
+rte_pci_map_device(struct rte_pci_device *dev)
+{
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+	return pci_map_device(dev);
+}
+
 /* Unmap pci device */
 RTE_EXPORT_SYMBOL(rte_pci_unmap_device)
 void
drivers/bus/pci/linux/pci_vfio.c +4 -0
index 4363d7ff2c..43ef810cc6 100644
@@ -738,6 +738,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 	struct mapped_pci_resource *vfio_res = NULL;
 	struct mapped_pci_res_list *vfio_res_list =
 		RTE_TAILQ_CAST(dev_vfio_tailq.head, mapped_pci_res_list);
+	uint8_t bar_mask = pci_get_bar_mask(dev);
 
 	struct pci_map *maps;
 
@@ -814,6 +815,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 		struct vfio_info_cap_header *hdr;
 		struct vfio_region_info_cap_sparse_mmap *sparse;
 
+		if ((bar_mask & (1 << i)) == 0)
+			continue;
+
 		ret = pci_vfio_get_region_info(vfio_dev_fd, &reg, i);
 		if (ret < 0) {
 			PCI_LOG(ERR, "%s cannot get device region info error %i (%s)",
drivers/bus/pci/pci_common.c +2 -0
index 3770b4ad75..21d8708b84 100644
@@ -3,6 +3,7 @@
  * Copyright 2013-2014 6WIND S.A.
  */
 
+#include <errno.h>
 #include <string.h>
 #include <inttypes.h>
 #include <stdint.h>
@@ -25,6 +26,7 @@
 #include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_kvargs.h>
 #include <rte_tailq.h>
 
 #include "private.h"
drivers/bus/pci/pci_common_uio.c +25 -24

114 lines not on this page · raw message

drivers/bus/pci/private.h +14 -0
index f266a1b04d..09c035112c 100644
@@ -43,8 +43,22 @@ struct rte_pci_device_internal {
 	struct rte_pci_device device;
 	/* PCI regions provided by e.g. VFIO. */
 	struct rte_pci_region region[RTE_MAX_PCI_REGIONS];
+	uint8_t bar_mask;	/* 0 = map all BARs. Set by rte_pci_map_device_bars(). */
 };
 
+#define PCI_BAR_MASK_ALL ((1U << PCI_MAX_RESOURCE) - 1)
+
+static inline uint8_t
+pci_get_bar_mask(struct rte_pci_device *dev)
+{
+	struct rte_pci_device_internal *pdev = RTE_PCI_DEVICE_INTERNAL(dev);
+	uint8_t mask = pdev->bar_mask;
+
+	if (mask == 0)
+		mask = PCI_BAR_MASK_ALL;
+	return mask;
+}
+
 /**
  * Scan the content of the PCI bus, and the devices in the devices
  * list
drivers/bus/pci/rte_bus_pci.h +17 -0
index 22a7beb1fc..72e3ce1395 100644
@@ -51,6 +51,23 @@ struct rte_devargs;
  */
 int rte_pci_map_device(struct rte_pci_device *dev);
 
+/**
+ * Map a selected set of PCI BARs.
+ *
+ * Bit N of bar_mask selects BAR N (0-5). A zero mask maps every valid BAR,
+ * which is what rte_pci_map_device() does. The driver calls this from probe()
+ * and must not set RTE_PCI_DRV_NEED_MAPPING, or the bus maps every BAR first.
+ *
+ * @param dev
+ *   PCI device to map.
+ * @param bar_mask
+ *   Bitmask of BARs to map.
+ * @return
+ *   0 on success, negative on error and positive if no driver is found.
+ */
+__rte_internal
+int rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask);
+
 /**
  * Unmap this device
  *
drivers/bus/pci/windows/pci.c +12 -0
index 383c6bdc2f..9706033938 100644
@@ -42,6 +42,18 @@ RTE_EXPORT_SYMBOL(rte_pci_map_device)
 int
 rte_pci_map_device(struct rte_pci_device *dev)
 {
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+
 	/* Only return success for devices bound to netuio.
 	 * Devices that are bound to netuio are mapped at
 	 * the bus probing stage.
Signature · 1 line
2.43.0
#5 lore raw

PATCH v3 1/1 bus/pci: map selected BARs from the driver

Not all PCI devices require every BAR to be mapped within DPDK; in some architectures, specific BARs must remain unmapped so they can be managed by external mechanisms. To support this, this patch introduces a new API enabling drivers to specify arguments for selective BAR mapping.

As a concrete use case, the proposed Altera MCDMA driver
(https://patches.dpdk.org/project/dpdk/list/?series=39993) currently maps BAR2 (the PIO region) unconditionally. Certain hardware designs require this PIO BAR to stay unmapped for out-of-band access. Following the acceptance of this API, the Altera MCDMA driver will be updated to adopt selective BAR mapping.

---
v3:
* Document the return value: 0, -EINVAL for a mask above BAR5, negative on mapping failure, and positive if no supported kernel driver is found.
* On Windows the mask is recorded only. Netuio maps the BARs at probe.
* Drop the unused errno.h and rte_kvargs.h includes.

v2:
* Drop the PCI bus devarg. A driver calls rte_pci_map_device_bars() from probe() and does not set RTE_PCI_DRV_NEED_MAPPING. A failed map is the driver's probe error.
* Rebased on v26.11. For 27.03.

 drivers/bus/pci/bsd/pci.c        | 25 +++++++++++++---
 drivers/bus/pci/linux/pci.c      | 25 +++++++++++++---
 drivers/bus/pci/linux/pci_vfio.c |  4 +++
 drivers/bus/pci/pci_common_uio.c | 49 ++++++++++++++++----------------
 drivers/bus/pci/private.h        | 14 +++++++++
 drivers/bus/pci/rte_bus_pci.h    | 21 ++++++++++++++
 drivers/bus/pci/windows/pci.c    | 12 ++++++++
 7 files changed, 118 insertions(+), 32 deletions(-)
drivers/bus/pci/bsd/pci.c +21 -4
index 2d29f8d2e2..5c10f2e823 100644
@@ -48,10 +48,8 @@
  * PCI probing under BSD.
  */
 
-/* Map pci device */
-RTE_EXPORT_SYMBOL(rte_pci_map_device)
-int
-rte_pci_map_device(struct rte_pci_device *dev)
+static int
+pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
 
@@ -70,6 +68,25 @@ rte_pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
+/* Map pci device */
+RTE_EXPORT_SYMBOL(rte_pci_map_device)
+int
+rte_pci_map_device(struct rte_pci_device *dev)
+{
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+	return pci_map_device(dev);
+}
+
 /* Unmap pci device */
 RTE_EXPORT_SYMBOL(rte_pci_unmap_device)
 void
drivers/bus/pci/linux/pci.c +21 -4
index 28949e3720..74ff60dcf0 100644
@@ -55,10 +55,8 @@ pci_get_kernel_driver_by_path(const char *filename, char *dri_name,
 	return -1;
 }
 
-/* Map pci device */
-RTE_EXPORT_SYMBOL(rte_pci_map_device)
-int
-rte_pci_map_device(struct rte_pci_device *dev)
+static int
+pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
 
@@ -84,6 +82,25 @@ rte_pci_map_device(struct rte_pci_device *dev)
 	return ret;
 }
 
+/* Map pci device */
+RTE_EXPORT_SYMBOL(rte_pci_map_device)
+int
+rte_pci_map_device(struct rte_pci_device *dev)
+{
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+	return pci_map_device(dev);
+}
+
 /* Unmap pci device */
 RTE_EXPORT_SYMBOL(rte_pci_unmap_device)
 void
drivers/bus/pci/linux/pci_vfio.c +4 -0
index 4363d7ff2c..43ef810cc6 100644
@@ -738,6 +738,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 	struct mapped_pci_resource *vfio_res = NULL;
 	struct mapped_pci_res_list *vfio_res_list =
 		RTE_TAILQ_CAST(dev_vfio_tailq.head, mapped_pci_res_list);
+	uint8_t bar_mask = pci_get_bar_mask(dev);
 
 	struct pci_map *maps;
 
@@ -814,6 +815,9 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev)
 		struct vfio_info_cap_header *hdr;
 		struct vfio_region_info_cap_sparse_mmap *sparse;
 
+		if ((bar_mask & (1 << i)) == 0)
+			continue;
+
 		ret = pci_vfio_get_region_info(vfio_dev_fd, &reg, i);
 		if (ret < 0) {
 			PCI_LOG(ERR, "%s cannot get device region info error %i (%s)",
drivers/bus/pci/pci_common_uio.c +25 -24

114 lines not on this page · raw message

drivers/bus/pci/private.h +14 -0
index f266a1b04d..09c035112c 100644
@@ -43,8 +43,22 @@ struct rte_pci_device_internal {
 	struct rte_pci_device device;
 	/* PCI regions provided by e.g. VFIO. */
 	struct rte_pci_region region[RTE_MAX_PCI_REGIONS];
+	uint8_t bar_mask;	/* 0 = map all BARs. Set by rte_pci_map_device_bars(). */
 };
 
+#define PCI_BAR_MASK_ALL ((1U << PCI_MAX_RESOURCE) - 1)
+
+static inline uint8_t
+pci_get_bar_mask(struct rte_pci_device *dev)
+{
+	struct rte_pci_device_internal *pdev = RTE_PCI_DEVICE_INTERNAL(dev);
+	uint8_t mask = pdev->bar_mask;
+
+	if (mask == 0)
+		mask = PCI_BAR_MASK_ALL;
+	return mask;
+}
+
 /**
  * Scan the content of the PCI bus, and the devices in the devices
  * list
drivers/bus/pci/rte_bus_pci.h +21 -0
index 22a7beb1fc..72e3ce1395 100644
@@ -51,6 +51,27 @@ struct rte_devargs;
  */
 int rte_pci_map_device(struct rte_pci_device *dev);
 
+/**
+ * Map a selected set of PCI BARs.
+ *
+ * Bit N of bar_mask selects BAR N (0-5). A zero mask maps every valid BAR,
+ * which is what rte_pci_map_device() does. The driver calls this from probe()
+ * and must not set RTE_PCI_DRV_NEED_MAPPING, or the bus maps every BAR first.
+ *
+ * @param dev
+ *   PCI device to map.
+ * @param bar_mask
+ *   Bitmask of BARs to map.
+ * @return
+ *   0 on success, -EINVAL if bar_mask selects a BAR above BAR5,
+ *   negative on mapping failure, and positive if no supported
+ *   kernel driver is found. On Windows the BARs are already mapped
+ *   at probe, so the mask is recorded and the existing netuio
+ *   result is returned.
+ */
+__rte_internal
+int rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask);
+
 /**
  * Unmap this device
  *
drivers/bus/pci/windows/pci.c +12 -0
index 383c6bdc2f..9706033938 100644
@@ -42,6 +42,18 @@ RTE_EXPORT_SYMBOL(rte_pci_map_device)
 int
 rte_pci_map_device(struct rte_pci_device *dev)
 {
+	return rte_pci_map_device_bars(dev, 0);
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_map_device_bars)
+int
+rte_pci_map_device_bars(struct rte_pci_device *dev, uint8_t bar_mask)
+{
+	if (bar_mask > PCI_BAR_MASK_ALL)
+		return -EINVAL;
+
+	RTE_PCI_DEVICE_INTERNAL(dev)->bar_mask = bar_mask;
+
 	/* Only return success for devices bound to netuio.
 	 * Devices that are bound to netuio are mapped at
 	 * the bus probing stage.
Signature · 1 line
2.43.0