Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53D99606A320 for ; Tue, 1 Dec 2026 10:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=altera.com header.i=@altera.com header.a=rsa-sha256 header.s=selector2 header.b=GoK3OzMM Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6421E40289; Tue, 1 Dec 2026 11:39:23 +0100 (CET) Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013008.outbound.protection.outlook.com [40.107.201.8]) by mails.dpdk.org (Postfix) with ESMTPS id 5E0064027A for ; Tue, 1 Dec 2026 11:39:21 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TEptZjW3lPlihEZ41EM4utFPwY8H6kIVJpXZVlA9g+kdNkZevVFnuofx5tdGmuv7tfjNQziQTB/5rAkFC3gcQ3Kn74ETkPycRRYnteY8xGqKZ/8uUA2mON5Bn5UqGSlUbYDYWYTZcsqmOXYXHnCPm3wwzQ/42Cgl8oi5Agyrr/XzjgRh1uPm/MknI1TsqHYcNoVnd9LsLuAjpEDUBSBoc2j7JZgWbfVGrtSuLrJeBvTa9NEyCN9kbcnsDoMn7RqRVzLcif+g6L4mE6b0S1R8fKthhdTQ/sTiCL+EsHNwHvcZ0dLBCQTWF6hjD+4Yn7xzwDOoOv/rzEr03MhJeDOCjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QDFC7AtqA6XXIITfDowYnACbG7pTHvPeoSxwXAQZ8MU=; b=ItM0XZ3tEPlGLeC6r26J0tGsereA/a44P31uJ+K3R1/8hRcXR2JqVt8Le2U8AhD6zOwAPG3FjljTQoDf1Xb8lsvMtL3HQlyJgpw5avjbTvXRKLGdcmfUvBaBpCdNgLLvkS83nm9UwFu01hm+xj4Jc8qp3xHuUVABJ0KP/UNHVuPQgsgXofhiRK3EqFXJFgGJ2ZOET4utt8/kVx+3nEKm0IGV/HJW9jJfmGp3GsO8yd4UeLNkpSdD04UifMSEmycbfeYp/b+cbXAXA/GPxWnx2iM7qmde+bs81CsfqcnONp5sUwKvOqzQFHoydGQVZtA50z5rj8iDMtiFhgM88E5lmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=altera.com; dmarc=pass action=none header.from=altera.com; dkim=pass header.d=altera.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=altera.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QDFC7AtqA6XXIITfDowYnACbG7pTHvPeoSxwXAQZ8MU=; b=GoK3OzMMWewDtSUtdYpl9Mhp9PvjF3ST6h3dF4E5Oy+c2RUkEfHOK8KAFfGbUBlfVhm9VjjHnPHP1l3N+x+K2+80fSsc+pG5swo2/utGEcn+jBfZKAksCkDM30WFW2EhY3pkvG2qLmmp8CVkPtRPkzGOOASh7QJNUUXaqFsh4rhgQbotQAXmtMnMGoPrXoHIob78RbnfFroG9YjG+g1iUKP5cyRSd0nYVqXraKPrgpv+vMY9qhtdbV73wzJMHZwsP/x7Jur20AAgobLoACaomnMC8fsflCpbbYEFcmMldvcn/N7nbS2QfDh3jKVduIQWsTch/0rX/7snWCiPRj8NBQ== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=altera.com; Received: from DS4PR03MB8131.namprd03.prod.outlook.com (2603:10b6:8:280::9) by PH7PR03MB7133.namprd03.prod.outlook.com (2603:10b6:510:2b6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 10:39:17 +0000 Received: from DS4PR03MB8131.namprd03.prod.outlook.com ([fe80::5759:ab24:f49c:ac71]) by DS4PR03MB8131.namprd03.prod.outlook.com ([fe80::5759:ab24:f49c:ac71%7]) with mapi id 15.21.0662.007; Tue, 1 Dec 2026 10:39:17 +0000 From: Cheryl Bansal To: chenbox@nvidia.com, nipun.gupta@amd.com Cc: david.marchand@redhat.com, stephen@networkplumber.org, dev@dpdk.org, Cheryl Bansal Subject: [PATCH v2] bus/pci: map selected BARs from the driver Date: Tue, 1 Dec 2026 16:09:06 +0530 Message-Id: <20261201103906.2722589-1-cheryl.bansal@altera.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261123061319.163645-2-cheryl.bansal@altera.com> References: <20261123061319.163645-2-cheryl.bansal@altera.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI1PR02CA0056.apcprd02.prod.outlook.com (2603:1096:4:1f5::7) To DS4PR03MB8131.namprd03.prod.outlook.com (2603:10b6:8:280::9) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS4PR03MB8131:EE_|PH7PR03MB7133:EE_ X-MS-Office365-Filtering-Correlation-Id: deba896b-b861-40ca-b9ec-08df4f975900 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|23010399003|366016|1800799024|376014|11063799006|18002099003|261009221227099003|261009223027099003|55112099003|22082099003|260925022911599003|260925021911599003|260925021311599003|10067099003|56012099006|261102130727099003|261102123227099003|261021123027099003|261021121427099003|261026121527099003|261028144727099003|261022105027099003|261026140227099003; X-Microsoft-Antispam-Message-Info: lrJcaCtQj78Izzb4vmOb52wrA1QdB2eqjwrUndvSC/C6F1SgAKy2XEiLU9Pbb6fi6octVzT+TAho6tz0+b02oecTt055fy5caN/VdCwFfHXkyqkBFcoZ31+FrWLYQzpj9tw7OHaRtkABmw4clpOAEjch5ZDEnqTaoAHKzu5zBvJY+YWlXooKFI+TQ1q51IypzovPhtA2JNvlx8V8z5m3iUawNpBFCodiiuJVWJb6ZBlUvUaLknAhaLXMiiT4Bcs+q1KiuUzHZzX1tbsx0sGTWKGSfTBsdnQHAUw1xhNT2PIE8QFVgG6FRYiDhH6r9vm+sHat7i7AnddFVoqPWsuZbU28esLGQix6ah0b+zbtmIGwYQ68dIbIuhDlrhse2Iy/iB96Oy6ldR5fhTPeCMAPWzhGC7JOYTZaMxKcUYzDCz5BTL6MX4shs1hJ0HwxEJnt8aTY3NelXvTQsCX+VEXX9hEZRx8kq+9bgR0eDY7S1iLQEtPheLnBWXa9DY4LApkPfQhNAHRu/qvbr01GQS5z3KPKVRphISNGFtySllJFVSVBhiLWfO9SJBVq+YnVIfgPz4AzGfSlIn6P9TW4zMTbhixD5ha4n0LMH/3+r7QOmT01wsdxFxa0x8Uq7U8dH8T1xjH44rvF2tlZ5pgMlFyDoPt2Xrajvj1/UstdCyRd0ww= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS4PR03MB8131.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(23010399003)(366016)(1800799024)(376014)(11063799006)(18002099003)(261009221227099003)(261009223027099003)(55112099003)(22082099003)(260925022911599003)(260925021911599003)(260925021311599003)(10067099003)(56012099006)(261102130727099003)(261102123227099003)(261021123027099003)(261021121427099003)(261026121527099003)(261028144727099003)(261022105027099003)(261026140227099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ibtF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?= X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-Network-Message-Id: deba896b-b861-40ca-b9ec-08df4f975900 X-MS-Exchange-CrossTenant-AuthSource: DS4PR03MB8131.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 10:39:17.0778 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fbd72e03-d4a5-4110-adce-614d51f2077a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NK25ynXGIWcLhz06tRDc/ffvrBRLuIuJ4oAiTBcd1f7KIfFpo2L1YUbQyU3C+AnlbJhEZVIE7u257fG4vCwFlD37Ci1gSglnLYLmmEiGH5E= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR03MB7133 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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. Signed-off-by: Cheryl Bansal --- 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(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 2d29f8d2e2..5c10f2e823 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -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 diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index 28949e3720..74ff60dcf0 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -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 diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 4363d7ff2c..43ef810cc6 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -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, ®, i); if (ret < 0) { PCI_LOG(ERR, "%s cannot get device region info error %i (%s)", diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 3770b4ad75..21d8708b84 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -3,6 +3,7 @@ * Copyright 2013-2014 6WIND S.A. */ +#include #include #include #include @@ -25,6 +26,7 @@ #include #include #include +#include #include #include "private.h" diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 52a10f806a..4635216eff 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -27,7 +27,7 @@ EAL_REGISTER_TAILQ(rte_uio_tailq) static int pci_uio_map_secondary(struct rte_pci_device *dev) { - int fd, i = 0, j, res_idx; + int fd, i, j; struct mapped_pci_resource *uio_res; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); @@ -38,15 +38,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev) if (rte_pci_addr_cmp(&uio_res->pci_addr, &dev->addr)) continue; - /* Map all BARs */ - for (res_idx = 0; res_idx != PCI_MAX_RESOURCE; res_idx++) { - /* skip empty BAR */ - if (dev->mem_resource[res_idx].phys_addr == 0) + /* Replay primary mappings (indexed by BAR) */ + for (i = 0; i != PCI_MAX_RESOURCE; i++) { + if (uio_res->maps[i].size == 0) continue; - if (i >= uio_res->nb_maps) - return -1; - /* * open devname, to mmap it */ @@ -80,9 +76,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) } return -1; } - dev->mem_resource[res_idx].addr = mapaddr; - - i++; + dev->mem_resource[i].addr = mapaddr; } return 0; } @@ -95,11 +89,12 @@ pci_uio_map_secondary(struct rte_pci_device *dev) int pci_uio_map_resource(struct rte_pci_device *dev) { - int i, map_idx = 0, ret; + int i, ret; uint64_t phaddr; struct mapped_pci_resource *uio_res = NULL; struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list); + uint8_t bar_mask = pci_get_bar_mask(dev); /* allocate uio resource */ ret = pci_uio_alloc_resource(dev, &uio_res); @@ -110,31 +105,34 @@ pci_uio_map_resource(struct rte_pci_device *dev) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return pci_uio_map_secondary(dev); - /* Map all BARs */ + /* Index maps[] by BAR number */ for (i = 0; i != PCI_MAX_RESOURCE; i++) { + if ((bar_mask & (1 << i)) == 0) + continue; + /* skip empty BAR */ phaddr = dev->mem_resource[i].phys_addr; if (phaddr == 0) continue; ret = pci_uio_map_resource_by_index(dev, i, - uio_res, map_idx); + uio_res, i); if (ret) goto error; - - map_idx++; } - uio_res->nb_maps = map_idx; + uio_res->nb_maps = PCI_MAX_RESOURCE; TAILQ_INSERT_TAIL(uio_res_list, uio_res, next); return 0; error: - for (i = 0; i < map_idx; i++) { - pci_unmap_resource(uio_res->maps[i].addr, - (size_t)uio_res->maps[i].size); - rte_free(uio_res->maps[i].path); + for (i = 0; i < PCI_MAX_RESOURCE; i++) { + if (uio_res->maps[i].addr != NULL) { + pci_unmap_resource(uio_res->maps[i].addr, + (size_t)uio_res->maps[i].size); + rte_free(uio_res->maps[i].path); + } } pci_uio_free_resource(dev, uio_res); return -1; @@ -149,6 +147,8 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res) return; for (i = 0; i != uio_res->nb_maps; i++) { + if (uio_res->maps[i].addr == NULL) + continue; pci_unmap_resource(uio_res->maps[i].addr, (size_t)uio_res->maps[i].size); if (rte_eal_process_type() == RTE_PROC_PRIMARY) @@ -166,10 +166,11 @@ pci_uio_remap_resource(struct rte_pci_device *dev) if (dev == NULL) return -1; - /* Remap all BARs */ + /* Remap mapped BARs only */ for (i = 0; i != PCI_MAX_RESOURCE; i++) { - /* skip empty BAR */ - if (dev->mem_resource[i].phys_addr == 0) + /* skip empty or unmapped BAR */ + if (dev->mem_resource[i].phys_addr == 0 || + dev->mem_resource[i].addr == NULL) continue; map_address = mmap(dev->mem_resource[i].addr, (size_t)dev->mem_resource[i].len, diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index f266a1b04d..09c035112c 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -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 diff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h index 22a7beb1fc..72e3ce1395 100644 --- a/drivers/bus/pci/rte_bus_pci.h +++ b/drivers/bus/pci/rte_bus_pci.h @@ -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 * diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c index 383c6bdc2f..9706033938 100644 --- a/drivers/bus/pci/windows/pci.c +++ b/drivers/bus/pci/windows/pci.c @@ -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. -- 2.43.0