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 375DF606A327 for ; Wed, 2 Dec 2026 12:44:10 +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=CyPD1Lwz Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 95E36402D9; Wed, 2 Dec 2026 13:44:08 +0100 (CET) Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010041.outbound.protection.outlook.com [52.101.46.41]) by mails.dpdk.org (Postfix) with ESMTPS id 4FC59402D5 for ; Wed, 2 Dec 2026 13:44:07 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ef+/LL5ktrnFO0fnD+g1saLUhqzZhcJ9GgcWK+C6cb0jt3yn/jUcVzP4BjJBLGByrIx+ljSnfgdDCzJS4FttJfXGCtQkElKOtoCPjczXFLOj6eiE5LiJvEYCSR52AseceRXHDmxDg+zk0Gisy8XuMTRCQalRxPSv+6CebQjh5pVVZlMTFM7QJsgVGnEiN7vpoFwl6Ifc44NibJRTjDjRymYSLSWEL5OMQdgTw53MUYZGx6nTaCk8xjwCMw6JJcU9gkv4Riqg+hSUSzYUNqwlNaGHLm2rNAEfarqWGIecdu1sh352R5UfvwZxkT25GVnd5XwVwqLUQNqOT/AEv/NC+A== 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=+ls6KT/+zyMp29mtB9mtzJOUBpm4YOHftUkh1ZHz93U=; b=SwRuBKv4GS/kvvGJqpxHsgCJ4+oZXTZ2rdz3znjwRNSqTYuojwSjCB8LYqYqMkg00v9DlWj5hRAYHnsTJNkmvz3wT1oM2s+oYswE1uO/NjLUVkDulA2h/Zf2q75uvm9d5tR2OR+HCIQFK9xNREXjyzCHoQRYirI5SOYdTMFm4G6R9fY98RxPcVvT1+g3XBALLgGd0LDsWJzWm2k/awMQ9r+VJ0sTW1HqFDMBpKSshfUIJxT9TU6hHMQcE5KIY9jG1tTIVlh68eQbUAJzdQDjMWRiUAiv+G4t3TkpzxhPYiUSXRTlxx2A1RiLWGKnBLjoRw3I2Q09PJN1fjE/1nphhg== 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=+ls6KT/+zyMp29mtB9mtzJOUBpm4YOHftUkh1ZHz93U=; b=CyPD1LwzHQa2LWaQudj73wwLnm15LqeKhBiRko3lCk+x/X64Q2qhA7IMdCTNv5YkegzP25q3+ud3Ul42wgoUuj2doCcbN55dswr8uPBVBnWWWVb438zrtBJndWgwYa6I8/95UVKSmH6eNaRzsGLo9x4C9t9S1jKRij0pmEuQhD/cs5mz0cliM4z8beU+7SvdhxzQzjyntbx+etYZfyjNTOQf+GQ2oWhphSqIylNEnx7GsfX4hxam0kOglXa/K7R7t39ecmWkvezhzLXQGMO5FDpQki5VY9leneGYKb+CLdEyl2O0NgvVMWBidgYUExBrWTxce2DsHsRaOlNoxQ8eIA== 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 SJ0PR03MB5406.namprd03.prod.outlook.com (2603:10b6:a03:28e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 12:44:01 +0000 Received: from DS4PR03MB8131.namprd03.prod.outlook.com ([fe80::5759:ab24:f49c:ac71]) by DS4PR03MB8131.namprd03.prod.outlook.com ([fe80::5759:ab24:f49c:ac71%3]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 12:44:01 +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 v3] bus/pci: map selected BARs from the driver Date: Wed, 2 Dec 2026 18:13:53 +0530 Message-Id: <20261202124353.873889-1-cheryl.bansal@altera.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201103906.2722589-1-cheryl.bansal@altera.com> References: <20261201103906.2722589-1-cheryl.bansal@altera.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2P153CA0024.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::13) 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_|SJ0PR03MB5406:EE_ X-MS-Office365-Filtering-Correlation-Id: b4e6c3b9-5800-4b1d-21c1-08df5071f0fb X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|23010399003|11063799006|261009223027099003|261009221227099003|22082099003|18002099003|55112099003|260925021311599003|260925021911599003|260925022911599003|56012099006|10067099003|261102123227099003|261102130727099003|261021121427099003|261021123027099003|261028144727099003|261026121527099003|261026140227099003|261022105027099003|261022075727099003; X-Microsoft-Antispam-Message-Info: jbgtxc5NiksnM9IfSg2wTmDkyN9ujGlgS2IVF30usQFKpxKd4Xtzf94H5HksnErbRh6+cwFgYn5EeEa5e5cGc5PEJ3KQdODoXGSmLpLa2dgMDJgA9NNTP6Y0UXKgy6uSuKR4zF6WCcoh80qt+YvWlAPjqFa9PIL8gK/iekpCzYXp4zcRNkbux5d1jBMAH1oYi/ePLBLeACX4SaGZrZPxohzDMkNUTEjc4yZWPPKx1sN9ayrv1F0ktjk2WovyRSrwsSzuVbjh6UivUlRLiu4OzrKYdrFHwHBVNoYuWHROIFzgIPtNBGNhtfORa2fveLcV8vIwX6WhJpWOzGvpvNT9QcKi7yzkZ1Jsnh9Qksqtbs68gGJFhQdk13lfC/Fzujz3QLcFxs97tIZvfoOxOMGdSytobndWlhwBEzgVlan8oi/Xi/q7g44VyHdBKuRR/Q0OiDykqVoxZ/lnipQHuYjn33ix1oJpFAPV9DtASHV5ySZVZgfSp0hpWRx/c6W8fbksfIUhw+m/Zn8LtxSPysPEOJLgGcrTq9rK5yXJtBXTxUCfL7T9KPYP+J/rMzLg+761sKC+4+igdr5EtaZumahgRTzE7GVG60NPy9lRvQLOFDZZ4dcgKWKXboAK8IkDR/tF 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)(376014)(1800799024)(366016)(23010399003)(11063799006)(261009223027099003)(261009221227099003)(22082099003)(18002099003)(55112099003)(260925021311599003)(260925021911599003)(260925022911599003)(56012099006)(10067099003)(261102123227099003)(261102130727099003)(261021121427099003)(261021123027099003)(261028144727099003)(261026121527099003)(261026140227099003)(261022105027099003)(261022075727099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?eGoDaDrwE1kWt9B/eGmzdfcsusuk0Yq4cERhZteCbfbsMBkOHR4yujqzPiL8?= =?us-ascii?Q?W7YX/J/+h7QNwJiChAh/Mt4h29WBN6P6o+VqAMmA+xW6DjWz0QVSK4raHdSo?= =?us-ascii?Q?4bvSQlaCxABQXi0kZe9ZZUKq+fXBOesmi5y+wkfsf473GKxnYj9/CI0QvvGn?= =?us-ascii?Q?o9S8GO7Gak39AlAFYoqjTXCl2kvsPKG1phK/1dFx/o9ifQxxNYI+KAtIOi8h?= =?us-ascii?Q?XTTKHqHLaQlmnD/rrVswWgB4l4BWCH0bbDCw+o6pOe8DRgIpNj5lspo5KM0L?= =?us-ascii?Q?8npni33ECKVpyC0DZiOOS4J/l3aWw5BEEodcGjVYH11lUmQevUvQfbC/6/P9?= =?us-ascii?Q?L23JyOIGhpApBlUCv0YS3aK+tBVdIUkT+4z0ysw4j79DEwbwhgS5YHpktbpW?= =?us-ascii?Q?5ysTKU6a5sdQlJihttUdjtwPhgD8cYEgPC+VBhDoux+kr2BV+uxbPMrEnVGC?= =?us-ascii?Q?w4NzrsY7m85SZRhAYFs4wNwfXjghOSkOzuxCGRsfjbgEPj9Znm3jPglg2RCu?= =?us-ascii?Q?vvAWV7n3JHWfEySgsIK70W5noE4kqEaOlLEkYnNtvX6QiDjSUmfY+Z6hpr9u?= =?us-ascii?Q?z3ZvQVtNJcEaQGZ5YIgMxFoqz0BM5cArIqYPg88QGv3LiGks6P2X8hb30Bkk?= =?us-ascii?Q?+j6/e4cT29i3Qm49qE1+qjZJNKb93Jzp9kG2RzKu0l86PxtJfXMgzkH426Es?= =?us-ascii?Q?jB093A/lbRotJFXH7hTt2zyGLBeoIMW3jc39fpYnMsTXzBAEF1y+hXgr9zlg?= =?us-ascii?Q?alnAkeKH6VvJ5dpFQ/N51D4oj6ldlpbAZVfyb7llVYC3Jir+CCE+RpRZUBGH?= =?us-ascii?Q?z2FR6Azvll14+OmEBc/eMwKmPMh99TjUzJ6z+zf1YsoctgrccWZNKgdB5EPK?= =?us-ascii?Q?H/elFMHzfkcsS4aIPa4rRaz5wfLIJwaV93h133iKPOKheSRLv+swU0PUJU3q?= =?us-ascii?Q?kCH7CwsW0LX8XkYqmxgzD/p8dLRPCbOI24rNmbtzJtS4spw8WxZ2UnTbW0sg?= =?us-ascii?Q?OpZR4PccJezuKXjyFqEAqn1iOjTK6njLPB765alty1shP2gkLZa32NK80aYp?= =?us-ascii?Q?MAjbSUtpEkGldK2sp80IURArKBV5gb1yZzWb8RPgFgDJAr7zAq6PfuJ8n6Uf?= =?us-ascii?Q?3kQaI9hqjZXVmmqkO4e/FXEnKQN06yfGnMLQoetZE8P4T9HZdh0NOwCye43Q?= =?us-ascii?Q?oYS/1w1cHXcmxP7mX3eGb248VmTwurmTzBL6zqZJmMAIiwHdY70C+g66SCY7?= =?us-ascii?Q?Nm/F6F2zWLCkS3uiYqFrChjhyNcxuksXUm1yO9uv/Cnm+olYH2V4vAA3oOGB?= =?us-ascii?Q?ih1EQxi859Hj36ubdUPdBmVPHyqi6gHRgLBUFLfp32SxsI6SZZBIDBJEo0G9?= =?us-ascii?Q?t1so6O+cVaIoTE/+hRrRMePHOIdmoo/nk7b5tO0xFRwZ6vTBOfGWwq5N3EHP?= =?us-ascii?Q?M771LWbw9EYy2SzbkmvMZXbORzlf1ysFbDX3EC3dpphKS7kai2vj/V25blkH?= =?us-ascii?Q?aPAKjrBhCmz5fyFsjdCjjCyZcIuRpzl5eXzu1nHtKDhteLhp+/LajdKx+P3E?= =?us-ascii?Q?CQDNWQvixSeMclkdPbBUtVMa43S9LxIkPz39m7lGiDqdYo3EP+AniTZ8tjvF?= =?us-ascii?Q?yn0l+qEw8bzZClbHMyPDbYGtpxNWWQfgPAX2P64pnL8+Rc65v+BRfNQYbHfV?= =?us-ascii?Q?C/MF60iz70jNgdvam7+urJRmGwwHtKkg+1RRr6nQQU/9CS3YwJD85DVYtL9e?= =?us-ascii?Q?GZt3sVHBEw=3D=3D?= X-OriginatorOrg: altera.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4e6c3b9-5800-4b1d-21c1-08df5071f0fb X-MS-Exchange-CrossTenant-AuthSource: DS4PR03MB8131.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 12:44:01.6457 (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: O1jociUCXVZv/dio5EaOq7OakLA+2F94tmtdXtY+qhGIb+a6XMrUR8MMbaxkjZxjcGwCaeFnp1g3pJxalAm00Be9GByjVJKjXV1mx0ucEh8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR03MB5406 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 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. Signed-off-by: Cheryl Bansal --- 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(-) 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_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,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 * 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